27#ifndef PL_SEARCH_PRED_HPP_
28#define PL_SEARCH_PRED_HPP_
111 class Pred :
public std::enable_shared_from_this<Pred> {
154 virtual bool call() {
return false; }
177 virtual std::string
get_name() {
return typeid(*this).name(); }
205 bool call()
override {
return false; }
212 extern std::shared_ptr<FailPred>
fail_pred;
240 bool call()
override;
342 bool call()
override;
379 bool call()
override;
409 bool call()
override;
445 bool call()
override;
537 bool call()
override;
A base class that represents a choice predicate.
Definition pred.hpp:224
bool call() override
Calls the choice predicate.
Definition pred.cpp:56
virtual bool has_next()=0
Checks if there are more choices available.
virtual bool make_choice()=0
Makes a choice from the available options.
ChoicePred(Trail *trail)
Constructs a ChoicePred that tries available choices.
Definition pred.hpp:231
virtual bool test_choice()
Tests the current choice for validity.
Definition pred.hpp:260
Represents a disjunction of predicates.
Definition pred.hpp:322
bool call() override
Calls the disjunction predicate, iterating through available predicates.
Definition pred.cpp:85
DisjPred(Trail *trail, std::vector< PredPtr > preds)
Constructs a DisjPred with the given predicates.
Definition pred.hpp:333
void set_continuation(PredPtr cont) override
Sets the continuation for all predicates in the disjunction.
Definition pred.cpp:98
std::vector< PredPtr > preds
The predicates in the disjunction.
Definition pred.hpp:353
Represents a failure predicate that always fails when called.
Definition pred.hpp:189
bool call() override
call method for FailPred always returns false, indicating failure.
Definition pred.hpp:205
void set_continuation(PredPtr cont) override
Sets the continuation of the predicate.
Definition pred.hpp:197
FailPred(Trail *trail)
Constructs a FailPred with the given trail -it does nothing and always fails when called.
Definition pred.hpp:196
Represents the equivalent of Prolog if-then-else i.e. (G1 -> G2; G3) - similar to (G1,...
Definition pred.hpp:427
bool call() override
Definition pred.cpp:154
void set_continuation(PredPtr cont) override
Sets the continuation for the then and else predicates to the given continuation which will be the co...
Definition pred.cpp:181
PredPtr then_pred
Definition pred.hpp:449
PredPtr if_pred
Definition pred.hpp:448
PredPtr else_pred
Definition pred.hpp:450
LoopBodyFactory is an abstract base class used for generating instances of a predicate class used in ...
Definition pred.hpp:456
virtual ~LoopBodyFactory()
Definition pred.hpp:466
virtual PredPtr make_body_pred(int depth)=0
Creates a new instance of the body predicate for the loop.
Trail * trail
Definition pred.hpp:458
LoopBodyFactory(Trail *trail)
Constructs a LoopBodyFactory with the given trail.
Definition pred.hpp:464
virtual bool loop_continues(int depth)
Determines if the loop should continue based on the current depth.
Definition pred.hpp:475
Represents a loop predicate that iterates over instances of a predicate.
Definition pred.hpp:521
int depth
Definition pred.hpp:541
Loop(Trail *trail, LoopBodyFactoryPtr bf)
Constructs a predicate that loops over (instances of) a predicate while loop_continues() is true.
Definition pred.hpp:532
bool call() override
Calls the Loop predicate.
Definition pred.cpp:200
Loop(Trail *trail, LoopBodyFactoryPtr bf, int depth)
Definition pred.hpp:535
LoopBodyFactoryPtr body_factory
Definition pred.hpp:523
Represents an equivalent of the Prolog call \+\+Pred. The aim is to determine if Pred succeeds withou...
Definition pred.hpp:394
PredPtr pred
Definition pred.hpp:411
NotNot(Trail *trail, PredPtr pred)
Create the equivalent of Prolog's \+\+p call.
Definition pred.hpp:401
bool call() override
Calls the NotNot predicate.
Definition pred.cpp:127
Represents the equivalent of Prolog's once(Pred). The aim is to remove any choicepoints produced by P...
Definition pred.hpp:365
PredPtr pred
Definition pred.hpp:382
bool call() override
Calls the once predicate.
Definition pred.cpp:112
Once(Trail *trail, PredPtr pred)
Constructs a Once predicate with the given trail and predicate.
Definition pred.hpp:372
Base class for Prolog-like predicates.
Definition pred.hpp:111
Pred(Trail *trail)
Default constructor.
Definition pred.hpp:117
bool call_continuation()
Calls the continuation of the predicate - first call_init and then call.
Definition pred.hpp:163
virtual std::string get_name()
For debugging.
Definition pred.hpp:177
PredPtr continuation
The continuation of the predicate.
Definition pred.hpp:180
virtual void call_init()
Initialize call.
Definition pred.hpp:151
virtual ~Pred()=default
Virtual destructor for proper cleanup.
PredPtr last_pred()
Follows the continuation chain to the last predicate.
Definition pred.cpp:48
virtual bool call()
Definition pred.hpp:154
Trail * trail
Pointer to the trail for managing variable bindings.
Definition pred.hpp:181
PredPtr get_continuation()
Gets the continuation of the predicate.
Definition pred.hpp:123
virtual void set_continuation(PredPtr cont)
Sets the continuation of the predicate.
Definition pred.hpp:129
The Trail class is used to manage variable bindings during the execution of Prolog-like predicates.
Definition trail.hpp:64
Represents a choice predicate that makes choices for a variable from a set of terms.
Definition pred.hpp:271
void call_init() override
Reset index so that all choices are considered when the predicate is (re)called.
Definition pred.hpp:286
bool has_next() override
Checks if there are more choices available.
Definition pred.hpp:292
bool make_choice() override
Makes a choice from the available options.
Definition pred.hpp:298
PVarPtr var
The variable for which choices are made.
Definition pred.hpp:304
size_t index
The current index in the choices vector.
Definition pred.hpp:306
VarChoicePred(Trail *trail, PVarPtr v, std::vector< TermPtr > choices)
Constructs a VarChoicePred with the given trail, variable, and choices.
Definition pred.hpp:279
std::vector< TermPtr > choices
The available choices for the variable.
Definition pred.hpp:305
std::shared_ptr< FailPred > fail_pred
A shared pointer to a reusable failure predicate.
Definition pred.cpp:41
std::string repr(PredPtr pred)
Definition pred.cpp:216
bool unify(TermPtr t1, TermPtr t2, Trail *trail)
Unifies two terms, binding variables as necessary.
Definition term.cpp:165
std::shared_ptr< Pred > PredPtr
Typedef for a shared pointer to a Pred object.
Definition typedefs.hpp:34
PredPtr conjunction(std::vector< PredPtr > preds)
Represents a conjunction of predicates by chaining them together via continuations....
Definition pred.cpp:72
std::shared_ptr< LoopBodyFactory > LoopBodyFactoryPtr
Definition typedefs.hpp:51
std::shared_ptr< PVar > PVarPtr
Definition typedefs.hpp:45
std::shared_ptr< Term > TermPtr
Typedefs for shared pointers to Terms and subclasses.
Definition typedefs.hpp:44
Definition of the Term class.
Definition of the binding trail.
Definition of common typedefs used in the pl_search library.