Package: metaheuristic-designer
Metaheuristic-designerThis is an object-oriented framework for the development, testing and analysis of metaheuristic optimization algorithms.It defines the components of a general evolutionary algorithm and offers some implementations of algorithms along with components
that can be used directly. Those components will be explained below.It was inspired by the articleMetaheuristics “in the large”that
discusses some of the issues in the research on metaheuristic optimization, sugesting the development of libraries for the standarization
of metaheuristic algorithms.Most of the design decisions are based on the bookIntroduction to evolutionary computing by Eiben, Agoston E.,
and James E. Smithwhich is very well expained and is highly recomended to anyone willing to learn about the topic.This framework doesn't claim to have a high performance, specially since the chosen language is Python and the code has not been
designed for speed. This shouldn't really be an issue since the highest amount of time spent in these kind of algorithms
tends to be in the evaluation of the objective function. If you want to compare an algorithm made with this tool with another
one that is available by other means, it is recomended to use the number of evaluations of the objective function as a metric instead of execution time.InstalationThe package is available in the PyPi repository (https://pypi.org/project/metaheuristic-designer/).To install it, use the pip command as follows:pipinstallmetaheuristic-designerExamplesThere are 2 scripts to test this repository:"examples/exec_basic.py": Optimize a simple function, in this case, the "sphere" function that calculates the squared norm of a vector, we want a vector that minmizes this function. There are two possible flags that can be added:"-a [Alg]" use one of the available algorithms, the choices are:HillClimb: simple hill climbing algorithm.LocalSearch: take the best of 20 randomly chosen neighbours.ES: (100+150)-ES, basic evolutionary strategy.HS: Harmony search algorithm.GA: genetic algorithm.SA: simulated annealing algorithm.DE: DE/best/1, differential evolution algorithm.PSO: simple particle swarm algorithm.NoSearch: no search is done."-m" use a memetic search like structure, do local search after mutation."examples/exec_basic.py": Evolve an image so that it matches the one given as an input.The same parameters as the previous script."-i [Image path]" read the image and evolve a random image into this one.It is recomended that you create a virtual environment to test the examples.This is done with the following commands:python-mvenvvenvsourcevenv/bin/activate
pipinstall.[examples]Once you have activate the virtual environment, you can execute one of the examples like this:python examples/example_basic.pyorpython examples/image_evolution.pyTo run the tests you need to install nox, to execute the tests use the commandnoxtestImplemented componentsThis package comes with some already made components that can be used in any algorithm in this frameworkSearch strategiesThe algorithms implemented are:Class nameStrategyParamsOther infoNoSearchDo nothingFor debugging purposesRandomSearchRandom SearchHillClimbHill climbLocalSearchLocal seachiters(number of neighbors to test each time)SASimulated annealingiter(iterations per temperature change),temp_init(initial temperature),alpha(exponent of the temperature change)GAGenetic algorithmpmut(probability of mutation),pcross(probability of crossover)ESEvolution strategyoffspringSize(number of indiviuals to generate each generation)HSHarmony searchHSM,HMCR,BW,PARPSOParticle Swarm optimizationw,c1,c2DEDifferential evolutionCROCoral Reef Optimizationrho,Fb,Fd,Pd,attemptsCRO_SLCoral Reef Optimization with substrate layersrho,Fb,Fd,Pd,attemptsPCRO_SLprobabilistic Coral Reef Optimization with substrate layersrho,Fb,Fd,Pd,attemptsDPCRO_SLDynamic probabilistic Coral Reef Optimization with substrate layersrho,Fb,Fd,Pd,attempts,group_subs,dyn_method,dyn_steps,prob_ampVNDVariable neighborhood descentRVNSRestricted variable neighborhood searchIn progressVNSVariable neighborhood searchIn progressCMA_ESCovariance matrix adaptation - Evolution strategyNot implemented yetSurvivor selection methodsThese are methods of selecting the individuals to use in future generations.The methods implemented are:Method nameAlgorithmParamsOther info"Elitism"Elitismamount"CondElitism"Conditional Elitismamount"nothing" or "generational"Replace all the parents with their childrenNeeds the offspring size to be equal to the population size"One-to-one" or "HillClimb"One to one (compare each parent with its child)Needs the offspring size to be equal to the population size"Prob-one-to-one" or "ProbHillClimb"Probabilitisc One to one (with a chance to always choose the child)pNeeds the offspring size to be equal to the population size"(m+n)" or "keepbest"(λ+μ), or choosing the λ best individuals taking parents and children"(m,n)" or "keepoffspring"(λ,μ), or taking the best λ childrenλ must be smaller than μ"CRO"A 2 step survivor selection method used in the CRO algorithm. Each individual attempts to enter the population K times and then a percentage of the worse individuals will be eliminated from the populationFd,Pd,attempts,maxPopSizeCan return a population with a variable number of individualsParent selection methodsThese are methods of selecting the individuals that will be mutated/perturbed in each generationThe methods implemented are:Method nameAlgorithmParamsOther info"Torunament"Choose parents by tournamentamount,p"Best"Select the n best individualsamount"Random"Take n individuals at randomamount"Roulette"Perform a selection with the roullette methodamount,method,F"SUS"Stochastic universal samplingamount,method,F"Nothing"Take all the individuals from the populationOperatorsClass nameDomainOther infoOperatorRealReal valued vectorsOperatorIntInteger valued vectorsOperatorBinaryBinary vectorsOperatorPermPermutationsOperatorListVariable length listsOperatorMetaOther operatorsOperatorLambdaAnyLets you specify a function as an operatorThe Operators functions available in the operator classes are:Method nameAlgorithmParamsDomains"1point"1 point crossoverReal, Int, Bin"2point"2 point crossoverReal, Int, Bin"Multipoint"multipoint crossoverReal, Int, Bin"WeightedAvg"Weighted average crossoverFReal, Int"BLXalpha"BLX-alpha crossoverCrReal"Multicross"multi-individual multipoint crossoverNindivReal, Int, Bin"XOR"Bytewise XOR with a random vectorNInt"XORCross"Bytewise XOR between 2 vectors component by componentInt"sbx"SBX crossoverCrReal"Perm"Permutate vector componentsNReal, Int, Bin, Perm"Gauss"Add Gaussian noiseFReal, Int"Laplace"Add noise following a Laplace distributionFReal, Int"Cauchy"Add noise following a Cauchy distributionFReal, Int"Poisson"Add noise following a Cauchy distributionFInt"Uniform"Add Uniform noiseLow,UpReal, Int"MutRand" or "MutNoise"Add random noise to a number of vector componentsmethod,N, optionaly:Low,Up,FReal, Int"MutSample"Take a sample from a probability distribution and put it on a number of vector componentsmethod,N, optionaly:Low,Up,FReal, Int"RandNoise"Add random noisemethod, optionaly:Low,Up,FReal, Int"RandSample"Sample from a probability distributionmethod, optionaly:Low,Up,FReal, Int"DE/Rand/1"Sample from a probability distributionF,CrReal, Int"DE/Best/1"Sample from a probability distributionF,CrReal, Int"DE/Rand/2"Sample from a probability distributionF,CrReal, Int"DE/Best/2"Sample from a probability distributionF,CrReal, Int"DE/Current-to-rand/1"Sample from a probability distributionF,CrReal, Int"DE/Current-to-best/1"Sample from a probability distributionF,CrReal, Int"DE/Current-to-pbest/1"Sample from a probability distributionF,Cr,pReal, Int"PSO"Sample from a probability distributionw,c1,c2Real, Int"Firefly"Sample from a probability distributiona,b,c,gReal, Int"Random"Sample from a probability distributionReal, Int, Bin, Perm"RandomMask"Randomly sample a number of vector componentsNReal, Int"Swap"Swap two componentsPerm"Insert"Insert a component and shift to the leftPerm"Scramble"Scramble permutation orderNPerm"Invert"Reverse order of componentsPerm"Roll"Roll components to the rightNPerm"PMX"Partially mapped crossoverPerm"OrderCross"Ordered crossoverPerm"branch"Choose one of the provided operators randomlyOperators"sequence"Apply all the provided operators in orderOperators"split"Apply each operator to a subset of vector components following the mask providedOperators"pick"Manually pick one of the operators provided (setting thechosen_idxattribute)Operators"Dummy"Assing the vector to a predefined valueAll"Custom"Provide a lambda function to apply as an operatorfunctionAll"Nothing"Do nothingAllInitializersInitializers create the initial population that will be evolved in the optimization process.Some of the implemente Initializers are:Class nameDescriptionOther infoDirectInitializerInitialize the population to a preset list of individualsSeedProbInitializerInitializes the population with another initializer and inserts user-specified individuals with a probabilitySeedDetermInitializerInitializes the population with another initializer and inserts a number of user-specified individuals into the populationGaussianVectorInitializerInitialize individuals with normally distributed vectorsUniformVectorInitializerInitialize individuals with uniformly random distributed vectorsPermInitializerInitialize individuals with random permuationsLambdaInitializerInitialize individuals with a user-defined functionEncodingsSpecifying the Encoding is optional but can be very helpful for some types of problems.An encoding will represent each solution differently in the optimization process and the evaluation of the fintess, since most algorithm work only with vectors, but we might need other types of datatypes for our optimization.Some of the implemented Encodings are:Class nameEncodingDecodingOther infoDefaultEncodingMakes no changes to the inputMakes no changes to the inputTypeCastEncodingChanges the datatype of the vector fromT1toT2Changes the datatype of the vectorfromT1toT2MatrixEncodingConverts a vector into a matrix of sizeNxMConverts a matrix to a vector with the.flatten()methodImageEncodingConverts a vector into a matrix of sizeNxMx1orNxMx3, each component is an unsigned 8bit numberConverts a matrix to a vector with the.flatten()methodLambdaEncodingApplies the user-definedencodefunctionApplies the user-defineddecodefunctionBenchmark functionsThe benchmark functions you can use to test the algorithms are:Class nameDomainOther infoMaxOnesIntegerDiophantineEqIntegerMaxOnesRealRealSphereRealHighCondEllipticRealBentCigarRealDiscusRealRosenbrockRealAckleyRealWeistrassRealGriewankRealRastriginRealModSchwefelRealKatsuuraRealHappyCatRealHGBatRealSumPowellRealN4XinSheYangRealThreeSATRealBinKnapsackBinaryMaxCliquePermutationTSPPermutationImgApproxIntegerImgStdIntegerImgEntropyInteger