Пример #1
0
        public void FinishReceiving()
        {
            string item = _expectedReceiveItems.Dequeue();

            _loadedItems.Enqueue(item);
            _isLoading = false;
            if (_expectedReceiveItems.Count == 0)
            {
                Rack rack = Warehouse.FindRackToSlot(_loadedItems.Peek(), _loadedItems.Count);
                if (rack == null)
                {
                    Program.Print("Racks are full");
                    return;
                }

                PrepareToSlot(rack.GetPickUpPoint(), rack, _loadedItems.Count);

                Robot picker = Warehouse.FindPickerToPick(rack);
                if (picker == null)
                {
                    Program.Print("can not find picker"); // bug here. or we increase number of picker?
                    return;
                }
                picker.PrepareToSlot(rack.GetPickUpPoint(), rack, _loadedItems.Count);
            }
        }
Пример #2
0
        public static bool AvoidTrafficJam(Rack rack)
        {
            Point pick_point = rack.GetPickUpPoint();

            foreach (Robot robot in _AllMovingRobots.Values)
            {
                if (robot._state != robot_state.free)
                {
                    if (rack._direction == Direction.Left ||
                        rack._direction == Direction.Right ||
                        rack._direction == Direction.Fix)
                    {
                        if (pick_point.X == robot._destination_point.X || pick_point.X == robot._location.X)
                        {
                            return(false);
                        }
                    }
                    else
                    {
                        if (pick_point.Y == robot._destination_point.Y || pick_point.Y == robot._location.Y)
                        {
                            return(false);
                        }
                    }
                }
            }

            //Program.Print("\n" + rack.GetPickUpPoint() + " avoid ");
            //foreach (Robot robot in _AllMovingRobots.Values)
            //    if (robot._state != robot_state.free)
            //        Program.Print(" " + robot._location + robot._destination_point);
            return(true);
        }
Пример #3
0
        public static Rack FindRackToSlot(String product_id, int quantity)
        {
            Product    product_info     = _DicItems[product_id];
            MaxStorage max_storage_info = _DicMaxStorage[product_info._productType];

            Rack result = null;

            if (product_info._storageType.Equals("fold"))
            {
                int start = rnd.Next(_generalRackList.Count);
                // Find empty spot in the racks which contain product
                for (int i = 0; i < _generalRackList.Count; i++)
                {
                    int  pos  = (i + start) % _generalRackList.Count;
                    Rack rack = _generalRackList[pos];

                    // Find rack with the same product type and the same shipper.
                    if (rack._productType.Equals(product_info._productType) &&
                        (rack._shipperID == product_info._shipperID) &&
                        rack.IsEnoughSpaceToSlot(quantity) && AvoidTrafficJam(rack))
                    {
                        result = rack;
                        break;
                    }
                }

                // If can't find empty spot from rack with product, get a new empty rack
                if (result == null && _generalEmptyRacksList.Count > 0)
                {
                    foreach (Rack emptyrack in _generalEmptyRacksList)
                    {
                        if (AvoidTrafficJam(emptyrack))
                        {
                            result = emptyrack;
                            _generalEmptyRacksList.Remove(result);
                            break;
                        }
                    }
                }
            }
            else
            {
                int start = rnd.Next(_hangerRackList.Count);
                // Find empty spot in the racks which contain product
                for (int i = 0; i < _hangerRackList.Count; i++)
                {
                    int  pos  = (i + start) % _hangerRackList.Count;
                    Rack rack = _hangerRackList[pos];

                    // Find rack with the same shipper.
                    if (rack._shipperID == product_info._shipperID &&
                        rack.IsEnoughSpaceToSlot(quantity) && AvoidTrafficJam(rack))
                    {
                        result = rack;
                    }
                }

                if (result == null && _hangerEmptyRackList.Count > 0)
                {
                    foreach (Rack emptyrack in _hangerEmptyRackList)
                    {
                        if (AvoidTrafficJam(emptyrack))
                        {
                            result = emptyrack;
                            _hangerEmptyRackList.Remove(result);
                            break;
                        }
                    }
                }
            }

            if (result != null)
            {
                result._expectedSlotQuantity += quantity;

                if (result.isEmpty())
                {
                    result._shipperID = product_info._shipperID;
                    result.SetMaxStorage(max_storage_info);
                    if (result._storageType.Equals("fold"))
                    {
                        _generalRackList.Add(result);
                        result._productType = product_info._productType;
                    }
                    else
                    {
                        _hangerRackList.Add(result);
                    }
                }
            }

            Program.Print("\nFind rack to slot: " + result._storageType + " " + result.GetPickUpPoint() + " " + result._num_items + "\n");
            return(result);
        }
Пример #4
0
        public void Pick(List <string> input)
        {
            for (int i = 1; i < input.Count; i += 2) // Add new order into the list
            {
                Order new_order      = new Order(input[i], int.Parse(input[i + 1]));
                Order existing_order = _PickOrders.FirstOrDefault(x => x._productID.Equals(new_order._productID));
                if (existing_order != null)
                {
                    existing_order._quantity += new_order._quantity;
                }
                else
                {
                    _PickOrders.Add(new_order);
                }
            }

            if (_time == 0 && _day != 0) // resume the activity of previous day
            {
                foreach (Robot robot in _AllMovingRobots.Values)
                {
                    robot.ResumeActivityLastDay();
                }
            }

            if (_time < 714)
            {
                while (_PickOrders.Count > 0)
                {
                    Order order         = FindOrderToHandle();
                    int   NumItemInRack = 0;

                    // Find rack contains order product
                    Rack rack = FindRackToPick(order, out NumItemInRack);
                    if (rack == null)
                    {
                        Program.PrintLine("Can not find rack contain the product");
                        _PickOrders.Remove(order);
                        continue;
                    }

                    // Get the pickup point of rack
                    Point pickup_point = rack.GetPickUpPoint();

                    // Find picking robot which is free and near rack
                    Robot picker = FindPickerToPick(rack);
                    if (picker == null) // All pickers are busy
                    {
                        //Program.Print("All pickers are busy");
                        return;
                    }

                    TransportRobot transporter = FindTransporterToPick(rack._location);
                    if (transporter == null) // All transporters are busy
                    {
                        //Program.Print("All transporters are busy");
                        return;
                    }

                    rack._expectedPickQuantity = (order._quantity > NumItemInRack) ? NumItemInRack : order._quantity;
                    order._quantity           -= rack._expectedPickQuantity;
                    if (order._quantity <= 0) // Get enought quantity, remove order from the list of orders
                    {
                        _PickOrders.Remove(order);
                    }

                    picker.PrepareToPick(pickup_point, rack, order._productID, rack._expectedPickQuantity);
                    transporter.PrepareToPick(pickup_point, rack, order._productID, rack._expectedPickQuantity);
                    Program.Print("Handle pick " + order._productID + " " + rack._expectedPickQuantity);
                }
            }
            //else
            //{
            //    foreach (Robot robot in _AllMovingRobots.Values)
            //    {
            //        robot.ForceReturnChargingPoint();
            //    }
            //}
        }