Exemple #1
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();
        }
Exemple #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);
        }
Exemple #3
0
        static void run()
        {
            IPopulator populator = new Populator("map.xml");
            IEvaluator evaluator = new Evaluator(null);
            IGeneticOperator mutator = new Mutator(null);
            ITerminator terminator = new FitnessThresholdTerminator(FitnessConverter.FromFloat(1.0f / 1024.0f));
            IOutputter outputter = new RoadNetworkXmlOutputter(@"c:\roadnetworktest\index.xml");

            GeneticEngine engine = new GeneticEngine(populator, evaluator, mutator, terminator, outputter);
            engine.Repeat(100);
            engine.FinishOutput();
        }