システムにジョブが入り、複数のリソースを要求するPython 2のキューイングシミュレーションモデルに取り組んでいます。到着する各ジョブは、さまざまな量のリソース (特定のリソースではありません!) を要求し、さまざまな時間リソースを使用します。
res[1] や res[2] など、特定のリソースを要求する例を見つけました。2 つのリソースをリクエストするだけです。
また、私のジョブは最初のジョブが完了した後にのみ実行されます。for ループに問題があることは理解していますが、適切に修正する方法がわかりません。この場合、2 つのリソースがあるため、a と b は時間 1 で実行できるはずですが、b は a が終了するまで待機します。奇数。
複数のリソースをリクエストし、適切なタイミングでジョブを実行するための助けをいただければ幸いです。
これまでの私のコードは次のとおりです。
import simpy
#resource
class SuperComputer:
def __init__(self, env):
self.nodes = simpy.Resource(env, capacity = 2)
#users of resource
class Job:
#enter: time the job enters the system
#timeout is how long the job occupies a resource for
#resources is how many resources a job needs in order to run
def __init__(self, env, name, enter,timeout, resources):
self.env = env
self.name = name
self.enter = enter
self.timeout = timeout
self.resources = resources
#system
def system(env, jobs, super_computer):
with super_computer.nodes.request() as req:
for job in jobs:
print('%s arrives at %s' % (job.name, job.enter))
yield req
yield env.timeout(job.enter)
print('%s starts running with %s resources at %s' % (job.name, job.resources, env.now))
yield env.timeout(job.timeout)
print('%s completed job at %s' % (job.name, env.now))
env = simpy.Environment()
super_computer = SuperComputer(env)
jobs = [
Job(env, 'a', 1, 4, 1),
Job(env, 'b', 1, 4, 1),
Job(env, 'c', 1, 4, 1),
Job(env, 'd', 1, 4, 1),
]
env.process(system(env, jobs, super_computer))
env.run(50)
出力:
a arrives at 1
a starts running with 1 resources at 1
a completed job at 5
b arrives at 1
b starts running with 1 resources at 6
b completed job at 10
c arrives at 1
c starts running with 1 resources at 11
c completed job at 15
d arrives at 1
d starts running with 1 resources at 16
d completed job at 20