1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071 |
- package algorithm.binary;
- import java.util.ArrayList;
- import java.util.List;
- import api.AlgorithmFrameworkFlex;
- import api.AlgorithmFrameworkFlex.Individual;
- import utility.StringFormat;
- public class GreedySinglePass extends AlgorithmFrameworkFlex{
- private int problemSize = 0;
- private boolean moreInformation = true;
- @Override
- protected Individual executeAlgo() {
- Individual best = new Individual();
- best.position = extractPositionAndAccess();
- println("Bit-Array_length: " + best.position.size());
- best.fitness = evaluatePosition(best.position);
- List<Double> runList = new ArrayList<Double>();
- runList.add(best.fitness);
- println("Start with: " + StringFormat.doubleFixedPlaces(2, best.fitness));
- problemSize = best.position.size();
-
-
- Individual bestFound = new Individual(best);
- bestFound.fitness = Float.MAX_VALUE;
- Individual start = new Individual(best);
- for(int index = 0; index < problemSize; index++)
- {
- boolean actualValue = start.position.get(index);
- start.position.set(index, !actualValue);
- double fitness = evaluatePosition(start.position);
- if(fitness < bestFound.fitness) {
- bestFound = new Individual(start);
- bestFound.fitness = fitness;
- }
- if(bestFound.fitness < best.fitness) {
- best = bestFound;
- }
-
-
- if(cancel) return null;
- println("Fitness: " + fitness + "FlippedIndex = " + index + "(" + problemSize + ")");
- }
-
-
- return best;
- }
-
-
- protected void println(String value) {
- if(moreInformation)console.println(value);
- }
-
- @Override
- protected int getProgressBarMaxCount() {
- return (problemSize * (problemSize + 1)) / 2;
- }
- @Override
- protected String algoInformationToPrint() {
- return "NoParameter";
- }
- @Override
- protected String plottFileName() {
- return "plottGreedy.txt";
- }
- }
|