|
|
Go to the documentation of this file. 34 #include "scip/misc.h" 57 assert(ksize < INT_MAX); 59 assert(esize < INT_MAX); 61 assert(layers < SHRT_MAX); 63 SCIP_CALL( SCIPallocMemory(scip, g) ); 86 SCIP_CALL( SCIPallocMemoryArray(scip, &(p-> locals), layers) ); 87 SCIP_CALL( SCIPallocMemoryArray(scip, &(p-> source), layers) ); 88 SCIP_CALL( SCIPallocMemoryArray(scip, &(p-> term), ksize) ); 89 SCIP_CALL( SCIPallocMemoryArray(scip, &(p-> mark), ksize) ); 90 SCIP_CALL( SCIPallocMemoryArray(scip, &(p-> grad), ksize) ); 91 SCIP_CALL( SCIPallocMemoryArray(scip, &(p-> inpbeg), ksize) ); 92 SCIP_CALL( SCIPallocMemoryArray(scip, &(p-> outbeg), ksize) ); 97 SCIP_CALL( SCIPallocMemoryArray(scip, &(p-> cost), esize) ); 98 SCIP_CALL( SCIPallocMemoryArray(scip, &(p-> tail), esize) ); 99 SCIP_CALL( SCIPallocMemoryArray(scip, &(p-> head), esize) ); 100 SCIP_CALL( SCIPallocMemoryArray(scip, &(p-> ieat), esize) ); 101 SCIP_CALL( SCIPallocMemoryArray(scip, &(p-> oeat), esize) ); 119 for( i = 0; i < p-> layers; i++ ) 141 assert(scip != NULL); 142 assert(graph != NULL); 147 nedges = graph-> edges; 149 SCIP_CALL( SCIPallocMemoryArray(scip, &(graph-> orgtail), nedges) ); 150 SCIP_CALL( SCIPallocMemoryArray(scip, &(graph-> orghead), nedges) ); 155 for( e = 0; e < nedges; e++ ) 157 orgtail[e] = graph-> tail[e]; 158 orghead[e] = graph-> head[e]; 161 SCIP_CALL( SCIPallocMemoryArray(scip, &(graph-> ancestors), nedges) ); 164 for( e = 0; e < nedges; e++ ) 166 SCIP_CALL( SCIPallocMemory(scip, &(ancestors[e])) ); 167 (ancestors)[e]->index = e; 168 (ancestors)[e]->parent = NULL; 175 int nnodes = graph-> knots; 176 SCIP_CALL( SCIPallocMemoryArray(scip, &(graph-> pcancestors), nnodes) ); 178 for( k = 0; k < nnodes; k++ ) 179 pcancestors[k] = NULL; 195 assert(scip != NULL); 197 assert((ksize < 0) || (ksize >= g-> knots)); 198 assert((esize < 0) || (esize >= g-> edges)); 199 assert((layers < 0) || (layers >= g-> layers)); 201 if( (layers > 0) && (layers != g-> layers) ) 203 SCIP_CALL( SCIPreallocMemoryArray(scip, &(g-> locals), layers) ); 204 SCIP_CALL( SCIPreallocMemoryArray(scip, &(g-> source), layers) ); 205 for( i = g-> layers; i < layers; i++ ) 212 if( (ksize > 0) && (ksize != g-> ksize) ) 215 SCIP_CALL( SCIPreallocMemoryArray(scip, &(g-> term), ksize) ); 216 SCIP_CALL( SCIPreallocMemoryArray(scip, &(g-> mark), ksize) ); 217 SCIP_CALL( SCIPreallocMemoryArray(scip, &(g-> grad), ksize) ); 218 SCIP_CALL( SCIPreallocMemoryArray(scip, &(g-> inpbeg), ksize) ); 219 SCIP_CALL( SCIPreallocMemoryArray(scip, &(g-> outbeg), ksize) ); 221 if( (esize > 0) && (esize != g-> esize) ) 224 SCIP_CALL( SCIPreallocMemoryArray(scip, &(g-> cost), esize) ); 225 SCIP_CALL( SCIPreallocMemoryArray(scip, &(g-> tail), esize) ); 226 SCIP_CALL( SCIPreallocMemoryArray(scip, &(g-> head), esize) ); 227 SCIP_CALL( SCIPreallocMemoryArray(scip, &(g-> ieat), esize) ); 228 SCIP_CALL( SCIPreallocMemoryArray(scip, &(g-> oeat), esize) ); 248 for( i = 0; i < grid_dim; i++ ) 251 for( j = i + 1; j < grid_dim; j++ ) 253 tmp = tmp * ncoords[j]; 255 if( shiftcoord == i ) 256 number += (currcoord[i] + 1) * tmp; 258 number += currcoord[i] * tmp; 288 while( i < ncoords[coord] ) 290 currcoord[coord] = i; 291 if( coord < grid_dim - 1 ) 292 compEdgesObst(coord + 1, grid_dim, nobstacles, ncoords, currcoord, edgecosts, gridedgecount, coords, gridedges, obst_coords, inobstacle); 295 x = coords[0][currcoord[0]]; 296 y = coords[1][currcoord[1]]; 299 for( z = 0; z < nobstacles; z++ ) 305 assert(obst_coords[0][z] < obst_coords[2][z]); 306 assert(obst_coords[1][z] < obst_coords[3][z]); 307 if( x > obst_coords[0][z] && x < obst_coords[2][z] && 308 y > obst_coords[1][z] && y < obst_coords[3][z] ) 311 inobstacle[node-1] = TRUE; 315 for( j = 0; j < grid_dim; j++ ) 317 if( currcoord[j] + 1 < ncoords[j] ) 319 if( inobst == FALSE ) 321 gridedges[0][*gridedgecount] = node; 322 gridedges[1][*gridedgecount] = getNodeNumber(grid_dim, j, ncoords, currcoord); 323 edgecosts[*gridedgecount] = coords[j][currcoord[j] + 1] - coords[j][currcoord[j]]; 349 while( i < ncoords[coord] ) 351 currcoord[coord] = i; 352 if( coord < grid_dim - 1 ) 353 compEdges(coord + 1, grid_dim, ncoords, currcoord, edgecosts, gridedgecount, coords, gridedges); 356 for( j = 0; j < grid_dim; j++ ) 358 if( currcoord[j] + 1 < ncoords[j] ) 360 gridedges[0][*gridedgecount] = getNodeNumber(grid_dim, -1, ncoords, currcoord); 361 gridedges[1][*gridedgecount] = getNodeNumber(grid_dim, j, ncoords, currcoord); 362 edgecosts[*gridedgecount] = coords[j][currcoord[j] + 1] - coords[j][currcoord[j]]; 403 assert(coords != NULL); 404 assert(grid_dim > 1); 406 assert(grid_dim == 2); 407 scale_factor = pow(10.0, ( double) scale_order); 410 SCIP_CALL( SCIPallocMemoryArray(scip, &termcoords, grid_dim) ); 412 for( i = 0; i < grid_dim; i++ ) 414 SCIP_CALL( SCIPallocMemoryArray(scip, &(termcoords[i]), nterms) ); 415 for( j = 0; j < nterms; j++ ) 416 termcoords[i][j] = coords[i][j]; 419 SCIP_CALL( SCIPallocMemoryArray(scip, &ncoords, grid_dim) ); 420 SCIP_CALL( SCIPallocMemoryArray(scip, &currcoord, grid_dim) ); 423 for( i = 0; i < grid_dim; i++ ) 426 SCIPsortInt(coords[i], nterms); 428 for( j = 0; j < nterms - 1; j++ ) 430 if( coords[i][j] == coords[i][j + 1] ) 436 coords[i][j + 1 - shift] = coords[i][j + 1]; 444 for( i = 0; i < grid_dim; i++ ) 445 nnodes = nnodes * ncoords[i]; 449 for( i = 0; i < grid_dim; i++ ) 450 tmp = tmp + nnodes / ncoords[i]; 452 nedges = grid_dim * nnodes - tmp; 453 SCIP_CALL( SCIPallocMemoryArray(scip, &gridedges, 2) ); 454 SCIP_CALL( SCIPallocMemoryArray(scip, &edgecosts, nedges) ); 455 SCIP_CALL( SCIPallocMemoryArray(scip, &(gridedges[0]), nedges) ); 456 SCIP_CALL( SCIPallocMemoryArray(scip, &(gridedges[1]), nedges) ); 457 SCIP_CALL( SCIPallocMemoryArray(scip, &(inobstacle), nnodes) ); 459 for( i = 0; i < nnodes; i++ ) 460 inobstacle[i] = FALSE; 461 compEdgesObst(0, grid_dim, nobstacles, ncoords, currcoord, edgecosts, &gridedgecount, coords, gridedges, obst_coords, inobstacle); 462 nedges = gridedgecount; 464 SCIP_CALL( graph_init(scip, gridgraph, nnodes, 2 * nedges, 1, 0) ); 467 SCIP_CALL( SCIPallocMemoryArray(scip, &(g-> grid_ncoords), grid_dim) ); 468 for( i = 0; i < grid_dim; i++ ) 475 for( i = 0; i < nnodes; i++ ) 479 for( i = 0; i < nedges; i++ ) 482 if( inobstacle[gridedges[1][i] - 1] == FALSE ) 484 cost = ((double) edgecosts[i]) / scale_factor; 485 graph_edge_add(scip, g, gridedges[0][i] - 1, gridedges[1][i] - 1, cost, cost); 490 for( i = 0; i < nterms; i++ ) 492 for( j = 0; j < grid_dim; j++ ) 494 for( k = 0; k <= ncoords[j]; k++ ) 496 assert(k != ncoords[j]); 497 if( coords[j][k] == termcoords[j][i] ) 518 for( i = 0; i < grid_dim; i++ ) 519 SCIPfreeMemoryArray(scip, &(termcoords[i])); 520 SCIPfreeMemoryArray(scip, &(gridedges[0])); 521 SCIPfreeMemoryArray(scip, &(gridedges[1])); 522 SCIPfreeMemoryArray(scip, &inobstacle); 523 SCIPfreeMemoryArray(scip, &termcoords); 524 SCIPfreeMemoryArray(scip, &edgecosts); 525 SCIPfreeMemoryArray(scip, &gridedges); 526 SCIPfreeMemoryArray(scip, &ncoords); 527 SCIPfreeMemoryArray(scip, &currcoord); 560 assert(coords != NULL); 561 assert(grid_dim > 1); 564 scale_factor = pow(10.0, ( double) scale_order); 567 SCIP_CALL( SCIPallocMemoryArray(scip, &termcoords, grid_dim) ); 568 for( i = 0; i < grid_dim; i++ ) 570 SCIP_CALL( SCIPallocMemoryArray(scip, &(termcoords[i]), nterms) ); 571 for( j = 0; j < nterms; j++ ) 572 termcoords[i][j] = coords[i][j]; 574 SCIP_CALL( SCIPallocMemoryArray(scip, &ncoords, grid_dim) ); 575 SCIP_CALL( SCIPallocMemoryArray(scip, &currcoord, grid_dim) ); 578 for( i = 0; i < grid_dim; i++ ) 581 SCIPsortInt(coords[i], nterms); 583 for( j = 0; j < nterms - 1; j++ ) 585 if( coords[i][j] == coords[i][j + 1] ) 591 coords[i][j + 1 - shift] = coords[i][j + 1]; 598 for( i = 0; i < grid_dim; i++ ) 599 nnodes = nnodes * ncoords[i]; 602 for( i = 0; i < grid_dim; i++ ) 604 tmp = tmp + nnodes / ncoords[i]; 607 nedges = grid_dim * nnodes - tmp; 609 SCIP_CALL( SCIPallocMemoryArray(scip, &gridedges, 2) ); 610 SCIP_CALL( SCIPallocMemoryArray(scip, &edgecosts, nedges) ); 611 SCIP_CALL( SCIPallocMemoryArray(scip, &(gridedges[0]), nedges) ); 612 SCIP_CALL( SCIPallocMemoryArray(scip, &(gridedges[1]), nedges) ); 616 compEdges(0, grid_dim, ncoords, currcoord, edgecosts, &gridedgecount, coords, gridedges); 619 SCIP_CALL( graph_init(scip, gridgraph, nnodes, 2 * nedges, 1, 0) ); 623 SCIP_CALL( SCIPallocMemoryArray(scip, &(g-> grid_ncoords), grid_dim) ); 624 for( i = 0; i < grid_dim; i++ ) 631 for( i = 0; i < nnodes; i++ ) 635 for( i = 0; i < nedges; i++ ) 638 cost = (double) edgecosts[i] / scale_factor; 639 graph_edge_add(scip, g, gridedges[0][i] - 1, gridedges[1][i] - 1, cost, cost); 643 for( i = 0; i < nterms; i++ ) 645 for( j = 0; j < grid_dim; j++ ) 647 for( k = 0; k <= ncoords[j]; k++ ) 649 assert(k != ncoords[j]); 650 if( coords[j][k] == termcoords[j][i] ) 664 printf( "root: (%d", termcoords[0][i]); 665 for( j = 1; j < grid_dim; j++ ) 666 printf( ", %d", termcoords[j][i]); 676 for( i = 0; i < grid_dim; i++ ) 677 SCIPfreeMemoryArray(scip, &(termcoords[i])); 679 SCIPfreeMemoryArray(scip, &(gridedges[0])); 680 SCIPfreeMemoryArray(scip, &(gridedges[1])); 681 SCIPfreeMemoryArray(scip, &termcoords); 682 SCIPfreeMemoryArray(scip, &edgecosts); 683 SCIPfreeMemoryArray(scip, &gridedges); 684 SCIPfreeMemoryArray(scip, &ncoords); 685 SCIPfreeMemoryArray(scip, &currcoord); 704 assert(grid_dim > 1); 706 assert(coords != NULL); 707 assert(ncoords != NULL); 708 if( *nodecoords == NULL ) 709 SCIP_CALL( SCIPallocMemoryArray(scip, nodecoords, grid_dim) ); 711 for( i = 0; i < grid_dim; i++ ) 714 for( j = i; j < grid_dim; j++ ) 715 tmp = tmp * ncoords[j]; 718 tmp = tmp / ncoords[i]; 720 (*nodecoords)[i] = coords[i][coord]; 737 assert(graph != NULL); 739 nnodes = graph-> knots; 740 nterms = graph-> terms; 741 prize = graph-> prize; 742 assert(prize != NULL); 743 assert(nnodes == graph-> ksize); 751 for( k = 0; k < nterms; ++k ) 758 for( k = 0; k < nnodes; ++k ) 764 node = nnodes + nterms; 770 assert(SCIPisGE(scip, prize[k], 0.0)); 783 assert((nterms + 1) == graph-> terms); 811 assert(graph != NULL); 812 assert(graph-> prize != NULL); 816 prize = graph-> prize; 817 nnodes = graph-> knots; 818 nterms = graph-> terms; 825 SCIP_CALL( graph_copy(scip, graph, newgraph) ); 829 SCIP_CALL( graph_resize(scip, (*newgraph), ((*newgraph)->ksize + 1), ((*newgraph)->esize + 2 * (nterms - 1)) , -1) ); 831 (*newgraph)->source[0] = graph-> source[0]; 832 root = (*newgraph)->source[0]; 835 pseudoroot = (*newgraph)->knots; 838 for( k = 0; k < nnodes; k++ ) 840 prizesum += prize[k]; 846 e = (*newgraph)->outbeg[root]; 850 enext = (*newgraph)->oeat[e]; 851 head = (*newgraph)->head[e]; 852 if( Is_term((*newgraph)->term[head]) ) 856 assert((*newgraph)->head[e] == head); 857 assert((*newgraph)->tail[e] == pseudoroot); 861 (*newgraph)->cost[e] = prizesum; 867 for( k = 0; k < nnodes; k++ ) 870 if( Is_pterm((*newgraph)->term[k]) ) 893 assert(graph != NULL); 894 assert(graph-> prize != NULL); 898 prize = graph-> prize; 899 nnodes = graph-> knots; 900 nterms = graph-> terms; 908 for( k = 0; k < nterms; ++k ) 912 pseudoroot = graph-> knots; 920 for( k = 0; k < nnodes; ++k ) 926 node = nnodes + nterms; 932 assert(SCIPisGE(scip, prize[k], 0.0)); 946 assert((nterms + 1) == graph-> terms); 967 assert(graph != NULL); 971 nnodes = graph-> knots; 972 nterms = graph-> terms; 973 prize = graph-> prize; 977 assert(prize != NULL); 978 assert(nnodes == graph-> ksize); 985 for( k = 0; k < nterms - 1; ++k ) 990 for( k = 0; k < nnodes; ++k ) 996 node = nnodes + nterms; 1001 assert(SCIPisGE(scip, prize[k], 0.0)); 1014 assert((nterms) == graph-> terms); 1023 SCIP_Real* maxweights 1031 assert(maxweights != NULL); 1032 assert(scip != NULL); 1033 assert(graph != NULL); 1034 assert(graph-> cost != NULL); 1035 assert(graph-> terms == 0); 1037 nnodes = graph-> knots; 1040 for( i = 0; i < nnodes; i++ ) 1042 if( SCIPisLT(scip, maxweights[i], 0.0) ) 1046 graph-> cost[e] -= maxweights[i]; 1056 for( i = 0; i < nnodes; i++ ) 1058 graph-> prize[i] = maxweights[i]; 1061 assert(SCIPisGE(scip, maxweights[i], 0.0)); 1066 assert(SCIPisLT(scip, maxweights[i], 0.0)); 1069 assert(nterms == graph-> terms); 1082 SCIP_Real* maxweights 1090 assert(maxweights != NULL); 1091 assert(scip != NULL); 1092 assert(graph != NULL); 1093 assert(graph-> cost != NULL); 1094 assert(graph-> terms == 0); 1096 nnodes = graph-> knots; 1099 for( i = 0; i < nnodes; i++ ) 1101 if( SCIPisLT(scip, maxweights[i], 0.0) ) 1105 graph-> cost[e] -= maxweights[i]; 1115 for( i = 0; i < nnodes; i++ ) 1117 graph-> prize[i] = maxweights[i]; 1120 assert(SCIPisGE(scip, maxweights[i], 0.0)); 1125 assert(SCIPisLT(scip, maxweights[i], 0.0)); 1128 assert(nterms == graph-> terms); 1146 assert(scip != NULL); 1149 SCIPfreeMemoryArray(scip, &(p-> locals)); 1150 SCIPfreeMemoryArray(scip, &(p-> source)); 1151 SCIPfreeMemoryArray(scip, &(p-> term)); 1152 SCIPfreeMemoryArray(scip, &(p-> mark)); 1153 SCIPfreeMemoryArray(scip, &(p-> grad)); 1154 SCIPfreeMemoryArray(scip, &(p-> inpbeg)); 1155 SCIPfreeMemoryArray(scip, &(p-> outbeg)); 1156 SCIPfreeMemoryArray(scip, &(p-> cost)); 1157 SCIPfreeMemoryArray(scip, &(p-> tail)); 1158 SCIPfreeMemoryArray(scip, &(p-> head)); 1159 SCIPfreeMemoryArray(scip, &(p-> ieat)); 1160 SCIPfreeMemoryArray(scip, &(p-> oeat)); 1162 if( p-> prize != NULL ) 1163 SCIPfreeMemoryArray(scip, &(p-> prize)); 1166 for( e = 0; e < p-> edges; e++ ) 1169 while( curr != NULL ) 1172 SCIPfreeMemory(scip, &(curr)); 1176 SCIPfreeMemoryArray(scip, &(p-> ancestors)); 1184 SCIPfreeMemoryArray(scip, &(p-> orgtail)); 1185 SCIPfreeMemoryArray(scip, &(p-> orghead)); 1188 while( curr != NULL ) 1191 SCIPfreeMemory(scip, &(curr)); 1200 while( curr != NULL ) 1203 SCIPfreeMemory(scip, &(curr)); 1213 SCIPfreeMemoryArray(scip, &(p-> maxdeg)); 1224 SCIPfreeMemory(scip, &(p)); 1259 BMScopyMemoryArray(g-> term, p-> term, ksize); 1260 BMScopyMemoryArray(g-> mark, p-> mark, ksize); 1261 BMScopyMemoryArray(g-> grad, p-> grad, ksize); 1264 BMScopyMemoryArray(g-> term, p-> term, ksize); 1281 assert(p-> maxdeg != NULL); 1282 SCIP_CALL( SCIPallocMemoryArray(scip, &(g-> maxdeg), g-> knots) ); 1326 for(i = 0; i < p-> knots; i++) 1328 (void)printf( "Knot %d, term=%d, grad=%d, inpbeg=%d, outbeg=%d\n", 1331 (void)fputc( '\n', stdout); 1333 for(i = 0; i < p-> edges; i++) 1335 (void)printf( "Edge %d, cost=%g, tail=%d, head=%d, ieat=%d, oeat=%d\n", 1338 (void)fputc( '\n', stdout); 1350 for(i = 0; i < p-> knots; i++) 1351 ident += (i + 1) * (p-> term[i] * 2 + p-> grad[i] * 3 1354 for(i = 0; i < p-> edges; i++) 1355 ident += (i + 1) * ((int)p-> cost[i] + p-> tail[i] 1358 (void)printf( "Graph Ident = %d\n", ident); 1369 assert(term < p->layers); 1394 assert(node < p->knots); 1395 assert(term < p->layers); 1397 if (term != p-> term[node]) 1404 p-> term[node] = term; 1422 typedef struct save_list 1432 IDX** ancestors = NULL; 1433 IDX** revancestors = NULL; 1434 IDX* tsancestors = NULL; 1435 IDX* stancestors = NULL; 1448 assert(t < p->knots); 1450 assert(s < p->knots); 1452 assert(scip != NULL); 1453 assert(p-> grad[s] > 0); 1454 assert(p-> grad[t] > 0); 1471 SCIP_CALL( SCIPallocBufferArray(scip, &slp, sgrad - 1) ); 1472 SCIP_CALL( SCIPallocBufferArray(scip, &ancestors, sgrad - 1) ); 1473 SCIP_CALL( SCIPallocBufferArray(scip, &revancestors, sgrad - 1) ); 1479 assert(p-> tail[es] == s); 1481 if( p-> head[es] != t ) 1483 assert(ancestors != NULL); 1484 assert(revancestors != NULL); 1485 assert(slp != NULL); 1487 ancestors[slc] = NULL; 1489 revancestors[slc] = NULL; 1492 slp[slc].mark = FALSE; 1494 slp[slc].knot = p-> head[es]; 1495 slp[slc].outcost = p-> cost[es]; 1499 assert(slc < sgrad); 1509 assert(slc == sgrad - 1); 1510 assert(tsancestors != NULL); 1511 assert(stancestors != NULL); 1514 for( i = 0; i < slc; i++ ) 1516 assert(slp != NULL); 1520 if( p-> head[et] == slp[i].knot ) 1535 if( SCIPisGT(scip, p-> cost[et], slp[i].outcost) ) 1538 assert(ancestors != NULL); 1539 assert(slp != NULL); 1542 p-> cost[et] = slp[i].outcost; 1548 assert(revancestors != NULL); 1549 assert(slp != NULL); 1552 p-> cost[anti] = slp[i].incost; 1558 for( i = 0; i < slc; i++ ) 1560 assert(slp != NULL); 1566 assert(ancestors != NULL); 1567 assert(revancestors != NULL); 1568 assert(ancestors[i] != NULL); 1569 assert(revancestors[i] != NULL); 1570 assert(slp != NULL); 1582 p-> cost[es] = slp[i].outcost; 1595 p-> cost[es] = slp[i].incost; 1619 assert(ancestors != NULL); 1620 assert(revancestors != NULL); 1621 for( i = 0; i < slc; i++ ) 1626 SCIPfreeBufferArray(scip, &revancestors); 1627 SCIPfreeBufferArray(scip, &ancestors); 1628 SCIPfreeBufferArray(scip, &slp); 1630 assert(p-> grad[s] == 0); 1647 assert(scip != NULL); 1653 g-> prize[i] -= cost; 1663 assert(j != g-> source[0]); 1675 assert(SCIPisEQ(scip, g-> prize[i], g-> cost[e])); 1690 assert(scip != NULL); 1695 if( g-> head[ets] == s ) 1706 IDX* etsancestors = NULL; 1727 assert(j != g-> source[0]); 1728 assert(!g-> mark[j]); 1739 assert(SCIPisEQ(scip, g-> prize[s], g-> cost[e])); 1750 assert(g-> grad[s] == 0); 1752 SCIPdebugMessage( "PC contract: %d, %d \n", t, s); 1797 if( (g-> tail[e] == k) && (g-> head[e] == j) ) 1804 if( SCIPisGT(scip, g-> cost[e], cost) ) 1891 assert(SCIPisGE(scip, cost1, 0.0) || SCIPisEQ(scip, cost1, ( double) UNKNOWN)); 1892 assert(SCIPisGE(scip, cost2, 0.0) || SCIPisEQ(scip, cost2, ( double) UNKNOWN)); 1894 assert(tail < g->knots); 1896 assert(head < g->knots); 1905 if( cost1 != UNKNOWN ) 1916 if( cost2 != UNKNOWN ) 1939 assert(e < g->edges); 1944 if( g-> inpbeg[head] == e ) 1953 if( g-> outbeg[tail] == e ) 1969 SCIP_Bool freeancestors 1974 assert(e < g->edges); 1978 assert(scip != NULL); 1985 assert(g-> head[e] == g-> tail[e + 1]); 1986 assert(g-> tail[e] == g-> head[e + 1]); 2022 assert(e < g->edges); 2028 assert(g-> head[e] == g-> tail[e + 1]); 2029 assert(g-> tail[e] == g-> head[e + 1]); 2068 for( e = 0; e < g-> edges; e++ ) 2090 assert(g-> head[e] == tail); 2091 assert(g-> tail[e] == head); 2113 assert(scip != NULL); 2114 assert(graph != NULL); 2117 nnodes = graph-> knots; 2119 for( k = 0; k < nnodes; k++ ) 2121 graph-> mark[k] = (graph-> grad[k] > 0); 2151 assert(scip != NULL); 2152 assert(graph != NULL); 2155 nnodes = graph-> knots; 2157 for( k = 0; k < nnodes; k++ ) 2159 graph-> mark[k] = (graph-> grad[k] > 0); 2175 const char* msg1 = "Knots: %d Edges: %d Terminals: %d\n"; 2187 printf( "Packing graph: "); 2188 printf( "Packing graph: \n "); 2189 new = malloc(( size_t)p-> knots * sizeof( new[0])); 2191 assert( new != NULL); 2195 for(i = 0; i < p-> knots; i++) 2214 printf( " graph vanished!\n"); 2221 for(i = 0; i < p-> edges; i++) 2257 for( i = 0; i < edges; i++ ) 2262 for(i = 0; i < p->knots; i++) 2268 (void)fputc( 'k', stdout); 2269 (void)fflush(stdout); 2272 if( p-> grad[i] > 0 ) 2278 for( i = 0; i < p-> edges; i += 2 ) 2281 if ((i % 1000) == 0) 2283 (void)fputc( 'e', stdout); 2284 (void)fflush(stdout); 2300 assert( new[p-> tail[i]] >= 0); 2301 assert( new[p-> head[i]] >= 0); 2313 for(l = 0; l < q-> layers; l++) 2325 for(l = 0; l < q-> layers; l++) 2328 for(i = 0; i < q->knots; i++) 2333 assert(q-> source[0] >= 0); 2349 const char* msg1 = "Nodes: %d Edges: %d Terminals: %d\n"; 2358 assert(scip != NULL); 2359 assert(graph != NULL); 2365 SCIP_CALL( SCIPallocBufferArray(scip, & new, g-> knots) ); 2368 printf( "Reduced graph: "); 2371 for( i = 0; i < g-> knots; i++ ) 2374 if( g-> grad[i] > 0 ) 2383 SCIPfreeBufferArray(scip, & new); 2386 printf( " graph vanished!\n"); 2392 for( i = 0; i < g-> edges; i++ ) 2401 assert(nnodes > 1 || nedges == 0); 2428 SCIP_CALL( SCIPallocMemoryArray(scip, &(q-> ancestors), nedges) ); 2432 SCIP_CALL( SCIPallocMemoryArray(scip, &(q-> prize), nnodes) ); 2435 for( i = 0; i < nedges; i++ ) 2440 SCIP_CALL( SCIPallocMemoryArray(scip, &(q-> pcancestors), nedges) ); 2441 for( i = 0; i < nnodes; i++ ) 2447 for( i = 0; i < g-> knots; i++ ) 2450 if( g-> grad[i] > 0 ) 2468 for( i = 0; i < g-> edges; i += 2 ) 2483 assert( new[g-> tail[i]] >= 0); 2484 assert( new[g-> head[i]] >= 0); 2497 SCIPfreeBufferArray(scip, & new); 2502 assert(q-> source[0] >= 0); 2519 assert(i < p->knots); 2536 const char* fehler1 = "*** Graph Validation Error: Head invalid, Knot %d, Edge %d, Tail=%d, Head=%d\n"; 2537 const char* fehler2 = "*** Graph Validation Error: Tail invalid, Knot %d, Edge %d, Tail=%d, Head=%d\n"; 2538 const char* fehler3 = "*** Graph Validation Error: Source invalid, Layer %d, Source %d, Terminal %d\n"; 2539 const char* fehler4 = "*** Graph Validation Error: FREE invalid, Edge %d/%d\n"; 2540 const char* fehler5 = "*** Graph Validation Error: Anti invalid, Edge %d/%d, Tail=%d/%d, Head=%d/%d\n"; 2541 const char* fehler6 = "*** Graph Validation Error: Knot %d with Grad 0 has Edges\n"; 2542 const char* fehler7 = "*** Graph Validation Error: Knot %d not connected\n"; 2544 const char* fehler8 = "*** Graph Validation Error: Wrong locals count, Layer %d, count is %d, should be %d\n"; 2546 const char* fehler9 = "*** Graph Validation Error: Wrong Terminal count, count is %d, should be %d\n"; 2554 locals = malloc(( size_t)p-> layers * sizeof( int)); 2555 assert(locals != NULL); 2556 for( l = 0; l < p-> layers; l++ ) 2557 locals[l] = p-> locals[l]; 2563 for( k = 0; k < p-> knots; k++ ) 2568 locals[p-> term[k]]--; 2573 if( p-> head[e] != k ) 2577 return(( void)fprintf(stderr, fehler1, k, e, p-> tail[e], p-> head[e]), FALSE); 2580 if( p-> tail[e] != k ) 2584 return(( void)fprintf(stderr, fehler2, k, e, p-> tail[e], p-> head[e]), FALSE); 2587 return(( void)fprintf(stderr, fehler9, p-> terms, p-> terms - terms), FALSE); 2589 for( l = 0; l < p-> layers; l++ ) 2592 if( locals[l] != 0 ) 2593 return(( void)fprintf(stderr, fehler8, 2599 return(( void)fprintf(stderr, fehler3, 2605 for( e = 0; e < p-> edges; e += 2 ) 2613 return(( void)fprintf(stderr, fehler4, e, e + 1), FALSE); 2616 return(( void)fprintf(stderr, fehler5, 2617 e, e + 1, p-> head[e], p-> tail[e + 1], 2621 for( k = 0; k < p-> knots; k++ ) 2626 for( k = 0; k < p-> knots; k++ ) 2628 if( (p-> grad[k] == 0) 2630 return(( void)fprintf(stderr, fehler6, k), FALSE); 2633 return(( void)fprintf(stderr, fehler7, k), FALSE); 2654 assert(graph != NULL); 2655 assert(result != NULL); 2656 nnodes = graph-> knots; 2660 SCIP_CALL_ABORT( SCIPallocBufferArray(scip, &terminal, nnodes) ); 2661 for( i = 0; i < nnodes; i++ ) 2662 terminal[i] = FALSE; 2664 SCIP_CALL_ABORT( SCIPqueueCreate(&queue, nnodes, 2.0) ); 2666 SCIP_CALL_ABORT( SCIPqueueInsert(queue, &root) ); 2668 terminal[root] = TRUE; 2670 while( !SCIPqueueIsEmpty(queue) ) 2672 pnode = (SCIPqueueRemove(queue)); 2681 assert(!terminal[i]); 2685 SCIP_CALL_ABORT( SCIPqueueInsert(queue, &graph-> head[e]) ); 2691 if( termcount != graph-> terms ) 2693 for( i = 0; i < nnodes; i++ ) 2695 SCIPdebugMessage( "not reached, node: %d\n", i); 2696 SCIPdebugMessage( "a: %d, b: %d: \n", termcount, graph-> terms); 2699 SCIPfreeBufferArray(scip, &terminal); 2700 SCIPqueueFree(&queue); 2702 return (termcount == graph-> terms); 2722 assert(graph != NULL); 2723 assert(cost != NULL); 2724 nnodes = graph-> knots; 2728 SCIP_CALL_ABORT( SCIPallocBufferArray(scip, &terminal, nnodes) ); 2729 SCIP_CALL_ABORT( SCIPallocBufferArray(scip, &reached, nnodes) ); 2730 for( i = 0; i < nnodes; i++ ) 2732 terminal[i] = FALSE; 2736 SCIP_CALL_ABORT( SCIPqueueCreate(&queue, nnodes, 2.0) ); 2738 SCIP_CALL_ABORT( SCIPqueueInsert(queue, &root) ); 2740 terminal[root] = TRUE; 2741 reached[root] = TRUE; 2742 while( !SCIPqueueIsEmpty(queue) ) 2744 pnode = (SCIPqueueRemove(queue)); 2747 if( SCIPisLT(scip, cost[e], BLOCKED) && !reached[graph-> head[e]] ) 2753 assert(!terminal[i]); 2757 SCIP_CALL_ABORT( SCIPqueueInsert(queue, &graph-> head[e]) ); 2761 SCIPfreeBufferArray(scip, &reached); 2762 SCIPfreeBufferArray(scip, &terminal); 2763 SCIPqueueFree(&queue); 2764 if (termcount != graph-> terms) 2766 for( i = 0; i < nnodes; i++ ) 2768 printf( "not reached, node: %d\n", i); 2772 return (termcount == graph-> terms);
SCIP_RETCODE graph_MwcsToSap(SCIP *scip, GRAPH *graph, SCIP_Real *maxweights)
SCIP_RETCODE graph_copy(SCIP *scip, GRAPH *orgraph, GRAPH **copygraph)
SCIP_RETCODE graph_knot_contract(SCIP *scip, GRAPH *p, int t, int s)
SCIP_RETCODE graph_grid_create(SCIP *scip, GRAPH **gridgraph, int **coords, int nterms, int grid_dim, int scale_order)
void graph_ident(const GRAPH *p)
SCIP_RETCODE pcgraphorg(SCIP *scip, GRAPH *graph)
void graph_uncover(GRAPH *g)
static int getNodeNumber(int grid_dim, int shiftcoord, int *ncoords, int *currcoord)
char graph_valid2(SCIP *scip, const GRAPH *graph, SCIP_Real *cost)
SCIP_RETCODE graph_PcSapCopy(SCIP *scip, GRAPH *graph, GRAPH **newgraph, SCIP_Real *offset)
SCIP_RETCODE graph_maxweight_transform(SCIP *scip, GRAPH *graph, SCIP_Real *maxweights)
SCIP_RETCODE graph_pack(SCIP *scip, GRAPH *graph, GRAPH **newgraph, SCIP_Bool verbose)
#define STP_OBSTACLES_GRID
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)
void SCIPintListNodeFree(SCIP *scip, IDX **node)
void graph_show(const GRAPH *p)
void graph_knot_add(GRAPH *p, int term)
miscellaneous methods used for solving Steiner problems
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)
SCIP_RETCODE graph_init(SCIP *scip, GRAPH **g, int ksize, int esize, int layers, int flags)
void graph_edge_del(SCIP *scip, GRAPH *g, int e, SCIP_Bool freeancestors)
#define STP_MAX_NODE_WEIGHT
SCIP_RETCODE graph_resize(SCIP *scip, GRAPH *g, int ksize, int esize, int layers)
SCIP_RETCODE graph_prize_transform(SCIP *scip, GRAPH *graph)
SCIP_RETCODE SCIPintListNodeAppendCopy(SCIP *scip, IDX **node1, IDX *node2)
#define STP_PRIZE_COLLECTING
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)
SCIP_RETCODE graph_knot_contractpc(SCIP *scip, GRAPH *g, int t, int s, int i)
static void edge_remove(GRAPH *g, int e)
includes various files containing graph methods used for Steiner problems
SCIP_RETCODE graph_init_history(SCIP *scip, GRAPH *graph)
void graph_edge_hide(GRAPH *g, int e)
int graph_valid(const GRAPH *p)
SCIP_RETCODE pcgraphtrans(SCIP *scip, GRAPH *graph)
SCIP_Bool graph_sol_valid(SCIP *scip, const GRAPH *graph, int *result)
void graph_trail(const GRAPH *p, int i)
void graph_free(SCIP *scip, GRAPH *p, SCIP_Bool final)
void graph_flags(GRAPH *p, int flags)
#define STP_ROOTED_PRIZE_COLLECTING
void prize_subtract(SCIP *scip, GRAPH *g, SCIP_Real cost, int i)
void graph_knot_chg(GRAPH *p, int node, int term)
int graph_edge_redirect(SCIP *scip, GRAPH *g, int eki, int k, int j, SCIP_Real cost)
SCIP_RETCODE graph_rootprize_transform(SCIP *scip, GRAPH *graph)
struct Int_List_Node * parent
SCIP_RETCODE graph_PcToSap(SCIP *scip, GRAPH *graph)
void graph_edge_add(SCIP *scip, GRAPH *g, int tail, int head, SCIP_Real cost1, SCIP_Real cost2)
SCIP_RETCODE graph_grid_coordinates(SCIP *scip, int **coords, int **nodecoords, int *ncoords, int node, int grid_dim)
|