48 for( i = 0; i < grid_dim; i++ )
51 for( j = i + 1; j < grid_dim; j++ )
53 tmp = tmp * ncoords[j];
56 number += (currcoord[i] + 1) * tmp;
58 number += currcoord[i] * tmp;
89 while( i < ncoords[coord] )
92 if( coord < grid_dim - 1 )
93 compEdgesObst(coord + 1, grid_dim, nobstacles, ncoords, currcoord, edgecosts, gridedgecount, coords, gridedges, obst_coords, inobstacle);
96 x = coords[0][currcoord[0]];
97 y = coords[1][currcoord[1]];
100 for( z = 0; z < nobstacles; z++ )
102 assert(obst_coords[0][z] < obst_coords[2][z]);
103 assert(obst_coords[1][z] < obst_coords[3][z]);
104 if( x > obst_coords[0][z] && x < obst_coords[2][z] &&
105 y > obst_coords[1][z] && y < obst_coords[3][z] )
108 inobstacle[node-1] =
TRUE;
112 for( j = 0; j < grid_dim; j++ )
114 if( currcoord[j] + 1 < ncoords[j] )
116 if( inobst ==
FALSE )
118 gridedges[0][*gridedgecount] = node;
119 gridedges[1][*gridedgecount] =
getNodeNumber(grid_dim, j, ncoords, currcoord);
120 edgecosts[*gridedgecount] = coords[j][currcoord[j] + 1] - coords[j][currcoord[j]];
145 while( i < ncoords[coord] )
147 currcoord[coord] = i;
148 if( coord < grid_dim - 1 )
149 compEdges(coord + 1, grid_dim, ncoords, currcoord, edgecosts, gridedgecount, coords, gridedges);
152 for( j = 0; j < grid_dim; j++ )
154 if( currcoord[j] + 1 < ncoords[j] )
156 gridedges[0][*gridedgecount] =
getNodeNumber(grid_dim, -1, ncoords, currcoord);
157 gridedges[1][*gridedgecount] =
getNodeNumber(grid_dim, j, ncoords, currcoord);
158 edgecosts[*gridedgecount] = coords[j][currcoord[j] + 1] - coords[j][currcoord[j]];
204 assert(coords !=
NULL);
205 assert(grid_dim > 1);
207 assert(grid_dim == 2);
208 scale_factor = pow(10.0, (
double) scale_order);
213 for( i = 0; i < grid_dim; i++ )
216 for( j = 0; j <
nterms; j++ )
217 termcoords[i][j] = coords[i][j];
224 for( i = 0; i < grid_dim; i++ )
229 for( j = 0; j < nterms - 1; j++ )
231 if( coords[i][j] == coords[i][j + 1] )
237 coords[i][j + 1 - shift] = coords[i][j + 1];
245 for( i = 0; i < grid_dim; i++ )
246 nnodes = nnodes * ncoords[i];
250 for( i = 0; i < grid_dim; i++ )
251 tmp = tmp + nnodes / ncoords[i];
253 nedges = grid_dim * nnodes - tmp;
260 for( i = 0; i <
nnodes; i++ )
261 inobstacle[i] =
FALSE;
262 compEdgesObst(0, grid_dim, nobstacles, ncoords, currcoord, edgecosts, &gridedgecount, coords, gridedges, obst_coords, inobstacle);
263 nedges = gridedgecount;
269 for( i = 0; i < grid_dim; i++ )
276 for( i = 0; i < nnodes; i++ )
280 for( i = 0; i < nedges; i++ )
283 if( inobstacle[gridedges[1][i] - 1] ==
FALSE )
285 cost = ((double) edgecosts[i]) / scale_factor;
286 graph_edge_add(scip, g, gridedges[0][i] - 1, gridedges[1][i] - 1, cost, cost);
291 for( i = 0; i <
nterms; i++ )
293 for( j = 0; j < grid_dim; j++ )
295 for( k = 0; k <= ncoords[j]; k++ )
297 assert(k != ncoords[j]);
298 if( coords[j][k] == termcoords[j][i] )
327 for( i = grid_dim - 1; i >= 0 ; --i )
363 assert(coords !=
NULL);
364 assert(grid_dim > 1);
367 scale_factor = pow(10.0, (
double) scale_order);
371 for( i = 0; i < grid_dim; i++ )
374 for( j = 0; j <
nterms; j++ )
375 termcoords[i][j] = coords[i][j];
381 for( i = 0; i < grid_dim; i++ )
386 for( j = 0; j < nterms - 1; j++ )
388 if( coords[i][j] == coords[i][j + 1] )
394 coords[i][j + 1 - shift] = coords[i][j + 1];
401 for( i = 0; i < grid_dim; i++ )
402 nnodes = nnodes * ncoords[i];
405 for( i = 0; i < grid_dim; i++ )
407 tmp = tmp + nnodes / ncoords[i];
410 nedges = grid_dim * nnodes - tmp;
419 compEdges(0, grid_dim, ncoords, currcoord, edgecosts, &gridedgecount, coords, gridedges);
427 for( i = 0; i < grid_dim; i++ )
434 for( i = 0; i < nnodes; i++ )
438 for( i = 0; i < nedges; i++ )
441 cost = (double) edgecosts[i] / scale_factor;
442 graph_edge_add(scip, g, gridedges[0][i] - 1, gridedges[1][i] - 1, cost, cost);
446 for( i = 0; i <
nterms; i++ )
448 for( j = 0; j < grid_dim; j++ )
450 for( k = 0; k <= ncoords[j]; k++ )
452 assert(k != ncoords[j]);
453 if( coords[j][k] == termcoords[j][i] )
476 for( i = grid_dim - 1; i >= 0 ; i-- )
499 assert(grid_dim > 1);
501 assert(coords !=
NULL);
502 assert(ncoords !=
NULL);
503 if( *nodecoords ==
NULL )
506 for( i = 0; i < grid_dim; i++ )
509 for( j = i; j < grid_dim; j++ )
510 tmp = tmp * ncoords[j];
513 tmp = tmp / ncoords[i];
515 (*nodecoords)[i] = coords[i][coord];
void graph_knot_chg(GRAPH *, int, int)
static volatile int nterms
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)
#define SCIPallocMemoryArray(scip, ptr, num)
enum SCIP_Retcode SCIP_RETCODE
includes various files containing graph methods used for Steiner tree problems
SCIP_RETCODE graph_pack(SCIP *, GRAPH *, GRAPH **, REDSOL *, SCIP_Bool)
#define SCIPfreeBufferArray(scip, ptr)
void graph_edge_add(SCIP *, GRAPH *, int, int, double, double)
void graph_knot_add(GRAPH *, int)
SCIP_RETCODE graph_obstgrid_create(SCIP *scip, GRAPH **gridgraph, int **coords, int **obst_coords, int nterms, int grid_dim, int nobstacles, int scale_order)
static void compEdges(int coord, int grid_dim, int *ncoords, int *currcoord, int *edgecosts, int *gridedgecount, int **coords, int **gridedges)
static int getNodeNumber(int grid_dim, int shiftcoord, int *ncoords, int *currcoord)
#define SCIPallocBufferArray(scip, ptr, num)
SCIP_RETCODE graph_grid_create(SCIP *scip, GRAPH **gridgraph, int **coords, int nterms, int grid_dim, int scale_order)
void SCIPsortInt(int *intarray, int len)
SCIP_RETCODE graph_init(SCIP *, GRAPH **, int, int, int)
SCIP_RETCODE graph_grid_coordinates(SCIP *scip, int **coords, int **nodecoords, int *ncoords, int node, int grid_dim)