Browse Source

Print and F_max update

Troppmann, Tom 3 years ago
parent
commit
1724fd572a

+ 47 - 22
src/algorithm/objectiveFunction/TopologieObjectiveFunction.java

@@ -22,11 +22,12 @@ public class TopologieObjectiveFunction {
 	/**
 	 * Maximum Energie Difference(kappa)
 	 */
-	static double k_eb = 400000.f;
+	static double k_eb = 20000.f;
 	/**
 	 * Maximum when all on Energie Difference(kappa)
 	 */
-	static double k_max = 450000.f;
+	static double k_max = 10.f;
+	static double lambda_max = 10.;
 	
 	//--> f_holon parameter
 	/**
@@ -107,24 +108,27 @@ public class TopologieObjectiveFunction {
 		//Calculate f_eb the penalty for unbalenced energy in the network
 		double f_eb = 0;
 		for(DecoratedNetwork net : state.getNetworkList()) {
-			double netEnergyDifference = 0;
-			netEnergyDifference += net.getConsumerList().stream().map(con -> con.getEnergySelfSupplied() - con.getEnergyFromConsumingElemnets()).reduce(0.f, Float::sum);
-			netEnergyDifference += net.getConsumerSelfSuppliedList().stream().map(con -> con.getEnergySelfSupplied() - con.getEnergyFromConsumingElemnets()).reduce(0.f, Float::sum);
-			netEnergyDifference += net.getSupplierList().stream().map(sup -> sup.getEnergyProducing() - sup.getEnergySelfConsuming()).reduce(0.f, Float::sum);
 			//abs
-			f_eb += Math.abs(netEnergyDifference);
+			f_eb += Math.abs(net.getTotalConsumption() - net.getTotalProduction());
 		}
+		//Average?
+		f_eb /= state.getNetworkList().size();
+		
+		
+		
 		
 		double f_maximum = 0;
-		final int timestep = state.getTimestepOfState();
 		for(DecoratedNetwork net : state.getNetworkList()) {
-			double maximumEnergy = 0;
-			maximumEnergy += net.getConsumerList().stream().map(con -> con.getModel().getMaximumConsumptionPossible(timestep) - con.getModel().getMaximumProductionPossible(timestep)).reduce(0.f, Float::sum);
-			maximumEnergy += net.getConsumerSelfSuppliedList().stream().map(con -> con.getModel().getMaximumConsumptionPossible(timestep) - con.getModel().getMaximumProductionPossible(timestep)).reduce(0.f, Float::sum);
-			maximumEnergy += net.getSupplierList().stream().map(con -> con.getModel().getMaximumConsumptionPossible(timestep) - con.getModel().getMaximumProductionPossible(timestep)).reduce(0.f, Float::sum);
-			f_maximum += Math.abs(maximumEnergy);
+			double prod = net.getTotalProduction();
+			double con = net.getTotalConsumption();
+			if(prod == 0 || con == 0) {
+				f_maximum += lambda_max;
+			}else {
+				f_maximum += lambda_max * (Math.abs(prod - con)/Math.max(prod, con));				
+			}
 		}
-		
+		//Average?
+		f_maximum /= state.getNetworkList().size();
 		
 		//calculate f_holon
 		double f_holon = 0;
@@ -169,7 +173,7 @@ public class TopologieObjectiveFunction {
 		
 		
 		f_selection += cost_of_cable_per_meter * addedCableMeters;
-		if(moreInformation)System.out.println("CostForWildcards:" + cost + ", CostSwitches(#" + amountOfAddedSwitch +"):" + cost_switch * amountOfAddedSwitch + ", CostCables(" +addedCableMeters+ "m):" + cost_of_cable_per_meter * addedCableMeters);
+		//if(moreInformation)System.out.println("CostForWildcards:" + cost + ", CostSwitches(#" + amountOfAddedSwitch +"):" + cost_switch * amountOfAddedSwitch + ", CostCables(" +addedCableMeters+ "m):" + cost_of_cable_per_meter * addedCableMeters);
 		
 		
 		//calculating f_grid
@@ -193,8 +197,11 @@ public class TopologieObjectiveFunction {
 		
 		
 		
-		
+		if(moreInformation) {
+			printWeightedValues(f_eb, f_maximum, f_holon, f_selection, f_grid);
+		}
 		//printUnsquashedValues(f_eb, f_maximum, f_holon, f_selection, f_grid);
+		
 		return (float) (w_eb * squash(f_eb, k_eb) 
 				+ w_max * squash(f_maximum, k_max) 
 				+ w_holon * squash(f_holon, k_holon) 
@@ -242,12 +249,30 @@ public class TopologieObjectiveFunction {
 		return (supplyPercentage < 100) ? -0.5 * supplyPercentage + 50: supplyPercentage - 100;
 	}
 	
-	static void printDistribution(double f_eb, double f_maximum, double f_holon, double f_selection, double f_grid){
-		 System.out.print(" f_eb(" + w_eb * squash(f_eb, k_eb) + ") ");
-		 System.out.print(" f_maximum(" + w_max * squash(f_maximum, k_max) + ") ");
-		 System.out.print(" f_holon(" + w_holon * squash(f_holon, k_holon)  + ") ");
-		 System.out.print(" f_selection(" + w_selection * squash(f_selection, k_selection)  + ") ");
-		 System.out.println(" f_grid(" + w_grid * f_grid + ") ");
+	static void printWeightedValues(double f_eb, double f_maximum, double f_holon, double f_selection, double f_grid){
+		 System.out.println("===================================================================");
+		 System.out.println(" f_eb: " + f_eb + ", k_eb: " + k_eb + ", w_eb: " + w_eb); 
+		 System.out.println(" squash(f_eb, k_eb): " + doubleToString(squash(f_eb, k_eb))); 
+		 System.out.println(" w_eb * squash(f_eb, k_eb): " + doubleToString(w_eb * squash(f_eb, k_eb))); 
+		 System.out.println("===================================================================");
+		 System.out.println(" f_maximum: " + f_maximum + ", k_max: " + k_max + ", w_max: " + w_max); 
+		 System.out.println(" squash(f_maximum, k_max): " + doubleToString(squash(f_maximum, k_max))); 
+		 System.out.println(" w_max * squash(f_maximum, k_max): " + doubleToString(w_max * squash(f_maximum, k_max))); 
+		 System.out.println("===================================================================");
+		 System.out.println(" f_selection: " + f_selection + ", k_selection: " + k_selection + ", w_selection: " + w_selection); 
+		 System.out.println(" squash(f_selection, k_selection): " + doubleToString(squash(f_selection, k_selection))); 
+		 System.out.println(" w_selection * squash(f_selection, k_selection): " + doubleToString(w_selection * squash(f_selection, k_selection))); 
+		 System.out.println("===================================================================");
+		 System.out.println(" f_holon: " + f_holon + ", k_holon: " + k_holon + ", w_holon: " + w_holon); 
+		 System.out.println(" squash(f_holon, k_holon): " + doubleToString(squash(f_holon, k_holon))); 
+		 System.out.println(" w_holon * squash(f_holon, k_holon): " + doubleToString(w_holon * squash(f_holon, k_holon))); 
+		 System.out.println("===================================================================");
+		 System.out.println(" f_grid: " + f_grid + ", k_grid: " + k_grid + ", w_grid: " + w_grid); 
+		 System.out.println(" squash(f_grid, k_grid): " + doubleToString(squash(f_grid, k_grid))); 
+		 System.out.println(" w_grid * squash(f_grid, k_grid): " + doubleToString(w_grid * squash(f_grid, k_grid))); 
+		 System.out.println("===================================================================");
+		 System.out.println();
+		 System.out.println();
 	}
 	static void printUnsquashedValues(double f_eb, double f_maximum, double f_holon, double f_selection, double f_grid){
 		 System.out.print(" f_eb(" + f_eb + ") ");

+ 1 - 1
src/algorithm/topologie/AcoAlgorithm.java

@@ -36,7 +36,7 @@ public class AcoAlgorithm extends TopologieAlgorithmFramework {
 	}
 	@Override
 	protected double evaluateState(DecoratedState actualstate, int amountOfAddedSwitch, double addedCableMeters, boolean moreInformation) {
-		return TopologieObjectiveFunction.getFitnessValueForState(actualstate, amountOfAddedSwitch, addedCableMeters, this.moreInformation);
+		return TopologieObjectiveFunction.getFitnessValueForState(actualstate, amountOfAddedSwitch, addedCableMeters, moreInformation);
 	}
 
 	@Override

+ 1 - 1
src/algorithm/topologie/GaAlgorithm.java

@@ -45,7 +45,7 @@ public class GaAlgorithm extends TopologieAlgorithmFramework {
 	}
 	@Override
 	protected double evaluateState(DecoratedState actualstate, int amountOfAddedSwitch, double addedCableMeters, boolean moreInformation) {
-		return TopologieObjectiveFunction.getFitnessValueForState(actualstate, amountOfAddedSwitch, addedCableMeters, this.moreInformation);
+		return TopologieObjectiveFunction.getFitnessValueForState(actualstate, amountOfAddedSwitch, addedCableMeters, moreInformation);
 	}
 
 	@Override

+ 1 - 1
src/algorithm/topologie/PsoAlgorithm.java

@@ -58,7 +58,7 @@ public class PsoAlgorithm extends TopologieAlgorithmFramework {
 	
 	@Override
 	protected double evaluateState(DecoratedState actualstate, int amountOfAddedSwitch, double addedCableMeters, boolean moreInformation) {
-		return TopologieObjectiveFunction.getFitnessValueForState(actualstate, amountOfAddedSwitch, addedCableMeters, this.moreInformation);
+		return TopologieObjectiveFunction.getFitnessValueForState(actualstate, amountOfAddedSwitch, addedCableMeters, moreInformation);
 	}
 
 	@Override

+ 12 - 1
src/api/TopologieAlgorithmFramework.java

@@ -469,7 +469,7 @@ public abstract class TopologieAlgorithmFramework implements AddOn{
 		}
 //		reset();
 //		this.extractPositionAndAccess();
-		double currentFitness = evaluateNetwork();
+		double currentFitness = evaluateNetworkAndPrint();
 		console.println("Actual Fitnessvalue: " + currentFitness);
 	}
 	
@@ -492,6 +492,16 @@ public abstract class TopologieAlgorithmFramework implements AddOn{
 		DecoratedState actualstate = control.getSimManager().getActualDecorState();
 		return evaluateState(actualstate, calculateAmountOfAddedSwitches(), addedCableMeter(), false);
 	}
+	private double evaluateNetworkAndPrint() {
+		runProgressbar.step();
+		for(HolonSwitch hSwitch: switchList) {
+			hSwitch.setManualMode(true);
+			hSwitch.setManualState(false);
+		}
+		control.calculateStateOnlyForCurrentTimeStep();
+		DecoratedState actualstate = control.getSimManager().getActualDecorState();
+		return evaluateState(actualstate, calculateAmountOfAddedSwitches(), addedCableMeter(), true);
+	}
 	
 	
 	private double addedCableMeter() {
@@ -607,6 +617,7 @@ public abstract class TopologieAlgorithmFramework implements AddOn{
 			hSwitch.setManualState(false);
 		}
 		updateVisual();
+		evaluateNetworkAndPrint();
 		console.println("Start: " + startFitness);
 		console.println("AlgoResult: " + runBest.fitness);
 	}