Scippy

UG

Ubiquity Generator framework

scipParaInstance.cpp
Go to the documentation of this file.
1/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2/* */
3/* This file is part of the program and software framework */
4/* UG --- Ubquity Generator Framework */
5/* */
6/* Copyright Written by Yuji Shinano <shinano@zib.de>, */
7/* Copyright (C) 2021-2024 by Zuse Institute Berlin, */
8/* licensed under LGPL version 3 or later. */
9/* Commercial licenses are available through <licenses@zib.de> */
10/* */
11/* This code is free software; you can redistribute it and/or */
12/* modify it under the terms of the GNU Lesser General Public License */
13/* as published by the Free Software Foundation; either version 3 */
14/* of the License, or (at your option) any later version. */
15/* */
16/* This program is distributed in the hope that it will be useful, */
17/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
18/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
19/* GNU Lesser General Public License for more details. */
20/* */
21/* You should have received a copy of the GNU Lesser General Public License */
22/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
23/* */
24/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
25
26/**@file scipParaInstance.cpp
27 * @brief ParaInstance extenstion for SCIP solver.
28 * @author Yuji Shinano
29 *
30 *
31 *
32 */
33
34/*---+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0----+----1----+----2*/
35
36
37#include <cstdlib>
38#include <cassert>
39#include <cstring>
40#include <cctype>
41#ifdef _MSC_VER
42#include <direct.h> //this is for _getcwd()
43#define getcwd(X, Y) _getcwd(X, Y)
44#else
45#include <unistd.h>
46#endif
47#include "ug/paraDef.h"
49#include "scip/scipdefplugins.h"
50#include "scip/reader_lp.h"
51#include "scip/cons_knapsack.h"
52#include "scip/cons_linear.h"
53#include "scip/cons_logicor.h"
54#include "scip/cons_setppc.h"
55#include "scip/cons_varbound.h"
56#include "scip/cons_bounddisjunction.h"
57#include "scip/cons_sos1.h"
58#include "scip/cons_sos2.h"
59#include "scip/pub_misc.h"
60#include "scipParaInstance.h"
61
62using namespace ParaSCIP;
63
64const static char *PRESOLVED_INSTANCE = "presolved.cip";
65
66/** hash key retrieval function for variables */
67static
69{ /*lint --e{715}*/
70 return elem;
71}
72
73/** returns TRUE iff the indices of both variables are equal */
74static
76{ /*lint --e{715}*/
77 if ( key1 == key2 )
78 return TRUE;
79 return FALSE;
80}
81
82/** returns the hash value of the key */
83static
85{ /*lint --e{715}*/
86 assert( SCIPvarGetIndex((SCIP_VAR*) key) >= 0 );
87 return (unsigned int) SCIPvarGetIndex((SCIP_VAR*) key);
88}
89
90void
91ScipParaInstance::allocateMemoryForOrdinaryConstraints(
92 )
93{
94 /** for linear constraints */
95 if( nLinearConss > 0 )
96 {
98 linearLhss = new SCIP_Real[nLinearConss];
99 linearRhss = new SCIP_Real[nLinearConss];
100 nLinearCoefs = new int[nLinearConss];
101 linearCoefs = new SCIP_Real*[nLinearConss];
103 }
104 /** for setppc constraints */
105 if( nSetppcConss )
106 {
108 nIdxSetppcVars = new int[nSetppcConss];
109 setppcTypes = new int[nSetppcConss];
110 idxSetppcVars = new int*[nSetppcConss];
111 }
112 /** for logical constraints */
113 if(nLogicorConss)
114 {
117 idxLogicorVars = new int*[nLogicorConss];
118 }
119 /** for knapsack constraints */
121 {
123 capacities = new SCIP_Longint[nKnapsackConss];
125 knapsackCoefs = new SCIP_Longint*[nKnapsackConss];
127 }
128 /** for varbound constraints */
129 if( nVarboundConss ){
131 varboundLhss = new SCIP_Real[nVarboundConss];
132 varboundRhss = new SCIP_Real[nVarboundConss];
134 varboundCoef2s = new SCIP_Real[nVarboundConss];
136 }
137 /** for bounddisjunction constraints */
139abort();
145 }
146 /** for SOS1 constraints */
147 if( nSos1Conss ){
148 idxSos1ConsNames = new int[nSos1Conss];
149 nSos1Coefs = new int[nSos1Conss];
150 sos1Coefs = new SCIP_Real*[nSos1Conss];
151 idxSos1CoefsVars = new int*[nSos1Conss];
152 }
153 /** for SOS2 constraints */
154 if( nSos2Conss ){
155 idxSos2ConsNames = new int[nSos2Conss];
156 nSos2Coefs = new int[nSos2Conss];
157 sos2Coefs = new SCIP_Real*[nSos2Conss];
158 idxSos2CoefsVars = new int*[nSos2Conss];
159 }
160}
161
162void
164 int c,
165 SCIP_CONS *cons
166 )
167{
169 (void) strcpy( &consNames[lConsNames], SCIPconsGetName(cons) );
170 lConsNames += strlen( SCIPconsGetName(cons) )+ 1;
171}
172
173void
175 SCIP *scip,
176 int c,
177 SCIP_CONS *cons
178 )
179{
182 linearLhss[nLinearConss] = SCIPgetLhsLinear(scip, cons);
183 linearRhss[nLinearConss] = SCIPgetRhsLinear(scip, cons);
184 int nvars = SCIPgetNVarsLinear(scip, cons);
185 nLinearCoefs[nLinearConss] = nvars;
186 linearCoefs[nLinearConss] = new SCIP_Real[nvars];
187 idxLinearCoefsVars[nLinearConss] = new int[nvars];
188 SCIP_Real *coefs = SCIPgetValsLinear(scip, cons);
189 SCIP_VAR **vars = SCIPgetVarsLinear(scip, cons);
190 for(int v = 0; v < nvars; ++v)
191 {
192 linearCoefs[nLinearConss][v] = coefs[v];
193 idxLinearCoefsVars[nLinearConss][v] = SCIPvarGetProbindex(vars[v]);
194 }
195 nLinearConss++;
196}
197
198void
200 SCIP *scip
201 )
202{
203 SCIP_VAR **vars = SCIPgetVars(scip);
204 for(int c = 0; c < nLinearConss; ++c )
205 {
206 SCIP_CONS* cons;
207 SCIP_VAR **varsInCons = new SCIP_VAR*[nLinearCoefs[c]];
208 for( int v = 0; v < nLinearCoefs[c]; v++)
209 {
210 varsInCons[v] = vars[idxLinearCoefsVars[c][v]];
211 }
212 SCIP_CALL_ABORT( SCIPcreateConsLinear(scip, &cons,
214 TRUE, TRUE, TRUE, TRUE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE) );
215 SCIP_CALL_ABORT( SCIPaddCons(scip, cons) );
216 SCIPdebug( SCIP_CALL_ABORT( SCIPprintCons(scip, cons, NULL) ) );
217 SCIP_CALL_ABORT( SCIPreleaseCons(scip, &cons) );
218 delete [] varsInCons;
219 }
220}
221
222/*************************************************************/
223/*** NOTE: setSetppcConstraint routine cannot work correctly */
224/*************************************************************/
225void
227 SCIP *scip,
228 int c,
229 SCIP_CONS *cons
230 )
231{
234 int nvars = SCIPgetNVarsSetppc(scip,cons);
236 setppcTypes[nSetppcConss] = SCIPgetTypeSetppc(scip,cons);
237 idxSetppcVars[nSetppcConss] = new int[nvars];
238 SCIP_VAR **vars = SCIPgetVarsSetppc(scip, cons);
239 for( int v = 0; v < nvars; ++v)
240 {
241 idxSetppcVars[nSetppcConss][v] = SCIPvarGetProbindex(vars[v]);
242 }
243 nSetppcConss++;
244}
245
246void
248 SCIP *scip
249 )
250{
251 SCIP_VAR **vars = SCIPgetVars(scip);
252 for(int c = 0; c < nSetppcConss; ++c )
253 {
254 SCIP_CONS* cons;
255 SCIP_VAR **varsInCons = new SCIP_VAR*[nIdxSetppcVars[c]];
256 for( int v = 0; v < nIdxSetppcVars[c]; v++)
257 {
258 varsInCons[v] = vars[idxSetppcVars[c][v]];
259 }
260 switch (setppcTypes[c])
261 {
262 case SCIP_SETPPCTYPE_PARTITIONING:
263 SCIP_CALL_ABORT( SCIPcreateConsSetpart(scip, &cons,
265 TRUE, TRUE, TRUE, TRUE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE) );
266 break;
267 case SCIP_SETPPCTYPE_PACKING:
268 SCIP_CALL_ABORT( SCIPcreateConsSetpack(scip, &cons,
270 TRUE, TRUE, TRUE, TRUE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE) );
271 break;
272 case SCIP_SETPPCTYPE_COVERING:
273 SCIP_CALL_ABORT( SCIPcreateConsSetcover(scip, &cons,
275 TRUE, TRUE, TRUE, TRUE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE) );
276 break;
277 default:
278 THROW_LOGICAL_ERROR2("invalid setppc constraint type: type = ", setppcTypes[c]);
279 }
280 SCIP_CALL_ABORT( SCIPaddCons(scip, cons) );
281 SCIPdebug( SCIP_CALL_ABORT( SCIPprintCons(scip, cons, NULL) ) );
282 SCIP_CALL_ABORT( SCIPreleaseCons(scip, &cons) );
283 delete [] varsInCons;
284 }
285}
286
287/**************************************************************/
288/*** NOTE: setLogicorConstraint routine cannot work correctly */
289/**************************************************************/
290void
292 SCIP *scip,
293 int c,
294 SCIP_CONS *cons
295 )
296{
299 int nvars = SCIPgetNVarsLogicor(scip, cons);
301 idxLogicorVars[nLogicorConss] = new int[nvars];
302
303 SCIP_VAR **vars = SCIPgetVarsLogicor(scip, cons);
304 for( int v = 0; v < nvars; ++v )
305 {
306 if( SCIPvarIsActive(vars[v]) )
307 idxLogicorVars[nLogicorConss][v] = SCIPvarGetProbindex(vars[v]);
308 else if( SCIPvarIsNegated(vars[v]) )
309 idxLogicorVars[nLogicorConss][v] = -SCIPvarGetProbindex(SCIPvarGetNegationVar(vars[v])) - 1;
310 else
311 idxLogicorVars[nLogicorConss][v] = INT_MAX;
312 }
314}
315
316void
318 SCIP *scip
319 )
320{
321 SCIP_VAR **vars = SCIPgetVars(scip);
322 for(int c = 0; c < nLogicorConss; ++c )
323 {
324 SCIP_CONS* cons;
325 SCIP_VAR **varsInCons = new SCIP_VAR*[nIdxLogicorVars[c]];
326 int v;
327 for( v = 0; v < nIdxLogicorVars[c]; v++)
328 {
329 if( idxLogicorVars[c][v] == INT_MAX )
330 break;
331 /* negated variable */
332 if( idxLogicorVars[c][v] < 0 )
333 {
334 SCIP_CALL_ABORT( SCIPgetNegatedVar(scip, vars[-(idxLogicorVars[c][v] + 1)], &varsInCons[v]) );
335 }
336 else
337 varsInCons[v] = vars[idxLogicorVars[c][v]];
338 }
339 if( v == nIdxLogicorVars[c] )
340 {
341 SCIP_CALL_ABORT( SCIPcreateConsLogicor(scip, &cons,
343 TRUE, FALSE, FALSE, FALSE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE) );
344 SCIP_CALL_ABORT( SCIPaddCons(scip, cons) );
345 SCIPdebug( SCIP_CALL_ABORT( SCIPprintCons(scip, cons, NULL) ) );
346 SCIP_CALL_ABORT( SCIPreleaseCons(scip, &cons) );
347 }
348 delete [] varsInCons;
349 }
350}
351
352/***************************************************************/
353/*** NOTE: setKnapsackConstraint routine cannot work correctly */
354/***************************************************************/
355void
357 SCIP *scip,
358 int c,
359 SCIP_CONS *cons
360 )
361{
364 capacities[nKnapsackConss] = SCIPgetCapacityKnapsack(scip, cons);
365 int nvars = SCIPgetNVarsKnapsack(scip, cons);
367 knapsackCoefs[nKnapsackConss] = new SCIP_Longint[nvars];
368 idxKnapsackCoefsVars[nKnapsackConss] = new int[nvars];
369 SCIP_Longint *weights = SCIPgetWeightsKnapsack(scip, cons);
370 SCIP_VAR **vars = SCIPgetVarsKnapsack(scip,cons);
371 for(int v = 0; v < nvars; ++v )
372 {
373 knapsackCoefs[nKnapsackConss][v] = weights[v];
374 idxKnapsackCoefsVars[nKnapsackConss][v] = SCIPvarGetProbindex(vars[v]);
375 }
377}
378
379
380void
382 SCIP *scip
383 )
384{
385 SCIP_VAR **vars = SCIPgetVars(scip);
386 for(int c = 0; c < nKnapsackConss; ++c )
387 {
388 SCIP_CONS* cons;
389 SCIP_VAR **varsInCons = new SCIP_VAR*[nLKnapsackCoefs[c]];
390 for( int v = 0; v < nLKnapsackCoefs[c]; v++)
391 {
392 varsInCons[v] = vars[idxKnapsackCoefsVars[c][v]];
393 }
394 SCIP_CALL_ABORT( SCIPcreateConsKnapsack(scip, &cons,
396 TRUE, TRUE, TRUE, TRUE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE) );
397 SCIP_CALL_ABORT( SCIPaddCons(scip, cons) );
398 SCIPdebug( SCIP_CALL_ABORT( SCIPprintCons(scip, cons, NULL) ) );
399 SCIP_CALL_ABORT( SCIPreleaseCons(scip, &cons) );
400 delete [] varsInCons;
401 }
402}
403
404/***************************************************************/
405/*** NOTE: setVarboundConstraint routine cannot work correctly */
406/***************************************************************/
407void
409 SCIP *scip,
410 int c,
411 SCIP_CONS *cons
412 )
413{
416 varboundLhss[nVarboundConss] = SCIPgetLhsVarbound(scip,cons);
417 varboundRhss[nVarboundConss] = SCIPgetRhsVarbound(scip,cons);
418 idxVarboundCoefVar1s[nVarboundConss] = SCIPvarGetProbindex(SCIPgetVarVarbound(scip,cons));
419 varboundCoef2s[nVarboundConss] = SCIPgetVbdcoefVarbound(scip,cons);
420 idxVarboundCoefVar2s[nVarboundConss] = SCIPvarGetProbindex(SCIPgetVbdvarVarbound(scip,cons));
422}
423
424void
426 SCIP *scip
427 )
428{
429 SCIP_VAR **vars = SCIPgetVars(scip);
430 for(int c = 0; c < nVarboundConss; ++c )
431 {
432 SCIP_CONS* cons;
433 SCIP_VAR *var1InCons = vars[idxVarboundCoefVar1s[c]];
434 SCIP_VAR *var2InCons = vars[idxVarboundCoefVar2s[c]];
435 SCIP_CALL_ABORT( SCIPcreateConsVarbound(scip, &cons,
436 &consNames[posConsNames[idxVarboundConsNames[c]]], var1InCons, var2InCons, varboundCoef2s[c], varboundLhss[c], varboundRhss[c],
437 TRUE, TRUE, TRUE, TRUE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE) );
438 SCIP_CALL_ABORT( SCIPaddCons(scip, cons) );
439 SCIPdebug( SCIP_CALL_ABORT( SCIPprintCons(scip, cons, NULL) ) );
440 SCIP_CALL_ABORT( SCIPreleaseCons(scip, &cons) );
441 }
442}
443
444/***************************************************************/
445/*** NOTE: setVarboundConstraint routine cannot work correctly */
446/***************************************************************/
447void
449 SCIP *scip,
450 int c,
451 SCIP_CONS *cons
452 )
453{
456 nVarsBoundDisjunction[nVarBoundDisjunctionConss] = SCIPgetNVarsBounddisjunction(scip,cons);
460 SCIP_VAR **vars = SCIPgetVarsBounddisjunction ( scip, cons );
461 SCIP_BOUNDTYPE *boundTypes = SCIPgetBoundtypesBounddisjunction( scip, cons );
462 SCIP_Real *bounds = SCIPgetBoundsBounddisjunction( scip, cons );
463 for( int v = 0; v < nVarsBoundDisjunction[nVarBoundDisjunctionConss]; ++v )
464 {
465 idxVarBoundDisjunction[nVarBoundDisjunctionConss][v] = SCIPvarGetProbindex(vars[v]);
468 }
470}
471
472void
474 SCIP *scip
475 )
476{
477 SCIP_VAR **vars = SCIPgetVars(scip);
478 for(int c = 0; c < nVarBoundDisjunctionConss; ++c )
479 {
480 SCIP_CONS* cons;
481 SCIP_VAR **boundVars = new SCIP_VAR*[nVarsBoundDisjunction[c]];
482 SCIP_BOUNDTYPE *types = new SCIP_BOUNDTYPE[nVarsBoundDisjunction[c]];
483 for( int v = 0; v < nVarsBoundDisjunction[c]; ++v )
484 {
485 boundVars[v] = vars[idxVarBoundDisjunction[c][v]];
486 types[v] = boundTypesBoundDisjunction[c][v];
487 }
488
489 SCIP_CALL_ABORT( SCIPcreateConsBounddisjunction(scip, &cons,
491 types, boundsBoundDisjunction[c],
492 TRUE, TRUE, TRUE, TRUE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE) );
493 SCIP_CALL_ABORT( SCIPaddCons(scip, cons) );
494 SCIPdebug( SCIP_CALL_ABORT( SCIPprintCons(scip, cons, NULL) ) );
495 SCIP_CALL_ABORT( SCIPreleaseCons(scip, &cons) );
496 delete [] boundVars;
497 delete [] types;
498 }
499}
500
501void
503 SCIP *scip,
504 int c,
505 SCIP_CONS *cons,
506 SCIP_CONS** consSOS1
507 )
508{
511 int nvars = SCIPgetNVarsSOS1(scip, cons);
512 nSos1Coefs[nSos1Conss] = nvars;
513 sos1Coefs[nSos1Conss] = new SCIP_Real[nvars];
514 idxSos1CoefsVars[nSos1Conss] = new int[nvars];
515 SCIP_Real *weights = SCIPgetWeightsSOS1(scip, cons);
516 SCIP_VAR **vars = SCIPgetVarsSOS1(scip,cons);
517 for( int v = 0; v < nvars; v++ )
518 {
519 sos1Coefs[nSos1Conss][v] = weights[v];
520 idxSos1CoefsVars[nSos1Conss][v] = SCIPvarGetProbindex(vars[v]);
521 }
522 // store constraint
523 consSOS1[nSos1Conss++] = cons;
524}
525
526void
528 SCIP *scip
529 )
530{
531 SCIP_VAR **vars = SCIPgetVars(scip);
532 for(int c = 0; c < nSos1Conss; ++c )
533 {
534 SCIP_CONS* cons;
535 SCIP_VAR **varsInCons = new SCIP_VAR*[nSos1Coefs[c]];
536 for( int v = 0; v < nSos1Coefs[c]; v++)
537 {
538 varsInCons[v] = vars[idxSos1CoefsVars[c][v]];
539 }
540 SCIP_CALL_ABORT( SCIPcreateConsSOS1(scip, &cons,
542 TRUE, TRUE, TRUE, TRUE, TRUE, FALSE, FALSE, FALSE, FALSE ) );
543 SCIP_CALL_ABORT( SCIPaddCons(scip, cons) );
544 SCIPdebug( SCIP_CALL_ABORT( SCIPprintCons(scip, cons, NULL) ) );
545 SCIP_CALL_ABORT( SCIPreleaseCons(scip, &cons) );
546 delete [] varsInCons;
547 }
548}
549
550void
552 SCIP *scip,
553 int c,
554 SCIP_CONS *cons,
555 SCIP_CONS** consSOS2
556 )
557{
560 int nvars = SCIPgetNVarsSOS2(scip, cons);
561 nSos2Coefs[nSos2Conss] = nvars;
562 sos2Coefs[nSos2Conss] = new SCIP_Real[nvars];
563 idxSos2CoefsVars[nSos2Conss] = new int[nvars];
564 SCIP_Real *weights = SCIPgetWeightsSOS2(scip, cons);
565 SCIP_VAR **vars = SCIPgetVarsSOS2(scip,cons);
566 for( int v = 0; v < nvars; v++ )
567 {
568 sos2Coefs[nSos2Conss][v] = weights[v];
569 idxSos2CoefsVars[nSos2Conss][v] = SCIPvarGetProbindex(vars[v]);
570 }
571 // store constraint
572 consSOS2[nSos2Conss++] = cons;
573}
574
575void
577 SCIP *scip
578 )
579{
580 SCIP_VAR **vars = SCIPgetVars(scip);
581 for(int c = 0; c < nSos2Conss; ++c )
582 {
583 SCIP_CONS* cons;
584 SCIP_VAR **varsInCons = new SCIP_VAR*[nSos2Coefs[c]];
585 for( int v = 0; v < nSos2Coefs[c]; v++)
586 {
587 varsInCons[v] = vars[idxSos2CoefsVars[c][v]];
588 }
589 SCIP_CALL_ABORT( SCIPcreateConsSOS2(scip, &cons,
591 TRUE, TRUE, TRUE, TRUE, TRUE, FALSE, FALSE, FALSE, FALSE ) );
592 SCIP_CALL_ABORT( SCIPaddCons(scip, cons) );
593 SCIPdebug( SCIP_CALL_ABORT( SCIPprintCons(scip, cons, NULL) ) );
594 SCIP_CALL_ABORT( SCIPreleaseCons(scip, &cons) );
595 delete [] varsInCons;
596 }
597}
598
599/***********************************************************************************************
600 * getActiveVariables is copied from read_lp.c of SCIP code
601 */
602void
604 SCIP* scip, /**< SCIP data structure */
605 SCIP_VAR** vars, /**< vars array to get active variables for */
606 SCIP_Real* scalars, /**< scalars a_1, ..., a_n in linear sum a_1*x_1 + ... + a_n*x_n + c */
607 int* nvars, /**< pointer to number of variables and values in vars and vals array */
608 SCIP_Real* constant, /**< pointer to constant c in linear sum a_1*x_1 + ... + a_n*x_n + c */
609 SCIP_Bool transformed /**< transformed constraint? */
610 )
611{
612 int requiredsize;
613 int v;
614
615 assert( scip != NULL );
616 assert( vars != NULL );
617 assert( scalars != NULL );
618 assert( nvars != NULL );
619 assert( constant != NULL );
620
621 if( transformed )
622 {
623 SCIP_CALL_ABORT( SCIPgetProbvarLinearSum(scip, vars, scalars, nvars, *nvars, constant, &requiredsize, TRUE) );
624
625 if( requiredsize > *nvars )
626 {
627 *nvars = requiredsize;
628 SCIP_CALL_ABORT( SCIPreallocBufferArray(scip, &vars, *nvars ) );
629 SCIP_CALL_ABORT( SCIPreallocBufferArray(scip, &scalars, *nvars ) );
630
631 SCIP_CALL_ABORT( SCIPgetProbvarLinearSum(scip, vars, scalars, nvars, *nvars, constant, &requiredsize, TRUE) );
632 assert( requiredsize <= *nvars );
633 }
634 }
635 else
636 {
637 for( v = 0; v < *nvars; ++v )
638 SCIP_CALL_ABORT( SCIPvarGetOrigvarSum(&vars[v], &scalars[v], constant) );
639 }
640}
641
642/***********************************************************************************************
643 * collectAggregatedVars is copied from read_lp.c of SCIP code
644 */
645void
647 SCIP* scip, /**< SCIP data structure */
648 int nvars, /**< number of mutable variables in the problem */
649 SCIP_VAR** vars, /**< variable array */
650 int* nAggregatedVars, /**< number of aggregated variables on output */
651 SCIP_VAR*** aggregatedVars, /**< array storing the aggregated variables on output */
652 SCIP_HASHTABLE** varAggregated /**< hashtable for checking duplicates */
653 )
654{
655 int j;
656
657 /* check variables */
658 for (j = 0; j < nvars; ++j)
659 {
660 SCIP_VARSTATUS status;
661 SCIP_VAR* var;
662
663 var = vars[j];
664 status = SCIPvarGetStatus(var);
665
666 /* collect aggregated variables in a list */
667 if( status >= SCIP_VARSTATUS_AGGREGATED )
668 {
669 assert( status == SCIP_VARSTATUS_AGGREGATED ||
670 status == SCIP_VARSTATUS_MULTAGGR ||
671 status == SCIP_VARSTATUS_NEGATED );
672
673 if ( ! SCIPhashtableExists(*varAggregated, (void*) var) )
674 {
675 (*aggregatedVars)[(*nAggregatedVars)++] = var;
676 SCIP_CALL_ABORT( SCIPhashtableInsert(*varAggregated, (void*) var) );
677 }
678 }
679 }
680}
681
682void
684 SCIP* scip, /**< SCIP data structure */
685 int c, /** aggregated constraint number */
686 const char* constName, /**< constraint name */
687 SCIP_VAR** vars, /**< array of variables */
688 SCIP_Real* vals, /**< array of values */
689 int nvars, /**< number of variables */
690 SCIP_Real lhsAndrhs /**< right hand side = left hand side */
691 )
692{
694 (void) strcpy( &aggregatedVarNames[lAggregatedVarNames], SCIPvarGetName(vars[c]) );
695 lAggregatedVarNames += strlen( SCIPvarGetName(vars[c]) );
696
698 (void) strcpy( &aggregatedConsNames[lAggregatedConsNames], constName );
699 lAggregatedConsNames += strlen( constName )+ 1;
700
701 aggregatedLhsAndLhss[c] = lhsAndrhs;
702 nAggregatedCoefs[c] = nvars;
703 int v;
704 for(v = 0; v < nvars - 1; ++v)
705 {
706 aggregatedCoefs[nLinearConss][v] = vals[v];
707 idxLinearCoefsVars[nLinearConss][v] = SCIPvarGetProbindex(vars[v]);
708 }
709 aggregatedCoefs[nLinearConss][v] = vals[v];
712}
713
714void
716 SCIP* scip, /**< SCIP data structure */
717 int nvars, /**< number of mutable variables in the problem */
718 int nAggregatedVars, /**< number of aggregated variables */
719 SCIP_VAR** aggregatedVars /**< array storing the aggregated variables */
720 )
721{
722 SCIP_VAR** activevars;
723 SCIP_Real* activevals;
724 int nactivevars;
725 SCIP_Real activeconstant = 0.0;
726 char consname[UG::LpMaxNamelen];
727
728 assert( scip != NULL );
729
730 /* write aggregation constraints */
731 SCIP_CALL_ABORT( SCIPallocBufferArray(scip, &activevars, nvars) );
732 SCIP_CALL_ABORT( SCIPallocBufferArray(scip, &activevals, nvars) );
733
734 /* compute lengths of aggregatedVarNames and aggregatedConsNames areas */
737 for( int j = 0; j < nAggregatedVars; j++ )
738 {
739 lAggregatedVarNames += strlen(SCIPvarGetName(aggregatedVars[j])) + 1;
740 (void) SCIPsnprintf(consname, UG::LpMaxNamelen, "aggr_%s", SCIPvarGetName(aggregatedVars[j]));
741 lAggregatedConsNames += strlen(consname) + 1;
742 }
743
744 if( nAggregatedVars )
745 {
746 /* allocate aggregatedVarNames and aggregatedConsNames areas */
749 }
750
751 /* set aggregated constraints */
755 for (int j = 0; j < nAggregatedVars; ++j)
756 {
757 /* set up list to obtain substitution variables */
758 nactivevars = 1;
759
760 activevars[0] = aggregatedVars[j];
761 activevals[0] = 1.0;
762 activeconstant = 0.0;
763
764 /* retransform given variables to active variables */
765 getActiveVariables(scip, activevars, activevals, &nactivevars, &activeconstant, TRUE);
766
767 activevals[nactivevars] = -1.0;
768 activevars[nactivevars] = aggregatedVars[j];
769 ++nactivevars;
770
771 /* set constraint */
772 (void) SCIPsnprintf(consname, UG::LpMaxNamelen, "aggr_%s", SCIPvarGetName(aggregatedVars[j]));
773 setAggregatedConstraint(scip, j, consname, activevars, activevals, nactivevars, - activeconstant );
774 }
775 assert(nAggregatedConss == nAggregatedVars);
776
777 /* free buffer arrays */
778 SCIPfreeBufferArray(scip, &activevars);
779 SCIPfreeBufferArray(scip, &activevals);
780}
781
782void
784 SCIP *scip
785 )
786{
787 SCIP_VAR **vars = SCIPgetVars(scip);
788 for(int c = 0; c < nAggregatedConss; ++c )
789 {
790 SCIP_CONS* cons;
791 SCIP_VAR **varsInCons = new SCIP_VAR*[nAggregatedCoefs[c]];
792 int v;
793 for( v = 0; v < nAggregatedCoefs[c] - 1; v++)
794 {
795 varsInCons[v] = vars[idxAggregatedCoefsVars[c][v]];
796 }
797 SCIP_VAR* newvar;
798 /* create new variable of the given name */
799 SCIP_CALL_ABORT( SCIPcreateVar(scip, &newvar, &aggregatedVarNames[posAggregatedVarNames[c]], 0.0, 1.0, 0.0, SCIP_VARTYPE_BINARY,
800 TRUE, FALSE, NULL, NULL, NULL, NULL, NULL) );
801 SCIP_CALL_ABORT( SCIPaddVar(scip, newvar) );
802 /* because the variable was added to the problem, it is captured by SCIP and we can safely release it right now
803 * without making the returned *var invalid
804 */
805 varsInCons[v] = newvar;
806 assert( SCIPvarGetProbindex(newvar) == (nVars + c) );
807 SCIP_CALL_ABORT( SCIPreleaseVar(scip, &newvar) );
808
809 SCIP_CALL_ABORT( SCIPcreateConsLinear(scip, &cons,
811 TRUE, TRUE, TRUE, TRUE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE) );
812 SCIP_CALL_ABORT( SCIPaddCons(scip, cons) );
813 SCIPdebug( SCIP_CALL_ABORT( SCIPprintCons(scip, cons, NULL) ) );
814 SCIP_CALL_ABORT( SCIPreleaseCons(scip, &cons) );
815 delete [] varsInCons;
816 }
817}
818
819/** constractor : only called from ScipInitiator */
821 SCIP *scip,
822 int method
823 ) : orgScip(0), paraInstanceScip(0), lProbName(0), probName(0), nCopies(0), origObjSense(0), objScale(0.0), objOffset(0.0), nVars(0), varIndexRange(0),
824 varLbs(0), varUbs(0), objCoefs(0), varTypes(0), lVarNames(0), varNames(0),
825 posVarNames(0), mapToOriginalIndecies(0), mapToSolverLocalIndecies(0), // mapToProbIndecies(0),
826 nConss(0), lConsNames(0), consNames(0),
827 posConsNames(0), copyIncreasedVariables(false),
828 nLinearConss(0), idxLinearConsNames(0), linearLhss(0),
829 linearRhss(0), nLinearCoefs(0), linearCoefs(0), idxLinearCoefsVars(0),
830 nSetppcConss(0), idxSetppcConsNames(0), nIdxSetppcVars(0), setppcTypes(0),
831 idxSetppcVars(0), nLogicorConss(0), idxLogicorConsNames(0), nIdxLogicorVars(0), idxLogicorVars(0),
832 nKnapsackConss(0), idxKnapsackConsNames(0), capacities(0), nLKnapsackCoefs(0),
833 knapsackCoefs(0), idxKnapsackCoefsVars(0),
834 nVarboundConss(0), idxVarboundConsNames(0), varboundLhss(0),varboundRhss(0), idxVarboundCoefVar1s(0),
835 varboundCoef2s(0), idxVarboundCoefVar2s(0),
836 nVarBoundDisjunctionConss(0), idxBoundDisjunctionConsNames(0), nVarsBoundDisjunction(0),
837 idxVarBoundDisjunction(0), boundTypesBoundDisjunction(0), boundsBoundDisjunction(0),
838 nSos1Conss(0),idxSos1ConsNames(0), nSos1Coefs(0), sos1Coefs(0), idxSos1CoefsVars(0),
839 nSos2Conss(0), idxSos2ConsNames(0), nSos2Coefs(0), sos2Coefs(0), idxSos2CoefsVars(0),
840 nAggregatedConss(0), lAggregatedVarNames(0), aggregatedVarNames(0), posAggregatedVarNames(0),
841 lAggregatedConsNames(0), aggregatedConsNames(0), posAggregatedConsNames(0),
842 aggregatedLhsAndLhss(0), nAggregatedCoefs(0), aggregatedCoefs(0), idxAggregatedCoefsVars(0),
843 userPlugins(0)
844{
845 assert( scip != NULL );
846 assert( SCIPgetStage(scip) == SCIP_STAGE_TRANSFORMED ||
847 SCIPgetStage(scip) == SCIP_STAGE_PRESOLVED ||
848 SCIPgetStage(scip) == SCIP_STAGE_SOLVING ||
849 SCIPgetStage(scip) == SCIP_STAGE_SOLVED ); // in case that presolving or root node solving solved the problem
850
851 // assert( SCIPgetStage(scip) == SCIP_STAGE_PRESOLVED ||
852 // SCIPgetStage(scip) == SCIP_STAGE_SOLVING ||
853 // SCIPgetStage(scip) == SCIP_STAGE_SOLVED ); // in case that presolving or root node solving solved the problem
854
855 lProbName = strlen(SCIPgetProbName(scip));
856 probName = new char[lProbName+1];
857 strcpy(probName, SCIPgetProbName(scip));
858
859 /** set objsen */
860 origObjSense = SCIPgetObjsense(scip); // always minimization problem
861 objScale = SCIPgetTransObjscale(scip); // Stefan is making now
862 objOffset = SCIPgetTransObjoffset(scip); // Stefan is making now
863
865
866 if( SCIPgetStage(scip) == SCIP_STAGE_TRANSFORMED || SCIPgetStage(scip) == SCIP_STAGE_SOLVED ) return;
867
868 if( method == 2 )
869 {
870 return; // Solver reads given instance file.
871 }
872
873 // if( method == 0 || method == 2 )
874 if( method == 0 )
875 {
876 nVars = SCIPgetNVars(scip);
878 SCIP_VAR **vars = SCIPgetVars(scip);
879
880 /* make varName and objCoefs and ovnm */
881 posVarNames = new int[nVars];
882 objCoefs = new SCIP_Real[nVars];
883 // mapToOriginalIndecies = new int[nVars];
884
885 lVarNames = 0;
886 for(int v = 0; v < nVars; ++v)
887 {
889 objCoefs[v] = SCIPvarGetObj(vars[v]);
890 assert(SCIPvarGetProbindex(vars[v])!=-1);
891 assert(SCIPvarGetProbindex(vars[v]) == v);
892 lVarNames += strlen(SCIPvarGetName(vars[v])) + 1;
893 }
894 varNames = new char[lVarNames];
895 varLbs = new SCIP_Real[nVars];
896 varUbs = new SCIP_Real[nVars];
897 varTypes = new int[nVars];
898 for(int v = 0; v < nVars; ++v )
899 {
900 SCIP_VAR *var = vars[v];
901 strcpy (&varNames[posVarNames[v]], SCIPvarGetName(var) );
902 varLbs[SCIPvarGetProbindex(var)] = SCIPvarGetLbLocal(var); //* we should use global?
903 varUbs[SCIPvarGetProbindex(var)] = SCIPvarGetUbLocal(var); //* we should use global?
904 varTypes[SCIPvarGetProbindex(var)] = SCIPvarGetType(var);
905 }
906
907 /*
908 if( method == 2 )
909 {
910 return; // Solver reads given instance file.
911 }
912 */
913
914 /* make constraints */
915 nConss = SCIPgetNConss(scip);
916 SCIP_CONS **conss = SCIPgetConss(scip);
917
918 if( nConss > 0 )
919 {
920 posConsNames = new int[nConss];
921 }
922 int tempSizeConsNames = 0;
923 /* make consNames map */
924 for( int c = 0; c < nConss; c++ )
925 {
926 tempSizeConsNames += strlen(SCIPconsGetName(conss[c])) + 1;
927 }
928 if( tempSizeConsNames > 0 )
929 {
930 consNames = new char[tempSizeConsNames];
931 }
932
933 SCIP_CONS** consSOS1;
934 SCIP_CONS** consSOS2;
935 nSos1Conss = 0;
936 nSos2Conss = 0;
937
938 /** collect SOS constraints in array for later output */
939 SCIP_CALL_ABORT( SCIPallocBufferArray(scip, &consSOS1, nConss) );
940 SCIP_CALL_ABORT( SCIPallocBufferArray(scip, &consSOS2, nConss) );
941
942 SCIP_CONS *cons;
943 const char* conshdlrname;
944 SCIP_CONSHDLR* conshdlr;
945
946 int nNotInitialActiveConss = 0;
947
948 /** count number of each constraint */
949 for (int c = 0; c < nConss; ++c)
950 {
951 cons = conss[c];
952 assert( cons != NULL);
953
954 /* in case the transformed is written only constraint are posted which are enabled in the current node */
955 if( !SCIPconsIsEnabled(cons) )
956 continue;
957
958 conshdlr = SCIPconsGetHdlr(cons);
959 assert( conshdlr != NULL );
960
961 if( SCIPconshdlrGetStartNActiveConss(conshdlr) > 0 )
962 {
963 conshdlrname = SCIPconshdlrGetName(conshdlr);
964 assert( SCIPconsIsTransformed(cons) );
965
966 if( strcmp(conshdlrname, "linear") == 0 )
967 {
968 nLinearConss++;
969 }
970 else if( strcmp(conshdlrname, "setppc") == 0 )
971 {
972 nSetppcConss++;
973 }
974 else if ( strcmp(conshdlrname, "logicor") == 0 )
975 {
977 }
978 else if ( strcmp(conshdlrname, "knapsack") == 0 )
979 {
981 }
982 else if ( strcmp(conshdlrname, "varbound") == 0 )
983 {
985 }
986 else if ( strcmp(conshdlrname, "bounddisjunction") == 0 )
987 {
989 }
990 else if ( strcmp(conshdlrname, "SOS1") == 0 )
991 {
992 nSos1Conss++;
993 }
994 else if ( strcmp(conshdlrname, "SOS2") == 0 )
995 {
996 nSos2Conss++;
997 }
998 else
999 {
1000 THROW_LOGICAL_ERROR3("constraint handler <", conshdlrname, "> can not print requested format");
1001 }
1002 }
1003 else
1004 {
1005 nNotInitialActiveConss++;
1006 }
1007 }
1008
1010
1012
1013 /** re-initialize counters for ordinary constraints */
1014 nLinearConss = 0;
1015 nSetppcConss = 0;
1016 nLogicorConss = 0;
1017 nKnapsackConss = 0;
1018 nVarboundConss = 0;
1020 nSos1Conss = 0;
1021 nSos2Conss = 0;
1022 nNotInitialActiveConss = 0;
1023
1024 /** initialize length of constraint names area */
1025 lConsNames = 0;
1026 for (int c = 0; c < nConss; ++c)
1027 {
1028 cons = conss[c];
1029
1030 /* in case the transformed is written only constraint are posted which are enabled in the current node */
1031 if( !SCIPconsIsEnabled(cons) )
1032 continue;
1033
1034 conshdlr = SCIPconsGetHdlr(cons);
1035
1036 if( SCIPconshdlrGetStartNActiveConss(conshdlr) > 0 )
1037 {
1038 conshdlrname = SCIPconshdlrGetName(conshdlr);
1039
1040 if( strcmp(conshdlrname, "linear") == 0 )
1041 {
1042 setLinearConstraint( scip, c, cons );
1043 }
1044 else if( strcmp(conshdlrname, "setppc") == 0 )
1045 {
1046 setSetppcConstraint( scip, c, cons );
1047 }
1048 else if ( strcmp(conshdlrname, "logicor") == 0 )
1049 {
1050 setLogicorConstraint( scip, c, cons );
1051 }
1052 else if ( strcmp(conshdlrname, "knapsack") == 0 )
1053 {
1054 setKnapsackConstraint( scip, c, cons );
1055 }
1056 else if ( strcmp(conshdlrname, "varbound") == 0 )
1057 {
1058 setVarboundConstraint( scip, c, cons );
1059 }
1060 else if ( strcmp(conshdlrname, "bounddisjunction") == 0 )
1061 {
1063 }
1064 else if ( strcmp(conshdlrname, "SOS1") == 0 )
1065 {
1066 setSos1Constraint( scip, c, cons, consSOS1);
1067 }
1068 else if ( strcmp(conshdlrname, "SOS2") == 0 )
1069 {
1070 setSos2Constraint( scip, c, cons, consSOS2);
1071 }
1072 }
1073 else
1074 {
1075 nNotInitialActiveConss++;
1076 }
1077 }
1078
1080
1081 SCIP_VAR** aggregatedVars;
1082 int nAggregatedVars = 0;
1083 SCIP_HASHTABLE* varAggregated;
1084
1085 // create hashtable for storing aggregated variables
1086 SCIP_CALL_ABORT( SCIPallocBufferArray(scip, &aggregatedVars, nVars) );
1087 SCIP_CALL_ABORT( SCIPhashtableCreate(&varAggregated, SCIPblkmem(scip), 1000, hashGetKeyVar, hashKeyEqVar, hashKeyValVar,
1088 NULL) );
1089
1090 // check for aggregated variables in SOS1 constraints and output aggregations as linear constraints
1091 for (int c = 0; c < nSos1Conss; ++c)
1092 {
1093 cons = consSOS1[c];
1094 SCIP_VAR **consvars = SCIPgetVarsSOS1(scip, cons);
1095 int nconsvars = SCIPgetNVarsSOS1(scip, cons);
1096
1097 collectAggregatedVars(scip, nconsvars, consvars, &nAggregatedVars, &aggregatedVars, &varAggregated);
1098 }
1099
1100 // check for aggregated variables in SOS2 constraints and output aggregations as linear constraints
1101 for (int c = 0; c < nSos2Conss; ++c)
1102 {
1103 cons = consSOS2[c];
1104 SCIP_VAR **consvars = SCIPgetVarsSOS2(scip, cons);
1105 int nconsvars = SCIPgetNVarsSOS2(scip, cons);
1106
1107 collectAggregatedVars(scip, nconsvars, consvars, &nAggregatedVars, &aggregatedVars, &varAggregated);
1108 }
1109
1110 // set aggregation constraints
1111 setAggregatedConstrains(scip, nVars, nAggregatedVars, aggregatedVars );
1112
1113 // free space
1114 SCIPfreeBufferArray(scip, &aggregatedVars);
1115 SCIPhashtableFree(&varAggregated);
1116
1117 // free space
1118 SCIPfreeBufferArray(scip, &consSOS1);
1119 SCIPfreeBufferArray(scip, &consSOS2);
1120 }
1121 else
1122 {
1123 SCIP_CALL_ABORT( SCIPwriteTransProblem(scip, PRESOLVED_INSTANCE, "cip", TRUE ) );
1124 }
1125}
1126
1128 )
1129{
1130 if(probName) delete[] probName;
1131 if(varLbs) delete[] varLbs;
1132 if(varUbs) delete[] varUbs;
1133 if(objCoefs) delete[] objCoefs;
1134 if(varTypes) delete[] varTypes;
1135 if(varNames) delete[] varNames;
1136 if(posVarNames) delete[] posVarNames;
1139 // if(mapToProbIndecies) delete[] mapToProbIndecies;
1140 if(consNames) delete[] consNames;
1141 if(posConsNames) delete[] posConsNames;
1142
1143 /** for linear constraints */
1144 if( nLinearConss > 0 )
1145 {
1146 if( idxLinearConsNames ) delete [] idxLinearConsNames;
1147 if( linearLhss ) delete [] linearLhss;
1148 if( linearRhss ) delete [] linearRhss;
1149 if( nLinearCoefs )
1150 {
1151 for(int i = 0; i < nLinearConss; i++ )
1152 {
1153 delete [] linearCoefs[i];
1154 delete [] idxLinearCoefsVars[i];
1155 }
1156 delete [] linearCoefs;
1157 delete [] idxLinearCoefsVars;
1158 delete [] nLinearCoefs;
1159 }
1160 }
1161 /** for setppc constraints */
1162 if( nSetppcConss )
1163 {
1164 if( idxSetppcConsNames ) delete [] idxSetppcConsNames;
1165 if( nIdxSetppcVars ) delete [] nIdxSetppcVars;
1166 if( setppcTypes ) delete [] setppcTypes;
1167 if( idxSetppcVars )
1168 {
1169 for(int i = 0; i < nSetppcConss; i++ )
1170 {
1171 delete idxSetppcVars[i];
1172 }
1173 delete [] idxSetppcVars;
1174 }
1175 }
1176 /** for logical constraints */
1177 if(nLogicorConss)
1178 {
1180 if( nIdxLogicorVars ) delete [] nIdxLogicorVars;
1181 if( idxLogicorVars )
1182 {
1183 for( int i = 0; i < nLogicorConss; i++ )
1184 {
1185 delete [] idxLogicorVars[i];
1186 }
1187 delete [] idxLogicorVars;
1188 }
1189 }
1190 /** for knapsack constraints */
1191 if(nKnapsackConss)
1192 {
1194 if( capacities ) delete [] capacities;
1195 if( nLKnapsackCoefs ) delete [] nLKnapsackCoefs;
1196 if( knapsackCoefs )
1197 {
1198 for( int i = 0; i < nKnapsackConss; i++ )
1199 {
1200 delete [] knapsackCoefs[i];
1201 delete [] idxKnapsackCoefsVars[i];
1202 }
1203 delete [] knapsackCoefs;
1204 delete [] idxKnapsackCoefsVars;
1205 }
1206 }
1207 /** for varbound constraints */
1208 if( nVarboundConss )
1209 {
1212 if( varboundCoef2s ) delete [] varboundCoef2s;
1214 }
1215
1216 /** for bounddisjunction constraints */
1218 {
1221 for( int c = 0; c < nVarBoundDisjunctionConss; c++ )
1222 {
1226 }
1227 }
1228
1229 /** for SOS1 constraints */
1230 if( nSos1Conss )
1231 {
1232 if( nSos1Coefs ) delete [] nSos1Coefs;
1233 if( sos1Coefs )
1234 {
1235 for( int i = 0; i < nSos1Conss; i++ )
1236 {
1237 delete [] sos1Coefs[i];
1238 delete [] idxSos1CoefsVars[i];
1239 }
1240 delete [] sos1Coefs;
1241 delete [] idxSos1CoefsVars;
1242 }
1243 }
1244 /** for SOS2 constraints */
1245 if( nSos2Conss )
1246 {
1247 if( nSos2Coefs ) delete [] nSos2Coefs;
1248 if( sos2Coefs )
1249 {
1250 for( int i = 0; i < nSos1Conss; i++ )
1251 {
1252 delete [] sos2Coefs[i];
1253 delete [] idxSos2CoefsVars[i];
1254 }
1255 delete sos2Coefs;
1256 delete idxSos2CoefsVars;
1257 }
1258 }
1259 /** for agrregated constraints */
1260 if( nAggregatedConss )
1261 {
1262 for( int i = 0; i < nAggregatedConss; i++ )
1263 {
1264 delete aggregatedCoefs[i];
1265 delete idxAggregatedCoefsVars[i];
1266 }
1267 delete [] aggregatedCoefs;
1268 delete [] idxAggregatedCoefsVars;
1269 aggregatedCoefs = 0;
1271
1272 if( aggregatedVarNames ) delete [] aggregatedVarNames;
1277 }
1278
1279 if( userPlugins ) delete userPlugins;
1280}
1281
1282bool
1284 SCIP *tempScip,
1285 ScipDiffParamSet *scipDiffParamSetRoot
1286 )
1287{
1288 SCIP_Longint originalLimitsNodes;
1289 SCIP_CALL_ABORT( SCIPgetLongintParam(tempScip, "limits/nodes", &originalLimitsNodes) );
1290 SCIP_CALL_ABORT( SCIPsetLongintParam(tempScip, "limits/nodes", 1) );
1291 if( scipDiffParamSetRoot ) scipDiffParamSetRoot->setParametersInScip(tempScip);
1292 SCIP_RETCODE ret = SCIPsolve(tempScip);
1293 if( ret != SCIP_OKAY )
1294 {
1295 exit(1); // LC should abort
1296 }
1297 // Then, solver status should be checked
1298 SCIP_STATUS status = SCIPgetStatus(tempScip);
1299 if( status == SCIP_STATUS_OPTIMAL ) // when sub-MIP is solved at root node, the solution may not be saved
1300 {
1301 return false;
1302 }
1303 else
1304 {
1305 if( status == SCIP_STATUS_MEMLIMIT )
1306 {
1307 std::cout << "Warning: SCIP was interrupted because the memory limit was reached" << std::endl;
1308 return false;
1309 }
1310 }
1311
1312 SCIP_CUT** cuts;
1313 int ncuts;
1314 int ncutsadded;
1315
1316 ncutsadded = 0;
1317 cuts = SCIPgetPoolCuts(tempScip);
1318 ncuts = SCIPgetNPoolCuts(tempScip);
1319 for( int c = 0; c < ncuts; ++c )
1320 {
1321 SCIP_ROW* row;
1322
1323 row = SCIPcutGetRow(cuts[c]);
1324 assert(!SCIProwIsLocal(row));
1325 assert(!SCIProwIsModifiable(row));
1326 if( SCIPcutGetAge(cuts[c]) == 0 && SCIProwIsInLP(row) )
1327 {
1328 char name[SCIP_MAXSTRLEN];
1329 SCIP_CONS* cons;
1330 SCIP_COL** cols;
1331 SCIP_VAR** vars;
1332 int ncols;
1333 int i;
1334
1335 /* create a linear constraint out of the cut */
1336 cols = SCIProwGetCols(row);
1337 ncols = SCIProwGetNNonz(row);
1338
1339 SCIP_CALL_ABORT( SCIPallocBufferArray(tempScip, &vars, ncols) );
1340 for( i = 0; i < ncols; ++i )
1341 vars[i] = SCIPcolGetVar(cols[i]);
1342
1343 (void) SCIPsnprintf(name, SCIP_MAXSTRLEN, "%s_%d", SCIProwGetName(row), SCIPgetNRuns(tempScip));
1344 SCIP_CALL_ABORT( SCIPcreateConsLinear(tempScip, &cons, name, ncols, vars, SCIProwGetVals(row),
1345 SCIProwGetLhs(row) - SCIProwGetConstant(row), SCIProwGetRhs(row) - SCIProwGetConstant(row),
1346 TRUE, TRUE, FALSE, FALSE, TRUE, FALSE, FALSE, FALSE, TRUE, FALSE) );
1347 SCIP_CALL_ABORT( SCIPaddCons(tempScip, cons) );
1348 SCIP_CALL_ABORT( SCIPreleaseCons(tempScip, &cons) );
1349
1350 SCIPfreeBufferArray(tempScip, &vars);
1351
1352 ncutsadded++;
1353 }
1354 }
1355 SCIP_CALL_ABORT( SCIPsetLongintParam(tempScip, "limits/nodes", originalLimitsNodes) );
1356 return true;
1357}
1358
1359/** create presolved problem instance that is solved by ParaSCIP */
1360void
1362 SCIP *scip,
1363 int method,
1364 bool noPreprocessingInLC,
1365 bool usetRootNodeCuts,
1366 ScipDiffParamSet *scipDiffParamSetRoot,
1367 ScipDiffParamSet *scipDiffParamSet,
1368 char *settingsNameLC,
1369 char *isolname
1370 )
1371{
1372
1373 switch ( method )
1374 {
1375 case 0 :
1376 {
1377 SCIP_CALL_ABORT( SCIPcreateProb(scip, probName, NULL, NULL, NULL, NULL, NULL, NULL, NULL) );
1378 SCIP_CALL_ABORT( SCIPsetObjsense(scip, SCIP_OBJSENSE_MINIMIZE) );
1379 for(int v = 0; v < nVars; ++v)
1380 {
1381 SCIP_VAR* newvar;
1382
1383 /* create new variable of the given name */
1384 SCIP_CALL_ABORT( SCIPcreateVar(scip, &newvar, &varNames[posVarNames[v]], varLbs[v], varUbs[v], objCoefs[v],
1385 SCIP_Vartype(varTypes[v]),
1386 TRUE, FALSE, NULL, NULL, NULL, NULL, NULL) );
1387 SCIP_CALL_ABORT( SCIPaddVar(scip, newvar) );
1388 assert( SCIPvarGetProbindex(newvar) == v );
1389 /* because the variable was added to the problem, it is captured by SCIP and we can safely release it right now
1390 * without making the returned *var invalid
1391 */
1392 SCIP_CALL_ABORT( SCIPreleaseVar(scip, &newvar) );
1393 }
1394
1395 if( nLinearConss )
1397 if( nSetppcConss)
1399 if( nLogicorConss )
1401 if( nKnapsackConss )
1403 if( nVarboundConss )
1407 if( nSos1Conss )
1409 if( nSos2Conss )
1411 if( nAggregatedConss )
1413 break;
1414 }
1415 case 1 :
1416 {
1417 if( scipDiffParamSet ) scipDiffParamSet->setParametersInScip(scip);
1418 SCIP_CALL_ABORT( SCIPreadProb(scip, PRESOLVED_INSTANCE, "cip" ) );
1419 nVars = SCIPgetNVars(scip);
1421 SCIP_VAR **vars = SCIPgetVars(scip);
1422 varLbs = new SCIP_Real[nVars];
1423 varUbs = new SCIP_Real[nVars];
1424 for(int v = 0; v < nVars; ++v )
1425 {
1426 SCIP_VAR *var = vars[v];
1427 varLbs[SCIPvarGetProbindex(var)] = SCIPvarGetLbLocal(var); //* we should use global?
1428 varUbs[SCIPvarGetProbindex(var)] = SCIPvarGetUbLocal(var); //* we should use global?
1429 }
1430 break;
1431 }
1432 case 2 :
1433 {
1434 SCIP *tempScip = 0;
1435 SCIP_Bool success = TRUE;
1436 SCIP_CALL_ABORT( SCIPcreate(&tempScip) );
1437 SCIP_CALL_ABORT( SCIPsetIntParam(tempScip, "timing/clocktype", 2) ); // always wall clock time
1438
1439 /* include default SCIP plugins */
1440 SCIP_CALL_ABORT( SCIPincludeDefaultPlugins(tempScip) );
1441 /** user include plugins */
1442 includeUserPlugins(tempScip);
1443
1444#ifdef SCIP_THREADSAFE_MESSAGEHDLRS
1445 SCIPsetMessagehdlrQuiet(tempScip, TRUE);
1446#endif
1447 // SCIP_CALL_ABORT( SCIPreadProb(tempScip, getFileName(), NULL ) );
1448 // std::cout << "file name = " << getFileName() << std::endl;
1449 // std::cout << "tempScip = " << tempScip << std::endl;
1450 if( scipDiffParamSet ) scipDiffParamSet->setParametersInScip(tempScip);
1451 int retcode = SCIPreadProb(tempScip, getFileName(), NULL );
1452 // assert( retcode == SCIP_OKAY );
1453 if( retcode != SCIP_OKAY )
1454 {
1455 std::cout << "SCIPreadProb returns: " << retcode << std::endl;
1456 if( getFileName()[0] == '.' )
1457 {
1458 char dir[512];
1459 std::cout << "Cannot read < " << getcwd(dir, 511) << "/" << getFileName() << std::endl;
1460 }
1461 else
1462 {
1463 std::cout << "Cannot read < " << getFileName() << std::endl;
1464 }
1465 exit(1);
1466 }
1467
1468 /* read initail solution, if it is specified */
1469 if( isolname )
1470 {
1471 SCIP_CALL_ABORT( SCIPtransformProb(tempScip));
1472 // NOTE:
1473 // When CPLEX license file cannot find, SCIPtransformProb(scip) may fail
1474 // SCIP_CALL_ABORT( SCIPreadSol(tempScip, isolname) );
1475 SCIP_CALL_ABORT( SCIPreadProb(tempScip, isolname, NULL ) );
1476 }
1477
1478 /* change problem name */
1479 char *probNameFromFileName;
1480 char *temp = new char[strlen(getFileName())+1];
1481 (void) strcpy(temp, getFileName());
1482 SCIPsplitFilename(temp, NULL, &probNameFromFileName, NULL, NULL);
1483 SCIP_CALL_ABORT( SCIPsetProbName(tempScip, probNameFromFileName));
1484
1485 /* presolve problem */
1486 if( noPreprocessingInLC )
1487 {
1488 SCIP_CALL_ABORT( SCIPsetIntParam(tempScip, "presolving/maxrounds", 0));
1489 }
1490 else
1491 {
1492 if( settingsNameLC )
1493 {
1494 SCIP_CALL_ABORT( SCIPreadParams(tempScip, settingsNameLC) );
1495 }
1496 /*
1497 else
1498 {
1499 SCIP_CALL_ABORT( SCIPsetPresolving(tempScip, SCIP_PARAMSETTING_FAST, TRUE) );
1500 }
1501 */
1502 }
1503 // SCIP_CALL_ABORT( SCIPsetIntParam(tempScip, "constraints/quadratic/replacebinaryprod", 0));
1504 // SCIP_CALL_ABORT( SCIPsetBoolParam(tempScip, "constraints/nonlinear/reformulate", FALSE));
1505 SCIP_CALL_ABORT( SCIPpresolve(tempScip) );
1506 SCIP_STATUS scipStatus = SCIPgetStatus(tempScip);
1507 if( scipStatus == SCIP_STATUS_OPTIMAL ) return; // the problem shold be solved in LC
1508
1509 /* adding root node cuts, if necessary */
1510 if( usetRootNodeCuts )
1511 {
1512 if( !addRootNodeCuts(tempScip,scipDiffParamSetRoot) )
1513 {
1514 return; // the problem shold be solved in LC
1515 }
1516 }
1517
1518 if( SCIPgetNVars(tempScip) == 0 ) // all variables were fixed in presolve
1519 {
1520 return; // the problem shold be solved in LC
1521 }
1522
1523 assert( SCIPgetStage(scip) == SCIP_STAGE_INIT );
1524
1525 assert( nCopies > 0 );
1526
1527 SCIP_HASHMAP* varmap = 0;
1528 SCIP_HASHMAP* conssmap = 0;
1529
1530 assert( nCopies == 1);
1531
1532 if( nCopies == 1 )
1533 {
1534 // SCIP_CALL_ABORT( SCIPfree(&scip) );
1535 // SCIP_CALL_ABORT( SCIPcreate(&scip) );
1536
1537 /* include default SCIP plugins */
1538 // SCIP_CALL_ABORT( SCIPincludeDefaultPlugins(scip) );
1539 /** user include plugins */
1540 // includeUserPlugins(scip);
1541
1542 /* copy all plugins and settings */
1543 #if SCIP_VERSION == 211 && SCIP_SUBVERSION == 0
1544 SCIP_CALL_ABORT( SCIPcopyPlugins(tempScip, scip, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE,
1545 TRUE, TRUE, TRUE, TRUE, &success) );
1546 #else
1547 #if SCIP_APIVERSION >= 100
1548 #if SCIP_APIVERSION >= 101
1549 SCIP_CALL_ABORT( SCIPcopyPlugins(tempScip, scip, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE,
1550 TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, FALSE, &success) );
1551 #else
1552 SCIP_CALL_ABORT( SCIPcopyPlugins(tempScip, scip, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE,
1553 TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, FALSE, &success) );
1554 #endif
1555 #elif SCIP_APIVERSION >= 17
1556 SCIP_CALL_ABORT( SCIPcopyPlugins(tempScip, scip, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE,
1557 TRUE, TRUE, TRUE, TRUE, TRUE, FALSE, &success) );
1558 #else
1559 SCIP_CALL_ABORT( SCIPcopyPlugins(tempScip, scip, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE,
1560 TRUE, TRUE, TRUE, TRUE, FALSE, &success) );
1561 #endif
1562 #endif
1563 SCIP_CALL_ABORT( SCIPcopyParamSettings(tempScip, scip) );
1564
1565 /* create the variable mapping hash map */
1566 if( SCIPgetNVars(tempScip) > 0 )
1567 {
1568 SCIP_CALL_ABORT( SCIPhashmapCreate(&varmap, SCIPblkmem(scip), SCIPgetNVars(tempScip)) );
1569 }
1570 if( SCIPgetNConss(tempScip) > 0 )
1571 {
1572 SCIP_CALL_ABORT( SCIPhashmapCreate(&conssmap, SCIPblkmem(scip), SCIPgetNConss(tempScip)) );
1573 }
1574
1575 /* create problem in the target SCIP and copying the source original problem data */
1576 SCIP_CALL_ABORT( SCIPcopyProb(tempScip, scip, varmap, conssmap, TRUE, probNameFromFileName) );
1577 delete [] temp; // probNameFromFileName is in temp
1578
1579 /* copy all variables and constraints */
1580 if( SCIPgetNVars(tempScip) > 0 )
1581 {
1582#if (SCIP_VERSION < 321 || ( SCIP_VERSION == 321 && SCIP_SUBVERSION < 2) )
1583 SCIP_CALL_ABORT( SCIPcopyVars(tempScip, scip, varmap, conssmap, TRUE) );
1584#else
1585 SCIP_CALL_ABORT( SCIPcopyVars(tempScip, scip, varmap, conssmap, NULL, NULL, 0, TRUE) );
1586#endif
1587 }
1588 if( SCIPgetNConss(tempScip) > 0 )
1589 {
1590 SCIP_CALL_ABORT( SCIPcopyConss(tempScip, scip, varmap, conssmap, TRUE, FALSE, &success) );
1591 }
1592
1593#if SCIP_APIVERSION > 39
1594 if( success )
1595 {
1596 SCIP_Bool valid;
1597
1598 /* copy the Benders' decomposition plugins explicitly, because it requires the variable mapping hash map */
1599 SCIP_CALL_ABORT( SCIPcopyBenders(tempScip, scip, NULL, TRUE, &valid) );
1600 }
1601#endif
1602
1603 if( !success )
1604 {
1605 if( SCIPgetNConss(tempScip) > 0 )
1606 {
1607 SCIPhashmapFree(&conssmap);
1608 }
1609 if( SCIPgetNVars(tempScip) > 0 )
1610 {
1611 SCIPhashmapFree(&varmap);
1612 }
1613 SCIPfree(&tempScip);
1614 std::cerr << "Some constraint handler did not perform a valid copy. Cannot solve this instance." << std::endl;
1615 exit(1);
1616 }
1617 }
1618
1619 nVars = SCIPgetNVars(tempScip);
1621 int n = SCIPgetNVars(scip);
1622
1623 // std::cout << "nVars = " << nVars << ", varIndexRange = " << varIndexRange << ", n = " << n << std::endl;
1624
1625 assert( nVars <= n );
1626 if( nVars < n )
1627 {
1629 varIndexRange = n;
1630 }
1631 // mapToProbIndecies = new int[SCIPgetNTotalVars(scip)];
1632 mapToOriginalIndecies = new int[SCIPgetNTotalVars(tempScip)]; // need to allocate enough for SCIPvarGetIndex(copyvar)
1633 mapToSolverLocalIndecies = new int[SCIPgetNTotalVars(tempScip)];
1634 for( int i = 0; i < SCIPgetNTotalVars(tempScip); i++ )
1635 {
1636 // mapToProbIndecies[i] = -1;
1637 mapToOriginalIndecies[i] = -1;
1639 }
1640
1641 assert(SCIPgetNTotalVars(scip) >= SCIPgetNVars(tempScip));
1642
1643 // SCIP_VAR **srcVars = SCIPgetVars(tempScip);
1644 SCIP_VAR **srcVars = SCIPgetVars(tempScip);
1645 // SCIP_VAR **targetVars = SCIPgetVars(scip);
1646 // for( int i = 0; i < SCIPgetNTotalVars(scip); i++ )
1647 for( int i = 0; i < SCIPgetNVars(tempScip); i++ )
1648 {
1649 SCIP_VAR* copyvar = (SCIP_VAR*)SCIPhashmapGetImage(varmap, (void*)srcVars[i]);
1650 // std::cout << i << ": index = " << SCIPvarGetIndex(copyvar) << std::endl;
1651 // assert(SCIPvarGetIndex(copyvar) >= 0);
1652 // if( copyvar && SCIPvarGetProbindex(copyvar) < n )
1653 if( copyvar )
1654 {
1655 // assert(SCIPvarGetProbindex(copyvar) >= 0);
1656 mapToOriginalIndecies[SCIPvarGetIndex(copyvar)] = i;
1657 mapToSolverLocalIndecies[i] = SCIPvarGetIndex(copyvar);
1658 // mapToProbIndecies[SCIPvarGetIndex(copyvar)] = SCIPvarGetProbindex(copyvar);
1659 // mapToOriginalIndecies[SCIPvarGetIndex(copyvar)] = SCIPvarGetProbindex(copyvar);
1660 // std::cout << i << ": " << SCIPvarGetName(copyvar) << std::endl;
1661 // std::cout << i << ": " << SCIPvarGetName(srcVars[i]) << std::endl;
1662 // std::cout << i << ": " << SCIPvarGetName(targetVars[SCIPvarGetProbindex(copyvar)]) << std::endl;
1663 }
1664 /*
1665 else
1666 {
1667 THROW_LOGICAL_ERROR1("the number of variables is inconsitent");
1668 }
1669 */
1670 }
1671
1672 /* free hash map */
1673 if( SCIPgetNConss(tempScip) > 0 )
1674 {
1675 SCIPhashmapFree(&conssmap);
1676 }
1677 if( SCIPgetNVars(tempScip) > 0 )
1678 {
1679 SCIPhashmapFree(&varmap);
1680 }
1681
1682 SCIPfree(&tempScip);
1683
1684 // n = SCIPgetNVars(scip);
1685 SCIP_VAR **vars = SCIPgetVars(scip);
1686 varLbs = new SCIP_Real[nVars];
1687 varUbs = new SCIP_Real[nVars];
1688 for(int v = 0; v < nVars; ++v )
1689 {
1690 SCIP_VAR *var = vars[v];
1691 varLbs[SCIPvarGetProbindex(var)] = SCIPvarGetLbLocal(var); //* we should use global?
1692 varUbs[SCIPvarGetProbindex(var)] = SCIPvarGetUbLocal(var); //* we should use global?
1693 }
1694
1695// #ifdef UG_DEBUG_SOLUTION
1696// assert(scip->set->debugsoldata == NULL);
1697// SCIP_CALL_ABORT( SCIPdebugSolDataCreate(&((scip->set)->debugsoldata)));
1698// SCIPdebugSetMainscipset(scip->set);
1699// #endif
1700 break;
1701 }
1702 default :
1703 THROW_LOGICAL_ERROR1("Undefined instance transfer method");
1704 }
1705}
1706
1707void
1709{
1710 /** free memory for ParaInstance to save memory */
1711 if(varLbs)
1712 {
1713 delete[] varLbs;
1714 varLbs = 0;
1715 }
1716 if(varUbs)
1717 {
1718 delete[] varUbs;
1719 varUbs = 0;
1720 }
1721 if(objCoefs)
1722 {
1723 delete[] objCoefs;
1724 objCoefs = 0;
1725 }
1726 if(varTypes)
1727 {
1728 delete[] varTypes;
1729 varTypes = 0;
1730 }
1731 if(posVarNames)
1732 {
1733 delete[] posVarNames;
1734 posVarNames = 0;
1735 }
1736
1737 if( nLinearConss )
1738 {
1739 delete [] idxLinearConsNames;
1741 delete [] linearLhss;
1742 linearLhss = 0;
1743 delete [] linearRhss;
1744 linearRhss = 0;
1745 for(int i = 0; i < nLinearConss; i++ )
1746 {
1747 delete [] linearCoefs[i];
1748 delete [] idxLinearCoefsVars[i];
1749 }
1750 delete [] linearCoefs;
1751 delete [] idxLinearCoefsVars;
1752 delete [] nLinearCoefs;
1753 linearCoefs = 0;
1755 nLinearCoefs = 0;
1756 }
1757 if( nSetppcConss )
1758 {
1759 delete [] idxSetppcConsNames;
1761 delete [] nIdxSetppcVars;
1762 nIdxSetppcVars = 0;
1763 delete [] setppcTypes;
1764 setppcTypes = 0;
1765 for(int i = 0; i < nSetppcConss; i++ )
1766 {
1767 delete idxSetppcVars[i];
1768 }
1769 delete [] idxSetppcVars;
1770 idxSetppcVars = 0;
1771 }
1772 if( nLogicorConss )
1773 {
1774 delete [] idxLogicorConsNames;
1776 delete [] nIdxLogicorVars;
1777 nIdxLogicorVars = 0;
1778 for( int i = 0; i < nLogicorConss; i++ )
1779 {
1780 delete [] idxLogicorVars[i];
1781 }
1782 delete [] idxLogicorVars;
1783 idxLogicorVars = 0;
1784 }
1785 if( nKnapsackConss )
1786 {
1787 delete [] idxKnapsackConsNames;
1789 delete [] capacities;
1790 capacities = 0;
1791 delete [] nLKnapsackCoefs;
1792 nLKnapsackCoefs = 0;
1793 for( int i = 0; i < nKnapsackConss; i++ )
1794 {
1795 delete [] knapsackCoefs[i];
1796 delete [] idxKnapsackCoefsVars[i];
1797 }
1798 delete [] knapsackCoefs;
1799 delete [] idxKnapsackCoefsVars;
1800 knapsackCoefs = 0;
1802 }
1803 if( nSos1Conss )
1804 {
1805 delete [] nSos1Coefs;
1806 nSos1Coefs = 0;
1807 for( int i = 0; i < nSos1Conss; i++ )
1808 {
1809 delete [] sos1Coefs[i];
1810 delete [] idxSos1CoefsVars[i];
1811 }
1812 delete [] sos1Coefs;
1813 delete [] idxSos1CoefsVars;
1814 sos1Coefs = 0;
1815 idxSos1CoefsVars = 0;
1816 }
1817 if( nSos2Conss )
1818 {
1819 delete [] nSos2Coefs;
1820 nSos2Coefs = 0;
1821 for( int i = 0; i < nSos1Conss; i++ )
1822 {
1823 delete [] sos2Coefs[i];
1824 delete [] idxSos2CoefsVars[i];
1825 }
1826 delete sos2Coefs;
1827 delete idxSos2CoefsVars;
1828 sos2Coefs = 0;
1829 idxSos2CoefsVars = 0;
1830 }
1831 if( nAggregatedConss )
1832 {
1833 for( int i = 0; i < nAggregatedConss; i++ )
1834 {
1835 delete aggregatedCoefs[i];
1836 delete idxAggregatedCoefsVars[i];
1837 }
1838 delete [] aggregatedCoefs;
1839 delete [] idxAggregatedCoefsVars;
1840 delete[] aggregatedLhsAndLhss;
1841 aggregatedCoefs = 0;
1844 }
1845}
1846
1847/** stringfy ScipParaInstance: for debug */
1848const std::string
1850 )
1851{
1852 std::ostringstream s;
1853
1854 s << "lProbName = " << lProbName << std::endl;
1855 s << "probName = " << probName << std::endl;
1856 s << "objSense = " << origObjSense << std::endl;
1857 s << "objScale = " << objScale << std::endl;
1858 s << "objOffset = " << objOffset << std::endl;
1859 s << "nVars = " << nVars << ", lVarNames = " << lVarNames << std::endl;
1860 for( int i = 0; i < nVars; i++ )
1861 {
1862 s << "[" << i << "]: varNames = " << &varNames[posVarNames[i]]
1863 << ", varsLbs = " << varLbs[i] << ", varsUbs = " << varUbs[i]
1864 << ", objCoefs = " << objCoefs[i] << ", varTypes = " << varTypes[i];
1866 {
1867 s << ", mapToOriginalIndecies = " << mapToOriginalIndecies[i];
1868 }
1870 {
1871 s << ", mapToSolverLocalIndecies = " << mapToSolverLocalIndecies[i];
1872 }
1873 s << std::endl;
1874 }
1875 s << "nConss = " << nConss << ", lConsNames = " << lConsNames << std::endl;
1876 for( int i = 0; i < nConss; i ++ )
1877 {
1878 s<< "[" << i << "]: consNames = " << &consNames[posConsNames[i]] << std::endl;
1879 }
1880
1881 /*************************
1882 * for linear constrains *
1883 * ***********************/
1884 s << "nLinearConss = " << nLinearConss << std::endl;
1885 for(int i = 0; i < nLinearConss; i++ )
1886 {
1887 s << "[" << i << "]: idxLinearConsNames = " << idxLinearConsNames[i]
1888 << ", linearLhss = " << linearLhss[i] << ", linearRhss = " << linearRhss[i]
1889 << ", nLinearCoefs = " << nLinearCoefs[i] << std::endl;
1890 for( int j = 0; j < nLinearCoefs[i]; j++ )
1891 {
1892 s << " [" << j << "]: linearCoefs = " << linearCoefs[i][j]
1893 << ", idxLinearCoefsVars = " << idxLinearCoefsVars[i][j] << std::endl;
1894 }
1895 }
1896
1897 /*************************
1898 * for setppc constrains *
1899 * ***********************/
1900 s << "nSetppcConss = " << nSetppcConss << std::endl;
1901 for(int i = 0; i < nSetppcConss; i++)
1902 {
1903 s << "[" << i << "]: idxSetppcConsNames = " << idxSetppcConsNames[i]
1904 << ", nIdxSetppcVars = " << nIdxSetppcVars[i] << ", setppcTypes = " << setppcTypes[i] << std::endl;
1905 for(int j = 0; j < nIdxSetppcVars[i]; j++ )
1906 {
1907 s << " [" << j << "]: idxSetppcVars = " << idxSetppcVars[i][j] << std::endl;
1908 }
1909 }
1910
1911 /*********************************
1912 * for logical constrains *
1913 *********************************/
1914 s << "nLogicorConss = " << nLogicorConss << std::endl;
1915 for(int i = 0; i < nLogicorConss; i++ )
1916 {
1917 s << "[" << i << "]: idxLogicorConsNames = " << idxLogicorConsNames[i]
1918 << ", nIdxLogicorVars = " << nIdxLogicorVars[i] << std::endl;
1919 for(int j = 0; j < nIdxLogicorVars[i]; j++ )
1920 {
1921 s << " [" << j << "]: idxLogicorVars = " << idxLogicorVars[i][j] << std::endl;
1922 }
1923 }
1924
1925 /*********************************
1926 * for knapsack constrains *
1927 *********************************/
1928 s << "nKnapsackConss = " << nKnapsackConss << std::endl;
1929 for(int i = 0; i < nKnapsackConss; i++)
1930 {
1931 s << "[" << i << "]: idxKnapsackConsNames = " << idxKnapsackConsNames[i]
1932 << ", capacities = " << capacities[i] << ", nLKnapsackCoefs = " << nLKnapsackCoefs[i] << std::endl;
1933 for(int j = 0; j < nLKnapsackCoefs[i]; j++ )
1934 {
1935 s << " [" << j << "]: knapsackCoefs = " << knapsackCoefs[i][j] << ", idxKnapsackCoefsVars = " << idxKnapsackCoefsVars[i][j] << std::endl;
1936 }
1937 }
1938
1939 /**********************************
1940 * for varbound constrains *
1941 *********************************/
1942 s << "nVarboundConss = " << nVarboundConss << std::endl;
1943 for(int i = 0; i < nVarboundConss; i++)
1944 {
1945 s << "[" << i << "]: idxVarboundConsNames = " << idxVarboundConsNames[i]
1946 << ", varboundLhss = " << varboundLhss[i] << ", varboundRhss = " << varboundRhss[i]
1947 << ", idxVarboundCoefVar1s = " << idxVarboundCoefVar1s[i] << ", varboundCoef2s = " << varboundCoef2s[i]
1948 << ", idxVarboundCoefVar2s = " << idxVarboundCoefVar2s[i] << std::endl;
1949 }
1950
1951 /*********************************
1952 * for SOS1 constraints *
1953 *********************************/
1954 s << "nSos1Conss = " << nSos1Conss << std::endl;
1955 for( int i = 0; i < nSos1Conss; i++ )
1956 {
1957 s << "[" << i << "]: idxSos1ConsNames = " << idxSos1ConsNames[i]
1958 << ", nSos1Coefs = " << nSos1Coefs[i] << std::endl;
1959 for(int j = 0; j < nSos1Coefs[i]; j++ )
1960 {
1961 s << " [" << j << "]: sos1Coefs = " << sos1Coefs[i][j] << ", idxSos1CoefsVars = " << idxSos1CoefsVars[i][j] << std::endl;
1962 }
1963 }
1964
1965 /*********************************
1966 * for SOS2 constraints *
1967 *********************************/
1968 s << "nSos2Conss = " << nSos2Conss << std::endl;
1969 for( int i = 0; i < nSos2Conss; i++ )
1970 {
1971 s << "[" << i << "]: idxSos2ConsNames = " << idxSos2ConsNames[i]
1972 << ", nSos2Coefs = " << nSos2Coefs[i] << std::endl;
1973 for(int j = 0; j < nSos2Coefs[i]; j++ )
1974 {
1975 s << " [" << j << "]: sos2Coefs = " << sos2Coefs[i][j] << ", idxSos2CoefsVars = " << idxSos2CoefsVars[i][j] << std::endl;
1976 }
1977 }
1978
1979 /**********************************
1980 * for aggregated constrains *
1981 *********************************/
1982 s << "nAggregatedConss = " << nAggregatedConss << ", lAggregatedVarNames = " << lAggregatedVarNames
1983 << ", lAggregatedConsNames = " << lAggregatedConsNames << std::endl;
1984 for(int i = 0; i < nAggregatedConss; i++)
1985 {
1986 s << "[" << i << "]: aggregatedVarNames = " << aggregatedVarNames[posAggregatedVarNames[i]]
1987 << ", aggregatedConsNames = " << aggregatedConsNames[posAggregatedConsNames[i]]
1988 << ", aggregatedLhsAndLhss = " << aggregatedLhsAndLhss[i] << ", nAggregatedCoefs = " << nAggregatedCoefs[i] << std::endl;
1989 for(int j = 0; j < nAggregatedCoefs[i]; j++ )
1990 {
1991 s << " [" << j << "]: aggregatedCoefs = " << aggregatedCoefs[i][j]
1992 << ", idxAggregatedCoefsVars = " << idxAggregatedCoefsVars[i][j] << std::endl;
1993 }
1994 }
1995 return s.str();
1996}
1997
Base class for instance data.
void setParametersInScip(SCIP *scip)
void setLinearConstraint(SCIP *scip, int c, SCIP_CONS *cons)
bool addRootNodeCuts(SCIP *scip, ScipDiffParamSet *scipDiffParamSetRoot)
void setSos2Constraint(SCIP *scip, int c, SCIP_CONS *cons, SCIP_CONS **consSOS2)
void setAggregatedConstrains(SCIP *scip, int nvars, int nAggregatedVars, SCIP_VAR **aggregatedVars)
void createVarboundConstraintsInSCIP(SCIP *scip)
void setAggregatedConstraint(SCIP *scip, int c, const char *constName, SCIP_VAR **vars, SCIP_Real *vals, int nvars, SCIP_Real lhsAndrhs)
void setSos1Constraint(SCIP *scip, int c, SCIP_CONS *cons, SCIP_CONS **consSOS1)
virtual const char * getFileName()=0
void createSetppcConstraintsInSCIP(SCIP *scip)
void createLinearConstraintsInSCIP(SCIP *scip)
void addOrdinaryConstraintName(int c, SCIP_CONS *cons)
SCIP_BOUNDTYPE ** boundTypesBoundDisjunction
void setSetppcConstraint(SCIP *scip, int c, SCIP_CONS *cons)
ScipUserPlugins * userPlugins
void getActiveVariables(SCIP *scip, SCIP_VAR **vars, SCIP_Real *scalars, int *nvars, SCIP_Real *constant, SCIP_Bool transformed)
void collectAggregatedVars(SCIP *scip, int nvars, SCIP_VAR **vars, int *nAggregatedVars, SCIP_VAR ***aggregatedVars, SCIP_HASHTABLE **varAggregated)
void createSos1ConstraintsInSCIP(SCIP *scip)
void setKnapsackConstraint(SCIP *scip, int c, SCIP_CONS *cons)
void setBoundDisjunctionConstraint(SCIP *scip, int c, SCIP_CONS *cons)
void createSos2ConstraintsInSCIP(SCIP *scip)
void createBoundDisjunctionConstraintInSCIP(SCIP *scip)
void setVarboundConstraint(SCIP *scip, int c, SCIP_CONS *cons)
void setLogicorConstraint(SCIP *scip, int c, SCIP_CONS *cons)
void createProblem(SCIP *scip, int method, bool noPreprocessingInLC, bool usetRootNodeCuts, ScipDiffParamSet *scipDiffParamSetRoot, ScipDiffParamSet *scipDiffParamSet, char *settingsNameLC, char *isolname)
void createLogicorConstraintsInSCIP(SCIP *scip)
void createKnapsackConstraintsInSCIP(SCIP *scip)
void createAggregatedVarsAndConstrainsInSCIP(SCIP *scip)
void includeUserPlugins(SCIP *inScip)
static const int LpMaxNamelen
Definition: paraDef.h:180
Defines for UG Framework.
#define THROW_LOGICAL_ERROR1(msg1)
Definition: paraDef.h:52
#define THROW_LOGICAL_ERROR2(msg1, msg2)
Definition: paraDef.h:69
#define THROW_LOGICAL_ERROR3(msg1, msg2, msg3)
Definition: paraDef.h:86
static SCIP_DECL_HASHGETKEY(hashGetKeyVar)
static const char * PRESOLVED_INSTANCE
static SCIP_DECL_HASHKEYEQ(hashKeyEqVar)
static SCIP_DECL_HASHKEYVAL(hashKeyValVar)
ParaInstance extenstion for SCIP solver.