# Modelling DFJ elminations constraints

**URL:** <https://discourse.julialang.org/t/modelling-dfj-elminations-constraints/29670>\
**Category:** Optimization (Mathematical)\
**Created:** [October 9, 2019, 2:30am UTC](https://discourse.julialang.org/t/modelling-dfj-elminations-constraints/29670 "2019-10-09T02:30:54Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Miguel\_Goncalves](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/miguel_goncalves/32/10699_2.png) [@Miguel\_Goncalves](https://discourse.julialang.org/u/Miguel_Goncalves)\
**Post date:** [October 9, 2019, 2:30am UTC](https://discourse.julialang.org/t/modelling-dfj-elminations-constraints/29670/1 "2019-10-09T02:30:54Z")

</div>

Hi, everyone.

I am new in this world of programming, specially in Julia, and i have found some trouble to ‘declare’ the subtour elimination from DFJ problems in Travelling Salesman Problem (TSP).

Constrait:  
 ![image](https://global.discourse-cdn.com/julialang/original/3X/1/4/1417e8c449ce99e1ad56f99cd41bfed938d78e22.png)

How can i compute this?

Thank you all very much in advance.

---

<div class="post-metadata">

**Author:** ![ericphanson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ericphanson/32/215186_2.png) [@ericphanson](https://discourse.julialang.org/u/ericphanson)\
**Post date:** [October 9, 2019, 9:14am UTC](https://discourse.julialang.org/t/modelling-dfj-elminations-constraints/29670/2 "2019-10-09T09:14:57Z")

</div>

Are you using JuMP? I think you would want to the use the function `combinations` from Combinatorics.jl to get all the subsets of `1:n` of a certain length, then for each subset add constraint (`@add_constraint` in JuMP).

Note that there are `2^n` subsets of `1:n` so you may have problems with even moderate `n`.

My package [TravelingSalesmanExact](https://github.com/ericphanson/TravelingSalesmanExact.jl) uses a variant of this approach where you don’t add constraints for every subtour, but rather you solve the problem once, see what subtours are in the “solution” you got, add constraints to remove those, and solve again and repeat until you end up with a full length tour.

---

<div class="post-metadata">

**Author:** ![odow](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/odow/32/28685_2.png) [@odow](https://discourse.julialang.org/u/odow)\
**Post date:** [October 9, 2019, 1:41pm UTC](https://discourse.julialang.org/t/modelling-dfj-elminations-constraints/29670/3 "2019-10-09T13:41:27Z")

</div>

Take a read of [Please read: make it easier to help you](https://discourse.julialang.org/t/psa-make-it-easier-to-help-you/14757)

In general, it’s a lot easier to help if you can provide a code snippet of what you are trying to achieve, what you have tried, and what the current error/behavior you are not expecting is.
