Scippy

SCIP

Solving Constraint Integer Programs

cons_sos2.c File Reference

Detailed Description

constraint handler for SOS type 2 constraints

Author
Marc Pfetsch

A specially ordered set of type 2 (SOS2) is a sequence of variables such that at most two variables are nonzero and if two variables are nonzero they must be adjacent in the specified sequence. Note that it is in principle allowed that a variable appears twice, but it then can be fixed to 0 if it is at least two apart in the sequence.

This constraint is useful when considering a piecewise affine approximation of a univariate (nonlinear) function $: [a,b] \rightarrow R$: Let $x_1 < \ldots < x_n$ be points in $[a,b]$ and introduce variables $\lambda_1, \ldots, \lambda_n$. To evaluate $f(x')$ at some point $x' \in [a,b]$ one can use the following constraints:

\[ \lambda_1 + \cdots + \lambda_n = 1,\quad x' = x_1 \lambda_1 + \cdots + x_n \lambda_n. \]

The value of $f(x')$ can the be approximated as

\[ f(x_1) \lambda_1 + \cdots + f(x_n) \lambda_n. \]

To get a valid piecewise affine approximation, $\lambda_1, \ldots, \lambda_n$ have to obey an SOS constraint of type 2.

This implementation of this constraint handler is based on classical ideas, see e.g.
"Special Facilities in General Mathematical Programming System for Non-Convex Problems Using Ordered Sets of Variables"
E. Beale and J. Tomlin, Proc. 5th IFORS Conference, 447-454 (1970)

The order of the variables is determined as follows:

  • If the constraint is created with SCIPcreateConsSOS2() and weights are given, the weights determine the order (decreasing weights). Additional variables can be added with SCIPaddVarSOS2(), which adds a variable with given weight.
  • If an empty constraint is created and then variables are added with SCIPaddVarSOS2(), weights are needed and stored.
  • All other calls ignore the weights, i.e., if a nonempty constraint is created or variables are added with SCIPappendVarSOS2().

Definition in file cons_sos2.c.

#include <assert.h>
#include "scip/cons_sos2.h"
#include "scip/cons_linear.h"
#include "scip/pub_misc.h"
#include <string.h>
#include <ctype.h>

Go to the source code of this file.

Macros

#define CONSHDLR_NAME   "SOS2"
 
#define CONSHDLR_DESC   "SOS2 constraint handler"
 
#define CONSHDLR_SEPAPRIORITY   10
 
#define CONSHDLR_ENFOPRIORITY   100
 
#define CONSHDLR_CHECKPRIORITY   -10
 
#define CONSHDLR_SEPAFREQ   0
 
#define CONSHDLR_PROPFREQ   1
 
#define CONSHDLR_EAGERFREQ   100
 
#define CONSHDLR_MAXPREROUNDS   -1
 
#define CONSHDLR_DELAYSEPA   FALSE
 
#define CONSHDLR_DELAYPROP   FALSE
 
#define CONSHDLR_DELAYPRESOL   FALSE
 
#define CONSHDLR_NEEDSCONS   TRUE
 
#define CONSHDLR_PROP_TIMING   SCIP_PROPTIMING_BEFORELP
 
#define EVENTHDLR_NAME   "SOS2"
 
#define EVENTHDLR_DESC   "bound change event handler for SOS2 constraints"
 

Functions

static SCIP_RETCODE fixVariableZeroNode (SCIP *scip, SCIP_VAR *var, SCIP_NODE *node, SCIP_Bool *infeasible)
 
static SCIP_RETCODE inferVariableZero (SCIP *scip, SCIP_VAR *var, SCIP_CONS *cons, int inferinfo, SCIP_Bool *infeasible, SCIP_Bool *tightened, SCIP_Bool *success)
 
static SCIP_RETCODE lockVariableSOS2 (SCIP *scip, SCIP_CONS *cons, SCIP_VAR *var)
 
static SCIP_RETCODE unlockVariableSOS2 (SCIP *scip, SCIP_CONS *cons, SCIP_VAR *var)
 
static SCIP_RETCODE consdataEnsurevarsSizeSOS2 (SCIP *scip, SCIP_CONSDATA *consdata, int num, SCIP_Bool reserveWeights)
 
static SCIP_RETCODE handleNewVariableSOS2 (SCIP *scip, SCIP_CONS *cons, SCIP_CONSDATA *consdata, SCIP_VAR *var, SCIP_Bool transformed)
 
static SCIP_RETCODE addVarSOS2 (SCIP *scip, SCIP_CONS *cons, SCIP_VAR *var, SCIP_Real weight)
 
static SCIP_RETCODE appendVarSOS2 (SCIP *scip, SCIP_CONS *cons, SCIP_VAR *var)
 
static SCIP_RETCODE deleteVarSOS2 (SCIP *scip, SCIP_CONS *cons, SCIP_CONSDATA *consdata, SCIP_EVENTHDLR *eventhdlr, int pos)
 
static SCIP_RETCODE presolRoundSOS2 (SCIP *scip, SCIP_CONS *cons, SCIP_CONSDATA *consdata, SCIP_EVENTHDLR *eventhdlr, SCIP_Bool *cutoff, SCIP_Bool *success, int *ndelconss, int *nfixedvars, int *nremovedvars)
 
static SCIP_RETCODE propSOS2 (SCIP *scip, SCIP_CONS *cons, SCIP_CONSDATA *consdata, SCIP_Bool *cutoff, int *nGen)
 
static SCIP_RETCODE enforceSOS2 (SCIP *scip, SCIP_CONSHDLR *conshdlr, int nconss, SCIP_CONS **conss, SCIP_RESULT *result)
 
static SCIP_RETCODE generateRowSOS2 (SCIP *scip, SCIP_CONSHDLR *conshdlr, SCIP_CONS *cons, SCIP_Bool local)
 
static SCIP_DECL_CONSHDLRCOPY (conshdlrCopySOS2)
 
static SCIP_DECL_CONSFREE (consFreeSOS2)
 
static SCIP_DECL_CONSEXITSOL (consExitsolSOS2)
 
static SCIP_DECL_CONSDELETE (consDeleteSOS2)
 
static SCIP_DECL_CONSTRANS (consTransSOS2)
 
static SCIP_DECL_CONSPRESOL (consPresolSOS2)
 
static SCIP_DECL_CONSINITLP (consInitlpSOS2)
 
static SCIP_DECL_CONSSEPALP (consSepalpSOS2)
 
static SCIP_DECL_CONSSEPASOL (consSepasolSOS2)
 
static SCIP_DECL_CONSENFOLP (consEnfolpSOS2)
 
static SCIP_DECL_CONSENFOPS (consEnfopsSOS2)
 
static SCIP_DECL_CONSCHECK (consCheckSOS2)
 
static SCIP_DECL_CONSPROP (consPropSOS2)
 
static SCIP_DECL_CONSRESPROP (consRespropSOS2)
 
static SCIP_DECL_CONSLOCK (consLockSOS2)
 
static SCIP_DECL_CONSPRINT (consPrintSOS2)
 
static SCIP_DECL_CONSCOPY (consCopySOS2)
 
static SCIP_DECL_CONSPARSE (consParseSOS2)
 
static SCIP_DECL_CONSGETVARS (consGetVarsSOS2)
 
static SCIP_DECL_CONSGETNVARS (consGetNVarsSOS2)
 
static SCIP_DECL_EVENTEXEC (eventExecSOS2)
 
SCIP_RETCODE SCIPincludeConshdlrSOS2 (SCIP *scip)
 
SCIP_RETCODE SCIPcreateConsSOS2 (SCIP *scip, SCIP_CONS **cons, const char *name, int nvars, SCIP_VAR **vars, SCIP_Real *weights, SCIP_Bool initial, SCIP_Bool separate, SCIP_Bool enforce, SCIP_Bool check, SCIP_Bool propagate, SCIP_Bool local, SCIP_Bool dynamic, SCIP_Bool removable, SCIP_Bool stickingatnode)
 
SCIP_RETCODE SCIPcreateConsBasicSOS2 (SCIP *scip, SCIP_CONS **cons, const char *name, int nvars, SCIP_VAR **vars, SCIP_Real *weights)
 
SCIP_RETCODE SCIPaddVarSOS2 (SCIP *scip, SCIP_CONS *cons, SCIP_VAR *var, SCIP_Real weight)
 
SCIP_RETCODE SCIPappendVarSOS2 (SCIP *scip, SCIP_CONS *cons, SCIP_VAR *var)
 
int SCIPgetNVarsSOS2 (SCIP *scip, SCIP_CONS *cons)
 
SCIP_VAR ** SCIPgetVarsSOS2 (SCIP *scip, SCIP_CONS *cons)
 
SCIP_RealSCIPgetWeightsSOS2 (SCIP *scip, SCIP_CONS *cons)
 

Macro Definition Documentation

#define CONSHDLR_DESC   "SOS2 constraint handler"

Definition at line 77 of file cons_sos2.c.

Referenced by SCIPincludeConshdlrSOS2().

#define CONSHDLR_SEPAPRIORITY   10

priority of the constraint handler for separation

Definition at line 78 of file cons_sos2.c.

Referenced by SCIPincludeConshdlrSOS2().

#define CONSHDLR_ENFOPRIORITY   100

priority of the constraint handler for constraint enforcing

Definition at line 79 of file cons_sos2.c.

Referenced by SCIPincludeConshdlrSOS2().

#define CONSHDLR_CHECKPRIORITY   -10

priority of the constraint handler for checking feasibility

Definition at line 80 of file cons_sos2.c.

Referenced by SCIPincludeConshdlrSOS2().

#define CONSHDLR_SEPAFREQ   0

frequency for separating cuts; zero means to separate only in the root node

Definition at line 81 of file cons_sos2.c.

Referenced by SCIPincludeConshdlrSOS2().

#define CONSHDLR_PROPFREQ   1

frequency for propagating domains; zero means only preprocessing propagation

Definition at line 82 of file cons_sos2.c.

Referenced by SCIPincludeConshdlrSOS2().

#define CONSHDLR_EAGERFREQ   100

frequency for using all instead of only the useful constraints in separation, propagation and enforcement, -1 for no eager evaluations, 0 for first only

Definition at line 83 of file cons_sos2.c.

Referenced by SCIPincludeConshdlrSOS2().

#define CONSHDLR_MAXPREROUNDS   -1

maximal number of presolving rounds the constraint handler participates in (-1: no limit)

Definition at line 85 of file cons_sos2.c.

Referenced by SCIPincludeConshdlrSOS2().

#define CONSHDLR_DELAYSEPA   FALSE

should separation method be delayed, if other separators found cuts?

Definition at line 86 of file cons_sos2.c.

Referenced by SCIPincludeConshdlrSOS2().

#define CONSHDLR_DELAYPROP   FALSE

should propagation method be delayed, if other propagators found reductions?

Definition at line 87 of file cons_sos2.c.

Referenced by SCIPincludeConshdlrSOS2().

#define CONSHDLR_DELAYPRESOL   FALSE

should presolving method be delayed, if other presolvers found reductions?

Definition at line 88 of file cons_sos2.c.

Referenced by SCIPincludeConshdlrSOS2().

#define CONSHDLR_NEEDSCONS   TRUE

should the constraint handler be skipped, if no constraints are available?

Definition at line 89 of file cons_sos2.c.

Referenced by SCIPincludeConshdlrSOS2().

#define CONSHDLR_PROP_TIMING   SCIP_PROPTIMING_BEFORELP

Definition at line 91 of file cons_sos2.c.

Referenced by SCIPincludeConshdlrSOS2().

#define EVENTHDLR_NAME   "SOS2"

Definition at line 94 of file cons_sos2.c.

Referenced by SCIP_DECL_EVENTEXEC(), and SCIPincludeConshdlrSOS2().

#define EVENTHDLR_DESC   "bound change event handler for SOS2 constraints"

Definition at line 95 of file cons_sos2.c.

Referenced by SCIPincludeConshdlrSOS2().

Function Documentation

static SCIP_RETCODE fixVariableZeroNode ( SCIP scip,
SCIP_VAR var,
SCIP_NODE node,
SCIP_Bool infeasible 
)
static

fix variable in given node to 0 or add constraint if variable is multi-aggregated

Parameters
scipSCIP pointer
varvariable to be fixed to 0
nodenode
infeasibleif fixing is infeasible

Definition at line 118 of file cons_sos2.c.

References FALSE, NULL, SCIP_CALL, SCIP_OKAY, SCIP_Real, SCIP_VARSTATUS_MULTAGGR, SCIPaddConsNode(), SCIPchgVarLbNode(), SCIPchgVarUbNode(), SCIPcreateConsLinear(), SCIPdebugMessage, SCIPisFeasNegative(), SCIPisFeasPositive(), SCIPisFeasZero(), SCIPreleaseCons(), SCIPvarGetLbLocal(), SCIPvarGetName(), SCIPvarGetStatus(), SCIPvarGetUbLocal(), and TRUE.

Referenced by enforceSOS2().

static SCIP_RETCODE inferVariableZero ( SCIP scip,
SCIP_VAR var,
SCIP_CONS cons,
int  inferinfo,
SCIP_Bool infeasible,
SCIP_Bool tightened,
SCIP_Bool success 
)
static

fix variable in local node to 0, and return whether the operation was feasible

Note
We do not add a linear constraint if the variable is multi-aggregated as in fixVariableZeroNode(), since this would be too time consuming.
Parameters
scipSCIP pointer
varvariable to be fixed to 0
consconstraint
inferinfoinfo for reverse prop.
infeasibleif fixing is infeasible
tightenedif fixing was performed
successwhether fixing was successful, i.e., variable is not multi-aggregated

Definition at line 169 of file cons_sos2.c.

References FALSE, SCIP_Bool, SCIP_CALL, SCIP_OKAY, SCIP_VARSTATUS_MULTAGGR, SCIPinferVarLbCons(), SCIPinferVarUbCons(), SCIPisFeasNegative(), SCIPisFeasPositive(), SCIPvarGetLbLocal(), SCIPvarGetStatus(), SCIPvarGetUbLocal(), and TRUE.

Referenced by propSOS2().

static SCIP_RETCODE lockVariableSOS2 ( SCIP scip,
SCIP_CONS cons,
SCIP_VAR var 
)
static

add lock on variable

Parameters
scipSCIP data structure
consconstraint
varvariable

Definition at line 212 of file cons_sos2.c.

References NULL, SCIP_CALL, SCIP_OKAY, SCIPisFeasNegative(), SCIPisFeasPositive(), SCIPlockVarCons(), SCIPvarGetLbLocal(), and SCIPvarGetUbLocal().

Referenced by handleNewVariableSOS2(), and presolRoundSOS2().

static SCIP_RETCODE unlockVariableSOS2 ( SCIP scip,
SCIP_CONS cons,
SCIP_VAR var 
)
static
Parameters
scipSCIP data structure
consconstraint
varvariable

Definition at line 231 of file cons_sos2.c.

References NULL, SCIP_CALL, SCIP_OKAY, SCIPisFeasNegative(), SCIPisFeasPositive(), SCIPunlockVarCons(), SCIPvarGetLbLocal(), and SCIPvarGetUbLocal().

Referenced by deleteVarSOS2(), and presolRoundSOS2().

static SCIP_RETCODE consdataEnsurevarsSizeSOS2 ( SCIP scip,
SCIP_CONSDATA consdata,
int  num,
SCIP_Bool  reserveWeights 
)
static

ensures that the vars and weights array can store at least num entries

Parameters
scipSCIP data structure
consdataconstraint data
numminimum number of entries to store
reserveWeightswhether the weights array is handled

Definition at line 250 of file cons_sos2.c.

References NULL, SCIP_CALL, SCIP_OKAY, SCIPcalcMemGrowSize(), and SCIPreallocBlockMemoryArray.

Referenced by addVarSOS2(), and appendVarSOS2().

static SCIP_RETCODE handleNewVariableSOS2 ( SCIP scip,
SCIP_CONS cons,
SCIP_CONSDATA consdata,
SCIP_VAR var,
SCIP_Bool  transformed 
)
static

handle new variable

Parameters
scipSCIP data structure
consconstraint
consdataconstraint data
varvariable
transformedwhether original variable was transformed

Definition at line 278 of file cons_sos2.c.

References lockVariableSOS2(), NULL, SCIP_CALL, SCIP_EVENTTYPE_BOUNDCHANGED, SCIP_OKAY, SCIPaddVarToRow(), SCIPcatchVarEvent(), SCIPchgRowLhs(), SCIPchgRowRhs(), SCIPconsGetHdlr(), SCIPconshdlrGetData(), SCIPisFeasGT(), SCIPisFeasLT(), SCIPisFeasNegative(), SCIPisFeasPositive(), SCIProwGetLhs(), SCIProwGetRhs(), SCIPvarGetLbLocal(), and SCIPvarGetUbLocal().

Referenced by addVarSOS2(), and appendVarSOS2().

static SCIP_RETCODE addVarSOS2 ( SCIP scip,
SCIP_CONS cons,
SCIP_VAR var,
SCIP_Real  weight 
)
static

adds a variable to an SOS2 constraint, a position given by weight - ascending order

Parameters
scipSCIP data structure
consconstraint
varvariable to add to the constraint
weightweight to determine position

Definition at line 335 of file cons_sos2.c.

References consdataEnsurevarsSizeSOS2(), handleNewVariableSOS2(), NULL, SCIP_Bool, SCIP_CALL, SCIP_INVALIDCALL, SCIP_OKAY, SCIPconsGetData(), SCIPconsGetName(), SCIPconsIsTransformed(), SCIPerrorMessage, SCIPgetTransformedVar(), SCIPvarIsTransformed(), and TRUE.

Referenced by SCIPaddVarSOS2().

static SCIP_RETCODE appendVarSOS2 ( SCIP scip,
SCIP_CONS cons,
SCIP_VAR var 
)
static

appends a variable to an SOS2 constraint

Parameters
scipSCIP data structure
consconstraint
varvariable to add to the constraint

Definition at line 403 of file cons_sos2.c.

References consdataEnsurevarsSizeSOS2(), FALSE, handleNewVariableSOS2(), NULL, SCIP_Bool, SCIP_CALL, SCIP_OKAY, SCIPconsGetData(), SCIPconsIsTransformed(), SCIPgetTransformedVar(), and SCIPvarIsTransformed().

Referenced by SCIPappendVarSOS2().

static SCIP_RETCODE deleteVarSOS2 ( SCIP scip,
SCIP_CONS cons,
SCIP_CONSDATA consdata,
SCIP_EVENTHDLR eventhdlr,
int  pos 
)
static

deletes a variable of an SOS2 constraint

Parameters
scipSCIP data structure
consconstraint
consdataconstraint data
eventhdlrcorresponding event handler
posposition of variable in array

Definition at line 447 of file cons_sos2.c.

References NULL, SCIP_CALL, SCIP_EVENTTYPE_BOUNDCHANGED, SCIP_OKAY, SCIPdropVarEvent(), and unlockVariableSOS2().

Referenced by presolRoundSOS2().

static SCIP_RETCODE presolRoundSOS2 ( SCIP scip,
SCIP_CONS cons,
SCIP_CONSDATA consdata,
SCIP_EVENTHDLR eventhdlr,
SCIP_Bool cutoff,
SCIP_Bool success,
int *  ndelconss,
int *  nfixedvars,
int *  nremovedvars 
)
static

perform one presolving round

We perform the following presolving steps.

  • If the bounds of one variable force it to be nonzero, we can fix all other variables with distance at least two to zero. If two variables are certain to be nonzero, we can fix all other variables to 0 and remove the constraint.
  • All variables fixed to zero, that are at the beginning or end of the constraint can be removed.
  • We substitute appregated variables.
  • If a constraint has at most two variables, we delete it.

We currently do not handle the following:

  • If we have at least two variables fixed to zero next to each-other, that are positioned in the inner part of this constraint, we can delete all but one of these variables.
  • If a variable appears twice not next to each-other, it can be fixed to 0. If one variable appears next to each-other and is already certain to be nonzero, we can fix all variables.
  • If a binary variable and its negation appear in the constraint, we might fix variables to zero or can forbid a zero value for them.
  • When, after removing all zero "border" variables, a constraint with more than two variables has at most two variables that are not fixed to 0, only one of these can take a nonzero value, because these variables need to be the "border" variables of this constraint. The same holds if we have exactly three variables in one constraint and the middle variable is certain to be not zero. In both cases we can upgrade this constraint constraint to an sos1 consisting only of the "border" variables. If these "border" variables are negations of each other, we can delete this constraint.
  • When, after removing all variables fixed to 0, that are possible, in a constraint each even positioned variable is fixed to 0, we can upgrade this constraint to an sos1 that holds all non-fixed variables.
  • Extract cliques for all odd and also for all even positioned binary variables
Parameters
scipSCIP pointer
consconstraint
consdataconstraint data
eventhdlrevent handler
cutoffwhether a cutoff happened
successwhether we performed a successful reduction
ndelconssnumber of deleted constraints
nfixedvarsnumber of fixed variables
nremovedvarsnumber of variables removed

Definition at line 507 of file cons_sos2.c.

References deleteVarSOS2(), FALSE, lockVariableSOS2(), NULL, SCIP_Bool, SCIP_CALL, SCIP_EVENTTYPE_BOUNDCHANGED, SCIP_OKAY, SCIP_Real, SCIPcatchVarEvent(), SCIPconsGetName(), SCIPconsIsModifiable(), SCIPdebugMessage, SCIPdelCons(), SCIPdropVarEvent(), SCIPfixVar(), SCIPgetProbvarSum(), SCIPisFeasNegative(), SCIPisFeasPositive(), SCIPisFeasZero(), SCIPisZero(), SCIPvarGetLbGlobal(), SCIPvarGetLbLocal(), SCIPvarGetName(), SCIPvarGetUbGlobal(), SCIPvarGetUbLocal(), TRUE, and unlockVariableSOS2().

Referenced by SCIP_DECL_CONSPRESOL().

static SCIP_RETCODE propSOS2 ( SCIP scip,
SCIP_CONS cons,
SCIP_CONSDATA consdata,
SCIP_Bool cutoff,
int *  nGen 
)
static

propagate variables

Parameters
scipSCIP pointer
consconstraint
consdataconstraint data
cutoffwhether a cutoff happened
nGennumber of domain changes

Definition at line 788 of file cons_sos2.c.

References FALSE, inferVariableZero(), NULL, SCIP_Bool, SCIP_CALL, SCIP_OKAY, SCIPconsGetName(), SCIPconsIsModifiable(), SCIPdebugMessage, SCIPdelConsLocal(), SCIPisFeasNegative(), SCIPisFeasPositive(), SCIPresetConsAge(), SCIPvarGetLbLocal(), SCIPvarGetName(), SCIPvarGetUbLocal(), and TRUE.

Referenced by enforceSOS2(), and SCIP_DECL_CONSPROP().

static SCIP_RETCODE enforceSOS2 ( SCIP scip,
SCIP_CONSHDLR conshdlr,
int  nconss,
SCIP_CONS **  conss,
SCIP_RESULT result 
)
static

enforcement method

We check whether the current solution is feasible, i.e., contains at most one nonzero variable. If not, we branch along the lines indicated by Beale and Tomlin:

We first compute $W = \sum_{j=1}^n |x_i|$ and $w = \sum_{j=1}^n j\, |x_i|$. Then we search for the index $k$ that satisfies

\[ k \leq \frac{w}{W} < k+1. \]

The branches are then

\[ x_1 = 0, \ldots, x_{k-1} = 0 \qquad \mbox{and}\qquad x_{k+1} = 0, \ldots, x_n = 0. \]

There is one special case that we have to consider: It can happen that $k$ is one too small. Example: $x_1 = 1 - \epsilon, x_2 = 0, x_3 = \epsilon$. Then $w = 1 - \epsilon + 3 \epsilon = 1 + 2 \epsilon$. This yields $k = 1$ and hence the first branch does not change the solution. We therefore increase $k$ by one if $x_k \neq 0$. This is valid, since we know that $x_{k+1} \neq 0$ (with respect to the original $k$); the corresponding branch will cut off the current solution, since $x_k \neq 0$.

Parameters
scipSCIP pointer
conshdlrconstraint handler
nconssnumber of constraints
conssindicator constraints
resultresult

Definition at line 984 of file cons_sos2.c.

References branchCons(), fixVariableZeroNode(), NULL, propSOS2(), REALABS, SCIP_Bool, SCIP_BRANCHDIR_DOWNWARDS, SCIP_BRANCHED, SCIP_CALL, SCIP_CUTOFF, SCIP_FEASIBLE, SCIP_OKAY, SCIP_Real, SCIP_REDUCEDDOM, SCIPcalcChildEstimate(), SCIPcalcNodeselPriority(), SCIPconsGetData(), SCIPconsGetName(), SCIPconshdlrGetName(), SCIPcreateChild(), SCIPdebugMessage, SCIPfeasFloor(), SCIPgetSolVal(), SCIPisFeasZero(), SCIPresetConsAge(), and SCIPvarGetName().

Referenced by SCIP_DECL_CONSENFOLP(), and SCIP_DECL_CONSENFOPS().

static SCIP_RETCODE generateRowSOS2 ( SCIP scip,
SCIP_CONSHDLR conshdlr,
SCIP_CONS cons,
SCIP_Bool  local 
)
static

Generate basic row

We generate the row corresponding to the following simple valid inequalities. Let $U$ and $U'$ be the largest and second largest upper bound of variables appearing in the constraint. Similarly let $L$ and $L'$ be the smallest and second smallest lower bound. The inequalities are:

\[ x_1 + \ldots + x_n \leq U + U' \qquad\mbox{and}\qquad x_1 + \ldots + x_n \geq L + L'. \]

Of course, these inequalities are only added if the upper and lower bounds are all finite and $L+L' < 0$ or $U+U' > 0$.

Parameters
scipSCIP pointer
conshdlrconstraint handler
consconstraint
localproduce local cut?

Definition at line 1187 of file cons_sos2.c.

References FALSE, NULL, REALABS, SCIP_CALL, SCIP_MAXSTRLEN, SCIP_OKAY, SCIP_Real, SCIPaddVarsToRowSameCoef(), SCIPconsGetData(), SCIPconsGetName(), SCIPcreateEmptyRowCons(), SCIPdebug, SCIPinfinity(), SCIPisFeasZero(), SCIPisInfinity(), SCIPprintRow(), SCIPsnprintf(), SCIPvarGetLbGlobal(), SCIPvarGetLbLocal(), SCIPvarGetUbGlobal(), and SCIPvarGetUbLocal().

Referenced by SCIP_DECL_CONSINITLP(), SCIP_DECL_CONSSEPALP(), and SCIP_DECL_CONSSEPASOL().

static SCIP_DECL_CONSHDLRCOPY ( conshdlrCopySOS2  )
static

copy method for constraint handler plugins (called when SCIP copies plugins)

Definition at line 1286 of file cons_sos2.c.

References CONSHDLR_NAME, NULL, SCIP_CALL, SCIP_OKAY, SCIPconshdlrGetName(), SCIPincludeConshdlrSOS2(), and TRUE.

static SCIP_DECL_CONSFREE ( consFreeSOS2  )
static

destructor of constraint handler to free constraint handler data (called when SCIP is exiting)

Definition at line 1303 of file cons_sos2.c.

References CONSHDLR_NAME, NULL, SCIP_OKAY, SCIPconshdlrGetData(), SCIPconshdlrGetName(), and SCIPfreeMemory.

static SCIP_DECL_CONSEXITSOL ( consExitsolSOS2  )
static

solving process deinitialization method of constraint handler (called before branch and bound process data is freed)

Definition at line 1322 of file cons_sos2.c.

References CONSHDLR_NAME, NULL, SCIP_CALL, SCIP_OKAY, SCIPconsGetData(), SCIPconsGetName(), SCIPconshdlrGetName(), SCIPdebugMessage, and SCIPreleaseRow().

static SCIP_DECL_CONSPRESOL ( consPresolSOS2  )
static
static SCIP_DECL_CONSINITLP ( consInitlpSOS2  )
static

LP initialization method of constraint handler (called before the initial LP relaxation at a node is solved)

Definition at line 1557 of file cons_sos2.c.

References CONSHDLR_NAME, FALSE, generateRowSOS2(), NULL, REALABS, SCIP_Bool, SCIP_CALL, SCIP_OKAY, SCIPaddCut(), SCIPconsGetData(), SCIPconsGetName(), SCIPconshdlrGetName(), SCIPdebug, SCIPdebugMessage, SCIPisInfinity(), SCIPprintRow(), SCIProwGetLhs(), SCIProwGetRhs(), and SCIProwIsInLP().

static SCIP_DECL_CONSSEPALP ( consSepalpSOS2  )
static
static SCIP_DECL_CONSSEPASOL ( consSepasolSOS2  )
static
static SCIP_DECL_CONSENFOLP ( consEnfolpSOS2  )
static

constraint enforcing method of constraint handler for LP solutions

Definition at line 1714 of file cons_sos2.c.

References CONSHDLR_NAME, enforceSOS2(), NULL, SCIP_CALL, SCIP_OKAY, and SCIPconshdlrGetName().

static SCIP_DECL_CONSENFOPS ( consEnfopsSOS2  )
static

constraint enforcing method of constraint handler for pseudo solutions

Definition at line 1730 of file cons_sos2.c.

References CONSHDLR_NAME, enforceSOS2(), NULL, SCIP_CALL, SCIP_OKAY, and SCIPconshdlrGetName().

static SCIP_DECL_CONSCHECK ( consCheckSOS2  )
static

feasibility check method of constraint handler for integral solutions

We simply check whether at most two variable are nonzero and in the case there are exactly two nonzero, then they have to be direct neighbors in the given solution.

Definition at line 1751 of file cons_sos2.c.

References CONSHDLR_NAME, NULL, SCIP_CALL, SCIP_FEASIBLE, SCIP_INFEASIBLE, SCIP_OKAY, SCIPconsGetData(), SCIPconsGetName(), SCIPconshdlrGetName(), SCIPdebugMessage, SCIPgetSolVal(), SCIPinfoMessage(), SCIPisFeasZero(), SCIPprintCons(), SCIPresetConsAge(), and SCIPvarGetName().

static SCIP_DECL_CONSPROP ( consPropSOS2  )
static
static SCIP_DECL_CONSRESPROP ( consRespropSOS2  )
static

propagation conflict resolving method of constraint handler

We check which bound changes were the reason for infeasibility. We use that inferinfo stores the index of the variable that has bounds that fix it to be nonzero (these bounds are the reason).

Definition at line 1867 of file cons_sos2.c.

References CONSHDLR_NAME, FALSE, NULL, SCIP_CALL, SCIP_DIDNOTFIND, SCIP_OKAY, SCIP_SUCCESS, SCIPaddConflictLb(), SCIPaddConflictUb(), SCIPconsGetData(), SCIPconsGetName(), SCIPconshdlrGetName(), SCIPdebugMessage, SCIPisFeasNegative(), SCIPisFeasPositive(), SCIPvarGetLbAtIndex(), and SCIPvarGetUbAtIndex().

static SCIP_DECL_CONSLOCK ( consLockSOS2  )
static

variable rounding lock method of constraint handler

Let lb and ub be the lower and upper bounds of a variable. Preprocessing usually makes sure that lb <= 0 <= ub.

  • If lb < 0 then rounding down may violate the constraint.
  • If ub > 0 then rounding up may violated the constraint.
  • If lb > 0 or ub < 0 then the constraint is infeasible and we do not have to deal with it here.
  • If lb == 0 then rounding down does not violate the constraint.
  • If ub == 0 then rounding up does not violate the constraint.

Definition at line 1919 of file cons_sos2.c.

References CONSHDLR_NAME, NULL, SCIP_CALL, SCIP_OKAY, SCIPaddVarLocks(), SCIPconsGetData(), SCIPconsGetName(), SCIPconshdlrGetName(), SCIPdebugMessage, SCIPisFeasNegative(), SCIPisFeasPositive(), SCIPvarGetLbLocal(), and SCIPvarGetUbLocal().

static SCIP_DECL_CONSPRINT ( consPrintSOS2  )
static

constraint display method of constraint handler

Definition at line 1959 of file cons_sos2.c.

References CONSHDLR_NAME, FALSE, NULL, SCIP_CALL, SCIP_OKAY, SCIPconsGetData(), SCIPconshdlrGetName(), SCIPinfoMessage(), and SCIPwriteVarName().

static SCIP_DECL_CONSCOPY ( consCopySOS2  )
static
static SCIP_DECL_CONSPARSE ( consParseSOS2  )
static

constraint parsing method of constraint handler

Definition at line 2055 of file cons_sos2.c.

References FALSE, NULL, SCIP_CALL, SCIP_OKAY, SCIP_Real, SCIP_VERBLEVEL_MINIMAL, SCIPaddVarSOS2(), SCIPcreateConsSOS2(), SCIPparseVarName(), SCIPverbMessage(), and TRUE.

static SCIP_DECL_CONSGETVARS ( consGetVarsSOS2  )
static

constraint method of constraint handler which returns the variables (if possible)

Definition at line 2113 of file cons_sos2.c.

References BMScopyMemoryArray, FALSE, NULL, SCIP_OKAY, SCIPconsGetData(), and TRUE.

static SCIP_DECL_CONSGETNVARS ( consGetNVarsSOS2  )
static

constraint method of constraint handler which returns the number of variables (if possible)

Definition at line 2136 of file cons_sos2.c.

References NULL, SCIP_OKAY, SCIPconsGetData(), and TRUE.

SCIP_RETCODE SCIPcreateConsSOS2 ( SCIP scip,
SCIP_CONS **  cons,
const char *  name,
int  nvars,
SCIP_VAR **  vars,
SCIP_Real weights,
SCIP_Bool  initial,
SCIP_Bool  separate,
SCIP_Bool  enforce,
SCIP_Bool  check,
SCIP_Bool  propagate,
SCIP_Bool  local,
SCIP_Bool  dynamic,
SCIP_Bool  removable,
SCIP_Bool  stickingatnode 
)

creates and captures a SOS2 constraint

We set the constraint to not be modifable. If the weights are non NULL, the variables are ordered according to these weights (in ascending order).

Note
the constraint gets captured, hence at one point you have to release it using the method SCIPreleaseCons()
Parameters
scipSCIP data structure
conspointer to hold the created constraint
namename of constraint
nvarsnumber of variables in the constraint
varsarray with variables of constraint entries
weightsweights determining the variable order, or NULL if natural order should be used
initialshould the LP relaxation of constraint be in the initial LP? Usually set to TRUE. Set to FALSE for 'lazy constraints'.
separateshould the constraint be separated during LP processing? Usually set to TRUE.
enforceshould the constraint be enforced during node processing? TRUE for model constraints, FALSE for additional, redundant constraints.
checkshould the constraint be checked for feasibility? TRUE for model constraints, FALSE for additional, redundant constraints.
propagateshould the constraint be propagated during node processing? Usually set to TRUE.
localis constraint only valid locally? Usually set to FALSE. Has to be set to TRUE, e.g., for branching constraints.
dynamicis constraint subject to aging? Usually set to FALSE. Set to TRUE for own cuts which are separated as constraints.
removableshould the relaxation be removed from the LP due to aging or cleanup? Usually set to FALSE. Set to TRUE for 'lazy constraints' and 'user cuts'.
stickingatnodeshould the constraint always be kept at the node where it was added, even if it may be moved to a more global node? Usually set to FALSE. Set to TRUE to for constraints that represent node data.

Definition at line 2268 of file cons_sos2.c.

References CONSHDLR_NAME, FALSE, NULL, SCIP_Bool, SCIP_CALL, SCIP_OKAY, SCIP_PLUGINNOTFOUND, SCIPallocBlockMemory, SCIPcreateCons(), SCIPduplicateBlockMemoryArray, SCIPerrorMessage, SCIPfindConshdlr(), and SCIPsortRealPtr().

Referenced by readSOS(), readSos(), readSOScons(), SCIP_DECL_CONSCOPY(), SCIP_DECL_CONSPARSE(), and SCIPcreateConsBasicSOS2().

SCIP_RETCODE SCIPcreateConsBasicSOS2 ( SCIP scip,
SCIP_CONS **  cons,
const char *  name,
int  nvars,
SCIP_VAR **  vars,
SCIP_Real weights 
)

creates and captures a SOS2 constraint with all constraint flags set to their default values.

Warning
Do NOT set the constraint to be modifiable manually, because this might lead to wrong results as the variable array will not be resorted
Note
the constraint gets captured, hence at one point you have to release it using the method SCIPreleaseCons()
Parameters
scipSCIP data structure
conspointer to hold the created constraint
namename of constraint
nvarsnumber of variables in the constraint
varsarray with variables of constraint entries
weightsweights determining the variable order, or NULL if natural order should be used

Definition at line 2351 of file cons_sos2.c.

References FALSE, SCIP_CALL, SCIP_OKAY, SCIPcreateConsSOS2(), and TRUE.

SCIP_RETCODE SCIPaddVarSOS2 ( SCIP scip,
SCIP_CONS cons,
SCIP_VAR var,
SCIP_Real  weight 
)

adds variable to SOS2 constraint, the position is determined by the given weight

Parameters
scipSCIP data structure
consconstraint
varvariable to add to the constraint
weightweight determining position of variable

Definition at line 2367 of file cons_sos2.c.

References addVarSOS2(), CONSHDLR_NAME, NULL, SCIP_CALL, SCIP_INVALIDDATA, SCIP_OKAY, SCIPconsGetHdlr(), SCIPconsGetName(), SCIPconshdlrGetName(), SCIPdebugMessage, SCIPerrorMessage, and SCIPvarGetName().

Referenced by readSOS(), readSos(), readSOScons(), and SCIP_DECL_CONSPARSE().

SCIP_RETCODE SCIPappendVarSOS2 ( SCIP scip,
SCIP_CONS cons,
SCIP_VAR var 
)

appends variable to SOS2 constraint

Parameters
scipSCIP data structure
consconstraint
varvariable to add to the constraint

Definition at line 2393 of file cons_sos2.c.

References appendVarSOS2(), CONSHDLR_NAME, NULL, SCIP_CALL, SCIP_INVALIDDATA, SCIP_OKAY, SCIPconsGetHdlr(), SCIPconsGetName(), SCIPconshdlrGetName(), SCIPdebugMessage, SCIPerrorMessage, and SCIPvarGetName().

int SCIPgetNVarsSOS2 ( SCIP scip,
SCIP_CONS cons 
)

gets number of variables in SOS2 constraint

Parameters
scipSCIP data structure
consconstraint

Definition at line 2418 of file cons_sos2.c.

References CONSHDLR_NAME, NULL, SCIPABORT, SCIPconsGetData(), SCIPconsGetHdlr(), SCIPconshdlrGetName(), and SCIPerrorMessage.

Referenced by SCIP_DECL_READERWRITE(), SCIPwriteGms(), and SCIPwriteLp().

SCIP_VAR** SCIPgetVarsSOS2 ( SCIP scip,
SCIP_CONS cons 
)

gets array of variables in SOS2 constraint

Parameters
scipSCIP data structure
consconstraint data

Definition at line 2443 of file cons_sos2.c.

References CONSHDLR_NAME, NULL, SCIPABORT, SCIPconsGetData(), SCIPconsGetHdlr(), SCIPconshdlrGetName(), and SCIPerrorMessage.

Referenced by SCIP_DECL_READERWRITE(), SCIPwriteGms(), and SCIPwriteLp().

SCIP_Real* SCIPgetWeightsSOS2 ( SCIP scip,
SCIP_CONS cons 
)

gets array of weights in SOS2 constraint (or NULL if not existent)

Parameters
scipSCIP data structure
consconstraint data

Definition at line 2468 of file cons_sos2.c.

References CONSHDLR_NAME, NULL, SCIPABORT, SCIPconsGetData(), SCIPconsGetHdlr(), SCIPconshdlrGetName(), and SCIPerrorMessage.

Referenced by SCIP_DECL_READERWRITE(), and SCIPwriteLp().