Пример #1
0
def do_exp():

    pop, log, best = run_pso(
        toolbox=toolbox,
        logbook=logbook,
        stats=stats,
        gen_curr=0,
        gen_step=GEN,
        invalidate_fitness=True,
        initial_pop=None,
        w=W,
        c1=C1,
        c2=C2,
        n=N,
    )

    solution = construct_solution(best, sorted_tasks)
    schedule = build_schedule(_wf, estimator, rm, solution)

    Utility.validate_static_schedule(_wf, schedule)

    makespan = Utility.makespan(schedule)
    print("Final makespan: {0}".format(makespan))
    print("Heft makespan: {0}".format(Utility.makespan(heft_schedule)))
    return makespan
Пример #2
0
    def test_fixed_ordering(self):
        _wf = wf("Montage_25")
        rm = ExperimentResourceManager(rg.r([10, 15, 25, 30]))
        estimator = SimpleTimeCostEstimator(comp_time_cost=0,
                                            transf_time_cost=0,
                                            transferMx=None,
                                            ideal_flops=20,
                                            transfer_time=100)
        sorted_tasks = HeftHelper.heft_rank(_wf, rm, estimator)

        heft_schedule = run_heft(_wf, rm, estimator)
        heft_mapping = schedule_to_position(heft_schedule)

        heft_gen = lambda: heft_mapping if random.random(
        ) > 0.95 else generate(_wf, rm, estimator)

        toolbox = Toolbox()
        # toolbox.register("generate", generate, _wf, rm, estimator)
        toolbox.register("generate", heft_gen)
        toolbox.register("fitness", fitness, _wf, rm, estimator, sorted_tasks)

        toolbox.register("force_vector_matrix", force_vector_matrix, rm)
        toolbox.register("velocity_and_position", velocity_and_position, _wf,
                         rm, estimator)
        toolbox.register("G", G)
        toolbox.register("kbest", Kbest)

        statistics = Statistics()
        statistics.register(
            "min", lambda pop: numpy.min([p.fitness.mofit for p in pop]))
        statistics.register(
            "avr", lambda pop: numpy.average([p.fitness.mofit for p in pop]))
        statistics.register(
            "max", lambda pop: numpy.max([p.fitness.mofit for p in pop]))
        statistics.register(
            "std", lambda pop: numpy.std([p.fitness.mofit for p in pop]))

        logbook = Logbook()
        logbook.header = ("gen", "G", "kbest", "min", "avr", "max", "std")

        pop_size = 100
        iter_number = 100
        kbest = pop_size
        ginit = 5

        final_pop = run_gsa(toolbox, statistics, logbook, pop_size,
                            iter_number, kbest, ginit)

        best = min(final_pop, key=lambda x: toolbox.fitness(x).mofit)
        solution = {
            MAPPING_SPECIE: list(zip(sorted_tasks, best)),
            ORDERING_SPECIE: sorted_tasks
        }
        schedule = build_schedule(_wf, estimator, rm, solution)
        Utility.validate_static_schedule(_wf, schedule)
        makespan = Utility.makespan(schedule)
        print("Final makespan: {0}".format(makespan))

        pass
Пример #3
0
def do_exp():
    pop, _logbook, best = run_gsa(toolbox, stats, logbook, pop_size, iter_number, kbest, ginit)
    solution = {MAPPING_SPECIE: list(best.entity.items()), ORDERING_SPECIE: sorted_tasks}
    schedule = build_schedule(_wf, estimator, rm, solution)
    Utility.validate_static_schedule(_wf, schedule)
    makespan = Utility.makespan(schedule)
    print("Final makespan: {0}".format(makespan))
    print("Final makespan: {0}".format(makespan))
    return makespan
Пример #4
0
def do_exp(wf_name):
    _wf = wf(wf_name)

    heft_schedule = run_heft(_wf, rm, estimator)

    Utility.validate_static_schedule(_wf, heft_schedule)

    makespan = Utility.makespan(heft_schedule)
    return makespan
