subtour elimination constraint pyomo









up vote
0
down vote

favorite












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










share|improve this question























  • Please state a clear question and describe how you previously tried to find an answer to that question on your own.
    – Tom
    Nov 9 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 9 at 21:31










  • Thank you. I have tried to provide more details now.
    – Mike
    Nov 9 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 9 at 22:02







  • 1




    Could you post the error messages you're seeing?
    – Bethany Nicholson
    Nov 12 at 15:34














up vote
0
down vote

favorite












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










share|improve this question























  • Please state a clear question and describe how you previously tried to find an answer to that question on your own.
    – Tom
    Nov 9 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 9 at 21:31










  • Thank you. I have tried to provide more details now.
    – Mike
    Nov 9 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 9 at 22:02







  • 1




    Could you post the error messages you're seeing?
    – Bethany Nicholson
    Nov 12 at 15:34












up vote
0
down vote

favorite









up vote
0
down vote

favorite











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










share|improve this question















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







constraints traveling-salesman pyomo






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 9 at 22:02









Joel

1,6086719




1,6086719










asked Nov 9 at 21:12









Mike

217




217











  • Please state a clear question and describe how you previously tried to find an answer to that question on your own.
    – Tom
    Nov 9 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 9 at 21:31










  • Thank you. I have tried to provide more details now.
    – Mike
    Nov 9 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 9 at 22:02







  • 1




    Could you post the error messages you're seeing?
    – Bethany Nicholson
    Nov 12 at 15:34
















  • Please state a clear question and describe how you previously tried to find an answer to that question on your own.
    – Tom
    Nov 9 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 9 at 21:31










  • Thank you. I have tried to provide more details now.
    – Mike
    Nov 9 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 9 at 22:02







  • 1




    Could you post the error messages you're seeing?
    – Bethany Nicholson
    Nov 12 at 15:34















Please state a clear question and describe how you previously tried to find an answer to that question on your own.
– Tom
Nov 9 at 21:31




Please state a clear question and describe how you previously tried to find an answer to that question on your own.
– Tom
Nov 9 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 9 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 9 at 21:31












Thank you. I have tried to provide more details now.
– Mike
Nov 9 at 21:37





Thank you. I have tried to provide more details now.
– Mike
Nov 9 at 21:37





1




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 9 at 22:02





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 9 at 22:02





1




1




Could you post the error messages you're seeing?
– Bethany Nicholson
Nov 12 at 15:34




Could you post the error messages you're seeing?
– Bethany Nicholson
Nov 12 at 15:34

















active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













 

draft saved


draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53233334%2fsubtour-elimination-constraint-pyomo%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown






























active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes















 

draft saved


draft discarded















































 


draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53233334%2fsubtour-elimination-constraint-pyomo%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

How to how show current date and time by default on contact form 7 in WordPress without taking input from user in datetimepicker

Syphilis

Darth Vader #20