Exemple #1
0
 public void LoadItemCategoriesFile(string item_categories_file)
 {
     using (var reader = new StreamReader(item_categories_file))
     {
         reader.ReadLine();
         while (!reader.EndOfStream)
         {
             var        line    = reader.ReadLine();
             MaxStorage storage = new MaxStorage(line);
             if (storage._productType != null)
             {
                 _DicMaxStorage.Add(storage._productType, storage);
             }
         }
     }
 }
Exemple #2
0
 public virtual void SetMaxStorage(MaxStorage max_storage)
 {
 }
Exemple #3
0
 public override void SetMaxStorage(MaxStorage max_storage)
 {
     _max_item = max_storage._maxHangerStorage;
 }
Exemple #4
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);
        }
Exemple #5
0
        private List <Rack> FindRackToStore(Product product_info, int quantity, MaxStorage max_storage_info)
        {
            List <Rack> result = new List <Rack>();

            if (product_info._storageType.Equals("fold"))
            {
                int max_storage = max_storage_info._maxFoldStorage;
                while (quantity >= 10)
                {
                    if (_generalEmptyRacksList.Count > 0)
                    {
                        result.Add(_generalEmptyRacksList[0]);
                        _generalEmptyRacksList.RemoveAt(0);
                        quantity -= max_storage;
                    }
                    else
                    {
                        break;
                    }
                }

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

                    if (quantity <= 0) //Get enough rack to store product.
                    {
                        break;
                    }

                    // Find rack with the same product type and the same shipper.
                    if (rack.IsFull() == false &&
                        rack._productType.Equals(product_info._productType) &&
                        (rack._shipperID == product_info._shipperID))
                    {
                        result.Add(rack);
                        quantity -= (rack._max_item - rack._num_items);
                    }
                }

                if (quantity > 0) //If still not enough empty spot, get one from the empty racks
                {
                    if (_generalEmptyRacksList.Count > 0)
                    {
                        result.Add(_generalEmptyRacksList[0]);
                        _generalEmptyRacksList.RemoveAt(0);
                        quantity -= max_storage;
                    }
                    else
                    {
                        Program.Print("Can't find rack to store item");
                    }
                }
            }
            else
            {
                int max_storage = max_storage_info._maxHangerStorage;
                while (quantity >= 30)
                {
                    if (_hangerEmptyRackList.Count > 0)
                    {
                        result.Add(_hangerEmptyRackList[0]);
                        _hangerEmptyRackList.RemoveAt(0);
                        quantity -= max_storage;
                    }
                    else
                    {
                        break;
                    }
                }

                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];

                    if (quantity <= 0) //Get enough rack to store product.
                    {
                        break;
                    }

                    // Find rack with the same shipper.
                    if (rack.IsFull() == false &&
                        (rack._shipperID == product_info._shipperID))
                    {
                        result.Add(rack);
                        quantity -= (rack._max_item - rack._num_items);
                    }
                }

                if (quantity > 0) //If still not enough rack, get one from the empty racks
                {
                    if (_hangerEmptyRackList.Count > 0)
                    {
                        result.Add(_hangerEmptyRackList[0]);
                        _hangerEmptyRackList.RemoveAt(0);
                        quantity -= max_storage;
                    }
                    else
                    {
                        Program.Print("Can't find rack to store item");
                    }
                }
            }

            return(result);
        }
Exemple #6
0
        public void Store(List <string> input)
        {
            int count = 0;

            Program.WriteOutput("store");

            for (int i = 1; i < input.Count; i += 2)
            {
                string product_id     = input[i];
                int    input_quantity = int.Parse(input[i + 1]);
                count++;
                Product product = _DicItems[product_id];
                if (product == null)
                {
                    Program.Print("Can not find product info");
                    continue;
                }

                MaxStorage max_storage_info = _DicMaxStorage[product._productType];
                if (max_storage_info == null)
                {
                    Program.Print("Can not find max storage");
                    continue;
                }

                List <Rack> suitable_racks = FindRackToStore(product, input_quantity, max_storage_info);

                foreach (Rack rack in suitable_racks)
                {
                    if (rack.isEmpty())
                    {
                        rack._shipperID = product._shipperID;
                        rack.SetMaxStorage(max_storage_info);
                        if (rack._storageType.Equals("fold"))
                        {
                            _generalRackList.Add(rack);
                            rack._productType = product._productType;
                        }
                        else
                        {
                            _hangerRackList.Add(rack);
                        }
                    }

                    int stored_quantity = 0;
                    if ((rack._num_items + input_quantity) <= rack._max_item)
                    {
                        stored_quantity = input_quantity;
                    }
                    else
                    {
                        stored_quantity = rack._max_item - rack._num_items;
                    }

                    rack._itemList.Add(new RackItem(product_id, stored_quantity));
                    rack._num_items += stored_quantity;
                    input_quantity  -= stored_quantity;

                    string store_product_command = String.Concat(Enumerable.Repeat(" " + product_id + " " + rack.GetXXYYDH(), stored_quantity));
                    Program.WriteOutput(store_product_command);
                }
            }

            Program.WriteOutput("\n");
            Program.Print("stock total: " + count.ToString());
        }