这个最小生成树问题,怎么用另一个算法来做

一、问题 的 提出

长虹街道近年来新建了 11 个居民小区,各小区的大致位置及相互间的距离(单位: 100m )如图所示。各居民小区的居民 人 数为: ① 3000 , ② 3500 , ③ 3700 , ④ 5000 , ⑤ 3000 , ⑥ 2500 , ⑦ 2800 , ⑧ 4500 , ⑨ 3300 , ⑩ 4000 , ⑾ 3500 。 试帮助决策。

长虹街道 11 个居民小区位置及相互间道路示意图

( 1 )在 11 个小区内准备共建一套医务所、邮局、储蓄所、综合超市等服务设施,应建于哪一居民小区,使 得 对居民来说感到方便 ?

( 2 )电信部门拟建宽带网铺设到各小区,应如何铺设最为经济?

sets:

cities/1..11/:level; !level(i)= the level of city;

link(cities, cities):

distance, !The distance matrix;

x; ! x(i,j)=1 if we use link i,j;

endsets

data: !Distance matrix, it need not be symmetirc;

distance = 0 4 100 6 100 100 8 100 100 100 100

4 0 7 5 100 100 100 100 100 100 100

100 7 0 100 6 5 100 100 100 100 100

6 5 11 0 5 100 100 6 100 100 100

100 100 6 5 0 4 100 8 6 100 100

100 100 5 100 4 0 100 100 7 100 100

8 100 100 100 100 100 0 4 100 5 100

100 100 100 6 8 100 4 0 4 100 5

100 100 100 100 6 7 100 4 0 100 6

100 100 100 100 100 100 5 100 100 0 6

100 100 100 100 100 100 100 5 6 6 0;

enddata

n=@size(cities); !The model size;

! Minimize total distance of the links;

min=@sum(link(i,j)|i #ne# j: distance(i,j)*x(i,j));

!There must be an arc out of city 1;

@sum(cities(i)|i #gt# 1: x(1,i))>=1;

!For city i, except the base (city 1);

@for(cities(i) | i #gt# 1 :

! It must be entered;

@sum(cities(j)| j #ne# i: x(j,i))=1;

! level(j)=levle(i)+1, if we link j and i;

@for(cities(j)| j #gt# 1 #and# j #ne# i :

level(j) >= level(i) + x(i,j)

- (n-2)*(1-x(i,j)) + (n-3)*x(j,i);

);

! The level of city is at least 1 but no more n-1,

and is 1 if it links to base (city 1);

@bnd(1,level(i),999999);

level(i)<=n-1-(n-2)*x(1,i);

);

! Make the x's 0/1;

@for(link : @bin(x));

主要计算结果:

Global optimal solution found.

Objective value: 47.00000

Objective bound: 47.00000

Infeasibilities: 0.000000

Extended solver steps: 0

Total solver iterations: 61

X( 1, 2) 1.000000 4.000000

X( 2, 4) 1.000000 5.000000

X( 4, 5) 1.000000 5.000000

X( 4, 8) 1.000000 6.000000

X( 5, 6) 1.000000 4.000000

X( 6, 3) 1.000000 5.000000

X( 7, 10) 1.000000 5.000000

X( 8, 7) 1.000000 4.000000

X( 8, 9) 1.000000 4.000000

X( 8, 11) 1.000000 5.000000