Modeling using a combination of logical and arithmetic operations
AnsweredI tried to combine logical and arithmetic operations as follows:
up = prob.addVars(M*P, R, name="Up", lb=0, ub=+1, vtype=GRB.CONTINUOUS)
vp = prob.addVars(N*P, R, name="Vp", lb=0, ub=+1, vtype=GRB.CONTINUOUS)
wp = prob.addVars(M*N, R, name="Wp", lb=0, ub=+1, vtype=GRB.CONTINUOUS)
u0 = prob.addVars(M*P, R, name="U0", lb=0, ub=+1, vtype=GRB.CONTINUOUS)
v0 = prob.addVars(N*P, R, name="V0", lb=0, ub=+1, vtype=GRB.CONTINUOUS)
w0 = prob.addVars(M*N, R, name="W0", lb=0, ub=+1, vtype=GRB.CONTINUOUS)
um = prob.addVars(M*P, R, name="Um", lb=0, ub=+1, vtype=GRB.CONTINUOUS)
vm = prob.addVars(N*P, R, name="Vm", lb=0, ub=+1, vtype=GRB.CONTINUOUS)
wm = prob.addVars(M*N, R, name="Wm", lb=0, ub=+1, vtype=GRB.CONTINUOUS)
expr = gp.LinExpr()
for i in range(M*P):
for j in range(N*P):
for k in range(M*N):
term = gp.LinExpr(T[i,j,k])
for r in range(R):
term.add(-gp.and_(um[i,r],vm[j,r],wm[k,r])
-gp.and_(um[i,r],vm[j,r],wm[k,r])
+gp.and_(um[i,r],vm[j,r],wp[k,r])
+gp.and_(um[i,r],vp[j,r],wm[k,r])
-gp.and_(um[i,r],vp[j,r],wp[k,r])
+gp.and_(up[i,r],vm[j,r],wm[k,r])
-gp.and_(up[i,r],vm[j,r],wp[k,r])
-gp.and_(up[i,r],vp[j,r],wm[k,r])
+gp.and_(up[i,r],vp[j,r],wp[k,r])
)
expr.add(term)
prob.setObjective( expr, GRB.MINIMIZE )
Here, T is a given tensor .
Is it possible to model the above formulation without introducing a lot of new variables?
Instead of using variables of type GRB.CONTINUOUS I also tried GRB.BINARY but without success.
Thank you for your help
0
-
Official comment
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 why not try our AI Gurobot?. -
Hi Marc,
Is it possible to model the above formulation without introducing a lot of new variables?
This is currently not possible. You have to introduce an additional variable for each \(\texttt{and}\) term and then add up the auxiliary variables, see addGenConstrAnd.
Best regards,
Jaromił0
Post is closed for comments.
Comments
2 comments