bfsearch 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +34 -0
- data/lib/bfsearch.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 247afe4bafa74ab46c6e096cebd4edf4b2ef5907
|
4
|
+
data.tar.gz: 905679e639975f10e7f43ec4e52409a4a8aef0b9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c6bb009ea49bc1d6dbf37937d95072b5745b19f646d1471a87556d9b7baf560b9f6d13ee18e893879396de9de0f3a5e403a6abc6fede90e0064f68bf12a80a5e
|
7
|
+
data.tar.gz: 992d72cae4ffd5632ae10d8103d456ca2eb253a76097724d8f59b27a2de4d6d4048209d636c73d162c804f89820b1cc35283d62b98c4a710edb69881d2a5bdc3
|
data/README.md
CHANGED
@@ -4,6 +4,40 @@
|
|
4
4
|
|
5
5
|
This Ruby gem implements the Best-First Search algorithm.
|
6
6
|
|
7
|
+
## Synopsis
|
8
|
+
|
9
|
+
require 'bfsearch'
|
10
|
+
|
11
|
+
distance = ->(a, b) { a.calculate_distance_to(b) }
|
12
|
+
neighbors = ->(node) { node.all_neighbors }
|
13
|
+
heuristic = ->(a, b) { a.calculate_optimistic_distance_to(b) }
|
14
|
+
|
15
|
+
path = BFsearch.find_path(start, destination, distance, neighbors,
|
16
|
+
heuristic)
|
17
|
+
|
18
|
+
This gem implements the Greedy Best-First Search algorithm. Its main and only
|
19
|
+
interface is `BFsearch.find_path`. This method requires a number of arguments,
|
20
|
+
which are:
|
21
|
+
|
22
|
+
start:: The starting node
|
23
|
+
destination:: The destination node
|
24
|
+
distance:: A function that calculates the real distance between two nodes
|
25
|
+
neighbors:: A function that returns all immediate neighbors of a node
|
26
|
+
heuristic:: A function that calculates the *optimistic* distance between
|
27
|
+
two nodes
|
28
|
+
|
29
|
+
The three functions are assumed to be `Proc` objects, i.e., procs or lambdas
|
30
|
+
that answer to `#call`. Moreover, `distance` and `heuristic` are assumed to
|
31
|
+
return a `Float`.
|
32
|
+
|
33
|
+
Heuristic must return an optimistic distance between two nodes. "Optimistic"
|
34
|
+
means that the value must be lower than or equal to what the distance function
|
35
|
+
would return: `heuristic(a, b) <= distance(a, b)`. For example, the air-line
|
36
|
+
distance would be such an optimistic function (compared to, e.g., the
|
37
|
+
manhattan distance).
|
38
|
+
|
39
|
+
gBFS can be turned into standard BFS with `heuristic = ->(a, b) { 0.0 }`.
|
40
|
+
|
7
41
|
## License
|
8
42
|
|
9
43
|
This code is licensed under the GNU GPL v3. See the file `COPYING` for
|
data/lib/bfsearch.rb
CHANGED
@@ -44,7 +44,7 @@ module BFsearch
|
|
44
44
|
# +neighbors_function#call(current_node)+ and returns a list of adjacent
|
45
45
|
# nodes.
|
46
46
|
#
|
47
|
-
# neighbors_function(node) # => Array
|
47
|
+
# neighbors_function.call(node) # => Array
|
48
48
|
#
|
49
49
|
# BFS is an informed search algorithm, i.e., it uses an heuristic to select
|
50
50
|
# the probably best next node at any given state. This heuristic is
|