def objective_functions(chro_str): pheno_type = BinaryChromosome.get_phenotype(chro_str) buildable, factory = utils.create_factory_from_pheno_type(pheno_type, production_line, False) factory.simulate(simulation_time) labor = factory.num_labor num_unit = factory.num_unit return np.array([-labor, num_unit])
def save_generation_info_to_excel(generation_dict, production_line, file_path, intialize=False): num_objective = MultiObjectiveAnalyzer.get_num_objective( generation_dict[1]) row_list = [] for num, generation, time in generation_dict.values(): for chromosome_info in generation: chro_list = [] chro_list.extend([num, time, chromosome_info[0]]) for idx in range(0, num_objective): chro_list.append(chromosome_info[1][idx]) pheno_info = BinaryChromosome.get_phenotype(chromosome_info[0]) cycle_time = utils.cycle_time_from_pheno_type(pheno_info) chro_list.append(cycle_time) row_list.append(chro_list) save_info_row = deepcopy(MultiObjectiveAnalyzer.basic_save_info_row) for idx in range(0, num_objective): save_info_row.append('objectvie' + str(idx + 1)) save_info_row.append('cycle_time') df = DataFrame(row_list, columns=save_info_row) with ExcelWriter(file_path, engine='xlsxwriter') as writer: df.to_excel(excel_writer=writer, sheet_name='result', header=True, index=False) return
def create_factory_from_chromosome(chromosome, production_line, initialize=False): pheno_type = BinaryChromosome.get_phenotype(chromosome) buildable, factory = utils.create_factory_from_pheno_type( pheno_type, production_line, initialize=initialize) return buildable, factory
def factory_build_check_2(chromosome, new_generation): check = True pheno_type = BinaryChromosome.get_phenotype(chromosome) cycle_time_idx = pheno_type['cycle_time'] if cycle_time_idx >= len(production_line.cycle_dict): return False buildable, factory = utils.create_factory_from_pheno_type(pheno_type, production_line, False) if not buildable: return buildable for chromosome_info in new_generation: chro_2 = chromosome_info[0] pheno_type_2 = BinaryChromosome.get_phenotype(chro_2) buildable, factory_2 = utils.create_factory_from_pheno_type(pheno_type_2, production_line, False) if factory == factory_2: check = False break return check
def factory_build_check(chromosome): pheno_type = BinaryChromosome.get_phenotype(chromosome) buildable, factory = utils.create_factory_from_pheno_type( pheno_type, production_line, False) return buildable
from moga.chromosome import BinaryChromosome from module_factory.optimization.analysis import MultiObjectiveAnalyzer from module_factory.component.production_line import ProductionLine from module_factory.optimization import utils from pandas import ExcelWriter, DataFrame import pickle # set BinaryChromosome from production line file production_line = ProductionLine('sample_data/production_line_200903.csv') geno_shape = utils.production_line_to_geno_shape(production_line) BinaryChromosome.set_geno_shape(**geno_shape) # set fitness check function def factory_build_check(chromosome): pheno_type = BinaryChromosome.get_phenotype(chromosome) buildable, factory = utils.create_factory_from_pheno_type( pheno_type, production_line, False) return buildable BinaryChromosome.fitted_in_geno_func_list.append(factory_build_check) with open('experiment/test.ge', 'rb') as f: generation_dict = pickle.load(f) ## evolution process to fig # MultiObjectiveAnalyzer.save_generation_info_to_excel(generation_dict, 'test_1.xlsx') # MultiObjectiveAnalyzer.save_evolution_process_to_fig(generation_dict, 'test.png') ## compare process to fig