您好,欢迎来到欧得旅游网。
搜索
您的当前位置:首页set和data解决运输问题2(使用.txt传递数据)

set和data解决运输问题2(使用.txt传递数据)

来源:欧得旅游网

使用lingo中的函数@file、@text进行纯文本文件数据的输入和输出。 注意:执行一次@file,输入1个记录,记录之间的分割符为'~' lingo程序的文件名为zuixiao.lg4 !最小运输费; !3产地,4销地的运输问题; !3 Warehouse,4 Customer Transportation Problem; sets:

使用lingo中的函数@file、@text进行纯文本文件数据的输入和输出。

注意:执行一次@file,输入1个记录,记录之间的分割符为'~'

lingo程序的文件名为zuixiao.lg4

!最小运输费;
!3产地,4销地的运输问题;
!3 Warehouse,4 Customer Transportation Problem;
sets:
Warehouse /1..3/:a;
Customer /1..4/:b;
Routes(Warehouse,Customer):c,x;
endsets
!Here are the parameters;
data:
a=@file(Ldata.txt);
b=@file(Ldata.txt);
c=@file(Ldata.txt);
enddata
!The objective;
[OBJ] min=@sum(Routes:c*x);
!The supply constraints;
@for(Warehouse(i):[SUP]
@sum(Customer(j):x(i,j))<=a(i));
!The demand constraints;
@for(Customer(j):[DEM]
@sum(Warehouse(i):x(i,j))=b(j));
end
-------------------------------------------------------------------------------

文件Ldata.txt中的数据格式如下:

30 25 21~ !'~'是记录分割符,该第一个记录是产量;
15 17 22 12~ !该第二个记录为需求量;
6 2 6 7
4 9 5 3
8 8 1 5 !最后一记录为单位运价;

-------------------------------------------------------------------------

注意,要把zuixiao.lg4和Ldata.txt放在同一文件夹下,然后再点击“Solve”,就得到如下结果:

X( 1, 1) 2.000000 0.000000
X( 1, 2) 17.00000 0.000000
X( 1, 3) 1.000000 0.000000
X( 1, 4) 0.000000 2.000000
X( 2, 1) 13.00000 0.000000
X( 2, 2) 0.000000 9.000000
X( 2, 3) 0.000000 1.000000
X( 2, 4) 12.00000 0.000000
X( 3, 1) 0.000000 7.000000
X( 3, 2) 0.000000 11.00000
X( 3, 3) 21.00000 0.000000
X( 3, 4) 0.000000 5.000000

Row Slack or Surplus Dual Price
OBJ 161.0000 -1.000000

即最小运输费为:161

Copyright © 2019- ovod.cn 版权所有 湘ICP备2023023988号-4

违法及侵权请联系:TEL:199 1889 7713 E-MAIL:2724546146@qq.com

本站由北京市万商天勤律师事务所王兴未律师提供法律服务