Over the next 12 months you anticipate the following demand for a product that y
ID: 3605569 • Letter: O
Question
Over the next 12 months you anticipate the following demand for a product that you sell:
At the beginning of month 1, you have 3 units in inventory. At the beginning of each month, you may order as many units of inventory as you like, and they are delivered essentially immediately. In each month that you order more than zero units, there is a $1.50 setup cost. If you order between 1 and 4 units cost per unit is $10.00 per unit, but if you order 5 or more units, the cost is $9.00 per unit. For example, the cost is $0.00 if you order zero units, $1.50 + 2 × $10.00 = $21.50 if you order two units, and $1.50 + 5 × $9.00 = $46.50 if you order five units. There is You have space for up to 20 units of inventory and your holding cost for each month is $0.50 per unit, applied to the average of the starting and ending inventory for the month. There is no limit to the amount that you can order, except that you cannot exceed 20 units of inventory at the end of each month. There is no benefit or credit for having leftover inventory at the end of month 12.
Create a Python program that computes the lowest-cost ordering plan, considering both ordering costs and inventory costs.
This is the code I have so far, but I need help understanding what's wrong with it:
Month 1 2 3 4 5 6 7 8 9 10 11 12 Demand (units) 4 6 5 6 8 3 4 2 8 5 4 3Explanation / Answer
Please remove the last for loop as displaying the remaining inventary at the end is not necessary.
import numpy
hugeNumber = float("inf")
stages = 12
startInventory = 3
inventoryCapacity = 20
setupCost = 1.5
holdingCost = 0.5
demand = numpy.array([-1000, 4, 6, 5, 6, 8, 3, 4, 2, 8, 5, 4, 3])
f = numpy.zeros([stages + 2, inventoryCapacity + 1])
x = numpy.zeros([stages + 1, inventoryCapacity + 1], dtype=int)
for t in range(stages, 0, -1):
for i in range(inventoryCapacity + 1):
minOrder = 0
maxOrder = inventoryCapacity - i + demand[t]
value = hugeNumber
for d in range(minOrder, maxOrder):
j = i + d - demand[t]
orderCost = 0
if d == 0:
orderCost = orderCost
if d < 5:
orderCost = setupCost + d * 10
elif d >= 5:
orderCost = setupCost + d * 9
moveValue = holdingCost * j + orderCost + f[t + 1, j]
if moveValue < value:
value = moveValue
bestMove = d
# End of p loop
f[t, i] = value
x[t, i] = bestMove
# End of i loop
# End of t loop
print("Optimal cost is " + str(f[1, startInventory]))
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.