Browse Source

minor changes for the paper studf

Rolf Egert 5 years ago
parent
commit
16b1762dcb

+ 30 - 7
src/exampleAlgorithms/PSOAlgotihm.java

@@ -60,7 +60,8 @@ public class PSOAlgotihm implements Algorithm {
 	private int maxIterations = 100; 
 	private double limit = 0.01; 
 	private double dependency = 2.07; 
-	private int rounds = 20; 
+	private int rounds = 20;
+	private int mutationInterval = 0;
 	
 	//Settings For GroupNode using and plotting
 	private boolean append = false;
@@ -151,6 +152,10 @@ public class PSOAlgotihm implements Algorithm {
 		roundsLabel.setBounds(20, 160, 100, 20);
 		parameterPanel.add(roundsLabel);
 		
+		JLabel mutationIntervalLabel = new JLabel("Mutation Interval");
+		mutationIntervalLabel.setBounds(20, 185, 100, 20);
+		parameterPanel.add(mutationIntervalLabel);
+		
 		JLabel cautionLabel = new JLabel(
 				"Caution: High values in the fields of 'Swarm Size' and 'Max. Iteration' may take some time to calculate.");
 		cautionLabel.setFont(new Font("Serif", Font.ITALIC, 12));
@@ -262,10 +267,24 @@ public class PSOAlgotihm implements Algorithm {
 		
 		JFormattedTextField roundsTextField = new JFormattedTextField(roundsFormatter);
 		roundsTextField.setValue(rounds);
-		roundsTextField.setToolTipText("Amount of rounds to be runed with the same starting ");
+		roundsTextField.setToolTipText("Number of algorithm repetitions for the same starting situation ");
 		roundsTextField.addPropertyChangeListener(propertyChange -> rounds = Integer.parseInt((roundsTextField.getValue().toString())));
 		roundsTextField.setBounds(125, 160, 50, 20);
 		parameterPanel.add(roundsTextField);
+	//--- subsequently Rolf Did stuff ------------------------------------------------------------------------------------------
+		/*NumberFormatter mutationIntervalFormatter = new NumberFormatter(inte);
+		mutationIntervalFormatter.setMinimum(0);
+		mutationIntervalFormatter.setMaximum(maxIterations);
+		mutationIntervalFormatter.setCommitsOnValidEdit(true);*/
+		
+		JFormattedTextField mutationIntervalTextfield = new JFormattedTextField(integerFormatter);
+		mutationIntervalTextfield.setValue(mutationInterval);
+		mutationIntervalTextfield.setToolTipText("The number of Iterations after which one mutation iteration is conducted");
+		mutationIntervalTextfield.addPropertyChangeListener(propertyChange -> mutationInterval = Integer.parseInt((mutationIntervalTextfield.getValue().toString())));
+		mutationIntervalTextfield.setBounds(125, 185, 50, 20);
+		parameterPanel.add(mutationIntervalTextfield);
+	//--- previously Rolf Did stuff ------------------------------------------------------------------------------------------
+		
 		return parameterPanel;
 	}
 	public JPanel createButtonPanel() {
@@ -485,11 +504,14 @@ public class PSOAlgotihm implements Algorithm {
 		evaluation(globalBest, swarm);
 		runList.add(globalBest.value);
 		for (int iteration = 0; iteration < maxIterations ; iteration++) {
+			int mutationAllowed = iteration % mutationInterval;
 			for (int particleNumber = 0; particleNumber < swarmSize; particleNumber++) {
 				Particle particle = swarm.get(particleNumber);				
 				for(int index = 0; index < dimensions; index++) {
 					updateVelocity(particle, index, globalBest);
 					updateGenotype(particle, index);
+		//-------Rolf changes below------------------------
+				if(mutationAllowed == 0 && iteration != 0)
 					mutation(particle, index);
 					decode(particle, index);
 				}
@@ -614,7 +636,7 @@ public class PSOAlgotihm implements Algorithm {
 		for(DecoratedNetwork net : state.getNetworkList()) {
 			float production = net.getSupplierList().stream().map(supplier -> supplier.getEnergyToSupplyNetwork()).reduce(0.0f, (a, b) -> a + b);
 			float consumption = net.getConsumerList().stream().map(con -> con.getEnergyNeededFromNetwork()).reduce(0.0f, (a, b) -> a + b);
-			nw_fitness += Math.abs(production - consumption); //Energy is now everywhere positive
+			nw_fitness += Math.abs((production - consumption)/100); //Energy is now everywhere positive
 		}
 		
 		// calculate object_fitness
@@ -623,7 +645,8 @@ public class PSOAlgotihm implements Algorithm {
 			//warum war das im network fitness und nicht hier im Object fitness??
 			object_fitness += net.getConsumerList().stream().map(con -> StateToDouble(con.getState())).reduce(0.0, (a,b) -> (a+b));
 			//System.out.println("objectfitness for statestuff: " + object_fitness);
-			object_fitness += net.getPassivNoEnergyList().stream().map(con -> 1000.0).reduce(0.0, (a, b) -> (a + b));
+			//object_fitness += net.getPassivNoEnergyList().stream().map(con -> 1000.0).reduce(0.0, (a, b) -> (a + b));
+			object_fitness += net.getPassivNoEnergyList().stream().map(sup -> inactiveHolonElementPenalty(sup.getModel())).reduce(0.0, (a, b) -> (a + b));
 			object_fitness += net.getSupplierList().stream().map(sup -> inactiveHolonElementPenalty(sup.getModel())).reduce(0.0, (a, b) -> (a + b));
 			object_fitness += net.getConsumerSelfSuppliedList().stream().map(con -> inactiveHolonElementPenalty(con.getModel())).reduce(0.0, (a, b) -> (a + b));
 		}
@@ -688,11 +711,11 @@ public class PSOAlgotihm implements Algorithm {
 	private double StateToDouble(HolonObjectState state) {
 		switch (state) {
 		case NOT_SUPPLIED:
-			return 300.0;
+			return 150.0;
 		case NO_ENERGY:
-			return 100.0;
+			return 150.0;
 		case OVER_SUPPLIED:
-			return 200.0;
+			return 100.0;
 		case PARTIALLY_SUPPLIED:
 			return 100.0;
 		case PRODUCER:

+ 9 - 0
src/ui/controller/Control.java

@@ -864,6 +864,15 @@ public class Control {
     public int getNumberHolonObjects(ArrayList<AbstractCpsObject> list) {
         return objectController.getNumberHolonObjects(list);
     }
+    
+    /**
+     * Get the number of HolonObjects in the given List
+     *
+     * @param list
+     */
+    public ArrayList<HolonObject> getAllHolonObjects(ArrayList<AbstractCpsObject> list) {
+        return objectController.getAllHolonObjects(list);
+    }
 
 
     /**

+ 17 - 1
src/ui/controller/ObjectController.java

@@ -176,7 +176,23 @@ public class ObjectController {
         }
         return val;
     }
-
+/**
+ * Helper added by Rolf TODO: macht hier vll keinen Sinn...
+ */
+    public ArrayList<HolonObject> getAllHolonObjects(ArrayList<AbstractCpsObject> list){
+    	ArrayList<HolonObject> allObj = new ArrayList<HolonObject>();
+    	
+    	for (AbstractCpsObject obj : list) {
+            if (obj instanceof HolonObject) {
+                allObj.add((HolonObject)obj);
+            } else if (obj instanceof CpsUpperNode) {
+                 allObj.addAll(getAllHolonObjects(((CpsUpperNode) obj).getNodes()));
+            }
+        }
+    	
+    	
+    	return allObj;
+    }
    
 
     /**

+ 1 - 1
src/ui/controller/UpdateController.java

@@ -371,7 +371,7 @@ public class UpdateController {
 					float production = dGroupNode.getProductionFromSupplier();
 					Object[] consumptionObj = { "Total Consumption:",  consumption};
 					Object[] productionObj = { "Total Production:",  production};
-					Object[] difference = { "Difference:",  Math.abs(consumption - production)};
+					Object[] difference = { "Difference:", production - consumption};
 					
 					
 					model.getPropertyTable().addRow(title);