Metaheuristic
This module contains the Metaheuristic class.
Created on Thu Sep 26 16:56:01 2019
@author: Jorge Mario Cruz-Duarte (jcrvz.github.io), e-mail: j.m.cruzduarte@ieee.org
A Metaheuristic object combines a problem, a population, and a sequence of
search operators into an iterative optimisation procedure.
Note
Population and Operators are re-exported by this module for convenience
but are fully documented in their own pages:
Population and Search Operators.
Lifecycle:
Initialise the population (
apply_initialiser).At each iteration, apply every operator in sequence (
apply_search_operator).After the run, retrieve the best solution with
get_solution().
Quick usage:
from customhys import benchmark_func as bf
from customhys.metaheuristic import Metaheuristic
func = bf.Sphere(5)
prob = {
"function": func.get_func_val,
"is_constrained": True,
"boundaries": func.get_search_range(),
}
ops = [
("random_search", {"scale": 0.01, "distribution": "uniform"}, "greedy"),
]
mh = Metaheuristic(prob, ops, num_agents=30, num_iterations=100)
mh.run()
pos, fit = mh.get_solution()
- class customhys.metaheuristic.Metaheuristic(problem, search_operators=None, num_agents=30, num_iterations=100, initial_scheme='random', verbose=False)[source]
Bases:
objectThis is the Metaheuristic class, each object corresponds to a metaheuristic implemented with a sequence of search operators from op, and it is based on a population from Population.
- __init__(problem, search_operators=None, num_agents=30, num_iterations=100, initial_scheme='random', verbose=False)[source]
Create a population-based metaheuristic by employing different simple search operators.
- Parameters:
problem (dict) –
This is a dictionary containing the ‘function’ that maps a 1-by-D array of real values to a real value, ‘is_constrained’ flag that indicates the solution is inside the search space, and the ‘boundaries’ (a tuple with two lists of size D). These two lists correspond to the lower and upper limits of domain, such as:
boundaries = (lower_boundaries, upper_boundaries)Note: Dimensions (D) of search domain are read from these boundaries. The problem can be obtained from the
benchmark_funcmodule.search_operators (list) – A list of available search operators. These operators must correspond to those available in the
operatorsmodule. This parameter is mandatory for metaheuristic implementations, for using parts of this class, these can be provided as a list ofoperators.num_agents (int) – Optional. Number of agents or population size. The default is 30.
num_iterations (int) – Optional. Number of iterations or generations that the metaheuristic is going to perform. The default is 100.
initial_scheme (str)
verbose (bool)
- Returns:
None.