Simulations CS2123 What are simulations? • Simulations attempt to model a real-world situation to learn before actually making what could be an expensive change. • Frequently, simulations investigate a situation prior to implementing the change. • Computer Scientists are sought to provide simulation assistance. Case #1: Space Shuttle Robotic Arm • In the 1970s, UTSA had a research contract to help model movement of the very expensive robotic arm. NASA didn’t want the arm to be damaged or damage the shuttle, harming the astronauts. • The simulation provided a graphical model of the arm movement and provided graphics with hidden-line filtering. • Robotic arm control software could then be modified to understand all movement tolerances. Case #2: Should WGFY add a teller? • The “We’ve Got a Fee for You” (WGFY) Bank is hearing many complaints from customers who are waiting in line at their bank. • Customers are complaining that they are waiting over 20 minutes • Lobby has three tellers, each with a separate queue • Due to bank lobby configuration expenses, labor expenses, and customer inconvenience, they would like a simulation to learn the effects of proposed changes • Alternative A: change to a single queue serving all tellers ($100K) • Alternative B: add another teller ($400K + $60K/year) • Alternative C: add another teller and utilize a single queue serving all tellers ($600K + $60K/year) Case #3: Call Center Management • A large insurance company needed to improve telephone coverage. Customers were hanging up due to long waits for a service representative during peak times (10 am – 2pm CDT). • Hang-up probability (of calls still live) • > 5 minutes – 40% • between 2 and 5 minutes – 20% • < 2 minutes – 5% • Company had geographic call centers in each major time zone. PST service representatives only worked with customers on the West coast; MST service representatives only worked with customers in the Rocky Mountain area; CDT service representatives worked with customers in any time zone. Case #3: Call Center Management (cont) • Due to labor costs and time to onboard new employees, adding labor is expensive and wouldn’t immediately change the call waiting times. Options (select combinations): • Add X employees (X * $100K/year) with impact not realized until after 3 months. • Provide automated call-back system ($500K + $400K/year support) • During low morning call periods in the MST and PST areas, use MST and PST service representatives to help with the peak in the CST. Licensing requirements would mandate additional training (productivity loss of 1 month per utilized service representative) Case #4: Podunk Intersection Congestion: • The City of Podunk needs to determine how to handle congestion at a particular intersection. Should a traffic light be installed or should a roundabout be used? • During Peak congestion (7am-9am and 4pm-6pm), traffic queues up to 4-9 vehicles and a wait time of over 1 minute. • Alternatives: • Traffic Light ($400K + $40K / yr). Average wait times are expected to be 50 seconds during peak due to waiting for a complete light cycle. • Roundabout ($600K + $0 / yr). Average wait times are expected to be less than 6 seconds (but it hasn’t been verified). Time-based Event Simulations • Cases 2 thru 4 are timed-based event simulations: • Need to know: • Arrival rates • Service time • Want to produce (at least): • • • • Average waiting time Average queue length Maximum waiting time Maximum queue length • Observations of current arrivals (customer at lobby, customer call, vehicles at intersections) can provide arrival rates • Observations of service time (teller service, call center service representative service, time to cross intersection) • Observations of existing wait time and queue length Time-based Event Simulations • Time-based Event List • Arrival events are inserted based on information from observations • Service completion events are inserted when servicing begins • Implementation: Ordered (by time) Linked List with duplicates • Clock • Next clock value set from time-based event list • Implementation: Simple integer value • Queues • While customers (or widgets ) are waiting, they queue up • Used to compute average waiting times, maximum waiting times, average queue length, and maximum queue length • Implementation: queue (with additional attributes for statistics) • Servers • Maintain whether they are busy • Associate the server with a queue • Trying to take the next customer (or widget) from the queue • Widgets • Represent the thing that moves through the simulation (customers, vehicles) • Implementation: structure (with additional attributes for statistics) Running a Simulation • runSimulation routine: • Loops through the dynamic list of time-based events • Based on the event type, invokes the appropriate capability. Examples: • Arrival: • arrival • enter queue • try to seize server • Service Completion: • release server (and server take’s another widget from queue if possible) Sample runSimulation: single queue, one server generateArrival(sim, 0); while (removeLL(sim->eventList, &event)) { sim->iClock = event.iTime; // advance clock switch(event.eventType); { case EVT_ARRIVAL: arrival(sim, &event.widget); queueUp(sim, queueTeller, &event.widget); seize(sim, queueTeller, serverTeller); break; case EVT_TELLER_COMPLETE: release(sim, queueTeller, serverTeller, &event.widget); leaveSystem(sim, event.widget); break; default: ErrExit(ERR_ALGORITHM, "Unknown event type: %d\n", event.iEventType); } } Queue Statistics - average waiting time Gather queue time for each widget. • Each widget includes a time in queue (for each queue). • On leaving queue: • Add the widget’s time to the queue time sum. • Add 1 to queue exit widget count.