pl_search_cpp 1.4
|
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 () |
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.
|
inline |
|
private |
Performs backtracking.
|
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.
p | The predicate to call. |
|
private |
Clears the environment and trail stacks.
|
private |
Cuts the environment stack to the choice point at the given index.
env_index | The index to cut back to. |
bool pl_search::Engine::execute | ( | PredPtr | p, |
bool | unbind | ||
) |
Executes a predicate.
p | The predicate to execute. |
unbind | Whether to unbind variables after execution. |
|
inlineprivate |
Makes the current choice, checks it, and continues execution (using the predicates continuation) if the choice is valid.
p | The predicate to make a choice on. |
|
private |
Pops the top predicate call from the environment stack.
|
private |
Pushes a predicate onto the environment stack.
p | The predicate to push. |
|
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).
p | The predicate to retry. |
|
private |
Trails a variable.
v | The variable to trail. |
Unifies two terms.
t1 | The first term. |
t2 | The second term. |
|
friend |
|
friend |
The following predicates need access to private attributes.
|
friend |
|
friend |
|
friend |
|
private |
Stack for environment entries.
|
private |
Stack for trail entries.