写lingo程序,急

写lingo程序,急,第1张

model:

sets:

firehouse/1..3/:num

fire/1..7/:

link(firehouse,fire):distance,x

endsets

data:

num=3,2,2

enddata

min=@sum(link:distance*x)

@for(firehouse(i):@sum(fire(j):x(i,j))=num(i))

@for(fire(j):@sum(firehouse(i):x(i,j))=1)

@for(link:@gin(x))

end

结果

X( 1, 1)0.0000000.000000

X( 1, 2)1.0000000.000000

X( 1, 3)0.0000000.000000

X( 1, 4)0.0000000.000000

X( 1, 5)0.0000000.000000

X( 1, 6)1.0000000.000000

X( 1, 7)1.0000000.000000

X( 2, 1)0.0000000.000000

X( 2, 2)0.0000000.000000

X( 2, 3)1.0000000.000000

X( 2, 4)1.0000000.000000

X( 2, 5)0.0000000.000000

X( 2, 6)0.0000000.000000

X( 2, 7)0.0000000.000000

X( 3, 1)1.0000000.000000

X( 3, 2)0.0000000.000000

X( 3, 3)0.0000000.000000

X( 3, 4)0.0000000.000000

X( 3, 5)1.0000000.000000

X( 3, 6)0.0000000.000000

X( 3, 7)0.0000000.000000

就是说1号消防站派车到2 6 7

2号到3 4

3号到1 5

sets:

point/1..12/:x,y,r,c

link(point,point):d

endsets

calc:

@for(link(i,j):d(i,j)=@sqrt((x(i)-x(j))^2+(y(i)-y(j))^2))

endcalc

min=@sum(link(i,j):d(i,j)*c(i)*r(i))

@sum(point:c)=2

@for(point:@bin(c))

function x=linliu(c,A,b)

[n1,n2]=size(A)

A=[A,eye(n1)]c=[-c,zeros(1,n1)]

x1=[zeros(1,n2),b']lk=[n2+1:n1+n2]

fp=fopen('f:\liu.m','wt')

fprintf(fp,'初始单纯形表:\n')

while(1)

x=x1(1:n2)

s1=[lk',b,A]

c

x1

fprintf(fp,' 基b')

for j=1:n2+n1

fprintf(fp,' x%d ',j)

end

fprintf(fp,'\n')

for i=1:n1

fprintf(fp,'%4.1f %4.1f',lk(i),b(i))

for j=1:n2+n1

fprintf(fp,'%4.1f ',A(i,j))

end

fprintf(fp,'\n')

end

fprintf(fp,' ')

for i=1:n1+n2

fprintf(fp,'%4.1f ',c(i))

end

fprintf(fp,'\n解为:\n')

for i=1:n2+n1

fprintf(fp,'x(%d)=%3.2f,',i,x1(i))

end

cc=[]ci=[]

for i=1:n1+n2

if c(i)<0

cc=[cc,c(i)]

ci=[ci,i]

end

end

nc=length(cc)

if nc==0

fprintf('达到最优解')

fprintf(fp,'\n达到最优解')

break

end

cliu=cc(1)

cl=ci(1)

for j=1:nc

if abs(cc(j))>abs(cliu)

cliu=cc(j)

cl=j

end

end

cc1=[]ci1=[]

for i=1:n1

if A(i,cl)>0

cc1=[cc1,A(i,cl)]

ci1=[ci1,i]

end

end

nc1=length(cc1)

if nc1==0

fprintf('无有界最优解')

fprintf(fp,'无有界最优解')

break

end

cliu=b(ci1(1))/cc1(1)

cl1=ci1(1)

for j=1:nc1

if b(ci1(j))/cc1(j)<cliu

cliu=b(ci1(j))/cc1(j)

cl1=ci1(j)

end

end

fprintf(fp,'\nx(%d)入基,x(%d)出基\n',cl,lk(cl1))

fprintf('\nx(%d)入基,x(%d)出基\n',cl,lk(cl1))

b(cl1)=b(cl1)/A(cl1,cl)

A(cl1,:)=A(cl1,:)/A(cl1,cl)

for k=1:n1

if k~=cl1

b(k)=b(k)-b(cl1)*A(k,cl)

A(k,:)=A(k,:)-A(cl1,:).*A(k,cl)

end

end

c=c-c(cl).*A(cl1,:)

x1(lk(cl1))=0

lk(cl1)=cl

for kk=1:n1

x1(lk(kk))=b(kk)

end

x=x1(1:n2)

end

fclose(fp)

检验:p31页 运筹学 清华

format rat

c=[2 3]A=[1 24 00 4]b=[81612]

x=linliu(c,A,b)


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/yw/11565747.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-17
下一篇 2023-05-17

发表评论

登录后才能评论

评论列表(0条)

保存