Skip to content
Snippets Groups Projects
Commit 1a2f1a30 authored by pjs's avatar pjs
Browse files

convert camelcase to snakecase

parent 52800707
No related branches found
No related tags found
No related merge requests found
...@@ -9,52 +9,51 @@ class MMk ...@@ -9,52 +9,51 @@ class MMk
include SimpleKit include SimpleKit
# Constructor - initializes the model parameters. # Constructor - initializes the model parameters.
# param: arrivalRate - The rate at which customers arrive to the system. # param: arrival_rate - The rate at which customers arrive to the system.
# param: serviceRate - The rate at which individual servers serve. # param: service_rate - The rate at which individual servers serve.
# param: maxServers - The total number of servers in the system. # param: max_servers - The total number of servers in the system.
def initialize(arrivalRate, serviceRate, maxServers) def initialize(arrival_rate, service_rate, max_servers)
@arrivalRate = arrivalRate @arrival_rate = arrival_rate
@serviceRate = serviceRate @service_rate = service_rate
@maxServers = maxServers @max_servers = max_servers
end end
# Initialize the model state and schedule any necessary events. # Initialize the model state and schedule any necessary events.
# Note that this particular model will terminate based on # Note that this particular model will terminate based on
# time by scheduling a halt 100 time units in the future. # time by scheduling a halt 100 time units in the future.
def init def init
@numAvailableServers = @maxServers @num_available_servers = @max_servers
@qLength = 0 @q_length = 0
schedule(:arrival, 0.0) schedule(:arrival, 0.0)
schedule(:halt, 100.0) schedule(:halt, 100.0)
dumpState("init") dump_state('init')
end end
# An arrival event increments the queue length, schedules the next # An arrival event increments the queue length, schedules the next
# arrival, and schedules a beginService event if a server is available. # arrival, and schedules a begin_service event if a server is available.
def arrival def arrival
@qLength += 1 @q_length += 1
schedule(:arrival, exponential(@arrivalRate)) schedule(:arrival, exponential(@arrival_rate))
schedule(:beginService, 0.0) if (@numAvailableServers > 0) schedule(:begin_service, 0.0) if @num_available_servers > 0
dumpState("Arrival") dump_state('arrival')
end end
# Start service for the first customer in line, removing that # Start service for the first customer in line, removing that
# customer from the queue and utilizing one of the available servers. # customer from the queue and utilizing one of the available servers.
# An endService will be scheduled. # An end_service will be scheduled.
def beginService def begin_service
@qLength -= 1 @q_length -= 1
@numAvailableServers -= 1 @num_available_servers -= 1
schedule(:endService, exponential(@serviceRate)) schedule(:end_service, exponential(@service_rate))
dumpState("Begin Svc") dump_state('begin svc')
end end
# Frees up an available server, and schedules a beginService if # Frees up an available server, and schedules a begin_service if
# anybody is waiting in line. # anybody is waiting in line.
def endService def end_service
@numAvailableServers += 1 @num_available_servers += 1
schedule(:beginService, 0.0) if (@qLength > 0) schedule(:begin_service, 0.0) if @q_length > 0
dumpState("End Svc") dump_state('end svc')
end end
# Exponential random variate generator. # Exponential random variate generator.
...@@ -67,13 +66,12 @@ class MMk ...@@ -67,13 +66,12 @@ class MMk
# A report mechanism which dumps the time, current event, and values # A report mechanism which dumps the time, current event, and values
# of the state variables to the console. # of the state variables to the console.
# param: event - The name of the event which invoked this method. # param: event - The name of the event which invoked this method.
def dumpState(event) def dump_state(event)
printf "Time: %8.3f\t%10s - Q: %d\tServers Available: %d\n", printf "Time: %8.3f\t%10s - Q: %d\tServers Available: %d\n",
model_time, event, @qLength, @numAvailableServers model_time, event, @q_length, @num_available_servers
end end
end end
# Instantiate an MMk object with a particular parameterization and run it. # Instantiate an MMk object with a particular parameterization and run it.
srand 7654321 srand 7_654_321
MMk.new(4.5, 1.0, 5).run MMk.new(4.5, 1.0, 5).run
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment