Beispiel #1
0
        /// <summary>
        /// Starts sequence to execute Travelling Salesman Problem algorithm with A* and a set of conditions
        /// </summary>
        /// <returns></returns>
        public string runTSP(int areaSizeInput, int numberOfCustomers)
        {
            var areaSize = areaSizeInput * 1000 / BaseConstants.PolygonSize; //sets size in nodes

            Depot = new Location(areaSize / 2, areaSize / 2, 0);
            //await generateSpace(areaSize, 1);
            groundGrid = grid;

            generateOrders(areaSize, numberOfCustomers);

            var truck = Truck.generateTruck("singleTruck1", 0, areaSize, Depot);

            var result = string.Empty;

            try
            {
                if (!Settings.DeliveryInterval)
                {
                    Order.sortOrders(ref orders, Depot);
                    doTruck(Depot, orders, truck);
                }
                else
                {
                    var timeClusteredOrders = new List <List <Order> >();
                    var intervals           = new DeliveryIntervals();
                    foreach (var interval in intervals.Intervals)
                    {
                        var ordersInInterval = orders.Where(x => x.dueTime.Equals(interval.Key)).ToList();
                        timeClusteredOrders.Add(ordersInInterval);
                    }

                    for (int i = 0; i < timeClusteredOrders.Count(); i++)
                    {
                        if (truck.time < intervals.Intervals.ToArray()[i].Value.start)
                        {
                            truck.time = intervals.Intervals.ToArray()[i].Value.start;
                        }

                        var timedOrders = timeClusteredOrders.ElementAt(i);
                        Order.sortOrders(ref timedOrders, truck.currentPosition);
                        doTruck(truck.currentPosition, timedOrders, truck);
                    }
                }
            }
            catch (Exception ex)
            {
                return("Unhandled exception during path reconstruction\nPlease try again");
            }

            result = ComposeResult(truck);

            return(result);
        }
Beispiel #2
0
        public Order(int X, int Y, int Weight, int dueTime = 0)
        {
            x      = X;
            y      = Y;
            weight = Weight;
            if (dueTime != 0)
            {
                var intervals = new DeliveryIntervals();
                this.dueTime = intervals.Intervals.ToArray()[dueTime - 1].Key;
            }

            Random rnd      = new Random();
            var    streets  = Enum.GetNames(typeof(StreetNames));
            var    street   = streets[rnd.Next(streets.Length)];
            var    building = rnd.Next(150);

            address = street + " - " + building.ToString();
        }
Beispiel #3
0
        /// <summary>
        /// Performs delivery depending on wether deliveries are scheduled or not, based on settings value
        /// </summary>
        /// <param name="truck"></param>
        private void performDelivery(Truck truck)
        {
            if (Settings.TrafficScore != 0)
            {
                Truck.adjustTruckSpeed();
            }


            if (!Settings.DeliveryInterval)
            {
                Order.sortOrders(ref orders, Depot);

                var ordersString = string.Empty;
                foreach (var o in orders)
                {
                    ordersString += $"{o.address}\t--\t{o.x}.{o.y}\n";
                }

                FSTSPRouting.buildUnitRoute(grid, orders, truck);
            }
            else
            {
                var timeClusteredOrders = new List <List <Order> >();
                var intervals           = new DeliveryIntervals();
                foreach (var interval in intervals.Intervals)
                {
                    var ordersInInterval = orders.Where(x => x.dueTime.Equals(interval.Key)).ToList();
                    timeClusteredOrders.Add(ordersInInterval);
                }

                for (int i = 0; i < timeClusteredOrders.Count(); i++)
                {
                    if (truck.time < intervals.Intervals.ToArray()[i].Value.start)
                    {
                        truck.status = Status.Idle;
                        truck.log.Add(new Log(truck.id,
                                              truck.currentPosition,
                                              orders.Where(x => (x.x == truck.currentPosition.x && x.y == truck.currentPosition.y)).First().address,
                                              truck.time,
                                              truck.status,
                                              "success"));
                        truck.time   = intervals.Intervals.ToArray()[i].Value.start;
                        truck.status = Status.Ready;

                        foreach (var drone in truck.drones)
                        {
                            drone.status = Status.Idle;
                            drone.log.Add(new Log(drone.id,
                                                  drone.currentPosition,
                                                  orders.Where(x => (x.x == truck.currentPosition.x && x.y == truck.currentPosition.y)).First().address,
                                                  drone.time,
                                                  drone.status,
                                                  "success"));
                            drone.time   = intervals.Intervals.ToArray()[i].Value.start;
                            drone.status = Status.Available;
                        }
                    }

                    var timedOrders = timeClusteredOrders.ElementAt(i);
                    Order.sortOrders(ref timedOrders, truck.currentPosition);
                    FSTSPRouting.buildUnitRoute(grid, timedOrders, truck);
                }
            }
        }