Esempio n. 1
0
    def __call__(self):

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

        wf_dag = HeftHelper.convert_to_parent_children_map(_wf)
        jobs = set(wf_dag.keys()) | set(x for xx in wf_dag.values() for x in xx)
        nodes = rm.get_nodes()
        mapMatrix = rd.initMapMatrix(jobs, nodes, estimator)
        rankList = rd.initRankList(wf_dag, nodes, estimator)
        ordFilter = rd.filterList(_wf)

        toolbox = self.toolbox(mapMatrix, rankList, ordFilter)

        pop, log, best = rd.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, rm=rm, wf=_wf, estimator=estimator, mapMatrix=mapMatrix, rankList=rankList, ordFilter=ordFilter,
        )

        schedule = rd_order.build_schedule(_wf, rm, estimator,  best, mapMatrix, rankList, ordFilter)

        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
Esempio n. 2
0
    def mapping(self, sorted_jobs, existing_plan, live_nodes, commcost,
                compcost):
        """def allocate(job, orders, jobson, prec, compcost, commcost):"""
        """ Allocate job to the machine with earliest finish time

        Operates in place
        """

        ## TODO: add finished tasks
        jobson = dict()
        for (node, items) in existing_plan.items():
            for item in items:
                if item.state == ScheduleItem.FINISHED or item.state == ScheduleItem.EXECUTING:
                    jobson[item.job] = node

        new_plan = existing_plan

        def ft(machine):
            #cost = st(machine)
            runtime = compcost(task, machine)
            cost = st(machine, runtime) + runtime
            ##print("machine: %s job:%s cost: %s" % (machine.name, task.id, cost))
            ##print("machine: " + str(machine.name) + " cost: " + str(cost))

            return cost

        if len(live_nodes) != 0:
            ## in case if there is not any live nodes we just return the same cleaned schedule
            for wf, tasks in sorted_jobs:
                ##wf_dag = self.convert_to_parent_children_map(wf)
                wf_dag = HeftHelper.convert_to_parent_children_map(wf)
                prec = reverse_dict(wf_dag)
                for task in tasks:
                    st = partial(self.start_time, wf, task, new_plan, jobson,
                                 prec, commcost)

                    # ress = [(key, ft(key)) for key in new_plan.keys()]
                    # agent_pair = min(ress, key=lambda x: x[1][0])
                    # agent = agent_pair[0]
                    # start = agent_pair[1][0]
                    # end = agent_pair[1][1]

                    # agent = min(new_plan.keys(), key=ft)
                    agent = min(live_nodes, key=ft)
                    runtime = compcost(task, agent)
                    start = st(agent, runtime)
                    end = ft(agent)

                    # new_plan[agent].append(ScheduleItem(task, start, end))
                    Schedule.insert_item(new_plan, agent,
                                         ScheduleItem(task, start, end))

                    jobson[task] = agent

        new_sched = Schedule(new_plan)
        return new_sched
Esempio n. 3
0
def filterList(wf):
    wf_dag = HeftHelper.convert_to_parent_children_map(wf)
    jobs = set(wf_dag.keys()) | set(x for xx in wf_dag.values() for x in xx)
    resultFilter = {job.id:{j.id for j in jobs} for job in jobs}
    headTask = wf.head_task
    ready = dict()
    readyParents = dict()
    for task in headTask.children:
        getTaskChildFilter(task, resultFilter, ready)
    for task in jobs:
        getTaskParentFilter(task, resultFilter, readyParents)
    return resultFilter