Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions benchmark/Adj/BenchAdj.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include <cstdint>

#include "Graph.hpp"
#include "RoadNetwork.hpp"
#include "Itinerary.hpp"
#include "FirstOrderDynamics.hpp"
#include "SparseMatrix.hpp"
Expand All @@ -11,11 +11,11 @@ using namespace dsm;
using Bench = sb::Bench<long long int>;

int main() {
Graph graph{};
RoadNetwork graph{};
graph.importOSMNodes("../test/data/forlì_nodes.csv");
graph.importOSMEdges("../test/data/forlì_edges.csv");
graph.buildAdj();
auto const& adj{graph.adjMatrix()};
auto const& adj{graph.adjacencyMatrix()};
auto const N{adj.n()};
SparseMatrix<bool> sm(N, N);
for (const auto& [srcId, dstId] : adj.elements()) {
Expand Down
2 changes: 1 addition & 1 deletion benchmark/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ set(CMAKE_CXX_EXTENSIONS OFF)
include_directories(../extern/benchmark/)

# add subdirectories
# add_subdirectory(Graph)
# add_subdirectory(RoadNetwork)
# add_subdirectory(Street)
add_subdirectory(Dynamics)
add_subdirectory(Adj)
6 changes: 3 additions & 3 deletions benchmark/Dynamics/BenchDynamics.cpp
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
#include <cstdint>

#include "Graph.hpp"
#include "RoadNetwork.hpp"
#include "Itinerary.hpp"
#include "FirstOrderDynamics.hpp"
#include "Bench.hpp"

using Graph = dsm::Graph;
using RoadNetwork = dsm::RoadNetwork;
using Itinerary = dsm::Itinerary;
using Dynamics = dsm::FirstOrderDynamics;

using Bench = sb::Bench<long long int>;

int main() {
Graph graph{};
RoadNetwork graph{};
graph.importOSMNodes("../test/data/forlì_nodes.csv");
graph.importOSMEdges("../test/data/forlì_edges.csv");
graph.buildAdj();
Expand Down
14 changes: 7 additions & 7 deletions benchmark/Graph/BenchGraph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@
#include <utility>
#include "Bench.hpp"

#include "Graph.hpp"
#include "RoadNetwork.hpp"

using Graph = dsm::Graph;
using RoadNetwork = dsm::RoadNetwork;
using Intersection = dsm::Intersection;
using Street = dsm::Street;
using SparseMatrix = dsm::SparseMatrix<bool>;

using Bench = sb::Bench<long long int>;

int main() {
Graph g1;
RoadNetwork g1;
const int n_rep{1000};
Bench b1(n_rep);

Expand Down Expand Up @@ -48,18 +48,18 @@ int main() {
}
Bench b2;
std::cout << "Benchmarking construction with adjacency matrix\n";
b2.benchmark([&sm]() -> void { Graph g(sm); });
b2.benchmark([&sm]() -> void { RoadNetwork g(sm); });
b2.print<sb::milliseconds>();

// Bench b3(1);
// Graph g2(sm);
// RoadNetwork g2(sm);
// std::cout << "Benchmarking building the adjacency matrix\n";
// b3.benchmark([&g2]() -> void { g2.buildAdj(); });
// b3.print<sb::microseconds>();

// Bench b4(3);
// Graph g3;
// g3.importMatrix("./Graph/data/matrix.dat");
// RoadNetwork g3;
// g3.importMatrix("./RoadNetwork/data/matrix.dat");
// std::cout << "Benchmarking the algorithm for the shortest path\n";
// b4.benchmark([&g3]() -> void { g3.shortestPath(0, 1); });
// b4.print<sb::microseconds>();
Expand Down
2 changes: 1 addition & 1 deletion benchmark/Street/BenchStreet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include <random>
#include "Bench.hpp"

#include "Graph.hpp"
#include "RoadNetwork.hpp"

using Agent = dsm::Agent<double>;
using Street = dsm::Street;
Expand Down
28 changes: 14 additions & 14 deletions examples/slow_charge_rb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
using Unit = unsigned int;
using Delay = uint8_t;

using Graph = dsm::Graph;
using RoadNetwork = dsm::RoadNetwork;
using Dynamics = dsm::FirstOrderDynamics;
using Street = dsm::Street;
using SpireStreet = dsm::SpireStreet;
Expand Down Expand Up @@ -83,7 +83,7 @@
fs::create_directory(OUT_FOLDER);
// Starting
std::cout << "Using dsm version: " << dsm::version() << '\n';
Graph graph{};
RoadNetwork graph{};
std::cout << "Importing matrix.dat...\n";
graph.importMatrix(IN_MATRIX, false);
graph.importCoordinates(IN_COORDS);
Expand All @@ -98,20 +98,20 @@
graph.makeRoundabout(i);
}
std::cout << "Making every street a spire...\n";
for (const auto& [id, street] : graph.streetSet()) {
for (const auto& [id, street] : graph.edges()) {

Check notice

Code scanning / Cppcheck (reported by Codacy)

MISRA 12.3 rule Note

MISRA 12.3 rule
graph.makeSpireStreet(id);
}
// check isSpire for each street
for (const auto& [id, street] : graph.streetSet()) {
for (const auto& [id, street] : graph.edges()) {

Check notice

Code scanning / Cppcheck (reported by Codacy)

MISRA 12.3 rule Note

MISRA 12.3 rule
if (!street->isSpire()) {
std::cerr << "Street " << id << " is not a spire.\n";
}
}
const auto& adj = graph.adjMatrix();
const auto& adj = graph.adjacencyMatrix();
auto const degreeVector = adj.getOutDegreeVector();

std::cout << "Setting roundabouts parameters..." << '\n';
for (const auto& [nodeId, node] : graph.nodeSet()) {
for (const auto& [nodeId, node] : graph.nodes()) {

Check notice

Code scanning / Cppcheck (reported by Codacy)

MISRA 12.3 rule Note

MISRA 12.3 rule
auto& rb = dynamic_cast<Roundabout&>(*node);
rb.setCapacity(degreeVector[nodeId]);
rb.setTransportCapacity(degreeVector[nodeId]);
Expand Down Expand Up @@ -149,23 +149,23 @@
#ifdef PRINT_DENSITIES
std::ofstream streetDensity(OUT_FOLDER + "densities.csv");
streetDensity << "time";
for (const auto& [id, street] : dynamics.graph().streetSet()) {
for (const auto& [id, street] : dynamics.graph().edges()) {

Check notice

Code scanning / Cppcheck (reported by Codacy)

MISRA 12.3 rule Note

MISRA 12.3 rule
streetDensity << ';' << id;
}
streetDensity << '\n';
#endif
#ifdef PRINT_FLOWS
std::ofstream streetFlow(OUT_FOLDER + "flows.csv");
streetFlow << "time";
for (const auto& [id, street] : dynamics.graph().streetSet()) {
for (const auto& [id, street] : dynamics.graph().edges()) {

Check notice

Code scanning / Cppcheck (reported by Codacy)

MISRA 12.3 rule Note

MISRA 12.3 rule
streetFlow << ';' << id;
}
streetFlow << '\n';
#endif
#ifdef PRINT_SPEEDS
std::ofstream streetSpeed(OUT_FOLDER + "speeds.csv");
streetSpeed << "time;";
for (const auto& [id, street] : dynamics.graph().streetSet()) {
for (const auto& [id, street] : dynamics.graph().edges()) {

Check notice

Code scanning / Cppcheck (reported by Codacy)

MISRA 12.3 rule Note

MISRA 12.3 rule
streetSpeed << ';' << id;
}
streetSpeed << '\n';
Expand All @@ -175,7 +175,7 @@
std::ofstream inSpires(OUT_FOLDER + "in_spires.csv");
outSpires << "time";
inSpires << "time";
for (const auto& [id, street] : dynamics.graph().streetSet()) {
for (const auto& [id, street] : dynamics.graph().edges()) {

Check notice

Code scanning / Cppcheck (reported by Codacy)

MISRA 12.3 rule Note

MISRA 12.3 rule
outSpires << ';' << id;
inSpires << ';' << id;
}
Expand Down Expand Up @@ -223,7 +223,7 @@
#ifdef PRINT_OUT_SPIRES
outSpires << dynamics.time();
inSpires << dynamics.time();
for (const auto& [id, street] : dynamics.graph().streetSet()) {
for (const auto& [id, street] : dynamics.graph().edges()) {

Check notice

Code scanning / Cppcheck (reported by Codacy)

MISRA 12.3 rule Note

MISRA 12.3 rule
auto& spire = dynamic_cast<SpireStreet&>(*street);
outSpires << ';' << spire.outputCounts(false);
inSpires << ';' << spire.inputCounts(false);
Expand All @@ -247,14 +247,14 @@
if (dynamics.time() % 10 == 0) {
#ifdef PRINT_DENSITIES
streetDensity << dynamics.time();
for (const auto& [id, street] : dynamics.graph().streetSet()) {
for (const auto& [id, street] : dynamics.graph().edges()) {

Check notice

Code scanning / Cppcheck (reported by Codacy)

MISRA 12.3 rule Note

MISRA 12.3 rule
streetDensity << ';' << street->density();
}
streetDensity << std::endl;
#endif
#ifdef PRINT_FLOWS
streetFlow << dynamics.time();
for (const auto& [id, street] : dynamics.graph().streetSet()) {
for (const auto& [id, street] : dynamics.graph().edges()) {

Check notice

Code scanning / Cppcheck (reported by Codacy)

MISRA 12.3 rule Note

MISRA 12.3 rule
const auto& meanSpeed = dynamics.streetMeanSpeed(id);
if (meanSpeed.has_value()) {
streetFlow << ';' << meanSpeed.value() * street->density();
Expand All @@ -266,7 +266,7 @@
#endif
#ifdef PRINT_SPEEDS
streetSpeed << dynamics.time();
for (const auto& [id, street] : dynamics.graph().streetSet()) {
for (const auto& [id, street] : dynamics.graph().edges()) {

Check notice

Code scanning / Cppcheck (reported by Codacy)

MISRA 12.3 rule Note

MISRA 12.3 rule
const auto& meanSpeed = dynamics.streetMeanSpeed(id);
if (meanSpeed.has_value()) {
streetSpeed << ';' << meanSpeed.value();
Expand Down
36 changes: 18 additions & 18 deletions examples/slow_charge_tl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
using Unit = unsigned int;
using Delay = uint8_t;

using Graph = dsm::Graph;
using RoadNetwork = dsm::RoadNetwork;
using Dynamics = dsm::FirstOrderDynamics;
using Street = dsm::Street;
using SpireStreet = dsm::SpireStreet;
Expand Down Expand Up @@ -90,7 +90,7 @@
fs::create_directory(OUT_FOLDER);
// Starting
std::cout << "Using dsm version: " << dsm::version() << '\n';
Graph graph{};
RoadNetwork graph{};
std::cout << "Importing matrix.dat...\n";
graph.importMatrix(IN_MATRIX, false);
graph.importCoordinates(IN_COORDS);
Expand Down Expand Up @@ -152,16 +152,16 @@
graph.makeTrafficLight(i, 120);
}
std::cout << "Making every street a spire...\n";
for (const auto& [id, street] : graph.streetSet()) {
for (const auto& [id, street] : graph.edges()) {

Check notice

Code scanning / Cppcheck (reported by Codacy)

MISRA 12.3 rule Note

MISRA 12.3 rule
graph.makeSpireStreet(id);
}
// check isSpire for each street
for (const auto& [id, street] : graph.streetSet()) {
for (const auto& [id, street] : graph.edges()) {

Check notice

Code scanning / Cppcheck (reported by Codacy)

MISRA 12.3 rule Note

MISRA 12.3 rule
if (!street->isSpire()) {
std::cerr << "Street " << id << " is not a spire.\n";
}
}
auto const degreeVector = graph.adjMatrix().getOutDegreeVector();
auto const degreeVector = graph.adjacencyMatrix().getOutDegreeVector();
// create gaussian random number generator
std::random_device rd;
std::mt19937 gen(rd());
Expand All @@ -170,15 +170,15 @@
std::array<uint8_t, 2> sda{0, 0};
auto random = [&d, &gen]() { return std::round(d(gen)); };
std::cout << "Setting traffic light parameters..." << '\n';
for (const auto& [nodeId, node] : graph.nodeSet()) {
for (const auto& [nodeId, node] : graph.nodes()) {

Check notice

Code scanning / Cppcheck (reported by Codacy)

MISRA 12.3 rule Note

MISRA 12.3 rule
auto& tl = dynamic_cast<TrafficLight&>(*node);
tl.setCapacity(degreeVector[nodeId]);
tl.setTransportCapacity(degreeVector[nodeId]);
double value = -1.;
while (value < 0.) {
value = random();
}
const auto& col = graph.adjMatrix().getCol(nodeId);
const auto& col = graph.adjacencyMatrix().getCol(nodeId);
std::set<Unit> streets;
const auto& refLat = node->coords().value().first;
for (const auto& id : col) {
Expand Down Expand Up @@ -208,7 +208,7 @@
std::cout << "Creating dynamics...\n";

Dynamics dynamics{graph, true, SEED, 0.6};
auto const& adj{dynamics.graph().adjMatrix()};
auto const& adj{dynamics.graph().adjacencyMatrix()};
Unit n{0};
{
std::vector<Unit> destinationNodes;
Expand Down Expand Up @@ -241,23 +241,23 @@
#ifdef PRINT_DENSITIES
std::ofstream streetDensity(OUT_FOLDER + "densities.csv");
streetDensity << "time";
for (const auto& [id, street] : dynamics.graph().streetSet()) {
for (const auto& [id, street] : dynamics.graph().edges()) {

Check notice

Code scanning / Cppcheck (reported by Codacy)

MISRA 12.3 rule Note

MISRA 12.3 rule
streetDensity << ';' << id;
}
streetDensity << '\n';
#endif
#ifdef PRINT_FLOWS
std::ofstream streetFlow(OUT_FOLDER + "flows.csv");
streetFlow << "time";
for (const auto& [id, street] : dynamics.graph().streetSet()) {
for (const auto& [id, street] : dynamics.graph().edges()) {

Check notice

Code scanning / Cppcheck (reported by Codacy)

MISRA 12.3 rule Note

MISRA 12.3 rule
streetFlow << ';' << id;
}
streetFlow << '\n';
#endif
#ifdef PRINT_SPEEDS
std::ofstream streetSpeed(OUT_FOLDER + "speeds.csv");
streetSpeed << "time";
for (const auto& [id, street] : dynamics.graph().streetSet()) {
for (const auto& [id, street] : dynamics.graph().edges()) {

Check notice

Code scanning / Cppcheck (reported by Codacy)

MISRA 12.3 rule Note

MISRA 12.3 rule
streetSpeed << ';' << id;
}
streetSpeed << '\n';
Expand All @@ -267,7 +267,7 @@
std::ofstream inSpires(OUT_FOLDER + "in_spires.csv");
outSpires << "time";
inSpires << "time";
for (const auto& [id, street] : dynamics.graph().streetSet()) {
for (const auto& [id, street] : dynamics.graph().edges()) {

Check notice

Code scanning / Cppcheck (reported by Codacy)

MISRA 12.3 rule Note

MISRA 12.3 rule
outSpires << ';' << id;
inSpires << ';' << id;
}
Expand All @@ -277,7 +277,7 @@
#ifdef PRINT_TP
std::ofstream outTP(OUT_FOLDER + "turn_probabilities.csv");
outTP << "time";
for (const auto& [id, street] : dynamics.graph().streetSet()) {
for (const auto& [id, street] : dynamics.graph().edges()) {

Check notice

Code scanning / Cppcheck (reported by Codacy)

MISRA 12.3 rule Note

MISRA 12.3 rule
outTP << ';' << id;
}
outTP << '\n';
Expand Down Expand Up @@ -335,7 +335,7 @@
#ifdef PRINT_OUT_SPIRES
outSpires << dynamics.time();
inSpires << dynamics.time();
for (const auto& [id, street] : dynamics.graph().streetSet()) {
for (const auto& [id, street] : dynamics.graph().edges()) {

Check notice

Code scanning / Cppcheck (reported by Codacy)

MISRA 12.3 rule Note

MISRA 12.3 rule
auto& spire = dynamic_cast<SpireStreet&>(*street);
outSpires << ';' << spire.outputCounts(false);
inSpires << ';' << spire.inputCounts(false);
Expand All @@ -359,7 +359,7 @@
#ifdef PRINT_TP
const auto& tc{dynamics.turnCounts()};
outTP << dynamics.time();
for (const auto& [id, street] : dynamics.graph().streetSet()) {
for (const auto& [id, street] : dynamics.graph().edges()) {

Check notice

Code scanning / Cppcheck (reported by Codacy)

MISRA 12.3 rule Note

MISRA 12.3 rule
const auto& probs{tc.at(id)};
outTP << ";[";
const auto& nextStreets = TM.at(id);
Expand Down Expand Up @@ -391,14 +391,14 @@
if (dynamics.time() % 10 == 0) {
#ifdef PRINT_DENSITIES
streetDensity << dynamics.time();
for (const auto& [id, street] : dynamics.graph().streetSet()) {
for (const auto& [id, street] : dynamics.graph().edges()) {

Check notice

Code scanning / Cppcheck (reported by Codacy)

MISRA 12.3 rule Note

MISRA 12.3 rule
streetDensity << ';' << street->density();
}
streetDensity << std::endl;
#endif
#ifdef PRINT_FLOWS
streetFlow << ';' << dynamics.time();
for (const auto& [id, street] : dynamics.graph().streetSet()) {
for (const auto& [id, street] : dynamics.graph().edges()) {

Check notice

Code scanning / Cppcheck (reported by Codacy)

MISRA 12.3 rule Note

MISRA 12.3 rule
const auto& meanSpeed = dynamics.streetMeanSpeed(id);
if (meanSpeed.has_value()) {
streetFlow << ';' << meanSpeed.value() * street->density();
Expand All @@ -410,7 +410,7 @@
#endif
#ifdef PRINT_SPEEDS
streetSpeed << dynamics.time();
for (const auto& [id, street] : dynamics.graph().streetSet()) {
for (const auto& [id, street] : dynamics.graph().edges()) {

Check notice

Code scanning / Cppcheck (reported by Codacy)

MISRA 12.3 rule Note

MISRA 12.3 rule
const auto& meanSpeed = dynamics.streetMeanSpeed(id);
if (meanSpeed.has_value()) {
streetSpeed << ';' << meanSpeed.value();
Expand Down
Loading
Loading