AMPL的多种解决方案

时间:2015-10-25 12:42:28

标签: mathematical-optimization modeling ampl operations-research

我正在尝试使用AMPL来模拟问题,我希望能够看到替代方案,或者多个"最佳或接近最优的"解决方案。

我在这个网站上看到:http://orinanobworld.blogspot.com/2011/02/finding-multiple-solutions-in-binary.html

我试图将这种类型的东西放到我自己的模型中

并尝试实施以下内容:

set RECORDS;  # items available to choose from
var Picked {RECORDS} binary; # the variables that were set to 1 for "picked"

#other conditions and model constraints....

# we now create some structure to record multiple solutions
param want := 5; # number of solutions we want
param nfound default 0; # number of solutions found
set ALTS {1..100} in {RECORDS}; # records which items were packed (and where) in each solution

# we add constraints to the previous model to exclude solutions we've already seen
s.t. Exclude {s in 1..nfound}: 
sum {i in ALTS[s]} (1 - Picked[i]) + sum {j in {RECORDS} diff ALTS[s]} Picked[j] >= 1;

# solve until either the problem becomes infeasible or the right number of solutions have been found
for {s in 1..want} {

solve; # solve the model
if solve_result = 'infeasible' then break; # if the model has become infeasible, give up

#packed is getting the value of players that are in a lineup that have a "1" (>.5)
let ALTS[s] := {i in RECORDS : Picked[i] > 0.5};
let nfound := s; # bump the counter for solutions found
display s;
display ALTS[s];
}

当我使用此代码运行我的模型时,它给出了5个完全相同的解决方案。我究竟做错了什么?作为一个单独的问题,似乎Picked也会在其中设置一些非二进制值(例如0.7235),即使我认为将其设置为二进制会将其限制为1或0。

1 个答案:

答案 0 :(得分:1)

您获得分数解决方案的事实表明您正在解决放松而不是MIP问题。例如,如果您使用不支持MIP的解算器(例如MINOS),通常会发出如下警告:

MINOS 5.51: ignoring integrality of 5 variables

并且您获得相同的解决方案,因为约束Exclude仅适用于二进制解决方案。如果使用CPIP或Gurobi等MIP求解器,则应获得不同的二进制解法。