Example: solving a sequence of related problems in the Python API¶
Illustrates how to solve a sequence of related problems in a loop.
Consider, for example, a sequence of related problems. The sequence begins with a model read from a formatted file, myprob.mps. (For more information about the math programming standard format MPS, see that topic in the reference manual, File formats supported by CPLEX.) Successive problems in the sequence reset the lower bound of the variable x0 and solve the model again with the new lower bound. The example prints the CPLEX log for each solution in a sequence of files named lb_set_to_0.log, lb_set_to_1.log, and so forth.
>>> c = cplex.Cplex("myprob.mps")
>>> for i in range(10):
... c.set_results_stream("lb_set_to_" + str(i) + ".log")
... c.variables.set_lower_bounds("x0", 1.0 * i)
... c.solve()
... if c.solution.get_status() == c.solution.status.infeasible:
... break
...