Navigation

  • index
  • modules |
  • next |
  • previous |
  • CPLEX Python API documentation »
  • CPLEX for Python users »
  • Example: solving a sequence of related problems in the Python API

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
  ...

Table of Contents

Contents:

  • Cplex
  • Python tutorial
  • CPLEX for Python users
    • CPLEX for Python users
    • Why Python?
    • Meet the Python API
    • Modifying and querying problem data in the Python API
    • Using polymorphism in the Python API
    • Example: generating a histogram
    • Querying solution information in the Python API
    • Examining variables with nonzero values in a solution
    • Displaying high precision nonzero values of a solution
    • Managing CPLEX parameters in the Python API
    • Using callbacks in the Python API
    • Example: displaying solutions with increased precision from the Python API
    • Example: examining the simplex tableau in the Python API
    • Example: solving a sequence of related problems in the Python API
    • Example: complex termination criteria in a callback

Previous topic

Example: examining the simplex tableau in the Python API

Next topic

Example: complex termination criteria in a callback

This Page

  • Show Source

Quick search

«

Navigation

  • index
  • modules |
  • next |
  • previous |
  • CPLEX Python API documentation »
  • CPLEX for Python users »
  • Example: solving a sequence of related problems in the Python API
© Copyright IBM Corporation. Created using Sphinx 9.1.0.