constraint handler for cardinality constraints
This constraint handler handles cardinality constraints of the form
\[ |\mbox{supp}(x)| \leq b \]
with integer right-hand side \(b\). Here, \(|\mbox{supp}(x)|\) denotes the number of nonzero entries of the vector \(x\).
Note that cardinality constraints generalize special ordered set of type one (SOS1) constraints in which \(b = 1\).
The implementation of this constraint handler is based on
"On the Structure of Linear Programs with Overlapping Cardinality Constraints"
T. Fischer and M. E. Pfetsch, Tech. rep., 2016
Definition in file cons_cardinality.c.
#include <assert.h>
#include "scip/cons_cardinality.h"
#include "scip/cons_linear.h"
#include "scip/cons_knapsack.h"
#include <string.h>
#include <ctype.h>
Go to the source code of this file.
Macros | |
#define | CONSHDLR_NAME "cardinality" |
#define | CONSHDLR_DESC "cardinality constraint handler" |
#define | CONSHDLR_SEPAPRIORITY 10 |
#define | CONSHDLR_ENFOPRIORITY 100 |
#define | CONSHDLR_CHECKPRIORITY -10 |
#define | CONSHDLR_SEPAFREQ 10 |
#define | CONSHDLR_PROPFREQ 1 |
#define | CONSHDLR_EAGERFREQ 100 |
#define | CONSHDLR_MAXPREROUNDS -1 |
#define | CONSHDLR_DELAYSEPA FALSE |
#define | CONSHDLR_DELAYPROP FALSE |
#define | CONSHDLR_NEEDSCONS TRUE |
#define | CONSHDLR_PROP_TIMING SCIP_PROPTIMING_BEFORELP |
#define | CONSHDLR_PRESOLTIMING SCIP_PRESOLTIMING_FAST |
#define | DEFAULT_BRANCHBALANCED FALSE |
#define | DEFAULT_BALANCEDDEPTH 20 |
#define | DEFAULT_BALANCEDCUTOFF 2.0 |
#define | EVENTHDLR_NAME "cardinality" |
#define | EVENTHDLR_DESC "bound change event handler for cardinality constraints" |
Functions | |
static SCIP_RETCODE | catchVarEventCardinality (SCIP *scip, SCIP_EVENTHDLR *eventhdlr, SCIP_CONSDATA *consdata, SCIP_VAR *var, SCIP_VAR *indvar, int pos, SCIP_EVENTDATA **eventdata) |
static SCIP_RETCODE | dropVarEventCardinality (SCIP *scip, SCIP_EVENTHDLR *eventhdlr, SCIP_CONSDATA *consdata, SCIP_VAR *var, SCIP_VAR *indvar, SCIP_EVENTDATA **eventdata) |
static SCIP_RETCODE | fixVariableZeroNode (SCIP *scip, SCIP_VAR *var, SCIP_NODE *node, SCIP_Bool *infeasible) |
static SCIP_RETCODE | fixVariableZero (SCIP *scip, SCIP_VAR *var, SCIP_Bool *infeasible, SCIP_Bool *tightened) |
static SCIP_RETCODE | lockVariableCardinality (SCIP *scip, SCIP_CONS *cons, SCIP_VAR *var, SCIP_VAR *indvar) |
static SCIP_RETCODE | unlockVariableCardinality (SCIP *scip, SCIP_CONS *cons, SCIP_VAR *var, SCIP_VAR *indvar) |
static SCIP_RETCODE | consdataEnsurevarsSizeCardinality (SCIP *scip, SCIP_CONSDATA *consdata, int num, SCIP_Bool reserveweights) |
static SCIP_RETCODE | handleNewVariableCardinality (SCIP *scip, SCIP_CONS *cons, SCIP_CONSDATA *consdata, SCIP_CONSHDLRDATA *conshdlrdata, SCIP_VAR *var, SCIP_VAR *indvar, int pos, SCIP_Bool transformed, SCIP_EVENTDATA **eventdata) |
static SCIP_RETCODE | addVarCardinality (SCIP *scip, SCIP_CONS *cons, SCIP_CONSHDLRDATA *conshdlrdata, SCIP_VAR *var, SCIP_VAR *indvar, SCIP_Real weight) |
static SCIP_RETCODE | appendVarCardinality (SCIP *scip, SCIP_CONS *cons, SCIP_CONSHDLRDATA *conshdlrdata, SCIP_VAR *var, SCIP_VAR *indvar) |
static SCIP_RETCODE | deleteVarCardinality (SCIP *scip, SCIP_CONS *cons, SCIP_CONSDATA *consdata, SCIP_EVENTHDLR *eventhdlr, int pos) |
static SCIP_RETCODE | polishPrimalSolution (SCIP *scip, SCIP_CONS **conss, int nconss, SCIP_SOL *sol, SCIP_SOL *primsol) |
static SCIP_RETCODE | consdataUnmarkEventdataVars (SCIP_CONSDATA *consdata) |
static SCIP_RETCODE | presolRoundCardinality (SCIP *scip, SCIP_CONS *cons, SCIP_CONSDATA *consdata, SCIP_EVENTHDLR *eventhdlr, SCIP_Bool *cutoff, SCIP_Bool *success, int *ndelconss, int *nupgdconss, int *nfixedvars, int *nremovedvars) |
static SCIP_RETCODE | propCardinality (SCIP *scip, SCIP_CONS *cons, SCIP_CONSDATA *consdata, SCIP_Bool *cutoff, int *nchgdomain) |
static SCIP_RETCODE | branchUnbalancedCardinality (SCIP *scip, SCIP_SOL *sol, SCIP_CONS *branchcons, SCIP_VAR **vars, SCIP_VAR **indvars, int nvars, int cardval, int branchnnonzero, int branchpos) |
static SCIP_RETCODE | branchBalancedCardinality (SCIP *scip, SCIP_CONSHDLR *conshdlr, SCIP_SOL *sol, SCIP_CONS *branchcons, SCIP_VAR **vars, SCIP_VAR **indvars, int nvars, int cardval, int branchnnonzero, int branchpos, SCIP_Real balancedcutoff) |
static SCIP_RETCODE | enforceCardinality (SCIP *scip, SCIP_CONSHDLR *conshdlr, SCIP_SOL *sol, int nconss, SCIP_CONS **conss, SCIP_RESULT *result) |
static SCIP_RETCODE | generateRowCardinality (SCIP *scip, SCIP_CONSHDLR *conshdlr, SCIP_CONS *cons, SCIP_Bool local, SCIP_ROW **rowlb, SCIP_ROW **rowub) |
static SCIP_RETCODE | initsepaBoundInequalityFromCardinality (SCIP *scip, SCIP_CONSHDLR *conshdlr, SCIP_CONS **conss, int nconss, SCIP_SOL *sol, SCIP_Bool solvedinitlp, int *ngen, SCIP_Bool *cutoff) |
static SCIP_RETCODE | separateCardinality (SCIP *scip, SCIP_CONSHDLR *conshdlr, SCIP_SOL *sol, int nconss, SCIP_CONS **conss, SCIP_RESULT *result) |
static | SCIP_DECL_CONSHDLRCOPY (conshdlrCopyCardinality) |
static | SCIP_DECL_CONSFREE (consFreeCardinality) |
static | SCIP_DECL_CONSEXITSOL (consExitsolCardinality) |
static | SCIP_DECL_CONSDELETE (consDeleteCardinality) |
static | SCIP_DECL_CONSTRANS (consTransCardinality) |
static | SCIP_DECL_CONSPRESOL (consPresolCardinality) |
static | SCIP_DECL_CONSINITLP (consInitlpCardinality) |
static | SCIP_DECL_CONSSEPALP (consSepalpCardinality) |
static | SCIP_DECL_CONSSEPASOL (consSepasolCardinality) |
static | SCIP_DECL_CONSENFOLP (consEnfolpCardinality) |
static | SCIP_DECL_CONSENFORELAX (consEnforelaxCardinality) |
static | SCIP_DECL_CONSENFOPS (consEnfopsCardinality) |
static | SCIP_DECL_CONSCHECK (consCheckCardinality) |
static | SCIP_DECL_CONSPROP (consPropCardinality) |
static | SCIP_DECL_CONSLOCK (consLockCardinality) |
static | SCIP_DECL_CONSPRINT (consPrintCardinality) |
static | SCIP_DECL_CONSCOPY (consCopyCardinality) |
static | SCIP_DECL_CONSPARSE (consParseCardinality) |
static | SCIP_DECL_CONSGETVARS (consGetVarsCardinality) |
static | SCIP_DECL_CONSGETNVARS (consGetNVarsCardinality) |
static | SCIP_DECL_EVENTEXEC (eventExecCardinality) |
SCIP_RETCODE | SCIPincludeConshdlrCardinality (SCIP *scip) |
SCIP_RETCODE | SCIPcreateConsCardinality (SCIP *scip, SCIP_CONS **cons, const char *name, int nvars, SCIP_VAR **vars, int cardval, SCIP_VAR **indvars, 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 | SCIPcreateConsBasicCardinality (SCIP *scip, SCIP_CONS **cons, const char *name, int nvars, SCIP_VAR **vars, int cardval, SCIP_VAR **indvars, SCIP_Real *weights) |
SCIP_RETCODE | SCIPchgCardvalCardinality (SCIP *scip, SCIP_CONS *cons, int cardval) |
SCIP_RETCODE | SCIPaddVarCardinality (SCIP *scip, SCIP_CONS *cons, SCIP_VAR *var, SCIP_VAR *indvar, SCIP_Real weight) |
SCIP_RETCODE | SCIPappendVarCardinality (SCIP *scip, SCIP_CONS *cons, SCIP_VAR *var, SCIP_VAR *indvar) |
int | SCIPgetNVarsCardinality (SCIP *scip, SCIP_CONS *cons) |
SCIP_VAR ** | SCIPgetVarsCardinality (SCIP *scip, SCIP_CONS *cons) |
int | SCIPgetCardvalCardinality (SCIP *scip, SCIP_CONS *cons) |
SCIP_Real * | SCIPgetWeightsCardinality (SCIP *scip, SCIP_CONS *cons) |
#define CONSHDLR_NAME "cardinality" |
Definition at line 45 of file cons_cardinality.c.
Referenced by SCIPaddVarCardinality(), SCIPappendVarCardinality(), SCIPchgCardvalCardinality(), SCIPcreateConsCardinality(), SCIPgetCardvalCardinality(), SCIPgetNVarsCardinality(), SCIPgetVarsCardinality(), SCIPgetWeightsCardinality(), and SCIPincludeConshdlrCardinality().
#define CONSHDLR_DESC "cardinality constraint handler" |
Definition at line 46 of file cons_cardinality.c.
Referenced by SCIPincludeConshdlrCardinality().
#define CONSHDLR_SEPAPRIORITY 10 |
priority of the constraint handler for separation
Definition at line 47 of file cons_cardinality.c.
Referenced by SCIPincludeConshdlrCardinality().
#define CONSHDLR_ENFOPRIORITY 100 |
priority of the constraint handler for constraint enforcing
Definition at line 48 of file cons_cardinality.c.
Referenced by SCIPincludeConshdlrCardinality().
#define CONSHDLR_CHECKPRIORITY -10 |
priority of the constraint handler for checking feasibility
Definition at line 49 of file cons_cardinality.c.
Referenced by SCIPincludeConshdlrCardinality().
#define CONSHDLR_SEPAFREQ 10 |
frequency for separating cuts; zero means to separate only in the root node
Definition at line 50 of file cons_cardinality.c.
Referenced by SCIPincludeConshdlrCardinality().
#define CONSHDLR_PROPFREQ 1 |
frequency for propagating domains; zero means only preprocessing propagation
Definition at line 51 of file cons_cardinality.c.
Referenced by SCIPincludeConshdlrCardinality().
#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 52 of file cons_cardinality.c.
Referenced by SCIPincludeConshdlrCardinality().
#define CONSHDLR_MAXPREROUNDS -1 |
maximal number of presolving rounds the constraint handler participates in (-1: no limit)
Definition at line 55 of file cons_cardinality.c.
Referenced by SCIPincludeConshdlrCardinality().
#define CONSHDLR_DELAYSEPA FALSE |
should separation method be delayed, if other separators found cuts?
Definition at line 58 of file cons_cardinality.c.
Referenced by SCIPincludeConshdlrCardinality().
#define CONSHDLR_DELAYPROP FALSE |
should propagation method be delayed, if other propagators found reductions?
Definition at line 59 of file cons_cardinality.c.
Referenced by SCIPincludeConshdlrCardinality().
#define CONSHDLR_NEEDSCONS TRUE |
should the constraint handler be skipped, if no constraints are available?
Definition at line 60 of file cons_cardinality.c.
Referenced by SCIPincludeConshdlrCardinality().
#define CONSHDLR_PROP_TIMING SCIP_PROPTIMING_BEFORELP |
Definition at line 62 of file cons_cardinality.c.
Referenced by SCIPincludeConshdlrCardinality().
#define CONSHDLR_PRESOLTIMING SCIP_PRESOLTIMING_FAST |
Definition at line 63 of file cons_cardinality.c.
Referenced by SCIPincludeConshdlrCardinality().
#define DEFAULT_BRANCHBALANCED FALSE |
whether to use balanced instead of unbalanced branching
Definition at line 66 of file cons_cardinality.c.
Referenced by SCIPincludeConshdlrCardinality().
#define DEFAULT_BALANCEDDEPTH 20 |
maximum depth for using balanced branching (-1: no limit)
Definition at line 67 of file cons_cardinality.c.
Referenced by SCIPincludeConshdlrCardinality().
#define DEFAULT_BALANCEDCUTOFF 2.0 |
determines that balanced branching is only used if the branching cut off value w.r.t. the current LP solution is greater than a given value
Definition at line 68 of file cons_cardinality.c.
Referenced by SCIPincludeConshdlrCardinality().
#define EVENTHDLR_NAME "cardinality" |
Definition at line 73 of file cons_cardinality.c.
Referenced by SCIPincludeConshdlrCardinality().
#define EVENTHDLR_DESC "bound change event handler for cardinality constraints" |
Definition at line 74 of file cons_cardinality.c.
Referenced by SCIPincludeConshdlrCardinality().
|
static |
catches bound change events for a variable and its indicator variable
scip | SCIP data structure |
eventhdlr | event handler for bound change events |
consdata | constraint data |
var | implied variable |
indvar | indicator variable |
pos | position in constraint |
eventdata | pointer to store event data for bound change events |
Definition at line 122 of file cons_cardinality.c.
References dropVarEventCardinality(), FALSE, SCIP_CALL, SCIP_EVENTTYPE_BOUNDCHANGED, SCIP_OKAY, SCIPallocBlockMemory, and SCIPcatchVarEvent().
Referenced by handleNewVariableCardinality(), and presolRoundCardinality().
|
static |
drops bound change events for a variable and its indicator variable
scip | SCIP data structure |
eventhdlr | event handler for bound change events |
consdata | constraint data |
var | implied variable |
indvar | indicator variable |
eventdata | pointer of event data for bound change events |
Definition at line 157 of file cons_cardinality.c.
References fixVariableZeroNode(), SCIP_CALL, SCIP_EVENTTYPE_BOUNDCHANGED, SCIP_OKAY, SCIPdropVarEvent(), and SCIPfreeBlockMemory.
Referenced by catchVarEventCardinality(), deleteVarCardinality(), and presolRoundCardinality().
|
static |
fix variable in given node to 0 or add constraint if variable is multi-aggregated
scip | SCIP pointer |
var | variable to be fixed to 0 |
node | node |
infeasible | pointer to store if fixing is infeasible |
Definition at line 188 of file cons_cardinality.c.
References FALSE, fixVariableZero(), SCIP_CALL, SCIP_OKAY, SCIP_Real, SCIP_VARSTATUS_MULTAGGR, SCIPaddConsNode(), SCIPchgVarLbNode(), SCIPchgVarUbNode(), SCIPcreateConsLinear(), SCIPdebugMsg, SCIPisFeasNegative(), SCIPisFeasPositive(), SCIPisFeasZero(), SCIPreleaseCons(), SCIPvarGetLbLocal(), SCIPvarGetName(), SCIPvarGetStatus(), SCIPvarGetUbLocal(), and TRUE.
Referenced by branchBalancedCardinality(), branchUnbalancedCardinality(), dropVarEventCardinality(), and enforceCardinality().
|
static |
try to fix variable to 0
Try to treat fixing by special consideration of multiaggregated variables. For a multi-aggregation
\[ x = \sum_{i=1}^n \alpha_i x_i + c, \]
we can express the fixing \(x = 0\) by fixing all \(x_i\) to 0 if \(c = 0\) and the lower bounds of \(x_i\) are nonnegative if \(\alpha_i > 0\) or the upper bounds are nonpositive if \(\alpha_i < 0\).
scip | SCIP pointer |
var | variable to be fixed to 0 |
infeasible | if fixing is infeasible |
tightened | if fixing was performed |
Definition at line 247 of file cons_cardinality.c.
References FALSE, lockVariableCardinality(), SCIP_Bool, SCIP_CALL, SCIP_OKAY, SCIP_Real, SCIP_VARSTATUS_MULTAGGR, SCIPfixVar(), SCIPflattenVarAggregationGraph(), SCIPisNegative(), SCIPisPositive(), SCIPisZero(), SCIPvarGetLbLocal(), SCIPvarGetMultaggrConstant(), SCIPvarGetMultaggrNVars(), SCIPvarGetMultaggrScalars(), SCIPvarGetMultaggrVars(), SCIPvarGetStatus(), SCIPvarGetUbLocal(), and TRUE.
Referenced by fixVariableZeroNode(), and propCardinality().
|
static |
add lock on variable
scip | SCIP data structure |
cons | constraint |
var | variable |
indvar | indicator variable |
Definition at line 316 of file cons_cardinality.c.
References SCIP_CALL, SCIP_OKAY, SCIPisFeasNegative(), SCIPisFeasPositive(), SCIPlockVarCons(), SCIPvarGetLbLocal(), SCIPvarGetUbLocal(), TRUE, and unlockVariableCardinality().
Referenced by fixVariableZero(), handleNewVariableCardinality(), and presolRoundCardinality().
|
static |
scip | SCIP data structure |
cons | constraint |
var | variable |
indvar | indicator variable |
Definition at line 337 of file cons_cardinality.c.
References consdataEnsurevarsSizeCardinality(), SCIP_CALL, SCIP_OKAY, SCIPisFeasNegative(), SCIPisFeasPositive(), SCIPunlockVarCons(), SCIPvarGetLbLocal(), SCIPvarGetUbLocal(), and TRUE.
Referenced by deleteVarCardinality(), lockVariableCardinality(), and presolRoundCardinality().
|
static |
ensures that the vars and weights array can store at least num entries
scip | SCIP data structure |
consdata | constraint data |
num | minimum number of entries to store |
reserveweights | whether the weights array is handled |
Definition at line 358 of file cons_cardinality.c.
References handleNewVariableCardinality(), SCIP_CALL, SCIP_OKAY, SCIPcalcMemGrowSize(), and SCIPreallocBlockMemoryArray.
Referenced by addVarCardinality(), appendVarCardinality(), and unlockVariableCardinality().
|
static |
handle new variable that was added to the constraint
We perform the following steps:
scip | SCIP data structure |
cons | constraint |
consdata | constraint data |
conshdlrdata | constraint handler data |
var | variable |
indvar | indicator variable to indicate whether variable may be treated as nonzero in cardinality constraint |
pos | position in constraint |
transformed | whether original variable was transformed |
eventdata | pointer to store event data for bound change events |
Definition at line 400 of file cons_cardinality.c.
References addVarCardinality(), catchVarEventCardinality(), lockVariableCardinality(), SCIP_CALL, SCIP_OKAY, SCIPaddVarToRow(), SCIPisFeasEQ(), SCIPisInfinity(), SCIPisZero(), SCIPmarkDoNotMultaggrVar(), SCIPvarGetLbGlobal(), SCIPvarGetLbLocal(), and SCIPvarGetUbGlobal().
Referenced by addVarCardinality(), appendVarCardinality(), consdataEnsurevarsSizeCardinality(), and SCIPcreateConsCardinality().
|
static |
adds a variable to a cardinality constraint, at position given by weight - ascending order
scip | SCIP data structure |
cons | constraint |
conshdlrdata | constraint handler data |
var | variable to add to the constraint |
indvar | indicator variable to indicate whether variable may be treated as nonzero in cardinality constraint (or NULL) |
weight | weight to determine position |
Definition at line 457 of file cons_cardinality.c.
References appendVarCardinality(), consdataEnsurevarsSizeCardinality(), FALSE, handleNewVariableCardinality(), SCIP_Bool, SCIP_CALL, SCIP_INVALIDCALL, SCIP_MAXSTRLEN, SCIP_OKAY, SCIP_VARTYPE_BINARY, SCIPaddVar(), SCIPblkmem(), SCIPconsGetData(), SCIPconsGetName(), SCIPconsIsTransformed(), SCIPcreateVar(), SCIPerrorMessage, SCIPgetNTotalVars(), SCIPgetTransformedVar(), SCIPhashmapCreate(), SCIPhashmapExists(), SCIPhashmapGetImage(), SCIPhashmapInsert(), SCIPreleaseVar(), SCIPsnprintf(), SCIPvarGetName(), SCIPvarIsBinary(), SCIPvarIsTransformed(), and TRUE.
Referenced by handleNewVariableCardinality(), and SCIPaddVarCardinality().
|
static |
appends a variable to a cardinality constraint
scip | SCIP data structure |
cons | constraint |
conshdlrdata | constraint handler data |
var | variable to add to the constraint |
indvar | indicator variable to indicate whether variable may be treated as nonzero in cardinality constraint |
Definition at line 584 of file cons_cardinality.c.
References consdataEnsurevarsSizeCardinality(), deleteVarCardinality(), FALSE, handleNewVariableCardinality(), SCIP_Bool, SCIP_CALL, SCIP_MAXSTRLEN, SCIP_OKAY, SCIP_VARTYPE_BINARY, SCIPaddVar(), SCIPblkmem(), SCIPconsGetData(), SCIPconsIsTransformed(), SCIPcreateVar(), SCIPgetNTotalVars(), SCIPgetTransformedVar(), SCIPhashmapCreate(), SCIPhashmapExists(), SCIPhashmapGetImage(), SCIPhashmapInsert(), SCIPreleaseVar(), SCIPsnprintf(), SCIPvarGetName(), SCIPvarIsBinary(), and SCIPvarIsTransformed().
Referenced by addVarCardinality(), and SCIPappendVarCardinality().
|
static |
deletes a variable from a cardinality constraint
scip | SCIP data structure |
cons | constraint |
consdata | constraint data |
eventhdlr | corresponding event handler |
pos | position of variable in array |
Definition at line 685 of file cons_cardinality.c.
References dropVarEventCardinality(), polishPrimalSolution(), SCIP_CALL, SCIP_OKAY, SCIPisFeasEQ(), SCIPvarGetLbLocal(), and unlockVariableCardinality().
Referenced by appendVarCardinality(), and presolRoundCardinality().
|
static |
for each indicator variable sets solution to 1.0 if the solution value of the implied variable is nonzero
scip | SCIP pointer |
conss | constraints |
nconss | number of constraints |
sol | solution to be enforced (or NULL) |
primsol | primal solution |
Definition at line 726 of file cons_cardinality.c.
References consdataUnmarkEventdataVars(), SCIP_CALL, SCIP_OKAY, SCIPconsGetData(), SCIPgetSolVal(), SCIPisFeasZero(), and SCIPsetSolVal().
Referenced by deleteVarCardinality(), and enforceCardinality().
|
static |
unmark variables that are marked for propagation
consdata | constraint data |
Definition at line 773 of file cons_cardinality.c.
References FALSE, presolRoundCardinality(), and SCIP_OKAY.
Referenced by polishPrimalSolution(), and presolRoundCardinality().
|
static |
perform one presolving round
We perform the following presolving steps:
scip | SCIP pointer |
cons | constraint |
consdata | constraint data |
eventhdlr | event handler |
cutoff | whether a cutoff happened |
success | whether we performed a successful reduction |
ndelconss | number of deleted constraints |
nupgdconss | number of upgraded constraints |
nfixedvars | number of fixed variables |
nremovedvars | number of variables removed |
Definition at line 809 of file cons_cardinality.c.
References catchVarEventCardinality(), consdataUnmarkEventdataVars(), deleteVarCardinality(), dropVarEventCardinality(), FALSE, lockVariableCardinality(), propCardinality(), SCIP_Bool, SCIP_CALL, SCIP_INVALIDDATA, SCIP_Longint, SCIP_OKAY, SCIP_Real, SCIPaddCons(), SCIPallocBufferArray, SCIPconsGetName(), SCIPconsIsChecked(), SCIPconsIsDynamic(), SCIPconsIsEnforced(), SCIPconsIsInitial(), SCIPconsIsLocal(), SCIPconsIsModifiable(), SCIPconsIsPropagated(), SCIPconsIsRemovable(), SCIPconsIsSeparated(), SCIPconsIsStickingAtNode(), SCIPcreateConsKnapsack(), SCIPdebugMsg, SCIPdelCons(), SCIPfixVar(), SCIPfreeBufferArray, SCIPgetProbvarSum(), SCIPisFeasEQ(), SCIPisFeasNegative(), SCIPisFeasPositive(), SCIPisFeasZero(), SCIPisZero(), SCIPreleaseCons(), SCIPvarGetLbLocal(), SCIPvarGetName(), SCIPvarGetUbLocal(), SCIPvarIsBinary(), TRUE, and unlockVariableCardinality().
Referenced by consdataUnmarkEventdataVars().
|
static |
propagates a cardinality constraint and its variables
The number 'ntreatnonzeros' that is assigned to the constraint data returns the number of variables that are either known to be nonzero or can be treated as nonzero. We say that a variable is known to be nonzero, if zero is outside the domain of this variable. A variable can be treated as nonzero, if its corresponding indicator variable 'indvar' is fixed to 1.0, e.g., by branching.
We perform the following propagation steps:
scip | SCIP pointer |
cons | constraint |
consdata | constraint data |
cutoff | whether a cutoff happened |
nchgdomain | number of domain changes |
Definition at line 1096 of file cons_cardinality.c.
References branchUnbalancedCardinality(), FALSE, fixVariableZero(), SCIP_Bool, SCIP_CALL, SCIP_OKAY, SCIPchgVarLb(), SCIPconsGetName(), SCIPconsIsModifiable(), SCIPdebugMsg, SCIPdelConsLocal(), SCIPisFeasEQ(), SCIPisFeasNegative(), SCIPisFeasPositive(), SCIPisFeasZero(), SCIPresetConsAge(), SCIPvarGetLbLocal(), SCIPvarGetName(), SCIPvarGetUbLocal(), SCIPvarIsBinary(), and TRUE.
Referenced by enforceCardinality(), and presolRoundCardinality().
|
static |
apply unbalanced branching (see the function enforceCardinality() for further information)
scip | SCIP pointer |
sol | solution to be enforced (or NULL) |
branchcons | cardinality constraint |
vars | variables of constraint |
indvars | indicator variables |
nvars | number of variables of constraint |
cardval | cardinality value of constraint |
branchnnonzero | number of variables that are fixed to be nonzero |
branchpos | position in array 'vars' |
Definition at line 1307 of file cons_cardinality.c.
References branchBalancedCardinality(), fixVariableZeroNode(), SCIP_Bool, SCIP_BRANCHDIR_DOWNWARDS, SCIP_CALL, SCIP_OKAY, SCIP_Real, SCIPcalcChildEstimate(), SCIPcalcNodeselPriority(), SCIPchgVarLbNode(), SCIPconsGetName(), SCIPcreateChild(), SCIPdebugMsg, SCIPgetLocalTransEstimate(), SCIPgetSolVal(), SCIPisFeasEQ(), SCIPisFeasNegative(), SCIPisFeasPositive(), SCIPisFeasZero(), SCIPvarGetLbLocal(), SCIPvarGetName(), and SCIPvarGetUbLocal().
Referenced by branchBalancedCardinality(), enforceCardinality(), and propCardinality().
|
static |
apply balanced branching (see the function enforceCardinality() for further information)
scip | SCIP pointer |
conshdlr | constraint handler |
sol | solution to be enforced (or NULL) |
branchcons | cardinality constraint |
vars | variables of constraint |
indvars | indicator variables |
nvars | number of variables of constraint |
cardval | cardinality value of constraint |
branchnnonzero | number of variables that are fixed to be nonzero |
branchpos | position in array 'vars' |
balancedcutoff | cut off value for deciding whether to apply balanced branching |
Definition at line 1410 of file cons_cardinality.c.
References branchUnbalancedCardinality(), enforceCardinality(), FALSE, fixVariableZeroNode(), MAX, REALABS, SCIP_Bool, SCIP_BRANCHDIR_DOWNWARDS, SCIP_CALL, SCIP_MAXSTRLEN, SCIP_OKAY, SCIP_PARAMETERWRONGVAL, SCIP_Real, SCIPaddConsNode(), SCIPallocBufferArray, SCIPcalcChildEstimate(), SCIPcalcNodeselPriority(), SCIPconsGetName(), SCIPconshdlrGetSepaFreq(), SCIPcreateChild(), SCIPcreateConsCardinality(), SCIPdebugMsg, SCIPerrorMessage, SCIPfloor(), SCIPfreeBufferArray, SCIPgetLocalTransEstimate(), SCIPgetNNodes(), SCIPgetSolVal(), SCIPisFeasLT(), SCIPisFeasNegative(), SCIPisFeasPositive(), SCIPisFeasZero(), SCIPreleaseCons(), SCIPsnprintf(), SCIPvarGetLbLocal(), SCIPvarGetUbLocal(), and TRUE.
Referenced by branchUnbalancedCardinality(), and enforceCardinality().
|
static |
enforcement method
We check whether the current solution is feasible. If not, the cardinality constraints can be enforced by different branching rules:
\[ r \leq \frac{w}{W} < r+1. \]
Choose a number \(s\) with \(0\leq s < \min\{k, r\}\). The branches are then\[ |\mbox{supp}(x_{d_1}, \ldots, x_{d_r})| \leq s \qquad \mbox{and}\qquad |\mbox{supp}(x_{d_{r+1}}, \ldots, x_{d_{n}})| \leq k-s-1, \]
where \(d_1, \ldots, d_n\) are the elements of the set \(D\).The branching constraint is chosen by the largest sum of variable values.
scip | SCIP pointer |
conshdlr | constraint handler |
sol | solution to be enforced (or NULL) |
nconss | number of constraints |
conss | indicator constraints |
result | result |
Definition at line 1701 of file cons_cardinality.c.
References branchBalancedCardinality(), branchUnbalancedCardinality(), FALSE, fixVariableZeroNode(), generateRowCardinality(), polishPrimalSolution(), propCardinality(), REALABS, SCIP_Bool, SCIP_BRANCHED, SCIP_CALL, SCIP_CUTOFF, SCIP_FEASIBLE, SCIP_OKAY, SCIP_Real, SCIP_REAL_MAX, SCIP_REDUCEDDOM, SCIP_VARSTATUS_MULTAGGR, SCIPconsGetData(), SCIPconsGetName(), SCIPconshdlrGetData(), SCIPconshdlrGetName(), SCIPcreateSolCopy(), SCIPdebugMsg, SCIPfreeSol(), SCIPgetCurrentNode(), SCIPgetDepth(), SCIPgetSolVal(), SCIPinfinity(), SCIPisFeasEQ(), SCIPisFeasGT(), SCIPisFeasNegative(), SCIPisFeasPositive(), SCIPisFeasZero(), SCIPresetConsAge(), SCIPtrySol(), SCIPvarGetLbLocal(), SCIPvarGetName(), SCIPvarGetStatus(), SCIPvarGetUbLocal(), and TRUE.
Referenced by branchBalancedCardinality().
|
static |
Generate row
We generate the row corresponding to the following simple valid inequalities:
\[ \frac{x_1}{u_1} + \ldots + \frac{x_n}{u_n} \leq k\qquad\mbox{and}\qquad \frac{x_1}{\ell_1} + \ldots + \frac{x_n}{\ell_1} \leq k, \]
where \(\ell_1, \ldots, \ell_n\) and \(u_1, \ldots, u_n\) are the nonzero and finite lower and upper bounds of the variables \(x_1, \ldots, x_n\) and k is the right hand side of the cardinality constraint. If at least k upper bounds < 0 or a lower bounds > 0, the constraint itself is redundant, so the cut is not applied (lower bounds > 0 and upper bounds < 0 are usually detected in presolving or propagation). Infinite bounds and zero are skipped. Thus \(\ell_1, \ldots, \ell_n\) are all negative, which results in the \(\leq\) inequality.
Note that in fact, any mixture of nonzero finite lower and upper bounds would lead to a valid inequality as above. However, usually either the lower or upper bound is nonzero. Thus, the above inequalities are the most interesting.
scip | SCIP pointer |
conshdlr | constraint handler |
cons | constraint |
local | produce local cut? |
rowlb | output: row for lower bounds (or NULL if not needed) |
rowub | output: row for upper bounds (or NULL if not needed) |
Definition at line 1970 of file cons_cardinality.c.
References FALSE, initsepaBoundInequalityFromCardinality(), SCIP_CALL, SCIP_MAXSTRLEN, SCIP_OKAY, SCIP_Real, SCIPaddVarsToRow(), SCIPallocBufferArray, SCIPconsGetData(), SCIPconsGetName(), SCIPcreateEmptyRowCons(), SCIPdebug, SCIPfreeBufferArray, SCIPinfinity(), SCIPisFeasEQ(), SCIPisInfinity(), SCIPisNegative(), SCIPisPositive(), SCIPisZero(), SCIPprintRow(), SCIPsnprintf(), SCIPvarGetLbGlobal(), SCIPvarGetLbLocal(), SCIPvarGetUbGlobal(), and TRUE.
Referenced by enforceCardinality(), and initsepaBoundInequalityFromCardinality().
|
static |
initialize or separate bound inequalities from cardinality constraints (see the function generateRowCardinality() for an explanation of bound inequalities)
scip | SCIP pointer |
conshdlr | constraint handler |
conss | cardinality constraints |
nconss | number of cardinality constraints |
sol | LP solution to be separated (or NULL) |
solvedinitlp | TRUE if initial LP relaxation at a node is solved |
ngen | pointer to store number of cuts generated (or NULL) |
cutoff | pointer to store whether a cutoff occurred |
Definition at line 2095 of file cons_cardinality.c.
References FALSE, generateRowCardinality(), SCIP_Bool, SCIP_CALL, SCIP_OKAY, SCIP_Real, SCIPaddRow(), SCIPconsGetData(), SCIPconsGetName(), SCIPconsIsLocal(), SCIPdebug, SCIPdebugMsg, SCIPisCutEfficacious(), SCIPisInfinity(), SCIPisLE(), SCIPprintRow(), SCIPreleaseRow(), SCIPresetConsAge(), SCIProwGetLhs(), SCIProwGetRhs(), SCIProwIsInLP(), separateCardinality(), and TRUE.
Referenced by generateRowCardinality(), and separateCardinality().
|
static |
separates cardinality constraints for arbitrary solutions
scip | SCIP pointer |
conshdlr | constraint handler |
sol | solution to be separated (or NULL) |
nconss | number of constraints |
conss | cardinality constraints |
result | result |
Definition at line 2208 of file cons_cardinality.c.
References initsepaBoundInequalityFromCardinality(), SCIP_Bool, SCIP_CALL, SCIP_CUTOFF, SCIP_DECL_CONSHDLRCOPY(), SCIP_DIDNOTFIND, SCIP_DIDNOTRUN, SCIP_OKAY, SCIP_SEPARATED, SCIPdebugMsg, SCIPisStopped(), and TRUE.
Referenced by initsepaBoundInequalityFromCardinality().
|
static |
copy method for constraint handler plugins (called when SCIP copies plugins)
Definition at line 2256 of file cons_cardinality.c.
Referenced by separateCardinality().
|
static |
destructor of constraint handler to free constraint handler data (called when SCIP is exiting)
Definition at line 2272 of file cons_cardinality.c.
|
static |
solving process deinitialization method of constraint handler (called before branch and bound process data is freed)
Definition at line 2296 of file cons_cardinality.c.
|
static |
frees specific constraint data
Definition at line 2342 of file cons_cardinality.c.
|
static |
transforms constraint data into data belonging to the transformed problem
Definition at line 2400 of file cons_cardinality.c.
|
static |
presolving method of constraint handler
Definition at line 2498 of file cons_cardinality.c.
|
static |
LP initialization method of constraint handler (called before the initial LP relaxation at a node is solved)
Definition at line 2577 of file cons_cardinality.c.
|
static |
separation method of constraint handler for LP solutions
Definition at line 2593 of file cons_cardinality.c.
|
static |
separation method of constraint handler for arbitrary primal solutions
Definition at line 2607 of file cons_cardinality.c.
|
static |
constraint enforcing method of constraint handler for LP solutions
Definition at line 2621 of file cons_cardinality.c.
|
static |
constraint enforcing method of constraint handler for relaxation solutions
Definition at line 2636 of file cons_cardinality.c.
|
static |
constraint enforcing method of constraint handler for pseudo solutions
Definition at line 2651 of file cons_cardinality.c.
|
static |
feasibility check method of constraint handler for integral solutions
We simply check whether more variables than allowed are nonzero in the given solution.
Definition at line 2669 of file cons_cardinality.c.
|
static |
domain propagation method of constraint handler
Definition at line 2740 of file cons_cardinality.c.
|
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.
Definition at line 2796 of file cons_cardinality.c.
|
static |
constraint display method of constraint handler
Definition at line 2846 of file cons_cardinality.c.
|
static |
constraint copying method of constraint handler
Definition at line 2876 of file cons_cardinality.c.
|
static |
constraint parsing method of constraint handler
Definition at line 2955 of file cons_cardinality.c.
|
static |
constraint method of constraint handler which returns the variables (if possible)
Definition at line 3040 of file cons_cardinality.c.
|
static |
constraint method of constraint handler which returns the number of variables (if possible)
Definition at line 3062 of file cons_cardinality.c.
|
static |
Definition at line 3083 of file cons_cardinality.c.