I am working with simpy to schedule the jobs with container. I am facing a problem that only those jobs are kept iterating which started at the time of the first iteration. i.e the first 3 jobs keep iterating . does not let the 4th job to come in the process. Second I also want to know the total execution time of all jobs? i will highly appreciate if someone can help me.
import simpy
from simpy.core import StopSimulation
from simpy.events import Timeout
class Cluster:
def __init__(self, env):
self.total_machines = simpy.Container(env,init=6)
self.end_time=0
#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, job_id,job_arrivaltime,job_time, job_machine_req):
self.env = env
self.job_id = job_id
self.job_arrivaltime = job_arrivaltime
self.job_time = job_time
self.job_machine_req = job_machine_req
#system
def system(env, job, cluster):
while job.job_machine_req<=cluster.total_machines.level:
print("cuurent level of cluster",cluster.total_machines.level)
print('%s arrives at %s' % (job.job_id, env.now))
yield cluster.total_machines.get(job.job_machine_req) #get the required resources
print('%s starts running with %s resources at %s' % (job.job_id, job.job_machine_req, env.now))
yield env.timeout(job.job_time) #wait for desired time of the job
print('%s completed job at %s' % (job.job_id, env.now))
yield cluster.total_machines.put(job.job_machine_req)
env = simpy.Environment() #create an simpy enviroment
cluster = Cluster(env) #intialize the cluster object
jobs = [
Job(env, '1', 0, 3, 2),
Job(env, '2', 0, 2, 2),
Job(env, '3', 0, 3, 1),
Job(env, '4', 0, 4, 3),
]
for job in jobs:
env.process(system(env, job, cluster))
env.run(until=4)