Edit on GitHub

geneticalgorithm2.data_types.result

 1import warnings
 2from dataclasses import dataclass
 3
 4from ..utils.aliases import array1D
 5
 6from .generation import Generation
 7from .base import DictLikeGetSet
 8
 9
10@dataclass
11class GAResult(DictLikeGetSet):
12
13    last_generation: Generation
14
15    @property
16    def variable(self) -> array1D:
17        return self.last_generation.variables[0]
18
19    @property
20    def score(self) -> float:
21        return self.last_generation.scores[0]
22
23    @property
24    def function(self):
25        warnings.warn(
26            f"'function' field is deprecated, will be removed in version 7, "
27            f"use 'score' to get best population score"
28        )
29        return self.score
12class GAResult(DictLikeGetSet):
13
14    last_generation: Generation
15
16    @property
17    def variable(self) -> array1D:
18        return self.last_generation.variables[0]
19
20    @property
21    def score(self) -> float:
22        return self.last_generation.scores[0]
23
24    @property
25    def function(self):
26        warnings.warn(
27            f"'function' field is deprecated, will be removed in version 7, "
28            f"use 'score' to get best population score"
29        )
30        return self.score
variable: numpy.ndarray
16    @property
17    def variable(self) -> array1D:
18        return self.last_generation.variables[0]
score: float
20    @property
21    def score(self) -> float:
22        return self.last_generation.scores[0]
function
24    @property
25    def function(self):
26        warnings.warn(
27            f"'function' field is deprecated, will be removed in version 7, "
28            f"use 'score' to get best population score"
29        )
30        return self.score