Browse Source

Randomizer Upgarde

Tom Troppmann 4 years ago
parent
commit
2571534f3a

+ 133 - 49
randomizerConfigFiles/elements.json

@@ -33,13 +33,25 @@
         "maxAmount" : 1,
         "priority" : "Essential",
         "energy" : -450.0,
-        "flexChance" : 0.95,
-	    "minCost" : 300,
-	    "maxCost" : 400,
-	    "minDuration" : 1,
-	    "maxDuration" : 10,
-	    "minCooldown" : 0,
-	    "maxCooldown" : 3
+		"onFlex" : {
+			"flexChance" : 0.95,
+			"minCost" : 300,
+			"maxCost" : 400,
+			"minDuration" : 1,
+			"maxDuration" : 10,
+			"minCooldown" : 0,
+			"maxCooldown" : 3
+		},
+		"offFlex" : {
+			"flexChance" : 0.95,
+			"minCost" : 300,
+			"maxCost" : 400,
+			"minDuration" : 1,
+			"maxDuration" : 10,
+			"minCooldown" : 0,
+			"maxCooldown" : 3
+		}
+        
     }
 	,{
         "name" : "Fridge",
@@ -47,13 +59,24 @@
         "maxAmount" : 1,
         "priority" : "Low",
         "energy" : -300.0,
-        "flexChance" : 0.95,
-	    "minCost" : 100,
-	    "maxCost" : 200,
-	    "minDuration" : 1,
-	    "maxDuration" : 10,
-	    "minCooldown" : 0,
-	    "maxCooldown" : 3
+		"onFlex" : {
+			"flexChance" : 0.95,
+			"minCost" : 100,
+			"maxCost" : 200,
+			"minDuration" : 1,
+			"maxDuration" : 10,
+			"minCooldown" : 0,
+			"maxCooldown" : 3
+		},
+		"offFlex" : {
+			"flexChance" : 0.95,
+			"minCost" : 100,
+			"maxCost" : 200,
+			"minDuration" : 1,
+			"maxDuration" : 10,
+			"minCooldown" : 0,
+			"maxCooldown" : 3
+		}
     }
 	,{
         "name" : "Water-Heater",
@@ -61,13 +84,25 @@
         "maxAmount" : 1,
         "priority" : "Medium",
         "energy" : -1300.0,
-        "flexChance" : 0.95,
-	    "minCost" : 200,
-	    "maxCost" : 250,
-	    "minDuration" : 1,
-	    "maxDuration" : 1,
-	    "minCooldown" : 0,
-	    "maxCooldown" : 3
+        
+		"onFlex" : {
+			"flexChance" : 0.95,
+			"minCost" : 200,
+			"maxCost" : 250,
+			"minDuration" : 1,
+			"maxDuration" : 1,
+			"minCooldown" : 0,
+			"maxCooldown" : 3
+		},
+		"offFlex" : {
+			"flexChance" : 0.95,
+			"minCost" : 200,
+			"maxCost" : 250,
+			"minDuration" : 1,
+			"maxDuration" : 1,
+			"minCooldown" : 0,
+			"maxCooldown" : 3
+		}
     }
 	,{
         "name" : "Microwave",
@@ -89,13 +124,25 @@
         "maxAmount" : 1,
         "energy" : -500.0,
         "priority" : "Low",
-        "flexChance" : 0.95,
-	    "minCost" : 50,
-	    "maxCost" : 100,
-	    "minDuration" : 1,
-	    "maxDuration" : 10,
-	    "minCooldown" : 0,
-	    "maxCooldown" : 3
+        
+		"onFlex" : {
+			"flexChance" : 0.95,
+			"minCost" : 50,
+			"maxCost" : 100,
+			"minDuration" : 1,
+			"maxDuration" : 10,
+			"minCooldown" : 0,
+			"maxCooldown" : 3
+		},
+		"offFlex" : {
+			"flexChance" : 0.95,
+			"minCost" : 50,
+			"maxCost" : 100,
+			"minDuration" : 1,
+			"maxDuration" : 10,
+			"minCooldown" : 0,
+			"maxCooldown" : 3
+		}
     }
 	,{
         "name" : "Solar-Panel",
@@ -103,13 +150,25 @@
         "maxAmount" : 1,
         "priority" : "Low",
         "energy" : 2000.0,
-        "flexChance" : 0.95,
-	    "minCost" : 120,
-	    "maxCost" : 300,
-	    "minDuration" : 1,
-	    "maxDuration" : 10,
-	    "minCooldown" : 0,
-	    "maxCooldown" : 3
+        
+		"onFlex" : {
+			"flexChance" : 0.95,
+			"minCost" : 120,
+			"maxCost" : 300,
+			"minDuration" : 1,
+			"maxDuration" : 10,
+			"minCooldown" : 0,
+			"maxCooldown" : 3
+		},
+		"offFlex" : {
+			"flexChance" : 0.95,
+			"minCost" : 120,
+			"maxCost" : 300,
+			"minDuration" : 1,
+			"maxDuration" : 10,
+			"minCooldown" : 0,
+			"maxCooldown" : 3
+		}
     }
 	,{
         "name" : "Radio",
@@ -124,13 +183,26 @@
         "maxAmount" : 1,
         "energy" : -2000.0,
         "priority" : "Medium",
-        "flexChance" : 0.95,
-	    "minCost" : 200,
-	    "maxCost" : 350,
-	    "minDuration" : 1,
-	    "maxDuration" : 10,
-	    "minCooldown" : 0,
-	    "maxCooldown" : 3
+		"onFlex" : {
+			"flexChance" : 0.95,
+			"minCost" : 200,
+			"maxCost" : 350,
+			"minDuration" : 1,
+			"maxDuration" : 10,
+			"minCooldown" : 0,
+			"maxCooldown" : 3
+
+		},
+		"offFlex" : {
+			"flexChance" : 0.95,
+			"minCost" : 200,
+			"maxCost" : 350,
+			"minDuration" : 1,
+			"maxDuration" : 10,
+			"minCooldown" : 0,
+			"maxCooldown" : 3
+
+		}
     }
 	,{
         "name" : "Air-Conditioner",
@@ -138,13 +210,25 @@
         "maxAmount" : 1,
         "priority" : "Low",
         "energy" : -2500.0,
-        "flexChance" : 0.95,
-	    "minCost" : 100,
-	    "maxCost" : 250,
-	    "minDuration" : 1,
-	    "maxDuration" : 10,
-	    "minCooldown" : 0,
-	    "maxCooldown" : 3
+        
+		"onFlex" : {
+			"flexChance" : 0.95,
+			"minCost" : 100,
+			"maxCost" : 250,
+			"minDuration" : 1,
+			"maxDuration" : 10,
+			"minCooldown" : 0,
+			"maxCooldown" : 3
+		},
+		"offFlex" : {
+			"flexChance" : 0.95,
+			"minCost" : 100,
+			"maxCost" : 250,
+			"minDuration" : 1,
+			"maxDuration" : 10,
+			"minCooldown" : 0,
+			"maxCooldown" : 3
+		}
     }
 	,{
         "name" : "Paper-Shredder",

+ 0 - 164
randomizerConfigFiles/elementsNoFlex.json

@@ -1,164 +0,0 @@
-[
-    {
-        "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.0,
-	    "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.0,
-	    "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.0,
-	    "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.0,
-	    "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.0,
-	    "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.0,
-	    "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.0,
-	    "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
-    }
-	
-]

+ 43 - 0
src/addOns/JSON/FlexibilitySketch.java

@@ -0,0 +1,43 @@
+package addOns.JSON;
+
+public class FlexibilitySketch{
+	public double flexChance;
+	public float minCost;
+	public float maxCost;
+	/** The Duration in TimeSteps how long the Flexibility is activated.*/
+	public int minDuration;
+	public int maxDuration;
+	/** The Duration after a successful activation between the next possible activation.*/
+	public int minCooldown;
+	public int maxCooldown;
+	
+	
+	public void checkValues(){
+
+		minDuration = Math.abs(minDuration);
+		maxDuration = Math.abs(maxDuration);
+		if(maxDuration < minDuration) {
+			//Swap
+			int intermediate = minDuration;
+			minDuration = maxDuration;
+			maxDuration = intermediate;
+		}
+		minCooldown = Math.abs(minCooldown);
+		maxCooldown = Math.abs(maxCooldown);
+		if(maxCooldown < minCooldown) {
+			//Swap
+			int intermediate = minCooldown;
+			minCooldown = maxCooldown;
+			maxCooldown = intermediate;
+		}
+		minCost = Math.abs(minCost);
+		maxCost = Math.abs(maxCost);
+		if(maxCost < minCost) {
+			//Swap
+			float intermediate = minCost;
+			minCost = maxCost;
+			maxCost = intermediate;
+		}
+		flexChance = Math.max(0, Math.min(1, flexChance)); //Clamp
+	}
+}

+ 110 - 0
src/addOns/JSON/HolonElementSketch.java

@@ -0,0 +1,110 @@
+package addOns.JSON;
+
+import classes.Constrain;
+import classes.Flexibility;
+import classes.HolonElement;
+import classes.HolonElement.Priority;
+import ui.model.Model;
+
+public class HolonElementSketch {
+	//HolonElement
+	public String name;
+	public int minAmount;
+	public int maxAmount;
+	public float energy;
+	
+	public String priority;
+	
+	public FlexibilitySketch onFlex;
+	public FlexibilitySketch offFlex;
+	
+	public HolonElementSketch(String name, int minAmount, int maxAmount, float energy) {
+		this.name = name;
+		this.minAmount = minAmount;
+		this.maxAmount = maxAmount;
+		this.energy = energy;
+	}
+	public HolonElement createHolonElement(Model model, boolean active, String nameOfHolonObject) {
+		HolonElement ele = new HolonElement(name, Random.nextIntegerInRange(minAmount, maxAmount + 1), energy , model);
+		ele.setActive(active);
+		if(onFlex != null && Random.nextDouble() < onFlex.flexChance)addFlex(ele, nameOfHolonObject, true);
+		if(offFlex != null && Random.nextDouble() < offFlex.flexChance)addFlex(ele, nameOfHolonObject, false);
+		ele.setPriority(Priority.valueOf(priority));
+		return ele;
+	}
+	
+	public void checkValues() {
+		minAmount = Math.abs(minAmount);
+		maxAmount = Math.abs(maxAmount);
+		if(maxAmount < minAmount) {
+			//Swap
+			int intermediate = minAmount;
+			minAmount = maxAmount;
+			maxAmount = intermediate;
+		}
+		if(onFlex != null) {
+			onFlex.checkValues();				
+		}
+		if(offFlex != null) {
+			onFlex.checkValues();				
+		}
+	}
+	
+	public void addFlex(HolonElement ele, String nameOfHolonObject,boolean onConstrain) {
+		Flexibility toCreateFlex = new Flexibility(ele);
+		FlexibilitySketch constrain = onConstrain?onFlex:offFlex;
+		
+		
+		toCreateFlex.name = nameOfHolonObject + "_" + ele.getEleName() + (onConstrain?"_OnFlex":"_OffFlex");
+		toCreateFlex.speed = 0;
+		toCreateFlex.setDuration(Random.nextIntegerInRange(constrain.minDuration, constrain.maxDuration+1));
+		toCreateFlex.cost = Random.nextFloatInRange(constrain.minCost, constrain.maxCost);
+		toCreateFlex.setCooldown(Random.nextIntegerInRange(constrain.minCooldown, constrain.maxCooldown+1));
+		toCreateFlex.offered=true;
+		if(onConstrain) {
+			toCreateFlex.constrainList.add(Constrain.createOnConstrain());
+		}else {
+			toCreateFlex.constrainList.add(Constrain.createOffConstrain());
+		}
+		ele.flexList.add(toCreateFlex);
+	}
+private static class Random{
+		
+		
+		private static java.util.Random random = new java.util.Random();
+	
+		/**
+		 * True or false
+		 * @return the random boolean.
+		 */
+		public static boolean nextBoolean(){
+			return random.nextBoolean();
+		}
+		/**
+		 * Between 0.0(inclusive) and 1.0 (exclusive)
+		 * @return the random double.
+		 */
+		public static double nextDouble() {
+			return random.nextDouble();
+		}
+		
+		public static float nextFloatInRange(float min, float max) {
+			return min + random.nextFloat() * Math.abs(max - min);
+		}
+		
+		
+		public static double nextDoubleInRange(double min, double max) {
+			return min + random.nextDouble() * Math.abs(max - min);
+		}
+		
+		/**
+		 * Random Int in Range [min;max[ with UniformDistirbution
+		 * @param min
+		 * @param max
+		 * @return
+		 */
+		public static int nextIntegerInRange(int min, int max) {
+			return min + random.nextInt(max - min);
+		}
+	}
+}

+ 86 - 95
src/addOns/RandomPriority.java → src/addOns/RandomOfferdFlexibility.java

@@ -1,7 +1,9 @@
 package addOns;
 
 import java.awt.BorderLayout;
+import java.awt.Component;
 import java.awt.Dimension;
+import java.awt.GridLayout;
 import java.util.ArrayList;
 import java.util.Hashtable;
 import java.util.List;
@@ -10,6 +12,7 @@ import java.util.stream.Collectors;
 import javax.swing.BorderFactory;
 import javax.swing.BoxLayout;
 import javax.swing.JButton;
+import javax.swing.JCheckBox;
 import javax.swing.JFrame;
 import javax.swing.JLabel;
 import javax.swing.JPanel;
@@ -32,16 +35,7 @@ import ui.controller.Control;
  */
 
 
-public class RandomPriority implements AddOn {
-	/**
-	 * Its like a Gradient the Values are on one Axis from Start to End:
-	 * |--start--lm--mh--he--end--|
-	 * lm: lowMedium
-	 * mh: mediumHigh
-	 * he: highEssential
-	 */
-	private int lm = 25 , mh = 50, he = 75;
-	private final int start = 0, end = 100;
+public class RandomOfferdFlexibility implements AddOn {
 	
 	
 	
@@ -50,14 +44,32 @@ public class RandomPriority implements AddOn {
 	private Control  control;
 	
 	private JPanel content = new JPanel();
-	private JSlider lowChanceSlider = new JSlider(JSlider.HORIZONTAL,0, 100, lm - start);
-	private JSlider mediumChanceSlider = new JSlider(JSlider.HORIZONTAL,0, 100, mh - lm);
-	private JSlider highChanceSlider = new JSlider(JSlider.HORIZONTAL,0, 100, he - mh);
-	private JSlider essentialChanceSlider = new JSlider(JSlider.HORIZONTAL,0, 100, end - he);
+	private JSlider activeSlider = new JSlider(JSlider.HORIZONTAL,0, 100, 50);
+
+
+
+	
+	private JCheckBox lowCheckbox = new JCheckBox("Low", true);
+	private JCheckBox mediumCheckbox = new JCheckBox("Medium", true);
+	private JCheckBox highCheckbox = new JCheckBox("High", true);
+	private JCheckBox essentialCheckbox = new JCheckBox("Essential", true);
+	private JSlider lowFlexTargetSlider = new JSlider(JSlider.HORIZONTAL,0, 100, 50);
+	private JSlider mediumFlexTargetSlider = new JSlider(JSlider.HORIZONTAL,0, 100, 50);
+	private JSlider highFlexTargetSlider = new JSlider(JSlider.HORIZONTAL,0, 100, 50);
+	private JSlider essentialFlexTargetSlider = new JSlider(JSlider.HORIZONTAL,0, 100, 50);
+
+	private JLabel lowPositiveLabel = new JLabel("0(0)");
+	private JLabel mediumPositiveLabel = new JLabel("0(0)");
+	private JLabel highPositiveLabel = new JLabel("0(0)");
+	private JLabel essentialPositiveLabel = new JLabel("0(0)");
+	private JLabel lowNegativeLabel = new JLabel("0(0)");
+	private JLabel mediumNegativeLabel = new JLabel("0(0)");
+	private JLabel highNegativeLabel = new JLabel("0(0)");
+	private JLabel essentialNegativeLabel = new JLabel("0(0)");
 	public static void main(String[] args)
 	{
 	      JFrame newFrame = new JFrame("exampleWindow");
-	      RandomPriority instance = new RandomPriority();
+	      RandomOfferdFlexibility instance = new RandomOfferdFlexibility();
 	      newFrame.setContentPane(instance.getPanel());
 	      newFrame.pack();
 	      newFrame.setVisible(true);
@@ -66,117 +78,96 @@ public class RandomPriority implements AddOn {
 	
 	
 	
-	public RandomPriority(){
+	public RandomOfferdFlexibility(){
 		content.setLayout(new BorderLayout());
 		content.add(createParameterPanel(), BorderLayout.CENTER);
+		content.add(createFlexPanel(), BorderLayout.EAST);
+		
 		JButton buttonRun = new JButton("Run");
 		buttonRun.addActionListener(actionEvent -> run());
 		content.add(buttonRun, BorderLayout.PAGE_END);
-		content.setPreferredSize(new Dimension(300,300));
+
+		//content.setPreferredSize(new Dimension(300,500));
+	}
+	private JPanel createFlexPanel() {
+		JPanel flexPanel = new JPanel();
+		flexPanel.setBorder(BorderFactory.createTitledBorder("Flexibility"));
+		GridLayout experimentLayout = new GridLayout(0,4);
+		flexPanel.setLayout(experimentLayout);
+		
+		//Label
+		
+		flexPanel.add(new JLabel("Priority:"));
+		flexPanel.add(new JLabel("Target:"));
+		flexPanel.add(new JLabel("PositiveAmount:"));
+		flexPanel.add(new JLabel("NegativeAmount:"));
+		
+		flexPanel.add(lowCheckbox);
+		flexPanel.add(initVisualizeSliderFlexibility(this.lowFlexTargetSlider, "PositivNegativ"));
+		flexPanel.add(this.lowPositiveLabel);
+		flexPanel.add(this.lowNegativeLabel);
+		
+		flexPanel.add(mediumCheckbox);
+		flexPanel.add(initVisualizeSliderFlexibility(this.mediumFlexTargetSlider, "PositivNegativ"));
+		flexPanel.add(this.mediumPositiveLabel);
+		flexPanel.add(this.mediumNegativeLabel);
+		
+		flexPanel.add(highCheckbox);
+		flexPanel.add(initVisualizeSliderFlexibility(this.highFlexTargetSlider, "PositivNegativ"));
+		flexPanel.add(this.highPositiveLabel);
+		flexPanel.add(this.highNegativeLabel);
+		
+		flexPanel.add(essentialCheckbox);
+		flexPanel.add(initVisualizeSliderFlexibility(this.essentialFlexTargetSlider, "PositivNegativ"));
+		flexPanel.add(this.essentialPositiveLabel);
+		flexPanel.add(this.essentialNegativeLabel);
+		
+		return flexPanel;
 	}
+
+
+
 	private JPanel createParameterPanel() {
+		JPanel centerPanel = new JPanel();
 		JPanel parameterPanel = new JPanel();
+		parameterPanel.setBorder(BorderFactory.createTitledBorder("Priority"));
 		parameterPanel.setLayout(new BoxLayout(parameterPanel, BoxLayout.PAGE_AXIS));
 		createParamaterSlider(parameterPanel);
-		return parameterPanel;
+		
+		
+		centerPanel.add(parameterPanel);
+		return centerPanel;
 	}
 	private void createParamaterSlider(JPanel parameterPanel) {
 		
-		parameterPanel.add(initVisualizeSlider(this.lowChanceSlider, "Low"));
-		parameterPanel.add(initVisualizeSlider(this.mediumChanceSlider, "Medium"));
-		parameterPanel.add(initVisualizeSlider(this.highChanceSlider, "High"));
-		parameterPanel.add(initVisualizeSlider(this.essentialChanceSlider, "Essential"));
-		
-		
-		lowChanceSlider.addChangeListener(actionEvent ->{
-			setLM(lowChanceSlider.getValue());
-			updateSliders();
-			System.out.println("lowChance = " +lowChanceSlider.getValue());
-		});
-		mediumChanceSlider.addChangeListener(actionEvent ->{
-			if(lm + mediumChanceSlider.getValue() <= 100) setMH(lm + mediumChanceSlider.getValue());
-			else setLM(end - mediumChanceSlider.getValue());
-			updateSliders();
-			System.out.println("mediumChance = " +  mediumChanceSlider.getValue());
-		});
-		highChanceSlider.addChangeListener(actionEvent ->{
-			if(mh + highChanceSlider.getValue() <= 100) setHE(mh + highChanceSlider.getValue());
-			else setMH(end - highChanceSlider.getValue());
-			updateSliders();
-			System.out.println("highChance = " +highChanceSlider.getValue());
-		});
-		essentialChanceSlider.addChangeListener(actionEvent ->{
-			setHE(end - essentialChanceSlider.getValue());
-			updateSliders();
-			System.out.println("essentialChance = " +essentialChanceSlider.getValue());
-		});
+
+		
 		
 		
 		
 	}
 
-	private void setLM(int value) {
-		lm = clamp(value, 0, 100);
-		if(lm > mh) mh = lm;
-		if(lm > he) he = lm;
-	}
-	
-	private void setMH(int value) {
-		mh = clamp(value, 0, 100);
-		if(mh < lm) lm = mh;
-		if(mh > he) he = mh;
-	}
-	
-	private void setHE(int value) {
-		he = clamp(value, 0, 100);
-		if(he < lm) lm = he;
-		if(he < mh) mh = he;
-	}
-	
-	
-	private int clamp(int input, int min , int max) {
-		return Math.max(min, Math.min(max, input));
-	}
-	
-	
-	private void updateSliders(){
-		lowChanceSlider.setValue(lm - start);
-		mediumChanceSlider.setValue(mh - lm);
-		highChanceSlider.setValue(he - mh);
-		essentialChanceSlider.setValue(end - he);
-	}
-	
-	
-
-	private JSlider initVisualizeSlider(JSlider jslider, String name) {
-		jslider.setBorder(BorderFactory.createTitledBorder(name));
+	private JSlider initVisualizeSliderFlexibility(JSlider jslider, String name) {
 		jslider.setMajorTickSpacing(50);
 		jslider.setMinorTickSpacing(5);
 		jslider.setPaintTicks(true);
 		Hashtable<Integer, JLabel> labelTable = new Hashtable<Integer, JLabel>();
-		labelTable.put( Integer.valueOf( 0 ), new JLabel("0.0") );
-		labelTable.put( Integer.valueOf( 50 ), new JLabel("0.5") );
-		labelTable.put( Integer.valueOf( 100 ), new JLabel("1.0") );
+		labelTable.put( Integer.valueOf( 0 ), new JLabel("Positiv") );
+		labelTable.put( Integer.valueOf( 100 ), new JLabel("Negativ") );
 		jslider.setLabelTable( labelTable );
 		jslider.setPaintLabels(true);
 		return jslider;
 	}
+	
+	
+	
 	private void run() {
 		//control.getModel().getObjectsOnCanvas().stream().filter(aCps -> aCps instanceof HolonObject)
 		List<HolonElement> elementList = createListOfHolonObjects(control.getModel().getObjectsOnCanvas()).stream().flatMap(hObject -> hObject.getElements().stream()).collect(Collectors.toList());
 		for(HolonElement element : elementList) {
+			element.setActive(Math.random() * 100.0 < activeSlider.getValue());
 			// Generate a random number between 0 and 100
-			double randomDoubleInRange = Math.random() * 100.0;
-			if(randomDoubleInRange <= lm) {
-				element.setPriority(Priority.Low);
-			} else if(randomDoubleInRange <= mh) {
-				element.setPriority(Priority.Medium);
-			} else if(randomDoubleInRange <= he) {
-				element.setPriority(Priority.High);
-			} else {
-				element.setPriority(Priority.Essential);
-			}
-			//System.out.println(randomDoubleInRange + ":" + element.getPriority());
+			
 			
 		}
 		control.calculateStateAndVisualForCurrentTimeStep();

+ 143 - 158
src/addOns/Randomizer.java

@@ -7,19 +7,26 @@ import java.io.FileNotFoundException;
 import java.io.FileReader;
 import java.text.NumberFormat;
 import java.util.ArrayList;
+import java.util.Comparator;
+import java.util.HashMap;
 import java.util.Hashtable;
 import java.util.List;
 import java.util.stream.Collectors;
 
 import javax.swing.BorderFactory;
+import javax.swing.Box;
 import javax.swing.BoxLayout;
+import javax.swing.ImageIcon;
 import javax.swing.JButton;
+import javax.swing.JCheckBox;
 import javax.swing.JFileChooser;
 import javax.swing.JFormattedTextField;
 import javax.swing.JFrame;
 import javax.swing.JLabel;
 import javax.swing.JPanel;
+import javax.swing.JScrollPane;
 import javax.swing.JSlider;
+import javax.swing.JSplitPane;
 import javax.swing.filechooser.FileNameExtensionFilter;
 import javax.swing.text.NumberFormatter;
 
@@ -32,6 +39,7 @@ import com.google.gson.JsonSyntaxException;
 import com.google.gson.annotations.Expose;
 import com.google.gson.annotations.SerializedName;
 
+import addOns.JSON.HolonElementSketch;
 import api.AddOn;
 import classes.AbstractCanvasObject;
 import classes.Constrain;
@@ -43,12 +51,20 @@ import classes.HolonObject;
 import classes.HolonSwitch;
 import ui.controller.Control;
 import ui.model.Model;
+import ui.view.RandomPriotity;
+import utility.Random;
+import utility.Util;
 
 public class Randomizer implements AddOn {
 	private Control  control;
 	private int minAmountOfElements = 3;
 	private int maxAmountOfElements = 7;
 	private JPanel content = new JPanel();
+	private JPanel tablePanel = new JPanel();
+	private RandomPriotity prioPanel = new RandomPriotity();
+	private JCheckBox priorityCheckbox = new JCheckBox("Random");
+	private boolean useRandomPriority = true;
+	
 	//To Test the Layout Faster   
 	public static void main(String[] args)
     {
@@ -62,23 +78,92 @@ public class Randomizer implements AddOn {
 	private File file;
 	public double randomChance = 1.0;
 	
+	
+	private HashMap<HolonObject, Boolean> objectMap = new HashMap<HolonObject, Boolean>();
+	private List<JCheckBox> checkboxList = new ArrayList<JCheckBox>();
+	
+	
+	
+	
+	
+	
 	public Randomizer(){
+		for(int i = 0; i < 30; i++) {
+			objectMap.put(new HolonObject("dude"), true);
+		}
 		content.setLayout(new BorderLayout());
-		content.add(createParameterPanel(), BorderLayout.CENTER);
+		JSplitPane splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT, createParameterPanel(), createFilterPanel());
+		splitPane.setDividerLocation(0.5);
+		content.add(splitPane, BorderLayout.CENTER);
+		
 		JButton buttonRun = new JButton("Run");
 		buttonRun.addActionListener(actionEvent -> run());
 		content.add(buttonRun, BorderLayout.PAGE_END);
-		content.setPreferredSize(new Dimension(300,300));
 	}
-	private JPanel createParameterPanel() {
-		JPanel parameterPanel = new JPanel(null);
-		parameterPanel.setPreferredSize(new Dimension(300,300));
+	private JScrollPane createFilterPanel() {
+		//Table
+		
+		tablePanel.setLayout(new BoxLayout(tablePanel, BoxLayout.PAGE_AXIS));
+		JScrollPane scrollPanel = new JScrollPane(tablePanel);
+		scrollPanel.setPreferredSize(new Dimension(300,300));
+		
+		
+		
+		fillTablePanel();
+		return scrollPanel;
+	}
+	
+	private void fillTablePanel() {
+		//Clear old Data
+		tablePanel.removeAll();
+		checkboxList.clear();
+		
+		//HeadPanel
+		JPanel headPanel = new JPanel();
+		headPanel.setLayout(new BoxLayout(headPanel, BoxLayout.LINE_AXIS));
+		headPanel.add(new JLabel("FILTER"));
+		headPanel.add(Box.createHorizontalGlue());
+		headPanel.add(new JLabel("SelectAll"));
+		JCheckBox selectAllCheckbox = new JCheckBox();
+		selectAllCheckbox.setSelected(true);
+		selectAllCheckbox.addItemListener(input -> checkboxList.forEach(box -> box.setSelected(selectAllCheckbox.isSelected())));
+		headPanel.add(selectAllCheckbox);
+		tablePanel.add(headPanel);
+		
+		
+		//Entrys
+		int lineSpace = 20;
+		for(HolonObject hObject: objectMap.keySet().stream().sorted(Comparator.comparing(ob -> ob.getName())).collect(Collectors.toList())) {
+			//Entry
+			JPanel entryPanel = new JPanel();
+			entryPanel.setLayout(new BoxLayout(entryPanel, BoxLayout.LINE_AXIS));
+			JLabel label = new JLabel(hObject.getName() + "[" + hObject.getId() + "]", new ImageIcon(Util.loadImage(hObject.getImage(), lineSpace, lineSpace)), JLabel.LEFT);
+			entryPanel.add(label);
+			entryPanel.add(Box.createHorizontalGlue());
+			JCheckBox checkbox = new JCheckBox();
+			checkbox.setSelected(true);
+			checkbox.addItemListener(change -> {
+				objectMap.put(hObject, checkbox.isSelected());
+				System.out.println("hObject:" + hObject + " changed to " + checkbox.isSelected());
+			});
+			checkboxList.add(checkbox);
+			entryPanel.add(checkbox);
+			tablePanel.add(entryPanel);
+		}
+	}
+	
+	
+	private JSplitPane createParameterPanel() {
+		
+		JPanel choosePanel = new JPanel(null);
+		choosePanel.setPreferredSize(new Dimension(300,200));
+		choosePanel.setMinimumSize(new Dimension(300,200));
 		JLabel minAmount = new JLabel("minAmountOfElements:");
 		minAmount.setBounds(20, 60 , 200, 20);
-		parameterPanel.add(minAmount);
+		choosePanel.add(minAmount);
 		JLabel maxAmount = new JLabel("maxAmountOfElements:");
 		maxAmount.setBounds(20, 85 , 200, 20);
-		parameterPanel.add(maxAmount);
+		choosePanel.add(maxAmount);
 		
 		//Integer formatter
 		NumberFormat format = NumberFormat.getIntegerInstance();
@@ -94,27 +179,41 @@ public class Randomizer implements AddOn {
 		minAmountTextField.setToolTipText("Only positive Integer.");
 		minAmountTextField.addPropertyChangeListener(actionEvent -> this.minAmountOfElements = Integer.parseInt(minAmountTextField.getValue().toString()));
 		minAmountTextField.setBounds(220, 60, 50, 20);
-		parameterPanel.add(minAmountTextField);
+		choosePanel.add(minAmountTextField);
 		
 		JFormattedTextField maxAmountTextField = new  JFormattedTextField(integerFormatter);
 		maxAmountTextField.setValue(this.maxAmountOfElements);
 		maxAmountTextField.setToolTipText("Only positive Integer.");
 		maxAmountTextField.addPropertyChangeListener(actionEvent -> this.maxAmountOfElements = Integer.parseInt(maxAmountTextField.getValue().toString()));
 		maxAmountTextField.setBounds(220, 85, 50, 20);
-		parameterPanel.add(maxAmountTextField);
-		
+		choosePanel.add(maxAmountTextField);
 		
 		JButton chooseFileButton = new JButton("Choose File");
 		chooseFileButton.setBounds(20, 10, 200, 30);
 		chooseFileButton.addActionListener(actionEvent -> file = openCatalogFile());
-		parameterPanel.add(chooseFileButton);
+		choosePanel.add(chooseFileButton);
 		
 		
 		JSlider bitSlider = createFlipChanceSlider();
 		bitSlider.setBounds(10, 110, 280, 80);
-		parameterPanel.add(bitSlider);
+		choosePanel.add(bitSlider);
+		
+		JPanel prioritySelectionPanel = new JPanel();
+		prioritySelectionPanel.setLayout(new BoxLayout(prioritySelectionPanel, BoxLayout.PAGE_AXIS));
+		//priorityCheckbox.setAlignmentY(0.0f);
+		//selection
+		prioritySelectionPanel.add(this.priorityCheckbox);
+		priorityCheckbox.addItemListener(change -> {
+			prioPanel.setEnabled(priorityCheckbox.isSelected());
+			useRandomPriority = priorityCheckbox.isSelected();
+		});
+		priorityCheckbox.setSelected(useRandomPriority);
 		
 		
+		prioritySelectionPanel.add(prioPanel);
+		JSplitPane parameterPanel = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, choosePanel, prioritySelectionPanel);
+		parameterPanel.setPreferredSize(new Dimension(600,200));
+		
 		return parameterPanel;
 	}
 	
@@ -124,16 +223,21 @@ public class Randomizer implements AddOn {
 		if(file == null) return;
 		readCatalogFromJson(file, holonElementCatalog);
 		holonElementCatalog.forEach(con -> con.checkValues());
-		
-		List<HolonObject> holonObjectList = new ArrayList<HolonObject>();
-		rollOutNodes(control.getModel().getObjectsOnCanvas(), holonObjectList, control.getModel().getCurIteration());
-		holonObjectList.forEach(con -> {
-			con.getElements().clear();
+		objectMap.forEach((hObject, state) ->{
+			//Ignore Filtered objects 
+			System.out.println("hObject:" + hObject + " state:" + state);
+			if(!state) {
+				return;
+			}
+			//Randomize
+			hObject.getElements().clear();
 			int randomAmountOfElementsToAdd = Random.nextIntegerInRange(minAmountOfElements, maxAmountOfElements + 1);
 			for(int i = 0; i < randomAmountOfElementsToAdd; i++) {
-				HolonElement ele = holonElementCatalog.get(Random.nextIntegerInRange(0, holonElementCatalog.size())).createHolonElement(control.getModel(), Random.nextDouble() < randomChance , con.getName());
-				con.getElements().add(ele);				
+				HolonElement ele = holonElementCatalog.get(Random.nextIntegerInRange(0, holonElementCatalog.size())).createHolonElement(control.getModel(), Random.nextDouble() < randomChance , hObject.getName());
+				if(this.useRandomPriority) ele.setPriority(prioPanel.getPriority());
+				hObject.getElements().add(ele);				
 			}
+			
 		});
 		control.calculateStateAndVisualForCurrentTimeStep();
 		control.updateCanvas();
@@ -141,21 +245,26 @@ public class Randomizer implements AddOn {
 		
 	}
 	
-	private void rollOutNodes(List<AbstractCanvasObject> nodes, 	List<HolonObject> consumerList, int timeStep) {
+	private void fillObjectMap(List<AbstractCanvasObject> nodes) {
 		for (AbstractCanvasObject aCps : nodes) {
 			if (aCps instanceof HolonObject) {
 				HolonObject hO = (HolonObject) aCps;
-				//if(hO.getEnergyAtTimeStep(control.getModel().getCurIteration()) < 0)
-				consumerList.add(hO);
+				objectMap.put(hO, true);
+				
 			}
 			else if(aCps instanceof GroupNode) {
-				rollOutNodes(((GroupNode)aCps).getNodes(), consumerList ,timeStep );
+				fillObjectMap(((GroupNode)aCps).getNodes());
 			}
 		}
 		
 	}
 	
-	
+	public void updateFilterList() {
+		objectMap.clear();
+		fillObjectMap(control.getModel().getObjectsOnCanvas());
+		
+		this.fillTablePanel();
+	}
 	
 	@Override
 	public JPanel getPanel() {
@@ -165,103 +274,11 @@ public class Randomizer implements AddOn {
 	public void setController(Control control) {
 		this.control = control;
 		
+		//Update Filter List
+		updateFilterList();
 	}
+	
 
-	private class HolonElementSketch {
-		//HolonElement
-		public String name;
-		public int minAmount;
-		public int maxAmount;
-		public float energy;
-		
-		public String priority;
-		
-		//Flexibility
-		public double flexChance;
-		@Expose
-		public float minCost;
-		public float maxCost;
-		
-		/** The Duration in TimeSteps how long the Flexibility is activated.*/
-		private int minDuration;
-		private int maxDuration;
-		/** The Duration after a successful activation between the next possible activation.*/
-		private int minCooldown;
-		private int maxCooldown;
-		
-		
-		
-		public HolonElementSketch(String name, int minAmount, int maxAmount, float energy) {
-			this.name = name;
-			this.minAmount = minAmount;
-			this.maxAmount = maxAmount;
-			this.energy = energy;
-		}
-		public HolonElement createHolonElement(Model model, boolean active, String nameOfHolonObject) {
-			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;
-		}
-		
-		public void checkValues() {
-			minAmount = Math.abs(minAmount);
-			maxAmount = Math.abs(maxAmount);
-			if(maxAmount < minAmount) {
-				//Swap
-				int intermediate = minAmount;
-				minAmount = maxAmount;
-				maxAmount = intermediate;
-			}
-			
-			minDuration = Math.abs(minDuration);
-			maxDuration = Math.abs(maxDuration);
-			if(maxDuration < minDuration) {
-				//Swap
-				int intermediate = minDuration;
-				minDuration = maxDuration;
-				maxDuration = intermediate;
-			}
-			minCooldown = Math.abs(minCooldown);
-			maxCooldown = Math.abs(maxCooldown);
-			if(maxCooldown < minCooldown) {
-				//Swap
-				int intermediate = minCooldown;
-				minCooldown = maxCooldown;
-				maxCooldown = intermediate;
-			}
-			minCost = Math.abs(minCost);
-			maxCost = Math.abs(maxCost);
-			if(maxCost < minCost) {
-				//Swap
-				float intermediate = minCost;
-				minCost = maxCost;
-				maxCost = intermediate;
-			}
-			flexChance = Math.max(0, Math.min(1, flexChance)); //Clamp
-		}
-		
-		public void addFlex(HolonElement ele, String nameOfHolonObject) {
-			Flexibility toCreateFlex = new Flexibility(ele);
-			boolean flexType = ele.isActive();
-			
-			
-			
-			toCreateFlex.name = nameOfHolonObject + "_" + ele.getEleName() + (flexType?"_OnFlex":"_OffFlex");
-			toCreateFlex.speed = 0;
-			toCreateFlex.setDuration(Random.nextIntegerInRange(minDuration, maxDuration+1));
-			toCreateFlex.cost = Random.nextFloatInRange(minCost, maxCost);
-			toCreateFlex.setCooldown(Random.nextIntegerInRange(minCooldown, maxCooldown+1));
-			toCreateFlex.offered=true;
-			if(flexType) {
-				toCreateFlex.constrainList.add(Constrain.createOnConstrain());
-			}else {
-				toCreateFlex.constrainList.add(Constrain.createOffConstrain());
-			}
-			ele.flexList.add(toCreateFlex);
-		}
-	}
 	private JSlider createFlipChanceSlider() {
 		JSlider flipChance =new JSlider(JSlider.HORIZONTAL,0, 100, 100);
 		flipChance.setBorder(BorderFactory.createTitledBorder("ActiveProbability"));
@@ -272,7 +289,11 @@ public class Randomizer implements AddOn {
 		labelTable.put( Integer.valueOf(0), new JLabel("0.0") );
 		labelTable.put( Integer.valueOf(50), new JLabel("0.5") );
 		labelTable.put( Integer.valueOf(100), new JLabel("1.0") );
-		flipChance.addChangeListener(actionEvent ->randomChance  =(double)flipChance.getValue()/100.0);
+		flipChance.setToolTipText("" +randomChance);
+		flipChance.addChangeListener(actionEvent ->{
+			randomChance  =(double)flipChance.getValue()/100.0;
+			flipChance.setToolTipText("" +randomChance);
+		});
 		flipChance.setLabelTable( labelTable );
 		flipChance.setPaintLabels(true);
 		return flipChance;
@@ -280,45 +301,7 @@ public class Randomizer implements AddOn {
 	
 	
 	
-	private static class Random{
-		
-		
-		private static java.util.Random random = new java.util.Random();
 	
-		/**
-		 * True or false
-		 * @return the random boolean.
-		 */
-		public static boolean nextBoolean(){
-			return random.nextBoolean();
-		}
-		/**
-		 * Between 0.0(inclusive) and 1.0 (exclusive)
-		 * @return the random double.
-		 */
-		public static double nextDouble() {
-			return random.nextDouble();
-		}
-		
-		public static float nextFloatInRange(float min, float max) {
-			return min + random.nextFloat() * Math.abs(max - min);
-		}
-		
-		
-		public static double nextDoubleInRange(double min, double max) {
-			return min + random.nextDouble() * Math.abs(max - min);
-		}
-		
-		/**
-		 * Random Int in Range [min;max[ with UniformDistirbution
-		 * @param min
-		 * @param max
-		 * @return
-		 */
-		public static int nextIntegerInRange(int min, int max) {
-			return min + random.nextInt(max - min);
-		}
-	}
 	private void readCatalogFromJson(File file, List<HolonElementSketch> catalog) {
 		Gson gson = new Gson();
 		JsonParser parser = new JsonParser();
@@ -328,6 +311,8 @@ public class Randomizer implements AddOn {
 				JsonArray jsonArray = jsonTreeRoot.getAsJsonArray();
 				jsonArray.forEach(jsonObject -> {
 					HolonElementSketch newObject= gson.fromJson( jsonObject, HolonElementSketch.class);
+					System.out.println(gson.toJson(newObject));
+					
 					catalog.add(newObject);
 				});
 			}	

+ 0 - 3
src/ui/controller/FlexManager.java

@@ -149,9 +149,6 @@ public class FlexManager {
 					!otherFlexInUseOrOnCooldown(); //No other flex of this ele in use
 		}
 		private boolean otherFlexInUseOrOnCooldown() {
-			System.out.println("Error " + this);
-			if(this.getFlex() == null )System.out.println("Error this.getFlex()");
-			if(this.getFlex().getElement() == null )System.out.println("Error this.getFlex().getElement()");
 			if(accessOtherFlex.get(this.getFlex().getElement()) == null) return false;
 			return accessOtherFlex.get(this.getFlex().getElement()).stream().anyMatch(flexWrapper -> flexWrapper != this && (flexWrapper.getState() == FlexState.IN_USE || flexWrapper.getState() == FlexState.ON_COOLDOWN));
 		}

+ 3 - 0
src/ui/view/AboutUsPopUp.java

@@ -1,6 +1,9 @@
 package ui.view;
 
 import javax.swing.*;
+
+import utility.Util;
+
 import java.awt.*;
 
 /**

+ 1 - 0
src/ui/view/AddElementPopUp.java

@@ -4,6 +4,7 @@ import classes.AbstractCanvasObject;
 import classes.HolonElement;
 import classes.HolonObject;
 import ui.model.Model;
+import utility.Util;
 
 import javax.swing.*;
 import javax.swing.border.EmptyBorder;

+ 2 - 0
src/ui/view/AddObjectPopUp.java

@@ -8,6 +8,8 @@ import classes.Pair;
 import ui.controller.Control;
 import java.lang.NumberFormatException;
 import ui.model.Model;
+import utility.Util;
+
 import javax.swing.*;
 import javax.swing.border.EmptyBorder;
 import javax.swing.filechooser.FileNameExtensionFilter;

+ 1 - 0
src/ui/view/AddOnWindow.java

@@ -33,6 +33,7 @@ import javax.tools.ToolProvider;
 
 import api.AddOn;
 import ui.controller.Control;
+import utility.Util;
 
 @SuppressWarnings("serial")
 public class AddOnWindow extends JFrame{

+ 1 - 0
src/ui/view/BackgroundPopUp.java

@@ -3,6 +3,7 @@ package ui.view;
 import classes.GroupNode;
 import ui.controller.Control;
 import ui.model.Model;
+import utility.Util;
 
 import javax.swing.*;
 import javax.swing.filechooser.FileNameExtensionFilter;

+ 1 - 0
src/ui/view/CanvasResizePopUp.java

@@ -2,6 +2,7 @@ package ui.view;
 
 import ui.controller.Control;
 import ui.model.Model;
+import utility.Util;
 
 import javax.swing.*;
 import java.awt.*;

+ 2 - 0
src/ui/view/Console.java

@@ -12,6 +12,8 @@ import javax.swing.JScrollPane;
 import javax.swing.JTextArea;
 import javax.swing.JToolBar;
 import javax.swing.text.DefaultCaret;
+
+import utility.Util;
 /**
  * Little new swing object to print data to a console.
  * @author tom

+ 1 - 0
src/ui/view/CreateTemplatePopUp.java

@@ -7,6 +7,7 @@ import classes.HolonObject;
 import classes.Pair;
 import ui.controller.Control;
 import ui.model.Model;
+import utility.Util;
 
 import javax.swing.*;
 import javax.swing.border.EmptyBorder;

+ 1 - 0
src/ui/view/FlexWindow.java

@@ -61,6 +61,7 @@ import ui.controller.FlexManager;
 import ui.controller.FlexManager.FlexState;
 import ui.controller.FlexManager.FlexWrapper;
 import ui.model.Model;
+import utility.Util;
 
 
 public class FlexWindow extends JFrame {

+ 1 - 0
src/ui/view/GUI.java

@@ -19,6 +19,7 @@ import ui.model.DecoratedState;
 import ui.model.Model;
 import ui.model.Model.FairnessModel;
 import ui.view.NewPopUp.Option;
+import utility.Util;
 
 import javax.swing.*;
 import javax.swing.border.Border;

+ 1 - 0
src/ui/view/GroupNodeCanvas.java

@@ -17,6 +17,7 @@ import ui.model.Supplier;
 import ui.model.VisualRepresentationalState;
 import ui.model.DecoratedHolonObject.HolonObjectState;
 import ui.model.DecoratedSwitch.SwitchState;
+import utility.Util;
 
 import javax.swing.*;
 

+ 8 - 6
src/ui/view/Languages.java

@@ -4,11 +4,13 @@ import java.io.FileReader;
 import java.io.IOException;
 import java.io.InputStreamReader;
 import java.nio.charset.Charset;
-
+
+import utility.Util;
+
 public class Languages {
 
 	static int languageVar = 0;
-
+
 	// Language Array Positions:
 	// ToolBar (0-16)
 	// Tables (17-24)
@@ -32,7 +34,7 @@ public class Languages {
 	 * Number of different Language Array Positions
 	 */
 	private static int languageSize = 105;
-
+
 	static String[] arrayEN = {
 			// ToolBar (0-16)
 			"File", "New", "Open", "Save", "Edit", "Undo", "Redo", "Find/Replace", "Edit showed Information", "Options",
@@ -71,7 +73,7 @@ public class Languages {
 			// Simulation ToolTip (89-93)
 			"Play", "Reset", "Forward", "Backward", "Time Slider",
 			// Image Size Slider (94)
-			"Image Size",
+			"Image Size",
 			// Menu - right click on HolonObjt (95-104)
 			"Cut", "Copy", "Paste", "Delete", "Group", "Ungroup", "Track", "Untrack","Category","Create Template"};
 
@@ -102,7 +104,7 @@ public class Languages {
 
 	public static void setLanguage(int i) {
 		languageVar = i;
-	}
+	}
 	
 	/**
 	 * Reads language file from jar, each line corresponds to
@@ -141,5 +143,5 @@ public class Languages {
 			//default: English
 			return arrayEN;
 		}
-	}
+	}
 }

+ 1 - 0
src/ui/view/MyCanvas.java

@@ -15,6 +15,7 @@ import ui.model.DecoratedHolonObject.HolonObjectState;
 import ui.model.DecoratedNetwork;
 import ui.model.DecoratedSwitch;
 import ui.model.DecoratedSwitch.SwitchState;
+import utility.Util;
 import ui.model.Model;
 import ui.model.Passiv;
 import ui.model.Supplier;

+ 1 - 0
src/ui/view/Outliner.java

@@ -26,6 +26,7 @@ import ui.controller.Control;
 import ui.model.Consumer;
 import ui.model.DecoratedCable;
 import ui.model.DecoratedHolonObject.HolonObjectState;
+import utility.Util;
 import ui.model.DecoratedNetwork;
 import ui.model.DecoratedState;
 import ui.model.DecoratedSwitch;

+ 135 - 0
src/ui/view/RandomPriotity.java

@@ -0,0 +1,135 @@
+package ui.view;
+
+import java.util.Hashtable;
+
+import javax.swing.BorderFactory;
+import javax.swing.BoxLayout;
+import javax.swing.JLabel;
+import javax.swing.JPanel;
+import javax.swing.JSlider;
+
+import classes.HolonElement.Priority;
+
+@SuppressWarnings("serial")
+public class RandomPriotity extends JPanel{
+	/**
+	 * Its like a Gradient the Values are on one Axis from Start to End:
+	 * |--start--lm--mh--he--end--|
+	 * lm: lowMedium
+	 * mh: mediumHigh
+	 * he: highEssential
+	 */
+	private int lm = 25 , mh = 50, he = 75;
+	private final int start = 0, end = 100;
+	
+	private JSlider lowChanceSlider = new JSlider(JSlider.HORIZONTAL,0, 100, lm - start);
+	private JSlider mediumChanceSlider = new JSlider(JSlider.HORIZONTAL,0, 100, mh - lm);
+	private JSlider highChanceSlider = new JSlider(JSlider.HORIZONTAL,0, 100, he - mh);
+	private JSlider essentialChanceSlider = new JSlider(JSlider.HORIZONTAL,0, 100, end - he);
+	
+	
+	public RandomPriotity(){
+		this.setLayout(new BoxLayout(this, BoxLayout.PAGE_AXIS));
+		this.add(initVisualizeSlider(this.lowChanceSlider, "Low"));
+		this.add(initVisualizeSlider(this.mediumChanceSlider, "Medium"));
+		this.add(initVisualizeSlider(this.highChanceSlider, "High"));
+		this.add(initVisualizeSlider(this.essentialChanceSlider, "Essential"));
+		lowChanceSlider.setToolTipText("" +((double)lowChanceSlider.getValue()/ 100.0));
+		mediumChanceSlider.setToolTipText("" +((double)mediumChanceSlider.getValue()/ 100.0));
+		highChanceSlider.setToolTipText("" +((double)highChanceSlider.getValue()/ 100.0));
+		essentialChanceSlider.setToolTipText("" +((double)essentialChanceSlider.getValue()/ 100.0));
+		lowChanceSlider.addChangeListener(actionEvent ->{
+			setLM(lowChanceSlider.getValue());
+			updateSliders();
+			lowChanceSlider.setToolTipText("" +((double)lowChanceSlider.getValue()/ 100.0));
+			System.out.println("lowChance = " +lowChanceSlider.getValue());
+		});
+		mediumChanceSlider.addChangeListener(actionEvent ->{
+			if(lm + mediumChanceSlider.getValue() <= 100) setMH(lm + mediumChanceSlider.getValue());
+			else setLM(end - mediumChanceSlider.getValue());
+			updateSliders();
+			mediumChanceSlider.setToolTipText("" +((double)mediumChanceSlider.getValue()/ 100.0));
+			System.out.println("mediumChance = " +  mediumChanceSlider.getValue());
+		});
+		highChanceSlider.addChangeListener(actionEvent ->{
+			if(mh + highChanceSlider.getValue() <= 100) setHE(mh + highChanceSlider.getValue());
+			else setMH(end - highChanceSlider.getValue());
+			updateSliders();
+			highChanceSlider.setToolTipText("" +((double)highChanceSlider.getValue()/ 100.0));
+			System.out.println("highChance = " +highChanceSlider.getValue());
+		});
+		essentialChanceSlider.addChangeListener(actionEvent ->{
+			setHE(end - essentialChanceSlider.getValue());
+			updateSliders();
+			essentialChanceSlider.setToolTipText("" +((double)essentialChanceSlider.getValue()/ 100.0));
+			System.out.println("essentialChance = " +essentialChanceSlider.getValue());
+		});
+	}
+
+	private void setLM(int value) {
+		lm = clamp(value, 0, 100);
+		if(lm > mh) mh = lm;
+		if(lm > he) he = lm;
+	}
+	
+	private void setMH(int value) {
+		mh = clamp(value, 0, 100);
+		if(mh < lm) lm = mh;
+		if(mh > he) he = mh;
+	}
+	
+	private void setHE(int value) {
+		he = clamp(value, 0, 100);
+		if(he < lm) lm = he;
+		if(he < mh) mh = he;
+	}
+	
+	
+	private int clamp(int input, int min , int max) {
+		return Math.max(min, Math.min(max, input));
+	}
+	
+	
+	private void updateSliders(){
+		lowChanceSlider.setValue(lm - start);
+		mediumChanceSlider.setValue(mh - lm);
+		highChanceSlider.setValue(he - mh);
+		essentialChanceSlider.setValue(end - he);
+	}
+	
+	
+
+	private JSlider initVisualizeSlider(JSlider jslider, String name) {
+		jslider.setBorder(BorderFactory.createTitledBorder(name));
+		jslider.setMajorTickSpacing(50);
+		jslider.setMinorTickSpacing(5);
+		jslider.setPaintTicks(true);
+		Hashtable<Integer, JLabel> labelTable = new Hashtable<Integer, JLabel>();
+		labelTable.put( Integer.valueOf( 0 ), new JLabel("0.0") );
+		labelTable.put( Integer.valueOf( 50 ), new JLabel("0.5") );
+		labelTable.put( Integer.valueOf( 100 ), new JLabel("1.0") );
+		jslider.setLabelTable( labelTable );
+		jslider.setPaintLabels(true);
+		return jslider;
+	}
+	
+	public Priority getPriority() {
+		double randomDoubleInRange = Math.random() * 100.0;
+		if(randomDoubleInRange <= lm) {
+			return Priority.Low;
+		} else if(randomDoubleInRange <= mh) {
+			return Priority.Medium;
+		} else if(randomDoubleInRange <= he) {
+			return Priority.High;
+		} else {
+			return Priority.Essential;
+		}
+	}
+	@Override
+	public void setEnabled(boolean value) {
+		lowChanceSlider.setEnabled(value);
+		mediumChanceSlider.setEnabled(value);
+		highChanceSlider.setEnabled(value);
+		essentialChanceSlider.setEnabled(value);
+	}
+}

+ 1 - 0
src/ui/view/TimePanel.java

@@ -3,6 +3,7 @@ package ui.view;
 import ui.controller.Control;
 import ui.controller.SingletonControl;
 import ui.model.Model;
+import utility.Util;
 
 import javax.swing.*;
 import javax.swing.event.ChangeEvent;

+ 42 - 0
src/utility/Random.java

@@ -0,0 +1,42 @@
+package utility;
+
+public class Random {
+		
+		
+		private static java.util.Random random = new java.util.Random();
+	
+		/**
+		 * True or false
+		 * @return the random boolean.
+		 */
+		public static boolean nextBoolean(){
+			return random.nextBoolean();
+		}
+		/**
+		 * Between 0.0(inclusive) and 1.0 (exclusive)
+		 * @return the random double.
+		 */
+		public static double nextDouble() {
+			return random.nextDouble();
+		}
+		
+		public static float nextFloatInRange(float min, float max) {
+			return min + random.nextFloat() * Math.abs(max - min);
+		}
+		
+		
+		public static double nextDoubleInRange(double min, double max) {
+			return min + random.nextDouble() * Math.abs(max - min);
+		}
+		
+		/**
+		 * Random Int in Range [min;max[ with UniformDistirbution
+		 * @param min
+		 * @param max
+		 * @return
+		 */
+		public static int nextIntegerInRange(int min, int max) {
+			return min + random.nextInt(max - min);
+		}
+	
+}

+ 5 - 5
src/ui/view/Util.java → src/utility/Util.java

@@ -1,4 +1,4 @@
-package ui.view;
+package utility;
 
 import java.awt.Image;
 import java.awt.image.BufferedImage;
@@ -88,7 +88,7 @@ public class Util {
 	 * @param h Height the loaded image should be scaled to.
 	 * @return A loaded and (smoothly) scaled image from the requested path.
 	 */
-	static Image loadImage(String url, int w, int h){
+	public static Image loadImage(String url, int w, int h){
 		return loadImage(url,w,h, Image.SCALE_SMOOTH);
 	}
 	
@@ -99,7 +99,7 @@ public class Util {
 	 * @param h Height the loaded image should be scaled to.
 	 * @return An image loaded from the requested path.
 	 */
-	static Image loadImage(String url){
+	public static Image loadImage(String url){
 		if(SAVE_MODE!=SAVE_NOTHING){
 			if(imgStorage.containsKey(url))return imgStorage.get(url);
 			else{
@@ -129,7 +129,7 @@ public class Util {
 	 * @param url The path (and file name) of the requested resource.
 	 * @return An InputStream from the requested resource.
 	 */
-	static InputStream loadStream(String url){
+	public static InputStream loadStream(String url){
 		InputStream o=xmp.getClass().getResourceAsStream(url);
 		if(o!=null)return o;
 		else{
@@ -150,5 +150,5 @@ public class Util {
 	}
 	
 	//Nobody needs an instance of this. I do, because I use it to load images from inside the JAR.
-	private Util(){}
+	private Util(){}
 }