Procházet zdrojové kódy

Upgrades InformationPanel

Troppmann, Tom před 4 roky
rodič
revize
e036d4c429

binární
exampleNetworks/Topologie_Version1.holon


+ 76 - 85
src/addOns/InformationPanel.java

@@ -4,7 +4,6 @@ import java.awt.BorderLayout;
 import java.awt.Dimension;
 import java.awt.GridBagConstraints;
 import java.awt.GridBagLayout;
-import java.awt.GridLayout;
 import java.awt.Insets;
 import java.util.ArrayList;
 import java.util.List;
@@ -20,17 +19,14 @@ import javax.swing.JPanel;
 import javax.swing.JScrollPane;
 import javax.swing.JSeparator;
 import javax.swing.JTextField;
-import javax.swing.SpringLayout;
 
 import api.AddOn;
 import classes.Flexibility;
+import classes.HolonElement;
 import classes.HolonElement.Priority;
 import ui.controller.Control;
 import ui.controller.FlexManager.FlexState;
-import ui.controller.FlexManager.FlexWrapper;
-import ui.model.DecoratedGroupNode;
 import ui.model.DecoratedHolonObject.HolonObjectState;
-import ui.model.DecoratedNetwork;
 import ui.model.DecoratedState;
 import ui.model.DecoratedSwitch.SwitchState;
 import ui.model.VisualRepresentationalState;
@@ -55,8 +51,20 @@ public class InformationPanel implements AddOn {
 		private int amountSupplier;
 	
 	private int amountHolonElements;
-		private int amountActiveHolonElements;
-		private int amountInactiveHolonElements;
+		private int amountElementEssential;
+		private int amountElementHigh;
+		private int amountElementMedium;
+		private int amountElementLow;
+		private int amountElementActiveEssential;
+		private int amountElementActiveHigh;
+		private int amountElementActiveMedium;
+		private int amountElementActiveLow;
+		private int amountElementInactiveEssential;
+		private int amountElementInactiveHigh;
+		private int amountElementInactiveMedium;
+		private int amountElementInactiveLow;
+	private int amountActiveHolonElements;
+	private int amountInactiveHolonElements;
 	private int amountFlexibilities;
 	private int amountActiveFlexibilities;
 		private int amountEssential;
@@ -120,43 +128,57 @@ public class InformationPanel implements AddOn {
 		
 		
 
-		entryList.add(new Entry(() -> Integer.toString(amountHolonObjects), "amountHolonObjects", middle));
-		entryList.add(new Entry(() -> Integer.toString(amountConsumer) + addPercentage(amountConsumer, amountHolonObjects), "\tamountConsumer", middle));
-		entryList.add(new Entry(() -> Integer.toString(amountUnderSupplied) + addPercentage(amountUnderSupplied, amountConsumer), "\t\tamountUnderSupplied", middle));
-		entryList.add(new Entry(() -> Integer.toString(amountPatiallySupplied) + addPercentage(amountPatiallySupplied, amountConsumer), "\t\tamountPatiallySupplied", middle));
-		entryList.add(new Entry(() -> Integer.toString(amountFullySupplied) + addPercentage(amountFullySupplied, amountConsumer), "\t\tamountFullySupplied", middle));
-		entryList.add(new Entry(() -> Integer.toString(amountOversupllied) + addPercentage(amountOversupllied, amountConsumer), "\t\tamountOversupllied", middle));
-		entryList.add(new Entry(() -> Integer.toString(amountSupplier) + addPercentage(amountSupplier, amountHolonObjects), "\tamountSupplier", middle));
-		entryList.add(new Entry(() -> Integer.toString(amountPassiv) + addPercentage(amountPassiv, amountHolonObjects), "\tamountPassiv", middle));
+		entryList.add(new Entry(() -> Integer.toString(amountHolonObjects), "HolonObjects", middle));
+		entryList.add(new Entry(() -> Integer.toString(amountConsumer) + addPercentage(amountConsumer, amountHolonObjects), "\tConsumer", middle));
+		entryList.add(new Entry(() -> Integer.toString(amountUnderSupplied) + addPercentage(amountUnderSupplied, amountConsumer), "\t\tUnderSupplied", middle));
+		entryList.add(new Entry(() -> Integer.toString(amountPatiallySupplied) + addPercentage(amountPatiallySupplied, amountConsumer), "\t\tPatiallySupplied", middle));
+		entryList.add(new Entry(() -> Integer.toString(amountFullySupplied) + addPercentage(amountFullySupplied, amountConsumer), "\t\tFullySupplied", middle));
+		entryList.add(new Entry(() -> Integer.toString(amountOversupllied) + addPercentage(amountOversupllied, amountConsumer), "\t\tOversupllied", middle));
+		entryList.add(new Entry(() -> Integer.toString(amountSupplier) + addPercentage(amountSupplier, amountHolonObjects), "\tSupplier", middle));
+		entryList.add(new Entry(() -> Integer.toString(amountPassiv) + addPercentage(amountPassiv, amountHolonObjects), "\tPassiv", middle));
 		addSeperator(middle);
-		entryList.add(new Entry(() -> Integer.toString(amountSwitch), "amountSwitch (not a HolonObject)", middle));
-		entryList.add(new Entry(() -> Integer.toString(amountActiveSwitch) + addPercentage(amountActiveSwitch, amountSwitch), "\tamountActiveSwitch", middle));
-		entryList.add(new Entry(() -> Integer.toString(amountInactiveSwitch) + addPercentage(amountInactiveSwitch, amountSwitch), "\tamountInactiveSwitch", middle));
+		entryList.add(new Entry(() -> Integer.toString(amountSwitch), "Switch (not a HolonObject)", middle));
+		entryList.add(new Entry(() -> Integer.toString(amountActiveSwitch) + addPercentage(amountActiveSwitch, amountSwitch), "\t[Active] Switch", middle));
+		entryList.add(new Entry(() -> Integer.toString(amountInactiveSwitch) + addPercentage(amountInactiveSwitch, amountSwitch), "\t[Inactive] Switch", middle));
 		
 		addSeperator(middle);
-		entryList.add(new Entry(() -> Integer.toString(amountHolonElements), "amountHolonElements", middle));
-		entryList.add(new Entry(() -> Integer.toString(amountActiveHolonElements) + addPercentage(amountActiveHolonElements, amountHolonElements), "\tamountActiveHolonElements", middle));
-		entryList.add(new Entry(() -> Integer.toString(amountInactiveHolonElements) + addPercentage(amountInactiveHolonElements, amountHolonElements), "\tamountInactiveHolonElements", middle));
+		entryList.add(new Entry(() -> Integer.toString(amountHolonElements), "HolonElements", middle));
+		entryList.add(new Entry(() -> Integer.toString(this.amountElementLow) + addPercentage(amountElementLow, amountHolonElements), "\tLow", middle));
+		entryList.add(new Entry(() -> Integer.toString(this.amountElementMedium) + addPercentage(amountElementMedium, amountHolonElements), "\tMedium", middle));
+		entryList.add(new Entry(() -> Integer.toString(this.amountElementHigh) + addPercentage(amountElementHigh, amountHolonElements), "\tHigh", middle));
+		entryList.add(new Entry(() -> Integer.toString(this.amountElementEssential) + addPercentage(amountElementEssential, amountHolonElements), "\tEssential", middle));
+		addSeperator(middle);
+		entryList.add(new Entry(() -> Integer.toString(amountActiveHolonElements) + addPercentage(amountActiveHolonElements, amountHolonElements), "[Active] HolonElements", middle));
+		entryList.add(new Entry(() -> Integer.toString(this.amountElementActiveLow) + addPercentage(amountElementActiveLow, amountActiveHolonElements), "\tLow", middle));
+		entryList.add(new Entry(() -> Integer.toString(this.amountElementActiveMedium) + addPercentage(amountElementActiveMedium, amountActiveHolonElements), "\tMedium", middle));
+		entryList.add(new Entry(() -> Integer.toString(this.amountElementActiveHigh) + addPercentage(amountElementActiveHigh, amountActiveHolonElements), "\tHigh", middle));
+		entryList.add(new Entry(() -> Integer.toString(this.amountElementActiveEssential) + addPercentage(amountElementActiveEssential, amountActiveHolonElements), "\tEssential", middle));
+		addSeperator(middle);
+		entryList.add(new Entry(() -> Integer.toString(amountInactiveHolonElements) + addPercentage(amountInactiveHolonElements, amountHolonElements), "[Inactive] HolonElements", middle));
+		entryList.add(new Entry(() -> Integer.toString(this.amountElementInactiveLow) + addPercentage(amountElementInactiveLow, amountInactiveHolonElements), "\tLow", middle));
+		entryList.add(new Entry(() -> Integer.toString(this.amountElementInactiveMedium) + addPercentage(amountElementInactiveMedium, amountInactiveHolonElements), "\tMedium", middle));
+		entryList.add(new Entry(() -> Integer.toString(this.amountElementInactiveHigh) + addPercentage(amountElementInactiveHigh, amountInactiveHolonElements), "\tHigh", middle));
+		entryList.add(new Entry(() -> Integer.toString(this.amountElementInactiveEssential) + addPercentage(amountElementInactiveEssential, amountInactiveHolonElements), "\tEssential", middle));
 		
 		addSeperator(middle);
-		entryList.add(new Entry(() -> Integer.toString(amountFlexibilities), "amountFlexibilities", middle));
-		entryList.add(new Entry(() -> Integer.toString(amountConsumingFlexibilities) + addPercentage(amountConsumingFlexibilities, amountFlexibilities), "\tamountConsumingFlexibilities", middle));
-		entryList.add(new Entry(() -> Integer.toString(amountProducingFlexibilities) + addPercentage(amountProducingFlexibilities, amountFlexibilities), "\tamountProducingFlexibilities", middle));
+		entryList.add(new Entry(() -> Integer.toString(amountFlexibilities), "Flexibilities", middle));
+		entryList.add(new Entry(() -> Integer.toString(amountConsumingFlexibilities) + addPercentage(amountConsumingFlexibilities, amountFlexibilities), "\tConsumingFlexibilities", middle));
+		entryList.add(new Entry(() -> Integer.toString(amountProducingFlexibilities) + addPercentage(amountProducingFlexibilities, amountFlexibilities), "\tProducingFlexibilities", middle));
 		addSeperator(middle);
-		entryList.add(new Entry(() -> Integer.toString(amountFlexibilities), "amountFlexibilities", middle));
-		entryList.add(new Entry(() -> Integer.toString(amountLow) + addPercentage(amountLow, amountFlexibilities), "\tamountLow", middle));
-		entryList.add(new Entry(() -> Integer.toString(amountMedium) + addPercentage(amountMedium, amountFlexibilities), "\tamountMedium", middle));
-		entryList.add(new Entry(() -> Integer.toString(amountHigh) + addPercentage(amountHigh, amountFlexibilities), "\tamountHigh", middle));
-		entryList.add(new Entry(() -> Integer.toString(amountEssential) + addPercentage(amountEssential, amountFlexibilities), "\tamountEssential", middle));
+		entryList.add(new Entry(() -> Integer.toString(amountFlexibilities), "Flexibilities", middle));
+		entryList.add(new Entry(() -> Integer.toString(amountLow) + addPercentage(amountLow, amountFlexibilities), "\tLow", middle));
+		entryList.add(new Entry(() -> Integer.toString(amountMedium) + addPercentage(amountMedium, amountFlexibilities), "\tMedium", middle));
+		entryList.add(new Entry(() -> Integer.toString(amountHigh) + addPercentage(amountHigh, amountFlexibilities), "\tHigh", middle));
+		entryList.add(new Entry(() -> Integer.toString(amountEssential) + addPercentage(amountEssential, amountFlexibilities), "\tEssential", middle));
 		addSeperator(middle);
-		entryList.add(new Entry(() -> Integer.toString(amountActiveFlexibilities), "amountActiveFlexibilities", middle));
-		entryList.add(new Entry(() -> Integer.toString(amountActiveLow) + addPercentage(amountActiveLow, amountActiveFlexibilities), "\tamountActiveLow", middle));
-		entryList.add(new Entry(() -> Integer.toString(amountActiveMedium) + addPercentage(amountActiveMedium, amountActiveFlexibilities), "\tamountActiveMedium", middle));
-		entryList.add(new Entry(() -> Integer.toString(amountActiveHigh) + addPercentage(amountActiveHigh, amountActiveFlexibilities), "\tamountActiveHigh", middle));
-		entryList.add(new Entry(() -> Integer.toString(amountActiveEssential) + addPercentage(amountActiveEssential, amountActiveFlexibilities), "\tamountActiveEssential", middle));
+		entryList.add(new Entry(() -> Integer.toString(amountActiveFlexibilities), "ActiveFlexibilities", middle));
+		entryList.add(new Entry(() -> Integer.toString(amountActiveLow) + addPercentage(amountActiveLow, amountActiveFlexibilities), "\tLow", middle));
+		entryList.add(new Entry(() -> Integer.toString(amountActiveMedium) + addPercentage(amountActiveMedium, amountActiveFlexibilities), "\tMedium", middle));
+		entryList.add(new Entry(() -> Integer.toString(amountActiveHigh) + addPercentage(amountActiveHigh, amountActiveFlexibilities), "\tHigh", middle));
+		entryList.add(new Entry(() -> Integer.toString(amountActiveEssential) + addPercentage(amountActiveEssential, amountActiveFlexibilities), "\tEssential", middle));
 		addSeperator(middle);
-		entryList.add(new Entry(() -> Integer.toString(amountGroupNodes), "amountGroupNodes", middle));
-		entryList.add(new Entry(() -> Integer.toString(amountHolons), "amountHolons", middle));
+		entryList.add(new Entry(() -> Integer.toString(amountGroupNodes), "GroupNodes", middle));
+		entryList.add(new Entry(() -> Integer.toString(amountHolons), "Holons", middle));
 		
 		return middle;
 	}
@@ -211,19 +233,6 @@ public class InformationPanel implements AddOn {
 		amountPassiv = dState.getNetworkList().stream().map(net -> net.getAmountOfPassiv()).reduce(0, Integer::sum);
 		
 		this.amountHolonObjects = amountConsumer + amountSupplier + amountPassiv;
-		int elements = 0;
-		elements += dState.getNetworkList().stream().map(net -> net.getConsumerList().stream().map(con->con.getModel().getNumberOfElements()).reduce(0, Integer::sum) ).reduce(0, Integer::sum);
-		elements += dState.getNetworkList().stream().map(net -> net.getSupplierList().stream().map(con->con.getModel().getNumberOfElements()).reduce(0, Integer::sum) ).reduce(0, Integer::sum);
-		elements += dState.getNetworkList().stream().map(net -> net.getConsumerSelfSuppliedList().stream().map(con->con.getModel().getNumberOfElements()).reduce(0, Integer::sum) ).reduce(0, Integer::sum);
-		elements += dState.getNetworkList().stream().map(net -> net.getPassivNoEnergyList().stream().map(con->con.getModel().getNumberOfElements()).reduce(0, Integer::sum) ).reduce(0, Integer::sum);
-		this.amountHolonElements = elements;
-		int activeElements = 0;
-		activeElements += dState.getNetworkList().stream().map(net -> net.getConsumerList().stream().map(con->con.getModel().getNumberOfActiveElements()).reduce(0, Integer::sum) ).reduce(0, Integer::sum);
-		activeElements += dState.getNetworkList().stream().map(net -> net.getSupplierList().stream().map(con->con.getModel().getNumberOfActiveElements()).reduce(0, Integer::sum) ).reduce(0, Integer::sum);
-		activeElements += dState.getNetworkList().stream().map(net -> net.getConsumerSelfSuppliedList().stream().map(con->con.getModel().getNumberOfActiveElements()).reduce(0, Integer::sum) ).reduce(0, Integer::sum);
-		activeElements += dState.getNetworkList().stream().map(net -> net.getPassivNoEnergyList().stream().map(con->con.getModel().getNumberOfActiveElements()).reduce(0, Integer::sum) ).reduce(0, Integer::sum);
-		this.amountActiveHolonElements = activeElements;
-		this.amountInactiveHolonElements = amountHolonElements - amountActiveHolonElements;
 		
 		
 		
@@ -248,7 +257,23 @@ public class InformationPanel implements AddOn {
 		
 		
 		amountHolons = dState.getNetworkList().size();
-		
+		List<HolonElement> listHolonElements = control.getModel().getAllHolonElemnts();
+		this.amountHolonElements = listHolonElements.size();
+		List<HolonElement> listAcitveHolonElemnts = listHolonElements.stream().filter(ele -> ele.isActive()).collect(Collectors.toList());
+		this.amountActiveHolonElements = listAcitveHolonElemnts.size();
+		this.amountInactiveHolonElements = amountHolonElements - amountActiveHolonElements;
+		this.amountElementLow = (int) listHolonElements.stream().filter(ele -> ele.getPriority() == Priority.Low).count();
+		this.amountElementMedium= (int) listHolonElements.stream().filter(ele -> ele.getPriority() == Priority.Medium).count();
+		this.amountElementHigh = (int) listHolonElements.stream().filter(ele -> ele.getPriority() == Priority.High).count();
+		this.amountElementEssential = (int) listHolonElements.stream().filter(ele -> ele.getPriority() == Priority.Essential).count();
+		this.amountElementActiveLow = (int) listAcitveHolonElemnts.stream().filter(ele -> ele.getPriority() == Priority.Low).count();
+		this.amountElementActiveMedium= (int) listAcitveHolonElemnts.stream().filter(ele -> ele.getPriority() == Priority.Medium).count();
+		this.amountElementActiveHigh = (int) listAcitveHolonElemnts.stream().filter(ele -> ele.getPriority() == Priority.High).count();
+		this.amountElementActiveEssential = (int) listAcitveHolonElemnts.stream().filter(ele -> ele.getPriority() == Priority.Essential).count();
+		this.amountElementInactiveLow = amountElementLow - amountElementActiveLow;
+		this.amountElementInactiveMedium= amountElementMedium - amountElementActiveMedium;
+		this.amountElementInactiveHigh = amountElementHigh - amountElementActiveHigh;
+		this.amountElementInactiveEssential = amountElementEssential - amountElementActiveEssential;
 		
 		
 		
@@ -274,41 +299,7 @@ public class InformationPanel implements AddOn {
 		
 	}
 	
-	private void printInfos(){
-		DecoratedState dState = control.getSimManager().getActualDecorState();
-		int count = 0;
-		for(DecoratedNetwork net :dState.getNetworkList()) {
-			System.out.print("net" + count++ + ":[");
-			for(float energy : net.getListOfEnergyThatIsOfferedByFlexibilitiesInThisNetwork()) {
-				System.out.print(energy +" ");
-			}
-			System.out.println("] ");
-			System.out.println("Consumption: " + net.getFlexibilityConsumptionCapacity());
-			System.out.println("Production: " + net.getFlexibilityProductionCapacity());
-			System.out.println("Average Consumption: " + net.getAverageFlexibilityConsumption());
-			System.out.println("Average Production: " + net.getAverageFlexibilityProduction());
-			System.out.println("Varianz Consumption: " + net.getVarianzInFlexibilitieConsumption());
-			System.out.println("Varianz Production: " + net.getVarianzInFlexibilitieProduction());
-			System.out.println("Diviation Consumption: " + net.getDiviationInFlexibilityConsumption());
-			System.out.println("Diviation Production: " + net.getDiviationInFlexibilityProduction());
-			
-			
-			
-			
-			
-		}
-		dState.getFlexManager().getAllFlexWrapper().stream().map(flexWrapper -> flexWrapper.getFlex()).forEach(flex -> {
-			flex.setCooldown(getRandomNumberInRange(0, 60*60*24));
-			flex.setDuration(getRandomNumberInRange(0, 60*60));
-			flex.setSpeed(getRandomNumberInRange(0, 120));
-		});
-		
-	}
-	
-	private int getRandomNumberInRange(int min, int max) {
-		
-		return r.nextInt((max - min) + 1) + min;
-	}
+
 	
 	
 

+ 4 - 0
src/ui/model/Model.java

@@ -20,6 +20,7 @@ import javax.swing.*;
 import java.awt.*;
 import java.util.*;
 import java.util.List;
+import java.util.stream.Collectors;
 
 /**
  * The Class Model is the class where everything is saved. All changes made to
@@ -768,6 +769,9 @@ public class Model {
         selectedHolonBody = i;
     }
 
+    public List<HolonElement> getAllHolonElemnts() {
+    	return getAllHolonObjectsOnCanvas().stream().flatMap(hO -> hO.getElements().stream()).collect(Collectors.toList());
+    }
     
     
     public ArrayList<HolonObject> getAllHolonObjectsOnCanvas(){