44 #define STP_DELPSEUDO_MAXGRAD 5 45 #define STP_DELPSEUDO_MAXNEDGES 10 66 assert(edgeidx1 != edgeidx2);
71 newcost = ecostrev[edgeidx1] + ecost[edgeidx2];
73 if( !
SCIPisGT(scip, newcost, cutoffs[cutoffidx]) )
76 if( cutoffsrev !=
NULL )
78 const SCIP_Real newcostrev = ecost[edgeidx1] + ecostrev[edgeidx2];
80 if( !
SCIPisGT(scip, newcostrev, cutoffsrev[cutoffidx]) )
100 assert(e < g->edges);
105 if( g->
inpbeg[head] == e )
112 assert(g->
ieat[i] == e);
113 if( g->
ieat[e] >= 0 )
122 if( g->
outbeg[tail] == e )
129 assert(g->
oeat[i] == e);
130 if( g->
oeat[e] >= 0 )
154 for( i = 0; i < grid_dim; i++ )
157 for( j = i + 1; j < grid_dim; j++ )
159 tmp = tmp * ncoords[j];
161 if( shiftcoord == i )
162 number += (currcoord[i] + 1) * tmp;
164 number += currcoord[i] * tmp;
194 while( i < ncoords[coord] )
196 currcoord[coord] = i;
197 if( coord < grid_dim - 1 )
198 compEdgesObst(coord + 1, grid_dim, nobstacles, ncoords, currcoord, edgecosts, gridedgecount, coords, gridedges, obst_coords, inobstacle);
201 x = coords[0][currcoord[0]];
202 y = coords[1][currcoord[1]];
205 for( z = 0; z < nobstacles; z++ )
207 assert(obst_coords[0][z] < obst_coords[2][z]);
208 assert(obst_coords[1][z] < obst_coords[3][z]);
209 if( x > obst_coords[0][z] && x < obst_coords[2][z] &&
210 y > obst_coords[1][z] && y < obst_coords[3][z] )
213 inobstacle[node-1] =
TRUE;
217 for( j = 0; j < grid_dim; j++ )
219 if( currcoord[j] + 1 < ncoords[j] )
221 if( inobst ==
FALSE )
223 gridedges[0][*gridedgecount] = node;
224 gridedges[1][*gridedgecount] =
getNodeNumber(grid_dim, j, ncoords, currcoord);
225 edgecosts[*gridedgecount] = coords[j][currcoord[j] + 1] - coords[j][currcoord[j]];
250 while( i < ncoords[coord] )
252 currcoord[coord] = i;
253 if( coord < grid_dim - 1 )
254 compEdges(coord + 1, grid_dim, ncoords, currcoord, edgecosts, gridedgecount, coords, gridedges);
257 for( j = 0; j < grid_dim; j++ )
259 if( currcoord[j] + 1 < ncoords[j] )
261 gridedges[0][*gridedgecount] =
getNodeNumber(grid_dim, -1, ncoords, currcoord);
262 gridedges[1][*gridedgecount] =
getNodeNumber(grid_dim, j, ncoords, currcoord);
263 edgecosts[*gridedgecount] = coords[j][currcoord[j] + 1] - coords[j][currcoord[j]];
290 assert(maxweights !=
NULL);
291 assert(scip !=
NULL);
292 assert(graph !=
NULL);
294 assert(graph->
terms == 0);
296 nnodes = graph->
knots;
299 for( i = 0; i <
nnodes; i++ )
301 if(
SCIPisLT(scip, maxweights[i], 0.0) )
305 graph->
cost[e] -= maxweights[i];
315 for( i = 0; i <
nnodes; i++ )
317 graph->
prize[i] = maxweights[i];
320 assert(
SCIPisGE(scip, maxweights[i], 0.0));
325 assert(
SCIPisLT(scip, maxweights[i], 0.0));
328 assert(nterms == graph->
terms);
351 assert(graph !=
NULL);
356 prize = graph->
prize;
357 nnodes = graph->
knots;
358 nterms = graph->
terms;
366 for( k = 0; k <
nterms; ++k )
370 pseudoroot = graph->
knots;
378 for( k = 0; k <
nnodes; ++k )
390 assert(
SCIPisGE(scip, prize[k], 0.0));
405 assert((nterms + 1) == graph->
terms);
448 assert(coords !=
NULL);
449 assert(grid_dim > 1);
451 assert(grid_dim == 2);
452 scale_factor =
pow(10.0, (
double) scale_order);
457 for( i = 0; i < grid_dim; i++ )
460 for( j = 0; j <
nterms; j++ )
461 termcoords[i][j] = coords[i][j];
468 for( i = 0; i < grid_dim; i++ )
473 for( j = 0; j < nterms - 1; j++ )
475 if( coords[i][j] == coords[i][j + 1] )
481 coords[i][j + 1 - shift] = coords[i][j + 1];
489 for( i = 0; i < grid_dim; i++ )
490 nnodes = nnodes * ncoords[i];
494 for( i = 0; i < grid_dim; i++ )
495 tmp = tmp + nnodes / ncoords[i];
497 nedges = grid_dim * nnodes - tmp;
504 for( i = 0; i <
nnodes; i++ )
505 inobstacle[i] =
FALSE;
506 compEdgesObst(0, grid_dim, nobstacles, ncoords, currcoord, edgecosts, &gridedgecount, coords, gridedges, obst_coords, inobstacle);
507 nedges = gridedgecount;
513 for( i = 0; i < grid_dim; i++ )
520 for( i = 0; i < nnodes; i++ )
524 for( i = 0; i < nedges; i++ )
527 if( inobstacle[gridedges[1][i] - 1] ==
FALSE )
529 cost = ((double) edgecosts[i]) / scale_factor;
530 graph_edge_add(scip, g, gridedges[0][i] - 1, gridedges[1][i] - 1, cost, cost);
535 for( i = 0; i <
nterms; i++ )
537 for( j = 0; j < grid_dim; j++ )
539 for( k = 0; k <= ncoords[j]; k++ )
541 assert(k != ncoords[j]);
542 if( coords[j][k] == termcoords[j][i] )
571 for( i = grid_dim - 1; i >= 0 ; --i )
607 assert(coords !=
NULL);
608 assert(grid_dim > 1);
611 scale_factor =
pow(10.0, (
double) scale_order);
615 for( i = 0; i < grid_dim; i++ )
618 for( j = 0; j <
nterms; j++ )
619 termcoords[i][j] = coords[i][j];
625 for( i = 0; i < grid_dim; i++ )
630 for( j = 0; j < nterms - 1; j++ )
632 if( coords[i][j] == coords[i][j + 1] )
638 coords[i][j + 1 - shift] = coords[i][j + 1];
645 for( i = 0; i < grid_dim; i++ )
646 nnodes = nnodes * ncoords[i];
649 for( i = 0; i < grid_dim; i++ )
651 tmp = tmp + nnodes / ncoords[i];
654 nedges = grid_dim * nnodes - tmp;
663 compEdges(0, grid_dim, ncoords, currcoord, edgecosts, &gridedgecount, coords, gridedges);
671 for( i = 0; i < grid_dim; i++ )
678 for( i = 0; i < nnodes; i++ )
682 for( i = 0; i < nedges; i++ )
685 cost = (double) edgecosts[i] / scale_factor;
686 graph_edge_add(scip, g, gridedges[0][i] - 1, gridedges[1][i] - 1, cost, cost);
690 for( i = 0; i <
nterms; i++ )
692 for( j = 0; j < grid_dim; j++ )
694 for( k = 0; k <= ncoords[j]; k++ )
696 assert(k != ncoords[j]);
697 if( coords[j][k] == termcoords[j][i] )
720 for( i = grid_dim - 1; i >= 0 ; i-- )
743 assert(grid_dim > 1);
745 assert(coords !=
NULL);
746 assert(ncoords !=
NULL);
747 if( *nodecoords ==
NULL )
750 for( i = 0; i < grid_dim; i++ )
753 for( j = i; j < grid_dim; j++ )
754 tmp = tmp * ncoords[j];
757 tmp = tmp / ncoords[i];
759 (*nodecoords)[i] = coords[i][coord];
773 assert(scip !=
NULL);
782 if( sizeterm2edge > 0 )
786 for(
int i = 0; i < sizeterm2edge; i++ )
800 const int root = g->
source;
801 const int nedges = g->
edges;
808 assert(nedges > 0 && g->
grad[root] > 0);
812 for(
int e = 0; e < nedges; e++ )
864 for(
int i = 0; i < g->
knots; i++ )
916 assert(node < g->knots);
930 const GRAPH* oldgraph,
937 assert(newgraph !=
NULL);
938 assert(oldgraph !=
NULL);
941 assert(newtail >= 0);
942 assert(newhead >= 0);
943 assert(oldtail >= 0);
944 assert(oldhead >= 0);
949 if( oldgraph->
term2edge[oldtail] >= 0 && oldgraph->
term2edge[oldhead] >= 0 && oldgraph->
term[oldtail] != oldgraph->
term[oldhead] )
953 assert(oldgraph->
source != oldtail && oldgraph->
source != oldhead);
971 assert(graph !=
NULL);
975 nnodes = graph->
knots;
977 for(
int k = 0; k <
nnodes; k++ )
979 graph->
mark[k] = (graph->
grad[k] > 0);
1006 const int root = graph->
source;
1009 assert(graph !=
NULL);
1012 for(
int k = 0; k <
nnodes; k++ )
1014 graph->
mark[k] = (graph->
grad[k] > 0);
1032 assert(graph !=
NULL);
1045 assert(graph !=
NULL);
1061 assert(scip !=
NULL);
1062 assert(graph !=
NULL);
1066 for(
int i = 0; i < graph->
knots; i++ )
1068 prizesum += graph->
prize[i];
1095 assert(scip !=
NULL);
1096 assert(graph !=
NULL);
1101 prize = graph->
prize;
1102 nnodes = graph->
knots;
1103 nterms = graph->
terms;
1114 SCIP_CALL(
graph_resize(scip, (*newgraph), ((*newgraph)->ksize + 1), ((*newgraph)->esize + 2 * (nterms - 1)) , -1) );
1116 (*newgraph)->source = graph->
source;
1117 root = (*newgraph)->source;
1120 pseudoroot = (*newgraph)->knots;
1124 for( k = 0; k <
nnodes; k++ )
1127 prizesum += prize[k];
1129 if( prize[k] > max )
1134 *offset -= prizesum;
1138 e = (*newgraph)->outbeg[root];
1142 enext = (*newgraph)->oeat[e];
1143 head = (*newgraph)->head[e];
1144 if(
Is_term((*newgraph)->term[head]) )
1148 assert((*newgraph)->head[e] == head);
1149 assert((*newgraph)->tail[e] == pseudoroot);
1153 (*newgraph)->cost[e] = prizesum;
1161 for( k = 0; k <
nnodes; k++ )
1164 if(
Is_pterm((*newgraph)->term[k]) )
1182 const int root = graph->
source;
1185 assert(scip !=
NULL && graph !=
NULL && offset !=
NULL);
1186 assert(graph->
outbeg[root] >= 0);
1189 assert(oldbigM > 0.0);
1191 *offset += (oldbigM - bigM);
1193 printf(
"new vs old %f, %f \n", bigM, oldbigM);
1197 assert(graph->
cost[e] == oldbigM);
1198 graph->
cost[e] = bigM;
1218 const int stp_type = graph->
stp_type;
1222 assert(scip !=
NULL);
1223 assert(graph !=
NULL);
1240 for(
int k = 0; k <
nnodes; k++ )
1243 assert(graph->
grad[k] > 0);
1244 maxp = graph->
prize[k];
1248 assert(maxvert >= 0);
1251 for(
int k = 0; k <
nnodes; k++ )
1253 newg->
mark[k] = (newg->
grad[k] > 0);
1258 assert(newg->
mark[k]);
1275 const int tail = graph->
tail[e];
1279 if( tail == graph->
source )
1316 pseudoroot = newg->
knots;
1320 for(
int k = 0; k <
nnodes; k++ )
1322 prizesum += prize[k];
1326 *offset -= prizesum;
1332 const int head = newg->
head[e];
1333 const int enext = newg->
oeat[e];
1339 assert(newg->
head[e] == head);
1340 assert(newg->
tail[e] == pseudoroot);
1344 newg->
cost[e] = prizesum;
1351 for(
int k = 0; k <
nnodes; k++ )
1356 assert(newg->
mark[k]);
1384 assert(graph !=
NULL);
1417 assert(aterm != -1);
1422 head = graph->
head[e];
1424 assert(graph->
head[e] == p->
head[e]);
1425 assert(graph->
tail[e] == p->
tail[e]);
1435 if( p->
head[e2] != root )
1436 assert(p->
term[p->
head[e2]] == -2);
1446 assert(p->
grad[aterm] == 0);
1452 for( k = 0; k <
nnodes; k++ )
1461 for( k = 0; k <
nnodes; k++)
1464 if( k < graph->norgmodelknots )
1472 if( nrootcands > 0 )
1475 for( k = 0; k < nrootcands; k++ )
1477 aterm = rootcands[k];
1489 assert(p->
grad[head] == 2);
1490 assert(head != root);
1512 p->
prize[root] = 0.0;
1530 assert(graph !=
NULL);
1533 nterms = graph->
terms;
1534 prize = graph->
prize;
1535 assert(prize !=
NULL);
1536 assert(nnodes == graph->
ksize);
1544 for(
int k = 0; k <
nterms; ++k )
1548 root = graph->
knots;
1556 for(
int k = 0; k <
nnodes; ++k )
1562 const int node = nnodes +
nterms;
1568 assert(
SCIPisGE(scip, prize[k], 0.0));
1590 assert((nterms + 1) == graph->
terms);
1612 assert(graph !=
NULL);
1616 nnodes = graph->
knots;
1617 nterms = graph->
terms;
1618 prize = graph->
prize;
1622 assert(prize !=
NULL);
1623 assert(nnodes == graph->
ksize);
1630 for(
int k = 0; k < nterms - 1; ++k )
1639 for(
int k = 0; k <
nnodes; ++k )
1650 assert(
SCIPisGE(scip, prize[k], 0.0));
1673 assert(nterms == graph->
terms);
1691 assert(maxweights !=
NULL);
1692 assert(scip !=
NULL);
1693 assert(graph !=
NULL);
1695 assert(graph->
terms == 0);
1697 nnodes = graph->
knots;
1700 for(
int i = 0; i <
nnodes; i++ )
1702 if(
SCIPisLT(scip, maxweights[i], 0.0) )
1705 graph->
cost[e] -= maxweights[i];
1707 else if(
SCIPisGT(scip, maxweights[i], 0.0) )
1714 for(
int i = 0; i <
nnodes; i++ )
1716 graph->
prize[i] = maxweights[i];
1719 assert(
SCIPisGE(scip, maxweights[i], 0.0));
1724 assert(
SCIPisLE(scip, maxweights[i], 0.0));
1727 assert(nterms == graph->
terms);
1754 assert(scip !=
NULL);
1755 assert(graph !=
NULL);
1762 nnodes = graph->
knots;
1763 maxweights = graph->
prize;
1765 assert(maxweights !=
NULL);
1768 for( i = 0; i <
nnodes; i++ )
1770 if(
SCIPisLT(scip, maxweights[i], 0.0) )
1773 graph->
cost[e] -= maxweights[i];
1778 if( graph->
grad[i] > maxgrad )
1781 maxgrad = graph->
grad[i];
1786 else if(
SCIPisGT(scip, maxweights[i], 0.0) )
1794 assert(graph->
terms == (npterms + nrterms));
1804 for(
int k = 0; k < npterms; k++ )
1812 for(
int k = 0; k <
nnodes; ++k )
1818 const int node = nnodes + i;
1824 assert(
SCIPisGE(scip, maxweights[k], 0.0));
1840 assert(i == npterms);
1860 const int root = graph->
source;
1862 assert(scip !=
NULL);
1863 assert(graph !=
NULL);
1873 const int enext = graph->
oeat[e];
1877 const int k = graph->
head[e];
1880 assert(graph->
grad[k] == 2);
1883 if( graph->
head[e2] != root )
1886 p = graph->
head[e2];
1902 if( graph->
grad[p] > maxgrad )
1905 maxgrad = graph->
grad[p];
1919 const int enext = graph->
oeat[e];
1920 const int k = graph->
head[e];
1953 const int grad = g->
grad[i];
1956 assert(scip !=
NULL);
1969 const int i1 = g->
head[e];
1976 assert(g->
grad[i] == 0);
2002 assert(scip !=
NULL);
2008 g->
prize[i] -= cost;
2018 assert(!g->
mark[j]);
2045 assert(scip !=
NULL);
2047 assert(newprize > 0.0);
2052 g->
prize[i] = newprize;
2062 assert(!g->
mark[j]);
2071 g->
cost[e] = newprize;
2088 assert(scip !=
NULL);
2093 if( g->
head[ets] == s )
2117 assert(scip !=
NULL);
2122 if( g->
head[ets] == s )
2147 assert(!g->
mark[j]);
2171 assert(g->
grad[s] == 0);
2207 assert(term < p->layers);
2230 assert(node < p->knots);
2231 assert(term < p->layers);
2233 if( term != p->
term[node] )
2238 p->
term[node] = term;
2255 assert(k < g->knots);
2283 const int degree = g->
grad[vertex];
2285 assert(scip !=
NULL);
2286 assert(success !=
NULL);
2288 assert(vertex >= 0);
2289 assert(vertex < g->knots);
2306 nspareedges = degree;
2318 incedge[edgecount] = e;
2319 ecostreal[edgecount] = g->
cost[e];
2320 ecost[edgecount] = edgecosts[e];
2321 ecostrev[edgecount] = edgecosts[
flipedge(e)];
2323 adjvert[edgecount++] = g->
head[e];
2328 assert(edgecount == degree);
2333 for(
int i = 0; i < degree - 1; i++ )
2335 const int adjvertex = adjvert[i];
2336 for(
int j = i + 1; j < degree; j++ )
2339 const SCIP_Bool cutoff =
cutoffEdge(scip, cutoffs, cutoffsrev, ecost, ecostrev, i, j, edgecount);
2341 assert(edgecount < STP_DELPSEUDO_MAXNEDGES);
2351 if( g->
head[e] == adjvert[j] )
2354 neigbedge[edgecount - 1] = e;
2361 if( ++replacecount > nspareedges )
2369 for(
int i = 0; i < degree; i++ )
2371 const int e = incedge[i];
2372 ancestors[i] =
NULL;
2373 revancestors[i] =
NULL;
2382 for(
int i = 0; i < degree - 1; i++ )
2384 for(
int j = i + 1; j < degree; j++ )
2386 const SCIP_Bool cutoff =
cutoffEdge(scip, cutoffs, cutoffsrev, ecost, ecostrev, i, j, edgecount);
2388 assert(edgecount < STP_DELPSEUDO_MAXNEDGES);
2395 const SCIP_Real newcost = ecostreal[i] + ecostreal[j];
2396 const int oldedge = incedge[(replacecount == nspareedges) ? replacecount - 1 : replacecount];
2398 const int oldtail = g->
tail[oldedge];
2399 const int oldhead = g->
head[oldedge];
2401 assert(replacecount <= nspareedges);
2402 assert(replacecount < nspareedges || neigbedge[edgecount - 1] >= 0);
2404 SCIP_CALL(
graph_edge_reinsert(scip, g, oldedge, adjvert[i], adjvert[j], newcost, ancestors[i], ancestors[j], revancestors[i], revancestors[j],
FALSE));
2407 if( neigbedge[edgecount - 1] < 0 )
2412 assert(oldtail == g->
tail[oldedge]);
2413 assert(oldhead == g->
head[oldedge]);
2423 for(
int i = 0; i < degree; i++ )
2460 assert(t < p->knots);
2462 assert(s < p->knots);
2464 assert(scip !=
NULL);
2465 assert(p->
grad[s] > 0);
2466 assert(p->
grad[t] > 0);
2470 if( solnode !=
NULL )
2500 assert(p->
tail[es] == s);
2502 if( p->
head[es] != t )
2504 assert(ancestors !=
NULL);
2505 assert(revancestors !=
NULL);
2506 assert(mark !=
NULL);
2507 assert(incost !=
NULL);
2508 assert(outcost !=
NULL);
2509 assert(edge !=
NULL);
2510 assert(knot !=
NULL);
2512 ancestors[slc] =
NULL;
2514 revancestors[slc] =
NULL;
2519 knot[slc] = p->
head[es];
2520 outcost[slc] = p->
cost[es];
2524 assert(slc < sgrad);
2528 assert(slc == sgrad - 1);
2531 for( i = 0; i < slc; i++ )
2533 const int ihead = knot[i];
2540 for( et = p->
outbeg[t]; et >= 0; et = p->
oeat[et] )
2541 if( p->
head[et] == ihead )
2546 for( et = p->
inpbeg[ihead]; et >= 0; et = p->
ieat[et] )
2547 if( p->
tail[et] == t )
2563 if( p->
cost[et] > outcost[i] )
2566 assert(ancestors !=
NULL);
2569 p->
cost[et] = outcost[i];
2575 assert(revancestors !=
NULL);
2576 assert(incost !=
NULL);
2578 p->
cost[anti] = incost[i];
2584 for( i = 0; i < slc; i++ )
2586 assert(mark !=
NULL);
2592 assert(ancestors !=
NULL);
2593 assert(revancestors !=
NULL);
2594 assert(ancestors[i] !=
NULL);
2595 assert(revancestors[i] !=
NULL);
2596 assert(knot !=
NULL);
2597 assert(outcost !=
NULL);
2598 assert(incost !=
NULL);
2610 p->
cost[es] = outcost[i];
2623 p->
cost[es] = incost[i];
2644 assert(ancestors !=
NULL);
2645 assert(revancestors !=
NULL);
2646 for( i = 0; i < slc; i++ )
2659 assert(p->
grad[s] == 0);
2702 assert(g->
tail[e] == k);
2704 if( g->
head[e] == j )
2803 assert(
SCIPisGE(scip, cost2, 0.0) ||
SCIPisEQ(scip, cost2, (
double) UNKNOWN));
2805 assert(tail < g->knots);
2807 assert(head < g->knots);
2816 if( cost1 != UNKNOWN )
2827 if( cost2 != UNKNOWN )
2850 assert(e < g->edges);
2854 assert(scip !=
NULL);
2861 assert(g->
head[e] == g->
tail[e + 1]);
2862 assert(g->
tail[e] == g->
head[e + 1]);
2898 assert(e < g->edges);
2904 assert(g->
head[e] == g->
tail[e + 1]);
2905 assert(g->
tail[e] == g->
head[e + 1]);
2941 const int t = g->
tail[e];
2942 const int h = g->
head[e];
2943 printf(
"e: %d %d->%d (%d->%d) \n", e, t, h, g->
term[t], g->
term[h]);
2955 int*
const gmark = g->
mark;
2959 assert(scip !=
NULL);
2961 assert(result !=
NULL);
2964 if( g->
grad[newroot] == 0 )
2967 for(
int k = 0; k <
nnodes; k++ )
2972 gmark[newroot] =
TRUE;
2974 queue[size++] = newroot;
2979 const int node = queue[--size];
2984 const int head = g->
head[
a];
2994 queue[size++] = head;
3002 for(
int k = 0; k <
nnodes; k++ )
3020 const int node = g->
tail[
a];
3021 if( gmark[node] && node != newroot )
3031 const int node = g->
tail[
a];
3032 if( node == newroot )
3056 const int nedges = graph->
edges;
3058 assert(scip !=
NULL);
3059 assert(graph !=
NULL);
3060 assert(result !=
NULL);
3062 for(
int i = 0; i < nedges; i++ )
3084 assert(scip !=
NULL);
3085 assert(graph !=
NULL);
3086 assert(result !=
NULL);
3089 nnodes = graph->
knots;
3101 assert(reached !=
NULL);
3103 for(
int i = 0; i <
nnodes; i++ )
3110 reached[root] =
TRUE;
3111 queue[size++] = root;
3115 const int node = queue[--size];
3121 const int i = graph->
head[e];
3149 if(termcount != graph->
terms)
3151 printf(
"termcount %d graph->terms %d \n", termcount, graph->
terms);
3152 printf(
"root %d \n", root);
3154 for(
int i = 0; i < nnodes && 0; i++ )
3158 printf(
"fail %d grad %d\n", i, graph->
grad[i]);
3161 printf(
"tail %d %d \n", graph->
tail[e], graph->
term[graph->
tail[e]]);
3170 return (termcount == graph->
terms);
3184 assert(solnode !=
NULL);
3188 while( curr !=
NULL )
3210 for( e = 0; e < nedges; e++ )
3220 const GRAPH* transgraph,
3221 const GRAPH* orggraph,
3222 const int* transsoledge,
3231 const int transnedges = transgraph->
edges;
3232 const int transnnodes = transgraph->
knots;
3233 const int orgnnodes = orggraph->
knots;
3236 assert(transgraph !=
NULL && orggraph !=
NULL && transsoledge !=
NULL && orgsoledge !=
NULL);
3246 for(
int k = 0; k < transnnodes; k++ )
3247 transnodearr[k] =
FALSE;
3249 for(
int e = 0; e < transnedges; e++ )
3250 if( transsoledge[e] ==
CONNECT )
3252 transnodearr[transgraph->
tail[e]] =
TRUE;
3253 transnodearr[transgraph->
head[e]] =
TRUE;
3257 for(
int k = 0; k < orgnnodes; k++ )
3258 orgnodearr[k] =
FALSE;
3260 for(
int e = 0; e < transnedges; e++ )
3261 if( transsoledge[e] ==
CONNECT )
3273 for(
int e = 0; e < orggraph->
edges; e++ )
3307 int nedges = (nsoledges !=
NULL)? *nsoledges : 0;
3311 assert(scip !=
NULL && tails !=
NULL && heads !=
NULL && pcancestors !=
NULL && solnodemark !=
NULL);
3313 if( solnodequeue !=
NULL )
3314 queue = solnodequeue;
3318 if( nsolnodes ==
NULL )
3320 assert(solnodequeue ==
NULL);
3322 for(
int k = 0; k < orgnnodes; k++ )
3323 if( solnodemark[k] )
3324 queue[nnodes++] = k;
3328 nnodes = *nsolnodes;
3329 assert(solnodequeue !=
NULL);
3335 while( qend != qstart )
3339 assert(qstart < qend);
3342 for( ; k < qend; k++ )
3344 const int ancestornode = queue[k];
3346 assert(solnodemark[ancestornode]);
3348 for(
IDX* curr = pcancestors[ancestornode]; curr !=
NULL; curr = curr->parent )
3350 const int ancestoredge = curr->index;
3351 assert(tails[ancestoredge] < orgnnodes && heads[ancestoredge] < orgnnodes);
3353 if( soledgemark !=
NULL && !soledgemark[ancestoredge] )
3355 soledgemark[ancestoredge] =
TRUE;
3358 if( !solnodemark[tails[ancestoredge]] )
3360 solnodemark[tails[ancestoredge]] =
TRUE;
3361 queue[nnodes++] = tails[ancestoredge];
3363 if( !solnodemark[heads[ancestoredge]] )
3365 solnodemark[heads[ancestoredge]] =
TRUE;
3366 queue[nnodes++] = heads[ancestoredge];
3373 if( nsolnodes !=
NULL )
3376 if( nsoledges !=
NULL )
3377 *nsoledges = nedges;
3379 if( solnodequeue ==
NULL )
3398 assert(graph !=
NULL);
3400 vorg = graph->
knots;
3402 for(
int k = 0; k < vorg; k++ )
3404 if( graph->
grad[k] > 0 )
3407 e += graph->
grad[k];
3423 int* RESTRICT edgearr,
3424 int* RESTRICT tailarr,
3425 int* RESTRICT start,
3433 assert(tailarr !=
NULL);
3434 assert(edgearr !=
NULL);
3435 assert(start !=
NULL);
3437 for(
int k = 0; k <
nnodes; k++ )
3443 tailarr[i++] = g->
tail[e] + 1;
3459 const int nedges = g->
edges;
3464 assert(nedgesorg % 2 == 0);
3466 printf(
"orgedes %d \n", nedgesorg);
3470 for(
int e = 0; e < nedgesorg / 2; e++ )
3473 for(
int e = 0; e < nedges; e += 2 )
3476 assert(curr->index >= 0 && curr->index / 2 < nedgesorg / 2);
3477 childcount[curr->index / 2]++;
3482 for(
int e = 0; e < nedgesorg / 2; e++ )
3483 if( childcount[e] > 1 )
3486 printf(
"nconflicts %d \n", nconflicts);
3506 assert(ksize < INT_MAX);
3508 assert(esize < INT_MAX);
3510 assert(layers < SHRT_MAX);
3587 assert(scip !=
NULL);
3588 assert(graph !=
NULL);
3592 nedges = graph->
edges;
3602 for(
int e = 0; e < nedges; e++ )
3604 orgtail[e] = tail[e];
3605 orghead[e] = head[e];
3616 for(
int k = 0; k <
nnodes; k++ )
3617 pcancestors[k] =
NULL;
3624 for(
int e = 0; e < nedges; e++ )
3627 (ancestors)[e]->index = e;
3628 (ancestors)[e]->parent =
NULL;
3643 assert(scip !=
NULL);
3645 assert((ksize < 0) || (ksize >= g->
knots));
3646 assert((esize < 0) || (esize >= g->
edges));
3647 assert((layers < 0) || (layers >= g->
layers));
3649 if( (layers > 0) && (layers != g->
layers) )
3652 if( (ksize > 0) && (ksize != g->
ksize) )
3662 if( (esize > 0) && (esize != g->
esize) )
3686 assert(scip !=
NULL);
3687 assert(graph !=
NULL);
3713 for(
int i = p->
grid_dim - 1; i >= 0; i-- )
3747 const int nedges = p->
edges;
3749 for(
int e = nedges - 1; e >= 0; e-- )
3752 while( curr !=
NULL )
3771 assert(scip !=
NULL);
3781 while( curr !=
NULL )
3799 while( curr !=
NULL )
3811 const GRAPH* orgraph,
3815 GRAPH* g = copygraph;
3816 const GRAPH* p = orgraph;
3817 const int ksize = p->
ksize;
3818 const int esize = p->
esize;
3820 assert(scip !=
NULL);
3821 assert(orgraph !=
NULL);
3822 assert(copygraph !=
NULL);
3823 assert(ksize == g->
ksize && ksize > 0);
3824 assert(esize == g->
esize && esize >= 0);
3858 for(
int k = 0; k < g->
knots; k++ )
3874 for(
int k = 0; k < g->
knots; k++ )
3885 for(
int k = 0; k < p->
grid_dim; k++ )
3902 const GRAPH* orgraph,
3906 const GRAPH* p = orgraph;
3924 for(i = 0; i < p->
knots; i++)
3926 (void)printf(
"Knot %d, term=%d, grad=%d, inpbeg=%d, outbeg=%d\n",
3929 (void)fputc(
'\n', stdout);
3931 for(i = 0; i < p->
edges; i++)
3933 (void)printf(
"Edge %d, cost=%g, tail=%d, head=%d, ieat=%d, oeat=%d\n",
3936 (void)fputc(
'\n', stdout);
3951 for( e = 0; e < g->
edges; e++ )
3973 assert(g->
head[e] == tail);
3974 assert(g->
tail[e] == head);
4006 assert(scip !=
NULL);
4007 assert(graph !=
NULL);
4013 oldnnodes = g->
knots;
4014 oldnedges = g->
edges;
4018 printf(
"Reduced graph: ");
4021 for(
int i = 0; i < oldnnodes; i++ )
4024 if( g->
grad[i] > 0 )
4036 printf(
" graph vanished!\n");
4042 for(
int i = 0; i < oldnedges; i++ )
4051 assert(nnodes > 1 || nedges == 0);
4098 for( i = 0; i < oldnnodes; i++ )
4107 assert(g->
grad[i] == 2);
4112 for(
int i = 0; i < oldnnodes; i++ )
4115 if( g->
grad[i] > 0 )
4137 for(
int i = 0; i < oldnedges; i += 2 )
4152 assert(
new[g->
tail[i]] >= 0);
4153 assert(
new[g->
head[i]] >= 0);
4162 assert(
new[g->
tail[i]] < nnodes &&
new[g->
head[i]] < nnodes);
4181 printf(
"Nodes: %d Edges: %d Terminals: %d\n", q->
knots, q->
edges, q->
terms);
4197 assert(i < g->knots);
4211 if( g->
grad[i] == 0 )
4248 int*
const gmark = g->
mark;
4250 assert(scip !=
NULL);
4253 assert(i < g->knots);
4266 if( g->
grad[i] == 0 )
4274 stackarr[stacksize++] = i;
4277 while( stacksize != 0 )
4279 node = stackarr[--stacksize];
4289 stackarr[stacksize++] = head;
4308 assert(reachable !=
NULL);
4310 for(
int k = 0; k <
nnodes; k++ )
4317 for(
int k = 0; k <
nnodes; k++ )
4332 const char* fehler1 =
"*** Graph invalid: Head invalid, Knot %d, Edge %d, Tail=%d, Head=%d\n";
4333 const char* fehler2 =
"*** Graph invalid: Tail invalid, Knot %d, Edge %d, Tail=%d, Head=%d\n";
4334 const char* fehler3 =
"*** Graph invalid: Source invalid, Layer %d, Source %d, Terminal %d\n";
4335 const char* fehler4 =
"*** Graph invalid: FREE invalid, Edge %d/%d\n";
4336 const char* fehler5 =
"*** Graph invalid: Anti invalid, Edge %d/%d, Tail=%d/%d, Head=%d/%d\n";
4337 const char* fehler6 =
"*** Graph invalid: Knot %d with Grad 0 has Edges\n";
4338 const char* fehler7 =
"*** Graph invalid: Knot %d not connected\n";
4339 const char* fehler9 =
"*** Graph invalid: Wrong Terminal count, count is %d, should be %d\n";
4353 for( k = 0; k <
nnodes; k++ )
4360 if( g->
head[e] != k )
4364 return((
void)fprintf(stderr, fehler1, k, e, g->
tail[e], g->
head[e]),
FALSE);
4367 if( g->
tail[e] != k )
4371 return((
void)fprintf(stderr, fehler2, k, e, g->
tail[e], g->
head[e]),
FALSE);
4374 return((
void)fprintf(stderr, fehler9, g->
terms, g->
terms - nterms),
FALSE);
4379 return((
void)fprintf(stderr, fehler3,
4382 for( e = 0; e < nedges; e += 2 )
4390 return((
void)fprintf(stderr, fehler4, e, e + 1),
FALSE);
4393 return((
void)fprintf(stderr, fehler5,
4394 e, e + 1, g->
head[e], g->
tail[e + 1],
4398 for( k = 0; k <
nnodes; k++ )
4403 for( k = 0; k <
nnodes; k++ )
4405 if( (g->
grad[k] == 0)
4407 return((
void)fprintf(stderr, fehler6, k),
FALSE);
4411 return((
void)fprintf(stderr, fehler7, k),
FALSE);
4417 const int root = g->
source;
4425 for( k = 0; k <
nnodes; k++ )
4427 if( k == root || (rooted && g->
term2edge[k] < 0) )
4437 if( g->
grad[k] != 2 )
4444 if( g->
tail[e] == root )
4455 pterm = g->
head[e2];
4466 assert(pterm != root);
4485 if( nterms != npterms || nterms != g->
terms - 1 )
4494 for( k = 0; k <
nnodes; k++ )
4507 for( k = 0; k <
nnodes; k++ )
SCIP_RETCODE graph_sol_getOrg(SCIP *scip, const GRAPH *transgraph, const GRAPH *orggraph, const int *transsoledge, int *orgsoledge)
SCIP_Bool SCIPisEQ(SCIP *scip, SCIP_Real val1, SCIP_Real val2)
#define SCIPfreeBlockMemoryArray(scip, ptr, num)
static volatile int nterms
#define SCIPallocBlockMemoryArray(scip, ptr, num)
void graph_sol_setNodeList(const GRAPH *g, STP_Bool *solnode, IDX *listnode)
SCIP_Bool graph_pc_isPcMw(const GRAPH *g)
SCIP_RETCODE graph_init(SCIP *scip, GRAPH **g, int ksize, int esize, int layers)
SCIP_Bool SCIPisGE(SCIP *scip, SCIP_Real val1, SCIP_Real val2)
#define SCIPfreeMemoryArrayNull(scip, ptr)
SCIP_RETCODE graph_grid_create(SCIP *scip, GRAPH **gridgraph, int **coords, int nterms, int grid_dim, int scale_order)
#define SCIPfreeMemoryArray(scip, ptr)
SCIP_RETCODE graph_copy(SCIP *scip, const GRAPH *orgraph, GRAPH **copygraph)
SCIP_RETCODE SCIPqueueInsert(SCIP_QUEUE *queue, void *elem)
SCIP_RETCODE graph_pc_init(SCIP *scip, GRAPH *g, int sizeprize, int sizeterm2edge)
SCIPInterval pow(const SCIPInterval &x, const SCIPInterval &y)
void graph_pc_updateTerm2edge(GRAPH *newgraph, const GRAPH *oldgraph, int newtail, int newhead, int oldtail, int oldhead)
#define SCIPallocMemoryArray(scip, ptr, num)
SCIP_Bool graph_sol_valid(SCIP *scip, const GRAPH *graph, const int *result)
void graph_pc_adaptSap(SCIP *scip, SCIP_Real bigM, GRAPH *graph, SCIP_Real *offset)
void graph_pc_chgPrize(SCIP *scip, GRAPH *g, SCIP_Real newprize, int i)
SCIP_RETCODE graph_knot_contract(SCIP *scip, GRAPH *p, int *solnode, int t, int s)
void graph_pc_presolExit(SCIP *scip, GRAPH *g)
SCIP_Bool graph_valid(const GRAPH *g)
SCIP_RETCODE graph_pc_getSapShift(SCIP *scip, GRAPH *graph, GRAPH **newgraph, SCIP_Real *offset)
int *RESTRICT mincut_temp
void graph_uncover(GRAPH *g)
void * SCIPqueueRemove(SCIP_QUEUE *queue)
SCIP_RETCODE graph_knot_delPseudo(SCIP *scip, GRAPH *g, const SCIP_Real *edgecosts, const SCIP_Real *cutoffs, const SCIP_Real *cutoffsrev, int vertex, SCIP_Bool *success)
static int getNodeNumber(int grid_dim, int shiftcoord, int *ncoords, int *currcoord)
SCIP_RETCODE graph_trail_arr(SCIP *scip, const GRAPH *g, int i)
void graph_free_history(SCIP *scip, GRAPH *p)
SCIP_RETCODE graph_pc_2rmw(SCIP *scip, GRAPH *graph)
enum SCIP_Retcode SCIP_RETCODE
SCIP_RETCODE graph_copy_data(SCIP *scip, const GRAPH *orgraph, GRAPH *copygraph)
void graph_path_exit(SCIP *, GRAPH *)
SCIP_Real graph_sol_getObj(const SCIP_Real *edgecost, const int *soledge, SCIP_Real offset, int nedges)
SCIP_RETCODE graph_pc_2pc(SCIP *scip, GRAPH *graph)
#define SCIPfreeBlockMemory(scip, ptr)
void graph_pc_2org(GRAPH *graph)
#define STP_DELPSEUDO_MAXNEDGES
#define SCIPfreeBufferArray(scip, ptr)
#define SCIPallocBlockMemory(scip, ptr)
SCIP_EXPORT void SCIPsortInt(int *intarray, int len)
SCIP_Real graph_pc_getPosPrizeSum(SCIP *scip, const GRAPH *graph)
SCIP_RETCODE graph_sol_reroot(SCIP *scip, GRAPH *g, int *result, int newroot)
SCIP_RETCODE graph_pack(SCIP *scip, GRAPH *graph, GRAPH **newgraph, SCIP_Bool verbose)
SCIP_RETCODE graph_edge_reinsert(SCIP *scip, GRAPH *g, int e1, int k1, int k2, SCIP_Real cost, IDX *ancestors0, IDX *ancestors1, IDX *revancestors0, IDX *revancestors1, SCIP_Bool forcedelete)
void graph_pc_subtractPrize(SCIP *scip, GRAPH *g, SCIP_Real cost, int i)
SCIP_RETCODE graph_pc_mw2rmw(SCIP *scip, GRAPH *graph, SCIP_Real prizesum)
SCIP_Bool SCIPisLE(SCIP *scip, SCIP_Real val1, SCIP_Real val2)
void SCIPintListNodeFree(SCIP *scip, IDX **node)
void graph_show(const GRAPH *p)
void graph_knot_add(GRAPH *p, int term)
static SCIP_Bool cutoffEdge(SCIP *scip, const SCIP_Real *cutoffs, const SCIP_Real *cutoffsrev, const SCIP_Real *ecost, const SCIP_Real *ecostrev, int edgeidx1, int edgeidx2, int cutoffidx)
SCIP_Bool SCIPqueueIsEmpty(SCIP_QUEUE *queue)
void graph_edge_printInfo(SCIP *scip, const GRAPH *g, int e)
int *RESTRICT mincut_dist
miscellaneous methods used for solving Steiner problems
SCIP_RETCODE SCIPintListNodeAppendCopy(SCIP *scip, IDX **node1, IDX *node2, SCIP_Bool *conflict)
void graph_pc_2transcheck(GRAPH *graph)
#define SCIPfreeBufferArrayNull(scip, ptr)
static void compEdges(int coord, int grid_dim, int *ncoords, int *currcoord, int *edgecosts, int *gridedgecount, int **coords, int **gridedges)
SCIP_RETCODE graph_obstgrid_create(SCIP *scip, GRAPH **gridgraph, int **coords, int **obst_coords, int nterms, int grid_dim, int nobstacles, int scale_order)
#define SCIPreallocMemoryArray(scip, ptr, newnum)
SCIP_Bool SCIPisZero(SCIP *scip, SCIP_Real val)
int graph_pc_deleteTerm(SCIP *scip, GRAPH *g, int i)
SCIP_Bool graph_pc_term2edgeConsistent(const GRAPH *g)
internal miscellaneous methods
void graph_free(SCIP *scip, GRAPH **graph, SCIP_Bool final)
void graph_edge_del(SCIP *scip, GRAPH *g, int e, SCIP_Bool freeancestors)
SCIP_RETCODE graph_get_edgeConflicts(SCIP *scip, const GRAPH *g)
void graph_pc_knot2nonTerm(GRAPH *g, int node)
SCIP_RETCODE graph_resize(SCIP *scip, GRAPH *g, int ksize, int esize, int layers)
SCIP_RETCODE SCIPqueueCreate(SCIP_QUEUE **queue, int initsize, SCIP_Real sizefac)
SCIP_RETCODE graph_pc_presolInit(SCIP *scip, GRAPH *g)
int *RESTRICT mincut_head
void graph_trail(const GRAPH *g, int i)
#define SCIPallocBufferArray(scip, ptr, num)
void graph_get_csr(const GRAPH *g, int *RESTRICT edgearr, int *RESTRICT tailarr, int *RESTRICT start, int *nnewedges)
SCIP_Bool graph_sol_unreduced(SCIP *scip, const GRAPH *graph, const int *result)
void graph_pc_2trans(GRAPH *graph)
SCIP_RETCODE graph_pc_2rpc(SCIP *scip, GRAPH *graph)
void graph_get_NVET(const GRAPH *graph, int *nnodes, int *nedges, int *nterms)
#define BMScopyMemoryArray(ptr, source, num)
static void compEdgesObst(int coord, int grid_dim, int nobstacles, int *ncoords, int *currcoord, int *edgecosts, int *gridedgecount, int **coords, int **gridedges, int **obst_coords, char *inobstacle)
int *RESTRICT mincut_prev
includes various files containing graph methods used for Steiner tree problems
SCIP_RETCODE graph_init_history(SCIP *scip, GRAPH *graph)
void graph_edge_hide(GRAPH *g, int e)
SCIP_RETCODE graph_pc_contractEdge(SCIP *scip, GRAPH *g, int *solnode, int t, int s, int i)
int *RESTRICT mincut_numb
#define SCIPfreeMemory(scip, ptr)
#define STP_DELPSEUDO_MAXGRAD
void graph_free_historyDeep(SCIP *scip, GRAPH *p)
int *RESTRICT rootedgeprevs
SCIP_RETCODE graph_pc_2mw(SCIP *scip, GRAPH *graph, SCIP_Real *maxweights)
SCIP_RETCODE graph_sol_markPcancestors(SCIP *scip, IDX **pcancestors, const int *tails, const int *heads, int orgnnodes, STP_Bool *solnodemark, STP_Bool *soledgemark, int *solnodequeue, int *nsolnodes, int *nsoledges)
SCIP_Bool SCIPisLT(SCIP *scip, SCIP_Real val1, SCIP_Real val2)
SCIP_Bool SCIPisGT(SCIP *scip, SCIP_Real val1, SCIP_Real val2)
SCIP_RETCODE SCIPStpHeurTMPrunePc(SCIP *scip, const GRAPH *g, const SCIP_Real *cost, int *result, STP_Bool *connected)
shortest paths based primal heuristics for Steiner problems
SCIP_RETCODE graph_knot_contractLowdeg2High(SCIP *scip, GRAPH *g, int *solnode, int t, int s)
void graph_knot_chg(GRAPH *p, int node, int term)
#define SCIPallocMemory(scip, ptr)
SCIP_RETCODE graph_pc_getSap(SCIP *scip, GRAPH *graph, GRAPH **newgraph, SCIP_Real *offset)
int graph_edge_redirect(SCIP *scip, GRAPH *g, int eki, int k, int j, SCIP_Real cost, SCIP_Bool forcedelete)
SCIP_RETCODE graph_pc_contractEdgeAncestors(SCIP *scip, GRAPH *g, int t, int s, int ets)
void SCIPqueueFree(SCIP_QUEUE **queue)
static void removeEdge(GRAPH *g, int e)
struct Int_List_Node * parent
#define SCIP_CALL_ABORT(x)
SCIP_RETCODE SCIPStpHeurTMPrune(SCIP *scip, const GRAPH *g, const SCIP_Real *cost, int layer, int *result, STP_Bool *connected)
void graph_knot_del(SCIP *scip, GRAPH *g, int k, SCIP_Bool freeancestors)
void graph_edge_add(SCIP *scip, GRAPH *g, int tail, int head, SCIP_Real cost1, SCIP_Real cost2)
int *RESTRICT mincut_next
SCIP_RETCODE graph_pc_getRsap(SCIP *scip, GRAPH *graph, GRAPH **newgraph, int *rootcands, int nrootcands, int root)
void graph_pc_2orgcheck(GRAPH *graph)
SCIP_RETCODE graph_grid_coordinates(SCIP *scip, int **coords, int **nodecoords, int *ncoords, int node, int grid_dim)
SCIP_RETCODE graph_termsReachable(SCIP *scip, const GRAPH *g, SCIP_Bool *reachable)