SevgiAkten / pycellga

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

Optimization Method Names as Enums rather than Strings #45

Closed jbytecode closed 3 months ago

jbytecode commented 3 months ago

It is always prone to errors to use string expressions for enumeration things.

The code has many optimization methods:

"cga", "sync_cga", "alpha_cga", "ccga", "mcccga"

I introduce a new type

class OptimizationMethod(Enum):
    CGA = 1
    SYNCGA = 2
    ALPHA_CGA = 3
    CCGA = 4
    MCCCGA = 5

so we can do

def __init__(self, 
                 method_name: OptimizationMethod = OptimizationMethod.CGA, 
                 ch_size: int = 0, 
                 n_rows: int = 0, 
                 n_cols: int = 0, 
                 gen_type: str = "", 
                 problem: AbstractProblem = None, 
                 vector: list = [],
                 mins : list[float] = [],
                 maxs : list[float] = []):

and users can never pass illegal type of method name.

jbytecode commented 3 months ago

This commit applies these change

https://github.com/SevgiAkten/pycellga/commit/07c9db7c3717ad1431cdda8425e0927c7745688e

and the tests are passed as well.

jbytecode commented 3 months ago

please feel free to close this issue if you are agreed with the change.

SevgiAkten commented 3 months ago

Thank you! I’ve reviewed the changes and agree with them. I'll close the issue now.