Browse Source

Adds Average Production/Consumption and gitignore irgonres tmp

Tom Troppmann 4 years ago
parent
commit
d510cdc218

+ 3 - 0
.gitignore

@@ -12,6 +12,9 @@ build/
 .metadata
 bin/
 tmp/
+
+
+*.txt
 *.class
 *.tmp
 *.bak

+ 21 - 11
src/exampleAlgorithms/InformationPanel.java

@@ -16,6 +16,7 @@ import javax.swing.JButton;
 import javax.swing.JFrame;
 import javax.swing.JLabel;
 import javax.swing.JPanel;
+import javax.swing.JScrollPane;
 import javax.swing.JSeparator;
 import javax.swing.JTextField;
 import javax.swing.SpringLayout;
@@ -29,12 +30,13 @@ import ui.controller.FlexManager.FlexWrapper;
 import ui.model.DecoratedGroupNode;
 import ui.model.DecoratedHolonObject.HolonObjectState;
 import ui.model.DecoratedState;
+import ui.model.VisualRepresentationalState;
 
 public class InformationPanel implements AddOn {
 	Control control;
 	
 	private JPanel content = new JPanel();
-	
+	private JScrollPane scrollPane;
 	
 	
 	//Fields
@@ -64,10 +66,10 @@ public class InformationPanel implements AddOn {
 		private int amountConsumingFlexibilities;
 		private int amountProducingFlexibilities;
 	private int amountPassiv;
-	
-	
-	
+		
 	private int amountHolons;
+	private float averageConsumption;
+	private float averageProduction;
 	
 	List<Entry> entryList = new ArrayList<Entry>();
 
@@ -78,11 +80,17 @@ public class InformationPanel implements AddOn {
 
 
 
+
+
 	
 	
 	public InformationPanel(){
 		content.setLayout(new BorderLayout());
-		content.add(createMiddlePanel(), BorderLayout.CENTER);
+		scrollPane = new JScrollPane(createMiddlePanel(),  JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
+	            JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
+		int size = 75;
+		scrollPane.setPreferredSize(new Dimension(16*size, 9*size));
+		content.add(scrollPane, BorderLayout.CENTER);
 		JButton button = new JButton("calculate");
 		button.addActionListener(action -> updateEntrys());
 		content.add(button, BorderLayout.SOUTH);
@@ -103,8 +111,7 @@ public class InformationPanel implements AddOn {
 		JPanel middle = new JPanel();
 		middle.setLayout(new GridBagLayout());
 		
-		int size = 75;
-		middle.setPreferredSize(new Dimension(16*size, 9*size));
+		
 		
 
 		entryList.add(new Entry(() -> Integer.toString(amountHolonObjects), "amountHolonObjects", middle));
@@ -140,6 +147,9 @@ public class InformationPanel implements AddOn {
 		entryList.add(new Entry(() -> Integer.toString(amountActiveEssential) + addPercentage(amountActiveEssential, amountActiveFlexibilities), "\tamountActiveEssential", middle));
 		addSeperator(middle);
 		entryList.add(new Entry(() -> Integer.toString(amountHolons), "amountHolons", middle));
+		addSeperator(middle);
+		entryList.add(new Entry(() -> String.format (Locale.US, "%.2f", averageConsumption), "averageConsumption", middle));
+		entryList.add(new Entry(() -> String.format (Locale.US, "%.2f", averageProduction), "averageProduction", middle));
 		
 		return middle;
 	}
@@ -223,10 +233,10 @@ public class InformationPanel implements AddOn {
 		amountActiveMedium = (int)flexActiveList.stream().filter(flex -> flex.getElement().getPriority() == Priority.Medium).count();
 		amountActiveLow = (int)flexActiveList.stream().filter(flex -> flex.getElement().getPriority() == Priority.Low).count();
 		this.amountActiveFlexibilities = amountActiveEssential + amountActiveHigh + amountActiveMedium + amountActiveLow;
-		
-		amountHolons = control.getSimManager().getActualVisualRepresentationalState().getAmountOfHolons();
-		
-		
+		VisualRepresentationalState visualState =control.getSimManager().getActualVisualRepresentationalState();
+		amountHolons = visualState.getAmountOfHolons();
+		averageConsumption =  visualState.getAverageConsumption();
+		averageProduction =  visualState.getAverageProduction();
 		int cost = 0;
 		int consumingFlex = 0;
 		float consumingFlexEnergy = 0.0f;

+ 22 - 18
src/ui/model/DecoratedGroupNode.java

@@ -83,43 +83,47 @@ public class DecoratedGroupNode {
 	
 	//Gather Informations:
 	public int getAmountOfSupplier() {
-		return supplierList.size() + groupNodeList.stream().map(groupNode -> groupNode.getAmountOfSupplier()).reduce(0, (a,b)->a+b);
+		return supplierList.size() + groupNodeList.stream().map(groupNode -> groupNode.getAmountOfSupplier()).reduce(0, Integer::sum);
 	}
 	public int getAmountOfConsumer() {
-		return consumerList.size() + groupNodeList.stream().map(groupNode -> groupNode.getAmountOfConsumer()).reduce(0, (a,b)->a+b);
+		return consumerList.size() + groupNodeList.stream().map(groupNode -> groupNode.getAmountOfConsumer()).reduce(0,Integer::sum);
 	}
 	public int getAmountOfPassiv() {
-		return passivList.size() + groupNodeList.stream().map(groupNode -> groupNode.getAmountOfPassiv()).reduce(0, (a,b)->a+b);
+		return passivList.size() + groupNodeList.stream().map(groupNode -> groupNode.getAmountOfPassiv()).reduce(0, Integer::sum);
 	}
 	
 	public int getAmountOfConsumerWithState(HolonObjectState state) {
-		return ((int) consumerList.stream().map(con -> con.getState()).filter(rightState -> (rightState == state)).count()) +  groupNodeList.stream().map(groupNode -> groupNode.getAmountOfConsumerWithState(state)).reduce(0, (a,b)->a+b);
+		return ((int) consumerList.stream().map(con -> con.getState()).filter(rightState -> (rightState == state)).count()) +  groupNodeList.stream().map(groupNode -> groupNode.getAmountOfConsumerWithState(state)).reduce(0, Integer::sum);
 	}
 	
 	public int getAmountOfElemntsFromHolonObjects() {
-		return passivList.stream().map(object -> object.getModel().getElements().size()).reduce(0, (a, b) -> a + b)+
-				supplierList.stream().map(object -> object.getModel().getElements().size()).reduce(0, (a, b) -> a + b)+
-				consumerList.stream().map(object -> object.getModel().getElements().size()).reduce(0, (a, b) -> a + b)+
-				groupNodeList.stream().map(groupNode -> groupNode.getAmountOfElemntsFromHolonObjects()).reduce(0, (a,b)->a+b);
+		return passivList.stream().map(object -> object.getModel().getElements().size()).reduce(0, Integer::sum)+
+				supplierList.stream().map(object -> object.getModel().getElements().size()).reduce(0, Integer::sum)+
+				consumerList.stream().map(object -> object.getModel().getElements().size()).reduce(0, Integer::sum)+
+				groupNodeList.stream().map(groupNode -> groupNode.getAmountOfElemntsFromHolonObjects()).reduce(0, Integer::sum);
 	}
 
 	public int getAmountOfAktiveElemntsFromHolonObjects() {
-		return passivList.stream().map(object -> object.getModel().getNumberOfActiveElements()).reduce(0, (a, b) -> a + b)+
-				supplierList.stream().map(object -> object.getModel().getNumberOfActiveElements()).reduce(0, (a, b) -> a + b)+
-				consumerList.stream().map(object -> object.getModel().getNumberOfActiveElements()).reduce(0, (a, b) -> a + b)+
-				groupNodeList.stream().map(groupNode -> groupNode.getAmountOfAktiveElemntsFromHolonObjects()).reduce(0, (a,b)->a+b);
+		return passivList.stream().map(object -> object.getModel().getNumberOfActiveElements()).reduce(0, Integer::sum)+
+				supplierList.stream().map(object -> object.getModel().getNumberOfActiveElements()).reduce(0, Integer::sum)+
+				consumerList.stream().map(object -> object.getModel().getNumberOfActiveElements()).reduce(0, Integer::sum)+
+				groupNodeList.stream().map(groupNode -> groupNode.getAmountOfAktiveElemntsFromHolonObjects()).reduce(0, Integer::sum);
 	}
 	public float getConsumptionFromConsumer() {		
-		return consumerList.stream().map(con -> con.getEnergyNeededFromNetwork()).reduce(0.f, (a, b) -> a + b)+
-				groupNodeList.stream().map(groupNode -> groupNode.getConsumptionFromConsumer()).reduce(0.f, (a,b)->a+b);
+		return consumerList.stream().map(con -> con.getEnergyNeededFromNetwork()).reduce(0.f, Float::sum)+
+				groupNodeList.stream().map(groupNode -> groupNode.getConsumptionFromConsumer()).reduce(0.f, Float::sum);
 	}
 	public float getProductionFromSupplier() {		
-		return supplierList.stream().map(sup -> sup.getEnergyToSupplyNetwork()).reduce(0.f, (a, b) -> a + b)+
-				groupNodeList.stream().map(groupNode -> groupNode.getProductionFromSupplier()).reduce(0.f, (a,b)->a+b);
+		return supplierList.stream().map(sup -> sup.getEnergyToSupplyNetwork()).reduce(0.f, Float::sum)+
+				groupNodeList.stream().map(groupNode -> groupNode.getProductionFromSupplier()).reduce(0.f, Float::sum);
 	}
 	
-	
-	
+	public float getAverageConsumption() {
+		return getConsumptionFromConsumer() / (float)getAmountOfHolons();
+	}
+	public float getAverageProduction() {
+		return getProductionFromSupplier() / (float)getAmountOfHolons();
+	}
 	
 	
 	public String toString() {

+ 21 - 0
src/ui/model/VisualRepresentationalState.java

@@ -283,6 +283,27 @@ public class VisualRepresentationalState {
 	}
 	
 	
+	
+	public float getConsumptionFromConsumer() {		
+		return consumerList.stream().map(con -> con.getEnergyNeededFromNetwork()).reduce(0.f, Float::sum)+
+				groupNodeList.stream().map(groupNode -> groupNode.getConsumptionFromConsumer()).reduce(0.f, Float::sum);
+	}
+	public float getProductionFromSupplier() {		
+		return supplierList.stream().map(sup -> sup.getEnergyToSupplyNetwork()).reduce(0.f, Float::sum)+
+				groupNodeList.stream().map(groupNode -> groupNode.getProductionFromSupplier()).reduce(0.f, Float::sum);
+	}
+	
+	public float getAverageConsumption() {
+		return getConsumptionFromConsumer() / (float)getAmountOfHolons();
+	}
+	public float getAverageProduction() {
+		return getProductionFromSupplier() / (float)getAmountOfHolons();
+	}
+	
+	
+	
+	
+	
 
 	//Generics
 	private <ModelOfObject, DecoratedObject> DecoratedGroupNode addObject(HashMap<ModelOfObject, CpsUpperNode> inGroupObjects, ModelOfObject modelOfObject, ArrayList<DecoratedObject> listToAdd, DecoratedObject object, HashMap<CpsUpperNode, DecoratedGroupNode> createdGroupNodes) {