Skip to content

Commit 89d7f14

Browse files
committed
return all stops progress
1 parent 062951a commit 89d7f14

File tree

7 files changed

+49
-31
lines changed

7 files changed

+49
-31
lines changed

connection_scan_algorithm/include/calculator.hpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,9 +121,10 @@ namespace TrRouting
121121
std::vector<int> tripsUsable; // after forwarrd calculation, keep a list of usable trips in time range for reverse calculation
122122
std::vector<std::tuple<int,int,int,int,int,short,short,int>> forwardConnections; // tuple: departureStopIndex, arrivalStopIndex, departureTimeSeconds, arrivalTimeSeconds, tripIndex, canBoard, canUnboard, sequence in trip
123123
std::vector<std::tuple<int,int,int,int,int,short,short,int>> reverseConnections; // tuple: departureStopIndex, arrivalStopIndex, departureTimeSeconds, arrivalTimeSeconds, tripIndex, canBoard, canUnboard, sequence in trip
124-
std::vector<std::pair<int,int>> accessFootpaths; // tuple: accessStopIndex, walkingTravelTimeSeconds
125-
std::vector<std::pair<int,int>> egressFootpaths; // tuple: egressStopIndex, walkingTravelTimeSeconds
124+
std::vector<std::pair<int,int>> accessFootpaths; // pair: accessStopIndex, walkingTravelTimeSeconds
125+
std::vector<std::pair<int,int>> egressFootpaths; // pair: egressStopIndex, walkingTravelTimeSeconds
126126
std::vector<std::tuple<int,int,int,int,int,short>> forwardJourneys; // index = stop index, tuple: final enter connection, final exit connection, final footpath, final exit trip index, transfer travel time, is same stop transfer (first, second, third and fourth values = -1 for access and egress journeys)
127+
std::vector<std::tuple<int,int,int,int,int,short>> forwardEgressJourneys; // index = stop index, tuple: final enter connection, final exit connection, final footpath, final exit trip index, transfer travel time, is same stop transfer (first, second, third and fourth values = -1 for access and egress journeys)
127128
std::vector<std::tuple<int,int,int,int,int,short>> reverseJourneys; // index = stop index, tuple: final enter connection, final exit connection, final footpath, final exit trip index, transfer travel time, is same stop transfer (first, second, third and fourth values = -1 for access and egress journeys)
128129
int maxTimeValue;
129130
int minAccessTravelTime;

connection_scan_algorithm/src/forward_calculation.cpp

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ namespace TrRouting
4444
connectionDepartureTime = std::get<connectionIndexes::TIME_DEP>(connection);
4545

4646
// no need to parse next connections if already reached destination from all egress stops:
47-
if ( (!params.returnAllStopsResult && reachedAtLeastOneEgressStop && maxEgressTravelTime >= 0 && connectionDepartureTime > tentativeEgressStopArrivalTime + maxEgressTravelTime) || (connectionDepartureTime - departureTimeSeconds > params.maxTotalTravelTimeSeconds))
47+
if ( (!params.returnAllStopsResult && reachedAtLeastOneEgressStop && maxEgressTravelTime >= 0 && tentativeEgressStopArrivalTime < MAX_INT && connectionDepartureTime > tentativeEgressStopArrivalTime + maxEgressTravelTime) || (connectionDepartureTime - departureTimeSeconds > params.maxTotalTravelTimeSeconds))
4848
{
4949
break;
5050
}
@@ -95,6 +95,10 @@ namespace TrRouting
9595
{
9696
stopsTentativeTime[footpathStopArrivalIndex] = footpathTravelTime + connectionArrivalTime + params.minWaitingTimeSeconds;
9797
forwardJourneys[footpathStopArrivalIndex] = std::make_tuple(tripsEnterConnection[tripIndex], i, footpathIndex, tripIndex, footpathTravelTime, (stopArrivalIndex == footpathStopArrivalIndex ? 1 : -1));
98+
if (stopArrivalIndex == footpathStopArrivalIndex)
99+
{
100+
forwardEgressJourneys[footpathStopArrivalIndex] = forwardJourneys[footpathStopArrivalIndex];
101+
}
98102
}
99103
footpathIndex++;
100104
}
@@ -109,18 +113,28 @@ namespace TrRouting
109113

