Browse Source

Adds Logger and Parameter Hidding

Troppmann, Tom 3 years ago
parent
commit
040826475f

+ 18 - 7
src/algorithm/objectiveFunction/TopologieObjectiveFunction.java

@@ -10,6 +10,7 @@ import java.util.HashSet;
 import java.util.Locale;
 import algorithm.objectiveFunction.GraphMetrics.Graph;
 import api.TopologieAlgorithmFramework.IndexCable;
+import classes.FloatLog;
 
 public class TopologieObjectiveFunction {
 	//Parameters
@@ -33,16 +34,16 @@ public class TopologieObjectiveFunction {
 	/**
 	 * maximum penalty from holon element distribution
 	 */
-	static double k_holon= 10000;
+	static double k_holon= 4000;
 	
 	
 	//--> f_selection paramaeter;
 	/**
 	 *  average Maximum Cost for selction(kappa) of switch and elements.
 	 */
-	static double k_selection = 50000;
-	static double cost_switch = 1000;
-	private static double cost_of_cable_per_meter = 0.8;
+	static double k_selection = 200000;
+	static double cost_switch = 3000;
+	private static double cost_of_cable_per_meter = 6;
 
 	//--> f_grid parameter
 	
@@ -71,8 +72,8 @@ public class TopologieObjectiveFunction {
 	static double range_for_k_avg_shortest_path = range(k_avg_shortest_path);
 	static double range_for_k_disjoint_path = range(k_disjoint_path - centerValue_disjoint_path);
 
-	
-	
+	public static FloatLog log = new FloatLog();
+	static boolean useLog = true;
 	static {
         //init
 		checkParameter();
@@ -200,9 +201,19 @@ public class TopologieObjectiveFunction {
 		
 		if(moreInformation) {
 			printWeightedValues(f_eb, f_maximum, f_holon, f_selection, f_grid);
+			if(useLog) {
+				System.out.println("Log");
+				System.out.println(log);
+			}
 		}
 		//printUnsquashedValues(f_eb, f_maximum, f_holon, f_selection, f_grid);
-		
+		if(useLog) {
+			log.addSample("Unsquashed f_eb", (float)f_eb);
+			log.addSample("Unsquashed f_maximum", (float)f_maximum);
+			log.addSample("Unsquashed f_holon", (float)f_holon);
+			log.addSample("Unsquashed f_selection", (float)f_selection);
+			log.addSample("Unsquashed f_grid", (float)f_grid);
+		}
 		return (float) (w_eb * squash(f_eb, k_eb) 
 				+ w_max * squash(f_maximum, k_max) 
 				+ w_holon * squash(f_holon, k_holon) 

+ 6 - 3
src/algorithm/topologie/AcoAlgorithm.java

@@ -2,6 +2,7 @@ package algorithm.topologie;
 
 import java.util.ArrayList;
 import java.util.HashSet;
+import java.util.LinkedList;
 import java.util.List;
 import java.util.ListIterator;
 import java.util.TreeSet;
@@ -29,9 +30,11 @@ public class AcoAlgorithm extends TopologieAlgorithmFramework {
 	public AcoAlgorithm(){
 		addIntParameter("popsize", popsize, intValue -> popsize = intValue, () -> popsize, 1);
 		addIntParameter("maxGenerations", maxGenerations, intValue -> maxGenerations = intValue, () -> maxGenerations, 1);
-		addDoubleParameter("Vaporization", p, doubleValue -> p = doubleValue, () -> p, 0.0, 1.0);
-		addDoubleParameter("FactorReset", convergenceFactorReset, doubleValue -> convergenceFactorReset = doubleValue, () -> convergenceFactorReset, 0.0, 1.0);
-		addBooleanParameter("moreInformation", moreInformation, booleanValue -> moreInformation = booleanValue);
+		addSeperator();
+		addDoubleParameter("Vaporization", p, doubleValue -> p = doubleValue, () -> p, true, 0.0, 1.0);
+		addDoubleParameter("FactorReset", convergenceFactorReset, doubleValue -> convergenceFactorReset = doubleValue, () -> convergenceFactorReset, true, 0.0, 1.0);
+		addSeperator();
+		addBooleanParameter("moreInformation", moreInformation, booleanValue -> moreInformation = booleanValue, new LinkedList<String>(), new LinkedList<String>());
 
 	}
 	@Override

+ 12 - 9
src/algorithm/topologie/GaAlgorithm.java

@@ -1,7 +1,9 @@
 package algorithm.topologie;
 
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.HashSet;
+import java.util.LinkedList;
 import java.util.List;
 import java.util.ListIterator;
 import java.util.TreeSet;
@@ -33,15 +35,16 @@ public class GaAlgorithm extends TopologieAlgorithmFramework {
 		addIntParameter("popsize", popsize, intValue -> popsize = intValue, () -> popsize, 1);
 		addIntParameter("maxGenerations", maxGenerations, intValue -> maxGenerations = intValue, () -> maxGenerations, 1);
 		addDoubleParameter("tournamentSize", tournamentSize, doubleValue -> tournamentSize = doubleValue, () -> tournamentSize, 1.0);
-		addDoubleParameter("fixedSwapProbability", fixedSwapProbability, doubleValue -> fixedSwapProbability = doubleValue, () -> fixedSwapProbability, 0.0, 1.0);
-		addBooleanParameter("useFixedSpawProbability", useFixedSpawProbability, booleanValue -> useFixedSpawProbability = booleanValue);
-		addDoubleParameter("fixedMutateProbability", fixedMutateProbability, doubleValue -> fixedMutateProbability = doubleValue, () -> fixedMutateProbability, 0.0, 1.0);
-		addBooleanParameter("useFixedMutateProbability", useFixedMutateProbability, booleanValue -> useFixedMutateProbability = booleanValue);
-		addBooleanParameter("useIntervalMutation", useIntervalMutation, booleanValue -> useIntervalMutation = booleanValue);
-		addDoubleParameter("mutateProbabilityInterval", mutateProbabilityInterval, doubleValue -> mutateProbabilityInterval = doubleValue, () -> mutateProbabilityInterval, 0.0, 1.0);
-		addDoubleParameter("maxMutationPercent", maxMutationPercent, doubleValue -> maxMutationPercent = doubleValue, () -> maxMutationPercent, 0.0, 1.0);
-		addBooleanParameter("moreInformation", moreInformation, booleanValue -> moreInformation = booleanValue);
-
+		addBooleanParameter("useFixedSpawProbability", useFixedSpawProbability, booleanValue -> useFixedSpawProbability = booleanValue, Arrays.asList("fixedSwapProbability"), new LinkedList<String>());
+		addDoubleParameter("fixedSwapProbability", fixedSwapProbability, doubleValue -> fixedSwapProbability = doubleValue, () -> fixedSwapProbability, useFixedSpawProbability, 0.0, 1.0);
+		addSeperator();
+		addBooleanParameter("Use Interval Mutation", useIntervalMutation, booleanValue -> useIntervalMutation = booleanValue, Arrays.asList("Probability for Frequency Mutation", "Scope of Mutation"), Arrays.asList("Probability for Bit-wise Mutation"));
+		addDoubleParameter("Probability for Frequency Mutation", mutateProbabilityInterval, doubleValue -> mutateProbabilityInterval = doubleValue, () -> mutateProbabilityInterval, useIntervalMutation, 0.0, 1.0);
+		addDoubleParameter("Probability for Bit-wise Mutation", fixedMutateProbability, doubleValue -> fixedMutateProbability = doubleValue, () -> fixedMutateProbability, !useIntervalMutation, 0.0, 1.0);
+		addDoubleParameter("Scope of Mutation", maxMutationPercent, doubleValue -> maxMutationPercent = doubleValue, () -> maxMutationPercent, useIntervalMutation, 0.0, 1.0);
+		addSeperator();
+		addBooleanParameter("Print Auxiliary Information", moreInformation, booleanValue -> moreInformation = booleanValue, new LinkedList<String>(), new LinkedList<String>());
+	
 	}
 	@Override
 	protected double evaluateState(DecoratedState actualstate, int amountOfAddedSwitch, double addedCableMeters, boolean moreInformation) {

+ 12 - 8
src/algorithm/topologie/PsoAlgorithm.java

@@ -1,7 +1,9 @@
 package algorithm.topologie;
 
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.HashSet;
+import java.util.LinkedList;
 import java.util.List;
 import java.util.ListIterator;
 import java.util.TreeSet;
@@ -35,16 +37,18 @@ public class PsoAlgorithm extends TopologieAlgorithmFramework {
 	public PsoAlgorithm(){
 		addIntParameter("Swarmsize", popsize, intValue -> popsize = intValue, () -> popsize, 1);
 		addIntParameter("Iterations", maxGenerations, intValue -> maxGenerations = intValue, () -> maxGenerations, 1);
+		addSeperator();
 		addDoubleParameter("Deviation", deviation, doubleValue -> deviation = doubleValue, () -> deviation, 0);
-		addDoubleParameter("Dependency", dependency, doubleValue -> dependency = doubleValue, () -> dependency, 2.001, 2.4);
-		addIntParameter("Mutation Frequency (Iteration)", mutationInterval, intValue -> mutationInterval = intValue, () -> mutationInterval, 0);
-		addBooleanParameter("Use Mutation Frequency", useIntervalMutation, booleanValue -> useIntervalMutation = booleanValue);
-		addDoubleParameter("Probability for Frequency Mutation", mutateProbabilityInterval, doubleValue -> mutateProbabilityInterval = doubleValue, () -> mutateProbabilityInterval, 0.0, 1.0);
-		addDoubleParameter("Probability for Bit-wise Mutation", mutationRate, doubleValue -> mutationRate = doubleValue, () -> mutationRate, 0.0, 1.0);
-		addDoubleParameter("Scope of Mutation", maxMutationPercent, doubleValue -> maxMutationPercent = doubleValue, () -> maxMutationPercent, 0.0, 1.0);
+		addDoubleParameter("Dependency", dependency, doubleValue -> dependency = doubleValue, () -> dependency, true, 2.001, 2.4);
 		addDoubleParameter("Particle Max-Velocity", maxVelocity, doubleValue -> maxVelocity = doubleValue, () -> maxVelocity, 0.0);
-		addBooleanParameter("Print Auxiliary Information", moreInformation, booleanValue -> moreInformation = booleanValue);
-
+		addSeperator();
+		addIntParameter("Mutation Frequency (Iteration)", mutationInterval, intValue -> mutationInterval = intValue, () -> mutationInterval, 0);
+		addBooleanParameter("Use Interval Mutation", useIntervalMutation, booleanValue -> useIntervalMutation = booleanValue, Arrays.asList("Probability for Frequency Mutation", "Scope of Mutation"), Arrays.asList("Probability for Bit-wise Mutation"));
+		addDoubleParameter("Probability for Frequency Mutation", mutateProbabilityInterval, doubleValue -> mutateProbabilityInterval = doubleValue, () -> mutateProbabilityInterval, useIntervalMutation, 0.0, 1.0);
+		addDoubleParameter("Probability for Bit-wise Mutation", mutationRate, doubleValue -> mutationRate = doubleValue, () -> mutationRate, !useIntervalMutation, 0.0, 1.0);
+		addDoubleParameter("Scope of Mutation", maxMutationPercent, doubleValue -> maxMutationPercent = doubleValue, () -> maxMutationPercent, useIntervalMutation, 0.0, 1.0);
+		addSeperator();
+		addBooleanParameter("Print Auxiliary Information", moreInformation, booleanValue -> moreInformation = booleanValue, new LinkedList<String>(), new LinkedList<String>());
 	}
 	
 	

+ 33 - 12
src/api/TopologieAlgorithmFramework.java

@@ -34,8 +34,12 @@ import javax.swing.JLabel;
 import javax.swing.JPanel;
 import javax.swing.JProgressBar;
 import javax.swing.JScrollPane;
+import javax.swing.JSeparator;
 import javax.swing.JSplitPane;
+import javax.swing.border.EmptyBorder;
 import javax.swing.text.NumberFormatter;
+
+import algorithm.objectiveFunction.TopologieObjectiveFunction;
 import classes.AbstractCanvasObject;
 import classes.Category;
 import classes.Edge;
@@ -66,6 +70,9 @@ public abstract class TopologieAlgorithmFramework implements AddOn{
 	private JPanel content = new JPanel();
 	protected Console console = new Console();
 	private JPanel borderPanel = new JPanel();
+	private HashMap<String, JPanel> panelMap = new HashMap<String, JPanel>();
+	
+	
 	
 	
 	//Settings groupNode
@@ -149,8 +156,9 @@ public abstract class TopologieAlgorithmFramework implements AddOn{
 		JPanel parameterPanel = new JPanel(null);
 		parameterPanel.setPreferredSize(new Dimension(510,300));
 		borderPanel.setLayout(new BoxLayout(borderPanel, BoxLayout.PAGE_AXIS));
-		addIntParameter("Repetitions", rounds, intInput -> rounds = intInput, () -> rounds, 1);
 		addIntParameter("Number of New Cables", amountOfNewCables, intInput -> amountOfNewCables = intInput, () -> amountOfNewCables, 0);
+		addSeperator();
+		addIntParameter("Repetitions", rounds, intInput -> rounds = intInput, () -> rounds, 1);
 		JScrollPane scrollPane = new JScrollPane(borderPanel);
 		scrollPane.setBounds(10, 0, 850, 292);
 		scrollPane.setBorder(BorderFactory.createEmptyBorder());
@@ -228,19 +236,24 @@ public abstract class TopologieAlgorithmFramework implements AddOn{
 
 
 
-
+	//addSeperator
+	protected void addSeperator() {
+		borderPanel.add(Box.createRigidArea(new Dimension(5, 5)));
+		borderPanel.add(new JSeparator());
+		borderPanel.add(Box.createRigidArea(new Dimension(5, 5)));
+	}
 
 
 	//int
 	protected void addIntParameter(String parameterName, int parameterValue, Consumer<Integer> setter, Supplier<Integer> getter) {
-		this.addIntParameter(parameterName, parameterValue, setter, getter, Integer.MIN_VALUE, Integer.MAX_VALUE);
+		this.addIntParameter(parameterName, parameterValue, setter, getter, true, Integer.MIN_VALUE, Integer.MAX_VALUE);
 	}
 	
 	protected void addIntParameter(String parameterName, int parameterValue, Consumer<Integer> setter, Supplier<Integer> getter, int parameterMinValue) {
-		this.addIntParameter(parameterName, parameterValue, setter, getter, parameterMinValue, Integer.MAX_VALUE);
+		this.addIntParameter(parameterName, parameterValue, setter, getter, true, parameterMinValue, Integer.MAX_VALUE);
 	}
 	
-	protected void addIntParameter(String parameterName, int parameterValue, Consumer<Integer> setter, Supplier<Integer> getter, int parameterMinValue, int parameterMaxValue) {
+	protected void addIntParameter(String parameterName, int parameterValue, Consumer<Integer> setter, Supplier<Integer> getter, boolean visible, int parameterMinValue, int parameterMaxValue) {
 		JPanel singleParameterPanel = new JPanel();
 		singleParameterPanel.setLayout(new BoxLayout(singleParameterPanel, BoxLayout.LINE_AXIS));
 		singleParameterPanel.setAlignmentX(0.0f);
@@ -315,23 +328,24 @@ public abstract class TopologieAlgorithmFramework implements AddOn{
 			stepsSizeLabel.setEnabled(enabled);
 			stepsSizeTextField.setEnabled(enabled);
 		});
-		
+		panelMap.put(parameterName, singleParameterPanel);
+		singleParameterPanel.setVisible(visible);
 		borderPanel.add(singleParameterPanel);
 	}
 	
 	
 	//double
 	protected void addDoubleParameter(String parameterName, double parameterValue, Consumer<Double> setter, Supplier<Double> getter) {
-		this.addDoubleParameter(parameterName, parameterValue, setter, getter, Double.MIN_VALUE, Double.MAX_VALUE);
+		this.addDoubleParameter(parameterName, parameterValue, setter, getter, true, Double.MIN_VALUE, Double.MAX_VALUE);
 	}
 	
 	
 	protected void addDoubleParameter(String parameterName, double parameterValue, Consumer<Double> setter, Supplier<Double> getter, double parameterMinValue) {
-		this.addDoubleParameter(parameterName, parameterValue, setter, getter, parameterMinValue, Double.MAX_VALUE);
+		this.addDoubleParameter(parameterName, parameterValue, setter, getter, true, parameterMinValue, Double.MAX_VALUE);
 	}
 	
 	
-	protected void addDoubleParameter(String parameterName, double parameterValue, Consumer<Double> setter, Supplier<Double> getter, double parameterMinValue, double parameterMaxValue) {
+	protected void addDoubleParameter(String parameterName, double parameterValue, Consumer<Double> setter, Supplier<Double> getter, boolean visible, double parameterMinValue, double parameterMaxValue) {
 		JPanel singleParameterPanel = new JPanel();
 		singleParameterPanel.setLayout(new BoxLayout(singleParameterPanel, BoxLayout.LINE_AXIS));
 		singleParameterPanel.setAlignmentX(0.0f);
@@ -411,19 +425,25 @@ public abstract class TopologieAlgorithmFramework implements AddOn{
 			stepsSizeLabel.setEnabled(enabled);
 			stepsSizeTextField.setEnabled(enabled);
 		});
-		
+		panelMap.put(parameterName, singleParameterPanel);
+		singleParameterPanel.setVisible(visible);
 		borderPanel.add(singleParameterPanel);
 	}
 	//boolean
-	protected void addBooleanParameter(String parameterName, boolean parameterValue, Consumer<Boolean> setter){
+	protected void addBooleanParameter(String parameterName, boolean parameterValue, Consumer<Boolean> setter, List<String> showParameterNames, List<String> hideParameterNames){
 		JPanel singleParameterPanel = new JPanel();
+		panelMap.put(parameterName, singleParameterPanel);
 		singleParameterPanel.setLayout(new BoxLayout(singleParameterPanel, BoxLayout.LINE_AXIS));
 		singleParameterPanel.setAlignmentX(0.0f);
 		singleParameterPanel.add(new JLabel(parameterName + ": "));
 		singleParameterPanel.add(Box.createHorizontalGlue());
 		JCheckBox useGroupNodeCheckBox = new JCheckBox();
+		useGroupNodeCheckBox.addActionListener(actionEvent -> {
+			setter.accept(useGroupNodeCheckBox.isSelected());
+			showParameterNames.forEach(string -> panelMap.get(string).setVisible(useGroupNodeCheckBox.isSelected()));
+			hideParameterNames.forEach(string -> panelMap.get(string).setVisible(!useGroupNodeCheckBox.isSelected()));
+		});
 		useGroupNodeCheckBox.setSelected(parameterValue);
-		useGroupNodeCheckBox.addActionListener(actionEvent -> setter.accept(useGroupNodeCheckBox.isSelected()));
 		singleParameterPanel.add(useGroupNodeCheckBox);
 		borderPanel.add(singleParameterPanel);
 	}
@@ -534,6 +554,7 @@ public abstract class TopologieAlgorithmFramework implements AddOn{
 			executeAlgoWithParameter();
 			
 		}
+		TopologieObjectiveFunction.log.clear();
 		updateVisual();
 		runProgressbar.finishedCancel();
 		control.guiDisable(false);

+ 47 - 0
src/classes/FloatLog.java

@@ -0,0 +1,47 @@
+package classes;
+
+import java.util.HashMap;
+import java.util.stream.Collectors;
+//To sample floats and get basic statistical values;
+public class FloatLog {
+	public class LogInfo{
+		public String parameterName;
+		public int sampleSize = 0;
+		public float min = Float.MAX_VALUE;
+		public float max = Float.MIN_VALUE;
+		private float sum = 0;
+		public float getAvg() {
+			if(sampleSize > 0)
+				return sum / (float)sampleSize;
+			return 0;
+		}
+		public void addSample(float sample) {
+			if(sample < min) min = sample;
+			if(sample > max) max = sample;
+			sum += sample;
+			sampleSize++;
+		}
+		public String toString() {
+			return "[" + parameterName + " in Range(" + min + ", " + max + ") with a Average of " + getAvg() + " from "+ sampleSize + " Smaples]"; 
+		}
+	}
+	public HashMap<String, LogInfo> logMap = new HashMap<String, LogInfo>();
+	public void addSample(String parameterName, float sample) {
+		//Puts the sample in the right LogInfo container or create a new container if not exist jet
+		if(logMap.containsKey(parameterName)) {
+			LogInfo info = logMap.get(parameterName);
+			info.addSample(sample);
+		}else {
+			LogInfo info = new LogInfo();
+			info.parameterName = parameterName;
+			info.addSample(sample);
+			logMap.put(parameterName, info);
+		}
+	}
+	public String toString() {
+		return logMap.values().stream().map(Object::toString).collect(Collectors.joining("\n"));
+	}
+	public void clear() {
+		logMap.clear();
+	}
+}