Skip to content

Commit

Permalink
Upd, evaluator.py with stdout_cleaner on Makefile evaluator
Browse files Browse the repository at this point in the history
  • Loading branch information
dimi-it committed Oct 28, 2023
1 parent 99ce179 commit 272d35f
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions byron/classes/evaluator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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:
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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

Expand Down

0 comments on commit 272d35f

Please sign in to comment.