Cplex is the class used to create and solve LP (linear program), QP (program with quadratic terms in the objective function), QCP (quadratically constrained program), and MIP (mixed integer program) Mathematical Programming models.

Namespace: ILOG.OPL
Assembly: oplall (in oplall.dll)

Syntax

C#
public class Cplex : IloModelerAdvImpl, IMPModeler, 
	IModeler, IModel, IAddable, ICopyable, IModelerAdv

Remarks

This class implements the IMPModeler modeling interface and its base interfaces. See the IBM ILOG Cplex User's Manual for more information about modeling.

Models to be solved by Cplex should be built using the IMPModeler (and base interface) methods to construct objects from the following list:

  • variables: objects of type INumVar and its extensions IIntVar, IBoolVar, and ISemiContVar
  • range constraints: objects of type IloRange 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 correponding linear terms. For more about the Q_i, see the chapter about QCP in the IBM 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 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 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 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 iterators 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 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 IBM ILOG Cplex User's Manual for more information about branch and cut.

Most users can simply call 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
    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 IntParam, DoubleParam, and 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 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 GetCplexStatus()()()() provides more detailed information about the status of the optimizer after Solve()()()() returns. For example, it can provide information about why the optimizer terminated prematurely (time limit, iteration limit, etc.). The methods IsPrimalFeasible and IsDualFeasible can be used to 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. These can be queried with the methods GetValue(INumExpr) and GetObjValue(Int32), respectively. 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 retrive 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 GetBoundSA(array<Double>[]()[][], array<Double>[]()[][], array<Double>[]()[][], array<Double>[]()[][], ILPMatrix), GetRangeSA(array<Double>[]()[][], array<Double>[]()[][], array<Double>[]()[][], array<Double>[]()[][], ILPMatrix), GetRHSSA(array<Double>[]()[][], array<Double>[]()[][], ILPMatrix), and GetObjSA(array<Double>[]()[][], array<Double>[]()[][], array<INumVar>[]()[][]).

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 GetQuality(Cplex..::..QualityType), which offers a variety of quality measures.

Inheritance Hierarchy

System..::..Object
  IloModelImpl
    IloModelerImpl
      IloModelerAdvImpl
        ILOG.OPL..::..Cplex

See Also