toysolver-0.8.1: Assorted decision procedures for SAT, SMT, Max-SAT, PB, MIP, etc
Copyright(c) Masahiro Sakai 2012-2014
LicenseBSD-style
Maintainermasahiro.sakai@gmail.com
Stabilityprovisional
Portabilitynon-portable
Safe HaskellSafe-Inferred
LanguageHaskell2010
Extensions
  • Cpp
  • ScopedTypeVariables
  • UnboxedTuples
  • BangPatterns
  • InstanceSigs
  • DeriveDataTypeable
  • ConstrainedClassMethods
  • MultiParamTypeClasses
  • MagicHash
  • RecursiveDo
  • ExplicitForAll

ToySolver.SAT.Solver.CDCL

Description

A CDCL SAT solver.

It follows the design of MiniSat and SAT4J.

See also:

Synopsis

The Solver type

data Solver Source #

Solver instance

Instances

Instances details
AddCardinality IO Solver Source # 
Instance details

Defined in ToySolver.SAT.Solver.CDCL

Methods

addAtLeast :: Solver -> [Lit] -> Int -> IO () Source #

addAtMost :: Solver -> [Lit] -> Int -> IO () Source #

addExactly :: Solver -> [Lit] -> Int -> IO () Source #

AddClause IO Solver Source # 
Instance details

Defined in ToySolver.SAT.Solver.CDCL

Methods

addClause :: Solver -> Clause -> IO () Source #

AddPBLin IO Solver Source # 
Instance details

Defined in ToySolver.SAT.Solver.CDCL

AddXORClause IO Solver Source # 
Instance details

Defined in ToySolver.SAT.Solver.CDCL

Methods

addXORClause :: Solver -> [Lit] -> Bool -> IO () Source #

addXORClauseSoft :: Solver -> Lit -> [Lit] -> Bool -> IO () Source #

NewVar IO Solver Source # 
Instance details

Defined in ToySolver.SAT.Solver.CDCL

Methods

newVar :: Solver -> IO Var Source #

newVars :: Solver -> Int -> IO [Var] Source #

newVars_ :: Solver -> Int -> IO () Source #

newSolver :: IO Solver Source #

Create a new Solver instance.

newSolverWithConfig :: Config -> IO Solver Source #

Create a new Solver instance with a given configulation.

Basic data structures

type Var = Int Source #

Variable is represented as positive integers (DIMACS format).

type Lit = Int Source #

Positive (resp. negative) literals are represented as positive (resp. negative) integers. (DIMACS format).

literal Source #

Arguments

:: Var

variable

-> Bool

polarity

-> Lit 

Construct a literal from a variable and its polarity. True (resp False) means positive (resp. negative) literal.

litNot :: Lit -> Lit Source #

Negation of the Lit.

litVar :: Lit -> Var Source #

Underlying variable of the Lit

litPolarity :: Lit -> Bool Source #

Polarity of the Lit. True means positive literal and False means negative literal.

evalLit :: IModel m => m -> Lit -> Bool Source #

Problem specification

newVar :: NewVar m a => a -> m Var Source #

Add a new variable

newVars :: NewVar m a => a -> Int -> m [Var] Source #

Add variables. newVars a n = replicateM n (newVar a), but maybe faster.

newVars_ :: NewVar m a => a -> Int -> m () Source #

Add variables. newVars_ a n = newVars a n >> return (), but maybe faster.

resizeVarCapacity :: Solver -> Int -> IO () Source #

Pre-allocate internal buffer for n variables.

Clauses

class NewVar m a => AddClause m a | a -> m where Source #

Methods

addClause :: a -> Clause -> m () Source #

Instances

Instances details
AddClause IO Solver Source # 
Instance details

Defined in ToySolver.SAT.Solver.CDCL

Methods

addClause :: Solver -> Clause -> IO () Source #

Monad m => AddClause m (Encoder m) Source # 
Instance details

Defined in ToySolver.SAT.Encoder.Cardinality

Methods

addClause :: Encoder m -> Clause -> m () Source #

Monad m => AddClause m (Encoder m) Source # 
Instance details

Defined in ToySolver.SAT.Encoder.Cardinality.Internal.Totalizer

Methods

addClause :: Encoder m -> Clause -> m () Source #

Monad m => AddClause m (Encoder m) Source # 
Instance details

Defined in ToySolver.SAT.Encoder.PB

Methods

addClause :: Encoder m -> Clause -> m () Source #

Monad m => AddClause m (Encoder m) Source # 
Instance details

Defined in ToySolver.SAT.Encoder.PBNLC

Methods

addClause :: Encoder m -> Clause -> m () Source #

Monad m => AddClause m (Encoder m) Source # 
Instance details

