Browse Source

Average Update

username 5 years ago
parent
commit
1121a63457
2 changed files with 100 additions and 1 deletions
  1. 80 1
      src/exampleAlgorithms/FlexExample.java
  2. 20 0
      src/ui/model/DecoratedNetwork.java

+ 80 - 1
src/exampleAlgorithms/FlexExample.java

@@ -46,6 +46,7 @@ import ui.model.DecoratedGroupNode;
 import ui.model.DecoratedNetwork;
 import ui.model.DecoratedState;
 import ui.model.Model;
+import ui.model.DecoratedHolonObject.HolonObjectState;
 
 public class FlexExample implements Algorithm {
 
@@ -229,6 +230,7 @@ public class FlexExample implements Algorithm {
 				}				
 			}
 			updateVisual();
+			calculateAllResults(result);
 			println("Amount of activatedFlex:" + result.activatedFlex + "   Amount of deactivatedElements:"+ result.deactivatedElements + "   TotalCost:"+result.totalCost);
 			printElapsedTime();
 			disableGuiInput(false);
@@ -402,9 +404,44 @@ public class FlexExample implements Algorithm {
 				
 				println("Activated FlexThisTimeStep: "+ amountflexActivated+"   CostForThisTimeStep:" + costForThisTimeStep);
 				result.totalCost += costForThisTimeStep;
-				
 			}
+			calculateStateResult(result);
+		}
+		private void calculateStateResult(RunResult result) {
+			control.calculateStateOnlyForCurrentTimeStep();
+			RunResult.TimeStepStateResult timeStepState = result.addTimeStepStateResult();
+			
+			for(DecoratedNetwork network: control.getSimManager().getActualDecorState().getNetworkList()) {
+				timeStepState.amountOfConsumer += network.getAmountOfConsumer();
+				timeStepState.amountOfConsumerOverSupplied += network.getAmountOfConsumerWithState(HolonObjectState.OVER_SUPPLIED);
+				timeStepState.amountOfConsumerPartiallySupplied += network.getAmountOfConsumerWithState(HolonObjectState.PARTIALLY_SUPPLIED);
+				timeStepState.amountOfConsumerSupplied += network.getAmountOfConsumerWithState(HolonObjectState.SUPPLIED);
+				timeStepState.amountOfConsumerUnSupplied += network.getAmountOfConsumerWithState(HolonObjectState.NOT_SUPPLIED);
+				timeStepState.amountOfPassiv += network.getAmountOfPassiv();
+				timeStepState.amountOfProducer += network.getAmountOfSupplier();	
+			}
+			println("Producer: " + timeStepState.amountOfProducer);
+			println("Consumer: " + timeStepState.amountOfConsumer);
+			println("ConsumerOverSupplied: " + timeStepState.amountOfConsumerOverSupplied);
+			println("ConsumerSupplied: " + timeStepState.amountOfConsumerSupplied);
+			println("ConsumerPartiallySupplied: " + timeStepState.amountOfConsumerPartiallySupplied);
+			println("ConsumerUnSupplied: " + timeStepState.amountOfConsumerUnSupplied);
+			println("ConsumerUnSupplied: " + timeStepState.amountOfPassiv);
+		}
+		private void calculateAllResults(RunResult result) {
+			println("----------");
+			println("Average producer proportion: " + result.getAvergaeProportionWithState(HolonObjectState.PRODUCER));
+			println("Average producer OverSupplied: " + result.getAvergaeProportionWithState(HolonObjectState.OVER_SUPPLIED));
+			println("Average producer Supplied: " + result.getAvergaeProportionWithState(HolonObjectState.SUPPLIED));
+			println("Average producer PartiallySupplied: " + result.getAvergaeProportionWithState(HolonObjectState.PARTIALLY_SUPPLIED));
+			println("Average producer NotSupplied: " + result.getAvergaeProportionWithState(HolonObjectState.NOT_SUPPLIED));
+			println("Average producer NoEnergy: " + result.getAvergaeProportionWithState(HolonObjectState.NO_ENERGY));
 		}
+		
+		
+		
+		
+		
 		private float shutDownAllConsumerElementsWithPriority(FlexManager flexManager, Set<HolonElement> allHolonElemntsInThisNetwork,
 				Priority emergencyShutDownPriority, RunResult result) {
 			
@@ -561,6 +598,48 @@ public class FlexExample implements Algorithm {
 			public int activatedFlex = 0;
 			public int deactivatedElements = 0;
 			public int totalCost = 0;
+			public LinkedList<TimeStepStateResult> timeStepList = new LinkedList<TimeStepStateResult>();
+			
+			
+			public TimeStepStateResult addTimeStepStateResult(){
+				TimeStepStateResult aResult = new TimeStepStateResult();
+				timeStepList.add(aResult);
+				return aResult;
+			}
+			
+			
+			public class TimeStepStateResult{
+				public int amountOfProducer = 0;
+				public int amountOfConsumer = 0;
+				public int amountOfPassiv = 0;
+				public int amountOfConsumerOverSupplied = 0;
+				public int amountOfConsumerSupplied = 0;
+				public int amountOfConsumerPartiallySupplied = 0;
+				public int amountOfConsumerUnSupplied= 0;
+				
+				public float getProportionWithState(HolonObjectState state) {
+					float amountOfObjects = amountOfProducer + amountOfConsumer + amountOfPassiv;
+					switch(state) {
+					case NOT_SUPPLIED:
+						return (float) amountOfConsumerUnSupplied / amountOfObjects;
+					case NO_ENERGY:
+						return (float) amountOfPassiv / amountOfObjects;
+					case OVER_SUPPLIED:
+						return (float) amountOfConsumerOverSupplied / amountOfObjects;
+					case PARTIALLY_SUPPLIED:
+						return (float) amountOfConsumerPartiallySupplied / amountOfObjects;
+					case PRODUCER:
+						return (float) amountOfProducer / amountOfObjects;
+					case SUPPLIED:
+						return (float) amountOfConsumerSupplied / amountOfObjects;
+					default:
+						return 0.f;
+					}
+				}
+			}
+			public float getAvergaeProportionWithState(HolonObjectState state) {
+				return timeStepList.stream().map(step -> step.getProportionWithState(state)).reduce((a,b) -> (a + b)).orElse(0.f) / (float) 100;
+			}
 		}
 		
 		private   class  Handle<T>{

+ 20 - 0
src/ui/model/DecoratedNetwork.java

@@ -281,4 +281,24 @@ public class DecoratedNetwork {
 		con.getSupplierList().add(con.new SupplierListEntry(sup, energy));
 		con.setEnergyFromNetwork(con.getEnergyFromNetwork() + energy);
 	}
+
+
+	public int getAmountOfConsumer() {
+		return consumerList.size() + this.consumerSelfSuppliedList.size();
+	}
+
+
+	public int getAmountOfSupplier() {
+		return supplierList.size();
+	}
+
+
+	public int getAmountOfConsumerWithState(HolonObjectState state) {
+		return (int) (consumerList.stream().filter(con -> con.getState() == state).count() + consumerSelfSuppliedList.stream().filter(con -> con.getState() == state).count());
+	}
+
+
+	public int getAmountOfPassiv() {
+		return passivNoEnergyList.size();
+	}
 }