dlvhex  2.5.0
Interpretation Class Reference

Stores a set of atoms efficiently as a bitset. More...

#include <include/dlvhex2/Interpretation.h>

Inheritance diagram for Interpretation:
Collaboration diagram for Interpretation:

Public Types

typedef boost::shared_ptr
< Interpretation
Ptr
typedef boost::shared_ptr
< const Interpretation
ConstPtr
typedef bm::bvector Storage
typedef boost::function< bool(IDAddress)> FilterCallback
typedef Storage::enumerator TrueBitIterator

Public Member Functions

 Interpretation ()
 Constructor.
 Interpretation (RegistryPtr registry)
 Constructor.
virtual ~Interpretation ()
 Destructor.
virtual unsigned filter (FilterCallback callback)
 Go through 1-bits and set to zero if callback returns false.
virtual std::ostream & print (std::ostream &o, const char *first, const char *sep, const char *last) const
 Prints the interpretation.
virtual std::ostream & printWithoutPrefix (std::ostream &o, const char *first, const char *sep, const char *last) const
 Prints the interpretation where atom names are printed without module prefixes (cf.
virtual std::ostream & printAsNumber (std::ostream &o, const char *first, const char *sep, const char *last) const
 Prints the interpretation where atom ID addresses are printed rather than atom names.
virtual std::ostream & print (std::ostream &o) const
 Prints the interpretation in curly braces with comma as atom delimiter.
virtual std::ostream & printWithoutPrefix (std::ostream &o) const
 Prints the interpretation in curly braces with comma as atom delimiter and with atom names printed without module prefixes (cf.
virtual std::ostream & printAsNumber (std::ostream &o) const
 Prints the interpretation where atom ID addresses are printed rather than atom names.
virtual std::ostream & printAsFacts (std::ostream &o) const
 Prints the interpretation as set of facts (each atom follows by a dot).
void add (const Interpretation &other)
 Adds another interpretation to this one.
void bit_and (const Interpretation &other)
 Bit-ands this interpretation with another interpretation one.
Ptr getInterpretationWithoutExternalAtomAuxiliaries () const
 Removed external atom auxiliaries from the interpretation and returns it as a new interpretation.
void setFact (IDAddress id)
 Adds an atom to the interpretation.
void clearFact (IDAddress id)
 Removes an atom from the interpretation.
bool getFact (IDAddress id) const
 Checks if a ground atom is true in the interpretation.
const StoragegetStorage () const
 Returns the internal storage of the interpretation.
StoragegetStorage ()
std::pair< TrueBitIterator,
TrueBitIterator
trueBits () const
 Returns a pair of a begin and an end operator to iterate through true atoms in the interpretation.
const OrdinaryAtomgetAtomToBit (IDAddress addr) const
 Helper function gives ordinary ground atom to true bit.
const OrdinaryAtomgetAtomToBit (TrueBitIterator it) const
 Helper function gives ordinary ground atom to true bit.
RegistryPtr getRegistry () const
void setRegistry (RegistryPtr registry1)
bool isClear () const
 Checks if the interpretation is empty.
void clear ()
 Resets the interpretation to the empty one.
bool operator== (const Interpretation &other) const
 Compares this interpretation atomwise to another one.
bool operator!= (const Interpretation &other) const
 Compares this interpretation atomwise to another one.
bool operator< (const Interpretation &other) const
 Compares this interpretation atomwise to another one and checks if it is a subset of other.
std::size_t getHash () const
 Returns the hash value of this interpretation.

Protected Attributes

RegistryPtr registry
 Regirstry used to interpret IDs when printing.
Storage bits
 Internal bitset storage.
bool hashUpdated
std::size_t myHash

Detailed Description

Stores a set of atoms efficiently as a bitset.

Definition at line 51 of file Interpretation.h.


Member Typedef Documentation

typedef boost::shared_ptr<const Interpretation> Interpretation::ConstPtr

Definition at line 58 of file Interpretation.h.

typedef boost::function<bool (IDAddress)> Interpretation::FilterCallback

Definition at line 60 of file Interpretation.h.

typedef boost::shared_ptr<Interpretation> Interpretation::Ptr

Definition at line 57 of file Interpretation.h.

Definition at line 59 of file Interpretation.h.


Constructor & Destructor Documentation

Constructor.

Definition at line 78 of file Interpretation.h.

Referenced by getInterpretationWithoutExternalAtomAuxiliaries().

Constructor.

Parameters:
registryRegistry to use for interpreting IDs.

Definition at line 59 of file Interpretation.cpp.

Destructor.

Definition at line 66 of file Interpretation.cpp.


Member Function Documentation

void Interpretation::add ( const Interpretation other)

Adds another interpretation to this one.

Parameters:
otherInterpretation to add.

Definition at line 181 of file Interpretation.cpp.

References bits, and hashUpdated.

void Interpretation::bit_and ( const Interpretation other)

Bit-ands this interpretation with another interpretation one.

Parameters:
otherInterpretation to bit-add.

Definition at line 188 of file Interpretation.cpp.

References bits, and hashUpdated.

void Interpretation::clear ( ) [inline]

Resets the interpretation to the empty one.

Definition at line 238 of file Interpretation.h.

void Interpretation::clearFact ( IDAddress  id) [inline]

Removes an atom from the interpretation.

Parameters:
idAddress of a ground atom ID.

Definition at line 183 of file Interpretation.h.

Referenced by filter().

unsigned Interpretation::filter ( FilterCallback  callback) [virtual]

Go through 1-bits and set to zero if callback returns false.

Parameters:
callbackCallback to use.
Returns:
Number of atoms removed from the interpretation.

Definition at line 71 of file Interpretation.cpp.

References bits, clearFact(), bm::bvector< Alloc >::count(), bm::bvector< Alloc >::end(), bm::bvector< Alloc >::first(), and bm::bvector< Alloc >::set().

const OrdinaryAtom& Interpretation::getAtomToBit ( IDAddress  addr) const [inline]

Helper function gives ordinary ground atom to true bit.

Parameters:
addrAddress of an ID of an ordinary ground atom.
Returns:
Shortcut for registry->ogatoms.getByAddress(addr).

Definition at line 212 of file Interpretation.h.

Helper function gives ordinary ground atom to true bit.

Parameters:
itIterator through addresses of IDs of ordinary ground atoms.
Returns:
Shortcut for registry->ogatoms.getByAddress(*it).

Definition at line 220 of file Interpretation.h.

bool Interpretation::getFact ( IDAddress  id) const [inline]

Checks if a ground atom is true in the interpretation.

Parameters:
idAddress of a ground atom ID.

Definition at line 190 of file Interpretation.h.

std::size_t Interpretation::getHash ( ) const

Returns the hash value of this interpretation.

Returns:
Hash value.

Definition at line 232 of file Interpretation.cpp.

References DLVHEX_BENCHMARK_REGISTER_AND_SCOPE, hash_value(), hashUpdated, and myHash.

Referenced by operator!=(), and operator==().

Removed external atom auxiliaries from the interpretation and returns it as a new interpretation.

The original (this) interpretation remains unchanged.

Parameters:
Newinterpretation with external auxiliaries removed.

Definition at line 195 of file Interpretation.cpp.

References bm::bvector< Alloc >::end(), bm::bvector< Alloc >::first(), getStorage(), Interpretation(), and registry.

Definition at line 223 of file Interpretation.h.

const Storage& Interpretation::getStorage ( ) const [inline]

Returns the internal storage of the interpretation.

Returns:
Interpretation as bitset (cf. bitmagic).

Definition at line 197 of file Interpretation.h.

Referenced by getInterpretationWithoutExternalAtomAuxiliaries(), and hash_value().

Definition at line 198 of file Interpretation.h.

bool Interpretation::isClear ( ) const [inline]

Checks if the interpretation is empty.

Returns:
True if there are no true atoms in the interpretation and false otherwise.

Definition at line 232 of file Interpretation.h.

bool Interpretation::operator!= ( const Interpretation other) const

Compares this interpretation atomwise to another one.

Parameters:
otherInterpretation to compare to.
Returns:
True if the interpretations are different and false otherwise.

Definition at line 220 of file Interpretation.cpp.

References bits, and getHash().

bool Interpretation::operator< ( const Interpretation other) const

Compares this interpretation atomwise to another one and checks if it is a subset of other.

Parameters:
otherInterpretation to compare to.
Returns:
True if the interpretations are equal and false otherwise.

Definition at line 227 of file Interpretation.cpp.

References bits.

bool Interpretation::operator== ( const Interpretation other) const

Compares this interpretation atomwise to another one.

Parameters:
otherInterpretation to compare to.
Returns:
True if the interpretations are equal and false otherwise.

Definition at line 213 of file Interpretation.cpp.

References bits, and getHash().

std::ostream & Interpretation::print ( std::ostream &  o,
const char *  first,
const char *  sep,
const char *  last 
) const [virtual]

Prints the interpretation.

Parameters:
oStream to print.
firstString to print at the begining of the output.
sepAtom delimiter.
lastString to print at the end of the output.
Returns:
o.

Definition at line 125 of file Interpretation.cpp.

References bits, bm::bvector< Alloc >::end(), bm::bvector< Alloc >::first(), ID::MAINKIND_ATOM, RawPrinter::print(), registry, and ID::SUBKIND_ATOM_ORDINARYG.

Referenced by print(), and printAsFacts().

std::ostream & Interpretation::print ( std::ostream &  o) const [virtual]

Prints the interpretation in curly braces with comma as atom delimiter.

Parameters:
oStream to print.
Returns:
o.

Reimplemented from InterpretationBase.

Definition at line 97 of file Interpretation.cpp.

References print().

std::ostream & Interpretation::printAsFacts ( std::ostream &  o) const [virtual]

Prints the interpretation as set of facts (each atom follows by a dot).

Parameters:
oStream to print.
Returns:
o.

Definition at line 115 of file Interpretation.cpp.

References bits, bm::bvector< Alloc >::end(), bm::bvector< Alloc >::first(), and print().

std::ostream & Interpretation::printAsNumber ( std::ostream &  o,
const char *  first,
const char *  sep,
const char *  last 
) const [virtual]

Prints the interpretation where atom ID addresses are printed rather than atom names.

Parameters:
oStream to print.
firstString to print at the begining of the output.
sepAtom delimiter.
lastString to print at the end of the output.
Returns:
o.

Definition at line 163 of file Interpretation.cpp.

References bits, bm::bvector< Alloc >::end(), and bm::bvector< Alloc >::first().

Referenced by printAsNumber().

std::ostream & Interpretation::printAsNumber ( std::ostream &  o) const [virtual]

Prints the interpretation where atom ID addresses are printed rather than atom names.

Parameters:
oStream to print.
Returns:
o.

Definition at line 109 of file Interpretation.cpp.

References printAsNumber().

std::ostream & Interpretation::printWithoutPrefix ( std::ostream &  o,
const char *  first,
const char *  sep,
const char *  last 
) const [virtual]

Prints the interpretation where atom names are printed without module prefixes (cf.

modular HEX).

Parameters:
oStream to print.
firstString to print at the begining of the output.
sepAtom delimiter.
lastString to print at the end of the output.
Returns:
o.

Definition at line 144 of file Interpretation.cpp.

References bits, bm::bvector< Alloc >::end(), bm::bvector< Alloc >::first(), ID::MAINKIND_ATOM, RawPrinter::printWithoutPrefix(), registry, and ID::SUBKIND_ATOM_ORDINARYG.

Referenced by printWithoutPrefix().

std::ostream & Interpretation::printWithoutPrefix ( std::ostream &  o) const [virtual]

Prints the interpretation in curly braces with comma as atom delimiter and with atom names printed without module prefixes (cf.

modular HEX).

Parameters:
oStream to print.
Returns:
o.

Definition at line 103 of file Interpretation.cpp.

References printWithoutPrefix().

void Interpretation::setFact ( IDAddress  id) [inline]

Adds an atom to the interpretation.

Parameters:
idAddress of a ground atom ID.

Definition at line 176 of file Interpretation.h.

void Interpretation::setRegistry ( RegistryPtr  registry1) [inline]

Definition at line 226 of file Interpretation.h.

Returns a pair of a begin and an end operator to iterate through true atoms in the interpretation.

Returns:
Pair of a begin and an end operator; dereferencing iterator gives IDAddress.

Definition at line 204 of file Interpretation.h.


Field Documentation

Internal bitset storage.

Definition at line 68 of file Interpretation.h.

Referenced by add(), bit_and(), filter(), operator!=(), operator<(), operator==(), print(), printAsFacts(), printAsNumber(), and printWithoutPrefix().

bool Interpretation::hashUpdated [mutable, protected]

Definition at line 71 of file Interpretation.h.

Referenced by add(), bit_and(), and getHash().

std::size_t Interpretation::myHash [mutable, protected]

Definition at line 74 of file Interpretation.h.

Referenced by getHash().

Regirstry used to interpret IDs when printing.

Definition at line 66 of file Interpretation.h.

Referenced by getInterpretationWithoutExternalAtomAuxiliaries(), print(), and printWithoutPrefix().


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