Skip to content

Commit 1194e87

Browse files
committed
[doc/irtgraph] Add example for irtgraph
1 parent 6498a44 commit 1194e87

File tree

3 files changed

+55
-1
lines changed

3 files changed

+55
-1
lines changed

doc/irtgraph.tex

Lines changed: 55 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,56 @@
11
\section{グラフ表現}
2-
\input{irtgraph-func}
2+
グラフを利用するためには、\verb|graph|のインスタンスを作り、グラフを構成するノードとノード間を繋ぐエッジを追加していく。
3+
エッジには方向があるため、無向グラフで二つのノードを接続する場合は\verb|:both|をtとして両方向に二つの\verb|arc|を追加する。
4+
グラフの標準クラス\verb|graph|では全てのエッジのcostが1である。
5+
作成したグラフはdot、pdf、pngなどの形式で保存でき、探索結果を引数に入れて経路を図示することもできる。
6+
7+
グラフ問題を解くソルバーは基底クラスの\verb|graph-search-solver|を継承しており、探索候補のノードをオープンリストに追加する順番やヒューリスティック関数を上書きする。
8+
\verb|breadth-first-graph-search-solver|(幅優先探索)、\verb|depth-first-graph-search-solver|(深さ優先探索)、\verb|best-first-graph-search-solver|(最良優先探索)、\verb|a*-graph-search-solver|(A*探索)が実装されている。
9+
10+
グラフ問題を解く例を以下に示す。
11+
12+
{\baselineskip=10pt
13+
\begin{verbatim}
14+
;; Make graph
15+
(setq gr (instance graph :init))
16+
17+
;; Add nodes
18+
(setq arad (instance node :init "Arad")
19+
sibiu (instance node :init "Sibiu")
20+
fagaras (instance node :init "Fagaras")
21+
rimnicu (instance node :init "Rimnicu Vilcea")
22+
pitesti (instance node :init "Pitesti")
23+
bucharest (instance node :init "Bucharest")
24+
zerind (instance node :init "Zerind")
25+
oradea (instance node :init "Oradea"))
26+
(send gr :add-node arad)
27+
(send gr :add-node sibiu)
28+
(send gr :add-node fagaras)
29+
(send gr :add-node rimnicu)
30+
(send gr :add-node pitesti)
31+
(send gr :add-node bucharest)
32+
(send gr :add-node zerind)
33+
(send gr :add-node oradea)
34+
35+
;; Add edges
36+
(setq ar1 (send gr :add-arc-from-to arad zerind :both t)
37+
ar2 (send gr :add-arc-from-to zerind oradea :both t)
38+
ar3 (send gr :add-arc-from-to oradea sibiu :both t)
39+
ar4 (send gr :add-arc-from-to arad sibiu :both t)
40+
ar5 (send gr :add-arc-from-to sibiu fagaras :both t)
41+
ar6 (send gr :add-arc-from-to fagaras bucharest :both t)
42+
ar7 (send gr :add-arc-from-to sibiu rimnicu :both t)
43+
ar8 (send gr :add-arc-from-to rimnicu pitesti :both t)
44+
ar9 (send gr :add-arc-from-to pitesti bucharest :both t))
45+
46+
;; Search path from Arad to Bucharest
47+
(setq sol (instance breadth-first-graph-search-solver :init))
48+
(setq path (send sol :solve-by-name gr "Arad" "Bucharest"))
49+
50+
;; Draw graph
51+
(send gr :write-to-pdf "test" path)))
52+
53+
\end{verbatim}
54+
}
55+
56+
\input{irtgraph-func}

doc/jmanual.dvi

3.52 KB
Binary file not shown.

doc/jmanual.pdf

2.41 KB
Binary file not shown.

0 commit comments

Comments
 (0)