macop.algorithms.multi¶
Multi-objetive classes algorithm
Classes
|
Multi-Ojective Evolutionary Algorithm with Scalar Decomposition |
|
Specific MO sub problem used into MOEAD |
-
class
macop.algorithms.multi.
MOEAD
(mu, T, initializer, evaluator, operators, policy, validator, maximise=True, parent=None, verbose=True)[source]¶ Multi-Ojective Evolutionary Algorithm with Scalar Decomposition
-
mu
¶ {int} – number of sub problems
-
T
¶ {[float]} – number of neightbors for each sub problem
-
nObjectives
¶ {int} – number of objectives (based of number evaluator)
-
initializer
¶ {function} – basic function strategy to initialize solution
-
evaluator
¶ {[function]} – list of basic function in order to obtained fitness (multiple objectives)
-
operators
¶ {[Operator]} – list of operator to use when launching algorithm
-
policy
¶ {Policy} – Policy class implementation strategy to select operators
-
validator
¶ {function} – basic function to check if solution is valid or not under some constraints
-
maximise
¶ {bool} – specify kind of optimisation problem
-
verbose
¶ {bool} – verbose or not information about the algorithm
-
population
¶ [{Solution}] – population of solution, one for each sub problem
-
pfPop
¶ [{Solution}] – pareto front population
-
weights
¶ [[{float}]] – random weights used for custom mu sub problems
-
callbacks
¶ {[Callback]} – list of Callback class implementation to do some instructions every number of evaluations and load when initializing algorithm
>>> import random >>> # operators import >>> from macop.operators.discrete.crossovers import SimpleCrossover >>> from macop.operators.discrete.mutators import SimpleMutation >>> # policy import >>> from macop.policies.classicals import RandomPolicy >>> # solution and algorithm >>> from macop.solutions.discrete import BinarySolution >>> from macop.algorithms.multi import MOEAD >>> # evaluator import >>> from macop.evaluators.discrete.mono import KnapsackEvaluator >>> # evaluator initialization (worths objects passed into data) >>> problem_size = 20 >>> worths1 = [ random.randint(0, 20) for i in range(problem_size) ] >>> evaluator1 = KnapsackEvaluator(data={'worths': worths1}) >>> worths2 = [ random.randint(10, 15) for i in range(problem_size) ] >>> evaluator2 = KnapsackEvaluator(data={'worths': worths2}) >>> # validator specification (based on weights of each objects) >>> weights = [ random.randint(5, 30) for i in range(problem_size) ] >>> validator = lambda solution: True if sum([weights[i] for i, value in enumerate(solution._data) if value == 1]) < 200 else False >>> # initializer function with lambda function >>> initializer = lambda x=20: BinarySolution.random(x, validator) >>> # operators list with crossover and mutation >>> operators = [SimpleCrossover(), SimpleMutation()] >>> policy = RandomPolicy(operators) >>> # MOEAD use multi-objective, hence list of evaluators with mu=100 and T=10 >>> algo = MOEAD(20, 5, initializer, [evaluator1, evaluator2], operators, policy, validator, maximise=True, verbose=False) >>> # run the algorithm and get the pareto front obtained >>> pf_solutions = algo.run(100) >>> # check size of expected pareto >>> len(pf_solutions) 33
-
-
class
macop.algorithms.multi.
MOSubProblem
(index, weights, initalizer, evaluator, operators, policy, validator, maximise=True, parent=None, verbose=True)[source]¶ Specific MO sub problem used into MOEAD
-
index
¶ {int} – sub problem index
-
weights
¶ {[float]} – sub problems objectives weights
-
initalizer
¶ {function} – basic function strategy to initialize solution
-
evaluator
¶ {function} – basic function in order to obtained fitness (mono or multiple objectives)
-
operators
¶ {[Operator]} – list of operator to use when launching algorithm
-
policy
¶ {Policy} – Policy class implementation strategy to select operators
-
validator
¶ {function} – basic function to check if solution is valid or not under some constraints
-
maximise
¶ {bool} – specify kind of optimisation problem
-
verbose
¶ {bool} – verbose or not information about the algorithm
-
currentSolution
¶ {Solution} – current solution managed for current evaluation
-
bestSolution
¶ {Solution} – best solution found so far during running algorithm
-
callbacks
¶ {[Callback]} – list of Callback class implementation to do some instructions every number of evaluations and load when initializing algorithm
Example:
>>> import random >>> # operators import >>> from macop.operators.discrete.crossovers import SimpleCrossover >>> from macop.operators.discrete.mutators import SimpleMutation >>> # policy import >>> from macop.policies.classicals import RandomPolicy >>> # solution and algorithm >>> from macop.solutions.discrete import BinarySolution >>> from macop.algorithms.multi import MOEAD, MOSubProblem >>> # evaluator import >>> from macop.evaluators.discrete.mono import KnapsackEvaluator >>> # evaluator initialization (worths objects passed into data) >>> problem_size = 20 >>> worths1 = [ random.randint(0, 20) for i in range(problem_size) ] >>> evaluator1 = KnapsackEvaluator(data={'worths': worths1}) >>> worths2 = [ random.randint(10, 15) for i in range(problem_size) ] >>> evaluator2 = KnapsackEvaluator(data={'worths': worths2}) >>> # validator specification (based on weights of each objects) >>> weights = [ random.randint(5, 30) for i in range(problem_size) ] >>> validator = lambda solution: True if sum([weights[i] for i, value in enumerate(solution._data) if value == 1]) < 200 else False >>> # initializer function with lambda function >>> initializer = lambda x=20: BinarySolution.random(x, validator) >>> # operators list with crossover and mutation >>> operators = [SimpleCrossover(), SimpleMutation()] >>> policy = RandomPolicy(operators) >>> algo = MOEAD(20, 5, initializer, [evaluator1, evaluator2], operators, policy, validator, maximise=True, verbose=False) >>> # weights of the sub problem >>> sub_problem_weights = [0.4, 0.6] >>> sub_evaluator = WeightedSum(data={'evaluators': [evaluator1, evaluator2], 'weights': sub_problem_weights}) >>> # first parameter is the index of the MOSubProblem >>> subProblem = MOSubProblem(0, sub_problem_weights, initializer, sub_evaluator, operators, policy, validator, maximise=True, parent=algo, verbose=False) >>> # run the algorithm >>> solution = subProblem.run(100) >>> solution._score 133.0
-