0

I am using Docplex (Cplex python version) with a maximization objective. I set the time limit, using

mdl.solve(TimeLimit=600).

It is possible that the model doesn't reach the optimal during this time, so i want to get the objective value (sub-optimal) when the timeLimit is reached. How can i do it? For the optimal, i use :

mdl.get_objective_values()

It gives me None when the time limit is reached!

Thanks,

1 Answers1

0

your model could be either infeasible or not provide a solution in the given time limit. You should test the status after solve:

    sol = mdl.solve(TimeLimit=600)
    if sol is not None:

        print_information("Ok")

    else:
        print("* model is infeasible")
Alex Fleischer
  • 9,276
  • 2
  • 12
  • 15
  • But how could i retrieve the sub-optimal solution (the variables values)? because with sol.get_objective_bounds() i get the last bound of the objective... When it's optimal the sol.get_var_solution(variables) returns what i need... – user12484944 Feb 08 '20 at 10:44
  • see nurses.py in CPLEX_Studio1210\python\examples\mp\modeling (model.parameters.timelimit = 120) and later (model.nurse_assignment_vars[n, s].solution_value ) – Alex Fleischer Feb 08 '20 at 17:30
  • Thank you. Actually, i'm using CP "mdl=CpoModel()". I have checked all the examples in example\cp\modeling. But apparently if the solution is not optimal, there is no access to the sub-optimal values. Do you think i should switch to mp? – user12484944 Feb 10 '20 at 09:21
  • Same with CPO but if there is no solution found, you can t get it – Alex Fleischer Feb 10 '20 at 09:31
  • Sorry for the silly question, i'm newbie to cplex... If there is no solution why did i get the bound value of my objective? The stopCause displays: SearchStoppedByLimit, so logically i should be able to access the solution of the displayed bound even though it's not optimal? am i wrong in something? – user12484944 Feb 10 '20 at 09:37
  • The solver (any solver) may be able to prove that there is no solution possible with an objective value better (or worse) than some value, even if we have not yet found a solution. Hence we may have a bound on the objective value, even if we don't have a solution. – TimChippingtonDerrick Feb 12 '20 at 08:16
  • Thank you! So we can take the objective bound as optimal value for comparison in case of no solution is found? – user12484944 Mar 02 '20 at 08:26