Esempio n. 1
0
def get_first_pareto(pop):
    '''
    get only first pareto

    :param pop:
    :return:
    '''
    return GA.get_pareto(pop)[0]
Esempio n. 2
0
def run_NSGA3(input_fname):
    modify = modifier.modify_testcase(input_fname)
    dim = modify.get_datasize()
    reference = get_ref()

    population = GA.initial_genes(dim,GLOB.POP)
    population_history = [population]
    for i in range(GLOB.MAX_IT):
        new_pop = GA.crossover(population)
        GA.evaluate(new_pop,modify)
        pareto = GA.get_pareto(new_pop)
        new_pop = select(pareto)
        population = new_pop
        population_history.append(population)

    first_pareto = get_first_pareto(population) #final result
def read_file(SIR_name, version):
    '''
    Read files in Result directory and get data
    return data by each MOEA and trial
    return reference points for the specific SIR program and version

    data: dictionary, key = MOEA value = 2D array.
          first dimension for each trial
          second dimension for data
          ex) dict['NSGA2'] = [[pt1,pt2, ...], [pt100,pt101, ...], ...]
              each pt = [evaluation metric1, metric2, metric3, ...]

    ref_pt: array.
            ex) ref_pt = [pt1, pt2, pt3, ...]
            each pt = [evaluation metric1, metric2, metric3, ...]

    :param SIR_name:  String, SIR program name
    :param version:   int, version of SIR program
    :return:
    '''
    directory = GLOB.RESULT_DIRECTORY + SIR_name + '/'
    data = dict()
    ref_pt = []

    for MOEA in GLOB.TRY_ALGORITHM:
        data_moea = [[] for i in range(GLOB.TRIALS_PER_VERSION)]
        for i in range(GLOB.TRIALS_PER_VERSION):
            fname = 'eval_' + SIR_name + '_version' + str(version) + '_' + MOEA + '_trial' + str(i) + '.csv'
            with open(directory + fname, 'r') as f:
                f.readline()
                rdr = csv.reader(f)
                for line in rdr:
                    for j in range(len(line)):
                        line[j] = float(line[j])
                    data_moea[i].append(np.array(line))
                    gene = GA.Gene_Info(None)
                    gene.set_eval(np.array(line))
                    ref_pt.append(gene)

            ref_pt = GA.get_pareto(ref_pt)[0] #update reference point
        data[MOEA] = data_moea

    for i in range(len(ref_pt)):
        ref_pt[i] = ref_pt[i].get_eval()

    return data, ref_pt
Esempio n. 4
0
def run_NSGA2(SIR_name, version, test_size):
    evaluator = evaluation.VEval(SIR_name, version, test_size)
    dim = test_size
    population = GA.initial_genes(dim, GLOB.POP, version)
    if GLOB.DEBUG:
        print('0', len(population))
    population_history = [population]
    for i in range(GLOB.MAX_IT):
        new_pop = GA.crossover(population, mr=1 / dim)
        GA.evaluate(new_pop, evaluator)
        pareto = GA.get_pareto(new_pop)
        new_pop = select(pareto)
        population = new_pop
        population_history.append(population)
        if GLOB.DEBUG:
            print(i, len(population))

    first_pareto = get_first_pareto(population)  #final result
    return first_pareto