Browse Source

ExampleNetworks

Tom 4 years ago
parent
commit
eded089de1

+ 164 - 0
exampleNetworks/RandomizerExample/elements.json

@@ -0,0 +1,164 @@
+[
+    {
+        "name" : "Lights",
+        "minAmount" : 1,
+        "maxAmount" : 1,
+        "priority" : "Low",
+        "energy" : -100.0
+    }
+    ,{
+        "name" : "LED-TV",
+        "minAmount" : 1,
+        "maxAmount" : 2,
+        "priority" : "Low",
+        "energy" : -85.0
+    }
+    ,{
+        "name" : "Ceiling-Fan",
+        "minAmount" : 1,
+        "maxAmount" : 2,
+        "priority" : "Low",
+        "energy" : -70.0
+    }
+    ,{
+        "name" : "Coffee-Maker",
+        "minAmount" : 1,
+        "maxAmount" : 1,
+        "priority" : "Low",
+        "energy" : -800.0
+    }
+    ,{
+        "name" : "PC",
+        "minAmount" : 1,
+        "maxAmount" : 1,
+        "priority" : "Essential",
+        "energy" : -450.0,
+        "flexChance" : 0.5,
+	    "minCost" : 300,
+	    "maxCost" : 400,
+	    "minDuration" : 1,
+	    "maxDuration" : 10,
+	    "minCooldown" : 0,
+	    "maxCooldown" : 3
+    }
+	,{
+        "name" : "Fridge",
+        "minAmount" : 1,
+        "maxAmount" : 1,
+        "priority" : "Low",
+        "energy" : -300.0,
+        "flexChance" : 0.5,
+	    "minCost" : 100,
+	    "maxCost" : 200,
+	    "minDuration" : 1,
+	    "maxDuration" : 10,
+	    "minCooldown" : 0,
+	    "maxCooldown" : 3
+    }
+	,{
+        "name" : "Water-Heater",
+        "minAmount" : 1,
+        "maxAmount" : 1,
+        "priority" : "Medium",
+        "energy" : -1300.0,
+        "flexChance" : 0.5,
+	    "minCost" : 200,
+	    "maxCost" : 250,
+	    "minDuration" : 1,
+	    "maxDuration" : 1,
+	    "minCooldown" : 0,
+	    "maxCooldown" : 3
+    }
+	,{
+        "name" : "Microwave",
+        "minAmount" : 1,
+        "maxAmount" : 1,
+        "priority" : "Low",
+        "energy" : -700.0
+    }
+	,{
+        "name" : "Toaster",
+        "minAmount" : 1,
+        "maxAmount" : 1,
+        "priority" : "Low",
+        "energy" : -800.0
+    }
+	,{
+        "name" : "Washing-Machine",
+        "minAmount" : 1,
+        "maxAmount" : 1,
+        "energy" : -500.0,
+        "priority" : "Low",
+        "flexChance" : 0.5,
+	    "minCost" : 50,
+	    "maxCost" : 100,
+	    "minDuration" : 1,
+	    "maxDuration" : 10,
+	    "minCooldown" : 0,
+	    "maxCooldown" : 3
+    }
+	,{
+        "name" : "Solar-Panel",
+        "minAmount" : 1,
+        "maxAmount" : 1,
+        "priority" : "Low",
+        "energy" : 2000.0,
+        "flexChance" : 0.5,
+	    "minCost" : 120,
+	    "maxCost" : 300,
+	    "minDuration" : 1,
+	    "maxDuration" : 10,
+	    "minCooldown" : 0,
+	    "maxCooldown" : 3
+    }
+	,{
+        "name" : "Radio",
+        "minAmount" : 1,
+        "maxAmount" : 10,
+        "priority" : "Low",
+        "energy" : -50.0
+    }
+	,{
+        "name" : "Oven",
+        "minAmount" : 1,
+        "maxAmount" : 1,
+        "energy" : -2000.0,
+        "priority" : "Medium",
+        "flexChance" : 0.5,
+	    "minCost" : 200,
+	    "maxCost" : 350,
+	    "minDuration" : 1,
+	    "maxDuration" : 10,
+	    "minCooldown" : 0,
+	    "maxCooldown" : 3
+    }
+	,{
+        "name" : "Air-Conditioner",
+        "minAmount" : 1,
+        "maxAmount" : 1,
+        "priority" : "Low",
+        "energy" : -2500.0,
+        "flexChance" : 0.5,
+	    "minCost" : 100,
+	    "maxCost" : 250,
+	    "minDuration" : 1,
+	    "maxDuration" : 10,
+	    "minCooldown" : 0,
+	    "maxCooldown" : 3
+    }
+	,{
+        "name" : "Paper-Shredder",
+        "minAmount" : 1,
+        "maxAmount" : 1,
+        "priority" : "Low",
+        "energy" : -220.0
+    }
+	,{
+        "name" : "Vacuum-Cleaner",
+        "minAmount" : 1,
+        "maxAmount" : 1,
+        "priority" : "Low",
+        "energy" : -220.0
+    }
+	
+]

