Scippy

SCIP

Solving Constraint Integer Programs

cons_sos1.c
Go to the documentation of this file.
1 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2 /* */
3 /* This file is part of the program and library */
4 /* SCIP --- Solving Constraint Integer Programs */
5 /* */
6 /* Copyright (C) 2002-2017 Konrad-Zuse-Zentrum */
7 /* fuer Informationstechnik Berlin */
8 /* */
9 /* SCIP is distributed under the terms of the ZIB Academic License. */
10 /* */
11 /* You should have received a copy of the ZIB Academic License */
12 /* along with SCIP; see the file COPYING. If not email to scip@zib.de. */
13 /* */
14 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
15 
16 /**@file cons_sos1.c
17  * @brief constraint handler for SOS type 1 constraints
18  * @author Tobias Fischer
19  * @author Marc Pfetsch
20  *
21  * A specially ordered set of type 1 (SOS1) is a sequence of variables such that at most one
22  * variable is nonzero. The special case of two variables arises, for instance, from equilibrium or
23  * complementary conditions like \f$x \cdot y = 0\f$. Note that it is in principle allowed that a
24  * variables appears twice, but it then can be fixed to 0.
25  *
26  * This implementation of this constraint handler is based on classical ideas, see e.g.@n
27  * "Special Facilities in General Mathematical Programming System for
28  * Non-Convex Problems Using Ordered Sets of Variables"@n
29  * E. Beale and J. Tomlin, Proc. 5th IFORS Conference, 447-454 (1970)
30  *
31  *
32  * The order of the variables is determined as follows:
33  *
34  * - If the constraint is created with SCIPcreateConsSOS1() and weights are given, the weights
35  * determine the order (decreasing weights). Additional variables can be added with
36  * SCIPaddVarSOS1(), which adds a variable with given weight.
37  *
38  * - If an empty constraint is created and then variables are added with SCIPaddVarSOS1(), weights
39  * are needed and stored.
40  *
41  * - All other calls ignore the weights, i.e., if a nonempty constraint is created or variables are
42  * added with SCIPappendVarSOS1().
43  *
44  * The validity of the SOS1 constraints can be enforced by different branching rules:
45  *
46  * - If classical SOS branching is used, branching is performed on only one SOS1 constraint.
47  * Depending on the parameters, there are two ways to choose this branching constraint. Either
48  * the constraint with the most number of nonzeros or the one with the largest nonzero-variable
49  * weight. The later version allows the user to specify an order for the branching importance of
50  * the constraints. Constraint branching can also be turned off.
51  *
52  * - Another way is to branch on the neighborhood of a single variable @p i, i.e., in one branch
53  * \f$x_i\f$ is fixed to zero and in the other its neighbors from the conflict graph.
54  *
55  * - If bipartite branching is used, then we branch using complete bipartite subgraphs of the
56  * conflict graph, i.e., in one branch fix the variables from the first bipartite partition and
57  * the variables from the second bipartite partition in the other.
58  *
59  * - In addition to variable domain fixings, it is sometimes also possible to add new SOS1
60  * constraints to the branching nodes. This results in a nonstatic conflict graph, which may
61  * change dynamically with every branching node.
62  *
63  *
64  * @todo Possibly allow to generate local cuts via strengthened local cuts (would need to modified coefficients of rows).
65  *
66  * @todo Check whether we can avoid turning off multi-aggregation (it is sometimes possible to fix a multi-aggregated
67  * variable to 0 by fixing the aggregating variables to 0).
68  */
69 
70 /*---+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0----+----1----+----2*/
71 
72 #include <assert.h>
73 
74 #include "scip/cons_sos1.h"
75 #include "scip/cons_linear.h"
76 #include "scip/cons_setppc.h"
77 #include "scip/pub_misc.h"
78 #include "scip/misc.h"
79 #include "scip/struct_misc.h"
80 #include "tclique/tclique.h"
81 #include <string.h>
82 #include <ctype.h>
83 
84 
85 /* constraint handler properties */
86 #define CONSHDLR_NAME "SOS1"
87 #define CONSHDLR_DESC "SOS1 constraint handler"
88 #define CONSHDLR_SEPAPRIORITY 1000 /**< priority of the constraint handler for separation */
89 #define CONSHDLR_ENFOPRIORITY 100 /**< priority of the constraint handler for constraint enforcing */
90 #define CONSHDLR_CHECKPRIORITY -10 /**< priority of the constraint handler for checking feasibility */
91 #define CONSHDLR_SEPAFREQ 10 /**< frequency for separating cuts; zero means to separate only in the root node */
92 #define CONSHDLR_PROPFREQ 1 /**< frequency for propagating domains; zero means only preprocessing propagation */
93 #define CONSHDLR_EAGERFREQ 100 /**< frequency for using all instead of only the useful constraints in separation,
94  * propagation and enforcement, -1 for no eager evaluations, 0 for first only */
95 #define CONSHDLR_MAXPREROUNDS -1 /**< maximal number of presolving rounds the constraint handler participates in (-1: no limit) */
96 #define CONSHDLR_DELAYSEPA FALSE /**< should separation method be delayed, if other separators found cuts? */
97 #define CONSHDLR_DELAYPROP FALSE /**< should propagation method be delayed, if other propagators found reductions? */
98 #define CONSHDLR_NEEDSCONS TRUE /**< should the constraint handler be skipped, if no constraints are available? */
99 #define CONSHDLR_PROP_TIMING SCIP_PROPTIMING_BEFORELP
100 #define CONSHDLR_PRESOLTIMING SCIP_PRESOLTIMING_MEDIUM
102 /* adjacency matrix */
103 #define DEFAULT_MAXSOSADJACENCY 10000 /**< do not create an adjacency matrix if number of SOS1 variables is larger than predefined value
104  * (-1: no limit) */
105 
106 /* presolving */
107 #define DEFAULT_MAXEXTENSIONS 1 /**< maximal number of extensions that will be computed for each SOS1 constraint */
108 #define DEFAULT_MAXTIGHTENBDS 5 /**< maximal number of bound tightening rounds per presolving round (-1: no limit) */
109 #define DEFAULT_PERFIMPLANALYSIS FALSE /**< if TRUE then perform implication graph analysis (might add additional SOS1 constraints) */
110 #define DEFAULT_DEPTHIMPLANALYSIS -1 /**< number of recursive calls of implication graph analysis (-1: no limit) */
112 /* propagation */
113 #define DEFAULT_CONFLICTPROP TRUE /**< whether to use conflict graph propagation */
114 #define DEFAULT_IMPLPROP TRUE /**< whether to use implication graph propagation */
115 #define DEFAULT_SOSCONSPROP FALSE /**< whether to use SOS1 constraint propagation */
117 /* branching rules */
118 #define DEFAULT_BRANCHSTRATEGIES "nbs" /**< possible branching strategies (see parameter DEFAULT_BRANCHINGRULE) */
119 #define DEFAULT_BRANCHINGRULE 'n' /**< which branching rule should be applied ? ('n': neighborhood, 'b': bipartite, 's': SOS1/clique)
120  * (note: in some cases an automatic switching to SOS1 branching is possible) */
121 #define DEFAULT_AUTOSOS1BRANCH TRUE /**< if TRUE then automatically switch to SOS1 branching if the SOS1 constraints do not overlap */
122 #define DEFAULT_FIXNONZERO FALSE /**< if neighborhood branching is used, then fix the branching variable (if positive in sign) to the value of the
123  * feasibility tolerance */
124 #define DEFAULT_ADDCOMPS FALSE /**< if TRUE then add complementarity constraints to the branching nodes (can be used in combination with
125  * neighborhood or bipartite branching) */
126 #define DEFAULT_MAXADDCOMPS -1 /**< maximal number of complementarity constraints added per branching node (-1: no limit) */
127 #define DEFAULT_ADDCOMPSDEPTH 30 /**< only add complementarity constraints to branching nodes for predefined depth (-1: no limit) */
128 #define DEFAULT_ADDCOMPSFEAS -0.6 /**< minimal feasibility value for complementarity constraints in order to be added to the branching node */
129 #define DEFAULT_ADDBDSFEAS 1.0 /**< minimal feasibility value for bound inequalities in order to be added to the branching node */
130 #define DEFAULT_ADDEXTENDEDBDS TRUE /**< should added complementarity constraints be extended to SOS1 constraints to get tighter bound inequalities */
132 /* selection rules */
133 #define DEFAULT_NSTRONGROUNDS 0 /**< maximal number of strong branching rounds to perform for each node (-1: auto)
134  * (only available for neighborhood and bipartite branching) */
135 #define DEFAULT_NSTRONGITER 10000 /**< maximal number LP iterations to perform for each strong branching round (-2: auto, -1: no limit) */
136 
137 /* separation */
138 #define DEFAULT_BOUNDCUTSFROMSOS1 FALSE /**< if TRUE separate bound inequalities from SOS1 constraints */
139 #define DEFAULT_BOUNDCUTSFROMGRAPH TRUE /**< if TRUE separate bound inequalities from the conflict graph */
140 #define DEFAULT_AUTOCUTSFROMSOS1 TRUE /**< if TRUE then automatically switch to separating from SOS1 constraints if the SOS1 constraints do not overlap */
141 #define DEFAULT_BOUNDCUTSFREQ 10 /**< frequency for separating bound cuts; zero means to separate only in the root node */
142 #define DEFAULT_BOUNDCUTSDEPTH 40 /**< node depth of separating bound cuts (-1: no limit) */
143 #define DEFAULT_MAXBOUNDCUTS 50 /**< maximal number of bound cuts separated per branching node */
144 #define DEFAULT_MAXBOUNDCUTSROOT 150 /**< maximal number of bound cuts separated per iteration in the root node */
145 #define DEFAULT_STRTHENBOUNDCUTS TRUE /**< if TRUE then bound cuts are strengthened in case bound variables are available */
146 #define DEFAULT_IMPLCUTSFREQ 0 /**< frequency for separating implied bound cuts; zero means to separate only in the root node */
147 #define DEFAULT_IMPLCUTSDEPTH 40 /**< node depth of separating implied bound cuts (-1: no limit) */
148 #define DEFAULT_MAXIMPLCUTS 50 /**< maximal number of implied bound cuts separated per branching node */
149 #define DEFAULT_MAXIMPLCUTSROOT 150 /**< maximal number of implied bound cuts separated per iteration in the root node */
151 /* event handler properties */
152 #define EVENTHDLR_NAME "SOS1"
153 #define EVENTHDLR_DESC "bound change event handler for SOS1 constraints"
155 /* defines */
156 #define DIVINGCUTOFFVALUE 1e6
157 
159 /** constraint data for SOS1 constraints */
160 struct SCIP_ConsData
161 {
162  int nvars; /**< number of variables in the constraint */
163  int maxvars; /**< maximal number of variables (= size of storage) */
164  int nfixednonzeros; /**< number of variables fixed to be nonzero */
165  SCIP_Bool local; /**< TRUE if constraint is only valid locally */
166  SCIP_VAR** vars; /**< variables in constraint */
167  SCIP_ROW* rowlb; /**< row corresponding to lower bounds, or NULL if not yet created */
168  SCIP_ROW* rowub; /**< row corresponding to upper bounds, or NULL if not yet created */
169  SCIP_Real* weights; /**< weights determining the order (ascending), or NULL if not used */
170 };
171 
172 
173 /** node data of a given node in the conflict graph */
174 struct SCIP_NodeData
175 {
176  SCIP_VAR* var; /**< variable belonging to node */
177  SCIP_VAR* lbboundvar; /**< bound variable @p z from constraint \f$x \geq \mu \cdot z\f$ (or NULL if not existent) */
178  SCIP_VAR* ubboundvar; /**< bound variable @p z from constraint \f$x \leq \mu \cdot z\f$ (or NULL if not existent) */
179  SCIP_Real lbboundcoef; /**< value \f$\mu\f$ from constraint \f$x \geq \mu z \f$ (0.0 if not existent) */
180  SCIP_Real ubboundcoef; /**< value \f$\mu\f$ from constraint \f$x \leq \mu z \f$ (0.0 if not existent) */
181  SCIP_Bool lbboundcomp; /**< TRUE if the nodes from the connected component of the conflict graph the given node belongs to
182  * all have the same lower bound variable */
183  SCIP_Bool ubboundcomp; /**< TRUE if the nodes from the connected component of the conflict graph the given node belongs to
184  * all have the same lower bound variable */
185 };
186 typedef struct SCIP_NodeData SCIP_NODEDATA;
187 
188 
189 /** successor data of a given nodes successor in the implication graph */
190 struct SCIP_SuccData
191 {
192  SCIP_Real lbimpl; /**< lower bound implication */
193  SCIP_Real ubimpl; /**< upper bound implication */
194 };
195 typedef struct SCIP_SuccData SCIP_SUCCDATA;
196 
197 
198 /** tclique data for bound cut generation */
199 struct TCLIQUE_Data
200 {
201  SCIP* scip; /**< SCIP data structure */
202  SCIP_CONSHDLR* conshdlr; /**< SOS1 constraint handler */
203  SCIP_DIGRAPH* conflictgraph; /**< conflict graph */
204  SCIP_SOL* sol; /**< LP solution to be separated (or NULL) */
205  SCIP_Real scaleval; /**< factor for scaling weights */
206  SCIP_Bool cutoff; /**< whether a cutoff occurred */
207  int ncuts; /**< number of bound cuts found in this iteration */
208  int nboundcuts; /**< number of bound cuts found so far */
209  int maxboundcuts; /**< maximal number of clique cuts separated per separation round (-1: no limit) */
210  SCIP_Bool strthenboundcuts; /**< if TRUE then bound cuts are strengthened in case bound variables are available */
211 };
214 /** SOS1 constraint handler data */
215 struct SCIP_ConshdlrData
216 {
217  /* conflict graph */
218  SCIP_DIGRAPH* conflictgraph; /**< conflict graph */
219  SCIP_DIGRAPH* localconflicts; /**< local conflicts */
220  SCIP_Bool isconflocal; /**< if TRUE then local conflicts are present and conflict graph has to be updated for each node */
221  SCIP_HASHMAP* varhash; /**< hash map from variable to node in the conflict graph */
222  int nsos1vars; /**< number of problem variables that are part of the SOS1 conflict graph */
223  /* adjacency matrix */
224  int maxsosadjacency; /**< do not create an adjacency matrix if number of SOS1 variables is larger than predefined
225  * value (-1: no limit) */
226  /* implication graph */
227  SCIP_DIGRAPH* implgraph; /**< implication graph (@p j is successor of @p i if and only if \f$ x_i\not = 0 \Rightarrow x_j\not = 0\f$) */
228  int nimplnodes; /**< number of nodes in the implication graph */
229  /* tclique graph */
230  TCLIQUE_GRAPH* tcliquegraph; /**< tclique graph data structure */
231  TCLIQUE_DATA* tcliquedata; /**< tclique data */
232  /* event handler */
233  SCIP_EVENTHDLR* eventhdlr; /**< event handler for bound change events */
234  SCIP_VAR** fixnonzerovars; /**< stack of variables fixed to nonzero marked by event handler */
235  int maxnfixnonzerovars; /**< size of stack fixnonzerovars */
236  int nfixnonzerovars; /**< number of variables fixed to nonzero marked by event handler */
237  /* presolving */
238  int cntextsos1; /**< counts number of extended SOS1 constraints */
239  int maxextensions; /**< maximal number of extensions that will be computed for each SOS1 constraint */
240  int maxtightenbds; /**< maximal number of bound tightening rounds per presolving round (-1: no limit) */
241  SCIP_Bool perfimplanalysis; /**< if TRUE then perform implication graph analysis (might add additional SOS1 constraints) */
242  int depthimplanalysis; /**< number of recursive calls of implication graph analysis (-1: no limit) */
243  /* propagation */
244  SCIP_Bool conflictprop; /**< whether to use conflict graph propagation */
245  SCIP_Bool implprop; /**< whether to use implication graph propagation */
246  SCIP_Bool sosconsprop; /**< whether to use SOS1 constraint propagation */
247  /* branching */
248  char branchingrule; /**< which branching rule should be applied ? ('n': neighborhood, 'b': bipartite, 's': SOS1/clique)
249  * (note: in some cases an automatic switching to SOS1 branching is possible) */
250  SCIP_Bool autosos1branch; /**< if TRUE then automatically switch to SOS1 branching if the SOS1 constraints do not overlap */
251  SCIP_Bool fixnonzero; /**< if neighborhood branching is used, then fix the branching variable (if positive in sign) to the value of the
252  * feasibility tolerance */
253  SCIP_Bool addcomps; /**< if TRUE then add complementarity constraints to the branching nodes additionally to domain fixings
254  * (can be used in combination with neighborhood or bipartite branching) */
255  int maxaddcomps; /**< maximal number of complementarity cons. and cor. bound ineq. added per branching node (-1: no limit) */
256  int addcompsdepth; /**< only add complementarity constraints to branching nodes for predefined depth (-1: no limit) */
257  SCIP_Real addcompsfeas; /**< minimal feasibility value for complementarity constraints in order to be added to the branching node */
258  SCIP_Real addbdsfeas; /**< minimal feasibility value for bound inequalities in order to be added to the branching node */
259  SCIP_Bool addextendedbds; /**< should added complementarity constraints be extended to SOS1 constraints to get tighter bound inequalities */
260  SCIP_Bool branchsos; /**< Branch on SOS condition in enforcing? This value can only be set to false if all SOS1 variables are binary */
261  SCIP_Bool branchnonzeros; /**< Branch on SOS cons. with most number of nonzeros? */
262  SCIP_Bool branchweight; /**< Branch on SOS cons. with highest nonzero-variable weight for branching - needs branchnonzeros to be false */
263  SCIP_Bool switchsos1branch; /**< whether to switch to SOS1 branching */
264  /* selection rules */
265  int nstrongrounds; /**< maximal number of strong branching rounds to perform for each node (-1: auto)
266  * (only available for neighborhood and bipartite branching) */
267  int nstrongiter; /**< maximal number LP iterations to perform for each strong branching round (-2: auto, -1: no limit) */
268  /* separation */
269  SCIP_Bool boundcutsfromsos1; /**< if TRUE separate bound inequalities from SOS1 constraints */
270  SCIP_Bool boundcutsfromgraph; /**< if TRUE separate bound inequalities from the conflict graph */
271  SCIP_Bool autocutsfromsos1; /**< if TRUE then automatically switch to separating SOS1 constraints if the SOS1 constraints do not overlap */
272  SCIP_Bool switchcutsfromsos1; /**< whether to switch to separate bound inequalities from SOS1 constraints */
273  int boundcutsfreq; /**< frequency for separating bound cuts; zero means to separate only in the root node */
274  int boundcutsdepth; /**< node depth of separating bound cuts (-1: no limit) */
275  int maxboundcuts; /**< maximal number of bound cuts separated per branching node */
276  int maxboundcutsroot; /**< maximal number of bound cuts separated per iteration in the root node */
277  int nboundcuts; /**< number of bound cuts found so far */
278  SCIP_Bool strthenboundcuts; /**< if TRUE then bound cuts are strengthened in case bound variables are available */
279  int implcutsfreq; /**< frequency for separating implied bound cuts; zero means to separate only in the root node */
280  int implcutsdepth; /**< node depth of separating implied bound cuts (-1: no limit) */
281  int maximplcuts; /**< maximal number of implied bound cuts separated per branching node */
282  int maximplcutsroot; /**< maximal number of implied bound cuts separated per iteration in the root node */
283 };
284 
285 
286 
287 /*
288  * local methods
289  */
290 
291 /** returns whether two vertices are adjacent in the conflict graph */
292 static
294  SCIP_Bool** adjacencymatrix, /**< adjacency matrix of conflict graph (lower half) (or NULL if an adjacencymatrix is not at hand) */
295  SCIP_DIGRAPH* conflictgraph, /**< conflict graph (or NULL if an adjacencymatrix is at hand) */
296  int vertex1, /**< first vertex */
297  int vertex2 /**< second vertex */
298  )
299 {
300  assert( adjacencymatrix != NULL || conflictgraph != NULL );
301 
302  /* we do not allow self-loops */
303  if ( vertex1 == vertex2 )
304  return FALSE;
305 
306  /* for debugging */
307  if ( adjacencymatrix == NULL )
308  {
309  int succvertex;
310  int* succ;
311  int nsucc1;
312  int nsucc2;
313  int j;
314 
315  nsucc1 = SCIPdigraphGetNSuccessors(conflictgraph, vertex1);
316  nsucc2 = SCIPdigraphGetNSuccessors(conflictgraph, vertex2);
317 
318  if ( nsucc1 < 1 || nsucc2 < 1 )
319  return FALSE;
320 
321  if ( nsucc1 > nsucc2 )
322  {
323  SCIPswapInts(&vertex1, &vertex2);
324  SCIPswapInts(&nsucc1, &nsucc2);
325  }
326 
327  succ = SCIPdigraphGetSuccessors(conflictgraph, vertex1);
328  SCIPsortInt(succ, nsucc1);
329 
330  for (j = 0; j < nsucc1; ++j)
331  {
332  succvertex = succ[j];
333  if ( succvertex == vertex2 )
334  return TRUE;
335  else if ( succvertex > vertex2 )
336  return FALSE;
337  }
338  }
339  else
340  {
341  if ( vertex1 < vertex2 )
342  return adjacencymatrix[vertex2][vertex1];
343  else
344  return adjacencymatrix[vertex1][vertex2];
345  }
346 
347  return FALSE;
348 }
349 
350 
351 /** checks whether a variable violates an SOS1 constraint w.r.t. sol together with at least one other variable */
352 static
354  SCIP* scip, /**< SCIP data structure */
355  SCIP_DIGRAPH* conflictgraph, /**< conflict graph (or NULL if an adjacencymatrix is at hand) */
356  int node, /**< node of variable in the conflict graph */
357  SCIP_SOL* sol /**< solution, or NULL to use current node's solution */
358  )
359 {
360  SCIP_Real solval;
361  SCIP_VAR* var;
362 
363  assert( scip != NULL );
364  assert( conflictgraph != NULL );
365  assert( node >= 0 );
366 
367  var = SCIPnodeGetVarSOS1(conflictgraph, node);
368  assert( var != NULL );
369  solval = SCIPgetSolVal(scip, sol, var);
370 
371  /* check whether variable is nonzero w.r.t. sol and the bounds have not been fixed to zero by propagation */
372  if ( ! SCIPisFeasZero(scip, solval) && ( ! SCIPisFeasZero(scip, SCIPvarGetLbLocal(var)) || ! SCIPisFeasZero(scip, SCIPvarGetUbLocal(var)) ) )
373  {
374  int* succ;
375  int nsucc;
376  int s;
377 
378  nsucc = SCIPdigraphGetNSuccessors(conflictgraph, node);
379  succ = SCIPdigraphGetSuccessors(conflictgraph, node);
380 
381  /* check whether a neighbor variable is nonzero w.r.t. sol */
382  for (s = 0; s < nsucc; ++s)
383  {
384  var = SCIPnodeGetVarSOS1(conflictgraph, succ[s]);
385  assert( var != NULL );
386  solval = SCIPgetSolVal(scip, sol, var);
387  if ( ! SCIPisFeasZero(scip, solval) && ( ! SCIPisFeasZero(scip, SCIPvarGetLbLocal(var)) || ! SCIPisFeasZero(scip, SCIPvarGetUbLocal(var)) ) )
388  return TRUE;
389  }
390  }
391 
392  return FALSE;
393 }
394 
395 
396 /** returns solution value of imaginary binary big-M variable of a given node from the conflict graph */
397 static
399  SCIP* scip, /**< SCIP pointer */
400  SCIP_DIGRAPH* conflictgraph, /**< conflict graph */
401  SCIP_SOL* sol, /**< primal solution, or NULL for current LP/pseudo solution */
402  int node /**< node of the conflict graph */
403  )
404 {
406  SCIP_VAR* var;
407  SCIP_Real val;
408 
409  assert( scip != NULL );
410  assert( conflictgraph != NULL );
411  assert( node >= 0 && node < SCIPdigraphGetNNodes(conflictgraph) );
412 
413  var = SCIPnodeGetVarSOS1(conflictgraph, node);
414  val = SCIPgetSolVal(scip, sol, var);
415 
416  if ( SCIPisFeasNegative(scip, val) )
417  {
418  bound = SCIPvarGetLbLocal(var);
419  assert( SCIPisFeasNegative(scip, bound) );
420 
421  if ( SCIPisInfinity(scip, -val) )
422  return 1.0;
423  else if ( SCIPisInfinity(scip, -bound) )
424  return 0.0;
425  else
426  return (val/bound);
427  }
428  else if ( SCIPisFeasPositive(scip, val) )
429  {
430  bound = SCIPvarGetUbLocal(var);
431  assert( SCIPisFeasPositive(scip, bound) );
432  assert( SCIPisFeasPositive(scip, val) );
433 
434  if ( SCIPisInfinity(scip, val) )
435  return 1.0;
436  else if ( SCIPisInfinity(scip, bound) )
437  return 0.0;
438  else
439  return (val/bound);
440  }
441  else
442  return 0.0;
443 }
444 
445 
446 /** gets (variable) lower bound value of current LP relaxation solution for a given node from the conflict graph */
447 static
449  SCIP* scip, /**< SCIP pointer */
450  SCIP_DIGRAPH* conflictgraph, /**< conflict graph */
451  SCIP_SOL* sol, /**< primal solution, or NULL for current LP/pseudo solution */
452  int node /**< node of the conflict graph */
453  )
454 {
455  SCIP_NODEDATA* nodedata;
456 
457  assert( scip != NULL );
458  assert( conflictgraph != NULL );
459  assert( node >= 0 && node < SCIPdigraphGetNNodes(conflictgraph) );
460 
461  /* get node data */
462  nodedata = (SCIP_NODEDATA*)SCIPdigraphGetNodeData(conflictgraph, node);
463  assert( nodedata != NULL );
464 
465  /* if variable is not involved in a variable upper bound constraint */
466  if ( nodedata->lbboundvar == NULL || ! nodedata->lbboundcomp )
467  return SCIPvarGetLbLocal(nodedata->var);
468 
469  return nodedata->lbboundcoef * SCIPgetSolVal(scip, sol, nodedata->lbboundvar);
470 }
471 
472 
473 /** gets (variable) upper bound value of current LP relaxation solution for a given node from the conflict graph */
474 static
476  SCIP* scip, /**< SCIP pointer */
477  SCIP_DIGRAPH* conflictgraph, /**< conflict graph */
478  SCIP_SOL* sol, /**< primal solution, or NULL for current LP/pseudo solution */
479  int node /**< node of the conflict graph */
480  )
481 {
482  SCIP_NODEDATA* nodedata;
483 
484  assert( scip != NULL );
485  assert( conflictgraph != NULL );
486  assert( node >= 0 && node < SCIPdigraphGetNNodes(conflictgraph) );
487 
488  /* get node data */
489  nodedata = (SCIP_NODEDATA*)SCIPdigraphGetNodeData(conflictgraph, node);
490  assert( nodedata != NULL );
491 
492  /* if variable is not involved in a variable upper bound constraint */
493  if ( nodedata->ubboundvar == NULL || ! nodedata->ubboundcomp )
494  return SCIPvarGetUbLocal(nodedata->var);
495 
496  return nodedata->ubboundcoef * SCIPgetSolVal(scip, sol, nodedata->ubboundvar);
497 }
498 
499 
500 /** returns whether variable is part of the SOS1 conflict graph */
501 static
503  SCIP_CONSHDLRDATA* conshdlrdata, /**< SOS1 constraint handler */
504  SCIP_VAR* var /**< variable */
505  )
506 {
507  assert( conshdlrdata != NULL );
508  assert( var != NULL );
509 
510  if ( conshdlrdata->varhash == NULL || ! SCIPhashmapExists(conshdlrdata->varhash, var) )
511  return FALSE;
512 
513  return TRUE;
514 }
515 
516 
517 /** returns SOS1 index of variable or -1 if variable is not part of the SOS1 conflict graph */
518 static
519 int varGetNodeSOS1(
520  SCIP_CONSHDLRDATA* conshdlrdata, /**< SOS1 constraint handler */
521  SCIP_VAR* var /**< variable */
522  )
523 {
524  assert( conshdlrdata != NULL );
525  assert( var != NULL );
526  assert( conshdlrdata->varhash != NULL );
527 
528  if ( ! SCIPhashmapExists(conshdlrdata->varhash, var) )
529  return -1;
530 
531  return (int) (size_t) SCIPhashmapGetImage(conshdlrdata->varhash, var);
532 }
533 
534 
535 /** fix variable in given node to 0 or add constraint if variable is multi-aggregated
536  *
537  * @todo Try to handle multi-aggregated variables as in fixVariableZero() below.
538  */
539 static
541  SCIP* scip, /**< SCIP pointer */
542  SCIP_VAR* var, /**< variable to be fixed to 0*/
543  SCIP_NODE* node, /**< node */
544  SCIP_Bool* infeasible /**< if fixing is infeasible */
545  )
546 {
547  /* if variable cannot be nonzero */
548  *infeasible = FALSE;
550  {
551  *infeasible = TRUE;
552  return SCIP_OKAY;
553  }
554 
555  /* if variable is multi-aggregated */
557  {
558  SCIP_CONS* cons;
559  SCIP_Real val;
560 
561  val = 1.0;
562 
563  if ( ! SCIPisFeasZero(scip, SCIPvarGetLbLocal(var)) || ! SCIPisFeasZero(scip, SCIPvarGetUbLocal(var)) )
564  {
565  SCIPdebugMsg(scip, "creating constraint to force multi-aggregated variable <%s> to 0.\n", SCIPvarGetName(var));
566  /* we have to insert a local constraint var = 0 */
567  SCIP_CALL( SCIPcreateConsLinear(scip, &cons, "branch", 1, &var, &val, 0.0, 0.0, TRUE, TRUE, TRUE, TRUE, TRUE,
568  TRUE, FALSE, FALSE, FALSE, FALSE) );
569  SCIP_CALL( SCIPaddConsNode(scip, node, cons, NULL) );
570  SCIP_CALL( SCIPreleaseCons(scip, &cons) );
571  }
572  }
573  else
574  {
575  if ( ! SCIPisFeasZero(scip, SCIPvarGetLbLocal(var)) )
576  SCIP_CALL( SCIPchgVarLbNode(scip, node, var, 0.0) );
577  if ( ! SCIPisFeasZero(scip, SCIPvarGetUbLocal(var)) )
578  SCIP_CALL( SCIPchgVarUbNode(scip, node, var, 0.0) );
579  }
580 
581  return SCIP_OKAY;
582 }
583 
584 
585 /** try to fix variable to 0
586  *
587  * Try to treat fixing by special consideration of multiaggregated variables. For a multi-aggregation
588  * \f[
589  * x = \sum_{i=1}^n \alpha_i x_i + c,
590  * \f]
591  * we can express the fixing \f$x = 0\f$ by fixing all \f$x_i\f$ to 0 if \f$c = 0\f$ and the lower bounds of \f$x_i\f$
592  * are nonnegative if \f$\alpha_i > 0\f$ or the upper bounds are nonpositive if \f$\alpha_i < 0\f$.
593  */
594 static
596  SCIP* scip, /**< SCIP pointer */
597  SCIP_VAR* var, /**< variable to be fixed to 0*/
598  SCIP_Bool* infeasible, /**< if fixing is infeasible */
599  SCIP_Bool* tightened /**< if fixing was performed */
600  )
601 {
602  assert( scip != NULL );
603  assert( var != NULL );
604  assert( infeasible != NULL );
605  assert( tightened != NULL );
606 
607  *infeasible = FALSE;
608  *tightened = FALSE;
609 
611  {
612  SCIP_Real aggrconst;
613 
614  /* if constant is 0 */
615  aggrconst = SCIPvarGetMultaggrConstant(var);
616  if ( SCIPisZero(scip, aggrconst) )
617  {
618  SCIP_VAR** aggrvars;
619  SCIP_Real* aggrvals;
620  SCIP_Bool allnonnegative = TRUE;
621  int naggrvars;
622  int i;
623 
625 
626  /* check whether all variables are "nonnegative" */
627  naggrvars = SCIPvarGetMultaggrNVars(var);
628  aggrvars = SCIPvarGetMultaggrVars(var);
629  aggrvals = SCIPvarGetMultaggrScalars(var);
630  for (i = 0; i < naggrvars; ++i)
631  {
632  if ( (SCIPisPositive(scip, aggrvals[i]) && SCIPisNegative(scip, SCIPvarGetLbLocal(aggrvars[i]))) ||
633  (SCIPisNegative(scip, aggrvals[i]) && SCIPisPositive(scip, SCIPvarGetUbLocal(aggrvars[i]))) )
634  {
635  allnonnegative = FALSE;
636  break;
637  }
638  }
639 
640  if ( allnonnegative )
641  {
642  /* all variables are nonnegative -> fix variables */
643  for (i = 0; i < naggrvars; ++i)
644  {
645  SCIP_Bool fixed;
646  SCIP_CALL( SCIPfixVar(scip, aggrvars[i], 0.0, infeasible, &fixed) );
647  if ( *infeasible )
648  return SCIP_OKAY;
649  *tightened = *tightened || fixed;
650  }
651  }
652  }
653  }
654  else
655  {
656  SCIP_CALL( SCIPfixVar(scip, var, 0.0, infeasible, tightened) );
657  }
658 
659  return SCIP_OKAY;
660 }
661 
662 
663 /** fix variable in local node to 0, and return whether the operation was feasible
664  *
665  * @note We do not add a linear constraint if the variable is multi-aggregated as in
666  * fixVariableZeroNode(), since this would be too time consuming.
667  */
668 static
670  SCIP* scip, /**< SCIP pointer */
671  SCIP_VAR* var, /**< variable to be fixed to 0*/
672  SCIP_CONS* cons, /**< constraint */
673  int inferinfo, /**< info for reverse prop. */
674  SCIP_Bool* infeasible, /**< if fixing is infeasible */
675  SCIP_Bool* tightened, /**< if fixing was performed */
676  SCIP_Bool* success /**< whether fixing was successful, i.e., variable is not multi-aggregated */
677  )
678 {
679  *infeasible = FALSE;
680  *tightened = FALSE;
681  *success = FALSE;
682 
683  /* if variable cannot be nonzero */
685  {
686  *infeasible = TRUE;
687  return SCIP_OKAY;
688  }
689 
690  /* directly fix variable if it is not multi-aggregated */
692  {
693  SCIP_Bool tighten;
694 
695  /* fix lower bound */
696  SCIP_CALL( SCIPinferVarLbCons(scip, var, 0.0, cons, inferinfo, FALSE, infeasible, &tighten) );
697  *tightened = *tightened || tighten;
698 
699  /* fix upper bound */
700  SCIP_CALL( SCIPinferVarUbCons(scip, var, 0.0, cons, inferinfo, FALSE, infeasible, &tighten) );
701  *tightened = *tightened || tighten;
702 
703  *success = TRUE;
704  }
705 
706  return SCIP_OKAY;
707 }
708 
709 
710 /** add lock on variable */
711 static
713  SCIP* scip, /**< SCIP data structure */
714  SCIP_CONS* cons, /**< constraint */
715  SCIP_VAR* var /**< variable */
716  )
717 {
718  assert( scip != NULL );
719  assert( cons != NULL );
720  assert( var != NULL );
721 
722  /* rounding down == bad if lb < 0, rounding up == bad if ub > 0 */
724 
725  return SCIP_OKAY;
726 }
727 
728 
729 /** remove lock on variable */
730 static
732  SCIP* scip, /**< SCIP data structure */
733  SCIP_CONS* cons, /**< constraint */
734  SCIP_VAR* var /**< variable */
735  )
736 {
737  assert( scip != NULL );
738  assert( cons != NULL );
739  assert( var != NULL );
740 
741  /* rounding down == bad if lb < 0, rounding up == bad if ub > 0 */
743 
744  return SCIP_OKAY;
745 }
746 
747 
748 /** ensures that the vars and weights array can store at least num entries */
749 static
751  SCIP* scip, /**< SCIP data structure */
752  SCIP_CONSDATA* consdata, /**< constraint data */
753  int num, /**< minimum number of entries to store */
754  SCIP_Bool reserveWeights /**< whether the weights array is handled */
755  )
756 {
757  assert( consdata != NULL );
758  assert( consdata->nvars <= consdata->maxvars );
759 
760  if ( num > consdata->maxvars )
761  {
762  int newsize;
763 
764  newsize = SCIPcalcMemGrowSize(scip, num);
765  SCIP_CALL( SCIPreallocBlockMemoryArray(scip, &consdata->vars, consdata->maxvars, newsize) );
766  if ( reserveWeights )
767  SCIP_CALL( SCIPreallocBlockMemoryArray(scip, &consdata->weights, consdata->maxvars, newsize) );
768  consdata->maxvars = newsize;
769  }
770  assert( num <= consdata->maxvars );
771 
772  return SCIP_OKAY;
773 }
774 
775 
776 /** handle new variable */
777 static
779  SCIP* scip, /**< SCIP data structure */
780  SCIP_CONS* cons, /**< constraint */
781  SCIP_CONSDATA* consdata, /**< constraint data */
782  SCIP_CONSHDLRDATA* conshdlrdata, /**< constraint handler data */
783  SCIP_VAR* var, /**< variable */
784  SCIP_Bool transformed /**< whether original variable was transformed */
785  )
786 {
787  SCIP_DIGRAPH* conflictgraph;
788  int node;
789 
790  assert( scip != NULL );
791  assert( cons != NULL );
792  assert( consdata != NULL );
793  assert( conshdlrdata != NULL );
794  assert( var != NULL );
795 
796  /* if we are in transformed problem, catch the variable's events */
797  if ( transformed )
798  {
799  assert( conshdlrdata->eventhdlr != NULL );
800 
801  /* catch bound change events of variable */
802  SCIP_CALL( SCIPcatchVarEvent(scip, var, SCIP_EVENTTYPE_BOUNDCHANGED, conshdlrdata->eventhdlr,
803  (SCIP_EVENTDATA*)cons, NULL) ); /*lint !e740*/
804 
805  /* if the variable if fixed to nonzero */
806  assert( consdata->nfixednonzeros >= 0 );
808  ++consdata->nfixednonzeros;
809  }
810 
811  /* install the rounding locks for the new variable */
812  SCIP_CALL( lockVariableSOS1(scip, cons, var) );
813 
814  /* branching on multiaggregated variables does not seem to work well, so avoid it */
815  SCIP_CALL( SCIPmarkDoNotMultaggrVar(scip, var) );
816 
817  /* add the new coefficient to the upper bound LP row, if necessary */
818  if ( consdata->rowub != NULL && ! SCIPisInfinity(scip, SCIPvarGetUbGlobal(var)) && ! SCIPisZero(scip, SCIPvarGetUbGlobal(var)) )
819  {
820  SCIP_CALL( SCIPaddVarToRow(scip, consdata->rowub, var, 1.0/SCIPvarGetUbGlobal(var)) );
821  }
822 
823  /* add the new coefficient to the lower bound LP row, if necessary */
824  if ( consdata->rowlb != NULL && ! SCIPisInfinity(scip, SCIPvarGetLbGlobal(var)) && ! SCIPisZero(scip, SCIPvarGetLbGlobal(var)) )
825  {
826  SCIP_CALL( SCIPaddVarToRow(scip, consdata->rowlb, var, 1.0/SCIPvarGetLbGlobal(var)) );
827  }
828 
829  /* return if the conflict graph has not been created yet */
830  conflictgraph = conshdlrdata->conflictgraph;
831  if ( conflictgraph == NULL )
832  return SCIP_OKAY;
833 
834  /* get node of variable in the conflict graph (or -1) */
835  node = varGetNodeSOS1(conshdlrdata, var);
836  assert( node < conshdlrdata->nsos1vars );
837 
838  /* if the variable is not already a node of the conflict graph */
839  if ( node < 0 )
840  {
841  /* variable does not appear in the conflict graph: switch to SOS1 branching rule, which does not make use of a conflict graph
842  * @todo: maybe recompute the conflict graph, implication graph and varhash instead */
843  SCIPdebugMsg(scip, "Switched to SOS1 branching rule, since conflict graph could be infeasible.\n");
844  conshdlrdata->switchsos1branch = TRUE;
845  return SCIP_OKAY;
846  }
847 
848  /* if the constraint is local, then there is no need to act, since local constraints are handled by the local conflict graph in the
849  * function enforceConflictgraph() */
850  if ( ! consdata->local )
851  {
852  SCIP_VAR** vars;
853  int nvars;
854  int v;
855 
856  vars = consdata->vars;
857  nvars = consdata->nvars;
858 
859  for (v = 0; v < nvars; ++v)
860  {
861  int nodev;
862 
863  if ( var == vars[v] )
864  continue;
865 
866  /* get node of variable in the conflict graph (or -1) */
867  nodev = varGetNodeSOS1(conshdlrdata, vars[v]);
868  assert( nodev < conshdlrdata->nsos1vars );
869 
870  /* if the variable is already a node of the conflict graph */
871  if ( nodev >= 0 )
872  {
873  int nsucc;
874  int nsuccv;
875 
876  nsucc = SCIPdigraphGetNSuccessors(conflictgraph, node);
877  nsuccv = SCIPdigraphGetNSuccessors(conflictgraph, nodev);
878 
879  /* add arcs if not existent */
880  SCIP_CALL( SCIPdigraphAddArcSafe(conflictgraph, nodev, node, NULL) );
881  SCIP_CALL( SCIPdigraphAddArcSafe(conflictgraph, node, nodev, NULL) );
882 
883  /* in case of new arcs: sort successors in ascending order */
884  if ( nsucc < SCIPdigraphGetNSuccessors(conflictgraph, node) )
885  {
886  SCIPdebugMsg(scip, "Added new conflict graph arc from variable %s to variable %s.\n", SCIPvarGetName(var), SCIPvarGetName(vars[v]));
887  SCIPsortInt(SCIPdigraphGetSuccessors(conflictgraph, node), SCIPdigraphGetNSuccessors(conflictgraph, node));
888  }
889 
890  if ( nsuccv < SCIPdigraphGetNSuccessors(conflictgraph, nodev) )
891  {
892  SCIPdebugMsg(scip, "Added new conflict graph arc from variable %s to variable %s.\n", SCIPvarGetName(vars[v]), SCIPvarGetName(var));
893  SCIPsortInt(SCIPdigraphGetSuccessors(conflictgraph, nodev), SCIPdigraphGetNSuccessors(conflictgraph, nodev));
894  }
895  }
896  else
897  {
898  /* variable does not appear in the conflict graph: switch to SOS1 branching rule, which does not make use of a conflict graph
899  * @todo: maybe recompute the conflict graph, implication graph and varhash instead */
900  SCIPdebugMsg(scip, "Switched to SOS1 branching rule, since conflict graph could be infeasible.\n");
901  conshdlrdata->switchsos1branch = TRUE;
902  return SCIP_OKAY;
903  }
904  }
905  }
906 
907  return SCIP_OKAY;
908 }
909 
910 
911 /** adds a variable to an SOS1 constraint, at position given by weight - ascending order */
912 static
914  SCIP* scip, /**< SCIP data structure */
915  SCIP_CONS* cons, /**< constraint */
916  SCIP_CONSHDLRDATA* conshdlrdata, /**< constraint handler data */
917  SCIP_VAR* var, /**< variable to add to the constraint */
918  SCIP_Real weight /**< weight to determine position */
919  )
920 {
921  SCIP_CONSDATA* consdata;
922  SCIP_Bool transformed;
923  int pos;
924  int j;
925 
926  assert( var != NULL );
927  assert( cons != NULL );
928  assert( conshdlrdata != NULL );
929 
930  consdata = SCIPconsGetData(cons);
931  assert( consdata != NULL );
932 
933  if ( consdata->weights == NULL && consdata->maxvars > 0 )
934  {
935  SCIPerrorMessage("cannot add variable to SOS1 constraint <%s> that does not contain weights.\n", SCIPconsGetName(cons));
936  return SCIP_INVALIDCALL;
937  }
938 
939  /* are we in the transformed problem? */
940  transformed = SCIPconsIsTransformed(cons);
941 
942  /* always use transformed variables in transformed constraints */
943  if ( transformed )
944  {
945  SCIP_CALL( SCIPgetTransformedVar(scip, var, &var) );
946  }
947  assert( var != NULL );
948  assert( transformed == SCIPvarIsTransformed(var) );
949 
950  SCIP_CALL( consdataEnsurevarsSizeSOS1(scip, consdata, consdata->nvars + 1, TRUE) );
951  assert( consdata->weights != NULL );
952  assert( consdata->maxvars >= consdata->nvars+1 );
953 
954  /* find variable position */
955  for (pos = 0; pos < consdata->nvars; ++pos)
956  {
957  if ( consdata->weights[pos] > weight )
958  break;
959  }
960  assert( 0 <= pos && pos <= consdata->nvars );
961 
962  /* move other variables, if necessary */
963  for (j = consdata->nvars; j > pos; --j)
964  {
965  consdata->vars[j] = consdata->vars[j-1];
966  consdata->weights[j] = consdata->weights[j-1];
967  }
968 
969  /* insert variable */
970  consdata->vars[pos] = var;
971  consdata->weights[pos] = weight;
972  ++consdata->nvars;
973 
974  /* handle the new variable */
975  SCIP_CALL( handleNewVariableSOS1(scip, cons, consdata, conshdlrdata, var, transformed) );
976 
977  return SCIP_OKAY;
978 }
979 
980 
981 /** appends a variable to an SOS1 constraint */
982 static
984  SCIP* scip, /**< SCIP data structure */
985  SCIP_CONS* cons, /**< constraint */
986  SCIP_CONSHDLRDATA* conshdlrdata, /**< constraint handler data */
987  SCIP_VAR* var /**< variable to add to the constraint */
988  )
989 {
990  SCIP_CONSDATA* consdata;
991  SCIP_Bool transformed;
992 
993  assert( var != NULL );
994  assert( cons != NULL );
995  assert( conshdlrdata != NULL );
996 
997  consdata = SCIPconsGetData(cons);
998  assert( consdata != NULL );
999 
1000  /* are we in the transformed problem? */
1001  transformed = SCIPconsIsTransformed(cons);
1002 
1003  /* always use transformed variables in transformed constraints */
1004  if ( transformed )
1005  {
1006  SCIP_CALL( SCIPgetTransformedVar(scip, var, &var) );
1007  }
1008  assert( var != NULL );
1009  assert( transformed == SCIPvarIsTransformed(var) );
1010 
1011  SCIP_CALL( consdataEnsurevarsSizeSOS1(scip, consdata, consdata->nvars + 1, FALSE) );
1012 
1013  /* insert variable */
1014  consdata->vars[consdata->nvars] = var;
1015  assert( consdata->weights != NULL || consdata->nvars > 0 );
1016  if ( consdata->weights != NULL && consdata->nvars > 0 )
1017  consdata->weights[consdata->nvars] = consdata->weights[consdata->nvars-1] + 1.0;
1018  ++consdata->nvars;
1019 
1020  /* handle the new variable */
1021  SCIP_CALL( handleNewVariableSOS1(scip, cons, consdata, conshdlrdata, var, transformed) );
1022 
1023  return SCIP_OKAY;
1024 }
1025 
1026 
1027 /** deletes a variable of an SOS1 constraint */
1028 static
1030  SCIP* scip, /**< SCIP data structure */
1031  SCIP_CONS* cons, /**< constraint */
1032  SCIP_CONSDATA* consdata, /**< constraint data */
1033  SCIP_EVENTHDLR* eventhdlr, /**< corresponding event handler */
1034  int pos /**< position of variable in array */
1035  )
1036 {
1037  int j;
1038 
1039  assert( 0 <= pos && pos < consdata->nvars );
1040 
1041  /* remove lock of variable */
1042  SCIP_CALL( unlockVariableSOS1(scip, cons, consdata->vars[pos]) );
1043 
1044  /* drop events on variable */
1045  SCIP_CALL( SCIPdropVarEvent(scip, consdata->vars[pos], SCIP_EVENTTYPE_BOUNDCHANGED, eventhdlr, (SCIP_EVENTDATA*)cons, -1) ); /*lint !e740*/
1046 
1047  /* delete variable - need to copy since order is important */
1048  for (j = pos; j < consdata->nvars-1; ++j)
1049  {
1050  consdata->vars[j] = consdata->vars[j+1]; /*lint !e679*/
1051  if ( consdata->weights != NULL )
1052  consdata->weights[j] = consdata->weights[j+1]; /*lint !e679*/
1053  }
1054  --consdata->nvars;
1055 
1056  return SCIP_OKAY;
1057 }
1058 
1059 
1060 /* ----------------------------- presolving --------------------------------------*/
1061 
1062 /** extends a given clique of the conflict graph
1063  *
1064  * Implementation of the Bron-Kerbosch Algorithm from the paper:
1065  * Algorithm 457: Finding all Cliques of an Undirected Graph, Bron & Kerbosch, Commun. ACM, 1973
1066  */
1067 static
1069  SCIP* scip, /**< SCIP pointer */
1070  SCIP_CONSHDLRDATA* conshdlrdata, /**< constraint handler data */
1071  SCIP_Bool** adjacencymatrix, /**< adjacencymatrix of the conflict graph (only lower half filled) */
1072  SCIP_DIGRAPH* vertexcliquegraph, /**< graph that contains the information which cliques contain a given vertex
1073  * vertices of variables = 0, ..., nsos1vars-1; vertices of cliques = nsos1vars, ..., nsos1vars+ncliques-1*/
1074  int nsos1vars, /**< number of SOS1 variables */
1075  int nconss, /**< number of SOS1 constraints */
1076  SCIP_CONS* cons, /**< constraint to be extended */
1077  SCIP_VAR** vars, /**< variables of extended clique */
1078  SCIP_Real* weights, /**< weights of extended clique */
1079  SCIP_Bool firstcall, /**< whether this is the first call of extension operator */
1080  SCIP_Bool usebacktrack, /**< whether backtracking is needed for the computation */
1081  int** cliques, /**< all cliques found so far */
1082  int* ncliques, /**< number of clique found so far */
1083  int* cliquesizes, /**< number of variables of current clique */
1084  int* newclique, /**< clique we want to extended*/
1085  int* workingset, /**< set of vertices that already served as extension and set of candidates that probably will lead to an extension */
1086  int nworkingset, /**< length of array workingset */
1087  int nexts, /**< number of vertices that already served as extension */
1088  int pos, /**< position of potential candidate */
1089  int* maxextensions, /**< maximal number of extensions */
1090  int* naddconss, /**< number of added constraints */
1091  SCIP_Bool* success /**< pointer to store if at least one new clique was found */
1092  )
1093 {
1094  int* workingsetnew = NULL;
1095  int nextsnew;
1096  int nworkingsetnew;
1097  int mincands;
1098  int btriter = 0; /* backtrack iterator */
1099  int selvertex;
1100  int selpos = -1;
1101  int fixvertex = -1;
1102  int i;
1103  int j;
1104 
1105  assert( scip != NULL );
1106  assert( conshdlrdata != NULL );
1107  assert( adjacencymatrix != NULL );
1108  assert( vertexcliquegraph != NULL );
1109  assert( cons != NULL );
1110  assert( cliques != NULL );
1111  assert( cliquesizes != NULL );
1112  assert( newclique != NULL );
1113  assert( workingset != NULL );
1114  assert( maxextensions != NULL );
1115  assert( naddconss != NULL );
1116  assert( success != NULL );
1117 
1118  if ( firstcall )
1119  *success = FALSE;
1120 
1121  mincands = nworkingset;
1122  if ( mincands < 1 )
1123  return SCIP_OKAY;
1124 
1125  /* allocate buffer array */
1126  SCIP_CALL( SCIPallocBufferArray(scip, &workingsetnew, nworkingset) );
1127 
1128 #ifdef SCIP_DEBUG
1129  for (i = 0; i < nexts; ++i)
1130  {
1131  int vertex = workingset[i];
1132  for (j = nexts; j < nworkingset; ++j)
1133  {
1134  assert( isConnectedSOS1(adjacencymatrix, NULL, vertex, workingset[j]) );
1135  }
1136  }
1137 #endif
1138 
1139  /* determine candidate with minimum number of disconnections */
1140  for (i = 0; i < nworkingset; ++i)
1141  {
1142  int vertex;
1143  int cnt = 0;
1144 
1145  vertex = workingset[i];
1146 
1147  /* count disconnections */
1148  for (j = nexts; j < nworkingset && cnt < mincands; ++j)
1149  {
1150  if ( vertex != workingset[j] && ! isConnectedSOS1(adjacencymatrix, NULL, vertex, workingset[j]) )
1151  {
1152  cnt++;
1153 
1154  /* save position of potential candidate */
1155  pos = j;
1156  }
1157  }
1158 
1159  /* check whether a new minimum was found */
1160  if ( cnt < mincands )
1161  {
1162  fixvertex = vertex;
1163  mincands = cnt;
1164  if ( i < nexts )
1165  {
1166  assert( pos >= 0 );
1167  selpos = pos;
1168  }
1169  else
1170  {
1171  selpos = i;
1172 
1173  /* preincrement */
1174  btriter = 1;
1175  }
1176  }
1177  }
1178 
1179  /* If fixed point is initially chosen from candidates then number of disconnections will be preincreased by one. */
1180 
1181  /* backtrackcycle */
1182  for (btriter = mincands + btriter; btriter >= 1; --btriter)
1183  {
1184  assert( selpos >= 0);
1185  assert( fixvertex >= 0);
1186 
1187  /* interchange */
1188  selvertex = workingset[selpos];
1189  workingset[selpos] = workingset[nexts];
1190  workingset[nexts] = selvertex;
1191 
1192  /* create new workingset */
1193  nextsnew = 0;
1194  for (j = 0 ; j < nexts; ++j)
1195  {
1196  if ( isConnectedSOS1(adjacencymatrix, NULL, selvertex, workingset[j]) )
1197  workingsetnew[nextsnew++] = workingset[j];
1198  }
1199  nworkingsetnew = nextsnew;
1200  for (j = nexts + 1; j < nworkingset; ++j)
1201  {
1202  if ( isConnectedSOS1(adjacencymatrix, NULL, selvertex, workingset[j]) )
1203  workingsetnew[nworkingsetnew++] = workingset[j];
1204  }
1205 
1206  newclique[cliquesizes[*ncliques]++] = selvertex;
1207 
1208  /* if we found a new clique */
1209  if ( nworkingsetnew == 0 )
1210  {
1211  char consname[SCIP_MAXSTRLEN];
1212  SCIP_CONSDATA* consdata;
1213  SCIP_CONS* newcons;
1214  int cliqueind;
1215 
1216  cliqueind = nsos1vars + *ncliques; /* index of clique in the vertex-clique graph */
1217 
1218  /* save new clique */
1219  assert( cliquesizes[*ncliques] >= 0 && cliquesizes[*ncliques] <= nsos1vars );
1220  assert( *ncliques < MAX(1, conshdlrdata->maxextensions) * nconss );
1221  SCIP_CALL( SCIPallocBufferArray(scip, &(cliques[*ncliques]), cliquesizes[*ncliques]) );/*lint !e866*/
1222  for (j = 0 ; j < cliquesizes[*ncliques]; ++j)
1223  {
1224  vars[j] = SCIPnodeGetVarSOS1(conshdlrdata->conflictgraph, newclique[j]);
1225  weights[j] = j+1;
1226  cliques[*ncliques][j] = newclique[j];
1227  }
1228 
1229  SCIPsortInt(cliques[*ncliques], cliquesizes[*ncliques]);
1230 
1231  /* create new constraint */
1232  (void) SCIPsnprintf(consname, SCIP_MAXSTRLEN, "extsos1_%" SCIP_LONGINT_FORMAT, conshdlrdata->cntextsos1, conshdlrdata->cntextsos1);
1233 
1234  SCIP_CALL( SCIPcreateConsSOS1(scip, &newcons, consname, cliquesizes[*ncliques], vars, weights,
1238  SCIPconsIsDynamic(cons),
1240 
1241  consdata = SCIPconsGetData(newcons);
1242 
1243  /* add directed edges to the vertex-clique graph */
1244  for (j = 0; j < consdata->nvars; ++j)
1245  {
1246  /* add arc from clique vertex to clique (needed in presolRoundConssSOS1() to delete redundand cliques) */
1247  SCIP_CALL( SCIPdigraphAddArcSafe(vertexcliquegraph, cliques[*ncliques][j], cliqueind, NULL) );
1248  }
1249 
1250  SCIP_CALL( SCIPaddCons(scip, newcons) );
1251  SCIP_CALL( SCIPreleaseCons(scip, &newcons) );
1252 
1253  ++(*naddconss);
1254  ++(conshdlrdata->cntextsos1);
1255  ++(*ncliques);
1256  cliquesizes[*ncliques] = cliquesizes[*ncliques-1]; /* cliquesizes[*ncliques] = size of newclique */
1257 
1258  *success = TRUE;
1259 
1260  --(*maxextensions);
1261 
1262  if ( *maxextensions <= 0 )
1263  {
1264  SCIPfreeBufferArray(scip, &workingsetnew);
1265  return SCIP_OKAY;
1266  }
1267  }
1268  else if ( nextsnew < nworkingsetnew ) /* else if the number of of candidates equals zero */
1269  {
1270  /* if backtracking is used, it is necessary to keep the memory for 'workingsetnew' */
1271  if ( usebacktrack )
1272  {
1273  SCIP_CALL( extensionOperatorSOS1(scip, conshdlrdata, adjacencymatrix, vertexcliquegraph, nsos1vars, nconss, cons, vars, weights, FALSE, usebacktrack,
1274  cliques, ncliques, cliquesizes, newclique, workingsetnew, nworkingsetnew, nextsnew, pos, maxextensions, naddconss, success) );
1275  if ( *maxextensions <= 0 )
1276  {
1277  SCIPfreeBufferArrayNull(scip, &workingsetnew);
1278  return SCIP_OKAY;
1279  }
1280  }
1281  else
1282  {
1283  int w;
1284 
1285  assert( nworkingset >= nworkingsetnew );
1286  for (w = 0; w < nworkingsetnew; ++w)
1287  workingset[w] = workingsetnew[w];
1288  nworkingset = nworkingsetnew;
1289 
1290  SCIPfreeBufferArrayNull(scip, &workingsetnew);
1291 
1292  SCIP_CALL( extensionOperatorSOS1(scip, conshdlrdata, adjacencymatrix, vertexcliquegraph, nsos1vars, nconss, cons, vars, weights, FALSE, usebacktrack,
1293  cliques, ncliques, cliquesizes, newclique, workingset, nworkingset, nextsnew, pos, maxextensions, naddconss, success) );
1294  assert( *maxextensions <= 0 );
1295  return SCIP_OKAY;
1296  }
1297  }
1298  assert( workingsetnew != NULL );
1299  assert( workingset != NULL );
1300 
1301  /* remove selvertex from clique */
1302  --cliquesizes[*ncliques];
1303 
1304  /* add selvertex to the set of vertices that already served as extension */
1305  ++nexts;
1306 
1307  if ( btriter > 1 )
1308  {
1309  /* select a candidate that is not connected to the fixed vertex */
1310  for (j = nexts; j < nworkingset; ++j)
1311  {
1312  assert( fixvertex != workingset[j] );
1313  if ( ! isConnectedSOS1(adjacencymatrix, NULL, fixvertex, workingset[j]) )
1314  {
1315  selpos = j;
1316  break;
1317  }
1318  }
1319  }
1320  }
1321 
1322  SCIPfreeBufferArrayNull(scip, &workingsetnew);
1323 
1324  return SCIP_OKAY;
1325 }
1326 
1327 
1328 /** generates conflict graph that is induced by the variables of a linear constraint */
1329 static
1331  SCIP_CONSHDLRDATA* conshdlrdata, /**< constraint handler data */
1332  SCIP_DIGRAPH* conflictgraphlin, /**< conflict graph of linear constraint (nodes: 1, ..., nlinvars) */
1333  SCIP_DIGRAPH* conflictgraphorig, /**< original conflict graph (nodes: 1, ..., nsos1vars) */
1334  SCIP_VAR** linvars, /**< linear variables in linear constraint */
1335  int nlinvars, /**< number of linear variables in linear constraint */
1336  int* posinlinvars /**< posinlinvars[i] = position (index) of SOS1 variable i in linear constraint,
1337  * posinlinvars[i]= -1 if @p i is not a SOS1 variable or not a variable of the linear constraint */
1338  )
1339 {
1340  int indexinsosvars;
1341  int indexinlinvars;
1342  int* succ;
1343  int nsucc;
1344  int v;
1345  int s;
1346 
1347  assert( conflictgraphlin != NULL );
1348  assert( conflictgraphorig != NULL );
1349  assert( linvars != NULL );
1350  assert( posinlinvars != NULL );
1351 
1352  for (v = 1; v < nlinvars; ++v) /* we start with v = 1, since "indexinlinvars < v" (see below) is never fulfilled for v = 0 */
1353  {
1354  indexinsosvars = varGetNodeSOS1(conshdlrdata, linvars[v]);
1355 
1356  /* if linvars[v] is contained in at least one SOS1 constraint */
1357  if ( indexinsosvars >= 0 )
1358  {
1359  succ = SCIPdigraphGetSuccessors(conflictgraphorig, indexinsosvars);
1360  nsucc = SCIPdigraphGetNSuccessors(conflictgraphorig, indexinsosvars);
1361 
1362  for (s = 0; s < nsucc; ++s)
1363  {
1364  assert( succ[s] >= 0 );
1365  indexinlinvars = posinlinvars[succ[s]];
1366  assert( indexinlinvars < nlinvars );
1367 
1368  if ( indexinlinvars >= 0 && indexinlinvars < v )
1369  {
1370  SCIP_CALL( SCIPdigraphAddArcSafe(conflictgraphlin, v, indexinlinvars, NULL) );
1371  SCIP_CALL( SCIPdigraphAddArcSafe(conflictgraphlin, indexinlinvars, v, NULL) );
1372  }
1373  }
1374  }
1375  }
1376 
1377  return SCIP_OKAY;
1378 }
1379 
1380 
1381 /** determine the common successors of the vertices from the considered clique */
1382 static
1384  SCIP_CONSHDLRDATA* conshdlrdata, /**< constraint handler data */
1385  SCIP_DIGRAPH* conflictgraph, /**< conflict graph */
1386  int* clique, /**< current clique */
1387  SCIP_VAR** vars, /**< clique variables */
1388  int nvars, /**< number of clique variables */
1389  int* comsucc, /**< pointer to store common successors of clique vertices (size = nvars) */
1390  int* ncomsucc /**< pointer to store number common successors of clique vertices */
1391  )
1392 {
1393  int nsucc;
1394  int* succ;
1395  int ind;
1396  int k = 0;
1397  int v;
1398  int i;
1399  int j;
1400 
1401  assert( conflictgraph != NULL );
1402  assert( clique != NULL );
1403  assert( vars != NULL );
1404  assert( comsucc != NULL );
1405  assert( ncomsucc != NULL );
1406 
1407  *ncomsucc = 0;
1408 
1409  /* determine the common successors of the vertices from the considered clique */
1410 
1411  /* determine successors of variable var[0] that are not in the clique */
1412  assert(vars[0] != NULL );
1413  ind = varGetNodeSOS1(conshdlrdata, vars[0]);
1414  assert( ind >= 0 && ind < SCIPdigraphGetNNodes(conflictgraph) );
1415  nsucc = SCIPdigraphGetNSuccessors(conflictgraph, ind);
1416  succ = SCIPdigraphGetSuccessors(conflictgraph, ind);
1417 
1418  for (j = 0; j < nvars; ++j)
1419  {
1420  for (i = k; i < nsucc; ++i)
1421  {
1422  if ( succ[i] > clique[j] )
1423  {
1424  k = i;
1425  break;
1426  }
1427  else if ( succ[i] == clique[j] )
1428  {
1429  k = i + 1;
1430  break;
1431  }
1432  else
1433  comsucc[(*ncomsucc)++] = succ[i];
1434  }
1435  }
1436 
1437  /* for all variables except the first one */
1438  for (v = 1; v < nvars; ++v)
1439  {
1440  int ncomsuccsave = 0;
1441  k = 0;
1442 
1443  assert(vars[v] != NULL );
1444  ind = varGetNodeSOS1(conshdlrdata, vars[v]);
1445  assert( ind >= 0 && ind < SCIPdigraphGetNNodes(conflictgraph) );
1446 
1447  if ( ind >= 0 )
1448  {
1449  nsucc = SCIPdigraphGetNSuccessors(conflictgraph, ind);
1450  succ = SCIPdigraphGetSuccessors(conflictgraph, ind);
1451 
1452  /* determine successors that are in comsucc */
1453  for (j = 0; j < *ncomsucc; ++j)
1454  {
1455  for (i = k; i < nsucc; ++i)
1456  {
1457  if ( succ[i] > comsucc[j] )
1458  {
1459  k = i;
1460  break;
1461  }
1462  else if ( succ[i] == comsucc[j] )
1463  {
1464  comsucc[ncomsuccsave++] = succ[i];
1465  k = i + 1;
1466  break;
1467  }
1468  }
1469  }
1470  *ncomsucc = ncomsuccsave;
1471  }
1472  }
1473 
1474  return SCIP_OKAY;
1475 }
1476 
1477 
1478 /** get nodes whose corresponding SOS1 variables are nonzero if an SOS1 variable of a given node is nonzero */
1479 static
1481  SCIP* scip, /**< SCIP pointer */
1482  SCIP_CONSHDLRDATA* conshdlrdata, /**< constraint handler data */
1483  SCIP_VAR** vars, /**< problem and SOS1 variables */
1484  SCIP_DIGRAPH* implgraph, /**< implication graph (@p j is successor of @p i if and only if \f$ x_i\not = 0 \Rightarrow x_j\not = 0\f$) */
1485  SCIP_HASHMAP* implhash, /**< hash map from variable to node in implication graph */
1486  SCIP_Bool* implnodes, /**< implnodes[i] = TRUE if the SOS1 variable corresponding to node i in the implication graph is implied to be nonzero */
1487  int node /**< node of the implication graph */
1488  )
1489 {
1490  SCIP_SUCCDATA** succdatas;
1491  int sos1node;
1492  int* succ;
1493  int nsucc;
1494  int s;
1495 
1496  assert( scip != NULL );
1497  assert( implgraph != NULL );
1498  assert( implnodes != NULL );
1499  assert( node >= 0 );
1500  assert( vars[node] != NULL );
1501  assert( (int) (size_t) SCIPhashmapGetImage(implhash, vars[node]) == node );
1502 
1503  /* get node of variable in the conflict graph (-1 if variable is no SOS1 variable) */
1504  sos1node = varGetNodeSOS1(conshdlrdata, vars[node]);
1505  if ( sos1node < 0 )
1506  return SCIP_OKAY;
1507 
1508  succdatas = (SCIP_SUCCDATA**) SCIPdigraphGetSuccessorsData(implgraph, node);
1509  nsucc = SCIPdigraphGetNSuccessors(implgraph, node);
1510  succ = SCIPdigraphGetSuccessors(implgraph, node);
1511 
1512  for (s = 0; s < nsucc; ++s)
1513  {
1514  SCIP_SUCCDATA* data;
1515  int succnode;
1516  succnode = succ[s];
1517  data = succdatas[s];
1518  sos1node = varGetNodeSOS1(conshdlrdata, vars[succnode]);
1519 
1520  /* if node is SOS1 and the corresponding variable is implied to be nonzero */
1521  assert( succdatas[s] != NULL );
1522  if ( sos1node >= 0 && ! implnodes[sos1node] && ( SCIPisFeasPositive(scip, data->lbimpl) || SCIPisFeasNegative(scip, data->ubimpl) ) )
1523  {
1524  assert( sos1node == succnode );
1525  implnodes[sos1node] = TRUE;
1526  SCIP_CALL( getSOS1Implications(scip, conshdlrdata, vars, implgraph, implhash, implnodes, succnode) );
1527  }
1528  }
1529 
1530  return SCIP_OKAY;
1531 }
1532 
1533 
1534 /** perform one presolving round for a single SOS1 constraint
1535  *
1536  * We perform the following presolving steps.
1537  *
1538  * - If the bounds of some variable force it to be nonzero, we can
1539  * fix all other variables to zero and remove the SOS1 constraints
1540  * that contain it.
1541  * - If a variable is fixed to zero, we can remove the variable.
1542  * - If a variable appears twice, it can be fixed to 0.
1543  * - We substitute appregated variables.
1544  */
1545 static
1547  SCIP* scip, /**< SCIP pointer */
1548  SCIP_CONS* cons, /**< constraint */
1549  SCIP_CONSDATA* consdata, /**< constraint data */
1550  SCIP_EVENTHDLR* eventhdlr, /**< event handler */
1551  SCIP_Bool* substituted, /**< whether a variable was substituted */
1552  SCIP_Bool* cutoff, /**< whether a cutoff happened */
1553  SCIP_Bool* success, /**< whether we performed a successful reduction */
1554  int* ndelconss, /**< number of deleted constraints */
1555  int* nupgdconss, /**< number of upgraded constraints */
1556  int* nfixedvars, /**< number of fixed variables */
1557  int* nremovedvars /**< number of variables removed */
1558  )
1559 {
1560  SCIP_VAR** vars;
1561  SCIP_Bool allvarsbinary;
1562  SCIP_Bool infeasible;
1563  SCIP_Bool fixed;
1564  int nfixednonzeros;
1565  int lastFixedNonzero;
1566  int j;
1567 
1568  assert( scip != NULL );
1569  assert( cons != NULL );
1570  assert( consdata != NULL );
1571  assert( eventhdlr != NULL );
1572  assert( cutoff != NULL );
1573  assert( success != NULL );
1574  assert( ndelconss != NULL );
1575  assert( nfixedvars != NULL );
1576  assert( nremovedvars != NULL );
1577 
1578  *substituted = FALSE;
1579  *cutoff = FALSE;
1580  *success = FALSE;
1581 
1582  SCIPdebugMsg(scip, "Presolving SOS1 constraint <%s>.\n", SCIPconsGetName(cons) );
1583 
1584  j = 0;
1585  nfixednonzeros = 0;
1586  lastFixedNonzero = -1;
1587  allvarsbinary = TRUE;
1588  vars = consdata->vars;
1589 
1590  /* check for variables fixed to 0 and bounds that fix a variable to be nonzero */
1591  while ( j < consdata->nvars )
1592  {
1593  int l;
1594  SCIP_VAR* var;
1595  SCIP_Real lb;
1596  SCIP_Real ub;
1597  SCIP_Real scalar;
1598  SCIP_Real constant;
1599 
1600  scalar = 1.0;
1601  constant = 0.0;
1602 
1603  /* check for aggregation: if the constant is zero the variable is zero iff the aggregated
1604  * variable is 0 */
1605  var = vars[j];
1606  SCIP_CALL( SCIPgetProbvarSum(scip, &var, &scalar, &constant) );
1607 
1608  /* if constant is zero and we get a different variable, substitute variable */
1609  if ( SCIPisZero(scip, constant) && ! SCIPisZero(scip, scalar) && var != vars[j] )
1610  {
1611  SCIPdebugMsg(scip, "substituted variable <%s> by <%s>.\n", SCIPvarGetName(vars[j]), SCIPvarGetName(var));
1612  SCIP_CALL( SCIPdropVarEvent(scip, consdata->vars[j], SCIP_EVENTTYPE_BOUNDCHANGED, eventhdlr, (SCIP_EVENTDATA*)cons, -1) ); /*lint !e740*/
1613  SCIP_CALL( SCIPcatchVarEvent(scip, var, SCIP_EVENTTYPE_BOUNDCHANGED, eventhdlr, (SCIP_EVENTDATA*)cons, NULL) ); /*lint !e740*/
1614 
1615  /* change the rounding locks */
1616  SCIP_CALL( unlockVariableSOS1(scip, cons, consdata->vars[j]) );
1617  SCIP_CALL( lockVariableSOS1(scip, cons, var) );
1618 
1619  vars[j] = var;
1620  *substituted = TRUE;
1621  }
1622 
1623  /* check whether the variable appears again later */
1624  for (l = j+1; l < consdata->nvars; ++l)
1625  {
1626  /* if variable appeared before, we can fix it to 0 and remove it */
1627  if ( vars[j] == vars[l] )
1628  {
1629  SCIPdebugMsg(scip, "variable <%s> appears twice in constraint, fixing it to 0.\n", SCIPvarGetName(vars[j]));
1630  SCIP_CALL( SCIPfixVar(scip, vars[j], 0.0, &infeasible, &fixed) );
1631 
1632  if ( infeasible )
1633  {
1634  *cutoff = TRUE;
1635  return SCIP_OKAY;
1636  }
1637  if ( fixed )
1638  ++(*nfixedvars);
1639  }
1640  }
1641 
1642  /* get bounds */
1643  lb = SCIPvarGetLbLocal(vars[j]);
1644  ub = SCIPvarGetUbLocal(vars[j]);
1645 
1646  /* if the variable if fixed to nonzero */
1647  if ( SCIPisFeasPositive(scip, lb) || SCIPisFeasNegative(scip, ub) )
1648  {
1649  ++nfixednonzeros;
1650  lastFixedNonzero = j;
1651  }
1652 
1653  /* if the variable is fixed to 0 */
1654  if ( SCIPisFeasZero(scip, lb) && SCIPisFeasZero(scip, ub) )
1655  {
1656  SCIPdebugMsg(scip, "deleting variable <%s> fixed to 0.\n", SCIPvarGetName(vars[j]));
1657  SCIP_CALL( deleteVarSOS1(scip, cons, consdata, eventhdlr, j) );
1658  ++(*nremovedvars);
1659  }
1660  else
1661  {
1662  /* check whether all variables are binary */
1663  if ( ! SCIPvarIsBinary(vars[j]) )
1664  allvarsbinary = FALSE;
1665 
1666  ++j;
1667  }
1668  }
1669 
1670  /* if the number of variables is less than 2 */
1671  if ( consdata->nvars < 2 )
1672  {
1673  SCIPdebugMsg(scip, "Deleting SOS1 constraint <%s> with < 2 variables.\n", SCIPconsGetName(cons));
1674 
1675  /* delete constraint */
1676  assert( ! SCIPconsIsModifiable(cons) );
1677  SCIP_CALL( SCIPdelCons(scip, cons) );
1678  ++(*ndelconss);
1679  *success = TRUE;
1680  return SCIP_OKAY;
1681  }
1682 
1683  /* if more than one variable are fixed to be nonzero, we are infeasible */
1684  if ( nfixednonzeros > 1 )
1685  {
1686  SCIPdebugMsg(scip, "The problem is infeasible: more than one variable has bounds that keep it from being 0.\n");
1687  assert( lastFixedNonzero >= 0 );
1688  *cutoff = TRUE;
1689  return SCIP_OKAY;
1690  }
1691 
1692  /* if there is exactly one fixed nonzero variable */
1693  if ( nfixednonzeros == 1 )
1694  {
1695  assert( lastFixedNonzero >= 0 );
1696 
1697  /* fix all other variables to zero */
1698  for (j = 0; j < consdata->nvars; ++j)
1699  {
1700  if ( j != lastFixedNonzero )
1701  {
1702  SCIP_CALL( fixVariableZero(scip, vars[j], &infeasible, &fixed) );
1703  if ( infeasible )
1704  {
1705  *cutoff = TRUE;
1706  return SCIP_OKAY;
1707  }
1708  if ( fixed )
1709  ++(*nfixedvars);
1710  }
1711  }
1712 
1713  SCIPdebugMsg(scip, "Deleting redundant SOS1 constraint <%s> with one variable.\n", SCIPconsGetName(cons));
1714 
1715  /* delete original constraint */
1716  assert( ! SCIPconsIsModifiable(cons) );
1717  SCIP_CALL( SCIPdelCons(scip, cons) );
1718  ++(*ndelconss);
1719  *success = TRUE;
1720  }
1721  /* note: there is no need to update consdata->nfixednonzeros, since the constraint is deleted as soon nfixednonzeros > 0. */
1722  else
1723  {
1724  /* if all variables are binary create a set packing constraint */
1725  if ( allvarsbinary && SCIPfindConshdlr(scip, "setppc") != NULL )
1726  {
1727  SCIP_CONS* setpackcons;
1728 
1729  /* create, add, and release the logicor constraint */
1730  SCIP_CALL( SCIPcreateConsSetpack(scip, &setpackcons, SCIPconsGetName(cons), consdata->nvars, consdata->vars,
1734  SCIP_CALL( SCIPaddCons(scip, setpackcons) );
1735  SCIP_CALL( SCIPreleaseCons(scip, &setpackcons) );
1736 
1737  SCIPdebugMsg(scip, "Upgrading SOS1 constraint <%s> to set packing constraint.\n", SCIPconsGetName(cons));
1738 
1739  /* remove the SOS1 constraint globally */
1740  assert( ! SCIPconsIsModifiable(cons) );
1741  SCIP_CALL( SCIPdelCons(scip, cons) );
1742  ++(*nupgdconss);
1743  *success = TRUE;
1744  }
1745  }
1746 
1747  return SCIP_OKAY;
1748 }
1749 
1750 
1751 
1752 /** perform one presolving round for all SOS1 constraints
1753  *
1754  * We perform the following presolving steps.
1755  *
1756  * - If the bounds of some variable force it to be nonzero, we can
1757  * fix all other variables to zero and remove the SOS1 constraints
1758  * that contain it.
1759  * - If a variable is fixed to zero, we can remove the variable.
1760  * - If a variable appears twice, it can be fixed to 0.
1761  * - We substitute appregated variables.
1762  * - Remove redundant SOS1 constraints
1763  *
1764  * If the adjacency matrix of the conflict graph is present, then
1765  * we perform the following additional presolving steps
1766  *
1767  * - Search for larger SOS1 constraints in the conflict graph
1768  */
1769 static
1771  SCIP* scip, /**< SCIP pointer */
1772  SCIP_EVENTHDLR* eventhdlr, /**< event handler */
1773  SCIP_CONSHDLRDATA* conshdlrdata, /**< constraint handler data */
1774  SCIP_DIGRAPH* conflictgraph, /**< conflict graph */
1775  SCIP_Bool** adjacencymatrix, /**< adjacency matrix of conflict graph (or NULL) */
1776  SCIP_CONS** conss, /**< SOS1 constraints */
1777  int nconss, /**< number of SOS1 constraints */
1778  int nsos1vars, /**< number of SOS1 variables */
1779  int* naddconss, /**< number of added constraints */
1780  int* ndelconss, /**< number of deleted constraints */
1781  int* nupgdconss, /**< number of upgraded constraints */
1782  int* nfixedvars, /**< number of fixed variables */
1783  int* nremovedvars, /**< number of variables removed */
1784  SCIP_RESULT* result /**< result */
1785  )
1786 {
1787  SCIP_DIGRAPH* vertexcliquegraph;
1788  SCIP_VAR** consvars;
1789  SCIP_Real* consweights;
1790  int** cliques = NULL;
1791  int ncliques = 0;
1792  int* cliquesizes = NULL;
1793  int* newclique = NULL;
1794  int* indconss = NULL;
1795  int* lengthconss = NULL;
1796  int* comsucc = NULL;
1797  int csize;
1798  int iter;
1799  int c;
1800 
1801  assert( scip != NULL );
1802  assert( eventhdlr != NULL );
1803  assert( conshdlrdata != NULL );
1804  assert( conflictgraph != NULL );
1805  assert( conss != NULL );
1806  assert( naddconss != NULL );
1807  assert( ndelconss != NULL );
1808  assert( nupgdconss != NULL );
1809  assert( nfixedvars != NULL );
1810  assert( nremovedvars != NULL );
1811  assert( result != NULL );
1812 
1813  /* create digraph whose nodes represent variables and cliques in the conflict graph */
1814  csize = MAX(1, conshdlrdata->maxextensions) * nconss;
1815  SCIP_CALL( SCIPdigraphCreate(&vertexcliquegraph, nsos1vars + csize) );
1816 
1817  /* allocate buffer arrays */
1818  SCIP_CALL( SCIPallocBufferArray(scip, &consvars, nsos1vars) );
1819  SCIP_CALL( SCIPallocBufferArray(scip, &consweights, nsos1vars) );
1820  SCIP_CALL( SCIPallocBufferArray(scip, &cliquesizes, csize) );
1821  SCIP_CALL( SCIPallocBufferArray(scip, &newclique, nsos1vars) );
1822  SCIP_CALL( SCIPallocBufferArray(scip, &indconss, csize) );
1823  SCIP_CALL( SCIPallocBufferArray(scip, &lengthconss, csize) );
1824  SCIP_CALL( SCIPallocBufferArray(scip, &comsucc, MAX(nsos1vars, csize)) );
1825  SCIP_CALL( SCIPallocBufferArray(scip, &cliques, csize) );
1826 
1827  /* get constraint indices and sort them in descending order of their lengths */
1828  for (c = 0; c < nconss; ++c)
1829  {
1830  SCIP_CONSDATA* consdata;
1831 
1832  consdata = SCIPconsGetData(conss[c]);
1833  assert( consdata != NULL );
1834 
1835  indconss[c] = c;
1836  lengthconss[c] = consdata->nvars;
1837  }
1838  SCIPsortDownIntInt(lengthconss, indconss, nconss);
1839 
1840  /* check each constraint */
1841  for (iter = 0; iter < nconss; ++iter)
1842  {
1843  SCIP_CONSDATA* consdata;
1844  SCIP_CONS* cons;
1845  SCIP_Bool substituted;
1846  SCIP_Bool success;
1847  SCIP_Bool cutoff;
1848  int savennupgdconss;
1849  int savendelconss;
1850 
1851  SCIP_VAR** vars;
1852  int nvars;
1853 
1854  c = indconss[iter];
1855 
1856  assert( conss != NULL );
1857  assert( conss[c] != NULL );
1858  cons = conss[c];
1859  consdata = SCIPconsGetData(cons);
1860 
1861  assert( consdata != NULL );
1862  assert( consdata->nvars >= 0 );
1863  assert( consdata->nvars <= consdata->maxvars );
1864  assert( ! SCIPconsIsModifiable(cons) );
1865  assert( ncliques < csize );
1866 
1867  savendelconss = *ndelconss;
1868  savennupgdconss = *nupgdconss;
1869 
1870  /* perform one presolving round for SOS1 constraint */
1871  SCIP_CALL( presolRoundConsSOS1(scip, cons, consdata, eventhdlr, &substituted, &cutoff, &success, ndelconss, nupgdconss, nfixedvars, nremovedvars) );
1872 
1873  if ( cutoff )
1874  {
1875  *result = SCIP_CUTOFF;
1876  break;
1877  }
1878 
1879  if ( *ndelconss > savendelconss || *nupgdconss > savennupgdconss || substituted )
1880  {
1881  *result = SCIP_SUCCESS;
1882  continue;
1883  }
1884 
1885  if ( success )
1886  *result = SCIP_SUCCESS;
1887 
1888  /* get number of variables of constraint */
1889  nvars = consdata->nvars;
1890 
1891  /* get variables of constraint */
1892  vars = consdata->vars;
1893 
1894  if ( nvars > 1 && conshdlrdata->maxextensions != 0 )
1895  {
1896  SCIP_Bool extended = FALSE;
1897  int cliquesize = 0;
1898  int ncomsucc = 0;
1899  int varprobind;
1900  int j;
1901 
1902  /* get clique and size of clique */
1903  for (j = 0; j < nvars; ++j)
1904  {
1905  varprobind = varGetNodeSOS1(conshdlrdata, vars[j]);
1906 
1907  if ( varprobind >= 0 )
1908  newclique[cliquesize++] = varprobind;
1909  }
1910 
1911  if ( cliquesize > 1 )
1912  {
1913  cliquesizes[ncliques] = cliquesize;
1914 
1915  /* sort clique vertices */
1916  SCIPsortInt(newclique, cliquesizes[ncliques]);
1917 
1918  /* check if clique is contained in an already known clique */
1919  if ( ncliques > 0 )
1920  {
1921  int* succ;
1922  int nsucc;
1923  int v;
1924 
1925  varprobind = newclique[0];
1926  ncomsucc = SCIPdigraphGetNSuccessors(vertexcliquegraph, varprobind);
1927  succ = SCIPdigraphGetSuccessors(vertexcliquegraph, varprobind);
1928 
1929  /* get all (already processed) cliques that contain 'varpropind' */
1930  for (j = 0; j < ncomsucc; ++j)
1931  {
1932  /* successors should have been sorted in a former step of the algorithm */
1933  assert( j == 0 || succ[j] > succ[j-1] );
1934  comsucc[j] = succ[j];
1935  }
1936 
1937  /* loop through remaining nodes of clique (case v = 0 already processed) */
1938  for (v = 1; v < cliquesize && ncomsucc > 0; ++v)
1939  {
1940  varprobind = newclique[v];
1941 
1942  /* get all (already processed) cliques that contain 'varpropind' */
1943  nsucc = SCIPdigraphGetNSuccessors(vertexcliquegraph, varprobind);
1944  succ = SCIPdigraphGetSuccessors(vertexcliquegraph, varprobind);
1945  assert( succ != NULL || nsucc == 0 );
1946 
1947  if ( nsucc < 1 )
1948  {
1949  ncomsucc = 0;
1950  break;
1951  }
1952 
1953  /* get intersection with comsucc */
1954  SCIP_CALL( SCIPcomputeArraysIntersection(comsucc, ncomsucc, succ, nsucc, comsucc, &ncomsucc) );
1955  }
1956  }
1957 
1958  /* if constraint is redundand then delete it */
1959  if ( ncomsucc > 0 )
1960  {
1961  assert( ! SCIPconsIsModifiable(cons) );
1962  SCIP_CALL( SCIPdelCons(scip, cons) );
1963  ++(*ndelconss);
1964  *result = SCIP_SUCCESS;
1965  continue;
1966  }
1967 
1968  if ( conshdlrdata->maxextensions != 0 && adjacencymatrix != NULL )
1969  {
1970  int maxextensions;
1971  ncomsucc = 0;
1972 
1973  /* determine the common successors of the vertices from the considered clique */
1974  SCIP_CALL( cliqueGetCommonSuccessorsSOS1(conshdlrdata, conflictgraph, newclique, vars, nvars, comsucc, &ncomsucc) );
1975 
1976  /* find extensions for the clique */
1977  maxextensions = conshdlrdata->maxextensions;
1978  extended = FALSE;
1979  SCIP_CALL( extensionOperatorSOS1(scip, conshdlrdata, adjacencymatrix, vertexcliquegraph, nsos1vars, nconss, cons, consvars, consweights,
1980  TRUE, (maxextensions <= 1) ? FALSE : TRUE, cliques, &ncliques, cliquesizes, newclique, comsucc, ncomsucc, 0, -1, &maxextensions,
1981  naddconss, &extended) );
1982  }
1983 
1984  /* if an extension was found for the current clique then free the old SOS1 constraint */
1985  if ( extended )
1986  {
1987  assert( ! SCIPconsIsModifiable(cons) );
1988  SCIP_CALL( SCIPdelCons(scip, cons) );
1989  ++(*ndelconss);
1990  *result = SCIP_SUCCESS;
1991  }
1992  else /* if we keep the constraint */
1993  {
1994  int cliqueind;
1995 
1996  cliqueind = nsos1vars + ncliques; /* index of clique in vertex-clique graph */
1997 
1998  /* add directed edges to the vertex-clique graph */
1999  assert( cliquesize >= 0 && cliquesize <= nsos1vars );
2000  assert( ncliques < csize );
2001  SCIP_CALL( SCIPallocBufferArray(scip, &cliques[ncliques], cliquesize) );/*lint !e866*/
2002  for (j = 0; j < cliquesize; ++j)
2003  {
2004  cliques[ncliques][j] = newclique[j];
2005  SCIP_CALL( SCIPdigraphAddArcSafe(vertexcliquegraph, cliques[ncliques][j], cliqueind, NULL) );
2006  }
2007 
2008  /* update number of maximal cliques */
2009  ++ncliques;
2010  }
2011  }
2012  }
2013  }
2014 
2015  /* free buffer arrays */
2016  for (c = ncliques-1; c >= 0; --c)
2017  SCIPfreeBufferArrayNull(scip, &cliques[c]);
2018  SCIPfreeBufferArrayNull(scip, &cliques);
2019  SCIPfreeBufferArrayNull(scip, &comsucc);
2020  SCIPfreeBufferArrayNull(scip, &lengthconss);
2021  SCIPfreeBufferArrayNull(scip, &indconss);
2022  SCIPfreeBufferArrayNull(scip, &newclique);
2023  SCIPfreeBufferArrayNull(scip, &cliquesizes);
2024  SCIPfreeBufferArrayNull(scip, &consweights);
2025  SCIPfreeBufferArrayNull(scip, &consvars);
2026  SCIPdigraphFree(&vertexcliquegraph);
2027 
2028  return SCIP_OKAY;
2029 }
2030 
2031 
2032 /** performs implication graph analysis
2033  *
2034  * Tentatively fixes a variable to nonzeero and extracts consequences from it:
2035  * - adds (possibly new) complementarity constraints to the problem if variables are implied to be zero
2036  * - returns that the subproblem is infeasible if the domain of a variable turns out to be empty
2037  */
2038 static
2040  SCIP* scip, /**< SCIP pointer */
2041  SCIP_CONSHDLRDATA* conshdlrdata, /**< constraint handler data */
2042  SCIP_DIGRAPH* conflictgraph, /**< conflict graph */
2043  SCIP_VAR** totalvars, /**< problem and SOS1 variables */
2044  SCIP_DIGRAPH* implgraph, /**< implication graph (@p j is successor of @p i if and only if \f$ x_i\not = 0 \Rightarrow x_j\not = 0\f$) */
2045  SCIP_HASHMAP* implhash, /**< hash map from variable to node in implication graph */
2046  SCIP_Bool** adjacencymatrix, /**< adjacencymatrix of the conflict graph (only lower half filled) */
2047  int givennode, /**< node of the conflict graph */
2048  int nonznode, /**< node of the conflict graph that is implied to be nonzero if given node is nonzero */
2049  SCIP_Real* impllbs, /**< current lower variable bounds if given node is nonzero (update possible) */
2050  SCIP_Real* implubs, /**< current upper variable bounds if given node is nonzero (update possible) */
2051  SCIP_Bool* implnodes, /**< indicates which variables are currently implied to be nonzero if given node is nonzero (update possible) */
2052  int* naddconss, /**< pointer to store number of added SOS1 constraints */
2053  int* probingdepth, /**< pointer to store current probing depth */
2054  SCIP_Bool* infeasible /**< pointer to store whether the subproblem gets infeasible if variable to 'nonznode' is nonzero */
2055  )
2056 {
2057  SCIP_SUCCDATA** succdatas;
2058  int succnode;
2059  int* succ;
2060  int nsucc;
2061  int s;
2062 
2063  assert( nonznode >= 0 && nonznode < SCIPdigraphGetNNodes(conflictgraph) );
2064 
2065  /* check probing depth */
2066  if ( conshdlrdata->depthimplanalysis >= 0 && *probingdepth >= conshdlrdata->depthimplanalysis )
2067  return SCIP_OKAY;
2068  ++(*probingdepth);
2069 
2070  /* get successors of 'nonznode' in the conflict graph */
2071  nsucc = SCIPdigraphGetNSuccessors(conflictgraph, nonznode);
2072  succ = SCIPdigraphGetSuccessors(conflictgraph, nonznode);
2073 
2074  /* loop through neighbors of 'nonznode' in the conflict graph; these variables are implied to be zero */
2075  for (s = 0; s < nsucc; ++s)
2076  {
2077  succnode = succ[s];
2078 
2079  /* if the current variable domain of the successor node does not contain the value zero then return that the problem is infeasible
2080  * else if 'succnode' is not already complementary to 'givennode' then add a new complementarity constraint */
2081  if ( givennode == succnode || SCIPisFeasPositive(scip, impllbs[succnode]) || SCIPisFeasNegative(scip, implubs[succnode]) )
2082  {
2083  *infeasible = TRUE;
2084  return SCIP_OKAY;
2085  }
2086  else if ( ! isConnectedSOS1(adjacencymatrix, NULL, givennode, succnode) )
2087  {
2088  char namesos[SCIP_MAXSTRLEN];
2089  SCIP_CONS* soscons = NULL;
2090  SCIP_VAR* var1;
2091  SCIP_VAR* var2;
2092 
2093  /* update implied bounds of succnode */
2094  impllbs[succnode] = 0;
2095  implubs[succnode] = 0;
2096 
2097  /* add arcs to the conflict graph */
2098  SCIP_CALL( SCIPdigraphAddArcSafe(conflictgraph, givennode, succnode, NULL) );
2099  SCIP_CALL( SCIPdigraphAddArcSafe(conflictgraph, succnode, givennode, NULL) );
2100 
2101  /* resort successors */
2102  SCIPsortInt(SCIPdigraphGetSuccessors(conflictgraph, givennode), SCIPdigraphGetNSuccessors(conflictgraph, givennode));
2103  SCIPsortInt(SCIPdigraphGetSuccessors(conflictgraph, succnode), SCIPdigraphGetNSuccessors(conflictgraph, succnode));
2104 
2105  /* update adjacencymatrix */
2106  if ( givennode > succnode )
2107  adjacencymatrix[givennode][succnode] = 1;
2108  else
2109  adjacencymatrix[succnode][givennode] = 1;
2110 
2111  var1 = SCIPnodeGetVarSOS1(conflictgraph, givennode);
2112  var2 = SCIPnodeGetVarSOS1(conflictgraph, succnode);
2113 
2114  /* create SOS1 constraint */
2115  assert( SCIPgetDepth(scip) == 0 );
2116  (void) SCIPsnprintf(namesos, SCIP_MAXSTRLEN, "presolved_sos1_%s_%s", SCIPvarGetName(var1), SCIPvarGetName(var2) );
2117  SCIP_CALL( SCIPcreateConsSOS1(scip, &soscons, namesos, 0, NULL, NULL, TRUE, TRUE, TRUE, FALSE, TRUE,
2118  FALSE, FALSE, FALSE, FALSE) );
2119 
2120  /* add variables to SOS1 constraint */
2121  SCIP_CALL( addVarSOS1(scip, soscons, conshdlrdata, var1, 1.0) );
2122  SCIP_CALL( addVarSOS1(scip, soscons, conshdlrdata, var2, 2.0) );
2123 
2124  /* add constraint */
2125  SCIP_CALL( SCIPaddCons(scip, soscons) );
2126 
2127  /* release constraint */
2128  SCIP_CALL( SCIPreleaseCons(scip, &soscons) );
2129 
2130  ++(*naddconss);
2131  }
2132  }
2133 
2134  /* by construction: nodes of SOS1 variables are equal for conflict graph and implication graph */
2135  assert( nonznode == (int) (size_t) SCIPhashmapGetImage(implhash, SCIPnodeGetVarSOS1(conflictgraph, nonznode)) );
2136  succdatas = (SCIP_SUCCDATA**) SCIPdigraphGetSuccessorsData(implgraph, nonznode);
2137  nsucc = SCIPdigraphGetNSuccessors(implgraph, nonznode);
2138  succ = SCIPdigraphGetSuccessors(implgraph, nonznode);
2139 
2140  /* go further in implication graph */
2141  for (s = 0; s < nsucc; ++s)
2142  {
2143  SCIP_SUCCDATA* data;
2144  int oldprobingdepth;
2145 
2146  succnode = succ[s];
2147  data = succdatas[s];
2148  oldprobingdepth = *probingdepth;
2149 
2150  /* if current lower bound is smaller than implied lower bound */
2151  if ( SCIPisFeasLT(scip, impllbs[succnode], data->lbimpl) )
2152  {
2153  impllbs[succnode] = data->lbimpl;
2154 
2155  /* if node is SOS1 and implied to be nonzero for the first time, then this recursively may imply further bound changes */
2156  if ( varGetNodeSOS1(conshdlrdata, totalvars[succnode]) >= 0 && ! implnodes[succnode] && SCIPisFeasPositive(scip, data->lbimpl) )
2157  {
2158  /* by construction: nodes of SOS1 variables are equal for conflict graph and implication graph */
2159  assert( succnode == (int) (size_t) SCIPhashmapGetImage(implhash, SCIPnodeGetVarSOS1(conflictgraph, succnode)) );
2160  implnodes[succnode] = TRUE; /* in order to avoid cycling */
2161  SCIP_CALL( performImplicationGraphAnalysis(scip, conshdlrdata, conflictgraph, totalvars, implgraph, implhash, adjacencymatrix, givennode, succnode, impllbs, implubs, implnodes, naddconss, probingdepth, infeasible) );
2162  *probingdepth = oldprobingdepth;
2163 
2164  /* return if the subproblem is known to be infeasible */
2165  if ( *infeasible )
2166  return SCIP_OKAY;
2167  }
2168  }
2169 
2170  /* if current upper bound is larger than implied upper bound */
2171  if ( SCIPisFeasGT(scip, implubs[succnode], data->ubimpl) )
2172  {
2173  implubs[succnode] = data->ubimpl;
2174 
2175  /* if node is SOS1 and implied to be nonzero for the first time, then this recursively may imply further bound changes */
2176  if ( varGetNodeSOS1(conshdlrdata, totalvars[succnode]) >= 0 && ! implnodes[succnode] && SCIPisFeasNegative(scip, data->ubimpl) )
2177  {
2178  /* by construction: nodes of SOS1 variables are equal for conflict graph and implication graph */
2179  assert( succnode == (int) (size_t) SCIPhashmapGetImage(implhash, SCIPnodeGetVarSOS1(conflictgraph, succnode)) );
2180  implnodes[succnode] = TRUE; /* in order to avoid cycling */
2181  SCIP_CALL( performImplicationGraphAnalysis(scip, conshdlrdata, conflictgraph, totalvars, implgraph, implhash, adjacencymatrix, givennode, succnode, impllbs, implubs, implnodes, naddconss, probingdepth, infeasible) );
2182  *probingdepth = oldprobingdepth;
2183 
2184  /* return if the subproblem is known to be infeasible */
2185  if ( *infeasible )
2186  return SCIP_OKAY;
2187  }
2188  }
2189  }
2190 
2191  return SCIP_OKAY;
2192 }
2193 
2194 
2195 /** returns whether node is implied to be zero; this information is taken from the input array 'implnodes' */
2196 static
2198  SCIP_DIGRAPH* conflictgraph, /**< conflict graph */
2199  SCIP_Bool* implnodes, /**< implnodes[i] = TRUE if the SOS1 variable corresponding to node i in the implication graph is implied to be nonzero */
2200  int node /**< node of the conflict graph (or -1) */
2201  )
2202 {
2203  int* succ;
2204  int nsucc;
2205  int s;
2206 
2207  if ( node < 0 )
2208  return FALSE;
2209 
2210  nsucc = SCIPdigraphGetNSuccessors(conflictgraph, node);
2211  succ = SCIPdigraphGetSuccessors(conflictgraph, node);
2212 
2213  /* check whether any successor is implied to be nonzero */
2214  for (s = 0; s < nsucc; ++s)
2215  {
2216  if ( implnodes[succ[s]] )
2217  return TRUE;
2218  }
2219 
2220  return FALSE;
2221 }
2222 
2223 
2224 /** updates arc data of implication graph */
2225 static
2227  SCIP* scip, /**< SCIP pointer */
2228  SCIP_DIGRAPH* implgraph, /**< implication graph */
2229  SCIP_HASHMAP* implhash, /**< hash map from variable to node in implication graph */
2230  SCIP_VAR** totalvars, /**< problem and SOS1 variables */
2231  SCIP_VAR* varv, /**< variable that is assumed to be nonzero */
2232  SCIP_VAR* varw, /**< implication variable */
2233  SCIP_Real lb, /**< old lower bound of \f$x_w\f$ */
2234  SCIP_Real ub, /**< old upper bound of \f$x_w\f$ */
2235  SCIP_Real newbound, /**< new bound of \f$x_w\f$ */
2236  SCIP_Bool lower, /**< whether to consider lower bound implication (otherwise upper bound) */
2237  int* nchgbds, /**< pointer to store number of changed bounds */
2238  SCIP_Bool* update, /**< pointer to store whether implication graph has been updated */
2239  SCIP_Bool* infeasible /**< pointer to store whether an infeasibility has been detected */
2240  )
2241 {
2242  SCIP_SUCCDATA** succdatas;
2243  SCIP_SUCCDATA* data = NULL;
2244  int nsucc;
2245  int* succ;
2246  int indv;
2247  int indw;
2248  int s;
2249 
2250  assert( scip != NULL );
2251  assert( implgraph != NULL );
2252  assert( implhash != NULL );
2253  assert( totalvars != NULL );
2254  assert( varv != NULL );
2255  assert( varw != NULL );
2256 
2257  /* if x_v != 0 turns out to be infeasible then fix x_v = 0 */
2258  if ( ( lower && SCIPisFeasLT(scip, ub, newbound) ) || ( ! lower && SCIPisFeasGT(scip, lb, newbound) ) )
2259  {
2260  SCIP_Bool infeasible1;
2261  SCIP_Bool infeasible2;
2262  SCIP_Bool tightened1;
2263  SCIP_Bool tightened2;
2264 
2265  SCIP_CALL( SCIPtightenVarLb(scip, varv, 0.0, FALSE, &infeasible1, &tightened1) );
2266  SCIP_CALL( SCIPtightenVarUb(scip, varv, 0.0, FALSE, &infeasible2, &tightened2) );
2267 
2268  if ( infeasible1 || infeasible2 )
2269  {
2270  SCIPdebugMsg(scip, "detected infeasibility while trying to fix variable <%s> to zero\n", SCIPvarGetName(varv));
2271  *infeasible = TRUE;
2272  }
2273 
2274  if ( tightened1 || tightened2 )
2275  {
2276  SCIPdebugMsg(scip, "fixed variable %s from lb = %f and ub = %f to 0.0 \n", SCIPvarGetName(varv), lb, ub);
2277  ++(*nchgbds);
2278  }
2279  }
2280 
2281  /* get successor information */
2282  indv = (int) (size_t) SCIPhashmapGetImage(implhash, varv); /* get index of x_v in implication graph */
2283  assert( (int) (size_t) SCIPhashmapGetImage(implhash, totalvars[indv]) == indv );
2284  succdatas = (SCIP_SUCCDATA**) SCIPdigraphGetSuccessorsData(implgraph, indv);
2285  nsucc = SCIPdigraphGetNSuccessors(implgraph, indv);
2286  succ = SCIPdigraphGetSuccessors(implgraph, indv);
2287 
2288  /* search for nodew in existing successors. If this is the case then check whether the lower implication bound may be updated ... */
2289  indw = (int) (size_t) SCIPhashmapGetImage(implhash, varw);
2290  assert( (int) (size_t) SCIPhashmapGetImage(implhash, totalvars[indw]) == indw );
2291  for (s = 0; s < nsucc; ++s)
2292  {
2293  if ( succ[s] == indw )
2294  {
2295  data = succdatas[s];
2296  assert( data != NULL );
2297  if ( lower && SCIPisFeasLT(scip, data->lbimpl, newbound) )
2298  {
2299  if ( SCIPvarIsIntegral(varw) )
2300  data->lbimpl = SCIPceil(scip, newbound);
2301  else
2302  data->lbimpl = newbound;
2303 
2304  *update = TRUE;
2305  SCIPdebugMsg(scip, "updated to implication %s != 0 -> %s >= %f\n", SCIPvarGetName(varv), SCIPvarGetName(varw), newbound);
2306  }
2307  else if ( ! lower && SCIPisFeasGT(scip, data->ubimpl, newbound) )
2308  {
2309  if ( SCIPvarIsIntegral(varw) )
2310  data->ubimpl = SCIPfloor(scip, newbound);
2311  else
2312  data->ubimpl = newbound;
2313 
2314  *update = TRUE;
2315  SCIPdebugMsg(scip, "updated to implication %s != 0 -> %s >= %f\n", SCIPvarGetName(varv), SCIPvarGetName(varw), newbound);
2316  }
2317  break;
2318  }
2319  }
2320 
2321  /* ..., otherwise if there does not exist an arc between indv and indw already, then create one and add implication */
2322  if ( s == nsucc )
2323  {
2324  assert( data == NULL );
2325  SCIP_CALL( SCIPallocBlockMemory(scip, &data) );
2326  if ( lower )
2327  {
2328  data->lbimpl = newbound;
2329  data->ubimpl = ub;
2330  SCIPdebugMsg(scip, "add implication %s != 0 -> %s >= %f\n", SCIPvarGetName(varv), SCIPvarGetName(varw), newbound);
2331  }
2332  else
2333  {
2334  data->lbimpl = lb;
2335  data->ubimpl = newbound;
2336  SCIPdebugMsg(scip, "add implication %s != 0 -> %s <= %f\n", SCIPvarGetName(varv), SCIPvarGetName(varw), newbound);
2337  }
2338  SCIP_CALL( SCIPdigraphAddArc(implgraph, indv, indw, (void*)data) );
2339  *update = TRUE;
2340  }
2341 
2342  return SCIP_OKAY;
2343 }
2344 
2345 
2346 /** updates implication graph
2347  *
2348  * Assume the variable from the input is nonzero. If this implies that some other variable is also nonzero, then
2349  * store this information in an implication graph
2350  */
2351 static
2353  SCIP* scip, /**< SCIP pointer */
2354  SCIP_CONSHDLRDATA* conshdlrdata, /**< constraint handler data */
2355  SCIP_DIGRAPH* conflictgraph, /**< conflict graph */
2356  SCIP_Bool** adjacencymatrix, /**< adjacency matrix of conflict graph (lower half) */
2357  SCIP_DIGRAPH* implgraph, /**< implication graph (@p j is successor of @p i if and only if \f$ x_i\not = 0 \Rightarrow x_j\not = 0\f$) */
2358  SCIP_HASHMAP* implhash, /**< hash map from variable to node in implication graph */
2359  SCIP_Bool* implnodes, /**< implnodes[i] = TRUE if the SOS1 variable corresponding to node i in the implication graph is implied to be nonzero */
2360  SCIP_VAR** totalvars, /**< problem and SOS1 variables */
2361  int** cliquecovers, /**< clique covers of linear constraint */
2362  int* cliquecoversizes, /**< size of clique covers */
2363  int* varincover, /**< array with varincover[i] = cover of SOS1 index @p i */
2364  SCIP_VAR** vars, /**< variables to be checked */
2365  SCIP_Real* coefs, /**< coefficients of variables in linear constraint */
2366  int nvars, /**< number of variables to be checked */
2367  SCIP_Real* bounds, /**< bounds of variables */
2368  SCIP_VAR* var, /**< variable that is assumed to be nonzero */
2369  SCIP_Real bound, /**< bound of variable */
2370  SCIP_Real boundnonzero, /**< bound of variable if it is known to be nonzero if infinity values are not summarized */
2371  int ninftynonzero, /**< number of times infinity/-infinity has to be summarized to boundnonzero */
2372  SCIP_Bool lower, /**< TRUE if lower bounds are consideres; FALSE for upper bounds */
2373  int* nchgbds, /**< pointer to store number of changed bounds */
2374  SCIP_Bool* update, /**< pointer to store whether implication graph has been updated */
2375  SCIP_Bool* infeasible /**< pointer to store whether an infeasibility has been detected */
2376  )
2377 {
2378  int nodev;
2379  int w;
2380 
2381  assert( update != NULL );
2382 
2383  /* update implication graph if possible */
2384  *update = FALSE;
2385  *infeasible = FALSE;
2386  nodev = varGetNodeSOS1(conshdlrdata, var); /* possibly -1 if var is not involved in an SOS1 constraint */
2387 
2388  /* if nodev is an index of an SOS1 variable and at least one lower bound of a variable that is not x_v is infinity */
2389  if ( nodev < 0 || SCIPisInfinity(scip, REALABS(bound)) || ninftynonzero > 1 )
2390  return SCIP_OKAY;
2391 
2392  /* for every variable x_w: compute upper bound of a_w * x_w if x_v is known to be nonzero */
2393  for (w = 0; w < nvars; ++w)
2394  {
2395  int newninftynonzero;
2396  SCIP_Bool implinfty = FALSE;
2397  int nodew;
2398 
2399  /* get node of x_w in conflict graph: nodew = -1 if it is no SOS1 variable */
2400  nodew = varGetNodeSOS1(conshdlrdata, vars[w]);
2401 
2402  newninftynonzero = ninftynonzero;
2403 
2404  /* variable should not be fixed to be already zero (note x_v is fixed to be nonzero by assumption) */
2405  if ( nodew < 0 || ( nodev != nodew && ! isConnectedSOS1(adjacencymatrix, NULL, nodev, nodew) && ! isImpliedZero(conflictgraph, implnodes, nodew) ) )
2406  {
2407  SCIP_Real implbound;
2408  SCIP_Bool implcoverw;
2409  int nodecliq;
2410  int indcliq;
2411  int ind;
2412  int j;
2413 
2414  /* boundnonzero is the bound of x_v if x_v is nonzero we use this information to get a bound of x_w if x_v is
2415  * nonzero; therefore, we have to perform some recomputations */
2416  implbound = boundnonzero - bound;
2417  ind = varincover[w];
2418  assert( cliquecoversizes[ind] > 0 );
2419 
2420  implcoverw = FALSE;
2421  for (j = 0; j < cliquecoversizes[ind]; ++j)
2422  {
2423  indcliq = cliquecovers[ind][j];
2424  assert( 0 <= indcliq && indcliq < nvars );
2425 
2426  nodecliq = varGetNodeSOS1(conshdlrdata, vars[indcliq]); /* possibly -1 if variable is not involved in an SOS1 constraint */
2427 
2428  /* if nodecliq is not a member of an SOS1 constraint or the variable corresponding to nodecliq is not implied to be zero if x_v != 0 */
2429  if ( nodecliq < 0 || (! isConnectedSOS1(adjacencymatrix, NULL, nodev, nodecliq) && ! isImpliedZero(conflictgraph, implnodes, nodecliq) ) )
2430  {
2431  if ( indcliq == w )
2432  {
2433  if ( ! SCIPisInfinity(scip, REALABS(bounds[w])) )
2434  implbound += bounds[w];
2435  else
2436  --newninftynonzero;
2437  implcoverw = TRUE;
2438  }
2439  else if ( implcoverw )
2440  {
2441  if ( SCIPisInfinity(scip, REALABS( bounds[indcliq] )) )
2442  implinfty = TRUE;
2443  else
2444  implbound -= bounds[indcliq];
2445  break;
2446  }
2447  else
2448  {
2449  if ( SCIPisInfinity(scip, REALABS( bounds[indcliq] ) ) )
2450  implinfty = TRUE;
2451  break;
2452  }
2453  }
2454  }
2455 
2456  /* check whether x_v != 0 implies a bound change of x_w */
2457  if ( ! implinfty && newninftynonzero == 0 )
2458  {
2459  SCIP_Real newbound;
2460  SCIP_Real coef;
2461  SCIP_Real lb;
2462  SCIP_Real ub;
2463 
2464  lb = SCIPvarGetLbLocal(vars[w]);
2465  ub = SCIPvarGetUbLocal(vars[w]);
2466  coef = coefs[w];
2467 
2468  if ( SCIPisFeasZero(scip, coef) )
2469  continue;
2470 
2471  newbound = implbound / coef;
2472 
2473  /* check if an implication can be added/updated or assumption x_v != 0 is infeasible */
2474  if ( lower )
2475  {
2476  if ( SCIPisFeasPositive(scip, coef) && SCIPisFeasLT(scip, lb, newbound) )
2477  {
2478  SCIP_CALL( updateArcData(scip, implgraph, implhash, totalvars, var, vars[w], lb, ub, newbound, TRUE, nchgbds, update, infeasible) );
2479  }
2480  else if ( SCIPisFeasNegative(scip, coef) && SCIPisFeasGT(scip, ub, newbound) )
2481  {
2482  SCIP_CALL( updateArcData(scip, implgraph, implhash, totalvars, var, vars[w], lb, ub, newbound, FALSE, nchgbds, update, infeasible) );
2483  }
2484  }
2485  else
2486  {
2487  if ( SCIPisFeasPositive(scip, coef) && SCIPisFeasGT(scip, ub, newbound) )
2488  {
2489  SCIP_CALL( updateArcData(scip, implgraph, implhash, totalvars, var, vars[w], lb, ub, newbound, FALSE, nchgbds, update, infeasible) );
2490  }
2491  else if ( SCIPisFeasNegative(scip, coef) && SCIPisFeasLT(scip, lb, newbound) )
2492  {
2493  SCIP_CALL( updateArcData(scip, implgraph, implhash, totalvars, var, vars[w], lb, ub, newbound, TRUE, nchgbds, update, infeasible) );
2494  }
2495  }
2496  }
2497  }
2498  }
2499 
2500  return SCIP_OKAY;
2501 }
2502 
2503 
2504 /** search new disjoint clique that covers given node
2505  *
2506  * For a given vertex @p v search for a clique of the conflict graph induced by the variables of a linear constraint that
2507  * - covers @p v and
2508  * - has an an empty intersection with already computed clique cover.
2509  */
2510 static
2512  SCIP* scip, /**< SCIP pointer */
2513  SCIP_DIGRAPH* conflictgraphroot, /**< conflict graph of the root node (nodes: 1, ..., @p nsos1vars) */
2514  SCIP_DIGRAPH* conflictgraphlin, /**< conflict graph of linear constraint (nodes: 1, ..., @p nlinvars) */
2515  SCIP_VAR** linvars, /**< variables in linear constraint */
2516  SCIP_Bool* coveredvars, /**< states which variables of the linear constraint are currently covered by a clique */
2517  int* clique, /**< array to store new clique in cover */
2518  int* cliquesize, /**< pointer to store the size of @p clique */
2519  int v, /**< position of variable in linear constraint that should be covered */
2520  SCIP_Bool considersolvals /**< TRUE if largest auxiliary bigM values of variables should be prefered */
2521  )
2522 {
2523  int nsucc;
2524  int s;
2525 
2526  assert( conflictgraphlin != NULL );
2527  assert( linvars != NULL );
2528  assert( coveredvars != NULL );
2529  assert( clique != NULL );
2530  assert( cliquesize != NULL );
2531 
2532  assert( ! coveredvars[v] ); /* we should produce a new clique */
2533 
2534  /* add index 'v' to the clique cover */
2535  clique[0] = v;
2536  *cliquesize = 1;
2537 
2538  nsucc = SCIPdigraphGetNSuccessors(conflictgraphlin, v);
2539  if ( nsucc > 0 )
2540  {
2541  int* extensions;
2542  int nextensions = 0;
2543  int nextensionsnew;
2544  int succnode;
2545  int* succ;
2546 
2547  /* allocate buffer array */
2548  SCIP_CALL( SCIPallocBufferArray(scip, &extensions, nsucc) );
2549 
2550  succ = SCIPdigraphGetSuccessors(conflictgraphlin, v);
2551 
2552  /* compute possible extensions for the clique cover */
2553  for (s = 0; s < nsucc; ++s)
2554  {
2555  succnode = succ[s];
2556  if ( ! coveredvars[succnode] )
2557  extensions[nextensions++] = succ[s];
2558  }
2559 
2560  /* while there exist possible extensions for the clique cover */
2561  while ( nextensions > 0 )
2562  {
2563  int bestindex = -1;
2564 
2565  if ( considersolvals )
2566  {
2567  SCIP_Real bestbigMval;
2568  SCIP_Real bigMval;
2569 
2570  bestbigMval = -SCIPinfinity(scip);
2571 
2572  /* search for the extension with the largest absolute value of its LP relaxation solution value */
2573  for (s = 0; s < nextensions; ++s)
2574  {
2575  bigMval = nodeGetSolvalBinaryBigMSOS1(scip, conflictgraphroot, NULL, extensions[s]);
2576  if ( SCIPisFeasLT(scip, bestbigMval, bigMval) )
2577  {
2578  bestbigMval = bigMval;
2579  bestindex = extensions[s];
2580  }
2581  }
2582  }
2583  else
2584  bestindex = extensions[0];
2585 
2586  assert( bestindex != -1 );
2587 
2588  /* add bestindex to the clique cover */
2589  clique[(*cliquesize)++] = bestindex;
2590 
2591  /* compute new 'extensions' array */
2592  nextensionsnew = 0;
2593  for (s = 0; s < nextensions; ++s)
2594  {
2595  if ( s != bestindex && isConnectedSOS1(NULL, conflictgraphlin, bestindex, extensions[s]) )
2596  extensions[nextensionsnew++] = extensions[s];
2597  }
2598  nextensions = nextensionsnew;
2599  }
2600 
2601  /* free buffer array */
2602  SCIPfreeBufferArray(scip, &extensions);
2603  }
2604 
2605  /* mark covered indices */
2606  for (s = 0; s < *cliquesize; ++s)
2607  {
2608  int ind;
2609 
2610  ind = clique[s];
2611  assert( 0 <= ind );
2612  assert( ! coveredvars[ind] );
2613  coveredvars[ind] = TRUE;
2614  }
2615 
2616  return SCIP_OKAY;
2617 }
2618 
2619 
2620 /** try to tighten upper and lower bounds for variables */
2621 static
2623  SCIP* scip, /**< SCIP pointer */
2624  SCIP_CONSHDLRDATA* conshdlrdata, /**< constraint handler data */
2625  SCIP_DIGRAPH* conflictgraph, /**< conflict graph */
2626  SCIP_DIGRAPH* implgraph, /**< implication graph (@p j is successor of @p i if and only if \f$ x_i\not = 0 \f$ implies a new lower/upper bound for \f$ x_j\f$) */
2627  SCIP_HASHMAP* implhash, /**< hash map from variable to node in implication graph */
2628  SCIP_Bool** adjacencymatrix, /**< adjacencymatrix of conflict graph */
2629  SCIP_VAR** totalvars, /**< problem and SOS1 vars */
2630  int ntotalvars, /**< number of problem and SOS1 variables*/
2631  int nsos1vars, /**< number of SOS1 variables */
2632  int* nchgbds, /**< pointer to store number of changed bounds */
2633  SCIP_Bool* implupdate, /**< pointer to store whether the implication graph has been updated in this function call */
2634  SCIP_Bool* cutoff /**< pointer to store if current nodes LP is infeasible */
2635  )
2636 {
2637  SCIP_CONSHDLR* conshdlrlinear;
2638  SCIP_CONS** linearconss;
2639  int nlinearconss;
2640 
2641  SCIP_Bool* implnodes = NULL; /* implnodes[i] = TRUE if the SOS1 variable corresponding to node i in the implication graph is implied to be nonzero */
2642  SCIP_Bool* coveredvars = NULL; /* coveredvars[i] = TRUE if variable with index i is covered by the clique cover */
2643  int* varindincons = NULL; /* varindincons[i] = position of SOS1 index i in linear constraint (-1 if x_i is not involved in linear constraint) */
2644 
2645  SCIP_VAR** trafolinvars = NULL; /* variables of transformed linear constraints without (multi)aggregated variables */
2646  int ntrafolinvars = 0;
2647  SCIP_Real* trafolinvals = NULL;
2648  SCIP_Real* trafoubs = NULL;
2649  SCIP_Real* trafolbs = NULL;
2650  SCIP_Real traforhs;
2651  SCIP_Real trafolhs;
2652 
2653  SCIP_VAR** sos1linvars = NULL; /* variables that are not contained in linear constraint, but are in conflict with a variable from the linear constraint */
2654  int nsos1linvars;
2655  int c;
2656 
2657  assert( scip != NULL );
2658  assert( conflictgraph != NULL );
2659  assert( adjacencymatrix != NULL );
2660  assert( nchgbds != NULL );
2661  assert( cutoff != NULL );
2662 
2663  *cutoff = FALSE;
2664  *implupdate = FALSE;
2665 
2666  /* get constraint handler data of linear constraints */
2667  conshdlrlinear = SCIPfindConshdlr(scip, "linear");
2668  if ( conshdlrlinear == NULL )
2669  return SCIP_OKAY;
2670 
2671  /* get linear constraints and number of linear constraints */
2672  nlinearconss = SCIPconshdlrGetNConss(conshdlrlinear);
2673  linearconss = SCIPconshdlrGetConss(conshdlrlinear);
2674 
2675  /* allocate buffer arrays */
2676  SCIP_CALL( SCIPallocBufferArray(scip, &sos1linvars, nsos1vars) );
2677  SCIP_CALL( SCIPallocBufferArray(scip, &implnodes, nsos1vars) );
2678  SCIP_CALL( SCIPallocBufferArray(scip, &varindincons, nsos1vars) );
2679  SCIP_CALL( SCIPallocBufferArray(scip, &coveredvars, ntotalvars) );
2680  SCIP_CALL( SCIPallocBufferArray(scip, &trafoubs, ntotalvars) );
2681  SCIP_CALL( SCIPallocBufferArray(scip, &trafolbs, ntotalvars) );
2682 
2683  /* for every linear constraint and every SOS1 variable */
2684  for (c = 0; c < nlinearconss + nsos1vars && ! (*cutoff); ++c)
2685  {
2686  SCIP_DIGRAPH* conflictgraphlin;
2687  int** cliquecovers = NULL; /* clique covers of indices of variables in linear constraint */
2688  int* cliquecoversizes = NULL; /* size of each cover */
2689  int ncliquecovers;
2690  SCIP_Real* cliquecovervals = NULL;
2691  int* varincover = NULL; /* varincover[i] = cover of SOS1 index i */
2692 
2693  int v;
2694  int i;
2695  int j;
2696 
2697  /* get transformed linear constraints (without aggregated variables) */
2698  if ( c < nlinearconss )
2699  {
2700  SCIP_VAR** origlinvars;
2701  int noriglinvars;
2702  SCIP_Real* origlinvals;
2703  SCIP_Real origrhs;
2704  SCIP_Real origlhs;
2705  SCIP_Real constant;
2706  int requiredsize;
2707 
2708  /* get data of linear constraint */
2709  noriglinvars = SCIPgetNVarsLinear(scip, linearconss[c]);
2710  origlinvars = SCIPgetVarsLinear(scip, linearconss[c]);
2711  origlinvals = SCIPgetValsLinear(scip, linearconss[c]);
2712  origrhs = SCIPgetRhsLinear(scip, linearconss[c]);
2713  origlhs = SCIPgetLhsLinear(scip, linearconss[c]);
2714 
2715  if ( noriglinvars < 1 )
2716  continue;
2717  assert( origlinvars != NULL );
2718  assert( origlinvals != NULL );
2719 
2720  /* copy variables and coefficients of linear constraint */
2721  SCIP_CALL( SCIPduplicateBufferArray(scip, &trafolinvars, origlinvars, noriglinvars) );
2722  SCIP_CALL( SCIPduplicateBufferArray(scip, &trafolinvals, origlinvals, noriglinvars) );
2723  ntrafolinvars = noriglinvars;
2724 
2725  /* transform linear constraint */
2726  constant = 0.0;
2727  SCIP_CALL( SCIPgetProbvarLinearSum(scip, trafolinvars, trafolinvals, &ntrafolinvars, noriglinvars, &constant, &requiredsize, TRUE) );
2728  if( requiredsize > ntrafolinvars )
2729  {
2730  SCIP_CALL( SCIPreallocBufferArray(scip, &trafolinvars, requiredsize) );
2731  SCIP_CALL( SCIPreallocBufferArray(scip, &trafolinvals, requiredsize) );
2732 
2733  SCIP_CALL( SCIPgetProbvarLinearSum(scip, trafolinvars, trafolinvals, &ntrafolinvars, requiredsize, &constant, &requiredsize, TRUE) );
2734  assert( requiredsize <= ntrafolinvars );
2735  }
2736  trafolhs = origlhs - constant;
2737  traforhs = origrhs - constant;
2738  }
2739  else
2740  {
2741  SCIP_VAR* var;
2742 
2743  var = SCIPnodeGetVarSOS1(conflictgraph, c-nlinearconss);
2744 
2746  {
2747  SCIP_Real constant;
2748 
2749  SCIP_CALL( SCIPallocBufferArray(scip, &trafolinvars, 2) );
2750  SCIP_CALL( SCIPallocBufferArray(scip, &trafolinvals, 2) );
2751 
2752  constant = SCIPvarGetAggrConstant(var);
2753  trafolinvars[0] = SCIPvarGetAggrVar(var);
2754  trafolinvals[0] = SCIPvarGetAggrScalar(var);
2755  trafolinvars[1] = var;
2756  trafolinvals[1] = -1.0;
2757  trafolhs = -constant;
2758  traforhs = -constant;
2759  ntrafolinvars = 2;
2760  }
2761  else if ( SCIPvarGetStatus(var) == SCIP_VARSTATUS_MULTAGGR )
2762  {
2763  SCIP_Real* scalars;
2764  SCIP_VAR** agrvars;
2765  SCIP_Real constant;
2766  int nagrvars;
2767 
2768  nagrvars = SCIPvarGetMultaggrNVars(var);
2769 
2770  SCIP_CALL( SCIPallocBufferArray(scip, &trafolinvars, nagrvars+1) );
2771  SCIP_CALL( SCIPallocBufferArray(scip, &trafolinvals, nagrvars+1) );
2772 
2773  agrvars = SCIPvarGetMultaggrVars(var);
2774  scalars = SCIPvarGetMultaggrScalars(var);
2775  constant = SCIPvarGetMultaggrConstant(var);
2776 
2777  for (v = 0; v < nagrvars; ++v)
2778  {
2779  trafolinvars[v] = agrvars[v];
2780  trafolinvals[v] = scalars[v];
2781  }
2782  trafolinvars[nagrvars] = var;
2783  trafolinvals[nagrvars] = -1.0;
2784  trafolhs = -constant;
2785  traforhs = -constant;
2786  ntrafolinvars = nagrvars + 1;
2787  }
2788  else if ( SCIPvarGetStatus(var) == SCIP_VARSTATUS_NEGATED )
2789  {
2790  SCIP_VAR* negvar;
2791  SCIP_Real negcons;
2792 
2793  /* get negation variable and negation offset */
2794  negvar = SCIPvarGetNegationVar(var);
2795  negcons = SCIPvarGetNegationConstant(var);
2796 
2797  SCIP_CALL( SCIPallocBufferArray(scip, &trafolinvars, 2) );
2798  SCIP_CALL( SCIPallocBufferArray(scip, &trafolinvals, 2) );
2799 
2800  trafolinvars[0] = negvar;
2801  trafolinvars[1] = var;
2802  trafolinvals[0] = 1.0;
2803  trafolinvals[1] = 1.0;
2804  trafolhs = negcons;
2805  traforhs = negcons;
2806  ntrafolinvars = 2;
2807  }
2808  else
2809  continue;
2810  }
2811 
2812  if ( ntrafolinvars == 0 )
2813  {
2814  SCIPfreeBufferArray(scip, &trafolinvars);
2815  SCIPfreeBufferArray(scip, &trafolinvals);
2816  continue;
2817  }
2818 
2819  /* compute lower and upper bounds of each term a_i * x_i of transformed constraint */
2820  for (v = 0; v < ntrafolinvars; ++v)
2821  {
2822  SCIP_Real lb = SCIPvarGetLbLocal(trafolinvars[v]);
2823  SCIP_Real ub = SCIPvarGetUbLocal(trafolinvars[v]);
2824 
2825  if ( trafolinvals[v] < 0.0 )
2826  {
2827  SCIP_Real temp;
2828 
2829  temp = lb;
2830  lb = ub;
2831  ub = temp;
2832  }
2833 
2834  if ( SCIPisInfinity(scip, REALABS(lb)) )
2835  trafolbs[v] = -SCIPinfinity(scip);
2836  else
2837  trafolbs[v] = lb * trafolinvals[v];
2838 
2839  if ( SCIPisInfinity(scip, REALABS(ub)) )
2840  trafoubs[v] = SCIPinfinity(scip);
2841  else
2842  trafoubs[v] = ub * trafolinvals[v];
2843  }
2844 
2845  /* initialization: mark all the SOS1 variables as 'not a member of the linear constraint' */
2846  for (v = 0; v < nsos1vars; ++v)
2847  varindincons[v] = -1;
2848 
2849  /* save position of SOS1 variables in linear constraint */
2850  for (v = 0; v < ntrafolinvars; ++v)
2851  {
2852  int node;
2853 
2854  node = varGetNodeSOS1(conshdlrdata, trafolinvars[v]);
2855 
2856  if ( node >= 0 )
2857  varindincons[node] = v;
2858  }
2859 
2860  /* create conflict graph of linear constraint */
2861  SCIP_CALL( SCIPdigraphCreate(&conflictgraphlin, ntrafolinvars) );
2862  SCIP_CALL( genConflictgraphLinearCons(conshdlrdata, conflictgraphlin, conflictgraph, trafolinvars, ntrafolinvars, varindincons) );
2863 
2864  /* mark all the variables as 'not covered by some clique cover' */
2865  for (i = 0; i < ntrafolinvars; ++i)
2866  coveredvars[i] = FALSE;
2867 
2868  /* allocate buffer array */
2869  SCIP_CALL( SCIPallocBufferArray(scip, &cliquecovervals, ntrafolinvars) );
2870  SCIP_CALL( SCIPallocBufferArray(scip, &cliquecoversizes, ntrafolinvars) );
2871  SCIP_CALL( SCIPallocBufferArray(scip, &cliquecovers, ntrafolinvars) );
2872 
2873  /* compute distinct cliques that cover all the variables of the linear constraint */
2874  ncliquecovers = 0;
2875  for (v = 0; v < ntrafolinvars; ++v)
2876  {
2877  /* if variable is not already covered by an already known clique cover */
2878  if ( ! coveredvars[v] )
2879  {
2880  SCIP_CALL( SCIPallocBufferArray(scip, &(cliquecovers[ncliquecovers]), ntrafolinvars) ); /*lint !e866*/
2881  SCIP_CALL( computeVarsCoverSOS1(scip, conflictgraph, conflictgraphlin, trafolinvars, coveredvars, cliquecovers[ncliquecovers], &(cliquecoversizes[ncliquecovers]), v, FALSE) );
2882  ++ncliquecovers;
2883  }
2884  }
2885 
2886  /* free conflictgraph */
2887  SCIPdigraphFree(&conflictgraphlin);
2888 
2889  /* compute variables that are not contained in transformed linear constraint, but are in conflict with a variable from the transformed linear constraint */
2890  nsos1linvars = 0;
2891  for (v = 0; v < ntrafolinvars; ++v)
2892  {
2893  int nodev;
2894 
2895  nodev = varGetNodeSOS1(conshdlrdata, trafolinvars[v]);
2896 
2897  /* if variable is an SOS1 variable */
2898  if ( nodev >= 0 )
2899  {
2900  int succnode;
2901  int nsucc;
2902  int* succ;
2903  int s;
2904 
2905  succ = SCIPdigraphGetSuccessors(conflictgraph, nodev);
2906  nsucc = SCIPdigraphGetNSuccessors(conflictgraph, nodev);
2907 
2908  for (s = 0; s < nsucc; ++s)
2909  {
2910  succnode = succ[s];
2911 
2912  /* if variable is not a member of linear constraint and not already listed in the array sos1linvars */
2913  if ( varindincons[succnode] == -1 )
2914  {
2915  sos1linvars[nsos1linvars] = SCIPnodeGetVarSOS1(conflictgraph, succnode);
2916  varindincons[succnode] = -2; /* mark variable as listed in array sos1linvars */
2917  ++nsos1linvars;
2918  }
2919  }
2920  }
2921  }
2922 
2923 
2924  /* try to tighten lower bounds */
2925 
2926  /* sort each cliquecover array in ascending order of the lower bounds of a_i * x_i; fill vector varincover */
2927  SCIP_CALL( SCIPallocBufferArray(scip, &varincover, ntrafolinvars) );
2928  for (i = 0; i < ncliquecovers; ++i)
2929  {
2930  for (j = 0; j < cliquecoversizes[i]; ++j)
2931  {
2932  int ind = cliquecovers[i][j];
2933 
2934  varincover[ind] = i;
2935  cliquecovervals[j] = trafoubs[ind];
2936  }
2937  SCIPsortDownRealInt(cliquecovervals, cliquecovers[i], cliquecoversizes[i]);
2938  }
2939 
2940  /* for every variable in transformed constraint: try lower bound tightening */
2941  for (v = 0; v < ntrafolinvars + nsos1linvars; ++v)
2942  {
2943  SCIP_Real newboundnonzero; /* new bound of a_v * x_v if we assume that x_v != 0 */
2944  SCIP_Real newboundnores; /* new bound of a_v * x_v if we assume that x_v = 0 is possible */
2945  SCIP_Real newbound; /* resulting new bound of x_v */
2946  SCIP_VAR* var;
2947  SCIP_Real trafoubv;
2948  SCIP_Real linval;
2949  SCIP_Real ub;
2950  SCIP_Real lb;
2951  SCIP_Bool tightened;
2952  SCIP_Bool infeasible;
2953  SCIP_Bool inftynores = FALSE;
2954  SCIP_Bool update;
2955  int ninftynonzero = 0;
2956  int nodev;
2957  int w;
2958 
2959  if ( v < ntrafolinvars )
2960  {
2961  var = trafolinvars[v];
2962  trafoubv = trafoubs[v];
2963  }
2964  else
2965  {
2966  assert( v >= ntrafolinvars );
2967  var = sos1linvars[v-ntrafolinvars];/*lint !e679*/
2968  trafoubv = 0.0;
2969  }
2970 
2971  ub = SCIPvarGetUbLocal(var);
2972  lb = SCIPvarGetLbLocal(var);
2973 
2974  if ( SCIPisInfinity(scip, -trafolhs) || SCIPisZero(scip, ub - lb) )
2975  continue;
2976 
2977  newboundnonzero = trafolhs;
2978  newboundnores = trafolhs;
2979  nodev = varGetNodeSOS1(conshdlrdata, var); /* possibly -1 if var is not involved in an SOS1 constraint */
2980  assert( nodev < nsos1vars );
2981 
2982  /* determine incidence vector of implication variables */
2983  for (w = 0; w < nsos1vars; ++w)
2984  implnodes[w] = FALSE;
2985  SCIP_CALL( getSOS1Implications(scip, conshdlrdata, totalvars, implgraph, implhash, implnodes, (int) (size_t) SCIPhashmapGetImage(implhash, var)) );
2986 
2987  /* compute new bound */
2988  for (i = 0; i < ncliquecovers; ++i)
2989  {
2990  int indcliq;
2991  int nodecliq;
2992 
2993  assert( cliquecoversizes[i] > 0 );
2994 
2995  indcliq = cliquecovers[i][0];
2996  assert( 0 <= indcliq && indcliq < ntrafolinvars );
2997 
2998  /* determine maximum without index v (note that the array 'cliquecovers' is sorted by the values of trafoub in non-increasing order) */
2999  if ( v != indcliq )
3000  {
3001  if ( SCIPisInfinity(scip, trafoubs[indcliq]) )
3002  inftynores = TRUE;
3003  else
3004  newboundnores -= trafoubs[indcliq];
3005  }
3006  else if ( cliquecoversizes[i] > 1 )
3007  {
3008  assert( 0 <= cliquecovers[i][1] && cliquecovers[i][1] < ntrafolinvars );
3009  if ( SCIPisInfinity(scip, trafoubs[cliquecovers[i][1]]) )
3010  inftynores = TRUE;
3011  else
3012  newboundnores -= trafoubs[cliquecovers[i][1]];/*lint --e{679}*/
3013  }
3014 
3015  /* determine maximum without index v and if x_v is nonzero (note that the array 'cliquecovers' is sorted by the values of trafoub in non-increasing order) */
3016  for (j = 0; j < cliquecoversizes[i]; ++j)
3017  {
3018  indcliq = cliquecovers[i][j];
3019  assert( 0 <= indcliq && indcliq < ntrafolinvars );
3020 
3021  nodecliq = varGetNodeSOS1(conshdlrdata, trafolinvars[indcliq]); /* possibly -1 if variable is not involved in an SOS1 constraint */
3022  assert( nodecliq < nsos1vars );
3023 
3024  if ( v != indcliq )
3025  {
3026  /* if nodev or nodecliq are not a member of an SOS1 constraint or the variable corresponding to nodecliq is not implied to be zero if x_v != 0 */
3027  if ( nodev < 0 || nodecliq < 0 || (! isConnectedSOS1(adjacencymatrix, NULL, nodev, nodecliq) && ! isImpliedZero(conflictgraph, implnodes, nodecliq) ) )
3028  {
3029  if ( SCIPisInfinity(scip, trafoubs[indcliq]) )
3030  ++ninftynonzero;
3031  else
3032  newboundnonzero -= trafoubs[indcliq];
3033  break; /* break since we are only interested in the maximum upper bound among the variables in the clique cover;
3034  * the variables in the clique cover form an SOS1 constraint, thus only one of them can be nonzero */
3035  }
3036  }
3037  }
3038  }
3039  assert( ninftynonzero == 0 || inftynores );
3040 
3041  /* if computed upper bound is not infinity and variable is contained in linear constraint */
3042  if ( ninftynonzero == 0 && v < ntrafolinvars )
3043  {
3044  linval = trafolinvals[v];
3045 
3046  if ( SCIPisFeasZero(scip, linval) )
3047  continue;
3048 
3049  /* compute new bound */
3050  if ( SCIPisFeasPositive(scip, newboundnores) && ! inftynores )
3051  newbound = newboundnonzero;
3052  else
3053  newbound = MIN(0, newboundnonzero);
3054  newbound /= linval;
3055 
3056  /* check if new bound is tighter than the old one or problem is infeasible */
3057  if ( SCIPisFeasPositive(scip, linval) && SCIPisFeasLT(scip, lb, newbound) )
3058  {
3059  if ( SCIPisFeasLT(scip, ub, newbound) )
3060  {
3061  *cutoff = TRUE;
3062  break;
3063  }
3064 
3065  if ( SCIPvarIsIntegral(var) )
3066  newbound = SCIPceil(scip, newbound);
3067 
3068  SCIP_CALL( SCIPtightenVarLb(scip, var, newbound, FALSE, &infeasible, &tightened) );
3069  assert( ! infeasible );
3070 
3071  if ( tightened )
3072  {
3073  SCIPdebugMsg(scip, "changed lower bound of variable %s from %f to %f \n", SCIPvarGetName(var), lb, newbound);
3074  ++(*nchgbds);
3075  }
3076  }
3077  else if ( SCIPisFeasNegative(scip, linval) && SCIPisFeasGT(scip, ub, newbound) )
3078  {
3079  /* if assumption a_i * x_i != 0 was not correct */
3080  if ( SCIPisFeasGT(scip, SCIPvarGetLbLocal(var), newbound) )
3081  {
3082  *cutoff = TRUE;
3083  break;
3084  }
3085 
3086  if ( SCIPvarIsIntegral(var) )
3087  newbound = SCIPfloor(scip, newbound);
3088 
3089  SCIP_CALL( SCIPtightenVarUb(scip, var, newbound, FALSE, &infeasible, &tightened) );
3090  assert( ! infeasible );
3091 
3092  if ( tightened )
3093  {
3094  SCIPdebugMsg(scip, "changed upper bound of variable %s from %f to %f \n", SCIPvarGetName(var), ub, newbound);
3095  ++(*nchgbds);
3096  }
3097  }
3098  }
3099 
3100  /* update implication graph if possible */
3101  SCIP_CALL( updateImplicationGraphSOS1(scip, conshdlrdata, conflictgraph, adjacencymatrix, implgraph, implhash, implnodes, totalvars, cliquecovers, cliquecoversizes, varincover,
3102  trafolinvars, trafolinvals, ntrafolinvars, trafoubs, var, trafoubv, newboundnonzero, ninftynonzero, TRUE, nchgbds, &update, &infeasible) );
3103  if ( infeasible )
3104  *cutoff = TRUE;
3105  else if ( update )
3106  *implupdate = TRUE;
3107  }
3108 
3109  if ( *cutoff == TRUE )
3110  {
3111  /* free memory */
3112  SCIPfreeBufferArrayNull(scip, &varincover);
3113  for (j = ncliquecovers-1; j >= 0; --j)
3114  SCIPfreeBufferArrayNull(scip, &cliquecovers[j]);
3115  SCIPfreeBufferArrayNull(scip, &cliquecovers);
3116  SCIPfreeBufferArrayNull(scip, &cliquecoversizes);
3117  SCIPfreeBufferArrayNull(scip, &cliquecovervals);
3118  SCIPfreeBufferArrayNull(scip, &trafolinvals);
3119  SCIPfreeBufferArrayNull(scip, &trafolinvars);
3120  break;
3121  }
3122 
3123 
3124  /* try to tighten upper bounds */
3125 
3126  /* sort each cliquecover array in ascending order of the lower bounds of a_i * x_i; fill vector varincover */
3127  for (i = 0; i < ncliquecovers; ++i)
3128  {
3129  for (j = 0; j < cliquecoversizes[i]; ++j)
3130  {
3131  int ind = cliquecovers[i][j];
3132 
3133  varincover[ind] = i;
3134  cliquecovervals[j] = trafolbs[ind];
3135  }
3136  SCIPsortRealInt(cliquecovervals, cliquecovers[i], cliquecoversizes[i]);
3137  }
3138 
3139  /* for every variable that is in transformed constraint or every variable that is in conflict with some variable from trans. cons.:
3140  try upper bound tightening */
3141  for (v = 0; v < ntrafolinvars + nsos1linvars; ++v)
3142  {
3143  SCIP_Real newboundnonzero; /* new bound of a_v*x_v if we assume that x_v != 0 */
3144  SCIP_Real newboundnores; /* new bound of a_v*x_v if there are no restrictions */
3145  SCIP_Real newbound; /* resulting new bound of x_v */
3146  SCIP_VAR* var;
3147  SCIP_Real linval;
3148  SCIP_Real trafolbv;
3149  SCIP_Real lb;
3150  SCIP_Real ub;
3151  SCIP_Bool tightened;
3152  SCIP_Bool infeasible;
3153  SCIP_Bool inftynores = FALSE;
3154  SCIP_Bool update;
3155  int ninftynonzero = 0;
3156  int nodev;
3157  int w;
3158 
3159  if ( v < ntrafolinvars )
3160  {
3161  var = trafolinvars[v];
3162  trafolbv = trafolbs[v];
3163  }
3164  else
3165  {
3166  assert( v-ntrafolinvars >= 0 );
3167  var = sos1linvars[v-ntrafolinvars];/*lint !e679*/
3168  trafolbv = 0.0; /* since variable is not a member of linear constraint */
3169  }
3170  lb = SCIPvarGetLbLocal(var);
3171  ub = SCIPvarGetUbLocal(var);
3172  if ( SCIPisInfinity(scip, traforhs) || SCIPisEQ(scip, lb, ub) )
3173  continue;
3174 
3175  newboundnonzero = traforhs;
3176  newboundnores = traforhs;
3177  nodev = varGetNodeSOS1(conshdlrdata, var); /* possibly -1 if var is not involved in an SOS1 constraint */
3178  assert( nodev < nsos1vars );
3179 
3180  /* determine incidence vector of implication variables (i.e., which SOS1 variables are nonzero if x_v is nonzero) */
3181  for (w = 0; w < nsos1vars; ++w)
3182  implnodes[w] = FALSE;
3183  SCIP_CALL( getSOS1Implications(scip, conshdlrdata, totalvars, implgraph, implhash, implnodes, (int) (size_t) SCIPhashmapGetImage(implhash, var)) );
3184 
3185  /* compute new bound */
3186  for (i = 0; i < ncliquecovers; ++i)
3187  {
3188  int indcliq;
3189  int nodecliq;
3190 
3191  assert( cliquecoversizes[i] > 0 );
3192 
3193  indcliq = cliquecovers[i][0];
3194  assert( 0 <= indcliq && indcliq < ntrafolinvars );
3195 
3196  /* determine minimum without index v (note that the array 'cliquecovers' is sorted by the values of trafolb in increasing order) */
3197  if ( v != indcliq )
3198  {
3199  /* if bound would be infinity */
3200  if ( SCIPisInfinity(scip, -trafolbs[indcliq]) )
3201  inftynores = TRUE;
3202  else
3203  newboundnores -= trafolbs[indcliq];
3204  }
3205  else if ( cliquecoversizes[i] > 1 )
3206  {
3207  assert( 0 <= cliquecovers[i][1] && cliquecovers[i][1] < ntrafolinvars );
3208  if ( SCIPisInfinity(scip, -trafolbs[cliquecovers[i][1]]) )
3209  inftynores = TRUE;
3210  else
3211  newboundnores -= trafolbs[cliquecovers[i][1]]; /*lint --e{679}*/
3212  }
3213 
3214  /* determine minimum without index v and if x_v is nonzero (note that the array 'cliquecovers' is sorted by the values of trafolb in increasing order) */
3215  for (j = 0; j < cliquecoversizes[i]; ++j)
3216  {
3217  indcliq = cliquecovers[i][j];
3218  assert( 0 <= indcliq && indcliq < ntrafolinvars );
3219 
3220  nodecliq = varGetNodeSOS1(conshdlrdata, trafolinvars[indcliq]); /* possibly -1 if variable is not involved in an SOS1 constraint */
3221  assert( nodecliq < nsos1vars );
3222 
3223  if ( v != indcliq )
3224  {
3225  /* if nodev or nodecliq are not a member of an SOS1 constraint or the variable corresponding to nodecliq is not implied to be zero if x_v != 0 */
3226  if ( nodev < 0 || nodecliq < 0 || (! isConnectedSOS1(adjacencymatrix, NULL, nodev, nodecliq) && ! isImpliedZero(conflictgraph, implnodes, nodecliq) ) )
3227  {
3228  /* if bound would be infinity */
3229  if ( SCIPisInfinity(scip, -trafolbs[indcliq]) )
3230  ++ninftynonzero;
3231  else
3232  newboundnonzero -= trafolbs[indcliq];
3233  break; /* break since we are only interested in the minimum lower bound among the variables in the clique cover;
3234  * the variables in the clique cover form an SOS1 constraint, thus only one of them can be nonzero */
3235  }
3236  }
3237  }
3238  }
3239  assert( ninftynonzero == 0 || inftynores );
3240 
3241 
3242  /* if computed bound is not infinity and variable is contained in linear constraint */
3243  if ( ninftynonzero == 0 && v < ntrafolinvars )
3244  {
3245  linval = trafolinvals[v];
3246 
3247  if ( SCIPisFeasZero(scip, linval) )
3248  continue;
3249 
3250  /* compute new bound */
3251  if ( SCIPisFeasNegative(scip, newboundnores) && ! inftynores )
3252  newbound = newboundnonzero;
3253  else
3254  newbound = MAX(0, newboundnonzero);
3255  newbound /= linval;
3256 
3257  /* check if new bound is tighter than the old one or problem is infeasible */
3258  if ( SCIPisFeasPositive(scip, linval) && SCIPisFeasGT(scip, ub, newbound) )
3259  {
3260  /* if new upper bound is smaller than the lower bound, we are infeasible */
3261  if ( SCIPisFeasGT(scip, lb, newbound) )
3262  {
3263  *cutoff = TRUE;
3264  break;
3265  }
3266 
3267  if ( SCIPvarIsIntegral(var) )
3268  newbound = SCIPfloor(scip, newbound);
3269 
3270  SCIP_CALL( SCIPtightenVarUb(scip, var, newbound, FALSE, &infeasible, &tightened) );
3271  assert( ! infeasible );
3272 
3273  if ( tightened )
3274  {
3275  SCIPdebugMsg(scip, "changed upper bound of variable %s from %f to %f \n", SCIPvarGetName(var), ub, newbound);
3276  ++(*nchgbds);
3277  }
3278  }
3279  else if ( SCIPisFeasNegative(scip, linval) && SCIPisFeasLT(scip, lb, newbound) )
3280  {
3281  /* if assumption a_i * x_i != 0 was not correct */
3282  if ( SCIPisFeasLT(scip, ub, newbound) )
3283  {
3284  *cutoff = TRUE;
3285  break;
3286  }
3287 
3288  if ( SCIPvarIsIntegral(var) )
3289  newbound = SCIPceil(scip, newbound);
3290 
3291  SCIP_CALL( SCIPtightenVarLb(scip, var, newbound, FALSE, &infeasible, &tightened) );
3292  assert( ! infeasible );
3293 
3294  if ( tightened )
3295  {
3296  SCIPdebugMsg(scip, "changed lower bound of variable %s from %f to %f \n", SCIPvarGetName(var), lb, newbound);
3297  ++(*nchgbds);
3298  }
3299  }
3300  }
3301 
3302  /* update implication graph if possible */
3303  SCIP_CALL( updateImplicationGraphSOS1(scip, conshdlrdata, conflictgraph, adjacencymatrix, implgraph, implhash, implnodes, totalvars, cliquecovers, cliquecoversizes, varincover,
3304  trafolinvars, trafolinvals, ntrafolinvars, trafolbs, var, trafolbv, newboundnonzero, ninftynonzero, FALSE, nchgbds, &update, &infeasible) );
3305  if ( infeasible )
3306  *cutoff = TRUE;
3307  else if ( update )
3308  *implupdate = TRUE;
3309  }
3310 
3311  /* free memory */
3312  SCIPfreeBufferArrayNull(scip, &varincover);
3313  for (j = ncliquecovers-1; j >= 0; --j)
3314  SCIPfreeBufferArrayNull(scip, &cliquecovers[j]);
3315  SCIPfreeBufferArrayNull(scip, &cliquecovers);
3316  SCIPfreeBufferArrayNull(scip, &cliquecoversizes);
3317  SCIPfreeBufferArrayNull(scip, &cliquecovervals);
3318  SCIPfreeBufferArrayNull(scip, &trafolinvals);
3319  SCIPfreeBufferArrayNull(scip, &trafolinvars);
3320 
3321  if ( *cutoff == TRUE )
3322  break;
3323  } /* end for every linear constraint */
3324 
3325  /* free buffer arrays */
3326  SCIPfreeBufferArrayNull(scip, &sos1linvars);
3327  SCIPfreeBufferArrayNull(scip, &trafolbs);
3328  SCIPfreeBufferArrayNull(scip, &trafoubs);
3329  SCIPfreeBufferArrayNull(scip, &coveredvars);
3330  SCIPfreeBufferArrayNull(scip, &varindincons);
3331  SCIPfreeBufferArrayNull(scip, &implnodes);
3332 
3333  return SCIP_OKAY;
3334 }
3335 
3336 
3337 /** perform one presolving round for variables
3338  *
3339  * We perform the following presolving steps:
3340  * - Tighten the bounds of the variables
3341  * - Update conflict graph based on bound implications of the variables
3342  */
3343 static
3345  SCIP* scip, /**< SCIP pointer */
3346  SCIP_CONSHDLRDATA* conshdlrdata, /**< constraint handler data */
3347  SCIP_DIGRAPH* conflictgraph, /**< conflict graph */
3348  SCIP_Bool** adjacencymatrix, /**< adjacencymatrix of conflict graph */
3349  int nsos1vars, /**< number of SOS1 variables */
3350  int* nfixedvars, /**< pointer to store number of fixed variables */
3351  int* nchgbds, /**< pointer to store number of changed bounds */
3352  int* naddconss, /**< pointer to store number of addded constraints */
3353  SCIP_RESULT* result /**< result */
3354  )
3355 {
3356  SCIP_DIGRAPH* implgraph;
3357  SCIP_HASHMAP* implhash;
3358 
3359  SCIP_Bool cutoff = FALSE;
3360  SCIP_Bool updateconfl;
3361 
3362  SCIP_VAR** totalvars;
3363  SCIP_VAR** probvars;
3364  int ntotalvars = 0;
3365  int nprobvars;
3366  int i;
3367  int j;
3368 
3369  /* determine totalvars (union of SOS1 and problem variables) */
3370  probvars = SCIPgetVars(scip);
3371  nprobvars = SCIPgetNVars(scip);
3372  SCIP_CALL( SCIPhashmapCreate(&implhash, SCIPblkmem(scip), nsos1vars + nprobvars) );
3373  SCIP_CALL( SCIPallocBufferArray(scip, &totalvars, nsos1vars + nprobvars) );
3374 
3375  for (i = 0; i < nsos1vars; ++i)
3376  {
3377  SCIP_VAR* var;
3378  var = SCIPnodeGetVarSOS1(conflictgraph, i);
3379 
3380  /* insert node number to hash map */
3381  assert( ! SCIPhashmapExists(implhash, var) );
3382  SCIP_CALL( SCIPhashmapInsert(implhash, var, (void*) (size_t) ntotalvars) );/*lint !e571*/
3383  assert( ntotalvars == (int) (size_t) SCIPhashmapGetImage(implhash, var) );
3384  totalvars[ntotalvars++] = var;
3385  }
3386 
3387  for (i = 0; i < nprobvars; ++i)
3388  {
3389  SCIP_VAR* var;
3390  var = probvars[i];
3391 
3392  /* insert node number to hash map if not existent */
3393  if ( ! SCIPhashmapExists(implhash, var) )
3394  {
3395  SCIP_CALL( SCIPhashmapInsert(implhash, var, (void*) (size_t) ntotalvars) );/*lint !e571*/
3396  assert( ntotalvars == (int) (size_t) SCIPhashmapGetImage(implhash, var) );
3397  totalvars[ntotalvars++] = var;
3398  }
3399  }
3400 
3401  /* create implication graph */
3402  SCIP_CALL( SCIPdigraphCreate(&implgraph, ntotalvars) );
3403 
3404  /* try to tighten the lower and upper bounds of the variables */
3405  updateconfl = FALSE;
3406  for (j = 0; (j < conshdlrdata->maxtightenbds || conshdlrdata->maxtightenbds == -1 ) && ! cutoff; ++j)
3407  {
3408  SCIP_Bool implupdate;
3409  int nchgbdssave;
3410 
3411  nchgbdssave = *nchgbds;
3412 
3413  assert( ntotalvars > 0 );
3414  SCIP_CALL( tightenVarsBoundsSOS1(scip, conshdlrdata, conflictgraph, implgraph, implhash, adjacencymatrix, totalvars, ntotalvars, nsos1vars, nchgbds, &implupdate, &cutoff) );
3415  if ( *nchgbds > nchgbdssave )
3416  {
3417  *result = SCIP_SUCCESS;
3418  if ( implupdate )
3419  updateconfl = TRUE;
3420  }
3421  else if ( implupdate )
3422  updateconfl = TRUE;
3423  else
3424  break;
3425  }
3426 
3427  /* perform implication graph analysis */
3428  if ( updateconfl && conshdlrdata->perfimplanalysis && ! cutoff )
3429  {
3430  SCIP_Real* implubs;
3431  SCIP_Real* impllbs;
3432  SCIP_Bool* implnodes;
3433  SCIP_Bool infeasible;
3434  SCIP_Bool fixed;
3435  int naddconsssave;
3436  int probingdepth;
3437 
3438  /* allocate buffer arrays */
3439  SCIP_CALL( SCIPallocBufferArray(scip, &implnodes, nsos1vars) );
3440  SCIP_CALL( SCIPallocBufferArray(scip, &impllbs, ntotalvars) );
3441  SCIP_CALL( SCIPallocBufferArray(scip, &implubs, ntotalvars) );
3442 
3443  naddconsssave = *naddconss;
3444  for (i = 0; i < nsos1vars; ++i)
3445  {
3446  /* initialize data for implication graph analysis */
3447  infeasible = FALSE;
3448  probingdepth = 0;
3449  for (j = 0; j < nsos1vars; ++j)
3450  implnodes[j] = FALSE;
3451  for (j = 0; j < ntotalvars; ++j)
3452  {
3453  impllbs[j] = SCIPvarGetLbLocal(totalvars[j]);
3454  implubs[j] = SCIPvarGetUbLocal(totalvars[j]);
3455  }
3456 
3457  /* try to update the conflict graph based on the information of the implication graph */
3458  SCIP_CALL( performImplicationGraphAnalysis(scip, conshdlrdata, conflictgraph, totalvars, implgraph, implhash, adjacencymatrix, i, i, impllbs, implubs, implnodes, naddconss, &probingdepth, &infeasible) );
3459 
3460  /* if the subproblem turned out to be infeasible then fix variable to zero */
3461  if ( infeasible )
3462  {
3463  SCIP_CALL( SCIPfixVar(scip, totalvars[i], 0.0, &infeasible, &fixed) );
3464 
3465  if ( fixed )
3466  {
3467  SCIPdebugMsg(scip, "fixed variable %s with lower bound %f and upper bound %f to zero\n",
3468  SCIPvarGetName(totalvars[i]), SCIPvarGetLbLocal(totalvars[i]), SCIPvarGetUbLocal(totalvars[i]));
3469  ++(*nfixedvars);
3470  }
3471 
3472  if ( infeasible )
3473  cutoff = TRUE;
3474  }
3475  }
3476 
3477  if ( *naddconss > naddconsssave )
3478  *result = SCIP_SUCCESS;
3479 
3480  /* free buffer arrays */
3481  SCIPfreeBufferArrayNull(scip, &implubs);
3482  SCIPfreeBufferArrayNull(scip, &impllbs);
3483  SCIPfreeBufferArrayNull(scip, &implnodes);
3484  }
3485 
3486  /* if an infeasibility has been detected */
3487  if ( cutoff )
3488  {
3489  SCIPdebugMsg(scip, "cutoff \n");
3490  *result = SCIP_CUTOFF;
3491  }
3492 
3493  /* free memory */;
3494  for (j = ntotalvars-1; j >= 0; --j)
3495  {
3496  SCIP_SUCCDATA** succdatas;
3497  int nsucc;
3498  int s;
3499 
3500  succdatas = (SCIP_SUCCDATA**) SCIPdigraphGetSuccessorsData(implgraph, j);
3501  nsucc = SCIPdigraphGetNSuccessors(implgraph, j);
3502 
3503  for (s = nsucc-1; s >= 0; --s)
3504  SCIPfreeBlockMemory(scip, &succdatas[s]);/*lint !e866*/
3505  }
3506  SCIPdigraphFree(&implgraph);
3507  SCIPfreeBufferArrayNull(scip, &totalvars);
3508  SCIPhashmapFree(&implhash);
3509 
3510  return SCIP_OKAY;
3511 }
3512 
3513 
3514 /* ----------------------------- propagation -------------------------------------*/
3515 
3516 /** propagate variables of SOS1 constraint */
3517 static
3519  SCIP* scip, /**< SCIP pointer */
3520  SCIP_CONS* cons, /**< constraint */
3521  SCIP_CONSDATA* consdata, /**< constraint data */
3522  SCIP_Bool* cutoff, /**< whether a cutoff happened */
3523  int* ngen /**< number of domain changes */
3524  )
3525 {
3526  assert( scip != NULL );
3527  assert( cons != NULL );
3528  assert( consdata != NULL );
3529  assert( cutoff != NULL );
3530  assert( ngen != NULL );
3531 
3532  *cutoff = FALSE;
3533 
3534  /* if more than one variable is fixed to be nonzero */
3535  if ( consdata->nfixednonzeros > 1 )
3536  {
3537  SCIPdebugMsg(scip, "the node is infeasible, more than 1 variable is fixed to be nonzero.\n");
3538  SCIP_CALL( SCIPresetConsAge(scip, cons) );
3539  *cutoff = TRUE;
3540  return SCIP_OKAY;
3541  }
3542 
3543  /* if exactly one variable is fixed to be nonzero */
3544  if ( consdata->nfixednonzeros == 1 )
3545  {
3546  SCIP_VAR** vars;
3547  SCIP_Bool infeasible;
3548  SCIP_Bool tightened;
3549  SCIP_Bool success;
3550  SCIP_Bool allVarFixed;
3551  int firstFixedNonzero;
3552  int nvars;
3553  int j;
3554 
3555  firstFixedNonzero = -1;
3556  nvars = consdata->nvars;
3557  vars = consdata->vars;
3558  assert( vars != NULL );
3559 
3560  /* search nonzero variable - is needed for propinfo */
3561  for (j = 0; j < nvars; ++j)
3562  {
3563  if ( SCIPisFeasPositive(scip, SCIPvarGetLbLocal(vars[j])) || SCIPisFeasNegative(scip, SCIPvarGetUbLocal(vars[j])) )
3564  {
3565  firstFixedNonzero = j;
3566  break;
3567  }
3568  }
3569  assert( firstFixedNonzero >= 0 );
3570 
3571  SCIPdebugMsg(scip, "variable <%s> is fixed nonzero, fixing other variables to 0.\n", SCIPvarGetName(vars[firstFixedNonzero]));
3572 
3573  /* fix variables before firstFixedNonzero to 0 */
3574  allVarFixed = TRUE;
3575  for (j = 0; j < firstFixedNonzero; ++j)
3576  {
3577  /* fix variable */
3578  SCIP_CALL( inferVariableZero(scip, vars[j], cons, firstFixedNonzero, &infeasible, &tightened, &success) );
3579  assert( ! infeasible );
3580  allVarFixed = allVarFixed && success;
3581  if ( tightened )
3582  ++(*ngen);
3583  }
3584 
3585  /* fix variables after firstFixedNonzero to 0 */
3586  for (j = firstFixedNonzero+1; j < nvars; ++j)
3587  {
3588  /* fix variable */
3589  SCIP_CALL( inferVariableZero(scip, vars[j], cons, firstFixedNonzero, &infeasible, &tightened, &success) );
3590  assert( ! infeasible ); /* there should be no variables after firstFixedNonzero that are fixed to be nonzero */
3591  allVarFixed = allVarFixed && success;
3592  if ( tightened )
3593  ++(*ngen);
3594  }
3595 
3596  /* reset constraint age counter */
3597  if ( *ngen > 0 )
3598  {
3599  SCIP_CALL( SCIPresetConsAge(scip, cons) );
3600  }
3601 
3602  /* delete constraint locally */
3603  if ( allVarFixed )
3604  {
3605  assert( !SCIPconsIsModifiable(cons) );
3606  SCIP_CALL( SCIPdelConsLocal(scip, cons) );
3607  }
3608  }
3609 
3610  return SCIP_OKAY;
3611 }
3612 
3613 
3614 /** propagate a variable that is known to be nonzero */
3615 static
3617  SCIP* scip, /**< SCIP pointer */
3618  SCIP_DIGRAPH* conflictgraph, /**< conflict graph */
3619  SCIP_DIGRAPH* implgraph, /**< implication graph */
3620  SCIP_CONS* cons, /**< some arbitrary SOS1 constraint */
3621  int node, /**< conflict graph node of variable that is known to be nonzero */
3622  SCIP_Bool implprop, /**< whether implication graph propagation shall be applied */
3623  SCIP_Bool* cutoff, /**< whether a cutoff happened */
3624  int* ngen /**< number of domain changes */
3625  )
3626 {
3627  int inferinfo;
3628  int* succ;
3629  int nsucc;
3630  int s;
3631 
3632  assert( scip != NULL );
3633  assert( conflictgraph != NULL );
3634  assert( cutoff != NULL );
3635  assert( ngen != NULL );
3636  assert( node >= 0 );
3637 
3638  *cutoff = FALSE;
3639  inferinfo = -node - 1;
3640 
3641  /* by assumption zero is outside the domain of variable */
3642  assert( SCIPisFeasPositive(scip, SCIPvarGetLbLocal(SCIPnodeGetVarSOS1(conflictgraph, node))) || SCIPisFeasNegative(scip, SCIPvarGetUbLocal(SCIPnodeGetVarSOS1(conflictgraph, node))) );
3643 
3644  /* apply conflict graph propagation (fix all neighbors in the conflict graph to zero) */
3645  succ = SCIPdigraphGetSuccessors(conflictgraph, node);
3646  nsucc = SCIPdigraphGetNSuccessors(conflictgraph, node);
3647  for (s = 0; s < nsucc; ++s)
3648  {
3649  SCIP_VAR* succvar;
3650  SCIP_Real lb;
3651  SCIP_Real ub;
3652 
3653  succvar = SCIPnodeGetVarSOS1(conflictgraph, succ[s]);
3654  lb = SCIPvarGetLbLocal(succvar);
3655  ub = SCIPvarGetUbLocal(succvar);
3656 
3657  if ( ! SCIPisFeasZero(scip, lb) || ! SCIPisFeasZero(scip, ub) )
3658  {
3659  SCIP_Bool infeasible;
3660  SCIP_Bool tightened;
3661  SCIP_Bool success;
3662 
3663  /* fix variable if it is not multi-aggregated */
3664  SCIP_CALL( inferVariableZero(scip, succvar, cons, inferinfo, &infeasible, &tightened, &success) );
3665 
3666  if ( infeasible )
3667  {
3668  /* variable cannot be nonzero */
3669  *cutoff = TRUE;
3670  return SCIP_OKAY;
3671  }
3672  if ( tightened )
3673  ++(*ngen);
3674  assert( success || SCIPvarGetStatus(succvar) == SCIP_VARSTATUS_MULTAGGR );
3675  }
3676  }
3677 
3678 
3679  /* apply implication graph propagation */
3680  if ( implprop && implgraph != NULL )
3681  {
3682  SCIP_SUCCDATA** succdatas;
3683 
3684 #ifndef NDEBUG
3685  SCIP_NODEDATA* nodedbgdata;
3686  nodedbgdata = (SCIP_NODEDATA*) SCIPdigraphGetNodeData(implgraph, node);
3687  assert( SCIPvarCompare(nodedbgdata->var, SCIPnodeGetVarSOS1(conflictgraph, node)) == 0 );
3688 #endif
3689 
3690  /* get successor datas */
3691  succdatas = (SCIP_SUCCDATA**) SCIPdigraphGetSuccessorsData(implgraph, node);
3692 
3693  if ( succdatas != NULL )
3694  {
3695  succ = SCIPdigraphGetSuccessors(implgraph, node);
3696  nsucc = SCIPdigraphGetNSuccessors(implgraph, node);
3697  for (s = 0; s < nsucc; ++s)
3698  {
3699  SCIP_SUCCDATA* succdata;
3700  SCIP_NODEDATA* nodedata;
3701  SCIP_VAR* var;
3702 
3703  nodedata = (SCIP_NODEDATA*) SCIPdigraphGetNodeData(implgraph, succ[s]);
3704  assert( nodedata != NULL );
3705  succdata = succdatas[s];
3706  assert( succdata != NULL );
3707  var = nodedata->var;
3708  assert( var != NULL );
3709 
3710  /* tighten variable if it is not multi-aggregated */
3712  {
3713  /* check for lower bound implication */
3714  if ( SCIPisFeasLT(scip, SCIPvarGetLbLocal(var), succdata->lbimpl) )
3715  {
3716  SCIP_Bool infeasible;
3717  SCIP_Bool tightened;
3718 
3719  SCIP_CALL( SCIPinferVarLbCons(scip, var, succdata->lbimpl, cons, inferinfo, FALSE, &infeasible, &tightened) );
3720  if ( infeasible )
3721  {
3722  *cutoff = TRUE;
3723  return SCIP_OKAY;
3724  }
3725  if ( tightened )
3726  ++(*ngen);
3727  }
3728 
3729  /* check for upper bound implication */
3730  if ( SCIPisFeasGT(scip, SCIPvarGetUbLocal(var), succdata->ubimpl) )
3731  {
3732  SCIP_Bool infeasible;
3733  SCIP_Bool tightened;
3734 
3735  SCIP_CALL( SCIPinferVarUbCons(scip, var, succdata->ubimpl, cons, inferinfo, FALSE, &infeasible, &tightened) );
3736  if ( infeasible )
3737  {
3738  *cutoff = TRUE;
3739  return SCIP_OKAY;
3740  }
3741  if ( tightened )
3742  ++(*ngen);
3743  }
3744  }
3745  }
3746  }
3747  }
3748 
3749  return SCIP_OKAY;
3750 }
3751 
3752 
3753 /** initialize implication graph
3754  *
3755  * @p j is successor of @p i if and only if \f$ x_i\not = 0 \Rightarrow x_j\not = 0\f$
3756  *
3757  * @note By construction the implication graph is globally valid.
3758  */
3759 static
3761  SCIP* scip, /**< SCIP pointer */
3762  SCIP_CONSHDLRDATA* conshdlrdata, /**< constraint handler data */
3763  SCIP_DIGRAPH* conflictgraph, /**< conflict graph */
3764  int nsos1vars, /**< number of SOS1 variables */
3765  int maxrounds, /**< maximal number of propagation rounds for generating implications */
3766  int* nchgbds, /**< pointer to store number of bound changes */
3767  SCIP_Bool* cutoff, /**< pointer to store whether a cutoff occurred */
3768  SCIP_Bool* success /**< whether initialization was successful */
3769  )
3770 {
3771  SCIP_HASHMAP* implhash = NULL;
3772  SCIP_Bool** adjacencymatrix = NULL;
3773  SCIP_Bool* implnodes = NULL;
3774  SCIP_VAR** implvars = NULL;
3775  SCIP_VAR** probvars;
3776  int nimplnodes;
3777  int nprobvars;
3778  int i;
3779  int j;
3780 
3781  assert( scip != NULL );
3782  assert( conshdlrdata != NULL );
3783  assert( conflictgraph != NULL );
3784  assert( conshdlrdata->implgraph == NULL );
3785  assert( conshdlrdata->nimplnodes == 0 );
3786  assert( cutoff != NULL );
3787  assert( nchgbds != NULL );
3788 
3789  *nchgbds = 0;
3790  *cutoff = FALSE;
3791 
3792  /* we do not create the adjacency matrix of the conflict graph if the number of SOS1 variables is larger than a predefined value */
3793  if ( conshdlrdata->maxsosadjacency != -1 && nsos1vars > conshdlrdata->maxsosadjacency )
3794  {
3795  *success = FALSE;
3796  SCIPdebugMsg(scip, "Implication graph was not created since number of SOS1 variables (%d) is larger than %d.\n", nsos1vars, conshdlrdata->maxsosadjacency);
3797 
3798  return SCIP_OKAY;
3799  }
3800  *success = TRUE;
3801 
3802  /* only add globally valid implications to implication graph */
3803  assert ( SCIPgetDepth(scip) == 0 );
3804 
3805  probvars = SCIPgetVars(scip);
3806  nprobvars = SCIPgetNVars(scip);
3807  nimplnodes = 0;
3808 
3809  /* create implication graph */
3810  SCIP_CALL( SCIPdigraphCreate(&conshdlrdata->implgraph, nsos1vars + nprobvars) );
3811 
3812  /* create hashmap */
3813  SCIP_CALL( SCIPhashmapCreate(&implhash, SCIPblkmem(scip), nsos1vars + nprobvars) );
3814 
3815  /* determine implvars (union of SOS1 and problem variables)
3816  * Note: For separation of implied bound cuts it is important that SOS1 variables are enumerated first
3817  */
3818  SCIP_CALL( SCIPallocBufferArray(scip, &implvars, nsos1vars + nprobvars) );
3819  for (i = 0; i < nsos1vars; ++i)
3820  {
3821  SCIP_VAR* var;
3822  var = SCIPnodeGetVarSOS1(conflictgraph, i);
3823 
3824  /* insert node number to hash map */
3825  assert( ! SCIPhashmapExists(implhash, var) );
3826  SCIP_CALL( SCIPhashmapInsert(implhash, var, (void*) (size_t) nimplnodes) );/*lint !e571*/
3827  assert( nimplnodes == (int) (size_t) SCIPhashmapGetImage(implhash, var) );
3828  implvars[nimplnodes++] = var;
3829  }
3830 
3831  for (i = 0; i < nprobvars; ++i)
3832  {
3833  SCIP_VAR* var;
3834  var = probvars[i];
3835 
3836  /* insert node number to hash map if not existent */
3837  if ( ! SCIPhashmapExists(implhash, var) )
3838  {
3839  SCIP_CALL( SCIPhashmapInsert(implhash, var, (void*) (size_t) nimplnodes) );/*lint !e571*/
3840  assert( nimplnodes == (int) (size_t) SCIPhashmapGetImage(implhash, var) );
3841  implvars[nimplnodes++] = var;
3842  }
3843  }
3844  conshdlrdata->nimplnodes = nimplnodes;
3845 
3846  /* add variables to nodes of implication graph */
3847  for (i = 0; i < nimplnodes; ++i)
3848  {
3849  SCIP_NODEDATA* nodedata = NULL;
3850 
3851  /* create node data */
3852  SCIP_CALL( SCIPallocBlockMemory(scip, &nodedata) );
3853  nodedata->var = implvars[i];
3854 
3855  /* set node data */
3856  SCIPdigraphSetNodeData(conshdlrdata->implgraph, (void*) nodedata, i);
3857  }
3858 
3859  /* allocate buffer arrays */
3860  SCIP_CALL( SCIPallocBufferArray(scip, &implnodes, nsos1vars) );
3861  SCIP_CALL( SCIPallocBufferArray(scip, &adjacencymatrix, nsos1vars) );
3862 
3863  for (i = 0; i < nsos1vars; ++i)
3864  SCIP_CALL( SCIPallocBufferArray(scip, &adjacencymatrix[i], i+1) ); /*lint !e866*/
3865 
3866  /* create adjacency matrix */
3867  for (i = 0; i < nsos1vars; ++i)
3868  {
3869  for (j = 0; j < i+1; ++j)
3870  adjacencymatrix[i][j] = 0;
3871  }
3872 
3873  for (i = 0; i < nsos1vars; ++i)
3874  {
3875  int* succ;
3876  int nsucc;
3877  succ = SCIPdigraphGetSuccessors(conflictgraph, i);
3878  nsucc = SCIPdigraphGetNSuccessors(conflictgraph, i);
3879 
3880  for (j = 0; j < nsucc; ++j)
3881  {
3882  if ( i > succ[j] )
3883  adjacencymatrix[i][succ[j]] = 1;
3884  }
3885  }
3886 
3887  assert( SCIPgetDepth(scip) == 0 );
3888 
3889  /* compute SOS1 implications from linear constraints and tighten bounds of variables */
3890  for (j = 0; (j < maxrounds || maxrounds == -1 ); ++j)
3891  {
3892  SCIP_Bool implupdate;
3893  int nchgbdssave;
3894 
3895  nchgbdssave = *nchgbds;
3896 
3897  assert( nimplnodes > 0 );
3898  SCIP_CALL( tightenVarsBoundsSOS1(scip, conshdlrdata, conflictgraph, conshdlrdata->implgraph, implhash, adjacencymatrix, implvars, nimplnodes, nsos1vars, nchgbds, &implupdate, cutoff) );
3899  if ( *cutoff || ( ! implupdate && ! ( *nchgbds > nchgbdssave ) ) )
3900  break;
3901  }
3902 
3903  /* free memory */
3904  for (i = nsos1vars-1; i >= 0; --i)
3905  SCIPfreeBufferArrayNull(scip, &adjacencymatrix[i]);
3906  SCIPfreeBufferArrayNull(scip, &adjacencymatrix);
3907  SCIPfreeBufferArrayNull(scip, &implnodes);
3908  SCIPfreeBufferArrayNull(scip, &implvars);
3909  SCIPhashmapFree(&implhash);
3910 
3911 #ifdef SCIP_DEBUG
3912  /* evaluate results */
3913  if ( cutoff )
3914  {
3915  SCIPdebugMsg(scip, "cutoff \n");
3916  }
3917  else if ( *nchgbds > 0 )
3918  {
3919  SCIPdebugMsg(scip, "found %d bound changes\n", *nchgbds);
3920  }
3921 #endif
3922 
3923  assert( conshdlrdata->implgraph != NULL );
3924 
3925  return SCIP_OKAY;
3926 }
3927 
3928 
3929 /** deinitialize implication graph */
3930 static
3932  SCIP* scip, /**< SCIP pointer */
3933  SCIP_CONSHDLRDATA* conshdlrdata /**< constraint handler data */
3934  )
3935 {
3936  int j;
3938  assert( scip != NULL );
3939  assert( conshdlrdata != NULL );
3940 
3941  /* free whole memory of implication graph */
3942  if ( conshdlrdata->implgraph == NULL )
3943  {
3944  assert( conshdlrdata->nimplnodes == 0 );
3945  return SCIP_OKAY;
3946  }
3947 
3948  /* free arc data */
3949  for (j = conshdlrdata->nimplnodes-1; j >= 0; --j)
3950  {
3951  SCIP_SUCCDATA** succdatas;
3952  int nsucc;
3953  int s;
3954 
3955  succdatas = (SCIP_SUCCDATA**) SCIPdigraphGetSuccessorsData(conshdlrdata->implgraph, j);
3956  nsucc = SCIPdigraphGetNSuccessors(conshdlrdata->implgraph, j);
3957 
3958  for (s = nsucc-1; s >= 0; --s)
3959  {
3960  assert( succdatas[s] != NULL );
3961  SCIPfreeBlockMemory(scip, &succdatas[s]);/*lint !e866*/
3962  }
3963  }
3964 
3965  /* free node data */
3966  for (j = conshdlrdata->nimplnodes-1; j >= 0; --j)
3967  {
3968  SCIP_NODEDATA* nodedata;
3969  nodedata = (SCIP_NODEDATA*)SCIPdigraphGetNodeData(conshdlrdata->implgraph, j);
3970  assert( nodedata != NULL );
3971  SCIPfreeBlockMemory(scip, &nodedata);
3972  SCIPdigraphSetNodeData(conshdlrdata->implgraph, NULL, j);
3973  }
3974 
3975  /* free implication graph */
3976  SCIPdigraphFree(&conshdlrdata->implgraph);
3977  conshdlrdata->nimplnodes = 0;
3978 
3979  return SCIP_OKAY;
3980 }
3981 
3982 
3983 /* ----------------------------- branching -------------------------------------*/
3984 
3985 /** get the vertices whose neighbor set covers a subset of the neighbor set of a given other vertex.
3986  *
3987  * This function can be used to compute sets of variables to branch on.
3988  */
3989 static
3991  SCIP_DIGRAPH* conflictgraph, /**< conflict graph */
3992  SCIP_Bool* verticesarefixed, /**< array that indicates which variables are currently fixed to zero */
3993  int vertex, /**< vertex (-1 if not needed) */
3994  int* neightocover, /**< neighbors of given vertex to be covered (or NULL if all neighbors shall be covered) */
3995  int nneightocover, /**< number of entries of neightocover (or 0 if all neighbors shall be covered )*/
3996  int* coververtices, /**< array to store the vertices whose neighbor set covers the neighbor set of the given vertex */
3997  int* ncoververtices /**< pointer to store size of coververtices */
3998  )
3999 {
4000  int* succ1;
4001  int nsucc1;
4002  int s;
4003 
4004  assert( conflictgraph != NULL );
4005  assert( verticesarefixed != NULL );
4006  assert( coververtices != NULL );
4007  assert( ncoververtices != NULL );
4008 
4009  *ncoververtices = 0;
4010 
4011  /* if all the neighbors shall be covered */
4012  if ( neightocover == NULL )
4013  {
4014  assert( nneightocover == 0 );
4015  nsucc1 = SCIPdigraphGetNSuccessors(conflictgraph, vertex);
4016  succ1 = SCIPdigraphGetSuccessors(conflictgraph, vertex);
4017  }
4018  else
4019  {
4020  nsucc1 = nneightocover;
4021  succ1 = neightocover;
4022  }
4023 
4024  /* determine all the successors of the first unfixed successor */
4025  for (s = 0; s < nsucc1; ++s)
4026  {
4027  int succvertex1 = succ1[s];
4028 
4029  if ( ! verticesarefixed[succvertex1] )
4030  {
4031  int succvertex2;
4032  int* succ2;
4033  int nsucc2;
4034  int j;
4035 
4036  nsucc2 = SCIPdigraphGetNSuccessors(conflictgraph, succvertex1);
4037  succ2 = SCIPdigraphGetSuccessors(conflictgraph, succvertex1);
4038 
4039  /* for the first unfixed vertex */
4040  if ( *ncoververtices == 0 )
4041  {
4042  for (j = 0; j < nsucc2; ++j)
4043  {
4044  succvertex2 = succ2[j];
4045  if ( ! verticesarefixed[succvertex2] )
4046  coververtices[(*ncoververtices)++] = succvertex2;
4047  }
4048  }
4049  else
4050  {
4051  int vv = 0;
4052  int k = 0;
4053  int v;
4054 
4055  /* determine all the successors that are in the set "coververtices" */
4056  for (v = 0; v < *ncoververtices; ++v)
4057  {
4058  assert( vv <= v );
4059  for (j = k; j < nsucc2; ++j)
4060  {
4061  succvertex2 = succ2[j];
4062  if ( succvertex2 > coververtices[v] )
4063  {
4064  /* coververtices[v] does not appear in succ2 list, go to next vertex in coververtices */
4065  k = j;
4066  break;
4067  }
4068  else if ( succvertex2 == coververtices[v] )
4069  {
4070  /* vertices are equal, copy to free position vv */
4071  coververtices[vv++] = succvertex2;
4072  k = j + 1;
4073  break;
4074  }
4075  }
4076  }
4077  /* store new size of coververtices */
4078  *ncoververtices = vv;
4079  }
4080  }
4081  }
4082 
4083 #ifdef SCIP_DEBUG
4084  /* check sorting */
4085  for (s = 0; s < *ncoververtices; ++s)
4086  {
4087  assert( *ncoververtices <= 1 || coververtices[*ncoververtices - 1] > coververtices[*ncoververtices - 2] );
4088  }
4089 #endif
4090 
4091  return SCIP_OKAY;
4092 }
4093 
4094 
4095 /** get vertices of variables that will be fixed to zero for each node */
4096 static
4098  SCIP* scip, /**< SCIP pointer */
4099  SCIP_DIGRAPH* conflictgraph, /**< conflict graph */
4100  SCIP_SOL* sol, /**< solution to be enforced (NULL for LP solution) */
4101  SCIP_Bool* verticesarefixed, /**< vector that indicates which variables are currently fixed to zero */
4102  SCIP_Bool bipbranch, /**< TRUE if bipartite branching method should be used */
4103  int branchvertex, /**< branching vertex */
4104  int* fixingsnode1, /**< vertices of variables that will be fixed to zero for the first node */
4105  int* nfixingsnode1, /**< pointer to store number of fixed variables for the first node */
4106  int* fixingsnode2, /**< vertices of variables that will be fixed to zero for the second node */
4107  int* nfixingsnode2 /**< pointer to store number of fixed variables for the second node */
4108  )
4109 {
4110  SCIP_Bool takeallsucc; /* whether to set fixingsnode1 = neighbors of 'branchvertex' in the conflict graph */
4111  int* succ;
4112  int nsucc;
4113  int j;
4114 
4115  assert( scip != NULL );
4116  assert( conflictgraph != NULL );
4117  assert( verticesarefixed != NULL );
4118  assert( ! verticesarefixed[branchvertex] );
4119  assert( fixingsnode1 != NULL );
4120  assert( fixingsnode2 != NULL );
4121  assert( nfixingsnode1 != NULL );
4122  assert( nfixingsnode2 != NULL );
4123 
4124  *nfixingsnode1 = 0;
4125  *nfixingsnode2 = 0;
4126  takeallsucc = TRUE;
4127 
4128  /* get successors and number of successors of branching vertex */
4129  nsucc = SCIPdigraphGetNSuccessors(conflictgraph, branchvertex);
4130  succ = SCIPdigraphGetSuccessors(conflictgraph, branchvertex);
4131 
4132  /* if bipartite branching method is turned on */
4133  if ( bipbranch )
4134  {
4135  SCIP_Real solval;
4136  int cnt = 0;
4137 
4138  /* get all the neighbors of the variable with index 'branchvertex' whose solution value is nonzero */
4139  for (j = 0; j < nsucc; ++j)
4140  {
4141  if ( ! SCIPisFeasZero(scip, SCIPgetSolVal(scip, sol, SCIPnodeGetVarSOS1(conflictgraph, succ[j]))) )
4142  {
4143  assert( ! verticesarefixed[succ[j]] );
4144  fixingsnode1[(*nfixingsnode1)++] = succ[j];
4145  }
4146  }
4147 
4148  /* if one of the sets fixingsnode1 or fixingsnode2 contains only one variable with a nonzero LP value we perform standard neighborhood branching */
4149  if ( *nfixingsnode1 > 0 )
4150  {
4151  /* get the vertices whose neighbor set cover the selected subset of the neighbors of the given branching vertex */
4152  SCIP_CALL( getCoverVertices(conflictgraph, verticesarefixed, branchvertex, fixingsnode1, *nfixingsnode1, fixingsnode2, nfixingsnode2) );
4153 
4154  /* determine the intersection of the neighbors of branchvertex with the intersection of all the neighbors of fixingsnode2 */
4155  SCIP_CALL( getCoverVertices(conflictgraph, verticesarefixed, branchvertex, fixingsnode2, *nfixingsnode2, fixingsnode1, nfixingsnode1) );
4156 
4157  for (j = 0; j < *nfixingsnode2; ++j)
4158  {
4159  solval = SCIPgetSolVal(scip, sol, SCIPnodeGetVarSOS1(conflictgraph, fixingsnode2[j]));
4160  if( ! SCIPisFeasZero(scip, solval) )
4161  ++cnt;
4162  }
4163 
4164  /* we decide whether to use all successors if one partition of complete bipartite subgraph has only one node */
4165  if ( cnt >= 2 )
4166  {
4167  cnt = 0;
4168  for (j = 0; j < *nfixingsnode1; ++j)
4169  {
4170  solval = SCIPgetSolVal(scip, sol, SCIPnodeGetVarSOS1(conflictgraph, fixingsnode1[j]));
4171  if( ! SCIPisFeasZero(scip, solval) )
4172  ++cnt;
4173  }
4174 
4175  if ( cnt >= 2 )
4176  takeallsucc = FALSE;
4177  }
4178  }
4179  }
4180 
4181  if ( takeallsucc )
4182  {
4183  /* get all the unfixed neighbors of the branching vertex */
4184  *nfixingsnode1 = 0;
4185  for (j = 0; j < nsucc; ++j)
4186  {
4187  if ( ! verticesarefixed[succ[j]] )
4188  fixingsnode1[(*nfixingsnode1)++] = succ[j];
4189  }
4190 
4191  if ( bipbranch )
4192  {
4193  /* get the vertices whose neighbor set covers the neighbor set of a given branching vertex */
4194  SCIP_CALL( getCoverVertices(conflictgraph, verticesarefixed, branchvertex, fixingsnode1, *nfixingsnode1, fixingsnode2, nfixingsnode2) );
4195  }
4196  else
4197  {
4198  /* use neighborhood branching, i.e, for the second node only the branching vertex can be fixed */
4199  fixingsnode2[0] = branchvertex;
4200  *nfixingsnode2 = 1;
4201  }
4202  }
4203 
4204  return SCIP_OKAY;
4205 }
4206 
4207 
4208 /** gets branching priorities for SOS1 variables and applies 'most infeasible selection' rule to determine a vertex for the next branching decision */
4209 static
4211  SCIP* scip, /**< SCIP pointer */
4212  SCIP_CONSHDLRDATA* conshdlrdata, /**< constraint handler data */
4213  SCIP_DIGRAPH* conflictgraph, /**< conflict graph */
4214  SCIP_SOL* sol, /**< solution to be enforced (NULL for LP solution) */
4215  int nsos1vars, /**< number of SOS1 variables */
4216  SCIP_Bool* verticesarefixed, /**< vector that indicates which variables are currently fixed to zero */
4217  SCIP_Bool bipbranch, /**< TRUE if bipartite branching method should be used */
4218  int* fixingsnode1, /**< vertices of variables that will be fixed to zero for the first node (size = nsos1vars) */
4219  int* fixingsnode2, /**< vertices of variables that will be fixed to zero for the second node (size = nsos1vars) */
4220  SCIP_Real* branchpriors, /**< pointer to store branching priorities (size = nsos1vars) or NULL if not needed */
4221  int* vertexbestprior, /**< pointer to store vertex with the best branching priority or NULL if not needed */
4222  SCIP_Bool* relsolfeas /**< pointer to store if LP relaxation solution is feasible */
4223  )
4224 {
4225  SCIP_Real bestprior;
4226  int i;
4227 
4228  assert( scip != NULL );
4229  assert( conshdlrdata != NULL );
4230  assert( conflictgraph != NULL );
4231  assert( verticesarefixed != NULL );
4232  assert( fixingsnode1 != NULL );
4233  assert( fixingsnode2 != NULL );
4234  assert( relsolfeas != NULL );
4235 
4236  bestprior = -SCIPinfinity(scip);
4237 
4238  for (i = 0; i < nsos1vars; ++i)
4239  {
4240  SCIP_Real prior;
4241  SCIP_Real solval;
4242  SCIP_Real sum1;
4243  SCIP_Real sum2;
4244  int nfixingsnode1;
4245  int nfixingsnode2;
4246  int nsucc;
4247  int j;
4248 
4249  nsucc = SCIPdigraphGetNSuccessors(conflictgraph, i);
4250 
4251  if ( nsucc == 0 || SCIPisFeasZero(scip, SCIPgetSolVal(scip, sol, SCIPnodeGetVarSOS1(conflictgraph, i))) || verticesarefixed[i] )
4252  prior = -SCIPinfinity(scip);
4253  else
4254  {
4255  SCIP_Bool iszero1 = TRUE;
4256  SCIP_Bool iszero2 = TRUE;
4257 
4258  /* get vertices of variables that will be fixed to zero for each strong branching execution */
4259  assert( ! verticesarefixed[i] );
4260  SCIP_CALL( getBranchingVerticesSOS1(scip, conflictgraph, sol, verticesarefixed, bipbranch, i, fixingsnode1, &nfixingsnode1, fixingsnode2, &nfixingsnode2) );
4261 
4262  sum1 = 0.0;
4263  for (j = 0; j < nfixingsnode1; ++j)
4264  {
4265  solval = SCIPgetSolVal(scip, sol, SCIPnodeGetVarSOS1(conflictgraph, fixingsnode1[j]));
4266  if ( ! SCIPisFeasZero(scip, solval) )
4267  {
4268  sum1 += REALABS( solval );
4269  iszero1 = FALSE;
4270  }
4271  }
4272 
4273  sum2 = 0.0;
4274  for (j = 0; j < nfixingsnode2; ++j)
4275  {
4276  solval = SCIPgetSolVal(scip, sol, SCIPnodeGetVarSOS1(conflictgraph, fixingsnode2[j]));
4277  if ( ! SCIPisFeasZero(scip, solval) )
4278  {
4279  sum2 += REALABS( solval );
4280  iszero2 = FALSE;
4281  }
4282  }
4283 
4284  if ( iszero1 || iszero2 )
4285  prior = -SCIPinfinity(scip);
4286  else
4287  prior = sum1 * sum2;
4288  }
4289 
4290  if ( branchpriors != NULL )
4291  branchpriors[i] = prior;
4292  if ( bestprior < prior )
4293  {
4294  bestprior = prior;
4295 
4296  if ( vertexbestprior != NULL )
4297  *vertexbestprior = i;
4298  }
4299  }
4300 
4301  if ( SCIPisInfinity(scip, -bestprior) )
4302  *relsolfeas = TRUE;
4303  else
4304  *relsolfeas = FALSE;
4305 
4306  return SCIP_OKAY;
4307 }
4308 
4309 
4310 /** performs strong branching with given domain fixings */
4311 static
4313  SCIP* scip, /**< SCIP pointer */
4314  SCIP_DIGRAPH* conflictgraph, /**< conflict graph */
4315  int* fixingsexec, /**< vertices of variables to be fixed to zero for this strong branching execution */
4316  int nfixingsexec, /**< number of vertices of variables to be fixed to zero for this strong branching execution */
4317  int* fixingsop, /**< vertices of variables to be fixed to zero for the opposite strong branching execution */
4318  int nfixingsop, /**< number of vertices of variables to be fixed to zero for the opposite strong branching execution */
4319  int inititer, /**< maximal number of LP iterations to perform */
4320  SCIP_Bool fixnonzero, /**< shall opposite variable (if positive in sign) fixed to the feasibility tolerance
4321  * (only possible if nfixingsop = 1) */
4322  int* domainfixings, /**< vertices that can be used to reduce the domain (should have size equal to number of variables) */
4323  int* ndomainfixings, /**< pointer to store number of vertices that can be used to reduce the domain, could be filled by earlier calls */
4324  SCIP_Bool* infeasible, /**< pointer to store whether branch is infeasible */
4325  SCIP_Real* objval, /**< pointer to store objective value of LP with fixed variables (SCIP_INVALID if reddomain = TRUE or lperror = TRUE) */
4326  SCIP_Bool* lperror /**< pointer to store whether an unresolved LP error or a strange solution status occurred */
4327  )
4328 {
4329  SCIP_LPSOLSTAT solstat;
4330  int i;
4331 
4332  assert( scip != NULL );
4333  assert( conflictgraph != NULL );
4334  assert( fixingsexec != NULL );
4335  assert( nfixingsop > 0 );
4336  assert( fixingsop != NULL );
4337  assert( nfixingsop > 0 );
4338  assert( inititer >= -1 );
4339  assert( domainfixings != NULL );
4340  assert( ndomainfixings != NULL );
4341  assert( *ndomainfixings >= 0 );
4342  assert( infeasible != NULL );
4343  assert( objval != NULL );
4344  assert( lperror != NULL );
4345 
4346  *objval = SCIP_INVALID; /* for debugging */
4347  *lperror = FALSE;
4348  *infeasible = FALSE;
4349 
4350  /* start probing */
4351  SCIP_CALL( SCIPstartProbing(scip) );
4352 
4353  /* perform domain fixings */
4354  if ( fixnonzero && nfixingsop == 1 )
4355  {
4356  SCIP_VAR* var;
4357  SCIP_Real lb;
4358  SCIP_Real ub;
4359 
4360  var = SCIPnodeGetVarSOS1(conflictgraph, fixingsop[0]);
4361  lb = SCIPvarGetLbLocal(var);
4362  ub = SCIPvarGetUbLocal(var);
4363 
4365  {
4366  if ( SCIPisZero(scip, lb) )
4367  {
4368  /* fix variable to some very small, but positive number or to 1.0 if variable is integral */
4369  if (SCIPvarIsIntegral(var) )
4370  {
4371  SCIP_CALL( SCIPchgVarLbProbing(scip, var, 1.0) );
4372  }
4373  else
4374  {
4375  SCIP_CALL( SCIPchgVarLbProbing(scip, var, 1.5 * SCIPfeastol(scip)) );
4376  }
4377  }
4378  else if ( SCIPisZero(scip, ub) )
4379  {
4380  /* fix variable to some negative number with small absolute value or to -1.0 if variable is integral */
4381  if (SCIPvarIsIntegral(var) )
4382  {
4383  SCIP_CALL( SCIPchgVarUbProbing(scip, var, -1.0) );
4384  }
4385  else
4386  {
4387  SCIP_CALL( SCIPchgVarUbProbing(scip, var, -1.5 * SCIPfeastol(scip)) );
4388  }
4389  }
4390  }
4391  }
4392 
4393  /* injects variable fixings into current probing node */
4394  for (i = 0; i < nfixingsexec && ! *infeasible; ++i)
4395  {
4396  SCIP_VAR* var;
4397 
4398  var = SCIPnodeGetVarSOS1(conflictgraph, fixingsexec[i]);
4399  if ( SCIPisFeasGT(scip, SCIPvarGetLbLocal(var), 0.0) || SCIPisFeasLT(scip, SCIPvarGetUbLocal(var), 0.0) )
4400  *infeasible = TRUE;
4401  else
4402  {
4403  SCIP_CALL( SCIPfixVarProbing(scip, var, 0.0) );
4404  }
4405  }
4406 
4407  /* apply domain propagation */
4408  if ( ! *infeasible )
4409  {
4410  SCIP_CALL( SCIPpropagateProbing(scip, 0, infeasible, NULL) );
4411  }
4412 
4413  if ( *infeasible )
4414  solstat = SCIP_LPSOLSTAT_INFEASIBLE;
4415  else
4416  {
4417  /* solve the probing LP */
4418  SCIP_CALL( SCIPsolveProbingLP(scip, inititer, lperror, NULL) );
4419  if ( *lperror )
4420  {
4421  SCIP_CALL( SCIPendProbing(scip) );
4422  return SCIP_OKAY;
4423  }
4424 
4425  /* get solution status */
4426  solstat = SCIPgetLPSolstat(scip);
4427  }
4428 
4429  /* if objective limit was reached, then the domain can be reduced */
4430  if ( solstat == SCIP_LPSOLSTAT_OBJLIMIT || solstat == SCIP_LPSOLSTAT_INFEASIBLE )
4431  {
4432  *infeasible = TRUE;
4433 
4434  for (i = 0; i < nfixingsop; ++i)
4435  domainfixings[(*ndomainfixings)++] = fixingsop[i];
4436  }
4437  else if ( solstat == SCIP_LPSOLSTAT_OPTIMAL || solstat == SCIP_LPSOLSTAT_TIMELIMIT || solstat == SCIP_LPSOLSTAT_ITERLIMIT )
4438  {
4439  /* get objective value of probing LP */
4440  *objval = SCIPgetLPObjval(scip);
4441  }
4442  else
4443  *lperror = TRUE;
4444 
4445  /* end probing */
4446  SCIP_CALL( SCIPendProbing(scip) );
4447 
4448  return SCIP_OKAY;
4449 }
4450 
4451 
4452 /** apply strong branching to determine the vertex for the next branching decision */
4453 static
4455  SCIP* scip, /**< SCIP pointer */
4456  SCIP_CONSHDLRDATA* conshdlrdata, /**< SOS1 constraint handler data */
4457  SCIP_DIGRAPH* conflictgraph, /**< conflict graph */
4458  SCIP_SOL* sol, /**< solution to be enforced (NULL for LP solution) */
4459  int nsos1vars, /**< number of SOS1 variables */
4460  SCIP_Real lpobjval, /**< current LP relaxation solution */
4461  SCIP_Bool bipbranch, /**< TRUE if bipartite branching method should be used */
4462  int nstrongrounds, /**< number of strong branching rounds */
4463  SCIP_Bool* verticesarefixed, /**< vector that indicates which variables are currently fixed to zero */
4464  int* fixingsnode1, /**< pointer to store vertices of variables that will be fixed to zero for the first node (size = nsos1vars) */
4465  int* fixingsnode2, /**< pointer to store vertices of variables that will be fixed to zero for the second node (size = nsos1vars) */
4466  int* vertexbestprior, /**< pointer to store vertex with the best strong branching priority */
4467  SCIP_Real* bestobjval1, /**< pointer to store LP objective for left child node of branching decision with best priority */
4468  SCIP_Real* bestobjval2, /**< pointer to store LP objective for right child node of branching decision with best priority */
4469  SCIP_RESULT* result /**< pointer to store result of strong branching */
4470  )
4471 {
4472  SCIP_Real* branchpriors = NULL;
4473  int* indsos1vars = NULL;
4474  int* domainfixings = NULL;
4475  int ndomainfixings;
4476  int nfixingsnode1;
4477  int nfixingsnode2;
4478 
4479  SCIP_Bool relsolfeas;
4480  SCIP_Real bestscore;
4481  int lastscorechange;
4482  int maxfailures;
4483 
4484  SCIP_Longint nlpiterations;
4485  SCIP_Longint nlps;
4486  int inititer;
4487  int j;
4488  int i;
4489 
4490  assert( scip != NULL );
4491  assert( conshdlrdata != NULL );
4492  assert( conflictgraph != NULL );
4493  assert( verticesarefixed != NULL );
4494  assert( fixingsnode1 != NULL );
4495  assert( fixingsnode2 != NULL );
4496  assert( vertexbestprior != NULL );
4497  assert( result != NULL );
4498 
4499  /* allocate buffer arrays */
4500  SCIP_CALL( SCIPallocBufferArray(scip, &branchpriors, nsos1vars) );
4501 
4502  /* get branching priorities */
4503  SCIP_CALL( getBranchingPrioritiesSOS1(scip, conshdlrdata, conflictgraph, sol, nsos1vars, verticesarefixed,
4504  bipbranch, fixingsnode1, fixingsnode2, branchpriors, NULL, &relsolfeas) );
4505 
4506  /* if LP relaxation solution is feasible */
4507  if ( relsolfeas )
4508  {
4509  SCIPdebugMsg(scip, "all the SOS1 constraints are feasible.\n");
4510  *result = SCIP_FEASIBLE;
4511 
4512  /* free memory */
4513  SCIPfreeBufferArrayNull(scip, &branchpriors);
4514 
4515  return SCIP_OKAY;
4516  }
4517 
4518  /* allocate buffer arrays */
4519  SCIP_CALL( SCIPallocBufferArray(scip, &indsos1vars, nsos1vars) );
4520  SCIP_CALL( SCIPallocBufferArray(scip, &domainfixings, nsos1vars) );
4521 
4522  /* sort branching priorities (descending order) */
4523  for (j = 0; j < nsos1vars; ++j)
4524  indsos1vars[j] = j;
4525  SCIPsortDownRealInt(branchpriors, indsos1vars, nsos1vars);
4526 
4527  /* determine the number of LP iterations to perform in each strong branch */
4528  nlpiterations = SCIPgetNDualResolveLPIterations(scip);
4529  nlps = SCIPgetNDualResolveLPs(scip);
4530  if ( nlps == 0 )
4531  {
4532  nlpiterations = SCIPgetNNodeInitLPIterations(scip);
4533  nlps = SCIPgetNNodeInitLPs(scip);
4534  if ( nlps == 0 )
4535  {
4536  nlpiterations = 1000;
4537  nlps = 1;
4538  }
4539  }
4540  assert(nlps >= 1);
4541 
4542  /* compute number of LP iterations performed per strong branching iteration */
4543  if ( conshdlrdata->nstrongiter == -2 )
4544  {
4545  inititer = (int)(2*nlpiterations / nlps);
4546  inititer = (int)((SCIP_Real)inititer * (1.0 + 20.0/SCIPgetNNodes(scip)));
4547  inititer = MAX(inititer, 10);
4548  inititer = MIN(inititer, 500);
4549  }
4550  else
4551  inititer = conshdlrdata->nstrongiter;
4552 
4553  /* get current LP relaxation solution */
4554  lpobjval = SCIPgetLPObjval(scip);
4555 
4556  /* determine branching variable by strong branching or reduce domain */
4557  ndomainfixings = 0;
4558  lastscorechange = -1;
4559  *vertexbestprior = indsos1vars[0]; /* for the case that nstrongrounds = 0 */
4560  bestscore = -SCIPinfinity(scip);
4561  *bestobjval1 = -SCIPinfinity(scip);
4562  *bestobjval2 = -SCIPinfinity(scip);
4563  maxfailures = nstrongrounds;
4564 
4565  /* for each strong branching round */
4566  for (j = 0; j < nstrongrounds; ++j)
4567  {
4568  int testvertex;
4569 
4570  /* get branching vertex for the current strong branching iteration */
4571  testvertex = indsos1vars[j];
4572 
4573  /* if variable with index 'vertex' does not violate any complementarity in its neighborhood for the current LP relaxation solution */
4574  if ( SCIPisPositive(scip, branchpriors[j]) )
4575  {
4576  SCIP_Bool infeasible1;
4577  SCIP_Bool infeasible2;
4578  SCIP_Bool lperror;
4579  SCIP_Real objval1;
4580  SCIP_Real objval2;
4581  SCIP_Real score;
4582 
4583  /* get vertices of variables that will be fixed to zero for each strong branching execution */
4584  assert( ! verticesarefixed[testvertex] );
4585  SCIP_CALL( getBranchingVerticesSOS1(scip, conflictgraph, sol, verticesarefixed, bipbranch, testvertex, fixingsnode1, &nfixingsnode1, fixingsnode2, &nfixingsnode2) );
4586 
4587  /* get information for first strong branching execution */
4588  SCIP_CALL( performStrongbranchSOS1(scip, conflictgraph, fixingsnode1, nfixingsnode1, fixingsnode2, nfixingsnode2,
4589  inititer, conshdlrdata->fixnonzero, domainfixings, &ndomainfixings, &infeasible1, &objval1, &lperror) );
4590  if ( lperror )
4591  continue;
4592 
4593  /* get information for second strong branching execution */
4594  SCIP_CALL( performStrongbranchSOS1(scip, conflictgraph, fixingsnode2, nfixingsnode2, fixingsnode1, nfixingsnode1,
4595  inititer, FALSE, domainfixings, &ndomainfixings, &infeasible2, &objval2, &lperror) );
4596  if ( lperror )
4597  continue;
4598 
4599  /* if both subproblems are infeasible */
4600  if ( infeasible1 && infeasible2 )
4601  {
4602  SCIPdebugMsg(scip, "detected cutoff.\n");
4603 
4604  /* update result */
4605  *result = SCIP_CUTOFF;
4606 
4607  /* free memory */
4608  SCIPfreeBufferArrayNull(scip, &domainfixings);
4609  SCIPfreeBufferArrayNull(scip, &indsos1vars);
4610  SCIPfreeBufferArrayNull(scip, &branchpriors);
4611 
4612  return SCIP_OKAY;
4613  }
4614  else if ( ! infeasible1 && ! infeasible2 ) /* both subproblems are feasible */
4615  {
4616  /* if domain has not been reduced in this for-loop */
4617  if ( ndomainfixings == 0 )
4618  {
4619  score = MAX( REALABS( objval1 - lpobjval ), SCIPfeastol(scip) ) * MAX( REALABS( objval2 - lpobjval ), SCIPfeastol(scip) );/*lint !e666*/
4620 
4621  if ( SCIPisPositive(scip, score - bestscore) )
4622  {
4623  bestscore = score;
4624  *vertexbestprior = testvertex;
4625  *bestobjval1 = objval1;
4626  *bestobjval2 = objval2;
4627 
4628  lastscorechange = j;
4629  }
4630  else if ( j - lastscorechange > maxfailures )
4631  break;
4632  }
4633  }
4634  }
4635  }
4636 
4637  /* if variable fixings have been detected by probing, then reduce domain */
4638  if ( ndomainfixings > 0 )
4639  {
4640  SCIP_NODE* node = SCIPgetCurrentNode(scip);
4641  SCIP_Bool infeasible;
4642 
4643  for (i = 0; i < ndomainfixings; ++i)
4644  {
4645  SCIP_CALL( fixVariableZeroNode(scip, SCIPnodeGetVarSOS1(conflictgraph, domainfixings[i]), node, &infeasible) );
4646  assert( ! infeasible );
4647  }
4648 
4649  SCIPdebugMsg(scip, "found %d domain fixings.\n", ndomainfixings);
4650 
4651  /* update result */
4652  *result = SCIP_REDUCEDDOM;
4653  }
4654 
4655  /* free buffer arrays */
4656  SCIPfreeBufferArrayNull(scip, &domainfixings);
4657  SCIPfreeBufferArrayNull(scip, &indsos1vars);
4658  SCIPfreeBufferArrayNull(scip, &branchpriors);
4659 
4660  return SCIP_OKAY;
4661 }
4662 
4663 
4664 /** for two given vertices @p v1 and @p v2 search for a clique in the conflict graph that contains these vertices. From
4665  * this clique, we create a bound constraint.
4666  */
4667 static
4669  SCIP* scip, /**< SCIP pointer */
4670  SCIP_DIGRAPH* conflictgraph, /**< conflict graph */
4671  SCIP_SOL* sol, /**< solution to be enforced (NULL for LP solution) */
4672  int v1, /**< first vertex that shall be contained in bound constraint */
4673  int v2, /**< second vertex that shall be contained in bound constraint */
4674  SCIP_VAR* boundvar, /**< bound variable of @p v1 and @p v2 (or NULL if not existent) */
4675  SCIP_Bool extend, /**< should @p v1 and @p v2 be greedily extended to a clique of larger size */
4676  SCIP_CONS* cons, /**< bound constraint */
4677  SCIP_Real* feas /**< feasibility value of bound constraint */
4678  )
4679 {
4680  SCIP_NODEDATA* nodedata;
4681  SCIP_Bool addv2 = TRUE;
4682  SCIP_Real solval;
4683  SCIP_VAR* var;
4684  SCIP_Real coef = 0.0;
4685  int nsucc;
4686  int s;
4687 
4688  int* extensions = NULL;
4689  int nextensions = 0;
4690  int nextensionsnew;
4691  int* succ;
4692 
4693  assert( scip != NULL );
4694  assert( conflictgraph != NULL );
4695  assert( cons != NULL );
4696  assert( feas != NULL );
4697 
4698  *feas = 0.0;
4699 
4700  /* add index 'v1' to the clique */
4701  nodedata = (SCIP_NODEDATA*)SCIPdigraphGetNodeData(conflictgraph, v1);
4702  var = nodedata->var;
4703  assert( boundvar == NULL || SCIPvarCompare(boundvar, nodedata->ubboundvar) == 0 );
4704  solval = SCIPgetSolVal(scip, sol, var);
4705 
4706  /* if 'v1' and 'v2' have the same bound variable then the bound cut can be strengthened */
4707  if ( boundvar == NULL )
4708  {
4709  if ( SCIPisFeasPositive(scip, solval) )
4710  {
4711  SCIP_Real ub;
4712  ub = SCIPvarGetUbLocal(var);
4713  assert( SCIPisFeasPositive(scip, ub));
4714 
4715  if ( ! SCIPisInfinity(scip, ub) )
4716  coef = 1.0/ub;
4717  }
4718  else if ( SCIPisFeasNegative(scip, solval) )
4719  {
4720  SCIP_Real lb;
4721  lb = SCIPvarGetLbLocal(var);
4722  assert( SCIPisFeasNegative(scip, lb) );
4723  if ( ! SCIPisInfinity(scip, -lb) )
4724  coef = 1.0/lb;
4725  }
4726  }
4727  else if ( boundvar == nodedata->ubboundvar )
4728  {
4729  if ( SCIPisFeasPositive(scip, solval) )
4730  {
4731  SCIP_Real ub;
4732 
4733  ub = nodedata->ubboundcoef;
4734  assert( SCIPisFeasPositive(scip, ub) );
4735  if ( ! SCIPisInfinity(scip, ub) )
4736  coef = 1.0/ub;
4737  }
4738  else if ( SCIPisFeasNegative(scip, solval) )
4739  {
4740  SCIP_Real lb;
4741 
4742  lb = nodedata->lbboundcoef;
4743  assert( SCIPisFeasPositive(scip, lb) );
4744  if ( ! SCIPisInfinity(scip, lb) )
4745  coef = 1.0/lb;
4746  }
4747  }
4748 
4749  if ( ! SCIPisZero(scip, coef) )
4750  {
4751  *feas += coef * solval;
4752  SCIP_CALL( SCIPaddCoefLinear(scip, cons, var, coef) );
4753  }
4754 
4755  /* if clique shall be greedily extended to a clique of larger size */
4756  if ( extend )
4757  {
4758  /* get successors */
4759  nsucc = SCIPdigraphGetNSuccessors(conflictgraph, v1);
4760  succ = SCIPdigraphGetSuccessors(conflictgraph, v1);
4761  assert( nsucc > 0 );
4762 
4763  /* allocate buffer array */
4764  SCIP_CALL( SCIPallocBufferArray(scip, &extensions, nsucc) );
4765 
4766  /* get possible extensions for the clique cover */
4767  for (s = 0; s < nsucc; ++s)
4768  extensions[s] = succ[s];
4769  nextensions = nsucc;
4770  }
4771  else
4772  nextensions = 1;
4773 
4774  /* while there exist possible extensions for the clique cover */
4775  while ( nextensions > 0 )
4776  {
4777  SCIP_Real bestbigMval;
4778  SCIP_Real bigMval;
4779  int bestindex = -1;
4780  int ext;
4781 
4782  bestbigMval = -SCIPinfinity(scip);
4783 
4784  /* if v2 has not been added to clique already */
4785  if ( addv2 )
4786  {
4787  bestindex = v2;
4788  addv2 = FALSE;
4789  }
4790  else /* search for the extension with the largest absolute value of its LP relaxation solution value */
4791  {
4792  assert( extensions != NULL );
4793  for (s = 0; s < nextensions; ++s)
4794  {
4795  ext = extensions[s];
4796  bigMval = nodeGetSolvalBinaryBigMSOS1(scip, conflictgraph, sol, ext);
4797  if ( SCIPisFeasLT(scip, bestbigMval, bigMval) )
4798  {
4799  bestbigMval = bigMval;
4800  bestindex = ext;
4801  }
4802  }
4803  }
4804  assert( bestindex != -1 );
4805 
4806  /* add bestindex variable to the constraint */
4807  nodedata = (SCIP_NODEDATA*)SCIPdigraphGetNodeData(conflictgraph, bestindex);
4808  var = nodedata->var;
4809  solval = SCIPgetSolVal(scip, sol, var);
4810  coef = 0.0;
4811  if ( boundvar == NULL )
4812  {
4813  if ( SCIPisFeasPositive(scip, solval) )
4814  {
4815  SCIP_Real ub;
4816  ub = SCIPvarGetUbLocal(var);
4817  assert( SCIPisFeasPositive(scip, ub));
4818 
4819  if ( ! SCIPisInfinity(scip, ub) )
4820  coef = 1.0/ub;
4821  }
4822  else if ( SCIPisFeasNegative(scip, solval) )
4823  {
4824  SCIP_Real lb;
4825  lb = SCIPvarGetLbLocal(var);
4826  assert( SCIPisFeasNegative(scip, lb) );
4827  if ( ! SCIPisInfinity(scip, -lb) )
4828  coef = 1.0/lb;
4829  }
4830  }
4831  else if ( boundvar == nodedata->ubboundvar )
4832  {
4833  if ( SCIPisFeasPositive(scip, solval) )
4834  {
4835  SCIP_Real ub;
4836 
4837  ub = nodedata->ubboundcoef;
4838  assert( SCIPisFeasPositive(scip, ub) );
4839  if ( ! SCIPisInfinity(scip, ub) )
4840  coef = 1.0/ub;
4841  }
4842  else if ( SCIPisFeasNegative(scip, solval) )
4843  {
4844  SCIP_Real lb;
4845 
4846  lb = nodedata->lbboundcoef;
4847  assert( SCIPisFeasPositive(scip, lb) );
4848  if ( ! SCIPisInfinity(scip, -lb) )
4849  coef = 1.0/lb;
4850  }
4851  }
4852  if ( ! SCIPisZero(scip, coef) )
4853  {
4854  *feas += coef * solval;
4855  SCIP_CALL( SCIPaddCoefLinear(scip, cons, var, coef) );
4856  }
4857 
4858  if ( extend )
4859  {
4860  assert( extensions != NULL );
4861  /* compute new 'extensions' array */
4862  nextensionsnew = 0;
4863  for (s = 0; s < nextensions; ++s)
4864  {
4865  if ( s != bestindex && isConnectedSOS1(NULL, conflictgraph, bestindex, extensions[s]) )
4866  extensions[nextensionsnew++] = extensions[s];
4867  }
4868  nextensions = nextensionsnew;
4869  }
4870  else
4871  nextensions = 0;
4872  }
4873 
4874  /* free buffer array */
4875  if ( extend )
4876  SCIPfreeBufferArray(scip, &extensions);
4877 
4878  /* subtract rhs of constraint from feasibility value or add bound variable if existent */
4879  if ( boundvar == NULL )
4880  *feas -= 1.0;
4881  else
4882  {
4883  SCIP_CALL( SCIPaddCoefLinear(scip, cons, boundvar, -1.0) );
4884  *feas -= SCIPgetSolVal(scip, sol, boundvar);
4885  }
4886 
4887  return SCIP_OKAY;
4888 }
4889 
4890 
4891 /** tries to add feasible complementarity constraints to a given child branching node.
4892  *
4893  * @note In this function the conflict graph is updated to the conflict graph of the considered child branching node.
4894  */
4895 static
4897  SCIP* scip, /**< SCIP pointer */
4898  SCIP_NODE* node, /**< branching node */
4899  SCIP_CONSHDLRDATA* conshdlrdata, /**< constraint handler data */
4900  SCIP_DIGRAPH* conflictgraph, /**< conflict graph of the current node */
4901  SCIP_DIGRAPH* localconflicts, /**< local conflicts (updates to local conflicts of child node) */
4902  SCIP_SOL* sol, /**< solution to be enforced (NULL for LP solution) */
4903  int nsos1vars, /**< number of SOS1 variables */
4904  SCIP_Bool* verticesarefixed, /**< vector that indicates which variables are currently fixed to zerox */
4905  int* fixingsnode1, /**< vertices of variables that will be fixed to zero for the branching node in the input of this function */
4906  int nfixingsnode1, /**< number of entries of array nfixingsnode1 */
4907  int* fixingsnode2, /**< vertices of variables that will be fixed to zero for the other branching node */
4908  int nfixingsnode2, /**< number of entries of array nfixingsnode2 */
4909  int* naddedconss, /**< pointer to store the number of added SOS1 constraints */
4910  SCIP_Bool onlyviolsos1 /**< should only SOS1 constraints be added that are violated by the LP solution */
4911  )
4912 {
4913  assert( scip != NULL );
4914  assert( node != NULL );
4915  assert( conshdlrdata != NULL );
4916  assert( conflictgraph != NULL );
4917  assert( verticesarefixed != NULL );
4918  assert( fixingsnode1 != NULL );
4919  assert( fixingsnode2 != NULL );
4920  assert( naddedconss != NULL );
4921 
4922  *naddedconss = 0;
4923 
4924  if ( nfixingsnode2 > 1 )
4925  {
4926  int* fixingsnode21; /* first partition of fixingsnode2 */
4927  int* fixingsnode22; /* second partition of fixingsnode2 */
4928  int nfixingsnode21;
4929  int nfixingsnode22;
4930 
4931  int* coverarray; /* vertices, not in fixingsnode1 that cover all the vertices in array fixingsnode22 */
4932  int ncoverarray;
4933 
4934  SCIP_Bool* mark;
4935  int* succarray;
4936  int nsuccarray;
4937  int* succ;
4938  int nsucc;
4939 
4940  int i;
4941  int s;
4942 
4943  /* allocate buffer arrays */
4944  SCIP_CALL( SCIPallocBufferArray(scip, &succarray, nsos1vars) );
4945  SCIP_CALL( SCIPallocBufferArray(scip, &mark, nsos1vars) );
4946  SCIP_CALL( SCIPallocBufferArray(scip, &fixingsnode21, nfixingsnode2) );
4947  SCIP_CALL( SCIPallocBufferArray(scip, &fixingsnode22, nfixingsnode2) );
4948 
4949  /* mark all the unfixed vertices with FALSE */
4950  for (i = 0; i < nsos1vars; ++i)
4951  mark[i] = (verticesarefixed[i]);
4952 
4953  /* mark all the vertices that are in the set fixingsnode1 */
4954  for (i = 0; i < nfixingsnode1; ++i)
4955  {
4956  assert( nfixingsnode1 <= 1 || (fixingsnode1[nfixingsnode1 - 1] > fixingsnode1[nfixingsnode1 - 2]) ); /* test: vertices are sorted */
4957  mark[fixingsnode1[i]] = TRUE;
4958  }
4959 
4960  /* mark all the vertices that are in the set fixingsnode2 */
4961  for (i = 0; i < nfixingsnode2; ++i)
4962  {
4963  assert( nfixingsnode2 <= 1 || (fixingsnode2[nfixingsnode2 - 1] > fixingsnode2[nfixingsnode2 - 2]) ); /* test: vertices are sorted */
4964  mark[fixingsnode2[i]] = TRUE;
4965  }
4966 
4967  /* compute the set of vertices that have a neighbor in the set fixingsnode2, but are not in the set fixingsnode1 or fixingsnode2 and are not already fixed */
4968  nsuccarray = 0;
4969  for (i = 0; i < nfixingsnode2; ++i)
4970  {
4971  nsucc = SCIPdigraphGetNSuccessors(conflictgraph, fixingsnode2[i]);
4972  succ = SCIPdigraphGetSuccessors(conflictgraph, fixingsnode2[i]);
4973 
4974  for (s = 0; s < nsucc; ++s)
4975  {
4976  int succnode = succ[s];
4977 
4978  if ( ! mark[succnode] )
4979  {
4980  mark[succnode] = TRUE;
4981  succarray[nsuccarray++] = succnode;
4982  }
4983  }
4984  }
4985 
4986  /* allocate buffer array */
4987  SCIP_CALL( SCIPallocBufferArray(scip, &coverarray, nsos1vars) );
4988 
4989  /* mark all the vertices with FALSE */
4990  for (i = 0; i < nsos1vars; ++i)
4991  mark[i] = FALSE;
4992 
4993  /* mark all the vertices that are in the set fixingsnode2 */
4994  for (i = 0; i < nfixingsnode2; ++i)
4995  mark[fixingsnode2[i]] = TRUE;
4996 
4997  /* for every node in succarray */
4998  for (i = 0; i < nsuccarray; ++i)
4999  {
5000  SCIP_Real solval1;
5001  SCIP_VAR* var1;
5002  int vertex1;
5003  int j;
5004 
5005  vertex1 = succarray[i];
5006  var1 = SCIPnodeGetVarSOS1(conflictgraph, vertex1);
5007  solval1 = SCIPgetSolVal(scip, sol, var1);
5008 
5009  /* we only add complementarity constraints if they are violated by the current LP solution */
5010  if ( ! onlyviolsos1 || ! SCIPisFeasZero(scip, solval1) )
5011  {
5012  /* compute first partition of fixingsnode2 that is the intersection of the neighbors of 'vertex1' with the set fixingsnode2 */
5013  nsucc = SCIPdigraphGetNSuccessors(conflictgraph, vertex1);
5014  succ = SCIPdigraphGetSuccessors(conflictgraph, vertex1);
5015  nfixingsnode21 = 0;
5016 
5017  for (s = 0; s < nsucc; ++s)
5018  {
5019  if ( mark[succ[s]] )
5020  {
5021  fixingsnode21[nfixingsnode21++] = succ[s];
5022  assert( nfixingsnode21 == 1 || (fixingsnode21[nfixingsnode21 - 1] > fixingsnode21[nfixingsnode21 - 2]) ); /* test: successor vertices are sorted */
5023  }
5024  }
5025 
5026  /* if variable can be fixed to zero */
5027  if ( nfixingsnode21 == nfixingsnode2 )
5028  {
5029  SCIP_Bool infeasible;
5030 
5031  SCIP_CALL( fixVariableZeroNode(scip, var1, node, &infeasible) );
5032  assert( ! infeasible );
5033  continue;
5034  }
5035 
5036  /* compute second partition of fixingsnode2 (that is fixingsnode2 \setminus fixingsnode21 ) */
5037  SCIP_CALL( SCIPcomputeArraysSetminus(fixingsnode2, nfixingsnode2, fixingsnode21, nfixingsnode21, fixingsnode22, &nfixingsnode22) );
5038  assert ( nfixingsnode22 + nfixingsnode21 == nfixingsnode2 );
5039 
5040  /* compute cover set (that are all the vertices not in fixingsnode1 and fixingsnode21, whose neighborhood covers all the vertices of fixingsnode22) */
5041  SCIP_CALL( getCoverVertices(conflictgraph, verticesarefixed, -1, fixingsnode22, nfixingsnode22, coverarray, &ncoverarray) );
5042  SCIP_CALL( SCIPcomputeArraysSetminus(coverarray, ncoverarray, fixingsnode1, nfixingsnode1, coverarray, &ncoverarray) );
5043  SCIP_CALL( SCIPcomputeArraysSetminus(coverarray, ncoverarray, fixingsnode21, nfixingsnode21, coverarray, &ncoverarray) );
5044 
5045  for (j = 0; j < ncoverarray; ++j)
5046  {
5047  int vertex2;
5048 
5049  vertex2 = coverarray[j];
5050  assert( vertex2 != vertex1 );
5051 
5052  /* prevent double enumeration */
5053  if ( vertex2 < vertex1 )
5054  {
5055  SCIP_VAR* var2;
5056  SCIP_Real solval2;
5057 
5058  var2 = SCIPnodeGetVarSOS1(conflictgraph, vertex2);
5059  solval2 = SCIPgetSolVal(scip, sol, var2);
5060 
5061  if ( onlyviolsos1 && ( SCIPisFeasZero(scip, solval1) || SCIPisFeasZero(scip, solval2) ) )
5062  continue;
5063 
5064  if ( ! isConnectedSOS1(NULL, conflictgraph, vertex1, vertex2) )
5065  {
5066  char name[SCIP_MAXSTRLEN];
5067  SCIP_CONS* conssos1 = NULL;
5068  SCIP_Bool takebound = FALSE;
5069  SCIP_Real feas;
5070 
5071  SCIP_NODEDATA* nodedata;
5072  SCIP_Real lbboundcoef1;
5073  SCIP_Real lbboundcoef2;
5074  SCIP_Real ubboundcoef1;
5075  SCIP_Real ubboundcoef2;
5076  SCIP_VAR* boundvar1;
5077  SCIP_VAR* boundvar2;
5078 
5079  /* get bound variables if available */
5080  nodedata = (SCIP_NODEDATA*)SCIPdigraphGetNodeData(conflictgraph, vertex1);
5081  assert( nodedata != NULL );
5082  boundvar1 = nodedata->ubboundvar;
5083  lbboundcoef1 = nodedata->lbboundcoef;
5084  ubboundcoef1 = nodedata->ubboundcoef;
5085  nodedata = (SCIP_NODEDATA*)SCIPdigraphGetNodeData(conflictgraph, vertex2);
5086  assert( nodedata != NULL );
5087  boundvar2 = nodedata->ubboundvar;
5088  lbboundcoef2 = nodedata->lbboundcoef;
5089  ubboundcoef2 = nodedata->ubboundcoef;
5090 
5091  if ( boundvar1 != NULL && boundvar2 != NULL && SCIPvarCompare(boundvar1, boundvar2) == 0 )
5092  takebound = TRUE;
5093 
5094  /* add new arc to local conflicts in order to generate tighter bound inequalities */
5095  if ( conshdlrdata->addextendedbds )
5096  {
5097  if ( localconflicts == NULL )
5098  {
5099  SCIP_CALL( SCIPdigraphCreate(&conshdlrdata->localconflicts, nsos1vars) );
5100  localconflicts = conshdlrdata->localconflicts;
5101  }
5102  SCIP_CALL( SCIPdigraphAddArc(localconflicts, vertex1, vertex2, NULL) );
5103  SCIP_CALL( SCIPdigraphAddArc(localconflicts, vertex2, vertex1, NULL) );
5104  SCIP_CALL( SCIPdigraphAddArc(conflictgraph, vertex1, vertex2, NULL) );
5105  SCIP_CALL( SCIPdigraphAddArc(conflictgraph, vertex2, vertex1, NULL) );
5106 
5107  /* can sort successors in place - do not use arcdata */
5108  SCIPsortInt(SCIPdigraphGetSuccessors(localconflicts, vertex1), SCIPdigraphGetNSuccessors(localconflicts, vertex1));
5109  SCIPsortInt(SCIPdigraphGetSuccessors(localconflicts, vertex2), SCIPdigraphGetNSuccessors(localconflicts, vertex2));
5110  SCIPsortInt(SCIPdigraphGetSuccessors(conflictgraph, vertex1), SCIPdigraphGetNSuccessors(conflictgraph, vertex1));
5111  SCIPsortInt(SCIPdigraphGetSuccessors(conflictgraph, vertex2), SCIPdigraphGetNSuccessors(conflictgraph, vertex2));
5112 
5113  /* mark conflictgraph as not local such that the new arcs are deleted after currents node processing */
5114  conshdlrdata->isconflocal = TRUE;
5115  }
5116 
5117  /* measure feasibility of complementarity between var1 and var2 */
5118  if ( ! takebound )
5119  {
5120  feas = -1.0;
5121  if ( SCIPisFeasPositive(scip, solval1) )
5122  {
5123  assert( SCIPisFeasPositive(scip, SCIPvarGetUbLocal(var1)));
5124  if ( ! SCIPisInfinity(scip, SCIPvarGetUbLocal(var1)) )
5125  feas += solval1/SCIPvarGetUbLocal(var1);
5126  }
5127  else if ( SCIPisFeasNegative(scip, solval1) )
5128  {
5129  assert( SCIPisFeasPositive(scip, SCIPvarGetLbLocal(var1)));
5130  if ( ! SCIPisInfinity(scip, -SCIPvarGetLbLocal(var1)) )
5131  feas += solval1/SCIPvarGetLbLocal(var1);
5132  }
5133 
5134  if ( SCIPisFeasPositive(scip, solval2) )
5135  {
5136  assert( SCIPisFeasPositive(scip, SCIPvarGetUbLocal(var2)));
5137  if ( ! SCIPisInfinity(scip, SCIPvarGetUbLocal(var2)) )
5138  feas += solval2/SCIPvarGetUbLocal(var2);
5139  }
5140  else if ( SCIPisFeasNegative(scip, solval2) )
5141  {
5142  assert( SCIPisFeasPositive(scip, SCIPvarGetLbLocal(var2)));
5143  if ( ! SCIPisInfinity(scip, -SCIPvarGetLbLocal(var2)) )
5144  feas += solval2/SCIPvarGetLbLocal(var2);
5145  }
5146  }
5147  else
5148  {
5149  feas = -SCIPgetSolVal(scip, sol, boundvar1);
5150  if ( SCIPisFeasPositive(scip, solval1) )
5151  {
5152  assert( SCIPisFeasPositive(scip, ubboundcoef1));
5153  if ( ! SCIPisInfinity(scip, ubboundcoef1) )
5154  feas += solval1/ubboundcoef1;
5155  }
5156  else if ( SCIPisFeasNegative(scip, solval1) )
5157  {
5158  assert( SCIPisFeasPositive(scip, lbboundcoef1));
5159  if ( ! SCIPisInfinity(scip, -lbboundcoef1) )
5160  feas += solval1/lbboundcoef1;
5161  }
5162 
5163  if ( SCIPisFeasPositive(scip, solval2) )
5164  {
5165  assert( SCIPisFeasPositive(scip, ubboundcoef2));
5166  if ( ! SCIPisInfinity(scip, ubboundcoef2) )
5167  feas += solval2/ubboundcoef2;
5168  }
5169  else if ( SCIPisFeasNegative(scip, solval2) )
5170  {
5171  assert( SCIPisFeasPositive(scip, lbboundcoef2));
5172  if ( ! SCIPisInfinity(scip, -lbboundcoef2) )
5173  feas += solval2/lbboundcoef2;
5174  }
5175  assert( ! SCIPisFeasNegative(scip, solval2) );
5176  }
5177 
5178  if ( SCIPisGT(scip, feas, conshdlrdata->addcompsfeas) )
5179  {
5180  /* create SOS1 constraint */
5181  (void) SCIPsnprintf(name, SCIP_MAXSTRLEN, "sos1_branchnode_%i_no_%i", SCIPnodeGetNumber(node), *naddedconss);
5182  SCIP_CALL( SCIPcreateConsSOS1(scip, &conssos1, name, 0, NULL, NULL, TRUE, TRUE, TRUE, FALSE, TRUE,
5183  TRUE, FALSE, FALSE, FALSE) );
5184 
5185  /* add variables to SOS1 constraint */
5186  SCIP_CALL( addVarSOS1(scip, conssos1, conshdlrdata, var1, 1.0) );
5187  SCIP_CALL( addVarSOS1(scip, conssos1, conshdlrdata, var2, 2.0) );
5188 
5189  /* add SOS1 constraint to the branching node */
5190  SCIP_CALL( SCIPaddConsNode(scip, node, conssos1, NULL) );
5191  ++(*naddedconss);
5192 
5193  /* release constraint */
5194  SCIP_CALL( SCIPreleaseCons(scip, &conssos1) );
5195  }
5196 
5197 
5198  /* add bound inequality*/
5199  if ( ! SCIPisFeasZero(scip, solval1) && ! SCIPisFeasZero(scip, solval2) )
5200  {
5201  /* possibly create linear constraint of the form x_i/u_i + x_j/u_j <= t if a bound variable t with x_i <= u_i * t and x_j <= u_j * t exists.
5202  * Otherwise try to create a constraint of the form x_i/u_i + x_j/u_j <= 1. Try the same for the lower bounds. */
5203  (void) SCIPsnprintf(name, SCIP_MAXSTRLEN, "boundcons_branchnode_%i_no_%i", SCIPnodeGetNumber(node), *naddedconss);
5204  if ( takebound )
5205  {
5206  /* create constraint with right hand side = 0.0 */
5207  SCIP_CALL( SCIPcreateConsLinear(scip, &conssos1, name, 0, NULL, NULL, -SCIPinfinity(scip), 0.0, TRUE, FALSE, TRUE, FALSE, FALSE,
5208  TRUE, FALSE, FALSE, FALSE, FALSE) );
5209 
5210  /* add variables */
5211  SCIP_CALL( getBoundConsFromVertices(scip, conflictgraph, sol, vertex1, vertex2, boundvar1, conshdlrdata->addextendedbds, conssos1, &feas) );
5212  }
5213  else
5214  {
5215  /* create constraint with right hand side = 1.0 */
5216  SCIP_CALL( SCIPcreateConsLinear(scip, &conssos1, name, 0, NULL, NULL, -SCIPinfinity(scip), 1.0, TRUE, FALSE, TRUE, FALSE, FALSE,
5217  TRUE, FALSE, FALSE, FALSE, FALSE) );
5218 
5219  /* add variables */
5220  SCIP_CALL( getBoundConsFromVertices(scip, conflictgraph, sol, vertex1, vertex2, NULL, conshdlrdata->addextendedbds, conssos1, &feas) );
5221  }
5222 
5223  /* add linear constraint to the branching node if usefull */
5224  if ( SCIPisGT(scip, feas, conshdlrdata->addbdsfeas ) )
5225  {
5226  SCIP_CALL( SCIPaddConsNode(scip, node, conssos1, NULL) );
5227  ++(*naddedconss);
5228  }
5229 
5230  /* release constraint */
5231  SCIP_CALL( SCIPreleaseCons(scip, &conssos1) );
5232  }
5233 
5234  /* break if number of added constraints exceeds a predefined value */
5235  if ( conshdlrdata->maxaddcomps >= 0 && *naddedconss > conshdlrdata->maxaddcomps )
5236  break;
5237  }
5238  }
5239  }
5240  }
5241 
5242  /* break if number of added constraints exceeds a predefined value */
5243  if ( conshdlrdata->maxaddcomps >= 0 && *naddedconss > conshdlrdata->maxaddcomps )
5244  break;
5245  }
5246 
5247  /* free buffer array */
5248  SCIPfreeBufferArray(scip, &coverarray);
5249  SCIPfreeBufferArray(scip, &fixingsnode22);
5250  SCIPfreeBufferArray(scip, &fixingsnode21);
5251  SCIPfreeBufferArray(scip, &mark);
5252  SCIPfreeBufferArray(scip, &succarray);
5253  }
5254 
5255  return SCIP_OKAY;
5256 }
5257 
5258 
5259 /** resets local conflict graph to the conflict graph of the root node */
5260 static
5262  SCIP_DIGRAPH* conflictgraph, /**< conflict graph of root node */
5263  SCIP_DIGRAPH* localconflicts, /**< local conflicts that should be removed from conflict graph */
5264  int nsos1vars /**< number of SOS1 variables */
5265  )
5266 {
5267  int j;
5268 
5269  for (j = 0; j < nsos1vars; ++j)
5270  {
5271  int nsuccloc;
5272 
5273  nsuccloc = SCIPdigraphGetNSuccessors(localconflicts, j);
5274  if ( nsuccloc > 0 )
5275  {
5276  int* succloc;
5277  int* succ;
5278  int nsucc;
5279  int k = 0;
5280 
5281  succloc = SCIPdigraphGetSuccessors(localconflicts, j);
5282  succ = SCIPdigraphGetSuccessors(conflictgraph, j);
5283  nsucc = SCIPdigraphGetNSuccessors(conflictgraph, j);
5284 
5285  /* reset number of successors */
5286  SCIP_CALL( SCIPcomputeArraysSetminus(succ, nsucc, succloc, nsuccloc, succ, &k) );
5287  SCIP_CALL( SCIPdigraphSetNSuccessors(conflictgraph, j, k) );
5288  SCIP_CALL( SCIPdigraphSetNSuccessors(localconflicts, j, 0) );
5289  }
5290  }
5291 
5292  return SCIP_OKAY;
5293 }
5294 
5295 
5296 /** Conflict graph enforcement method
5297  *
5298  * The conflict graph can be enforced by different branching rules:
5299  *
5300  * - Branch on the neighborhood of a single variable @p i, i.e., in one branch \f$x_i\f$ is fixed to zero and in the
5301  * other its neighbors from the conflict graph.
5302  *
5303  * - Branch on complete bipartite subgraphs of the conflict graph, i.e., in one branch fix the variables from the first
5304  * bipartite partition and the variables from the second bipartite partition in the other.
5305  *
5306  * - In addition to variable domain fixings, it is sometimes also possible to add new SOS1 constraints to the branching
5307  * nodes. This results in a nonstatic conflict graph, which may change dynamically with every branching node.
5308  *
5309  * We make use of different selection rules that define on which system of SOS1 variables to branch next:
5310  *
5311  * - Most infeasible branching: Branch on the system of SOS1 variables with largest violation.
5312  *
5313  * - Strong branching: Here, the LP-relaxation is partially solved for each branching decision among a candidate list.
5314  * Then the decision with best progress is chosen.
5315  */
5316 static
5318  SCIP* scip, /**< SCIP pointer */
5319  SCIP_CONSHDLRDATA* conshdlrdata, /**< constraint handler data */
5320  SCIP_CONSHDLR* conshdlr, /**< constraint handler */
5321  int nconss, /**< number of constraints */
5322  SCIP_CONS** conss, /**< SOS1 constraints */
5323  SCIP_SOL* sol, /**< solution to be enforced (NULL for LP solution) */
5324  SCIP_RESULT* result /**< result */
5325  )
5326 {
5327  SCIP_DIGRAPH* conflictgraph;
5328  int nsos1vars;
5329 
5330  SCIP_Bool* verticesarefixed = NULL;
5331  int* fixingsnode1 = NULL;
5332  int* fixingsnode2 = NULL;
5333  int nfixingsnode1;
5334  int nfixingsnode2;
5335 
5336  SCIP_Real bestobjval1 = -SCIPinfinity(scip);
5337  SCIP_Real bestobjval2 = -SCIPinfinity(scip);
5338  SCIP_Real lpobjval = -SCIPinfinity(scip);
5339 
5340  SCIP_Bool infeasible;
5341  SCIP_Bool bipbranch = FALSE;
5342  int nstrongrounds;
5343 
5344  int branchvertex;
5345  SCIP_NODE* node1;
5346  SCIP_NODE* node2;
5347  SCIP_Real nodeselest;
5348  SCIP_Real objest;
5349 
5350  int i;
5351  int j;
5352  int c;
5353 
5354  assert( scip != NULL );
5355  assert( conshdlrdata != NULL );
5356  assert( conshdlr != NULL );
5357  assert( conss != NULL );
5358  assert( result != NULL );
5359 
5360  SCIPdebugMsg(scip, "Enforcing SOS1 conflict graph <%s>.\n", SCIPconshdlrGetName(conshdlr) );
5361  *result = SCIP_DIDNOTRUN;
5362 
5363  /* get number of SOS1 variables */
5364  nsos1vars = conshdlrdata->nsos1vars;
5365 
5366  /* get conflict graph */
5367  conflictgraph = conshdlrdata->conflictgraph;
5368  assert( ! conshdlrdata->isconflocal ); /* conflictgraph should be the one of the root node */
5369 
5370  /* check each constraint and update conflict graph if necessary */
5371  for (c = 0; c < nconss; ++c)
5372  {
5373  SCIP_CONSDATA* consdata;
5374  SCIP_CONS* cons;
5375  SCIP_Bool cutoff;int ngen;
5376 
5377  cons = conss[c];
5378  assert( cons != NULL );
5379  consdata = SCIPconsGetData(cons);
5380  assert( consdata != NULL );
5381 
5382  /* do nothing if there are not enough variables - this is usually eliminated by preprocessing */
5383  if ( consdata->nvars < 2 )
5384  continue;
5385 
5386  /* first perform propagation (it might happen that standard propagation is turned off) */
5387  ngen = 0;
5388  SCIP_CALL( propConsSOS1(scip, cons, consdata, &cutoff, &ngen) );
5389  SCIPdebugMsg(scip, "propagating <%s> in enforcing (cutoff: %u, domain reductions: %d).\n", SCIPconsGetName(cons), cutoff, ngen);
5390  if ( cutoff )
5391  {
5392  *result = SCIP_CUTOFF;
5393  break;
5394  }
5395  if ( ngen > 0 )
5396  {
5397  *result = SCIP_REDUCEDDOM;
5398  break;
5399  }
5400  assert( ngen == 0 );
5401 
5402  /* add local conflicts to conflict graph and save them in 'localconflicts' */
5403  if ( consdata->local )
5404  {
5405  SCIP_VAR** vars;
5406  int nvars;
5407  int indi;
5408  int indj;
5409 
5410  if ( conshdlrdata->localconflicts == NULL )
5411  {
5412  SCIP_CALL( SCIPdigraphCreate(&conshdlrdata->localconflicts, nsos1vars ) );
5413  }
5414 
5415  vars = consdata->vars;
5416  nvars = consdata->nvars;
5417  for (i = 0; i < nvars-1; ++i)
5418  {
5419  SCIP_VAR* var;
5420 
5421  var = vars[i];
5422  indi = varGetNodeSOS1(conshdlrdata, var);
5423  assert( indi >= 0 );
5424 
5425  if ( ! SCIPisFeasZero(scip, SCIPvarGetUbLocal(var)) || ! SCIPisFeasZero(scip, SCIPvarGetLbLocal(var)) )
5426  {
5427  for (j = i+1; j < nvars; ++j)
5428  {
5429  var = vars[j];
5430  indj = varGetNodeSOS1(conshdlrdata, var);
5431  assert( indj >= 0 );
5432 
5433  if ( ! SCIPisFeasZero(scip, SCIPvarGetUbLocal(var)) || ! SCIPisFeasZero(scip, SCIPvarGetLbLocal(var)) )
5434  {
5435  if ( ! isConnectedSOS1(NULL, conflictgraph, indi, indj) )
5436  {
5437  SCIP_CALL( SCIPdigraphAddArcSafe(conflictgraph, indi, indj, NULL) );
5438  SCIP_CALL( SCIPdigraphAddArcSafe(conflictgraph, indj, indi, NULL) );
5439 
5440  SCIP_CALL( SCIPdigraphAddArcSafe(conshdlrdata->localconflicts, indi, indj, NULL) );
5441  SCIP_CALL( SCIPdigraphAddArcSafe(conshdlrdata->localconflicts, indj, indi, NULL) );
5442 
5443  conshdlrdata->isconflocal = TRUE;
5444  }
5445  }
5446  }
5447  }
5448  }
5449  }
5450  }
5451 
5452  /* sort successor list of conflict graph if necessary */
5453  if ( conshdlrdata->isconflocal )
5454  {
5455  for (j = 0; j < nsos1vars; ++j)
5456  {
5457  int nsuccloc;
5458 
5459  nsuccloc = SCIPdigraphGetNSuccessors(conshdlrdata->localconflicts, j);
5460  if ( nsuccloc > 0 )
5461  {
5462  SCIPsortInt(SCIPdigraphGetSuccessors(conflictgraph, j), SCIPdigraphGetNSuccessors(conflictgraph, j));
5463  SCIPsortInt(SCIPdigraphGetSuccessors(conshdlrdata->localconflicts, j), nsuccloc);
5464  }
5465  }
5466  }
5467 
5468  if ( *result == SCIP_CUTOFF || *result == SCIP_REDUCEDDOM )
5469  {
5470  /* remove local conflicts from conflict graph */
5471  if ( conshdlrdata->isconflocal )
5472  {
5473  SCIP_CALL( resetConflictgraphSOS1(conflictgraph, conshdlrdata->localconflicts, nsos1vars) );
5474  conshdlrdata->isconflocal = FALSE;
5475  }
5476  return SCIP_OKAY;
5477  }
5478 
5479 
5480  /* detect fixed variables */
5481  SCIP_CALL( SCIPallocBufferArray(scip, &verticesarefixed, nsos1vars) );
5482  for (j = 0; j < nsos1vars; ++j)
5483  {
5484  SCIP_VAR* var;
5485  SCIP_Real ub;
5486  SCIP_Real lb;
5487 
5488  var = SCIPnodeGetVarSOS1(conflictgraph, j);
5489  ub = SCIPvarGetUbLocal(var);
5490  lb = SCIPvarGetLbLocal(var);
5491  if ( SCIPisFeasZero(scip, ub) && SCIPisFeasZero(scip, lb) )
5492  verticesarefixed[j] = TRUE;
5493  else
5494  verticesarefixed[j] = FALSE;
5495  }
5496 
5497  /* should bipartite branching be used? */
5498  if ( conshdlrdata->branchingrule == 'b' )
5499  bipbranch = TRUE;
5500 
5501  /* determine number of strong branching iterations */
5502  if ( conshdlrdata->nstrongrounds >= 0 )
5503  nstrongrounds = MIN(conshdlrdata->nstrongrounds, nsos1vars);
5504  else
5505  {
5506  /* determine number depending on depth, based on heuristical considerations */
5507  if ( SCIPgetDepth(scip) <= 10 )
5508  nstrongrounds = MAX(10, (int)SCIPfloor(scip, pow(log((SCIP_Real)nsos1vars), 1.0)));/*lint !e666*/
5509  else if ( SCIPgetDepth(scip) <= 20 )
5510  nstrongrounds = MAX(5, (int)SCIPfloor(scip, pow(log((SCIP_Real)nsos1vars), 0.7)));/*lint !e666*/
5511  else
5512  nstrongrounds = 0;
5513  nstrongrounds = MIN(nsos1vars, nstrongrounds);
5514  }
5515 
5516 
5517  /* allocate buffer arrays */
5518  SCIP_CALL( SCIPallocBufferArray(scip, &fixingsnode1, nsos1vars) );
5519  if ( bipbranch )
5520  SCIP_CALL( SCIPallocBufferArray(scip, &fixingsnode2, nsos1vars) );
5521  else
5522  SCIP_CALL( SCIPallocBufferArray(scip, &fixingsnode2, 1) );
5523 
5524 
5525  /* if strongbranching is turned off: use most infeasible branching */
5526  if ( nstrongrounds == 0 )
5527  {
5528  SCIP_Bool relsolfeas;
5529 
5530  /* get branching vertex using most infeasible branching */
5531  SCIP_CALL( getBranchingPrioritiesSOS1(scip, conshdlrdata, conflictgraph, sol, nsos1vars, verticesarefixed, bipbranch, fixingsnode1, fixingsnode2, NULL, &branchvertex, &relsolfeas) );
5532 
5533  /* if LP relaxation solution is feasible */
5534  if ( relsolfeas )
5535  {
5536  SCIPdebugMsg(scip, "all the SOS1 constraints are feasible.\n");
5537 
5538  /* update result */
5539  *result = SCIP_FEASIBLE;
5540 
5541  /* remove local conflicts from conflict graph */
5542  if ( conshdlrdata->isconflocal )
5543  {
5544  SCIP_CALL( resetConflictgraphSOS1(conflictgraph, conshdlrdata->localconflicts, nsos1vars) );
5545  conshdlrdata->isconflocal = FALSE;
5546  }
5547 
5548  /* free memory */
5549  SCIPfreeBufferArrayNull(scip, &fixingsnode2);
5550  SCIPfreeBufferArrayNull(scip, &fixingsnode1);
5551  SCIPfreeBufferArrayNull(scip, &verticesarefixed);
5552 
5553  return SCIP_OKAY;
5554  }
5555  }
5556  else
5557  {
5558  /* get branching vertex using strong branching */
5559  SCIP_CALL( getBranchingDecisionStrongbranchSOS1(scip, conshdlrdata, conflictgraph, sol, nsos1vars, lpobjval, bipbranch, nstrongrounds, verticesarefixed,
5560  fixingsnode1, fixingsnode2, &branchvertex, &bestobjval1, &bestobjval2, result) );
5561 
5562  if ( *result == SCIP_CUTOFF || *result == SCIP_FEASIBLE || *result == SCIP_REDUCEDDOM )
5563  {
5564  /* remove local conflicts from conflict graph */
5565  if ( conshdlrdata->isconflocal )
5566  {
5567  SCIP_CALL( resetConflictgraphSOS1(conflictgraph, conshdlrdata->localconflicts, nsos1vars) );
5568  conshdlrdata->isconflocal = FALSE;
5569  }
5570 
5571  /* free memory */
5572  SCIPfreeBufferArrayNull(scip, &fixingsnode2);
5573  SCIPfreeBufferArrayNull(scip, &fixingsnode1);
5574  SCIPfreeBufferArrayNull(scip, &verticesarefixed);
5575 
5576  return SCIP_OKAY;
5577  }
5578  }
5579 
5580  /* if we shouldleave branching decision to branching rules */
5581  if ( ! conshdlrdata->branchsos )
5582  {
5583  /* remove local conflicts from conflict graph */
5584  if ( conshdlrdata->isconflocal )
5585  {
5586  SCIP_CALL( resetConflictgraphSOS1(conflictgraph, conshdlrdata->localconflicts, nsos1vars) );
5587  conshdlrdata->isconflocal = FALSE;
5588  }
5589 
5590  if ( SCIPvarIsBinary(SCIPnodeGetVarSOS1(conflictgraph, branchvertex)) )
5591  {
5592  *result = SCIP_INFEASIBLE;
5593  return SCIP_OKAY;
5594  }
5595  else
5596  {
5597  SCIPerrorMessage("Incompatible parameter setting: branchsos can only be set to false if all SOS1 variables are binary.\n");
5598  return SCIP_PARAMETERWRONGVAL;
5599  }
5600  }
5601 
5602  /* create branching nodes */
5603 
5604  /* get vertices of variables that will be fixed to zero for each node */
5605  assert( branchvertex >= 0 && branchvertex < nsos1vars );
5606  assert( ! verticesarefixed[branchvertex] );
5607  SCIP_CALL( getBranchingVerticesSOS1(scip, conflictgraph, sol, verticesarefixed, bipbranch, branchvertex, fixingsnode1, &nfixingsnode1, fixingsnode2, &nfixingsnode2) );
5608 
5609  /* calculate node selection and objective estimate for node 1 */
5610  nodeselest = 0.0;
5611  objest = 0.0;
5612  for (j = 0; j < nfixingsnode1; ++j)
5613  {
5614  SCIP_VAR* var;
5615 
5616  var = SCIPnodeGetVarSOS1(conflictgraph, fixingsnode1[j]);
5617  nodeselest += SCIPcalcNodeselPriority(scip, var, SCIP_BRANCHDIR_DOWNWARDS, 0.0);
5618  objest += SCIPcalcChildEstimate(scip, var, 0.0);
5619  }
5620  /* take the average of the individual estimates */
5621  objest = objest/((SCIP_Real) nfixingsnode1);
5622 
5623  /* create node 1 */
5624  SCIP_CALL( SCIPcreateChild(scip, &node1, nodeselest, objest) );
5625 
5626  /* fix variables for the first node */
5627  if ( conshdlrdata->fixnonzero && nfixingsnode2 == 1 )
5628  {
5629  SCIP_VAR* var;
5630  SCIP_Real lb;
5631  SCIP_Real ub;
5632 
5633  var = SCIPnodeGetVarSOS1(conflictgraph, fixingsnode2[0]);
5634  lb = SCIPvarGetLbLocal(var);
5635  ub = SCIPvarGetUbLocal(var);
5636 
5638  {
5639  if ( SCIPisZero(scip, lb) )
5640  {
5641  /* fix variable to some very small, but positive number or to 1.0 if variable is integral */
5642  if (SCIPvarIsIntegral(var) )
5643  {
5644  SCIP_CALL( SCIPchgVarLbNode(scip, node1, var, 1.0) );
5645  }
5646  else
5647  {
5648  SCIP_CALL( SCIPchgVarLbNode(scip, node1, var, 1.5 * SCIPfeastol(scip)) );
5649  }
5650  }
5651  else if ( SCIPisZero(scip, ub) )
5652  {
5653  if (SCIPvarIsIntegral(var) )
5654  {
5655  /* fix variable to some negative number with small absolute value to -1.0 if variable is integral */
5656  SCIP_CALL( SCIPchgVarUbNode(scip, node1, var, -1.0) );
5657  }
5658  else
5659  {
5660  /* fix variable to some negative number with small absolute value to -1.0 if variable is integral */
5661  SCIP_CALL( SCIPchgVarUbNode(scip, node1, var, -1.5 * SCIPfeastol(scip)) );
5662  }
5663  }
5664  }
5665  }
5666  for (j = 0; j < nfixingsnode1; ++j)
5667  {
5668  /* fix variable to zero */
5669  SCIP_CALL( fixVariableZeroNode(scip, SCIPnodeGetVarSOS1(conflictgraph, fixingsnode1[j]), node1, &infeasible) );
5670  assert( ! infeasible );
5671  }
5672 
5673  /* calculate node selection and objective estimate for node 2 */
5674  nodeselest = 0.0;
5675  objest = 0.0;
5676  for (j = 0; j < nfixingsnode2; ++j)
5677  {
5678  SCIP_VAR* var;
5679 
5680  var = SCIPnodeGetVarSOS1(conflictgraph, fixingsnode2[j]);
5681  nodeselest += SCIPcalcNodeselPriority(scip, var, SCIP_BRANCHDIR_DOWNWARDS, 0.0);
5682  objest += SCIPcalcChildEstimate(scip, var, 0.0);
5683  }
5684 
5685  /* take the average of the individual estimates */
5686  objest = objest/((SCIP_Real) nfixingsnode2);
5687 
5688  /* create node 2 */
5689  SCIP_CALL( SCIPcreateChild(scip, &node2, nodeselest, objest) );
5690 
5691  /* fix variables to zero */
5692  for (j = 0; j < nfixingsnode2; ++j)
5693  {
5694  SCIP_CALL( fixVariableZeroNode(scip, SCIPnodeGetVarSOS1(conflictgraph, fixingsnode2[j]), node2, &infeasible) );
5695  assert( ! infeasible );
5696  }
5697 
5698 
5699  /* add complementarity constraints to the branching nodes */
5700  if ( conshdlrdata->addcomps && ( conshdlrdata->addcompsdepth == -1 || conshdlrdata->addcompsdepth >= SCIPgetDepth(scip) ) )
5701  {
5702  int naddedconss;
5703 
5704  assert( ! conshdlrdata->fixnonzero );
5705 
5706  /* add complementarity constraints to the left branching node */
5707  SCIP_CALL( addBranchingComplementaritiesSOS1(scip, node1, conshdlrdata, conflictgraph, conshdlrdata->localconflicts, sol,
5708  nsos1vars, verticesarefixed, fixingsnode1, nfixingsnode1, fixingsnode2, nfixingsnode2, &naddedconss, TRUE) );
5709 
5710  if ( naddedconss == 0 )
5711  {
5712  /* add complementarity constraints to the right branching node */
5713  SCIP_CALL( addBranchingComplementaritiesSOS1(scip, node2, conshdlrdata, conflictgraph, conshdlrdata->localconflicts, sol,
5714  nsos1vars, verticesarefixed, fixingsnode2, nfixingsnode2, fixingsnode1, nfixingsnode1, &naddedconss, TRUE) );
5715  }
5716  }
5717 
5718  /* sets node's lower bound to the best known value */
5719  if ( nstrongrounds > 0 )
5720  {
5721  SCIP_CALL( SCIPupdateNodeLowerbound(scip, node1, MAX(lpobjval, bestobjval1) ) );
5722  SCIP_CALL( SCIPupdateNodeLowerbound(scip, node2, MAX(lpobjval, bestobjval2) ) );
5723  }
5724 
5725  /* remove local conflicts from conflict graph */
5726  if ( conshdlrdata->isconflocal )
5727  {
5728  SCIP_CALL( resetConflictgraphSOS1(conflictgraph, conshdlrdata->localconflicts, nsos1vars) );
5729  conshdlrdata->isconflocal = FALSE;
5730  }
5731 
5732  /* free buffer arrays */
5733  SCIPfreeBufferArrayNull(scip, &fixingsnode2);
5734  SCIPfreeBufferArrayNull(scip, &fixingsnode1);
5735  SCIPfreeBufferArrayNull(scip, &verticesarefixed );
5736  *result = SCIP_BRANCHED;
5737 
5738  return SCIP_OKAY;
5739 }
5740 
5741 
5742 /** SOS1 branching enforcement method
5743  *
5744  * We check whether the current solution is feasible, i.e., contains at most one nonzero
5745  * variable. If not, we branch along the lines indicated by Beale and Tomlin:
5746  *
5747  * We first compute \f$W = \sum_{j=1}^n |x_i|\f$ and \f$w = \sum_{j=1}^n j\, |x_i|\f$. Then we
5748  * search for the index \f$k\f$ that satisfies
5749  * \f[
5750  * k \leq \frac{w}{W} < k+1.
5751  * \f]
5752  * The branches are then
5753  * \f[
5754  * x_1 = 0, \ldots, x_k = 0 \qquad \mbox{and}\qquad x_{k+1} = 0, \ldots, x_n = 0.
5755  * \f]
5756  *
5757  * If the constraint contains two variables, the branching of course simplifies.
5758  *
5759  * Depending on the parameters (@c branchnonzeros, @c branchweight) there are three ways to choose
5760  * the branching constraint.
5761  *
5762  * <TABLE>
5763  * <TR><TD>@c branchnonzeros</TD><TD>@c branchweight</TD><TD>constraint chosen</TD></TR>
5764  * <TR><TD>@c true </TD><TD> ? </TD><TD>most number of nonzeros</TD></TR>
5765  * <TR><TD>@c false </TD><TD> @c true </TD><TD>maximal weight corresponding to nonzero variable</TD></TR>
5766  * <TR><TD>@c false </TD><TD> @c true </TD><TD>largest sum of variable values</TD></TR>
5767  * </TABLE>
5768  *
5769  * @c branchnonzeros = @c false, @c branchweight = @c true allows the user to specify an order for
5770  * the branching importance of the constraints (setting the weights accordingly).
5771  *
5772  * Constraint branching can also be turned off using parameter @c branchsos.
5773  */
5774 static
5776  SCIP* scip, /**< SCIP pointer */
5777  SCIP_CONSHDLR* conshdlr, /**< constraint handler */
5778  int nconss, /**< number of constraints */
5779  SCIP_CONS** conss, /**< indicator constraints */
5780  SCIP_SOL* sol, /**< solution to be enforced (NULL for LP solution) */
5781  SCIP_RESULT* result /**< result */
5782  )
5783 {
5784  SCIP_CONSHDLRDATA* conshdlrdata;
5785  SCIP_CONSDATA* consdata;
5786  SCIP_NODE* node1;
5787  SCIP_NODE* node2;
5789  SCIP_Real maxWeight;
5790  SCIP_VAR** vars;
5791  int nvars;
5792  int c;
5793 
5794  assert( scip != NULL );
5795  assert( conshdlr != NULL );
5796  assert( conss != NULL );
5797  assert( result != NULL );
5798 
5799  maxWeight = -SCIP_REAL_MAX;
5800  branchCons = NULL;
5801 
5802  SCIPdebugMsg(scip, "Enforcing SOS1 constraints <%s>.\n", SCIPconshdlrGetName(conshdlr) );
5803  *result = SCIP_FEASIBLE;
5804 
5805  /* get constraint handler data */
5806  conshdlrdata = SCIPconshdlrGetData(conshdlr);
5807  assert( conshdlrdata != NULL );
5808 
5809  /* check each constraint */
5810  for (c = 0; c < nconss; ++c)
5811  {
5812  SCIP_CONS* cons;
5813  SCIP_Bool cutoff;
5814  SCIP_Real weight;
5815  int ngen;
5816  int cnt;
5817  int j;
5818 
5819  cons = conss[c];
5820  assert( cons != NULL );
5821  consdata = SCIPconsGetData(cons);
5822  assert( consdata != NULL );
5823 
5824  ngen = 0;
5825  cnt = 0;
5826  nvars = consdata->nvars;
5827  vars = consdata->vars;
5828 
5829  /* do nothing if there are not enough variables - this is usually eliminated by preprocessing */
5830  if ( nvars < 2 )
5831  continue;
5832 
5833  /* first perform propagation (it might happen that standard propagation is turned off) */
5834  SCIP_CALL( propConsSOS1(scip, cons, consdata, &cutoff, &ngen) );
5835  SCIPdebugMsg(scip, "propagating <%s> in enforcing (cutoff: %u, domain reductions: %d).\n", SCIPconsGetName(cons), cutoff, ngen);
5836  if ( cutoff )
5837  {
5838  *result = SCIP_CUTOFF;
5839  return SCIP_OKAY;
5840  }
5841  if ( ngen > 0 )
5842  {
5843  *result = SCIP_REDUCEDDOM;
5844  return SCIP_OKAY;
5845  }
5846  assert( ngen == 0 );
5847 
5848  /* check constraint */
5849  weight = 0.0;
5850  for (j = 0; j < nvars; ++j)
5851  {
5852  SCIP_Real val = REALABS(SCIPgetSolVal(scip, sol, vars[j]));
5853 
5854  if ( ! SCIPisFeasZero(scip, val) )
5855  {
5856  if ( conshdlrdata->branchnonzeros )
5857  weight += 1.0;
5858  else
5859  {
5860  if ( conshdlrdata->branchweight )
5861  {
5862  /* choose maximum nonzero-variable weight */
5863  if ( consdata->weights[j] > weight )
5864  weight = consdata->weights[j];
5865  }
5866  else
5867  weight += val;
5868  }
5869  ++cnt;
5870  }
5871  }
5872  /* if constraint is violated */
5873  if ( cnt > 1 && weight > maxWeight )
5874  {
5875  maxWeight = weight;
5876  branchCons = cons;
5877  }
5878  }
5879 
5880  /* if all constraints are feasible */
5881  if ( branchCons == NULL )
5882  {
5883  SCIPdebugMsg(scip, "All SOS1 constraints are feasible.\n");
5884  return SCIP_OKAY;
5885  }
5886 
5887  /* if we should leave branching decision to branching rules */
5888  if ( ! conshdlrdata->branchsos )
5889  {
5890  int j;
5891 
5892  consdata = SCIPconsGetData(branchCons);
5893  for (j = 0; j < consdata->nvars; ++j)
5894  {
5895  if ( ! SCIPvarIsBinary(consdata->vars[j]) )
5896  break;
5897  }
5898 
5899  if ( j == consdata->nvars )
5900  {
5901  *result = SCIP_INFEASIBLE;
5902  return SCIP_OKAY;
5903  }
5904  else
5905  {
5906  SCIPerrorMessage("Incompatible parameter setting: branchsos can only be set to false if all SOS1 variables are binary.\n");
5907  return SCIP_PARAMETERWRONGVAL;
5908  }
5909  }
5910 
5911  /* otherwise create branches */
5912  SCIPdebugMsg(scip, "Branching on constraint <%s> (weight: %f).\n", SCIPconsGetName(branchCons), maxWeight);
5913  consdata = SCIPconsGetData(branchCons);
5914  assert( consdata != NULL );
5915  nvars = consdata->nvars;
5916  vars = consdata->vars;
5917 
5918  if ( nvars == 2 )
5919  {
5920  SCIP_Bool infeasible;
5921 
5922  /* constraint is infeasible: */
5923  assert( ! SCIPisFeasZero(scip, SCIPgetSolVal(scip, sol, vars[0])) && ! SCIPisFeasZero(scip, SCIPgetSolVal(scip, sol, vars[1])) );
5924 
5925  /* create branches */
5926  SCIPdebugMsg(scip, "Creating two branches.\n");
5927 
5928  SCIP_CALL( SCIPcreateChild(scip, &node1, SCIPcalcNodeselPriority(scip, vars[0], SCIP_BRANCHDIR_DOWNWARDS, 0.0), SCIPcalcChildEstimate(scip, vars[0], 0.0) ) );
5929  SCIP_CALL( fixVariableZeroNode(scip, vars[0], node1, &infeasible) );
5930  assert( ! infeasible );
5931 
5932  SCIP_CALL( SCIPcreateChild(scip, &node2, SCIPcalcNodeselPriority(scip, vars[1], SCIP_BRANCHDIR_DOWNWARDS, 0.0), SCIPcalcChildEstimate(scip, vars[1], 0.0) ) );
5933  SCIP_CALL( fixVariableZeroNode(scip, vars[1], node2, &infeasible) );
5934  assert( ! infeasible );
5935  }
5936  else
5937  {
5938  SCIP_Bool infeasible;
5939  SCIP_Real weight1;
5940  SCIP_Real weight2;
5941  SCIP_Real nodeselest;
5942  SCIP_Real objest;
5943  SCIP_Real w;
5944  int j;
5945  int ind;
5946  int cnt;
5947 
5948  cnt = 0;
5949 
5950  weight1 = 0.0;
5951  weight2 = 0.0;
5952 
5953  /* compute weight */
5954  for (j = 0; j < nvars; ++j)
5955  {
5956  SCIP_Real val = REALABS(SCIPgetSolVal(scip, sol, vars[j]));
5957  weight1 += val * (SCIP_Real) j;
5958  weight2 += val;
5959 
5960  if ( ! SCIPisFeasZero(scip, val) )
5961  ++cnt;
5962  }
5963 
5964  assert( cnt >= 2 );
5965  assert( !SCIPisFeasZero(scip, weight2) );
5966  w = weight1/weight2; /*lint !e795*/
5967 
5968  ind = (int) SCIPfloor(scip, w);
5969  assert( 0 <= ind && ind < nvars-1 );
5970 
5971  /* branch on variable ind: either all variables up to ind or all variables after ind are zero */
5972  SCIPdebugMsg(scip, "Branching on variable <%s>.\n", SCIPvarGetName(vars[ind]));
5973 
5974  /* calculate node selection and objective estimate for node 1 */
5975  nodeselest = 0.0;
5976  objest = 0.0;
5977  for (j = 0; j <= ind; ++j)
5978  {
5979  nodeselest += SCIPcalcNodeselPriority(scip, vars[j], SCIP_BRANCHDIR_DOWNWARDS, 0.0);
5980  objest += SCIPcalcChildEstimate(scip, vars[j], 0.0);
5981  }
5982  /* take the average of the individual estimates */
5983  objest = objest/(SCIP_Real)(ind + 1.0);
5984 
5985  /* create node 1 */
5986  SCIP_CALL( SCIPcreateChild(scip, &node1, nodeselest, objest) );
5987  for (j = 0; j <= ind; ++j)
5988  {
5989  SCIP_CALL( fixVariableZeroNode(scip, vars[j], node1, &infeasible) );
5990  assert( ! infeasible );
5991  }
5992 
5993  /* calculate node selection and objective estimate for node 1 */
5994  nodeselest = 0.0;
5995  objest = 0.0;
5996  for (j = ind+1; j < nvars; ++j)
5997  {
5998  nodeselest += SCIPcalcNodeselPriority(scip, vars[j], SCIP_BRANCHDIR_DOWNWARDS, 0.0);
5999  objest += SCIPcalcChildEstimate(scip, vars[j], 0.0);
6000  }
6001  /* take the average of the individual estimates */
6002  objest = objest/((SCIP_Real) (nvars - ind - 1));
6003 
6004  /* create node 2 */
6005  SCIP_CALL( SCIPcreateChild(scip, &node2, nodeselest, objest) );
6006  for (j = ind+1; j < nvars; ++j)
6007  {
6008  SCIP_CALL( fixVariableZeroNode(scip, vars[j], node2, &infeasible) );
6009  assert( ! infeasible );
6010  }
6011  }
6012  SCIP_CALL( SCIPresetConsAge(scip, branchCons) );
6013  *result = SCIP_BRANCHED;
6014 
6015  return SCIP_OKAY;
6016 }
6017 
6018 
6019 /** constraint enforcing method of constraint handler */
6020 static
6022  SCIP* scip, /**< SCIP pointer */
6023  SCIP_CONSHDLR* conshdlr, /**< constraint handler */
6024  int nconss, /**< number of constraints */
6025  SCIP_CONS** conss, /**< indicator constraints */
6026  SCIP_SOL* sol, /**< solution to be enforced (NULL for LP solution) */
6027  SCIP_RESULT* result /**< result */
6028  )
6029 {
6030  SCIP_CONSHDLRDATA* conshdlrdata;
6031 
6032  assert( scip != NULL );
6033  assert( conshdlr != NULL );
6034  assert( conss != NULL );
6035  assert( result != NULL );
6036 
6037  /* get constraint handler data */
6038  conshdlrdata = SCIPconshdlrGetData(conshdlr);
6039  assert( conshdlrdata != NULL );
6040 
6041  if ( conshdlrdata->addcomps && conshdlrdata->fixnonzero )
6042  {
6043  SCIPerrorMessage("Incompatible parameter setting: addcomps = TRUE and fixnonzero = TRUE.\n");
6044  return SCIP_PARAMETERWRONGVAL;
6045  }
6046 
6047  if ( conshdlrdata->fixnonzero && ( conshdlrdata->branchingrule == 'b' || conshdlrdata->branchingrule == 's' ) )
6048  {
6049  SCIPerrorMessage("Incompatible parameter setting: nonzero fixing is not compatible with bipartite or sos1 branching.\n");
6050  return SCIP_PARAMETERWRONGVAL;
6051  }
6052 
6053  if ( conshdlrdata->branchingrule == 's' && conshdlrdata->nstrongrounds != 0 )
6054  {
6055  SCIPerrorMessage("Strong branching is not available for SOS1 branching.\n");
6056  return SCIP_PARAMETERWRONGVAL;
6057  }
6058 
6059  if ( conshdlrdata->branchingrule == 's' || conshdlrdata->switchsos1branch )
6060  {
6061  /* enforce SOS1 constraints */
6062  SCIP_CALL( enforceConssSOS1(scip, conshdlr, nconss, conss, sol, result) );
6063  }
6064  else
6065  {
6066  if ( conshdlrdata->branchingrule != 'n' && conshdlrdata->branchingrule != 'b' )
6067  {
6068  SCIPerrorMessage("branching rule %c unknown\n", conshdlrdata->branchingrule);
6069  return SCIP_PARAMETERWRONGVAL;
6070  }
6071 
6072  /* enforce conflict graph */
6073  SCIP_CALL( enforceConflictgraph(scip, conshdlrdata, conshdlr, nconss, conss, sol, result) );
6074  }
6075 
6076  return SCIP_OKAY;
6077 }
6078 
6079 
6080 /* ----------------------------- separation ------------------------------------*/
6081 
6082 /** initialitze tclique graph and create clique data */
6083 static
6085  SCIP* scip, /**< SCIP pointer */
6086  SCIP_CONSHDLR* conshdlr, /**< constraint handler */
6087  SCIP_CONSHDLRDATA* conshdlrdata, /**< constraint handler data */
6088  SCIP_DIGRAPH* conflictgraph, /**< conflict graph */
6089  int nsos1vars /**< number of SOS1 variables */
6090  )
6091 {
6092  TCLIQUE_DATA* tcliquedata;
6093  int j;
6094 
6095  /* try to generate bound cuts */
6096  if ( ! tcliqueCreate(&conshdlrdata->tcliquegraph) )
6097  return SCIP_NOMEMORY;
6098 
6099  /* add nodes */
6100  for (j = 0; j < nsos1vars; ++j)
6101  {
6102  if ( ! tcliqueAddNode(conshdlrdata->tcliquegraph, j, 0 ) )
6103  return SCIP_NOMEMORY;
6104  }
6105 
6106  /* add edges */
6107  for (j = 0; j < nsos1vars; ++j)
6108  {
6109  int* succ;
6110  int nsucc;
6111  int succnode;
6112  int i;
6113 
6114  nsucc = SCIPdigraphGetNSuccessors(conflictgraph, j);
6115  succ = SCIPdigraphGetSuccessors(conflictgraph, j);
6116 
6117  for (i = 0; i < nsucc; ++i)
6118  {
6119  succnode = succ[i];
6120 
6121  if ( succnode > j && SCIPvarIsActive(SCIPnodeGetVarSOS1(conflictgraph, succnode)) )
6122  {
6123  if ( ! tcliqueAddEdge(conshdlrdata->tcliquegraph, j, succnode) )
6124  return SCIP_NOMEMORY;
6125  }
6126  }
6127  }
6128  if ( ! tcliqueFlush(conshdlrdata->tcliquegraph) )
6129  return SCIP_NOMEMORY;
6130 
6131 
6132  /* allocate clique data */
6133  SCIP_CALL( SCIPallocBlockMemory(scip, &conshdlrdata->tcliquedata) );
6134  tcliquedata = conshdlrdata->tcliquedata;
6135 
6136  /* initialize clique data */
6137  tcliquedata->scip = scip;
6138  tcliquedata->sol = NULL;
6139  tcliquedata->conshdlr = conshdlr;
6140  tcliquedata->conflictgraph = conflictgraph;
6141  tcliquedata->scaleval = 1000.0;
6142  tcliquedata->ncuts = 0;
6143  tcliquedata->nboundcuts = conshdlrdata->nboundcuts;
6144  tcliquedata->strthenboundcuts = conshdlrdata->strthenboundcuts;
6145  tcliquedata->maxboundcuts = conshdlrdata->maxboundcutsroot;
6146 
6147  return SCIP_OKAY;
6148 }
6149 
6150 
6151 /** update weights of tclique graph */
6152 static
6154  SCIP* scip, /**< SCIP pointer */
6155  SCIP_CONSHDLRDATA* conshdlrdata, /**< constraint handler data */
6156  TCLIQUE_DATA* tcliquedata, /**< tclique data */
6157  SCIP_DIGRAPH* conflictgraph, /**< conflict graph */
6158  SCIP_SOL* sol, /**< LP solution to be separated (or NULL) */
6159  int nsos1vars /**< number of SOS1 variables */
6160  )
6161 {
6162  SCIP_Real scaleval;
6163  int j;
6164 
6165  scaleval = tcliquedata->scaleval;
6166 
6167  for (j = 0; j < nsos1vars; ++j)
6168  {
6169  SCIP_Real solval;
6170  SCIP_Real bound;
6171  SCIP_VAR* var;
6172 
6173  var = SCIPnodeGetVarSOS1(conflictgraph, j);
6174  solval = SCIPgetSolVal(scip, sol, var);
6175 
6176  if ( SCIPisFeasPositive(scip, solval) )
6177  {
6178  if ( conshdlrdata->strthenboundcuts )
6179  bound = REALABS( nodeGetSolvalVarboundUbSOS1(scip, conflictgraph, sol, j) );
6180  else
6181  bound = REALABS( SCIPvarGetUbLocal(var) );
6182  }
6183  else if ( SCIPisFeasNegative(scip, solval) )
6184  {
6185  if ( conshdlrdata->strthenboundcuts )
6186  bound = REALABS( nodeGetSolvalVarboundLbSOS1(scip, conflictgraph, sol, j) );
6187  else
6188  bound = REALABS( SCIPvarGetLbLocal(var) );
6189  }
6190  else
6191  bound = 0.0;
6192 
6193  solval = REALABS( solval );
6194 
6195  if ( ! SCIPisFeasZero(scip, bound) && ! SCIPisInfinity(scip, bound) )
6196  {
6197  SCIP_Real nodeweight;
6198  nodeweight = REALABS( solval/bound ) * scaleval;/*lint !e414*/
6199  tcliqueChangeWeight(conshdlrdata->tcliquegraph, j, (int)nodeweight);
6200  }
6201  else
6202  {
6203  tcliqueChangeWeight(conshdlrdata->tcliquegraph, j, 0);
6204  }
6205  }
6206 
6207  return SCIP_OKAY;
6208 }
6209 
6210 
6211 /** adds bound cut(s) to separation storage */
6212 static
6214  SCIP* scip, /**< SCIP pointer */
6215  TCLIQUE_DATA* tcliquedata, /**< clique data */
6216  SCIP_ROW* rowlb, /**< row for lower bounds (or NULL) */
6217  SCIP_ROW* rowub, /**< row for upper bounds (or NULL) */
6218  SCIP_Bool* success, /**< pointer to store if bound cut was added */
6219  SCIP_Bool* cutoff /**< pointer to store if a cutoff occurred */
6220  )
6221 {
6222  assert( scip != NULL );
6223  assert( tcliquedata != NULL );
6224  assert( success != NULL);
6225  assert( cutoff != NULL );
6226 
6227  *success = FALSE;
6228  *cutoff = FALSE;
6229 
6230  /* add cut for lower bounds */
6231  if ( rowlb != NULL )
6232  {
6233  if ( ! SCIProwIsInLP(rowlb) && SCIPisCutEfficacious(scip, NULL, rowlb) )
6234  {
6235  SCIP_Bool infeasible;
6236 
6237  SCIP_CALL( SCIPaddCut(scip, NULL, rowlb, FALSE, &infeasible) );
6238  if ( infeasible )
6239  *cutoff = TRUE;
6240  SCIPdebug( SCIP_CALL( SCIPprintRow(scip, rowlb, NULL) ) );
6241  ++tcliquedata->nboundcuts;
6242  ++tcliquedata->ncuts;
6243  *success = TRUE;
6244  }
6245  }
6246 
6247  /* add cut for upper bounds */
6248  if ( rowub != NULL )
6249  {
6250  if ( ! SCIProwIsInLP(rowub) && SCIPisCutEfficacious(scip, NULL, rowub) )
6251  {
6252  SCIP_Bool infeasible;
6253 
6254  SCIP_CALL( SCIPaddCut(scip, NULL, rowub, FALSE, &infeasible) );
6255  if ( infeasible )
6256  *cutoff = TRUE;
6257  SCIPdebug( SCIP_CALL( SCIPprintRow(scip, rowub, NULL) ) );
6258  ++tcliquedata->nboundcuts;
6259  ++tcliquedata->ncuts;
6260  *success = TRUE;
6261  }
6262  }
6263 
6264  return SCIP_OKAY;
6265 }
6266 
6267 
6268 /** Generate bound constraint
6269  *
6270  * We generate the row corresponding to the following simple valid inequalities:
6271  * \f[
6272  * \frac{x_1}{u_1} + \ldots + \frac{x_n}{u_n} \leq 1\qquad\mbox{and}\qquad
6273  * \frac{x_1}{\ell_1} + \ldots + \frac{x_n}{\ell_1} \leq 1,
6274  * \f]
6275  * where \f$\ell_1, \ldots, \ell_n\f$ and \f$u_1, \ldots, u_n\f$ are the nonzero and finite lower and upper bounds of
6276  * the variables \f$x_1, \ldots, x_n\f$. If an upper bound < 0 or a lower bound > 0, the constraint itself is
6277  * redundant, so the cut is not applied (lower bounds > 0 and upper bounds < 0 are usually detected in presolving or
6278  * propagation). Infinite bounds and zero are skipped. Thus \f$\ell_1, \ldots, \ell_n\f$ are all negative, which
6279  * results in the \f$\leq\f$ inequality. In case of the presence of variable upper bounds, the bound inequality can
6280  * be further strengthened.
6281  *
6282  * Note that in fact, any mixture of nonzero finite lower and upper bounds would lead to a valid inequality as
6283  * above. However, usually either the lower or upper bound is nonzero. Thus, the above inequalities are the most
6284  * interesting.
6285  */
6286 static
6288  SCIP* scip, /**< SCIP pointer */
6289  SCIP_CONSHDLR* conshdlr, /**< constraint handler */
6290  SCIP_DIGRAPH* conflictgraph, /**< conflict graph */
6291  int* nodes, /**< conflict graph nodes for bound constraint */
6292  int nnodes, /**< number of conflict graph nodes for bound constraint */
6293  SCIP_Real rhs, /**< right hand side of bound constraint */
6294  SCIP_Bool local, /**< in any case produce a local cut (even if local bounds of variables are valid globally) */
6295  SCIP_Bool global, /**< in any case produce a global cut */
6296  SCIP_Bool strengthen, /**< whether trying to strengthen bound constraint */
6297  SCIP_Bool removable, /**< should the inequality be removed from the LP due to aging or cleanup? */
6298  const char* nameext, /**< part of name of bound constraints */
6299  SCIP_ROW** rowlb, /**< output: row for lower bounds (or NULL if not needed) */
6300  SCIP_ROW** rowub /**< output: row for upper bounds (or NULL if not needed) */
6301  )
6302 {
6303  char name[SCIP_MAXSTRLEN];
6304  SCIP_VAR* lbboundvar = NULL;
6305  SCIP_VAR* ubboundvar = NULL;
6306  SCIP_Bool locallbs;
6307  SCIP_Bool localubs;
6308  SCIP_VAR** vars;
6309  SCIP_Real* vals;
6310 
6311  assert( scip != NULL );
6312  assert( conshdlr != NULL );
6313  assert( conflictgraph != NULL );
6314  assert( ! local || ! global );
6315  assert( nodes != NULL );
6316 
6317  /* allocate buffer array */
6318  SCIP_CALL( SCIPallocBufferArray(scip, &vars, nnodes+1) );
6319  SCIP_CALL( SCIPallocBufferArray(scip, &vals, nnodes+1) );
6320 
6321  /* take care of upper bounds */
6322  if ( rowub != NULL )
6323  {
6324  SCIP_Bool useboundvar;
6325  int cnt = 0;
6326  int j;
6327 
6328  /* Loop through all variables. We check whether all bound variables (if existent) are equal; if this is the
6329  * case then the bound constraint can be strengthened */
6330  localubs = local;
6331  useboundvar = strengthen;
6332  for (j = 0; j < nnodes; ++j)
6333  {
6334  SCIP_NODEDATA* nodedata;
6335  SCIP_VAR* var;
6336  SCIP_Real val;
6337 
6338  nodedata = (SCIP_NODEDATA*)SCIPdigraphGetNodeData(conflictgraph, nodes[j]);
6339  assert( nodedata != NULL );
6340  var = nodedata->var;
6341  assert( var != NULL );
6342 
6343  /* if variable is not involved in a variable bound constraint */
6344  if ( ! useboundvar || nodedata->ubboundvar == NULL )
6345  {
6346  useboundvar = FALSE;
6347  if ( localubs )
6348  {
6349  assert( ! global );
6350  val = SCIPvarGetUbLocal(var);
6351  }
6352  else
6353  {
6354  val = SCIPvarGetUbGlobal(var);
6355  if ( ! global && ! SCIPisFeasEQ(scip, val, SCIPvarGetUbLocal(var)) )
6356  {
6357  localubs = TRUE;
6358  val = SCIPvarGetUbLocal(var);
6359  }
6360  }
6361  }
6362  else
6363  {
6364  /* in this case the cut is always valid globally */
6365 
6366  /* if we have a bound variable for the first time */
6367  if ( ubboundvar == NULL )
6368  {
6369  ubboundvar = nodedata->ubboundvar;
6370  val = nodedata->ubboundcoef;
6371  }
6372  /* else if the bound variable equals the stored bound variable */
6373  else if ( ubboundvar == nodedata->ubboundvar )
6374  val = nodedata->ubboundcoef;
6375  else /* else use bounds on the variables */
6376  {
6377  useboundvar = FALSE;
6378 
6379  /* restart 'for'-loop */
6380  j = -1;
6381  cnt = 0;
6382  continue;
6383  }
6384  }
6385 
6386  /* should not apply the cut if a variable is fixed to be negative -> constraint is redundant */
6387  if ( SCIPisNegative(scip, val) )
6388  break;
6389 
6390  /* store variable if relevant for bound inequality */
6391  if ( ! SCIPisInfinity(scip, val) && ! SCIPisZero(scip, val) )
6392  {
6393  vars[cnt] = var;
6394 
6395  /* if only two nodes then we scale the cut differently */
6396  if ( nnodes == 2 )
6397  vals[cnt++] = val;
6398  else
6399  vals[cnt++] = 1.0/val;
6400  }
6401  }
6402 
6403  /* if cut is meaningful */
6404  if ( j == nnodes && cnt >= 2 )/*lint !e850*/
6405  {
6406  /* if only two nodes then we scale the cut differently */
6407  if ( nnodes == 2 )
6408  {
6409  SCIP_Real save;
6410 
6411  save = vals[0];
6412  vals[0] = vals[1];
6413  vals[1] = save;
6414  rhs = rhs * vals[0] * vals[1];
6415  assert( (! useboundvar && cnt == 2 ) || (useboundvar && cnt == 3 ) );
6416  }
6417 
6418  if ( useboundvar )
6419  {
6420  /* add bound variable to array */
6421  vars[cnt] = ubboundvar;
6422  vals[cnt++] = -rhs;
6423  assert(ubboundvar != NULL );
6424 
6425  /* create upper bound inequality if at least two of the bounds are finite and nonzero */
6426  (void) SCIPsnprintf(name, SCIP_MAXSTRLEN, "sosub#%s", nameext);
6427  SCIP_CALL( SCIPcreateEmptyRowCons(scip, rowub, conshdlr, name, -SCIPinfinity(scip), 0.0, localubs, FALSE, removable) );
6428  SCIP_CALL( SCIPaddVarsToRow(scip, *rowub, cnt, vars, vals) );
6429  SCIPdebug( SCIP_CALL( SCIPprintRow(scip, *rowub, NULL) ) );
6430  }
6431  else
6432  {
6433  /* create upper bound inequality if at least two of the bounds are finite and nonzero */
6434  (void) SCIPsnprintf(name, SCIP_MAXSTRLEN, "sosub#%s", nameext);
6435  SCIP_CALL( SCIPcreateEmptyRowCons(scip, rowub, conshdlr, name, -SCIPinfinity(scip), rhs, localubs, FALSE, removable) );
6436  SCIP_CALL( SCIPaddVarsToRow(scip, *rowub, cnt, vars, vals) );
6437  SCIPdebug( SCIP_CALL( SCIPprintRow(scip, *rowub, NULL) ) );
6438  }
6439  }
6440  }
6441 
6442 
6443  /* take care of lower bounds */
6444  if ( rowlb != NULL )
6445  {
6446  SCIP_Bool useboundvar;
6447  int cnt;
6448  int j;
6449 
6450  /* loop through all variables. We check whether all bound variables (if existent) are equal; if this is the
6451  * case then the bound constraint can be strengthened */
6452  cnt = 0;
6453  locallbs = local;
6454  useboundvar = strengthen;
6455  for (j = 0; j < nnodes; ++j)
6456  {
6457  SCIP_NODEDATA* nodedata;
6458  SCIP_VAR* var;
6459  SCIP_Real val;
6460 
6461  nodedata = (SCIP_NODEDATA*)SCIPdigraphGetNodeData(conflictgraph, nodes[j]);
6462  assert( nodedata != NULL );
6463  var = nodedata->var;
6464  assert( var != NULL );
6465 
6466  /* if variable is not involved in a variable bound constraint */
6467  if ( ! useboundvar || nodedata->lbboundvar == NULL )
6468  {
6469  useboundvar = FALSE;
6470  if ( locallbs )
6471  {
6472  assert( ! global );
6473  val = SCIPvarGetLbLocal(var);
6474  }
6475  else
6476  {
6477  val = SCIPvarGetLbGlobal(var);
6478  if ( ! global && ! SCIPisFeasEQ(scip, val, SCIPvarGetLbLocal(var)) )
6479  {
6480  locallbs = TRUE;
6481  val = SCIPvarGetUbLocal(var);
6482  }
6483  }
6484  }
6485  else
6486  {
6487  /* in this case the cut is always valid globally */
6488 
6489  /* if we have a bound variable for the first time */
6490  if ( lbboundvar == NULL )
6491  {
6492  lbboundvar = nodedata->lbboundvar;
6493  val = nodedata->lbboundcoef;
6494  }
6495  /* else if the bound variable equals the stored bound variable */
6496  else if ( SCIPvarCompare(lbboundvar, nodedata->lbboundvar) == 0 )
6497  {
6498  val = nodedata->lbboundcoef;
6499  }
6500  else /* else use bounds on the variables */
6501  {
6502  useboundvar = FALSE;
6503 
6504  /* restart 'for'-loop */
6505  j = -1;
6506  cnt = 0;
6507  continue;
6508  }
6509  }
6510 
6511  /* should not apply the cut if a variable is fixed to be positive -> constraint is redundant */
6512  if ( SCIPisPositive(scip, val) )
6513  break;
6514 
6515  /* store variable if relevant for bound inequality */
6516  if ( ! SCIPisInfinity(scip, -val) && ! SCIPisZero(scip, val) )
6517  {
6518  vars[cnt] = var;
6519 
6520  /* if only two nodes then we scale the cut differently */
6521  if ( nnodes == 2 )
6522  vals[cnt++] = val;
6523  else
6524  vals[cnt++] = 1.0/val;
6525  }
6526  }
6527 
6528  /* if cut is meaningful */
6529  if ( j == nnodes && cnt >= 2 )/*lint !e850*/
6530  {
6531  /* if only two nodes then we scale the cut differently */
6532  if ( nnodes == 2 )
6533  {
6534  SCIP_Real save;
6535 
6536  save = vals[0];
6537  vals[0] = vals[1];
6538  vals[1] = save;
6539  rhs = rhs * vals[0] * vals[1];
6540  assert( (! useboundvar && cnt == 2 ) || (useboundvar && cnt == 3 ) );
6541  }
6542 
6543  if ( useboundvar )
6544  {
6545  /* add bound variable to array */
6546  vars[cnt] = lbboundvar;
6547  vals[cnt++] = -rhs;
6548  assert(lbboundvar != NULL );
6549 
6550  /* create upper bound inequality if at least two of the bounds are finite and nonzero */
6551  (void) SCIPsnprintf(name, SCIP_MAXSTRLEN, "soslb#%s", nameext);
6552  SCIP_CALL( SCIPcreateEmptyRowCons(scip, rowlb, conshdlr, name, -SCIPinfinity(scip), 0.0, locallbs, FALSE, TRUE) );
6553  SCIP_CALL( SCIPaddVarsToRow(scip, *rowlb, cnt, vars, vals) );
6554  SCIPdebug( SCIP_CALL( SCIPprintRow(scip, *rowlb, NULL) ) );
6555  }
6556  else
6557  {
6558  /* create upper bound inequality if at least two of the bounds are finite and nonzero */
6559  (void) SCIPsnprintf(name, SCIP_MAXSTRLEN, "soslb#%s", nameext);
6560  SCIP_CALL( SCIPcreateEmptyRowCons(scip, rowlb, conshdlr, name, -SCIPinfinity(scip), rhs, locallbs, FALSE, TRUE) );
6561  SCIP_CALL( SCIPaddVarsToRow(scip, *rowlb, cnt, vars, vals) );
6562  SCIPdebug( SCIP_CALL( SCIPprintRow(scip, *rowlb, NULL) ) );
6563  }
6564  }
6565  }
6566 
6567  /* free buffer array */
6568  SCIPfreeBufferArray(scip, &vals);
6569  SCIPfreeBufferArray(scip, &vars);
6570 
6571  return SCIP_OKAY;
6572 }
6573 
6574 
6575 /** generates bound cuts using a clique found by algorithm for maximum weight clique
6576  * and decides whether to stop generating cliques with the algorithm for maximum weight clique
6577  */
6578 static
6579 TCLIQUE_NEWSOL(tcliqueNewsolClique)
6580 {
6581  TCLIQUE_WEIGHT minweightinc;
6582 
6583  assert( acceptsol != NULL );
6584  assert( stopsolving != NULL );
6585  assert( tcliquedata != NULL );
6586 
6587  /* we don't accept the solution as new incumbent, because we want to find many violated clique inequalities */
6588  *acceptsol = FALSE;
6589  *stopsolving = FALSE;
6590 
6591  /* slightly increase the minimal weight for additional cliques */
6592  minweightinc = (cliqueweight - *minweight)/10;
6593  minweightinc = MAX(minweightinc, 1);
6594  *minweight += minweightinc;
6595 
6596  /* adds cut if weight of the clique is greater than 1 */
6597  if( cliqueweight > tcliquedata->scaleval )
6598  {
6599  SCIP* scip;
6600  SCIP_SOL* sol;
6601  SCIP_Real unscaledweight;
6602  SCIP_Real solval;
6603  SCIP_Real bound;
6604  SCIP_VAR* var;
6605  int node;
6606  int i;
6607 
6608  scip = tcliquedata->scip;
6609  sol = tcliquedata->sol;
6610  assert( scip != NULL );
6611 
6612  /* calculate the weight of the clique in unscaled fractional variable space */
6613  unscaledweight = 0.0;
6614  for( i = 0; i < ncliquenodes; i++ )
6615  {
6616  node = cliquenodes[i];
6617  var = SCIPnodeGetVarSOS1(tcliquedata->conflictgraph, node);
6618  solval = SCIPgetSolVal(scip, sol, var);
6619 
6620  if ( SCIPisFeasPositive(scip, solval) )
6621  {
6622  if ( tcliquedata->strthenboundcuts )
6623  bound = REALABS( nodeGetSolvalVarboundUbSOS1(scip, tcliquedata->conflictgraph, sol, node) );
6624  else
6625  bound = REALABS( SCIPvarGetUbLocal(var) );
6626  }
6627  else if ( SCIPisFeasNegative(scip, solval) )
6628  {
6629  if ( tcliquedata->strthenboundcuts )
6630  bound = REALABS( nodeGetSolvalVarboundLbSOS1(scip, tcliquedata->conflictgraph, sol, node) );
6631  else
6632  bound = REALABS( SCIPvarGetLbLocal(var) );
6633  }
6634  else
6635  bound = 0.0;
6636 
6637  solval = REALABS( solval );
6638 
6639  if ( ! SCIPisFeasZero(scip, bound) && ! SCIPisInfinity(scip, bound) )
6640  unscaledweight += REALABS( solval/bound );/*lint !e414*/
6641  }
6642 
6643  if ( SCIPisEfficacious(scip, unscaledweight - 1.0) )
6644  {
6645  char nameext[SCIP_MAXSTRLEN];
6646  SCIP_ROW* rowlb = NULL;
6647  SCIP_ROW* rowub = NULL;
6648  SCIP_Bool success;
6649  SCIP_Bool cutoff;
6650 
6651  /* generate bound inequalities for lower and upper bound case
6652  * NOTE: tests have shown that non-removable rows give the best results */
6653  (void) SCIPsnprintf(nameext, SCIP_MAXSTRLEN, "%d", tcliquedata->nboundcuts);
6654  if ( generateBoundInequalityFromSOS1Nodes(scip, tcliquedata->conshdlr, tcliquedata->conflictgraph,
6655  cliquenodes, ncliquenodes, 1.0, FALSE, FALSE, tcliquedata->strthenboundcuts, FALSE, nameext, &rowlb, &rowub) != SCIP_OKAY )
6656  {
6657  SCIPerrorMessage("Unexpected error in bound cut creation.\n");
6658  SCIPABORT();
6659  return; /*lint !e527*/
6660  }
6661 
6662  /* add bound cut(s) to separation storage if existent */
6663  if ( addBoundCutSepa(scip, tcliquedata, rowlb, rowub, &success, &cutoff) != SCIP_OKAY )
6664  {
6665  SCIPerrorMessage("Unexpected error in bound cut creation.\n");
6666  SCIPABORT();
6667  return; /*lint !e527*/
6668  }
6669 
6670  if ( rowlb != NULL )
6671  {
6672  if ( SCIPreleaseRow(scip, &rowlb) != SCIP_OKAY )
6673  {
6674  SCIPerrorMessage("Cannot release row,\n");
6675  SCIPABORT();
6676  return; /*lint !e527*/
6677  }
6678  }
6679  if ( rowub != NULL )
6680  {
6681  if ( SCIPreleaseRow(scip, &rowub) != SCIP_OKAY )
6682  {
6683  SCIPerrorMessage("Cannot release row,\n");
6684  SCIPABORT();
6685  return; /*lint !e527*/
6686  }
6687  }
6688 
6689  /* if at least one cut has been added */
6690  if ( success )
6691  {
6692  SCIPdebugMsg(scip, " -> found bound cut corresponding to clique (act=%g)\n", unscaledweight);
6693 
6694  /* if we found more than half the cuts we are allowed to generate, we accept the clique as new incumbent,
6695  * such that only more violated cuts are generated afterwards
6696  */
6697  if( tcliquedata->maxboundcuts >= 0 )
6698  {
6699  if ( tcliquedata->ncuts > tcliquedata->maxboundcuts/2 )
6700  *acceptsol = TRUE;
6701  if ( tcliquedata->ncuts >= tcliquedata->maxboundcuts )
6702  *stopsolving = TRUE;
6703  }
6704  }
6705  else
6706  *stopsolving = TRUE;
6707  }
6708  }
6709 }
6710 
6711 
6712 /** separate bound inequalities from conflict graph */
6713 static
6715  SCIP* scip, /**< SCIP pointer */
6716  SCIP_CONSHDLR* conshdlr, /**< constraint handler */
6717  SCIP_CONSHDLRDATA* conshdlrdata, /**< constraint handler data */
6718  SCIP_SOL* sol, /**< LP solution to be separated (or NULL) */
6719  int maxboundcuts, /**< maximal number of bound cuts separated per separation round (-1: no limit) */
6720  int* ngen, /**< pointer to store number of cuts generated */
6721  SCIP_Bool* cutoff /**< pointer whether a cutoff occurred */
6722  )
6723 {
6724  SCIP_DIGRAPH* conflictgraph;
6725  TCLIQUE_DATA* tcliquedata;
6726  TCLIQUE_WEIGHT cliqueweight;
6727  TCLIQUE_STATUS tcliquestatus;
6728  int nsos1vars;
6729 
6730  SCIP_Real scaleval = 1000.0; /* factor for scaling weights */
6731  int maxtreenodes = 10000; /* maximal number of nodes of b&b tree */
6732  int maxzeroextensions = 1000; /* maximal number of zero-valued variables extending the clique (-1: no limit) */
6733  int backtrackfreq = 1000; /* frequency for premature backtracking up to tree level 1 (0: no backtracking) */
6734  int ntreenodes;
6735  int* cliquenodes;
6736  int ncliquenodes;
6737 
6738  assert( scip != NULL );
6739  assert( conshdlr != NULL );
6740  assert( conshdlrdata != NULL );
6741  assert( ngen != NULL );
6742 
6743  /* get conflict graph */
6744  conflictgraph = SCIPgetConflictgraphSOS1(conshdlr);
6745  assert( conflictgraph != NULL );
6746 
6747  /* get number of SOS1 variables */
6748  nsos1vars = SCIPgetNSOS1Vars(conshdlr);
6749 
6750  /* initialize data of tclique graph*/
6751  tcliquedata = conshdlrdata->tcliquedata;
6752  tcliquedata->scaleval = scaleval;
6753  tcliquedata->maxboundcuts = maxboundcuts;
6754  tcliquedata->sol = sol;
6755  tcliquedata->ncuts = 0;
6756  tcliquedata->cutoff = FALSE;
6757 
6758  /* update the weights of the tclique graph */
6759  SCIP_CALL( updateWeightsTCliquegraph(scip, conshdlrdata, tcliquedata, conflictgraph, sol, nsos1vars) );
6760 
6761  /* allocate buffer array */
6762  SCIP_CALL( SCIPallocBufferArray(scip, &cliquenodes, nsos1vars) );
6763 
6764  /* start algorithm to find maximum weight cliques and use them to generate bound cuts */
6765  tcliqueMaxClique(tcliqueGetNNodes, tcliqueGetWeights, tcliqueIsEdge, tcliqueSelectAdjnodes,
6766  conshdlrdata->tcliquegraph, tcliqueNewsolClique, tcliquedata,
6767  cliquenodes, &ncliquenodes, &cliqueweight, (int)scaleval-1, (int)scaleval+1,
6768  maxtreenodes, backtrackfreq, maxzeroextensions, -1, &ntreenodes, &tcliquestatus);
6769 
6770  /* free buffer array */
6771  SCIPfreeBufferArray(scip, &cliquenodes);
6772 
6773  /* get number of cuts of current separation round */
6774  *ngen = tcliquedata->ncuts;
6775 
6776  /* store whether a cutoff occurred */
6777  *cutoff = tcliquedata->cutoff;
6778 
6779  /* update number of bound cuts in separator data */
6780  conshdlrdata->nboundcuts = tcliquedata->nboundcuts;
6781 
6782  return SCIP_OKAY;
6783 }
6784 
6785 
6786 /** Generate a bound constraint from the variables of an SOS1 constraint (see generateBoundInequalityFromSOS1Nodes() for more information) */
6787 static
6789  SCIP* scip, /**< SCIP pointer */
6790  SCIP_CONSHDLR* conshdlr, /**< constraint handler */
6791  SCIP_CONS* cons, /**< SOS1 constraint */
6792  SCIP_Bool local, /**< in any case produce a local cut (even if local bounds of variables are valid globally) */
6793  SCIP_Bool global, /**< in any case produce a global cut */
6794  SCIP_Bool strengthen, /**< whether trying to strengthen bound constraint */
6795  SCIP_Bool removable, /**< should the inequality be removed from the LP due to aging or cleanup? */
6796  SCIP_ROW** rowlb, /**< output: row for lower bounds (or NULL if not needed) */
6797  SCIP_ROW** rowub /**< output: row for upper bounds (or NULL if not needed) */
6798  )
6799 {
6800  SCIP_CONSHDLRDATA* conshdlrdata;
6801  SCIP_CONSDATA* consdata;
6802  int* nodes;
6803  int nvars;
6804  int cnt = 0;
6805  int j;
6806 
6807  assert( scip != NULL );
6808  assert( conshdlr != NULL );
6809  assert( cons != NULL );
6810 
6811  /* get constraint data */
6812  consdata = SCIPconsGetData(cons);
6813  assert( consdata != NULL );
6814  assert( consdata->vars != NULL );
6815  nvars = consdata->nvars;
6816 
6817  /* get constraint handler data */
6818  conshdlrdata = SCIPconshdlrGetData(conshdlr);
6819  assert( conshdlrdata != NULL );
6820  assert( strcmp(SCIPconshdlrGetName(conshdlr), CONSHDLR_NAME) == 0 );
6821 
6822  /* allocate buffer array */
6823  SCIP_CALL( SCIPallocBufferArray(scip, &nodes, nvars) );
6824 
6825  /* get nodes in the conflict graph */
6826  for (j = 0; j < nvars; ++j)
6827  {
6828  if ( SCIPisFeasNegative(scip, SCIPvarGetLbLocal(consdata->vars[j])) || SCIPisFeasPositive(scip, SCIPvarGetUbLocal(consdata->vars[j])) )
6829  {
6830  assert( varGetNodeSOS1(conshdlrdata, consdata->vars[j]) >= 0 );
6831  nodes[cnt++] = varGetNodeSOS1(conshdlrdata, consdata->vars[j]);
6832  }
6833  }
6834 
6835  /* generate bound constraint from conflict graph nodes */
6836  if ( cnt > 0 )
6837  {
6838  SCIP_CALL( generateBoundInequalityFromSOS1Nodes(scip, conshdlr, conshdlrdata->conflictgraph, nodes, cnt, 1.0, local, global,
6839  strengthen, removable, SCIPconsGetName(cons), rowlb, rowub) );
6840  }
6841 
6842  /* free buffer array */
6843  SCIPfreeBufferArray(scip, &nodes);
6844 
6845  return SCIP_OKAY;
6846 }
6847 
6848 
6849 /** initialize or separate bound inequalities from SOS1 constraints */
6850 static
6852  SCIP* scip, /**< SCIP pointer */
6853  SCIP_CONSHDLR* conshdlr, /**< constraint handler */
6854  SCIP_CONSHDLRDATA* conshdlrdata, /**< constraint handler data */
6855  SCIP_CONS** conss, /**< SOS1 constraints */
6856  int nconss, /**< number of SOS1 constraints */
6857  SCIP_SOL* sol, /**< LP solution to be separated (or NULL) */
6858  SCIP_Bool solvedinitlp, /**< TRUE if initial LP relaxation at a node is solved */
6859  int maxboundcuts, /**< maximal number of bound cuts separated per separation round (-1: no limit) */
6860  int* ngen, /**< pointer to store number of cuts generated (or NULL) */
6861  SCIP_Bool* cutoff /**< pointer to store whether a cutoff occurred */
6862  )
6863 {
6864  int cnt = 0;
6865  int c;
6866 
6867  assert( scip != NULL );
6868  assert( conshdlrdata != NULL );
6869  assert( conss != NULL );
6870 
6871  *cutoff = FALSE;
6872 
6873  for (c = 0; c < nconss; ++c)
6874  {
6875  SCIP_CONSDATA* consdata;
6876  SCIP_ROW* rowub = NULL;
6877  SCIP_ROW* rowlb = NULL;
6878  SCIP_Bool release = FALSE;
6879 
6880  assert( conss != NULL );
6881  assert( conss[c] != NULL );
6882  consdata = SCIPconsGetData(conss[c]);
6883  assert( consdata != NULL );
6884 
6885  if ( solvedinitlp )
6886  {
6887  SCIPdebugMsg(scip, "Separating inequalities for SOS1 constraint <%s>.\n", SCIPconsGetName(conss[c]) );
6888  }
6889  else
6890  {
6891  SCIPdebugMsg(scip, "Checking for initial rows for SOS1 constraint <%s>.\n", SCIPconsGetName(conss[c]) );
6892  }
6893 
6894  /* in case that the SOS1 constraint is local, we always generate new rows - the former rows might be invalid;
6895  * otherwise if the SOS1 constraint is global, we only generate rows if not yet done */
6896  if ( consdata->local )
6897  {
6898  SCIP_CALL( generateBoundInequalityFromSOS1Cons(scip, conshdlr, conss[c], TRUE, FALSE, TRUE, FALSE, &rowlb, &rowub) );
6899  release = TRUE;
6900  }
6901  else
6902  {
6903  if ( consdata->rowub == NULL || consdata->rowlb == NULL )
6904  {
6905  SCIP_CALL( generateBoundInequalityFromSOS1Cons(scip, conshdlr, conss[c], FALSE, TRUE, TRUE, FALSE,
6906  (consdata->rowlb == NULL) ? &consdata->rowlb : NULL,
6907  (consdata->rowub == NULL) ? &consdata->rowub : NULL) ); /*lint !e826*/
6908  }
6909  rowub = consdata->rowub;
6910  rowlb = consdata->rowlb;
6911  }
6912 
6913  /* put corresponding rows into LP */
6914  if ( rowub != NULL && ! SCIProwIsInLP(rowub) && ( solvedinitlp || SCIPisCutEfficacious(scip, sol, rowub) ) )
6915  {
6916  SCIP_CALL( SCIPaddCut(scip, NULL, rowub, FALSE, cutoff) );
6917  SCIPdebug( SCIP_CALL( SCIPprintRow(scip, rowub, NULL) ) );
6918 
6919  if ( solvedinitlp )
6920  {
6921  SCIP_CALL( SCIPresetConsAge(scip, conss[c]) );
6922  }
6923  ++cnt;
6924  }
6925 
6926  if ( ! (*cutoff) && rowlb != NULL && ! SCIProwIsInLP(rowlb) && ( solvedinitlp || SCIPisCutEfficacious(scip, sol, rowlb) ) )
6927  {
6928  SCIP_CALL( SCIPaddCut(scip, NULL, rowlb, FALSE, cutoff) );
6929  SCIPdebug( SCIP_CALL( SCIPprintRow(scip, rowlb, NULL) ) );
6930 
6931  if ( solvedinitlp )
6932  {
6933  SCIP_CALL( SCIPresetConsAge(scip, conss[c]) );
6934  }
6935  ++cnt;
6936  }
6937 
6938  /* release rows if they are local */
6939  if ( release )
6940  {
6941  if ( rowlb != NULL )
6942  {
6943  SCIP_CALL( SCIPreleaseRow(scip, &rowlb) );
6944  }
6945  if ( rowub != NULL )
6946  {
6947  SCIP_CALL( SCIPreleaseRow(scip, &rowub) );
6948  }
6949  }
6950 
6951  if ( *cutoff || ( maxboundcuts >= 0 && cnt >= maxboundcuts ) )
6952  break;
6953  }
6954 
6955  /* store number of generated cuts */
6956  if ( ngen != NULL )
6957  *ngen = cnt;
6958 
6959  return SCIP_OKAY;
6960 }
6961 
6962 
6963 /** separate implied bound cuts */
6964 static
6966  SCIP* scip, /**< SCIP pointer */
6967  SCIP_CONSHDLR* conshdlr, /**< constraint handler */
6968  SCIP_CONSHDLRDATA* conshdlrdata, /**< constraint handler data */
6969  SCIP_SOL* sol, /**< LP solution to be separated (or NULL) */
6970  int maxcuts, /**< maximal number of implied bound cuts separated per separation round (-1: no limit) */
6971  int* ngen, /**< pointer to store number of cuts generated */
6972  SCIP_Bool* cutoff /**< pointer whether a cutoff occurred */
6973  )
6974 {
6975  SCIP_DIGRAPH* implgraph;
6976  SCIP_Bool genbreak;
6977  int nimplnodes;
6978  int i;
6979 
6980  assert( scip != NULL);
6981  assert( conshdlrdata != NULL);
6982  assert( conshdlr != NULL);
6983  assert( ngen != NULL);
6984  assert( cutoff != NULL);
6985 
6986  *cutoff = FALSE;
6987  *ngen = 0;
6988 
6989  /* return if conflict graph is not available */
6990  if ( conshdlrdata->conflictgraph == NULL )
6991  return SCIP_OKAY;
6992 
6993  /* get implication graph */
6994  implgraph = conshdlrdata->implgraph;
6995 
6996  /* create implication graph if not done already */
6997  if ( implgraph == NULL )
6998  {
6999  int nchbds;
7000 
7001  if ( SCIPgetDepth(scip) == 0 )
7002  {
7003  SCIP_Bool success;
7004  SCIP_CALL( initImplGraphSOS1(scip, conshdlrdata, conshdlrdata->conflictgraph, conshdlrdata->nsos1vars, conshdlrdata->maxtightenbds, &nchbds, cutoff, &success) );
7005  if ( *cutoff || ! success )
7006  return SCIP_OKAY;
7007  implgraph = conshdlrdata->implgraph;
7008  }
7009  else
7010  {
7011  return SCIP_OKAY;
7012  }
7013  }
7014  nimplnodes = conshdlrdata->nimplnodes;
7015  assert( implgraph != NULL );
7016  assert( nimplnodes > 0);
7017 
7018  /* exit if implication graph has no arcs between its nodes */
7019  if ( SCIPdigraphGetNArcs(implgraph) < 1 )
7020  return SCIP_OKAY;
7021 
7022  /* loop through all nodes of the implication graph */
7023  genbreak = FALSE;
7024  for (i = 0; i < nimplnodes && ! genbreak; ++i)
7025  {
7026  SCIP_SUCCDATA** succdatas;
7027  SCIP_NODEDATA* nodedata;
7028  SCIP_Real solval;
7029  SCIP_VAR* var;
7030  int* succ;
7031  int nsucc;
7032  int s;
7033 
7034  succdatas = (SCIP_SUCCDATA**) SCIPdigraphGetSuccessorsData(implgraph, i);
7035  nodedata = (SCIP_NODEDATA*) SCIPdigraphGetNodeData(implgraph, i);
7036  assert( nodedata != NULL );
7037  var = nodedata->var;
7038  assert( var != NULL );
7039  solval = SCIPgetSolVal(scip, sol, var);
7040 
7041  if ( succdatas != NULL && ! SCIPisFeasZero(scip, solval) )
7042  {
7043  succ = SCIPdigraphGetSuccessors(implgraph, i);
7044  nsucc = SCIPdigraphGetNSuccessors(implgraph, i);
7045 
7046  for (s = 0; s < nsucc && ! genbreak; ++s)
7047  {
7048  SCIP_SUCCDATA* succdata;
7049  SCIP_VAR* succvar;
7050  SCIP_ROW* cut = NULL;
7051  SCIP_Bool bound1lower;
7052  SCIP_Bool bound2lower;
7053  SCIP_Real solvalsucc;
7054  SCIP_Real bound1;
7055  SCIP_Real bound2;
7056  SCIP_Real lhsrhs;
7057  SCIP_Real impl;
7058  int k;
7059 
7060  nodedata = (SCIP_NODEDATA*) SCIPdigraphGetNodeData(implgraph, succ[s]);
7061  succdata = succdatas[s];
7062  assert( nodedata != NULL && succdata != NULL && nodedata->var != NULL );
7063  succvar = nodedata->var;
7064  solvalsucc = SCIPgetSolVal(scip, sol, succvar);
7065 
7066  /* determine coefficients for bound inequality */
7067  assert( ! SCIPisFeasZero(scip, solval) );
7068  if ( SCIPisFeasNegative(scip, solval) )
7069  {
7070  bound1lower = TRUE;
7071  bound1 = SCIPvarGetLbGlobal(var);
7072  }
7073  else
7074  {
7075  bound1lower = FALSE;
7076  bound1 = SCIPvarGetUbGlobal(var);
7077  }
7078 
7079  /* handle lower bound upper bound implications */
7080  for (k = 0; k < 2; ++k)
7081  {
7082  if ( k == 0 )
7083  {
7084  SCIP_Real lbsucc;
7085  lbsucc = SCIPvarGetLbGlobal(succvar);
7086  if ( SCIPisFeasLT(scip, lbsucc, succdata->lbimpl) )
7087  {
7088  impl = succdata->lbimpl;
7089  bound2 = lbsucc;
7090  }
7091  else
7092  continue;
7093  }
7094  else
7095  {
7096  SCIP_Real ubsucc;
7097  ubsucc = SCIPvarGetUbGlobal(succvar);
7098  if ( SCIPisFeasGT(scip, ubsucc, succdata->ubimpl) )
7099  {
7100  impl = succdata->ubimpl;
7101  bound2 = ubsucc;
7102  }
7103  else
7104  continue;
7105  }
7106 
7107  if ( SCIPisInfinity(scip, REALABS(bound1)) || SCIPisInfinity(scip, REALABS(bound2)) )
7108  continue;
7109  assert( ! SCIPisInfinity(scip, REALABS(impl)) );
7110 
7111  if ( SCIPisFeasNegative(scip, bound2-impl) )
7112  bound2lower = TRUE;
7113  else
7114  bound2lower = FALSE;
7115 
7116  /* determine left/right hand side of bound inequality */
7117  lhsrhs = bound1 * bound2;
7118 
7119  /* create cut */
7120  if ( bound1lower == bound2lower )
7121  {
7122  if ( SCIPisFeasGT(scip, solval * (bound2-impl) + solvalsucc * bound1, lhsrhs) )
7123  {
7124  SCIP_CALL( SCIPcreateEmptyRowCons(scip, &cut, conshdlr, "", -SCIPinfinity(scip), lhsrhs, FALSE, FALSE, TRUE) );
7125  }
7126  else
7127  continue;
7128  }
7129  else
7130  {
7131  if ( SCIPisFeasLT(scip, solval * (bound2-impl) + solvalsucc * bound1, lhsrhs) )
7132  {
7133  SCIP_CALL( SCIPcreateEmptyRowCons(scip, &cut, conshdlr, "", lhsrhs, SCIPinfinity(scip), FALSE, FALSE, TRUE) );
7134  }
7135  else
7136  continue;
7137  }
7138 
7139  /* add coefficients of variables */
7140  SCIP_CALL( SCIPcacheRowExtensions(scip, cut) );
7141  SCIP_CALL( SCIPaddVarToRow(scip, cut, var, bound2-impl) );
7142  SCIP_CALL( SCIPaddVarToRow(scip, cut, succvar, bound1) );
7143  SCIP_CALL( SCIPflushRowExtensions(scip, cut) );
7144 
7145  /* add cut if useful */
7146  if ( ! SCIProwIsInLP(cut) && SCIPisCutEfficacious(scip, NULL, cut) )
7147  {
7148  SCIP_Bool infeasible;
7149  SCIP_CALL( SCIPaddCut(scip, NULL, cut, FALSE, &infeasible) );
7150  if ( infeasible )
7151  {
7152  genbreak = TRUE;
7153  *cutoff = TRUE;
7154  break;
7155  }
7156  SCIPdebug( SCIP_CALL( SCIPprintRow(scip, cut, NULL) ) );
7157 #ifdef SCIP_DEBUG
7158  if ( k == 0 )
7159  {
7160  SCIPdebugMsg(scip, "added cut for implication %s != 0 -> %s >= %f \n", SCIPvarGetName(var), SCIPvarGetName(succvar), succdata->lbimpl);
7161  }
7162  else
7163  {
7164  SCIPdebugMsg(scip, "added cut for implication %s != 0 -> %s <= %f \n", SCIPvarGetName(var), SCIPvarGetName(succvar), succdata->ubimpl);
7165  }
7166 #endif
7167 
7168  ++(*ngen);
7169  }
7170 
7171  if ( maxcuts >= 0 && *ngen > maxcuts )
7172  {
7173  genbreak = TRUE;
7174  break;
7175  }
7176  }
7177 
7178  if ( cut != NULL )
7179  SCIP_CALL( SCIPreleaseRow(scip, &cut) );
7180  }
7181  }
7182  }
7183 
7184  return SCIP_OKAY;
7185 }
7186 
7187 
7188 /** separates SOS1 constraints for arbitrary solutions */
7189 static
7191  SCIP* scip, /**< SCIP pointer */
7192  SCIP_CONSHDLR* conshdlr, /**< constraint handler */
7193  SCIP_SOL* sol, /**< solution to be separated (or NULL) */
7194  int nconss, /**< number of constraints */
7195  SCIP_CONS** conss, /**< SOS1 constraints */
7196  SCIP_RESULT* result /**< result */
7197  )
7198 {
7199  SCIP_CONSHDLRDATA* conshdlrdata;
7200  int depth;
7201 
7202  assert( scip != NULL );
7203  assert( conshdlr != NULL );
7204  assert( conss != NULL );
7205  assert( result != NULL );
7206 
7207  *result = SCIP_DIDNOTRUN;
7208 
7209  if ( nconss == 0 )
7210  return SCIP_OKAY;
7211 
7212  /* only separate cuts if we are not close to terminating */
7213  if( SCIPisStopped(scip) )
7214  return SCIP_OKAY;
7215 
7216  *result = SCIP_DIDNOTFIND;
7217 
7218  /* get constraint handler data */
7219  conshdlrdata = SCIPconshdlrGetData(conshdlr);
7220  assert( conshdlrdata != NULL );
7221 
7222  /* get node depth */
7223  depth = SCIPgetDepth(scip);
7224 
7225 
7226  /* separate bound (clique) inequalities */
7227  if ( conshdlrdata->boundcutsfreq >= 0 && ( (conshdlrdata->boundcutsfreq == 0 && depth == 0) || (conshdlrdata->boundcutsfreq > 0 && depth % conshdlrdata->boundcutsfreq == 0)) )
7228  {
7229  int maxboundcuts;
7230  int ngen = 0;
7231 
7232  /* determine maximal number of cuts*/
7233  if ( depth == 0 )
7234  maxboundcuts = conshdlrdata->maxboundcutsroot;
7235  else
7236  maxboundcuts = conshdlrdata->maxboundcuts;
7237 
7238  if ( maxboundcuts >= 1 )
7239  {
7240  /* separate bound inequalities from SOS1 constraints */
7241  if( conshdlrdata->boundcutsfromsos1 || conshdlrdata->switchcutsfromsos1 )
7242  {
7243  SCIP_Bool cutoff;
7244 
7245  SCIP_CALL( initsepaBoundInequalityFromSOS1Cons(scip, conshdlr, conshdlrdata, conss, nconss, sol, TRUE, maxboundcuts, &ngen, &cutoff) );
7246  if ( cutoff )
7247  {
7248  *result = SCIP_CUTOFF;
7249  return SCIP_OKAY;
7250  }
7251  }
7252 
7253  /* separate bound inequalities from the conflict graph */
7254  if( conshdlrdata->boundcutsfromgraph && ! conshdlrdata->switchcutsfromsos1 )
7255  {
7256  SCIP_Bool cutoff;
7257  SCIP_CALL( sepaBoundInequalitiesFromGraph(scip, conshdlr, conshdlrdata, sol, maxboundcuts, &ngen, &cutoff) );
7258  if ( cutoff )
7259  {
7260  *result = SCIP_CUTOFF;
7261  return SCIP_OKAY;
7262  }
7263  }
7264  }
7265 
7266  /* evaluate results */
7267  if ( ngen > 0 )
7268  *result = SCIP_SEPARATED;
7269  SCIPdebugMsg(scip, "Separated %d bound (clique) inequalities.\n", ngen);
7270  }
7271 
7272 
7273  /* separate implied bound inequalities */
7274  if ( conshdlrdata->implcutsfreq >= 0 && ( (conshdlrdata->implcutsfreq == 0 && depth == 0) || (conshdlrdata->implcutsfreq > 0 && depth % conshdlrdata->implcutsfreq == 0)) )
7275  {
7276  int maximplcuts;
7277  int ngen = 0;
7278 
7279  /* determine maximal number of cuts*/
7280  if ( depth == 0 )
7281  maximplcuts = conshdlrdata->maximplcutsroot;
7282  else
7283  maximplcuts = conshdlrdata->maximplcuts;
7284 
7285  /* call separator for implied bound cuts */
7286  if ( maximplcuts >= 1 )
7287  {
7288  SCIP_Bool cutoff;
7289  SCIP_CALL( sepaImplBoundCutsSOS1(scip, conshdlr, conshdlrdata, sol, maximplcuts, &ngen, &cutoff) );
7290  if ( cutoff )
7291  {
7292  *result = SCIP_CUTOFF;
7293  return SCIP_OKAY;
7294  }
7295  }
7296 
7297  /* evaluate results */
7298  if ( ngen > 0 )
7299  *result = SCIP_SEPARATED;
7300  SCIPdebugMsg(scip, "Separated %d implied bound inequalities.\n", ngen);
7301  }
7302 
7303  return SCIP_OKAY;
7304 }
7305 
7306 
7307 /* -------------------------- heuristic methods --------------------------------*/
7308 
7309 /** gets weights determining an order of the variables in a heuristic for the maximum weighted independent set problem */
7310 static
7312  SCIP* scip, /**< SCIP pointer */
7313  SCIP_SOL* sol, /**< primal solution or NULL for current LP solution */
7314  SCIP_DIGRAPH* conflictgraph, /**< conflict graph */
7315  int nsos1vars, /**< number of SOS1 variables */
7316  SCIP_Bool* indicatorzero, /**< vector that indicates which variables are currently fixed to zero */
7317  SCIP_Real* weights /**< pointer to store weights determining the order of the variables (length = nsos1vars) */
7318  )
7319 {
7320  SCIP_VAR* var;
7321  SCIP_Real val;
7322  SCIP_Real sum;
7323  int nviols;
7324  int* succ;
7325  int nsucc;
7326  int i;
7327  int j;
7328 
7329  assert( scip != NULL );
7330  assert( conflictgraph != NULL );
7331  assert( indicatorzero != NULL );
7332  assert( weights != NULL );
7333 
7334  for (i = 0; i < nsos1vars; ++i)
7335  {
7336  nsucc = SCIPdigraphGetNSuccessors(conflictgraph, i);
7337 
7338  if( nsucc == 0 || indicatorzero[i] )
7339  weights[i] = 0.0;
7340  else
7341  {
7342  var = SCIPnodeGetVarSOS1(conflictgraph, i);
7343  val = REALABS( SCIPgetSolVal(scip, sol, var) );
7344  if ( SCIPisFeasZero(scip, val) )
7345  weights[i] = 0.0;
7346  else
7347  {
7348  succ = SCIPdigraphGetSuccessors(conflictgraph, i);
7349 
7350  nviols = 0;
7351  sum = 0.0;
7352  for (j = 0; j < nsucc; ++j)
7353  {
7354  SCIP_Real valsucc;
7355 
7356  valsucc = REALABS( SCIPgetSolVal(scip, sol, SCIPnodeGetVarSOS1(conflictgraph, succ[j])) );
7357  if( ! SCIPisFeasZero(scip, valsucc) )
7358  {
7359  sum += MIN(10E05, valsucc);
7360  ++nviols;
7361  }
7362  }
7363 
7364  if ( nviols == 0 )
7365  weights[i] = 0.0;
7366  else
7367  {
7368  assert( SCIPisFeasPositive(scip, sum * (SCIP_Real)nviols));
7369  val = MIN(1e6, val);
7370  weights[i] = ( val + SCIPsumepsilon(scip) ) / ( sum * (SCIP_Real)nviols + SCIPsumepsilon(scip) );
7371  }
7372  }
7373  }
7374  }
7375 
7376  return SCIP_OKAY;
7377 }
7378 
7379 
7380 /* marks neighbors of a given node as not a member of the maximal independent set */
7381 static
7383  SCIP* scip, /**< SCIP pointer */
7384  SCIP_CONSHDLR* conshdlr, /**< SOS1 constraint handler */
7385  SCIP_DIGRAPH* conflictgraph, /**< conflict graph */
7386  int node, /**< node of the conflict graph */
7387  SCIP_Bool* mark, /**< indicator vector of processed nodes */
7388  SCIP_Bool* indset, /**< indicator vector of current independent */
7389  int* cnt, /**< pointer to store number of marked nodes */
7390  SCIP_Bool* cutoff /**< pointer to store whether operation is infeasible */
7391  )
7392 {
7393  int nsucc;
7394  int* succ;
7395  int j;
7396 
7397  assert( scip != NULL );
7398  assert( conflictgraph != NULL );
7399  assert( mark != NULL );
7400  assert( indset != NULL );
7401  assert( cutoff != NULL );
7402  assert( cnt != NULL );
7403 
7404  *cutoff = FALSE;
7405 
7406  nsucc = SCIPdigraphGetNSuccessors(conflictgraph, node);
7407  succ = SCIPdigraphGetSuccessors(conflictgraph, node);
7408 
7409  /* for all successors */
7410  for (j = 0; j < nsucc && !(*cutoff); ++j)
7411  {
7412  int succj;
7413 
7414  succj = succ[j];
7415  assert( indset[succj] == 0 );
7416  if( ! mark[succj] )
7417  {
7418  SCIP_VARSTATUS varstatus;
7419  SCIP_VAR* var;
7420 
7421  /* mark node as processed */
7422  mark[succj] = TRUE;
7423  ++(*cnt);
7424 
7425  /* get variable and variable status corresponding to successor node */
7426  var = SCIPnodeGetVarSOS1(conflictgraph, succj);
7427  varstatus = SCIPvarGetStatus(var);
7428 
7429  /* if variable is aggregated */
7430  if ( varstatus == SCIP_VARSTATUS_AGGREGATED )
7431  {
7432  int aggrnode;
7433 
7434  aggrnode = SCIPvarGetNodeSOS1(conshdlr, SCIPvarGetAggrVar(var));
7435 
7436  /* if aggregated variable is an SOS1 variable */
7437  if ( aggrnode >= 0 )
7438  {
7439  /* if aggregated variable is implied to be zero */
7440  if ( SCIPisFeasZero(scip, SCIPvarGetAggrConstant(var)) )
7441  {
7442  if ( ! mark[aggrnode] )
7443  {
7444  mark[aggrnode] = TRUE;
7445  ++(*cnt);
7446  }
7447  else if ( indset[aggrnode] == 1 )
7448  {
7449  *cutoff = TRUE;
7450  return SCIP_OKAY;
7451  }
7452  }
7453  else
7454  {
7455  /* if aggregated variable is not already a member of the maximal independent set */
7456  if ( indset[aggrnode] == 0 )
7457  {
7458  /* if variable is already marked */
7459  if ( mark[aggrnode] )
7460  {
7461  *cutoff = TRUE;
7462  return SCIP_OKAY;
7463  }
7464  else
7465  {
7466  indset[aggrnode] = 1;
7467  mark[aggrnode] = TRUE;
7468  ++(*cnt);
7469  }
7470 
7471  /* mark neighbors of aggregated variable */
7472  SCIP_CALL( markNeighborsMWISHeuristic(scip, conshdlr, conflictgraph, aggrnode, mark, indset, cnt, cutoff) );
7473  }
7474  }
7475  }
7476  }
7477  else if ( varstatus == SCIP_VARSTATUS_NEGATED )
7478  {
7479  int negnode;
7480 
7481  negnode = SCIPvarGetNodeSOS1(conshdlr, SCIPvarGetNegationVar(var));
7482 
7483  /* if negated variable is an SOS1 variable */
7484  if ( negnode >= 0 )
7485  {
7486  if ( SCIPisFeasZero(scip, SCIPvarGetNegationConstant(var) ) )
7487  {
7488  if ( indset[negnode] == 1 )
7489  {
7490  *cutoff = TRUE;
7491  return SCIP_OKAY;
7492  }
7493  else if ( ! mark[negnode] )
7494  {
7495  mark[negnode] = TRUE;
7496  ++(*cnt);
7497  }
7498  }
7499  }
7500  }
7501  }
7502  }
7503 
7504  return SCIP_OKAY;
7505 }
7506 
7507 
7508 /** calls greedy algorithm for the maximum weighted independent set problem (MWIS)
7509  *
7510  * We compute a feasible solution to
7511  * \f[
7512  * \begin{array}{ll}
7513  * \min\limits_{z} & {x^*}^T z \\
7514  * & z_i + z_j \leq 1, \qquad (i,j)\in E \\
7515  * & z_i \in \{0,1\}, \qquad\quad i\in V
7516  * \end{array}
7517  * \f]
7518  * by the algorithm GGWMIN of Shuichi Sakai, Mitsunori Togasaki and Koichi Yamazaki in "A note on greedy algorithms for the
7519  * maximum weighted independent set problem", Discrete Applied Mathematics. Here \f$x^*\f$ denotes the current LP
7520  * relaxation solution. Note that the solution of the MWIS is the indicator vector of an independent set.
7521  */
7522 static
7524  SCIP* scip, /**< SCIP pointer */
7525  SCIP_SOL* sol, /**< primal solution or NULL for current LP solution */
7526  SCIP_CONSHDLR* conshdlr, /**< SOS1 constraint handler */
7527  SCIP_DIGRAPH* conflictgraph, /**< conflict graph */
7528  int nsos1vars, /**< number of SOS1 variables */
7529  SCIP_Bool* indicatorzero, /**< vector that indicates which variables are currently fixed to zero */
7530  SCIP_Bool* indset /**< pointer to store indicator vector of an independent set */
7531  )
7532 {
7533  SCIP_Bool* mark = NULL;
7534  SCIP_Real* weights = NULL;
7535  int* indscipvars = NULL;
7536  int ind;
7537  int nsucc;
7538  int i;
7539  int k;
7540 
7541  assert( scip != NULL );
7542  assert( conflictgraph != NULL );
7543  assert( indicatorzero != NULL );
7544  assert( indset != NULL );
7545 
7546  /* allocate buffer arrays */
7547  SCIP_CALL( SCIPallocBufferArray(scip, &mark, nsos1vars) );
7548  SCIP_CALL( SCIPallocBufferArray(scip, &weights, nsos1vars) );
7549  SCIP_CALL( SCIPallocBufferArray(scip, &indscipvars, nsos1vars) );
7550 
7551  /* sort SOS1 variables in nonincreasing order of weights */
7552  for (i = 0; i < nsos1vars; ++i)
7553  indscipvars[i] = i;
7554 
7555  SCIP_CALL( getVectorOfWeights(scip, sol, conflictgraph, nsos1vars, indicatorzero, weights) );
7556  SCIPsortDownRealInt(weights, indscipvars, nsos1vars);
7557 
7558  /* mark fixed variables and variables without any neighbors in the conflict graph */
7559  k = 0;
7560  for (i = 0; i < nsos1vars; ++i)
7561  {
7562  nsucc = SCIPdigraphGetNSuccessors(conflictgraph, i);
7563 
7564  if ( indset[i] == 0 )
7565  {
7566  if( indicatorzero[i] )
7567  {
7568  mark[i] = TRUE;
7569  ++k;
7570  }
7571  else if ( nsucc == 0 )
7572  {
7573  indset[i] = 1;
7574  mark[i] = TRUE;
7575  ++k;
7576  }
7577  else
7578  mark[i] = FALSE;
7579  }
7580  else
7581  {
7582  SCIP_Bool cutoff;
7583 
7584  ++k;
7585  mark[i] = TRUE;
7586 
7587  SCIP_CALL( markNeighborsMWISHeuristic(scip, conshdlr, conflictgraph, i, mark, indset, &k, &cutoff) );
7588  assert( ! cutoff );
7589  }
7590  }
7591 
7592  /* mark vertices in the order of their largest weight */
7593  for (i = 0; k < nsos1vars; ++i) /*lint !e440*/
7594  {
7595  assert( i < nsos1vars );
7596 
7597  ind = indscipvars[i];
7598 
7599  if ( ! mark[ind] )
7600  {
7601  SCIP_Bool cutoff;
7602 
7603  /* mark ind */
7604  indset[ind] = 1;
7605  mark[ind] = TRUE;
7606  ++k;
7607 
7608  SCIP_CALL( markNeighborsMWISHeuristic(scip, conshdlr, conflictgraph, ind, mark, indset, &k, &cutoff) );
7609  if ( cutoff )
7610  indset[ind] = 0;
7611  }
7612  }
7613  assert( k == nsos1vars );
7614 
7615  /* free buffer arrays */
7616  SCIPfreeBufferArrayNull(scip, &indscipvars);
7617  SCIPfreeBufferArrayNull(scip, &weights);
7618  SCIPfreeBufferArrayNull(scip, &mark);
7619 
7620  return SCIP_OKAY;
7621 }
7622 
7623 
7624 /** based on solution values of the variables, fixes variables of the conflict graph to zero to turn all SOS1 constraints feasible
7625  *
7626  * if the SOS1 constraints do not overlap, the method makeSOS1constraintsFeasible() may be faster
7627  */
7628 static
7630  SCIP* scip, /**< SCIP pointer */
7631  SCIP_CONSHDLR* conshdlr, /**< SOS1 constraint handler */
7632  SCIP_SOL* sol, /**< solution */
7633  SCIP_Bool* changed, /**< pointer to store whether the solution has been changed */
7634  SCIP_Bool* allroundable /**< pointer to store whether all variables are roundable */
7635  )
7636 {
7637  SCIP_DIGRAPH* conflictgraph; /* conflict graph for SOS1 constraints */
7638  SCIP_Bool* indicatorzero; /* indicates which solution values are zero */
7639  SCIP_Bool* indset; /* indicator vector of feasible solution; i.e., an independent set */
7640  int nsos1vars;
7641  int j;
7642 
7643  assert( scip != NULL );
7644  assert( conshdlr != NULL );
7645  assert( sol != NULL );
7646  assert( changed != NULL );
7647 
7648  *allroundable = TRUE;
7649  *changed = FALSE;
7650 
7651  /* get number of SOS1 variables */
7652  nsos1vars = SCIPgetNSOS1Vars(conshdlr);
7653  assert( nsos1vars >= 0 );
7654 
7655  /* get conflict graph */
7656  conflictgraph = SCIPgetConflictgraphSOS1(conshdlr);
7657  assert( conflictgraph != NULL );
7658 
7659  /* allocate buffer arrays */
7660  SCIP_CALL( SCIPallocBufferArray(scip, &indset, nsos1vars) );
7661  SCIP_CALL( SCIPallocBufferArray(scip, &indicatorzero, nsos1vars) );
7662 
7663  /* determine if variables with nonzero solution value are roundable */
7664  for (j = 0; j < nsos1vars; ++j)
7665  {
7666  SCIP_VAR* var;
7667  SCIP_Real lb;
7668  SCIP_Real ub;
7669 
7670  var = SCIPnodeGetVarSOS1(conflictgraph, j);
7671  lb = SCIPvarGetLbLocal(var);
7672  ub = SCIPvarGetUbLocal(var);
7673  indset[j] = 0;
7674 
7675  /* if solution value of variable is zero */
7676  if ( SCIPisFeasZero(scip, SCIPgetSolVal(scip, sol, var)) )
7677  indicatorzero[j] = TRUE;
7678  else
7679  {
7680  indicatorzero[j] = FALSE;
7681 
7682  /* if variable is not roundable */
7683  if ( ! SCIPvarMayRoundDown(var) && ! SCIPvarMayRoundUp(var) )
7684  {
7685  *allroundable = FALSE;
7686  break;
7687  }
7688 
7689  /* if bounds of variable are fixed to zero */
7690  if ( SCIPisFeasZero(scip, ub) && SCIPisFeasZero(scip, lb) )
7691  indicatorzero[j] = TRUE;
7692  else if ( SCIPisFeasPositive(scip, lb) || SCIPisFeasNegative(scip, ub) ) /* if variable is fixed to be nonzero */
7693  indset[j] = 1;
7694  }
7695  }
7696 
7697  /* return if at least one SOS1 variable is not roundable */
7698  if ( ! (*allroundable) )
7699  {
7700  SCIPfreeBufferArray(scip, &indicatorzero);
7701  SCIPfreeBufferArray(scip, &indset);
7702  return SCIP_OKAY;
7703  }
7704 
7705  /* call greedy algorithm for the maximum weighted independent set problem */
7706  SCIP_CALL( maxWeightIndSetHeuristic(scip, sol, conshdlr, conflictgraph, nsos1vars, indicatorzero, indset) );
7707 
7708  /* make solution feasible */
7709  for (j = 0; j < nsos1vars; ++j)
7710  {
7711  if ( indset[j] == 0 )
7712  {
7713  SCIP_CALL( SCIPsetSolVal(scip, sol, SCIPnodeGetVarSOS1(conflictgraph, j), 0.0) );
7714  *changed = TRUE;
7715  }
7716  }
7717 
7718  /* free buffer arrays */
7719  SCIPfreeBufferArray(scip, &indicatorzero);
7720  SCIPfreeBufferArray(scip, &indset);
7721 
7722 #ifdef SCIP_NDEBUG
7723  {
7724  SCIP_CONSDATA* consdata;
7725  SCIP_CONS** conss;
7726  int nconss;
7727  int c;
7728 
7729  conss = SCIPconshdlrGetConss(conshdlr);
7730  nconss = SCIPconshdlrGetNConss(conshdlr);
7731  for (c = 0; c < nconss; ++c)
7732  {
7733  int cnt = 0;
7734  consdata = SCIPconsGetData(conss[c]);
7735  assert( consdata != NULL );
7736 
7737  for (j = 0; j < consdata->nvars; ++j)
7738  {
7739  if ( ! SCIPisFeasZero(scip, SCIPgetSolVal(scip, sol, consdata->vars[j])) )
7740  {
7741  ++cnt;
7742  }
7743  }
7744  assert( cnt < 2 );
7745  }
7746  }
7747 #endif
7748 
7749  return SCIP_OKAY;
7750 }
7751 
7752 
7753 /** based on solution values of the variables, fixes variables of the SOS1 constraints to zero to turn these constraints feasible
7754  *
7755  * if the SOS1 constraints overlap, the method makeSOS1constraintsFeasible() may result in better primal solutions
7756  */
7757 static
7759  SCIP* scip, /**< SCIP pointer */
7760  SCIP_CONSHDLR* conshdlr, /**< SOS1 constraint handler */
7761  SCIP_SOL* sol, /**< solution */
7762  SCIP_Bool* changed, /**< pointer to store whether the solution has been changed */
7763  SCIP_Bool* allroundable /**< pointer to store whether all variables are roundable */
7764  )
7765 {
7766  SCIP_CONSDATA* consdata;
7767  SCIP_CONS** conss;
7768  int nconss;
7769  int c;
7770 
7771  assert( scip != NULL );
7772  assert( conshdlr != NULL );
7773  assert( sol != NULL );
7774  assert( changed != NULL );
7775 
7776  *allroundable = TRUE;
7777  *changed = FALSE;
7778 
7779  /* get SOS1 constraints and number of SOS1 constraints */
7780  conss = SCIPconshdlrGetConss(conshdlr);
7781  nconss = SCIPconshdlrGetNConss(conshdlr);
7782  assert( nconss > 0 );
7783 
7784  /* loop through all SOS1 constraints */
7785  for (c = 0; c < nconss && *allroundable; ++c)
7786  {
7787  SCIP_CONS* cons;
7788  SCIP_VAR** vars;
7789  SCIP_Bool varisfixed = FALSE;
7790  SCIP_Real maxval = 0.0;
7791  int pos = -1;
7792  int nvars;
7793  int j;
7794 
7795  cons = conss[c];
7796  assert( cons != NULL );
7797  consdata = SCIPconsGetData(cons);
7798  assert( consdata != NULL );
7799 
7800  nvars = consdata->nvars;
7801  vars = consdata->vars;
7802 
7803  /* search for maximum solution value */
7804  for (j = 0; j < nvars; ++j)
7805  {
7806  SCIP_VAR* var;
7807 
7808  var = vars[j];
7809 
7810  if ( ! SCIPisFeasZero(scip, SCIPgetSolVal(scip, sol, var)) )
7811  {
7812  SCIP_Real lb;
7813  SCIP_Real ub;
7814 
7815  lb = SCIPvarGetLbLocal(var);
7816  ub = SCIPvarGetUbLocal(var);
7817 
7818  /* if variable is not roundable */
7819  if ( ! SCIPvarMayRoundDown(var) && ! SCIPvarMayRoundUp(var) )
7820  {
7821  *allroundable = FALSE;
7822  break;
7823  }
7824 
7825  /* it is possible that the bounds were proagated to zero although the current solution value is nonzero
7826  * in this case fix the solution value to zero */
7827  if ( SCIPisFeasZero(scip, ub) && SCIPisFeasZero(scip, lb) )
7828  {
7829  SCIP_CALL( SCIPsetSolVal(scip, sol, var, 0.0) );
7830  *changed = TRUE;
7831  }
7832  else if ( SCIPisFeasPositive(scip, lb) || SCIPisFeasNegative(scip, ub) ) /* if variable is fixed to be nonzero */
7833  {
7834  assert( ! varisfixed );
7835  varisfixed = TRUE;
7836  maxval = SCIPgetSolVal(scip, sol, var);
7837  pos = j;
7838  }
7839  else if ( ! varisfixed && SCIPisFeasGT(scip, REALABS(SCIPgetSolVal(scip, sol, var)), REALABS(maxval)) ) /* search for variable with maximum solution value */
7840  {
7841  maxval = SCIPgetSolVal(scip, sol, var);
7842  pos = j;
7843  }
7844 
7845  /* fix variable to zero; the solution value of the variable with maximum solution value
7846  * will be restored in a later step */
7847  SCIP_CALL( SCIPsetSolVal(scip, sol, var, 0.0) );
7848  *changed = TRUE;
7849  }
7850  }
7851 
7852  if ( ! (*allroundable) )
7853  break;
7854  else if ( pos >= 0 ) /* restore solution of variable with maximum solution value */
7855  {
7856  SCIP_CALL( SCIPsetSolVal(scip, sol, vars[pos], maxval) );
7857  }
7858  }
7859 
7860 #ifdef SCIP_NDEBUG
7861  if ( *allroundable )
7862  {
7863  for (c = 0; c < nconss; ++c)
7864  {
7865  int cnt = 0;
7866  int j;
7867 
7868  consdata = SCIPconsGetData(conss[c]);
7869  assert( consdata != NULL );
7870 
7871  for (j = 0; j < consdata->nvars; ++j)
7872  {
7873  if ( ! SCIPisFeasZero(scip, SCIPgetSolVal(scip, sol, consdata->vars[j])) )
7874  {
7875  ++cnt;
7876  }
7877  }
7878  assert( cnt < 2 );
7879  }
7880  }
7881 #endif
7882 
7883  return SCIP_OKAY;
7884 }
7885 
7886 
7887 /** determine a diving variables and boundchanges of diving variables by analyzing the conflict graph
7888  *
7889  * if the SOS1 constraints do not overlap, the method getDiveBdChgsSOS1constraints() may be faster
7890  */
7891 static
7893  SCIP* scip, /**< SCIP pointer */
7894  SCIP_CONSHDLR* conshdlr, /**< SOS1 constraint handler */
7895  SCIP_DIVESET* diveset, /**< diving settings */
7896  SCIP_SOL* sol, /**< solution */
7897  SCIP_Bool* success /**< pointer to store */
7898  )
7899 {
7900  SCIP_DIGRAPH* conflictgraph;
7901  SCIP_VAR* bestvar = NULL;
7902  SCIP_Bool bestvarfixneigh = FALSE;
7903  SCIP_Real bestscore = SCIP_REAL_MIN;
7904  int bestnode = -1;
7905  int nsos1vars;
7906  int v;
7907 
7908  assert( scip != NULL );
7909  assert( conshdlr != NULL );
7910  assert( diveset != NULL );
7911  assert( success != NULL );
7912 
7913  *success = FALSE;
7914 
7915  /* get number of SOS1 variables */
7916  nsos1vars = SCIPgetNSOS1Vars(conshdlr);
7917 
7918  /* get conflict graph of SOS1 constraints */
7919  conflictgraph = SCIPgetConflictgraphSOS1(conshdlr);
7920 
7921  /* loop over SOS1 variables */
7922  for (v = 0; v < nsos1vars; ++v)
7923  {
7924  /* check whether the variable violates an SOS1 constraint together with at least one other variable */
7925  if ( isViolatedSOS1(scip, conflictgraph, v, sol) )
7926  {
7927  SCIP_VAR* var;
7928  SCIP_Real solval;
7929  SCIP_Real score;
7930  SCIP_Real bound;
7931  SCIP_Real fracval;
7932  SCIP_Bool fixneigh;
7933 
7934  var = SCIPnodeGetVarSOS1(conflictgraph, v);
7935  solval = SCIPgetSolVal(scip, sol, var);
7936 
7937  /* compute (variable) bound of candidate */
7938  if ( SCIPisFeasNegative(scip, solval) )
7939  bound = nodeGetSolvalVarboundLbSOS1(scip, conflictgraph, sol, v);
7940  else
7941  bound = nodeGetSolvalVarboundUbSOS1(scip, conflictgraph, sol, v);
7942 
7943  /* bound may have changed in propagation; ensure that fracval <= 1 */
7944  if ( SCIPisFeasLT(scip, REALABS(bound), REALABS(solval)) )
7945  bound = solval;
7946 
7947  /* ensure finiteness */
7948  bound = MIN(DIVINGCUTOFFVALUE, REALABS(bound)); /*lint !e666*/
7949  fracval = MIN(DIVINGCUTOFFVALUE, REALABS(solval)); /*lint !e666*/
7950  assert( ! SCIPisInfinity(scip, bound) );
7951  assert( ! SCIPisInfinity(scip, fracval) );
7952  assert( SCIPisPositive(scip, bound) );
7953 
7954  /* get fractionality of candidate */
7955  fracval /= (bound + SCIPsumepsilon(scip));
7956 
7957  /* should SOS1 variables be scored by the diving heuristics specific score function;
7958  * otherwise use the score function of the SOS1 constraint handler */
7960  {
7961  SCIP_Bool roundup;
7962 
7963  SCIP_CALL( SCIPgetDivesetScore(scip, diveset, SCIP_DIVETYPE_SOS1VARIABLE, var, solval, fracval,
7964  &score, &roundup) );
7965 
7966  fixneigh = roundup;
7967  if ( SCIPisFeasNegative(scip, solval) )
7968  fixneigh = !fixneigh;
7969  }
7970  else
7971  {
7972  /* we always fix the candidates neighbors in the conflict graph to zero */
7973  fixneigh = TRUE;
7974 
7975  /* score fractionality of candidate */
7976  score = fracval;
7977  }
7978 
7979  /* best candidate maximizes the score */
7980  if ( score > bestscore )
7981  {
7982  bestscore = score;
7983 
7984  *success = TRUE;
7985  bestvar = var;
7986  bestnode = v;
7987  bestvarfixneigh = fixneigh;
7988  }
7989  }
7990  }
7991  assert( !(*success) || bestvar != NULL );
7992 
7993  if ( *success )
7994  {
7995  int* succ;
7996  int nsucc;
7997  int s;
7998 
7999  assert( bestnode >= 0 && bestnode < nsos1vars );
8000 
8001  nsucc = SCIPdigraphGetNSuccessors(conflictgraph, bestnode);
8002  succ = SCIPdigraphGetSuccessors(conflictgraph, bestnode);
8003 
8004  /* if the diving score voted for fixing the best variable to 0.0, we add this as the preferred bound change;
8005  * otherwise, fixing the neighbors in the conflict graph to 0.0 is the preferred bound change.
8006  */
8007  assert( SCIPisFeasNegative(scip, SCIPvarGetLbLocal(bestvar)) || SCIPisFeasPositive(scip, SCIPvarGetUbLocal(bestvar)) );
8008  SCIP_CALL( SCIPaddDiveBoundChange(scip, bestvar, SCIP_BRANCHDIR_FIXED, 0.0, !bestvarfixneigh) );
8009  for (s = 0; s < nsucc; ++s)
8010  {
8011  SCIP_VAR* var;
8012 
8013  var = SCIPnodeGetVarSOS1(conflictgraph, succ[s]);
8014 
8015  /* if variable is not already fixed */
8017  {
8018  SCIP_CALL( SCIPaddDiveBoundChange(scip, var, SCIP_BRANCHDIR_FIXED, 0.0, bestvarfixneigh) );
8019  }
8020  }
8021  }
8022 
8023  return SCIP_OKAY;
8024 }
8025 
8026 
8027 /** determine a diving variables and boundchanges of diving variables by analyzing the SOS1 constraints
8028  *
8029  * if the SOS1 constraints overlap, the method getDiveBdChgsSOS1conflictgraph() may produce better results (e.g., due to more
8030  * diving candidates)
8031  */
8032 static
8034  SCIP* scip, /**< SCIP pointer */
8035  SCIP_CONSHDLR* conshdlr, /**< SOS1 constraint handler */
8036  SCIP_DIVESET* diveset, /**< diving settings */
8037  SCIP_SOL* sol, /**< solution */
8038  SCIP_Bool* success /**< pointer to store */
8039  )
8040 {
8041  SCIP_VAR* bestvar = NULL;
8042  SCIP_Bool bestvarfixcomp = FALSE;
8043  SCIP_Real bestscore = SCIP_REAL_MIN;
8044  SCIP_CONSDATA* consdata;
8045  SCIP_CONS** conss;
8046  int nconss;
8047  int bestcons = -1;
8048  int c;
8049 
8050  assert( scip != NULL );
8051  assert( conshdlr != NULL );
8052  assert( diveset != NULL );
8053  assert( success != NULL );
8054 
8055  *success = FALSE;
8056 
8057  /* get SOS1 constraints and number of SOS1 constraints */
8058  conss = SCIPconshdlrGetConss(conshdlr);
8059  nconss = SCIPconshdlrGetNConss(conshdlr);
8060 
8061  /* loop through all SOS1 constraints */
8062  for (c = 0; c < nconss; ++c)
8063  {
8064  SCIP_VAR** vars;
8065  int nvars;
8066  int cnt = 0;
8067  int j;
8068 
8069  consdata = SCIPconsGetData(conss[c]);
8070  assert( consdata != NULL );
8071 
8072  nvars = consdata->nvars;
8073  vars = consdata->vars;
8074 
8075  /* check whether SOS1 constraint is violated */
8076  for (j = 0; j < nvars && cnt < 2; ++j)
8077  {
8078  SCIP_VAR* var;
8079 
8080  var = vars[j];
8081 
8082  /* check whether variable is nonzero w.r.t. sol and the bounds have not been fixed to zero by propagation */
8083  if ( !SCIPisFeasZero(scip, SCIPgetSolVal(scip, sol, var))
8084  && (!SCIPisFeasZero(scip, SCIPvarGetLbLocal(var)) || !SCIPisFeasZero(scip, SCIPvarGetUbLocal(var))) )
8085  ++cnt;
8086  }
8087 
8088  /* if SOS1 constraint is not violated then continue with the next SOS1 constraint */
8089  if ( cnt < 2 )
8090  continue;
8091 
8092  /* get diving score of every variable in constraint */
8093  for (j = 0; j < nvars; ++j)
8094  {
8095  SCIP_VAR* var;
8096  SCIP_Real solval;
8097  SCIP_Real score;
8098  SCIP_Real bound;
8099  SCIP_Real fracval;
8100  SCIP_Real lb;
8101  SCIP_Real ub;
8102  SCIP_Bool fixcomp; /* whether to fix the complementary variables of the candidate in the SOS1 constraint to zero */
8103 
8104  var = vars[j];
8105  solval = SCIPgetSolVal(scip, sol, var);
8106  lb = SCIPvarGetLbLocal(var);
8107  ub = SCIPvarGetUbLocal(var);
8108 
8109  /* check whether variable is nonzero w.r.t. sol and the bounds have not been fixed to zero by propagation */
8110  if ( ! SCIPisFeasZero(scip, solval) && ( ! SCIPisFeasZero(scip, lb) || ! SCIPisFeasZero(scip, ub) ) )
8111  {
8112  /* compute (variable) bound of candidate */
8113  if ( SCIPisFeasNegative(scip, solval) )
8114  bound = lb;
8115  else
8116  bound = ub;
8117 
8118  /* bound may have changed in propagation; ensure that fracval <= 1 */
8119  if ( SCIPisFeasLT(scip, REALABS(bound), REALABS(solval)) )
8120  bound = solval;
8121 
8122  /* ensure finiteness */
8123  bound = MIN(DIVINGCUTOFFVALUE, REALABS(bound)); /*lint !e666*/
8124  fracval = MIN(DIVINGCUTOFFVALUE, REALABS(solval)); /*lint !e666*/
8125  assert( ! SCIPisInfinity(scip, bound) );
8126  assert( ! SCIPisInfinity(scip, fracval) );
8127  assert( SCIPisPositive(scip, bound) );
8128 
8129  /* get fractionality of candidate */
8130  fracval /= (bound + SCIPsumepsilon(scip));
8131 
8132  /* should SOS1 variables be scored by the diving heuristics specific score function;
8133  * otherwise use the score function of the SOS1 constraint handler
8134  */
8136  {
8137  SCIP_Bool roundup;
8138 
8139  SCIP_CALL( SCIPgetDivesetScore(scip, diveset, SCIP_DIVETYPE_SOS1VARIABLE, var, solval, fracval,
8140  &score, &roundup) );
8141 
8142  fixcomp = roundup;
8143  if ( SCIPisFeasNegative(scip, solval) )
8144  fixcomp = !fixcomp;
8145  }
8146  else
8147  {
8148  /* we always fix the complementary variables of the candidate in the SOS1 constraint to zero */
8149  fixcomp = TRUE;
8150 
8151  /* score fractionality of candidate */
8152  score = fracval;
8153  }
8154 
8155  /* best candidate maximizes the score */
8156  if ( score > bestscore )
8157  {
8158  bestscore = score;
8159 
8160  *success = TRUE;
8161  bestvar = var;
8162  bestcons = c;
8163  bestvarfixcomp = fixcomp;
8164  }
8165  }
8166  }
8167  }
8168  assert( !(*success) || bestvar != NULL );
8169 
8170  if ( *success )
8171  {
8172  SCIP_VAR** vars;
8173  int nvars;
8174  int j;
8175 
8176  consdata = SCIPconsGetData(conss[bestcons]);
8177  assert( consdata != NULL );
8178 
8179  nvars = consdata->nvars;
8180  vars = consdata->vars;
8181 
8182  assert( bestcons >= 0 && bestcons < nconss );
8183 
8184  /* if the diving score voted for fixing the best variable to 0.0, we add this as the preferred bound change;
8185  * otherwise, fixing the complementary variables of the candidate in the SOS1 constraint to 0.0 is the preferred bound change.
8186  */
8187  assert( SCIPisFeasNegative(scip, SCIPvarGetLbLocal(bestvar)) || SCIPisFeasPositive(scip, SCIPvarGetUbLocal(bestvar)) );
8188 
8189  SCIP_CALL( SCIPaddDiveBoundChange(scip, bestvar, SCIP_BRANCHDIR_FIXED, 0.0, !bestvarfixcomp) );
8190  for (j = 0; j < nvars; ++j)
8191  {
8192  SCIP_VAR* var;
8193 
8194  var = vars[j];
8195 
8196  /* if variable is not already fixed and is not the candidate variable */
8197  if ( var != bestvar && ( SCIPisFeasNegative(scip, SCIPvarGetLbLocal(var)) || SCIPisFeasPositive(scip, SCIPvarGetUbLocal(var)) ) )
8198  {
8199  SCIP_CALL( SCIPaddDiveBoundChange(scip, var, SCIP_BRANCHDIR_FIXED, 0.0, bestvarfixcomp) );
8200  }
8201  }
8202  }
8203 
8204  return SCIP_OKAY;
8205 }
8206 
8207 
8208 /* --------------------initialization/deinitialization ------------------------*/
8209 
8210 /** check whether \f$x_1\f$ is a bound variable of \f$x_0\f$; i.e., \f$x_0 \leq c\cdot x_1\f$ or \f$x_0 \geq d\cdot x_1\f$
8211  * for positive values \f$c, d\f$. If true, then add this information to the node data of the conflict graph.
8212  */
8213 static
8215  SCIP* scip, /**< SCIP pointer */
8216  SCIP_CONSHDLRDATA* conshdlrdata, /**< SOS1 constraint handler data */
8217  SCIP_VAR* var0, /**< first variable */
8218  SCIP_VAR* var1, /**< second variable */
8219  SCIP_Real val0, /**< first coefficient */
8220  SCIP_Real val1 /**< second coefficient */
8221  )
8222 {
8223  int node0;
8224 
8225  assert( scip != NULL );
8226  assert( conshdlrdata != NULL );
8227  assert( var0 != NULL && var1 != NULL );
8228 
8229  /* get nodes of variable in the conflict graph (node = -1 if no SOS1 variable) */
8230  node0 = varGetNodeSOS1(conshdlrdata, var0);
8231 
8232  /* if var0 is an SOS1 variable */
8233  if ( node0 >= 0 )
8234  {
8235  SCIP_Real val;
8236 
8237  assert( ! SCIPisFeasZero(scip, val0) );
8238  val = -val1/val0;
8239 
8240  /* check variable bound relation of variables */
8241 
8242  /* handle lower bound case */
8243  if ( SCIPisFeasNegative(scip, val0) && SCIPisFeasNegative(scip, val) )
8244  {
8245  SCIP_NODEDATA* nodedata;
8246 
8247  /* get node data of the conflict graph */
8248  nodedata = (SCIP_NODEDATA*)SCIPdigraphGetNodeData(conshdlrdata->conflictgraph, node0);
8249 
8250  /* @todo: maybe save multiple variable bounds for each SOS1 variable */
8251  if ( nodedata->lbboundvar == NULL )
8252  {
8253  /* add variable bound information to node data */
8254  nodedata->lbboundvar = var1;
8255  nodedata->lbboundcoef = val;
8256 
8257  SCIPdebugMsg(scip, "detected variable bound constraint %s >= %f %s.\n", SCIPvarGetName(var0), val, SCIPvarGetName(var1));
8258  }
8259  }
8260  /* handle upper bound case */
8261  else if ( SCIPisFeasPositive(scip, val0) && SCIPisFeasPositive(scip, val) )
8262  {
8263  SCIP_NODEDATA* nodedata;
8264  assert( SCIPisFeasPositive(scip, val0) );
8265 
8266  /* get node data of the conflict graph */
8267  nodedata = (SCIP_NODEDATA*)SCIPdigraphGetNodeData(conshdlrdata->conflictgraph, node0);
8268 
8269  if ( nodedata->ubboundvar == NULL )
8270  {
8271  /* add variable bound information to node data */
8272  nodedata->ubboundvar = var1;
8273  nodedata->ubboundcoef = val;
8274 
8275  SCIPdebugMsg(scip, "detected variable bound constraint %s <= %f %s.\n", SCIPvarGetName(var0), val, SCIPvarGetName(var1));
8276  }
8277  }
8278  }
8279 
8280  return SCIP_OKAY;
8281 }
8282 
8283 
8284 /** pass connected component \f$C\f$ of the conflict graph and check whether all the variables correspond to a unique variable upper bound variable \f$z\f$,
8285  * i.e., \f$x_i \leq u_i z\f$ for every \f$i\in C\f$.
8286  *
8287  * @note if the bound variable is unique, then bound inequalities can be strengthened.
8288  */
8289 static
8291  SCIP* scip, /**< SCIP pointer */
8292  SCIP_DIGRAPH* conflictgraph, /**< conflict graph */
8293  int node, /**< current node of connected component */
8294  SCIP_VAR* boundvar, /**< bound variable of connected component */
8295  SCIP_Bool checklb, /**< whether to check lower bound variable (else upper bound variable) */
8296  SCIP_Bool* processed, /**< states for each variable whether it has been processed */
8297  int* concomp, /**< current connected component */
8298  int* nconcomp, /**< pointer to store number of elements of connected component */
8299  SCIP_Bool* unique /**< pointer to store whether bound variable is unique */
8300  )
8301 {
8302  int* succ;
8303  int nsucc;
8304  int s;
8305 
8306  assert( scip != NULL );
8307  assert( conflictgraph != NULL );
8308  assert( processed != NULL );
8309  assert( concomp != NULL );
8310  assert( nconcomp != NULL );
8311  assert( unique != NULL );
8312 
8313  processed[node] = TRUE;/*lint !e737*/
8314  concomp[(*nconcomp)++] = node;
8315 
8316  /* if bound variable of connected component without new node is unique */
8317  if ( *unique )
8318  {
8319  SCIP_NODEDATA* nodedata;
8320  SCIP_VAR* comparevar;
8321  nodedata = (SCIP_NODEDATA*)SCIPdigraphGetNodeData(conflictgraph, node);
8322  assert( nodedata != NULL );
8323 
8324  if ( checklb )
8325  comparevar = nodedata->lbboundvar;
8326  else
8327  comparevar = nodedata->ubboundvar;
8328 
8329  /* check whether bound variable is unique for connected component without new node */
8330  if ( boundvar == NULL )
8331  {
8332  if ( comparevar != NULL )
8333  *unique = FALSE;
8334  }
8335  else
8336  {
8337  if ( comparevar == NULL )
8338  *unique = FALSE;
8339  else if ( SCIPvarCompare(boundvar, comparevar) != 0 )
8340  *unique = FALSE;
8341  }
8342  }
8343 
8344  /* pass through successor variables */
8345  nsucc = SCIPdigraphGetNSuccessors(conflictgraph, node);
8346  succ = SCIPdigraphGetSuccessors(conflictgraph, node);
8347  for (s = 0; s < nsucc; ++s)
8348  {
8349  if ( ! processed[succ[s]] )
8350  SCIP_CALL( passConComponentVarbound(scip, conflictgraph, succ[s], boundvar, checklb, processed, concomp, nconcomp, unique) );
8351  }
8352 
8353  return SCIP_OKAY;
8354 }
8355 
8356 
8357 /** for each connected component \f$C\f$ of the conflict graph check whether all the variables correspond to a unique variable upper bound variable \f$z\f$
8358  * (e.g., for the upper bound case this means that \f$x_i \leq u_i z\f$ for every \f$i\in C\f$).
8359  *
8360  * @note if the bound variable is unique, then bound inequalities can be strengthened.
8361  */
8362 static
8364  SCIP* scip, /**< SCIP pointer */
8365  SCIP_DIGRAPH* conflictgraph, /**< conflict graph */
8366  int nsos1vars, /**< number of SOS1 variables */
8367  SCIP_Bool checklb /**< whether to check lower bound variable (else check upper bound variable) */
8368  )
8370  SCIP_Bool* processed; /* states for each variable whether it has been processed */
8371  int* concomp; /* current connected component */
8372  int nconcomp;
8373  int j;
8374 
8375  assert( scip != NULL );
8376  assert( conflictgraph != NULL );
8377 
8378  /* allocate buffer arrays and initialize 'processed' array */
8379  SCIP_CALL( SCIPallocBufferArray(scip, &processed, nsos1vars) );
8380  SCIP_CALL( SCIPallocBufferArray(scip, &concomp, nsos1vars) );
8381  for (j = 0; j < nsos1vars; ++j)
8382  processed[j] = FALSE;
8383 
8384  /* run through all SOS1 variables */
8385  for (j = 0; j < nsos1vars; ++j)
8386  {
8387  /* if variable belongs to a connected component that has not been processed so far */
8388  if ( ! processed[j] )
8389  {
8390  SCIP_NODEDATA* nodedata;
8391  SCIP_VAR* boundvar;
8392  SCIP_Bool unique;
8393  int* succ;
8394  int nsucc;
8395  int s;
8396 
8397  nodedata = (SCIP_NODEDATA*)SCIPdigraphGetNodeData(conflictgraph, j);
8398  assert( nodedata != NULL );
8399 
8400  if ( checklb )
8401  boundvar = nodedata->lbboundvar;
8402  else
8403  boundvar = nodedata->ubboundvar;
8404  unique = TRUE;
8405 
8406  processed[j] = TRUE;
8407  concomp[0] = j;
8408  nconcomp = 1;
8409 
8410  /* pass through successor variables */
8411  nsucc = SCIPdigraphGetNSuccessors(conflictgraph, j);
8412  succ = SCIPdigraphGetSuccessors(conflictgraph, j);
8413  for (s = 0; s < nsucc; ++s)
8414  {
8415  if ( ! processed[succ[s]] )
8416  {
8417  SCIP_CALL( passConComponentVarbound(scip, conflictgraph, succ[s], boundvar, checklb, processed, concomp, &nconcomp, &unique) );
8418  }
8419  }
8420 
8421  /* if the connected component has a unique bound variable */
8422  if ( unique && boundvar != NULL )
8423  {
8424  for (s = 0; s < nconcomp; ++s)
8425  {
8426  nodedata = (SCIP_NODEDATA*)SCIPdigraphGetNodeData(conflictgraph, concomp[s]);
8427  assert( processed[concomp[s]] == TRUE );
8428  assert( nodedata != NULL );
8429 
8430  if ( checklb )
8431  nodedata->lbboundcomp = TRUE;
8432  else
8433  nodedata->ubboundcomp = TRUE;
8434  }
8435  SCIPdebugMsg(scip, "Found a connected component of size <%i> with unique bound variable.\n", nconcomp);
8436  }
8437  }
8438  }
8439 
8440  /* free buffer arrays */
8441  SCIPfreeBufferArray(scip, &concomp);
8442  SCIPfreeBufferArray(scip, &processed);
8443 
8444  return SCIP_OKAY;
8445 }
8446 
8447 
8448 /** check all linear constraints for variable bound constraints of the form \f$c\cdot z \leq x \leq d\cdot z\f$, where @p x is some SOS1
8449  * variable and @p z is some arbitrary variable (not necessarily binary)
8450  */
8451 static
8453  SCIP* scip, /**< SCIP pointer */
8454  SCIP_CONSHDLRDATA* conshdlrdata, /**< SOS1 constraint handler data */
8455  SCIP_CONS** linconss, /**< linear constraints */
8456  int nlinconss /**< number of linear constraints */
8457  )
8459  int c;
8460 
8461  /* loop through linear constraints */
8462  for (c = 0; c < nlinconss; ++c)
8463  {
8464  SCIP_CONS* lincons;
8465  int nvars;
8466 
8467  lincons = linconss[c];
8468 
8469  /* variable bound constraints only contain two variables */
8470  nvars = SCIPgetNVarsLinear(scip, lincons);
8471  if ( nvars == 2 )
8472  {
8473  SCIP_VAR** vars;
8474  SCIP_Real* vals;
8475  SCIP_VAR* var0;
8476  SCIP_VAR* var1;
8477  SCIP_Real lhs;
8478  SCIP_Real rhs;
8479 
8480  /* get constraint data */
8481  vars = SCIPgetVarsLinear(scip, lincons);
8482  vals = SCIPgetValsLinear(scip, lincons);
8483  lhs = SCIPgetLhsLinear(scip, lincons);
8484  rhs = SCIPgetRhsLinear(scip, lincons);
8485 
8486  var0 = vars[0];
8487  var1 = vars[1];
8488  assert( var0 != NULL && var1 != NULL );
8489 
8490  /* at least one variable should be an SOS1 variable */
8491  if ( varIsSOS1(conshdlrdata, var0) || varIsSOS1(conshdlrdata, var1) )
8492  {
8493  SCIP_Real val0;
8494  SCIP_Real val1;
8495 
8496  /* check whether right hand side or left hand side of constraint is zero */
8497  if ( SCIPisFeasZero(scip, lhs) )
8498  {
8499  val0 = -vals[0];
8500  val1 = -vals[1];
8501 
8502  /* check whether the two variables are in a variable bound relation */
8503  SCIP_CALL( detectVarboundSOS1(scip, conshdlrdata, var0, var1, val0, val1) );
8504  SCIP_CALL( detectVarboundSOS1(scip, conshdlrdata, var1, var0, val1, val0) );
8505  }
8506  else if( SCIPisFeasZero(scip, rhs) )
8507  {
8508  val0 = vals[0];
8509  val1 = vals[1];
8510 
8511  /* check whether the two variables are in a variable bound relation */
8512  SCIP_CALL( detectVarboundSOS1(scip, conshdlrdata, var0, var1, val0, val1) );
8513  SCIP_CALL( detectVarboundSOS1(scip, conshdlrdata, var1, var0, val1, val0) );
8514  }
8515  }
8516  }
8517  }
8518 
8519  return SCIP_OKAY;
8520 }
8521 
8522 
8523 /** switch to SOS1 branching and separating bound iniqualities from SOS1 constraints if the SOS1 constraints do not overlap */
8524 static
8526  SCIP* scip, /**< SCIP pointer */
8527  SCIP_CONSHDLRDATA* conshdlrdata, /**< SOS1 constraint handler data */
8528  SCIP_DIGRAPH* conflictgraph, /**< conflict graph */
8529  SCIP_CONS** conss, /**< SOS1 constraints */
8530  int nconss /**< number of SOS1 constraints */
8531  )
8532 {
8533  SCIP_Bool nonoverlap = TRUE;
8534  int c;
8535 
8536  /* loop through all SOS1 constraints */
8537  if ( conshdlrdata->nsos1vars > 0 )
8538  {
8539  for (c = 0; c < nconss && nonoverlap; ++c)
8540  {
8541  SCIP_CONSDATA* consdata;
8542  SCIP_VAR** vars;
8543  int notfixed = 0;
8544  int nvars;
8545  int i;
8546 
8547  assert( conss[c] != NULL );
8548 
8549  /* get constraint data field of the constraint */
8550  consdata = SCIPconsGetData(conss[c]);
8551  assert( consdata != NULL );
8552 
8553  /* get variables and number of variables of constraint */
8554  nvars = consdata->nvars;
8555  vars = consdata->vars;
8556 
8557  /* get number of variables of SOS1 constraint that are not fixed to zero */
8558  for (i = 0; i < nvars; ++i)
8559  {
8560  if ( ! SCIPisFeasZero(scip, SCIPvarGetLbLocal(vars[i])) || ! SCIPisFeasZero(scip, SCIPvarGetUbLocal(vars[i])) )
8561  ++notfixed;
8562  }
8563 
8564  /* check variables of SOS1 constraint */
8565  for (i = 0; i < nvars; ++i)
8566  {
8567  int node;
8568 
8569  assert( vars[i] != NULL );
8570 
8571  node = varGetNodeSOS1(conshdlrdata, vars[i]);
8572  assert( node >= 0 || ( SCIPisFeasZero(scip, SCIPvarGetLbLocal(vars[i])) && SCIPisFeasZero(scip, SCIPvarGetUbLocal(vars[i]))) );
8573  assert( node < conshdlrdata->nsos1vars );
8574  assert( node < 0 || SCIPdigraphGetNSuccessors(conflictgraph, node) >= notfixed-1 );
8575  if ( node >= 0 && SCIPdigraphGetNSuccessors(conflictgraph, node) > notfixed-1 )
8576  {
8577  nonoverlap = FALSE;
8578  break;
8579  }
8580  }
8581  }
8582  }
8583 
8584  /* if the SOS1 constraints do not overlap */
8585  if ( nonoverlap )
8586  {
8587  if ( conshdlrdata->autosos1branch )
8588  {
8589  conshdlrdata->switchsos1branch = TRUE;
8590  SCIPdebugMsg(scip, "Switched to SOS1 branching, since the SOS1 constraints do not overlap\n");
8591  }
8592 
8593  if ( conshdlrdata->autocutsfromsos1 )
8594  {
8595  conshdlrdata->switchcutsfromsos1 = TRUE;
8596  SCIPdebugMsg(scip, "Switched to separating bound cuts from SOS1 constraints (and not from the conflict graph), since the SOS1 constraints do not overlap\n");
8597  }
8598  }
8599 
8600  return SCIP_OKAY;
8601 }
8602 
8603 
8604 /** sets node data of conflict graph nodes */
8605 static
8607  SCIP* scip, /**< SCIP pointer */
8608  SCIP_CONSHDLRDATA* conshdlrdata, /**< SOS1 constraint handler data */
8609  int nsos1vars /**< number of SOS1 variables */
8610  )
8611 {
8612  SCIP_CONSHDLR* linconshdlr;
8613  SCIP_CONS** linconss;
8614  int nlinconss;
8615 
8616  /* if no SOS1 variables exist -> exit */
8617  if ( nsos1vars == 0 )
8618  return SCIP_OKAY;
8619 
8620  /* get constraint handler data of linear constraints */
8621  linconshdlr = SCIPfindConshdlr(scip, "linear");
8622  if ( linconshdlr == NULL )
8623  return SCIP_OKAY;
8624 
8625  /* get linear constraints and number of linear constraints */
8626  nlinconss = SCIPconshdlrGetNConss(linconshdlr);
8627  linconss = SCIPconshdlrGetConss(linconshdlr);
8628 
8629  /* check linear constraints for variable bound constraints */
8630  SCIP_CALL( checkLinearConssVarboundSOS1(scip, conshdlrdata, linconss, nlinconss) );
8631 
8632  /* for each connected component of the conflict graph check whether all the variables correspond to a unique variable
8633  * upper bound variable */
8634  SCIP_CALL( checkConComponentsVarbound(scip, conshdlrdata->conflictgraph, conshdlrdata->nsos1vars, TRUE) );
8635  SCIP_CALL( checkConComponentsVarbound(scip, conshdlrdata->conflictgraph, conshdlrdata->nsos1vars, FALSE) );
8636 
8637  return SCIP_OKAY;
8638 }
8639 
8640 
8641 /** initialize conflictgraph and create hashmap for SOS1 variables */
8642 static
8644  SCIP* scip, /**< SCIP pointer */
8645  SCIP_CONSHDLRDATA* conshdlrdata, /**< constraint handler data */
8646  SCIP_CONS** conss, /**< SOS1 constraints */
8647  int nconss /**< number of SOS1 constraints */
8648  )
8650  SCIP_Bool* nodecreated; /* nodecreated[i] = TRUE if a node in the conflict graph is already created for index i
8651  * (with i index of the original variables) */
8652  int* nodeorig; /* nodeorig[i] = node of original variable x_i in the conflict graph */
8653  int ntotalvars;
8654  int cntsos;
8655  int i;
8656  int j;
8657  int c;
8658 
8659  assert( conshdlrdata != NULL );
8660  assert( nconss == 0 || conss != NULL );
8661 
8662  /* get the number of original problem variables */
8663  ntotalvars = SCIPgetNTotalVars(scip);
8664 
8665  /* initialize vector 'nodecreated' */
8666  SCIP_CALL( SCIPallocBufferArray(scip, &nodeorig, ntotalvars) );
8667  SCIP_CALL( SCIPallocBufferArray(scip, &nodecreated, ntotalvars) );
8668  for (i = 0; i < ntotalvars; ++i)
8669  nodecreated[i] = FALSE;
8670 
8671  /* compute number of SOS1 variables */
8672  cntsos = 0;
8673  for (c = 0; c < nconss; ++c)
8674  {
8675  SCIP_CONSDATA* consdata;
8676  SCIP_VAR** vars;
8677  int nvars;
8678 
8679  assert( conss[c] != NULL );
8680 
8681  /* get constraint data field of the constraint */
8682  consdata = SCIPconsGetData(conss[c]);
8683  assert( consdata != NULL );
8684 
8685  /* get variables and number of variables of constraint */
8686  nvars = consdata->nvars;
8687  vars = consdata->vars;
8688 
8689  /* update number of SOS1 variables */
8690  for (i = 0; i < nvars; ++i)
8691  {
8692  SCIP_VAR* var;
8693 
8694  var = vars[i];
8695 
8696  /* if the variable is not fixed to zero */
8697  if ( ! SCIPisFeasZero(scip, SCIPvarGetLbLocal(var)) || ! SCIPisFeasZero(scip, SCIPvarGetUbLocal(var)) )
8698  {
8699  int ind;
8700 
8701  ind = SCIPvarGetIndex(var);
8702  assert( ind >= 0 && ind < ntotalvars );
8703  if ( ! nodecreated[ind] )
8704  {
8705  nodecreated[ind] = TRUE; /* mark node as counted */
8706  nodeorig[ind] = cntsos;
8707  ++cntsos;
8708  }
8709  }
8710  }
8711  }
8712  if ( cntsos <= 0 )
8713  {
8714  /* free buffer arrays */
8715  SCIPfreeBufferArray(scip, &nodecreated);
8716  SCIPfreeBufferArray(scip, &nodeorig);
8717  conshdlrdata->nsos1vars = 0;
8718  return SCIP_OKAY;
8719  }
8720 
8721  /* reinitialize vector 'nodecreated' */
8722  for (i = 0; i < ntotalvars; ++i)
8723  nodecreated[i] = FALSE;
8724 
8725  /* create conflict graph */
8726  SCIP_CALL( SCIPdigraphCreate(&conshdlrdata->conflictgraph, cntsos) );
8727 
8728  /* set up hash map */
8729  SCIP_CALL( SCIPhashmapCreate(&conshdlrdata->varhash, SCIPblkmem(scip), cntsos) );
8730 
8731  /* for every SOS1 constraint */
8732  cntsos = 0;
8733  for (c = 0; c < nconss; ++c)
8734  {
8735  SCIP_CONSDATA* consdata;
8736  SCIP_VAR** vars;
8737  int nvars;
8738 
8739  assert( conss[c] != NULL );
8740 
8741  /* get constraint data field of the constraint */
8742  consdata = SCIPconsGetData(conss[c]);
8743  assert( consdata != NULL );
8744 
8745  /* get variables and number of variables of constraint */
8746  nvars = consdata->nvars;
8747  vars = consdata->vars;
8748 
8749  /* add edges to the conflict graph and create node data for each of its nodes */
8750  for (i = 0; i < nvars; ++i)
8751  {
8752  SCIP_VAR* var;
8753 
8754  var = vars[i];
8755 
8756  /* if the variable is not fixed to zero */
8757  if ( ! SCIPisFeasZero(scip, SCIPvarGetLbLocal(var)) || ! SCIPisFeasZero(scip, SCIPvarGetUbLocal(var)) )
8758  {
8759  int indi;
8760 
8761  indi = SCIPvarGetIndex(var);
8762 
8763  if ( ! nodecreated[indi] )
8764  {
8765  SCIP_NODEDATA* nodedata = NULL;
8766 
8767  /* insert node number to hash map */
8768  assert( ! SCIPhashmapExists(conshdlrdata->varhash, var) );
8769  SCIP_CALL( SCIPhashmapInsert(conshdlrdata->varhash, var, (void*) (size_t) cntsos) );/*lint !e571*/
8770  assert( cntsos == (int) (size_t) SCIPhashmapGetImage(conshdlrdata->varhash, var) );
8771  assert( SCIPhashmapExists(conshdlrdata->varhash, var) );
8772 
8773  /* create node data */
8774  SCIP_CALL( SCIPallocBlockMemory(scip, &nodedata) );
8775  nodedata->var = var;
8776  nodedata->lbboundvar = NULL;
8777  nodedata->ubboundvar = NULL;
8778  nodedata->lbboundcoef = 0.0;
8779  nodedata->ubboundcoef = 0.0;
8780  nodedata->lbboundcomp = FALSE;
8781  nodedata->ubboundcomp = FALSE;
8782 
8783  /* set node data */
8784  SCIPdigraphSetNodeData(conshdlrdata->conflictgraph, (void*)nodedata, cntsos);
8785 
8786  /* mark node and var data of node as created and update SOS1 counter */
8787  nodecreated[indi] = TRUE;
8788  ++cntsos;
8789  }
8790 
8791  /* add edges to the conflict graph */
8792  for (j = i+1; j < nvars; ++j)
8793  {
8794  var = vars[j];
8795 
8796  /* if the variable is not fixed to zero */
8797  if ( ! SCIPisFeasZero(scip, SCIPvarGetLbLocal(var)) || ! SCIPisFeasZero(scip, SCIPvarGetUbLocal(var)) )
8798  {
8799  int indj;
8800 
8801  indj = SCIPvarGetIndex(var);
8802 
8803  /* in case indi = indj the variable will be deleted in the presolving step */
8804  if ( indi != indj )
8805  {
8806  /* arcs have to be added 'safe' */
8807  SCIP_CALL( SCIPdigraphAddArcSafe(conshdlrdata->conflictgraph, nodeorig[indi], nodeorig[indj], NULL) );
8808  SCIP_CALL( SCIPdigraphAddArcSafe(conshdlrdata->conflictgraph, nodeorig[indj], nodeorig[indi], NULL) );
8809  }
8810  }
8811  }
8812  }
8813  }
8814  }
8815 
8816  /* set number of problem variables that are contained in at least one SOS1 constraint */
8817  conshdlrdata->nsos1vars = cntsos;
8818 
8819  /* free buffer arrays */
8820  SCIPfreeBufferArray(scip, &nodecreated);
8821  SCIPfreeBufferArray(scip, &nodeorig);
8822 
8823  /* sort successors in ascending order */
8824  for (j = 0; j < conshdlrdata->nsos1vars; ++j)
8825  {
8826  int nsucc;
8827 
8828  nsucc = SCIPdigraphGetNSuccessors(conshdlrdata->conflictgraph, j);
8829  SCIPsortInt(SCIPdigraphGetSuccessors(conshdlrdata->conflictgraph, j), nsucc);
8830  }
8831 
8832  return SCIP_OKAY;
8833 }
8834 
8835 
8836 /** free conflict graph, nodedata and hashmap */
8837 static
8839  SCIP* scip, /**< SCIP pointer */
8840  SCIP_CONSHDLRDATA* conshdlrdata /**< constraint handler data */
8841  )
8842 {
8843  int j;
8845  if ( conshdlrdata->conflictgraph == NULL )
8846  {
8847  assert( conshdlrdata->nsos1vars == 0 );
8848  return SCIP_OKAY;
8849  }
8850 
8851  /* for every SOS1 variable */
8852  assert( conshdlrdata->nsos1vars > 0 );
8853  for (j = 0; j < conshdlrdata->nsos1vars; ++j)
8854  {
8855  SCIP_NODEDATA* nodedata;
8856 
8857  /* get node data */
8858  assert( conshdlrdata->conflictgraph != NULL );
8859  nodedata = (SCIP_NODEDATA*)SCIPdigraphGetNodeData(conshdlrdata->conflictgraph, j);
8860  assert( nodedata != NULL );
8861 
8862  /* free node data */
8863  SCIPfreeBlockMemory(scip, &nodedata);
8864  SCIPdigraphSetNodeData(conshdlrdata->conflictgraph, NULL, j);
8865  }
8866 
8867  /* free conflict graph and hash map */
8868  assert( conshdlrdata->varhash != NULL );
8869  SCIPhashmapFree(&conshdlrdata->varhash);
8870  SCIPdigraphFree(&conshdlrdata->conflictgraph);
8871  conshdlrdata->nsos1vars = 0;
8872 
8873  assert( conshdlrdata->varhash == NULL );
8874  assert( conshdlrdata->conflictgraph == NULL );
8875 
8876  return SCIP_OKAY;
8877 }
8878 
8879 
8880 /* ---------------------------- constraint handler callback methods ----------------------*/
8881 
8882 /** copy method for constraint handler plugins (called when SCIP copies plugins) */
8883 static
8884 SCIP_DECL_CONSHDLRCOPY(conshdlrCopySOS1)
8885 { /*lint --e{715}*/
8886  assert( scip != NULL );
8887  assert( conshdlr != NULL );
8888  assert( strcmp(SCIPconshdlrGetName(conshdlr), CONSHDLR_NAME) == 0 );
8889 
8890  /* call inclusion method of constraint handler */
8892 
8893  *valid = TRUE;
8894 
8895  return SCIP_OKAY;
8896 }
8897 
8898 
8899 /** destructor of constraint handler to free constraint handler data (called when SCIP is exiting) */
8900 static
8901 SCIP_DECL_CONSFREE(consFreeSOS1)
8902 {
8903  SCIP_CONSHDLRDATA* conshdlrdata;
8904 
8905  assert( scip != NULL );
8906  assert( conshdlr != NULL );
8907  assert( strcmp(SCIPconshdlrGetName(conshdlr), CONSHDLR_NAME) == 0 );
8908 
8909  conshdlrdata = SCIPconshdlrGetData(conshdlr);
8910  assert(conshdlrdata != NULL);
8911 
8912  /* free stack of variables fixed to nonzero (usually already freed in consExitsolSOS1 unless instance was solved during presolving) */
8913  SCIPfreeBlockMemoryArrayNull(scip, &conshdlrdata->fixnonzerovars, conshdlrdata->maxnfixnonzerovars); /*lint !e737*/
8914 
8915  SCIPfreeBlockMemory(scip, &conshdlrdata);
8916 
8917  return SCIP_OKAY;
8918 }
8919 
8920 
8921 /** solving process initialization method of constraint handler (called when branch and bound process is about to begin) */
8922 static
8923 SCIP_DECL_CONSINITSOL(consInitsolSOS1)
8924 { /*lint --e{715}*/
8925  SCIP_CONSHDLRDATA* conshdlrdata;
8926 
8927  assert( scip != NULL );
8928  assert( conshdlr != NULL );
8929  assert( strcmp(SCIPconshdlrGetName(conshdlr), CONSHDLR_NAME) == 0 );
8930 
8931  conshdlrdata = SCIPconshdlrGetData(conshdlr);
8932  assert( conshdlrdata != NULL );
8933 
8934  conshdlrdata->nsos1vars = 0;
8935  conshdlrdata->varhash = NULL;
8936 
8937  if ( nconss > 0 )
8938  {
8939  /* initialize conflict graph and hashmap for SOS1 variables */
8940  SCIP_CALL( initConflictgraph(scip, conshdlrdata, conss, nconss) );
8941 
8942  /* add data to conflict graph nodes */
8943  SCIP_CALL( computeNodeDataSOS1(scip, conshdlrdata, conshdlrdata->nsos1vars) );
8944 
8945  if ( ( conshdlrdata->autosos1branch || conshdlrdata->autocutsfromsos1 )
8946  && ( ! conshdlrdata->switchsos1branch || ! conshdlrdata->switchcutsfromsos1 )
8947  )
8948  {
8949  /* switch to nonoverlapping methods if the SOS1 constraints do not overlap */
8950  SCIP_CALL( checkSwitchNonoverlappingSOS1Methods(scip, conshdlrdata, conshdlrdata->conflictgraph, conss, nconss) );
8951  }
8952 
8953  /* initialize tclique graph */
8954  SCIP_CALL( initTCliquegraph(scip, conshdlr, conshdlrdata, conshdlrdata->conflictgraph, conshdlrdata->nsos1vars) );
8955 
8956  /* create local conflict graph if needed */
8957  if ( conshdlrdata->addcomps )
8958  {
8959  SCIP_CALL( SCIPdigraphCreate(&conshdlrdata->localconflicts, conshdlrdata->nsos1vars) );
8960  }
8961 
8962  /* initialize stack of variables fixed to nonzero (memory may be already allocated in consTransSOS1()) */
8963  if ( conshdlrdata->fixnonzerovars == NULL )
8964  {
8965  conshdlrdata->maxnfixnonzerovars = conshdlrdata->nsos1vars;
8966  SCIP_CALL( SCIPallocBlockMemoryArray(scip, &conshdlrdata->fixnonzerovars, conshdlrdata->maxnfixnonzerovars) );
8967  }
8968  }
8969 
8970  return SCIP_OKAY;
8971 }
8972 
8973 
8974 /** solving process deinitialization method of constraint handler (called before branch and bound process data is freed) */
8975 static
8976 SCIP_DECL_CONSEXITSOL(consExitsolSOS1)
8977 { /*lint --e{715}*/
8978  SCIP_CONSHDLRDATA* conshdlrdata;
8979  int c;
8980 
8981  assert( scip != NULL );
8982  assert( conshdlr != NULL );
8983  assert( strcmp(SCIPconshdlrGetName(conshdlr), CONSHDLR_NAME) == 0 );
8984  conshdlrdata = SCIPconshdlrGetData(conshdlr);
8985  assert( conshdlrdata != NULL );
8986 
8987  /* check each constraint */
8988  for (c = 0; c < nconss; ++c)
8989  {
8990  SCIP_CONSDATA* consdata;
8991 
8992  assert( conss != NULL );
8993  assert( conss[c] != NULL );
8994  consdata = SCIPconsGetData(conss[c]);
8995  assert( consdata != NULL );
8996 
8997  SCIPdebugMsg(scip, "Exiting SOS1 constraint <%s>.\n", SCIPconsGetName(conss[c]) );
8998 
8999  /* free rows */
9000  if ( consdata->rowub != NULL )
9001  {
9002  SCIP_CALL( SCIPreleaseRow(scip, &consdata->rowub) );
9003  }
9004 
9005  if ( consdata->rowlb != NULL )
9006  {
9007  SCIP_CALL( SCIPreleaseRow(scip, &consdata->rowlb) );
9008  }
9009  }
9010 
9011  /* free implication graph */
9012  if ( conshdlrdata->implgraph != NULL )
9013  {
9014  SCIP_CALL( freeImplGraphSOS1(scip, conshdlrdata) );
9015  }
9016  assert( conshdlrdata->implgraph == NULL );
9017 
9018  /* free tclique graph and tclique data */
9019  if ( conshdlrdata->tcliquegraph != NULL )
9020  {
9021  assert( conshdlrdata->tcliquedata != NULL );
9022  SCIPfreeBlockMemory(scip, &conshdlrdata->tcliquedata);
9023  tcliqueFree(&conshdlrdata->tcliquegraph);
9024  }
9025  assert(conshdlrdata->tcliquegraph == NULL);
9026  assert(conshdlrdata->tcliquedata == NULL);
9027 
9028  /* free stack of variables fixed to nonzero */
9029  SCIPfreeBlockMemoryArrayNull(scip, &conshdlrdata->fixnonzerovars, conshdlrdata->maxnfixnonzerovars); /*lint !e737*/
9030  conshdlrdata->nfixnonzerovars = 0;
9031  conshdlrdata->maxnfixnonzerovars = 0;
9032 
9033  /* free graph for storing local conflicts */
9034  if ( conshdlrdata->localconflicts != NULL )
9035  SCIPdigraphFree(&conshdlrdata->localconflicts);
9036  assert( conshdlrdata->localconflicts == NULL );
9037 
9038  /* free conflict graph */
9039  SCIP_CALL( freeConflictgraph(scip, conshdlrdata) );
9040  assert( conshdlrdata->conflictgraph == NULL );
9041 
9042  return SCIP_OKAY;
9043 }
9044 
9045 
9046 /** frees specific constraint data */
9047 static
9048 SCIP_DECL_CONSDELETE(consDeleteSOS1)
9049 {
9050  assert( scip != NULL );
9051  assert( conshdlr != NULL );
9052  assert( cons != NULL );
9053  assert( consdata != NULL );
9054  assert( strcmp(SCIPconshdlrGetName(conshdlr), CONSHDLR_NAME) == 0 );
9055 
9056  SCIPdebugMsg(scip, "Deleting SOS1 constraint <%s>.\n", SCIPconsGetName(cons) );
9057 
9058  /* drop events on transformed variables */
9059  if ( SCIPconsIsTransformed(cons) )
9060  {
9061  SCIP_CONSHDLRDATA* conshdlrdata;
9062  int j;
9063 
9064  /* get constraint handler data */
9065  conshdlrdata = SCIPconshdlrGetData(conshdlr);
9066  assert( conshdlrdata != NULL );
9067  assert( conshdlrdata->eventhdlr != NULL );
9068 
9069  for (j = 0; j < (*consdata)->nvars; ++j)
9070  {
9071  SCIP_CALL( SCIPdropVarEvent(scip, (*consdata)->vars[j], SCIP_EVENTTYPE_BOUNDCHANGED, conshdlrdata->eventhdlr,
9072  (SCIP_EVENTDATA*)cons, -1) ); /*lint !e737 !e740*/
9073  }
9074  }
9075 
9076  SCIPfreeBlockMemoryArray(scip, &(*consdata)->vars, (*consdata)->maxvars);
9077  if ( (*consdata)->weights != NULL )
9078  {
9079  SCIPfreeBlockMemoryArray(scip, &(*consdata)->weights, (*consdata)->maxvars);
9080  }
9081 
9082  /* free rows */
9083  if ( (*consdata)->rowub != NULL )
9084  {
9085  SCIP_CALL( SCIPreleaseRow(scip, &(*consdata)->rowub) );
9086  }
9087  if ( (*consdata)->rowlb != NULL )
9088  {
9089  SCIP_CALL( SCIPreleaseRow(scip, &(*consdata)->rowlb) );
9090  }
9091  assert( (*consdata)->rowub == NULL );
9092  assert( (*consdata)->rowlb == NULL );
9093 
9094  SCIPfreeBlockMemory(scip, consdata);
9095 
9096  return SCIP_OKAY;
9097 }
9098 
9099 
9100 /** transforms constraint data into data belonging to the transformed problem */
9101 static
9102 SCIP_DECL_CONSTRANS(consTransSOS1)
9103 {
9104  SCIP_CONSDATA* consdata;
9105  SCIP_CONSHDLRDATA* conshdlrdata;
9106  SCIP_CONSDATA* sourcedata;
9107  char s[SCIP_MAXSTRLEN];
9108  int j;
9109 
9110  assert( scip != NULL );
9111  assert( conshdlr != NULL );
9112  assert( strcmp(SCIPconshdlrGetName(conshdlr), CONSHDLR_NAME) == 0 );
9113  assert( sourcecons != NULL );
9114  assert( targetcons != NULL );
9115 
9116  /* get constraint handler data */
9117  conshdlrdata = SCIPconshdlrGetData(conshdlr);
9118  assert( conshdlrdata != NULL );
9119  assert( conshdlrdata->eventhdlr != NULL );
9120 
9121  SCIPdebugMsg(scip, "Transforming SOS1 constraint: <%s>.\n", SCIPconsGetName(sourcecons) );
9122 
9123  /* get data of original constraint */
9124  sourcedata = SCIPconsGetData(sourcecons);
9125  assert( sourcedata != NULL );
9126  assert( sourcedata->nvars > 0 );
9127  assert( sourcedata->nvars <= sourcedata->maxvars );
9128 
9129  /* initialize stack of variables fixed to nonzero */
9130  if ( conshdlrdata->fixnonzerovars == NULL )
9131  {
9132  conshdlrdata->maxnfixnonzerovars = SCIPgetNTotalVars(scip);
9133  SCIP_CALL( SCIPallocBlockMemoryArray(scip, &conshdlrdata->fixnonzerovars, conshdlrdata->maxnfixnonzerovars) );
9134  }
9135 
9136  /* create constraint data */
9137  SCIP_CALL( SCIPallocBlockMemory(scip, &consdata) );
9138 
9139  consdata->nvars = sourcedata->nvars;
9140  consdata->maxvars = sourcedata->nvars;
9141  consdata->rowub = NULL;
9142  consdata->rowlb = NULL;
9143  consdata->nfixednonzeros = 0;
9144  consdata->local = sourcedata->local;
9145  SCIP_CALL( SCIPallocBlockMemoryArray(scip, &consdata->vars, consdata->nvars) );
9146  /* if weights were used */
9147  if ( sourcedata->weights != NULL )
9148  {
9149  SCIP_CALL( SCIPduplicateBlockMemoryArray(scip, &consdata->weights, sourcedata->weights, consdata->nvars) );
9150  }
9151  else
9152  consdata->weights = NULL;
9153 
9154  for (j = 0; j < sourcedata->nvars; ++j)
9155  {
9156  assert( sourcedata->vars[j] != 0 );
9157  SCIP_CALL( SCIPgetTransformedVar(scip, sourcedata->vars[j], &(consdata->vars[j])) );
9158 
9159  /* if variable is fixed to be nonzero */
9160  if ( SCIPisFeasPositive(scip, SCIPvarGetLbLocal(consdata->vars[j])) || SCIPisFeasNegative(scip, SCIPvarGetUbLocal(consdata->vars[j])) )
9161  ++(consdata->nfixednonzeros);
9162  }
9163 
9164  /* create transformed constraint with the same flags */
9165  (void) SCIPsnprintf(s, SCIP_MAXSTRLEN, "t_%s", SCIPconsGetName(sourcecons));
9166  SCIP_CALL( SCIPcreateCons(scip, targetcons, s, conshdlr, consdata,
9167  SCIPconsIsInitial(sourcecons), SCIPconsIsSeparated(sourcecons),
9168  SCIPconsIsEnforced(sourcecons), SCIPconsIsChecked(sourcecons),
9169  SCIPconsIsPropagated(sourcecons), SCIPconsIsLocal(sourcecons),
9170  SCIPconsIsModifiable(sourcecons), SCIPconsIsDynamic(sourcecons),
9171  SCIPconsIsRemovable(sourcecons), SCIPconsIsStickingAtNode(sourcecons)) );
9172 
9173  /* catch bound change events on variable */
9174  for (j = 0; j < consdata->nvars; ++j)
9175  {
9176  SCIP_CALL( SCIPcatchVarEvent(scip, consdata->vars[j], SCIP_EVENTTYPE_BOUNDCHANGED, conshdlrdata->eventhdlr,
9177  (SCIP_EVENTDATA*)*targetcons, NULL) ); /*lint !e740*/
9178  }
9179 
9180 #ifdef SCIP_DEBUG
9181  if ( consdata->nfixednonzeros > 0 )
9182  {
9183  SCIPdebugMsg(scip, "constraint <%s> has %d variables fixed to be nonzero.\n", SCIPconsGetName(*targetcons),
9184  consdata->nfixednonzeros );
9185  }
9186 #endif
9187 
9188  return SCIP_OKAY;
9189 }
9190 
9191 
9192 /** presolving method of constraint handler */
9193 static
9194 SCIP_DECL_CONSPRESOL(consPresolSOS1)
9195 { /*lint --e{715}*/
9196  SCIP_CONSHDLRDATA* conshdlrdata;
9197  int oldnfixedvars;
9198  int oldnchgbds;
9199  int oldndelconss;
9200  int oldnupgdconss;
9201  int nremovedvars;
9202 
9203  assert( scip != NULL );
9204  assert( conshdlr != NULL );
9205  assert( strcmp(SCIPconshdlrGetName(conshdlr), CONSHDLR_NAME) == 0 );
9206  assert( result != NULL );
9207 
9208  conshdlrdata = SCIPconshdlrGetData(conshdlr);
9209  assert( conshdlrdata != NULL );
9210 
9211  SCIPdebugMsg(scip, "Presolving SOS1 constraints.\n");
9212 
9213  *result = SCIP_DIDNOTRUN;
9214 
9215  SCIPdebug( oldnfixedvars = *nfixedvars; )
9216  SCIPdebug( oldnchgbds = *nchgbds; )
9217  SCIPdebug( oldndelconss = *ndelconss; )
9218  SCIPdebug( oldnupgdconss = *nupgdconss; )
9219  nremovedvars = 0;
9220 
9221  /* only run if success if possible */
9222  if( nconss > 0 && ( nrounds == 0 || nnewfixedvars > 0 || nnewaggrvars > 0 || nnewchgbds > 0 ) )
9223  {
9224  SCIP_Bool** adjacencymatrix = NULL;
9225  SCIP_DIGRAPH* conflictgraph;
9226  SCIP_EVENTHDLR* eventhdlr;
9227  int nsos1vars;
9228  int i;
9229  int j;
9230 
9231  *result = SCIP_DIDNOTFIND;
9232 
9233  /* get constraint handler data */
9234  assert( SCIPconshdlrGetData(conshdlr) != NULL );
9235  eventhdlr = SCIPconshdlrGetData(conshdlr)->eventhdlr;
9236  assert( eventhdlr != NULL );
9237 
9238  /* initialize conflict graph */
9239  SCIP_CALL( initConflictgraph(scip, conshdlrdata, conss, nconss));
9240 
9241  /* get conflict graph and number of SOS1 variables */
9242  conflictgraph = conshdlrdata->conflictgraph;
9243  nsos1vars = conshdlrdata->nsos1vars;
9244  if ( nsos1vars < 2 )
9245  {
9246  SCIP_CALL( freeConflictgraph(scip, conshdlrdata));
9247  return SCIP_OKAY;
9248  }
9249 
9250  /* we do not create the adjacency matrix of the conflict graph if the number of SOS1 variables is larger than a predefined value */
9251  if ( conshdlrdata->maxsosadjacency == -1 || nsos1vars <= conshdlrdata->maxsosadjacency )
9252  {
9253  /* allocate buffer arrays for adjacency matrix */
9254  SCIP_CALL( SCIPallocBufferArray(scip, &adjacencymatrix, nsos1vars) );
9255  for (i = 0; i < nsos1vars; ++i)
9256  {
9257  SCIP_CALL( SCIPallocBufferArray(scip, &adjacencymatrix[i], i+1) );/*lint !e866*/
9258  }
9259 
9260  /* create adjacency matrix */
9261  for (i = 0; i < nsos1vars; ++i)
9262  {
9263  for (j = 0; j < i+1; ++j)
9264  adjacencymatrix[i][j] = 0;
9265  }
9266  for (i = 0; i < nsos1vars; ++i)
9267  {
9268  int* succ;
9269  int nsucc;
9270 
9271  succ = SCIPdigraphGetSuccessors(conflictgraph, i);
9272  nsucc = SCIPdigraphGetNSuccessors(conflictgraph, i);
9273 
9274  for (j = 0; j < nsucc; ++j)
9275  {
9276  if ( i > succ[j] )
9277  adjacencymatrix[i][succ[j]] = 1;
9278  }
9279  }
9280  }
9281  else
9282  {
9283  SCIPdebugMsg(scip, "Adjacency matrix was not created since number of SOS1 variables (%d) is larger than %d.\n", nsos1vars, conshdlrdata->maxsosadjacency);
9284  }
9285 
9286  /* perform one presolving round for SOS1 constraints */
9287  SCIP_CALL( presolRoundConssSOS1(scip, eventhdlr, conshdlrdata, conflictgraph, adjacencymatrix, conss, nconss, nsos1vars, naddconss, ndelconss, nupgdconss, nfixedvars, &nremovedvars, result) );
9288 
9289  if ( adjacencymatrix != NULL )
9290  {
9291  /* perform one presolving round for SOS1 variables */
9292  if ( conshdlrdata->maxtightenbds != 0 && *result != SCIP_CUTOFF )
9293  {
9294  SCIP_CALL( presolRoundVarsSOS1(scip, conshdlrdata, conflictgraph, adjacencymatrix, nsos1vars, nfixedvars, nchgbds, naddconss, result) );
9295  }
9296 
9297  /* free adjacency matrix */
9298  for (j = nsos1vars-1; j >= 0; --j)
9299  SCIPfreeBufferArrayNull(scip, &adjacencymatrix[j]);
9300  SCIPfreeBufferArrayNull(scip, &adjacencymatrix);
9301  }
9302 
9303  /* free memory allocated in function initConflictgraph() */
9304  SCIP_CALL( freeConflictgraph(scip, conshdlrdata));
9305  }
9306  (*nchgcoefs) += nremovedvars;
9307 
9308  SCIPdebugMsg(scip, "presolving fixed %d variables, changed %d bounds, removed %d variables, deleted %d constraints, and upgraded %d constraints.\n",
9309  *nfixedvars - oldnfixedvars, *nchgbds - oldnchgbds, nremovedvars, *ndelconss - oldndelconss, *nupgdconss - oldnupgdconss);
9310 
9311  return SCIP_OKAY;
9312 }
9313 
9314 
9315 /** LP initialization method of constraint handler (called before the initial LP relaxation at a node is solved) */
9316 static
9317 SCIP_DECL_CONSINITLP(consInitlpSOS1)
9318 {
9319  SCIP_CONSHDLRDATA* conshdlrdata;
9320 
9321  assert( scip != NULL );
9322  assert( conshdlr != NULL );
9323  assert( strcmp(SCIPconshdlrGetName(conshdlr), CONSHDLR_NAME) == 0 );
9324 
9325  conshdlrdata = SCIPconshdlrGetData(conshdlr);
9326  assert( conshdlrdata != NULL );
9327 
9328  *infeasible = FALSE;
9329 
9330  /* checking for initial rows for SOS1 constraints */
9331  if( conshdlrdata->boundcutsfromsos1 || conshdlrdata->switchcutsfromsos1 )
9332  {
9333  SCIP_CALL( initsepaBoundInequalityFromSOS1Cons(scip, conshdlr, conshdlrdata, conss, nconss, NULL, FALSE, -1, NULL, infeasible) );
9334  }
9335 
9336  return SCIP_OKAY;
9337 }
9338 
9339 
9340 /** separation method of constraint handler for LP solutions */
9341 static
9342 SCIP_DECL_CONSSEPALP(consSepalpSOS1)
9343 { /*lint --e{715}*/
9344  assert( scip != NULL );
9345  assert( conshdlr != NULL );
9346  assert( conss != NULL );
9347  assert( strcmp(SCIPconshdlrGetName(conshdlr), CONSHDLR_NAME) == 0 );
9348  assert( result != NULL );
9349 
9350  SCIP_CALL( separateSOS1(scip, conshdlr, NULL, nconss, conss, result) );
9351 
9352  return SCIP_OKAY;
9353 }
9354 
9355 
9356 /** separation method of constraint handler for arbitrary primal solutions */
9357 static
9358 SCIP_DECL_CONSSEPASOL(consSepasolSOS1)
9359 { /*lint --e{715}*/
9360  assert( scip != NULL );
9361  assert( conshdlr != NULL );
9362  assert( conss != NULL );
9363  assert( strcmp(SCIPconshdlrGetName(conshdlr), CONSHDLR_NAME) == 0 );
9364  assert( result != NULL );
9365 
9366  SCIP_CALL( separateSOS1(scip, conshdlr, sol, nconss, conss, result) );
9367 
9368  return SCIP_OKAY;
9369 }
9370 
9371 
9372 /** constraint enforcing method of constraint handler for LP solutions */
9373 static
9374 SCIP_DECL_CONSENFOLP(consEnfolpSOS1)
9375 { /*lint --e{715}*/
9376  assert( scip != NULL );
9377  assert( conshdlr != NULL );
9378  assert( conss != NULL );
9379  assert( strcmp(SCIPconshdlrGetName(conshdlr), CONSHDLR_NAME) == 0 );
9380  assert( result != NULL );
9381 
9382  SCIP_CALL( enforceSOS1(scip, conshdlr, nconss, conss, NULL, result) );
9383 
9384  return SCIP_OKAY;
9385 }
9386 
9387 
9388 /** constraint enforcing method of constraint handler for relaxation solutions */
9389 static
9390 SCIP_DECL_CONSENFORELAX(consEnforelaxSOS1)
9391 { /*lint --e{715}*/
9392  assert( scip != NULL );
9393  assert( conshdlr != NULL );
9394  assert( conss != NULL );
9395  assert( strcmp(SCIPconshdlrGetName(conshdlr), CONSHDLR_NAME) == 0 );
9396  assert( result != NULL );
9397 
9398  SCIP_CALL( enforceSOS1(scip, conshdlr, nconss, conss, sol, result) );
9399 
9400  return SCIP_OKAY;
9401 }
9402 
9403 
9404 /** constraint enforcing method of constraint handler for pseudo solutions */
9405 static
9406 SCIP_DECL_CONSENFOPS(consEnfopsSOS1)
9407 { /*lint --e{715}*/
9408  assert( scip != NULL );
9409  assert( conshdlr != NULL );
9410  assert( conss != NULL );
9411  assert( strcmp(SCIPconshdlrGetName(conshdlr), CONSHDLR_NAME) == 0 );
9412  assert( result != NULL );
9413 
9414  SCIP_CALL( enforceSOS1(scip, conshdlr, nconss, conss, NULL, result) );
9415 
9416  return SCIP_OKAY;
9417 }
9418 
9419 
9420 /** feasibility check method of constraint handler for integral solutions
9421  *
9422  * We simply check whether at most one variable is nonzero in the given solution.
9423  */
9424 static
9425 SCIP_DECL_CONSCHECK(consCheckSOS1)
9426 { /*lint --e{715}*/
9427  int c;
9428 
9429  assert( scip != NULL );
9430  assert( conshdlr != NULL );
9431  assert( conss != NULL );
9432  assert( strcmp(SCIPconshdlrGetName(conshdlr), CONSHDLR_NAME) == 0 );
9433  assert( result != NULL );
9434 
9435  *result = SCIP_FEASIBLE;
9436 
9437  /* check each constraint */
9438  for (c = 0; c < nconss && (*result == SCIP_FEASIBLE || completely); ++c)
9439  {
9440  SCIP_CONSDATA* consdata;
9441  int j;
9442  int cnt;
9443 
9444  cnt = 0;
9445  assert( conss[c] != NULL );
9446  consdata = SCIPconsGetData(conss[c]);
9447  assert( consdata != NULL );
9448  SCIPdebugMsg(scip, "Checking SOS1 constraint <%s>.\n", SCIPconsGetName(conss[c]));
9449 
9450  /* check all variables */
9451  for (j = 0; j < consdata->nvars; ++j)
9452  {
9453  /* if variable is nonzero */
9454  if ( ! SCIPisFeasZero(scip, SCIPgetSolVal(scip, sol, consdata->vars[j])) )
9455  {
9456  ++cnt;
9457 
9458  /* if more than one variable is nonzero */
9459  if ( cnt > 1 )
9460  {
9461  SCIP_CALL( SCIPresetConsAge(scip, conss[c]) );
9462  *result = SCIP_INFEASIBLE;
9463 
9464  if ( printreason )
9465  {
9466  int l;
9467 
9468  SCIP_CALL( SCIPprintCons(scip, conss[c], NULL) );
9469  SCIPinfoMessage(scip, NULL, ";\nviolation: ");
9470 
9471  for (l = 0; l < consdata->nvars; ++l)
9472  {
9473  /* if variable is nonzero */
9474  if ( ! SCIPisFeasZero(scip, SCIPgetSolVal(scip, sol, consdata->vars[l])) )
9475  {
9476  SCIPinfoMessage(scip, NULL, "<%s> = %.15g ",
9477  SCIPvarGetName(consdata->vars[l]), SCIPgetSolVal(scip, sol, consdata->vars[l]));
9478  }
9479  }
9480  SCIPinfoMessage(scip, NULL, "\n");
9481  }
9482  }
9483  }
9484  }
9485  }
9486 
9487  return SCIP_OKAY;
9488 }
9489 
9490 
9491 /** domain propagation method of constraint handler */
9492 static
9493 SCIP_DECL_CONSPROP(consPropSOS1)
9494 { /*lint --e{715}*/
9495  SCIP_CONSHDLRDATA* conshdlrdata;
9496  SCIP_DIGRAPH* conflictgraph;
9497  SCIP_DIGRAPH* implgraph;
9498  int ngen = 0;
9500  assert( scip != NULL );
9501  assert( conshdlr != NULL );
9502  assert( conss != NULL );
9503  assert( strcmp(SCIPconshdlrGetName(conshdlr), CONSHDLR_NAME) == 0 );
9504  assert( result != NULL );
9505  assert( SCIPisTransformed(scip) );
9506 
9507  /* return if number of SOS1 constraints is zero */
9508  if ( nconss < 1 )
9509  {
9510  *result = SCIP_DIDNOTRUN;
9511  return SCIP_OKAY;
9512  }
9513  *result = SCIP_DIDNOTFIND;
9514 
9515  /* get constraint handler data */
9516  conshdlrdata = SCIPconshdlrGetData(conshdlr);
9517  assert( conshdlrdata != NULL );
9518 
9519  /* get conflict graph */
9520  conflictgraph = conshdlrdata->conflictgraph;
9521 
9522  /* get/initialize implication graph */
9523  implgraph = conshdlrdata->implgraph;
9524  if ( implgraph == NULL && conshdlrdata->implprop && conflictgraph != NULL )
9525  {
9526  if ( SCIPgetDepth(scip) == 0 )
9527  {
9528  SCIP_Bool success;
9529  SCIP_Bool cutoff;
9530  int nchbds;
9531 
9532  SCIP_CALL( initImplGraphSOS1(scip, conshdlrdata, conflictgraph, conshdlrdata->nsos1vars, conshdlrdata->maxtightenbds, &nchbds, &cutoff, &success) );
9533  if ( ! success )
9534  conshdlrdata->implprop = FALSE;
9535 
9536  if ( cutoff )
9537  {
9538  *result = SCIP_CUTOFF;
9539  return SCIP_OKAY;
9540  }
9541  else if ( nchbds > 0 )
9542  *result = SCIP_REDUCEDDOM;
9543  implgraph = conshdlrdata->implgraph;
9544  }
9545  else
9546  conshdlrdata->implprop = FALSE;
9547  }
9548 
9549  /* if conflict graph propagation shall be used */
9550  if ( conshdlrdata->conflictprop && conflictgraph != NULL )
9551  {
9552  SCIP_VAR** fixnonzerovars;
9553  int nfixnonzerovars;
9554  int j;
9555 
9556  assert( nconss > 0 );
9557 
9558  /* stack of variables fixed to nonzero */
9559  nfixnonzerovars = conshdlrdata->nfixnonzerovars;
9560  fixnonzerovars = conshdlrdata->fixnonzerovars;
9561  assert( fixnonzerovars != NULL );
9562 
9563  /* check each variable from stack */
9564  for (j = 0; j < nfixnonzerovars; ++j)
9565  {
9566  SCIP_VAR* var;
9567 
9568  var = fixnonzerovars[j];
9569  if ( var != NULL )
9570  {
9571  int node;
9572  node = varGetNodeSOS1(conshdlrdata, var);
9573 
9574  /* if variable is involved in an SOS1 constraint */
9575  if ( node >= 0 )
9576  {
9577  assert( varGetNodeSOS1(conshdlrdata, var) < conshdlrdata->nsos1vars );
9578  SCIPdebugMsg(scip, "Propagating SOS1 variable <%s>.\n", SCIPvarGetName(var) );
9579 
9580  /* if zero is outside the domain of variable */
9582  {
9583  SCIP_Bool cutoff;
9584 
9585  SCIP_CALL( propVariableNonzero(scip, conflictgraph, implgraph, conss[0], node, conshdlrdata->implprop, &cutoff, &ngen) );
9586  if ( cutoff )
9587  {
9588  *result = SCIP_CUTOFF;
9589  return SCIP_OKAY;
9590  }
9591  }
9592  }
9593  }
9594  }
9595  }
9596  conshdlrdata->nfixnonzerovars = 0;
9597 
9598  /* if SOS1 constraint propagation shall be used */
9599  if ( conshdlrdata->sosconsprop || conflictgraph == NULL )
9600  {
9601  int c;
9602 
9603  /* check each constraint */
9604  for (c = 0; c < nconss; ++c)
9605  {
9606  SCIP_CONS* cons;
9607  SCIP_CONSDATA* consdata;
9608  SCIP_Bool cutoff;
9609 
9610  assert( conss[c] != NULL );
9611  cons = conss[c];
9612  consdata = SCIPconsGetData(cons);
9613  assert( consdata != NULL );
9614  SCIPdebugMsg(scip, "Propagating SOS1 constraint <%s>.\n", SCIPconsGetName(cons) );
9615 
9616  SCIP_CALL( propConsSOS1(scip, cons, consdata, &cutoff, &ngen) );
9617  if ( cutoff )
9618  {
9619  *result = SCIP_CUTOFF;
9620  return SCIP_OKAY;
9621  }
9622  }
9623  }
9624 
9625  SCIPdebugMsg(scip, "Propagated %d domains.\n", ngen);
9626  if ( ngen > 0 )
9627  *result = SCIP_REDUCEDDOM;
9628 
9629  return SCIP_OKAY;
9630 }
9631 
9632 
9633 /** propagation conflict resolving method of constraint handler
9634  *
9635  * We check which bound changes were the reason for infeasibility. We
9636  * use that @a inferinfo stores the index of the variable that has
9637  * bounds that fix it to be nonzero (these bounds are the reason). */
9638 static
9639 SCIP_DECL_CONSRESPROP(consRespropSOS1)
9640 { /*lint --e{715}*/
9641  SCIP_VAR* var;
9642 
9643  assert( scip != NULL );
9644  assert( cons != NULL );
9645  assert( strcmp(SCIPconshdlrGetName(conshdlr), CONSHDLR_NAME) == 0 );
9646  assert( infervar != NULL );
9647  assert( bdchgidx != NULL );
9648  assert( result != NULL );
9649 
9650  *result = SCIP_DIDNOTFIND;
9651  SCIPdebugMsg(scip, "Propagation resolution method of SOS1 constraint <%s>.\n", SCIPconsGetName(cons));
9652 
9653  /* check whether conflict was detected in variable propagation or constraint propagation */
9654  if ( inferinfo < 0 )
9655  {
9656  SCIP_CONSHDLRDATA* conshdlrdata;
9657 
9658  assert( conshdlr != NULL );
9659 
9660  /* get constraint handler data */
9661  conshdlrdata = SCIPconshdlrGetData(conshdlr);
9662  assert( conshdlrdata != NULL );
9663  assert( conshdlrdata->conflictgraph != NULL );
9664  assert( inferinfo >= -conshdlrdata->maxnfixnonzerovars );
9665  assert( inferinfo >= -conshdlrdata->nsos1vars );
9666  assert( inferinfo <= -1 );
9667 
9668  var = SCIPnodeGetVarSOS1(conshdlrdata->conflictgraph, -inferinfo - 1);
9669  }
9670  else
9671  {
9672  SCIP_CONSDATA* consdata;
9673 
9674  /* get constraint data */
9675  consdata = SCIPconsGetData(cons);
9676  assert( consdata != NULL );
9677  assert( inferinfo < consdata->nvars );
9678 
9679  var = consdata->vars[inferinfo];
9680  }
9681  assert( var != NULL );
9682  assert( var != infervar );
9683 
9684  /* check if lower bound of var was the reason */
9685  if ( SCIPisFeasPositive(scip, SCIPgetVarLbAtIndex(scip, var, bdchgidx, FALSE)) )
9686  {
9687  SCIP_CALL( SCIPaddConflictLb(scip, var, bdchgidx) );
9688  *result = SCIP_SUCCESS;
9689  }
9690 
9691  /* check if upper bound of var was the reason */
9692  if ( SCIPisFeasNegative(scip, SCIPgetVarUbAtIndex(scip, var, bdchgidx, FALSE)) )
9693  {
9694  SCIP_CALL( SCIPaddConflictUb(scip, var, bdchgidx) );
9695  *result = SCIP_SUCCESS;
9696  }
9697 
9698  return SCIP_OKAY;
9699 }
9700 
9701 
9702 /** variable rounding lock method of constraint handler
9703  *
9704  * Let lb and ub be the lower and upper bounds of a
9705  * variable. Preprocessing usually makes sure that lb <= 0 <= ub.
9706  *
9707  * - If lb < 0 then rounding down may violate the constraint.
9708  * - If ub > 0 then rounding up may violated the constraint.
9709  * - If lb > 0 or ub < 0 then the constraint is infeasible and we do
9710  * not have to deal with it here.
9711  * - If lb == 0 then rounding down does not violate the constraint.
9712  * - If ub == 0 then rounding up does not violate the constraint.
9713  */
9714 static
9715 SCIP_DECL_CONSLOCK(consLockSOS1)
9716 {
9717  SCIP_CONSDATA* consdata;
9718  SCIP_VAR** vars;
9719  int nvars;
9720  int j;
9722  assert( scip != NULL );
9723  assert( conshdlr != NULL );
9724  assert( cons != NULL );
9725  assert( strcmp(SCIPconshdlrGetName(conshdlr), CONSHDLR_NAME) == 0 );
9726  consdata = SCIPconsGetData(cons);
9727  assert( consdata != NULL );
9728 
9729  SCIPdebugMsg(scip, "Locking constraint <%s>.\n", SCIPconsGetName(cons));
9730 
9731  vars = consdata->vars;
9732  nvars = consdata->nvars;
9733  assert( vars != NULL );
9734 
9735  for (j = 0; j < nvars; ++j)
9736  {
9737  SCIP_VAR* var;
9738  var = vars[j];
9739 
9740  /* if lower bound is negative, rounding down may violate constraint */
9741  if ( SCIPisFeasNegative(scip, SCIPvarGetLbLocal(var)) )
9742  {
9743  SCIP_CALL( SCIPaddVarLocks(scip, var, nlockspos, nlocksneg) );
9744  }
9745 
9746  /* additionally: if upper bound is positive, rounding up may violate constraint */
9747  if ( SCIPisFeasPositive(scip, SCIPvarGetUbLocal(var)) )
9748  {
9749  SCIP_CALL( SCIPaddVarLocks(scip, var, nlocksneg, nlockspos) );
9750  }
9751  }
9752 
9753  return SCIP_OKAY;
9754 }
9755 
9756 
9757 /** constraint display method of constraint handler */
9758 static
9759 SCIP_DECL_CONSPRINT(consPrintSOS1)
9760 { /*lint --e{715}*/
9761  SCIP_CONSDATA* consdata;
9762  int j;
9763 
9764  assert( scip != NULL );
9765  assert( conshdlr != NULL );
9766  assert( cons != NULL );
9767  assert( strcmp(SCIPconshdlrGetName(conshdlr), CONSHDLR_NAME) == 0 );
9768 
9769  consdata = SCIPconsGetData(cons);
9770  assert( consdata != NULL );
9771 
9772  for (j = 0; j < consdata->nvars; ++j)
9773  {
9774  if ( j > 0 )
9775  SCIPinfoMessage(scip, file, ", ");
9776  SCIP_CALL( SCIPwriteVarName(scip, file, consdata->vars[j], FALSE) );
9777  if ( consdata->weights == NULL )
9778  SCIPinfoMessage(scip, file, " (%d)", j+1);
9779  else
9780  SCIPinfoMessage(scip, file, " (%3.2f)", consdata->weights[j]);
9781  }
9782 
9783  return SCIP_OKAY;
9784 }
9785 
9786 
9787 /** constraint copying method of constraint handler */
9788 static
9789 SCIP_DECL_CONSCOPY(consCopySOS1)
9790 { /*lint --e{715}*/
9791  SCIP_CONSDATA* sourceconsdata;
9792  SCIP_VAR** sourcevars;
9793  SCIP_VAR** targetvars;
9794  SCIP_Real* sourceweights;
9795  SCIP_Real* targetweights;
9796  const char* consname;
9797  int nvars;
9798  int v;
9799 
9800  assert( scip != NULL );
9801  assert( sourcescip != NULL );
9802  assert( sourcecons != NULL );
9803  assert( strcmp(SCIPconshdlrGetName(SCIPconsGetHdlr(sourcecons)), CONSHDLR_NAME) == 0 );
9804 
9805  *valid = TRUE;
9806 
9807  if ( name != NULL )
9808  consname = name;
9809  else
9810  consname = SCIPconsGetName(sourcecons);
9811 
9812  SCIPdebugMsg(scip, "Copying SOS1 constraint <%s> ...\n", consname);
9813 
9814  sourceconsdata = SCIPconsGetData(sourcecons);
9815  assert( sourceconsdata != NULL );
9816 
9817  /* get variables and weights of the source constraint */
9818  nvars = sourceconsdata->nvars;
9819 
9820  if ( nvars == 0 )
9821  return SCIP_OKAY;
9822 
9823  sourcevars = sourceconsdata->vars;
9824  assert( sourcevars != NULL );
9825  sourceweights = sourceconsdata->weights;
9826  assert( sourceweights != NULL );
9827 
9828  /* duplicate variable array */
9829  SCIP_CALL( SCIPallocBufferArray(sourcescip, &targetvars, nvars) );
9830  SCIP_CALL( SCIPduplicateBufferArray(sourcescip, &targetweights, sourceweights, nvars) );
9831 
9832  /* get copied variables in target SCIP */
9833  for( v = 0; v < nvars && *valid; ++v )
9834  {
9835  SCIP_CALL( SCIPgetVarCopy(sourcescip, scip, sourcevars[v], &(targetvars[v]), varmap, consmap, global, valid) );
9836  }
9837 
9838  /* only create the target constraint, if all variables could be copied */
9839  if( *valid )
9840  {
9841  SCIP_CALL( SCIPcreateConsSOS1(scip, cons, consname, nvars, targetvars, targetweights,
9842  initial, separate, enforce, check, propagate, local, dynamic, removable, stickingatnode) );
9843  }
9844 
9845  /* free buffer array */
9846  SCIPfreeBufferArray(sourcescip, &targetweights);
9847  SCIPfreeBufferArray(sourcescip, &targetvars);
9848 
9849  return SCIP_OKAY;
9850 }
9851 
9852 
9853 /** constraint parsing method of constraint handler */
9854 static
9855 SCIP_DECL_CONSPARSE(consParseSOS1)
9856 { /*lint --e{715}*/
9857  SCIP_VAR* var;
9858  SCIP_Real weight;
9859  const char* s;
9860  char* t;
9862  assert(scip != NULL);
9863  assert(conshdlr != NULL);
9864  assert( strcmp(SCIPconshdlrGetName(conshdlr), CONSHDLR_NAME) == 0 );
9865  assert(cons != NULL);
9866  assert(success != NULL);
9867 
9868  *success = TRUE;
9869  s = str;
9870 
9871  /* create empty SOS1 constraint */
9872  SCIP_CALL( SCIPcreateConsSOS1(scip, cons, name, 0, NULL, NULL, initial, separate, enforce, check, propagate, local, dynamic, removable, stickingatnode) );
9873 
9874  /* loop through string */
9875  do
9876  {
9877  /* parse variable name */
9878  SCIP_CALL( SCIPparseVarName(scip, s, &var, &t) );
9879  s = t;
9880 
9881  /* skip until beginning of weight */
9882  while ( *s != '\0' && *s != '(' )
9883  ++s;
9884 
9885  if ( *s == '\0' )
9886  {
9887  SCIPverbMessage(scip, SCIP_VERBLEVEL_MINIMAL, NULL, "Syntax error: expected weight at input: %s\n", s);
9888  *success = FALSE;
9889  return SCIP_OKAY;
9890  }
9891  /* skip '(' */
9892  ++s;
9893 
9894  /* find weight */
9895  weight = strtod(s, &t);
9896  if ( t == NULL )
9897  {
9898  SCIPverbMessage(scip, SCIP_VERBLEVEL_MINIMAL, NULL, "Syntax error during parsing of the weight: %s\n", s);
9899  *success = FALSE;
9900  return SCIP_OKAY;
9901  }
9902  s = t;
9903 
9904  /* skip white space, ',', and ')' */
9905  while ( *s != '\0' && ( isspace((unsigned char)*s) || *s == ',' || *s == ')' ) )
9906  ++s;
9907 
9908  /* add variable */
9909  SCIP_CALL( SCIPaddVarSOS1(scip, *cons, var, weight) );
9910  }
9911  while ( *s != '\0' );
9912 
9913  return SCIP_OKAY;
9914 }
9915 
9916 
9917 /** constraint method of constraint handler which returns the variables (if possible) */
9918 static
9919 SCIP_DECL_CONSGETVARS(consGetVarsSOS1)
9920 { /*lint --e{715}*/
9921  SCIP_CONSDATA* consdata;
9922 
9923  consdata = SCIPconsGetData(cons);
9924  assert(consdata != NULL);
9926  if( varssize < consdata->nvars )
9927  (*success) = FALSE;
9928  else
9929  {
9930  assert(vars != NULL);
9931 
9932  BMScopyMemoryArray(vars, consdata->vars, consdata->nvars);
9933  (*success) = TRUE;
9934  }
9935 
9936  return SCIP_OKAY;
9937 }
9938 
9939 
9940 /** constraint method of constraint handler which returns the number of variables (if possible) */
9941 static
9942 SCIP_DECL_CONSGETNVARS(consGetNVarsSOS1)
9943 { /*lint --e{715}*/
9944  SCIP_CONSDATA* consdata;
9945 
9946  consdata = SCIPconsGetData(cons);
9947  assert(consdata != NULL);
9949  (*nvars) = consdata->nvars;
9950  (*success) = TRUE;
9951 
9952  return SCIP_OKAY;
9953 }
9954 
9955 
9956 /* ---------------- Callback methods of event handler ---------------- */
9957 
9958 /** exec the event handler
9959  *
9960  * We update the number of variables fixed to be nonzero
9961  */
9962 static
9963 SCIP_DECL_EVENTEXEC(eventExecSOS1)
9964 {
9965  SCIP_CONSHDLRDATA* conshdlrdata;
9966  SCIP_EVENTTYPE eventtype;
9967  SCIP_CONSHDLR* conshdlr;
9968  SCIP_CONSDATA* consdata;
9969  SCIP_CONS* cons;
9970  SCIP_Real oldbound;
9971  SCIP_Real newbound;
9972 
9973  assert( eventhdlr != NULL );
9974  assert( eventdata != NULL );
9975  assert( strcmp(SCIPeventhdlrGetName(eventhdlr), EVENTHDLR_NAME) == 0 );
9976  assert( event != NULL );
9977 
9978  cons = (SCIP_CONS*)eventdata;
9979  assert( cons != NULL );
9980  consdata = SCIPconsGetData(cons);
9981  assert( 0 <= consdata->nfixednonzeros && consdata->nfixednonzeros <= consdata->nvars );
9982 
9983  oldbound = SCIPeventGetOldbound(event);
9984  newbound = SCIPeventGetNewbound(event);
9985 
9986  eventtype = SCIPeventGetType(event);
9987  switch ( eventtype )
9988  {
9990  /* if variable is now fixed to be nonzero */
9991  if ( ! SCIPisFeasPositive(scip, oldbound) && SCIPisFeasPositive(scip, newbound) )
9992  {
9993  conshdlr = SCIPconsGetHdlr(cons);
9994  assert( conshdlr != NULL );
9995  conshdlrdata = SCIPconshdlrGetData(conshdlr);
9996  assert( conshdlrdata != NULL );
9997 
9998  /* store variable fixed to be nonzero on stack */
9999  assert( 0 <= conshdlrdata->nfixnonzerovars && conshdlrdata->nfixnonzerovars <= SCIPgetNTotalVars(scip) );
10000  if ( conshdlrdata->nfixnonzerovars < conshdlrdata->maxnfixnonzerovars )
10001  {
10002  assert( conshdlrdata->fixnonzerovars != NULL );
10003  assert( SCIPeventGetVar(event) != NULL );
10004  conshdlrdata->fixnonzerovars[conshdlrdata->nfixnonzerovars++] = SCIPeventGetVar(event);
10005  }
10006 
10007  ++(consdata->nfixednonzeros);
10008  }
10009  break;
10010 
10012  /* if variable is now fixed to be nonzero */
10013  if ( ! SCIPisFeasNegative(scip, oldbound) && SCIPisFeasNegative(scip, newbound) )
10014  {
10015  conshdlr = SCIPconsGetHdlr(cons);
10016  assert( conshdlr != NULL );
10017  conshdlrdata = SCIPconshdlrGetData(conshdlr);
10018  assert( conshdlrdata != NULL );
10019 
10020  /* store variable fixed to be nonzero on stack */
10021  assert( 0 <= conshdlrdata->nfixnonzerovars && conshdlrdata->nfixnonzerovars <= SCIPgetNTotalVars(scip) );
10022  if ( conshdlrdata->nfixnonzerovars < conshdlrdata->maxnfixnonzerovars )
10023  {
10024  assert( conshdlrdata->fixnonzerovars != NULL );
10025  assert( SCIPeventGetVar(event) != NULL );
10026  conshdlrdata->fixnonzerovars[conshdlrdata->nfixnonzerovars++] = SCIPeventGetVar(event);
10027  }
10028 
10029  ++(consdata->nfixednonzeros);
10030  }
10031  break;
10032 
10034  /* if variable is not fixed to be nonzero anymore */
10035  if ( SCIPisFeasPositive(scip, oldbound) && ! SCIPisFeasPositive(scip, newbound) )
10036  --(consdata->nfixednonzeros);
10037  break;
10038 
10040  /* if variable is not fixed to be nonzero anymore */
10041  if ( SCIPisFeasNegative(scip, oldbound) && ! SCIPisFeasNegative(scip, newbound) )
10042  --(consdata->nfixednonzeros);
10043  break;
10044 
10045  default:
10046  SCIPerrorMessage("invalid event type.\n");
10047  return SCIP_INVALIDDATA;
10048  }
10049  assert( 0 <= consdata->nfixednonzeros && consdata->nfixednonzeros <= consdata->nvars );
10050 
10051  SCIPdebugMsg(scip, "changed bound of variable <%s> from %f to %f (nfixednonzeros: %d).\n", SCIPvarGetName(SCIPeventGetVar(event)),
10052  oldbound, newbound, consdata->nfixednonzeros);
10053 
10054  return SCIP_OKAY;
10055 }
10056 
10057 
10058 /** constraint handler method to determine a diving variable by assigning a variable and two values for diving */
10059 static
10060 SCIP_DECL_CONSGETDIVEBDCHGS(consGetDiveBdChgsSOS1)
10061 {
10062  SCIP_CONSHDLRDATA* conshdlrdata;
10063 
10064  assert( scip != NULL );
10065  assert( conshdlr != NULL );
10066  assert( strcmp(SCIPconshdlrGetName(conshdlr), CONSHDLR_NAME) == 0 );
10067  assert( diveset != NULL );
10068  assert( success != NULL );
10069  assert( infeasible != NULL );
10070 
10071  *infeasible = FALSE;
10072  *success = FALSE;
10073 
10074  if ( strcmp(SCIPconshdlrGetName(conshdlr), CONSHDLR_NAME) != 0 )
10075  {
10076  SCIPerrorMessage("not an SOS1 constraint handler.\n");
10077  return SCIP_INVALIDDATA;
10078  }
10079  conshdlrdata = SCIPconshdlrGetData(conshdlr);
10080  assert( conshdlrdata != NULL );
10081 
10082  /* if the SOS1 constraints do not overlap, we apply a faster method getDiveBdChgsSOS1constraints() that does not make use of the conflict graph;
10083  * for overlapping SOS1 constraints we apply the method getDiveBdChgsSOS1conflictgraph(), which then may produce better results (e.g. due to more
10084  * diving candidates) */
10085  if ( conshdlrdata->switchsos1branch )
10086  {
10087  SCIP_CALL( getDiveBdChgsSOS1constraints(scip, conshdlr, diveset, sol, success) );
10088  }
10089  else
10090  {
10091  SCIP_CALL( getDiveBdChgsSOS1conflictgraph(scip, conshdlr, diveset, sol, success) );
10092  }
10093 
10094  return SCIP_OKAY;
10095 }
10096 
10097 
10098 /* ---------------- Constraint specific interface methods ---------------- */
10099 
10100 /** creates the handler for SOS1 constraints and includes it in SCIP */
10102  SCIP* scip /**< SCIP data structure */
10103  )
10104 {
10105  SCIP_CONSHDLRDATA* conshdlrdata;
10106  SCIP_CONSHDLR* conshdlr;
10108  /* create constraint handler data */
10109  SCIP_CALL( SCIPallocBlockMemory(scip, &conshdlrdata) );
10110  conshdlrdata->branchsos = TRUE;
10111  conshdlrdata->switchsos1branch = FALSE;
10112  conshdlrdata->switchcutsfromsos1 = FALSE;
10113  conshdlrdata->eventhdlr = NULL;
10114  conshdlrdata->fixnonzerovars = NULL;
10115  conshdlrdata->maxnfixnonzerovars = 0;
10116  conshdlrdata->nfixnonzerovars = 0;
10117  conshdlrdata->conflictgraph = NULL;
10118  conshdlrdata->localconflicts = NULL;
10119  conshdlrdata->isconflocal = FALSE;
10120  conshdlrdata->implgraph = NULL;
10121  conshdlrdata->nimplnodes = 0;
10122  conshdlrdata->nboundcuts = 0;
10123  conshdlrdata->tcliquegraph = NULL;
10124  conshdlrdata->tcliquedata = NULL;
10125  conshdlrdata->cntextsos1 = -1;
10126  conshdlrdata->varhash = NULL;
10127 
10128  /* create event handler for bound change events */
10129  SCIP_CALL( SCIPincludeEventhdlrBasic(scip, &conshdlrdata->eventhdlr, EVENTHDLR_NAME, EVENTHDLR_DESC, eventExecSOS1, NULL) );
10130  if ( conshdlrdata->eventhdlr == NULL )
10131  {
10132  SCIPerrorMessage("event handler for SOS1 constraints not found.\n");
10133  return SCIP_PLUGINNOTFOUND;
10134  }
10135 
10136  /* include constraint handler */
10139  consEnfolpSOS1, consEnfopsSOS1, consCheckSOS1, consLockSOS1, conshdlrdata) );
10140  assert(conshdlr != NULL);
10141 
10142  /* set non-fundamental callbacks via specific setter functions */
10143  SCIP_CALL( SCIPsetConshdlrCopy(scip, conshdlr, conshdlrCopySOS1, consCopySOS1) );
10144  SCIP_CALL( SCIPsetConshdlrDelete(scip, conshdlr, consDeleteSOS1) );
10145  SCIP_CALL( SCIPsetConshdlrGetDiveBdChgs(scip, conshdlr, consGetDiveBdChgsSOS1) );
10146  SCIP_CALL( SCIPsetConshdlrExitsol(scip, conshdlr, consExitsolSOS1) );
10147  SCIP_CALL( SCIPsetConshdlrInitsol(scip, conshdlr, consInitsolSOS1) );
10148  SCIP_CALL( SCIPsetConshdlrFree(scip, conshdlr, consFreeSOS1) );
10149  SCIP_CALL( SCIPsetConshdlrGetVars(scip, conshdlr, consGetVarsSOS1) );
10150  SCIP_CALL( SCIPsetConshdlrGetNVars(scip, conshdlr, consGetNVarsSOS1) );
10151  SCIP_CALL( SCIPsetConshdlrInitlp(scip, conshdlr, consInitlpSOS1) );
10152  SCIP_CALL( SCIPsetConshdlrParse(scip, conshdlr, consParseSOS1) );
10153  SCIP_CALL( SCIPsetConshdlrPresol(scip, conshdlr, consPresolSOS1, CONSHDLR_MAXPREROUNDS, CONSHDLR_PRESOLTIMING) );
10154  SCIP_CALL( SCIPsetConshdlrPrint(scip, conshdlr, consPrintSOS1) );
10156  SCIP_CALL( SCIPsetConshdlrResprop(scip, conshdlr, consRespropSOS1) );
10157  SCIP_CALL( SCIPsetConshdlrSepa(scip, conshdlr, consSepalpSOS1, consSepasolSOS1, CONSHDLR_SEPAFREQ, CONSHDLR_SEPAPRIORITY, CONSHDLR_DELAYSEPA) );
10158  SCIP_CALL( SCIPsetConshdlrTrans(scip, conshdlr, consTransSOS1) );
10159  SCIP_CALL( SCIPsetConshdlrEnforelax(scip, conshdlr, consEnforelaxSOS1) );
10160 
10161  /* add SOS1 constraint handler parameters */
10162 
10163  /* adjacency matrix parameters */
10164  SCIP_CALL( SCIPaddIntParam(scip, "constraints/" CONSHDLR_NAME "/maxsosadjacency",
10165  "do not create an adjacency matrix if number of SOS1 variables is larger than predefined value (-1: no limit)",
10166  &conshdlrdata->maxsosadjacency, TRUE, DEFAULT_MAXSOSADJACENCY, -1, INT_MAX, NULL, NULL) );
10167 
10168  /* presolving parameters */
10169  SCIP_CALL( SCIPaddIntParam(scip, "constraints/" CONSHDLR_NAME "/maxextensions",
10170  "maximal number of extensions that will be computed for each SOS1 constraint (-1: no limit)",
10171  &conshdlrdata->maxextensions, TRUE, DEFAULT_MAXEXTENSIONS, -1, INT_MAX, NULL, NULL) );
10172 
10173  SCIP_CALL( SCIPaddIntParam(scip, "constraints/" CONSHDLR_NAME "/maxtightenbds",
10174  "maximal number of bound tightening rounds per presolving round (-1: no limit)",
10175  &conshdlrdata->maxtightenbds, TRUE, DEFAULT_MAXTIGHTENBDS, -1, INT_MAX, NULL, NULL) );
10176 
10177  SCIP_CALL( SCIPaddBoolParam(scip, "constraints/" CONSHDLR_NAME "/perfimplanalysis",
10178  "if TRUE then perform implication graph analysis (might add additional SOS1 constraints)",
10179  &conshdlrdata->perfimplanalysis, TRUE, DEFAULT_PERFIMPLANALYSIS, NULL, NULL) );
10180 
10181  SCIP_CALL( SCIPaddIntParam(scip, "constraints/" CONSHDLR_NAME "/depthimplanalysis",
10182  "number of recursive calls of implication graph analysis (-1: no limit)",
10183  &conshdlrdata->depthimplanalysis, TRUE, DEFAULT_DEPTHIMPLANALYSIS, -1, INT_MAX, NULL, NULL) );
10184 
10185  /* propagation parameters */
10186  SCIP_CALL( SCIPaddBoolParam(scip, "constraints/" CONSHDLR_NAME "/conflictprop",
10187  "whether to use conflict graph propagation",
10188  &conshdlrdata->conflictprop, TRUE, DEFAULT_CONFLICTPROP, NULL, NULL) );
10189 
10190  SCIP_CALL( SCIPaddBoolParam(scip, "constraints/" CONSHDLR_NAME "/implprop",
10191  "whether to use implication graph propagation",
10192  &conshdlrdata->implprop, TRUE, DEFAULT_IMPLPROP, NULL, NULL) );
10193 
10194  SCIP_CALL( SCIPaddBoolParam(scip, "constraints/" CONSHDLR_NAME "/sosconsprop",
10195  "whether to use SOS1 constraint propagation",
10196  &conshdlrdata->sosconsprop, TRUE, DEFAULT_SOSCONSPROP, NULL, NULL) );
10197 
10198  /* branching parameters */
10199  SCIP_CALL( SCIPaddCharParam(scip, "constraints/" CONSHDLR_NAME "/branchingrule",
10200  "which branching rule should be applied ? ('n': neighborhood, 'b': bipartite, 's': SOS1/clique) (note: in some cases an automatic switching to SOS1 branching is possible)",
10201  &conshdlrdata->branchingrule, TRUE, DEFAULT_BRANCHINGRULE, DEFAULT_BRANCHSTRATEGIES, NULL, NULL) );
10202 
10203  SCIP_CALL( SCIPaddBoolParam(scip, "constraints/" CONSHDLR_NAME "/autosos1branch",
10204  "if TRUE then automatically switch to SOS1 branching if the SOS1 constraints do not overlap",
10205  &conshdlrdata->autosos1branch, TRUE, DEFAULT_AUTOSOS1BRANCH, NULL, NULL) );
10206 
10207  SCIP_CALL( SCIPaddBoolParam(scip, "constraints/" CONSHDLR_NAME "/fixnonzero",
10208  "if neighborhood branching is used, then fix the branching variable (if positive in sign) to the value of the feasibility tolerance",
10209  &conshdlrdata->fixnonzero, TRUE, DEFAULT_FIXNONZERO, NULL, NULL) );
10210 
10211  SCIP_CALL( SCIPaddBoolParam(scip, "constraints/" CONSHDLR_NAME "/addcomps",
10212  "if TRUE then add complementarity constraints to the branching nodes (can be used in combination with neighborhood or bipartite branching)",
10213  &conshdlrdata->addcomps, TRUE, DEFAULT_ADDCOMPS, NULL, NULL) );
10214 
10215  SCIP_CALL( SCIPaddIntParam(scip, "constraints/" CONSHDLR_NAME "/maxaddcomps",
10216  "maximal number of complementarity constraints added per branching node (-1: no limit)",
10217  &conshdlrdata->maxaddcomps, TRUE, DEFAULT_MAXADDCOMPS, -1, INT_MAX, NULL, NULL) );
10218 
10219  SCIP_CALL( SCIPaddRealParam(scip, "constraints/" CONSHDLR_NAME "/addcompsfeas",
10220  "minimal feasibility value for complementarity constraints in order to be added to the branching node",
10221  &conshdlrdata->addcompsfeas, TRUE, DEFAULT_ADDCOMPSFEAS, -SCIP_REAL_MAX, SCIP_REAL_MAX, NULL, NULL) );
10222 
10223  SCIP_CALL( SCIPaddRealParam(scip, "constraints/" CONSHDLR_NAME "/addbdsfeas",
10224  "minimal feasibility value for bound inequalities in order to be added to the branching node",
10225  &conshdlrdata->addbdsfeas, TRUE, DEFAULT_ADDBDSFEAS, -SCIP_REAL_MAX, SCIP_REAL_MAX, NULL, NULL) );
10226 
10227  SCIP_CALL( SCIPaddBoolParam(scip, "constraints/" CONSHDLR_NAME "/addextendedbds",
10228  "should added complementarity constraints be extended to SOS1 constraints to get tighter bound inequalities",
10229  &conshdlrdata->addextendedbds, TRUE, DEFAULT_ADDEXTENDEDBDS, NULL, NULL) );
10230 
10231  SCIP_CALL( SCIPaddBoolParam(scip, "constraints/" CONSHDLR_NAME "/branchsos",
10232  "Use SOS1 branching in enforcing (otherwise leave decision to branching rules)? This value can only be set to false if all SOS1 variables are binary",
10233  &conshdlrdata->branchsos, FALSE, TRUE, NULL, NULL) );
10234 
10235  SCIP_CALL( SCIPaddBoolParam(scip, "constraints/" CONSHDLR_NAME "/branchnonzeros",
10236  "Branch on SOS constraint with most number of nonzeros?",
10237  &conshdlrdata->branchnonzeros, FALSE, FALSE, NULL, NULL) );
10238 
10239  SCIP_CALL( SCIPaddBoolParam(scip, "constraints/" CONSHDLR_NAME "/branchweight",
10240  "Branch on SOS cons. with highest nonzero-variable weight for branching (needs branchnonzeros = false)?",
10241  &conshdlrdata->branchweight, FALSE, FALSE, NULL, NULL) );
10242 
10243  SCIP_CALL( SCIPaddIntParam(scip, "constraints/" CONSHDLR_NAME "/addcompsdepth",
10244  "only add complementarity constraints to branching nodes for predefined depth (-1: no limit)",
10245  &conshdlrdata->addcompsdepth, TRUE, DEFAULT_ADDCOMPSDEPTH, -1, INT_MAX, NULL, NULL) );
10246 
10247  /* selection rule parameters */
10248  SCIP_CALL( SCIPaddIntParam(scip, "constraints/" CONSHDLR_NAME "/nstrongrounds",
10249  "maximal number of strong branching rounds to perform for each node (-1: auto); only available for neighborhood and bipartite branching",
10250  &conshdlrdata->nstrongrounds, TRUE, DEFAULT_NSTRONGROUNDS, -1, INT_MAX, NULL, NULL) );
10251 
10252  SCIP_CALL( SCIPaddIntParam(scip, "constraints/" CONSHDLR_NAME "/nstrongiter",
10253  "maximal number LP iterations to perform for each strong branching round (-2: auto, -1: no limit)",
10254  &conshdlrdata->nstrongiter, TRUE, DEFAULT_NSTRONGITER, -2, INT_MAX, NULL, NULL) );
10255 
10256  /* separation parameters */
10257  SCIP_CALL( SCIPaddBoolParam(scip, "constraints/" CONSHDLR_NAME "/boundcutsfromsos1",
10258  "if TRUE separate bound inequalities from initial SOS1 constraints",
10259  &conshdlrdata->boundcutsfromsos1, TRUE, DEFAULT_BOUNDCUTSFROMSOS1, NULL, NULL) );
10260 
10261  SCIP_CALL( SCIPaddBoolParam(scip, "constraints/" CONSHDLR_NAME "/boundcutsfromgraph",
10262  "if TRUE separate bound inequalities from the conflict graph",
10263  &conshdlrdata->boundcutsfromgraph, TRUE, DEFAULT_BOUNDCUTSFROMGRAPH, NULL, NULL) );
10264 
10265  SCIP_CALL( SCIPaddBoolParam(scip, "constraints/" CONSHDLR_NAME "/autocutsfromsos1",
10266  "if TRUE then automatically switch to separating initial SOS1 constraints if the SOS1 constraints do not overlap",
10267  &conshdlrdata->autocutsfromsos1, TRUE, DEFAULT_AUTOCUTSFROMSOS1, NULL, NULL) );
10268 
10269  SCIP_CALL( SCIPaddIntParam(scip, "constraints/" CONSHDLR_NAME "/boundcutsfreq",
10270  "frequency for separating bound cuts; zero means to separate only in the root node",
10271  &conshdlrdata->boundcutsfreq, TRUE, DEFAULT_BOUNDCUTSFREQ, -1, SCIP_MAXTREEDEPTH, NULL, NULL) );
10272 
10273  SCIP_CALL( SCIPaddIntParam(scip, "constraints/" CONSHDLR_NAME "/boundcutsdepth",
10274  "node depth of separating bound cuts (-1: no limit)",
10275  &conshdlrdata->boundcutsdepth, TRUE, DEFAULT_BOUNDCUTSDEPTH, -1, INT_MAX, NULL, NULL) );
10276 
10277  SCIP_CALL( SCIPaddIntParam(scip, "constraints/" CONSHDLR_NAME "/maxboundcuts",
10278  "maximal number of bound cuts separated per branching node",
10279  &conshdlrdata->maxboundcuts, TRUE, DEFAULT_MAXBOUNDCUTS, 0, INT_MAX, NULL, NULL) );
10280 
10281  SCIP_CALL( SCIPaddIntParam(scip, "constraints/" CONSHDLR_NAME "/maxboundcutsroot",
10282  "maximal number of bound cuts separated per iteration in the root node",
10283  &conshdlrdata->maxboundcutsroot, TRUE, DEFAULT_MAXBOUNDCUTSROOT, 0, INT_MAX, NULL, NULL) );
10284 
10285  SCIP_CALL( SCIPaddBoolParam(scip, "constraints/" CONSHDLR_NAME "/strthenboundcuts",
10286  "if TRUE then bound cuts are strengthened in case bound variables are available",
10287  &conshdlrdata->strthenboundcuts, TRUE, DEFAULT_STRTHENBOUNDCUTS, NULL, NULL) );
10288 
10289  SCIP_CALL( SCIPaddIntParam(scip, "constraints/" CONSHDLR_NAME "/implcutsfreq",
10290  "frequency for separating implied bound cuts; zero means to separate only in the root node",
10291  &conshdlrdata->implcutsfreq, TRUE, DEFAULT_IMPLCUTSFREQ, -1, SCIP_MAXTREEDEPTH, NULL, NULL) );
10292 
10293  SCIP_CALL( SCIPaddIntParam(scip, "constraints/" CONSHDLR_NAME "/implcutsdepth",
10294  "node depth of separating implied bound cuts (-1: no limit)",
10295  &conshdlrdata->implcutsdepth, TRUE, DEFAULT_IMPLCUTSDEPTH, -1, INT_MAX, NULL, NULL) );
10296 
10297  SCIP_CALL( SCIPaddIntParam(scip, "constraints/" CONSHDLR_NAME "/maximplcuts",
10298  "maximal number of implied bound cuts separated per branching node",
10299  &conshdlrdata->maximplcuts, TRUE, DEFAULT_MAXIMPLCUTS, 0, INT_MAX, NULL, NULL) );
10300 
10301  SCIP_CALL( SCIPaddIntParam(scip, "constraints/" CONSHDLR_NAME "/maximplcutsroot",
10302  "maximal number of implied bound cuts separated per iteration in the root node",
10303  &conshdlrdata->maximplcutsroot, TRUE, DEFAULT_MAXIMPLCUTSROOT, 0, INT_MAX, NULL, NULL) );
10304 
10305  return SCIP_OKAY;
10306 }
10307 
10308 
10309 /** creates and captures a SOS1 constraint
10310  *
10311  * We set the constraint to not be modifable. If the weights are non NULL, the variables are ordered according to these
10312  * weights (in ascending order).
10313  *
10314  * @note The constraint gets captured, hence at one point you have to release it using the method SCIPreleaseCons().
10315  */
10317  SCIP* scip, /**< SCIP data structure */
10318  SCIP_CONS** cons, /**< pointer to hold the created constraint */
10319  const char* name, /**< name of constraint */
10320  int nvars, /**< number of variables in the constraint */
10321  SCIP_VAR** vars, /**< array with variables of constraint entries */
10322  SCIP_Real* weights, /**< weights determining the variable order, or NULL if natural order should be used */
10323  SCIP_Bool initial, /**< should the LP relaxation of constraint be in the initial LP?
10324  * Usually set to TRUE. Set to FALSE for 'lazy constraints'. */
10325  SCIP_Bool separate, /**< should the constraint be separated during LP processing?
10326  * Usually set to TRUE. */
10327  SCIP_Bool enforce, /**< should the constraint be enforced during node processing?
10328  * TRUE for model constraints, FALSE for additional, redundant constraints. */
10329  SCIP_Bool check, /**< should the constraint be checked for feasibility?
10330  * TRUE for model constraints, FALSE for additional, redundant constraints. */
10331  SCIP_Bool propagate, /**< should the constraint be propagated during node processing?
10332  * Usually set to TRUE. */
10333  SCIP_Bool local, /**< is constraint only valid locally?
10334  * Usually set to FALSE. Has to be set to TRUE, e.g., for branching constraints. */
10335  SCIP_Bool dynamic, /**< is constraint subject to aging?
10336  * Usually set to FALSE. Set to TRUE for own cuts which
10337  * are separated as constraints. */
10338  SCIP_Bool removable, /**< should the relaxation be removed from the LP due to aging or cleanup?
10339  * Usually set to FALSE. Set to TRUE for 'lazy constraints' and 'user cuts'. */
10340  SCIP_Bool stickingatnode /**< should the constraint always be kept at the node where it was added, even
10341  * if it may be moved to a more global node?
10342  * Usually set to FALSE. Set to TRUE to for constraints that represent node data. */
10343  )
10344 {
10345  SCIP_CONSHDLR* conshdlr;
10346  SCIP_CONSDATA* consdata;
10347  SCIP_Bool modifiable;
10348  SCIP_Bool transformed;
10349  int v;
10350 
10351  modifiable = FALSE;
10352 
10353  /* find the SOS1 constraint handler */
10354  conshdlr = SCIPfindConshdlr(scip, CONSHDLR_NAME);
10355  if ( conshdlr == NULL )
10356  {
10357  SCIPerrorMessage("<%s> constraint handler not found\n", CONSHDLR_NAME);
10358  return SCIP_PLUGINNOTFOUND;
10359  }
10360 
10361  /* are we in the transformed problem? */
10362  transformed = SCIPgetStage(scip) >= SCIP_STAGE_TRANSFORMED;
10363 
10364  /* create constraint data */
10365  SCIP_CALL( SCIPallocBlockMemory(scip, &consdata) );
10366  consdata->vars = NULL;
10367  consdata->nvars = nvars;
10368  consdata->maxvars = nvars;
10369  consdata->rowub = NULL;
10370  consdata->rowlb = NULL;
10371  consdata->nfixednonzeros = transformed ? 0 : -1;
10372  consdata->weights = NULL;
10373  consdata->local = local;
10374 
10375  if ( nvars > 0 )
10376  {
10377  SCIP_CALL( SCIPduplicateBlockMemoryArray(scip, &consdata->vars, vars, nvars) );
10378 
10379  /* check weights */
10380  if ( weights != NULL )
10381  {
10382  /* store weights */
10383  SCIP_CALL( SCIPduplicateBlockMemoryArray(scip, &consdata->weights, weights, nvars) );
10384 
10385  /* sort variables - ascending order */
10386  SCIPsortRealPtr(consdata->weights, (void**)consdata->vars, nvars);
10387  }
10388  }
10389  else
10390  {
10391  assert( weights == NULL );
10392  }
10393 
10394  /* branching on multiaggregated variables does not seem to work well, so avoid it */
10395  for (v = 0; v < nvars; ++v)
10396  {
10397  SCIP_CALL( SCIPmarkDoNotMultaggrVar(scip, consdata->vars[v]) );
10398  }
10399 
10400  /* create constraint */
10401  SCIP_CALL( SCIPcreateCons(scip, cons, name, conshdlr, consdata, initial, separate, enforce, check, propagate,
10402  local, modifiable, dynamic, removable, stickingatnode) );
10403  assert( transformed == SCIPconsIsTransformed(*cons) );
10404 
10405  /* replace original variables by transformed variables in transformed constraint, add locks, and catch events */
10406  for (v = nvars - 1; v >= 0; --v)
10407  {
10408  SCIP_CONSHDLRDATA* conshdlrdata;
10409 
10410  /* always use transformed variables in transformed constraints */
10411  if ( transformed )
10412  {
10413  SCIP_CALL( SCIPgetTransformedVar(scip, consdata->vars[v], &(consdata->vars[v])) );
10414  }
10415  assert( consdata->vars[v] != NULL );
10416  assert( transformed == SCIPvarIsTransformed(consdata->vars[v]) );
10417 
10418  /* get constraint handler data */
10419  conshdlrdata = SCIPconshdlrGetData(conshdlr);
10420  assert( conshdlrdata != NULL );
10421 
10422  /* handle the new variable */
10423  SCIP_CALL( handleNewVariableSOS1(scip, *cons, consdata, conshdlrdata, consdata->vars[v], transformed) );
10424  }
10425 
10426  return SCIP_OKAY;
10427 }
10428 
10429 
10430 /** creates and captures a SOS1 constraint with all constraint flags set to their default values.
10431  *
10432  * @warning Do NOT set the constraint to be modifiable manually, because this might lead
10433  * to wrong results as the variable array will not be resorted
10434  *
10435  * @note the constraint gets captured, hence at one point you have to release it using the method SCIPreleaseCons()
10436  */
10438  SCIP* scip, /**< SCIP data structure */
10439  SCIP_CONS** cons, /**< pointer to hold the created constraint */
10440  const char* name, /**< name of constraint */
10441  int nvars, /**< number of variables in the constraint */
10442  SCIP_VAR** vars, /**< array with variables of constraint entries */
10443  SCIP_Real* weights /**< weights determining the variable order, or NULL if natural order should be used */
10444  )
10445 {
10446  SCIP_CALL( SCIPcreateConsSOS1( scip, cons, name, nvars, vars, weights, TRUE, TRUE, TRUE, TRUE, TRUE, FALSE, FALSE, FALSE, FALSE) );
10447 
10448  return SCIP_OKAY;
10449 }
10450 
10451 
10452 /** adds variable to SOS1 constraint, the position is determined by the given weight */
10454  SCIP* scip, /**< SCIP data structure */
10455  SCIP_CONS* cons, /**< constraint */
10456  SCIP_VAR* var, /**< variable to add to the constraint */
10457  SCIP_Real weight /**< weight determining position of variable */
10458  )
10460  SCIP_CONSHDLRDATA* conshdlrdata;
10461  SCIP_CONSHDLR* conshdlr;
10462 
10463  assert( scip != NULL );
10464  assert( var != NULL );
10465  assert( cons != NULL );
10466 
10467  SCIPdebugMsg(scip, "adding variable <%s> to constraint <%s> with weight %g\n", SCIPvarGetName(var), SCIPconsGetName(cons), weight);
10468 
10469  conshdlr = SCIPconsGetHdlr(cons);
10470  assert( conshdlr != NULL );
10471  if ( strcmp(SCIPconshdlrGetName(conshdlr), CONSHDLR_NAME) != 0 )
10472  {
10473  SCIPerrorMessage("constraint is not an SOS1 constraint.\n");
10474  return SCIP_INVALIDDATA;
10475  }
10476 
10477  conshdlrdata = SCIPconshdlrGetData(conshdlr);
10478  assert( conshdlrdata != NULL );
10479 
10480  SCIP_CALL( addVarSOS1(scip, cons, conshdlrdata, var, weight) );
10481 
10482  return SCIP_OKAY;
10483 }
10484 
10485 
10486 /** appends variable to SOS1 constraint */
10488  SCIP* scip, /**< SCIP data structure */
10489  SCIP_CONS* cons, /**< constraint */
10490  SCIP_VAR* var /**< variable to add to the constraint */
10491  )
10492 {
10493  SCIP_CONSHDLRDATA* conshdlrdata;
10494  SCIP_CONSHDLR* conshdlr;
10495 
10496  assert( scip != NULL );
10497  assert( var != NULL );
10498  assert( cons != NULL );
10499 
10500  SCIPdebugMsg(scip, "appending variable <%s> to constraint <%s>\n", SCIPvarGetName(var), SCIPconsGetName(cons));
10501 
10502  conshdlr = SCIPconsGetHdlr(cons);
10503  assert( conshdlr != NULL );
10504  if ( strcmp(SCIPconshdlrGetName(conshdlr), CONSHDLR_NAME) != 0 )
10505  {
10506  SCIPerrorMessage("constraint is not an SOS1 constraint.\n");
10507  return SCIP_INVALIDDATA;
10508  }
10509 
10510  conshdlrdata = SCIPconshdlrGetData(conshdlr);
10511  assert( conshdlrdata != NULL );
10512 
10513  SCIP_CALL( appendVarSOS1(scip, cons, conshdlrdata, var) );
10514 
10515  return SCIP_OKAY;
10516 }
10517 
10518 
10519 /** gets number of variables in SOS1 constraint */
10520 int SCIPgetNVarsSOS1(
10521  SCIP* scip, /**< SCIP data structure */
10522  SCIP_CONS* cons /**< constraint */
10523  )
10524 {
10525  SCIP_CONSDATA* consdata;
10527  assert( scip != NULL );
10528  assert( cons != NULL );
10529 
10530  if ( strcmp(SCIPconshdlrGetName(SCIPconsGetHdlr(cons)), CONSHDLR_NAME) != 0 )
10531  {
10532  SCIPerrorMessage("constraint is not an SOS1 constraint.\n");
10533  SCIPABORT();
10534  return -1; /*lint !e527*/
10535  }
10536 
10537  consdata = SCIPconsGetData(cons);
10538  assert( consdata != NULL );
10539 
10540  return consdata->nvars;
10541 }
10542 
10543 
10544 /** gets array of variables in SOS1 constraint */
10546  SCIP* scip, /**< SCIP data structure */
10547  SCIP_CONS* cons /**< constraint data */
10548  )
10549 {
10550  SCIP_CONSDATA* consdata;
10552  assert( scip != NULL );
10553  assert( cons != NULL );
10554 
10555  if ( strcmp(SCIPconshdlrGetName(SCIPconsGetHdlr(cons)), CONSHDLR_NAME) != 0 )
10556  {
10557  SCIPerrorMessage("constraint is not an SOS1 constraint.\n");
10558  SCIPABORT();
10559  return NULL; /*lint !e527*/
10560  }
10561 
10562  consdata = SCIPconsGetData(cons);
10563  assert( consdata != NULL );
10564 
10565  return consdata->vars;
10566 }
10567 
10568 
10569 /** gets array of weights in SOS1 constraint (or NULL if not existent) */
10571  SCIP* scip, /**< SCIP data structure */
10572  SCIP_CONS* cons /**< constraint data */
10573  )
10574 {
10575  SCIP_CONSDATA* consdata;
10577  assert( scip != NULL );
10578  assert( cons != NULL );
10579 
10580  if ( strcmp(SCIPconshdlrGetName(SCIPconsGetHdlr(cons)), CONSHDLR_NAME) != 0 )
10581  {
10582  SCIPerrorMessage("constraint is not an SOS1 constraint.\n");
10583  SCIPABORT();
10584  return NULL; /*lint !e527*/
10585  }
10586 
10587  consdata = SCIPconsGetData(cons);
10588  assert( consdata != NULL );
10589 
10590  return consdata->weights;
10591 }
10592 
10593 
10594 /** gets conflict graph of SOS1 constraints (or NULL if not existent)
10595  *
10596  * @note The conflict graph is globally valid; local changes are not taken into account.
10597  */
10599  SCIP_CONSHDLR* conshdlr /**< SOS1 constraint handler */
10600  )
10601 {
10602  SCIP_CONSHDLRDATA* conshdlrdata;
10603 
10604  assert( conshdlr != NULL );
10605 
10606  if ( strcmp(SCIPconshdlrGetName(conshdlr), CONSHDLR_NAME) != 0 )
10607  {
10608  SCIPerrorMessage("not an SOS1 constraint handler.\n");
10609  SCIPABORT();
10610  return NULL; /*lint !e527*/
10611  }
10612  conshdlrdata = SCIPconshdlrGetData(conshdlr);
10613  assert( conshdlrdata != NULL );
10614 
10615  return conshdlrdata->conflictgraph;
10616 }
10617 
10618 
10619 /** gets number of problem variables that are part of the SOS1 conflict graph */
10620 int SCIPgetNSOS1Vars(
10621  SCIP_CONSHDLR* conshdlr /**< SOS1 constraint handler */
10622  )
10623 {
10624  SCIP_CONSHDLRDATA* conshdlrdata;
10625 
10626  assert( conshdlr != NULL );
10627 
10628  if ( strcmp(SCIPconshdlrGetName(conshdlr), CONSHDLR_NAME) != 0 )
10629  {
10630  SCIPerrorMessage("not an SOS1 constraint handler.\n");
10631  SCIPABORT();
10632  return -1; /*lint !e527*/
10633  }
10634  conshdlrdata = SCIPconshdlrGetData(conshdlr);
10635  assert( conshdlrdata != NULL );
10636 
10637  return conshdlrdata->nsos1vars;
10638 }
10639 
10640 
10641 /** returns whether variable is part of the SOS1 conflict graph */
10643  SCIP_CONSHDLR* conshdlr, /**< SOS1 constraint handler */
10644  SCIP_VAR* var /**< variable */
10645  )
10646 {
10647  SCIP_CONSHDLRDATA* conshdlrdata;
10649  assert( var != NULL );
10650  assert( conshdlr != NULL );
10651 
10652  if ( strcmp(SCIPconshdlrGetName(conshdlr), CONSHDLR_NAME) != 0 )
10653  {
10654  SCIPerrorMessage("not an SOS1 constraint handler.\n");
10655  SCIPABORT();
10656  return FALSE; /*lint !e527*/
10657  }
10658  conshdlrdata = SCIPconshdlrGetData(conshdlr);
10659  assert( conshdlrdata != NULL );
10660 
10661  return varIsSOS1(conshdlrdata, var);
10662 }
10663 
10664 
10665 /** returns SOS1 index of variable or -1 if variable is not part of the SOS1 conflict graph */
10666 int SCIPvarGetNodeSOS1(
10667  SCIP_CONSHDLR* conshdlr, /**< SOS1 constraint handler */
10668  SCIP_VAR* var /**< variable */
10669  )
10670 {
10671  SCIP_CONSHDLRDATA* conshdlrdata;
10673  assert( conshdlr != NULL );
10674  assert( var != NULL );
10675 
10676  if ( strcmp(SCIPconshdlrGetName(conshdlr), CONSHDLR_NAME) != 0 )
10677  {
10678  SCIPerrorMessage("Not an SOS1 constraint handler.\n");
10679  SCIPABORT();
10680  return -1; /*lint !e527*/
10681  }
10682  conshdlrdata = SCIPconshdlrGetData(conshdlr);
10683  assert( conshdlrdata != NULL );
10684 
10685  if ( conshdlrdata->varhash == NULL )
10686  {
10687  SCIPerrorMessage("Hashmap not yet initialized.\n");
10688  SCIPABORT();
10689  return -1; /*lint !e527*/
10690  }
10691 
10692  return varGetNodeSOS1(conshdlrdata, var);
10693 }
10694 
10695 
10696 /** returns variable that belongs to a given node from the conflict graph */
10698  SCIP_DIGRAPH* conflictgraph, /**< conflict graph */
10699  int node /**< node from the conflict graph */
10700  )
10701 {
10702  SCIP_NODEDATA* nodedata;
10704  assert( conflictgraph != NULL );
10705  assert( node >= 0 && node < SCIPdigraphGetNNodes(conflictgraph) );
10706 
10707  /* get node data */
10708  nodedata = (SCIP_NODEDATA*)SCIPdigraphGetNodeData(conflictgraph, node);
10709 
10710  if ( nodedata == NULL )
10711  {
10712  SCIPerrorMessage("variable is not assigned to an index.\n");
10713  SCIPABORT();
10714  return NULL; /*lint !e527*/
10715  }
10716 
10717  return nodedata->var;
10718 }
10719 
10720 
10721 /** based on solution values of the variables, fixes variables to zero to turn all SOS1 constraints feasible */
10723  SCIP* scip, /**< SCIP pointer */
10724  SCIP_CONSHDLR* conshdlr, /**< SOS1 constraint handler */
10725  SCIP_SOL* sol, /**< solution */
10726  SCIP_Bool* changed, /**< pointer to store whether the solution has been changed */
10727  SCIP_Bool* success /**< pointer to store whether SOS1 constraints have been turned feasible and
10728  * solution was good enough */
10729  )
10730 {
10731  SCIP_CONSHDLRDATA* conshdlrdata;
10732  SCIP_Real roundobjval;
10733  SCIP_Bool allroundable;
10734 
10735  assert( scip != NULL );
10736  assert( conshdlr != NULL );
10737  assert( sol != NULL );
10738  assert( changed != NULL );
10739  assert( success != NULL );
10740 
10741  if ( strcmp(SCIPconshdlrGetName(conshdlr), CONSHDLR_NAME) != 0 )
10742  {
10743  SCIPerrorMessage("Not an SOS1 constraint handler.\n");
10744  return SCIP_PARAMETERWRONGVAL;
10745  }
10746  conshdlrdata = SCIPconshdlrGetData(conshdlr);
10747  assert( conshdlrdata != NULL );
10748 
10749  *changed = FALSE;
10750  *success = FALSE;
10751  allroundable = FALSE;
10752 
10753  /* check number of SOS1 constraints */
10754  if ( SCIPconshdlrGetNConss(conshdlr) < 1 )
10755  {
10756  *success = TRUE;
10757  return SCIP_OKAY;
10758  }
10759 
10760  /* if the SOS1 constraints do not overlap, we apply a faster method makeSOS1constraintsFeasible() that does not make use of the conflict graph;
10761  * for overlapping SOS1 constraints we apply the method makeSOS1conflictgraphFeasible(), which then may produce better feasible solutions */
10762  if ( conshdlrdata->switchsos1branch )
10763  {
10764  SCIP_CALL( makeSOS1constraintsFeasible(scip, conshdlr, sol, changed, &allroundable) );
10765  }
10766  else
10767  {
10768  SCIP_CALL( makeSOS1conflictgraphFeasible(scip, conshdlr, sol, changed, &allroundable) );
10769  }
10770 
10771  if ( ! allroundable )
10772  return SCIP_OKAY;
10773 
10774  /* check whether objective value of rounded solution is good enough */
10775  roundobjval = SCIPgetSolOrigObj(scip, sol);
10776  if ( SCIPgetObjsense(scip) == SCIP_OBJSENSE_MAXIMIZE )
10777  roundobjval *= -1;
10778 
10779  if ( SCIPisLT(scip, roundobjval, SCIPgetUpperbound(scip) ) )
10780  *success = TRUE;
10781 
10782  return SCIP_OKAY;
10783 }
enum SCIP_Result SCIP_RESULT
Definition: type_result.h:52
void SCIPsortRealInt(SCIP_Real *realarray, int *intarray, int len)
#define DEFAULT_IMPLPROP
Definition: cons_sos1.c:116
#define DIVINGCUTOFFVALUE
Definition: cons_sos1.c:162
#define SCIPfreeBlockMemoryArray(scip, ptr, num)
Definition: scip.h:21909
SCIP_Bool SCIPisFeasZero(SCIP *scip, SCIP_Real val)
Definition: scip.c:46151
void ** SCIPdigraphGetSuccessorsData(SCIP_DIGRAPH *digraph, int node)
Definition: misc.c:6835
static SCIP_RETCODE presolRoundConsSOS1(SCIP *scip, SCIP_CONS *cons, SCIP_CONSDATA *consdata, SCIP_EVENTHDLR *eventhdlr, SCIP_Bool *substituted, SCIP_Bool *cutoff, SCIP_Bool *success, int *ndelconss, int *nupgdconss, int *nfixedvars, int *nremovedvars)
Definition: cons_sos1.c:1552
static SCIP_RETCODE genConflictgraphLinearCons(SCIP_CONSHDLRDATA *conshdlrdata, SCIP_DIGRAPH *conflictgraphlin, SCIP_DIGRAPH *conflictgraphorig, SCIP_VAR **linvars, int nlinvars, int *posinlinvars)
Definition: cons_sos1.c:1336
#define SCIPreallocBlockMemoryArray(scip, ptr, oldnum, newnum)
Definition: scip.h:21898
SCIP_RETCODE SCIPflattenVarAggregationGraph(SCIP *scip, SCIP_VAR *var)
Definition: scip.c:18829
SCIP_RETCODE SCIPsetConshdlrDelete(SCIP *scip, SCIP_CONSHDLR *conshdlr, SCIP_DECL_CONSDELETE((*consdelete)))
Definition: scip.c:6228
static SCIP_RETCODE enforceConssSOS1(SCIP *scip, SCIP_CONSHDLR *conshdlr, int nconss, SCIP_CONS **conss, SCIP_SOL *sol, SCIP_RESULT *result)
Definition: cons_sos1.c:5781
#define DEFAULT_MAXIMPLCUTS
Definition: cons_sos1.c:154
static SCIP_RETCODE fixVariableZero(SCIP *scip, SCIP_VAR *var, SCIP_Bool *infeasible, SCIP_Bool *tightened)
Definition: cons_sos1.c:601
SCIP_Real SCIPfeastol(SCIP *scip)
Definition: scip.c:45274
enum TCLIQUE_Status TCLIQUE_STATUS
Definition: tclique.h:57
#define SCIPallocBlockMemoryArray(scip, ptr, num)
Definition: scip.h:21892
#define DEFAULT_MAXSOSADJACENCY
Definition: cons_sos1.c:104
void tcliqueFree(TCLIQUE_GRAPH **tcliquegraph)
SCIP_RETCODE SCIPtightenVarLb(SCIP *scip, SCIP_VAR *var, SCIP_Real newbound, SCIP_Bool force, SCIP_Bool *infeasible, SCIP_Bool *tightened)
Definition: scip.c:22118
SCIP_RETCODE SCIPcacheRowExtensions(SCIP *scip, SCIP_ROW *row)
Definition: scip.c:30233
SCIP_Real SCIPgetVarUbAtIndex(SCIP *scip, SCIP_VAR *var, SCIP_BDCHGIDX *bdchgidx, SCIP_Bool after)
Definition: scip.c:19263
SCIP_Bool SCIPisFeasEQ(SCIP *scip, SCIP_Real val1, SCIP_Real val2)
Definition: scip.c:46086
SCIP_NODE * SCIPgetCurrentNode(SCIP *scip)
Definition: scip.c:40453
SCIP_STAGE SCIPgetStage(SCIP *scip)
Definition: scip.c:814
static SCIP_RETCODE detectVarboundSOS1(SCIP *scip, SCIP_CONSHDLRDATA *conshdlrdata, SCIP_VAR *var0, SCIP_VAR *var1, SCIP_Real val0, SCIP_Real val1)
Definition: cons_sos1.c:8220
SCIP_Bool SCIPconsIsDynamic(SCIP_CONS *cons)
Definition: cons.c:8140
SCIP_Real * SCIPvarGetMultaggrScalars(SCIP_VAR *var)
Definition: var.c:16958
SCIP_RETCODE SCIPsetConshdlrTrans(SCIP *scip, SCIP_CONSHDLR *conshdlr, SCIP_DECL_CONSTRANS((*constrans)))
Definition: scip.c:6251
static SCIP_DECL_CONSENFOPS(consEnfopsSOS1)
Definition: cons_sos1.c:9412
static SCIP_RETCODE propVariableNonzero(SCIP *scip, SCIP_DIGRAPH *conflictgraph, SCIP_DIGRAPH *implgraph, SCIP_CONS *cons, int node, SCIP_Bool implprop, SCIP_Bool *cutoff, int *ngen)
Definition: cons_sos1.c:3622
SCIP_Bool SCIPisFeasLT(SCIP *scip, SCIP_Real val1, SCIP_Real val2)
Definition: scip.c:46099
static SCIP_RETCODE getDiveBdChgsSOS1constraints(SCIP *scip, SCIP_CONSHDLR *conshdlr, SCIP_DIVESET *diveset, SCIP_SOL *sol, SCIP_Bool *success)
Definition: cons_sos1.c:8039
SCIP_Real SCIPgetVarLbAtIndex(SCIP *scip, SCIP_VAR *var, SCIP_BDCHGIDX *bdchgidx, SCIP_Bool after)
Definition: scip.c:19123
TCLIQUE_Bool tcliqueCreate(TCLIQUE_GRAPH **tcliquegraph)
static SCIP_DECL_CONSENFORELAX(consEnforelaxSOS1)
Definition: cons_sos1.c:9396
#define CONSHDLR_NAME
Definition: cons_sos1.c:86
SCIP_VAR ** SCIPgetVarsSOS1(SCIP *scip, SCIP_CONS *cons)
Definition: cons_sos1.c:10551
#define CONSHDLR_PROPFREQ
Definition: cons_sos1.c:92
static SCIP_DECL_CONSSEPALP(consSepalpSOS1)
Definition: cons_sos1.c:9348
struct TCLIQUE_Graph TCLIQUE_GRAPH
Definition: tclique.h:38
#define DEFAULT_ADDCOMPSFEAS
Definition: cons_sos1.c:133
SCIP_RETCODE SCIPcatchVarEvent(SCIP *scip, SCIP_VAR *var, SCIP_EVENTTYPE eventtype, SCIP_EVENTHDLR *eventhdlr, SCIP_EVENTDATA *eventdata, int *filterpos)
Definition: scip.c:40275
SCIP_CONSHDLR * SCIPfindConshdlr(SCIP *scip, const char *name)
Definition: scip.c:6541
SCIP_RETCODE SCIPflushRowExtensions(SCIP *scip, SCIP_ROW *row)
Definition: scip.c:30256
static SCIP_DECL_CONSINITLP(consInitlpSOS1)
Definition: cons_sos1.c:9323
static SCIP_DECL_CONSFREE(consFreeSOS1)
Definition: cons_sos1.c:8907
TCLIQUE_Bool tcliqueAddNode(TCLIQUE_GRAPH *tcliquegraph, int node, TCLIQUE_WEIGHT weight)
SCIP_Real SCIPvarGetLbGlobal(SCIP_VAR *var)
Definition: var.c:17166
SCIP_RETCODE SCIPsetConshdlrGetVars(SCIP *scip, SCIP_CONSHDLR *conshdlr, SCIP_DECL_CONSGETVARS((*consgetvars)))
Definition: scip.c:6481
#define SCIP_MAXSTRLEN
Definition: def.h:215
static SCIP_RETCODE getDiveBdChgsSOS1conflictgraph(SCIP *scip, SCIP_CONSHDLR *conshdlr, SCIP_DIVESET *diveset, SCIP_SOL *sol, SCIP_Bool *success)
Definition: cons_sos1.c:7898
static SCIP_RETCODE inferVariableZero(SCIP *scip, SCIP_VAR *var, SCIP_CONS *cons, int inferinfo, SCIP_Bool *infeasible, SCIP_Bool *tightened, SCIP_Bool *success)
Definition: cons_sos1.c:675
#define DEFAULT_MAXBOUNDCUTS
Definition: cons_sos1.c:149
SCIP_RETCODE SCIPsetConshdlrEnforelax(SCIP *scip, SCIP_CONSHDLR *conshdlr, SCIP_DECL_CONSENFORELAX((*consenforelax)))
Definition: scip.c:5973
static SCIP_RETCODE cliqueGetCommonSuccessorsSOS1(SCIP_CONSHDLRDATA *conshdlrdata, SCIP_DIGRAPH *conflictgraph, int *clique, SCIP_VAR **vars, int nvars, int *comsucc, int *ncomsucc)
Definition: cons_sos1.c:1389
static SCIP_RETCODE performStrongbranchSOS1(SCIP *scip, SCIP_DIGRAPH *conflictgraph, int *fixingsexec, int nfixingsexec, int *fixingsop, int nfixingsop, int inititer, SCIP_Bool fixnonzero, int *domainfixings, int *ndomainfixings, SCIP_Bool *infeasible, SCIP_Real *objval, SCIP_Bool *lperror)
Definition: cons_sos1.c:4318
SCIPInterval pow(const SCIPInterval &x, const SCIPInterval &y)
SCIP_RETCODE SCIPresetConsAge(SCIP *scip, SCIP_CONS *cons)
Definition: scip.c:27962
SCIP_RETCODE SCIPdelCons(SCIP *scip, SCIP_CONS *cons)
Definition: scip.c:12481
int SCIPcalcMemGrowSize(SCIP *scip, int num)
Definition: scip.c:45601
SCIP_VAR ** SCIPvarGetMultaggrVars(SCIP_VAR *var)
Definition: var.c:16946
static long bound
SCIP_RETCODE SCIPaddVarToRow(SCIP *scip, SCIP_ROW *row, SCIP_VAR *var, SCIP_Real val)
Definition: scip.c:30288
SCIP_Bool SCIPisPositive(SCIP *scip, SCIP_Real val)
Definition: scip.c:45876
SCIP_Real SCIPvarGetLbLocal(SCIP_VAR *var)
Definition: var.c:17222
int * SCIPdigraphGetSuccessors(SCIP_DIGRAPH *digraph, int node)
Definition: misc.c:6817
SCIP_Real * SCIPgetWeightsSOS1(SCIP *scip, SCIP_CONS *cons)
Definition: cons_sos1.c:10576
static SCIP_RETCODE getSOS1Implications(SCIP *scip, SCIP_CONSHDLRDATA *conshdlrdata, SCIP_VAR **vars, SCIP_DIGRAPH *implgraph, SCIP_HASHMAP *implhash, SCIP_Bool *implnodes, int node)
Definition: cons_sos1.c:1486
SCIP_RETCODE SCIPchgVarLbNode(SCIP *scip, SCIP_NODE *node, SCIP_VAR *var, SCIP_Real newbound)
Definition: scip.c:21781
static SCIP_RETCODE makeSOS1constraintsFeasible(SCIP *scip, SCIP_CONSHDLR *conshdlr, SCIP_SOL *sol, SCIP_Bool *changed, SCIP_Bool *allroundable)
Definition: cons_sos1.c:7764
SCIP_RETCODE SCIPincludeEventhdlrBasic(SCIP *scip, SCIP_EVENTHDLR **eventhdlrptr, const char *name, const char *desc, SCIP_DECL_EVENTEXEC((*eventexec)), SCIP_EVENTHDLRDATA *eventhdlrdata)
Definition: scip.c:8526
#define CONSHDLR_MAXPREROUNDS
Definition: cons_sos1.c:96
SCIP_RETCODE SCIPgetTransformedVar(SCIP *scip, SCIP_VAR *var, SCIP_VAR **transvar)
Definition: scip.c:18575
static SCIP_RETCODE propConsSOS1(SCIP *scip, SCIP_CONS *cons, SCIP_CONSDATA *consdata, SCIP_Bool *cutoff, int *ngen)
Definition: cons_sos1.c:3524
SCIP_RETCODE SCIPparseVarName(SCIP *scip, const char *str, SCIP_VAR **var, char **endptr)
Definition: scip.c:17656
SCIP_Bool SCIPvarIsBinary(SCIP_VAR *var)
Definition: var.c:16732
SCIP_RETCODE SCIPmakeSOS1sFeasible(SCIP *scip, SCIP_CONSHDLR *conshdlr, SCIP_SOL *sol, SCIP_Bool *changed, SCIP_Bool *success)
Definition: cons_sos1.c:10728
static SCIP_RETCODE extensionOperatorSOS1(SCIP *scip, SCIP_CONSHDLRDATA *conshdlrdata, SCIP_Bool **adjacencymatrix, SCIP_DIGRAPH *vertexcliquegraph, int nsos1vars, int nconss, SCIP_CONS *cons, SCIP_VAR **vars, SCIP_Real *weights, SCIP_Bool firstcall, SCIP_Bool usebacktrack, int **cliques, int *ncliques, int *cliquesizes, int *newclique, int *workingset, int nworkingset, int nexts, int pos, int *maxextensions, int *naddconss, SCIP_Bool *success)
Definition: cons_sos1.c:1074
SCIP_Bool SCIPisFeasNegative(SCIP *scip, SCIP_Real val)
Definition: scip.c:46175
static SCIP_Bool isImpliedZero(SCIP_DIGRAPH *conflictgraph, SCIP_Bool *implnodes, int node)
Definition: cons_sos1.c:2203
#define DEFAULT_ADDBDSFEAS
Definition: cons_sos1.c:134
static SCIP_RETCODE updateArcData(SCIP *scip, SCIP_DIGRAPH *implgraph, SCIP_HASHMAP *implhash, SCIP_VAR **totalvars, SCIP_VAR *varv, SCIP_VAR *varw, SCIP_Real lb, SCIP_Real ub, SCIP_Real newbound, SCIP_Bool lower, int *nchgbds, SCIP_Bool *update, SCIP_Bool *infeasible)
Definition: cons_sos1.c:2232
static SCIP_Real nodeGetSolvalBinaryBigMSOS1(SCIP *scip, SCIP_DIGRAPH *conflictgraph, SCIP_SOL *sol, int node)
Definition: cons_sos1.c:404
#define DEFAULT_CONFLICTPROP
Definition: cons_sos1.c:115
static SCIP_DECL_CONSRESPROP(consRespropSOS1)
Definition: cons_sos1.c:9645
SCIP_CONS ** SCIPconshdlrGetConss(SCIP_CONSHDLR *conshdlr)
Definition: cons.c:4485
#define FALSE
Definition: def.h:64
static SCIP_RETCODE deleteVarSOS1(SCIP *scip, SCIP_CONS *cons, SCIP_CONSDATA *consdata, SCIP_EVENTHDLR *eventhdlr, int pos)
Definition: cons_sos1.c:1035
#define CONSHDLR_EAGERFREQ
Definition: cons_sos1.c:93
SCIP_RETCODE SCIPhashmapCreate(SCIP_HASHMAP **hashmap, BMS_BLKMEM *blkmem, int mapsize)
Definition: misc.c:2765
#define CONSHDLR_SEPAPRIORITY
Definition: cons_sos1.c:88
const char * SCIPeventhdlrGetName(SCIP_EVENTHDLR *eventhdlr)
Definition: event.c:278
SCIP_RETCODE SCIPincludeConshdlrBasic(SCIP *scip, SCIP_CONSHDLR **conshdlrptr, const char *name, const char *desc, int enfopriority, int chckpriority, int eagerfreq, SCIP_Bool needscons, SCIP_DECL_CONSENFOLP((*consenfolp)), SCIP_DECL_CONSENFOPS((*consenfops)), SCIP_DECL_CONSCHECK((*conscheck)), SCIP_DECL_CONSLOCK((*conslock)), SCIP_CONSHDLRDATA *conshdlrdata)
Definition: scip.c:5831
static SCIP_Real nodeGetSolvalVarboundLbSOS1(SCIP *scip, SCIP_DIGRAPH *conflictgraph, SCIP_SOL *sol, int node)
Definition: cons_sos1.c:454
static SCIP_RETCODE passConComponentVarbound(SCIP *scip, SCIP_DIGRAPH *conflictgraph, int node, SCIP_VAR *boundvar, SCIP_Bool checklb, SCIP_Bool *processed, int *concomp, int *nconcomp, SCIP_Bool *unique)
Definition: cons_sos1.c:8296
#define CONSHDLR_CHECKPRIORITY
Definition: cons_sos1.c:90
SCIP_Real SCIPinfinity(SCIP *scip)
Definition: scip.c:45816
miscellaneous datastructures
int SCIPgetNSOS1Vars(SCIP_CONSHDLR *conshdlr)
Definition: cons_sos1.c:10626
int SCIPsnprintf(char *t, int len, const char *s,...)
Definition: misc.c:9340
SCIP_Bool SCIPisNegative(SCIP *scip, SCIP_Real val)
Definition: scip.c:45888
#define TRUE
Definition: def.h:63
#define SCIPdebug(x)
Definition: pub_message.h:74
enum SCIP_Retcode SCIP_RETCODE
Definition: type_retcode.h:53
static SCIP_Real nodeGetSolvalVarboundUbSOS1(SCIP *scip, SCIP_DIGRAPH *conflictgraph, SCIP_SOL *sol, int node)
Definition: cons_sos1.c:481
SCIP_Real SCIPvarGetNegationConstant(SCIP_VAR *var)
Definition: var.c:17003
SCIP_RETCODE SCIPaddConflictUb(SCIP *scip, SCIP_VAR *var, SCIP_BDCHGIDX *bdchgidx)
Definition: scip.c:26813
SCIP_RETCODE SCIPaddVarLocks(SCIP *scip, SCIP_VAR *var, int nlocksdown, int nlocksup)
Definition: scip.c:21255
SCIP_Bool SCIPconsIsStickingAtNode(SCIP_CONS *cons)
Definition: cons.c:8160
SCIP_RETCODE SCIPincludeConshdlrSOS1(SCIP *scip)
Definition: cons_sos1.c:10107
enum SCIP_Varstatus SCIP_VARSTATUS
Definition: type_var.h:48
static SCIP_RETCODE maxWeightIndSetHeuristic(SCIP *scip, SCIP_SOL *sol, SCIP_CONSHDLR *conshdlr, SCIP_DIGRAPH *conflictgraph, int nsos1vars, SCIP_Bool *indicatorzero, SCIP_Bool *indset)
Definition: cons_sos1.c:7529
#define EVENTHDLR_NAME
Definition: cons_sos1.c:158
#define CONSHDLR_ENFOPRIORITY
Definition: cons_sos1.c:89
SCIP_Real SCIPvarGetAggrScalar(SCIP_VAR *var)
Definition: var.c:16912
SCIP_Bool SCIPconsIsTransformed(SCIP_CONS *cons)
Definition: cons.c:8190
SCIP_RETCODE SCIPcomputeArraysIntersection(int *array1, int narray1, int *array2, int narray2, int *intersectarray, int *nintersectarray)
Definition: misc.c:9139
static SCIP_RETCODE separateSOS1(SCIP *scip, SCIP_CONSHDLR *conshdlr, SCIP_SOL *sol, int nconss, SCIP_CONS **conss, SCIP_RESULT *result)
Definition: cons_sos1.c:7196
void SCIPsortDownIntInt(int *intarray1, int *intarray2, int len)
SCIP_RETCODE SCIPaddDiveBoundChange(SCIP *scip, SCIP_VAR *var, SCIP_BRANCHDIR dir, SCIP_Real value, SCIP_Bool preferred)
Definition: scip.c:36042
SCIP_RETCODE SCIPtightenVarUb(SCIP *scip, SCIP_VAR *var, SCIP_Real newbound, SCIP_Bool force, SCIP_Bool *infeasible, SCIP_Bool *tightened)
Definition: scip.c:22234
#define SCIPfreeBlockMemory(scip, ptr)
Definition: scip.h:21907
static SCIP_RETCODE resetConflictgraphSOS1(SCIP_DIGRAPH *conflictgraph, SCIP_DIGRAPH *localconflicts, int nsos1vars)
Definition: cons_sos1.c:5267
SCIP_RETCODE SCIPsetConshdlrSepa(SCIP *scip, SCIP_CONSHDLR *conshdlr, SCIP_DECL_CONSSEPALP((*conssepalp)), SCIP_DECL_CONSSEPASOL((*conssepasol)), int sepafreq, int sepapriority, SCIP_Bool delaysepa)
Definition: scip.c:5885
SCIP_RETCODE SCIPchgVarLbProbing(SCIP *scip, SCIP_VAR *var, SCIP_Real newbound)
Definition: scip.c:35220
static SCIP_RETCODE initConflictgraph(SCIP *scip, SCIP_CONSHDLRDATA *conshdlrdata, SCIP_CONS **conss, int nconss)
Definition: cons_sos1.c:8649
SCIP_RETCODE SCIPchgVarUbNode(SCIP *scip, SCIP_NODE *node, SCIP_VAR *var, SCIP_Real newbound)
Definition: scip.c:21825
#define SCIPduplicateBufferArray(scip, ptr, source, num)
Definition: scip.h:21933
tclique user interface
void SCIPsortDownRealInt(SCIP_Real *realarray, int *intarray, int len)
void * SCIPhashmapGetImage(SCIP_HASHMAP *hashmap, void *origin)
Definition: misc.c:2903
SCIP_Bool SCIPisEQ(SCIP *scip, SCIP_Real val1, SCIP_Real val2)
Definition: scip.c:45751
#define DEFAULT_ADDCOMPSDEPTH
Definition: cons_sos1.c:132
static SCIP_DECL_CONSGETVARS(consGetVarsSOS1)
Definition: cons_sos1.c:9925
#define SCIPfreeBufferArray(scip, ptr)
Definition: scip.h:21937
enum SCIP_LPSolStat SCIP_LPSOLSTAT
Definition: type_lp.h:42
Constraint handler for the set partitioning / packing / covering constraints .
#define SCIPallocBlockMemory(scip, ptr)
Definition: scip.h:21890
SCIP_Bool SCIPisTransformed(SCIP *scip)
Definition: scip.c:1010
SCIP_VAR * SCIPvarGetNegationVar(SCIP_VAR *var)
Definition: var.c:16992
SCIP_Bool SCIPconsIsRemovable(SCIP_CONS *cons)
Definition: cons.c:8150
#define SCIP_EVENTTYPE_BOUNDCHANGED
Definition: type_event.h:108
SCIP_RETCODE SCIPsetConshdlrInitlp(SCIP *scip, SCIP_CONSHDLR *conshdlr, SCIP_DECL_CONSINITLP((*consinitlp)))
Definition: scip.c:6274
#define SCIPdebugMsg
Definition: scip.h:451
SCIP_RETCODE SCIPaddIntParam(SCIP *scip, const char *name, const char *desc, int *valueptr, SCIP_Bool isadvanced, int defaultvalue, int minvalue, int maxvalue, SCIP_DECL_PARAMCHGD((*paramchgd)), SCIP_PARAMDATA *paramdata)
Definition: scip.c:4202
SCIP_Real SCIPgetRhsLinear(SCIP *scip, SCIP_CONS *cons)
static SCIP_RETCODE getVectorOfWeights(SCIP *scip, SCIP_SOL *sol, SCIP_DIGRAPH *conflictgraph, int nsos1vars, SCIP_Bool *indicatorzero, SCIP_Real *weights)
Definition: cons_sos1.c:7317
SCIP_RETCODE SCIPsetConshdlrParse(SCIP *scip, SCIP_CONSHDLR *conshdlr, SCIP_DECL_CONSPARSE((*consparse)))
Definition: scip.c:6458
SCIP_RETCODE SCIPaddCoefLinear(SCIP *scip, SCIP_CONS *cons, SCIP_VAR *var, SCIP_Real val)
void SCIPinfoMessage(SCIP *scip, FILE *file, const char *formatstr,...)
Definition: scip.c:1336
SCIP_RETCODE SCIPcreateCons(SCIP *scip, SCIP_CONS **cons, const char *name, SCIP_CONSHDLR *conshdlr, SCIP_CONSDATA *consdata, SCIP_Bool initial, SCIP_Bool separate, SCIP_Bool enforce, SCIP_Bool check, SCIP_Bool propagate, SCIP_Bool local, SCIP_Bool modifiable, SCIP_Bool dynamic, SCIP_Bool removable, SCIP_Bool stickingatnode)
Definition: scip.c:27146
SCIP_RETCODE SCIPaddConflictLb(SCIP *scip, SCIP_VAR *var, SCIP_BDCHGIDX *bdchgidx)
Definition: scip.c:26746
#define DEFAULT_IMPLCUTSDEPTH
Definition: cons_sos1.c:153
SCIP * scip
Definition: cons_sos1.c:207
static SCIP_DECL_CONSENFOLP(consEnfolpSOS1)
Definition: cons_sos1.c:9380
SCIP_Longint SCIPgetNDualResolveLPIterations(SCIP *scip)
Definition: scip.c:41667
SCIP_Bool SCIProwIsInLP(SCIP_ROW *row)
Definition: lp.c:16522
SCIP_Bool SCIPhashmapExists(SCIP_HASHMAP *hashmap, void *origin)
Definition: misc.c:2997
#define SCIP_EVENTTYPE_LBRELAXED
Definition: type_event.h:64
int SCIPdigraphGetNNodes(SCIP_DIGRAPH *digraph)
Definition: misc.c:6744
SCIP_Longint SCIPnodeGetNumber(SCIP_NODE *node)
Definition: tree.c:7143
SCIP_RETCODE SCIPdigraphCreate(SCIP_DIGRAPH **digraph, int nnodes)
Definition: misc.c:6443
SCIP_Real SCIPvarGetUbGlobal(SCIP_VAR *var)
Definition: var.c:17176
static SCIP_DECL_CONSINITSOL(consInitsolSOS1)
Definition: cons_sos1.c:8929
SCIP_RETCODE SCIPsetConshdlrInitsol(SCIP *scip, SCIP_CONSHDLR *conshdlr, SCIP_DECL_CONSINITSOL((*consinitsol)))
Definition: scip.c:6094
#define SCIPduplicateBlockMemoryArray(scip, ptr, source, num)
Definition: scip.h:21904
static SCIP_DECL_CONSLOCK(consLockSOS1)
Definition: cons_sos1.c:9721
SCIP_Bool SCIPisCutEfficacious(SCIP *scip, SCIP_SOL *sol, SCIP_ROW *cut)
Definition: scip.c:33761
static SCIP_DECL_EVENTEXEC(eventExecSOS1)
Definition: cons_sos1.c:9969
SCIP_Real SCIPeventGetNewbound(SCIP_EVENT *event)
Definition: event.c:1162
static const NodeData nodedata[]
Definition: gastrans.c:74
SCIP_RETCODE SCIPsetConshdlrGetDiveBdChgs(SCIP *scip, SCIP_CONSHDLR *conshdlr, SCIP_DECL_CONSGETDIVEBDCHGS((*consgetdivebdchgs)))
Definition: scip.c:6527
SCIP_RETCODE SCIPsetConshdlrCopy(SCIP *scip, SCIP_CONSHDLR *conshdlr, SCIP_DECL_CONSHDLRCOPY((*conshdlrcopy)), SCIP_DECL_CONSCOPY((*conscopy)))
Definition: scip.c:5997
int SCIPvarGetNodeSOS1(SCIP_CONSHDLR *conshdlr, SCIP_VAR *var)
Definition: cons_sos1.c:10672
TCLIQUE_Bool tcliqueAddEdge(TCLIQUE_GRAPH *tcliquegraph, int node1, int node2)
SCIP_RETCODE SCIPdigraphSetNSuccessors(SCIP_DIGRAPH *digraph, int node, int nsuccessors)
Definition: misc.c:6728
#define SCIPerrorMessage
Definition: pub_message.h:45
const char * SCIPconshdlrGetName(SCIP_CONSHDLR *conshdlr)
Definition: cons.c:4113
SCIP_RETCODE SCIPaddCons(SCIP *scip, SCIP_CONS *cons)
Definition: scip.c:12410
#define DEFAULT_NSTRONGITER
Definition: cons_sos1.c:141
SCIP_Bool SCIPisLT(SCIP *scip, SCIP_Real val1, SCIP_Real val2)
Definition: scip.c:45764
#define DEFAULT_IMPLCUTSFREQ
Definition: cons_sos1.c:152
#define DEFAULT_SOSCONSPROP
Definition: cons_sos1.c:117
SCIP_RETCODE SCIPpropagateProbing(SCIP *scip, int maxproprounds, SCIP_Bool *cutoff, SCIP_Longint *ndomredsfound)
Definition: scip.c:35477
static SCIP_DECL_CONSPRINT(consPrintSOS1)
Definition: cons_sos1.c:9765
#define CONSHDLR_DELAYSEPA
Definition: cons_sos1.c:97
SCIP_RETCODE SCIPdelConsLocal(SCIP *scip, SCIP_CONS *cons)
Definition: scip.c:13111
#define DEFAULT_AUTOCUTSFROMSOS1
Definition: cons_sos1.c:146
SCIP_RETCODE SCIPaddVarSOS1(SCIP *scip, SCIP_CONS *cons, SCIP_VAR *var, SCIP_Real weight)
Definition: cons_sos1.c:10459
void tcliqueChangeWeight(TCLIQUE_GRAPH *tcliquegraph, int node, TCLIQUE_WEIGHT weight)
SCIP_RETCODE SCIPfixVarProbing(SCIP *scip, SCIP_VAR *var, SCIP_Real fixedval)
Definition: scip.c:35337
void * SCIPdigraphGetNodeData(SCIP_DIGRAPH *digraph, int node)
Definition: misc.c:6754
static SCIP_RETCODE updateWeightsTCliquegraph(SCIP *scip, SCIP_CONSHDLRDATA *conshdlrdata, TCLIQUE_DATA *tcliquedata, SCIP_DIGRAPH *conflictgraph, SCIP_SOL *sol, int nsos1vars)
Definition: cons_sos1.c:6159
SCIP_RETCODE SCIPgetProbvarSum(SCIP *scip, SCIP_VAR **var, SCIP_Real *scalar, SCIP_Real *constant)
Definition: scip.c:18929
#define SCIPfreeBufferArrayNull(scip, ptr)
Definition: scip.h:21938
static SCIP_DECL_CONSGETNVARS(consGetNVarsSOS1)
Definition: cons_sos1.c:9948
static SCIP_RETCODE generateBoundInequalityFromSOS1Cons(SCIP *scip, SCIP_CONSHDLR *conshdlr, SCIP_CONS *cons, SCIP_Bool local, SCIP_Bool global, SCIP_Bool strengthen, SCIP_Bool removable, SCIP_ROW **rowlb, SCIP_ROW **rowub)
Definition: cons_sos1.c:6794
SCIP_Bool SCIPisEfficacious(SCIP *scip, SCIP_Real efficacy)
Definition: scip.c:33779
void SCIPdigraphSetNodeData(SCIP_DIGRAPH *digraph, void *dataptr, int node)
Definition: misc.c:6770
BMS_BLKMEM * SCIPblkmem(SCIP *scip)
Definition: scip.c:45519
SCIP_RETCODE SCIPunlockVarCons(SCIP *scip, SCIP_VAR *var, SCIP_CONS *cons, SCIP_Bool lockdown, SCIP_Bool lockup)
Definition: scip.c:21383
static SCIP_RETCODE sepaBoundInequalitiesFromGraph(SCIP *scip, SCIP_CONSHDLR *conshdlr, SCIP_CONSHDLRDATA *conshdlrdata, SCIP_SOL *sol, int maxboundcuts, int *ngen, SCIP_Bool *cutoff)
Definition: cons_sos1.c:6720
const char * SCIPconsGetName(SCIP_CONS *cons)
Definition: cons.c:7881
SCIP_RETCODE SCIPmarkDoNotMultaggrVar(SCIP *scip, SCIP_VAR *var)
Definition: scip.c:25494
SCIP_Real SCIPvarGetAggrConstant(SCIP_VAR *var)
Definition: var.c:16923
SCIP_Bool SCIPconsIsPropagated(SCIP_CONS *cons)
Definition: cons.c:8100
SCIP_RETCODE SCIPendProbing(SCIP *scip)
Definition: scip.c:35187
struct SCIP_EventData SCIP_EVENTDATA
Definition: type_event.h:155
const char * SCIPvarGetName(SCIP_VAR *var)
Definition: var.c:16552
SCIP_CONSHDLR * conshdlr
Definition: cons_sos1.c:208
SCIP_RETCODE SCIPsetConshdlrFree(SCIP *scip, SCIP_CONSHDLR *conshdlr, SCIP_DECL_CONSFREE((*consfree)))
Definition: scip.c:6022
void SCIPhashmapFree(SCIP_HASHMAP **hashmap)
Definition: misc.c:2798
static SCIP_RETCODE fixVariableZeroNode(SCIP *scip, SCIP_VAR *var, SCIP_NODE *node, SCIP_Bool *infeasible)
Definition: cons_sos1.c:546
SCIP_CONSHDLRDATA * SCIPconshdlrGetData(SCIP_CONSHDLR *conshdlr)
Definition: cons.c:4133
internal miscellaneous methods
#define NULL
Definition: lpi_spx1.cpp:137
#define EVENTHDLR_DESC
Definition: cons_sos1.c:159
#define REALABS(x)
Definition: def.h:159
#define SCIP_EVENTTYPE_UBRELAXED
Definition: type_event.h:66
void tcliqueMaxClique(TCLIQUE_GETNNODES((*getnnodes)), TCLIQUE_GETWEIGHTS((*getweights)), TCLIQUE_ISEDGE((*isedge)), TCLIQUE_SELECTADJNODES((*selectadjnodes)), TCLIQUE_GRAPH *tcliquegraph, TCLIQUE_NEWSOL((*newsol)), TCLIQUE_DATA *tcliquedata, int *maxcliquenodes, int *nmaxcliquenodes, TCLIQUE_WEIGHT *maxcliqueweight, TCLIQUE_WEIGHT maxfirstnodeweight, TCLIQUE_WEIGHT minweight, int maxntreenodes, int backtrackfreq, int maxnzeroextensions, int fixednode, int *ntreenodes, TCLIQUE_STATUS *status)
SCIP_RETCODE SCIPcreateChild(SCIP *scip, SCIP_NODE **node, SCIP_Real nodeselprio, SCIP_Real estimate)
Definition: scip.c:36704
static SCIP_RETCODE appendVarSOS1(SCIP *scip, SCIP_CONS *cons, SCIP_CONSHDLRDATA *conshdlrdata, SCIP_VAR *var)
Definition: cons_sos1.c:989
static SCIP_RETCODE tightenVarsBoundsSOS1(SCIP *scip, SCIP_CONSHDLRDATA *conshdlrdata, SCIP_DIGRAPH *conflictgraph, SCIP_DIGRAPH *implgraph, SCIP_HASHMAP *implhash, SCIP_Bool **adjacencymatrix, SCIP_VAR **totalvars, int ntotalvars, int nsos1vars, int *nchgbds, SCIP_Bool *implupdate, SCIP_Bool *cutoff)
Definition: cons_sos1.c:2628
#define SCIP_CALL(x)
Definition: def.h:306
#define SCIP_EVENTTYPE_LBTIGHTENED
Definition: type_event.h:63
#define DEFAULT_MAXADDCOMPS
Definition: cons_sos1.c:131
int SCIPgetNTotalVars(SCIP *scip)
Definition: scip.c:12208
SCIP_Bool SCIPisFeasGT(SCIP *scip, SCIP_Real val1, SCIP_Real val2)
Definition: scip.c:46125
SCIP_RETCODE SCIPsolveProbingLP(SCIP *scip, int itlim, SCIP_Bool *lperror, SCIP_Bool *cutoff)
Definition: scip.c:35713
static SCIP_RETCODE computeNodeDataSOS1(SCIP *scip, SCIP_CONSHDLRDATA *conshdlrdata, int nsos1vars)
Definition: cons_sos1.c:8612
SCIP_RETCODE SCIPgetProbvarLinearSum(SCIP *scip, SCIP_VAR **vars, SCIP_Real *scalars, int *nvars, int varssize, SCIP_Real *constant, int *requiredsize, SCIP_Bool mergemultiples)
Definition: scip.c:18873
SCIP_Real SCIPvarGetMultaggrConstant(SCIP_VAR *var)
Definition: var.c:16970
#define DEFAULT_DEPTHIMPLANALYSIS
Definition: cons_sos1.c:112
static SCIP_RETCODE initsepaBoundInequalityFromSOS1Cons(SCIP *scip, SCIP_CONSHDLR *conshdlr, SCIP_CONSHDLRDATA *conshdlrdata, SCIP_CONS **conss, int nconss, SCIP_SOL *sol, SCIP_Bool solvedinitlp, int maxboundcuts, int *ngen, SCIP_Bool *cutoff)
Definition: cons_sos1.c:6857
#define DEFAULT_BOUNDCUTSFROMSOS1
Definition: cons_sos1.c:144
void SCIPverbMessage(SCIP *scip, SCIP_VERBLEVEL msgverblevel, FILE *file, const char *formatstr,...)
Definition: scip.c:1353
SCIP_Bool SCIPconsIsLocal(SCIP_CONS *cons)
Definition: cons.c:8120
SCIP_RETCODE SCIPdigraphAddArc(SCIP_DIGRAPH *digraph, int startnode, int endnode, void *data)
Definition: misc.c:6666
SCIP_RETCODE SCIPsetConshdlrResprop(SCIP *scip, SCIP_CONSHDLR *conshdlr, SCIP_DECL_CONSRESPROP((*consresprop)))
Definition: scip.c:6297
SCIP_DIGRAPH * SCIPgetConflictgraphSOS1(SCIP_CONSHDLR *conshdlr)
Definition: cons_sos1.c:10604
SCIP_RETCODE SCIPaddCut(SCIP *scip, SCIP_SOL *sol, SCIP_ROW *cut, SCIP_Bool forcecut, SCIP_Bool *infeasible)
Definition: scip.c:33869
struct SCIP_ConsData SCIP_CONSDATA
Definition: type_cons.h:50
SCIP_Bool strthenboundcuts
Definition: cons_sos1.c:216
SCIP_Bool SCIPdivesetSupportsType(SCIP_DIVESET *diveset, SCIP_DIVETYPE divetype)
Definition: heur.c:590
int SCIPconshdlrGetNConss(SCIP_CONSHDLR *conshdlr)
Definition: cons.c:4515
#define DEFAULT_NSTRONGROUNDS
Definition: cons_sos1.c:138
SCIP_RETCODE SCIPaddConsNode(SCIP *scip, SCIP_NODE *node, SCIP_CONS *cons, SCIP_NODE *validnode)
Definition: scip.c:12960
SCIP_RETCODE SCIPcomputeArraysSetminus(int *array1, int narray1, int *array2, int narray2, int *setminusarray, int *nsetminusarray)
Definition: misc.c:9195
#define CONSHDLR_DELAYPROP
Definition: cons_sos1.c:98
SCIP_Bool SCIPvarIsSOS1(SCIP_CONSHDLR *conshdlr, SCIP_VAR *var)
Definition: cons_sos1.c:10648
SCIP_RETCODE SCIPcreateConsSetpack(SCIP *scip, SCIP_CONS **cons, const char *name, int nvars, SCIP_VAR **vars, SCIP_Bool initial, SCIP_Bool separate, SCIP_Bool enforce, SCIP_Bool check, SCIP_Bool propagate, SCIP_Bool local, SCIP_Bool modifiable, SCIP_Bool dynamic, SCIP_Bool removable, SCIP_Bool stickingatnode)
Definition: cons_setppc.c:9034
SCIP_RETCODE SCIPappendVarSOS1(SCIP *scip, SCIP_CONS *cons, SCIP_VAR *var)
Definition: cons_sos1.c:10493
static SCIP_DECL_CONSPROP(consPropSOS1)
Definition: cons_sos1.c:9499
#define CONSHDLR_NEEDSCONS
Definition: cons_sos1.c:99
static SCIP_RETCODE checkConComponentsVarbound(SCIP *scip, SCIP_DIGRAPH *conflictgraph, int nsos1vars, SCIP_Bool checklb)
Definition: cons_sos1.c:8369
#define SCIPallocBufferArray(scip, ptr, num)
Definition: scip.h:21925
SCIP_RETCODE SCIPsetSolVal(SCIP *scip, SCIP_SOL *sol, SCIP_VAR *var, SCIP_Real val)
Definition: scip.c:37867
public data structures and miscellaneous methods
#define DEFAULT_MAXBOUNDCUTSROOT
Definition: cons_sos1.c:150
SCIP_RETCODE SCIPdigraphAddArcSafe(SCIP_DIGRAPH *digraph, int startnode, int endnode, void *data)
Definition: misc.c:6694
int SCIPdigraphGetNSuccessors(SCIP_DIGRAPH *digraph, int node)
Definition: misc.c:6802
static SCIP_RETCODE freeImplGraphSOS1(SCIP *scip, SCIP_CONSHDLRDATA *conshdlrdata)
Definition: cons_sos1.c:3937
SCIP_VAR * SCIPeventGetVar(SCIP_EVENT *event)
Definition: event.c:982
#define CONSHDLR_PROP_TIMING
Definition: cons_sos1.c:100
#define DEFAULT_AUTOSOS1BRANCH
Definition: cons_sos1.c:124
static SCIP_DECL_CONSSEPASOL(consSepasolSOS1)
Definition: cons_sos1.c:9364
#define SCIP_Bool
Definition: def.h:61
static SCIP_DECL_CONSEXITSOL(consExitsolSOS1)
Definition: cons_sos1.c:8982
SCIP_LPSOLSTAT SCIPgetLPSolstat(SCIP *scip)
Definition: scip.c:28854
static SCIP_RETCODE getBranchingDecisionStrongbranchSOS1(SCIP *scip, SCIP_CONSHDLRDATA *conshdlrdata, SCIP_DIGRAPH *conflictgraph, SCIP_SOL *sol, int nsos1vars, SCIP_Real lpobjval, SCIP_Bool bipbranch, int nstrongrounds, SCIP_Bool *verticesarefixed, int *fixingsnode1, int *fixingsnode2, int *vertexbestprior, SCIP_Real *bestobjval1, SCIP_Real *bestobjval2, SCIP_RESULT *result)
Definition: cons_sos1.c:4460
static SCIP_DECL_CONSDELETE(consDeleteSOS1)
Definition: cons_sos1.c:9054
SCIP_EVENTTYPE SCIPeventGetType(SCIP_EVENT *event)
Definition: event.c:959
#define DEFAULT_MAXTIGHTENBDS
Definition: cons_sos1.c:110
static SCIP_RETCODE enforceConflictgraph(SCIP *scip, SCIP_CONSHDLRDATA *conshdlrdata, SCIP_CONSHDLR *conshdlr, int nconss, SCIP_CONS **conss, SCIP_SOL *sol, SCIP_RESULT *result)
Definition: cons_sos1.c:5323
SCIP_RETCODE SCIPcreateEmptyRowCons(SCIP *scip, SCIP_ROW **row, SCIP_CONSHDLR *conshdlr, const char *name, SCIP_Real lhs, SCIP_Real rhs, SCIP_Bool local, SCIP_Bool modifiable, SCIP_Bool removable)
Definition: scip.c:30022
int SCIPgetDepth(SCIP *scip)
Definition: scip.c:42094
SCIP_Bool cutoff
Definition: cons_sos1.c:212
SCIP_RETCODE SCIPupdateNodeLowerbound(SCIP *scip, SCIP_NODE *node, SCIP_Real newbound)
Definition: scip.c:13394
SCIP_RETCODE SCIPprintCons(SCIP *scip, SCIP_CONS *cons, FILE *file)
Definition: scip.c:28652
#define MAX(x, y)
Definition: tclique_def.h:75
int SCIPdigraphGetNArcs(SCIP_DIGRAPH *digraph)
Definition: misc.c:6784
#define CONSHDLR_DESC
Definition: cons_sos1.c:87
static SCIP_RETCODE freeConflictgraph(SCIP *scip, SCIP_CONSHDLRDATA *conshdlrdata)
Definition: cons_sos1.c:8844
SCIP_CONSHDLR * SCIPconsGetHdlr(SCIP_CONS *cons)
Definition: cons.c:7901
int SCIPvarCompare(SCIP_VAR *var1, SCIP_VAR *var2)
Definition: var.c:11249
static SCIP_RETCODE addVarSOS1(SCIP *scip, SCIP_CONS *cons, SCIP_CONSHDLRDATA *conshdlrdata, SCIP_VAR *var, SCIP_Real weight)
Definition: cons_sos1.c:919
SCIP_Bool SCIPconsIsChecked(SCIP_CONS *cons)
Definition: cons.c:8080
static SCIP_RETCODE getBranchingVerticesSOS1(SCIP *scip, SCIP_DIGRAPH *conflictgraph, SCIP_SOL *sol, SCIP_Bool *verticesarefixed, SCIP_Bool bipbranch, int branchvertex, int *fixingsnode1, int *nfixingsnode1, int *fixingsnode2, int *nfixingsnode2)
Definition: cons_sos1.c:4103
SCIP_Bool SCIPconsIsInitial(SCIP_CONS *cons)
Definition: cons.c:8050
SCIP_RETCODE SCIPdropVarEvent(SCIP *scip, SCIP_VAR *var, SCIP_EVENTTYPE eventtype, SCIP_EVENTHDLR *eventhdlr, SCIP_EVENTDATA *eventdata, int filterpos)
Definition: scip.c:40321
int SCIPgetNVarsSOS1(SCIP *scip, SCIP_CONS *cons)
Definition: cons_sos1.c:10526
SCIP_Real SCIPcalcNodeselPriority(SCIP *scip, SCIP_VAR *var, SCIP_BRANCHDIR branchdir, SCIP_Real targetvalue)
Definition: scip.c:36654
SCIP_VAR * SCIPnodeGetVarSOS1(SCIP_DIGRAPH *conflictgraph, int node)
Definition: cons_sos1.c:10703
SCIP_VAR * SCIPvarGetAggrVar(SCIP_VAR *var)
Definition: var.c:16901
SCIP_Real scaleval
Definition: cons_sos1.c:211
SCIP_Longint SCIPgetNDualResolveLPs(SCIP *scip)
Definition: scip.c:41647
#define DEFAULT_BOUNDCUTSDEPTH
Definition: cons_sos1.c:148
SCIP_RETCODE SCIPfixVar(SCIP *scip, SCIP_VAR *var, SCIP_Real fixedval, SCIP_Bool *infeasible, SCIP_Bool *fixed)
Definition: scip.c:25141
#define BMScopyMemoryArray(ptr, source, num)
Definition: memory.h:89
SCIPInterval log(const SCIPInterval &x)
SCIP_RETCODE SCIPlockVarCons(SCIP *scip, SCIP_VAR *var, SCIP_CONS *cons, SCIP_Bool lockdown, SCIP_Bool lockup)
Definition: scip.c:21309
SCIP_Real SCIPgetSolOrigObj(SCIP *scip, SCIP_SOL *sol)
Definition: scip.c:38090
static SCIP_RETCODE performImplicationGraphAnalysis(SCIP *scip, SCIP_CONSHDLRDATA *conshdlrdata, SCIP_DIGRAPH *conflictgraph, SCIP_VAR **totalvars, SCIP_DIGRAPH *implgraph, SCIP_HASHMAP *implhash, SCIP_Bool **adjacencymatrix, int givennode, int nonznode, SCIP_Real *impllbs, SCIP_Real *implubs, SCIP_Bool *implnodes, int *naddconss, int *probingdepth, SCIP_Bool *infeasible)
Definition: cons_sos1.c:2045
SCIP_RETCODE SCIPsetConshdlrPrint(SCIP *scip, SCIP_CONSHDLR *conshdlr, SCIP_DECL_CONSPRINT((*consprint)))
Definition: scip.c:6435
#define SCIP_EVENTTYPE_UBTIGHTENED
Definition: type_event.h:65
Constraint handler for linear constraints in their most general form, .
static SCIP_RETCODE initImplGraphSOS1(SCIP *scip, SCIP_CONSHDLRDATA *conshdlrdata, SCIP_DIGRAPH *conflictgraph, int nsos1vars, int maxrounds, int *nchgbds, SCIP_Bool *cutoff, SCIP_Bool *success)
Definition: cons_sos1.c:3766
static SCIP_DECL_CONSHDLRCOPY(conshdlrCopySOS1)
Definition: cons_sos1.c:8890
int SCIPvarGetMultaggrNVars(SCIP_VAR *var)
Definition: var.c:16934
SCIP_Bool SCIPisInfinity(SCIP *scip, SCIP_Real val)
Definition: scip.c:45827
#define DEFAULT_BRANCHSTRATEGIES
Definition: cons_sos1.c:120
SCIP_RETCODE SCIPinferVarLbCons(SCIP *scip, SCIP_VAR *var, SCIP_Real newbound, SCIP_CONS *infercons, int inferinfo, SCIP_Bool force, SCIP_Bool *infeasible, SCIP_Bool *tightened)
Definition: scip.c:22414
static SCIP_RETCODE initTCliquegraph(SCIP *scip, SCIP_CONSHDLR *conshdlr, SCIP_CONSHDLRDATA *conshdlrdata, SCIP_DIGRAPH *conflictgraph, int nsos1vars)
Definition: cons_sos1.c:6090
static SCIP_RETCODE addBoundCutSepa(SCIP *scip, TCLIQUE_DATA *tcliquedata, SCIP_ROW *rowlb, SCIP_ROW *rowub, SCIP_Bool *success, SCIP_Bool *cutoff)
Definition: cons_sos1.c:6219
SCIP_Real SCIPcalcChildEstimate(SCIP *scip, SCIP_VAR *var, SCIP_Real targetvalue)
Definition: scip.c:36681
#define SCIP_MAXTREEDEPTH
Definition: def.h:242
#define CONSHDLR_SEPAFREQ
Definition: cons_sos1.c:91
int maxboundcuts
Definition: cons_sos1.c:215
SCIP_RETCODE SCIPcreateConsBasicSOS1(SCIP *scip, SCIP_CONS **cons, const char *name, int nvars, SCIP_VAR **vars, SCIP_Real *weights)
Definition: cons_sos1.c:10443
static SCIP_DECL_CONSCOPY(consCopySOS1)
Definition: cons_sos1.c:9795
int SCIPgetNVars(SCIP *scip)
Definition: scip.c:11631
#define SCIP_REAL_MAX
Definition: def.h:136
#define SCIP_REAL_MIN
Definition: def.h:137
SCIP_RETCODE SCIPcreateConsLinear(SCIP *scip, SCIP_CONS **cons, const char *name, int nvars, SCIP_VAR **vars, SCIP_Real *vals, SCIP_Real lhs, SCIP_Real rhs, SCIP_Bool initial, SCIP_Bool separate, SCIP_Bool enforce, SCIP_Bool check, SCIP_Bool propagate, SCIP_Bool local, SCIP_Bool modifiable, SCIP_Bool dynamic, SCIP_Bool removable, SCIP_Bool stickingatnode)
#define DEFAULT_BOUNDCUTSFROMGRAPH
Definition: cons_sos1.c:145
SCIP_RETCODE SCIPreleaseRow(SCIP *scip, SCIP_ROW **row)
Definition: scip.c:30160
#define DEFAULT_ADDEXTENDEDBDS
Definition: cons_sos1.c:135
static SCIP_RETCODE getBoundConsFromVertices(SCIP *scip, SCIP_DIGRAPH *conflictgraph, SCIP_SOL *sol, int v1, int v2, SCIP_VAR *boundvar, SCIP_Bool extend, SCIP_CONS *cons, SCIP_Real *feas)
Definition: cons_sos1.c:4674
SCIP_Longint SCIPgetNNodeInitLPIterations(SCIP *scip)
Definition: scip.c:41739
SCIP_Longint SCIPgetNNodeInitLPs(SCIP *scip)
Definition: scip.c:41721
SCIP_Real SCIPgetLPObjval(SCIP *scip)
Definition: scip.c:28897
SCIP_Bool SCIPisGT(SCIP *scip, SCIP_Real val1, SCIP_Real val2)
Definition: scip.c:45790
static SCIP_RETCODE addBranchingComplementaritiesSOS1(SCIP *scip, SCIP_NODE *node, SCIP_CONSHDLRDATA *conshdlrdata, SCIP_DIGRAPH *conflictgraph, SCIP_DIGRAPH *localconflicts, SCIP_SOL *sol, int nsos1vars, SCIP_Bool *verticesarefixed, int *fixingsnode1, int nfixingsnode1, int *fixingsnode2, int nfixingsnode2, int *naddedconss, SCIP_Bool onlyviolsos1)
Definition: cons_sos1.c:4902
static SCIP_RETCODE makeSOS1conflictgraphFeasible(SCIP *scip, SCIP_CONSHDLR *conshdlr, SCIP_SOL *sol, SCIP_Bool *changed, SCIP_Bool *allroundable)
Definition: cons_sos1.c:7635
SCIP_RETCODE SCIPaddCharParam(SCIP *scip, const char *name, const char *desc, char *valueptr, SCIP_Bool isadvanced, char defaultvalue, const char *allowedvalues, SCIP_DECL_PARAMCHGD((*paramchgd)), SCIP_PARAMDATA *paramdata)
Definition: scip.c:4286
static const SCIP_Real scalars[]
Definition: lp.c:5563
SCIP_RETCODE SCIPgetVarCopy(SCIP *sourcescip, SCIP *targetscip, SCIP_VAR *sourcevar, SCIP_VAR **targetvar, SCIP_HASHMAP *varmap, SCIP_HASHMAP *consmap, SCIP_Bool global, SCIP_Bool *success)
Definition: scip.c:1911
SCIP_VAR ** SCIPgetVarsLinear(SCIP *scip, SCIP_CONS *cons)
SCIP_CONSDATA * SCIPconsGetData(SCIP_CONS *cons)
Definition: cons.c:7911
static SCIP_DECL_CONSPARSE(consParseSOS1)
Definition: cons_sos1.c:9861
SCIP_RETCODE SCIPinferVarUbCons(SCIP *scip, SCIP_VAR *var, SCIP_Real newbound, SCIP_CONS *infercons, int inferinfo, SCIP_Bool force, SCIP_Bool *infeasible, SCIP_Bool *tightened)
Definition: scip.c:22527
SCIP_RETCODE SCIPreleaseCons(SCIP *scip, SCIP_CONS **cons)
Definition: scip.c:27323
static SCIP_RETCODE checkSwitchNonoverlappingSOS1Methods(SCIP *scip, SCIP_CONSHDLRDATA *conshdlrdata, SCIP_DIGRAPH *conflictgraph, SCIP_CONS **conss, int nconss)
Definition: cons_sos1.c:8531
SCIP_RETCODE SCIPsetConshdlrPresol(SCIP *scip, SCIP_CONSHDLR *conshdlr, SCIP_DECL_CONSPRESOL((*conspresol)), int maxprerounds, SCIP_PRESOLTIMING presoltiming)
Definition: scip.c:6190
static SCIP_RETCODE branchCons(SCIP *scip, SCIP_CONS *cons, SCIP_RESULT *result)
SCIP_Real SCIPeventGetOldbound(SCIP_EVENT *event)
Definition: event.c:1138
SCIP_Bool SCIPisFeasPositive(SCIP *scip, SCIP_Real val)
Definition: scip.c:46163
struct SCIP_SuccData SCIP_SUCCDATA
Definition: cons_sos1.c:201
SCIP_VAR ** SCIPgetVars(SCIP *scip)
Definition: scip.c:11586
SCIP_VARSTATUS SCIPvarGetStatus(SCIP_VAR *var)
Definition: var.c:16671
static SCIP_RETCODE lockVariableSOS1(SCIP *scip, SCIP_CONS *cons, SCIP_VAR *var)
Definition: cons_sos1.c:718
static SCIP_RETCODE sepaImplBoundCutsSOS1(SCIP *scip, SCIP_CONSHDLR *conshdlr, SCIP_CONSHDLRDATA *conshdlrdata, SCIP_SOL *sol, int maxcuts, int *ngen, SCIP_Bool *cutoff)
Definition: cons_sos1.c:6971
#define SCIP_Real
Definition: def.h:135
SCIP_Bool SCIPconsIsModifiable(SCIP_CONS *cons)
Definition: cons.c:8130
SCIP_RETCODE SCIPaddVarsToRow(SCIP *scip, SCIP_ROW *row, int nvars, SCIP_VAR **vars, SCIP_Real *vals)
Definition: scip.c:30314
#define DEFAULT_MAXIMPLCUTSROOT
Definition: cons_sos1.c:155
#define DEFAULT_BOUNDCUTSFREQ
Definition: cons_sos1.c:147
SCIP_Bool SCIPisStopped(SCIP *scip)
Definition: scip.c:1138
#define MIN(x, y)
Definition: memory.c:75
SCIP_RETCODE SCIPsetConshdlrGetNVars(SCIP *scip, SCIP_CONSHDLR *conshdlr, SCIP_DECL_CONSGETNVARS((*consgetnvars)))
Definition: scip.c:6504
#define DEFAULT_BRANCHINGRULE
Definition: cons_sos1.c:121
constraint handler for SOS type 1 constraints
#define DEFAULT_FIXNONZERO
Definition: cons_sos1.c:125
#define DEFAULT_PERFIMPLANALYSIS
Definition: cons_sos1.c:111
SCIP_Bool SCIPconsIsEnforced(SCIP_CONS *cons)
Definition: cons.c:8070
static SCIP_RETCODE updateImplicationGraphSOS1(SCIP *scip, SCIP_CONSHDLRDATA *conshdlrdata, SCIP_DIGRAPH *conflictgraph, SCIP_Bool **adjacencymatrix, SCIP_DIGRAPH *implgraph, SCIP_HASHMAP *implhash, SCIP_Bool *implnodes, SCIP_VAR **totalvars, int **cliquecovers, int *cliquecoversizes, int *varincover, SCIP_VAR **vars, SCIP_Real *coefs, int nvars, SCIP_Real *bounds, SCIP_VAR *var, SCIP_Real bound, SCIP_Real boundnonzero, int ninftynonzero, SCIP_Bool lower, int *nchgbds, SCIP_Bool *update, SCIP_Bool *infeasible)
Definition: cons_sos1.c:2358
#define SCIP_INVALID
Definition: def.h:155
SCIP_Bool SCIPconsIsSeparated(SCIP_CONS *cons)
Definition: cons.c:8060
#define SCIP_DIVETYPE_SOS1VARIABLE
Definition: type_heur.h:46
SCIP_RETCODE SCIPprintRow(SCIP *scip, SCIP_ROW *row, FILE *file)
Definition: scip.c:30762
static SCIP_RETCODE getCoverVertices(SCIP_DIGRAPH *conflictgraph, SCIP_Bool *verticesarefixed, int vertex, int *neightocover, int nneightocover, int *coververtices, int *ncoververtices)
Definition: cons_sos1.c:3996
void SCIPsortInt(int *intarray, int len)
static SCIP_RETCODE presolRoundVarsSOS1(SCIP *scip, SCIP_CONSHDLRDATA *conshdlrdata, SCIP_DIGRAPH *conflictgraph, SCIP_Bool **adjacencymatrix, int nsos1vars, int *nfixedvars, int *nchgbds, int *naddconss, SCIP_RESULT *result)
Definition: cons_sos1.c:3350
static SCIP_DECL_CONSPRESOL(consPresolSOS1)
Definition: cons_sos1.c:9200
#define SCIP_Longint
Definition: def.h:120
void SCIPsortRealPtr(SCIP_Real *realarray, void **ptrarray, int len)
int SCIPvarGetIndex(SCIP_VAR *var)
Definition: var.c:16849
SCIP_OBJSENSE SCIPgetObjsense(SCIP *scip)
Definition: scip.c:10881
static SCIP_RETCODE checkLinearConssVarboundSOS1(SCIP *scip, SCIP_CONSHDLRDATA *conshdlrdata, SCIP_CONS **linconss, int nlinconss)
Definition: cons_sos1.c:8458
static SCIP_RETCODE handleNewVariableSOS1(SCIP *scip, SCIP_CONS *cons, SCIP_CONSDATA *consdata, SCIP_CONSHDLRDATA *conshdlrdata, SCIP_VAR *var, SCIP_Bool transformed)
Definition: cons_sos1.c:784
static SCIP_RETCODE consdataEnsurevarsSizeSOS1(SCIP *scip, SCIP_CONSDATA *consdata, int num, SCIP_Bool reserveWeights)
Definition: cons_sos1.c:756
static SCIP_RETCODE unlockVariableSOS1(SCIP *scip, SCIP_CONS *cons, SCIP_VAR *var)
Definition: cons_sos1.c:737
static SCIP_Bool varIsSOS1(SCIP_CONSHDLRDATA *conshdlrdata, SCIP_VAR *var)
Definition: cons_sos1.c:508
static SCIP_DECL_CONSCHECK(consCheckSOS1)
Definition: cons_sos1.c:9431
static SCIP_RETCODE presolRoundConssSOS1(SCIP *scip, SCIP_EVENTHDLR *eventhdlr, SCIP_CONSHDLRDATA *conshdlrdata, SCIP_DIGRAPH *conflictgraph, SCIP_Bool **adjacencymatrix, SCIP_CONS **conss, int nconss, int nsos1vars, int *naddconss, int *ndelconss, int *nupgdconss, int *nfixedvars, int *nremovedvars, SCIP_RESULT *result)
Definition: cons_sos1.c:1776
SCIP_Bool SCIPisZero(SCIP *scip, SCIP_Real val)
Definition: scip.c:45864
SCIP_Real * SCIPgetValsLinear(SCIP *scip, SCIP_CONS *cons)
SCIP_RETCODE SCIPcreateConsSOS1(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)
Definition: cons_sos1.c:10322
TCLIQUE_Bool tcliqueFlush(TCLIQUE_GRAPH *tcliquegraph)
struct SCIP_ConshdlrData SCIP_CONSHDLRDATA
Definition: type_cons.h:49
#define DEFAULT_STRTHENBOUNDCUTS
Definition: cons_sos1.c:151
#define nnodes
Definition: gastrans.c:65
SCIP_Real SCIPvarGetUbLocal(SCIP_VAR *var)
Definition: var.c:17232
static SCIP_RETCODE markNeighborsMWISHeuristic(SCIP *scip, SCIP_CONSHDLR *conshdlr, SCIP_DIGRAPH *conflictgraph, int node, SCIP_Bool *mark, SCIP_Bool *indset, int *cnt, SCIP_Bool *cutoff)
Definition: cons_sos1.c:7388
#define SCIPfreeBlockMemoryArrayNull(scip, ptr, num)
Definition: scip.h:21910
SCIP_RETCODE SCIPgetDivesetScore(SCIP *scip, SCIP_DIVESET *diveset, SCIP_DIVETYPE divetype, SCIP_VAR *divecand, SCIP_Real divecandsol, SCIP_Real divecandfrac, SCIP_Real *candscore, SCIP_Bool *roundup)
Definition: scip.c:35902
SCIP_Bool SCIPvarIsTransformed(SCIP_VAR *var)
Definition: var.c:16694
SCIP_Real SCIPsumepsilon(SCIP *scip)
Definition: scip.c:45260
SCIP_Real SCIPgetUpperbound(SCIP *scip)
Definition: scip.c:42472
SCIP_RETCODE SCIPstartProbing(SCIP *scip)
Definition: scip.c:35055
static SCIP_RETCODE getBranchingPrioritiesSOS1(SCIP *scip, SCIP_CONSHDLRDATA *conshdlrdata, SCIP_DIGRAPH *conflictgraph, SCIP_SOL *sol, int nsos1vars, SCIP_Bool *verticesarefixed, SCIP_Bool bipbranch, int *fixingsnode1, int *fixingsnode2, SCIP_Real *branchpriors, int *vertexbestprior, SCIP_Bool *relsolfeas)
Definition: cons_sos1.c:4216
SCIP_RETCODE SCIPhashmapInsert(SCIP_HASHMAP *hashmap, void *origin, void *image)
Definition: misc.c:2846
#define CONSHDLR_PRESOLTIMING
Definition: cons_sos1.c:101
void SCIPswapInts(int *value1, int *value2)
Definition: misc.c:8970
SCIP_Real SCIPceil(SCIP *scip, SCIP_Real val)
Definition: scip.c:45949
int TCLIQUE_WEIGHT
Definition: tclique.h:37
static SCIP_DECL_CONSGETDIVEBDCHGS(consGetDiveBdChgsSOS1)
Definition: cons_sos1.c:10066
void SCIPdigraphFree(SCIP_DIGRAPH **digraph)
Definition: misc.c:6589
SCIP_RETCODE SCIPsetConshdlrExitsol(SCIP *scip, SCIP_CONSHDLR *conshdlr, SCIP_DECL_CONSEXITSOL((*consexitsol)))
Definition: scip.c:6118
SCIP_Longint SCIPgetNNodes(SCIP *scip)
Definition: scip.c:41182
#define SCIPABORT()
Definition: def.h:278
SCIP_RETCODE SCIPwriteVarName(SCIP *scip, FILE *file, SCIP_VAR *var, SCIP_Bool type)
Definition: scip.c:17353
SCIP_Bool SCIPvarIsIntegral(SCIP_VAR *var)
Definition: var.c:16743
SCIP_RETCODE SCIPchgVarUbProbing(SCIP *scip, SCIP_VAR *var, SCIP_Real newbound)
Definition: scip.c:35264
static TCLIQUE_NEWSOL(tcliqueNewsolClique)
Definition: cons_sos1.c:6585
#define DEFAULT_ADDCOMPS
Definition: cons_sos1.c:128
static SCIP_RETCODE generateBoundInequalityFromSOS1Nodes(SCIP *scip, SCIP_CONSHDLR *conshdlr, SCIP_DIGRAPH *conflictgraph, int *nodes, int nnodes, SCIP_Real rhs, SCIP_Bool local, SCIP_Bool global, SCIP_Bool strengthen, SCIP_Bool removable, const char *nameext, SCIP_ROW **rowlb, SCIP_ROW **rowub)
Definition: cons_sos1.c:6293
static SCIP_RETCODE enforceSOS1(SCIP *scip, SCIP_CONSHDLR *conshdlr, int nconss, SCIP_CONS **conss, SCIP_SOL *sol, SCIP_RESULT *result)
Definition: cons_sos1.c:6027
#define DEFAULT_MAXEXTENSIONS
Definition: cons_sos1.c:109
int nboundcuts
Definition: cons_sos1.c:214
SCIP_Real SCIPgetSolVal(SCIP *scip, SCIP_SOL *sol, SCIP_VAR *var)
Definition: scip.c:38007
static SCIP_DECL_CONSTRANS(consTransSOS1)
Definition: cons_sos1.c:9108
int SCIPgetNVarsLinear(SCIP *scip, SCIP_CONS *cons)
static int varGetNodeSOS1(SCIP_CONSHDLRDATA *conshdlrdata, SCIP_VAR *var)
Definition: cons_sos1.c:525
SCIP_SOL * sol
Definition: cons_sos1.c:210
SCIP_Real SCIPgetLhsLinear(SCIP *scip, SCIP_CONS *cons)
SCIP_RETCODE SCIPaddRealParam(SCIP *scip, const char *name, const char *desc, SCIP_Real *valueptr, SCIP_Bool isadvanced, SCIP_Real defaultvalue, SCIP_Real minvalue, SCIP_Real maxvalue, SCIP_DECL_PARAMCHGD((*paramchgd)), SCIP_PARAMDATA *paramdata)
Definition: scip.c:4258
SCIP_DIGRAPH * conflictgraph
Definition: cons_sos1.c:209
SCIP_Real SCIPfloor(SCIP *scip, SCIP_Real val)
Definition: scip.c:45937
SCIP_Bool SCIPvarMayRoundUp(SCIP_VAR *var)
Definition: var.c:3280
static SCIP_RETCODE computeVarsCoverSOS1(SCIP *scip, SCIP_DIGRAPH *conflictgraphroot, SCIP_DIGRAPH *conflictgraphlin, SCIP_VAR **linvars, SCIP_Bool *coveredvars, int *clique, int *cliquesize, int v, SCIP_Bool considersolvals)
Definition: cons_sos1.c:2517
static SCIP_Bool isConnectedSOS1(SCIP_Bool **adjacencymatrix, SCIP_DIGRAPH *conflictgraph, int vertex1, int vertex2)
Definition: cons_sos1.c:299
SCIP_Bool SCIPvarMayRoundDown(SCIP_VAR *var)
Definition: var.c:3272
SCIP_RETCODE SCIPaddBoolParam(SCIP *scip, const char *name, const char *desc, SCIP_Bool *valueptr, SCIP_Bool isadvanced, SCIP_Bool defaultvalue, SCIP_DECL_PARAMCHGD((*paramchgd)), SCIP_PARAMDATA *paramdata)
Definition: scip.c:4176
SCIP_Bool SCIPvarIsActive(SCIP_VAR *var)
Definition: var.c:16839
static SCIP_Bool isViolatedSOS1(SCIP *scip, SCIP_DIGRAPH *conflictgraph, int node, SCIP_SOL *sol)
Definition: cons_sos1.c:359
uint64_t SCIP_EVENTTYPE
Definition: type_event.h:134
#define SCIPreallocBufferArray(scip, ptr, num)
Definition: scip.h:21929
SCIP_RETCODE SCIPsetConshdlrProp(SCIP *scip, SCIP_CONSHDLR *conshdlr, SCIP_DECL_CONSPROP((*consprop)), int propfreq, SCIP_Bool delayprop, SCIP_PROPTIMING proptiming)
Definition: scip.c:5931