SevgiAkten / pycellga

Cellular Genetic Algorithms in Python.
https://sevgiakten.github.io/pycellga/
MIT License
2 stars 1 forks source link

combining all the functionalty in a single optimizer #6

Closed jbytecode closed 4 months ago

jbytecode commented 1 year ago

Now, it is time to implement an optimizer function. It will be necessary for the simulation suite.

The definition of the optimizer function should be in the form of

def optimize(
      type: str, 
      problem: AbstractProblem,
      crossover,
      mutation, 
      selection, 
      crossprob: float, 
      mutateprob: float, 
      maxiter: int,
      etc...
)

so we can optimize the OneMax by a simple call like

result = optimize("Binary", OneMax, OnePointCrossover, BitSwapMutation, TournamentSelection, 0.80, 0.10, 1000, etc...) 

and the function may return a Dict() something like

    x => [1,1,1,1,1,1,1,1,1],
   obj => 9,
   foundatiteration => 10,
   etc.
jbytecode commented 1 year ago

The file https://github.com/SevgiAkten/pycell/blob/main/cga/optimizer.py includes an optimizer but there are still some issues:

SevgiAkten commented 1 year ago

I printed optimizer results and parameters in another way. Nevertheless, I researched pretty_printer(d: dict) to learn it. Thank you sir for sharing this information with me.

jbytecode commented 1 year ago

When you have a dict object in Python which is created like

>>> v = {"x":  3, "y": 10, "z": [1, 2, 3]}

then you are able to access its elements using string keys like

>>> v["x"]
3
>>> v["y"]
10
>>> v["z"]
[1, 2, 3]

so it is better to use compact key values rather than sentences.

So a key value Best Solution Chromosome : is not a proper use.

jbytecode commented 1 year ago

of course, we should not use single character strings, a key value like pop_size is okay, the point here is that the key values are like variable names