我正在将 Lemon C++ 库用于图形,我需要做的是找到两个节点之间的所有路径。我能够找到一条路径(最短),但我需要所有这些。
有没有办法用柠檬做到这一点?
// Create the graph
ListDigraph g;
ListDigraph::Node a = g.addNode();
ListDigraph::Node b = g.addNode();
ListDigraph::Node c = g.addNode();
ListDigraph::Node d = g.addNode();
ListDigraph::Node e = g.addNode();
ListDigraph::Arc a_b = g.addArc(a, b);
ListDigraph::Arc b_c = g.addArc(b, c);
ListDigraph::Arc c_d = g.addArc(c, d);
ListDigraph::Arc a_e = g.addArc(a, e);
ListDigraph::Arc e_d = g.addArc(e, d);
// Assign labels to edges and arcs
ListDigraph::NodeMap<std::string> nodeValues(g);
nodeValues[a] = "a";
nodeValues[b] = "b";
nodeValues[c] = "c";
nodeValues[d] = "d";
nodeValues[e] = "e";
ListDigraph::ArcMap<std::string> arcValues(g);
arcValues[a_b] = "a->b";
arcValues[b_c] = "b->c";
arcValues[c_d] = "c->d";
arcValues[a_e] = "a->e";
arcValues[e_d] = "e->d";
// Find the shortest path
Bfs<ListDigraph> bfs(g);
bfs.init();
bfs.addSource(a);
bfs.start();
if (bfs.reached(c))
{
std::cout << nodeValues[c];
ListDigraph::Node prev = bfs.predNode(c);
while (prev != INVALID)
{
std::cout << "<-" << nodeValues[prev];
prev = bfs.predNode(prev);
}
std::cout << std::endl;
}
=> c<-b<-a