Skip to content

Commit c15b830

Browse files
authored
Enhance templates in Dynamics classes (#231)
* Template on Agent and not on Delay in Dynamics * Enhance template use in Dynamics classes * Fix warning * Fix * Reworked examples * Fix pylint * Update rb script
1 parent 0bf5a03 commit c15b830

File tree

13 files changed

+225
-272
lines changed

13 files changed

+225
-272
lines changed

benchmark/Dynamics/BenchDynamics.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
using Graph = dsm::Graph;
99
using Itinerary = dsm::Itinerary;
10-
using Dynamics = dsm::FirstOrderDynamics<uint32_t>;
10+
using Dynamics = dsm::FirstOrderDynamics;
1111

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

@@ -28,8 +28,6 @@ int main() {
2828
dynamics.addItinerary(it2);
2929
dynamics.addItinerary(it3);
3030
dynamics.addItinerary(it4);
31-
dynamics.setErrorProbability(0.3);
32-
dynamics.setMinSpeedRateo(0.95);
3331

3432
const int n_rep{100};
3533
Bench b1(n_rep);

examples/Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
slow_charge_tl:
2-
./slow_charge_tl.out 69 0.3 ./sctl 0
2+
./slow_charge_tl.out 69 0.3 ./sctl 0 450
33
slow_charge_rb:
4-
./slow_charge_rb.out 69 0.3 ./scrb/
4+
./slow_charge_rb.out 69 0.3 ./scrb/ 900
55
stalingrado:
66
./stalingrado.out

examples/slow_charge_rb.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ namespace fs = std::filesystem;
1818

1919
std::atomic<unsigned int> progress{0};
2020
std::atomic<bool> bExitFlag{false};
21-
uint nAgents{450};
2221

2322
// uncomment these lines to print densities, flows and speeds
2423
#define PRINT_DENSITIES
@@ -30,7 +29,7 @@ using Unit = unsigned int;
3029
using Delay = uint8_t;
3130

3231
using Graph = dsm::Graph;
33-
using Dynamics = dsm::FirstOrderDynamics<Delay>;
32+
using Dynamics = dsm::FirstOrderDynamics;
3433
using Street = dsm::Street;
3534
using SpireStreet = dsm::SpireStreet;
3635
using Roundabout = dsm::Roundabout;
@@ -42,21 +41,23 @@ void printLoadingBar(int const i, int const n) {
4241
}
4342

4443
int main(int argc, char** argv) {
45-
if (argc != 4) {
44+
if (argc != 5) {
4645
std::cerr << "Usage: " << argv[0]
47-
<< " <SEED> <ERROR_PROBABILITY> <OUT_FOLDER_BASE>\n";
46+
<< " <SEED> <ERROR_PROBABILITY> <OUT_FOLDER_BASE> <INIT_NAGENTS>\n";
4847
return 1;
4948
}
5049

5150
const int SEED = std::stoi(argv[1]); // seed for random number generator
5251
const double ERROR_PROBABILITY{std::stod(argv[2])};
5352
const std::string BASE_OUT_FOLDER{argv[3]};
53+
auto nAgents{std::stoul(argv[4])};
5454

5555
std::cout << "-------------------------------------------------\n";
5656
std::cout << "Input parameters:\n";
5757
std::cout << "Seed: " << SEED << '\n';
5858
std::cout << "Error probability: " << ERROR_PROBABILITY << '\n';
5959
std::cout << "Base output folder: " << BASE_OUT_FOLDER << '\n';
60+
std::cout << "Initial number of agents: " << nAgents << '\n';
6061
std::cout << "-------------------------------------------------\n";
6162

6263
const std::string IN_MATRIX{"./data/matrix.dat"}; // input matrix file
@@ -83,12 +84,11 @@ int main(int argc, char** argv) {
8384
graph.importCoordinates(IN_COORDS);
8485
std::cout << "Setting street parameters..." << '\n';
8586
for (const auto& [streetId, street] : graph.streetSet()) {
86-
street->setLength(2e3);
87-
street->setCapacity(225);
8887
street->setTransportCapacity(1);
8988
street->setMaxSpeed(13.9);
9089
}
9190
graph.buildAdj();
91+
graph.normalizeStreetCapacities();
9292

9393
std::cout << "Number of nodes: " << graph.nNodes() << '\n';
9494
std::cout << "Number of streets: " << graph.nEdges() << '\n';

examples/slow_charge_tl.cpp

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ namespace fs = std::filesystem;
1818

1919
std::atomic<unsigned int> progress{0};
2020
std::atomic<bool> bExitFlag{false};
21-
uint nAgents{315}; // 315 for error probability 0.3, 450 for error probability 0.05
2221

2322
// uncomment these lines to print densities, flows and speeds
2423
#define PRINT_DENSITIES
@@ -31,7 +30,7 @@ using Unit = unsigned int;
3130
using Delay = uint8_t;
3231

3332
using Graph = dsm::Graph;
34-
using Dynamics = dsm::FirstOrderDynamics<Delay>;
33+
using Dynamics = dsm::FirstOrderDynamics;
3534
using Street = dsm::Street;
3635
using SpireStreet = dsm::SpireStreet;
3736
using TrafficLight = dsm::TrafficLight;
@@ -43,9 +42,10 @@ void printLoadingBar(int const i, int const n) {
4342
}
4443

4544
int main(int argc, char** argv) {
46-
if (argc != 5) {
47-
std::cerr << "Usage: " << argv[0]
48-
<< " <SEED> <ERROR_PROBABILITY> <OUT_FOLDER_BASE> <OPTIMIZE>\n";
45+
if (argc != 6) {
46+
std::cerr
47+
<< "Usage: " << argv[0]
48+
<< " <SEED> <ERROR_PROBABILITY> <OUT_FOLDER_BASE> <OPTIMIZE> <INIT_NAGENTS>\n";
4949
return 1;
5050
}
5151

@@ -54,6 +54,7 @@ int main(int argc, char** argv) {
5454
std::string BASE_OUT_FOLDER{argv[3]};
5555
const bool OPTIMIZE{std::string(argv[4]) != std::string("0")};
5656
BASE_OUT_FOLDER += OPTIMIZE ? "_op/" : "/";
57+
auto nAgents{std::stoul(argv[5])};
5758

5859
const std::string IN_MATRIX{"./data/matrix.dat"}; // input matrix file
5960
const std::string IN_COORDS{"./data/coordinates.dsm"}; // input coords file
@@ -68,6 +69,7 @@ int main(int argc, char** argv) {
6869
std::cout << "Seed: " << SEED << '\n';
6970
std::cout << "Error probability: " << ERROR_PROBABILITY << '\n';
7071
std::cout << "Base output folder: " << BASE_OUT_FOLDER << '\n';
72+
std::cout << "Initial number of agents: " << nAgents << '\n';
7173
if (OPTIMIZE) {
7274
std::cout << "Traffic light optimization ENABLED.\n";
7375
}
@@ -89,12 +91,11 @@ int main(int argc, char** argv) {
8991
graph.importCoordinates(IN_COORDS);
9092
std::cout << "Setting street parameters..." << '\n';
9193
for (const auto& [streetId, street] : graph.streetSet()) {
92-
street->setLength(2e3);
93-
street->setCapacity(225);
9494
street->setTransportCapacity(1);
9595
street->setMaxSpeed(13.9);
9696
}
9797
graph.buildAdj();
98+
graph.normalizeStreetCapacities();
9899
const auto dv = graph.adjMatrix().getDegreeVector();
99100

100101
// graph.addStreet(Street(100002, std::make_pair(0, 108)));

examples/stalingrado.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ using Delay = uint8_t;
2121

2222
using Graph = dsm::Graph;
2323
using Itinerary = dsm::Itinerary;
24-
using Dynamics = dsm::FirstOrderDynamics<Delay>;
24+
using Dynamics = dsm::FirstOrderDynamics;
2525
using Street = dsm::Street;
2626
using SpireStreet = dsm::SpireStreet;
2727
using TrafficLight = dsm::TrafficLight;

profiling/main.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ using unit = uint32_t;
1010

1111
using Graph = dsm::Graph;
1212
using Itinerary = dsm::Itinerary;
13-
using Dynamics = dsm::FirstOrderDynamics<unit>;
13+
using Dynamics = dsm::FirstOrderDynamics;
1414

1515
int main() {
1616
Graph graph{};
@@ -36,13 +36,12 @@ int main() {
3636

3737
std::cout << "Creating dynamics...\n";
3838

39-
Dynamics dynamics{graph};
39+
Dynamics dynamics{graph, std::nullopt, 0.95};
4040
dynamics.addItinerary(it1);
4141
dynamics.addItinerary(it2);
4242
dynamics.addItinerary(it3);
4343
dynamics.addItinerary(it4);
4444
dynamics.setErrorProbability(0.3);
45-
dynamics.setMinSpeedRateo(0.95);
4645
dynamics.updatePaths();
4746

4847
std::cout << "Done.\n"

src/dsm/dsm.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
static constexpr uint8_t DSM_VERSION_MAJOR = 2;
88
static constexpr uint8_t DSM_VERSION_MINOR = 2;
9-
static constexpr uint8_t DSM_VERSION_PATCH = 4;
9+
static constexpr uint8_t DSM_VERSION_PATCH = 5;
1010

1111
static auto const DSM_VERSION =
1212
std::format("{}.{}.{}", DSM_VERSION_MAJOR, DSM_VERSION_MINOR, DSM_VERSION_PATCH);

0 commit comments

Comments
 (0)