{ "cells": [ { "cell_type": "code", "execution_count": 22, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "C:\\Users\\brandl\r\n", "clearing ivy cache\r\n" ] } ], "source": [ "val userHome = System.getProperty(\"user.home\")\n", "\n", "println(userHome)\n", "\n", "if(userHome.contains(\"brandl\")){\n", " println(\"clearing ivy cache\")\n", " java.io.File(\"$userHome/.ivy2/cache/org.kalasim/\").deleteRecursively()\n", "}\n" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "@file:Repository(\"*mavenLocal\")\n", "@file:DependsOn(\"com.github.holgerbrandl:kalasim:0.7.99\")" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "import org.kalasim.*" ] }, { "cell_type": "code", "execution_count": 3, "metadata": { "pycharm": { "name": "#%%\n" } }, "outputs": [], "source": [ "//:classpath" ] }, { "cell_type": "code", "execution_count": 4, "metadata": { "pycharm": { "name": "#%%\n" } }, "outputs": [ { "data": { "text/html": [ "
\n", " " ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "%use lets-plot" ] }, { "cell_type": "code", "execution_count": 27, "metadata": { "pycharm": { "name": "#%%\n" } }, "outputs": [], "source": [ "import org.jetbrains.letsPlot.ggsize\n", "import org.jetbrains.letsPlot.intern.Plot\n", "import org.jetbrains.letsPlot.lets_plot\n", "import krangl.irisData\n", "import krangl.toMap\n", "import org.kalasim.examples.MM1Queue\n", "import org.kalasim.plot.letsplot.display\n", "import org.kalasim.plot.letsplot.displayStateTimeline\n", "import org.kalasim.analysis.InteractionEvent\n", "import kotlinx.datetime.Instant\n", "import kotlin.time.DurationUnit\n" ] }, { "cell_type": "code", "execution_count": 28, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "rho is 0.75. With rho>1 the system would be unstable, because there are more arrivals then the server can serve.\r\n" ] } ], "source": [ "val mm1 = MM1Queue().apply {\n", " run(100)\n", "}" ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
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. \n", "

" ] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ " mm1.traces.filterIsInstance().asDataFrame()" ] }, { "cell_type": "code", "execution_count": 9, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", " " ] }, "execution_count": 9, "metadata": {}, "output_type": "execute_result" } ], "source": [ "mm1.server.claimedTimeline.display()" ] }, { "cell_type": "code", "execution_count": 10, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", " " ] }, "execution_count": 10, "metadata": {}, "output_type": "execute_result" } ], "source": [ "mm1.server.requesters.lengthOfStayMonitor.display()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## MM1 with tick-transformation" ] }, { "cell_type": "code", "execution_count": 11, "metadata": { "pycharm": { "name": "#%%\n" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "rho is 0.75. With rho>1 the system would be unstable, because there are more arrivals then the server can serve.\r\n" ] }, { "data": { "text/plain": [ "{\n", " \"now\": \"50.00\",\n", " \"num_components\": 42,\n", " \"queue\": [\n", " \"Customer.30\",\n", " \"Customer.31\",\n", " \"ComponentGenerator.1\",\n", " \"Customer.36\",\n", " \"Customer.32\",\n", " \"Customer.34\",\n", " \"Customer.38\",\n", " \"Customer.37\",\n", " \"Customer.40\",\n", " \"Customer.33\",\n", " \"Customer.35\",\n", " \"Customer.39\"\n", " ]\n", "}" ] }, "execution_count": 11, "metadata": {}, "output_type": "execute_result" } ], "source": [ "val mm1 = MM1Queue()\n", "\n", "// redo but with set tick-transform\n", "mm1.tickTransform = OffsetTransform(\n", " offset = Instant.parse(\"2021-01-01T00:00:00.00Z\"),\n", " tickUnit = DurationUnit.MINUTES\n", ")\n", "\n", "mm1.run(50)" ] }, { "cell_type": "code", "execution_count": 30, "metadata": { "pycharm": { "name": "#%%\n" } }, "outputs": [ { "data": { "text/html": [ "
\n", " " ] }, "execution_count": 30, "metadata": {}, "output_type": "execute_result" } ], "source": [ "mm1.server.activities.display(\"MM1 Server Utilization\")" ] }, { "cell_type": "code", "execution_count": 31, "metadata": { "pycharm": { "name": "#%%\n" } }, "outputs": [ { "data": { "text/html": [ "
\n", " " ] }, "execution_count": 31, "metadata": {}, "output_type": "execute_result" } ], "source": [ "mm1.componentGenerator.arrivals.displayStateTimeline(\"MM1 Server Utilization\")" ] }, { "cell_type": "code", "execution_count": 32, "metadata": { "pycharm": { "name": "#%%\n" } }, "outputs": [ { "data": { "text/html": [ "
\n", " " ] }, "execution_count": 32, "metadata": {}, "output_type": "execute_result" } ], "source": [ "mm1.server.claimedTimeline.display(\"Claimed Server Capacity\")" ] }, { "cell_type": "code", "execution_count": 33, "metadata": { "pycharm": { "name": "#%%\n" } }, "outputs": [], "source": [ "val customerTimeline =\n", " mm1.componentGenerator.arrivals.first().statusTimeline" ] }, { "cell_type": "code", "execution_count": 34, "metadata": { "pycharm": { "name": "#%%\n" } }, "outputs": [ { "data": { "text/html": [ "
\n", " " ] }, "execution_count": 34, "metadata": {}, "output_type": "execute_result" } ], "source": [ "\n", "customerTimeline.display(\"Arrival State Timeline\", forceTickAxis = true)\n" ] }, { "cell_type": "code", "execution_count": 36, "metadata": { "pycharm": { "name": "#%%\n" } }, "outputs": [ { "data": { "text/html": [ "
\n", " " ] }, "execution_count": 36, "metadata": {}, "output_type": "execute_result" } ], "source": [ "customerTimeline.display(\"Arrival State Timeline\")" ] }, { "cell_type": "markdown", "metadata": { "pycharm": { "name": "#%%\n" } }, "source": [ "## Car" ] }, { "cell_type": "code", "execution_count": 32, "metadata": {}, "outputs": [], "source": [ "import org.kalasim.*\n", "import org.kalasim.misc.*\n", "import org.kalasim.plot.letsplot.display\n", "import org.kalasim.plot.letsplot.displayStateProportions" ] }, { "cell_type": "code", "execution_count": 40, "metadata": {}, "outputs": [], "source": [ "class Driver : Resource()\n", "\n", "class TrafficLight : State(\"red\")\n", "\n", "class Car : Component() {\n", "\n", " val trafficLight = get()\n", " val driver = get()\n", "\n", " override fun process() = sequence {\n", " request(driver) {\n", " hold(10)\n", " }\n", "\n", " request(driver) {\n", " hold(1.0, description = \"driving\")\n", "\n", " wait(trafficLight, \"green\")\n", " }\n", " }\n", "}" ] }, { "cell_type": "code", "execution_count": 56, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "simulation setup complete\r\n" ] } ], "source": [ "val sim = createSimulation(enableComponentLogger = false) {\n", " dependency { TrafficLight() }\n", " dependency { Driver() }\n", " dependency {\n", " Car()\n", " }\n", " println(\"simulation setup complete\")\n", "}" ] }, { "cell_type": "code", "execution_count": 57, "metadata": {}, "outputs": [], "source": [ "sim.run(20)" ] }, { "cell_type": "code", "execution_count": 58, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", " " ] }, "execution_count": 58, "metadata": {}, "output_type": "execute_result" } ], "source": [ "sim.get().claimedTimeline.display()" ] }, { "cell_type": "code", "execution_count": 59, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", " " ] }, "execution_count": 59, "metadata": {}, "output_type": "execute_result" } ], "source": [ "sim.get().activities.display()" ] }, { "cell_type": "code", "execution_count": 60, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "TrafficLight.1[red]" ] }, "execution_count": 60, "metadata": {}, "output_type": "execute_result" } ], "source": [ "sim.get()" ] }, { "cell_type": "code", "execution_count": 55, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "Car.1" ] }, "execution_count": 55, "metadata": {}, "output_type": "execute_result" } ], "source": [ "sim.get()" ] }, { "cell_type": "code", "execution_count": 62, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", " " ] }, "execution_count": 62, "metadata": {}, "output_type": "execute_result" } ], "source": [ "sim.get().statusTimeline.display()" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Kotlin", "language": "kotlin", "name": "kotlin" }, "language_info": { "codemirror_mode": "text/x-kotlin", "file_extension": ".kt", "mimetype": "text/x-kotlin", "name": "kotlin", "nbconvert_exporter": "", "pygments_lexer": "kotlin", "version": "1.6.20-dev-6372" }, "pycharm": { "revision": "98fc42e1-0e72-461b-b6b6-cc2c0988eeac" } }, "nbformat": 4, "nbformat_minor": 4 }