Exemplo n.º 1
0
    def do_it(self, ngen, cxpb, mutpb):
        pop = self.toolbox.population(n=self.no_list)

        #inital calculation of fitness for base population. TODO: Optimization. InitialFitness can be taken from the Job Object itself.
        fitness = self.toolbox.map(self.toolbox.evaluate, pop)
        for ind, fit in zip(pop, fitness):
            ind.fitness.values = fit

        best = [copy.deepcopy(ind) for ind in pop]
        for g in range(ngen):
            Logger.info("ListGA Generation: %s" % (g))

            best = select(pop, self.no_list)
            record = self.stats.compile(best)
            self.logbook.record(**record)
            pop = [copy.deepcopy(ind) for ind in best]

            for child1, child2 in zip(pop[::2], pop[1::2]):
                if random.random() < cxpb:
                    crossover(child1, child2)
                    del child1.fitness.values, child2.fitness.values
            for mutant in pop:
                mutate(mutant, mutpb)

            #TODO: Perform double justification here
            for ind in best:
                if not ind in pop:
                    pop.append(ind)
            #invalids = [ind for ind in pop if not ind.fitness.valid]
            fitnesses = self.toolbox.map(self.toolbox.evaluate, pop)
            for ind, fit in zip(pop, fitnesses):
                if fit is not None:
                    ind.fitness.values = fit

        return select(pop, n=1)
Exemplo n.º 2
0
def visualize(simulation_result):
    resource_frequency = {}
    for task in simulation_result.execution_history:
        if task.finished - task.started == 0:
            continue
        for resource in task.usedResources:
            if resource.max_share_count is not 0:
                if not resource in resource_frequency:
                    resource_frequency[resource] = 0
                resource_frequency[resource] += 1
    top_resources = []
    for resource, frequency in resource_frequency.items():
        top_resources.append((resource, frequency))

    top_resources.sort(key=lambda tup: tup[1], reverse=True)
    Logger.info("Top required Resources:")

    for resource in top_resources[:10]:
        Logger.info("name: '%s', is testbed: %s, frequency: %s" % (resource[0].name, resource[0].is_testbed, resource[1]))

    fig = plt.figure(figsize=(30, 25))

    ax1 = fig.add_subplot(211)
    plot_gantt(simulation_result, top_resources[:7], ax1)

    ax2 = fig.add_subplot(212)
    plot_gantt(simulation_result, top_resources[:7], ax2)
    ax2.set_xscale('log')

    return ax1, ax2
Exemplo n.º 3
0
def visualize(simulation_result):
    resource_frequency = {}
    for task in simulation_result.execution_history:
        if task.finished - task.started == 0:
            continue
        for resource in task.usedResources:
            if resource.max_share_count is not 0:
                if not resource in resource_frequency:
                    resource_frequency[resource] = 0
                resource_frequency[resource] += 1
    top_resources = []
    for resource, frequency in resource_frequency.items():
        top_resources.append((resource, frequency))

    top_resources.sort(key=lambda tup: tup[1], reverse=True)
    Logger.info("Top required Resources:")

    for resource in top_resources[:10]:
        Logger.info("name: '%s', is testbed: %s, frequency: %s" %
                    (resource[0].name, resource[0].is_testbed, resource[1]))

    fig = plt.figure(figsize=(30, 25))

    ax1 = fig.add_subplot(211)
    plot_gantt(simulation_result, top_resources[:7], ax1)

    ax2 = fig.add_subplot(212)
    plot_gantt(simulation_result, top_resources[:7], ax2)
    ax2.set_xscale('log')

    return ax1, ax2
Exemplo n.º 4
0
    def initialize(self):
        super(PPPolicies, self).initialize()
        Logger.info("Generating initial Population with RBRS")
        initial_pop = self._generate_RBRS(self.job, self.param["listNoList"])
        Logger.info("Applying ListGA to initial population")
        listGA = ListGA(self.job, initial_pop)
        task_list = listGA.do_it(self.param["listGAGen"],
                                 self.param["listGACXp"],
                                 self.param["listGAMUTp"])[0]
        self.listGALog = listGA.get_logbook()
        if self.param["arcGAGen"] > 0:
            arcGA = ArcGA(self.job, task_list)
            arc_list = arcGA.do_it(self.param["arcGAGen"],
                                   self.param["arcGACXp"],
                                   self.param["arcGAMUTp"])[0]  #2, 0.5, 0.1
            #Logger.warning("len arc list: %s" % (len(arc_list)))
            self.arcGALog = arcGA.get_logbook()

            self.scheduler = MfssRB(self.job,
                                    task_list,
                                    arc_list,
                                    ignore_infeasible_schedules=True)
        else:
            self.arcGALog = []
            self.arcGALog.append({"min": 0, "max": 0})

            self.scheduler = MfssRB(self.job,
                                    task_list, [],
                                    ignore_infeasible_schedules=True)
