public void Test() { int iterations = 20; INetworkDataProvider metlinkProvider = new MetlinkDataProvider(); //http://ptv.vic.gov.au/stop/view/StopID var testRoutes2 = new[,] { { new MetlinkNode(19965, metlinkProvider), new MetlinkNode(19879, metlinkProvider) }, { new MetlinkNode(12018, metlinkProvider), new MetlinkNode(18475, metlinkProvider) }, { new MetlinkNode(19965, metlinkProvider), new MetlinkNode(19842, metlinkProvider) } }; var testRoutes = new[,] { // Long inter-suburban routes { new MetlinkNode(19965, metlinkProvider), new MetlinkNode(19879, metlinkProvider) }, // Coburg - Ringwood { new MetlinkNode(20005, metlinkProvider), new MetlinkNode(19855, metlinkProvider) }, // Epping - Frankston { new MetlinkNode(19990, metlinkProvider), new MetlinkNode(19921, metlinkProvider) }, // Hurstbridge - Werribee { new MetlinkNode(19844, metlinkProvider), new MetlinkNode(20000, metlinkProvider) }, // Belgrave - Watergardens { new MetlinkNode(19886, metlinkProvider), new MetlinkNode(40221, metlinkProvider) }, // Cranbourne - Craigieburn // Lateral inter-suburban routes. { new MetlinkNode(19965, metlinkProvider), new MetlinkNode(19935, metlinkProvider) }, // Coburg - Heidelberg { new MetlinkNode(19965, metlinkProvider), new MetlinkNode(628, metlinkProvider) }, // Coburg - Kew (Wilsmear/Grandview) { new MetlinkNode(19990, metlinkProvider), new MetlinkNode(19246, metlinkProvider) }, // East Kew Terminus - Box Hill (r202) { new MetlinkNode(12018, metlinkProvider), new MetlinkNode(18475, metlinkProvider) }, // Yarravile - Highpoint (r223) { new MetlinkNode(4808, metlinkProvider), new MetlinkNode(19649, metlinkProvider) }, // Greensborough - Boxhill // Inner-city routes. { new MetlinkNode(19843, metlinkProvider), new MetlinkNode(22180, metlinkProvider) }, // Parliament - Southern Cross { new MetlinkNode(17882, metlinkProvider), new MetlinkNode(19841, metlinkProvider) }, // 9-Spring St/Bourke St - Flagstaff { new MetlinkNode(19489, metlinkProvider), new MetlinkNode(19973, metlinkProvider) }, // Melbourne Uni - North Melbourne { new MetlinkNode(18034, metlinkProvider), new MetlinkNode(17901, metlinkProvider) }, // 2-King St/La Trobe St - Melbourne Town Hall/Collins St { new MetlinkNode(18450, metlinkProvider), new MetlinkNode(19594, metlinkProvider) }, // Casino - Royal Childrens Hospital/Flemington Rd // Commuter Routes { new MetlinkNode(19965, metlinkProvider), new MetlinkNode(19842, metlinkProvider) }, // Coburg - Melbourne Central { new MetlinkNode(19876, metlinkProvider), new MetlinkNode(19841, metlinkProvider) }, // Lilydale - Flagstaff { new MetlinkNode(19489, metlinkProvider), new MetlinkNode(19921, metlinkProvider) }, // Werribee - North Melbourne { new MetlinkNode(20005, metlinkProvider), new MetlinkNode(19843, metlinkProvider) }, // Epping - Parliament { new MetlinkNode(19855, metlinkProvider), new MetlinkNode(19854, metlinkProvider) } // Frankston - Flinders St }; bool first = true; DateTime time = DateTime.Parse("8:00 AM 7/05/2012"); bool cont = true; while (cont) { foreach (SearchType searchType in Enum.GetValues(typeof(SearchType))) { if (searchType == SearchType.DFS_BiDir || searchType == SearchType.DFS_Standard) continue; //foreach (bool bidir in new[] { true, false }) { for (int i = 0; i < testRoutes.GetLength(0); i++) { //try { testRoutes[i, 0].RetrieveData(); testRoutes[i, 1].RetrieveData(); EvolutionaryProperties properties = new EvolutionaryProperties(); properties.NetworkDataProviders = new [] {metlinkProvider}; properties.PointDataProviders = new [] {new WalkingDataProvider()}; properties.ProbMinDistance = 0.7; properties.ProbMinTransfers = 0.2; properties.MaximumWalkDistance = 1.5; properties.PopulationSize = 100; properties.MaxDistance = 0.5; properties.DepartureTime = time; properties.NumberToKeep = 25; properties.MutationRate = 0.1; properties.CrossoverRate = 0.7; //properties.Bidirectional = bidir; //properties.RouteGenerator = new AlRouteGenerator(properties); properties.SearchType = SearchType.Greedy_BiDir; properties.RouteGenerator = new DFSRoutePlanner(properties); properties.Mutator = new StandardMutator(properties); properties.Breeder = new StandardBreeder(properties); properties.FitnessFunction = new AlFitnessFunction(properties); properties.Database = new MySqlDatabase("20110606fordistributionforrmit"); properties.Destination = testRoutes[i, 0]; properties.Origin = testRoutes[i, 1]; properties.Destination.RetrieveData(); properties.Database.Open(); //properties.DataStructures = new DataStructures(properties); var planner = new EvolutionaryRoutePlanner(properties); Stopwatch sw = Stopwatch.StartNew(); planner.Start(); StreamWriter writer = new StreamWriter( "results/" + searchType + "-" + testRoutes[i, 0].Id + "-" + testRoutes[i, 1].Id + ".csv", true); writer.WriteLine( "[New iteration {0}-{1} ({2}-{3}) {4} @ {5}]", testRoutes[i, 0].Id, testRoutes[i, 1].Id, testRoutes[i, 0].StopSpecName, testRoutes[i, 1].StopSpecName, searchType, DateTime.Now.ToString(CultureInfo.InvariantCulture)); Console.WriteLine( "[New iteration {0}-{1} ({2}-{3}) {4} @ {5}]", testRoutes[i, 0].Id, testRoutes[i, 1].Id, testRoutes[i, 0].StopSpecName, testRoutes[i, 1].StopSpecName, searchType, DateTime.Now.ToString(CultureInfo.InvariantCulture)); writer.WriteLine( "Average UnifiedFitnessScore, Minimum Fitenss, Diversity Metric, Total Time (Iteration), Total Time (Test),Iteration number"); this.writeInfo(writer, planner, sw.Elapsed, 0); for (int j = 0; j < 99; j++) { planner.SolveStep(); this.writeInfo(writer, planner, sw.Elapsed, j + 1); } writer.WriteLine("Path: " + String.Join(",",planner.Result.BestPath)); writer.Close(); properties.Database.Close(); } /* catch (Exception e) { Console.WriteLine("Exception!: {0} ({1}). Writing to error log...", e, e.Message); StreamWriter writer = new StreamWriter("error.log", true); writer.WriteLine( "[{0}] Exception!: {1} ({2}).\n{3}", DateTime.Now.ToString(CultureInfo.InvariantCulture), e, e.Message, e.StackTrace); writer.WriteLine( "[Last error thrown on: {0}-{1} ({2}-{3}) {4} @ {5}]", testRoutes[i, 0].Id, testRoutes[i, 1].Id, testRoutes[i, 0].StopSpecName, testRoutes[i, 1].StopSpecName, searchType, DateTime.Now.ToString(CultureInfo.InvariantCulture)); writer.Close(); throw; } * */ } } } var reader = new StreamReader("cont.txt"); string result = reader.ReadToEnd().Trim(); switch (result) { case "yes": cont = true; break; case "no": cont = false; break; default: Console.WriteLine("Cant read {0}" , ((FileStream)reader.BaseStream).Name); break; } reader.Close(); } }
public TestFitnessFunction() { MetlinkDataProvider provider = new MetlinkDataProvider(); EvolutionaryProperties properties = new EvolutionaryProperties(); properties.DepartureTime = DateTime.Parse("27/06/2012 10:15 AM"); properties.NetworkDataProviders = new [] {provider}; properties.PointDataProviders = new [] {new WalkingDataProvider()}; properties.FitnessFunction = new AlFitnessFunction(properties); properties.Database = new MySqlDatabase("20110606fordistributionforrmit"); /* Route testRoute = new Route(-1) { new MetlinkNode(19967,provider), new MetlinkNode(19966,provider), new MetlinkNode(19965,provider), new MetlinkNode(9327,provider), new MetlinkNode(9326,provider), new MetlinkNode(9325,provider), new MetlinkNode(9324,provider), new MetlinkNode(9323,provider), new MetlinkNode(20754,provider), new MetlinkNode(9321,provider), new MetlinkNode(9320,provider), new MetlinkNode(9319,provider), new MetlinkNode(9318,provider), new MetlinkNode(9317,provider), new MetlinkNode(9316,provider), new MetlinkNode(9313,provider), new MetlinkNode(9312,provider), new MetlinkNode(20756,provider) }; foreach (var node in testRoute) { node.RetrieveData(); Console.WriteLine(node.ToString()); } Fitness score = properties.FitnessFunction.GetFitness(testRoute); */ Console.WriteLine("Press Enter."); Console.ReadLine(); for (int i = 0; i < 12; i++) { properties.DepartureTime = DateTime.Parse("27/06/2012 6:00 PM").AddMinutes(i*5); var testRoute = new Route(-1) { new MetlinkNode(19965, provider), new MetlinkNode(19966, provider), new MetlinkNode(19967, provider), new MetlinkNode(19968, provider), new MetlinkNode(19969, provider), new MetlinkNode(19970, provider), new MetlinkNode(19971, provider), new MetlinkNode(19972, provider), new MetlinkNode(19973, provider), new MetlinkNode(20041, provider), new MetlinkNode(20040, provider), new MetlinkNode(20039, provider), }; /** var testRoute = new Route(-1) { new MetlinkNode(9335 , provider), new MetlinkNode(9334 , provider), new MetlinkNode(9333 , provider), new MetlinkNode(9332 , provider), new MetlinkNode(9331 , provider), new MetlinkNode(9330 , provider), new MetlinkNode(9329 , provider), new MetlinkNode(9328 , provider), new MetlinkNode(9327 , provider), new MetlinkNode(9326 , provider), new MetlinkNode(9325 , provider), new MetlinkNode(9324 , provider), new MetlinkNode(9323 , provider), new MetlinkNode(20754 , provider), new MetlinkNode(9321 , provider), new MetlinkNode(9320 , provider), new MetlinkNode(9319 , provider), new MetlinkNode(9318 , provider), new MetlinkNode(9317 , provider), new MetlinkNode(9316 , provider), new MetlinkNode(9313 , provider), new MetlinkNode(9312 , provider), new MetlinkNode(20756 , provider), new MetlinkNode(9310 , provider), new MetlinkNode(20757 , provider), }; */ var score = properties.FitnessFunction.GetFitness(testRoute); Console.WriteLine("Score: {0}", score); //Thread.Sleep(1000); } //properties.Database.Open(); //properties.DataStructures = new DataStructures(properties); //EvolutionaryRoutePlanner planner = new EvolutionaryRoutePlanner(properties); // Stopwatch sw = Stopwatch.StartNew(); // planner.Start(); }
public TestDFS() { /* Console.WriteLine("Testing simple search on adjacency matrix..."); var ADFS = new AdjacencyDepthFirstSearch(adjacencyMatrix, 0, 5); int[] path = ADFS.Run(); Console.WriteLine("Result: " + String.Join(",\n",path)); Console.ReadLine(); */ var provider = new MetlinkDataProvider(); INetworkNode[] route = null; int depth = 7; Stopwatch sw = Stopwatch.StartNew(); Console.WriteLine("Testing on PT network... (DFS)"); while (route == null) { for (int i = 3; i < 11; i++) { checked { Console.Write("Solving to depth: {0} entropy {1} --> ", depth++, i / 10.0); long totalIterations = 0; long totalNodes = 0; for (int j = 0; j < 500; j++) { var tdfs = new PTGreedySearch(depth, true, provider, provider.GetNodeFromId(19965), provider.GetNodeFromId(19879)); tdfs.Entropy = i / 10.0; route = tdfs.Run(); totalIterations += tdfs.Iterations; totalNodes += route.Length; } Console.WriteLine( "Average Iterations: {0} Average Route Length: {1}", totalIterations / 500.0, totalNodes / 500.0); } } } //Console.WriteLine("Result: \n " + String.Join(",\n",route.Cast<object>()) + " Time: " + sw.Elapsed.TotalSeconds + " s"); Console.WriteLine("Result: Time: " + sw.Elapsed.TotalSeconds + " s Total nodes: " + route.Length); return; Console.ReadLine(); Console.WriteLine("Testing on PT network... (Greedy)"); sw.Restart(); route = null; depth = 7; while (route == null) { Console.Write("Solving to depth: {0} --> ", depth++); INetworkNode origin = provider.GetNodeFromId(19965); INetworkNode destination = provider.GetNodeFromId(19879); origin.RouteId = provider.GetRoutesForNode(origin)[0]; destination.RouteId = provider.GetRoutesForNode(destination)[0]; var tdfs = new PTGreedySearch(depth, true, provider, origin, destination); Console.WriteLine(""); route = tdfs.Run(); Console.WriteLine(""); Console.WriteLine("Iterations: " + tdfs.Iterations); } // Console.WriteLine("Result: \n" + String.Join(", ", route.Cast<object>()) + " Time: " + sw.Elapsed.TotalSeconds + " s Total nodes: " + route.Length); Console.WriteLine("Result: Time: " + sw.Elapsed.TotalSeconds + " s Total nodes: " + route.Length); Console.ReadLine(); Console.WriteLine("Testing on PT network... (A*)"); sw.Restart(); route = null; depth = 7; while (route == null) { Console.Write("Solving to depth: {0} --> ", depth++); INetworkNode origin = provider.GetNodeFromId(19965); INetworkNode destination = provider.GetNodeFromId(19879); origin.RouteId = provider.GetRoutesForNode(origin)[0]; destination.RouteId = provider.GetRoutesForNode(destination)[0]; var tdfs = new PTAStarSearch(depth,true, provider, origin, destination); Console.WriteLine(""); route = tdfs.Run(); Console.WriteLine(""); Console.WriteLine("Iterations: " + tdfs.Iterations); } //Console.WriteLine("Result: \n" + String.Join(", ", route.Cast<object>()) + " Time: " + sw.Elapsed.TotalSeconds + " s Total nodes: " + route.Length); Console.WriteLine("Result: Time: " + sw.Elapsed.TotalSeconds + " s Total nodes: " + route.Length); /* Console.WriteLine("Testing on PT network... (Rand)"); sw.Restart(); route = null; depth = 7; while (route == null) { Console.Write("Solving to depth: {0} --> ", depth++); INetworkNode origin = provider.GetNodeFromId(19965); INetworkNode destination = provider.GetNodeFromId(19842); origin.RouteId = provider.GetRoutesForNode(origin)[0]; destination.RouteId = provider.GetRoutesForNode(destination)[0]; var tdfs = new RandDepthFirstSearch(false, depth, provider, origin, destination); Console.WriteLine(""); route = tdfs.Run(); Console.WriteLine(""); Console.WriteLine("Iterations: " + tdfs.Iterations); } Console.WriteLine("Result: " + String.Join(",\n", route.Cast<object>()) + " Time: " + sw.Elapsed.TotalSeconds + " s"); */ }