110114
std::cerr << "-- " << reachableConnectionsCount << " forward connections parsed on " << connectionsCount << std::endl;
111115

112-
116+
int egressStopArrivalTime {-1};
117+
int egressExitConnection {-1};
118+
int egressTravelTime {-1};
113119
// find best egress stop:
114120
if (!params.returnAllStopsResult)
115121
{
116122
i = 0;
117-
for (auto & arrivalTime : stopsTentativeTime)
123+
for (auto & egressFootpath : egressFootpaths)
118124
{
119-
if (stopsEgressTravelTime[i] >= 0 && arrivalTime < MAX_INT && arrivalTime + stopsEgressTravelTime[i] < bestArrivalTime)
125+
//std::cerr << stops[egressFootpath.first].name << std::endl;
126+
egressExitConnection = std::get<1>(forwardEgressJourneys[egressFootpath.first]);
127+
if (egressExitConnection != -1)
120128
{
121-
bestArrivalTime = arrivalTime + stopsEgressTravelTime[i];
122-
bestEgressStopIndex = i;
123-
bestEgressTravelTime = stopsEgressTravelTime[i];
129+
egressTravelTime = stopsEgressTravelTime[egressFootpath.first];
130+
egressStopArrivalTime = std::get<connectionIndexes::TIME_ARR>(forwardConnections[egressExitConnection]) + egressTravelTime;
131+
//std::cerr << egressTravelTime << " - " << egressStopArrivalTime << std::endl;
132+
if (egressStopArrivalTime >= 0 && egressStopArrivalTime < MAX_INT && egressStopArrivalTime < bestArrivalTime)
133+
{
134+
bestArrivalTime = egressStopArrivalTime;
135+
bestEgressStopIndex = egressFootpath.first;
136+
bestEgressTravelTime = egressTravelTime;
137+
}
124138
}
125139
i++;
126140
}

connection_scan_algorithm/src/forward_journey.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ namespace TrRouting
7070

7171
//std::cerr << stops[resultingStopIndex].name << " : " << std::get<0>(forwardJourneys[resultingStopIndex]) << std::endl;
7272
// recreate journey:
73-
resultingStopJourneyStep = forwardJourneys[resultingStopIndex];
73+
resultingStopJourneyStep = forwardEgressJourneys[resultingStopIndex];
7474

7575
if (resultingStopJourneyStep == emptyJourneyStep) // ignore stops with no route
7676
{
@@ -238,9 +238,9 @@ namespace TrRouting
238238
stepJson["type"] = "egress";
239239
stepJson["travelTimeSeconds"] = transferTime;
240240
stepJson["travelTimeMinutes"] = Toolbox::convertSecondsToMinutes(transferTime);
241-
stepJson["departureTime"] = Toolbox::convertSecondsToFormattedTime(departureTimeSeconds);
241+
stepJson["departureTime"] = Toolbox::convertSecondsToFormattedTime(arrivalTime);
242242
stepJson["arrivalTime"] = Toolbox::convertSecondsToFormattedTime(arrivalTime + transferTime);
243-
stepJson["departureTimeSeconds"] = departureTimeSeconds;
243+
stepJson["departureTimeSeconds"] = arrivalTime;
244244
stepJson["arrivalTimeSeconds"] = arrivalTime + transferTime;
245245
json["steps"].push_back(stepJson);
246246
}

connection_scan_algorithm/src/preparations.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ namespace TrRouting
8181
tripsEnabled = std::vector<int>(trips.size());
8282
tripsUsable = std::vector<int>(trips.size());
8383
forwardJourneys = std::vector<std::tuple<int,int,int,int,int,short>>(stops.size());
84+
forwardEgressJourneys = std::vector<std::tuple<int,int,int,int,int,short>>(stops.size());
8485
reverseJourneys = std::vector<std::tuple<int,int,int,int,int,short>>(stops.size());
8586

8687
}

