Examples of HCBag


Examples of com.niacin.persistence.HCBag

    return bag;
  }
  @Override
  public void unpack(Bag bag)
  {
    HCBag hb = (HCBag) bag;
    name = hb.getName();
    state = hb.getState();
    remainingEvaluations = hb.getRemainingEvaluations();
    currentSolution = hb.getCurrentSolution();
    bestSoFarSolution = hb.getBestSoFarSolution();
    neighbours = new ArrayList<Solution>(hb.getNeighbours());
    neighbourPos = hb.getNeighbourPos();
  }
View Full Code Here

Examples of com.niacin.persistence.HCBag

  Solution nextSolution = null;

  @Override
  public Solution getNextInput(Problem problem)
  {
    HCBag bag = (HCBag) Persistence.load(problem.name(), HCBag.class);
    if (bag == null)
      state = HillClimbing.START;
    else
      unpack(bag);

    if (bag != null && bag.getRemainingEvaluations() == 0)
    {
      log.info("NO BUDGET: bailing out with the best so far solution");
      nextSolution = bag.getBestSoFarSolution();
      return nextSolution;
    }

    switch (state)
    {
      case START :
        log.info("START");
        name = problem.name();
        remainingEvaluations = problem.getRemainingTrials();
        currentSolution = problem.initialSolution();
        bestSoFarSolution = currentSolution;
        nextSolution = currentSolution;

        neighbours = new ArrayList<Solution>();
        neighbourPos = 0;
        state = HillClimbing.GENERATE_NEIGHBOURS;
        break;
      case MOVE :
      {
        log.info("CLIMB");
        double bestImprovement = 0;
        boolean moved = false;
        FitnessComparator comparator = new SimpleFitnessComparator();
        for (Solution neighbour : neighbours)
        {
          double improvement = comparator.compare(problem, neighbour, currentSolution);
          if (improvement > bestImprovement)
          {
            currentSolution = neighbour;
            nextSolution = neighbour;
            bestImprovement = improvement;
            moved = true;

            if (comparator.compare(problem, neighbour, bag.getBestSoFarSolution()) > 0)
            {
              log.info("UPDATING BEST SO FAR. FITNESS:" + neighbour.getFitness());
              bestSoFarSolution = neighbour;
            }
          }
        }
        if (!moved && bag.getRemainingEvaluations() > 0)
        {
          log.info("RANDOM RESTART");
          currentSolution = problem.generateRandomRestart();
          nextSolution = currentSolution;
          state = HillClimbing.GENERATE_NEIGHBOURS;
View Full Code Here

Examples of com.niacin.persistence.HCBag

  public static final int EVALUATE_NEIGHBOURS = 3;

  @Override
  public Bag pack(Problem problem)
  {
    HCBag bag = new HCBag();
    bag.setName(problem.name());
    bag.setState(state);
    bag.setRemainingEvaluations(remainingEvaluations);
    bag.setBestSoFarSolution(bestSoFarSolution);
    bag.setCurrentSolution(currentSolution);
    bag.setNeighbours(new ArrayList<Solution>(neighbours));
    bag.setNeighbourPos(neighbourPos);
    return bag;
  }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.