# The module provides a simple abstract class `SearchProblem[S,A]` to be specialized for a specific problem.
#
# The concrete class `SearchSolver` is used to configure, query, and run a solver for a given problem.
+#
+# For an example, see the `puzzle.nit` program in the `examples` subdirectory.
module search
import realtime
# An heuristic of the estimated `cost` going from `state` to a goal state.
#
# Is is expected that the heuristic is *admissible*, it means its is an
- # optimistic estimation that never an over-estimate, thus is cannot be#
+ # optimistic estimation and never an over-estimate, thus is cannot be
# higher than the lowest possible remaining cost.
# See `SearchSolver::do_revisit` for details.
#
# `steps` is the maximum number of steps a giver configuration can run.
fun run_configs(steps: Int)
do
- var s
-
var c = 0
loop
if astar.run_config(steps, c, "A*") then break
# 2. Apply the method `run`, that will search and return a solution.
# 3. Retrieve information from the solution.
#
-# ~~~~
+# ~~~~nitish
# var p: SearchProblem = new MyProblem
# var res = p.astar.run
# if res != null then print "Found plan with {res.depth} actions, that cost {res.cost}: {res.plan.join(", ")}"
print msg
var t = new Clock
- var res = run_steps(steps)
+ run_steps(steps)
print "\t{self}"
var l = t.lapse
print "\ttime={l}"
# Used to compare nodes with their score.
# Smaller is score, smaller is the node.
private class NodeComparator[S: Object, A]
- super Comparator[SearchNode[S, A]]
+ super Comparator
+ redef type COMPARED: SearchNode[S, A]
redef fun compare(a,b) do return a.score <=> b.score
end
print "result:{state}"
for n in path do
var a = n.action
- if a != null then print " + {a or else ""}"
+ if a != null then print " + {a}"
print " {n.steps}: {n.state} ({n.cost}$)"
end
end