Module logicng

Class MaxSATSolver


  • public class MaxSATSolver
    extends Object
    A wrapper for the OpenWBO solver.
    Since:
    1.0
    Version:
    2.4.0
    • Method Detail

      • incWBO

        @Deprecated
        public static MaxSATSolver incWBO()
        Deprecated.
        this factory method without parameter will be removed in the future, use incWBO(FormulaFactory) instead
        Returns a new MaxSAT solver using incremental WBO as algorithm with the default configuration.
        Returns:
        the MaxSAT solver
      • incWBO

        public static MaxSATSolver incWBO​(FormulaFactory f)
        Returns a new MaxSAT solver using incremental WBO as algorithm with the MaxSAT configuration from the formula factory.
        Parameters:
        f - the formula factory
        Returns:
        the MaxSAT solver
      • incWBO

        @Deprecated
        public static MaxSATSolver incWBO​(MaxSATConfig config)
        Deprecated.
        this factory method without formula factory will be removed in the future, use incWBO(FormulaFactory, MaxSATConfig) instead
        Returns a new MaxSAT solver using incremental WBO as algorithm with the given configuration.
        Parameters:
        config - the configuration
        Returns:
        the MaxSAT solver
      • incWBO

        public static MaxSATSolver incWBO​(FormulaFactory f,
                                          MaxSATConfig config)
        Returns a new MaxSAT solver using incremental WBO as algorithm with the given configuration.
        Parameters:
        f - the formula factory
        config - the configuration
        Returns:
        the MaxSAT solver
      • linearSU

        @Deprecated
        public static MaxSATSolver linearSU()
        Deprecated.
        this factory method without parameter will be removed in the future, use linearSU(FormulaFactory) instead
        Returns a new MaxSAT solver using LinearSU as algorithm with the default configuration.
        Returns:
        the MaxSAT solver
      • linearSU

        public static MaxSATSolver linearSU​(FormulaFactory f)
        Returns a new MaxSAT solver using LinearSU as algorithm with the MaxSAT configuration from the formula factory.
        Parameters:
        f - the formula factory
        Returns:
        the MaxSAT solver
      • linearSU

        @Deprecated
        public static MaxSATSolver linearSU​(MaxSATConfig config)
        Deprecated.
        this factory method without formula factory will be removed in the future, use linearSU(FormulaFactory, MaxSATConfig) instead
        Returns a new MaxSAT solver using LinearSU as algorithm with the given configuration.
        Parameters:
        config - the configuration
        Returns:
        the MaxSAT solver
      • linearSU

        public static MaxSATSolver linearSU​(FormulaFactory f,
                                            MaxSATConfig config)
        Returns a new MaxSAT solver using LinearSU as algorithm with the given configuration.
        Parameters:
        config - the configuration
        f - the formula factory
        Returns:
        the MaxSAT solver
      • linearUS

        @Deprecated
        public static MaxSATSolver linearUS()
        Deprecated.
        this factory method without parameter will be removed in the future, use linearUS(FormulaFactory) instead
        Returns a new MaxSAT solver using LinearUS as algorithm with the default configuration.
        Returns:
        the MaxSAT solver
      • linearUS

        public static MaxSATSolver linearUS​(FormulaFactory f)
        Returns a new MaxSAT solver using LinearUS as algorithm with the MaxSAT configuration from the formula factory.
        Parameters:
        f - the formula factory
        Returns:
        the MaxSAT solver
      • linearUS

        @Deprecated
        public static MaxSATSolver linearUS​(MaxSATConfig config)
        Deprecated.
        this factory method without formula factory will be removed in the future, use linearUS(FormulaFactory, MaxSATConfig) instead
        Returns a new MaxSAT solver using LinearUS as algorithm with the given configuration.
        Parameters:
        config - the configuration
        Returns:
        the MaxSAT solver
      • linearUS

        public static MaxSATSolver linearUS​(FormulaFactory f,
                                            MaxSATConfig config)
        Returns a new MaxSAT solver using LinearUS as algorithm with the given configuration.
        Parameters:
        config - the configuration
        f - the formula factory
        Returns:
        the MaxSAT solver
      • msu3

        @Deprecated
        public static MaxSATSolver msu3()
        Deprecated.
        this factory method without parameter will be removed in the future, use msu3(FormulaFactory) instead
        Returns a new MaxSAT solver using MSU3 as algorithm with the default configuration.
        Returns:
        the MaxSAT solver
      • msu3

        public static MaxSATSolver msu3​(FormulaFactory f)
        Returns a new MaxSAT solver using MSU3 as algorithm with the MaxSAT configuration from the formula factory.
        Parameters:
        f - the formula factory
        Returns:
        the MaxSAT solver
      • msu3

        @Deprecated
        public static MaxSATSolver msu3​(MaxSATConfig config)
        Deprecated.
        this factory method without formula factory will be removed in the future, use msu3(FormulaFactory, MaxSATConfig) instead
        Returns a new MaxSAT solver using MSU3 as algorithm with the given configuration.
        Parameters:
        config - the configuration
        Returns:
        the MaxSAT solver
      • msu3

        public static MaxSATSolver msu3​(FormulaFactory f,
                                        MaxSATConfig config)
        Returns a new MaxSAT solver using MSU3 as algorithm with the given configuration.
        Parameters:
        config - the configuration
        f - the formula factory
        Returns:
        the MaxSAT solver
      • wbo

        @Deprecated
        public static MaxSATSolver wbo()
        Deprecated.
        this factory method without parameter will be removed in the future, use wbo(FormulaFactory) instead
        Returns a new MaxSAT solver using WBO as algorithm with the default configuration.
        Returns:
        the MaxSAT solver
      • wbo

        public static MaxSATSolver wbo​(FormulaFactory f)
        Returns a new MaxSAT solver using WBO as algorithm with the MaxSAT configuration from the formula factory.
        Parameters:
        f - the formula factory
        Returns:
        the MaxSAT solver
      • wbo

        @Deprecated
        public static MaxSATSolver wbo​(MaxSATConfig config)
        Deprecated.
        this factory method without formula factory will be removed in the future, use wbo(FormulaFactory, MaxSATConfig) instead
        Returns a new MaxSAT solver using MSU3 as algorithm with the given configuration.
        Parameters:
        config - the configuration
        Returns:
        the MaxSAT solver
      • wbo

        public static MaxSATSolver wbo​(FormulaFactory f,
                                       MaxSATConfig config)
        Returns a new MaxSAT solver using MSU3 as algorithm with the given configuration.
        Parameters:
        config - the configuration
        f - the formula factory
        Returns:
        the MaxSAT solver
      • wmsu3

        @Deprecated
        public static MaxSATSolver wmsu3()
        Deprecated.
        this factory method without parameter will be removed in the future, use wmsu3(FormulaFactory) instead
        Returns a new MaxSAT solver using weighted MSU3 as algorithm with the default configuration.
        Returns:
        the MaxSAT solver
      • wmsu3

        public static MaxSATSolver wmsu3​(FormulaFactory f)
        Returns a new MaxSAT solver using weighted MSU3 as algorithm with the MaxSAT configuration from the formula factory.
        Parameters:
        f - the formula factory
        Returns:
        the MaxSAT solver
      • wmsu3

        @Deprecated
        public static MaxSATSolver wmsu3​(MaxSATConfig config)
        Deprecated.
        this factory method without formula factory will be removed in the future, use wmsu3(FormulaFactory, MaxSATConfig) instead
        Returns a new MaxSAT solver using weighted MSU3 as algorithm with the given configuration.
        Parameters:
        config - the configuration
        Returns:
        the MaxSAT solver
      • wmsu3

        public static MaxSATSolver wmsu3​(FormulaFactory f,
                                         MaxSATConfig config)
        Returns a new MaxSAT solver using weighted MSU3 as algorithm with the given configuration.
        Parameters:
        config - the configuration
        f - the formula factory
        Returns:
        the MaxSAT solver
      • oll

        public static MaxSATSolver oll​(FormulaFactory f)
        Returns a new MaxSAT solver using weighted OLL as algorithm with the MaxSAT configuration from the formula factory.
        Parameters:
        f - the formula factory
        Returns:
        the MaxSAT solver
      • oll

        public static MaxSATSolver oll​(FormulaFactory f,
                                       MaxSATConfig config)
        Returns a new MaxSAT solver using weighted OLL as algorithm with the given configuration.
        Parameters:
        config - the configuration
        f - the formula factory
        Returns:
        the MaxSAT solver
      • isWeighted

        public boolean isWeighted()
        Returns whether this solver can handle weighted instances or not.
        Returns:
        whether this solver can handle weighted instances or not
      • addHardFormula

        public void addHardFormula​(Formula formula)
        Adds a new hard formula to the solver. Hard formulas must always be true.
        Parameters:
        formula - the formula
        Throws:
        IllegalStateException - if a formula is added to a solver which is already solved.
      • addSoftFormula

        public void addSoftFormula​(Formula formula,
                                   int weight)
        Adds a new soft formula to the solver.
        Parameters:
        formula - the formula
        weight - the weight
        Throws:
        IllegalStateException - if a formula is added to a solver which is already solved.
        IllegalArgumentException - if the weight is <1
      • addCNF

        protected void addCNF​(Formula formula,
                              int weight)
        Adds a formula which is already in CNF to the solver.
        Parameters:
        formula - the formula in CNF
        weight - the weight of this CNF (or -1 for a hard constraint)
      • addClause

        protected void addClause​(Formula formula,
                                 int weight)
        Adds a clause to the solver.
        Parameters:
        formula - the clause
        weight - the weight of the clause (or -1 for a hard clause)
      • solve

        public MaxSAT.MaxSATResult solve()
        Solves the formula on the solver and returns the result.
        Returns:
        the result (SAT, UNSAT, Optimum found)
      • solve

        public MaxSAT.MaxSATResult solve​(MaxSATHandler handler)
        Solves the formula on the solver and returns the result.
        Parameters:
        handler - a MaxSAT handler
        Returns:
        the result (SAT, UNSAT, Optimum found, or UNDEF if canceled by the handler)
      • result

        public int result()
        Returns the minimum weight (or number of clauses if unweighted) of clauses which have to be unsatisfied. Therefore, if the minimum number of weights is 0, the formula is satisfiable.
        Returns:
        the minimum weight of clauses which have to be unsatisfied
        Throws:
        IllegalStateException - if the formula is not yet solved
      • model

        public Assignment model()
        Returns the model of the current result.
        Returns:
        the model of the current result
        Throws:
        IllegalStateException - if the formula is not yet solved
      • createAssignment

        protected Assignment createAssignment​(LNGBooleanVector vec)
        Creates an assignment from a Boolean vector of the solver.
        Parameters:
        vec - the vector of the solver
        Returns:
        the assignment
      • stats

        public MaxSAT.Stats stats()
        Returns the stats of the underlying solver.
        Returns:
        the stats of the underlying solver
      • getAlgorithm

        public MaxSATSolver.Algorithm getAlgorithm()
        Returns the algorithm for this solver.
        Returns:
        the algorithm
      • factory

        public FormulaFactory factory()
        Returns the formula factory for this solver.
        Returns:
        the formula factory