Example #1
0
def simulation(n=12):
    """
    n is an optional argument specifying the number of processes in the
    simulation. n defaults to 12.

    Create a list of processes, then run these processes through the
    following scheduling algorithms, in order:

    1. SJF (no preemption)
    2. SJF (with preemption)
    3. Round-Robin (preemption, time slice defaults to 200ms)
    4. Preemptive-Priority via Round-Robin 
            (default time slice 100ms)
    5. Preemptive-Priority with aging via Round-Robin 
            (default time slice 100ms)

    After each algorithm runs, it returns a CompletedPlist. Each
    process records information about itself as it runs, and the 
    statistics() method on a CompletedPlist computes min/avg/max
    values for turnaround time, initial wait time, and total
    wait time.

    Although the time for a context switch (TCS) is set as a global variable, 
    I don't reccommend changing it. The instructions said that 7ms of the 
    switch was for removing a "before" process, and 10ms of the switch 
    was for selecting the next process. There was no provided information 
    on how to scale these values for different values of TCS. 

    To change the 10/90 arrival time distribution, look at the top of 
    process_priority.py. At the top, there is a global variable called 
    PERCENT_ARRIVING_TIME_ZERO, defaulted to 10.

    """
    plist = prp.create_plist()
    simulations = [
        sjf, sjf_preemption, roundrobin, roundrobin_priority, fcfs_aging
    ]

    for sim in simulations:
        # for clarity, print the name of the simulation
        print("RUNNING {}".format(sim.__name__), end='\n\n')

        # python passes all lists by reference, so copy plist to not
        cpy = deepcopy(plist)

        # run the simulation
        plist_completed = sim(cpy)

        # print statistics after scheduling completes
        print(end='\n')
        plist_completed.statistics()
        print(end='\n')
Example #2
0
def simulation(n=12):
    """
    n is an optional argument specifying the number of processes in the
    simulation. n defaults to 12.

    Create a list of processes, then run these processes through the
    following scheduling algorithms, in order:

    1. SJF (no preemption)
    2. SJF (with preemption)
    3. Round-Robin (preemption, time slice defaults to 200ms)
    4. Preemptive-Priority via Round-Robin 
            (default time slice 100ms)
    5. Preemptive-Priority with aging via Round-Robin 
            (default time slice 100ms)

    After each algorithm runs, it returns a CompletedPlist. Each
    process records information about itself as it runs, and the 
    statistics() method on a CompletedPlist computes min/avg/max
    values for turnaround time, initial wait time, and total
    wait time.

    Although the time for a context switch (TCS) is set as a global variable, 
    I don't reccommend changing it. The instructions said that 7ms of the 
    switch was for removing a "before" process, and 10ms of the switch 
    was for selecting the next process. There was no provided information 
    on how to scale these values for different values of TCS. 

    To change the 10/90 arrival time distribution, look at the top of 
    process_priority.py. At the top, there is a global variable called 
    PERCENT_ARRIVING_TIME_ZERO, defaulted to 10.

    """
    plist = prp.create_plist()
    simulations = [sjf, sjf_preemption, roundrobin, roundrobin_priority, fcfs_aging]

    for sim in simulations:
        # for clarity, print the name of the simulation
        print("RUNNING {}".format(sim.__name__), end="\n\n")

        # python passes all lists by reference, so copy plist to not
        cpy = deepcopy(plist)

        # run the simulation
        plist_completed = sim(cpy)

        # print statistics after scheduling completes
        print(end="\n")
        plist_completed.statistics()
        print(end="\n")
            if (running_process.popped is None):
                running_process.popped = TIME

        if (running_process.is_complete()):

            running_process.completes(TIME)
            p_completed.push(running_process)
            completed += 1

            # we will not check for a context switch until the
            # next iteration, decrement time. this way, a context switch will
            # begin immediately as a process completes
            TIME -= 1

            # 7 ms in context switch to clear old process
            prev_process = running_process
            TIMECS_REMAINING += 7
            running_process = None

        else:
            running_process.time -= 1

    return p_completed


if __name__ == "__main__":
    plist = pr.create_plist()  # takes optional argument for num processes
    plist_completed = fcfs_aging(plist)
    print()
    plist_completed.statistics()
            if (running_process.popped is None):
                running_process.popped = TIME

        if (running_process.is_complete()):

            running_process.completes(TIME)
            p_completed.push(running_process)
            completed += 1

            # we will not check for a context switch until the
            # next iteration, decrement time. this way, a context switch will
            # begin immediately as a process completes
            TIME -= 1

            # 7 ms in context switch to clear old process
            prev_process = running_process
            TIMECS_REMAINING += 7
            running_process = None

        else:
            running_process.time -= 1

    return p_completed

if __name__ == "__main__":
    plist = pr.create_plist()  # takes optional argument for num processes
    plist_completed = fcfs_aging(plist)
    print()
    plist_completed.statistics()