Пример #1
0
std::pair<Time, bool> Fragment::findArriveTime(size_t fromIndex, Time leave, size_t toIndex) const {
    auto    leaves = getStopTimes(fromIndex);
    auto    leaveIt = std::find(leaves.cbegin(), leaves.cend(), leave);
    if (leaveIt == leaves.cend()) {
        return std::make_pair(leave, false);
    }
    return std::make_pair(*(leaveIt + toIndex - fromIndex), true);
}
Пример #2
0
/*
 ***************************************************************
 * Display the final path to take and also store it in the file.
 ***************************************************************
 */
void displayPathAndWriteToFile(int sourceLineIndex, int destLineIndex, STATION *source, STATION * dest, STATION *transferStation, int numberOfStationsCurrentLine, int numberOfStationsTransferLine, STATION* currentTransferStation) {

  int stopTime=0, totalTimeMin=0, totalTimeSec=0, transferTime=0; 
  char *towards1, *towards2; //Station name towards which the train is headed.

  //No transfer required
  if(transferStation == NULL) {
    if(source->stationNumber > dest->stationNumber)
      towards1 = line[sourceLineIndex]->start->stationName;
    else if (source->stationNumber < dest->stationNumber) 
      towards1 = line[sourceLineIndex]->end->stationName;

    stopTime = getStopTimes(source,dest);
    totalTimeMin = (stopTime + abs(source->timeToReach - dest->timeToReach))/60;
    totalTimeSec = (stopTime + abs(source->timeToReach - dest->timeToReach))%60;

    fprintf(out, "Start from %s station on %s line towards %s for %d stations to arrive at %s.\nTotal duration of journey: %d minutes %d seconds\n", source->stationName, source->lineName, towards1, numberOfStationsCurrentLine, dest->stationName, totalTimeMin, totalTimeSec);

    printf("\nStart from %s station on %s line towards %s for %d stations to arrive at %s.", source->stationName, source->lineName, towards1, numberOfStationsCurrentLine, dest->stationName);
    printf("\nTotal duration of journey: %d minutes %d seconds\n\n", totalTimeMin, totalTimeSec);
  }

  //Transfer required
  else {
    if(source->stationNumber > currentTransferStation->stationNumber)
      towards1 = line[sourceLineIndex]->start->stationName;
    else if (source->stationNumber < currentTransferStation->stationNumber)
      towards1 = line[sourceLineIndex]->end->stationName;

    if(transferStation->stationNumber > dest->stationNumber)
      towards2 = line[destLineIndex]->start->stationName;
    else if(transferStation->stationNumber <= dest->stationNumber)
      towards2 = line[destLineIndex]->end->stationName;

    stopTime = getStopTimes(source,currentTransferStation);
    stopTime+= getStopTimes(transferStation, dest);
    transferTime = getTransferTime(source, dest, dest->lineName);

    //If the destination is sae as transfer station, then no need to consider the transfer or transfer time
    if(numberOfStationsTransferLine == 0 && (strcmp(transferStation->stationName, dest->stationName)==0)) {
      totalTimeMin = (stopTime + abs(currentTransferStation->timeToReach - source->timeToReach) + abs(transferStation->timeToReach - dest->timeToReach))/60;
      totalTimeSec = (stopTime + abs(currentTransferStation->timeToReach - source->timeToReach) + abs(transferStation->timeToReach - dest->timeToReach))%60;

    fprintf(out, "Start from %s station on %s line towards %s for %d stations to reach %s.\nTotal duration of journey: %d minutes %d seconds.", source->stationName, source->lineName, towards1, numberOfStationsCurrentLine, currentTransferStation->stationName, totalTimeMin, totalTimeSec);

    printf("\nStart from %s station on %s line towards %s for %d stations to reach %s.", source->stationName, source->lineName, towards1, numberOfStationsCurrentLine, currentTransferStation->stationName);
    printf("\nTotal duration of journey: %d minutes %d seconds\n\n", totalTimeMin, totalTimeSec);
    }

    // Consider the transfer and transfer time
    else{
      totalTimeMin = (stopTime + abs(currentTransferStation->timeToReach - source->timeToReach) + transferTime + abs(transferStation->timeToReach - dest->timeToReach))/60;
      totalTimeSec = (stopTime + abs(currentTransferStation->timeToReach - source->timeToReach) + transferTime + abs(transferStation->timeToReach - dest->timeToReach))%60;
    
      fprintf(out, "Start from %s station on %s line towards %s for %d stations to reach %s.\nTransfer to %s line.\nTake %s line towards %s for %d stations to reach %s.\nTotal duration of journey: %d minutes %d seconds.", source->stationName, source->lineName, towards1, numberOfStationsCurrentLine, currentTransferStation->stationName, transferStation->lineName, transferStation->lineName, towards2, numberOfStationsTransferLine, dest->stationName, totalTimeMin, totalTimeSec);

      printf("\nStart from %s station on %s line towards %s for %d stations to reach %s.", source->stationName, source->lineName, towards1, numberOfStationsCurrentLine, currentTransferStation->stationName);
      printf("\nTransfer to %s line.", transferStation->lineName);
      printf("\nTake %s line towards %s for %d stations to reach %s", transferStation->lineName, towards2, numberOfStationsTransferLine, dest->stationName);
     printf("\nTotal duration of journey: %d minutes %d seconds\n\n", totalTimeMin, totalTimeSec);
   }
  }
}