dlvhex  2.5.0
BaseModelGenerator Class Reference

Base class for all model generators. More...

#include <include/dlvhex2/BaseModelGenerator.h>

Inheritance diagram for BaseModelGenerator:
Collaboration diagram for BaseModelGenerator:

Data Structures

struct  ExternalAnswerTupleCallback
 Base class for callback functions for handling external atom answer tuples. More...
struct  ExternalAnswerTupleMultiCallback
 Callback function object for handling external atom answer tuples by multiple callbacks. More...
struct  IntegrateExternalAnswerIntoInterpretationCB
 For usual model building where we want to collect all true answers as replacement atoms in an interpretation. More...
struct  VerifyExternalAnswerAgainstPosNegGuessInterpretationCB
 Callback for checking whether external computations reflect guesses of external atom truth values. More...
struct  VerifyExternalAtomCB
 Verifies positive and negative replacement atoms against an external atom. More...

Public Member Functions

 BaseModelGenerator (InterpretationConstPtr input)
 Constructor.
virtual ~BaseModelGenerator ()
 Destructor.

Protected Member Functions

virtual bool evaluateExternalAtom (ProgramCtx &ctx, ID eatomID, InterpretationConstPtr inputi, ExternalAnswerTupleCallback &cb, NogoodContainerPtr nogoods=NogoodContainerPtr(), InterpretationConstPtr assigned=InterpretationConstPtr(), InterpretationConstPtr changed=InterpretationConstPtr(), bool *fromCache=0) const
 Evaluates an external atom.
virtual bool evaluateExternalAtomQuery (PluginAtom::Query &query, ExternalAnswerTupleCallback &cb, NogoodContainerPtr nogoods, bool *fromCache=0) const
 Evaluates an external atom under a single and fixed input vector.
virtual void learnSupportSetsForExternalAtom (ProgramCtx &ctx, ID eatomID, NogoodContainerPtr nogoods) const
 Calculates constant input tuples from auxiliary input predicates and from given constants calls eatom function with each input tuple and maximum input for support set learning.
virtual bool evaluateExternalAtoms (ProgramCtx &ctx, const std::vector< ID > &eatoms, InterpretationConstPtr inputi, ExternalAnswerTupleCallback &cb, NogoodContainerPtr nogoods=NogoodContainerPtr()) const
 Evaluates multiple external atoms.
virtual bool verifyEAtomAnswerTuple (RegistryPtr reg, const ExternalAtom &eatom, const Tuple &t) const
 Checks if an output tuple matches the output pattern in the program.
virtual InterpretationPtr projectEAtomInputInterpretation (RegistryPtr reg, const ExternalAtom &eatom, InterpretationConstPtr full) const
 Project a given interpretation to all predicates that are predicate inputs in the given eatom.
virtual void buildEAtomInputTuples (RegistryPtr reg, const ExternalAtom &eatom, InterpretationConstPtr i, InterpretationPtr inputs) const
 Extracts the ground input vectors from the interpretation.
InterpretationConstPtr computeExtensionOfDomainPredicates (const ComponentGraph::ComponentInfo &ci, ProgramCtx &ctx, InterpretationConstPtr edb, std::vector< ID > &deidb, std::vector< ID > &deidbInnerEatoms, bool enumerateNonmonotonic=true)
 Computes the relevant domain atoms, i.e., the extensions of the domain predicates.

Friends

class UnfoundedSetCheckerOld
class UnfoundedSetChecker
class EncodingBasedUnfoundedSetChecker
class AssumptionBasedUnfoundedSetChecker

Detailed Description

Base class for all model generators.

Definition at line 103 of file BaseModelGenerator.h.


Constructor & Destructor Documentation

Constructor.

Parameters:
inputInput interpretation, i.e., facts to be added before solving.

Definition at line 117 of file BaseModelGenerator.h.

virtual BaseModelGenerator::~BaseModelGenerator ( ) [inline, virtual]

Destructor.

Definition at line 120 of file BaseModelGenerator.h.


Member Function Documentation

