Skip to content

Commit

Permalink
circular dependencies, README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
Zoran Jankovic committed May 22, 2024
1 parent a48c562 commit c7d84e2
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 4 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,9 @@ def some_func(args):


custom_factory = GAFactory()
custom_factory.chromosome_mutation_selector = BottomMutationSelector(RandomChromosomeMutationRateDeterminator())
custom_factory.chromosome_mutation_selector = (
BottomMutationSelector(custom_factory.chromosome_mutation_rate_determinator,
custom_factory.get_gene_mutation_selector()))
ga = GA(cost_function=some_func, factory=custom_factory)
ga.add(-25, 25, 1)
ga.add(-5, 5, 0.1)
Expand Down
5 changes: 3 additions & 2 deletions gadapt/adapters/ga_logging/logging_settings.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import datetime
import logging
import os
from os.path import isfile, join

from gadapt.utils.TimeStampFormatter import TimestampFormatter

Expand All @@ -21,7 +20,9 @@ def init_logging(is_logging: bool):
os.mkdir(path)
now = datetime.datetime.now()

formatted_date_time = now.strftime('%Y_%m_%d_%H_%M_%S_') + f'{now.microsecond // 1000:03d}'
formatted_date_time = (
now.strftime("%Y_%m_%d_%H_%M_%S_") + f"{now.microsecond // 1000:03d}"
)
logpath = os.path.join(path, f"gadapt_log_{formatted_date_time}.log")
handler = logging.FileHandler(logpath)
handler.setFormatter(
Expand Down
12 changes: 11 additions & 1 deletion gadapt/ga.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from gadapt.ga_model.decision_variable import DecisionVariable
from gadapt.ga_model.ga_options import GAOptions
from gadapt.ga_model.ga_results import GAResults
import copy


class GA:
Expand Down Expand Up @@ -230,7 +231,7 @@ def execute(self) -> GAResults:
return results
ga_options = GAOptions(self)
factory: BaseGAFactory = self.get_factory()
factory.initialize_factory(self)
factory.initialize_factory(self.clone())
return GAExecutor(ga_options, factory).execute()

def get_factory(self) -> BaseGAFactory:
Expand Down Expand Up @@ -740,3 +741,12 @@ def timeout(self) -> int | str:
@timeout.setter
def timeout(self, value: int | str) -> None:
self._timeout = ga_utils.try_get_int(value)

def clone(self):
# Create a new instance of the class
new_instance = self.__class__.__new__(self.__class__)

# Copy the attributes from the current instance to the new instance
new_instance.__dict__ = copy.deepcopy(self.__dict__)

return new_instance

0 comments on commit c7d84e2

Please sign in to comment.