]> gitweb.factorcode.org Git - factor.git/blob - extra/path-finding/path-finding-docs.factor
Harmonize spelling
[factor.git] / extra / path-finding / path-finding-docs.factor
1 ! Copyright (C) 2010 Samuel Tardieu.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: assocs help.markup help.syntax math sequences ;
4 IN: path-finding
5
6 { <astar> <bfs> <dijkstra> } related-words
7
8 HELP: astar
9 { $description "This tuple must be subclassed and its method " { $link cost } ", "
10   { $link heuristic } ", and " { $link neighbors } " must be implemented. "
11   "Alternatively, the " { $link <astar> } " word can be used to build a non-specialized version." } ;
12
13 HELP: cost
14 { $values
15   { "from" "a node" }
16   { "to" "a node" }
17   { "astar" "an instance of a subclassed " { $link astar } " tuple" }
18   { "n" number }
19 }
20 { $description "Return the cost to go from " { $snippet "from" } " to " { $snippet "to" } ". "
21   { $snippet "to" } " is necessarily a neighbor of " { $snippet "from" } "."
22 } ;
23
24 HELP: heuristic
25 { $values
26   { "from" "a node" }
27   { "to" "a node" }
28   { "astar" "an instance of a subclassed " { $link astar } " tuple" }
29   { "n" number }
30 }
31 { $description "Return the estimated (undervalued) cost to go from " { $snippet "from" } " to " { $snippet "to" } ". "
32   { $snippet "from" } " and " { $snippet "to" } " are not necessarily neighbors."
33 } ;
34
35 HELP: neighbors
36 { $values
37   { "node" "a node" }
38   { "astar" "an instance of a subclassed " { $link astar } " tuple" }
39   { "seq" "a sequence of nodes" }
40 }
41 { $description "Return the list of nodes reachable from " { $snippet "node" } "." } ;
42
43 HELP: <astar>
44 { $values
45   { "neighbors" { $quotation ( node -- seq ) } }
46   { "cost" { $quotation ( from to -- cost ) } }
47   { "heuristic" { $quotation ( pos target -- cost ) } }
48   { "astar" astar }
49 }
50 { $description "Build an astar object from the given quotations. The "
51   { $snippet "neighbors" } " one builds the list of neighbours. The "
52   { $snippet "cost" } " and " { $snippet "heuristic" } " ones represent "
53   "respectively the cost for transitioning from a node to one of its neighbor, "
54   "and the underestimated cost for going from a node to the target. This solution "
55   "may not be as efficient as subclassing the " { $link astar } " tuple."
56 } ;
57
58 HELP: <bfs>
59 { $values
60   { "neighbors" assoc }
61   { "astar" astar }
62 }
63 { $description "Build an astar object from the " { $snippet "neighbors" } " assoc. "
64   "When used with " { $link find-path } ", this astar tuple will use the breadth-first search (BFS) "
65   "path finding algorithm which is a particular case of the general A* algorithm."
66 } ;
67
68 HELP: <dijkstra>
69 { $values
70   { "costs" assoc }
71   { "astar" astar }
72 }
73 { $description "Build an astar object from the " { $snippet "costs" } " assoc. "
74   "The assoc keys are edges of the graph, while the corresponding values are assocs whose keys are "
75   "the edges that can be reached and whose values are the costs to reach those edges. When used with "
76   { $link find-path } ", this astar tuple will use the Dijkstra path finding algorithm which is "
77   "a particular case of the general A* algorithm."
78 } ;
79
80 HELP: find-path
81 { $values
82   { "start" "a node" }
83   { "target" "a node" }
84   { "astar" astar }
85   { "path/f" "an optimal path from " { $snippet "start" } " to " { $snippet "target" }
86     ", or f if no such path exists" }
87 }
88 { $description "Find a path between " { $snippet "start" } " and " { $snippet "target" }
89   " using the A* algorithm."
90 } ;
91
92 HELP: considered
93 { $values
94   { "astar" astar }
95   { "considered" sequence }
96 }
97 { $description "When called after a call to " { $link find-path } ", return a list of nodes "
98   "which have been examined during the A* exploration."
99 } ;
100
101 ARTICLE: "path-finding" "Path finding using the A* algorithm"
102 "The " { $vocab-link "path-finding" } " vocabulary implements a graph search algorithm for finding the least-cost path from one node to another using the A* algorithm." $nl
103 "The " { $link astar } " tuple may be derived from and its " { $link cost } ", " { $link heuristic } ", and " { $link neighbors } " methods overwritten, or the " { $link <astar> } " or " { $link <bfs> } " words can be used to build a new tuple." $nl
104 "Make an A* object:"
105 { $subsections <astar> <bfs> }
106 "Find a path between nodes:"
107 { $subsections find-path } ;
108
109 ABOUT: "path-finding"