Traffic Flow Dynamics Model
Graph.hpp
1 #ifndef GRAPH_HPP
2 #define GRAPH_HPP
3 
5 
10 
11 #include "../utils/SparseMatrix.hpp"
12 #include "Street.hpp"
13 #include "Vehicle.hpp"
14 #include <memory>
15 #include <string>
16 #include <vector>
17 
18 class Graph {
19 private:
20  SparseMatrix<bool> _adjMatrix;
21  std::vector<std::vector<double>> _nodesCoordinates; // coordinates matrix
22  std::vector<std::shared_ptr<Street>> _streets; // streets in the network
23  std::vector<std::shared_ptr<Vehicle>> _vehicles; // vehicles in the network
24  std::vector<int> _vehiclesOnStreet; // vehicles on the street
25  int _n; // dimension
26  double _temperature = 0.; // temperature of the network
27  int _time = 0; // time of the simulation
28  double _meanTimeTraveled = 0.; // mean time traveled by vehicles
29  int _nVehiclesToDst = 0; // number of vehicles to destination
30  uint16_t _timeScale = 100; // time scale for the simulation
31  std::mt19937 _rng{std::random_device{}()}; // random number generator
32 
33  int _minDistance(int const, int const)
34  const; // algorithm for min distance between two nodes
35  std::vector<int>
36  _nextStep(int const,
37  int const); // next step for the destination (min. distance)
38  void _removeVehicles(bool); // remove a vehicles from the network
39  int _getTimeDifference(
40  std::shared_ptr<Vehicle>) const; // get traveltime difference in a street
41  void _changeStreet(std::shared_ptr<Vehicle>,
42  double const &); // change street of a vehicle
43  void _evolve(bool); // evolve the vehicle's position
44  int _findStreet(int const,
45  int const) const; // find street with origin and destination
46  double _getStreetMeanVelocity(int const) const; // get the mean velocity of a
47  // street
48  std::vector<double>
49  _getDensityCounts(int const) const; // get the density
50  // counts of all streets
51  std::vector<double> _getTravelTimeCounts(int const) const; // get the travel
52  // time counts of
53  // all vehicles
54 
55 public:
56  Graph(std::string);
57  ~Graph() = default;
58 
59  void setSeed(int const);
60  void setTimeScale(int const);
61  int getTimeScale() const noexcept;
62  void addVehicle(int);
64  void addRndmVehicles(int);
65  void addVehiclesUniformly(int);
66  void setTemperature(double const);
67  double getTemperature() const noexcept;
69  void updateTransMatrix();
71  void evolve(bool);
72  void evolve();
73 
74  void printMatrix() noexcept;
75  void print(bool const) const noexcept;
76  void printStreets() const
77  noexcept;
78 
79  void fprintMatrix(char const *);
80  void fprint(bool const) const noexcept;
81  void fprintStreets(std::string const &) const
82  noexcept;
83  void fprintVisual(
84  std::string const &) const noexcept;
85  void fprintHistogram(std::string const &, std::string const &, int const,
86  std::string const &) const; // print histograms
87  void fprintDistribution(
88  std::string const &,
89  std::string const &) const;
91  std::string const &, std::string const &,
92  double const) const;
93  void fprintActualState(std::string const &,
94  std::string const &) const;
95 
96  // void save(const char *) const noexcept; // TODO: save network in file
97 };
98 
99 #endif
Graph class.
Definition: Graph.hpp:18
int getTimeScale() const noexcept
get the time scale
Definition: Graph.cpp:316
void printStreets() const noexcept
print streets on terminal with nodes and number of vehicles
Definition: Graph.cpp:481
void addRndmVehicles(int)
add vehicles of random type in _vehicles
Definition: Graph.cpp:332
Graph(std::string)
import from file (only matrix)
Definition: Graph.cpp:251
void fprintDistribution(std::string const &, std::string const &) const
print graphs whit format y \t x
Definition: Graph.cpp:616
void updateTransMatrix()
update the transition matrix
Definition: Graph.cpp:393
void fprint(bool const) const noexcept
print network info on file
Definition: Graph.cpp:499
void fprintStreets(std::string const &) const noexcept
print streets on file with nodes and number of vehicles
Definition: Graph.cpp:512
void setTemperature(double const)
set the temperature of the network
Definition: Graph.cpp:378
double getTemperature() const noexcept
get the system temperature
Definition: Graph.cpp:388
void addVehicle(int)
Adds a vehicle with a given type.
Definition: Graph.cpp:320
void setTimeScale(int const)
set the time scale
Definition: Graph.cpp:306
void setSeed(int const)
set the seed of the random number generator
Definition: Graph.cpp:302
void fprintTimeDistribution(std::string const &, std::string const &, double const) const
print graphs whit format y \t t
Definition: Graph.cpp:664
void printMatrix() noexcept
print adjency matrix on terminal
Definition: Graph.cpp:442
void fprintMatrix(char const *)
print adjency matrix on file
Definition: Graph.cpp:494
void print(bool const) const noexcept
print network info on terminal
Definition: Graph.cpp:444
void addVehiclesUniformly(int)
add vehicles uniformly on the streets
Definition: Graph.cpp:348
void fprintVisual(std::string const &) const noexcept
print file for visual.py
Definition: Graph.cpp:523
void fprintActualState(std::string const &, std::string const &) const
print actual state
Definition: Graph.cpp:705
void fprintHistogram(std::string const &, std::string const &, int const, std::string const &) const
Print some network's data in a elegible format.
Definition: Graph.cpp:551
void evolve()
evolve the network with reinsertion (default)
Definition: Graph.cpp:440