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
4a9c1410
Commit
4a9c1410
authored
9 years ago
by
Etienne Kneuss
Browse files
Options
Downloads
Patches
Plain Diff
Update tests to new API
parent
7542e642
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/integration/scala/leon/integration/solvers/ModelEnumerationSuite.scala
+64
-60
64 additions, 60 deletions
...cala/leon/integration/solvers/ModelEnumerationSuite.scala
src/main/scala/leon/utils/ModelEnumerator.scala
+2
-11
2 additions, 11 deletions
src/main/scala/leon/utils/ModelEnumerator.scala
with
66 additions
and
71 deletions
src/integration/scala/leon/integration/solvers/ModelEnumerationSuite.scala
+
64
−
60
View file @
4a9c1410
...
...
@@ -52,13 +52,15 @@ class ModelEnumeratorSuite extends LeonTestSuiteWithProgram with ExpressionsDSL
val
cnstr
=
GreaterThan
(
fcall
(
"List1.size"
)(
l
.
toVariable
),
bi
(
2
))
val
me
=
getModelEnum
val
enum
=
me
.
enumSimple
(
Seq
(
l
),
cnstr
)
try
{
val
models
=
me
.
enum
Simple
(
Seq
(
l
),
cnstr
)
.
take
(
5
).
toList
val
models
=
enum
.
take
(
5
).
toList
assert
(
models
.
size
===
5
,
"We can enumerate at least 5 lists of size 3+"
)
assert
(
models
.
toSet
.
size
===
5
,
"Models are distinct"
)
}
finally
{
me
.
shutdown
()
enum
.
free
()
}
}
...
...
@@ -70,13 +72,11 @@ class ModelEnumeratorSuite extends LeonTestSuiteWithProgram with ExpressionsDSL
val
me
=
getModelEnum
try
{
val
models
=
me
.
enumSimple
(
Seq
(
l
),
cnstr
).
take
(
5
).
toList
val
enum
=
me
.
enumSimple
(
Seq
(
l
),
cnstr
)
val
models
=
enum
.
take
(
5
).
toList
enum
.
free
()
assert
(
models
.
size
===
1
,
"We can only enumerate one list of size 0"
)
}
finally
{
me
.
shutdown
()
}
assert
(
models
.
size
===
1
,
"We can only enumerate one list of size 0"
)
}
test
(
"Varying model enumeration 1"
)
{
implicit
fix
=>
...
...
@@ -92,38 +92,45 @@ class ModelEnumeratorSuite extends LeonTestSuiteWithProgram with ExpressionsDSL
val
evaluator
=
new
DefaultEvaluator
(
fix
.
_1
,
fix
.
_2
)
val
me
=
getModelEnum
try
{
// 1 model of each size
val
models1
=
me
.
enum
Varying
(
Seq
(
l
),
cnstr
,
car
)
.
toList
assert
(
models1
.
size
===
2
,
"We can enumerate 2 lists of varying size 0 < .. < 3"
)
// 1 model of each size
val
enum1
=
me
.
enumVarying
(
Seq
(
l
),
cnstr
,
car
)
val
models1
=
enum
1
.
toList
enum1
.
free
(
)
// 3 models of each size
val
models2
=
me
.
enumVarying
(
Seq
(
l
),
cnstr
,
car
,
3
).
toList
assert
(
models2
.
size
===
6
,
"We can enumerate 6 lists of varying size 0 < .. < 3 with 3 per size"
)
assert
(
models1
.
size
===
2
,
"We can enumerate 2 lists of varying size 0 < .. < 3"
)
// 3 models of each size
val
enum2
=
me
.
enumVarying
(
Seq
(
l
),
cnstr
,
car
,
3
)
val
models2
=
enum2
.
toList
enum2
.
free
()
val
car2
=
fcall
(
"List1.sum"
)(
l
.
toVariable
)
assert
(
models2
.
size
===
6
,
"We can enumerate 6 lists of varying size 0 < .. < 3 with 3 per size"
)
// 1 model of each sum
val
models3
=
me
.
enumVarying
(
Seq
(
l
),
cnstr
,
car2
).
take
(
4
).
toList
assert
(
models3
.
size
===
4
,
"We can enumerate >=4 lists of varying sum, with 0 < .. < 3"
)
val
carResults3
=
models3
.
groupBy
(
m
=>
evaluator
.
eval
(
car2
,
m
).
result
.
get
)
assert
(
carResults3
.
size
===
4
,
"We should have 4 distinct sums"
)
assert
(
carResults3
.
forall
(
_
.
_2
.
size
===
1
),
"We should have 1 model per sum"
)
val
car2
=
fcall
(
"List1.sum"
)(
l
.
toVariable
)
// 2 model of each sum
val
models4
=
me
.
enumVarying
(
Seq
(
l
),
cnstr
,
car2
,
2
).
take
(
4
).
toList
assert
(
models4
.
size
===
4
,
"We can enumerate >=4 lists of varying sum, with 0 < .. < 3"
)
// 1 model of each sum
val
enum3
=
me
.
enumVarying
(
Seq
(
l
),
cnstr
,
car2
)
val
models3
=
enum3
.
take
(
4
).
toList
enum3
.
free
()
val
carResults4
=
models4
.
groupBy
(
m
=>
evaluator
.
eval
(
car2
,
m
).
result
.
get
)
assert
(
carResults4
.
size
>=
2
,
"We should have at least 2 distinct sums"
)
assert
(
carResults4
.
forall
(
_
.
_2
.
size
<=
2
),
"We should have at most 2 models per sum"
)
assert
(
models3
.
size
===
4
,
"We can enumerate >=4 lists of varying sum, with 0 < .. < 3"
)
val
carResults3
=
models3
.
groupBy
(
m
=>
evaluator
.
eval
(
car2
,
m
).
result
.
get
)
assert
(
carResults3
.
size
===
4
,
"We should have 4 distinct sums"
)
assert
(
carResults3
.
forall
(
_
.
_2
.
size
===
1
),
"We should have 1 model per sum"
)
// 2 model of each sum
val
enum4
=
me
.
enumVarying
(
Seq
(
l
),
cnstr
,
car2
,
2
)
val
models4
=
enum4
.
take
(
4
).
toList
enum4
.
free
()
assert
(
models4
.
size
===
4
,
"We can enumerate >=4 lists of varying sum, with 0 < .. < 3"
)
val
carResults4
=
models4
.
groupBy
(
m
=>
evaluator
.
eval
(
car2
,
m
).
result
.
get
)
assert
(
carResults4
.
size
>=
2
,
"We should have at least 2 distinct sums"
)
assert
(
carResults4
.
forall
(
_
.
_2
.
size
<=
2
),
"We should have at most 2 models per sum"
)
}
finally
{
me
.
shutdown
()
}
}
test
(
"Varying model enumeration 2"
)
{
implicit
fix
=>
...
...
@@ -138,19 +145,19 @@ class ModelEnumeratorSuite extends LeonTestSuiteWithProgram with ExpressionsDSL
val
me
=
getModelEnum
try
{
// 1 model of each caracteristic (which is a boolean, so only two possibilities
)
val
models3
=
me
.
enum
Varying
(
Seq
(
l
),
cnstr
,
car
)
.
take
(
10
).
toList
assert
(
models3
.
size
===
2
,
"We can enumerate only 2 lists of varying size==0"
)
// 1 model of each caracteristic (which is a boolean, so only two possibilities)
val
enum3
=
me
.
enumVarying
(
Seq
(
l
),
cnstr
,
car
)
val
models3
=
enum
3
.
take
(
10
).
toList
enum3
.
free
(
)
assert
(
models3
.
size
===
2
,
"We can enumerate only 2 lists of varying size==0"
)
// 1 model of each caracteristic (which is a boolean, so only two possibilities)
val
models4
=
me
.
enumVarying
(
Seq
(
l
),
cnstr
,
car
,
2
).
take
(
10
).
toList
assert
(
models4
.
size
===
4
,
"We can enumerate only 4 lists of varying size==0 (2 each)"
)
}
finally
{
me
.
shutdown
()
}
// 1 model of each caracteristic (which is a boolean, so only two possibilities)
val
enum4
=
me
.
enumVarying
(
Seq
(
l
),
cnstr
,
car
,
2
)
val
models4
=
enum4
.
take
(
10
).
toList
enum4
.
free
()
assert
(
models4
.
size
===
4
,
"We can enumerate only 4 lists of varying size==0 (2 each)"
)
}
test
(
"Maximizing size"
)
{
implicit
fix
=>
...
...
@@ -164,20 +171,20 @@ class ModelEnumeratorSuite extends LeonTestSuiteWithProgram with ExpressionsDSL
val
evaluator
=
new
DefaultEvaluator
(
fix
.
_1
,
fix
.
_2
)
val
me
=
getModelEnum
try
{
val
models1
=
me
.
enumMaximizing
(
Seq
(
l
),
cnstr
,
car
).
take
(
5
).
toList
val
enum1
=
me
.
enumMaximizing
(
Seq
(
l
),
cnstr
,
car
)
val
models1
=
enum1
.
take
(
5
).
toList
enum1
.
free
()
assert
(
models1
.
size
<
5
,
"It took less than 5 models to reach max"
)
assert
(
evaluator
.
eval
(
car
,
models1
.
last
).
result
===
Some
(
bi
(
4
)),
"Max should be 4"
)
assert
(
models1
.
size
<
5
,
"It took less than 5 models to reach max"
)
assert
(
evaluator
.
eval
(
car
,
models1
.
last
).
result
===
Some
(
bi
(
4
)),
"Max should be 4"
)
val
models2
=
me
.
enumMaximizing
(
Seq
(
l
),
BooleanLiteral
(
true
),
car
).
take
(
4
).
toList
val
enum2
=
me
.
enumMaximizing
(
Seq
(
l
),
BooleanLiteral
(
true
),
car
)
val
models2
=
enum2
.
take
(
4
).
toList
enum2
.
free
()
assert
(
models2
.
size
==
4
,
"Unbounded search yields models"
)
// in 4 steps, it should reach lists of size > 10
assert
(
evaluator
.
eval
(
GreaterThan
(
car
,
bi
(
10
)),
models2
.
last
).
result
===
Some
(
T
),
"Progression should be efficient"
)
}
finally
{
me
.
shutdown
()
}
assert
(
models2
.
size
==
4
,
"Unbounded search yields models"
)
// in 4 steps, it should reach lists of size > 10
assert
(
evaluator
.
eval
(
GreaterThan
(
car
,
bi
(
10
)),
models2
.
last
).
result
===
Some
(
T
),
"Progression should be efficient"
)
}
test
(
"Minimizing size"
)
{
implicit
fix
=>
...
...
@@ -191,15 +198,12 @@ class ModelEnumeratorSuite extends LeonTestSuiteWithProgram with ExpressionsDSL
val
evaluator
=
new
DefaultEvaluator
(
fix
.
_1
,
fix
.
_2
)
val
me
=
getModelEnum
try
{
val
models1
=
me
.
enumMinimizing
(
Seq
(
l
),
cnstr
,
car
).
take
(
5
).
toList
assert
(
models1
.
size
<
5
,
"It took less than 5 models to reach min"
)
assert
(
evaluator
.
eval
(
car
,
models1
.
last
).
result
===
Some
(
bi
(
0
)),
"Min should be 0"
)
val
enum1
=
me
.
enumMinimizing
(
Seq
(
l
),
cnstr
,
car
)
val
models1
=
enum1
.
take
(
5
).
toList
enum1
.
free
()
}
finally
{
me
.
shutdown
()
}
assert
(
models1
.
size
<
5
,
"It took less than 5 models to reach min"
)
assert
(
evaluator
.
eval
(
car
,
models1
.
last
).
result
===
Some
(
bi
(
0
)),
"Min should be 0"
)
}
}
This diff is collapsed.
Click to expand it.
src/main/scala/leon/utils/ModelEnumerator.scala
+
2
−
11
View file @
4a9c1410
...
...
@@ -11,10 +11,9 @@ import evaluators._
import
solvers._
class
ModelEnumerator
(
ctx
:
LeonContext
,
pgm
:
Program
,
sf
:
SolverFactory
[
Solver
])
{
private
[
this
]
var
reclaimPool
=
List
[
Solver
]()
private
[
this
]
val
evaluator
=
new
DefaultEvaluator
(
ctx
,
pgm
)
def
enumSimple
(
ids
:
Seq
[
Identifier
],
satisfying
:
Expr
)
:
Iterator
[
Map
[
Identifier
,
Expr
]]
=
{
def
enumSimple
(
ids
:
Seq
[
Identifier
],
satisfying
:
Expr
)
:
Freeable
Iterator
[
Map
[
Identifier
,
Expr
]]
=
{
enumVarying0
(
ids
,
satisfying
,
None
,
-
1
)
}
...
...
@@ -95,11 +94,10 @@ class ModelEnumerator(ctx: LeonContext, pgm: Program, sf: SolverFactory[Solver])
case
object
Up
extends
SearchDirection
case
object
Down
extends
SearchDirection
private
[
this
]
def
enumOptimizing
(
ids
:
Seq
[
Identifier
],
satisfying
:
Expr
,
measure
:
Expr
,
dir
:
SearchDirection
)
:
Iterator
[
Map
[
Identifier
,
Expr
]]
=
{
private
[
this
]
def
enumOptimizing
(
ids
:
Seq
[
Identifier
],
satisfying
:
Expr
,
measure
:
Expr
,
dir
:
SearchDirection
)
:
Freeable
Iterator
[
Map
[
Identifier
,
Expr
]]
=
{
assert
(
measure
.
getType
==
IntegerType
)
val
s
=
sf
.
getNewSolver
reclaimPool
::=
s
s
.
assertCnstr
(
satisfying
)
...
...
@@ -197,11 +195,4 @@ class ModelEnumerator(ctx: LeonContext, pgm: Program, sf: SolverFactory[Solver])
}
}
}
def
shutdown
()
=
{
println
(
"Terminating!"
)
reclaimPool
.
foreach
(
sf
.
reclaim
)
}
}
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