number_in_queue2_stat = SimpleStatsTimeVarying('number_in_queue2')
number_available_server1_stat = SimpleStatsTimeVarying(
    'number_available_server1')
number_available_server2_stat = SimpleStatsTimeVarying(
    'number_available_server2')
tandem_queue_with_blocking.add_state_change_listener(number_in_queue1_stat)
tandem_queue_with_blocking.add_state_change_listener(number_in_queue2_stat)
tandem_queue_with_blocking.add_state_change_listener(
    number_available_server1_stat)
tandem_queue_with_blocking.add_state_change_listener(
    number_available_server2_stat)

stop_time = 100000.0
# stop_time = 1000
# EventList.verbose = True
EventList.stop_at_time(stop_time)
upper_range = 20

# number_leaves = 100000
# EventList.stop_on_event(number_leaves, 'leave2')
print('Simulation will run for {time:,.2f} time units'.format(
    time=EventList.stop_time))
print('Buffer sizes will be from 1 to {upper:,d}'.format(upper=upper_range))
# print('Simulation will run for {num:,d} leave2 events'.format(num=number_leaves))

for buffer_size in range(1, upper_range + 1):
    tandem_queue_with_blocking.buffer_size = buffer_size

    EventList.reset()

    number_in_queue1_stat.reset()
entity_server.add_state_change_listener(inner_delay_in_queue_stat)

inner_number_in_queue_stat = CollectionSizeTimeVarying('queue')
entity_server.add_state_change_listener(inner_number_in_queue_stat)

outer_number_in_queue_stat = SimpleStatsTally('outer_number_in_queue')

outer_delay_in_queue_stat = SimpleStatsTally('mean_delay_in_queue')

# print(getattr(entity_server, 'number_servers'))

runtime = 800.0
p = 0.975
numberReps = 100

EventList.stop_at_time(runtime)

start = time()
for rep in range(numberReps):
    EventList.reset()
    inner_delay_in_queue_stat.reset()
    inner_number_in_queue_stat.reset()
    EventList.start_simulation()
    outer_delay_in_queue_stat.new_observation(inner_delay_in_queue_stat.mean)
    outer_number_in_queue_stat.new_observation(inner_number_in_queue_stat.mean)
end = time()
elapsed = end - start
print('\n{reps:d} replications of length {runtime:,.1f} took {time:,.4f} sec'.
      format(reps=numberReps, runtime=runtime, time=elapsed))
print('95% CI for number in queue: {mean:,.4f} \u00B1 {halfwidth:,.4f}'.format(
    mean=outer_number_in_queue_stat.mean,
예제 #3
0
from simkit.examples.arrivalprocess import ArrivalProcess
from simkit.base import EventList
from simkit.simutil import SimpleStateChangeDumper
from simkit.rand import RandomVariate

interarrival_time_generator = RandomVariate.instance('Exponential', mean=1.7)
arrival_process = ArrivalProcess(interarrival_time_generator)
print(arrival_process.describe())
print()

arrival_process.add_state_change_listener(SimpleStateChangeDumper())

EventList.verbose = True
EventList.stop_at_time(15.0)

EventList.reset()
EventList.start_simulation()
from simkit.examples.arrivalprocess import ArrivalProcess
from simkit.examples.arrivalprocess import EntityCreator
from simkit.base import EventList
from simkit.simutil import SimpleStateChangeDumper

if __name__ == "__main__":
    generator = Exponential(1.7)
    arrival_process = ArrivalProcess(generator)
    print(arrival_process)

    print(type(arrival_process))

    dumper = SimpleStateChangeDumper()
    arrival_process.add_state_change_listener(dumper)

    EventList.stop_at_time(100.0)

    EventList.verbose = True

    EventList.reset()
    EventList.start_simulation()

    EventList.cold_reset()
    EventList.stop_on_event(10, 'entity_arrival')

    entityCreator = EntityCreator(generator)

    print("With EntityCreator")
    EventList.reset()
    EventList.start_simulation()
service_mean = simple_server.service_time_generator.alpha * simple_server.service_time_generator.beta
arrival_mean = (arrival_process.interarrival_time_generator.min +
                arrival_process.interarrival_time_generator.max) * 0.5
intensity = service_mean / (simple_server.total_number_servers * arrival_mean)

print('\ntraffic intensity = {rho:.4f}'.format(rho=intensity))

stop_time = 150000
# stopTime = 50

# arrival_process_stat = TruncatingSimpleStatsTimeVarying(truncation_time, 'number_arrivals')
# arrival_process.add_state_change_listener(arrival_process_stat)

# EventList.verbose = True

EventList.stop_at_time(stop_time + truncation_time)
EventList.reset()
EventList.start_simulation()

print(
    '\nSimulation ended at simtime {time:,.2f}'.format(time=EventList.simtime))

# print(arrival_process_stat)
# print(number_in_queue_stat)
# print(number_available_servers_stat)

# print('{num:,d} customers arrived'.format(num=arrival_process.number_arrivals))
# print('{num:,d} customers served'.format(num=simple_server.number_served))

print('Avg number in queue = {avg:.4f}'.format(avg=number_in_queue_stat.mean))
utilization = 1.0 - number_available_servers_stat.mean / simple_server.total_number_servers