Browse Source

Information

Tom 5 năm trước cách đây
mục cha
commit
b2a03bea34

+ 23 - 9
src/exampleAlgorithms/AcoAlgorithm.java

@@ -59,6 +59,9 @@ public class AcoAlgorithm implements Algorithm {
 		private int rounds = 3;
 		
 		private int resetCount = 0;
+		private boolean moreInformation = false;
+		
+		
 		
 		
 		//Settings For GroupNode using and cancel
@@ -104,6 +107,7 @@ public class AcoAlgorithm implements Algorithm {
 		      newFrame.pack();
 		      newFrame.setVisible(true);
 		      newFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
+		      
 		}
 		public AcoAlgorithm() {
 			content.setLayout(new BorderLayout());
@@ -158,6 +162,14 @@ public class AcoAlgorithm implements Algorithm {
 			progressBar.setStringPainted(true);
 			parameterPanel.add(progressBar);
 			
+			JCheckBox informationCheckBox = new JCheckBox("More Information");
+			informationCheckBox.setSelected(this.moreInformation);
+			informationCheckBox.setBounds(350, 60, 220, 20);
+			informationCheckBox.addActionListener(actionEvent -> {
+				moreInformation = informationCheckBox.isSelected();
+			});
+			parameterPanel.add(informationCheckBox);
+			
 			JPanel borderPanel = new JPanel(null);
 			borderPanel.setBounds(350, 85, 185, 50);
 			borderPanel.setBorder(BorderFactory.createTitledBorder(""));
@@ -394,7 +406,7 @@ public class AcoAlgorithm implements Algorithm {
 			printElapsedTime();
 			setState(runBest.position);
 			updateVisual();
-			println("ResetsCount:"+resetCount);
+			if(moreInformation)println("ResetsCount:"+resetCount);
 			println("AlgoResult:" + runBest.fitness);
 			
 			
@@ -422,35 +434,37 @@ public class AcoAlgorithm implements Algorithm {
 		private Individual executeAcoAlgo() {
 			Individual best = new Individual();
 			best.position = extractPositionAndAccess();
-			println("Bit-Array_length: " + best.position.size());
+			if(moreInformation)println("Bit-Array_length: " + best.position.size());
 			best.fitness = evaluatePosition(best.position, false);
-			println("Start with Fitness: " + best.fitness);
+			console.print("Start with: " + best.fitness);
+			if(moreInformation)println("");
 			int problemSize = best.position.size();
 			if(problemSize == 0) return best;
 			List<Double> pheromones = initPheromones(problemSize);
 			List<Individual> population = new ArrayList<Individual>();
-			println("Size To Test:" + population.size());
+			if(moreInformation)println("Size To Test:" + population.size());
 			for(int generation = 0; generation< maxGenerations; generation++) {
 				population.clear();
 				population = constructSolutionsBiasedBy(pheromones);
-				println("Generation" + generation + " start with Fitness: " + best.fitness);
+				if(moreInformation)println("Generation" + generation + " start with Fitness: " + best.fitness);
 				for(Individual i : population) {
 					i.fitness = evaluatePosition(i.position, true);
-					println("Fitness" + i.fitness);
+					if(moreInformation)println("Fitness" + i.fitness);
 					if(i.fitness < best.fitness) best = i;	
 				}
-				println("________________");
+				if(moreInformation)println("________________");
 				vaporizeIntensifiePheromons(pheromones, best.position, problemSize);
 				double cf = calculateConvergenceFactor(pheromones, problemSize);
-				println("ConvergenceFactor = " + cf);
+				if(moreInformation)println("ConvergenceFactor = " + cf);
 				if(cf > this.convergenceFactorReset) {
 					pheromones = initPheromones(problemSize);
 					resetCount++;
 				}
+				if(cancel)return null;
 			}
 			
 			
-			println("RoundResult:" + best.fitness);
+			println("   End With:" + best.fitness);
 			return best;
 			
 		}

+ 20 - 10
src/exampleAlgorithms/GaAlgorithm.java

@@ -64,7 +64,7 @@ public class GaAlgorithm implements Algorithm {
 		private boolean useGroupNode = false;
 		private DecoratedGroupNode dGroupNode = null;
 		private boolean cancel = false;
-		
+		private boolean moreInformation = false;
 		
 
 		//Parameter defined by Algo
@@ -187,7 +187,15 @@ public class GaAlgorithm implements Algorithm {
 			});
 			borderPanel.add(useGroupNodeCheckBox);
 			
-	
+			JCheckBox informationCheckBox = new JCheckBox("More Information");
+			informationCheckBox.setSelected(this.moreInformation);
+			informationCheckBox.setBounds(350, 60, 220, 20);
+			informationCheckBox.addActionListener(actionEvent -> {
+				moreInformation = informationCheckBox.isSelected();
+			});
+			parameterPanel.add(informationCheckBox);
+			
+			
 			//Integer formatter
 			NumberFormat format = NumberFormat.getIntegerInstance();
 			format.setGroupingUsed(false);
@@ -474,17 +482,18 @@ public class GaAlgorithm implements Algorithm {
 		private Individual executeGaAlgo() {
 			Individual best = new Individual();
 			best.position = extractPositionAndAccess();
-			println("Bit-Array_length: " + best.position.size());
+			if(moreInformation)println("Bit-Array_length: " + best.position.size());
 			best.fitness = evaluatePosition(best.position, false);
-			println("Start with Fitness: " + best.fitness);
+			console.print("Start with: " + best.fitness);
+			if(moreInformation)println("");
 			int problemSize = best.position.size();
 			List<Individual> population = initPopuluationRandom(problemSize, best);
-			println("Size To Test:" + population.size());
+			if(moreInformation)println("Size To Test:" + population.size());
 			for(int generation = 0; generation< maxGenerations; generation++) {
-				println("Generation" + generation + " start with Fitness: " + best.fitness);
+				if(moreInformation)println("Generation" + generation + " start with Fitness: " + best.fitness);
 				for(Individual i : population) {
 					i.fitness = evaluatePosition(i.position, true);
-					println("Fitness" + i.fitness);
+					if(moreInformation)println("Fitness" + i.fitness);
 					if(i.fitness < best.fitness) best = i;
 					
 				}
@@ -501,11 +510,12 @@ public class GaAlgorithm implements Algorithm {
 					childList.add(childB);
 				}
 				population = childList;
-				println("________________");
+				if(moreInformation)println("________________");
+				if(cancel)return null;
 			}
 			
 			
-			println("RoundResult:" + best.fitness);
+			println("   End with:" + best.fitness);
 			return best;
 			
 		}
@@ -558,7 +568,7 @@ public class GaAlgorithm implements Algorithm {
 			//the remaining part is the chance to fight another time; 2.7 -> 70% chance to fight a second time
 			if( participants > 1) {		
 				if(Random.nextDouble() < participants - 1.0) {
-					println("Chance to find a match");
+					//println("Chance to find a match");
 					Individual next = population.get(Random.nextIntegerInRange(0, popsize));
 					if(next.fitness < tournamentBest.fitness) tournamentBest = next;
 				}

+ 0 - 1
src/exampleAlgorithms/PSOAlgorithm.java

@@ -77,7 +77,6 @@ public class PSOAlgorithm implements Algorithm {
 	
 	//Parameter for Plotting (Default Directory in Constructor)
 	private JFileChooser fileChooser = new JFileChooser();
-
 	
 	
 	//Gui Part: