1.软件版本

MATLAB2013b

2.本算法理论知识

        库存管理​​系统​​​是一个现代化公司ERP软件中不可或缺的一部分,它的存在对于​​企业​​​的决策层和管理人员来说都是十分重要的。特别是对商品销售企业来说,如何最合理地管理好企业的库存物品具有十分重大的意义,它直接关系到企业的经济利益。所以,库存管理系统应该能够为它的使用者提供足够的信息和高效的查询功能。但是,一直以来人们仍然在使用传统手工的方式管理企业​​库存​​​的各种​​物资​​​和​​设备​​​,显而易见,这种管理方式存在着诸多缺点,如:管理效率低下、容易出错等。此外,随着企业经营的时间越来越长,业务​​范围​​​也会不断扩大,这样将会产生越来越多的数据。这对信息的查询、更新和维护都带来了极大的困难。随着信息科学技术的不断发展,​​计算机​​​技术日渐成熟,,其强大的​​信息​​​管理​​功能​​​已为人们深刻认同和接受,管理信息系统已经进入了现代社会的各个领域并日益发挥着重要的作用。作为典型的信息管理系统​​软件​​,使用计算机对库存信息进行管理具有使用手工管理无法比拟的优势。例如,商品的检索迅速、便于查询、系统更加可靠、管理的商品更多,保密性好,成本低等。这些独有的优点能够极大地提高企业的日常管理效率,也是企业实现现代化管理,逐步与世界接轨的重要前提条件。

3.部分核心程序

% eventdata  reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
PNUM = str2num(get(handles.edit1,'String'));
Ant_Num = str2num(get(handles.edit2,'String'));
Itertions = str2num(get(handles.edit3,'String'));
Alpha = str2num(get(handles.edit4,'String'));
Beta = str2num(get(handles.edit5,'String'));
Rho = str2num(get(handles.edit6,'String'));
Car_Load = str2num(get(handles.edit7,'String'));
Q = str2num(get(handles.edit8,'String'));
gama = str2num(get(handles.edit9,'String'));
see = str2num(get(handles.edit10,'String'));
SEEK1 = str2num(get(handles.edit11,'String'));
SEEK2 = str2num(get(handles.edit12,'String'));

RandStream.setDefaultStream(RandStream('mt19937ar','seed',SEEK1));
Position = 100*rand(PNUM,2);
RandStream.setDefaultStream(RandStream('mt19937ar','seed',SEEK2));
Times = 4*rand(PNUM,1);

D = zeros(PNUM,PNUM);
for i=1:PNUM
for j=1:PNUM
if i~=j
D(i,j) = sqrt((Position(i,1)-Position(j,1))^2+(Position(i,2)-Position(j,2))^2);
else
D(i,j) = 1e-30;
end
D(j,i) = D(i,j);
end
end
U = zeros(PNUM,PNUM);
for i=1:PNUM
for j=1:PNUM
if i~=j
U(i,j) = D(i,1)+D(j,1)-D(i,j);
else
U(i,j) = 1e-30;
end
U(j,i) = U(i,j);
end
end
Carrier = 0;
ED = 1./D;
Infor_cube = ones(PNUM,PNUM);
%存储并记录路径的生成
Infor_Tabu = zeros(Ant_Num,PNUM+20);
COUNT = 1;
%各代最佳路线
Best_Road = [Itertions,PNUM+20];
%各代最佳路线的长度
Best_Length= inf.*ones(Itertions,1);
Avg_Length = zeros(Itertions,1);

