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>
impl<'a> SolutionNode<'a>
Sourcepub fn new(goal: Rc<Goal>, kb: &'a KnowledgeBase) -> Self
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);
Sourcepub fn set_no_backtracking(&mut self)
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>
impl<'a> Clone for SolutionNode<'a>
Source§fn clone(&self) -> SolutionNode<'a>
fn clone(&self) -> SolutionNode<'a>
1.0.0 · Source§const fn clone_from(&mut self, source: &Self)
const fn clone_from(&mut self, source: &Self)
source
. Read moreSource§impl<'a> Debug for SolutionNode<'a>
impl<'a> Debug for SolutionNode<'a>
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:
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 -------------------------