Class: Eventsims::Randomsim
- Inherits:
-
Object
- Object
- Eventsims::Randomsim
- Defined in:
- lib/eventsims/simevent.rb
Overview
module Simevent
Direct Known Subclasses
Instance Method Summary collapse
- #arrival ⇒ Object
- #custspend ⇒ Object
-
#get_servend_ ⇒ Object
Returns time when servce begin.
- #getarrive_ ⇒ Object
- #idle ⇒ Object
- #idletime_ ⇒ Object
-
#initialize(*args) ⇒ Randomsim
constructor
A new instance of Randomsim.
-
#intarrival ⇒ Object
Methods to be used outside of initialize returning necessary values Main methods.
-
#otherresults(list1, list2, list3) ⇒ Object
Method used to calculate the rest of the data like time when service begins wait time in queue, (_queue) time customer spent in the system (_custspend).
- #queuewait ⇒ Object
- #servbegin ⇒ Object
- #servbegins_ ⇒ Object
- #servend ⇒ Object
- #service ⇒ Object
Constructor Details
#initialize(*args) ⇒ Randomsim
Returns a new instance of Randomsim.
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 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 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 |
# File 'lib/eventsims/simevent.rb', line 6 def initialize(*args) ''' Initialisation ''' stop, amount, @_intarrival, @_service = 10, (2..20).step(1).to_a.sample, [], [] if args.size == 0 amount.times{@_intarrival << (1..stop).step(1).to_a.sample} amount.times{@_service << (1..stop).step(1).to_a.sample} elsif args.size == 1 args[0].times{@_intarrival << (1..stop).step(1).to_a.sample} args[0].times{@_service << (1..stop).step(1).to_a.sample} elsif args.size == 2 args[1].times{@_intarrival << (1..args[0]).step(1).to_a.sample} args[1].times{@_service << (1..args[0]).step(1).to_a.sample} elsif args.size == 3 args[2].times{@_intarrival << (1..args[0]).step(1).to_a.sample} args[2].times{@_service << (1..args[1]).step(1).to_a.sample} else raise "Arguments must be between 0 to 3" end #Sets its first value to zero @_intarrival[0] = 0 # Required variables @_arrival, @_preservstart, @_servstart = [], [0], [] @_queue, @_servend, @_custspend, @_idle = [], [], [], [0] def getarrive_() '''Returns arrival time''' increase = 0 @_intarrival.each {|i| increase +=i @_arrival << increase } return @_arrival end def servbegins_() '''Returns time when service begin''' increase = 0 i = 0; while i < @_service.size increase+= @_service[i] @_preservstart << increase i+=1 end @_preservstart.pop return @_preservstart end #populate @_servend with values. just to get same size @_intarrival.each{|i| @_servend << i} #Please maintain order if you are editing the code! # Calling functions getarrive_() #Returns arrival time servbegins_() #Returns time when servce begin def get_servend_() '''Retuns time when service ends''' x = 0; while x < ((@_preservstart).size) @_servend[x] = @_preservstart[x] + @_service[x] s = 1; while s < (@_preservstart).size if @_preservstart[s] < (maximum = @_arrival[s] > @_servend[x]? @_arrival[s] : @_servend[x]) @_preservstart[s] = (maximum) end s+=1 end x+=1 end return @_servend end # Method used to calculate the rest of the data like #time when service begins #wait time in queue, (_queue) #time customer spent in the system (_custspend) def otherresults(list1, list2, list3) ''' Stores and return the value of (list2 - list3) in list1 ''' x = 0; while x < list2.size list1 << (list2[x] - list3[x]) x+=1 end list1[0] = 0 if list1[0] < 0 end def idletime_() '''Returns the idle time of server''' x,y = 0,1 while y < @_servend.size (@_idle) << (@_servstart[y] - @_servend[x]) x+=1; y+=1 end return @_idle end # Calling other methods get_servend_() otherresults(@_servstart, @_servend, @_service) otherresults(@_queue, @_servstart, @_arrival) otherresults(@_custspend, @_servend, @_arrival) idletime_() end |
Instance Method Details
#arrival ⇒ Object
121 122 123 124 |
# File 'lib/eventsims/simevent.rb', line 121 def arrival() '''Returns the arrival time''' return @_arrival end |
#custspend ⇒ Object
146 147 148 149 |
# File 'lib/eventsims/simevent.rb', line 146 def custspend() '''Returns the time customer spends in system''' return @_custspend end |
#get_servend_ ⇒ Object
Returns time when servce begin
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/eventsims/simevent.rb', line 66 def get_servend_() '''Retuns time when service ends''' x = 0; while x < ((@_preservstart).size) @_servend[x] = @_preservstart[x] + @_service[x] s = 1; while s < (@_preservstart).size if @_preservstart[s] < (maximum = @_arrival[s] > @_servend[x]? @_arrival[s] : @_servend[x]) @_preservstart[s] = (maximum) end s+=1 end x+=1 end return @_servend end |
#getarrive_ ⇒ Object
38 39 40 41 42 43 44 |
# File 'lib/eventsims/simevent.rb', line 38 def getarrive_() '''Returns arrival time''' increase = 0 @_intarrival.each {|i| increase +=i @_arrival << increase } return @_arrival end |
#idle ⇒ Object
151 152 153 154 |
# File 'lib/eventsims/simevent.rb', line 151 def idle() '''Returns the idle time of server''' return @_idle end |
#idletime_ ⇒ Object
95 96 97 98 99 100 101 102 103 |
# File 'lib/eventsims/simevent.rb', line 95 def idletime_() '''Returns the idle time of server''' x,y = 0,1 while y < @_servend.size (@_idle) << (@_servstart[y] - @_servend[x]) x+=1; y+=1 end return @_idle end |
#intarrival ⇒ Object
Methods to be used outside of initialize returning necessary values Main methods
116 117 118 119 |
# File 'lib/eventsims/simevent.rb', line 116 def intarrival() '''Returns the interarrival time''' return @_intarrival end |
#otherresults(list1, list2, list3) ⇒ Object
Method used to calculate the rest of the data like time when service begins wait time in queue, (_queue) time customer spent in the system (_custspend)
86 87 88 89 90 91 92 93 |
# File 'lib/eventsims/simevent.rb', line 86 def otherresults(list1, list2, list3) ''' Stores and return the value of (list2 - list3) in list1 ''' x = 0; while x < list2.size list1 << (list2[x] - list3[x]) x+=1 end list1[0] = 0 if list1[0] < 0 end |
#queuewait ⇒ Object
136 137 138 139 |
# File 'lib/eventsims/simevent.rb', line 136 def queuewait() """Returns the customer's waiting time in the queue""" return @_queue end |
#servbegin ⇒ Object
131 132 133 134 |
# File 'lib/eventsims/simevent.rb', line 131 def servbegin() '''Returns the time when service began''' return @_servstart end |
#servbegins_ ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/eventsims/simevent.rb', line 46 def servbegins_() '''Returns time when service begin''' increase = 0 i = 0; while i < @_service.size increase+= @_service[i] @_preservstart << increase i+=1 end @_preservstart.pop return @_preservstart end |
#servend ⇒ Object
141 142 143 144 |
# File 'lib/eventsims/simevent.rb', line 141 def servend() '''Returns the time service ended''' return @_servend end |
#service ⇒ Object
126 127 128 129 |
# File 'lib/eventsims/simevent.rb', line 126 def service() '''Returns the service time''' return @_service end |