Skip to content

Commit

Permalink
fix minsk bug
Browse files Browse the repository at this point in the history
  • Loading branch information
Daoortor committed Dec 9, 2024
1 parent dd89ccd commit 5cbf874
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
2 changes: 2 additions & 0 deletions models/include/transportSystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ struct TransportSystem {
TransportSystem() = default;
// Construct a transport system from JSON data
explicit TransportSystem(const QDir &sourceDir);
void initStopById();
void initStopByName();
void initStopNamesAutomaton();
// Check if all pointers point inside corresponding containers
[[nodiscard]] bool isValid() const;
Expand Down
13 changes: 12 additions & 1 deletion models/src/transportSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,18 @@ TransportSystem::TransportSystem(const QDir &sourceDir) {
cout << "Transport system loaded" << endl;
}

void TransportSystem::initStopById() {
for (auto &stop : stops) {
stopById[stop.id] = &stop;
}
}

void TransportSystem::initStopByName() {
for (auto &stop : stops) {
stopByName[stop.name] = &stop;
}
}

void TransportSystem::initStopNamesAutomaton() {
std::vector<QString> stationNames;
stationNames.reserve(stops.size());
Expand All @@ -163,7 +175,6 @@ void TransportSystem::initStopNamesAutomaton() {
stopNamesAutomaton = SuffixAutomaton(stationNames);
}


bool TransportSystem::isValid() const {
bool routesAreValid = ranges::all_of(routes.begin(), routes.end(), [&](const Route &route) {
return route.stopTimes >= &*stopTimes.begin() && route.stopTimes < &*stopTimes.end() &&
Expand Down
3 changes: 3 additions & 0 deletions test/test-data/minsk-subway.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,9 @@ TransportSystem makeMinskSubway() {
}
start += route.tripCount * route.stopCount;
}
subway.initStopById();
subway.initStopByName();
subway.initStopNamesAutomaton();

return subway;
}
Expand Down

0 comments on commit 5cbf874

Please sign in to comment.