2017-04-10 12 views
0

carwashをSimpyの例のリストに記載されているように考えてください。ここで、車が修理されるたびに、次の車を清掃する前に、対応する洗浄ユニットを修理しなければならないと仮定する。その間、サービスされた車は出ることができます。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

は、通常の事業体がその間にそれを使用できないように非常に高い優先順位を使用して、リソースを使用するエンティティをモデル化することです。だからあなたの「ゴーストカーは、」実際に、このような悪い考えではありません。

関連する問題