Returning upper and lower bound of the second objective in a multiobjective formulation (two objectives)
AnsweredHi!
I need to return the upper and lower bound for my second objective function (and gap%) in my two objective formulation.
Here are my functions:
def set_objective():
model.ModelSense = GRB.MAXIMIZE
z1 = quicksum(z_ki[k, i] for k in D for i in PP)
z2 = -quicksum(
(t_kim[k, k + 2 * nr_passengers + nr_drivers, 0] - (t_kim[k, k, 0]) for k in D)
)
model.setObjectiveN(z1, index=0, priority=1)
model.setObjectiveN(z2, index=1, priority=0)
model.update()
return z1, z2
def optimize():
model.setParam("TimeLimit", 200)
add_constraints()
model.optimize()
runtime = model.Runtime
bestObjective = model.PoolObjVal
objectiveBound = model.PoolObjBound
return runtime, bestObjective, objectiveBound
def run_only_once():
runtime, bestObjective, objectiveBound = optimize()
path = get_result()
objective1 = z1.getValue()
objective2 = z2.getValue() * -1
return path, objective1, objective2, runtime, bestObjective, objectiveBound
My current code does not return what I want. Can you help me? Without using the callback function?
-
Hi,
When the optimization of a multi-objective problem finishes, it is possible to query the objective value for each objective on each solution. You would need to first set the SolutionNumber parameter to determine which solution you are interested in and set the ObjNumber parameter to choose an objective. You can then query the ObjNVal and Xn attributes on the model and the variables objects, respectively, to retrieve the objective value and the solution value for a particular solution. Please have a look at the "querying multi-objective results" section in the documentation of Multiple Objectives -> Working With Multiple Objectives for a clear example of how this can be done.
As mentioned in the documentation of Multiple Objectives -> Additional Details, it is not possible to directly query the attributes such as ObjBound and MIPGap for an individual objective step of a multi-objective problem. The only workaround is to use callbacks.
Best regards,
Maliheh
0
Please sign in to leave a comment.
Comments
1 comment