Example #1
0
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()
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()

    # This should throw a ValueError
    # arrival_process.waitDelay('Foo', -.001)
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()
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()
Example #5
0
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 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()