Class: Symian::IncidentGenerator

Inherits:
Object
  • Object
show all
Defined in:
lib/symian/generator.rb

Instance Method Summary collapse

Constructor Details

#initialize(simulation, options = {}) ⇒ IncidentGenerator

Returns a new instance of IncidentGenerator.

Raises:

  • (ArgumentError)


10
11
12
13
14
15
16
17
18
# File 'lib/symian/generator.rb', line 10

def initialize(simulation, options={})
  @simulation = simulation

  @arrival_times = Sequence.create(options)
  raise ArgumentError unless @arrival_times

  # NOTE: so far we support only sequential integer iids
  @next_iid = 0
end

Instance Method Details

#generateObject



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/symian/generator.rb', line 21

def generate
  # get next incident arrival time
  next_arrival = @arrival_times.next

  # handle case where arrival times is limited source
  return nil unless next_arrival

  # increase @next_iid
  @next_iid += 1

  # generate and return incident
  i = Incident.new(@next_iid, next_arrival,
                   :category => 'normal', # not supported at the moment
                   :priority => 0)        # not supported at the moment

  @simulation.new_event(Event::ET_INCIDENT_ARRIVAL, i, next_arrival, nil)
end