using My.Collections;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;

namespace Navigator;

class Program
{
    static void Main()
    {
        var lines = File.ReadAllLines("Städte.csv");

        List<string> cities =
            lines.Select(line => line.Split(';')[0])
                    .Distinct()
                    .Union(lines.Select(line => line.Split(';')[1])
                    .Distinct())
                    .ToList();

        // Strecken in csv-Datei immer in beide Richtungen gleiche Entfernung, daher Directed=false
        var graphCities = new ShortestPathGraph<string>(false);

        foreach (var city in cities)
            graphCities.AddNode(city);

        foreach (var line in lines)
        {
            var columns = line.Split(';');

            var (start, end, weight) = (columns[0], columns[1], columns[2]);

            graphCities.AddEdge(graphCities[start], graphCities[end], double.Parse(weight));
        }

        // Alle möglichen Routen berechnen
        for (int i = 0; i < graphCities.Nodes.Count; i++)
        {
            var start = graphCities.Nodes[i];
            for (int j = i + 1; j < graphCities.Nodes.Count; j++)
            {
                var end = graphCities.Nodes[j];

                Console.WriteLine(new string('=', 80));
                Console.WriteLine($"{start} - {end}");

                var route = graphCities.BFS(start, end);
                Console.WriteLine($"Pfad (BFS)        : " +
                       $"{string.Join(" -> ", route.path)}, " +
                       $"Entfernung: {route.distance} Knoten");

                route = graphCities.Dijkstra(start, end);
                Console.WriteLine($"Pfad (Dijkstra)   : " +
                       $"{string.Join(" -> ", route.path)}, " +
                       $"Entfernung: {route.distance} km");

                route = graphCities.BellmanFord(start, end);
                Console.WriteLine($"Pfad (BellmanFord): " +
                       $"{string.Join(" -> ", route.path)}, " +
                       $"Entfernung: {route.distance} km");
            }
        }
    }
}