In [22]:
val userHome = System.getProperty("user.home")

println(userHome)

if(userHome.contains("brandl")){
    println("clearing ivy cache")
    java.io.File("$userHome/.ivy2/cache/org.kalasim/").deleteRecursively()
}
C:\Users\brandl
clearing ivy cache
In [1]:
@file:Repository("*mavenLocal")
@file:DependsOn("com.github.holgerbrandl:kalasim:0.7.99")
In [2]:
import org.kalasim.*
In [3]:
//:classpath
In [4]:
%use lets-plot
In [27]:
import org.jetbrains.letsPlot.ggsize
import org.jetbrains.letsPlot.intern.Plot
import org.jetbrains.letsPlot.lets_plot
import krangl.irisData
import krangl.toMap
import org.kalasim.examples.MM1Queue
import org.kalasim.plot.letsplot.display
import org.kalasim.plot.letsplot.displayStateTimeline
import org.kalasim.analysis.InteractionEvent
import java.time.Instant
import java.util.concurrent.TimeUnit
In [28]:
val mm1 = MM1Queue().apply {
    run(100)
}
rho is 0.75. With rho>1 the system would be unstable, because there are more arrivals then the server can serve.
In [8]:
mm1.traces.filterIsInstance<InteractionEvent>().asDataFrame()
Out[8]:
actioncurComponentdetailssourcelogLeveltime
Createdmaincapacity=1 serverINFO.00
createmainComponentGenerator.1INFO.00
activatemainscheduled for .00ComponentGenerator.1INFO.00
run +100.00mainscheduled for 100.00mainINFO.00
hold +.68ComponentGenerator.1scheduled for .68ComponentGenerator.1INFO.00
createComponentGenerator.1Customer.1INFO.68
activateComponentGenerator.1scheduled for .68Customer.1INFO.68
hold +.55ComponentGenerator.1scheduled for 1.23ComponentGenerator.1INFO.68
Requesting 1.0 from server with priority null a...Customer.1nullCustomer.1INFO.68
nullCustomer.1nullCustomer.1INFO.68

... with 732 more rows. Shape: 742 x 6.

In [9]:
mm1.server.claimedTimeline.display()
Out[9]:
In [10]:
mm1.server.requesters.lengthOfStayMonitor.display()
Out[10]:

MM1 with tick-transformation

In [11]:
val mm1 = MM1Queue()

// redo but with set tick-transform
mm1.tickTransform = OffsetTransform(
    offset = Instant.parse("2021-01-01T00:00:00.00Z"),
    tickUnit = TimeUnit.MINUTES
)

mm1.run(50)
rho is 0.75. With rho>1 the system would be unstable, because there are more arrivals then the server can serve.
Out[11]:
{
  "now": "50.00",
  "num_components": 42,
  "queue": [
    "Customer.30",
    "Customer.31",
    "ComponentGenerator.1",
    "Customer.36",
    "Customer.32",
    "Customer.34",
    "Customer.38",
    "Customer.37",
    "Customer.40",
    "Customer.33",
    "Customer.35",
    "Customer.39"
  ]
}
In [30]:
mm1.server.activities.display("MM1 Server Utilization")
Out[30]:
In [31]:
mm1.componentGenerator.arrivals.displayStateTimeline("MM1 Server Utilization")
Out[31]:
In [32]:
mm1.server.claimedTimeline.display("Claimed Server Capacity")
Out[32]:
In [33]:
val customerTimeline =
    mm1.componentGenerator.arrivals.first().statusTimeline
In [34]:
customerTimeline.display("Arrival State Timeline", forceTickAxis = true)
Out[34]:
In [36]:
customerTimeline.display("Arrival State Timeline")
Out[36]:

Car

In [32]:
import org.kalasim.*
import org.kalasim.misc.*
import org.kalasim.plot.letsplot.display
import org.kalasim.plot.letsplot.displayStateProportions
In [40]:
class Driver : Resource()

class TrafficLight : State<String>("red")

class Car : Component() {

    val trafficLight = get<TrafficLight>()
    val driver = get<Driver>()

    override fun process() = sequence {
                request(driver) {
                    hold(10)
                }

        request(driver) {
            hold(1.0, description = "driving")

            wait(trafficLight, "green")
        }
    }
}
In [56]:
val sim  = createSimulation(enableConsoleLogger = false) {
    dependency { TrafficLight() }
    dependency { Driver() }
    dependency {
        Car()
    }
    println("simulation setup complete")
}
simulation setup complete
In [57]:
sim.run(20)
In [58]:
sim.get<Driver>().claimedTimeline.display()
Out[58]:
In [59]:
sim.get<Driver>().activities.display()
Out[59]:
In [60]:
sim.get<TrafficLight>()
Out[60]:
TrafficLight.1[red]
In [55]:
sim.get<Car>()
Out[55]:
Car.1
In [62]:
sim.get<Car>().statusTimeline.display()
Out[62]:
In [ ]: