Class: ErlangC::Calculator

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(arrival_rate, serv_time, wait_time = 30) ⇒ Calculator

Returns a new instance of Calculator.



6
7
8
# File 'lib/erlang_c_calculator.rb', line 6

def initialize(arrival_rate, serv_time, wait_time = 30)
  @arrival_rate, @serv_time, @wait_time = arrival_rate, serv_time, wait_time
end

Instance Attribute Details

#arrival_rateObject

Returns the value of attribute arrival_rate.



4
5
6
# File 'lib/erlang_c_calculator.rb', line 4

def arrival_rate
  @arrival_rate
end

#serv_timeObject

Returns the value of attribute serv_time.



4
5
6
# File 'lib/erlang_c_calculator.rb', line 4

def serv_time
  @serv_time
end

#wait_timeObject

Returns the value of attribute wait_time.



4
5
6
# File 'lib/erlang_c_calculator.rb', line 4

def wait_time
  @wait_time
end

Instance Method Details

#agents_neededObject



27
28
29
30
31
32
33
# File 'lib/erlang_c_calculator.rb', line 27

def agents_needed
  agents = (traffic_intensity + 1).to_i
  while average_wait(agents) >= wait_time
    agents += 1
  end
  agents
end

#average_wait(num_agents) ⇒ Object



23
24
25
# File 'lib/erlang_c_calculator.rb', line 23

def average_wait(num_agents)
  (erlang_c_probability(num_agents) * serv_time) / (num_agents - traffic_intensity)
end

#erlang_c_probability(m) ⇒ Object



14
15
16
17
18
19
20
21
# File 'lib/erlang_c_calculator.rb', line 14

def erlang_c_probability(m)
  u = traffic_intensity

  return 1 if u > m

  product = (0..m).inject(1){|prod, j| (prod * j/u) + 1}
  1.0/((product * (m - u)/u) + 1)
end

#traffic_intensityObject



10
11
12
# File 'lib/erlang_c_calculator.rb', line 10

def traffic_intensity
  (arrival_rate * serv_time).to_f
end