0

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)     
    
wasiq khan
  • 11
  • 2
  • Total execution time depends on your device. Certain IDEs give you the time it takes to finish running a piece of code (VS code I think does this). Your other question I can't answer because I don't know anything about Simpy. Have a nice day :) – realFishSam Oct 07 '21 at 14:34
  • why do you need the while loop? – Michael Oct 08 '21 at 02:05
  • In def system delete the while and at the top add yield env.timeout(job.job_arrivaltime ) – Michael Oct 08 '21 at 02:08
  • Hi, Michael thank you so much.it really works – wasiq khan Oct 08 '21 at 14:23
  • Hi, after this I got another problem when I run a different combination of jobs it keeps running all without resetting the time. i.e when I run 3! combinations of these following jobs process doesn't reset the time.it considers 2nd combination as the next job. how can i reset the processing time to 0 after running one combination? Job(env, '1', 0, 3, 2), Job(env, '2', 0, 2, 2), Job(env, '3', 0, 3, 1), – wasiq khan Oct 08 '21 at 16:34
  • Basically, my question is how to reset the simulation time after one combination. So the next combination should start again from 0. – wasiq khan Oct 08 '21 at 17:59
  • There is not a good way to "reset" the clock. If you really need a clean start then you need to create a new environment and everything in it for each batch. Or you need to make sure a new batch does not start until until the old batch finishes. I suspect even though you have several batches , they are all getting submitted at time 0. Can you used the job arrival time to space things out? – Michael Oct 17 '21 at 03:41

0 Answers0