-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTSP_Solver.R
26 lines (24 loc) · 1.06 KB
/
TSP_Solver.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# Resolver o Problema do Caixeiro Viajante com package do R : TSP
library(TSP)
X <-rbind(c(0., 928., 987., 1961., 977., 232., 1610., 1943., 1361., 1467.),
c(928., 0., 1656., 577., 1879., 1584., 1330., 351., 1909.,470.),
c(987., 1656., 0., 387., 1575., 332., 1978., 857., 754.,987.),
c(1961., 577., 387., 0., 1471., 844., 576., 1615., 129.,92.),
c( 977., 1879., 1575., 1471., 0., 1358., 727., 434., 872.,671.),
c( 232., 1584., 332., 844., 1358., 0., 1087., 585., 187.,384.),
c(1610., 1330., 1978., 576., 727., 1087., 0., 1151., 1529.,1361.),
c(1943., 351., 857., 1615., 434., 585., 1151., 0., 92.,1507. ),
c(1361., 1909., 754., 129., 872., 187., 1529., 92., 0., 569.),
c(1467., 470., 987., 92., 671., 384., 1361., 1507., 569., 0.))
print(X)
tsp <- TSP(X)
N=100
solutions <-numeric(100)
for (i in 1:N) {
tour <- solve_TSP(tsp)
tour
tour_length(tour)
solutions[i]<- tour_length(tour)
}
print(min(solutions))
print(max(solutions))