Traffic Flow Dynamics Model
Graph Class Reference

Graph class. More...

#include <Graph.hpp>

Public Member Functions

 Graph (std::string)
 import from file (only matrix) More...
 
void setSeed (int const)
 set the seed of the random number generator More...
 
void setTimeScale (int const)
 set the time scale More...
 
int getTimeScale () const noexcept
 get the time scale More...
 
void addVehicle (int)
 Adds a vehicle with a given type. More...
 
void addRndmVehicles (int)
 add vehicles of random type in _vehicles More...
 
void addVehiclesUniformly (int)
 add vehicles uniformly on the streets More...
 
void setTemperature (double const)
 set the temperature of the network More...
 
double getTemperature () const noexcept
 get the system temperature More...
 
void updateTransMatrix ()
 update the transition matrix More...
 
void evolve (bool)
 evolve the network More...
 
void evolve ()
 evolve the network with reinsertion (default) More...
 
void printMatrix () noexcept
 print adjency matrix on terminal More...
 
void print (bool const) const noexcept
 print network info on terminal More...
 
void printStreets () const noexcept
 print streets on terminal with nodes and number of vehicles More...
 
void fprintMatrix (char const *)
 print adjency matrix on file
 
void fprint (bool const) const noexcept
 print network info on file More...
 
void fprintStreets (std::string const &) const noexcept
 print streets on file with nodes and number of vehicles More...
 
void fprintVisual (std::string const &) const noexcept
 print file for visual.py More...
 
void fprintHistogram (std::string const &, std::string const &, int const, std::string const &) const
 Print some network's data in a elegible format. More...
 
void fprintDistribution (std::string const &, std::string const &) const
 print graphs whit format y \t x More...
 
void fprintTimeDistribution (std::string const &, std::string const &, double const) const
 print graphs whit format y \t t More...
 
void fprintActualState (std::string const &, std::string const &) const
 print actual state More...
 

Detailed Description

Graph class.

This class is used to represent a graph. It contains the adjency matrix, the coordinates matrix, the streets, the vehicles, the number of vehicles on each street, the dimension, the temperature, the time, the mean time traveled and the number of vehicles to destination.

Constructor & Destructor Documentation

◆ Graph()

Graph::Graph ( std::string  fName)

import from file (only matrix)

Generate the graph from the matrix.

Parameters
fNamematrix file path

Member Function Documentation

◆ addRndmVehicles()

void Graph::addRndmVehicles ( int  nVehicles)

add vehicles of random type in _vehicles

Adds a fixed number of vehicles with random types Adds a fixed number of vehicles with random types starting at their origin.

Parameters
nVehiclesnumber of vehiclesù
Exceptions
std::invalid_argumentif nVehicles < 0

◆ addVehicle()

void Graph::addVehicle ( int  type)

Adds a vehicle with a given type.

add a vehicle of a type in _vehicles street

Parameters
typevehicle type
Exceptions
std::invalid_argumentif type is invalid

◆ addVehiclesUniformly()

void Graph::addVehiclesUniformly ( int  nVehicles)

add vehicles uniformly on the streets

Adds a fixed number of vehicles with random types Adds a fixed number of vehicles with random types uniformply distributed on the graph.

Parameters
nVehiclesnumber of vehicles
Exceptions
std::invalid_argumentif nVehicles < 0

◆ evolve() [1/2]

void Graph::evolve ( )

evolve the network with reinsertion (default)

Updates the state of the system reinserting vehicles Updates the state of the system by moving vehicles and reinserting them in the streets from their origin.

◆ evolve() [2/2]

void Graph::evolve ( bool  reinsert)

evolve the network

Updates the state of the system.

Updates the state of the system by moving vehicles. The evolution algorithm, for all vehicles:

  • checks if a vehicle is able to move from its actual position, i.e. checks its time penalty. If it is not able to move then the penalty is decreased by one. If it is able the next step is randocmly choosen depending on the transition matrix.
  • if the destination street is full, then a time step is lost (like a STOP sign). Else, the vehicle enters the street with a velocity which depends on the veicle density of the street.
  • depending on the entering velocity, a new time penalty is assigned to the vehicle, of the form \(\frac{L}{v(t)}\), with \(L\) length of the street
    Parameters
    reinsertif true, vehicles are reinserted in the streets from their origin

◆ fprint()

void Graph::fprint ( bool const  printGraph) const
noexcept

print network info on file

Print information of the network.

Parameters
printGraphif true, prints the graph. Print information of the network like number of nodes, number of streets and the graph.

◆ fprintActualState()

