Example: modifying a model lpex3.py¶
Modify the model in the sample lpex3.py.
The sample lpex3.py demonstrates how to:
set CPLEX parameters;
set CPLEX parameters;
modify an optimization model;
modify an optimization model;
start optimization from an existing basis.
start optimization from an existing basis.
The problem that lpex3.py solves looks like this:
The constraints Hx=d represent the flow conservation of a pure network flow problem. The sample solves this problem in two steps:
First, the CPLEX network optimizer solves:
First, the CPLEX network optimizer solves: Minimize c^Tx subject to Hx = d l ≤ x ≤ u
Second, the sample adds the constraints Ax=b to the model, and invokes the dual simplex optimizer to solve the full problem, starting from the optimal basis of the network problem.
Second, the sample adds the constraints Ax=b to the model, and invokes the dual simplex optimizer to solve the full problem, starting from the optimal basis of the network problem.
The dual simplex optimizer is highly effective in such a case because this basis remains dual feasible after the slacks (artificial variables) of the added constraints are initialized as basic.
The 0 (zero) values in the data are omitted in the sample. CPLEX makes extensive use of sparse matrix methods and, although CPLEX correctly handles any explicit zero coefficients given to it, most programs solving models of more than modest size benefit (in terms of both storage space and speed) if the natural sparsity of the model is exploited from the very start.
Before solving the model, the sample selects the network optimizer by setting the parameter lpmethod to the value parameters.lpmethod.values.network.
The sample also sets the simplex display parameter so that the simplex optimizer logs information as it executes.
For an introduction to CPLEX parameters in the CPLEX Python API, see also the topic parameters.