summaryrefslogtreecommitdiffstats
path: root/src/CS340.TSP/Program.cs
blob: 3dfe855674d79bb44c9d70aff2c288b6e1b46672 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
using System;
using System.IO;
using System.Linq;
using Extensions;
using Graph;
using Graph.IO;
using Interfaces;

namespace TSP
{
    using Graph = Graph<double>;
    class Program
    {

        // https://swharden.com/CsharpDataVis/drawing/3-drawing-in-wpf.md.html
        static void Main(string[] args)
        {
            foreach (var item in Directory.GetFiles("graphs/"))
            {
                Graph graph = GraphFile.Read(new FileReader(item));
                Graph mst = graph.MST(0);
                GraphFile.Print(mst, new ConsoleWriter());
                Console.WriteLine(
                    graph.Vertices.Sum(vertex =>
                        vertex.Edges.FirstOrDefault(edge => edge.V == vertex.Parent).Weight));
            }
        }
    }

    class ConsoleWriter : IFileWriter
    {
        public void WriteAllLines(string[] lines) =>
            Array.ForEach(lines, line => Console.WriteLine(line));
    }
}