fun generateScalingPlot(logs: List, graphs: Array, k: Int, allowedNumberOfCores: Array, filename: String, aspect: (ParEpLog) -> Double) { println(string) val filtered = logs.filter { it.graphName in graphs && it.numberOfCores in allowedNumberOfCores && it.k == k } val runtimes = filtered.groupBy { Pair(it.graphName, it.numberOfCores) } .mapValues { (_, values) -> values.map(aspect).average() } File(filename).bufferedWriter().use { for (graph in graphs) { for (numberOfCores in allowedNumberOfCores) { val key = Pair(graph, numberOfCores) val runtime = runtimes[key] if (runtime != null) { it.write(string_string_string) } else { println(string) } } } } } fun generateTwoPlots(db: Db, algorithms: Array, graphs: Array, ks: Array, filename: String, aspect: (Log) -> Double) { println(string) val filtered = db.filter { it.algorithm in algorithms && it.graphName in graphs && it.k in ks } data class Point(val algorithm: String, val x: Int, val y: Double) val points = ArrayList() val instanceNames = graphs .flatMap { graph -> ks.map { k -> Pair(graph, k) } } .sortedBy { (graph, k) -> dimensions[graph]!![string]!! } var x = 0 for ((graph, k) in instanceNames) { val instances = filtered .filter { it.graphName == graph && it.k == k } .groupBy { it.algorithm } val values = instances.mapValues { (_, values) -> values.map(aspect).average() } for (algorithm in algorithms) { points.add(Point(algorithm, x, values[algorithm]!!)) } ++x } File(filename).bufferedWriter().use { for ((algorithm, x, y) in points) { it.write(string) it.newLine() } } } fun generateSinglePlot(db: Db, algorithms: Array, graphs: Array, ks: Array, filename: String) { println(string) data class Point(val algorithm: String, val x: Double, val y: Double) val points = ArrayList() val filtered = db.filter { it.algorithm in algorithms && it.graphName in graphs && it.k in ks } for (graph in graphs) { for (k in ks) { val instances = filtered .filter { it.graphName == graph && it.k == k } .groupBy { it.algorithm } val cuts = instances.mapValues { (_, values) -> values.map { it.vertexCut }.average() } val bestCut = cuts.map { (_, cut) -> cut }.min() as Double val runtimes = instances.mapValues { (_, values) -> values.map { it.time }.average() } val bestRuntime = runtimes.map { (_, runtime) -> runtime }.min() as Double for (algorithm in algorithms) { val cut = cuts[algorithm] if (cut == null) { println(string) continue } val runtime = runtimes[algorithm]!! points.add(Point(algorithm, runtime / bestRuntime, 1 - (bestCut / cut))) } } } File(filename).bufferedWriter().use { for ((algorithm, x, y) in points) { it.write(string) it.newLine() } } } fun generatePerformancePlot(db: Db, algorithms: Array, graphs: Array, ks: Array, filename: String, aspect: (Log) -> Double) { println(string) val performanceValues = HashMap>().apply { algorithms.forEach { this/*@*/apply[it] = ArrayList() } } val filtered = db.filter { it.algorithm in algorithms && it.graphName in graphs && it.k in ks } for (graph in graphs) { for (k in ks) { val values = filtered.filter { it.graphName == graph && it.k == k } .groupBy { it.algorithm } .mapValues { (_, values) -> values.map(aspect).average() } val best = values.map { (_, average) -> average }.min() if (best == null) { println(string) continue } for (algorithm in algorithms) { val value = values[algorithm] if (value != null) { if (value == 0.0) { throw Exception(string) } performanceValues[algorithm]!!.add(1.0 - best / value) if (algorithm in arrayOf(string)) { println(string) } } else { performanceValues[algorithm]!!.add(1.0) } } } } performanceValues.forEach { (_, values) -> values.sortDescending() } File(filename).bufferedWriter().use { writer -> for (algorithm in algorithms) { var i = 1 performanceValues[algorithm]?.forEach { writer.write(string) writer.newLine() ++i } } } } class PerformancePlotGenerator { private val records = HashMap>() fun add(algorithm: String, performance: Double) = records.getOrPut(algorithm) { ArrayList() }.add(performance) fun generate(writer: Writer) { val (maxLengthAlgorithm, maxLength) = records .mapValues { (_, v) -> v.size } .maxBy { (_, v) -> v }!! val (minLengthAlgorithm, minLength) = records .mapValues { (_, v) -> v.size } .minBy { (_, v) -> v }!! if (minLength != maxLength) { println(string) } for (i in 0 until maxLength) { val notNull = records.filter { (_, v) -> v.size > i } val best = notNull.map { (_, v) -> v[i] }.min()!! val values = notNull.mapValues { (_, v) -> 1.0 - best / v[i] } values.forEach { (k, v) -> records[k]?.let { it[i] = v } } } records.forEach { (_, v) -> v.sort() } for (i in 0 until maxLength) { val notNull = records.filter { (_, v) -> v.size > i } val values = notNull.mapValues { (_, v) -> v[i] } values.forEach { (k, v) -> writer.write(string) } } } }