From f1c6aebac318682b80b482d8bee457c6c3e87300 Mon Sep 17 00:00:00 2001 From: Grufoony Date: Fri, 30 Jan 2026 17:16:42 +0100 Subject: [PATCH 1/2] init --- benchmark/Bench_Agent.cpp | 28 +++++++++++++-------------- benchmark/Bench_Intersection.cpp | 10 +++++----- benchmark/Bench_Roundabout.cpp | 8 ++++---- benchmark/Bench_Street.cpp | 20 +++++++++---------- src/dsf/mobility/Agent.cpp | 14 ++++++++------ src/dsf/mobility/Agent.hpp | 12 ++++++++---- src/dsf/mobility/RoadDynamics.hpp | 21 ++++++++++---------- test/base/Test_node.cpp | 20 +++++++++---------- test/mobility/Test_agent.cpp | 20 +++++++++---------- test/mobility/Test_dynamics.cpp | 2 +- test/mobility/Test_street.cpp | 32 +++++++++++++++---------------- 11 files changed, 97 insertions(+), 90 deletions(-) diff --git a/benchmark/Bench_Agent.cpp b/benchmark/Bench_Agent.cpp index c7bdbf76..8f388654 100644 --- a/benchmark/Bench_Agent.cpp +++ b/benchmark/Bench_Agent.cpp @@ -7,7 +7,7 @@ static void BM_Agent_ConstructionWithItinerary(benchmark::State& state) { std::time_t spawnTime = 0; for (auto _ : state) { dsf::mobility::Agent agent( - spawnTime++, std::make_shared(1, 1), 0); + 0, spawnTime++, std::make_shared(1, 1), 0); benchmark::DoNotOptimize(agent); } } @@ -19,7 +19,7 @@ static void BM_Agent_ConstructionWithTrip(benchmark::State& state) { std::make_shared(2, 2), std::make_shared(3, 3)}; for (auto _ : state) { - dsf::mobility::Agent agent(spawnTime++, trip, 0); + dsf::mobility::Agent agent(0, spawnTime++, trip, 0); benchmark::DoNotOptimize(agent); } } @@ -27,41 +27,41 @@ static void BM_Agent_ConstructionWithTrip(benchmark::State& state) { static void BM_Agent_ConstructionRandom(benchmark::State& state) { std::time_t spawnTime = 0; for (auto _ : state) { - dsf::mobility::Agent agent(spawnTime++); + dsf::mobility::Agent agent(0, spawnTime++); benchmark::DoNotOptimize(agent); } } static void BM_Agent_SetSrcNodeId(benchmark::State& state) { - dsf::mobility::Agent agent(0, std::make_shared(1, 1), 0); + dsf::mobility::Agent agent(0, 0, std::make_shared(1, 1), 0); for (auto _ : state) { agent.setSrcNodeId(5); } } static void BM_Agent_SetStreetId(benchmark::State& state) { - dsf::mobility::Agent agent(0, std::make_shared(1, 1), 0); + dsf::mobility::Agent agent(0, 0, std::make_shared(1, 1), 0); for (auto _ : state) { agent.setStreetId(10); } } static void BM_Agent_SetNextStreetId(benchmark::State& state) { - dsf::mobility::Agent agent(0, std::make_shared(1, 1), 0); + dsf::mobility::Agent agent(0, 0, std::make_shared(1, 1), 0); for (auto _ : state) { agent.setNextStreetId(15); } } static void BM_Agent_SetSpeed(benchmark::State& state) { - dsf::mobility::Agent agent(0, std::make_shared(1, 1), 0); + dsf::mobility::Agent agent(0, 0, std::make_shared(1, 1), 0); for (auto _ : state) { agent.setSpeed(50.0); } } static void BM_Agent_SetFreeTime(benchmark::State& state) { - dsf::mobility::Agent agent(0, std::make_shared(1, 1), 0); + dsf::mobility::Agent agent(0, 0, std::make_shared(1, 1), 0); std::time_t freeTime = 100; for (auto _ : state) { agent.setFreeTime(freeTime++); @@ -69,7 +69,7 @@ static void BM_Agent_SetFreeTime(benchmark::State& state) { } static void BM_Agent_IncrementDistance(benchmark::State& state) { - dsf::mobility::Agent agent(0, std::make_shared(1, 1), 0); + dsf::mobility::Agent agent(0, 0, std::make_shared(1, 1), 0); for (auto _ : state) { agent.incrementDistance(10.0); } @@ -82,14 +82,14 @@ static void BM_Agent_UpdateItinerary(benchmark::State& state) { std::make_shared(3, 3), std::make_shared(4, 4), std::make_shared(5, 5)}; - dsf::mobility::Agent agent(0, trip, 0); + dsf::mobility::Agent agent(0, 0, trip, 0); for (auto _ : state) { agent.updateItinerary(); } } static void BM_Agent_Reset(benchmark::State& state) { - dsf::mobility::Agent agent(0, std::make_shared(1, 1), 0); + dsf::mobility::Agent agent(0, 0, std::make_shared(1, 1), 0); agent.setSpeed(50.0); agent.setStreetId(10); std::time_t spawnTime = 1000; @@ -100,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, std::make_shared(1, 1), 0); + dsf::mobility::Agent agent(0, 0, std::make_shared(1, 1), 0); agent.setSpeed(50.0); agent.setStreetId(10); for (auto _ : state) { @@ -126,7 +126,7 @@ static void BM_Agent_Getters(benchmark::State& state) { } static void BM_Agent_Itinerary(benchmark::State& state) { - dsf::mobility::Agent agent(0, std::make_shared(1, 1), 0); + dsf::mobility::Agent agent(0, 0, std::make_shared(1, 1), 0); for (auto _ : state) { auto const& pItinerary = agent.itinerary(); benchmark::DoNotOptimize(pItinerary); @@ -138,7 +138,7 @@ static void BM_Agent_Trip(benchmark::State& state) { std::make_shared(1, 1), std::make_shared(2, 2), std::make_shared(3, 3)}; - dsf::mobility::Agent agent(0, trip, 0); + dsf::mobility::Agent agent(0, 0, trip, 0); for (auto _ : state) { auto trip = agent.trip(); benchmark::DoNotOptimize(trip); diff --git a/benchmark/Bench_Intersection.cpp b/benchmark/Bench_Intersection.cpp index b97f6717..62b18438 100644 --- a/benchmark/Bench_Intersection.cpp +++ b/benchmark/Bench_Intersection.cpp @@ -25,7 +25,7 @@ static void BM_Intersection_AddAgentWithAngle(benchmark::State& state) { dsf::mobility::Intersection intersection(0); intersection.setCapacity(100); auto agent = std::make_unique( - spawnTime++, std::make_shared(1, 1), 0); + 0, spawnTime++, std::make_shared(1, 1), 0); intersection.addAgent(0.0, std::move(agent)); } } @@ -36,7 +36,7 @@ static void BM_Intersection_AddAgentWithoutAngle(benchmark::State& state) { dsf::mobility::Intersection intersection(0); intersection.setCapacity(100); auto agent = std::make_unique( - spawnTime++, std::make_shared(1, 1), 0); + 0, spawnTime++, std::make_shared(1, 1), 0); intersection.addAgent(std::move(agent)); } } @@ -47,7 +47,7 @@ static void BM_Intersection_nAgents(benchmark::State& state) { std::time_t spawnTime = 0; auto pItinerary = std::make_shared(1, 1); for (int i = 0; i < 100; ++i) { - auto agent = std::make_unique(spawnTime++, pItinerary, 0); + auto agent = std::make_unique(0, spawnTime++, pItinerary, 0); intersection.addAgent(std::move(agent)); } for (auto _ : state) { @@ -62,7 +62,7 @@ static void BM_Intersection_Density(benchmark::State& state) { std::time_t spawnTime = 0; auto pItinerary = std::make_shared(1, 1); for (int i = 0; i < 100; ++i) { - auto agent = std::make_unique(spawnTime++, pItinerary, 0); + auto agent = std::make_unique(0, spawnTime++, pItinerary, 0); intersection.addAgent(std::move(agent)); } for (auto _ : state) { @@ -77,7 +77,7 @@ static void BM_Intersection_IsFull(benchmark::State& state) { std::time_t spawnTime = 0; auto pItinerary = std::make_shared(1, 1); for (int i = 0; i < 100; ++i) { - auto agent = std::make_unique(spawnTime++, pItinerary, 0); + auto agent = std::make_unique(0, spawnTime++, pItinerary, 0); intersection.addAgent(std::move(agent)); } for (auto _ : state) { diff --git a/benchmark/Bench_Roundabout.cpp b/benchmark/Bench_Roundabout.cpp index 5d3f13be..526a515a 100644 --- a/benchmark/Bench_Roundabout.cpp +++ b/benchmark/Bench_Roundabout.cpp @@ -25,7 +25,7 @@ static void BM_Roundabout_Enqueue(benchmark::State& state) { std::time_t spawnTime = 0; auto pItinerary = std::make_shared(1, 1); for (auto _ : state) { - auto agent = std::make_unique(spawnTime++, pItinerary, 0); + auto agent = std::make_unique(0, spawnTime++, pItinerary, 0); roundabout.enqueue(std::move(agent)); } } @@ -36,7 +36,7 @@ static void BM_Roundabout_Dequeue(benchmark::State& state) { dsf::mobility::Roundabout roundabout(0); roundabout.setCapacity(100); auto agent = std::make_unique( - spawnTime++, std::make_shared(1, 1), 0); + 0, spawnTime++, std::make_shared(1, 1), 0); roundabout.enqueue(std::move(agent)); auto dequeued = roundabout.dequeue(); benchmark::DoNotOptimize(dequeued); @@ -49,7 +49,7 @@ static void BM_Roundabout_Density(benchmark::State& state) { std::time_t spawnTime = 0; auto pItinerary = std::make_shared(1, 1); for (int i = 0; i < 100; ++i) { - auto agent = std::make_unique(spawnTime++, pItinerary, 0); + auto agent = std::make_unique(0, spawnTime++, pItinerary, 0); roundabout.enqueue(std::move(agent)); } for (auto _ : state) { @@ -64,7 +64,7 @@ static void BM_Roundabout_IsFull(benchmark::State& state) { std::time_t spawnTime = 0; auto pItinerary = std::make_shared(1, 1); for (int i = 0; i < 100; ++i) { - auto agent = std::make_unique(spawnTime++, pItinerary, 0); + auto agent = std::make_unique(0, spawnTime++, pItinerary, 0); roundabout.enqueue(std::move(agent)); } for (auto _ : state) { diff --git a/benchmark/Bench_Street.cpp b/benchmark/Bench_Street.cpp index 5a4927dd..07c22410 100644 --- a/benchmark/Bench_Street.cpp +++ b/benchmark/Bench_Street.cpp @@ -24,7 +24,7 @@ static void BM_Street_AddAgent(benchmark::State& state) { std::time_t spawnTime = 0; auto pItinerary = std::make_shared(1, 1); for (auto _ : state) { - auto agent = std::make_unique(spawnTime++, pItinerary, 0); + auto agent = std::make_unique(0, spawnTime++, pItinerary, 0); street.addAgent(std::move(agent)); } } @@ -34,7 +34,7 @@ static void BM_Street_Enqueue(benchmark::State& state) { std::time_t spawnTime = 0; auto pItinerary = std::make_shared(1, 1); for (int i = 0; i < 50; ++i) { - auto agent = std::make_unique(spawnTime++, pItinerary, 0); + auto agent = std::make_unique(0, spawnTime++, pItinerary, 0); street.addAgent(std::move(agent)); } size_t queueId = 0; @@ -51,7 +51,7 @@ static void BM_Street_Dequeue(benchmark::State& state) { std::time_t spawnTime = 0; auto pItinerary = std::make_shared(1, 1); for (int i = 0; i < 50; ++i) { - auto agent = std::make_unique(spawnTime++, pItinerary, 0); + auto agent = std::make_unique(0, spawnTime++, pItinerary, 0); street.addAgent(std::move(agent)); street.enqueue(0); } @@ -69,7 +69,7 @@ static void BM_Street_nAgents(benchmark::State& state) { std::time_t spawnTime = 0; auto pItinerary = std::make_shared(1, 1); for (int i = 0; i < 50; ++i) { - auto agent = std::make_unique(spawnTime++, pItinerary, 0); + auto agent = std::make_unique(0, spawnTime++, pItinerary, 0); street.addAgent(std::move(agent)); if (i % 2 == 0) street.enqueue(0); @@ -85,7 +85,7 @@ static void BM_Street_Density(benchmark::State& state) { std::time_t spawnTime = 0; auto pItinerary = std::make_shared(1, 1); for (int i = 0; i < 50; ++i) { - auto agent = std::make_unique(spawnTime++, pItinerary, 0); + auto agent = std::make_unique(0, spawnTime++, pItinerary, 0); street.addAgent(std::move(agent)); if (i % 2 == 0) street.enqueue(0); @@ -101,7 +101,7 @@ static void BM_Street_nMovingAgents(benchmark::State& state) { std::time_t spawnTime = 0; auto pItinerary = std::make_shared(1, 1); for (int i = 0; i < 50; ++i) { - auto agent = std::make_unique(spawnTime++, pItinerary, 0); + auto agent = std::make_unique(0, spawnTime++, pItinerary, 0); street.addAgent(std::move(agent)); } for (auto _ : state) { @@ -115,7 +115,7 @@ static void BM_Street_nExitingAgents(benchmark::State& state) { std::time_t spawnTime = 0; auto pItinerary = std::make_shared(1, 1); for (int i = 0; i < 50; ++i) { - auto agent = std::make_unique(spawnTime++, pItinerary, 0); + auto agent = std::make_unique(0, spawnTime++, pItinerary, 0); street.addAgent(std::move(agent)); street.enqueue(0); } @@ -141,7 +141,7 @@ static void BM_CoilStreet_AddAgent(benchmark::State& state) { std::time_t spawnTime = 0; auto pItinerary = std::make_shared(1, 1); for (auto _ : state) { - auto agent = std::make_unique(spawnTime++, pItinerary, 0); + auto agent = std::make_unique(0, spawnTime++, pItinerary, 0); street.addAgent(std::move(agent)); } } @@ -152,7 +152,7 @@ static void BM_CoilStreet_MeanFlow(benchmark::State& state) { std::time_t spawnTime = 0; auto pItinerary = std::make_shared(1, 1); for (int i = 0; i < 50; ++i) { - auto agent = std::make_unique(spawnTime++, pItinerary, 0); + auto agent = std::make_unique(0, spawnTime++, pItinerary, 0); street.addAgent(std::move(agent)); street.enqueue(0); if (i % 2 == 0) { @@ -171,7 +171,7 @@ static void BM_CoilStreet_Dequeue(benchmark::State& state) { std::time_t spawnTime = 0; auto pItinerary = std::make_shared(1, 1); for (int i = 0; i < 50; ++i) { - auto agent = std::make_unique(spawnTime++, pItinerary, 0); + auto agent = std::make_unique(0, spawnTime++, pItinerary, 0); street.addAgent(std::move(agent)); street.enqueue(0); } diff --git a/src/dsf/mobility/Agent.cpp b/src/dsf/mobility/Agent.cpp index c1ff16ce..30e475ab 100644 --- a/src/dsf/mobility/Agent.cpp +++ b/src/dsf/mobility/Agent.cpp @@ -3,12 +3,13 @@ #include namespace dsf::mobility { - Agent::Agent(std::time_t const& spawnTime, + Agent::Agent(Id const id, + std::time_t const& spawnTime, std::shared_ptr itinerary, std::optional srcNodeId) - : m_spawnTime{spawnTime}, + : m_id{id}, + m_spawnTime{spawnTime}, m_freeTime{0}, - m_id{0}, m_trip{itinerary != nullptr ? std::vector>{itinerary} : std::vector>{}}, m_srcNodeId{srcNodeId}, @@ -16,12 +17,13 @@ namespace dsf::mobility { m_itineraryIdx{0}, m_speed{0.}, m_distance{0.} {} - Agent::Agent(std::time_t const& spawnTime, + Agent::Agent(Id const id, + std::time_t const& spawnTime, std::vector> const& trip, std::optional srcNodeId) - : m_spawnTime{spawnTime}, + : m_id{id}, + m_spawnTime{spawnTime}, m_freeTime{spawnTime}, - m_id{0}, m_trip{trip}, m_srcNodeId{srcNodeId}, m_nextStreetId{std::nullopt}, diff --git a/src/dsf/mobility/Agent.hpp b/src/dsf/mobility/Agent.hpp index af60525d..333500b3 100644 --- a/src/dsf/mobility/Agent.hpp +++ b/src/dsf/mobility/Agent.hpp @@ -27,13 +27,13 @@ namespace dsf::mobility { /// @brief The Agent class represents an agent in the network. class Agent { private: - std::time_t m_spawnTime, m_freeTime; Id m_id; + std::time_t m_spawnTime, m_freeTime; std::vector> m_trip; std::optional m_streetId; std::optional m_srcNodeId; std::optional m_nextStreetId; - size_t m_itineraryIdx; + std::size_t m_itineraryIdx; double m_speed; double m_distance; // Travelled distance std::optional m_maxDistance; // Maximum distance for stochastic agents @@ -41,17 +41,21 @@ namespace dsf::mobility { public: /// @brief Construct a new Agent object + /// @param id The agent's id /// @param spawnTime The agent's spawn time /// @param itineraryId Optional, The agent's destination node. If not provided, the agent is a random agent /// @param srcNodeId Optional, The id of the source node of the agent - Agent(std::time_t const& spawnTime, + Agent(Id const id, + std::time_t const& spawnTime, std::shared_ptr itinerary = nullptr, std::optional srcNodeId = std::nullopt); /// @brief Construct a new Agent object + /// @param id The agent's id /// @param spawnTime The agent's spawn time /// @param itineraryIds The agent's itinerary /// @param srcNodeId Optional, The id of the source node of the agent - Agent(std::time_t const& spawnTime, + Agent(Id const id, + std::time_t const& spawnTime, std::vector> const& trip, std::optional srcNodeId = std::nullopt); diff --git a/src/dsf/mobility/RoadDynamics.hpp b/src/dsf/mobility/RoadDynamics.hpp index 8f750763..8d0967eb 100644 --- a/src/dsf/mobility/RoadDynamics.hpp +++ b/src/dsf/mobility/RoadDynamics.hpp @@ -231,12 +231,12 @@ namespace dsf::mobility { void addAgent(std::unique_ptr agent); template - requires(std::is_constructible_v) + requires(std::is_constructible_v) void addAgent(TArgs&&... args); template - requires(std::is_constructible_v) - void addAgents(Size nAgents, TArgs&&... args); + requires(std::is_constructible_v) + void addAgents(std::size_t const nAgents, TArgs&&... args); /// @brief Add an itinerary /// @param ...args The arguments to construct the itinerary @@ -1345,8 +1345,7 @@ namespace dsf::mobility { streetIt = this->graph().edges().begin(); } auto const& street{streetIt->second}; - this->addAgent( - std::make_unique(this->time_step(), pItinerary, street->source())); + this->addAgent(pItinerary, street->source()); auto& pAgent{this->m_agents.back()}; pAgent->setStreetId(street->id()); this->setAgentSpeed(pAgent); @@ -1557,18 +1556,20 @@ namespace dsf::mobility { template requires(is_numeric_v) template - requires(std::is_constructible_v) + requires(std::is_constructible_v) void RoadDynamics::addAgent(TArgs&&... args) { - addAgent(std::make_unique(this->time_step(), std::forward(args)...)); + addAgent(std::make_unique( + this->m_nAddedAgents, this->time_step(), std::forward(args)...)); } template requires(is_numeric_v) template - requires(std::is_constructible_v) - void RoadDynamics::addAgents(Size nAgents, TArgs&&... args) { + requires(std::is_constructible_v) + void RoadDynamics::addAgents(std::size_t const nAgents, TArgs&&... args) { for (size_t i{0}; i < nAgents; ++i) { - addAgent(std::make_unique(this->time_step(), std::forward(args)...)); + addAgent(std::make_unique( + this->m_nAddedAgents, this->time_step(), std::forward(args)...)); } } diff --git a/test/base/Test_node.cpp b/test/base/Test_node.cpp index f4924355..2dee6a40 100644 --- a/test/base/Test_node.cpp +++ b/test/base/Test_node.cpp @@ -103,9 +103,9 @@ TEST_CASE("Intersection") { Intersection intersection{42}; intersection.setCapacity(3); // Add agents with different angles - auto agent1 = std::make_unique(1); - auto agent2 = std::make_unique(2); - auto agent3 = std::make_unique(3); + auto agent1 = std::make_unique(1, 1); + auto agent2 = std::make_unique(2, 2); + auto agent3 = std::make_unique(3, 3); intersection.addAgent(10.0, std::move(agent1)); intersection.addAgent(5.0, std::move(agent2)); intersection.addAgent(20.0, std::move(agent3)); @@ -128,12 +128,12 @@ TEST_CASE("Intersection") { SUBCASE("Capacity and error handling") { Intersection intersection{99}; intersection.setCapacity(2); - auto agent1 = std::make_unique(1); - auto agent2 = std::make_unique(2); + auto agent1 = std::make_unique(1, 1); + auto agent2 = std::make_unique(2, 2); intersection.addAgent(0.0, std::move(agent1)); intersection.addAgent(1.0, std::move(agent2)); CHECK(intersection.isFull()); - auto agent3 = std::make_unique(3); + auto agent3 = std::make_unique(3, 3); CHECK_THROWS_AS(intersection.addAgent(2.0, std::move(agent3)), std::runtime_error); // Lowering capacity below current agent count throws CHECK_THROWS_AS(intersection.setCapacity(1), std::runtime_error); @@ -143,9 +143,9 @@ TEST_CASE("Intersection") { Intersection intersection{50}; intersection.setCapacity(3); // Add agents using single parameter version (without explicit angle) - auto agent1 = std::make_unique(10); - auto agent2 = std::make_unique(20); - auto agent3 = std::make_unique(30); + auto agent1 = std::make_unique(0, 10); + auto agent2 = std::make_unique(1, 20); + auto agent3 = std::make_unique(2, 30); intersection.addAgent(std::move(agent1)); CHECK_EQ(intersection.nAgents(), 1); @@ -158,7 +158,7 @@ TEST_CASE("Intersection") { CHECK(intersection.isFull()); // Verify that adding another agent when full throws an error - auto agent4 = std::make_unique(40); + auto agent4 = std::make_unique(3, 40); CHECK_THROWS_AS(intersection.addAgent(std::move(agent4)), std::runtime_error); } } diff --git a/test/mobility/Test_agent.cpp b/test/mobility/Test_agent.cpp index c94cfbc2..ba11c16a 100644 --- a/test/mobility/Test_agent.cpp +++ b/test/mobility/Test_agent.cpp @@ -16,7 +16,7 @@ TEST_CASE("Agent") { GIVEN("An agent and its itinerary") { auto itinerary = std::make_shared(0, 5); WHEN("The Agent is constructed") { - Agent agent{0, itinerary}; + Agent agent{0, 0, itinerary}; THEN("The agent and itinerary ids are set correctly") { CHECK_EQ(agent.itinerary()->id(), itinerary->id()); CHECK_FALSE(agent.streetId().has_value()); @@ -31,7 +31,7 @@ TEST_CASE("Agent") { auto itinerary = std::make_shared(0, 5); dsf::Id srcNodeId{0}; WHEN("The Agent is constructed") { - Agent agent{0, itinerary, srcNodeId}; + Agent agent{0, 0, itinerary, srcNodeId}; THEN("The agent and itinerary ids are set correctly") { CHECK_EQ(agent.itinerary()->id(), itinerary->id()); CHECK_FALSE(agent.streetId().has_value()); @@ -45,7 +45,7 @@ TEST_CASE("Agent") { } GIVEN("No initinerary ids and no source node id") { WHEN("The agent is constructed") { - auto randomAgent = Agent{0}; + auto randomAgent = Agent{0, 0}; THEN("The agent is a random agent") { CHECK(randomAgent.isRandom()); } } } @@ -54,7 +54,7 @@ TEST_CASE("Agent") { TEST_CASE("Agent methods") { auto itinerary42 = std::make_shared(42, 100); - Agent agent{0, itinerary42, 7}; + Agent agent{0, 0, itinerary42, 7}; SUBCASE("setSrcNodeId and srcNodeId") { agent.setSrcNodeId(99); CHECK(agent.srcNodeId().has_value()); @@ -97,7 +97,7 @@ TEST_CASE("Agent methods") { auto it2 = std::make_shared(2, 20); auto it3 = std::make_shared(3, 30); std::vector> trip = {it1, it2, it3}; - Agent a2{0, trip, 0}; + Agent a2{0, 0, trip, 0}; CHECK_EQ(a2.itinerary()->id(), 1); a2.updateItinerary(); CHECK_EQ(a2.itinerary()->id(), 2); @@ -126,7 +126,7 @@ TEST_CASE("Agent methods") { TEST_CASE("Agent formatting") { SUBCASE("std::format with complete agent") { auto itinerary42 = std::make_shared(42, 100); - Agent agent{0, itinerary42, 7}; + Agent agent{0, 0, itinerary42, 7}; agent.setStreetId(10); agent.setNextStreetId(15); agent.setSpeed(13.5); @@ -146,7 +146,7 @@ TEST_CASE("Agent formatting") { } SUBCASE("std::format with random agent") { - Agent randomAgent{5}; + Agent randomAgent{0, 5, 0}; std::string formatted = std::format("{}", randomAgent); CHECK(formatted.find("id: 0") != std::string::npos); @@ -162,7 +162,7 @@ TEST_CASE("Agent formatting") { SUBCASE("std::format with agent with optional nullopts") { auto itinerary99 = std::make_shared(99, 200); - Agent agent{10, itinerary99}; + Agent agent{0, 10, itinerary99}; std::string formatted = std::format("{}", agent); CHECK(formatted.find("id: 0") != std::string::npos); @@ -172,7 +172,7 @@ TEST_CASE("Agent formatting") { CHECK(formatted.find("itineraryId: 99") != std::string::npos); } SUBCASE("hasArrived") { - Agent agent{10}; // spawnTime = 10 + Agent agent{0, 10}; // spawnTime = 10 CHECK(agent.isRandom()); // Test Max Distance @@ -187,7 +187,7 @@ TEST_CASE("Agent formatting") { // Test Max Time // Reset agent - agent = Agent{10}; + agent = Agent{1, 10}; agent.setMaxTime(50); // Max duration 50. Should expire at 10+50=60. // Before expiration diff --git a/test/mobility/Test_dynamics.cpp b/test/mobility/Test_dynamics.cpp index c78f97ec..1744ede5 100644 --- a/test/mobility/Test_dynamics.cpp +++ b/test/mobility/Test_dynamics.cpp @@ -1359,7 +1359,7 @@ TEST_CASE("Stationary Weights Impact on Random Navigation") { // Add many random agents to Street 0 for (int i = 0; i < numAgents; ++i) { - auto agent = std::make_unique(0, nullptr, 0); + auto agent = std::make_unique(i, 0, nullptr, 0); agent->setStreetId(0); agent->setSpeed(10.0); agent->setFreeTime(0); diff --git a/test/mobility/Test_street.cpp b/test/mobility/Test_street.cpp index 7dbb1fc7..7fe88a79 100644 --- a/test/mobility/Test_street.cpp +++ b/test/mobility/Test_street.cpp @@ -166,11 +166,11 @@ TEST_CASE("Street") { } } SUBCASE("addAgent") { - Agent a1{0, nullptr, 0}; + Agent a1{0, 0, nullptr, 0}; a1.setFreeTime(5); - Agent a2{0, nullptr, 0}; + Agent a2{1, 0, nullptr, 0}; a2.setFreeTime(3); - Agent a3{0, nullptr, 0}; + Agent a3{2, 0, nullptr, 0}; a3.setFreeTime(7); Street street{1, std::make_pair(0, 1), 3.5}; @@ -185,10 +185,10 @@ TEST_CASE("Street") { /*This tests the insertion of an agent in a street's queue*/ // define some agents - Agent a1{0, nullptr, 0}; // they are all in street 1 - Agent a2{0, nullptr, 0}; - Agent a3{0, nullptr, 0}; - Agent a4{0, nullptr, 0}; + Agent a1{0, 0, nullptr, 0}; // they are all in street 1 + Agent a2{1, 0, nullptr, 0}; + Agent a3{2, 0, nullptr, 0}; + Agent a4{3, 0, nullptr, 0}; Street street{1, std::make_pair(0, 1), 3.5}; // fill the queue @@ -213,10 +213,10 @@ TEST_CASE("Street") { /*This tests the exit of an agent from a street's queue*/ // define some agents - Agent a1{0, nullptr, 0}; // they are all in street 1 - Agent a2{0, nullptr, 0}; - Agent a3{0, nullptr, 0}; - Agent a4{0, nullptr, 0}; + Agent a1{0, 0, nullptr, 0}; // they are all in street 1 + Agent a2{1, 0, nullptr, 0}; + Agent a3{2, 0, nullptr, 0}; + Agent a4{3, 0, nullptr, 0}; Street street{1, std::make_pair(0, 1), 3.5}; // fill the queue @@ -261,7 +261,7 @@ TEST_CASE("Street with a coil") { street.enableCounter("EntryCoil", dsf::mobility::CounterPosition::ENTRY); CHECK_EQ(street.counterName(), "EntryCoil"); WHEN("An agent is added") { - street.addAgent(std::make_unique(0, nullptr)); + street.addAgent(std::make_unique(0, 0, nullptr, 0)); THEN("The input flow is one immediately") { CHECK_EQ(street.counts(), 1); } street.enqueue(0); THEN("The input flow is still one") { CHECK_EQ(street.counts(), 1); } @@ -275,7 +275,7 @@ TEST_CASE("Street with a coil") { street.enableCounter("", dsf::mobility::CounterPosition::MIDDLE); CHECK_EQ(street.counterName(), "Coil_1"); WHEN("An agent is added") { - street.addAgent(std::make_unique(0, nullptr)); + street.addAgent(std::make_unique(0, 0, nullptr, 0)); THEN("The input flow is zero") { CHECK_EQ(street.counts(), 0); } street.enqueue(0); THEN("The input flow is one once enqueued") { CHECK_EQ(street.counts(), 1); } @@ -291,7 +291,7 @@ TEST_CASE("Street with a coil") { street.enableCounter("ExitCoil", dsf::mobility::CounterPosition::EXIT); CHECK_EQ(street.counterName(), "ExitCoil"); WHEN("An agent is added and enqueued") { - street.addAgent(std::make_unique(0, nullptr)); + street.addAgent(std::make_unique(0, 0, nullptr, 0)); street.enqueue(0); THEN("The input flow is zero") { CHECK_EQ(street.counts(), 0); } street.dequeue(0); @@ -589,8 +589,8 @@ TEST_CASE("Street formatting") { Street street{30, std::make_pair(10, 20), 50.0, 15.0, 1}; // Add some agents - auto agent1 = std::make_unique(0, nullptr); - auto agent2 = std::make_unique(0, nullptr); + auto agent1 = std::make_unique(0, 0, nullptr); + auto agent2 = std::make_unique(1, 0, nullptr); street.addAgent(std::move(agent1)); street.addAgent(std::move(agent2)); From f68c6b9fb7af2f2f65c1f4ab8436c2b2c7e156ef Mon Sep 17 00:00:00 2001 From: grufoony Date: Mon, 2 Feb 2026 15:16:53 +0100 Subject: [PATCH 2/2] Copilot fix --- src/dsf/mobility/Agent.hpp | 2 ++ src/dsf/mobility/RoadDynamics.hpp | 4 ++-- test/mobility/Test_agent.cpp | 2 +- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/dsf/mobility/Agent.hpp b/src/dsf/mobility/Agent.hpp index 333500b3..8ab14e47 100644 --- a/src/dsf/mobility/Agent.hpp +++ b/src/dsf/mobility/Agent.hpp @@ -59,6 +59,8 @@ namespace dsf::mobility { std::vector> const& trip, std::optional srcNodeId = std::nullopt); + /// @brief Set the id of the source node of the agent + /// @param srcNodeId The id of the source node void setSrcNodeId(Id srcNodeId); /// @brief Set the street occupied by the agent /// @param streetId The id of the street currently occupied by the agent diff --git a/src/dsf/mobility/RoadDynamics.hpp b/src/dsf/mobility/RoadDynamics.hpp index 8d0967eb..5b1dffaf 100644 --- a/src/dsf/mobility/RoadDynamics.hpp +++ b/src/dsf/mobility/RoadDynamics.hpp @@ -1559,7 +1559,7 @@ namespace dsf::mobility { requires(std::is_constructible_v) void RoadDynamics::addAgent(TArgs&&... args) { addAgent(std::make_unique( - this->m_nAddedAgents, this->time_step(), std::forward(args)...)); + this->m_nInsertedAgents, this->time_step(), std::forward(args)...)); } template @@ -1569,7 +1569,7 @@ namespace dsf::mobility { void RoadDynamics::addAgents(std::size_t const nAgents, TArgs&&... args) { for (size_t i{0}; i < nAgents; ++i) { addAgent(std::make_unique( - this->m_nAddedAgents, this->time_step(), std::forward(args)...)); + this->m_nInsertedAgents, this->time_step(), std::forward(args)...)); } } diff --git a/test/mobility/Test_agent.cpp b/test/mobility/Test_agent.cpp index ba11c16a..c04d65c0 100644 --- a/test/mobility/Test_agent.cpp +++ b/test/mobility/Test_agent.cpp @@ -146,7 +146,7 @@ TEST_CASE("Agent formatting") { } SUBCASE("std::format with random agent") { - Agent randomAgent{0, 5, 0}; + Agent randomAgent{0, 5}; std::string formatted = std::format("{}", randomAgent); CHECK(formatted.find("id: 0") != std::string::npos);