Class: Symian::SupportGroup

Inherits:
Object
  • Object
show all
Includes:
YAMLSerializable
Defined in:
lib/symian/support_group.rb

Constant Summary collapse

ATTRIBUTES =

setup readable/accessible attributes

[ :sgid, :operators ]
TRACED_ATTRIBUTES =
ATTRIBUTES + [ :incident_queue_info ]

Instance Method Summary collapse

Methods included from YAMLSerializable

#to_yaml_properties

Constructor Details

#initialize(support_group_id, simulation, work_time_characterization, operator_characterizations) ⇒ SupportGroup

Returns a new instance of SupportGroup.



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/symian/support_group.rb', line 26

def initialize(support_group_id, simulation, work_time_characterization, operator_characterizations)
  @sgid = support_group_id
  @simulation = simulation

  # initialize needed_work_time_rng
  @needed_work_time_rv = ERV::RandomVariable.new(work_time_characterization)

  # create operators
  @operators = []

  if operator_characterizations.kind_of?(Hash)
    operator_characterizations = [ operator_characterizations ]
  end

  next_op_id = 1
  operator_characterizations.each do |x|
    x[:number].times do |y|
      op = Operator.new("OP#{next_op_id}_#{@sgid}", @sgid, x.reject { |k, v| k == :number })
      @operators << op
      next_op_id = next_op_id + 1
    end
  end

  # initialize incident queue and related tracking information
  @incident_queue = []
  @incident_queue_info = []
end

Instance Method Details

#initialize_at(time) ⇒ Object



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/symian/support_group.rb', line 55

def initialize_at(time)
  # find out which operators are off duty and schedule their comeback
  @operators_off_work = @operators.select do |x|
    !x.workshift.active_at?(time)
  end
  @operators_off_work.each do |op|
    t = op.workshift.secs_to_begin_of_shift(time)
    @simulation.new_event(Event::ET_OPERATOR_RETURNING, op.oid,
                          time + t, @sgid)
  end

  # find out which operators are on duty and schedule their leaving
  @available_operators = @operators - @operators_off_work
  @available_operators.each do |op|
    t = op.workshift.secs_to_end_of_shift(time)
    @simulation.new_event(Event::ET_OPERATOR_LEAVING, op.oid,
                          time + t, @sgid) unless t == WorkShift::Infinity
  end
end

#new_incident(incident, time) ⇒ Object



76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/symian/support_group.rb', line 76

def new_incident(incident, time)
  # increase number of visited SGs
  incident.visited_support_groups += 1

  incident_info = {
    # set up incident needed work time
    :needed_work_time => @needed_work_time_rv.next,
    # # reset queue_time_at_last_sg attribute
    # :queue_time => 0
  }

  # put incident at the end of the queue
  @incident_queue << [ incident, incident_info, time ]

  # update queue size tracking information
  @incident_queue_info << { :size => @incident_queue.size, :time => time }
  @simulation.new_event(Event::ET_SUPPORT_GROUP_QUEUE_SIZE_CHANGE, @incident_queue.size,
                        time, @sgid)

  # try to allocate operator
  try_to_allocate_operator(time)
end

#operator_arrived_at_work(operator_id, time) ⇒ Object



117
118
119
120
121
122
123
124
# File 'lib/symian/support_group.rb', line 117

def operator_arrived_at_work(operator_id, time)
  op = @operators.find{|x| x.oid == operator_id }
  @operators_off_work.delete(op)
  @available_operators << op
  try_to_allocate_operator(time)
  @simulation.new_event(Event::ET_OPERATOR_LEAVING, op.oid,
                        time + op.workshift.duration, @sgid)
end

#operator_finished_working(operator_id, time) ⇒ Object



127
128
129
130
131
132
133
# File 'lib/symian/support_group.rb', line 127

def operator_finished_working(operator_id, time)
  op = @operators.find{|x| x.oid == operator_id }
  if op.workshift.secs_to_end_of_shift(time) > 0
    @available_operators << op
  end
  try_to_allocate_operator(time)
end

#operator_going_home(operator_id, time) ⇒ Object



108
109
110
111
112
113
114
# File 'lib/symian/support_group.rb', line 108

def operator_going_home(operator_id, time)
  op = @operators.find{|x| x.oid == operator_id }
  @available_operators.delete_if{|x| x.oid == operator_id }
  @operators_off_work << op
  @simulation.new_event(Event::ET_OPERATOR_RETURNING, op.oid,
                        time + 86400 - op.workshift.duration, @sgid)
end

#schedule_incident_for_reassignment(incident, incident_info, time) ⇒ Object



100
101
102
103
104
105
# File 'lib/symian/support_group.rb', line 100

def schedule_incident_for_reassignment(incident, incident_info, time)
  @incident_queue.unshift [ incident, incident_info, time ]
  # update queue size tracking information
  @incident_queue_info << { :size => @incident_queue.size, :time => time }
  try_to_allocate_operator(time)
end