Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
N
NIWO
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Packages
Packages
Container Registry
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Christian Müller
NIWO
Commits
d5e78c71
Commit
d5e78c71
authored
Jul 21, 2017
by
Christian Müller
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
better tests
parent
8542dd8d
Changes
2
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
213 additions
and
176 deletions
+213
-176
src/main/scala/de/tum/workflows/toz3/toz3.scala
src/main/scala/de/tum/workflows/toz3/toz3.scala
+27
-23
src/test/scala/de/tum/workflows/ltl/tests/Z3Test.scala
src/test/scala/de/tum/workflows/ltl/tests/Z3Test.scala
+186
-153
No files found.
src/main/scala/de/tum/workflows/toz3/toz3.scala
View file @
d5e78c71
...
...
@@ -10,6 +10,9 @@ import java.util.HashMap
import
com.typesafe.scalalogging.LazyLogging
object
toZ3
extends
LazyLogging
{
type
VarCtx
=
Map
[
Var
,
(
Option
[
Int
]
,
Expr
,
Sort
)]
def
succ
(
ctx
:
Context
,
e
:
ArithExpr
)
=
{
val
One
=
ctx
.
mkInt
(
1
)
ctx
.
mkAdd
(
e
,
One
)
...
...
@@ -17,6 +20,7 @@ object toZ3 extends LazyLogging {
var
counter
=
0
// TODO: how to not make this static?
val
fun_ctx
=
new
HashMap
[
String
,
FuncDecl
]()
def
new_tname
()
=
{
...
...
@@ -24,7 +28,7 @@ object toZ3 extends LazyLogging {
"t"
+
counter
}
def
buildVarCtx
(
ctx
:
Context
,
var_ctx
:
Map
[
Var
,
(
Int
,
Expr
,
Sort
)],
vars
:
List
[
Var
])
=
{
def
buildVarCtx
(
ctx
:
Context
,
var_ctx
:
VarCtx
,
vars
:
List
[
Var
])
:
VarCtx
=
{
val
indices
=
(
vars
.
size
-
1
)
to
0
by
-
1
val
newexprs
=
(
for
((
v
,
i
)
<-
vars
.
zip
(
indices
))
yield
{
// count = count - 1;
...
...
@@ -35,26 +39,31 @@ object toZ3 extends LazyLogging {
}
else
{
ctx
.
mkFiniteDomainSort
(
v
.
typ
,
1
)
// TODO: sort size?
}
v
->
(
i
,
ctx
.
mkBound
(
i
,
sort
),
sort
)
v
->
(
Some
(
i
)
,
ctx
.
mkBound
(
i
,
sort
),
sort
)
})
toMap
// if the index is defined, increment, otherwise use the expr (which is a constant f.e.)
val
oldvars
=
(
for
((
v
,
(
i
,
e
,
s
))
<-
var_ctx
)
yield
{
val
newi
=
i
+
vars
.
size
val
newbound
=
ctx
.
mkBound
(
newi
,
s
)
v
->
(
newi
,
newbound
,
s
)
if
(
i
.
isDefined
)
{
val
newi
=
i
.
get
+
vars
.
size
val
newbound
=
ctx
.
mkBound
(
newi
,
s
)
v
->
(
Some
(
newi
),
newbound
,
s
)
}
else
{
v
->
(
i
,
e
,
s
)
}
})
newexprs
++
oldvars
}
def
updateTime
(
texpr
:
ArithExpr
,
tvar
:
Option
[
Var
],
oldctx
:
Map
[
Var
,
(
Int
,
Expr
,
Sort
)],
newctx
:
Map
[
Var
,
(
Int
,
Expr
,
Sort
)]
)
=
{
def
updateTime
(
texpr
:
ArithExpr
,
tvar
:
Option
[
Var
],
oldctx
:
VarCtx
,
newctx
:
VarCtx
)
=
{
if
(
tvar
.
isEmpty
)
{
texpr
}
else
{
texpr
.
substitute
(
oldctx
(
tvar
.
get
).
_2
,
newctx
(
tvar
.
get
).
_2
).
asInstanceOf
[
ArithExpr
]
}
}
def
unaryTemporalOperator
(
ctx
:
Context
,
f
:
Formula
,
texpr
:
ArithExpr
,
tvar
:
Option
[
Var
],
var_ctx
:
Map
[
Var
,
(
Int
,
Expr
,
Sort
)]
)
=
{
var_ctx
:
VarCtx
)
=
{
val
new_tvar_name
=
new_tname
()
val
new_tsymbol
=
ctx
.
mkSymbol
(
new_tvar_name
)
val
new_tvar
=
Var
(
new_tvar_name
,
"Int"
)
...
...
@@ -71,7 +80,7 @@ object toZ3 extends LazyLogging {
}
def
toZ3
(
ctx
:
Context
,
f
:
Formula
,
texpr
:
ArithExpr
,
tvar
:
Option
[
Var
],
var_ctx
:
Map
[
Var
,
(
Int
,
Expr
,
Sort
)]
)
:
BoolExpr
=
{
var_ctx
:
VarCtx
)
:
BoolExpr
=
{
// texpr is an expression e with the form given by the following grammar:
// e ::= 0 | t | succ(e)
// tvar is Some(t) if e contains t or None otherwise
...
...
@@ -214,24 +223,19 @@ object toZ3 extends LazyLogging {
}
}
def
checkZ3
(
f
:
Formula
)
=
{
val
cfg
=
new
HashMap
[
String
,
String
]();
cfg
.
put
(
"model"
,
"true"
);
val
ctx
=
new
Context
(
cfg
);
def
translate
(
f
:
Formula
,
ctx
:
Context
)
=
{
logger
.
info
(
s
"Using formula:\n$f"
)
fun_ctx
.
clear
()
val
expr
=
toZ3
(
ctx
,
f
,
ctx
.
mkInt
(
0
),
None
,
Map
())
logger
.
info
(
s
"Checking Z3 expression:\n$expr"
)
val
s
=
ctx
.
mkSolver
()
s
.
add
(
expr
)
s
logger
.
info
(
s
"Built Z3 expression:\n$expr"
)
expr
}
def
checkZ3
(
f
:
Formula
,
ctx
:
Context
,
varctx
:
Map
[
Var
,
(
Int
,
Expr
,
Sort
)])
=
{
def
translate
(
f
:
Formula
,
ctx
:
Context
,
varctx
:
VarCtx
)
=
{
logger
.
info
(
s
"Using formula:\n${f.pretty()}"
)
fun_ctx
.
clear
()
val
expr
=
toZ3
(
ctx
,
f
,
ctx
.
mkInt
(
0
),
None
,
varctx
)
logger
.
info
(
s
"Checking Z3 expression:\n$expr"
)
val
s
=
ctx
.
mkSolver
()
s
.
add
(
expr
)
s
logger
.
info
(
s
"Built Z3 expression:\n$expr"
)
expr
}
}
src/test/scala/de/tum/workflows/ltl/tests/Z3Test.scala
View file @
d5e78c71
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment