整理一下做完整的钢管订购与运输问题(题1,3)[前面的数据输入有误,多谢明明同学帮忙找错……]

首先铁路的数据

a = {{1, 29, 20}, {1, 30, 202}, {2, 30, 1200}, {3, 31, 690}, {4, 33,
690}, {5, 35, 462}, {6, 38, 70}, {7, 39, 30}, {23, 24, 450}, {24,
25, 80}, {24, 26, 1150}, {27, 28, 306}, {28, 29, 195}, {26, 30,
1100}, {30, 31, 720}, {31, 32, 520}, {32, 33, 170}, {33, 35,
88}, {33, 34, 160}, {34, 36, 70}, {34, 37, 320}, {37, 38,
160}, {38, 39, 290}}

公路数据(题1)

b = {{8, 9, 104}, {9, 10, 301}, {10, 11, 750}, {11, 12, 606}, {12, 13,
194}, {13, 14, 205}, {14, 15, 201}, {15, 16, 680}, {16, 17,
480}, {17, 18, 300}, {18, 19, 220}, {19, 20, 210}, {20, 21,
420}, {21, 22, 500}, {9, 23, 3}, {10, 25, 2}, {11, 26, 600}, {12,
27, 10}, {13, 28, 5}, {14, 29, 10}, {1, 14, 31}, {15, 30, 12}, {16,
31, 42}, {17, 32, 70}, {18, 35, 10}, {19, 36, 10}, {20, 37,
62}, {6, 21, 110}, {21, 38, 30}, {22, 39, 20}, {7, 22, 20}}

公路数据(题2)

b = {{8, 9, 104}, {9, 10, 301}, {10, 11, 750}, {11, 12, 606}, {12, 13,
194}, {13, 14, 205}, {14, 15, 201}, {15, 16, 680}, {16, 17,
480}, {17, 18, 300}, {18, 19, 220}, {19, 20, 210}, {20, 21,
420}, {21, 22, 500}, {9, 23, 3}, {10, 25, 2}, {11, 26, 600}, {12,
27, 10}, {13, 28, 5}, {14, 29, 10}, {1, 14, 31}, {15, 30, 12}, {16,
31, 42}, {17, 32, 70}, {18, 35, 10}, {19, 36, 10}, {20, 37,
62}, {6, 21, 110}, {21, 38, 30}, {22, 39, 20}, {7, 22, 20}, {34,
35, 130}, {35, 36, 190}, {36, 37, 260}, {6, 37, 100}}

Floyd算法

Floyd[n_, a_List] :=
Module[{i, j, k}, d = Table[Infinity, {i, n}, {j, n}];
r = Table[j, {i, n}, {j, n}];
For[i = 1, i <= n, i++, d[[i, i]] = 0];
For[i = 1, i <= Length[a], i++,
d[[a[[i, 1]], a[[i, 2]]]] = a[[i, 3]];
d[[a[[i, 2]], a[[i, 1]]]] = a[[i, 3]]];
For[k = 1, k <= n, k++,
For[i = 1, i <= n, i++,
For[j = 1, j <= n, j++,
If[d[[i, k]] + d[[k, j]] < d[[i, j]],
d[[i, j]] = d[[i, k]] + d[[k, j]];
r[[i, j]] = r[[i, k]]]]]]];
Floyd[39, a];
MatrixForm[d]
MatrixForm[r] Continue reading “整理一下做完整的钢管订购与运输问题(题1,3)[前面的数据输入有误,多谢明明同学帮忙找错……]”

建模之钢管订购问题~

很郁闷,2点了,还没解决我白天留下的问题,暂且记下重要数据和代码

建模钢管

(*以下是铁路的数据*)
a = {{1, 29, 20}, {1, 30, 202}, {2, 30, 1200}, {3, 31, 690}, {4, 33,
690}, {5, 35, 462}, {6, 38, 70}, {7, 39, 30}, {23, 24, 450}, {24,
25, 80}, {24, 26, 1150}, {27, 28, 306}, {28, 29, 195}, {26, 30,
1100}, {30, 31, 720}, {31, 32, 520}, {32, 33, 170}, {33, 35,
88}, {33, 34, 160}, {34, 36, 70}, {34, 37, 320}, {37, 38,
160}, {38, 39, 290}}

(*Floyd算法*) Continue reading “建模之钢管订购问题~”