connection_scan_algorithm/src/resets.cpp

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,22 @@ namespace TrRouting
88

99
calculationTime = algorithmCalculationTime.getDurationMicrosecondsNoStop();
1010

11-
std::fill(stopsTentativeTime.begin(), stopsTentativeTime.end(), MAX_INT);
11+
std::fill(stopsTentativeTime.begin(), stopsTentativeTime.end(), MAX_INT);
1212
std::fill(stopsReverseTentativeTime.begin(), stopsReverseTentativeTime.end(), -1);
1313
//std::fill(stopsD.begin(), stopsD.end(), MAX_INT);
1414
//std::fill(stopsReverseTentativeTime.begin(), stopsReverseTentativeTime.end(), std::deque<std::pair<int,int>>(1, std::make_pair(MAX_INT, MAX_INT));
15-
std::fill(stopsAccessTravelTime.begin(), stopsAccessTravelTime.end(), -1);
16-
std::fill(stopsEgressTravelTime.begin(), stopsEgressTravelTime.end(), -1);
17-
std::fill(tripsEnterConnection.begin(), tripsEnterConnection.end(), -1);
18-
std::fill(tripsExitConnection.begin(), tripsExitConnection.end(), -1);
15+
std::fill(stopsAccessTravelTime.begin(), stopsAccessTravelTime.end(), -1);
16+
std::fill(stopsEgressTravelTime.begin(), stopsEgressTravelTime.end(), -1);
17+
std::fill(tripsEnterConnection.begin(), tripsEnterConnection.end(), -1);
18+
std::fill(tripsExitConnection.begin(), tripsExitConnection.end(), -1);
1919
std::fill(tripsEnterConnectionTransferTravelTime.begin(), tripsEnterConnectionTransferTravelTime.end(), MAX_INT);
20-
std::fill(tripsExitConnectionTransferTravelTime.begin(), tripsExitConnectionTransferTravelTime.end(), MAX_INT);
20+
std::fill(tripsExitConnectionTransferTravelTime.begin(), tripsExitConnectionTransferTravelTime.end(), MAX_INT);
2121
//std::fill(tripsReverseTime.begin(), tripsReverseTime.end(), MAX_INT);
22-
std::fill(tripsEnabled.begin(), tripsEnabled.end(), 1);
23-
std::fill(tripsUsable.begin(), tripsUsable.end(), 0);
24-
std::fill(forwardJourneys.begin(), forwardJourneys.end(), std::make_tuple(-1,-1,-1,-1,-1,-1));
25-
std::fill(reverseJourneys.begin(), reverseJourneys.end(), std::make_tuple(-1,-1,-1,-1,-1,-1));
22+
std::fill(tripsEnabled.begin(), tripsEnabled.end(), 1);
23+
std::fill(tripsUsable.begin(), tripsUsable.end(), 0);
24+
std::fill(forwardJourneys.begin(), forwardJourneys.end(), std::make_tuple(-1,-1,-1,-1,-1,-1));
25+
std::fill(forwardEgressJourneys.begin(), forwardEgressJourneys.end(), std::make_tuple(-1,-1,-1,-1,-1,-1));
26+
std::fill(reverseJourneys.begin(), reverseJourneys.end(), std::make_tuple(-1,-1,-1,-1,-1,-1));
2627

2728
accessFootpaths.clear();
2829
egressFootpaths.clear();
@@ -96,8 +97,8 @@ namespace TrRouting
9697
{
9798
maxAccessTravelTime = accessFootpath.second;
9899
}
99-
//result.json += "origin_stop: " + stops[accessFootpath.first].name + " - " + Toolbox::convertSecondsToFormattedTime(stopsTentativeTime[accessFootpath.first]) + "\n";
100-
//result.json += std::to_string(stops[accessFootpath.first].id) + ",";
100+
//std::cerr << "origin_stop: " << stops[accessFootpath.first].name << " - " << Toolbox::convertSecondsToFormattedTime(stopsTentativeTime[accessFootpath.first]) << std::endl;
101+
//std::cerr << std::to_string(stops[accessFootpath.first].id) + ",";
101102
}
102103
}
103104

