stdlib/strings: Moved String as abstract, FlatString now the name for array-based...
[nit.git] / lib / a_star.nit
index 0c81a48..3d8112d 100644 (file)
 # Services related to pathfinding of graphs using A*
 # A single graph may have different properties according to the `PathContext` used
 #
+#
 # Usage:
 #
-#    # Weighted graph (letters are nodes, digits are weights):
-#    #
-#    #     a -2- b
-#    #    /     /
-#    #   3     1
-#    #  /     /
-#    # c -3- d -8- e
-#    #
-#    var graph = new Graph[Node,WeigthedLink[Node]]
+# ~~~
+# # Weighted graph (letters are nodes, digits are weights):
+# #
+# #     a -2- b
+# #    /     /
+# #   3     1
+# #  /     /
+# # c -3- d -8- e
+# #
+# var graph = new Graph[Node,WeigthedLink[Node]]
 #
-#    var na = new Node(graph)
-#    var nb = new Node(graph)
-#    var nc = new Node(graph)
-#    var nd = new Node(graph)
-#    var ne = new Node(graph)
+# var na = new Node(graph)
+# var nb = new Node(graph)
+# var nc = new Node(graph)
+# var nd = new Node(graph)
+# var ne = new Node(graph)
 #
-#    var lab = new WeightedLink(graph, na, nb, 2)
-#    var lac = new WeightedLink(graph, na, nc, 3)
-#    var lbd = new WeightedLink(graph, nb, nd, 1)
-#    var lcd = new WeightedLink(graph, nc, nd, 3)
-#    var lde = new WeightedLink(graph, nd, ne, 8)
+# var lab = new WeightedLink(graph, na, nb, 2)
+# var lac = new WeightedLink(graph, na, nc, 3)
+# var lbd = new WeightedLink(graph, nb, nd, 1)
+# var lcd = new WeightedLink(graph, nc, nd, 3)
+# var lde = new WeightedLink(graph, nd, ne, 8)
 #
-#    var context = new WeightedPathContext(graph)
+# var context = new WeightedPathContext(graph)
 #
-#    var path = na.path_to(ne, 100, context)
-#    assert path != null else print "No possible path"
+# var path = na.path_to(ne, 100, context)
+# assert path != null else print "No possible path"
 #
-#    while not path.at_end_of_path do
-#        print path.step
-#    end
+# assert path.step == nb
+# assert path.step == nd
+# assert path.step == ne
+# assert path.at_end_of_path
+# ~~~
 module a_star
 
 redef class Object
@@ -181,42 +185,9 @@ class Node
                        end
                end
        end
-
-       # Find closes node with matching caracteristic
-       # TODO remove closures
-       fun find_closest(max_to_search: Int): nullable N !with(n: N): Bool
-       do
-               if with(self) then return self
-
-               var frontier = new List[N]
-               graph.pathfinding_current_evocation += 1
-               var current_evocation = graph.pathfinding_current_evocation
-
-               frontier.add(self)
-               self.last_pathfinding_evocation = current_evocation
-
-               var i = 0
-               while not frontier.is_empty do
-                       var node = frontier.shift
-
-                       for link in node.links do
-                               var to = link.to
-                               if to.last_pathfinding_evocation != current_evocation then
-                                       if with(to) then return to
-
-                                       frontier.add(to)
-                                       to.last_pathfinding_evocation = current_evocation
-                               end
-                       end
-
-                       i += 1
-                       if i > max_to_search then return null
-               end
-
-               return null
-       end
 end
 
+# Link between two nodes and associated to a graph
 class Link
        type N: Node
        type L: Link