A node in the backtrack-zipper visited by a BacktrackSolver.

The solver visits the virtual search tree with a zipper.

A node is the zipper (this class) is associated to:

  • a state of the problem (indirectly),
  • the actions not yet explored from the state (see totry)
  • the action that yields to the state (see action), used to backtrack.
  • and the parent node in the zipper (see parent).

There is no direct link between a node and a state; it is unneeded since the same state is used, and mutated, during the whole execution of the solver.

This class is exposed to allow queries on the solution provided by the solver.

Introduced properties

fun action: nullable A

ai :: BacktrackNode :: action

The last action executed
protected fun action=(action: nullable A)

ai :: BacktrackNode :: action=

The last action executed
init defaultinit(parent: nullable BacktrackNode[A], action: nullable A, depth: Int, steps: Int)

ai :: BacktrackNode :: defaultinit

fun depth: Int

ai :: BacktrackNode :: depth

The depth of self in the search-tree.
protected fun depth=(depth: Int)

ai :: BacktrackNode :: depth=

The depth of self in the search-tree.
fun parent: nullable BacktrackNode[A]

ai :: BacktrackNode :: parent

The previous node in the backtrack-zipper
protected fun parent=(parent: nullable BacktrackNode[A])

ai :: BacktrackNode :: parent=

The previous node in the backtrack-zipper
fun path: Sequence[BacktrackNode[A]]

ai :: BacktrackNode :: path

Build a sequence of nodes from the initial node to self
fun plan: Sequence[A]

ai :: BacktrackNode :: plan

Build a sequence of actions from the initial state to self
fun steps: Int

ai :: BacktrackNode :: steps

The number of steps needed by the solver to process self.
protected fun steps=(steps: Int)

ai :: BacktrackNode :: steps=

The number of steps needed by the solver to process self.
fun totry: nullable Array[A]

ai :: BacktrackNode :: totry

The remaining actions to try from this node
protected fun totry=(totry: nullable Array[A])

ai :: BacktrackNode :: totry=

The remaining actions to try from this node

Redefined properties

redef type SELF: BacktrackNode[A]

ai $ BacktrackNode :: SELF

Type of this instance, automatically specialized in every class
redef fun to_s: String

ai $ BacktrackNode :: to_s

User readable representation of self.

All properties

fun !=(other: nullable Object): Bool

core :: Object :: !=

Have self and other different values?
fun ==(other: nullable Object): Bool

core :: Object :: ==

Have self and other the same value?
type CLASS: Class[SELF]

core :: Object :: CLASS

The type of the class of self.
type SELF: Object

core :: Object :: SELF

Type of this instance, automatically specialized in every class
fun action: nullable A

ai :: BacktrackNode :: action

The last action executed
protected fun action=(action: nullable A)

ai :: BacktrackNode :: action=

The last action executed
protected fun class_factory(name: String): CLASS

core :: Object :: class_factory

Implementation used by get_class to create the specific class.
fun class_name: String

core :: Object :: class_name

The class name of the object.
init defaultinit(parent: nullable BacktrackNode[A], action: nullable A, depth: Int, steps: Int)

ai :: BacktrackNode :: defaultinit

fun depth: Int

ai :: BacktrackNode :: depth

The depth of self in the search-tree.
protected fun depth=(depth: Int)

ai :: BacktrackNode :: depth=

The depth of self in the search-tree.
fun get_class: CLASS

core :: Object :: get_class

The meta-object representing the dynamic type of self.
fun hash: Int

core :: Object :: hash

The hash code of the object.
init init

core :: Object :: init

fun inspect: String

core :: Object :: inspect

Developer readable representation of self.
protected fun inspect_head: String

core :: Object :: inspect_head

Return "CLASSNAME:#OBJECTID".
intern fun is_same_instance(other: nullable Object): Bool

core :: Object :: is_same_instance

Return true if self and other are the same instance (i.e. same identity).
fun is_same_serialized(other: nullable Object): Bool

