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];
1487 assert(p->
grad[head] == 2);
1488 assert(head != root);
1508 p->
prize[root] = 0.0;
1526 assert(graph !=
NULL);
1529 nterms = graph->
terms;
1530 prize = graph->
prize;
1531 assert(prize !=
NULL);
1532 assert(nnodes == graph->
ksize);
1540 for(
int k = 0; k <
nterms; ++k )
1544 root = graph->
knots;
1552 for(
int k = 0; k <
nnodes; ++k )
1558 const int node = nnodes +
nterms;
1564 assert(
SCIPisGE(scip, prize[k], 0.0));
1586 assert((nterms + 1) == graph->
terms);
1608 assert(graph !=
NULL);
1612 nnodes = graph->
knots;
1613 nterms = graph->
terms;
1614 prize = graph->
prize;
1618 assert(prize !=
NULL);
1619 assert(nnodes == graph->
ksize);
1626 for(
int k = 0; k < nterms - 1; ++k )
1635 for(
int k = 0; k <
nnodes; ++k )
1646 assert(
SCIPisGE(scip, prize[k], 0.0));
1669 assert(nterms == graph->
terms);
1687 assert(maxweights !=
NULL);
1688 assert(scip !=
NULL);
1689 assert(graph !=
NULL);
1691 assert(graph->
terms == 0);
1693 nnodes = graph->
knots;
1696 for(
int i = 0; i <
nnodes; i++ )
1698 if(
SCIPisLT(scip, maxweights[i], 0.0) )
1701 graph->
cost[e] -= maxweights[i];
1703 else if(
SCIPisGT(scip, maxweights[i], 0.0) )
1710 for(
int i = 0; i <
nnodes; i++ )
1712 graph->
prize[i] = maxweights[i];
1715 assert(
SCIPisGE(scip, maxweights[i], 0.0));
1720 assert(
SCIPisLE(scip, maxweights[i], 0.0));
1723 assert(nterms == graph->
terms);
1750 assert(scip !=
NULL);
1751 assert(graph !=
NULL);
1758 nnodes = graph->
knots;
1759 maxweights = graph->
prize;
1761 assert(maxweights !=
NULL);
1764 for( i = 0; i <
nnodes; i++ )
1766 if(
SCIPisLT(scip, maxweights[i], 0.0) )
1769 graph->
cost[e] -= maxweights[i];
1774 if( graph->
grad[i] > maxgrad )
1777 maxgrad = graph->
grad[i];
1782 else if(
SCIPisGT(scip, maxweights[i], 0.0) )
1790 assert(graph->
terms == (npterms + nrterms));
1800 for(
int k = 0; k < npterms; k++ )
1808 for(
int k = 0; k <
nnodes; ++k )
1814 const int node = nnodes + i;
1820 assert(
SCIPisGE(scip, maxweights[k], 0.0));
1836 assert(i == npterms);
1856 const int root = graph->
source;
1858 assert(scip !=
NULL);
1859 assert(graph !=
NULL);
1869 const int enext = graph->
oeat[e];
1873 const int k = graph->
head[e];
1876 assert(graph->
grad[k] == 2);
1879 if( graph->
head[e2] != root )
1882 p = graph->
head[e2];
1898 if( graph->
grad[p] > maxgrad )
1901 maxgrad = graph->
grad[p];
1915 const int enext = graph->
oeat[e];
1916 const int k = graph->
head[e];
1949 const int grad = g->
grad[i];
1952 assert(scip !=
NULL);
1965 const int i1 = g->
head[e];
1972 assert(g->
grad[i] == 0);
1998 assert(scip !=
NULL);
2004 g->
prize[i] -= cost;
2014 assert(!g->
mark[j]);
2041 assert(scip !=
NULL);
2043 assert(newprize > 0.0);
2048 g->
prize[i] = newprize;
2058 assert(!g->
mark[j]);
2067 g->
cost[e] = newprize;
2084 assert(scip !=
NULL);
2089 if( g->
head[ets] == s )
2113 assert(scip !=
NULL);
2118 if( g->
head[ets] == s )
2143 assert(!g->
mark[j]);
2167 assert(g->
grad[s] == 0);
2203 assert(term < p->layers);
2226 assert(node < p->knots);
2227 assert(term < p->layers);
2229 if( term != p->
term[node] )
2234 p->
term[node] = term;
2251 assert(k < g->knots);
2279 const int degree = g->
grad[vertex];
2281 assert(scip !=
NULL);
2282 assert(success !=
NULL);
2284 assert(vertex >= 0);
2285 assert(vertex < g->knots);
2302 nspareedges = degree;
2314 incedge[edgecount] = e;
2315 ecostreal[edgecount] = g->
cost[e];
2316 ecost[edgecount] = edgecosts[e];
2317 ecostrev[edgecount] = edgecosts[
flipedge(e)];
2319 adjvert[edgecount++] = g->
head[e];
2324 assert(edgecount == degree);
2329 for(
int i = 0; i < degree - 1; i++ )
2331 const int adjvertex = adjvert[i];
2332 for(
int j = i + 1; j < degree; j++ )
2335 const SCIP_Bool cutoff =
cutoffEdge(scip, cutoffs, cutoffsrev, ecost, ecostrev, i, j, edgecount);
2337 assert(edgecount < STP_DELPSEUDO_MAXNEDGES);
2347 if( g->
head[e] == adjvert[j] )
2350 neigbedge[edgecount - 1] = e;
2357 if( ++replacecount > nspareedges )
2365 for(
int i = 0; i < degree; i++ )
2367 const int e = incedge[i];
2368 ancestors[i] =
NULL;
2369 revancestors[i] =
NULL;
2378 for(
int i = 0; i < degree - 1; i++ )
2380 for(
int j = i + 1; j < degree; j++ )
2382 const SCIP_Bool cutoff =
cutoffEdge(scip, cutoffs, cutoffsrev, ecost, ecostrev, i, j, edgecount);
2384 assert(edgecount < STP_DELPSEUDO_MAXNEDGES);
2391 const SCIP_Real newcost = ecostreal[i] + ecostreal[j];
2392 const int oldedge = incedge[(replacecount == nspareedges) ? replacecount - 1 : replacecount];
2394 const int oldtail = g->
tail[oldedge];
2395 const int oldhead = g->
head[oldedge];
2397 assert(replacecount <= nspareedges);
2398 assert(replacecount < nspareedges || neigbedge[edgecount - 1] >= 0);
2400 SCIP_CALL(
graph_edge_reinsert(scip, g, oldedge, adjvert[i], adjvert[j], newcost, ancestors[i], ancestors[j], revancestors[i], revancestors[j],
FALSE));
2403 if( neigbedge[edgecount - 1] < 0 )
2408 assert(oldtail == g->
tail[oldedge]);
2409 assert(oldhead == g->
head[oldedge]);
2419 for(
int i = 0; i < degree; i++ )
2456 assert(t < p->knots);
2458 assert(s < p->knots);
2460 assert(scip !=
NULL);
2461 assert(p->
grad[s] > 0);
2462 assert(p->
grad[t] > 0);
2466 if( solnode !=
NULL )
2496 assert(p->
tail[es] == s);
2498 if( p->
head[es] != t )
2500 assert(ancestors !=
NULL);
2501 assert(revancestors !=
NULL);
2502 assert(mark !=
NULL);
2503 assert(incost !=
NULL);
2504 assert(outcost !=
NULL);
2505 assert(edge !=
NULL);
2506 assert(knot !=
NULL);
2508 ancestors[slc] =
NULL;
2510 revancestors[slc] =
NULL;
2515 knot[slc] = p->
head[es];
2516 outcost[slc] = p->
cost[es];
2520 assert(slc < sgrad);
2524 assert(slc == sgrad - 1);
2527 for( i = 0; i < slc; i++ )
2529 const int ihead = knot[i];
2536 for( et = p->
outbeg[t]; et >= 0; et = p->
oeat[et] )
2537 if( p->
head[et] == ihead )
2542 for( et = p->
inpbeg[ihead]; et >= 0; et = p->
ieat[et] )
2543 if( p->
tail[et] == t )
2559 if( p->
cost[et] > outcost[i] )
2562 assert(ancestors !=
NULL);
2565 p->
cost[et] = outcost[i];
2571 assert(revancestors !=
NULL);
2572 assert(incost !=
NULL);
2574 p->
cost[anti] = incost[i];
2580 for( i = 0; i < slc; i++ )
2582 assert(mark !=
NULL);
2588 assert(ancestors !=
NULL);
2589 assert(revancestors !=
NULL);
2590 assert(ancestors[i] !=
NULL);
2591 assert(revancestors[i] !=
NULL);
2592 assert(knot !=
NULL);
2593 assert(outcost !=
NULL);
2594 assert(incost !=
NULL);
2606 p->
cost[es] = outcost[i];
2619 p->
cost[es] = incost[i];
2640 assert(ancestors !=
NULL);
2641 assert(revancestors !=
NULL);
2642 for( i = 0; i < slc; i++ )
2655 assert(p->
grad[s] == 0);
2698 assert(g->
tail[e] == k);
2700 if( g->
head[e] == j )
2799 assert(
SCIPisGE(scip, cost2, 0.0) ||
SCIPisEQ(scip, cost2, (
double) UNKNOWN));
2801 assert(tail < g->knots);
2803 assert(head < g->knots);
2812 if( cost1 != UNKNOWN )
2823 if( cost2 != UNKNOWN )
2846 assert(e < g->edges);
2850 assert(scip !=
NULL);
2857 assert(g->
head[e] == g->
tail[e + 1]);
2858 assert(g->
tail[e] == g->
head[e + 1]);
2894 assert(e < g->edges);
2900 assert(g->
head[e] == g->
tail[e + 1]);
2901 assert(g->
tail[e] == g->
head[e + 1]);
2937 const int t = g->
tail[e];
2938 const int h = g->
head[e];
2939 printf(
"e: %d %d->%d (%d->%d) \n", e, t, h, g->
term[t], g->
term[h]);
2951 int*
const gmark = g->
mark;
2955 assert(scip !=
NULL);
2957 assert(result !=
NULL);
2960 if( g->
grad[newroot] == 0 )
2963 for(
int k = 0; k <
nnodes; k++ )
2968 gmark[newroot] =
TRUE;
2970 queue[size++] = newroot;
2975 const int node = queue[--size];
2980 const int head = g->
head[
a];
2990 queue[size++] = head;
2998 for(
int k = 0; k <
nnodes; k++ )
3016 const int node = g->
tail[
a];
3017 if( gmark[node] && node != newroot )
3027 const int node = g->
tail[
a];
3028 if( node == newroot )
3052 const int nedges = graph->
edges;
3054 assert(scip !=
NULL);
3055 assert(graph !=
NULL);
3056 assert(result !=
NULL);
3058 for(
int i = 0; i < nedges; i++ )
3080 assert(scip !=
NULL);
3081 assert(graph !=
NULL);
3082 assert(result !=
NULL);
3085 nnodes = graph->
knots;
3097 assert(reached !=
NULL);
3099 for(
int i = 0; i <
nnodes; i++ )
3106 reached[root] =
TRUE;
3107 queue[size++] = root;
3111 const int node = queue[--size];
3117 const int i = graph->
head[e];
3145 if(termcount != graph->
terms)
3147 printf(
"termcount %d graph->terms %d \n", termcount, graph->
terms);
3148 printf(
"root %d \n", root);
3150 for(
int i = 0; i < nnodes && 0; i++ )
3154 printf(
"fail %d grad %d\n", i, graph->
grad[i]);
3157 printf(
"tail %d %d \n", graph->
tail[e], graph->
term[graph->
tail[e]]);
3166 return (termcount == graph->
terms);
3180 assert(solnode !=
NULL);
3184 while( curr !=
NULL )
3206 for( e = 0; e < nedges; e++ )
3216 const GRAPH* transgraph,
3217 const GRAPH* orggraph,
3218 const int* transsoledge,
3227 const int transnedges = transgraph->
edges;
3228 const int transnnodes = transgraph->
knots;
3229 const int orgnnodes = orggraph->
knots;
3232 assert(transgraph !=
NULL && orggraph !=
NULL && transsoledge !=
NULL && orgsoledge !=
NULL);
3242 for(
int k = 0; k < transnnodes; k++ )
3243 transnodearr[k] =
FALSE;
3245 for(
int e = 0; e < transnedges; e++ )
3246 if( transsoledge[e] ==
CONNECT )
3248 transnodearr[transgraph->
tail[e]] =
TRUE;
3249 transnodearr[transgraph->
head[e]] =
TRUE;
3253 for(
int k = 0; k < orgnnodes; k++ )
3254 orgnodearr[k] =
FALSE;
3256 for(
int e = 0; e < transnedges; e++ )
3257 if( transsoledge[e] ==
CONNECT )
3269 for(
int e = 0; e < orggraph->
edges; e++ )
3303 int nedges = (nsoledges !=
NULL)? *nsoledges : 0;
3307 assert(scip !=
NULL && tails !=
NULL && heads !=
NULL && pcancestors !=
NULL && solnodemark !=
NULL);
3309 if( solnodequeue !=
NULL )
3310 queue = solnodequeue;
3314 if( nsolnodes ==
NULL )
3316 assert(solnodequeue ==
NULL);
3318 for(
int k = 0; k < orgnnodes; k++ )
3319 if( solnodemark[k] )
3320 queue[nnodes++] = k;
3324 nnodes = *nsolnodes;
3325 assert(solnodequeue !=
NULL);
3331 while( qend != qstart )
3335 assert(qstart < qend);
3338 for( ; k < qend; k++ )
3340 const int ancestornode = queue[k];
3342 assert(solnodemark[ancestornode]);
3344 for(
IDX* curr = pcancestors[ancestornode]; curr !=
NULL; curr = curr->parent )
3346 const int ancestoredge = curr->index;
3347 assert(tails[ancestoredge] < orgnnodes && heads[ancestoredge] < orgnnodes);
3349 if( soledgemark !=
NULL && !soledgemark[ancestoredge] )
3351 soledgemark[ancestoredge] =
TRUE;
3354 if( !solnodemark[tails[ancestoredge]] )
3356 solnodemark[tails[ancestoredge]] =
TRUE;
3357 queue[nnodes++] = tails[ancestoredge];
3359 if( !solnodemark[heads[ancestoredge]] )
3361 solnodemark[heads[ancestoredge]] =
TRUE;
3362 queue[nnodes++] = heads[ancestoredge];
3369 if( nsolnodes !=
NULL )
3372 if( nsoledges !=
NULL )
3373 *nsoledges = nedges;
3375 if( solnodequeue ==
NULL )
3394 assert(graph !=
NULL);
3396 vorg = graph->
knots;
3398 for(
int k = 0; k < vorg; k++ )
3400 if( graph->
grad[k] > 0 )
3403 e += graph->
grad[k];
3429 assert(tailarr !=
NULL);
3430 assert(edgearr !=
NULL);
3431 assert(start !=
NULL);
3433 for(
int k = 0; k <
nnodes; k++ )
3439 tailarr[i++] = g->
tail[e] + 1;
3455 const int nedges = g->
edges;
3460 assert(nedgesorg % 2 == 0);
3462 printf(
"orgedes %d \n", nedgesorg);
3466 for(
int e = 0; e < nedgesorg / 2; e++ )
3469 for(
int e = 0; e < nedges; e += 2 )
3472 assert(curr->index >= 0 && curr->index / 2 < nedgesorg / 2);
3473 childcount[curr->index / 2]++;
3478 for(
int e = 0; e < nedgesorg / 2; e++ )
3479 if( childcount[e] > 1 )
3482 printf(
"nconflicts %d \n", nconflicts);
3502 assert(ksize < INT_MAX);
3504 assert(esize < INT_MAX);
3506 assert(layers < SHRT_MAX);
3583 assert(scip !=
NULL);
3584 assert(graph !=
NULL);
3588 nedges = graph->
edges;
3598 for(
int e = 0; e < nedges; e++ )
3600 orgtail[e] = tail[e];
3601 orghead[e] = head[e];
3612 for(
int k = 0; k <
nnodes; k++ )
3613 pcancestors[k] =
NULL;
3620 for(
int e = 0; e < nedges; e++ )
3623 (ancestors)[e]->index = e;
3624 (ancestors)[e]->parent =
NULL;
3639 assert(scip !=
NULL);
3641 assert((ksize < 0) || (ksize >= g->
knots));
3642 assert((esize < 0) || (esize >= g->
edges));
3643 assert((layers < 0) || (layers >= g->
layers));
3645 if( (layers > 0) && (layers != g->
layers) )
3648 if( (ksize > 0) && (ksize != g->
ksize) )
3658 if( (esize > 0) && (esize != g->
esize) )
3682 assert(scip !=
NULL);
3683 assert(graph !=
NULL);
3709 for(
int i = p->
grid_dim - 1; i >= 0; i-- )
3743 const int nedges = p->
edges;
3745 for(
int e = nedges - 1; e >= 0; e-- )
3748 while( curr !=
NULL )
3767 assert(scip !=
NULL);
3777 while( curr !=
NULL )
3795 while( curr !=
NULL )
3807 const GRAPH* orgraph,
3811 GRAPH* g = copygraph;
3812 const GRAPH* p = orgraph;
3813 const int ksize = p->
ksize;
3814 const int esize = p->
esize;
3816 assert(scip !=
NULL);
3817 assert(orgraph !=
NULL);
3818 assert(copygraph !=
NULL);
3819 assert(ksize == g->
ksize && ksize > 0);
3820 assert(esize == g->
esize && esize >= 0);
3854 for(
int k = 0; k < g->
knots; k++ )
3870 for(
int k = 0; k < g->
knots; k++ )
3881 for(
int k = 0; k < p->
grid_dim; k++ )
3898 const GRAPH* orgraph,
3902 const GRAPH* p = orgraph;
3920 for(i = 0; i < p->
knots; i++)
3922 (void)printf(
"Knot %d, term=%d, grad=%d, inpbeg=%d, outbeg=%d\n",
3925 (void)fputc(
'\n', stdout);
3927 for(i = 0; i < p->
edges; i++)
3929 (void)printf(
"Edge %d, cost=%g, tail=%d, head=%d, ieat=%d, oeat=%d\n",
3932 (void)fputc(
'\n', stdout);
3947 for( e = 0; e < g->
edges; e++ )
3969 assert(g->
head[e] == tail);
3970 assert(g->
tail[e] == head);
4002 assert(scip !=
NULL);
4003 assert(graph !=
NULL);
4009 oldnnodes = g->
knots;
4010 oldnedges = g->
edges;
4014 printf(
"Reduced graph: ");
4017 for(
int i = 0; i < oldnnodes; i++ )
4020 if( g->
grad[i] > 0 )
4032 printf(
" graph vanished!\n");
4038 for(
int i = 0; i < oldnedges; i++ )
4047 assert(nnodes > 1 || nedges == 0);
4094 for( i = 0; i < oldnnodes; i++ )
4103 assert(g->
grad[i] == 2);
4108 for(
int i = 0; i < oldnnodes; i++ )
4111 if( g->
grad[i] > 0 )
4133 for(
int i = 0; i < oldnedges; i += 2 )
4148 assert(
new[g->
tail[i]] >= 0);
4149 assert(
new[g->
head[i]] >= 0);
4158 assert(
new[g->
tail[i]] < nnodes &&
new[g->
head[i]] < nnodes);
4177 printf(
"Nodes: %d Edges: %d Terminals: %d\n", q->
knots, q->
edges, q->
terms);
4193 assert(i < g->knots);
4207 if( g->
grad[i] == 0 )
4244 int*
const gmark = g->
mark;
4246 assert(scip !=
NULL);
4249 assert(i < g->knots);
4262 if( g->
grad[i] == 0 )
4270 stackarr[stacksize++] = i;
4273 while( stacksize != 0 )
4275 node = stackarr[--stacksize];
4285 stackarr[stacksize++] = head;
4304 assert(reachable !=
NULL);
4306 for(
int k = 0; k <
nnodes; k++ )
4313 for(
int k = 0; k <
nnodes; k++ )
4328 const char* fehler1 =
"*** Graph invalid: Head invalid, Knot %d, Edge %d, Tail=%d, Head=%d\n";
4329 const char* fehler2 =
"*** Graph invalid: Tail invalid, Knot %d, Edge %d, Tail=%d, Head=%d\n";
4330 const char* fehler3 =
"*** Graph invalid: Source invalid, Layer %d, Source %d, Terminal %d\n";
4331 const char* fehler4 =
"*** Graph invalid: FREE invalid, Edge %d/%d\n";
4332 const char* fehler5 =
"*** Graph invalid: Anti invalid, Edge %d/%d, Tail=%d/%d, Head=%d/%d\n";
4333 const char* fehler6 =
"*** Graph invalid: Knot %d with Grad 0 has Edges\n";
4334 const char* fehler7 =
"*** Graph invalid: Knot %d not connected\n";
4335 const char* fehler9 =
"*** Graph invalid: Wrong Terminal count, count is %d, should be %d\n";
4349 for( k = 0; k <
nnodes; k++ )
4356 if( g->
head[e] != k )
4360 return((
void)fprintf(stderr, fehler1, k, e, g->
tail[e], g->
head[e]),
FALSE);
4363 if( g->
tail[e] != k )
4367 return((
void)fprintf(stderr, fehler2, k, e, g->
tail[e], g->
head[e]),
FALSE);
4370 return((
void)fprintf(stderr, fehler9, g->
terms, g->
terms - nterms),
FALSE);
4375 return((
void)fprintf(stderr, fehler3,
4378 for( e = 0; e < nedges; e += 2 )
4386 return((
void)fprintf(stderr, fehler4, e, e + 1),
FALSE);
4389 return((
void)fprintf(stderr, fehler5,
4390 e, e + 1, g->
head[e], g->
tail[e + 1],
4394 for( k = 0; k <
nnodes; k++ )
4399 for( k = 0; k <
nnodes; k++ )
4401 if( (g->
grad[k] == 0)
4403 return((
void)fprintf(stderr, fehler6, k),
FALSE);
4407 return((
void)fprintf(stderr, fehler7, k),
FALSE);
4413 const int root = g->
source;
4421 for( k = 0; k <
nnodes; k++ )
4423 if( k == root || (rooted && g->
term2edge[k] < 0) )
4433 if( g->
grad[k] != 2 )
4440 if( g->
tail[e] == root )
4451 pterm = g->
head[e2];
4462 assert(pterm != root);
4481 if( nterms != npterms || nterms != g->
terms - 1 )
4490 for( k = 0; k <
nnodes; k++ )
4503 for( k = 0; k <
nnodes; k++ )
SCIP_RETCODE graph_sol_getOrg(SCIP *scip, const GRAPH *transgraph, const GRAPH *orggraph, const int *transsoledge, int *orgsoledge)
#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)
#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 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 SCIPisGE(SCIP *scip, SCIP_Real val1, SCIP_Real val2)
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)
SCIP_RETCODE SCIPqueueInsert(SCIP_QUEUE *queue, void *elem)
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)
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
SCIP_Bool SCIPisEQ(SCIP *scip, SCIP_Real val1, SCIP_Real val2)
#define SCIPfreeBufferArray(scip, ptr)
SCIP_Bool SCIPqueueIsEmpty(SCIP_QUEUE *queue)
#define SCIPallocBlockMemory(scip, ptr)
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)
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)
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)
SCIP_Bool SCIPisLT(SCIP *scip, SCIP_Real val1, SCIP_Real val2)
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)
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)
void SCIPqueueFree(SCIP_QUEUE **queue)
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)
SCIP_Bool SCIPisGT(SCIP *scip, SCIP_Real val1, SCIP_Real val2)
SCIP_RETCODE SCIPqueueCreate(SCIP_QUEUE **queue, int initsize, SCIP_Real sizefac)
#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_RETCODE SCIPStpHeurTMPrunePc(SCIP *scip, const GRAPH *g, const SCIP_Real *cost, int *result, STP_Bool *connected)
shortest paths based primal heuristics for Steiner problems
void SCIPsortInt(int *intarray, int len)
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)
void * SCIPqueueRemove(SCIP_QUEUE *queue)
#define SCIPallocMemory(scip, ptr)
SCIP_Bool SCIPisZero(SCIP *scip, SCIP_Real val)
SCIP_Bool SCIPisLE(SCIP *scip, SCIP_Real val1, SCIP_Real val2)
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)
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)