- java.lang.Object
-
- org.logicng.solvers.maxsat.encodings.Encoder
-
public class Encoder extends Object
Encoders for cardinality constraints, pseudo Booleans and AMO constraints.- Since:
- 1.0
- Version:
- 2.4.0
-
-
Field Summary
Fields Modifier and Type Field Description protected MaxSATConfig.AMOEncodingamoEncodingprotected MaxSATConfig.CardinalityEncodingcardinalityEncodingprotected MaxSATConfig.IncrementalStrategyincrementalStrategyprotected Ladderladderprotected ModularTotalizermtotalizerprotected MaxSATConfig.PBEncodingpbEncodingprotected SequentialWeightCounterswcprotected Totalizertotalizer
-
Constructor Summary
Constructors Modifier Constructor Description Encoder(MaxSATConfig.CardinalityEncoding cardinality)Constructs a new Encoder.protectedEncoder(MaxSATConfig.IncrementalStrategy incremental, MaxSATConfig.CardinalityEncoding cardinality, MaxSATConfig.AMOEncoding amo, MaxSATConfig.PBEncoding pb)Constructs a new Encoder.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidbuildCardinality(MiniSatStyleSolver s, LNGIntVector lits, int rhs)Manages the building of cardinality encodings.MaxSATConfig.CardinalityEncodingcardEncoding()Returns the cardinality encoding.voidencodeAMO(MiniSatStyleSolver s, LNGIntVector lits)Encodes an AMO constraint in the given solver.voidencodeCardinality(MiniSatStyleSolver s, LNGIntVector lits, int rhs)Encodes a cardinality constraint in the given solver.voidencodePB(MiniSatStyleSolver s, LNGIntVector lits, LNGIntVector coeffs, int rhs)Encodes a pseudo-Boolean constraint.booleanhasCardEncoding()Returnstrueif the cardinality encoding was built,falseotherwise.booleanhasPBEncoding()Returnstrueif the pseudo-Boolean encoding was built,falseotherwise.voidincEncodePB(MiniSatStyleSolver s, LNGIntVector lits, LNGIntVector coeffs, int rhs, LNGIntVector assumptions, int size)Incrementally encodes a pseudo-Boolean constraint.voidincUpdateCardinality(MiniSatStyleSolver s, LNGIntVector join, LNGIntVector lits, int rhs, LNGIntVector assumptions)Manages the incremental update of cardinality constraints.voidincUpdatePB(MiniSatStyleSolver s, LNGIntVector lits, LNGIntVector coeffs, int rhs)Manages the incremental update of pseudo-Boolean encodings.voidincUpdatePBAssumptions(LNGIntVector assumptions)Manages the incremental update of assumptions.LNGIntVectorlits()Returns the totalizer's literals.LNGIntVectoroutputs()Returns the totalizer's output literals.voidsetAMOEncoding(MaxSATConfig.AMOEncoding enc)Sets the AMO encoding.voidsetIncremental(MaxSATConfig.IncrementalStrategy incremental)Sets the incremental strategy for the totalizer encoding.voidsetModulo(int m)Controls the modulo value that is used in the modulo totalizer encoding.voidsetPBEncoding(MaxSATConfig.PBEncoding enc)Sets the pseudo Boolean encoding.StringtoString()voidupdateCardinality(MiniSatStyleSolver s, int rhs)Updates the cardinality constraint.voidupdatePB(MiniSatStyleSolver s, int rhs)Updates a pseudo-Boolean encoding.
-
-
-
Field Detail
-
cardinalityEncoding
protected final MaxSATConfig.CardinalityEncoding cardinalityEncoding
-
ladder
protected final Ladder ladder
-
mtotalizer
protected final ModularTotalizer mtotalizer
-
totalizer
protected final Totalizer totalizer
-
swc
protected final SequentialWeightCounter swc
-
incrementalStrategy
protected MaxSATConfig.IncrementalStrategy incrementalStrategy
-
pbEncoding
protected MaxSATConfig.PBEncoding pbEncoding
-
amoEncoding
protected MaxSATConfig.AMOEncoding amoEncoding
-
-
Constructor Detail
-
Encoder
public Encoder(MaxSATConfig.CardinalityEncoding cardinality)
Constructs a new Encoder.- Parameters:
cardinality- the cardinality constraint encoder
-
Encoder
protected Encoder(MaxSATConfig.IncrementalStrategy incremental, MaxSATConfig.CardinalityEncoding cardinality, MaxSATConfig.AMOEncoding amo, MaxSATConfig.PBEncoding pb)
Constructs a new Encoder.- Parameters:
incremental- the incremental strategycardinality- the cardinality constraint encoderamo- the AMO constraint encoderpb- the pseudo Boolean encoder
-
-
Method Detail
-
cardEncoding
public MaxSATConfig.CardinalityEncoding cardEncoding()
Returns the cardinality encoding.- Returns:
- the cardinality encoding
-
setPBEncoding
public void setPBEncoding(MaxSATConfig.PBEncoding enc)
Sets the pseudo Boolean encoding.- Parameters:
enc- the pseudo Boolean encoding
-
setAMOEncoding
public void setAMOEncoding(MaxSATConfig.AMOEncoding enc)
Sets the AMO encoding.- Parameters:
enc- the AMO encoding
-
setModulo
public void setModulo(int m)
Controls the modulo value that is used in the modulo totalizer encoding.- Parameters:
m- the module value
-
setIncremental
public void setIncremental(MaxSATConfig.IncrementalStrategy incremental)
Sets the incremental strategy for the totalizer encoding.- Parameters:
incremental- the incremental strategy
-
encodeAMO
public void encodeAMO(MiniSatStyleSolver s, LNGIntVector lits)
Encodes an AMO constraint in the given solver.- Parameters:
s- the solverlits- the literals for the constraint- Throws:
IllegalStateException- if the AMO encoding is unknown
-
encodeCardinality
public void encodeCardinality(MiniSatStyleSolver s, LNGIntVector lits, int rhs)
Encodes a cardinality constraint in the given solver.- Parameters:
s- the solverlits- the literals for the constraintrhs- the right-hand side of the constraint- Throws:
IllegalStateException- if the cardinality encoding is unknown
-
updateCardinality
public void updateCardinality(MiniSatStyleSolver s, int rhs)
Updates the cardinality constraint.- Parameters:
s- the solverrhs- the new right-hand side- Throws:
IllegalStateException- if the cardinality encoding is unknown
-
buildCardinality
public void buildCardinality(MiniSatStyleSolver s, LNGIntVector lits, int rhs)
Manages the building of cardinality encodings. Currently, is only used for incremental solving.- Parameters:
s- the solverlits- the literals for the constraintrhs- the right-hand side of the constraint- Throws:
IllegalStateException- if the cardinality encoding does not support incrementality
-
incUpdateCardinality
public void incUpdateCardinality(MiniSatStyleSolver s, LNGIntVector join, LNGIntVector lits, int rhs, LNGIntVector assumptions)
Manages the incremental update of cardinality constraints.- Parameters:
s- the solverjoin- the join literalslits- the literals of the constraintrhs- the right-hand side of the constraintassumptions- the assumptions- Throws:
IllegalStateException- if the cardinality encoding does not support incrementality
-
encodePB
public void encodePB(MiniSatStyleSolver s, LNGIntVector lits, LNGIntVector coeffs, int rhs)
Encodes a pseudo-Boolean constraint.- Parameters:
s- the solverlits- the literals of the constraintcoeffs- the coefficients of the constraintsrhs- the right-hand side of the constraint- Throws:
IllegalStateException- if the pseudo-Boolean encoding is unknown
-
updatePB
public void updatePB(MiniSatStyleSolver s, int rhs)
Updates a pseudo-Boolean encoding.- Parameters:
s- the solverrhs- the new right-hand side- Throws:
IllegalStateException- if the pseudo-Boolean encoding is unknown
-
incEncodePB
public void incEncodePB(MiniSatStyleSolver s, LNGIntVector lits, LNGIntVector coeffs, int rhs, LNGIntVector assumptions, int size)
Incrementally encodes a pseudo-Boolean constraint.- Parameters:
s- the solverlits- the literals of the constraintcoeffs- the coefficients of the constraintrhs- the right-hand size of the constraintassumptions- the current assumptionssize- the size- Throws:
IllegalStateException- if the pseudo-Boolean encoding is unknown
-
incUpdatePB
public void incUpdatePB(MiniSatStyleSolver s, LNGIntVector lits, LNGIntVector coeffs, int rhs)
Manages the incremental update of pseudo-Boolean encodings.- Parameters:
s- the solverlits- the literals of the constraintcoeffs- the coefficients of the constraintrhs- the new right-hand side of the constraint- Throws:
IllegalStateException- if the pseudo-Boolean encoding is unknown
-
incUpdatePBAssumptions
public void incUpdatePBAssumptions(LNGIntVector assumptions)
Manages the incremental update of assumptions.- Parameters:
assumptions- the assumptions- Throws:
IllegalStateException- if the pseudo-Boolean encoding is unknown
-
hasCardEncoding
public boolean hasCardEncoding()
Returnstrueif the cardinality encoding was built,falseotherwise.- Returns:
trueif the cardinality encoding was built
-
hasPBEncoding
public boolean hasPBEncoding()
Returnstrueif the pseudo-Boolean encoding was built,falseotherwise.- Returns:
trueif the pseudo-Boolean encoding was built
-
lits
public LNGIntVector lits()
Returns the totalizer's literals.- Returns:
- the literals
-
outputs
public LNGIntVector outputs()
Returns the totalizer's output literals.- Returns:
- the literals
-
-