Skip to content
Snippets Groups Projects
Commit 32678cbe authored by Ali Sinan Köksal's avatar Ali Sinan Köksal
Browse files

Util class with timer.

parent 113f9777
No related branches found
No related tags found
No related merge requests found
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
}
Timer.stop
timer.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
}
}
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
Timer.stop
timer.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
}
}
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
}
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment