Skip to content

Commit

Permalink
v0.9 release
Browse files Browse the repository at this point in the history
  • Loading branch information
holgerbrandl committed Apr 14, 2023
1 parent b5014cc commit f985803
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 161 deletions.
4 changes: 2 additions & 2 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ plugins {
}

group = "com.github.holgerbrandl"
version = "0.8.101"
//version = "0.9-SNAPSHOT"
//version = "0.8.101"
version = "0.9"


repositories {
Expand Down
9 changes: 6 additions & 3 deletions docs/userguide/docs/changes.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
# Kalasim Release History

## v0.9 (Not yet released)
## v0.9

Developer snapshots are deposited on maven-central starting with v0.8.90+
Released at 2023-04-13

Major
* Changed API to always favor `kotlin.time.Duration` to express durations. Previously untyped `Numbers` were used that often led to confusion in larger simulations models. Evey simulation environment has now a `DurationUnit` such as seconds, hours, etc. (defaulting to minutes if not specified). To indicate this breaking change to the user in her IDE, new [opt-in](https://kotlinlang.org/docs/opt-in-requirements.html) annotations were introduced

* Changed API to always favor `kotlin.time.Duration` to express durations. Previously untyped `Numbers` were used that often led to confusion in larger simulations models. Evey simulation environment has now a `DurationUnit` such as seconds, hours, etc. (defaulting to minutes if not specified).
* New [opt-in](https://kotlinlang.org/docs/opt-in-requirements.html) annotations were introduced to prevent use of untyped duration arguments in interaction functions such as ``
* Migrated use of `Instant` to `kotlinx.datetime.Instant` for better API consistency
* New sampling functions to sample durations directly: `val uni = uniform(5.minutes, 2.hours); uni() // results in Duration`

Minor

Expand Down
2 changes: 1 addition & 1 deletion docs/userguide/docs/setup.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
To get started simply add it as a dependency:
```
dependencies {
implementation "com.github.holgerbrandl:kalasim:0.8.101"
implementation "com.github.holgerbrandl:kalasim:0.9"
}
```

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ class Deposit(val gridPosition: GridPosition, size: Int) : DepletableResource(ca
val miningShaft = Resource("MineShaft[${this}]", 1)
}


/** A discrete position on the surface */
data class GridPosition(val x: Int, val y: Int) {
val mapCoordinates: Point2D
Expand All @@ -30,7 +29,6 @@ data class GridPosition(val x: Int, val y: Int) {
sqrt(pow((x - other.x).toDouble(), 2.0) - pow((y - other.y).toDouble(), 2.0))
}


class DepositMap(
numDeposits: Int = 10,
maxCapacity: Int = 1000,
Expand Down Expand Up @@ -145,8 +143,6 @@ class Harvester(initialPosition: GridPosition, private val gridUnitsPerHour: Dou
}

fun harvesting(): Sequence<Component> = sequence {
// require(currentDeposit != null) { "deposit must be set when harvesting" }

if(currentDeposit == null) {
currentDeposit = get<Base>().requestAssignment(this@Harvester)
}
Expand All @@ -158,7 +154,7 @@ class Harvester(initialPosition: GridPosition, private val gridUnitsPerHour: Dou
moveTo(currentDeposit!!.gridPosition)


// MODEL 1: Mine increments: THis allows for better progress monitoring in the UI, but is overly
// MODEL 1: Mine increments: This allows for better progress monitoring in the UI, but is overly
// complex from a modelling and event perspective
// Could we avoid the loop by using process interaction here? --> yes use mine-shafts see below
val miningUnitsPerHour = 15.0
Expand All @@ -177,15 +173,6 @@ class Harvester(initialPosition: GridPosition, private val gridUnitsPerHour: Dou
}
}

//MODEL 1 more concise but lacks the ability to track mining status at the deposits
// val quantity = min(tank.capacity - tank.level, currentDeposit!!.level)
// request(currentDeposit!!.miningShaft) {
// currentState = MINING
// hold((miningUnitsPerHour * quantity).hours, "Mining deposit $currentDeposit")
// take(currentDeposit!!, quantity, failDelay = 0)
// put(tank, quantity, capacityLimitMode = CapacityLimitMode.CAP)
// }

if(tank.isFull) {
activate(process = Harvester::unload)
} else {
Expand Down Expand Up @@ -220,8 +207,10 @@ class Base : Component(process=Base::consumeWater) {

// water consumption of the base
fun consumeWater() = sequence {
hold(1.hours)
take(refinery, quantity = min(refinery.level, waterConsumption()))
while(true) {
hold(1.hours)
take(refinery, quantity = min(refinery.level, waterConsumption()))
}
}

/** Performs analysis to find a suitable deposit for harvesting for the given harvester. */
Expand All @@ -243,15 +232,6 @@ class Base : Component(process=Base::consumeWater) {

fun reportScanCompleted(searchPosition: GridPosition) {
scanHistory[searchPosition] = now

// val mapSize = get<DepositMap>().gridDimension
// println(
// "map coverage increased to ${
// (scanHistory.size.toDouble() / (mapSize.height * mapSize.width)).roundAny(
// 2
// )
// }"
// )
}
}

Expand All @@ -261,10 +241,6 @@ class LunarMining(
logEvents: Boolean = true,
seed: Int = Defaults.DEFAULT_SEED
) : Environment(enableConsoleLogger = logEvents, randomSeed = seed) {
// init {
// tickTransform = TickTransform(DurationUnit.MINUTES)
// }

// the initially unknown list of deposits
val map = dependency { DepositMap(numDeposits = numDeposits) }
val base = dependency { Base() }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ fun main() {
composition(base)

defaults()
translate((baseCoordinates.x + 3) * scaledXUnit, (baseCoordinates.y + 18) * scaledYUnit)
translate((baseCoordinates.x + 3) * scaledXUnit, (baseCoordinates.y + 22) * scaledYUnit)
drawer.fill = ColorRGBa.BLACK
drawer.fontMap = font
if(!lumi.harvesters.any { it.isHolding(UNLOADING_HARVESTER) }) {
Expand Down
140 changes: 38 additions & 102 deletions simulations/notebooks/kotlin-conf-23.ipynb

Large diffs are not rendered by default.

26 changes: 3 additions & 23 deletions src/main/kotlin/org/kalasim/examples/elevator/Elevator.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
//Elevator.kt
@file:OptIn(AmbiguousDuration::class)

package org.kalasim.examples.elevator

import org.kalasim.*
Expand All @@ -12,6 +10,7 @@ import org.kalasim.misc.AmbiguousDuration
import org.kalasim.misc.repeat
import org.kalasim.plot.kravis.display
import java.awt.Point
import kotlin.time.Duration.Companion.days
import kotlin.time.DurationUnit

// For example documentation see https://www.kalasim.org/examples/office_tower/
Expand Down Expand Up @@ -246,26 +245,7 @@ typealias Requests = MutableMap<Pair<Floor, Direction>, TickTime>
fun main() {
val elevator = Elevator()

elevator.run(100000)

// try with single visitor to get started
// Visitor(3, 12)
// run(2000)

//print summary
println("Floor n Length Length_of_stay")
elevator.floors.forEach {
it.let {
println(
"%5d%5d%15.3f%15.3f".format(
it.level,
it.queue.lengthOfStayStatistics.statistics().n,
it.queue.queueLengthTimeline.statistics().mean,
it.queue.lengthOfStayStatistics.statistics().mean
)
)
}
}
elevator.run(2.days)

// elevator.floors[0].queue.queueLengthTimeline.display("queue length on ground floor")
println(elevator.cars[0].visitors.statistics.lengthOfStayStats)
}

0 comments on commit f985803

Please sign in to comment.