@Override public void offerSolution() { FitInstance<Instance> solution = task.getFitInstance(stats.getBestInstance()); System.out.println("Offering solution with f = " + solution.getFitness()); otherAlgorithms .get(ThreadLocalRandom.current().nextInt(otherAlgorithms.size())) .acceptSolution(solution); }
protected Edge addChildToBest(Instance instance) { List<MutatedInstanceMetaData<Instance, MutationType>> offspring = crossover.apply(stats.getBestInstance(), instance); FitInstance<Instance> md0 = task.getFitInstance(offspring.get(0).getInstance()); FitInstance<Instance> md1 = task.getFitInstance(offspring.get(1).getInstance()); if (md0.getFitness() > md1.getFitness()) { return graph.addNode( stats.getBestNode(), offspring.get(0).getMutations(), md0, task.getNumberOfFitnessEvaluations()); } return graph.addNode( stats.getBestNode(), offspring.get(1).getMutations(), md1, task.getNumberOfFitnessEvaluations()); }
@Override protected List<Node<Instance>> getStartNodes() { List<Node<Instance>> startNodes = super.getStartNodes(); if (!offeredSolutions.isEmpty()) { startNodes.remove(0); FitInstance<Instance> bestOfferedSolution = Collections.max(offeredSolutions); offeredSolutions.clear(); Node<Instance> node = addChildToBest(bestOfferedSolution.getInstance()).getDest(); System.out.println( "Crossover (" + stats.getBestFitness() + ", " + bestOfferedSolution.getFitness() + ") best child fitness = " + node.getFitness()); startNodes.add(node); } return startNodes; }