Module logicng

Class Encoder


  • public class Encoder
    extends Object
    Encoders for cardinality constraints, pseudo Booleans and AMO constraints.
    Since:
    1.0
    Version:
    2.4.0
    • Method Detail

      • 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 solver
        lits - 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 solver
        lits - the literals for the constraint
        rhs - 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 solver
        rhs - 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 solver
        lits - the literals for the constraint
        rhs - 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 solver
        join - the join literals
        lits - the literals of the constraint
        rhs - the right-hand side of the constraint
        assumptions - 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 solver
        lits - the literals of the constraint
        coeffs - the coefficients of the constraints
        rhs - 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 solver
        rhs - 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 solver
        lits - the literals of the constraint
        coeffs - the coefficients of the constraint
        rhs - the right-hand size of the constraint
        assumptions - the current assumptions
        size - 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 solver
        lits - the literals of the constraint
        coeffs - the coefficients of the constraint
        rhs - 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()
        Returns true if the cardinality encoding was built, false otherwise.
        Returns:
        true if the cardinality encoding was built
      • hasPBEncoding

        public boolean hasPBEncoding()
        Returns true if the pseudo-Boolean encoding was built, false otherwise.
        Returns:
        true if 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