macop.algorithms.base

Basic Algorithm class

Classes

Algorithm(initalizer, evaluator, operators, …)

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

class macop.algorithms.base.Algorithm(initalizer, evaluator, operators, policy, validator, maximise=True, parent=None, verbose=True)[source]

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

This class enables to manage some common usages of operation research algorithms: - initialization function of solution - validator function to check if solution is valid or not (based on some criteria) - evaluation function to give fitness score to a solution - operators used in order to update solution during search process - policy process applied when choosing next operator to apply - callbacks function in order to do some relative stuff every number of evaluation or reload algorithm state - parent algorithm associated to this new algorithm instance (hierarchy management)

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 comparison

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

parent

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

addCallback(_callback)[source]

Add new callback to algorithm specifying usefull parameters

Parameters

_callback – {Callback} – specific Callback instance

end(verbose=True)[source]

Display end message into run method

evaluate(solution)[source]

Evaluate a solution using evaluator passed when intialize algorithm

Parameters

solution – {Solution} – solution to evaluate

Returns

{float} – 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

getGlobalMaxEvaluation()[source]

Get the global max number of evaluation (if inner algorithm)

Returns

{int} – current global max number of evaluation

getParent()[source]

Recursively find the main parent algorithm attached of the current algorithm

Returns

{Algorithm} – main algorithm set for this algorithm

increaseEvaluation()[source]

Increase number of evaluation once a solution is evaluated for each dependant algorithm (parents hierarchy)

initRun()[source]

Initialize the current solution and best solution using the initialiser function

isBetter(_solution)[source]

Check if solution is better than best found

Parameters

solution – {Solution} – solution to compare with best one

Returns

{bool} – True if better

progress()[source]

Log progress and apply callbacks if necessary

resume()[source]

Resume algorithm using Callback instances

run(evaluations)[source]

Run the specific algorithm following number of evaluations to find optima

stop()[source]

Global stopping criteria (check for parents algorithm hierarchy too)

update(solution)[source]

Apply update function to solution using specific policy Check if solution is valid after modification and returns it

Parameters

solution – {Solution} – solution to update using current policy

Returns

{Solution} – updated solution obtained by the selected operator