Está en la página 1de 20

PURDUE UNIVERSITY

ELECTRICAL ENGINEERING TECHNOLOGY

FINAL PROJECT

Franklin Pacheco

Class: MET 503 APPLIED OPTIMIZATION

Professor: Prof. Dr. Mark French

Spring 2015

Executive Summary

This project aims to explain alternative optimization methods that can be used in smart grids.
The specific application in this project was to determine the better option of energy
distribution minimizing the cost to provide energy from different sources to different loads
considering constraints in the demand, supply capabilities and capacity of each power link.

Table of Contents

Executive Summary ............................................................................................................... 2

Table of Contents .................................................................................................................. 2

Introduction .......................................................................................................................... 1

Statement of the Problem..................................................................................................... 1


4.1

Design space .................................................................................................................. 2

Solution Methods .................................................................................................................. 3


5.1

KarushKuhnTucker conditions................................................................................... 5

5.2

LP- Simplex method....................................................................................................... 7

Conclusions ......................................................................................................................... 10

Bibliografa .......................................................................................................................... 10

Annexes ............................................................................................................................... 11
8.1

Particle Swarm Optimization....................................................................................... 11

Genetic Algorithms.............................................................................................................. 14

Introduction

Smart grid generally refers to a class of technology people are using to bring utility electricity
delivery systems into the 21st century, using computer-based remote control and automation.
These systems are made possible by two-way communication technology and computer
processing that has been used for decades in other industries. They are beginning to be used
on electricity networks, from the power plants and wind farms all the way to the consumers of
electricity in homes and businesses. They offer many benefits to utilities and consumers mostly
seen in big improvements in energy efficiency on the electricity grid and in the energy users
homes and offices. (Office of Electricity Delivery & Energy Reliability, n.d.)
In a smart grid, the concept of optimization is involved in different aspects as is shown in
Figure 1.

Figure 1. Smart Grid Optimization

One specific aspect to work in this work is the optimization in distribution, minimizing
the cost to connect different loads with available sources. The determination of the best
network topology can help in a network self-healing.
The self-healing grid isolates problems immediately as they occur, before they cascade
into major blackouts, and reorganizes the grid and reroutes energy transmissions so
services continue for all customers while the problem is physically repaired by line
crews. A self-healing smarter grid can provide a number of benefits that lead to a more
stable and efficient system. (Amin, 2013).

Statement of the Problem

I pretended to determine the best alternative to deliver energy to different demand sites
from different supply sources when there are different constraints. Even though the
exercise seemed to be very simple, the idea was to identify how difficult it could be
when the design space is affected by a considerable number of constraints.
The design of the objective function was based in the paper Optimization Models for
Energy Reallocation in Smart Grid of Nygard et al.

4.1 Design space


There are J distinct demands for energy for which alternative sources of supply must be
allocated in the short term to respond to disruptions. For each of these J demands there
is a finite set of available supply sources that can be allocated to meet the demand.
Figure 2 shows a bipartite graph in which the supply sources are nodes in the left set and
demand sites are nodes in the right set. (Nygard, Ghosn, Minhaz, & Ranganathan, 2011)

Figure 2. A bipartite graph with supply and demand nodes. (Nygard, Ghosn, Minhaz, & Ranganathan, 2011)

The variables and constants utilized are:


cij: cost per power flow unit of assigning supply source i to demand site j. This
cost includes multiple factors taken together, such as prices established under
existing contracts, regulatory principles, prices negotiated in near real time,
issues related to the viability of transmission paths, and expected reliability.
si: level of energy available of a given supply source i
dj: level of energy needed of specific demand sites. Sources can supply multiple
demand sites, and demand sites can be served from multiple sources.
xij: power flow on link from supply sources to demand sites (ij).
uij: the capacity (upper bound) that can be allocated to an available pathway
connecting nodes i and j
With this definitions, the mathematical expression of the optimization problem is:
I

Min z = cij xij


=i 1 =j 1

Subject to :
I

x
i =1

ij

x
j =1

ij

dj

for all j

sj

for all i

0 xij uij

for all i and j

Solution Methods

In the document consulted the purpose is to define the optimization models, the authors
do not resolve a numerical value example. They use a smart grid simulator which runs
as a Multi-Agent System (MAS) using the Java Agent Development Framework
(JADE). Hence, in this project I decided to solve a basic problem considering 2 sources
and 3 loads utilizing different optimization methods.

The problem stated is:


