Exemplo n.º 1
0
  /**
   * Creates a new instance of problem CEC2009_UF6.
   *
   * @param numberOfVariables Number of variables.
   * @param solutionType The solution type must "Real" or "BinaryReal".
   */
  public CEC2009_UF6(String solutionType, Integer numberOfVariables, int N, double epsilon)
      throws ClassNotFoundException {
    numberOfVariables_ = numberOfVariables.intValue();
    numberOfObjectives_ = 2;
    numberOfConstraints_ = 0;
    problemName_ = "CEC2009_UF6";

    N_ = N;
    epsilon_ = epsilon;

    upperLimit_ = new double[numberOfVariables_];
    lowerLimit_ = 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);
    }
  } // CEC2009_UF6
Exemplo n.º 2
0
Arquivo: Main.java Projeto: ai-se/SPL
  public boolean[] randomProduct() {

    boolean[] prod = new boolean[ProductLineProblem.numFeatures];
    for (int i = 0; i < prod.length; i++) {
      prod[i] = r.nextBoolean();
    }

    int rand = r.nextInt(3);

    try {
      IOrder order;
      if (rand == 0) {
        order =
            new RandomWalkDecorator(new VarOrderHeap(new NegativeLiteralSelectionStrategy()), 1);
      } else if (rand == 1) {
        order =
            new RandomWalkDecorator(new VarOrderHeap(new PositiveLiteralSelectionStrategy()), 1);
      } else {
        order = new RandomWalkDecorator(new VarOrderHeap(new RandomLiteralSelectionStrategy()), 1);
      }

      // dimacsSolver.reset();
      ISolver dimacsSolver2 = SolverFactory.instance().createSolverByName("MiniSAT");
      dimacsSolver2.setTimeout(SATtimeout);

      DimacsReader dr = new DimacsReader(dimacsSolver2);
      dr.parseInstance(new FileReader(ProductLineProblem.fm));
      ((Solver) dimacsSolver2).setOrder(order);

      ISolver solverIterator = new ModelIterator(dimacsSolver2);
      solverIterator.setTimeoutMs(iteratorTimeout);

      if (solverIterator.isSatisfiable()) {
        int[] i = solverIterator.findModel();

        for (int j = 0; j < i.length; j++) {
          int feat = i[j];

          int posFeat = feat > 0 ? feat : -feat;

          if (posFeat > 0) {
            prod[posFeat - 1] = feat > 0;
          }

          //                    else
          //                    {
          //                         prod[nFeat-1] = r.nextBoolean();
          //                    }
        }
      }

      // solverIterator = null;
    } catch (Exception e) {
      e.printStackTrace();
      System.exit(0);
    }

    return prod;
  }