%说明:本程序为frankwolfe算法,通过输入总流量、在路网情况已知时配流并求出费用值。
clear all
clc
disp('========================================================================');
disp(' 《frankwolfe算法》');
disp('运行环境:MATLAB 8.3.0.532 ');
disp('制 作 人:兰州交通大学 刘志祥');
disp('Q Q:531548824');
disp('=========================================================================');
%% 定义变量及常数
syms x1 x2 x3 x4 x5 x6 x7 x8 x9 lambda real
%%以下9行为通用模块
% Q=input('总流量=');%总流量
% numf=input('路径总数=');
% numx=input('路段总数=');
% fid=fopen('E:\MATLAB\编程书源代码\自己的算法\FW算法计算过程.txt','w');%设置运行结果输出文件
% x=[x1,x2,x3,x4,x5,x6,x7,x8,x9];
% x=x(1,1:numx)
% W=input('自由阻抗矩阵=');
% cap=input('走行流量系数=');
% Mxf=input('路径构成矩阵=');
Q=200 %总流量
numf=3;
numx=3;
fid=fopen('E:\MATLAB\编程书源代码\自己的算法\FW算法计算过程.txt','w');%设置运行结果输出文件
x=[x1,x2,x3,x4,x5,x6,x7,x8,x9];
x=x(1,1:numx);
W=[5 10 15];
cap=[0.1 0.025 0.025];
Mxf=[1 0 0;0 1 0;0 0 1];
%% step_初始化
X0=zeros(1,numx);
t=zeros(1,numx);
t=W+cap.*x; %路段走行时间函数
tt=t;
disp('路径阻抗函数:');
disp(t');
t0=subs(t,x,X0);
ft=(Mxf*t0')'; %路径的走行时间初值
N=30; %最大迭代次数
cont=0;
[Min,index]=min(t0);
X1=Mxf(index,:).*Q; %全有全无法为最短路径上的路段分配流量
fprintf(fid,'\r\n=============================================\r\n');
for i=1:N
cont=cont+1;
Y1=zeros(numx); %辅助路段流
t=W+cap.*X1; %路段时间
ft=(Mxf*t')'; %路径时间
fprintf(fid,' <第%d次的计算结果>\r\n',i);
%% step2_更新阻抗
fprintf(fid,'阻 抗 值:');
for(j=1:numf)
fprintf(fid,'%7.2f ',ft(1,j));
end
fprintf(fid,'\r\n');
%% step3_确定迭代方向
[Min,index]=min(ft);
fprintf(fid,'辅助流量:');
Y1=Mxf(index,:).*Q; %全有全无法求辅助流量
for(k=1:numx)
fprintf(fid,'%7.2f ',Y1(1,k));
end
fprintf(fid,'\r\n');
S=Y1-X1; %搜索方向 <
clear all
clc
disp('========================================================================');
disp(' 《frankwolfe算法》');
disp('运行环境:MATLAB 8.3.0.532 ');
disp('制 作 人:兰州交通大学 刘志祥');
disp('Q Q:531548824');
disp('=========================================================================');
%% 定义变量及常数
syms x1 x2 x3 x4 x5 x6 x7 x8 x9 lambda real
%%以下9行为通用模块
% Q=input('总流量=');%总流量
% numf=input('路径总数=');
% numx=input('路段总数=');
% fid=fopen('E:\MATLAB\编程书源代码\自己的算法\FW算法计算过程.txt','w');%设置运行结果输出文件
% x=[x1,x2,x3,x4,x5,x6,x7,x8,x9];
% x=x(1,1:numx)
% W=input('自由阻抗矩阵=');
% cap=input('走行流量系数=');
% Mxf=input('路径构成矩阵=');
Q=200 %总流量
numf=3;
numx=3;
fid=fopen('E:\MATLAB\编程书源代码\自己的算法\FW算法计算过程.txt','w');%设置运行结果输出文件
x=[x1,x2,x3,x4,x5,x6,x7,x8,x9];
x=x(1,1:numx);
W=[5 10 15];
cap=[0.1 0.025 0.025];
Mxf=[1 0 0;0 1 0;0 0 1];
%% step_初始化
X0=zeros(1,numx);
t=zeros(1,numx);
t=W+cap.*x; %路段走行时间函数
tt=t;
disp('路径阻抗函数:');
disp(t');
t0=subs(t,x,X0);
ft=(Mxf*t0')'; %路径的走行时间初值
N=30; %最大迭代次数
cont=0;
[Min,index]=min(t0);
X1=Mxf(index,:).*Q; %全有全无法为最短路径上的路段分配流量
fprintf(fid,'\r\n=============================================\r\n');
for i=1:N
cont=cont+1;
Y1=zeros(numx); %辅助路段流
t=W+cap.*X1; %路段时间
ft=(Mxf*t')'; %路径时间
fprintf(fid,' <第%d次的计算结果>\r\n',i);
%% step2_更新阻抗
fprintf(fid,'阻 抗 值:');
for(j=1:numf)
fprintf(fid,'%7.2f ',ft(1,j));
end
fprintf(fid,'\r\n');
%% step3_确定迭代方向
[Min,index]=min(ft);
fprintf(fid,'辅助流量:');
Y1=Mxf(index,:).*Q; %全有全无法求辅助流量
for(k=1:numx)
fprintf(fid,'%7.2f ',Y1(1,k));
end
fprintf(fid,'\r\n');
S=Y1-X1; %搜索方向 <