Ejemplo n.º 1
0
        public static List <Location> simpleRoute(SquareGrid grid, Location start, Location finish)
        {
            List <Location> path  = new List <Location>();
            AStarSearch     astar = new AStarSearch(grid, start, finish);

            path = astar.ReconstructPath(start, finish, astar.cameFrom);

            return(path);
        }
Ejemplo n.º 2
0
        private string doDrone(List <Order> droneOrders)
        {
            List <List <Location> > dronePaths = new List <List <Location> >();

            foreach (var order in droneOrders)
            {
                List <Location> path  = new List <Location>();
                AStarSearch     astar = new AStarSearch(grid, Depot, new Location(order.x, order.y, 0));
                path = astar.ReconstructPath(Depot, new Location(order.x, order.y, 0), astar.cameFrom);
                var returnPath = path;
                returnPath.Reverse();
                path.AddRange(returnPath);
                dronePaths.Add(path);
            }

            return(Drone.droneStatusUpdate(dronePaths, DroneTime));
        }
Ejemplo n.º 3
0
        public static string[] DrawGrid(SquareGrid grid, AStarSearch astar, Location start, Location goal)
        {
            string[] output = new string[4];
            // Печать массива cameFrom
            for (int z = 0; z < 4; z++)
            {
                for (var y = 0; y < 41; y++)
                {
                    for (var x = 0; x < 41; x++)
                    {
                        Location id  = new Location(x, y, z);
                        Location ptr = id;
                        if (!astar.cameFrom.TryGetValue(id, out ptr))
                        {
                            ptr = id;
                        }
                        if (start.x == x && start.y == y && start.z == z) /*Console.Write("\u2191 ");*/ x {
                            ++; output[z] += "S";
                        }
                        if (goal.x == x && goal.y == y && goal.z == z) /*Console.Write("\u2191 ");*/ x {
                            ++; output[z] += "F";
                        }

                        if (grid.walls.Contains(id)) /*Console.Write("##");*/ output {
Ejemplo n.º 4
0
        private string doTruck(Location depot, List <Order> truckOrders, Truck truck)
        {
            if (truckOrders is null)
            {
                return(string.Empty);
            }
            if (Settings.TrafficScore != 0)
            {
                Truck.adjustTruckSpeed();
            }

            List <List <Location> > truckPaths = new List <List <Location> >();
            List <Location>         path;

            AStarSearch astar = new AStarSearch(groundGrid, depot, new Location(truckOrders.First().x, truckOrders.First().y, 0));

            path = astar.ReconstructPath(depot, new Location(truckOrders.First().x, truckOrders.First().y, 0), astar.cameFrom);
            truckPaths.Add(path);

            truck.currentPosition = new Location(truckOrders.First().x, truckOrders.First().y, 0);
            var pathLength   = path.Count * BaseConstants.PolygonSize;
            var deliveryTime = pathLength / BaseConstants.TruckSpeed + BaseConstants.DropDeliveryTime;

            truck.time  += deliveryTime;
            truck.status = Status.OnMission;

            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,
                                  "Delivery finished"));

            for (int i = 0; i < truckOrders.Count - 1; i++)
            {
                if (Settings.TrafficScore != 0)
                {
                    Truck.adjustTruckSpeed(truck.time);
                }

                var start            = new Location(truckOrders[i].x, truckOrders[i].y, 0);
                var deliveryLocation = new Location(truckOrders[i + 1].x, truckOrders[i + 1].y, 0);

                astar = new AStarSearch(groundGrid, start, deliveryLocation);
                path  = astar.ReconstructPath(start, deliveryLocation, astar.cameFrom);
                truckPaths.Add(path);

                pathLength   = path.Count * BaseConstants.PolygonSize;
                deliveryTime = pathLength / BaseConstants.TruckSpeed + BaseConstants.DropDeliveryTime;

                truck.currentPosition = deliveryLocation;
                truck.time           += deliveryTime;
                truck.status          = Status.OnMission;

                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,
                                      "Delivery finished"));
            }

            //astar = new AStarSearch(groundGrid, new Location(truckOrders.Last().x, truckOrders.Last().y, 0), Depot);
            //path = astar.ReconstructPath(new Location(truckOrders.Last().x, truckOrders.Last().y, 0), Depot, astar.cameFrom);
            //truckPaths.Add(path);

            return(Truck.truckStatusUpdate(truckPaths, TruckTime));
        }