def optimal_panels_battery_multi(Ce, Cv, Cp, Cb, Vp, Vb, demand, irradiance, xp_min): energy_building = EnergyBuildingMulti(irradiance, demand, N, Ce, Cv, qinit, Cb, Vb, Cp, Vp, xp_min) algorithm = NSGAII( problem=energy_building, population_size=100, offspring_population_size=100, mutation=PolynomialMutation(probability=1.0 / problem.number_of_variables, distribution_index=20), crossover=SBXCrossover(probability=1.0, distribution_index=20), termination_criterion=StoppingByEvaluations(max_evaluations=25000)) algorithm.run() solutions = algorithm.get_result() for solution in solutions: #print('Solution:',solution.variables, 'Maximum value:',solution.objectives[0]) Xp = solution.variables[0] Xb = solution.variables[1] C = solution.objectives[0] print(f'Xp {Xp}, Xb {Xb}, Cost {C}') return Xb, Xp, C, algorithm
def psp_test(): path = '/home/thinkpad/Documents/jemoa/src/main/resources/instances/psp/o4p25_0.txt' psp_instance = PspInstance() psp_instance.read_(path) max_evaluations = 50000 binary_string_length = psp_instance.n_var problem = PortfolioSocialProblem(psp_instance) algorithm = NSGAII( problem=problem, population_size=100, offspring_population_size=100, mutation=BitFlipMutation(probability=1.0 / binary_string_length), crossover=SPXCrossover(probability=1.0), termination_criterion=StoppingByEvaluations(max_evaluations=max_evaluations), dominance_comparator=DominanceComparator() ) progress_bar = ProgressBarObserver(max=max_evaluations) algorithm.observable.register(progress_bar) algorithm.run() front = algorithm.get_result() for s in front: s.objectives = [-1 * obj for obj in s.objectives] # Save results to file # print_function_values_to_file(front, 'FUN.' + algorithm.get_name() + "-" + problem.get_name()) print_solutions_to_file(front, DIRECTORY_RESULTS + 'SOLUTIONS.' + algorithm.get_name() + "-" + problem.get_name()) print('Algorithm (continuous problem): ' + algorithm.get_name()) print('Problem: ' + problem.get_name()) print('Computing time: ' + str(algorithm.total_computing_time))
read_solutions, ) from jmetal.util.termination_criterion import StoppingByEvaluations if __name__ == "__main__": problem = Srinivas() problem.reference_front = read_solutions( filename="resources/reference_front/Srinivas.pf") max_evaluations = 25000 algorithm = NSGAII( problem=problem, population_size=100, offspring_population_size=100, mutation=PolynomialMutation(probability=1.0 / problem.number_of_variables, distribution_index=20), crossover=SBXCrossover(probability=1.0, distribution_index=20), termination_criterion=StoppingByEvaluations( max_evaluations=max_evaluations), dominance_comparator=DominanceComparator(), ) algorithm.run() front = algorithm.get_result() # Save results to file print_function_values_to_file(front, "FUN." + algorithm.label) print_variables_to_file(front, "VAR." + algorithm.label) print(f"Algorithm: {algorithm.get_name()}") print(f"Problem: {problem.get_name()}")
from jmetal.algorithm.multiobjective import NSGAII from jmetal.operator import SBXCrossover, PolynomialMutation from jmetal.problem import ZDT1 from jmetal.util.termination_criterion import StoppingByEvaluations problem = ZDT1() algorithm = NSGAII( problem=problem, population_size=100, offspring_population_size=100, mutation=PolynomialMutation(probability=1.0 / problem.number_of_variables, distribution_index=20), crossover=SBXCrossover(probability=1.0, distribution_index=20), termination_criterion=StoppingByEvaluations(max_evaluations=25000)) algorithm.run()
if __name__ == '__main__': # Problem set problem = llvmMultiobjetiveProblem( max_epochs=config_max_epochs, population_size=config_population_size, offspring_population_size=config_offspring_population_size, solution_length=config_solution_length, verbose=config_verbose) # Algorithm set algorithm = NSGAII( problem=problem, population_size=config_population_size, offspring_population_size=config_offspring_population_size, mutation=IntegerPolynomialMutation(config_probability_mutation), crossover=SBXCrossover(config_probability_crossover), selection=RandomSolutionSelection(), termination_criterion=problem) algorithm.run() nds = get_non_dominated_solutions(algorithm.get_result()) with open(f"{problem.config_to_str()}_results.csv", "w") as file: for sol in nds: file.write(f'{sol.variables};{sol.objectives}\n') with open(f"{problem.config_to_str()}_results.data", "w") as file: #Outputs file.write('\nSettings:')