浏览代码

Reinit method updated

Jérôme BUISINE 4 年之前
父节点
当前提交
677afbf2c3
共有 1 个文件被更改,包括 13 次插入13 次删除
  1. 13 13
      algorithms/Algorithm.py

+ 13 - 13
algorithms/Algorithm.py

@@ -14,25 +14,24 @@ class Algorithm():
         self.validator = _validator
         self.policy = _policy
 
-        self.currentSolution = self.initializer()
-        
-        # evaluate current solution
-        self.currentSolution.evaluate(self.evaluator)
-
-        # keep in memory best known solution (current solution)
-        self.bestSolution = self.currentSolution
-
         # other parameters
         self.maxEvalutations = 0 # by default
-        self.numberOfEvaluations = 0
         self.maximise = _maximise
 
+        self.initRun()
+
 
-    def reinit(self):
+    def initRun(self):
         """
-        Reinit the whole variable
+        Reinit the whole variables
         """
-        self.currentSolution = self.initializer
+
+        self.currentSolution = self.initializer()
+        
+        # evaluate current solution
+        self.currentSolution.evaluate(self.evaluator)
+
+        # keep in memory best known solution (current solution)
         self.bestSolution = self.currentSolution
 
         self.numberOfEvaluations = 0
@@ -92,9 +91,10 @@ class Algorithm():
         Run the specific algorithm following number of evaluations to find optima
         """
         self.maxEvalutations = _evaluations
+        self.initRun()
 
         logging.info("Run %s with %s evaluations" % (self.__str__(), _evaluations))
-
+        
 
     def progress(self):
         logging.info("-- Evaluation n°%s of %s, %s%%" % (self.numberOfEvaluations, self.maxEvalutations, "{0:.2f}".format((self.numberOfEvaluations) / self.maxEvalutations * 100.)))