inventory.m

来自「TSP问题,即旅行商问题,matlab环境下可以运行」· M 代码 · 共 40 行

M
40
字号
function cost=inventory(v,l)
global customer;
global depot;
global demand;  
global UD;
global c;
global cm;
global h;
global A;
global hs;
global Q;
%计算路线总长度

double cost;
leng=0;
if l>1
    for i=2:l
            leng=distance(demand,v(i),v(i+1))+leng;
    end
    leng=leng+distance(demand,v(1)+customer,v(2))+distance(demand,v(l+1),v(1)+customer);
end
if l==1
      leng=2*distance(demand,v(1)+customer,v(2));
  end
  cost=0;

%计算路线总需求
D=sum(demand(v(2:l+1),3));
%计算路线上提前期的平均需求
u=0;
for i=2:l+1
   u=UD(v(i))+u;
end
R=u-(u*h*Q)/(hs*D);
BR=(u-R)^2/(2*u);
transportationcost=((c+cm*leng)*D)/Q;
inventorycost=(Q/2+R-u/2)*h+(D/Q)*A+(hs*BR*D)/Q;
cost=transportationcost+inventorycost;
%cost=transportationcost;

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?