Matlab 7 Ga

zhaozj2021-02-16  57

The Genetic Algorithm and Direct Search Toolbox is provided in Matlab 7.0, and now is now briefly introduced. Please keep the author information is complete when reproduced. 1. First write the Fitness function, and the contents of the function will be referred to. Function score = my_func1 (POP)% F (x1, x2) = 21.5 x1 * sin (4 * pi * x1) x2 * sin (20 * pi * x2)% -3.0 <= x1 <= 12.1; 4.1 < = x2 <= 5.8 score = -21.5 - POP (1) * sin (4 * pi * pop (1)) - POP (2) * sin (20 * pi * pop (2)); can know% from the GA function X = GA (FITNESSFCN, NVARS) finds the minimum of FITNESSFCN using% GA. NVARS is the dimension (number of design variables) of the% FITNESSFCN. FITNESSFCN accepts a vector X of size 1-by-NAVRS,% and returns a scalar evaluated at X.%% X = GA (FITNESSFCN, NAVRS, OPTIONS) finds the minimum for% FITNESSFCN with the default optimization parameters replaced by values% in the structure OPTIONS. OPTIONS can be created with the GAOPTIMSET% function.ga is looking for the smallest Value, so the original function is handed.

Turning out of this site. [PARSE] LiHuanc [/ PARSE] About optimization: f (x1, x2) = 21.5 x1 * sin (4 * pi * x1) x2 * sin (20 * pi * x2) -3.0 <= x1 <= 12.1 4.1 <= x2 <= 5.8 [PARSE] Zonly [/ parse] Under [/ parse] Oh, this problem is very small, I use nlpsolver1.0 (download to the website www.easyworm.com) to calculate: the initial value X1 = 11.600000, X2 = 4.500000 optimal target value For the most advantages of 37.650301 x1 * = 11.625545, x2 * = 4.525056 LINGO 8.0 calculation results are the most advantages of 37.45030 x1 * = 11.62554, x2 * = 4.325057

2, Gatool's usage Enter Gatool in the MATLAB7 command line, see the drawings. At PopulationSize = 10000; please pay attention to the selection of Mutation functions. f (x1 *, x2 *) = - my_func1 (x1 *, x2 *) = 38.84741978236206, where x1 * = 11.62378; x2 * = 5.725013, the use of the GA function is used to use the non-original setting, so the GA is used Two modifiers, and Mutation To use the MutationUniform function. Opt1 = gaoptimset; Opt1.popinitRange = [[-3.0 4.1]; [12.1 5.8]]; OPT1.PopulationSize = 1000; Opt1.mutationFCN=@mutationuniform; [x, fval] = Ga (@ my_func1, 2, opt1) result as follows: >> opt1opt1 = PopulationType: 'doubleVector'PopInitRange: [2x2 double] PopulationSize: 1000EliteCount: 2CrossoverFraction: 0.80000000000000MigrationDirection:' forward'MigrationInterval: 20MigrationFraction: 0.20000000000000Generations: 100TimeLimit: InfFitnessLimit: -InfStallGenLimit: 50StallTimeLimit: 20InitialPopulation: [] InitialScores : [] PlotInterval: 1CreationFcn: @gacreationuniformFitnessScalingFcn: @fitscalingrankSelectionFcn: @selectionstochunifCrossoverFcn: @crossoverscatteredMutationFcn: @mutationuniformHybridFcn: [] Display: 'final'PlotFcns: [] OutputFcns: [] Vectorized:' off '>> [x, fval] = GA (@ my_func1, 2, opt1) Optimization Terminated: stall generations limit exceeded.x = 11.60992040806107 5.72602745388080fval = -38.6161949630000001 >> (thumbnail, click on the picture link to see the original picture)

转载请注明原文地址:https://www.9cbs.com/read-17855.html

New Post(0)