dlvhex
2.5.0
|
Base class for all model generators. More...
#include <include/dlvhex2/BaseModelGenerator.h>
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 |
Base class for all model generators.
Definition at line 103 of file BaseModelGenerator.h.
BaseModelGenerator::BaseModelGenerator | ( | InterpretationConstPtr | input | ) | [inline] |
Constructor.
input | Input 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.
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.
reg | RegistryPtr. |
eatom | The external atom whose input vectors shall be computed. |
i | The input interpretation to the external atom. |
inputs | The 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.
ci | The component whose domain atoms to be computed |
ctx | ProgramCtx |
edb | Set of facts (usually the input model of the component) |
deidb | The IDB used for computing the domain expansion; this is a simplified version of the actual IDB and is computed by addDomainPredicatesAndCreateDomainExplorationProgram. |
deidbInnerEatoms | The 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. |
enumerateNonmonotonic | If 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
eatomID | The external atom to evaluate. |
inputi | Interpretation to use as input to the external atom. |
cb | Callback during evaluation of the external atom (see BaseModelGenerator::ExternalAnswerTupleCallback). |
nogoods | Container to add learned nogoods to (if external learning is enabled), can be NULL. |
assigned | Set of atoms currently assigned; can be used by the external atom to optimize evaluation; can be NULL to indicate that all atoms are assigned. |
changed | Set 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. |
fromCache | Pointer to a bool field which is is stored whether the query was answered from cache (true) or by actual evaluation (false); can be NULL. |
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.
query | See PluginInterface::Query. |
cb | Callback during evaluation of the external atom (see BaseModelGenerator::ExternalAnswerTupleCallback). |
nogoods | Container to add learned nogoods to (if external learning is enabled), can be NULL. |
fromCache | Pointer to a bool field which is is stored whether the query was answered from cache (true) or by actual evaluation (false); can be NULL. |
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.
eatoms | Vector of all external atoms to evaluate. |
inputi | Interpretation to use as input to the external atoms. |
cb | Callback during evaluation of the external atoms (see BaseModelGenerator::ExternalAnswerTupleCallback). |
nogoods | Container to add learned nogoods to (if external learning is enabled), can be NULL. |
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.
ctx | ProgramCtx. |
eatomID | The external atom to evaluate. |
nogoods | Container to add learned nogoods to (if external learning is enabled), can be NULL. |
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().
InterpretationPtr BaseModelGenerator::projectEAtomInputInterpretation | ( | RegistryPtr | reg, |
const ExternalAtom & | eatom, | ||
InterpretationConstPtr | full | ||
) | const [protected, virtual] |
Project a given interpretation to all predicates that are predicate inputs in the given eatom.
reg | RegistryPtr. |
eatom | The external atom whose output patter is to be used for the projection. |
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.
reg | RegistryPtr. |
eatom | The external atom whose output patter is to be used for the verification. |
t | The tuple to verify. |
Definition at line 698 of file BaseModelGenerator.cpp.
References PluginAtom::getPredicate(), ID::isAnonymousVariable(), LOG, LOG_SCOPE, ExternalAtom::pluginAtom, and Atom::tuple.
Referenced by evaluateExternalAtomQuery().
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.