// Una ruta sobre un mapa real: BFS frente a Dijkstra, y la línea recta para revisarla.
// Uso: route_demo mapa.txt calles.tsv "calle de origen" "calle de destino"
#include <iomanip>
#include <iostream>
#include <string>
#include <vector>

#include "map_file.h"
#include "shortest_paths.h"
#include "traversals.h"

int main(int argc, char* argv[]) {
    if (argc != 5) {
        std::cerr << "uso: route_demo mapa.txt calles.tsv origen destino\n";
        return 2;
    }
    MapFile map = read_map_file(argv[1]);
    std::vector<Street> streets = read_streets(argv[2]);
    Graph graph = graph_of(map);
    int from = node_of_street(streets, argv[3]);
    int to = node_of_street(streets, argv[4]);
    std::cout << "de " << argv[3] << " (nodo " << from << ") a " << argv[4] << " (nodo " << to << ")\n";
    double straight = straight_meters(map.points[from], map.points[to]);
    std::cout << std::fixed << std::setprecision(0) << "linea recta: " << straight << " metros\n";

    std::vector<int> fewest = path_to(bfs(graph, from).parent, to);
    Meters fewest_meters = path_meters(graph, fewest);
    std::cout << "BFS:      " << fewest.size() - 1 << " aristas, " << fewest_meters << " metros\n";

    DijkstraResult result = dijkstra(graph, from);
    std::vector<int> route = path_to(result.parent, to);
    std::cout << "Dijkstra: " << route.size() - 1 << " aristas, " << result.distance[to] << " metros\n";
    std::cout << std::setprecision(2) << "ruta sobre linea recta: " << result.distance[to] / straight << "\n";
    return 0;
}
