Finding all optimal solution for a Multiobjective Optimization
AnsweredHi,
I have set up a multiobjective mixed integer optimization model with Gurobi. In my case, I have two objectives. As far as I have understood, Gurobi does not support finding a Pareto frontier. I have two questions:
1.) I was trying to find multiple optimal solution using the PoolSearchMode and PoolSolutions. I thought this way gurobi will give me all possible optimal solutions in the feasible region. And I would use these point to find a Pareto frontier. Is it a right approach ?
2.) I am unable to retrieve multiple optimal solutions and get the program to print all the optimal values for both objective functions. This is the code I am using to print all the values, but it is throwing error.
m.Params.PoolSearchMode = 2
m.Params.PoolSolutions = 5
m.Params.PoolGap = 1
m.optimize()
m.solCount
for k in range(m.SolCount):
m.Params.SolutionNumber = k
print(Obj1.getValue())
print(Obj2.getValue())
This is not printing all feasible solutions for for both objective value. Please help.
Thanks,
Purnima

Hi Purnima,
You need to set the parameter for each objective. If you have 2 objectives, you can access the environment for both objectives and then set parameters as follows
env0 = m.getMultiobjEnv(0)
env1 = m.getMultiobjEnv(1)
# setting pool parameter for first objective
env0.setParam('PoolSearchMode', 2)
env0.setParam('PoolSolutions', 10)
env0.setParam('PoolGap', 1)
# setting pool parameter for second objective
env1.setParam('PoolSearchMode', 2)
env1.setParam('PoolSolutions', 10)
env1.setParam('PoolGap', 1)
# allow the complete pool to contain 10 solutions from first objective
# and 10 solutions from second objective
m.setParam('PoolSolutions', 20)In this way, Gurobi will search for 10 solutions when optimizing the first objective and 10 solutions when optimizing the second objective. Note that the model with the second objective also contains the constraint for the allowed degradation of the first objective.
When checking the objectives for all solutions, you probably need to set the parameter ObjNumber in a similar way as you set SolutionNumber.
I hope this helps,
Marika0 
Hi Marika,
Thank you for your response. It's still not clear to me on how to use ObjNumber to print all the values of optimal solution for both Obj1 and Obj2.
m.optimize()
m.solCountfor w in range(m.SolCount):
m.Params.SolutionNumber = w
print([var.X for var in Obj1.getValue()])
print([var.X for var in Obj2.getValue()])
If I try to run this piece of code , I get this error : AttributeError: 'float' object has no attribute 'X'
Could help me figure out how to print all the solution values ?
Thanks,
Purnima
0 
Hi Purnima,
You can print the objective values as follows
for w in range(m.SolCount):
m.Params.SolutionNumber = w
# consider all objectives for this solution
for i in range(2):
m.Params.ObjNumber = i
# value of objective i
print(m.ObjNVal)
# print all variable values for this solution
m.printAttr('Xn')Best regards,
Marika0
Please sign in to leave a comment.
Comments
3 comments