module Jukebox.Sat.Minimise where
import Jukebox.Sat
solveLocalMin :: SatSolver s => s -> [Lit] -> [Lit] -> IO Bool
solveLocalMin s as ms =
do b <- solve s as
if b then do l <- newLit s
localMin s as l ms
addClause s [neg l]
return True
else do return False
localMin :: SatSolver s => s -> [Lit] -> Lit -> [Lit] -> IO ()
localMin s as l ms =
do
bs <- sequence [ modelValue s m | m <- ms ]
sequence_ [ addClause s [neg l, neg m] | (m,b) <- ms `zip` bs, b /= Just True ]
let ms1 = [ m | (m,Just True) <- ms `zip` bs ]
addClause s (neg l : [ neg m | m <- ms1 ])
b <- solve s (l:as)
if b then localMin s as l ms1
else return ()