Skip to content

Commit eb83c88

Browse files
authored
Merge pull request #385 from physycom/priority
Make priority attribute boolean and bugfixing traffic lights
2 parents 953ae8d + 6a0955b commit eb83c88

File tree

10 files changed

+655
-240
lines changed

10 files changed

+655
-240
lines changed

examples/slow_charge_tl.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ int main(int argc, char** argv) {
150150
}
151151
graph.adjustNodeCapacities();
152152
std::cout << "Setting traffic light parameters..." << '\n';
153-
graph.initTrafficLights();
153+
graph.autoInitTrafficLights();
154154
std::cout << "Done." << std::endl;
155155

156156
std::cout << "Creating dynamics...\n";

src/dsf/bindings.cpp

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -165,13 +165,18 @@ PYBIND11_MODULE(dsf_cpp, m) {
165165
"adjustNodeCapacities",
166166
&dsf::mobility::RoadNetwork::adjustNodeCapacities,
167167
dsf::g_docstrings.at("dsf::mobility::RoadNetwork::adjustNodeCapacities").c_str())
168-
.def("initTrafficLights",
169-
&dsf::mobility::RoadNetwork::initTrafficLights,
170-
pybind11::arg("minGreenTime") = 30,
171-
dsf::g_docstrings.at("dsf::mobility::RoadNetwork::initTrafficLights").c_str())
168+
.def("autoInitTrafficLights",
169+
&dsf::mobility::RoadNetwork::autoInitTrafficLights,
170+
pybind11::arg("mainRoadPercentage") = 0.6,
171+
dsf::g_docstrings.at("dsf::mobility::RoadNetwork::autoInitTrafficLights")
172+
.c_str())
172173
.def("autoMapStreetLanes",
173174
&dsf::mobility::RoadNetwork::autoMapStreetLanes,
174175
dsf::g_docstrings.at("dsf::mobility::RoadNetwork::autoMapStreetLanes").c_str())
176+
.def("autoAssignRoadPriorities",
177+
&dsf::mobility::RoadNetwork::autoAssignRoadPriorities,
178+
dsf::g_docstrings.at("dsf::mobility::RoadNetwork::autoAssignRoadPriorities")
179+
.c_str())
175180
.def("setStreetStationaryWeights",
176181
&dsf::mobility::RoadNetwork::setStreetStationaryWeights,
177182
pybind11::arg("weights"),

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 = 4;
8-
static constexpr uint8_t DSF_VERSION_MINOR = 6;
9-
static constexpr uint8_t DSF_VERSION_PATCH = 2;
8+
static constexpr uint8_t DSF_VERSION_MINOR = 7;
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/mobility/Road.cpp

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,7 @@ namespace dsf::mobility {
2222
m_length{length},
2323
m_maxSpeed{maxSpeed},
2424
m_nLanes{nLanes},
25-
m_name{std::move(name)},
26-
m_priority{nLanes * 100} {
25+
m_name{std::move(name)} {
2726
if (!(length > 0.)) {
2827
throw std::invalid_argument(
2928
std::format("The length of a road ({}) must be greater than 0.", length));
@@ -84,10 +83,6 @@ namespace dsf::mobility {
8483
}
8584
m_transportCapacity = transportCapacity;
8685
}
87-
void Road::setPriority(int priority) {
88-
assert(priority >= 0);
89-
m_priority = priority;
90-
}
9186
Direction Road::turnDirection(double const& previousStreetAngle) const {
9287
auto const deltaAngle{this->deltaAngle(previousStreetAngle)};
9388
if (std::abs(deltaAngle) >= std::numbers::pi) {

src/dsf/mobility/Road.hpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ namespace dsf::mobility {
2626
int m_capacity;
2727
double m_transportCapacity;
2828
std::string m_name;
29-
int m_priority;
29+
bool m_hasPriority = false;
3030
std::set<Id> m_forbiddenTurns; // Stores the forbidden turns (road ids)
3131
std::optional<RoadType> m_roadType{std::nullopt};
3232

@@ -70,9 +70,8 @@ namespace dsf::mobility {
7070
/// @param transportCapacity The transport capacity
7171
/// @throws std::invalid_argument If the transport capacity is less or equal to 0
7272
void setTransportCapacity(double transportCapacity);
73-
/// @brief Set the road's priority
74-
/// @param priority The road's priority
75-
void setPriority(int priority);
73+
/// @brief Set the road's priority to true
74+
inline void setPriority() { m_hasPriority = true; }
7675
/// @brief Add a road id to the forbidden turns
7776
/// @param roadId The road id to add
7877
void addForbiddenTurn(Id roadId);
@@ -102,8 +101,8 @@ namespace dsf::mobility {
102101
/// @return std::string The name
103102
inline auto const& name() const noexcept { return m_name; }
104103
/// @brief Get the priority
105-
/// @return int The priority
106-
inline auto priority() const noexcept { return m_priority; }
104+
/// @return bool Whether the road has priority
105+
inline auto hasPriority() const noexcept { return m_hasPriority; }
107106
/// @brief Get the road's forbidden turns
108107
/// @return std::set<Id> The road's forbidden turns
109108
/// @details The forbidden turns are the road ids that are not allowed to be used by the agents

0 commit comments

Comments
 (0)