Detailed Description
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 "blockmemshell/memory.h"
#include "scip/cons_cardinality.h"
#include "scip/cons_knapsack.h"
#include "scip/cons_linear.h"
#include "scip/pub_cons.h"
#include "scip/pub_event.h"
#include "scip/pub_lp.h"
#include "scip/pub_message.h"
#include "scip/pub_misc.h"
#include "scip/pub_misc_sort.h"
#include "scip/pub_var.h"
#include "scip/scip_branch.h"
#include "scip/scip_cons.h"
#include "scip/scip_copy.h"
#include "scip/scip_cut.h"
#include "scip/scip_event.h"
#include "scip/scip_general.h"
#include "scip/scip_lp.h"
#include "scip/scip_mem.h"
#include "scip/scip_message.h"
#include "scip/scip_numerics.h"
#include "scip/scip_param.h"
#include "scip/scip_prob.h"
#include "scip/scip_sol.h"
#include "scip/scip_solvingstats.h"
#include "scip/scip_tree.h"
#include "scip/scip_var.h"
#include <ctype.h>
#include <stdlib.h>
#include <string.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) |
Macro Definition Documentation
◆ CONSHDLR_NAME
#define CONSHDLR_NAME "cardinality" |
Definition at line 68 of file cons_cardinality.c.
Referenced by SCIPaddVarCardinality(), SCIPappendVarCardinality(), SCIPchgCardvalCardinality(), SCIPcreateConsCardinality(), SCIPgetCardvalCardinality(), SCIPgetNVarsCardinality(), SCIPgetVarsCardinality(), SCIPgetWeightsCardinality(), and SCIPincludeConshdlrCardinality().
◆ CONSHDLR_DESC
#define CONSHDLR_DESC "cardinality constraint handler" |
Definition at line 69 of file cons_cardinality.c.
Referenced by SCIPincludeConshdlrCardinality().
◆ CONSHDLR_SEPAPRIORITY
#define CONSHDLR_SEPAPRIORITY 10 |
priority of the constraint handler for separation
Definition at line 70 of file cons_cardinality.c.
Referenced by SCIPincludeConshdlrCardinality().
◆ CONSHDLR_ENFOPRIORITY
#define CONSHDLR_ENFOPRIORITY 100 |
priority of the constraint handler for constraint enforcing
Definition at line 71 of file cons_cardinality.c.
Referenced by SCIPincludeConshdlrCardinality().
◆ CONSHDLR_CHECKPRIORITY
#define CONSHDLR_CHECKPRIORITY -10 |
priority of the constraint handler for checking feasibility
Definition at line 72 of file cons_cardinality.c.
Referenced by SCIPincludeConshdlrCardinality().
◆ CONSHDLR_SEPAFREQ
#define CONSHDLR_SEPAFREQ 10 |
frequency for separating cuts; zero means to separate only in the root node
Definition at line 73 of file cons_cardinality.c.
Referenced by SCIPincludeConshdlrCardinality().
◆ CONSHDLR_PROPFREQ
#define CONSHDLR_PROPFREQ 1 |
frequency for propagating domains; zero means only preprocessing propagation
Definition at line 74 of file cons_cardinality.c.
Referenced by SCIPincludeConshdlrCardinality().
◆ CONSHDLR_EAGERFREQ
#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 75 of file cons_cardinality.c.
Referenced by SCIPincludeConshdlrCardinality().
◆ CONSHDLR_MAXPREROUNDS
#define CONSHDLR_MAXPREROUNDS -1 |
maximal number of presolving rounds the constraint handler participates in (-1: no limit)
Definition at line 78 of file cons_cardinality.c.
Referenced by SCIPincludeConshdlrCardinality().
◆ CONSHDLR_DELAYSEPA
#define CONSHDLR_DELAYSEPA FALSE |
should separation method be delayed, if other separators found cuts?
Definition at line 81 of file cons_cardinality.c.
Referenced by SCIPincludeConshdlrCardinality().
◆ CONSHDLR_DELAYPROP
#define CONSHDLR_DELAYPROP FALSE |
should propagation method be delayed, if other propagators found reductions?
Definition at line 82 of file cons_cardinality.c.
Referenced by SCIPincludeConshdlrCardinality().
◆ CONSHDLR_NEEDSCONS
#define CONSHDLR_NEEDSCONS TRUE |
should the constraint handler be skipped, if no constraints are available?
Definition at line 83 of file cons_cardinality.c.
Referenced by SCIPincludeConshdlrCardinality().
◆ CONSHDLR_PROP_TIMING
#define CONSHDLR_PROP_TIMING SCIP_PROPTIMING_BEFORELP |
Definition at line 85 of file cons_cardinality.c.
Referenced by SCIPincludeConshdlrCardinality().
◆ CONSHDLR_PRESOLTIMING
#define CONSHDLR_PRESOLTIMING SCIP_PRESOLTIMING_FAST |
Definition at line 86 of file cons_cardinality.c.
Referenced by SCIPincludeConshdlrCardinality().
◆ DEFAULT_BRANCHBALANCED
#define DEFAULT_BRANCHBALANCED FALSE |
whether to use balanced instead of unbalanced branching
Definition at line 89 of file cons_cardinality.c.
Referenced by SCIPincludeConshdlrCardinality().
◆ DEFAULT_BALANCEDDEPTH
#define DEFAULT_BALANCEDDEPTH 20 |
maximum depth for using balanced branching (-1: no limit)
Definition at line 90 of file cons_cardinality.c.
Referenced by SCIPincludeConshdlrCardinality().
◆ DEFAULT_BALANCEDCUTOFF
#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 91 of file cons_cardinality.c.
Referenced by SCIPincludeConshdlrCardinality().
◆ EVENTHDLR_NAME
#define EVENTHDLR_NAME "cardinality" |
Definition at line 96 of file cons_cardinality.c.
Referenced by SCIPincludeConshdlrCardinality().
◆ EVENTHDLR_DESC
#define EVENTHDLR_DESC "bound change event handler for cardinality constraints" |
Definition at line 97 of file cons_cardinality.c.
Referenced by SCIPincludeConshdlrCardinality().
Function Documentation
◆ catchVarEventCardinality()
|
static |
catches bound change events for a variable and its indicator variable
- Parameters
-
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 145 of file cons_cardinality.c.
References dropVarEventCardinality(), FALSE, NULL, SCIP_CALL, SCIP_EVENTTYPE_BOUNDCHANGED, SCIP_OKAY, SCIPallocBlockMemory, and SCIPcatchVarEvent().
Referenced by handleNewVariableCardinality(), and presolRoundCardinality().
◆ dropVarEventCardinality()
|
static |
drops bound change events for a variable and its indicator variable
- Parameters
-
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 180 of file cons_cardinality.c.
References fixVariableZeroNode(), NULL, SCIP_CALL, SCIP_EVENTTYPE_BOUNDCHANGED, SCIP_OKAY, SCIPdropVarEvent(), and SCIPfreeBlockMemory.
Referenced by catchVarEventCardinality(), deleteVarCardinality(), and presolRoundCardinality().
◆ fixVariableZeroNode()
|
static |
fix variable in given node to 0 or add constraint if variable is multi-aggregated
- Parameters
-
scip SCIP pointer var variable to be fixed to 0 node node infeasible pointer to store if fixing is infeasible
Definition at line 211 of file cons_cardinality.c.
References FALSE, fixVariableZero(), NULL, 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().
◆ fixVariableZero()
|
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\).
- Parameters
-
scip SCIP pointer var variable to be fixed to 0 infeasible if fixing is infeasible tightened if fixing was performed
Definition at line 270 of file cons_cardinality.c.
References FALSE, lockVariableCardinality(), NULL, 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().
◆ lockVariableCardinality()
|
static |
add lock on variable
- Parameters
-
scip SCIP data structure cons constraint var variable indvar indicator variable
Definition at line 339 of file cons_cardinality.c.
References NULL, SCIP_CALL, SCIP_OKAY, SCIPisFeasNegative(), SCIPisFeasPositive(), SCIPlockVarCons(), SCIPvarGetLbLocal(), SCIPvarGetUbLocal(), TRUE, and unlockVariableCardinality().
Referenced by fixVariableZero(), handleNewVariableCardinality(), and presolRoundCardinality().
◆ unlockVariableCardinality()
|
static |
- Parameters
-
scip SCIP data structure cons constraint var variable indvar indicator variable
Definition at line 360 of file cons_cardinality.c.
References consdataEnsurevarsSizeCardinality(), NULL, SCIP_CALL, SCIP_OKAY, SCIPisFeasNegative(), SCIPisFeasPositive(), SCIPunlockVarCons(), SCIPvarGetLbLocal(), SCIPvarGetUbLocal(), and TRUE.
Referenced by deleteVarCardinality(), lockVariableCardinality(), and presolRoundCardinality().
◆ consdataEnsurevarsSizeCardinality()
|
static |
ensures that the vars and weights array can store at least num entries
- Parameters
-
scip SCIP data structure consdata constraint data num minimum number of entries to store reserveweights whether the weights array is handled
Definition at line 381 of file cons_cardinality.c.
References handleNewVariableCardinality(), NULL, SCIP_CALL, SCIP_OKAY, SCIPcalcMemGrowSize(), and SCIPreallocBlockMemoryArray.
Referenced by addVarCardinality(), appendVarCardinality(), and unlockVariableCardinality().
◆ handleNewVariableCardinality()
|
static |
handle new variable that was added to the constraint
We perform the following steps:
- catch bound change events of variable.
- update rounding locks of variable.
- don't allow multiaggregation of variable, since this cannot be handled by branching in the current implementation
- update lower and upper bound row, i.e., the linear representations of the cardinality constraints
- Parameters
-
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 423 of file cons_cardinality.c.
References addVarCardinality(), catchVarEventCardinality(), lockVariableCardinality(), NULL, SCIP_CALL, SCIP_OKAY, SCIPaddVarToRow(), SCIPisFeasEQ(), SCIPisInfinity(), SCIPisZero(), SCIPmarkDoNotMultaggrVar(), SCIPvarGetLbGlobal(), SCIPvarGetLbLocal(), and SCIPvarGetUbGlobal().
Referenced by addVarCardinality(), appendVarCardinality(), consdataEnsurevarsSizeCardinality(), and SCIPcreateConsCardinality().
◆ addVarCardinality()
|
static |
adds a variable to a cardinality constraint, at position given by weight - ascending order
- Parameters
-
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 480 of file cons_cardinality.c.
References appendVarCardinality(), consdataEnsurevarsSizeCardinality(), FALSE, handleNewVariableCardinality(), NULL, 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().
◆ appendVarCardinality()
|
static |
appends a variable to a cardinality constraint
- Parameters
-
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 608 of file cons_cardinality.c.
References consdataEnsurevarsSizeCardinality(), deleteVarCardinality(), FALSE, handleNewVariableCardinality(), NULL, 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().
◆ deleteVarCardinality()
|
static |
deletes a variable from a cardinality constraint
- Parameters
-
scip SCIP data structure cons constraint consdata constraint data eventhdlr corresponding event handler pos position of variable in array
Definition at line 709 of file cons_cardinality.c.
References dropVarEventCardinality(), NULL, polishPrimalSolution(), SCIP_CALL, SCIP_OKAY, SCIPisFeasEQ(), SCIPvarGetLbLocal(), and unlockVariableCardinality().
Referenced by appendVarCardinality(), and presolRoundCardinality().
◆ polishPrimalSolution()
|
static |
for each indicator variable sets solution to 1.0 if the solution value of the implied variable is nonzero
- Parameters
-
scip SCIP pointer conss constraints nconss number of constraints sol solution to be enforced (or NULL) primsol primal solution
Definition at line 750 of file cons_cardinality.c.
References consdataUnmarkEventdataVars(), NULL, SCIP_CALL, SCIP_OKAY, SCIPconsGetData(), SCIPgetSolVal(), SCIPisFeasZero(), and SCIPsetSolVal().
Referenced by deleteVarCardinality(), and enforceCardinality().
◆ consdataUnmarkEventdataVars()
|
static |
unmark variables that are marked for propagation
- Parameters
-
consdata constraint data
Definition at line 797 of file cons_cardinality.c.
References FALSE, NULL, presolRoundCardinality(), and SCIP_OKAY.
Referenced by polishPrimalSolution(), and presolRoundCardinality().
◆ presolRoundCardinality()
|
static |
perform one presolving round
We perform the following presolving steps:
- If the bounds of some variable force it to be nonzero, we can fix all other variables to zero and remove the cardinality constraints that contain it.
- If a variable is fixed to zero, we can remove the variable.
- If a variable appears twice, it can be fixed to 0.
- We substitute appregated variables.
- Parameters
-
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 833 of file cons_cardinality.c.
References catchVarEventCardinality(), consdataUnmarkEventdataVars(), deleteVarCardinality(), dropVarEventCardinality(), FALSE, lockVariableCardinality(), NULL, 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().
◆ propCardinality()
|
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:
- if the number 'ntreatnonzeros' is greater than the cardinality value of the constraint, then the current subproblem is marked as infeasible.
- if the cardinality constraint is saturated, i.e., the number 'ntreatnonzeros' is equal to the cardinality value of the constraint, then fix all the other variables of the constraint to zero.
- remove the cardinality constraint locally if all variables are either fixed to zero or can be treated as nonzero.
- if a (binary) indicator variable is fixed to zero, then fix the corresponding implied variable to zero.
- if zero is outside of the domain of an implied variable, then fix the corresponding indicator variable to one.
- Parameters
-
scip SCIP pointer cons constraint consdata constraint data cutoff whether a cutoff happened nchgdomain number of domain changes
Definition at line 1120 of file cons_cardinality.c.
References branchUnbalancedCardinality(), FALSE, fixVariableZero(), NULL, 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().
◆ branchUnbalancedCardinality()
|
static |
apply unbalanced branching (see the function enforceCardinality() for further information)
- Parameters
-
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 1331 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().
◆ branchBalancedCardinality()
|
static |
apply balanced branching (see the function enforceCardinality() for further information)
- Parameters
-
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 1434 of file cons_cardinality.c.
References branchUnbalancedCardinality(), enforceCardinality(), FALSE, fixVariableZeroNode(), MAX, MIN, NULL, 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(), TRUE, and w.
Referenced by branchUnbalancedCardinality(), and enforceCardinality().
◆ enforceCardinality()
|
static |
enforcement method
We check whether the current solution is feasible. If not, the cardinality constraints can be enforced by different branching rules:
- Unbalanced branching: Branch on the neighborhood of a single variable \(i\), i.e., in one branch \(x_i\) is fixed to zero and in the other we modify cardinality constraints \(|\mbox{supp}(x)| \leq k\) with \(i\in D\) to \(|\mbox{supp}(x_{D\setminus i}) \leq k-1\)
- Balanced branching: First, choose a cardinality constraint \(|\mbox{supp}(x_D) \leq k\) that is violated by the current LP solution. Then, we compute \(W = \sum_{j=1}^n |x_i|\) and \(w = \sum_{j=1}^n j\, |x_i|\). Next, search for the index \(r\) that satisfies
\[ 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.
- Parameters
-
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 1725 of file cons_cardinality.c.
References branchBalancedCardinality(), branchUnbalancedCardinality(), FALSE, fixVariableZeroNode(), generateRowCardinality(), NULL, 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().
◆ generateRowCardinality()
|
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.
- Parameters
-
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 1994 of file cons_cardinality.c.
References FALSE, initsepaBoundInequalityFromCardinality(), NULL, 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().
◆ initsepaBoundInequalityFromCardinality()
|
static |
initialize or separate bound inequalities from cardinality constraints (see the function generateRowCardinality() for an explanation of bound inequalities)
- Parameters
-
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 2120 of file cons_cardinality.c.
References FALSE, generateRowCardinality(), NULL, 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().
◆ separateCardinality()
|
static |
separates cardinality constraints for arbitrary solutions
- Parameters
-
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 2233 of file cons_cardinality.c.
References initsepaBoundInequalityFromCardinality(), NULL, SCIP_Bool, SCIP_CALL, SCIP_CUTOFF, SCIP_DECL_CONSHDLRCOPY(), SCIP_DIDNOTFIND, SCIP_DIDNOTRUN, SCIP_OKAY, SCIP_SEPARATED, SCIPdebugMsg, SCIPisStopped(), and TRUE.
Referenced by initsepaBoundInequalityFromCardinality().
◆ SCIP_DECL_CONSHDLRCOPY()
|
static |
copy method for constraint handler plugins (called when SCIP copies plugins)
Definition at line 2281 of file cons_cardinality.c.
Referenced by separateCardinality().
◆ SCIP_DECL_CONSFREE()
|
static |
destructor of constraint handler to free constraint handler data (called when SCIP is exiting)
Definition at line 2297 of file cons_cardinality.c.
◆ SCIP_DECL_CONSEXITSOL()
|
static |
solving process deinitialization method of constraint handler (called before branch and bound process data is freed)
Definition at line 2321 of file cons_cardinality.c.
◆ SCIP_DECL_CONSDELETE()
|
static |
frees specific constraint data
Definition at line 2367 of file cons_cardinality.c.
◆ SCIP_DECL_CONSTRANS()
|
static |
transforms constraint data into data belonging to the transformed problem
Definition at line 2425 of file cons_cardinality.c.
◆ SCIP_DECL_CONSPRESOL()
|
static |
presolving method of constraint handler
Definition at line 2523 of file cons_cardinality.c.
◆ SCIP_DECL_CONSINITLP()
|
static |
LP initialization method of constraint handler (called before the initial LP relaxation at a node is solved)
Definition at line 2602 of file cons_cardinality.c.
◆ SCIP_DECL_CONSSEPALP()
|
static |
separation method of constraint handler for LP solutions
Definition at line 2618 of file cons_cardinality.c.
◆ SCIP_DECL_CONSSEPASOL()
|
static |
separation method of constraint handler for arbitrary primal solutions
Definition at line 2632 of file cons_cardinality.c.
◆ SCIP_DECL_CONSENFOLP()
|
static |
constraint enforcing method of constraint handler for LP solutions
Definition at line 2646 of file cons_cardinality.c.
◆ SCIP_DECL_CONSENFORELAX()
|
static |
constraint enforcing method of constraint handler for relaxation solutions
Definition at line 2661 of file cons_cardinality.c.
◆ SCIP_DECL_CONSENFOPS()
|
static |
constraint enforcing method of constraint handler for pseudo solutions
Definition at line 2676 of file cons_cardinality.c.
◆ SCIP_DECL_CONSCHECK()
|
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 2694 of file cons_cardinality.c.
◆ SCIP_DECL_CONSPROP()
|
static |
domain propagation method of constraint handler
Definition at line 2765 of file cons_cardinality.c.
◆ SCIP_DECL_CONSLOCK()
|
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 rhs of the constraint can be updated and the variable can be removed from the constraint. Thus, 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 2821 of file cons_cardinality.c.
◆ SCIP_DECL_CONSPRINT()
|
static |
constraint display method of constraint handler
Definition at line 2873 of file cons_cardinality.c.
◆ SCIP_DECL_CONSCOPY()
|
static |
constraint copying method of constraint handler
Definition at line 2903 of file cons_cardinality.c.
◆ SCIP_DECL_CONSPARSE()
|
static |
constraint parsing method of constraint handler
Definition at line 2982 of file cons_cardinality.c.
◆ SCIP_DECL_CONSGETVARS()
|
static |
constraint method of constraint handler which returns the variables (if possible)
Definition at line 3067 of file cons_cardinality.c.
◆ SCIP_DECL_CONSGETNVARS()
|
static |
constraint method of constraint handler which returns the number of variables (if possible)
Definition at line 3089 of file cons_cardinality.c.
◆ SCIP_DECL_EVENTEXEC()
|
static |
Definition at line 3110 of file cons_cardinality.c.