Skip to content

Commit 90b9584

Browse files
authored
Handle u-turns in updatePaths function (#279)
* Try to fix * Last fix * Update version * Revert * Less lines
1 parent a7667da commit 90b9584

File tree

5 files changed

+15
-12
lines changed

5 files changed

+15
-12
lines changed

README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,7 @@ pip install -r ./requirements.txt
3636
## Installation
3737
The library can be installed using CMake. To build and install the project in the default folder run:
3838
```shell
39-
cmake -B build -DCMAKE_BUILD_TYPE=Release
40-
cmake --build build
39+
cmake -B build -DCMAKE_BUILD_TYPE=Release && cmake --build build
4140
sudo cmake --install build
4241
```
4342
Otherwise, it is possible to customize the installation path:

src/dsm/dsm.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
static constexpr uint8_t DSM_VERSION_MAJOR = 2;
88
static constexpr uint8_t DSM_VERSION_MINOR = 5;
9-
static constexpr uint8_t DSM_VERSION_PATCH = 8;
9+
static constexpr uint8_t DSM_VERSION_PATCH = 9;
1010

1111
static auto const DSM_VERSION =
1212
std::format("{}.{}.{}", DSM_VERSION_MAJOR, DSM_VERSION_MINOR, DSM_VERSION_PATCH);

src/dsm/headers/RoadDynamics.hpp

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -400,25 +400,25 @@ namespace dsm {
400400
return;
401401
}
402402
}
403-
403+
Logger::info(std::format("Threshold {}", m_weightTreshold));
404404
auto const destinationID = pItinerary->destination();
405-
std::vector<double> shortestDistances(this->graph().nNodes());
405+
std::vector<DijkstraResult> shortestPaths(this->graph().nNodes());
406406
tbb::parallel_for_each(
407407
this->graph().nodes().cbegin(),
408408
this->graph().nodes().cend(),
409-
[this, &shortestDistances, &destinationID](auto const& it) -> void {
409+
[this, &shortestPaths, &destinationID](auto const& it) -> void {
410410
auto const nodeId{it.first};
411411
if (nodeId == destinationID) {
412-
shortestDistances[nodeId] = -1.;
412+
shortestPaths[nodeId] = DijkstraResult{};
413413
} else {
414414
auto result =
415415
this->graph().shortestPath(nodeId, destinationID, m_weightFunction);
416416
if (result.has_value()) {
417-
shortestDistances[nodeId] = result.value().distance();
417+
shortestPaths[nodeId] = *result;
418418
} else {
419419
Logger::warning(std::format(
420420
"No path found from node {} to node {}", nodeId, destinationID));
421-
shortestDistances[nodeId] = -1.;
421+
shortestPaths[nodeId] = DijkstraResult{};
422422
}
423423
}
424424
});
@@ -429,7 +429,7 @@ namespace dsm {
429429
continue;
430430
}
431431
// save the minimum distance between i and the destination
432-
const auto minDistance{shortestDistances[nodeId]};
432+
const auto minDistance{shortestPaths[nodeId].distance()};
433433
if (minDistance < 0.) {
434434
continue;
435435
}
@@ -451,10 +451,13 @@ namespace dsm {
451451
}
452452
continue;
453453
}
454-
auto const distance{shortestDistances[nextNodeId]};
454+
auto const distance{shortestPaths[nextNodeId].distance()};
455455
if (distance < 0.) {
456456
continue;
457457
}
458+
if (shortestPaths[nextNodeId].path()[1] == nodeId && !node->isRoundabout()) {
459+
continue;
460+
}
458461
bool const bIsMinDistance{
459462
std::abs(m_weightFunction(&this->graph(), nodeId, nextNodeId) + distance -
460463
minDistance) <

src/dsm/sources/DijkstraWeights.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ namespace dsm {
1515
const auto length{(*street)->length()};
1616
const auto speed{(*street)->maxSpeed() *
1717
(1. - (*street)->nAgents() / (*street)->capacity())};
18-
return length / speed;
18+
return std::ceil(length / speed);
1919
}
2020
} // namespace weight_functions
2121

src/dsm/utility/DijkstraResult.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ namespace dsm {
1818
double m_distance;
1919

2020
public:
21+
DijkstraResult() : m_path{}, m_distance{-1.} {}
2122
/// @brief Construct a new DijkstraResult object
2223
/// @param path, A vector of the ids of the nodes in the path
2324
/// @param distance, The distance of the path

0 commit comments

Comments
 (0)