Quellcode durchsuchen

Varianz and Dispersion for holons(networks)

Tom Troppmann vor 4 Jahren
Ursprung
Commit
a960808d5e
2 geänderte Dateien mit 75 neuen und 2 gelöschten Zeilen
  1. 63 1
      src/ui/model/DecoratedNetwork.java
  2. 12 1
      src/ui/model/Supplier.java

+ 63 - 1
src/ui/model/DecoratedNetwork.java

@@ -228,7 +228,7 @@ public class DecoratedNetwork {
 			float energyNeeded = hObject.getEnergyNeededFromConsumingElementsWithFlex(Iteration, flexManager);
 			float energySelfProducing = hObject.getEnergySelfProducingFromProducingElementsWithFlex(Iteration, flexManager);
 			if(energyNeeded < energySelfProducing) {
-				Supplier sup = new Supplier(hObject, energySelfProducing - energyNeeded);
+				Supplier sup = new Supplier(hObject, energySelfProducing - energyNeeded, energyNeeded);
 				supplierList.add(sup);
 			} else if (energyNeeded > energySelfProducing) {
 				Consumer con = new Consumer(hObject);
@@ -301,4 +301,66 @@ public class DecoratedNetwork {
 	public int getAmountOfPassiv() {
 		return passivNoEnergyList.size();
 	}
+	public int getAmountOfHolonObjects() {
+		return getAmountOfConsumer() + getAmountOfSupplier() + getAmountOfPassiv();
+	}
+	
+	
+	public float getTotalConsumption() {
+		float energy = consumerList.stream().map(con -> con.getEnergyFromConsumingElemnets()).reduce(0.f, Float::sum) + consumerSelfSuppliedList.stream().map(con -> con.getEnergyFromConsumingElemnets()).reduce(0.f, Float::sum);
+		energy += supplierList.stream().map(sup -> sup.getEnergySelfConsuming()).reduce(0.f,  Float::sum);
+		return energy;
+	}
+	
+	public float getAverageConsumptionInNetworkForHolonObject(){
+		return getTotalConsumption() / (float)getAmountOfHolonObjects();
+	}
+	
+	public float getTotalProduction() {
+		float energy = consumerList.stream().map(con -> con.getEnergySelfSupplied()).reduce(0.f, Float::sum) + consumerSelfSuppliedList.stream().map(con -> con.getEnergySelfSupplied()).reduce(0.f, Float::sum);
+		energy += supplierList.stream().map(sup -> sup.getEnergyProducing()).reduce(0.f,  Float::sum);
+		return energy;
+	}
+	
+	public float getAverageProductionInNetworkForHolonObject() {
+		return getTotalProduction() /  (float) getAmountOfHolonObjects();
+	}
+	
+	/**
+	 * returns the Varianz in Poduction
+	 * @return
+	 */
+	public float getVarianzInProductionInNetworkForHolonObjects() {
+		float average = getAverageProductionInNetworkForHolonObject();
+		float sum = consumerList.stream().map(con -> sqared(con.getEnergySelfSupplied() - average)).reduce(0.f, Float::sum) 
+				+ consumerSelfSuppliedList.stream().map(con -> sqared(con.getEnergySelfSupplied() - average)).reduce(0.f, Float::sum)
+				+ supplierList.stream().map(sup -> sqared(sup.getEnergyProducing() - average)).reduce(0.f,  Float::sum);
+		return sum / (float) getAmountOfHolonObjects();
+	}
+	
+	
+	public float getDispersionInProductionInNetworkForHolonObjects() {
+		return (float)Math.sqrt(getVarianzInProductionInNetworkForHolonObjects());
+	}
+	
+	
+	public float getVarianzInConsumptionInNetworkForHolonObjects() {
+		float average = getAverageConsumptionInNetworkForHolonObject();
+		float sum = consumerList.stream().map(con -> sqared(con.getEnergyFromConsumingElemnets() - average)).reduce(0.f, Float::sum) 
+				+ consumerSelfSuppliedList.stream().map(con -> sqared(con.getEnergyFromConsumingElemnets() - average)).reduce(0.f, Float::sum)
+				+ supplierList.stream().map(sup -> sqared(sup.getEnergySelfConsuming() - average)).reduce(0.f,  Float::sum);
+		return sum / (float) getAmountOfHolonObjects();
+	}
+	
+	public float getDispersionInConsumptionInNetworkForHolonObjects() {
+		return (float)Math.sqrt(getVarianzInProductionInNetworkForHolonObjects());
+	}
+	
+	//Help Function
+	private float sqared(float input) {
+		return (float) Math.pow(input, 2);
+	}
+	
+	
+	
 }

+ 12 - 1
src/ui/model/Supplier.java

@@ -9,10 +9,12 @@ public class Supplier extends DecoratedHolonObject {
 	private ArrayList<ConsumerListEntry> consumerList = new ArrayList<ConsumerListEntry>();
 	private float energyToSupplyNetwork;
 	private float energySupplied;
-	public Supplier(HolonObject objectToLookAt, float energyToSupplyNetwork) {
+	private float energySelfConsuming;
+	public Supplier(HolonObject objectToLookAt, float energyToSupplyNetwork, float energySelfConsuming) {
 		super(objectToLookAt);
 		this.energyToSupplyNetwork = energyToSupplyNetwork;
 		energySupplied = 0.0f;
+		this.energySelfConsuming = energySelfConsuming;
 	}
 
 	@Override
@@ -32,6 +34,15 @@ public class Supplier extends DecoratedHolonObject {
 		return energyToSupplyNetwork;
 	}
 
+	
+	public float getEnergySelfConsuming() {
+		return energySelfConsuming;
+	}
+	
+	public float getEnergyProducing() {
+		return energyToSupplyNetwork + energySelfConsuming;
+	}
+	
 	public float getEnergySupplied() {
 		return energySupplied;
 	}