Skip to content

Commit

Permalink
reverse calcul
Browse files Browse the repository at this point in the history
ation correct
  • Loading branch information
kaligrafy committed Nov 28, 2017
1 parent 89d7f14 commit cccc974
Show file tree
Hide file tree
Showing 7 changed files with 77 additions and 51 deletions.
1 change: 1 addition & 0 deletions connection_scan_algorithm/include/calculator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ namespace TrRouting
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)
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)
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)
std::vector<std::tuple<int,int,int,int,int,short>> reverseAccessJourneys; // 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)
int maxTimeValue;
int minAccessTravelTime;
int maxEgressTravelTime;
Expand Down
16 changes: 9 additions & 7 deletions connection_scan_algorithm/src/forward_calculation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,14 +90,16 @@ namespace TrRouting
{
footpathStopArrivalIndex = std::get<1>(footpaths[footpathIndex]);
footpathTravelTime = std::get<2>(footpaths[footpathIndex]);

if (footpathTravelTime <= params.maxTransferWalkingTravelTimeSeconds && footpathTravelTime + params.minWaitingTimeSeconds + connectionArrivalTime < stopsTentativeTime[footpathStopArrivalIndex])
if (footpathTravelTime <= params.maxTransferWalkingTravelTimeSeconds)
{
stopsTentativeTime[footpathStopArrivalIndex] = footpathTravelTime + connectionArrivalTime + params.minWaitingTimeSeconds;
forwardJourneys[footpathStopArrivalIndex] = std::make_tuple(tripsEnterConnection[tripIndex], i, footpathIndex, tripIndex, footpathTravelTime, (stopArrivalIndex == footpathStopArrivalIndex ? 1 : -1));
if (stopArrivalIndex == footpathStopArrivalIndex)
if (footpathTravelTime + params.minWaitingTimeSeconds + connectionArrivalTime < stopsTentativeTime[footpathStopArrivalIndex])
{
forwardEgressJourneys[footpathStopArrivalIndex] = forwardJourneys[footpathStopArrivalIndex];
stopsTentativeTime[footpathStopArrivalIndex] = footpathTravelTime + connectionArrivalTime + params.minWaitingTimeSeconds;
forwardJourneys[footpathStopArrivalIndex] = std::make_tuple(tripsEnterConnection[tripIndex], i, footpathIndex, tripIndex, footpathTravelTime, (stopArrivalIndex == footpathStopArrivalIndex ? 1 : -1));
}
if (stopArrivalIndex == footpathStopArrivalIndex && (std::get<4>(forwardEgressJourneys[footpathStopArrivalIndex]) == -1 || std::get<connectionIndexes::TIME_ARR>(forwardConnections[std::get<1>(forwardEgressJourneys[footpathStopArrivalIndex])]) > connectionArrivalTime))
{
forwardEgressJourneys[footpathStopArrivalIndex] = std::make_tuple(tripsEnterConnection[tripIndex], i, footpathIndex, tripIndex, footpathTravelTime, 1);
}
}
footpathIndex++;
Expand Down Expand Up @@ -128,7 +130,7 @@ namespace TrRouting
{
egressTravelTime = stopsEgressTravelTime[egressFootpath.first];
egressStopArrivalTime = std::get<connectionIndexes::TIME_ARR>(forwardConnections[egressExitConnection]) + egressTravelTime;
//std::cerr << egressTravelTime << " - " << egressStopArrivalTime << std::endl;
std::cerr << stops[egressFootpath.first].name << ": " << egressTravelTime << " - " << Toolbox::convertSecondsToFormattedTime(egressStopArrivalTime) << std::endl;
if (egressStopArrivalTime >= 0 && egressStopArrivalTime < MAX_INT && egressStopArrivalTime < bestArrivalTime)
{
bestArrivalTime = egressStopArrivalTime;
Expand Down
1 change: 1 addition & 0 deletions connection_scan_algorithm/src/preparations.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ namespace TrRouting
forwardJourneys = std::vector<std::tuple<int,int,int,int,int,short>>(stops.size());
forwardEgressJourneys = std::vector<std::tuple<int,int,int,int,int,short>>(stops.size());
reverseJourneys = std::vector<std::tuple<int,int,int,int,int,short>>(stops.size());
reverseAccessJourneys = std::vector<std::tuple<int,int,int,int,int,short>>(stops.size());

}

Expand Down
2 changes: 1 addition & 1 deletion connection_scan_algorithm/src/resets.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ namespace TrRouting
std::fill(forwardJourneys.begin(), forwardJourneys.end(), std::make_tuple(-1,-1,-1,-1,-1,-1));
std::fill(forwardEgressJourneys.begin(), forwardEgressJourneys.end(), std::make_tuple(-1,-1,-1,-1,-1,-1));
std::fill(reverseJourneys.begin(), reverseJourneys.end(), std::make_tuple(-1,-1,-1,-1,-1,-1));
std::fill(reverseAccessJourneys.begin(), reverseAccessJourneys.end(), std::make_tuple(-1,-1,-1,-1,-1,-1));

accessFootpaths.clear();
egressFootpaths.clear();
Expand Down Expand Up @@ -139,7 +140,6 @@ namespace TrRouting
{
minEgressTravelTime = egressFootpath.second;
}
stopsEgressTravelTime[egressFootpath.first] = egressFootpath.second;
//stopsD[egressFootpath.first] = egressFootpath.second;
//result.json += "origin_stop: " + stops[accessFootpath.first].name + " - " + Toolbox::convertSecondsToFormattedTime(stopsTentativeTime[accessFootpath.first]) + "\n";
//result.json += std::to_string((int)(ceil(egressFootpath.second))) + ",";
Expand Down
39 changes: 28 additions & 11 deletions connection_scan_algorithm/src/reverse_calculation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ namespace TrRouting
for(auto & connection : reverseConnections)
{
// ignore connections before departure time + minimum access travel time:
if (std::get<connectionIndexes::TIME_ARR>(connection) <= arrivalTimeSeconds + minEgressTravelTime)
if (std::get<connectionIndexes::TIME_ARR>(connection) <= arrivalTimeSeconds - minEgressTravelTime)
{
tripIndex = std::get<connectionIndexes::TRIP>(connection);

Expand All @@ -60,7 +60,7 @@ namespace TrRouting
if (tripExitConnectionIndex != -1 || stopArrivalTentativeTime >= connectionArrivalTime)
{

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])*/))
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]))) // <= to make sure we get the same result as forward calculation, which uses >
{
tripsExitConnection[tripIndex] = i;
tripsExitConnectionTransferTravelTime[tripIndex] = std::get<4>(reverseJourneys[stopArrivalIndex]);
Expand All @@ -86,10 +86,17 @@ namespace TrRouting
footpathStopDepartureIndex = std::get<1>(footpaths[footpathIndex]);
footpathTravelTime = std::get<2>(footpaths[footpathIndex]);

if (footpathTravelTime <= params.maxTransferWalkingTravelTimeSeconds && connectionDepartureTime - footpathTravelTime - params.minWaitingTimeSeconds > stopsReverseTentativeTime[footpathStopDepartureIndex])
if (footpathTravelTime <= params.maxTransferWalkingTravelTimeSeconds)
{
stopsReverseTentativeTime[footpathStopDepartureIndex] = connectionDepartureTime - footpathTravelTime - params.minWaitingTimeSeconds;
reverseJourneys[footpathStopDepartureIndex] = std::make_tuple(i, tripsExitConnection[tripIndex], footpathIndex, tripIndex, footpathTravelTime, (stopDepartureIndex == footpathStopDepartureIndex ? 1 : -1));
if (connectionDepartureTime - footpathTravelTime - params.minWaitingTimeSeconds >= stopsReverseTentativeTime[footpathStopDepartureIndex])
{
stopsReverseTentativeTime[footpathStopDepartureIndex] = connectionDepartureTime - footpathTravelTime - params.minWaitingTimeSeconds;
reverseJourneys[footpathStopDepartureIndex] = std::make_tuple(i, tripsExitConnection[tripIndex], footpathIndex, tripIndex, footpathTravelTime, (stopDepartureIndex == footpathStopDepartureIndex ? 1 : -1));
}
if (stopDepartureIndex == footpathStopDepartureIndex && (std::get<4>(reverseAccessJourneys[footpathStopDepartureIndex]) == -1 || std::get<connectionIndexes::TIME_DEP>(reverseConnections[std::get<1>(reverseAccessJourneys[footpathStopDepartureIndex])]) <= connectionDepartureTime))
{
reverseAccessJourneys[footpathStopDepartureIndex] = std::make_tuple(i, tripsExitConnection[tripIndex], footpathIndex, tripIndex, footpathTravelTime, 1);
}
}
footpathIndex++;
}
Expand All @@ -102,17 +109,27 @@ namespace TrRouting
i++;
}