%开始循环
while COUNT<=Itertions
COUNT
Infor_Tabu(:,1) = randint(Ant_Num,1,[1,1]);
for i=1:Ant_Num
VISITDAT = Infor_Tabu(i,:);
VISITDAT = VISITDAT(VISITDAT>0);
VISITDAT_ = setdiff(1:PNUM,VISITDAT);
VISIT_Tmp = length(VISITDAT_);
j = 1;
while j <= PNUM
if ~isempty(VISITDAT_)
for k=1:length(VISITDAT_)
x(k) = (Infor_cube(VISITDAT(end),VISITDAT_(k))^Alpha)*(ED(VISITDAT(end),VISITDAT_(k))^Beta)*(U(VISITDAT(end),VISITDAT_(k))^gama);
end
Weights=rand(1,1);
if Weights < see
Select = find(max(x));
else
x = x/(sum(x));
%按累积概论进行判断
Xadd = cumsum(x);
Select = find(Xadd>=rand);
end
if isempty(Select)==1
Select = 1;
Carrier = Carrier + Times(Select);
else
Carrier = Carrier + Times(VISITDAT_(Select(1)));
end
if Carrier>Car_Load
Select = 1;
j = j-1;
Carrier = 0;
Infor_Tabu(i,length(VISITDAT)+1) = Select(1);
else
Infor_Tabu(i,length(VISITDAT)+1) = VISITDAT_(Select(1));
end
end
VISITDAT = Infor_Tabu(i,:);
VISITDAT = VISITDAT(VISITDAT>0);
VISITDAT_ = setdiff(1:PNUM,VISITDAT);
x = [];
if VISITDAT(end) ~= 1
Infor_Tabu(i,1:(length(VISITDAT)+1))=[VISITDAT,1];
end
j = j + 1;
end
Carrier=0;
end
%记录本代各种参数
L = zeros(Ant_Num,1);
for i=1:Ant_Num
Infor_Tabu_tmps = Infor_Tabu(i,:);
R = Infor_Tabu_tmps(Infor_Tabu_tmps>0);
for j=1:(length(R)-1)
L(i) = L(i) + D(R(j),R(j+1));
end
end
Best_Length(COUNT) = min(L);
pos = find(L==Best_Length(COUNT));
Best_Road(COUNT,1:length(Infor_Tabu(pos(1),:)))=Infor_Tabu(pos(1),:);
%最优解进行更新
select = find(Best_Road(COUNT,:)==1);
FF = [];
FF2 = 0;
for I1 = 1:(length(select)-1)
Best_Road2 = Best_Road(COUNT,select(I1):select(I1+1));
Best_Road_len = length(Best_Road2);
T = zeros((length(select)-1),1);
for I4=1:(Best_Road_len-1)
T(I1) = T(I1) + D(Best_Road2(I4),Best_Road2(I4+1));
end
for I2 = 2:(Best_Road_len-1)
for I3=(I2+1):(Best_Road_len-1)
Best_Road3 = Best_Road2;
Best_Road31 = Best_Road3(I2);
Best_Road32 = Best_Road3(I3);
Best_Road3(I2) = Best_Road32;
Best_Road3(I3) = Best_Road31;
TT = zeros(1);
for I4=1:(Best_Road_len-1)
TT = TT + D(Best_Road3(I4),Best_Road3(I4+1));
end
if TT<T(I1)
T(I1) = TT;
Best_Road2 = Best_Road3;
end
end
end
if I1 >= 2
Best_Road2=Best_Road2(2:Best_Road_len);
end
FF = [FF,Best_Road2];
FF2 = FF2+T(I1);
end
Best_Length(COUNT) = FF2;
Best_Road(COUNT,1:length(FF)) = FF;
FF = [];
FF2 = 0;
Avg_Length(COUNT) = mean(L);
COUNT = COUNT+1;
%更新信息素
Delta_Infor = zeros(PNUM,PNUM);
for i=1:Ant_Num
Infor_Tabu_tmps = Infor_Tabu(i,:);
R = Infor_Tabu_tmps(Infor_Tabu_tmps>0);
for j=1:(length(R)-1)
Delta_Infor(R(j),R(j+1))=Delta_Infor(R(j),R(j+1))+Q/L(i);
end
end
Infor_cube = (1-Rho).*Infor_cube+Delta_Infor;
%禁忌表清零
Infor_Tabu = zeros(Ant_Num,PNUM);
Carrier = 0;
end

Pos = find(Best_Length==min(Best_Length));
best_route = Best_Road(Pos(1),:);
best_length = Best_Length(Pos(1));
best_route = best_route(best_route>0);

best_route
best_length

axes(handles.axes1);
plot([Position(best_route,1)],[Position(best_route,2)],'ro');
axis square;

axes(handles.axes2);
plot([Position(best_route,1)],[Position(best_route,2)],'rs');
hold on
plot([Position(best_route,1)],[Position(best_route,2)],'b-');
axis square;

axes(handles.axes3);
plot(Best_Length,'b-o');
hold on
plot(Avg_Length,'r-o');
grid on;
legend('最短距离','平均距离');

4.仿真结果

【禁忌搜索】基于禁忌搜索算法实现经典VRP问题的matlab仿真_VRP

仿真效果如下所示:

【禁忌搜索】基于禁忌搜索算法实现经典VRP问题的matlab仿真_禁忌搜索_02

A06-12