1、例总流量为100,走行函数为: 模型求解的Matlab 源码:syms lambda ;tt =0 0 0 ;xx = 0 0 0 0 0 ;t1 = 4 + (0.6/40)*xx(1,1);t2 =6 + (0.9/40) *xx(1,2);t3 = 2 + (0.3/60) *xx(1,3);t4 = 5 + (0.75/40) *xx(1,4) ;t5 = 3 + (0.45/40) *xx(1,5) ;Q = 100;N=8 ; % 迭代次数 ,本例只设置最大迭代次数。也可另外设置收敛条件 tt(1,1)= t1 +t4 ; tt(1,2) = t2 + t5 ; tt(1,3) =
2、t1+ t3 +t5 ; y = 0 0 0; %置初值Min = 50000; for j = 1 : 3 if tt(1 ,j) Min %计算最小走行时间的路段 ,用全有全无法分配流量 Min = tt(1,j); index = j; end end % y(1,index) = Q; if index =1 xx(1,1)= Q; xx(1,4)=Q; elseif index =2 xx(1,2)= Q; xx(1,5)=Q; else xx(1,1)= Q; xx(1,3)=Q; xx(1,5)=Q; end for i =1 :N y = 0 0 0 0 0 ; t1 = 4
3、+ (0.6/40)*xx(1,1);t2 =6 + (0.9/40) *xx(1,2);t3 = 2 + (0.3/60) *xx(1,3);t4 = 5 + (0.75/40) *xx(1,4) ;t5 = 3 + (0.45/40) *xx(1,5) ; tt(1,1)= t1 +t4 ; tt(1,2) = t2 + t5 ; tt(1,3) =t1+ t3 +t5 ;fprintf(第 %d 次迭代的 路径时间值: , i); tt Min = 50000; for j = 1 : 3 if tt(1 ,j) 0 & lambda1(m,1) 1 & isreal(lambda1(m,1) lambda2 =lambda1(m,1); endendend fprintf(第 %d 次迭代的最优步长值是: , i);lambda2fprintf(第 %d 次迭代的路段流量值是: , i);xx = xx + lambda2*(y - xx ) % 得到下一步的流量值, 且进行下一次迭代end