Skip to content

Commit

Permalink
- #11: add methods to convert between method enums and names
Browse files Browse the repository at this point in the history
  • Loading branch information
fbergmann committed Jan 25, 2022
1 parent 0c89de3 commit 3c20ea7
Showing 1 changed file with 78 additions and 1 deletion.
79 changes: 78 additions & 1 deletion basico/task_parameterestimation.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,18 @@


class PE:
"""Constants for Parameter estimation method names"""
"""Constants for Parameter estimation method names
Convert between method names to enums
>>> T.from_enum(0)
'Current Solution Statistics'
>>> T.to_enum('Current Solution Statistics')
17
"""
CURRENT_SOLUTION = "Current Solution Statistics"
RANDOM_SEARCH = "Random Search"
SIMULATED_ANNEALING = "Simulated Annealing"
Expand All @@ -53,6 +64,72 @@ class PE:
PRAXIS = "Praxis"
TRUNCATED_NEWTON = "Truncated Newton"

_names = None
_values = None

@classmethod
def _create_name_map(cls):
return {
COPASI.CTaskEnum.Method_Statistics: PE.CURRENT_SOLUTION,
COPASI.CTaskEnum.Method_RandomSearch: PE.RANDOM_SEARCH,
COPASI.CTaskEnum.Method_SimulatedAnnealing: PE.SIMULATED_ANNEALING,
COPASI.CTaskEnum.Method_DifferentialEvolution: PE.DIFFERENTIAL_EVOLUTION,
COPASI.CTaskEnum.Method_ScatterSearch: PE.SCATTER_SEARCH,
COPASI.CTaskEnum.Method_GeneticAlgorithm: PE.GENETIC_ALGORITHM,
COPASI.CTaskEnum.Method_GeneticAlgorithmSR: PE.GENETIC_ALGORITHM_SR,
COPASI.CTaskEnum.Method_SRES: PE.EVOLUTIONARY_STRATEGY_SRES,
COPASI.CTaskEnum.Method_ParticleSwarm: PE.PARTICLE_SWARM,
COPASI.CTaskEnum.Method_LevenbergMarquardt: PE.LEVENBERG_MARQUARDT,
COPASI.CTaskEnum.Method_HookeJeeves: PE.HOOKE_JEEVES,
COPASI.CTaskEnum.Method_NelderMead: PE.NELDER_MEAD,
COPASI.CTaskEnum.Method_SteepestDescent: PE.STEEPEST_DESCENT,
COPASI.CTaskEnum.Method_NL2SOL: PE.NL2SOL,
COPASI.CTaskEnum.Method_Praxis: PE.PRAXIS,
COPASI.CTaskEnum.Method_TruncatedNewton: PE.TRUNCATED_NEWTON,
}

@classmethod
def _create_value_map(cls):
return {
PE.CURRENT_SOLUTION: COPASI.CTaskEnum.Method_Statistics,
PE.RANDOM_SEARCH: COPASI.CTaskEnum.Method_RandomSearch,
PE.SIMULATED_ANNEALING: COPASI.CTaskEnum.Method_SimulatedAnnealing,
PE.DIFFERENTIAL_EVOLUTION: COPASI.CTaskEnum.Method_DifferentialEvolution,
PE.SCATTER_SEARCH: COPASI.CTaskEnum.Method_ScatterSearch,
PE.GENETIC_ALGORITHM: COPASI.CTaskEnum.Method_GeneticAlgorithm,
PE.GENETIC_ALGORITHM_SR: COPASI.CTaskEnum.Method_GeneticAlgorithmSR,
PE.EVOLUTIONARY_STRATEGY_SRES: COPASI.CTaskEnum.Method_SRES,
PE.PARTICLE_SWARM: COPASI.CTaskEnum.Method_ParticleSwarm,
PE.LEVENBERG_MARQUARDT: COPASI.CTaskEnum.Method_LevenbergMarquardt,
PE.HOOKE_JEEVES: COPASI.CTaskEnum.Method_HookeJeeves,
PE.NELDER_MEAD: COPASI.CTaskEnum.Method_NelderMead,
PE.STEEPEST_DESCENT: COPASI.CTaskEnum.Method_SteepestDescent,
PE.NL2SOL: COPASI.CTaskEnum.Method_NL2SOL,
PE.PRAXIS: COPASI.CTaskEnum.Method_Praxis,
PE.TRUNCATED_NEWTON: COPASI.CTaskEnum.Method_TruncatedNewton,
}

@classmethod
def from_enum(cls, int_value):
if cls._names is None:
cls._names = cls._create_name_map()

return cls._names.get(int_value, PE.CURRENT_SOLUTION)

@classmethod
def to_enum(cls, value):
if cls._values is None:
cls._values = cls._create_value_map()

return cls._values.get(value, COPASI.CTaskEnum.Method_Statistics)

@classmethod
def all_method_names(cls):
if cls._names is None:
cls._names = cls._create_name_map()

return list(cls._names.values())


try:
from . import model_io
Expand Down

0 comments on commit 3c20ea7

Please sign in to comment.