public ProfileView(Profiles.Profile _Profile = null, bool Sync = false) { InitializeComponent(); Translate(); Edit = _Profile != null; Profile = _Profile; if (Edit) { Description.Text = Profile.Description; Gameversion.SelectedIndex = Profile.GameVersion; TSV.Value = Profile.TSV; ShinyCharm.Checked = Profile.ShinyCharm; Key3.Value = Profile.Seeds[3]; Key2.Value = Profile.Seeds[2]; Key1.Value = Profile.Seeds[1]; Key0.Value = Profile.Seeds[0]; } else { Gameversion.SelectedIndex = 0; } // Sync from mainwindow if (Sync) { B_Current_Click(null, null); } }
/// <summary> /// Tests calculating a number of routes. /// </summary> public static Action GetTestInstructionGenerationParallel(Router router, Profiles.Profile profile, int count) { var random = new System.Random(); return(() => { var errors = 0; System.Threading.Tasks.Parallel.ForEach(Enumerable.Range(0, count), (x) => { var v1 = (uint)random.Next((int)router.Db.Network.VertexCount); var v2 = (uint)random.Next((int)router.Db.Network.VertexCount - 1); if (v1 == v2) { v2++; } var f1 = router.Db.Network.GetVertex(v1); var f2 = router.Db.Network.GetVertex(v2); var route = router.TryCalculate(Itinero.Osm.Vehicles.Vehicle.Car.Fastest(), f1, f2); if (route.IsError) { errors++; } else { var instructions = route.Value.GenerateInstructions(); } }); Itinero.Logging.Logger.Log("Runner", Logging.TraceEventType.Information, "{0}/{1} routes failed.", errors, count); }); }
/// <summary> /// Tests calculating a number of routes. /// </summary> public static Action GetTestRandomRoutes(Router router, Profiles.Profile profile, int count) { var random = new System.Random(); return(() => { var i = count; var errors = 0; while (i > 0) { i--; var v1 = (uint)random.Next((int)router.Db.Network.VertexCount); var v2 = (uint)random.Next((int)router.Db.Network.VertexCount - 1); if (v1 == v2) { v2++; } var f1 = router.Db.Network.GetVertex(v1); var f2 = router.Db.Network.GetVertex(v2); var route = router.TryCalculate(Itinero.Osm.Vehicles.Vehicle.Car.Fastest(), f1, f2); if (route.IsError) { errors++; } } Itinero.Logging.Logger.Log("Runner", Logging.TraceEventType.Information, "{0}/{1} routes failed.", errors, count); }); }
/// <summary> /// Tests calculating a number of routes. /// </summary> public static Action GetTestRandomRoutes(Router router, Profiles.Profile profile, int count) { var random = new System.Random(); return(() => { var i = count; while (i > 0) { i--; var v1 = (uint)random.Next((int)router.Db.Network.VertexCount); var v2 = (uint)random.Next((int)router.Db.Network.VertexCount - 1); if (v1 == v2) { v2++; } var f1 = router.Db.Network.GetVertex(v1); var f2 = router.Db.Network.GetVertex(v2); var route = router.TryCalculate(Vehicle.Car.Fastest(), f1, f2); } }); }
/// <summary> /// Tests calculating a number of routes. /// </summary> public static Action GetTestInstructionGenerationParallel(Router router, Profiles.Profile profile, int count) { var random = new System.Random(); var routes = new List <Route>(); while (routes.Count < count) { var v1 = (uint)random.Next((int)router.Db.Network.VertexCount); var v2 = (uint)random.Next((int)router.Db.Network.VertexCount - 1); if (v1 == v2) { v2++; } var f1 = router.Db.Network.GetVertex(v1); var f2 = router.Db.Network.GetVertex(v2); var route = router.TryCalculate(Itinero.Osm.Vehicles.Vehicle.Car.Fastest(), f1, f2); if (!route.IsError) { routes.Add(route.Value); } } return(() => { System.Threading.Tasks.Parallel.ForEach(Enumerable.Range(0, count), (x) => { var instructions = routes[x].GenerateInstructions(); }); }); }
/// <summary> /// Tests a number of resolves. /// </summary> public static Action GetTestRandomResolves(Router router, Profiles.Profile profile, int count) { var random = new System.Random(); return(() => { var i = count; var errors = 0; while (i > 0) { i--; var v1 = (uint)random.Next((int)router.Db.Network.VertexCount); var f1 = router.Db.Network.GetVertex(v1); var routerPoint = router.TryResolve(profile, f1); if (routerPoint.IsError) { errors++; } } Itinero.Logging.Logger.Log("Runner", Logging.TraceEventType.Information, "{0}/{1} resolves failed.", errors, count); }); }
/// <summary> /// Adds a transfers db. /// </summary> public static void AddTransfersDb(this TransitDb db, Profiles.Profile profile, IAttributeCollection defaultProfile, float maxTimeInSeconds) { var transfersDb = new TransfersDb(db.StopsCount); var factor = profile.Factor(defaultProfile); // add all transfers. var enumerator1 = db.GetStopsEnumerator(); while (enumerator1.MoveNext()) { var enumerator2 = db.GetStopsEnumerator(); while (enumerator2.MoveNext()) { if (enumerator1.Id < enumerator2.Id) { var distance = Coordinate.DistanceEstimateInMeter(enumerator1.Latitude, enumerator1.Longitude, enumerator2.Latitude, enumerator2.Longitude); var time = (int)System.Math.Round(distance * factor.Value, 0); if (time < maxTimeInSeconds) { transfersDb.AddTransfer(enumerator1.Id, enumerator2.Id, time); } } } } db.AddTransfersDb(profile, transfersDb); }
/// <summary> /// Tests adding a contracted graph. /// </summary> public static Action GetTestAddContracted(RouterDb routerDb, Profiles.Profile profile, bool forceEdgeBased) { return(() => { routerDb.AddContracted(profile, forceEdgeBased); }); }
/// <summary> /// Tests calculating a weight matrix. /// </summary> public static Action GetTestDirectedWeightMatrix(Router router, Profiles.Profile profile, int count) { var random = new System.Random(145171654); var vertices = new HashSet <uint>(); var locations = new List <Coordinate>(); while (locations.Count < count) { var v = (uint)random.Next((int)router.Db.Network.VertexCount); if (!vertices.Contains(v)) { vertices.Add(v); locations.Add(router.Db.Network.GetVertex(v)); } } var locationsArray = locations.ToArray(); var massResolver = new MassResolvingAlgorithm(router, new Profiles.IProfileInstance[] { profile }, locationsArray); massResolver.Run(); var edges = new List <DirectedEdgeId>(); foreach (var resolved in massResolver.RouterPoints) { edges.Add(new DirectedEdgeId(resolved.EdgeId, true)); edges.Add(new DirectedEdgeId(resolved.EdgeId, false)); } return(() => { var result = router.TryCalculateWeight(profile, edges.ToArray(), edges.ToArray(), null); }); }
/// <summary> /// Tests calculating a weight matrix. /// </summary> public static Action GetTestWeightMatrix(Router router, Profiles.Profile profile, int count) { var random = new System.Random(145171654); var vertices = new HashSet <uint>(); var locations = new List <Coordinate>(); while (locations.Count < count) { var v = (uint)random.Next((int)router.Db.Network.VertexCount); if (!vertices.Contains(v)) { vertices.Add(v); locations.Add(router.Db.Network.GetVertex(v)); } } var locationsArray = locations.ToArray(); var massResolver = new MassResolvingAlgorithm(router, new Profiles.IProfileInstance[] { profile }, locationsArray); massResolver.Run(); return(() => { var invalids = new HashSet <int>(); var weights = router.CalculateWeight(profile, massResolver.RouterPoints.ToArray(), invalids); }); }
/// <summary> /// Tests calculating a weight matrix. /// </summary> public static Action GetTestWeightMatrixAlgorithm(Router router, Profiles.Profile profile, int count) { var random = new System.Random(145171654); var vertices = new HashSet <uint>(); var locations = new List <Coordinate>(); while (locations.Count < count) { var v = (uint)random.Next((int)router.Db.Network.VertexCount); if (!vertices.Contains(v)) { vertices.Add(v); locations.Add(router.Db.Network.GetVertex(v)); } } var locationsArray = locations.ToArray(); var massResolver = new MassResolvingAlgorithm(router, new Profiles.IProfileInstance[] { profile }, locationsArray); massResolver.Run(); return(() => { var matrix = new Itinero.Algorithms.Matrices.WeightMatrixAlgorithm(router, profile, massResolver); matrix.Run(); Assert.IsTrue(matrix.HasSucceeded); }); }
/// <summary> /// Gets the stop links db. /// </summary> public StopLinksDb GetStopLinksDb(Profiles.Profile profile) { if (profile == null) { throw new ArgumentNullException("profile"); } return(_stoplinksDbs[profile.Name]); }
/// <summary> /// Returns true if there is a transfers db for the given profile. /// </summary> public bool HasTransfersDb(Profiles.Profile profile) { if (profile == null) { throw new ArgumentNullException("profile"); } return(_transfersDbs.ContainsKey(profile.Name)); }
/// <summary> /// Returns true if there is a stop links db for the given profile. /// </summary> public bool HasStopLinksDb(Profiles.Profile profile) { if (profile == null) { throw new ArgumentNullException("profile"); } return(_stoplinksDbs.ContainsKey(profile.Name)); }
/// <summary> /// Tests a number of resolves. /// </summary> public static Func <string> GetTestRandomResolvesCached(Router router, Profiles.Profile profile, int count, int unique) { var random = new System.Random(); var pool = new List <Coordinate>(); // make sure all locations are near to accessible roads. while (pool.Count < unique) { var v1 = (uint)random.Next((int)router.Db.Network.VertexCount); var f1 = router.Db.Network.GetVertex(v1); var factor = router.GetDefaultGetFactor(profile); var edgeEnumerator = router.Db.Network.GetEdgeEnumerator(); edgeEnumerator.MoveTo(v1); while (edgeEnumerator.MoveNext()) { var f = factor(edgeEnumerator.Current.Data.Profile); if (f.Value != 0) { pool.Add(router.Db.Network.GetVertex(v1)); break; } } } var vertices = new List <Coordinate>(); while (vertices.Count < count) { var p = random.Next(unique); vertices.Add(pool[p]); } // make sure the router is fresh. router = new Router(router.Db); // resolve all. return(() => { router.ResolverCache = new ResolverCache(); var errors = 0; for (var i = 0; i < vertices.Count; i++) { var routerPoint = router.TryResolve(profile, vertices[i]); if (routerPoint.IsError) { errors++; } } router.ResolverCache = null; return string.Format("{0}/{1} cached resolves failed.", errors, count); }); }
/// <summary> /// Adds the transfers db. /// </summary> public void AddTransfersDb(Profiles.Profile profile, TransfersDb db) { if (profile == null) { throw new ArgumentNullException("profile"); } if (db == null) { throw new ArgumentNullException("db"); } _transfersDbs[profile.Name] = db; }
/// <summary> /// Tests adding islands data. /// </summary> public static Action GetTestAddIslandData(RouterDb routerDb, Profiles.Profile profile) { return(() => { routerDb.AddIslandData(profile); #if DEBUG MetaCollection <ushort> islands; if (routerDb.VertexData.TryGet("islands_" + profile.FullName, out islands)) { var islandDb = routerDb.ExtractArea(v => { return islands[v] != ushort.MaxValue; }, (f, t) => { var fromCount = islands[f]; var toCount = islands[t]; //if (fromCount != Constants.ISLAND_SINGLETON && // toCount != Constants.ISLAND_SINGLETON) //{ // return false; //} if (fromCount < 1024 && fromCount != 0 && fromCount != Constants.ISLAND_RESTRICTED) { return true; } if (toCount < 1024 && toCount != 0 && toCount != Constants.ISLAND_RESTRICTED) { return true; } if (toCount == Constants.ISLAND_RESTRICTED && fromCount == Constants.ISLAND_RESTRICTED) { // single-vertex restrictions on both sides. return true; } return false; }); File.WriteAllText("islands_" + profile.FullName + ".geojson", islandDb.GetGeoJson(true, false)); } #endif }); }
/// <summary> /// Gets the transfers db. /// </summary> public TransfersDb GetTransfersDb(Profiles.Profile profile) { if (profile == null) { throw new ArgumentNullException("profile"); } TransfersDb transfersDb = null; if (_transfersDbs.TryGetValue(profile.Name, out transfersDb)) { return(transfersDb); } return(null); }
/// <summary> /// Tests calculating a number of routes. /// </summary> public static Func <string> GetTestRandomDirectedRoutes(Router router, Profiles.Profile profile, int count) { var random = new System.Random(); var list = new List <Tuple <RouterPoint, bool> >(); while (list.Count < count * 2) { var v1 = (uint)random.Next((int)router.Db.Network.VertexCount); var f1 = router.Db.Network.GetVertex(v1); var resolved = router.TryResolve(profile, f1); if (resolved.IsError) { continue; } var direction = random.NextDouble() >= 0.5; list.Add(new Tuple <RouterPoint, bool>(resolved.Value, direction)); } return(() => { var errors = 0; var success = 0; for (var i = 0; i < list.Count; i += 2) { var route = router.TryCalculate(profile, list[i].Item1, list[i].Item2, list[i + 1].Item1, list[i + 1].Item2); if (route.IsError) { #if DEBUG var startJson = list[i].Item1.ToGeoJson(router.Db); var endJson = list[i + 1].Item1.ToGeoJson(router.Db); #endif errors++; } else { #if DEBUG var startJson = list[i].Item1.ToGeoJson(router.Db); var endJson = list[i + 1].Item1.ToGeoJson(router.Db); #endif success++; } } return string.Format("{0}/{1} routes failed.", errors, count); }); }
/// <summary> /// Tests calculating a number of routes. /// </summary> public static Func <string> GetTestRandomRoutesParallel(Router router, Profiles.Profile profile, int count) { var random = new System.Random(); var list = new List <RouterPoint>(); while (list.Count < count * 2) { var v1 = (uint)random.Next((int)router.Db.Network.VertexCount); var f1 = router.Db.Network.GetVertex(v1); var resolved = router.TryResolve(profile, f1); if (resolved.IsError) { continue; } var direction = random.NextDouble() >= 0.5; list.Add(resolved.Value); } return(() => { var errors = 0; var success = 0; System.Threading.Tasks.Parallel.ForEach(Enumerable.Range(0, count), (x) => { int i = x * 2; var route = router.TryCalculate(profile, list[i], list[i + 1]); if (route.IsError) { #if DEBUG var startJson = list[i].ToGeoJson(router.Db); var endJson = list[i + 1].ToGeoJson(router.Db); #endif errors++; } else { #if DEBUG var startJson = list[i].ToGeoJson(router.Db); var endJson = list[i + 1].ToGeoJson(router.Db); #endif success++; } }); return string.Format("{0}/{1} routes failed.", errors, count); }); }
/// <summary> /// Tests calculating a number of directed sequences. /// </summary> public static Func <string> GetTestDirectedSequences(Router router, Profiles.Profile profile, int count) { var random = new System.Random(); var list = new List <(RouterPoint[] routerpoints, float?[] preferredDirections)> { (router.Resolve(profile, StagingHelper.GetLocations("./Tests/data/sequence1.geojson")), null), // http://geojson.io/#id=gist:xivk/e4d07e82b1abfb424e4626ab0b6fc2c9&map=15/49.8486/6.0846 (router.Resolve(profile, StagingHelper.GetLocations("./Tests/data/sequence1.geojson")), new float?[] { 90f, null, null }), // http://geojson.io/#id=gist:xivk/ec116b8a58c0a2a93c7f53a86603139c&map=16/49.8501/6.0792 (router.Resolve(profile, StagingHelper.GetLocations("./Tests/data/sequence1.geojson")), new float?[] { null, -90, null }), // http://geojson.io/#id=gist:xivk/e4d07e82b1abfb424e4626ab0b6fc2c9&map=15/49.8486/6.0846 (router.Resolve(profile, StagingHelper.GetLocations("./Tests/data/sequence1.geojson")), new float?[] { 90f, null, 90 }), // the last perferred direction is impossible, but this should still work. (router.Resolve(profile, StagingHelper.GetLocations("./Tests/data/sequence2.geojson")), null), (router.Resolve(profile, StagingHelper.GetLocations("./Tests/data/sequence2.geojson")), new float?[] { null, null, null, null, null, null, null, 180, null, -90 }), (router.Resolve(profile, StagingHelper.GetLocations("./Tests/data/sequence3.geojson")), null) }; return(() => { var errors = 0; for (var i = 0; i < list.Count; i++) { var route = router.TryCalculate(profile, list[i].routerpoints, 60, list[i].preferredDirections); if (route.IsError) { #if DEBUG #endif errors++; } else { #if DEBUG var json = route.Value.ToGeoJson(); #endif } } return string.Format("{0}/{1} routes failed.", errors, list.Count); }); }
/// <summary> /// Tests a number of resolves. /// </summary> public static Func <string> GetTestRandomResolvesParallel(Router router, Profiles.Profile profile, int count) { var random = new System.Random(); var vertices = new List <Coordinate>(); // make sure all locations are near to accesible roads. while (vertices.Count < count) { var v1 = (uint)random.Next((int)router.Db.Network.VertexCount); var f1 = router.Db.Network.GetVertex(v1); var factor = router.GetDefaultGetFactor(profile); var edgeEnumerator = router.Db.Network.GetEdgeEnumerator(); edgeEnumerator.MoveTo(v1); while (edgeEnumerator.MoveNext()) { var f = factor(edgeEnumerator.Current.Data.Profile); if (f.Value != 0) { vertices.Add(router.Db.Network.GetVertex(v1)); break; } } } // make sure the router is fresh. router = new Router(router.Db); // resolve all. return(() => { var errors = 0; System.Threading.Tasks.Parallel.ForEach(Enumerable.Range(0, count), (x) => { var routerPoint = router.TryResolve(profile, vertices[x]); if (routerPoint.IsError) { errors++; } }); return string.Format("{0}/{1} resolves failed.", errors, vertices.Count); }); }
/// <summary> /// Tests a number of resolves. /// </summary> public static Action GetTestRandomResolvesParallel(Router router, Profiles.Profile profile, int count) { var random = new System.Random(); return(() => { var errors = 0; System.Threading.Tasks.Parallel.ForEach(Enumerable.Range(0, count), (x) => { var v1 = (uint)random.Next((int)router.Db.Network.VertexCount); var f1 = router.Db.Network.GetVertex(v1); var routerPoint = router.TryResolve(profile, f1); if (routerPoint.IsError) { errors++; } }); Itinero.Logging.Logger.Log("Runner", Logging.TraceEventType.Information, "{0}/{1} resolves failed.", errors, count); }); }
private void B_Save_Click(object sender, EventArgs e) { if (string.IsNullOrWhiteSpace(Description.Text)) { MessageBox.Show("Description field is empty!", "Empty field!", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } var newProfile = new Profiles.Profile() { Description = Description.Text, GameVersion = Gameversion.SelectedIndex, TSV = (ushort)TSV.Value, TRV = (byte)TRV.Value, ShinyCharm = ShinyCharm.Checked, Seeds = new uint[] { Key0.Value, Key1.Value, Key2.Value, Key3.Value, } }; if (Edit) { int i = Profiles.GameProfiles.IndexOf(Profile); Profiles.GameProfiles[i] = newProfile; } else { Profiles.GameProfiles.Add(newProfile); } Profiles.WriteProfiles(); MessageBox.Show("Profiles updated!", "Success!", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); Close(); }
/// <summary> /// Tests calculating a number of sequences. /// </summary> public static Func <string> GetTestSequences(Router router, Profiles.Profile profile, int count) { var random = new System.Random(); var list = new List <RouterPoint[]>(); var locations = StagingHelper.GetLocations("./Tests/data/sequence1.geojson"); var routerpoints = router.Resolve(profile, locations); list.Add(routerpoints); locations = StagingHelper.GetLocations("./Tests/data/sequence2.geojson"); routerpoints = router.Resolve(profile, locations); list.Add(routerpoints); return(() => { var errors = 0; for (var i = 0; i < list.Count; i++) { var route = router.TryCalculate(profile, list[i].ToArray()); if (route.IsError) { #if DEBUG #endif errors++; } else { #if DEBUG var json = route.Value.ToGeoJson(); #endif } } return string.Format("{0}/{1} routes failed.", errors, list.Count); }); }
public async Task GetById_Ok() { //Setup var id = Guid.NewGuid(); var profile = new Profiles.Profile(id, "firstName", "lastName", "Male", DateTimeOffset.Now, "City", string.Empty); var serviceMock = new Mock <IProfileService>(); serviceMock .Setup(x => x.GetByIdAsync(id)) .ReturnsAsync(profile); var client = TestServerHelper.New(collection => { collection.AddScoped(_ => serviceMock.Object); }); //Act var response = await client.GetAsync($"profiles/{id}"); //Assert Assert.AreEqual(HttpStatusCode.OK, response.StatusCode); }
/// <summary> /// Adds a transfers db. /// </summary> public static void AddTransfersDb(this TransitDb db, Profiles.Profile profile, float maxTimeInSeconds) { db.AddTransfersDb(profile, TransitDbExtensions.DefaultEdgeProfile, maxTimeInSeconds); }
/// <summary> /// Tests a number of resolve connected. /// </summary> public static Func <string> GetTestRandomResolvesConnectedParallel(Router router, Profiles.Profile profile, int count, int testIterations = 5) { var random = new System.Random(); var vertices = new List <Coordinate>(); // make sure all locations are near to accessible roads. while (vertices.Count < count) { var v1 = (uint)random.Next((int)router.Db.Network.VertexCount); var f1 = router.Db.Network.GetVertex(v1); var factor = router.GetDefaultGetFactor(profile); var edgeEnumerator = router.Db.Network.GetEdgeEnumerator(); edgeEnumerator.MoveTo(v1); while (edgeEnumerator.MoveNext()) { var f = factor(edgeEnumerator.Current.Data.Profile); if (f.Value != 0) { vertices.Add(router.Db.Network.GetVertex(v1)); break; } } } return(() => { // resolve all. var errors = 0; for (var i = 0; i < testIterations; i++) { // make sure the router is fresh. router = new Router(router.Db); System.Threading.Tasks.Parallel.ForEach(Enumerable.Range(0, count), (x) => { var routerPoint = router.TryResolveConnected(profile, vertices[x], 1000, 250); if (routerPoint.IsError) { errors++; } }); } return $"{errors}/{vertices.Count * testIterations} resolves failed in {testIterations} iterations."; }); }
/// <summary> /// Tests calculating a collection of one to one routes. /// </summary> public static Func <EdgePath <float>[][]> GetTestManyToManyRoutes(Router router, Profiles.Profile profile, int size) { var random = new System.Random(); var vertices = new HashSet <uint>(); while (vertices.Count < size) { var v = (uint)random.Next((int)router.Db.Network.VertexCount); if (!vertices.Contains(v)) { vertices.Add(v); } } var resolvedPoints = new RouterPoint[vertices.Count]; var i = 0; foreach (var v in vertices) { resolvedPoints[i] = router.Resolve(profile, router.Db.Network.GetVertex(v), 500); i++; } return(() => { return router.TryCalculateRaw(profile, router.GetDefaultWeightHandler(profile), resolvedPoints, resolvedPoints, null).Value; }); }
/// <summary> /// Tests calculating a collection of one to one routes. /// </summary> public static Func <PerformanceTestResult <EdgePath <float>[][]> > GetTestManyToManyRoutes(Router router, Profiles.Profile profile, int size) { var random = new System.Random(); var list = new List <RouterPoint>(); while (list.Count < size) { var v1 = (uint)random.Next((int)router.Db.Network.VertexCount); var f1 = router.Db.Network.GetVertex(v1); var resolved = router.TryResolve(profile, f1); if (resolved.IsError) { continue; } var direction = random.NextDouble() >= 0.5; list.Add(resolved.Value); } var resolvedPoints = list.ToArray(); return(() => { return new PerformanceTestResult <EdgePath <float>[][]>( router.TryCalculateRaw(profile, router.GetDefaultWeightHandler(profile), resolvedPoints, resolvedPoints, null).Value); }); }