-1
$\begingroup$

I am trying to solve the following problem.

How to build a deterministic optimization model for the following fc

we have $x_1,x_2,...,x_365$ are the order shipped from an FC to a customer for 365 days We have $o_1,..,o_365$ the amount that we ship from the DC to the FC. We have the parameter $d1,d2,d3,...,d365$ is the the demand for the day.

We have $l_1,l_2,l_3,l_4,l_5,...,l_365$ is the lost sales for the day.

We also have $I_1,I_2,I_3,...,I_(365)$ is the inventory stored in the FC.

I have the following definition for my lost sales

$l_i=d_i-x_i$

and we have inventory is

$I_1=50-x_1$ starting iventory is 50

$I_2=i_1-x_2$

$i_3=i_2-x3$

$i_4=i_3-x_4+o_1$ [take 3 day for an order to reach ]

$i_365=i_{364}-x_{365}+o_{362}$

Problem is I am not sure how to code this in python pulp.

I have the following objective function I want to minimize $50(x_1+..+x365)+2(o_1+...+o_365$)+3(ls_1+...+l_365)+1(o_1+..+o_365$)

I got final which is a csv file which shows how much I ordered for the 365 days of the year. It is where I get my demand

But my model return all the zeroes and this cannot be right because my lost sales constraint is not satisfied.

days    orders
1       0
2      4
3     1
4    4
5    0
6   1
7   2
8   0
9        5
10       2
11      5

mport pandas as pd 
from pulp import LpMaximize, LpProblem, LpStatus, lpSum, LpVariable,LpMinimize,LpInteger
from pulp import LpBinary
from pulp import LpSolverDefault
import pulp 





k3=pd.read_csv("final.csv")
w2=k3["orders"]
demandStore=w2.tolist()


#DAY shipped 
#WE HAVE ONE DAY MAY HAVE MULTIPLE ORDERS
xArray=[]

    
model = LpProblem(name="small", sense=LpMinimize)


xs = [LpVariable("xs{}_var".format(i+1),lowBound=0,upBound=50, cat="Integer") for i in range(0,365)]  

#ORDERS
os=  [LpVariable("os{}_var".format(i+1),lowBound=0,upBound=50, cat="Integer") for i in range(0,365)] 

#lost sale
ls=  [LpVariable("ls{}_var".format(i+1),lowBound=0,upBound=50, cat="Integer") for i in range(0,365)] 


#inventory
iv=[LpVariable("iv{}_var".format(i+1),lowBound=0,upBound=50, cat="Integer") for i in range(0,365)]

k=[]
#we have here the lost sales 


for i in range(0,365):
#lost sales constraint is demand-orders
   w=ls[i]==demandStore[i]-xs[i]
   k.append(w)
for i in range(0,365):
    model+=k[i]
   
    
cons1=iv[0]==50-xs[0]
cons2=iv[1]==iv[0]-xs[1]+os[0]
cons3=iv[2]==iv[1]-xs[2]+os[1]
model+=cons1
model+=cons2
model+=cons3
k2=[]
for i in range(0,365):
    cool2=xs[i]<=iv[i]
    k2.append(cool2)
for i in range(0,365):
    model+=k2[i]
k3=[]
for i in range(3,365):
    cool=iv[i]==iv[i-1]-xs[i]+os[i-1]
    k3.append(cool)
for i in range(0,362):
    model+=k3[i]
    




One=pulp.lpSum([50*xs[i]+2*os[i]+60*ls[i]+1*iv[i] for i in range(0,365)])
#Two=pulp.lpSum([os[i]*2 for i in range(0,365)])
#Three=pulp.lpSum([iv[i]*1 for i in range(0,365)])
#four=pulp.lpSum([ls[i]*30 for i in range(0,365)])
model+=One
#model+=Two
#model+=Three
#model+=four
model.solve()
#model.solve()
name=[]
value=[]
for var in model.variables():
    print(var.name, " ",var.value())
    name.append(var.name)
    value.append(var.value())


$\endgroup$
3
  • 1
    $\begingroup$ I am no expert in pulp but I think section under lost sales you are making assignment whereas in solver programming involving a decision variable, in most cases, assignments are like equality constraints. In other words you may need to turn these into constraints. Check pulp solver documentation. $\endgroup$ Commented Nov 21, 2022 at 1:02
  • $\begingroup$ I got a new issue I modded my code but now all my decision variable return as zero $\endgroup$ Commented Nov 21, 2022 at 19:30
  • 1
    $\begingroup$ I am not seeing you are linking xs, os and iv with ls- variable that is linked to demandstore or demandstore being used anywhere in the constraints. Without that solver will happily make all vars except lost_sales as 0 and make lost sales= demandstore. $\endgroup$ Commented Nov 21, 2022 at 23:30

1 Answer 1

2
$\begingroup$

I see same name used for vars ls, os and iv. Try to change that. Also a single line to define xArray is

xArray = [*range(365)]
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.