Browse Source

Adds active Flexibilities

- amountOfHolons
Tom Troppmann 4 years ago
parent
commit
eb2a92ed15

+ 22 - 0
src/api/AlgorithmFrameworkFlex.java

@@ -580,6 +580,10 @@ public abstract class AlgorithmFrameworkFlex implements AddOn{
 		int producingFlex = 0;
 		float producingFlexEnergy = 0.0f;
 		int maxCooldown = 0;
+		int amountEssential = 0;
+		int amountHigh = 0;
+		int amountMedium = 0;
+		int amountLow = 0;
 		for(FlexWrapper flexWrapper :state.getFlexManager().getAllFlexWrapperWithState(FlexState.IN_USE)) {
 			amountOfUsedFlex++;
 			cost += flexWrapper.getFlex().cost;
@@ -592,6 +596,23 @@ public abstract class AlgorithmFrameworkFlex implements AddOn{
 				producingFlexEnergy += energy;
 			}
 			if(flexWrapper.getFlex().getCooldown() > maxCooldown) maxCooldown = flexWrapper.getFlex().getCooldown();
+			switch(flexWrapper.getFlex().getElement().getPriority()) {
+			case Essential:
+				amountEssential++;
+				break;
+			case High:
+				amountHigh++;
+				break;
+			case Low:
+				amountLow++;
+				break;
+			case Medium:
+				amountMedium++;
+				break;
+			default:
+				break;
+			
+			}
 		}
 		
 		
@@ -603,6 +624,7 @@ public abstract class AlgorithmFrameworkFlex implements AddOn{
 		console.println(consumingFlex + " consuimg flexibilities that consumed " + consumingFlexEnergy + "Energy.");
 		//Producing Flexibilities
 		console.println(producingFlex + " producing flexibilities that produce " + producingFlexEnergy + "Energy.");
+		console.println("Flex in use:\t" + "Low= " + amountLow + "\tMedium= " + amountMedium + "\tHigh= " + amountHigh + "\tEssential= " + amountEssential);
 		//Total cost:
 		console.println("Total Cost: "+ cost);
 		//Longest Cooldown

+ 41 - 9
src/exampleAlgorithms/InformationPanel.java

@@ -26,6 +26,7 @@ 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.DecoratedState;
 
@@ -37,28 +38,37 @@ public class InformationPanel implements AddOn {
 	
 	
 	//Fields
-	private int amountHolonObjects;
 	private int amountSwitch;
-	private int amountConsumer;
-		private int	amountUnderSupplied;
-		private int amountPatiallySupplied;
-		private int amountFullySupplied;
-		private int amountOversupllied;
+	private int amountHolonObjects;
+		private int amountConsumer;
+			private int	amountUnderSupplied;
+			private int amountPatiallySupplied;
+			private int amountFullySupplied;
+			private int amountOversupllied;
 		private int amountSupplier;
 	
 	private int amountHolonElements;
 		private int amountActiveHolonElements;
 		private int amountInactiveHolonElements;
 	private int amountFlexibilities;
+	private int amountActiveFlexibilities;
 		private int amountEssential;
+		private int amountActiveEssential;
 		private int amountHigh;
+		private int amountActiveHigh;
 		private int amountMedium;
+		private int amountActiveMedium;
 		private int amountLow;
+		private int amountActiveLow;
 
 		private int amountConsumingFlexibilities;
 		private int amountProducingFlexibilities;
 	private int amountPassiv;
 	
+	
+	
+	private int amountHolons;
+	
 	List<Entry> entryList = new ArrayList<Entry>();
 
 	private int currentEntryVerticalPosition = 0;
@@ -66,6 +76,8 @@ public class InformationPanel implements AddOn {
 
 
 
+
+
 	
 	
 	public InformationPanel(){
@@ -91,7 +103,7 @@ public class InformationPanel implements AddOn {
 		JPanel middle = new JPanel();
 		middle.setLayout(new GridBagLayout());
 		
-		int size = 60;
+		int size = 75;
 		middle.setPreferredSize(new Dimension(16*size, 9*size));
 		
 
@@ -120,8 +132,14 @@ public class InformationPanel implements AddOn {
 		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));
-		
-		
+		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));
+		addSeperator(middle);
+		entryList.add(new Entry(() -> Integer.toString(amountHolons), "amountHolons", middle));
 		
 		return middle;
 	}
@@ -197,6 +215,18 @@ public class InformationPanel implements AddOn {
 		amountMedium = (int)flexList.stream().filter(flex -> flex.getElement().getPriority() == Priority.Medium).count();
 		amountLow = (int)flexList.stream().filter(flex -> flex.getElement().getPriority() == Priority.Low).count();
 		this.amountFlexibilities = amountEssential + amountHigh + amountMedium + amountLow;
+		
+		
+		List<Flexibility> flexActiveList = control.getSimManager().getActualFlexManager().getAllFlexWrapperWithState(FlexState.IN_USE).stream().map(flex -> flex.getFlex()).collect(Collectors.toList());
+		amountActiveEssential = (int)flexActiveList.stream().filter(flex -> flex.getElement().getPriority() == Priority.Essential).count();
+		amountActiveHigh = (int)flexActiveList.stream().filter(flex -> flex.getElement().getPriority() == Priority.High).count();
+		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();
+		
+		
 		int cost = 0;
 		int consumingFlex = 0;
 		float consumingFlexEnergy = 0.0f;
@@ -220,6 +250,8 @@ public class InformationPanel implements AddOn {
 	}
 	
 	
+
+	
 	@Override
 	public JPanel getPanel() {
 		return content;

+ 7 - 0
src/ui/model/DecoratedGroupNode.java

@@ -74,6 +74,13 @@ public class DecoratedGroupNode {
 		return groupNodeList;
 	}
 	
+	
+	//Returns the amount of holons and count himself 
+	public int getAmountOfHolons() {
+		return 1 + groupNodeList.stream().map(groupNode -> groupNode.getAmountOfHolons()).reduce(0, Integer::sum);
+	}
+	
+	
 	//Gather Informations:
 	public int getAmountOfSupplier() {
 		return supplierList.size() + groupNodeList.stream().map(groupNode -> groupNode.getAmountOfSupplier()).reduce(0, (a,b)->a+b);

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

@@ -274,6 +274,15 @@ public class VisualRepresentationalState {
 	private <DecoratedObject> void addToGroupNode(DecoratedObject object, ArrayList<DecoratedObject> groupNodeListPar) {
 		groupNodeListPar.add(object);
 	}
+	
+	
+	
+	
+	public int getAmountOfHolons() {
+		return 1 + groupNodeList.stream().map(groupNode -> groupNode.getAmountOfHolons()).reduce(0, Integer::sum);
+	}
+	
+	
 
 	//Generics
 	private <ModelOfObject, DecoratedObject> DecoratedGroupNode addObject(HashMap<ModelOfObject, CpsUpperNode> inGroupObjects, ModelOfObject modelOfObject, ArrayList<DecoratedObject> listToAdd, DecoratedObject object, HashMap<CpsUpperNode, DecoratedGroupNode> createdGroupNodes) {