Advertisement
Guest User

Untitled

a guest
Oct 28th, 2016
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 5.47 KB | None | 0 0
  1. #include <iostream>
  2. #include <algorithm>
  3. #include <chrono>
  4. #include "auxiliaires.h"
  5. #include "arret.h"
  6. #include "ligne.h"
  7. using namespace std::chrono;
  8. int main(int argc, char *argv[]) {
  9.     high_resolution_clock::time_point t1 = high_resolution_clock::now();
  10.     //Redirect stdout to file
  11.     std::ofstream out("out.txt");
  12.     std::streambuf *coutOrigBuf = std::cout.rdbuf();
  13.     std::cout.rdbuf(out.rdbuf());
  14.     std::vector<std::vector<std::string>> stops;
  15.     std::vector<std::vector<std::string>> stopsStation;
  16.     std::vector<std::vector<std::string>> lines;
  17.     std::vector<std::vector<std::string>> travels;
  18.     std::vector<std::vector<std::string>> calendar_dates;
  19.     std::vector<Arret> arrets;
  20.     std::vector<Ligne> lignes;
  21.     std::vector<Voyage> voyages;
  22.     std::vector<Station> stations;
  23.     //stop_times.txt takes a while to read and parse. (Big File)
  24.     lireFichier("RTC/stop_times.txt", stops, ',', true);
  25.     lireFichier("RTC/routes.txt", lines, ',', true);
  26.     lireFichier("RTC/trips.txt", travels, ',', true);
  27.     lireFichier("RTC/stops.txt", stopsStation, ',', true);
  28.     lireFichier("RTC/calendar_dates.txt", calendar_dates, ',', true);
  29.     for (std::vector<std::string> arret : stops) {
  30.         arrets.push_back(Arret(arret));
  31.     }
  32.     std::sort(arrets.begin(), arrets.end(), [](const Arret &a, const Arret &b) {
  33.         return a.getVoyageId() < b.getVoyageId(); //Loop faster
  34.     });
  35.     for (std::vector<std::string> ligne : lines) {
  36.         lignes.push_back(Ligne(ligne));
  37.     }
  38.     std::sort(lignes.begin(), lignes.end(), [](const Ligne &a, const Ligne &b) {
  39.         return a.getNumero() < b.getNumero();
  40.     });
  41.     for (std::vector<std::string> voyage : travels) {
  42.         for (Ligne &ligne : lignes) {
  43.             if (ligne.getId() == stoi(voyage[0])) {
  44.                 voyages.push_back(Voyage(voyage, &ligne));
  45.                 ligne.addVoyage(&voyages.back());
  46.                 break;
  47.             }
  48.         }
  49.     }
  50.     std::sort(voyages.begin(), voyages.end(), [](const Voyage &a, const Voyage &b) {
  51.         return a.getId() < b.getId();
  52.     });
  53.     for (std::vector<std::string> stopStation : stopsStation) {
  54.         Station station(stopStation);
  55.         stations.push_back(station);
  56.     }
  57.     std::sort(stations.begin(), stations.end(), [](Station a, Station b){
  58.         return a.getId() < b.getId();
  59.     });
  60.     int compteurPrecedent = 0;
  61.     for(Voyage &voyage : voyages) {
  62.         bool firstArretFound = false;
  63.         std::vector<Arret> arretsForVoyage;
  64.         for(int i = compteurPrecedent; i < arrets.size(); i++) {
  65.             if(voyage.getId() == arrets[i].getVoyageId()) {
  66.                 firstArretFound = true;
  67.                 arretsForVoyage.push_back(arrets[i]);
  68.             } else if(firstArretFound) {
  69.                 compteurPrecedent = i;
  70.                 break;
  71.             }
  72.         }
  73.         voyage.setArrets(arretsForVoyage);
  74.     }
  75.     high_resolution_clock::time_point t2 = high_resolution_clock::now();
  76.     double duration = (double)duration_cast<microseconds>(t2 - t1).count() / 1000 / 1000;
  77.     std::cout << std::endl;
  78.     std::cout << "Chargement des données terminé en " <<  duration << " secondes" << std::endl;
  79.     std::cout << "======================" << std::endl;
  80.     std::cout << "  LIGNE DE LA RTC" << std::endl;
  81.     std::cout << "  COMPTE : " << lignes.size() << std::endl;
  82.     std::cout << "======================" << std::endl;
  83.     for (Ligne &ligne : lignes) {
  84.         std::cout << ligne << std::endl;
  85.     }
  86.     std::cout << std::endl;
  87.     std::cout << "======================" << std::endl;
  88.     std::cout << "  STATION DE LA RTC" << std::endl;
  89.     std::cout << "  COMPTE : " << stations.size() << std::endl;
  90.     std::cout << "======================" << std::endl;
  91.     for (Station &station : stations) {
  92.         std::cout << station << std::endl;
  93.     }
  94.     std::string service_id_otd_1;
  95.     std::string service_id_otd_2;
  96.     Date currentDate;
  97.     Heure currentTime;
  98.     for (int i = 0; i < calendar_dates.size(); i++) {
  99.         if(currentDate == calendar_dates[i][1]) {
  100.             service_id_otd_1 = calendar_dates[i][0];
  101.             service_id_otd_2 = calendar_dates[i+1][0];
  102.             break;
  103.         }
  104.     }
  105.     std::vector<Voyage*> voyagesProchaineHeure;
  106.     for(Voyage &voyage: voyages) {
  107.         if(voyage.getServiceId() == service_id_otd_1 || voyage.getServiceId() == service_id_otd_2) {
  108.             if (voyage.getHeureDepart() - currentTime > 0 && voyage.getHeureFin() - currentTime < 3600){
  109.                 voyagesProchaineHeure.push_back(&voyage);
  110.             }
  111.         }
  112.     }
  113.     std::sort(voyagesProchaineHeure.begin(), voyagesProchaineHeure.end(), [](Voyage &a, Voyage &b){
  114.         return a.getHeureDepart() <b.getHeureDepart();
  115.     });
  116.     for(Voyage *voyage: voyagesProchaineHeure) {
  117.         std::cout << std::endl;
  118.         std::cout << "======================" << std::endl;
  119.         std::cout << "  VOYAGES DE LA JOURNÉE DU " << currentDate << std::endl;
  120.         std::cout << "  " << voyage->getHeureDepart() << " - " << voyage->getHeureFin() << std::endl;
  121.         std::cout << "  COMPTE : " << voyage->getArrets().size() << std::endl;
  122.         std::cout << "======================" << std::endl;
  123.         std::cout << voyage->getLigne()->getNumero() << " : " << voyage->getDestination() << std::endl;
  124.         for(Arret &arret : voyage->getArrets()) {
  125.             std::cout << arret.getHeureDepart() << " - " << arret.getStationId() << std::endl;
  126.         }
  127.     }
  128.     return 0;
  129. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement