sum of two variables integer
回答済みI have the variables x and y.
x = pd.Series(m4.addVars(stocks), index=stocks)
y = pd.Series(m4.addVars(stocks), index=stocks)
x and y can be non-integer each, but x + y should be integer. I have no idea how i could do this. Could anyone help me (in python)? Thanks in advance.
-
正式なコメント
This post is more than three years old. Some information may not be up to date. For current information, please check the Gurobi Documentation or Knowledge Base. If you need more help, please create a new post in the community forum, or try Gurobot, our chatbot interface offering instant, expert-level support. -
You can define an additional integer variable \(z \in \mathbb{Z}\) and define an equality constraint \(x + y = z\).
You will have to do define one additional integer variable and equality constraint for every sum \(x+y\).0 -
Hello Jaromil
Thank you for your answer. I tried this, but it wouldn't work. Do you know, what's incorrect with this?
x3 = pd.Series(m4.addVars(stocks), index=stocks)
y3 = pd.Series(m4.addVars(stocks), index=stocks)
z3 = pd.Series(m4.addVars(stocks, vtype=gb.GRB.INTEGER), index=stocks)m4.addConstr(x3 + y3 = z3)
0 -
You defined your variables x3,y3,z3 as pandas Series objects. In order to construct constraints in Gurobi, you have to use the the underlying variable objects. Something like the following should work
x = m4.addVars(stocks)
y = m4.addVars(stocks)
z = m4.addVars(stocks, vtype=gb.GRB.INTEGER)
x3 = pd.Series(x, index=stocks)
y3 = pd.Series(y, index=stocks)
z3 = pd.Series(z, index=stocks)
for s in stocks:
# I assume here that stocks are integer values
m.addConstr(x[s] + y[s] == z[s], name="aux_eq_%d"%(s))Best regards,
Jaromił0
投稿コメントは受け付けていません。
コメント
4件のコメント