44 #include "scip/scip.h" 47 #include "scip/cons_linear.h" 48 #include "scip/cons_setppc.h" 49 #include "scip/misc.h" 50 #include "scip/struct_misc.h" 63 #define CONS_SPECIFIC 2 67 #define SYM_CONS_LIMIT 20000 68 #define CYC_CONS_LIMIT 15000 84 SCIP_CONS** flowbcons;
151 double maximum = 0.0;
157 *central_term = g->
source[0];
168 for( i = 0; i < g->
knots; i++ )
177 *central_term = center;
182 SCIP_CALL( SCIPallocBufferArray(scip, &path, g->
knots) );
183 SCIP_CALL( SCIPallocBufferArray(scip, &cost, g->
edges) );
185 assert(path != NULL);
186 assert(cost != NULL);
188 for( i = 0; i < g->
knots; i++ )
191 for( i = 0; i < g->edges; i++ )
194 for( i = 0; i < g->
knots; i++ )
204 for( k = 0; k < g->
knots; k++ )
206 assert((path[k].edge >= 0) || (k == i));
207 assert((path[k].edge >= 0) || (path[k].dist == 0));
213 if( path[k].dist > max )
239 if( SCIPisLT(scip, max, minimum) || (SCIPisEQ(scip, max, minimum) && (g->
grad[i] > degree)) )
255 SCIPfreeBufferArray(scip, &cost);
256 SCIPfreeBufferArray(scip, &path);
258 SCIPverbMessage(scip, SCIP_VERBLEVEL_HIGH, NULL,
"Central Terminal is %d (min=%g, max=%g, old=%g)\n",
259 center, minimum, maximum, oldval);
261 *central_term = center;
269 SCIP_PROBDATA** probdata,
273 assert(scip != NULL);
274 assert(probdata != NULL);
277 SCIP_CALL( SCIPallocMemory(scip, probdata) );
279 (*probdata)->graph =
graph;
280 (*probdata)->xval = NULL;
281 (*probdata)->lastlpiters = -1;
286 (*probdata)->copy =
FALSE;
287 (*probdata)->logfile = NULL;
288 (*probdata)->origlogfile = NULL;
289 (*probdata)->intlogfile = NULL;
290 (*probdata)->origintlogfile = NULL;
292 (*probdata)->ug =
FALSE;
293 (*probdata)->nSolvers = 0;
294 (*probdata)->ugDual = 0.0;
303 SCIP_PROBDATA** probdata
308 SCIPdebugMessage(
"probdataFree \n");
309 assert(scip != NULL);
310 assert(probdata != NULL);
313 for( e = 0; e < (*probdata)->nvars; ++e )
315 SCIP_CALL( SCIPreleaseVar(scip, &(*probdata)->edgevars[e]) );
317 SCIPfreeMemoryArrayNull(scip, &(*probdata)->edgevars);
319 if( (*probdata)->offsetvar != NULL )
321 SCIP_CALL( SCIPreleaseVar(scip, &(*probdata)->offsetvar) );
327 assert((*probdata)->mode ==
MODE_CUT);
330 for( t = 0; t < (*probdata)->nnodes; ++t)
332 SCIP_CALL( SCIPreleaseCons(scip, &((*probdata)->degcons[t])) );
334 SCIPfreeMemoryArrayNull(scip, &((*probdata)->degcons));
340 assert((*probdata)->mode ==
MODE_CUT);
342 for( e = 0; e < (*probdata)->nnonterms; e++ )
343 SCIP_CALL( SCIPreleaseCons(scip, &((*probdata)->flowbcons[e])) );
345 SCIPfreeMemoryArrayNull(scip, &((*probdata)->flowbcons));
351 for( e = 0; e < (*probdata)->nedges; e++ )
352 SCIP_CALL( SCIPreleaseCons(scip, &((*probdata)->prizecyclecons[e])) );
354 SCIPfreeMemoryArrayNull(scip, &((*probdata)->prizecyclecons));
360 if( (*probdata)->usesymcons )
362 e = (((*probdata)->realnterms - 1) * (*probdata)->realnterms) / 2;
364 for( t = 0; t < e; ++t)
365 SCIP_CALL( SCIPreleaseCons(scip, &((*probdata)->prizesymcons[t])) );
367 SCIPfreeMemoryArrayNull(scip, &((*probdata)->prizesymcons));
369 SCIP_CALL( SCIPreleaseCons(scip, &((*probdata)->prizecons)) );
376 for( t = 0; t < (*probdata)->realnterms; ++t)
378 SCIP_CALL( SCIPreleaseCons(scip, &((*probdata)->pathcons[t])) );
381 else if( (*probdata)->mode ==
MODE_FLOW )
383 for( t = 0; t < (*probdata)->realnterms; ++t)
386 for( e = 0; e < (*probdata)->nnodes - 1; ++e )
388 SCIP_CALL( SCIPreleaseCons(scip, &((*probdata)->pathcons[t * ((*probdata)->nnodes - 1 ) + e])) );
390 for( e = 0; e < (*probdata)->nedges; ++e )
392 SCIP_CALL( SCIPreleaseVar(scip, &(*probdata)->flowvars[t * (*probdata)->nedges + e]) );
394 if( (*probdata)->bigt )
397 SCIPfreeMemoryArrayNull(scip, &(*probdata)->flowvars);
402 for( t = 0; t < (*probdata)->realnterms; ++t)
404 for( e = 0; e < (*probdata)->nedges; ++e )
406 SCIP_CALL( SCIPreleaseCons(scip, &((*probdata)->edgecons[t * (*probdata)->nedges + e])) );
408 if( (*probdata)->bigt )
412 SCIPfreeMemoryArrayNull(scip, &((*probdata)->edgecons));
413 SCIPfreeMemoryArrayNull(scip, &((*probdata)->pathcons));
416 SCIPfreeMemoryArrayNull(scip, &(*probdata)->xval);
417 SCIPfreeMemoryArrayNull(scip, &(*probdata)->realterms);
420 SCIPfreeMemory(scip, probdata);
429 const char* filename,
433 char label[SCIP_MAXSTRLEN];
439 assert(graph != NULL);
440 file = fopen((filename != NULL) ? filename :
"stpgraph.gml",
"w");
443 for( e = 0; e < graph->
edges; e += 2 )
445 assert(graph->
tail[e] == graph->
head[e + 1]);
446 assert(graph->
tail[e + 1] == graph->
head[e]);
451 SCIPgmlWriteOpening(file,
FALSE);
456 for( n = 0; n < graph->
knots; ++n )
459 if( n == graph->
source[0] )
461 (void)SCIPsnprintf(label, SCIP_MAXSTRLEN,
"(%d) Root", n);
462 SCIPgmlWriteNode(file, (
unsigned int)n, label,
"rectangle",
"#666666", NULL);
465 else if( graph->
term[n] == 0 )
467 (void)SCIPsnprintf(label, SCIP_MAXSTRLEN,
"(%d) Terminal %d", n, e + 1);
468 SCIPgmlWriteNode(file, (
unsigned int)n, label,
"circle",
"#ff0000", NULL);
473 (void)SCIPsnprintf(label, SCIP_MAXSTRLEN,
"(%d) Node %d", n, n + 1 - e - m);
474 SCIPgmlWriteNode(file, (
unsigned int)n, label,
"circle",
"#336699", NULL);
477 (void)SCIPsnprintf(label, SCIP_MAXSTRLEN,
"");
478 if( n == graph->
source[0] )
481 SCIPgmlWriteNode(file, (
unsigned int)n, label,
"rectangle",
"#666666", NULL);
484 else if( graph->
term[n] == 0 )
487 SCIPgmlWriteNode(file, (
unsigned int)n, label,
"rectangle",
"#666666", NULL);
492 SCIPgmlWriteNode(file, (
unsigned int)n, label,
"circle",
"#666666", NULL);
499 for( e = 0; e < graph->
edges; e += 2 )
502 (void)SCIPsnprintf(label, SCIP_MAXSTRLEN,
"%8.2f", graph->
cost[e]);
504 if( edgemark != NULL && edgemark[e / 2] )
505 SCIPgmlWriteEdge(file, (
unsigned int)graph->
tail[e], (
unsigned int)graph->
head[e], label,
"#ff0000");
507 SCIPgmlWriteEdge(file, (
unsigned int)graph->
tail[e], (
unsigned int)graph->
head[e], label, NULL);
511 SCIPgmlWriteClosing(file);
520 SCIP_PROBDATA* probdata
525 assert(scip != NULL);
526 assert(probdata != NULL);
528 SCIPdebugMessage(
"createHopeConstraint \n");
529 graph = probdata->graph;
530 assert(graph != NULL);
532 SCIPdebugMessage(
"Hop limit: %f \n ", rhs);
535 SCIP_CALL( SCIPcreateConsLinear ( scip, &(probdata->hopcons),
"HopConstraint", 0, NULL, NULL,
536 -SCIPinfinity(scip), rhs,
TRUE,
TRUE,
TRUE,
TRUE,
TRUE,
FALSE,
FALSE,
FALSE,
FALSE,
FALSE) );
538 SCIP_CALL( SCIPaddCons(scip, probdata->hopcons) );
548 SCIP_PROBDATA* probdata
553 char consname[SCIP_MAXSTRLEN];
557 assert(scip != NULL);
558 assert(probdata != NULL);
560 SCIPdebugMessage(
"createDegreeConstraints \n");
561 graph = probdata->graph;
562 nnodes = probdata->nnodes;
564 SCIP_CALL( SCIPallocMemoryArray(scip, &(probdata->degcons), nnodes ) );
566 for( k = 0; k <
nnodes; ++k )
568 (void)SCIPsnprintf(consname, SCIP_MAXSTRLEN,
"DegreeConstraint%d", k);
569 SCIP_CALL( SCIPcreateConsLinear(scip, &(probdata->degcons[k]), consname, 0, NULL, NULL,
570 -SCIPinfinity(scip), (SCIP_Real)graph->
maxdeg[k],
TRUE,
TRUE,
TRUE,
TRUE,
TRUE,
FALSE,
FALSE,
FALSE,
FALSE,
FALSE) );
572 SCIP_CALL( SCIPaddCons(scip, probdata->degcons[k]) );
583 SCIP_PROBDATA* probdata
593 char consname[SCIP_MAXSTRLEN];
595 assert(scip != NULL);
596 assert(probdata != NULL);
598 graph = probdata->graph;
599 realnterms = probdata->realnterms;
601 assert(graph != NULL);
604 nedges = graph->
edges;
606 SCIPdebugMessage(
"createPrizeConstraints \n");
610 ro2 = (realnterms * (realnterms - 1)) / 2;
611 SCIP_CALL( SCIPallocMemoryArray(scip, &(probdata->prizesymcons), ro2) );
612 for( r = 0; r < ro2; r++ )
614 (void)SCIPsnprintf(consname, SCIP_MAXSTRLEN,
"PrizeSymConstraint%d", r);
617 SCIP_CALL( SCIPcreateConsLinear(scip, &(probdata->prizesymcons[r]), consname, 0, NULL, NULL,
618 -SCIPinfinity(scip), 1.0,
TRUE,
TRUE,
TRUE,
TRUE,
TRUE,
FALSE,
FALSE,
FALSE,
FALSE,
FALSE) );
620 SCIP_CALL( SCIPcreateConsSetpack(scip, &(probdata->prizesymcons[r]), consname, 0, NULL,
TRUE,
TRUE,
623 SCIP_CALL( SCIPaddCons(scip, probdata->prizesymcons[r]) );
630 (void)SCIPsnprintf(consname, SCIP_MAXSTRLEN,
"PrizeConstraint");
631 SCIP_CALL( SCIPcreateConsLinear ( scip, &(probdata->prizecons), consname, 0, NULL, NULL,
632 1.0, 1.0,
TRUE,
TRUE,
TRUE,
TRUE,
TRUE,
FALSE,
FALSE,
FALSE,
FALSE,
FALSE) );
633 SCIP_CALL( SCIPaddCons(scip, probdata->prizecons) );
639 SCIP_CALL( SCIPallocMemoryArray(scip, &(probdata->prizecyclecons), nedges) );
640 for( r = 0; r <
nedges; r++ )
642 (void)SCIPsnprintf(consname, SCIP_MAXSTRLEN,
"PrizeLPConstraint%d", ro2);
643 if( root == graph->
head[r] )
645 SCIP_CALL( SCIPcreateConsLinear ( scip, &(probdata->prizecyclecons[ro2]), consname, 0, NULL, NULL,
646 -SCIPinfinity(scip), 1.0,
TRUE,
TRUE,
TRUE,
TRUE,
TRUE,
FALSE,
FALSE,
FALSE,
FALSE,
FALSE) );
650 SCIP_CALL( SCIPcreateConsLinear ( scip, &(probdata->prizecyclecons[ro2]), consname, 0, NULL, NULL,
651 -SCIPinfinity(scip), 0.0,
TRUE,
TRUE,
TRUE,
TRUE,
TRUE,
FALSE,
FALSE,
FALSE,
FALSE,
FALSE) );
653 SCIP_CALL( SCIPaddCons(scip, probdata->prizecyclecons[ro2++]) );
659 SCIP_CALL( SCIPallocMemoryArray(scip, &(probdata->prizecyclecons), realnterms) );
662 (void)SCIPsnprintf(consname, SCIP_MAXSTRLEN,
"PrizeLPConstraint%d", r);
663 SCIP_CALL( SCIPcreateConsLinear ( scip, &(probdata->prizecyclecons[r]), consname, 0, NULL, NULL,
664 -SCIPinfinity(scip), 0,
TRUE,
TRUE,
TRUE,
TRUE,
TRUE,
FALSE,
FALSE,
FALSE,
FALSE,
FALSE) );
665 SCIP_CALL( SCIPaddCons(scip, probdata->prizecyclecons[r]) );
667 assert(r == realnterms);
678 SCIP_RETCODE createFlowBalanceConstraints(
680 SCIP_PROBDATA* probdata
687 char consname[SCIP_MAXSTRLEN];
689 assert(scip != NULL);
690 assert(probdata != NULL);
692 graph = probdata->graph;
694 assert(graph != NULL);
703 SCIPdebugMessage(
"createFlowBalanceConstraints \n");
706 SCIP_CALL( SCIPallocMemoryArray(scip, &(probdata->flowbcons), nnonterms) );
709 (void)SCIPsnprintf(consname, SCIP_MAXSTRLEN,
"FlowBalanceConstraint%d", r);
710 SCIP_CALL( SCIPcreateConsLinear ( scip, &(probdata->flowbcons[r]), consname, 0, NULL, NULL,
711 -SCIPinfinity(scip), 0.0,
TRUE,
TRUE,
TRUE,
TRUE,
TRUE,
FALSE,
FALSE,
FALSE,
FALSE,
FALSE) );
712 SCIP_CALL( SCIPaddCons(scip, probdata->flowbcons[r]) );
724 SCIP_PROBDATA* probdata
728 char consname[SCIP_MAXSTRLEN];
737 assert(scip != NULL);
738 assert(probdata != NULL);
741 SCIPdebugMessage(
"createConstraints \n");
742 graph = probdata->graph;
743 nedges = probdata->nedges;
744 nnodes = probdata->nnodes;
745 realnterms = probdata->realnterms;
748 if( !probdata->bigt )
751 SCIP_CALL( SCIPallocMemoryArray(scip, &(probdata->edgecons), (realnterms) * (nedges)) );
754 for( e = 0; e <
nedges; ++e )
756 (void)SCIPsnprintf(consname, SCIP_MAXSTRLEN,
"EdgeConstraint%d_%d", t, e);
757 SCIP_CALL( SCIPcreateConsLinear ( scip, &( probdata->edgecons[t * nedges + e] ), consname, 0, NULL, NULL,
758 -SCIPinfinity(scip), 0.0,
TRUE,
TRUE,
TRUE,
TRUE,
TRUE,
FALSE, probdata->mode ==
MODE_PRICE,
FALSE,
FALSE,
FALSE) );
759 SCIP_CALL( SCIPaddCons(scip, probdata->edgecons[t * nedges + e]) );
766 SCIP_CALL( SCIPallocMemoryArray(scip, &(probdata->edgecons), nedges) );
767 for( e = 0; e <
nedges; ++e )
769 (void)SCIPsnprintf(consname, SCIP_MAXSTRLEN,
"EdgeConstraintT%d", e);
770 SCIP_CALL( SCIPcreateConsLinear ( scip, &( probdata->edgecons[e] ), consname,
771 0, NULL, NULL, -SCIPinfinity(scip), 0.0,
773 SCIP_CALL( SCIPaddCons(scip, probdata->edgecons[e]) );
781 SCIP_CALL( SCIPallocMemoryArray(scip, &(probdata->pathcons), realnterms) );
785 (void)SCIPsnprintf(consname, SCIP_MAXSTRLEN,
"PathConstraint%d", t);
786 SCIP_CALL( SCIPcreateConsLinear ( scip, &(probdata->pathcons[t]), consname, 0, NULL, NULL, 1.0, SCIPinfinity(scip),
789 SCIP_CALL( SCIPaddCons(scip, probdata->pathcons[t]) );
796 if( !probdata->bigt )
799 SCIP_CALL( SCIPallocMemoryArray(scip, &(probdata->pathcons), realnterms * (nnodes - 1)) );
803 for( k = 0; k <
nnodes; ++k )
806 if( k != graph->
source[0])
809 if( k != probdata->realterms[t] )
811 (void)SCIPsnprintf(consname, SCIP_MAXSTRLEN,
"PathConstraint%d_%d", t, k2);
812 SCIP_CALL( SCIPcreateConsLinear(scip, &( probdata->pathcons[t * (nnodes - 1) + k2] ), consname,
813 0, NULL, NULL, 0.0, 0.0,
TRUE,
TRUE,
TRUE,
TRUE,
TRUE,
FALSE,
FALSE,
FALSE,
FALSE,
FALSE) );
814 SCIP_CALL( SCIPaddCons(scip, probdata->pathcons[t * (nnodes - 1) + k2]) );
820 (void)SCIPsnprintf(consname, SCIP_MAXSTRLEN,
"PathConstraint%d_%d", t, k2);
821 SCIP_CALL( SCIPcreateConsLinear(scip, &( probdata->pathcons[t * (nnodes - 1) + k2] ), consname,
822 0, NULL, NULL, 1.0, 1.0,
TRUE,
TRUE,
TRUE,
TRUE,
TRUE,
FALSE,
FALSE,
FALSE,
FALSE,
FALSE) );
823 SCIP_CALL( SCIPaddCons(scip, probdata->pathcons[t * (nnodes - 1) + k2]) );
834 SCIP_CALL( SCIPallocMemoryArray(scip, &(probdata->pathcons), (nnodes - 1)) );
836 for( k = 0; k <
nnodes; ++k )
839 if( k != graph->
source[0])
842 if( graph->
term[k] != 0 )
844 (void)SCIPsnprintf(consname, SCIP_MAXSTRLEN,
"PathConstraintT%d", k2);
845 SCIP_CALL( SCIPcreateConsLinear(scip, &( probdata->pathcons[k2] ), consname,
846 0, NULL, NULL, 0.0, 0.0,
TRUE,
TRUE,
TRUE,
TRUE,
TRUE,
FALSE,
FALSE,
FALSE,
FALSE,
FALSE) );
847 SCIP_CALL( SCIPaddCons(scip, probdata->pathcons[k2]) );
852 (void)SCIPsnprintf(consname, SCIP_MAXSTRLEN,
"PathConstraintT%d", k2);
853 SCIP_CALL( SCIPcreateConsLinear(scip, &( probdata->pathcons[k2] ), consname,
854 0, NULL, NULL, 1.0, 1.0,
TRUE,
TRUE,
TRUE,
TRUE,
TRUE,
FALSE,
FALSE,
FALSE,
FALSE,
FALSE) );
855 SCIP_CALL( SCIPaddCons(scip, probdata->pathcons[k2]) );
870 SCIP_PROBDATA* probdata,
882 char varname[SCIP_MAXSTRLEN];
884 assert(scip != NULL);
885 assert(probdata != NULL);
889 graph = probdata->graph;
890 SCIPdebugMessage(
"createVariables \n");
895 int nedges = probdata->nedges;
896 int nvars = probdata->nvars;
898 int root = graph->
source[0];
900 SCIP_Bool objint = SCIPisIntegral(scip, offset);
902 assert(nedges == graph->
edges);
904 SCIP_CALL( SCIPallocMemoryArray(scip, &probdata->xval, nvars) );
905 SCIP_CALL( SCIPallocMemoryArray(scip, &probdata->edgevars, nvars) );
910 assert(probdata->nlayers == 1);
912 for( e = 0; e <
nedges; ++e )
914 (void)SCIPsnprintf(varname, SCIP_MAXSTRLEN,
"x_%d_%d", graph->
tail[e], graph->
head[e]);
915 SCIP_CALL( SCIPcreateVarBasic(scip, &probdata->edgevars[e], varname, 0.0, 1.0, graph->
cost[e], SCIP_VARTYPE_BINARY) );
916 SCIP_CALL( SCIPaddVar(scip, probdata->edgevars[e]) );
917 objint = objint && SCIPisIntegral(scip, graph->
cost[e]);
922 for( e = 0; e <
nedges; e=e+2 )
926 (void)SCIPsnprintf(varname, SCIP_MAXSTRLEN,
"x_%d_%d", graph->
tail[e], graph->
head[e]);
927 SCIP_CALL( SCIPcreateConsLinear(scip, &cons, varname,
928 0, NULL, NULL, -SCIPinfinity(scip), 1.0,
TRUE,
TRUE,
TRUE,
TRUE,
TRUE,
FALSE,
FALSE,
FALSE,
FALSE,
FALSE) );
930 SCIP_CALL( SCIPaddCons(scip, cons) );
931 SCIP_CALL( SCIPaddCoefLinear(scip, cons, probdata->edgevars[e], 1.0) );
932 SCIP_CALL( SCIPaddCoefLinear(scip, cons, probdata->edgevars[e+1], 1.0) );
939 for( e = 0; e <
nedges; ++e )
943 SCIP_CALL( SCIPaddCoefLinear(scip, probdata->hopcons, probdata->edgevars[e], hopfactor) );
950 for( k = 0; k <
nnodes; ++k )
954 SCIP_CALL( SCIPaddCoefLinear(scip, probdata->degcons[k], probdata->edgevars[e], 1.0) );
955 SCIP_CALL( SCIPaddCoefLinear(scip, probdata->degcons[k], probdata->edgevars[
flipedge(e)], 1.0) );
970 for( k = 0; k <
nnodes; k++ )
977 SCIP_CALL( SCIPaddCoefLinear(scip, probdata->flowbcons[k2], probdata->edgevars[a], 1.0) );
982 SCIP_CALL( SCIPaddCoefLinear(scip, probdata->flowbcons[k2], probdata->edgevars[a], -1.0) );
989 if( probdata->usesymcons )
991 SCIP_CALL( SCIPallocBufferArray(scip, &pseudoterms, probdata->realnterms) );
998 for( e = 0; e <
nedges; e++ )
1000 head = graph->
head[e];
1001 SCIP_CALL( SCIPaddCoefLinear(scip, probdata->prizecyclecons[e], probdata->edgevars[e], 1.0) );
1002 SCIP_CALL( SCIPaddCoefLinear(scip, probdata->prizecyclecons[e], probdata->edgevars[
flipedge(e)], 1.0) );
1007 SCIP_CALL( SCIPaddCoefLinear(scip, probdata->prizecyclecons[e], probdata->edgevars[a], -1.0) );
1015 head = graph->
head[e];
1019 SCIP_CALL( SCIPaddCoefLinear(scip, probdata->prizecons, probdata->edgevars[e], 1.0) );
1022 SCIP_CALL( SCIPchgVarBranchPriority(scip, probdata->edgevars[e], 10) );
1023 if( probdata->usesymcons )
1027 assert(pseudoterms != NULL);
1029 pseudoterms[t] = head;
1030 for( k = 0; k < t; k++ )
1035 SCIP_CALL( SCIPaddCoefLinear(scip, probdata->prizesymcons[k2], probdata->edgevars[a], 1.0) );
1037 SCIP_CALL( SCIPaddCoefSetppc(scip, probdata->prizesymcons[k2], probdata->edgevars[a]) );
1040 SCIP_CALL( SCIPaddCoefLinear(scip, probdata->prizesymcons[k2], probdata->edgevars[e], 1.0) );
1042 SCIP_CALL( SCIPaddCoefSetppc(scip, probdata->prizesymcons[k2], probdata->edgevars[e]) );
1050 if( probdata->usesymcons )
1051 SCIPfreeBufferArray(scip, &pseudoterms);
1059 for( e = 0; e <
nedges; ++e )
1061 (void)SCIPsnprintf(varname, SCIP_MAXSTRLEN,
"EdgeVar%d_%d", graph->
tail[e], graph->
head[e]);
1063 SCIP_CALL( SCIPcreateVarBasic(scip, &var, varname, 0.0, 1.0, graph->
cost[e], SCIP_VARTYPE_BINARY) );
1064 objint = objint && SCIPisIntegral(scip, graph->
cost[e]);
1065 SCIP_CALL( SCIPaddVar(scip, var) );
1066 SCIP_CALL( SCIPchgVarUbLazy(scip, var, 1.0) );
1068 if( !probdata->bigt )
1072 SCIP_CALL( SCIPaddCoefLinear(scip, probdata->edgecons[t * nedges + e], var, -1.0) );
1077 SCIP_CALL( SCIPaddCoefLinear(scip, probdata->edgecons[e], var, (
double) -realnterms) );
1079 probdata->edgevars[e] = var;
1089 probdata->flowvars = NULL;
1092 SCIP_CALL( SCIPallocMemoryArray(scip, &path, graph->
knots) );
1093 SCIP_CALL( SCIPallocMemoryArray(scip, &edgecost, nedges) );
1094 for( e = 0; e <
nedges; ++e )
1095 edgecost[e] = graph->
cost[e];
1097 for( e = 0; e < graph->knots; e++ )
1105 (void)SCIPsnprintf(varname, SCIP_MAXSTRLEN,
"PathVar%d_0", t);
1107 SCIP_CALL( SCIPcreateVarBasic(scip, &var, varname, 0.0, SCIPinfinity(scip), 0.0, SCIP_VARTYPE_CONTINUOUS) );
1108 SCIP_CALL( SCIPaddVar(scip, var) );
1109 SCIP_CALL( SCIPchgVarUbLazy(scip, var, 1.0) );
1110 SCIP_CALL( SCIPaddCoefLinear(scip, probdata->pathcons[t], var, 1.0) );
1111 tail = probdata->realterms[t];
1112 while( tail != root )
1114 if( !probdata->bigt )
1116 SCIP_CALL( SCIPaddCoefLinear(scip, probdata->edgecons[t * nedges + path[tail].
edge], var, 1.0) );
1120 SCIP_CALL( SCIPaddCoefLinear(scip, probdata->edgecons[path[tail].
edge], var, 1.0) );
1123 tail = graph->
tail[path[tail].
edge];
1128 SCIPfreeMemoryArray(scip, &edgecost);
1129 SCIPfreeMemoryArray(scip, &path);
1136 if ( !probdata->bigt )
1141 SCIP_CALL( SCIPallocMemoryArray(scip, &probdata->flowvars, nflows * nedges) );
1144 for( e = 0; e <
nedges; ++e )
1146 for( t = 0; t < nflows; ++t )
1149 (void)SCIPsnprintf(varname, SCIP_MAXSTRLEN,
"FlowVar%d.%d_%d", t, graph->
tail[e], graph->
head[e]);
1150 SCIP_CALL( SCIPcreateVarBasic(scip, &var, varname, 0.0, SCIPinfinity(scip), 0.0, SCIP_VARTYPE_CONTINUOUS) );
1151 SCIP_CALL( SCIPaddVar(scip, var) );
1152 probdata->flowvars[t * nedges + e] = var;
1153 SCIP_CALL( SCIPaddCoefLinear(scip, probdata->edgecons[t * nedges + e], probdata->flowvars[t * nedges + e], 1.0) );
1158 for( t = 0; t < nflows; ++t )
1161 for( k = 0; k <
nnodes; ++k )
1168 SCIP_CALL( SCIPaddCoefLinear(scip, probdata->pathcons[t * (nnodes - 1) + k2], probdata->flowvars[t * nedges + e], 1.0) );
1174 SCIP_CALL( SCIPaddCoefLinear(scip, probdata->pathcons[t * (nnodes - 1) + k2], probdata->flowvars[t * nedges + e], -1.0) );
1185 SCIP_CALL( SCIPsetObjIntegral(scip) );
1189 probdata->edgevars = NULL;
1190 probdata->flowvars = NULL;
1194 (void) SCIPsnprintf(varname, SCIP_MAXSTRLEN,
"OFFSET");
1195 SCIP_CALL( SCIPcreateVarBasic(scip, &probdata->offsetvar, varname, 1.0, 1.0, offset, SCIP_VARTYPE_CONTINUOUS) );
1196 SCIP_CALL( SCIPaddVar(scip, probdata->offsetvar) );
1215 SCIPdebugMessage(
"########################## probcopy ###########################\n");
1217 SCIP_CALL(
graph_copy(scip, sourcedata->graph, &graphcopy) );
1224 (*targetdata)->minelims = sourcedata->minelims;
1225 (*targetdata)->offset = sourcedata->offset;
1226 (*targetdata)->mode = sourcedata->mode;
1227 (*targetdata)->bigt = sourcedata->bigt;
1228 (*targetdata)->nlayers = sourcedata->nlayers;
1229 (*targetdata)->nedges = sourcedata->nedges;
1230 (*targetdata)->nnodes = sourcedata->nnodes;
1231 (*targetdata)->nterms = sourcedata->nterms;
1232 (*targetdata)->nnonterms = sourcedata->nnonterms;
1233 (*targetdata)->realnterms = sourcedata->realnterms;
1234 (*targetdata)->emitgraph = sourcedata->emitgraph;
1235 (*targetdata)->usesymcons = sourcedata->usesymcons;
1236 (*targetdata)->usecyclecons = sourcedata->usecyclecons;
1237 (*targetdata)->nvars = sourcedata->nvars;
1238 (*targetdata)->copy =
TRUE;
1239 (*targetdata)->offsetvar = NULL;
1241 if( sourcedata->offsetvar != NULL && SCIPvarIsActive(sourcedata->offsetvar) )
1245 SCIP_CALL( SCIPgetVarCopy(sourcescip, scip, sourcedata->offsetvar, &((*targetdata)->offsetvar), varmap, consmap, global, &success) );
1248 SCIP_CALL( SCIPcaptureVar(scip, (*targetdata)->offsetvar) );
1251 if( sourcedata->nedges > 0 )
1259 SCIP_CALL( SCIPallocMemoryArray(scip, &(*targetdata)->xval, sourcedata->nvars) );
1260 SCIP_CALL( SCIPallocMemoryArray(scip, &(*targetdata)->edgevars, sourcedata->nvars) );
1262 for( v = sourcedata->nvars - 1; v >= 0; --v )
1264 SCIP_CALL( SCIPgetVarCopy(sourcescip, scip, sourcedata->edgevars[v], &((*targetdata)->edgevars[v]), varmap, consmap, global, &success) );
1267 SCIP_CALL( SCIPcaptureVar(scip, (*targetdata)->edgevars[v]) );
1273 (*targetdata)->edgecons = NULL;
1274 (*targetdata)->pathcons = NULL;
1277 SCIP_CALL( SCIPallocMemoryArray(scip, &(*targetdata)->degcons, sourcedata->nnodes) );
1278 for( c = sourcedata->nnodes - 1; c >= 0; --c )
1280 SCIP_CALL( SCIPgetConsCopy(sourcescip, scip, sourcedata->degcons[c], &((*targetdata)->degcons[c]),
1281 SCIPconsGetHdlr(sourcedata->degcons[c]), varmap, consmap,
1282 SCIPconsGetName(sourcedata->degcons[c]),
1283 SCIPconsIsInitial(sourcedata->degcons[c]),
1284 SCIPconsIsSeparated(sourcedata->degcons[c]),
1285 SCIPconsIsEnforced(sourcedata->degcons[c]),
1286 SCIPconsIsChecked(sourcedata->degcons[c]),
1287 SCIPconsIsPropagated(sourcedata->degcons[c]),
1288 SCIPconsIsLocal(sourcedata->degcons[c]),
1289 SCIPconsIsModifiable(sourcedata->degcons[c]),
1290 SCIPconsIsDynamic(sourcedata->degcons[c]),
1291 SCIPconsIsRemovable(sourcedata->degcons[c]),
1292 SCIPconsIsStickingAtNode(sourcedata->degcons[c]),
1293 global, &success) );
1296 SCIP_CALL( SCIPcaptureCons(scip, (*targetdata)->degcons[c]) );
1303 SCIP_CALL( SCIPallocMemoryArray(scip, &(*targetdata)->flowbcons, sourcedata->nnonterms) );
1304 for( c = sourcedata->nnonterms - 1; c >= 0; --c )
1306 SCIP_CALL( SCIPgetConsCopy(sourcescip, scip, sourcedata->flowbcons[c], &((*targetdata)->flowbcons[c]),
1307 SCIPconsGetHdlr(sourcedata->flowbcons[c]), varmap, consmap,
1308 SCIPconsGetName(sourcedata->flowbcons[c]),
1309 SCIPconsIsInitial(sourcedata->flowbcons[c]),
1310 SCIPconsIsSeparated(sourcedata->flowbcons[c]),
1311 SCIPconsIsEnforced(sourcedata->flowbcons[c]),
1312 SCIPconsIsChecked(sourcedata->flowbcons[c]),
1313 SCIPconsIsPropagated(sourcedata->flowbcons[c]),
1314 SCIPconsIsLocal(sourcedata->flowbcons[c]),
1315 SCIPconsIsModifiable(sourcedata->flowbcons[c]),
1316 SCIPconsIsDynamic(sourcedata->flowbcons[c]),
1317 SCIPconsIsRemovable(sourcedata->flowbcons[c]),
1318 SCIPconsIsStickingAtNode(sourcedata->flowbcons[c]),
1319 global, &success) );
1322 SCIP_CALL( SCIPcaptureCons(scip, (*targetdata)->flowbcons[c]) );
1328 SCIP_CALL( SCIPallocMemoryArray(scip, &(*targetdata)->prizecyclecons, sourcedata->nedges) );
1329 for( c = sourcedata->nedges - 1; c >= 0; --c )
1331 SCIP_CALL( SCIPgetConsCopy(sourcescip, scip, sourcedata->prizecyclecons[c], &((*targetdata)->prizecyclecons[c]),
1332 SCIPconsGetHdlr(sourcedata->prizecyclecons[c]), varmap, consmap,
1333 SCIPconsGetName(sourcedata->prizecyclecons[c]),
1334 SCIPconsIsInitial(sourcedata->prizecyclecons[c]),
1335 SCIPconsIsSeparated(sourcedata->prizecyclecons[c]),
1336 SCIPconsIsEnforced(sourcedata->prizecyclecons[c]),
1337 SCIPconsIsChecked(sourcedata->prizecyclecons[c]),
1338 SCIPconsIsPropagated(sourcedata->prizecyclecons[c]),
1339 SCIPconsIsLocal(sourcedata->prizecyclecons[c]),
1340 SCIPconsIsModifiable(sourcedata->prizecyclecons[c]),
1341 SCIPconsIsDynamic(sourcedata->prizecyclecons[c]),
1342 SCIPconsIsRemovable(sourcedata->prizecyclecons[c]),
1343 SCIPconsIsStickingAtNode(sourcedata->prizecyclecons[c]),
1344 global, &success) );
1347 SCIP_CALL( SCIPcaptureCons(scip, (*targetdata)->prizecyclecons[c]) );
1353 v = ((sourcedata->realnterms - 1) * sourcedata->realnterms ) / 2;
1354 SCIP_CALL( SCIPallocMemoryArray(scip, &(*targetdata)->prizesymcons, v) );
1355 for( c = v - 1; c >= 0; --c )
1357 SCIP_CALL( SCIPgetConsCopy(sourcescip, scip, sourcedata->prizesymcons[c], &((*targetdata)->prizesymcons[c]),
1358 SCIPconsGetHdlr(sourcedata->prizesymcons[c]), varmap, consmap,
1359 SCIPconsGetName(sourcedata->prizesymcons[c]),
1360 SCIPconsIsInitial(sourcedata->prizesymcons[c]),
1361 SCIPconsIsSeparated(sourcedata->prizesymcons[c]),
1362 SCIPconsIsEnforced(sourcedata->prizesymcons[c]),
1363 SCIPconsIsChecked(sourcedata->prizesymcons[c]),
1364 SCIPconsIsPropagated(sourcedata->prizesymcons[c]),
1365 SCIPconsIsLocal(sourcedata->prizesymcons[c]),
1366 SCIPconsIsModifiable(sourcedata->prizesymcons[c]),
1367 SCIPconsIsDynamic(sourcedata->prizesymcons[c]),
1368 SCIPconsIsRemovable(sourcedata->prizesymcons[c]),
1369 SCIPconsIsStickingAtNode(sourcedata->prizesymcons[c]),
1370 global, &success) );
1373 SCIP_CALL( SCIPcaptureCons(scip, (*targetdata)->prizesymcons[c]) );
1379 SCIP_CALL( SCIPgetConsCopy(sourcescip, scip, sourcedata->prizecons, &((*targetdata)->prizecons),
1380 SCIPconsGetHdlr(sourcedata->prizecons), varmap, consmap,
1381 SCIPconsGetName(sourcedata->prizecons),
1382 SCIPconsIsInitial(sourcedata->prizecons),
1383 SCIPconsIsSeparated(sourcedata->prizecons),
1384 SCIPconsIsEnforced(sourcedata->prizecons),
1385 SCIPconsIsChecked(sourcedata->prizecons),
1386 SCIPconsIsPropagated(sourcedata->prizecons),
1387 SCIPconsIsLocal(sourcedata->prizecons),
1388 SCIPconsIsModifiable(sourcedata->prizecons),
1389 SCIPconsIsDynamic(sourcedata->prizecons),
1390 SCIPconsIsRemovable(sourcedata->prizecons),
1391 SCIPconsIsStickingAtNode(sourcedata->prizecons),
1392 global, &success) );
1395 SCIP_CALL( SCIPcaptureCons(scip, (*targetdata)->prizecons) );
1404 if( sourcedata->bigt )
1406 SCIP_CALL( SCIPallocMemoryArray(scip, &(*targetdata)->edgecons, sourcedata->nedges) );
1408 for( c = sourcedata->nedges - 1; c >= 0; --c )
1410 SCIP_CALL( SCIPgetConsCopy(sourcescip, scip, sourcedata->edgecons[c], &((*targetdata)->edgecons[c]),
1411 SCIPconsGetHdlr(sourcedata->edgecons[c]), varmap, consmap,
1412 SCIPconsGetName(sourcedata->edgecons[c]),
1413 SCIPconsIsInitial(sourcedata->edgecons[c]),
1414 SCIPconsIsSeparated(sourcedata->edgecons[c]),
1415 SCIPconsIsEnforced(sourcedata->edgecons[c]),
1416 SCIPconsIsChecked(sourcedata->edgecons[c]),
1417 SCIPconsIsPropagated(sourcedata->edgecons[c]),
1418 SCIPconsIsLocal(sourcedata->edgecons[c]),
1419 SCIPconsIsModifiable(sourcedata->edgecons[c]),
1420 SCIPconsIsDynamic(sourcedata->edgecons[c]),
1421 SCIPconsIsRemovable(sourcedata->edgecons[c]),
1422 SCIPconsIsStickingAtNode(sourcedata->edgecons[c]),
1423 global, &success) );
1426 SCIP_CALL( SCIPcaptureCons(scip, (*targetdata)->edgecons[c]) );
1431 SCIP_CALL( SCIPallocMemoryArray(scip, &(*targetdata)->edgecons, sourcedata->realnterms * sourcedata->nedges) );
1432 for( c = sourcedata->realnterms * sourcedata->nedges - 1; c >= 0; --c )
1434 SCIP_CALL( SCIPgetConsCopy(sourcescip, scip, sourcedata->edgecons[c], &((*targetdata)->edgecons[c]),
1435 SCIPconsGetHdlr(sourcedata->edgecons[c]), varmap, consmap,
1436 SCIPconsGetName(sourcedata->edgecons[c]),
1437 SCIPconsIsInitial(sourcedata->edgecons[c]),
1438 SCIPconsIsSeparated(sourcedata->edgecons[c]),
1439 SCIPconsIsEnforced(sourcedata->edgecons[c]),
1440 SCIPconsIsChecked(sourcedata->edgecons[c]),
1441 SCIPconsIsPropagated(sourcedata->edgecons[c]),
1442 SCIPconsIsLocal(sourcedata->edgecons[c]),
1443 SCIPconsIsModifiable(sourcedata->edgecons[c]),
1444 SCIPconsIsDynamic(sourcedata->edgecons[c]),
1445 SCIPconsIsRemovable(sourcedata->edgecons[c]),
1446 SCIPconsIsStickingAtNode(sourcedata->edgecons[c]),
1447 global, &success) );
1450 SCIP_CALL( SCIPcaptureCons(scip, (*targetdata)->edgecons[c]) );
1457 SCIP_CALL( SCIPallocMemoryArray(scip, &(*targetdata)->pathcons, sourcedata->realnterms) );
1458 for( c = sourcedata->realnterms - 1; c >= 0; --c )
1460 SCIP_CALL( SCIPgetConsCopy(sourcescip, scip, sourcedata->pathcons[c], &((*targetdata)->pathcons[c]),
1461 SCIPconsGetHdlr(sourcedata->pathcons[c]), varmap, consmap,
1462 SCIPconsGetName(sourcedata->pathcons[c]),
1463 SCIPconsIsInitial(sourcedata->pathcons[c]),
1464 SCIPconsIsSeparated(sourcedata->pathcons[c]),
1465 SCIPconsIsEnforced(sourcedata->pathcons[c]),
1466 SCIPconsIsChecked(sourcedata->pathcons[c]),
1467 SCIPconsIsPropagated(sourcedata->pathcons[c]),
1468 SCIPconsIsLocal(sourcedata->pathcons[c]),
1469 SCIPconsIsModifiable(sourcedata->pathcons[c]),
1470 SCIPconsIsDynamic(sourcedata->pathcons[c]),
1471 SCIPconsIsRemovable(sourcedata->pathcons[c]),
1472 SCIPconsIsStickingAtNode(sourcedata->pathcons[c]),
1473 global, &success) );
1476 SCIP_CALL( SCIPcaptureCons(scip, (*targetdata)->pathcons[c]) );
1480 else if( sourcedata->mode ==
MODE_FLOW )
1482 if( sourcedata->bigt )
1484 SCIP_CALL( SCIPallocMemoryArray(scip, &(*targetdata)->flowvars, sourcedata->nedges) );
1485 SCIP_CALL( SCIPallocMemoryArray(scip, &(*targetdata)->pathcons, (sourcedata->nnodes - 1)) );
1486 for( c = sourcedata->nnodes - 2; c >= 0; --c )
1488 SCIP_CALL( SCIPgetConsCopy(sourcescip, scip, sourcedata->pathcons[c], &((*targetdata)->pathcons[c]),
1489 SCIPconsGetHdlr(sourcedata->pathcons[c]), varmap, consmap,
1490 SCIPconsGetName(sourcedata->pathcons[c]),
1491 SCIPconsIsInitial(sourcedata->pathcons[c]),
1492 SCIPconsIsSeparated(sourcedata->pathcons[c]),
1493 SCIPconsIsEnforced(sourcedata->pathcons[c]),
1494 SCIPconsIsChecked(sourcedata->pathcons[c]),
1495 SCIPconsIsPropagated(sourcedata->pathcons[c]),
1496 SCIPconsIsLocal(sourcedata->pathcons[c]),
1497 SCIPconsIsModifiable(sourcedata->pathcons[c]),
1498 SCIPconsIsDynamic(sourcedata->pathcons[c]),
1499 SCIPconsIsRemovable(sourcedata->pathcons[c]),
1500 SCIPconsIsStickingAtNode(sourcedata->pathcons[c]),
1501 global, &success) );
1504 SCIP_CALL( SCIPcaptureCons(scip, (*targetdata)->pathcons[c]) );
1507 for( v = (*targetdata)->nedges - 1; v >= 0; --v )
1509 SCIP_CALL( SCIPgetVarCopy(sourcescip, scip, sourcedata->flowvars[v], &((*targetdata)->flowvars[v]), varmap, consmap, global, &success) );
1512 SCIP_CALL( SCIPcaptureVar(scip, (*targetdata)->flowvars[v]) );
1517 SCIP_CALL( SCIPallocMemoryArray(scip, &(*targetdata)->flowvars, sourcedata->realnterms * sourcedata->nedges) );
1518 SCIP_CALL( SCIPallocMemoryArray(scip, &(*targetdata)->pathcons, sourcedata->realnterms * (sourcedata->nnodes - 1)) );
1519 for( c = sourcedata->realnterms * (sourcedata->nnodes - 1) - 1; c >= 0; --c )
1521 SCIP_CALL( SCIPgetConsCopy(sourcescip, scip, sourcedata->pathcons[c], &((*targetdata)->pathcons[c]),
1522 SCIPconsGetHdlr(sourcedata->pathcons[c]), varmap, consmap,
1523 SCIPconsGetName(sourcedata->pathcons[c]),
1524 SCIPconsIsInitial(sourcedata->pathcons[c]),
1525 SCIPconsIsSeparated(sourcedata->pathcons[c]),
1526 SCIPconsIsEnforced(sourcedata->pathcons[c]),
1527 SCIPconsIsChecked(sourcedata->pathcons[c]),
1528 SCIPconsIsPropagated(sourcedata->pathcons[c]),
1529 SCIPconsIsLocal(sourcedata->pathcons[c]),
1530 SCIPconsIsModifiable(sourcedata->pathcons[c]),
1531 SCIPconsIsDynamic(sourcedata->pathcons[c]),
1532 SCIPconsIsRemovable(sourcedata->pathcons[c]),
1533 SCIPconsIsStickingAtNode(sourcedata->pathcons[c]),
1534 global, &success) );
1537 SCIP_CALL( SCIPcaptureCons(scip, (*targetdata)->pathcons[c]) );
1540 for( v = sourcedata->nedges * sourcedata->realnterms - 1; v >= 0; --v )
1542 SCIP_CALL( SCIPgetVarCopy(sourcescip, scip, sourcedata->flowvars[v], &((*targetdata)->flowvars[v]), varmap, consmap, global, &success) );
1545 SCIP_CALL( SCIPcaptureVar(scip, (*targetdata)->flowvars[v]) );
1552 SCIP_CALL( SCIPallocMemoryArray(scip, &(*targetdata)->realterms, sourcedata->realnterms) );
1553 for( i = 0; i < sourcedata->realnterms; ++i )
1555 (*targetdata)->realterms[i] = sourcedata->realterms[i];
1560 (*targetdata)->edgevars = NULL;
1561 (*targetdata)->xval = NULL;
1562 (*targetdata)->realterms = NULL;
1563 (*targetdata)->edgecons = NULL;
1564 (*targetdata)->pathcons = NULL;
1565 (*targetdata)->flowvars = NULL;
1568 *result = SCIP_SUCCESS;
1578 SCIPdebugMessage(
"probdelorigStp \n");
1580 SCIPdebugMessage(
"free original problem data\n");
1582 if( (*probdata)->graph != NULL )
1584 if ( (*probdata)->mode ==
MODE_CUT )
1603 SCIP_Real timelimit;
1606 SCIPdebugMessage(
"probtransStp \n");
1608 SCIP_CALL( SCIPgetBoolParam(scip,
"stp/countpresoltime", &update) );
1613 SCIP_CALL( SCIPgetRealParam(scip,
"limits/time", &timelimit) );
1614 timelimit -= SCIPgetReadingTime(scip);
1615 timelimit = MAX(0.0,timelimit);
1616 SCIP_CALL( SCIPsetRealParam(scip,
"limits/time", timelimit) );
1620 SCIP_CALL(
probdataCreate(scip, targetdata, sourcedata->graph) );
1622 (*targetdata)->nlayers = sourcedata->nlayers;
1623 (*targetdata)->nedges = sourcedata->nedges;
1624 (*targetdata)->nnodes = sourcedata->nnodes;
1625 (*targetdata)->nterms = sourcedata->nterms;
1626 (*targetdata)->realnterms = sourcedata->realnterms;
1627 (*targetdata)->nnonterms = sourcedata->nnonterms;
1628 (*targetdata)->emitgraph = sourcedata->emitgraph;
1629 (*targetdata)->usesymcons = sourcedata->usesymcons;
1630 (*targetdata)->usecyclecons = sourcedata->usecyclecons;
1631 (*targetdata)->nvars = sourcedata->nvars;
1632 (*targetdata)->mode = sourcedata->mode;
1633 (*targetdata)->offset = sourcedata->offset;
1634 (*targetdata)->minelims = sourcedata->minelims;
1635 (*targetdata)->bigt = sourcedata->bigt;
1636 (*targetdata)->logfile = sourcedata->logfile;
1637 (*targetdata)->origlogfile = &(sourcedata->logfile);
1638 (*targetdata)->intlogfile = sourcedata->intlogfile;
1639 (*targetdata)->origintlogfile = &(sourcedata->intlogfile);
1641 if( sourcedata->offsetvar != NULL )
1643 SCIP_CALL( SCIPtransformVar(scip, sourcedata->offsetvar, &(*targetdata)->offsetvar) );
1646 (*targetdata)->offsetvar = NULL;
1648 if( sourcedata->nedges > 0 )
1653 SCIP_CALL( SCIPallocMemoryArray(scip, &(*targetdata)->xval, sourcedata->nvars) );
1654 SCIP_CALL( SCIPallocMemoryArray(scip, &(*targetdata)->edgevars, sourcedata->nvars) );
1655 SCIP_CALL( SCIPtransformVars(scip, sourcedata->nvars, sourcedata->edgevars, (*targetdata)->edgevars) );
1660 (*targetdata)->edgecons = NULL;
1661 (*targetdata)->pathcons = NULL;
1664 SCIP_CALL( SCIPallocMemoryArray(scip, &(*targetdata)->degcons, sourcedata->nnodes) );
1665 SCIP_CALL( SCIPtransformConss(scip, sourcedata->nnodes, sourcedata->degcons, (*targetdata)->degcons) );
1672 SCIP_CALL( SCIPallocMemoryArray(scip, &(*targetdata)->flowbcons, sourcedata->nnonterms) );
1673 SCIP_CALL( SCIPtransformConss(scip, sourcedata->nnonterms, sourcedata->flowbcons, (*targetdata)->flowbcons) );
1678 SCIP_CALL( SCIPallocMemoryArray(scip, &(*targetdata)->prizecyclecons, sourcedata->nedges) );
1679 SCIP_CALL( SCIPtransformConss(scip, sourcedata->nedges, sourcedata->prizecyclecons, (*targetdata)->prizecyclecons) );
1684 if( sourcedata->usesymcons )
1686 i = ((sourcedata->realnterms - 1) * (sourcedata->realnterms)) / 2;
1687 SCIP_CALL( SCIPallocMemoryArray(scip, &(*targetdata)->prizesymcons, i) );
1688 SCIP_CALL( SCIPtransformConss(scip, i, sourcedata->prizesymcons, (*targetdata)->prizesymcons) );
1690 SCIP_CALL( SCIPtransformCons(scip, sourcedata->prizecons, &(*targetdata)->prizecons) );
1700 if( sourcedata->bigt )
1702 SCIP_CALL( SCIPallocMemoryArray(scip, &(*targetdata)->edgecons, sourcedata->nedges) );
1703 SCIP_CALL( SCIPtransformConss(scip, sourcedata->nedges, sourcedata->edgecons, (*targetdata)->edgecons) );
1707 SCIP_CALL( SCIPallocMemoryArray(scip, &(*targetdata)->edgecons, sourcedata->realnterms * sourcedata->nedges) );
1708 SCIP_CALL( SCIPtransformConss(scip, sourcedata->realnterms * sourcedata->nedges, sourcedata->edgecons, (*targetdata)->edgecons) );
1714 SCIP_CALL( SCIPallocMemoryArray(scip, &(*targetdata)->pathcons, sourcedata->realnterms) );
1715 SCIP_CALL( SCIPtransformConss(scip, sourcedata->realnterms, sourcedata->pathcons, (*targetdata)->pathcons) );
1718 else if( sourcedata->mode ==
MODE_FLOW )
1720 if( sourcedata->bigt )
1722 SCIP_CALL( SCIPallocMemoryArray(scip, &(*targetdata)->flowvars, sourcedata->nedges) );
1723 SCIP_CALL( SCIPallocMemoryArray(scip, &(*targetdata)->pathcons, (sourcedata->nnodes - 1)) );
1724 SCIP_CALL( SCIPtransformConss(scip, (sourcedata->nnodes - 1), sourcedata->pathcons, (*targetdata)->pathcons) );
1725 SCIP_CALL( SCIPtransformVars(scip, sourcedata->nedges, sourcedata->flowvars, (*targetdata)->flowvars) );
1729 SCIP_CALL( SCIPallocMemoryArray(scip, &(*targetdata)->flowvars, sourcedata->realnterms * sourcedata->nedges) );
1730 SCIP_CALL( SCIPallocMemoryArray(scip, &(*targetdata)->pathcons, sourcedata->realnterms * (sourcedata->nnodes - 1)) );
1731 SCIP_CALL( SCIPtransformConss(scip, sourcedata->realnterms * (sourcedata->nnodes - 1), sourcedata->pathcons, (*targetdata)->pathcons) );
1732 SCIP_CALL( SCIPtransformVars(scip, sourcedata->nedges * sourcedata->realnterms, sourcedata->flowvars, (*targetdata)->flowvars) );
1738 SCIP_CALL( SCIPallocMemoryArray(scip, &(*targetdata)->realterms, sourcedata->realnterms) );
1739 for( i = 0; i < sourcedata->realnterms; ++i )
1741 (*targetdata)->realterms[i] = sourcedata->realterms[i];
1746 (*targetdata)->edgevars = NULL;
1747 (*targetdata)->xval = NULL;
1748 (*targetdata)->realterms = NULL;
1749 (*targetdata)->edgecons = NULL;
1750 (*targetdata)->pathcons = NULL;
1751 (*targetdata)->flowvars = NULL;
1762 assert(scip != NULL);
1763 assert(probdata != NULL);
1765 if( probdata->logfile != NULL )
1768 SCIP_Real factor = 1.0;
1791 if( SCIPgetNSols(scip) > 0 )
1800 success = fclose(probdata->logfile);
1803 SCIPerrorMessage(
"An error occurred while closing file <%s>\n", probdata->logfile);
1804 return SCIP_FILECREATEERROR;
1807 probdata->logfile = NULL;
1808 *(probdata->origlogfile) = NULL;
1811 if( probdata->intlogfile != NULL )
1813 int success = fclose(probdata->intlogfile);
1816 SCIPerrorMessage(
"An error occurred while closing file <%s>\n", probdata->intlogfile);
1817 return SCIP_FILECREATEERROR;
1820 probdata->intlogfile = NULL;
1821 *(probdata->origintlogfile) = NULL;
1831 SCIPdebugMessage(
"free transformed problem data\n");
1849 const char* filename
1852 SCIP_PROBDATA* probdata;
1855 SCIP_Real oldtimelimit;
1856 SCIP_Real presoltimelimit;
1873 char* intlogfilename;
1875 char tmpfilename[SCIP_MAXSTRLEN];
1878 char presolvefilename[SCIP_MAXSTRLEN];
1881 assert(scip != NULL);
1883 presolinfo.
fixed = 0;
1886 SCIP_CALL(
graph_load(scip, &graph, filename, &presolinfo) );
1888 SCIPdebugMessage(
"load type :: %d \n\n", graph->
stp_type);
1889 SCIPdebugMessage(
"fixed: %f \n\n", presolinfo.
fixed );
1899 SCIP_CALL( SCIPgetCharParam(scip,
"stp/mode", &mode) );
1900 SCIP_CALL( SCIPgetIntParam(scip,
"stp/compcentral", &compcentral) );
1901 SCIP_CALL( SCIPgetIntParam(scip,
"stp/reduction", &reduction) );
1902 SCIP_CALL( SCIPgetIntParam(scip,
"stp/usesymcons", &(symcons)) );
1903 SCIP_CALL( SCIPgetIntParam(scip,
"stp/usecyclecons", &(cyclecons)) );
1904 SCIP_CALL( SCIPgetIntParam(scip,
"stp/minelims", &(probdata->minelims)) );
1905 SCIP_CALL( SCIPgetBoolParam(scip,
"stp/emitgraph", &(probdata->emitgraph)) );
1906 SCIP_CALL( SCIPgetBoolParam(scip,
"stp/bigt", &(probdata->bigt)) );
1907 SCIP_CALL( SCIPgetBoolParam(scip,
"stp/printGraph", &print) );
1908 SCIP_CALL( SCIPgetStringParam(scip,
"stp/logfile", &logfilename) );
1909 SCIP_CALL( SCIPgetStringParam(scip,
"stp/intlogfile", &intlogfilename) );
1912 logfilename =
"RPC.sol";
1915 if( logfilename != NULL && logfilename[0] !=
'\0' )
1917 probdata->logfile = fopen(logfilename,
"w");
1919 if( probdata->logfile == NULL )
1921 SCIPerrorMessage(
"cannot create file <%s> for writing\n", logfilename);
1922 SCIPprintSysError(logfilename);
1923 return SCIP_FILECREATEERROR;
1927 if( intlogfilename != NULL && intlogfilename[0] !=
'\0' )
1929 probdata->intlogfile = fopen(intlogfilename,
"w");
1931 if( probdata->intlogfile == NULL )
1933 SCIPerrorMessage(
"cannot create file <%s> for writing\n", intlogfilename);
1934 SCIPprintSysError(intlogfilename);
1935 return SCIP_FILECREATEERROR;
1940 (void) SCIPsnprintf(tmpfilename, SCIP_MAXSTRLEN,
"%s", filename);
1942 SCIPsplitFilename(tmpfilename, NULL, &probname, NULL, NULL);
1945 SCIP_CALL( SCIPcreateProbBasic(scip, probname) );
1946 SCIP_CALL( SCIPsetProbDelorig(scip, probdelorigStp) );
1947 SCIP_CALL( SCIPsetProbTrans(scip, probtransStp) );
1948 SCIP_CALL( SCIPsetProbDeltrans(scip, probdeltransStp) );
1949 SCIP_CALL( SCIPsetProbExitsol(scip, probexitsolStp) );
1950 SCIP_CALL( SCIPsetProbCopy(scip, probcopyStp) );
1953 SCIP_CALL( SCIPsetObjsense(scip, SCIP_OBJSENSE_MINIMIZE) );
1956 SCIP_CALL( SCIPsetProbData(scip, probdata) );
1959 SCIP_CALL( SCIPsetIntParam(scip,
"heuristics/rens/freq", -1) );
1960 SCIP_CALL( SCIPsetIntParam(scip,
"heuristics/rins/freq", -1) );
1961 SCIP_CALL( SCIPsetIntParam(scip,
"heuristics/dins/freq", -1) );
1962 SCIP_CALL( SCIPsetIntParam(scip,
"heuristics/crossover/freq", -1) );
1963 SCIP_CALL( SCIPsetIntParam(scip,
"heuristics/mutation/freq", -1) );
1964 SCIP_CALL( SCIPsetIntParam(scip,
"heuristics/clique/freq", -1) );
1965 SCIP_CALL( SCIPsetIntParam(scip,
"heuristics/vbounds/freq", -1) );
1966 SCIP_CALL( SCIPsetIntParam(scip,
"heuristics/bound/freq", -1) );
1967 SCIP_CALL( SCIPsetIntParam(scip,
"heuristics/zeroobj/freq", -1) );
1975 strcpy(probtype,
"SPG");
1978 strcpy(probtype,
"SAP");
1982 strcpy(probtype,
"PCSPG");
1986 strcpy(probtype,
"RPCST");
1990 strcpy(probtype,
"NWSPG");
1994 strcpy(probtype,
"DCST");
1998 strcpy(probtype,
"RSMT");
2002 strcpy(probtype,
"OARSMT");
2006 strcpy(probtype,
"MWCS");
2010 strcpy(probtype,
"HCDST");
2014 strcpy(probtype,
"UNKNOWN");
2033 else if( mode ==
'p' )
2040 assert(mode ==
'c');
2044 assert(graph != NULL );
2056 SCIP_CALL( SCIPsetIntParam(scip,
"separating/gomory/freq", -1) );
2057 SCIP_CALL( SCIPsetIntParam(scip,
"separating/flowcover/freq", -1) );
2058 SCIP_CALL( SCIPsetIntParam(scip,
"separating/cmir/freq", -1) );
2059 SCIP_CALL( SCIPsetIntParam(scip,
"separating/strongcg/freq", -1) );
2060 SCIP_CALL( SCIPsetIntParam(scip,
"heuristics/oneopt/freq", -1) );
2064 SCIP_CALL( SCIPsetIntParam(scip,
"heuristics/rounding/freq", -1) );
2065 SCIP_CALL( SCIPsetIntParam(scip,
"heuristics/trivial/freq", -1) );
2069 SCIP_CALL( SCIPgetRealParam(scip,
"limits/time", &oldtimelimit) );
2070 SCIP_CALL( SCIPgetRealParam(scip,
"stp/pretimelimit", &presoltimelimit) );
2072 if( presoltimelimit > -0.5 )
2074 SCIP_CALL( SCIPsetRealParam(scip,
"limits/time", presoltimelimit) );
2078 SCIP_CALL(
reduce(scip, &graph, &offset, reduction, probdata->minelims) );
2081 graph = packedgraph;
2082 probdata->graph =
graph;
2084 SCIP_CALL( SCIPsetRealParam(scip,
"limits/time", oldtimelimit) );
2087 probdata->usecyclecons =
TRUE;
2089 probdata->usecyclecons =
TRUE;
2091 probdata->usecyclecons =
FALSE;
2094 probdata->usesymcons =
TRUE;
2096 probdata->usesymcons =
TRUE;
2098 probdata->usesymcons =
FALSE;
2100 if( probdata->usesymcons )
2101 SCIPdebugMessage(
"USE SYM CONS: %d \n", (
int) (0.5 * (graph->
terms - 1) * graph->
terms));
2103 SCIPdebugMessage(
"NO SYM CONS: \n");
2107 fptr=fopen(
"rededges.txt",
"a");
2112 fprintf(fptr,
"%d\n",((graph->
orgedges - graph->
edges) / 2));
2115 fptr=fopen(
"rednodes.txt",
"a");
2139 nedges = graph->
edges;
2140 nnodes = graph->
knots;
2141 probdata->nvars =
nedges;
2142 probdata->nnodes =
nnodes;
2143 probdata->nedges =
nedges;
2144 probdata->nterms = graph->
terms;
2145 probdata->nlayers = graph->
layers;
2150 realnterms = graph->
terms - 1;
2154 SCIP_CALL( SCIPallocMemoryArray(scip, &probdata->realterms, realnterms) );
2156 for( k = 0; k <
nnodes; ++k )
2158 if( graph->
term[k] == 0 && k != graph->
source[0] )
2160 probdata->realterms[t] = k;
2161 SCIPdebugMessage(
"realterms[%d] = %d \n ", t, probdata->realterms[t]);
2170 SCIP_CALL( SCIPaddCons(scip, cons) );
2171 SCIP_CALL( SCIPreleaseCons(scip, &cons) );
2182 if( pc || rpc || mw )
2185 SCIP_CALL( createFlowBalanceConstraints(scip, probdata) );
2197 probdata->pathcons = NULL;
2198 probdata->edgecons = NULL;
2199 probdata->nlayers = 0;
2200 probdata->nnodes = 0;
2201 probdata->nedges = 0;
2202 probdata->nterms = 0;
2203 probdata->nnonterms = 0;
2204 probdata->realnterms = 0;
2205 probdata->nedges = 0;
2206 probdata->nvars = 0;
2207 probdata->realterms = NULL;
2208 probdata->xval = NULL;
2218 (void)SCIPsnprintf(presolvefilename, SCIP_MAXSTRLEN,
"presol/%s-presolve.stp", probname);
2219 SCIP_CALL( SCIPwriteOrigProblem(scip, presolvefilename, NULL,
FALSE) );
2222 if( graph != NULL && probdata->mode ==
MODE_CUT )
2239 SCIP_CALL(
SCIPdualAscentStp(scip, graph, NULL, &lpobjval,
TRUE, NULL, NULL, NULL, graph->
source[0], 1, NULL, NULL) );
2247 SCIP_PROBDATA* probdata,
2251 assert(probdata != NULL);
2253 probdata->graph =
graph;
2259 SCIP_PROBDATA* probdata
2262 assert(probdata != NULL);
2264 return probdata->graph;
2270 SCIP_PROBDATA* probdata,
2274 assert(probdata != NULL);
2276 probdata->offset =
offset;
2285 SCIP_PROBDATA* probdata;
2287 assert(scip != NULL);
2289 probdata = SCIPgetProbData(scip);
2290 assert(probdata != NULL);
2292 return probdata->nvars;
2300 SCIP_PROBDATA* probdata;
2302 assert(scip != NULL);
2304 probdata = SCIPgetProbData(scip);
2305 assert(probdata != NULL);
2307 return probdata->edgevars;
2315 SCIP_PROBDATA* probdata;
2317 assert(scip != NULL);
2319 probdata = SCIPgetProbData(scip);
2320 assert(probdata != NULL);
2322 return probdata->nlayers;
2330 SCIP_PROBDATA* probdata;
2332 assert(scip != NULL);
2334 probdata = SCIPgetProbData(scip);
2335 assert(probdata != NULL);
2337 return probdata->nedges;
2345 SCIP_PROBDATA* probdata;
2347 assert(scip != NULL);
2349 probdata = SCIPgetProbData(scip);
2350 assert(probdata != NULL);
2352 return probdata->nterms;
2360 SCIP_PROBDATA* probdata;
2362 assert(scip != NULL);
2364 probdata = SCIPgetProbData(scip);
2365 assert(probdata != NULL);
2367 return probdata->realnterms;
2375 SCIP_PROBDATA* probdata;
2378 assert(scip != NULL);
2380 probdata = SCIPgetProbData(scip);
2381 assert(probdata != NULL);
2383 graph = probdata->graph;
2384 assert(graph != NULL);
2395 SCIP_PROBDATA* probdata;
2397 assert(scip != NULL);
2399 probdata = SCIPgetProbData(scip);
2400 assert(probdata != NULL);
2402 return probdata->offset;
2412 SCIP_PROBDATA* probdata;
2414 assert(scip != NULL);
2416 probdata = SCIPgetProbData(scip);
2417 assert(probdata != NULL);
2419 return probdata->edgevars[idx];
2429 SCIP_PROBDATA* probdata;
2433 assert(scip != NULL);
2435 probdata = SCIPgetProbData(scip);
2436 assert(probdata != NULL);
2437 vals = probdata->xval;
2439 nedges = probdata->nedges;
2440 assert(nedges >= 0);
2442 SCIP_CALL_ABORT( SCIPgetSolVals(scip, sol, nedges, probdata->edgevars, vals) );
2444 for( e = 0; e <
nedges; e++ )
2445 vals[e] = fmax(0.0, fmin(vals[e], 1.0));
2456 SCIP_PROBDATA* probdata;
2458 assert(scip != NULL);
2459 probdata = SCIPgetProbData(scip);
2460 assert(probdata != NULL);
2462 return probdata->edgecons;
2470 SCIP_PROBDATA* probdata;
2472 assert(scip != NULL);
2473 probdata = SCIPgetProbData(scip);
2474 assert(probdata != NULL);
2476 return probdata->pathcons;
2485 SCIP_PROBDATA* probdata;
2487 assert(scip != NULL);
2489 probdata = SCIPgetProbData(scip);
2490 assert(probdata != NULL);
2492 return probdata->realterms;
2500 SCIP_PROBDATA* probdata;
2502 assert(scip != NULL);
2504 probdata = SCIPgetProbData(scip);
2505 assert(probdata != NULL);
2507 return probdata->edgevars;
2515 SCIP_PROBDATA* probdata;
2517 assert(scip != NULL);
2519 probdata = SCIPgetProbData(scip);
2520 assert(probdata != NULL);
2522 return probdata->bigt;
2528 const char* filename,
2533 SCIP_PROBDATA* probdata;
2535 SCIP_Bool* edgemark;
2538 assert(scip != NULL);
2539 probdata = SCIPgetProbData(scip);
2540 assert(probdata != NULL);
2549 edgevars = probdata->edgevars;
2550 SCIP_CALL( SCIPallocBufferArray(scip, &edgemark, probdata->nedges / 2) );
2553 for( e = 0; e < probdata->graph->edges; e += 2 )
2554 if( !SCIPisZero(scip, SCIPgetSolVal(scip, sol, edgevars[e])) || !SCIPisZero(scip, SCIPgetSolVal(scip, sol, edgevars[e + 1])) )
2555 edgemark[e / 2] =
TRUE;
2557 edgemark[e / 2] =
FALSE;
2562 SCIPfreeBufferArray(scip, &edgemark);
2574 SCIP_PROBDATA* probdata;
2575 probdata = SCIPgetProbData(scip);
2577 if( probdata->intlogfile != NULL )
2598 SCIP_PROBDATA* probdata;
2608 assert(scip != NULL);
2610 probdata = SCIPgetProbData(scip);
2612 assert(probdata != NULL);
2614 edgevars = probdata->edgevars;
2616 graph = probdata->graph;
2618 assert(graph != NULL);
2620 sol = SCIPgetBestSol(scip);
2627 assert(norgedges >= 0);
2628 assert(norgnodes >= 1);
2630 SCIP_CALL( SCIPallocBufferArray(scip, &orgedges, norgedges) );
2631 SCIP_CALL( SCIPallocBufferArray(scip, &orgnodes, norgnodes) );
2633 for( e = 0; e < norgedges; e++ )
2634 orgedges[e] =
FALSE;
2635 for( k = 0; k < norgnodes; k++ )
2636 orgnodes[k] =
FALSE;
2643 while( curr != NULL )
2663 for( e = 0; e < graph->
edges; e++ )
2665 if( !SCIPisZero(scip, SCIPgetSolVal(scip, sol, edgevars[e])) )
2668 curr = ancestors[e];
2669 while( curr != NULL )
2693 norgnodes -= graph->
terms;
2694 nsolnodes -= graph->
terms;
2695 nsoledges -= graph->
terms;
2696 assert(nsolnodes >= 0);
2697 assert(nsoledges >= 1);
2702 for( k = 0; k < norgnodes; k++ )
2703 if( orgnodes[k] ==
TRUE )
2704 SCIPinfoMessage(scip, file,
"V %d\n", k + 1);
2710 for( e = 0; e < norgedges; e++ )
2711 if( orgedges[e] ==
TRUE )
2712 SCIPinfoMessage(scip, file,
"E %d %d\n", graph->
orgtail[e] + 1, graph->
orghead[e] + 1);
2716 for( e = 0; e < norgedges; e += 2 )
2720 if( orgedges[e] ==
TRUE || orgedges[e + 1] ==
TRUE )
2721 SCIPinfoMessage(scip, file,
"E %d %d\n", graph->
orgtail[e] + 1, graph->
orghead[e] + 1);
2737 assert(coords != NULL);
2741 assert(grid_dim > 1);
2742 assert(grid_dim < 256);
2743 SCIP_CALL( SCIPallocBufferArray(scip, &nodenumber, norgnodes) );
2744 strcpy(strdim,
"P");
2745 for( i = 1; i < grid_dim; i++ )
2746 strcat(strdim,
"P");
2748 assert(ncoords != NULL);
2751 for( e = 0; e < norgedges; e++ )
2753 if( !SCIPisZero(scip, SCIPgetSolVal(scip, sol, edgevars[e])) )
2756 assert(orgedges[e] ==
FALSE);
2774 for( k = 0; k < norgnodes; k++ )
2776 if( orgnodes[k] ==
TRUE )
2778 nodenumber[k] = nodecount++;
2781 for( i = 0; i < grid_dim; i++ )
2788 assert(nodecount == nsolnodes);
2789 for( e = 0; e < norgedges; e += 2 )
2791 if( orgedges[e] ==
TRUE || orgedges[e + 1] ==
TRUE )
2792 SCIPinfoMessage(scip, file,
"E %d %d\n", nodenumber[graph->
orgtail[e]] + 1, nodenumber[graph->
orghead[e]] + 1);
2794 SCIPfreeBufferArray(scip, &nodenumber);
2803 for( e = 0; e <= graph->
edges; e++ )
2805 if( e == graph->
edges || !SCIPisZero(scip, SCIPgetSolVal(scip, sol, edgevars[e])) )
2808 if( e < graph->edges )
2809 curr = ancestors[e];
2812 while( curr != NULL )
2816 if( !SCIPisZero(scip, SCIPgetSolVal(scip, sol, edgevars[
flipedge(e)])) )
2856 orgnodes[root] =
TRUE;
2857 assert(nsolnodes == 0);
2865 if( orgnodes[k] ==
TRUE )
2868 while( curr != NULL )
2893 for( k = 0; k < norgnodes; k++ )
2894 if( orgnodes[k] ==
TRUE )
2895 SCIPinfoMessage(scip, file,
"V %d\n", k + 1);
2898 for( e = 0; e < norgedges; e += 2 )
2899 if( orgedges[e] ==
TRUE || orgedges[e + 1] ==
TRUE )
2900 SCIPinfoMessage(scip, file,
"E %d %d\n", graph->
orgtail[e] + 1, graph->
orghead[e] + 1);
2903 SCIPfreeBufferArray(scip, &orgnodes);
2904 SCIPfreeBufferArray(scip, &orgedges);
2913 const char* formatstr,
2917 SCIP_PROBDATA* probdata;
2920 assert(scip != NULL);
2922 probdata = SCIPgetProbData(scip);
2923 assert(probdata != NULL);
2925 if( probdata->logfile == NULL )
2928 va_start(ap, formatstr);
2929 SCIPmessageVFPrintInfo(SCIPgetMessagehdlr(scip), probdata->logfile, formatstr, ap);
2942 SCIP_PROBDATA* probdata;
2946 assert(scip != NULL);
2948 probdata = SCIPgetProbData(scip);
2949 edgevars = probdata->edgevars;
2951 graph = probdata->graph;
2952 assert(graph != NULL);
2953 assert(edgevars != NULL);
2956 SCIP_CALL( SCIPcreateSol(scip, &sol, heur) );
2961 SCIP_Real* edgecost;
2962 SCIP_Real* flowvals;
2964 SCIP_VAR** pathvars;
2965 SCIP_VAR* var = NULL;
2966 char varname[SCIP_MAXSTRLEN];
2969 int nedges = probdata->nedges;
2976 SCIP_CALL( SCIPallocMemoryArray(scip, &flowvals, nedges * (probdata->bigt ? 1 : realnterms)) );
2977 BMSclearMemoryArray(flowvals, nedges * (probdata->bigt ? 1 : realnterms));
2980 SCIP_CALL( SCIPallocMemoryArray(scip, &edgecost, nedges) );
2981 SCIP_CALL( SCIPallocMemoryArray(scip, &path, graph->
knots) );
2991 SCIP_CALL( SCIPallocMemoryArray(scip, &pathvars, realnterms) );
2995 for( e = 0; e <
nedges; e++ )
2997 if( SCIPisEQ(scip, nval[e], 1.0) )
3000 edgecost[e] = SCIPinfinity(scip);
3003 for( e = 0; e < graph->
knots; e++ )
3013 (void)SCIPsnprintf(varname, SCIP_MAXSTRLEN,
"PathVar%d_X", t);
3015 SCIP_CALL( SCIPcreateVarBasic(scip, &var, varname, 0.0, SCIPinfinity(scip), 0.0, SCIP_VARTYPE_CONTINUOUS) );
3016 SCIP_CALL( SCIPaddVar(scip, var) );
3017 SCIP_CALL( SCIPaddCoefLinear(scip, probdata->pathcons[t], var, 1.0) );
3018 SCIP_CALL( SCIPsetSolVal(scip, sol, var, 1.0) );
3019 assert(var != NULL);
3020 assert(pathvars != NULL);
3023 tail = probdata->realterms[t];
3026 while( tail != graph->
source[0] )
3028 if( !probdata->bigt )
3033 assert(var != NULL);
3034 SCIP_CALL( SCIPaddCoefLinear(scip, probdata->edgecons[t * nedges + path[tail].
edge], var, 1.0) );
3039 flowvals[t * nedges + path[tail].
edge] = 1.0;
3046 assert(var != NULL);
3047 SCIP_CALL( SCIPaddCoefLinear(scip, probdata->edgecons[path[tail].
edge], var, 1.0) );
3052 flowvals[path[tail].
edge] += 1.0;
3055 tail = graph->
tail[path[tail].
edge];
3059 assert(var != NULL);
3060 SCIP_CALL( SCIPreleaseVar(scip, &var) );
3065 SCIP_CALL( SCIPsetSolVals(scip, sol, probdata->nvars, edgevars, nval) );
3068 SCIP_CALL( SCIPsetSolVals(scip, sol, nedges * (probdata->bigt ? 1 : realnterms) , probdata->flowvars, flowvals) );
3075 SCIPfreeMemoryArrayNull(scip, &flowvals);
3076 SCIPfreeMemoryArrayNull(scip, &edgecost);
3077 SCIPfreeMemoryArrayNull(scip, &path);
3078 SCIPfreeMemoryArrayNull(scip, &pathvars);
3085 int nvars = probdata->nvars;
3088 for( e = 0; e <
nvars; e++ )
3090 if( SCIPisGT(scip, nval[e], SCIPvarGetUbGlobal(edgevars[e])) || SCIPisGT(scip, SCIPvarGetLbGlobal(edgevars[e]), nval[e]) )
3093 SCIP_CALL( SCIPfreeSol(scip, &sol) );
3103 for( k = 0; k < graph->
knots; ++k )
3109 int edge1 = graph->
inpbeg[k];
3110 int edge2 = graph->
ieat[edge1];
3113 if( !SCIPisZero(scip, graph->
cost[edge2]) )
3119 assert(SCIPisZero(scip, graph->
cost[edge2]));
3121 if( nval[edge2] > 0.5 )
3123 assert(nval[edge1] < 0.5);
3126 assert(nval[edge1] > 0.5);
3127 assert(nval[edge2] < 0.5);
3129 origterm = graph->
tail[edge2];
3145 SCIP_CALL( SCIPsetSolVals(scip, sol, nvars, edgevars, nval) );
3147 if( probdata->offsetvar != NULL && SCIPvarIsActive(probdata->offsetvar) )
3149 SCIP_CALL( SCIPsetSolVal(scip, sol, probdata->offsetvar, 1.0) );
3154 SCIPdebugMessage(
"checked sol: feasible=%u\n", feasible);
3159 SCIP_CALL( SCIPcheckSolOrig(scip, sol, &feasible,
TRUE,
TRUE) );
3160 SCIPdebugMessage(
"checked sol org: feasible=%u\n", feasible);
3165 SCIP_VAR** origvars;
3170 SCIP_CALL( SCIPcreateOrigSol(scip, &newsol, SCIPsolGetHeur(sol)) );
3171 origvars = SCIPgetOrigVars(scip);
3172 norigvars = SCIPgetNOrigVars(scip);
3174 for( v = 0; v < norigvars; ++v )
3177 SCIP_CALL( SCIPsetSolVal(scip, newsol, var, SCIPgetSolVal(scip, sol, var)) );
3180 SCIP_CALL( SCIPfreeSol(scip, &sol) );
3193 SCIP_CALL( SCIPaddSolFree(scip, &sol, success) );
3197 SCIP_CALL( SCIPfreeSol(scip, &sol) );
3210 const char* filename,
3214 char label[SCIP_MAXSTRLEN];
3220 assert(graph != NULL);
3221 file = fopen((filename != NULL) ? filename :
"graphX.gml",
"w");
3223 for( e = 0; e < graph->
edges; e += 2 )
3225 assert(graph->
tail[e] == graph->
head[e + 1]);
3226 assert(graph->
tail[e + 1] == graph->
head[e]);
3230 SCIPgmlWriteOpening(file,
FALSE);
3235 for( n = 0; n < graph->
knots; ++n )
3237 if( n == graph->
source[0] )
3239 (void)SCIPsnprintf(label, SCIP_MAXSTRLEN,
"(%d) Root", n);
3240 SCIPgmlWriteNode(file, (
unsigned int)n, label,
"rectangle",
"#666666", NULL);
3243 else if( graph->
term[n] == 0 )
3245 (void)SCIPsnprintf(label, SCIP_MAXSTRLEN,
"(%d) Terminal %d", n, e + 1);
3246 SCIPgmlWriteNode(file, (
unsigned int)n, label,
"circle",
"#ff0000", NULL);
3251 (void)SCIPsnprintf(label, SCIP_MAXSTRLEN,
"(%d) Node %d", n, n + 1 - e - m);
3252 SCIPgmlWriteNode(file, (
unsigned int)n, label,
"circle",
"#336699", NULL);
3257 for( e = 0; e < graph->
edges; e += 2 )
3259 (void)SCIPsnprintf(label, SCIP_MAXSTRLEN,
"%8.2f", graph->
cost[e]);
3260 if( edgemark != NULL && edgemark[e / 2] ==
TRUE )
3261 SCIPgmlWriteEdge(file, (
unsigned int)graph->
tail[e], (
unsigned int)graph->
head[e], label,
"#ff0000");
3266 for( e = 0; e < graph->
edges; e += 2 )
3272 (void)SCIPsnprintf(label, SCIP_MAXSTRLEN,
"%8.2f", graph->
cost[e]);
3273 if( edgemark != NULL && edgemark[e / 2] ==
TRUE )
3274 SCIPgmlWriteEdge(file, (
unsigned int)graph->
tail[e], (
unsigned int)graph->
head[e], label,
"#ff0000");
3276 SCIPgmlWriteEdge(file, (
unsigned int)graph->
tail[e], (
unsigned int)graph->
head[e], label, NULL);
3281 SCIPgmlWriteClosing(file);
3291 SCIP_PROBDATA* probdata;
3293 assert(scip != NULL);
3295 probdata = SCIPgetProbData(scip);
3296 assert(probdata != NULL);
3298 return probdata->stp_type;
3306 SCIP_PROBDATA* probdata;
3308 assert(scip != NULL);
3310 probdata = SCIPgetProbData(scip);
3311 assert(probdata != NULL);
3313 if( probdata->logfile != NULL )
3316 SCIP_Real factor = 1.0;
3339 if( SCIPgetNSols(scip) > 0 )
3348 success = fclose(probdata->logfile);
3351 SCIPerrorMessage(
"An error occurred while closing file <%s>\n", probdata->logfile);
3352 return SCIP_FILECREATEERROR;
3355 probdata->logfile = NULL;
3368 SCIP_PROBDATA* probdata;
3370 assert(scip != NULL);
3372 probdata = SCIPgetProbData(scip);
3373 probdata->ug =
TRUE;
3374 probdata->ugDual = dual;
3383 SCIP_PROBDATA* probdata;
3385 assert(scip != NULL);
3387 probdata = SCIPgetProbData(scip);
SCIP_RETCODE graph_path_init(SCIP *, GRAPH *)
static SCIP_RETCODE createVariables(SCIP *scip, SCIP_PROBDATA *probdata, SCIP_Real offset)
SCIP_RETCODE SCIPdualAscentStp(SCIP *scip, GRAPH *g, SCIP_Real *redcost, SCIP_Real *objval, SCIP_Bool addcuts, GNODE **gnodearrterms, int *edgearrint, int *nodearrint, int root, int nruns, char *edgearrchar, char *nodearrchar)
static SCIP_RETCODE central_terminal(SCIP *scip, GRAPH *g, int *central_term, int centertype)
int SCIPprobdataGetNTerms(SCIP *scip)
static SCIP_DECL_PROBEXITSOL(probexitsolStp)
static SCIP_DECL_PROBTRANS(probtransStp)
SCIP_CONS ** SCIPprobdataGetEdgeConstraints(SCIP *scip)
Constraint handler for Steiner problems.
void SCIPprobdataSetOffset(SCIP_PROBDATA *probdata, SCIP_Real offset)
SCIP_RETCODE SCIPdualAscentAddCutsStp(SCIP *scip, GRAPH *g, int nruns)
SCIP_VAR ** SCIPprobdataGetVars(SCIP *scip)
int SCIPprobdataGetNEdges(SCIP *scip)
SCIP_RETCODE SCIPprobdataWriteIntermediateSolution(SCIP *scip)
SCIP_RETCODE graph_mincut_init(SCIP *, GRAPH *)
static SCIP_RETCODE probdataCreate(SCIP *scip, SCIP_PROBDATA **probdata, GRAPH *graph)
Problem data for stp problem.
void graph_path_exit(SCIP *, GRAPH *)
int SCIPprobdataGetNVars(SCIP *scip)
static SCIP_RETCODE probdataPrintGraph(GRAPH *graph, const char *filename, SCIP_Bool *edgemark)
void graph_free(SCIP *, GRAPH *, SCIP_Bool)
static SCIP_RETCODE createConstraints(SCIP *scip, SCIP_PROBDATA *probdata)
int SCIPprobdataGetNLayers(SCIP *scip)
SCIP_RETCODE SCIPprobdataWriteLogfileEnd(SCIP *scip)
GRAPH * SCIPprobdataGetGraph(SCIP_PROBDATA *probdata)
Problem data which is accessible in all places.
#define STP_OBSTACLES_GRID
SCIP_CONS ** prizesymcons
void SCIPprobdataWriteLogLine(SCIP *scip, const char *formatstr,...)
SCIP_RETCODE graph_pack(SCIP *, GRAPH *, GRAPH **, SCIP_Bool)
int * SCIPprobdataGetRTerms(SCIP *scip)
SCIP_RETCODE SCIPprobdataWriteSolution(SCIP *scip, FILE *file)
static SCIP_RETCODE probdataFree(SCIP *scip, SCIP_PROBDATA **probdata)
void SCIPprobdataSetNSolvers(SCIP *scip, int nSolvers)
SCIP_CONS ** SCIPprobdataGetPathConstraints(SCIP *scip)
int SCIPprobdataGetRNTerms(SCIP *scip)
SCIP_Bool SCIPprobdataIsBigt(SCIP *scip)
SCIP_RETCODE SCIPprobdataAddNewSol(SCIP *scip, SCIP_Real *nval, SCIP_SOL *sol, SCIP_HEUR *heur, SCIP_Bool *success)
SCIP_RETCODE SCIPprobdataPrintGraph(SCIP *scip, const char *filename, SCIP_SOL *sol, SCIP_Bool printsol)
SCIP_Real SCIPprobdataGetOffset(SCIP *scip)
SCIP_RETCODE reduce(SCIP *, GRAPH **, SCIP_Real *, int, int)
SCIP_RETCODE graph_grid_coordinates(SCIP *, int **, int **, int *, int, int)
#define STP_MAX_NODE_WEIGHT
SCIP_RETCODE SCIPprobdataPrintGraph2(const GRAPH *graph, const char *filename, SCIP_Bool *edgemark)
SCIP_RETCODE SCIPprobdataCreate(SCIP *scip, const char *filename)
int SCIPprobdataGetType(SCIP *scip)
void SCIPprobdataSetGraph(SCIP_PROBDATA *probdata, GRAPH *graph)
SCIP_CONS ** prizecyclecons
SCIP_VAR ** SCIPprobdataGetEdgeVars(SCIP *scip)
void graph_mincut_exit(SCIP *, GRAPH *)
#define STP_PRIZE_COLLECTING
void SCIPprobdataSetDualBound(SCIP *scip, SCIP_Real dual)
SCIP_RETCODE SCIPdualAscentPcStp(SCIP *scip, GRAPH *g, SCIP_Real *redcost, SCIP_Real *objval, SCIP_Bool addcuts, int nruns)
int SCIPprobdataGetRoot(SCIP *scip)
SCIP_RETCODE SCIPcreateConsStp(SCIP *scip, SCIP_CONS **cons, const char *name, GRAPH *graph)
includes various files containing graph methods used for Steiner problems
static SCIP_DECL_PROBDELTRANS(probdeltransStp)
SCIP_RETCODE graph_load(SCIP *, GRAPH **, const char *, PRESOL *)
#define STP_ROOTED_PRIZE_COLLECTING
static SCIP_DECL_PROBCOPY(probcopyStp)
SCIP_Real * SCIPprobdataGetXval(SCIP *scip, SCIP_SOL *sol)
SCIP_VAR * SCIPprobdataGetedgeVarByIndex(SCIP *scip, int idx)
static SCIP_RETCODE createHopConstraint(SCIP *scip, SCIP_PROBDATA *probdata)
static SCIP_RETCODE createPrizeConstraints(SCIP *scip, SCIP_PROBDATA *probdata)
struct Int_List_Node * parent
static SCIP_RETCODE createDegreeConstraints(SCIP *scip, SCIP_PROBDATA *probdata)
SCIP_RETCODE graph_copy(SCIP *, GRAPH *, GRAPH **)
static SCIP_DECL_PROBDELORIG(probdelorigStp)
void graph_path_exec(SCIP *, const GRAPH *, int, int, SCIP_Real *, PATH *)