from simkit.base import Adapter from simkit.simutil import SimpleStateChangeDumper from simkit.examples.arrivalprocess import BatchArrivalProcess from simkit.examples.simpleserver import SimpleServer interarrival_time_generator = RandomVariate.instance('Exponential', mean=2.5) batch_generator = RandomVariate.instance('Discrete', values=[1, 2, 3, 4, 5], \ frequencies=[20, 30, 40, 50, 60]) batch_arrival_process = BatchArrivalProcess(interarrival_time_generator, batch_generator) print(batch_arrival_process.describe()) number_servers = 1 service_time_generator = RandomVariate.instance('Gamma', alpha=1.2, beta=2.3) simple_server = SimpleServer(number_servers, service_time_generator) print(simple_server.describe()) adapter = Adapter('arrival1', 'arrival') adapter.connect(batch_arrival_process, simple_server) batch_arrival_process.add_state_change_listener(SimpleStateChangeDumper()) simple_server.add_state_change_listener(SimpleStateChangeDumper()) stopTime = 20.0 EventList.verbose = True EventList.stop_at_time(stopTime) EventList.stop_on_event(10, 'arrival') EventList.reset() EventList.start_simulation()
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()
total_number_servers = 2 service_time_generator = RandomVariate.instance('Gamma', alpha=2.5, beta=1.2) server = ServerWithReneges(total_number_servers, service_time_generator) print(server.describe()) creator.add_sim_event_listener(server) delay_in_queue_stat = SimpleStatsTally('delay_in_queue') server.add_state_change_listener(delay_in_queue_stat) number_in_queue_stat = CollectionSizeTimeVarying('queue') server.add_state_change_listener(number_in_queue_stat) for rep in range(1, 5): start = time() EventList.stop_at_time(100000.0) EventList.reset() number_in_queue_stat.reset() EventList.start_simulation() end = time() print('\nReplication {rep:,d} took {time:.4f} sec'.format(time=end - start, rep=rep)) print('Simulation ended at simtime {time:,.0f}\n'.format( time=EventList.simtime)) print('Avg delay in queue = {avg:,.4f}'.format( avg=(delay_in_queue_stat.mean))) print('Avg number in queue = {avg:.4f}'.format( avg=number_in_queue_stat.time_varying_mean())) print('There have been {num:,d} reneges'.format(num=server.number_reneges)) print('There have been {num:,d} served'.format(
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()
inner_delay_in_queue_stat = TruncatingSimpleStatsTally('delay_in_queue', truncation_point) 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') p = 0.975 numberReps = 50 EventList.stop_on_event(truncation_point + steady_state_observations, 'start_service') print('\nRunning {reps:d} replications with truncation at {tp:,d} observations and {ss:,d} observations in steady-state '.\ format(reps=numberReps,tp=truncation_point, ss=steady_state_observations)) start = time() for rep in range(1, numberReps + 1): if rep % 10 == 0: print('rep {rep:d} halfwidth {hw:,.4f}'.format( rep=rep, hw=outer_delay_in_queue_stat.halfwidth(p))) 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()
self.schedule('q', 1.0) self.schedule('b', 0.5) self.schedule('c', 2.0, 3) self.schedule('c', 1.5, 2) self.schedule('d', 3.4, 1, 2, 3) self.schedule('d', 3.4, 1, 2, 4) def b(self): print('In b()!') self.cancel('a') self.cancel('c', 3) def a(self): print('In a()!') def c(self, i): print('In c(): i = ' + str(i)) self.cancel('d', 1, 2, 3) def d(self, x, y, z): print('In D: args = (' + str(x) + ',' + str(y) + ',' + str(z) + ')') if __name__ == '__main__': test = TestCancelled() EventList.verbose = True EventList.reset() EventList.start_simulation()
heap = [] heappush(heap, evt) heappush(heap, evt2) heappush(heap, evt3) heappush(heap, evt4) copy = heap.copy() copy.sort() dump='Event List:' for e in copy: dump += '\n' + str(e) print(dump) el = EventList() evt = source.schedule('Foo', 1.0) evt1 = SimEntityBase().schedule('bar', 2.0, [1]) evt2 = SimEntityBase().schedule('boo', 2.0, [], priority=Priority.HIGH) print (EventList.dump()) print (Priority.DEFAULT < Priority.HIGH) print (Priority.DEFAULT > Priority.HIGH) # print(evt1 < evt2) # print(evt1 > evt2) copy = EventList.event_list copy.sort()
from simkit.base import EventList from simkit.base import SimEntityBase class Test(SimEntityBase): def run(self): self.schedule('init', 0.0, 0) def init(self, i): self.schedule('init', 0.0, i + 1) if __name__=='__main__': # interarrival_time_generator = RandomVariate.getInstance('Exponential', mean=3.0) # arrival_process = ArrivalProcess(interarrival_time_generator) # print(arrival_process.describe()) test = Test() EventList.stop_on_event(10, 'init') EventList.verbose = True EventList.reset() EventList.start_simulation()
from simkit.base import EventList from simkit.rand import RandomVariate from simkit.simutil import SimpleStateChangeDumper from simkit.base import Adapter from simkit.examples.transferline import TransferLine from simkit.examples.transferline import JobCreator job_creator = JobCreator(RandomVariate.instance('Exponential', mean=1.7)) print(job_creator.describe()) number_stations = 3 number_machines = [5, 4, 2] service_times = [RandomVariate.instance('Gamma', alpha=3.2, beta=2.3), \ RandomVariate.instance('Uniform', min=4.5, max=6.7), RandomVariate.instance('Exponential', mean=3.0)] transfer_line = TransferLine(number_stations, number_machines, service_times) print(transfer_line.describe()) adapter = Adapter('job_arrival', 'arrival') adapter.connect(job_creator, transfer_line) transfer_line.add_state_change_listener(SimpleStateChangeDumper()) # EventList.stopAtTime(20.0) EventList.stop_on_event(10, 'job_complete') EventList.verbose = True EventList.reset() EventList.start_simulation()
from simkit.examples.arrivalprocess import ArrivalProcess from simkit.rand import RandomVariate from simkit.base import EventList from inspect import getmembers arrivalProcess = ArrivalProcess(RandomVariate.instance('Constant', value=3.4)) print(arrivalProcess.describe()) print(EventList.sim_entities) arrivalProcess.persistent = False EventList.reset() print(EventList.sim_entities) print(getmembers(arrivalProcess))
from simkit.examples.arrivalprocess import EntityCreator from simkit.examples.entityserver import EntityServer from simkit.base import EventList from simkit.rand import RandomVariate from simkit.base import Adapter entity_creator = EntityCreator(RandomVariate.instance('Constant', value=2.3)) entity_server = EntityServer(1, RandomVariate.instance('Constant', value=2.2)) adapter = Adapter("entity_arrival", "arrival") adapter.connect(entity_creator, entity_server) # simEvent = entity_creator.waitDelay('Foo', 1.2, Priority.HIGH, Entity()) # print(simEvent) # print(simEvent.id) # copy = simEvent.copy() # print(copy) # print(copy.id) EventList.stop_on_event(5, 'start_service') EventList.verbose = True EventList.reset() EventList.start_simulation()