sdiehl / haskell-picosat Goto Github PK
View Code? Open in Web Editor NEWHaskell bindings for PicoSAT solver
License: MIT License
Haskell bindings for PicoSAT solver
License: MIT License
If you create a large problem, then picosat fails with stack overflow. It actually creates and solves the problem, but fails in getSolution while going through the results with forM. Here is a test program and a new version of forM which would work for arbitrary large problems (as long as you have heap space). It returns the solution list in the same order as before, but if you remove the "reverse" in the mapM', then it would still work but return the result in the opposite order (and would be slightly faster).
module Main where
import Control.Monad (forM)
import Picosat
vars :: Int
vars = 1000000
clauses :: [[Int]]
clauses = fmap (\x -> [x]) [1 .. vars]
main :: IO ()
main = do
putStrLn "Running new forM':"
sol1 <- forM' [1 .. vars] return
print $ last sol1
-- putStrLn "Running old forM:"
-- sol2 <- forM [1 .. vars] return
-- print $ last sol2
putStrLn $ "Running Picosat with " ++ show (length clauses) ++ " clauses:"
sol <- Picosat.solve clauses
putStrLn $ show sol
mapM' :: Monad m => (a -> m b) -> [a] -> [b] -> m [b]
mapM' _ [] ys = return (reverse ys)
mapM' f (x : xs) ys = f x >>= \y -> mapM' f xs (y : ys)
forM' :: Monad m => [a] -> (a -> m b) -> m [b]
forM' xs f = mapM' f xs []
In the Stackage Nightly build:
Building picosat-0.1.4...
Preprocessing library picosat-0.1.4...
[1 of 1] Compiling Picosat ( src/Picosat.hs, dist/build/Picosat.o )
Preprocessing test suite 'Sudoku' for picosat-0.1.4...
[1 of 1] Compiling Main ( test/Sudoku.hs, dist/build/Sudoku/Sudoku-tmp/Main.o )
Linking dist/build/Sudoku/Sudoku ...
Preprocessing test suite 'Scoped' for picosat-0.1.4...
[1 of 1] Compiling Main ( test/Scoped.hs, dist/build/Scoped/Scoped-tmp/Main.o )
Linking dist/build/Scoped/Scoped ...
Preprocessing test suite 'rand-shared-improvement' for picosat-0.1.4...
[1 of 1] Compiling Main ( test/Rand.hs, dist/build/rand-shared-improvement/rand-shared-improvement-tmp/Main.o )
test/Rand.hs:2:1: error:
Failed to load interface for ‘RandomCNF’
Use -v to see a list of the files searched for.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.