-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
33a7dda
commit a8f2e33
Showing
8 changed files
with
146 additions
and
231 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
#include "crow_all.h" | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,44 +1,19 @@ | ||
#pragma once | ||
#ifndef PREPROCESSING_HPP | ||
#define PREPROCESSING_HPP | ||
|
||
#include "graph.hpp" | ||
#include <string> | ||
#include <vector> | ||
#include <set> | ||
#include <unordered_map> | ||
#include <atomic> | ||
#include <unordered_set> | ||
#include <algorithm> | ||
#include <fstream> | ||
#include <sstream> | ||
#include <iostream> | ||
#include <stdexcept> | ||
#include "graph.hpp" | ||
|
||
typedef struct s_Connection { | ||
int landmarkA; | ||
int landmarkB; | ||
int time; | ||
} s_Connection; | ||
|
||
typedef struct s_Result { | ||
int maxId; | ||
std::vector<std::string> errorReport; | ||
} s_Result; | ||
|
||
typedef std::unordered_map<int, std::vector<int>> TPDF_GRAPH; | ||
typedef std::unordered_set<std::string> TPDF_CONNECTIONS; | ||
typedef std::vector<s_Connection> TPDF_CONNECTIONS_WITH_TIME; // | ||
|
||
s_Result analyze_file(const std::string& filePath, int maxLines); | ||
|
||
bool preprocess_data(const std::string& filePath, int maxLines); | ||
|
||
//json file | ||
void write_json_to_file(const TPDF_CONNECTIONS_WITH_TIME& connectionsWithTime, const std::string& outputJsonFile); | ||
|
||
bool preprocess_data(const std::string& filePath, int maxLines, const std::string& outputJsonFile); | ||
|
||
void process_chunk( | ||
const std::vector<std::string>& lines, // Remarque : Utilisez std::string et std::vector | ||
Graph& graph, | ||
TPDF_CONNECTIONS& seenConnections, | ||
std::atomic<int>& maxId, // Remarque : Utilisez std::atomic | ||
TPDF_CONNECTIONS_WITH_TIME& connectionsWithTime | ||
); | ||
/** | ||
* @brief Prétraite les données d'un fichier CSV et les stocke dans un graphe. | ||
* | ||
* @param filePath Chemin du fichier CSV. | ||
* @param maxLines Nombre maximum de lignes à traiter (0 = toutes les lignes). | ||
* @param graph Référence au graphe dans lequel les données sont stockées. | ||
* @return true si le prétraitement est réussi, false sinon. | ||
*/ | ||
bool preprocess_data(const std::string& filePath, int maxLines, Graph& graph); | ||
|
||
#endif // PREPROCESSING_HPP |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,138 +1,56 @@ | ||
#include "includes/graph.hpp" | ||
#include "includes/preprocessing.hpp" | ||
#include <iostream> | ||
#include <vector> | ||
#include <string> | ||
#include <chrono> | ||
#include <fstream> | ||
#include <stdexcept> | ||
#include <chrono> // Pour mesurer le temps d'exécution | ||
|
||
using namespace std; | ||
using namespace chrono; | ||
|
||
// Fonction pour afficher le logo | ||
void display_logo(const string& file_path) { | ||
ifstream logo_file(file_path); | ||
if (logo_file.is_open()) { | ||
string line; | ||
while (getline(logo_file, line)) { | ||
cout << line << endl; | ||
} | ||
logo_file.close(); | ||
} else { | ||
cerr << "Error: Unable to open logo file." << endl; | ||
} | ||
} | ||
|
||
// Fonction pour afficher une barre de progression | ||
void display_progress_bar(size_t current, size_t total) { | ||
const int barWidth = 50; | ||
float progress = static_cast<float>(current) / total; | ||
int position = static_cast<int>(progress * barWidth); | ||
|
||
cout << "\r["; | ||
for (int i = 0; i < barWidth; ++i) { | ||
if (i < position) cout << "="; | ||
else if (i == position) cout << ">"; | ||
else cout << " "; | ||
} | ||
cout << "] " << int(progress * 100.0) << "% (" << current << "/" << total << ")"; | ||
cout.flush(); | ||
} | ||
|
||
// Prétraitement des données | ||
bool preprocess_data_with_progress(const string& filePath, int maxLines, Graph& graph, size_t& totalLinesProcessed) { | ||
ifstream inputFile(filePath); | ||
if (!inputFile.is_open()) { | ||
throw runtime_error("Error: Unable to find the CSV file!" + filePath); | ||
} | ||
|
||
// Compter les lignes dans le fichier | ||
size_t totalLines = 0; | ||
string line; | ||
while (getline(inputFile, line)) { | ||
++totalLines; | ||
if (maxLines > 0 && totalLines >= static_cast<size_t>(maxLines)) break; | ||
} | ||
inputFile.clear(); | ||
inputFile.seekg(0, ios::beg); | ||
|
||
// Charger les données dans le graphe | ||
size_t currentLine = 0; | ||
while (getline(inputFile, line) && (maxLines <= 0 || currentLine < static_cast<size_t>(maxLines))) { | ||
++currentLine; | ||
|
||
int source, target, weight; | ||
if (sscanf(line.c_str(), "%d,%d,%d", &source, &target, &weight) == 3) { | ||
graph.add_edge(source, target, weight); | ||
} | ||
|
||
display_progress_bar(currentLine, totalLines); | ||
int main(int argc, char* argv[]) { | ||
if (argc != 4) { | ||
std::cerr << "Usage: " << argv[0] << " <input_file> <source> <target>\n"; | ||
return 1; | ||
} | ||
|
||
inputFile.close(); | ||
cout << endl; | ||
|
||
totalLinesProcessed = currentLine; | ||
return true; | ||
} | ||
|
||
int main() { | ||
string logoFilePath = "logo/Logo QPS.txt"; // Chemin du fichier contenant le logo | ||
display_logo(logoFilePath); | ||
|
||
string inputFilePath = "data/usa_roads.csv"; // Remplacez par le chemin de votre fichier CSV | ||
int maxLines = 28854314; // Nombre maximal de lignes à traiter (ou -1 pour tout charger) | ||
std::string inputFilePath = argv[1]; | ||
int source = std::stoi(argv[2]); | ||
int target = std::stoi(argv[3]); | ||
|
||
Graph graph; | ||
|
||
size_t totalLinesProcessed = 0; | ||
try { | ||
cout << "Prétraitement des données en cours..." << endl; | ||
auto startTime = high_resolution_clock::now(); | ||
|
||
preprocess_data_with_progress(inputFilePath, maxLines, graph, totalLinesProcessed); | ||
|
||
auto endTime = high_resolution_clock::now(); | ||
duration<double> elapsed = endTime - startTime; | ||
|
||
cout << "Prétraitement terminé avec succès !" << endl; | ||
cout << "Nombre total de lignes traitées : " << totalLinesProcessed << endl; | ||
cout << "Temps écoulé : " << elapsed.count() << " secondes." << endl; | ||
} catch (const exception& e) { | ||
cerr << "Erreur: " << e.what() << endl; | ||
return 1; | ||
} | ||
|
||
// Boucle principale pour entrer les requêtes de chemin le plus court | ||
while (true) { | ||
int source, target; | ||
cout << "Entrez le point de départ (ou -1 pour quitter) : "; | ||
cin >> source; | ||
if (source == -1) break; | ||
|
||
cout << "Entrez le point d'arrivée : "; | ||
cin >> target; | ||
|
||
cout << "Recherche du chemin le plus court..." << endl; | ||
auto startTime = high_resolution_clock::now(); | ||
|
||
int totalTime = 0; | ||
auto path = graph.shortest_path(source, target, totalTime); | ||
|
||
auto endTime = high_resolution_clock::now(); | ||
duration<double> elapsed = endTime - startTime; | ||
// Mesurer le temps de prétraitement | ||
auto preprocessingStart = std::chrono::high_resolution_clock::now(); | ||
preprocess_data(inputFilePath, 0, graph); | ||
auto preprocessingEnd = std::chrono::high_resolution_clock::now(); | ||
std::chrono::duration<double> preprocessingTime = preprocessingEnd - preprocessingStart; | ||
|
||
std::cout << "Prétraitement terminé. Données chargées en mémoire.\n"; | ||
std::cout << "Temps de prétraitement : " << preprocessingTime.count() << " secondes.\n"; | ||
|
||
// Mesurer le temps de calcul du chemin le plus court | ||
auto pathCalculationStart = std::chrono::high_resolution_clock::now(); | ||
int totalTime; | ||
std::vector<int> path = graph.shortest_path(source, target, totalTime); | ||
auto pathCalculationEnd = std::chrono::high_resolution_clock::now(); | ||
std::chrono::duration<double> pathCalculationTime = pathCalculationEnd - pathCalculationStart; | ||
|
||
if (path.empty()) { | ||
cout << "Aucun chemin trouvé entre " << source << " et " << target << "." << endl; | ||
std::cout << "Aucun chemin trouvé entre " << source << " et " << target << ".\n"; | ||
} else { | ||
cout << "Chemin le plus court de " << source << " à " << target << " : "; | ||
std::cout << "Chemin le plus court : "; | ||
for (int node : path) { | ||
cout << node << " "; | ||
std::cout << node << " "; | ||
} | ||
cout << "\nTemps total : " << totalTime << " unités." << endl; | ||
cout << "Recherche terminée en " << elapsed.count() << " secondes." << endl; | ||
std::cout << "\nTemps total : " << totalTime << "\n"; | ||
} | ||
|
||
std::cout << "Temps de calcul du chemin : " << pathCalculationTime.count() << " secondes.\n"; | ||
|
||
} catch (const std::exception& e) { | ||
std::cerr << "Erreur : " << e.what() << "\n"; | ||
return 1; | ||
} | ||
|
||
cout << "Programme terminé. Merci d'avoir utilisé notre service !" << endl; | ||
return 0; | ||
} |
Oops, something went wrong.