Defined in ToySolver.SAT.Encoder.Tseitin

Methods

addClause :: Encoder m -> Clause -> m () Source #

PrimMonad m => AddClause m (CNFStore m) Source # 
Instance details

Defined in ToySolver.SAT.Store.CNF

Methods

addClause :: CNFStore m -> Clause -> m () Source #

PrimMonad m => AddClause m (PBStore m) Source # 
Instance details

Defined in ToySolver.SAT.Store.PB

Methods

addClause :: PBStore m -> Clause -> m () Source #

type Clause = [Lit] Source #

Disjunction of Lit.

Cardinality constraints

class AddClause m a => AddCardinality m a | a -> m where Source #

Minimal complete definition

addAtLeast

Methods

addAtLeast Source #

Arguments

:: a 
-> [Lit]

set of literals {l1,l2,..} (duplicated elements are ignored)

-> Int

n

-> m () 

Add a cardinality constraints atleast({l1,l2,..},n).

addAtMost Source #

Arguments

:: a 
-> [Lit]

set of literals {l1,l2,..} (duplicated elements are ignored)

-> Int

n

-> m () 

Add a cardinality constraints atmost({l1,l2,..},n).

addExactly Source #

Arguments

:: a 
-> [Lit]

set of literals {l1,l2,..} (duplicated elements are ignored)

-> Int

n

-> m () 

Add a cardinality constraints exactly({l1,l2,..},n).

Instances

Instances details
AddCardinality IO Solver Source # 
Instance details

Defined in ToySolver.SAT.Solver.CDCL

Methods

addAtLeast :: Solver -> [Lit] -> Int -> IO () Source #

addAtMost :: Solver -> [Lit] -> Int -> IO () Source #

addExactly :: Solver -> [Lit] -> Int -> IO () Source #

PrimMonad m => AddCardinality m (Encoder m) Source # 
Instance details

Defined in ToySolver.SAT.Encoder.Cardinality

Methods

addAtLeast :: Encoder m -> [Lit] -> Int -> m () Source #

addAtMost :: Encoder m -> [Lit] -> Int -> m () Source #

addExactly :: Encoder m -> [Lit] -> Int -> m () Source #

PrimMonad m => AddCardinality m (Encoder m) Source # 
Instance details

Defined in ToySolver.SAT.Encoder.PB

Methods

addAtLeast :: Encoder m -> [Lit] -> Int -> m () Source #

addAtMost :: Encoder m -> [Lit] -> Int -> m () Source #

addExactly :: Encoder m -> [Lit] -> Int -> m () Source #

Monad m => AddCardinality m (Encoder m) Source # 
Instance details

Defined in ToySolver.SAT.Encoder.PBNLC

Methods

addAtLeast :: Encoder m -> [Lit] -> Int -> m () Source #

addAtMost :: Encoder m -> [Lit] -> Int -> m () Source #

addExactly :: Encoder m -> [Lit] -> Int -> m () Source #

PrimMonad m => AddCardinality m (PBStore m) Source # 
Instance details

Defined in ToySolver.SAT.Store.PB

Methods

addAtLeast :: PBStore m -> [Lit] -> Int -> m () Source #

addAtMost :: PBStore m -> [Lit] -> Int -> m () Source #

addExactly :: PBStore m -> [Lit] -> Int -> m () Source #

type AtLeast = ([Lit], Int) Source #

type Exactly = ([Lit], Int) Source #

(Linear) pseudo-boolean constraints

class AddCardinality m a => AddPBLin m a | a -> m where Source #

Minimal complete definition

addPBAtLeast

Methods

addPBAtLeast Source #

Arguments

:: a 
-> PBLinSum

list of terms [(c1,l1),(c2,l2),…]

-> Integer

n

-> m () 

Add a pseudo boolean constraints c1*l1 + c2*l2 + … ≥ n.

addPBAtMost Source #

Arguments

:: a 
-> PBLinSum

list of [(c1,l1),(c2,l2),…]

-> Integer

n

-> m () 

Add a pseudo boolean constraints c1*l1 + c2*l2 + … ≤ n.

addPBExactly Source #

Arguments

:: a 
-> PBLinSum

list of terms [(c1,l1),(c2,l2),…]

-> Integer

n

-> m () 

Add a pseudo boolean constraints c1*l1 + c2*l2 + … = n.

addPBAtLeastSoft Source #

Arguments

:: a 
-> Lit

Selector literal sel

-> PBLinSum

list of terms [(c1,l1),(c2,l2),…]

-> Integer

n

-> m () 

Add a soft pseudo boolean constraints sel ⇒ c1*l1 + c2*l2 + … ≥ n.

addPBAtMostSoft Source #

Arguments

:: a 
-> Lit

Selector literal sel

-> PBLinSum

list of terms [(c1,l1),(c2,l2),…]

-> Integer

n

-> m () 

Add a soft pseudo boolean constraints sel ⇒ c1*l1 + c2*l2 + … ≤ n.

addPBExactlySoft Source #

Arguments

:: a 
-> Lit

Selector literal sel

-> PBLinSum

list of terms [(c1,l1),(c2,l2),…]

-> Integer

n

-> m () 

Add a soft pseudo boolean constraints sel ⇒ c1*l1 + c2*l2 + … = n.

Instances

Instances details
AddPBLin IO Solver Source # 
Instance details

Defined in ToySolver.SAT.Solver.CDCL

PrimMonad m => AddPBLin m (Encoder m) Source # 
Instance details

Defined in ToySolver.SAT.Encoder.PB

Monad m => AddPBLin m (Encoder m) Source # 
Instance details

Defined in ToySolver.SAT.Encoder.PBNLC

PrimMonad m => AddPBLin m (PBStore m) Source # 
Instance details

Defined in ToySolver.SAT.Store.PB

XOR clauses

class AddClause m a => AddXORClause m a | a -> m where Source #

Minimal complete definition

addXORClause

Methods

addXORClause Source #

Arguments

:: a 
-> [Lit]

literals [l1, l2, …, ln]

-> Bool

rhs

-> m () 

Add a parity constraint l1 ⊕ l2 ⊕ … ⊕ ln = rhs

addXORClauseSoft Source #

Arguments

:: a 
-> Lit

Selector literal sel

-> [Lit]

literals [l1, l2, …, ln]

-> Bool

rhs

-> m () 

Add a soft parity constraint sel ⇒ l1 ⊕ l2 ⊕ … ⊕ ln = rhs

Instances

Instances details
AddXORClause IO Solver Source # 
Instance details

Defined in ToySolver.SAT.Solver.CDCL

Methods

addXORClause :: Solver -> [Lit] -> Bool -> IO () Source #

addXORClauseSoft :: Solver -> Lit -> [Lit] -> Bool -> IO () Source #

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)

Theory

Solving

solve :: Solver -> IO Bool Source #

Solve constraints. Returns True if the problem is SATISFIABLE. Returns False if the problem is UNSATISFIABLE.

solveWith Source #

Arguments

:: Solver 
-> [Lit]

Assumptions

-> IO Bool 

Solve constraints under assuptions. Returns True if the problem is SATISFIABLE. Returns False if the problem is UNSATISFIABLE.

cancel :: Solver -> IO () Source #

Cancel exectution of solve or solveWith.

This can be called from other threads.

Extract results

class IModel a where Source #

Methods

evalVar :: a -> Var -> Bool Source #

Instances

Instances details
IModel (UArray Var Bool) Source # 
Instance details

Defined in ToySolver.SAT.Types

Methods

evalVar :: UArray Var Bool -> Var -> Bool Source #

IModel (Array Var Bool) Source # 
Instance details

Defined in ToySolver.SAT.Types

Methods

evalVar :: Array Var Bool -> Var -> Bool Source #

IModel (Var -> Bool) Source # 
Instance details

Defined in ToySolver.SAT.Types

Methods

evalVar :: (Var -> Bool) -> Var -> Bool Source #

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 LitSet 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 LitSet 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

setVarPolarity :: Solver -> Var -> Bool -> IO () Source #

The default polarity of a variable.

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

Callbacks

setLogger :: Solver -> (String -> IO ()) -> IO () Source #

set callback function for receiving messages.

clearLogger :: Solver -> IO () Source #

Clear logger function set by setLogger.

setTerminateCallback :: Solver -> IO Bool -> IO () Source #

Set a callback function used to indicate a termination requirement to the solver.

The solver will periodically call this function and check its return value during the search. If the callback function returns True the solver terminates and throws Canceled exception.

See also clearTerminateCallback and IPASIR's ipasir_set_terminate() function.

clearTerminateCallback :: Solver -> IO () Source #

Clear a callback function set by setTerminateCallback

setLearnCallback :: Solver -> (Clause -> IO ()) -> IO () Source #

Set a callback function used to extract learned clauses from the solver. The solver will call this function for each learned clause.

See also clearLearnCallback and IPASIR's ipasir_set_learn() function.

clearLearnCallback :: Solver -> IO () Source #

Clear a callback function set by setLearnCallback

Read state

getNVars :: Solver -> IO Int Source #

number of variables of the problem.

getNConstraints :: Solver -> IO Int Source #

number of constraints.

getNLearntConstraints :: Solver -> IO Int Source #

number of learnt constrints.

getFixedLiterals :: Solver -> IO [Lit] Source #

it returns a set of literals that are fixed without any assumptions.

Internal API