本文整理汇总了C++中ListGraph::erase方法的典型用法代码示例。如果您正苦于以下问题:C++ ListGraph::erase方法的具体用法?C++ ListGraph::erase怎么用?C++ ListGraph::erase使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ListGraph
的用法示例。
在下文中一共展示了ListGraph::erase方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: some
/**
second relaxation of tsp
idea:
remove some (random) node
take mst
add shortest two edges of the removed node
*/
int TSPRelaxation::mstOnSubgraph()
{
// create a copy of the graph
ListGraph g;
ListGraph::EdgeMap<int> weight(g);
ListGraph::NodeMap<ListGraph::Node> nodemap(g);
GraphCopy<ListGraph, ListGraph> copy(this->g, g);
copy.edgeMap(this->weight, weight).nodeCrossRef(nodemap).run();
// remove a random node
// removed will contain the node of this->g corresponding to the removed one afterwards
int del = rand() % countNodes(g);
ListGraph::Node removed;
for (ListGraph::NodeIt n(g); n != INVALID; ++n)
{
if (del == 0)
{
removed = nodemap[n];
g.erase(n);
break;
}
del--;
}
// calculate mst
MST mst(g, weight);
int w = mst.prim();
// search for two shortest edges incident to the removed node
int mins[] = {numeric_limits<int>::max(), numeric_limits<int>::max()};
for (ListGraph::IncEdgeIt e(this->g, removed); e != INVALID; ++e)
{ // iterate over all incident nodes
if (this->weight[e] < mins[0])
{ // shortest found yet
mins[1] = mins[0];
mins[0] = this->weight[e];
}
// 2nd-shortest
else if (this->weight[e] < mins[1]) mins[1] = this->weight[e];
}
return w + mins[0] + mins[1];
}