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-2025 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#if SCIP_APIVERSION >= 128
624 SCIP_CALL_ABORT( SCIPgetProbvarLinearSum(scip, vars, scalars, nvars, *nvars, constant, &requiredsize) );
625#else
626 SCIP_CALL_ABORT( SCIPgetProbvarLinearSum(scip, vars, scalars, nvars, *nvars, constant, &requiredsize, TRUE) );
627#endif
628
629 if( requiredsize > *nvars )
630 {
631 *nvars = requiredsize;
632 SCIP_CALL_ABORT( SCIPreallocBufferArray(scip, &vars, *nvars ) );
633 SCIP_CALL_ABORT( SCIPreallocBufferArray(scip, &scalars, *nvars ) );
634
635#if SCIP_APIVERSION >= 128
636 SCIP_CALL_ABORT( SCIPgetProbvarLinearSum(scip, vars, scalars, nvars, *nvars, constant, &requiredsize) );
637#else
638 SCIP_CALL_ABORT( SCIPgetProbvarLinearSum(scip, vars, scalars, nvars, *nvars, constant, &requiredsize, TRUE) );
639#endif
640 assert( requiredsize <= *nvars );
641 }
642 }
643 else
644 {
645 for( v = 0; v < *nvars; ++v )
646 SCIP_CALL_ABORT( SCIPvarGetOrigvarSum(&vars[v], &scalars[v], constant) );
647 }
648}
649
650/***********************************************************************************************
651 * collectAggregatedVars is copied from read_lp.c of SCIP code
652 */
653void
655 SCIP* scip, /**< SCIP data structure */
656 int nvars, /**< number of mutable variables in the problem */
657 SCIP_VAR** vars, /**< variable array */
658 int* nAggregatedVars, /**< number of aggregated variables on output */
659 SCIP_VAR*** aggregatedVars, /**< array storing the aggregated variables on output */
660 SCIP_HASHTABLE** varAggregated /**< hashtable for checking duplicates */
661 )
662{
663 int j;
664
665 /* check variables */
666 for (j = 0; j < nvars; ++j)
667 {
668 SCIP_VARSTATUS status;
669 SCIP_VAR* var;
670
671 var = vars[j];
672 status = SCIPvarGetStatus(var);
673
674 /* collect aggregated variables in a list */
675 if( status >= SCIP_VARSTATUS_AGGREGATED )
676 {
677 assert( status == SCIP_VARSTATUS_AGGREGATED ||
678 status == SCIP_VARSTATUS_MULTAGGR ||
679 status == SCIP_VARSTATUS_NEGATED );
680
681 if ( ! SCIPhashtableExists(*varAggregated, (void*) var) )
682 {
683 (*aggregatedVars)[(*nAggregatedVars)++] = var;
684 SCIP_CALL_ABORT( SCIPhashtableInsert(*varAggregated, (void*) var) );
685 }
686 }
687 }
688}
689
690void
692 SCIP* scip, /**< SCIP data structure */
693 int c, /** aggregated constraint number */
694 const char* constName, /**< constraint name */
695 SCIP_VAR** vars, /**< array of variables */
696 SCIP_Real* vals, /**< array of values */
697 int nvars, /**< number of variables */
698 SCIP_Real lhsAndrhs /**< right hand side = left hand side */
699 )
700{
702 (void) strcpy( &aggregatedVarNames[lAggregatedVarNames], SCIPvarGetName(vars[c]) );
703 lAggregatedVarNames += strlen( SCIPvarGetName(vars[c]) );
704
706 (void) strcpy( &aggregatedConsNames[lAggregatedConsNames], constName );
707 lAggregatedConsNames += strlen( constName )+ 1;
708
709 aggregatedLhsAndLhss[c] = lhsAndrhs;
710 nAggregatedCoefs[c] = nvars;
711 int v;
712 for(v = 0; v < nvars - 1; ++v)
713 {
714 aggregatedCoefs[nLinearConss][v] = vals[v];
715 idxLinearCoefsVars[nLinearConss][v] = SCIPvarGetProbindex(vars[v]);
716 }
717 aggregatedCoefs[nLinearConss][v] = vals[v];
720}
721
722void
724 SCIP* scip, /**< SCIP data structure */
725 int nvars, /**< number of mutable variables in the problem */
726 int nAggregatedVars, /**< number of aggregated variables */
727 SCIP_VAR** aggregatedVars /**< array storing the aggregated variables */
728 )
729{
730 SCIP_VAR** activevars;
731 SCIP_Real* activevals;
732 int nactivevars;
733 SCIP_Real activeconstant = 0.0;
734 char consname[UG::LpMaxNamelen];
735
736 assert( scip != NULL );
737
738 /* write aggregation constraints */
739 SCIP_CALL_ABORT( SCIPallocBufferArray(scip, &activevars, nvars) );
740 SCIP_CALL_ABORT( SCIPallocBufferArray(scip, &activevals, nvars) );
741
742 /* compute lengths of aggregatedVarNames and aggregatedConsNames areas */
745 for( int j = 0; j < nAggregatedVars; j++ )
746 {
747 lAggregatedVarNames += strlen(SCIPvarGetName(aggregatedVars[j])) + 1;
748 (void) SCIPsnprintf(consname, UG::LpMaxNamelen, "aggr_%s", SCIPvarGetName(aggregatedVars[j]));
749 lAggregatedConsNames += strlen(consname) + 1;
750 }
751
752 if( nAggregatedVars )
753 {
754 /* allocate aggregatedVarNames and aggregatedConsNames areas */
757 }
758
759 /* set aggregated constraints */
763 for (int j = 0; j < nAggregatedVars; ++j)
764 {
765 /* set up list to obtain substitution variables */
766 nactivevars = 1;
767
768 activevars[0] = aggregatedVars[j];
769 activevals[0] = 1.0;
770 activeconstant = 0.0;
771
772 /* retransform given variables to active variables */
773 getActiveVariables(scip, activevars, activevals, &nactivevars, &activeconstant, TRUE);
774
775 activevals[nactivevars] = -1.0;
776 activevars[nactivevars] = aggregatedVars[j];
777 ++nactivevars;
778
779 /* set constraint */
780 (void) SCIPsnprintf(consname, UG::LpMaxNamelen, "aggr_%s", SCIPvarGetName(aggregatedVars[j]));
781 setAggregatedConstraint(scip, j, consname, activevars, activevals, nactivevars, - activeconstant );
782 }
783 assert(nAggregatedConss == nAggregatedVars);
784
785 /* free buffer arrays */
786 SCIPfreeBufferArray(scip, &activevars);
787 SCIPfreeBufferArray(scip, &activevals);
788}
789
790void
792 SCIP *scip
793 )
794{
795 SCIP_VAR **vars = SCIPgetVars(scip);
796 for(int c = 0; c < nAggregatedConss; ++c )
797 {
798 SCIP_CONS* cons;
799 SCIP_VAR **varsInCons = new SCIP_VAR*[nAggregatedCoefs[c]];
800 int v;
801 for( v = 0; v < nAggregatedCoefs[c] - 1; v++)
802 {
803 varsInCons[v] = vars[idxAggregatedCoefsVars[c][v]];
804 }
805 SCIP_VAR* newvar;
806 /* create new variable of the given name */
807 SCIP_CALL_ABORT( SCIPcreateVar(scip, &newvar, &aggregatedVarNames[posAggregatedVarNames[c]], 0.0, 1.0, 0.0, SCIP_VARTYPE_BINARY,
808 TRUE, FALSE, NULL, NULL, NULL, NULL, NULL) );
809 SCIP_CALL_ABORT( SCIPaddVar(scip, newvar) );
810 /* because the variable was added to the problem, it is captured by SCIP and we can safely release it right now
811 * without making the returned *var invalid
812 */
813 varsInCons[v] = newvar;
814 assert( SCIPvarGetProbindex(newvar) == (nVars + c) );
815 SCIP_CALL_ABORT( SCIPreleaseVar(scip, &newvar) );
816
817 SCIP_CALL_ABORT( SCIPcreateConsLinear(scip, &cons,
819 TRUE, TRUE, TRUE, TRUE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE) );
820 SCIP_CALL_ABORT( SCIPaddCons(scip, cons) );
821 SCIPdebug( SCIP_CALL_ABORT( SCIPprintCons(scip, cons, NULL) ) );
822 SCIP_CALL_ABORT( SCIPreleaseCons(scip, &cons) );
823 delete [] varsInCons;
824 }
825}
826
827/** constractor : only called from ScipInitiator */
829 SCIP *scip,
830 int method
831 ) : orgScip(0), paraInstanceScip(0), lProbName(0), probName(0), nCopies(0), origObjSense(0), objScale(0.0), objOffset(0.0), nVars(0), varIndexRange(0),
832 varLbs(0), varUbs(0), objCoefs(0), varTypes(0), lVarNames(0), varNames(0),
833 posVarNames(0), mapToOriginalIndecies(0), mapToSolverLocalIndecies(0), // mapToProbIndecies(0),
834 nConss(0), lConsNames(0), consNames(0),
835 posConsNames(0), copyIncreasedVariables(false),
836 nLinearConss(0), idxLinearConsNames(0), linearLhss(0),
837 linearRhss(0), nLinearCoefs(0), linearCoefs(0), idxLinearCoefsVars(0),
838 nSetppcConss(0), idxSetppcConsNames(0), nIdxSetppcVars(0), setppcTypes(0),
839 idxSetppcVars(0), nLogicorConss(0), idxLogicorConsNames(0), nIdxLogicorVars(0), idxLogicorVars(0),
840 nKnapsackConss(0), idxKnapsackConsNames(0), capacities(0), nLKnapsackCoefs(0),
841 knapsackCoefs(0), idxKnapsackCoefsVars(0),
842 nVarboundConss(0), idxVarboundConsNames(0), varboundLhss(0),varboundRhss(0), idxVarboundCoefVar1s(0),
843 varboundCoef2s(0), idxVarboundCoefVar2s(0),
844 nVarBoundDisjunctionConss(0), idxBoundDisjunctionConsNames(0), nVarsBoundDisjunction(0),
845 idxVarBoundDisjunction(0), boundTypesBoundDisjunction(0), boundsBoundDisjunction(0),
846 nSos1Conss(0),idxSos1ConsNames(0), nSos1Coefs(0), sos1Coefs(0), idxSos1CoefsVars(0),
847 nSos2Conss(0), idxSos2ConsNames(0), nSos2Coefs(0), sos2Coefs(0), idxSos2CoefsVars(0),
848 nAggregatedConss(0), lAggregatedVarNames(0), aggregatedVarNames(0), posAggregatedVarNames(0),
849 lAggregatedConsNames(0), aggregatedConsNames(0), posAggregatedConsNames(0),
850 aggregatedLhsAndLhss(0), nAggregatedCoefs(0), aggregatedCoefs(0), idxAggregatedCoefsVars(0),
851 userPlugins(0)
852{
853 assert( scip != NULL );
854 assert( SCIPgetStage(scip) == SCIP_STAGE_TRANSFORMED ||
855 SCIPgetStage(scip) == SCIP_STAGE_PRESOLVED ||
856 SCIPgetStage(scip) == SCIP_STAGE_SOLVING ||
857 SCIPgetStage(scip) == SCIP_STAGE_SOLVED ); // in case that presolving or root node solving solved the problem
858
859 // assert( SCIPgetStage(scip) == SCIP_STAGE_PRESOLVED ||
860 // SCIPgetStage(scip) == SCIP_STAGE_SOLVING ||
861 // SCIPgetStage(scip) == SCIP_STAGE_SOLVED ); // in case that presolving or root node solving solved the problem
862
863 lProbName = strlen(SCIPgetProbName(scip));
864 probName = new char[lProbName+1];
865 strcpy(probName, SCIPgetProbName(scip));
866
867 /** set objsen */
868 origObjSense = SCIPgetObjsense(scip); // always minimization problem
869 objScale = SCIPgetTransObjscale(scip); // Stefan is making now
870 objOffset = SCIPgetTransObjoffset(scip); // Stefan is making now
871
873
874 if( SCIPgetStage(scip) == SCIP_STAGE_TRANSFORMED || SCIPgetStage(scip) == SCIP_STAGE_SOLVED ) return;
875
876 if( method == 2 )
877 {
878 return; // Solver reads given instance file.
879 }
880
881 // if( method == 0 || method == 2 )
882 if( method == 0 )
883 {
884 nVars = SCIPgetNVars(scip);
886 SCIP_VAR **vars = SCIPgetVars(scip);
887
888 /* make varName and objCoefs and ovnm */
889 posVarNames = new int[nVars];
890 objCoefs = new SCIP_Real[nVars];
891 // mapToOriginalIndecies = new int[nVars];
892
893 lVarNames = 0;
894 for(int v = 0; v < nVars; ++v)
895 {
897 objCoefs[v] = SCIPvarGetObj(vars[v]);
898 assert(SCIPvarGetProbindex(vars[v])!=-1);
899 assert(SCIPvarGetProbindex(vars[v]) == v);
900 lVarNames += strlen(SCIPvarGetName(vars[v])) + 1;
901 }
902 varNames = new char[lVarNames];
903 varLbs = new SCIP_Real[nVars];
904 varUbs = new SCIP_Real[nVars];
905 varTypes = new int[nVars];
906 for(int v = 0; v < nVars; ++v )
907 {
908 SCIP_VAR *var = vars[v];
909 strcpy (&varNames[posVarNames[v]], SCIPvarGetName(var) );
910 varLbs[SCIPvarGetProbindex(var)] = SCIPvarGetLbLocal(var); //* we should use global?
911 varUbs[SCIPvarGetProbindex(var)] = SCIPvarGetUbLocal(var); //* we should use global?
912 varTypes[SCIPvarGetProbindex(var)] = SCIPvarGetType(var);
913 }
914
915 /*
916 if( method == 2 )
917 {
918 return; // Solver reads given instance file.
919 }
920 */
921
922 /* make constraints */
923 nConss = SCIPgetNConss(scip);
924 SCIP_CONS **conss = SCIPgetConss(scip);
925
926 if( nConss > 0 )
927 {
928 posConsNames = new int[nConss];
929 }
930 int tempSizeConsNames = 0;
931 /* make consNames map */
932 for( int c = 0; c < nConss; c++ )
933 {
934 tempSizeConsNames += strlen(SCIPconsGetName(conss[c])) + 1;
935 }
936 if( tempSizeConsNames > 0 )
937 {
938 consNames = new char[tempSizeConsNames];
939 }
940
941 SCIP_CONS** consSOS1;
942 SCIP_CONS** consSOS2;
943 nSos1Conss = 0;
944 nSos2Conss = 0;
945
946 /** collect SOS constraints in array for later output */
947 SCIP_CALL_ABORT( SCIPallocBufferArray(scip, &consSOS1, nConss) );
948 SCIP_CALL_ABORT( SCIPallocBufferArray(scip, &consSOS2, nConss) );
949
950 SCIP_CONS *cons;
951 const char* conshdlrname;
952 SCIP_CONSHDLR* conshdlr;
953
954 int nNotInitialActiveConss = 0;
955
956 /** count number of each constraint */
957 for (int c = 0; c < nConss; ++c)
958 {
959 cons = conss[c];
960 assert( cons != NULL);
961
962 /* in case the transformed is written only constraint are posted which are enabled in the current node */
963 if( !SCIPconsIsEnabled(cons) )
964 continue;
965
966 conshdlr = SCIPconsGetHdlr(cons);
967 assert( conshdlr != NULL );
968
969 if( SCIPconshdlrGetStartNActiveConss(conshdlr) > 0 )
970 {
971 conshdlrname = SCIPconshdlrGetName(conshdlr);
972 assert( SCIPconsIsTransformed(cons) );
973
974 if( strcmp(conshdlrname, "linear") == 0 )
975 {
976 nLinearConss++;
977 }
978 else if( strcmp(conshdlrname, "setppc") == 0 )
979 {
980 nSetppcConss++;
981 }
982 else if ( strcmp(conshdlrname, "logicor") == 0 )
983 {
985 }
986 else if ( strcmp(conshdlrname, "knapsack") == 0 )
987 {
989 }
990 else if ( strcmp(conshdlrname, "varbound") == 0 )
991 {
993 }
994 else if ( strcmp(conshdlrname, "bounddisjunction") == 0 )
995 {
997 }
998 else if ( strcmp(conshdlrname, "SOS1") == 0 )
999 {
1000 nSos1Conss++;
1001 }
1002 else if ( strcmp(conshdlrname, "SOS2") == 0 )
1003 {
1004 nSos2Conss++;
1005 }
1006 else
1007 {
1008 THROW_LOGICAL_ERROR3("constraint handler <", conshdlrname, "> can not print requested format");
1009 }
1010 }
1011 else
1012 {
1013 nNotInitialActiveConss++;
1014 }
1015 }
1016
1018
1020
1021 /** re-initialize counters for ordinary constraints */
1022 nLinearConss = 0;
1023 nSetppcConss = 0;
1024 nLogicorConss = 0;
1025 nKnapsackConss = 0;
1026 nVarboundConss = 0;
1028 nSos1Conss = 0;
1029 nSos2Conss = 0;
1030 nNotInitialActiveConss = 0;
1031
1032 /** initialize length of constraint names area */
1033 lConsNames = 0;
1034 for (int c = 0; c < nConss; ++c)
1035 {
1036 cons = conss[c];
1037
1038 /* in case the transformed is written only constraint are posted which are enabled in the current node */
1039 if( !SCIPconsIsEnabled(cons) )
1040 continue;
1041
1042 conshdlr = SCIPconsGetHdlr(cons);
1043
1044 if( SCIPconshdlrGetStartNActiveConss(conshdlr) > 0 )
1045 {
1046 conshdlrname = SCIPconshdlrGetName(conshdlr);
1047
1048 if( strcmp(conshdlrname, "linear") == 0 )
1049 {
1050 setLinearConstraint( scip, c, cons );
1051 }
1052 else if( strcmp(conshdlrname, "setppc") == 0 )
1053 {
1054 setSetppcConstraint( scip, c, cons );
1055 }
1056 else if ( strcmp(conshdlrname, "logicor") == 0 )
1057 {
1058 setLogicorConstraint( scip, c, cons );
1059 }
1060 else if ( strcmp(conshdlrname, "knapsack") == 0 )
1061 {
1062 setKnapsackConstraint( scip, c, cons );
1063 }
1064 else if ( strcmp(conshdlrname, "varbound") == 0 )
1065 {
1066 setVarboundConstraint( scip, c, cons );
1067 }
1068 else if ( strcmp(conshdlrname, "bounddisjunction") == 0 )
1069 {
1071 }
1072 else if ( strcmp(conshdlrname, "SOS1") == 0 )
1073 {
1074 setSos1Constraint( scip, c, cons, consSOS1);
1075 }
1076 else if ( strcmp(conshdlrname, "SOS2") == 0 )
1077 {
1078 setSos2Constraint( scip, c, cons, consSOS2);
1079 }
1080 }
1081 else
1082 {
1083 nNotInitialActiveConss++;
1084 }
1085 }
1086
1088
1089 SCIP_VAR** aggregatedVars;
1090 int nAggregatedVars = 0;
1091 SCIP_HASHTABLE* varAggregated;
1092
1093 // create hashtable for storing aggregated variables
1094 SCIP_CALL_ABORT( SCIPallocBufferArray(scip, &aggregatedVars, nVars) );
1095 SCIP_CALL_ABORT( SCIPhashtableCreate(&varAggregated, SCIPblkmem(scip), 1000, hashGetKeyVar, hashKeyEqVar, hashKeyValVar,
1096 NULL) );
1097
1098 // check for aggregated variables in SOS1 constraints and output aggregations as linear constraints
1099 for (int c = 0; c < nSos1Conss; ++c)
1100 {
1101 cons = consSOS1[c];
1102 SCIP_VAR **consvars = SCIPgetVarsSOS1(scip, cons);
1103 int nconsvars = SCIPgetNVarsSOS1(scip, cons);
1104
1105 collectAggregatedVars(scip, nconsvars, consvars, &nAggregatedVars, &aggregatedVars, &varAggregated);
1106 }
1107
1108 // check for aggregated variables in SOS2 constraints and output aggregations as linear constraints
1109 for (int c = 0; c < nSos2Conss; ++c)
1110 {
1111 cons = consSOS2[c];
1112 SCIP_VAR **consvars = SCIPgetVarsSOS2(scip, cons);
1113 int nconsvars = SCIPgetNVarsSOS2(scip, cons);
1114
1115 collectAggregatedVars(scip, nconsvars, consvars, &nAggregatedVars, &aggregatedVars, &varAggregated);
1116 }
1117
1118 // set aggregation constraints
1119 setAggregatedConstrains(scip, nVars, nAggregatedVars, aggregatedVars );
1120
1121 // free space
1122 SCIPfreeBufferArray(scip, &aggregatedVars);
1123 SCIPhashtableFree(&varAggregated);
1124
1125 // free space
1126 SCIPfreeBufferArray(scip, &consSOS1);
1127 SCIPfreeBufferArray(scip, &consSOS2);
1128 }
1129 else
1130 {
1131 SCIP_CALL_ABORT( SCIPwriteTransProblem(scip, PRESOLVED_INSTANCE, "cip", TRUE ) );
1132 }
1133}
1134
1136 )
1137{
1138 if(probName) delete[] probName;
1139 if(varLbs) delete[] varLbs;
1140 if(varUbs) delete[] varUbs;
1141 if(objCoefs) delete[] objCoefs;
1142 if(varTypes) delete[] varTypes;
1143 if(varNames) delete[] varNames;
1144 if(posVarNames) delete[] posVarNames;
1147 // if(mapToProbIndecies) delete[] mapToProbIndecies;
1148 if(consNames) delete[] consNames;
1149 if(posConsNames) delete[] posConsNames;
1150
1151 /** for linear constraints */
1152 if( nLinearConss > 0 )
1153 {
1154 if( idxLinearConsNames ) delete [] idxLinearConsNames;
1155 if( linearLhss ) delete [] linearLhss;
1156 if( linearRhss ) delete [] linearRhss;
1157 if( nLinearCoefs )
1158 {
1159 for(int i = 0; i < nLinearConss; i++ )
1160 {
1161 delete [] linearCoefs[i];
1162 delete [] idxLinearCoefsVars[i];
1163 }
1164 delete [] linearCoefs;
1165 delete [] idxLinearCoefsVars;
1166 delete [] nLinearCoefs;
1167 }
1168 }
1169 /** for setppc constraints */
1170 if( nSetppcConss )
1171 {
1172 if( idxSetppcConsNames ) delete [] idxSetppcConsNames;
1173 if( nIdxSetppcVars ) delete [] nIdxSetppcVars;
1174 if( setppcTypes ) delete [] setppcTypes;
1175 if( idxSetppcVars )
1176 {
1177 for(int i = 0; i < nSetppcConss; i++ )
1178 {
1179 delete idxSetppcVars[i];
1180 }
1181 delete [] idxSetppcVars;
1182 }
1183 }
1184 /** for logical constraints */
1185 if(nLogicorConss)
1186 {
1188 if( nIdxLogicorVars ) delete [] nIdxLogicorVars;
1189 if( idxLogicorVars )
1190 {
1191 for( int i = 0; i < nLogicorConss; i++ )
1192 {
1193 delete [] idxLogicorVars[i];
1194 }
1195 delete [] idxLogicorVars;
1196 }
1197 }
1198 /** for knapsack constraints */
1199 if(nKnapsackConss)
1200 {
1202 if( capacities ) delete [] capacities;
1203 if( nLKnapsackCoefs ) delete [] nLKnapsackCoefs;
1204 if( knapsackCoefs )
1205 {
1206 for( int i = 0; i < nKnapsackConss; i++ )
1207 {
1208 delete [] knapsackCoefs[i];
1209 delete [] idxKnapsackCoefsVars[i];
1210 }
1211 delete [] knapsackCoefs;
1212 delete [] idxKnapsackCoefsVars;
1213 }
1214 }
1215 /** for varbound constraints */
1216 if( nVarboundConss )
1217 {
1220 if( varboundCoef2s ) delete [] varboundCoef2s;
1222 }
1223
1224 /** for bounddisjunction constraints */
1226 {
1229 for( int c = 0; c < nVarBoundDisjunctionConss; c++ )
1230 {
1234 }
1235 }
1236
1237 /** for SOS1 constraints */
1238 if( nSos1Conss )
1239 {
1240 if( nSos1Coefs ) delete [] nSos1Coefs;
1241 if( sos1Coefs )
1242 {
1243 for( int i = 0; i < nSos1Conss; i++ )
1244 {
1245 delete [] sos1Coefs[i];
1246 delete [] idxSos1CoefsVars[i];
1247 }
1248 delete [] sos1Coefs;
1249 delete [] idxSos1CoefsVars;
1250 }
1251 }
1252 /** for SOS2 constraints */
1253 if( nSos2Conss )
1254 {
1255 if( nSos2Coefs ) delete [] nSos2Coefs;
1256 if( sos2Coefs )
1257 {
1258 for( int i = 0; i < nSos1Conss; i++ )
1259 {
1260 delete [] sos2Coefs[i];
1261 delete [] idxSos2CoefsVars[i];
1262 }
1263 delete sos2Coefs;
1264 delete idxSos2CoefsVars;
1265 }
1266 }
1267 /** for agrregated constraints */
1268 if( nAggregatedConss )
1269 {
1270 for( int i = 0; i < nAggregatedConss; i++ )
1271 {
1272 delete aggregatedCoefs[i];
1273 delete idxAggregatedCoefsVars[i];
1274 }
1275 delete [] aggregatedCoefs;
1276 delete [] idxAggregatedCoefsVars;
1277 aggregatedCoefs = 0;
1279
1280 if( aggregatedVarNames ) delete [] aggregatedVarNames;
1285 }
1286
1287 if( userPlugins ) delete userPlugins;
1288}
1289
1290bool
1292 SCIP *tempScip,
1293 ScipDiffParamSet *scipDiffParamSetRoot
1294 )
1295{
1296 SCIP_Longint originalLimitsNodes;
1297 SCIP_CALL_ABORT( SCIPgetLongintParam(tempScip, "limits/nodes", &originalLimitsNodes) );
1298 SCIP_CALL_ABORT( SCIPsetLongintParam(tempScip, "limits/nodes", 1) );
1299 if( scipDiffParamSetRoot ) scipDiffParamSetRoot->setParametersInScip(tempScip);
1300 SCIP_RETCODE ret = SCIPsolve(tempScip);
1301 if( ret != SCIP_OKAY )
1302 {
1303 exit(1); // LC should abort
1304 }
1305 // Then, solver status should be checked
1306 SCIP_STATUS status = SCIPgetStatus(tempScip);
1307 if( status == SCIP_STATUS_OPTIMAL ) // when sub-MIP is solved at root node, the solution may not be saved
1308 {
1309 return false;
1310 }
1311 else
1312 {
1313 if( status == SCIP_STATUS_MEMLIMIT )
1314 {
1315 std::cout << "Warning: SCIP was interrupted because the memory limit was reached" << std::endl;
1316 return false;
1317 }
1318 }
1319
1320 SCIP_CUT** cuts;
1321 int ncuts;
1322 int ncutsadded;
1323
1324 ncutsadded = 0;
1325 cuts = SCIPgetPoolCuts(tempScip);
1326 ncuts = SCIPgetNPoolCuts(tempScip);
1327 for( int c = 0; c < ncuts; ++c )
1328 {
1329 SCIP_ROW* row;
1330
1331 row = SCIPcutGetRow(cuts[c]);
1332 assert(!SCIProwIsLocal(row));
1333 assert(!SCIProwIsModifiable(row));
1334 if( SCIPcutGetAge(cuts[c]) == 0 && SCIProwIsInLP(row) )
1335 {
1336 char name[SCIP_MAXSTRLEN];
1337 SCIP_CONS* cons;
1338 SCIP_COL** cols;
1339 SCIP_VAR** vars;
1340 int ncols;
1341 int i;
1342
1343 /* create a linear constraint out of the cut */
1344 cols = SCIProwGetCols(row);
1345 ncols = SCIProwGetNNonz(row);
1346
1347 SCIP_CALL_ABORT( SCIPallocBufferArray(tempScip, &vars, ncols) );
1348 for( i = 0; i < ncols; ++i )
1349 vars[i] = SCIPcolGetVar(cols[i]);
1350
1351 (void) SCIPsnprintf(name, SCIP_MAXSTRLEN, "%s_%d", SCIProwGetName(row), SCIPgetNRuns(tempScip));
1352 SCIP_CALL_ABORT( SCIPcreateConsLinear(tempScip, &cons, name, ncols, vars, SCIProwGetVals(row),
1353 SCIProwGetLhs(row) - SCIProwGetConstant(row), SCIProwGetRhs(row) - SCIProwGetConstant(row),
1354 TRUE, TRUE, FALSE, FALSE, TRUE, FALSE, FALSE, FALSE, TRUE, FALSE) );
1355 SCIP_CALL_ABORT( SCIPaddCons(tempScip, cons) );
1356 SCIP_CALL_ABORT( SCIPreleaseCons(tempScip, &cons) );
1357
1358 SCIPfreeBufferArray(tempScip, &vars);
1359
1360 ncutsadded++;
1361 }
1362 }
1363 SCIP_CALL_ABORT( SCIPsetLongintParam(tempScip, "limits/nodes", originalLimitsNodes) );
1364 return true;
1365}
1366
1367/** create presolved problem instance that is solved by ParaSCIP */
1368void
1370 SCIP *scip,
1371 int method,
1372 bool noPreprocessingInLC,
1373 bool usetRootNodeCuts,
1374 ScipDiffParamSet *scipDiffParamSetRoot,
1375 ScipDiffParamSet *scipDiffParamSet,
1376 char *settingsNameLC,
1377 char *isolname
1378 )
1379{
1380
1381 switch ( method )
1382 {
1383 case 0 :
1384 {
1385 SCIP_CALL_ABORT( SCIPcreateProb(scip, probName, NULL, NULL, NULL, NULL, NULL, NULL, NULL) );
1386 SCIP_CALL_ABORT( SCIPsetObjsense(scip, SCIP_OBJSENSE_MINIMIZE) );
1387 for(int v = 0; v < nVars; ++v)
1388 {
1389 SCIP_VAR* newvar;
1390
1391 /* create new variable of the given name */
1392 SCIP_CALL_ABORT( SCIPcreateVar(scip, &newvar, &varNames[posVarNames[v]], varLbs[v], varUbs[v], objCoefs[v],
1393 SCIP_Vartype(varTypes[v]),
1394 TRUE, FALSE, NULL, NULL, NULL, NULL, NULL) );
1395 SCIP_CALL_ABORT( SCIPaddVar(scip, newvar) );
1396 assert( SCIPvarGetProbindex(newvar) == v );
1397 /* because the variable was added to the problem, it is captured by SCIP and we can safely release it right now
1398 * without making the returned *var invalid
1399 */
1400 SCIP_CALL_ABORT( SCIPreleaseVar(scip, &newvar) );
1401 }
1402
1403 if( nLinearConss )
1405 if( nSetppcConss)
1407 if( nLogicorConss )
1409 if( nKnapsackConss )
1411 if( nVarboundConss )
1415 if( nSos1Conss )
1417 if( nSos2Conss )
1419 if( nAggregatedConss )
1421 break;
1422 }
1423 case 1 :
1424 {
1425 if( scipDiffParamSet ) scipDiffParamSet->setParametersInScip(scip);
1426 SCIP_CALL_ABORT( SCIPreadProb(scip, PRESOLVED_INSTANCE, "cip" ) );
1427 nVars = SCIPgetNVars(scip);
1429 SCIP_VAR **vars = SCIPgetVars(scip);
1430 varLbs = new SCIP_Real[nVars];
1431 varUbs = new SCIP_Real[nVars];
1432 for(int v = 0; v < nVars; ++v )
1433 {
1434 SCIP_VAR *var = vars[v];
1435 varLbs[SCIPvarGetProbindex(var)] = SCIPvarGetLbLocal(var); //* we should use global?
1436 varUbs[SCIPvarGetProbindex(var)] = SCIPvarGetUbLocal(var); //* we should use global?
1437 }
1438 break;
1439 }
1440 case 2 :
1441 {
1442 SCIP *tempScip = 0;
1443 SCIP_Bool success = TRUE;
1444 SCIP_CALL_ABORT( SCIPcreate(&tempScip) );
1445 SCIP_CALL_ABORT( SCIPsetIntParam(tempScip, "timing/clocktype", 2) ); // always wall clock time
1446
1447 /* include default SCIP plugins */
1448 SCIP_CALL_ABORT( SCIPincludeDefaultPlugins(tempScip) );
1449 /** user include plugins */
1450 includeUserPlugins(tempScip);
1451
1452#ifdef SCIP_THREADSAFE_MESSAGEHDLRS
1453 SCIPsetMessagehdlrQuiet(tempScip, TRUE);
1454#endif
1455 // SCIP_CALL_ABORT( SCIPreadProb(tempScip, getFileName(), NULL ) );
1456 // std::cout << "file name = " << getFileName() << std::endl;
1457 // std::cout << "tempScip = " << tempScip << std::endl;
1458 if( scipDiffParamSet ) scipDiffParamSet->setParametersInScip(tempScip);
1459 int retcode = SCIPreadProb(tempScip, getFileName(), NULL );
1460 // assert( retcode == SCIP_OKAY );
1461 if( retcode != SCIP_OKAY )
1462 {
1463 std::cout << "SCIPreadProb returns: " << retcode << std::endl;
1464 if( getFileName()[0] == '.' )
1465 {
1466 char dir[512];
1467 std::cout << "Cannot read < " << getcwd(dir, 511) << "/" << getFileName() << std::endl;
1468 }
1469 else
1470 {
1471 std::cout << "Cannot read < " << getFileName() << std::endl;
1472 }
1473 exit(1);
1474 }
1475
1476 /* read initail solution, if it is specified */
1477 if( isolname )
1478 {
1479 SCIP_CALL_ABORT( SCIPtransformProb(tempScip));
1480 // NOTE:
1481 // When CPLEX license file cannot find, SCIPtransformProb(scip) may fail
1482 // SCIP_CALL_ABORT( SCIPreadSol(tempScip, isolname) );
1483 SCIP_CALL_ABORT( SCIPreadProb(tempScip, isolname, NULL ) );
1484 }
1485
1486 /* change problem name */
1487 char *probNameFromFileName;
1488 char *temp = new char[strlen(getFileName())+1];
1489 (void) strcpy(temp, getFileName());
1490 SCIPsplitFilename(temp, NULL, &probNameFromFileName, NULL, NULL);
1491 SCIP_CALL_ABORT( SCIPsetProbName(tempScip, probNameFromFileName));
1492
1493 /* presolve problem */
1494 if( noPreprocessingInLC )
1495 {
1496 SCIP_CALL_ABORT( SCIPsetIntParam(tempScip, "presolving/maxrounds", 0));
1497 }
1498 else
1499 {
1500 if( settingsNameLC )
1501 {
1502 SCIP_CALL_ABORT( SCIPreadParams(tempScip, settingsNameLC) );
1503 }
1504 /*
1505 else
1506 {
1507 SCIP_CALL_ABORT( SCIPsetPresolving(tempScip, SCIP_PARAMSETTING_FAST, TRUE) );
1508 }
1509 */
1510 }
1511 // SCIP_CALL_ABORT( SCIPsetIntParam(tempScip, "constraints/quadratic/replacebinaryprod", 0));
1512 // SCIP_CALL_ABORT( SCIPsetBoolParam(tempScip, "constraints/nonlinear/reformulate", FALSE));
1513 SCIP_CALL_ABORT( SCIPpresolve(tempScip) );
1514 SCIP_STATUS scipStatus = SCIPgetStatus(tempScip);
1515 if( scipStatus == SCIP_STATUS_OPTIMAL ) return; // the problem shold be solved in LC
1516
1517 /* adding root node cuts, if necessary */
1518 if( usetRootNodeCuts )
1519 {
1520 if( !addRootNodeCuts(tempScip,scipDiffParamSetRoot) )
1521 {
1522 return; // the problem shold be solved in LC
1523 }
1524 }
1525
1526 if( SCIPgetNVars(tempScip) == 0 ) // all variables were fixed in presolve
1527 {
1528 return; // the problem shold be solved in LC
1529 }
1530
1531 assert( SCIPgetStage(scip) == SCIP_STAGE_INIT );
1532
1533 assert( nCopies > 0 );
1534
1535 SCIP_HASHMAP* varmap = 0;
1536 SCIP_HASHMAP* conssmap = 0;
1537
1538 assert( nCopies == 1);
1539
1540 if( nCopies == 1 )
1541 {
1542 // SCIP_CALL_ABORT( SCIPfree(&scip) );
1543 // SCIP_CALL_ABORT( SCIPcreate(&scip) );
1544
1545 /* include default SCIP plugins */
1546 // SCIP_CALL_ABORT( SCIPincludeDefaultPlugins(scip) );
1547 /** user include plugins */
1548 // includeUserPlugins(scip);
1549
1550 /* copy all plugins and settings */
1551#if SCIP_APIVERSION >= 131
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, TRUE, TRUE, FALSE, &success) );
1554#elif SCIP_APIVERSION >= 101
1555 SCIP_CALL_ABORT( SCIPcopyPlugins(tempScip, scip, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE,
1556 TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, FALSE, &success) );
1557#elif SCIP_APIVERSION >= 100
1558 SCIP_CALL_ABORT( SCIPcopyPlugins(tempScip, scip, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE,
1559 TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, FALSE, &success) );
1560#elif SCIP_APIVERSION >= 17
1561 SCIP_CALL_ABORT( SCIPcopyPlugins(tempScip, scip, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE,
1562 TRUE, TRUE, TRUE, TRUE, TRUE, FALSE, &success) );
1563#else
1564 SCIP_CALL_ABORT( SCIPcopyPlugins(tempScip, scip, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE,
1565 TRUE, TRUE, TRUE, TRUE, FALSE, &success) );
1566#endif
1567 SCIP_CALL_ABORT( SCIPcopyParamSettings(tempScip, scip) );
1568
1569 /* create the variable mapping hash map */
1570 if( SCIPgetNVars(tempScip) > 0 )
1571 {
1572 SCIP_CALL_ABORT( SCIPhashmapCreate(&varmap, SCIPblkmem(scip), SCIPgetNVars(tempScip)) );
1573 }
1574 if( SCIPgetNConss(tempScip) > 0 )
1575 {
1576 SCIP_CALL_ABORT( SCIPhashmapCreate(&conssmap, SCIPblkmem(scip), SCIPgetNConss(tempScip)) );
1577 }
1578
1579 /* create problem in the target SCIP and copying the source original problem data */
1580 SCIP_CALL_ABORT( SCIPcopyProb(tempScip, scip, varmap, conssmap, TRUE, probNameFromFileName) );
1581 delete [] temp; // probNameFromFileName is in temp
1582
1583 /* copy all variables and constraints */
1584 if( SCIPgetNVars(tempScip) > 0 )
1585 {
1586#if (SCIP_VERSION < 321 || ( SCIP_VERSION == 321 && SCIP_SUBVERSION < 2) )
1587 SCIP_CALL_ABORT( SCIPcopyVars(tempScip, scip, varmap, conssmap, TRUE) );
1588#else
1589 SCIP_CALL_ABORT( SCIPcopyVars(tempScip, scip, varmap, conssmap, NULL, NULL, 0, TRUE) );
1590#endif
1591 }
1592 if( SCIPgetNConss(tempScip) > 0 )
1593 {
1594 SCIP_CALL_ABORT( SCIPcopyConss(tempScip, scip, varmap, conssmap, TRUE, FALSE, &success) );
1595 }
1596
1597#if SCIP_APIVERSION > 39
1598 if( success )
1599 {
1600 SCIP_Bool valid;
1601
1602 /* copy the Benders' decomposition plugins explicitly, because it requires the variable mapping hash map */
1603 SCIP_CALL_ABORT( SCIPcopyBenders(tempScip, scip, NULL, TRUE, &valid) );
1604 }
1605#endif
1606
1607 if( !success )
1608 {
1609 if( SCIPgetNConss(tempScip) > 0 )
1610 {
1611 SCIPhashmapFree(&conssmap);
1612 }
1613 if( SCIPgetNVars(tempScip) > 0 )
1614 {
1615 SCIPhashmapFree(&varmap);
1616 }
1617 SCIPfree(&tempScip);
1618 std::cerr << "Some constraint handler did not perform a valid copy. Cannot solve this instance." << std::endl;
1619 exit(1);
1620 }
1621 }
1622
1623 nVars = SCIPgetNVars(tempScip);
1625 int n = SCIPgetNVars(scip);
1626
1627 // std::cout << "nVars = " << nVars << ", varIndexRange = " << varIndexRange << ", n = " << n << std::endl;
1628
1629 assert( nVars <= n );
1630 if( nVars < n )
1631 {
1633 varIndexRange = n;
1634 }
1635 // mapToProbIndecies = new int[SCIPgetNTotalVars(scip)];
1636 mapToOriginalIndecies = new int[SCIPgetNTotalVars(tempScip)]; // need to allocate enough for SCIPvarGetIndex(copyvar)
1637 mapToSolverLocalIndecies = new int[SCIPgetNTotalVars(tempScip)];
1638 for( int i = 0; i < SCIPgetNTotalVars(tempScip); i++ )
1639 {
1640 // mapToProbIndecies[i] = -1;
1641 mapToOriginalIndecies[i] = -1;
1643 }
1644
1645 assert(SCIPgetNTotalVars(scip) >= SCIPgetNVars(tempScip));
1646
1647 // SCIP_VAR **srcVars = SCIPgetVars(tempScip);
1648 SCIP_VAR **srcVars = SCIPgetVars(tempScip);
1649 // SCIP_VAR **targetVars = SCIPgetVars(scip);
1650 // for( int i = 0; i < SCIPgetNTotalVars(scip); i++ )
1651 for( int i = 0; i < SCIPgetNVars(tempScip); i++ )
1652 {
1653 SCIP_VAR* copyvar = (SCIP_VAR*)SCIPhashmapGetImage(varmap, (void*)srcVars[i]);
1654 // std::cout << i << ": index = " << SCIPvarGetIndex(copyvar) << std::endl;
1655 // assert(SCIPvarGetIndex(copyvar) >= 0);
1656 // if( copyvar && SCIPvarGetProbindex(copyvar) < n )
1657 if( copyvar )
1658 {
1659 // assert(SCIPvarGetProbindex(copyvar) >= 0);
1660 mapToOriginalIndecies[SCIPvarGetIndex(copyvar)] = i;
1661 mapToSolverLocalIndecies[i] = SCIPvarGetIndex(copyvar);
1662 // mapToProbIndecies[SCIPvarGetIndex(copyvar)] = SCIPvarGetProbindex(copyvar);
1663 // mapToOriginalIndecies[SCIPvarGetIndex(copyvar)] = SCIPvarGetProbindex(copyvar);
1664 // std::cout << i << ": " << SCIPvarGetName(copyvar) << std::endl;
1665 // std::cout << i << ": " << SCIPvarGetName(srcVars[i]) << std::endl;
1666 // std::cout << i << ": " << SCIPvarGetName(targetVars[SCIPvarGetProbindex(copyvar)]) << std::endl;
1667 }
1668 /*
1669 else
1670 {
1671 THROW_LOGICAL_ERROR1("the number of variables is inconsitent");
1672 }
1673 */
1674 }
1675
1676 /* free hash map */
1677 if( SCIPgetNConss(tempScip) > 0 )
1678 {
1679 SCIPhashmapFree(&conssmap);
1680 }
1681 if( SCIPgetNVars(tempScip) > 0 )
1682 {
1683 SCIPhashmapFree(&varmap);
1684 }
1685
1686 SCIPfree(&tempScip);
1687
1688 // n = SCIPgetNVars(scip);
1689 SCIP_VAR **vars = SCIPgetVars(scip);
1690 varLbs = new SCIP_Real[nVars];
1691 varUbs = new SCIP_Real[nVars];
1692 for(int v = 0; v < nVars; ++v )
1693 {
1694 SCIP_VAR *var = vars[v];
1695 varLbs[SCIPvarGetProbindex(var)] = SCIPvarGetLbLocal(var); //* we should use global?
1696 varUbs[SCIPvarGetProbindex(var)] = SCIPvarGetUbLocal(var); //* we should use global?
1697 }
1698
1699// #ifdef UG_DEBUG_SOLUTION
1700// assert(scip->set->debugsoldata == NULL);
1701// SCIP_CALL_ABORT( SCIPdebugSolDataCreate(&((scip->set)->debugsoldata)));
1702// SCIPdebugSetMainscipset(scip->set);
1703// #endif
1704 break;
1705 }
1706 default :
1707 THROW_LOGICAL_ERROR1("Undefined instance transfer method");
1708 }
1709}
1710
1711void
1713{
1714 /** free memory for ParaInstance to save memory */
1715 if(varLbs)
1716 {
1717 delete[] varLbs;
1718 varLbs = 0;
1719 }
1720 if(varUbs)
1721 {
1722 delete[] varUbs;
1723 varUbs = 0;
1724 }
1725 if(objCoefs)
1726 {
1727 delete[] objCoefs;
1728 objCoefs = 0;
1729 }
1730 if(varTypes)
1731 {
1732 delete[] varTypes;
1733 varTypes = 0;
1734 }
1735 if(posVarNames)
1736 {
1737 delete[] posVarNames;
1738 posVarNames = 0;
1739 }
1740
1741 if( nLinearConss )
1742 {
1743 delete [] idxLinearConsNames;
1745 delete [] linearLhss;
1746 linearLhss = 0;
1747 delete [] linearRhss;
1748 linearRhss = 0;
1749 for(int i = 0; i < nLinearConss; i++ )
1750 {
1751 delete [] linearCoefs[i];
1752 delete [] idxLinearCoefsVars[i];
1753 }
1754 delete [] linearCoefs;
1755 delete [] idxLinearCoefsVars;
1756 delete [] nLinearCoefs;
1757 linearCoefs = 0;
1759 nLinearCoefs = 0;
1760 }
1761 if( nSetppcConss )
1762 {
1763 delete [] idxSetppcConsNames;
1765 delete [] nIdxSetppcVars;
1766 nIdxSetppcVars = 0;
1767 delete [] setppcTypes;
1768 setppcTypes = 0;
1769 for(int i = 0; i < nSetppcConss; i++ )
1770 {
1771 delete idxSetppcVars[i];
1772 }
1773 delete [] idxSetppcVars;
1774 idxSetppcVars = 0;
1775 }
1776 if( nLogicorConss )
1777 {
1778 delete [] idxLogicorConsNames;
1780 delete [] nIdxLogicorVars;
1781 nIdxLogicorVars = 0;
1782 for( int i = 0; i < nLogicorConss; i++ )
1783 {
1784 delete [] idxLogicorVars[i];
1785 }
1786 delete [] idxLogicorVars;
1787 idxLogicorVars = 0;
1788 }
1789 if( nKnapsackConss )
1790 {
1791 delete [] idxKnapsackConsNames;
1793 delete [] capacities;
1794 capacities = 0;
1795 delete [] nLKnapsackCoefs;
1796 nLKnapsackCoefs = 0;
1797 for( int i = 0; i < nKnapsackConss; i++ )
1798 {
1799 delete [] knapsackCoefs[i];
1800 delete [] idxKnapsackCoefsVars[i];
1801 }
1802 delete [] knapsackCoefs;
1803 delete [] idxKnapsackCoefsVars;
1804 knapsackCoefs = 0;
1806 }
1807 if( nSos1Conss )
1808 {
1809 delete [] nSos1Coefs;
1810 nSos1Coefs = 0;
1811 for( int i = 0; i < nSos1Conss; i++ )
1812 {
1813 delete [] sos1Coefs[i];
1814 delete [] idxSos1CoefsVars[i];
1815 }
1816 delete [] sos1Coefs;
1817 delete [] idxSos1CoefsVars;
1818 sos1Coefs = 0;
1819 idxSos1CoefsVars = 0;
1820 }
1821 if( nSos2Conss )
1822 {
1823 delete [] nSos2Coefs;
1824 nSos2Coefs = 0;
1825 for( int i = 0; i < nSos1Conss; i++ )
1826 {
1827 delete [] sos2Coefs[i];
1828 delete [] idxSos2CoefsVars[i];
1829 }
1830 delete sos2Coefs;
1831 delete idxSos2CoefsVars;
1832 sos2Coefs = 0;
1833 idxSos2CoefsVars = 0;
1834 }
1835 if( nAggregatedConss )
1836 {
1837 for( int i = 0; i < nAggregatedConss; i++ )
1838 {
1839 delete aggregatedCoefs[i];
1840 delete idxAggregatedCoefsVars[i];
1841 }
1842 delete [] aggregatedCoefs;
1843 delete [] idxAggregatedCoefsVars;
1844 delete[] aggregatedLhsAndLhss;
1845 aggregatedCoefs = 0;
1848 }
1849}
1850
1851/** stringfy ScipParaInstance: for debug */
1852const std::string
1854 )
1855{
1856 std::ostringstream s;
1857
1858 s << "lProbName = " << lProbName << std::endl;
1859 s << "probName = " << probName << std::endl;
1860 s << "objSense = " << origObjSense << std::endl;
1861 s << "objScale = " << objScale << std::endl;
1862 s << "objOffset = " << objOffset << std::endl;
1863 s << "nVars = " << nVars << ", lVarNames = " << lVarNames << std::endl;
1864 for( int i = 0; i < nVars; i++ )
1865 {
1866 s << "[" << i << "]: varNames = " << &varNames[posVarNames[i]]
1867 << ", varsLbs = " << varLbs[i] << ", varsUbs = " << varUbs[i]
1868 << ", objCoefs = " << objCoefs[i] << ", varTypes = " << varTypes[i];
1870 {
1871 s << ", mapToOriginalIndecies = " << mapToOriginalIndecies[i];
1872 }
1874 {
1875 s << ", mapToSolverLocalIndecies = " << mapToSolverLocalIndecies[i];
1876 }
1877 s << std::endl;
1878 }
1879 s << "nConss = " << nConss << ", lConsNames = " << lConsNames << std::endl;
1880 for( int i = 0; i < nConss; i ++ )
1881 {
1882 s<< "[" << i << "]: consNames = " << &consNames[posConsNames[i]] << std::endl;
1883 }
1884
1885 /*************************
1886 * for linear constrains *
1887 * ***********************/
1888 s << "nLinearConss = " << nLinearConss << std::endl;
1889 for(int i = 0; i < nLinearConss; i++ )
1890 {
1891 s << "[" << i << "]: idxLinearConsNames = " << idxLinearConsNames[i]
1892 << ", linearLhss = " << linearLhss[i] << ", linearRhss = " << linearRhss[i]
1893 << ", nLinearCoefs = " << nLinearCoefs[i] << std::endl;
1894 for( int j = 0; j < nLinearCoefs[i]; j++ )
1895 {
1896 s << " [" << j << "]: linearCoefs = " << linearCoefs[i][j]
1897 << ", idxLinearCoefsVars = " << idxLinearCoefsVars[i][j] << std::endl;
1898 }
1899 }
1900
1901 /*************************
1902 * for setppc constrains *
1903 * ***********************/
1904 s << "nSetppcConss = " << nSetppcConss << std::endl;
1905 for(int i = 0; i < nSetppcConss; i++)
1906 {
1907 s << "[" << i << "]: idxSetppcConsNames = " << idxSetppcConsNames[i]
1908 << ", nIdxSetppcVars = " << nIdxSetppcVars[i] << ", setppcTypes = " << setppcTypes[i] << std::endl;
1909 for(int j = 0; j < nIdxSetppcVars[i]; j++ )
1910 {
1911 s << " [" << j << "]: idxSetppcVars = " << idxSetppcVars[i][j] << std::endl;
1912 }
1913 }
1914
1915 /*********************************
1916 * for logical constrains *
1917 *********************************/
1918 s << "nLogicorConss = " << nLogicorConss << std::endl;
1919 for(int i = 0; i < nLogicorConss; i++ )
1920 {
1921 s << "[" << i << "]: idxLogicorConsNames = " << idxLogicorConsNames[i]
1922 << ", nIdxLogicorVars = " << nIdxLogicorVars[i] << std::endl;
1923 for(int j = 0; j < nIdxLogicorVars[i]; j++ )
1924 {
1925 s << " [" << j << "]: idxLogicorVars = " << idxLogicorVars[i][j] << std::endl;
1926 }
1927 }
1928
1929 /*********************************
1930 * for knapsack constrains *
1931 *********************************/
1932 s << "nKnapsackConss = " << nKnapsackConss << std::endl;
1933 for(int i = 0; i < nKnapsackConss; i++)
1934 {
1935 s << "[" << i << "]: idxKnapsackConsNames = " << idxKnapsackConsNames[i]
1936 << ", capacities = " << capacities[i] << ", nLKnapsackCoefs = " << nLKnapsackCoefs[i] << std::endl;
1937 for(int j = 0; j < nLKnapsackCoefs[i]; j++ )
1938 {
1939 s << " [" << j << "]: knapsackCoefs = " << knapsackCoefs[i][j] << ", idxKnapsackCoefsVars = " << idxKnapsackCoefsVars[i][j] << std::endl;
1940 }
1941 }
1942
1943 /**********************************
1944 * for varbound constrains *
1945 *********************************/
1946 s << "nVarboundConss = " << nVarboundConss << std::endl;
1947 for(int i = 0; i < nVarboundConss; i++)
1948 {
1949 s << "[" << i << "]: idxVarboundConsNames = " << idxVarboundConsNames[i]
1950 << ", varboundLhss = " << varboundLhss[i] << ", varboundRhss = " << varboundRhss[i]
1951 << ", idxVarboundCoefVar1s = " << idxVarboundCoefVar1s[i] << ", varboundCoef2s = " << varboundCoef2s[i]
1952 << ", idxVarboundCoefVar2s = " << idxVarboundCoefVar2s[i] << std::endl;
1953 }
1954
1955 /*********************************
1956 * for SOS1 constraints *
1957 *********************************/
1958 s << "nSos1Conss = " << nSos1Conss << std::endl;
1959 for( int i = 0; i < nSos1Conss; i++ )
1960 {
1961 s << "[" << i << "]: idxSos1ConsNames = " << idxSos1ConsNames[i]
1962 << ", nSos1Coefs = " << nSos1Coefs[i] << std::endl;
1963 for(int j = 0; j < nSos1Coefs[i]; j++ )
1964 {
1965 s << " [" << j << "]: sos1Coefs = " << sos1Coefs[i][j] << ", idxSos1CoefsVars = " << idxSos1CoefsVars[i][j] << std::endl;
1966 }
1967 }
1968
1969 /*********************************
1970 * for SOS2 constraints *
1971 *********************************/
1972 s << "nSos2Conss = " << nSos2Conss << std::endl;
1973 for( int i = 0; i < nSos2Conss; i++ )
1974 {
1975 s << "[" << i << "]: idxSos2ConsNames = " << idxSos2ConsNames[i]
1976 << ", nSos2Coefs = " << nSos2Coefs[i] << std::endl;
1977 for(int j = 0; j < nSos2Coefs[i]; j++ )
1978 {
1979 s << " [" << j << "]: sos2Coefs = " << sos2Coefs[i][j] << ", idxSos2CoefsVars = " << idxSos2CoefsVars[i][j] << std::endl;
1980 }
1981 }
1982
1983 /**********************************
1984 * for aggregated constrains *
1985 *********************************/
1986 s << "nAggregatedConss = " << nAggregatedConss << ", lAggregatedVarNames = " << lAggregatedVarNames
1987 << ", lAggregatedConsNames = " << lAggregatedConsNames << std::endl;
1988 for(int i = 0; i < nAggregatedConss; i++)
1989 {
1990 s << "[" << i << "]: aggregatedVarNames = " << aggregatedVarNames[posAggregatedVarNames[i]]
1991 << ", aggregatedConsNames = " << aggregatedConsNames[posAggregatedConsNames[i]]
1992 << ", aggregatedLhsAndLhss = " << aggregatedLhsAndLhss[i] << ", nAggregatedCoefs = " << nAggregatedCoefs[i] << std::endl;
1993 for(int j = 0; j < nAggregatedCoefs[i]; j++ )
1994 {
1995 s << " [" << j << "]: aggregatedCoefs = " << aggregatedCoefs[i][j]
1996 << ", idxAggregatedCoefsVars = " << idxAggregatedCoefsVars[i][j] << std::endl;
1997 }
1998 }
1999 return s.str();
2000}
2001
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.