Пример #5
0
def do_exp(wf_name):
    _wf = wf(wf_name)
    rm = ExperimentResourceManager(rg.r([10, 15, 25, 30]))
    estimator = SimpleTimeCostEstimator(comp_time_cost=0,
                                        transf_time_cost=0,
                                        transferMx=None,
                                        ideal_flops=20,
                                        transfer_time=100)

    empty_fixed_schedule_part = Schedule({node: [] for node in rm.get_nodes()})

    heft_schedule = run_heft(_wf, rm, estimator)

    ga_functions = GAFunctions2(_wf, rm, estimator)

    generate = partial(ga_generate,
                       ga_functions=ga_functions,
                       fixed_schedule_part=empty_fixed_schedule_part,
                       current_time=0.0,
                       init_sched_percent=0.05,
                       initial_schedule=heft_schedule)

    stats = tools.Statistics(lambda ind: ind.fitness.values[0])
    stats.register("avg", numpy.mean)
    stats.register("std", numpy.std)
    stats.register("min", numpy.min)
    stats.register("max", numpy.max)

    logbook = tools.Logbook()
    logbook.header = ["gen", "evals"] + stats.fields

    toolbox = Toolbox()
    toolbox.register("generate", generate)
    toolbox.register(
        "evaluate",
        fit_converter(
            ga_functions.build_fitness(empty_fixed_schedule_part, 0.0)))
    toolbox.register("clone", deepcopy)
    toolbox.register("mate", ga_functions.crossover)
    toolbox.register("sweep_mutation", ga_functions.sweep_mutation)
    toolbox.register("mutate", ga_functions.mutation)
    # toolbox.register("select_parents", )
    # toolbox.register("select", tools.selTournament, tournsize=4)
    toolbox.register("select", tools.selRoulette)
    pop, logbook, best = run_ga(toolbox=toolbox,
                                logbook=logbook,
                                stats=stats,
                                **GA_PARAMS)

    resulted_schedule = ga_functions.build_schedule(best,
                                                    empty_fixed_schedule_part,
                                                    0.0)

    Utility.validate_static_schedule(_wf, resulted_schedule)

    ga_makespan = Utility.makespan(resulted_schedule)
    return ga_makespan
Пример #6
0
def do_exp():
    pop, _logbook, best = run_gsa(toolbox, stats, logbook, pop_size, 0, iter_number, None, kbest, ginit, **{"w":W, "c":C})

    schedule = build_schedule(_wf, rm, estimator,  best)
    Utility.validate_static_schedule(_wf, schedule)
    makespan = Utility.makespan(schedule)
    print("Final makespan: {0}".format(makespan))
    print("Heft makespan: {0}".format(Utility.makespan(heft_schedule)))
    return makespan
Пример #7
0
def do_exp(wf_name):
    _wf = wf(wf_name)
    rm = ExperimentResourceManager(rg.r([10, 15, 25, 30]))
    estimator = SimpleTimeCostEstimator(comp_time_cost=0, transf_time_cost=0, transferMx=None,
                                                ideal_flops=20, transfer_time=100)

    empty_fixed_schedule_part = Schedule({node: [] for node in rm.get_nodes()})

    heft_schedule = run_heft(_wf, rm, estimator)

    ga_functions = GAFunctions2(_wf, rm, estimator)

    generate = partial(ga_generate, ga_functions=ga_functions,
                               fixed_schedule_part=empty_fixed_schedule_part,
                               current_time=0.0, init_sched_percent=0.05,
                               initial_schedule=heft_schedule)


    stats = tools.Statistics(lambda ind: ind.fitness.values[0])
    stats.register("avg", numpy.mean)
    stats.register("std", numpy.std)
    stats.register("min", numpy.min)
    stats.register("max", numpy.max)

    logbook = tools.Logbook()
    logbook.header = ["gen", "evals"] + stats.fields

    toolbox = Toolbox()
    toolbox.register("generate", generate)
    toolbox.register("evaluate", fit_converter(ga_functions.build_fitness(empty_fixed_schedule_part, 0.0)))
    toolbox.register("clone", deepcopy)
    toolbox.register("mate", ga_functions.crossover)
    toolbox.register("sweep_mutation", ga_functions.sweep_mutation)
    toolbox.register("mutate", ga_functions.mutation)
    # toolbox.register("select_parents", )
    # toolbox.register("select", tools.selTournament, tournsize=4)
    toolbox.register("select", tools.selRoulette)
    pop, logbook, best = run_ga(toolbox=toolbox,
                                logbook=logbook,
                                stats=stats,
                                **GA_PARAMS)

    resulted_schedule = ga_functions.build_schedule(best, empty_fixed_schedule_part, 0.0)

    Utility.validate_static_schedule(_wf, resulted_schedule)

    ga_makespan = Utility.makespan(resulted_schedule)
    return ga_makespan
