133 int nnodes = graph_->nnodes;
134 int nedges = graph_->nedges;
137 for(
int e = 0; e < nedges; ++e)
142 hasFixedEdges =
true;
148 if( nnodes < 3 || hasFixedEdges )
165 for( i = 0; i <
nnodes; i++ )
166 assert( i == nodes[i].
id );
176 for( i = 0; i <
nnodes; i++ )
181 for(
int u = 0; u < nnodes - 2 && !foundThreeCircle; ++u)
183 for(
int v = u + 1; v < nnodes - 1 && !foundThreeCircle; ++v)
189 for(
int w = v + 1; (w <
nnodes) && !foundThreeCircle; ++w)
198 foundThreeCircle =
true;
217 if( !foundThreeCircle )
230 int subtourlength = 3;
231 for(; subtourlength <
nnodes; subtourlength++ )
236 for( i = 0; i <
nnodes; i++)
238 if( (maxmin < dist[i] && dist[i] != DBL_MAX) || (maxmin == dist[i] && !subtour[i]) )
244 if(newnodeindex == -1)
246 couldNotInsert =
TRUE;
255 while( edge != NULL )
262 assert(edge != NULL);
263 assert(subtour[edge->
adjac->
id]);
269 startnode = edge->
adjac;
275 edges[1] = successor[node->
id];
276 edges[2] =
findEdge(nodes, edges[1]->adjac->id, newnodeindex);
277 assert( edges[2] != NULL );
285 for( i = 0; i < 3; i++ )
286 bestedges[i] = edges[i];
288 node = edges[1]->
adjac;
289 edges[0] = edges[2]->
back;
291 while( node != startnode);
293 if( minval == DBL_MAX )
295 couldNotInsert =
TRUE;
301 assert(bestedges[0]->adjac->id == bestedges[1]->
back->
adjac->
id);
302 assert(bestedges[1]->adjac->id == bestedges[2]->
back->
adjac->
id);
303 assert(bestedges[2]->adjac->id == bestedges[0]->
back->
adjac->
id);
304 assert(subtour[bestedges[0]->adjac->id]);
305 assert(subtour[bestedges[1]->adjac->id]);
306 assert(bestedges[2]->adjac->id == newnodeindex);
307 assert(!subtour[newnodeindex]);
310 successor[bestedges[0]->
adjac->
id] = bestedges[0]->
back;
311 successor[bestedges[2]->adjac->id] = bestedges[2]->
back;
312 dist[newnodeindex] = 0.0;
313 subtour[newnodeindex] =
true;
329 for( i = 0; i <
nnodes; i++ )
SCIP_DECL_HEURFREE(HeurFarthestInsert::scip_free)
SCIP_Real SCIPvarGetLbGlobal(SCIP_VAR *var)
void updateDistances(GRAPHNODE *nodes, double *dist, int idx)
SCIP_DECL_HEUREXITSOL(HeurFarthestInsert::scip_exitsol)
generator for global cuts in undirected graphs
#define SCIPfreeBufferArray(scip, ptr)
farthest insert - combinatorial heuristic for TSP
SCIP_Real SCIPvarGetUbGlobal(SCIP_VAR *var)
struct GraphEdge * first_edge
C++ wrapper classes for SCIP.
C++ problem data for TSP.
#define SCIPallocBufferArray(scip, ptr, num)
SCIP_RETCODE SCIPsetSolVal(SCIP *scip, SCIP_SOL *sol, SCIP_VAR *var, SCIP_Real val)
SCIP_DECL_HEURCLONE(scip::ObjCloneable *HeurFarthestInsert::clone)
SCIP_RETCODE SCIPfreeSol(SCIP *scip, SCIP_SOL **sol)
SCIP_RETCODE SCIPtrySol(SCIP *scip, SCIP_SOL *sol, SCIP_Bool printreason, SCIP_Bool completely, SCIP_Bool checkbounds, SCIP_Bool checkintegrality, SCIP_Bool checklprows, SCIP_Bool *stored)
scip::ObjProbData * SCIPgetObjProbData(SCIP *scip)
SCIP_DECL_HEURINIT(HeurFarthestInsert::scip_init)
SCIP_DECL_HEUREXEC(HeurFarthestInsert::scip_exec)
SCIP_DECL_HEURINITSOL(HeurFarthestInsert::scip_initsol)
Definition of base class for all clonable classes.
SCIP_DECL_HEUREXIT(HeurFarthestInsert::scip_exit)
GRAPHEDGE * findEdge(GRAPHNODE *nodes, int index1, int index2)
void capture_graph(GRAPH *gr)
void release_graph(GRAPH **gr)
#define BMSclearMemoryArray(ptr, num)
SCIP_RETCODE SCIPcreateSol(SCIP *scip, SCIP_SOL **sol, SCIP_HEUR *heur)