Skip to content

Commit b29f7e6

Browse files
authored
Merge pull request #622 from nakane11/clear-open-list
[irteus/irtgraph.l] Add clear-open-list in solve-init
2 parents 9a8fbc2 + 9aea594 commit b29f7e6

File tree

4 files changed

+59
-5
lines changed

4 files changed

+59
-5
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.

irteus/irtgraph.l

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -509,13 +509,15 @@ Args:
509509

510510
(defmethod graph-search-solver
511511
(:solve-init (prblm)
512+
(send self :clear-open-list)
512513
(setq close-list nil)
513514
(send self :add-to-open-list
514515
(instance solver-node :init (send prblm :start-state) :cost 0)))
515516
(:find-node-in-close-list (n)
516517
(find (send n :state) close-list))
517-
(:solve (prblm &key (verbose nil))
518-
(send self :solve-init prblm)
518+
(:solve (prblm &key (verbose nil) (resume nil))
519+
(unless resume
520+
(send self :solve-init prblm))
519521
(while (not (send self :null-open-list?))
520522
;;; (if verbose
521523
;;; (warn "current open-list num -> ~A -- ~A --~%"
@@ -537,8 +539,6 @@ Args:
537539
)))
538540
(warn "open-list is nil... -- ~A --~%" :solve)
539541
(warn "search was missed!! -- ~A --~%" :solve)
540-
(send self :clear-open-list)
541-
(setq close-list nil)
542542
nil)
543543
;; open-list functions
544544
(:add-to-open-list (obj/list)

0 commit comments

Comments
 (0)