Storage optimization problem: how to add new constraints to update LP variable limits based on new inputs

252 views
Skip to first unread message

Alex Tian

unread,
Apr 21, 2015, 7:01:46 AM4/21/15
to pulp-or...@googlegroups.com

Hello all,

I’m trying to solve an storage optimization problem using PULP in Python, where given daily prices I want to maximize the profit, say for the next year (365 days). I have defined a list of 365 variables “net_withdrawals” (positive number for withdrawals and negative if injections), and set an initial lower and upper limits in the declaration.

However, and I also have constraints defined that, the storage stock/inventory level at any time must be between 0 and maximum capacity, and so far so good. I’m having issue with adding another constraints to “futher“ limit the “net_withdrawals” variables for each day between a narrower range, based on the current stock level: e.g, withdrawal rate is halved and injection rate is doubled if the stock goes below 50% of the total capacity, and vice versa.

I can work out the current stock level, however as it is an Affine Expressions, I cannot seem to use if-else conditional statement to check his value and define the new limits for “net_withdrawals” variables. E.g.: total capacity is 1000, and I tried:

Optimization_model = pulp.LpProblem(Model - LP', pulp.LpMaximize)

periods = range(0, NUMBER_OF_DAYS)

net_withdrawals = [pulp.LpVariable("net_withdrawals_%s" % i, lowBound=-50, upBound=50) for i in periods]

For day in periods:

Stock_level -= net_withdrawals[i]

 

If stock_level < 500:

Optimization_model += net_withdrawals[i] < -25

Optimization_model += net_withdrawals[i] > 50

                        Else:

Optimization_model += net_withdrawals[i] < -50

Optimization_model += net_withdrawals[i] > 25

I’d like to add different constraints for boundary limits based on different stock levels, e.g. 25%, 50%, 75% etc…
But I could not seem to get this basic logic working.

Would anyone be able to suggest/advice?
I really appreciate it and thanks in advance.

Thanks.
Alex

Harshit Mahajan

unread,
Jun 1, 2020, 12:46:37 AM6/1/20
to pulp-or-discuss
Hi Alex, 

I came across the same problem. Just wanted to check with you if you had made some progress or could direct me to some other resources. 
Thanks in advance for your help. 

Best Regards
Harshit
Reply all
Reply to author
Forward
0 new messages