CPXXaddindconstr and CPXaddindconstr
The routine CPXXaddindconstr/CPXaddindconstr adds an indicator constraint
to the specified problem object.
int CPXXaddindconstr( CPXCENVptr env, CPXLPptr lp, CPXDIM indvar, int complemented, CPXDIM nzcnt, double rhs, int sense, CPXDIM const * linind, double const * linval, char const * indname_str )
int CPXaddindconstr( CPXCENVptr env, CPXLPptr lp, int indvar, int complemented, int nzcnt, double rhs, int sense, int const * linind, double const * linval, char const * indname_str )
Description
The routine CPXXaddindconstr/CPXaddindconstr
adds an indicator constraint to the specified problem object. This routine may be called any time
after a call to CPXXcreateprob/CPXcreateprob.
An indicator constraint is a linear constraint that is enforced only:
- when an associated binary variable takes a value of 1, or
- when an associated binary variable takes the value of 0 (zero) if the binary variable is complemented.
The linear constraint may be a less-than-or-equal-to constraint, a greater-than-or-equal-to constraint, or an equality constraint.
sense |
= 'L' |
<= constraint |
sense |
= 'G' |
>= constraint |
sense |
= 'E' |
== constraint |
This routine adds only one indicator constraint at a time. Also, it
can add only one type of indicator constraint (an IF constraint, designated
in an LP format file as ->). When you want to add other types of
indicator constraints, such as IfOnly (<-) or IfAndOnlyIf (< - >), or
when you are building a model with many indicator constraints, you can use
CPXXaddindconstraints and CPXaddindconstraints.
Arguments
- env
-
A pointer to the CPLEX environment, as returned by
CPXXopenCPLEX/CPXopenCPLEX. - lp
-
A pointer to a CPLEX LP problem object, as returned by
CPXXcreateprob/CPXcreateprob. - indvar
- The binary variable that acts as the indicator for this constraint.
- complemented
- A Boolean value that specifies whether the indicator variable is complemented. The linear constraint must be satisfied when the indicator takes a value of 1 (one) if the indicator is not complemented, and similarly, the linear constraint must be satisfied when the indicator takes a value of 0 (zero) if the indicator is complemented.
- nzcnt
-
An integer that specifies the number of nonzero coefficients in the linear portion of the indicator constraint. This argument gives the length of the arrays
linindandlinval. - rhs
- The righthand side value for the linear portion of the indicator constraint.
- sense
- The sense of the linear portion of the indicator constraint. Specify 'L' for <= or 'G' for >= or 'E' for ==.
- linind
-
An array that with
linvaldefines the linear portion of the indicator constraint. - linval
-
An array that with
lininddefines the linear portion of the indicator constraint. The nonzero coefficients of the linear terms must be stored in sequential locations in the arrayslinindandlinvalfrom positions0tonzcnt-1. Each entry,linind[i], indicates the variable index of the corresponding coefficient,linval[i]. - indname_str
- The name of the constraint to be added. May be NULL, in which case the new constraint is assigned a default name if the indicator constraints already resident in the CPLEX problem object have names; otherwise, no name is associated with the constraint.
Return
The routine returns zero if successful and nonzero if an error occurs.Example
status = CPXaddindconstr (env, lp, indicator, complemented, nzcnt,
rhs, 'G', ind, val, newindname);