Exemple #1
0
  /**
   * Creates a LZ09_F2 problem instance
   *
   * @param solutionType The solution type must "Real" or "BinaryReal".
   */
  public LZ09_F2(String solutionType, Integer ptype, Integer dtype, Integer ltype)
      throws ClassNotFoundException {
    numberOfVariables_ = 30;
    numberOfObjectives_ = 2;
    numberOfConstraints_ = 0;
    problemName_ = "LZ09_F2";

    LZ09_ = new LZ09(numberOfVariables_, numberOfObjectives_, ptype, dtype, ltype);

    lowerLimit_ = new double[numberOfVariables_];
    upperLimit_ = new double[numberOfVariables_];
    lowerLimit_[0] = 0.0;
    upperLimit_[0] = 1.0;
    for (int var = 1; var < numberOfVariables_; var++) {
      lowerLimit_[var] = -1.0;
      upperLimit_[var] = 1.0;
    } // for

    if (solutionType.compareTo("BinaryReal") == 0) solutionType_ = new BinaryRealSolutionType(this);
    else if (solutionType.compareTo("Real") == 0) solutionType_ = new RealSolutionType(this);
    else {
      System.out.println("Error: solution type " + solutionType + " invalid");
      System.exit(-1);
    }
  } // LZ09_F2
Exemple #2
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

    // 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
  double fitnessFunction(Solution individual, double[] lambda) {
    double fitness;
    fitness = 0.0;

    if (functionType_.equals("_TCHE1")) {
      double maxFun = -1.0e+30;

      for (int n = 0; n < problem_.getNumberOfObjectives(); n++) {
        double diff = Math.abs(individual.getObjective(n) - z_[n]);

        double feval;
        if (lambda[n] == 0) {
          feval = 0.0001 * diff;
        } else {
          feval = diff * lambda[n];
        }
        if (feval > maxFun) {
          maxFun = feval;
        }
      } // for

      fitness = maxFun;
    } // if
    else if (functionType_.equals("_AGG")) {
      double sum = 0.0;
      for (int n = 0; n < problem_.getNumberOfObjectives(); n++) {
        sum += (lambda[n]) * individual.getObjective(n);
      }

      fitness = sum;

    } else if (functionType_.equals("_PBI")) {
      double d1, d2, nl;
      double theta = 5.0;

      d1 = d2 = nl = 0.0;

      for (int i = 0; i < problem_.getNumberOfObjectives(); i++) {
        d1 += (individual.getObjective(i) - z_[i]) * lambda[i];
        nl += Math.pow(lambda[i], 2.0);
      }
      nl = Math.sqrt(nl);
      d1 = Math.abs(d1) / nl;

      for (int i = 0; i < problem_.getNumberOfObjectives(); i++) {
        d2 += Math.pow((individual.getObjective(i) - z_[i]) - d1 * (lambda[i] / nl), 2.0);
      }
      d2 = Math.sqrt(d2);

      fitness = (d1 + theta * d2);
    } else {
      System.out.println("MOEAD.fitnessFunction: unknown type " + functionType_);
      System.exit(-1);
    }
    return fitness;
  } // fitnessEvaluation
Exemple #4
0
  public void readProblem(String fileName) throws FileNotFoundException, IOException {

    Reader inputFile = new BufferedReader(new InputStreamReader(new FileInputStream(fileName)));

    StreamTokenizer token = new StreamTokenizer(inputFile);
    try {
      token.nextToken();

      numberOfCities_ = (int) token.nval;

      distanceMatrix_ = new double[numberOfCities_][numberOfCities_];
      flujo1 = new double[numberOfCities_][numberOfCities_];
      flujo2 = new double[numberOfCities_][numberOfCities_];

      // Cargar objetivo 1
      for (int k = 0; k < numberOfCities_; k++) {
        for (int j = 0; j < numberOfCities_; j++) {
          token.nextToken();
          flujo1[k][j] = token.nval;
        }
      }

      // Cargar objetivo 2
      for (int k = 0; k < numberOfCities_; k++) {
        for (int j = 0; j < numberOfCities_; j++) {
          token.nextToken();
          flujo2[k][j] = token.nval;
        }
      }

      // Carga de distancias
      for (int k = 0; k < numberOfCities_; k++) {
        for (int j = 0; j < numberOfCities_; j++) {
          token.nextToken();
          distanceMatrix_[k][j] = token.nval;
        }
      }

    } // try
    catch (Exception e) {
      System.err.println("QAP.readProblem(): error when reading data file " + e);
      System.exit(1);
    } // catch
  } // readProblem
