Cplex
is the class used to create and solve a large variety of Mathematical Programming models.
For a list of all members of this type, see Cplex Members.
System.Object
ILOG.CPLEX.CplexModeler
ILOG.CPLEX.Cplex
Public static (Shared in Visual Basic) members of this type are safe for multithreaded operations. Instance members are not guaranteed to be thread-safe.
Such models include:
This class implements the modeling interface IMPModeler
and its base interfaces. See the ILOG CPLEX User's Manual for more information about modeling.
Models to be solved by Cplex
should be built by the IMPModeler
(and base interface) methods to construct objects from the following list:
INumVar
and its extensions IIntVar
, IloBoolVar
, and ISemiContVar
IRange
with (piecewise) linear or quadratic expressionsIConstraint
of the form expr1 relation expr2, where both expressions are linear or quadratic and may optionally contain piecewise linear terms.ILPMatrix
IObjective
with a (piecewise) linear and/or quadratic expressionsIConversion
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 ILOG 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 SOS
s.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 ILOG 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.Auto
Cplex
automatically selects an algorithm. This is the default setting.Cplex.Algorithm.Primal
Cplex.Algorithm.Dual
Cplex.Algorithm.Network
Cplex.Algorithm.Barrier
Cplex.Algorithm.Sifting
Cplex
defaults to the Cplex.Algorithm.Auto
setting.Cplex.Algorithm.Concurrent
Cplex
defaults to the Cplex.Algorithm.Auto
setting.Numerous other parameters allow you to control algorithmic aspects of the optimizer. See Cplex.IntParam
, Cplex.DoubleParam
, Cplex.BooleanParam
, and Cplex.StringParam
for further information. Parameters are set with the method Cplex.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 solve
method returns a Boolean value indicating 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
indicates whether the solution is feasible, bounded, or optimal, or if 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.
Namespace: ILOG.CPLEX
Assembly: ILOG.CPLEX (in ILOG.CPLEX.dll)