Struct SolutionNode

Source
pub struct SolutionNode<'a> {
    pub goal: Rc<Goal>,
    pub kb: &'a KnowledgeBase,
    pub parent_node: Option<Rc<RefCell<SolutionNode<'a>>>>,
    pub ss: Rc<SubstitutionSet<'a>>,
    pub no_backtracking: bool,
    pub child: Option<Rc<RefCell<SolutionNode<'a>>>>,
    pub rule_index: usize,
    pub number_facts_rules: usize,
    pub head_sn: Option<Rc<RefCell<SolutionNode<'a>>>>,
    pub tail_sn: Option<Rc<RefCell<SolutionNode<'a>>>>,
    pub operator_tail: Option<Operator>,
    pub more_solutions: bool,
}
Expand description

Represents a node in a proof tree.

A solution node holds the goal to be resolved, various parameters concerning that goal, and a reference to the substitution set, which represents the state of the search so far.

Fields§

§goal: Rc<Goal>

The goal which this solution node seeks to resolve.

§kb: &'a KnowledgeBase

Reference to the Knowledge Base.

§parent_node: Option<Rc<RefCell<SolutionNode<'a>>>>

Reference to the parent node in the proof tree.

§ss: Rc<SubstitutionSet<'a>>

Substitution Set - holds the complete or partial solution.

§no_backtracking: bool

Flag used by the Cut operator (!) to prevent backtracking.

§child: Option<Rc<RefCell<SolutionNode<'a>>>>

Refers to the solution node of a rule’s body. (For Complex goals.)

§rule_index: usize

The index of a fact or rule. (For Complex goals.)

§number_facts_rules: usize

The number of facts and rules for the goal above. (For Complex goals.)

§head_sn: Option<Rc<RefCell<SolutionNode<'a>>>>

Head solution node.

§tail_sn: Option<Rc<RefCell<SolutionNode<'a>>>>

Tail solution node. (For And/Or goals.)

§operator_tail: Option<Operator>

Tail of And/Or operator. (For And/Or goals.)

§more_solutions: bool

Flag for built-in predicates, which have only 1 solution.

Implementations§

Source§

impl<'a> SolutionNode<'a>

Source

pub fn new(goal: Rc<Goal>, kb: &'a KnowledgeBase) -> Self

Creates a new SolutionNode struct, with default values.

The parent_node is set to None, and the solution (ss) is initialized to an empty substitution set.

§Usage
use std::rc::Rc;
use suiron::*;

let goal = parse_query("test($X)").unwrap();
let kb   = test_kb();
let node = SolutionNode::new(Rc::new(goal), &kb);
Source

pub fn set_no_backtracking(&mut self)

Sets the no_backtracking flag to true.

The Cut operator (!) calls this method to disable backtracking on the current node and all of its ancestors.

§Note

In order to avoid weeks of whack-a-mole with compiler errors, this method was implemented with ‘unsafe’ code.

§Usage
use std::rc::Rc;
use suiron::*;

let kb = test_kb();
let query = parse_query("test").unwrap();
let solution_node = make_base_node(Rc::new(query), &kb);

solution_node.borrow_mut().set_no_backtracking();

Trait Implementations§

Source§

impl<'a> Clone for SolutionNode<'a>

Source§

fn clone(&self) -> SolutionNode<'a>

Returns a duplicate of the value. Read more
1.0.0 · Source§

const fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<'a> Debug for SolutionNode<'a>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Display for SolutionNode<'_>

Displays a summary of a solution node for debugging purposes.
KB, the substitution set (ss) and tail_sn are excluded. For example:

----- Solution Node -----
	goal: grandfather($X, $Y)
	parent_node: None
	no_backtracking: false
	rule_index: 0
	number_facts_rules: 2
	head_sn: None
	operator_tail: None
-------------------------
Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'a> Freeze for SolutionNode<'a>

§

impl<'a> !RefUnwindSafe for SolutionNode<'a>

§

impl<'a> !Send for SolutionNode<'a>

§

impl<'a> !Sync for SolutionNode<'a>

§

impl<'a> Unpin for SolutionNode<'a>

§

impl<'a> !UnwindSafe for SolutionNode<'a>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.