Losing multiobjective behavior after feasibility relaxation?
AnsweredWhen I run model.feasRelax on my multiobjective model (with minrelax = 0), it seems to automatically turn the model into a single objective model (model.IsMultiObj = 0 and model.NumObj =1). Thus, I'm no longer able to access the values of each of my individual objective functions with the updated solutions. Is there any way to get around this so that I can record the objective values?
The other option I have is to manually recalculate each of the terms in my objective function after the fact, using the solutions. But this is a bit tedious so I'm wondering if there's an alternative.
-
This is expected behavior - the feasibility relaxation creates a single objective to minimize the solution's violation of the original constraints with respect to the specified metric. Note that only \( \texttt{minrelax=False} \) is currently supported for multi-objective models.
To evaluate your multiple objectives at the feasibility relaxation's solution, you can store each objective function as a LinExpr object, then call LinExpr.getValue() once the feasibility relaxation finishes solving. For example, the following code
import gurobipy as gp
# Build simple model
m = gp.Model()
x = m.addVars(3, name='x')
m.addConstr(x[0] >= 20)
m.addConstr(x[1] >= 10)
m.addConstr(x[2] >= 5)
# Store objectives as LinExpr objects
obj1 = x[0] + x[2]
obj2 = 2*x[1]
# Solve feasibility relaxation (minrelax=False)
# For illustrative purposes - our model is feasible
m.feasRelaxS(0, False, True, True)
m.optimize()
# Evaluate objectives at current solution
print(f'obj1 = {obj1.getValue()}')
print(f'obj2 = {obj2.getValue()}')evaluates the two linear expressions given the feasibility relaxation solution:
obj1 = 25.0
obj2 = 20.01 -
Yes, this is the kind of solution I was looking for. Thank you!
0
Please sign in to leave a comment.
Comments
2 comments