-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* refactoring: towards dependency injection and IOC * completed extraction of simulation's business logic to Simulation object * create Benchmark object * working fitness plotting service * use newborns as timeline; add individuals distance plotter * legend for messy plot * Abstract stat service * Add benchmark option for parallel execution * working aggregate data gathered at the end of parallel simulations execution
- Loading branch information
1 parent
f0846cf
commit 394a16a
Showing
13 changed files
with
457 additions
and
87 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
venv/ | ||
__pycache__/ | ||
.DS_Store | ||
*.svg | ||
*.svg | ||
*.mat |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import logging | ||
from typing import List | ||
from services.plotters import * | ||
from services.persistence import * | ||
from services.statistics import * | ||
|
||
class Simulation: | ||
def __init__(self, population: Population): | ||
self.population = population | ||
self.plotterServices: List[IPlotterService] = list() | ||
self.persistenceServices: List[IPersistenceService] = list() | ||
self.statServices: List[IStatService] = list() | ||
|
||
def withService(self, service: Service) -> Any: | ||
if isinstance(service, IPlotterService): | ||
target = self.plotterServices | ||
elif isinstance(service, IPersistenceService): | ||
target = self.persistenceServices | ||
elif isinstance(service, IStatService): | ||
target = self.statServices | ||
|
||
target.append(service) | ||
|
||
return self | ||
|
||
def runServices(self) -> None: | ||
for plotter in self.plotterServices: | ||
plotter.plot(self.population) | ||
|
||
for saver in self.persistenceServices: | ||
saver.save(self.population) | ||
|
||
for stater in self.statServices: | ||
stater.stat(self.population) | ||
|
||
def run(self, *_) -> None: | ||
generation, epoch = next(self.population.generations()) | ||
|
||
logging.info(f"Epoch: {epoch}") | ||
logging.debug(generation) | ||
logging.info(f"Best gene (fitness={generation[0].fitness():.2f}):\n{generation[0]}") | ||
|
||
self.runServices() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
__all__ = ["persistence", "plotters"] |
Oops, something went wrong.