本文整理汇总了C++中graph::removeEdge方法的典型用法代码示例。如果您正苦于以下问题:C++ graph::removeEdge方法的具体用法?C++ graph::removeEdge怎么用?C++ graph::removeEdge使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类graph
的用法示例。
在下文中一共展示了graph::removeEdge方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: kruskal
void kruskal(graph &g, graph &sf)
// from weighted graph g, set sf to minimum spanning forest
// uses a priority queue with edges sorted from large to min weight
// since top of queue is the back of underlying vector
// for every edge, add to sf, but if it creates cycle, then
// remove it and move to next edge
{
g.clearMark();
pqueue edges = getEdges(g);
while (!edges.empty())
{
edgepair pair = edges.top();
edges.pop();
// add both edges to create undirected edges
sf.addEdge(pair.i, pair.j, pair.cost);
sf.addEdge(pair.j, pair.i, pair.cost);
if (isCyclic(sf))
{
sf.removeEdge(pair.i, pair.j);
sf.removeEdge(pair.j, pair.i);
}
}
}
示例2: findSpanningForest
void findSpanningForest(graph &g, graph &sf)
// Create a graph sf that contains a spanning forest on the graph g.
{
if (isConnected(g) && !isCyclic(g))
{
sf = g;
}
else
{
// add nodes to sf
for (int i = 0; i < g.numNodes(); i++)
{
sf.addNode(g.getNode(i));
}
// build sf
for (int i = 0; i < g.numNodes(); i++)
{
for (int j = 0; j < g.numNodes(); j++)
{
if (g.isEdge(i, j) && !sf.isEdge(i, j))
{
sf.addEdge(i, j, g.getEdgeWeight(i, j));
sf.addEdge(j, i, g.getEdgeWeight(j, i));
if(isCyclic(sf))
{
sf.removeEdge(j, i);
sf.removeEdge(i, j);
} // if
} // if
} // for
} // for
} // else
} // findSpanningForest
示例3: findMSF
void findMSF(graph &g, graph &sf, int start)
// finds a minimum spanning tree in graph 'g'
{
priority_queue<edge, vector<edge>, CompareEdge> pq;
vector<int> lst = getNeighbors(start, g);
// build our priority queue
for (int i = 0; i < lst.size(); i++)
{
pq.push(g.getEdge(start, lst[i]));
g.mark(start, lst[i]);
}
// visit the start node
g.visit(start);
int src, dst, w;
edge top;
while (!pq.empty())
{
top = pq.top();
pq.pop();
src = top.getSource();
dst = top.getDest();
w = top.getWeight();
// add edges
if (!sf.isEdge(src, dst))
{
sf.addEdge(src, dst, w);
sf.addEdge(dst, src, w);
// delete edges if we make a cycle
if (isCyclic(sf))
{
sf.removeEdge(src, dst);
sf.removeEdge(dst, src);
}
else
{
g.visit(src);
lst = getNeighbors(dst, g);
for (int i = 0; i < lst.size(); i++)
{
if (!g.isMarked(dst, lst[i]))
{
pq.push(g.getEdge(dst, lst[i]));
g.mark(dst, lst[i]);
}
} // for
} // else
} // if
} // while
} // findMSF