diff --git a/examples/stalingrado.cpp b/examples/stalingrado.cpp index 1b78a310c..785201a57 100644 --- a/examples/stalingrado.cpp +++ b/examples/stalingrado.cpp @@ -110,7 +110,7 @@ int main() { if (progress % 300 == 0) { ofs << progress << ';' << spire.outputCounts(true) << std::endl; } - dynamics.addAgents(4, *it / 2, 0); + dynamics.addAgents(*it / 2, 4, 0); } dynamics.evolve(false); ++progress; diff --git a/src/dsm/dsm.hpp b/src/dsm/dsm.hpp index 3eca5b552..bc34c24ba 100644 --- a/src/dsm/dsm.hpp +++ b/src/dsm/dsm.hpp @@ -6,7 +6,7 @@ static constexpr uint8_t DSM_VERSION_MAJOR = 2; static constexpr uint8_t DSM_VERSION_MINOR = 2; -static constexpr uint8_t DSM_VERSION_PATCH = 6; +static constexpr uint8_t DSM_VERSION_PATCH = 7; static auto const DSM_VERSION = std::format("{}.{}.{}", DSM_VERSION_MAJOR, DSM_VERSION_MINOR, DSM_VERSION_PATCH); diff --git a/src/dsm/headers/Dynamics.hpp b/src/dsm/headers/Dynamics.hpp index 67434f36e..0a896e83b 100644 --- a/src/dsm/headers/Dynamics.hpp +++ b/src/dsm/headers/Dynamics.hpp @@ -147,25 +147,18 @@ namespace dsm { void setDestinationNodes(const std::span& destinationNodes, bool updatePaths = true); - /// @brief Add an agent to the simulation - /// @param agent The agent - void addAgent(const agent_t& agent); /// @brief Add an agent to the simulation /// @param agent std::unique_ptr to the agent void addAgent(std::unique_ptr agent); - /// @brief Add an agent with given source node and itinerary - /// @param srcNodeId The id of the source node - /// @param itineraryId The id of the itinerary - /// @throws std::invalid_argument If the source node or the itinerary are not found - void addAgent(Id srcNodeId, Id itineraryId); - /// @brief Add a pack of agents to the simulation - /// @param itineraryId The index of the itinerary - /// @param nAgents The number of agents to add - /// @throw std::invalid_argument If the itinerary is not found - /// @details adds nAgents agents with the same itinerary of id itineraryId - void addAgents(Id itineraryId, - Size nAgents = 1, - std::optional srcNodeId = std::nullopt); + + template + requires(std::is_constructible_v) + void addAgent(TArgs&&... args); + + template + requires(std::is_constructible_v) + void addAgents(Size nAgents, TArgs&&... args); + /// @brief Add a pack of agents to the simulation /// @param agents Parameter pack of agents template @@ -180,27 +173,12 @@ namespace dsm { /// @brief Add a set of agents to the simulation /// @param agents Generic container of agents, represented by an std::span void addAgents(std::span agents); - /// @brief Add a set of agents to the simulation - /// @param nAgents The number of agents to add - /// @param uniformly If true, the agents are added uniformly on the streets - /// @throw std::runtime_error If there are no itineraries - virtual void addAgentsUniformly(Size nAgents, - std::optional itineraryId = std::nullopt); - template - requires(std::is_same_v> || - std::is_same_v>) - void addAgentsRandomly(Size nAgents, - const TContainer& src_weights, - const TContainer& dst_weights); - - void addRandomAgents(Size nAgents, std::optional srcNodeId = std::nullopt); /// @brief Remove an agent from the simulation /// @param agentId the id of the agent to remove void removeAgent(Size agentId); template - requires(std::is_convertible_v && - (std::is_convertible_v && ...)) + requires(std::is_convertible_v && (std::is_convertible_v && ...)) /// @brief Remove a pack of agents from the simulation /// @param id the id of the first agent to remove /// @param ids the pack of ides of the agents to remove @@ -333,19 +311,6 @@ namespace dsm { } } - template - void Dynamics::addAgent(const agent_t& agent) { - if (m_agents.size() + 1 > m_graph.maxCapacity()) { - throw std::overflow_error(buildLog( - std::format("Graph is already holding the max possible number of agents ({})", - m_graph.maxCapacity()))); - } - if (m_agents.contains(agent.id())) { - throw std::invalid_argument( - buildLog(std::format("Agent with id {} already exists.", agent.id()))); - } - m_agents.emplace(agent.id(), std::make_unique(agent)); - } template void Dynamics::addAgent(std::unique_ptr agent) { if (m_agents.size() + 1 > m_graph.maxCapacity()) { @@ -359,47 +324,24 @@ namespace dsm { } m_agents.emplace(agent->id(), std::move(agent)); } + template - void Dynamics::addAgent(Id srcNodeId, Id itineraryId) { - if (m_agents.size() + 1 > m_graph.maxCapacity()) { - throw std::overflow_error(buildLog( - std::format("Graph is already holding the max possible number of agents ({})", - m_graph.maxCapacity()))); - } - if (!(srcNodeId < m_graph.nodeSet().size())) { - throw std::invalid_argument( - buildLog(std::format("Node with id {} not found", srcNodeId))); - } - if (!(m_itineraries.contains(itineraryId))) { - throw std::invalid_argument( - buildLog(std::format("Itinerary with id {} not found", itineraryId))); - } - Size agentId{0}; - if (!m_agents.empty()) { - agentId = m_agents.rbegin()->first + 1; - } - this->addAgent(agent_t{agentId, itineraryId, srcNodeId}); + template + requires(std::is_constructible_v) + void Dynamics::addAgent(TArgs&&... args) { + addAgent(std::make_unique(std::forward(args)...)); } + template - void Dynamics::addAgents(Id itineraryId, - Size nAgents, - std::optional srcNodeId) { - if (m_agents.size() + nAgents > m_graph.maxCapacity()) { - throw std::overflow_error(buildLog( - std::format("Graph is already holding the max possible number of agents ({})", - m_graph.maxCapacity()))); - } - auto itineraryIt{m_itineraries.find(itineraryId)}; - if (itineraryIt == m_itineraries.end()) { - throw std::invalid_argument( - buildLog(std::format("Itinerary with id {} not found", itineraryId))); - } - Size agentId{0}; + template + requires(std::is_constructible_v) + void Dynamics::addAgents(Size nAgents, TArgs&&... args) { + Id agentId{0}; if (!m_agents.empty()) { agentId = m_agents.rbegin()->first + 1; } - for (Size i{0}; i < nAgents; ++i, ++agentId) { - this->addAgent(agent_t{agentId, itineraryId, srcNodeId}); + for (size_t i{0}; i < nAgents; ++i, ++agentId) { + addAgent(std::make_unique(agentId, std::forward(args)...)); } } @@ -412,171 +354,17 @@ namespace dsm { template requires(is_agent_v && (is_agent_v && ...)) void Dynamics::addAgents(T1 agent, Tn... agents) { - addAgent(agent); + addAgent(std::make_unique(agent)); addAgents(agents...); } template void Dynamics::addAgents(std::span agents) { - if (this->m_agents.size() + agents.size() > this->m_graph.maxCapacity()) { - throw std::overflow_error(buildLog( - std::format("Graph is already holding the max possible number of agents ({})", - this->m_graph.maxCapacity()))); - } std::ranges::for_each(agents, [this](const auto& agent) -> void { - this->m_agents.push_back(std::make_unique(agent)); + addAgent(std::make_unique(agent)); }); } - template - void Dynamics::addAgentsUniformly(Size nAgents, - std::optional itineraryId) { - if (m_agents.size() + nAgents > m_graph.maxCapacity()) { - throw std::overflow_error(buildLog( - std::format("Graph is already holding the max possible number of agents ({})", - this->m_graph.maxCapacity()))); - } - if (m_itineraries.empty()) { - // TODO: make this possible for random agents - throw std::invalid_argument( - buildLog("It is not possible to add random agents without itineraries.")); - } - const bool randomItinerary{!itineraryId.has_value()}; - std::uniform_int_distribution itineraryDist{ - 0, static_cast(m_itineraries.size() - 1)}; - std::uniform_int_distribution streetDist{ - 0, static_cast(m_graph.streetSet().size() - 1)}; - for (Size i{0}; i < nAgents; ++i) { - if (randomItinerary) { - auto itineraryIt{m_itineraries.begin()}; - std::advance(itineraryIt, itineraryDist(m_generator)); - itineraryId = itineraryIt->first; - } - Id agentId{0}; - if (!m_agents.empty()) { - agentId = m_agents.rbegin()->first + 1; - } - Id streetId{0}; - do { - // I dunno why this works and the following doesn't - const auto& streetSet = m_graph.streetSet(); - auto streetIt = streetSet.begin(); - // auto streetIt = this->m_graph->streetSet().begin(); - Size step = streetDist(m_generator); - std::advance(streetIt, step); - streetId = streetIt->first; - } while (m_graph.streetSet()[streetId]->isFull()); - const auto& street{m_graph.streetSet()[streetId]}; - agent_t agent{agentId, itineraryId.value(), street->nodePair().first}; - agent.setStreetId(streetId); - this->addAgent(agent); - this->setAgentSpeed(agentId); - m_agents[agentId]->incrementDelay( - std::ceil(street->length() / m_agents[agentId]->speed())); - street->addAgent(agentId); - ++agentId; - } - } - - template - template - requires(std::is_same_v> || - std::is_same_v>) - void Dynamics::addAgentsRandomly(Size nAgents, - const TContainer& src_weights, - const TContainer& dst_weights) { - if (src_weights.size() == 1 && dst_weights.size() == 1 && - src_weights.begin()->first == dst_weights.begin()->first) { - throw std::invalid_argument(buildLog( - std::format("The only source node {} is also the only destination node.", - src_weights.begin()->first))); - } - auto const srcSum{std::accumulate( - src_weights.begin(), - src_weights.end(), - 0., - [](double sum, const std::pair& p) { - if (p.second < 0.) { - throw std::invalid_argument(buildLog(std::format( - "Negative weight ({}) for source node {}.", p.second, p.first))); - } - return sum + p.second; - })}; - auto const dstSum{std::accumulate( - dst_weights.begin(), - dst_weights.end(), - 0., - [](double sum, const std::pair& p) { - if (p.second < 0.) { - throw std::invalid_argument(buildLog(std::format( - "Negative weight ({}) for destination node {}.", p.second, p.first))); - } - return sum + p.second; - })}; - std::uniform_real_distribution srcUniformDist{0., srcSum}; - std::uniform_real_distribution dstUniformDist{0., dstSum}; - while (nAgents > 0) { - Id srcId{0}, dstId{0}; - if (dst_weights.size() == 1) { - dstId = dst_weights.begin()->first; - srcId = dstId; - } - double dRand, sum; - while (srcId == dstId) { - dRand = srcUniformDist(m_generator); - sum = 0.; - for (const auto& [id, weight] : src_weights) { - srcId = id; - sum += weight; - if (dRand < sum) { - break; - } - } - } - if (src_weights.size() > 1) { - dstId = srcId; - } - while (dstId == srcId) { - dRand = dstUniformDist(m_generator); - sum = 0.; - for (const auto& [id, weight] : dst_weights) { - dstId = id; - sum += weight; - if (dRand < sum) { - break; - } - } - } - // find the itinerary with the given destination as destination - auto itineraryIt{std::find_if( - m_itineraries.begin(), m_itineraries.end(), [dstId](const auto& itinerary) { - return itinerary.second->destination() == dstId; - })}; - if (itineraryIt == m_itineraries.end()) { - throw std::invalid_argument( - buildLog(std::format("Itinerary with destination {} not found.", dstId))); - } - this->addAgent(srcId, itineraryIt->first); - --nAgents; - } - } - - template - void Dynamics::addRandomAgents(Size nAgents, std::optional srcNodeId) { - if (m_agents.size() + nAgents > m_graph.maxCapacity()) { - throw std::overflow_error(buildLog( - std::format("Graph is already holding the max possible number of agents ({})", - m_graph.maxCapacity()))); - } - Id agentId{0}; - if (!m_agents.empty()) { - agentId = m_agents.rbegin()->first + 1; - } - for (auto i{0}; i < nAgents; ++i, ++agentId) { - this->addAgent(agent_t{agentId, srcNodeId}); - } - } - template void Dynamics::removeAgent(Size agentId) { m_agents.erase(agentId); diff --git a/src/dsm/headers/RoadDynamics.hpp b/src/dsm/headers/RoadDynamics.hpp index dd76405ee..92324d3f6 100644 --- a/src/dsm/headers/RoadDynamics.hpp +++ b/src/dsm/headers/RoadDynamics.hpp @@ -101,6 +101,23 @@ namespace dsm { m_dataUpdatePeriod = dataUpdatePeriod; } + /// @brief Add a set of agents to the simulation + /// @param nAgents The number of agents to add + /// @param uniformly If true, the agents are added uniformly on the streets + /// @throw std::runtime_error If there are no itineraries + void addAgentsUniformly(Size nAgents, std::optional itineraryId = std::nullopt); + /// @brief Add a set of agents to the simulation + /// @param nAgents The number of agents to add + /// @param src_weights The weights of the source nodes + /// @param dst_weights The weights of the destination nodes + /// @throw std::invalid_argument If the source and destination nodes are the same + template + requires(std::is_same_v> || + std::is_same_v>) + void addAgentsRandomly(Size nAgents, + const TContainer& src_weights, + const TContainer& dst_weights); + /// @brief Evolve the simulation /// @details Evolve the simulation by moving the agents and updating the travel times. /// In particular: @@ -467,6 +484,143 @@ namespace dsm { m_passageProbability = passageProbability; } + template + requires(is_numeric_v) + void RoadDynamics::addAgentsUniformly(Size nAgents, + std::optional optItineraryId) { + if (this->m_itineraries.empty()) { + // TODO: make this possible for random agents + throw std::invalid_argument( + buildLog("It is not possible to add random agents without itineraries.")); + } + Id itineraryId{0}; + const bool randomItinerary{!optItineraryId.has_value()}; + if (!randomItinerary) { + itineraryId = optItineraryId.value(); + } + std::uniform_int_distribution itineraryDist{ + 0, static_cast(this->m_itineraries.size() - 1)}; + std::uniform_int_distribution streetDist{ + 0, static_cast(this->m_graph.nEdges() - 1)}; + for (Size i{0}; i < nAgents; ++i) { + if (randomItinerary) { + auto itineraryIt{this->m_itineraries.begin()}; + std::advance(itineraryIt, itineraryDist(this->m_generator)); + itineraryId = itineraryIt->first; + } + Id agentId{0}; + if (!this->m_agents.empty()) { + agentId = this->m_agents.rbegin()->first + 1; + } + Id streetId{0}; + do { + auto streetIt = this->m_graph.streetSet().begin(); + Size step = streetDist(this->m_generator); + std::advance(streetIt, step); + streetId = streetIt->first; + } while (this->m_graph.streetSet()[streetId]->isFull() && + this->m_agents.size() < this->m_graph.maxCapacity()); + const auto& street{this->m_graph.streetSet()[streetId]}; + this->addAgent(agentId, itineraryId, street->nodePair().first); + this->m_agents[agentId]->setStreetId(streetId); + this->setAgentSpeed(agentId); + this->m_agents[agentId]->incrementDelay( + std::ceil(street->length() / this->m_agents[agentId]->speed())); + street->addAgent(agentId); + ++agentId; + } + } + + template + requires(is_numeric_v) + template + requires(std::is_same_v> || + std::is_same_v>) + void RoadDynamics::addAgentsRandomly(Size nAgents, + const TContainer& src_weights, + const TContainer& dst_weights) { + if (src_weights.size() == 1 && dst_weights.size() == 1 && + src_weights.begin()->first == dst_weights.begin()->first) { + throw std::invalid_argument(buildLog( + std::format("The only source node {} is also the only destination node.", + src_weights.begin()->first))); + } + auto const srcSum{std::accumulate( + src_weights.begin(), + src_weights.end(), + 0., + [](double sum, const std::pair& p) { + if (p.second < 0.) { + throw std::invalid_argument(buildLog(std::format( + "Negative weight ({}) for source node {}.", p.second, p.first))); + } + return sum + p.second; + })}; + auto const dstSum{std::accumulate( + dst_weights.begin(), + dst_weights.end(), + 0., + [](double sum, const std::pair& p) { + if (p.second < 0.) { + throw std::invalid_argument(buildLog(std::format( + "Negative weight ({}) for destination node {}.", p.second, p.first))); + } + return sum + p.second; + })}; + std::uniform_real_distribution srcUniformDist{0., srcSum}; + std::uniform_real_distribution dstUniformDist{0., dstSum}; + Id agentId{0}; + if (!this->m_agents.empty()) { + agentId = this->m_agents.rbegin()->first + 1; + } + while (nAgents > 0) { + Id srcId{0}, dstId{0}; + if (dst_weights.size() == 1) { + dstId = dst_weights.begin()->first; + srcId = dstId; + } + double dRand, sum; + while (srcId == dstId) { + dRand = srcUniformDist(this->m_generator); + sum = 0.; + for (const auto& [id, weight] : src_weights) { + srcId = id; + sum += weight; + if (dRand < sum) { + break; + } + } + } + if (src_weights.size() > 1) { + dstId = srcId; + } + while (dstId == srcId) { + dRand = dstUniformDist(this->m_generator); + sum = 0.; + for (const auto& [id, weight] : dst_weights) { + dstId = id; + sum += weight; + if (dRand < sum) { + break; + } + } + } + // find the itinerary with the given destination as destination + auto itineraryIt{std::find_if(this->m_itineraries.begin(), + this->m_itineraries.end(), + [dstId](const auto& itinerary) { + return itinerary.second->destination() == dstId; + })}; + if (itineraryIt == this->m_itineraries.end()) { + throw std::invalid_argument( + buildLog(std::format("Itinerary with destination {} not found.", dstId))); + } + this->addAgent(agentId, itineraryIt->first, srcId); + --nAgents; + ++agentId; + } + } + template requires(is_numeric_v) void RoadDynamics::evolve(bool reinsert_agents) { diff --git a/test/Test_dynamics.cpp b/test/Test_dynamics.cpp index d60df69a0..52abb1b21 100644 --- a/test/Test_dynamics.cpp +++ b/test/Test_dynamics.cpp @@ -125,7 +125,7 @@ TEST_CASE("Dynamics") { Dynamics dynamics{graph, 69}; dynamics.addItinerary(Itinerary{2, 2}); WHEN("We add the agent") { - dynamics.addAgent(0, 2); + dynamics.addAgent(0, 2, 0); THEN("The agent is added") { CHECK_EQ(dynamics.nAgents(), 1); const auto& agent = dynamics.agents().at(0); @@ -134,16 +134,6 @@ TEST_CASE("Dynamics") { CHECK_EQ(agent->itineraryId(), 2); } } - WHEN("We try to add an agent with a non-existing source node") { - THEN("An exception is thrown") { - CHECK_THROWS_AS(dynamics.addAgent(3, 2), std::invalid_argument); - } - } - WHEN("We try to add an agent with a non-existing itinerary") { - THEN("An exception is thrown") { - CHECK_THROWS_AS(dynamics.addAgent(0, 0), std::invalid_argument); - } - } } } SUBCASE("addAgentsUniformly") { @@ -290,7 +280,7 @@ TEST_CASE("Dynamics") { Dynamics dynamics{graph, 69}; dynamics.setPassageProbability(p); WHEN("We add some agent") { - dynamics.addRandomAgents(n); + dynamics.addAgents(n); THEN("The number of agents is correct") { CHECK_EQ(dynamics.nAgents(), 100); } THEN("If we evolve the dynamics agent disappear gradually") { for (auto i{0}; i < 40; ++i) { @@ -308,13 +298,8 @@ TEST_CASE("Dynamics") { Dynamics dynamics{graph, 69}; Itinerary itinerary{0, 2}; dynamics.addItinerary(itinerary); - WHEN("We add an agent with itinerary 1") { - THEN("An exception is thrown") { - CHECK_THROWS_AS(dynamics.addAgents(1), std::invalid_argument); - } - } - WHEN("We add and agent with itinerary 0") { - dynamics.addAgents(0); + WHEN("We add an agent with itinerary 0") { + dynamics.addAgent(0, 0); THEN( "The number of agents is 1 and the destination is the same as the " "itinerary") { @@ -326,7 +311,7 @@ TEST_CASE("Dynamics") { } } WHEN("We add 69 agents with itinerary 0") { - dynamics.addAgents(0, 69); + dynamics.addAgents(69, 0); THEN("The number of agents is 69") { CHECK_EQ(dynamics.nAgents(), 69); } } } @@ -345,10 +330,8 @@ TEST_CASE("Dynamics") { WHEN("We add more than one agent") { THEN("It throws") { CHECK_THROWS_AS(dynamics.addAgentsUniformly(1), std::overflow_error); - CHECK_THROWS_AS(dynamics.addAgents(0, 1), std::overflow_error); - auto dummyAgent = Agent(0, 0); - CHECK_THROWS_AS(dynamics.addAgent(dummyAgent), std::overflow_error); - CHECK_THROWS_AS(dynamics.addAgent(std::make_unique(dummyAgent)), + CHECK_THROWS_AS(dynamics.addAgent(1, 0, 0), std::overflow_error); + CHECK_THROWS_AS(dynamics.addAgent(std::make_unique(Agent(1, 0))), std::overflow_error); } } @@ -477,7 +460,7 @@ TEST_CASE("Dynamics") { dynamics.addItinerary(itinerary); dynamics.updatePaths(); WHEN("We add an agent randomly and evolve the dynamics") { - dynamics.addAgent(Agent(0, 0, 0)); + dynamics.addAgent(0, 0, 0); dynamics.evolve(false); dynamics.evolve(false); THEN("The agent evolves") { @@ -508,7 +491,7 @@ TEST_CASE("Dynamics") { Itinerary itinerary{0, 1}; dynamics.addItinerary(itinerary); dynamics.updatePaths(); - dynamics.addAgent(Agent(0, 0, 0)); + dynamics.addAgent(0, 0, 0); WHEN("We evolve the dynamics") { dynamics.evolve(false); dynamics.evolve(false); @@ -533,7 +516,7 @@ TEST_CASE("Dynamics") { Itinerary itinerary{0, 1}; dynamics.addItinerary(itinerary); dynamics.updatePaths(); - dynamics.addAgent(Agent(0, 0, 0)); + dynamics.addAgent(0, 0, 0); WHEN("We evolve the dynamics with reinsertion") { dynamics.evolve(true); dynamics.evolve(true); @@ -566,8 +549,7 @@ TEST_CASE("Dynamics") { std::vector dsts{1, 2}; dynamics.setDestinationNodes(dsts); std::vector trip{2, 1}; - Agent agent{0, trip, 0}; - dynamics.addAgent(agent); + dynamics.addAgent(0, trip, 0); auto const& pAgent{dynamics.agents().at(0)}; WHEN("We evolve the dynamics") { dynamics.evolve(false); @@ -611,7 +593,7 @@ TEST_CASE("Dynamics") { Itinerary itinerary{0, 2}; dynamics.addItinerary(itinerary); dynamics.updatePaths(); - dynamics.addAgent(Agent(0, 0, 0)); + dynamics.addAgent(0, 0, 0); WHEN("We evolve the dynamics") { dynamics.evolve(false); THEN( @@ -802,8 +784,8 @@ TEST_CASE("Dynamics") { Dynamics dynamics{graph2, 69}; std::vector destinationNodes{0, 2, 3, 4}; dynamics.setDestinationNodes(destinationNodes); - dynamics.addAgents(0, 7, 2); - dynamics.addAgents(2, 7, 0); + dynamics.addAgents(7, 0, 2); + dynamics.addAgents(7, 2, 0); dynamics.setDataUpdatePeriod(4); auto const& cycles{tl.cycles()}; WHEN("We evolve the dynamics and optimize traffic lights") { @@ -827,10 +809,10 @@ TEST_CASE("Dynamics") { "We evolve the dynamics and optimize traffic lights with outgoing " "streets " "full") { - dynamics.addAgents(0, 5, 1); - dynamics.addAgents(2, 5, 1); - dynamics.addAgents(3, 5, 1); - dynamics.addAgents(4, 5, 1); + dynamics.addAgents(5, 0, 1); + dynamics.addAgents(5, 2, 1); + dynamics.addAgents(5, 3, 1); + dynamics.addAgents(5, 4, 1); for (int i = 0; i < 15; ++i) { dynamics.evolve(false); } @@ -869,14 +851,14 @@ TEST_CASE("Dynamics") { dynamics.addItinerary(itinerary); dynamics.addItinerary(itinerary2); dynamics.updatePaths(); - dynamics.addAgent(Agent(0, 0, 0)); - dynamics.addAgent(Agent(1, 1, 2)); + dynamics.addAgent(0, 0, 0); + dynamics.addAgent(1, 1, 2); WHEN( "We evolve the dynamics adding an agent on the path of the agent " "with " "priority") { dynamics.evolve(false); - dynamics.addAgent(Agent(2, 0, 1)); + dynamics.addAgent(2, 0, 1); dynamics.evolve(false); dynamics.evolve(false); THEN("The agents are trapped into the roundabout") { @@ -905,7 +887,7 @@ TEST_CASE("Dynamics") { Itinerary itinerary{0, 2}; dynamics.addItinerary(itinerary); dynamics.updatePaths(); - dynamics.addAgent(Agent(0, 0, 0)); + dynamics.addAgent(0, 0, 0); WHEN("We evolve the dynamics") { dynamics.evolve(false); dynamics.evolve(false); @@ -938,7 +920,7 @@ TEST_CASE("Dynamics") { Itinerary itinerary{0, 2}; dynamics.addItinerary(itinerary); dynamics.updatePaths(); - dynamics.addAgents(0, 4, 0); + dynamics.addAgents(4, 0, 0); dynamics.evolve(false); dynamics.evolve(false); double meanSpeed{0.}; @@ -956,7 +938,7 @@ TEST_CASE("Dynamics") { CHECK_EQ(dynamics.streetMeanSpeed(0.2, true).std, 0.); CHECK_EQ(dynamics.streetMeanSpeed(0.2, false).mean, 15.); CHECK_EQ(dynamics.streetMeanSpeed(0.2, false).std, 0.); - dynamics.addAgents(0, 10, 0); + (10, 0, 0); dynamics.evolve(false); meanSpeed = 0.; for (const auto& [agentId, agent] : dynamics.agents()) { @@ -1009,9 +991,9 @@ TEST_CASE("Dynamics") { dynamics.updatePaths(); WHEN("We add agents and evolve the dynamics") { // add an agent in C, D, A - dynamics.addAgent(Agent(0, 0, 4)); - dynamics.addAgent(Agent(1, 0, 3)); - dynamics.addAgent(Agent(2, 0, 1)); + dynamics.addAgent(0, 0, 4); + dynamics.addAgent(1, 0, 3); + dynamics.addAgent(2, 0, 1); dynamics.evolve(false); dynamics.evolve(false); dynamics.evolve(false); @@ -1031,9 +1013,9 @@ TEST_CASE("Dynamics") { } } WHEN("We add agents of another itinerary and update the dynamics") { - dynamics.addAgent(Agent(0, 1, 2)); - dynamics.addAgent(Agent(1, 1, 3)); - dynamics.addAgent(Agent(2, 1, 4)); + dynamics.addAgent(0, 1, 2); + dynamics.addAgent(1, 1, 3); + dynamics.addAgent(2, 1, 4); dynamics.evolve(false); dynamics.evolve(false); dynamics.evolve(false); @@ -1067,7 +1049,7 @@ TEST_CASE("Dynamics") { Itinerary itinerary{0, 2}; dynamics.addItinerary(itinerary); dynamics.updatePaths(); - dynamics.addAgent(Agent(0, 0, 0)); + dynamics.addAgent(0, 0, 0); WHEN("We evolve the dynamics") { dynamics.evolve(false); dynamics.evolve(false); @@ -1099,7 +1081,7 @@ TEST_CASE("Dynamics") { Itinerary itinerary{0, 2}; dynamics.addItinerary(itinerary); dynamics.updatePaths(); - dynamics.addAgent(Agent(0, 0, 0)); + dynamics.addAgent(0, 0, 0); WHEN("We evolve the dynamics") { dynamics.evolve(false); dynamics.evolve(false);