Skip to content

Commit 73b3ae0

Browse files
committed
Fix lane assegnation
1 parent c081726 commit 73b3ae0

File tree

1 file changed

+24
-7
lines changed

1 file changed

+24
-7
lines changed

src/dsm/headers/RoadDynamics.hpp

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,15 @@ namespace dsm {
4040
template <typename delay_t>
4141
requires(is_numeric_v<delay_t>)
4242
class RoadDynamics : public Dynamics<Agent<delay_t>> {
43+
private:
4344
protected:
4445
Time m_previousOptimizationTime;
45-
double m_errorProbability;
46+
47+
private:
48+
std::optional<double> m_errorProbability;
4649
std::optional<double> m_passageProbability;
50+
51+
protected:
4752
std::vector<double> m_travelTimes;
4853
std::unordered_map<Id, Id> m_agentNextStreetId;
4954
bool m_forcePriorities;
@@ -163,7 +168,7 @@ namespace dsm {
163168
RoadDynamics<delay_t>::RoadDynamics(Graph& graph, std::optional<unsigned int> seed)
164169
: Dynamics<Agent<delay_t>>(graph, seed),
165170
m_previousOptimizationTime{0},
166-
m_errorProbability{0.},
171+
m_errorProbability{std::nullopt},
167172
m_passageProbability{std::nullopt},
168173
m_forcePriorities{false} {
169174
for (const auto& [streetId, street] : this->m_graph.streetSet()) {
@@ -200,11 +205,13 @@ namespace dsm {
200205
auto possibleMoves = this->m_graph.adjMatrix().getRow(nodeId, true);
201206
if (!pAgent->isRandom()) {
202207
std::uniform_real_distribution<double> uniformDist{0., 1.};
203-
if (this->m_itineraries.size() > 0 &&
204-
uniformDist(this->m_generator) > m_errorProbability) {
205-
const auto& it = this->m_itineraries[pAgent->itineraryId()];
206-
if (it->destination() != nodeId) {
207-
possibleMoves = it->path().getRow(nodeId, true);
208+
if (!(this->itineraries().empty())) {
209+
if (!(m_errorProbability.has_value() &&
210+
uniformDist(this->m_generator) < m_errorProbability)) {
211+
const auto& it = this->m_itineraries[pAgent->itineraryId()];
212+
if (it->destination() != nodeId) {
213+
possibleMoves = it->path().getRow(nodeId, true);
214+
}
208215
}
209216
}
210217
}
@@ -436,6 +443,16 @@ namespace dsm {
436443
for (auto const& queue : street->exitQueues()) {
437444
weights.push_back(1. / (queue.size() + 1));
438445
}
446+
// If all weights are the same, make the last 0
447+
if (std::all_of(weights.begin(), weights.end(), [&](double w) {
448+
return std::abs(w - weights.front()) <
449+
std::numeric_limits<double>::epsilon();
450+
})) {
451+
weights.back() = 0.;
452+
if (nLanes > 2) {
453+
weights.front() = 0.;
454+
}
455+
}
439456
// Normalize the weights
440457
auto const sum = std::accumulate(weights.begin(), weights.end(), 0.);
441458
for (auto& w : weights) {

0 commit comments

Comments
 (0)