The maximum supply capacity is 50KW and 80KW. The demand requirements are:
20KW, 30KW and 40KW. Since there are 2 loads and 3 sources, there are 6 possible
power flow links. The costs per power flow unit and the maximum capacity available in
each power link are shown in the next tables:
cij:
Source(i)\Load(j)
1
2
3
4 $/KW
4 $/KW
1 $/KW
1
5 $/KW
4 $/KW
5 $/KW
2
xij:
Source(i)\Load(j)
1
2

1
30 KW
35 KW

2
25 KW
25 KW

3
25 KW
25 KW

The mathematical expression of the problem is:

Minimize z = 4 x11 + 4 x12 + x13 + 5 x21 + 4 x22 + 5 x23


Subject to :
x11 + x21 20
x12 + x22 30
x13 + x23 40
x11 + x12 + x13 50
x11 + x12 + x13 80
0 x11 30
0 x12 25
0 x13 25
0 x21 35
0 x22 25
0 x23 25
Even though the objective function looks very simple, there exists 17 constraints that
difficult the resolution by the methods that we have seen in classes such as penalty
function and steepest descent. Therefore, the main work performed in this project was to
learn other methods that could be useful to solve this problem in a better way:

The problem was solved utilizing Mathcad and defining some vectors for easier
manipulation of the values:

50
s :=
80

4
4

1
C :=
5
4

5

20
d := 30

40

x11
x12

x13
X( x11 , x12 , x13 , x21 , x22 , x23) :=
x21
x22

x23

30
25

25
u :=
35
25

25

The expression in the standard form in Mathcad is:


Objective function:
T

z( x11 , x12 , x13 , x21 , x22 , x23) := C X( x11 , x12 , x13 , x21 , x22 , x23) 4 x11 + 4 x12 + 5 x21 + x13 + 4 x22 + 5 x23

Constraints:
g1( x11 , x12 , x13 , x21 , x22 , x23) := x11 x21 + d
g2( x11 , x12 , x13 , x21 , x22 , x23) := x12 x22 + d
g3( x11 , x12 , x13 , x21 , x22 , x23) := x13 x23 + d

0
1
2

g4( x11 , x12 , x13 , x21 , x22 , x23) := x11 + x12 + x13 s
g5( x11 , x12 , x13 , x21 , x22 , x23) := x11 + x12 + x13 s
g6( x11 , x12 , x13 , x21 , x22 , x23) := x11 u
g7( x11 , x12 , x13 , x21 , x22 , x23) := x12 u
g8( x11 , x12 , x13 , x21 , x22 , x23) := x13 u
g9( x11 , x12 , x13 , x21 , x22 , x23) := x21 u

g12( x11 , x12 , x13 , x21 , x22 , x23) := x11

g13( x11 , x12 , x13 , x21 , x22 , x23) := x12

g14( x11 , x12 , x13 , x21 , x22 , x23) := x13

g15( x11 , x12 , x13 , x21 , x22 , x23) := x21

g10( x11 , x12 , x13 , x21 , x22 , x23) := x22 u


g11( x11 , x12 , x13 , x21 , x22 , x23) := x23 u

4
5

g16( x11 , x12 , x13 , x21 , x22 , x23) := x22


g17( x11 , x12 , x13 , x21 , x22 , x23) := x23

5.1 KarushKuhnTucker conditions


This method allows inequality constraints and generalizes the method of Lagrange
multipliers, which allows only equality constraints.

In applying the Karush-Kuhn-Tucker method, a trick is to check the cases 1 = 0, 1 >


0, 2 = 0, 2 > 0, . . . , p = 0, p > 0 and see whether they give feasible solutions.
In synthesis the KKT conditions are:
1. * 0
2. Df(x*) + *T Dh(x*) + *TDg(x*) = 0T
3. *Tg(x*) = 0
In this case there are 17 Karush-Kuhn-Tucker multipliers and 0 Lagrange multipliers
5

The constraints were expressed in matrix form:


1
0
0
1

1
1

0
0
A := 0

0
0
1

0
0

0
0
0

0 1 0

1 0

0
0

0
0
0

0
1

0
0

0
0
1
0

0 1 0

0 1 0

1 0

0 1 0

0 1 0

0 1

d0

d1

d2
s
0
s
1
u 0

u 1

u
b := 2

u3
u
4
u
5
0
0

0
0
0

0

Applying the KKT conditions, the equations to solve are:

Solving the system of equations the results were:


20
5

25
Xstar =
0
25

15

Giving an objective value function of 300 $.

