Class: Symian::Simulation
- Inherits:
-
Object
- Object
- Symian::Simulation
- Defined in:
- lib/symian/simulation.rb
Constant Summary collapse
- ATTRIBUTES =
[ :start_time ]
Instance Method Summary collapse
-
#initialize(configuration, performance_analyzer, trace = TraceCollector.new(:memory)) ⇒ Simulation
constructor
A new instance of Simulation.
- #new_event(type, data, time, destination) ⇒ Object
- #now ⇒ Object
- #run ⇒ Object
Constructor Details
#initialize(configuration, performance_analyzer, trace = TraceCollector.new(:memory)) ⇒ Simulation
Returns a new instance of Simulation.
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/symian/simulation.rb', line 19 def initialize(configuration, performance_analyzer, trace=TraceCollector.new(:memory)) @configuration = configuration # setup performance analyzer and simulation trace @performance_analyzer = performance_analyzer @trace = trace # setup simulation start and current time @current_time = @start_time = @configuration.start_time # create support groups @support_groups = {} @configuration.support_groups.each do |name,conf| @support_groups[name] = SupportGroup.new(name, self, conf[:work_time], conf[:operators]) end # create transition matrix @transition_matrix = TransitionMatrix.new(@configuration.transition_matrix) # create event queue @event_queue = SortedArray.new end |
Instance Method Details
#new_event(type, data, time, destination) ⇒ Object
43 44 45 |
# File 'lib/symian/simulation.rb', line 43 def new_event(type, data, time, destination) @event_queue << Event.new(type, data, time, destination) end |
#now ⇒ Object
48 49 50 |
# File 'lib/symian/simulation.rb', line 48 def now @current_time end |
#run ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 |
# File 'lib/symian/simulation.rb', line 53 def run # initialize support groups @support_groups.values.each do |sg| sg.initialize_at(@configuration.start_time) end # generate first incident ig = IncidentGenerator.new(self, @configuration.incident_generation) ig.generate # schedule end of simulation unless @configuration.end_time.nil? # puts "Simulation ends at: #{@configuration.end_time}" new_event(Event::ET_END_OF_SIMULATION, nil, @configuration.end_time, nil) end # calculate warmup threshold warmup_threshold = @configuration.start_time + @configuration.warmup_duration @incidents_being_worked_on ||= [] # launch simulation until @event_queue.empty? e = @event_queue.shift # sanity check on simulation time flow if @current_time > e.time raise 'Error: simulation time inconsistency for event ' + "e.type=#{e.type} @current_time=#{@current_time}, e.time=#{e.time}" end @current_time = e.time #Trace.new_event e case e.type when Event::ET_INCIDENT_ARRIVAL sg_name = @transition_matrix.escalation('In') sg = @support_groups[sg_name] sg.new_incident(e.data, e.time) @incidents_being_worked_on << e.data # generate next incident ig.generate # TODO: pinpoint instant for calculation of time spent in enqueued state when Event::ET_INCIDENT_ASSIGNMENT # TODO: implement calculation of time spent in suspended state when Event::ET_OPERATOR_ACTIVITY_STARTS when Event::ET_OPERATOR_ACTIVITY_FINISHES sg = @support_groups[e.destination] sg.operator_finished_working(e.data[0], e.time) when Event::ET_INCIDENT_RESCHEDULING sg = @support_groups[e.destination] sg.schedule_incident_for_reassignment(e.data[0], e.data[1], e.time) # TODO: pinpoint instant for calculation of time spent in suspended state when Event::ET_INCIDENT_ESCALATION inc = e.data sg_name = @transition_matrix.escalation(e.destination) if sg_name == "Out" inc.closure_time = e.time # remove incident from list of incidents being worked on and add it to trace @incidents_being_worked_on.delete(inc) @trace.record_incidents(inc) else sg = @support_groups[sg_name] sg.new_incident(inc, e.time) end when Event::ET_OPERATOR_LEAVING sg = @support_groups[e.destination] sg.operator_going_home(e.data, e.time) when Event::ET_OPERATOR_RETURNING sg = @support_groups[e.destination] sg.operator_arrived_at_work(e.data, e.time) when Event::ET_SUPPORT_GROUP_QUEUE_SIZE_CHANGE when Event::ET_END_OF_SIMULATION break end end # save trace file @trace.save_and_close kpis = @performance_analyzer.calculate_kpis(@trace) kpis.merge(incidents_being_worked_on: @incidents_being_worked_on.size) end |