Scippy

GCG

Branch-and-Price & Column Generation for Everyone

scip_misc.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 scip_misc.c
30 * @brief various SCIP helper methods
31 * @author Martin Bergner
32 */
33
34/*---+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0----+----1----+----2*/
35
36#include "gcg/scip_misc.h"
37#include "scip/scipdefplugins.h"
38#include <string.h>
39#include "scip/cons_indicator.h"
40
41/** returns TRUE if variable is relevant, FALSE otherwise */
43 SCIP_VAR* var /**< variable to test */
44 )
45{
46 assert(var != NULL);
49}
50
51/** returns the type of an arbitrary SCIP constraint */
53 SCIP* scip, /**< SCIP data structure */
54 SCIP_CONS* cons /**< constraint to get type for */
55 )
56{
57 SCIP_CONSHDLR* conshdlr;
58 const char * conshdlrname;
59 assert(cons != NULL);
60 conshdlr = SCIPconsGetHdlr(cons);
61 assert(conshdlr != NULL);
62 conshdlrname = SCIPconshdlrGetName(conshdlr);
63
64 if( strcmp(conshdlrname, "linear") == 0 )
65 {
66 return linear;
67 }
68 else if( strcmp(conshdlrname, "setppc") == 0 )
69 {
70 switch ( SCIPgetTypeSetppc(scip, cons) ) {
72 return setcovering;
74 return setpacking;
76 return setpartitioning;
77 default:
78 return unknown;
79 }
80 }
81 else if( strcmp(conshdlrname, "logicor") == 0 )
82 {
83 return logicor;
84 }
85 else if( strcmp(conshdlrname, "knapsack") == 0 )
86 {
87 return knapsack;
88 }
89 else if( strcmp(conshdlrname, "varbound") == 0 )
90 {
91 return varbound;
92 }
93 else if( strcmp(conshdlrname, "SOS1") == 0 )
94 {
95 return sos1;
96 }
97 else if( strcmp(conshdlrname, "SOS2") == 0 )
98 {
99 return sos2;
100 }
101 else if( strcmp(conshdlrname, "indicator") == 0 )
102 {
103 return indicator;
104 }
105 return unknown;
106}
107
108/** returns the rhs of an arbitrary SCIP constraint */
110 SCIP* scip, /**< SCIP data structure */
111 SCIP_CONS* cons /**< constraint to get left hand side for */
112 )
113{
114 int nconsvars;
115 SCIP_VAR** consvars;
116 SCIP_CONSHDLR* conshdlr;
117 const char * conshdlrname;
118 SCIP_Longint * w;
119 SCIP_Real rhs;
120 int i;
121
122 assert(scip != NULL);
123 assert(cons != NULL);
124 conshdlr = SCIPconsGetHdlr(cons);
125 assert(conshdlr != NULL);
126 conshdlrname = SCIPconshdlrGetName(conshdlr);
127
128 if( strcmp(conshdlrname, "linear") == 0 )
129 {
130 return SCIPgetRhsLinear(scip, cons);
131 }
132 else if( strcmp(conshdlrname, "setppc") == 0 )
133 {
134 switch ( SCIPgetTypeSetppc(scip, cons) ) {
135 case SCIP_SETPPCTYPE_PARTITIONING: /* fall through desired */
137 rhs = 1.0;
138
139 nconsvars = SCIPgetNVarsSetppc(scip, cons);
140 consvars = SCIPgetVarsSetppc(scip, cons);
141
142 for( i = 0; i < nconsvars; i++ )
143 {
144 if( SCIPvarIsNegated(consvars[i]) )
145 rhs -= 1.0;
146 }
147
148 return rhs;
149
151 return SCIPinfinity(scip);
152 }
153 }
154 else if( strcmp(conshdlrname, "logicor") == 0 )
155 {
156 return SCIPinfinity(scip);
157 }
158 else if( strcmp(conshdlrname, "knapsack") == 0 )
159 {
160 rhs = SCIPgetCapacityKnapsack(scip, cons);
161
162 /* copy Longint array to SCIP_Real array */
164 consvars = SCIPgetVarsKnapsack(scip, cons);
165 nconsvars = SCIPgetNVarsKnapsack(scip, cons);
166
167 for( i = 0; i < nconsvars; i++ )
168 {
169 if( SCIPvarIsNegated(consvars[i]) )
170 rhs -= w[i];
171 }
172
173 return rhs;
174 }
175 else if( strcmp(conshdlrname, "varbound") == 0 )
176 {
177 rhs = SCIPgetRhsVarbound(scip, cons);
178
180 rhs -= 1.0;
181
183 rhs -= SCIPgetVbdcoefVarbound(scip, cons);
184
185 return rhs;
186 }
187 else if( strcmp(conshdlrname, "SOS1") == 0 )
188 {
189 SCIPdebugMessage("WARNING: SOS1 NOT IMPLEMENTED\n");
190 }
191 else if( strcmp(conshdlrname, "SOS2") == 0 )
192 {
193 SCIPdebugMessage("WARNING: SOS2 NOT IMPLEMENTED\n");
194 }
195 else if( strcmp(conshdlrname, "indicator") == 0 )
196 {
197 return 0.;
198 }
199 else
200 {
201 SCIPdebugMessage("WARNING: NOT IMPLEMENTED");
202 }
203 return -SCIPinfinity(scip);
204}
205
206/** returns the lhs of an arbitrary SCIP constraint */
208 SCIP* scip, /**< SCIP data structure */
209 SCIP_CONS* cons /**< constraint to get left hand side for */
210 )
211{
212 SCIP_CONSHDLR* conshdlr;
213 const char * conshdlrname;
214 int nconsvars;
215 SCIP_VAR** consvars;
216 SCIP_Real lhs;
217 int i;
218
219
220 assert(scip != NULL);
221 assert(cons != NULL);
222 conshdlr = SCIPconsGetHdlr(cons);
223 assert(conshdlr != NULL);
224 conshdlrname = SCIPconshdlrGetName(conshdlr);
225
226 if( strcmp(conshdlrname, "linear") == 0 )
227 {
228 return SCIPgetLhsLinear(scip, cons);
229 }
230 else if( strcmp(conshdlrname, "setppc") == 0 )
231 {
232 switch ( SCIPgetTypeSetppc(scip, cons) ) {
233 case SCIP_SETPPCTYPE_PARTITIONING: /* fall through desired */
235 lhs = 1.0;
236
237 nconsvars = SCIPgetNVarsSetppc(scip, cons);
238 consvars = SCIPgetVarsSetppc(scip, cons);
239
240 for( i = 0; i < nconsvars; i++ )
241 {
242 if( SCIPvarIsNegated(consvars[i]) )
243 lhs -= 1.0;
244 }
245
246 return lhs;
247
249 return -SCIPinfinity(scip);
250 }
251 }
252 else if( strcmp(conshdlrname, "logicor") == 0 )
253 {
254 lhs = 1.0;
255
256 nconsvars = SCIPgetNVarsLogicor(scip, cons);
257 consvars = SCIPgetVarsLogicor(scip, cons);
258
259 for( i = 0; i < nconsvars; i++ )
260 {
261 if( SCIPvarIsNegated(consvars[i]) )
262 lhs -= 1.0;
263 }
264
265 return lhs;
266 }
267 else if( strcmp(conshdlrname, "knapsack") == 0 )
268 {
269 return -SCIPinfinity(scip);
270 }
271 else if( strcmp(conshdlrname, "varbound") == 0 )
272 {
273 lhs = SCIPgetLhsVarbound(scip, cons);
274
276 lhs -= 1.0;
277
279 lhs -= SCIPgetVbdcoefVarbound(scip, cons);
280
281 return lhs;
282 }
283 else if( strcmp(conshdlrname, "SOS1") == 0 )
284 {
285 SCIPdebugMessage("WARNING: SOS1 NOT IMPLEMENTED\n");
286 }
287 else if( strcmp(conshdlrname, "SOS2") == 0 )
288 {
289 SCIPdebugMessage("WARNING: SOS2 NOT IMPLEMENTED\n");
290 }
291 else if( strcmp(conshdlrname, "indicator") == 0 )
292 {
293 return -SCIPinfinity(scip);
294 }
295 else
296 {
297 SCIPdebugMessage("WARNING: NOT IMPLEMENTED");
298 }
299 return SCIPinfinity(scip);
300}
301
302/** returns the dual farkas sol of an arbitrary SCIP constraint */
304 SCIP* scip, /**< SCIP data structure */
305 SCIP_CONS* cons /**< constraint to get left hand side for */
306 )
307{
308 SCIP_CONSHDLR* conshdlr;
309 const char * conshdlrname;
310
311 assert(scip != NULL);
312 assert(cons != NULL);
313 conshdlr = SCIPconsGetHdlr(cons);
314 assert(conshdlr != NULL);
315 conshdlrname = SCIPconshdlrGetName(conshdlr);
316
317 if( strcmp(conshdlrname, "linear") == 0 )
318 {
319 return SCIPgetDualfarkasLinear(scip, cons);
320 }
321 else if( strcmp(conshdlrname, "setppc") == 0 )
322 {
323 return SCIPgetDualfarkasSetppc(scip, cons);
324 }
325 else if( strcmp(conshdlrname, "logicor") == 0 )
326 {
327 return SCIPgetDualfarkasLogicor(scip, cons);
328 }
329 else if( strcmp(conshdlrname, "knapsack") == 0 )
330 {
331 return SCIPgetDualfarkasKnapsack(scip, cons);
332 }
333 else if( strcmp(conshdlrname, "varbound") == 0 )
334 {
335 return SCIPgetDualfarkasVarbound(scip, cons);
336 }
337 else if( strcmp(conshdlrname, "SOS1") == 0 )
338 {
339 SCIPdebugMessage("WARNING: SOS1 NOT IMPLEMENTED\n");
340 }
341 else if( strcmp(conshdlrname, "SOS2") == 0 )
342 {
343 SCIPdebugMessage("WARNING: SOS2 NOT IMPLEMENTED\n");
344 }
345 else if( strcmp(conshdlrname, "origbranch") == 0 )
346 {
347 SCIPdebugMessage("origbranch: return dualfarkas 0\n");
348 return 0.0;
349 }
350 else if( strcmp(conshdlrname, "masterbranch") == 0 )
351 {
352 SCIPdebugMessage("masterbranch: return dualsol 0\n");
353 return 0.0;
354 }
355 else if( strcmp(conshdlrname, "indicator") == 0 )
356 {
357 SCIPdebugMessage("WARNING: indicator conss NOT IMPLEMENTED");
358 }
359 else
360 {
361 SCIPdebugMessage("WARNING: NOT IMPLEMENTED");
362 }
363 return SCIPinfinity(scip);
364}
365
366/** returns the dual sol of an arbitrary SCIP constraint */
368 SCIP* scip, /**< SCIP data structure */
369 SCIP_CONS* cons /**< constraint to get left hand side for */
370 )
371{
372 SCIP_CONSHDLR* conshdlr;
373 const char * conshdlrname;
374
375 assert(scip != NULL);
376 assert(cons != NULL);
377 conshdlr = SCIPconsGetHdlr(cons);
378 assert(conshdlr != NULL);
379 conshdlrname = SCIPconshdlrGetName(conshdlr);
380
381 if( strcmp(conshdlrname, "linear") == 0 )
382 {
383 return SCIPgetDualsolLinear(scip, cons);
384 }
385 else if( strcmp(conshdlrname, "setppc") == 0 )
386 {
387 return SCIPgetDualsolSetppc(scip, cons);
388 }
389 else if( strcmp(conshdlrname, "logicor") == 0 )
390 {
391 return SCIPgetDualsolLogicor(scip, cons);
392 }
393 else if( strcmp(conshdlrname, "knapsack") == 0 )
394 {
395 return SCIPgetDualsolKnapsack(scip, cons);
396 }
397 else if( strcmp(conshdlrname, "varbound") == 0 )
398 {
399 return SCIPgetDualsolVarbound(scip, cons);
400 }
401 else if( strcmp(conshdlrname, "SOS1") == 0 )
402 {
403 SCIPdebugMessage("WARNING: SOS1 NOT IMPLEMENTED\n");
404 }
405 else if( strcmp(conshdlrname, "SOS2") == 0 )
406 {
407 SCIPdebugMessage("WARNING: SOS2 NOT IMPLEMENTED\n");
408 }
409 else if( strcmp(conshdlrname, "origbranch") == 0 )
410 {
411 SCIPdebugMessage("origbranch: return Dualsol 0\n");
412 return 0.0;
413 }
414 else if( strcmp(conshdlrname, "masterbranch") == 0 )
415 {
416 SCIPdebugMessage("masterbranch: return dualsol 0\n");
417 return 0.0;
418 }
419 else if( strcmp(conshdlrname, "indicator") == 0 )
420 {
421 SCIPdebugMessage("WARNING: indicator conss NOT IMPLEMENTED");
422 }
423 else
424 {
425 SCIPdebugMessage("WARNING: NOT IMPLEMENTED");
426 }
427 return SCIPinfinity(scip);
428}
429
430
431
432/** returns the number of variables in an arbitrary SCIP constraint */
434 SCIP* scip, /**< SCIP data structure */
435 SCIP_CONS* cons /**< constraint to get number of variables */
436 )
437{
438 SCIP_CONSHDLR* conshdlr;
439 const char * conshdlrname;
440
441 assert(scip != NULL);
442 assert(cons != NULL);
443 conshdlr = SCIPconsGetHdlr(cons);
444 assert(conshdlr != NULL);
445 conshdlrname = SCIPconshdlrGetName(conshdlr);
446
447 if( strcmp(conshdlrname, "linear") == 0 )
448 {
449 return SCIPgetNVarsLinear(scip, cons);
450 }
451 else if( strcmp(conshdlrname, "setppc") == 0 )
452 {
453 return SCIPgetNVarsSetppc(scip, cons);
454 }
455 else if( strcmp(conshdlrname, "logicor") == 0 )
456 {
457 return SCIPgetNVarsLogicor(scip, cons);
458 }
459 else if( strcmp(conshdlrname, "knapsack") == 0 )
460 {
461 return SCIPgetNVarsKnapsack(scip, cons);
462 }
463 else if( strcmp(conshdlrname, "varbound") == 0 )
464 {
465 return 2;
466 }
467 else if( strcmp(conshdlrname, "indicator") == 0 )
468 {
469 return 2;
470 }
471 else if( strcmp(conshdlrname, "SOS1") == 0 )
472 {
473 return SCIPgetNVarsSOS1(scip, cons);
474 }
475 else if( strcmp(conshdlrname, "SOS2") == 0 )
476 {
477 return SCIPgetNVarsSOS2(scip, cons);
478 }
479 else
480 {
481 SCIPwarningMessage(scip, "GCGconsGetNVars: NOT IMPLEMENTED <%s>\n", conshdlrname);
482 return 0;
483 }
484}
485
486/** returns the variable array of an arbitrary SCIP constraint */
488 SCIP* scip, /**< SCIP data structure */
489 SCIP_CONS* cons, /**< constraint to get variables from */
490 SCIP_VAR** vars, /**< array where variables are stored */
491 int nvars /**< size of storage array */
492 )
493{
494
495 SCIP_CONSHDLR* conshdlr;
496 const char * conshdlrname;
497 int i;
498
499 assert(scip != NULL);
500 assert(cons != NULL);
501 assert(vars != NULL);
502 assert(nvars > 0);
503
504 conshdlr = SCIPconsGetHdlr(cons);
505 assert(conshdlr != NULL);
506 conshdlrname = SCIPconshdlrGetName(conshdlr);
507
508 if( strcmp(conshdlrname, "linear") == 0 )
509 {
510 if( nvars < SCIPgetNVarsLinear(scip, cons) )
511 return SCIP_INVALIDDATA;
512
514 }
515 else if( strcmp(conshdlrname, "setppc") == 0 )
516 {
517 SCIP_VAR** consvars;
518 int nconsvars;
519
520 consvars = SCIPgetVarsSetppc(scip, cons);
521 nconsvars = SCIPgetNVarsSetppc(scip, cons);
522
523 if( nvars < nconsvars )
524 return SCIP_INVALIDDATA;
525
526 for( i = 0; i < nconsvars; i++ )
527 if( !SCIPvarIsNegated(consvars[i]) )
528 vars[i] = consvars[i];
529 else
530 vars[i] = SCIPvarGetNegatedVar(consvars[i]);
531 }
532 else if( strcmp(conshdlrname, "logicor") == 0 )
533 {
534 SCIP_VAR** consvars;
535 int nconsvars;
536
537 consvars = SCIPgetVarsLogicor(scip, cons);
538 nconsvars = SCIPgetNVarsLogicor(scip, cons);
539
540 if( nvars < nconsvars )
541 return SCIP_INVALIDDATA;
542
543 for( i = 0; i < nconsvars; i++ )
544 if( !SCIPvarIsNegated(consvars[i]) )
545 vars[i] = consvars[i];
546 else
547 vars[i] = SCIPvarGetNegatedVar(consvars[i]);
548 }
549 else if( strcmp(conshdlrname, "knapsack") == 0 )
550 {
551 SCIP_VAR** consvars;
552 int nconsvars;
553
554 consvars = SCIPgetVarsKnapsack(scip, cons);
555 nconsvars = SCIPgetNVarsKnapsack(scip, cons);
556
557 if( nvars < nconsvars )
558 return SCIP_INVALIDDATA;
559
560 for( i = 0; i < nconsvars; i++ )
561 if( !SCIPvarIsNegated(consvars[i]) )
562 vars[i] = consvars[i];
563 else
564 vars[i] = SCIPvarGetNegatedVar(consvars[i]);
565 }
566 else if( strcmp(conshdlrname, "varbound") == 0 )
567 {
568 if( nvars < 2 )
569 return SCIP_INVALIDDATA;
570
572 vars[0] = SCIPgetVarVarbound(scip, cons);
573 else
575
577 vars[1] = SCIPgetVbdvarVarbound(scip, cons);
578 else
580 }
581 else if( strcmp(conshdlrname, "SOS1") == 0 )
582 {
583 if( nvars < SCIPgetNVarsSOS1(scip, cons) )
584 return SCIP_INVALIDDATA;
585
586 BMScopyMemoryArray(vars, SCIPgetVarsSOS1(scip, cons), nvars);
587 }
588 else if( strcmp(conshdlrname, "SOS2") == 0 )
589 {
590 if( nvars < SCIPgetNVarsSOS2(scip, cons) )
591 return SCIP_INVALIDDATA;
592
593 BMScopyMemoryArray(vars, SCIPgetVarsSOS2(scip, cons), nvars);
594 }
595 else if( strcmp(conshdlrname, "indicator") == 0 )
596 {
597 if( nvars != 2 )
598 return SCIP_INVALIDDATA;
599
600 /* indicator conss : s - My <= 0 */
601
602 /* slack variable first */
603 vars[0] = SCIPgetSlackVarIndicator(cons);
604 vars[1] = SCIPgetBinaryVarIndicator(cons);
605 }
606 else
607 {
608 SCIPwarningMessage(scip, "GCGconsGetVars: NOT IMPLEMENTED <%s>\n", conshdlrname);
609 }
610 return SCIP_OKAY;
611}
612
613
614/**
615 * Returns the value array of an arbitrary SCIP constraint
616 * @todo SOS1 & SOS2 not implemented yet
617 */
619 SCIP* scip, /**< SCIP data structure */
620 SCIP_CONS* cons, /**< constraint to get values from */
621 SCIP_Real* vals, /**< array where values are stored */
622 int nvals /**< size of storage array */
623 )
624{
625 SCIP_CONSHDLR* conshdlr;
626 const char* conshdlrname;
627 int i;
628 int nvars;
629
630 assert(scip != NULL);
631 assert(cons != NULL);
632 assert(vals != NULL);
633 assert(nvals > 0);
634
635 conshdlr = SCIPconsGetHdlr(cons);
636 assert(conshdlr != NULL);
637 conshdlrname = SCIPconshdlrGetName(conshdlr);
638
639 if( strcmp(conshdlrname, "linear") == 0 )
640 {
641 nvars = SCIPgetNVarsLinear(scip, cons);
642 if( nvals < nvars )
643 return SCIP_INVALIDDATA;
644
645 BMScopyMemoryArray(vals, SCIPgetValsLinear(scip, cons), nvars);
646 }
647 else if( strcmp(conshdlrname, "setppc") == 0 )
648 {
649 SCIP_VAR** vars;
650 vars = SCIPgetVarsSetppc(scip, cons);
651 nvars = SCIPgetNVarsSetppc(scip, cons);
652 if( nvals < nvars )
653 return SCIP_INVALIDDATA;
654
655 for( i = 0; i < nvals; i++ )
656 if( !SCIPvarIsNegated(vars[i]) )
657 vals[i] = 1.0;
658 else
659 vals[i] = -1.0;
660 }
661 else if( strcmp(conshdlrname, "logicor") == 0 )
662 {
663 SCIP_VAR** vars;
664 vars = SCIPgetVarsLogicor(scip, cons);
665 nvars = SCIPgetNVarsLogicor(scip, cons);
666 if( nvals < nvars )
667 return SCIP_INVALIDDATA;
668
669 for( i = 0; i < nvals; i++ )
670 {
671 if( !SCIPvarIsNegated(vars[i]) )
672 vals[i] = 1.0;
673 else
674 vals[i] = -1.0;
675 }
676 }
677 else if( strcmp(conshdlrname, "knapsack") == 0 )
678 {
679 SCIP_VAR** vars;
680
681 /* copy Longint array to SCIP_Real array */
683 vars = SCIPgetVarsKnapsack(scip, cons);
684 nvars = SCIPgetNVarsKnapsack(scip, cons);
685 if( nvals < nvars )
686 return SCIP_INVALIDDATA;
687
688 for( i = 0; i < nvars; i++ )
689 {
690 if( !SCIPvarIsNegated(vars[i]) )
691 vals[i] = w[i];
692 else
693 vals[i] = -w[i];
694 }
695 }
696 else if( strcmp(conshdlrname, "varbound") == 0 )
697 {
698 nvars = 2;
699 if( nvals < nvars )
700 return SCIP_INVALIDDATA;
701
703 vals[0] = 1.0;
704 else
705 vals[0] = -1.0;
706
708 vals[1] = SCIPgetVbdcoefVarbound(scip, cons);
709 else
710 vals[1] = -SCIPgetVbdcoefVarbound(scip, cons);
711 }
712 else if( strcmp(conshdlrname, "SOS1") == 0 )
713 {
714 /* store constraint */
715 SCIPerrorMessage("WARNING: SOS1 NOT IMPLEMENTED\n");
716 }
717 else if( strcmp(conshdlrname, "SOS2") == 0 )
718 {
719 /* store constraint */
720 SCIPdebugMessage("WARNING: SOS2 NOT IMPLEMENTED\n");
721 }
722 else if( strcmp(conshdlrname, "indicator") == 0 )
723 {
724 if( nvals != 2 )
725 return SCIP_INVALIDDATA;
726
727 /* indicator conss : s - My <= 0 */
728
729 /* slack variable first */
730 vals[0] = 1.;
732 }
733 else
734 {
735 SCIPwarningMessage(scip, "GCGconsGetVals: UNKNOWN NOT IMPLEMENTED: %s\n", conshdlrname);
736 }
737 return SCIP_OKAY;
738}
739
740/** returns true if the constraint should be a master constraint and false otherwise */
742 SCIP* scip, /**< SCIP data structure */
743 SCIP_CONS* cons /**< constraint to check */
744){
745
746 SCIP_Real lhs;
747 SCIP_Real rhs;
748
749 assert(scip != NULL);
750
751 rhs = GCGconsGetRhs(scip, cons);
752 lhs = GCGconsGetLhs(scip, cons);
753
754
755 return !(SCIPisEQ(scip, lhs, rhs) || SCIPisInfinity(scip, -lhs) || SCIPisInfinity(scip, rhs) );
756}
757
758
759/** returns true if the constraint should be a master constraint and false otherwise */
761 SCIP* scip, /**< SCIP data structure */
762 SCIP_CONS* cons, /**< constraint to check */
763 SCIP_SETPPCTYPE* setppctype /**< returns the type of the constraints */
764 )
765{
766 SCIP_VAR** vars;
767 SCIP_Real* vals;
768 int i;
769
770 int nvars;
771 SCIP_Bool relevant = TRUE;
772 assert(scip != NULL);
773 assert(cons != NULL);
774 assert(setppctype != NULL);
775
776 *setppctype = SCIP_SETPPCTYPE_PACKING;
777 SCIPdebugMessage("cons %s is ", SCIPconsGetName(cons));
778
780 {
781 SCIPdebugPrintf("setcov, part or logicor.\n");
782 return TRUE;
783 }
784 nvars = GCGconsGetNVars(scip, cons);
785 vars = NULL;
786 vals = NULL;
787 if( nvars > 0 )
788 {
789 SCIP_CALL_ABORT( SCIPallocBufferArray(scip, &vars, nvars) );
790 SCIP_CALL_ABORT( SCIPallocBufferArray(scip, &vals, nvars) );
791 SCIP_CALL_ABORT( GCGconsGetVars(scip, cons, vars, nvars) );
792 SCIP_CALL_ABORT( GCGconsGetVals(scip, cons, vals, nvars) );
793 }
794
795 /* check vars and vals for integrality */
796 for( i = 0; i < nvars && relevant; ++i )
797 {
798 assert(vars != NULL);
799 assert(vals != NULL);
800
801 if( !SCIPvarIsBinary(vars[i]) )
802 {
803 SCIPdebugPrintf("(%s is not integral) ", SCIPvarGetName(vars[i]) );
804 relevant = FALSE;
805 }
806 if( !SCIPisEQ(scip, vals[i], 1.0) )
807 {
808 SCIPdebugPrintf("(coeff for var %s is %.2f != 1.0) ", SCIPvarGetName(vars[i]), vals[i] );
809 relevant = FALSE;
810 }
811 }
812
813 if( relevant )
814 {
815 SCIP_Real rhs = GCGconsGetRhs(scip, cons);
816 SCIP_Real lhs = GCGconsGetLhs(scip, cons);
817 SCIPdebugPrintf("(lhs %.2f, rhs %.2f)", lhs, rhs);
818
819 if( SCIPisEQ(scip, lhs, 1.0) && SCIPisEQ(scip, rhs, 1.0) )
820 {
821 *setppctype = SCIP_SETPPCTYPE_PARTITIONING;
822 }
823 else if( SCIPisEQ(scip, lhs, 1.0) && SCIPisGE(scip, rhs, nvars*1.0) )
824 {
825 *setppctype = SCIP_SETPPCTYPE_COVERING;
826 }
827 else if( SCIPisLE(scip, lhs, 0.0) && SCIPisEQ(scip, rhs, 1.0) )
828 {
829 *setppctype = SCIP_SETPPCTYPE_PACKING;
830 }
831 else
832 {
833 relevant = FALSE;
834 }
835 }
836
837 /* free temporary data */
840
841 SCIPdebugPrintf("%s master\n", relevant ? "in" : "not in");
842 return relevant;
843}
844
845/** returns true if the constraint should be a master constraint and false otherwise */
847 SCIP* scip, /**< SCIP data structure */
848 SCIP_CONS* cons /**< constraint to check */
849)
850{
851 SCIP_VAR** vars;
852 SCIP_Real* vals;
853 int i;
854
855 int nvars;
856 SCIP_Bool relevant = TRUE;
857 assert(scip != NULL);
858 assert(cons != NULL);
859
860 SCIPdebugMessage("cons %s is ", SCIPconsGetName(cons));
861
862 if( GCGconsGetType(scip, cons) == setpartitioning )
863 {
864 return TRUE;
865 }
866 nvars = GCGconsGetNVars(scip, cons);
867 vars = NULL;
868 vals = NULL;
869 if( nvars > 0 )
870 {
871 SCIP_CALL_ABORT( SCIPallocBufferArray(scip, &vars, nvars) );
872 SCIP_CALL_ABORT( SCIPallocBufferArray(scip, &vals, nvars) );
873 SCIP_CALL_ABORT( GCGconsGetVars(scip, cons, vars, nvars) );
874 SCIP_CALL_ABORT( GCGconsGetVals(scip, cons, vals, nvars) );
875 }
876
877 /* check vars and vals for integrality */
878 for( i = 0; i < nvars && relevant; ++i )
879 {
880 assert(vars != NULL);
881 assert(vals != NULL);
882
883// if( !SCIPvarIsBinary(vars[i]) )
884// {
885// SCIPdebugPrintf("(%s is not integral) ", SCIPvarGetName(vars[i]) );
886// relevant = FALSE;
887// }
888 if( !SCIPisEQ(scip, vals[i], 1.0) )
889 {
890 SCIPdebugPrintf("(coeff for var %s is %.2f != 1.0) ", SCIPvarGetName(vars[i]), vals[i] );
891 relevant = FALSE;
892 }
893 }
894
895 if( relevant )
896 {
897 SCIP_Real rhs = GCGconsGetRhs(scip, cons);
898 SCIP_Real lhs = GCGconsGetLhs(scip, cons);
899 SCIPdebugPrintf("(lhs %.2f, rhs %.2f)", lhs, rhs);
900
901 if(! SCIPisFeasEQ(scip, lhs, rhs) )
902 {
903 relevant = FALSE;
904 }
905 }
906
907 /* free temporary data */
910
911 SCIPdebugPrintf("%s master\n", relevant ? "in" : "not in");
912 return relevant;
913}
914
915
916
917/** returns TRUE or FALSE, depending whether we are in the root node or not */
919 GCG* gcg /**< GCG data structure */
920 )
921{
922 SCIP* scip;
923 assert(gcg != NULL);
926 return TRUE;
927 else
929}
SCIP_VAR * w
#define SCIP_Longint
#define SCIP_Bool
#define SCIP_Real
#define SCIP_CALL_ABORT(x)
#define TRUE
#define FALSE
SCIP_Real SCIPgetDualsolLinear(SCIP *scip, SCIP_CONS *cons)
int SCIPgetNVarsKnapsack(SCIP *scip, SCIP_CONS *cons)
SCIP_Real SCIPgetVbdcoefVarbound(SCIP *scip, SCIP_CONS *cons)
int SCIPgetNVarsLogicor(SCIP *scip, SCIP_CONS *cons)
SCIP_Real SCIPgetRhsLinear(SCIP *scip, SCIP_CONS *cons)
SCIP_VAR ** SCIPgetVarsLinear(SCIP *scip, SCIP_CONS *cons)
SCIP_Real SCIPgetDualfarkasVarbound(SCIP *scip, SCIP_CONS *cons)
SCIP_VAR ** SCIPgetVarsSOS2(SCIP *scip, SCIP_CONS *cons)
SCIP_Real SCIPgetLhsLinear(SCIP *scip, SCIP_CONS *cons)
SCIP_Real SCIPgetDualsolLogicor(SCIP *scip, SCIP_CONS *cons)
int SCIPgetNVarsLinear(SCIP *scip, SCIP_CONS *cons)
SCIP_Real * SCIPgetValsLinear(SCIP *scip, SCIP_CONS *cons)
SCIP_VAR * SCIPgetVbdvarVarbound(SCIP *scip, SCIP_CONS *cons)
int SCIPgetNVarsSetppc(SCIP *scip, SCIP_CONS *cons)
int SCIPgetNVarsSOS2(SCIP *scip, SCIP_CONS *cons)
SCIP_VAR ** SCIPgetVarsSetppc(SCIP *scip, SCIP_CONS *cons)
SCIP_VAR * SCIPgetBinaryVarIndicator(SCIP_CONS *cons)
SCIP_VAR * SCIPgetVarVarbound(SCIP *scip, SCIP_CONS *cons)
SCIP_Real SCIPgetDualfarkasLinear(SCIP *scip, SCIP_CONS *cons)
enum SCIP_SetppcType SCIP_SETPPCTYPE
SCIP_Longint * SCIPgetWeightsKnapsack(SCIP *scip, SCIP_CONS *cons)
SCIP_VAR * SCIPgetSlackVarIndicator(SCIP_CONS *cons)
SCIP_Longint SCIPgetCapacityKnapsack(SCIP *scip, SCIP_CONS *cons)
SCIP_Real SCIPgetLhsVarbound(SCIP *scip, SCIP_CONS *cons)
SCIP_SETPPCTYPE SCIPgetTypeSetppc(SCIP *scip, SCIP_CONS *cons)
SCIP_VAR ** SCIPgetVarsSOS1(SCIP *scip, SCIP_CONS *cons)
SCIP_VAR ** SCIPgetVarsLogicor(SCIP *scip, SCIP_CONS *cons)
SCIP_Real SCIPgetRhsVarbound(SCIP *scip, SCIP_CONS *cons)
SCIP_VAR ** SCIPgetVarsKnapsack(SCIP *scip, SCIP_CONS *cons)
SCIP_Real SCIPgetDualfarkasLogicor(SCIP *scip, SCIP_CONS *cons)
SCIP_Real SCIPgetDualfarkasKnapsack(SCIP *scip, SCIP_CONS *cons)
SCIP_Real SCIPgetDualsolVarbound(SCIP *scip, SCIP_CONS *cons)
int SCIPgetNVarsSOS1(SCIP *scip, SCIP_CONS *cons)
SCIP_Real SCIPgetDualsolSetppc(SCIP *scip, SCIP_CONS *cons)
SCIP_Real SCIPgetDualsolKnapsack(SCIP *scip, SCIP_CONS *cons)
SCIP_Real SCIPgetDualfarkasSetppc(SCIP *scip, SCIP_CONS *cons)
SCIP_SETPPCTYPE_PARTITIONING
SCIP_SETPPCTYPE_COVERING
SCIP_SETPPCTYPE_PACKING
SCIP * GCGgetMasterprob(GCG *gcg)
Definition: gcg.cpp:99
SCIP_STAGE SCIPgetStage(SCIP *scip)
SCIP_Bool GCGisRootNode(GCG *gcg)
Definition: scip_misc.c:918
SCIP_Bool GCGisVarRelevant(SCIP_VAR *var)
Definition: scip_misc.c:42
SCIP_Bool GCGconsIsRanged(SCIP *scip, SCIP_CONS *cons)
Definition: scip_misc.c:741
SCIP_Real GCGconsGetRhs(SCIP *scip, SCIP_CONS *cons)
Definition: scip_misc.c:109
SCIP_Bool GCGgetConsIsCardinalityCons(SCIP *scip, SCIP_CONS *cons)
Definition: scip_misc.c:846
consType GCGconsGetType(SCIP *scip, SCIP_CONS *cons)
Definition: scip_misc.c:52
SCIP_Real GCGconsGetDualsol(SCIP *scip, SCIP_CONS *cons)
Definition: scip_misc.c:367
SCIP_Real GCGconsGetDualfarkas(SCIP *scip, SCIP_CONS *cons)
Definition: scip_misc.c:303
SCIP_Bool GCGgetConsIsSetppc(SCIP *scip, SCIP_CONS *cons, SCIP_SETPPCTYPE *setppctype)
Definition: scip_misc.c:760
SCIP_RETCODE GCGconsGetVars(SCIP *scip, SCIP_CONS *cons, SCIP_VAR **vars, int nvars)
Definition: scip_misc.c:487
SCIP_Real GCGconsGetLhs(SCIP *scip, SCIP_CONS *cons)
Definition: scip_misc.c:207
SCIP_RETCODE GCGconsGetVals(SCIP *scip, SCIP_CONS *cons, SCIP_Real *vals, int nvals)
Definition: scip_misc.c:618
int GCGconsGetNVars(SCIP *scip, SCIP_CONS *cons)
Definition: scip_misc.c:433
void SCIPwarningMessage(SCIP *scip, const char *formatstr,...)
const char * SCIPconshdlrGetName(SCIP_CONSHDLR *conshdlr)
SCIP_CONSHDLR * SCIPconsGetHdlr(SCIP_CONS *cons)
const char * SCIPconsGetName(SCIP_CONS *cons)
#define SCIPallocBufferArray(scip, ptr, num)
#define SCIPfreeBufferArrayNull(scip, ptr)
SCIP_Real SCIPinfinity(SCIP *scip)
SCIP_Bool SCIPisGE(SCIP *scip, SCIP_Real val1, SCIP_Real val2)
SCIP_Bool SCIPisFeasEQ(SCIP *scip, SCIP_Real val1, SCIP_Real val2)
SCIP_Bool SCIPisLE(SCIP *scip, SCIP_Real val1, SCIP_Real val2)
SCIP_Bool SCIPisInfinity(SCIP *scip, SCIP_Real val)
SCIP_Bool SCIPisEQ(SCIP *scip, SCIP_Real val1, SCIP_Real val2)
SCIP_NODE * SCIPgetCurrentNode(SCIP *scip)
SCIP_NODE * SCIPgetRootNode(SCIP *scip)
SCIP_VAR * SCIPvarGetNegatedVar(SCIP_VAR *var)
SCIP_Bool SCIPvarIsActive(SCIP_VAR *var)
SCIP_Bool SCIPvarIsBinary(SCIP_VAR *var)
SCIP_VARSTATUS SCIPvarGetStatus(SCIP_VAR *var)
SCIP_Real SCIPvarGetUbGlobal(SCIP_VAR *var)
const char * SCIPvarGetName(SCIP_VAR *var)
SCIP_Bool SCIPvarIsNegated(SCIP_VAR *var)
#define NULL
#define BMScopyMemoryArray(ptr, source, num)
#define SCIPerrorMessage
#define SCIPdebugMessage
#define SCIPdebugPrintf
various SCIP helper methods
consType
Definition: scip_misc.h:49
@ setcovering
Definition: scip_misc.h:50
@ indicator
Definition: scip_misc.h:51
@ linear
Definition: scip_misc.h:50
@ unknown
Definition: scip_misc.h:51
@ sos2
Definition: scip_misc.h:51
@ sos1
Definition: scip_misc.h:51
@ varbound
Definition: scip_misc.h:50
@ setpartitioning
Definition: scip_misc.h:50
@ setpacking
Definition: scip_misc.h:50
@ logicor
Definition: scip_misc.h:51
@ knapsack
Definition: scip_misc.h:50
Definition: struct_gcg.h:55
SCIP_INVALIDDATA
SCIP_OKAY
enum SCIP_Retcode SCIP_RETCODE
SCIP_STAGE_SOLVING
SCIP_VARSTATUS_FIXED
SCIP_VARSTATUS_MULTAGGR
SCIP_VARSTATUS_NEGATED
SCIP_VARSTATUS_AGGREGATED