/** * It launches the algorithm * * @param confFile String it is the filename of the configuration file. */ public void execute(String confFile) { parameters = new parseParameters(); parameters.parseConfigurationFile(confFile); Algorithm method = new Algorithm(parameters); method.execute(); }
public static void main(String[] args) throws JMException, ClassNotFoundException { Problem problem; // The problem to solve Algorithm algorithm; // The algorithm to use Operator crossover; // Crossover operator Operator mutation; // Mutation operator Operator selection; // Selection operator // int bits ; // Length of bit string in the OneMax problem // bits = 512 ; // problem = new OneMax(bits); problem = new Sphere("Real", 20); // problem = new Easom("Real") ; // problem = new Griewank("Real", 10) ; algorithm = new DE(problem); // Asynchronous cGA /* Algorithm parameters*/ algorithm.setInputParameter("populationSize", 100); algorithm.setInputParameter("maxEvaluations", 1000000); // Crossover operator crossover = CrossoverFactory.getCrossoverOperator("DifferentialEvolutionCrossover"); crossover.setParameter("CR", 0.1); crossover.setParameter("F", 0.5); crossover.setParameter("DE_VARIANT", "rand/1/bin"); // Add the operators to the algorithm selection = SelectionFactory.getSelectionOperator("DifferentialEvolutionSelection"); algorithm.addOperator("crossover", crossover); algorithm.addOperator("selection", selection); /* Execute the Algorithm */ long initTime = System.currentTimeMillis(); SolutionSet population = algorithm.execute(); long estimatedTime = System.currentTimeMillis() - initTime; System.out.println("Total execution time: " + estimatedTime); /* Log messages */ System.out.println("Objectives values have been writen to file FUN"); population.printObjectivesToFile("FUN"); System.out.println("Variables values have been writen to file VAR"); population.printVariablesToFile("VAR"); } // main
/** @param args the command line arguments -- modelname, alg_name, evaluation_times, [runid] */ public static void main(String[] args) throws Exception { try { String name = args[0]; URL location = Main.class.getProtectionDomain().getCodeSource().getLocation(); String loc = location.toString(); String project_path = loc.substring(5, loc.lastIndexOf("SPL/")) + "SPL/"; // with '/' at the end String fm = project_path + "dimacs_data/" + name + ".dimacs"; String augment = fm + ".augment"; String dead = fm + ".dead"; String mandatory = fm + ".mandatory"; String seed = fm + ".richseed"; String opfile = fm + ".sipop"; Problem p = new ProductLineProblem(fm, augment, mandatory, dead, seed); // Problem p = new ProductLineProblemNovelPrep(fm, augment, mandatory, dead, seed, // opfile); // GroupedProblem.grouping((ProductLineProblem) p, 100); System.exit(0); Algorithm a; int evaluation_times = Integer.parseInt(args[2]); String alg_name = args[1]; String runid = ""; if (args.length >= 4) { runid = args[3]; } switch (alg_name) { case "IBEA": a = new SPL_SettingsIBEA(p).configureICSE2013(evaluation_times); break; case "SIPIBEA": a = new SPL_SettingsIBEA(p).configureSIPIBEA(evaluation_times); break; case "SPEA2": a = new SPL_SettingsEMOs(p).configureSPEA2(evaluation_times); break; case "NSGA2": a = new SPL_SettingsEMOs(p).configureNSGA2(evaluation_times); break; case "IBEASEED": a = new SPL_SettingsIBEA(p).configureIBEASEED(evaluation_times); break; case "SATIBEA": // a = new SPL_SettingsIBEA(p).configureICSE15(1000, fm, ((ProductLineProblem) // p).getNumFeatures(), // ((ProductLineProblem) p).getConstraints()); a = new SPL_SettingsIBEA(p) .configureSATIBEA( evaluation_times, fm, ((ProductLineProblem) p).getNumFeatures(), ((ProductLineProblem) p).getConstraints()); break; default: a = new SPL_SettingsIBEA(p).configureICSE2013(evaluation_times); } long start = System.currentTimeMillis(); SolutionSet pop = a.execute(); float total_time = (System.currentTimeMillis() - start) / 1000.0f; String file_tag = name + "_" + alg_name + '_' + evaluation_times / 1000 + "k_" + runid + ".txt"; String file_path = project_path + "j_res/" + file_tag; File file = new File(file_path); if (!file.exists()) { file.createNewFile(); } FileWriter fw = new FileWriter(file.getAbsoluteFile()); BufferedWriter bw = new BufferedWriter(fw); for (int i = 0; i < pop.size(); i++) { Variable v = pop.get(i).getDecisionVariables()[0]; bw.write((Binary) v + "\n"); System.out.println("Conf" + (i + 1) + ": " + (Binary) v + " "); } bw.write("~~~\n"); for (int i = 0; i < pop.size(); i++) { Variable v = pop.get(i).getDecisionVariables()[0]; for (int j = 0; j < pop.get(i).getNumberOfObjectives(); j++) { bw.write(pop.get(i).getObjective(j) + " "); System.out.print(pop.get(i).getObjective(j) + " "); } bw.write("\n"); System.out.println(""); } System.out.println(total_time); bw.write("~~~\n" + total_time + "\n"); bw.close(); fw.close(); } catch (Exception e) { e.printStackTrace(); } }
/** * @param args Command line arguments. The first (optional) argument specifies the problem to * solve. * @throws JMException * @throws IOException * @throws SecurityException Usage: three options - jmetal.metaheuristics.mocell.MOCell_main - * jmetal.metaheuristics.mocell.MOCell_main problemName - * jmetal.metaheuristics.mocell.MOCell_main problemName ParetoFrontFile */ public static void main(String[] args) throws JMException, IOException, ClassNotFoundException { Problem problem; // The problem to solve Algorithm algorithm; // The algorithm to use Operator mutation; // Mutation operator QualityIndicator indicators; // Object to get quality indicators // Logger object and file to store log messages logger_ = Configuration.logger_; fileHandler_ = new FileHandler("PAES_main.log"); logger_.addHandler(fileHandler_); indicators = null; if (args.length == 1) { Object[] params = {"Real"}; problem = (new ProblemFactory()).getProblem(args[0], params); } // if else if (args.length == 2) { Object[] params = {"Real"}; problem = (new ProblemFactory()).getProblem(args[0], params); indicators = new QualityIndicator(problem, args[1]); } // if else { // Default problem problem = new Kursawe("ArrayReal", 3); // problem = new Fonseca("Real"); // problem = new Kursawe("BinaryReal",3); // problem = new Water("Real"); // problem = new ZDT4("Real", 1000); // problem = new WFG1("Real"); // problem = new DTLZ1("Real"); // problem = new OKA2("Real") ; } // else algorithm = new PAES(problem); // Algorithm parameters algorithm.setInputParameter("archiveSize", 100); algorithm.setInputParameter("biSections", 5); algorithm.setInputParameter("maxEvaluations", 25000); // Mutation (Real variables) mutation = MutationFactory.getMutationOperator("PolynomialMutation"); mutation.setParameter("probability", 1.0 / problem.getNumberOfVariables()); mutation.setParameter("distributionIndex", 20.0); // Mutation (BinaryReal variables) // mutation = MutationFactory.getMutationOperator("BitFlipMutation"); // mutation.setParameter("probability",0.1); // Add the operators to the algorithm algorithm.addOperator("mutation", mutation); // Execute the Algorithm long initTime = System.currentTimeMillis(); SolutionSet population = algorithm.execute(); long estimatedTime = System.currentTimeMillis() - initTime; // Result messages // STEP 8. Print the results logger_.info("Total execution time: " + estimatedTime + "ms"); logger_.info("Variables values have been writen to file VAR"); population.printVariablesToFile("VAR"); logger_.info("Objectives values have been writen to file FUN"); population.printObjectivesToFile("FUN"); if (indicators != null) { logger_.info("Quality indicators"); logger_.info("Hypervolume: " + indicators.getHypervolume(population)); logger_.info("GD : " + indicators.getGD(population)); logger_.info("IGD : " + indicators.getIGD(population)); logger_.info("Spread : " + indicators.getSpread(population)); logger_.info("Epsilon : " + indicators.getEpsilon(population)); } // if } // main
/** * @param args Command line arguments. * @throws JMException * @throws IOException * @throws SecurityException Usage: three choices - jmetal.metaheuristics.nsgaII.NSGAII_main - * jmetal.metaheuristics.nsgaII.NSGAII_main problemName - * jmetal.metaheuristics.nsgaII.NSGAII_main problemName paretoFrontFile */ public static void main(String[] args) throws JMException, IOException, ClassNotFoundException { Problem problem; // The problem to solve Algorithm algorithm; // The algorithm to use Operator crossover; // Crossover operator Operator mutation; // Mutation operator Operator selection; // Selection operator QualityIndicator indicators; // Object to get quality indicators // Logger object and file to store log messages logger_ = Configuration.logger_; fileHandler_ = new FileHandler("IBEA.log"); logger_.addHandler(fileHandler_); indicators = null; if (args.length == 1) { Object[] params = {"Real"}; problem = (new ProblemFactory()).getProblem(args[0], params); } // if else if (args.length == 2) { Object[] params = {"Real"}; problem = (new ProblemFactory()).getProblem(args[0], params); indicators = new QualityIndicator(problem, args[1]); } // if else { // Default problem problem = new Kursawe("Real", 3); // problem = new Kursawe("BinaryReal", 3); // problem = new Water("Real"); // problem = new ZDT1("ArrayReal", 100); // problem = new ConstrEx("Real"); // problem = new DTLZ1("Real"); // problem = new OKA2("Real") ; } // else algorithm = new IBEA(problem); // Algorithm parameters algorithm.setInputParameter("populationSize", 100); algorithm.setInputParameter("archiveSize", 100); algorithm.setInputParameter("maxEvaluations", 25000); // Mutation and Crossover for Real codification crossover = CrossoverFactory.getCrossoverOperator("SBXCrossover"); crossover.setParameter("probability", 1.0); crossover.setParameter("distribuitionIndex", 20.0); mutation = MutationFactory.getMutationOperator("PolynomialMutation"); mutation.setParameter("probability", 1.0 / problem.getNumberOfVariables()); mutation.setParameter("distributionIndex", 20.0); /* Mutation and Crossover Binary codification */ /* crossover = CrossoverFactory.getCrossoverOperator("SinglePointCrossover"); crossover.setParameter("probability",0.9); mutation = MutationFactory.getMutationOperator("BitFlipMutation"); mutation.setParameter("probability",1.0/80); */ /* Selection Operator */ selection = new BinaryTournament(new FitnessComparator()); // Add the operators to the algorithm algorithm.addOperator("crossover", crossover); algorithm.addOperator("mutation", mutation); algorithm.addOperator("selection", selection); // Execute the Algorithm long initTime = System.currentTimeMillis(); SolutionSet population = algorithm.execute(); long estimatedTime = System.currentTimeMillis() - initTime; // Print the results logger_.info("Total execution time: " + estimatedTime + "ms"); logger_.info("Variables values have been writen to file VAR"); population.printVariablesToFile("VAR"); logger_.info("Objectives values have been writen to file FUN"); population.printObjectivesToFile("FUN"); if (indicators != null) { logger_.info("Quality indicators"); logger_.info("Hypervolume: " + indicators.getHypervolume(population)); logger_.info("GD : " + indicators.getGD(population)); logger_.info("IGD : " + indicators.getIGD(population)); logger_.info("Spread : " + indicators.getSpread(population)); logger_.info("Epsilon : " + indicators.getEpsilon(population)); } // if } // main