Graph2D.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_GRAPH2D_H_
9 #define FIELDS2COVER_TYPES_GRAPH2D_H_
10 
11 #include <vector>
12 #include <unordered_map>
15 
16 namespace f2c::types {
17 
18 class Graph2D : public Graph {
19  public:
21  using Graph::addEdge;
23  using Graph::removeEdge;
25  using Graph::shortestPath;
27 
28  Graph2D& addDirectedEdge(const Point& from, const Point& to, int64_t cost);
29  Graph2D& addEdge(const Point& i, const Point& j, int64_t cost);
30  Graph2D& addDirectedEdge(const Point& from, const Point& to);
31  Graph2D& addEdge(const Point& i, const Point& j);
33  const Point& from, const Point& to, Graph2D& short_path_g);
35  const Point& i, const Point& j, Graph2D& short_path_g);
36 
37  Graph2D& removeDirectedEdge(const Point& from, const Point& to);
38  Graph2D& removeEdge(const Point& i, const Point& j);
39 
40  size_t numNodes() const;
41  std::vector<Point> getNodes() const;
42 
43  size_t nodeToIndex(const Point& p) const;
44  Point indexToNode(size_t id) const;
45 
46  std::vector<std::vector<Point>> allPathsBetween(
47  const Point& from, const Point& to) const;
48 
49  std::vector<Point> shortestPath(const Point& from, const Point& to,
50  int64_t INF = 1<<30);
51 
52  int64_t shortestPathCost(const Point& from, const Point& to,
53  int64_t INF = 1<<30);
54 
55  protected:
56  std::unordered_map<Point, size_t> nodes_to_index_;
57  std::unordered_map<size_t, Point> index_to_nodes_;
58 
59  private:
60  double scale_ {1e3};
61 };
62 
63 } // namespace f2c::types
64 
65 #endif // FIELDS2COVER_TYPES_GRAPH2D_H_
66 
f2c::types::Graph2D
Definition: Graph2D.h:18
f2c::types::Graph2D::scale_
double scale_
Definition: Graph2D.h:60
f2c::types::Graph2D::addEdge
Graph2D & addEdge(const Point &i, const Point &j, int64_t cost)
Definition: Graph2D.cpp:23
Point.h
f2c::types
Types used by fields2cover library.
Definition: Cell.h:20
f2c::types::Graph2D::shortestPathCost
int64_t shortestPathCost(const Point &from, const Point &to, int64_t INF=1<< 30)
Definition: Graph2D.cpp:101
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::Graph2D::numNodes
size_t numNodes() const
Definition: Graph2D.cpp:57
f2c::types::Graph2D::indexToNode
Point indexToNode(size_t id) const
Definition: Graph2D.cpp:73
f2c::types::Graph2D::removeDirectedEdge
Graph2D & removeDirectedEdge(const Point &from, const Point &to)
Definition: Graph2D.cpp:48
f2c::types::Graph2D::addDirectedEdge
Graph2D & addDirectedEdge(const Point &from, const Point &to, int64_t cost)
Definition: Graph2D.cpp:12
f2c::types::Graph::addDirectedEdge
Graph & addDirectedEdge(size_t from, size_t to, int64_t cost)
Definition: Graph.cpp:13
f2c::types::Graph2D::getNodes
std::vector< Point > getNodes() const
Definition: Graph2D.cpp:61
f2c::types::Graph::allPathsBetween
std::vector< std::vector< size_t > > allPathsBetween(size_t from, size_t to) const
Definition: Graph.cpp:68
f2c::types::Graph2D::nodeToIndex
size_t nodeToIndex(const Point &p) const
Definition: Graph2D.cpp:69
f2c::types::Graph2D::index_to_nodes_
std::unordered_map< size_t, Point > index_to_nodes_
Definition: Graph2D.h:57
f2c::types::Graph2D::shortestPath
std::vector< Point > shortestPath(const Point &from, const Point &to, int64_t INF=1<< 30)
Definition: Graph2D.cpp:91
f2c::types::Point
Definition: Point.h:21
f2c::types::Graph
Definition: Graph.h:23
f2c::types::Graph2D::removeEdge
Graph2D & removeEdge(const Point &i, const Point &j)
Definition: Graph2D.cpp:53
Graph.h
f2c::types::Graph::removeEdge
Graph & removeEdge(size_t i, size_t j)
Definition: Graph.cpp:33
f2c::types::Graph2D::nodes_to_index_
std::unordered_map< Point, size_t > nodes_to_index_
Definition: Graph2D.h:56
f2c::types::Graph::addEdge
Graph & addEdge(size_t i, size_t j, int64_t cost)
Definition: Graph.cpp:21
f2c::types::Graph::shortestPathCost
int64_t shortestPathCost(size_t from, size_t to, int64_t INF=1e15)
Definition: Graph.cpp:161
f2c::types::Graph2D::allPathsBetween
std::vector< std::vector< Point > > allPathsBetween(const Point &from, const Point &to) const
Definition: Graph2D.cpp:77
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