Graph.h
Go to the documentation of this file.
1 //=============================================================================
2 // Copyright (C) 2021-2024 Wageningen University - All Rights Reserved
3 // Author: Gonzalo Mier
4 // BSD-3 License
5 //=============================================================================
6 
7 #pragma once
8 #ifndef FIELDS2COVER_TYPES_GRAPH_H_
9 #define FIELDS2COVER_TYPES_GRAPH_H_
10 
11 #include <cstdint>
12 #include <vector>
13 #include <functional>
14 #include <utility>
15 #include <unordered_map>
16 
17 namespace f2c::types {
18 
19 typedef std::unordered_map<size_t, std::unordered_map<size_t, int64_t>>
21 typedef std::pair<std::vector<size_t>, int64_t> pair_vec_size__int;
22 
23 class Graph {
24  public:
25  Graph& addDirectedEdge(size_t from, size_t to, int64_t cost);
26  Graph& addEdge(size_t i, size_t j, int64_t cost);
27  Graph& removeDirectedEdge(size_t from, size_t to);
28  Graph& removeEdge(size_t i, size_t j);
29 
30  size_t numNodes() const;
31  size_t numEdges() const;
33 
34  std::vector<size_t> getEdgesFrom(size_t s) const;
35 
36  int64_t getCostFromEdge(size_t from, size_t to,
37  int64_t INF = 1e15) const;
38 
39  std::vector<std::vector<size_t>> allPathsBetween(
40  size_t from, size_t to) const;
41 
42  std::vector<std::vector<pair_vec_size__int>>
43  shortestPathsAndCosts(int64_t INF = 1e15);
44 
45  std::vector<size_t> shortestPath(size_t from, size_t to,
46  int64_t INF = 1e15);
47 
48  int64_t shortestPathCost(size_t from, size_t to,
49  int64_t INF = 1e15);
50 
51  protected:
52  void DFS(size_t from, size_t to,
53  std::vector<std::vector<size_t>>& routes,
54  std::vector<bool>& visited,
55  int& route_index) const;
56 
57  protected:
59  std::vector<std::vector<pair_vec_size__int>> shortest_paths_;
60 };
61 
62 } // namespace f2c::types
63 
64 #endif // FIELDS2COVER_TYPES_GRAPH_H_
f2c::types
Types used by fields2cover library.
Definition: Cell.h:20
f2c::types::Graph::edges_
map_to_map_to_int edges_
Definition: Graph.h:58
f2c::types::Graph::shortestPath
std::vector< size_t > shortestPath(size_t from, size_t to, int64_t INF=1e15)
Definition: Graph.cpp:154
f2c::types::Graph::getEdges
map_to_map_to_int getEdges() const
Definition: Graph.cpp:46
f2c::types::Graph::shortestPathsAndCosts
std::vector< std::vector< pair_vec_size__int > > shortestPathsAndCosts(int64_t INF=1e15)
Definition: Graph.cpp:101
f2c::types::Graph::getCostFromEdge
int64_t getCostFromEdge(size_t from, size_t to, int64_t INF=1e15) const
Definition: Graph.cpp:61
f2c::types::map_to_map_to_int
std::unordered_map< size_t, std::unordered_map< size_t, int64_t > > map_to_map_to_int
Definition: Graph.h:20
f2c::types::Graph::shortest_paths_
std::vector< std::vector< pair_vec_size__int > > shortest_paths_
Definition: Graph.h:59
f2c::types::Graph::getEdgesFrom
std::vector< size_t > getEdgesFrom(size_t s) const
Definition: Graph.cpp:50
f2c::types::Graph::addDirectedEdge
Graph & addDirectedEdge(size_t from, size_t to, int64_t cost)
Definition: Graph.cpp:13
f2c::types::Graph::allPathsBetween
std::vector< std::vector< size_t > > allPathsBetween(size_t from, size_t to) const
Definition: Graph.cpp:68
f2c::types::pair_vec_size__int
std::pair< std::vector< size_t >, int64_t > pair_vec_size__int
Definition: Graph.h:21
f2c::types::Graph
Definition: Graph.h:23
f2c::types::Graph::numNodes
size_t numNodes() const
Definition: Graph.cpp:37
f2c::types::Graph::removeEdge
Graph & removeEdge(size_t i, size_t j)
Definition: Graph.cpp:33
f2c::types::Graph::addEdge
Graph & addEdge(size_t i, size_t j, int64_t cost)
Definition: Graph.cpp:21
f2c::types::Graph::numEdges
size_t numEdges() const
Definition: Graph.cpp:41
f2c::types::Graph::shortestPathCost
int64_t shortestPathCost(size_t from, size_t to, int64_t INF=1e15)
Definition: Graph.cpp:161
f2c::types::Graph::DFS
void DFS(size_t from, size_t to, std::vector< std::vector< size_t >> &routes, std::vector< bool > &visited, int &route_index) const
Definition: Graph.cpp:81
f2c::types::Graph::removeDirectedEdge
Graph & removeDirectedEdge(size_t from, size_t to)
Definition: Graph.cpp:26


fields2cover
Author(s):
autogenerated on Fri Apr 25 2025 02:18:31