#include #include using namespace std; constexpr double INFINITY = numeric_limits::infinity(); constexpr size_t NO_VERTEX = numeric_limits::max(); // ====================================================================== // ===== Définissez ici les types demandés : /* ====================================================================== * Une fonction pour tester si une distance est infinie. */ bool is_infinite(double x); // ====================================================================== // ===== Définissez ici les fonctions demandées : /* ====================================================================== * N'ÉCRIVEZ RIEN DE NOTÉ SOUS CETTE LIGNE ! * Toutes les lignes à partir d'ici seront supprimées dans l'évaluation. */ /* ====================================================================== * Une fonction pour tester si une distance est infinie. * Veuillez ne pas modifier cette partie du code. */ #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wfloat-equal" bool is_infinite(double x) { return x == INFINITY; } #pragma GCC diagnostic pop /* ====================================================================== * Exemple de Wikipedia : https://fr.wikipedia.org/wiki/Algorithme_de_Dijkstra */ void graph_create_ex1(graph_t& g) { graph_init(g, 6); graph_add_edge(g, 0, 1, 7.0); graph_add_edge(g, 0, 2, 9.0); graph_add_edge(g, 0, 5, 14.0); graph_add_edge(g, 1, 2, 10.0); graph_add_edge(g, 1, 3, 15.0); graph_add_edge(g, 2, 3, 11.0); graph_add_edge(g, 2, 5, 2.0); graph_add_edge(g, 3, 4, 6.0); graph_add_edge(g, 4, 5, 9.0); } /* ====================================================================== * Second exemple de Wikipedia : https://fr.wikipedia.org/wiki/Algorithme_de_Dijkstra */ void graph_create_ex2(graph_t& g) { graph_init(g, 10); enum Villes { A = 0, B, C, D, E, F, G, H, I, J }; graph_add_edge(g, A, B, 85.0); graph_add_edge(g, A, C, 217.0); graph_add_edge(g, A, E, 173.0); graph_add_edge(g, B, F, 80.0); graph_add_edge(g, C, G, 186.0); graph_add_edge(g, C, H, 103.0); graph_add_edge(g, D, H, 183.0); graph_add_edge(g, E, J, 502.0); graph_add_edge(g, F, I, 250.0); // change it to 237 => shortest path changes graph_add_edge(g, H, J, 167.0); graph_add_edge(g, I, J, 84.0); } // ====================================================================== int main() { graph_t g; graph_create_ex1(g); path_display(Dijkstra(g, 0, 4)); graph_create_ex2(g); path_display(Dijkstra(g, 0, 9)); return 0; }