예제 #1
0
 public void Wait(Drone drone, int turns)
 {
     Commands.Add(string.Format("{0} W {1}", drone.id, turns));
 }
예제 #2
0
 public void Unload(Drone drone, Warehouse warehouse, int productID, int count)
 {
     Commands.Add(string.Format("{0} U {1} {2} {3}", drone.id, warehouse.id, productID, count));
 }
예제 #3
0
 public void Deliver(Drone drone, Order order, int productID, int count)
 {
     Commands.Add(string.Format("{0} D {1} {2} {3}", drone.id, order.ID, productID, count));
 }
예제 #4
0
        public static void Run(string input)
        {
            if (isRunning)
            {
                return;
            }

            isRunning = true;

            // Clear previous data
            Clear();

            // Load data
            Loader.Load(input);

            // Pre simulation works do be done:
            Orders.Sort();
            divideDrones();

            // Simulation
            Deadline = 10;
            List <Warehouse> www = new List <Warehouse>(Warehouses.Count);

            for (int i = 0; i < Deadline; i++)
            {
                int dronesInUse = 0;
                while (dronesInUse < drones.Count - 1)
                {
                    Order o = Orders[0];
                    Orders.RemoveAt(0);

                    www.AddRange(Warehouses);
                    while (o.Set.Count > 0)
                    {
                        Warehouse closeW = findCLosestWarehouse(www, o.GetDestination(), o.Set);

                        Drone d = drones[dronesInUse++];

                        int productID;
                        int count;
                        for (int a = 0; a < ProductsCount; a++)
                        {
                            if (closeW.Set.Items[a] > 0 && o.Set.Items[a] > 0)
                            {
                                productID = a;
                                count     = Math.Min(closeW.Set.Items[a], o.Set.Items[a]);



                                closeW.Set.Remove(productID, count);
                                o.Set.Remove(productID, count);

                                Commands.Load(d, closeW, productID, count);
                                Commands.Deliver(d, o, productID, count);
                            }
                        }

                        if (dronesInUse == drones.Count)
                        {
                            break;
                        }
                    }

JumpItem:

                    www.Clear();
                }

                if (Orders.Count == 0)
                {
                    break;
                }
            }

            // Write commands
            Commands.Write(input + ".out");

            isRunning = false;

            MessageBox.Show("Done.");
        }