public string Solve(IRouteSource routeSource, int maxSecondsWithoutImprovement) { if (routeSource.OptimalRoute != null) { Console.WriteLine("Expect optimal route " + routeSource.OptimalRoute + " to have fitness " + CalculateRouteLength(routeSource.OptimalRoute, routeSource)); } var stopwatch = new Stopwatch(); stopwatch.Start(); var geneticSolver = new GeneticSolver { GetCanonicalGenes = GetCanonicalGenes, MaxSecondsWithoutImprovement = maxSecondsWithoutImprovement, NumberOfParentLines = 4 }; string result = geneticSolver.GetBest( routeSource.GeneSet.Length, routeSource.GeneSet, child => CalculateRouteLength(child, routeSource), (generation, fitness, genes, strategy) => Display(generation, fitness, genes, strategy, stopwatch)); Console.WriteLine(GetCanonicalGenes(result)); return GetCanonicalGenes(result); }
public ICloudQueueSendOnlyBusConfigurationBuilder RouteUsing(IRouteSource source) { if (source == null) throw new ArgumentNullException("source"); foreach (var route in source.Read()) { _routes.Add(route); } return this; }
public static void Configure(IRouteSource routeSource, IRouteMonitor routeMonitor = null) { if (routeSource == null) throw new ArgumentNullException("routeSource"); Register(RouteTable.Routes, routeSource.GetRouteItems()); if (routeMonitor != null) routeMonitor.Monitor(routeSource, Register); }
public RoutingHost(ILoggerFactory logger, CustomRouter router, IRouteStore store, IRouteSource source, IRoutingConfig config) { _router = router; _logger = logger?.CreateLogger <RoutingHost>(); _store = store; _source = source; _config = config; var ignore = WatchLoop(); }
public static int CalculateRouteLength( string sequence, IRouteSource routeSource) { var points = sequence.ToList(); int distinctCount = points.Distinct().Count(); points.Add(points[0]); double routeLength = points .Select((x, i) => i == 0 ? 0 : routeSource.GetDistance(x, points[i - 1])) .Sum(); int fitness = 1000 * (sequence.Length - distinctCount) + (int)Math.Floor(routeLength); return fitness; }
public static IAppBuilder UseDashboard(this IAppBuilder app, string pathMatch, IDashboardOptions options, IRouteSource routeSource) { if (app == null) { throw new ArgumentNullException(nameof(app)); } if (pathMatch == null) { throw new ArgumentNullException(nameof(pathMatch)); } if (options == null) { throw new ArgumentNullException(nameof(options)); } if (routeSource == null) { throw new ArgumentException(nameof(routeSource)); } SignatureConversions.AddConversions(app); app.Map(pathMatch, subApp => { var routes = routeSource.GetRoutes(); void TempQualifier(Func <IDictionary <string, object>, MidFunc> middleware) => subApp.Use(middleware(subApp.Properties)); if (routes == null) { throw new ArgumentNullException(nameof(routes)); } TempQualifier(_ => UseDashboard(options, routes)); }); return(app); }
public void Monitor(IRouteSource routeSource, Action<RouteCollection, IEnumerable<RouteItem>> action) { _watcher = new FileSystemWatcher(HostingEnvironment.MapPath("~/"), _routeConfigFileName); _watcher.IncludeSubdirectories = true; _watcher.EnableRaisingEvents = true; _watcher.NotifyFilter = NotifyFilters.LastAccess | NotifyFilters.LastWrite | NotifyFilters.FileName | NotifyFilters.DirectoryName; Action a = () => { try { _watcher.EnableRaisingEvents = false; action(RouteTable.Routes, routeSource.GetRouteItems()); _watcher.EnableRaisingEvents = true; } catch { } // we don't want to put the server down if some exception happens. we have to do some logging here. }; _watcher.Created += delegate(object sender, FileSystemEventArgs e) { a(); }; _watcher.Deleted += delegate(object sender, FileSystemEventArgs e) { a(); }; _watcher.Changed += delegate(object sender, FileSystemEventArgs e) { a(); }; _watcher.Renamed += delegate(object sender, RenamedEventArgs e) { a(); }; }
public void Add(IRouteSource routeSource) { Guard.AgainstNull(nameof(routeSource), routeSource); routeSources.Add(routeSource); }
public void Add(IRouteSource routeSource) { Guard.AgainstNull(nameof(routeSource), routeSource); routeSources.Add(routeSource); }