diff --git a/byron/classes/evaluator.py b/byron/classes/evaluator.py index 853d139..7a6472e 100644 --- a/byron/classes/evaluator.py +++ b/byron/classes/evaluator.py @@ -319,6 +319,7 @@ class MakefileEvaluator(EvaluatorABC): _make_flags: tuple[str] _makefile: str _required_files: tuple[str] + _stdout_cleaner: Callable[[str], Sequence[float] | float] | None _byron_base_dir: str _timeout: int | None @@ -330,6 +331,7 @@ def __init__( make_command='make', make_flags: Sequence[str] = ('-s',), makefile='Makefile', + stdout_cleaner: Callable[[str], Sequence[float] | float] | None = None, timeout: int | None = 60, **kwargs, ) -> None: @@ -359,6 +361,7 @@ def __init__( self._required_files = tuple(required_files) self._timeout = timeout self._byron_base_dir = os.getcwd() + self._stdout_cleaner = stdout_cleaner for f in self._required_files: if not os.path.exists(f): @@ -419,9 +422,12 @@ def evaluate_population(self, population: Population) -> None: if result is None: raise RuntimeError(f"Thread failed (returned None)") else: - value = [float(r) for r in result.stdout.split()] - if len(value) == 1: - value = value[0] + if self._stdout_cleaner is None: + value = [float(r) if '.' in r else int(r) for r in result.stdout.split()] + if len(value) == 1: + value = value[0] + else: + value = self._stdout_cleaner(result.stdout) fitness = make_fitness(value) population[i].fitness = fitness