Class: ErlangC::Calculator
- Inherits:
-
Object
- Object
- ErlangC::Calculator
- Defined in:
- lib/erlang_c_calculator.rb
Instance Attribute Summary collapse
-
#arrival_rate ⇒ Object
Returns the value of attribute arrival_rate.
-
#serv_time ⇒ Object
Returns the value of attribute serv_time.
-
#wait_time ⇒ Object
Returns the value of attribute wait_time.
Instance Method Summary collapse
- #agents_needed ⇒ Object
- #average_wait(num_agents) ⇒ Object
- #erlang_c_probability(m) ⇒ Object
-
#initialize(arrival_rate, serv_time, wait_time = 30) ⇒ Calculator
constructor
A new instance of Calculator.
- #traffic_intensity ⇒ Object
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_rate ⇒ Object
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_time ⇒ Object
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_time ⇒ Object
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_needed ⇒ Object
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_intensity ⇒ Object
10 11 12 |
# File 'lib/erlang_c_calculator.rb', line 10 def traffic_intensity (arrival_rate * serv_time).to_f end |