Bitwise operator Python vs Julia
AnsweredI have a working model in python.
mdl = Model('myModel')
mdl.setParam('MIPGap', 0.000001)
mdl.setParam('TimeLimit', 10)
x = mdl.addVars(A, vtype=GRB.BINARY)
u = mdl.addVars(N, vtype=GRB.CONTINUOUS)
mdl.modelSense = GRB.MINIMIZE;
mdl.setObjective(quicksum(x[i,j]*c[i,j] for i,j in A))
mdl.addConstrs(quicksum(x[i,j] for j in V if j!=i)==1 for i in N);
mdl.addConstrs(quicksum(x[i,j] for i in V if i!=j)==1 for j in N);
mdl.addConstrs((x[i,j]==1) >> (u[i]+q[j]==u[j]) for i,j in A if i!= 0 and j!=0);
mdl.addConstrs(u[i]>=q[i] for i in N);
mdl.addConstrs(u[i]<=Q for i in N);
What I am doing is rewriting it in Julia using Jump, but I don't know how to add constraint "(x[i,j]==1) >> (u[i]+q[j]==u[j]) for i,j in A if i!= 0 and j!=0". I tried something like this:
"@constraint(mdl, x[i,j] >> u[i]+d[j]==u[j] for (i,j) in A if i!= 0 & j!=0);"
but it is not working. How should I do it?

This is more of a Julia Jump related question, so it might be better to ask in a Julia/JuMP forum.
Nevertheless, you want to formulate constraints of the form "if \(x=1\) then \(u+q=w\)". I don't know whether JuMP supports indicator constraints but you can formulate an indicator constraint "by hand" as described in How do I model conditional statements in Gurobi? I assume that your \(x\) is binary, so you could formulate the conditional statement "if \(x \geq 0.5\) then \(u+q=w\)".
Moreover, the thread Conditional constraint if else in JuMP might be helpful .
Best regards,
Jaromił0 
Jaromił Najman thank you for your answer, but ConditionalJump does not support newer version of JuMP, which I need. How exactly that code "by hand" would look like in this case?
0 
How exactly that code "by hand" would look like in this case?
The Knowledge Base article How do I model conditional statements in Gurobi? describes a formulation which you would have to implement in JuMP. In the formulation described in the article, if your \(x\) variable is binary, you can set \(y=0.5\) and set \(\epsilon=0\).
0
Please sign in to leave a comment.
Comments
3 comments