Namespace: ILOG.CPLEX
Assembly: ILOG.CPLEX (in ILOG.CPLEX.dll) Version: 22.1.1.0
Syntax
| C# |
|---|
public class Cplex : CplexModeler, IDisposable |
| Visual Basic |
|---|
Public Class Cplex _ Inherits CplexModeler _ Implements IDisposable |
Remarks
- LP (linear programming) models,
- QP (programs with quadratic terms in the objective function),
- QCP (quadratically constrained programming) models, including the special case of SOCP (second order cone programming), and
- MIP (mixed integer programming) models.
This class implements the modeling interface IMPModeler and its base interfaces. See the topic Modeling an optimization problem with Concert Technology in the Java API in the CPLEX User's Manual for more information about modeling.
Models to be solved by Cplex should be built by the methods of IMPModeler (and base interface) to construct objects from the following list:
- variables: objects of type INumVar and its extensions IIntVar and ISemiContVar
- range constraints: objects of type IRange with (piecewise) linear or quadratic expressions
- other relational constraints: objects of type IConstraint of the form expr1 relation expr2, where both expressions are linear or quadratic and may optionally contain piecewise linear terms.
- LP matrices: objects of type ILPMatrix
- a linear, piecewise linear, or quadratic objective: an object of type IObjective with a (piecewise) linear and/or quadratic expressions
- variable type conversions: objects of type IConversion
- special ordered sets: objects of type ISOS1 or ISOS2
Cplex stores such models internally in the standard math programming matrix representation:
Minimize (or Maximize) c'x + x'Qx
subject to L <= Ax <= U
a_i'x + x'Q_i x <= r_i, for i = 1, ..., q
l <= x <= u.
Thus A is the matrix of linear constraint coefficients, and L and U are the vectors of lower and upper bounds on the vector of variables, x. The Q matrix must be positive semi-definite (or negative semi-definite in the maximization case) and represents the quadratic terms of the objective function. The matrices Q_i must be positive semi-definite and represent the quadratic terms of the i-th quadratic constraint, and the a_i are vectors containing the corresponding linear terms. For more about the Q_i, see the chapter about QCP in the CPLEX User's Manual.
If the model contains integer, Boolean, or semi-continuous variables, or if the model has special ordered sets (SOSs), the model is referred to as a mixed integer program (MIP). You can query whether the active model is a MIP with the method Cplex.IsMIP.
A model with quadratic terms in the objective is referred to as a mixed integer quadratic program (MIQP) if it is also a MIP, and a quadratic program (QP) otherwise. You can query whether the active model has a quadratic objective by calling method Cplex.IsQO.
A model with quadratic constraints is referred to as a quadratically constrained program (MIQCP) if it is also a MIP, and as QCP otherwise. You can query whether the active model is quadratically constrained by calling the method Cplex.IsQC. A QCP may or may not have a quadratic objective; that is, a given problem may be both QP and QCP. Likewise, a MIQCP may or may not have a quadratic objective; that is, a given problem may be both MIQP and MIQCP.
If there are no quadratic terms in the objective, no integer constraints, and the problem is not quadratically constrained, it is called a linear program (LP).
If there are no quadratic terms in the objective, and the problem is not quadratically constrained, but there are integer variables, it is called a mixed integer linear program (MILP).
Special ordered sets (SOS) fall outside the conventional representation in terms of A and Q matrices and are stored separately.
Information related to the matrix representation of the model can be queried through these methods:
- Cplex.GetNcols for querying the number of columns of A,
- Cplex.GetNrows for querying the number of rows of A; that is, the number of linear constraints,
- Cplex.GetNQCs for querying the number of quadratic constraints,
- Cplex.GetNNZs for querying the number of nonzero elements in A, and
- Cplex.GetNSOSs for querying the number of SOSs.
Additional information about the active model can be obtained through enumerators defined on the different types of modeling objects.
Cplex effectively treats all models as MIQCP models. That is, it allows the most general case, although the solution algorithms make efficient use of special cases, such as the absence of quadratic terms in the formulation.
The method Cplex.Solve is used to solve the active model. It begins by solving the root relaxation of the MIQCP model, where all integrality constraints and SOSs are ignored. If the model has no integrality constraints or SOSs, then the optimization is complete once the root relaxation is solved. Otherwise, Cplex uses a branch and cut procedure to reintroduce the integrality constraints and SOS constraints. See the CPLEX User's Manual for more information about branch and cut.
Most users can simply call the method Cplex.Solve to solve their models. However, several parameters are available for users who require more control. Perhaps the most important one is Cplex.IntParam.RootAlg, which determines the algorithm used to solve the root relaxation. Possible settings, as defined in Cplex.Algorithm are:
- Cplex.Algorithm.AutoCplex automatically selects an algorithm. This is the default setting.
- Cplex.Algorithm.Primal Use the primal simplex algorithm.
- Cplex.Algorithm.Dual Use the dual simplex algorithm.
- Cplex.Algorithm.Network Use network simplex on the embedded network part of the model, followed by dual simplex on the entire model.
- Cplex.Algorithm.Barrier Use the barrier algorithm.
- Cplex.Algorithm.Sifting Use the sifting algorithm. This option is not available for quadratic problems. If selected nonetheless, Cplex defaults to the Cplex.Algorithm.Auto setting.
- Cplex.Algorithm.Concurrent Use several algorithms concurrently. This option is not available for quadratic problems. If selected nonetheless, Cplex defaults to the Cplex.Algorithm.Auto setting.
Numerous other parameters allow you to control algorithmic aspects of the optimizer. See Cplex.IntParam, Cplex.LongParam, Cplex.DoubleParam, Cplex.BooleanParam, and Cplex.StringParam for further information. Parameters are set with the method setParam.
Even higher levels of control can be achieved through the use of goals (see Cplex.Goal) or callbacks (see Cplex.Callback and its extensions).
The Cplex.Solve method returns a Boolean value reporting whether (true) or not (false) a solution (not necessarily the optimal one) has been found. Further information about the solution can be queried with the method getStatus. The return code of type Cplex.Status reports whether the solution is feasible, bounded, or optimal, or whether the model has been proven to be infeasible or unbounded. See Cplex.Status for more information.
The method Cplex.GetCplexStatus provides more detailed information about the status of the optimizer after Cplex.Solve returns. For example, it can provide information about why the optimizer terminated prematurely (time limit, iteration limit, or other limits). The methods Cplex.IsPrimalFeasible and Cplex.IsDualFeasible determine whether a primal or dual feasible solution has been found and can be queried.
The most important solution information computed by Cplex are usually the solution vector and the objective function value. The method Cplex.GetValue queries the solution vector and Cplex.GetObjValue queries the value of the objective function. Most optimizers also compute additional solution information. (for example, dual values, reduced costs, simplex bases, etc.) This additional information can also be queried through various methods of Cplex. If you attempt to retrieve solution information that is not available from a particular optimizer, Cplex will throw an exception.
If you are solving an LP and a basis is available, the solution can be further analyzed by performing sensitivity analysis. This information tells * you how sensitive the solution is with respect to changes in variable bounds, constraint bounds, or objective coefficients. The information is computed and accessed with the methods Cplex.GetBoundSA, Cplex.GetRangeSA, Cplex.GetRHSSA, and Cplex.GetObjSA.
An important consideration when you access solution information is the numeric quality of the solution. Since Cplex performs arithmetic operations using finite precision, solutions are always subject to numeric errors. For most problems, numeric errors are well within reasonable tolerances. However, for numerically difficult models, you are advised to verify the quality of the solution using the method Cplex.GetQuality, which offers a variety of quality measures.