macop.algorithms.Algorithm

Abstract Algorithm class used as basic algorithm implementation with some specific initialization

Classes

Algorithm(_initalizer, _evaluator, …[, …])

Algorithm class used as basic algorithm

class macop.algorithms.Algorithm.Algorithm(_initalizer, _evaluator, _operators, _policy, _validator, _maximise=True, _parent=None)[source]

Algorithm class used as basic algorithm

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 optimization problem

currentSolution

{Solution} – current solution managed for current evaluation

bestSolution

{Solution} – best solution found so far during running algorithm

checkpoint

{Checkpoint} – Checkpoint class implementation to keep track of algorithm and restart

parent

{Algorithm} – parent algorithm reference in case of inner Algorithm instance (optional)

addCheckpoint(_class, _every, _filepath)[source]

Add checkpoint to algorithm specifying usefull parameters

_class

{class} – Checkpoint class type

_every

{int} – checkpoint frequency based on evaluations

_filepath

{str} – file path where checkpoints will be saved

evaluate(solution)[source]
Returns

fitness score of solution which is not already evaluated or changed

Note

if multi-objective problem this method can be updated using array of evaluator

getGlobalEvaluation()[source]

Get the global number of evaluation (if inner algorithm)

Returns

{int} – current global number of evaluation

increaseEvaluation()[source]

Increase number of evaluation once a solution is evaluated

initRun()[source]

Method which initialiazes or re-initializes the whole algorithm context (operators, current solution, policy, best solution (by default current solution))

isBetter(solution)[source]

Check if solution is better than best found

Returns

{bool} – True if better

resume()[source]

Resume algorithm using checkpoint instance

Raises

ValueError – No checkpoint initialize (use addCheckpoint or setCheckpoint is you want to use this process)

run(_evaluations)[source]

Run the specific algorithm following number of evaluations to find optima

setCheckpoint(_checkpoint)[source]

Set checkpoint instance directly

_checkpoint

{Checkpoint} – checkpoint instance

stop()[source]

Global stopping criteria (check for inner algorithm too)

update(solution)[source]

Apply update function to solution using specific policy

Check if solution is valid after modification and returns it

Returns

{Solution} – updated solution obtained by the selected operator