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
51 changes: 32 additions & 19 deletions benchmark/Bench_Agent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,21 @@
#include <benchmark/benchmark.h>
#include <memory>

static void BM_Agent_ConstructionWithItineraryId(benchmark::State& state) {
static void BM_Agent_ConstructionWithItinerary(benchmark::State& state) {
std::time_t spawnTime = 0;
for (auto _ : state) {
dsf::mobility::Agent agent(spawnTime++, 1, 0);
dsf::mobility::Agent agent(
spawnTime++, std::make_shared<dsf::mobility::Itinerary>(1, 1), 0);

Check notice

Code scanning / Cppcheck (reported by Codacy)

MISRA 12.3 rule Note test

MISRA 12.3 rule
benchmark::DoNotOptimize(agent);
}
}

static void BM_Agent_ConstructionWithTrip(benchmark::State& state) {
std::time_t spawnTime = 0;
std::vector<dsf::Id> trip = {1, 2, 3};
std::vector<std::shared_ptr<dsf::mobility::Itinerary>> trip = {
std::make_shared<dsf::mobility::Itinerary>(1, 1),
std::make_shared<dsf::mobility::Itinerary>(2, 2),
std::make_shared<dsf::mobility::Itinerary>(3, 3)};
for (auto _ : state) {
dsf::mobility::Agent agent(spawnTime++, trip, 0);
benchmark::DoNotOptimize(agent);
Expand All @@ -29,58 +33,63 @@ static void BM_Agent_ConstructionRandom(benchmark::State& state) {
}

static void BM_Agent_SetSrcNodeId(benchmark::State& state) {
dsf::mobility::Agent agent(0, 1, 0);
dsf::mobility::Agent agent(0, std::make_shared<dsf::mobility::Itinerary>(1, 1), 0);

Check notice

Code scanning / Cppcheck (reported by Codacy)

MISRA 12.3 rule Note test

MISRA 12.3 rule
for (auto _ : state) {
agent.setSrcNodeId(5);
}
}

static void BM_Agent_SetStreetId(benchmark::State& state) {
dsf::mobility::Agent agent(0, 1, 0);
dsf::mobility::Agent agent(0, std::make_shared<dsf::mobility::Itinerary>(1, 1), 0);

Check notice

Code scanning / Cppcheck (reported by Codacy)

MISRA 12.3 rule Note test

MISRA 12.3 rule
for (auto _ : state) {
agent.setStreetId(10);
}
}

static void BM_Agent_SetNextStreetId(benchmark::State& state) {
dsf::mobility::Agent agent(0, 1, 0);
dsf::mobility::Agent agent(0, std::make_shared<dsf::mobility::Itinerary>(1, 1), 0);

Check notice

Code scanning / Cppcheck (reported by Codacy)

MISRA 12.3 rule Note test

MISRA 12.3 rule
for (auto _ : state) {
agent.setNextStreetId(15);
}
}

static void BM_Agent_SetSpeed(benchmark::State& state) {
dsf::mobility::Agent agent(0, 1, 0);
dsf::mobility::Agent agent(0, std::make_shared<dsf::mobility::Itinerary>(1, 1), 0);

Check notice

Code scanning / Cppcheck (reported by Codacy)

MISRA 12.3 rule Note test

MISRA 12.3 rule
for (auto _ : state) {
agent.setSpeed(50.0);
}
}

static void BM_Agent_SetFreeTime(benchmark::State& state) {
dsf::mobility::Agent agent(0, 1, 0);
dsf::mobility::Agent agent(0, std::make_shared<dsf::mobility::Itinerary>(1, 1), 0);

Check notice

Code scanning / Cppcheck (reported by Codacy)

MISRA 12.3 rule Note test

MISRA 12.3 rule
std::time_t freeTime = 100;
for (auto _ : state) {
agent.setFreeTime(freeTime++);
}
}

static void BM_Agent_IncrementDistance(benchmark::State& state) {
dsf::mobility::Agent agent(0, 1, 0);
dsf::mobility::Agent agent(0, std::make_shared<dsf::mobility::Itinerary>(1, 1), 0);

Check notice

Code scanning / Cppcheck (reported by Codacy)

MISRA 12.3 rule Note test

MISRA 12.3 rule
for (auto _ : state) {
agent.incrementDistance(10.0);
}
}

static void BM_Agent_UpdateItinerary(benchmark::State& state) {
std::vector<dsf::Id> trip = {1, 2, 3, 4, 5};
std::vector<std::shared_ptr<dsf::mobility::Itinerary>> trip = {
std::make_shared<dsf::mobility::Itinerary>(1, 1),
std::make_shared<dsf::mobility::Itinerary>(2, 2),
std::make_shared<dsf::mobility::Itinerary>(3, 3),
std::make_shared<dsf::mobility::Itinerary>(4, 4),
std::make_shared<dsf::mobility::Itinerary>(5, 5)};
dsf::mobility::Agent agent(0, trip, 0);
for (auto _ : state) {
agent.updateItinerary();
}
}

static void BM_Agent_Reset(benchmark::State& state) {
dsf::mobility::Agent agent(0, 1, 0);
dsf::mobility::Agent agent(0, std::make_shared<dsf::mobility::Itinerary>(1, 1), 0);

Check notice

Code scanning / Cppcheck (reported by Codacy)

MISRA 12.3 rule Note test

MISRA 12.3 rule
agent.setSpeed(50.0);
agent.setStreetId(10);
std::time_t spawnTime = 1000;
Expand All @@ -91,7 +100,7 @@ static void BM_Agent_Reset(benchmark::State& state) {

// Getter benchmarks - these are inline so very fast
static void BM_Agent_Getters(benchmark::State& state) {
dsf::mobility::Agent agent(0, 1, 0);
dsf::mobility::Agent agent(0, std::make_shared<dsf::mobility::Itinerary>(1, 1), 0);

Check notice

Code scanning / Cppcheck (reported by Codacy)

MISRA 12.3 rule Note test

MISRA 12.3 rule
agent.setSpeed(50.0);
agent.setStreetId(10);
for (auto _ : state) {
Expand All @@ -116,23 +125,27 @@ static void BM_Agent_Getters(benchmark::State& state) {
}
}

static void BM_Agent_ItineraryId(benchmark::State& state) {
dsf::mobility::Agent agent(0, 1, 0);
static void BM_Agent_Itinerary(benchmark::State& state) {
dsf::mobility::Agent agent(0, std::make_shared<dsf::mobility::Itinerary>(1, 1), 0);

Check notice

Code scanning / Cppcheck (reported by Codacy)

MISRA 12.3 rule Note test

MISRA 12.3 rule
for (auto _ : state) {
auto itineraryId = agent.itineraryId();
benchmark::DoNotOptimize(itineraryId);
auto const& pItinerary = agent.itinerary();
benchmark::DoNotOptimize(pItinerary);
}
}

static void BM_Agent_Trip(benchmark::State& state) {
dsf::mobility::Agent agent(0, {1, 2, 3}, 0);
std::vector<std::shared_ptr<dsf::mobility::Itinerary>> trip = {
std::make_shared<dsf::mobility::Itinerary>(1, 1),
std::make_shared<dsf::mobility::Itinerary>(2, 2),
std::make_shared<dsf::mobility::Itinerary>(3, 3)};
dsf::mobility::Agent agent(0, trip, 0);
for (auto _ : state) {
auto trip = agent.trip();
benchmark::DoNotOptimize(trip);
}
}

BENCHMARK(BM_Agent_ConstructionWithItineraryId);
BENCHMARK(BM_Agent_ConstructionWithItinerary);
BENCHMARK(BM_Agent_ConstructionWithTrip);
BENCHMARK(BM_Agent_ConstructionRandom);
BENCHMARK(BM_Agent_SetSrcNodeId);
Expand All @@ -144,7 +157,7 @@ BENCHMARK(BM_Agent_IncrementDistance);
BENCHMARK(BM_Agent_UpdateItinerary);
BENCHMARK(BM_Agent_Reset);
BENCHMARK(BM_Agent_Getters);
BENCHMARK(BM_Agent_ItineraryId);
BENCHMARK(BM_Agent_Itinerary);
BENCHMARK(BM_Agent_Trip);

BENCHMARK_MAIN();
15 changes: 10 additions & 5 deletions benchmark/Bench_Intersection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ static void BM_Intersection_AddAgentWithAngle(benchmark::State& state) {
for (auto _ : state) {
dsf::mobility::Intersection intersection(0);
intersection.setCapacity(100);
auto agent = std::make_unique<dsf::mobility::Agent>(spawnTime++, 1, 0);
auto agent = std::make_unique<dsf::mobility::Agent>(
spawnTime++, std::make_shared<dsf::mobility::Itinerary>(1, 1), 0);

Check notice

Code scanning / Cppcheck (reported by Codacy)

MISRA 12.3 rule Note test

MISRA 12.3 rule
intersection.addAgent(0.0, std::move(agent));
}
}
Expand All @@ -34,7 +35,8 @@ static void BM_Intersection_AddAgentWithoutAngle(benchmark::State& state) {
for (auto _ : state) {
dsf::mobility::Intersection intersection(0);
intersection.setCapacity(100);
auto agent = std::make_unique<dsf::mobility::Agent>(spawnTime++, 1, 0);
auto agent = std::make_unique<dsf::mobility::Agent>(
spawnTime++, std::make_shared<dsf::mobility::Itinerary>(1, 1), 0);

Check notice

Code scanning / Cppcheck (reported by Codacy)

MISRA 12.3 rule Note test

MISRA 12.3 rule
intersection.addAgent(std::move(agent));
}
}
Expand All @@ -43,8 +45,9 @@ static void BM_Intersection_nAgents(benchmark::State& state) {
dsf::mobility::Intersection intersection(0);
intersection.setCapacity(1000);
std::time_t spawnTime = 0;
auto pItinerary = std::make_shared<dsf::mobility::Itinerary>(1, 1);
for (int i = 0; i < 100; ++i) {
auto agent = std::make_unique<dsf::mobility::Agent>(spawnTime++, 1, 0);
auto agent = std::make_unique<dsf::mobility::Agent>(spawnTime++, pItinerary, 0);
intersection.addAgent(std::move(agent));
}
for (auto _ : state) {
Expand All @@ -57,8 +60,9 @@ static void BM_Intersection_Density(benchmark::State& state) {
dsf::mobility::Intersection intersection(0);
intersection.setCapacity(1000);
std::time_t spawnTime = 0;
auto pItinerary = std::make_shared<dsf::mobility::Itinerary>(1, 1);
for (int i = 0; i < 100; ++i) {
auto agent = std::make_unique<dsf::mobility::Agent>(spawnTime++, 1, 0);
auto agent = std::make_unique<dsf::mobility::Agent>(spawnTime++, pItinerary, 0);
intersection.addAgent(std::move(agent));
}
for (auto _ : state) {
Expand All @@ -71,8 +75,9 @@ static void BM_Intersection_IsFull(benchmark::State& state) {
dsf::mobility::Intersection intersection(0);
intersection.setCapacity(1000);
std::time_t spawnTime = 0;
auto pItinerary = std::make_shared<dsf::mobility::Itinerary>(1, 1);
for (int i = 0; i < 100; ++i) {
auto agent = std::make_unique<dsf::mobility::Agent>(spawnTime++, 1, 0);
auto agent = std::make_unique<dsf::mobility::Agent>(spawnTime++, pItinerary, 0);
intersection.addAgent(std::move(agent));
}
for (auto _ : state) {
Expand Down
12 changes: 8 additions & 4 deletions benchmark/Bench_Roundabout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@ static void BM_Roundabout_Enqueue(benchmark::State& state) {
dsf::mobility::Roundabout roundabout(0);
roundabout.setCapacity(1000);
std::time_t spawnTime = 0;
auto pItinerary = std::make_shared<dsf::mobility::Itinerary>(1, 1);
for (auto _ : state) {
auto agent = std::make_unique<dsf::mobility::Agent>(spawnTime++, 1, 0);
auto agent = std::make_unique<dsf::mobility::Agent>(spawnTime++, pItinerary, 0);
roundabout.enqueue(std::move(agent));
}
}
Expand All @@ -34,7 +35,8 @@ static void BM_Roundabout_Dequeue(benchmark::State& state) {
for (auto _ : state) {
dsf::mobility::Roundabout roundabout(0);
roundabout.setCapacity(100);
auto agent = std::make_unique<dsf::mobility::Agent>(spawnTime++, 1, 0);
auto agent = std::make_unique<dsf::mobility::Agent>(
spawnTime++, std::make_shared<dsf::mobility::Itinerary>(1, 1), 0);

Check notice

Code scanning / Cppcheck (reported by Codacy)

MISRA 12.3 rule Note test

MISRA 12.3 rule
roundabout.enqueue(std::move(agent));
auto dequeued = roundabout.dequeue();
benchmark::DoNotOptimize(dequeued);
Expand All @@ -45,8 +47,9 @@ static void BM_Roundabout_Density(benchmark::State& state) {
dsf::mobility::Roundabout roundabout(0);
roundabout.setCapacity(1000);
std::time_t spawnTime = 0;
auto pItinerary = std::make_shared<dsf::mobility::Itinerary>(1, 1);
for (int i = 0; i < 100; ++i) {
auto agent = std::make_unique<dsf::mobility::Agent>(spawnTime++, 1, 0);
auto agent = std::make_unique<dsf::mobility::Agent>(spawnTime++, pItinerary, 0);
roundabout.enqueue(std::move(agent));
}
for (auto _ : state) {
Expand All @@ -59,8 +62,9 @@ static void BM_Roundabout_IsFull(benchmark::State& state) {
dsf::mobility::Roundabout roundabout(0);
roundabout.setCapacity(1000);
std::time_t spawnTime = 0;
auto pItinerary = std::make_shared<dsf::mobility::Itinerary>(1, 1);
for (int i = 0; i < 100; ++i) {
auto agent = std::make_unique<dsf::mobility::Agent>(spawnTime++, 1, 0);
auto agent = std::make_unique<dsf::mobility::Agent>(spawnTime++, pItinerary, 0);
roundabout.enqueue(std::move(agent));
}
for (auto _ : state) {
Expand Down
30 changes: 20 additions & 10 deletions benchmark/Bench_Street.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,19 @@ static void BM_Street_AddAgent(benchmark::State& state) {
100, // capacity
1.0);
std::time_t spawnTime = 0;
auto pItinerary = std::make_shared<dsf::mobility::Itinerary>(1, 1);
for (auto _ : state) {
auto agent = std::make_unique<dsf::mobility::Agent>(spawnTime++, 1, 0);
auto agent = std::make_unique<dsf::mobility::Agent>(spawnTime++, pItinerary, 0);
street.addAgent(std::move(agent));
}
}

static void BM_Street_Enqueue(benchmark::State& state) {
dsf::mobility::Street street(0, {0, 1}, 100.0, 13.8888888889, 2, "test", {}, 100, 1.0);
std::time_t spawnTime = 0;
auto pItinerary = std::make_shared<dsf::mobility::Itinerary>(1, 1);
for (int i = 0; i < 50; ++i) {
auto agent = std::make_unique<dsf::mobility::Agent>(spawnTime++, 1, 0);
auto agent = std::make_unique<dsf::mobility::Agent>(spawnTime++, pItinerary, 0);
street.addAgent(std::move(agent));
}
size_t queueId = 0;
Expand All @@ -47,8 +49,9 @@ static void BM_Street_Enqueue(benchmark::State& state) {
static void BM_Street_Dequeue(benchmark::State& state) {
dsf::mobility::Street street(0, {0, 1}, 100.0, 13.8888888889, 2, "test", {}, 100, 1.0);
std::time_t spawnTime = 0;
auto pItinerary = std::make_shared<dsf::mobility::Itinerary>(1, 1);
for (int i = 0; i < 50; ++i) {
auto agent = std::make_unique<dsf::mobility::Agent>(spawnTime++, 1, 0);
auto agent = std::make_unique<dsf::mobility::Agent>(spawnTime++, pItinerary, 0);
street.addAgent(std::move(agent));
street.enqueue(0);
}
Expand All @@ -64,8 +67,9 @@ static void BM_Street_Dequeue(benchmark::State& state) {
static void BM_Street_nAgents(benchmark::State& state) {
dsf::mobility::Street street(0, {0, 1}, 100.0, 13.8888888889, 2, "test", {}, 100, 1.0);
std::time_t spawnTime = 0;
auto pItinerary = std::make_shared<dsf::mobility::Itinerary>(1, 1);
for (int i = 0; i < 50; ++i) {
auto agent = std::make_unique<dsf::mobility::Agent>(spawnTime++, 1, 0);
auto agent = std::make_unique<dsf::mobility::Agent>(spawnTime++, pItinerary, 0);
street.addAgent(std::move(agent));
if (i % 2 == 0)
street.enqueue(0);
Expand All @@ -79,8 +83,9 @@ static void BM_Street_nAgents(benchmark::State& state) {
static void BM_Street_Density(benchmark::State& state) {
dsf::mobility::Street street(0, {0, 1}, 100.0, 13.8888888889, 2, "test", {}, 100, 1.0);
std::time_t spawnTime = 0;
auto pItinerary = std::make_shared<dsf::mobility::Itinerary>(1, 1);
for (int i = 0; i < 50; ++i) {
auto agent = std::make_unique<dsf::mobility::Agent>(spawnTime++, 1, 0);
auto agent = std::make_unique<dsf::mobility::Agent>(spawnTime++, pItinerary, 0);
street.addAgent(std::move(agent));
if (i % 2 == 0)
street.enqueue(0);
Expand All @@ -94,8 +99,9 @@ static void BM_Street_Density(benchmark::State& state) {
static void BM_Street_nMovingAgents(benchmark::State& state) {
dsf::mobility::Street street(0, {0, 1}, 100.0, 13.8888888889, 2, "test", {}, 100, 1.0);
std::time_t spawnTime = 0;
auto pItinerary = std::make_shared<dsf::mobility::Itinerary>(1, 1);
for (int i = 0; i < 50; ++i) {
auto agent = std::make_unique<dsf::mobility::Agent>(spawnTime++, 1, 0);
auto agent = std::make_unique<dsf::mobility::Agent>(spawnTime++, pItinerary, 0);
street.addAgent(std::move(agent));
}
for (auto _ : state) {
Expand All @@ -107,8 +113,9 @@ static void BM_Street_nMovingAgents(benchmark::State& state) {
static void BM_Street_nExitingAgents(benchmark::State& state) {
dsf::mobility::Street street(0, {0, 1}, 100.0, 13.8888888889, 2, "test", {}, 100, 1.0);
std::time_t spawnTime = 0;
auto pItinerary = std::make_shared<dsf::mobility::Itinerary>(1, 1);
for (int i = 0; i < 50; ++i) {
auto agent = std::make_unique<dsf::mobility::Agent>(spawnTime++, 1, 0);
auto agent = std::make_unique<dsf::mobility::Agent>(spawnTime++, pItinerary, 0);
street.addAgent(std::move(agent));
street.enqueue(0);
}
Expand All @@ -132,8 +139,9 @@ static void BM_CoilStreet_AddAgent(benchmark::State& state) {
dsf::mobility::Street street(0, {0, 1}, 100.0, 13.8888888889, 2, "test", {}, 100, 1.0);
street.enableCounter();
std::time_t spawnTime = 0;
auto pItinerary = std::make_shared<dsf::mobility::Itinerary>(1, 1);
for (auto _ : state) {
auto agent = std::make_unique<dsf::mobility::Agent>(spawnTime++, 1, 0);
auto agent = std::make_unique<dsf::mobility::Agent>(spawnTime++, pItinerary, 0);
street.addAgent(std::move(agent));
}
}
Expand All @@ -142,8 +150,9 @@ static void BM_CoilStreet_MeanFlow(benchmark::State& state) {
dsf::mobility::Street street(0, {0, 1}, 100.0, 13.8888888889, 2, "test", {}, 100, 1.0);
street.enableCounter();
std::time_t spawnTime = 0;
auto pItinerary = std::make_shared<dsf::mobility::Itinerary>(1, 1);
for (int i = 0; i < 50; ++i) {
auto agent = std::make_unique<dsf::mobility::Agent>(spawnTime++, 1, 0);
auto agent = std::make_unique<dsf::mobility::Agent>(spawnTime++, pItinerary, 0);
street.addAgent(std::move(agent));
street.enqueue(0);
if (i % 2 == 0) {
Expand All @@ -160,8 +169,9 @@ static void BM_CoilStreet_Dequeue(benchmark::State& state) {
dsf::mobility::Street street(0, {0, 1}, 100.0, 13.8888888889, 2, "test", {}, 100, 1.0);
street.enableCounter();
std::time_t spawnTime = 0;
auto pItinerary = std::make_shared<dsf::mobility::Itinerary>(1, 1);
for (int i = 0; i < 50; ++i) {
auto agent = std::make_unique<dsf::mobility::Agent>(spawnTime++, 1, 0);
auto agent = std::make_unique<dsf::mobility::Agent>(spawnTime++, pItinerary, 0);
street.addAgent(std::move(agent));
street.enqueue(0);
}
Expand Down
6 changes: 4 additions & 2 deletions examples/stalingrado.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,11 @@ int main() {
// Create the dynamics
FirstOrderDynamics dynamics{graph, false, 69, 0.6};
dynamics.setSpeedFluctuationSTD(0.2);
dynamics.addItinerary(std::unique_ptr<Itinerary>(new Itinerary(4, 4)));
dynamics.addItinerary(4, 4);
dynamics.updatePaths();

auto pItinerary = dynamics.itineraries().at(4);

// lauch progress bar
thread_t t([MAX_TIME]() {
while (progress < MAX_TIME) {
Expand All @@ -103,7 +105,7 @@ int main() {
ofs << progress << ';' << coil->counts() << std::endl;
coil->resetCounter();
}
dynamics.addAgents(*it, 4, 0);
dynamics.addAgents(*it, pItinerary, 0);
}
dynamics.evolve(false);
++progress;
Expand Down
2 changes: 1 addition & 1 deletion src/dsf/dsf.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

static constexpr uint8_t DSF_VERSION_MAJOR = 4;
static constexpr uint8_t DSF_VERSION_MINOR = 7;
static constexpr uint8_t DSF_VERSION_PATCH = 0;
static constexpr uint8_t DSF_VERSION_PATCH = 1;

static auto const DSF_VERSION =
std::format("{}.{}.{}", DSF_VERSION_MAJOR, DSF_VERSION_MINOR, DSF_VERSION_PATCH);
Expand Down
Loading