Browse Source

Adds additional Information in the GreedyAlgorithms

TomTroppmann 2 years ago
parent
commit
9d30acc0ea

+ 19 - 3
src/algorithm/binary/GreedyAlgorithm.java

@@ -9,7 +9,17 @@ import utility.StringFormat;
 public class GreedyAlgorithm extends AlgorithmFrameworkFlex{
 
 	private int problemSize = 0;
-	private boolean moreInformation = true;
+	private boolean moreInformation = false;
+	
+	
+	public GreedyAlgorithm() {
+		super();
+		addBooleanParameter("More Information", moreInformation, booleanValue -> moreInformation = booleanValue);
+	}
+	
+	
+	
+	
 	@Override
 	protected Individual executeAlgo() {
 		Individual best = new Individual();
@@ -44,6 +54,7 @@ public class GreedyAlgorithm extends AlgorithmFrameworkFlex{
 					bestInThisRound = new Individual(startInThisRound);	
 					bestInThisRound.fitness = fitness;
 					indexToRemove = i;
+					
 				}
 				startInThisRound.position.set(i, actualValue);
 			}
@@ -53,9 +64,11 @@ public class GreedyAlgorithm extends AlgorithmFrameworkFlex{
 			if(bestAfterRound.fitness < best.fitness) {
 				best = bestAfterRound;
 			}
+			runList.add(best.fitness);
 			indexList.remove(Integer.valueOf(indexToRemove));
 		}
-		
+		this.runList = runList;
+		console.println("Fitness: " + best.fitness);
 		return best;
 	}
 
@@ -67,9 +80,12 @@ public class GreedyAlgorithm extends AlgorithmFrameworkFlex{
 	
 	@Override
 	protected int getProgressBarMaxCount() {
-		return (problemSize * (problemSize + 1)) / 2;
+		List<Boolean> best = extractPositionAndAccess();
+		problemSize = best.size();
+		return ((problemSize * (problemSize + 1)) / 2) * rounds;
 	}
 
+	
 	@Override
 	protected String algoInformationToPrint() {
 		return "NoParameter";

+ 19 - 14
src/algorithm/binary/GreedySinglePass.java

@@ -22,16 +22,16 @@ import utility.Tuple;
 public class GreedySinglePass extends AlgorithmFrameworkFlex {
 
 	private int problemSize = 0;
-	private boolean moreInformation = true;
-
-	/**
-	 * Method to get the current Position alias a ListOf Booleans for aktive
-	 * settings on the Objects on the Canvas. Also initialize the Access Hashmap to
-	 * swap faster positions.
-	 * 
-	 * @param model
-	 * @return
-	 */
+	private boolean moreInformation = false;
+
+	
+	
+	public GreedySinglePass() {
+		super();
+		addBooleanParameter("More Information", moreInformation, booleanValue -> moreInformation = booleanValue);
+	}
+	
+
 	protected List<Integer> generateRandomLayerIndexList() {
 		Model model = control.getModel();
 		List<AbstractCanvasObject> nodes = (dGroupNode != null) ? dGroupNode.getModel().getNodes()
@@ -121,6 +121,7 @@ public class GreedySinglePass extends AlgorithmFrameworkFlex {
 		bestFound.fitness = Float.MAX_VALUE;
 		Individual start = new Individual(best);
 		List<Integer> radomizedForEachLayerIndexList = generateRandomLayerIndexList();
+		
 		for (Integer index : radomizedForEachLayerIndexList) {
 			boolean actualValue = start.position.get(index);
 			start.position.set(index, !actualValue);
@@ -129,6 +130,7 @@ public class GreedySinglePass extends AlgorithmFrameworkFlex {
 			if (kicked) {
 				bestFound = new Individual(start);
 				bestFound.fitness = fitness;
+				
 			} else {
 				start.position.set(index, actualValue);
 			}
@@ -136,12 +138,13 @@ public class GreedySinglePass extends AlgorithmFrameworkFlex {
 			if (bestFound.fitness < best.fitness) {
 				best = bestFound;
 			}
-
+			runList.add(bestFound.fitness);
 			if (cancel)
 				return null;
 			println("Fitness: " + fitness + "\tFlippedIndex = " + index + "(" + problemSize + ")" + kicked);
 		}
-
+		console.println("Fitness: " + bestFound.fitness);
+		this.runList = runList;
 		return best;
 	}
 
@@ -152,9 +155,11 @@ public class GreedySinglePass extends AlgorithmFrameworkFlex {
 
 	@Override
 	protected int getProgressBarMaxCount() {
-		return (problemSize * (problemSize + 1)) / 2;
+		List<Boolean> best = extractPositionAndAccess();
+		problemSize = best.size();
+		return problemSize * rounds;
 	}
-
+	
 	@Override
 	protected String algoInformationToPrint() {
 		return "NoParameter";

+ 1 - 0
src/api/AlgorithmFrameworkFlex.java

@@ -975,6 +975,7 @@ public abstract class AlgorithmFrameworkFlex implements AddOn {
 			count = 0;
 			isActive = true;
 			progressBar.setValue(0);
+			
 			progressBar.setMaximum(getProgressBarMaxCount());
 		}