Package org.mcp.sat
Class SATInteger
java.lang.Object
org.mcp.sat.SATInteger
- All Implemented Interfaces:
Serializable
- Direct Known Subclasses:
MutableSATInteger
Abstract base class for SAT-based integer encodings.
Provides methods for encoding, decoding, and querying integer values using SAT formulas. Supports conversion between SAT assignments and integer values, and value constraints.
- Since:
- 2025-02-28
- Author:
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final org.logicng.formulas.Variable[]Bit vector representing the integer (each bit is a SAT variable).protected final org.logicng.formulas.FormulaFactoryFormula factory for creating SAT formulas.protected final longMaximum value representable by this SATInteger. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedSATInteger(org.logicng.formulas.FormulaFactory factory, org.logicng.formulas.Variable[] bitvec) Constructs a SATInteger from a formula factory and bit vector. -
Method Summary
Modifier and TypeMethodDescriptionprotected abstract org.logicng.formulas.FormulafirstBitsEqual(long val, int length) Returns a formula representing the firstlengthbits equal to the given value.org.logicng.formulas.Variable[]Returns the bit vector.org.logicng.formulas.FormulaFactoryReturns the formula factory.getValueSatisfying(org.logicng.formulas.Formula formula) Returns the value satisfying the given formula, or 0 if unsatisfiable.intgetValueSatisfyingToInt(org.logicng.formulas.Formula formula) Converts a SAT assignment to an int value.getValuesSatisfying(org.logicng.formulas.Formula formula, int max) Returns a list of values satisfying the input formula, up to a maximum number.abstract longsatAssignmentToLong(org.logicng.datastructures.Assignment assignment) Converts a SAT assignment to a long value.intsize()Returns the number of bits in this SATInteger.final org.logicng.formulas.Formulavalue(long val) Returns a formula representing the exact value.
-
Field Details
-
_factory
protected final org.logicng.formulas.FormulaFactory _factoryFormula factory for creating SAT formulas. -
_bitvec
protected final org.logicng.formulas.Variable[] _bitvecBit vector representing the integer (each bit is a SAT variable). -
_maxVal
protected final long _maxValMaximum value representable by this SATInteger.
-
-
Constructor Details
-
SATInteger
protected SATInteger(org.logicng.formulas.FormulaFactory factory, org.logicng.formulas.Variable[] bitvec) Constructs a SATInteger from a formula factory and bit vector.- Parameters:
factory- the formula factorybitvec- the bit vector (array of SAT variables)
-
-
Method Details
-
size
public int size()Returns the number of bits in this SATInteger.- Returns:
- the number of bits
-
satAssignmentToLong
public abstract long satAssignmentToLong(org.logicng.datastructures.Assignment assignment) Converts a SAT assignment to a long value.- Parameters:
assignment- the SAT assignment- Returns:
- the corresponding long value
-
getValueSatisfyingToInt
public int getValueSatisfyingToInt(org.logicng.formulas.Formula formula) Converts a SAT assignment to an int value. Only supports up to 31 bits.- Parameters:
formula- the SAT formula assignment- Returns:
- the corresponding int value
-
getValueSatisfying
Returns the value satisfying the given formula, or 0 if unsatisfiable.- Parameters:
formula- the SAT formula assignment- Returns:
- the value as a Long, or 0L if unsatisfiable
-
getValuesSatisfying
Returns a list of values satisfying the input formula, up to a maximum number.- Parameters:
formula- the SAT formula constraintmax- the maximum number of values desired- Returns:
- the list of satisfying values
-
value
public final org.logicng.formulas.Formula value(long val) Returns a formula representing the exact value.- Parameters:
val- the value to encode- Returns:
- the formula representing the value
-
getFactory
public org.logicng.formulas.FormulaFactory getFactory()Returns the formula factory.- Returns:
- the formula factory
-
getBitvec
public org.logicng.formulas.Variable[] getBitvec()Returns the bit vector.- Returns:
- the bit vector (array of SAT variables)
-
firstBitsEqual
protected abstract org.logicng.formulas.Formula firstBitsEqual(long val, int length) Returns a formula representing the firstlengthbits equal to the given value.- Parameters:
val- the value to comparelength- the number of bits to check- Returns:
- the formula representing the equality
-