0

I am struggling to formulate the following subtour elimination constraint for TSP-like problem in Pyomo, given a graph G(V,A) where node 1 is the depot:

enter image description here

where x_ij and y_h are binary constraints that I have previously defined as binary variables.

First, I created a dictionary of all possible subsets S such that node 1 is always contained: subsets_s.

Then, I have been trying with something like this, but I am running into errors:

model1.con3=ConstraintList()
for h in model1.V:
    if h is not 1:    
         for i in model1.S:
             if h not in subsets_s[i]['nodes_subset']:
                 S=subsets_s[i]['nodes_subset']
                 for v in S:
                     print(v)
                     model1.con3.add(sum(sum(model1.x[v,j]) for j in  
                     model1.V if j not in S)>=model1.y[h])                                     

Do you have any suggestions?

Thank you

Joel
  • 1,564
  • 7
  • 12
  • 20
Mike
  • 375
  • 1
  • 4
  • 14
  • Please state a clear question and describe how you previously tried to find an answer to that question on your own. – Tom Nov 09 '18 at 21:31
  • What have you tried? How are you struggling? Is it because of performance or because you couldn't write your constraint? – V. Brunelle Nov 09 '18 at 21:31
  • Thank you. I have tried to provide more details now. – Mike Nov 09 '18 at 21:37
  • 1
    For a graph with *n* nodes, there will be approximately 2^n subtour elimination constraints. The method I learned in university to deal with this is to start with no subtour elimination constraints and see what the solution is. If the solution includes a subtour, add a subtour elimination constraint to remove that subtour. Continue until you have no more subtours in your optimal solution. (If this takes too long, you can always use a heuristic method to get a "good" but not necessarily optimal solution) – Joel Nov 09 '18 at 22:02
  • 1
    Could you post the error messages you're seeing? – Bethany Nicholson Nov 12 '18 at 15:34

0 Answers0