2017-04-10 6 views
0

Simpy 예제 목록에 설명 된대로 carwash을 고려하십시오. 이제 차를 수리 할 때마다 다음 세탁기를 청소하기 전에 해당 세척 장치를 수리해야한다고 가정합니다. 그 사이에, 서비스되는 차는 떠날 수있다.Simpy : 사용자에게 서비스하는 것 이상으로 리소스를 차단하십시오.

위의 모델을 어떻게 만들 수 있습니까? 나의 현재의 해결책은 재생 시간 동안 세차기를 막는 우선 순위가 높은 유령 자동차를 갖추는 것입니다. 나는이 해결책을 매우 우아하게 생각하지 않으며 더 나은 방법이 있다고 생각한다.

위에서 언급 한 튜토리얼의 열악한 복사본을 나타내는 아래의 예에서 서비스되는 자동차는 재생 기간 동안 펌프를 나갈 수 없습니다. 어떻게 의도 된 동작을 모방하도록 고칠 수 있습니까? 나는 해결책이 간단하다고 생각한다. 나는 단지 그것을 보지 못한다.

import random 
import simpy 

RANDOM_SEED = 42 
NUM_MACHINES = 2 # Number of machines in the carwash 
WASHTIME = 5  # Minutes it takes to clean a car 
REGENTIME = 3 
T_INTER = 7  # Create a car every ~7 minutes 
SIM_TIME = 20  # Simulation time in minutes 


class Carwash(object): 
    def __init__(self, env, num_machines, washtime): 
     self.env = env 
     self.machine = simpy.Resource(env, num_machines) 
     self.washtime = washtime 

    def wash(self, car): 
     yield self.env.timeout(WASHTIME) 
     print("Carwash removed %s's dirt at %.2f." % (car, env.now)) 

    def regenerateUnit(self): 
     yield self.env.timeout(REGENTIME) 
     print("Carwash's pump regenerated for next user at %.2f." % (env.now)) 


def car(env, name, cw): 
    print('%s arrives at the carwash at %.2f.' % (name, env.now)) 
    with cw.machine.request() as request: 
     yield request 

     print('%s enters the carwash at %.2f.' % (name, env.now)) 
     yield env.process(cw.wash(name)) 

     yield env.process(cw.regenerateUnit()) 

     print('%s leaves the carwash at %.2f.' % (name, env.now)) 


def setup(env, num_machines, washtime, t_inter): 
    # Create the carwash 
    carwash = Carwash(env, num_machines, washtime) 

    # Create 4 initial cars 
    for i in range(4): 
     env.process(car(env, 'Car %d' % i, carwash)) 

    # Create more cars while the simulation is running 
    while True: 
     yield env.timeout(random.randint(t_inter - 2, t_inter + 2)) 
     i += 1 
     env.process(car(env, 'Car %d' % i, carwash)) 


# Setup and start the simulation 
random.seed(RANDOM_SEED) # This helps reproducing the results 

# Create an environment and start the setup process 
env = simpy.Environment() 
env.process(setup(env, NUM_MACHINES, WASHTIME, T_INTER)) 

# Execute! 
env.run(until=SIM_TIME) 

미리 감사드립니다.

답변

1

당신이 원하는 것은 매우 높은 우선 순위를 가진 귀하의 리소스를 사용하는 엔티티를 모델링하여 일반 엔티티가 사용할 수 없도록 만드는 것입니다. 그래서 당신의 "유령 자동차"는 실제로 그렇게 나쁜 생각이 아닙니다.