/// <summary> /// Configure the tour planning with a scenario by specifying its size via <paramref name="scenarioSize"/>. /// </summary> /// <param name="scenarioSize">Specifies the amount of objects, which will be created randomly.</param> public async void SetScenario(ScenarioSize scenarioSize) { SendProgressInfo("Initializing..."); var center = new Point(6.130833, 49.611389); // LUX //var center = new System.Windows.Point(8.4, 49); // KA var radius = 7.5; // radius in km try { var s = await Task.Run(() => RandomScenarioBuilder.CreateScenario(scenarioSize, center, radius)); wpfMap.SetMapLocation(center, 10); SetScenario(s); Finished?.Invoke(); SendProgressInfo("Ready"); Initialized(); } catch (Exception ex) { MessageBox.Show(ex.Message); } }
public static Scenario CreateScenario(ScenarioSize size, Point center) { double radius = 5 * (Convert.ToInt32(size) + 1); // radius in km const int TRUCK_MIN_CAPACITY = 20; const int TRUCK_MAX_CAPACITY = 30; const int ORDER_MIN_AMOUNT = 1; const int ORDER_MAX_AMOUNT = 4; int numDepots, numVehiclesPerDepot, numOrdersPerVehicle; TimeSpan operatingPeriod; switch (size) { default: numDepots = 1; numVehiclesPerDepot = 3; numOrdersPerVehicle = 3; operatingPeriod = TimeSpan.FromHours(2); break; case ScenarioSize.Small: numDepots = 2; numVehiclesPerDepot = 3; numOrdersPerVehicle = 6; operatingPeriod = TimeSpan.FromHours(3); break; case ScenarioSize.Medium: numDepots = 2; numVehiclesPerDepot = 4; numOrdersPerVehicle = 9; operatingPeriod = TimeSpan.FromHours(4); break; case ScenarioSize.Large: numDepots = 3; numVehiclesPerDepot = 5; numOrdersPerVehicle = 17; operatingPeriod = TimeSpan.FromHours(6); break; case ScenarioSize.Huge: numDepots = 5; numVehiclesPerDepot = 6; numOrdersPerVehicle = 21; operatingPeriod = TimeSpan.FromHours(8); break; } // calculate random coordinates around the center var coordinates = GetRandomCoordinates(center, radius, numOrdersPerVehicle * numVehiclesPerDepot * numDepots + numDepots); // and match them to the road by reverse-locating them var result = GetMatchedCoordinates(coordinates); var rand = new Random(); // build orders var enumerable = result.ToList(); var orders = (from p in enumerable.Take(numOrdersPerVehicle * numVehiclesPerDepot * numDepots) select new Order { Id = Guid.NewGuid().ToString(), Quantity = Convert.ToInt32(ORDER_MIN_AMOUNT + Math.Floor(rand.NextDouble() * (1 + ORDER_MAX_AMOUNT - ORDER_MIN_AMOUNT))), Longitude = p.Item1.X, Latitude = p.Item1.Y, Description = p.Item2 }).ToList(); // build depots var palette = new[] { (Color)ColorConverter.ConvertFromString("#66c2a5"), (Color)ColorConverter.ConvertFromString("#fc8d62"), (Color)ColorConverter.ConvertFromString("#8da0cb"), (Color)ColorConverter.ConvertFromString("#e78ac3"), (Color)ColorConverter.ConvertFromString("#a6d854") }; int ci = 0; Func <Color> GetColor = () => palette[ci++ % palette.Length]; var depots = (from p in enumerable.Skip(numOrdersPerVehicle * numVehiclesPerDepot * numDepots) select new Depot { Id = Guid.NewGuid().ToString(), Longitude = p.Item1.X, Latitude = p.Item1.Y, Description = p.Item2, Color = GetColor(), Fleet = (from a in Enumerable.Range(0, numVehiclesPerDepot) select new Vehicle { Id = Guid.NewGuid().ToString(), Capacity = Convert.ToInt32(TRUCK_MIN_CAPACITY + Math.Floor(rand.NextDouble() * (1 + TRUCK_MAX_CAPACITY - TRUCK_MIN_CAPACITY))) }).ToList() }).ToList(); // wire-up back-reference vehicle->depot foreach (var d in depots) { foreach (var v in d.Fleet) { v.Depot = d; } } return(new Scenario { OperatingPeriod = operatingPeriod, Orders = orders, Depots = depots }); }
public static Scenario CreateScenario(ScenarioSize size, Point center, double radius) { int TRUCK_MIN_CAPACITY = 20; int TRUCK_MAX_CAPACITY = 30; int ORDER_MIN_AMOUNT = 1; int ORDER_MAX_AMOUNT = 4; int numDepots, numVehiclesPerDepot, numOrdersPerVehicle; TimeSpan operatingPeriod; switch (size) { case ScenarioSize.Tiny: default: numDepots = 1; numVehiclesPerDepot = 3; numOrdersPerVehicle = 3; operatingPeriod = TimeSpan.FromHours(2); break; case ScenarioSize.Small: numDepots = 2; numVehiclesPerDepot = 3; numOrdersPerVehicle = 6; operatingPeriod = TimeSpan.FromHours(3); break; case ScenarioSize.Medium: numDepots = 2; numVehiclesPerDepot = 4; numOrdersPerVehicle = 9; operatingPeriod = TimeSpan.FromHours(4); break; case ScenarioSize.Large: numDepots = 3; numVehiclesPerDepot = 5; numOrdersPerVehicle = 17; operatingPeriod = TimeSpan.FromHours(6); break; } // calculate random coordinates around the center var coordinates = GetRandomCoordinates(center, radius, numOrdersPerVehicle * numVehiclesPerDepot * numDepots + numDepots); // and match them to the road by reverse-locating them var result = GetMatchedCoordinates(coordinates); var rand = new Random(); // build orders var orders = (from p in result.Take(numOrdersPerVehicle * numVehiclesPerDepot * numDepots) select new Order { Id = Guid.NewGuid().ToString(), Quantity = Convert.ToInt32(ORDER_MIN_AMOUNT + Math.Floor(rand.NextDouble() * (1 + ORDER_MAX_AMOUNT - ORDER_MIN_AMOUNT))), Longitude = p.X, Latitude = p.Y }).ToList(); // build depots var palette = new[] { Colors.Blue, Colors.Green, Colors.Salmon }; int ci = 0; Func <Color> GetColor = () => palette[(ci++) % palette.Length]; var depots = (from p in result.Skip(numOrdersPerVehicle * numVehiclesPerDepot * numDepots) select new Depot { Id = Guid.NewGuid().ToString(), Longitude = p.X, Latitude = p.Y, Color = GetColor(), Fleet = (from a in Enumerable.Range(0, numVehiclesPerDepot) select new Vehicle { Id = Guid.NewGuid().ToString(), Capacity = Convert.ToInt32(TRUCK_MIN_CAPACITY + Math.Floor(rand.NextDouble() * (1 + TRUCK_MAX_CAPACITY - TRUCK_MIN_CAPACITY))) }).ToList(), }).ToList(); // wire-up back-reference vehicle->depot foreach (var d in depots) { foreach (var v in d.Fleet) { v.Depot = d; } } return(new Scenario { OperatingPeriod = operatingPeriod, Orders = orders, Depots = depots, }); }
public static Scenario CreateRandomScenario(ScenarioSize size, System.Windows.Point center, double radius) { int TRUCK_MIN_CAPACITY = 4; int TRUCK_MAX_CAPACITY = 10; int ORDER_MIN_AMOUNT = 1; int ORDER_MAX_AMOUNT = 4; int numDepots, numVehiclesPerDepot, numOrdersPerVehicle, operatingPeriod; switch (size) { case ScenarioSize.Tiny: default: numDepots = 1; numVehiclesPerDepot = 3; numOrdersPerVehicle = 3; operatingPeriod = 2 * 60 * 60; break; case ScenarioSize.Small: numDepots = 2; numVehiclesPerDepot = 3; numOrdersPerVehicle = 6; operatingPeriod = 3 * 60 * 60; break; case ScenarioSize.Medium: numDepots = 2; numVehiclesPerDepot = 4; numOrdersPerVehicle = 9; operatingPeriod = 4 * 60 * 60; break; case ScenarioSize.Large: numDepots = 3; numVehiclesPerDepot = 5; numOrdersPerVehicle = 17; operatingPeriod = 6 * 60 * 60; break; } var rand = new Random(); Func<System.Windows.Point, double, System.Windows.Point> randomCoordinate = (c, r) => { var angle = rand.NextDouble() * 2 * Math.PI; var distance = r * Math.Sqrt(rand.NextDouble()); return new System.Windows.Point { X = c.X + distance * Math.Cos(angle), Y = c.Y + distance * Math.Sin(angle) }; }; List<Location> locations = new List<Location>(); for (int i = 0; i < numOrdersPerVehicle * numVehiclesPerDepot * numDepots + numDepots; i++) { var p = randomCoordinate(center, radius); locations.Add(new Location { coordinate = new Point { point = new PlainPoint { x = p.X, y = p.Y } } }); } var xlocate = new XLocateWSClient(); xlocate.ClientCredentials.UserName.UserName = "******"; xlocate.ClientCredentials.UserName.Password = App.Token; var result = xlocate.findLocations(locations.ToArray(), new[] { new ReverseSearchOption { param = ReverseSearchParameter.ENGINE_TARGETSIZE, value = "1" }, new ReverseSearchOption { param = ReverseSearchParameter.ENGINE_FILTERMODE, value = "1" }}, null, null, new CallerContext { wrappedProperties = new[] { new CallerContextProperty { key = "CoordFormat", value = "OG_GEODECIMAL" } } } ); var orders = (from p in result.Take(numOrdersPerVehicle * numVehiclesPerDepot * numDepots) select new Order { Id = Guid.NewGuid().ToString(), Quantity = System.Convert.ToInt32(ORDER_MIN_AMOUNT + Math.Floor(rand.NextDouble() * (1 + ORDER_MAX_AMOUNT - ORDER_MIN_AMOUNT))), Longitude = p.wrappedResultList[0].coordinates.point.x, Latitude = p.wrappedResultList[0].coordinates.point.y }).ToList(); var palette = new Color[] { Colors.Blue, Colors.Green, Colors.Brown }; int ci = 0; Func<Color> GetColor = () => palette[(ci++) % palette.Length]; var depots = (from p in result.Skip(numOrdersPerVehicle * numVehiclesPerDepot * numDepots) select new Depot { Id = Guid.NewGuid().ToString(), Longitude = p.wrappedResultList[0].coordinates.point.x, Latitude = p.wrappedResultList[0].coordinates.point.y, Color = GetColor(), Fleet = (from a in Enumerable.Range(0, numVehiclesPerDepot) select new Vehicle { Id = Guid.NewGuid().ToString(), Capacity = System.Convert.ToInt32(TRUCK_MIN_CAPACITY + Math.Floor(rand.NextDouble() * (1 + TRUCK_MAX_CAPACITY - TRUCK_MIN_CAPACITY))) }).ToList(), }).ToList(); // wire-up back-reference vehicle->depot foreach (var d in depots) foreach (var v in d.Fleet) v.Depot = d; return new Scenario { NumDepots = numDepots, NumOrdersPerVehicle = numOrdersPerVehicle, NumVehiclesPerDepot = numOrdersPerVehicle, OperatingPeriod = operatingPeriod, Orders = orders, Depots = depots, }; }