Пример #1
0
  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
    HashMap parameters; // Operator parameters

    int threads = 4; // 0 - use all the available cores
    IParallelEvaluator parallelEvaluator = new MultithreadedEvaluator(threads);

    // problem = new Sphere("Real", 10) ;
    problem = new Griewank("Real", 10);

    algorithm = new pgGA(problem, parallelEvaluator); // Generational GA

    /* Algorithm parameters*/
    algorithm.setInputParameter("populationSize", 100);
    algorithm.setInputParameter("maxEvaluations", 2500000);

    // Mutation and Crossover for Real codification
    parameters = new HashMap();
    parameters.put("probability", 0.9);
    parameters.put("distributionIndex", 20.0);
    crossover = CrossoverFactory.getCrossoverOperator("SBXCrossover", parameters);

    parameters = new HashMap();
    parameters.put("probability", 1.0 / problem.getNumberOfVariables());
    parameters.put("distributionIndex", 20.0);
    mutation = MutationFactory.getMutationOperator("PolynomialMutation", parameters);

    /* Selection Operator */
    parameters = null;
    selection = SelectionFactory.getSelectionOperator("BinaryTournament", parameters);

    /* 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;
    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
Пример #2
0
  public static void main(String[] args) {
    try {
      Datos datos = Datos.cargarDatosDeArgs(args);

      String salidaFun = "SALIDA_FUN_GREEDY.txt";
      String salidaVar = "SALIDA_VAR_GREEDY.txt";

      if (args.length >= 7) {
        salidaFun = args[8];
      }

      if (args.length >= 8) {
        salidaVar = args[9];
      }

      System.out.println("---- Parametros a utilizar ----");
      System.out.println("Salidas: " + salidaFun + ", " + salidaVar);

      double[] params = {0.0, 0.05, 0.1, 0.15, 0.20, 0.25, 0.3, 0.35, 0.4, 0.45, 0.5};

      SolutionSet solSetGreedy = new SolutionSet(params.length);
      Problem problem = new Problema(datos);
      for (double p : params) {
        Permutation resultado = ejecutarGreedy(datos, p);
        Solution solucionGreedy = new Solution(problem, new Variable[] {resultado});

        problem.evaluateConstraints(solucionGreedy);
        problem.evaluate(solucionGreedy);

        solSetGreedy.add(solucionGreedy);

        // Imprimo y genero datos de la misma forma que el AE

        System.out.println("F1: " + solucionGreedy.getObjective(0));
        System.out.println("F2: " + solucionGreedy.getObjective(1));
        System.out.println("----");
      }

      ((Problema) problem).imprimirSolucion("SALIDA_GREEDY.txt", solSetGreedy);
      solSetGreedy.printFeasibleFUN(salidaFun);
      solSetGreedy.printFeasibleVAR(salidaVar);

    } catch (Throwable t) {
      System.out.println(t.getMessage());
      return;
    }
  }
 public RouteSetCombinedGuidedMutation(HashMap<String, Object> parameters, Problem prob) {
   super(parameters);
   ObjWiseMut = new Operator[prob.getNumberOfObjectives() + 1][];
   ObjWiseMut[TNDP.OBJECTIVES.IVTT] = new Operator[] {TEL};
   ObjWiseMut[TNDP.OBJECTIVES.TP] = new Operator[] {Add};
   ObjWiseMut[TNDP.OBJECTIVES.UP] = new Operator[] {Add};
   ObjWiseMut[TNDP.OBJECTIVES.RL] = new Operator[] {TEL, Del};
   ObjWiseMut[TNDP.OBJECTIVES.DO] = new Operator[] {TEO, Del};
   ObjWiseMut[TNDP.OBJECTIVES.WT] = new Operator[] {Add, Del};
   ObjWiseMut[TNDP.OBJECTIVES.FS] = new Operator[] {Add, Del};
   ObjWiseMut[ObjWiseMut.length - 1] = new Operator[] {Add, Del};
 }
Пример #4
0
  /**
   * @param args Command line arguments. The first (optional) argument specifies the problem to
   *     solve.
   * @throws JMException
   */
  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

    HashMap parameters; // Operator parameters

    // Logger object and file to store log messages
    logger_ = Configuration.logger_;
    fileHandler_ = new FileHandler("FastPGA_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("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 FastPGA(problem);

    algorithm.setInputParameter("maxPopSize", 100);
    algorithm.setInputParameter("initialPopulationSize", 100);
    algorithm.setInputParameter("maxEvaluations", 25000);
    algorithm.setInputParameter("a", 20.0);
    algorithm.setInputParameter("b", 1.0);
    algorithm.setInputParameter("c", 20.0);
    algorithm.setInputParameter("d", 0.0);

    // Parameter "termination"
    // If the preferred stopping criterium is PPR based, termination must
    // be set to 0; otherwise, if the algorithm is intended to iterate until
    // a give number of evaluations is carried out, termination must be set to
    // that number
    algorithm.setInputParameter("termination", 1);

    // Mutation and Crossover for Real codification
    parameters = new HashMap();
    parameters.put("probability", 0.9);
    parameters.put("distributionIndex", 20.0);
    crossover = CrossoverFactory.getCrossoverOperator("SBXCrossover", parameters);
    // crossover.setParameter("probability",0.9);
    // crossover.setParameter("distributionIndex",20.0);

    parameters = new HashMap();
    parameters.put("probability", 1.0 / problem.getNumberOfVariables());
    parameters.put("distributionIndex", 20.0);
    mutation = MutationFactory.getMutationOperator("PolynomialMutation", parameters);
    // Mutation and Crossover for Binary codification

    parameters = new HashMap();
    parameters.put("comparator", new FPGAFitnessComparator());
    selection = new BinaryTournament(parameters);

    algorithm.addOperator("crossover", crossover);
    algorithm.addOperator("mutation", mutation);
    algorithm.addOperator("selection", selection);

    long initTime = System.currentTimeMillis();
    SolutionSet population = algorithm.execute();
    long estimatedTime = System.currentTimeMillis() - initTime;

    // Result messages
    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));

      int evaluations = ((Integer) algorithm.getOutputParameter("evaluations")).intValue();
      logger_.info("Speed      : " + evaluations + " evaluations");
    } // if
  } // main