dlvhex
2.5.0
|
Stores a set of signed literals which cannot be simultanously true. More...
#include <include/dlvhex2/Nogood.h>
Public Member Functions | |
Nogood () | |
Constructs an empty nogood. | |
Nogood (InterpretationConstPtr assigned, InterpretationConstPtr interpretation) | |
Constructs a nogood from an interpretation. | |
void | recomputeHash () |
Recomputes the hash after literals were added. | |
size_t | getHash () |
Returns the hash of the nogood. | |
const Nogood & | operator= (const Nogood &other) |
Overwrites the contents of the nogood with a new one. | |
bool | operator== (const Nogood &ng2) const |
Compares the nogood to another one. | |
bool | operator!= (const Nogood &ng2) const |
Compares the nogood to another one. | |
std::ostream & | print (std::ostream &o) const |
Prints the nogood in numeric format. | |
std::string | getStringRepresentation (RegistryPtr reg) const |
Prints the nogood in string format. | |
Nogood | resolve (const Nogood &ng2, IDAddress groundlitadr) |
Performs resolution on this nogood with another one using a given ground literal. | |
Nogood | resolve (const Nogood &ng2, ID lit) |
Performs resolution on this nogood with another one using a given literal ID. | |
void | applyVariableSubstitution (RegistryPtr reg, const std::map< ID, ID > &subst) |
Substitutes variables in this (nonground) nogood. | |
void | heuristicNormalization (RegistryPtr reg) |
Renames variables in this nogoods. | |
void | insert (ID lit) |
Adds a literal to this nogood. | |
template<class InputIterator > | |
void | insert (InputIterator begin, InputIterator end) |
bool | isGround () const |
Checks groundness of this nogood. | |
bool | match (RegistryPtr reg, ID atomID, Nogood &instance) const |
Checks if there is a substitution of variables in this nogood such that atomID occurs in the substitution and computes the instance of the nogood in that case. | |
std::string | dbgsave () const |
void | dbgload (std::string str) |
Private Attributes | |
std::size_t | hashValue |
Hash value of the nogood for indexing purposes. | |
bool | ground |
True if the nogood is ground and false otherwise. |
Stores a set of signed literals which cannot be simultanously true.
A nogood is used to restrict the search space. To this end, they contain signed literals (that is, positive or negative atoms) which cannot be simultanously true in a compatible set.
In dlvhex, they are mainly used to encode conditions which contradict the semantics of external atoms. For instance, the nogood { p(a), -q(a), -&diff[p,q](a) } encodes that whenever the atom p(a) is true and the atom q(a) is false, then the atom &diff[p,q](a) must be true (i.e. must not be false) since constant a will be in the output of the set difference of p and q.
Note: For constructing external source output atoms (such as &diff[p,q](a)), use the method ExternalLearningHelper::getOutputAtom.
Nogoods can be added to the reasoner in the method PluginAtom::retrieve. When adding dlvhex IDs to a nogood, they need to be passed through NogoodContainer::createLiteral to strip off property flags (Nogood::insert performs this step automatically).
Nogood::Nogood | ( | ) |
Constructs an empty nogood.
Definition at line 69 of file Nogood.cpp.
Nogood::Nogood | ( | InterpretationConstPtr | assigned, |
InterpretationConstPtr | interpretation | ||
) |
Constructs a nogood from an interpretation.
assigned | Set of atoms to respect. |
interpretation | Truth values of the atoms in assigned . |
Definition at line 73 of file Nogood.cpp.
References NogoodContainer::createLiteral(), and insert().
void Nogood::applyVariableSubstitution | ( | RegistryPtr | reg, |
const std::map< ID, ID > & | subst | ||
) |
Substitutes variables in this (nonground) nogood.
reg | Registry used to resolve literal IDs. |
subst | Variable substitution of pairs (X,Y) to replace variable X by Y. |
Definition at line 203 of file Nogood.cpp.
References ID::address, NogoodContainer::createLiteral(), DBGLOG, getStringRepresentation(), insert(), and Atom::tuple.
Referenced by SimpleNogoodContainer::addAllResolvents(), and heuristicNormalization().
void Nogood::dbgload | ( | std::string | str | ) |
Definition at line 367 of file Nogood.cpp.
References NogoodContainer::createLiteral(), and insert().
std::string Nogood::dbgsave | ( | ) | const |
Definition at line 357 of file Nogood.cpp.
size_t Nogood::getHash | ( | ) |
Returns the hash of the nogood.
Definition at line 94 of file Nogood.cpp.
References hashValue.
Referenced by NogoodSet::addNogood(), ExternalLearningHelper::learnFromInputOutputBehavior(), ExternalLearningHelper::learnFromNegativeAtoms(), and NogoodSet::removeNogood().
std::string Nogood::getStringRepresentation | ( | RegistryPtr | reg | ) | const |
Prints the nogood in string format.
reg | Registry used to resolve atom IDs. |
Definition at line 152 of file Nogood.cpp.
References ID::address, ID::isNaf(), ID::isOrdinaryGroundAtom(), and RawPrinter::print().
Referenced by SimpleNogoodContainer::addAllResolvents(), GenuineGuessAndCheckModelGeneratorFactory::addInconsistencyCauseFromSuccessor(), GenuineGuessAndCheckModelGenerator::addNogood(), applyVariableSubstitution(), EncodingBasedUnfoundedSetChecker::constructUFSDetectionProblemOptimizationPartLearnedFromMainSearch(), GenuineGuessAndCheckModelGenerator::generalizeNogood(), PluginAtom::generalizeNogood(), GenuineGuessAndCheckModelGenerator::generateNextModel(), InternalGroundASPSolver::getImplicationGraphAsDotString(), InternalGroundASPSolver::getInconsistencyCause(), NogoodSet::getStringRepresentation(), UnfoundedSetChecker::getUFSNogoodUFSBased(), heuristicNormalization(), GenuineGuessAndCheckModelGenerator::identifyInconsistencyCause(), GenuineGuessAndCheckModelGenerator::inlineExternalAtoms(), ExternalLearningHelper::learnFromFunctionality(), ExternalLearningHelper::learnFromGroundRule(), ExternalLearningHelper::learnFromInputOutputBehavior(), ExternalLearningHelper::learnFromNegativeAtoms(), AssumptionBasedUnfoundedSetChecker::learnNogoodsFromMainSearch(), GenuineGuessAndCheckModelGenerator::learnSupportSets(), ExternalLearningHelper::DefaultInputNogoodProvider::operator()(), TestASPQueryAtom::retrieveOrLearnSupportSets(), ImmediateNogoodGrounder::update(), LazyNogoodGrounder::update(), GenuineGuessAndCheckModelGenerator::updateEANogoods(), UnfoundedSetChecker::verifyExternalAtomByEvaluation(), and AnnotatedGroundProgram::verifyExternalAtomsUsingCompleteSupportSets().
void Nogood::heuristicNormalization | ( | RegistryPtr | reg | ) |
Renames variables in this nogoods.
reg | Registry used to resolve literal IDs. |
Definition at line 226 of file Nogood.cpp.
References applyVariableSubstitution(), DBGLOG, getStringRepresentation(), isGround(), and Atom::tuple.
void Nogood::insert | ( | ID | lit | ) |
Adds a literal to this nogood.
Note: Before adding, the literal is passed through NogoodContainer::createLiteral to translate it into a uniform form (strip off property flags from the ID).
lit | ID of the literal to add. |
Reimplemented from Set< ID >.
Definition at line 280 of file Nogood.cpp.
References NogoodContainer::createLiteral(), ground, and ID::isOrdinaryGroundAtom().
Referenced by CDNLSolver::addNogoodAndUpdateWatchingStructures(), applyVariableSubstitution(), AssumptionBasedUnfoundedSetChecker::constructUFSDetectionProblemBasicEABehavior(), AssumptionBasedUnfoundedSetChecker::constructUFSDetectionProblemDefineAuxiliaries(), AssumptionBasedUnfoundedSetChecker::constructUFSDetectionProblemFacts(), EncodingBasedUnfoundedSetChecker::constructUFSDetectionProblemNecessaryPart(), AssumptionBasedUnfoundedSetChecker::constructUFSDetectionProblemNonempty(), EncodingBasedUnfoundedSetChecker::constructUFSDetectionProblemOptimizationPartBasicEAKnowledge(), EncodingBasedUnfoundedSetChecker::constructUFSDetectionProblemOptimizationPartEAEnforement(), EncodingBasedUnfoundedSetChecker::constructUFSDetectionProblemOptimizationPartRestrictToCompatibleSet(), AssumptionBasedUnfoundedSetChecker::constructUFSDetectionProblemRestrictToSCC(), AssumptionBasedUnfoundedSetChecker::constructUFSDetectionProblemRule(), InternalGroundASPSolver::createNogoodsForRule(), InternalGroundASPSolver::createNogoodsForRuleBody(), InternalGroundASPSolver::createSingularLoopNogoods(), dbgload(), PluginAtom::generalizeNogood(), FLPModelGeneratorBase::getFLPNogood(), InternalGroundASPSolver::getInconsistencyCause(), InternalGroundASPSolver::getLoopNogood(), UnfoundedSetChecker::getUFSNogoodReductBased(), UnfoundedSetChecker::getUFSNogoodUFSBased(), CDNLSolver::handlePreviousModel(), ExternalLearningHelper::learnFromFunctionality(), ExternalLearningHelper::learnFromGroundRule(), ExternalLearningHelper::learnFromInputOutputBehavior(), ExternalLearningHelper::learnFromNegativeAtoms(), match(), Nogood(), EncodingBasedUnfoundedSetChecker::nogoodTransformation(), AssumptionBasedUnfoundedSetChecker::nogoodTransformation(), ExternalLearningHelper::DefaultInputNogoodProvider::operator()(), resolve(), CDNLSolver::resolve(), TestSetMinusNogoodBasedLearningAtom::retrieve(), TestSetMinusNongroundNogoodBasedLearningAtom::retrieve(), TestPlugin::TestSetUnionAtom::retrieve(), TestASPQueryAtom::retrieveOrLearnSupportSets(), and ImmediateNogoodGrounder::update().
void Nogood::insert | ( | InputIterator | begin, |
InputIterator | end | ||
) | [inline] |
Definition at line 178 of file Nogood.h.
References Set< T >::end(), and Set< T >::insert().
bool Nogood::isGround | ( | ) | const |
Checks groundness of this nogood.
Definition at line 291 of file Nogood.cpp.
References ground.
Referenced by CDNLSolver::addNogoodAndUpdateWatchingStructures(), EncodingBasedUnfoundedSetChecker::constructUFSDetectionProblemOptimizationPartLearnedFromMainSearch(), GenuineGuessAndCheckModelGenerator::generalizeNogood(), PluginAtom::generalizeNogood(), PluginAtom::guardSupportSet(), heuristicNormalization(), GenuineGuessAndCheckModelGenerator::inlineExternalAtoms(), AssumptionBasedUnfoundedSetChecker::learnNogoodsFromMainSearch(), GenuineGuessAndCheckModelGenerator::learnSupportSets(), match(), ImmediateNogoodGrounder::update(), LazyNogoodGrounder::update(), GenuineGuessAndCheckModelGenerator::updateEANogoods(), UnfoundedSetChecker::verifyExternalAtomByEvaluation(), and AnnotatedGroundProgram::verifyExternalAtomsUsingCompleteSupportSets().
bool Nogood::match | ( | RegistryPtr | reg, |
ID | atomID, | ||
Nogood & | instance | ||
) | const |
Checks if there is a substitution of variables in this nogood such that atomID
occurs in the substitution and computes the instance of the nogood in that case.
atomID | An atom to be contained in the substitution. |
instance | A nogood to contain the substitution in the success case. |
atomID
could be matched to this nogood. Definition at line 297 of file Nogood.cpp.
References ID::ALL_ONES, NogoodContainer::createLiteral(), DBGLOG, ground, insert(), isGround(), ID::isNaf(), ID::isOrdinaryGroundAtom(), ID::isVariableTerm(), Atom::kind, ID::SUBKIND_ATOM_ORDINARYG, ID::SUBKIND_MASK, Atom::tuple, and OrdinaryAtom::unifiesWith().
Referenced by ImmediateNogoodGrounder::update().
bool Nogood::operator!= | ( | const Nogood & | ng2 | ) | const |
Compares the nogood to another one.
Nogood | to compare to. |
Definition at line 130 of file Nogood.cpp.
References operator==().
Overwrites the contents of the nogood with a new one.
other | Nogood to copy to this one. |
Definition at line 100 of file Nogood.cpp.
bool Nogood::operator== | ( | const Nogood & | ng2 | ) | const |
Compares the nogood to another one.
Nogood | to compare to. |
Definition at line 109 of file Nogood.cpp.
References Set< T >::begin(), Set< ID >::end(), hashValue, Set< T >::size(), and Set< ID >::size().
Referenced by operator!=().
std::ostream & Nogood::print | ( | std::ostream & | o | ) | const |
Prints the nogood in numeric format.
o | Stream to write to. |
o
. Definition at line 136 of file Nogood.cpp.
References ID::address, and ID::isNaf().
void Nogood::recomputeHash | ( | ) |
Recomputes the hash after literals were added.
Definition at line 84 of file Nogood.cpp.
References ID::address, hashValue, and ID::kind.
Referenced by NogoodSet::addNogood(), and NogoodSet::removeNogood().
Nogood Nogood::resolve | ( | const Nogood & | ng2, |
IDAddress | groundlitadr | ||
) |
Performs resolution on this nogood with another one using a given ground literal.
ng2 | Second nogood. |
groundlitadr | Address of a literal which occurs positively in one and negativly in the other nogood. |
groundlitadr
being resolved from this nogood union ng2
. Definition at line 177 of file Nogood.cpp.
References Set< T >::begin(), NogoodContainer::createLiteral(), DBGLOG, Set< T >::end(), Set< T >::erase(), insert(), Set< T >::size(), and Set< ID >::size().
Referenced by SimpleNogoodContainer::addAllResolvents().
Nogood Nogood::resolve | ( | const Nogood & | ng2, |
ID | lit | ||
) |
Performs resolution on this nogood with another one using a given literal ID.
ng2 | Second nogood. |
lit | ID of a literal which occurs positively in one and negativly in the other nogood. |
lit
being resolved from this nogood union ng2
. Definition at line 190 of file Nogood.cpp.
References ID::address, Set< T >::begin(), NogoodContainer::createLiteral(), DBGLOG, Set< T >::end(), Set< T >::erase(), insert(), ID::isOrdinaryGroundAtom(), Set< ID >::size(), and Set< T >::size().
bool Nogood::ground [private] |
True if the nogood is ground and false otherwise.
Definition at line 79 of file Nogood.h.
Referenced by insert(), isGround(), match(), and operator=().
std::size_t Nogood::hashValue [private] |
Hash value of the nogood for indexing purposes.
Definition at line 76 of file Nogood.h.
Referenced by getHash(), operator=(), operator==(), and recomputeHash().