Activity: Your Model in the Apps

KSL Applications Activities

Author

Manuel D. Rossetti, PhD P.E.

Work in pairs, but each partner builds the model on their own laptop. Each question asks you to predict before you act; write the prediction down, then check it.

The question. The Distribution app activity showed that the pharmacy’s service times are not exponential, and that the apps’ RV Overrides can change a distribution’s parameters but not its family. To simulate the pharmacy with gamma service times, you must change the model’s code, and then make your model available to the apps. You will do both, and then repeat the staffing study with your own model.

Setup. Get the starter file GammaPharmacy.kt from the code/ folder beside this activity. Put it in src/main/kotlin/student/activities in your KSL project, the package the file declares; create the folder if you do not have it. Open the project in IntelliJ.

1. Change the model

  1. Read GammaPharmacy.kt. It is the book’s drive-through pharmacy, with two parts at the end: a GammaPharmacyModelBuilder and a main function. Which lines make numPharmacists a control that the apps can change? Under what name will the apps show the service time’s random variable?

  2. TODO 1. Use the service time data’s sample mean, 0.853 minute, and standard deviation, 0.484 minute, from the Distribution app activity. Find the shape and scale of the gamma distribution with the same mean and variance. (For a gamma distribution with shape \(\alpha\) and scale \(\beta\), the mean is \(\alpha\beta\) and the variance is \(\alpha\beta^2\).) Round the shape to two decimals and the scale to three, then make the change the comment describes.

  3. TODO 2. In the Single-Model app activity, the time between arrivals appeared as EventGenerator_12:TimeBtwEventsRV. Make the change the comment describes, and predict the name the apps will show for that random variable now.

  4. Run main. Before you look, use the M/G/1 results (Appendix C, the section Non-Markovian Queues and Approximations) to predict the time in the system with one pharmacist and your gamma service time. Does the 95% confidence interval contain your prediction? If not, recall what happened in the Single-Model app activity and decide what to do.

2. Build the JAR

  1. In IntelliJ’s Gradle window, run Tasks > build > jar (or type ./gradlew jar in the terminal; on Windows, gradlew.bat jar). Find the file it writes in build/libs. Besides your pharmacy, what is in that JAR?

3. Bundle it with the Bundle Workbench

Start KSL Bundle Workbench and click Open JAR…. Choose the JAR you just built.

  1. The Overview tab lists the model builders the workbench found. How many are there, and why more than your one?

  2. On the Bundle identity tab, set the Bundle id to edu.uark.<your username>.pharmacy and the Display name to <Your name>'s Pharmacy, then click Apply bundle identity. Why must the bundle id be unique?

  3. On the Models tab, untick In bundle for every model except GammaPharmacy, and make sure SINGLE and SCENARIO are ticked for it. Then predict: which controls, which random-variable parameters, and which responses will your model show? Double-click the GammaPharmacy row to check. You wrote one control. Where did the others come from? Which random-variable parameters can the apps now change for the service time?

  4. On the Catalog tab, feature and label these: the number of pharmacists (Number of Pharmacists, unit pharmacists), the service time’s shape and scale, and the outputs System Time (Avg Time in System, unit min), Num in System, and Num Served. What will a user of the apps see differently because of this?

  5. Click Validate, and fix anything the health banner reports. Then click Assemble bundle JAR…, go to the bundles folder of your KSLWork folder, and save the bundle there as pharmacy-<your username>.jar. Why that folder? What would happen if you saved it in the workbench’s default folder instead?

4. Use it

  1. Start KSL Single. Is your bundle in the Pick a Model window? Pick your model, check its RV Overrides tab, and simulate with the defaults. Predict first: will the results match your run of main exactly?

  2. In KSL Scenario, build six scenarios with 30 replications each: your GammaPharmacy with 1, 2, and 3 pharmacists, and the book’s DriveThroughPharmacyWithQ with its mean service time overridden to 0.855 and 1, 2, and 3 pharmacists. Both models now have the same mean service time. Predict: for which number of pharmacists will the two models differ most? Run all six together.

  3. Compare Num Served between your model and the book’s model with the same number of pharmacists. They are two different models from two different bundles. Why are the counts almost identical?

  4. Use the cost model from the Scenario app activity ($50 per pharmacist-hour and $0.50 per car-minute in the system) to compute the cost per hour of all six scenarios. Does the input model change the staffing recommendation? Where does the choice of distribution matter, and where does it not?

  5. If you have an AI assistant connected to the KSL Server: ask it to describe your model by its bundle id. Do your labels and units appear?

Afterward

Every change to the model’s code means building the JAR and bundling it again. If your project has the Gradle task ksl bundle > deployBundle (the course repository’s does), it does the whole round in one step, using the identity written in build.gradle.kts. Use the workbench to see and curate your model; use the task when you are changing code often.