public static void SearchSingle(String filePath, String outDir, bool quiet = false) { // if (!filePath.Contains("180")) // return; Console.ForegroundColor = ConsoleColor.Yellow; Console.WriteLine("Loading file {0}", filePath); Graph graph = Graph.FromFile(filePath); Console.WriteLine("Graph loaded: {0} has {1} vertices", graph.Name, graph.Count); #if ALGA String savePath = outDir + DSC + "TourfileA" + DSC + "tour" + graph.Name + ".txt"; #else String savePath = outDir + DSC + "TourfileB" + DSC + "tour" + graph.Name + ".txt"; #endif String datePath = Path.GetDirectoryName(savePath) + Path.DirectorySeparatorChar; datePath += Path.GetFileNameWithoutExtension(savePath) + "."; datePath += DateTime.Now.ToShortDateString().Replace('/', '-'); datePath += Path.GetExtension(savePath); Route best = null; if (File.Exists(savePath)) { best = Route.FromFile(graph, savePath); Console.Write("Record to beat: "); Console.ForegroundColor = ConsoleColor.White; Console.Write(best.Length); Console.ForegroundColor = ConsoleColor.Yellow; Console.WriteLine(" ({0})", File.GetLastWriteTime(savePath).ToShortDateString()); } Route dayBest = null; if (File.Exists(datePath)) { dayBest = Route.FromFile(graph, datePath); Console.Write("Today's record: "); Console.ForegroundColor = ConsoleColor.White; Console.Write(dayBest.Length); Console.ForegroundColor = ConsoleColor.Yellow; Console.WriteLine(" ({0})", File.GetLastWriteTime(datePath).ToShortTimeString()); } bool record = false; bool dayRecord = false; #if ALGA var searcher = new StochasticHillClimbSearcher(new ReversingSearcher()) { Attempts = graph.Count < 17 ? 256 : graph.Count < 50 ? 65536 : graph.Count < 100 ? 32768 : graph.Count < 500 ? 8192 : 4096, Threads = 4 }; #else var searcher = new AntColonySearcher <Ant> { Threads = 4, AntCount = 48 * graph.Count, StepCount = 65536 }; #endif searcher.BetterRouteFound += (sender, e) => { if (best == null || e.Route.Length < best.Length) { record = dayRecord = true; e.Route.Save(savePath); e.Route.Save(datePath); /* * /* * try { * Process.Start("git", string.Format("add {0}", savePath)); * Process.Start("git", string.Format("commit -m \"[AUTO] New all time record for {0}\"", graph.Name)); * Process.Start("git", "push origin linux"); * } catch { * * } */ } else if (dayBest == null || e.Route.Length < dayBest.Length) { dayRecord = true; e.Route.Save(datePath); } }; Route route = RunSearch(graph, searcher, null, quiet); if (record || route.Save(savePath)) { Console.ForegroundColor = ConsoleColor.Yellow; Console.WriteLine("****************"); Console.WriteLine("** NEW RECORD **"); Console.WriteLine("****************"); route.Save(datePath); } else if (dayRecord || route.Save(datePath)) { Console.ForegroundColor = ConsoleColor.Yellow; Console.WriteLine("================"); Console.WriteLine("== DAY RECORD =="); Console.WriteLine("================"); } }
public static void SearchSingle( String filePath, String outDir, bool quiet = false ) { // if (!filePath.Contains("180")) // return; Console.ForegroundColor = ConsoleColor.Yellow; Console.WriteLine( "Loading file {0}", filePath ); Graph graph = Graph.FromFile( filePath ); Console.WriteLine( "Graph loaded: {0} has {1} vertices", graph.Name, graph.Count ); #if ALGA String savePath = outDir + DSC + "TourfileA" + DSC + "tour" + graph.Name + ".txt"; #else String savePath = outDir + DSC + "TourfileB" + DSC + "tour" + graph.Name + ".txt"; #endif String datePath = Path.GetDirectoryName( savePath ) + Path.DirectorySeparatorChar; datePath += Path.GetFileNameWithoutExtension( savePath ) + "."; datePath += DateTime.Now.ToShortDateString().Replace( '/', '-' ); datePath += Path.GetExtension( savePath ); Route best = null; if ( File.Exists( savePath ) ) { best = Route.FromFile( graph, savePath ); Console.Write( "Record to beat: " ); Console.ForegroundColor = ConsoleColor.White; Console.Write( best.Length ); Console.ForegroundColor = ConsoleColor.Yellow; Console.WriteLine( " ({0})", File.GetLastWriteTime( savePath ).ToShortDateString() ); } Route dayBest = null; if ( File.Exists( datePath ) ) { dayBest = Route.FromFile( graph, datePath ); Console.Write( "Today's record: " ); Console.ForegroundColor = ConsoleColor.White; Console.Write( dayBest.Length ); Console.ForegroundColor = ConsoleColor.Yellow; Console.WriteLine( " ({0})", File.GetLastWriteTime( datePath ).ToShortTimeString() ); } bool record = false; bool dayRecord = false; #if ALGA var searcher = new StochasticHillClimbSearcher(new ReversingSearcher()) { Attempts = graph.Count < 17 ? 256 : graph.Count < 50 ? 65536 : graph.Count < 100 ? 32768 : graph.Count < 500 ? 8192 : 4096, Threads = 4 }; #else var searcher = new AntColonySearcher<Ant> { Threads = 4, AntCount = 48 * graph.Count, StepCount = 65536 }; #endif searcher.BetterRouteFound += ( sender, e ) => { if ( best == null || e.Route.Length < best.Length ) { record = dayRecord = true; e.Route.Save( savePath ); e.Route.Save( datePath ); /* /* try { Process.Start("git", string.Format("add {0}", savePath)); Process.Start("git", string.Format("commit -m \"[AUTO] New all time record for {0}\"", graph.Name)); Process.Start("git", "push origin linux"); } catch { } */ } else if ( dayBest == null || e.Route.Length < dayBest.Length ) { dayRecord = true; e.Route.Save( datePath ); } }; Route route = RunSearch( graph, searcher, null, quiet ); if ( record || route.Save( savePath ) ) { Console.ForegroundColor = ConsoleColor.Yellow; Console.WriteLine( "****************" ); Console.WriteLine( "** NEW RECORD **" ); Console.WriteLine( "****************" ); route.Save( datePath ); } else if ( dayRecord || route.Save( datePath ) ) { Console.ForegroundColor = ConsoleColor.Yellow; Console.WriteLine( "================" ); Console.WriteLine( "== DAY RECORD ==" ); Console.WriteLine( "================" ); } }