sets:
j3(j1,j2)|&2#gt#&1|:c;
endsets
&1表示第一个基本集合元素的索引值
输出
@GIN(X) 定义 X 为整型变量,代表X为正整数解
@SUM(<集合名>(下标范围):关于集合属性的目标函数表达式);
model:
sets:
cols/1..24/: e; !这是列;
rows/1..53/: s; !这是行;
links(rows,cols): c; !运输单价,决策运输量; c为矩阵
endsets
!==================================;
data:
c = @file('data_std.txt');
s = @file('data2.txt');
enddata
!==================================;
submodel transfer:
max = cost; ! 目标函数极小化;
cost = @sum(links: c*e); !目标函数:运输总成本;
! cost = @sum(cols(j): c(4,j)*e(j));
@for(rows(i):
@sum(cols(j): c(i,j)*e(j)) >= s(i) ); ! 产量约束;
@sum(cols(j): e(j))=500; !一天的标定食量;
e(8)>=300; !大米的含量要求;
endsubmodel
!==================================;
calc:
@solve(transfer); !运行子模块(解线性规划);
@divert('transfer_out.txt');!向.txt文件按自定格式输出数据;
@write('最大活性物质含量权值=',cost,@newline(1),'最优分配方案x=');
! @for(rows(i):
@write(@newline(1));
@writefor(cols(j): ' ',@format(e(j),'8.8f') ) ;
@divert(); !关闭输出文件;
endcalc
end
vc中运行的求解模型
model:
sets:
cols/1..24/: e; !这是列;
rows/1..53/: s,d,t; !这是行;
links(rows,cols): c; !运输单价,决策运输量;
endsets
!==================================;
data:
c = @file('data_std.txt');
enddata
DATA:
!把VC中的数据m_Num1,…,m_Num6传递到Lingo中的变量num1,…,num6;
s=@POINTER(1);
d=@POINTER(2);
!把Lingo计算的结果和状态分别传到VC中的变量res,dStatus;
@POINTER(3)=e;
@POINTER(4)=@STATUS();
ENDDATA
!==================================;
submodel transfer:
!max = cost; ! 目标函数极大化;
[cost]max = @sum(rows(i):d(i)*@sum(cols(j):c(i,j)*e(j)));
!cost = @sum(cols(j): c(4,j)*e(j));
@for(rows(i):
@sum(cols(j)|s(i)#GT#0: c(i,j)*e(j)) >= s(i) ); ! 产量约束;
@sum(cols(j): e(j))=500; !一天的标定食量;
e(8)>=300; !大米的含量要求;
endsubmodel
!==================================;
calc:
@solve(transfer); !运行子模块(解线性规划);
@for(rows(i):
t(i) = @sum(cols(j):c(i,j)*e(j)));
!t(1) = 8;
@divert('transfer_out.txt');!向.txt文件按自定格式输出数据;
@write('最大活性物质含量权值=',cost,@newline(1),'最优分配方案x=');
! @write(@newline(1));
@writefor(cols(j): ' ,',@format(e(j),'7.3f') ) ;
@write(@newline(1));
@write('最优分配方案下的各净含量t=');
@writefor(rows(i): ' ,',@format(t(i),'10.3f') );
@divert(); !关闭输出文件;
endcalc
DATA:
@POINTER(5)=cost;
@POINTER(6)=t;
ENDDATA
end