# by making `charging_request` part of the thunk we return? # Something like this: # # return (self.charging, charging_request) # # which fsm.trampoline would then handle appropriately. return self.charging def charging(self, data): # The charging station has been acquired; yield env.timeout(self.charging_time) # BCS is the battery charging station print("%s leaving the bcs at %s" % (self.name, self.env.now)) self.charging_station.release(self.charging_request) if __name__ == "__main__": env = simpy.Environment() bcs = simpy.Resource(env, capacity=2) cars = [ Car( env, name=process_name(i, of=4), charging_station=bcs, driving_time=i * 2, charging_time=5, ) for i in range(4) ] env.run()
["unimportant_work"] if unimportant_work.process in repairman_processes else [] ) return f"Repairman at {repairman_at}; broken {broken_machines}; unimportant_work state {unimportant_work.state}, made {unimportant_work.works_made}" # Setup and start the simulation print("Machine shop") # This helps reproducing the results rng1.seed(RANDOM_SEED) rng2.seed(RANDOM_SEED) # Create an environment and start the setup process env = simpy.Environment() repairman = simpy.PreemptiveResource(env, capacity=1) machines = [ Machine(env, id=i, name=process_name(i, of=NUM_MACHINES), repairman=repairman) for i in range(NUM_MACHINES) ] unimportant_work = UnimportantWork(env, repairman=repairman) # Execute! env.run(until=SIM_TIME) # Analyis/results print("Machine shop results after %s weeks" % WEEKS) for machine in machines: print("%s made %d parts." % (machine.name, machine.parts_made)) print(snapshot(env, repairman, unimportant_work, machines))
return f"Repairman at {repairman_at}; broken {broken_machines}; unimportant_work state {unimportant_work.state}, made {unimportant_work.works_made}" # Setup and start the simulation print("Machine shop") # This helps reproducing the results rng1.seed(RANDOM_SEED) rng2.seed(RANDOM_SEED) # Create an environment and start the setup process env = simpy.Environment() repairman = simpy.PreemptiveResource(env, capacity=1) machines = [ Machine(env, id=i, name=process_name(i, of=NUM_MACHINES), repairman=repairman) for i in range(NUM_MACHINES) ] unimportant_work = UnimportantWork(env, repairman=repairman) # Execute! env.run(until=SIM_TIME) # Analyis/results print("Machine shop results after %s weeks" % WEEKS) for machine in machines: print("%s made %d parts." % (machine.name, machine.parts_made)) print(snapshot(env, repairman, unimportant_work, machines))
start = env.now yield env.timeout(done_in) done_in = 0 except simpy.Interrupt: done_in -= env.now - start # Setup and start the simulation print("Machine shop") # This helps reproducing the results rng1.seed(RANDOM_SEED) rng2.seed(RANDOM_SEED) # Create an environment and start the setup process env = simpy.Environment() repairman = simpy.PreemptiveResource(env, capacity=1) machines = [ Machine(env, process_name(i, of=NUM_MACHINES), repairman) for i in range(NUM_MACHINES) ] env.process(other_jobs(env, repairman)) # Execute! env.run(until=SIM_TIME) # Analyis/results print("Machine shop results after %s weeks" % WEEKS) for machine in machines: print("%s made %d parts." % (machine.name, machine.parts_made))
import simpy from simpy_fsm.v1 import process_name # BCS is the battery charging station def car(env, name, bcs, driving_time, charge_duration): # Simulate driving to the BCS yield env.timeout(driving_time) # Request one of its charging spots print("%s arriving at %d" % (name, env.now)) with bcs.request() as req: yield req # Charge the battery print("%s starting to charge at %s" % (name, env.now)) yield env.timeout(charge_duration) print("%s leaving the bcs at %s" % (name, env.now)) if __name__ == "__main__": env = simpy.Environment() bcs = simpy.Resource(env, capacity=2) for i in range(4): env.process(car(env, process_name(i, of=4), bcs, i * 2, 5)) env.run()