Skip to content

Commit

Permalink
Update tsp_lazy_constraints.jl
Browse files Browse the repository at this point in the history
  • Loading branch information
odow authored Oct 9, 2024
1 parent cd36562 commit 84a279f
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions docs/src/tutorials/algorithms/tsp_lazy_constraints.jl
Original file line number Diff line number Diff line change
Expand Up @@ -116,15 +116,15 @@ import Plots
# The vertices are assumed to be randomly distributed in the Euclidean space;
# thus, the weight (distance) of each edge is defined as follows.

function generate_distance_matrix(n; random_seed = 1234)
function generate_distance_matrix(n; random_seed = 1)
rng = Random.MersenneTwister(random_seed)
X = 100 * rand(rng, n)
Y = 100 * rand(rng, n)
d = [sqrt((X[i] - X[j])^2 + (Y[i] - Y[j])^2) for i in 1:n, j in 1:n]
return X, Y, d
end

n = 40
n = 20
X, Y, d = generate_distance_matrix(n)

# For the JuMP model, we first initialize the model object. Then, we create the
Expand Down Expand Up @@ -252,7 +252,6 @@ function subtour_elimination_callback(cb_data)
if !(1 < length(cycle) < n)
return # Only add a constraint if there is a cycle
end
println("Found cycle of length $(length(cycle))")
S = [(i, j) for (i, j) in Iterators.product(cycle, cycle) if i < j]
con = @build_constraint(
sum(lazy_model[:x][i, j] for (i, j) in S) <= length(cycle) - 1,
Expand Down

0 comments on commit 84a279f

Please sign in to comment.