快速探索随机树:朝随机点生长
Rapidly-exploring random trees
RRT 如何朝随机样本生长一棵树来规划无碰撞路径,Voronoi 偏置为何让它探索得快,概率完备性承诺什么、不承诺什么,以及 RRT* 如何通过选择父节点和重连改善路径质量;用一个合成的 S 形走廊演示。
rrt朝随机点生长一棵树
快速探索随机树(RRT)是一种为机器人寻找无碰撞路径的方法。它从起点出发,向外生长一棵由可达位置组成的树。每一步,它随机选一个点,找到树上离这个点最近的节点,再从该节点朝这个点走一小步。基本构造
设想一个小机器人在房间里,三堵墙围成一条 S 形走廊。机器人没有自由空间的地图。它只能询问碰撞检测器,也就是一个回答“这个位置或这段直线移动会不会撞墙”的程序。树从机器人所在处开始,一点点绕过墙壁。一旦某根树枝到达目标,沿树枝回到起点就得到一条路径。在我们合成的这个房间里,RRT 找到的第一条路径平均是最短路径长度的 1.449 倍。
关键在于哪个节点获得生长的机会。树边缘的节点面对一大片空地。落在这片空地里的随机点,离它最近,所以它经常被选中。于是树被拉向未探索的空间,“快速探索”这个名字就是这么来的。Voronoi 解释 拉,而不是推
Steven LaValle 在 1998 年的一份技术报告中提出了 RRT。他的设计对象有两类:关节很多的机器人,以及运动受约束的机器人,例如不能横向滑动的汽车。RRT 从不需要把两个给定状态精确连起来。它只需朝随机点挪一小步,连汽车也做得到。摘要与动机
只要路径存在、运行时间足够长,基本 RRT 找到路径的概率就趋于 1。它不保证路径短。2011 年提出的变体 RRT* 增加了两个修补步骤。对没有动力学的机器人,只要搜索半径足够大,它的最佳路径会随着树长大而趋近最短路径。如果要在同一个固定环境里规划许多条不同的路径,相关的方法是概率路线图。贡献
循环、偏置、保证与 RRT*
本节写出规划问题,给出基本循环,解释它为何探索得快,区分三种不同的保证,然后介绍 RRT*。
规划问题
位形是对机器人所处位置的完整描述,例如点机器人的位置,或机械臂每个关节的角度。所有位形构成的集合叫位形空间,见机器人学概览。速度也要考虑时,规划器在状态空间中搜索,状态空间还包含速度。LaValle 1998 年的报告把两者都当作一个有界空间 。规划器要找到一条从起点 到目标状态或目标区域的连续路径。问题设定,第2页
障碍物并不以形状的形式存储。规划器只能检测某个给定状态是否落在障碍区域内。树的每个顶点和每条边都必须位于自由空间 中,即 里障碍物以外的部分。问题设定,第2页
运动服从状态转移方程 ,其中 是控制输入。新状态通过在一小段时间 上积分这个方程得到,可以用欧拉法,更好的是龙格–库塔(Runge–Kutta)这类高阶方法。能朝任意方向移动的机器人叫完整(holonomic)机器人,此时 ,且 。非完整机器人(例如汽车)做不到这一点。状态转移,第2页
LaValle 和 Kuffner 列出 RRT 规划器的六个组成部分。前四个是状态空间、起点与目标、碰撞检测器和输入集合。另外两个是增量模拟器和度量:前者在短时间内施加某个输入,后者是衡量两个状态之间距离的函数。六个组成部分,第2页
基本循环
树一开始只有一个顶点,即起点。然后反复执行同一步。GENERATE_RRT,第2页 图1
- 抽取一个随机状态 ,通常在整个空间上均匀抽取。
- 按度量找到树上离它最近的顶点 。
- 选出能让 在不碰撞的前提下最接近 的输入,模拟它,得到 。
- 如果这次移动无碰撞,就加入 以及一条从 出发的边,并记下所用的输入。
LaValle 和 Kuffner 把这样的一步称为扩展(EXTEND)。它有三种结果。已到达(Reached):新顶点到达样本。已前进(Advanced):在样本之前加入了一个顶点。受困(Trapped):不存在无碰撞的新状态。EXTEND,第4–5页
对沿直线运动的完整机器人,Karaman 和 Frazzoli 把第 3 步写成一个叫 Steer 的转向函数。Steer,第11页
用文字说:在离最近顶点不超过 的所有点 中,取离样本最近的那个。所以树朝 直线前进,最多走一个步长 ;如果样本比 还近,就正好到达它。
为什么探索得快:Voronoi 偏置
一个顶点的 Voronoi 单元,是空间中离这个顶点比离其他任何顶点都近的区域。均匀随机样本必然落在某个顶点的单元里,被扩展的就是那个顶点。所以每个顶点被选中的概率与它的单元大小成正比。LaValle 和 Kuffner 用文字陈述了这一点;下面的公式是我们自己的转写,适用于均匀采样和最近顶点规则。Voronoi 偏置,第4–5页
用文字说:顶点 下一个被扩展的概率,等于它的 Voronoi 单元 的面积(一般情形下是体积 )除以整个空间 的面积。前沿上的顶点面对开阔空间,单元很大,所以生长得最多。
朴素随机树的行为不同。如果随机挑一个顶点、朝随机方向移动,那么每个顶点生长的机会都一样。大多数顶点挤在根附近,于是树总在已经长过的地方继续长。LaValle 1998 年的报告做过这个对比,我们示例的第 2 部分重复了它。朴素随机树,第3页 LaValle 和 Kuffner 把 RRT 描述为把树拉向样本,而另一些规划器是把树从已有顶点推开。拉与推,第4页
从长远看,顶点的分布会和样本一样。LaValle 和 Kuffner 证明,顶点分布依概率收敛到采样分布(他们的定理4)。LaValle 1998 年的报告已经论证,无论根在哪里,顶点最终都会均匀分布,并用卡方检验做了核对。定理4,第6页 均匀性,第3–4页
三种不同的承诺
规划器可以承诺三种很不一样的东西,要把它们分开。
完备的规划器在路径存在时一定找到它,不存在时报告失败。RRT 这类基于采样的规划器不是完备的。使用随机样本时,它们是概率完备的:如果路径存在,随着样本数增加,找到路径的概率趋于 1。LaValle 强调,这种收敛有多快才是最有用的信息,但通常很难证明。完备性的几种概念,第185–186页
对完整机器人,LaValle 和 Kuffner 证明了概率完备性。条件是自由空间有界、开、连通,可以是非凸的。此时任一自由点到最近顶点的距离依概率趋于 0(引理1–2,定理3)。定理3,第5页 Karaman 和 Frazzoli 重述了这个结果,并给出随样本数指数下降的失败概率。他们把它归于 LaValle 和 Kuffner(2001)。定理16,第17页
对非完整机器人,LaValle 和 Kuffner 的证明需要很强的条件。输入集合必须有限, 必须恒定。EXTEND 必须随机选择输入。顶点之间至少相距某个 。目标必须能由某个有限的输入序列到达(定理5)。定理5,第6页
第三种承诺是渐近最优性:当样本数趋于无穷时,找到的最佳路径代价以概率 1 收敛到最优代价。概率完备性对此只字未提。LaValle 早期的两篇文献都说,关于收敛速度和路径质量的界仍是开放问题。开放问题,第3–4页 收敛速度,第6页
他们报告的是测量结果。在 LaValle 1998 年于二维凸区域中的实验里,树上通往根的路径平均是最优长度的 1.3 到 2.0 倍。LaValle 和 Kuffner 报告,在正方形区域中,树上距离与直线距离之比始终在 1.3 到 1.7 之间。这些是实验观察,不是界。路径比,第3页 路径比,第7页
为什么基本 RRT 不是渐近最优的
Karaman 和 Frazzoli 证明 RRT 不是渐近最优的(他们的定理33)。它的最佳路径代价收敛到一个随机极限,这个极限以概率 1 严格高于最优值。他们指出,这解释了为什么多次重启 RRT 会有帮助。定理33,第28页
原因在循环里就看得出。每个新顶点都连到它的最近顶点,边一旦建立就不再改变。通往目标的那根树枝一旦成形,别处新增的顶点就无法把它拉直。
RRT*:先选父节点,再重连
RRT* 保留 RRT 产生顶点的方式,但更仔细地选择边。它需要每个顶点的到达代价,即从起点沿树走到该顶点的路径长度。RRT*,算法6
用文字说:到达一个顶点的代价,等于到达它父节点的代价加上两者之间边的长度;起点的代价为零。
RRT* 加入 时,会查看半径 以内的所有顶点,然后做两步。RRT*,第15–16页
- 选择父节点。在能与 无碰撞相连的邻近顶点中,选出让 到达代价最低的那个。最近顶点只是默认选择。
- 重连(rewire)。对每个邻近顶点,检查经过 是否比它当前的路径更便宜。如果是,就把 设为它的新父节点。
对同一个样本序列,RRT 和 RRT* 建出的顶点集合相同,只是边不同。相同的顶点,第14–15页 Karaman 和 Frazzoli 指出,RRT* 的计算量最多比 RRT 多一个常数倍。复杂度,第1页与第4页
半径随树的增长而收缩。在 Karaman 和 Frazzoli 的 arXiv 版本中,它的形式如下。算法6与定理38,第15–16页和第29页
用文字说: 是顶点数, 是空间维数, 是自由空间的体积, 是单位球的体积()。半径随树长大而缩小,但缩得足够慢,使每个新顶点仍有大约 个邻居;它也永远不超过步长 。只要常数 高于所给门限,RRT* 就是渐近最优的。
紧随其后的定理 39 处理用 个最近顶点代替半径的版本。在 arXiv 版本中,当 时它是渐近最优的。定理39,第29页 同一篇论文中路线图方法 PRM* 的半径常数不同,是 ,不要把两者混用。PRM*,第13–14页
这些结果有前提。Karaman 和 Frazzoli 是在没有微分约束的路径规划下证明的:空间是 维中的有界区域(),用直线连接。带动力学的机器人留给了其他工作。问题表述,第4–6页
实用变体
目标偏置。不总是均匀采样,而是以一个小概率直接返回目标本身。LaValle 和 Kuffner 发现,0.05 这样的偏置通常收敛得快得多。偏置过大,规划器就像势场规划器,即总是朝目标“下坡”走的规划器,会卡在障碍物后面的局部极小处。RRT-GoalBias,第7页 LaValle 的书举了 1/100 作为例子,并给出同样的警告。目标偏置,第235页
连接(CONNECT)。CONNECT 朝同一个样本反复执行 EXTEND,直到到达样本或受困。LaValle 和 Kuffner 发现,CONNECT 最适合完整问题,EXTEND 最适合非完整问题。原因是 CONNECT 更依赖度量。CONNECT,第7–8页
两棵树。双向 RRT 从起点和目标各长一棵树,并设法让它们长到一起。LaValle 和 Kuffner 发现,在适用的场合,这比单棵树高效得多。他们在完整规划中最成功的版本是一棵树用扩展、另一棵用连接。双向,第8页 问题在于,有微分约束时,两条轨迹必须精确接上。这需要转向或打靶方法,而单棵树到达一个目标区域就不需要。连接两棵树,第8–9页 LaValle 的书建议总是扩展较小的那棵树。这对“虫子陷阱”(bug trap)问题有帮助,在这类问题里,一棵树很难逃出一个口袋状区域。平衡搜索,第236页
许多棵树。在每个样本处都新建一棵树,树一旦相连就合并,得到的就是概率路线图。PRM 作为极限,第9页 两棵以上的树,第237页
书中的版本。在 LaValle 的书中,RRT 是快速探索稠密树(RDT)的随机情形。书中把每个样本连到树上任意位置的最近点,而不只是最近顶点,并去掉了步长。书中也指出,带步长的版本更容易实现。RDT,第229–231页,脚注14
度量。理想的度量是真实的剩余代价(cost-to-go),例如最短路径长度。计算它和求解规划问题本身一样难,所以规划器只用简单的度量。度量问题,第3页 快速找到最近顶点本身也是个问题,常用 k-d 树解决,见近似最近邻搜索。最近点,第235页
S 形走廊的仿真
本节在一个小的合成世界里运行 RRT 和 RRT*,并与精确的最短路径比较。程序是原创的,只用 numpy,随机种子固定。所有数字都只是这个玩具世界和这些种子的性质,不是一般的性能数据。
机器人是正方形 中的一个点。三堵闭合的矩形墙 –、– 和 – 围成一条 S 形走廊。起点是 ,目标是以 为圆心、半径 0.5 的圆盘。边与矩形的碰撞检测是精确的(Liang–Barsky 裁剪)。真实的规划器通常只检查边上的若干点。精确最短路径来自可见性图,即矩形角点之间不穿墙的直线组成的图,再用 Dijkstra 算法搜索(见一致代价搜索)。
“迭代次数”指抽取的样本数。“顶点数”指起点加上被接受的扩展;新点或新边发生碰撞的样本会被丢弃。
import heapq
import numpy as np
# Synthetic 2-D world: point robot in the square [0, 10] x [0, 10].
# Obstacles are closed axis-aligned rectangles (xmin, ymin, xmax, ymax).
RECTS = np.array([
[2.0, 0.0, 3.0, 7.0], # wall rising from the bottom
[5.0, 3.0, 6.0, 10.0], # wall hanging from the top
[7.0, 0.0, 8.0, 6.0], # wall rising from the bottom
])
LO, HI = 0.0, 10.0
START = np.array([1.0, 1.0])
GOAL = np.array([9.0, 1.0])
GOAL_RADIUS = 0.5
def point_free(p):
x, y = p
inside = (RECTS[:, 0] <= x) & (x <= RECTS[:, 2]) & (RECTS[:, 1] <= y) & (y <= RECTS[:, 3])
return not inside.any()
def segments_free(a, b):
# Exact test: does segment a[i] -> b[i] avoid every closed rectangle?
# Liang-Barsky clipping against all rectangles at once. a, b: (m, 2).
a = np.atleast_2d(a)[:, None, :]
d = np.atleast_2d(b)[:, None, :] - a
lo = RECTS[None, :, :2]
hi = RECTS[None, :, 2:]
t0 = np.zeros((a.shape[0], RECTS.shape[0]))
t1 = np.ones_like(t0)
hit = np.ones(t0.shape, dtype=bool)
for k in range(2):
dk = d[..., k]
ak = a[..., k]
par = np.abs(dk) < 1e-15
outside = par & ((ak < lo[..., k]) | (ak > hi[..., k]))
hit &= ~outside
with np.errstate(divide="ignore", invalid="ignore"):
ta = (lo[..., k] - ak) / dk
tb = (hi[..., k] - ak) / dk
tmin = np.where(par, -np.inf, np.minimum(ta, tb))
tmax = np.where(par, np.inf, np.maximum(ta, tb))
t0 = np.maximum(t0, tmin)
t1 = np.minimum(t1, tmax)
hit &= t0 <= t1
return ~hit.any(axis=1)
def seg_free(a, b):
return bool(segments_free(a[None], b[None])[0])
def steer(x_near, x_rand, eta):
d = x_rand - x_near
n = np.hypot(d[0], d[1])
return x_rand.copy() if n <= eta else x_near + d * (eta / n)
def visibility_optimum():
# Shortest collision-free path for a point robot among rectangles:
# Dijkstra on the visibility graph of start, goal and rectangle corners
# (corners pushed 1e-6 outward so grazing edges count as free).
e = 1e-6
nodes = [START, GOAL]
for x0, y0, x1, y1 in RECTS:
for c in ([x0 - e, y0 - e], [x1 + e, y0 - e], [x0 - e, y1 + e], [x1 + e, y1 + e]):
c = np.array(c)
if LO <= c[0] <= HI and LO <= c[1] <= HI and point_free(c):
nodes.append(c)
P = np.array(nodes)
m = len(P)
I, J = np.triu_indices(m, 1)
ok = segments_free(P[I], P[J])
adj = [[] for _ in range(m)]
for i, j, f in zip(I, J, ok):
if f:
w = float(np.hypot(*(P[i] - P[j])))
adj[i].append((j, w))
adj[j].append((i, w))
dist = [np.inf] * m
dist[0] = 0.0
pq = [(0.0, 0)]
while pq:
dcur, u = heapq.heappop(pq)
if dcur > dist[u]:
continue
for v, w in adj[u]:
if dcur + w < dist[v]:
dist[v] = dcur + w
heapq.heappush(pq, (dist[v], v))
return dist[1]
def sample(rng, goal_bias):
if rng.random() < goal_bias:
return GOAL.copy()
return rng.uniform(LO, HI, size=2)
def rrt_first_solution(seed, eta=0.5, goal_bias=0.05, max_iter=20000):
# Basic RRT (nearest vertex, steer by at most eta, keep the edge if free).
# Stops at the first vertex inside the goal disc.
rng = np.random.default_rng(seed)
V = np.empty((max_iter + 1, 2))
parent = np.empty(max_iter + 1, dtype=int)
cost = np.empty(max_iter + 1)
V[0], parent[0], cost[0] = START, -1, 0.0
n = 1
for it in range(1, max_iter + 1):
x_rand = sample(rng, goal_bias)
i_near = int(np.argmin(((V[:n] - x_rand) ** 2).sum(axis=1)))
x_new = steer(V[i_near], x_rand, eta)
if point_free(x_new) and seg_free(V[i_near], x_new):
V[n], parent[n] = x_new, i_near
cost[n] = cost[i_near] + np.hypot(*(x_new - V[i_near]))
n += 1
if np.hypot(*(x_new - GOAL)) <= GOAL_RADIUS:
return it, n, cost[n - 1]
return None, n, np.inf
def rrt_and_rrtstar(seed, n_iter, checkpoints, eta=1.0, goal_bias=0.05, gamma=None):
# Runs RRT and RRT* on the same sample sequence and reports, at each
# checkpoint, the best cost-to-come among vertices in the goal disc.
rng = np.random.default_rng(seed)
cap = n_iter + 1
V = np.empty((cap, 2))
par_rrt = np.empty(cap, dtype=int)
c_rrt = np.empty(cap)
par_star = np.empty(cap, dtype=int)
c_star = np.empty(cap)
children = [[] for _ in range(cap)]
V[0] = START
par_rrt[0] = par_star[0] = -1
c_rrt[0] = c_star[0] = 0.0
n = 1
rewires = 0
out = {}
for it in range(1, n_iter + 1):
x_rand = sample(rng, goal_bias)
d2 = ((V[:n] - x_rand) ** 2).sum(axis=1)
i_near = int(np.argmin(d2))
x_new = steer(V[i_near], x_rand, eta)
if point_free(x_new) and seg_free(V[i_near], x_new):
# RRT: parent is the nearest vertex.
par_rrt[n] = i_near
c_rrt[n] = c_rrt[i_near] + np.hypot(*(x_new - V[i_near]))
# RRT*: choose the cheapest parent in the shrinking ball, then rewire.
r = min(gamma * np.sqrt(np.log(n) / n), eta) if n > 1 else eta
dn = np.sqrt(((V[:n] - x_new) ** 2).sum(axis=1))
near = np.nonzero(dn <= r)[0]
if near.size:
free = segments_free(V[near], np.repeat(x_new[None], near.size, 0))
near, dnear = near[free], dn[near[free]]
else:
dnear = dn[near]
best, cbest = i_near, c_star[i_near] + dn[i_near]
if near.size:
k = int(np.argmin(c_star[near] + dnear))
if c_star[near[k]] + dnear[k] < cbest:
best, cbest = int(near[k]), float(c_star[near[k]] + dnear[k])
V[n] = x_new
par_star[n], c_star[n] = best, cbest
children[best].append(n)
for j, dj in zip(near, dnear):
if cbest + dj < c_star[j] - 1e-12:
children[par_star[j]].remove(j)
par_star[j] = n
children[n].append(j)
delta = c_star[j] - (cbest + dj)
stack = [j]
while stack: # propagate the cost drop to all descendants
u = stack.pop()
c_star[u] -= delta
stack.extend(children[u])
rewires += 1
n += 1
if it in checkpoints:
in_goal = np.hypot(V[:n, 0] - GOAL[0], V[:n, 1] - GOAL[1]) <= GOAL_RADIUS
b_rrt = c_rrt[:n][in_goal].min() if in_goal.any() else np.inf
b_star = c_star[:n][in_goal].min() if in_goal.any() else np.inf
out[it] = (n, b_rrt, b_star, rewires, r if n > 1 else eta)
# Consistency check: stored RRT* costs equal costs recomputed along parents.
err = 0.0
for v in range(1, n):
p = par_star[v]
err = max(err, abs(c_star[v] - c_star[p] - np.hypot(*(V[v] - V[p]))))
return out, err
def coverage_demo(K=500, seed=0):
# LaValle (1998) style setting: empty square [0,100]^2, step 1, root (50,50).
# RRT versus a naive random tree (random vertex, random direction).
lo, hi, step, root = 0.0, 100.0, 1.0, np.array([50.0, 50.0])
g = np.linspace(0.5, 99.5, 100)
G = np.stack(np.meshgrid(g, g), -1).reshape(-1, 2)
res = {}
for name in ("rrt", "naive"):
rng = np.random.default_rng(seed)
V = np.empty((K, 2))
V[0] = root
for n in range(1, K):
if name == "rrt":
x = rng.uniform(lo, hi, size=2)
i = int(np.argmin(((V[:n] - x) ** 2).sum(axis=1)))
d = x - V[i]
new = V[i] + d / np.hypot(*d) * step
else:
i = int(rng.integers(n))
th = rng.uniform(0, 2 * np.pi)
new = V[i] + step * np.array([np.cos(th), np.sin(th)])
V[n] = np.clip(new, lo, hi)
far = float(np.hypot(*(V - root).T).max())
covered = 0
for chunk in np.array_split(G, 10):
dmin = np.sqrt(((chunk[:, None, :] - V[None]) ** 2).sum(-1)).min(1)
covered += int((dmin <= 5.0).sum())
res[name] = (far, covered / len(G))
return res
opt = visibility_optimum()
free_area = (HI - LO) ** 2 - float(((RECTS[:, 2] - RECTS[:, 0]) * (RECTS[:, 3] - RECTS[:, 1])).sum())
d = 2
gamma_star = (2 * (1 + 1 / d)) ** (1 / d) * (free_area / np.pi) ** (1 / d)
print("World: [0,10]^2, 3 rectangles, start (1,1), goal disc r=0.5 at (9,1)")
print(f"free area = {free_area:.1f}, optimal path length (visibility graph) = {opt:.4f}")
print(f"optimal length to goal-disc boundary = {opt - GOAL_RADIUS:.4f}")
print()
print("[1] Basic RRT, eta=0.5, goal bias 0.05, stop at first vertex in goal disc")
it0, n0, c0 = rrt_first_solution(0)
print(f"seed 0: iterations={it0}, vertices={n0}, path length={c0:.4f}, ratio to optimum={c0 / (opt - GOAL_RADIUS):.3f}")
stats = []
for s in range(20):
it, n, c = rrt_first_solution(s)
stats.append((it, n, c / (opt - GOAL_RADIUS)))
st = np.array(stats, dtype=float)
print(f"20 seeds: solved {int(np.isfinite(st[:, 2]).sum())}/20, median iterations={np.median(st[:, 0]):.0f}, "
f"min/max iterations={st[:, 0].min():.0f}/{st[:, 0].max():.0f}")
print(f"20 seeds: path/optimum ratio mean={st[:, 2].mean():.3f}, min={st[:, 2].min():.3f}, max={st[:, 2].max():.3f}")
print()
print("[2] Voronoi bias: empty [0,100]^2, step 1, root (50,50), 500 vertices")
cov = coverage_demo()
for name in ("rrt", "naive"):
far, frac = cov[name]
print(f"{name:5s}: farthest vertex from root={far:.2f}, grid points within 5 of a vertex={frac:.3f}")
print()
gamma = 1.1 * gamma_star
print(f"[3] RRT vs RRT* on the same samples, eta=1.0, gamma*={gamma_star:.4f}, gamma={gamma:.4f}")
cps = (1000, 2000, 3000, 4000)
out, err = rrt_and_rrtstar(1, 4000, cps, gamma=gamma)
def fmt(c):
return "no path yet" if not np.isfinite(c) else f"{c:.4f} ({c / (opt - GOAL_RADIUS):.3f}x)"
for k in cps:
n, br, bs, rw, r = out[k]
print(f"iter {k:4d}: vertices={n:4d}, radius={r:.4f}, best RRT={fmt(br)}, best RRT*={fmt(bs)}, rewires so far={rw}")
print(f"RRT* stored costs match costs recomputed along parent links (max error < 1e-9): {err < 1e-9}")
print()
print("[4] Five seeds, 2000 iterations: best cost / optimum")
rows = []
for s in range(2, 7):
o, _ = rrt_and_rrtstar(s, 2000, (2000,), gamma=gamma)
_, br, bs, _, _ = o[2000]
rows.append((br / (opt - GOAL_RADIUS), bs / (opt - GOAL_RADIUS)))
print(f"seed {s}: RRT {rows[-1][0]:.3f}, RRT* {rows[-1][1]:.3f}")
rows = np.array(rows)
print(f"mean: RRT {rows[:, 0].mean():.3f}, RRT* {rows[:, 1].mean():.3f}")
程序输出:
World: [0,10]^2, 3 rectangles, start (1,1), goal disc r=0.5 at (9,1)
free area = 80.0, optimal path length (visibility graph) = 21.8162
optimal length to goal-disc boundary = 21.3162
[1] Basic RRT, eta=0.5, goal bias 0.05, stop at first vertex in goal disc
seed 0: iterations=899, vertices=542, path length=27.8689, ratio to optimum=1.307
20 seeds: solved 20/20, median iterations=1171, min/max iterations=711/1718
20 seeds: path/optimum ratio mean=1.449, min=1.295, max=1.585
[2] Voronoi bias: empty [0,100]^2, step 1, root (50,50), 500 vertices
rrt : farthest vertex from root=48.28, grid points within 5 of a vertex=0.379
naive: farthest vertex from root=6.19, grid points within 5 of a vertex=0.028
[3] RRT vs RRT* on the same samples, eta=1.0, gamma*=8.7404, gamma=9.6144
iter 1000: vertices= 451, radius=1.0000, best RRT=no path yet, best RRT*=no path yet, rewires so far=366
iter 2000: vertices=1219, radius=0.7343, best RRT=33.3145 (1.563x), best RRT*=23.7576 (1.115x), rewires so far=1150
iter 3000: vertices=2041, radius=0.5876, best RRT=33.3145 (1.563x), best RRT*=23.1021 (1.084x), rewires so far=1777
iter 4000: vertices=2858, radius=0.5074, best RRT=33.3145 (1.563x), best RRT*=22.3850 (1.050x), rewires so far=2422
RRT* stored costs match costs recomputed along parent links (max error < 1e-9): True
[4] Five seeds, 2000 iterations: best cost / optimum
seed 2: RRT 1.726, RRT* 1.070
seed 3: RRT 1.455, RRT* 1.077
seed 4: RRT 1.459, RRT* 1.056
seed 5: RRT 1.499, RRT* 1.065
seed 6: RRT 1.577, RRT* 1.046
mean: RRT 1.543, RRT* 1.063
世界。自由面积为 。到目标圆心的最短路径长 21.8162(习题2会手算核对)。在目标圆盘边缘停下可省 0.5,得到 21.3162。下面的所有比值都除以 21.3162。
第1部分:基本 RRT。20 个种子全部到达目标圆盘;种子 0 用了 899 次迭代,路径是最优值的 1.307 倍。平均比值 1.449 落在 LaValle 观察到的 1.3–2.0 范围内。但我们的世界不是凸的,这不证明任何一般结论。
第2部分:Voronoi 偏置。这里大致重复 LaValle 1998 年对比的设定:空的正方形,步长 1,从中心长出 500 个顶点。顶点数相同,RRT 离根最远到 48.28,覆盖 37.9% 的测试网格点;朴素随机树只到 6.19,覆盖 2.8%。
第3部分:同一组样本上的 RRT 与 RRT*。对这个世界,arXiv 版本的门限为 ,我们取 (这是我们的选择)。两棵树都在 1000 到 2000 次迭代之间首次到达目标。此后 RRT 的最佳路径一直停在 33.3145(最优值的 1.563 倍);RRT* 的则不断缩短,到 4000 次迭代时从 1.115 倍降到 1.050 倍。最后一行检查确认,RRT* 存储的代价与沿父节点链重新计算的代价相等。
输出的半径是最后一个被接受顶点所用的半径。它用的是插入该顶点之前的顶点数,因为代码在加入顶点之前计算 r。在 2000 次迭代的检查点,这个数是 1218:。1000 次迭代时公式给出的值大于 1,所以上限 生效。
第4部分:另外五个种子。2000 次迭代时,每个种子上 RRT* 都更短,用的是同样的顶点:平均比值 1.063,RRT 为 1.543。
第3部分在小尺度上展示了理论:RRT 通往目标的树枝被冻结,RRT* 的则不断变短。这只是一次运行,不是收敛的证明。
保证到哪里为止
本节列出 RRT 不承诺什么,以及它在哪里吃力。
基本 RRT 不保证路径质量。概率完备性只关乎找到某条路径。基本 RRT 的最佳代价收敛到高于最优值的值(定理33)。定理33,第28页 1.3–2.0 和 1.3–1.7 的比值是实验观察,不是界。路径比,第3页 路径比,第7页
失败什么也证明不了。基于采样的规划器在任何有限预算后失败,都没有证明路径不存在。完备性的几种概念,第185–186页 狭窄通道需要很多样本,而收敛速度一般是未知的。能证明“无路可走”的规划器必须是完备的,通常意味着组合方法。
度量问题。在简单度量下的最近顶点,可能是个糟糕的生长起点,对汽车等受约束的机器人尤其如此。真实的剩余代价最理想,但计算它和求出规划本身一样难。度量问题,第3页
带动力学时保证很窄。对非完整机器人,LaValle 和 Kuffner 的完备性证明需要上面列出的强条件。定理5,第6页 Karaman 和 Frazzoli 关于 RRT* 的最优性结果假设没有微分约束。问题表述,第4–6页 仅凭这些结果,不能说明 RRT* 对汽车或带动力学的机器人是渐近最优的。
目标偏置会设陷阱。偏置太强时,离目标最近的顶点会被一次次推向同一堵墙,一次次受困。RRT-GoalBias,第7页
边的检测。真实的规划器在边上每隔 检查一个点。间隔太小会浪费碰撞检测,间隔太大可能直接跳过薄障碍物。检查线段,第216页 我们的示例用精确的矩形检测避开了这个问题,真实机器人很少有这种条件。
单查询与多查询。RRT 不做预计算,路线图要做。LaValle 和 Kuffner 指出,因此不能直接比较两者的速度,偏向任何一方的例子都很容易构造。比较,第9页
示例只是玩具。一个点机器人、三个矩形、选定的步长和种子。渐近最优性是极限意义上的陈述,我们在 4000 次迭代时得到的 1.050 只是一次运行。
习题
这些习题涉及 Voronoi 偏置、两道手算题、一个关于保证的反例,以及方法选择。
-
为什么 RRT 能迅速铺开,而朴素随机树(随机挑一个顶点,朝随机方向移动)却停留在根附近?用示例中的数字说明。
答案:在 RRT 中,生长的是离均匀样本最近的顶点。所以每个顶点生长的概率与它的 Voronoi 单元面积成正比。前沿顶点的单元大,生长得最多,把树向外拉。朴素随机树让每个顶点以同样的频率生长,而大多数顶点在根附近,所以它总在原处继续长。在第 2 部分,500 个顶点之后,RRT 最远的顶点离根 48.28,37.9% 的测试点在树的 5 以内。朴素随机树只到达 6.19,覆盖 2.8%。
-
(a) 在示例世界中,从 到 的最短路径绕过角点 、、、、 和 。计算它的长度,并与 21.8162 比较。(b) 计算这个世界中 RRT* 的 (,自由面积 80),并与 8.7404 比较。
答案:(a) 各段为 :;:1;:;:1;:;:1;:。总和为 21.8162。在目标圆盘处停下,沿最后一段直线省去 0.5,得到 21.3162。(b) 。
-
一位队友说:“RRT 是概率完备的,所以只要运行得够久,路径就会变成最短的。而如果它在 10 000 次迭代后还失败,就说明没有路径。”分别给这两句话各举一个反例。
答案:前一句:概率完备性关乎能否找到路径,与路径长度无关。Karaman 和 Frazzoli 证明 RRT 不是渐近最优的:它的最佳代价以概率 1 收敛到一个高于最优值的随机值。在第 3 部分,从 2000 到 4000 次迭代,RRT 的最佳路径一直停在 33.3145(最优值的 1.563 倍)。同期 RRT* 改善到 1.050。后一句:概率完备不等于完备。有限预算后的失败不能证明路径不存在,狭窄通道可能需要非常多的样本。只有完备的规划器才能证明路径不存在。
-
你会选择哪种规划器?为什么?(a) 一辆带动力学的类车机器人要在新环境中到达一个目标区域,只需一次。(b) 固定工作单元里的 7 关节机械臂要回答成千上万个起点–终点查询。(c) 小型二维栅格地图上的点机器人,要求得到栅格分辨率下的最短路径。(d) 移动机器人应该尽快给出第一条路径,并在剩余时间里不断改进。
答案:(a) 用 EXTEND 的单棵 RRT,在状态空间中采样,通过模拟器施加输入。它从不需要在两个给定状态之间精确转向,RRT 正是为此设计的。(b) 概率路线图(概率路线图):在固定的工作单元里,预计算的代价能被大量查询摊薄。(c) 用 A* 做栅格搜索,它在栅格分辨率下最优,在二维中开销很小。Karaman 和 Frazzoli 既指出了这种分辨率限制,也指出栅格规模随维数指数增长。(d) RRT*,它不断改进路径,在没有动力学的机器人上,满足半径条件时是渐近最优的。另一种选择是先用基本 RRT,再用轨迹优化做局部平滑。
-
为什么目标偏置太大会有害?文献用的是什么数值?
答案:偏置很强时,许多样本就是目标本身。树会一直把离目标最近的顶点直接朝目标扩展。如果中间有墙,这个顶点就一次次受困,就像卡在局部极小处的势场规划器。小的偏置让大多数样本继续用于探索:LaValle 和 Kuffner 用 0.05,LaValle 的书举了 1/100 为例。我们的示例用 0.05。
历史与延伸阅读
本节概述我们读过的原始文献,并建议下一步读什么。
LaValle 的报告《Rapidly-exploring random trees: A new tool for path planning》是爱荷华州立大学计算机科学系的技术报告 TR 98-11,日期为 1998 年 10 月。编号和日期取自 LaValle 著作的参考文献,因为 PDF 的页眉没能在文本提取中保留下来。这份四页的报告针对非完整和高维问题提出 RRT,并说它已被用于最多十二个自由度的问题。摘要,第1页 参考文献条目103 它是技术报告,不是期刊或会议论文。报告中已经预期,对完整问题,RRT“might be faster”(可能更快),快于基本的路线图规划器,同时承认很难做出决定性的比较。与 PRM 的比较,第3页
LaValle 和 Kuffner 的《Rapidly-exploring random trees: Progress and prospects》是一本书中的一章。该书名为《Algorithmic and Computational Robotics: New Directions》,2001 年出版,由 Donald、Lynch 和 Rus 编辑。它加入了 EXTEND 和 CONNECT 函数、目标偏置、双向版本,以及上文用到的概率完备性定理。第3–5节 参考文献条目108 这一章按每棵树使用的函数,把双树变体命名为 RRT-ExtExt、RRT-ExtCon 和 RRT-ConCon。
Karaman 和 Frazzoli 的《Sampling-based algorithms for optimal motion planning》于 2011 年 5 月发布在 arXiv 上。同年,它发表于《International Journal of Robotics Research》。它证明了 RRT 不是渐近最优的,并提出了 RRT*,以及 PRM* 和快速探索随机图(RRG)。本文引用的常数来自 arXiv 版本。摘要与贡献,第1–5页
想读教科书式的讲解,可以看 LaValle《Planning Algorithms》第5章。那里把 RRT 放在快速探索稠密树和路线图的框架中。5.5节 图上的双树思想见双向搜索。机械臂规划所在的关节空间见机器人运动学和逆运动学。碰撞检测器所用地图的一种来源见占据栅格地图。抓取和操作任务中的机械臂运动是 RRT 的常见用途。
先判断,再看解释
在示例中,RRT 和 RRT* 使用同一个随机样本序列。从第 2000 到第 4000 次迭代,RRT 的最佳路径一直是 33.3145(最优值的 1.563 倍),RRT* 从 1.115 倍降到 1.050 倍。哪种解释正确?
学习目标
- 写出 RRT 的基本循环(采样、最近顶点、步长受限的转向、碰撞检测、加边),用 Voronoi 偏置解释它为什么快速伸向未探索区域,并说明目标偏置、CONNECT 与双向搜索各自的作用与风险。
- 区分概率完备性、完备性与渐近最优性;说明 RRT 为什么不是渐近最优,RRT* 如何通过选择父节点、重连和随顶点数收缩的连接半径改善路径,以及该保证依赖的条件。
先修与延伸
查看知识关联图 →参考文献
- Rapidly-exploring random trees: A new tool for path planning — scoped
Steven M. LaValle · 1998 - Rapidly-exploring random trees: Progress and prospects — scoped
Steven M. LaValle; James J. Kuffner · 2001 - Sampling-based algorithms for optimal motion planning (arXiv v1) — scoped
Sertac Karaman; Emilio Frazzoli · 2011 - Planning Algorithms, Chapter 5: Sampling-Based Motion Planning — scoped
Steven M. LaValle · 2006
版本1 · 编写状态: 已完成记录中的技术复核
查看技术检查记录(AI)
Claude · 2026-12-03 · Independent AI check (Claude subagent, not the author; not a human or expert review). Research was done by a separate research subagent (facts.md) and the prose by a writer subagent. Gemini app style-only edits had been applied to the English opening (intuition) section before this check; each logged edit was compared with its old text and none changed a fact, hedge or attribution. The Chinese opening had no Gemini pass, so the checker did its own D012 readability pass on it. Ran example.py with the pinned interpreter (numpy 1.26.4): output identical to example.stdout.txt, and the python block in en.mdx and zh.mdx is byte-identical to example.py. Re-derived the visibility-graph optimum 21.8162/21.3162, gamma* = 8.7404, the printed radius 0.7343 at 1218 vertices and the cap at 1000 iterations, and checked every number quoted in the prose against the output. Re-opened the sources myself: Karaman-Frazzoli arXiv:1105.1186v1 via pdftotext (Steer p. 11, PRM*/RRG constants pp. 13-14, RRT* text and Algorithm 6 pp. 15-16, Theorems 15-16 p. 17, Theorem 33 p. 28, Theorems 38-39 p. 29, abstract p. 1, section 1.3 and problem scope p. 4); LaValle's Planning Algorithms ch. 5 via pdftotext (RDT swath and footnote 14 pp. 229-230, goal bias 1/100 and balanced bidirectional search pp. 235-236, sampling-based roadmaps pp. 237-238 and 246); LaValle 1998 TR (4 pages) and LaValle-Kuffner 2001 (PDF pp. 1-9) by OCR, spot-checking twelve DOF, naive tree and random walk bias, the 1.3-2.0 ratio in 2-D convex spaces, chi-square uniformity, 'might be faster', the six components, pull versus push, Reached/Trapped, Theorems 3-5, the 1.3-1.7 ratio, goal bias 0.05, RRT-ExtCon and the PRM limiting case. Compared zh and en section by section, checked display-equation parity, citation IDs, MDX safety, links (only published topics are linked; probabilistic-roadmaps, grasping and manipulation stay inline code) and data.json catalogue IDs and quiz answer. Not checked: the IJRR journal version of Karaman-Frazzoli, their proofs and complexity section, and LaValle-Kuffner pp. 10-19.
- 用固定解释器(numpy 1.26.4)运行 example.py,输出与 example.stdout.txt 一致;中英文代码块与 example.py 逐字节相同。
- 手算核对最优路径 21.8162、gamma* = 8.7404、半径 0.7343 和各比值,与输出相符。
- 重新打开 Karaman–Frazzoli arXiv v1:Steer 在第 11 页,算法 6 在第 15–16 页,定理 33 在第 28 页,定理 38(半径常数)和定理 39(k 近邻常数)在第 29 页。
- 核对 LaValle 书第 5 章:RDT 把样本连到树“扫过区域”(swath)上的最近点,脚注 14 说明去掉了步长;目标偏置 1/100 和平衡双向搜索在第 235–236 页。
- 通过 OCR 抽查 LaValle 1998 和 LaValle–Kuffner 2001 的引用句,均有原文支持。
- 中英文逐节对照:结论、数字、习题、答案和限定语一致;公式、引用编号和链接一致,MDX 安全。
核对的来源位置:
- Rapidly-exploring random trees: A new tool for path planning — scoped · Lav98c.pdf, 4 PDF pages, Type-3 fonts so pdftotext fails; rendered at 200 dpi and OCR'd with tesseract; all 4 pages read in full. p. 1: abstract (nonholonomic constraints incl. dynamics, high DOF, up to twelve DOF), §1 motivation (PRM connection problem can be as hard as a nonlinear controller). p. 2: §2 problem setting (metric space X, implicit X_obs, X_free), state transition equation, Euler/Runge-Kutta, holonomic f = u, GENERATE_RRT pseudocode and explanation. p. 3: §3 seven properties, square [0,100]^2 with Δt = 1 and root (50,50), naive random tree bias, Voronoi explanation, 1.3–2.0 path ratio, chi-square uniformity, uniform-convergence argument, metric problem, comparison with PRM (single nearest neighbour, minimal edges, 'difficult to make a conclusive experimental comparison'). p. 4: §4 examples, §5 research issues (multiple RRTs, goal bias warning, convergence-rate bounds open), references. Report number TR 98-11 and date Oct. 1998 not visible in the OCR text; taken from Planning Algorithms bibliography entry [103]. Figures not inspected beyond captions.
- Rapidly-exploring random trees: Progress and prospects — scoped · LavKuf01.pdf, 19 PDF pages, OCR as above. Read in full PDF pp. 1–9: abstract; §1 introduction (differential constraints, dynamic-programming contrast, PRM connection problem, p. 3); §2 six-component formulation, holonomic/nonholonomic/kinodynamic cases (pp. 2–4); §3 BUILD_RRT and EXTEND with Reached/Advanced/Trapped, pull-vs-push, Voronoi-area selection probability (pp. 4–5); §4 Lemmas 1–2, Theorem 3 (p. 5), Theorems 4–5 and conditions, open rate of convergence, convex-hull branches, 1.3–1.7 ratio (pp. 6–7); §5 RRT-GoalBias (0.05), GoalZoom, step size, CONNECT (p. 7–8), bidirectional RRT_BIDIRECTIONAL, ExtExt/ExtCon/ConCon, many trees and PRM as the limiting case (pp. 8–9); start of §6 (single- vs multiple-query comparison, p. 9). Skimmed only the first lines of pp. 10–16 (experiments, conclusions, references). Venue (A K Peters 2001, pp. 293–308) taken from Planning Algorithms bibliography [108]; not printed in the PDF. Not read: experiment details, figures.
- Sampling-based algorithms for optimal motion planning (arXiv v1) — scoped · arXiv:1105.1186v1 PDF via pdftotext, arXiv PDF page numbers. Read pp. 1–6 (abstract; §1.1 PRM/RRT background; §1.2 optimal planning and grid A* resolution limit, p. 4; §1.3 contributions; Table 1, p. 5; §2.1 problem formulation, p. 6); pp. 11–17 (§3.1 Steer with η and Near; §3.2 Algorithms 1–3 PRM, sPRM, RRT with k-nearest/bounded-degree/variable-radius variants, p. 12; §3.3 PRM* (radius and k rules), RRG, RRT* Algorithms 4–6, pp. 13–16; §4.1 robust feasibility, Definition 14, Theorems 15–16, p. 17); pp. 28–29 (Theorem 33 non-optimality of RRT and the restart remark; Theorems 34–39 including Theorem 38's γ_RRT* condition; opening of §4.3). Not read: §2.2 beyond the k-nearest percolation theorem on p. 9, §4.2.1 other proofs, §4.3 complexity analysis, §5 experiments, §6, appendices. Journal version (IJRR 30(7), 2011) not opened; the Theorem 38 constant is quoted from v1 only.
- Planning Algorithms, Chapter 5: Sampling-Based Motion Planning — scoped · ch5.pdf (printed pp. 185–248) via pdftotext. Read: chapter opening pp. 185–186 (complete / resolution complete / probabilistically complete, rate of convergence); §5.3.4 opening pp. 215–216 (path-segment checking with step Δq); §5.5 pp. 229–237: RDT definition, footnote 14 (step size dropped), Figs. 5.16–5.21 exploration algorithm and stopping configuration, §5.5.2 opening and Kd-tree paragraph (p. 235), §5.5.3 single-tree goal bias 1/100 (p. 235), balanced bidirectional RDT Fig. 5.24 (p. 236), more than two trees and the PRM limit (p. 237); Further Reading pp. 245–246; bibliography entries [103], [105]–[108]. Not read: §5.1–§5.2, §5.3.1–5.3.3, most of §5.4, §5.5.2 approximate methods in detail, Chapter 14.
相关主题