connection_scan_algorithm/src/reverse_calculation.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,8 @@ namespace TrRouting
5959
// reachable connections only here:
6060
if (tripExitConnectionIndex != -1 || stopArrivalTentativeTime >= connectionArrivalTime)
6161
{
62-
63-
if (std::get<connectionIndexes::CAN_UNBOARD>(connection) == 1 && (tripExitConnectionIndex == -1 || (std::get<0>(reverseJourneys[stopArrivalIndex]) == -1 && std::get<4>(reverseJourneys[stopArrivalIndex]) >= 0 && std::get<4>(reverseJourneys[stopArrivalIndex]) < tripsExitConnectionTransferTravelTime[tripIndex])))
62+
63+
if (std::get<connectionIndexes::CAN_UNBOARD>(connection) == 1 && (tripExitConnectionIndex == -1/* || (std::get<0>(reverseJourneys[stopArrivalIndex]) == -1 && std::get<4>(reverseJourneys[stopArrivalIndex]) >= 0 && std::get<4>(reverseJourneys[stopArrivalIndex]) < tripsExitConnectionTransferTravelTime[tripIndex])*/))
6464
{
6565
tripsExitConnection[tripIndex] = i;
6666
tripsExitConnectionTransferTravelTime[tripIndex] = std::get<4>(reverseJourneys[stopArrivalIndex]);

connection_scan_algorithm/src/reverse_journey.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -76,12 +76,13 @@ namespace TrRouting
7676
{
7777
continue;
7878
}
79-
79+
std::cerr << stops[bestEgressStopIndex].name << std::endl;
8080
i = 0;
8181
while ((std::get<0>(resultingStopJourneyStep) != -1 && std::get<1>(resultingStopJourneyStep) != -1))
8282
{
83-
journey.push_front(resultingStopJourneyStep);
84-
bestEgressStopIndex = std::get<connectionIndexes::STOP_ARR>(reverseConnections[std::get<0>(resultingStopJourneyStep)]);
83+
journey.push_back(resultingStopJourneyStep);
84+
bestEgressStopIndex = std::get<connectionIndexes::STOP_DEP>(reverseConnections[std::get<0>(resultingStopJourneyStep)]);
85+
std::cerr << stops[std::get<connectionIndexes::STOP_DEP>(reverseConnections[std::get<0>(resultingStopJourneyStep)])].name << " > " << stops[std::get<connectionIndexes::STOP_ARR>(reverseConnections[std::get<1>(resultingStopJourneyStep)])].name << std::endl;
8586
resultingStopJourneyStep = reverseJourneys[bestEgressStopIndex];
8687
i++;
8788
}
@@ -103,8 +104,8 @@ namespace TrRouting
103104
if (std::get<0>(journeyStep) != -1 && std::get<1>(journeyStep) != -1)
104105
{
105106
// journey tuple: final enter connection, final exit connection, final footpath
106-
journeyStepEnterConnection = forwardConnections[std::get<0>(journeyStep)];
107-
journeyStepExitConnection = forwardConnections[std::get<1>(journeyStep)];
107+
journeyStepEnterConnection = reverseConnections[std::get<0>(journeyStep)];
108+
journeyStepExitConnection = reverseConnections[std::get<1>(journeyStep)];
108109
journeyStepStopDeparture = stops[std::get<connectionIndexes::STOP_DEP>(journeyStepEnterConnection)];
109110
journeyStepStopArrival = stops[std::get<connectionIndexes::STOP_ARR>(journeyStepExitConnection)];
110111
journeyStepTrip = trips[std::get<3>(journeyStep)];

0 commit comments

Comments
 (0)