BIN
exampleNetworks/exampleNet.holon


File diff suppressed because it is too large
+ 2 - 0
plottAcoAlgo.txt


+ 6 - 5
src/exampleAlgorithms/Evaluation.java

@@ -33,11 +33,12 @@ public class Evaluation {
 		
 		// calculate object_fitness
 		for(DecoratedNetwork net : state.getNetworkList()) {
-			object_fitness += net.getConsumerList().stream().map(con -> holonObjectSupplyPenaltyFunction(con.getSupplyBarPercentage()) + inactiveHolonElementPenalty(con.getModel())).reduce(0.0, (a, b) -> (a + b));
-			object_fitness += net.getConsumerList().stream().map(con -> StateToDouble(con.getState())).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));
+			object_fitness += net.getConsumerList().stream().map(con -> holonObjectSupplyPenaltyFunction(con.getSupplyBarPercentage()) 
+																		+ StateToDouble(con.getState()) 
+																		+ inactiveHolonElementPenalty(con.getModel()) ).reduce(0.0, Double::sum);
+			object_fitness += net.getPassivNoEnergyList().stream().map(sup -> inactiveHolonElementPenalty(sup.getModel())).reduce(0.0, Double::sum);
+			object_fitness += net.getSupplierList().stream().map(sup -> inactiveHolonElementPenalty(sup.getModel())).reduce(0.0, Double::sum);
+			object_fitness += net.getConsumerSelfSuppliedList().stream().map(con -> inactiveHolonElementPenalty(con.getModel())).reduce(0.0, Double::sum);
 		}
 		// calculate flexibility fitness old cost flex
 		/*for(FlexWrapper flexWrapper :state.getFlexManager().getAllFlexWrapperWithState(FlexState.IN_USE)) {

+ 9 - 0
src/exampleAlgorithms/RandomPriority.java

@@ -18,6 +18,7 @@ import javax.swing.JSlider;
 import api.AddOn;
 import classes.AbstractCpsObject;
 import classes.CpsUpperNode;
+import classes.Flexibility;
 import classes.HolonElement;
 import classes.HolonElement.Priority;
 import classes.HolonObject;
@@ -180,6 +181,14 @@ public class RandomPriority implements AddOn {
 		}
 		control.calculateStateAndVisualForCurrentTimeStep();
 		control.updateCanvas();
+		List<Flexibility> flexList = control.getSimManager().getActualFlexManager().getAllFlexWrapper().stream().filter(flexwrapper -> flexwrapper.getFlex().offered).map(flex -> flex.getFlex()).collect(Collectors.toList());
+		long amountOfEssential = flexList.stream().filter(flex -> flex.getElement().getPriority() == Priority.Essential).count();
+		long amountOfHigh = flexList.stream().filter(flex -> flex.getElement().getPriority() == Priority.High).count();
+		long amountOfMedium = flexList.stream().filter(flex -> flex.getElement().getPriority() == Priority.Medium).count();
+		long amountOfLow = flexList.stream().filter(flex -> flex.getElement().getPriority() == Priority.Low).count();
+		long overall = amountOfEssential + amountOfHigh + amountOfMedium + amountOfLow;
+		System.out.println(" amountOfEssential: " + amountOfEssential  + " amountOfHigh: " + amountOfHigh + " amountOfMedium: " +amountOfMedium + " amountOfLow: " +amountOfLow + " of overall " + overall + "Flexes");
+	
 	}
 	
 	

+ 14 - 4
src/exampleAlgorithms/Randomizer.java

@@ -9,6 +9,7 @@ import java.text.NumberFormat;
 import java.util.ArrayList;
 import java.util.Hashtable;
 import java.util.List;
+import java.util.stream.Collectors;
 
 import javax.swing.BorderFactory;
 import javax.swing.BoxLayout;
@@ -29,6 +30,7 @@ import com.google.gson.JsonIOException;
 import com.google.gson.JsonParser;
 import com.google.gson.JsonSyntaxException;
 import com.google.gson.annotations.Expose;
+import com.google.gson.annotations.SerializedName;
 
 import api.AddOn;
 import classes.AbstractCpsObject;
@@ -36,6 +38,7 @@ import classes.Constrain;
 import classes.CpsUpperNode;
 import classes.Flexibility;
 import classes.HolonElement;
+import classes.HolonElement.Priority;
 import classes.HolonObject;
 import classes.HolonSwitch;
 import ui.controller.Control;
@@ -122,9 +125,9 @@ public class Randomizer implements AddOn {
 		readCatalogFromJson(file, holonElementCatalog);
 		holonElementCatalog.forEach(con -> con.checkValues());
 		
-		List<HolonObject> consumerList = new ArrayList<HolonObject>();
-		rollOutNodes(control.getModel().getObjectsOnCanvas(), consumerList, control.getModel().getCurIteration());
-		consumerList.forEach(con -> {
+		List<HolonObject> holonObjectList = new ArrayList<HolonObject>();
+		rollOutNodes(control.getModel().getObjectsOnCanvas(), holonObjectList, control.getModel().getCurIteration());
+		holonObjectList.forEach(con -> {
 			con.getElements().clear();
 			int randomAmountOfElementsToAdd = Random.nextIntegerInRange(minAmountOfElements, maxAmountOfElements + 1);
 			for(int i = 0; i < randomAmountOfElementsToAdd; i++) {
@@ -134,13 +137,16 @@ public class Randomizer implements AddOn {
 		});
 		control.calculateStateAndVisualForCurrentTimeStep();
 		control.updateCanvas();
+		
+		
 	}
 	
 	private void rollOutNodes(List<AbstractCpsObject> nodes, 	List<HolonObject> consumerList, int timeStep) {
 		for (AbstractCpsObject aCps : nodes) {
 			if (aCps instanceof HolonObject) {
 				HolonObject hO = (HolonObject) aCps;
-				if(hO.getEnergyAtTimeStep(control.getModel().getCurIteration()) < 0)consumerList.add(hO);
+				//if(hO.getEnergyAtTimeStep(control.getModel().getCurIteration()) < 0)
+				consumerList.add(hO);
 			}
 			else if(aCps instanceof CpsUpperNode) {
 				rollOutNodes(((CpsUpperNode)aCps).getNodes(), consumerList ,timeStep );
@@ -167,6 +173,9 @@ public class Randomizer implements AddOn {
 		public int minAmount;
 		public int maxAmount;
 		public float energy;
+		
+		public String priority;
+		
 		//Flexibility
 		public double flexChance;
 		@Expose
@@ -192,6 +201,7 @@ public class Randomizer implements AddOn {
 			HolonElement ele = new HolonElement(name, Random.nextIntegerInRange(minAmount, maxAmount + 1), energy , model);
 			ele.setActive(active);
 			if(Random.nextDouble() < flexChance)addFlex(ele, nameOfHolonObject);
+			ele.setPriority(Priority.valueOf(priority));
 			return ele;
 		}
 		

Some files were not shown because too many files changed in this diff