pl_search_cpp 1.4
Loading...
Searching...
No Matches
Public Member Functions | Private Member Functions | Private Attributes | Friends | List of all members
pl_search::Engine Class Reference

The Engine class manages the execution of predicates and backtracking. More...

#include <engine.hpp>

Public Member Functions

 Engine ()
 
bool unify (TermPtr t1, TermPtr t2)
 Unifies two terms.
 
bool execute (PredPtr p, bool unbind)
 Executes a predicate.
 

Private Member Functions

void trail (PVarPtr v)
 Trails a variable.
 
void backtrack ()
 Performs backtracking.
 
bool call_predicate (PredPtr p)
 Call a predicate.
 
bool retry_predicate (PredPtr p)
 Retries the call on a predicate.
 
bool make_choice_and_continue (PredPtr p)
 Makes the current choice, checks it, and continues execution (using the predicates continuation) if the choice is valid.
 
void push (PredPtr p)
 Pushes a predicate onto the environment stack.
 
void pop_pred_call ()
 Pops the top predicate call from the environment stack.
 
void cut_to_choice_point (int env_index)
 Cuts the environment stack to the choice point at the given index.
 
void clear_stacks ()
 Clears the environment and trail stacks.
 

Private Attributes

std::stack< trail_entry * > trail_stack
 Stack for trail entries.
 
std::stack< env_entry * > env_stack
 Stack for environment entries.
 

Friends

class Cut
 
class DisjPred
 
class IfThenElse
 
class ::EngineTest
 
void Pred::wrap_with_once ()
 

Detailed Description

The Engine class manages the execution of predicates and backtracking.

Execution uses a continuation-passing style for predicates that represent a conjunction of goals. The engine implements backtracking and choice points.

Constructor & Destructor Documentation

◆ Engine()

pl_search::Engine::Engine ( )
inline

Member Function Documentation

◆ backtrack()

void pl_search::Engine::backtrack ( )
private

Performs backtracking.

◆ call_predicate()

bool pl_search::Engine::call_predicate ( PredPtr  p)
private

Call a predicate.

If the call is non-deterministic, the predicate is pushed onto the environment stack before the call. Otherwise the is not pushed and the call is made directly.

Parameters
pThe predicate to call.
Returns
True if the call succeeds, false otherwise.

◆ clear_stacks()

void pl_search::Engine::clear_stacks ( )
private

Clears the environment and trail stacks.

◆ cut_to_choice_point()

void pl_search::Engine::cut_to_choice_point ( int  env_index)
private

Cuts the environment stack to the choice point at the given index.

Parameters
env_indexThe index to cut back to.

◆ execute()

bool pl_search::Engine::execute ( PredPtr  p,
bool  unbind 
)

Executes a predicate.

Parameters
pThe predicate to execute.
unbindWhether to unbind variables after execution.
Returns
True if the execution succeeds, false otherwise.

◆ make_choice_and_continue()

bool pl_search::Engine::make_choice_and_continue ( PredPtr  p)
inlineprivate

Makes the current choice, checks it, and continues execution (using the predicates continuation) if the choice is valid.

Parameters
pThe predicate to make a choice on.
Returns
True if the choice is valid and the predicates continuation succeeds, false otherwise.

◆ pop_pred_call()

void pl_search::Engine::pop_pred_call ( )
private

Pops the top predicate call from the environment stack.

◆ push()

void pl_search::Engine::push ( PredPtr  p)
private

Pushes a predicate onto the environment stack.

Parameters
pThe predicate to push.

◆ retry_predicate()

bool pl_search::Engine::retry_predicate ( PredPtr  p)
private

Retries the call on a predicate.

If the predicate has no more choices, it is popped from the environment stack. Otherwise, the predicate is called. Note that only predicates that have been pushed onto the environment stack can be retried (as they are non-deterministic).

Parameters
pThe predicate to retry.

◆ trail()

void pl_search::Engine::trail ( PVarPtr  v)
private

Trails a variable.

Parameters
vThe variable to trail.

◆ unify()

bool pl_search::Engine::unify ( TermPtr  t1,
TermPtr  t2 
)

Unifies two terms.

Parameters
t1The first term.
t2The second term.
Returns
True if the terms unify, false otherwise.

Friends And Related Symbol Documentation

◆ ::EngineTest

friend class ::EngineTest
friend

◆ Cut

friend class Cut
friend

The following predicates need access to private attributes.

◆ DisjPred

friend class DisjPred
friend

◆ IfThenElse

friend class IfThenElse
friend

◆ Pred::wrap_with_once

void Pred::wrap_with_once ( )
friend

Member Data Documentation

◆ env_stack

std::stack<env_entry *> pl_search::Engine::env_stack
private

Stack for environment entries.

◆ trail_stack

std::stack<trail_entry *> pl_search::Engine::trail_stack
private

Stack for trail entries.


The documentation for this class was generated from the following files: