1

I am trying to use AMPL to model a problem, and I want to be able to see alternatives, or multiple "optimal or near optimal" solutions.

I read on this site: http://orinanobworld.blogspot.com/2011/02/finding-multiple-solutions-in-binary.html

I have tried to fit this type of thing to my own model

and have tried to implement something like the following:

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];
}

When I run my model using this code, it gives me 5 of the exact same solution. What am I doing wrong? As a separate issue, it also seems like Picked also gets some non-binary values set in it (0.7235 for example), even though i thought setting it to binary would restrict it to 1 or 0.

Derek
  • 11,715
  • 32
  • 127
  • 228

1 Answers1

1

The fact that you get fractional solution suggests that you are solving a relaxation rather than a MIP problem. This can happen, for example, if you use a solver that doesn't support MIP such as MINOS and normally it gives you a warning like this:

MINOS 5.51: ignoring integrality of 5 variables

And you get identical solutions because the constraint Exclude only works for binary solutions. If you use a MIP solver such as CPLEX or Gurobi, you should get different binary solutions.

vitaut
  • 49,672
  • 25
  • 199
  • 336
  • 1
    Wow - thanks for the insight. I had seen that result from MINOS, but I didn't quite understand what it was talking about. I managed to get a trial version of CPLEX and it indeed worked. – Derek Oct 25 '15 at 21:25