Пример #8
0
def do_exp():
    best, log, current = run_sa(
        toolbox=toolbox,
        logbook=logbook,
        stats=stats,
        initial_solution=initial_state, T=T, N=N
    )

    solution = {MAPPING_SPECIE: [item for item in best.mapping.items()], ORDERING_SPECIE: best.ordering}
    schedule = build_schedule(_wf, estimator, rm, solution)
    Utility.validate_static_schedule(_wf, schedule)
    makespan = Utility.makespan(schedule)
    heft_makespan = Utility.makespan(heft_schedule)
    print("Final makespan: {0}".format(makespan))
    print("Heft makespan: {0}".format(heft_makespan))
    return makespan
Пример #9
0
    def test_fixed_ordering(self):
        _wf = wf("Montage_25")
        rm = ExperimentResourceManager(rg.r([10, 15, 25, 30]))
        estimator = SimpleTimeCostEstimator(comp_time_cost=0, transf_time_cost=0, transferMx=None,
                                            ideal_flops=20, transfer_time=100)
        sorted_tasks = HeftHelper.heft_rank(_wf, rm, estimator)

        heft_schedule = run_heft(_wf, rm, estimator)
        heft_mapping = schedule_to_position(heft_schedule)

        heft_gen = lambda: heft_mapping if random.random() > 0.95 else generate(_wf, rm, estimator)


        toolbox = Toolbox()
        # toolbox.register("generate", generate, _wf, rm, estimator)
        toolbox.register("generate", heft_gen)
        toolbox.register("fitness", fitness, _wf, rm, estimator, sorted_tasks)

        toolbox.register("force_vector_matrix", force_vector_matrix, rm)
        toolbox.register("velocity_and_position", velocity_and_position, _wf, rm, estimator)
        toolbox.register("G", G)
        toolbox.register("kbest", Kbest)

        statistics = Statistics()
        statistics.register("min", lambda pop: numpy.min([p.fitness.mofit for p in pop]))
        statistics.register("avr", lambda pop: numpy.average([p.fitness.mofit for p in pop]))
        statistics.register("max", lambda pop: numpy.max([p.fitness.mofit for p in pop]))
        statistics.register("std", lambda pop: numpy.std([p.fitness.mofit for p in pop]))

        logbook = Logbook()
        logbook.header = ("gen", "G", "kbest", "min", "avr", "max", "std")

        pop_size = 100
        iter_number = 100
        kbest = pop_size
        ginit = 5

        final_pop = run_gsa(toolbox, statistics, logbook, pop_size, iter_number, kbest, ginit)

        best = min(final_pop, key=lambda x: toolbox.fitness(x).mofit)
        solution = {MAPPING_SPECIE: list(zip(sorted_tasks, best)), ORDERING_SPECIE: sorted_tasks}
        schedule = build_schedule(_wf, estimator, rm, solution)
        Utility.validate_static_schedule(_wf, schedule)
        makespan = Utility.makespan(schedule)
        print("Final makespan: {0}".format(makespan))

        pass
