Beispiel #1
0
        public void InitializeGraph_UpdatePheromone_Success()
        {
            var options = new BaseOptions(numberOfIterations: 100, numberOfRegions: 3, alfa: 1, beta: 5, ro: 0.6, delta: 0.1D);

            var graph = new BasicGraph("baba.txt", "baba.txt");

            graph.VerticesWeights = new List <Vertex>
            {
                new Vertex(0, 4),
                new Vertex(1, 3),
                new Vertex(2, 8),
                new Vertex(3, 7),
                new Vertex(4, 5),
                new Vertex(5, 3),
                new Vertex(6, 6),
                new Vertex(7, 7),
                new Vertex(8, 2)
            };

            var weightOfColonies = new[] { 1, 2, 3 };
            var treil            = new List <HashSet <Vertex> >();

            for (var i = 0; i < options.NumberOfRegions; i++)
            {
                treil.Add(new HashSet <Vertex>());
                treil[i].UnionWith(graph.VerticesWeights.Skip(i * 3).Take(3));
            }

            graph.InitializePheromoneMatrix();
            graph.UpdatePhermone(weightOfColonies, treil, options, 5);

            var expectedPheromoneMatrix = new double[9, 9]
            {
                {
                    0, 0.000041, 0.000041,
                    Constants.MinimalValueOfPheromone, Constants.MinimalValueOfPheromone,
                    Constants.MinimalValueOfPheromone, Constants.MinimalValueOfPheromone,
                    Constants.MinimalValueOfPheromone, Constants.MinimalValueOfPheromone
                },
                {
                    0.000041, 0, 0.000041,
                    Constants.MinimalValueOfPheromone, Constants.MinimalValueOfPheromone,
                    Constants.MinimalValueOfPheromone, Constants.MinimalValueOfPheromone,
                    Constants.MinimalValueOfPheromone, Constants.MinimalValueOfPheromone
                },
                {
                    0.000041, 0.000041, 0,
                    Constants.MinimalValueOfPheromone, Constants.MinimalValueOfPheromone,
                    Constants.MinimalValueOfPheromone, Constants.MinimalValueOfPheromone,
                    Constants.MinimalValueOfPheromone, Constants.MinimalValueOfPheromone
                },
                {
                    Constants.MinimalValueOfPheromone, Constants.MinimalValueOfPheromone,
                    Constants.MinimalValueOfPheromone, 0, 0.000041,
                    0.000041, Constants.MinimalValueOfPheromone,
                    Constants.MinimalValueOfPheromone, Constants.MinimalValueOfPheromone
                },
                {
                    Constants.MinimalValueOfPheromone, Constants.MinimalValueOfPheromone,
                    Constants.MinimalValueOfPheromone, 0.000041, 0,
                    0.000041, Constants.MinimalValueOfPheromone,
                    Constants.MinimalValueOfPheromone, Constants.MinimalValueOfPheromone
                },
                {
                    Constants.MinimalValueOfPheromone, Constants.MinimalValueOfPheromone,
                    Constants.MinimalValueOfPheromone, 0.000041,
                    0.000041, 0, Constants.MinimalValueOfPheromone,
                    Constants.MinimalValueOfPheromone, Constants.MinimalValueOfPheromone
                },
                {
                    Constants.MinimalValueOfPheromone, Constants.MinimalValueOfPheromone,
                    Constants.MinimalValueOfPheromone, Constants.MinimalValueOfPheromone,
                    Constants.MinimalValueOfPheromone, Constants.MinimalValueOfPheromone, 0,
                    0.086004, 0.086004
                },
                {
                    Constants.MinimalValueOfPheromone, Constants.MinimalValueOfPheromone,
                    Constants.MinimalValueOfPheromone, Constants.MinimalValueOfPheromone,
                    Constants.MinimalValueOfPheromone, Constants.MinimalValueOfPheromone,
                    0.086004, 0, 0.086004
                },
                {
                    Constants.MinimalValueOfPheromone, Constants.MinimalValueOfPheromone,
                    Constants.MinimalValueOfPheromone, Constants.MinimalValueOfPheromone,
                    Constants.MinimalValueOfPheromone, Constants.MinimalValueOfPheromone,
                    0.086004, 0.086004, 0
                }
            };

            CollectionAssert.AreEqual(graph.PheromoneMatrix, graph.PheromoneMatrix);
        }