dlvhex  2.5.0
Nogood Class Reference

Stores a set of signed literals which cannot be simultanously true. More...

#include <include/dlvhex2/Nogood.h>

Inheritance diagram for Nogood:
Collaboration diagram for Nogood:

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 Nogoodoperator= (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.

Detailed Description

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).

Definition at line 72 of file Nogood.h.


Constructor & Destructor Documentation

Constructs an empty nogood.

Definition at line 69 of file Nogood.cpp.

Nogood::Nogood ( InterpretationConstPtr  assigned,
InterpretationConstPtr  interpretation 
)

Constructs a nogood from an interpretation.

Parameters:
assignedSet of atoms to respect.
interpretationTruth values of the atoms in assigned.

Definition at line 73 of file Nogood.cpp.

References NogoodContainer::createLiteral(), and insert().


Member Function Documentation

void Nogood::applyVariableSubstitution ( RegistryPtr  reg,
const std::map< ID, ID > &  subst 
)

Substitutes variables in this (nonground) nogood.

Parameters:
regRegistry used to resolve literal IDs.
substVariable 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.

Returns:
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.

Parameters:
regRegistry used to resolve atom IDs.
Returns:
String representation of the nogood.

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().

Renames variables in this nogoods.

Parameters:
regRegistry 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).

Parameters:
litID 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().

template<class InputIterator >
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::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.

Parameters:
atomIDAn atom to be contained in the substitution.
instanceA nogood to contain the substitution in the success case.
Returns:
True if 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.

Parameters:
Nogoodto compare to.
Returns:
Comparison result (antivalence).

Definition at line 130 of file Nogood.cpp.

References operator==().

const Nogood & Nogood::operator= ( const Nogood other)

Overwrites the contents of the nogood with a new one.

Parameters:
otherNogood to copy to this one.
Returns:
Reference to this object.

Definition at line 100 of file Nogood.cpp.

References ground, and hashValue.

bool Nogood::operator== ( const Nogood ng2) const

Compares the nogood to another one.

Parameters:
Nogoodto compare to.
Returns:
Comparison result (equivalence).

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.

Parameters:
oStream to write to.
Returns:
o.

Definition at line 136 of file Nogood.cpp.

References ID::address, and ID::isNaf().

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.

Parameters:
ng2Second nogood.
groundlitadrAddress of a literal which occurs positively in one and negativly in the other nogood.
Returns:
Nogood with 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.

Parameters:
ng2Second nogood.
litID of a literal which occurs positively in one and negativly in the other nogood.
Returns:
Nogood with 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().


Field Documentation

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().


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