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
32678cbe
Commit
32678cbe
authored
14 years ago
by
Ali Sinan Köksal
Browse files
Options
Downloads
Patches
Plain Diff
Util class with timer.
parent
113f9777
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
cp-demo/RedBlackTree.scala
+7
-25
7 additions, 25 deletions
cp-demo/RedBlackTree.scala
cp-demo/SortedList.scala
+4
-16
4 additions, 16 deletions
cp-demo/SortedList.scala
src/cp/Utils.scala
+17
-0
17 additions, 0 deletions
src/cp/Utils.scala
with
28 additions
and
41 deletions
cp-demo/RedBlackTree.scala
+
7
−
25
View file @
32678cbe
import
cp.Definitions._
import
cp.Utils._
object
RedBlackTree
{
@spec
sealed
abstract
class
Color
...
...
@@ -85,20 +86,23 @@ object RedBlackTree {
// enumerateAllUpTo(bound)
/*
try {
val t = choose((t: Tree) => size(t) > 7 && height(t) <= 3)
} catch {
case e: UnsatisfiableConstraintException => println("constraint is unsatisfiable")
}
*/
val
solutionSet
=
scala
.
collection
.
mutable
.
Set
[
Tree
]()
println
(
"Fixing size of trees to "
+
(
bound
))
Timer
.
go
val
timer
=
new
Timer
(
"Fixed-size enumeration"
,
true
)
timer
.
start
for
(
tree
<-
findAll
((
t
:
Tree
)
=>
isRedBlackTree
(
t
)
&&
boundValues
(
t
,
bound
-
1
)
&&
size
(
t
)
==
bound
))
{
solutionSet
+=
tree
}
T
imer
.
stop
t
imer
.
stop
// for (tree <- solutionSet)
// println(print(tree) + "\n-----------\n")
println
(
"Fixed-size solution set size : "
+
solutionSet
.
size
)
...
...
@@ -113,32 +117,24 @@ object RedBlackTree {
val
set4
=
scala
.
collection
.
mutable
.
Set
[
Tree
]()
println
(
"Minimizing size:"
)
Timer
.
go
for
(
tree
<-
findAll
((
t
:
Tree
)
=>
isRedBlackTree
(
t
)
&&
boundValues
(
t
,
bound
)
minimizing
size
(
t
)))
{
set1
+=
tree
}
Timer
.
stop
println
(
"Minimizing height:"
)
Timer
.
go
for
(
tree
<-
findAll
((
t
:
Tree
)
=>
isRedBlackTree
(
t
)
&&
boundValues
(
t
,
bound
)
minimizing
height
(
t
)))
{
set2
+=
tree
}
Timer
.
stop
println
(
"Minimizing bound:"
)
Timer
.
go
for
((
tree
,
bb
)
<-
findAll
((
t
:
Tree
,
b
:
Int
)
=>
isRedBlackTree
(
t
)
&&
boundValues
(
t
,
b
)
&&
b
>=
0
&&
b
<=
bound
minimizing
b
))
{
set3
+=
tree
}
Timer
.
stop
println
(
"No minimization:"
)
Timer
.
go
for
(
tree
<-
findAll
((
t
:
Tree
)
=>
isRedBlackTree
(
t
)
&&
boundValues
(
t
,
bound
)))
{
set4
+=
tree
}
Timer
.
stop
println
(
"Solution set size: "
+
set1
.
size
)
assert
(
set1
==
set2
)
...
...
@@ -155,17 +151,3 @@ object RedBlackTree {
case
Empty
()
=>
"E"
}
}
object
Timer
{
var
start
:
Long
=
0L
var
end
:
Long
=
0L
def
go
=
{
start
=
System
.
currentTimeMillis
}
def
stop
:
Double
=
{
end
=
System
.
currentTimeMillis
val
seconds
=
(
end
-
start
)
/
1000.0
println
(
" Measured time: "
+
seconds
+
" s"
)
seconds
}
}
This diff is collapsed.
Click to expand it.
cp-demo/SortedList.scala
+
4
−
16
View file @
32678cbe
import
cp.Definitions._
import
cp.Utils.Timer
object
Lists
{
@spec
sealed
abstract
class
List
...
...
@@ -29,25 +30,12 @@ object SortedList {
val
len
=
if
(
args
.
isEmpty
)
3
else
args
(
0
).
toInt
val
set
=
scala
.
collection
.
mutable
.
Set
[
List
]()
Timer
.
go
val
timer
=
new
Timer
(
"Sorted list enumeration"
,
true
)
timer
.
start
for
(
list
<-
findAll
((
l
:
List
)
=>
isSorted
(
l
)
&&
valuesWithin
(
l
,
0
,
len
)
&&
size
(
l
)
==
len
))
set
+=
list
T
imer
.
stop
t
imer
.
stop
println
(
"size : "
+
set
.
size
)
}
}
object
Timer
{
var
start
:
Long
=
0L
var
end
:
Long
=
0L
def
go
=
{
start
=
System
.
currentTimeMillis
}
def
stop
:
Double
=
{
end
=
System
.
currentTimeMillis
val
seconds
=
(
end
-
start
)
/
1000.0
println
(
" Measured time: "
+
seconds
+
" s"
)
seconds
}
}
This diff is collapsed.
Click to expand it.
src/cp/Utils.scala
0 → 100644
+
17
−
0
View file @
32678cbe
package
cp
object
Utils
{
class
Timer
(
description
:
String
,
verbose
:
Boolean
=
false
)
{
var
beginning
:
Long
=
0L
var
end
:
Long
=
0L
def
start
=
{
beginning
=
System
.
currentTimeMillis
}
def
stop
:
Double
=
{
end
=
System
.
currentTimeMillis
val
seconds
=
(
end
-
beginning
)
/
1000.0
if
(
verbose
)
println
(
"Timer \""
+
description
+
"\": "
+
seconds
+
" s"
)
seconds
}
}
}
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