浏览代码

Amelioration code

Arthur Brandao 6 年之前
父节点
当前提交
16ae41c729
共有 4 个文件被更改,包括 32 次插入48 次删除
  1. 1 1
      Bandit/ControlBandit.cpp
  2. 二进制
      Bandit/GSATSolver
  3. 29 46
      Bandit/GSATThread.cpp
  4. 2 1
      Bandit/GSATThread.hpp

+ 1 - 1
Bandit/ControlBandit.cpp

@@ -108,7 +108,7 @@ fillAndHeuristic ControlBandit::methodEps() {
 		//Tirage au sort de fill et heuristic
 		fah.fill = this->getRandomFill();
 		fah.heuristic = this->getRandomHeuristic();
-		printf("=== Random === : %d %d\n", fah.fill, fah.heuristic);
+		//printf("=== Random === : %d %d\n", fah.fill, fah.heuristic);
 	} else {
 		//Utilisation des meilleurs fill et heuristic
 		fah.fill = this->getBestFill();

二进制
Bandit/GSATSolver


+ 29 - 46
Bandit/GSATThread.cpp

@@ -114,29 +114,7 @@ void GSATThread::initThread(int id, bool verbose) {
 	//Les threads vont jouer les bandits pour etablir les moyennes
 	bool solve = false;
 	while(!end && !solve && !cb.queueIsEmpty()){
-		//Recup le prochaine fill et heuristic à tester
-		fillAndHeuristic fah = cb.next();
-		//Calcul
-		solve = gsat[id]->start(fah.fill, fah.heuristic);
-		//Affiche
-		if(verbose) {
-			if(solve) {
-				printf(CYAN);
-			}
-			printf("c [thread:%2d][iteration:%5d][fill:%d][heuristic:%d]Satisfied clauses (begin: %d)(end:%d)\n",
-				id,
-		   		gsat[id]->getNbIterations(),
-		   		gsat[id]->getHeuristicFill(),
-		   		gsat[id]->getHeuristicSolve(),
-		   		gsat[id]->getNbSatisfiedClausesFill(),
-		   		gsat[id]->getNbSatisfiedClausesSolve());
-			if(solve) {
-				printf(RESET);
-			}
-		}
-		//Ajoute le resultat aux moyenne
-		cb.addFill(fah.fill, gsat[id]->getNbSatisfiedClausesFill());
-		cb.addHeuristic(fah.heuristic, gsat[id]->getNbSatisfiedClausesSolve());
+		solve = this->calc(id, verbose);
 	}
 	//Si 1er arreter
 	if(!end && solve) {
@@ -155,29 +133,7 @@ void GSATThread::runThread(int id, bool verbose) {
 	//Les threads vont jouer les bandits avec la méthode choisit
 	bool solve = false;
 	while(!end && !solve){
-		//Recup le prochaine fill et heuristic à tester
-		fillAndHeuristic fah = cb.next();
-		//Calcul
-		solve = gsat[id]->start(fah.fill, fah.heuristic);
-		//Affiche
-		if(verbose) {
-			if(solve) {
-				printf(CYAN);
-			}
-			printf("c [thread:%2d][iteration:%5d][fill:%d][heuristic:%d]Satisfied clauses (begin: %d)(end:%d)\n",
-				id,
-		   		gsat[id]->getNbIterations(),
-		   		gsat[id]->getHeuristicFill(),
-		   		gsat[id]->getHeuristicSolve(),
-		   		gsat[id]->getNbSatisfiedClausesFill(),
-		   		gsat[id]->getNbSatisfiedClausesSolve());
-			if(solve) {
-				printf(RESET);
-			}
-		}
-		//Ajoute le resultat aux moyenne
-		cb.addFill(fah.fill, gsat[id]->getNbSatisfiedClausesFill());
-		cb.addHeuristic(fah.heuristic, gsat[id]->getNbSatisfiedClausesSolve());
+		solve = this->calc(id, verbose);
 	}
 	//Si 1er arreter
 	if(!end && solve) {
@@ -190,4 +146,31 @@ void GSATThread::runThread(int id, bool verbose) {
 		result.nbSatisfiedClausesFill = gsat[id]->getNbSatisfiedClausesFill();
 		result.nbSatisfiedClausesSolve = gsat[id]->getNbSatisfiedClausesSolve();
 	}
+}
+
+bool GSATThread::calc(int id, bool verbose) {
+	//Recup le prochaine fill et heuristic à tester
+	fillAndHeuristic fah = cb.next();
+	//Calcul
+	bool solve = gsat[id]->start(fah.fill, fah.heuristic);
+	//Affiche
+	if(verbose) {
+		if(solve) {
+			printf(CYAN);
+		}
+		printf("c [thread:%2d][iteration:%5d][fill:%d][heuristic:%d]Satisfied clauses (begin: %d)(end:%d)\n",
+			id,
+		   	gsat[id]->getNbIterations(),
+		   	gsat[id]->getHeuristicFill(),
+		   	gsat[id]->getHeuristicSolve(),
+		   	gsat[id]->getNbSatisfiedClausesFill(),
+		   	gsat[id]->getNbSatisfiedClausesSolve());
+		if(solve) {
+			printf(RESET);
+		}
+	}
+	//Ajoute le resultat aux moyenne
+	cb.addFill(fah.fill, gsat[id]->getNbSatisfiedClausesFill());
+	cb.addHeuristic(fah.heuristic, gsat[id]->getNbSatisfiedClausesSolve());
+	return solve;
 }

+ 2 - 1
Bandit/GSATThread.hpp

@@ -31,7 +31,7 @@ class GSATThread {
 		bool solve();
 		bool solve(bool);
 		void printResult();
-		
+
 		/* --- Getter --- */
 		inline unsigned int getNbVariables() {return gsat[0]->getNbVariables();}
 		inline unsigned int getNbClauses() {return gsat[0]->getNbClauses();}
@@ -51,6 +51,7 @@ class GSATThread {
 
 		void initThread(int, bool);
 		void runThread(int, bool);
+		bool calc(int, bool);
 };
 
 #endif