def run_SPEA2(SIR_name, version, test_size): evaluator = evaluation.VEval(SIR_name, version, test_size) dim = test_size population = GA.initial_genes(dim, GLOB.POP) archive = [] population_history = [population] archive_history = [archive] if GLOB.DEBUG: print('0', len(population)) for i in range(GLOB.MAX_IT): #update union = population + archive GA.evaluate(union, evaluator) get_fitness(union) archive = select(union) population = GA.crossover(archive)[GLOB.POP + 1:] if GLOB.DEBUG: print(i, len(population)) #save history population_history.append(population) archive_history.append(archive) first_pareto = get_first_pareto(archive) #final result return first_pareto
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
def run_TAEA(SIR_name, version, test_size): evaluator = evaluation.VEval(SIR_name, version, test_size) dim = test_size population = GA.initial_genes(dim, GLOB.POP,version) population_history = [population] CA, DA = [], [] #covergence archive, diversity archive GA.evaluate(population,evaluator) if GLOB.DEBUG: print('0', 0) for i in range(GLOB.MAX_IT): CA, DA = collect_non_dominated(population,CA,DA) #print(len(CA), len(DA)) population = new_crossover(CA,DA,GLOB.CROSSOVER_RATE,1/test_size) GA.evaluate(population,evaluator) if GLOB.DEBUG: print(i,len(CA+DA), 'covergence archive size', len(CA), 'divergence archive size', len(DA)) return CA+DA
def get_APFDc(): #moea and greedy for SIR_name in GLOB.TEST_PGM: directory = GLOB.RESULT_DIRECTORY + SIR_name + '/' for version in range(GLOB.NUM_VERSIONS[SIR_name]): evaluator = veval.VEval(SIR_name, version + 1, GLOB.NUM_TESTCASES[SIR_name], MOEA=False) for MOEA in GLOB.TRY_ALGORITHM + GLOB.TRY_GALGORITHM: sequences = [] APFDc = [] for i in range(GLOB.TRIALS_PER_VERSION): fname = 'seq_' + SIR_name + '_version' + str( version + 1) + '_' + MOEA + '_trial' + str(i) + '.csv' with open(directory + fname, 'r') as f: rdr = csv.reader(f) for line in rdr: for j in range(len(line)): line[j] = int(line[j]) sequences.append(line) if MOEA in GLOB.TRY_GALGORITHM: break for seq in sequences: APFDc.append(evaluator.eval(seq)) mean = sum(APFDc) / len(APFDc) std = np.array(APFDc).std() maximum = max(APFDc) fname = 'APFDc_' + SIR_name + '_version' + str( version + 1) + '_' + MOEA + '.csv' with open(GLOB.RESULT_DIRECTORY + 'Indicator/' + fname, 'w', newline='') as f: wr = csv.writer(f) wr.writerow(['mean', 'std', 'max']) wr.writerow([mean, std, maximum]) wr.writerow(APFDc) print('finish to write', fname) #hybrid for SIR_name in GLOB.TEST_PGM: directory = GLOB.RESULT_DIRECTORY + SIR_name + '_hybrid/' for version in range(GLOB.NUM_VERSIONS[SIR_name]): evaluator = veval.VEval(SIR_name, version + 1, GLOB.NUM_TESTCASES[SIR_name], MOEA=False) for MOEA in GLOB.TRY_ALGORITHM: sequences = [] APFDc = [] for i in range(GLOB.TRIALS_PER_VERSION): fname = 'seq_' + SIR_name + '_version' + str( version + 1) + '_' + MOEA + '_trial' + str(i) + '.csv' with open(directory + fname, 'r') as f: rdr = csv.reader(f) for line in rdr: for j in range(len(line)): line[j] = int(line[j]) sequences.append(line) if MOEA in GLOB.TRY_GALGORITHM: break for seq in sequences: APFDc.append(evaluator.eval(seq)) mean = sum(APFDc) / len(APFDc) std = np.array(APFDc).std() maximum = max(APFDc) fname = 'APFDc_' + SIR_name + '_version' + str( version + 1) + '_' + MOEA + '_hybrid.csv' with open(GLOB.RESULT_DIRECTORY + 'Indicator/' + fname, 'w', newline='') as f: wr = csv.writer(f) wr.writerow(['mean', 'std', 'max']) wr.writerow([mean, std, maximum]) wr.writerow(APFDc) print('finish to write', fname)