简体   繁体   中英

PuLP how to set next variable according to previous results?

I have a constraint in my linear program for inventory that goes:

x[next period] = x[this period] + purchases[this period] - sold[this period]

Decision variables are purchases[this period] and sold[this period]. Solved for several periods with rolling horizon period.

When I put it in PuLP like this, all the x[t] other than the first (constant input, ex. 12345) end up to be 0.

T = range(0,7)
x = [0 for t in T]
x[0] = 12345

for t in T:
    prob += x[t] + p[t] - s[t] == x[t+1], "some label %s"(t)
    prob += x[t+1] >= 0

Solved it! For anyone who's interested in this...

I added it as a variable and added the following constraint prob += x[0] == 12345

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM