Parcourir la source

use of inheritance for solutions; check if sol already computed

Jérôme BUISINE il y a 4 ans
Parent
commit
dbd4ab57df

+ 3 - 2
macop/algorithms/Algorithm.py

@@ -212,8 +212,9 @@ class Algorithm():
         # two parameters are sent if specific crossover solution are wished
         sol = self._policy.apply(_solution)
 
-        # compute fitness of new solution
-        sol.evaluate(self._evaluator)
+        # compute fitness of new solution if not already computed
+        if sol._score is None:
+            sol.evaluate(self._evaluator)
 
         if (sol.isValid(self._validator)):
             return sol

+ 1 - 3
macop/solutions/BinarySolution.py

@@ -24,9 +24,7 @@ class BinarySolution(Solution):
             data: {ndarray} --  array of binary values
             size: {int} -- size of binary array values
         """
-
-        self._data = data
-        self._size = size
+        super().__init__(data, size)
 
     def random(self, validator):
         """

+ 1 - 3
macop/solutions/CombinatoryIntegerSolution.py

@@ -25,9 +25,7 @@ class CombinatoryIntegerSolution(Solution):
             data: {ndarray} --  array of binary values
             size: {int} -- size of binary array values
         """
-
-        self._data = data
-        self._size = size
+        super().__init__(data, size)
 
     def random(self, validator):
         """

+ 1 - 3
macop/solutions/IntegerSolution.py

@@ -25,9 +25,7 @@ class IntegerSolution(Solution):
             data: {ndarray} --  array of binary values
             size: {int} -- size of binary array values
         """
-
-        self._data = data
-        self._size = size
+        super().__init__(data, size)
 
     def random(self, validator):
         """