core :: Object :: is_same_serialized

Is self the same as other in a serialization context?
intern fun is_same_type(other: Object): Bool

core :: Object :: is_same_type

Return true if self and other have the same dynamic type.
intern fun object_id: Int

core :: Object :: object_id

An internal hash code for the object based on its identity.
fun output

core :: Object :: output

Display self on stdout (debug only).
intern fun output_class_name

core :: Object :: output_class_name

Display class name on stdout (debug only).
fun parent: nullable BacktrackNode[A]

ai :: BacktrackNode :: parent

The previous node in the backtrack-zipper
protected fun parent=(parent: nullable BacktrackNode[A])

ai :: BacktrackNode :: parent=

The previous node in the backtrack-zipper
fun path: Sequence[BacktrackNode[A]]

ai :: BacktrackNode :: path

Build a sequence of nodes from the initial node to self
fun plan: Sequence[A]

ai :: BacktrackNode :: plan

Build a sequence of actions from the initial state to self
fun serialization_hash: Int

core :: Object :: serialization_hash

Hash value use for serialization
fun steps: Int

ai :: BacktrackNode :: steps

The number of steps needed by the solver to process self.
protected fun steps=(steps: Int)

ai :: BacktrackNode :: steps=

The number of steps needed by the solver to process self.
intern fun sys: Sys

core :: Object :: sys

Return the global sys object, the only instance of the Sys class.
abstract fun to_jvalue(env: JniEnv): JValue

core :: Object :: to_jvalue

fun to_s: String

core :: Object :: to_s

User readable representation of self.
fun totry: nullable Array[A]

ai :: BacktrackNode :: totry

The remaining actions to try from this node
protected fun totry=(totry: nullable Array[A])

ai :: BacktrackNode :: totry=

The remaining actions to try from this node
package_diagram ai::BacktrackNode BacktrackNode core::Object Object ai::BacktrackNode->core::Object

Parents

interface Object

core :: Object

The root of the class hierarchy.

Class definitions

ai $ BacktrackNode
# A node in the backtrack-zipper visited by a `BacktrackSolver`.
#
# The solver visits the virtual search tree with a zipper.
#
# A node is the zipper (this class) is associated to:
# * a state of the problem (indirectly),
# * the actions not yet explored from the state (see `totry`)
# * the action that yields to the state (see `action`), used to backtrack.
# * and the parent node in the zipper (see `parent`).
#
# There is no direct link between a node and a state; it is unneeded
# since the same state is used, and mutated, during the whole execution of the solver.
#
# This class is exposed to allow queries on the solution provided by the solver.
class BacktrackNode[A]
	# The previous node in the backtrack-zipper
	var parent: nullable BacktrackNode[A]

	# The last action executed
	var action: nullable A

	# The remaining actions to try from this node
	var totry: nullable Array[A] = null

	# The depth of `self` in the search-tree.
	var depth: Int

	# The number of steps needed by the solver to process `self`.
	# This is just a useless generation number, but could be used to evaluate
	# the behavior of search algorithms.
	var steps: Int

	# Build a sequence of nodes from the initial node to `self`
	# ensure `result.first.parent == null and result.last == self`
	fun path: Sequence[BacktrackNode[A]]
	do
		var res = new List[BacktrackNode[A]]
		res.add(self)
		var node = parent
		while node != null do
			res.unshift(node)
			node = node.parent
		end
		return res
	end

	# Build a sequence of actions from the initial state to `self`
	# See `path` for a more detailed plan.
	fun plan: Sequence[A]
	do
		var res = new List[A]
		var node: nullable BacktrackNode[A] = self
		while node != null do
			var a = node.action
			if a != null then res.unshift(a)
			node = node.parent
		end
		return res
	end

	redef fun to_s do
		var res = "#{steps} d={depth}"
		var tt = totry
		if tt != null then res += " tt={tt.join(" ")}"
		return res
	end
end
lib/ai/backtrack.nit:234,1--300,3