Skip to content
Open
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
28 changes: 14 additions & 14 deletions benchmark/Bench_Agent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
std::time_t spawnTime = 0;
for (auto _ : state) {
dsf::mobility::Agent agent(
spawnTime++, std::make_shared<dsf::mobility::Itinerary>(1, 1), 0);
0, 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);
}
}
Expand All @@ -19,57 +19,57 @@
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);
dsf::mobility::Agent agent(0, spawnTime++, trip, 0);
benchmark::DoNotOptimize(agent);
}
}

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<dsf::mobility::Itinerary>(1, 1), 0);
dsf::mobility::Agent agent(0, 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, std::make_shared<dsf::mobility::Itinerary>(1, 1), 0);
dsf::mobility::Agent agent(0, 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, std::make_shared<dsf::mobility::Itinerary>(1, 1), 0);
dsf::mobility::Agent agent(0, 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, std::make_shared<dsf::mobility::Itinerary>(1, 1), 0);
dsf::mobility::Agent agent(0, 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, std::make_shared<dsf::mobility::Itinerary>(1, 1), 0);
dsf::mobility::Agent agent(0, 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, std::make_shared<dsf::mobility::Itinerary>(1, 1), 0);
dsf::mobility::Agent agent(0, 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);
}
Expand All @@ -82,14 +82,14 @@
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);
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<dsf::mobility::Itinerary>(1, 1), 0);
dsf::mobility::Agent agent(0, 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 @@ -100,7 +100,7 @@

// Getter benchmarks - these are inline so very fast
static void BM_Agent_Getters(benchmark::State& state) {
dsf::mobility::Agent agent(0, std::make_shared<dsf::mobility::Itinerary>(1, 1), 0);
dsf::mobility::Agent agent(0, 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 @@ -126,7 +126,7 @@
}

static void BM_Agent_Itinerary(benchmark::State& state) {
dsf::mobility::Agent agent(0, std::make_shared<dsf::mobility::Itinerary>(1, 1), 0);
dsf::mobility::Agent agent(0, 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 const& pItinerary = agent.itinerary();
benchmark::DoNotOptimize(pItinerary);
Expand All @@ -138,7 +138,7 @@
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);
dsf::mobility::Agent agent(0, 0, trip, 0);
for (auto _ : state) {
auto trip = agent.trip();
benchmark::DoNotOptimize(trip);
Expand Down
10 changes: 5 additions & 5 deletions benchmark/Bench_Intersection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
dsf::mobility::Intersection intersection(0);
intersection.setCapacity(100);
auto agent = std::make_unique<dsf::mobility::Agent>(
spawnTime++, std::make_shared<dsf::mobility::Itinerary>(1, 1), 0);
0, 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 @@ -36,7 +36,7 @@
dsf::mobility::Intersection intersection(0);
intersection.setCapacity(100);
auto agent = std::make_unique<dsf::mobility::Agent>(
spawnTime++, std::make_shared<dsf::mobility::Itinerary>(1, 1), 0);
0, 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 @@ -47,7 +47,7 @@
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++, pItinerary, 0);
auto agent = std::make_unique<dsf::mobility::Agent>(0, spawnTime++, pItinerary, 0);
intersection.addAgent(std::move(agent));
}
for (auto _ : state) {
Expand All @@ -62,7 +62,7 @@
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++, pItinerary, 0);
auto agent = std::make_unique<dsf::mobility::Agent>(0, spawnTime++, pItinerary, 0);
intersection.addAgent(std::move(agent));
}
for (auto _ : state) {
Expand All @@ -77,7 +77,7 @@
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++, pItinerary, 0);
auto agent = std::make_unique<dsf::mobility::Agent>(0, spawnTime++, pItinerary, 0);
intersection.addAgent(std::move(agent));
}
for (auto _ : state) {
Expand Down
8 changes: 4 additions & 4 deletions benchmark/Bench_Roundabout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
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++, pItinerary, 0);
auto agent = std::make_unique<dsf::mobility::Agent>(0, spawnTime++, pItinerary, 0);
roundabout.enqueue(std::move(agent));
}
}
Expand All @@ -36,7 +36,7 @@
dsf::mobility::Roundabout roundabout(0);
roundabout.setCapacity(100);
auto agent = std::make_unique<dsf::mobility::Agent>(
spawnTime++, std::make_shared<dsf::mobility::Itinerary>(1, 1), 0);
0, 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 @@ -49,7 +49,7 @@
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++, pItinerary, 0);
auto agent = std::make_unique<dsf::mobility::Agent>(0, spawnTime++, pItinerary, 0);
roundabout.enqueue(std::move(agent));
}
for (auto _ : state) {
Expand All @@ -64,7 +64,7 @@
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++, pItinerary, 0);
auto agent = std::make_unique<dsf::mobility::Agent>(0, spawnTime++, pItinerary, 0);
roundabout.enqueue(std::move(agent));
}
for (auto _ : state) {
Expand Down
20 changes: 10 additions & 10 deletions benchmark/Bench_Street.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ static void BM_Street_AddAgent(benchmark::State& state) {
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++, pItinerary, 0);
auto agent = std::make_unique<dsf::mobility::Agent>(0, spawnTime++, pItinerary, 0);
street.addAgent(std::move(agent));
}
}
Expand All @@ -34,7 +34,7 @@ static void BM_Street_Enqueue(benchmark::State& state) {
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++, pItinerary, 0);
auto agent = std::make_unique<dsf::mobility::Agent>(0, spawnTime++, pItinerary, 0);
street.addAgent(std::move(agent));
}
size_t queueId = 0;
Expand All @@ -51,7 +51,7 @@ static void BM_Street_Dequeue(benchmark::State& state) {
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++, pItinerary, 0);
auto agent = std::make_unique<dsf::mobility::Agent>(0, spawnTime++, pItinerary, 0);
street.addAgent(std::move(agent));
street.enqueue(0);
}
Expand All @@ -69,7 +69,7 @@ static void BM_Street_nAgents(benchmark::State& state) {
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++, pItinerary, 0);
auto agent = std::make_unique<dsf::mobility::Agent>(0, spawnTime++, pItinerary, 0);
street.addAgent(std::move(agent));
if (i % 2 == 0)
street.enqueue(0);
Expand All @@ -85,7 +85,7 @@ static void BM_Street_Density(benchmark::State& state) {
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++, pItinerary, 0);
auto agent = std::make_unique<dsf::mobility::Agent>(0, spawnTime++, pItinerary, 0);
street.addAgent(std::move(agent));
if (i % 2 == 0)
street.enqueue(0);
Expand All @@ -101,7 +101,7 @@ static void BM_Street_nMovingAgents(benchmark::State& state) {
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++, pItinerary, 0);
auto agent = std::make_unique<dsf::mobility::Agent>(0, spawnTime++, pItinerary, 0);
street.addAgent(std::move(agent));
}
for (auto _ : state) {
Expand All @@ -115,7 +115,7 @@ static void BM_Street_nExitingAgents(benchmark::State& state) {
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++, pItinerary, 0);
auto agent = std::make_unique<dsf::mobility::Agent>(0, spawnTime++, pItinerary, 0);
street.addAgent(std::move(agent));
street.enqueue(0);
}
Expand All @@ -141,7 +141,7 @@ static void BM_CoilStreet_AddAgent(benchmark::State& state) {
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++, pItinerary, 0);
auto agent = std::make_unique<dsf::mobility::Agent>(0, spawnTime++, pItinerary, 0);
street.addAgent(std::move(agent));
}
}
Expand All @@ -152,7 +152,7 @@ static void BM_CoilStreet_MeanFlow(benchmark::State& state) {
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++, pItinerary, 0);
auto agent = std::make_unique<dsf::mobility::Agent>(0, spawnTime++, pItinerary, 0);
street.addAgent(std::move(agent));
street.enqueue(0);
if (i % 2 == 0) {
Expand All @@ -171,7 +171,7 @@ static void BM_CoilStreet_Dequeue(benchmark::State& state) {
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++, pItinerary, 0);
auto agent = std::make_unique<dsf::mobility::Agent>(0, spawnTime++, pItinerary, 0);
street.addAgent(std::move(agent));
street.enqueue(0);
}
Expand Down
14 changes: 8 additions & 6 deletions src/dsf/mobility/Agent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,27 @@
#include <utility>