void Graph::fprintActualState ( std::string const &  outFolder,
std::string const &  opt 
) const

print actual state

Print the means of some network's data in a format readable by LaTeX.

Parameters
outFolderfolder where the data file will be saved.
optis used to select wich data print. In particolar you can choose between the following options:
  • "q/k" to print the mean flow/capacity
  • "u/k" to print the mean velocity/capacity
Exceptions
std::invalid_argumentif opt is not valid

◆ fprintDistribution()

void Graph::fprintDistribution ( std::string const &  outFolder,
std::string const &  opt 
) const

print graphs whit format y \t x

Print some network's data distributions in a format readable by LaTeX.

Parameters
outFolderfolder where the data file will be saved.
optis used to select wich data print. In particolar you can choose between the following options:
  • "u/q" to print the velocity/flux distribution
  • "q/k" to print the flow/capacity distribution
  • "u/k" to print the velocity/capacity distribution
Exceptions
std::invalid_argumentif opt is not valid

◆ fprintHistogram()

void Graph::fprintHistogram ( std::string const &  outFolder,
std::string const &  opt,
int const  nBins,
std::string const &  format 
) const

Print some network's data in a elegible format.

Parameters
outFolderfolder where the data file will be saved.
optis used to select wich data print. In particolar you can choose between the following options:
  • "density" to print the histogram of the vehicle density on the streets.
  • "traveltime" to print the histogram of the travel time of the vehicles.
nBinsis the number of bins used to create the histogram.
formatis the format of the data. In particolar you can choose between the following options:
  • "latex" to print the data in a format readable by latex.
  • "root" to print the data in a format readable by root.
Exceptions
std::invalid_argumentif nBins < 1 or format/option is invalid.

◆ fprintStreets()

void Graph::fprintStreets ( std::string const &  fName) const
noexcept

print streets on file with nodes and number of vehicles

Print information of every street on a file.

Parameters
fNamename of the file where the information will be saved. Print information of every street like index, origin, destination, number of vehicles and input velocity.

◆ fprintTimeDistribution()

void Graph::fprintTimeDistribution ( std::string const &  outFolder,
std::string const &  opt,
double const  timeZero 
) const

print graphs whit format y \t t

Print some network's data in a format readable by LaTeX.

Parameters
outFolderfolder where the data file will be saved.
optis used to select wich data print. In particolar you can choose between the following options:
  • "k" to append the mean capacity of the network to the file k-t.dat
  • "q" to append the mean flow of the network to the file q-t.dat
  • "u" to append the mean velocity of the network to the file u-t.dat
timeZerois the time at which the simulation starts
Exceptions
std::invalid_argumentif opt is not valid

◆ fprintVisual()

void Graph::fprintVisual ( std::string const &  outFolder) const
noexcept

print file for visual.py

Print network's data in a format readable by the script visual.py.

Parameters
outFolderfolder where the data file will be saved.

◆ getTemperature()

double Graph::getTemperature ( ) const
noexcept

get the system temperature

get the temperature of the network

Returns
temperature

◆ getTimeScale()

int Graph::getTimeScale ( ) const
noexcept

get the time scale

Get the time scale of the simulation.

Returns
time scale

◆ print()

void Graph::print ( bool const  printGraph) const
noexcept

print network info on terminal

Print informations about the system.

◆ printMatrix()

void Graph::printMatrix ( )
noexcept

print adjency matrix on terminal

Print the transition matrix.

◆ printStreets()

void Graph::printStreets ( ) const
noexcept

print streets on terminal with nodes and number of vehicles

Print information of every street. Print information of every street like index, origin, destination, number of vehicles and input velocity.

◆ setSeed()

void Graph::setSeed ( int const  seed)

set the seed of the random number generator

Set the seed for the random number generator.

Parameters
seedseed for the random number generator

◆ setTemperature()

void Graph::setTemperature ( double const  temperature)

set the temperature of the network

set the system temperature

Parameters
temperature
Exceptions
std::invalid_argumentif temperature < 0

◆ setTimeScale()

void Graph::setTimeScale ( int const  timeScale)

set the time scale

Set the time scale for the simulation. Default value is 100.

Parameters
timeScaletime scale
Exceptions
std::invalid_argumentif timeScale < 1

◆ updateTransMatrix()

void Graph::updateTransMatrix ( )

update the transition matrix

create all the transition matrices for all vehicle types

The transition matrix is updated according to the expected traveltime using Dijsktra's algorithm. It uses also temperature to simulate the effect of a noise.


The documentation for this class was generated from the following files: