基于退火算法的生产企业原材料的订购与运输分析
摘要
这个是数学建模国赛的一道题,在我进行数学建模国赛之前的一道练习题,有所借鉴,注释给的很详细,使用时将各部分分开。
某建筑和装饰板材的生产企业所用原材料主要是木质纤维和其他植物素纤维材料,
总体可分为A,B,C三种类型。该企业每年按48周安排生产,需要提前制定24周的原材料订购和转运计划,即根据产能要求确定需要订购的原材料供应商(称为“供应商”)
和相应每周的原材料订购数量(称为“订货量”),确定第三方物流公司(称为“转运商”)并委托其将供应商每周的原材料供货数量(称为“供货量”)转运到企业仓库。
本文针对生产企业原材料的订购与运输进行分析,通过对供应商实际供货量、企业对供应商的订单需求、转运商损耗率数据进行预处理,将不直观的数据转化为简洁的数据表,利用TOPSIS-熵权法、退火算法和贪心算法建立模型并进行分析与模拟。
针对问题一,我们通过MATLAB对附件中的数据进行量化处理。通过数据集成、数据变换得到可操作、可进行调用的数据组,也为之后问题二、问题三的建模提供基础数据。此外,对表格中的数据进行量化分析,建立反应保障企业生产重要性的数学模型。从重要性来看,建立指标评价体系,论述选取评价指标的合理性。根据指标数据建立TOPSIS模型,确定评价指标,明确指标类型,使其正向化,得到初步的指标,然后通过熵权法最终确定各项指标的权重,进一步得出重要性分数和排名。其中前3家企业及其得分分别为:
S229 | 1.2 | 354887 | 240 | 0.945833 | 1 |
S361 | 1 | 328080 | 240 | 0.879167 | 0.924457 |
S140 | 1.1 | 302047 | 219 | 0.886364 | 0.851096 |
针对问题二,细分为两个小方向,分别解决最小供应商数量需求与制订供应商、转运商方案的问题。一,从最小供应商数量需求来看,只需要考虑仓库储存量、企业的产能,供需关系达到平衡即可。二,从制订供应商、转运商方案来看,使用退火算法分析,对商家进一步优化选择。即商家的选取具有合理性,逐步保证方案的优化,最终可以得出合理的正确的优化方案。
针对问题三,通过第二问进一步进行分析。延用第二问退火算法多次迭代优化,相比于第二问,引入了仓储、材料的成本计算,由于A类相对于C类的天然仓储优势,自然完成了题目要求,对转运商质量进行排序,利用贪心算法得到每家转运商的转运方案,再进一步引入转运商的转运损耗率,制定新的订购方案及转运方案并对其进行效果分析。
针对问题四,该企业通过技术改造已具备了提高产能的潜力。在问题三的基础上,修改产能要求至不设限,而有8位转运商进行限制,得出每周产能提高数。
关键词 TOPSIS—熵权法 退火算法 贪心算法 采购方案
%第一问,删掉
%topsis代码
%处理数据
clc;clear
[num,txt,raw]=xlsread("C:\Users\珊瑚宫心海\Desktop\附件1 近5年402家供应商的相关数据.xlsx",1);
[num2,txt2,raw2]=xlsread("C:\Users\珊瑚宫心海\Desktop\附件1 近5年402家供应商的相关数据.xlsx",2);
%计算订单完成的周数
sum_dabiao=zeros(402,1);
[m,n]=size(num);%计算m行n列
for j=1:m
for i=1:n
if num(j,i)~=0&&num2(j,i)>=num(j,i)
sum_dabiao(j,1)=sum_dabiao(j,1)+1;
end
end
end
num_wancheng=sum(num~=0,2);%计算订单的周数
num2_sum_cailiao=sum(num2,2);%求出总材料量;
num2_mean=mean(num2,2);%得出平均材料量;
num2_wancheng=sum(num2~=0,2);%计算供应商供货周数;
num2_wugongji=sum(num2==0,2);%计算没供货周数;
num2_month=num2_mean*4;
wanchenglv=sum_dabiao./num_wancheng;%完成率
%将材料量化
cl=ones(402,1);
zhaoA = strcmp(txt2(2:end,2),'A');%找出A,标记1
findA=find(zhaoA==1);%找出字符串所在
zhaoB = strcmp(txt2(2:end,2),'B');%找出B,标记1
findB=find(zhaoB==1);%找出字符串所在
cl(findA)=1.2;
cl(findB)=1.1;
data1=[cl num2_sum_cailiao num2_wancheng wanchenglv];
bingt=[sum(num2_sum_cailiao<100),sum(num2_sum_cailiao>=100&num2_sum_cailiao<1000),sum(num2_sum_cailiao>=1000&num2_sum_cailiao<10000),sum(num2_sum_cailiao>=10000)];
pie3(bingt)
legend('供货量小于100','供货量100-1000','供货量1000-10000','供货量大于10000')
%%
%熵权topsis
x=data1;%导入数据
[n,m]=size(x);
% 归一化处理
[X,pc]=mapminmax(x',0,1);
pc.ymin=0.002; % 最小值
pc.ymax=0.996; % 最大值
pc.yrange=pc.ymax-pc.ymin; % 极差
X=mapminmax(x',pc);
X=X'; % X为归一化后的数据
% 计算比重
for i=1:n
for j=1:m
p(i,j)=X(i,j)/sum(X(:,j));
end
end
%计算熵值
k=1/log(n);
for j=1:m
e(j)=-k*sum(p(:,j).*log(p(:,j)));
end
d=ones(1,m)-e; % 计算信息熵冗余度
w=d./sum(d); % 求权值w
%TOPSIS综合评价
A=data1;%评价矩阵
W=w%权重
[ma,na]=size(A);
for i=1:na
B(:,i)=A(:,i)*W(i); %得到加权标准化矩阵
end
V1=zeros(1,na); %初始化正理想解和负理想解
V2=zeros(1,na);
BMAX=max(B); %取加权标准化矩阵每列的最大值和最小值
BMIN=min(B);
for i=1:na
V1(i)=BMAX(i);
V2(i)=BMIN(i);
end
for i=1:ma
C1=B(i,:)-V1;
S1(i)=norm(C1); %S1,S2分别为离正理想点和负理想点的距离
C2=B(i,:)-V2;
S2(i)=norm(C2);
T(i)=S2(i)/(S1(i)+S2(i));
end
output=T'%得出评分
xlswrite('评分.xlsx',output)
问题二
clc;clear;
[num,txt,raw]=xlsread("C:\Users\珊瑚宫心海\Desktop\新建 Microsoft Excel 工作表 (2).xlsx");
data=xlsread("C:\Users\珊瑚宫心海\Desktop\附件1 近5年402家供应商的相关数据.xlsx",2);
index=1:402;
num2=[index' num];
num3=sortrows(num2,7);%对排名升序
wushi50=num3(1:50,:);
indexC=find(wushi50(:,2)==1);
C=wushi50(indexC,:);
for i=1:20
Max(i)=max(data(C(i,1),:));
end
T=28200*0.72;
cangku=0;%表示出库材料存量
buy=zeros(20,24);
A=0;
f=100000000;%初始化
X=1000;%模拟次数
count=1;
for Xunhuan=1:X
for i=1:20
buy(i,1)=min(6000,randi(round([Max(i)*0.3,Max(i)*0.6])));
end
if sum(buy(:,1))>=T
cangku=sum(buy(:,1))-T;
Changku(1)=cangku;
for j=2:24%星期
for i=1:20%供应商
fanwei=min(6000,round([Max(i)*0.3,Max(i)*0.6]));
if sum(buy(:,j))<=T||cangku<=2*T
buy(i,j)=randi(fanwei);
if sum(buy(:,j))>=T
cangku=cangku+sum(buy(:,j))-T;
if cangku>=2*T
continue
end
end
end
end
if sum(buy(:,j))<=T
cangku=cangku-(T-sum(buy(:,j)));
end
Changku(j)=cangku;%记录每周仓库的存储数量
end
end
%数据合并
Buy=zeros(402,24)*nan;
Buy(C(:,1),:)=buy;
%%
%模拟转运损耗
into=xlsread("C:\Users\珊瑚宫心海\Desktop\附件2 近5年8家转运商的相关数据.xlsx",'B2:IG9');
yunshu=zeros(5,24)
for j=1:8%第j个转运商
hang=into(j,:);
%sunhao=unique(hang);
%[m,n]=size(sunhao);
for i=1:24
xunzhe=randi(240)
yunshu(j,i)=hang(xunzhe)
end
end
%%
%实施转运
p=1:8;;
a=1;%第a列
transport=zeros(20,24);
for i=1:24%24周
a=1;%第a行
R=0;%运输量
yunshu2=[p' yunshu(:,i)];
yunshu2(find(yunshu2(:,2)==0),:)=[];%剔除不运输的转运商
[m,n]=size(yunshu2);
yunshu3=sortrows(yunshu2,2)%进行降序
for j=1:20%20家供应商
indexT=yunshu3(a,1);
if R<=6000
R=R+buy(j,i);
transport(j,i)=indexT;
else
a=a+1;
if a>m
a=m;
end
transport(j,i)=yunshu3(a,1);
R=0;
R=R+buy(j,i);
end
end
end
Transport=zeros(402,24)*nan;
Transport(C(:,1),:)=transport;
%%
%计算损失
Sunshi=zeros(20,24)*nan;
for j=1:24;%周
for i=1:20%供应商
Shunshi(i,j)=buy(i,j)*yunshu(transport(i,j),j)
end
end
Shunshi2=zeros(402,24);
Shunshi2(C(:,1),:)=Shunshi;
if length(find(Changku>=0))==24 && cangku>2*T
F(count)=sum(sum(buy))*1.5+sum(Changku)*0.5;
count=count+1
if F(count-1)<f
f=F(count-1);
Buy2=Buy;
Transport2=Transport;
Shunshi3=Shunshi2;
xlswrite('问题2损耗',Shunshi3);
xlswrite('问题2订购方案',Buy2);
xlswrite('问题2运输方案',Transport);
end
end
Xunhuan
end
x=1:count-1;
F2=sort(F,'descend')
plot(x,F2,'-k*','linewidth',1)
title('\fontname{宋体}有效模拟图');
xlabel('\fontname{宋体}有效模拟次数');;
ylabel('\fontname{宋体}花费成本');
set(gca,'FontName','Times New Roman','fontsize',10.5)
box on
grid on
xlim([1,count-1])
figure
plot(x,F,'-k*','linewidth',1)
title('\fontname{宋体}有效模拟图');
xlabel('\fontname{宋体}有效模拟次数');;
ylabel('\fontname{宋体}花费成本');
set(gca,'FontName','Times New Roman','fontsize',10.5)
box on
grid on
xlim([1,count-1])
第三问
%第三问代码
clc;clear;
[num,txt,raw]=xlsread("C:\Users\珊瑚宫心海\Desktop\新建 Microsoft Excel 工作表 (2).xlsx");
data=xlsread("C:\Users\珊瑚宫心海\Desktop\附件1 近5年402家供应商的相关数据.xlsx",2);
index=1:402;
num2=[index' num];
num3=sortrows(num2,7);%对排名进行升序
wushi=num3(1:50,:);
%找出卖A的
indexA=find(wushi(:,2)==1.2);
A=wushi(indexA,:);
%找出卖B的
indexB=find(wushi(:,2)==1.1);
B=wushi(indexB,:);
%找出卖C的
indexC=find(wushi(:,2)==1);
C=wushi(indexC,:);
for i=1:16
MaxA(i)=max(data(A(i,1),:));
end
for i=1:14
MaxB(i)=max(data(B(i,1),:));
end
for i=1:20
MaxC(i)=max(data(C(i,1),:));
end
F=[]
Buy2=[];
R2=[];
Transport=[];
Shunshi2=[];
f=1000000000;
count=1;
X=100%模拟次数
for Xunhuan=1:X
x=rand(1,3);y=sum(x);r=x/y;
r2=sort(r,2)
TA=28200*0.6*r2(3);
TB=28200*0.66*r2(2);
TC=28200*0.72*r2(1);
if TC<1
TC=1
end
changkuA=0;
changkuB=0;
changkuC=0;%表示出库材料存量
buyA=zeros(16,24);
buyB=zeros(14,24);
buyC=zeros(20,24);
%%
%购买材料A
for i=1:16
buyA(i,1)=min(round(TC*0.5),randi(round([MaxA(i)*0.5,MaxA(i)])));
end
if sum(buyA(:,1))>=TA
changkuA=sum(buyA(:,1))-TA;
ChangkuA(1)=changkuA;
for j=2:24%星期
for i=1:16%供应商
fanwei=min(round(TC*0.5),randi(round([MaxA(i)*0.5,MaxA(i)])));
if fanwei==0;
fanwei=1
end
if sum(buyA(:,j))<=TA||changkuA<=2*TA
buyA(i,j)=randi(fanwei);
if sum(buyA(:,j))>=TA
changkuA=changkuA+sum(buyA(:,j))-TA;
if changkuA>=2*TA
continue
end
end
end
end
if sum(buyA(:,j))<=TA
changkuA=changkuA-(TA-sum(buyA(:,j)));
end
ChangkuA(j)=changkuA;%记录每周仓库的存储数量
end
end
%%
%购买材料B
for i=1:14
buyB(i,1)=min(round(TB*0.5),randi(round([MaxB(i)*0.5,MaxB(i)])));
end
if sum(buyB(:,1))>=TB
changkuB=sum(buyB(:,1))-TB;
ChangkuB(1)=changkuB;
for j=2:24%星期
for i=1:14%供应商
fanwei=min(round(TC*0.5),randi(round([MaxB(i)*0.5,MaxB(i)])));
if fanwei==0;
fanwei=1;
end
if sum(buyB(:,j))<=TB||changkuB<=2*TB
buyB(i,j)=randi(fanwei);
if sum(buyB(:,j))>=TB
changkuB=changkuB+sum(buyB(:,j))-TB;
if changkuB>=2*TB
continue
end
end
end
end
if sum(buyB(:,j))<=TB
changkuB=changkuB-(TB-sum(buyB(:,j)));
end
ChangkuB(j)=changkuB;%记录每周仓库的存储数量
end
end
%%
%购买材料C
for i=1:20
buyC(i,1)=min(round(TC*0.5),randi(round([MaxC(i)*0.5,MaxC(i)])));
end
if sum(buyC(:,1))>=TC
changkuC=sum(buyC(:,1))-TC;
ChangkuC(1)=changkuC;
for j=2:24%星期
for i=1:20%供应商
fanwei=min(round(TC*0.5),randi(round([MaxC(i)*0.5,MaxC(i)])));
if fanwei==0
fanwei=1
end
if sum(buyC(:,j))<=TC||changkuC<=2*TC
buyC(i,j)=randi(fanwei);
if sum(buyC(:,j))>=TC
changkuC=changkuC+sum(buyC(:,j))-TC;
if changkuC>=2*TC
continue
end
end
end
end
if sum(buyC(:,j))<=TC
changkuC=changkuC-(TC-sum(buyC(:,j)));
end
ChangkuC(j)=changkuC;%记录每周仓库的存储数量
end
end
Buy=zeros(50,24);
Buy(A(:,7),:)=buyA;
Buy(B(:,7),:)=buyB;
Buy(C(:,7),:)=buyC;
%数据合并
buy=zeros(402,24)*nan;
buy(A(:,1),:)=buyA;
buy(B(:,1),:)=buyB;
buy(C(:,1),:)=buyC;
%xlswrite('订购方案2',buy);
%%
%模拟转运损耗
fujian2=xlsread("C:\Users\珊瑚宫心海\Desktop\附件2 近5年8家转运商的相关数据.xlsx",'B2:IG9');
yunshu=zeros(5,24);
for j=1:8%第j个转运商
hang=fujian2(j,:);
%sunhao=unique(hang);
%[m,n]=size(sunhao);
for i=1:24
xunzhe=randi(240);
yunshu(j,i)=hang(xunzhe);
end
end
%%
%实施转运
p=1:8;%运输排名
transport=zeros(50,24);
for i=1:24%24周
a=1;%第a行
R=0;%运输量
yunshu2=[p' yunshu(:,i)];
yunshu2(find(yunshu2(:,2)==0),:)=[];%剔除不运输的转运商
[m,n]=size(yunshu2);
yunshu3=sortrows(yunshu2,2);%进行降序
for j=1:50%50家供应商
indexT=yunshu3(a,1);
if Buy(j,i)==0
continue
end
if R<=6000
R=R+Buy(j,i);
transport(j,i)=indexT;
else
a=a+1;
if a>m
a=m;
end
transport(j,i)=yunshu3(a,1);
R=0;
R=R+Buy(j,i);
end
end
end
Transport2=ones(402,24)*nan;
Transport2(wushi(:,1),:)=transport;
%%
%计算损失
Sunshi=zeros(50,24);
for j=1:24%周
for i=1:50%供应商
if transport(i,j)==0
continue
end
Shunshi(i,j)=Buy(i,j)*yunshu(transport(i,j),j);
end
end
Shunshi2=ones(402,24)*nan;
Shunshi2(wushi(:,1),:)=Shunshi;
if length(find(ChangkuA>=0))==24&&length(find(ChangkuB>=0))==24&&length(find(ChangkuC>=0))==24&&sum(sum(Buy))>406080
F(count)=sum(sum(buyA))*1.2+sum(sum(buyB))*1.1+sum(sum(buyC))+0.5*(sum(ChangkuA)+sum(ChangkuB)+sum(ChangkuC))+sum(sum(Buy))*0.5;
count=count+1;
if F(count-1)<f
f=F(count-1);
R2=r2;
Buy2=buy;
Transport3=Transport2;
Shunshi3=Shunshi2;
xlswrite('问题三订单',Buy2);
xlswrite('问题三转运',Transport3);
xlswrite('问题三损耗',Shunshi3);
end
end
Xunhuan
end
%结果画图
x=1:count-1;
F2=sort(F,'descend')
plot(x,F2,'-k*','linewidth',1)
title('\fontname{宋体}有效模拟图');
xlabel('\fontname{宋体}有效模拟次数');;
ylabel('\fontname{宋体}花费成本');
set(gca,'FontName','Times New Roman','fontsize',10.5)
box on
grid on
xlim([1,count-1])
figure
plot(x,F,'-k*','linewidth',1)
title('\fontname{宋体}有效模拟图');
xlabel('\fontname{宋体}有效模拟次数');;
ylabel('\fontname{宋体}花费成本');
set(gca,'FontName','Times New Roman','fontsize',10.5)
box on
grid on
xlim([1,count-1])
第四问
%第四问
clc;clear;
[num,txt,raw]=xlsread("C:\Users\珊瑚宫心海\Desktop\新建 Microsoft Excel 工作表 (2).xlsx");
data=xlsread("C:\Users\珊瑚宫心海\Desktop\附件1 近5年402家供应商的相关数据.xlsx",2);
index=1:402;
num2=[index' num];
num3=sortrows(num2,7);%对排名进行升序
wushi=num3(1:50,:);
%找出卖A的
indexA=find(wushi(:,2)==1.2);
A=wushi(indexA,:);
%找出卖B的
indexB=find(wushi(:,2)==1.1);
B=wushi(indexB,:);
%找出卖C的
indexC=find(wushi(:,2)==1);
C=wushi(indexC,:);
for i=1:16
MaxA(i)=max(data(A(i,1),:));
end
for i=1:14
MaxB(i)=max(data(B(i,1),:));
end
for i=1:20
MaxC(i)=max(data(C(i,1),:));
end
F=[]
Buy2=[];
R2=[];
Transport=[];
Shunshi2=[];
f=1000000000;
count=1;
X=1000%模拟次数
for Xunhuan=1:X
x=rand(1,3);
y=sum(x);
r=x/y;
r2=sort(r,2)
TA=40625*0.6*r2(1);
TB=40625*0.66*r2(2);
TC=40625*0.72*r2(3);
if TA<1
TA=1
end
changkuA=0;
changkuB=0;
changkuC=0;%表示出库材料存量
buyA=zeros(16,24);
buyB=zeros(14,24);
buyC=zeros(20,24);
%%
%购买材料A
for i=1:16
buyA(i,1)=min(round(TC*0.5),randi(round([MaxA(i)*0.5,MaxA(i)])));
end
if sum(buyA(:,1))>=TA
changkuA=sum(buyA(:,1))-TA;
ChangkuA(1)=changkuA;
for j=2:24%星期
for i=1:16%供应商
fanwei=min(round(TC*0.5),randi(round([MaxA(i)*0.5,MaxA(i)])));
if fanwei==0;
fanwei=1
end
if sum(buyA(:,j))<=TA||changkuA<=2*TA
buyA(i,j)=randi(fanwei);
if sum(buyA(:,j))>=TA
changkuA=changkuA+sum(buyA(:,j))-TA;
if changkuA>=2*TA
continue
end
end
end
end
if sum(buyA(:,j))<=TA
changkuA=changkuA-(TA-sum(buyA(:,j)));
end
ChangkuA(j)=changkuA;%记录每周仓库的存储数量
end
end
%%
%购买材料B
for i=1:14
buyB(i,1)=min(round(TB*0.5),randi(round([MaxB(i)*0.5,MaxB(i)])));
end
if sum(buyB(:,1))>=TB
changkuB=sum(buyB(:,1))-TB;
ChangkuB(1)=changkuB;
for j=2:24%星期
for i=1:14%供应商
fanwei=min(round(TC*0.5),randi(round([MaxB(i)*0.5,MaxB(i)])));
if fanwei==0;
fanwei=1;
end
if sum(buyB(:,j))<=TB||changkuB<=2*TB
buyB(i,j)=randi(fanwei);
if sum(buyB(:,j))>=TB
changkuB=changkuB+sum(buyB(:,j))-TB;
if changkuB>=2*TB
continue
end
end
end
end
if sum(buyB(:,j))<=TB
changkuB=changkuB-(TB-sum(buyB(:,j)));
end
ChangkuB(j)=changkuB;%记录每周仓库的存储数量
end
end
%%
%购买材料C
for i=1:20
buyC(i,1)=min(round(TC*0.5),randi(round([MaxC(i)*0.5,MaxC(i)])));
end
if sum(buyC(:,1))>=TC
changkuC=sum(buyC(:,1))-TC;
ChangkuC(1)=changkuC;
for j=2:24%星期
for i=1:20%供应商
fanwei=min(round(TC*0.5),randi(round([MaxC(i)*0.5,MaxC(i)])));
if fanwei==0
fanwei=1
end
if sum(buyC(:,j))<=TC||changkuC<=2*TC
buyC(i,j)=randi(fanwei);
if sum(buyC(:,j))>=TC
changkuC=changkuC+sum(buyC(:,j))-TC;
if changkuC>=2*TC
continue
end
end
end
end
if sum(buyC(:,j))<=TC
changkuC=changkuC-(TC-sum(buyC(:,j)));
end
ChangkuC(j)=changkuC;%记录每周仓库的存储数量
end
end
Buy=zeros(50,24);
Buy(A(:,7),:)=buyA;
Buy(B(:,7),:)=buyB;
Buy(C(:,7),:)=buyC;
%数据合并
buy=zeros(402,24)*nan;
buy(A(:,1),:)=buyA;
buy(B(:,1),:)=buyB;
buy(C(:,1),:)=buyC;
%xlswrite('订购方案2',buy);
%%
%模拟转运损耗
fujian2=xlsread("C:\Users\珊瑚宫心海\Desktop\附件2 近5年8家转运商的相关数据.xlsx",'B2:IG9');
yunshu=zeros(5,24);
for j=1:8%第j个转运商
hang=fujian2(j,:);
%sunhao=unique(hang);
%[m,n]=size(sunhao);
for i=1:24
xunzhe=randi(240);
yunshu(j,i)=hang(xunzhe);
end
end
%%
%实施转运
p=1:8;%运输排名
transport=zeros(50,24);
for i=1:24%24周
a=1;%第a行
R=0;%运输量
yunshu2=[p' yunshu(:,i)];
yunshu2(find(yunshu2(:,2)==0),:)=[];%剔除不运输的转运商
[m,n]=size(yunshu2);
yunshu3=sortrows(yunshu2,2);%进行降序
for j=1:50%50家供应商
indexT=yunshu3(a,1);
if Buy(j,i)==0
continue
end
if R<=6000
R=R+Buy(j,i);
transport(j,i)=indexT;
else
a=a+1;
if a>m
a=m;
end
transport(j,i)=yunshu3(a,1);
R=0;
R=R+Buy(j,i);
end
end
end
Transport2=ones(402,24)*nan;
Transport2(wushi(:,1),:)=transport;
%%
%计算损失
Sunshi=zeros(50,24);
for j=1:24%周
for i=1:50%供应商
if transport(i,j)==0
continue
end
Shunshi(i,j)=Buy(i,j)*yunshu(transport(i,j),j);
end
end
Shunshi2=ones(402,24)*nan;
Shunshi2(wushi(:,1),:)=Shunshi;
if length(find(ChangkuA>=0))==24&&length(find(ChangkuB>=0))==24&&length(find(ChangkuC>=0))==24&&sum(sum(Buy))>702000
F(count)=sum(sum(buyA))*1.2+sum(sum(buyB))*1.1+sum(sum(buyC))+0.5*(sum(ChangkuA)+sum(ChangkuB)+sum(ChangkuC))+sum(sum(Buy))*0.5;
count=count+1;
if F(count-1)<f
f=F(count-1);
R2=r2;
Buy2=buy;
Transport3=Transport2;
Shunshi3=Shunshi2;
xlswrite('问题四订单',Buy2);
xlswrite('问题四转运',Transport3);
xlswrite('问题四损耗',Shunshi3);
end
end
Xunhuan
count
end
%结果画图
x=1:count-1;
F2=sort(F,'descend')
plot(x,F2,'-k*','linewidth',1)
title('\fontname{宋体}问题四有效模拟图');
xlabel('\fontname{宋体}有效模拟次数');;
ylabel('\fontname{宋体}花费成本');
set(gca,'FontName','Times New Roman','fontsize',10.5)
box on
grid on
xlim([1,count-1])
figure
plot(x,F,'-k*','linewidth',1)
title('\fontname{宋体}问题四有效模拟图');
xlabel('\fontname{宋体}有效模拟次数');;
ylabel('\fontname{宋体}花费成本');
set(gca,'FontName','Times New Roman','fontsize',10.5)
box on
grid on
xlim([1,count-1])
绘图
%前五十供应商画图
clc;clear
[num2,txt2,~]=xlsread("C:\Users\珊瑚宫心海\Desktop\新建 Microsoft Excel 工作表 (2).xlsx");
index=1:402;
num3=[index' num2];
num4=sortrows(num3,7);%对排名进行升序
num5=num4(1:50,:);
wushi=sortrows(num5,1);
indexA=find(wushi(:,2)==1.2);
A=wushi(indexA,:);
indexB=find(wushi(:,2)==1.1);
B=wushi(indexB,:);
indexC=find(wushi(:,2)==1);
C=wushi(indexC,:);
%平均每周
a1=A(:,3)./420
b1=B(:,3)./420
c1=C(:,3)./420
%平均每月
a2=A(:,3)./60
b2=B(:,3)./60
c2=C(:,3)./60
%每月画图
plot(A(:,1),a2,'-k*','linewidth',1)
title('\fontname{宋体}材料A每月平均供应量');
xlabel('\fontname{宋体}供应商\fontname{Times New Roman}ID');
ylabel('\fontname{宋体}材料供应量');
set(gca,'FontName','Times New Roman','fontsize',10.5)
box on
grid on
xlim([1,240])
figure
plot(B(:,1),b2,'-k*','linewidth',1)
title('\fontname{宋体}材料B每月平均供应量');
xlabel('\fontname{宋体}供应商\fontname{Times New Roman}ID');;
ylabel('\fontname{宋体}材料供应量');
set(gca,'FontName','Times New Roman','fontsize',10.5)
box on
grid on
xlim([1,240])
figure
plot(C(:,1),c2,'-k*','linewidth',1)
title('\fontname{宋体}材料C每月平均供应量');
xlabel('\fontname{宋体}供应商\fontname{Times New Roman}ID');
ylabel('\fontname{宋体}材料供应量');
set(gca,'FontName','Times New Roman','fontsize',10.5)
box on
grid on
xlim([1,240])
%%
%分离附件1订单材料ABC
clc;clear
[num,txt,~]=xlsread("C:\Users\珊瑚宫心海\Desktop\附件1 近5年402家供应商的相关数据.xlsx",1);
cailiao=ones(402,1);
xunzhaoA = strcmp(txt(2:end,2),'A');%找出A,标记为1
mA=find(xunzhaoA==1);%找出字符串所在的索引
xunzhaoB = strcmp(txt(2:end,2),'B');%找出A,标记为1
mB=find(xunzhaoB==1);%找出字符串所在的索引
xunzhaoC = strcmp(txt(2:end,2),'C');%找出A,标记为1
mC=find(xunzhaoC==1);%找出字符串所在的索引
cailiao(mA)=1.2;
cailiao(mB)=1.1;
cailiao(mC)=1;
indexA=find(cailiao(:,1)==1.2);
A=num(indexA,:);
indexB=find(cailiao(:,1)==1.1);
B=num(indexB,:);
indexC=find(cailiao(:,1)==1);
C=num(indexC,:);
shengchanli=sum(reshape(sum(A),48,5))./0.6+sum(reshape(sum(B),48,5))./0.66+sum(reshape(sum(C),48,5))./0.72;
plot(shengchanli)