41 lines
1.7 KiB
TeX
41 lines
1.7 KiB
TeX
% Copyright (c) 2014,2016 Casper Ti. Vector
|
|
% Public domain.
|
|
|
|
\chapter{基于深度优先搜索算法计算过渡矩阵}
|
|
两种最常见的树搜索算法是广度优先搜索(BFS)和深度优先搜索(DFS).
|
|
在此, 我们推荐深度优先搜索, 因为它可以通过编写递归代码简单实现.
|
|
给定一个顶点$\bm x_{v}$和一个代表单元$K_{r_{0}} \in \mathcal{M}_{v}$,
|
|
我们需要一些初始化设置.
|
|
令$\mathbb{T}_{r_{0},r_{0}} = \mathbb{I}_{3}$,
|
|
令$\mathscr{V}$表示长度为$N_C$的标签数组,
|
|
用于标记已访问过的单元.
|
|
标签数组初始值设置为\texttt{false}.
|
|
以下算法是基于深度优先搜索算法\parencite{algorithmbook}计算过渡矩阵.
|
|
使用以下算法可以获得等式\eqref{ch2:eq:finalgradrelation}中的$\mathbb{T}_{i,r_{0}} (i=1,2,\cdots,N_{C})$.
|
|
|
|
\begin{algorithm}
|
|
\caption{基于深度优先搜索计算过渡矩阵的算法}
|
|
\label{alg:dft}
|
|
\begin{algorithmic}[1]
|
|
\Procedure{T}{$G_{v}$}
|
|
\State $\mathbb{T}_{r_{0},r_{0}} \gets \mathbb{I}_{3}$
|
|
\For{$i \gets 1, N_{C}$}
|
|
\State $\mathscr{V}_{i} \gets \texttt{false}$
|
|
\EndFor
|
|
\State DFS($r_{0}$)
|
|
\EndProcedure
|
|
\Statex
|
|
\Procedure{DFS}{$i$}\Comment{输入整数$i$, 表示单元$K_{i} \in \mathcal{M}_{v}$}
|
|
\State $\mathscr{V}_{i} \gets \texttt{false}$
|
|
\ForAll {$K_{l} \in \mathcal{M}_{v}$}
|
|
\If {$K_{i}$与$K_{l}$有公共面且$\mathscr{V}_{l} = \texttt{false}$}
|
|
\State 通过\eqref{ch2:eq:gradtransexp}计算关于单元$K_{l}, K_{i} \in \mathcal{M}_{v}$的过渡矩阵$\mathbb{T}_{l,i}$
|
|
\State $\mathbb{T}_{l,r_{0}} \gets \mathbb{T}_{l,i}\mathbb{T}_{i,r_{0}}$
|
|
\State DFS($l$)\Comment{使用整数$l$递归调用DFS}
|
|
\EndIf
|
|
\EndFor
|
|
\EndProcedure
|
|
\end{algorithmic}
|
|
\end{algorithm}
|
|
% vim:ts=4:sw=4
|