The topology resultant is shown next, there is

5.2 LP- Simplex method

The process can be resolved using matrices.


We start with an augmented matrix with the coefficients of the objective function and
constraints:

Applying operations the objective is to obtain the identity matrix in the upper left side
and vector 0 below it:

The algorithm can be summarized as follows:

(Chong & H., 2014)


8

The matrix augmented with the slack variables in Mathcad is:

Since the solution performed manually took very long, there is an easy way to perform
this calculation in Matlab. The code implemented was using the function linprog:
clear
clc
c=[4;4;1;5;4;5];
A=[-1,0,0,-1,0,0;...
0,-1,0,0,-1,0;...
0,0,-1,0,0,-1;...
1,1,1,0,0,0;...
1,1,1,0,0,0;...
1,0,0,0,0,0;...
0,1,0,0,0,0;...
0,0,1,0,0,0;...
0,0,0,1,0,0;...
0,0,0,0,1,0;...
0,0,0,0,0,1];
b=[-20;-30;-40;50;80;30;25;25;35;25;25];
lb = zeros(6,1);
x=linprog(c,A,b,[],[],lb);
x

The answer was:


Optimization terminated.
x=
20.0000
5.0000
25.0000
0.0000
25.0000
15.0000

Which are the same results obtained with the KKT conditions.
As we can see, even though the objective function was simple, the addition of many
constraints makes the problem very difficult to manage manually. In this cases it is
possible to see the importance of software tools that help to solve this kind of problems.
Trying to find other methods of optimization, I looked to population methods such as
Particle Swarm optimization, since I learned the application of those in an unconstraint
situation, I did not applied them to the current problem. However, I explain the work
performed with them in the Annexes section.

Conclusions

The introduction of various constraints convert a simple problem in something


difficult to manage manually. In these cases it is necessary software tools
specialized in solve this kind of optimization problems
The optimization of the power distribution from different sources to different
loads is necessary in smart grids with the objective of performing self-healing
when there is an outage. This allow to reconnect the loads finding the best new
topology without the intervention of the man.

Bibliografa

Amin, M. (March de 2013). The Self-healing Grid: A Concept Two Decades in the Making .
Obtenido de IEEE Smart Grid: http://smartgrid.ieee.org/march-2013/813-the-selfhealing-grid-a-concept-two-decades-in-the-making
Capehart, B. L., C., T. W., & J., K. W. (2011). Guide to Energy Management. Lilburn: The
Fairmont Press, Inc.
Chong, E. K., & H., Z. S. (2014). Introduction to Optimization. Hoboken, New Jersey: John Wiley
& Sons, Inc.
Chrysler. (September de 2014). FCA Fiat Chrysler Automobiles. Obtenido de
http://media.chrysler.com/newsrelease.do;jsessionid=DC5AA8835CCCE16CA887FB5B5
94A6D7F?&id=328&mid=
Nygard, K. E., Ghosn, S. B., Minhaz, M., & Ranganathan, P. (2011). Optimization Models for
Energy Reallocation in a Smart Grid. IEEE INFOCOM 2011 Workshop on M2MCN-2011,
186-190.
Office of Electricity Delivery & Energy Reliability. (s.f.). Smart Grid. Recuperado el 12 de April
de
2015,
de
Energy.gov:
http://energy.gov/oe/services/technologydevelopment/smart-grid
Vedenyov, M. (15 de June de 2011). Travelling salesman problem with Genetic algorithm.
Recuperado
el
09
de
April
de
2015,
de
Mathworks:
http://www.mathworks.com/matlabcentral/fileexchange/31818-travelling-salesmanproblem-with-genetic-algorithm
Wikipedia. (s.f.). Wipedia. Obtenido de www.wikipedia.org

10

Annexes

In this section it is included additional work and research performed during the
realization of the present project.
8.1 Particle Swarm Optimization
It is a computational method that optimizes a problem by iteratively trying to improve a
candidate solution with regard to a given measure of quality. PSO optimizes a problem
by having a population of candidate solutions, here dubbed particles, and moving these
particles around in the search-space according to simple mathematical formulae over the
particle's position and velocity. Each particle's movement is influenced by its local best
known position but, is also guided toward the best known positions in the search-space,
which are updated as better positions are found by other particles. This is expected to
move the swarm toward the best solutions. (Wikipedia, n.d.).
PSO Algorithm

I implemented this algorithm in Matlab to obtain the global minimum of a function known as
the Griewank only in 2D with learning purposes.
The function for a 2D Griewank is:
f ( x1 , x2) := 1 +

