[Layout optimization] Matlab source code analysis of bus scheduling problem based on genetic algorithm

1. Introduction

1 Background analysis of the bus scheduling system.
As the construction of urban traffic facilities lags behind the growth rate of traffic demand, urban traffic conditions are deteriorating day by day. Traffic jams occur to varying degrees at major traffic intersections and some roads with concentrated traffic. The problem has become a bottleneck restricting urban development.
The urban transportation system is an open and complex system composed of urban road networks, vehicles and management systems. There are many ways to solve urban traffic. For example, the current number restriction measures are one of the better methods. Through the number restriction operation, the number of people who take the bus on foot increases, so how to solve the problem of bus scheduling is particularly necessary. Reasonably solving the problem of public transportation scheduling system is a complex problem. It needs to consider complex factors such as people, vehicles, roads, etc. Therefore, it is necessary to use high-tech technical methods to better solve urban road traffic problems. Nowadays, intelligent transportation systems (ITS ) Has become one of the important ways to solve this problem.
The intelligent scheduling of operating vehicles is one of the typical problems that need to be solved in the intelligent dispatch of public transportation vehicles. In the context of Intelligent Transportation System (ITS), the formulation of bus schedules is the core content of urban public transportation dispatch and is the daily command of public transportation dispatch The important basis for the normal operation of vehicles is also the basic basis for the work of bus dispatchers and drivers. A reasonable bus schedule can help bus companies improve vehicle utilization efficiency, reduce operating costs and reduce passenger waiting time to improve service quality.
2 Vehicle driving model
Insert picture description here
3 Passenger boarding and disembarking model
Insert picture description here
4 Application steps of
genetic algorithm Genetic algorithm GA is a global optimization method based on evolution and genetic theory.
The basic steps of simple genetic algorithm to solve the problem are as follows:
(1) Initialization: randomly generate N individuals as the initial population P(0), which is a set of feasible solutions for the objective function. Set the evolution algebra counter to zero and set the maximum evolution algebra iter_max;
(2) Individual evaluation: Substitute the initial population into the objective function, and calculate the fitness of each population in the current population according to the fitness function;
(3) Judgment of termination conditions: Given termination conditions, determine whether the algorithm satisfies the termination conditions, and if so, go to (8);
(4) Selection operation: perform a selection operation on the initial group, good individuals are copied in large numbers, and poor quality Individuals are rarely copied or even eliminated;
(5) Crossover calculation: Crossover calculation is performed based on crossover probability;
(6) Mutation calculation: Crossover calculation is performed based on mutation probability;
(7) Group P(t) undergoes selection calculation and crossover calculation After the mutation operation, the next-generation population P(t+1) composed of N new individuals is obtained, then go to (2), otherwise go to (4);
(8) Continuous evolution will eventually get the objective function, adaptation The individual with the highest degree is output as the optimal solution or satisfactory solution of the problem, and the calculation is terminated.
Insert picture description here
Insert picture description here

Second, the source code

% 产生t(i)序列
clc,clear,close all
warning off
Tmin = 1;   % 表示相邻车辆间发车间隔的最小值(min)
Tmax = 10;  % 表示相邻车辆间发车间隔的最大值(min)
delta = 4;  % 表示相邻车辆发车间隔之差的限制值
m = 500;    % 表示总的发车次数(车次)
a = randi(10);  % t(1)第一个值的取值范围设定为1-10之间随机取值
t(1) = a;       % 赋值
maxt = 960;    % t(i)的最大值
% Loop
for i=2:m
    flag = 1;       % 标志变量
    while flag == 1
        % Tmin< t(i)-t(i-1) < Tmax
        a1 = randi(9);
        if a1>Tmin+2 && i==2
            t(i)=t(i-1)+a1; % Tmin < t(i)-t(i-1) < Tmax
            flag = 0;   % i 时间点计算完毕
        elseif a1>Tmin+2 && i>2  % |t(i+1)-2*t(i)+t(i-1)|<delta 
            t(i)=t(i-1)+a1; % Tmin < t(i)-t(i-1) < Tmax
            if abs( (t(i)-t(i-1)) -(t(i-1)-t(i-2)) )<delta
                flag = 0;  % i 时间点计算完毕
            end
        end
    end
    function flag=test(code)
% code       output: 染色体的编码值
global Tmin Tmax delta
x=code; %先解码
flag=1;
for i=3:length(x)
    else
        flag=0;
    end
end    
% 产生t(i)序列
function ret=Mutation(pmutation,lenchrom,chrom,sizepop,num,maxgen)
% 本函数完成变异操作
% pcorss                input  : 变异概率
% lenchrom              input  : 染色体长度
% chrom     input  : 染色体群
% sizepop               input  : 种群规模
% opts                  input  : 变异方法的选择
% pop                   input  : 当前种群的进化代数和最大的进化代数信息
% bound                 input  : 每个个体的上届和下届
% maxgen                input  :最大迭代次数
% num                   input  : 当前迭代次数
% ret                   output : 变异后的染色体
function t = pop_meet_conditions(maxt)
global Tmin Tmax delta m tt PP Q cita
% 输入变量说明:
% Tmin = 1;   % 表示相邻车辆间发车间隔的最小值(min)
% Tmax = 10;  % 表示相邻车辆间发车间隔的最大值(min)
% delta = 4;  % 表示相邻车辆发车间隔之差的限制值
% m = 500;    % 表示总的发车次数(车次)
% maxt = 960;    % t(i)的最大值

% 输出变量说明:
% t为满足条件的个体

a = randi(10);  % t(1)第一个值的取值范围设定为1-10之间随机取值
t(1) = a;       % 赋值

flag = 1;       % 标志变量
% Loop
while flag==1
    
    for i=2:m
        flag = 1;       % 标志变量
        while flag == 1
            % Tmin< t(i)-t(i-1) < Tmax
            a1 = randi(9);
            if a1>Tmin+2 && i==2
                t(i)=t(i-1)+a1; % Tmin < t(i)-t(i-1) < Tmax
                flag = 0;   % i 时间点计算完毕
            elseif a1>Tmin+2 && i>2  % |t(i+1)-2*t(i)+t(i-1)|<delta 
                t(i)=t(i-1)+a1; % Tmin < t(i)-t(i-1) < Tmax
                if abs( (t(i)-t(i-1)) -(t(i-1)-t(i-2)) )<delta
                    flag = 0;  % i 时间点计算完毕
                end
            end
        end
    end 

Complete code or write on behalf of adding QQ1575304183

Past review>>>>>>

[Layout optimization] Matlab source code based on particle swarm optimization algorithm

[Optimized layout] Matlab source code for optimal layout of charging station based on particle swarm algorithm

[] Layout optimization artificial fish-based layout optimization matlab source

[Layout] Optimization optimize wireless sensor network (WSN) algorithm based Sparrow covered matlab source

[] Optimization solution based on genetic algorithm optimization of vehicle headway matlab source

[Knapsack problem] Matlab source code for solving knapsack problem based on particle swarm

[Knapsack problem] based on genetic algorithm to solve the multi-knapsack problem matlab source code

[Layout optimization] Solving power load distribution matlab source code based on differential evolution algorithm

[Path planning] based on genetic algorithm to solve the island material supply problem matlab source code

Guess you like

Origin blog.csdn.net/qq_34763204/article/details/113721262