I've managed to model a problem as an LP problem with binary variables and solve it (using PuLP and GLPK). I believe that I read somewhere that you can "add your solution as a new constraint" to get the solver to come up with an alternative solution. Unfortunately I can't find where I read this, and I can't see how to "add the solution" to prevent the solver coming up with the previous solution. If what I read is correct, can someone explain how to do this please?
I am very new to LP. I have searched for an answer but it is likely I failed because I don't know the right search terms. I do know that in general enumerating the solution space isn't feasible because of the very large size of the space. I am simply interested in knowing how to "add a solution" to prevent the solver finding it again.
An LP with binary variables is no longer an LP (but rather a MIP). A constraint to forbid a previously found integer solution x*(i)
can be formulated as follows.
P subset of I
be the set corresponding to indices where x*(i)=1
. Q subset of I
be the set corresponding to indices where x*(i)=0
.Obviously P+Q=I
. Add to the model the following constraint:
sum(i in P, x(i)) - sum(i in Q, x(i)) <= p - 1
where p
is the cardinality (number of elements) of set P
. The derivation of this constraint is here.