优化选址基于matlab蚁群算法求解电动汽车充电站与换电站选址优化问题含Matlab源码 1182期
Posted 紫极神光
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了优化选址基于matlab蚁群算法求解电动汽车充电站与换电站选址优化问题含Matlab源码 1182期相关的知识,希望对你有一定的参考价值。
一、简介
1 概要
模拟蚂蚁觅食行为(最短路径原理)设计的算法。讲蚂蚁群觅食的特点抽象出来转化成数学描述。
• 蚁群算法(Ant Colony Algorithm, ACA)由Marco Dorigo于1992年在他的博士论文中首次提出。
• 蚂蚁在寻找食物源时,会在其经过的路径上释放一种信息素,并能够感知其它蚂蚁释放的信息素。信息素浓度的大小表征路径的远近,信息素浓度越高,表示对应的路径距离越短。
• 通常,蚂蚁会以较大的概率优先选择信息素浓度较高的路径,并释放 一定量的信息素,以增强该条路径上的信息素浓度,这样,会形成一个正反馈。最终,蚂蚁能够找到一条从巢穴到食物源的最佳路径,即距离最短。
• 生物学家同时发现,路径上的信息素浓度会随着时间的推进而逐渐衰减。
• 将蚁群算法应用于解决优化问题,其基本思路为:用蚂蚁的行走路径表示待优化问题的可行解,整个蚂蚁群体的所有路径构成待优化问题的解空间。路径较短的蚂蚁释放的信息素量较多,随着时间的推进,较短 的路径上累积的信息素浓度逐渐增高,选择该路径的蚂蚁个数也愈来愈多。最终,整个蚂蚁会在正反馈的作用下集中到最佳的路径上,此时对应的便是待优化问题的最优解。
类比GA(遗传算法)的交叉、选择、变异,PSO(粒子群算法)的个体、群体极值优化,蚁群算法也有自己的优化策略:正反馈的信息机制、信息素浓度的更新、蚂蚁对能够访问的路径的筛选。
2 基本思想
蚁群算法的基本原理来源于自然界蚂蚁觅食的最短路径原理。根据昆虫学家的观察,发现自然界的蚂蚁虽然视觉不发达,但它可以在没有任何提示的情况下找到从食物源到巢穴的最短路径,并且能在环境发生变化(如原有路径上有了障碍物)后,自适应地搜索新的最佳路径。蚂蚁是如何做到这一点的呢?
原来,蚂蚁在寻找食物源时,能在其走过的路径上放一种蚂蚁特有的分泌物-信息 素,也可称为信息素,使得一定范围内的其他蚂蚁能够察觉到并由此影响它们以后的行为。当一些路径上通过的蚂蚁越来越多时,其留下的信息素也越来越多,以致信息素强度增大(当然,随时间的推移会逐渐减弱,所以蚂蚁选择该路径的概率也越高,从而更增加了该路径的信息素强度,这种选择过程被称之为蚂蚁的自催化行为。 由于其原理是一种正反馈机制,因此,也可将蚂蚁王国理解为所谓的增强型学习系统。 这里我们用一个图来说明蚂蚁觅食的最短路径选择原理,如图所示。在中,假设A点是蚂蚁的巢穴,B点是食物,A、B两点间有一个障碍物,那么此时从A点到B点 的蚂蚁就必须决定往左走还是往右走,而从B点到A点的蚂蚁也必须决定选择走哪条路径。 这种决定会受到各条路径上以往蚂蚁留下的信息素浓度(即残留信息素浓度)的影响。 如果往 右走的路径上的信息素浓度比较大,那么右边的路径被蚂蚁选中的可能性也就大一些。但对于第一批探路的蚂蚁,因为没有信息素的影响或影响比较小,所以它们选择向左或者向右的可能性是一样的,正如图所示的那样。随着觅食过程的进行,各条道路上信息 素的强度开始出现变化,有的线路强,有的 线路弱。现以从A点到B点的蚂蚁为例说明(从B点到 A点的蚂蚁,过程也基本是一样的)随后过程的变化。由于路径 ADB比路径ACB要短,因此选择ADB路径的第一只蚂蚁要比选择ACB的第一只蚂蚁早到达B点。此时,从B点向 A点看,路径BDA A上的信息素浓度要比路径BCA上的信息素浓度大。因此从下一时刻开始,从B点到A 点的蚂蚁,它们选择 BDA路径的可能性要比选择BCA路径的可能性就大些,从而使ABDA路线上的信息素进一步增强,于是依D赖信息素强度选择路径的蚂蚁逐渐偏向于选择路径 ADB,如图所示。随着时间的推移,几乎所有的蚂蚁都会选择路径 ADB(或 BDA)搬运食物,而我们同时也会发现:ADB路径也正是事实上的最短路径。这种蚁群寻径的原理可简单理解为:对于单个的蚂蚁,它并没有要寻找最短路径的主观上的故意;但对于整个蚁群系统,它们又确实达到了寻找到最短路径的观上的效果。 在自然界中,蚁群的这种寻找路径的过程表现为一种正反馈的过程,“蚁群算法”就是模拟 生物学上蚂蚁群觅食寻找最短路径的原理衍生出来的。例如,我们把只具备了简单功能的工 作单元视为“蚂蚁”,那么上述寻找路径的过程可以用于解释蚁群算法中人工蚁群的寻优过程。 这也就是蚁群算法的基本思想。
3 算法设计的流程
这里以TSP问题为例,算法设计的流程如下:
步骤1:对相关参数进行初始化,包括蚁群规模、信息素因子、启发函数因子、信息素挥发因子、信息素常数、最大迭代次数等,以及将数据读入程序,并进行预处理:比如将城市的坐标信息转换为城市间的距离矩阵。
步骤2:随机将蚂蚁放于不同出发点,对每个蚂蚁计算其下个访问城市,直到有蚂蚁访问完所有城市。
步骤3:计算各蚂蚁经过的路径长度Lk,记录当前迭代次数最优解,同时对路径上的信息素浓度进行更新。
步骤4:判断是否达到最大迭代次数,若否,返回步骤2;是,结束程序。
步骤5:输出结果,并根据需要输出寻优过程中的相关指标,如运行时间、收敛迭代次数等。
4 数学模型
二、源代码
function varargout = antinface(varargin)
% ANTINFACE M-file for antinface.fig
% ANTINFACE, by itself, creates a new ANTINFACE or raises the existing
% singleton*.
%
% H = ANTINFACE returns the handle to a new ANTINFACE or the handle to
% the existing singleton*.
%
% ANTINFACE('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in ANTINFACE.M with the given input arguments.
%
% ANTINFACE('Property','Value',...) creates a new ANTINFACE or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before antinface_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to antinface_OpeningFcn via varargin.
%
% *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one
% instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES
% Edit the above text to modify the response to help antinface
% Last Modified by GUIDE v2.5 02-Jun-2021 10:29:35
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @antinface_OpeningFcn, ...
'gui_OutputFcn', @antinface_OutputFcn, ...
'gui_LayoutFcn', [] , ...
'gui_Callback', []);
if nargin && ischar(varargin{1})
gui_State.gui_Callback = str2func(varargin{1});
end
if nargout
[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT
% --- Executes just before antinface is made visible.
function antinface_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user state (see GUIDATA)
% varargin command line arguments to antinface (see VARARGIN)
% Choose default command line output for antinface
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
h=waitbar(0,'请等待......');
for i=1:100
waitbar(i/100);
end
delete(h);
% UIWAIT makes antinface wait for user response (see UIRESUME)
% uiwait(handles.handles);
% --- Outputs from this function are returned to the command line.
function varargout = antinface_OutputFcn(hObject, eventdata, handles)
% varargout cell array for returning output args (see VARARGOUT);
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user state (see GUIDATA)
% Get default command line output from handles structure
varargout{1} = handles.output;
function edit_initao_Callback(hObject, eventdata, handles)
% hObject handle to edit_initao (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user state (see GUIDATA)
% Hints: get(hObject,'String') returns contents of edit_initao as text
% str2double(get(hObject,'String')) returns contents of edit_initao as a double
% --- Executes during object creation, after setting all properties.
function edit_initao_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit_initao (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function edit_q_Callback(hObject, eventdata, handles)
% hObject handle to edit_q (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user state (see GUIDATA)
% Hints: get(hObject,'String') returns contents of edit_q as text
% str2double(get(hObject,'String')) returns contents of edit_q as a double
% --- Executes during object creation, after setting all properties.
function edit_q_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit_q (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function edit_alpha_Callback(hObject, eventdata, handles)
% hObject handle to edit_alpha (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user state (see GUIDATA)
% Hints: get(hObject,'String') returns contents of edit_alpha as text
% str2double(get(hObject,'String')) returns contents of edit_alpha as a double
% --- Executes during object creation, after setting all properties.
function edit_alpha_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit_alpha (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function edit_rou_Callback(hObject, eventdata, handles)
% hObject handle to edit_rou (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user state (see GUIDATA)
% Hints: get(hObject,'String') returns contents of edit_rou as text
% str2double(get(hObject,'String')) returns contents of edit_rou as a double
% --- Executes during object creation, after setting all properties.
function edit_rou_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit_rou (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function edit_beta_Callback(hObject, eventdata, handles)
% hObject handle to edit_beta (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user state (see GUIDATA)
% Hints: get(hObject,'String') returns contents of edit_beta as text
% str2double(get(hObject,'String')) returns contents of edit_beta as a double
% --- Executes during object creation, after setting all properties.
function edit_beta_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit_beta (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function edit_ncmax_Callback(hObject, eventdata, handles)
% hObject handle to edit_ncmax (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user state (see GUIDATA)
% Hints: get(hObject,'String') returns contents of edit_ncmax as text
% str2double(get(hObject,'String')) returns contents of edit_ncmax as a double
% --- Executes during object creation, after setting all properties.
function edit_ncmax_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit_ncmax (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function edit_antsum_Callback(hObject, eventdata, handles)
% hObject handle to edit_antsum (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user state (see GUIDATA)
% Hints: get(hObject,'String') returns contents of edit_antsum as text
% str2double(get(hObject,'String')) returns contents of edit_antsum as a double
% --- Executes during object creation, after setting all properties.
function edit_antsum_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit_antsum (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
三、运行结果
四、备注
版本:2014a
以上是关于优化选址基于matlab蚁群算法求解电动汽车充电站与换电站选址优化问题含Matlab源码 1182期的主要内容,如果未能解决你的问题,请参考以下文章
优化选址基于matlab改进的粒子群算法求解充电桩选址优化问题含Matlab源码 1964期
优化求址基于matlab遗传算法求解变电站选址优化问题含Matlab源码 YC006期
优化充电基于matlab遗传算法求解电动汽车充电统一管理优化问题(含负荷功率曲线对比图及充电计划)含Matlab源码 2300期
优化充电基于matlab遗传算法求解电动汽车充电统一管理优化问题(含负荷功率曲线对比图及充电计划)含Matlab源码 2300期