This repository was archived by the owner on Feb 27, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.gradle.kts
More file actions
140 lines (131 loc) · 4.59 KB
/
Copy pathbuild.gradle.kts
File metadata and controls
140 lines (131 loc) · 4.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
import java.awt.GraphicsEnvironment
import java.io.ByteArrayOutputStream
import java.util.*
plugins {
application
alias(libs.plugins.gitSemVer)
alias(libs.plugins.collektive)
alias(libs.plugins.kotlin.jvm)
alias(libs.plugins.kotlin.qa)
alias(libs.plugins.multiJvmTesting)
alias(libs.plugins.taskTree)
}
repositories {
mavenCentral()
}
/*
* Only required if you plan to use Protelis, remove otherwise
*/
sourceSets {
main {
dependencies {
implementation(libs.bundles.alchemist)
implementation(libs.bundles.collektive)
implementation(kotlin("reflect"))
}
resources {
srcDir("src/main/protelis")
}
}
}
multiJvm {
jvmVersionForCompilation.set(17)
}
dependencies {
implementation(kotlin("stdlib-jdk8"))
if (!GraphicsEnvironment.isHeadless()) {
implementation("it.unibo.alchemist:alchemist-swingui:${libs.versions.alchemist.get()}")
}
}
// Heap size estimation for batches
val maxHeap: Long? by project
val heap: Long = maxHeap ?: if (System.getProperty("os.name").lowercase().contains("linux")) {
ByteArrayOutputStream().use { output ->
exec {
executable = "bash"
args = listOf("-c", "cat /proc/meminfo | grep MemAvailable | grep -o '[0-9]*'")
standardOutput = output
}
output.toString().trim().toLong() / 1024
}.also { println("Detected ${it}MB RAM available.") } * 9 / 10
} else {
// Guess 16GB RAM of which 2 used by the OS
14 * 1024L
}
val taskSizeFromProject: Int? by project
val taskSize = taskSizeFromProject ?: 512
val threadCount = maxOf(1, minOf(Runtime.getRuntime().availableProcessors(), heap.toInt() / taskSize))
val alchemistGroupBatch = "Run batch simulations"
val alchemistGroupGraphic = "Run graphic simulations with Alchemist"
/*
* This task is used to run all experiments in sequence
*/
val runAllGraphic by tasks.register<DefaultTask>("runAllGraphic") {
group = alchemistGroupGraphic
description = "Launches all simulations with the graphic subsystem enabled"
}
val runAllBatch by tasks.register<DefaultTask>("runAllBatch") {
group = alchemistGroupBatch
description = "Launches all experiments"
}
fun String.capitalizeString(): String =
this.replaceFirstChar {
if (it.isLowerCase()) {
it.titlecase(
Locale.getDefault(),
)
} else {
it.toString()
}
}
/*
* Scan the folder with the simulation files, and create a task for each one of them.
*/
File(rootProject.rootDir.path + "/src/main/yaml").listFiles()
?.filter { it.extension == "yml" }
?.sortedBy { it.nameWithoutExtension }
?.forEach {
fun basetask(name: String, additionalConfiguration: JavaExec.() -> Unit = {}) = tasks.register<JavaExec>(name) {
description = "Launches graphic simulation ${it.nameWithoutExtension}"
mainClass.set("it.unibo.alchemist.Alchemist")
classpath = sourceSets["main"].runtimeClasspath
args("run", it.absolutePath)
javaLauncher.set(
javaToolchains.launcherFor {
languageVersion.set(JavaLanguageVersion.of(multiJvm.latestJava))
},
)
if (System.getenv("CI") == "true") {
args("--override", "terminate: { type: AfterTime, parameters: [2] } ")
} else {
this.additionalConfiguration()
}
}
val capitalizedName = it.nameWithoutExtension.capitalizeString()
val graphic by basetask("run${capitalizedName}Graphic") {
group = alchemistGroupGraphic
args(
"--override",
"monitors: { type: SwingGUI, parameters: { graphics: effects/${it.nameWithoutExtension}.json } }",
"--override",
"launcher: { parameters: { batch: [], autoStart: false } }",
"--verbosity",
"error"
)
}
runAllGraphic.dependsOn(graphic)
val batch by basetask("run${capitalizedName}Batch") {
group = alchemistGroupBatch
description = "Launches batch experiments for $capitalizedName"
maxHeapSize = "${minOf(heap.toInt(), Runtime.getRuntime().availableProcessors() * taskSize)}m"
File("data").mkdirs()
}
runAllBatch.dependsOn(batch)
}
tasks.withType(KotlinCompile::class).all {
compilerOptions{
freeCompilerArgs = listOf("-Xcontext-receivers")
allWarningsAsErrors = false
}
}