Package net.sf.tweety.logics.pl.util
Class CanonicalIterator
- java.lang.Object
-
- net.sf.tweety.logics.pl.util.CanonicalIterator
-
- All Implemented Interfaces:
java.util.Iterator<PlBeliefSet>
,BeliefSetIterator<PlFormula,PlBeliefSet>
public class CanonicalIterator extends java.lang.Object implements BeliefSetIterator<PlFormula,PlBeliefSet>
Provides an iterator on all syntactically equivalent knowledge bases.- Author:
- Matthias Thimm
-
-
Field Summary
Fields Modifier and Type Field Description private java.math.BigInteger
next
The next value used for compiling a knowledge base.private java.math.BigInteger
upperBoundIndex
The upper bound used for enumerating knowledge bases.
-
Constructor Summary
Constructors Constructor Description CanonicalIterator()
Default constructor.CanonicalIterator(java.lang.Integer startIndex)
Creates a new enumerator that enumerates knowledge bases starting from the given indexCanonicalIterator(java.lang.Integer startIndex, java.lang.Integer endIndex)
Creates a new enumerator that enumerates knowledge bases starting from the given start index up to the given end index (including)CanonicalIterator(java.lang.Long startIndex)
Creates a new enumerator that enumerates knowledge bases starting from the given indexCanonicalIterator(java.lang.Long startIndex, java.lang.Long endIndex)
Creates a new enumerator that enumerates knowledge bases starting from the given start index up to the given end index (including)CanonicalIterator(java.math.BigInteger startIndex)
Creates a new enumerator that enumerates knowledge bases starting from the given indexCanonicalIterator(java.math.BigInteger startIndex, java.math.BigInteger endIndex)
Creates a new enumerator that enumerates knowledge bases starting from the given start index up to the given end index (including)
-
Method Summary
Modifier and Type Method Description static java.util.BitSet
beliefSet2BitSet(PlBeliefSet bs)
Creates a bitset representation of the given belief set.private PlBeliefSet
bitset2BeliefSet(java.util.BitSet s)
Parses a knowledge base (PlBeliefSet) from the the given bitset.private static java.lang.String
formula2String(PlFormula f, java.util.Map<Proposition,java.lang.Integer> prop)
Encodes the given formula as a bitstring.private void
gotoNextValidIndex()
Sets this.next to the next value actually encoding a belief base (or to this.upperBoundIndex if set).boolean
hasNext()
private boolean
isLessThan(java.util.BitSet s, boolean equal, int i, int j, int k, int l)
Checks whether the bitvector at positions [i,...,j] is less than the bitvector at positions [k,...,l].PlBeliefSet
next()
java.math.BigInteger
nextIndex()
Returns the index of the next element.private Pair<java.util.Collection<PlFormula>,java.lang.Integer>
parseAssociativeFormula(java.util.BitSet s, int idx, int numOfTerms, PlSignature sig)
Parses an associate formula from the given bitset starting at index idx, with the given number of terms and the given signatureprivate Pair<PlFormula,java.lang.Integer>
parseFormula(java.util.BitSet s, int idx, PlSignature sig)
Reads the next formula of the given bitset, starting at the given index.private Pair<PlFormula,java.lang.Integer>
parseProposition(java.util.BitSet s, int idx, PlSignature sig)
Parses a proposition in bitset s starting from idx.
-
-
-
Constructor Detail
-
CanonicalIterator
public CanonicalIterator()
Default constructor. Creates an enumerator that enumerates knowledge bases starting from index 1.
-
CanonicalIterator
public CanonicalIterator(java.lang.Long startIndex)
Creates a new enumerator that enumerates knowledge bases starting from the given index- Parameters:
startIndex
- some integer value
-
CanonicalIterator
public CanonicalIterator(java.lang.Integer startIndex)
Creates a new enumerator that enumerates knowledge bases starting from the given index- Parameters:
startIndex
- some integer value
-
CanonicalIterator
public CanonicalIterator(java.math.BigInteger startIndex)
Creates a new enumerator that enumerates knowledge bases starting from the given index- Parameters:
startIndex
- some integer value
-
CanonicalIterator
public CanonicalIterator(java.lang.Long startIndex, java.lang.Long endIndex)
Creates a new enumerator that enumerates knowledge bases starting from the given start index up to the given end index (including)- Parameters:
startIndex
- some integer valueendIndex
- some integer value
-
CanonicalIterator
public CanonicalIterator(java.lang.Integer startIndex, java.lang.Integer endIndex)
Creates a new enumerator that enumerates knowledge bases starting from the given start index up to the given end index (including)- Parameters:
startIndex
- some integer valueendIndex
- some integer value
-
CanonicalIterator
public CanonicalIterator(java.math.BigInteger startIndex, java.math.BigInteger endIndex)
Creates a new enumerator that enumerates knowledge bases starting from the given start index up to the given end index (including)- Parameters:
startIndex
- some integer valueendIndex
- some integer value
-
-
Method Detail
-
gotoNextValidIndex
private void gotoNextValidIndex()
Sets this.next to the next value actually encoding a belief base (or to this.upperBoundIndex if set).
-
isLessThan
private boolean isLessThan(java.util.BitSet s, boolean equal, int i, int j, int k, int l)
Checks whether the bitvector at positions [i,...,j] is less than the bitvector at positions [k,...,l]. If equal=true, "less" is substituted by "less or equal".- Parameters:
s
- some bitsetequal
- whether equality is allowedi
- start index of first bitvector (including)j
- end index of first bitvector (including)k
- start index of second bitvector (including)l
- end index of second bitvector (including)- Returns:
- "true" if [i,...,j] is less (or equal) [k,...,l]
-
parseAssociativeFormula
private Pair<java.util.Collection<PlFormula>,java.lang.Integer> parseAssociativeFormula(java.util.BitSet s, int idx, int numOfTerms, PlSignature sig)
Parses an associate formula from the given bitset starting at index idx, with the given number of terms and the given signature- Parameters:
s
- some bitsetidx
- the starting index of the formula to be parsednumOfTerms
- the number of terms to be parsedsig
- the current signature- Returns:
- the set of parsed terms and the index position in s after this formula
-
parseProposition
private Pair<PlFormula,java.lang.Integer> parseProposition(java.util.BitSet s, int idx, PlSignature sig)
Parses a proposition in bitset s starting from idx.- Parameters:
s
- some bitsetidx
- the starting index of the propositionsig
- the current signature- Returns:
- the formula parsed and the index in s after this formula
-
parseFormula
private Pair<PlFormula,java.lang.Integer> parseFormula(java.util.BitSet s, int idx, PlSignature sig)
Reads the next formula of the given bitset, starting at the given index.- Parameters:
s
- a bitsetidx
- the start index of a formulasig
- the current signature- Returns:
- the formula that has been read and the index right in the bitset right after this formula; if the bitset if invalid, "null" is returned
-
bitset2BeliefSet
private PlBeliefSet bitset2BeliefSet(java.util.BitSet s)
Parses a knowledge base (PlBeliefSet) from the the given bitset. If the bitset does not encode a PlBeliefSet, null is returned- Parameters:
s
- some bitset- Returns:
- the knowledge base encoded by the bitset, or null.
-
hasNext
public boolean hasNext()
- Specified by:
hasNext
in interfaceBeliefSetIterator<PlFormula,PlBeliefSet>
- Specified by:
hasNext
in interfacejava.util.Iterator<PlBeliefSet>
-
next
public PlBeliefSet next()
- Specified by:
next
in interfaceBeliefSetIterator<PlFormula,PlBeliefSet>
- Specified by:
next
in interfacejava.util.Iterator<PlBeliefSet>
-
nextIndex
public java.math.BigInteger nextIndex()
Returns the index of the next element.- Returns:
- the index of the next element.
-
formula2String
private static java.lang.String formula2String(PlFormula f, java.util.Map<Proposition,java.lang.Integer> prop)
Encodes the given formula as a bitstring.- Parameters:
f
- some formulaprop
- map of propositions to their indices- Returns:
- a bitstring representing the formula
-
beliefSet2BitSet
public static java.util.BitSet beliefSet2BitSet(PlBeliefSet bs)
Creates a bitset representation of the given belief set.- Parameters:
bs
- some belief set- Returns:
- a bitset representation of the belief set
-
-