Issue in using condition based constraint
AnsweredHello.
I am trying to solve a optimization problem similar to TSP however in my case it is not necessary to visit all nodes. My objective function is to maximize collection of items between start and end node by trying to visit as many nodes as possible based on some battery constraints.
However, I am struggling to add a connectivity constraint.
I tried to use the 2nd degree constraint from TSP for my optimization problem where I want to make the algorithm choose the TSP constraint only if a particular node is selected.
Eg: m.addConstrs(x.sum(i,j) == 2 for i in range(n) for j in range (i) if x(i,j) == 1)
Here, x is the decision variable (binary).
What am I doing wrong and is there any better way to put a connectivity constraint between nodes?
-
Official comment
Hi Shubham,
You should be able to formulate this using indicator constraints. These constraints will only be active if the indicator variable - here \(x(i,j)\) - is true.
Cheers,
Matthias -
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?.
Post is closed for comments.
Comments
2 comments