Activity: Your Model in the Apps
KSL Applications Activities
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
Read
GammaPharmacy.kt. It is the book’s drive-through pharmacy, with two parts at the end: aGammaPharmacyModelBuilderand amainfunction. Which lines makenumPharmacistsa control that the apps can change? Under what name will the apps show the service time’s random variable?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.
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.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
- In IntelliJ’s Gradle window, run Tasks > build > jar (or type
./gradlew jarin the terminal; on Windows,gradlew.bat jar). Find the file it writes inbuild/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.
The Overview tab lists the model builders the workbench found. How many are there, and why more than your one?
On the Bundle identity tab, set the Bundle id to
edu.uark.<your username>.pharmacyand the Display name to<Your name>'s Pharmacy, then click Apply bundle identity. Why must the bundle id be unique?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 theGammaPharmacyrow 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?On the Catalog tab, feature and label these: the number of pharmacists (
Number of Pharmacists, unitpharmacists), the service time’s shape and scale, and the outputsSystem Time(Avg Time in System, unitmin),Num in System, andNum Served. What will a user of the apps see differently because of this?Click Validate, and fix anything the health banner reports. Then click Assemble bundle JAR…, go to the
bundlesfolder of yourKSLWorkfolder, and save the bundle there aspharmacy-<your username>.jar. Why that folder? What would happen if you saved it in the workbench’s default folder instead?
4. Use it
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
mainexactly?In KSL Scenario, build six scenarios with 30 replications each: your
GammaPharmacywith 1, 2, and 3 pharmacists, and the book’sDriveThroughPharmacyWithQwith 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.Compare
Num Servedbetween 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?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?
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.