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
aa3504e5
Commit
aa3504e5
authored
Jul 16, 2018
by
Christian Müller
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
model extraction
parent
663f1e49
Changes
11
Hide whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
130 additions
and
35 deletions
+130
-35
build.sbt
build.sbt
+1
-1
classes/artifacts/LoopingWorkflows_jar/LoopingWorkflows.jar
classes/artifacts/LoopingWorkflows_jar/LoopingWorkflows.jar
+0
-0
classes/artifacts/loopingworkflows_jar/niwo-ltl.jar
classes/artifacts/loopingworkflows_jar/niwo-ltl.jar
+0
-0
project/build.properties
project/build.properties
+1
-1
src/main/scala/de/tum/workflows/MainInvariants.scala
src/main/scala/de/tum/workflows/MainInvariants.scala
+1
-4
src/main/scala/de/tum/workflows/MainInvariantsInference.scala
...main/scala/de/tum/workflows/MainInvariantsInference.scala
+76
-0
src/main/scala/de/tum/workflows/Utils.scala
src/main/scala/de/tum/workflows/Utils.scala
+1
-1
src/main/scala/de/tum/workflows/toz3/InvariantChecker.scala
src/main/scala/de/tum/workflows/toz3/InvariantChecker.scala
+33
-25
src/main/scala/de/tum/workflows/toz3/Z3.scala
src/main/scala/de/tum/workflows/toz3/Z3.scala
+4
-2
src/main/scala/de/tum/workflows/toz3/Z3QFree.scala
src/main/scala/de/tum/workflows/toz3/Z3QFree.scala
+12
-0
src/test/scala/de/tum/workflows/ltl/tests/InvariantTest.scala
...test/scala/de/tum/workflows/ltl/tests/InvariantTest.scala
+1
-1
No files found.
build.sbt
View file @
aa3504e5
...
...
@@ -11,7 +11,7 @@ libraryDependencies ++= Seq(
"ch.qos.logback"
%
"logback-classic"
%
"1.1.7"
,
"org.scalactic"
%%
"scalactic"
%
"3.0.4"
%
"test"
,
"org.scalatest"
%%
"scalatest"
%
"3.0.4"
%
"test"
,
"org.scala-graph"
%%
"graph-core"
%
"1.12.
1
"
,
"org.scala-graph"
%%
"graph-core"
%
"1.12.
5
"
,
"org.scala-graph"
%%
"graph-dot"
%
"1.12.1"
,
"org.scala-lang.modules"
%%
"scala-parser-combinators"
%
"1.0.5"
)
...
...
classes/artifacts/LoopingWorkflows_jar/LoopingWorkflows.jar
0 → 100644
View file @
aa3504e5
File added
classes/artifacts/loopingworkflows_jar/niwo-ltl.jar
0 → 100644
View file @
aa3504e5
File added
project/build.properties
View file @
aa3504e5
sbt.version
=
1.1.
2
sbt.version
=
1.1.
6
src/main/scala/de/tum/workflows/MainInvariants.scala
View file @
aa3504e5
...
...
@@ -27,10 +27,7 @@ object MainInvariants extends App with LazyLogging {
// InvariantChecker.invariantNoninterStubborn _
// InvariantChecker.invariantAllEqual _
val
(
t
,
(
res
,
dot
))
=
time
{
// InvariantChecker.checkInvariantOnce(spec.w, inv(spec), true)
InvariantChecker
.
checkInvariantFP
(
spec
,
invariant
(
spec
))
}
val
(
res
,
dot
,
t
)
=
InvariantChecker
.
checkInvariantFPDot
(
spec
,
invariant
(
spec
))
val
msg
=
s
"Invariant was ${if (res) "" else "
not
"}proven (took $t ms)\n"
write
(
s
"$name.inv"
,
msg
)
...
...
src/main/scala/de/tum/workflows/MainInvariantsInference.scala
0 → 100644
View file @
aa3504e5
package
de.tum.workflows
import
com.microsoft.z3.Status
import
com.typesafe.scalalogging.LazyLogging
import
de.tum.workflows.Utils._
import
de.tum.workflows.blocks.Spec
import
de.tum.workflows.toz3._
object
MainInvariantsInference
extends
App
with
LazyLogging
{
def
generate
(
name
:
String
,
spec
:
Spec
)
{
logger
.
info
(
s
"Encoding Spec:\n$spec"
)
def
invariant
=
InvariantGenerator
.
invariantNoninterStubbornSingleBS
_
// InvariantGenerator.invariantNoninterStubbornBS _
// InvariantChecker.invariantNoninterStubborn _
// InvariantChecker.invariantAllEqual _
val
(
res
,
label
,
t
)
=
InvariantChecker
.
checkInvariantFPHeadLabel
(
spec
,
invariant
(
spec
),
InvProperties
(
stubborn
=
false
,
eliminateAux
=
false
))
val
msg
=
s
"Invariant was ${if (res) "" else "
not
"}proven (took $t ms)\n"
// Invariant not valid
if
(!
res
)
{
// Try to break headlabel invariant
val
(
status
,
solver
)
=
InvariantChecker
.
checkOnZ3
(
label
)
if
(
status
==
Status
.
SATISFIABLE
)
{
// Broken, found model
// logger.info(s"Model:\n${Z3.printModel(solver.getModel())}")
logger
.
info
(
s
"Initial State Invariant: ${label}"
)
val
model
=
Z3QFree
.
modelFacts
(
solver
.
getModel
())
model
foreach
{
f
=>
logger
.
info
(
f
.
toString
())
}
// Not constant
val
tar
=
1
val
g
=
Encoding
.
toGraph
(
spec
.
w
)
}
else
{
logger
.
error
(
"Invariant not valid, but also not satisfiable."
)
}
}
}
def
generateExample
(
name
:
String
)
{
logger
.
info
(
s
"Generating $name"
)
val
spec
=
ExampleWorkflows
.
parseExample
(
name
)
if
(
spec
.
isEmpty
)
{
logger
.
error
(
s
"Not a valid spec: $name"
)
}
spec
.
foreach
(
generate
(
name
,
_
))
}
def
generateAllExamples
()
{
clear
()
// Fill results alphabetically
for
(
k
<-
ExampleWorkflows
.
examples
.
keys
.
toList
.
sorted
)
{
generateExample
(
k
)
}
}
clear
()
// generateExample("nonomitting/conference")
generateExample
(
"tests/conference_linear_small"
)
// generateExample("tests/loopexampleNoOracle")
// generateAllExamples()
}
\ No newline at end of file
src/main/scala/de/tum/workflows/Utils.scala
View file @
aa3504e5
...
...
@@ -70,7 +70,7 @@ object Utils extends LazyLogging {
val
filenames
=
s
"${name}_$model${if (desc.isEmpty()) "" else s"
_$desc
"}"
// do not blow up the formula with auxilliary elimination
val
(
res
,
graph
,
labelling
,
provens
,
dot
,
time
)
=
val
(
res
,
graph
,
labelling
,
provens
,
dot
,
time
,
headlabel
)
=
InvariantChecker
.
checkInvariantFPLabelling
(
spec
,
inv
,
properties
)
for
((
s
,
i
)
<-
dot
.
zipWithIndex
)
{
Utils
.
write
(
s
"${filenames}_$i.dot"
,
s
)
...
...
src/main/scala/de/tum/workflows/toz3/InvariantChecker.scala
View file @
aa3504e5
...
...
@@ -22,7 +22,7 @@ import de.tum.workflows.foltl.Properties
case
class
InvProperties
(
stubborn
:
Boolean
,
eliminateAux
:
Boolean
)
{
}
object
InvProperties
{
val
DEFAULT
=
InvProperties
(
true
,
true
)
val
DEFAULT
=
InvProperties
(
stubborn
=
true
,
eliminateAux
=
true
)
}
object
InvariantChecker
extends
LazyLogging
{
...
...
@@ -47,10 +47,9 @@ object InvariantChecker extends LazyLogging {
// Can only check universal things
val
neg
=
Neg
(
f
).
simplify
()
//
univfree
is now in E*, so can be solved as SAT Problem
//
neg
is now in E*, so can be solved as SAT Problem
val
stripped
=
FormulaFunctions
.
stripQuantifiers
(
neg
)
// val prefix = FormulaFunctions.collectQuantifiersSub(univfree)
val
satform
=
FOTransformers
.
eliminatePredicates
(
stripped
)
// Checking QFree
...
...
@@ -107,7 +106,7 @@ object InvariantChecker extends LazyLogging {
val
labels
=
labellist
.
head
val
proven
=
provenlist
.
head
// check if done, i.e. all edges proven
val
toProve
=
(
graph
.
edges
--
proven
)
val
toProve
=
graph
.
edges
--
proven
if
(
toProve
.
isEmpty
)
{
logger
.
info
(
"Everything proven. Terminating."
)
(
true
,
labellist
,
provenlist
)
...
...
@@ -137,22 +136,22 @@ object InvariantChecker extends LazyLogging {
// check if relabelled invariant still satisfiable
// never relabel initial node
logger
.
info
(
s
"Invariant not inductive, strengthening."
)
if
(!
isfirst
)
{
// check if strengthened -> old_inv else use conjunction
// val strengthened = Preconditions.abstractPrecondition(post, next, spec, properties)
val
newinv
=
And
(
labels
(
next
.
_1
),
strengthened
).
simplify
()
val
nostrangebindings
=
FormulaFunctions
.
checkBindings
(
newinv
)
if
(!
nostrangebindings
)
{
logger
.
error
(
"New invariant binds variables more than once"
)
logger
.
error
(
s
"Invariant would be $newinv"
)
}
val
newlabels
=
labels
.
updated
(
next
.
_1
,
strengthened
)
val
newinv
=
And
(
labels
(
next
.
_1
),
strengthened
).
simplify
()
val
nostrangebindings
=
FormulaFunctions
.
checkBindings
(
newinv
)
if
(!
nostrangebindings
)
{
logger
.
error
(
"New invariant binds variables more than once"
)
logger
.
error
(
s
"Invariant would be $newinv"
)
}
val
newlabels
=
labels
.
updated
(
next
.
_1
,
strengthened
)
if
(!
isfirst
)
{
val
invalidated
=
proven
.
filter
(
_
.
_2
==
next
.
_1
)
val
newproven
=
(
proven
--
invalidated
)
+
next
val
(
status2
,
solver2
)
=
checkOnZ3
(
Implies
(
newinv
,
False
))
if
(
status2
==
Status
.
SATISFIABLE
)
{
// Negation of newinv still sat, newinv does not imply false)
...
...
@@ -163,9 +162,9 @@ object InvariantChecker extends LazyLogging {
(
false
,
newlabels
::
labellist
,
newproven
::
provenlist
)
}
}
else
{
logger
.
info
(
"
Would have to relabel
initial node. Terminating."
)
logger
.
info
(
s
"Model: ${Z3.printModel(solver.getModel())}"
)
(
false
,
labellist
,
provenlist
)
logger
.
info
(
"
Relabelled
initial node. Terminating."
)
//
logger.info(s"Model: ${Z3.printModel(solver.getModel())}")
(
false
,
newlabels
,
provenlist
)
}
}
}
...
...
@@ -176,16 +175,25 @@ object InvariantChecker extends LazyLogging {
val
(
time
,
(
result
,
labellings
,
proven
))
=
Utils
.
time
{
checkInvariantRec
(
labels
,
List
(
Set
()))
}
val
dot1
=
labellings
.
zip
(
proven
).
reverse
val
dot2
=
dot1
.
map
(
(
tup
)
=>
Encoding
.
toDot
(
graph
)(
tup
.
_1
.
map
(
t
=>
(
t
.
_1
,
{
val
dot2
=
dot1
.
map
(
tup
=>
Encoding
.
toDot
(
graph
)(
tup
.
_1
.
map
(
t
=>
(
t
.
_1
,
{
if
(
t
.
_2
.
opsize
()
<=
5000
)
t
.
_2
.
pretty
()
else
"TOO BIG"
})),
tup
.
_2
))
// Find out label of initial node
val
startnode
=
graph
.
find
(
0
).
get
val
headlabel
=
labellings
.
last
.
get
(
startnode
).
get
(
result
,
graph
,
labellings
.
reverse
,
proven
.
reverse
,
dot2
,
time
)
(
result
,
graph
,
labellings
.
reverse
,
proven
.
reverse
,
dot2
,
time
,
headlabel
)
}
def
checkInvariantFP
(
spec
:
Spec
,
inv
:
Formula
,
properties
:
InvProperties
=
InvProperties
.
DEFAULT
)
=
{
val
(
result
,
graph
,
afterlabels
,
proven
,
dot
,
time
)
=
checkInvariantFPLabelling
(
spec
,
inv
,
properties
)
(
result
,
dot
)
def
checkInvariantFPDot
(
spec
:
Spec
,
inv
:
Formula
,
properties
:
InvProperties
=
InvProperties
.
DEFAULT
)
=
{
val
(
result
,
graph
,
afterlabels
,
proven
,
dot
,
time
,
_
)
=
checkInvariantFPLabelling
(
spec
,
inv
,
properties
)
(
result
,
dot
,
time
)
}
def
checkInvariantFPHeadLabel
(
spec
:
Spec
,
inv
:
Formula
,
properties
:
InvProperties
=
InvProperties
.
DEFAULT
)
=
{
val
(
result
,
graph
,
afterlabels
,
proven
,
dot
,
time
,
headlabel
)
=
checkInvariantFPLabelling
(
spec
,
inv
,
properties
)
(
result
,
headlabel
,
time
)
}
def
checkInvariantOnce
(
spec
:
Spec
,
inv
:
Formula
,
properties
:
InvProperties
)
=
{
...
...
src/main/scala/de/tum/workflows/toz3/Z3.scala
View file @
aa3504e5
...
...
@@ -270,7 +270,7 @@ object Z3 extends LazyLogging {
// sb ++= s"Type $k: ${v.mkString(",")}\n"
// }
sb
++=
"
Evalu
ations:\n"
sb
++=
"
Rel
ations:\n"
val
sortedConsts
=
model
.
getConstDecls
().
sortBy
(
_
.
getName
.
toString
())
val
(
l1
,
l2
)
=
sortedConsts
.
partition
(
s
=>
{
...
...
@@ -279,7 +279,7 @@ object Z3 extends LazyLogging {
case
_
=>
false
}
})
val
funs
=
l1
.
map
(
s
=>
{
val
interp
=
model
.
getConstInterp
(
s
)
(
FunFromVar
.
unapply
(
s
.
getName
.
toString
).
get
,
interp
.
toString
)
...
...
@@ -299,6 +299,8 @@ object Z3 extends LazyLogging {
}
sb
++=
"\n"
}
sb
++=
"\nNon-Relations:\n"
// Rest of the consts
for
(
f
<-
l2
)
{
...
...
src/main/scala/de/tum/workflows/toz3/Z3QFree.scala
View file @
aa3504e5
...
...
@@ -146,6 +146,18 @@ object Z3QFree extends LazyLogging {
}
}
def
modelFacts
(
model
:
Model
)
:
List
[(
Fun
,
Formula
)]
=
{
val
sortedConsts
=
model
.
getConstDecls
().
sortBy
(
_
.
getName
.
toString
())
val
funs
=
sortedConsts
.
map
(
s
=>
{
val
fun
=
FunFromVar
.
unapply
(
s
.
getName
.
toString
).
get
val
interp
=
Z3QFree
.
mapback
(
model
.
getConstInterp
(
s
))
(
fun
,
interp
)
})
toList
funs
}
def
translate
(
f
:
Formula
,
ctx
:
Context
)
=
{
// logger.info(s"Using formula:\n$f")
val
expr
=
toZ3
(
ctx
,
f
)
...
...
src/test/scala/de/tum/workflows/ltl/tests/InvariantTest.scala
View file @
aa3504e5
...
...
@@ -42,7 +42,7 @@ class InvariantTest extends FlatSpec {
val
inv
=
Forall
(
List
(
"a"
,
"b"
),
Eq
(
Fun
(
"R"
,
Some
(
"t1"
),
List
(
"a"
,
"b"
)),
Fun
(
"R"
,
Some
(
"t2"
),
List
(
"a"
,
"b"
))))
val
(
safe
,
msg
)
=
InvariantChecker
.
checkInvariantFP
(
spec
,
inv
)
val
(
safe
,
msg
,
time
)
=
InvariantChecker
.
checkInvariantFPDot
(
spec
,
inv
)
safe
should
be
(
true
)
}
...
...
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