void BaseModelGenerator::buildEAtomInputTuples ( RegistryPtr  reg,
const ExternalAtom eatom,
InterpretationConstPtr  i,
InterpretationPtr  inputs 
) const [protected, virtual]

Extracts the ground input vectors from the interpretation.

Using auxiliary input predicate and the eatom, the method calculates all tuples that are inputs to the eatom and store them as true bits into inputs, bits can be looked up in the EAInputTupleCache in registry.

Parameters:
regRegistryPtr.
eatomThe external atom whose input vectors shall be computed.
iThe input interpretation to the external atom.
inputsThe set of input vector extracted from i; each bit can be resolved using Registry::EAInputTupleCache.

Definition at line 769 of file BaseModelGenerator.cpp.

References ExternalAtom::auxInputMapping, ExternalAtom::auxInputPredicate, DBGLOG, DLVHEX_BENCHMARK_REGISTER_AND_SCOPE, ExternalAtom::getAuxInputMask(), ID_FAIL(), ExternalAtom::inputs, LOG_SCOPE, and EAInputTupleCache::lookupOrCreate().

Referenced by evaluateExternalAtom().

InterpretationConstPtr BaseModelGenerator::computeExtensionOfDomainPredicates ( const ComponentGraph::ComponentInfo ci,
ProgramCtx ctx,
InterpretationConstPtr  edb,
std::vector< ID > &  deidb,
std::vector< ID > &  deidbInnerEatoms,
bool  enumerateNonmonotonic = true 
) [protected]

Computes the relevant domain atoms, i.e., the extensions of the domain predicates.

Parameters:
ciThe component whose domain atoms to be computed
ctxProgramCtx
edbSet of facts (usually the input model of the component)
deidbThe IDB used for computing the domain expansion; this is a simplified version of the actual IDB and is computed by addDomainPredicatesAndCreateDomainExplorationProgram.
deidbInnerEatomsThe inner atoms which are relevant for liberal domain-expansion safety; this is a subset of all inner external atoms in the unit and is computed by addDomainPredicatesAndCreateDomainExplorationProgram.
enumerateNonmonotonicIf true, then the inner external atoms in deidbInnerEatoms are evaluated under all possible inputs to make sure that they are fully grounded; otherwise they are evaluated only under the current EDB, but then the grounding might be incomplete and might require incremental expansion.

Definition at line 1113 of file BaseModelGenerator.cpp.

References ID::address, Rule::body, DBGLOG, DLVHEX_BENCHMARK_REGISTER_AND_SCOPE, evaluateExternalAtom(), ExternalAtom::getExtSourceProperties(), PluginAtom::getInputType(), GenuineGrounder::getInstance(), ExternalAtom::getPredicateInputMask(), Rule::head, ModelGeneratorBase< Interpretation >::input, ExternalAtom::inputs, ExtSourceProperties::isAntimonotonic(), ExtSourceProperties::isMonotonic(), ID::MAINKIND_ATOM, ProgramCtx::maxint, ExternalAtom::pluginAtom, ExternalAtom::predicate, PluginAtom::PREDICATE, ComponentGraph::ComponentInfo::predicatesDefinedInComponent, ID::PROPERTY_AUX, ProgramCtx::registry(), ID::SUBKIND_ATOM_ORDINARYG, Atom::tuple, and ExternalAtom::updatePredicateInputMask().

Referenced by GenuineWellfoundedModelGenerator::generateNextModel(), and GenuineGuessAndCheckModelGenerator::GenuineGuessAndCheckModelGenerator().

bool BaseModelGenerator::evaluateExternalAtom ( ProgramCtx ctx,
ID  eatomID,
InterpretationConstPtr  inputi,
ExternalAnswerTupleCallback cb,
NogoodContainerPtr  nogoods = NogoodContainerPtr(),
InterpretationConstPtr  assigned = InterpretationConstPtr(),
InterpretationConstPtr  changed = InterpretationConstPtr(),
bool *  fromCache = 0 
) const [protected, virtual]

Evaluates an external atom.

Projects input interpretation for predicate inputs calculates constant input tuples from auxiliary input predicates and from given constants calls eatom function with each input tuple reintegrates output tuples as auxiliary atoms into outputi (inputi and outputi may point to the same interpretation) fromCache may point to a boolean (or be 0) where the method stored whether the query was answered from cache

Parameters:
eatomIDThe external atom to evaluate.
inputiInterpretation to use as input to the external atom.
cbCallback during evaluation of the external atom (see BaseModelGenerator::ExternalAnswerTupleCallback).
nogoodsContainer to add learned nogoods to (if external learning is enabled), can be NULL.
assignedSet of atoms currently assigned; can be used by the external atom to optimize evaluation; can be NULL to indicate that all atoms are assigned.
changedSet of atoms which possibly changed since last evaluation under the same input; can be used by the external atom to optimize evaluation; can be NULL to indicate that all atoms might have changed.
fromCachePointer to a bool field which is is stored whether the query was answered from cache (true) or by actual evaluation (false); can be NULL.
Returns:
False if process was aborted by callback and true otherwise.

Definition at line 434 of file BaseModelGenerator.cpp.

References ExternalAtom::auxInputPredicate, buildEAtomInputTuples(), DBGLOG, DLVHEX_BENCHMARK_REGISTER_AND_COUNT, DLVHEX_BENCHMARK_REGISTER_AND_SCOPE, BaseModelGenerator::ExternalAnswerTupleCallback::eatom(), evaluateExternalAtomQuery(), PluginAtom::getPredicateID(), ExternalAtom::getPredicateInputMask(), ID_FAIL(), ExternalAtom::inputs, LOG, LOG_SCOPE, EAInputTupleCache::lookup(), ExternalAtom::pluginAtom, ExternalAtom::predicate, projectEAtomInputInterpretation(), ProgramCtx::registry(), Atom::tuple, and ExternalAtom::updatePredicateInputMask().

Referenced by computeExtensionOfDomainPredicates(), evaluateExternalAtoms(), UnfoundedSetChecker::verifyExternalAtomByEvaluation(), and GenuineGuessAndCheckModelGenerator::verifyExternalAtomByEvaluation().

bool BaseModelGenerator::evaluateExternalAtomQuery ( PluginAtom::Query query,
ExternalAnswerTupleCallback cb,
NogoodContainerPtr  nogoods,
bool *  fromCache = 0 
) const [protected, virtual]

Evaluates an external atom under a single and fixed input vector.

Parameters:
querySee PluginInterface::Query.
cbCallback during evaluation of the external atom (see BaseModelGenerator::ExternalAnswerTupleCallback).
nogoodsContainer to add learned nogoods to (if external learning is enabled), can be NULL.
fromCachePointer to a bool field which is is stored whether the query was answered from cache (true) or by actual evaluation (false); can be NULL.
Returns:
False if process was aborted by callback and true otherwise.

Definition at line 554 of file BaseModelGenerator.cpp.

References ExternalAtom::auxInputPredicate, ProgramCtx::config, PluginAtom::Query::ctx, DLVHEX_BENCHMARK_REGISTER_AND_SCOPE, PluginAtom::Query::eatomID, PluginAtom::Answer::get(), Configuration::getOption(), ID_FAIL(), BaseModelGenerator::ExternalAnswerTupleCallback::input(), PluginAtom::Query::input, ExternalAtom::inputs, Logger::Instance(), PluginAtom::Query::interpretation, LOG, BaseModelGenerator::ExternalAnswerTupleCallback::output(), Logger::PLUGIN, ExternalAtom::pluginAtom, printrange(), ProgramCtx::registry(), PluginAtom::retrieveFacade(), Atom::tuple, and verifyEAtomAnswerTuple().

Referenced by evaluateExternalAtom().

bool BaseModelGenerator::evaluateExternalAtoms ( ProgramCtx ctx,
const std::vector< ID > &  eatoms,
InterpretationConstPtr  inputi,
ExternalAnswerTupleCallback cb,
NogoodContainerPtr  nogoods = NogoodContainerPtr() 
) const [protected, virtual]

Evaluates multiple external atoms.

Calls BaseModelGenerator::evaluateExternalAtom for each atom in eatoms.