Exemple #5
0
  /**
   * Constructor. Creates a default instance of the Srinivas problem
   *
   * @param solutionType The solution type must "Real" or "BinaryReal".
   */
  public Srinivas(String solutionType) throws ClassNotFoundException {
    numberOfVariables_ = 2;
    numberOfObjectives_ = 2;
    numberOfConstraints_ = 2;
    problemName_ = "Srinivas";

    lowerLimit_ = new double[numberOfVariables_];
    upperLimit_ = new double[numberOfVariables_];
    for (int var = 0; var < numberOfVariables_; var++) {
      lowerLimit_[var] = -20.0;
      upperLimit_[var] = 20.0;
    } // for

    if (solutionType.compareTo("BinaryReal") == 0) solutionType_ = new BinaryRealSolutionType(this);
    else if (solutionType.compareTo("Real") == 0) solutionType_ = new RealSolutionType(this);
    else {
      System.out.println("Error: solution type " + solutionType + " invalid");
      System.exit(-1);
    }
  } // Srinivas
  public void initNeighborhood() {
    double[] x = new double[populationSize];
    int[] idx = new int[populationSize];

    for (int i = 0; i < populationSize; i++) {
      // calculate the distances based on weight vectors
      for (int j = 0; j < populationSize; j++) {
        x[j] = Utils.distVector(lambda_[i], lambda_[j]);
        // x[j] = dist_vector(population[i].namda,population[j].namda);
        idx[j] = j;
        // System.out.println("x["+j+"]: "+x[j]+ ". idx["+j+"]: "+idx[j]) ;
      } // for

      // find 'niche' nearest neighboring subproblems
      Utils.minFastSort(x, idx, populationSize, T_);
      // minfastsort(x,idx,population.size(),niche);

      System.arraycopy(idx, 0, neighborhood_[i], 0, T_);
    } // for
  } // initNeighborhood
  /**
   * Creates a new DTLZ5 problem instance
   *
   * @param numberOfVariables Number of variables
   * @param numberOfObjectives Number of objective functions
   * @param solutionType The solution type must "Real" or "BinaryReal".
   */
  public DTLZ5(String solutionType, Integer numberOfVariables, Integer numberOfObjectives)
      throws ClassNotFoundException {
    numberOfVariables_ = numberOfVariables.intValue();
    numberOfObjectives_ = numberOfObjectives.intValue();
    numberOfConstraints_ = 0;
    problemName_ = "DTLZ5";

    lowerLimit_ = new double[numberOfVariables_];
    upperLimit_ = new double[numberOfVariables_];
    for (int var = 0; var < numberOfVariables_; var++) {
      lowerLimit_[var] = 0.0;
      upperLimit_[var] = 1.0;
    }

    if (solutionType.compareTo("BinaryReal") == 0) solutionType_ = new BinaryRealSolutionType(this);
    else if (solutionType.compareTo("Real") == 0) solutionType_ = new RealSolutionType(this);
    else {
      System.out.println("Error: solution type " + solutionType + " invalid");
      System.exit(-1);
    }
  } // DTLZ5
Exemple #8
0
  /**
   * Creates a new instance of problem CEC2009_UF10.
   *
   * @param numberOfVariables Number of variables.
   * @param solutionType The solution type must "Real" or "BinaryReal".
   */
  public CEC2009_UF10(String solutionType, Integer numberOfVariables)
      throws ClassNotFoundException {
    numberOfVariables_ = numberOfVariables.intValue();
    numberOfObjectives_ = 3;
    numberOfConstraints_ = 0;
    problemName_ = "CEC2009_UF10";

    upperLimit_ = new double[numberOfVariables_];
    lowerLimit_ = new double[numberOfVariables_];

    // Establishes upper and lower limits for the variables
    for (int var = 0; var < numberOfVariables_; var++) {
      lowerLimit_[var] = 0.0;
      upperLimit_[var] = 1.0;
    } // for

    if (solutionType.compareTo("BinaryReal") == 0) solutionType_ = new BinaryRealSolutionType(this);
    else if (solutionType.compareTo("Real") == 0) solutionType_ = new RealSolutionType(this);
    else {
      System.out.println("Error: solution type " + solutionType + " invalid");
      System.exit(-1);
    }
  } // CEC2009_UF10
Exemple #9
0
  /**
   * @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
Exemple #10
0
  /**
   * @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