static void mutate2() { XmlTextReader reader = new XmlTextReader("network.xml"); reader.MoveToContent(); RoadNetwork network = new RoadNetwork(reader); Mutator mutator = new Mutator(null); RoadNetwork mutated = Mutator.Mutate(network); XmlTextWriter writer = new XmlTextWriter("mutant.xml", Encoding.ASCII); writer.Formatting = Formatting.Indented; mutated.WriteXml(writer); writer.Flush(); writer.Close(); }
public void TestD1() { Mutator RNCO = new Mutator(null); AATreeGeneration generation = new AATreeGeneration(); ArrayList individuals = new ArrayList(); //Populate with identical entries. Vertex[] theVertices = new Vertex[5]; RoadNetwork theRoad; Map theMap; 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); } RNCO.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); }
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(); }