Exemplo n.º 5
0
    def initialize(self):
        super(JFPol, self).initialize()
        Logger.info("Generating initial Population with RBRS")
        initial_pop = self._generate_RBRS(self.job, 10)
        Logger.info("Applying ListGA to initial population")
        listGA = ListGA(self.job, initial_pop)
        task_list = listGA.do_it(150, 0.8, 0.2)[0]
        self.listGALog = listGA.get_logbook()

        self.scheduler = DomainRB(self.job, task_list,  ignore_infeasible_schedules=True)
Exemplo n.º 6
0
def deserialize(file_path):
    Logger.info("loading data from file: %s" % file_path)
    job = cPickle.load(open(file_path, "rb"))
    Logger.info("loaded %s tasks" % (len(job.tasks.values())))
    Logger.info("loaded %s resources" % (len(job.resources.values())))
    Logger.info("loaded %s capabilities"  % (len(job.capabilities.values())))

    return job
Exemplo n.º 7
0
def deserialize(file_path):
    Logger.info("loading data from file: %s" % file_path)
    job = cPickle.load(open(file_path, "rb"))
    Logger.info("loaded %s tasks" % (len(job.tasks.values())))
    Logger.info("loaded %s resources" % (len(job.resources.values())))
    Logger.info("loaded %s capabilities" % (len(job.capabilities.values())))

    return job
Exemplo n.º 8
0
    def initialize(self):
        super(PPPolicies, self).initialize()
        Logger.info("Generating initial Population with RBRS")
        initial_pop = self._generate_RBRS(self.job, self.param["listNoList"])
        Logger.info("Applying ListGA to initial population")
        listGA = ListGA(self.job, initial_pop)
        task_list = listGA.do_it(self.param["listGAGen"], self.param["listGACXp"], self.param["listGAMUTp"])[0]
        self.listGALog = listGA.get_logbook()
        if self.param["arcGAGen"] > 0:
            arcGA = ArcGA(self.job, task_list)
            arc_list = arcGA.do_it(self.param["arcGAGen"], self.param["arcGACXp"],self.param["arcGAMUTp"])[0] #2, 0.5, 0.1
            #Logger.warning("len arc list: %s" % (len(arc_list)))
            self.arcGALog = arcGA.get_logbook()

            self.scheduler = MfssRB(self.job, task_list, arc_list, ignore_infeasible_schedules=True)
        else:
            self.arcGALog = []
            self.arcGALog.append({"min":0, "max":0})

            self.scheduler = MfssRB(self.job, task_list, [], ignore_infeasible_schedules=True)
Exemplo n.º 9
0
    def do_it(self, ngen, cxpb, mutpb):
        pop = self.toolbox.population(n=self.no_list)

        #inital calculation of fitness for base population. TODO: Optimization. InitialFitness can be taken from the Job Object itself.
        fitness = self.toolbox.map(self.toolbox.evaluate, pop)
        for ind, fit in zip(pop, fitness):
            ind.fitness.values = fit

        best =  [copy.deepcopy(ind) for ind in pop]
        for g in range(ngen):
            Logger.info("ListGA Generation: %s" % (g))



            best = select(pop,self.no_list)
            record = self.stats.compile(best)
            self.logbook.record(**record)
            pop = [copy.deepcopy(ind) for ind in best]

            for child1, child2 in zip(pop[::2], pop[1::2]):
                    if random.random() < cxpb:
                        crossover(child1, child2)
                        del child1.fitness.values, child2.fitness.values
            for mutant in pop:
                    mutate(mutant, mutpb)

            #TODO: Perform double justification here
            for ind in best:
                if not ind in pop:
                    pop.append(ind)
            #invalids = [ind for ind in pop if not ind.fitness.valid]
            fitnesses = self.toolbox.map(self.toolbox.evaluate, pop)
            for ind, fit in zip(pop, fitnesses):
                if fit is not None:
                    ind.fitness.values = fit

        return select(pop, n=1)
