GCG 4.1.1 (dev)

Generic Column Generation

Loading...
Searching...
No Matches
zerohalf_selector.c
Go to the documentation of this file.
1/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2/* */
3/* This file is part of the program and library */
4/* GCG --- Generic Column Generation */
5/* a Dantzig-Wolfe decomposition based extension */
6/* of the branch-cut-and-price framework */
7/* SCIP --- Solving Constraint Integer Programs */
8/* */
9/* Copyright (C) 2010-2026 Operations Research, RWTH Aachen University */
10/* Zuse Institute Berlin (ZIB) */
11/* */
12/* Licensed under the Apache License, Version 2.0 (the "License"); */
13/* you may not use this file except in compliance with the License. */
14/* You may obtain a copy of the License at */
15/* */
16/* http://www.apache.org/licenses/LICENSE-2.0 */
17/* */
18/* Unless required by applicable law or agreed to in writing, software */
19/* distributed under the License is distributed on an "AS IS" BASIS, */
20/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. */
21/* See the License for the specific language governing permissions and */
22/* limitations under the License. */
23/* */
24/* You should have received a copy of the Apache-2.0 license */
25/* along with GCG; see the file LICENSE. If not visit gcg.or.rwth-aachen.de.*/
26/* */
27/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
28
29/**@file zerohalf_selector.c
30 * @brief {0,1/2}-cuts separator
31 * @author Leona Gottwald
32 * @author Manuel Kutschka
33 * @author Kati Wolter
34 *
35 * {0,1/2}-Chvátal-Gomory cuts separator. It solves the following separation problem:
36 * Consider an integer program
37 * \f[
38 * \min \{ c^T x : Ax \leq b, x \geq 0, x \mbox{ integer} \}
39 * \f]
40 * and a fractional solution \f$x^*\f$ of its LP relaxation. Find a weightvector \f$u\f$ whose entries \f$u_i\f$ are either 0 or
41 * \f$\frac{1}{2}\f$ such that the following inequality is valid for all integral solutions and violated by \f$x^*\f$:
42 * \f[
43 * \lfloor(u^T A) x \rfloor \leq \lfloor u^T b\rfloor
44 * \f]
45 *
46 * References:
47 * - Alberto Caprara, Matteo Fischetti. {0,1/2}-Chvatal-Gomory cuts. Math. Programming, Volume 74, p221--235, 1996.
48 * - Arie M. C. A. Koster, Adrian Zymolka and Manuel Kutschka. \n
49 * Algorithms to separate {0,1/2}-Chvatal-Gomory cuts.
50 * Algorithms - ESA 2007: 15th Annual European Symposium, Eilat, Israel, October 8-10, 2007, \n
51 * Proceedings. Lecture Notes in Computer Science, Volume 4698, p. 693--704, 2007.
52 * - Arie M. C. A. Koster, Adrian Zymolka and Manuel Kutschka. \n
53 * Algorithms to separate {0,1/2}-Chvatal-Gomory cuts (Extended Version). \n
54 * ZIB Report 07-10, Zuse Institute Berlin, 2007. http://www.zib.de/Publications/Reports/ZR-07-10.pdf
55 * - Manuel Kutschka. Algorithmen zur Separierung von {0,1/2}-Schnitten. Diplomarbeit. Technische Universitaet Berlin, 2007.
56 */
57
58/*---+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0----+----1----+----2*/
59
60#include "string.h"
61#include "scip/sepa_zerohalf.h"
62#include "scip/cutsel_hybrid.h"
64
65#include "gcg/gcg.h"
66
67/* SCIPcalcRowIntegralScalar parameters */
68#define MAXDNOM 1000LL
69#define MAXSCALE 1000.0
70
71/* other defines */
72#define MAXREDUCTIONROUNDS 100 /**< maximum number of rounds to perform reductions on the mod 2 system */
73#define BOUNDSWITCH 0.5 /**< threshold for bound switching */
74#define MAXAGGRLEN(nvars) ((int)(0.1*(nvars)+1000))
75
76typedef struct Mod2Col MOD2_COL;
77typedef struct Mod2Row MOD2_ROW;
78typedef struct Mod2Matrix MOD2_MATRIX;
79typedef struct TransIntRow TRANSINTROW;
80
81
82/** enum for different types of row indices in ROWINDEX structure */
83
84#define ROWIND_TYPE unsigned int
85#define ORIG_RHS 0u
86#define ORIG_LHS 1u
87#define TRANSROW 2u
88
89/* macro to get a unique index from the rowindex */
90#define UNIQUE_INDEX(rowind) (3*(rowind).index + (rowind).type)
91
92
93
94/** structure containing a transformed integral row obtained by relaxing an lp row */
95struct TransIntRow
96{
97 SCIP_Real slack; /**< slack of row after transformation */
98 SCIP_Real rhs; /**< right hand side value of integral row after transformation */
99 SCIP_Real* vals; /**< values of row */
100 int* varinds; /**< problem variable indices of row */
101 int size; /**< alloc size of row */
102 int len; /**< length of row */
103 int rank; /**< rank of row */
104 SCIP_Bool local; /**< is row local? */
105};
106
107/** structure representing a row in the mod 2 system */
108struct Mod2Row
109{
110 ROWINDEX* rowinds; /**< index set of rows associated with the mod 2 row */
111 MOD2_COL** nonzcols; /**< sorted array of non-zero mod 2 columns in this mod 2 row */
112 SCIP_Real slack; /**< slack of mod 2 row */
113 SCIP_Real maxsolval; /**< maximum solution value of columns in mod 2 row */
114 int index; /**< unique index of mod 2 row */
115 int pos; /**< position of mod 2 row in mod 2 matrix rows array */
116 int rhs; /**< rhs of row */
117 int nrowinds; /**< number of elements in rowinds */
118 int rowindssize; /**< size of rowinds array */
119 int nnonzcols; /**< number of columns in nonzcols */
120 int nonzcolssize; /**< size of nonzcols array */
121};
122
123/** structure representing a column in the mod 2 system */
124struct Mod2Col
125{
126 SCIP_HASHSET* nonzrows; /**< the set of rows that contain this column */
127 SCIP_Real solval; /**< solution value of the column */
128 int pos; /**< position of column in matrix */
129 int index; /**< index of SCIP column associated to this column */
130};
131
132/** matrix representing the modulo 2 system */
133struct Mod2Matrix
134{
135 MOD2_COL** cols; /**< columns of the matrix */
136 MOD2_ROW** rows; /**< rows of the matrix */
137 TRANSINTROW* transintrows; /**< transformed integral rows obtained from non-integral lp rows */
138 int ntransintrows; /**< number of transformed integral rows obtained from non-integral lp rows */
139 int nzeroslackrows; /**< number of rows with zero slack */
140 int nrows; /**< number of rows of the matrix; number of elements in rows */
141 int ncols; /**< number of cols of the matrix; number of elements in cols */
142 int rowssize; /**< length of rows array */
143 int colssize; /**< length of cols array */
144};
145
146
147/** data of separator */
148
149//typedef struct GCG_ZeroHalfData GCG_ZEROHALFDATA;
150
151
152
153/** create an instance of cut indices */
155 SCIP* scip, /**< SCIP data structure (master problem) */
156 GCG_CUTINDICES** cutindices, /**< pointer to store cutindices */
157 int nindices, /**< number of indices */
158 ROWINDEX* rowindex /**< indices */
159)
160{
161 int i;
162
163 assert(scip != NULL);
164 assert(nindices > 0);
165 assert(cutindices != NULL);
166
167 SCIP_CALL( SCIPallocBuffer(scip, cutindices) );
168 (*cutindices)->nindices = nindices;
169 (*cutindices)->indices = NULL;
170
171 SCIP_CALL( SCIPallocBufferArray(scip, &((*cutindices)->indices), nindices) );
172 for( i = 0; i < nindices; i++ )
173 {
174 (*cutindices)->indices[i] = rowindex[i].index;
175 }
176
177 return SCIP_OKAY;
178}
179
180/** create an instance of cut indices */
182 SCIP* scip, /**< SCIP data structure (master problem) */
183 GCG_CUTINDICES** cutindices, /**< pointer to store cutindices */
184 int nindices, /**< number of indices */
185 int* indices /**< indices */
186)
187{
188 assert(scip != NULL);
189 assert(nindices > 0);
190 assert(cutindices != NULL);
191
192 SCIP_CALL( SCIPallocBuffer(scip, cutindices) );
193 (*cutindices)->nindices = nindices;
194 (*cutindices)->indices = indices;
195
196 return SCIP_OKAY;
197}
198
199/** free an instance of cut indices */
201 SCIP* scip, /**< SCIP data structure (master problem) */
202 GCG_CUTINDICES** cutindices /**< pointer to cutindices */
203)
204{
205 assert(scip != NULL);
206 assert(cutindices != NULL);
207 assert(*cutindices != NULL);
208
209 if( (*cutindices)->nindices > 0 )
210 {
211 SCIPfreeBufferArray(scip, &((*cutindices)->indices));
212 }
213
214 assert((*cutindices)->indices == NULL);
215
216 SCIPfreeBuffer(scip, cutindices);
217 *cutindices = NULL;
218
219 return SCIP_OKAY;
220}
221
222
223#define COLINFO_GET_MOD2COL(x) ((MOD2_COL*) (((uintptr_t)(x)) & ~((uintptr_t)1)))
224#define COLINFO_GET_RHSOFFSET(x) ((int) (((uintptr_t)(x)) & ((uintptr_t)1)))
225#define COLINFO_CREATE(mod2col, rhsoffset) ((void*) (((uintptr_t)(mod2col)) | ((uintptr_t)(rhsoffset))))
226
227
228#ifndef NDEBUG
229static
231{
232 int i;
233 SCIP_Real maxsolval = 0.0;
234
235 for( i = 0; i < row->nnonzcols; ++i )
236 {
237 assert(row->nonzcols[i]->solval > 0.0);
238 maxsolval = MAX(maxsolval, row->nonzcols[i]->solval);
239
240 if( i + 1 < row->nnonzcols )
241 assert(row->nonzcols[i]->index < row->nonzcols[i+1]->index);
242 }
243
244 assert(row->maxsolval == maxsolval); /*lint !e777*/
245}
246#else
247#define checkRow(x)
248#endif
249
250/** compare to mod 2 columns by there index */
251static
252SCIP_DECL_SORTPTRCOMP(compareColIndex)
253{
254 MOD2_COL* col1;
255 MOD2_COL* col2;
256
257 col1 = (MOD2_COL*) elem1;
258 col2 = (MOD2_COL*) elem2;
259
260 if( col1->index < col2->index )
261 return -1;
262 if( col2->index < col1->index )
263 return 1;
264
265 return 0;
266}
267
268/** comparison function for slack of mod 2 rows */
269static
270SCIP_DECL_SORTPTRCOMP(compareRowSlack)
271{
272 MOD2_ROW* row1;
273 MOD2_ROW* row2;
274 SCIP_Bool slack1iszero;
275 SCIP_Bool slack2iszero;
276
277 row1 = (MOD2_ROW*) elem1;
278 row2 = (MOD2_ROW*) elem2;
279
280 slack1iszero = EPSZ(row1->slack, SCIP_DEFAULT_EPSILON);
281 slack2iszero = EPSZ(row2->slack, SCIP_DEFAULT_EPSILON);
282
283 /* zero slack comes first */
284 if( slack1iszero && !slack2iszero )
285 return -1;
286 if( slack2iszero && !slack1iszero )
287 return 1;
288 if( !slack1iszero && !slack2iszero )
289 return 0;
290
291 /* prefer rows that contain columns with large solution value */
292 if( row1->maxsolval > row2->maxsolval )
293 return -1;
294 if( row2->maxsolval > row1->maxsolval )
295 return 1;
296
297 /* rows with less non-zeros come first rows */
298 if( row1->nnonzcols < row2->nnonzcols )
299 return -1;
300 if( row2->nnonzcols < row1->nnonzcols )
301 return 1;
302
303 return 0;
304}
305
306/** take integral real value modulo 2 */
307static
309 SCIP* scip, /**< scip data structure */
310 SCIP_Real val /**< value to take mod 2 */
311)
312{
314 val *= 0.5;
315 return (REALABS(SCIPround(scip, val) - val) > 0.1) ? 1 : 0;
316}
317
318/** returns the integral value for the given scaling parameters, see SCIPcalcIntegralScalar() */
319static
321 SCIP_Real val, /**< value that should be scaled to an integral value */
322 SCIP_Real scalar, /**< scalar that should be tried */
323 SCIP_Real mindelta, /**< minimal relative allowed difference of scaled coefficient s*c and integral i */
324 SCIP_Real maxdelta, /**< maximal relative allowed difference of scaled coefficient s*c and integral i */
325 SCIP_Real* sval, /**< pointer to store the scaled value */
326 SCIP_Real* intval /**< pointer to store the scaled integral value */
327)
328{
329 SCIP_Real upviol;
330 SCIP_Real downviol;
331 SCIP_Real downval;
332 SCIP_Real upval;
333
334 assert(mindelta <= 0.0);
335 assert(maxdelta >= 0.0);
336
337 *sval = val * scalar;
338 downval = floor(*sval);
339 upval = ceil(*sval);
340
341 downviol = SCIPrelDiff(*sval, downval) - maxdelta;
342 upviol = mindelta - SCIPrelDiff(*sval, upval);
343
344 if( downviol < upviol )
345 *intval = downval;
346 else
347 *intval = upval;
348}
349
350/** Tries to transform a non-integral row into an integral row that can be used in zerohalf separation */
351static
353 SCIP* scip, /**< scip data structure */
354 SCIP_SOL* sol, /**< solution to separate, or NULL for LP solution */
355 SCIP_Bool allowlocal, /**< should local cuts be allowed */
356 SCIP_Real maxslack, /**< maximum slack allowed for transformed row */
357 int sign, /**< +1 or -1 scale to select the side of the row */
358 SCIP_Bool local, /**< is the row only valid locally? */
359 int rank, /**< rank of row */
360 int rowlen, /**< length of row */
361 SCIP_Real* rowvals, /**< coefficients of columns in row */
362 SCIP_COL** rowcols, /**< columns of row */
363 SCIP_Real rhs, /**< right hand side of row */
364 int* intvarpos, /**< clean buffer array of size SCIPgetNVars that will be clean when the function returns */
365 TRANSINTROW* introw, /**< pointer to return transformed row */
366 SCIP_Bool* success /**< pointer to return whether the transformation succeeded */
367)
368{
369 int i;
370 int transrowlen;
371 SCIP_Real transrowrhs;
372 int* transrowvars;
373 SCIP_Real* transrowvals;
374
375 assert(scip != NULL);
376 assert(sign == +1 || sign == -1);
377 assert(rowvals != NULL || rowlen == 0);
378 assert(rowcols != NULL || rowlen == 0);
379 assert(intvarpos != NULL);
380 assert(introw != NULL);
381 assert(success != NULL);
382
383 SCIP_CALL( SCIPallocBlockMemoryArray(scip, &transrowvars, rowlen) );
384 SCIP_CALL( SCIPallocBlockMemoryArray(scip, &transrowvals, rowlen) );
385 transrowlen = 0;
386 transrowrhs = rhs;
387
388 /* first add all integral variables to the transformed row and remember their positions in the row */
389 for( i = 0; i < rowlen; ++i )
390 {
391 int probindex;
392
393 if( !SCIPcolIsIntegral(rowcols[i]) ) /*lint !e613*/
394 continue;
395
396 probindex = SCIPcolGetVarProbindex(rowcols[i]);
397 transrowvars[transrowlen] = probindex;
398 transrowvals[transrowlen] = sign * rowvals[i];
399 intvarpos[probindex] = ++transrowlen;
400 }
401
402 /* now loop over the non-integral columns of the row and project them out using simple or variable bounds */
403 *success = TRUE;
404
405 for( i = 0; i < rowlen; ++i )
406 {
407 int closestvbdind;
408 SCIP_Real closestbound;
409 SCIP_VAR* vbdvar;
410 SCIP_Real vbdcoef;
411 SCIP_Real vbdconst;
412 SCIP_VAR* colvar;
413 SCIP_Real val;
414 SCIP_Real closestvbd;
415 SCIP_Bool localbound;
416
417 if( SCIPcolIsIntegral(rowcols[i]) ) /*lint !e613*/
418 continue;
419
420 localbound = FALSE;
421
422 colvar = SCIPcolGetVar(rowcols[i]); /*lint !e613*/
423
424 val = sign * rowvals[i]; /*lint !e613*/
425
426 /* if the value is positive we need to use a lower bound constraint */
427 if( val > 0.0 )
428 {
429 /* retrieve simple variable bound */
430 closestbound = SCIPvarGetLbGlobal(colvar);
431 if( allowlocal && SCIPisSumGT(scip, SCIPvarGetLbLocal(colvar), closestbound) )
432 {
433 /* only use local bound if it is better thatn the global bound */
434 closestbound = SCIPvarGetLbLocal(colvar);
435 localbound = TRUE;
436 }
437
438 /* retrieve closest variable bound */
439 SCIP_CALL( SCIPgetVarClosestVlb(scip, colvar, NULL, &closestvbd, &closestvbdind) );
440
441 /* if a suitable variable bound exists which is at least as good as a local simple bound
442 * or better than a global simple bound we use it
443 */
444 if( closestvbdind >= 0 && (SCIPisGT(scip, closestvbd, closestbound) || (localbound && SCIPisSumEQ(scip, closestvbd, closestbound))) )
445 {
446 vbdcoef = SCIPvarGetVlbCoefs(colvar)[closestvbdind];
447 vbdvar = SCIPvarGetVlbVars(colvar)[closestvbdind];
448 vbdconst = SCIPvarGetVlbConstants(colvar)[closestvbdind];
449 closestbound = closestvbd;
450 }
451 else
452 {
453 closestvbdind = -1;
454 }
455 }
456 else
457 {
458 /* retrieve simple variable bound */
459 closestbound = SCIPvarGetUbGlobal(colvar);
460 if( allowlocal && SCIPisSumLT(scip, SCIPvarGetUbLocal(colvar), closestbound) )
461 {
462 closestbound = SCIPvarGetUbLocal(colvar);
463 localbound = TRUE;
464 }
465
466 /* retrieve closest variable bound */
467 SCIP_CALL( SCIPgetVarClosestVub(scip, colvar, NULL, &closestvbd, &closestvbdind) );
468
469 /* if a suitable variable bound exists which is at least as good as a local simple bound
470 * or better than a global simple bound we use it
471 */
472 if( closestvbdind >= 0 && (SCIPisLT(scip, closestvbd, closestbound) || (localbound && SCIPisSumEQ(scip, closestvbd, closestbound))) )
473 {
474 vbdcoef = SCIPvarGetVubCoefs(colvar)[closestvbdind];
475 vbdvar = SCIPvarGetVubVars(colvar)[closestvbdind];
476 vbdconst = SCIPvarGetVubConstants(colvar)[closestvbdind];
477 closestbound = closestvbd;
478 }
479 else
480 {
481 closestvbdind = -1;
482 }
483 }
484
485 if( closestvbdind >= 0 )
486 {
487 SCIP_Real coef;
488 int pos;
489
490 coef = val * vbdcoef; /*lint !e644*/
491 transrowrhs -= val * vbdconst; /*lint !e644*/
492
493 pos = intvarpos[SCIPvarGetProbindex(vbdvar)] - 1; /*lint !e644*/
494 if( pos >= 0 )
495 {
496 transrowvals[pos] += coef;
497 }
498 else
499 {
500 transrowvars[transrowlen] = SCIPvarGetProbindex(vbdvar);
501 transrowvals[transrowlen] = coef;
502 intvarpos[SCIPvarGetProbindex(vbdvar)] = ++transrowlen;
503 }
504 }
505 else if( !SCIPisInfinity(scip, REALABS(closestbound)) )
506 {
507 local = local || localbound;
508 transrowrhs -= val * closestbound;
509 }
510 else
511 {
512 *success = FALSE;
513 break;
514 }
515 }
516
517 for( i = 0; i < transrowlen;)
518 {
519 intvarpos[transrowvars[i]] = 0;
520 if( SCIPisZero(scip, transrowvals[i]) )
521 {
522 --transrowlen;
523 transrowvals[i] = transrowvals[transrowlen];
524 transrowvars[i] = transrowvars[transrowlen];
525 }
526 else
527 ++i;
528 }
529
530 if( transrowlen <= 1 )
531 *success = FALSE;
532
533 if( *success )
534 {
535 SCIP_Real mindelta;
536 SCIP_Real maxdelta;
537 SCIP_Real intscalar;
538 int nchgcoefs;
539
541
542 *success = ! SCIPcutsTightenCoefficients(scip, local, transrowvals, &transrowrhs, transrowvars, &transrowlen, &nchgcoefs);
543
544 mindelta = -SCIPepsilon(scip);
545 maxdelta = SCIPsumepsilon(scip);
546
547 if( *success )
548 {
549 SCIP_CALL( SCIPcalcIntegralScalar(transrowvals, transrowlen, mindelta, maxdelta, MAXDNOM, MAXSCALE, &intscalar, success) );
550
551 if( *success )
552 {
553 SCIP_Real floorrhs;
554 SCIP_Real slack;
555
556 transrowrhs *= intscalar; /*lint !e644*/
557
558 /* slack is initialized to zero since the transrowrhs can still change due to bound usage in the loop below;
559 * the floored right hand side is then added afterwards
560 */
561 slack = 0.0;
562 for( i = 0; i < transrowlen; ++i )
563 {
564 SCIP_Real solval = SCIPgetSolVal(scip, sol, vars[transrowvars[i]]);
565 SCIP_Real intval;
566 SCIP_Real newval;
567
568 getIntegralScalar(transrowvals[i], intscalar, mindelta, maxdelta, &newval, &intval);
569
570 if( !SCIPisEQ(scip, intval, newval) )
571 {
572 if( intval < newval )
573 {
574 SCIP_Real lb = local ? SCIPvarGetLbLocal(vars[transrowvars[i]]) : SCIPvarGetLbGlobal(vars[transrowvars[i]]);
575
576 if( SCIPisInfinity(scip, -lb) )
577 {
578 *success = FALSE;
579 break;
580 }
581
582 transrowrhs += (intval - newval) * lb;
583 }
584 else
585 {
586 SCIP_Real ub = local ? SCIPvarGetUbLocal(vars[transrowvars[i]]) : SCIPvarGetUbGlobal(vars[transrowvars[i]]);
587
588 if( SCIPisInfinity(scip, ub) )
589 {
590 *success = FALSE;
591 break;
592 }
593
594 transrowrhs += (intval - newval) * ub;
595 }
596 }
597
598 slack -= solval * intval;
599 transrowvals[i] = intval;
600 }
601
602 if( *success )
603 {
604 floorrhs = SCIPfeasFloor(scip, transrowrhs);
605 slack += floorrhs;
606
607 if( slack <= maxslack )
608 {
609 introw->rhs = floorrhs;
610 introw->slack = slack;
611 introw->vals = transrowvals;
612 introw->varinds = transrowvars;
613 introw->len = transrowlen;
614 introw->size = rowlen;
615 introw->local = local;
616 introw->rank = rank;
617
618 if( !SCIPisEQ(scip, floorrhs, transrowrhs) )
619 introw->rank += 1;
620 }
621 else
622 {
623 *success = FALSE;
624 }
625 }
626 }
627 }
628 }
629
630 if( !(*success) )
631 {
632 SCIPfreeBlockMemoryArray(scip, &transrowvals, rowlen);
633 SCIPfreeBlockMemoryArray(scip, &transrowvars, rowlen);
634 }
635
636 return SCIP_OKAY;
637}
638
639
640/** Tries to transform non-integral rows into an integral form by using simple and variable bounds */
641static
643 GCG* gcg, /**< GCG data structure */
644 SCIP_SOL* sol, /**< solution to separate, or NULL for LP solution */
645 GCG_ZEROHALFDATA * zhdata, /**< zerohalf separator data */
646 MOD2_MATRIX* mod2matrix, /**< mod2 matrix structure */
647 SCIP_Bool allowlocal, /**< should local cuts be allowed */
648 SCIP_Real maxslack /**< maximum slack allowed for mod 2 rows */
649 )
650{
651 SCIP* scip;
652 SCIP_ROW** rows;
653 int nrows;
654 int* intvarpos;
655 int i;
656 int maxnonzeros;
657 SCIP_CONS** masterconss;
658
659 /* we only use the rows from the master constraints; Vladi used all */
660 /* OG: SCIP_CALL( SCIPgetLPRowsData(scip, &rows, &nrows) );*/
661
663 masterconss = zhdata->masterconss;
664 nrows = zhdata->nmasterconss;
665
666 SCIP_CALL( SCIPallocBufferArray(scip, &rows, nrows) );
667
668 for( i = 0; i < nrows; i++ )
669 {
670 SCIP_ROW* consrow;
671
672 consrow = SCIPconsGetRow(scip, masterconss[i]);
673 assert(consrow != NULL);
674 rows[i] = consrow;
675 }
676
677 SCIP_CALL( SCIPallocBlockMemoryArray(scip, &mod2matrix->transintrows, 2*nrows) );
678 mod2matrix->ntransintrows = 0;
679
681
682 maxnonzeros = (int)(SCIPgetNLPCols(scip) * zhdata->maxrowdensity) + zhdata->densityoffset;
683
684 for( i = 0; i < nrows; ++i )
685 {
686 int rowlen;
687 SCIP_Real activity;
688 SCIP_Real lhs;
689 SCIP_Real rhs;
690 SCIP_Real lhsslack;
691 SCIP_Real rhsslack;
692 SCIP_Real* rowvals;
693 SCIP_COL** rowcols;
694
695 /* skip integral rows and rows not suitable for generating cuts */
696 /* OG: if( SCIProwIsModifiable(rows[i]) || SCIProwIsIntegral(rows[i]) || (SCIProwIsLocal(rows[i]) && !allowlocal) || SCIProwGetNNonz(rows[i]) > maxnonzeros ) */
697 if( SCIProwIsIntegral(rows[i]) || (SCIProwIsLocal(rows[i]) && !allowlocal) || SCIProwGetNNonz(rows[i]) > maxnonzeros )
698 continue;
699
700 lhs = SCIProwGetLhs(rows[i]) - SCIProwGetConstant(rows[i]);
701 rhs = SCIProwGetRhs(rows[i]) - SCIProwGetConstant(rows[i]);
702 activity = SCIPgetRowSolActivity(scip, rows[i], sol) - SCIProwGetConstant(rows[i]);
703
704 /* compute lhsslack: activity - lhs */
705 if( SCIPisInfinity(scip, -SCIProwGetLhs(rows[i])) )
706 lhsslack = SCIPinfinity(scip);
707 else
708 {
709 lhsslack = activity - lhs;
710 }
711
712 /* compute rhsslack: rhs - activity */
713 if( SCIPisInfinity(scip, SCIProwGetRhs(rows[i])) )
714 rhsslack = SCIPinfinity(scip);
715 else
716 rhsslack = rhs - activity;
717
718 if( rhsslack > maxslack && lhsslack > maxslack )
719 continue;
720
721 rowlen = SCIProwGetNLPNonz(rows[i]);
722 rowvals = SCIProwGetVals(rows[i]);
723 rowcols = SCIProwGetCols(rows[i]);
724
725 if( rhsslack <= maxslack )
726 {
728 TRANSINTROW* introw = &mod2matrix->transintrows[mod2matrix->ntransintrows];
729 SCIP_CALL( transformNonIntegralRow(scip, sol, allowlocal, maxslack, 1, SCIProwIsLocal(rows[i]), SCIProwGetRank(rows[i]), \
730 rowlen, rowvals, rowcols, rhs, intvarpos, introw, &success) );
731
732 assert(success == 1 || success == 0);
733 mod2matrix->ntransintrows += (int)success;
734 }
735
736 if( lhsslack <= maxslack )
737 {
739 TRANSINTROW* introw = &mod2matrix->transintrows[mod2matrix->ntransintrows];
740 SCIP_CALL( transformNonIntegralRow(scip, sol, allowlocal, maxslack, -1, SCIProwIsLocal(rows[i]), SCIProwGetRank(rows[i]), \
741 rowlen, rowvals, rowcols, -lhs, intvarpos, introw, &success) );
742
743 assert(success == 1 || success == 0);
744 mod2matrix->ntransintrows += (int)success;
745 }
746 }
747
748 SCIPfreeCleanBufferArray(scip, &intvarpos);
750
751 return SCIP_OKAY;
752}
753
754
755/** adds new column to the mod 2 matrix */
756static
758 SCIP* scip, /**< SCIP datastructure */
759 MOD2_MATRIX* mod2matrix, /**< mod 2 matrix */
760 SCIP_HASHMAP* origvar2col, /**< hash map for mapping of problem variables to mod 2 columns */
761 SCIP_VAR* origvar, /**< problem variable to create mod 2 column for */
762 SCIP_Real solval, /**< solution value of problem variable */
763 int rhsoffset /**< offset in right hand side due complementation (mod 2) */
764)
765{
766 MOD2_COL* col;
767
768 /* allocate memory */
770
771 /* initialize fields */
772 col->pos = mod2matrix->ncols++;
773 col->index = SCIPvarGetProbindex(origvar);
774 col->solval = solval;
776
777 /* add column to mod 2 matrix */
778 SCIP_CALL( SCIPensureBlockMemoryArray(scip, &mod2matrix->cols, &mod2matrix->colssize, mod2matrix->ncols) );
779 mod2matrix->cols[col->pos] = col;
780
781 /* create mapping of problem variable to mod 2 column with its right hand side offset */
782 assert(rhsoffset >= 0);
783 SCIP_CALL( SCIPhashmapInsert(origvar2col, (void*) origvar, COLINFO_CREATE(col, rhsoffset)) ); /*lint !e571*/
784
785 return SCIP_OKAY;
786}
787
788/** links row to mod 2 column */
789static
791 BMS_BLKMEM* blkmem, /**< block memory shell */
792 MOD2_COL* col, /**< mod 2 column */
793 MOD2_ROW* row /**< mod 2 row */
794)
795{
796 SCIP_CALL( SCIPhashsetInsert(col->nonzrows, blkmem, (void*)row) );
797
798 assert(SCIPhashsetExists(col->nonzrows, (void*)row));
799
800 row->maxsolval = MAX(col->solval, row->maxsolval);
801
802 return SCIP_OKAY;
803}
804
805/** unlinks row from mod 2 column */
806static
808 MOD2_COL* col, /**< mod 2 column */
809 MOD2_ROW* row /**< mod 2 row */
810)
811{
812 SCIP_CALL( SCIPhashsetRemove(col->nonzrows, (void*)row) );
813
814 assert(!SCIPhashsetExists(col->nonzrows, (void*)row));
815#ifndef NDEBUG
816 {
817 int nslots = SCIPhashsetGetNSlots(col->nonzrows);
819 int i;
820
821 for( i = 0; i < nslots; ++i )
822 {
823 assert(rows[i] != row);
824 }
825 }
826#endif
827
828 return SCIP_OKAY;
829}
830
831/** unlinks row from mod 2 column */
832static
834 MOD2_ROW* row /**< mod 2 row */,
835 MOD2_COL* col /**< mod 2 column */
836)
837{
838 int i;
839
840 assert(row->nnonzcols == 0 || row->nonzcols != NULL);
841
842 SCIP_UNUSED( SCIPsortedvecFindPtr((void**) row->nonzcols, compareColIndex, col, row->nnonzcols, &i) );
843 assert(row->nonzcols[i] == col);
844
845 --row->nnonzcols;
846 BMSmoveMemoryArray(row->nonzcols + i, row->nonzcols + i + 1, row->nnonzcols - i); /*lint !e866*/
847
848 if( col->solval >= row->maxsolval )
849 {
850 row->maxsolval = 0.0;
851 for( i = 0; i < row->nnonzcols; ++i )
852 {
853 row->maxsolval = MAX(row->nonzcols[i]->solval, row->maxsolval);
854 }
855 }
856}
857
858/** adds a SCIP_ROW to the mod 2 matrix */
859static
861 SCIP* scip, /**< scip data structure */
862 BMS_BLKMEM* blkmem, /**< block memory shell */
863 MOD2_MATRIX* mod2matrix, /**< modulo 2 matrix */
864 SCIP_HASHMAP* origcol2col, /**< hashmap to retrieve the mod 2 column from a SCIP_COL */
865 SCIP_ROW* origrow, /**< original SCIP row */
866 SCIP_Real slack, /**< slack of row */
867 ROWIND_TYPE side, /**< side of row that is used for mod 2 row, must be ORIG_RHS or ORIG_LHS */
868 int rhsmod2 /**< modulo 2 value of the row's right hand side */
869)
870{
871 SCIP_Real* rowvals;
872 SCIP_COL** rowcols;
873 int rowlen;
874 int i;
875 MOD2_ROW* row;
876
877 SCIP_ALLOC( BMSallocBlockMemory(blkmem, &row) );
878
879 row->index = mod2matrix->nrows++;
880 SCIP_CALL( SCIPensureBlockMemoryArray(scip, &mod2matrix->rows, &mod2matrix->rowssize, mod2matrix->nrows) );
881 mod2matrix->rows[row->index] = row;
882
883 row->slack = MAX(0.0, slack);
884 row->maxsolval = 0.0;
885 row->rhs = rhsmod2;
886 row->nrowinds = 1;
887 row->rowinds = NULL;
888 row->rowindssize = 0;
889
890 if( SCIPisZero(scip, row->slack) )
891 ++mod2matrix->nzeroslackrows;
892
894 row->rowinds[0].type = side;
895 row->rowinds[0].index = (unsigned int)SCIProwGetLPPos(origrow);
896
897 row->nnonzcols = 0;
898 row->nonzcolssize = 0;
899 row->nonzcols = NULL;
900
901 rowlen = SCIProwGetNNonz(origrow);
902 rowvals = SCIProwGetVals(origrow);
903 rowcols = SCIProwGetCols(origrow);
904
905 for( i = 0; i < rowlen; ++i )
906 {
907 if( mod2(scip, rowvals[i]) == 1 )
908 {
909 void* colinfo;
910 MOD2_COL* col;
911 int rhsoffset;
912
913 colinfo = SCIPhashmapGetImage(origcol2col, (void*)SCIPcolGetVar(rowcols[i]));
914
915 /* extract the righthand side offset from the colinfo and update the righthand side */
916 rhsoffset = COLINFO_GET_RHSOFFSET(colinfo);
917 row->rhs = (row->rhs + rhsoffset) % 2;
918
919 /* extract the column pointer from the colinfo */
920 col = COLINFO_GET_MOD2COL(colinfo);
921
922 if( col != NULL )
923 {
924 int k;
925
926 k = row->nnonzcols++;
927
929 row->nonzcols[k] = col;
930
931 SCIP_CALL( mod2colLinkRow(blkmem, col, row) );
932 }
933 }
934 }
935
936 SCIPsortPtr((void**)row->nonzcols, compareColIndex, row->nnonzcols);
937
938 checkRow(row);
939
940 return SCIP_OKAY;
941}
942
943/** adds a transformed integral row to the mod 2 matrix */
944static
946 SCIP* scip, /**< scip data structure */
947 MOD2_MATRIX* mod2matrix, /**< modulo 2 matrix */
948 SCIP_HASHMAP* origcol2col, /**< hashmap to retrieve the mod 2 column from a SCIP_COL */
949 int transrowind /**< index to transformed int row */
950)
951{
952 int i;
953 SCIP_VAR** vars;
954 BMS_BLKMEM* blkmem;
955 MOD2_ROW* row;
956 TRANSINTROW* introw;
957
959
961 introw = &mod2matrix->transintrows[transrowind];
962
963 blkmem = SCIPblkmem(scip);
964 row->index = mod2matrix->nrows++;
965 SCIP_CALL( SCIPensureBlockMemoryArray(scip, &mod2matrix->rows, &mod2matrix->rowssize, mod2matrix->nrows) );
966 mod2matrix->rows[row->index] = row;
967
968 row->slack = MAX(0.0, introw->slack);
969 row->rhs = mod2(scip, introw->rhs);
970 row->nrowinds = 1;
971 row->rowinds = NULL;
972 row->rowindssize = 0;
973 row->maxsolval = 0.0;
974
975 if( SCIPisZero(scip, row->slack) )
976 ++mod2matrix->nzeroslackrows;
977
979 row->rowinds[0].type = TRANSROW;
980 row->rowinds[0].index = (unsigned int)transrowind;
981
982 row->nnonzcols = 0;
983 row->nonzcolssize = 0;
984 row->nonzcols = NULL;
985
986 for( i = 0; i < introw->len; ++i )
987 {
988 if( mod2(scip, introw->vals[i]) == 1 )
989 {
990 void* colinfo;
991 MOD2_COL* col;
992 int rhsoffset;
993
994 colinfo = SCIPhashmapGetImage(origcol2col, (void*)vars[introw->varinds[i]]);
995
996 /* extract the righthand side offset from the colinfo and update the righthand side */
997 rhsoffset = COLINFO_GET_RHSOFFSET(colinfo);
998 row->rhs = (row->rhs + rhsoffset) % 2;
999
1000 /* extract the column pointer from the colinfo */
1001 col = COLINFO_GET_MOD2COL(colinfo);
1002
1003 if( col != NULL )
1004 {
1005 int k;
1006
1007 k = row->nnonzcols++;
1008
1010 row->nonzcols[k] = col;
1011
1012 SCIP_CALL( mod2colLinkRow(blkmem, col, row) );
1013 }
1014 }
1015 }
1016
1017 SCIPsortPtr((void**)row->nonzcols, compareColIndex, row->nnonzcols);
1018
1019 checkRow(row);
1020
1021 return SCIP_OKAY;
1022}
1023
1024/** free all resources held by the mod 2 matrix */
1025static
1027 GCG* gcg, /**< GCG data structure */
1028 MOD2_MATRIX* mod2matrix /**< pointer to mod2 matrix structure */
1029)
1030{
1031 SCIP* scip;
1032 int i;
1033
1035
1036 for( i = 0; i < mod2matrix->ncols; ++i )
1037 {
1038 SCIPhashsetFree(&mod2matrix->cols[i]->nonzrows, SCIPblkmem(scip));
1039 SCIPfreeBlockMemory(scip, &mod2matrix->cols[i]); /*lint !e866*/
1040 }
1041
1042 for( i = 0; i < mod2matrix->nrows; ++i )
1043 {
1044 SCIPfreeBlockMemoryArrayNull(scip, &mod2matrix->rows[i]->nonzcols, mod2matrix->rows[i]->nonzcolssize);
1045 SCIPfreeBlockMemoryArrayNull(scip, &mod2matrix->rows[i]->rowinds, mod2matrix->rows[i]->rowindssize);
1046 SCIPfreeBlockMemory(scip, &mod2matrix->rows[i]); /*lint !e866*/
1047 }
1048
1049 for( i = 0; i < mod2matrix->ntransintrows; ++i )
1050 {
1051 SCIPfreeBlockMemoryArray(scip, &mod2matrix->transintrows[i].vals, mod2matrix->transintrows[i].size);
1052 SCIPfreeBlockMemoryArray(scip, &mod2matrix->transintrows[i].varinds, mod2matrix->transintrows[i].size);
1053 }
1054
1055 SCIPfreeBlockMemoryArray(scip, &mod2matrix->transintrows, 2* GCGgetNMasterConss(gcg)); /*lint !e647*/
1056
1057 SCIPfreeBlockMemoryArrayNull(scip, &mod2matrix->rows, mod2matrix->rowssize);
1058 SCIPfreeBlockMemoryArrayNull(scip, &mod2matrix->cols, mod2matrix->colssize);
1059}
1060
1061/** build the modulo 2 matrix from all integral rows in the LP, and non-integral rows
1062 * if the transformation to an integral row succeeds
1063 */
1064static
1066 GCG* gcg, /**< GCG data structure */
1067 SCIP_SOL* sol, /**< solution to separate, or NULL for LP solution */
1068 GCG_ZEROHALFDATA* zhdata, /**< zerohalf separator data */
1069 BMS_BLKMEM* blkmem, /**< block memory shell */
1070 MOD2_MATRIX* mod2matrix, /**< mod 2 matrix */
1071 SCIP_Bool allowlocal, /**< should local cuts be allowed */
1072 SCIP_Real maxslack /**< maximum slack allowed for mod 2 rows */
1073 )
1074{
1075 SCIP* scip;
1076 SCIP_VAR** vars;
1077 SCIP_ROW** rows;
1078 SCIP_COL** cols;
1079 SCIP_HASHMAP* origcol2col;
1080 int ncols;
1081 int nrows;
1082 int nintvars;
1083 int maxnonzeros;
1084 int i;
1085 SCIP_CONS** mastercons;
1086
1088 mastercons = zhdata->masterconss;
1089 nrows = zhdata->nmasterconss;
1090
1091 SCIPallocBufferArray(scip, &rows, nrows);
1092 for( i = 0; i < nrows; i++ )
1093 {
1094 SCIP_ROW* consrow;
1095
1096 consrow = SCIPconsGetRow(scip, mastercons[i]);
1097 assert(consrow != NULL);
1098 rows[i] = consrow;
1099 }
1100
1101 /* OG: SCIP_CALL( SCIPgetLPRowsData(scip, &rows, &nrows) ); */
1102 SCIP_CALL( SCIPgetLPColsData(scip, &cols, &ncols) );
1103
1106
1107 /* initialize fields */
1108 mod2matrix->cols = NULL;
1109 mod2matrix->colssize = 0;
1110 mod2matrix->ncols = 0;
1111 mod2matrix->rows = NULL;
1112 mod2matrix->rowssize = 0;
1113 mod2matrix->nrows = 0;
1114 mod2matrix->nzeroslackrows = 0;
1115
1116 SCIP_CALL( SCIPhashmapCreate(&origcol2col, SCIPblkmem(scip), 1) );
1117
1118 /* add all integral vars if they are not at their bound */
1119 for( i = 0; i < nintvars; ++i )
1120 {
1121 SCIP_Real lb;
1122 SCIP_Real ub;
1123 SCIP_Real lbsol;
1124 SCIP_Real ubsol;
1125 SCIP_Real primsol;
1126 SCIP_Bool useub;
1127
1128 primsol = SCIPgetSolVal(scip, sol, vars[i]);
1129
1130 lb = allowlocal ? SCIPvarGetLbLocal(vars[i]) : SCIPvarGetLbGlobal(vars[i]);
1131 lbsol = MAX(0.0, primsol - lb);
1132 if( SCIPisZero(scip, lbsol) )
1133 {
1134 SCIP_CALL( SCIPhashmapInsert(origcol2col, (void*) vars[i], COLINFO_CREATE(NULL, mod2(scip, lb))) ); /*lint !e571*/
1135 continue;
1136 }
1137
1138 ub = allowlocal ? SCIPvarGetUbLocal(vars[i]) : SCIPvarGetUbGlobal(vars[i]);
1139 ubsol = MAX(0.0, ub - primsol);
1140 if( SCIPisZero(scip, ubsol) )
1141 {
1142 SCIP_CALL( SCIPhashmapInsert(origcol2col, (void*) vars[i], COLINFO_CREATE(NULL, mod2(scip, ub))) ); /*lint !e571*/
1143 continue;
1144 }
1145
1146 if( SCIPisInfinity(scip, ub) ) /* if there is no ub, use lb */
1147 useub = FALSE;
1148 else if( SCIPisInfinity(scip, -lb) ) /* if there is no lb, use ub */
1149 useub = TRUE;
1150 else if( SCIPisLT(scip, primsol, (1.0 - BOUNDSWITCH) * lb + BOUNDSWITCH * ub) )
1151 useub = FALSE;
1152 else
1153 useub = TRUE;
1154
1155 if( useub )
1156 {
1157 assert(ubsol > 0.0);
1158
1159 /* coverity[var_deref_model] */
1160 SCIP_CALL( mod2MatrixAddCol(scip, mod2matrix, origcol2col, vars[i], ubsol, mod2(scip, ub)) );
1161 }
1162 else
1163 {
1164 assert(lbsol > 0.0);
1165
1166 /* coverity[var_deref_model] */
1167 SCIP_CALL( mod2MatrixAddCol(scip, mod2matrix, origcol2col, vars[i], lbsol, mod2(scip, lb)) );
1168 }
1169 }
1170
1171 maxnonzeros = (int)(SCIPgetNLPCols(scip) * zhdata->maxrowdensity) + zhdata->densityoffset;
1172
1173 /* add all integral rows using the created columns */
1174 for( i = 0; i < nrows; ++i )
1175 {
1176 SCIP_Real lhs;
1177 SCIP_Real rhs;
1178 SCIP_Real activity;
1179 SCIP_Real lhsslack;
1180 SCIP_Real rhsslack;
1181 int lhsmod2;
1182 int rhsmod2;
1183
1184 /* skip non-integral rows and rows not suitable for generating cuts */
1185 /* OG: if( SCIProwIsModifiable(rows[i]) || !SCIProwIsIntegral(rows[i]) || (SCIProwIsLocal(rows[i]) && !allowlocal) || SCIProwGetNNonz(rows[i]) > maxnonzeros )*/
1186 if( !SCIProwIsIntegral(rows[i]) || (SCIProwIsLocal(rows[i]) && !allowlocal) || SCIProwGetNNonz(rows[i]) > maxnonzeros )
1187 continue;
1188
1189 lhsmod2 = 0;
1190 rhsmod2 = 0;
1191 activity = SCIPgetRowSolActivity(scip, rows[i], sol) - SCIProwGetConstant(rows[i]);
1192
1193 /* since row is integral we can ceil/floor the lhs/rhs after subtracting the constant */
1194 lhs = SCIPfeasCeil(scip, SCIProwGetLhs(rows[i]) - SCIProwGetConstant(rows[i]));
1195 rhs = SCIPfeasFloor(scip, SCIProwGetRhs(rows[i]) - SCIProwGetConstant(rows[i]));
1196
1197 /* compute lhsslack: activity - lhs */
1198 if( SCIPisInfinity(scip, -SCIProwGetLhs(rows[i])) )
1199 lhsslack = SCIPinfinity(scip);
1200 else
1201 {
1202 lhsslack = activity - lhs;
1203 lhsmod2 = mod2(scip, lhs);
1204 }
1205
1206 /* compute rhsslack: rhs - activity */
1207 if( SCIPisInfinity(scip, SCIProwGetRhs(rows[i])) )
1208 rhsslack = SCIPinfinity(scip);
1209 else
1210 {
1211 rhsslack = rhs - activity;
1212 rhsmod2 = mod2(scip, rhs);
1213 }
1214
1215 if( rhsslack <= maxslack && lhsslack <= maxslack )
1216 {
1217 if( lhsmod2 == rhsmod2 )
1218 {
1219 /* maxslack < 1 implies rhs - lhs = rhsslack + lhsslack < 2. Therefore lhs = rhs (mod2) can only hold if they
1220 * are equal
1221 */
1222 assert(SCIPisEQ(scip, lhs, rhs));
1223
1224 /* use rhs */
1225 /* coverity[var_deref_model] */
1226 SCIP_CALL( mod2MatrixAddOrigRow(scip, blkmem, mod2matrix, origcol2col, rows[i], rhsslack, ORIG_RHS, rhsmod2) );
1227 }
1228 else
1229 {
1230 /* use both */
1231 /* coverity[var_deref_model] */
1232 SCIP_CALL( mod2MatrixAddOrigRow(scip, blkmem, mod2matrix, origcol2col, rows[i], lhsslack, ORIG_LHS, lhsmod2) );
1233 SCIP_CALL( mod2MatrixAddOrigRow(scip, blkmem, mod2matrix, origcol2col, rows[i], rhsslack, ORIG_RHS, rhsmod2) );
1234 }
1235 }
1236 else if( rhsslack <= maxslack )
1237 {
1238 /* use rhs */
1239 /* coverity[var_deref_model] */
1240 SCIP_CALL( mod2MatrixAddOrigRow(scip, blkmem, mod2matrix, origcol2col, rows[i], rhsslack, ORIG_RHS, rhsmod2) );
1241 }
1242 else if( lhsslack <= maxslack )
1243 {
1244 /* use lhs */
1245 /* coverity[var_deref_model] */
1246 SCIP_CALL( mod2MatrixAddOrigRow(scip, blkmem, mod2matrix, origcol2col, rows[i], lhsslack, ORIG_LHS, lhsmod2) );
1247 }
1248 }
1249
1250 /* transform non-integral rows */
1251 SCIP_CALL( mod2MatrixTransformContRows(gcg, sol, zhdata, mod2matrix, allowlocal, maxslack) );
1252
1253 /* add all transformed integral rows using the created columns */
1254 for( i = 0; i < mod2matrix->ntransintrows; ++i )
1255 {
1256 SCIP_CALL( mod2MatrixAddTransRow(scip, mod2matrix, origcol2col, i) );
1257 }
1258
1259 SCIPhashmapFree(&origcol2col);
1260 SCIPfreeBufferArray(scip, &rows);
1261
1262 return SCIP_OKAY;
1263}
1264
1265/* compare two mod 2 columns for equality */
1266static
1268{ /*lint --e{715}*/
1269 MOD2_COL* col1;
1270 MOD2_COL* col2;
1271 int nslotscol1;
1272 MOD2_ROW** col1rows;
1273 int i;
1274
1275 col1 = (MOD2_COL*) key1;
1276 col2 = (MOD2_COL*) key2;
1277
1279 return FALSE;
1280
1281 nslotscol1 = SCIPhashsetGetNSlots(col1->nonzrows);
1282 col1rows = (MOD2_ROW**) SCIPhashsetGetSlots(col1->nonzrows);
1283 for( i = 0; i < nslotscol1; ++i )
1284 {
1285 if( col1rows[i] != NULL && !SCIPhashsetExists(col2->nonzrows, (void*)col1rows[i]) )
1286 return FALSE;
1287 }
1288
1289 return TRUE;
1290}
1291
1292/* compute a signature of the rows in a mod 2 matrix as hash value */
1293static
1294SCIP_DECL_HASHKEYVAL(columnGetSignature)
1295{ /*lint --e{715}*/
1296 MOD2_COL* col;
1297 MOD2_ROW** rows;
1298 uint64_t signature;
1299 int i;
1300 int nslots;
1301
1302 col = (MOD2_COL*) key;
1303
1304 nslots = SCIPhashsetGetNSlots(col->nonzrows);
1305 rows = (MOD2_ROW**) SCIPhashsetGetSlots(col->nonzrows);
1306
1307 signature = 0;
1308 for( i = 0; i < nslots; ++i )
1309 {
1310 if( rows[i] != NULL )
1311 signature |= SCIPhashSignature64(rows[i]->index);
1312 }
1313
1314 return signature;
1315}
1316
1317/* compare two mod 2 rows for equality */
1318static
1320{ /*lint --e{715}*/
1321 MOD2_ROW* row1;
1322 MOD2_ROW* row2;
1323 int i;
1324
1325 row1 = (MOD2_ROW*) key1;
1326 row2 = (MOD2_ROW*) key2;
1327
1328 assert(row1 != NULL);
1329 assert(row2 != NULL);
1330 assert(row1->nnonzcols == 0 || row1->nonzcols != NULL);
1331 assert(row2->nnonzcols == 0 || row2->nonzcols != NULL);
1332
1333 if( row1->nnonzcols != row2->nnonzcols || row1->rhs != row2->rhs )
1334 return FALSE;
1335
1336 for( i = 0; i < row1->nnonzcols; ++i )
1337 {
1338 if( row1->nonzcols[i] != row2->nonzcols[i] )
1339 return FALSE;
1340 }
1341
1342 return TRUE;
1343}
1344
1345/* compute a signature of a mod 2 row as hash value */
1346static
1347SCIP_DECL_HASHKEYVAL(rowGetSignature)
1348{ /*lint --e{715}*/
1349 MOD2_ROW* row;
1350 int i;
1351 uint64_t signature;
1352
1353 row = (MOD2_ROW*) key;
1354 assert(row->nnonzcols == 0 || row->nonzcols != NULL);
1355
1356 signature = row->rhs; /*lint !e732*/
1357
1358 for( i = 0; i < row->nnonzcols; ++i )
1359 signature |= SCIPhashSignature64(row->nonzcols[i]->index);
1360
1361 return signature;
1362}
1363
1364/** removes a row from the mod 2 matrix */
1365static
1367 SCIP* scip, /**< scip data structure */
1368 MOD2_MATRIX* mod2matrix, /**< the mod 2 matrix */
1369 MOD2_ROW* row /**< mod 2 row */
1370)
1371{
1372 int i;
1373 int position = row->pos;
1374
1375 checkRow(row);
1376
1377 /* update counter for zero slack rows */
1378 if( SCIPisZero(scip, row->slack) )
1379 --mod2matrix->nzeroslackrows;
1380
1381 /* remove the row from the array */
1382 --mod2matrix->nrows;
1383 mod2matrix->rows[position] = mod2matrix->rows[mod2matrix->nrows];
1384 mod2matrix->rows[position]->pos = position;
1385
1386 /* unlink columns from row */
1387 for( i = 0; i < row->nnonzcols; ++i )
1388 {
1389 SCIP_CALL( mod2colUnlinkRow(row->nonzcols[i], row) );
1390 }
1391
1392 /* free row */
1396
1397 return SCIP_OKAY;
1398}
1399
1400/** removes a column from the mod 2 matrix */
1401static
1403 SCIP* scip, /**< scip data structure */
1404 MOD2_MATRIX* mod2matrix, /**< the mod 2 matrix */
1405 MOD2_COL* col /**< a column in the mod 2 matrix */
1406)
1407{
1408 int i;
1409 int nslots;
1410 MOD2_ROW** rows;
1411 int position;
1412
1413 assert(col != NULL);
1414
1415 /* cppcheck-suppress nullPointer */
1416 position = col->pos;
1417
1418 /* remove column from arrays */
1419 --mod2matrix->ncols;
1420 mod2matrix->cols[position] = mod2matrix->cols[mod2matrix->ncols];
1421 mod2matrix->cols[position]->pos = position;
1422
1423 /* cppcheck-suppress nullPointer */
1424 nslots = SCIPhashsetGetNSlots(col->nonzrows);
1425 /* cppcheck-suppress nullPointer */
1426 rows = (MOD2_ROW**) SCIPhashsetGetSlots(col->nonzrows);
1427
1428 /* adjust rows of column */
1429 for( i = 0; i < nslots; ++i )
1430 {
1431 if( rows[i] != NULL )
1432 mod2rowUnlinkCol(rows[i], col);
1433 }
1434
1435 /* free column */
1438}
1439
1440/* remove columns that are (Prop3 iii) zero (Prop3 iv) identify indentical columns (Prop3 v) unit vector columns */
1441static
1443 SCIP* scip, /**< scip data structure */
1444 MOD2_MATRIX* mod2matrix, /**< mod 2 matrix */
1445 GCG_ZEROHALFDATA* zhdata
1446)
1447{
1448 int i;
1449 SCIP_HASHTABLE* columntable;
1450
1451 SCIP_CALL( SCIPhashtableCreate(&columntable, SCIPblkmem(scip), mod2matrix->ncols,
1452 SCIPhashGetKeyStandard, columnsEqual, columnGetSignature, NULL) );
1453
1454 for( i = 0; i < mod2matrix->ncols; )
1455 {
1456 MOD2_COL* col = mod2matrix->cols[i];
1457 int nnonzrows = SCIPhashsetGetNElements(col->nonzrows);
1458 if( nnonzrows == 0 )
1459 { /* Prop3 iii */
1460 mod2matrixRemoveCol(scip, mod2matrix, col);
1461 }
1462 else if( nnonzrows == 1 )
1463 { /* Prop3 v */
1464 MOD2_ROW* row;
1465
1466 {
1467 int j = 0;
1468 MOD2_ROW** rows;
1469 rows = (MOD2_ROW**) SCIPhashsetGetSlots(col->nonzrows);
1470 while( rows[j] == NULL )
1471 ++j;
1472
1473 row = rows[j];
1474 }
1475
1476 checkRow(row);
1477
1478 /* column is unit vector, so add its solution value to the rows slack and remove it */
1479 if( SCIPisZero(scip, row->slack) )
1480 --mod2matrix->nzeroslackrows;
1481
1482 row->slack += col->solval;
1483 assert(!SCIPisZero(scip, row->slack));
1484
1485 mod2matrixRemoveCol(scip, mod2matrix, col);
1486 ++zhdata->nreductions;
1487
1488 checkRow(row);
1489 }
1490 else
1491 {
1492 MOD2_COL* identicalcol;
1493 identicalcol = (MOD2_COL*)SCIPhashtableRetrieve(columntable, col);
1494 if( identicalcol != NULL )
1495 {
1496 assert(identicalcol != col);
1497
1498 /* column is identical to other column so add its solution value to the other one and then remove and free it */
1499 identicalcol->solval += col->solval;
1500
1501 /* also adjust the solval of the removed column so that the maxsolval of each row is properly updated */
1502 col->solval = identicalcol->solval;
1503
1504 mod2matrixRemoveCol(scip, mod2matrix, col);
1505 }
1506 else
1507 {
1508 SCIP_CALL( SCIPhashtableInsert(columntable, (void*)col) );
1509 ++i;
1510 }
1511 }
1512 }
1513
1514 SCIPhashtableFree(&columntable);
1515
1516 return SCIP_OKAY;
1517}
1518
1519#define NONZERO(x) (COPYSIGN(1e-100, (x)) + (x))
1520
1521/** computes maximal violation that can be achieved for zerohalf cuts where this row particiaptes */
1522static
1524 MOD2_ROW* row /**< mod 2 row */
1525)
1526{
1527 SCIP_Real viol;
1528
1529 viol = 1.0 - row->slack;
1530 viol *= 0.5;
1531
1532 return viol;
1533}
1534
1535/** remove rows that are (a) zero (b) identical to other rows (keep the one with smallest slack) (c) have slack greater
1536 * than 1 (d) for zero rows with 1 as rhs and slack less than 1, we can directly generate a cut and remove the row (Lemma 4)
1537 */
1538static
1540 SCIP* scip, /**< scip data structure */
1541 SCIP_SOL* sol, /**< solution to separate, or NULL for LP solution */
1542 MOD2_MATRIX* mod2matrix, /**< the mod 2 matrix */
1543 GCG_ZEROHALFDATA* zhdata,
1544 SCIP_Bool allowlocal, /**< should local cuts be allowed */
1545 GCG_CUTINDICES*** cutindices,
1546 int* ncutindices,
1547 int maxcuts
1548)
1549{
1550 int i;
1551 SCIP_HASHTABLE* rowtable;
1552
1553 SCIP_CALL( SCIPhashtableCreate(&rowtable, SCIPblkmem(scip), mod2matrix->nrows,
1554 SCIPhashGetKeyStandard, rowsEqual, rowGetSignature, NULL) );
1555
1556 for( i = 0; i < mod2matrix->nrows; )
1557 {
1558 MOD2_ROW* row = mod2matrix->rows[i];
1559 row->pos = i;
1560
1561 checkRow(row);
1562
1563 assert(row->nnonzcols == 0 || row->nonzcols != NULL);
1564
1565 if( (row->nnonzcols == 0 && row->rhs == 0) || computeMaxViolation(row) < zhdata->minviol )
1566 { /* (a) and (c) */
1567 zhdata->nreductions += row->nnonzcols;
1568 SCIP_CALL( mod2matrixRemoveRow(scip, mod2matrix, row) );
1569 }
1570 else if( row->nnonzcols > 0 )
1571 { /* (b) */
1572 MOD2_ROW* identicalrow;
1573 identicalrow = (MOD2_ROW*)SCIPhashtableRetrieve(rowtable, (void*)row);
1574 if( identicalrow != NULL )
1575 {
1576 assert(identicalrow != row);
1577 assert(identicalrow->nnonzcols == 0 || identicalrow->nonzcols != NULL);
1578
1579 checkRow(identicalrow);
1580
1581 /* row is identical to other row; only keep the one with smaller slack */
1582 if( identicalrow->slack <= row->slack )
1583 {
1584 SCIP_CALL( mod2matrixRemoveRow(scip, mod2matrix, row) );
1585 }
1586 else
1587 {
1588 assert(SCIPhashtableExists(rowtable, (void*)identicalrow));
1589
1590 SCIP_CALL( SCIPhashtableRemove(rowtable, (void*)identicalrow) );
1591 assert(!SCIPhashtableExists(rowtable, (void*)identicalrow));
1592
1593 SCIP_CALL( SCIPhashtableInsert(rowtable, (void*)row) );
1594
1595 SCIPswapPointers((void**) &mod2matrix->rows[row->pos], (void**) &mod2matrix->rows[identicalrow->pos]);
1596 SCIPswapInts(&row->pos, &identicalrow->pos);
1597
1598 assert(mod2matrix->rows[row->pos] == row && mod2matrix->rows[identicalrow->pos] == identicalrow);
1599 assert(identicalrow->pos == i);
1600 assert(row->pos < i);
1601
1602 SCIP_CALL( mod2matrixRemoveRow(scip, mod2matrix, identicalrow) );
1603 }
1604 }
1605 else
1606 {
1607 SCIP_CALL( SCIPhashtableInsert(rowtable, (void*)row) );
1608 ++i;
1609 }
1610 }
1611 else
1612 {
1613 GCG_CUTINDICES* cutindex;
1614 /* (d) */
1615 assert(row->nnonzcols == 0 && row->rhs == 1 && SCIPisLT(scip, row->slack, 1.0));
1616
1617 /* OG: SCIP_CALL( generateZerohalfCut(scip, sol, mod2matrix, sepa, sepadata, allowlocal, row) ); */
1618 // transfer the indices associated with this cut to cutindices
1619 if( *ncutindices < maxcuts )
1620 {
1622 (*cutindices)[*ncutindices] = cutindex;
1623 (*ncutindices)++;
1624 }
1625
1626
1627 if( zhdata->infeasible )
1628 goto TERMINATE;
1629
1630 SCIP_CALL( mod2matrixRemoveRow(scip, mod2matrix, row) );
1631 ++i;
1632 }
1633 }
1634 TERMINATE:
1635 SCIPhashtableFree(&rowtable);
1636
1637 return SCIP_OKAY;
1638}
1639
1640/** add a mod2 row to another one */
1641static
1643 GCG* gcg, /**< GCG data structure */
1644 BMS_BLKMEM* blkmem, /**< block memory shell */
1645 MOD2_MATRIX* mod2matrix, /**< mod 2 matrix */
1646 MOD2_ROW* row, /**< mod 2 row */
1647 MOD2_ROW* rowtoadd /**< mod 2 row that is added to the other mod 2 row */
1648 )
1649{
1650 SCIP* scip;
1651 SCIP_Shortbool* contained;
1652 int i;
1653 int j;
1654 int k;
1655 int nnewentries;
1656 int nlprows;
1657 MOD2_COL** newnonzcols;
1658 SCIP_Real newslack;
1659
1660 checkRow(row);
1661 checkRow(rowtoadd);
1662
1663 assert(row->nnonzcols == 0 || row->nonzcols != NULL);
1664 assert(rowtoadd->nnonzcols == 0 || rowtoadd->nonzcols != NULL);
1665
1667 nlprows = GCGgetNMasterConss(gcg); //SCIPgetNLPRows(scip);
1668 row->rhs ^= rowtoadd->rhs;
1669
1670 newslack = row->slack + rowtoadd->slack;
1671 blkmem = SCIPblkmem(scip);
1672
1673 if( SCIPisZero(scip, row->slack) && !SCIPisZero(scip, newslack) )
1674 --mod2matrix->nzeroslackrows;
1675
1676 row->slack = newslack;
1677
1678 {
1679 /* the maximum index return by the UNIQUE_INDEX macro is 3 times
1680 * the maximum index value in the ROWINDEX struct. The index value could
1681 * be the lp position of an original row or the index of a transformed row.
1682 * Hence we need to allocate 3 times the maximum of these two possible
1683 * index types.
1684 */
1685 int allocsize = 3 * MAX(nlprows, mod2matrix->ntransintrows);
1686 SCIP_CALL( SCIPallocCleanBufferArray(scip, &contained, allocsize) );
1687 }
1688
1689 /* remember entries that are in the row to add */
1690 for( i = 0; i < rowtoadd->nrowinds; ++i )
1691 {
1692 contained[UNIQUE_INDEX(rowtoadd->rowinds[i])] = 1;
1693 }
1694
1695 /* remove the entries that are in both rows from the row (1 + 1 = 0 (mod 2)) */
1696 nnewentries = rowtoadd->nrowinds;
1697 for( i = 0; i < row->nrowinds; )
1698 {
1699 if( contained[UNIQUE_INDEX(row->rowinds[i])] )
1700 {
1701 --nnewentries;
1702 contained[UNIQUE_INDEX(row->rowinds[i])] = 0;
1703 --row->nrowinds;
1704 row->rowinds[i] = row->rowinds[row->nrowinds];
1705 }
1706 else
1707 {
1708 ++i;
1709 }
1710 }
1711
1712 SCIP_CALL( SCIPensureBlockMemoryArray(scip, &row->rowinds, &row->rowindssize, row->nrowinds + nnewentries) );
1713
1714 /* add remaining entries of row to add */
1715 for ( i = 0; i < rowtoadd->nrowinds; ++i )
1716 {
1717 if( contained[UNIQUE_INDEX(rowtoadd->rowinds[i])] )
1718 {
1719 contained[UNIQUE_INDEX(rowtoadd->rowinds[i])] = 0;
1720 row->rowinds[row->nrowinds++] = rowtoadd->rowinds[i];
1721 }
1722 }
1723
1724 SCIPfreeCleanBufferArray(scip, &contained);
1725
1726 SCIP_CALL( SCIPallocBufferArray(scip, &newnonzcols, row->nnonzcols + rowtoadd->nnonzcols) );
1727
1728 i = 0;
1729 j = 0;
1730 k = 0;
1731 row->maxsolval = 0.0;
1732
1733 /* since columns are sorted we can merge them */
1734 while( i < row->nnonzcols && j < rowtoadd->nnonzcols )
1735 {
1736 if( row->nonzcols[i] == rowtoadd->nonzcols[j] )
1737 {
1738 SCIP_CALL( mod2colUnlinkRow(row->nonzcols[i], row) );
1739 ++i;
1740 ++j;
1741 }
1742 else if( row->nonzcols[i]->index < rowtoadd->nonzcols[j]->index )
1743 {
1744 row->maxsolval = MAX(row->maxsolval, row->nonzcols[i]->solval);
1745 newnonzcols[k++] = row->nonzcols[i++];
1746 }
1747 else
1748 {
1749 SCIP_CALL( mod2colLinkRow(blkmem, rowtoadd->nonzcols[j], row) );
1750 newnonzcols[k++] = rowtoadd->nonzcols[j++];
1751 }
1752 }
1753
1754 while( i < row->nnonzcols )
1755 {
1756 row->maxsolval = MAX(row->maxsolval, row->nonzcols[i]->solval);
1757 newnonzcols[k++] = row->nonzcols[i++];
1758 }
1759
1760 while( j < rowtoadd->nnonzcols )
1761 {
1762 SCIP_CALL( mod2colLinkRow(blkmem, rowtoadd->nonzcols[j], row) );
1763 newnonzcols[k++] = rowtoadd->nonzcols[j++];
1764 }
1765
1766 row->nnonzcols = k;
1768 BMScopyMemoryArray(row->nonzcols, newnonzcols, row->nnonzcols);
1769
1770 SCIPfreeBufferArray(scip, &newnonzcols);
1771
1772 assert(row->nnonzcols == 0 || row->nonzcols != NULL);
1773 checkRow(row);
1774 checkRow(rowtoadd);
1775
1776 return SCIP_OKAY;
1777}
1778
1779/* --------------------------------------------------------------------------------------------------------------------
1780 * callback methods of separator
1781 * -------------------------------------------------------------------------------------------------------------------- */
1782
1783// SCIP_CALL( SCIPcreateRandom(scip, &sepadata->randnumgen, (unsigned int)sepadata->initseed, TRUE) );
1784// SCIPfreeRandom(scip, &sepadata->randnumgen);
1785
1786
1787/** perform the zerohalf cut separation */
1789 GCG* gcg,
1790 SCIP_SOL* sol,
1791 SCIP_Bool allowlocal,
1792 int depth, /* current depth */
1793 GCG_ZEROHALFDATA* zhdata,
1794 int ncalls,
1795 int maxcuts,
1796 GCG_CUTINDICES*** cutindices,
1797 int* ncutindices
1798 )
1799{
1800 SCIP* scip;
1801 int i;
1802 int k;
1803
1804 SCIP_Real maxslack;
1805 MOD2_MATRIX mod2matrix;
1806 MOD2_ROW** nonzrows;
1807
1809
1810 assert(zhdata != NULL);
1811
1812 maxslack = depth == 0 ? zhdata->maxslackroot : zhdata->maxslack;
1813 maxslack += 2 * SCIPfeastol(scip);
1814
1815 *ncutindices = 0;
1816 zhdata->infeasible = FALSE;
1817
1818 SCIP_CALL( buildMod2Matrix(gcg, sol, zhdata, SCIPblkmem(scip), &mod2matrix, allowlocal, maxslack) );
1819
1820 SCIPdebugMsg(scip, "built mod2 matrix (%i rows, %i cols)\n", mod2matrix.nrows, mod2matrix.ncols);
1821
1822 SCIP_CALL( SCIPallocBufferArray(scip, &nonzrows, mod2matrix.nrows) );
1823
1824 for( k = 0; k < MAXREDUCTIONROUNDS; ++k )
1825 {
1826 int ncancel;
1827
1828 zhdata->nreductions = 0;
1829
1830 assert(mod2matrix.nzeroslackrows <= mod2matrix.nrows);
1831 SCIP_CALL( mod2matrixPreprocessRows(scip, sol, &mod2matrix, zhdata, allowlocal, cutindices, ncutindices, maxcuts) );
1832 assert(mod2matrix.nzeroslackrows <= mod2matrix.nrows);
1833
1834 SCIPdebugMsg(scip, "preprocessed rows (%i rows, %i cols, %i cuts) \n", mod2matrix.nrows, mod2matrix.ncols,
1835 *ncutindices);
1836
1837 if( mod2matrix.nrows == 0 )
1838 break;
1839
1840 if( *ncutindices >= maxcuts )
1841 {
1842 SCIPdebugMsg(scip, "enough cuts, stopping (%i rows, %i cols)\n", mod2matrix.nrows, mod2matrix.ncols);
1843 break;
1844 }
1845
1846 SCIP_CALL( mod2matrixPreprocessColumns(scip, &mod2matrix, zhdata) );
1847
1848 SCIPdebugMsg(scip, "preprocessed columns (%i rows, %i cols)\n", mod2matrix.nrows, mod2matrix.ncols);
1849
1850 ncancel = mod2matrix.nrows;
1851 if( ncancel > 100 )
1852 {
1853 ncancel = 100;
1854 SCIPselectPtr((void**) mod2matrix.rows, compareRowSlack, ncancel, mod2matrix.nrows);
1855 }
1856
1857 SCIPsortPtr((void**) mod2matrix.rows, compareRowSlack, ncancel);
1858
1859 if( mod2matrix.ncols == 0 )
1860 break;
1861
1862 assert(mod2matrix.nzeroslackrows <= mod2matrix.nrows);
1863
1864 /* apply Prop5 */
1865 for( i = 0; i < ncancel; ++i )
1866 {
1867 int j;
1868 MOD2_COL* col = NULL;
1869 MOD2_ROW* row = mod2matrix.rows[i];
1870
1871 if( SCIPisPositive(scip, row->slack) || row->nnonzcols == 0 )
1872 continue;
1873
1874 SCIPdebugMsg(scip, "processing row %i/%i (%i/%i cuts)\n", i, mod2matrix.nrows, *ncutindices, maxcuts);
1875
1876 for( j = 0; j < row->nnonzcols; ++j )
1877 {
1878 if( row->nonzcols[j]->solval == row->maxsolval ) /*lint !e777*/
1879 {
1880 col = row->nonzcols[j];
1881 break;
1882 }
1883 }
1884
1885 assert( col != NULL );
1886
1887 {
1888 int nslots;
1889 int nnonzrows;
1890 MOD2_ROW** rows;
1891
1892 ++zhdata->nreductions;
1893
1894 nnonzrows = 0;
1895 /* cppcheck-suppress nullPointer */
1896 nslots = SCIPhashsetGetNSlots(col->nonzrows);
1897 /* cppcheck-suppress nullPointer */
1898 rows = (MOD2_ROW**) SCIPhashsetGetSlots(col->nonzrows);
1899
1900 for( j = 0; j < nslots; ++j )
1901 {
1902 if( rows[j] != NULL && rows[j] != row )
1903 nonzrows[nnonzrows++] = rows[j];
1904 }
1905
1906 for( j = 0; j < nnonzrows; ++j )
1907 {
1908 SCIP_CALL( mod2rowAddRow(gcg, SCIPblkmem(scip), &mod2matrix, nonzrows[j], row) );
1909 }
1910
1911 /* cppcheck-suppress nullPointer */
1912 row->slack = col->solval;
1913 --mod2matrix.nzeroslackrows;
1914
1915 mod2matrixRemoveCol(scip, &mod2matrix, col);
1916 }
1917 }
1918
1919 SCIPdebugMsg(scip, "applied proposition five (%i rows, %i cols)\n", mod2matrix.nrows, mod2matrix.ncols);
1920
1921 if( zhdata->nreductions == 0 )
1922 {
1923 SCIPdebugMsg(scip, "no change, stopping (%i rows, %i cols)\n", mod2matrix.nrows, mod2matrix.ncols);
1924 break;
1925 }
1926 }
1927
1928 for( i = 0; i < mod2matrix.nrows && *ncutindices < maxcuts; ++i )
1929 {
1930 GCG_CUTINDICES* cutindex;
1931 MOD2_ROW* row = mod2matrix.rows[i];
1932
1933 if( computeMaxViolation(row) < zhdata->minviol ) // computeViolation(row)
1934 break;
1935
1936 if( row->rhs == 0 )
1937 continue;
1938
1939 /* OG: SCIP_CALL( generateZerohalfCut(scip, sol, &mod2matrix, sepa, sepadata, allowlocal, row) ); */
1940 // transfer the indices associated with this cut to cutindices
1942 (*cutindices)[*ncutindices] = cutindex;
1943 (*ncutindices)++;
1944
1945 }
1946
1947 SCIPdebugMsg(scip, "total number of cuts found: %i\n", *ncutindices);
1948
1949 /* If cuts where found we apply a filtering procedure using the scores and the orthogonalities,
1950 * similar to the sepastore. We only add the cuts that make it through this process and discard
1951 * the rest.
1952 */
1953
1954 SCIPfreeBufferArray(scip, &nonzrows);
1955
1956 destroyMod2Matrix(gcg, &mod2matrix);
1957
1958 return SCIP_OKAY;
1959}
#define SCIP_Shortbool
#define SCIP_Bool
#define SCIP_DEFAULT_EPSILON
#define SCIP_ALLOC(x)
#define SCIP_Real
#define MAX(x, y)
#define REALABS(x)
#define EPSZ(x, eps)
#define TRUE
#define FALSE
GCG interface methods.
GCG_EXPORT int GCGgetNMasterConss(GCG *gcg)
Definition relax_gcg.c:4211
SCIP * GCGgetMasterprob(GCG *gcg)
Definition gcg.cpp:99
int SCIPgetNContVars(SCIP *scip)
int SCIPgetNVars(SCIP *scip)
SCIP_VAR ** SCIPgetVars(SCIP *scip)
void SCIPhashmapFree(SCIP_HASHMAP **hashmap)
void * SCIPhashmapGetImage(SCIP_HASHMAP *hashmap, void *origin)
SCIP_RETCODE SCIPhashmapInsert(SCIP_HASHMAP *hashmap, void *origin, void *image)
SCIP_RETCODE SCIPhashmapCreate(SCIP_HASHMAP **hashmap, BMS_BLKMEM *blkmem, int mapsize)
void SCIPhashsetFree(SCIP_HASHSET **hashset, BMS_BLKMEM *blkmem)
SCIP_Bool SCIPhashsetExists(SCIP_HASHSET *hashset, void *element)
void ** SCIPhashsetGetSlots(SCIP_HASHSET *hashset)
int SCIPhashsetGetNElements(SCIP_HASHSET *hashset)
int SCIPhashsetGetNSlots(SCIP_HASHSET *hashset)
SCIP_RETCODE SCIPhashsetInsert(SCIP_HASHSET *hashset, BMS_BLKMEM *blkmem, void *element)
SCIP_RETCODE SCIPhashsetCreate(SCIP_HASHSET **hashset, BMS_BLKMEM *blkmem, int size)
SCIP_RETCODE SCIPhashsetRemove(SCIP_HASHSET *hashset, void *element)
void SCIPhashtableFree(SCIP_HASHTABLE **hashtable)
SCIP_Bool SCIPhashtableExists(SCIP_HASHTABLE *hashtable, void *element)
SCIP_RETCODE SCIPhashtableCreate(SCIP_HASHTABLE **hashtable, BMS_BLKMEM *blkmem, int tablesize, SCIP_DECL_HASHGETKEY((*hashgetkey)), SCIP_DECL_HASHKEYEQ((*hashkeyeq)), SCIP_DECL_HASHKEYVAL((*hashkeyval)), void *userptr)
void * SCIPhashtableRetrieve(SCIP_HASHTABLE *hashtable, void *key)
SCIP_RETCODE SCIPhashtableRemove(SCIP_HASHTABLE *hashtable, void *element)
SCIP_RETCODE SCIPhashtableInsert(SCIP_HASHTABLE *hashtable, void *element)
#define SCIPhashSignature64(a)
#define SCIPdebugMsg
SCIP_DECL_HASHKEYEQ(SCIPhashKeyEqString)
SCIP_DECL_HASHKEYVAL(SCIPhashKeyValString)
SCIP_RETCODE SCIPcalcIntegralScalar(SCIP_Real *vals, int nvals, SCIP_Real mindelta, SCIP_Real maxdelta, SCIP_Longint maxdnom, SCIP_Real maxscale, SCIP_Real *intscalar, SCIP_Bool *success)
SCIP_Real SCIPrelDiff(SCIP_Real val1, SCIP_Real val2)
void SCIPswapInts(int *value1, int *value2)
void SCIPswapPointers(void **pointer1, void **pointer2)
SCIP_DECL_SORTPTRCOMP(SCIPbendersComp)
int SCIPcolGetVarProbindex(SCIP_COL *col)
SCIP_VAR * SCIPcolGetVar(SCIP_COL *col)
SCIP_Bool SCIPcolIsIntegral(SCIP_COL *col)
SCIP_Bool SCIPcutsTightenCoefficients(SCIP *scip, SCIP_Bool cutislocal, SCIP_Real *cutcoefs, SCIP_Real *cutrhs, int *cutinds, int *cutnnz, int *nchgcoefs)
SCIP_RETCODE SCIPgetLPColsData(SCIP *scip, SCIP_COL ***cols, int *ncols)
int SCIPgetNLPCols(SCIP *scip)
#define SCIPfreeCleanBufferArray(scip, ptr)
#define SCIPfreeBuffer(scip, ptr)
#define SCIPallocCleanBufferArray(scip, ptr, num)
#define SCIPfreeBlockMemoryArray(scip, ptr, num)
BMS_BLKMEM * SCIPblkmem(SCIP *scip)
#define SCIPensureBlockMemoryArray(scip, ptr, arraysizeptr, minsize)
#define SCIPallocBufferArray(scip, ptr, num)
#define SCIPallocBlockMemoryArray(scip, ptr, num)
#define SCIPallocBuffer(scip, ptr)
#define SCIPfreeBlockMemory(scip, ptr)
#define SCIPfreeBlockMemoryArrayNull(scip, ptr, num)
#define SCIPallocBlockMemory(scip, ptr)
SCIP_Bool SCIProwIsIntegral(SCIP_ROW *row)
SCIP_Real SCIProwGetLhs(SCIP_ROW *row)
int SCIProwGetNNonz(SCIP_ROW *row)
SCIP_COL ** SCIProwGetCols(SCIP_ROW *row)
SCIP_Real SCIProwGetRhs(SCIP_ROW *row)
int SCIProwGetNLPNonz(SCIP_ROW *row)
int SCIProwGetLPPos(SCIP_ROW *row)
SCIP_Bool SCIProwIsLocal(SCIP_ROW *row)
int SCIProwGetRank(SCIP_ROW *row)
SCIP_Real SCIProwGetConstant(SCIP_ROW *row)
SCIP_Real * SCIProwGetVals(SCIP_ROW *row)
SCIP_Real SCIPgetRowSolActivity(SCIP *scip, SCIP_ROW *row, SCIP_SOL *sol)
SCIP_Real SCIPgetSolVal(SCIP *scip, SCIP_SOL *sol, SCIP_VAR *var)
SCIP_Real SCIPinfinity(SCIP *scip)
SCIP_Bool SCIPisPositive(SCIP *scip, SCIP_Real val)
SCIP_Real SCIPfeasCeil(SCIP *scip, SCIP_Real val)
SCIP_Real SCIPfeasFloor(SCIP *scip, SCIP_Real val)
SCIP_Bool SCIPisInfinity(SCIP *scip, SCIP_Real val)
SCIP_Bool SCIPisSumLT(SCIP *scip, SCIP_Real val1, SCIP_Real val2)
SCIP_Real SCIPround(SCIP *scip, SCIP_Real val)
SCIP_Bool SCIPisSumEQ(SCIP *scip, SCIP_Real val1, SCIP_Real val2)
SCIP_Bool SCIPisFeasIntegral(SCIP *scip, SCIP_Real val)
SCIP_Real SCIPfeastol(SCIP *scip)
SCIP_Bool SCIPisGT(SCIP *scip, SCIP_Real val1, SCIP_Real val2)
SCIP_Bool SCIPisEQ(SCIP *scip, SCIP_Real val1, SCIP_Real val2)
SCIP_Bool SCIPisZero(SCIP *scip, SCIP_Real val)
SCIP_Real SCIPepsilon(SCIP *scip)
SCIP_Real SCIPsumepsilon(SCIP *scip)
SCIP_Bool SCIPisLT(SCIP *scip, SCIP_Real val1, SCIP_Real val2)
SCIP_Bool SCIPisSumGT(SCIP *scip, SCIP_Real val1, SCIP_Real val2)
SCIP_Real * SCIPvarGetVlbCoefs(SCIP_VAR *var)
SCIP_Real SCIPvarGetUbLocal(SCIP_VAR *var)
SCIP_Real SCIPvarGetUbGlobal(SCIP_VAR *var)
SCIP_RETCODE SCIPgetVarClosestVub(SCIP *scip, SCIP_VAR *var, SCIP_SOL *sol, SCIP_Real *closestvub, int *closestvubidx)
int SCIPvarGetProbindex(SCIP_VAR *var)
SCIP_Real * SCIPvarGetVlbConstants(SCIP_VAR *var)
SCIP_RETCODE SCIPgetVarClosestVlb(SCIP *scip, SCIP_VAR *var, SCIP_SOL *sol, SCIP_Real *closestvlb, int *closestvlbidx)
SCIP_Real SCIPvarGetLbLocal(SCIP_VAR *var)
SCIP_VAR ** SCIPvarGetVlbVars(SCIP_VAR *var)
SCIP_Real SCIPvarGetLbGlobal(SCIP_VAR *var)
SCIP_Real * SCIPvarGetVubConstants(SCIP_VAR *var)
SCIP_VAR ** SCIPvarGetVubVars(SCIP_VAR *var)
SCIP_Real * SCIPvarGetVubCoefs(SCIP_VAR *var)
void SCIPselectPtr(void **ptrarray, SCIP_DECL_SORTPTRCOMP((*ptrcomp)), int k, int len)
SCIP_Bool SCIPsortedvecFindPtr(void **ptrarray, SCIP_DECL_SORTPTRCOMP((*ptrcomp)), void *val, int len, int *pos)
void SCIPsortPtr(void **ptrarray, SCIP_DECL_SORTPTRCOMP((*ptrcomp)), int len)
static assert(heur !=NULL)
SCIP_CALL(SCIPgetExternBranchCands(origprob, &lpcands, &lpcandssol, NULL, &nlpcands, NULL, NULL, NULL, NULL))
SCIP_VAR ** vars
SCIP_Longint ncalls
int j
int nintvars
SCIP_Bool success
SCIP_Real solval
int i
SCIPfreeBufferArray(scip, &cycles)
int nlprows
SCIP_SOL * sol
int depth
#define NULL
#define BMSallocBlockMemory(mem, ptr)
#define SCIP_UNUSED(x)
#define BMScopyMemoryArray(ptr, source, num)
#define BMSmoveMemoryArray(ptr, source, num)
struct BMS_BlkMem BMS_BLKMEM
SCIP_ROW * SCIPconsGetRow(SCIP *scip, SCIP_CONS *cons)
struct Mod2Row MOD2_ROW
struct Mod2Matrix MOD2_MATRIX
struct Mod2Col MOD2_COL
struct TransIntRow TRANSINTROW
struct RowIndex ROWINDEX
SCIP_CONS ** masterconss
SCIP_Real solval
SCIP_HASHSET * nonzrows
MOD2_ROW ** rows
TRANSINTROW * transintrows
MOD2_COL ** cols
ROWINDEX * rowinds
SCIP_Real maxsolval
MOD2_COL ** nonzcols
SCIP_Real slack
unsigned int index
unsigned int type
SCIP_Real * vals
struct SCIP_Cons SCIP_CONS
struct Gcg GCG
Definition type_gcg.h:44
struct SCIP_Row SCIP_ROW
struct SCIP_Col SCIP_COL
struct SCIP_HashMap SCIP_HASHMAP
struct SCIP_HashSet SCIP_HASHSET
struct SCIP_HashTable SCIP_HASHTABLE
enum SCIP_Retcode SCIP_RETCODE
struct Scip SCIP
struct SCIP_Sol SCIP_SOL
struct SCIP_Var SCIP_VAR
SCIP_RETCODE GCGcreateCutIndicesFromArray(SCIP *scip, GCG_CUTINDICES **cutindices, int nindices, int *indices)
SCIP_RETCODE GCGselectConstraintsZeroHalf(GCG *gcg, SCIP_SOL *sol, SCIP_Bool allowlocal, int depth, GCG_ZEROHALFDATA *zhdata, int ncalls, int maxcuts, GCG_CUTINDICES ***cutindices, int *ncutindices)
#define MAXDNOM
#define BOUNDSWITCH
SCIP_RETCODE GCGfreeCutIndices(SCIP *scip, GCG_CUTINDICES **cutindices)
#define ORIG_RHS
#define COLINFO_GET_RHSOFFSET(x)
static SCIP_RETCODE transformNonIntegralRow(SCIP *scip, SCIP_SOL *sol, SCIP_Bool allowlocal, SCIP_Real maxslack, int sign, SCIP_Bool local, int rank, int rowlen, SCIP_Real *rowvals, SCIP_COL **rowcols, SCIP_Real rhs, int *intvarpos, TRANSINTROW *introw, SCIP_Bool *success)
static void destroyMod2Matrix(GCG *gcg, MOD2_MATRIX *mod2matrix)
#define ORIG_LHS
static SCIP_RETCODE mod2MatrixAddOrigRow(SCIP *scip, BMS_BLKMEM *blkmem, MOD2_MATRIX *mod2matrix, SCIP_HASHMAP *origcol2col, SCIP_ROW *origrow, SCIP_Real slack, ROWIND_TYPE side, int rhsmod2)
#define MAXREDUCTIONROUNDS
static void getIntegralScalar(SCIP_Real val, SCIP_Real scalar, SCIP_Real mindelta, SCIP_Real maxdelta, SCIP_Real *sval, SCIP_Real *intval)
static SCIP_RETCODE mod2matrixRemoveRow(SCIP *scip, MOD2_MATRIX *mod2matrix, MOD2_ROW *row)
static SCIP_RETCODE buildMod2Matrix(GCG *gcg, SCIP_SOL *sol, GCG_ZEROHALFDATA *zhdata, BMS_BLKMEM *blkmem, MOD2_MATRIX *mod2matrix, SCIP_Bool allowlocal, SCIP_Real maxslack)
#define MAXSCALE
static void mod2rowUnlinkCol(MOD2_ROW *row, MOD2_COL *col)
#define UNIQUE_INDEX(rowind)
#define COLINFO_GET_MOD2COL(x)
static int mod2(SCIP *scip, SCIP_Real val)
static SCIP_Real computeMaxViolation(MOD2_ROW *row)
static void checkRow(MOD2_ROW *row)
#define TRANSROW
static SCIP_RETCODE mod2MatrixAddTransRow(SCIP *scip, MOD2_MATRIX *mod2matrix, SCIP_HASHMAP *origcol2col, int transrowind)
static void mod2matrixRemoveCol(SCIP *scip, MOD2_MATRIX *mod2matrix, MOD2_COL *col)
static SCIP_RETCODE mod2matrixPreprocessColumns(SCIP *scip, MOD2_MATRIX *mod2matrix, GCG_ZEROHALFDATA *zhdata)
static SCIP_RETCODE mod2MatrixAddCol(SCIP *scip, MOD2_MATRIX *mod2matrix, SCIP_HASHMAP *origvar2col, SCIP_VAR *origvar, SCIP_Real solval, int rhsoffset)
static SCIP_RETCODE mod2rowAddRow(GCG *gcg, BMS_BLKMEM *blkmem, MOD2_MATRIX *mod2matrix, MOD2_ROW *row, MOD2_ROW *rowtoadd)
static SCIP_RETCODE mod2colLinkRow(BMS_BLKMEM *blkmem, MOD2_COL *col, MOD2_ROW *row)
static SCIP_RETCODE mod2MatrixTransformContRows(GCG *gcg, SCIP_SOL *sol, GCG_ZEROHALFDATA *zhdata, MOD2_MATRIX *mod2matrix, SCIP_Bool allowlocal, SCIP_Real maxslack)
#define COLINFO_CREATE(mod2col, rhsoffset)
#define ROWIND_TYPE
static SCIP_RETCODE mod2colUnlinkRow(MOD2_COL *col, MOD2_ROW *row)
static SCIP_RETCODE mod2matrixPreprocessRows(SCIP *scip, SCIP_SOL *sol, MOD2_MATRIX *mod2matrix, GCG_ZEROHALFDATA *zhdata, SCIP_Bool allowlocal, GCG_CUTINDICES ***cutindices, int *ncutindices, int maxcuts)
SCIP_RETCODE GCGcreateCutIndicesFromRowindex(SCIP *scip, GCG_CUTINDICES **cutindices, int nindices, ROWINDEX *rowindex)
struct GCG_ZeroHalfData GCG_ZEROHALFDATA
struct GCG_CutIndices GCG_CUTINDICES