gurobimultiple-resultsets

Why I am getting same answers in gurobi when I am finding multiple solutions?


I am using Gurobi for solving an optimization problem. In my problem, the goal is to analyze the most possible solutions. For this purpose, I am using the parameter:

PoolSearchMode=2 

in Gurobi to find multiple solutions. But, when I retrieve the solutions, there are some same results!. For example, if it returns 100 solutions, half of them are the same and actually I have 50 different solutions.

For more detail, I am trying to find some sets of nodes in a graph that have a special feature. So I have set the parameter "PoolSearchMode" to 2 that causes the MIP to do a systematic search for the n best solutions. I have defined a parameter "best" to find solutions that have "objVal" equal to the best one. In the blow there is a part of my code:

m.Params.PoolSearchMode = 2
m.Params.PoolSolutions = 100

b = m.addVars(Edges, vtype=GRB.BINARY,  name = "b")
.
.
.

if m.status == GRB.Status.OPTIMAL:

     best = 0
     for key in range(m.SolCount):
           m.setParam(GRB.Param.SolutionNumber, key) 
           if m.objVal == m.PoolObjVal:
                 best+=1

      optimal_sets = [[] for i in range(best)]     

      for key in range(best):
            m.setParam(GRB.Param.SolutionNumber, key) 

            for e in (Edges):
                  if b[e].Xn>0 and b[e].varname[2:]=="{}".format(External_node):
                            optimal_sets[key].append(int(b[e].varname[0:2]))

     return optimal_sets

I have checked and I found that, if there are not 100 solutions in a graph, it returns fewer solutions. But in these sets also there are same results like:

[1,2,3],
[1,2,3],
[1,3,5] 

How can I fix this issue to get different solutions?


Solution

  • It seems that Gurobi returns multiple solutions to the MIP that can be mapped to the same solution of your underlying problem. I'm sure that if you checked the entire solution vector all these solutions would indeed be different. You are only looking at a subset of the variables in your set optimal_sets.