Hello guys
I am trying to make a new way to solve a problem in supply chain, but I need to define a external function to calculate the price of the product. I am solving this directly in python.
My issue is that, I define a variable called price in the following way:
price = { }
for o in customerorder:
for p in product:
price[o, p] = m.addVar(prototype(duedate[o], harvestingtime[o, p], maximumshelflife[p]), name="price_{}_{}".format(o, p))
Where the definition of the function prototype(this is my own function) is the following:
def prototype(duedate, harvestingtime, maximumshelflife):
t = duedate
h = harvtime
m = maximumshelflife
su = (a value defined by the user)
s2 = (a value defined by the user)
s1 = (a value defined by the user)
sl = (a value defined by the user)
t1 = h + m*0.4
t2 = h + m*0.5
t3 = h + m*0.7
t4 = h + m*0.8
t5 = h + m*0.9
prot = 0
try:
if t < h:
prot = su
elif t >= h and t < t1:
prot = su
elif t >= t1 and t < t2:
prot = (su*(t2-t)+s2*(t-t1))/(t2-t1)
elif t >= t2 and t < t3:
prot = s2
elif t >= t3 and t < t4:
prot = (s2*(t4-t)+s1*(t-t3))/(t4-t3)
elif t >= t4 and t < t5:
prot = s1
elif t >= t5 and t < m:
prot = (s1*(m-t)+sl*(t-t5))/(m-t5)
elif t>=m:
prot = 0
except Exception:
prot = 0
return prot
Then my problem is that, this variable is always returning empty, error, or zero. It does not calculate anything.
Does anyone know how to handle an issue like this?
Thanks a lot in advance!