Module logicng

Class PBEncoder


  • public class PBEncoder
    extends Object
    An encoder for pseudo-Boolean constraints.
    Since:
    1.0
    Version:
    2.3.0
    • Constructor Detail

      • PBEncoder

        public PBEncoder​(FormulaFactory f,
                         PBConfig pbConfig,
                         CCConfig ccConfig)
        Constructs a new pseudo-Boolean encoder with given configurations.
        Parameters:
        f - the formula factory
        pbConfig - the pseudo-Boolean encoder configuration
        ccConfig - the cardinality constraints encoder configuration
      • PBEncoder

        public PBEncoder​(FormulaFactory f,
                         PBConfig pbConfig)
        Constructs a new pseudo-Boolean encoder with a given configuration.
        Parameters:
        f - the formula factory
        pbConfig - the pseudo-Boolean encoder configuration
      • PBEncoder

        public PBEncoder​(FormulaFactory f)
        Constructs a new pseudo-Boolean encoder which uses the configuration of the formula factory.
        Parameters:
        f - the formula factory
    • Method Detail

      • encode

        public List<Formula> encode​(PBConstraint constraint)
        Encodes a pseudo-Boolean constraint and returns its CNF encoding.
        Parameters:
        constraint - the pseudo-Boolean constraint
        Returns:
        the CNF encoding of the pseudo-Boolean constraint
      • config

        public PBConfig config()
        Returns the current configuration of this encoder. If the encoder was constructed with a given configuration, this configuration will always be used. Otherwise, the current configuration from the formula factory is used.
        Returns:
        the current configuration of
      • encode

        protected List<Formula> encode​(Literal[] lits,
                                       int[] coeffs,
                                       int rhs)
        Builds a pseudo Boolean constraint of the form c_1 * lit_1 + c_2 * lit_2 + ... + c_n * lit_n >= k.
        Parameters:
        lits - the literals lit_1 ... lit_n
        coeffs - the coefficients c_1 ... c_n
        rhs - the right-hand side k of the constraint
        Returns:
        the CNF encoding of the pseudo Boolean constraint
        Throws:
        IllegalArgumentException - if the right-hand side of the cardinality constraint is negative or larger than the number of literals