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); }
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(); // } //} }
public Order(string product, int quantity, Rack rack) { _productID = product; _quantity = quantity; _rack = rack; }
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); }
public Order(string product, int quantity) { _productID = product; _quantity = quantity; _rack = null; }
public Order() { _productID = ""; _quantity = 0; _rack = null; }