Browse Source

Objective Function update in weights

Tom Troppmann 4 years ago
parent
commit
27f0a117d0

+ 23 - 14
src/exampleAlgorithms/ObjectiveFunctionByCarlos.java

@@ -12,10 +12,10 @@ public class ObjectiveFunctionByCarlos {
 	//Parameters
 	
 	//weight for f_g(H)
-	static double w_eb = .35f, w_state = .35f, w_pro = .1f, w_perf = .1f, w5=.1f;
+	static double w_eb = .3, w_state = .3, w_pro = .2, w_perf = .1, w_holon=.1;
 	
 	//kappas for squashing function
-	static double k_eb = 1000000.f, k_state = 30000, k_pro = 2100, k_perf = 1100, k_holon= 200000;
+	static double k_eb = 1000000.f, k_state = 15000, k_pro = 2100, k_perf = 1100, k_holon= 200000;
 	
 	//theta for f_pro
 	static double theta = 3;
@@ -57,7 +57,7 @@ public class ObjectiveFunctionByCarlos {
 	 * Here should all invariants be placed to be checked on initialization.
 	 */
 	private static void checkParameter() {
-		if(!(Math.abs(w_eb + w_state + w_pro + w_perf + w5 - 1) < 0.001)) {
+		if(!(Math.abs(w_eb + w_state + w_pro + w_perf + w_holon - 1) < 0.001)) {
 			System.err.println("ParameterError in ObjectiveFunction: w1 + w2 + w3 + w4 + w5 should be 1");
 		}
 	}
@@ -101,7 +101,7 @@ public class ObjectiveFunctionByCarlos {
 		//calculate f_pro the penalty function for priority usage 
 		// for each active flexibility punish
 		double f_pro = 0;
-		f_pro = state.getFlexManager().getAllFlexesOrderedThisTimeStep().stream().map(flex -> Math.pow(theta, priorityToDouble(flex.getElement().getPriority()) )).reduce(0.0, Double::sum);
+		f_pro = state.getFlexManager().getAllFlexesOrderedThisTimeStep().stream().map(flex -> Math.pow(theta, priorityToDouble(flex.getElement().getPriority()) ) - 1.0).reduce(0.0, Double::sum);
 		
 		//calculate f_perf the penalty function for the quality of a flexibility used
 		
@@ -127,8 +127,8 @@ public class ObjectiveFunctionByCarlos {
 			double prod = net.getTotalProduction();
 			double flexcapProd = net.getFlexibilityProductionCapacity();
 			double flexcapCon = net.getFlexibilityConsumptionCapacity();
-			double f_change_positive = (con > 0.0)?  flexcapProd / con : 1.0;
-			double f_change_negativ = (prod > 0.0)? flexcapCon / prod: 1.0;
+			double f_change_positive = lambda_f_change - lambda_f_change * Math.min(1, (con > 0.0)?  flexcapProd / con : 1.0 );
+			double f_change_negativ = lambda_f_change - lambda_f_change * Math.min(1, (prod > 0.0)? flexcapCon / prod: 1.0);
 			
 			
 			
@@ -136,12 +136,12 @@ public class ObjectiveFunctionByCarlos {
 			
 			double f_element = f_elements_diviation_production +f_elements_diviation_consumption;
 			double f_flexibility = f_flexibility_diviation_consumption +f_flexibility_diviation_production;
-			double f_change = lambda_f_change  - 0.5 * lambda_f_change * ( Math.min(1, f_change_positive) + Math.min(1, f_change_negativ));
+			double f_change = f_change_positive + f_change_negativ;
 			
 			f_holon += f_element + f_flexibility + f_change;
-			System.out.print( "f_element=" + doubleToString(f_element));
-			System.out.print( " f_flexibility=" + doubleToString(f_flexibility));
-			System.out.println( " f_change=" + doubleToString(f_change));
+//			System.out.print( "f_element=" + doubleToString(f_element));
+//			System.out.print( " f_flexibility=" + doubleToString(f_flexibility));
+//			System.out.println( " f_change=" + doubleToString(f_change));
 //			System.out.print( "f+elements=" + doubleToString(f_elements_diviation_production));
 //			System.out.print( " f-elements=" + doubleToString(f_elements_diviation_consumption));
 //			System.out.print( " f+flexibility" + doubleToString(f_flexibility_diviation_consumption));
@@ -154,14 +154,23 @@ public class ObjectiveFunctionByCarlos {
 		
 		
 		
-//		System.out.print( "f_eb=" + f_eb);
+//		System.out.print( "f_ebVALUE=" + f_eb);
 //		System.out.print( " f_state=" + f_state);
 //		System.out.print( " f_pro=" + f_pro);
 //		System.out.print( " f_perf=" + f_perf);
 //		System.out.println( " f_holon=" + f_holon);
-		
-		
-		return (float) (w_eb * squash(f_eb, k_eb) + w_state * squash(f_state, k_state) + w_pro * squash(f_pro, k_pro) + w_perf * squash(f_perf, k_perf) + w5 * squash(f_holon, k_holon));
+		double q1 = squash(f_eb, k_eb);
+		double q2 = squash(f_state, k_state);
+		double q3 = squash(f_pro, k_pro);
+		double q4 = squash(f_perf, k_perf);
+		double q5 = squash(f_holon, k_holon);
+//		System.out.print( "f_eb=" + q1);
+//		System.out.print( " f_state=" + q2);
+//		System.out.print( " f_pro=" + q3);
+//		System.out.print( " f_perf=" + q4);
+//		System.out.println( " f_holon=" + q5);
+//		
+		return (float) (w_eb * q1 + w_state * q2 + w_pro * q3 + w_perf * q4 + w_holon * q5);
 	}
 	
 	private static String doubleToString(double value) {

+ 1 - 1
src/exampleAlgorithms/PsoAlgorithm.java

@@ -40,8 +40,8 @@ public class PsoAlgorithm extends AlgorithmFrameworkFlex{
 		super();
 		addIntParameter("swarmSize", swarmSize, intValue -> swarmSize = intValue, () -> swarmSize, 1);
 		addIntParameter("maxIterations", maxIterations, intValue -> maxIterations = intValue, () -> maxIterations, 1);
-		addIntParameter("mutationInterval", mutationInterval, intValue -> mutationInterval = intValue, () -> mutationInterval, 0);
 		addDoubleParameter("dependency", dependency, doubleValue -> dependency = doubleValue, () -> dependency, 2.001, 2.4);
+		addIntParameter("mutationInterval", mutationInterval, intValue -> mutationInterval = intValue, () -> mutationInterval, 0);
 		addBooleanParameter("useIntervalMutation", useIntervalMutation, booleanValue -> useIntervalMutation = booleanValue);
 		addDoubleParameter("mutateProbabilityInterval", mutateProbabilityInterval, doubleValue -> mutateProbabilityInterval = doubleValue, () -> mutateProbabilityInterval, 0.0, 1.0);
 		addDoubleParameter("maxMutationPercent", maxMutationPercent, doubleValue -> maxMutationPercent = doubleValue, () -> maxMutationPercent, 0.0, 1.0);