Browse Source

Algo cleanup (started), producers are blue now, fitnessfunction error
fixed

Rolf Egert 2 years ago
parent
commit
679233045f

+ 14 - 14
src/algorithm/binary/PsoAlgorithm.java

@@ -13,7 +13,7 @@ public class PsoAlgorithm extends AlgorithmFrameworkFlex{
 	private int swarmSize = 20; 
 	private int maxIterations = 100; 
 	private double dependency = 2.07; 
-	private int mutationInterval = 1;
+	private int mutationIteration = 1;
 	private boolean useIntervalMutation = true;
 	private double mutationRate = 0.01;
 	private double mutateProbabilityInterval = 0.01;
@@ -37,17 +37,17 @@ public class PsoAlgorithm extends AlgorithmFrameworkFlex{
 	
 	public PsoAlgorithm() {
 		super();
-		addIntParameter("swarmSize", swarmSize, intValue -> swarmSize = intValue, () -> swarmSize, 1);
-		addIntParameter("maxIterations", maxIterations, intValue -> maxIterations = intValue, () -> maxIterations, 1);
-		addDoubleParameter("dependency", dependency, doubleValue -> dependency = doubleValue, () -> dependency, 2.001, 2.4);
-		addIntParameter("mutationInterval", mutationInterval, intValue -> mutationInterval = intValue, () -> mutationInterval, 0);
-		addBooleanParameter("useIntervalMutation", useIntervalMutation, booleanValue -> useIntervalMutation = booleanValue);
-		addDoubleParameter("mutateProbabilityInterval", mutateProbabilityInterval, doubleValue -> mutateProbabilityInterval = doubleValue, () -> mutateProbabilityInterval, 0.0, 1.0);
-		addDoubleParameter("mutationRate", mutationRate, doubleValue -> mutationRate = doubleValue, () -> mutationRate, 0.0, 1.0);
-		addDoubleParameter("maxMutationPercent", maxMutationPercent, doubleValue -> maxMutationPercent = doubleValue, () -> maxMutationPercent, 0.0, 1.0);
-		addDoubleParameter("maxVelocity", maxVelocity, doubleValue -> maxVelocity = doubleValue, () -> maxVelocity, 0.0);
+		addIntParameter("Particles", swarmSize, intValue -> swarmSize = intValue, () -> swarmSize, 1);
+		addIntParameter("Iterations", maxIterations, intValue -> maxIterations = intValue, () -> maxIterations, 1);
+		addDoubleParameter("Dependency", dependency, doubleValue -> dependency = doubleValue, () -> dependency, 2.001, 2.4);
+		addIntParameter("Mutation iteration", mutationIteration, intValue -> mutationIteration = intValue, () -> mutationIteration, 0);
+		addBooleanParameter("Interval-based mutation", useIntervalMutation, booleanValue -> useIntervalMutation = booleanValue);
+		addDoubleParameter("Mutation probability (%)", mutateProbabilityInterval, doubleValue -> mutateProbabilityInterval = doubleValue, () -> mutateProbabilityInterval, 0.0, 1.0);
+	//	addDoubleParameter("mutationRate", mutationRate, doubleValue -> mutationRate = doubleValue, () -> mutationRate, 0.0, 1.0);
+		addDoubleParameter("Mutation severity (% of problem size)", maxMutationPercent, doubleValue -> maxMutationPercent = doubleValue, () -> maxMutationPercent, 0.0, 1.0);
+		addDoubleParameter("Velocity", maxVelocity, doubleValue -> maxVelocity = doubleValue, () -> maxVelocity, 0.0);
 		
-		addBooleanParameter("moreInformation", moreInformation , booleanValue -> moreInformation = booleanValue);
+		addBooleanParameter("Detailed information", moreInformation , booleanValue -> moreInformation = booleanValue);
 	}
 	
 
@@ -103,7 +103,7 @@ public class PsoAlgorithm extends AlgorithmFrameworkFlex{
 		evaluation(globalBest, swarm);
 		runList.add(globalBest.fitness);
 		for (int iteration = 0; iteration < maxIterations ; iteration++) {
-			int mutationAllowed = iteration % mutationInterval;
+			int mutationAllowed = iteration % mutationIteration;
 			double bitsFlipped = 0;
 			for (int particleNumber = 0; particleNumber < swarmSize; particleNumber++) {
 				Particle particle = swarm.get(particleNumber);		
@@ -123,7 +123,7 @@ public class PsoAlgorithm extends AlgorithmFrameworkFlex{
 					for(int index = 0; index < dimensions; index++) {
 						updateVelocity(particle, index, globalBest);
 						updateGenotype(particle, index);
-						if(mutationAllowed == 0 && iteration != 0 && Random.nextDouble() < mutationRate) {
+						if(mutationAllowed == 0 && iteration != 0 && Random.nextDouble() < mutateProbabilityInterval) {
 							count++;
 							mutation(particle, index);
 						}
@@ -264,7 +264,7 @@ public class PsoAlgorithm extends AlgorithmFrameworkFlex{
 				+ " maxIterations:" + maxIterations
 				+ " swarmSize:" + swarmSize
 				+ " dependency:" +  dependency
-				+ " mutationInterval:" +  mutationInterval
+				+ " mutationInterval:" +  mutationIteration
 				+ " maxVelocity: " + maxVelocity
 				+ (useIntervalMutation? 
 						(" mutateProbabilityInterval:" +  mutateProbabilityInterval

+ 1 - 1
src/algorithm/objectiveFunction/ObjectiveFunctionByCarlos.java

@@ -46,7 +46,7 @@ public class ObjectiveFunctionByCarlos {
 	 * <br>
 	 *  {@link ObjectiveFunctionByCarlos#squash}
 	 */
-	static double squash_subtract = 1.0f / (1.f + (float) Math.exp(5.0));
+	static double squash_subtract = 100.f / (1.f + (float) Math.exp(5.0));
 	static double range_for_kappa_f_unre = range(kappa_f_unre);
 	static double range_for_kappa_f_cool = range(kappa_f_cool);
 	static double range_for_kappa_f_dur = range(kappa_f_dur);

+ 8 - 8
src/api/AlgorithmFrameworkFlex.java

@@ -240,7 +240,7 @@ public abstract class AlgorithmFrameworkFlex implements AddOn{
 		cancelButton.addActionListener(actionEvent -> cancel());
 		buttonPanel.add(cancelButton);
 		
-		JButton fitnessButton =  new JButton("Fitness");
+		JButton fitnessButton =  new JButton("Evaluate");
 		fitnessButton.setToolTipText("Fitness for the current state.");
 		fitnessButton.addActionListener(actionEvent -> fitness());
 		buttonPanel.add(fitnessButton);
@@ -324,7 +324,7 @@ public abstract class AlgorithmFrameworkFlex implements AddOn{
 		stepsTextField.setPreferredSize(new Dimension(40, 30));
 		singleParameterPanel.add(stepsTextField);
 		
-		JLabel stepsSizeLabel = new JLabel("StepsSize: ");
+		JLabel stepsSizeLabel = new JLabel("Step size: ");
 		stepsSizeLabel.setEnabled(false);
 		singleParameterPanel.add(stepsSizeLabel);
 		
@@ -418,7 +418,7 @@ public abstract class AlgorithmFrameworkFlex implements AddOn{
 		stepsTextField.setPreferredSize(new Dimension(40, 30));
 		singleParameterPanel.add(stepsTextField);
 		
-		JLabel stepsSizeLabel = new JLabel("StepsSize: ");
+		JLabel stepsSizeLabel = new JLabel("Step size: ");
 		stepsSizeLabel.setEnabled(false);
 		singleParameterPanel.add(stepsSizeLabel);
 		
@@ -465,7 +465,7 @@ public abstract class AlgorithmFrameworkFlex implements AddOn{
 	}
 	private long printElapsedTime(){
 		long elapsedMilliSeconds = System.currentTimeMillis() - startTime;
-		console.println("Execution Time of Algo in Milliseconds:" + elapsedMilliSeconds);
+		console.println("Execution Time in Milliseconds:" + elapsedMilliSeconds);
 		return elapsedMilliSeconds;
 	}
 	
@@ -484,7 +484,7 @@ public abstract class AlgorithmFrameworkFlex implements AddOn{
 	
 	private void fitness() {
 		if(runThread.isAlive()) {
-			console.println("Run have to be cancelled First.");
+			console.println("Run have to be cancelled first.");
 			return;
 		}
 		double currentFitness = evaluatePosition(extractPositionAndAccess());
@@ -496,7 +496,7 @@ public abstract class AlgorithmFrameworkFlex implements AddOn{
 	private void selectGroupNode() {
 		Object[] possibilities = control.getSimManager().getActualVisualRepresentationalState().getCreatedGroupNodes().values().stream().map(aCps -> new Handle<DecoratedGroupNode>(aCps)).toArray();
 		@SuppressWarnings("unchecked")
-		Handle<DecoratedGroupNode> selected = (Handle<DecoratedGroupNode>) JOptionPane.showInputDialog(content, "Select GroupNode:", "GroupNode?",  JOptionPane.OK_OPTION,new ImageIcon(new BufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB)) , possibilities, "");
+		Handle<DecoratedGroupNode> selected = (Handle<DecoratedGroupNode>) JOptionPane.showInputDialog(content, "Select group-node:", "Select a designated area",  JOptionPane.OK_OPTION,new ImageIcon(new BufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB)) , possibilities, "");
 		if(selected != null) {
 			console.println("Selected: " + selected);
 			dGroupNode = selected.object;
@@ -629,13 +629,13 @@ public abstract class AlgorithmFrameworkFlex implements AddOn{
 		setState(runBest.position);
 		updateVisual();
 		console.println("Start: " + StringFormat.doubleFixedPlaces(2,startFitness));
-		console.println("AlgoResult: " + StringFormat.doubleFixedPlaces(2,runBest.fitness));
+		console.println("Result: " + StringFormat.doubleFixedPlaces(2,runBest.fitness));
 		if(this.algoUseFlexes)calculateAndPrintFlexInfos(control.getSimManager().getActualDecorState());
 		runPrinter.openStream();
 		if(rounds > 1) {
 			RunValues avgRun = avg.getAverage();
 			
-			runPrinter.println("Average.Result: " + StringFormat.doubleFixedPlaces(2, avgRun.result) + " Average.ExecutionTime:" + avgRun.executionTime + " "  + this.stringStatFromRunValues(avg.getAverage(), "Average."));
+			runPrinter.println("Average result: " + StringFormat.doubleFixedPlaces(2, avgRun.result) + " Average time:" + avgRun.executionTime + " "  + this.stringStatFromRunValues(avg.getAverage(), "Average."));
 		}
 		runPrinter.println("");
 		runPrinter.closeStream();

+ 1 - 1
src/preferences/ColorPreference.java

@@ -22,7 +22,7 @@ public class ColorPreference {
 		public static final Color Inactive = new Color(128, 154, 163);
 	}
 	public static class HolonObject{
-		public static final Color Producer = Color.lightGray;
+		public static final Color Producer = new Color(153, 204, 255);
 		public static final Color OverSupplied = new Color(166, 78, 229);
 		public static final Color Supplied = new Color(13, 175, 28);
 		public static final Color PartiallySupplied = Color.yellow;