Пример #1
0
        public void DoAxesRotationTspWithNoReturn_Test()
        {
            // arrange
            var s = new Node {
                Coord = new Coordinate {
                    X = 0, Y = 0
                }, Visited = false, IsStartOrEnd = true
            };
            var a = new Node {
                Coord = new Coordinate {
                    X = 1, Y = 1
                }, Visited = false, IsStartOrEnd = false
            };
            var b = new Node {
                Coord = new Coordinate {
                    X = 2, Y = 1
                }, Visited = false, IsStartOrEnd = false
            };
            var c = new Node {
                Coord = new Coordinate {
                    X = -1, Y = 6
                }, Visited = false, IsStartOrEnd = false
            };
            var t = new Node {
                Coord = new Coordinate {
                    X = 4, Y = 0
                }, Visited = false, IsStartOrEnd = true
            };

            var nodes = new List <Node> {
                s, a, b, c, t
            };

            // expected path
            var expectedPath = new Queue <Coordinate>();

            expectedPath.Enqueue(s.Coord);
            expectedPath.Enqueue(c.Coord);
            expectedPath.Enqueue(a.Coord);
            expectedPath.Enqueue(b.Coord);
            expectedPath.Enqueue(t.Coord);

            var axesRot = new AxisRotation();


            // act
            var greedyPath = axesRot.DoAxesRotationTspWithNoReturn(nodes);

            // assert
            Assert.Equal(greedyPath.Path, expectedPath);
        }
Пример #2
0
        public static void Main(string[] args)
        {
            var axisRotation = new AxisRotation();
            // Load sample data
            var data1 = SampleData.LoadData();
            var data2 = SampleData.LoadData();

            // Get Greedy Path
            //var greedy = axisRotation.DoGreedyTspWithNoReturn(data1);
            //Console.WriteLine($"AxesRot Distance: {greedy.DistanceTravelled}");

            // Get Axes Rotation Path
            var axesRot = axisRotation.DoAxesRotationTspWithNoReturn(data2);

            axisRotation.PrintPath(axesRot.Path);
            Console.WriteLine($"AxesRot Distance: {axesRot.DistanceTravelled}");
        }
Пример #3
0
        public static void PrintSample(AxisRotation axisRotation, int sample)
        {
            var sampleData = SampleData.LoadDataFromJsonFile($"Data/sample_data_{sample}.json");

            // Result from Greedy Algorithm
            Console.WriteLine("********** GREEDY *********");
            var greedy = axisRotation.DoGreedyTspWithNoReturn(sampleData);

            axisRotation.DisplayData(greedy);
            Console.WriteLine("********** GREEDY *********");

            // Result from Axes Rotation Algorithm
            Console.WriteLine("********** AXES ROTATION *********");
            var axesRot = axisRotation.DoAxesRotationTspWithNoReturn(sampleData);

            axisRotation.DisplayData(axesRot);
            Console.WriteLine("********** AXES ROTATION *********");
        }
Пример #4
0
        public static void MultiSampleStats(int sampleSize)
        {
            var sampleOfSamples = new List <List <Node> >();
            var stats           = new List <Tuple <double, double> >();

            for (int i = 0; i < sampleSize; i++)
            {
                var filename = $"Data/multi_{i}.json";
                var sample   = SampleData.GenerateRandomData(20, filename);

                // load data
                var smp = SampleData.LoadDataFromJsonFile(filename);

                // this here is what you should never do, but for now...
                var alg = new AxisRotation();
                var grd = alg.DoGreedyTspWithNoReturn(sample);
                var axr = alg.DoAxesRotationTspWithNoReturn(smp);

                var cmp = new Tuple <double, double>(grd.DistanceTravelled, axr.DistanceTravelled);
                stats.Add(cmp);
            }

            SaveToDisk(stats, $"Data/cmp_2.csv");
        }