1
4000

(x12 + x22) cos x1 cos x2


1

The calculations were implemented in Matlab with the next code:


11

clear
clc
clf
syms x
f=@(x1,x2) 1+1/4000*(x1^2+x2^2)-cos(x1/sqrt(1))*cos(x2/sqrt(2));
xlabel('x_1');
ylabel('x_2');
title('part b');
X1 = [-5:.1:5]';
X2 = [-5:.1:5]';
[x1,x2]=meshgrid(X1',X2');
func= 1+1/4000*(x1.^2+x2.^2)-cos(x1/sqrt(1))*cos(x2/sqrt(2));
subplot(1,2,1);
mesh(x1,x2,func);
subplot(1,2,2);
contour(x1,x2,func,10);

d=20; %d-population size


k=1;
vmax=5;
for i=1:d
X(:,i)=-5+10*rand(2,1);
V(:,i)=-5+10*rand(2,1);
end
p=X;
for i=1:d
fx(i)= f(X(1,i),X(2,i));
end
[fmin,pos]=min(fx);
g=X(:,pos);

while(norm(g)>0.1)
best(k)=min(fx);
worst(k)=max(fx);
average(k)=mean(fx);
for i=1:d
r(:,i)=rand(2,1);
s(:,i)=rand(2,1);
end
w=0.95;
c1=2;
c2=2;
for i=1:d
Vnext(:,i)=w*V(:,i)+c1*r(:,i).*(p(:,i)-X(:,i))+c2*s(:,i).*(gX(:,i));
Vnext(1,i)=min(vmax,max(-vmax,(Vnext(1,i))));
Vnext(2,i)=min(vmax,max(-vmax,(Vnext(2,i))));
end
Xnext=X+Vnext;

12

for i=1:d
fnext(i)= f(Xnext(1,i),Xnext(2,i));
fpbest(i)=f(p(1,i),p(2,i));
if fnext(i)<fpbest(i)
pnext(:,i)=Xnext(:,i);
else
pnext(:,i)=p(:,i);
end
end

[fmin,pos]=min(fnext);
if fmin<f(g(1),g(2))
gnext=Xnext(:,pos);
else
gnext=g;
end
drawnow;
hold on;
plot(g(1),g(2),'x');
%plot(X(1,:),X(2,:),'x');
k=k+1;
X=Xnext;
V=Vnext;
g=gnext;
p=pnext;
fx=fnext;
end
x1star=g(1);
x2star=g(2);
fprintf('The value of x that minimizes f is: [%.5f , %.5f]\n', x1star,
x2star)
fprintf('The number of iterations is: %d\n',k)

Knowing that the global minimum is x= [0,0]T. The exit criteria used was that the norm of the
global best less than 0.1
The results were:
13

The value of x that minimizes f is: [0.06430 , 0.05252]


The number of iterations is: 32
In the next figure is it possible to observe the global best values in all the iterations:

Genetic Algorithms

It is a search heuristic that mimics the process of natural selection, it belongs to the larger class
of evolutionary algorithms (EA), which generate solutions to optimization problems using
techniques inspired by natural evolution, such as inheritance, mutation, selection, and
crossover. (Wikipedia, n.d.).
The algorithm for Genetic Algorithms is:

I applied genetic algorithms to solve the traveling sales problem for 10 cities. The code was a
modification of the tsp_ga.m code found in mathworks.com (Vedenyov, 2011).

14

Locations of the cities.


0.4306 3.7094 6.9330 9.3582 4.7758 1.2910 4.83831 9.4560 3.6774 3.2849
7.7288 2.9727 1.7785 6.9080 2.6394 4.5774 8.43692 8.8150 7.0002 7.5569

There are

( N 1)!
2

possible paths because it does not matter in which city begin and if the

path is in one side or in its opposite.


For this exercise, there are 181440 possible paths.

clear
clc
clf
nn=10; % number of cities
asz=10; % area size
asx x asz
ps=1000; % population size
ng=1000; % number of generation
pm=0.01; % probability of mutation of exchange 2 random cities in the
path (per gene, per generation)
pm2=0.00; % probability of mutation of exchange 2 pieces of path (per
gene, per generation)
pmf=0.00; % probability of mutation of flip random piece of path
%r=asz*rand(2,nn); % randomly distribute cities
% r(1,:) -x coordinates of cities
% r(2,:) -y coordinates of cities
r(1,:)=[0.4306 3.7094 6.9330 9.3582 4.7758 1.2910
3.6774 3.2849];
r(2,:)=[7.7288 2.9727 1.7785 6.9080 2.6394 4.5774
7.0002 7.5569];