Parameters:
eatomsVector of all external atoms to evaluate.
inputiInterpretation to use as input to the external atoms.
cbCallback during evaluation of the external atoms (see BaseModelGenerator::ExternalAnswerTupleCallback).
nogoodsContainer to add learned nogoods to (if external learning is enabled), can be NULL.
Returns:
False if process was aborted by callback and true otherwise.

Definition at line 680 of file BaseModelGenerator.cpp.

References evaluateExternalAtom(), and LOG.

Referenced by GenuineWellfoundedModelGenerator::generateNextModel(), WellfoundedModelGenerator::generateNextModel(), PlainModelGenerator::generateNextModel(), GenuineGuessAndCheckModelGenerator::GenuineGuessAndCheckModelGenerator(), GenuinePlainModelGenerator::GenuinePlainModelGenerator(), GuessAndCheckModelGenerator::GuessAndCheckModelGenerator(), and FLPModelGeneratorBase::isCompatibleSet().

void BaseModelGenerator::learnSupportSetsForExternalAtom ( ProgramCtx ctx,
ID  eatomID,
NogoodContainerPtr  nogoods 
) const [protected, virtual]

Calculates constant input tuples from auxiliary input predicates and from given constants calls eatom function with each input tuple and maximum input for support set learning.

Parameters:
ctxProgramCtx.
eatomIDThe external atom to evaluate.
nogoodsContainer to add learned nogoods to (if external learning is enabled), can be NULL.
Returns:
False if process was aborted by callback and true otherwise.

Definition at line 611 of file BaseModelGenerator.cpp.

References ExternalAtom::auxInputPredicate, DBGLOG, DLVHEX_BENCHMARK_REGISTER_AND_SCOPE, ExternalAtom::getAuxInputMask(), ExternalAtom::getExtSourceProperties(), PluginAtom::getPredicateID(), ExternalAtom::getPredicateInputMask(), ID_FAIL(), ExternalAtom::inputs, PluginAtom::learnSupportSets(), LOG_SCOPE, EAInputTupleCache::lookup(), ExternalAtom::pluginAtom, ExternalAtom::predicate, ExtSourceProperties::providesSupportSets(), ProgramCtx::registry(), Atom::tuple, and ExternalAtom::updatePredicateInputMask().

Referenced by GenuineGuessAndCheckModelGenerator::inlineExternalAtoms(), and GenuineGuessAndCheckModelGenerator::learnSupportSets().

Project a given interpretation to all predicates that are predicate inputs in the given eatom.

Parameters:
regRegistryPtr.
eatomThe external atom whose output patter is to be used for the projection.
Returns:
Projection of full as a new interpretation.

Definition at line 752 of file BaseModelGenerator.cpp.

References DLVHEX_BENCHMARK_REGISTER_AND_SCOPE, and ExternalAtom::getPredicateInputMask().

Referenced by evaluateExternalAtom().

bool BaseModelGenerator::verifyEAtomAnswerTuple ( RegistryPtr  reg,
const ExternalAtom eatom,
const Tuple t 
) const [protected, virtual]

Checks if an output tuple matches the output pattern in the program.

Parameters:
regRegistryPtr.
eatomThe external atom whose output patter is to be used for the verification.
tThe tuple to verify.
Returns:
False if tuple does not unify with eatom output pattern (the caller must decide whether to throw an exception or ignore the tuple), and true otherwise.

Definition at line 698 of file BaseModelGenerator.cpp.

References PluginAtom::getPredicate(), ID::isAnonymousVariable(), LOG, LOG_SCOPE, ExternalAtom::pluginAtom, and Atom::tuple.

Referenced by evaluateExternalAtomQuery().


Friends And Related Function Documentation

friend class AssumptionBasedUnfoundedSetChecker [friend]

Definition at line 109 of file BaseModelGenerator.h.

friend class EncodingBasedUnfoundedSetChecker [friend]

Definition at line 108 of file BaseModelGenerator.h.

friend class UnfoundedSetChecker [friend]

Definition at line 107 of file BaseModelGenerator.h.

friend class UnfoundedSetCheckerOld [friend]

Definition at line 106 of file BaseModelGenerator.h.


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