简体   繁体   English

PuLP如何根据先前的结果设置下一个变量?

[英]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. 当我像这样将其放在PuLP中时,除第一个(常量输入,例如12345)以外的所有x [t]最终都为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 我将其添加为变量,并添加以下约束概率+ = x [0] == 12345

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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