✅作者简介:热爱科研的Matlab仿真开发者,擅长数据处理、建模仿真、程序设计、完整代码获取、论文复现及科研仿真。
🍎 往期回顾关注个人主页:Matlab科研工作室
👇 关注我领取海量matlab电子书和数学建模资料
🍊个人信条:格物致知,完整Matlab代码获取及仿真咨询内容私信。
🔥 内容介绍
这段代码是 2D 环境下的双向 RRT(Bi-RRT)路径规划实现,核心逻辑是通过两棵树(分别从起点和终点生长)快速探索构型空间,最终找到一条无碰撞路径。代码结构简洁,模块化程度高,下面从 核心功能、代码解析、关键细节 三方面展开说明:
一、核心功能总览
• 环境:2D 平面构型空间(范围 [0,0]~[100,100]),支持自定义障碍物(通过 make2Dobstacles() 创建)。
• 算法:双向 RRT(Bi-RRT),通过两棵树(G1 从起点生长,G2 从终点生长)双向探索,比单向 RRT 收敛更快。
• 目标:找到从起点 (0,0) 到终点 (80,80) 的无碰撞路径,并可视化展示。
2. 算法优化点(代码隐含的设计)
• 双向探索:比单向 RRT 收敛更快,因为两棵树同时向对方生长,搜索范围更小。
• 目标偏向采样:通过 mi 参数控制,减少随机采样的盲目性,加速两棵树相遇。
• 碰撞检测:每次扩展节点时都会检查新边与障碍物是否碰撞,确保路径无碰撞。
3. 可能的调试方向
• 若未找到路径:可增大 maxNodeNum(如 2000)、减小 deltaQ(提高探索精度)、调整 mi(增加目标偏向概率)或优化障碍物布局。
• 若可视化异常:检查 plotRRTpath 方法是否正确提取路径(通过父节点回溯),确保 Node 类存储了父节点索引。
• 若碰撞检测失效:检查 make2Dobstacles() 的输出格式是否与 RRT 类的碰撞检测函数兼容。
⛳️ 运行结果
📣 部分代码
%be expressed using either vertices or linear in/equalities, according to
%the input scheme,
%
%
% I = intersectionHull('vert', V1, 'lcon', A2,b2, 'lcon', A3,b3,Aeq3,,beq3,...)
%
%The arguments specifying different polyhedra are separated using labels
%'vert' and 'lcon'. The label 'vert' signifies that an input polyhedron will
%be expressed using vertices and is to be followed by any string of input arguments
%accepted by vert2lcon(). The label 'lcon' signifies that an input polyhedron will
%be expressed using linear constraints and is to be followed by any string of
%input arguments accepted by lcon2vert().
%
%The output, I, is a struct containing fields
%
% I.vert: A matrix whose rows are the vertices of the polyhedron formed from
% the intersection.
% I.lcon: The quadruplet of linear constraint data {A,b,Aeq,beq}
% describing the polyhedral intersection.
%
%EXAMPLE 1: This example computes the intersection of a unit square and an
%oblique 2D line segment, both expressed in terms of their vertices.
%
% V1=dec2bin(0:2^2-1,2)-'0'; %vertices of unit square
%
% V2=[1,1;0,-1]; %vertices of 2D line segment
%
% I=intersectionHull('vert',V1,'vert',V2); %compute intersection
%
%The intersection is another line segment with vertices
%
% >> I.vert
%
% ans =
%
% 0.5000 0
% 1.0000 1.0000
%
%EXAMPLE 2: This example computes the intersection of a unit cube, expressed in
%terms of its vertices, and an infinite oblique 3D line, expressed in terms of linear equalities.
%Note that the line is an unbounded polyhedron. This is okay, since we know in advance
%that the final polyhedron formed from the intersection is bounded.
%
% V=dec2bin(0:2^3-1,3)-'0'; %vertices of unit cube
%
% Aeq=[1 -1 0; 0 1 -1]; beq=[0;0]; %oblique line in 3D
%
% I=intersectionHull('vert',V,'lcon',[],[],Aeq,beq); %compute intersection
%
%Once again, the intersection is a line segment. Its vertices are
%
% >> I.vert %vertices of line segment of intersection
%
% ans =
%
% 0.0000 0.0000 0.0000
% 1.0000 1.0000 1.0000
%%%%begin parsing
if isnumeric(varargin{1})
TOL=varargin{1};
varargin(1)=[];
else
TOL=[];
end
N=length(varargin);
idxType = [find(cellfun(@ischar,varargin)),N+1];
L=length(idxType)-1;
S(L).type=[];
S(L).args={};
S(L).A=[];
S(L).b=[];
S(L).Aeq=[];
S(L).beq=[];
for i=1:L
j=idxType(i);
k=idxType(i+1);
S(i).type=varargin{j};
S(i).args=varargin(j+1:k-1);
if isempty(S(i).args)
error 'Syntax error - arguments missing'
end
lcon=cell(1,4);
switch S(i).type
case 'vert'
[lcon{1:4}] = vert2lcon(S(i).args{:});
case 'lcon'
lcon(1:k-j-1) = S(i).args;
case 'qlcon' %deliberately undocumented - no point in using this
lcon(1:k-j-1) = S(i).args(2:end);
otherwise
error(['Unrecognized representation label of polyhedron ' num2str(i)]);
end
[S(i).A, S(i).b, S(i).Aeq, S(i).beq] = deal(lcon{:});
end
%%%%end parsing
A=vertcat(S.A);
b=vertcat(S.b);
Aeq=vertcat(S.Aeq);
beq=vertcat(S.beq);
[V,nr,nre]=lcon2vert(A,b,Aeq,beq,TOL);
I.vert=V;
I.lcon={A(nr,:),b(nr,:), Aeq(nre,:),beq(nre,:)};
🔗 参考文献
🏆团队擅长辅导定制多种科研领域MATLAB仿真,助力科研梦:
🌈 各类智能优化算法改进及应用
生产调度、经济调度、装配线调度、充电优化、车间调度、发车优化、水库调度、三维装箱、物流选址、货位优化、公交排班优化、充电桩布局优化、车间布局优化、集装箱船配载优化、水泵组合优化、解医疗资源分配优化、设施布局优化、可视域基站和无人机选址优化、背包问题、 风电场布局、时隙分配优化、 最佳分布式发电单元分配、多阶段管道维修、 工厂-中心-需求点三级选址问题、 应急生活物质配送中心选址、 基站选址、 道路灯柱布置、 枢纽节点部署、 输电线路台风监测装置、 集装箱调度、 机组优化、 投资优化组合、云服务器组合优化、 天线线性阵列分布优化、CVRP问题、VRPPD问题、多中心VRP问题、多层网络的VRP问题、多中心多车型的VRP问题、 动态VRP问题、双层车辆路径规划(2E-VRP)、充电车辆路径规划(EVRP)、油电混合车辆路径规划、混合流水车间问题、 订单拆分调度问题、 公交车的调度排班优化问题、航班摆渡车辆调度问题、选址路径规划问题、港口调度、港口岸桥调度、停机位分配、机场航班调度、泄漏源定位
🌈 机器学习和深度学习时序、回归、分类、聚类和降维
2.1 bp时序、回归预测和分类
2.2 ENS声神经网络时序、回归预测和分类
2.3 SVM/CNN-SVM/LSSVM/RVM支持向量机系列时序、回归预测和分类
2.4 CNN|TCN|GCN卷积神经网络系列时序、回归预测和分类
2.5 ELM/KELM/RELM/DELM极限学习机系列时序、回归预测和分类
2.6 GRU/Bi-GRU/CNN-GRU/CNN-BiGRU门控神经网络时序、回归预测和分类
2.7 ELMAN递归神经网络时序、回归\预测和分类
2.8 LSTM/BiLSTM/CNN-LSTM/CNN-BiLSTM/长短记忆神经网络系列时序、回归预测和分类
2.9 RBF径向基神经网络时序、回归预测和分类