Skip to content

Commit e027caf

Browse files
authored
Change input/output notation to origin/destination (#309)
* Change input/output notation to origin/destination * Removing unused functions * Update version and docs
1 parent 9120d66 commit e027caf

File tree

6 files changed

+44
-132
lines changed

6 files changed

+44
-132
lines changed

src/dsf/dsf.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
#include <format>
66

77
static constexpr uint8_t DSF_VERSION_MAJOR = 3;
8-
static constexpr uint8_t DSF_VERSION_MINOR = 1;
9-
static constexpr uint8_t DSF_VERSION_PATCH = 1;
8+
static constexpr uint8_t DSF_VERSION_MINOR = 2;
9+
static constexpr uint8_t DSF_VERSION_PATCH = 0;
1010

1111
static auto const DSF_VERSION =
1212
std::format("{}.{}.{}", DSF_VERSION_MAJOR, DSF_VERSION_MINOR, DSF_VERSION_PATCH);

src/dsf/headers/RoadDynamics.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,7 @@ namespace dsf {
392392
}
393393
Logger::info(std::format("Cache enabled (default folder is {})", g_cacheFolder));
394394
}
395-
for (const auto& nodeId : this->graph().outputNodes()) {
395+
for (const auto& nodeId : this->graph().destinationNodes()) {
396396
this->addItinerary(nodeId, nodeId);
397397
}
398398
// updatePaths();
@@ -1361,10 +1361,10 @@ namespace dsf {
13611361
void RoadDynamics<delay_t>::addAgentsRandomly(
13621362
Size nAgents, const std::variant<std::monostate, size_t, double> minNodeDistance) {
13631363
std::unordered_map<Id, double> src_weights, dst_weights;
1364-
for (auto const& id : this->graph().inputNodes()) {
1364+
for (auto const& id : this->graph().originNodes()) {
13651365
src_weights[id] = 1.;
13661366
}
1367-
for (auto const& id : this->graph().outputNodes()) {
1367+
for (auto const& id : this->graph().destinationNodes()) {
13681368
dst_weights[id] = 1.;
13691369
}
13701370
addAgentsRandomly(nAgents, src_weights, dst_weights, minNodeDistance);

src/dsf/headers/RoadNetwork.hpp

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@ namespace dsf {
4949
class RoadNetwork : public Network<RoadJunction, Street> {
5050
private:
5151
std::unordered_map<std::string, Id> m_nodeMapping;
52-
std::vector<Id> m_inputNodes;
53-
std::vector<Id> m_outputNodes;
52+
std::vector<Id> m_originNodes;
53+
std::vector<Id> m_destinationNodes;
5454
unsigned long long m_maxAgentCapacity;
5555

5656
/// @brief Reassign the street ids using the max node id
@@ -111,6 +111,15 @@ namespace dsf {
111111
/// @brief Import the graph's nodes from a file
112112
/// @param fileName The name of the file to import the nodes from.
113113
/// @throws std::invalid_argument if the file is not found, invalid or the format is not supported
114+
/// @details The file format is csv-like with the ';' separator. Supported columns (in order):
115+
/// - id: The id of the node
116+
/// - lon: The x coordinate of the node
117+
/// - lat: The y coordinate of the node
118+
/// - type: The type of the node
119+
/// The node type can be one of the following:
120+
/// - traffic_signals: intersection + traffic light
121+
/// - roundabout
122+
/// - origin/destination: intesection counted as origin, destination or both. To have both, the string must contain both the strings "origin" and "destination".
114123
void importOSMNodes(const std::string& fileName);
115124
/// @brief Import the graph's streets from a file
116125
/// @param fileName The name of the file to import the streets from.
@@ -226,18 +235,20 @@ namespace dsf {
226235
return m_nodeMapping;
227236
}
228237

229-
/// @brief Get the input nodes of the graph
230-
/// @return std::vector<Id> const& The input nodes of the graph
231-
inline std::vector<Id> const& inputNodes() const noexcept { return m_inputNodes; }
232-
/// @brief Get the input nodes of the graph
233-
/// @return std::vector<Id>& The input nodes of the graph
234-
inline std::vector<Id>& inputNodes() noexcept { return m_inputNodes; }
235-
/// @brief Get the output nodes of the graph
236-
/// @return std::vector<Id> const& The output nodes of the graph
237-
inline std::vector<Id> const& outputNodes() const noexcept { return m_outputNodes; }
238-
/// @brief Get the output nodes of the graph
239-
/// @return std::vector<Id>& The output nodes of the graph
240-
inline std::vector<Id>& outputNodes() noexcept { return m_outputNodes; }
238+
/// @brief Get the origin nodes of the graph
239+
/// @return std::vector<Id> const& The origin nodes of the graph
240+
inline std::vector<Id> const& originNodes() const noexcept { return m_originNodes; }
241+
/// @brief Get the origin nodes of the graph
242+
/// @return std::vector<Id>& The origin nodes of the graph
243+
inline std::vector<Id>& originNodes() noexcept { return m_originNodes; }
244+
/// @brief Get the destination nodes of the graph
245+
/// @return std::vector<Id> const& The destination nodes of the graph
246+
inline std::vector<Id> const& destinationNodes() const noexcept {
247+
return m_destinationNodes;
248+
}
249+
/// @brief Get the destination nodes of the graph
250+
/// @return std::vector<Id>& The destination nodes of the graph
251+
inline std::vector<Id>& destinationNodes() noexcept { return m_destinationNodes; }
241252

242253
/// @brief Get the shortest path between two nodes using dijkstra algorithm
243254
/// @param source The source node

src/dsf/headers/TrafficLight.hpp

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -78,25 +78,9 @@ namespace dsf {
7878
~TrafficLight() = default;
7979

8080
TrafficLight& operator++();
81-
/// @brief Get the maximum green time over every cycle
82-
/// @param priorityStreets bool, if true, only the priority streets are considered;
83-
/// if false, only the non-priority streets are considered
84-
/// @return Delay The maximum green time
85-
/// @details The maximum green time is the maximum green time of all the cycles for
86-
/// the priority streets if priorityStreets is true, or for the non-priority
87-
/// streets if priorityStreets is false.
8881

8982
static void setAllowFreeTurns(bool allow);
9083

91-
Delay maxGreenTime(bool priorityStreets) const;
92-
/// @brief Get the minimum green time over every cycle
93-
/// @param priorityStreets bool, if true, only the priority streets are considered;
94-
/// if false, only the non-priority streets are considered
95-
/// @return Delay The minimum green time
96-
/// @details The minimum green time is the minimum green time of all the cycles for
97-
/// the priority streets if priorityStreets is true, or for the non-priority
98-
/// streets if priorityStreets is false.
99-
Delay minGreenTime(bool priorityStreets) const;
10084
/// @brief Get the mean green time over every cycle
10185
/// @param priorityStreets bool, if true, only the priority streets are considered;
10286
/// if false, only the non-priority streets are considered
@@ -132,12 +116,6 @@ namespace dsf {
132116
/// @param oldStreetId Id, the old street id
133117
/// @param newStreetId Id, the new street id
134118
void moveCycle(Id const oldStreetId, Id const newStreetId);
135-
/// @brief Increase the green times of the traffic light for priority streets and decrease the green times for non-priority streets
136-
/// @param delta Delay, the time to increase or decrease the green times
137-
void increaseGreenTimes(Delay const delta);
138-
/// @brief Decrease the green times of the traffic light for priority streets and increase the green times for non-priority streets
139-
/// @param delta Delay, the time to increase or decrease the green times
140-
void decreaseGreenTimes(Delay const delta);
141119
/// @brief Increase the phase times of the traffic light cycles
142120
/// @param phase Delay, the amount of time to increase the phase for each cycle
143121
void increasePhases(Delay const phase);
@@ -155,10 +133,6 @@ namespace dsf {
155133
/// @param direction Direction, the direction
156134
/// @return true if the traffic light is green for the street and direction
157135
bool isGreen(Id const streetId, Direction direction) const;
158-
/// @brief Returns true if the traffic light has green increased for all the cycles with priority
159-
/// @param priority bool, if true, only the priority streets are considered; else, only the non-priority streets are considered
160-
/// @return true if the traffic light has green increased for all the cycles with priority
161-
bool isFavouringDirection(bool const priority) const;
162136
/// @brief Resets all traffic light cycles
163137
/// @details For more info, see @ref TrafficLightCycle::reset()
164138
void resetCycles();

src/dsf/sources/RoadNetwork.cpp

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -768,15 +768,14 @@ namespace dsf {
768768
} else {
769769
addNode<Intersection>(nodeIndex,
770770
std::make_pair(std::stod(lat), std::stod(lon)));
771-
if ((highway.find("in_out") != std::string::npos) ||
772-
(highway.find("outgoing_only") != std::string::npos)) {
773-
Logger::debug(std::format("Setting node {} as an output node", nodeIndex));
774-
m_outputNodes.push_back(nodeIndex);
771+
if (highway.find("destination") != std::string::npos) {
772+
Logger::debug(
773+
std::format("Setting node {} as a destination node", nodeIndex));
774+
m_destinationNodes.push_back(nodeIndex);
775775
}
776-
if ((highway.find("in_out") != std::string::npos) ||
777-
(highway.find("ingoing_only") != std::string::npos)) {
778-
Logger::debug(std::format("Setting node {} as an input node", nodeIndex));
779-
m_inputNodes.push_back(nodeIndex);
776+
if (highway.find("origin") != std::string::npos) {
777+
Logger::debug(std::format("Setting node {} as an origin node", nodeIndex));
778+
m_originNodes.push_back(nodeIndex);
780779
}
781780
}
782781
m_nodeMapping.emplace(std::make_pair(id, nodeIndex));
@@ -1056,11 +1055,13 @@ namespace dsf {
10561055
file << ";traffic_light";
10571056
} else if (pNode->isRoundabout()) {
10581057
file << ";roundabout";
1059-
} else if (std::find(m_inputNodes.begin(), m_inputNodes.end(), nodeId) !=
1060-
m_inputNodes.end() ||
1061-
std::find(m_outputNodes.begin(), m_outputNodes.end(), nodeId) !=
1062-
m_outputNodes.end()) {
1063-
file << ";io";
1058+
} else if (std::find(m_originNodes.begin(), m_originNodes.end(), nodeId) !=
1059+
m_originNodes.end()) {
1060+
file << ";origin";
1061+
} else if (std::find(m_destinationNodes.begin(),
1062+
m_destinationNodes.end(),
1063+
nodeId) != m_destinationNodes.end()) {
1064+
file << ";destination";
10641065
} else {
10651066
file << ";";
10661067
}

src/dsf/sources/TrafficLight.cpp

Lines changed: 0 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -71,38 +71,6 @@ namespace dsf {
7171
return *this;
7272
}
7373

74-
Delay TrafficLight::maxGreenTime(bool priorityStreets) const {
75-
Delay maxTime{0};
76-
for (auto const& [streetId, cycles] : m_cycles) {
77-
if (priorityStreets && m_streetPriorities.contains(streetId)) {
78-
for (auto const& [direction, cycle] : cycles) {
79-
maxTime = std::max(maxTime, cycle.greenTime());
80-
}
81-
} else {
82-
for (auto const& [direction, cycle] : cycles) {
83-
maxTime = std::max(maxTime, cycle.greenTime());
84-
}
85-
}
86-
}
87-
return maxTime;
88-
}
89-
90-
Delay TrafficLight::minGreenTime(bool priorityStreets) const {
91-
Delay minTime{std::numeric_limits<Delay>::max()};
92-
for (auto const& [streetId, cycles] : m_cycles) {
93-
if (priorityStreets && m_streetPriorities.contains(streetId)) {
94-
for (auto const& [direction, cycle] : cycles) {
95-
minTime = std::min(minTime, cycle.greenTime());
96-
}
97-
} else {
98-
for (auto const& [direction, cycle] : cycles) {
99-
minTime = std::min(minTime, cycle.greenTime());
100-
}
101-
}
102-
}
103-
return minTime;
104-
}
105-
10674
double TrafficLight::meanGreenTime(bool priorityStreets) const {
10775
double meanTime{0.};
10876
size_t nCycles{0};
@@ -123,20 +91,6 @@ namespace dsf {
12391
return meanTime / nCycles;
12492
}
12593

126-
void TrafficLight::increaseGreenTimes(Delay const delta) {
127-
for (auto& [streetId, cycles] : m_cycles) {
128-
if (m_streetPriorities.contains(streetId)) {
129-
for (auto& [direction, cycle] : cycles) {
130-
cycle = TrafficLightCycle(cycle.greenTime() + delta, cycle.phase());
131-
}
132-
} else {
133-
for (auto& [direction, cycle] : cycles) {
134-
cycle = TrafficLightCycle(cycle.greenTime() - delta, cycle.phase() + delta);
135-
}
136-
}
137-
}
138-
}
139-
14094
void TrafficLight::increasePhases(Delay const phase) {
14195
for (auto& [streetId, cycles] : m_cycles) {
14296
for (auto& [direction, cycle] : cycles) {
@@ -147,20 +101,6 @@ namespace dsf {
147101
}
148102
}
149103

150-
void TrafficLight::decreaseGreenTimes(Delay const delta) {
151-
for (auto& [streetId, cycles] : m_cycles) {
152-
if (!m_streetPriorities.contains(streetId)) {
153-
for (auto& [direction, cycle] : cycles) {
154-
cycle = TrafficLightCycle(cycle.greenTime() + delta, cycle.phase());
155-
}
156-
} else {
157-
for (auto& [direction, cycle] : cycles) {
158-
cycle = TrafficLightCycle(cycle.greenTime() - delta, cycle.phase() + delta);
159-
}
160-
}
161-
}
162-
}
163-
164104
bool TrafficLight::isDefault() const {
165105
for (auto const& [streetId, cycles] : m_cycles) {
166106
for (auto const& [direction, cycle] : cycles) {
@@ -228,20 +168,6 @@ namespace dsf {
228168
return m_cycles.at(streetId).at(direction).isGreen(m_cycleTime, m_counter);
229169
}
230170

231-
bool TrafficLight::isFavouringDirection(bool const priority) const {
232-
for (auto const& [streetId, cycles] : m_cycles) {
233-
if ((priority && m_streetPriorities.contains(streetId)) ||
234-
(!priority && !m_streetPriorities.contains(streetId))) {
235-
for (auto const& [direction, cycle] : cycles) {
236-
if (!cycle.isGreenTimeIncreased()) {
237-
return false;
238-
}
239-
}
240-
}
241-
}
242-
return true;
243-
}
244-
245171
void TrafficLight::resetCycles() {
246172
m_defaultCycles.empty() ? m_defaultCycles = m_cycles : m_cycles = m_defaultCycles;
247173
}

0 commit comments

Comments
 (0)