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