Exemplo n.º 10
0
def worker(id, nr_cores, scheduler, job, n, return_values, extremes, parameters=None):
    os.system("taskset -p 0xFFFFFFFF %d" % os.getpid())
    pbar = ProgressBar(maxval=n).start()
    Logger.info("spawning worker id %s" % id)
    numpy.random.seed(id + int(time.time()))
    random.seed()
    #Logger.log_level = 2
    results = []
    min = None
    max = None
    if job.already_initialized == True:
        for task in job.tasks.values():
            size = len(task.pre_computed_execution_times) / nr_cores
            task.pre_computed_execution_times = task.pre_computed_execution_times[id*size:(id +1)*size]
    Scheduler = schedulerForName(scheduler) #gives us the correct class to use

    for i in range(0, n):
        if id == 0:
            pbar.update(i)

        scheduler = Scheduler(job, parameters)
        if job.already_initialized == False:
            job.initialize()
            scheduler.initialize()

        result = simulate_schedule(scheduler)
        results.append(result.total_time)
        if min is None or  result.total_time < min.total_time:
            min = result
        if max is None or  result.total_time > max.total_time:
            max = result

    return_values[id] = results
    extremes[id] = (min, max)
    if id == 0:
        pbar.finish()
Exemplo n.º 11
0
    def do_it(self, ngen, cxpb, mutpb):
        Logger.info("ArcGA: Creating Initial Population")
        pop = self.toolbox.population(n=self.no_p)
        Logger.info("ArcGA: Calculating base fitness")
        #inital calculation of fitness for base population.
        fitness = self.toolbox.map(self.toolbox.evaluate, pop)
        for ind, fit in zip(pop, fitness):
            if fit is not None:
                ind.fitness.values = fit

        best = [copy.deepcopy(ind) for ind in pop]
        for g in range(ngen):

            Logger.info("ArcGA Generation: %s" % (g))
            best = self.select(pop, self.no_p)
            record = self.stats.compile(best)
            self.logbook.record(**record)
            pop = [copy.deepcopy(ind) for ind in best]

            if random.random() < cxpb:
                self.crossover(pop, cxpb)


            for mutant in pop:
               if random.random() < mutpb:
                    self.mutate(mutant, 0.5)


            #invalids = [ind for ind in pop if not ind.fitness.valid]
            for ind in best:
                if not ind in pop:
                    pop.append(ind)

            fitnesses = self.toolbox.map(self.toolbox.evaluate, pop)
            for ind, fit in zip(pop, fitnesses):
                if fit is not None:
                    ind.fitness.values = fit

        best = self.select(pop, n=1)
        return best
Exemplo n.º 12
0
    def do_it(self, ngen, cxpb, mutpb):
        Logger.info("ArcGA: Creating Initial Population")
        pop = self.toolbox.population(n=self.no_p)
        Logger.info("ArcGA: Calculating base fitness")
        #inital calculation of fitness for base population.
        fitness = self.toolbox.map(self.toolbox.evaluate, pop)
        for ind, fit in zip(pop, fitness):
            if fit is not None:
                ind.fitness.values = fit

        best = [copy.deepcopy(ind) for ind in pop]
        for g in range(ngen):

            Logger.info("ArcGA Generation: %s" % (g))
            best = self.select(pop, self.no_p)
            record = self.stats.compile(best)
            self.logbook.record(**record)
            pop = [copy.deepcopy(ind) for ind in best]

            if random.random() < cxpb:
                self.crossover(pop, cxpb)

            for mutant in pop:
                if random.random() < mutpb:
                    self.mutate(mutant, 0.5)

            #invalids = [ind for ind in pop if not ind.fitness.valid]
            for ind in best:
                if not ind in pop:
                    pop.append(ind)

            fitnesses = self.toolbox.map(self.toolbox.evaluate, pop)
            for ind, fit in zip(pop, fitnesses):
                if fit is not None:
                    ind.fitness.values = fit

        best = self.select(pop, n=1)
        return best
Exemplo n.º 13
0
def load_simulation_result(file_path):
    Logger.info("loading simulation result from file: %s " % file_path)
    return cPickle.load(open(file_path, "rb"))
Exemplo n.º 14
0
def save_simulation_result(result, output_file):
    Logger.info("writing simulation result to file: %s" % output_file)
    cPickle.dump(result, open(output_file, "wb"))
Exemplo n.º 15
0
def load_simulation_result(file_path):
    Logger.info("loading simulation result from file: %s " % file_path )
    return cPickle.load(open(file_path, "rb"))
Exemplo n.º 16
0
def save_simulation_result(result, output_file):
    Logger.info("writing simulation result to file: %s" % output_file)
    cPickle.dump(result, open(output_file, "wb"))