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
include SimpleKit
# Constructor - initializes the model parameters.
# param: arrivalRate - The rate at which customers arrive to the system.
# param: serviceRate - The rate at which individual servers serve.
# param: maxServers - The total number of servers in the system.
def initialize(arrivalRate, serviceRate, maxServers)
@arrivalRate = arrivalRate
@serviceRate = serviceRate
@maxServers = maxServers
# param: arrival_rate - The rate at which customers arrive to the system.
# param: service_rate - The rate at which individual servers serve.
# param: max_servers - The total number of servers in the system.
def initialize(arrival_rate, service_rate, max_servers)
@arrival_rate = arrival_rate
@service_rate = service_rate
@max_servers = max_servers
end
# Initialize the model state and schedule any necessary events.
# Note that this particular model will terminate based on
# time by scheduling a halt 100 time units in the future.
def init
@numAvailableServers = @maxServers
@qLength = 0
@num_available_servers = @max_servers
@q_length = 0
schedule(:arrival, 0.0)
schedule(:halt, 100.0)
dumpState("init")
dump_state('init')
end
# 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
@qLength += 1
schedule(:arrival, exponential(@arrivalRate))
schedule(:beginService, 0.0) if (@numAvailableServers > 0)
dumpState("Arrival")
@q_length += 1
schedule(:arrival, exponential(@arrival_rate))
schedule(:begin_service, 0.0) if @num_available_servers > 0
dump_state('arrival')
end
# Start service for the first customer in line, removing that
# customer from the queue and utilizing one of the available servers.
# An endService will be scheduled.
def beginService
@qLength -= 1
@numAvailableServers -= 1
schedule(:endService, exponential(@serviceRate))
dumpState("Begin Svc")
# An end_service will be scheduled.
def begin_service
@q_length -= 1
@num_available_servers -= 1
schedule(:end_service, exponential(@service_rate))
dump_state('begin svc')
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.
def endService
@numAvailableServers += 1
schedule(:beginService, 0.0) if (@qLength > 0)
dumpState("End Svc")
def end_service
@num_available_servers += 1
schedule(:begin_service, 0.0) if @q_length > 0
dump_state('end svc')
end
# Exponential random variate generator.
......@@ -67,13 +66,12 @@ class MMk
# A report mechanism which dumps the time, current event, and values
# of the state variables to the console.
# 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",
model_time, event, @qLength, @numAvailableServers
model_time, event, @q_length, @num_available_servers
end
end
# 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
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