Copyright | (c) Masahiro Sakai 2012 |
---|---|
License | BSD-style |
Maintainer | masahiro.sakai@gmail.com |
Stability | provisional |
Portability | non-portable |
Safe Haskell | Safe-Inferred |
Language | Haskell2010 |
Extensions |
|
ToySolver.SAT.Types
Description
Synopsis
- type Var = Int
- type VarSet = IntSet
- type VarMap = IntMap
- validVar :: Var -> Bool
- class IModel a where
- type Model = UArray Var Bool
- restrictModel :: Int -> Model -> Model
- type Lit = Int
- type LitSet = IntSet
- type LitMap = IntMap
- litUndef :: Lit
- validLit :: Lit -> Bool
- literal :: Var -> Bool -> Lit
- litNot :: Lit -> Lit
- litVar :: Lit -> Var
- litPolarity :: Lit -> Bool
- evalLit :: IModel m => m -> Lit -> Bool
- type Clause = [Lit]
- normalizeClause :: Clause -> Maybe Clause
- instantiateClause :: forall m. Monad m => (Lit -> m LBool) -> Clause -> m (Maybe Clause)
- clauseSubsume :: Clause -> Clause -> Bool
- evalClause :: IModel m => m -> Clause -> Bool
- clauseToPBLinAtLeast :: Clause -> PBLinAtLeast
- type PackedVar = PackedLit
- type PackedLit = Int32
- packLit :: Lit -> PackedLit
- unpackLit :: PackedLit -> Lit
- type PackedClause = Vector PackedLit
- packClause :: Clause -> PackedClause
- unpackClause :: PackedClause -> Clause
- type AtLeast = ([Lit], Int)
- type Exactly = ([Lit], Int)
- normalizeAtLeast :: AtLeast -> AtLeast
- instantiateAtLeast :: forall m. Monad m => (Lit -> m LBool) -> AtLeast -> m AtLeast
- evalAtLeast :: IModel m => m -> AtLeast -> Bool
- evalExactly :: IModel m => m -> Exactly -> Bool
- type PBLinTerm = (Integer, Lit)
- type PBLinSum = [PBLinTerm]
- type PBLinAtLeast = (PBLinSum, Integer)
- type PBLinExactly = (PBLinSum, Integer)
- normalizePBLinSum :: (PBLinSum, Integer) -> (PBLinSum, Integer)
- normalizePBLinAtLeast :: PBLinAtLeast -> PBLinAtLeast
- normalizePBLinExactly :: PBLinExactly -> PBLinExactly
- instantiatePBLinAtLeast :: forall m. Monad m => (Lit -> m LBool) -> PBLinAtLeast -> m PBLinAtLeast
- instantiatePBLinExactly :: Monad m => (Lit -> m LBool) -> PBLinExactly -> m PBLinExactly
- cutResolve :: PBLinAtLeast -> PBLinAtLeast -> Var -> PBLinAtLeast
- cardinalityReduction :: PBLinAtLeast -> AtLeast
- negatePBLinAtLeast :: PBLinAtLeast -> PBLinAtLeast
- evalPBLinSum :: IModel m => m -> PBLinSum -> Integer
- evalPBLinAtLeast :: IModel m => m -> PBLinAtLeast -> Bool
- evalPBLinExactly :: IModel m => m -> PBLinAtLeast -> Bool
- pbLinLowerBound :: PBLinSum -> Integer
- pbLinUpperBound :: PBLinSum -> Integer
- pbLinSubsume :: PBLinAtLeast -> PBLinAtLeast -> Bool
- type PBTerm = (Integer, [Lit])
- type PBSum = [PBTerm]
- evalPBSum :: IModel m => m -> PBSum -> Integer
- evalPBConstraint :: IModel m => m -> Constraint -> Bool
- evalPBFormula :: IModel m => m -> Formula -> Maybe Integer
- evalPBSoftFormula :: IModel m => m -> SoftFormula -> Maybe Integer
- pbLowerBound :: PBSum -> Integer
- pbUpperBound :: PBSum -> Integer
- removeNegationFromPBSum :: PBSum -> PBSum
- type XORClause = ([Lit], Bool)
- normalizeXORClause :: XORClause -> XORClause
- instantiateXORClause :: forall m. Monad m => (Lit -> m LBool) -> XORClause -> m XORClause
- evalXORClause :: IModel m => m -> XORClause -> Bool
- class Monad m => NewVar m a | a -> m where
- class NewVar m a => AddClause m a | a -> m where
- class AddClause m a => AddCardinality m a | a -> m where
- addAtLeast :: a -> [Lit] -> Int -> m ()
- addAtMost :: a -> [Lit] -> Int -> m ()
- addExactly :: a -> [Lit] -> Int -> m ()
- class AddCardinality m a => AddPBLin m a | a -> m where
- addPBAtLeast :: a -> PBLinSum -> Integer -> m ()
- addPBAtMost :: a -> PBLinSum -> Integer -> m ()
- addPBExactly :: a -> PBLinSum -> Integer -> m ()
- addPBAtLeastSoft :: a -> Lit -> PBLinSum -> Integer -> m ()
- addPBAtMostSoft :: a -> Lit -> PBLinSum -> Integer -> m ()
- addPBExactlySoft :: a -> Lit -> PBLinSum -> Integer -> m ()
- class AddPBLin m a => AddPBNL m a | a -> m where
- addPBNLAtLeast :: a -> PBSum -> Integer -> m ()
- addPBNLAtMost :: a -> PBSum -> Integer -> m ()
- addPBNLExactly :: a -> PBSum -> Integer -> m ()
- addPBNLAtLeastSoft :: a -> Lit -> PBSum -> Integer -> m ()
- addPBNLAtMostSoft :: a -> Lit -> PBSum -> Integer -> m ()
- addPBNLExactlySoft :: a -> Lit -> PBSum -> Integer -> m ()
- class AddClause m a => AddXORClause m a | a -> m where
- addXORClause :: a -> [Lit] -> Bool -> m ()
- addXORClauseSoft :: a -> Lit -> [Lit] -> Bool -> m ()
- addSOS2 :: AddClause m a => a -> [Lit] -> m ()
- evalSOS2 :: IModel m => m -> [Lit] -> Bool
Variable
Model
type Model = UArray Var Bool Source #
A model is represented as a mapping from variables to its values.
Literal
Positive (resp. negative) literals are represented as positive (resp. negative) integers. (DIMACS format).
litPolarity :: Lit -> Bool Source #
Clause
normalizeClause :: Clause -> Maybe Clause Source #
Normalizing clause
Nothing
if the clause is trivially true.
Packed Clause
type PackedClause = Vector PackedLit Source #
packClause :: Clause -> PackedClause Source #
unpackClause :: PackedClause -> Clause Source #
Cardinality Constraint
normalizeAtLeast :: AtLeast -> AtLeast Source #
(Linear) Pseudo Boolean Constraint
type PBLinAtLeast = (PBLinSum, Integer) Source #
type PBLinExactly = (PBLinSum, Integer) Source #
normalizePBLinSum :: (PBLinSum, Integer) -> (PBLinSum, Integer) Source #
normalizing PB term of the form c1 x1 + c2 x2 ... cn xn + c into d1 x1 + d2 x2 ... dm xm + d where d1,...,dm ≥ 1.
normalizePBLinAtLeast :: PBLinAtLeast -> PBLinAtLeast Source #
normalizing PB constraint of the form c1 x1 + c2 cn ... cn xn >= b.
normalizePBLinExactly :: PBLinExactly -> PBLinExactly Source #
normalizing PB constraint of the form c1 x1 + c2 cn ... cn xn = b.
instantiatePBLinAtLeast :: forall m. Monad m => (Lit -> m LBool) -> PBLinAtLeast -> m PBLinAtLeast Source #
instantiatePBLinExactly :: Monad m => (Lit -> m LBool) -> PBLinExactly -> m PBLinExactly Source #
cutResolve :: PBLinAtLeast -> PBLinAtLeast -> Var -> PBLinAtLeast Source #
evalPBLinAtLeast :: IModel m => m -> PBLinAtLeast -> Bool Source #
evalPBLinExactly :: IModel m => m -> PBLinAtLeast -> Bool Source #
pbLinLowerBound :: PBLinSum -> Integer Source #
pbLinUpperBound :: PBLinSum -> Integer Source #
pbLinSubsume :: PBLinAtLeast -> PBLinAtLeast -> Bool Source #
Non-linear Pseudo Boolean constraint
evalPBConstraint :: IModel m => m -> Constraint -> Bool Source #
evalPBSoftFormula :: IModel m => m -> SoftFormula -> Maybe Integer Source #
pbLowerBound :: PBSum -> Integer Source #
pbUpperBound :: PBSum -> Integer Source #
removeNegationFromPBSum :: PBSum -> PBSum Source #
XOR Clause
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)
normalizeXORClause :: XORClause -> XORClause Source #
Normalize XOR clause
Type classes for solvers
class Monad m => NewVar m a | a -> m where Source #
Minimal complete definition
Methods
Add a new variable
newVars :: a -> Int -> m [Var] Source #
Add variables. newVars a n = replicateM n (newVar a)
, but maybe faster.
newVars_ :: a -> Int -> m () Source #
Add variables. newVars_ a n = newVars a n >> return ()
, but maybe faster.
Instances
NewVar IO Solver Source # | |
Monad m => NewVar m (Encoder m) Source # | |
Monad m => NewVar m (Encoder m) Source # | |
Monad m => NewVar m (Encoder m) Source # | |
Monad m => NewVar m (Encoder m) Source # | |
Monad m => NewVar m (Encoder m) Source # | |
PrimMonad m => NewVar m (CNFStore m) Source # | |
PrimMonad m => NewVar m (PBStore m) Source # | |
class NewVar m a => AddClause m a | a -> m where Source #
Instances
AddClause IO Solver Source # | |
Monad m => AddClause m (Encoder m) Source # | |
Monad m => AddClause m (Encoder m) Source # | |
Monad m => AddClause m (Encoder m) Source # | |
Monad m => AddClause m (Encoder m) Source # | |
Monad m => AddClause m (Encoder m) Source # | |
PrimMonad m => AddClause m (CNFStore m) Source # | |
PrimMonad m => AddClause m (PBStore m) Source # | |
class AddClause m a => AddCardinality m a | a -> m where Source #
Minimal complete definition
Methods
Add a cardinality constraints atleast({l1,l2,..},n).
Add a cardinality constraints atmost({l1,l2,..},n).
Add a cardinality constraints exactly({l1,l2,..},n).
Instances
AddCardinality IO Solver Source # | |
PrimMonad m => AddCardinality m (Encoder m) Source # | |
PrimMonad m => AddCardinality m (Encoder m) Source # | |
Monad m => AddCardinality m (Encoder m) Source # | |
PrimMonad m => AddCardinality m (PBStore m) Source # | |
class AddCardinality m a => AddPBLin m a | a -> m where Source #
Minimal complete definition
Methods
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.
Arguments
:: a | |
-> Lit | Selector literal |
-> PBLinSum | list of terms |
-> Integer | n |
-> m () |
Add a soft pseudo boolean constraints sel ⇒ c1*l1 + c2*l2 + … ≥ n.
Arguments
:: a | |
-> Lit | Selector literal |
-> PBLinSum | list of terms |
-> Integer | n |
-> m () |
Add a soft pseudo boolean constraints sel ⇒ c1*l1 + c2*l2 + … ≤ n.
Arguments
:: a | |
-> Lit | Selector literal |
-> PBLinSum | list of terms |
-> Integer | n |
-> m () |
Add a soft pseudo boolean constraints sel ⇒ c1*l1 + c2*l2 + … = n.
Instances
class AddPBLin m a => AddPBNL m a | a -> m where Source #
Minimal complete definition
Methods
Add a non-linear pseudo boolean constraints c1*ls1 + c2*ls2 + … ≥ n.
Add a non-linear pseudo boolean constraints c1*ls1 + c2*ls2 + … ≥ n.
Add a non-linear pseudo boolean constraints c1*ls1 + c2*ls2 + … = n.
Arguments
:: a | |
-> Lit | Selector literal |
-> PBSum | List of terms |
-> Integer | n |
-> m () |
Add a soft non-linear pseudo boolean constraints sel ⇒ c1*ls1 + c2*ls2 + … ≥ n.
Arguments
:: a | |
-> Lit | Selector literal |
-> PBSum | List of terms |
-> Integer | n |
-> m () |
Add a soft non-linear pseudo boolean constraints sel ⇒ c1*ls1 + c2*ls2 + … ≤ n.
Arguments
:: a | |
-> Lit | Selector literal |
-> PBSum | List of terms |
-> Integer | n |
-> m () |
Add a soft non-linear pseudo boolean constraints lit ⇒ c1*ls1 + c2*ls2 + … = n.
Instances
class AddClause m a => AddXORClause m a | a -> m where Source #
Minimal complete definition
Methods
Add a parity constraint l1 ⊕ l2 ⊕ … ⊕ ln = rhs
Add a soft parity constraint sel ⇒ l1 ⊕ l2 ⊕ … ⊕ ln = rhs