Advertisement
Guest User

Untitled

a guest
Mar 18th, 2019
48
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.52 KB | None | 0 0
  1. def move_item(item, reasonCode, WarehouseID):
  2. reason_dict = {1 : ["Warehouse" + " " + WarehouseID + ": " + "weight cap for" + " " + item.get_type() + " " + "reached", "Item ID:" + " " + str(item.get_number())],
  3. 2 : ["Warehouse" + " " + WarehouseID + ": " + "too many of type:" + " " + item.get_type() + " " + "in this warehouse" + " " + "Item ID: " + str(item.get_number())],
  4. 3 : ["Warehouse" + " " + WarehouseID + ": " + "Cannot add due to the insurance cap being exceeded" + " " + "Item ID:" + " " + str(item.get_number())]}
  5.  
  6. print()
  7. print(reason_dict.get(reasonCode)[0])
  8. wh_list = [WarehouseA, WarehouseB, WarehouseC, WarehouseD]
  9. wh_dict = {"A" : WarehouseA, "B" : WarehouseB, "C" : WarehouseC, "D" : WarehouseD}
  10.  
  11. if reasonCode == 1: #shape to heavy for warehouse
  12. temp_list = []
  13. for warehouse in wh_list:
  14. if warehouse != wh_dict.get(WarehouseID): # all warehouse BUT the one the item is coming from
  15. if warehouse.get_weight_capacity(item.get_type())[0] > wh_dict.get(WarehouseID).get_weight_capacity(item.get_type())[0]: #compares candidate wh to original wh
  16. warehouse.add_item_to_warehouse(item)
  17. if warehouse.add_item_to_warehouse(item):
  18. print(" Moved item to the next available warehouse", "Warehouse", warehouse.ID)
  19. break
  20.  
  21. if reasonCode == 2: #shape capacity full in this warehouse
  22. temp_list = []
  23. for warehouse in wh_list:
  24. if warehouse != wh_dict.get(WarehouseID): # all warehouse BUT the one the item is coming from
  25. if warehouse.get_shape_capacity(item.get_type())[0] - warehouse.get_shape_capacity(item.get_type())[1] > 0: # is there space for this shape in the warehouse?
  26. if item.get_weight() <= warehouse.get_weight_capacity(item.get_type())[0]: # can the warehouse max shape weight accomodate this shape?
  27. if warehouse.add_item_to_warehouse(item):
  28. print(" Moved item to the next available warehouse", "Warehouse", warehouse.ID)
  29. break
  30.  
  31. if reasonCode == 3: # insurance capacity exceeded
  32. temp_list = []
  33. for warehouse in wh_list:
  34. if warehouse != wh_dict.get(WarehouseID): # all warehouse BUT the one the item is coming from
  35. if item.get_value() >= warehouse.get_insurance(): #warehouse.get_insurance():
  36. print(" Item" + " " + "ID:" + " " + str(item.get_number()) + ": " + "Has been rejected due to it being higher insurance")
  37. break
  38. if (warehouse.get_insurance() - warehouse.get_insured_capacity()) >= item.get_value(): # is there space for this shape in the warehouse
  39. #print("1 bow")
  40. if warehouse.get_shape_capacity(item.get_type())[0] - warehouse.get_shape_capacity(item.get_type())[1] > 0:
  41. #print("2 bow")
  42. if item.get_weight() <= warehouse.get_weight_capacity(item.get_type())[0]:
  43. #print("3 bow")
  44. if warehouse.add_item_to_warehouse(item):
  45. print(" Moved item to the next available warehouse", "Warehouse", warehouse.ID)
  46. break
  47. else:
  48. print(" This item cannot be accomodated in any warehouse and therefore has been discarded")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement