algorithms for the design of stabilizing switching graphs for ......discrete-time switched linear...

128
politecnico di milano Engineering School School of Industrial and Information Engineering Dipartimento di Elettronica, Informazione e Bioingegneria Master of Science in Automation and Control Engineering Algorithms for the Design of Stabilizing Switching Graphs for Discrete-Time Switched Linear Systems Supervisor: prof . fabio dercole Master Graduation Thesis by: luiz alfredo cavalcante lourenco Student Id n. 875934 Academic Year 2017-2018 [ September 7, 2018 at 10:46 – version 1.0 ]

Upload: others

Post on 02-Jan-2021

10 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Algorithms for the Design of Stabilizing Switching Graphs for ......Discrete-Time Switched Linear Systems Supervisor: prof. fabio dercole Master Graduation Thesis by: luiz alfredo

politecnico di milano

Engineering School

School of Industrial and Information Engineering

Dipartimento di Elettronica, Informazione e Bioingegneria

Master of Science in

Automation and Control Engineering

Algorithms for the Design ofStabilizing Switching Graphs for

Discrete-Time Switched Linear Systems

Supervisor:

prof . fabio dercole

Master Graduation Thesis by:

luiz alfredo cavalcante lourenco

Student Id n. 875934

Academic Year 2017-2018

[ September 7, 2018 at 10:46 – version 1.0 ]

Page 2: Algorithms for the Design of Stabilizing Switching Graphs for ......Discrete-Time Switched Linear Systems Supervisor: prof. fabio dercole Master Graduation Thesis by: luiz alfredo

[ September 7, 2018 at 10:46 – version 1.0 ]

Page 3: Algorithms for the Design of Stabilizing Switching Graphs for ......Discrete-Time Switched Linear Systems Supervisor: prof. fabio dercole Master Graduation Thesis by: luiz alfredo

To my loving parents, who have always been there for me

and have helped me overcome countless hurdles.

[ September 7, 2018 at 10:46 – version 1.0 ]

Page 4: Algorithms for the Design of Stabilizing Switching Graphs for ......Discrete-Time Switched Linear Systems Supervisor: prof. fabio dercole Master Graduation Thesis by: luiz alfredo

[ September 7, 2018 at 10:46 – version 1.0 ]

Page 5: Algorithms for the Design of Stabilizing Switching Graphs for ......Discrete-Time Switched Linear Systems Supervisor: prof. fabio dercole Master Graduation Thesis by: luiz alfredo

A C K N O W L E D G M E N T S

I’m thankful for Professor Dercole’s guidance during the course of thiswork and also for his patience with regards to my time constraints asa double degree student.Big thanks also to Professor Della Rossa, for providing the sourcecode of the stability checking algorithms, which helped saving a lot oftime. As well as teaching me how to run my algorithms remotely on aserver.

v

[ September 7, 2018 at 10:46 – version 1.0 ]

Page 6: Algorithms for the Design of Stabilizing Switching Graphs for ......Discrete-Time Switched Linear Systems Supervisor: prof. fabio dercole Master Graduation Thesis by: luiz alfredo

[ September 7, 2018 at 10:46 – version 1.0 ]

Page 7: Algorithms for the Design of Stabilizing Switching Graphs for ......Discrete-Time Switched Linear Systems Supervisor: prof. fabio dercole Master Graduation Thesis by: luiz alfredo

C O N T E N T S

Abstract xiii1 an introduction to discrete-time switched lin-

ear systems 1

1.1 Definition and General Notation 1

1.2 Constrained Switching 1

1.3 Stability 4

1.4 A simple example 6

2 tree-based algorithms for stability analisys 9

2.1 Arbitrary Switching 9

2.2 Arbitrary Switching Example 10

2.3 Constrained Switching 10

2.4 Constrained Switching Example 13

2.5 Choice and computation of the matrix norm 14

3 algorithm design 15

3.1 Stabilizing Algorithm 1 15

3.2 Stabilizing Algorithm 2 16

3.3 Stabilizing Algorithm 3 18

3.4 Stabilizing Algorithm 4 21

4 implementation 25

4.1 Directed Graph Functions from Matlab 25

4.1.1 digraph 25

4.1.2 addnode 25

4.1.3 rmnode 25

4.1.4 addedge 25

4.1.5 rmedge 26

4.1.6 findedge 26

4.1.7 numnodes 26

4.1.8 successors 26

4.1.9 predecessors 26

4.1.10 plot 27

4.2 Other Matlab Functions 27

4.2.1 tic and toc 27

4.2.2 struct 28

4.2.3 DataType12DataType2 28

4.3 User Defined Functions 28

4.3.1 ComputePd (Appendix A.1) 28

4.3.2 ComputeKd (Appendix A.2) 28

4.3.3 ComputeNorm (Appendix A.3) 28

4.3.4 Constrained_Stability (Appendix A.1)) 29

4.3.5 Numerical Precision 29

4.3.6 Arbitrary_Graph (Appendix A.5) 29

4.3.7 Graph_to_Edges (Appendix A.6) 30

4.3.8 Remove_Isolated (Appendix A.7) 30

4.4 Main Algorithms 30

4.4.1 Implementation of Stabilizing Algorithm 1 30

vii

[ September 7, 2018 at 10:46 – version 1.0 ]

Page 8: Algorithms for the Design of Stabilizing Switching Graphs for ......Discrete-Time Switched Linear Systems Supervisor: prof. fabio dercole Master Graduation Thesis by: luiz alfredo

4.4.2 Implementation of Stabilizing Algorithm 2 30

4.4.3 Implementation of Stabilizing Algorithm 3 32

4.4.4 Implementation of Stabilizing Algorithm 4 32

5 test cases 35

5.1 Test Case 1 35

5.2 Test Case 2 38

5.3 Test Case 3 58

5.3.1 Different Edge Choice for Algorithm 2 65

5.4 Hints toward improvement 68

5.5 Test Case 4 70

6 conclusion and future work 73

bibliography 77

a appendix : code listings-user defined functions 81

b appendix : code listings-main algorithms 91

viii

[ September 7, 2018 at 10:46 – version 1.0 ]

Page 9: Algorithms for the Design of Stabilizing Switching Graphs for ......Discrete-Time Switched Linear Systems Supervisor: prof. fabio dercole Master Graduation Thesis by: luiz alfredo

L I S T O F F I G U R E S

Figure 1.1 First Example: A switching graph with threemodes 3

Figure 1.2 Arbitrary switching graph with three modes 3

Figure 1.3 Second Example: Another switching graph withthree modes 5

Figure 1.4 All possible state transitions for the example 7

Figure 1.5 Switching Graph for the example 7

Figure 1.6 Limited state transitions for the example 8

Figure 2.1 Alg. A’s Tree 10

Figure 2.2 Example tree for Alg. A 11

Figure 2.3 Trees for Alg. B 11

Figure 2.4 Unstable Cycle’s State Transition 13

Figure 2.5 Stable Switching Graph 13

Figure 3.1 Example 1-Algorithm 1’s idea. 16

Figure 3.2 Example 2-Algorithm 1’s idea. 16

Figure 3.3 Example 1-Algorithm 2’s idea 18

Figure 3.4 Example 2-Algorithm 2’s idea 19

Figure 3.5 Example 3-Algorithm 2’s idea 20

Figure 3.6 Algorithm 3’s idea 21

Figure 3.7 Algorithm 4’s idea 23

Figure 4.1 Plot function representation 27

Figure 4.2 Arbitrary_Graph Function Example 31

Figure 4.3 Remove_Isolated Example 32

Figure 4.4 Difference between allowing up to nrep or al-most nrep + 1 repetitions 33

Figure 5.1 Test1-Algorithm 1-First Iteration 36

Figure 5.2 Test1-Algorithm 1-Result 36

Figure 5.3 Test1-Algorithm 1, 2 and 3 (nrep = 1)-Result 37

Figure 5.4 Test1-Algorithm 1, 2 and 3 (nrep = 2)-Result 38

Figure 5.5 Test2-Algorithm 1-Second Iteration 39

Figure 5.6 Test2-Algorithm 1-Before Third Iteration 39

Figure 5.7 Test2-Algorithms 1 and 2-Result 40

Figure 5.8 Test2-Algorithms 2, 3 and 4-Second Iteration 40

Figure 5.9 Test2-Algorithm 2-Second Iteration-Remove_Isolated 41

Figure 5.10 Test2-Algorithm 2-Third Iteration 41

Figure 5.11 Test2-Algorithm 2-Third Iteration-Remove_Isolated 42

Figure 5.12 Test2-Algorithm 3-Second Iteration-Remove_Isolated 43

Figure 5.13 Test2-Algorithm 3-Third Iteration 43

Figure 5.14 Test2-Algorithm 3-Third Iteration-Remove_Isolated 44

Figure 5.15 Test2-Algorithm 3-Fourth Iteration 44

Figure 5.16 Test2-Algorithm 3-Fourth Iteration-Remove_Isolated 45

Figure 5.17 Test2-Algorithm 3-Result 45

Figure 5.18 Test2-Algorithm 3 (nrep = 2)-Second Itera-tion 46

ix

[ September 7, 2018 at 10:46 – version 1.0 ]

Page 10: Algorithms for the Design of Stabilizing Switching Graphs for ......Discrete-Time Switched Linear Systems Supervisor: prof. fabio dercole Master Graduation Thesis by: luiz alfredo

Figure 5.19 Test2-Algorithm 3 (nrep = 2)-Second Iteration-Remove_Isolated 46

Figure 5.20 Test2-Algorithm 3 (nrep = 2)-Third Iteration 47

Figure 5.21 Test2-Algorithm 3 (nrep = 2)-Third Iteration-Remove_Isolated 47

Figure 5.22 Test2-Algorithm 3 (nrep = 2)-Fourth Iteration 48

Figure 5.23 Test2-Algorithm 3 (nrep = 2)-Fourth Iteration-Remove_Isolated 48

Figure 5.24 Test2-Algorithm 3 (nrep = 2)-Result 49

Figure 5.25 Test2-Algorithm 4-Second Iteration-Remove_Isolated 49

Figure 5.26 Test2-Algorithm 4-Third Iteration 50

Figure 5.27 Test2-Algorithm 4-Third Iteration-Remove_Isolated 50

Figure 5.28 Test2-Algorithm 4-Fourth Iteration 51

Figure 5.29 Test2-Algorithm 4-Fourth Iteration-Remove_Isolated 51

Figure 5.30 Test2-Algorithm 4-Iteration 5 52

Figure 5.31 Test2-Algorithm 4-Iteration 5-Remove_Isolated 52

Figure 5.32 Test2-Algorithm 4-Iteration 6 53

Figure 5.33 Test2-Algorithm 4-Iteration 6-Remove_Isolated 53

Figure 5.34 Test2-Algorithm 4-Iteration 7 54

Figure 5.35 Test2-Algorithm 4-Iteration 7-Remove_Isolated 54

Figure 5.36 Test2-Algorithm 4-Iteration 8 55

Figure 5.37 Test2-Algorithm 4-Iteration 8-Remove_Isolated 55

Figure 5.38 Test2-Algorithm 4-Iteration 9 56

Figure 5.39 Test2-Algorithm 4-Iteration 9-Remove_Isolated 56

Figure 5.40 Test2-Algorithm 4-Iteration 10 57

Figure 5.41 Test2-Algorithm 4-Iteration 10-Remove_Isolated 57

Figure 5.42 Test2-Algorithm 4-Result 58

Figure 5.43 Test3-Proposed Graph from [28] 58

Figure 5.44 Test3-Algorithm 1-Final Graph 59

Figure 5.45 Test3-Algorithm 1-Time per iteration 60

Figure 5.46 Test3-Algorithm 2-Final Graph 61

Figure 5.47 Test3-Algorithm 2-Amount of nodes 61

Figure 5.48 Test3-Algorithm 2-Time per iteration 62

Figure 5.49 Test3-Algorithm 3-Amount of nodes 62

Figure 5.50 Test3-Algorithm 3-Time per iteration 63

Figure 5.51 Test3-Algorithm 4-Amount of nodes 63

Figure 5.52 Test3-Algorithm 4-Time per iteration 64

Figure 5.53 Test3-Algorithm 2 with different edge choice(nrep = 1)-Result 65

Figure 5.54 Test3-Algorithm 2 with different edge choice(nrep = 3)-Result 66

Figure 5.55 Test3-Algorithm 2 with different edge choice(nrep = 1)-Amount of nodes 66

Figure 5.56 Test3-Algorithm 2 with different edge choice(nrep = 3)-Amount of nodes 67

Figure 5.57 Test3-Algorithm 2 with different edge choice(nrep = 1)-Time per iteration 67

Figure 5.58 Test3-Algorithm 2 with different edge choice(nrep = 3)-Time per iteration 68

Figure 5.59 Test3-New idea-Start 69

x

[ September 7, 2018 at 10:46 – version 1.0 ]

Page 11: Algorithms for the Design of Stabilizing Switching Graphs for ......Discrete-Time Switched Linear Systems Supervisor: prof. fabio dercole Master Graduation Thesis by: luiz alfredo

Figure 5.60 Test3-New idea-Result 1 69

Figure 5.61 Test3-New idea-Result 2 70

Figure 5.62 Test4-Alg. 1 Result 71

Figure 6.1 Future Work Idea 1 74

Figure 6.2 Future Work Idea 2 75

L I S T O F TA B L E S

Table 1.1 Notation Summary for Switched Linear Sys-tems 2

Table 1.2 Notation Summary for Constrained SwitchedLinear Systems 4

Table 1.3 Minimal Switching Sequences 4

L I S T I N G S

Listing A.1 ComputePd 82

Listing A.2 ComputeKd 84

Listing A.3 ComputeNorm 84

Listing A.4 Constrained_Stability 85

Listing A.5 Arbitrary_Graph 88

Listing A.6 Graph_to_Edges 88

Listing A.7 Remove_Isolated 89

Listing B.1 Stabilizing Algorithm 1 in Matlab (Alg. 1) 92

Listing B.2 Stabilizing Algorithm 2 in Matlab (Alg. 2) 94

Listing B.3 Stabilizing Algorithm 3 in Matlab (Alg. 3) 100

Listing B.4 Stabilizing Algorithm 4 in Matlab (Alg. 4) 107

xi

[ September 7, 2018 at 10:46 – version 1.0 ]

Page 12: Algorithms for the Design of Stabilizing Switching Graphs for ......Discrete-Time Switched Linear Systems Supervisor: prof. fabio dercole Master Graduation Thesis by: luiz alfredo

[ September 7, 2018 at 10:46 – version 1.0 ]

Page 13: Algorithms for the Design of Stabilizing Switching Graphs for ......Discrete-Time Switched Linear Systems Supervisor: prof. fabio dercole Master Graduation Thesis by: luiz alfredo

A B S T R A C T

We developed four algorithms, implementing different heuristics, forthe automatic generation of switching graphs that stabilize a givendiscrete-time switched linear system. The algorithms iteratively check(by means of tree-based algorithms recently developed by ProfessorsDercole and Della Rossa) the stability of the system constrained bythe switching graph, that is iteratively modified until a stabilizing so-lution is reached. The procedure starts either from the graph allowingarbitrary switching or from an application-specific graph under whichthe system is unstable.In order to modify the graph, we exploit an important theoreticalresult (due to Professor Dai) that tightly lower bounds the system’sconstrained joint spectral radius—bounding the long-term averagegrowth rate of the system’s trajectories—by looking at the stability ofmatrix products computed along cycles of the switching graph. Thisresult allows us to modify the switching graphs by iteratively cuttingunstable cycles (cycles with unstable matrix product), by preventingin different ways their indefinite repetition. The procedure eventuallyterminates with a graph free of unstable cycles, thus resulting in astable system.The final graphs from all algorithms are either stabilizing, or empty (0nodes). There are, however, important trade-offs between their speedand restrictiveness. The first two algorithms are faster and produceswitching graphs that are more restrictive, while Algorithms 3 and 4

are slower and produce less-restrictive switching graphs; terminationfor the latter algorithms has not been proven yet. Accordingly, thechoice of algorithm should be application driven.In some cases, the resulting switching graph could be improved indifferent ways to fit a given application better, even by adding someof the freedom lost during the heuristic. This can be done manually,by someone with knowledge about the system and using the resultfrom our algorithms as the starting point, or automatically, e.g., byapplying Algorithm 1 or 2 (granting fast termination) starting from alarge (possibly unstable) graph produced by Algorithm 3 or 4.

xiii

[ September 7, 2018 at 10:46 – version 1.0 ]

Page 14: Algorithms for the Design of Stabilizing Switching Graphs for ......Discrete-Time Switched Linear Systems Supervisor: prof. fabio dercole Master Graduation Thesis by: luiz alfredo

S O M M A R I O

In questa tesi sono stati sviluppati quattro algoritmi per la generazioneautomatica di grafi di commutazione che stabilizzino un determinatosistema lineare a commutazione (switched) a tempo discreto. Glialgoritmi modificano iterativamente il grafo di commutazione, control-lando di volta in volta la stabilità del sistema mediante metodi diretti(ad albero di prodotti di matrici) recentemente sviluppati dal gruppodel Professor Dercole ([11] e [12]).La procedura inizia da un grafo assegnato, specifico dell’applicazioneconsiderata o dal grafo che consente la commutazione arbitraria,rispetto al quale il sistema risulta instabile. Per modificare il grafo,sfruttiamo un importante risultato teorico (dovuto al Professor Dai[10]) che mostra come un maggiorante stretto al raggio spettrale con-giunto (joint) del sistema a commutazione vincolata—estremo superi-ore del tasso di crescita medio a lungo termine delle traiettorie—possaessere ottenuto osservando la stabilità dei prodotti di matrici lungoi cicli del grafo di commutazione. Questo risultato ci permette dimodificare il grafo tagliandone iterativamente i cicli instabili (cicli conprodotto di matrici instabile).I quattro algoritmi proposti si differenziano per l’euristica utilizzataa tal fine, essenzialmente per impedire di ripetere indefinitamente ilciclo instabile individuato, con l’obiettivo di terminare con un grafoprivo di cicli instabili, quindi risultante in un sistema a commutazionestabile.I grafi finali di tutti gli algoritmi sono stabilizzanti o vuoti (0 nodi).Vi sono, tuttavia, importanti compromessi tra la loro velocità e lerestrizioni che impongono alla commutazione. I primi due algoritmiproposti sono veloci, ma producano grafi di commutazione severa-mente restrittivi, mentre i due successivi algoritmi impongono menovincoli, permettendo di percorrere i cicli instabili un numero limitatodi volte. Essi richiedono tempi di calcolo maggiori e, per il momento,non abbiamo dimostrato la loro sicura terminazione.La scelta dell’algoritmo più idoneo dipende quindi dalla specificaapplicazione e dal tempo e potenza di calcolo disponibili. In alcunicasi, il grafico di commutazione risultante potrebbe essere miglioratoin modi diversi per adattarsi meglio al caso specifico considerato,anche reintroducendo parte della libertà di commutazione persa conl’euristica dell’algoritmo. Questo può essere fatto manualmente, sec-ondo direttive suggerite dall’applicazione stessa, o automaticamente,per esempio usando in modalità mista gli algoritmi proposti: primal’algoritmo 3 o 4 per arrivare ad un grafo stabilizzante, magari moltogrande, o addirittura fermandosi ad un risultato parziale non stabiliz-zante; poi l’algoritmo 1 o 2 per snellire il grafo e garantire terminazionead un grafo stabilizzante.

xiv

[ September 7, 2018 at 10:46 – version 1.0 ]

Page 15: Algorithms for the Design of Stabilizing Switching Graphs for ......Discrete-Time Switched Linear Systems Supervisor: prof. fabio dercole Master Graduation Thesis by: luiz alfredo

Possibili sviluppi futuri, idee per formalizzare le dimostrazioni diterminazione degli algoritmi 3 e 4, ed approcci complementari sonobrevemente discussi in conclusione di questo lavoro.

xv

[ September 7, 2018 at 10:46 – version 1.0 ]

Page 16: Algorithms for the Design of Stabilizing Switching Graphs for ......Discrete-Time Switched Linear Systems Supervisor: prof. fabio dercole Master Graduation Thesis by: luiz alfredo

1A N I N T R O D U C T I O N T O D I S C R E T E - T I M E S W I T C H E DL I N E A R S Y S T E M S

In this chapter the basic notions on discrete-time switched linearsystems are described. This description focus on the parts that areimportant for the next sections and a more detailed description can befound in [9], [21] and [22]. For basics on linear algebra, [18] and [30].

1.1 definition and general notation

A switched linear system is a system that can change its behavior inaccordance to finite a set of modes, given that each mode is describedby a linear operation (left-multiplication by a matrix) on the system’sstate. Such system is clearly non linear, since different modes are activeat different times, or better considered linear time-varying among afinite set of matrices. We will describe our notation by considering thefollowing discrete-time switched linear system

x(t+ 1) = Aσtx(t), x(1) = x1 (1.1)

where x(t) ∈ Rn and x1 are the current and initial state respectively,σt ∈M = {1, 2, . . . ,m} and σ1 are the current and initial mode of thesystem respectively. The matrix Aσ(t) ∈ A = {A1, . . . , Am} is nxn anddescribes the dynamics of the system at time t, therefore, the stateat time t+ 1 comes from left-multiplying the state x(t) by the matrixmode Aσt .Another way to see Equation (1.1) is the followingx(t+ 1) = Aσx1,

Aσ = AσtAσt−1 . . . Aσ1 .(1.2)

The system described by Equation (1.2) is the (left-)matrix product ofthe system’s matrices applied when following the switching sequenceσ =σ1, σ1, . . . , σt.The switching sequence can be (right-) infinite, assuming σ[l,k], k > las the finite subsequence σ[l,k] =σl, . . . , σk and σ[l,∞] the infinite sub-sequence σ[l,∞] =σl, σl+1, . . . ; we also call σ1σ2, the concatenationof switching sequences σ1 and σ2.Table 1.1 is a summary for the notation described above.

1.2 constrained switching

As said in section Section 1.1, the system follows the switching se-quence σ, such sequence can be arbitrary and these systems receiveda lot of attention in the past (as in [1], [2], [3] and [15]), or it mightfollow some logical rules (constrained switching). In this section we

1

[ September 7, 2018 at 10:46 – version 1.0 ]

Page 17: Algorithms for the Design of Stabilizing Switching Graphs for ......Discrete-Time Switched Linear Systems Supervisor: prof. fabio dercole Master Graduation Thesis by: luiz alfredo

2 an introduction to discrete-time switched linear systems

Symbol Description Dimensions

x(t) State at time t n

x1 Initial state n

σ(t) Mode at time t 1

σ1 Initial mode 1

m Number of modes 1

M Set of modes set with m elements

Aσt System’s matrix at time t nxn

Aσ1 System’s initial matrix nxn

Aσ System’s matrix product nxn

A Set of matrixes set with m elements

σ Switching sequence it’s a set of σt’s

σ1σ2 Concatenation it’s a set of σt’s

Table 1.1: Notation Summary for Switched Linear Systems.

will describe the notation for constrained switching, which is whenthe switching can’t freely change from one mode to another (such asin [1], [5], [10] , [13], [16], [17], [19], [20], [23], [27] and [32] ). We willdenote by Σk and Σ the sets of the corresponding length-k and infiniteswitching sequences.The constraints are represented through directed graphs, being thatwe can either choose the edges or the nodes to represent the system’smodes. We opted to use the edges names to represent the modes,which means the graph’s nodes act just as a memory for the pastmodes.Basically, we have a finite automaton G = (V,E), where G is thedirected graph, V = {1, . . . , V} is the set of nodes and E ⊂ VxVxM theset of edges. Therefore and edge can be seen as the tuple e[v ′,v ′′] =(v ′, v ′′, w[v ′,v ′′]), being v’,v” nodes and w[v ′,v ′′] the respective edge’sweight that represents the system’s mode used to go from node v’ tov”. Sometimes a starting node set S ⊂ V is also considered ([31], [12]),however, for this work we always consider S = V.The Table 1.2 is a summary for the notation described above.In Figure 1.1 we can see a graph that constrains a system with threemodes, a graph that represents arbitrary switching can be seen inFigure 1.2 and another type of switching graph for the same system isshown in Figure 1.3. Basically, in the graph in Figure 1.2 all edges havethe destination node as the label (even the edges from selfloops) andit doesn’t constrain the system whatsoever, which means the systemcan switch between modes freely. Meanwhile, both graphs in Figure1.1 and Figure 1.3, remove possible switching sequences.For the constraining graphs of Figure 1.1 through Figure 1.3, it ispossible to identify a finite set of finite sequences (each correspondingto a specific path in G) that can be arbitrarily concatenated (as wellas the corresponding paths in G) to generate all possible switching

[ September 7, 2018 at 10:46 – version 1.0 ]

Page 18: Algorithms for the Design of Stabilizing Switching Graphs for ......Discrete-Time Switched Linear Systems Supervisor: prof. fabio dercole Master Graduation Thesis by: luiz alfredo

1.2 constrained switching 3

Figure 1.1: A switching graph with three modes.

Figure 1.2: Arbitrary switching graph with three modes.

[ September 7, 2018 at 10:46 – version 1.0 ]

Page 19: Algorithms for the Design of Stabilizing Switching Graphs for ......Discrete-Time Switched Linear Systems Supervisor: prof. fabio dercole Master Graduation Thesis by: luiz alfredo

4 an introduction to discrete-time switched linear systems

Symbol Description

Σk Length-k σ set

Σ Infinite length σ set

V Automata’s node set

v Automata’s node

E Automata’s edge set

e[v ′,v ′′] Automata’s edge from nodes v’ to v”

w[v ′,v ′′] Weight for e[v ′,v ′′](system’s mode)

G Directed Graph

S Automata’s initial node set

Table 1.2: Notation Summary for Constrained Switched Linear Systems

sequences. The sequences are listed in Table 1.3 and are easily identifi-able through the visual inspections of the corresponding graph (thesequences are trivially composed by the single system’s modes forthe graph in Figure 1.2 allowing arbitrary switching). This property ishowever not general of switching graphs.It’s clear from looking at Table 1.3 that in Figure 1.3 the system hasmore freedom than in Figure 1.1, since the concatenations open upmany more possibilities such as the possibility of using mode 2 formore than one step and the possibility of using mode 3 after mode 2.

Graph σ(s)

Figure1.1 σ1 = {1}, σ2 = {3}, σ3 = {21}

Figure1.2 σ1 = {1}, σ2 = {2}, σ3 = {3}

Figure1.3 σ1 = {1}, σ2 = {3}, σ3 = {21}, σ4 = {23},

σ5 = {221}, σ6 = {223}, σ7 = {2221}, σ8 = {2223}

Table 1.3: Minimal Switching Sequences.

1.3 stability

A given finite swiching sequence σ is stable/unstable/contractingdepending on the matrix product’s spectral radius (ρ(Aσ)), whichis the largest modulus among its eigenvalues. Stable, if ρ(Aσ) < 1,unstable if ρ(Aσ) > 1, and a contraction if ||Aσ|| < 1, || · || being amatrix norm.The system described by Equation(1.1) is asymptotically stable if x(t)converges to zero starting from any initial state x1 and following anyswitching sequence σ, this can also be seen as the matrix productconverging to the zero matrix (Aσ → 0). The system is unstable whenthe sequence of states x(t), t >= 1 is unbounded for some x1 and σ,

[ September 7, 2018 at 10:46 – version 1.0 ]

Page 20: Algorithms for the Design of Stabilizing Switching Graphs for ......Discrete-Time Switched Linear Systems Supervisor: prof. fabio dercole Master Graduation Thesis by: luiz alfredo

1.3 stability 5

Figure 1.3: Another switching graph with three modes.

the same can be said if we consider it exponentially unstable, whichhappens when the states are exponentially unbounded.Considering non-asymptotic stability, the state is also bounded for allswitching sequences and initial conditions, but the state does convergeto zero along some sequence starting from some initial condition.Considering non-exponentially instability, no sequence and initialcondition give an exponentially unbounded state, but some give anunbounded state.First, we define a parameter that will be used to determinate asymp-totic stability or exponential instabillity for arbitrary switching sys-tems, the Joint Spectral Radius (JSR) of A (introduced in [29])

JSR(A) = limk→∞ ρk(A), ρk(A) = max

σ∈Mk||Aσ||

1/k. (1.3)

A system is asymptotically stable (exponentially unstable) iff JSR(A)<1(> 1) [15]. When JSR(A)= 1 the system can be Lyapunov stable ornot and this makes the stability problem undecidable. [7]Another important parameter is the Generalized Spectral Radius(GSR)

GSR(A) = lim supk→∞ ρbk(A), ρbk(A) = max

σ∈Mkρ(Aσ)

1/k. (1.4)

The JSR and GSR coincide [14] and

ρbk(A) 6 GSR(A) = JSR(A) 6 ρk(A) (1.5)

is valid for any k. When we have constrained switching, we havesimilar parameters called Constrained Joint Spectral Radius (CJSR)

[ September 7, 2018 at 10:46 – version 1.0 ]

Page 21: Algorithms for the Design of Stabilizing Switching Graphs for ......Discrete-Time Switched Linear Systems Supervisor: prof. fabio dercole Master Graduation Thesis by: luiz alfredo

6 an introduction to discrete-time switched linear systems

and Constrained Generalized Spectral Radius (CGSR). CJSR stillworks as a way to determinate stability or exponential instabillity onsystems

CJSR(A, Σ) = limk→∞ ρk(A, Σ), ρk(A, Σ) = max

σ∈Σk||Aσ||

1/k, (1.6)

CGSR(A, Σ) = lim supk→∞ ρbk(A, Σ), ρ

bk(A, Σ) = max

σ∈Σkρ(Aσ)

1/k, (1.7)

however, the CGSR doesn’t provide a CJSR lower bound anymore (e.g.,stable systems can have unstable modes). According to [10] The CJSRcan be limited instead, by looking at periodic switching sequences

ρb(per)k (A, Σ) = max

σ∈Σ(per)k

ρ(Aσ)1/k, (1.8)

where Σ(per)k is the set of length-k admissable periods. We then have

the Theorem 1.4 from [10] which states that

maxl6k

ρb(per)l (A) 6 JSR(A) = sup

k>1ρb(per)k (A, Σ). (1.9)

1.4 a simple example

As an example, we have a system withm = 2, which means the systemswitches between two different matrices

A1 =

[0.4 0.3

0.2 0.1

], A2 =

[1 0.5

0.5 1

](1.10)

with eigenvalues λ11 = 0.54, λ12 = −0.04 for A1 and λ21 = 0.5,λ22 = 1.5 for A2. This system is unsconstrained, therefore the systemcan alternate modes freely (Arbitrary Switching), for this examplewe will consider first all possibilites in the spam of three steps (23

possibilites). Considering the initial state to be x1 = [1 1] we get thestates from Figure 1.4.However, if instead we have a constraints such as not allowing A2to be used more than three times in a row, such constraints can beseen in the graph of Figure 1.5, this constrain only removes one of thepossibilities in the three-step scenario, the one where A2 is used allthe time. This time the possibilities are shown in Figure 1.6.This hints us that by constraining the system its possible to change itsbehaviour, in ways that may guarantee stability. This will be the typeof strategy that will be put to use in order to force stability into thesystem.

[ September 7, 2018 at 10:46 – version 1.0 ]

Page 22: Algorithms for the Design of Stabilizing Switching Graphs for ......Discrete-Time Switched Linear Systems Supervisor: prof. fabio dercole Master Graduation Thesis by: luiz alfredo

1.4 a simple example 7

Figure 1.4: All possible state transitions for the example.

Figure 1.5: Switching Graph for the example.

[ September 7, 2018 at 10:46 – version 1.0 ]

Page 23: Algorithms for the Design of Stabilizing Switching Graphs for ......Discrete-Time Switched Linear Systems Supervisor: prof. fabio dercole Master Graduation Thesis by: luiz alfredo

8 an introduction to discrete-time switched linear systems

Figure 1.6: Limited state transitions for the example.

[ September 7, 2018 at 10:46 – version 1.0 ]

Page 24: Algorithms for the Design of Stabilizing Switching Graphs for ......Discrete-Time Switched Linear Systems Supervisor: prof. fabio dercole Master Graduation Thesis by: luiz alfredo

2T R E E - B A S E D A L G O R I T H M S F O R S TA B I L I T YA N A L I S Y S

In our work, we use the tree-based algorithms proposed in [11] and[12] to check the stability of discrete-time switched linear systems.First, we describe the algorithm for arbitrary switching, give a simpleexample and then we do the same for the case of constrained switching.We will focus primarly on the algorithms themselves. See [12] for moredetails and proofs.An important property from Alg. B that will be exploited in Chap-ter 3 is the retrieval of an unstable cycle, whenever the system isexponentially unstable. (See more details in Section 2.3.)For simplicity, we will denote a switching graph that stabilizes thesystem as a stable graph, and a switching graph, under which theconstrained system is unstable as an unstable graph. (This is valid forthe following chapters as well.)

2.1 arbitrary switching

The algorithm is the following, seen in Alg. A.

Algorithm A Arbitrary Switchingset the root of T to I set JSRlow = JSR ′up = 0, JSRup = + inf, k = 0

1: while Tk is not empty do JSR ′′up = 0, k ′ = k+ 12: for each A ∈ Tk and Ai ∈ A do3: if ||AiA|| < 1 then4: set JSR ′up = max{||AiA||1/k

′, JSR ′up}

5: else6: set JSR ′′up = max{||AiA||1/k

′, JSR ′′up}

7: add AiA as child of A to Tk ′

8: end if9: set JSRlow = max{ρ(AiA)1/k

′, JSRlow}

10: if JSRlow > 1 then11: set exit=true, break12: end if13: end for14: if exit then15: set k = k ′, return ρ(A) > 116: end if17: set JSRup = min{JSR ′′up, JSRup}, k = k ′

18: end while19: set JSRup = JSR ′up and return ρ(A) < 1

The algorithm creates a tree that keeps expanding (see in more detailbelow) until Tk is empty (stable) or when the lower bound of the JSRis found to be greater than one (unstable). On Figure 2.1 we can see

9

[ September 7, 2018 at 10:46 – version 1.0 ]

Page 25: Algorithms for the Design of Stabilizing Switching Graphs for ......Discrete-Time Switched Linear Systems Supervisor: prof. fabio dercole Master Graduation Thesis by: luiz alfredo

10 tree-based algorithms for stability analisys

Figure 2.1: Alg. A’s Tree

how this expansion works, for a general case with 5 modes, the treestarts with the Identity Matrix and then creates new leaves.After computing the JSR bounds for every leaf, it then creates a newlevel, in which each element is the a mode times the parent. Whenthe norm (||AiA||) for a leaf is less than one, that leaf doesn’t expandanymore. The algorithm terminates when either the k-th level (Tk) ofthe tree is empty (stable) or when one leaf has a lower bound greaterthan one (unstable).Alg. A terminates if and only if the system is either asymptoticallystable or exponentially unstable. (For definitions, check Section 1.3)

2.2 arbitrary switching example

Considering the case of arbitrary switching treated in Section 1.4 andusing sum-of-squares polynomial matrix norms (as seen in Section 2.5),with d = 1 (other norms could be used) we get the tree seen in Figure2.2. It’s worth to highlight the termination of the algorithm when thelower bound for the JSR was computed to be greater than one in thebottom-right leaf (matrix A2). Therefore the system is (exponentially)unstable.

2.3 constrained switching

When the system is under constrained switching, we can rely on thetheretical results from Dai ([10]). By the equality in Equation (1.9) thereare repeatable matrix products Aσ with σ ∈ Σ(per)

k and ρ(Aσ) > 1 iffρ(A, Σ) > 1. Alg. B uses this result to classify a system as exponentially

[ September 7, 2018 at 10:46 – version 1.0 ]

Page 26: Algorithms for the Design of Stabilizing Switching Graphs for ......Discrete-Time Switched Linear Systems Supervisor: prof. fabio dercole Master Graduation Thesis by: luiz alfredo

2.3 constrained switching 11

Figure 2.2: Example tree for Alg. A

Figure 2.3: Trees for Alg. B

unstable whenever there is an unstable cycle (cycle which will updateCJSRlow > 1 and then terminate).The tree structure is similar to the one from Alg. A. The main differ-ences are that Alg. B creates a tree for every node v ∈ V (denoted Tv),and the new leaves have to follow the constraints from the switchinggraph. Therefore, besides having a matrix product A associated toevery leaf, it also has an associated node A.s from the switching graph.A general case can be seen in Figure 2.3, where CJSRlow is onlyupdated whenever a cycle is found. In this case, one of the trees startsfrom node v and computes CSJRlow = max{ρ(A1)1/k

′, CJSRlow} once

it returns to v, while the other tree starts from node y and computesCSJRlow = max{ρ(A3A1)1/k

′, CJSRlow}, once it returns.

Alg. B terminates if and only if the system is either asymptoticallystable or exponentially unstable. (For definitions, check Section 1.3)

[ September 7, 2018 at 10:46 – version 1.0 ]

Page 27: Algorithms for the Design of Stabilizing Switching Graphs for ......Discrete-Time Switched Linear Systems Supervisor: prof. fabio dercole Master Graduation Thesis by: luiz alfredo

12 tree-based algorithms for stability analisys

Algorithm B Constrained Switchingfor each v ∈ V set the root of Tv to I and I.s = vset CJSRlow = CJSR ′up = 0, CJSRup = + inf, k = 0

1: while Tv,k is not empty for all v ∈ V do CJSR ′′up = 0, k ′ = k+ 12: for each v ∈ V, A ∈ Tv,k and (A.s,w, i) ∈ E do3: if ||AiA|| < 1 then4: set CJSR ′up = max{||AiA||1/k

′, CJSR ′up}

5: else6: set CJSR ′′up = max{||AiA||1/k

′, CJSR ′′up}

7: add AiA as child of A to Tv,k ′

8: AiA.s = w9: end if

10: if w = v (the tree returns to the initial node) then11: set CSJRlow = max{(ρ(AiA)1/k

′, CJSRlow)}

12: end if13: if CJSRlow > 1 then14: set exit=true, break15: end if16: end for17: if exit then18: set k = k ′, return ρ(A,Σ) > 119: end if20: set CJSRup = min{CJSR ′′up, CJSRup}, k = k ′

21: end while22: set CJSRup = CJSR ′up and return ρ(A,Σ) < 1

[ September 7, 2018 at 10:46 – version 1.0 ]

Page 28: Algorithms for the Design of Stabilizing Switching Graphs for ......Discrete-Time Switched Linear Systems Supervisor: prof. fabio dercole Master Graduation Thesis by: luiz alfredo

2.4 constrained switching example 13

Figure 2.4: Unstable Cycle’s State Transition

Figure 2.5: Stable Switching Graph

2.4 constrained switching example

We go back to the example from Section 1.4, this time we will considerthe constraints seen in Figure 1.5. It results on instability, detected oncycle [1,2,3,1], which corresponds to following modes [2,2,1]. This isindeed true, if we allow the system to undergo such cycles duringsome time this becomes clear, as seen in Figure 2.4, where the value ofstates x1 and x2 keeps increasing exponentially.If, we don’t allow mode 2 to repeat by constraining the system withthe switching graph of Figure 2.5 we stabilize the system.

[ September 7, 2018 at 10:46 – version 1.0 ]

Page 29: Algorithms for the Design of Stabilizing Switching Graphs for ......Discrete-Time Switched Linear Systems Supervisor: prof. fabio dercole Master Graduation Thesis by: luiz alfredo

14 tree-based algorithms for stability analisys

2.5 choice and computation of the matrix norm

We use sum-of-squares polynomial norms optimized to minimize thelargest norm among the system’s matrices in A ([4], [26]). With poly-nomial degree 2d, d > 1, a sum-of-squares norm of x ∈ Rn is ||x||d =

((||x||(d))TPdx(d))1/(2d) (e.g., the ellipsoid norm ||x||1 = (xTP1x)

1/2

for d = 1 [6]), where Pd is a nd × nd symmetric positive-definitematrix, nd = (n+ d− 1)!/((n− 1)!d!) is the number of monomialsof degree d in the components of x, and x(d) ∈ Rnd lists the mono-mials in a preassigned order defined by an nd × nd fullrank binarymatrix Kd such that Kdx(d) = x⊗d = x⊗ · · · ⊗ x d-times, ⊗ being theKronecker product.The induced matrix norm ||A||d = maxx ||Ax||d/||x||d is the smallest αsolving the Linear Matrix Inequality (LMI)

(A(d))TPdA(d) −α2dPd � 0, (2.1)

where A(d) = (KTdKd)−1KTdA

⊗dKd [8]. The norm is then computed bybisection on α.Optimizing the matrix Pd to minimize maxi ||Ai||d (to be done onlyonce before applying these algorithms) also reduces to α-bisection,while testing for each considered α the feasibility w.r.t. Pd [25] ofthe set of m LMIs (Equation (2.1)), one for each system’s mode. Thefeasibility test is very efficient (interior programming methods) andreturns, when positive, a feasible Pd. The obtained minimum α is aJSR (or CJSR) upper bound that improves for increasing d (thoughit becomes tight for large d only under arbitrary switching). Ourheuristic is to increase d when our algorithms abnormally terminatewithout a decision on stability.

[ September 7, 2018 at 10:46 – version 1.0 ]

Page 30: Algorithms for the Design of Stabilizing Switching Graphs for ......Discrete-Time Switched Linear Systems Supervisor: prof. fabio dercole Master Graduation Thesis by: luiz alfredo

3A L G O R I T H M D E S I G N

In this chapter, we will describe four algorithms for the design ofstabilizing switching graph starting from a given graph (e.g., allow-ing arbitrary switching) under which the system is unstable. Eachalgorithm presents their own heuristic, which are based on breakingunstable cycles obtained from Alg. B (see more details in Section 2.3).By iteratively breaking such cycles, we expect to eventually reach astabilizing switching graph, or an empty switching graph.These algorithms may over-constrain the system to guarantee stability.Some of the stable cycles of the switching graph, those involvingunstable sub-cycles, are removed during the procedures.

3.1 stabilizing algorithm 1

The inequality in Equation (1.9) says that if the system is unstable,then there are unstable periods (i.e. cycles of the switching graph Gwith unstable associated matrix products). These cycles are detectedwith the stability analysis algorithms from Chapter 2 and our idea isto "break" them to stabilize the system.For Alg. 1 we constrain the system with an unstable graph and thenwe iteratively remove an edge that belongs to an unstable cycle untilthe graph becomes stable. The algorithm terminates (considering thestability analysis always terminates), granted that the only act doneis that of removing edges. Therefore, since we start with a finitenumber of edges, it either converges to a stable switching graph or toa switching graph with 0 nodes (G{}).

Algorithm 1 Stabilizing Algorithm 1

set G = arbitrary switching graph{A.c,ρ(A,Σ)} =run Alg. B

while ρ(A,Σ) > 1 doremove one edge of A.c from G (i.e. the first edge)remove all isolated nodesupdate G{A.c,ρ(A,Σ)} = run Alg. B

end whilereturn G

where A.c is the unstable cycle obtained from Alg. B and an isolatednode is a node that misses either outgoing edges or incoming edges.When using Alg. 1 we will mainly cut the first edge of unstablecycles, unless a different choice is mentioned beforehand. As a simpleexample, we can think of a system with 2 modes of operation, withA1 = 0.5 and A2 = 1.3. At first, an arbitrary switching graph with 2nodes is created, but instability is detected for node’s 2 self-cycle. The

15

[ September 7, 2018 at 10:46 – version 1.0 ]

Page 31: Algorithms for the Design of Stabilizing Switching Graphs for ......Discrete-Time Switched Linear Systems Supervisor: prof. fabio dercole Master Graduation Thesis by: luiz alfredo

16 algorithm design

Figure 3.1: Algorithm 1’s idea, where A1 = 0.5 and A2 = 1.3.

Figure 3.2: Algorithm 1’s idea, where A1 = 0.5 and A2 = 3.0.

algorithm removes that edge, the resulting graph stabilizes the system,therefore being the final result, this can be seen in Figure 3.1.However, if A1 = 0.5 and A2 = 3.0 we would end with a single node,as seen in Figure 3.2. This result is trivial and the next algorithms tryto overcome this.

3.2 stabilizing algorithm 2

Alg. 1 is really simple, but it ends up constraining the system toomuch, as seen in Figure 3.1, it never allows the 2nd mode of operationto happen twice or more in a row or in Figure 3.2, where the algorithmterminated on a single node graph. Alg. 2 is another simple algorithm,but that tries to give more freedom to the system by allowing a finitenumber nrep > 1 of repetitions of any detected unstable cycle.

[ September 7, 2018 at 10:46 – version 1.0 ]

Page 32: Algorithms for the Design of Stabilizing Switching Graphs for ......Discrete-Time Switched Linear Systems Supervisor: prof. fabio dercole Master Graduation Thesis by: luiz alfredo

3.2 stabilizing algorithm 2 17

Algorithm 2 Stabilizing Algorithm 2

set G = arbitrary switching graph (with originial nodes){A.c,ρ(A,Σ)} =run Alg. B

while ρ(A,Σ) > 1 doif A.c contains only original nodes then

remove one edge of A.c from G (i.e. the first edge)allow at most nrep repetitions of the cycle, by creating a

chain of nrepT new nodes (replica nodes), where T is the period ofthe cycles (the number of edges), and connect it to the node fromwhich the edge has been removed.

for each edge (v,w, e) not belonging to the cycle from a nodev of the cycle, add (z,w, e) to each replica node z representing nodev in the chain

elseeither cuts the last edge ingoing a replica node of A.c, or cuts

the following edge, which goes to an original node (the type of cuthas to be chosen beforehand)

end ifremove all isolated nodesupdate original nodes (they can also be removed)update G{A.c,ρ(A,Σ)} = run Alg. B

end whilereturn G

When using Alg. 2 we will mainly cut the last edge ingoing a replicanode of A.c. The only cases where we cut the following edge is whensuch is explicitly informed in the description (Section 5.3). In general,cutting the edge ingoing a replica node is equivalent to cutting all thefollowing edges of the replica node, because both isolate the node.Which means the first choice tends to be more restrictive.Following the 2 modes example with A1 = 0.5 and A2 = 1.3, withnrep = 2. At first, an arbitrary switching graph with 2 nodes iscreated, but instability is detected for node’s 2 self-cycle. The algorithmremoves that edge, creating replica nodes 21 and 22, and then copyingthe edges going to 1 from 2. The resulting graph doesn’t stabilize thesystem, detecting instability in A.c = {1, 2, 21, 22, 1}, since it containsreplica nodes, the edge going from 21 to 22 is cut, resulting in a stableswitching graph. This can be seen in Figure 3.3.When A1 = 0.5, A2 = 3.0 and nrep = 2, we get Figure 3.4. Thefirst and second switching graph are the same as the last example,however when the stability is checked with the second graph, a cyclein A.c = {1, 2, 1} is detected instead. Since this cycle doesn’t containreplica nodes, Alg. 2 creates a chain of 4 new nodes, and removingthe edge (1, 2, 2), which isolates 3 nodes (2, 21 and 22). After removingall isolated nodes, the third graph is obtained, from which instabilityis detected for cycle A.c = {1, 23, 11, 24, 12, 1}. This cycle has replicanodes, therefore, edge (24, 12, 1) is removed, leaving nodes 24 and 12

[ September 7, 2018 at 10:46 – version 1.0 ]

Page 33: Algorithms for the Design of Stabilizing Switching Graphs for ......Discrete-Time Switched Linear Systems Supervisor: prof. fabio dercole Master Graduation Thesis by: luiz alfredo

18 algorithm design

Figure 3.3: Algorithm 2’s idea with nrep = 2, A1 = 0.5 and A2 = 1.3

isolated. The isolated nodes are removed and we end with the finalswitching graph.However, when we have A1 = 0.5, A2 = 5.0 and nrep = 1 (to have alower amount of nodes), we also end with a trivial solution, as seen inFigure 3.5.Alg. 2 also always terminates, even though new nodes are created,they are always replica nodes. Whenever we create replica nodes, wealso remove an original edge, and whenever we don’t create replicanodes, we cut edges between replica nodes. Therefore, the numberof replica nodes created is limited by the number of original edges(assuming that the system can only be stable or unstable and Alg. Bterminates) and the heuristic either converges to a stable switchinggraph or to G{}.

3.3 stabilizing algorithm 3

Another algorithm, similiar to Alg. 2 is Alg. 3.The main difference being that this time, even if A.c doesn’t containonly original nodes, it still it allows to repeat a given number nrepof times. Another big difference is that, instead of cutting one edge,and starting the chain from there (as in Alg. 2), it cuts all edges fromthe cycle and builds one chain starting from every node in A.c, thisintroduces less switching constraint.Considering the system A1 = 0.5, A2 = 5.0 and nrep = 1 again. Byrunning Alg. 3, a better result is obtained when compared to thesingle node graph from Figure 3.5. As seen in Figure 3.6, the algorithmcreates 2 chains when detecting a cycle with length 2 in the secondswitching graph instead of a single chain. It also keeps creating chains

[ September 7, 2018 at 10:46 – version 1.0 ]

Page 34: Algorithms for the Design of Stabilizing Switching Graphs for ......Discrete-Time Switched Linear Systems Supervisor: prof. fabio dercole Master Graduation Thesis by: luiz alfredo

3.3 stabilizing algorithm 3 19

Figure 3.4: Algorithm 2’s idea with nrep = 2, A1 = 0.5 and A2 = 3.0

[ September 7, 2018 at 10:46 – version 1.0 ]

Page 35: Algorithms for the Design of Stabilizing Switching Graphs for ......Discrete-Time Switched Linear Systems Supervisor: prof. fabio dercole Master Graduation Thesis by: luiz alfredo

20 algorithm design

Figure 3.5: Algorithm 2’s idea with nrep = 1, A1 = 0.5 and A2 = 5.0

Algorithm 3 Stabilizing Algorithm 3

set G = arbitrary switching graph (with originial nodes){A.c,ρ(A,Σ)} =run Alg. B

while ρ(A,Σ) > 1 doremove all edges of A.c from G

allow at most nrep repetitions of the cycle, by creating a T chainsof nrepT new nodes (replica nodes), where T is the period of thecycles (the number of edges), and connect each chain to the nodefrom which the edge has been removed

for each edge (v,w, e) not belonging to the cycle, with w beingan original nodes and v a node in the cycle, add (z,w, e) to eachreplica node z representing node v in the chain

remove all isolated nodesupdate original nodes (they can also be removed)update G{A.c,ρ(A,Σ)} = run Alg. B

end whilereturn G

[ September 7, 2018 at 10:46 – version 1.0 ]

Page 36: Algorithms for the Design of Stabilizing Switching Graphs for ......Discrete-Time Switched Linear Systems Supervisor: prof. fabio dercole Master Graduation Thesis by: luiz alfredo

3.4 stabilizing algorithm 4 21

Figure 3.6: Algorithm 3’s idea, with A1 = 0.5, A2 = 5.0 and nrep = 1

even when an unstable cycle containing replica nodes (11 and 22) wasdetected in the third switching graph. However, the termination of Alg.3 has yet to be proven (or proven to not happen under all scenarios),unlike for the previous algorithms.

3.4 stabilizing algorithm 4

This last algorithm (Alg. 4) is basically Alg. 3, but every node is treatedas an original node, this change was made to give more freedom tothe system. In other words, we have:The idea is to have even more freedom than in the previous scenario, al-lowing for even more switching sequences. This means, this algorithmmay take even longer to terminate.

[ September 7, 2018 at 10:46 – version 1.0 ]

Page 37: Algorithms for the Design of Stabilizing Switching Graphs for ......Discrete-Time Switched Linear Systems Supervisor: prof. fabio dercole Master Graduation Thesis by: luiz alfredo

22 algorithm design

Algorithm 4 Stabilizing Algorithm 4

set G = arbitrary switching graph{A.c,ρ(A,Σ)} =run Alg. B

while ρ(A,Σ) > 1 doremove all edges of A.c from G

allow at most nrep repetitions of the cycle, by creating a T chainsof nrepT new nodes (replica nodes), where T is the period of thecycles (the number of edges), and connect each chain to the nodefrom which the edge has been removed

for each edge (v,w, e) not belonging to the cycle, with w beingan original node and v a node in the cycle, add (z,w, e) to eachreplica node z representing node v in the chain

remove all isolated nodesall nodes become original nodes (main difference from Alg. 3){A.c,ρ(A,Σ)} = run Alg. B

end whilereturn G

Considering the same example of Section 3.3 and starting from beforethe removal of isolated nodes in the third switching graph, since thesecond switching graph is always the same for Algorithms 3 and 4.By running Alg. 4 we get the procedure seen in Figure 3.7, the stepsshowing isolated nodes were hidden (besides the one before the thirdswitching graph), since the number of nodes becomes really large(for a full similiar example, check Section 5.2). In this algorithm, theedges going into old replica nodes are copied (the algorithm considersall nodes, including replica, from the previous step original), as seen(before the removal of isolated nodes in the third switching graph)in the edge (22,21,2), that doesn’t exist in Figure 3.6. This procedureconstrains the system much less, resulting in a graph that allows formode 2 to happen twice in a row during a switching sequence, insteadof only once.

[ September 7, 2018 at 10:46 – version 1.0 ]

Page 38: Algorithms for the Design of Stabilizing Switching Graphs for ......Discrete-Time Switched Linear Systems Supervisor: prof. fabio dercole Master Graduation Thesis by: luiz alfredo

3.4 stabilizing algorithm 4 23

Figure 3.7: Algorithm 4’s idea, with A1 = 0.5, A2 = 5.0 and nrep = 1

[ September 7, 2018 at 10:46 – version 1.0 ]

Page 39: Algorithms for the Design of Stabilizing Switching Graphs for ......Discrete-Time Switched Linear Systems Supervisor: prof. fabio dercole Master Graduation Thesis by: luiz alfredo

[ September 7, 2018 at 10:46 – version 1.0 ]

Page 40: Algorithms for the Design of Stabilizing Switching Graphs for ......Discrete-Time Switched Linear Systems Supervisor: prof. fabio dercole Master Graduation Thesis by: luiz alfredo

4I M P L E M E N TAT I O N

The implementation was done in Matlab, the code listings are in theappendix.

4.1 directed graph functions from matlab

In here the functions related to digraphs used in the implementationare described.[24]

4.1.1 digraph

The function G = digraph(A), creates a directed graph (G = (V,E))based on a square adjacency matrix (A). The location of each nonzeroentry in A specifies an edge for the graph, and the weight of the edge

is equal to the value of the entry. For example, A =

[1 2

1 2

]results on

an arbitrary switching graph with 2 modes of operation.

4.1.2 addnode

The function G = addnode(G, k) adds k new nodes to the directedgraph G. For example, having G1 = addnode(G, 2) on the 2 modesof operation arbitrary switching graph from the previous subsectionwould result on it having 2 extra nodes without any edges (nodes 3and 4).

4.1.3 rmnode

The function G = rmnode(G, v) removes node v, together with all itsincoming and outgoing edges, from the directed graph G. For example,having G2 = rmnode(G1, 4) on the previous example, would result init having only 1 node without edges (node 3).

4.1.4 addedge

The function G = addedge(G, v,w, e) adds an edge on the directedgraphG coming from v and going tow, with the weight e. For example,having G3 = addedge(G2, 3, 3, 3), on the previous example wouldresult on node 3 having a self-loop with weight 3.

25

[ September 7, 2018 at 10:46 – version 1.0 ]

Page 41: Algorithms for the Design of Stabilizing Switching Graphs for ......Discrete-Time Switched Linear Systems Supervisor: prof. fabio dercole Master Graduation Thesis by: luiz alfredo

26 implementation

4.1.5 rmedge

The function G = rmedge(G, v,w) removes the edge on G comingfrom v and going to w. For example, having G4 = rmedge(G3, 3, 3),on the previous example would result on node 3 having no edgesagain.

4.1.6 findedge

Every edge and node have and identificantion number (ID). Thefunction EID = findedge(G, v,w) finds the ID from an edge in G

that comes from v and goes into w. For example, having EID =

findedge(G4, 2, 2), on the previous example would result on EID = 4.The ID is used to look the weight up in the edges matrix (that containsdata for all edges) and then place the same weight into copied edgesfor replica nodes.

4.1.7 numnodes

The function Num = numnodes(G) returns the total number of nodesin G. Having Num = numnodes(G4), on the previous example wouldresult on Num = 3.

4.1.8 successors

A node v being a successor of a node w means there exists an edge(v,w,•) in the graph. The function SucIDs = successors(G, v) re-turns a list containing all nodes that succeed v. Having SucIDs =

successors(G, 1), on the previous example would result on SucIDs =[1, 2], whereas having SucIDs = successors(G, 3), would return anempty list.

4.1.9 predecessors

A node v being a predecessor of a node w means there exists anedge (w,v,•) in the graph. The function PreIDs = predecessors(G, v)returns a list containing all nodes that preceed v directly. HavingPreIDs = predecessors(G, 1), on the previous example would re-sult on PreIDs = [1, 2], whereas having PreIDs = predecessors(G, 3),would return an empty list.

[ September 7, 2018 at 10:46 – version 1.0 ]

Page 42: Algorithms for the Design of Stabilizing Switching Graphs for ......Discrete-Time Switched Linear Systems Supervisor: prof. fabio dercole Master Graduation Thesis by: luiz alfredo

4.2 other matlab functions 27

Figure 4.1: Plot function representation

4.1.10 plot

It’s possible to directly plot the graph by using the plot function, thereare many parameters that can be changed, such as the color and thesize of the nodes. In Figure 4.1 we can see the results of plotting G,G1, G2, G3 and G4 by using plot(Gk, ′ EdgeLabel ′, Gk.Edges.Weight,′LineWidth ′, 1.5, ′NodeColor ′, ′ y ′, ′MarkerSize ′, 15, ′ArrowSize ′,10, ′ EdgeColor ′, ′ k ′, ′ Layout ′, ′ circle ′). This function makes it easierto visualize how the graph is.

4.2 other matlab functions

4.2.1 tic and toc

tic is used to start a stopwatch timer (CPU time) and toc reads theelapsed time from the stopwatch timer (CPU time) started by the ticfunction. The function reads the internal time at the execution of thetoc command, and displays the elapsed time since the most recent callto the tic function, in seconds. Therefore, in a given script where a ticcommand is executed after 5 seconds, and a toc command after 25

[ September 7, 2018 at 10:46 – version 1.0 ]

Page 43: Algorithms for the Design of Stabilizing Switching Graphs for ......Discrete-Time Switched Linear Systems Supervisor: prof. fabio dercole Master Graduation Thesis by: luiz alfredo

28 implementation

seconds, ’Elapsed time is 20 seconds.’ will be displayed. This is usefulto quickly figure out the script’s bottlenecks.

4.2.2 struct

struct creates a structure array data type that groups related data usingdata containers called fields. The data in each field can be of differenttypes and one can acces the data stored by using dot notation (struct-Name.fieldName). For instance, s[i] = struct( ′mat ′,matrices[i],′v ′, nodeout[i], ′w ′, nodein[i]) could be used as a way to representweightless directed graphs and associate the edges to their respectivematrices, where nodeout and nodein are lists containing informationof origin and destination respectively for every edge.One important scructure used in our work is the tree, which has 4fields, ’mat’, which contains a matrix, ’init’, contains the initial node,’state’, contains the current node and ’memory’, which contains allthe nodes that were in the path from the node in ’init’ to the node in’state’, this structure was used for the implementation of Alg. B.

4.2.3 DataType12DataType2

Many times, data type conversions were needed, such as the table2arraywhich was used to convert G.Edges, that has a table data type to anarray, in order to input information into the tree structure and test G’sstability.

4.3 user defined functions

4.3.1 ComputePd (Appendix A.1)

ComputePd is used to compute Pd. The method for obtaining it is inSection 2.5 and its needed solve Equation (2.1).

4.3.2 ComputeKd (Appendix A.2)

ComputeKd is used to compute the binary matrix Kd. Which is nec-essary for the computation of A(d) which is needed to solve Equation(2.1).

4.3.3 ComputeNorm (Appendix A.3)

ComputeNorm computes the norm of the multiplicative matrices inthe nodes. It solves the LMI of Equation (2.1) for d > 1. There is alsothe option of simply using the largest (absolute) eigenvalue as thenorm, this is done by having the parameter d = 0 instead.

[ September 7, 2018 at 10:46 – version 1.0 ]

Page 44: Algorithms for the Design of Stabilizing Switching Graphs for ......Discrete-Time Switched Linear Systems Supervisor: prof. fabio dercole Master Graduation Thesis by: luiz alfredo

4.3 user defined functions 29

4.3.4 Constrained_Stability (Appendix A.1))

Reproduction of Alg. B, by using the tree structure, it decides wetherthe constrained system is stable or not. It receives as input d, thematrices of the modes, a matrix nedgesx3 containing all edges of thesystem in the form [v, w, e], where nedges is the total number ofedges in the graph.The function returns a flag Stable which describes wether the systemis unstable (0) or stable (1), the upper and lower CSJR bounds anda list called Cycle, which contains the cycle where instability wasdetected, if the system is stable, Cycle is an empty list.Cycle always has the same first and last elements. For example, if anunstable cycle is detected between nodes v and w, Cycle = [vw v] orCycle = [wvw]. Which are different ways to represent the same cycle.

4.3.5 Numerical Precision

For the stability test (ComputePd, CompudeKd, ComputeNorm andConstrained_Stability), we’ve used floating point precision in orderto speed up the calculations. This means that, the stability test isnot correct for any given test, since it approxiamates the calculations,instead of computing it symbolically. However, this was not an issue,since for most tests we used first ordem systems (n = 1), where thefinal results’ stability could be checked manually.One option is to use "arbitrary precision arithmetic", also knownas "variable precision arithmetic", implemented in Matlab with thefunction vpa(x, dig). The idea is to keep the computation of x symbolicand then use function vpa to evaluate each element of x to at least digcorrect significant digits. This would obviously increases the time and(especially) memory requirements of our algorithms. Note, however,that one correct significant digit in the evaluation of the bounds to thesystem’s Constrained Joint Spectral Radius (CJSR) is enough for ourstability test.Another option would be "interval arithmetic", where computationsare kept in floating point precision, but each real is represented by theinterval into which it is guaranteed to be, according to the worst pos-sible under- and over-estimation rounding errors. Interval arithmeticis not internally supported in Matlab, but there are external packageslike b4m (www.ti3.tu-harburg.de/zemke/b4m/). The implementationand test of both options were left for future developments.

4.3.6 Arbitrary_Graph (Appendix A.5)

This function creates arbitrary switching graphs, given a number m ofsystem modes. This is done by building a square adjacency matrix Athat has values equivalent to the column. Which means, the generalform would be:

[ September 7, 2018 at 10:46 – version 1.0 ]

Page 45: Algorithms for the Design of Stabilizing Switching Graphs for ......Discrete-Time Switched Linear Systems Supervisor: prof. fabio dercole Master Graduation Thesis by: luiz alfredo

30 implementation

Am =

1 2 3 . . . m

1 2 3 . . . m

. . . . . . . .

1 2 3 . . . m

(4.1)

By plotting the results of Arbitrary_Graph(3) and Arbitrary_Graph(10),we get the graphs seen in Figure 4.2. Which are clearly arbitrary switch-ing graphs with 3 modes and 10 modes respectively.

4.3.7 Graph_to_Edges (Appendix A.6)

This function takes the edges from a directed graph and converts themto an array data type. Because the main algorithms were built usingthe digraph functions from matlab, in which the edges have the tabledata type, and the Constrained_Stability algorithm edges need to bein array data type.

4.3.8 Remove_Isolated (Appendix A.7)

Removes all isolated nodes and updates the original nodes of a graph.The function follows the logic of repeatedly removing the nodes thatare isolated until there are no more isolated nodes. If one of theremoved nodes is an original node, it then updates the nodes that areconsidered original.The reason why this function repeatedly removes nodes is that oncea node is removed, it might make it so other nodes become isolated.An example is inFigure 4.3, in the first iteration, the algorithm detectsthat node 2 is isolated, then removes it. In the second iteration, detectsthat node 3 is isolated, then removes it. Lastly, the algorithm detectsno isolated nodes and terminates, returning the last graph.

4.4 main algorithms

The algorithms also contain steps to label the nodes, this only affectsthe visualization.

4.4.1 Implementation of Stabilizing Algorithm 1

The implementation of Alg. 1 was pretty straightfoward as can be seenin Appendix B.1.

4.4.2 Implementation of Stabilizing Algorithm 2

The implementation of Alg. 2 (Appendix B.2) was also pretty straight-foward. It contains loops for the reproduction of the removed cycles,

[ September 7, 2018 at 10:46 – version 1.0 ]

Page 46: Algorithms for the Design of Stabilizing Switching Graphs for ......Discrete-Time Switched Linear Systems Supervisor: prof. fabio dercole Master Graduation Thesis by: luiz alfredo

4.4 main algorithms 31

Figure 4.2: Arbitrary_Graph Function Example

[ September 7, 2018 at 10:46 – version 1.0 ]

Page 47: Algorithms for the Design of Stabilizing Switching Graphs for ......Discrete-Time Switched Linear Systems Supervisor: prof. fabio dercole Master Graduation Thesis by: luiz alfredo

32 implementation

Figure 4.3: Remove_Isolated Example

copying the successors from the original nodes. After this is done, itthen removes the isolated nodes, checks the stability and repeats.If there are replica nodes in the unstable cycle, it simply cuts the lastedge before and original node. This is done by simply detecting whereis the edge that goes from one replica node to one original node in thecycle and then cutting it.

4.4.3 Implementation of Stabilizing Algorithm 3

An important detail that differs the implementation of Alg. 3 (Ap-pendix B.3) from the one of Alg. 2 was in the reproduction of theremoved unstable cycles, which is done starting on every node fromthe removed cycle.Since the Cycle obtained from the Constrained_Stability functionhas the same node as first and last element, what is done is the removalof the last element, rotation and adding of new last element for allpossible cycle representations. For example, if Cycle = [1 2 3 4 1] isdetected, it creates Cycle_aux = [1 2 3 4] and then creates the rotations,[1 2 3 4], [2 3 4 1], [3 4 1 2], [4 1 2 3], finally, by copying the first elementinto the end we get the cycles [1 2 3 4 1], [2 3 4 1 2], [3 4 1 2 3], [4 1 2 3 4]

An option to decide wether the cycle will be repeated nrep times oralmost nrep + 1 was also added, where nrep repetitions are allowedand the follwing T − 1 edges are also allowed (T being the number ofedges in the cycle), the difference is shown in Figure 4.4.

4.4.4 Implementation of Stabilizing Algorithm 4

The implementation of Alg. 4 is similar to that of Alg. 3, with theonly difference being that all the nodes from the previous step areconsidered original nodes. It also has the option of allowing up tonrep cycles, or almost nrep + 1 cycles.

[ September 7, 2018 at 10:46 – version 1.0 ]

Page 48: Algorithms for the Design of Stabilizing Switching Graphs for ......Discrete-Time Switched Linear Systems Supervisor: prof. fabio dercole Master Graduation Thesis by: luiz alfredo

4.4 main algorithms 33

Figure 4.4: Difference between allowing up to nrep or almost nrep + 1

repetitions- The left graph contains 2 full repetitions of the cy-cle, while the right graph, contains almost 2 repetitions, by notadding the last node. All edges and nodes that don’t belong tothe reproduced cycle are hidden.

[ September 7, 2018 at 10:46 – version 1.0 ]

Page 49: Algorithms for the Design of Stabilizing Switching Graphs for ......Discrete-Time Switched Linear Systems Supervisor: prof. fabio dercole Master Graduation Thesis by: luiz alfredo

[ September 7, 2018 at 10:46 – version 1.0 ]

Page 50: Algorithms for the Design of Stabilizing Switching Graphs for ......Discrete-Time Switched Linear Systems Supervisor: prof. fabio dercole Master Graduation Thesis by: luiz alfredo

5T E S T C A S E S

This chapter consists of 3 test cases. The first (Section 5.1) and second(Section 5.2) test cases consist on 1-dim (n = 1) systems with 2 modes(m = 2), such systems are much more intuitive, because one can graspits (in)stability by just multiplying the A1 and A2 values. The purposeof these tests are the following:

• Reinforce the differences between the stabilizing algorithms.

• Highlight the differences for different choices of nrep.

• Show that the scripts’ procedures conform to what was expectedin Chapter 3.

• Show the scripts results’ interface (how all graphs appear to theuser)

The third test case (Section 5.3) consists on a 2-dim (n = 2) system,with 4 modes (m = 4) and was taken from the literature of switchedsystems [28].In Section 5.4, we try to highlight potential new procedures that canimprove the results obtained for the system in Section 5.3.Lastly, in the fourth test case (Section 5.5), we will show that termina-tion on an empty graph does not imply there doesn’t exist an suitablestabilizing graph for the system. This will be done by running Alg. 1

and Alg. 2 on a simples system.Edge labels won’t always be shown, especially when the graph hasa large number of nodes, so that the figures are not overloaded. Thisis actually possible because we always start from the graph allowingarbitrary switching , where all edges are in the form (v,w,w) evenwhen v = w (selfloop), therefore we can represent the label as the firstdigit in the pointed node’s label (i.e: all edges going into node 2 . . .will have weight 2). The are exceptions in the final graphs, since theyusually contain fewer nodes and in Section 5.4, where we also showthe edge labels.

5.1 test case 1

The first test case consists on a system with 2 modes of operationgA1 = 0.5 and A2 = 1.2 and d = 0. First, we apply Alg. 1 and, as can beseen in Figure 5.1, an unstable cycle ([2 2]) is detected and thereafter,the edge from this cycle is removed (Figure 5.2), this graph is stableand is taken as the final result.

35

[ September 7, 2018 at 10:46 – version 1.0 ]

Page 51: Algorithms for the Design of Stabilizing Switching Graphs for ......Discrete-Time Switched Linear Systems Supervisor: prof. fabio dercole Master Graduation Thesis by: luiz alfredo

36 test cases

Figure 5.1: Test1-Algorithm 1-First iteration of Alg. 1-Creating the arbitraryswitching graph and detecting instability in the selfloop of node2.

Figure 5.2: Test1-Algorithm 1-The selfloop edge is removed, resulting in thisgraph when running Alg. 1 on the given system.

[ September 7, 2018 at 10:46 – version 1.0 ]

Page 52: Algorithms for the Design of Stabilizing Switching Graphs for ......Discrete-Time Switched Linear Systems Supervisor: prof. fabio dercole Master Graduation Thesis by: luiz alfredo

5.1 test case 1 37

Figure 5.3: Test1-Algorithm 1, 2 and 3 (nrep = 1)-The resulting graph fromrunning Alg. 2, Alg. 3 or Alg. 4 with nrep = 1 on the givensystem, the selfloop cycle is reproduced once.

On the other hand, when we apply Alg. 2, by allowing nrep = 1

and nrep = 2 repetitions of the encountered unstable cycles. Startingfrom Figure 5.1, we get Figure 5.3 (nrep = 1) and Figure 5.4 (nrep =

2). Since this algorithm tries to replicate detected unstable cyclesnrep times, it gives more freedom to the graph, by allowing morecombinations.When Alg. 3 and Alg. 4 are run, they result on the same switchinggraphs as Alg. 2. This is the case since the procedure is exactly thesame when only single-edge unstable cycles are detected. But it’s clearthat the final graph gives more freedom to the system, especially fornrep = 2, in which we can have mode 2 three times in a row, whiletwo times in a row with nrep = 1 and only once with Alg. 1.

[ September 7, 2018 at 10:46 – version 1.0 ]

Page 53: Algorithms for the Design of Stabilizing Switching Graphs for ......Discrete-Time Switched Linear Systems Supervisor: prof. fabio dercole Master Graduation Thesis by: luiz alfredo

38 test cases

Figure 5.4: Test1-Algorithm 1, 2 and 3 (nrep = 2)-The resulting graph fromrunning Alg. 2, Alg. 3 or Alg. 4 with nrep = 2 on the givensystem, the selfloop cycle is repeated twice.

5.2 test case 2

The second test case consists on a similar system, the only differencebeing that we have A2 = 10 (really unstable considering A1 = 0.5) thistime. We also used d = 0 for this case.By using Alg. 1, we start by making an arbitrary switching graph seenin Figure 5.1, an unstable cycle [2 2] is detected and the first edge (onlyedge in this case) is removed. Resulting in the graph from Figure 5.5,on this new graph, the unstable cycle [1 2 1] is detected and the firstedge is removed, as seen in Figure 5.6, node 2 becomes isolated and isremoved. The final graph is in Figure 5.7.If instead, we use Alg. 2 with nrep = 1, we start with the samearbitrary graph (Figure 5.1), in the second iteration(Figure 5.8) theunstable cycle [1 2 1] is detected, the cycle is reproduced (Figure 5.9),producing some isolated nodes, which are removed. On the thirditeration (Figure 5.10) the unstable cycle [1 22 11 1] is detected, sinceit contains replica nodes, the last edge between replica nodes is cut(Figure 5.11), the isolated nodes are removed, resulting in a singlenode with a selfloop (Figure 5.7).

[ September 7, 2018 at 10:46 – version 1.0 ]

Page 54: Algorithms for the Design of Stabilizing Switching Graphs for ......Discrete-Time Switched Linear Systems Supervisor: prof. fabio dercole Master Graduation Thesis by: luiz alfredo

5.2 test case 2 39

Figure 5.5: Test2-Algorithm 1-Second iteration,the selfloop edge is removed,then unstable cycle [1 2 1] is detected.

Figure 5.6: Test2-Algorithm 1-The first edge ([1 2]) is removed, and node2 becomes isolated, this is the Remove_Isolated part of thealgorithm.

[ September 7, 2018 at 10:46 – version 1.0 ]

Page 55: Algorithms for the Design of Stabilizing Switching Graphs for ......Discrete-Time Switched Linear Systems Supervisor: prof. fabio dercole Master Graduation Thesis by: luiz alfredo

40 test cases

Figure 5.7: Test2-Algorithms 1 and 2-After removing the isolated nodes,only node 1 with a selfloop remains.

Figure 5.8: Test2-Algorithm 2 and 2 (nrep = 1) and 3 (nrep = 1) -Seconditeration, the selfloop edge is removed, then unstable cycle [1 2 1]

is detected.

[ September 7, 2018 at 10:46 – version 1.0 ]

Page 56: Algorithms for the Design of Stabilizing Switching Graphs for ......Discrete-Time Switched Linear Systems Supervisor: prof. fabio dercole Master Graduation Thesis by: luiz alfredo

5.2 test case 2 41

Figure 5.9: Test2-Algorithm 2 (nrep = 1)-Second iteration, isolated nodes 2and 21 will be removed.

Figure 5.10: Test2-Algorithm 2 (nrep = 1)-Third iteration detects the unsta-ble cycle [1 22 11 1], which contains replica nodes.

[ September 7, 2018 at 10:46 – version 1.0 ]

Page 57: Algorithms for the Design of Stabilizing Switching Graphs for ......Discrete-Time Switched Linear Systems Supervisor: prof. fabio dercole Master Graduation Thesis by: luiz alfredo

42 test cases

Figure 5.11: Test2-Algorithm 2 (nrep = 1)-Since the cycle had replica nodes,the edge between 11 and 22 is removed, nodes 11 and 22 areisolated.

Next, with Alg. 3 with nrep = 1, we get the graphs of Figure 5.1,Figure 5.8 and from Figure 5.12 through Figure 5.17. The result isdefinitely better than the one from the previous algorithms, which justproduce the trivial result of a node with a selfloop.If we have Alg. 3 with nrep = 2, we end with an slightly better result,where a few more possibilities are allowed. (Figure 5.18-Figure 5.24)Lastly, Alg. 4 with nrep = 1, we get the graphs of Figure 5.1, Figure5.8 and from Figure 5.25 through Figure 5.42. The result (Figure 5.42)ends up being the best so far (as expected), allowing mode 2 to happenonce, or twice in a row.

[ September 7, 2018 at 10:46 – version 1.0 ]

Page 58: Algorithms for the Design of Stabilizing Switching Graphs for ......Discrete-Time Switched Linear Systems Supervisor: prof. fabio dercole Master Graduation Thesis by: luiz alfredo

5.2 test case 2 43

Figure 5.12: Test2-Algorithm 3 (nrep = 1)-Second iteration, isolated nodes2, 21, 12 and 23 will be removed.

Figure 5.13: Test2-Algorithm 3 (nrep = 1)-Third iteration detects the unsta-ble cycle [1 22 11 1].

[ September 7, 2018 at 10:46 – version 1.0 ]

Page 59: Algorithms for the Design of Stabilizing Switching Graphs for ......Discrete-Time Switched Linear Systems Supervisor: prof. fabio dercole Master Graduation Thesis by: luiz alfredo

44 test cases

Figure 5.14: Test2-Algorithm 3 (nrep = 1)-The original edges are replicated,some nodes become isolated.

Figure 5.15: Test2-Algorithm 3 (nrep = 1)-On the fourth iteration, afterremoving the isolated nodes, the algorithm detects the unstablecycle [1 24 13 14 1].

[ September 7, 2018 at 10:46 – version 1.0 ]

Page 60: Algorithms for the Design of Stabilizing Switching Graphs for ......Discrete-Time Switched Linear Systems Supervisor: prof. fabio dercole Master Graduation Thesis by: luiz alfredo

5.2 test case 2 45

Figure 5.16: Test2-Algorithm 3 (nrep = 1)-The cycle was replicated andsome nodes become isolated.

Figure 5.17: Test2-Algorithm 3 (nrep = 1)-The result is a graph with 5 nodesthat forces the system to undergo mode 1 at least four times ina row whenever mode 2 happens.

[ September 7, 2018 at 10:46 – version 1.0 ]

Page 61: Algorithms for the Design of Stabilizing Switching Graphs for ......Discrete-Time Switched Linear Systems Supervisor: prof. fabio dercole Master Graduation Thesis by: luiz alfredo

46 test cases

Figure 5.18: Test2-Algorithm 3 (nrep = 2)-Second iteration,the selfloop edgeis removed, then unstable cycle [1 2 1] is detected.

Figure 5.19: Test2-Algorithm 3 (nrep = 2)-Second iteration, isolated nodes2, 21, 12 and 23 will be removed.

[ September 7, 2018 at 10:46 – version 1.0 ]

Page 62: Algorithms for the Design of Stabilizing Switching Graphs for ......Discrete-Time Switched Linear Systems Supervisor: prof. fabio dercole Master Graduation Thesis by: luiz alfredo

5.2 test case 2 47

Figure 5.20: Test2-Algorithm 3 (nrep = 2)-Third iteration detects the unsta-ble cycle [1 23 11 1].

Figure 5.21: Test2-Algorithm 3 (nrep = 2)-The original edges are replicated,some nodes become isolated.

[ September 7, 2018 at 10:46 – version 1.0 ]

Page 63: Algorithms for the Design of Stabilizing Switching Graphs for ......Discrete-Time Switched Linear Systems Supervisor: prof. fabio dercole Master Graduation Thesis by: luiz alfredo

48 test cases

Figure 5.22: Test2-Algorithm 3 (nrep = 2)-On the fourth iteration, afterremoving the isolated nodes, the algorithm detects the unstablecycle [1 27 15 16 1].

Figure 5.23: Test2-Algorithm 3 (nrep = 2)-The cycle was replicated andsome nodes become isolated.

[ September 7, 2018 at 10:46 – version 1.0 ]

Page 64: Algorithms for the Design of Stabilizing Switching Graphs for ......Discrete-Time Switched Linear Systems Supervisor: prof. fabio dercole Master Graduation Thesis by: luiz alfredo

5.2 test case 2 49

Figure 5.24: Test2-Algorithm 3 (nrep = 2)-The result is a graph with 9 nodesthat forces the system to undergo mode 1 at least three or fourtimes in a row depending on which node the system is at, thisis slightly better than the result for nrep = 1.

Figure 5.25: Test2-Algorithm 4-Iteration 2-The original edges are replicated,some nodes become isolated.

[ September 7, 2018 at 10:46 – version 1.0 ]

Page 65: Algorithms for the Design of Stabilizing Switching Graphs for ......Discrete-Time Switched Linear Systems Supervisor: prof. fabio dercole Master Graduation Thesis by: luiz alfredo

50 test cases

Figure 5.26: Test2-Algorithm 4-Third iteration, after removing the isolatednodes, the algorithm detects an unstable cycle.

Figure 5.27: Test2-Algorithm 4-Iteration 3-The original edges are replicated,some nodes become isolated.

[ September 7, 2018 at 10:46 – version 1.0 ]

Page 66: Algorithms for the Design of Stabilizing Switching Graphs for ......Discrete-Time Switched Linear Systems Supervisor: prof. fabio dercole Master Graduation Thesis by: luiz alfredo

5.2 test case 2 51

Figure 5.28: Test2-Algorithm 4-On the fourth iteration, after removing theisolated nodes, the algorithm detects an unstable cycle.

Figure 5.29: Test2-Algorithm 4-Iteration 4-The original edges are replicated,some nodes become isolated.

[ September 7, 2018 at 10:46 – version 1.0 ]

Page 67: Algorithms for the Design of Stabilizing Switching Graphs for ......Discrete-Time Switched Linear Systems Supervisor: prof. fabio dercole Master Graduation Thesis by: luiz alfredo

52 test cases

Figure 5.30: Test2-Algorithm 4-On iteration 5, after removing the isolatednodes, the algorithm detects an unstable cycle.

Figure 5.31: Test2-Algorithm 4-Iteration 5-The original edges are replicated,some nodes become isolated.

[ September 7, 2018 at 10:46 – version 1.0 ]

Page 68: Algorithms for the Design of Stabilizing Switching Graphs for ......Discrete-Time Switched Linear Systems Supervisor: prof. fabio dercole Master Graduation Thesis by: luiz alfredo

5.2 test case 2 53

Figure 5.32: Test2-Algorithm 4-On iteration 6, after removing the isolatednodes, the algorithm detects an unstable cycle.

Figure 5.33: Test2-Algorithm 4-Iteration 6-The original edges are replicated,some nodes become isolated.

[ September 7, 2018 at 10:46 – version 1.0 ]

Page 69: Algorithms for the Design of Stabilizing Switching Graphs for ......Discrete-Time Switched Linear Systems Supervisor: prof. fabio dercole Master Graduation Thesis by: luiz alfredo

54 test cases

Figure 5.34: Test2-Algorithm 4-On iteration 7, after removing the isolatednodes, the algorithm detects an unstable cycle.

Figure 5.35: Test2-Algorithm 4-Iteration 7-The original edges are replicated,some nodes become isolated.

[ September 7, 2018 at 10:46 – version 1.0 ]

Page 70: Algorithms for the Design of Stabilizing Switching Graphs for ......Discrete-Time Switched Linear Systems Supervisor: prof. fabio dercole Master Graduation Thesis by: luiz alfredo

5.2 test case 2 55

Figure 5.36: Test2-Algorithm 4-On iteration 8, after removing the isolatednodes, the algorithm detects an unstable cycle.

Figure 5.37: Test2-Algorithm 4-Iteration 8-The original edges are replicated,some nodes become isolated.

[ September 7, 2018 at 10:46 – version 1.0 ]

Page 71: Algorithms for the Design of Stabilizing Switching Graphs for ......Discrete-Time Switched Linear Systems Supervisor: prof. fabio dercole Master Graduation Thesis by: luiz alfredo

56 test cases

Figure 5.38: Test2-Algorithm 4-On iteration 9, after removing the isolatednodes, the algorithm detects an unstable cycle.

Figure 5.39: Test2-Algorithm 4-Iteration 9-The original edges are replicated,some nodes become isolated.

[ September 7, 2018 at 10:46 – version 1.0 ]

Page 72: Algorithms for the Design of Stabilizing Switching Graphs for ......Discrete-Time Switched Linear Systems Supervisor: prof. fabio dercole Master Graduation Thesis by: luiz alfredo

5.2 test case 2 57

Figure 5.40: Test2-Algorithm 4-On iteration 10, after removing the isolatednodes, the algorithm detects an unstable cycle.

Figure 5.41: Test2-Algorithm 4-Iteration 10-The original edges are replicated,some nodes become isolated.

[ September 7, 2018 at 10:46 – version 1.0 ]

Page 73: Algorithms for the Design of Stabilizing Switching Graphs for ......Discrete-Time Switched Linear Systems Supervisor: prof. fabio dercole Master Graduation Thesis by: luiz alfredo

58 test cases

Figure 5.42: Test2-Algorithm 4-The result is a graph with 12 nodes thatforces the system to undergo mode 1 at least four times in arow whenever mode 2 happens, or at least seven times whenmode 2 happens twice.

Figure 5.43: Test3-Proposed Graph from [28].

5.3 test case 3

We consider 2-dim case based on [28], where the dynamics of a plantthat may experience controller failures: xt+1 = (A+BKi)xt, with

A =

[0.94 0.56

0.14 0.46

], B =

[0

1

],

and Ki = (k1,i, k2,i). The control gains switch to represent 4 failuremodes. When everything works as expected, i = 1,and K1 = (k1 k2),= (−0.49 0.27), The second and third modes cor-respond respectively to a failure of the first and second part of thecontroller, with K2 = (0, k2) and K3 = (k1, 0). The last mode is the to-tal failure case with K4 = (0, 0). The graph proposed for this problemin [28] can be seen in Figure 5.43.Starting from an arbitrary switching graph for the system (with 4modes). All four algorithms have been tested, Algs. 1 and 2 (nrep = 1)

[ September 7, 2018 at 10:46 – version 1.0 ]

Page 74: Algorithms for the Design of Stabilizing Switching Graphs for ......Discrete-Time Switched Linear Systems Supervisor: prof. fabio dercole Master Graduation Thesis by: luiz alfredo

5.3 test case 3 59

Figure 5.44: Test3-Algorithm 1-Resulting graph for the system described inSection 5.3.

terminated quickly, while Algs. 3 and 4 (nrep = 1) did not terminatefor a long amount of time and all algorithms had d = 6 for the norm.In Subsection 5.3.1, we also use Alg. 2. However, we will cut thefollowing edge instead of the standard one (described in Section 3.2)and will have nrep = 1 and nrep = 3.The final graph, obtained by running Alg. 1 is shown in Figure 5.44,since this algorithm only cuts edges, the amount of nodes can onlygo down, in this case, it keeps the initial amount (4 nodes) during alliterations.Note that A1 and A3 are stable, whereas A2 and A4 are not. Theselfloops of the unstable modes are (obviously) removed, and thatafter mode 2 the graph forces the use of a stable mode (1 or 3), whereasafter mode 4 the graph also allows mode 2. This graph constrainsthe system significantly less than the one from Figure 5.43, in whichtwo failures in a row were assumed not possible for both controllers.However, as seen in Figure 5.44 no matter how many times mode 3happens, which is a failure in the second controller k2, the systemshould remain stable. This is also true for many other paths, such as[4 2] and [4 3], which represents fixing only one controller when bothfailed.The times taken per iteration are in Figure 5.45, there is a comparisonbetween the time taken to run the stability test (Alg. B), which wascalled Stability-Check and the total time spent during the iterationTotal in the figures, it’s clear that running the stability test takes themost time for all iterations.The final graph, obtained by running Alg. 2 also results in a stablesolution, which is shown in Figure 5.46, this graph allows node 4 tohappen twice in a row, instead of only once, as in Figure 5.44. The

[ September 7, 2018 at 10:46 – version 1.0 ]

Page 75: Algorithms for the Design of Stabilizing Switching Graphs for ......Discrete-Time Switched Linear Systems Supervisor: prof. fabio dercole Master Graduation Thesis by: luiz alfredo

60 test cases

Figure 5.45: Test3-Algorithm 1-Comparison between the time taken to runthe stability test (Alg. B) and the total amount of time taken periteration.

amount of nodes per iteration is shown in Figure 5.47 (the nodesconsidered are the ones after all isolated ones have been removed), theamount increases and then descreases as the iterations go by.In Figure 5.48, we can see the time comparison between the total timeand the time allocated for the stability test (Alg. B) per iteration.As seen in Section 3.2, when using Alg. 2, we have two possible choicesAs already mentioned, after a long time(as seen in Figure 5.50, Alg.3 did not terminate, we can see the amount of nodes per iteration inFigure 5.49 and the times in Figure 5.50. Iteration 21, for instance, tookover 40 hours to complete. The same tendencies of having most of thetime alocated for stability-checking prevails.Lastly, we have something similar with running Alg. 4, the amountof nodes and the time per iteration are in Figure 5.51 and Figure 5.52

respectively.

[ September 7, 2018 at 10:46 – version 1.0 ]

Page 76: Algorithms for the Design of Stabilizing Switching Graphs for ......Discrete-Time Switched Linear Systems Supervisor: prof. fabio dercole Master Graduation Thesis by: luiz alfredo

5.3 test case 3 61

Figure 5.46: Test3-Algorithm 2-Resulting graph for the system described inSection 5.3.

Figure 5.47: Test3-Algorithm 2-Total amount of nodes (non-isolated) periteration.

[ September 7, 2018 at 10:46 – version 1.0 ]

Page 77: Algorithms for the Design of Stabilizing Switching Graphs for ......Discrete-Time Switched Linear Systems Supervisor: prof. fabio dercole Master Graduation Thesis by: luiz alfredo

62 test cases

Figure 5.48: Test3-Algorithm 2-Comparison between the time taken to runthe stability test (Alg. B) and the total amount of time taken periteration.

Figure 5.49: Test3-Algorithm 3-Total amount of nodes (non-isolated) periteration.

[ September 7, 2018 at 10:46 – version 1.0 ]

Page 78: Algorithms for the Design of Stabilizing Switching Graphs for ......Discrete-Time Switched Linear Systems Supervisor: prof. fabio dercole Master Graduation Thesis by: luiz alfredo

5.3 test case 3 63

Figure 5.50: Test3-Algorithm 3-Comparison between the time taken to runthe stability test (Alg. B) and the total amount of time taken periteration.

Figure 5.51: Test3-Algorithm 4-Total amount of nodes (non-isolated) periteration.

[ September 7, 2018 at 10:46 – version 1.0 ]

Page 79: Algorithms for the Design of Stabilizing Switching Graphs for ......Discrete-Time Switched Linear Systems Supervisor: prof. fabio dercole Master Graduation Thesis by: luiz alfredo

64 test cases

Figure 5.52: Test3-Algorithm 4-Comparison between the time taken to runthe stability test (Alg. B) and the total amount of time taken periteration.

[ September 7, 2018 at 10:46 – version 1.0 ]

Page 80: Algorithms for the Design of Stabilizing Switching Graphs for ......Discrete-Time Switched Linear Systems Supervisor: prof. fabio dercole Master Graduation Thesis by: luiz alfredo

5.3 test case 3 65

Figure 5.53: Test3-Algorithm 2 with different edge choice (nrep = 1)-Resulting graph for the system described in Section 5.3.

5.3.1 Different Edge Choice for Algorithm 2

When we apply the standard edge cutting (last edge ingoing a replicanode of A.c) with any nrep > 1, we get the switching graph in Figure5.46. However, when we choose the following edge, we obtain Figure5.53 and Figure 5.54 for nrep = 1 and nrep = 3 respectively. Thisresults on a switching graphs that allow more switching sequencespossibilities (in both new cases, mode 2 can repeat twice, while inFigure 5.54, the system mode 4 can repeat up to four times). At sametime, it’s important to note that these repetitions are compensated byforcing the system to not undergo some modes during the chain (i.e.after mode 2 happens twice, the system has to undergo mode 3).The amount of nodes per iteration can be seen in Figure 5.55 (nrep = 1)and Figure 5.56 (nrep = 3) and the elapsed time per iteration canbe seen in Figure 5.57 (nrep = 1) and Figure 5.58 (nrep = 3). It’snoticeable that this edge choice requires more iterations to complete,and it takes longer to terminate, especially when we have a large nrep.

[ September 7, 2018 at 10:46 – version 1.0 ]

Page 81: Algorithms for the Design of Stabilizing Switching Graphs for ......Discrete-Time Switched Linear Systems Supervisor: prof. fabio dercole Master Graduation Thesis by: luiz alfredo

66 test cases

Figure 5.54: Test3-Algorithm 2 with different edge choice (nrep = 3)-Resulting graph for the system described in Section 5.3.

Figure 5.55: Test3-Algorithm 2 with different edge choice (nrep = 1)-Totalamount of nodes (non-isolated) per iteration.

[ September 7, 2018 at 10:46 – version 1.0 ]

Page 82: Algorithms for the Design of Stabilizing Switching Graphs for ......Discrete-Time Switched Linear Systems Supervisor: prof. fabio dercole Master Graduation Thesis by: luiz alfredo

5.3 test case 3 67

Figure 5.56: Test3-Algorithm 2 with different edge choice (nrep = 3)-Totalamount of nodes (non-isolated) per iteration.

Figure 5.57: Test3-Algorithm 2 with different edge choice (nrep = 1)-Comparison between the time taken to run the stability test(Alg. B) and the total amount of time taken per iteration.

[ September 7, 2018 at 10:46 – version 1.0 ]

Page 83: Algorithms for the Design of Stabilizing Switching Graphs for ......Discrete-Time Switched Linear Systems Supervisor: prof. fabio dercole Master Graduation Thesis by: luiz alfredo

68 test cases

Figure 5.58: Test3-Algorithm 2 with different edge choice (nrep = 3)-Comparison between the time taken to run the stability test(Alg. B) and the total amount of time taken per iteration.

5.4 hints toward improvement

An interesting result is obtained when we start from the unstablegraph from iteration 6 of Alg. 3 (Figure 5.59) and then apply Alg.1, obtaining the stabilizing graph in Figure 5.60. In many ways, thisresult is less constraining than the one of Alg. 2, since it allows formode 2 to happen twice in a row. However, in many ways it alsoconstrains more the system, since mode 4 is only allowed to happentwice in a row after the edge (2, 6, 2).The algorithm terminated quickly (in under 5 minutes). However,when we tried to compute Alg. 1 starting from iteration 10, it did notterminate in over 15 hours. The reasons for this were, most likely, thatsome cycles were barely (un)stable and the graph had too many nodes,making the stability test’s tree expand too much.We also tried running Alg. 2 with nrep = 1 on Figure 5.59, it tookroughly 90 minutes to terminate in Figure 5.61, which is strictly betterthan Figure 5.60.These results hint towards a direction to automatically produce bettersolutions. This will be briefly discussed in the next chapter (Chapter6).

[ September 7, 2018 at 10:46 – version 1.0 ]

Page 84: Algorithms for the Design of Stabilizing Switching Graphs for ......Discrete-Time Switched Linear Systems Supervisor: prof. fabio dercole Master Graduation Thesis by: luiz alfredo

5.4 hints toward improvement 69

Figure 5.59: Test3-Starting unstable graph, obtained on iteration 6 of Alg. 3.

Figure 5.60: Test3-Resulting stabilizing graph, by running Alg. 1 on thegraph in Figure 5.59

[ September 7, 2018 at 10:46 – version 1.0 ]

Page 85: Algorithms for the Design of Stabilizing Switching Graphs for ......Discrete-Time Switched Linear Systems Supervisor: prof. fabio dercole Master Graduation Thesis by: luiz alfredo

70 test cases

Figure 5.61: Test3-Resulting stabilizing graph, by running Alg. 2 withnrep = 1 on the graph in Figure 5.59

5.5 test case 4

In order to illustrate that one of the stabilizing algorithms terminatingon an empty graph (see more in Chapter 3) does not imply that thereis no suitable stabilzing graph, we will test our algorithms on thefollowing 2 modes system:

A1 =

[1.1 0

0 0.9

]and A2 =

[0.1 0

0 1.2

].

This time, for simplicity, we will run only the first two algorithms.We then have that Alg. 1 terminates on an empty graph and Alg. 2

with nrep = 1 terminates on a graph with 3 nodes that can be seenin Figure 5.62. Therefore, Alg. 1 terminated on an empty graph eventhough a suitable solution existed. The same can be said for the otheralgorithms.

[ September 7, 2018 at 10:46 – version 1.0 ]

Page 86: Algorithms for the Design of Stabilizing Switching Graphs for ......Discrete-Time Switched Linear Systems Supervisor: prof. fabio dercole Master Graduation Thesis by: luiz alfredo

5.5 test case 4 71

Figure 5.62: Test4-Resulting graph (non-empty) from running Alg. 2 on thesystem.

[ September 7, 2018 at 10:46 – version 1.0 ]

Page 87: Algorithms for the Design of Stabilizing Switching Graphs for ......Discrete-Time Switched Linear Systems Supervisor: prof. fabio dercole Master Graduation Thesis by: luiz alfredo

[ September 7, 2018 at 10:46 – version 1.0 ]

Page 88: Algorithms for the Design of Stabilizing Switching Graphs for ......Discrete-Time Switched Linear Systems Supervisor: prof. fabio dercole Master Graduation Thesis by: luiz alfredo

6C O N C L U S I O N A N D F U T U R E W O R K

Four algorithms were developed in order to design a stabilizing switch-ing graph for a discrete-time switched linear systems. Basically, theidea behind these algorithms is to start from a given graph (i.e. arbi-trary switching graph), detect unstable cycles and then try to limit therepetitions of these cycles to a finite amount of times, while avoidingto modify the graph too much. This may result in a stable switchinggraph, which might not be the best for all applications.Two of these algorithms (Algorithms 1 and 2) are guaranteed to eitherconverge to a stabilizing switching graph or to an empty graph (seemore details in Chapter 3), while the remaining two (Algorithms 3 and4), have not yet been proved to do so, but are expected to do the same,based on the following intution. Longer and longer cycles must containa smaller sub-cycle that is repeated an increasing number of times.Specifically, given a cycle γ of length m, you can identify the sub-cycleof γs of lengthms<m that is repeated consecutively the largest numberof times, say k, within the period of γ, that is γ = (...)(γs)k(...). SinceAlgs. 3 and 4 cut all unstable cycles of progressively increasing length,sooner or later it will be impossible to have longer unstable cycles.Converting this intuition into formal proof will be part of our futureresearch. However, even if the last 2 algorithms were demonstrated toconverge, the time taken for them to terminate might be an issue (asseen in Section 5.3), making the first two (or a mixed approach, seebelow) more practical in many scenarios.Termination on an empty graph does not imply there is no suitablegraph that stabilizes system, especially in the cases of Algs. 1 and 2. Asimple example for Alg. 2 can be seen in Section 5.5. In general, Algs.3 and 4 are expected to rarely terminate on an empty graph (especiallywith large nrep) and whenever they do, it means an stabilizing graphmay be hard to find. However, from the engineering point of view,this might not be very relevant, because with large nrep Algs. 3 and 4

might take too long to terminate.From our tests, it’s noticeable that most of the time is spent in checkingthe system’s stability, which takes longer when the graph becomeslarger and computing the stability takes longer, since the unstablecycles contain more and more nodes. This becomes a problem sinceour algorithms do many ’small’ modifications and have to check thestability at every change, especially on Alg. 3 and Alg. 4 where thenumber of nodes increase in a less restrained fashion.These algorithms can be used to obtain a stabilizing switching graphwhich will be used either directly for a specific application, or as astarting point. Basically, one can analyse the graphs, and then manipu-late them in a way that suits the application the best, instead of usingthe graph directly.

73

[ September 7, 2018 at 10:46 – version 1.0 ]

Page 89: Algorithms for the Design of Stabilizing Switching Graphs for ......Discrete-Time Switched Linear Systems Supervisor: prof. fabio dercole Master Graduation Thesis by: luiz alfredo

74 conclusion and future work

Figure 6.1: Expansion idea for possible future algorithms based on thiswork’s algorithms.

A possible idea for future algorithms on this matter are ones such thatget the results from our proposed algorithms and try to improve theswitching graph by accomodating user preferences, or by giving morefreedom to the switching graph. This can be used to have a betterfinal result, or maybe obtain a good result faster, as seen in Figure 6.1,where Alg. 1 is used to trim the arbitrary switching graph quickly andanother type of algorithm is used to improve the result.These new algorithms could, for example, create modifications thatdon’t require stability checking as often, in order to obtain fasterresults. They could also try to create switching sequences in a ’smarter’way, in Figure 6.1 whenever the system’s mode 2 happens, it has to becompensated by running mode 1 twice, and when mode 2 happenstwice, the system has to run mode 1 three times in a row and so on. Inother words, this new algorithm would start from a stable switchinggraph and then modify it to add more freedom, which is differentfrom our algorithms that start from an unstable switch graph andmodifies it as little as possible until it’s stable.Another possible idea for a new algorithm is one that starts withan intermediate graph (non-stabilizing) of either Alg. 3 or Alg. 4,something similar was done in Subsection 5.4 with Algs. 1 and 2 (thesealgorithms do not necessarily have to be used). However, the iterationfrom which the graph was taken was manually chosen. Therefore thealgorithm would also need some way to decide which iteration to stopAlgs. 3 and 4. Basically, as seen in Figure 6.2, one would run Algs. 3

[ September 7, 2018 at 10:46 – version 1.0 ]

Page 90: Algorithms for the Design of Stabilizing Switching Graphs for ......Discrete-Time Switched Linear Systems Supervisor: prof. fabio dercole Master Graduation Thesis by: luiz alfredo

conclusion and future work 75

Figure 6.2: Reduction idea for possible future algorithms based on thiswork’s algorithms.

or 4 and at some point stop, take the switching graph (which shouldcontain many nodes) and then use some procedure to trim it, whichcould be old (i.e Algs. 1 or 2), or something new.

[ September 7, 2018 at 10:46 – version 1.0 ]

Page 91: Algorithms for the Design of Stabilizing Switching Graphs for ......Discrete-Time Switched Linear Systems Supervisor: prof. fabio dercole Master Graduation Thesis by: luiz alfredo

[ September 7, 2018 at 10:46 – version 1.0 ]

Page 92: Algorithms for the Design of Stabilizing Switching Graphs for ......Discrete-Time Switched Linear Systems Supervisor: prof. fabio dercole Master Graduation Thesis by: luiz alfredo

B I B L I O G R A P H Y

[1] A. A. Agrachev and D. Liberzon. “Lie-algebraic stability criteriafor switched systems.” SIAM Journal on Control and Optimization,vol. 40 (2001), pp. 253–269 (cit. on pp. 1, 2).

[2] A. A. Ahmadi, R. M. Jungers, P. A. Parrilo, and M. Roozbehani.“Joint spectral radius and path-complete graph lyapunov func-tions.” SIAM Journal on Control and Optimization, vol. 52 (2014),pp. 687–717 (cit. on p. 1).

[3] T. Ando and M.-H. Shih. “Simultaneous contractibility.” SIAMJournal on Matrix Analysis and Applications, vol. 19 (1998), pp. 487–498 (cit. on p. 1).

[4] F. Blanchini and S. Miani. “Set-theoretic methods in control.”Springer, (2008) (cit. on p. 14).

[5] P.-A. Bliman and G. Ferrari-Trecate. “Stability analysis of discrete-time switched systems through lyapunov functions with non-minimal state.” In Proceedings of IFAC conference on the analysisand design of hybrid systems, (2003), pp. 325–330 (cit. on p. 2).

[6] V. D. Blondel, Y. Nesterov, and J Theys. “On the accuracy ofthe ellipsoid norm approximation of the joint spectral radius.”Linear Algebra and Its Applications, vol. 394 (2005), pp. 91–107

(cit. on p. 14).

[7] V. D. Blondel and J. N. Tsitsiklis. “The boundedness of all prod-ucts of a pair of matrices is undecidable.” Systems & ControlLetters, vol. 41 (2000), pp. 135–140 (cit. on p. 5).

[8] G. Chesi, P. Colaneri, J. C. Geromel, R. Middleton, and R. Shorten.“A nonconservative LMI condition for stability of switched sys-tems with guaranteed dwell time.” IEEE Transactions on Auto-matic Control, vol. 57 (2012), pp. 1297–1302 (cit. on p. 14).

[9] P. Colaneri. Analysis and Control of Linear Switched Systems. http://home.deib.polimi.it/colaneri/SW.pdf. Online LectureNotes, Accessed: 2018-06-15. 2009 (cit. on p. 1).

[10] X. Dai. “Robust periodic stability implies uniform exponentialstability of markovian jump linear systems and random linearordinary differential equations.” Journal of The Franklin Institute,vol. 351 (2014), pp. 2910–2937 (cit. on pp. xiv, 2, 6, 10).

[11] F. Dercole and F. Della Rossa. “A simple tree-based algorithm fordeciding the stability of discrete-time switched linear systems.”In Proceedings of the 56th IEEE Conference on Decision and Control,(2017) (cit. on pp. xiv, 9).

[12] F. Dercole and F. Della Rossa. “Tree-based algorithms for thestability of discrete-time switched linear systems under arbi-trary and constrained switching.” IEEE Transactions on AutomaticControl (2018). (to appear) (cit. on pp. xiv, 2, 9).

77

[ September 7, 2018 at 10:46 – version 1.0 ]

Page 93: Algorithms for the Design of Stabilizing Switching Graphs for ......Discrete-Time Switched Linear Systems Supervisor: prof. fabio dercole Master Graduation Thesis by: luiz alfredo

78 bibliography

[13] R. Essick, J. W. Lee, and G. E. Dullerud. “Control of linearswitched systems with receding horizon modal information.”IEEE Transactions on Automatic Control, vol. 59 (2014), pp. 2340–2352 (cit. on p. 2).

[14] L. Gurvits. “Stability of discrete linear inclusion.” Linear Algebraand Its Applications, vol. 231 (1995), pp. 47–85 (cit. on p. 5).

[15] R. Jungers. “The joint spectral radius.” Springer, vol. 385 (2009)(cit. on pp. 1, 5).

[16] V. Kozyakin. “The Berger–Wang formula for the Markovianjoint spectral radius.” Linear Algebra and its Applications, vol. 448

(2014), pp. 315–328 (cit. on p. 2).

[17] A. Kundu and D. Chatterjee. “Stabilizing switching signals forswitched systems.” IEEE Transactions on Automatic Control, vol.60 (2015), pp. 882–888 (cit. on p. 2).

[18] D. C. Lay, S. R. Lay, and J. J. McDonald. “Linear Algebra and ItsApplications.” Pearson, Classics illustrated , 5th Edition (2016)(cit. on p. 1).

[19] J.-W. Lee and G. E. Dullerud. “Optimal disturbance attenua-tion for discretetime switched and Markovian jump linear sys-tems.” SIAM Journal on Control and Optimization, vol. 45 (2006),1329–1358 (cit. on p. 2).

[20] J.-W. Lee and G. E. Dullerud. “Uniform stabilization of discrete-time switched and Markovian jump linear systems.” Automatica,vol. 42 (2006), 205–218 (cit. on p. 2).

[21] D. Liberzon. Switching in Systems and Control. Birkhauser, 2003

(cit. on p. 1).

[22] D. Liberzon and A. S. Morse. “Basic problems in stability anddesign of switched systems.” IEEE Control Systems Magazine vol.19 (1999), pp. 59–70 (cit. on p. 1).

[23] H. Lin and P. J. Antsaklis. “Stability and stabilizability of switchedlinear systems: a survey of recent results.” IEEE Transactions onAutomatic Control, vol. 54 (2009), 308–322 (cit. on p. 2).

[24] Matlab Online Documentation. https://it.mathworks.com/help/matlab/ref/digraph.html. Accessed: 2018-06-15 (cit. on p. 25).

[25] Y. Nesterov and A. Nemirovskii. “Interior-point polynomialalgorithms in convex programming.” SIAM, (1994) (cit. on p. 14).

[26] P. A. Parrilo and A. Jadbabaie. “Approximation of the jointspectral radius using sum of squares.” Linear Algebra and ItsApplications, vol. 428 (2008), pp. 2385–2402 (cit. on p. 14).

[27] M. Philippe and R. M. Jungers. “A sufficient condition for theboundedness of matrix products accepted by an automaton.” InProceedings of the 18th international conference on hybrid systems:Computation and control, (2015), pp. 51–57 (cit. on p. 2).

[ September 7, 2018 at 10:46 – version 1.0 ]

Page 94: Algorithms for the Design of Stabilizing Switching Graphs for ......Discrete-Time Switched Linear Systems Supervisor: prof. fabio dercole Master Graduation Thesis by: luiz alfredo

bibliography 79

[28] M. Philippe, R. Essick, G. E. Dullerud, and R. M. Jungers. “Stabil-ity of discrete-time switching systems with constrained switch-ing sequences.” Automatica, vol. 72 (2016), pp. 242–250 (cit. onpp. 35, 58).

[29] G. C Rota and W. Strang. “A note on the joint spectral radius.” InProceedings of the Netherlands Academy, vol. 22 (1960), pp. 379–381

(cit. on p. 5).

[30] G. Strang. “Introduction to Linear Algebra.” Wellesley-CambridgePress and SIAM, 5th Edition (2016) (cit. on p. 1).

[31] Y. Wang, N. Roohi, G. E. Dullerud, and M. Viswanathan. “Sta-bility analysis of switched linear systems defined by regularlanguages.” IEEE Transactions on Automatic Control, vol. 62 (2017),pp. 2568–2575 (cit. on p. 2).

[32] Y. Wang, N. Roohi, G.E. Dullerud, and M. Viswanathan. “Sta-bility of linear autonomous systems under regular switchingsequences.” In Proceedings of the 53rd IEEE conference on decisionand control (2014), pp. 5445–5450 (cit. on p. 2).

[ September 7, 2018 at 10:46 – version 1.0 ]

Page 95: Algorithms for the Design of Stabilizing Switching Graphs for ......Discrete-Time Switched Linear Systems Supervisor: prof. fabio dercole Master Graduation Thesis by: luiz alfredo

[ September 7, 2018 at 10:46 – version 1.0 ]

Page 96: Algorithms for the Design of Stabilizing Switching Graphs for ......Discrete-Time Switched Linear Systems Supervisor: prof. fabio dercole Master Graduation Thesis by: luiz alfredo

AA P P E N D I X : C O D E L I S T I N G S - U S E R D E F I N E DF U N C T I O N S

All codes from user-defined functions are in this appendix, thesefunctions descriptions can be found in Section 4.3.

81

[ September 7, 2018 at 10:46 – version 1.0 ]

Page 97: Algorithms for the Design of Stabilizing Switching Graphs for ......Discrete-Time Switched Linear Systems Supervisor: prof. fabio dercole Master Graduation Thesis by: luiz alfredo

82 appendix

Listing A.1: ComputePd

1 function [P,norm,Kd,res,A]=ComputePd(A,d,norm0,toll)

2 if nargin==0

3 rng( ’ shuffle ’)4 N=5;

5 m=3;

6 d=4;

7 A=rand(N,N,m);

8 norm0=1;

9 toll=1e-4;

10 elseif nargin==2

11 norm0=1;

12 toll=1e-6;

13 end

14 if iscell(A)

15 m=length(A);

16 N=length(A{1});

17 Amat=zeros(N,N,m);

18 for mat=1:m

19 Amat(:,:,mat)=A{mat};

20 end

21 A=Amat;

22 end

23 N=size(A,1); m=size(A,3);

24 Kd=computeKd(N,d);

25 for matrice=1:m

26 P=A(:,:,matrice);

27 for grado=2:d

28 P=kron(P,A(:,:,matrice));

29 end

30 A2(:,:,matrice)=(Kd’*Kd)\Kd’*P*Kd;

31 end

32 A=A2;

33 N=size(A2,1);

34 nmin=0;

35 tmin=1; �

[ September 7, 2018 at 10:46 – version 1.0 ]

Page 98: Algorithms for the Design of Stabilizing Switching Graphs for ......Discrete-Time Switched Linear Systems Supervisor: prof. fabio dercole Master Graduation Thesis by: luiz alfredo

appendix 83

1 while tmin>0

2 setlmis([]);

3 P=lmivar(1,[N 1]);

4 lmiterm([1 1 1 P],-1,1);

5 lmiterm([1 1 1 0],1);

6 for i=1:m

7 lmiterm([i+1 1 1 P],A(:,:,i)’,A(:,:,i));

8 lmiterm([i+1 1 1 P],-norm0^2,1);

9 end

10 lmis=getlmis;

11 tmin=feasp(lmis,[0,0,0,0,1],0);

12 if tmin>0, nmin=norm0; norm0=2*norm0; end

13 end

14 while norm0-nmin>toll

15 norm=(nmin+norm0)/2;

16 setlmis([]);

17 P=lmivar(1,[N 1]);

18 lmiterm([1 1 1 P],-1,1);

19 lmiterm([1 1 1 0],1);

20 for i=1:m

21 lmiterm([i+1 1 1 P],A(:,:,i)’,A(:,:,i));

22 lmiterm([i+1 1 1 P],-norm^2,1);

23 end

24 lmis=getlmis;

25 [tmin,xfeas]=feasp(lmis,[0,0,0,0,1],0);

26 if tmin>0, nmin=norm; else norm0=norm; end

27 end

28 norm=(nmin+norm0)/2;

29 P=dec2mat(lmis,xfeas,P);

30 res=zeros(m,1);

31 for i=1:m

32 res(i)=max(eig(A(:,:,i)’*P*A(:,:,i)-norm^2*P));

33 end �

[ September 7, 2018 at 10:46 – version 1.0 ]

Page 99: Algorithms for the Design of Stabilizing Switching Graphs for ......Discrete-Time Switched Linear Systems Supervisor: prof. fabio dercole Master Graduation Thesis by: luiz alfredo

84 appendix

Listing A.2: ComputeKd

1 function Kd=computeKd(n,d)

2 Kd=zeros(n^d,nchoosek(n+d-1,n-1));

3 for i=1:n^d % per ogni riga

4 ds=dec2base(i-1,n,d);

5 dd=zeros(1,n);

6 % calcolo la potenza di ciascuna x

7 for ddj=0:n-1

8 s=dec2base(ddj,n);

9 dd(ddj+1)=sum(ds==s);

10 end

11 % trovo la colonna in cui mettere l’1

12 j=1;

13 topindex=d;

14 for livello=0:n-2

15 for k=(dd(livello+1)+1):topindex

16 j=j+nchoosek(n-1-livello+topindex-k-1,n-1-

livello-1);

17 end

18 topindex=topindex-dd(livello+1);

19 end

20 Kd(i,j)=1;

21 end �

Listing A.3: ComputeNorm

1 function gg=ComputeNorm(A,P,d,Kd)

2 if d==0

3 gg=max(svd(A));% for d equal to 0 gets biggest eigenvalue.

4 return

5 end

6 Ad=A;

7 for grado=2:d

8 Ad=kron(Ad,A);

9 end

10 A=(Kd’*Kd)\Kd’*Ad*Kd;

11 setlmis([])

12 g = lmivar(1,[1,0]); % g scalar

13 lmiterm([1,1,1,0],A’*P*A)

14 lmiterm([1,1,1,g],-1,P)

15 lmiterm([1,2,2,g],-1,1)

16 lmisys = getlmis;

17 c=1;

18 gg=mincx(lmisys,c,[0,0,0,0,1],[],[]); �

[ September 7, 2018 at 10:46 – version 1.0 ]

Page 100: Algorithms for the Design of Stabilizing Switching Graphs for ......Discrete-Time Switched Linear Systems Supervisor: prof. fabio dercole Master Graduation Thesis by: luiz alfredo

appendix 85

Listing A.4: Constrained_Stability

1 function [Stable,JSRl,JSRu,Cycle]=Constrained_Stability(matrices,

edges,d)

2 Cycle=[];

3 tic % to measure elapsed time, toc used to measure time elapsed

between tic and toc.

4 JSRl=0;%CJSRlow

5 JSRu=Inf;%CJSRup

6 JSRu1=0;%CJSRup’

7

8 if d~=0

9 [PP,gg,Kd] = ComputePd(matrices,d);

10 else

11 PP=[]; Kd=[];

12 end

13

14 totEdges=length(edges(:,1));

15 totStates=max(edges(:,1));

16 edgesState={};

17 for state=1:totStates

18 edgeState{state}=edges(edges(:,1)==state,:,:);% for each

state, decides which edges it has, for instance, for

state 1 could have edges 1 1 1 1 2 2

19 end

20 howmanyedgeState=cellfun( ’ size ’,edgeState,1);%applies function

size to every cell in the edgeState tuple, how many edges per

state.

21 N=1;%depth 1 on the trees

22 flag=0;%I added this flag to not have problems when tree is empty

23 for i=1:totEdges

24 Vi=ComputeNorm(matrices{edges(i,3)},PP,d,Kd);%value of the

initial state norm, the 3rd column is Ai, 1st/2nd column

S0/S1

25 if Vi>1

26 tree(i)=struct( ’mat ’,matrices{edges(i,3)}, ’ in i t ’,edges(i,1), ’ state ’,edges(i,2), ’memory’,[edges(i,1),edges(i,2)]);% stato da cui sono partito, stato in cui arrivo

27 % Basically, tree is a list of tuples when Vi>1.

28 flag=1;

29 end

30 M=matrices{edges(i,3)};

31 rhoM=max(abs(eig(M)));

32 if rhoM>=1

33 if edges(i,1)==edges(i,2)

34 Cycle=[edges(i,1),edges(i,2)];

35 Stable=0; �

[ September 7, 2018 at 10:46 – version 1.0 ]

Page 101: Algorithms for the Design of Stabilizing Switching Graphs for ......Discrete-Time Switched Linear Systems Supervisor: prof. fabio dercole Master Graduation Thesis by: luiz alfredo

86 appendix

1 %stringa=sprintf(’Al passo %d ho trovato una matrice

instabile.’,N);

2 %fprintf([stringa, ’\n’]);

3 %fprintf(’The max(abs(eig(M))) is %d ,its a self

cycle’,rhoM);

4 toc

5 return;

6 end

7 end

8 end

9 if flag==1

10 tree=tree(~cellfun( ’isempty ’,{tree.state}));%removes the

empty cells(ones where Vi<1)

11 end

12 if flag==0

13 tree=[];

14 end

15 %

16 %%

17 mult=0;

18 while ~isempty(tree)

19 N=N+1;%depth+1(depth 1 previously analysed, so its added in

loop’s start)

20 %fprintf(’\n%d iteration, %d leafs\n’,N,length(tree))%length

of tree is the number of leaves left.

21 if length(tree)>1e8

22 error( ’Too many leafs : increase d’);% this is for the

case where we add too many leafs, would be good to

change the norm

23 end

24 treeold=tree;%memorize the leaves

25 % Inizializzazione dello step

26 JSRu2=0;%CJSRup’’=0

27 NMatNewLevel=[0,cumsum(howmanyedgeState(cell2mat({tree(:).

state})))];%cell to matrix of the leaves states, then

makes a vector with the number of edges per state and

does the cumulative sum.

28 %the cumulative sum consists of a vector containing the sum

of the

29 %previous values from the vector of size(tree) and values

equal to

30 %number of edges per state from tree

31 mult=mult+NMatNewLevel(end);%this is basically an estimation

of the number of edges coming from the new level states,

added with that of previous levels

32 tree=struct( ’mat ’,num2cell(zeros(NMatNewLevel(end),1)), ’ in i t ’,0, ’ state ’,0, ’memory’,0);%Using the estimated number of

new tree branches, we do a tree with zeros

33 for indice=1:length(tree)% for all in the lenth of tree(going

through all leaves new, old_leaf 1 is parent for 2

leaves, thats the logic...)

34 j=sum(NMatNewLevel<indice);

35 %j is the number of elements of NMatNewLevel smaller than

indice(including 0), it represents a leaf �

[ September 7, 2018 at 10:46 – version 1.0 ]

Page 102: Algorithms for the Design of Stabilizing Switching Graphs for ......Discrete-Time Switched Linear Systems Supervisor: prof. fabio dercole Master Graduation Thesis by: luiz alfredo

appendix 87

1 i=indice-NMatNewLevel(j); % identifico l’edge da usare

2 %i is indice minus the biggest element in NMatNewLevel<

indice, its normally the number of the edges(possible

types of Ai)

3 try%normally, only the statements between the try and

CATCH are executed. However, if an error occurs while

executing any of the statements, the error is

captured into an object, and the

4 %statements between the CATCH and END are executed.

5 curr_edge=edgeState{treeold(j).state}(i,:);%gets edge ’i’

from the edges of the old state of leaf ’j’

6 %returns the current edge, revise this part later(

shouldnt be essential to understand)/\

7 catch

8 keyboard

9 end

10 M=matrices{curr_edge(3)}*treeold(j).mat;%M is Ai*A, where

A is mat from treeold leaf j

11 rhoM=max(abs(eig(M)));%biggest absolute eigenvalue on M,

current edge i coming from leaf j

12 if curr_edge(2)==treeold(j).init % se ho trovato una

sequenza instabile ripetibile

13 JSRl=max(rhoM^(1/N),JSRl);%updates CJSRlow

14 if any(rhoM>=1)%returns unstable results...

15 %stringa=sprintf(’Al passo %d ho trovato una matrice

instabile.’,N);

16 %fprintf([stringa, ’\n’]);

17 %fprintf(’JSR in (%f,%f)\n’,JSRl,JSRu);

18 %fprintf(’Cutted branches %f\n’, 100*(1-mult/(

totEdges^N)));

19 Stable=0;

20 Cycle=[treeold(j).memory,curr_edge(2)];

21 toc

22 return;

23 end

24 end

25 Vi=ComputeNorm(M,PP,d,Kd);

26 if Vi>1

27 tree(indice).mat=M;

28 tree(indice).state=curr_edge(2);

29 tree(indice).init=treeold(j).init;%init is always

mantained... that’s why its kept above.

30 tree(indice).memory=[treeold(j).memory,curr_edge(2)];

%% I ADDED THIS(MEMORY)

31 JSRu2=max(Vi^(1/N),JSRu2);%CJSRUP’’ updated

32 else

33 JSRu1=max(Vi^(1/N),JSRu1);%CJSRup’ updated

34 end

35 end �

[ September 7, 2018 at 10:46 – version 1.0 ]

Page 103: Algorithms for the Design of Stabilizing Switching Graphs for ......Discrete-Time Switched Linear Systems Supervisor: prof. fabio dercole Master Graduation Thesis by: luiz alfredo

88 appendix

1 JSRu=min(JSRu2,JSRu);%CJSRup for now receives CJSRup’’,

unless the tree is stable...

2 tree=tree(cell2mat({tree.state})~=0);

3 end

4 JSRu=JSRu1;

5 %stringa=sprintf(’Al passo %d tutte le matrici sono contrazioni

.’,N);

6 %fprintf([stringa, ’\n’]);

7 %fprintf(’JSR in (%f,%f)\n’,JSRl,JSRu);

8 %fprintf(’Cutted branches %f\n’, 100*(1-mult/(totEdges^N)))

9 Stable=1;

10 toc �

Listing A.5: Arbitrary_Graph

1 function G=Arbitrary_Graph(N)

2 %names={};

3 for i=1:N

4 %names(i)={char(string(i)+’Start’)};

5 for j=1:N

6 A(i,j)=j;

7 end

8 end

9 G=digraph(A);

10 %plot(G,’EdgeLabel’,G.Edges.Weight,’LineWidth’,1.5,’NodeColor’,’y

’,’MarkerSize’,15,’ArrowSize’,10,’EdgeColor’,’k’) �

Listing A.6: Graph_to_Edges

1 function [edges]=Tree_to_Edges(G)

2 T=G.Edges;

3 edges = table2array(T);%comes in correct format St St+1 Ai �

[ September 7, 2018 at 10:46 – version 1.0 ]

Page 104: Algorithms for the Design of Stabilizing Switching Graphs for ......Discrete-Time Switched Linear Systems Supervisor: prof. fabio dercole Master Graduation Thesis by: luiz alfredo

appendix 89

Listing A.7: Remove_Isolated

1 function [G_new,new_max_old,Label_List] = Remove_Isolated(G,

max_old,Label_List)

2 condition=1;

3 max_old2=max_old;

4 while condition==1

5 condition=0;

6 RmvStates=[];

7 new_max_old=max_old2;

8 for i=1:numnodes(G)

9 out_edges = successors(G,i);

10 in_edges = predecessors(G,i);

11 if or(isempty(out_edges),isempty(in_edges))

12 % fprintf(’Removing node %d, because its isolated\n’,

i);

13 RmvStates = [RmvStates i];

14 condition=1;

15 if i<=max_old2

16 new_max_old=new_max_old-1;

17 % fprintf(’New number of originial nodes %d\n’,

new_max_old);

18 end

19 end

20 end

21 max_old2=new_max_old;

22 for i=1:length(RmvStates)

23 Label_List(RmvStates(i))=0;

24 end

25 Label_List=Label_List(Label_List ~= 0);

26 G=rmnode(G,RmvStates);

27 end

28 G_new=G; �

[ September 7, 2018 at 10:46 – version 1.0 ]

Page 105: Algorithms for the Design of Stabilizing Switching Graphs for ......Discrete-Time Switched Linear Systems Supervisor: prof. fabio dercole Master Graduation Thesis by: luiz alfredo

[ September 7, 2018 at 10:46 – version 1.0 ]

Page 106: Algorithms for the Design of Stabilizing Switching Graphs for ......Discrete-Time Switched Linear Systems Supervisor: prof. fabio dercole Master Graduation Thesis by: luiz alfredo

BA P P E N D I X : C O D E L I S T I N G S - M A I N A L G O R I T H M S

All codes regarding the main algorithms are in this appendix, thesefunctions descriptions can be found in Section 4.4.

91

[ September 7, 2018 at 10:46 – version 1.0 ]

Page 107: Algorithms for the Design of Stabilizing Switching Graphs for ......Discrete-Time Switched Linear Systems Supervisor: prof. fabio dercole Master Graduation Thesis by: luiz alfredo

92 appendix

Listing B.1: Stabilizing Algorithm 1 in Matlab (Alg. 1)

1 clear

2 close all

3 %% data

4 %n = 2; % dimension, not neeeded

5 A = [0.94 0.56 ; 0.14 0.46] ; % state

6 B = [0 ; 1] ; % input to state

7 K1 = [-0.49 0.27] ; % control mode 1

8 K2 = [0 K1(2)] ; % control mode 2

9 K3 = [K1(1) 0] ; % control mode 3

10 K4 = [0 0] ; % control mode 4

11 matrices = {A+B*K1 ; A+B*K2 ; A+B*K3 ; A+B*K4} ; % matrix set \

Sigma, 4 labels

12 d=6;

13 %matrices = {0.5;1.2};

14 %matrices = {0.5;10};

15 %matrices = {0.5;3};

16 d=0;%for d equal to 0 gets biggest eigenvalue.

17 matrices = {[1.1 0;0 0.9] ; [0.1 0;0 1.2]};

18 %load Alg3G40.mat

19 old=matrices;

20 %% Starting

21 TimeStart=tic;

22 plot_interval=1;

23 cyc_cont=1;

24 Stable=0;

25 G=Arbitrary_Graph(length(matrices));

26 %IntermediateGraph{1}=GraphInt{40};

27 %G=GraphInt{40};

28 for i=1:numnodes(G)

29 Label_List(i)=[i];

30 end

31 G.Nodes.Type=Label_List’;

32 edges=Graph_to_Edges(G);

33 iteration=1;

34 [Stable,JSRl,JSRu,Cycle]=Constrained_Stability(matrices,edges,d);

35 TimeTree(iteration)=toc; �

[ September 7, 2018 at 10:46 – version 1.0 ]

Page 108: Algorithms for the Design of Stabilizing Switching Graphs for ......Discrete-Time Switched Linear Systems Supervisor: prof. fabio dercole Master Graduation Thesis by: luiz alfredo

appendix 93

1 max_old=numnodes(G);

2 Time(iteration)=toc(TimeStart);

3 while Stable==0%trims heavily the graph

4 TimeStart=tic;

5 iteration

6 Cycle

7 Total_Nodes(iteration)=numnodes(G);

8 if mod(iteration,plot_interval)==0 %plotting

9 ap(1)=Label_List(Cycle(1));

10 vis=strcat( ’\{ ’,mat2str(ap(1)));11 for i=2:length(Cycle)

12 ap(i)=Label_List(Cycle(i));

13 vis=strcat(vis, ’−>’,mat2str(ap(i)));14 end

15 vis=strcat(vis, ’\} ’);16 figure()

17 G.Nodes.Type=Label_List’;

18 plot(G, ’NodeLabel ’,G.Nodes.Type, ’LineWidth ’,1.5, ’NodeColor ’, ’y ’, ’MarkerSize ’,15, ’ArrowSize ’,10, ’EdgeColor ’, ’k ’, ’Layout ’, ’ c ircle ’)

19 title([ ’ Iteration ’,num2str(iteration), ’\newline ’, ’Detected Cycle ’,vis])

20 end

21 CycleList(cyc_cont,:)={Cycle};%contains all cycles

22 cyc_cont=cyc_cont+1;

23 G=rmedge(G,Cycle(1),Cycle(2));%Removes the first edge

24 %G=rmedge(G,Cycle(length(Cycle)-1),Cycle(length(Cycle)));%

Removes the last edge

25 if mod(iteration,plot_interval)==0

26 G.Nodes.Type=Label_List’;

27 figure()

28 plot(G, ’NodeLabel ’,G.Nodes.Type, ’LineWidth ’,1.5, ’NodeColor’, ’y ’, ’MarkerSize ’,15, ’ArrowSize ’,10, ’EdgeColor ’, ’k ’, ’Layout ’, ’ c ircle ’)

29 title([ ’Before isolated nodes removal of iteration ’,num2str(iteration+1), ’\newline ’, ’Numnodes = ’,num2str(numnodes(G))])

30 end

31 [G,max_old,Label_List]=Remove_Isolated(G,max_old,Label_List);

32 iteration=iteration+1;

33 IntermediateGraph{iteration}=G;

34 fprintf( ’Computing tree iteration %d \n’,iteration);35 edges=Graph_to_Edges(G);

36 [Stable,JSRl,JSRu,Cycle]=Constrained_Stability(matrices,edges

,d);

37 TimeTree(iteration)=toc;

38 Time(iteration)=toc(TimeStart);

39 end

40 Total_Nodes(iteration)=numnodes(G);

41 G.Nodes.Type=Label_List’;

42 figure()

43 plot(G, ’EdgeLabel ’,G.Edges.Weight, ’NodeLabel ’,G.Nodes.Type, ’LineWidth ’,1.5, ’NodeColor ’, ’y ’, ’MarkerSize ’,15, ’ArrowSize ’,10, ’EdgeColor ’, ’k ’, ’Layout ’, ’ c ircle ’)

44 title( ’ Final Graph’) �

[ September 7, 2018 at 10:46 – version 1.0 ]

Page 109: Algorithms for the Design of Stabilizing Switching Graphs for ......Discrete-Time Switched Linear Systems Supervisor: prof. fabio dercole Master Graduation Thesis by: luiz alfredo

94 appendix

Listing B.2: Stabilizing Algorithm 2 in Matlab (Alg. 2)

1 clear

2 close all

3 %% data

4 %n = 2; % dimension, not neeeded

5 A = [0.94 0.56 ; 0.14 0.46] ; % state

6 B = [0 ; 1] ; % input to state

7 K1 = [-0.49 0.27] ; % control mode 1

8 K2 = [0 K1(2)] ; % control mode 2

9 K3 = [K1(1) 0] ; % control mode 3

10 K4 = [0 0] ; % control mode 4

11 matrices = {A+B*K1 ; A+B*K2 ; A+B*K3 ; A+B*K4} ; % matrix set \

Sigma, 4 labels

12 d=6;

13 %matrices = {0.5;10};

14 %matrices = {0.5;1.2};

15 d=0;%for d equal to 0 gets biggest eigenvalue.

16 d=0;%for d equal to 0 gets biggest eigenvalue.

17 matrices = {[1.1 0;0 0.9] ; [0.1 0;0 1.2]};

18 load Alg3G40.mat

19 %%

20 %Initial Conditions

21 TimeStart=tic;

22 NameList=[];

23 for i=1:length(matrices)

24 NameList = [NameList i];

25 end

26 plot_interval=100;

27 nrep=1;%Number of Cycle repetitions(chain), different results for

different nrep

28 condition=0;%Decides wether we add chains or trim an existent

spiral

29 iteration=1;

30 G=Arbitrary_Graph(length(matrices));

31 %IntermediateGraph{1}=GraphInt{20};

32 %G=GraphInt{20};

33 edges=Graph_to_Edges(G);

34 fprintf( ’Computing tree iteration %d \n’,iteration);35 [Stable,JSRl,JSRu,Cycle]=Constrained_Stability(matrices,edges,d); �

[ September 7, 2018 at 10:46 – version 1.0 ]

Page 110: Algorithms for the Design of Stabilizing Switching Graphs for ......Discrete-Time Switched Linear Systems Supervisor: prof. fabio dercole Master Graduation Thesis by: luiz alfredo

appendix 95

1 TimeTree(iteration)=toc;

2 max_old=numnodes(G);

3 for i=1:numnodes(G)

4 Label_List(i)=[i];

5 count_type(i)=[1];%counts the variable of each type

6 end

7 G.Nodes.Type=Label_List’;

8 Time(iteration)=toc(TimeStart);

9 while Stable==0

10 TimeStart=tic;

11 iteration

12 Cycle

13 max_old2=numnodes(G);

14 Total_Nodes(iteration)=numnodes(G);

15 if mod(iteration,plot_interval)==0 %plotting

16 ap(1)=Label_List(Cycle(1));

17 vis=strcat( ’\{ ’,mat2str(ap(1)));18 for i=2:length(Cycle)

19 ap(i)=Label_List(Cycle(i));

20 vis=strcat(vis, ’−>’,mat2str(ap(i)));21 end

22 vis=strcat(vis, ’\} ’);23 figure()

24 G.Nodes.Type=Label_List’;

25 plot(G, ’NodeLabel ’,G.Nodes.Type, ’LineWidth ’,1.5, ’NodeColor ’, ’y ’, ’MarkerSize ’,15, ’ArrowSize ’,10, ’EdgeColor ’, ’k ’, ’Layout ’, ’ c ircle ’)

26 title([ ’ Iteration ’,num2str(iteration), ’\newline ’, ’Detected Cycle ’,vis])

27 end

28 first_n=0;

29 first_o=0;

30 for i=1:length(Cycle)

31 if Cycle(i)>max_old

32 condition=1;

33 last_new_node=i;

34 end

35 if Cycle(i)<=max_old �

[ September 7, 2018 at 10:46 – version 1.0 ]

Page 111: Algorithms for the Design of Stabilizing Switching Graphs for ......Discrete-Time Switched Linear Systems Supervisor: prof. fabio dercole Master Graduation Thesis by: luiz alfredo

96 appendix

1 last_old_node=i;

2 end

3 if Cycle(i)>max_old && first_n==0

4 first_new_node=i;

5 first_n=1;

6 end

7 if Cycle(i)<=max_old && first_o==0

8 first_old_node=i;

9 first_o=1;

10 end

11 end

12 if condition==0 %when we don’t have new nodes in the cycle

13 New = nrep*(length(Cycle)-1);

14 G = addnode(G,New); %adds the new nodes for the spiral

15 EdgeIndex = findedge(G,Cycle(1),Cycle(2));

16 edges=Graph_to_Edges(G);

17 EdgeWeight = edges(EdgeIndex,3);%gets the weight before

its removed

18 curr_node = numnodes(G)-New+1; %first new node

19 G = addedge(G,Cycle(1),curr_node,EdgeWeight); % connects

where the edge will be removed to the new node

20 sucIDs = successors(G,Cycle(2));

21 for k=1:length(sucIDs)

22 if length(Cycle)>2

23 if sucIDs(k)<=max_old && sucIDs(k)~=Cycle(3)

24 EdgeIndex = findedge(G,Cycle(2),sucIDs(k));

25 edges=Graph_to_Edges(G);

26 EdgeWeight = edges(EdgeIndex,3);

27 G = addedge(G,curr_node,sucIDs(k),EdgeWeight)

;

28 end

29 end

30 if length(Cycle)==2

31 if sucIDs(k)<=max_old && sucIDs(k)~=Cycle(1)

32 EdgeIndex = findedge(G,Cycle(2),sucIDs(k));

33 edges=Graph_to_Edges(G);

34 EdgeWeight = edges(EdgeIndex,3);

35 G = addedge(G,curr_node,sucIDs(k),EdgeWeight)

; �

[ September 7, 2018 at 10:46 – version 1.0 ]

Page 112: Algorithms for the Design of Stabilizing Switching Graphs for ......Discrete-Time Switched Linear Systems Supervisor: prof. fabio dercole Master Graduation Thesis by: luiz alfredo

appendix 97

1 end

2 end

3 end

4 for j=2:(length(Cycle)-1)

5 EdgeIndex = findedge(G,Cycle(j),Cycle(j+1));

6 edges = Graph_to_Edges(G);

7 EdgeWeight = edges(EdgeIndex,3);

8 G = addedge(G,curr_node,curr_node+1,EdgeWeight);

9 curr_node = curr_node+1;

10 sucIDs = successors(G,Cycle(j+1));

11 for k=1:length(sucIDs)

12 if j+2<=length(Cycle)

13 if sucIDs(k)<=max_old && sucIDs(k)~=Cycle(j+2)

14 EdgeIndex = findedge(G,Cycle(j+1),sucIDs(k)

);

15 edges=Graph_to_Edges(G);

16 EdgeWeight = edges(EdgeIndex,3);

17 G = addedge(G,curr_node,sucIDs(k),

EdgeWeight);

18 end

19 end

20 if j+2==(length(Cycle)+1)

21 if sucIDs(k)<=max_old && sucIDs(k)~=Cycle(2)

22 EdgeIndex = findedge(G,Cycle(j+1),sucIDs(k)

);

23 edges=Graph_to_Edges(G);

24 EdgeWeight = edges(EdgeIndex,3);

25 G = addedge(G,curr_node,sucIDs(k),

EdgeWeight);

26 end

27 end

28 end

29 end

30 for i=1:(nrep-1) %recreates the Cycle nrep

31 for j=1:(length(Cycle)-1)

32 EdgeIndex = findedge(G,Cycle(j),Cycle(j+1));

33 edges = Graph_to_Edges(G);

34 EdgeWeight = edges(EdgeIndex,3);

35 G = addedge(G,curr_node,curr_node+1,EdgeWeight); �

[ September 7, 2018 at 10:46 – version 1.0 ]

Page 113: Algorithms for the Design of Stabilizing Switching Graphs for ......Discrete-Time Switched Linear Systems Supervisor: prof. fabio dercole Master Graduation Thesis by: luiz alfredo

98 appendix

1 curr_node = curr_node+1;

2 sucIDs = successors(G,Cycle(j+1));

3 for k=1:length(sucIDs)

4 if j+2<=length(Cycle)

5 if sucIDs(k)<=max_old && sucIDs(k)~=Cycle(j

+2)

6 EdgeIndex = findedge(G,Cycle(j+1),

sucIDs(k));

7 edges=Graph_to_Edges(G);

8 EdgeWeight = edges(EdgeIndex,3);

9 G = addedge(G,curr_node,sucIDs(k),

EdgeWeight);

10 end

11 end

12 if j+2==(length(Cycle)+1)

13 if sucIDs(k)<=max_old && sucIDs(k)~=Cycle

(2)

14 EdgeIndex = findedge(G,Cycle(j+1),

sucIDs(k));

15 edges=Graph_to_Edges(G);

16 EdgeWeight = edges(EdgeIndex,3);

17 G = addedge(G,curr_node,sucIDs(k),

EdgeWeight);

18 end

19 end

20 end

21 end

22 end

23 G = rmedge(G,Cycle(1),Cycle(2));%Removes the first edge

24 end

25 if condition==1 %when we have new nodes in the cycle

26

27 if first_old_node==1

28 Node1 = Cycle(last_new_node-1);

29 Node2 = Cycle(last_new_node);

30 Node3 = Cycle(last_new_node+1);

31 end

32 if first_new_node==1

33 if first_old_node==2

34 Node1 = Cycle(end);

35 end �

[ September 7, 2018 at 10:46 – version 1.0 ]

Page 114: Algorithms for the Design of Stabilizing Switching Graphs for ......Discrete-Time Switched Linear Systems Supervisor: prof. fabio dercole Master Graduation Thesis by: luiz alfredo

appendix 99

1 if first_old_node>2

2 Node1 = Cycle(first_old_node-2);

3 end

4 Node2 = Cycle(first_old_node-1);

5 Node3 = Cycle(first_old_node);

6 end

7 fprintf( ’Removing edge from (%d,%d)\n’,Node1,Node2);8 G = rmedge(G,Node1,Node2); %cuts the last edge inside the

chain

9 %fprintf(’Removing edge from (%d,%d)\n’,Node2,Node3);

10 %G = rmedge(G,Node2,Node3); %cuts the following edge at

the end of the chain

11 condition=0;%resets the condition

12 end

13 for i=(max_old2+1):(numnodes(G))

14 preIDs = predecessors(G,i);

15 EdgeIndex = findedge(G,preIDs(1),i);

16 edges=Graph_to_Edges(G);

17 EdgeWeight = edges(EdgeIndex,3);

18 Label=strcat(num2str(EdgeWeight),num2str(count_type(

EdgeWeight)));

19 Label_List(i) =[str2num(Label)];

20 count_type(EdgeWeight)=count_type(EdgeWeight)+1;

21 end

22 if mod(iteration,plot_interval)==0

23 G.Nodes.Type=Label_List’;

24 figure()

25 plot(G, ’NodeLabel ’,G.Nodes.Type, ’LineWidth ’,1.5, ’NodeColor’, ’y ’, ’MarkerSize ’,15, ’ArrowSize ’,10, ’EdgeColor ’, ’k ’, ’Layout ’, ’ c ircle ’)

26 title([ ’Before isolated nodes removal of iteration ’,num2str(iteration+1), ’\newline ’, ’Numnodes = ’,num2str(numnodes(G))])

27 end

28 [G,max_old,Label_List]=Remove_Isolated(G,max_old,Label_List);

%removes isolated nodes

29 iteration=iteration+1;

30 fprintf( ’Computing tree iteration %d \n’,iteration);31 edges=Graph_to_Edges(G);

32 [Stable,JSRl,JSRu,Cycle]=Constrained_Stability(matrices,edges

,d);

33 TimeTree(iteration)=toc;

34 Time(iteration)=toc(TimeStart);

35 end

36 Total_Nodes(iteration)=numnodes(G);

37 G.Nodes.Type=Label_List’;

38 figure()

39 plot(G, ’EdgeLabel ’,G.Edges.Weight, ’NodeLabel ’,G.Nodes.Type, ’LineWidth ’,1.5, ’NodeColor ’, ’y ’, ’MarkerSize ’,15, ’ArrowSize ’,10, ’EdgeColor ’, ’k ’, ’Layout ’, ’ c ircle ’)

40 title( ’ Final Graph’) �

[ September 7, 2018 at 10:46 – version 1.0 ]

Page 115: Algorithms for the Design of Stabilizing Switching Graphs for ......Discrete-Time Switched Linear Systems Supervisor: prof. fabio dercole Master Graduation Thesis by: luiz alfredo

100 appendix

Listing B.3: Stabilizing Algorithm 3 in Matlab (Alg. 3)

1 clear

2 close all

3 %% data

4 A = [0.94 0.56 ; 0.14 0.46] ; % state

5 B = [0 ; 1] ; % input to state

6 K1 = [-0.49 0.27] ; % control mode 1

7 K2 = [0 K1(2)] ; % control mode 2

8 K3 = [K1(1) 0] ; % control mode 3

9 K4 = [0 0] ; % control mode 4

10 matrices = {A+B*K1 ; A+B*K2 ; A+B*K3 ; A+B*K4} ; % matrix set \

Sigma, 4 labels

11 d=6;

12 %matrices = {0.5;10};%example

13 %matrices = {0.1;0.5;2.1};

14 %matrices = {0.5;1.5};

15 %matrices = {0.5;5};

16 %d=0;%for d equal to 0 gets biggest eigenvalue.

17 %%

18 %Initial Conditions

19 TimeStart=tic;

20 plot_interval=1; % iteration interval between plots

21 nrep=1; % Number of Cycle repetitions(chain), different results

for different nrep.

22 condition=0; % Decides wether we add chains or trim an existent

spiral, in this alg, it’s always 0

23 iteration=1; % initial iteration

24 almost=0; % 1 for almost nrep+1, 0 for at most nrep

25 G=Arbitrary_Graph(length(matrices)); % Builds arbitrary switching

graph

26 for i=1:length(matrices)

27 Label_List(i)=[i];

28 count_type(i)=[1];%counts the variable of each type

29 end

30 G.Nodes.Type=Label_List’;

31 edges=Graph_to_Edges(G); % gets the edges from the graph to use

the stability algorithm

32 fprintf( ’Computing tree iteration %d \n’,iteration);33 [Stable,JSRl,JSRu,Cycle]=Constrained_Stability(matrices,edges,d);

% checks stability for arbitrary swithing graph

34 max_old_old=length(matrices); %max_old saves the number of

original nodes that haven’t been removed. It will be updated

on every iteration.

35 Time(iteration)=toc(TimeStart); �

[ September 7, 2018 at 10:46 – version 1.0 ]

Page 116: Algorithms for the Design of Stabilizing Switching Graphs for ......Discrete-Time Switched Linear Systems Supervisor: prof. fabio dercole Master Graduation Thesis by: luiz alfredo

appendix 101

1 TimeTree(iteration)=toc;

2 while Stable==0 %keeps running while the result is unstable

3 TimeStart=tic;

4 iteration

5 Cycle

6 EdgeList=[];

7 Total_Nodes(iteration)=numnodes(G);

8 for k=1:(length(Cycle)-1)

9 EdgeIndex = findedge(G,Cycle(k),Cycle(k+1));

10 edges=Graph_to_Edges(G);

11 EdgeWeight = edges(EdgeIndex,3);

12 EdgeList = [EdgeList EdgeWeight];

13 end

14 if mod(iteration,plot_interval)==0 %plotting

15 ap(1)=Label_List(Cycle(1));

16 vis=strcat( ’\{ ’,mat2str(ap(1)));17 for i=2:length(Cycle)

18 ap(i)=Label_List(Cycle(i));

19 vis=strcat(vis, ’−>’,mat2str(ap(i)));20 end

21 vis=strcat(vis, ’\} ’);22 figure()

23 G.Nodes.Type=Label_List’;

24 plot(G, ’NodeLabel ’,G.Nodes.Type, ’LineWidth ’,1.5, ’NodeColor ’, ’y ’, ’MarkerSize ’,15, ’ArrowSize ’,10, ’EdgeColor ’, ’k ’, ’Layout ’, ’ c ircle ’)

25 title([ ’ Iteration ’,num2str(iteration), ’\newline ’, ’Detected Cycle ’,vis])

26 end

27 if condition==0 %When we add nodes to the chain.

28 max_old2=numnodes(G);

29 max_old=max_old_old;

30 for a=1:(length(Cycle)-1) %Builds all possible cycle

structures(starting from all possible nodes in the

cycle.

31 Cycle_aux=Cycle(1:length(Cycle)-1); %Since the Cycle

obtained has the same first and last elements,

32 %this creates an auxiliary cycle that removes that.

33 CycleRef=zeros(1,length(Cycle));

34 for i=1:length(Cycle_aux)%rebuilds the cycle

structure for a given ’a’, being ’CycleRef’ the

new way to represent ’Cycle’

35 if (a+i-1)<=length(Cycle_aux)% i.e Cycle=[2 3 2],

CycleRef=[2 3 2] for a=1 and CycleRef=[3 2

3] for a=2 �

[ September 7, 2018 at 10:46 – version 1.0 ]

Page 117: Algorithms for the Design of Stabilizing Switching Graphs for ......Discrete-Time Switched Linear Systems Supervisor: prof. fabio dercole Master Graduation Thesis by: luiz alfredo

102 appendix

1 CycleRef(i)=Cycle_aux(a+i-1);

2 end

3 if (a+i-1)>length(Cycle_aux)

4 CycleRef(i)=Cycle_aux(a+i-1-length(Cycle_aux)

);

5 end

6 end

7 CycleRef(length(Cycle))=Cycle(a);%Last element for

CycleRef

8 New = nrep*(length(Cycle)-1)+(length(Cycle)-2);

9 if almost==0

10 New = nrep*(length(Cycle)-1);

11 end

12 G = addnode(G,New); %adds the new nodes for the

chains

13 EdgeIndex = findedge(G,CycleRef(1),CycleRef(2));%

checks the first edge from the cycle

14 edges=Graph_to_Edges(G);

15 EdgeWeight = edges(EdgeIndex,3);%gets the weight

before its removed of that edge

16 curr_node = numnodes(G)-New+1; %first new node

17 if nrep>0 || length(Cycle)>2

18 G = addedge(G,CycleRef(1),curr_node,EdgeWeight);

% connects where the edge will be removed to

the new node

19 sucIDs = successors(G,CycleRef(2)); %checks the

nodes that come after the second node

20 for k=1:length(sucIDs) %adds the edges going down

to the original nodes(<=max_old), in a way

to copy the successors

21 if length(Cycle)>2

22 if sucIDs(k)<=max_old && sucIDs(k)~=

CycleRef(3)

23 EdgeIndex = findedge(G,CycleRef(2),

sucIDs(k));

24 edges=Graph_to_Edges(G);

25 EdgeWeight = edges(EdgeIndex,3);

26 G = addedge(G,curr_node,sucIDs(k),

EdgeWeight);

27 end

28 end

29 if length(Cycle)==2

30 if sucIDs(k)<=max_old && sucIDs(k)~=

CycleRef(1)

31 EdgeIndex = findedge(G,CycleRef(2),

sucIDs(k));

32 edges=Graph_to_Edges(G);

33 EdgeWeight = edges(EdgeIndex,3);

34 G = addedge(G,curr_node,sucIDs(k),

EdgeWeight);

35 end �

[ September 7, 2018 at 10:46 – version 1.0 ]

Page 118: Algorithms for the Design of Stabilizing Switching Graphs for ......Discrete-Time Switched Linear Systems Supervisor: prof. fabio dercole Master Graduation Thesis by: luiz alfredo

appendix 103

1 end

2 end

3 end

4 v=1;

5 if nrep==0

6 v=2;

7 end

8 for j=2:(length(Cycle)-v)%does the same operation of

connecting the new nodes to the original ones, as

it follows the Cycle

9 EdgeIndex = findedge(G,CycleRef(j),CycleRef(j+1))

;

10 edges = Graph_to_Edges(G);

11 EdgeWeight = edges(EdgeIndex,3);

12 G = addedge(G,curr_node,curr_node+1,EdgeWeight);%

goes up in the spiral to the next node

13 curr_node = curr_node+1;

14 sucIDs = successors(G,CycleRef(j+1));

15 for k=1:length(sucIDs)% connects the new nodes to

the original ones(downward)

16 if j+2<=length(Cycle)

17 if sucIDs(k)<=max_old && sucIDs(k)~=

CycleRef(j+2)

18 EdgeIndex = findedge(G,CycleRef(j+1),

sucIDs(k));

19 edges=Graph_to_Edges(G);

20 EdgeWeight = edges(EdgeIndex,3);

21 G = addedge(G,curr_node,sucIDs(k),

EdgeWeight);

22 end

23 end

24 if j+2==(length(Cycle)+1)

25 if sucIDs(k)<=max_old && sucIDs(k)~=

CycleRef(2)

26 EdgeIndex = findedge(G,CycleRef(j+1),

sucIDs(k));

27 edges=Graph_to_Edges(G);

28 EdgeWeight = edges(EdgeIndex,3);

29 G = addedge(G,curr_node,sucIDs(k),

EdgeWeight);

30 end

31 end

32 end

33 end

34 for i=1:(nrep-1) %recreates the Cycle nrep-1 times(

the first time was created above)

35 for j=1:(length(Cycle)-1) �

[ September 7, 2018 at 10:46 – version 1.0 ]

Page 119: Algorithms for the Design of Stabilizing Switching Graphs for ......Discrete-Time Switched Linear Systems Supervisor: prof. fabio dercole Master Graduation Thesis by: luiz alfredo

104 appendix

1 EdgeIndex = findedge(G,CycleRef(j),CycleRef(j

+1));

2 edges = Graph_to_Edges(G);

3 EdgeWeight = edges(EdgeIndex,3);

4 G = addedge(G,curr_node,curr_node+1,

EdgeWeight);

5 curr_node = curr_node+1;

6 sucIDs = successors(G,CycleRef(j+1));

7 for k=1:length(sucIDs)

8 if j+2<=length(Cycle)

9 if sucIDs(k)<=max_old && sucIDs(k)~=

CycleRef(j+2)

10 EdgeIndex = findedge(G,CycleRef(j

+1),sucIDs(k));

11 edges=Graph_to_Edges(G);

12 EdgeWeight = edges(EdgeIndex,3);

13 G = addedge(G,curr_node,sucIDs(k)

,EdgeWeight);

14 end

15 end

16 if j+2==(length(Cycle)+1)

17 if sucIDs(k)<=max_old && sucIDs(k)~=

CycleRef(2)

18 EdgeIndex = findedge(G,CycleRef(j

+1),sucIDs(k));

19 edges=Graph_to_Edges(G);

20 EdgeWeight = edges(EdgeIndex,3);

21 G = addedge(G,curr_node,sucIDs(k)

,EdgeWeight);

22 end

23 end

24 end

25 end

26 end

27 if nrep>0 && almost==1

28 for j=1:(length(Cycle)-2)% allows almost nrep+1

29 EdgeIndex = findedge(G,CycleRef(j),CycleRef(j

+1));

30 edges = Graph_to_Edges(G);

31 EdgeWeight = edges(EdgeIndex,3);

32 G = addedge(G,curr_node,curr_node+1,

EdgeWeight);

33 curr_node = curr_node+1;

34 sucIDs = successors(G,CycleRef(j+1));

35 for k=1:length(sucIDs) �

[ September 7, 2018 at 10:46 – version 1.0 ]

Page 120: Algorithms for the Design of Stabilizing Switching Graphs for ......Discrete-Time Switched Linear Systems Supervisor: prof. fabio dercole Master Graduation Thesis by: luiz alfredo

appendix 105

1 if j+2<=length(Cycle)

2 if sucIDs(k)<=max_old && sucIDs(k)~=

CycleRef(j+2)

3 EdgeIndex = findedge(G,CycleRef(j

+1),sucIDs(k));

4 edges=Graph_to_Edges(G);

5 EdgeWeight = edges(EdgeIndex,3);

6 G = addedge(G,curr_node,sucIDs(k)

,EdgeWeight);

7 end

8 end

9 if j+2==(length(Cycle)+1)

10 if sucIDs(k)<=max_old && sucIDs(k)~=

CycleRef(2)

11 EdgeIndex = findedge(G,CycleRef(j

+1),sucIDs(k));

12 edges=Graph_to_Edges(G);

13 EdgeWeight = edges(EdgeIndex,3);

14 G = addedge(G,curr_node,sucIDs(k)

,EdgeWeight);

15 end

16 end

17 end

18 end

19 end

20 end

21 for a=1:(length(Cycle)-1)

22 G = rmedge(G,Cycle(a),Cycle(a+1)); %Removes the edge

used to create the chain

23 end

24 end

25 % here we update Label List(starting from max_old+1)

26 for i=(max_old2+1):(numnodes(G))

27 preIDs = predecessors(G,i);

28 EdgeIndex = findedge(G,preIDs(1),i);

29 edges=Graph_to_Edges(G);

30 EdgeWeight = edges(EdgeIndex,3);

31 Label=strcat(num2str(EdgeWeight),num2str(count_type(

EdgeWeight)));

32 Label_List(i) =[str2num(Label)];

33 count_type(EdgeWeight)=count_type(EdgeWeight)+1;

34 end

35 if mod(iteration,plot_interval)==0 �

[ September 7, 2018 at 10:46 – version 1.0 ]

Page 121: Algorithms for the Design of Stabilizing Switching Graphs for ......Discrete-Time Switched Linear Systems Supervisor: prof. fabio dercole Master Graduation Thesis by: luiz alfredo

106 appendix

1 G.Nodes.Type=Label_List’;

2 figure()

3 plot(G, ’NodeLabel ’,G.Nodes.Type, ’LineWidth ’,1.5, ’NodeColor’, ’y ’, ’MarkerSize ’,15, ’ArrowSize ’,10, ’EdgeColor ’, ’k ’, ’Layout ’, ’ c ircle ’)

4 title([ ’Before isolated nodes removal of iteration ’,num2str(iteration+1), ’\newline ’, ’Numnodes = ’,num2str(numnodes(G))])

5 end

6 [G,max_old_old,Label_List]=Remove_Isolated(G,max_old_old,

Label_List);%removes isolated nodes and updates max_old

if one of the original nodes is removed.

7 iteration=iteration+1;

8 fprintf( ’Computing tree iteration %d \n’,iteration);9 edges=Graph_to_Edges(G);

10 [Stable,JSRl,JSRu,Cycle]=Constrained_Stability(matrices,edges

,d);% runs stability checking algorithm

11 TimeTree(iteration)=toc;

12 Time(iteration)=toc(TimeStart);

13 end

14 Total_Nodes(iteration)=numnodes(G);

15 G.Nodes.Type=Label_List’;

16 figure()

17 plot(G, ’EdgeLabel ’,G.Edges.Weight, ’NodeLabel ’,G.Nodes.Type, ’LineWidth ’,1.5, ’NodeColor ’, ’y ’, ’MarkerSize ’,15, ’ArrowSize ’,10, ’EdgeColor ’, ’k ’, ’Layout ’, ’ c ircle ’)

18 title( ’ Final Graph’) �

[ September 7, 2018 at 10:46 – version 1.0 ]

Page 122: Algorithms for the Design of Stabilizing Switching Graphs for ......Discrete-Time Switched Linear Systems Supervisor: prof. fabio dercole Master Graduation Thesis by: luiz alfredo

appendix 107

Listing B.4: Stabilizing Algorithm 4 in Matlab (Alg. 4)

1 clear

2 close all

3 %% data

4 A = [0.94 0.56 ; 0.14 0.46] ; % state

5 B = [0 ; 1] ; % input to state

6 K1 = [-0.49 0.27] ; % control mode 1

7 K2 = [0 K1(2)] ; % control mode 2

8 K3 = [K1(1) 0] ; % control mode 3

9 K4 = [0 0] ; % control mode 4

10 matrices = {A+B*K1 ; A+B*K2 ; A+B*K3 ; A+B*K4} ; % matrix set \

Sigma, 4 labels

11 d=6;

12 %matrices = {0.5;10};%example

13 %matrices = {0.1;0.5;2.1};

14 %matrices = {0.5;1.2};

15 %matrices = {0.5;5};

16 %d=0;%for d equal to 0 gets biggest eigenvalue.

17 %%

18 %Initial Conditions

19 TimeStart=tic;

20 plot_interval=100; % iteration interval between plots

21 nrep=1; % Number of Cycle repetitions(spiral), different results

for different rep.

22 condition=0; % Decides wether we add chains or trim an existent

spiral, in this alg, it’s always 0

23 almost=0; % 1 for almost nrep+1, 0 for at most nrep

24 iteration=1; % initial iteration

25 G=Arbitrary_Graph(length(matrices)); % Builds arbitrary switching

graph

26 for i=1:length(matrices)

27 Label_List(i)=[i];

28 count_type(i)=[1];%counts the variable of each type

29 end

30 G.Nodes.Type=Label_List’;

31 edges=Graph_to_Edges(G); % gets the edges from the graph to use

the stability algorithm

32 GraphInt{iteration}=G;

33 fprintf( ’Computing tree iteration %d \n’,iteration);34 [Stable,JSRl,JSRu,Cycle]=Constrained_Stability(matrices,edges,d);

% checks stability for arbitrary swithing graph

35 max_old_old=length(matrices); %max_old_old saves the number of

original nodes that haven’t been removed. It will be updated

on every iteration. �

[ September 7, 2018 at 10:46 – version 1.0 ]

Page 123: Algorithms for the Design of Stabilizing Switching Graphs for ......Discrete-Time Switched Linear Systems Supervisor: prof. fabio dercole Master Graduation Thesis by: luiz alfredo

108 appendix

1 Time(iteration)=toc(TimeStart);

2 TimeTree(iteration)=toc;

3 while Stable==0 %keeps running while the result is unstable

4 TimeStart=tic;

5 iteration

6 Cycle

7 EdgeList=[];

8 Total_Nodes(iteration)=numnodes(G);

9 for k=1:(length(Cycle)-1)

10 EdgeIndex = findedge(G,Cycle(k),Cycle(k+1));

11 edges=Graph_to_Edges(G);

12 EdgeWeight = edges(EdgeIndex,3);

13 EdgeList = [EdgeList EdgeWeight];

14 end

15 if mod(iteration,plot_interval)==0 %plotting

16 ap(1)=Label_List(Cycle(1));

17 vis=strcat( ’\{ ’,mat2str(ap(1)));18 for i=2:length(Cycle)

19 ap(i)=Label_List(Cycle(i));

20 vis=strcat(vis, ’−>’,mat2str(ap(i)));21 end

22 vis=strcat(vis, ’\} ’);23 figure()

24 G.Nodes.Type=Label_List’;

25 plot(G, ’NodeLabel ’,G.Nodes.Type, ’LineWidth ’,1.5, ’NodeColor ’, ’y ’, ’MarkerSize ’,15, ’ArrowSize ’,10, ’EdgeColor ’, ’k ’, ’Layout ’, ’ c ircle ’)

26 title([ ’ Iteration ’,num2str(iteration), ’\newline ’, ’Detected Cycle ’,vis])

27 end

28 if condition==0 %When we add nodes to the spiral.

29 max_old=numnodes(G);%MODIFICATION ALL NODES FROM LAST

STEP BECOME "ORIGINAL"

30 for a=1:(length(Cycle)-1) %Builds all possible cycle

structures(starting from all possible nodes in the

cycle.

31 Cycle_aux=Cycle(1:length(Cycle)-1); %Since the Cycle

obtained has the same first and last elements,

32 %this creates an auxiliary cycle that removes that.

33 CycleRef=zeros(1,length(Cycle));

34 for i=1:length(Cycle_aux)%rebuilds the cycle

structure for a given ’a’, being ’CycleRef’ the

new way to represent ’Cycle’

35 if (a+i-1)<=length(Cycle_aux)% i.e Cycle=[2 3 2],

CycleRef=[2 3 2] for a=1 and CycleRef=[3 2

3] for a=2 �

[ September 7, 2018 at 10:46 – version 1.0 ]

Page 124: Algorithms for the Design of Stabilizing Switching Graphs for ......Discrete-Time Switched Linear Systems Supervisor: prof. fabio dercole Master Graduation Thesis by: luiz alfredo

appendix 109

1 CycleRef(i)=Cycle_aux(a+i-1);

2 end

3 if (a+i-1)>length(Cycle_aux)

4 CycleRef(i)=Cycle_aux(a+i-1-length(Cycle_aux)

);

5 end

6 end

7 CycleRef(length(Cycle))=Cycle(a);%Last element for

CycleRef

8 New = nrep*(length(Cycle)-1)+(length(Cycle)-2);

9 if almost==0

10 New = nrep*(length(Cycle)-1);

11 end

12 G = addnode(G,New); %adds the new nodes for the

spiral

13 EdgeIndex = findedge(G,CycleRef(1),CycleRef(2));%

checks the first edge from the cycle

14 edges=Graph_to_Edges(G);

15 EdgeWeight = edges(EdgeIndex,3);%gets the weight

before its removed of that edge

16 curr_node = numnodes(G)-New+1; %first new node

17 if nrep>0 || length(Cycle)>2

18 G = addedge(G,CycleRef(1),curr_node,EdgeWeight);

% connects where the edge will be removed to

the new node

19 sucIDs = successors(G,CycleRef(2)); %checks the

nodes that come after the second node

20 for k=1:length(sucIDs) %adds the edges going down

to the original nodes(<=max_old), in a way

to copy the successors

21 if length(Cycle)>2

22 if sucIDs(k)<=max_old && sucIDs(k)~=

CycleRef(3)

23 EdgeIndex = findedge(G,CycleRef(2),

sucIDs(k));

24 edges=Graph_to_Edges(G);

25 EdgeWeight = edges(EdgeIndex,3);

26 G = addedge(G,curr_node,sucIDs(k),

EdgeWeight);

27 end

28 end

29 if length(Cycle)==2

30 if sucIDs(k)<=max_old && sucIDs(k)~=

CycleRef(1)

31 EdgeIndex = findedge(G,CycleRef(2),

sucIDs(k));

32 edges=Graph_to_Edges(G);

33 EdgeWeight = edges(EdgeIndex,3);

34 G = addedge(G,curr_node,sucIDs(k),

EdgeWeight);

35 end �

[ September 7, 2018 at 10:46 – version 1.0 ]

Page 125: Algorithms for the Design of Stabilizing Switching Graphs for ......Discrete-Time Switched Linear Systems Supervisor: prof. fabio dercole Master Graduation Thesis by: luiz alfredo

110 appendix

1 end

2 end

3 end

4 v=1;

5 if nrep==0

6 v=2;

7 end

8 for j=2:(length(Cycle)-v)%does the same operation of

connecting the new nodes to the original ones, as

it follows the Cycle

9 EdgeIndex = findedge(G,CycleRef(j),CycleRef(j+1))

;

10 edges = Graph_to_Edges(G);

11 EdgeWeight = edges(EdgeIndex,3);

12 G = addedge(G,curr_node,curr_node+1,EdgeWeight);%

goes up in the chain to the next node

13 curr_node = curr_node+1;

14 sucIDs = successors(G,CycleRef(j+1));

15 for k=1:length(sucIDs)% connects the new nodes to

the original ones(downward)

16 if j+2<=length(Cycle)

17 if sucIDs(k)<=max_old && sucIDs(k)~=

CycleRef(j+2)

18 EdgeIndex = findedge(G,CycleRef(j+1),

sucIDs(k));

19 edges=Graph_to_Edges(G);

20 EdgeWeight = edges(EdgeIndex,3);

21 G = addedge(G,curr_node,sucIDs(k),

EdgeWeight);

22 end

23 end

24 if j+2==(length(Cycle)+1)

25 if sucIDs(k)<=max_old && sucIDs(k)~=

CycleRef(2)

26 EdgeIndex = findedge(G,CycleRef(j+1),

sucIDs(k));

27 edges=Graph_to_Edges(G);

28 EdgeWeight = edges(EdgeIndex,3);

29 G = addedge(G,curr_node,sucIDs(k),

EdgeWeight);

30 end

31 end

32 end

33 end

34 for i=1:(nrep-1) %recreates the Cycle nrep-1 times(

the first time was created above)

35 for j=1:(length(Cycle)-1) �

[ September 7, 2018 at 10:46 – version 1.0 ]

Page 126: Algorithms for the Design of Stabilizing Switching Graphs for ......Discrete-Time Switched Linear Systems Supervisor: prof. fabio dercole Master Graduation Thesis by: luiz alfredo

appendix 111

1 EdgeIndex = findedge(G,CycleRef(j),CycleRef(j

+1));

2 edges = Graph_to_Edges(G);

3 EdgeWeight = edges(EdgeIndex,3);

4 G = addedge(G,curr_node,curr_node+1,

EdgeWeight);

5 curr_node = curr_node+1;

6 sucIDs = successors(G,CycleRef(j+1));

7 for k=1:length(sucIDs)

8 if j+2<=length(Cycle)

9 if sucIDs(k)<=max_old && sucIDs(k)~=

CycleRef(j+2)

10 EdgeIndex = findedge(G,CycleRef(j

+1),sucIDs(k));

11 edges=Graph_to_Edges(G);

12 EdgeWeight = edges(EdgeIndex,3);

13 G = addedge(G,curr_node,sucIDs(k)

,EdgeWeight);

14 end

15 end

16 if j+2==(length(Cycle)+1)

17 if sucIDs(k)<=max_old && sucIDs(k)~=

CycleRef(2)

18 EdgeIndex = findedge(G,CycleRef(j

+1),sucIDs(k));

19 edges=Graph_to_Edges(G);

20 EdgeWeight = edges(EdgeIndex,3);

21 G = addedge(G,curr_node,sucIDs(k)

,EdgeWeight);

22 end

23 end

24 end

25 end

26 end

27 if nrep>0 && almost==1

28 for j=1:(length(Cycle)-2)% allows almost nrep+1

29 EdgeIndex = findedge(G,CycleRef(j),CycleRef(j

+1));

30 edges = Graph_to_Edges(G);

31 EdgeWeight = edges(EdgeIndex,3);

32 G = addedge(G,curr_node,curr_node+1,

EdgeWeight);

33 curr_node = curr_node+1;

34 sucIDs = successors(G,CycleRef(j+1));

35 for k=1:length(sucIDs) �

[ September 7, 2018 at 10:46 – version 1.0 ]

Page 127: Algorithms for the Design of Stabilizing Switching Graphs for ......Discrete-Time Switched Linear Systems Supervisor: prof. fabio dercole Master Graduation Thesis by: luiz alfredo

112 appendix

1 if j+2<=length(Cycle)

2 if sucIDs(k)<=max_old && sucIDs(k)~=

CycleRef(j+2)

3 EdgeIndex = findedge(G,CycleRef(j

+1),sucIDs(k));

4 edges=Graph_to_Edges(G);

5 EdgeWeight = edges(EdgeIndex,3);

6 G = addedge(G,curr_node,sucIDs(k)

,EdgeWeight);

7 end

8 end

9 if j+2==(length(Cycle)+1)

10 if sucIDs(k)<=max_old && sucIDs(k)~=

CycleRef(2)

11 EdgeIndex = findedge(G,CycleRef(j

+1),sucIDs(k));

12 edges=Graph_to_Edges(G);

13 EdgeWeight = edges(EdgeIndex,3);

14 G = addedge(G,curr_node,sucIDs(k)

,EdgeWeight);

15 end

16 end

17 end

18 end

19 end

20 end

21 for a=1:(length(Cycle)-1)

22 G = rmedge(G,Cycle(a),Cycle(a+1)); %Removes the edge

used to create the chain

23 end

24 end

25 for i=(max_old+1):(numnodes(G))

26 preIDs = predecessors(G,i);

27 EdgeIndex = findedge(G,preIDs(1),i);

28 edges=Graph_to_Edges(G);

29 EdgeWeight = edges(EdgeIndex,3);

30 Label=strcat(num2str(EdgeWeight),num2str(count_type(

EdgeWeight)));

31 Label_List(i) =[str2num(Label)];

32 count_type(EdgeWeight)=count_type(EdgeWeight)+1;

33 end

34 if mod(iteration,plot_interval)==0

35 G.Nodes.Type=Label_List’; �

[ September 7, 2018 at 10:46 – version 1.0 ]

Page 128: Algorithms for the Design of Stabilizing Switching Graphs for ......Discrete-Time Switched Linear Systems Supervisor: prof. fabio dercole Master Graduation Thesis by: luiz alfredo

appendix 113

1 figure()

2 plot(G, ’NodeLabel ’,G.Nodes.Type, ’LineWidth ’,1.5, ’NodeColor’, ’y ’, ’MarkerSize ’,15, ’ArrowSize ’,10, ’EdgeColor ’, ’k ’, ’Layout ’, ’ c ircle ’)

3 title([ ’Before isolated nodes removal of iteration ’,num2str(iteration+1), ’\newline ’, ’Numnodes = ’,num2str(numnodes(G))])

4 end

5 [G,max_old_old,Label_List]=Remove_Isolated(G,max_old_old,

Label_List);%removes isolated nodes and updates max_old

if one of the original nodes is removed.

6 iteration=iteration+1;

7 fprintf( ’Computing tree iteration %d \n’,iteration);8 edges=Graph_to_Edges(G);

9 [Stable,JSRl,JSRu,Cycle]=Constrained_Stability(matrices,edges

,d);% runs stability checking algorithm

10 GraphInt{iteration}=G;

11 if iteration==40

12 Stable=1;

13 save Alg3G40.mat GraphInt

14 end

15 TimeTree(iteration)=toc;

16 Time(iteration)=toc(TimeStart);

17 end

18 Total_Nodes(iteration)=numnodes(G);

19 G.Nodes.Type=Label_List’;

20 figure()

21 plot(G, ’EdgeLabel ’,G.Edges.Weight, ’NodeLabel ’,G.Nodes.Type, ’LineWidth ’,1.5, ’NodeColor ’, ’y ’, ’MarkerSize ’,15, ’ArrowSize ’,10, ’EdgeColor ’, ’k ’, ’Layout ’, ’ c ircle ’)

22 title( ’ Final Graph’) �

[ September 7, 2018 at 10:46 – version 1.0 ]