36 #define NODE_ID_UNDEFINED -2 72 assert(nodepos < nnodes_max);
74 return (nodepos * nnodes_max);
87 assert(nnodes_curr >= 0);
88 assert(nnodes_curr <= nnodes_max);
89 assert(nodepos < nnodes_curr);
91 return (nodepos * nnodes_max + nnodes_curr);
103 const int*
const nodeids = cgraph->
nodeids;
108 for( nodepos = cgraph->
nnodes_curr - 1; nodepos >= 0; nodepos-- )
110 if( nodeids[nodepos] == nodeid )
114 assert(nodepos >= 0);
128 const int*
const nodeids = cgraph->
nodeids;
130 assert(edgecosts && nodeids);
131 assert(nnodes_max > 1);
132 assert(nnodes_curr <= nnodes_max);
133 assert(nnodes_curr >= 0);
137 for(
int i = 0; i < nnodes_curr - 1; i++ )
146 for(
int i = 0; i < nnodes_curr; i++ )
155 for(
int i = 0; i < nnodes_curr; i++ )
166 for(
int i = 0; i < nnodes_curr; i++ )
170 for(
int j = 0; j < nnodes_curr; j++ )
173 const SCIP_Real cost_ij = edgecosts[start_i + j];
174 const SCIP_Real cost_ji = edgecosts[start_j + i];
178 if( !
EQ(cost_ji, cost_ij) )
180 SCIPdebugMessage(
"wrong edge costs between %d and %d (%f != %f) \n", i, j, cost_ij, cost_ji);
188 const int start = nnodes_curr > 0 ?
getEdgeEnd(nnodes_curr - 1, nnodes_curr, nnodes_max) : 0;
190 for(
int i = start; i < nnodes_max * nnodes_max; i++ )
198 for(
int i = nnodes_curr; i < nnodes_max; i++ )
220 assert(cgraph && ids);
229 for(
int i = 0; i < nids; i++ )
231 if( cgraph->
nodeids[i] != ids[i] )
253 for(
int i = 0; i <
nnodes; i++ )
274 assert(scip && cgraph);
275 assert(maxnnodes > 1);
291 for(
int i = 0; i < maxnnodes * maxnnodes; i++ )
294 for(
int i = 0; i < maxnnodes; i++ )
297 for(
int i = 0; i < maxnnodes + 1; i++ )
317 assert(scip && cgraph);
339 for(
int i = 0; i < nnodes_curr; i++ )
383 assert(nodepos >= 0 && nodepos < nnodes_curr);
384 assert(cgraph->
nodeids[nodepos] == nodeid);
386 for(
int i = start, j = 0; i != start + nnodes_curr; i++, j++ )
389 assert(
GE(newcost, 0.0));
392 if( newcost < edgecosts[i] )
393 edgecosts[i] = newcost;
396 for(
int i = 0; i < nnodes_curr; i++ )
402 assert(
GE(newcost, 0.0));
404 if( newcost < edgecosts[pos] )
405 edgecosts[pos] = newcost;
424 const int nnodes_curr_new = nodepos_new + 1;
426 const int start_new =
getEdgeStart(nodepos_new, nnodes_max);
429 assert(edgecosts && cgraph->
nodeids);
432 assert(nodepos_new < nnodes_max);
437 for(
int i = start_new; i < start_new + nodepos_new; i++ )
442 for(
int i = 0; i < nodepos_new; i++ )
444 const int end =
getEdgeEnd(i, nodepos_new, nnodes_max);
450 lastedge =
getEdgeEnd(nodepos_new, nnodes_curr_new, nnodes_max) - 1;
451 assert(lastedge >= 0 && lastedge == start_new + nodepos_new);
455 cgraph->
nodeids[nodepos_new] = nodeid;
469 const int nodepos_top = nnodes_curr - 1;
473 assert(nodepos_new >= 0 && nodepos_new <= nodepos_top);
475 if( nodepos_new != nodepos_top )
478 const int start_new =
getEdgeStart(nodepos_new, nnodes_max);
479 const int start_top =
getEdgeStart(nodepos_top, nnodes_max);
482 for(
int i = 0; i < nodepos_top; i++ )
484 if( i != nodepos_new )
486 const int edgepos =
getEdgeStart(i, nnodes_max) + nodepos_new;
488 assert(
EQ(edgecosts[edgepos], edgecosts[start_new + i]));
490 edgecosts[edgepos] = edgecosts[start_top + i];
494 assert(start_new + nodepos_top < start_top);
499 edgecosts[start_new + nodepos_new] =
FARAWAY;
544 for(
int i = last_start; i < last_end; i++ )
564 const int*
const nodeids = cgraph->
nodeids;
569 for( nodepos = cgraph->
nnodes_curr - 1; nodepos >= 0; nodepos-- )
571 if( nodeids[nodepos] == nodeid )
575 assert(nodepos >= 0);
576 assert(0 &&
"not fully implemented yet");
603 assert(0 &&
"not yet implemented");
621 assert(edgecosts && preds);
633 for(
int i = 0; i <
nnodes; i++ )
636 const int pred = preds[i];
641 assert(pred >= 0 && pred < nnodes);
644 obj += edgecosts[start + pred];
668 assert(scip && cmst);
669 assert(maxnnodes > 1);
697 assert(scip && cmst);
727 assert(edgecosts && preds && dist && dheap && state);
729 assert(nnodes_curr <= cmst->nnodes_max);
730 assert(mstroot >= 0 && mstroot < nnodes_curr);
732 for(
int i = 0; i < nnodes_curr; i++ )
736 for(
int i = 0; i < nnodes_curr; i++ )
749 assert(dheap->
size == 1);
752 while( dheap->
size > 0 )
759 assert(k >= 0 && k < nnodes_curr);
762 for(
int m = 0; m < nnodes_curr; m++ )
766 const SCIP_Real ecost = edgecosts[start + m];
768 if( ecost < dist[m] )
784 for(
int i = 0; i < nnodes_curr; i++ )
787 assert(preds[i] != -1 || i == mstroot);
SCIP_RETCODE cmst_init(SCIP *scip, CMST **cmst, int maxnnodes)
static int getNnodesCurr(const CGRAPH *cgraph)
SCIP_Bool cgraph_valid(const CGRAPH *cgraph)
#define SCIPfreeMemoryArray(scip, ptr)
SCIP_Bool * node_has_adjcosts
#define SCIPallocMemoryArray(scip, ptr, num)
void cgraph_clean(CGRAPH *cgraph)
includes complete graph methods, in particular for MST calculation
void cgraph_node_append(CGRAPH *cgraph, int nodeid)
SCIP_Real cgraph_edge_getCost(const CGRAPH *cgraph, int nodeid_tail, int nodeid_head)
enum SCIP_Retcode SCIP_RETCODE
void cgraph_node_deleteTop(CGRAPH *cgraph)
static int getPositionFromId(const CGRAPH *cgraph, int nodeid)
SCIP_Bool graph_heap_isClean(const DHEAP *)
static int getEdgeEnd(int nodepos, int nnodes_curr, int nnodes_max)
SCIP_Bool cgraph_node_hasAdjCosts(const CGRAPH *cgraph, int nodepos)
SCIP_Bool cmst_isSync(const CGRAPH *cgraph, const CMST *cmst)
#define CGRAPH_EDGECOST_UNDEFINED_VALUE
SCIP_Bool cgraph_idsInSync(const CGRAPH *cgraph, const int *ids, int nids)
void cmst_free(SCIP *scip, CMST **cmst)
static int getNnodesMax(const CGRAPH *cgraph)
void cgraph_free(SCIP *scip, CGRAPH **cgraph)
void graph_heap_free(SCIP *, SCIP_Bool, SCIP_Bool, DHEAP **)
SCIP_RETCODE cgraph_init(SCIP *scip, CGRAPH **cgraph, int maxnnodes)
static int getEdgeStart(int nodepos, int nnodes_max)
#define BMScopyMemoryArray(ptr, source, num)
#define SCIPfreeMemory(scip, ptr)
SCIP_Bool cgraph_isEmpty(const CGRAPH *cgraph)
void cgraph_node_repositionTop(CGRAPH *cgraph, int nodeid_new)
void cgraph_node_delete(CGRAPH *cgraph, int nodeid)
SCIP_Bool cgraph_idIsContained(const CGRAPH *cgraph, int id)
int cgraph_node_getTopId(const CGRAPH *cgraph)
SCIP_RETCODE graph_heap_create(SCIP *, int, int *, DENTRY *, DHEAP **)
int graph_heap_deleteMinReturnNode(DHEAP *)
#define SCIPallocMemory(scip, ptr)
void cgraph_node_applyMinAdjCosts(CGRAPH *cgraph, int nodepos, int nodeid)
void graph_heap_correct(int, SCIP_Real, DHEAP *)
#define NODE_ID_UNDEFINED
void cmst_computeMst(const CGRAPH *cgraph, int mstroot, CMST *cmst)