27#ifndef PL_SEARCH_PRED_HPP_
28#define PL_SEARCH_PRED_HPP_
54class Pred :
public std::enable_shared_from_this<Pred> {
115 std::string
get_name() {
return typeid(
this).name(); }
208 for (
auto it =
preds.begin(); it !=
preds.end(); it++) {
Represents a choice predicate.
Definition pred.hpp:127
ChoicePred(Engine *eng, ChoiceIteratorPtr ch)
Constructs a ChoicePred with the given choice iterator.
Definition pred.hpp:136
ChoiceIteratorPtr choice_iterator
Pointer to the choice iterator.
Definition pred.hpp:129
bool apply_choice() override
Applies a choice for the choice predicate.
Definition pred.cpp:65
bool more_choices() override
Checks if there are more choices for the choice predicate.
Definition pred.cpp:71
void initialize_call() override
Initializes the predicate call.
Definition pred.hpp:139
Represents a Prolog like cut. When called it pops env_stack thus removing choicepoints.
Definition pred.hpp:235
Cut(Engine *eng, int index)
Constructs a Cut predicate.
Definition pred.hpp:243
void set_cut_point(int cut_point)
Definition pred.hpp:249
void initialize_call() override
Initializes the predicate call.
Definition pred.hpp:245
int env_index
Definition pred.hpp:252
bool apply_choice() override
Applies a choice for the cut predicate.
Definition pred.cpp:94
Represents a deterministic predicate.
Definition pred.hpp:167
DetPred(Engine *eng)
Represents a deterministic predicate.
Definition pred.hpp:173
bool apply_choice() override
Noop - all the work is done in initialize_call.
Definition pred.hpp:179
Represents a disjunction of predicates.
Definition pred.hpp:193
bool apply_choice() override
Applies a choice.
Definition pred.hpp:213
void initialize_call() override
Initializes the predicate call.
Definition pred.hpp:206
bool more_choices() override
Checks if there are more choices.
Definition pred.hpp:224
int index
index of the current predicate choice
Definition pred.hpp:228
DisjPred(Engine *eng, std::vector< PredPtr > preds)
Constructs a DisjPred with the given predicates.
Definition pred.hpp:203
std::vector< PredPtr > preds
The predicates in the disjunction.
Definition pred.hpp:227
The Engine class manages the execution of predicates and backtracking.
Definition engine.hpp:69
Represents the equivalent of Prolog if-then-else i.e. (G1 -> G2; G3) - similar to (G1,...
Definition pred.hpp:305
void set_continuation(PredPtr cont)
Sets the continuation of the predicate.
Definition pred.cpp:192
PredPtr then_pred
Definition pred.hpp:324
PredPtr if_then_pred
Definition pred.hpp:326
bool more_choices() override
Checks if there are more choices.
Definition pred.cpp:188
bool apply_choice() override
Applies a choice.
Definition pred.cpp:176
std::shared_ptr< Cut > cut_pred
Definition pred.hpp:327
int choice_number
Definition pred.hpp:328
PredPtr if_pred
Definition pred.hpp:323
void initialize_call() override
Initializes the predicate call.
Definition pred.cpp:168
PredPtr else_pred
Definition pred.hpp:325
LoopBodyFactory is an abstract base class used for generating instances of a predicate class used in ...
Definition pred.hpp:334
virtual ~LoopBodyFactory()
Definition pred.hpp:340
virtual PredPtr make_body_pred()=0
virtual bool loop_continues()=0
LoopBodyFactory(Engine *eng)
Definition pred.hpp:338
Engine * engine
Definition pred.hpp:336
Constructs a predicate that loops over (instances of) a predicate while some condition (loop_continue...
Definition pred.hpp:351
void initialize_call() override
Initializes the predicate call.
Definition pred.cpp:197
PredPtr saved_continuation
Definition pred.hpp:369
LoopBodyFactory * body_factory
Definition pred.hpp:353
Loop(Engine *eng, LoopBodyFactory *bf)
Constructs a predicate that loops over (instances of) a predicate while some condition (loop_continue...
Definition pred.hpp:362
void set_continuation(PredPtr cont)
Sets the continuation for the loop predicate.
Definition pred.cpp:203
bool apply_choice() override
Applies a choice for the loop predicate.
Definition pred.cpp:219
Intended for internal use by NotNot which injects this call directly after the predicate supplied to ...
Definition pred.hpp:259
bool * succeeded
Definition pred.hpp:274
NotNotEnd(Engine *eng, bool *succ)
NotNot::initialize_call uses this to "terminate" the call supplied to NotNot.
Definition pred.hpp:268
bool apply_choice() override
Applies a choice for the not-not-end predicate.
Definition pred.cpp:103
void initialize_call() override
Initializes the predicate call.
Definition pred.hpp:270
Represents an equivalent of the Prolog call \+\+Call. The aim is to determine if Call succeeds withou...
Definition pred.hpp:281
NotNot(Engine *eng, PredPtr p)
Create the equivalent of Prolog's \+\+p call.
Definition pred.hpp:288
PredPtr pred
Definition pred.hpp:295
bool more_choices() override
Checks if there are more choices for the not-not predicate.
Definition pred.cpp:143
bool apply_choice() override
Applies a choice for the not-not predicate.
Definition pred.cpp:125
bool another_choice
Definition pred.hpp:297
bool succeeded
Definition pred.hpp:296
PredPtr saved_continuation
Definition pred.hpp:298
void initialize_call() override
Initializes the call for the not-not predicate.
Definition pred.cpp:111
Abstract base class for Prolog-like predicates.
Definition pred.hpp:54
virtual bool more_choices()
Checks if there are more choices.
Definition pred.hpp:76
Pred(Engine *eng)
Default constructor.
Definition pred.hpp:59
Engine * engine
Definition pred.hpp:119
PredPtr continuation
The continuation of the predicate.
Definition pred.hpp:118
std::string get_name()
For debugging.
Definition pred.hpp:115
virtual void initialize_call()
Initializes the predicate call.
Definition pred.hpp:64
virtual ~Pred()=default
Virtual destructor for proper cleanup.
PredPtr last_pred()
Follows the continuation chain to the last predicate.
Definition pred.cpp:47
virtual bool apply_choice()
Applies a choice.
Definition pred.hpp:70
PredPtr get_continuation()
Gets the continuation of the predicate.
Definition pred.hpp:82
void wrap_with_once()
Wraps the predicate with a once.
Definition pred.cpp:55
virtual void set_continuation(PredPtr cont)
Sets the continuation of the predicate.
Definition pred.hpp:88
bool is_non_det()
Determines if the predicate is non-deterministic.
Definition pred.hpp:100
Represents a semi-deterministic predicate.
Definition pred.hpp:147
bool is_non_det()
Definition pred.hpp:161
bool more_choices() override
Applies a choice.
Definition pred.hpp:159
SemiDetPred(Engine *eng)
Represents a semi-deterministic predicate.
Definition pred.hpp:153
Definition choice_iterator.hpp:16
std::shared_ptr< ChoiceIterator > ChoiceIteratorPtr
Definition pred.hpp:122
std::string repr(PredPtr pred)
Definition pred.cpp:231
std::shared_ptr< Pred > PredPtr
Typedef for a shared pointer to a Pred object.
Definition typedefs.hpp:33
PredPtr conjunction(std::vector< PredPtr > preds)
Represents a conjunction of predicates by chaining them together via continuations.
Definition pred.cpp:78
Definition of the Term class.
Definition of common typedefs used in the pl_search library.