コード例 #1
0
        em.create_user(
            f'bike_{bid}',
            initial_process='IncludeBike',
            initial_dock=dock
        )
        bid += 1

# Creating cyclists as users
for c in range(N_CYCLISTS):
    from_station = random.choice(STATIONS)
    to_station = random.choice([s for s in STATIONS if s != from_station])
    user = em.create_user(
        f'cyclist_{c}',
        instant=round(random.uniform(0, 30), 2),
        initial_process='Cycle',
        from_station=from_station,
        to_station=to_station
    )

# Running simulation
em.run()

# Reporting
for r in pm.rm.resources:
    print('\n', r)
    print(pm.get_resource(r).usage)

print(em.checkpoints)

print(em.get_state(at=5))
コード例 #2
0
# Create car wash with NUM_MACHINE machines and attach car wash process
pm.create_resource('machines', capacity=NUM_MACHINES)


class CarWash(Process):
    def definition(self, user):
        # Car arrives and requests the use of a machine
        yield user.waits('machines')

        # Car enters the car wash and spends WASHTIME minutes inside
        yield user.waits(timedelta(minutes=WASHTIME))

        # Car leaves the car wash and releases the machine for the next car to use
        user.set_checkpoint(f'Left the carwash. {random.randint(50, 99)}% of dirt removed.')
        user.releases('machines')

pm.attach_process(CarWash)

# Create event stream
em = EventManager(pm)
now = datetime.now()
times = np.concatenate([np.zeros(3), np.random.randint(T_INTER-2, T_INTER+2, int(SIM_TIME/(T_INTER-2)))]).cumsum()
for i, t in enumerate(times):
    em.create_user(f'Car {i}', instant=now+timedelta(minutes=t))

if __name__ == '__main__':
    # Execute!
    em.run(until=now+timedelta(minutes=SIM_TIME))
    print(em.checkpoints)
    print(pm.get_resource('machines').usage)
コード例 #3
0
            td = random.expovariate(1.0 / time_discussing)
            # yield as long as the customer is discussing at the counter
            yield user.waits(td)
            # release the resource
            user.releases('counters')
            user.set_checkpoint('Finished')
        else:
            # release the resource
            user.releases('counters')
            # customer reneged
            user.set_checkpoint('Reneged')


# store process into process Manager
pm.attach_process(CustomerWaitCounter)

# create event manager
em = EventManager(pm)
for i in range(NEW_CUSTOMERS):
    # create new customer
    t = random.expovariate(1.0 / INTERVAL_CUSTOMERS)
    em.create_user(f'Customer {i}', instant=t)

# random.seed(RANDOM_SEED)

if __name__ == '__main__':
    # execute the program
    em.run()
    print(em.checkpoints)
    print(pm.get_resource('counters').usage)