static void evaluate() { XmlTextReader reader = new XmlTextReader("network.xml"); reader.MoveToContent(); RoadNetwork network = new RoadNetwork(reader); Console.WriteLine("Dimensions: " + network.Map.Width + " x " + network.Map.Height); Console.WriteLine("Start:" + network.Map.Start.X + ", " + network.Map.Start.Y); Console.WriteLine("End:" + network.Map.End.X + ", " + network.Map.End.Y); for (int i = 0; i < network.Map.TownCount; i++) { Coordinates town = network.Map.GetTown(i); Console.WriteLine("Town:" + town.X + "," + town.Y); } for (int i = 0; i < network.EdgeCount; i++) { Edge edge = network.GetEdge(i); Console.WriteLine("Edge:" + edge.Start.Coordinates.X + "," + edge.Start.Coordinates.Y + " - " + edge.End.Coordinates.X + "," + edge.End.Coordinates.Y); } IEvaluator evaluator = new Evaluator(null); uint fitness = evaluator.Evaluate(network); float v = FitnessConverter.ToFloat(fitness); Console.WriteLine("Fitness: " + fitness); Console.WriteLine("Floating Point Fitness: " + v + " " + 1 / v); }
//[TestMethod] public void TestE1() { Evaluator RoadEvaluator = new Evaluator(null); GenerationIndex results = GenerationIndex.Load("index.xml"); AATreeGeneration temp = new AATreeGeneration(); for (int i = 0; i < results.Count; i++) { IGeneration generation = results[i].LoadGeneration(new RoadNetworkReader()); for (int j = 0; j < results[i].Count; j++) { Assert.AreEqual(RoadEvaluator.Evaluate(((IndividualWithFitness)generation.Get(j)).Individual), generation.Get(j).Fitness); } } }
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(); }