Example #1
0
  @Test
  public void testPerformInitialisation() {
    FunctionOptimisationProblem problem = new FunctionOptimisationProblem();
    problem.setDomain("R(-32.768:32.768)^30");
    problem.setFunction(new Ackley());

    MeasuredStoppingCondition condition =
        new MeasuredStoppingCondition(new Iterations(), new Maximum(), 100);

    ABC abc = new ABC();
    abc.addStoppingCondition(condition);
    abc.setOptimisationProblem(problem);
    abc.setWorkerBeePercentage(ConstantControlParameter.of(0.7));

    abc.performInitialisation();
    assertEquals(abc.getTopology().length(), 100);
    assertEquals(abc.getWorkerBees().length(), 70);
    assertEquals(abc.getOnlookerBees().length(), 30);
    HashMap<Type, Type> map = new HashMap<Type, Type>();

    for (HoneyBee bee : abc.getTopology()) {
      map.put(bee.getPosition(), bee.getPosition());
    }
    for (HoneyBee bee : abc.getWorkerBees()) {
      map.put(bee.getPosition(), bee.getPosition());
    }
    for (HoneyBee bee : abc.getOnlookerBees()) {
      map.put(bee.getPosition(), bee.getPosition());
    }

    assertEquals(100, map.size());
  }
Example #2
0
  /**
   * @TODO: Change this to use something better than a string @TODO: complete this method
   *
   * @param x
   * @param dimensionBitNumber
   * @return
   */
  public String generateBitString(Vector x, int dimensionBitNumber) {
    double a = x.doubleValueOf(0);
    double b = x.doubleValueOf(1);
    double c = x.doubleValueOf(2);
    double d = x.doubleValueOf(3);

    StringBuilder str = new StringBuilder();

    for (int i = 0; i < dimensionBitNumber * delegate.getDomain().getDimension(); i++) {
      double result = Math.sin(2 * Math.PI * (i - a) * b * Math.cos(2 * Math.PI * c * (i - a))) + d;

      if (result > 0.0) {
        str.append('1');
      } else {
        str.append('0');
      }
    }

    return str.toString();
  }
Example #3
0
 /**
  * Sets the g function with a specified problem.
  *
  * @param problem FunctionOptimisationProblem used for the g function.
  */
 public void setHEF6_g(FunctionOptimisationProblem problem) {
   this.hef6_g_problem = problem;
   this.hef6_g = (ContinuousFunction) problem.getFunction();
 }
Example #4
0
 @Override
 protected Fitness calculateFitness(Type solution) {
   String bitString = generateBitString((Vector) solution, bitsPerDimension);
   Vector expandedVector = decodeBitString(bitString, bitsPerDimension);
   return delegate.getFitness(expandedVector);
 }
Example #5
0
 public void setProblem(FunctionOptimisationProblem problem) {
   this.delegate = problem;
   bitsPerDimension = getRequiredNumberOfBits(delegate.getDomain());
 }