44 #define getcwd(X, Y) _getcwd(X, Y) 50 #include "scip/scipdefplugins.h" 51 #include "scip/reader_lp.h" 52 #include "scip/cons_knapsack.h" 53 #include "scip/cons_linear.h" 54 #include "scip/cons_logicor.h" 55 #include "scip/cons_setppc.h" 56 #include "scip/cons_varbound.h" 57 #include "scip/cons_bounddisjunction.h" 58 #include "scip/cons_sos1.h" 59 #include "scip/cons_sos2.h" 60 #include "scip/pub_misc.h" 87 assert( SCIPvarGetIndex((SCIP_VAR*) key) >= 0 );
88 return (
unsigned int) SCIPvarGetIndex((SCIP_VAR*) key);
92 ScipParaInstance::allocateMemoryForOrdinaryConstraints(
96 if( nLinearConss > 0 )
98 idxLinearConsNames =
new int[nLinearConss];
99 linearLhss =
new SCIP_Real[nLinearConss];
100 linearRhss =
new SCIP_Real[nLinearConss];
101 nLinearCoefs =
new int[nLinearConss];
102 linearCoefs =
new SCIP_Real*[nLinearConss];
103 idxLinearCoefsVars =
new int*[nLinearConss];
108 idxSetppcConsNames =
new int[nSetppcConss];
109 nIdxSetppcVars =
new int[nSetppcConss];
110 setppcTypes =
new int[nSetppcConss];
111 idxSetppcVars =
new int*[nSetppcConss];
116 idxLogicorConsNames =
new int[nLogicorConss];
117 nIdxLogicorVars =
new int[nLogicorConss];
118 idxLogicorVars =
new int*[nLogicorConss];
123 idxKnapsackConsNames =
new int[nKnapsackConss];
124 capacities =
new SCIP_Longint[nKnapsackConss];
125 nLKnapsackCoefs =
new int[nKnapsackConss];
126 knapsackCoefs =
new SCIP_Longint*[nKnapsackConss];
127 idxKnapsackCoefsVars =
new int*[nKnapsackConss];
130 if( nVarboundConss ){
131 idxVarboundConsNames =
new int[nVarboundConss];
132 varboundLhss =
new SCIP_Real[nVarboundConss];
133 varboundRhss =
new SCIP_Real[nVarboundConss];
134 idxVarboundCoefVar1s =
new int[nVarboundConss];
135 varboundCoef2s =
new SCIP_Real[nVarboundConss];
136 idxVarboundCoefVar2s =
new int[nVarboundConss];
139 if( nVarBoundDisjunctionConss ){
141 idxBoundDisjunctionConsNames =
new int[nVarBoundDisjunctionConss];
142 nVarsBoundDisjunction =
new int[nVarBoundDisjunctionConss];
143 boundsBoundDisjunction =
new SCIP_Real*[nVarBoundDisjunctionConss];
144 boundTypesBoundDisjunction =
new SCIP_BOUNDTYPE*[nVarBoundDisjunctionConss];
145 idxVarBoundDisjunction =
new int*[nVarBoundDisjunctionConss];
149 idxSos1ConsNames =
new int[nSos1Conss];
150 nSos1Coefs =
new int[nSos1Conss];
151 sos1Coefs =
new SCIP_Real*[nSos1Conss];
152 idxSos1CoefsVars =
new int*[nSos1Conss];
156 idxSos2ConsNames =
new int[nSos2Conss];
157 nSos2Coefs =
new int[nSos2Conss];
158 sos2Coefs =
new SCIP_Real*[nSos2Conss];
159 idxSos2CoefsVars =
new int*[nSos2Conss];
164 ScipParaInstance::addOrdinaryConstraintName(
169 posConsNames[c] = lConsNames;
170 (void) strcpy( &consNames[lConsNames], SCIPconsGetName(cons) );
171 lConsNames += strlen( SCIPconsGetName(cons) )+ 1;
175 ScipParaInstance::setLinearConstraint(
181 addOrdinaryConstraintName(c, cons);
182 idxLinearConsNames[nLinearConss] = c;
183 linearLhss[nLinearConss] = SCIPgetLhsLinear(
scip, cons);
184 linearRhss[nLinearConss] = SCIPgetRhsLinear(
scip, cons);
185 int nvars = SCIPgetNVarsLinear(
scip, cons);
186 nLinearCoefs[nLinearConss] = nvars;
187 linearCoefs[nLinearConss] =
new SCIP_Real[nvars];
188 idxLinearCoefsVars[nLinearConss] =
new int[nvars];
189 SCIP_Real *coefs = SCIPgetValsLinear(
scip, cons);
190 SCIP_VAR **vars = SCIPgetVarsLinear(
scip, cons);
191 for(
int v = 0; v < nvars; ++v)
193 linearCoefs[nLinearConss][v] = coefs[v];
194 idxLinearCoefsVars[nLinearConss][v] = SCIPvarGetProbindex(vars[v]);
200 ScipParaInstance::createLinearConstraintsInSCIP(
204 SCIP_VAR **vars = SCIPgetVars(scip);
205 for(
int c = 0; c < nLinearConss; ++c )
208 SCIP_VAR **varsInCons =
new SCIP_VAR*[nLinearCoefs[c]];
209 for(
int v = 0; v < nLinearCoefs[c]; v++)
211 varsInCons[v] = vars[idxLinearCoefsVars[c][v]];
213 SCIP_CALL_ABORT( SCIPcreateConsLinear(scip, &cons,
214 &consNames[posConsNames[idxLinearConsNames[c]]], nLinearCoefs[c], varsInCons, linearCoefs[c],linearLhss[c], linearRhss[c],
215 TRUE, TRUE, TRUE, TRUE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE) );
216 SCIP_CALL_ABORT( SCIPaddCons(scip, cons) );
217 SCIPdebug( SCIP_CALL_ABORT( SCIPprintCons(scip, cons, NULL) ) );
218 SCIP_CALL_ABORT( SCIPreleaseCons(scip, &cons) );
219 delete [] varsInCons;
227 ScipParaInstance::setSetppcConstraint(
233 addOrdinaryConstraintName(c, cons);
234 idxSetppcConsNames[nSetppcConss] = c;
235 int nvars = SCIPgetNVarsSetppc(
scip,cons);
236 nIdxSetppcVars[nSetppcConss] = nvars;
237 setppcTypes[nSetppcConss] = SCIPgetTypeSetppc(
scip,cons);
238 idxSetppcVars[nSetppcConss] =
new int[nvars];
239 SCIP_VAR **vars = SCIPgetVarsSetppc(
scip, cons);
240 for(
int v = 0; v < nvars; ++v)
242 idxSetppcVars[nSetppcConss][v] = SCIPvarGetProbindex(vars[v]);
248 ScipParaInstance::createSetppcConstraintsInSCIP(
252 SCIP_VAR **vars = SCIPgetVars(scip);
253 for(
int c = 0; c < nSetppcConss; ++c )
256 SCIP_VAR **varsInCons =
new SCIP_VAR*[nIdxSetppcVars[c]];
257 for(
int v = 0; v < nIdxSetppcVars[c]; v++)
259 varsInCons[v] = vars[idxSetppcVars[c][v]];
261 switch (setppcTypes[c])
263 case SCIP_SETPPCTYPE_PARTITIONING:
264 SCIP_CALL_ABORT( SCIPcreateConsSetpart(scip, &cons,
265 &consNames[posConsNames[idxSetppcConsNames[c]]], nIdxSetppcVars[c], varsInCons,
266 TRUE, TRUE, TRUE, TRUE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE) );
268 case SCIP_SETPPCTYPE_PACKING:
269 SCIP_CALL_ABORT( SCIPcreateConsSetpack(scip, &cons,
270 &consNames[posConsNames[idxSetppcConsNames[c]]], nIdxSetppcVars[c], varsInCons,
271 TRUE, TRUE, TRUE, TRUE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE) );
273 case SCIP_SETPPCTYPE_COVERING:
274 SCIP_CALL_ABORT( SCIPcreateConsSetcover(scip, &cons,
275 &consNames[posConsNames[idxSetppcConsNames[c]]], nIdxSetppcVars[c], varsInCons,
276 TRUE, TRUE, TRUE, TRUE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE) );
281 SCIP_CALL_ABORT( SCIPaddCons(scip, cons) );
282 SCIPdebug( SCIP_CALL_ABORT( SCIPprintCons(scip, cons, NULL) ) );
283 SCIP_CALL_ABORT( SCIPreleaseCons(scip, &cons) );
284 delete [] varsInCons;
292 ScipParaInstance::setLogicorConstraint(
298 addOrdinaryConstraintName(c, cons);
299 idxLogicorConsNames[nLogicorConss] = c;
300 int nvars = SCIPgetNVarsLogicor(
scip, cons);
301 nIdxLogicorVars[nLogicorConss] = nvars;
302 idxLogicorVars[nLogicorConss] =
new int[nvars];
304 SCIP_VAR **vars = SCIPgetVarsLogicor(
scip, cons);
305 for(
int v = 0; v < nvars; ++v )
307 if( SCIPvarIsActive(vars[v]) )
308 idxLogicorVars[nLogicorConss][v] = SCIPvarGetProbindex(vars[v]);
309 else if( SCIPvarIsNegated(vars[v]) )
310 idxLogicorVars[nLogicorConss][v] = -SCIPvarGetProbindex(SCIPvarGetNegationVar(vars[v])) - 1;
312 idxLogicorVars[nLogicorConss][v] = INT_MAX;
318 ScipParaInstance::createLogicorConstraintsInSCIP(
322 SCIP_VAR **vars = SCIPgetVars(scip);
323 for(
int c = 0; c < nLogicorConss; ++c )
326 SCIP_VAR **varsInCons =
new SCIP_VAR*[nIdxLogicorVars[c]];
328 for( v = 0; v < nIdxLogicorVars[c]; v++)
330 if( idxLogicorVars[c][v] == INT_MAX )
333 if( idxLogicorVars[c][v] < 0 )
335 SCIP_CALL_ABORT( SCIPgetNegatedVar(scip, vars[-(idxLogicorVars[c][v] + 1)], &varsInCons[v]) );
338 varsInCons[v] = vars[idxLogicorVars[c][v]];
340 if( v == nIdxLogicorVars[c] )
342 SCIP_CALL_ABORT( SCIPcreateConsLogicor(scip, &cons,
343 &consNames[posConsNames[idxLogicorConsNames[c]]], nIdxLogicorVars[c], varsInCons,
344 TRUE, FALSE, FALSE, FALSE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE) );
345 SCIP_CALL_ABORT( SCIPaddCons(scip, cons) );
346 SCIPdebug( SCIP_CALL_ABORT( SCIPprintCons(scip, cons, NULL) ) );
347 SCIP_CALL_ABORT( SCIPreleaseCons(scip, &cons) );
349 delete [] varsInCons;
357 ScipParaInstance::setKnapsackConstraint(
363 addOrdinaryConstraintName(c, cons);
364 idxKnapsackConsNames[nKnapsackConss] = c;
365 capacities[nKnapsackConss] = SCIPgetCapacityKnapsack(
scip, cons);
366 int nvars = SCIPgetNVarsKnapsack(
scip, cons);
367 nLKnapsackCoefs[nKnapsackConss] = nvars;
368 knapsackCoefs[nKnapsackConss] =
new SCIP_Longint[nvars];
369 idxKnapsackCoefsVars[nKnapsackConss] =
new int[nvars];
370 SCIP_Longint *weights = SCIPgetWeightsKnapsack(
scip, cons);
371 SCIP_VAR **vars = SCIPgetVarsKnapsack(
scip,cons);
372 for(
int v = 0; v < nvars; ++v )
374 knapsackCoefs[nKnapsackConss][v] = weights[v];
375 idxKnapsackCoefsVars[nKnapsackConss][v] = SCIPvarGetProbindex(vars[v]);
382 ScipParaInstance::createKnapsackConstraintsInSCIP(
386 SCIP_VAR **vars = SCIPgetVars(scip);
387 for(
int c = 0; c < nKnapsackConss; ++c )
390 SCIP_VAR **varsInCons =
new SCIP_VAR*[nLKnapsackCoefs[c]];
391 for(
int v = 0; v < nLKnapsackCoefs[c]; v++)
393 varsInCons[v] = vars[idxKnapsackCoefsVars[c][v]];
395 SCIP_CALL_ABORT( SCIPcreateConsKnapsack(scip, &cons,
396 &consNames[posConsNames[idxKnapsackConsNames[c]]], nLKnapsackCoefs[c], varsInCons, knapsackCoefs[c], capacities[c],
397 TRUE, TRUE, TRUE, TRUE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE) );
398 SCIP_CALL_ABORT( SCIPaddCons(scip, cons) );
399 SCIPdebug( SCIP_CALL_ABORT( SCIPprintCons(scip, cons, NULL) ) );
400 SCIP_CALL_ABORT( SCIPreleaseCons(scip, &cons) );
401 delete [] varsInCons;
409 ScipParaInstance::setVarboundConstraint(
415 addOrdinaryConstraintName(c, cons);
416 idxVarboundConsNames[nVarboundConss] = c;
417 varboundLhss[nVarboundConss] = SCIPgetLhsVarbound(
scip,cons);
418 varboundRhss[nVarboundConss] = SCIPgetRhsVarbound(
scip,cons);
419 idxVarboundCoefVar1s[nVarboundConss] = SCIPvarGetProbindex(SCIPgetVarVarbound(
scip,cons));
420 varboundCoef2s[nVarboundConss] = SCIPgetVbdcoefVarbound(
scip,cons);
421 idxVarboundCoefVar2s[nVarboundConss] = SCIPvarGetProbindex(SCIPgetVbdvarVarbound(
scip,cons));
426 ScipParaInstance::createVarboundConstraintsInSCIP(
430 SCIP_VAR **vars = SCIPgetVars(scip);
431 for(
int c = 0; c < nVarboundConss; ++c )
434 SCIP_VAR *var1InCons = vars[idxVarboundCoefVar1s[c]];
435 SCIP_VAR *var2InCons = vars[idxVarboundCoefVar2s[c]];
436 SCIP_CALL_ABORT( SCIPcreateConsVarbound(scip, &cons,
437 &consNames[posConsNames[idxVarboundConsNames[c]]], var1InCons, var2InCons, varboundCoef2s[c], varboundLhss[c], varboundRhss[c],
438 TRUE, TRUE, TRUE, TRUE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE) );
439 SCIP_CALL_ABORT( SCIPaddCons(scip, cons) );
440 SCIPdebug( SCIP_CALL_ABORT( SCIPprintCons(scip, cons, NULL) ) );
441 SCIP_CALL_ABORT( SCIPreleaseCons(scip, &cons) );
449 ScipParaInstance::setBoundDisjunctionConstraint(
455 addOrdinaryConstraintName(c, cons);
456 idxBoundDisjunctionConsNames[nVarBoundDisjunctionConss] = c;
457 nVarsBoundDisjunction[nVarBoundDisjunctionConss] = SCIPgetNVarsBounddisjunction(
scip,cons);
458 idxVarBoundDisjunction[nVarBoundDisjunctionConss] =
new int[nVarsBoundDisjunction[nVarBoundDisjunctionConss]];
459 boundsBoundDisjunction[nVarBoundDisjunctionConss] =
new SCIP_Real[nVarsBoundDisjunction[nVarBoundDisjunctionConss]];
460 boundTypesBoundDisjunction[nVarBoundDisjunctionConss] =
new SCIP_BOUNDTYPE[nVarsBoundDisjunction[nVarBoundDisjunctionConss]];
461 SCIP_VAR **vars = SCIPgetVarsBounddisjunction (
scip, cons );
462 SCIP_BOUNDTYPE *boundTypes = SCIPgetBoundtypesBounddisjunction(
scip, cons );
463 SCIP_Real *bounds = SCIPgetBoundsBounddisjunction(
scip, cons );
464 for(
int v = 0; v < nVarsBoundDisjunction[nVarBoundDisjunctionConss]; ++v )
466 idxVarBoundDisjunction[nVarBoundDisjunctionConss][v] = SCIPvarGetProbindex(vars[v]);
467 boundsBoundDisjunction[nVarBoundDisjunctionConss][v] = bounds[v];
468 boundTypesBoundDisjunction[nVarBoundDisjunctionConss][v] = boundTypes[v];
470 nVarBoundDisjunctionConss++;
474 ScipParaInstance::createBoundDisjunctionConstraintInSCIP(
478 SCIP_VAR **vars = SCIPgetVars(scip);
479 for(
int c = 0; c < nVarBoundDisjunctionConss; ++c )
482 SCIP_VAR **boundVars =
new SCIP_VAR*[nVarsBoundDisjunction[c]];
483 SCIP_BOUNDTYPE *types =
new SCIP_BOUNDTYPE[nVarsBoundDisjunction[c]];
484 for(
int v = 0; v < nVarsBoundDisjunction[c]; ++v )
486 boundVars[v] = vars[idxVarBoundDisjunction[c][v]];
487 types[v] = boundTypesBoundDisjunction[c][v];
490 SCIP_CALL_ABORT( SCIPcreateConsBounddisjunction(scip, &cons,
491 &consNames[posConsNames[idxBoundDisjunctionConsNames[c]]], nVarsBoundDisjunction[c], boundVars,
492 types, boundsBoundDisjunction[c],
493 TRUE, TRUE, TRUE, TRUE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE) );
494 SCIP_CALL_ABORT( SCIPaddCons(scip, cons) );
495 SCIPdebug( SCIP_CALL_ABORT( SCIPprintCons(scip, cons, NULL) ) );
496 SCIP_CALL_ABORT( SCIPreleaseCons(scip, &cons) );
503 ScipParaInstance::setSos1Constraint(
510 addOrdinaryConstraintName(c, cons);
511 idxSos1ConsNames[nSos1Conss] = c;
512 int nvars = SCIPgetNVarsSOS1(
scip, cons);
513 nSos1Coefs[nSos1Conss] = nvars;
514 sos1Coefs[nSos1Conss] =
new SCIP_Real[nvars];
515 idxSos1CoefsVars[nSos1Conss] =
new int[nvars];
516 SCIP_Real *weights = SCIPgetWeightsSOS1(
scip, cons);
517 SCIP_VAR **vars = SCIPgetVarsSOS1(
scip,cons);
518 for(
int v = 0; v < nvars; v++ )
520 sos1Coefs[nSos1Conss][v] = weights[v];
521 idxSos1CoefsVars[nSos1Conss][v] = SCIPvarGetProbindex(vars[v]);
524 consSOS1[nSos1Conss++] = cons;
528 ScipParaInstance::createSos1ConstraintsInSCIP(
532 SCIP_VAR **vars = SCIPgetVars(scip);
533 for(
int c = 0; c < nSos1Conss; ++c )
536 SCIP_VAR **varsInCons =
new SCIP_VAR*[nSos1Coefs[c]];
537 for(
int v = 0; v < nSos1Coefs[c]; v++)
539 varsInCons[v] = vars[idxSos1CoefsVars[c][v]];
541 SCIP_CALL_ABORT( SCIPcreateConsSOS1(scip, &cons,
542 &consNames[posConsNames[idxSos1ConsNames[c]]], nSos1Coefs[c], varsInCons, sos1Coefs[c],
543 TRUE, TRUE, TRUE, TRUE, TRUE, FALSE, FALSE, FALSE, FALSE ) );
544 SCIP_CALL_ABORT( SCIPaddCons(scip, cons) );
545 SCIPdebug( SCIP_CALL_ABORT( SCIPprintCons(scip, cons, NULL) ) );
546 SCIP_CALL_ABORT( SCIPreleaseCons(scip, &cons) );
547 delete [] varsInCons;
552 ScipParaInstance::setSos2Constraint(
559 addOrdinaryConstraintName(c, cons);
560 idxSos2ConsNames[nSos2Conss] = c;
561 int nvars = SCIPgetNVarsSOS2(
scip, cons);
562 nSos2Coefs[nSos2Conss] = nvars;
563 sos2Coefs[nSos2Conss] =
new SCIP_Real[nvars];
564 idxSos2CoefsVars[nSos2Conss] =
new int[nvars];
565 SCIP_Real *weights = SCIPgetWeightsSOS2(
scip, cons);
566 SCIP_VAR **vars = SCIPgetVarsSOS2(
scip,cons);
567 for(
int v = 0; v < nvars; v++ )
569 sos2Coefs[nSos2Conss][v] = weights[v];
570 idxSos2CoefsVars[nSos2Conss][v] = SCIPvarGetProbindex(vars[v]);
573 consSOS2[nSos2Conss++] = cons;
577 ScipParaInstance::createSos2ConstraintsInSCIP(
581 SCIP_VAR **vars = SCIPgetVars(scip);
582 for(
int c = 0; c < nSos2Conss; ++c )
585 SCIP_VAR **varsInCons =
new SCIP_VAR*[nSos2Coefs[c]];
586 for(
int v = 0; v < nSos2Coefs[c]; v++)
588 varsInCons[v] = vars[idxSos2CoefsVars[c][v]];
590 SCIP_CALL_ABORT( SCIPcreateConsSOS2(scip, &cons,
591 &consNames[posConsNames[idxSos2ConsNames[c]]], nSos2Coefs[c], varsInCons, sos2Coefs[c],
592 TRUE, TRUE, TRUE, TRUE, TRUE, FALSE, FALSE, FALSE, FALSE ) );
593 SCIP_CALL_ABORT( SCIPaddCons(scip, cons) );
594 SCIPdebug( SCIP_CALL_ABORT( SCIPprintCons(scip, cons, NULL) ) );
595 SCIP_CALL_ABORT( SCIPreleaseCons(scip, &cons) );
596 delete [] varsInCons;
604 ScipParaInstance::getActiveVariables(
610 SCIP_Bool transformed
616 assert(
scip != NULL );
617 assert( vars != NULL );
618 assert( scalars != NULL );
619 assert( nvars != NULL );
620 assert( constant != NULL );
624 SCIP_CALL_ABORT( SCIPgetProbvarLinearSum(
scip, vars, scalars, nvars, *nvars, constant, &requiredsize, TRUE) );
626 if( requiredsize > *nvars )
628 *nvars = requiredsize;
629 SCIP_CALL_ABORT( SCIPreallocBufferArray(
scip, &vars, *nvars ) );
630 SCIP_CALL_ABORT( SCIPreallocBufferArray(
scip, &scalars, *nvars ) );
632 SCIP_CALL_ABORT( SCIPgetProbvarLinearSum(
scip, vars, scalars, nvars, *nvars, constant, &requiredsize, TRUE) );
633 assert( requiredsize <= *nvars );
638 for( v = 0; v < *nvars; ++v )
639 SCIP_CALL_ABORT( SCIPvarGetOrigvarSum(&vars[v], &scalars[v], constant) );
647 ScipParaInstance::collectAggregatedVars(
651 int* nAggregatedVars,
652 SCIP_VAR*** aggregatedVars,
653 SCIP_HASHTABLE** varAggregated
659 for (j = 0; j < nvars; ++j)
661 SCIP_VARSTATUS status;
665 status = SCIPvarGetStatus(var);
668 if( status >= SCIP_VARSTATUS_AGGREGATED )
670 assert( status == SCIP_VARSTATUS_AGGREGATED ||
671 status == SCIP_VARSTATUS_MULTAGGR ||
672 status == SCIP_VARSTATUS_NEGATED );
674 if ( ! SCIPhashtableExists(*varAggregated, (
void*) var) )
676 (*aggregatedVars)[(*nAggregatedVars)++] = var;
677 SCIP_CALL_ABORT( SCIPhashtableInsert(*varAggregated, (
void*) var) );
684 ScipParaInstance::setAggregatedConstraint(
687 const char* constName,
694 posAggregatedVarNames[c] = lAggregatedVarNames;
695 (void) strcpy( &aggregatedVarNames[lAggregatedVarNames], SCIPvarGetName(vars[c]) );
696 lAggregatedVarNames += strlen( SCIPvarGetName(vars[c]) );
698 posAggregatedConsNames[c] = lAggregatedConsNames;
699 (void) strcpy( &aggregatedConsNames[lAggregatedConsNames], constName );
700 lAggregatedConsNames += strlen( constName )+ 1;
702 aggregatedLhsAndLhss[c] = lhsAndrhs;
703 nAggregatedCoefs[c] = nvars;
705 for(v = 0; v < nvars - 1; ++v)
707 aggregatedCoefs[nLinearConss][v] = vals[v];
708 idxLinearCoefsVars[nLinearConss][v] = SCIPvarGetProbindex(vars[v]);
710 aggregatedCoefs[nLinearConss][v] = vals[v];
711 idxLinearCoefsVars[nLinearConss][v] = c;
716 ScipParaInstance::setAggregatedConstrains(
720 SCIP_VAR** aggregatedVars
723 SCIP_VAR** activevars;
724 SCIP_Real* activevals;
726 SCIP_Real activeconstant = 0.0;
729 assert(
scip != NULL );
732 SCIP_CALL_ABORT( SCIPallocBufferArray(
scip, &activevars, nvars) );
733 SCIP_CALL_ABORT( SCIPallocBufferArray(
scip, &activevals, nvars) );
736 lAggregatedVarNames = 0;
737 lAggregatedConsNames = 0;
738 for(
int j = 0; j < nAggregatedVars; j++ )
740 lAggregatedVarNames += strlen(SCIPvarGetName(aggregatedVars[j])) + 1;
741 (void) SCIPsnprintf(consname,
UG::LpMaxNamelen,
"aggr_%s", SCIPvarGetName(aggregatedVars[j]));
742 lAggregatedConsNames += strlen(consname) + 1;
745 if( nAggregatedVars )
748 aggregatedVarNames =
new char[lAggregatedVarNames];
749 aggregatedConsNames =
new char[lAggregatedConsNames];
753 nAggregatedConss = 0;
754 lAggregatedVarNames = 0;
755 lAggregatedConsNames = 0;
756 for (
int j = 0; j < nAggregatedVars; ++j)
761 activevars[0] = aggregatedVars[j];
763 activeconstant = 0.0;
766 getActiveVariables(
scip, activevars, activevals, &nactivevars, &activeconstant, TRUE);
768 activevals[nactivevars] = -1.0;
769 activevars[nactivevars] = aggregatedVars[j];
773 (void) SCIPsnprintf(consname,
UG::LpMaxNamelen,
"aggr_%s", SCIPvarGetName(aggregatedVars[j]));
774 setAggregatedConstraint(
scip, j, consname, activevars, activevals, nactivevars, - activeconstant );
776 assert(nAggregatedConss == nAggregatedVars);
779 SCIPfreeBufferArray(
scip, &activevars);
780 SCIPfreeBufferArray(
scip, &activevals);
784 ScipParaInstance::createAggregatedVarsAndConstrainsInSCIP(
788 SCIP_VAR **vars = SCIPgetVars(scip);
789 for(
int c = 0; c < nAggregatedConss; ++c )
792 SCIP_VAR **varsInCons =
new SCIP_VAR*[nAggregatedCoefs[c]];
794 for( v = 0; v < nAggregatedCoefs[c] - 1; v++)
796 varsInCons[v] = vars[idxAggregatedCoefsVars[c][v]];
800 SCIP_CALL_ABORT( SCIPcreateVar(scip, &newvar, &aggregatedVarNames[posAggregatedVarNames[c]], 0.0, 1.0, 0.0, SCIP_VARTYPE_BINARY,
801 TRUE, FALSE, NULL, NULL, NULL, NULL, NULL) );
802 SCIP_CALL_ABORT( SCIPaddVar(scip, newvar) );
806 varsInCons[v] = newvar;
807 assert( SCIPvarGetProbindex(newvar) == (
nVars + c) );
808 SCIP_CALL_ABORT( SCIPreleaseVar(scip, &newvar) );
810 SCIP_CALL_ABORT( SCIPcreateConsLinear(scip, &cons,
811 &aggregatedConsNames[posAggregatedConsNames[c]], nAggregatedCoefs[c], varsInCons, aggregatedCoefs[c],aggregatedLhsAndLhss[c], aggregatedLhsAndLhss[c],
812 TRUE, TRUE, TRUE, TRUE, TRUE, FALSE, FALSE, FALSE, FALSE, FALSE) );
813 SCIP_CALL_ABORT( SCIPaddCons(scip, cons) );
814 SCIPdebug( SCIP_CALL_ABORT( SCIPprintCons(scip, cons, NULL) ) );
815 SCIP_CALL_ABORT( SCIPreleaseCons(scip, &cons) );
816 delete [] varsInCons;
824 ) :
orgScip(0), paraInstanceScip(0), lProbName(0), probName(0), nCopies(0), origObjSense(0), objScale(0.0), objOffset(0.0),
nVars(0),
varIndexRange(0),
825 varLbs(0), varUbs(0), objCoefs(0), varTypes(0), lVarNames(0), varNames(0),
827 nConss(0), lConsNames(0), consNames(0),
829 nLinearConss(0), idxLinearConsNames(0), linearLhss(0),
830 linearRhss(0), nLinearCoefs(0), linearCoefs(0), idxLinearCoefsVars(0),
831 nSetppcConss(0), idxSetppcConsNames(0), nIdxSetppcVars(0), setppcTypes(0),
832 idxSetppcVars(0), nLogicorConss(0), idxLogicorConsNames(0), nIdxLogicorVars(0), idxLogicorVars(0),
833 nKnapsackConss(0), idxKnapsackConsNames(0), capacities(0), nLKnapsackCoefs(0),
834 knapsackCoefs(0), idxKnapsackCoefsVars(0),
835 nVarboundConss(0), idxVarboundConsNames(0), varboundLhss(0),varboundRhss(0), idxVarboundCoefVar1s(0),
836 varboundCoef2s(0), idxVarboundCoefVar2s(0),
837 nVarBoundDisjunctionConss(0), idxBoundDisjunctionConsNames(0), nVarsBoundDisjunction(0),
838 idxVarBoundDisjunction(0), boundTypesBoundDisjunction(0), boundsBoundDisjunction(0),
839 nSos1Conss(0),idxSos1ConsNames(0), nSos1Coefs(0), sos1Coefs(0), idxSos1CoefsVars(0),
840 nSos2Conss(0), idxSos2ConsNames(0), nSos2Coefs(0), sos2Coefs(0), idxSos2CoefsVars(0),
841 nAggregatedConss(0), lAggregatedVarNames(0), aggregatedVarNames(0), posAggregatedVarNames(0),
842 lAggregatedConsNames(0), aggregatedConsNames(0), posAggregatedConsNames(0),
843 aggregatedLhsAndLhss(0), nAggregatedCoefs(0), aggregatedCoefs(0), idxAggregatedCoefsVars(0),
846 assert(
scip != NULL );
847 assert( SCIPgetStage(
scip) == SCIP_STAGE_TRANSFORMED ||
848 SCIPgetStage(
scip) == SCIP_STAGE_PRESOLVED ||
849 SCIPgetStage(
scip) == SCIP_STAGE_SOLVING ||
850 SCIPgetStage(
scip) == SCIP_STAGE_SOLVED );
856 lProbName = strlen(SCIPgetProbName(
scip));
857 probName =
new char[lProbName+1];
858 strcpy(probName, SCIPgetProbName(
scip));
861 origObjSense = SCIPgetObjsense(
scip);
862 objScale = SCIPgetTransObjscale(
scip);
863 objOffset = SCIPgetTransObjoffset(
scip);
865 paraInstanceScip =
scip;
867 if( SCIPgetStage(
scip) == SCIP_STAGE_TRANSFORMED || SCIPgetStage(
scip) == SCIP_STAGE_SOLVED )
return;
879 SCIP_VAR **vars = SCIPgetVars(
scip);
882 posVarNames =
new int[
nVars];
883 objCoefs =
new SCIP_Real[
nVars];
887 for(
int v = 0; v <
nVars; ++v)
889 posVarNames[v] = lVarNames;
890 objCoefs[v] = SCIPvarGetObj(vars[v]);
891 assert(SCIPvarGetProbindex(vars[v])!=-1);
892 assert(SCIPvarGetProbindex(vars[v]) == v);
893 lVarNames += strlen(SCIPvarGetName(vars[v])) + 1;
895 varNames =
new char[lVarNames];
896 varLbs =
new SCIP_Real[
nVars];
897 varUbs =
new SCIP_Real[
nVars];
898 varTypes =
new int[
nVars];
899 for(
int v = 0; v <
nVars; ++v )
901 SCIP_VAR *var = vars[v];
902 strcpy (&varNames[posVarNames[v]], SCIPvarGetName(var) );
903 varLbs[SCIPvarGetProbindex(var)] = SCIPvarGetLbLocal(var);
904 varUbs[SCIPvarGetProbindex(var)] = SCIPvarGetUbLocal(var);
905 varTypes[SCIPvarGetProbindex(var)] = SCIPvarGetType(var);
916 nConss = SCIPgetNConss(
scip);
917 SCIP_CONS **conss = SCIPgetConss(
scip);
921 posConsNames =
new int[nConss];
923 int tempSizeConsNames = 0;
925 for(
int c = 0; c < nConss; c++ )
927 tempSizeConsNames += strlen(SCIPconsGetName(conss[c])) + 1;
929 if( tempSizeConsNames > 0 )
931 consNames =
new char[tempSizeConsNames];
934 SCIP_CONS** consSOS1;
935 SCIP_CONS** consSOS2;
940 SCIP_CALL_ABORT( SCIPallocBufferArray(
scip, &consSOS1, nConss) );
941 SCIP_CALL_ABORT( SCIPallocBufferArray(
scip, &consSOS2, nConss) );
944 const char* conshdlrname;
945 SCIP_CONSHDLR* conshdlr;
947 int nNotInitialActiveConss = 0;
950 for (
int c = 0; c < nConss; ++c)
953 assert( cons != NULL);
956 if( !SCIPconsIsEnabled(cons) )
959 conshdlr = SCIPconsGetHdlr(cons);
960 assert( conshdlr != NULL );
962 if( SCIPconshdlrGetStartNActiveConss(conshdlr) > 0 )
964 conshdlrname = SCIPconshdlrGetName(conshdlr);
965 assert( SCIPconsIsTransformed(cons) );
967 if( strcmp(conshdlrname,
"linear") == 0 )
971 else if( strcmp(conshdlrname,
"setppc") == 0 )
975 else if ( strcmp(conshdlrname,
"logicor") == 0 )
979 else if ( strcmp(conshdlrname,
"knapsack") == 0 )
983 else if ( strcmp(conshdlrname,
"varbound") == 0 )
987 else if ( strcmp(conshdlrname,
"bounddisjunction") == 0 )
989 nVarBoundDisjunctionConss++;
991 else if ( strcmp(conshdlrname,
"SOS1") == 0 )
995 else if ( strcmp(conshdlrname,
"SOS2") == 0 )
1001 THROW_LOGICAL_ERROR3(
"constraint handler <", conshdlrname,
"> can not print requested format");
1006 nNotInitialActiveConss++;
1010 assert(nConss == (nLinearConss + nSetppcConss + nLogicorConss + nKnapsackConss + nVarboundConss + nVarBoundDisjunctionConss + nSos1Conss + nSos2Conss + nNotInitialActiveConss) );
1012 allocateMemoryForOrdinaryConstraints();
1020 nVarBoundDisjunctionConss = 0;
1023 nNotInitialActiveConss = 0;
1027 for (
int c = 0; c < nConss; ++c)
1032 if( !SCIPconsIsEnabled(cons) )
1035 conshdlr = SCIPconsGetHdlr(cons);
1037 if( SCIPconshdlrGetStartNActiveConss(conshdlr) > 0 )
1039 conshdlrname = SCIPconshdlrGetName(conshdlr);
1041 if( strcmp(conshdlrname,
"linear") == 0 )
1043 setLinearConstraint(
scip, c, cons );
1045 else if( strcmp(conshdlrname,
"setppc") == 0 )
1047 setSetppcConstraint(
scip, c, cons );
1049 else if ( strcmp(conshdlrname,
"logicor") == 0 )
1051 setLogicorConstraint(
scip, c, cons );
1053 else if ( strcmp(conshdlrname,
"knapsack") == 0 )
1055 setKnapsackConstraint(
scip, c, cons );
1057 else if ( strcmp(conshdlrname,
"varbound") == 0 )
1059 setVarboundConstraint(
scip, c, cons );
1061 else if ( strcmp(conshdlrname,
"bounddisjunction") == 0 )
1063 setBoundDisjunctionConstraint(
scip, c, cons );
1065 else if ( strcmp(conshdlrname,
"SOS1") == 0 )
1067 setSos1Constraint(
scip, c, cons, consSOS1);
1069 else if ( strcmp(conshdlrname,
"SOS2") == 0 )
1071 setSos2Constraint(
scip, c, cons, consSOS2);
1076 nNotInitialActiveConss++;
1080 assert(nConss == (nLinearConss + nSetppcConss + nLogicorConss + nKnapsackConss + nVarboundConss + nVarBoundDisjunctionConss + nSos1Conss + nSos2Conss + nNotInitialActiveConss ) );
1082 SCIP_VAR** aggregatedVars;
1083 int nAggregatedVars = 0;
1084 SCIP_HASHTABLE* varAggregated;
1087 SCIP_CALL_ABORT( SCIPallocBufferArray(
scip, &aggregatedVars, nVars) );
1088 SCIP_CALL_ABORT( SCIPhashtableCreate(&varAggregated, SCIPblkmem(
scip), 1000, hashGetKeyVar, hashKeyEqVar, hashKeyValVar,
1092 for (
int c = 0; c < nSos1Conss; ++c)
1095 SCIP_VAR **consvars = SCIPgetVarsSOS1(
scip, cons);
1096 int nconsvars = SCIPgetNVarsSOS1(
scip, cons);
1098 collectAggregatedVars(
scip, nconsvars, consvars, &nAggregatedVars, &aggregatedVars, &varAggregated);
1102 for (
int c = 0; c < nSos2Conss; ++c)
1105 SCIP_VAR **consvars = SCIPgetVarsSOS2(
scip, cons);
1106 int nconsvars = SCIPgetNVarsSOS2(
scip, cons);
1108 collectAggregatedVars(
scip, nconsvars, consvars, &nAggregatedVars, &aggregatedVars, &varAggregated);
1112 setAggregatedConstrains(
scip, nVars, nAggregatedVars, aggregatedVars );
1115 SCIPfreeBufferArray(
scip, &aggregatedVars);
1116 SCIPhashtableFree(&varAggregated);
1119 SCIPfreeBufferArray(
scip, &consSOS1);
1120 SCIPfreeBufferArray(
scip, &consSOS2);
1131 if(probName)
delete[] probName;
1132 if(varLbs)
delete[] varLbs;
1133 if(varUbs)
delete[] varUbs;
1134 if(objCoefs)
delete[] objCoefs;
1135 if(varTypes)
delete[] varTypes;
1136 if(varNames)
delete[] varNames;
1137 if(posVarNames)
delete[] posVarNames;
1141 if(consNames)
delete[] consNames;
1142 if(posConsNames)
delete[] posConsNames;
1145 if( nLinearConss > 0 )
1147 if( idxLinearConsNames )
delete [] idxLinearConsNames;
1148 if( linearLhss )
delete [] linearLhss;
1149 if( linearRhss )
delete [] linearRhss;
1152 for(
int i = 0; i < nLinearConss; i++ )
1154 delete [] linearCoefs[i];
1155 delete [] idxLinearCoefsVars[i];
1157 delete [] linearCoefs;
1158 delete [] idxLinearCoefsVars;
1159 delete [] nLinearCoefs;
1165 if( idxSetppcConsNames )
delete [] idxSetppcConsNames;
1166 if( nIdxSetppcVars )
delete [] nIdxSetppcVars;
1167 if( setppcTypes )
delete [] setppcTypes;
1170 for(
int i = 0; i < nSetppcConss; i++ )
1172 delete idxSetppcVars[i];
1174 delete [] idxSetppcVars;
1180 if( idxLogicorConsNames)
delete [] idxLogicorConsNames;
1181 if( nIdxLogicorVars )
delete [] nIdxLogicorVars;
1182 if( idxLogicorVars )
1184 for(
int i = 0; i < nLogicorConss; i++ )
1186 delete [] idxLogicorVars[i];
1188 delete [] idxLogicorVars;
1194 if( idxKnapsackConsNames )
delete [] idxKnapsackConsNames;
1195 if( capacities )
delete [] capacities;
1196 if( nLKnapsackCoefs )
delete [] nLKnapsackCoefs;
1199 for(
int i = 0; i < nKnapsackConss; i++ )
1201 delete [] knapsackCoefs[i];
1202 delete [] idxKnapsackCoefsVars[i];
1204 delete [] knapsackCoefs;
1205 delete [] idxKnapsackCoefsVars;
1209 if( nVarboundConss )
1211 if( idxVarboundConsNames )
delete [] idxVarboundConsNames;
1212 if( idxVarboundCoefVar1s )
delete [] idxVarboundCoefVar1s;
1213 if( varboundCoef2s )
delete [] varboundCoef2s;
1214 if( idxVarboundCoefVar2s )
delete [] idxVarboundCoefVar2s;
1218 if( nVarBoundDisjunctionConss )
1220 if( idxBoundDisjunctionConsNames )
delete [] idxBoundDisjunctionConsNames;
1221 if( nVarsBoundDisjunction )
delete[] nVarsBoundDisjunction;
1222 for(
int c = 0; c < nVarBoundDisjunctionConss; c++ )
1224 if( idxVarBoundDisjunction[c] )
delete[] idxVarBoundDisjunction[c];
1225 if( boundTypesBoundDisjunction[c] )
delete[] boundTypesBoundDisjunction[c];
1226 if( boundsBoundDisjunction[c] )
delete[] boundsBoundDisjunction[c];
1233 if( nSos1Coefs )
delete [] nSos1Coefs;
1236 for(
int i = 0; i < nSos1Conss; i++ )
1238 delete [] sos1Coefs[i];
1239 delete [] idxSos1CoefsVars[i];
1241 delete [] sos1Coefs;
1242 delete [] idxSos1CoefsVars;
1248 if( nSos2Coefs )
delete [] nSos2Coefs;
1251 for(
int i = 0; i < nSos1Conss; i++ )
1253 delete [] sos2Coefs[i];
1254 delete [] idxSos2CoefsVars[i];
1257 delete idxSos2CoefsVars;
1261 if( nAggregatedConss )
1263 for(
int i = 0; i < nAggregatedConss; i++ )
1265 delete aggregatedCoefs[i];
1266 delete idxAggregatedCoefsVars[i];
1268 delete [] aggregatedCoefs;
1269 delete [] idxAggregatedCoefsVars;
1270 aggregatedCoefs = 0;
1271 idxAggregatedCoefsVars = 0;
1273 if( aggregatedVarNames )
delete [] aggregatedVarNames;
1274 if( posAggregatedVarNames )
delete[] posAggregatedVarNames;
1275 if( aggregatedConsNames )
delete [] aggregatedConsNames;
1276 if( posAggregatedConsNames )
delete[] posAggregatedConsNames;
1277 if( aggregatedLhsAndLhss )
delete[] aggregatedLhsAndLhss;
1280 if( userPlugins )
delete userPlugins;
1284 ScipParaInstance::addRootNodeCuts(
1289 SCIP_Longint originalLimitsNodes;
1290 SCIP_CALL_ABORT( SCIPgetLongintParam(tempScip,
"limits/nodes", &originalLimitsNodes) );
1291 SCIP_CALL_ABORT( SCIPsetLongintParam(tempScip,
"limits/nodes", 1) );
1293 SCIP_RETCODE ret = SCIPsolve(tempScip);
1294 if( ret != SCIP_OKAY )
1299 SCIP_STATUS status = SCIPgetStatus(tempScip);
1300 if( status == SCIP_STATUS_OPTIMAL )
1306 if( status == SCIP_STATUS_MEMLIMIT )
1308 std::cout <<
"Warning: SCIP was interrupted because the memory limit was reached" << std::endl;
1318 cuts = SCIPgetPoolCuts(tempScip);
1319 ncuts = SCIPgetNPoolCuts(tempScip);
1320 for(
int c = 0; c < ncuts; ++c )
1324 row = SCIPcutGetRow(cuts[c]);
1325 assert(!SCIProwIsLocal(row));
1326 assert(!SCIProwIsModifiable(row));
1327 if( SCIPcutGetAge(cuts[c]) == 0 && SCIProwIsInLP(row) )
1329 char name[SCIP_MAXSTRLEN];
1337 cols = SCIProwGetCols(row);
1338 ncols = SCIProwGetNNonz(row);
1340 SCIP_CALL_ABORT( SCIPallocBufferArray(tempScip, &vars, ncols) );
1341 for( i = 0; i < ncols; ++i )
1342 vars[i] = SCIPcolGetVar(cols[i]);
1344 (void) SCIPsnprintf(name, SCIP_MAXSTRLEN,
"%s_%d", SCIProwGetName(row), SCIPgetNRuns(tempScip));
1345 SCIP_CALL_ABORT( SCIPcreateConsLinear(tempScip, &cons, name, ncols, vars, SCIProwGetVals(row),
1346 SCIProwGetLhs(row) - SCIProwGetConstant(row), SCIProwGetRhs(row) - SCIProwGetConstant(row),
1347 TRUE, TRUE, FALSE, FALSE, TRUE, FALSE, FALSE, FALSE, TRUE, FALSE) );
1348 SCIP_CALL_ABORT( SCIPaddCons(tempScip, cons) );
1349 SCIP_CALL_ABORT( SCIPreleaseCons(tempScip, &cons) );
1351 SCIPfreeBufferArray(tempScip, &vars);
1356 SCIP_CALL_ABORT( SCIPsetLongintParam(tempScip,
"limits/nodes", originalLimitsNodes) );
1365 bool noPreprocessingInLC,
1366 bool usetRootNodeCuts,
1369 char *settingsNameLC,
1378 SCIP_CALL_ABORT( SCIPcreateProb(scip, probName, NULL, NULL, NULL, NULL, NULL, NULL, NULL) );
1379 SCIP_CALL_ABORT( SCIPsetObjsense(scip, SCIP_OBJSENSE_MINIMIZE) );
1380 for(
int v = 0; v <
nVars; ++v)
1385 SCIP_CALL_ABORT( SCIPcreateVar(scip, &newvar, &varNames[posVarNames[v]], varLbs[v], varUbs[v], objCoefs[v],
1386 SCIP_Vartype(varTypes[v]),
1387 TRUE, FALSE, NULL, NULL, NULL, NULL, NULL) );
1388 SCIP_CALL_ABORT( SCIPaddVar(scip, newvar) );
1389 assert( SCIPvarGetProbindex(newvar) == v );
1393 SCIP_CALL_ABORT( SCIPreleaseVar(scip, &newvar) );
1397 createLinearConstraintsInSCIP( scip );
1399 createSetppcConstraintsInSCIP( scip );
1401 createLogicorConstraintsInSCIP( scip );
1402 if( nKnapsackConss )
1403 createKnapsackConstraintsInSCIP( scip );
1404 if( nVarboundConss )
1405 createVarboundConstraintsInSCIP( scip );
1406 if( nVarBoundDisjunctionConss )
1407 createBoundDisjunctionConstraintInSCIP( scip );
1409 createSos1ConstraintsInSCIP( scip );
1411 createSos2ConstraintsInSCIP( scip );
1412 if( nAggregatedConss )
1413 createAggregatedVarsAndConstrainsInSCIP( scip );
1420 nVars = SCIPgetNVars(scip);
1422 SCIP_VAR **vars = SCIPgetVars(scip);
1423 varLbs =
new SCIP_Real[
nVars];
1424 varUbs =
new SCIP_Real[
nVars];
1425 for(
int v = 0; v <
nVars; ++v )
1427 SCIP_VAR *var = vars[v];
1428 varLbs[SCIPvarGetProbindex(var)] = SCIPvarGetLbLocal(var);
1429 varUbs[SCIPvarGetProbindex(var)] = SCIPvarGetUbLocal(var);
1436 SCIP_Bool success = TRUE;
1437 SCIP_CALL_ABORT( SCIPcreate(&tempScip) );
1438 SCIP_CALL_ABORT( SCIPsetIntParam(tempScip,
"timing/clocktype", 2) );
1441 SCIP_CALL_ABORT( SCIPincludeDefaultPlugins(tempScip) );
1445 #ifdef SCIP_THREADSAFE_MESSAGEHDLRS 1446 SCIPsetMessagehdlrQuiet(tempScip, TRUE);
1452 int retcode = SCIPreadProb(tempScip,
getFileName(), NULL );
1454 if( retcode != SCIP_OKAY )
1456 std::cout <<
"SCIPreadProb returns: " << retcode << std::endl;
1460 std::cout <<
"Cannot read < " << getcwd(dir, 511) <<
"/" <<
getFileName() << std::endl;
1464 std::cout <<
"Cannot read < " <<
getFileName() << std::endl;
1472 SCIP_CALL_ABORT( SCIPtransformProb(tempScip));
1476 SCIP_CALL_ABORT( SCIPreadProb(tempScip, isolname, NULL ) );
1480 char *probNameFromFileName;
1483 SCIPsplitFilename(temp, NULL, &probNameFromFileName, NULL, NULL);
1484 SCIP_CALL_ABORT( SCIPsetProbName(tempScip, probNameFromFileName));
1487 if( noPreprocessingInLC )
1489 SCIP_CALL_ABORT( SCIPsetIntParam(tempScip,
"presolving/maxrounds", 0));
1493 if( settingsNameLC )
1495 SCIP_CALL_ABORT( SCIPreadParams(tempScip, settingsNameLC) );
1506 SCIP_CALL_ABORT( SCIPpresolve(tempScip) );
1507 SCIP_STATUS scipStatus = SCIPgetStatus(tempScip);
1508 if( scipStatus == SCIP_STATUS_OPTIMAL )
return;
1511 if( usetRootNodeCuts )
1513 if( !addRootNodeCuts(tempScip,scipDiffParamSetRoot) )
1519 if( SCIPgetNVars(tempScip) == 0 )
1524 assert( SCIPgetStage(scip) == SCIP_STAGE_INIT );
1526 assert( nCopies > 0 );
1528 SCIP_HASHMAP* varmap = 0;
1529 SCIP_HASHMAP* conssmap = 0;
1531 assert( nCopies == 1);
1544 #if SCIP_VERSION == 211 && SCIP_SUBVERSION == 0 1545 SCIP_CALL_ABORT( SCIPcopyPlugins(tempScip, scip, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE,
1546 TRUE, TRUE, TRUE, TRUE, &success) );
1548 #if SCIP_APIVERSION >= 100 1549 #if SCIP_APIVERSION >= 101 1550 SCIP_CALL_ABORT( SCIPcopyPlugins(tempScip, scip, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE,
1551 TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, FALSE, &success) );
1553 SCIP_CALL_ABORT( SCIPcopyPlugins(tempScip, scip, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE,
1554 TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, FALSE, &success) );
1556 #elif SCIP_APIVERSION >= 17 1557 SCIP_CALL_ABORT( SCIPcopyPlugins(tempScip, scip, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE,
1558 TRUE, TRUE, TRUE, TRUE, TRUE, FALSE, &success) );
1560 SCIP_CALL_ABORT( SCIPcopyPlugins(tempScip, scip, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE,
1561 TRUE, TRUE, TRUE, TRUE, FALSE, &success) );
1564 SCIP_CALL_ABORT( SCIPcopyParamSettings(tempScip, scip) );
1567 if( SCIPgetNVars(tempScip) > 0 )
1569 SCIP_CALL_ABORT( SCIPhashmapCreate(&varmap, SCIPblkmem(scip), SCIPgetNVars(tempScip)) );
1571 if( SCIPgetNConss(tempScip) > 0 )
1573 SCIP_CALL_ABORT( SCIPhashmapCreate(&conssmap, SCIPblkmem(scip), SCIPgetNConss(tempScip)) );
1577 SCIP_CALL_ABORT( SCIPcopyProb(tempScip, scip, varmap, conssmap, TRUE, probNameFromFileName) );
1581 if( SCIPgetNVars(tempScip) > 0 )
1583 #if (SCIP_VERSION < 321 || ( SCIP_VERSION == 321 && SCIP_SUBVERSION < 2) ) 1584 SCIP_CALL_ABORT( SCIPcopyVars(tempScip, scip, varmap, conssmap, TRUE) );
1586 SCIP_CALL_ABORT( SCIPcopyVars(tempScip, scip, varmap, conssmap, NULL, NULL, 0, TRUE) );
1589 if( SCIPgetNConss(tempScip) > 0 )
1591 SCIP_CALL_ABORT( SCIPcopyConss(tempScip, scip, varmap, conssmap, TRUE, FALSE, &success) );
1594 #if SCIP_APIVERSION > 39 1600 SCIP_CALL_ABORT( SCIPcopyBenders(tempScip, scip, NULL, TRUE, &valid) );
1606 if( SCIPgetNConss(tempScip) > 0 )
1608 SCIPhashmapFree(&conssmap);
1610 if( SCIPgetNVars(tempScip) > 0 )
1612 SCIPhashmapFree(&varmap);
1614 SCIPfree(&tempScip);
1615 std::cerr <<
"Some constraint handler did not perform a valid copy. Cannot solve this instance." << std::endl;
1620 nVars = SCIPgetNVars(tempScip);
1622 int n = SCIPgetNVars(scip);
1626 assert(
nVars <= n );
1635 for(
int i = 0; i < SCIPgetNTotalVars(tempScip); i++ )
1642 assert(SCIPgetNTotalVars(scip) >= SCIPgetNVars(tempScip));
1645 SCIP_VAR **srcVars = SCIPgetVars(tempScip);
1648 for(
int i = 0; i < SCIPgetNVars(tempScip); i++ )
1650 SCIP_VAR* copyvar = (SCIP_VAR*)SCIPhashmapGetImage(varmap, (
void*)srcVars[i]);
1674 if( SCIPgetNConss(tempScip) > 0 )
1676 SCIPhashmapFree(&conssmap);
1678 if( SCIPgetNVars(tempScip) > 0 )
1680 SCIPhashmapFree(&varmap);
1683 SCIPfree(&tempScip);
1686 SCIP_VAR **vars = SCIPgetVars(scip);
1687 varLbs =
new SCIP_Real[
nVars];
1688 varUbs =
new SCIP_Real[
nVars];
1689 for(
int v = 0; v <
nVars; ++v )
1691 SCIP_VAR *var = vars[v];
1692 varLbs[SCIPvarGetProbindex(var)] = SCIPvarGetLbLocal(var);
1693 varUbs[SCIPvarGetProbindex(var)] = SCIPvarGetUbLocal(var);
1709 ScipParaInstance::freeMemory()
1734 delete[] posVarNames;
1740 delete [] idxLinearConsNames;
1741 idxLinearConsNames = 0;
1742 delete [] linearLhss;
1744 delete [] linearRhss;
1746 for(
int i = 0; i < nLinearConss; i++ )
1748 delete [] linearCoefs[i];
1749 delete [] idxLinearCoefsVars[i];
1751 delete [] linearCoefs;
1752 delete [] idxLinearCoefsVars;
1753 delete [] nLinearCoefs;
1755 idxLinearCoefsVars = 0;
1760 delete [] idxSetppcConsNames;
1761 idxSetppcConsNames = 0;
1762 delete [] nIdxSetppcVars;
1764 delete [] setppcTypes;
1766 for(
int i = 0; i < nSetppcConss; i++ )
1768 delete idxSetppcVars[i];
1770 delete [] idxSetppcVars;
1775 delete [] idxLogicorConsNames;
1776 idxLogicorConsNames = 0;
1777 delete [] nIdxLogicorVars;
1778 nIdxLogicorVars = 0;
1779 for(
int i = 0; i < nLogicorConss; i++ )
1781 delete [] idxLogicorVars[i];
1783 delete [] idxLogicorVars;
1786 if( nKnapsackConss )
1788 delete [] idxKnapsackConsNames;
1789 idxKnapsackConsNames = 0;
1790 delete [] capacities;
1792 delete [] nLKnapsackCoefs;
1793 nLKnapsackCoefs = 0;
1794 for(
int i = 0; i < nKnapsackConss; i++ )
1796 delete [] knapsackCoefs[i];
1797 delete [] idxKnapsackCoefsVars[i];
1799 delete [] knapsackCoefs;
1800 delete [] idxKnapsackCoefsVars;
1802 idxKnapsackCoefsVars = 0;
1806 delete [] nSos1Coefs;
1808 for(
int i = 0; i < nSos1Conss; i++ )
1810 delete [] sos1Coefs[i];
1811 delete [] idxSos1CoefsVars[i];
1813 delete [] sos1Coefs;
1814 delete [] idxSos1CoefsVars;
1816 idxSos1CoefsVars = 0;
1820 delete [] nSos2Coefs;
1822 for(
int i = 0; i < nSos1Conss; i++ )
1824 delete [] sos2Coefs[i];
1825 delete [] idxSos2CoefsVars[i];
1828 delete idxSos2CoefsVars;
1830 idxSos2CoefsVars = 0;
1832 if( nAggregatedConss )
1834 for(
int i = 0; i < nAggregatedConss; i++ )
1836 delete aggregatedCoefs[i];
1837 delete idxAggregatedCoefsVars[i];
1839 delete [] aggregatedCoefs;
1840 delete [] idxAggregatedCoefsVars;
1841 delete[] aggregatedLhsAndLhss;
1842 aggregatedCoefs = 0;
1843 idxAggregatedCoefsVars = 0;
1844 aggregatedLhsAndLhss = 0;
1853 std::ostringstream s;
1855 s <<
"lProbName = " << lProbName << std::endl;
1856 s <<
"probName = " << probName << std::endl;
1857 s <<
"objSense = " << origObjSense << std::endl;
1858 s <<
"objScale = " << objScale << std::endl;
1859 s <<
"objOffset = " << objOffset << std::endl;
1860 s <<
"nVars = " <<
nVars <<
", lVarNames = " << lVarNames << std::endl;
1861 for(
int i = 0; i <
nVars; i++ )
1863 s <<
"[" << i <<
"]: varNames = " << &varNames[posVarNames[i]]
1864 <<
", varsLbs = " << varLbs[i] <<
", varsUbs = " << varUbs[i]
1865 <<
", objCoefs = " << objCoefs[i] <<
", varTypes = " << varTypes[i];
1876 s <<
"nConss = " << nConss <<
", lConsNames = " << lConsNames << std::endl;
1877 for(
int i = 0; i < nConss; i ++ )
1879 s<<
"[" << i <<
"]: consNames = " << &consNames[posConsNames[i]] << std::endl;
1885 s <<
"nLinearConss = " << nLinearConss << std::endl;
1886 for(
int i = 0; i < nLinearConss; i++ )
1888 s <<
"[" << i <<
"]: idxLinearConsNames = " << idxLinearConsNames[i]
1889 <<
", linearLhss = " << linearLhss[i] <<
", linearRhss = " << linearRhss[i]
1890 <<
", nLinearCoefs = " << nLinearCoefs[i] << std::endl;
1891 for(
int j = 0; j < nLinearCoefs[i]; j++ )
1893 s <<
" [" << j <<
"]: linearCoefs = " << linearCoefs[i][j]
1894 <<
", idxLinearCoefsVars = " << idxLinearCoefsVars[i][j] << std::endl;
1901 s <<
"nSetppcConss = " << nSetppcConss << std::endl;
1902 for(
int i = 0; i < nSetppcConss; i++)
1904 s <<
"[" << i <<
"]: idxSetppcConsNames = " << idxSetppcConsNames[i]
1905 <<
", nIdxSetppcVars = " << nIdxSetppcVars[i] <<
", setppcTypes = " << setppcTypes[i] << std::endl;
1906 for(
int j = 0; j < nIdxSetppcVars[i]; j++ )
1908 s <<
" [" << j <<
"]: idxSetppcVars = " << idxSetppcVars[i][j] << std::endl;
1915 s <<
"nLogicorConss = " << nLogicorConss << std::endl;
1916 for(
int i = 0; i < nLogicorConss; i++ )
1918 s <<
"[" << i <<
"]: idxLogicorConsNames = " << idxLogicorConsNames[i]
1919 <<
", nIdxLogicorVars = " << nIdxLogicorVars[i] << std::endl;
1920 for(
int j = 0; j < nIdxLogicorVars[i]; j++ )
1922 s <<
" [" << j <<
"]: idxLogicorVars = " << idxLogicorVars[i][j] << std::endl;
1929 s <<
"nKnapsackConss = " << nKnapsackConss << std::endl;
1930 for(
int i = 0; i < nKnapsackConss; i++)
1932 s <<
"[" << i <<
"]: idxKnapsackConsNames = " << idxKnapsackConsNames[i]
1933 <<
", capacities = " << capacities[i] <<
", nLKnapsackCoefs = " << nLKnapsackCoefs[i] << std::endl;
1934 for(
int j = 0; j < nLKnapsackCoefs[i]; j++ )
1936 s <<
" [" << j <<
"]: knapsackCoefs = " << knapsackCoefs[i][j] <<
", idxKnapsackCoefsVars = " << idxKnapsackCoefsVars[i][j] << std::endl;
1943 s <<
"nVarboundConss = " << nVarboundConss << std::endl;
1944 for(
int i = 0; i < nVarboundConss; i++)
1946 s <<
"[" << i <<
"]: idxVarboundConsNames = " << idxVarboundConsNames[i]
1947 <<
", varboundLhss = " << varboundLhss[i] <<
", varboundRhss = " << varboundRhss[i]
1948 <<
", idxVarboundCoefVar1s = " << idxVarboundCoefVar1s[i] <<
", varboundCoef2s = " << varboundCoef2s[i]
1949 <<
", idxVarboundCoefVar2s = " << idxVarboundCoefVar2s[i] << std::endl;
1955 s <<
"nSos1Conss = " << nSos1Conss << std::endl;
1956 for(
int i = 0; i < nSos1Conss; i++ )
1958 s <<
"[" << i <<
"]: idxSos1ConsNames = " << idxSos1ConsNames[i]
1959 <<
", nSos1Coefs = " << nSos1Coefs[i] << std::endl;
1960 for(
int j = 0; j < nSos1Coefs[i]; j++ )
1962 s <<
" [" << j <<
"]: sos1Coefs = " << sos1Coefs[i][j] <<
", idxSos1CoefsVars = " << idxSos1CoefsVars[i][j] << std::endl;
1969 s <<
"nSos2Conss = " << nSos2Conss << std::endl;
1970 for(
int i = 0; i < nSos2Conss; i++ )
1972 s <<
"[" << i <<
"]: idxSos2ConsNames = " << idxSos2ConsNames[i]
1973 <<
", nSos2Coefs = " << nSos2Coefs[i] << std::endl;
1974 for(
int j = 0; j < nSos2Coefs[i]; j++ )
1976 s <<
" [" << j <<
"]: sos2Coefs = " << sos2Coefs[i][j] <<
", idxSos2CoefsVars = " << idxSos2CoefsVars[i][j] << std::endl;
1983 s <<
"nAggregatedConss = " << nAggregatedConss <<
", lAggregatedVarNames = " << lAggregatedVarNames
1984 <<
", lAggregatedConsNames = " << lAggregatedConsNames << std::endl;
1985 for(
int i = 0; i < nAggregatedConss; i++)
1987 s <<
"[" << i <<
"]: aggregatedVarNames = " << aggregatedVarNames[posAggregatedVarNames[i]]
1988 <<
", aggregatedConsNames = " << aggregatedConsNames[posAggregatedConsNames[i]]
1989 <<
", aggregatedLhsAndLhss = " << aggregatedLhsAndLhss[i] <<
", nAggregatedCoefs = " << nAggregatedCoefs[i] << std::endl;
1990 for(
int j = 0; j < nAggregatedCoefs[i]; j++ )
1992 s <<
" [" << j <<
"]: aggregatedCoefs = " << aggregatedCoefs[i][j]
1993 <<
", idxAggregatedCoefsVars = " << idxAggregatedCoefsVars[i][j] << std::endl;
static const int LpMaxNamelen
ParaInstance extenstion for SCIP solver.
void setParametersInScip(SCIP *scip)
virtual const char * getFileName()=0
bool copyIncreasedVariables
void createProblem(SCIP *scip, int method, bool noPreprocessingInLC, bool usetRootNodeCuts, ScipDiffParamSet *scipDiffParamSetRoot, ScipDiffParamSet *scipDiffParamSet, char *settingsNameLC, char *isolname)
Defines for UG Framework.
static SCIP_DECL_HASHKEYVAL(hashKeyValVar)
#define THROW_LOGICAL_ERROR1(msg1)
#define THROW_LOGICAL_ERROR2(msg1, msg2)
int * mapToSolverLocalIndecies
static const char * PRESOLVED_INSTANCE
void includeUserPlugins(SCIP *inScip)
virtual ~ScipParaInstance()
int * mapToOriginalIndecies
static SCIP_DECL_HASHGETKEY(hashGetKeyVar)
const std::string toString()
#define THROW_LOGICAL_ERROR3(msg1, msg2, msg3)
static SCIP_DECL_HASHKEYEQ(hashKeyEqVar)