// find best egress stop:
int accessStopDepartureTime {-1};
int accessEnterConnection {-1};
int accessTravelTime {-1};
// find best access stop:
if (!params.returnAllStopsResult)
{
i = 0;
for (auto & departureTime : stopsReverseTentativeTime)
for (auto & accessFootpath : accessFootpaths)
{
if (stopsAccessTravelTime[i] >= 0 && departureTime >= 0 && departureTime - stopsAccessTravelTime[i] > bestDepartureTime)
accessEnterConnection = std::get<0>(reverseAccessJourneys[accessFootpath.first]);
if (accessEnterConnection != -1)
{
bestDepartureTime = departureTime - stopsAccessTravelTime[i];
bestAccessStopIndex = i;
bestAccessTravelTime = stopsAccessTravelTime[i];
accessTravelTime = stopsAccessTravelTime[accessFootpath.first];
accessStopDepartureTime = std::get<connectionIndexes::TIME_DEP>(reverseConnections[accessEnterConnection]) - accessTravelTime - params.minWaitingTimeSeconds;
std::cerr << stops[accessFootpath.first].name << ": " << accessTravelTime << " t: " << trips[std::get<connectionIndexes::TRIP>(reverseConnections[accessEnterConnection])].id << " - " << Toolbox::convertSecondsToFormattedTime(accessStopDepartureTime) << std::endl;
if (accessStopDepartureTime >= 0 && accessStopDepartureTime < MAX_INT && accessStopDepartureTime > bestDepartureTime)
{
bestDepartureTime = accessStopDepartureTime;
bestAccessStopIndex = accessFootpath.first;
bestAccessTravelTime = accessTravelTime;
}
}
i++;
}
Expand Down
Loading

0 comments on commit cccc974

Please sign in to comment.