pl_search_cpp 2.2
Loading...
Searching...
No Matches
Public Member Functions | Protected Attributes | List of all members
pl_search::VarChoicePred Class Reference

Represents a choice predicate that makes choices for a variable from a set of terms. More...

#include <pred.hpp>

Inheritance diagram for pl_search::VarChoicePred:
Inheritance graph
[legend]
Collaboration diagram for pl_search::VarChoicePred:
Collaboration graph
[legend]

Public Member Functions

 VarChoicePred (Trail *trail, PVarPtr v, std::vector< TermPtr > choices)
 Constructs a VarChoicePred with the given trail, variable, and choices.
 
void call_init () override
 Reset index so that all choices are considered when the predicate is (re)called.
 
bool has_next () override
 Checks if there are more choices available.
 
bool make_choice () override
 Makes a choice from the available options.
 
- Public Member Functions inherited from pl_search::ChoicePred
 ChoicePred (Trail *trail)
 Constructs a ChoicePred that tries available choices.
 
bool call () override
 Calls the choice predicate.
 
virtual bool test_choice ()
 Tests the current choice for validity.
 
- Public Member Functions inherited from pl_search::Pred
 Pred (Trail *trail)
 Default constructor.
 
PredPtr get_continuation ()
 Gets the continuation of the predicate.
 
virtual void set_continuation (PredPtr cont)
 Sets the continuation of the predicate.
 
PredPtr last_pred ()
 Follows the continuation chain to the last predicate.
 
bool call_continuation ()
 Calls the continuation of the predicate - first call_init and then call.
 
virtual ~Pred ()=default
 Virtual destructor for proper cleanup.
 
virtual std::string get_name ()
 For debugging.
 

Protected Attributes

PVarPtr var
 The variable for which choices are made.
 
std::vector< TermPtrchoices
 The available choices for the variable.
 
size_t index
 The current index in the choices vector.
 
- Protected Attributes inherited from pl_search::Pred
PredPtr continuation
 The continuation of the predicate.
 
Trailtrail
 Pointer to the trail for managing variable bindings.
 

Detailed Description

Represents a choice predicate that makes choices for a variable from a set of terms.

The VarChoicePred class is a specific implementation of a choice predicate that makes choices for a variable from a set of terms. It uses the unify function to bind the variable to a term and tests the choice for validity.

Constructor & Destructor Documentation

◆ VarChoicePred()

pl_search::VarChoicePred::VarChoicePred ( Trail trail,
PVarPtr  v,
std::vector< TermPtr choices 
)
inline

Constructs a VarChoicePred with the given trail, variable, and choices.

Parameters
trailPointer to the trail.
vThe variable for which choices are made.
choicesA vector of terms representing the available choices for the variable.

Member Function Documentation

◆ call_init()

void pl_search::VarChoicePred::call_init ( )
inlineoverridevirtual

Reset index so that all choices are considered when the predicate is (re)called.

Reimplemented from pl_search::Pred.

◆ has_next()

bool pl_search::VarChoicePred::has_next ( )
inlineoverridevirtual

Checks if there are more choices available.

Returns
True if there are more choices, false otherwise.

Implements pl_search::ChoicePred.

◆ make_choice()

bool pl_search::VarChoicePred::make_choice ( )
inlineoverridevirtual

Makes a choice from the available options.

Returns
True if a choice is made successfully, false otherwise.

Implements pl_search::ChoicePred.

Member Data Documentation

◆ choices

std::vector<TermPtr> pl_search::VarChoicePred::choices
protected

The available choices for the variable.

◆ index

size_t pl_search::VarChoicePred::index
protected

The current index in the choices vector.

◆ var

PVarPtr pl_search::VarChoicePred::var
protected

The variable for which choices are made.


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