Forum Discussion
FICO
1 year agoCommunity Manager
How to apply termination conditions to each objective function in multi-objective model
Hello everyone, I am implementing a multi-objective model in Python, and I would like to set a time limit for each objective function. It would be best if I could set different time limits for each,...
FICO
1 year agoCommunity Manager
We don't have a good way to do this at the moment. Something you can try is to implement your own soft time limit in a callback. If there is a callback which is frequently called while solving your problem, you can use it to check whether your time limit has been hit, and if so, set mipabsstop to a large value to make the Optimizer accept the current solution. Then reset mipabsstop at the start of the next objective (in the beforeobjective callback).
Unfortunately there is not a convenient callback in which to check time limits. I would suggest trying the cutround callback, added in Xpress 9.6, which is called at every opportunity for cut separation during the solve, which means once every round of cuts added at the root node, and at least once per node solve in the branch and bound tree. This might provide enough resolution to implement your time limits.
Below is an example showing roughly how to do this. In a future release we plan to add proper support for this use case.
Regards,
Chris
import xpress as xp
time_limits = [
10, 20, 30, 40, 50 # etc.
]
def cutround(cb_prob, data, ifxpress):
"""Called at every opportunity for cut separation during the solve,
which means once every round of cuts added at the root node, and at
least once per node solve in the branch and bound tree."""
# Check the time limit for this objective
global time_limits
current_obj_index = cb_prob.attributes.solvedobjs
time_limit = time_limits[current_obj_index]
# The time attribute is reset to zero at the start of every objective
solve_time = cb_prob.attributes.time
if (
(solve_time > time_limit) and
# Only move on to the next objective if we found a solution (optional)
(cb_prob.attributes.mipsols > 0)
):
# Accept the current solution
print(f'Objective {current_obj_index + 1} hit time limit after {solve_time} seconds')
cb_prob.controls.mipabsstop = xp.infinity
def beforeobjective(cb_prob, data):
"""Called before every objective is solved"""
# Reset stopping conditions
cb_prob.controls.mipabsstop = 0
model = xp.problem()
# Define problem here...
model.addcbcutround(cutround)
model.addcbbeforeobjective(beforeobjective)
model.optimize()Related Content
Related Content
Multi-objective optimization in Python
Hello, I'd like to define a multi-objective optimization problem in Xpress Python. It seems like adding multiple lines of p.setObjective is not the right way to do. Could you describe what's the pre...6 years agoPlace FICO® Xpress Optimization ForumFICO® Xpress Optimization Forum2 unread comments2 unread0Views0likes2CommentsHow to detect between termination by timeout or tolerance
The documentation doesn't clearly explain XPRS_UNF. I believe it means the optimisation finished either due to a XPRS_MAXTIME being reached or a tolerance being met. Without comparing time and tolera...1 year agoPlace FICO® Xpress Optimization ForumFICO® Xpress Optimization Forum6 unread comments6 unread0Views0likes6Comments