Điều khiển thông minh
Post on 11-Apr-2017
183 Views
Preview:
TRANSCRIPT
ĐIỀU KHIỂN THÔNG MINH
TOPIC:
GENETIC FUZZY CONTROLLER
Nguyễn Văn Tiến Anh
INTELLIGENT CONTROL
2016
GENETIC FUZZY CONTROLLER 1
§1. Đề bàiĐiều khiển vận tốc của xe theo vận tốc tốc mong muốn . Phương trình của hệ thống:
Trong đó:• là tín hiệu điều khiển • là khối lượng xe• là hệ số sức cản của gió• là lực điều khiển• là hằng số engine/brake timeYêu cầu:Bộ điều khiển:
2
INTELLIGENT CONTROL
2016
GENETIC FUZZY CONTROLLER
§2. Genetic Fuzzy Controller
3
INTELLIGENT CONTROL
2016
GENETIC FUZZY CONTROLLER
� 𝑑𝑑𝑡 System
-
𝑣𝑑ሺ𝑡ሻ 𝑣ሺ𝑡ሻ
• Biến tối ưu: • Ràng buộc:
§2. Genetic Fuzzy ControllerHàm mục tiêu:Yêu cầu:
4
INTELLIGENT CONTROL
2016
GENETIC FUZZY CONTROLLER
§2. Genetic Fuzzy Controller• Xem hệ thống có dạng bậc 2. Đáp ứng ngõ ra khi đầu vào là tín hiệu
step:
Khi đó:• Độ vọt lố: • Settling time: • Rise time:
5
INTELLIGENT CONTROL
2016
GENETIC FUZZY CONTROLLER
§2. Genetic Fuzzy Controller• Khi biết được , , thì tìm được đáp ứng tối ưu mà bộ điều khiển
hướng tới:
Với:
6
INTELLIGENT CONTROL
2016
GENETIC FUZZY CONTROLLER
§2. Genetic Fuzzy Controller• Các bộ điều khiển thỏa mãn yêu cầu về , , thì đáp ứng sẽ nằm trong
vùng như ở đồ thị dưới.• Bộ điều khiển Genetic Fuzzy sẽ tìm thông số tối ưu để đáp ứng nằm
trong miền yêu cầu
7
INTELLIGENT CONTROL
2016
GENETIC FUZZY CONTROLLER
𝐹=∑ (𝑐𝑟𝑒𝑓 −𝑐 )2
§2. Outline of the Basic Genetic Algorithm1. [Start] Generate random population of n 2. [Fitness] Evaluate the fitness f(x) of each chromosome x in the population 3. [New population] Create a new population by repeating following steps until the new population is complete
3.1. [Selection] Select two parent chromosomes from a population according to their fitness (the better fitness, the bigger chance to be selected) 3.2. [Crossover] With a crossover probability cross over the parents to form new offspring (children). If no crossover was performed, offspring is the exact copy of parents. 3.3. [Mutation] With a mutation probability mutate new offspring at each locus (position in chromosome). 3.4. [Accepting] Place new offspring in the new population
4. [Replace] Use new generated population for a further run of the algorithm 5. [Test] If the end condition is satisfied, stop, and return the best solution in population 6. [Loop] Go to step 2
8
INTELLIGENT CONTROL
2016
GENETIC FUZZY CONTROLLER
§2. Genetic Fuzzy Controller
9
INTELLIGENT CONTROL
2016
GENETIC FUZZY CONTROLLER
%% Initializationempty_element.Chromosome=[];empty_element.FitValue=[];pop=repmat(empty_element,nPop,1);% Population
for i=1:nPop
end
% Initialize Position pop(i).Chromosome=randi([0 1],VarSize);
% Evaluation pop(i).FitValue = CostFunction(pop(i).Position);
Population(i)
% Sort PopulationFitness=[pop.FitValue];[Fitness, SortOrder]=sort(Fitness);pop=pop(SortOrder);
% Store Best SolutionBestSol=pop(1);% Array to Hold Best Fitness ValuesBestFit=zeros(MaxIt,1);% Store Fitness ValueWorstFit=pop(end).FitValue;
Chromosome
Fitness Value
§2. Genetic Fuzzy Controller
10
INTELLIGENT CONTROL
2016
GENETIC FUZZY CONTROLLER
% New Populationfor it=1:MaxIt % Crossover popc=repmat(empty_element,nc/2,2); % value for crossover for k=1:nc/2 % Roulette Wheel Selection ip1=RouletteWheelSelection(Fitness); ip2=RouletteWheelSelection(Fitness); % Select Parents p1=pop(ip1); p2=pop(ip2); % Perform Crossover [popc(k,1).Chromosome, popc(k,2).Chromosome]=... Crossover(p1.Chromosome,p2.Chromosome); % Evaluate Offsprings popc(k,1).FitValue=CostFunction(popc(k,1).Chromosome); popc(k,2).FitValue=CostFunction(popc(k,2).Chromosome); end popc=popc(:); end
function [index] = RouletteWheelSelection(arrayInput)len = length(arrayInput);% if input is one element then just return rightawayif len ==1 index =1; return;endif (~isempty(find(arrayInput<1, 1))) if (min(arrayInput) ~=0) arrayInput = 1/min(arrayInput)*arrayInput; else temp= arrayInput; temp(arrayInput==0) = inf; arrayInput = 1/min(temp)*arrayInput; endendtemp = 0;tempProb = zeros(1,len);for i= 1:len tempProb(i) = temp + arrayInput(i); temp = tempProb(i);endi = fix(rand*floor(tempProb(end)))+1;index = find(tempProb >= i, 1);
http://www.mathworks.com/matlabcentral/fileexchange/45735-roulette-wheel-selection
§2. Genetic Fuzzy Controller
11
INTELLIGENT CONTROL
2016
GENETIC FUZZY CONTROLLER
% New Populationfor it=1:MaxIt % Crossover popc=repmat(empty_element,nc/2,2); % value for crossover for k=1:nc/2 % Roulette Wheel Selection ip1=RouletteWheelSelection(Fitness); ip2=RouletteWheelSelection(Fitness); % Select Parents p1=pop(ip1); p2=pop(ip2); % Perform Crossover [popc(k,1).Chromosome, popc(k,2).Chromosome]=... Crossover(p1.Chromosome,p2.Chromosome); % Evaluate Offsprings popc(k,1).FitValue=CostFunction(popc(k,1).Chromosome); popc(k,2).FitValue=CostFunction(popc(k,2).Chromosome); end popc=popc(:); end
function [y1, y2]=Crossover(x1,x2) pSinglePoint=0.1; pDoublePoint=0.2; pUniform=1-pSinglePoint-pDoublePoint; METHOD=RouletteWheelSelection([pSinglePoint pDoublePoint pUniform]); switch METHOD case 1 [y1, y2]=SinglePointCrossover(x1,x2); case 2 [y1, y2]=DoublePointCrossover(x1,x2); case 3 [y1, y2]=UniformCrossover(x1,x2); endend
§2. Genetic Fuzzy Controller
12
INTELLIGENT CONTROL
2016
GENETIC FUZZY CONTROLLER
% New Populationfor it=1:MaxIt % Crossover %[…] % Mutation popm=repmat(empty_element,nm,1); for k=1:nm % Select Parent i=randi([1 nPop]); p=pop(i); % Perform Mutation popm(k).Chromosome=Mutate(p.Chromosome,mu); % Evaluate Mutant popm(k).FitValue=CostFunction(popm(k).Chromosome); end end
function y=Mutate(x,mu) nVar=numel(x); nmu=ceil(mu*nVar); j=randsample(nVar,nmu); y=x; y(j)=1-x(j);end
§2. Genetic Fuzzy Controller
13
INTELLIGENT CONTROL
2016
GENETIC FUZZY CONTROLLER
% New Populationfor it=1:MaxIt % Crossover %[…] % Mutation %[…] % Create Merged Population pop=[pop;popc;popm]; %#ok % Sort Population Fitness=[pop.FitValue]; [Fitness, SortOrder]=sort(Fitness); pop=pop(SortOrder); % Update Worst Fitness Value WorstFit=max(WorstFit,pop(end).FitValue); % Truncation pop=pop(1:nPop); Fitness=Fitness(1:nPop); % Store Best Solution Ever Found BestSol=pop(1); % Store Best Cost Ever Found BestFit(it)=BestSol.FitValue; % Show Iteration Information disp(['Iteration ' num2str(it) ': Best Cost = ' num2str(BestFit(it))]); end
§2. Genetic Fuzzy Controller
14
INTELLIGENT CONTROL
2016
GENETIC FUZZY CONTROLLER
% Cost Functionfunction z=e_square(x)
% [...]rules=zeros(5,5);k=1;leftbound=1;rightbound=bitn;for id1=1:5 for id2=1:5
rules(id1,id2)=bit2num(x(leftbound:rightbound)... , [Varmin, Varmax]);
k=k+1; leftbound=leftbound+bitn; rightbound=rightbound+bitn; end end% [...]
end
function num = bit2num(bit, range)integer = polyval(bit, 2);num = integer*((range(2)-range(1))/(2^length(bit)-1)) + range(1);end
§2. Genetic Fuzzy Controller
15
INTELLIGENT CONTROL
2016
GENETIC FUZZY CONTROLLER
% Cost Functionfunction z=e_square(x)
% [...]Mp=bit2num(x(leftbound:rightbound), [0, 0.05]);leftbound=leftbound+bitn;rightbound=rightbound+bitn;t_settling=bit2num(x(leftbound:rightbound), [7, 8]);leftbound=leftbound+bitn;rightbound=rightbound+bitn;t_rise=bit2num(x(leftbound:rightbound), [4, 6.5]);
xi = abs(log(Mp))/sqrt((log(Mp))^2+pi^2);wn = 4/t_settling/xi;wd=(pi-atan2(sqrt(1-xi^2),xi))/t_rise;ref_crl = @(x) 1-exp(-xi*wn*x).*(cos(wd*x)+xi*sin(wd*x)/sqrt(1-xi^2));% [...]
end
𝑐 (𝑡 )=1−𝑒− 𝜉𝜔𝑛 𝑡 (cos𝜔𝑑𝑡+𝜉
√1−𝜉 2sin𝜔𝑑𝑡)
𝜉=|ln𝑀𝑝|
√( ln𝑀𝑝)2+𝜋 2𝜔𝑑=
𝜋−𝑎𝑡𝑎𝑛2 (√1−𝜉2 ,𝜉 )𝑡𝑟
𝜔𝑛=4𝜉 𝑡 𝑠
§2. Genetic Fuzzy ControllerFitness Function
16
INTELLIGENT CONTROL
2016
GENETIC FUZZY CONTROLLER
§2. Genetic Fuzzy ControllerĐáp ứng
17
INTELLIGENT CONTROL
2016
GENETIC FUZZY CONTROLLER
top related