diff --git a/nkcs/ea.py b/nkcs/ea.py index 71babcd..85e091e 100644 --- a/nkcs/ea.py +++ b/nkcs/ea.py @@ -52,12 +52,9 @@ def to_string(self) -> str: def mutate(self) -> None: """Mutate an individual.""" - for i in range(len(self.genome)): + for i, gene in enumerate(self.genome): if np.random.uniform(low=0, high=1) < Cons.P_MUT: - if self.genome[i] == 0: - self.genome[i] = 1 - else: - self.genome[i] = 0 + self.genome[i] = 1 if gene == 0 else 1 def uniform_crossover(self, parent: Ind) -> None: """Perform uniform crossover.""" @@ -192,9 +189,9 @@ def print_archive(self, s: int) -> None: def print_pop(self) -> None: """Print the current populations.""" for s in range(Cons.S): - logger.info(f"Species {s}") + logger.info("Species %d", s) for p in self.pop[s]: - logger.info(p.to_string()) + logger.info("%s", p.to_string()) def run_ea( self, nkcs: NKCS, evals: np.ndarray, pbest: np.ndarray, pavg: np.ndarray diff --git a/nkcs/main.py b/nkcs/main.py index e0ff97e..53c47a6 100644 --- a/nkcs/main.py +++ b/nkcs/main.py @@ -16,7 +16,7 @@ # along with this program. If not, see . # -"""Main script for starting NKCS (co)evolutionary experiments.""" +"""Main script for starting NKCS coevolutionary experiments.""" from __future__ import annotations @@ -34,8 +34,6 @@ from .plot import plot if __name__ == "__main__": - """Run experiment..""" - # results storage n_res: Final[int] = Cons.F * Cons.E evals: np.ndarray = np.zeros((n_res, Cons.G)) diff --git a/nkcs/nkcs.py b/nkcs/nkcs.py index 3a9e29f..c3be09f 100644 --- a/nkcs/nkcs.py +++ b/nkcs/nkcs.py @@ -167,6 +167,6 @@ def display(self) -> None: """Print an NKCS species.""" logger.info(f"con: {self.map}") logger.info("fitness table:") - for i in range(len(self.ftable)): + for i, fitness in enumerate(self.ftable): logger.info(f"Gene {i}") - logger.info(self.ftable[i]) + logger.info(fitness)