4.83831 9.4560
8.43692 8.8150

dsm=zeros(nn,nn); % matrix of distances


for n1=1:nn-1
r1=r(:,n1);
for n2=n1+1:nn
r2=r(:,n2);
dr=r1-r2;
dr2=dr'*dr;
drl=sqrt(dr2);
dsm(n1,n2)=drl;
dsm(n2,n1)=drl;
end
end
% start from random closed paths:

15

G=zeros(ps,nn); % genes, G(i,:) - gene of i-path, G(i,:) is row-vector


with cities number in the path
for psc=1:ps
G(psc,:)=randperm(nn);
end
figure('units','normalized','position',[0.05 0.2 0.9 0.6]);
subplot(1,2,1);
% to plot best path:
hpb=plot(NaN,NaN,'r-');
ht=title(' ');
hold on;
% plot nodes numbers
for n=1:nn
text(r(1,n),r(2,n),num2str(n));
end
plot(r(1,:),r(2,:),'k.'); % plot cities as black dots
axis equal;
xlim([-0.1*asz 1.1*asz]);
ylim([-0.1*asz 1.1*asz]);
hi=imagesc(G);
pthd=zeros(ps,1); %path lengths
p=zeros(ps,1); % probabilities
for gc=1:ng % generations loop
% find paths length:
for psc=1:ps
Gt=G(psc,:);
pt=0; % path length summation
for nc=1:nn-1
pt=pt+dsm(Gt(nc),Gt(nc+1));
end
% last and first:
pt=pt+dsm(Gt(nn),Gt(1));
pthd(psc)=pt;
end
ipthd=1./pthd; % inverse path lengths, we want to maximize inverse
path length
p=ipthd/sum(ipthd); % probabilities
[mbp bp]=max(p);
Gb=G(bp,:); % best path
% update best path on figure:
if mod(gc,5)==0
set(hpb,'Xdata',[r(1,Gb) r(1,Gb(1))],'YData',[r(2,Gb)
r(2,Gb(1))]);
set(ht,'string',['generation: ' num2str(gc) ' best path
length: ' num2str(pthd(bp))]);
set(hi,'CData',G);
drawnow;
end
% crossover:
ii=roulette_wheel_indexes(ps,p); % genes with cities numers in ii
will be put to crossover
% length(ii)=ps, then more probability p(i) of i-gene then more
% frequently it repeated in ii list
Gc=G(ii,:); % genes to crossover

16

Gch=zeros(ps,nn); % childrens
for prc=1:(ps/2) % pairs counting
i1=1+2*(prc-1);
g1=Gc(i1,:);
cp=ceil((nn-1)*rand); % crossover point
% child:
g1ch=insert_begining(g1,g2,cp);
Gch(i1,:)=g1ch;
end
G=Gch; % now children
% mutation of exchange 2 random cities:
for psc=1:ps
if rand<pm
rnp=ceil(nn*rand); % random number of sicies to permuation
rpnn=randperm(nn);
ctp=rpnn(1:rnp); %chose rnp random cities to permutation
Gt=G(psc,ctp); % get this cites from the list
Gt=Gt(randperm(rnp)); % permutate cities
G(psc,ctp)=Gt; % % return citeis back
end
end
G(1,:)=Gb; % elitism
end

roulette_wheel_indexes.m
cpr=cumsum(prn);
n=length(prn);
% make cpr - row-vector if neccessary:
sz=size(cpr);
if sz(1)>sz(2)
cpr1=cpr';
else
cpr1=cpr;
end
i1=interp1([0 cpr1],1:(n+1),rand(1,m),'linear');
ii=floor(i1); % random numbers from 1:n according probabilities

insert_begining.m
function gch=insert_begining_slow(g1,g2,cp)
% insert begining from g2 (g2(1:cp)) to geging of g1 (g1(1:cp))
% return modified g1 in such way

for cpc=1:cp
if g2(cpc)~=g1(cpc) % if not same
ind=find(g1==g2(cpc)); % then where where is it
% swap:
g1(ind)=g1(cpc); % send to that place
g1(cpc)=g2(cpc);
end
end

17

gch=g1;

After 1000 iterations, the best path is:

[1 6 2 5 3 4 8 7 9 10 1]

18

También podría gustarte