namespace dsf::mobility {
Agent::Agent(std::time_t const& spawnTime,
Agent::Agent(Id const id,
std::time_t const& spawnTime,
std::shared_ptr<Itinerary> itinerary,
std::optional<Id> srcNodeId)
: m_spawnTime{spawnTime},
: m_id{id},
m_spawnTime{spawnTime},
m_freeTime{0},
m_id{0},
m_trip{itinerary != nullptr ? std::vector<std::shared_ptr<Itinerary>>{itinerary}
: std::vector<std::shared_ptr<Itinerary>>{}},
m_srcNodeId{srcNodeId},
m_nextStreetId{std::nullopt},
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<std::shared_ptr<Itinerary>> const& trip,
std::optional<Id> 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},
Expand Down
14 changes: 10 additions & 4 deletions src/dsf/mobility/Agent.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,34 +27,40 @@ 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<std::shared_ptr<Itinerary>> m_trip;
std::optional<Id> m_streetId;
std::optional<Id> m_srcNodeId;
std::optional<Id> m_nextStreetId;
size_t m_itineraryIdx;
std::size_t m_itineraryIdx;
double m_speed;
double m_distance; // Travelled distance
std::optional<double> m_maxDistance; // Maximum distance for stochastic agents
std::optional<std::time_t> m_maxTime; // Maximum time for stochastic agents

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> itinerary = nullptr,
std::optional<Id> 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<std::shared_ptr<Itinerary>> const& trip,
std::optional<Id> 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
Expand Down
Loading
Loading