Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
I
inox
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
LARA
inox
Commits
d228bea0
Commit
d228bea0
authored
12 years ago
by
Régis Blanc
Browse files
Options
Downloads
Patches
Plain Diff
fix bugs in SatSolver, can be run with scala (not with Leon though)
parent
1288fc0b
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
testcases/Sat.scala
+47
-46
47 additions, 46 deletions
testcases/Sat.scala
with
47 additions
and
46 deletions
testcases/Sat.scala
+
47
−
46
View file @
d228bea0
...
@@ -201,9 +201,10 @@ object Sat {
...
@@ -201,9 +201,10 @@ object Sat {
}
}
def
simplify
(
vars
:
VarList
)
:
VarList
=
vars
match
{
def
simplify
(
vars
:
VarList
)
:
VarList
=
vars
match
{
case
VarNil
()
=>
Var
Nil
(
)
case
VarNil
()
=>
Var
Lit
(
false
)
case
VarLit
(
b
)
=>
VarLit
(
b
)
case
VarLit
(
b
)
=>
VarLit
(
b
)
case
VarCons
(
VarLit
(
b
),
vs
)
=>
if
(
b
)
VarList
(
true
)
else
simplify
(
vs
)
case
VarCons
(
1
,
vs
)
=>
VarLit
(
true
)
case
VarCons
(-
1
,
vs
)
=>
simplify
(
vs
)
case
VarCons
(
v
,
vs
)
=>
VarCons
(
v
,
simplify
(
vs
))
case
VarCons
(
v
,
vs
)
=>
VarCons
(
v
,
simplify
(
vs
))
}
}
...
@@ -219,8 +220,8 @@ object Sat {
...
@@ -219,8 +220,8 @@ object Sat {
case
VarLit
(
b
)
=>
VarLit
(
b
)
case
VarLit
(
b
)
=>
VarLit
(
b
)
case
VarCons
(
v
,
vs
)
=>
case
VarCons
(
v
,
vs
)
=>
if
(
v
==
variable
&&
value
)
VarLit
(
true
)
if
(
v
==
variable
&&
value
)
VarLit
(
true
)
else
if
(
v
==
variable
&&
!
value
)
VarCons
(
VarLit
(
false
)
,
substitute
(
vs
,
variable
,
value
))
else
if
(
v
==
variable
&&
!
value
)
VarCons
(
-
1
,
substitute
(
vs
,
variable
,
value
))
else
if
(
v
==
-
variable
&&
value
)
VarCons
(
VarLit
(
false
)
,
substitute
(
vs
,
variable
,
value
))
else
if
(
v
==
-
variable
&&
value
)
VarCons
(
-
1
,
substitute
(
vs
,
variable
,
value
))
else
if
(
v
==
-
variable
&&
!
value
)
VarLit
(
true
)
else
if
(
v
==
-
variable
&&
!
value
)
VarLit
(
true
)
else
VarCons
(
v
,
substitute
(
vs
,
variable
,
value
))
else
VarCons
(
v
,
substitute
(
vs
,
variable
,
value
))
}
}
...
@@ -275,46 +276,46 @@ object Sat {
...
@@ -275,46 +276,46 @@ object Sat {
}
}
//
def main(args: Array[String]) {
def
main
(
args
:
Array
[
String
])
{
//
val f1 = And(Var(1), Or(Var(1), Not(Var(2)), Var(3)), Var(2), Not(Var(3)))
val
f1
=
And
(
Var
(
1
),
Or
(
Var
(
1
),
Not
(
Var
(
2
)),
Var
(
3
)),
Var
(
2
),
Not
(
Var
(
3
)))
//
val dnff1 = clauses2list(dnfNaive(f1))
val
dnff1
=
clauses2list
(
dnfNaive
(
f1
))
//
val vars1 = vars(f1)
val
vars1
=
vars
(
f1
)
//
vars.foreach(v => {
//
vars.foreach(v => {
//
//
//
})
//
})
//
println(f1 + " translated in dnf as:\n\t" + dnff1.mkString("\n\t"))
println
(
f1
+
" translated in dnf as:\n\t"
+
dnff1
.
mkString
(
"\n\t"
))
//
}
}
//some non-leon functions to test the program with scala
//some non-leon functions to test the program with scala
//
object False {
object
False
{
//
def apply(): Formula = And(Var(1), Not(Var(1)))
def
apply
()
:
Formula
=
And
(
Var
(
1
),
Not
(
Var
(
1
)))
//
}
}
//
object True {
object
True
{
//
def apply(): Formula = Or(Var(1), Not(Var(1)))
def
apply
()
:
Formula
=
Or
(
Var
(
1
),
Not
(
Var
(
1
)))
//
}
}
//
object Or {
object
Or
{
//
def apply(fs: Formula*): Formula = fs match {
def
apply
(
fs
:
Formula*
)
:
Formula
=
fs
match
{
//
case Seq() => False()
case
Seq
()
=>
False
()
//
case Seq(f) => f
case
Seq
(
f
)
=>
f
//
case fs => fs.reduceLeft((f1, f2) => Or(f1, f2))
case
fs
=>
fs
.
reduceLeft
((
f1
,
f2
)
=>
Or
(
f1
,
f2
))
//
}
}
//
}
}
//
object And {
object
And
{
//
def apply(fs: Formula*): Formula = fs match {
def
apply
(
fs
:
Formula*
)
:
Formula
=
fs
match
{
//
case Seq() => True()
case
Seq
()
=>
True
()
//
case Seq(f) => f
case
Seq
(
f
)
=>
f
//
case fs => fs.reduceLeft((f1, f2) => And(f1, f2))
case
fs
=>
fs
.
reduceLeft
((
f1
,
f2
)
=>
And
(
f1
,
f2
))
//
}
}
//
}
}
//
def clause2list(cl: VarList): List[Int] = cl match {
def
clause2list
(
cl
:
VarList
)
:
List
[
Int
]
=
cl
match
{
//
case VarCons(v, vs) => v :: clause2list(vs)
case
VarCons
(
v
,
vs
)
=>
v
::
clause2list
(
vs
)
//
case VarNil() => Nil
case
VarNil
()
=>
Nil
//
case VarLit(b) => if(b) List(1) else List(-1)
case
VarLit
(
b
)
=>
if
(
b
)
List
(
1
)
else
List
(-
1
)
//
}
}
//
def clauses2list(cll: ClauseList): List[List[Int]] = cll match {
def
clauses2list
(
cll
:
ClauseList
)
:
List
[
List
[
Int
]]
=
cll
match
{
//
case ClauseCons(cl, cls) => clause2list(cl) :: clauses2list(cls)
case
ClauseCons
(
cl
,
cls
)
=>
clause2list
(
cl
)
::
clauses2list
(
cls
)
//
case ClauseNil() => Nil
case
ClauseNil
()
=>
Nil
//
case ClauseLit(b) => if(b) List(List(1)) else List(List(-1))
case
ClauseLit
(
b
)
=>
if
(
b
)
List
(
List
(
1
))
else
List
(
List
(-
1
))
//
}
}
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment