package student.activities import ksl.modeling.entity.KSLProcess import ksl.modeling.entity.ProcessModel import ksl.modeling.entity.ResourceWithQ import ksl.modeling.variable.IndicatorResponse import ksl.modeling.variable.RandomVariable import ksl.modeling.variable.Response import ksl.modeling.variable.TWResponse import ksl.simulation.Model import ksl.simulation.ModelElement import ksl.utilities.random.rvariable.TriangularRV /** * The airport checkpoint's identification inspection over a 10-hour day whose * arrival rate changes by the hour, with a morning rush. The model is the * process view model of the airport activities; the activity writes the parts * marked TODO. As given, the file compiles and runs, with no passengers. */ fun main() { val extraStart: Int? = null // the hour (1 to 10) in which a second officer starts val extraHours = 3 // how many hours the second officer works val m = Model("AirportRushHourModel") AirportRushHour(m, extraOfficerStartHour = extraStart, extraOfficerHours = extraHours, name = "Airport") m.numberOfReplications = 30 // 30 days m.lengthOfReplication = 600.0 // 10 hours, in minutes m.simulate() m.print() } class AirportRushHour( parent: ModelElement, extraOfficerStartHour: Int? = null, extraOfficerHours: Int = 3, name: String? = null ) : ProcessModel(parent, name = name) { /** Passengers per hour, for each of the 10 hours of the day. */ private val hourlyRates = doubleArrayOf(20.0, 40.0, 50.0, 40.0, 25.0, 15.0, 15.0, 20.0, 25.0, 20.0) private val myInspectionTimeRV = RandomVariable(this, TriangularRV(0.75, 1.5, 3.0, 2)) private val myNS = TWResponse(this, "Num in System") private val mySysTime = Response(this, "System Time") private val myWaitTime = Response(this, "Wait Time") private val myWTGE5 = IndicatorResponse({ x -> x >= 5.0 }, myWaitTime, "WaitTime >= 5 minutes") private val myOfficer: ResourceWithQ = ResourceWithQ(this, "Officer", 1) // TODO 1: create a PiecewiseConstantRateFunction from hourlyRates (10 segments // of 60 minutes; the rates must be per minute), an // NHPPPiecewiseRateFunctionEventGenerator on stream 1, and its arrival function, // which activates a Passenger's securityProcess. // TODO 2: create a ResponseSchedule of ten 60-minute intervals, not repeated, // that collects the wait time, the number waiting, and the officer's // instantaneous utilization in each hour. // TODO 3: if extraOfficerStartHour is not null, create a CapacitySchedule that // keeps 1 officer before that hour, 2 officers for extraOfficerHours hours, // and 1 officer after, and have the officer use it. private inner class Passenger : Entity() { val securityProcess: KSLProcess = process { myNS.increment() val arriveTime = time val a = seize(myOfficer) myWaitTime.value = time - arriveTime delay(myInspectionTimeRV) release(a) mySysTime.value = time - arriveTime myNS.decrement() } } }