Browse Source

fitness changes

Rolf Egert 5 years ago
parent
commit
a4fe4f5f06
1 changed files with 21 additions and 7 deletions
  1. 21 7
      src/exampleAlgorithms/PSOAlgotihm.java

+ 21 - 7
src/exampleAlgorithms/PSOAlgotihm.java

@@ -567,10 +567,8 @@ public class PSOAlgotihm implements Algorithm {
 		int activeElements = obj.getNumberOfActiveElements();
 		int maxElements = obj.getElements().size();
 		
-		if(activeElements == maxElements)
-			result =0;
-		else result = (float) Math.pow((maxElements -activeElements),2)*100;
-		
+		//result = (float) Math.pow((maxElements -activeElements),2)*10;
+		result = (float) Math.pow(5, 4* (maxElements -activeElements)/maxElements) - 1 ;
 		
 	return result;
 		
@@ -582,8 +580,8 @@ public class PSOAlgotihm implements Algorithm {
 	 * @return
 	 */
 	private double holonObjectSupplyPenaltyFunction(float supplyPercentage) {
-		float result = 0;
-		if(supplyPercentage == 1)
+		double result = 0;
+		/*if(supplyPercentage == 1)
 			return result;
 		else if(supplyPercentage < 1 && supplyPercentage >= 0.25) // undersupplied inbetween 25% and 100%
 			result = (float) Math.pow(1/supplyPercentage, 2);
@@ -596,7 +594,14 @@ public class PSOAlgotihm implements Algorithm {
 		
 		if(Float.isInfinite(result) || Float.isNaN(result))
 			result = 1000;
-	
+	*/
+		if(supplyPercentage <= 1.0) {
+			result = Math.pow(5,((100 - (supplyPercentage*100))/50 + 2)) - Math.pow(5, 2);
+		}
+		else {
+			result = Math.pow(6,((100 - (supplyPercentage*100))/50 + 2)) - Math.pow(6, 2);
+		}
+		
 		return result;
 	}
 	/**
@@ -718,6 +723,14 @@ public class PSOAlgotihm implements Algorithm {
 		 * each step of movement from the swarm.
 		 */
 		public void printToStream(BufferedWriter out) throws IOException {
+			try {
+				out.write(maxIterations + "," + allRuns.size() + "," + swarmSize);
+				out.newLine();
+
+			}
+			catch(IOException e) {
+				println(e.getMessage());
+			}
 			allRuns.forEach(run -> {
 				try {
 					out.write( run.stream().map(Object::toString).collect(Collectors.joining(", ")));
@@ -731,6 +744,7 @@ public class PSOAlgotihm implements Algorithm {
 			out.write(calculateAverageRun().stream().map(Object::toString).collect(Collectors.joining(", ")));
 			out.newLine();
 		}
+		
 		private List<Double> calculateAverageRun(){
 			int amountOfRuns = allRuns.size();
 			List<Double> newAverageRun = new ArrayList<Double>();