Академический Документы
Профессиональный Документы
Культура Документы
Supervisors:
Ulf Jonsson, Xiaoming Hu, Yuecheng Yang
1
Sammanfattning
Ett intressant omrade inom matematiken ar att beskriva fenomenet
med flockar och svarmar. Med hjalp av grafteori kan man beskriva ett
system av agenter som skickar information mellan varandra och med hjalp
av algoritmer som beskriver hur varje agents informationen ska uppdateras
sa att konsensus nas.
Om informationen beskriver en position eller forflyttning i rummet
kan man observera ett beteende som liknar det hos djurflockar eller in-
sektssvarmar. Manga andra tillampningsomraden finns ocksa, till exempel
i system av robotar nar det saknas central styrning och internt beslutsta-
gande ar onskvart.
I denna rapport kommer olika algoritmer for att uppdatera en agents
status att undersokas for att bestamma vilka krav som finns for att kon-
sensus skall nas. Forsta delen kommer att behandla ett enklare fall dar
varje agent tar emot information fran en oforanderlig uppsattning agen-
ter. Specifikt sa kommer en algoritm, dar en agents status bestams av
en linjar funktion som beror pa statusen hos de agenter fran vilka infor-
mation mottages, att studeras. Ett krav for att denna algoritm ska na
konsensus ar att varje agent bade skickar och tar emot information fran
samtliga ovriga agenter, direkt eller indirekt via andra agenter. Om alla in-
formationsoverforingar vags lika sa kommer alla agenter na medelvardet
av agenternas initialvarden. Konsensus kan ocksa nas under mindre re-
striktiva villkor, om det finns en agent som skickar information till alla
andra noder (direkt eller indirekt).
Forandringar av systemets beteende vid olika uppdateringsalgoritmer
kommer att studeras och datorsimuleringar av dessa fenomen kommer att
ges. Ett intressant fall ar da informationen (ofta position, hastighet eller
acceleration) endast kan tas emot fran de agenter som finns inom ett givet
avstand. darmed forandras den uppsattning agenter med vilka information
overfors med tiden. Detta resulterar i olinjara algoritmer och framforallt
kommer simulationer och tolkningar av dessa att ges. En observation ar att
om konsensus nas eller inte beror starkt pa densiteten bland agenterna i
utgangslaget samt det maximala avstand vid vilket informationsoverforing
kan ske.
2
Acknowledgements
We would like to thank our supervisors, Ulf Jonsson, Xiaoming Hu, and Yuecheng
Yang for all the time and help they have given us in the work on this bachelors
thesis.
3
CONTENTS
Contents
1 Introduction 5
2 Aim 5
3 Graph Theory 5
3.1 The Definition of a Graph . . . . . . . . . . . . . . . . . . . . . . 6
3.2 The Adjacency Matrix . . . . . . . . . . . . . . . . . . . . . . . . 6
3.2.1 Unweighted Adjacency Matrix . . . . . . . . . . . . . . . 7
3.2.2 Weighed Adjacency Matrix . . . . . . . . . . . . . . . . . 7
3.3 The Laplacian . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
3.4 Results from Matrix Theory . . . . . . . . . . . . . . . . . . . . . 8
3.4.1 The Gershgorin Circle Theorem . . . . . . . . . . . . . . . 8
3.4.2 Perron-Frobenius Theorem . . . . . . . . . . . . . . . . . 8
6 Discussion 24
References 26
Appendices 27
A Java Application 27
B Matlab Simulations 33
4
3 GRAPH THEORY
1 Introduction
Distributed consensus is a concept that is used in a wide range of applications,
from human decision making to advanced robotic systems. The basic principle
of distributed consensus is that agents in a group communicate with each other
in order to reach a consensus, rather than each agent making decisions for it self
or having a universal source giving instructions to all agents. In more detail,
each agent receives information from a set of other agents in the group. The
agents then adjust their own information state depending on the information
received from other agents with the goal to reach a consensus, an agreement,
amongst all agents in the group. The information that is observed differs from
application to application. In the case of swarming of insects or flocking of
animals, the information of interest is the position and velocity of each agent.
In the example of a network of temperature sensors, the relevant information
would be the measured temperature.
The manner in which each agents information changes depending on the
information input from other agents can be described by a consensus algorithm.
The consensus algorithm varies depending on the application and the model. In
the case of swarming and flocking, the consensus algorithm may be a function
of the position and velocity of each agent. If, additionally, the velocity, position
or acceleration of each agent is given by the consensus algorithm, a model for
the behaviour of agents in flocks or swarms may be obtained.
Graph theory can be used to describe the communication links between the
agents in a group. The graph theory gives support to mathematical analysis of
different consensus algorithms.
2 Aim
The aim of this bachelors thesis is to present a rigorous and thorough inves-
tigation of a certain basic consensus algorithm associated with a non-changing
graph, eventually providing a sufficient requirement for consensus, as well as
considering other consensus algorithms more suitable for modelling of swarms
and flocks and carry out consensus studies of these.
3 Graph Theory
Let us observe a group of agents transferring information between one another
through some sort of connection. The connection between some agents may be
of such nature that information is only sent one way, while other connections
are such that information transfers are sent both ways over that connection.
An example of this is shown in Figure 1, where the arrows represent informa-
tion transfers. In the figure some connections send information both ways and
some are only one-way connections. The layout of the connections, including
the direction of the information transfers, is known as the information trans-
fer topology. One might desire to weigh the information received from certain
agents differently, as the information held by some agents may be of greater
importance or greater reliability than others. A way of describing the informa-
tion transfer topology and the weight of each connection for a network of agents
is through the use of graph theory. We will see that the use of graph theory
5
3 GRAPH THEORY
6
3 GRAPH THEORY
where aij are the elements of the unweighted adjacency matrix or the weighed
adjacency matrix. By this definition, if G is undirected then L is symmetric,
that is, L = LT . Additionally we can provide this valuable property of the
Laplacian.
Theorem 1. Any vector u span(1) where 1 = (1, 1, ..., 1)T Rn satisfies the
equation Lu = 0.
Proof. We have that
u = span(1) = u = 1
For some constant . We then get
Lu = 0 L1 = 0 L1 = 0
since is arbitrary so we must only show the last relation. From the definition
of L we get for the i:th component of L1
X X X
[L1]i = lii + lij = aij + (aij ) = 0.
j6=i j6=i j6=i
7
3 GRAPH THEORY
Then every eigenvalues of A is located in at least one of the discs centred in aii
and with a radius of Ri .
Proof. If is a eigenvalue of A and
Pn is the corresponding eigenvector, then
A = . This can be rewritten as j=1 aij j = i , i which is equivalent to
n
X
aij j = i aii i , i (2)
j=1
j6=i
This means that lies within a disc centred at aii with radius Ri
8
4 LINEAR CONSENSUS IN CONTINUOUS TIME
where xi (t) is the information state of node i at time t with xi (0) being the
initial state of node i. The algorithm can be interpreted as the change of agent
is information being the difference between its own information and the agents
connected to agent is information.
With the laplacian L from (1) one can rewrite the consensus algorithm for
all agents in a more compact form
x = Lx. (3)
9
4 LINEAR CONSENSUS IN CONTINUOUS TIME
S1,k = ek t : LIk
It can be shown that there exists vectors k,m 6= 0 such that with the set
(m )
X
i k t
S2,k = t k,i e : lk > 0 , m {1, 2, . . . , lk }
i=1
10
4 LINEAR CONSENSUS IN CONTINUOUS TIME
since aij 0 and aij R. Thus all of the discs are centred at lii and extend
from the origin to 2lii . The disc corresponding to the largest lii will encircle all
other discs and therefore all eigenvalues of L are contained in the disc centred
at max{lii } with radius max{lii }. Since
X
lii = aij 0
j6=i
the largest disc only encircles points either in the origin or with positive real
parts. Thus all of the eigenvalues corresponding to L are either in the origin or
have positive real parts. This completes the proof.
Theorem 6. If the graph corresponding to L is strongly connected, the eigen-
value k = 0 corresponding to L is a simple eigenvalue.
Proof. First we must prove that the matrix L has an eigenvalue at the origin,
however, this is obvious from Theorem 1. We apply Theorem 3 to the matrix
cI L where I is the identity matrix. If the graph corresponding to L is a
strongly connected graph, then L is an irreducible matrix. It can be shown that
if L is an irreducible matrix, then so is cI L. We choose c large enough so
that cI L is a nonnegative matrix. The theorem then tells us that the largest
eigenvalue of cI L, or equivalently the eigenvalue of L located in the origin,
is simple. If the zero eigenvalue of L is simple, so is the zero eigenvalue of L.
This completes the proof.
11
4 LINEAR CONSENSUS IN CONTINUOUS TIME
Theorem 7. Consider the equation (3). Let the graph G corresponding to the
Laplacian L be strongly connected, then it holds that
i) a consensus is reached for all initial states x(0);
ii) there exists a 6= 0 satisfying T L = 0 and the consensus achieved is
where
T x(0)
= Pn . (6)
i=1 i
Proof.
i) We will begin by showing that the system converges. To use Corollary 1, we
observe that the system (3) is the same as system (4) with M = L. It is clear
from the corollary that if we can show that L has a simple eigenvalue in the
origin and all other eigenvalues have negative real parts, the solution converges.
Equivalently, we can show that L has a simple eigenvalue in the origin and all
other eigenvalues have positive real parts. The fact that all eigenvalues of L have
positive real parts or are located in the origin is provided in Theorem 5. The
fact that the eigenvalue located in the origin is simple is given from Theorem 6.
Thus the requirements in Corollary 1 are met and the system converges.
To show that consensus is achieved, we apply Corollary 1 that states that
the system converges to the one-dimensional nullspace of L. From Theorem
1 we have that a vector belonging to the nullspace of L is 1. If L1 = 0 then
L1 = 0 as well and thus 1 belongs to the nullspace of L as well. Since the
nullspace of L is one-dimensional, the nullspace of L is span(1). Thus the
system converges to 1 for some constant , which means that consensus is
achieved for any initial state x(0).
ii) First we show that there exists a 6= 0 such that
T L = 0
rank(L) = n 1.
rank(L) = n 1 = rank(LT ) = n 1
y(t) = T x(t).
y(t) = T Lx(t) = 0
12
4 LINEAR CONSENSUS IN CONTINUOUS TIME
Thus
lim y(t) = y(0)
t
lim T x(t) = T x(0)
t
1 = T x(0)
T
T x(0)
= Pn .
i=0 i
This completes the proof.
A special case of Theorem 7 can be made for balanced graphs.
Definition 1. A graph G is balanced if
X X
aij = aji i
j6=i j6=i
or in other words, the total weight of all edges entering a node is equal to the
total weight of all edges exiting the node.
Corollary 2. Consider Theorem 7, if the graph G is also balanced the consensus
reached is
lim x(t) = 1 = (, , . . . , )T
t
where
n
1X
= xi (0),
n i=1
i.e, the consensus reached is the average of the initial values.
Proof. From part ii ) of Theorem 7, there exist a satisfying T L = 0 and the
consensus reached depends on . If = 1 we have that
T X X
1 L i= lji = lji + lii .
j j6=i
with
n
T x(0) 1X
= Pn = xi (0), (8)
i=1 i n i=1
thus the corollary is true.
Remark 1. Theorem 7 also holds under the weaker condition that the graph
contains a spanning tree. This is discussed in [5] and its references.
13
5 SWARMS AND FLOCKING
14
5 SWARMS AND FLOCKING
xi (t) = ui
15
5 SWARMS AND FLOCKING
xi (t + d) = xi (t) + d xi (t)
with the discrete time jump d set to 0.001. This equation is an approximation
and is not exact but becoms more accurate for small d. This d will be used
throughout the entire chapter as the results of the simulations should be a
accurate enough within a margin of confidence. An interesting fact that can be
drawn from these plots is that even though the initial positions of the different
simulations are relatively similar and the simulation parameters are identical,
the outcome of the simulations are quite different. Furthermore, most initial
states of the simulations gives a strongly connected graph. Despite the fact
that the graph is strongly connected in the initial state, the simulation of the
agents may not converge to a single location. This implies that a stronger
restriction on the initial states than the initial graph being strongly connected
is required for consensus.
In Figure 6 the percentage of the initial positions that leads to consensus
between all agents on one position is plotted against the maximum radius for a
connection between two agents to be established, r. From the simulations we
can observe a shift around a certain r where most initial states below seem to
not reach consensus but most initial states above do reach consensus. This is
done for different numbers of agents, with less agents a bigger r is needed for
a high probability of the agents to reach consensus. These plots are based on
100 simulations for each value of r, with 0.01 r 0.50 and a step of 0.01
(resulting in a total of 5000 simulations for each plot).
16
5 SWARMS AND FLOCKING
17
5 SWARMS AND FLOCKING
18
5 SWARMS AND FLOCKING
19
5 SWARMS AND FLOCKING
and also grows largely negative as kxi xj k 0. A function that satisfies these
requirements is for example
rd
(x) = 1 .
x2
Our new update function now has the form
X
ui = aij (xj xi )(kxi xj k). (10)
jNi
where the term in the direction of (xi xj ) grows large, that is, away from
node j, which is in accordance with our requirements of the function . Using
this new update law will make to nodes travel towards each other up until
the distance between them is less than rd , they will then repel each other and
eventually they will settle at distance rd from each other. In larger groups of
nodes, a sort of crowding phenomena will appear, where only the nodes in
direct vicinity will be repelling a certain node, whilst the node will be attracted
by other nodes further away than rd , causing the nodes in the large group to
settle at a smaller distance than rd .
5.2.2 Simulations
Examples of simulations with collision avoidance where the agents converges to
one group and thus reaches consensus is shown in Figure 7. Another example
where the agents do not reach consensus and form two different groups can be
observed in Figure 8. These simulations were done with 100 agents spawning in
a circle of radius 0.5 with the radius set to r = 0.3 and rd = 0.01.
In Figure 9 the connection between consensus rate and number of spawning
nodes for a number of simulations can be observed. The nodes are spawned in a
circular area with the radius 0.5 and the maximum distance for communication
between nodes r = 0.3 together with the desired distance between agents rd =
0.01. The plot is based on the results of 100 simulations for each number of
spawning nodes. As expected a higher initial density seems to increase the
probability of convergence.
The second parameter looked at is the maximum distance for a connection
between two agents r. Plots of the relation to the consensus rate can be observed
in Figure 10. The plot is, as before, based on 100 simulations at each r with the
agents spawning in a circle with a radius of 0.5. Another possibility is to keep
the desired distance rd constant when changing the maximum radius r. The
result is interesting as a certain combination of r and rd seem to give a high
convergence rate as seen in Figure 11.
20
5 SWARMS AND FLOCKING
(a) At time 0.001. (b) At time 0.050. (c) At time 0.100. (d) At time 0.150.
(a) At time 0.001. (b) At time 0.050. (c) At time 0.100. (d) At time 0.150.
Figure 8: Plot of consensus between the horizontal and vertical position of a set
of agents. With connections based on distance and collision avoidance.
21
5 SWARMS AND FLOCKING
Figure 10: The percentage of the simulations that reached consensus compared
to the maximum distance for a connection. Based on 100 simulations at each
value of r, with rd = 0.025r.
22
5 SWARMS AND FLOCKING
Figure 11: The percentage of the simulations that reached consensus compared
to the maximum distance for a connection. Based on 100 simulations at each
value of r, with constant rd = 0.01.
5.3 Leaders
Leaders are agents that not only follow the other agents in the group but also
have the desire to move towards a certain target state. In animal flocks this
could correspond to an animal having knowledge about a location with food or
water. A number of leaders can be introduced and an interesting possibility is
to give the connection to leaders a higher weight in order to simulate that the
leaders in the flock are chosen leaders, and therefore the individuals will follow
them more than other individuals.
5.3.2 Simulations
A simulation with 100 agents, of which five were leaders, is shown in Figure
12. The input parameters used were r = 0.3 and rd = 0.01 together with the
23
6 DISCUSSION
6 Discussion
In the first part highly defined rules on convergence for certain algorithms can
be set up, although they are simpler than what is applicable in most real world
scenarios it gives basic understanding to the consensus algorithms used later.
With the more advanced algorithms, relations to the convergence conditions for
simpler consensus algorithms can be made.
Lots of analysis can be done based on the simulations, and as the final
result depends on the random initial state analysis based on large numbers of
simulations are desirable.
Using connections based on the distance between nodes and having collision
avoidance is some of the basic rules that is needed to make the model more
connected to the applications. The agents dependence on the input parame-
ters is generally high, but as the simulations show there are ranges for which
small changes in the configuration increases the probability of convergence by a
significant amount.
More properties can be added and interesting results shows when leaders
that steer the group in a specific direction is added. Other variations could also
be added, such as obstacles that the agents need to avoid.
24
6 DISCUSSION
25
REFERENCES
References
[1] Roger A. Horn and Charles R. Johnson, Matrix analysis, Cambrigde, U.K.:
Cambridge University Press, 1999.
[2] William E. Boyce and Richard C. Diprima, Elementary Differential Equa-
tions and Boundary Value Problems, Eighth Edition, Department of Mathe-
matical Sciences, Rensselaer Polytechnic Institute, John Wiley & Sons Inc,
2005.
[3] Turker Biyikoglu, Josef Leydold and Peter F. Stadler, Laplacian Eigenvec-
tors of Graphs Springer, 2007.
[7] Howard Anton, Chris Rorres, Elementary Linear Algebra with Supplemen-
tial Applications, 10th Edition, International Student Version, Drexel Uni-
versity, University of Pennsylvania, John Wiley & Sons Inc, 2011.
26
A JAVA APPLICATION
A Java Application
A Java Application (shown in Figure 13) was built to easily test the behaviour
of the agents when the input parameters is changed. The application uses the
algorithms described in the report with data from the user. There is also a
possibility to run a program of simulations with pre-specified input parameters
and the results saved to a text file for later usage. An algorithm to determine
if consensus is reached have been implemented.
The significant parts of the code, where the algorithms is implemented, have
been attached. The application and the full source code can be downloaded
from https://sjovall.org/KTH/SA104X-public/sim/javaapp/.
27
A JAVA APPLICATION
public c l a s s Agents {
private int n = 1 0 0 0 ;
public A r r a y L i s t <Point2D . Double> x0 = new A r r a y L i s t <Point2D . Double > ( ) ;
private A r r a y L i s t <Point2D . Double> x S t a r t = new A r r a y L i s t <Point2D . Double > ( ) ;
public double R = 0 . 3 ;
public double d = 0 . 0 0 0 1 ;
private int spawnpattern = 1 ;
private double minR = 0 . 0 1 ;
private boolean f i n i s h e d ;
private double currentTime = 0 ;
private boolean l e a d e r s ;
private int leadersNum = 5 ;
private double l e a d e r s F o l l o w T a r g e t = 1 ;
private double l e a d e r s F o l l o w F l o c k = 0 ;
public boolean i s F i n i s h e d ( ) {
return f i n i s h e d ;
}
public Agents ( ) {
finished = false ;
leaders = false ;
}
28
A JAVA APPLICATION
public void c y c l e ( ) {
A r r a y L i s t <Point2D . Double> dx = new A r r a y L i s t <Point2D . Double > ( ) ;
i f ( minR == 0 ) {
dx = c a l c D i f f B a s i c ( ) ;
} else {
dx = c a l c D i f f M i n D i s t ( ) ;
}
if ( leaders ) {
f o r ( int i = 0 ; i < leadersNum ; i ++) {
Point2D . Double t o T a r g e t = new Point2D . Double (
( t a r g e t . getX ( ) x0 . g e t ( i ) . getX ( ) ) ,
( t a r g e t . getY ( ) x0 . g e t ( i ) . getY ( ) ) ) ;
toTarget . x = toTarget . x / toTarget . distance (0 , 0 ) ;
toTarget . y = toTarget . y / toTarget . distance (0 , 0 ) ;
Point2D . Double newDx = new Point2D . Double (
( l e a d e r s F o l l o w F l o c k dx . g e t ( i ) . getX ( )
+ l e a d e r s F o l l o w T a r g e t t o T a r g e t . getX ( ) ) ,
( l e a d e r s F o l l o w F l o c k dx . g e t ( i ) . getY ( )
+ l e a d e r s F o l l o w T a r g e t t o T a r g e t . getY ( ) ) ) ;
dx . s e t ( i , newDx ) ;
}
}
29
A JAVA APPLICATION
i f ( c o n v e r g e d ( dx ) ) {
f i n i s h e d = true ;
}
}
public boolean i s C o n s e n s u s ( ) {
boolean [ ] b e l o n g 2 g r o u p = new boolean [ x0 . s i z e ( ) ] ;
Arrays . f i l l ( belong2group , f a l s e ) ;
b e l o n g 2 g r o u p [ 0 ] = true ;
// System . o u t . p r i n t l n ( b e l o n g 2 g r o u p . l e n g t h ) ;
b e l o n g 2 g r o u p = inGroup ( belong2group , 0 ) ;
return true ;
}
public int isConsensusNum ( ) {
i f ( isConsensus ( ) ) {
return 1 ;
} else {
return 0 ;
}
}
30
A JAVA APPLICATION
31
A JAVA APPLICATION
dx . add ( d x i ) ;
}
return dx ;
}
public void s e t u p ( ) {
x S t a r t = new A r r a y L i s t <Point2D . Double > ( ) ;
switch ( spawnpattern ) {
case 0 :
f o r ( int i = 0 ; i < n ; i ++) {
x S t a r t . add (new Point2D . Double ( Math . random ( ) , Math . random ( ) ) ) ;
}
break ;
case 1 :
f o r ( int i = 0 ; i < n ; i ++) {
Point2D . Double p = new Point2D . Double ( Math . random ( ) , Math
. random ( ) ) ;
Point2D . Double middle = new Point2D . Double ( 0 . 5 , 0 . 5 ) ;
while ( p . d i s t a n c e ( middle ) > 0 . 5 ) {
p = new Point2D . Double ( Math . random ( ) , Math . random ( ) ) ;
}
x S t a r t . add ( p ) ;
}
break ;
}
restart ();
}
public void r e s t a r t ( ) {
x0 = new A r r a y L i s t <Point2D . Double > ( ) ;
f o r ( int i = 0 ; i < x S t a r t . s i z e ( ) ; i ++) {
x0 . add ( x S t a r t . g e t ( i ) ) ;
}
t h i s . currentTime = 0 ;
finished = false ;
System . out . p r i n t l n ( i s C o n s e n s u s i s + i s C o n s e n s u s ( ) ) ;
}
32
B MATLAB SIMULATIONS
B Matlab Simulations
Early simulations were mostly done in Matlab. The Matlab scripts and
simulink files are located on https://sjovall.org/KTH/SA104X-public/sim/
matlab/.
33