Procházet zdrojové kódy

Adds additional Log Information

Troppmann, Tom před 4 roky
rodič
revize
b31b894f0b

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

@@ -249,7 +249,7 @@ public class GaAlgorithm extends AlgorithmFrameworkFlex{
 				+ " maxGenerations:" + maxGenerations
 				+ " popsize:" + popsize
 				+ " tournamentSize:" +  tournamentSize
-				+ (useFixedSpawProbability? " fixedSwapProbability:" +  fixedSwapProbability:" swapProbability:" + "1.0f/problemsize")
+				+ (useFixedSpawProbability? " fixedSwapProbability:" +  fixedSwapProbability : " swapProbability:" + "1.0f/problemsize")
 				+ (useIntervalMutation? 
 						(" mutateProbabilityInterval:" +  mutateProbabilityInterval
 						+ " maxMutationPercent:" +  maxMutationPercent)

+ 48 - 33
src/algorithm/objectiveFunction/TopologieObjectiveFunction.java

@@ -142,39 +142,7 @@ public class TopologieObjectiveFunction {
 		f_holon /= state.getNetworkList().size();
 		
 		//calculating f_selection
-		double f_selection = 0;
-		double cost = 0;
-		for(DecoratedNetwork net : state.getNetworkList()) {
-			for(DecoratedHolonObject dHobject : net.getConsumerList()) {
-				if(dHobject.getModel().getName().contains("Wildcard")){
-					if(dHobject.getModel().getName().length() > 9) {
-						String costString = dHobject.getModel().getName().substring(9);
-						cost += Double.parseDouble(costString);
-					}
-				}
-			}
-			for(DecoratedHolonObject dHobject : net.getConsumerSelfSuppliedList()) {
-				if(dHobject.getModel().getName().contains("Wildcard")){
-					if(dHobject.getModel().getName().length() > 9) {
-						String costString = dHobject.getModel().getName().substring(9);
-						cost += Double.parseDouble(costString);
-					}
-				}
-			}
-			for(DecoratedHolonObject dHobject : net.getSupplierList()) {
-				if(dHobject.getModel().getName().contains("Wildcard")){
-					if(dHobject.getModel().getName().length() > 9) {
-						String costString = dHobject.getModel().getName().substring(9);
-						cost += Double.parseDouble(costString);
-					}
-				}
-			}
-		}
-		f_selection += cost;
-		f_selection += cost_switch * amountOfAddedSwitch;
-		
-		
-		f_selection += cost_of_cable_per_meter * addedCableMeters;
+		double f_selection = calculateTopologieCost(state, amountOfAddedSwitch, addedCableMeters);
 		//if(moreInformation)System.out.println("CostForWildcards:" + cost + ", CostSwitches(#" + amountOfAddedSwitch +"):" + cost_switch * amountOfAddedSwitch + ", CostCables(" +addedCableMeters+ "m):" + cost_of_cable_per_meter * addedCableMeters);
 		
 		
@@ -224,6 +192,53 @@ public class TopologieObjectiveFunction {
 				+ w_grid * squash(f_grid, k_grid));
 	}
 
+	public static double calculateTopologieCost(DecoratedState state, int amountOfAddedSwitch,
+			double addedCableMeters) {
+		double cost = calculateWildcardCost(state);
+		cost += calculateAddedSwitchCost(amountOfAddedSwitch);
+		cost += calculateAddedCableCost(addedCableMeters);		
+		return cost;
+	}
+
+	public static double calculateAddedCableCost(double addedCableMeters) {
+		return cost_of_cable_per_meter * addedCableMeters;
+	}
+
+	public static double calculateAddedSwitchCost(int amountOfAddedSwitch) {
+		return cost_switch * amountOfAddedSwitch;
+	}
+
+	public static double calculateWildcardCost(DecoratedState state) {
+		double cost = 0;
+		for(DecoratedNetwork net : state.getNetworkList()) {
+			for(DecoratedHolonObject dHobject : net.getConsumerList()) {
+				if(dHobject.getModel().getName().contains("Wildcard")){
+					if(dHobject.getModel().getName().length() > 9) {
+						String costString = dHobject.getModel().getName().substring(9);
+						cost += Double.parseDouble(costString);
+					}
+				}
+			}
+			for(DecoratedHolonObject dHobject : net.getConsumerSelfSuppliedList()) {
+				if(dHobject.getModel().getName().contains("Wildcard")){
+					if(dHobject.getModel().getName().length() > 9) {
+						String costString = dHobject.getModel().getName().substring(9);
+						cost += Double.parseDouble(costString);
+					}
+				}
+			}
+			for(DecoratedHolonObject dHobject : net.getSupplierList()) {
+				if(dHobject.getModel().getName().contains("Wildcard")){
+					if(dHobject.getModel().getName().length() > 9) {
+						String costString = dHobject.getModel().getName().substring(9);
+						cost += Double.parseDouble(costString);
+					}
+				}
+			}
+		}
+		return cost;
+	}
+
 	private static String doubleToString(double value) {
 		return String.format (Locale.US, "%.2f", value);
 	}

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

@@ -87,7 +87,11 @@ public class AcoAlgorithm extends TopologieAlgorithmFramework {
 
 	@Override
 	protected String algoInformationToPrint() {
-		return "GA for topologie generation";
+		return "Aco for Topologie "+ " Rounds:" + rounds 
+				+ " maxGenerations:" + maxGenerations 
+				+ " popsize:" +  popsize
+				+ " vaporization:" +  p
+				+ " convergenceFactorReset:" +  convergenceFactorReset;
 	}
 
 	@Override

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

@@ -99,7 +99,16 @@ public class GaAlgorithm extends TopologieAlgorithmFramework {
 
 	@Override
 	protected String algoInformationToPrint() {
-		return "GA for topologie generation";
+		return "GaAlgo"+ " Rounds:" + rounds 
+				+ " maxGenerations:" + maxGenerations
+				+ " popsize:" + popsize
+				+ " tournamentSize:" +  tournamentSize
+				+ (useFixedSpawProbability? " fixedSwapProbability:" +  fixedSwapProbability:" swapProbability:" + "1.0f/problemsize")
+				+ (useIntervalMutation? 
+						(" mutateProbabilityInterval:" +  mutateProbabilityInterval
+						+ " maxMutationPercent:" +  maxMutationPercent)
+						: 
+						(useFixedMutateProbability? " fixedMutateProbability:" +  fixedMutateProbability:" mutateProbability:" + "1.0f/problemsize"));
 	}
 
 	@Override

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

@@ -161,7 +161,16 @@ public class PsoAlgorithm extends TopologieAlgorithmFramework {
 
 	@Override
 	protected String algoInformationToPrint() {
-		return "PSO for topologie generation";
+		return "PsoAlgo"+ " Rounds:" + rounds 
+				+ " maxIterations:" + maxGenerations
+				+ " swarmSize:" + popsize
+				+ " dependency:" +  dependency
+				+ " mutationInterval:" +  mutationInterval
+				+ " maxVelocity: " + maxVelocity
+				+ " deviation: " + deviation
+				+ (useIntervalMutation? 
+						(" mutateProbabilityInterval:" +  mutateProbabilityInterval
+						+ " maxMutationPercent:" +  maxMutationPercent) : " mutationRate:" + mutationRate);
 	}
 
 	@Override

+ 27 - 22
src/api/TopologieAlgorithmFramework.java

@@ -988,37 +988,42 @@ public abstract class TopologieAlgorithmFramework implements AddOn{
 		
 		
 		
-		List<Flexibility> flexActiveList = control.getSimManager().getActualFlexManager().getAllFlexWrapperWithState(FlexState.IN_USE).stream().map(flex -> flex.getFlex()).collect(Collectors.toList());
-		int amountActiveEssential = (int)flexActiveList.stream().filter(flex -> flex.getElement().getPriority() == Priority.Essential).count();
-		int amountActiveHigh = (int)flexActiveList.stream().filter(flex -> flex.getElement().getPriority() == Priority.High).count();
-		int amountActiveMedium = (int)flexActiveList.stream().filter(flex -> flex.getElement().getPriority() == Priority.Medium).count();
-		int amountActiveLow = (int)flexActiveList.stream().filter(flex -> flex.getElement().getPriority() == Priority.Low).count();
-		int amountActiveFlexibilities = amountActiveEssential + amountActiveHigh + amountActiveMedium + amountActiveLow;
 		int amountHolons = state.getNetworkList().size();
 		int amountSwitch = state.getDecoratedSwitches().size();
 		int amountActiveSwitch = (int)state.getDecoratedSwitches().stream().filter(dswitch -> (dswitch.getState() == SwitchState.Closed)).count();
 		
+		int addedSwitches = calculateAmountOfAddedSwitches();
+		double addedCableMeters = addedCableMeter();
+		double wildcardCost = TopologieObjectiveFunction.calculateWildcardCost(state);
+		double cableCost = TopologieObjectiveFunction.calculateWildcardCost(state);
+		double switchCost = TopologieObjectiveFunction.calculateWildcardCost(state);
+		double totalCost = wildcardCost + cableCost + switchCost;
 		
 		return	"HolonObjects["
-			+	" Passiv: " + percentage(amountOfPassiv, amountOfObjects)
-			+	" Producer: " + percentage(amountOfSupplier, amountOfObjects)
-			+	" Consumer: " + percentage(amountOfConsumer, amountOfObjects)
-			+	" Unsupplied: " + percentage(unSuppliedConsumer, amountOfConsumer)
-			+	" PartiallySupplied: " + percentage(partiallySuppliedConsumer, amountOfObjects)
-			+	" Supplied: " + percentage(suppliedConsumer, amountOfConsumer)
-			+	" Over: " + percentage(overSuppliedConsumer, amountOfConsumer)
-			+  "]" + "   HolonElemnts["
-			+	" Active: " + percentage(activeElements, amountOfelements)
-			+ "]" + "Flexibilities_active[" 
-			+ " Essential: " + percentage(amountActiveEssential, amountActiveFlexibilities)
-			+ " High: " + percentage(amountActiveHigh, amountActiveFlexibilities)
-			+ " Medium: " + percentage(amountActiveMedium, amountActiveFlexibilities)
-			+ " Low: " + percentage(amountActiveLow, amountActiveFlexibilities)
-			+ "]" + " activeSwitches:" + percentage(amountActiveSwitch,amountSwitch)
+			+ " Passiv: " + percentage(amountOfPassiv, amountOfObjects)
+			+ " Producer: " + percentage(amountOfSupplier, amountOfObjects)
+			+ " Consumer: " + percentage(amountOfConsumer, amountOfObjects)
+			+ " Unsupplied: " + percentage(unSuppliedConsumer, amountOfConsumer)
+			+ " PartiallySupplied: " + percentage(partiallySuppliedConsumer, amountOfObjects)
+			+ " Supplied: " + percentage(suppliedConsumer, amountOfConsumer)
+			+ " Over: " + percentage(overSuppliedConsumer, amountOfConsumer)
+			+ "]" + "   HolonElemnts["
+			+ " Active: " + percentage(activeElements, amountOfelements)
+			+ "]" 
+			+ " activeSwitches:" + percentage(amountActiveSwitch,amountSwitch)
 			+ " Holons: " + amountHolons
 			+ " totalConsumption: " + totalConsumption
 			+ " totalProduction: " + totalProduction
-			+ " difference: " + difference;
+			+ " difference: " + difference
+			+ " Topologie["
+			+ " addedCableMeters:" + addedCableMeters
+			+ " addedSwitches: " + addedSwitches
+			+ " totalCost: " + totalCost + "("
+			+ " wildcardCost: " + wildcardCost
+			+ " cableCost: " + cableCost
+			+ " switchCost: " + switchCost
+			+  ")]"
+			;
 		
 	}