Upload
others
View
38
Download
8
Embed Size (px)
Citation preview
GAtoolbox: a Matlab-based Genetic
Algorithm Toolbox for Function
Optimization
Code: 27.001
Justo José Roberts1,3, Agnelo Marotta Cassula2,
José Luz Silveira, Pedro Osvaldo Prado3,
José Celso Freire Junior2
1IPBEN-UNESP Guaratinguetá, Brazil 2São Paulo State University (UNESP), Brazil 3National University of Mar del Plata (UNMdP), Argentina
Structure
12/11/2017 2
I. Introduction and Objectives
II. Theoretical Background
III. Description of GAtoolbox
IV. Implementation
V. Conclusion and Future Work
I. Introduction
• It has become very popular in engineering activities, primarily
because of the availability and affordability of high speed
computers.
12/11/2017 3
• Optimization is the “determination of values for design variables
which minimize (maximize) the objective, while satisfying all
constraints”.
• Determine how desirable or undesirable the performance of a
system or a design is every day engineers decision.
• Genetic Algorithms (GA) constitutes an important topic in
Engineering Optimization undergraduate/postgraduate course.
I. Objectives
• Describe the main features of the developed
GAtoolbox.
• Present the results of its implementation in a
practical study case.
12/11/2017 4
II. Theoretical Background
Classification of optimization algorithms
Algorithms
Deterministic
Linear programming
Non-linear programming
Gradient-based
Gradient-free
...
Stochastic Heuristic
Metaheuristic
11/12/2017 5
II. Theoretical Background
12/11/2017 6
Genetic Algorithm
II. Theoretical Background
11/12/2017 7
Genetic Algorithms (GA)
• Probabilistic algorithms
Evolutionary algorithms
population based naturally
inspired Metaheuristic.
• Conceived in 1960 by John Holland
species adaptation and natural
selection computers.
• Later, in the 1980s David E.
Goldberg first success in
industrial application with Gas.
Chromosome
DNA
Gene
Start
Generate first
populationEvaluate fitness
Are optimization
criteria met?Best individuals
Translate
End
Selection
Recombination
Mutation
Generate first
population
II. Theoretical Background
12/11/2017 8
Simple Genetic Algorithm
No
Yes
III. Description of GAtoolbox
12/11/2017 9
Four main
modules Subroutines
1
2
3
4
· Linear ranking
· Non-linear ranking
· Roulette wheel selection
· Stochastic universal sampling
· Tournament selection
· Normalized geometric selection
· Discrete recombination
· Single-point crossover
· Double-point crossover
· Multi-point crossover
· Shuffle crossover
· Blend recombination (BLX-α)
· Line recombination
· Arithmetic recombination
· Flat recombination (BLX-0.0)
· Intermediate recombination
· Binary mutation
· Breeder mutation
· Boundary mutation
· Uniform mutation
· Multi-uniform mutation
· Non-uniform mutation
· Multi-non-uniform mutation
· Maximum time and generations
· Hitting a bound
· Running mean
· Standard deviation
· Best-worst
· Phi
· Uniform reinsertion
· Worst and fitness-based reinsertion
Parameter
definition
END
START
· Real decimal
· Integer decimal
· Binary
Variables setting
· Number of variables
· Population size
Geration of initial population
Fitness assignment
Selection
Recombination
Mutation
Satisfy optimization
criteria?
Evolution
Reinsertion
mf x
0, 1,...,jg x j J + K
, 1,...,l u
i i ix x x i n
1 2, ,...,T
nx x x x S
m 1,...,MMinimize
subjected to
Optimization problem definition
Problem Definition Module
III. Description of GAtoolbox
12/11/2017 10
1
( )mf x 1,2,...,m M
( ) 0jg x 1,2,...,j J
( ) 0kh x 1,2,...,k K
i i ixLB x xUB 1,2,...,i n
x S
Subjected to
Minimize Mono-objective
Multi-objective
Unconstrained
Constrained
Problem Definition Module
III. Description of GAtoolbox
12/11/2017 11
1
min ( )f xMono-objective
Multi-objective 1 2min ( ) ( ), ( ),..., ( )m Mf x f x f x f x
A
F
E
D
Non-dominated solution
Dominated solutions
Pareto FrontRegion with no
feasible
solutions
1
4
2
3
B
C
f1
f2
*
* *
Dominace :
Pareto Optimal : |
Pareto Front :
x x
x S x x
PF x S
x S
NSGA-II
Nondominated Sorting Genetic Algorithm II
Problem Definition Module
III. Description of GAtoolbox
11/12/2017 12
1
( ) 0jg x 1,2,...,j J
( ) 0kh x 1,2,...,k K
i i ixLB x xUB 1,2,...,i n
Constrained problem
Approach adopted: dominance-based penalty-free
0
j
m
worst j
j
f x if g x
x
f g x otherwise
Method of Deb
Niching strategy based on Euclidean
distance
Method of Coello Coello and Montes
Variable number of competitors and not
deterministic
Variable Setting Module
III. Description of GAtoolbox
12/11/2017 13
2
Genotype space = {0,1} Phenotype space
Encoding
(representation)
Decoding
(inverse representation) 01110101
01000100
10010010
10010001
Representation critical decision in any application, namely that of
deciding how best to represent a candidate solution of the algorithm.
Generally accepted that it is better to encode numerical variables directly as:
• Integers
• Floating point variables
Variable Setting Module
III. Description of GAtoolbox
12/11/2017 14
2
Variable representations supported by GAtoolbox
GA works on Variable representation Need conversion?
binary real decimal Yes
binary integer decimal Yes
real decimal real decimal No
integer decimal integer decimal No
Integer representation truncation method 0,5
0,5
i i
i i
i
x se x
x x se r
x se r
Generation of Initial Population Module
III. Description of GAtoolbox
12/11/2017 15
3
First step in the GA is to create the initial population of individuals
Generate a required number of individuals uniformly distributed in the
desire range
11 12
1000 1100
0100 0011
1010 1011
x x
pop
Binary coding
11 12
2.33 23.6
1.35 0.55
10.1 1.23
x x
pop
Real representation
Evolution Module
III. Description of GAtoolbox
12/11/2017 16
4
Fitness assignment
Selection
Recombination
Mutation
Satisfy optimization
criteria?
Reinsertion
Evolution Module
III. Description of GAtoolbox
12/11/2017 17
4
Linear ranking
Non-linear ranking higher selective pressure
Fitness
assignment
12/11/2017
Evolution Module
III. Description of GAtoolbox
18
4
Roulette wheel selection Stochastic universal sampling
Normalized geometric selection
Spin
Spin
Tournament method Ranking Fitness Chromosome
1 2,1 Q
2 5 A
3 7,5 Z
4 10 W
5 11,2 S
6 20 R
7 2,3 F
8 24 I
11
1 1
irank x
popSize
q qP rank
q
Selection
Fitness Value Chromosome
1 Q
2 A A
3 Z
4 W A
5 S
6 R R
7 F
8 I I
Pick the best
parent Pick K at
random
12/11/2017
Evolution Module
III. Description of GAtoolbox
19
4
Recombination
Operator Variable representation
Discrete recombination All representations
Single-point crossover Binary and decimal integer
Double-point crossover Binary and decimal integer
Multi-point crossover Binary and decimal integer
Shuffle crossover Binary and decimal integer
Blend recombination (BLX-α) Decimal real
Line recombination Decimal real
Arithmetic recombination Decimal real
12/11/2017
Evolution Module
III. Description of GAtoolbox
20
4
Single-point crossover Binary and decimal integer
Double-point crossover Binary and decimal integer
Multi-point crossover Binary and decimal integer
Shuffle crossover Binary and decimal integer
Multi-point crossover Single-point crossover
Recombination
12/11/2017
Evolution Module
III. Description of GAtoolbox
21
4
Discrete recombination All representations
Line recombination Decimal real
Arithmetic recombination Decimal real
Blend recombination (BLX-α) Decimal real
Recombination
12/11/2017
Evolution Module
III. Description of GAtoolbox
22
4
Mutation
Operator Variable representation
Binary mutation Binary
Breeder GA Decimal real and integer
Boundary mutation Decimal real and integer
Uniform mutation Decimal real and integer
Multi-uniform mutation Decimal real and integer
Non-uniform mutation Decimal real and integer
Multi-non-uniform mutation Decimal real and integer
12/11/2017
Evolution Module
III. Description of GAtoolbox
23
4
Breeder GA
Uniform mutation
Non-uniform mutation
Mutation
12/11/2017
Evolution Module
III. Description of GAtoolbox
24
4
Termination
criteria
Maximum time or
Nº of generations
Hitting bound
Running mean
Standard deviation
Best-worst
Phi
max 0
0
t t
maxGen nGen
* lim
obj objF t F
1
*1
last
last
t*
obj objti t t
F t F i
2
1 1
1 1
pop pop
pop pop
N N
TC obj objN Ni i
F i F i
* *max 1 obj obj popF F i i N
*
1
1
1 1
pop
pop
obj
N
objN
i
F
F i
12/11/2017
Evolution Module
III. Description of GAtoolbox
25
4
Reinsertion
Pure reinsertion offspring (λ) = parents (μ)
Uniform reinsertion offspring (λ) < parents (μ)
Elitist reinsertion offspring (λ) < parents (μ)
Worst and fitness-based offspring (λ) = parents (μ)
λbest ... ... ... ... λworst μbest ... ... ... ... μworst
λ∙genGap λ∙(1-genGap) μ∙genGap μ∙(1-genGap)
λbest ... ... μbest ... ...
Parents Offspring
New population
Old population
12/11/2017
Parallel Computing
III. Description of GAtoolbox
26
• To reduce the computational time in the
execution of the optimization algorithm,
GAtoolbox allows the possibility of
parallel computation.
• Parallel Computing Toolbox (PCT)
• Run as many as eight Matlab workers on
your local machine in addition to your
Matlab client session.
parfor (parallel for-loops)
parfor
local workers
IV. Implementation
Step 1: setting up the optimization model
12/11/2017 27
% OPTIMIZATION MODEL
GaOptions = ga_options();
GaOptions.popSize = 50;
GaOptions.maxGen = 100;
GaOptions.numObj = 1;
GaOptions.numVar = 2;
GaOptions.numCons = 2;
GaOptions.xLB = [0,0];
GaOptions.xUB = [6,6];
GaOptions.varType = [2];
GaOptions.objFun = @test_fun305c;
% COMPONENTS' NAME
GaOptions.nameObj = {'Obj_1'};
GaOptions.nameVar = {'x_1','x_2'};
% SELECTION
GaOptions.selFun = 'coelloSelec';
GaOptions.coelloSr = 0.7;
% GENETIC ALGORITHM OPERATORS
GaOptions.recombiFun = 'blxRecombin';
GaOptions.BLXalpha = 0.5;
GaOptions.pXover = 0.9;
GaOptions.mutateFun = 'nonUniformMutate';
GaOptions.shapeB = 5;
GaOptions.pMut = 0.2;
% PARALLEL COMPUTING
GaOptions.useParallel = 'no';
% PLOT RESULTS
GaOptions.bestFitMeanPlot = 1;
% CALL GA FUNCTION
[xBest,bestObjValue,timeRun,GaOptions,Result]
= ga_constraint_optimization(GaOptions);
Step 2: create the objective function
function [y, cons] = test_fun305c(x)
y = [0];
cons = [0,0];
% OBJECTIVE FUNCTION
% MIN problem objective function
y(1) = (x(1).^2 + x(2) - 11).^2 + (x(1) + x(2).^2 - 7).^2;
% CONSTRAINTS
% Compute the constraint violation
c = 4.84 - (x(1) - 0.05).^2 - (x(2) - 2.5).^2;
cons(1) = (c<0)*abs(c);
c = x(1).^2 + (x(2) - 2.5).^2 - 4.84;
cons(2) = (c<0)*abs(c);
Step 3: Results
#Generation 50 / 50
currentGen 50
evaluateCount 2500
totalTime 588
Nwt Twt Npv Tpv Ndg NPVc
0 2 1023 4 3 7,99E+05
0 3 1020 4 3 8,00E+05
0 2 1017 4 3 8,00E+05
0 2 1016 4 3 8,01E+05
0 2 1040 4 3 8,01E+05
0 2 1030 4 3 8,03E+05
0 2 1028 4 3 8,03E+05
IV. Implementation – Study Case
12/11/2017 28
≈
=
CONV
AC DC
PV
WT
BT
DG
LAC
Ewt(kWh)
t(h)
Epv(kWh)
t(h)
SOC(%); Qbt(kWh)
t(h)
ηconv(%)
Pconv/Pconv,r (%)
Fdg(L/h)
Pdg(kW)
ηdg(%)
Pdg(kW)
Eload(kWh)
t(h)
Optimal design of Hybrid Power Systems (HPS)
Stochastic behavior of renewable resources and demand
Non-linear characteristic of some components Complexity
12/11/2017 29
START
Input parameters: component characteristics, renewable resources, load
END
Set of efficient solutions (configurations of HPS)
Compute the energy balance of the
system for one year of operation:
8760
1
i
i
E t
NPVc
LPSP
EMCO2
fren
fexess
SOCmin
Restrictions
Objetive/s
Compute:
Simulation Module Optimization Module (GAtoolbox)
Assess population
Select best individuals
Stopping
criteria met? Yes
No
Create first generation
Generate new population
(recombination, mutation)
Nwt
Npv
Ndg
Nbt
Nconv
IV. Implementation – Study Case
12/11/2017 30
Simulation Module
0%
10%
20%
30%
40%
50%
60%
70%
80%
90%
100%
0
5
10
15
20
25
30
35
40
45
1 5 9 13 17 21 25 29 33 37 41 45 49 53 57 61
SO
C (
%)
En
erg
y (
kW
h)
Hours (h)
0%
10%
20%
30%
40%
50%
60%
70%
80%
90%
100%
0,0
5,0
10,0
15,0
20,0
25,0
30,0
1 2 3 4 5 6 7 8 9 10 11 12 13
SO
C (
%)
En
erg
ia (
kW
h)
Horas (h)
WT PV DG Load Unmet Load Energy Excess SOC
IV. Implementation – Study Case
12/11/2017 31
Input data
Meteorological measurements
Demand load curve
0 50 100 150 200 250 3000
5
10
15
20
25
Pow
er
(kW
)Hour (h)
Weekday Weekend WeekendWeekday
HPS components
PV panel
Rated power 0.11 kWp
Area 1.02 m2
Initial capital (IC) 2900 $/kW
O&M 1% of IC $/year
Lifetime 25 year
Life cycle emissions 0.059 kgCO2e/kWh
Wind turbine
Rated power 7 kW
Tower height 17.5 m
Initial capital (IC) 3669 $/kW
O&M 3% of IC $/year
Lifetime 20 year
Life cycle emissions 0.02 kgCO2e/kWh
IV. Implementation – Study Case
12/11/2017 32
Minimization of Cost and Maximization of Reliability
( , )m CMIN f NPV LPS
Restrictions
LPSPadm [%] 5 %
fren.min [%] 0 %
fexess,adm [%] 100 %
Fdg,adm [L/year] Inf
EMCO2,adm [t/year] Inf
[Nwt,min ; Nwt,max] [0,15]
[Npv,min ; Npv,max] [0,300]
[Nbt,min ; Nbt,max] [0,50]
[Ndg,min ; Ndg,max] [0,3]
[Nconv,min ; Nconv,max] [0,6]
6,677,248 combinations
Net Present Value of costs
Loss of Power Supply Probability
IV. Implementation – Study Case
12/11/2017 33
Optimization Graphical Results ( , )m CMIN f NPV LPS
0 410000 820000 1230000 1640000 20500000
10000
20000
30000
40000
50000
Generation 1
Generation 2
Generation 3
Generation 4
Generation 5
LP
S (
kW
h/y
ear)
NPVc ($)
0,0
1,0
2,0
3,0
4,0
5,0
6,0
LP
SP
(%
)
288000 306000 324000 342000 3600000
500
1000
1500
2000
2500
3000
3500
4000
Generation 10
Generation 30
Generation 50
LP
S (
kW
h/y
ear)
NPVc ($)
0,0
1,0
2,0
3,0
4,0
5,0
6,0
LP
SP
(%
)
Sol 1
Sol 2
Sol 3
IV. Implementation – Study Case
12/11/2017 34
Optimization Numerical Results ( , )m CMIN f NPV LPS
WT
(kW)
PV
(kW)
DG
(kW)
BT
(kWh)
CONV
(kW)
Eexess
(%)
RF
(%)
Hdg
(h/yr)
Fdg
(L/yr)
LCOE
($/kWh)
LPSP
(%)
NPVc
($)
Sol 1 7x7 0 0 16x4 4x5 52.35 100 -- -- 0.2693 4.99 290,773.55
Sol 2 9x7 0 0 23x4 4x5 61.79 100 0 0 0.3080 1.83 343,610.00
Sol 3 7x7 0 2x10 21x4 4x5 51.53 98.22 653 1654.4 0.3160 0 359,081.14
WT
(kW)
PV
(kW)
DG
(kW)
BT
(kWh)
CONV
(kW)
Eexess
(%)
RF
(%)
Hdg
(h/yr)
Fdg
(L/yr)
LCOE
($/kWh)
LPSP
(%)
NPVc
($)
Sol 1 7x7 0 0 16x4 4x5 52.35 100 -- -- 0.2693 4.99 290,773.55
Sol 2 9x7 0 0 23x4 4x5 61.79 100 0 0 0.3080 1.83 343,610.00
Sol 3 7x7 0 2x10 21x4 4x5 51.53 98.22 653 1654.4 0.3160 0 359,081.14
Improve reliability
+ 23% investment
V. Conclusion
• The GAtoolbox is a useful tool to teach the
basics of GA in an undergraduate/postgraduate
optimization course.
• Advantages of implementing the code in Matlab
students become familiar with it aid to
develop their final projects.
12/11/2017 35
• The implementation of the toolbox in open
architecture software such as Matlab meets
the expectations of a flexible tool for
researching purposes as well.
V. Future Work
Other functionalities will be integrated in future
versions of the GAtoolbox:
• Friendly graphical user interphase.
• Other metaheuristics such as Particle Swarm
Optimization, Tabu Search, Differential
Evolution, among others.
• Help documentation.
12/11/2017 36