from simkit.rand import RandomVariate from simkit.base import EventList from simkit.simutil import SimpleStateChangeDumper from simkit.examples.basic import TandemQueueWithBlocking from simkit.stats import SimpleStatsTimeVarying from simkit.rand import RandomVariate from random import Random # Uncomment to seed with computer clock time # RandomVariate.baseRNG = Random() interarrval_time_generator = RandomVariate.instance('Exponential', mean=1.8) service_time_generator = [ RandomVariate.instance('Gamma', alpha=2.5, beta=1.6), RandomVariate.instance('Uniform', min=2.2, max=4.4) ] number_servers = [3, 2] buffer_size = 1 print(interarrval_time_generator) print(service_time_generator) tandem_queue_with_blocking = TandemQueueWithBlocking( interarrval_time_generator, number_servers[0], number_servers[1], service_time_generator[0], service_time_generator[1], buffer_size) print(tandem_queue_with_blocking.describe()) simple_state_change_dumper = SimpleStateChangeDumper() # tandem_queue_with_blocking.add_state_change_listener(simple_state_change_dumper) number_in_queue1_stat = SimpleStatsTimeVarying('number_in_queue1') number_in_queue2_stat = SimpleStatsTimeVarying('number_in_queue2')
from simkit.rand import RandomVariate from simkit.base import EventList 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')
from simkit.examples.entitycreator import EntityCreator from simkit.examples.entityserver import EntityServer from simkit.stats import SimpleStatsTally from simkit.stats import CollectionSizeTimeVarying from simkit.rand import RandomVariate from simkit.base import EventList from time import time interarrival_time_generator = RandomVariate.instance('Uniform', min=0.9, max=2.2) entity_creator = EntityCreator(interarrival_time_generator) print(entity_creator.describe()) total_number_servers = 2 service_time_generator = RandomVariate.instance('Gamma', alpha=1.7, beta=1.8) entity_server = EntityServer(total_number_servers, service_time_generator) print(entity_server.describe()) entity_creator.add_sim_event_listener(entity_server) inner_delay_in_queue_stat = SimpleStatsTally("delay_in_queue") 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')
from simkit.stats import IndexedSimpleStatsTally from simkit.base import IndexedStateChangeEvent from simkit.base import SimEntityBase from simkit.rand import RandomVariate source = SimEntityBase() print(source.describe()) name = 'foo' rv = RandomVariate.instance('Exponential', mean=2.3) stats = IndexedSimpleStatsTally(name) for i in range(1000): for j in range(4): event = IndexedStateChangeEvent(j, source, name, rv.generate) stats.state_change(event) print(stats)
from simkit.examples.entityserver import EntityServer from simkit.rand import RandomVariate from simkit.examples.entitycreator import EntityCreator from simkit.base import EventList from simkit.simutil import SimpleStateChangeDumper from simkit.stats import SimpleStatsTally from simkit.stats import CollectionSizeTimeVarying from simkit.quantiles import student_t from math import sqrt interarrivalMean = 1.7 interarrival = RandomVariate.instance('Exponential', mean=interarrivalMean) entity_creator = EntityCreator(interarrival) print (entity_creator.describe()) alpha = 1.7 beta = 1.8 number_servers = 2 generator = RandomVariate.instance('Gamma', alpha=alpha, beta=beta) entity_server = EntityServer(number_servers, generator) print(entity_server.describe()) entity_creator.add_sim_event_listener(entity_server) dumper = SimpleStateChangeDumper() delay_in_queue_stat = SimpleStatsTally("delay_in_queue") entity_server.add_state_change_listener(delay_in_queue_stat) time_in_system_stat = SimpleStatsTally('time_in_system')
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.serverwithreneges import CustomerCreator from simkit.examples.serverwithreneges import ServerWithReneges from simkit.rand import RandomVariate from simkit.base import EventList from simkit.stats import SimpleStatsTally from simkit.stats import CollectionSizeTimeVarying from time import time interarrival_generator = RandomVariate.instance('Exponential', mean=1.5) renege_generator = RandomVariate.instance('Uniform', min=2.0, max=6.0) creator = CustomerCreator(interarrival_generator, renege_generator) print(creator.describe()) 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()
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.rand import RandomVariate from simkit.rand import Discrete rv = RandomVariate.instance('Discrete', values=[1, 2, 3, 4, 5], frequencies=[20, 30, 40, 50, 60]) print(rv) counts = {} number = 1000000 for i in range(number): x = rv.generate if counts.keys().__contains__(x): counts[x] = counts[x] + 1 else: counts[x] = 1 print(counts) for x in sorted(counts.keys()): counts[x] = counts[x] / number print('{x:d} = {p:.4f}'.format(x=x, p=counts[x])) counts.clear() rv = RandomVariate.instance('Discrete', values=['one', 'two', 'three', 'four', 'fiver'], frequencies=[20, 30, 40, 50, 60]) for i in range(number): x = rv.generate
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 StoppedArrivalProcess from simkit.rand import RandomVariate from simkit.base import EventList interarrival_time_generator = RandomVariate.instance('Gamma', alpha=2.1, beta=1.8) stop_time = 30.0 stopped_arrival_process = StoppedArrivalProcess(interarrival_time_generator, stop_time) print(stopped_arrival_process.describe()) EventList.verbose = True EventList.reset() EventList.start_simulation()
from simkit.rand import RandomVariate from simkit.stats import SimpleStatsTally if __name__ == '__main__': rv = RandomVariate.instance('Exponential', mean=1) print(rv) sum = 0.0 n = 1000000 for i in range(n): sum += rv.generate() # print(rv.generate()) print(sum / n) print() rv.seed(2468) for i in range(1, 5): print(rv.generate()) rv2 = RandomVariate.instance('Exponential', 'simkit.rand', mean=1.0 + i / 10) rv2.mean = 1.0 + i / 10 print(rv2) # for module in modules: # print(module) rv3 = RandomVariate.instance('Constant', 'simkit.rand', value=5.4) print(rv3) for i in range(4): print(rv3.generate())
from pydoc import describe from simkit.examples import twocranesberth from simkit.rand import RandomVariate from simkit.base import EventList from simkit.simutil import SimpleStateChangeDumper from simkit.examples.twocranesberth import ShipArrivalProcess from simkit.examples.twocranesberth import TwoCranesBerth from simkit.stats import SimpleStatsTally interarrival_genarator = RandomVariate.instance('Exponential', mean=0.7) unload_time_generator = RandomVariate.instance('Uniform', min=0.5, max=1.5) ship_arrival_process = ShipArrivalProcess(interarrival_genarator, unload_time_generator) two_cranes_berth = TwoCranesBerth() ship_arrival_process.add_sim_event_listener(two_cranes_berth) simple_state_dumper = SimpleStateChangeDumper() ship_arrival_process.add_state_change_listener(simple_state_dumper) two_cranes_berth.add_state_change_listener(simple_state_dumper) print(ship_arrival_process) print(two_cranes_berth) delay_in_queue_stat = SimpleStatsTally('delay_in_queue') time_in_system_stat = SimpleStatsTally('time_in_system') two_cranes_berth.add_state_change_listener(delay_in_queue_stat) two_cranes_berth.add_state_change_listener(time_in_system_stat)
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()