Пример #10
0
    def __call__(self):

        toolbox, stats, logbook = self.toolbox(), self.stats(), self.logbook()
        _wf, rm, estimator = self.env()
        heft_schedule = self.heft_schedule()

        pop, log, best = run_gsa(toolbox=toolbox,
                                 logbook=logbook,
                                 statistics=stats,
                                 n=self.N,
                                 iter_number=self.GEN,
                                 kbest=self.KBEST,
                                 ginit=self.G)

        schedule = build_schedule(_wf, rm, estimator, best)

        Utility.validate_static_schedule(_wf, schedule)
        makespan = Utility.makespan(schedule)
        print("Final makespan: {0}".format(makespan))
        print("Heft makespan: {0}".format(Utility.makespan(heft_schedule)))
        return makespan
Пример #11
0
    def __call__(self):

        toolbox, stats, logbook = self.toolbox(), self.stats(), self.logbook()
        _wf, rm, estimator = self.env()
        heft_schedule = self.heft_schedule()

        pop, log, best = run_pso(
            toolbox=toolbox,
            logbook=logbook,
            stats=stats,
            gen_curr=0, gen_step=self.GEN, invalidate_fitness=True, initial_pop=None,
            w=self.W, c1=self.C1, c2=self.C2, n=self.N,
        )

        schedule = build_schedule(_wf, rm, estimator,  best)

        Utility.validate_static_schedule(_wf, schedule)
        makespan = Utility.makespan(schedule)
        print("Final makespan: {0}".format(makespan))
        print("Heft makespan: {0}".format(Utility.makespan(heft_schedule)))
        return makespan
Пример #12
0
def do_exp():

    pop, log, best = run_pso(
        toolbox=toolbox,
        logbook=logbook,
        stats=stats,
        gen_curr=0, gen_step=GEN, invalidate_fitness=True, initial_pop=None,
        w=W, c1=C1, c2=C2, n=N,
    )



    best_position = best.entity
    solution = construct_solution(best_position, sorted_tasks)
    schedule = build_schedule(_wf, estimator, rm, solution)

    Utility.validate_static_schedule(_wf, schedule)

    makespan = Utility.makespan(schedule)
    print("Final makespan: {0}".format(makespan))
    print("Heft makespan: {0}".format(Utility.makespan(heft_schedule)))
    return makespan
Пример #13
0
    def __call__(self):

        toolbox, stats, logbook = self.toolbox(), self.stats(), self.logbook()
        _wf, rm, estimator = self.env()
        heft_schedule = self.heft_schedule()

        pop, log, best = run_gsa(
            toolbox=toolbox,
            logbook=logbook,
            statistics=stats,
            pop_size=self.N,
            iter_number=self.GEN,
            kbest=self.KBEST,
            ginit=self.G
        )

        schedule = build_schedule(_wf, rm, estimator,  best)

        Utility.validate_static_schedule(_wf, schedule)
        makespan = Utility.makespan(schedule)
        print("Final makespan: {0}".format(makespan))
        print("Heft makespan: {0}".format(Utility.makespan(heft_schedule)))
        return makespan
Пример #14
0
 def _validate(self, wf, estimator, schedule):
      max_makespan = Utility.makespan(schedule)
      seq_time_validaty = Utility.validateNodesSeq(schedule)
      sched = deepcopy(schedule)
      mark_finished(sched)
      Utility.validate_static_schedule(wf, schedule)
Пример #15
0
 def _validate(self, wf, estimator, schedule):
     max_makespan = Utility.makespan(schedule)
     seq_time_validaty = Utility.validateNodesSeq(schedule)
     sched = deepcopy(schedule)
     mark_finished(sched)
     Utility.validate_static_schedule(wf, schedule)