Copyright | (c) Masahiro Sakai 2012-2014 |
---|---|
License | BSD-style |
Maintainer | masahiro.sakai@gmail.com |
Stability | provisional |
Portability | non-portable (BangPatterns, ScopedTypeVariables, CPP, DeriveDataTypeable, RecursiveDo) |
Safe Haskell | None |
Language | Haskell2010 |
A CDCL SAT solver.
It follows the design of MiniSat and SAT4J.
See also:
- data Solver
- newSolver :: IO Solver
- newSolverWithConfig :: Config -> IO Solver
- type Var = Int
- type Lit = Int
- literal :: Var -> Bool -> Lit
- litNot :: Lit -> Lit
- litVar :: Lit -> Var
- litPolarity :: Lit -> Bool
- evalLit :: IModel m => m -> Lit -> Bool
- newVar :: Solver -> IO Var
- newVars :: Solver -> Int -> IO [Var]
- newVars_ :: Solver -> Int -> IO ()
- resizeVarCapacity :: Solver -> Int -> IO ()
- addClause :: Solver -> Clause -> IO ()
- type Clause = [Lit]
- evalClause :: IModel m => m -> Clause -> Bool
- addAtLeast :: Solver -> [Lit] -> Int -> IO ()
- addAtMost :: Solver -> [Lit] -> Int -> IO ()
- addExactly :: Solver -> [Lit] -> Int -> IO ()
- type AtLeast = ([Lit], Int)
- type Exactly = ([Lit], Int)
- evalAtLeast :: IModel m => m -> AtLeast -> Bool
- evalExactly :: IModel m => m -> Exactly -> Bool
- addPBAtLeast :: Solver -> PBLinSum -> Integer -> IO ()
- addPBAtMost :: Solver -> PBLinSum -> Integer -> IO ()
- addPBExactly :: Solver -> PBLinSum -> Integer -> IO ()
- addPBAtLeastSoft :: Solver -> Lit -> PBLinSum -> Integer -> IO ()
- addPBAtMostSoft :: Solver -> Lit -> PBLinSum -> Integer -> IO ()
- addPBExactlySoft :: Solver -> Lit -> PBLinSum -> Integer -> IO ()
- type PBLinTerm = (Integer, Lit)
- type PBLinSum = [PBLinTerm]
- type PBLinAtLeast = (PBLinSum, Integer)
- type PBLinExactly = (PBLinSum, Integer)
- evalPBLinSum :: IModel m => m -> PBLinSum -> Integer
- evalPBLinAtLeast :: IModel m => m -> PBLinAtLeast -> Bool
- evalPBLinExactly :: IModel m => m -> PBLinAtLeast -> Bool
- addXORClause :: Solver -> [Lit] -> Bool -> IO ()
- addXORClauseSoft :: Solver -> Lit -> [Lit] -> Bool -> IO ()
- type XORClause = ([Lit], Bool)
- evalXORClause :: IModel m => m -> XORClause -> Bool
- setTheory :: Solver -> TheorySolver -> IO ()
- solve :: Solver -> IO Bool
- solveWith :: Solver -> [Lit] -> IO Bool
- data BudgetExceeded = BudgetExceeded
- class IModel a where
- type Model = UArray Var Bool
- getModel :: Solver -> IO Model
- getFailedAssumptions :: Solver -> IO [Lit]
- getAssumptionsImplications :: Solver -> IO [Lit]
- data Config = Config {
- configRestartStrategy :: !RestartStrategy
- configRestartFirst :: !Int
- configRestartInc :: !Double
- configLearningStrategy :: !LearningStrategy
- configLearntSizeFirst :: !Int
- configLearntSizeInc :: !Double
- configCCMin :: !Int
- configEnablePhaseSaving :: !Bool
- configEnableForwardSubsumptionRemoval :: !Bool
- configEnableBackwardSubsumptionRemoval :: !Bool
- configRandomFreq :: !Double
- configPBHandlerType :: !PBHandlerType
- configEnablePBSplitClausePart :: !Bool
- configCheckModel :: !Bool
- configVarDecay :: !Double
- configConstrDecay :: !Double
- getConfig :: Solver -> IO Config
- setConfig :: Solver -> Config -> IO ()
- modifyConfig :: Solver -> (Config -> Config) -> IO ()
- data RestartStrategy
- data LearningStrategy
- setVarPolarity :: Solver -> Var -> Bool -> IO ()
- setLogger :: Solver -> (String -> IO ()) -> IO ()
- setRandomGen :: Solver -> GenIO -> IO ()
- getRandomGen :: Solver -> IO GenIO
- setConfBudget :: Solver -> Maybe Int -> IO ()
- data PBHandlerType
- setRestartStrategy :: Solver -> RestartStrategy -> IO ()
- setRestartFirst :: Solver -> Int -> IO ()
- defaultRestartFirst :: Int
- setRestartInc :: Solver -> Double -> IO ()
- defaultRestartInc :: Double
- setLearntSizeFirst :: Solver -> Int -> IO ()
- defaultLearntSizeFirst :: Int
- setLearntSizeInc :: Solver -> Double -> IO ()
- defaultLearntSizeInc :: Double
- setCCMin :: Solver -> Int -> IO ()
- defaultCCMin :: Int
- setLearningStrategy :: Solver -> LearningStrategy -> IO ()
- setEnablePhaseSaving :: Solver -> Bool -> IO ()
- getEnablePhaseSaving :: Solver -> IO Bool
- defaultEnablePhaseSaving :: Bool
- setEnableForwardSubsumptionRemoval :: Solver -> Bool -> IO ()
- getEnableForwardSubsumptionRemoval :: Solver -> IO Bool
- defaultEnableForwardSubsumptionRemoval :: Bool
- setEnableBackwardSubsumptionRemoval :: Solver -> Bool -> IO ()
- getEnableBackwardSubsumptionRemoval :: Solver -> IO Bool
- defaultEnableBackwardSubsumptionRemoval :: Bool
- setCheckModel :: Solver -> Bool -> IO ()
- setRandomFreq :: Solver -> Double -> IO ()
- defaultRandomFreq :: Double
- setPBHandlerType :: Solver -> PBHandlerType -> IO ()
- setPBSplitClausePart :: Solver -> Bool -> IO ()
- getPBSplitClausePart :: Solver -> IO Bool
- defaultPBSplitClausePart :: Bool
- getNVars :: Solver -> IO Int
- getNConstraints :: Solver -> IO Int
- getNLearntConstraints :: Solver -> IO Int
- getVarFixed :: Solver -> Var -> IO LBool
- getLitFixed :: Solver -> Var -> IO LBool
- getFixedLiterals :: Solver -> IO [Lit]
- nVars :: Solver -> IO Int
- nAssigns :: Solver -> IO Int
- nConstraints :: Solver -> IO Int
- nLearnt :: Solver -> IO Int
- varBumpActivity :: Solver -> Var -> IO ()
- varDecayActivity :: Solver -> IO ()
The Solver
type
newSolverWithConfig :: Config -> IO Solver Source #
Create a new Solver
instance with a given configulation.
Basic data structures
Positive (resp. negative) literals are represented as positive (resp. negative) integers. (DIMACS format).
litPolarity :: Lit -> Bool Source #
Problem specification
newVars :: Solver -> Int -> IO [Var] Source #
Add variables. newVars solver n = replicateM n (newVar solver)
newVars_ :: Solver -> Int -> IO () Source #
Add variables. newVars_ solver n = newVars solver n >> return ()
Clauses
Cardinality constraints
:: Solver | The |
-> [Lit] | set of literals {l1,l2,..} (duplicated elements are ignored) |
-> Int | n. |
-> IO () |
Add a cardinality constraints atleast({l1,l2,..},n).
:: Solver | The |
-> [Lit] | set of literals {l1,l2,..} (duplicated elements are ignored) |
-> Int | n |
-> IO () |
Add a cardinality constraints atmost({l1,l2,..},n).
:: Solver | The |
-> [Lit] | set of literals {l1,l2,..} (duplicated elements are ignored) |
-> Int | n |
-> IO () |
Add a cardinality constraints exactly({l1,l2,..},n).
(Linear) pseudo-boolean constraints
Add a pseudo boolean constraints c1*l1 + c2*l2 + … ≥ n.
Add a pseudo boolean constraints c1*l1 + c2*l2 + … ≤ n.
Add a pseudo boolean constraints c1*l1 + c2*l2 + … = n.
:: Solver | The |
-> Lit | Selector literal |
-> PBLinSum | list of terms |
-> Integer | n |
-> IO () |
Add a soft pseudo boolean constraints sel ⇒ c1*l1 + c2*l2 + … ≥ n.
:: Solver | The |
-> Lit | Selector literal |
-> PBLinSum | list of terms |
-> Integer | n |
-> IO () |
Add a soft pseudo boolean constraints sel ⇒ c1*l1 + c2*l2 + … ≤ n.
:: Solver | The |
-> Lit | Selector literal |
-> PBLinSum | list of terms |
-> Integer | n |
-> IO () |
Add a soft pseudo boolean constraints sel ⇒ c1*l1 + c2*l2 + … = n.
type PBLinAtLeast = (PBLinSum, Integer) Source #
type PBLinExactly = (PBLinSum, Integer) Source #
evalPBLinAtLeast :: IModel m => m -> PBLinAtLeast -> Bool Source #
evalPBLinExactly :: IModel m => m -> PBLinAtLeast -> Bool Source #
XOR clauses
Add a parity constraint l1 ⊕ l2 ⊕ … ⊕ ln = rhs
:: Solver | The |
-> Lit | Selector literal |
-> [Lit] | literals |
-> Bool | rhs |
-> IO () |
Add a soft parity constraint sel ⇒ l1 ⊕ l2 ⊕ … ⊕ ln = rhs
type XORClause = ([Lit], Bool) Source #
XOR clause
'([l1,l2..ln], b)' means l1 ⊕ l2 ⊕ ⋯ ⊕ ln = b.
Note that:
- True can be represented as ([], False)
- False can be represented as ([], True)
Thery
Solving
data BudgetExceeded Source #
Extract results
type Model = UArray Var Bool Source #
A model is represented as a mapping from variables to its values.
getModel :: Solver -> IO Model Source #
After solve
returns True, it returns an satisfying assignment.
getFailedAssumptions :: Solver -> IO [Lit] Source #
After solveWith
returns False, it returns a set of assumptions
that leads to contradiction. In particular, if it returns an empty
set, the problem is unsatisiable without any assumptions.
getAssumptionsImplications :: Solver -> IO [Lit] Source #
EXPERIMENTAL API: After solveWith
returns True or failed with BudgetExceeded
exception,
it returns a set of literals that are implied by assumptions.
Solver configulation
Config | |
|
data RestartStrategy Source #
Restart strategy.
The default value can be obtained by def
.
data LearningStrategy Source #
Learning strategy.
The default value can be obtained by def
.
setLogger :: Solver -> (String -> IO ()) -> IO () Source #
set callback function for receiving messages.
setRandomGen :: Solver -> GenIO -> IO () Source #
Set random generator used by the random variable selection
getRandomGen :: Solver -> IO GenIO Source #
Get random generator used by the random variable selection
data PBHandlerType Source #
Pseudo boolean constraint handler implimentation.
The default value can be obtained by def
.
Deprecated
setRestartStrategy :: Solver -> RestartStrategy -> IO () Source #
Deprecated: Use setConfig
setRestartFirst :: Solver -> Int -> IO () Source #
Deprecated: Use setConfig
The initial restart limit. (default 100) Zero and negative values are used to disable restart.
defaultRestartFirst :: Int Source #
Deprecated: Use configRestartFirst def
default value for RestartFirst
.
setRestartInc :: Solver -> Double -> IO () Source #
Deprecated: Use setConfig
The factor with which the restart limit is multiplied in each restart. (default 1.5)
This must be >1
.
defaultRestartInc :: Double Source #
Deprecated: Use configRestartInc def
default value for RestartInc
.
setLearntSizeFirst :: Solver -> Int -> IO () Source #
Deprecated: Use setConfig
The initial limit for learnt clauses.
Negative value means computing default value from problem instance.
defaultLearntSizeFirst :: Int Source #
Deprecated: Use learntSizeFirst def
default value for LearntSizeFirst
.
setLearntSizeInc :: Solver -> Double -> IO () Source #
Deprecated: Use setConfig
The limit for learnt clauses is multiplied with this factor each restart. (default 1.1)
This must be >1
.
defaultLearntSizeInc :: Double Source #
Deprecated: Use learntSizeInc def
default value for LearntSizeInc
.
setCCMin :: Solver -> Int -> IO () Source #
Deprecated: Use setConfig
Controls conflict clause minimization (0=none, 1=basic, 2=deep)
defaultCCMin :: Int Source #
Deprecated: Use ccMin def
default value for CCMin
.
setLearningStrategy :: Solver -> LearningStrategy -> IO () Source #
Deprecated: Use setConfig
defaultEnablePhaseSaving :: Bool Source #
Deprecated: Use configEnablePhaseSaving def
defaultEnableForwardSubsumptionRemoval :: Bool Source #
Deprecated: Use configEnableForwardSubsumptionRemoval def
defaultEnableBackwardSubsumptionRemoval :: Bool Source #
Deprecated: Use configEnableBackwardSubsumptionRemoval def
setRandomFreq :: Solver -> Double -> IO () Source #
Deprecated: Use setConfig
The frequency with which the decision heuristic tries to choose a random variable
defaultRandomFreq :: Double Source #
Deprecated: Use configRandomFreq def
setPBHandlerType :: Solver -> PBHandlerType -> IO () Source #
Deprecated: Use setConfig
setPBSplitClausePart :: Solver -> Bool -> IO () Source #
Deprecated: Use setConfig
Split PB-constraints into a PB part and a clause part.
Example from minisat+ paper:
- 4 x1 + 4 x2 + 4 x3 + 4 x4 + 2y1 + y2 + y3 ≥ 4
would be split into
- x1 + x2 + x3 + x4 + ¬z ≥ 1 (clause part)
- 2 y1 + y2 + y3 + 4 z ≥ 4 (PB part)
where z is a newly introduced variable, not present in any other constraint.
Reference:
- N . Eéen and N. Sörensson. Translating Pseudo-Boolean Constraints into SAT. JSAT 2:1–26, 2006.
getPBSplitClausePart :: Solver -> IO Bool Source #
See documentation of setPBSplitClausePart
.
defaultPBSplitClausePart :: Bool Source #
Deprecated: Use configEnablePBSplitClausePart def
See documentation of setPBSplitClausePart
.
Read state
getFixedLiterals :: Solver -> IO [Lit] Source #
it returns a set of literals that are fixed without any assumptions.
Read state (deprecated)
nVars :: Solver -> IO Int Source #
Deprecated: Use getNVars instead
number of variables of the problem.
nAssigns :: Solver -> IO Int Source #
Deprecated: nAssigns is deprecated
number of assigned variables.
nConstraints :: Solver -> IO Int Source #
Deprecated: Use getNConstraints instead
number of constraints.
nLearnt :: Solver -> IO Int Source #
Deprecated: Use getNLearntConstraints instead
number of learnt constrints.
Internal API
varDecayActivity :: Solver -> IO () Source #