?? d_2.r
字號:
### 讀數據
rc<-read.csv("D_data.csv")
### 將數據寫成矩陣
lab1<-paste("X", 1:5, sep="")
lab2<-paste("Z", 1:73, sep="")
labT<-c("D", lab1, lab2); labT
### 寫矩陣
source("write_matrix.R")
dist<-write_matrix(rc, labT)
source("write_file2.R")
write_file2(labT, dist, file="dist2.ldt")
### Floyd 算法求任意兩點的最短路
source("floyd.R")
dist<-floyd(dist)
dist
str<-c(
58, 59, 61, 62, 63, 64, 65, 66, 67, 68, 72, 73,
14, 15, 16,
52,53,
41,42,
29, 31, 33,
18
)
str<-c(
62, 16, 15, 14,
67, 66, 63, 18,
69, 68, 29, 31, 33,
72, 73, 42, 41,
61, 59, 58, 52, 53
)
lab2<-paste("Z", str, sep="")
labT<-c("D", lab1, lab2); labT
#### 計算小矩陣 ####################################
source("comput_small_matrix.R")
index<-comput_small_matrix(dist, labT)
D<-dist[index, index]
D
### 寫文件, 為LINGO運算使用
source("write_file2.R")
write_file2(labT, D)
### 此時用LINGO軟件計算最優生成樹
#### 計算給定路線長度 ####################################
str<-c(60, 59, 58, 52); labT<-c("D",paste("Z", str, sep=""), "X5")
str<-c(61, 59, 62, 16, 15, 14); labT<-c("D",paste("Z", str, sep=""), "X1")
str<-c(67, 66, 63, 18); labT<-c("D",paste("Z", str, sep=""), "X2")
str<-c(69, 68, 29, 31,33); labT<-c("D",paste("Z", str, sep=""), "X3")
str<-c(72, 73, 42, 41); labT<-c("D",paste("Z", str, sep=""), "X4")
str<-c(71, 70, 35, 34,32, 33); labT<-c("D",paste("Z", str, sep=""), "X3")
index<-comput_small_matrix(dist, labT)
D<-dist[index, index];D
n<-length(index);n
L<-0
for (i in 1:(n-1))
L<-L+D[i, i+1]
L
#### 計算小圈的TSP ####################################
str1<-c(67, 66, 63, 18);
str2<-c(27, 64, 65)
labT<-c("D",paste("Z", str1, sep=""), "X2", paste("Z", str2, sep=""))
str1<-c(61, 59, 53, 52);
str2<-c(58, 60)
labT<-c("D",paste("Z", str1, sep=""), "X5", paste("Z", str2, sep=""))
str1<-c(72, 73, 42, 41);
str2<-c(36, 71)
labT<-c("D",paste("Z", str1, sep=""), "X4", paste("Z", str2, sep=""))
str1<-c(69, 70, 35, 34, 32, 30, 31, 28);
str2<-c(33, 29, 68)
labT<-c("D",paste("Z", str1, sep=""), "X3", paste("Z", str2, sep=""))
str1<-c(62, 16, 15, 14);
str2<-c(11, 10, 9, 8)
labT<-c("D",paste("Z", str1, sep=""), "X1", paste("Z", str2, sep=""))
str<-c(19:26); labT<-c("X2",paste("Z", str, sep=""));labT
str<-c(27:31,33);labT<-c("X3",paste("Z", str, sep=""));labT
str<-c(43,40,39,38,37);labT<-c("X4",paste("Z", str, sep=""));labT
str<-c(44:51);labT<-c("X5",paste("Z", str, sep=""));labT
str<-c(54:57);labT<-c("X5",paste("Z", str, sep=""));labT
str<-c(2:7);labT<-c("X1",paste("Z", str, sep=""));labT
str<-c(12,13,1);labT<-c("X1",paste("Z", str, sep=""));labT
str<-c(17,19); labT<-c("X2",paste("Z", str, sep=""));labT
str<-c(20:26); labT<-c("X2",paste("Z", str, sep=""));labT
index<-comput_small_matrix(dist, labT)
D<-dist[index, index];D
write_file2(labT, D)
#### 調用D1_TSP
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -