Esempio n. 1
0
        public void TestD5()
        {
            AllInOneOperator AIOO = new AllInOneOperator(null);
            AATreeGeneration generation = new AATreeGeneration();
            ArrayList individuals = new ArrayList();
            //Populate with identical entries.
            RoadNetwork theRoad;
            Vertex[] theVertices = new Vertex[5];
            Map theMap = Map.FromFile("map.xml");
            ArrayList RN = new ArrayList();
            for (int i = 0; i < 10; i++)
            {
                theRoad = new RoadNetwork(theMap);
                RN.Add(theRoad);
                //RN[i] = new RoadNetwork(theMap);
                theVertices[0] = ((RoadNetwork)RN[i]).AddVertex(0, 0);
                theVertices[1] = ((RoadNetwork)RN[i]).AddVertex(10, 0);
                theVertices[2] = ((RoadNetwork)RN[i]).AddVertex(5, 5);
                theVertices[3] = ((RoadNetwork)RN[i]).AddVertex(0, 10);
                theVertices[4] = ((RoadNetwork)RN[i]).AddVertex(10, 10);
                ((RoadNetwork)RN[i]).AddEdge(theVertices[0], theVertices[1]);
                ((RoadNetwork)RN[i]).AddEdge(theVertices[0], theVertices[3]);
                ((RoadNetwork)RN[i]).AddEdge(theVertices[3], theVertices[4]);
                ((RoadNetwork)RN[i]).AddEdge(theVertices[1], theVertices[4]);
                ((RoadNetwork)RN[i]).AddEdge(theVertices[0], theVertices[2]);
                ((RoadNetwork)RN[i]).AddEdge(theVertices[1], theVertices[2]);
                ((RoadNetwork)RN[i]).AddEdge(theVertices[3], theVertices[2]);
                ((RoadNetwork)RN[i]).AddEdge(theVertices[4], theVertices[2]);
                //Add vertex and add edge
                generation.Insert(RN[i], 1);
            }
            AIOO.Operate(generation, individuals);
            //Ensure population is made up of valid roadnetworks.
            //Ensure all are not the same.
            Boolean passed = false;
            for (int i = 0; i < individuals.Count; i++)
            {
                for (int j = 0; j < individuals.Count; j++)
                {
                    //Cross check each of the 5 vertices
                    for (int k = 0; k < ((RoadNetwork)individuals[i]).VertexCount; k++)
                    {
                        for (int l = 0; l < ((RoadNetwork)individuals[j]).VertexCount; l++)
                        {

                            if (((RoadNetwork)individuals[i]).GetVertex(k).Coordinates.X != ((RoadNetwork)individuals[j]).GetVertex(l).Coordinates.X)
                            {
                                passed = true;
                            }
                        }
                    }
                }
            }
            Assert.IsTrue(passed);
        }
Esempio n. 2
0
        public void TestF1()
        {
            RoadNetworkXmlOutputter RNO = new RoadNetworkXmlOutputter("map.xml");
            Map theMap;
            theMap = Map.FromFile("map.xml");
            Vertex[] theVertices = new Vertex[4];
            RoadNetwork RN1 = new RoadNetwork(theMap);
                theVertices[0] = ((RoadNetwork)RN1).AddVertex(0, 0);
                theVertices[1] = ((RoadNetwork)RN1).AddVertex(10, 0);
                ((RoadNetwork)RN1).AddEdge(theVertices[0], theVertices[1]);
            RoadNetwork RN2 = new RoadNetwork(theMap);
                theVertices[2] = ((RoadNetwork)RN2).AddVertex(5, 5);
                theVertices[3] = ((RoadNetwork)RN2).AddVertex(10, 10);
                ((RoadNetwork)RN2).AddEdge(theVertices[2], theVertices[3]);
            AATreeGeneration generation = new AATreeGeneration();
            generation.Insert(RN1, 1);
            generation.Insert(RN2, 2);

            XmlWriter writer1 = XmlWriter.Create("test1xml.xml");
            XmlWriter writer2 = XmlWriter.Create("test2xml.xml");
            //Output individuals/generation somehow.
            RN1.WriteXml(writer1);
            writer1.Close();
            RN2.WriteXml(writer2);
            writer2.Close();

            XmlTextReader reader1 = new XmlTextReader("test1xml.xml");
            XmlTextReader reader2= new XmlTextReader("test2xml.xml");
            RoadNetworkReader rnr = new RoadNetworkReader();

            RoadNetwork RNL1 = (RoadNetwork)rnr.ReadIndividual(reader1);
            RoadNetwork RNL2 = (RoadNetwork)rnr.ReadIndividual(reader2);
            Assert.AreEqual(RNL1.GetVertex(0).Coordinates.X, 0);
            Assert.AreEqual(RNL1.GetVertex(0).Coordinates.Y, 0);
            Assert.AreEqual(RNL1.GetVertex(1).Coordinates.X, 10);
            Assert.AreEqual(RNL1.GetVertex(1).Coordinates.Y, 0);
            Assert.AreEqual(RNL2.GetVertex(0).Coordinates.X, 5);
            Assert.AreEqual(RNL2.GetVertex(0).Coordinates.Y, 5);
            Assert.AreEqual(RNL2.GetVertex(1).Coordinates.X, 10);
            Assert.AreEqual(RNL2.GetVertex(1).Coordinates.Y, 10);
            Assert.AreEqual(RNL1.GetEdge(0).Start.Coordinates.X, 0);
            Assert.AreEqual(RNL1.GetEdge(0).Start.Coordinates.Y, 0);
            Assert.AreEqual(RNL1.GetEdge(0).End.Coordinates.X, 10);
            Assert.AreEqual(RNL1.GetEdge(0).End.Coordinates.Y, 0);
            Assert.AreEqual(RNL2.GetEdge(0).Start.Coordinates.X, 5);
            Assert.AreEqual(RNL2.GetEdge(0).Start.Coordinates.Y, 5);
            Assert.AreEqual(RNL2.GetEdge(0).End.Coordinates.X, 10);
            Assert.AreEqual(RNL2.GetEdge(0).End.Coordinates.Y, 10);
        }
Esempio n. 3
0
        static void Save()
        {
            Random random = new Random();

            Map map = Map.FromFile("map.xml");

            IOutputter outputter = new RoadNetworkXmlOutputter("c:\\cits3200test\\roadnetworks.xml");
            outputter.OpenOutput();

            for (int g = 0; g < 10; g++)
            {
                AATreeGeneration generation = new AATreeGeneration();

                for (int i = 0; i < 20; i++)
                {
                    RoadNetwork network = new RoadNetwork(map);

                    for (int v = 0; v < 100; v++)
                    {
                        network.AddVertex(random.Next(100), random.Next(100));
                    }

                    for (int e = 0; e < 1000; e++)
                    {
                        network.AddEdge(network.GetVertex(random.Next(100)), network.GetVertex(random.Next(100)));
                    }

                    generation.Insert(network, (uint)i);
                }

                outputter.OutputGeneration(generation, g);
            }

            outputter.CloseOutput();
        }