forked from ZigRazor/CXXGraph
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdijkstra_example.cpp
More file actions
48 lines (38 loc) · 1.54 KB
/
dijkstra_example.cpp
File metadata and controls
48 lines (38 loc) · 1.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#include <CXXGraph/CXXGraph.hpp>
#include <iostream>
#include <memory>
using std::make_shared;
int main() {
CXXGraph::Node<int> node0("0", 0);
CXXGraph::Node<int> node1("1", 1);
CXXGraph::Node<int> node2("2", 2);
CXXGraph::Node<int> node3("3", 3);
CXXGraph::DirectedWeightedEdge<int> edge1("1", node1, node2, 2.0);
CXXGraph::DirectedWeightedEdge<int> edge2("2", node2, node3, 2.0);
CXXGraph::DirectedWeightedEdge<int> edge3("3", node0, node1, 2.0);
CXXGraph::DirectedWeightedEdge<int> edge4("4", node0, node3, 1.0);
CXXGraph::T_EdgeSet<int> edgeSet;
edgeSet.insert(make_shared<CXXGraph::DirectedWeightedEdge<int>>(edge1));
edgeSet.insert(make_shared<CXXGraph::DirectedWeightedEdge<int>>(edge2));
edgeSet.insert(make_shared<CXXGraph::DirectedWeightedEdge<int>>(edge3));
edgeSet.insert(make_shared<CXXGraph::DirectedWeightedEdge<int>>(edge4));
// Can print out the edges for debugging
std::cout << edge1 << "\n";
std::cout << edge2 << "\n";
std::cout << edge3 << "\n";
std::cout << edge4 << "\n";
CXXGraph::Graph<int> graph(edgeSet);
auto res = graph.dijkstra(node0, node3);
std::cout << "Dijkstra Result: " << res.result << "\n";
for (auto& name : res.path) {
std::cout << "->" << name << std::endl;
}
std::cout << " ======= CP ====== " << std::endl;
res = graph.criticalpath_deterministic(node0, node3);
std::cout << "CP Result: " << res.result << "\n";
std::cout << "CP path size: " << res.path.size() << "\n";
for (auto& name : res.path) {
std::cout << "->" << name << std::endl;
}
return 0;
}