Skip to content
Snippets Groups Projects
Commit 0e97bfb0 authored by Philippe Suter's avatar Philippe Suter
Browse files

little Sat solver in one (big, fat) line

parent 1e525071
No related branches found
No related tags found
No related merge requests found
import cp.Definitions._
import cp.Terms._
object SatSolver extends App {
val problem : List[List[Int]] = List(
List(-1, 2, 3),
List(1, -2),
List(4)
)
type CM = Constraint1[Map[Int,Boolean]]
val solution : CM =
problem.foldLeft[CM]((m:Map[Int,Boolean]) => true)((cons:CM,clause:List[Int]) => cons && clause.foldLeft[CM]((m:Map[Int,Boolean]) => false)((cons:CM,lit:Int) => {
val isPos = lit > 0
val abs = scala.math.abs(lit)
cons || ((m:Map[Int,Boolean]) => m(abs) == isPos)
}))
val answer = solution.solve
println("Solution map : " + answer)
(1 to 4).foreach(i => println("i : " + answer(i)))
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment