discrete_optimization.generic_tools.ea package
Submodules
discrete_optimization.generic_tools.ea.alternating_ga module
- class discrete_optimization.generic_tools.ea.alternating_ga.AlternatingGa(problem: Problem, objectives: str | list[str], encodings: list[str] | list[dict[str, Any]] | None = None, mutations: list[Mutation] | list[DeapMutation] | None = None, crossovers: list[DeapCrossover] | None = None, selections: list[DeapSelection] | None = None, objective_handling: ObjectiveHandling | None = None, objective_weights: list[float] | None = None, pop_size: int | None = None, max_evals: int = 10000, sub_evals: list[int] | None = None, mut_rate: float | None = None, crossover_rate: float | None = None, tournament_size: float | None = None, deap_verbose: bool = False, params_objective_function: ParamsObjectiveFunction | None = None, **kwargs)[source]
Bases:
SolverDO
,WarmstartMixin
Multi-encoding single objective GA
- Parameters:
problem – the problem to solve
encoding –
name (str) of an encoding registered in the register solution of Problem or a dictionary of the form {‘type’: TypeAttribute, ‘n’: int} where type refers to a TypeAttribute and n
to the dimension of the problem in this encoding (e.g. length of the vector)
by default, the first encoding in the problem register_solution will be used.
- set_warm_start(solution: Solution) None [source]
Make the solver warm start from the given solution.
Will be ignored if arg initial_variable is set and not None in call to solve().
- solve(**kwargs: Any) ResultStorage [source]
Generic solving function.
- Parameters:
callbacks – list of callbacks used to hook into the various stage of the solve
**kwargs – any argument specific to the solver
Solvers deriving from SolverDo should use callbacks methods .on_step_end(), … during solve(). But some solvers are not yet updated and are just ignoring it.
Returns (ResultStorage): a result object containing potentially a pool of solutions to a discrete-optimization problem
discrete_optimization.generic_tools.ea.deap_wrappers module
discrete_optimization.generic_tools.ea.ga module
- class discrete_optimization.generic_tools.ea.ga.DeapCrossover(value)[source]
Bases:
Enum
An enumeration.
- CX_ONE_POINT = 3
- CX_ORDERED = 2
- CX_PARTIALY_MATCHED = 5
- CX_TWO_POINT = 4
- CX_UNIFORM = 0
- CX_UNIFORM_PARTIALY_MATCHED = 1
- class discrete_optimization.generic_tools.ea.ga.DeapMutation(value)[source]
Bases:
Enum
An enumeration.
- MUT_FLIP_BIT = 0
- MUT_SHUFFLE_INDEXES = 1
- MUT_UNIFORM_INT = 2
- class discrete_optimization.generic_tools.ea.ga.DeapSelection(value)[source]
Bases:
Enum
An enumeration.
- SEL_BEST = 2
- SEL_RANDOM = 1
- SEL_ROULETTE = 4
- SEL_STOCHASTIC_UNIVERSAL_SAMPLING = 6
- SEL_TOURNAMENT = 0
- SEL_WORST = 5
- class discrete_optimization.generic_tools.ea.ga.Ga(problem: Problem, objectives: str | list[str], mutation: Mutation | DeapMutation | None = None, crossover: DeapCrossover | None = None, selection: DeapSelection = DeapSelection.SEL_TOURNAMENT, encoding: str | dict[str, Any] | None = None, objective_handling: ObjectiveHandling = ObjectiveHandling.SINGLE, objective_weights: list[float] | None = None, pop_size: int = 100, max_evals: int | None = None, mut_rate: float = 0.1, crossover_rate: float = 0.9, tournament_size: float = 0.2, deap_verbose: bool = True, initial_population: list[list[Any]] | None = None, params_objective_function: ParamsObjectiveFunction | None = None, **kwargs)[source]
Bases:
SolverDO
,WarmstartMixin
Single objective GA
- Parameters:
problem – the problem to solve
encoding –
name (str) of an encoding registered in the register solution of Problem or a dictionary of the form {‘type’: TypeAttribute, ‘n’: int} where type refers to a TypeAttribute and n
to the dimension of the problem in this encoding (e.g. length of the vector)
by default, the first encoding in the problem register_solution will be used.
- hyperparameters: list[Hyperparameter] = [EnumHyperparameter(name='crossover', default=None, depends_on=None, name_in_kwargs='crossover'), EnumHyperparameter(name='selection', default=<DeapSelection.SEL_TOURNAMENT: 0>, depends_on=None, name_in_kwargs='selection'), IntegerHyperparameter(name='pop_size', default=100, depends_on=None, name_in_kwargs='pop_size', low=1, high=1000, step=1, log=False), FloatHyperparameter(name='mut_rate', default=0.1, depends_on=None, name_in_kwargs='mut_rate', low=0, high=0.9, suggest_low=False, suggest_high=False, step=None, log=False), FloatHyperparameter(name='crossover_rate', default=0.9, depends_on=None, name_in_kwargs='crossover_rate', low=0, high=1, suggest_low=False, suggest_high=False, step=None, log=False), FloatHyperparameter(name='tournament_size', default=0.2, depends_on=None, name_in_kwargs='tournament_size', low=0, high=1, suggest_low=False, suggest_high=False, step=None, log=False)]
Hyperparameters available for this solver.
- These hyperparameters are to be feed to **kwargs found in
__init__()
init_model() (when available)
solve()
- set_warm_start(solution: Solution) None [source]
Make the solver warm start from the given solution.
Will be ignored if arg initial_variable is set and not None in call to solve().
- solve(**kwargs: Any) ResultStorage [source]
Generic solving function.
- Parameters:
callbacks – list of callbacks used to hook into the various stage of the solve
**kwargs – any argument specific to the solver
Solvers deriving from SolverDo should use callbacks methods .on_step_end(), … during solve(). But some solvers are not yet updated and are just ignoring it.
Returns (ResultStorage): a result object containing potentially a pool of solutions to a discrete-optimization problem
discrete_optimization.generic_tools.ea.ga_tools module
- class discrete_optimization.generic_tools.ea.ga_tools.ParametersAltGa(mutations: list[Mutation | DeapMutation], crossovers: list[DeapCrossover], selections: list[DeapSelection], encodings: list[str], objective_handling: ObjectiveHandling, objectives: str | list[str], objective_weights: list[float], pop_size: int, max_evals: int, mut_rate: float, crossover_rate: float, tournament_size: float, deap_verbose: bool, sub_evals: list[int])[source]
Bases:
object
- static default_mrcpsp() ParametersAltGa [source]
- static default_msrcpsp() ParametersAltGa [source]
- class discrete_optimization.generic_tools.ea.ga_tools.ParametersGa(mutation: Mutation | DeapMutation, crossover: DeapCrossover, selection: DeapSelection, encoding: str, objective_handling: ObjectiveHandling, objectives: str | list[str], objective_weights: list[float], pop_size: int, max_evals: int, mut_rate: float, crossover_rate: float, tournament_size: float, deap_verbose: bool)[source]
Bases:
object
- static default_rcpsp() ParametersGa [source]
discrete_optimization.generic_tools.ea.nsga module
- class discrete_optimization.generic_tools.ea.nsga.Nsga(problem: Problem, objectives: str | list[str], mutation: Mutation | DeapMutation | None = None, crossover: DeapCrossover | None = None, encoding: str | dict[str, Any] | None = None, objective_weights: list[float] | None = None, pop_size: int = 100, max_evals: int | None = None, mut_rate: float = 0.1, crossover_rate: float = 0.9, deap_verbose: bool = True)[source]
Bases:
SolverDO
,WarmstartMixin
NSGA
- Parameters:
problem – the problem to solve
encoding –
name (str) of an encoding registered in the register solution of Problem or a dictionary of the form {‘type’: TypeAttribute, ‘n’: int} where type refers to a TypeAttribute and n
to the dimension of the problem in this encoding (e.g. length of the vector)
by default, the first encoding in the problem register_solution will be used.
- set_warm_start(solution: Solution) None [source]
Make the solver warm start from the given solution.
Will be ignored if arg initial_variable is set and not None in call to solve().
- solve(**kwargs: Any) ResultStorage [source]
Generic solving function.
- Parameters:
callbacks – list of callbacks used to hook into the various stage of the solve
**kwargs – any argument specific to the solver
Solvers deriving from SolverDo should use callbacks methods .on_step_end(), … during solve(). But some solvers are not yet updated and are just ignoring it.
Returns (ResultStorage): a result object containing potentially a pool of solutions to a discrete-optimization problem