94 |-------------------------------------------------------------------------------- /docs/docs/examples/example-basics/shortest-path.md: -------------------------------------------------------------------------------- 1 | # Shortest Path Example 2 | 3 | The shortest path algorithm implemented in `graaf::algorithm::get_shortest_path` can be used to compute the shortest 4 | path between any two vertices in a graph. 5 | 6 | Consider the following graph: 7 | 8 |95 |
97 |96 |
9 |13 | 14 | In order to compute the shortest path between *vertex 0* and *vertex 2*, we call: 15 | 16 | ```c++ 17 | const auto maybe_shortest_path{bfs_shortest_path(graph, start, target)}; 18 | 19 | // Assert that we found a path at all 20 | assert(maybe_shortest_path.has_value()); 21 | auto shortest_path{maybe_shortest_path.value()}; 22 | ``` 23 | 24 | ## Visualizing the shortest path 25 | 26 | If we want to visualize the shortest path on the graph, we can create our own vertex and edge writers. These writers 27 | then determine the vertex and edge attributes based on whether the vertex or edge is contained in the shortest path. 28 | 29 | First, we create a datastructure of all edges on the shortest path such that we can query it in the edge writer: 30 | 31 | ```c++ 32 | // We use a set here for O(1) time contains checks 33 | std::unordered_set10 |
12 |11 |
69 |-------------------------------------------------------------------------------- /docs/docs/examples/example-basics/transport-example.md: -------------------------------------------------------------------------------- 1 | # Network Example 2 | 3 | This example showcases graph traversal and shortest path algorithms in an undirected graph network. As such, it 4 | demonstrates the usage of the following classes and algorithms: 5 | 6 | - The undirected_graph implemented in `graaf::undirected_graph` 7 | - The shortest path algorithm implemented in `graaf::algorithm::get_shortest_path` 8 | - The graph traversal implemented in `graaf::algorithm::graph_traversal` 9 | 10 | Using the following graph: 11 | 12 |70 |
72 |71 |
13 |17 | 18 | Custom vertex and edge. In order to use Dijkstra, we should provide the get_weight() function for the edge. 19 | 20 | ```cpp 21 | struct station { 22 | std::string name{}; 23 | }; 24 | 25 | struct railroad : public graaf::weighted_edge14 |
16 |15 |
58 |62 | 63 | Result of weighted shortest path, chosen edges are coloured red 64 |59 |
61 |60 |
65 |69 | 70 | ```cpp 71 | void print_shortest_path(const graaf::undirected_graph66 |
68 |67 |
102 |106 | 107 | ### Graph example usage 108 | 109 | First code block: traversing a weighted graph for the shortest path (Dijkstra) and printing the result to *.dot file. 110 | Second code block: traversing an unweighted graph for the shortest path and printing the result to *.dot file. 111 | The last one is traversing the graph from a given vertex and printing the result to *.dot file. 112 | 113 | ```cpp 114 | const auto [graph, start, target]{create_graph_with_start_and_target()}; 115 | 116 | const auto weighted_shortest_path{ 117 | graaf::algorithm::dijkstra_shortest_path(graph, start, target)}; 118 | print_shortest_path(graph, weighted_shortest_path, 119 | "example_weighted_graph.dot"); 120 | 121 | const auto unweighted_shortest_path{ 122 | graaf::algorithm::bfs_shortest_path(graph, start, target)}; 123 | print_shortest_path(graph, unweighted_shortest_path, 124 | "example_unwieghted_graph.dot"); 125 | 126 | seen_edges_t seen_edges{}; 127 | graaf::algorithm::breadth_first_traverse( 128 | graph, start, record_edges_callback{seen_edges}); 129 | print_visited_vertices(graph, seen_edges, 130 | "example_traverse_BFS_graph.dot"); 131 | ``` 132 | -------------------------------------------------------------------------------- /docs/docs/examples/intro.md: -------------------------------------------------------------------------------- 1 | --- 2 | sidebar_position: 1 3 | --- 4 | 5 | # Examples 6 | 7 | This section contains example usages of the Graaf library. 8 | If there is a usecase you would like to see an example of, please open an issue in 9 | our [issue tracker](https://github.com/bobluppes/graaf/issues). -------------------------------------------------------------------------------- /docs/docs/quickstart/basics/_category_.json: -------------------------------------------------------------------------------- 1 | { 2 | "label": "Quickstart - Basics", 3 | "position": 3, 4 | "link": { 5 | "type": "generated-index", 6 | "description": "5 minutes to learn the most important Graaf concepts." 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /docs/docs/quickstart/basics/architecture.md: -------------------------------------------------------------------------------- 1 | --- 2 | sidebar_position: 1 3 | --- 4 | 5 | # Graaf Architecture 6 | 7 | From a very high level, the project is structured in two parts: 8 | 9 | - The graph classes and core data structures 10 | - Algorithms and additional functionality 11 | 12 | ## Graph classes and core data structures 13 | 14 | The main class of the library is the abstract graph class: 15 | 16 | ```c++ 17 | enum class edge_type { WEIGHTED, UNWEIGHTED }; 18 | enum class graph_spec { DIRECTED, UNDIRECTED }; 19 | 20 | template103 |
105 |104 |
graaf::directed_graph<MyVertexClass, MyEdgeClass>
28 | >
29 | ),
30 | },
31 | {
32 | title: 'Lightning Fast',
33 | Svg: require('@site/static/img/undraw_docusaurus_react.svg').default,
34 | description: (
35 | <>
36 | Graaf is written in C++ with performance in mind. This allows users to
37 | efficiently perform complex algorithms on large graphs.
38 | >
39 | ),
40 | },
41 | ];
42 |
43 | function Feature({title, Svg, description}: FeatureItem) {
44 | return (
45 | {description}
52 |{siteConfig.tagline}
17 |