moved reserve
This commit is contained in:
@@ -17,16 +17,13 @@ std::ostream& operator<<(std::ostream& os, const Graphe& g) {
|
|||||||
}
|
}
|
||||||
os << "Edges:\n";
|
os << "Edges:\n";
|
||||||
for (const auto& edge : g.m_Edges) {
|
for (const auto& edge : g.m_Edges) {
|
||||||
os << " Start: " << edge.m_Start->m_Name
|
os << " Start: " << edge.m_Start->m_Name << ", End: " << edge.m_End->m_Name << ", Values: " << edge.m_Values << "\n";
|
||||||
<< ", End: " << edge.m_End->m_Name
|
|
||||||
<< ", Values: " << edge.m_Values << "\n";
|
|
||||||
}
|
}
|
||||||
return os;
|
return os;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Graphe::Graphe(const string& fileName) {
|
Graphe::Graphe(const string& fileName) {
|
||||||
// load the graph from the file
|
|
||||||
ifstream file(fileName);
|
ifstream file(fileName);
|
||||||
if (!file.is_open()) {
|
if (!file.is_open()) {
|
||||||
// cerr << "Error opening file: " << fileName << endl;
|
// cerr << "Error opening file: " << fileName << endl;
|
||||||
@@ -66,8 +63,10 @@ Graphe::Graphe(const string& fileName) {
|
|||||||
directed = (value == "true");
|
directed = (value == "true");
|
||||||
} else if (key == "NB_VERTICES") {
|
} else if (key == "NB_VERTICES") {
|
||||||
nb_vertices = stoi(value);
|
nb_vertices = stoi(value);
|
||||||
|
m_Vertecies.reserve(nb_vertices);
|
||||||
} else if (key == "NB_EDGES") {
|
} else if (key == "NB_EDGES") {
|
||||||
nb_edges = stoi(value);
|
nb_edges = stoi(value);
|
||||||
|
m_Edges.reserve(nb_edges);
|
||||||
} else if (key == "NB_VALUES_BY_VERTEX") {
|
} else if (key == "NB_VALUES_BY_VERTEX") {
|
||||||
nb_values_by_vertex = stoi(value);
|
nb_values_by_vertex = stoi(value);
|
||||||
} else if (key == "NB_VALUES_BY_EDGE") {
|
} else if (key == "NB_VALUES_BY_EDGE") {
|
||||||
@@ -78,12 +77,9 @@ Graphe::Graphe(const string& fileName) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
m_Vertecies.reserve(nb_vertices);
|
|
||||||
m_Edges.reserve(nb_edges);
|
|
||||||
|
|
||||||
if (verticesSection) {
|
if (verticesSection) {
|
||||||
// cout << "Reading vertices : " << line << endl;
|
// cout << "Reading vertices : " << line << endl;
|
||||||
if(line.starts_with("VER")) {
|
if (line.size() >= 3 && line.substr(0, 3) == "VER") {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
regex vertexRegex(R"(^(\d+)\s(\w+)\s?(.*)$)");
|
regex vertexRegex(R"(^(\d+)\s(\w+)\s?(.*)$)");
|
||||||
@@ -108,7 +104,7 @@ Graphe::Graphe(const string& fileName) {
|
|||||||
}
|
}
|
||||||
if (edgesSection) {
|
if (edgesSection) {
|
||||||
// cout << "Reading edges : " << line << endl;
|
// cout << "Reading edges : " << line << endl;
|
||||||
if(line.starts_with("EDG")) {
|
if (line.size() >= 3 && line.substr(0, 3) == "EDG") {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
regex edgeRegex(R"(^(\d+)\s(\d+)\s?(.*)$)");
|
regex edgeRegex(R"(^(\d+)\s(\d+)\s?(.*)$)");
|
||||||
|
|||||||
@@ -1,15 +1,15 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
void printYellow(const std::string& text) {
|
inline void printYellow(const std::string& text) {
|
||||||
std::cout << "\033[33m" << text << "\033[0m";
|
std::cout << "\033[33m" << text << "\033[0m";
|
||||||
}
|
}
|
||||||
void printRed(const std::string& text) {
|
inline void printRed(const std::string& text) {
|
||||||
std::cout << "\033[31m" << text << "\033[0m";
|
std::cout << "\033[31m" << text << "\033[0m";
|
||||||
}
|
}
|
||||||
void printGreen(const std::string& text) {
|
inline void printGreen(const std::string& text) {
|
||||||
std::cout << "\033[32m" << text << "\033[0m";
|
std::cout << "\033[32m" << text << "\033[0m";
|
||||||
}
|
}
|
||||||
void printBlue(const std::string& text) {
|
inline void printBlue(const std::string& text) {
|
||||||
std::cout << "\033[34m" << text << "\033[0m";
|
std::cout << "\033[34m" << text << "\033[0m";
|
||||||
}
|
}
|
||||||
59
src/main.cpp
59
src/main.cpp
@@ -1,33 +1,38 @@
|
|||||||
#include <iostream>
|
|
||||||
|
|
||||||
#include "Algo.h"
|
#include "Algo.h"
|
||||||
#include "Graphe.h"
|
#include "Graphe.h"
|
||||||
|
#include <chrono>
|
||||||
|
#include <ctime>
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
int main(int argc, char** argv) {
|
int main(int argc, char** argv) {
|
||||||
Graphe graphe("graphe-oriente-01.gra");
|
auto start = std::chrono::high_resolution_clock::now();
|
||||||
std::cout << graphe << std::endl;
|
Graphe graphe("graphe-communes.gra");
|
||||||
auto result = PlusCourtCheminNbArcs(graphe, graphe.getVertex("a"));
|
auto end = std::chrono::high_resolution_clock::now();
|
||||||
|
auto duration = std::chrono::duration_cast<std::chrono::milliseconds>(end - start).count();
|
||||||
|
std::cout << "Temps de chargement du graphe : " << duration << " ms.\n";
|
||||||
|
// std::cout << graphe << std::endl;
|
||||||
|
// auto result = PlusCourtCheminNbArcs(graphe, graphe.getVertex("a"));
|
||||||
|
|
||||||
std::cout << "Résultat :\n";
|
// std::cout << "Résultat :\n";
|
||||||
for (auto& [vertex, longueur] : result) {
|
// for (auto& [vertex, longueur] : result) {
|
||||||
std::cout << vertex->m_Name << " " << longueur << "\n";
|
// std::cout << vertex->m_Name << " " << longueur << "\n";
|
||||||
}
|
// }
|
||||||
|
|
||||||
auto result2 = PlusCourtCheminsNbArcs(graphe, graphe.getVertex("a"));
|
// auto result2 = PlusCourtCheminsNbArcs(graphe, graphe.getVertex("a"));
|
||||||
|
|
||||||
std::cout << "Résultat :\n";
|
// std::cout << "Résultat :\n";
|
||||||
for (auto& [vertex, chemin] : result2) {
|
// for (auto& [vertex, chemin] : result2) {
|
||||||
std::cout << vertex->m_Name << " " << chemin << "\n";
|
// std::cout << vertex->m_Name << " " << chemin << "\n";
|
||||||
}
|
// }
|
||||||
|
|
||||||
auto result3 = PlusCourtChemin(graphe, graphe.getVertex("a"), graphe.getVertex("e"));
|
// auto result3 = PlusCourtChemin(graphe, graphe.getVertex("a"), graphe.getVertex("e"));
|
||||||
|
|
||||||
std::cout << "Résultat :\n";
|
// std::cout << "Résultat :\n";
|
||||||
std::cout << result3 << std::endl;
|
// std::cout << result3 << std::endl;
|
||||||
|
|
||||||
auto result4 = PlusCourtCheminDjikstra(graphe, graphe.getVertex("a"));
|
// auto result4 = PlusCourtCheminDjikstra(graphe, graphe.getVertex("a"));
|
||||||
std::cout << "Résultat :\n";
|
// std::cout << "Résultat :\n";
|
||||||
for (auto& [vertex, longueur] : result4) {
|
// for (auto& [vertex, longueur] : result4) {
|
||||||
std::cout << vertex->m_Name << " " << longueur << "\n";
|
// std::cout << vertex->m_Name << " " << longueur << "\n";
|
||||||
}
|
// }
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user