picosat 0.1.0.0 → 0.1.0.1
raw patch · 2 files changed
+29/−16 lines, 2 files
Files
- picosat.cabal +6/−5
- src/Picosat.hs +23/−11
picosat.cabal view
@@ -1,28 +1,29 @@ name: picosat-version: 0.1.0.0+version: 0.1.0.1 synopsis: Bindings to the PicoSAT solver-homepage: http://www.stephendiehl.com+homepage: https://github.com/sdiehl/haskell-picosat license: MIT license-file: LICENSE author: Stephen Diehl maintainer: stephen.m.diehl@gmail.com copyright: 2012 Stephen Diehl-category: Math+Category: Logic build-type: Simple cabal-version: >=1.10 extra-source-files: cbits/picosat.h Bug-Reports: https://github.com/sdiehl/haskell-picosat/issues -Category: Logic Description: `picosat` provides bindings for the fast PicoSAT solver library. Source-Repository head Type: git- Location: https://github.com/sdiehl/haskell-picosat+ Location: git@github.com:sdiehl/haskell-picosat.git library exposed-modules: Picosat+ other-extensions:+ ForeignFunctionInterface Cc-options: Ghc-options: -Wall
src/Picosat.hs view
@@ -1,5 +1,19 @@ {-# LANGUAGE ForeignFunctionInterface #-} +{- | The solve function takes a nested list of integers representing variables in clauses and returns the+ solution. Usage:++@+import Picosat++main :: IO [Int]+main = do+ solve [[1, -2, 3], [2,4,5], [4,6]]+ -- Solution [1,-2,3,4,5,6]+@++-}+ module Picosat ( solve, solveST,@@ -17,24 +31,22 @@ import Foreign.Ptr import Foreign.C.Types -default (Int)--foreign import ccall unsafe "picosat_init" picosat_init+foreign import ccall safe "picosat_init" picosat_init :: IO (Ptr a) -foreign import ccall unsafe "picosat_reset" picosat_reset+foreign import ccall safe "picosat_reset" picosat_reset :: Ptr a -> IO () -foreign import ccall unsafe "picosat_add" picosat_add+foreign import ccall safe "picosat_add" picosat_add :: Ptr a -> CInt -> IO CInt -foreign import ccall unsafe "picosat_variables" picosat_variables+foreign import ccall safe "picosat_variables" picosat_variables :: Ptr a -> IO CInt -foreign import ccall unsafe "picosat_sat" picosat_sat+foreign import ccall safe "picosat_sat" picosat_sat :: Ptr a -> CInt -> IO CInt -foreign import ccall unsafe "picosat_deref" picosat_deref+foreign import ccall safe "picosat_deref" picosat_deref :: Ptr a -> CInt -> IO CInt unknown, satisfiable, unsatisfiable :: CInt@@ -69,12 +81,12 @@ | a == satisfiable -> getSolution pico | otherwise -> error "Picosat error." -toCIntegers :: Integral a => [[a]] -> [[CInt]]-toCIntegers = map $ map fromIntegral+toCInts :: Integral a => [[a]] -> [[CInt]]+toCInts = map $ map fromIntegral solve :: Integral a => [[a]] -> IO Solution solve cls = do- let ccls = toCIntegers cls+ let ccls = toCInts cls pico <- picosat_init _ <- addClauses pico ccls sol <- solution pico