theodoros alexandros karagkioules -  · introduction this work is the result of a 6 months...

67
INRIA:“The French Institute for Research in Com- puter Science and Automation ’’ Team COATI:“Combinatorics, Optimization, and Algorithms for Telecommunications’’ Research Report k-Maximum Matching and Applications Theodoros Alexandros KARAGKIOULES Supervisor: Nicolas NISSE Research Officer Inria

Upload: others

Post on 16-Jan-2020

4 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Theodoros Alexandros KARAGKIOULES -  · Introduction This work is the result of a 6 months internship, under the supervision of research O cer Nicolas NISSE. The original scope of

INRIAldquoThe French Institute for Research in Com-puter Science and Automation rsquorsquoTeam COATIldquoCombinatorics Optimization andAlgorithms for Telecommunicationsrsquorsquo

Research Report

k-Maximum Matching and Applications

Theodoros Alexandros KARAGKIOULES

Supervisor

Nicolas NISSEResearch OfficerInria

Contents

Contents 1

Introduction 3

1 Algorithms 511 Maximum matching 512 k-maximum matching 5

121 k-matching for Airport Slot assignment 6122 The case where k=3 6123 The case of Paths 7124 The case of the Spider 7

2 Application 921 Description 922 Reyni Erdos 1023 Barabasi Albert 1624 Amadeus Graphs 2325 Bipartite 2726 Bipartite with degree seq 32Appendix A 39

BipartiteGraphGeneratorpy 39RandomGraphGeneratorpy 44kequals3MaximumMatchingpy 46Plotmat 51

Bibliography 65

1

Introduction

This work is the result of a 6 months internship under the supervision of research OfficerNicolas NISSE

The original scope of the internship was the introduction to the k-maximum matchingproblem along with the application of a special case of the problem on a industrial-specific variant and the theoretical exploration of the k-maximum matching problem onspecific graph families

The Internship was divided into two independent stages that ran simultaneously

On the first stage of the internship inspiration was drawn from an application of thek- maximum matching on airport slot assignment As itrsquos described in the followingsections the k-maximum matching problem can be used for the reassignment of flightsto time slots for landing In collaboration with Amadeus the k-maximum matchingalgorithm was applied on actual data to test its efficiency

During the second phase of the internship all the combinatorial optimization aspects ofthe k-maximum problem (complexity etc) were introduced The case where k = 3 wasstudied and the proposed algorithm [7] for that case was implemented and applied onrandom graphs and on bipartite graphs that simulated the Amadeus data

Additionally based on a proposed algorithm for Paths [7] a new algorithm was pro-posed that computes the k-maximum matching on a specific type of tree the Spider

3

Chapter 1

Algorithms

11 Maximum matching

In this section the Classical Maximum matching is presented

Let G = (VE) be a graph A matching M sube E of G is a set of edges pairwisedisjoint A vertex v isin V is defined as covered by M if there is e isinM such that v isin eOtherwise v is said exposed The size of a maximum matching in G is denoted by micro(G)

The problem of computing a maximum matching has been widely studied and it iswell known that it can be solved in polynomial-time The most popular algorithm forcomputing the classical maximum matching is by Edmonds[4] This algorithm has beenused broadly in the calculations on random graphs that follow in the next chapter

Augmenting Paths A path P = (v0 middot middot middot vk) of G is a sequence of pairwise distinctvertices such that ei = vi vi+1 isin E for each 0 le i lt k The path P is said M -augmenting if v0 and vk are exposed and for any 0 le i lt k ei = vi vi+1 isin M ifand only if i is odd In particular an augmenting path has always an odd length A wellknown theorem of Claude Berge states that a matching M is maximum if and only ifthere are no M -augmenting paths [1]

Related work The first algorithm for solving the maximum matching problem inpolynomial-time in general graphs is due to Edmonds [4] Then many work has beendedicated to design more efficient algorithms In particular the algorithms in [5 6] arebased on augmenting paths in the non-decreasing order of their lengths

12 k-maximum matching

Let microk(GM) denote the size of a maximum matching that can be obtained fromM sube E in G by augmenting paths of length at most kk ge 1 where k is an odd integerTo define the k-Matching Problem one must compute a sequence of augmenting-paths

5

6 Algorithms

of length le k that allow to obtain from M a matching of size microk(GM)

In the cases k isin 1 3 it has been proven that the computational complexity of the k-Matching Problem is equivalent to the one of the classical maximum matching problem(without any constraint on the length of paths) Hence for k isin 1 3 it can be solvedin polynomial time

121 k-matching for Airport Slot assignment

The k-maximum matching problem has been found to have an application in the aviationindustry When an aircraft is approaching an airport it is assigned by Air Traffic Controla landing time (called slot) If there is a delay for any reason (weather conditions latearrival priority) it looses its slot and a new slot needs to by reassigned to it Howeverslots for landing are a scarce resource of the airports and to avoid conflicts and forsafety reasons Airline Operation Controllers have to regularly modify the assignment ofthe slots of the aircraft

This modification of the slot-assignment uses only two kinds of operations either assignaircraft A to a free slot or give A the slot of B and assign B to a free slot The problemis then the following

Let k ge 1 be an odd integer and let G be a graph and M be a matching of GWhat is the maximum size of a matching that can be obtained from M by using onlyaugmenting paths of length at most k

Let G = (X cup YE) be a bipartite graph X represents the set of aircraft and Yrepresents the set of available slots There is an edge between a isin X and s isin Y if theslot s is compatible with the schedules of aircraft A Let M be a matching of G thatcorresponds to a pre-established valid assignment of some slots to some aircraft Theproblem of reassignment of slots is equivalent to computing a maximum matching thatcan be obtained from M by augmenting only paths of length at most 3

122 The case where k=3

Let G be a graph and M sube E(G) be a matching of G An edge e isin E(G) M is saiduseless if e is incident to two edges of M ie if each endpoint of e is incident to oneedge of M An edge e isinM is said forced if at least one of its endpoints has degree onein G

Finally let G be the graph obtained from G and the matching M by first removingall useless edges (but keeping their endpoints) and then by removing the forced edgesand their endpoints Let M be the matching resulting from M in G ie M equals Mminus the forced edges Note that M has no useless edges nor forced edges Abusingthe notations we will identify the paths in G with some paths in G

12 k-maximum matching 7

This algorithm has been used to implement the k-maximum matching programme thatcomputes the data provided by Amadeus and also the randomly generated graphs of thefollowing chapter

123 The case of Paths

Let Q = (v1 middot middot middot vi) be the maximum alternating path containing v1 If Q is notaugmenting or if Q has length more than k (ie i gt k) the algorithm is appliedrecursively on P (v1 middot middot middot viminus1) Otherwise Q is augmented (it is added to the desiredsequence of paths) and the algorithm is applied recursively on P Q

Algorithm 1 k-matching(PnM)

Require A path Pn = (v1 middot middot middot vn) a matching M sube E(P ) and an odd integer k ge 1Ensure A sequence (Q1 middot middot middot Qr) of augmenting paths with r = microk(PM)minus |M |1 if n = 1 then return empty2 else3 Let 1 lt i le n be the smallest integer (at least 2) such that vi is exposed4 if v1 is not exposed OR i gt k then5 Let P prime = (vi middot middot middot vn) and M prime = M cap E(P prime) return k-matching(P primeM prime)6 else7 Let P prime = (vi+1 middot middot middot vn) and M prime = M cap E(P prime) return (v1 middot middot middot vi)cup

k-matching(P primeM prime)8 end if9 end if

124 The case of the Spider

Theorem 11 Let S be a spider andM its initial matching and (P1 Pr) a sequenceof augmenting paths of length le k such that microk(SM) = |M |+ r then exist (Q1 Qr)a sequence of augmenting paths of length le k such that at most one such path containsthe center C

Proof Let S be a spider and lets assume that the optimal sequence of augmentingpaths SP is known along with the set of branches Br (those paths of S from a leaf tothe nn of CAssume for contradiction that exist ge 2 augmenting paths that contain the center Cand let Pi and Pj be the first such paths Let Pi = (umi

C uni) and Pj =

(umj C unj

) and let Q = (umi C unj

) be the (augmenting) pathcontaining partially Pi the center C and partially Pj Since [C uni

] sub [C unj] in order

for Pj to be an augmenting path then exist H = (Pj Pi) Q Letrsquos also assume thatthere is a set of paths A = A1 At isin SP between Pi and Pj and A sube Brsuch that forallk isin 1 2 t Ak Pi = empty or Ak Pj = empty Also there is a set of pathsB = B1 Bf isin SP between Pi and Pj and B sube Br such that foralln isin 1 2 fBn is non intersecting with any paths in AQPi Pj and H Then the optimal sequenceof augmenting paths can be the following

8 Algorithms

P1 P2 P3 A1 At QB1 Bf H Pr where augmenting only path Q oncecan lead to the equivalently optimal solution

Algorithm 2 Spider algorithm(SM)

1 M prime = M2 Let there be a set of leaves λ1 λr3 xk is the nn of C in the path C rarr λk4 for i isin 1 r do5 for j 6= i do M primeprime=Path Algorithm(λi rarr λjM)6 for k isin i j do M primeprime=M primeprimecupPath Algorithm(λk rarr xkM)7 end for8 end for9 if M primeprime gt M prime then10 M prime = M primeprime

11 end if12 end for13 return M prime

Proof Let there be an optimal solution that is obtained by the paths in the sequenceQprime = (P prime1 P

primer) for the spider

Let there also be a set of paths from leaf to leaf PLL = Pll1 P lln a set ofbranches BR = Br1 Brm and a sequence of augmenting paths Q = (P1 Pr)such that for j isin 1 r Pj isin PLL and forall i 6= j isin 1 r Pi isin BR

Applying the path algorithm for Pj and then for the r minus 1 paths of Q and due toTheorem 21 it is ensured that the matching produced will lead to a feasible solutionsince C is never exposed

Due to the iterative nature of the algorithm it can be checked that all possible com-binations of Pj and Pi that construct Q are considered and that one of the solutionscomputed as above will be the initial optimal solution Qprime

Thus by induction Spider Algorithm will always produce an optimal matching on aSpider

Chapter 2

Application

21 Description

This chapter aims at providing the picture of analysis on the data provided by Amadeusthe bipartite graphs and the random graphs generated

The random graphs have been generated as purely random graphs based on the ReyniErdos and the Barabasi Albert with different values of connectivity probability or con-nectivity

The bipartite graphs were generated on the density of the Amadeus graphs to simu-late better the results Additionally an extra set of test have been made on bipartitegraphs that simulate the degree distribution of the Amadeus graphs Certain classesof degree distribution were selected and based on those 480 bipartite graphs have beengenerated

At every graph the classical matching is computed based on the Edmonds algorithmthen the k-matching algorithm is used as described in section 122 Lastly a greedyalgorithm is implemented to be used for comparison

The ultimate goal is to explore the efficiency of the k-matching algorithm for the caseof k = 3 and to compare it with the result of the Edmonds algorithm and of course theGreedy implementationThe results follow along with some comments

9

10 Application

22 Reyni Erdos

bull RNxy are randomly generated graphs with a fixed number of 1000 nodes

bull There are 6 categories based on the initial matching and probability p of connection

bull x = L S L When the initial matching is large and S when it is small

bull y = 1 2 3 1 when p = lognn

2 when p = 13

and 3 when p = lognn

+ 01

Computation time over |E|

Computation time over |E| - Comments

bull This is a very straightforward set of figures

22 Reyni Erdos 11

bull When the initial matching is sufficiently large then the forced edges are taken out(a process which takes a fragment of the computation time) and then the classicalmatching algorithm (Edmonds) is applied on a smaller graph(G) This reducessignificantly the computation time

bull When the initial matching is small then the computation time of the constraintalgorithm might be larger than that of Edmonds The reason is that the constraintalgorithm need some time to compute the useless and forced edges and thenEdmonds algorithm is applied on G G Thus the overall processing time issometimes larger

Sorted matching size

Sorted matching size - Comments

12 Application

bull This set of figures represents the ascending order of the Classical matching sizealong with its corresponding Constraint and Greedy equivalent

bull When the probability is sufficiently higher than the threshold lognn

then the threealgorithms produce identical results of optimal matching

bull For lower probability there is a difference between the results of the algorithms

bull the degree of that difference is depicted in the first set of figures presented

bull It is interesting to observe that a change on the Constraint algorithm is associatedwith a even more significant change in the Greedy algorithm

bull There is a difference only when the probability is at the connectedness threshholdlognn

bull The difference is very small compared to the size of the matching ( 500)

bull The difference in matching size appears mostly at the Greedy implementationwhen compared to the constraint algorithm

Sorted Ratios

22 Reyni Erdos 13

Sorted Ratios - Comments

bull This set of figures depicts the ratios VV

EE

∆∆

in ascending order of VV

bull It is evident that when the initial matching is large the amount of forced edges(and their endpoints) removed is high thus the ratio of Nodes and edges is verylow For higher probabilities almost all edges are removed as useless

bull For a smaller initial matching almost no forced edges (and their endpoints) areremoved which we conclude be the node ration being close to 1 There is somesmall amount of useless edges removed though since the ratio of edges is less butclose to 1

bull The ratio of ∆ for large initial matching follows the trend of the node ratio yetfor smaller initial matching it deviates significantly

14 Application

Sorted |E||V |

Sorted |E||V | - Comments

bull Although as graph density the ratio 2|E||V |(|V |minus1)

is considered in this set of figures

we evaluate the correlation of the ratio |E||V | of G and G since the density of G

could acquire values higher than that of G

bull The figures are calculated in ascending order for the ratio of G

bull For the case of large initial matching the two ratios for G and G remain almostconstant ( to the extent of the probability of each graph) since removing forcededges( and their endpoints) alters the |E| and |V | proportionately

22 Reyni Erdos 15

bull For the case of small initial matching we observe some deviation in the valuesof the ration for G and that is explained with the removal of only useless edgeswhich only alters the |E| and keeps |V | in the original values

Sorted ∆

Sorted ∆-Comments

bull In this set of figures the ascending order of the ∆ of G is associated with the ∆of G

bull There is no significant jump of the ∆ for each graph category which tells that thatwe are comparing a uniform distribution of random grapghs for each probabilitycase

16 Application

bull For larger initial matching we observe the difference in the ∆s of G and G giventhe removed forced edges( and their endpoints) At some cases the ∆ of G dropsto 0 since the vast majority of edges have been declared forced and removed alongwith their endpoints

bull For smaller initial matching the ∆s of G and G follow mostly the same trend onlya few number of different instances

23 Barabasi Albert

Graph characteristics Barabasi Albert

bull BAxy are randomly generated graphs with a fixed number of 1000 nodes

bull There are 6 categories based on ini matching and of attached edges m

bull x = L S L When the initial matching is large and S when it is small

bull y = 1 2 3 1 when m = [1 10] 2 when m = [20 50] and 3 m = [50 100]

Computation time over |E|

23 Barabasi Albert 17

Computation time over |E| - Comments

bull When the initial matching is sufficiently large then the forced edges are taken out(a process which takes a fragment of the computation time) and then the classicalmatching algorithm (Edmonds) is applied on a smaller graph(G) This reducessignificantly the computation time

bull When the initial matching is small then the computation time of the constraintalgorithm might be larger than that of Edmonds The reason is that the constraintalgorithm need some time to compute the useless and forced edges and thenEdmonds algorithm is applied on G G Thus the overall processing time issometimes larger

Sorted matching size

18 Application

Sorted matching size-Comments

bull In this graph the matching size of the classical algorithm is depicted in ascendingorder along with the corresponding constraint algorithm and greedy result

bull Here in the case where m is small for both cases of initial matching (small large)the result may vary greatly starting from a value of half the perfect matching withsmall differences between the results of the various algorithm implementations

bull For the other cases of m the results converge

bull This is explained as for small values of m the graph is disconnected

bull In the matching size difference set of figures a very noticing difference value ap-pears For the cases of small m( the number of existing nodes that a new node isconnected to at the creation of the graph) we can see that the difference in the

23 Barabasi Albert 19

matching size compared to that of the perfect matching could be up to 40 ofthat of the matching size So there are occasions where the matching size is 200edges when the perfect matching would have been 500

bull the difference between the Constraint matching and the classical matching andthe difference of the constraint matching and that of the greedy matching do notshow significant values

Sorted Ratios

Sorted Ratio s -Comments

bull This set of figures depicts the ratios VV

EE

∆∆

in ascending order of VV

20 Application

bull It is evident that when the initial matching is large the amount of forced edges(and their endpoints) removed is high thus the ratio of Nodes and edges is verylow For higher probabilities almost all edges are removed as useless

bull For a smaller initial matching almost no forced edges (and their endpoints) areremoved which we conclude be the node ration being close to 1 There is somesmall amount of useless edges removed though since the ratio of edges is less butclose to 1

bull The ratio of ∆ for large initial matching follows the trend of the node ratio yetfor smaller initial matching it deviates significantly

Sorted |E||V |

23 Barabasi Albert 21

Sorted |E||V | - Comments

bull Although as graph density the ratio 2|E||V |(|V |minus1)

is considered in this set of figures

we evaluate the correlation of the ratio |E||V | of G and G since the density of G

could acquire values higher than that of G

bull The figures are calculated in ascending order for the ratio of G

bull For the case of large initial matching the two ratios for G and G remain almostconstant ( to the extent of the edge attraction m of each graph) since removingforced edges( and their endpoints) alters the |E| and |V | proportionately

bull For the case of small initial matching we observe some deviation in the valuesof the ration for G and that is explained with the removal of only useless edgeswhich only alters the |E| and keeps |V | in the original values

Sorted ∆

22 Application

Sorted ∆-Comments

bull In this set of figures the ascending order of the ∆ of G is associated with the ∆of G

bull There is a significant jump of the ∆ for each graph category which tells that thatwe are not comparing a uniform distribution of random graphs and based on theedge attraction m the graphs can vary in form

bull For larger initial matching we observe the difference in the ∆s of G and G giventhe removed forced edges( and their endpoints) At some cases the ∆ of G dropsto 0 since the vast majority of edges have been declared forced and removed alongwith their endpoints What is interesting is that the ∆ of G oscilates within stablelimits

24 Amadeus Graphs 23

bull For smaller initial matching the ∆s of G and G follow mostly the same trend onlya few number of different instances

24 Amadeus Graphs

Graph characteristics Amadeus graphs

bull These are the bipartite graphs provided by Amadeus

Computation time over |E|

Computation time over |E| - Comments

24 Application

bull For every instance the computation time of the classical algorithm is always smallerto that of the constraint matching

bull This allows as to speculate that we always compute a smaller G which also impliesthat we always find a set of forced edges and useless

Sorted matching size

Sorted matching size - Comments

bull Size of matching has an upward trend since the magnitude of the graphs is notthe same for the 160 instances

bull No significant deviation is noticed as per the first graph

24 Amadeus Graphs 25

bull Except from deviation from the perfect matching (number of flights) where some-times it could get up to 40

bull For the Amadeus Bipartite graphs we can see that the difference of the Classicaland the constraint implementation is not more than 1 edge in the matching

bull There appears to be a difference of up to 24 edges between the Classical matchingand the Perfect matching which is computed as the number of flights

bull The greedy algorithm performs well with only a few instances deviating slightlyform the Constraint algorithm result

Sorted Ratios

Sorted Ratios - Comments

26 Application

bull

Sorted |E||V |

Sorted |E||V | - Comments

bull Density of the graphs shows that on average we have 25-3 available time slot perflight

bull The line for the same value for G shows that there is a large deviation for everyinstance which allows for the hypothesis that the amount of useless+forced edgesof G has no obvious correlation to that of G

25 Bipartite 27

Sorted ∆

Sorted ∆-Comments

bull As per the previous related graphs for ∆ there is in significant drop in the ∆ of Gand G

25 Bipartite

Graph characteristics Bipartite random Graphs

bull BIPxy are randomly generated graphs with a fixed number of 1000(n=500 andm=500) nodes

bull There are 6 categories based on ini matching and probability p

28 Application

bull Probability p has been chosen as such in order to simulate the |E||V | 25 of theAmadeus bipartite graphs

bull So in order to have about 2-4 edges for every node we choose accordingly theprobability p to choose one of the n lowastm possible edges

bull x = L S L When the initial matching is large and S when it is small

bull y = 1 2 3 1 when p = 18250

2 when p = 25250

and 3 when p = 34250

Computation time over

Computation time overedges-Comments

bull

25 Bipartite 29

Sorted matching size

Sorted matching size-Comments

bull In these set of graphs one can instantly notice that only a few instances with highprobability can reach a matching size equal to the perfect matching

bull For the case of the initial matching we witness that there is a gap between the lineof the classical matching and those of the constraint and greedy results suggestingsmaller matching sizes of 10-40 edges

bull For the case of the small initial matching the result of the constraint matchingis now close to the result of the classical matching yet the greedy algorithm stillshows a relevantly big difference

30 Application

bull In this set of bipartite graphs we can witness that the result of the Constraintmatching shows a difference with the classical matching when the initial matchingis large The difference is smaller as the probability gets larger

bull For the case of the small initial matching the above phenomenom does not occuryet the greedy results deviates from that of the constraint matching

bull As per the pefrect matching compared to the classical matching a difference of5-10 edges is evident at almost all cases

Sorted Ratios

Sorted Ratios-Comments

bull Great max degree deviation

25 Bipartite 31

bull Regardless of the probability the ration of nodes and edges seems to have similarbehaviour when compared to the respective graphs of the same matching scale

bull Same gap between nodes ration and edges ration for all cases

Sorted |E||V |

Sorted |E||V | - Comments

bull In these set of figures we witness that the |E||V | acquires values relevant to those ofthe amadeus graphs The random graphs were constructed to depict this similarity

bull For smaller initial matching the ratios for G and G show the same upward trendand also they acquire closer values It represents the decrease of the averagenumber of forced edges in comparison to the larger matching cases

32 Application

Sorted ∆

Sorted ∆-Comments

bull ∆ acquires the same min and max values for each probability case (expected)

bull Gap in the case of large initial matching

26 Bipartite with degree seq

Graph characteristics

bull DEQBIPxy are randomly generated graphs based on three different types of degreedistribution of the Amadeus graphs

26 Bipartite with degree seq 33

bull There are 6 categories based on ini matching and degree distribution

bull x = L S L When the initial matching is large and S when it is small

bull y = 1 2 3 1 when degree distribution is based on file 2 when degree distributionis based on file and 3 when degree distribution is based on file

Computation time over

34 Application

Computation time overedges-Comments

bull Greedy algorithm takes minimum amount of time

bull The smaller the initial matching the more smaller the difference in comoutationtime of Constraint and classical algorithm

bull Due to preprocessing and the fact that G and G are the almost identical thetotal time needed to apply the constraint algorithm is in some cases bigger

Sorted matching size

26 Bipartite with degree seq 35

Sorted matching size-Comments

bull Classical matching is equal to perfect matching in every case

bull Constraint and greedy have identical behaviour

bull The larger the spectrum of the degree sequence the more efficient the matching

Sorted Ratios

36 Application

Sorted Ratios-Comments

bull With large initial matching most of the edges are considenred uselles or forced andare removed thus the ratio is close(if not equal to) zero

bull For small matching and large degree sequence sectrum hte max degree remainsthe same Only a few forced edges (and their nodes) are removed apparently nonodes with max degree

Sorted |E||V |

26 Bipartite with degree seq 37

Sorted |E||V | - Comments

bull In these set of figures we witness that the |E||V | acquires values relevant to those ofthe amadeus graphs The random graphs were constructed to depict this similarity

bull For smaller initial matching the ratios for G and G show the same upward trendand also they acquire closer values It repsresent the decrease of the averagenumber of forced edges in comparison to the larger matching cases

Sorted ∆

38 Application

Sorted ∆-Comments

bull Big difference in max degree in large initial matching

bull Almost identical behaviour in the case of small initial matching

Appendix A 39

Appendix A

BipartiteGraphGeneratorpy

from future import divisionimport networkx as nx

from networkxalgorithms import approximationimport collectionsimport randomimport mathfrom networkxalgorithms import bipartiteif name == main

for i in range(1481)waqs 481index=1n=randomrandint(100 1000)

n1=95 was 500me1=118

n2=251 was 500me2=903

n3=165 was 500me3=412

m=0m1=0p=randomrandom()p1=18250p2=25250p3=34250print ip=05t1=randomrandint(0 1)print im2=randomrandint(n2minus1 n2+1)G = nxGraph()ma = nxGraph()

aseq1=[1 2 3 4 5 3]

bseq1=[4 3 3 1 2 2 1]

aseq2=[16 14 14 14 12 11]bseq2=[0 0 0 0 0 0]

aseq3=[8 7 8 8 8 8]bseq3=[0 0 0 0 0 0]

40 Application

print Gnumber of edges()if ilt=160

G=bipartiteconfiguration model(aseq1 bseq1 create using=None seed=None)A=nxadjacency matrix(G)for ii in range(0n1+me1)

maadd node(ii)A=[Rtodense()tolist()[0] for R in A]

printnummanumber of nodes()rl=randomsample(range(0n1+me1) n1+me1)m=0done vertices = set()for p in rlprintin fordone verticesadd(p)

neighbors = []list()for iii in range(0n1+me1)

if A[p][iii]==1neighborsappend(iii)

randomshuffle(neighbors)continue loop = Truedegree = len(neighbors)

print degreej = 0p4=randomrandom()while continue loop and (jltdegree)print in loop

next = neighbors[j]if next not in done vertices and p not in done vertices

done verticesadd(p)done verticesadd(next)if p4gt=07print added edge

maadd edge(pnext)m=m+1

continue loop = Falsej += 1

print matching listOfedgeprint maedge

MA=nxadjacency matrix(ma)print MA

MA=[Rtodense()tolist()[0] for R in MA]print MA

B=[ join(map(strR)) for R in A]MB=[ join(map(strR)) for R in MA]

C=njoin(B)+nMC=njoin(MB)+n

print nprint mprint m1

filea=str(i)+txtwith open(fileaw) as f

Appendix A 41

fwrite(str(n1+me1))fwrite(n)fwrite(str(n1+me1))fwrite(n)fwrite(str(m))fwrite(n)fwrite(n)fwrite(C)fwrite(n)fwrite(MC)

elif igt160 and ilt321G=bipartiteconfiguration model(aseq2 bseq2 create using=None seed=None)A=nxadjacency matrix(G)for ii in range(0n2+me2)

maadd node(ii)A=[Rtodense()tolist()[0] for R in A]

printnummanumber of nodes()rl=randomsample(range(0n2+me2) n2+me2)m=0done vertices = set()for p in rlprintin fordone verticesadd(p)

neighbors = []list()for iii in range(0n2+me2)

if A[p][iii]==1neighborsappend(iii)

randomshuffle(neighbors)continue loop = Truedegree = len(neighbors)

print degreej = 0p4=randomrandom()while continue loop and (jltdegree)

print in loopnext = neighbors[j]if next not in done vertices and p not in done vertices

done verticesadd(p)done verticesadd(next)if p4gt=07

print added edgemaadd edge(pnext)m=m+1

continue loop = Falsej += 1

print matching listOfedgeprint maedge

MA=nxadjacency matrix(ma)print MA

MA=[Rtodense()tolist()[0] for R in MA]print MA

B=[ join(map(strR)) for R in A]MB=[ join(map(strR)) for R in MA]

42 Application

C=njoin(B)+nMC=njoin(MB)+n

print nprint mprint m1

filea=str(i)+txtwith open(fileaw) as f

fwrite(str(n2+me2))fwrite(n)fwrite(str(n2+me2))fwrite(n)fwrite(str(m))fwrite(n)fwrite(n)fwrite(C)fwrite(n)fwrite(MC)

elseG=bipartiteconfiguration model(aseq3 bseq3 create using=None seed=None)A=nxadjacency matrix(G)for ii in range(0n3+me3)

maadd node(ii)A=[Rtodense()tolist()[0] for R in A]

printnummanumber of nodes()rl=randomsample(range(0n3+me3) n3+me3)m=0done vertices = set()for p in rlprintin fordone verticesadd(p)

neighbors = []list()for iii in range(0n3+me3)

if A[p][iii]==1neighborsappend(iii)

randomshuffle(neighbors)continue loop = Truedegree = len(neighbors)

print degreej = 0p4=randomrandom()while continue loop and (jltdegree)

print in loopnext = neighbors[j]if next not in done vertices and p not in done vertices

done verticesadd(p)done verticesadd(next)if p4gt=07print added edge

maadd edge(pnext)m=m+1

continue loop = Falsej += 1

Appendix A 43

print matching listOfedgeprint maedge

MA=nxadjacency matrix(ma)print MA

MA=[Rtodense()tolist()[0] for R in MA]print MA

B=[ join(map(strR)) for R in A]MB=[ join(map(strR)) for R in MA]

C=njoin(B)+nMC=njoin(MB)+n

print nprint mprint m1

filea=str(i)+txtwith open(fileaw) as f

fwrite(str(n3+me3))fwrite(n)fwrite(str(n3+me3))fwrite(n)fwrite(str(m))fwrite(n)fwrite(n)fwrite(C)fwrite(n)fwrite(MC)

print nRandom graphs with random matching have been generated

44 Application

RandomGraphGeneratorpy

from future import divisionimport networkx as nxfrom networkxalgorithms import approximationimport collectionsimport randomimport mathif name == main

for i in range(1481)index=1n=randomrandint(100 1000)

n=1000m=0m1=0p=randomrandom()p1=mathlog(n2)np2=13p3=mathlog(n2)n+01p=05t1=randomrandint(0 1)print im2=randomrandint(n2minus1 n2+1)G = nxGraph()ma = nxGraph()print nme1=randomrandint(1 10)me2=randomrandint(2050)me3=randomrandint(50100)if ilt241

if ilt=80G=nxfast gnp random graph(n p1 seed=None directed=False)

elif igt80 and ilt161G=nxfast gnp random graph(n p2 seed=None directed=False)

elseG=nxfast gnp random graph(n p3 seed=None directed=False)

elseif ilt=320

G=nxbarabasi albert graph(n me1 seed=None)elif igt320 and ilt401

G=nxbarabasi albert graph(n me2 seed=None)else

G=nxbarabasi albert graph(n me3 seed=None)A=nxadjacency matrix(G)for ii in range(0n)

maadd node(ii)A=[Rtodense()tolist()[0] for R in A]

rl=randomsample(range(0n) n)m=0

Appendix A 45

done vertices = set()for p in rl

done verticesadd(p)neighbors = []list()for iii in range(0n)

if A[p][iii]==1neighborsappend(iii)

randomshuffle(neighbors)continue loop = Truedegree = len(neighbors)j = 0p2=randomrandom()while continue loop and (jltdegree)

next = neighbors[j]if next not in done vertices and p not in done vertices

done verticesadd(p)done verticesadd(next)if p2gt=00 Larger probability for smaller initial matching

maadd edge(pnext)m=m+1

continue loop = Falsej += 1

print matching listOfedgeprint maedgeMA=nxadjacency matrix(ma)MA=[Rtodense()tolist()[0] for R in MA]print MAB=[ join(map(strR)) for R in A]MB=[ join(map(strR)) for R in MA]

C=njoin(B)+nMC=njoin(MB)+nprint MCprint nprint mprint m1filea=str(i)+txtwith open(fileaw) as f

fwrite(str(n))fwrite(n)fwrite(str(n))fwrite(n)fwrite(str(m))fwrite(n)fwrite(n)fwrite(C)fwrite(n)fwrite(MC)

print nRandom graphs with random matching have been generated

46 Application

kequals3MaximumMatchingpy

from future import divisionimport networkx as nxfrom networkxalgorithms import bipartiteimport matplotlibpyplot as pltimport collectionsimport timeitimport xlwtimport xlrdimport mathimport sys

Case for General Graphsdef forced edges(Gadj dict2matching dict1num nodesforced)

flagg=0for n in range(0num nodes)

for k in adj dict2[n]if ([k]==matching dict1[n])

count=0for l in range(0num nodes)

count=count+adj dict2[l]count(k)if (len(adj dict2[n])==1) or (count==1)

forcedadd edge(nk)Gremove edge(nk)Gremove node(n)Gremove node(k)printforced edgenktemp=kflagg=1for m in range (len(adj dict2[n])minus1minus1minus1)

adj dict2[adj dict2[n][m]]remove(n)adj dict2[n]remove(adj dict2[n][m])

if adj dict2[temp]for l in range(len(adj dict2[temp])minus1minus1minus1)

if (adj dict2[temp][l]=n)adj dict2[adj dict2[temp][l]]remove(temp)adj dict2[temp]remove(adj dict2[temp][l])

break

def useless edges(num nodesadj dict1matching dict1uselessadj dict2G)for n in range(0num nodes)

for k in adj dict1[n]if ([k]=matching dict1[n]) and matching dict1[n] and matching dict1[k]

uselessadd edge(nk)Gremove edge(n k)

Appendix A 47

tempa=kadj dict2[n]remove(k)adj dict2[tempa]remove(n)adj dict1[tempa]remove(n)

return G

def Greedy(num nodesadj dict3matching dict2)

for n in range(0num nodes)if matching dict2[n]

flag2=minus1flag3=minus1for v in adj dict3[n]

if not matching dict2[v]flag2=vbreak

for p in adj dict3[matching dict2[n][0]]if not matching dict2[p]

flag3=pbreak

if (flag2=minus1) and (flag3=minus1) and (flag2=flag3)tempr=matching dict2[n][0]matching dict2[n]=[flag2]matching dict2[flag2]=[n]matching dict2[tempr]=[flag3]matching dict2[flag3]=[tempr]

elsefor k in adj dict3[n]

if not matching dict2[k]matching dict2[n]=[k]matching dict2[k]=[n]break

yo1=0for i in range(0num nodes)

if matching dict2[i] and [i]==matching dict2[matching dict2[i][0]]yo1=yo1+1

greedy size=yo12return greedy size

def General()

INPUTSwb = xlwtWorkbook()ws = wbadd sheet(Results Random)book=xlrdopen workbook(filenames randomxls)

48 Application

style0 = xlwteasyxf(fontbold on)style1 = xlwteasyxf(num format str=0000)INPUTSwswrite(0 0File style0)wswrite(0 1 Nodesstyle0)wswrite(0 2 Initial matchingstyle0)wswrite(0 3 NodesGstyle0)wswrite(0 4 EdgesGstyle0)wswrite(0 5 MaxDegreeGstyle0)wswrite(0 6 NodesG hatstyle0)wswrite(0 7 EdgesG Hatstyle0)wswrite(0 8 Useless edgesstyle0)wswrite(0 9 Forced edgesstyle0)wswrite(0 10 MaxDegreeG Hatstyle0)wswrite(0 11 Classical matchingstyle0)wswrite(0 12 Final matchingstyle0)wswrite(0 13 Greedy matchingstyle0)wswrite(0 14 Time classicalstyle0)wswrite(0 15 Time algorithmstyle0)wswrite(0 16 Time greedystyle0)wswrite(0 17 Perfect matching ratiostyle0)wswrite(0 18 Nodes ratiostyle0)wswrite(0 19 Edges ratiostyle0)wswrite(0 20 Matching ratiostyle0)

print nWelcomeThis is an implementation for general random graphs It uses Edmonds algorithm to compute maximum matching on G Hatn

for index in range (1481)was 481

if (index==482)f=open(Algotel generaltxtr)readlines()

elsefilea=str(booksheet by index(0)cell(index0))s=fileareplace(textu)replace()f=open(sr)readlines()Truewswrite(index 0 s)

print index

num nodes=int([xstrip()split() for x in f][0][0])

num matching=int([xstrip()split() for x in f][2][0])

adj temp = [xstrip()split() for x in f][44+num nodes]adj=[map(intR) for R in adj temp]

matching temp=[xstrip()split() for x in f][4+num nodes+14+2num nodes+1]matching1=[map(intR) for R in matching temp]

adj dict1=i[ii for iix in enumerate(L) if x] for iL in enumerate(adj)adj dict2=i[ii for iix in enumerate(L) if x] for iL in enumerate(adj)

Appendix A 49

adj dict3=i[ii for iix in enumerate(L) if x] for iL in enumerate(adj)

matching dict1=i[ii for iix in enumerate(L) if x] for iL in enumerate(matching1)matching dict2=i[ii for iix in enumerate(L) if x] for iL in enumerate(matching1)print adj dict2print matching dict2wswrite(index 1 num nodes)wswrite(index 2 num matching)

G = nxGraph()

useless= nxGraph()forced = nxGraph()

Fill Graphfor n in range(0num nodes)

for k in adj dict1[n]Gadd edge(nk)

Gt=Gnumber of edges()wswrite(index 3 Gnumber of nodes())wswrite(index 4 Gnumber of edges())wswrite(index 5 max(Gdegree()values()))

Compute Edmonds classical matching on G for comparison

startB = timeitdefault timer()Classical Matching=nxmax weight matching(G maxcardinality=False)stopB = timeitdefault timer()

Compute Gˆ nad MˆstartC = timeitdefault timer()useless edges(num nodesadj dict1matching dict1uselessadj dict2G)forced edges(Gadj dict2matching dict1num nodesforced)Final Matching=nxmax weight matching(G maxcardinality=False)stopC = timeitdefault timer()

GreedystartG = timeitdefault timer()greedy size=Greedy(num nodesadj dict3matching dict2)stopG = timeitdefault timer()

wswrite(index 6 Gnumber of nodes())wswrite(index 7 Gnumber of edges())wswrite(index 8 uselessnumber of edges())wswrite(index 9 forcednumber of edges())if Gdegree()values()

wswrite(index 10 max(Gdegree()values()))else

50 Application

wswrite(index 10 0)wswrite(index 11 len(Classical Matching)2)wswrite(index 12 len(Final Matching)2+forcednumber of edges())wswrite(index 13 greedy size)wswrite(index 14 stopB minus startBstyle1)wswrite(index 15 stopC minus startCstyle1)wswrite(index 16 stopG minus startGstyle1)wswrite(index 17 (len(Final Matching)2+forcednumber of edges())(num nodes2)style1)wswrite(index 18 Gnumber of nodes()Gtstyle1)wswrite(index 19 Gnumber of edges()Gtstyle1)wswrite(index 20 (len(Final Matching)2+forcednumber of edges())(len(Classical Matching)2)style1)

wbsave(AA Results Random Reyni Large Bipartitexls)

Main function Here we must choose the input form of the dataif name == main

startA = timeitdefault timer()General()stopA = timeitdefault timer()

print nThis program has terminatednnRunning time for 480 files stopAminusstartAprint nnPlease open AA Results Random Reyni Largexls file to see the Results

Appendix A 51

Plotmat

clear allclose allload(RN1Lmat)load(RN1Smat)load(RN2Lmat)load(RN2Smat)load(RN3Lmat)load(RN3Smat)

Plotsh(1)=figure(NameHistogram of Matching size difference between Constraint Algorithm and Greedy AlgorithmNumberTitleoff)

RN1L Greedydiff=RN1L Final matchingminusRN1L Greedy matchingRN2L Greedydiff=RN2L Final matchingminusRN2L Greedy matchingRN3L Greedydiff=RN3L Final matchingminusRN3L Greedy matchingRN1S Greedydiff=RN1S Final matchingminusRN1S Greedy matchingRN2S Greedydiff=RN2S Final matchingminusRN2S Greedy matchingRN3S Greedydiff=RN3S Final matchingminusRN3S Greedy matching

RN1L Finaldiff=RN1L Classical matchingminusRN1L Final matchingRN2L Finaldiff=RN2L Classical matchingminusRN2L Final matchingRN3L Finaldiff=RN3L Classical matchingminusRN3L Final matchingRN1S Finaldiff=RN1S Classical matchingminusRN1S Final matchingRN2S Finaldiff=RN2S Classical matchingminusRN2S Final matchingRN3S Finaldiff=RN3S Classical matchingminusRN3S Final matching

RN1L Classicaldiff=(RN1L Nodes2)minusRN1L Classical matchingRN2L Classicaldiff=(RN2L Nodes2)minusRN2L Classical matchingRN3L Classicaldiff=(RN3L Nodes2)minusRN3L Classical matchingRN1S Classicaldiff=(RN1S Nodes2)minusRN1S Classical matchingRN2S Classicaldiff=(RN2S Nodes2)minusRN2S Classical matchingRN3S Classicaldiff=(RN3S Nodes2)minusRN3S Classical matching

subplot(231)hold onhistf(RN1L Greedydiff0110facecolorbfacealpha9edgealpha1)histf(RN1L Finaldiff0110facecolorrfacealpha5edgealpha1)histf(RN1L Classicaldiff0110facecolorgfacealpha5edgealpha1)legalpha(ConminusGreClasminusConPerfminusClasslocationnortheast)legend boxoffaxis tightxlabel(edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN1L)grid on

subplot(232)hold onhistf(RN2L Greedydiff0110facecolorbfacealpha9edgealpha1)

52 Application

histf(RN2L Finaldiff0110facecolorrfacealpha5edgealpha1)histf(RN2L Classicaldiff0110facecolorgfacealpha5edgealpha1)legalpha(ConminusGreClasminusConPerfminusClasslocationnortheast)legend boxoffaxis tightxlabel(edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN2L)grid on

subplot(233)hold onhistf(RN3L Greedydiff0110facecolorbfacealpha5edgealpha1)histf(RN3L Finaldiff0110facecolorrfacealpha5edgealpha1)histf(RN3L Classicaldiff0110facecolorgfacealpha5edgealpha1)legalpha(ConminusGreClasminusConPerfminusClasslocationnortheast)legend boxoffaxis tightxlabel(edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN3L)grid on

subplot(234)hold onhistf(RN1S Greedydiff0110facecolorbfacealpha5edgealpha1)histf(RN1S Finaldiff0110facecolorrfacealpha5edgealpha1)histf(RN1S Classicaldiff0110facecolorgfacealpha5edgealpha1)legalpha(ConminusGreClasminusConPerfminusClasslocationnortheast)legend boxoffaxis tightxlabel(edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(R1NS)grid on

subplot(235)hold onhistf(RN2S Greedydiff0110facecolorbfacealpha5edgealpha1)histf(RN2S Finaldiff0110facecolorrfacealpha5edgealpha1)histf(RN2S Classicaldiff0110facecolorgfacealpha5edgealpha1)legalpha(ConminusGreClasminusConPerfminusClasslocationnortheast)legend boxoffaxis tightxlabel(edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN2S)grid on

subplot(236)hold onhistf(RN3S Greedydiff0110facecolorbfacealpha5edgealpha1)histf(RN3S Finaldiff0110facecolorrfacealpha5edgealpha1)histf(RN3S Classicaldiff0110facecolorgfacealpha5edgealpha1)

Appendix A 53

legalpha(ConminusGreClasminusConPerfminusClasslocationnortheast)legend boxoffaxis tightgrid ontitle(RN3S)xlabel(edges) xminusaxis labelylabel(instances) yminusaxis labelset(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN1png minusr300)h(2)=figure(NameHistogram of Max Degree of G AND G HatNumberTitleoff)RN1L x=RN1L MaxDegreeGminusRN1L MaxDegreeG HatRN2L x=RN2L MaxDegreeGminusRN2L MaxDegreeG HatRN3L x=RN3L MaxDegreeGminusRN3L MaxDegreeG HatRN1S x=RN1S MaxDegreeGminusRN1S MaxDegreeG HatRN2S x=RN2S MaxDegreeGminusRN2S MaxDegreeG HatRN3S x=RN3S MaxDegreeGminusRN3S MaxDegreeG Hatsubplot(231)hold onhistf(RN1L MaxDegreeG0150facecolorbfacealpha5edgealpha1)histf(RN1L MaxDegreeG Hat0150facecolorrfacealpha5edgealpha1)histf(RN1L x0150facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightxlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN1L)grid on

subplot(232)hold onhistf(RN2L MaxDegreeG010500facecolorbfacealpha5edgealpha1)histf(RN2L MaxDegreeG Hat010500facecolorrfacealpha5edgealpha1)histf(RN2L x010500facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightxlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN2L)grid on

subplot(233)hold onhistf(RN3L MaxDegreeG010300facecolorbfacealpha5edgealpha1)histf(RN3L MaxDegreeG Hat010300facecolorrfacealpha5edgealpha1)histf(RN3L x010300facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightxlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN3L)

54 Application

grid on

subplot(234)hold onhistf(RN1S MaxDegreeG0150facecolorbfacealpha5edgealpha1)histf(RN1S MaxDegreeG Hat0150facecolorrfacealpha5edgealpha1)histf(RN1S x0150facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightxlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(R1NS)grid on

subplot(235)hold onhistf(RN2S MaxDegreeG010500facecolorbfacealpha5edgealpha1)histf(RN2S MaxDegreeG Hat010500facecolorrfacealpha5edgealpha1)histf(RN2S x010500facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightxlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN2S)grid on

subplot(236)hold onhistf(RN3S MaxDegreeG05300facecolorbfacealpha5edgealpha1)histf(RN3S MaxDegreeG Hat05300facecolorrfacealpha5edgealpha1)histf(RN3S x05300facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightgrid ontitle(RN3S)xlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labelset(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN2png minusr300)

h(3)=figure(NameComputation time over edgesNumberTitleoff)

subplot(231)hold onstem(RN1L EdgesGRN1L Time classicalg)stem(RN1L EdgesGRN1L Time algorithmro)stem(RN1L EdgesGRN1L Time greedybx)grid on

Appendix A 55

title(RN1L)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)

subplot(232)hold onstem(RN2L EdgesGRN2L Time classicalg)stem(RN2L EdgesGRN2L Time algorithmro)stem(RN2L EdgesGRN2L Time greedybx)grid ontitle(RN2L)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)

subplot(233)hold onstem(RN3L EdgesGRN3L Time classicalg)stem(RN3L EdgesGRN3L Time algorithmro)stem(RN3L EdgesGRN3L Time greedybx)grid ontitle(RN3L)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)

subplot(234)hold onstem(RN1S EdgesGRN1S Time classicalg)stem(RN1S EdgesGRN1S Time algorithmro)stem(RN1S EdgesGRN1S Time greedybx)grid ontitle(RN1S)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)

subplot(235)hold onstem(RN2S EdgesGRN2S Time classicalg)stem(RN2S EdgesGRN2S Time algorithmro)stem(RN2S EdgesGRN2S Time greedybx)grid ontitle(RN2S)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)

subplot(236)hold onstem(RN3S EdgesGRN3S Time classicalg)stem(RN3S EdgesGRN3S Time algorithmro)stem(RN3S EdgesGRN3S Time greedybx)

56 Application

grid ontitle(RN3S)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)set(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN3png minusr300)

h(4)=figure(NameSorted matching sizeNumberTitleoff)RN1L Sorted matching temp(1)=RN1L Classical matchingRN1L Sorted matching temp(2)=RN1L Final matchingRN1L Sorted matching temp(3)=RN1L Greedy matchingRN1L Sorted matching temp(4)=RN1L Initial matchingRN1L Sorted matching=sortrows(RN1L Sorted matching temp)

RN2L Sorted matching temp(1)=RN2L Classical matchingRN2L Sorted matching temp(2)=RN2L Final matchingRN2L Sorted matching temp(3)=RN2L Greedy matchingRN2L Sorted matching temp(4)=RN2L Initial matchingRN2L Sorted matching=sortrows(RN2L Sorted matching temp)

RN3L Sorted matching temp(1)=RN3L Classical matchingRN3L Sorted matching temp(2)=RN3L Final matchingRN3L Sorted matching temp(3)=RN3L Greedy matchingRN3L Sorted matching temp(4)=RN3L Initial matchingRN3L Sorted matching=sortrows(RN3L Sorted matching temp)

RN1S Sorted matching temp(1)=RN1S Classical matchingRN1S Sorted matching temp(2)=RN1S Final matchingRN1S Sorted matching temp(3)=RN1S Greedy matchingRN1S Sorted matching temp(4)=RN1S Initial matchingRN1S Sorted matching=sortrows(RN1S Sorted matching temp)

RN2S Sorted matching temp(1)=RN2S Classical matchingRN2S Sorted matching temp(2)=RN2S Final matchingRN2S Sorted matching temp(3)=RN2S Greedy matchingRN2S Sorted matching temp(4)=RN2S Initial matchingRN2S Sorted matching=sortrows(RN2S Sorted matching temp)

RN3S Sorted matching temp(1)=RN3S Classical matchingRN3S Sorted matching temp(2)=RN3S Final matchingRN3S Sorted matching temp(3)=RN3S Greedy matchingRN3S Sorted matching temp(4)=RN3S Initial matchingRN3S Sorted matching=sortrows(RN3S Sorted matching temp)

subplot(231)hold onplot(RN1L Sorted matching(1)b)plot(RN1L Sorted matching(2)g)plot(RN1L Sorted matching(3)r)plot(RN1L Sorted matching(4)m)

Appendix A 57

grid ontitle(RN1L)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)

subplot(232)hold onplot(RN2L Sorted matching(1)b)plot(RN2L Sorted matching(2)g)plot(RN2L Sorted matching(3)r)plot(RN2L Sorted matching(4)m)grid ontitle(RN2L)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)

subplot(233)hold onplot(RN3L Sorted matching(1)b)plot(RN3L Sorted matching(2)g)plot(RN3L Sorted matching(3)r)plot(RN3L Sorted matching(4)m)grid ontitle(RN3L)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)

subplot(234)hold onplot(RN1S Sorted matching(1)b)plot(RN1S Sorted matching(2)g)plot(RN1S Sorted matching(3)r)plot(RN1S Sorted matching(4)m)grid ontitle(RN1S)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)

subplot(235)hold onplot(RN2S Sorted matching(1)b)plot(RN2S Sorted matching(2)g)plot(RN2S Sorted matching(3)r)plot(RN2S Sorted matching(4)m)grid ontitle(RN2S)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)

58 Application

subplot(236)hold onplot(RN3S Sorted matching(1)b)plot(RN3S Sorted matching(2)g)plot(RN3S Sorted matching(3)r)plot(RN3S Sorted matching(4)m)grid ontitle(RN3S)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)set(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN4png minusr300)h(5)=figure(NameSorted RatiosNumberTitleoff)RN1L ratio1=RN1L NodesG hatRN1L NodesGRN2L ratio1=RN2L NodesG hatRN2L NodesGRN3L ratio1=RN3L NodesG hatRN3L NodesGRN1S ratio1=RN1S NodesG hatRN1S NodesGRN2S ratio1=RN2S NodesG hatRN2S NodesGRN3S ratio1=RN3S NodesG hatRN3S NodesG

RN1L ratio2=RN1L EdgesG HatRN1L EdgesGRN2L ratio2=RN2L EdgesG HatRN2L EdgesGRN3L ratio2=RN3L EdgesG HatRN3L EdgesGRN1S ratio2=RN1S EdgesG HatRN1S EdgesGRN2S ratio2=RN2S EdgesG HatRN2S EdgesGRN3S ratio2=RN3S EdgesG HatRN3S EdgesG

RN1L ratio3=RN1L MaxDegreeG HatRN1L MaxDegreeGRN2L ratio3=RN2L MaxDegreeG HatRN2L MaxDegreeGRN3L ratio3=RN3L MaxDegreeG HatRN3L MaxDegreeGRN1S ratio3=RN1S MaxDegreeG HatRN1S MaxDegreeGRN2S ratio3=RN2S MaxDegreeG HatRN2S MaxDegreeGRN3S ratio3=RN3S MaxDegreeG HatRN3S MaxDegreeG

RN1L ratio(1)=RN1L ratio1RN1L ratio(2)=RN1L ratio2RN1L ratio(3)=RN1L ratio3

RN2L ratio(1)=RN2L ratio1RN2L ratio(2)=RN2L ratio2RN2L ratio(3)=RN2L ratio3

RN3L ratio(1)=RN3L ratio1RN3L ratio(2)=RN3L ratio2RN3L ratio(3)=RN3L ratio3

RN1S ratio(1)=RN1S ratio1RN1S ratio(2)=RN1S ratio2RN1S ratio(3)=RN1S ratio3

RN2S ratio(1)=RN2S ratio1

Appendix A 59

RN2S ratio(2)=RN2S ratio2RN2S ratio(3)=RN2S ratio3

RN3S ratio(1)=RN3S ratio1RN3S ratio(2)=RN3S ratio2RN3S ratio(3)=RN3S ratio3

RN1L ratio sorted=sortrows(RN1L ratio)RN2L ratio sorted=sortrows(RN2L ratio)RN3L ratio sorted=sortrows(RN3L ratio)RN1S ratio sorted=sortrows(RN1S ratio)RN2S ratio sorted=sortrows(RN2S ratio)RN3S ratio sorted=sortrows(RN3S ratio)

subplot(231)hold onplot(RN1L ratio sorted(1)b)plot(RN1L ratio sorted(2)g)plot(RN1L ratio sorted(3)r)grid ontitle(RN1L)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)

subplot(232)hold onplot(RN2L ratio sorted(1)b)plot(RN2L ratio sorted(2)g)plot(RN2L ratio sorted(3)r)grid ontitle(RN2L)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)

subplot(233)hold onplot(RN3L ratio sorted(1)b)plot(RN3L ratio sorted(2)g)plot(RN3L ratio sorted(3)r)grid ontitle(RN3L)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)

subplot(234)hold onplot(RN1S ratio sorted(1)b)plot(RN1S ratio sorted(2)g)plot(RN1S ratio sorted(3)r)grid on

60 Application

title(RN1S)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)

subplot(235)hold onplot(RN2S ratio sorted(1)b)plot(RN2S ratio sorted(2)g)plot(RN2S ratio sorted(3)r)grid ontitle(RN2S)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)

subplot(236)hold onplot(RN3S ratio sorted(1)b)plot(RN3S ratio sorted(2)g)plot(RN3S ratio sorted(3)r)grid ontitle(RN3S)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)set(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN5png minusr300)

h(6)=figure(NameSorted edges over nodesNumberTitleoff)

RN1L DegreeG1=(RN1L EdgesG)(RN1L NodesG)RN1L DegreeG Hat1=(RN1L EdgesG Hat)(RN1L NodesG hat)

RN1L Degree temp1(1)=RN1L DegreeG1RN1L Degree temp1(2)=RN1L DegreeG Hat1RN1L Degree sorted1=sortrows(RN1L Degree temp1)subplot(231)hold on

plot(RN1L Degree sorted1(1)b)plot(RN1L Degree sorted1(2)g)grid ontitle(RN1L)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)

RN2L DegreeG1=(RN2L EdgesG)(RN2L NodesG)RN2L DegreeG Hat1=(RN2L EdgesG Hat)(RN2L NodesG hat)

RN2L Degree temp1(1)=RN2L DegreeG1

Appendix A 61

RN2L Degree temp1(2)=RN2L DegreeG Hat1RN2L Degree sorted1=sortrows(RN2L Degree temp1)

subplot(232)hold onplot(RN2L Degree sorted1(1)b)plot(RN2L Degree sorted1(2)g)grid ontitle(RN2L)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)

RN3L DegreeG1=(RN3L EdgesG)(RN3L NodesG)RN3L DegreeG Hat1=(RN3L EdgesG Hat)(RN3L NodesG hat)

RN3L Degree temp1(1)=RN3L DegreeG1RN3L Degree temp1(2)=RN3L DegreeG Hat1RN3L Degree sorted1=sortrows(RN3L Degree temp1)

subplot(233)hold onplot(RN3L Degree sorted1(1)b)plot(RN3L Degree sorted1(2)g)grid ontitle(RN3L)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)

RN1S DegreeG1=(RN1S EdgesG)(RN1S NodesG)RN1S DegreeG Hat1=(RN1S EdgesG Hat)(RN1S NodesG hat)

RN1S Degree temp1(1)=RN1S DegreeG1RN1S Degree temp1(2)=RN1S DegreeG Hat1RN1S Degree sorted1=sortrows(RN1S Degree temp1)

subplot(234)hold onplot(RN1S Degree sorted1(1)b)plot(RN1S Degree sorted1(2)g)grid ontitle(RN1S)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)

RN2S DegreeG1=(RN2S EdgesG)(RN2S NodesG)RN2S DegreeG Hat1=(RN2S EdgesG Hat)(RN2S NodesG hat)

RN2S Degree temp1(1)=RN2S DegreeG1

62 Application

RN2S Degree temp1(2)=RN2S DegreeG Hat1RN2S Degree sorted1=sortrows(RN2S Degree temp1)

subplot(235)hold onplot(RN2S Degree sorted1(1)b)plot(RN2S Degree sorted1(2)g)grid ontitle(RN2S)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)

RN3S DegreeG1=(RN3S EdgesG)(RN3S NodesG)RN3S DegreeG Hat1=(RN3S EdgesG Hat)(RN3S NodesG hat)

RN3S Degree temp1(1)=RN3S DegreeG1RN3S Degree temp1(2)=RN3S DegreeG Hat1RN3S Degree sorted1=sortrows(RN3S Degree temp1)

subplot(236)hold onplot(RN3S Degree sorted1(1)b)plot(RN3S Degree sorted1(2)g)grid ontitle(RN3S)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)set(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN6png minusr300)h(7)=figure(NameSorted mATCHED DEGREENumberTitleoff)RN1L ratioMax(1)=RN1L MaxDegreeGRN1L ratioMax(2)=RN1L MaxDegreeG Hat

RN1L ratio sortedMax=sortrows(RN1L ratioMax)subplot(231)hold onplot(RN1L ratio sortedMax(1)b)plot(RN1L ratio sortedMax(2)g)grid ontitle(RN1L)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)

RN2L ratioMax(1)=RN2L MaxDegreeGRN2L ratioMax(2)=RN2L MaxDegreeG Hat

RN2L ratio sortedMax=sortrows(RN2L ratioMax)subplot(232)

Appendix A 63

hold onplot(RN2L ratio sortedMax(1)b)plot(RN2L ratio sortedMax(2)g)grid ontitle(RN2L)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)

RN3L ratioMax(1)=RN3L MaxDegreeGRN3L ratioMax(2)=RN3L MaxDegreeG Hat

RN3L ratio sortedMax=sortrows(RN3L ratioMax)subplot(233)hold onplot(RN3L ratio sortedMax(1)b)plot(RN3L ratio sortedMax(2)g)grid ontitle(RN3L)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)

RN1S ratioMax(1)=RN1S MaxDegreeGRN1S ratioMax(2)=RN1S MaxDegreeG Hat

RN1S ratio sortedMax=sortrows(RN1S ratioMax)subplot(234)hold onplot(RN1S ratio sortedMax(1)b)plot(RN1S ratio sortedMax(2)g)grid ontitle(RN1S)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)

RN2S ratioMax(1)=RN2S MaxDegreeGRN2S ratioMax(2)=RN2S MaxDegreeG Hat

RN2S ratio sortedMax=sortrows(RN2S ratioMax)

subplot(235)hold onplot(RN2S ratio sortedMax(1)b)plot(RN2S ratio sortedMax(2)g)grid ontitle(RN2S)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)

RN3S ratioMax(1)=RN3S MaxDegreeGRN3S ratioMax(2)=RN3S MaxDegreeG Hat

64 Application

RN3S ratio sortedMax=sortrows(RN3S ratioMax)subplot(236)hold onplot(RN3S ratio sortedMax(1)b)plot(RN3S ratio sortedMax(2)g)grid ontitle(RN1L)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)set(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN7png minusr300)

tilefigs()(h)

Bibliography

[1] C Berge ldquoTWO THEOREMS IN GRAPH THEORYrdquo Proceedings of the NationalAcademy of Sciences of the United States of America vol 43 no 9 pp 842ndash844Sep 1957

[2] L Bui S Sanghavi and R Srikant ldquoDistributed link scheduling with constantoverheadrdquo IEEEACM Trans Netw vol 17 no 5 pp 1467ndash1480 2009

[3] R Duan and S Pettie ldquoLinear-time approximation for maximum weight matchingrdquoJ ACM vol 61 no 1 2014

[4] J Edmonds ldquoPaths trees and flowersrdquo Canadian Journal of Mathematics vol 17pp 449ndash467 1965

[5] J E Hopcroft and R M Karp ldquoAn n52 algorithm for maximum matchings inbipartite graphsrdquo SIAM J Comput vol 2 no 4 pp 225ndash231 1973

[6] S Micali and V V Vazirani ldquoAn O(radic|V ||E|) algorithm for finding maximum

matching in general graphsrdquo in 21st Symp on Foundations of Comp Sc (FOCS)IEEE 1980 pp 17ndash27

[7] N Nisse A Salch and V Weber ldquoRecovery of disrupted airline operationsrdquo 2015httphalinriafrSomething

[8] X Wu and R Srikant ldquoRegulated maximal matching A distributed schedulingalgorithm for multi-hop wireless networks with nodeexclusive spectrum sharingrdquo inIEEE Conf on Decision and Control 2005

65

  • Contents
  • Introduction
  • Algorithms
    • Maximum matching
    • k-maximum matching
      • k-matching for Airport Slot assignment
      • The case where k=3
      • The case of Paths
      • The case of the Spider
          • Application
            • Description
            • Reyni Erdos
            • Barabaacutesi Albert
            • Amadeus Graphs
            • Bipartite
            • Bipartite with degree seq
            • Appendix A
              • BipartiteGraphGeneratorpy
              • RandomGraphGeneratorpy
              • kequals3MaximumMatchingpy
              • Plotmat
                  • Bibliography
Page 2: Theodoros Alexandros KARAGKIOULES -  · Introduction This work is the result of a 6 months internship, under the supervision of research O cer Nicolas NISSE. The original scope of

Contents

Contents 1

Introduction 3

1 Algorithms 511 Maximum matching 512 k-maximum matching 5

121 k-matching for Airport Slot assignment 6122 The case where k=3 6123 The case of Paths 7124 The case of the Spider 7

2 Application 921 Description 922 Reyni Erdos 1023 Barabasi Albert 1624 Amadeus Graphs 2325 Bipartite 2726 Bipartite with degree seq 32Appendix A 39

BipartiteGraphGeneratorpy 39RandomGraphGeneratorpy 44kequals3MaximumMatchingpy 46Plotmat 51

Bibliography 65

1

Introduction

This work is the result of a 6 months internship under the supervision of research OfficerNicolas NISSE

The original scope of the internship was the introduction to the k-maximum matchingproblem along with the application of a special case of the problem on a industrial-specific variant and the theoretical exploration of the k-maximum matching problem onspecific graph families

The Internship was divided into two independent stages that ran simultaneously

On the first stage of the internship inspiration was drawn from an application of thek- maximum matching on airport slot assignment As itrsquos described in the followingsections the k-maximum matching problem can be used for the reassignment of flightsto time slots for landing In collaboration with Amadeus the k-maximum matchingalgorithm was applied on actual data to test its efficiency

During the second phase of the internship all the combinatorial optimization aspects ofthe k-maximum problem (complexity etc) were introduced The case where k = 3 wasstudied and the proposed algorithm [7] for that case was implemented and applied onrandom graphs and on bipartite graphs that simulated the Amadeus data

Additionally based on a proposed algorithm for Paths [7] a new algorithm was pro-posed that computes the k-maximum matching on a specific type of tree the Spider

3

Chapter 1

Algorithms

11 Maximum matching

In this section the Classical Maximum matching is presented

Let G = (VE) be a graph A matching M sube E of G is a set of edges pairwisedisjoint A vertex v isin V is defined as covered by M if there is e isinM such that v isin eOtherwise v is said exposed The size of a maximum matching in G is denoted by micro(G)

The problem of computing a maximum matching has been widely studied and it iswell known that it can be solved in polynomial-time The most popular algorithm forcomputing the classical maximum matching is by Edmonds[4] This algorithm has beenused broadly in the calculations on random graphs that follow in the next chapter

Augmenting Paths A path P = (v0 middot middot middot vk) of G is a sequence of pairwise distinctvertices such that ei = vi vi+1 isin E for each 0 le i lt k The path P is said M -augmenting if v0 and vk are exposed and for any 0 le i lt k ei = vi vi+1 isin M ifand only if i is odd In particular an augmenting path has always an odd length A wellknown theorem of Claude Berge states that a matching M is maximum if and only ifthere are no M -augmenting paths [1]

Related work The first algorithm for solving the maximum matching problem inpolynomial-time in general graphs is due to Edmonds [4] Then many work has beendedicated to design more efficient algorithms In particular the algorithms in [5 6] arebased on augmenting paths in the non-decreasing order of their lengths

12 k-maximum matching

Let microk(GM) denote the size of a maximum matching that can be obtained fromM sube E in G by augmenting paths of length at most kk ge 1 where k is an odd integerTo define the k-Matching Problem one must compute a sequence of augmenting-paths

5

6 Algorithms

of length le k that allow to obtain from M a matching of size microk(GM)

In the cases k isin 1 3 it has been proven that the computational complexity of the k-Matching Problem is equivalent to the one of the classical maximum matching problem(without any constraint on the length of paths) Hence for k isin 1 3 it can be solvedin polynomial time

121 k-matching for Airport Slot assignment

The k-maximum matching problem has been found to have an application in the aviationindustry When an aircraft is approaching an airport it is assigned by Air Traffic Controla landing time (called slot) If there is a delay for any reason (weather conditions latearrival priority) it looses its slot and a new slot needs to by reassigned to it Howeverslots for landing are a scarce resource of the airports and to avoid conflicts and forsafety reasons Airline Operation Controllers have to regularly modify the assignment ofthe slots of the aircraft

This modification of the slot-assignment uses only two kinds of operations either assignaircraft A to a free slot or give A the slot of B and assign B to a free slot The problemis then the following

Let k ge 1 be an odd integer and let G be a graph and M be a matching of GWhat is the maximum size of a matching that can be obtained from M by using onlyaugmenting paths of length at most k

Let G = (X cup YE) be a bipartite graph X represents the set of aircraft and Yrepresents the set of available slots There is an edge between a isin X and s isin Y if theslot s is compatible with the schedules of aircraft A Let M be a matching of G thatcorresponds to a pre-established valid assignment of some slots to some aircraft Theproblem of reassignment of slots is equivalent to computing a maximum matching thatcan be obtained from M by augmenting only paths of length at most 3

122 The case where k=3

Let G be a graph and M sube E(G) be a matching of G An edge e isin E(G) M is saiduseless if e is incident to two edges of M ie if each endpoint of e is incident to oneedge of M An edge e isinM is said forced if at least one of its endpoints has degree onein G

Finally let G be the graph obtained from G and the matching M by first removingall useless edges (but keeping their endpoints) and then by removing the forced edgesand their endpoints Let M be the matching resulting from M in G ie M equals Mminus the forced edges Note that M has no useless edges nor forced edges Abusingthe notations we will identify the paths in G with some paths in G

12 k-maximum matching 7

This algorithm has been used to implement the k-maximum matching programme thatcomputes the data provided by Amadeus and also the randomly generated graphs of thefollowing chapter

123 The case of Paths

Let Q = (v1 middot middot middot vi) be the maximum alternating path containing v1 If Q is notaugmenting or if Q has length more than k (ie i gt k) the algorithm is appliedrecursively on P (v1 middot middot middot viminus1) Otherwise Q is augmented (it is added to the desiredsequence of paths) and the algorithm is applied recursively on P Q

Algorithm 1 k-matching(PnM)

Require A path Pn = (v1 middot middot middot vn) a matching M sube E(P ) and an odd integer k ge 1Ensure A sequence (Q1 middot middot middot Qr) of augmenting paths with r = microk(PM)minus |M |1 if n = 1 then return empty2 else3 Let 1 lt i le n be the smallest integer (at least 2) such that vi is exposed4 if v1 is not exposed OR i gt k then5 Let P prime = (vi middot middot middot vn) and M prime = M cap E(P prime) return k-matching(P primeM prime)6 else7 Let P prime = (vi+1 middot middot middot vn) and M prime = M cap E(P prime) return (v1 middot middot middot vi)cup

k-matching(P primeM prime)8 end if9 end if

124 The case of the Spider

Theorem 11 Let S be a spider andM its initial matching and (P1 Pr) a sequenceof augmenting paths of length le k such that microk(SM) = |M |+ r then exist (Q1 Qr)a sequence of augmenting paths of length le k such that at most one such path containsthe center C

Proof Let S be a spider and lets assume that the optimal sequence of augmentingpaths SP is known along with the set of branches Br (those paths of S from a leaf tothe nn of CAssume for contradiction that exist ge 2 augmenting paths that contain the center Cand let Pi and Pj be the first such paths Let Pi = (umi

C uni) and Pj =

(umj C unj

) and let Q = (umi C unj

) be the (augmenting) pathcontaining partially Pi the center C and partially Pj Since [C uni

] sub [C unj] in order

for Pj to be an augmenting path then exist H = (Pj Pi) Q Letrsquos also assume thatthere is a set of paths A = A1 At isin SP between Pi and Pj and A sube Brsuch that forallk isin 1 2 t Ak Pi = empty or Ak Pj = empty Also there is a set of pathsB = B1 Bf isin SP between Pi and Pj and B sube Br such that foralln isin 1 2 fBn is non intersecting with any paths in AQPi Pj and H Then the optimal sequenceof augmenting paths can be the following

8 Algorithms

P1 P2 P3 A1 At QB1 Bf H Pr where augmenting only path Q oncecan lead to the equivalently optimal solution

Algorithm 2 Spider algorithm(SM)

1 M prime = M2 Let there be a set of leaves λ1 λr3 xk is the nn of C in the path C rarr λk4 for i isin 1 r do5 for j 6= i do M primeprime=Path Algorithm(λi rarr λjM)6 for k isin i j do M primeprime=M primeprimecupPath Algorithm(λk rarr xkM)7 end for8 end for9 if M primeprime gt M prime then10 M prime = M primeprime

11 end if12 end for13 return M prime

Proof Let there be an optimal solution that is obtained by the paths in the sequenceQprime = (P prime1 P

primer) for the spider

Let there also be a set of paths from leaf to leaf PLL = Pll1 P lln a set ofbranches BR = Br1 Brm and a sequence of augmenting paths Q = (P1 Pr)such that for j isin 1 r Pj isin PLL and forall i 6= j isin 1 r Pi isin BR

Applying the path algorithm for Pj and then for the r minus 1 paths of Q and due toTheorem 21 it is ensured that the matching produced will lead to a feasible solutionsince C is never exposed

Due to the iterative nature of the algorithm it can be checked that all possible com-binations of Pj and Pi that construct Q are considered and that one of the solutionscomputed as above will be the initial optimal solution Qprime

Thus by induction Spider Algorithm will always produce an optimal matching on aSpider

Chapter 2

Application

21 Description

This chapter aims at providing the picture of analysis on the data provided by Amadeusthe bipartite graphs and the random graphs generated

The random graphs have been generated as purely random graphs based on the ReyniErdos and the Barabasi Albert with different values of connectivity probability or con-nectivity

The bipartite graphs were generated on the density of the Amadeus graphs to simu-late better the results Additionally an extra set of test have been made on bipartitegraphs that simulate the degree distribution of the Amadeus graphs Certain classesof degree distribution were selected and based on those 480 bipartite graphs have beengenerated

At every graph the classical matching is computed based on the Edmonds algorithmthen the k-matching algorithm is used as described in section 122 Lastly a greedyalgorithm is implemented to be used for comparison

The ultimate goal is to explore the efficiency of the k-matching algorithm for the caseof k = 3 and to compare it with the result of the Edmonds algorithm and of course theGreedy implementationThe results follow along with some comments

9

10 Application

22 Reyni Erdos

bull RNxy are randomly generated graphs with a fixed number of 1000 nodes

bull There are 6 categories based on the initial matching and probability p of connection

bull x = L S L When the initial matching is large and S when it is small

bull y = 1 2 3 1 when p = lognn

2 when p = 13

and 3 when p = lognn

+ 01

Computation time over |E|

Computation time over |E| - Comments

bull This is a very straightforward set of figures

22 Reyni Erdos 11

bull When the initial matching is sufficiently large then the forced edges are taken out(a process which takes a fragment of the computation time) and then the classicalmatching algorithm (Edmonds) is applied on a smaller graph(G) This reducessignificantly the computation time

bull When the initial matching is small then the computation time of the constraintalgorithm might be larger than that of Edmonds The reason is that the constraintalgorithm need some time to compute the useless and forced edges and thenEdmonds algorithm is applied on G G Thus the overall processing time issometimes larger

Sorted matching size

Sorted matching size - Comments

12 Application

bull This set of figures represents the ascending order of the Classical matching sizealong with its corresponding Constraint and Greedy equivalent

bull When the probability is sufficiently higher than the threshold lognn

then the threealgorithms produce identical results of optimal matching

bull For lower probability there is a difference between the results of the algorithms

bull the degree of that difference is depicted in the first set of figures presented

bull It is interesting to observe that a change on the Constraint algorithm is associatedwith a even more significant change in the Greedy algorithm

bull There is a difference only when the probability is at the connectedness threshholdlognn

bull The difference is very small compared to the size of the matching ( 500)

bull The difference in matching size appears mostly at the Greedy implementationwhen compared to the constraint algorithm

Sorted Ratios

22 Reyni Erdos 13

Sorted Ratios - Comments

bull This set of figures depicts the ratios VV

EE

∆∆

in ascending order of VV

bull It is evident that when the initial matching is large the amount of forced edges(and their endpoints) removed is high thus the ratio of Nodes and edges is verylow For higher probabilities almost all edges are removed as useless

bull For a smaller initial matching almost no forced edges (and their endpoints) areremoved which we conclude be the node ration being close to 1 There is somesmall amount of useless edges removed though since the ratio of edges is less butclose to 1

bull The ratio of ∆ for large initial matching follows the trend of the node ratio yetfor smaller initial matching it deviates significantly

14 Application

Sorted |E||V |

Sorted |E||V | - Comments

bull Although as graph density the ratio 2|E||V |(|V |minus1)

is considered in this set of figures

we evaluate the correlation of the ratio |E||V | of G and G since the density of G

could acquire values higher than that of G

bull The figures are calculated in ascending order for the ratio of G

bull For the case of large initial matching the two ratios for G and G remain almostconstant ( to the extent of the probability of each graph) since removing forcededges( and their endpoints) alters the |E| and |V | proportionately

22 Reyni Erdos 15

bull For the case of small initial matching we observe some deviation in the valuesof the ration for G and that is explained with the removal of only useless edgeswhich only alters the |E| and keeps |V | in the original values

Sorted ∆

Sorted ∆-Comments

bull In this set of figures the ascending order of the ∆ of G is associated with the ∆of G

bull There is no significant jump of the ∆ for each graph category which tells that thatwe are comparing a uniform distribution of random grapghs for each probabilitycase

16 Application

bull For larger initial matching we observe the difference in the ∆s of G and G giventhe removed forced edges( and their endpoints) At some cases the ∆ of G dropsto 0 since the vast majority of edges have been declared forced and removed alongwith their endpoints

bull For smaller initial matching the ∆s of G and G follow mostly the same trend onlya few number of different instances

23 Barabasi Albert

Graph characteristics Barabasi Albert

bull BAxy are randomly generated graphs with a fixed number of 1000 nodes

bull There are 6 categories based on ini matching and of attached edges m

bull x = L S L When the initial matching is large and S when it is small

bull y = 1 2 3 1 when m = [1 10] 2 when m = [20 50] and 3 m = [50 100]

Computation time over |E|

23 Barabasi Albert 17

Computation time over |E| - Comments

bull When the initial matching is sufficiently large then the forced edges are taken out(a process which takes a fragment of the computation time) and then the classicalmatching algorithm (Edmonds) is applied on a smaller graph(G) This reducessignificantly the computation time

bull When the initial matching is small then the computation time of the constraintalgorithm might be larger than that of Edmonds The reason is that the constraintalgorithm need some time to compute the useless and forced edges and thenEdmonds algorithm is applied on G G Thus the overall processing time issometimes larger

Sorted matching size

18 Application

Sorted matching size-Comments

bull In this graph the matching size of the classical algorithm is depicted in ascendingorder along with the corresponding constraint algorithm and greedy result

bull Here in the case where m is small for both cases of initial matching (small large)the result may vary greatly starting from a value of half the perfect matching withsmall differences between the results of the various algorithm implementations

bull For the other cases of m the results converge

bull This is explained as for small values of m the graph is disconnected

bull In the matching size difference set of figures a very noticing difference value ap-pears For the cases of small m( the number of existing nodes that a new node isconnected to at the creation of the graph) we can see that the difference in the

23 Barabasi Albert 19

matching size compared to that of the perfect matching could be up to 40 ofthat of the matching size So there are occasions where the matching size is 200edges when the perfect matching would have been 500

bull the difference between the Constraint matching and the classical matching andthe difference of the constraint matching and that of the greedy matching do notshow significant values

Sorted Ratios

Sorted Ratio s -Comments

bull This set of figures depicts the ratios VV

EE

∆∆

in ascending order of VV

20 Application

bull It is evident that when the initial matching is large the amount of forced edges(and their endpoints) removed is high thus the ratio of Nodes and edges is verylow For higher probabilities almost all edges are removed as useless

bull For a smaller initial matching almost no forced edges (and their endpoints) areremoved which we conclude be the node ration being close to 1 There is somesmall amount of useless edges removed though since the ratio of edges is less butclose to 1

bull The ratio of ∆ for large initial matching follows the trend of the node ratio yetfor smaller initial matching it deviates significantly

Sorted |E||V |

23 Barabasi Albert 21

Sorted |E||V | - Comments

bull Although as graph density the ratio 2|E||V |(|V |minus1)

is considered in this set of figures

we evaluate the correlation of the ratio |E||V | of G and G since the density of G

could acquire values higher than that of G

bull The figures are calculated in ascending order for the ratio of G

bull For the case of large initial matching the two ratios for G and G remain almostconstant ( to the extent of the edge attraction m of each graph) since removingforced edges( and their endpoints) alters the |E| and |V | proportionately

bull For the case of small initial matching we observe some deviation in the valuesof the ration for G and that is explained with the removal of only useless edgeswhich only alters the |E| and keeps |V | in the original values

Sorted ∆

22 Application

Sorted ∆-Comments

bull In this set of figures the ascending order of the ∆ of G is associated with the ∆of G

bull There is a significant jump of the ∆ for each graph category which tells that thatwe are not comparing a uniform distribution of random graphs and based on theedge attraction m the graphs can vary in form

bull For larger initial matching we observe the difference in the ∆s of G and G giventhe removed forced edges( and their endpoints) At some cases the ∆ of G dropsto 0 since the vast majority of edges have been declared forced and removed alongwith their endpoints What is interesting is that the ∆ of G oscilates within stablelimits

24 Amadeus Graphs 23

bull For smaller initial matching the ∆s of G and G follow mostly the same trend onlya few number of different instances

24 Amadeus Graphs

Graph characteristics Amadeus graphs

bull These are the bipartite graphs provided by Amadeus

Computation time over |E|

Computation time over |E| - Comments

24 Application

bull For every instance the computation time of the classical algorithm is always smallerto that of the constraint matching

bull This allows as to speculate that we always compute a smaller G which also impliesthat we always find a set of forced edges and useless

Sorted matching size

Sorted matching size - Comments

bull Size of matching has an upward trend since the magnitude of the graphs is notthe same for the 160 instances

bull No significant deviation is noticed as per the first graph

24 Amadeus Graphs 25

bull Except from deviation from the perfect matching (number of flights) where some-times it could get up to 40

bull For the Amadeus Bipartite graphs we can see that the difference of the Classicaland the constraint implementation is not more than 1 edge in the matching

bull There appears to be a difference of up to 24 edges between the Classical matchingand the Perfect matching which is computed as the number of flights

bull The greedy algorithm performs well with only a few instances deviating slightlyform the Constraint algorithm result

Sorted Ratios

Sorted Ratios - Comments

26 Application

bull

Sorted |E||V |

Sorted |E||V | - Comments

bull Density of the graphs shows that on average we have 25-3 available time slot perflight

bull The line for the same value for G shows that there is a large deviation for everyinstance which allows for the hypothesis that the amount of useless+forced edgesof G has no obvious correlation to that of G

25 Bipartite 27

Sorted ∆

Sorted ∆-Comments

bull As per the previous related graphs for ∆ there is in significant drop in the ∆ of Gand G

25 Bipartite

Graph characteristics Bipartite random Graphs

bull BIPxy are randomly generated graphs with a fixed number of 1000(n=500 andm=500) nodes

bull There are 6 categories based on ini matching and probability p

28 Application

bull Probability p has been chosen as such in order to simulate the |E||V | 25 of theAmadeus bipartite graphs

bull So in order to have about 2-4 edges for every node we choose accordingly theprobability p to choose one of the n lowastm possible edges

bull x = L S L When the initial matching is large and S when it is small

bull y = 1 2 3 1 when p = 18250

2 when p = 25250

and 3 when p = 34250

Computation time over

Computation time overedges-Comments

bull

25 Bipartite 29

Sorted matching size

Sorted matching size-Comments

bull In these set of graphs one can instantly notice that only a few instances with highprobability can reach a matching size equal to the perfect matching

bull For the case of the initial matching we witness that there is a gap between the lineof the classical matching and those of the constraint and greedy results suggestingsmaller matching sizes of 10-40 edges

bull For the case of the small initial matching the result of the constraint matchingis now close to the result of the classical matching yet the greedy algorithm stillshows a relevantly big difference

30 Application

bull In this set of bipartite graphs we can witness that the result of the Constraintmatching shows a difference with the classical matching when the initial matchingis large The difference is smaller as the probability gets larger

bull For the case of the small initial matching the above phenomenom does not occuryet the greedy results deviates from that of the constraint matching

bull As per the pefrect matching compared to the classical matching a difference of5-10 edges is evident at almost all cases

Sorted Ratios

Sorted Ratios-Comments

bull Great max degree deviation

25 Bipartite 31

bull Regardless of the probability the ration of nodes and edges seems to have similarbehaviour when compared to the respective graphs of the same matching scale

bull Same gap between nodes ration and edges ration for all cases

Sorted |E||V |

Sorted |E||V | - Comments

bull In these set of figures we witness that the |E||V | acquires values relevant to those ofthe amadeus graphs The random graphs were constructed to depict this similarity

bull For smaller initial matching the ratios for G and G show the same upward trendand also they acquire closer values It represents the decrease of the averagenumber of forced edges in comparison to the larger matching cases

32 Application

Sorted ∆

Sorted ∆-Comments

bull ∆ acquires the same min and max values for each probability case (expected)

bull Gap in the case of large initial matching

26 Bipartite with degree seq

Graph characteristics

bull DEQBIPxy are randomly generated graphs based on three different types of degreedistribution of the Amadeus graphs

26 Bipartite with degree seq 33

bull There are 6 categories based on ini matching and degree distribution

bull x = L S L When the initial matching is large and S when it is small

bull y = 1 2 3 1 when degree distribution is based on file 2 when degree distributionis based on file and 3 when degree distribution is based on file

Computation time over

34 Application

Computation time overedges-Comments

bull Greedy algorithm takes minimum amount of time

bull The smaller the initial matching the more smaller the difference in comoutationtime of Constraint and classical algorithm

bull Due to preprocessing and the fact that G and G are the almost identical thetotal time needed to apply the constraint algorithm is in some cases bigger

Sorted matching size

26 Bipartite with degree seq 35

Sorted matching size-Comments

bull Classical matching is equal to perfect matching in every case

bull Constraint and greedy have identical behaviour

bull The larger the spectrum of the degree sequence the more efficient the matching

Sorted Ratios

36 Application

Sorted Ratios-Comments

bull With large initial matching most of the edges are considenred uselles or forced andare removed thus the ratio is close(if not equal to) zero

bull For small matching and large degree sequence sectrum hte max degree remainsthe same Only a few forced edges (and their nodes) are removed apparently nonodes with max degree

Sorted |E||V |

26 Bipartite with degree seq 37

Sorted |E||V | - Comments

bull In these set of figures we witness that the |E||V | acquires values relevant to those ofthe amadeus graphs The random graphs were constructed to depict this similarity

bull For smaller initial matching the ratios for G and G show the same upward trendand also they acquire closer values It repsresent the decrease of the averagenumber of forced edges in comparison to the larger matching cases

Sorted ∆

38 Application

Sorted ∆-Comments

bull Big difference in max degree in large initial matching

bull Almost identical behaviour in the case of small initial matching

Appendix A 39

Appendix A

BipartiteGraphGeneratorpy

from future import divisionimport networkx as nx

from networkxalgorithms import approximationimport collectionsimport randomimport mathfrom networkxalgorithms import bipartiteif name == main

for i in range(1481)waqs 481index=1n=randomrandint(100 1000)

n1=95 was 500me1=118

n2=251 was 500me2=903

n3=165 was 500me3=412

m=0m1=0p=randomrandom()p1=18250p2=25250p3=34250print ip=05t1=randomrandint(0 1)print im2=randomrandint(n2minus1 n2+1)G = nxGraph()ma = nxGraph()

aseq1=[1 2 3 4 5 3]

bseq1=[4 3 3 1 2 2 1]

aseq2=[16 14 14 14 12 11]bseq2=[0 0 0 0 0 0]

aseq3=[8 7 8 8 8 8]bseq3=[0 0 0 0 0 0]

40 Application

print Gnumber of edges()if ilt=160

G=bipartiteconfiguration model(aseq1 bseq1 create using=None seed=None)A=nxadjacency matrix(G)for ii in range(0n1+me1)

maadd node(ii)A=[Rtodense()tolist()[0] for R in A]

printnummanumber of nodes()rl=randomsample(range(0n1+me1) n1+me1)m=0done vertices = set()for p in rlprintin fordone verticesadd(p)

neighbors = []list()for iii in range(0n1+me1)

if A[p][iii]==1neighborsappend(iii)

randomshuffle(neighbors)continue loop = Truedegree = len(neighbors)

print degreej = 0p4=randomrandom()while continue loop and (jltdegree)print in loop

next = neighbors[j]if next not in done vertices and p not in done vertices

done verticesadd(p)done verticesadd(next)if p4gt=07print added edge

maadd edge(pnext)m=m+1

continue loop = Falsej += 1

print matching listOfedgeprint maedge

MA=nxadjacency matrix(ma)print MA

MA=[Rtodense()tolist()[0] for R in MA]print MA

B=[ join(map(strR)) for R in A]MB=[ join(map(strR)) for R in MA]

C=njoin(B)+nMC=njoin(MB)+n

print nprint mprint m1

filea=str(i)+txtwith open(fileaw) as f

Appendix A 41

fwrite(str(n1+me1))fwrite(n)fwrite(str(n1+me1))fwrite(n)fwrite(str(m))fwrite(n)fwrite(n)fwrite(C)fwrite(n)fwrite(MC)

elif igt160 and ilt321G=bipartiteconfiguration model(aseq2 bseq2 create using=None seed=None)A=nxadjacency matrix(G)for ii in range(0n2+me2)

maadd node(ii)A=[Rtodense()tolist()[0] for R in A]

printnummanumber of nodes()rl=randomsample(range(0n2+me2) n2+me2)m=0done vertices = set()for p in rlprintin fordone verticesadd(p)

neighbors = []list()for iii in range(0n2+me2)

if A[p][iii]==1neighborsappend(iii)

randomshuffle(neighbors)continue loop = Truedegree = len(neighbors)

print degreej = 0p4=randomrandom()while continue loop and (jltdegree)

print in loopnext = neighbors[j]if next not in done vertices and p not in done vertices

done verticesadd(p)done verticesadd(next)if p4gt=07

print added edgemaadd edge(pnext)m=m+1

continue loop = Falsej += 1

print matching listOfedgeprint maedge

MA=nxadjacency matrix(ma)print MA

MA=[Rtodense()tolist()[0] for R in MA]print MA

B=[ join(map(strR)) for R in A]MB=[ join(map(strR)) for R in MA]

42 Application

C=njoin(B)+nMC=njoin(MB)+n

print nprint mprint m1

filea=str(i)+txtwith open(fileaw) as f

fwrite(str(n2+me2))fwrite(n)fwrite(str(n2+me2))fwrite(n)fwrite(str(m))fwrite(n)fwrite(n)fwrite(C)fwrite(n)fwrite(MC)

elseG=bipartiteconfiguration model(aseq3 bseq3 create using=None seed=None)A=nxadjacency matrix(G)for ii in range(0n3+me3)

maadd node(ii)A=[Rtodense()tolist()[0] for R in A]

printnummanumber of nodes()rl=randomsample(range(0n3+me3) n3+me3)m=0done vertices = set()for p in rlprintin fordone verticesadd(p)

neighbors = []list()for iii in range(0n3+me3)

if A[p][iii]==1neighborsappend(iii)

randomshuffle(neighbors)continue loop = Truedegree = len(neighbors)

print degreej = 0p4=randomrandom()while continue loop and (jltdegree)

print in loopnext = neighbors[j]if next not in done vertices and p not in done vertices

done verticesadd(p)done verticesadd(next)if p4gt=07print added edge

maadd edge(pnext)m=m+1

continue loop = Falsej += 1

Appendix A 43

print matching listOfedgeprint maedge

MA=nxadjacency matrix(ma)print MA

MA=[Rtodense()tolist()[0] for R in MA]print MA

B=[ join(map(strR)) for R in A]MB=[ join(map(strR)) for R in MA]

C=njoin(B)+nMC=njoin(MB)+n

print nprint mprint m1

filea=str(i)+txtwith open(fileaw) as f

fwrite(str(n3+me3))fwrite(n)fwrite(str(n3+me3))fwrite(n)fwrite(str(m))fwrite(n)fwrite(n)fwrite(C)fwrite(n)fwrite(MC)

print nRandom graphs with random matching have been generated

44 Application

RandomGraphGeneratorpy

from future import divisionimport networkx as nxfrom networkxalgorithms import approximationimport collectionsimport randomimport mathif name == main

for i in range(1481)index=1n=randomrandint(100 1000)

n=1000m=0m1=0p=randomrandom()p1=mathlog(n2)np2=13p3=mathlog(n2)n+01p=05t1=randomrandint(0 1)print im2=randomrandint(n2minus1 n2+1)G = nxGraph()ma = nxGraph()print nme1=randomrandint(1 10)me2=randomrandint(2050)me3=randomrandint(50100)if ilt241

if ilt=80G=nxfast gnp random graph(n p1 seed=None directed=False)

elif igt80 and ilt161G=nxfast gnp random graph(n p2 seed=None directed=False)

elseG=nxfast gnp random graph(n p3 seed=None directed=False)

elseif ilt=320

G=nxbarabasi albert graph(n me1 seed=None)elif igt320 and ilt401

G=nxbarabasi albert graph(n me2 seed=None)else

G=nxbarabasi albert graph(n me3 seed=None)A=nxadjacency matrix(G)for ii in range(0n)

maadd node(ii)A=[Rtodense()tolist()[0] for R in A]

rl=randomsample(range(0n) n)m=0

Appendix A 45

done vertices = set()for p in rl

done verticesadd(p)neighbors = []list()for iii in range(0n)

if A[p][iii]==1neighborsappend(iii)

randomshuffle(neighbors)continue loop = Truedegree = len(neighbors)j = 0p2=randomrandom()while continue loop and (jltdegree)

next = neighbors[j]if next not in done vertices and p not in done vertices

done verticesadd(p)done verticesadd(next)if p2gt=00 Larger probability for smaller initial matching

maadd edge(pnext)m=m+1

continue loop = Falsej += 1

print matching listOfedgeprint maedgeMA=nxadjacency matrix(ma)MA=[Rtodense()tolist()[0] for R in MA]print MAB=[ join(map(strR)) for R in A]MB=[ join(map(strR)) for R in MA]

C=njoin(B)+nMC=njoin(MB)+nprint MCprint nprint mprint m1filea=str(i)+txtwith open(fileaw) as f

fwrite(str(n))fwrite(n)fwrite(str(n))fwrite(n)fwrite(str(m))fwrite(n)fwrite(n)fwrite(C)fwrite(n)fwrite(MC)

print nRandom graphs with random matching have been generated

46 Application

kequals3MaximumMatchingpy

from future import divisionimport networkx as nxfrom networkxalgorithms import bipartiteimport matplotlibpyplot as pltimport collectionsimport timeitimport xlwtimport xlrdimport mathimport sys

Case for General Graphsdef forced edges(Gadj dict2matching dict1num nodesforced)

flagg=0for n in range(0num nodes)

for k in adj dict2[n]if ([k]==matching dict1[n])

count=0for l in range(0num nodes)

count=count+adj dict2[l]count(k)if (len(adj dict2[n])==1) or (count==1)

forcedadd edge(nk)Gremove edge(nk)Gremove node(n)Gremove node(k)printforced edgenktemp=kflagg=1for m in range (len(adj dict2[n])minus1minus1minus1)

adj dict2[adj dict2[n][m]]remove(n)adj dict2[n]remove(adj dict2[n][m])

if adj dict2[temp]for l in range(len(adj dict2[temp])minus1minus1minus1)

if (adj dict2[temp][l]=n)adj dict2[adj dict2[temp][l]]remove(temp)adj dict2[temp]remove(adj dict2[temp][l])

break

def useless edges(num nodesadj dict1matching dict1uselessadj dict2G)for n in range(0num nodes)

for k in adj dict1[n]if ([k]=matching dict1[n]) and matching dict1[n] and matching dict1[k]

uselessadd edge(nk)Gremove edge(n k)

Appendix A 47

tempa=kadj dict2[n]remove(k)adj dict2[tempa]remove(n)adj dict1[tempa]remove(n)

return G

def Greedy(num nodesadj dict3matching dict2)

for n in range(0num nodes)if matching dict2[n]

flag2=minus1flag3=minus1for v in adj dict3[n]

if not matching dict2[v]flag2=vbreak

for p in adj dict3[matching dict2[n][0]]if not matching dict2[p]

flag3=pbreak

if (flag2=minus1) and (flag3=minus1) and (flag2=flag3)tempr=matching dict2[n][0]matching dict2[n]=[flag2]matching dict2[flag2]=[n]matching dict2[tempr]=[flag3]matching dict2[flag3]=[tempr]

elsefor k in adj dict3[n]

if not matching dict2[k]matching dict2[n]=[k]matching dict2[k]=[n]break

yo1=0for i in range(0num nodes)

if matching dict2[i] and [i]==matching dict2[matching dict2[i][0]]yo1=yo1+1

greedy size=yo12return greedy size

def General()

INPUTSwb = xlwtWorkbook()ws = wbadd sheet(Results Random)book=xlrdopen workbook(filenames randomxls)

48 Application

style0 = xlwteasyxf(fontbold on)style1 = xlwteasyxf(num format str=0000)INPUTSwswrite(0 0File style0)wswrite(0 1 Nodesstyle0)wswrite(0 2 Initial matchingstyle0)wswrite(0 3 NodesGstyle0)wswrite(0 4 EdgesGstyle0)wswrite(0 5 MaxDegreeGstyle0)wswrite(0 6 NodesG hatstyle0)wswrite(0 7 EdgesG Hatstyle0)wswrite(0 8 Useless edgesstyle0)wswrite(0 9 Forced edgesstyle0)wswrite(0 10 MaxDegreeG Hatstyle0)wswrite(0 11 Classical matchingstyle0)wswrite(0 12 Final matchingstyle0)wswrite(0 13 Greedy matchingstyle0)wswrite(0 14 Time classicalstyle0)wswrite(0 15 Time algorithmstyle0)wswrite(0 16 Time greedystyle0)wswrite(0 17 Perfect matching ratiostyle0)wswrite(0 18 Nodes ratiostyle0)wswrite(0 19 Edges ratiostyle0)wswrite(0 20 Matching ratiostyle0)

print nWelcomeThis is an implementation for general random graphs It uses Edmonds algorithm to compute maximum matching on G Hatn

for index in range (1481)was 481

if (index==482)f=open(Algotel generaltxtr)readlines()

elsefilea=str(booksheet by index(0)cell(index0))s=fileareplace(textu)replace()f=open(sr)readlines()Truewswrite(index 0 s)

print index

num nodes=int([xstrip()split() for x in f][0][0])

num matching=int([xstrip()split() for x in f][2][0])

adj temp = [xstrip()split() for x in f][44+num nodes]adj=[map(intR) for R in adj temp]

matching temp=[xstrip()split() for x in f][4+num nodes+14+2num nodes+1]matching1=[map(intR) for R in matching temp]

adj dict1=i[ii for iix in enumerate(L) if x] for iL in enumerate(adj)adj dict2=i[ii for iix in enumerate(L) if x] for iL in enumerate(adj)

Appendix A 49

adj dict3=i[ii for iix in enumerate(L) if x] for iL in enumerate(adj)

matching dict1=i[ii for iix in enumerate(L) if x] for iL in enumerate(matching1)matching dict2=i[ii for iix in enumerate(L) if x] for iL in enumerate(matching1)print adj dict2print matching dict2wswrite(index 1 num nodes)wswrite(index 2 num matching)

G = nxGraph()

useless= nxGraph()forced = nxGraph()

Fill Graphfor n in range(0num nodes)

for k in adj dict1[n]Gadd edge(nk)

Gt=Gnumber of edges()wswrite(index 3 Gnumber of nodes())wswrite(index 4 Gnumber of edges())wswrite(index 5 max(Gdegree()values()))

Compute Edmonds classical matching on G for comparison

startB = timeitdefault timer()Classical Matching=nxmax weight matching(G maxcardinality=False)stopB = timeitdefault timer()

Compute Gˆ nad MˆstartC = timeitdefault timer()useless edges(num nodesadj dict1matching dict1uselessadj dict2G)forced edges(Gadj dict2matching dict1num nodesforced)Final Matching=nxmax weight matching(G maxcardinality=False)stopC = timeitdefault timer()

GreedystartG = timeitdefault timer()greedy size=Greedy(num nodesadj dict3matching dict2)stopG = timeitdefault timer()

wswrite(index 6 Gnumber of nodes())wswrite(index 7 Gnumber of edges())wswrite(index 8 uselessnumber of edges())wswrite(index 9 forcednumber of edges())if Gdegree()values()

wswrite(index 10 max(Gdegree()values()))else

50 Application

wswrite(index 10 0)wswrite(index 11 len(Classical Matching)2)wswrite(index 12 len(Final Matching)2+forcednumber of edges())wswrite(index 13 greedy size)wswrite(index 14 stopB minus startBstyle1)wswrite(index 15 stopC minus startCstyle1)wswrite(index 16 stopG minus startGstyle1)wswrite(index 17 (len(Final Matching)2+forcednumber of edges())(num nodes2)style1)wswrite(index 18 Gnumber of nodes()Gtstyle1)wswrite(index 19 Gnumber of edges()Gtstyle1)wswrite(index 20 (len(Final Matching)2+forcednumber of edges())(len(Classical Matching)2)style1)

wbsave(AA Results Random Reyni Large Bipartitexls)

Main function Here we must choose the input form of the dataif name == main

startA = timeitdefault timer()General()stopA = timeitdefault timer()

print nThis program has terminatednnRunning time for 480 files stopAminusstartAprint nnPlease open AA Results Random Reyni Largexls file to see the Results

Appendix A 51

Plotmat

clear allclose allload(RN1Lmat)load(RN1Smat)load(RN2Lmat)load(RN2Smat)load(RN3Lmat)load(RN3Smat)

Plotsh(1)=figure(NameHistogram of Matching size difference between Constraint Algorithm and Greedy AlgorithmNumberTitleoff)

RN1L Greedydiff=RN1L Final matchingminusRN1L Greedy matchingRN2L Greedydiff=RN2L Final matchingminusRN2L Greedy matchingRN3L Greedydiff=RN3L Final matchingminusRN3L Greedy matchingRN1S Greedydiff=RN1S Final matchingminusRN1S Greedy matchingRN2S Greedydiff=RN2S Final matchingminusRN2S Greedy matchingRN3S Greedydiff=RN3S Final matchingminusRN3S Greedy matching

RN1L Finaldiff=RN1L Classical matchingminusRN1L Final matchingRN2L Finaldiff=RN2L Classical matchingminusRN2L Final matchingRN3L Finaldiff=RN3L Classical matchingminusRN3L Final matchingRN1S Finaldiff=RN1S Classical matchingminusRN1S Final matchingRN2S Finaldiff=RN2S Classical matchingminusRN2S Final matchingRN3S Finaldiff=RN3S Classical matchingminusRN3S Final matching

RN1L Classicaldiff=(RN1L Nodes2)minusRN1L Classical matchingRN2L Classicaldiff=(RN2L Nodes2)minusRN2L Classical matchingRN3L Classicaldiff=(RN3L Nodes2)minusRN3L Classical matchingRN1S Classicaldiff=(RN1S Nodes2)minusRN1S Classical matchingRN2S Classicaldiff=(RN2S Nodes2)minusRN2S Classical matchingRN3S Classicaldiff=(RN3S Nodes2)minusRN3S Classical matching

subplot(231)hold onhistf(RN1L Greedydiff0110facecolorbfacealpha9edgealpha1)histf(RN1L Finaldiff0110facecolorrfacealpha5edgealpha1)histf(RN1L Classicaldiff0110facecolorgfacealpha5edgealpha1)legalpha(ConminusGreClasminusConPerfminusClasslocationnortheast)legend boxoffaxis tightxlabel(edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN1L)grid on

subplot(232)hold onhistf(RN2L Greedydiff0110facecolorbfacealpha9edgealpha1)

52 Application

histf(RN2L Finaldiff0110facecolorrfacealpha5edgealpha1)histf(RN2L Classicaldiff0110facecolorgfacealpha5edgealpha1)legalpha(ConminusGreClasminusConPerfminusClasslocationnortheast)legend boxoffaxis tightxlabel(edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN2L)grid on

subplot(233)hold onhistf(RN3L Greedydiff0110facecolorbfacealpha5edgealpha1)histf(RN3L Finaldiff0110facecolorrfacealpha5edgealpha1)histf(RN3L Classicaldiff0110facecolorgfacealpha5edgealpha1)legalpha(ConminusGreClasminusConPerfminusClasslocationnortheast)legend boxoffaxis tightxlabel(edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN3L)grid on

subplot(234)hold onhistf(RN1S Greedydiff0110facecolorbfacealpha5edgealpha1)histf(RN1S Finaldiff0110facecolorrfacealpha5edgealpha1)histf(RN1S Classicaldiff0110facecolorgfacealpha5edgealpha1)legalpha(ConminusGreClasminusConPerfminusClasslocationnortheast)legend boxoffaxis tightxlabel(edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(R1NS)grid on

subplot(235)hold onhistf(RN2S Greedydiff0110facecolorbfacealpha5edgealpha1)histf(RN2S Finaldiff0110facecolorrfacealpha5edgealpha1)histf(RN2S Classicaldiff0110facecolorgfacealpha5edgealpha1)legalpha(ConminusGreClasminusConPerfminusClasslocationnortheast)legend boxoffaxis tightxlabel(edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN2S)grid on

subplot(236)hold onhistf(RN3S Greedydiff0110facecolorbfacealpha5edgealpha1)histf(RN3S Finaldiff0110facecolorrfacealpha5edgealpha1)histf(RN3S Classicaldiff0110facecolorgfacealpha5edgealpha1)

Appendix A 53

legalpha(ConminusGreClasminusConPerfminusClasslocationnortheast)legend boxoffaxis tightgrid ontitle(RN3S)xlabel(edges) xminusaxis labelylabel(instances) yminusaxis labelset(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN1png minusr300)h(2)=figure(NameHistogram of Max Degree of G AND G HatNumberTitleoff)RN1L x=RN1L MaxDegreeGminusRN1L MaxDegreeG HatRN2L x=RN2L MaxDegreeGminusRN2L MaxDegreeG HatRN3L x=RN3L MaxDegreeGminusRN3L MaxDegreeG HatRN1S x=RN1S MaxDegreeGminusRN1S MaxDegreeG HatRN2S x=RN2S MaxDegreeGminusRN2S MaxDegreeG HatRN3S x=RN3S MaxDegreeGminusRN3S MaxDegreeG Hatsubplot(231)hold onhistf(RN1L MaxDegreeG0150facecolorbfacealpha5edgealpha1)histf(RN1L MaxDegreeG Hat0150facecolorrfacealpha5edgealpha1)histf(RN1L x0150facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightxlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN1L)grid on

subplot(232)hold onhistf(RN2L MaxDegreeG010500facecolorbfacealpha5edgealpha1)histf(RN2L MaxDegreeG Hat010500facecolorrfacealpha5edgealpha1)histf(RN2L x010500facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightxlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN2L)grid on

subplot(233)hold onhistf(RN3L MaxDegreeG010300facecolorbfacealpha5edgealpha1)histf(RN3L MaxDegreeG Hat010300facecolorrfacealpha5edgealpha1)histf(RN3L x010300facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightxlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN3L)

54 Application

grid on

subplot(234)hold onhistf(RN1S MaxDegreeG0150facecolorbfacealpha5edgealpha1)histf(RN1S MaxDegreeG Hat0150facecolorrfacealpha5edgealpha1)histf(RN1S x0150facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightxlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(R1NS)grid on

subplot(235)hold onhistf(RN2S MaxDegreeG010500facecolorbfacealpha5edgealpha1)histf(RN2S MaxDegreeG Hat010500facecolorrfacealpha5edgealpha1)histf(RN2S x010500facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightxlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN2S)grid on

subplot(236)hold onhistf(RN3S MaxDegreeG05300facecolorbfacealpha5edgealpha1)histf(RN3S MaxDegreeG Hat05300facecolorrfacealpha5edgealpha1)histf(RN3S x05300facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightgrid ontitle(RN3S)xlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labelset(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN2png minusr300)

h(3)=figure(NameComputation time over edgesNumberTitleoff)

subplot(231)hold onstem(RN1L EdgesGRN1L Time classicalg)stem(RN1L EdgesGRN1L Time algorithmro)stem(RN1L EdgesGRN1L Time greedybx)grid on

Appendix A 55

title(RN1L)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)

subplot(232)hold onstem(RN2L EdgesGRN2L Time classicalg)stem(RN2L EdgesGRN2L Time algorithmro)stem(RN2L EdgesGRN2L Time greedybx)grid ontitle(RN2L)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)

subplot(233)hold onstem(RN3L EdgesGRN3L Time classicalg)stem(RN3L EdgesGRN3L Time algorithmro)stem(RN3L EdgesGRN3L Time greedybx)grid ontitle(RN3L)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)

subplot(234)hold onstem(RN1S EdgesGRN1S Time classicalg)stem(RN1S EdgesGRN1S Time algorithmro)stem(RN1S EdgesGRN1S Time greedybx)grid ontitle(RN1S)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)

subplot(235)hold onstem(RN2S EdgesGRN2S Time classicalg)stem(RN2S EdgesGRN2S Time algorithmro)stem(RN2S EdgesGRN2S Time greedybx)grid ontitle(RN2S)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)

subplot(236)hold onstem(RN3S EdgesGRN3S Time classicalg)stem(RN3S EdgesGRN3S Time algorithmro)stem(RN3S EdgesGRN3S Time greedybx)

56 Application

grid ontitle(RN3S)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)set(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN3png minusr300)

h(4)=figure(NameSorted matching sizeNumberTitleoff)RN1L Sorted matching temp(1)=RN1L Classical matchingRN1L Sorted matching temp(2)=RN1L Final matchingRN1L Sorted matching temp(3)=RN1L Greedy matchingRN1L Sorted matching temp(4)=RN1L Initial matchingRN1L Sorted matching=sortrows(RN1L Sorted matching temp)

RN2L Sorted matching temp(1)=RN2L Classical matchingRN2L Sorted matching temp(2)=RN2L Final matchingRN2L Sorted matching temp(3)=RN2L Greedy matchingRN2L Sorted matching temp(4)=RN2L Initial matchingRN2L Sorted matching=sortrows(RN2L Sorted matching temp)

RN3L Sorted matching temp(1)=RN3L Classical matchingRN3L Sorted matching temp(2)=RN3L Final matchingRN3L Sorted matching temp(3)=RN3L Greedy matchingRN3L Sorted matching temp(4)=RN3L Initial matchingRN3L Sorted matching=sortrows(RN3L Sorted matching temp)

RN1S Sorted matching temp(1)=RN1S Classical matchingRN1S Sorted matching temp(2)=RN1S Final matchingRN1S Sorted matching temp(3)=RN1S Greedy matchingRN1S Sorted matching temp(4)=RN1S Initial matchingRN1S Sorted matching=sortrows(RN1S Sorted matching temp)

RN2S Sorted matching temp(1)=RN2S Classical matchingRN2S Sorted matching temp(2)=RN2S Final matchingRN2S Sorted matching temp(3)=RN2S Greedy matchingRN2S Sorted matching temp(4)=RN2S Initial matchingRN2S Sorted matching=sortrows(RN2S Sorted matching temp)

RN3S Sorted matching temp(1)=RN3S Classical matchingRN3S Sorted matching temp(2)=RN3S Final matchingRN3S Sorted matching temp(3)=RN3S Greedy matchingRN3S Sorted matching temp(4)=RN3S Initial matchingRN3S Sorted matching=sortrows(RN3S Sorted matching temp)

subplot(231)hold onplot(RN1L Sorted matching(1)b)plot(RN1L Sorted matching(2)g)plot(RN1L Sorted matching(3)r)plot(RN1L Sorted matching(4)m)

Appendix A 57

grid ontitle(RN1L)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)

subplot(232)hold onplot(RN2L Sorted matching(1)b)plot(RN2L Sorted matching(2)g)plot(RN2L Sorted matching(3)r)plot(RN2L Sorted matching(4)m)grid ontitle(RN2L)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)

subplot(233)hold onplot(RN3L Sorted matching(1)b)plot(RN3L Sorted matching(2)g)plot(RN3L Sorted matching(3)r)plot(RN3L Sorted matching(4)m)grid ontitle(RN3L)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)

subplot(234)hold onplot(RN1S Sorted matching(1)b)plot(RN1S Sorted matching(2)g)plot(RN1S Sorted matching(3)r)plot(RN1S Sorted matching(4)m)grid ontitle(RN1S)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)

subplot(235)hold onplot(RN2S Sorted matching(1)b)plot(RN2S Sorted matching(2)g)plot(RN2S Sorted matching(3)r)plot(RN2S Sorted matching(4)m)grid ontitle(RN2S)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)

58 Application

subplot(236)hold onplot(RN3S Sorted matching(1)b)plot(RN3S Sorted matching(2)g)plot(RN3S Sorted matching(3)r)plot(RN3S Sorted matching(4)m)grid ontitle(RN3S)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)set(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN4png minusr300)h(5)=figure(NameSorted RatiosNumberTitleoff)RN1L ratio1=RN1L NodesG hatRN1L NodesGRN2L ratio1=RN2L NodesG hatRN2L NodesGRN3L ratio1=RN3L NodesG hatRN3L NodesGRN1S ratio1=RN1S NodesG hatRN1S NodesGRN2S ratio1=RN2S NodesG hatRN2S NodesGRN3S ratio1=RN3S NodesG hatRN3S NodesG

RN1L ratio2=RN1L EdgesG HatRN1L EdgesGRN2L ratio2=RN2L EdgesG HatRN2L EdgesGRN3L ratio2=RN3L EdgesG HatRN3L EdgesGRN1S ratio2=RN1S EdgesG HatRN1S EdgesGRN2S ratio2=RN2S EdgesG HatRN2S EdgesGRN3S ratio2=RN3S EdgesG HatRN3S EdgesG

RN1L ratio3=RN1L MaxDegreeG HatRN1L MaxDegreeGRN2L ratio3=RN2L MaxDegreeG HatRN2L MaxDegreeGRN3L ratio3=RN3L MaxDegreeG HatRN3L MaxDegreeGRN1S ratio3=RN1S MaxDegreeG HatRN1S MaxDegreeGRN2S ratio3=RN2S MaxDegreeG HatRN2S MaxDegreeGRN3S ratio3=RN3S MaxDegreeG HatRN3S MaxDegreeG

RN1L ratio(1)=RN1L ratio1RN1L ratio(2)=RN1L ratio2RN1L ratio(3)=RN1L ratio3

RN2L ratio(1)=RN2L ratio1RN2L ratio(2)=RN2L ratio2RN2L ratio(3)=RN2L ratio3

RN3L ratio(1)=RN3L ratio1RN3L ratio(2)=RN3L ratio2RN3L ratio(3)=RN3L ratio3

RN1S ratio(1)=RN1S ratio1RN1S ratio(2)=RN1S ratio2RN1S ratio(3)=RN1S ratio3

RN2S ratio(1)=RN2S ratio1

Appendix A 59

RN2S ratio(2)=RN2S ratio2RN2S ratio(3)=RN2S ratio3

RN3S ratio(1)=RN3S ratio1RN3S ratio(2)=RN3S ratio2RN3S ratio(3)=RN3S ratio3

RN1L ratio sorted=sortrows(RN1L ratio)RN2L ratio sorted=sortrows(RN2L ratio)RN3L ratio sorted=sortrows(RN3L ratio)RN1S ratio sorted=sortrows(RN1S ratio)RN2S ratio sorted=sortrows(RN2S ratio)RN3S ratio sorted=sortrows(RN3S ratio)

subplot(231)hold onplot(RN1L ratio sorted(1)b)plot(RN1L ratio sorted(2)g)plot(RN1L ratio sorted(3)r)grid ontitle(RN1L)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)

subplot(232)hold onplot(RN2L ratio sorted(1)b)plot(RN2L ratio sorted(2)g)plot(RN2L ratio sorted(3)r)grid ontitle(RN2L)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)

subplot(233)hold onplot(RN3L ratio sorted(1)b)plot(RN3L ratio sorted(2)g)plot(RN3L ratio sorted(3)r)grid ontitle(RN3L)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)

subplot(234)hold onplot(RN1S ratio sorted(1)b)plot(RN1S ratio sorted(2)g)plot(RN1S ratio sorted(3)r)grid on

60 Application

title(RN1S)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)

subplot(235)hold onplot(RN2S ratio sorted(1)b)plot(RN2S ratio sorted(2)g)plot(RN2S ratio sorted(3)r)grid ontitle(RN2S)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)

subplot(236)hold onplot(RN3S ratio sorted(1)b)plot(RN3S ratio sorted(2)g)plot(RN3S ratio sorted(3)r)grid ontitle(RN3S)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)set(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN5png minusr300)

h(6)=figure(NameSorted edges over nodesNumberTitleoff)

RN1L DegreeG1=(RN1L EdgesG)(RN1L NodesG)RN1L DegreeG Hat1=(RN1L EdgesG Hat)(RN1L NodesG hat)

RN1L Degree temp1(1)=RN1L DegreeG1RN1L Degree temp1(2)=RN1L DegreeG Hat1RN1L Degree sorted1=sortrows(RN1L Degree temp1)subplot(231)hold on

plot(RN1L Degree sorted1(1)b)plot(RN1L Degree sorted1(2)g)grid ontitle(RN1L)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)

RN2L DegreeG1=(RN2L EdgesG)(RN2L NodesG)RN2L DegreeG Hat1=(RN2L EdgesG Hat)(RN2L NodesG hat)

RN2L Degree temp1(1)=RN2L DegreeG1

Appendix A 61

RN2L Degree temp1(2)=RN2L DegreeG Hat1RN2L Degree sorted1=sortrows(RN2L Degree temp1)

subplot(232)hold onplot(RN2L Degree sorted1(1)b)plot(RN2L Degree sorted1(2)g)grid ontitle(RN2L)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)

RN3L DegreeG1=(RN3L EdgesG)(RN3L NodesG)RN3L DegreeG Hat1=(RN3L EdgesG Hat)(RN3L NodesG hat)

RN3L Degree temp1(1)=RN3L DegreeG1RN3L Degree temp1(2)=RN3L DegreeG Hat1RN3L Degree sorted1=sortrows(RN3L Degree temp1)

subplot(233)hold onplot(RN3L Degree sorted1(1)b)plot(RN3L Degree sorted1(2)g)grid ontitle(RN3L)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)

RN1S DegreeG1=(RN1S EdgesG)(RN1S NodesG)RN1S DegreeG Hat1=(RN1S EdgesG Hat)(RN1S NodesG hat)

RN1S Degree temp1(1)=RN1S DegreeG1RN1S Degree temp1(2)=RN1S DegreeG Hat1RN1S Degree sorted1=sortrows(RN1S Degree temp1)

subplot(234)hold onplot(RN1S Degree sorted1(1)b)plot(RN1S Degree sorted1(2)g)grid ontitle(RN1S)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)

RN2S DegreeG1=(RN2S EdgesG)(RN2S NodesG)RN2S DegreeG Hat1=(RN2S EdgesG Hat)(RN2S NodesG hat)

RN2S Degree temp1(1)=RN2S DegreeG1

62 Application

RN2S Degree temp1(2)=RN2S DegreeG Hat1RN2S Degree sorted1=sortrows(RN2S Degree temp1)

subplot(235)hold onplot(RN2S Degree sorted1(1)b)plot(RN2S Degree sorted1(2)g)grid ontitle(RN2S)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)

RN3S DegreeG1=(RN3S EdgesG)(RN3S NodesG)RN3S DegreeG Hat1=(RN3S EdgesG Hat)(RN3S NodesG hat)

RN3S Degree temp1(1)=RN3S DegreeG1RN3S Degree temp1(2)=RN3S DegreeG Hat1RN3S Degree sorted1=sortrows(RN3S Degree temp1)

subplot(236)hold onplot(RN3S Degree sorted1(1)b)plot(RN3S Degree sorted1(2)g)grid ontitle(RN3S)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)set(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN6png minusr300)h(7)=figure(NameSorted mATCHED DEGREENumberTitleoff)RN1L ratioMax(1)=RN1L MaxDegreeGRN1L ratioMax(2)=RN1L MaxDegreeG Hat

RN1L ratio sortedMax=sortrows(RN1L ratioMax)subplot(231)hold onplot(RN1L ratio sortedMax(1)b)plot(RN1L ratio sortedMax(2)g)grid ontitle(RN1L)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)

RN2L ratioMax(1)=RN2L MaxDegreeGRN2L ratioMax(2)=RN2L MaxDegreeG Hat

RN2L ratio sortedMax=sortrows(RN2L ratioMax)subplot(232)

Appendix A 63

hold onplot(RN2L ratio sortedMax(1)b)plot(RN2L ratio sortedMax(2)g)grid ontitle(RN2L)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)

RN3L ratioMax(1)=RN3L MaxDegreeGRN3L ratioMax(2)=RN3L MaxDegreeG Hat

RN3L ratio sortedMax=sortrows(RN3L ratioMax)subplot(233)hold onplot(RN3L ratio sortedMax(1)b)plot(RN3L ratio sortedMax(2)g)grid ontitle(RN3L)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)

RN1S ratioMax(1)=RN1S MaxDegreeGRN1S ratioMax(2)=RN1S MaxDegreeG Hat

RN1S ratio sortedMax=sortrows(RN1S ratioMax)subplot(234)hold onplot(RN1S ratio sortedMax(1)b)plot(RN1S ratio sortedMax(2)g)grid ontitle(RN1S)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)

RN2S ratioMax(1)=RN2S MaxDegreeGRN2S ratioMax(2)=RN2S MaxDegreeG Hat

RN2S ratio sortedMax=sortrows(RN2S ratioMax)

subplot(235)hold onplot(RN2S ratio sortedMax(1)b)plot(RN2S ratio sortedMax(2)g)grid ontitle(RN2S)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)

RN3S ratioMax(1)=RN3S MaxDegreeGRN3S ratioMax(2)=RN3S MaxDegreeG Hat

64 Application

RN3S ratio sortedMax=sortrows(RN3S ratioMax)subplot(236)hold onplot(RN3S ratio sortedMax(1)b)plot(RN3S ratio sortedMax(2)g)grid ontitle(RN1L)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)set(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN7png minusr300)

tilefigs()(h)

Bibliography

[1] C Berge ldquoTWO THEOREMS IN GRAPH THEORYrdquo Proceedings of the NationalAcademy of Sciences of the United States of America vol 43 no 9 pp 842ndash844Sep 1957

[2] L Bui S Sanghavi and R Srikant ldquoDistributed link scheduling with constantoverheadrdquo IEEEACM Trans Netw vol 17 no 5 pp 1467ndash1480 2009

[3] R Duan and S Pettie ldquoLinear-time approximation for maximum weight matchingrdquoJ ACM vol 61 no 1 2014

[4] J Edmonds ldquoPaths trees and flowersrdquo Canadian Journal of Mathematics vol 17pp 449ndash467 1965

[5] J E Hopcroft and R M Karp ldquoAn n52 algorithm for maximum matchings inbipartite graphsrdquo SIAM J Comput vol 2 no 4 pp 225ndash231 1973

[6] S Micali and V V Vazirani ldquoAn O(radic|V ||E|) algorithm for finding maximum

matching in general graphsrdquo in 21st Symp on Foundations of Comp Sc (FOCS)IEEE 1980 pp 17ndash27

[7] N Nisse A Salch and V Weber ldquoRecovery of disrupted airline operationsrdquo 2015httphalinriafrSomething

[8] X Wu and R Srikant ldquoRegulated maximal matching A distributed schedulingalgorithm for multi-hop wireless networks with nodeexclusive spectrum sharingrdquo inIEEE Conf on Decision and Control 2005

65

  • Contents
  • Introduction
  • Algorithms
    • Maximum matching
    • k-maximum matching
      • k-matching for Airport Slot assignment
      • The case where k=3
      • The case of Paths
      • The case of the Spider
          • Application
            • Description
            • Reyni Erdos
            • Barabaacutesi Albert
            • Amadeus Graphs
            • Bipartite
            • Bipartite with degree seq
            • Appendix A
              • BipartiteGraphGeneratorpy
              • RandomGraphGeneratorpy
              • kequals3MaximumMatchingpy
              • Plotmat
                  • Bibliography
Page 3: Theodoros Alexandros KARAGKIOULES -  · Introduction This work is the result of a 6 months internship, under the supervision of research O cer Nicolas NISSE. The original scope of

Introduction

This work is the result of a 6 months internship under the supervision of research OfficerNicolas NISSE

The original scope of the internship was the introduction to the k-maximum matchingproblem along with the application of a special case of the problem on a industrial-specific variant and the theoretical exploration of the k-maximum matching problem onspecific graph families

The Internship was divided into two independent stages that ran simultaneously

On the first stage of the internship inspiration was drawn from an application of thek- maximum matching on airport slot assignment As itrsquos described in the followingsections the k-maximum matching problem can be used for the reassignment of flightsto time slots for landing In collaboration with Amadeus the k-maximum matchingalgorithm was applied on actual data to test its efficiency

During the second phase of the internship all the combinatorial optimization aspects ofthe k-maximum problem (complexity etc) were introduced The case where k = 3 wasstudied and the proposed algorithm [7] for that case was implemented and applied onrandom graphs and on bipartite graphs that simulated the Amadeus data

Additionally based on a proposed algorithm for Paths [7] a new algorithm was pro-posed that computes the k-maximum matching on a specific type of tree the Spider

3

Chapter 1

Algorithms

11 Maximum matching

In this section the Classical Maximum matching is presented

Let G = (VE) be a graph A matching M sube E of G is a set of edges pairwisedisjoint A vertex v isin V is defined as covered by M if there is e isinM such that v isin eOtherwise v is said exposed The size of a maximum matching in G is denoted by micro(G)

The problem of computing a maximum matching has been widely studied and it iswell known that it can be solved in polynomial-time The most popular algorithm forcomputing the classical maximum matching is by Edmonds[4] This algorithm has beenused broadly in the calculations on random graphs that follow in the next chapter

Augmenting Paths A path P = (v0 middot middot middot vk) of G is a sequence of pairwise distinctvertices such that ei = vi vi+1 isin E for each 0 le i lt k The path P is said M -augmenting if v0 and vk are exposed and for any 0 le i lt k ei = vi vi+1 isin M ifand only if i is odd In particular an augmenting path has always an odd length A wellknown theorem of Claude Berge states that a matching M is maximum if and only ifthere are no M -augmenting paths [1]

Related work The first algorithm for solving the maximum matching problem inpolynomial-time in general graphs is due to Edmonds [4] Then many work has beendedicated to design more efficient algorithms In particular the algorithms in [5 6] arebased on augmenting paths in the non-decreasing order of their lengths

12 k-maximum matching

Let microk(GM) denote the size of a maximum matching that can be obtained fromM sube E in G by augmenting paths of length at most kk ge 1 where k is an odd integerTo define the k-Matching Problem one must compute a sequence of augmenting-paths

5

6 Algorithms

of length le k that allow to obtain from M a matching of size microk(GM)

In the cases k isin 1 3 it has been proven that the computational complexity of the k-Matching Problem is equivalent to the one of the classical maximum matching problem(without any constraint on the length of paths) Hence for k isin 1 3 it can be solvedin polynomial time

121 k-matching for Airport Slot assignment

The k-maximum matching problem has been found to have an application in the aviationindustry When an aircraft is approaching an airport it is assigned by Air Traffic Controla landing time (called slot) If there is a delay for any reason (weather conditions latearrival priority) it looses its slot and a new slot needs to by reassigned to it Howeverslots for landing are a scarce resource of the airports and to avoid conflicts and forsafety reasons Airline Operation Controllers have to regularly modify the assignment ofthe slots of the aircraft

This modification of the slot-assignment uses only two kinds of operations either assignaircraft A to a free slot or give A the slot of B and assign B to a free slot The problemis then the following

Let k ge 1 be an odd integer and let G be a graph and M be a matching of GWhat is the maximum size of a matching that can be obtained from M by using onlyaugmenting paths of length at most k

Let G = (X cup YE) be a bipartite graph X represents the set of aircraft and Yrepresents the set of available slots There is an edge between a isin X and s isin Y if theslot s is compatible with the schedules of aircraft A Let M be a matching of G thatcorresponds to a pre-established valid assignment of some slots to some aircraft Theproblem of reassignment of slots is equivalent to computing a maximum matching thatcan be obtained from M by augmenting only paths of length at most 3

122 The case where k=3

Let G be a graph and M sube E(G) be a matching of G An edge e isin E(G) M is saiduseless if e is incident to two edges of M ie if each endpoint of e is incident to oneedge of M An edge e isinM is said forced if at least one of its endpoints has degree onein G

Finally let G be the graph obtained from G and the matching M by first removingall useless edges (but keeping their endpoints) and then by removing the forced edgesand their endpoints Let M be the matching resulting from M in G ie M equals Mminus the forced edges Note that M has no useless edges nor forced edges Abusingthe notations we will identify the paths in G with some paths in G

12 k-maximum matching 7

This algorithm has been used to implement the k-maximum matching programme thatcomputes the data provided by Amadeus and also the randomly generated graphs of thefollowing chapter

123 The case of Paths

Let Q = (v1 middot middot middot vi) be the maximum alternating path containing v1 If Q is notaugmenting or if Q has length more than k (ie i gt k) the algorithm is appliedrecursively on P (v1 middot middot middot viminus1) Otherwise Q is augmented (it is added to the desiredsequence of paths) and the algorithm is applied recursively on P Q

Algorithm 1 k-matching(PnM)

Require A path Pn = (v1 middot middot middot vn) a matching M sube E(P ) and an odd integer k ge 1Ensure A sequence (Q1 middot middot middot Qr) of augmenting paths with r = microk(PM)minus |M |1 if n = 1 then return empty2 else3 Let 1 lt i le n be the smallest integer (at least 2) such that vi is exposed4 if v1 is not exposed OR i gt k then5 Let P prime = (vi middot middot middot vn) and M prime = M cap E(P prime) return k-matching(P primeM prime)6 else7 Let P prime = (vi+1 middot middot middot vn) and M prime = M cap E(P prime) return (v1 middot middot middot vi)cup

k-matching(P primeM prime)8 end if9 end if

124 The case of the Spider

Theorem 11 Let S be a spider andM its initial matching and (P1 Pr) a sequenceof augmenting paths of length le k such that microk(SM) = |M |+ r then exist (Q1 Qr)a sequence of augmenting paths of length le k such that at most one such path containsthe center C

Proof Let S be a spider and lets assume that the optimal sequence of augmentingpaths SP is known along with the set of branches Br (those paths of S from a leaf tothe nn of CAssume for contradiction that exist ge 2 augmenting paths that contain the center Cand let Pi and Pj be the first such paths Let Pi = (umi

C uni) and Pj =

(umj C unj

) and let Q = (umi C unj

) be the (augmenting) pathcontaining partially Pi the center C and partially Pj Since [C uni

] sub [C unj] in order

for Pj to be an augmenting path then exist H = (Pj Pi) Q Letrsquos also assume thatthere is a set of paths A = A1 At isin SP between Pi and Pj and A sube Brsuch that forallk isin 1 2 t Ak Pi = empty or Ak Pj = empty Also there is a set of pathsB = B1 Bf isin SP between Pi and Pj and B sube Br such that foralln isin 1 2 fBn is non intersecting with any paths in AQPi Pj and H Then the optimal sequenceof augmenting paths can be the following

8 Algorithms

P1 P2 P3 A1 At QB1 Bf H Pr where augmenting only path Q oncecan lead to the equivalently optimal solution

Algorithm 2 Spider algorithm(SM)

1 M prime = M2 Let there be a set of leaves λ1 λr3 xk is the nn of C in the path C rarr λk4 for i isin 1 r do5 for j 6= i do M primeprime=Path Algorithm(λi rarr λjM)6 for k isin i j do M primeprime=M primeprimecupPath Algorithm(λk rarr xkM)7 end for8 end for9 if M primeprime gt M prime then10 M prime = M primeprime

11 end if12 end for13 return M prime

Proof Let there be an optimal solution that is obtained by the paths in the sequenceQprime = (P prime1 P

primer) for the spider

Let there also be a set of paths from leaf to leaf PLL = Pll1 P lln a set ofbranches BR = Br1 Brm and a sequence of augmenting paths Q = (P1 Pr)such that for j isin 1 r Pj isin PLL and forall i 6= j isin 1 r Pi isin BR

Applying the path algorithm for Pj and then for the r minus 1 paths of Q and due toTheorem 21 it is ensured that the matching produced will lead to a feasible solutionsince C is never exposed

Due to the iterative nature of the algorithm it can be checked that all possible com-binations of Pj and Pi that construct Q are considered and that one of the solutionscomputed as above will be the initial optimal solution Qprime

Thus by induction Spider Algorithm will always produce an optimal matching on aSpider

Chapter 2

Application

21 Description

This chapter aims at providing the picture of analysis on the data provided by Amadeusthe bipartite graphs and the random graphs generated

The random graphs have been generated as purely random graphs based on the ReyniErdos and the Barabasi Albert with different values of connectivity probability or con-nectivity

The bipartite graphs were generated on the density of the Amadeus graphs to simu-late better the results Additionally an extra set of test have been made on bipartitegraphs that simulate the degree distribution of the Amadeus graphs Certain classesof degree distribution were selected and based on those 480 bipartite graphs have beengenerated

At every graph the classical matching is computed based on the Edmonds algorithmthen the k-matching algorithm is used as described in section 122 Lastly a greedyalgorithm is implemented to be used for comparison

The ultimate goal is to explore the efficiency of the k-matching algorithm for the caseof k = 3 and to compare it with the result of the Edmonds algorithm and of course theGreedy implementationThe results follow along with some comments

9

10 Application

22 Reyni Erdos

bull RNxy are randomly generated graphs with a fixed number of 1000 nodes

bull There are 6 categories based on the initial matching and probability p of connection

bull x = L S L When the initial matching is large and S when it is small

bull y = 1 2 3 1 when p = lognn

2 when p = 13

and 3 when p = lognn

+ 01

Computation time over |E|

Computation time over |E| - Comments

bull This is a very straightforward set of figures

22 Reyni Erdos 11

bull When the initial matching is sufficiently large then the forced edges are taken out(a process which takes a fragment of the computation time) and then the classicalmatching algorithm (Edmonds) is applied on a smaller graph(G) This reducessignificantly the computation time

bull When the initial matching is small then the computation time of the constraintalgorithm might be larger than that of Edmonds The reason is that the constraintalgorithm need some time to compute the useless and forced edges and thenEdmonds algorithm is applied on G G Thus the overall processing time issometimes larger

Sorted matching size

Sorted matching size - Comments

12 Application

bull This set of figures represents the ascending order of the Classical matching sizealong with its corresponding Constraint and Greedy equivalent

bull When the probability is sufficiently higher than the threshold lognn

then the threealgorithms produce identical results of optimal matching

bull For lower probability there is a difference between the results of the algorithms

bull the degree of that difference is depicted in the first set of figures presented

bull It is interesting to observe that a change on the Constraint algorithm is associatedwith a even more significant change in the Greedy algorithm

bull There is a difference only when the probability is at the connectedness threshholdlognn

bull The difference is very small compared to the size of the matching ( 500)

bull The difference in matching size appears mostly at the Greedy implementationwhen compared to the constraint algorithm

Sorted Ratios

22 Reyni Erdos 13

Sorted Ratios - Comments

bull This set of figures depicts the ratios VV

EE

∆∆

in ascending order of VV

bull It is evident that when the initial matching is large the amount of forced edges(and their endpoints) removed is high thus the ratio of Nodes and edges is verylow For higher probabilities almost all edges are removed as useless

bull For a smaller initial matching almost no forced edges (and their endpoints) areremoved which we conclude be the node ration being close to 1 There is somesmall amount of useless edges removed though since the ratio of edges is less butclose to 1

bull The ratio of ∆ for large initial matching follows the trend of the node ratio yetfor smaller initial matching it deviates significantly

14 Application

Sorted |E||V |

Sorted |E||V | - Comments

bull Although as graph density the ratio 2|E||V |(|V |minus1)

is considered in this set of figures

we evaluate the correlation of the ratio |E||V | of G and G since the density of G

could acquire values higher than that of G

bull The figures are calculated in ascending order for the ratio of G

bull For the case of large initial matching the two ratios for G and G remain almostconstant ( to the extent of the probability of each graph) since removing forcededges( and their endpoints) alters the |E| and |V | proportionately

22 Reyni Erdos 15

bull For the case of small initial matching we observe some deviation in the valuesof the ration for G and that is explained with the removal of only useless edgeswhich only alters the |E| and keeps |V | in the original values

Sorted ∆

Sorted ∆-Comments

bull In this set of figures the ascending order of the ∆ of G is associated with the ∆of G

bull There is no significant jump of the ∆ for each graph category which tells that thatwe are comparing a uniform distribution of random grapghs for each probabilitycase

16 Application

bull For larger initial matching we observe the difference in the ∆s of G and G giventhe removed forced edges( and their endpoints) At some cases the ∆ of G dropsto 0 since the vast majority of edges have been declared forced and removed alongwith their endpoints

bull For smaller initial matching the ∆s of G and G follow mostly the same trend onlya few number of different instances

23 Barabasi Albert

Graph characteristics Barabasi Albert

bull BAxy are randomly generated graphs with a fixed number of 1000 nodes

bull There are 6 categories based on ini matching and of attached edges m

bull x = L S L When the initial matching is large and S when it is small

bull y = 1 2 3 1 when m = [1 10] 2 when m = [20 50] and 3 m = [50 100]

Computation time over |E|

23 Barabasi Albert 17

Computation time over |E| - Comments

bull When the initial matching is sufficiently large then the forced edges are taken out(a process which takes a fragment of the computation time) and then the classicalmatching algorithm (Edmonds) is applied on a smaller graph(G) This reducessignificantly the computation time

bull When the initial matching is small then the computation time of the constraintalgorithm might be larger than that of Edmonds The reason is that the constraintalgorithm need some time to compute the useless and forced edges and thenEdmonds algorithm is applied on G G Thus the overall processing time issometimes larger

Sorted matching size

18 Application

Sorted matching size-Comments

bull In this graph the matching size of the classical algorithm is depicted in ascendingorder along with the corresponding constraint algorithm and greedy result

bull Here in the case where m is small for both cases of initial matching (small large)the result may vary greatly starting from a value of half the perfect matching withsmall differences between the results of the various algorithm implementations

bull For the other cases of m the results converge

bull This is explained as for small values of m the graph is disconnected

bull In the matching size difference set of figures a very noticing difference value ap-pears For the cases of small m( the number of existing nodes that a new node isconnected to at the creation of the graph) we can see that the difference in the

23 Barabasi Albert 19

matching size compared to that of the perfect matching could be up to 40 ofthat of the matching size So there are occasions where the matching size is 200edges when the perfect matching would have been 500

bull the difference between the Constraint matching and the classical matching andthe difference of the constraint matching and that of the greedy matching do notshow significant values

Sorted Ratios

Sorted Ratio s -Comments

bull This set of figures depicts the ratios VV

EE

∆∆

in ascending order of VV

20 Application

bull It is evident that when the initial matching is large the amount of forced edges(and their endpoints) removed is high thus the ratio of Nodes and edges is verylow For higher probabilities almost all edges are removed as useless

bull For a smaller initial matching almost no forced edges (and their endpoints) areremoved which we conclude be the node ration being close to 1 There is somesmall amount of useless edges removed though since the ratio of edges is less butclose to 1

bull The ratio of ∆ for large initial matching follows the trend of the node ratio yetfor smaller initial matching it deviates significantly

Sorted |E||V |

23 Barabasi Albert 21

Sorted |E||V | - Comments

bull Although as graph density the ratio 2|E||V |(|V |minus1)

is considered in this set of figures

we evaluate the correlation of the ratio |E||V | of G and G since the density of G

could acquire values higher than that of G

bull The figures are calculated in ascending order for the ratio of G

bull For the case of large initial matching the two ratios for G and G remain almostconstant ( to the extent of the edge attraction m of each graph) since removingforced edges( and their endpoints) alters the |E| and |V | proportionately

bull For the case of small initial matching we observe some deviation in the valuesof the ration for G and that is explained with the removal of only useless edgeswhich only alters the |E| and keeps |V | in the original values

Sorted ∆

22 Application

Sorted ∆-Comments

bull In this set of figures the ascending order of the ∆ of G is associated with the ∆of G

bull There is a significant jump of the ∆ for each graph category which tells that thatwe are not comparing a uniform distribution of random graphs and based on theedge attraction m the graphs can vary in form

bull For larger initial matching we observe the difference in the ∆s of G and G giventhe removed forced edges( and their endpoints) At some cases the ∆ of G dropsto 0 since the vast majority of edges have been declared forced and removed alongwith their endpoints What is interesting is that the ∆ of G oscilates within stablelimits

24 Amadeus Graphs 23

bull For smaller initial matching the ∆s of G and G follow mostly the same trend onlya few number of different instances

24 Amadeus Graphs

Graph characteristics Amadeus graphs

bull These are the bipartite graphs provided by Amadeus

Computation time over |E|

Computation time over |E| - Comments

24 Application

bull For every instance the computation time of the classical algorithm is always smallerto that of the constraint matching

bull This allows as to speculate that we always compute a smaller G which also impliesthat we always find a set of forced edges and useless

Sorted matching size

Sorted matching size - Comments

bull Size of matching has an upward trend since the magnitude of the graphs is notthe same for the 160 instances

bull No significant deviation is noticed as per the first graph

24 Amadeus Graphs 25

bull Except from deviation from the perfect matching (number of flights) where some-times it could get up to 40

bull For the Amadeus Bipartite graphs we can see that the difference of the Classicaland the constraint implementation is not more than 1 edge in the matching

bull There appears to be a difference of up to 24 edges between the Classical matchingand the Perfect matching which is computed as the number of flights

bull The greedy algorithm performs well with only a few instances deviating slightlyform the Constraint algorithm result

Sorted Ratios

Sorted Ratios - Comments

26 Application

bull

Sorted |E||V |

Sorted |E||V | - Comments

bull Density of the graphs shows that on average we have 25-3 available time slot perflight

bull The line for the same value for G shows that there is a large deviation for everyinstance which allows for the hypothesis that the amount of useless+forced edgesof G has no obvious correlation to that of G

25 Bipartite 27

Sorted ∆

Sorted ∆-Comments

bull As per the previous related graphs for ∆ there is in significant drop in the ∆ of Gand G

25 Bipartite

Graph characteristics Bipartite random Graphs

bull BIPxy are randomly generated graphs with a fixed number of 1000(n=500 andm=500) nodes

bull There are 6 categories based on ini matching and probability p

28 Application

bull Probability p has been chosen as such in order to simulate the |E||V | 25 of theAmadeus bipartite graphs

bull So in order to have about 2-4 edges for every node we choose accordingly theprobability p to choose one of the n lowastm possible edges

bull x = L S L When the initial matching is large and S when it is small

bull y = 1 2 3 1 when p = 18250

2 when p = 25250

and 3 when p = 34250

Computation time over

Computation time overedges-Comments

bull

25 Bipartite 29

Sorted matching size

Sorted matching size-Comments

bull In these set of graphs one can instantly notice that only a few instances with highprobability can reach a matching size equal to the perfect matching

bull For the case of the initial matching we witness that there is a gap between the lineof the classical matching and those of the constraint and greedy results suggestingsmaller matching sizes of 10-40 edges

bull For the case of the small initial matching the result of the constraint matchingis now close to the result of the classical matching yet the greedy algorithm stillshows a relevantly big difference

30 Application

bull In this set of bipartite graphs we can witness that the result of the Constraintmatching shows a difference with the classical matching when the initial matchingis large The difference is smaller as the probability gets larger

bull For the case of the small initial matching the above phenomenom does not occuryet the greedy results deviates from that of the constraint matching

bull As per the pefrect matching compared to the classical matching a difference of5-10 edges is evident at almost all cases

Sorted Ratios

Sorted Ratios-Comments

bull Great max degree deviation

25 Bipartite 31

bull Regardless of the probability the ration of nodes and edges seems to have similarbehaviour when compared to the respective graphs of the same matching scale

bull Same gap between nodes ration and edges ration for all cases

Sorted |E||V |

Sorted |E||V | - Comments

bull In these set of figures we witness that the |E||V | acquires values relevant to those ofthe amadeus graphs The random graphs were constructed to depict this similarity

bull For smaller initial matching the ratios for G and G show the same upward trendand also they acquire closer values It represents the decrease of the averagenumber of forced edges in comparison to the larger matching cases

32 Application

Sorted ∆

Sorted ∆-Comments

bull ∆ acquires the same min and max values for each probability case (expected)

bull Gap in the case of large initial matching

26 Bipartite with degree seq

Graph characteristics

bull DEQBIPxy are randomly generated graphs based on three different types of degreedistribution of the Amadeus graphs

26 Bipartite with degree seq 33

bull There are 6 categories based on ini matching and degree distribution

bull x = L S L When the initial matching is large and S when it is small

bull y = 1 2 3 1 when degree distribution is based on file 2 when degree distributionis based on file and 3 when degree distribution is based on file

Computation time over

34 Application

Computation time overedges-Comments

bull Greedy algorithm takes minimum amount of time

bull The smaller the initial matching the more smaller the difference in comoutationtime of Constraint and classical algorithm

bull Due to preprocessing and the fact that G and G are the almost identical thetotal time needed to apply the constraint algorithm is in some cases bigger

Sorted matching size

26 Bipartite with degree seq 35

Sorted matching size-Comments

bull Classical matching is equal to perfect matching in every case

bull Constraint and greedy have identical behaviour

bull The larger the spectrum of the degree sequence the more efficient the matching

Sorted Ratios

36 Application

Sorted Ratios-Comments

bull With large initial matching most of the edges are considenred uselles or forced andare removed thus the ratio is close(if not equal to) zero

bull For small matching and large degree sequence sectrum hte max degree remainsthe same Only a few forced edges (and their nodes) are removed apparently nonodes with max degree

Sorted |E||V |

26 Bipartite with degree seq 37

Sorted |E||V | - Comments

bull In these set of figures we witness that the |E||V | acquires values relevant to those ofthe amadeus graphs The random graphs were constructed to depict this similarity

bull For smaller initial matching the ratios for G and G show the same upward trendand also they acquire closer values It repsresent the decrease of the averagenumber of forced edges in comparison to the larger matching cases

Sorted ∆

38 Application

Sorted ∆-Comments

bull Big difference in max degree in large initial matching

bull Almost identical behaviour in the case of small initial matching

Appendix A 39

Appendix A

BipartiteGraphGeneratorpy

from future import divisionimport networkx as nx

from networkxalgorithms import approximationimport collectionsimport randomimport mathfrom networkxalgorithms import bipartiteif name == main

for i in range(1481)waqs 481index=1n=randomrandint(100 1000)

n1=95 was 500me1=118

n2=251 was 500me2=903

n3=165 was 500me3=412

m=0m1=0p=randomrandom()p1=18250p2=25250p3=34250print ip=05t1=randomrandint(0 1)print im2=randomrandint(n2minus1 n2+1)G = nxGraph()ma = nxGraph()

aseq1=[1 2 3 4 5 3]

bseq1=[4 3 3 1 2 2 1]

aseq2=[16 14 14 14 12 11]bseq2=[0 0 0 0 0 0]

aseq3=[8 7 8 8 8 8]bseq3=[0 0 0 0 0 0]

40 Application

print Gnumber of edges()if ilt=160

G=bipartiteconfiguration model(aseq1 bseq1 create using=None seed=None)A=nxadjacency matrix(G)for ii in range(0n1+me1)

maadd node(ii)A=[Rtodense()tolist()[0] for R in A]

printnummanumber of nodes()rl=randomsample(range(0n1+me1) n1+me1)m=0done vertices = set()for p in rlprintin fordone verticesadd(p)

neighbors = []list()for iii in range(0n1+me1)

if A[p][iii]==1neighborsappend(iii)

randomshuffle(neighbors)continue loop = Truedegree = len(neighbors)

print degreej = 0p4=randomrandom()while continue loop and (jltdegree)print in loop

next = neighbors[j]if next not in done vertices and p not in done vertices

done verticesadd(p)done verticesadd(next)if p4gt=07print added edge

maadd edge(pnext)m=m+1

continue loop = Falsej += 1

print matching listOfedgeprint maedge

MA=nxadjacency matrix(ma)print MA

MA=[Rtodense()tolist()[0] for R in MA]print MA

B=[ join(map(strR)) for R in A]MB=[ join(map(strR)) for R in MA]

C=njoin(B)+nMC=njoin(MB)+n

print nprint mprint m1

filea=str(i)+txtwith open(fileaw) as f

Appendix A 41

fwrite(str(n1+me1))fwrite(n)fwrite(str(n1+me1))fwrite(n)fwrite(str(m))fwrite(n)fwrite(n)fwrite(C)fwrite(n)fwrite(MC)

elif igt160 and ilt321G=bipartiteconfiguration model(aseq2 bseq2 create using=None seed=None)A=nxadjacency matrix(G)for ii in range(0n2+me2)

maadd node(ii)A=[Rtodense()tolist()[0] for R in A]

printnummanumber of nodes()rl=randomsample(range(0n2+me2) n2+me2)m=0done vertices = set()for p in rlprintin fordone verticesadd(p)

neighbors = []list()for iii in range(0n2+me2)

if A[p][iii]==1neighborsappend(iii)

randomshuffle(neighbors)continue loop = Truedegree = len(neighbors)

print degreej = 0p4=randomrandom()while continue loop and (jltdegree)

print in loopnext = neighbors[j]if next not in done vertices and p not in done vertices

done verticesadd(p)done verticesadd(next)if p4gt=07

print added edgemaadd edge(pnext)m=m+1

continue loop = Falsej += 1

print matching listOfedgeprint maedge

MA=nxadjacency matrix(ma)print MA

MA=[Rtodense()tolist()[0] for R in MA]print MA

B=[ join(map(strR)) for R in A]MB=[ join(map(strR)) for R in MA]

42 Application

C=njoin(B)+nMC=njoin(MB)+n

print nprint mprint m1

filea=str(i)+txtwith open(fileaw) as f

fwrite(str(n2+me2))fwrite(n)fwrite(str(n2+me2))fwrite(n)fwrite(str(m))fwrite(n)fwrite(n)fwrite(C)fwrite(n)fwrite(MC)

elseG=bipartiteconfiguration model(aseq3 bseq3 create using=None seed=None)A=nxadjacency matrix(G)for ii in range(0n3+me3)

maadd node(ii)A=[Rtodense()tolist()[0] for R in A]

printnummanumber of nodes()rl=randomsample(range(0n3+me3) n3+me3)m=0done vertices = set()for p in rlprintin fordone verticesadd(p)

neighbors = []list()for iii in range(0n3+me3)

if A[p][iii]==1neighborsappend(iii)

randomshuffle(neighbors)continue loop = Truedegree = len(neighbors)

print degreej = 0p4=randomrandom()while continue loop and (jltdegree)

print in loopnext = neighbors[j]if next not in done vertices and p not in done vertices

done verticesadd(p)done verticesadd(next)if p4gt=07print added edge

maadd edge(pnext)m=m+1

continue loop = Falsej += 1

Appendix A 43

print matching listOfedgeprint maedge

MA=nxadjacency matrix(ma)print MA

MA=[Rtodense()tolist()[0] for R in MA]print MA

B=[ join(map(strR)) for R in A]MB=[ join(map(strR)) for R in MA]

C=njoin(B)+nMC=njoin(MB)+n

print nprint mprint m1

filea=str(i)+txtwith open(fileaw) as f

fwrite(str(n3+me3))fwrite(n)fwrite(str(n3+me3))fwrite(n)fwrite(str(m))fwrite(n)fwrite(n)fwrite(C)fwrite(n)fwrite(MC)

print nRandom graphs with random matching have been generated

44 Application

RandomGraphGeneratorpy

from future import divisionimport networkx as nxfrom networkxalgorithms import approximationimport collectionsimport randomimport mathif name == main

for i in range(1481)index=1n=randomrandint(100 1000)

n=1000m=0m1=0p=randomrandom()p1=mathlog(n2)np2=13p3=mathlog(n2)n+01p=05t1=randomrandint(0 1)print im2=randomrandint(n2minus1 n2+1)G = nxGraph()ma = nxGraph()print nme1=randomrandint(1 10)me2=randomrandint(2050)me3=randomrandint(50100)if ilt241

if ilt=80G=nxfast gnp random graph(n p1 seed=None directed=False)

elif igt80 and ilt161G=nxfast gnp random graph(n p2 seed=None directed=False)

elseG=nxfast gnp random graph(n p3 seed=None directed=False)

elseif ilt=320

G=nxbarabasi albert graph(n me1 seed=None)elif igt320 and ilt401

G=nxbarabasi albert graph(n me2 seed=None)else

G=nxbarabasi albert graph(n me3 seed=None)A=nxadjacency matrix(G)for ii in range(0n)

maadd node(ii)A=[Rtodense()tolist()[0] for R in A]

rl=randomsample(range(0n) n)m=0

Appendix A 45

done vertices = set()for p in rl

done verticesadd(p)neighbors = []list()for iii in range(0n)

if A[p][iii]==1neighborsappend(iii)

randomshuffle(neighbors)continue loop = Truedegree = len(neighbors)j = 0p2=randomrandom()while continue loop and (jltdegree)

next = neighbors[j]if next not in done vertices and p not in done vertices

done verticesadd(p)done verticesadd(next)if p2gt=00 Larger probability for smaller initial matching

maadd edge(pnext)m=m+1

continue loop = Falsej += 1

print matching listOfedgeprint maedgeMA=nxadjacency matrix(ma)MA=[Rtodense()tolist()[0] for R in MA]print MAB=[ join(map(strR)) for R in A]MB=[ join(map(strR)) for R in MA]

C=njoin(B)+nMC=njoin(MB)+nprint MCprint nprint mprint m1filea=str(i)+txtwith open(fileaw) as f

fwrite(str(n))fwrite(n)fwrite(str(n))fwrite(n)fwrite(str(m))fwrite(n)fwrite(n)fwrite(C)fwrite(n)fwrite(MC)

print nRandom graphs with random matching have been generated

46 Application

kequals3MaximumMatchingpy

from future import divisionimport networkx as nxfrom networkxalgorithms import bipartiteimport matplotlibpyplot as pltimport collectionsimport timeitimport xlwtimport xlrdimport mathimport sys

Case for General Graphsdef forced edges(Gadj dict2matching dict1num nodesforced)

flagg=0for n in range(0num nodes)

for k in adj dict2[n]if ([k]==matching dict1[n])

count=0for l in range(0num nodes)

count=count+adj dict2[l]count(k)if (len(adj dict2[n])==1) or (count==1)

forcedadd edge(nk)Gremove edge(nk)Gremove node(n)Gremove node(k)printforced edgenktemp=kflagg=1for m in range (len(adj dict2[n])minus1minus1minus1)

adj dict2[adj dict2[n][m]]remove(n)adj dict2[n]remove(adj dict2[n][m])

if adj dict2[temp]for l in range(len(adj dict2[temp])minus1minus1minus1)

if (adj dict2[temp][l]=n)adj dict2[adj dict2[temp][l]]remove(temp)adj dict2[temp]remove(adj dict2[temp][l])

break

def useless edges(num nodesadj dict1matching dict1uselessadj dict2G)for n in range(0num nodes)

for k in adj dict1[n]if ([k]=matching dict1[n]) and matching dict1[n] and matching dict1[k]

uselessadd edge(nk)Gremove edge(n k)

Appendix A 47

tempa=kadj dict2[n]remove(k)adj dict2[tempa]remove(n)adj dict1[tempa]remove(n)

return G

def Greedy(num nodesadj dict3matching dict2)

for n in range(0num nodes)if matching dict2[n]

flag2=minus1flag3=minus1for v in adj dict3[n]

if not matching dict2[v]flag2=vbreak

for p in adj dict3[matching dict2[n][0]]if not matching dict2[p]

flag3=pbreak

if (flag2=minus1) and (flag3=minus1) and (flag2=flag3)tempr=matching dict2[n][0]matching dict2[n]=[flag2]matching dict2[flag2]=[n]matching dict2[tempr]=[flag3]matching dict2[flag3]=[tempr]

elsefor k in adj dict3[n]

if not matching dict2[k]matching dict2[n]=[k]matching dict2[k]=[n]break

yo1=0for i in range(0num nodes)

if matching dict2[i] and [i]==matching dict2[matching dict2[i][0]]yo1=yo1+1

greedy size=yo12return greedy size

def General()

INPUTSwb = xlwtWorkbook()ws = wbadd sheet(Results Random)book=xlrdopen workbook(filenames randomxls)

48 Application

style0 = xlwteasyxf(fontbold on)style1 = xlwteasyxf(num format str=0000)INPUTSwswrite(0 0File style0)wswrite(0 1 Nodesstyle0)wswrite(0 2 Initial matchingstyle0)wswrite(0 3 NodesGstyle0)wswrite(0 4 EdgesGstyle0)wswrite(0 5 MaxDegreeGstyle0)wswrite(0 6 NodesG hatstyle0)wswrite(0 7 EdgesG Hatstyle0)wswrite(0 8 Useless edgesstyle0)wswrite(0 9 Forced edgesstyle0)wswrite(0 10 MaxDegreeG Hatstyle0)wswrite(0 11 Classical matchingstyle0)wswrite(0 12 Final matchingstyle0)wswrite(0 13 Greedy matchingstyle0)wswrite(0 14 Time classicalstyle0)wswrite(0 15 Time algorithmstyle0)wswrite(0 16 Time greedystyle0)wswrite(0 17 Perfect matching ratiostyle0)wswrite(0 18 Nodes ratiostyle0)wswrite(0 19 Edges ratiostyle0)wswrite(0 20 Matching ratiostyle0)

print nWelcomeThis is an implementation for general random graphs It uses Edmonds algorithm to compute maximum matching on G Hatn

for index in range (1481)was 481

if (index==482)f=open(Algotel generaltxtr)readlines()

elsefilea=str(booksheet by index(0)cell(index0))s=fileareplace(textu)replace()f=open(sr)readlines()Truewswrite(index 0 s)

print index

num nodes=int([xstrip()split() for x in f][0][0])

num matching=int([xstrip()split() for x in f][2][0])

adj temp = [xstrip()split() for x in f][44+num nodes]adj=[map(intR) for R in adj temp]

matching temp=[xstrip()split() for x in f][4+num nodes+14+2num nodes+1]matching1=[map(intR) for R in matching temp]

adj dict1=i[ii for iix in enumerate(L) if x] for iL in enumerate(adj)adj dict2=i[ii for iix in enumerate(L) if x] for iL in enumerate(adj)

Appendix A 49

adj dict3=i[ii for iix in enumerate(L) if x] for iL in enumerate(adj)

matching dict1=i[ii for iix in enumerate(L) if x] for iL in enumerate(matching1)matching dict2=i[ii for iix in enumerate(L) if x] for iL in enumerate(matching1)print adj dict2print matching dict2wswrite(index 1 num nodes)wswrite(index 2 num matching)

G = nxGraph()

useless= nxGraph()forced = nxGraph()

Fill Graphfor n in range(0num nodes)

for k in adj dict1[n]Gadd edge(nk)

Gt=Gnumber of edges()wswrite(index 3 Gnumber of nodes())wswrite(index 4 Gnumber of edges())wswrite(index 5 max(Gdegree()values()))

Compute Edmonds classical matching on G for comparison

startB = timeitdefault timer()Classical Matching=nxmax weight matching(G maxcardinality=False)stopB = timeitdefault timer()

Compute Gˆ nad MˆstartC = timeitdefault timer()useless edges(num nodesadj dict1matching dict1uselessadj dict2G)forced edges(Gadj dict2matching dict1num nodesforced)Final Matching=nxmax weight matching(G maxcardinality=False)stopC = timeitdefault timer()

GreedystartG = timeitdefault timer()greedy size=Greedy(num nodesadj dict3matching dict2)stopG = timeitdefault timer()

wswrite(index 6 Gnumber of nodes())wswrite(index 7 Gnumber of edges())wswrite(index 8 uselessnumber of edges())wswrite(index 9 forcednumber of edges())if Gdegree()values()

wswrite(index 10 max(Gdegree()values()))else

50 Application

wswrite(index 10 0)wswrite(index 11 len(Classical Matching)2)wswrite(index 12 len(Final Matching)2+forcednumber of edges())wswrite(index 13 greedy size)wswrite(index 14 stopB minus startBstyle1)wswrite(index 15 stopC minus startCstyle1)wswrite(index 16 stopG minus startGstyle1)wswrite(index 17 (len(Final Matching)2+forcednumber of edges())(num nodes2)style1)wswrite(index 18 Gnumber of nodes()Gtstyle1)wswrite(index 19 Gnumber of edges()Gtstyle1)wswrite(index 20 (len(Final Matching)2+forcednumber of edges())(len(Classical Matching)2)style1)

wbsave(AA Results Random Reyni Large Bipartitexls)

Main function Here we must choose the input form of the dataif name == main

startA = timeitdefault timer()General()stopA = timeitdefault timer()

print nThis program has terminatednnRunning time for 480 files stopAminusstartAprint nnPlease open AA Results Random Reyni Largexls file to see the Results

Appendix A 51

Plotmat

clear allclose allload(RN1Lmat)load(RN1Smat)load(RN2Lmat)load(RN2Smat)load(RN3Lmat)load(RN3Smat)

Plotsh(1)=figure(NameHistogram of Matching size difference between Constraint Algorithm and Greedy AlgorithmNumberTitleoff)

RN1L Greedydiff=RN1L Final matchingminusRN1L Greedy matchingRN2L Greedydiff=RN2L Final matchingminusRN2L Greedy matchingRN3L Greedydiff=RN3L Final matchingminusRN3L Greedy matchingRN1S Greedydiff=RN1S Final matchingminusRN1S Greedy matchingRN2S Greedydiff=RN2S Final matchingminusRN2S Greedy matchingRN3S Greedydiff=RN3S Final matchingminusRN3S Greedy matching

RN1L Finaldiff=RN1L Classical matchingminusRN1L Final matchingRN2L Finaldiff=RN2L Classical matchingminusRN2L Final matchingRN3L Finaldiff=RN3L Classical matchingminusRN3L Final matchingRN1S Finaldiff=RN1S Classical matchingminusRN1S Final matchingRN2S Finaldiff=RN2S Classical matchingminusRN2S Final matchingRN3S Finaldiff=RN3S Classical matchingminusRN3S Final matching

RN1L Classicaldiff=(RN1L Nodes2)minusRN1L Classical matchingRN2L Classicaldiff=(RN2L Nodes2)minusRN2L Classical matchingRN3L Classicaldiff=(RN3L Nodes2)minusRN3L Classical matchingRN1S Classicaldiff=(RN1S Nodes2)minusRN1S Classical matchingRN2S Classicaldiff=(RN2S Nodes2)minusRN2S Classical matchingRN3S Classicaldiff=(RN3S Nodes2)minusRN3S Classical matching

subplot(231)hold onhistf(RN1L Greedydiff0110facecolorbfacealpha9edgealpha1)histf(RN1L Finaldiff0110facecolorrfacealpha5edgealpha1)histf(RN1L Classicaldiff0110facecolorgfacealpha5edgealpha1)legalpha(ConminusGreClasminusConPerfminusClasslocationnortheast)legend boxoffaxis tightxlabel(edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN1L)grid on

subplot(232)hold onhistf(RN2L Greedydiff0110facecolorbfacealpha9edgealpha1)

52 Application

histf(RN2L Finaldiff0110facecolorrfacealpha5edgealpha1)histf(RN2L Classicaldiff0110facecolorgfacealpha5edgealpha1)legalpha(ConminusGreClasminusConPerfminusClasslocationnortheast)legend boxoffaxis tightxlabel(edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN2L)grid on

subplot(233)hold onhistf(RN3L Greedydiff0110facecolorbfacealpha5edgealpha1)histf(RN3L Finaldiff0110facecolorrfacealpha5edgealpha1)histf(RN3L Classicaldiff0110facecolorgfacealpha5edgealpha1)legalpha(ConminusGreClasminusConPerfminusClasslocationnortheast)legend boxoffaxis tightxlabel(edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN3L)grid on

subplot(234)hold onhistf(RN1S Greedydiff0110facecolorbfacealpha5edgealpha1)histf(RN1S Finaldiff0110facecolorrfacealpha5edgealpha1)histf(RN1S Classicaldiff0110facecolorgfacealpha5edgealpha1)legalpha(ConminusGreClasminusConPerfminusClasslocationnortheast)legend boxoffaxis tightxlabel(edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(R1NS)grid on

subplot(235)hold onhistf(RN2S Greedydiff0110facecolorbfacealpha5edgealpha1)histf(RN2S Finaldiff0110facecolorrfacealpha5edgealpha1)histf(RN2S Classicaldiff0110facecolorgfacealpha5edgealpha1)legalpha(ConminusGreClasminusConPerfminusClasslocationnortheast)legend boxoffaxis tightxlabel(edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN2S)grid on

subplot(236)hold onhistf(RN3S Greedydiff0110facecolorbfacealpha5edgealpha1)histf(RN3S Finaldiff0110facecolorrfacealpha5edgealpha1)histf(RN3S Classicaldiff0110facecolorgfacealpha5edgealpha1)

Appendix A 53

legalpha(ConminusGreClasminusConPerfminusClasslocationnortheast)legend boxoffaxis tightgrid ontitle(RN3S)xlabel(edges) xminusaxis labelylabel(instances) yminusaxis labelset(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN1png minusr300)h(2)=figure(NameHistogram of Max Degree of G AND G HatNumberTitleoff)RN1L x=RN1L MaxDegreeGminusRN1L MaxDegreeG HatRN2L x=RN2L MaxDegreeGminusRN2L MaxDegreeG HatRN3L x=RN3L MaxDegreeGminusRN3L MaxDegreeG HatRN1S x=RN1S MaxDegreeGminusRN1S MaxDegreeG HatRN2S x=RN2S MaxDegreeGminusRN2S MaxDegreeG HatRN3S x=RN3S MaxDegreeGminusRN3S MaxDegreeG Hatsubplot(231)hold onhistf(RN1L MaxDegreeG0150facecolorbfacealpha5edgealpha1)histf(RN1L MaxDegreeG Hat0150facecolorrfacealpha5edgealpha1)histf(RN1L x0150facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightxlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN1L)grid on

subplot(232)hold onhistf(RN2L MaxDegreeG010500facecolorbfacealpha5edgealpha1)histf(RN2L MaxDegreeG Hat010500facecolorrfacealpha5edgealpha1)histf(RN2L x010500facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightxlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN2L)grid on

subplot(233)hold onhistf(RN3L MaxDegreeG010300facecolorbfacealpha5edgealpha1)histf(RN3L MaxDegreeG Hat010300facecolorrfacealpha5edgealpha1)histf(RN3L x010300facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightxlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN3L)

54 Application

grid on

subplot(234)hold onhistf(RN1S MaxDegreeG0150facecolorbfacealpha5edgealpha1)histf(RN1S MaxDegreeG Hat0150facecolorrfacealpha5edgealpha1)histf(RN1S x0150facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightxlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(R1NS)grid on

subplot(235)hold onhistf(RN2S MaxDegreeG010500facecolorbfacealpha5edgealpha1)histf(RN2S MaxDegreeG Hat010500facecolorrfacealpha5edgealpha1)histf(RN2S x010500facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightxlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN2S)grid on

subplot(236)hold onhistf(RN3S MaxDegreeG05300facecolorbfacealpha5edgealpha1)histf(RN3S MaxDegreeG Hat05300facecolorrfacealpha5edgealpha1)histf(RN3S x05300facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightgrid ontitle(RN3S)xlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labelset(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN2png minusr300)

h(3)=figure(NameComputation time over edgesNumberTitleoff)

subplot(231)hold onstem(RN1L EdgesGRN1L Time classicalg)stem(RN1L EdgesGRN1L Time algorithmro)stem(RN1L EdgesGRN1L Time greedybx)grid on

Appendix A 55

title(RN1L)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)

subplot(232)hold onstem(RN2L EdgesGRN2L Time classicalg)stem(RN2L EdgesGRN2L Time algorithmro)stem(RN2L EdgesGRN2L Time greedybx)grid ontitle(RN2L)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)

subplot(233)hold onstem(RN3L EdgesGRN3L Time classicalg)stem(RN3L EdgesGRN3L Time algorithmro)stem(RN3L EdgesGRN3L Time greedybx)grid ontitle(RN3L)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)

subplot(234)hold onstem(RN1S EdgesGRN1S Time classicalg)stem(RN1S EdgesGRN1S Time algorithmro)stem(RN1S EdgesGRN1S Time greedybx)grid ontitle(RN1S)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)

subplot(235)hold onstem(RN2S EdgesGRN2S Time classicalg)stem(RN2S EdgesGRN2S Time algorithmro)stem(RN2S EdgesGRN2S Time greedybx)grid ontitle(RN2S)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)

subplot(236)hold onstem(RN3S EdgesGRN3S Time classicalg)stem(RN3S EdgesGRN3S Time algorithmro)stem(RN3S EdgesGRN3S Time greedybx)

56 Application

grid ontitle(RN3S)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)set(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN3png minusr300)

h(4)=figure(NameSorted matching sizeNumberTitleoff)RN1L Sorted matching temp(1)=RN1L Classical matchingRN1L Sorted matching temp(2)=RN1L Final matchingRN1L Sorted matching temp(3)=RN1L Greedy matchingRN1L Sorted matching temp(4)=RN1L Initial matchingRN1L Sorted matching=sortrows(RN1L Sorted matching temp)

RN2L Sorted matching temp(1)=RN2L Classical matchingRN2L Sorted matching temp(2)=RN2L Final matchingRN2L Sorted matching temp(3)=RN2L Greedy matchingRN2L Sorted matching temp(4)=RN2L Initial matchingRN2L Sorted matching=sortrows(RN2L Sorted matching temp)

RN3L Sorted matching temp(1)=RN3L Classical matchingRN3L Sorted matching temp(2)=RN3L Final matchingRN3L Sorted matching temp(3)=RN3L Greedy matchingRN3L Sorted matching temp(4)=RN3L Initial matchingRN3L Sorted matching=sortrows(RN3L Sorted matching temp)

RN1S Sorted matching temp(1)=RN1S Classical matchingRN1S Sorted matching temp(2)=RN1S Final matchingRN1S Sorted matching temp(3)=RN1S Greedy matchingRN1S Sorted matching temp(4)=RN1S Initial matchingRN1S Sorted matching=sortrows(RN1S Sorted matching temp)

RN2S Sorted matching temp(1)=RN2S Classical matchingRN2S Sorted matching temp(2)=RN2S Final matchingRN2S Sorted matching temp(3)=RN2S Greedy matchingRN2S Sorted matching temp(4)=RN2S Initial matchingRN2S Sorted matching=sortrows(RN2S Sorted matching temp)

RN3S Sorted matching temp(1)=RN3S Classical matchingRN3S Sorted matching temp(2)=RN3S Final matchingRN3S Sorted matching temp(3)=RN3S Greedy matchingRN3S Sorted matching temp(4)=RN3S Initial matchingRN3S Sorted matching=sortrows(RN3S Sorted matching temp)

subplot(231)hold onplot(RN1L Sorted matching(1)b)plot(RN1L Sorted matching(2)g)plot(RN1L Sorted matching(3)r)plot(RN1L Sorted matching(4)m)

Appendix A 57

grid ontitle(RN1L)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)

subplot(232)hold onplot(RN2L Sorted matching(1)b)plot(RN2L Sorted matching(2)g)plot(RN2L Sorted matching(3)r)plot(RN2L Sorted matching(4)m)grid ontitle(RN2L)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)

subplot(233)hold onplot(RN3L Sorted matching(1)b)plot(RN3L Sorted matching(2)g)plot(RN3L Sorted matching(3)r)plot(RN3L Sorted matching(4)m)grid ontitle(RN3L)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)

subplot(234)hold onplot(RN1S Sorted matching(1)b)plot(RN1S Sorted matching(2)g)plot(RN1S Sorted matching(3)r)plot(RN1S Sorted matching(4)m)grid ontitle(RN1S)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)

subplot(235)hold onplot(RN2S Sorted matching(1)b)plot(RN2S Sorted matching(2)g)plot(RN2S Sorted matching(3)r)plot(RN2S Sorted matching(4)m)grid ontitle(RN2S)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)

58 Application

subplot(236)hold onplot(RN3S Sorted matching(1)b)plot(RN3S Sorted matching(2)g)plot(RN3S Sorted matching(3)r)plot(RN3S Sorted matching(4)m)grid ontitle(RN3S)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)set(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN4png minusr300)h(5)=figure(NameSorted RatiosNumberTitleoff)RN1L ratio1=RN1L NodesG hatRN1L NodesGRN2L ratio1=RN2L NodesG hatRN2L NodesGRN3L ratio1=RN3L NodesG hatRN3L NodesGRN1S ratio1=RN1S NodesG hatRN1S NodesGRN2S ratio1=RN2S NodesG hatRN2S NodesGRN3S ratio1=RN3S NodesG hatRN3S NodesG

RN1L ratio2=RN1L EdgesG HatRN1L EdgesGRN2L ratio2=RN2L EdgesG HatRN2L EdgesGRN3L ratio2=RN3L EdgesG HatRN3L EdgesGRN1S ratio2=RN1S EdgesG HatRN1S EdgesGRN2S ratio2=RN2S EdgesG HatRN2S EdgesGRN3S ratio2=RN3S EdgesG HatRN3S EdgesG

RN1L ratio3=RN1L MaxDegreeG HatRN1L MaxDegreeGRN2L ratio3=RN2L MaxDegreeG HatRN2L MaxDegreeGRN3L ratio3=RN3L MaxDegreeG HatRN3L MaxDegreeGRN1S ratio3=RN1S MaxDegreeG HatRN1S MaxDegreeGRN2S ratio3=RN2S MaxDegreeG HatRN2S MaxDegreeGRN3S ratio3=RN3S MaxDegreeG HatRN3S MaxDegreeG

RN1L ratio(1)=RN1L ratio1RN1L ratio(2)=RN1L ratio2RN1L ratio(3)=RN1L ratio3

RN2L ratio(1)=RN2L ratio1RN2L ratio(2)=RN2L ratio2RN2L ratio(3)=RN2L ratio3

RN3L ratio(1)=RN3L ratio1RN3L ratio(2)=RN3L ratio2RN3L ratio(3)=RN3L ratio3

RN1S ratio(1)=RN1S ratio1RN1S ratio(2)=RN1S ratio2RN1S ratio(3)=RN1S ratio3

RN2S ratio(1)=RN2S ratio1

Appendix A 59

RN2S ratio(2)=RN2S ratio2RN2S ratio(3)=RN2S ratio3

RN3S ratio(1)=RN3S ratio1RN3S ratio(2)=RN3S ratio2RN3S ratio(3)=RN3S ratio3

RN1L ratio sorted=sortrows(RN1L ratio)RN2L ratio sorted=sortrows(RN2L ratio)RN3L ratio sorted=sortrows(RN3L ratio)RN1S ratio sorted=sortrows(RN1S ratio)RN2S ratio sorted=sortrows(RN2S ratio)RN3S ratio sorted=sortrows(RN3S ratio)

subplot(231)hold onplot(RN1L ratio sorted(1)b)plot(RN1L ratio sorted(2)g)plot(RN1L ratio sorted(3)r)grid ontitle(RN1L)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)

subplot(232)hold onplot(RN2L ratio sorted(1)b)plot(RN2L ratio sorted(2)g)plot(RN2L ratio sorted(3)r)grid ontitle(RN2L)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)

subplot(233)hold onplot(RN3L ratio sorted(1)b)plot(RN3L ratio sorted(2)g)plot(RN3L ratio sorted(3)r)grid ontitle(RN3L)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)

subplot(234)hold onplot(RN1S ratio sorted(1)b)plot(RN1S ratio sorted(2)g)plot(RN1S ratio sorted(3)r)grid on

60 Application

title(RN1S)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)

subplot(235)hold onplot(RN2S ratio sorted(1)b)plot(RN2S ratio sorted(2)g)plot(RN2S ratio sorted(3)r)grid ontitle(RN2S)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)

subplot(236)hold onplot(RN3S ratio sorted(1)b)plot(RN3S ratio sorted(2)g)plot(RN3S ratio sorted(3)r)grid ontitle(RN3S)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)set(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN5png minusr300)

h(6)=figure(NameSorted edges over nodesNumberTitleoff)

RN1L DegreeG1=(RN1L EdgesG)(RN1L NodesG)RN1L DegreeG Hat1=(RN1L EdgesG Hat)(RN1L NodesG hat)

RN1L Degree temp1(1)=RN1L DegreeG1RN1L Degree temp1(2)=RN1L DegreeG Hat1RN1L Degree sorted1=sortrows(RN1L Degree temp1)subplot(231)hold on

plot(RN1L Degree sorted1(1)b)plot(RN1L Degree sorted1(2)g)grid ontitle(RN1L)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)

RN2L DegreeG1=(RN2L EdgesG)(RN2L NodesG)RN2L DegreeG Hat1=(RN2L EdgesG Hat)(RN2L NodesG hat)

RN2L Degree temp1(1)=RN2L DegreeG1

Appendix A 61

RN2L Degree temp1(2)=RN2L DegreeG Hat1RN2L Degree sorted1=sortrows(RN2L Degree temp1)

subplot(232)hold onplot(RN2L Degree sorted1(1)b)plot(RN2L Degree sorted1(2)g)grid ontitle(RN2L)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)

RN3L DegreeG1=(RN3L EdgesG)(RN3L NodesG)RN3L DegreeG Hat1=(RN3L EdgesG Hat)(RN3L NodesG hat)

RN3L Degree temp1(1)=RN3L DegreeG1RN3L Degree temp1(2)=RN3L DegreeG Hat1RN3L Degree sorted1=sortrows(RN3L Degree temp1)

subplot(233)hold onplot(RN3L Degree sorted1(1)b)plot(RN3L Degree sorted1(2)g)grid ontitle(RN3L)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)

RN1S DegreeG1=(RN1S EdgesG)(RN1S NodesG)RN1S DegreeG Hat1=(RN1S EdgesG Hat)(RN1S NodesG hat)

RN1S Degree temp1(1)=RN1S DegreeG1RN1S Degree temp1(2)=RN1S DegreeG Hat1RN1S Degree sorted1=sortrows(RN1S Degree temp1)

subplot(234)hold onplot(RN1S Degree sorted1(1)b)plot(RN1S Degree sorted1(2)g)grid ontitle(RN1S)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)

RN2S DegreeG1=(RN2S EdgesG)(RN2S NodesG)RN2S DegreeG Hat1=(RN2S EdgesG Hat)(RN2S NodesG hat)

RN2S Degree temp1(1)=RN2S DegreeG1

62 Application

RN2S Degree temp1(2)=RN2S DegreeG Hat1RN2S Degree sorted1=sortrows(RN2S Degree temp1)

subplot(235)hold onplot(RN2S Degree sorted1(1)b)plot(RN2S Degree sorted1(2)g)grid ontitle(RN2S)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)

RN3S DegreeG1=(RN3S EdgesG)(RN3S NodesG)RN3S DegreeG Hat1=(RN3S EdgesG Hat)(RN3S NodesG hat)

RN3S Degree temp1(1)=RN3S DegreeG1RN3S Degree temp1(2)=RN3S DegreeG Hat1RN3S Degree sorted1=sortrows(RN3S Degree temp1)

subplot(236)hold onplot(RN3S Degree sorted1(1)b)plot(RN3S Degree sorted1(2)g)grid ontitle(RN3S)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)set(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN6png minusr300)h(7)=figure(NameSorted mATCHED DEGREENumberTitleoff)RN1L ratioMax(1)=RN1L MaxDegreeGRN1L ratioMax(2)=RN1L MaxDegreeG Hat

RN1L ratio sortedMax=sortrows(RN1L ratioMax)subplot(231)hold onplot(RN1L ratio sortedMax(1)b)plot(RN1L ratio sortedMax(2)g)grid ontitle(RN1L)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)

RN2L ratioMax(1)=RN2L MaxDegreeGRN2L ratioMax(2)=RN2L MaxDegreeG Hat

RN2L ratio sortedMax=sortrows(RN2L ratioMax)subplot(232)

Appendix A 63

hold onplot(RN2L ratio sortedMax(1)b)plot(RN2L ratio sortedMax(2)g)grid ontitle(RN2L)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)

RN3L ratioMax(1)=RN3L MaxDegreeGRN3L ratioMax(2)=RN3L MaxDegreeG Hat

RN3L ratio sortedMax=sortrows(RN3L ratioMax)subplot(233)hold onplot(RN3L ratio sortedMax(1)b)plot(RN3L ratio sortedMax(2)g)grid ontitle(RN3L)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)

RN1S ratioMax(1)=RN1S MaxDegreeGRN1S ratioMax(2)=RN1S MaxDegreeG Hat

RN1S ratio sortedMax=sortrows(RN1S ratioMax)subplot(234)hold onplot(RN1S ratio sortedMax(1)b)plot(RN1S ratio sortedMax(2)g)grid ontitle(RN1S)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)

RN2S ratioMax(1)=RN2S MaxDegreeGRN2S ratioMax(2)=RN2S MaxDegreeG Hat

RN2S ratio sortedMax=sortrows(RN2S ratioMax)

subplot(235)hold onplot(RN2S ratio sortedMax(1)b)plot(RN2S ratio sortedMax(2)g)grid ontitle(RN2S)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)

RN3S ratioMax(1)=RN3S MaxDegreeGRN3S ratioMax(2)=RN3S MaxDegreeG Hat

64 Application

RN3S ratio sortedMax=sortrows(RN3S ratioMax)subplot(236)hold onplot(RN3S ratio sortedMax(1)b)plot(RN3S ratio sortedMax(2)g)grid ontitle(RN1L)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)set(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN7png minusr300)

tilefigs()(h)

Bibliography

[1] C Berge ldquoTWO THEOREMS IN GRAPH THEORYrdquo Proceedings of the NationalAcademy of Sciences of the United States of America vol 43 no 9 pp 842ndash844Sep 1957

[2] L Bui S Sanghavi and R Srikant ldquoDistributed link scheduling with constantoverheadrdquo IEEEACM Trans Netw vol 17 no 5 pp 1467ndash1480 2009

[3] R Duan and S Pettie ldquoLinear-time approximation for maximum weight matchingrdquoJ ACM vol 61 no 1 2014

[4] J Edmonds ldquoPaths trees and flowersrdquo Canadian Journal of Mathematics vol 17pp 449ndash467 1965

[5] J E Hopcroft and R M Karp ldquoAn n52 algorithm for maximum matchings inbipartite graphsrdquo SIAM J Comput vol 2 no 4 pp 225ndash231 1973

[6] S Micali and V V Vazirani ldquoAn O(radic|V ||E|) algorithm for finding maximum

matching in general graphsrdquo in 21st Symp on Foundations of Comp Sc (FOCS)IEEE 1980 pp 17ndash27

[7] N Nisse A Salch and V Weber ldquoRecovery of disrupted airline operationsrdquo 2015httphalinriafrSomething

[8] X Wu and R Srikant ldquoRegulated maximal matching A distributed schedulingalgorithm for multi-hop wireless networks with nodeexclusive spectrum sharingrdquo inIEEE Conf on Decision and Control 2005

65

  • Contents
  • Introduction
  • Algorithms
    • Maximum matching
    • k-maximum matching
      • k-matching for Airport Slot assignment
      • The case where k=3
      • The case of Paths
      • The case of the Spider
          • Application
            • Description
            • Reyni Erdos
            • Barabaacutesi Albert
            • Amadeus Graphs
            • Bipartite
            • Bipartite with degree seq
            • Appendix A
              • BipartiteGraphGeneratorpy
              • RandomGraphGeneratorpy
              • kequals3MaximumMatchingpy
              • Plotmat
                  • Bibliography
Page 4: Theodoros Alexandros KARAGKIOULES -  · Introduction This work is the result of a 6 months internship, under the supervision of research O cer Nicolas NISSE. The original scope of

Chapter 1

Algorithms

11 Maximum matching

In this section the Classical Maximum matching is presented

Let G = (VE) be a graph A matching M sube E of G is a set of edges pairwisedisjoint A vertex v isin V is defined as covered by M if there is e isinM such that v isin eOtherwise v is said exposed The size of a maximum matching in G is denoted by micro(G)

The problem of computing a maximum matching has been widely studied and it iswell known that it can be solved in polynomial-time The most popular algorithm forcomputing the classical maximum matching is by Edmonds[4] This algorithm has beenused broadly in the calculations on random graphs that follow in the next chapter

Augmenting Paths A path P = (v0 middot middot middot vk) of G is a sequence of pairwise distinctvertices such that ei = vi vi+1 isin E for each 0 le i lt k The path P is said M -augmenting if v0 and vk are exposed and for any 0 le i lt k ei = vi vi+1 isin M ifand only if i is odd In particular an augmenting path has always an odd length A wellknown theorem of Claude Berge states that a matching M is maximum if and only ifthere are no M -augmenting paths [1]

Related work The first algorithm for solving the maximum matching problem inpolynomial-time in general graphs is due to Edmonds [4] Then many work has beendedicated to design more efficient algorithms In particular the algorithms in [5 6] arebased on augmenting paths in the non-decreasing order of their lengths

12 k-maximum matching

Let microk(GM) denote the size of a maximum matching that can be obtained fromM sube E in G by augmenting paths of length at most kk ge 1 where k is an odd integerTo define the k-Matching Problem one must compute a sequence of augmenting-paths

5

6 Algorithms

of length le k that allow to obtain from M a matching of size microk(GM)

In the cases k isin 1 3 it has been proven that the computational complexity of the k-Matching Problem is equivalent to the one of the classical maximum matching problem(without any constraint on the length of paths) Hence for k isin 1 3 it can be solvedin polynomial time

121 k-matching for Airport Slot assignment

The k-maximum matching problem has been found to have an application in the aviationindustry When an aircraft is approaching an airport it is assigned by Air Traffic Controla landing time (called slot) If there is a delay for any reason (weather conditions latearrival priority) it looses its slot and a new slot needs to by reassigned to it Howeverslots for landing are a scarce resource of the airports and to avoid conflicts and forsafety reasons Airline Operation Controllers have to regularly modify the assignment ofthe slots of the aircraft

This modification of the slot-assignment uses only two kinds of operations either assignaircraft A to a free slot or give A the slot of B and assign B to a free slot The problemis then the following

Let k ge 1 be an odd integer and let G be a graph and M be a matching of GWhat is the maximum size of a matching that can be obtained from M by using onlyaugmenting paths of length at most k

Let G = (X cup YE) be a bipartite graph X represents the set of aircraft and Yrepresents the set of available slots There is an edge between a isin X and s isin Y if theslot s is compatible with the schedules of aircraft A Let M be a matching of G thatcorresponds to a pre-established valid assignment of some slots to some aircraft Theproblem of reassignment of slots is equivalent to computing a maximum matching thatcan be obtained from M by augmenting only paths of length at most 3

122 The case where k=3

Let G be a graph and M sube E(G) be a matching of G An edge e isin E(G) M is saiduseless if e is incident to two edges of M ie if each endpoint of e is incident to oneedge of M An edge e isinM is said forced if at least one of its endpoints has degree onein G

Finally let G be the graph obtained from G and the matching M by first removingall useless edges (but keeping their endpoints) and then by removing the forced edgesand their endpoints Let M be the matching resulting from M in G ie M equals Mminus the forced edges Note that M has no useless edges nor forced edges Abusingthe notations we will identify the paths in G with some paths in G

12 k-maximum matching 7

This algorithm has been used to implement the k-maximum matching programme thatcomputes the data provided by Amadeus and also the randomly generated graphs of thefollowing chapter

123 The case of Paths

Let Q = (v1 middot middot middot vi) be the maximum alternating path containing v1 If Q is notaugmenting or if Q has length more than k (ie i gt k) the algorithm is appliedrecursively on P (v1 middot middot middot viminus1) Otherwise Q is augmented (it is added to the desiredsequence of paths) and the algorithm is applied recursively on P Q

Algorithm 1 k-matching(PnM)

Require A path Pn = (v1 middot middot middot vn) a matching M sube E(P ) and an odd integer k ge 1Ensure A sequence (Q1 middot middot middot Qr) of augmenting paths with r = microk(PM)minus |M |1 if n = 1 then return empty2 else3 Let 1 lt i le n be the smallest integer (at least 2) such that vi is exposed4 if v1 is not exposed OR i gt k then5 Let P prime = (vi middot middot middot vn) and M prime = M cap E(P prime) return k-matching(P primeM prime)6 else7 Let P prime = (vi+1 middot middot middot vn) and M prime = M cap E(P prime) return (v1 middot middot middot vi)cup

k-matching(P primeM prime)8 end if9 end if

124 The case of the Spider

Theorem 11 Let S be a spider andM its initial matching and (P1 Pr) a sequenceof augmenting paths of length le k such that microk(SM) = |M |+ r then exist (Q1 Qr)a sequence of augmenting paths of length le k such that at most one such path containsthe center C

Proof Let S be a spider and lets assume that the optimal sequence of augmentingpaths SP is known along with the set of branches Br (those paths of S from a leaf tothe nn of CAssume for contradiction that exist ge 2 augmenting paths that contain the center Cand let Pi and Pj be the first such paths Let Pi = (umi

C uni) and Pj =

(umj C unj

) and let Q = (umi C unj

) be the (augmenting) pathcontaining partially Pi the center C and partially Pj Since [C uni

] sub [C unj] in order

for Pj to be an augmenting path then exist H = (Pj Pi) Q Letrsquos also assume thatthere is a set of paths A = A1 At isin SP between Pi and Pj and A sube Brsuch that forallk isin 1 2 t Ak Pi = empty or Ak Pj = empty Also there is a set of pathsB = B1 Bf isin SP between Pi and Pj and B sube Br such that foralln isin 1 2 fBn is non intersecting with any paths in AQPi Pj and H Then the optimal sequenceof augmenting paths can be the following

8 Algorithms

P1 P2 P3 A1 At QB1 Bf H Pr where augmenting only path Q oncecan lead to the equivalently optimal solution

Algorithm 2 Spider algorithm(SM)

1 M prime = M2 Let there be a set of leaves λ1 λr3 xk is the nn of C in the path C rarr λk4 for i isin 1 r do5 for j 6= i do M primeprime=Path Algorithm(λi rarr λjM)6 for k isin i j do M primeprime=M primeprimecupPath Algorithm(λk rarr xkM)7 end for8 end for9 if M primeprime gt M prime then10 M prime = M primeprime

11 end if12 end for13 return M prime

Proof Let there be an optimal solution that is obtained by the paths in the sequenceQprime = (P prime1 P

primer) for the spider

Let there also be a set of paths from leaf to leaf PLL = Pll1 P lln a set ofbranches BR = Br1 Brm and a sequence of augmenting paths Q = (P1 Pr)such that for j isin 1 r Pj isin PLL and forall i 6= j isin 1 r Pi isin BR

Applying the path algorithm for Pj and then for the r minus 1 paths of Q and due toTheorem 21 it is ensured that the matching produced will lead to a feasible solutionsince C is never exposed

Due to the iterative nature of the algorithm it can be checked that all possible com-binations of Pj and Pi that construct Q are considered and that one of the solutionscomputed as above will be the initial optimal solution Qprime

Thus by induction Spider Algorithm will always produce an optimal matching on aSpider

Chapter 2

Application

21 Description

This chapter aims at providing the picture of analysis on the data provided by Amadeusthe bipartite graphs and the random graphs generated

The random graphs have been generated as purely random graphs based on the ReyniErdos and the Barabasi Albert with different values of connectivity probability or con-nectivity

The bipartite graphs were generated on the density of the Amadeus graphs to simu-late better the results Additionally an extra set of test have been made on bipartitegraphs that simulate the degree distribution of the Amadeus graphs Certain classesof degree distribution were selected and based on those 480 bipartite graphs have beengenerated

At every graph the classical matching is computed based on the Edmonds algorithmthen the k-matching algorithm is used as described in section 122 Lastly a greedyalgorithm is implemented to be used for comparison

The ultimate goal is to explore the efficiency of the k-matching algorithm for the caseof k = 3 and to compare it with the result of the Edmonds algorithm and of course theGreedy implementationThe results follow along with some comments

9

10 Application

22 Reyni Erdos

bull RNxy are randomly generated graphs with a fixed number of 1000 nodes

bull There are 6 categories based on the initial matching and probability p of connection

bull x = L S L When the initial matching is large and S when it is small

bull y = 1 2 3 1 when p = lognn

2 when p = 13

and 3 when p = lognn

+ 01

Computation time over |E|

Computation time over |E| - Comments

bull This is a very straightforward set of figures

22 Reyni Erdos 11

bull When the initial matching is sufficiently large then the forced edges are taken out(a process which takes a fragment of the computation time) and then the classicalmatching algorithm (Edmonds) is applied on a smaller graph(G) This reducessignificantly the computation time

bull When the initial matching is small then the computation time of the constraintalgorithm might be larger than that of Edmonds The reason is that the constraintalgorithm need some time to compute the useless and forced edges and thenEdmonds algorithm is applied on G G Thus the overall processing time issometimes larger

Sorted matching size

Sorted matching size - Comments

12 Application

bull This set of figures represents the ascending order of the Classical matching sizealong with its corresponding Constraint and Greedy equivalent

bull When the probability is sufficiently higher than the threshold lognn

then the threealgorithms produce identical results of optimal matching

bull For lower probability there is a difference between the results of the algorithms

bull the degree of that difference is depicted in the first set of figures presented

bull It is interesting to observe that a change on the Constraint algorithm is associatedwith a even more significant change in the Greedy algorithm

bull There is a difference only when the probability is at the connectedness threshholdlognn

bull The difference is very small compared to the size of the matching ( 500)

bull The difference in matching size appears mostly at the Greedy implementationwhen compared to the constraint algorithm

Sorted Ratios

22 Reyni Erdos 13

Sorted Ratios - Comments

bull This set of figures depicts the ratios VV

EE

∆∆

in ascending order of VV

bull It is evident that when the initial matching is large the amount of forced edges(and their endpoints) removed is high thus the ratio of Nodes and edges is verylow For higher probabilities almost all edges are removed as useless

bull For a smaller initial matching almost no forced edges (and their endpoints) areremoved which we conclude be the node ration being close to 1 There is somesmall amount of useless edges removed though since the ratio of edges is less butclose to 1

bull The ratio of ∆ for large initial matching follows the trend of the node ratio yetfor smaller initial matching it deviates significantly

14 Application

Sorted |E||V |

Sorted |E||V | - Comments

bull Although as graph density the ratio 2|E||V |(|V |minus1)

is considered in this set of figures

we evaluate the correlation of the ratio |E||V | of G and G since the density of G

could acquire values higher than that of G

bull The figures are calculated in ascending order for the ratio of G

bull For the case of large initial matching the two ratios for G and G remain almostconstant ( to the extent of the probability of each graph) since removing forcededges( and their endpoints) alters the |E| and |V | proportionately

22 Reyni Erdos 15

bull For the case of small initial matching we observe some deviation in the valuesof the ration for G and that is explained with the removal of only useless edgeswhich only alters the |E| and keeps |V | in the original values

Sorted ∆

Sorted ∆-Comments

bull In this set of figures the ascending order of the ∆ of G is associated with the ∆of G

bull There is no significant jump of the ∆ for each graph category which tells that thatwe are comparing a uniform distribution of random grapghs for each probabilitycase

16 Application

bull For larger initial matching we observe the difference in the ∆s of G and G giventhe removed forced edges( and their endpoints) At some cases the ∆ of G dropsto 0 since the vast majority of edges have been declared forced and removed alongwith their endpoints

bull For smaller initial matching the ∆s of G and G follow mostly the same trend onlya few number of different instances

23 Barabasi Albert

Graph characteristics Barabasi Albert

bull BAxy are randomly generated graphs with a fixed number of 1000 nodes

bull There are 6 categories based on ini matching and of attached edges m

bull x = L S L When the initial matching is large and S when it is small

bull y = 1 2 3 1 when m = [1 10] 2 when m = [20 50] and 3 m = [50 100]

Computation time over |E|

23 Barabasi Albert 17

Computation time over |E| - Comments

bull When the initial matching is sufficiently large then the forced edges are taken out(a process which takes a fragment of the computation time) and then the classicalmatching algorithm (Edmonds) is applied on a smaller graph(G) This reducessignificantly the computation time

bull When the initial matching is small then the computation time of the constraintalgorithm might be larger than that of Edmonds The reason is that the constraintalgorithm need some time to compute the useless and forced edges and thenEdmonds algorithm is applied on G G Thus the overall processing time issometimes larger

Sorted matching size

18 Application

Sorted matching size-Comments

bull In this graph the matching size of the classical algorithm is depicted in ascendingorder along with the corresponding constraint algorithm and greedy result

bull Here in the case where m is small for both cases of initial matching (small large)the result may vary greatly starting from a value of half the perfect matching withsmall differences between the results of the various algorithm implementations

bull For the other cases of m the results converge

bull This is explained as for small values of m the graph is disconnected

bull In the matching size difference set of figures a very noticing difference value ap-pears For the cases of small m( the number of existing nodes that a new node isconnected to at the creation of the graph) we can see that the difference in the

23 Barabasi Albert 19

matching size compared to that of the perfect matching could be up to 40 ofthat of the matching size So there are occasions where the matching size is 200edges when the perfect matching would have been 500

bull the difference between the Constraint matching and the classical matching andthe difference of the constraint matching and that of the greedy matching do notshow significant values

Sorted Ratios

Sorted Ratio s -Comments

bull This set of figures depicts the ratios VV

EE

∆∆

in ascending order of VV

20 Application

bull It is evident that when the initial matching is large the amount of forced edges(and their endpoints) removed is high thus the ratio of Nodes and edges is verylow For higher probabilities almost all edges are removed as useless

bull For a smaller initial matching almost no forced edges (and their endpoints) areremoved which we conclude be the node ration being close to 1 There is somesmall amount of useless edges removed though since the ratio of edges is less butclose to 1

bull The ratio of ∆ for large initial matching follows the trend of the node ratio yetfor smaller initial matching it deviates significantly

Sorted |E||V |

23 Barabasi Albert 21

Sorted |E||V | - Comments

bull Although as graph density the ratio 2|E||V |(|V |minus1)

is considered in this set of figures

we evaluate the correlation of the ratio |E||V | of G and G since the density of G

could acquire values higher than that of G

bull The figures are calculated in ascending order for the ratio of G

bull For the case of large initial matching the two ratios for G and G remain almostconstant ( to the extent of the edge attraction m of each graph) since removingforced edges( and their endpoints) alters the |E| and |V | proportionately

bull For the case of small initial matching we observe some deviation in the valuesof the ration for G and that is explained with the removal of only useless edgeswhich only alters the |E| and keeps |V | in the original values

Sorted ∆

22 Application

Sorted ∆-Comments

bull In this set of figures the ascending order of the ∆ of G is associated with the ∆of G

bull There is a significant jump of the ∆ for each graph category which tells that thatwe are not comparing a uniform distribution of random graphs and based on theedge attraction m the graphs can vary in form

bull For larger initial matching we observe the difference in the ∆s of G and G giventhe removed forced edges( and their endpoints) At some cases the ∆ of G dropsto 0 since the vast majority of edges have been declared forced and removed alongwith their endpoints What is interesting is that the ∆ of G oscilates within stablelimits

24 Amadeus Graphs 23

bull For smaller initial matching the ∆s of G and G follow mostly the same trend onlya few number of different instances

24 Amadeus Graphs

Graph characteristics Amadeus graphs

bull These are the bipartite graphs provided by Amadeus

Computation time over |E|

Computation time over |E| - Comments

24 Application

bull For every instance the computation time of the classical algorithm is always smallerto that of the constraint matching

bull This allows as to speculate that we always compute a smaller G which also impliesthat we always find a set of forced edges and useless

Sorted matching size

Sorted matching size - Comments

bull Size of matching has an upward trend since the magnitude of the graphs is notthe same for the 160 instances

bull No significant deviation is noticed as per the first graph

24 Amadeus Graphs 25

bull Except from deviation from the perfect matching (number of flights) where some-times it could get up to 40

bull For the Amadeus Bipartite graphs we can see that the difference of the Classicaland the constraint implementation is not more than 1 edge in the matching

bull There appears to be a difference of up to 24 edges between the Classical matchingand the Perfect matching which is computed as the number of flights

bull The greedy algorithm performs well with only a few instances deviating slightlyform the Constraint algorithm result

Sorted Ratios

Sorted Ratios - Comments

26 Application

bull

Sorted |E||V |

Sorted |E||V | - Comments

bull Density of the graphs shows that on average we have 25-3 available time slot perflight

bull The line for the same value for G shows that there is a large deviation for everyinstance which allows for the hypothesis that the amount of useless+forced edgesof G has no obvious correlation to that of G

25 Bipartite 27

Sorted ∆

Sorted ∆-Comments

bull As per the previous related graphs for ∆ there is in significant drop in the ∆ of Gand G

25 Bipartite

Graph characteristics Bipartite random Graphs

bull BIPxy are randomly generated graphs with a fixed number of 1000(n=500 andm=500) nodes

bull There are 6 categories based on ini matching and probability p

28 Application

bull Probability p has been chosen as such in order to simulate the |E||V | 25 of theAmadeus bipartite graphs

bull So in order to have about 2-4 edges for every node we choose accordingly theprobability p to choose one of the n lowastm possible edges

bull x = L S L When the initial matching is large and S when it is small

bull y = 1 2 3 1 when p = 18250

2 when p = 25250

and 3 when p = 34250

Computation time over

Computation time overedges-Comments

bull

25 Bipartite 29

Sorted matching size

Sorted matching size-Comments

bull In these set of graphs one can instantly notice that only a few instances with highprobability can reach a matching size equal to the perfect matching

bull For the case of the initial matching we witness that there is a gap between the lineof the classical matching and those of the constraint and greedy results suggestingsmaller matching sizes of 10-40 edges

bull For the case of the small initial matching the result of the constraint matchingis now close to the result of the classical matching yet the greedy algorithm stillshows a relevantly big difference

30 Application

bull In this set of bipartite graphs we can witness that the result of the Constraintmatching shows a difference with the classical matching when the initial matchingis large The difference is smaller as the probability gets larger

bull For the case of the small initial matching the above phenomenom does not occuryet the greedy results deviates from that of the constraint matching

bull As per the pefrect matching compared to the classical matching a difference of5-10 edges is evident at almost all cases

Sorted Ratios

Sorted Ratios-Comments

bull Great max degree deviation

25 Bipartite 31

bull Regardless of the probability the ration of nodes and edges seems to have similarbehaviour when compared to the respective graphs of the same matching scale

bull Same gap between nodes ration and edges ration for all cases

Sorted |E||V |

Sorted |E||V | - Comments

bull In these set of figures we witness that the |E||V | acquires values relevant to those ofthe amadeus graphs The random graphs were constructed to depict this similarity

bull For smaller initial matching the ratios for G and G show the same upward trendand also they acquire closer values It represents the decrease of the averagenumber of forced edges in comparison to the larger matching cases

32 Application

Sorted ∆

Sorted ∆-Comments

bull ∆ acquires the same min and max values for each probability case (expected)

bull Gap in the case of large initial matching

26 Bipartite with degree seq

Graph characteristics

bull DEQBIPxy are randomly generated graphs based on three different types of degreedistribution of the Amadeus graphs

26 Bipartite with degree seq 33

bull There are 6 categories based on ini matching and degree distribution

bull x = L S L When the initial matching is large and S when it is small

bull y = 1 2 3 1 when degree distribution is based on file 2 when degree distributionis based on file and 3 when degree distribution is based on file

Computation time over

34 Application

Computation time overedges-Comments

bull Greedy algorithm takes minimum amount of time

bull The smaller the initial matching the more smaller the difference in comoutationtime of Constraint and classical algorithm

bull Due to preprocessing and the fact that G and G are the almost identical thetotal time needed to apply the constraint algorithm is in some cases bigger

Sorted matching size

26 Bipartite with degree seq 35

Sorted matching size-Comments

bull Classical matching is equal to perfect matching in every case

bull Constraint and greedy have identical behaviour

bull The larger the spectrum of the degree sequence the more efficient the matching

Sorted Ratios

36 Application

Sorted Ratios-Comments

bull With large initial matching most of the edges are considenred uselles or forced andare removed thus the ratio is close(if not equal to) zero

bull For small matching and large degree sequence sectrum hte max degree remainsthe same Only a few forced edges (and their nodes) are removed apparently nonodes with max degree

Sorted |E||V |

26 Bipartite with degree seq 37

Sorted |E||V | - Comments

bull In these set of figures we witness that the |E||V | acquires values relevant to those ofthe amadeus graphs The random graphs were constructed to depict this similarity

bull For smaller initial matching the ratios for G and G show the same upward trendand also they acquire closer values It repsresent the decrease of the averagenumber of forced edges in comparison to the larger matching cases

Sorted ∆

38 Application

Sorted ∆-Comments

bull Big difference in max degree in large initial matching

bull Almost identical behaviour in the case of small initial matching

Appendix A 39

Appendix A

BipartiteGraphGeneratorpy

from future import divisionimport networkx as nx

from networkxalgorithms import approximationimport collectionsimport randomimport mathfrom networkxalgorithms import bipartiteif name == main

for i in range(1481)waqs 481index=1n=randomrandint(100 1000)

n1=95 was 500me1=118

n2=251 was 500me2=903

n3=165 was 500me3=412

m=0m1=0p=randomrandom()p1=18250p2=25250p3=34250print ip=05t1=randomrandint(0 1)print im2=randomrandint(n2minus1 n2+1)G = nxGraph()ma = nxGraph()

aseq1=[1 2 3 4 5 3]

bseq1=[4 3 3 1 2 2 1]

aseq2=[16 14 14 14 12 11]bseq2=[0 0 0 0 0 0]

aseq3=[8 7 8 8 8 8]bseq3=[0 0 0 0 0 0]

40 Application

print Gnumber of edges()if ilt=160

G=bipartiteconfiguration model(aseq1 bseq1 create using=None seed=None)A=nxadjacency matrix(G)for ii in range(0n1+me1)

maadd node(ii)A=[Rtodense()tolist()[0] for R in A]

printnummanumber of nodes()rl=randomsample(range(0n1+me1) n1+me1)m=0done vertices = set()for p in rlprintin fordone verticesadd(p)

neighbors = []list()for iii in range(0n1+me1)

if A[p][iii]==1neighborsappend(iii)

randomshuffle(neighbors)continue loop = Truedegree = len(neighbors)

print degreej = 0p4=randomrandom()while continue loop and (jltdegree)print in loop

next = neighbors[j]if next not in done vertices and p not in done vertices

done verticesadd(p)done verticesadd(next)if p4gt=07print added edge

maadd edge(pnext)m=m+1

continue loop = Falsej += 1

print matching listOfedgeprint maedge

MA=nxadjacency matrix(ma)print MA

MA=[Rtodense()tolist()[0] for R in MA]print MA

B=[ join(map(strR)) for R in A]MB=[ join(map(strR)) for R in MA]

C=njoin(B)+nMC=njoin(MB)+n

print nprint mprint m1

filea=str(i)+txtwith open(fileaw) as f

Appendix A 41

fwrite(str(n1+me1))fwrite(n)fwrite(str(n1+me1))fwrite(n)fwrite(str(m))fwrite(n)fwrite(n)fwrite(C)fwrite(n)fwrite(MC)

elif igt160 and ilt321G=bipartiteconfiguration model(aseq2 bseq2 create using=None seed=None)A=nxadjacency matrix(G)for ii in range(0n2+me2)

maadd node(ii)A=[Rtodense()tolist()[0] for R in A]

printnummanumber of nodes()rl=randomsample(range(0n2+me2) n2+me2)m=0done vertices = set()for p in rlprintin fordone verticesadd(p)

neighbors = []list()for iii in range(0n2+me2)

if A[p][iii]==1neighborsappend(iii)

randomshuffle(neighbors)continue loop = Truedegree = len(neighbors)

print degreej = 0p4=randomrandom()while continue loop and (jltdegree)

print in loopnext = neighbors[j]if next not in done vertices and p not in done vertices

done verticesadd(p)done verticesadd(next)if p4gt=07

print added edgemaadd edge(pnext)m=m+1

continue loop = Falsej += 1

print matching listOfedgeprint maedge

MA=nxadjacency matrix(ma)print MA

MA=[Rtodense()tolist()[0] for R in MA]print MA

B=[ join(map(strR)) for R in A]MB=[ join(map(strR)) for R in MA]

42 Application

C=njoin(B)+nMC=njoin(MB)+n

print nprint mprint m1

filea=str(i)+txtwith open(fileaw) as f

fwrite(str(n2+me2))fwrite(n)fwrite(str(n2+me2))fwrite(n)fwrite(str(m))fwrite(n)fwrite(n)fwrite(C)fwrite(n)fwrite(MC)

elseG=bipartiteconfiguration model(aseq3 bseq3 create using=None seed=None)A=nxadjacency matrix(G)for ii in range(0n3+me3)

maadd node(ii)A=[Rtodense()tolist()[0] for R in A]

printnummanumber of nodes()rl=randomsample(range(0n3+me3) n3+me3)m=0done vertices = set()for p in rlprintin fordone verticesadd(p)

neighbors = []list()for iii in range(0n3+me3)

if A[p][iii]==1neighborsappend(iii)

randomshuffle(neighbors)continue loop = Truedegree = len(neighbors)

print degreej = 0p4=randomrandom()while continue loop and (jltdegree)

print in loopnext = neighbors[j]if next not in done vertices and p not in done vertices

done verticesadd(p)done verticesadd(next)if p4gt=07print added edge

maadd edge(pnext)m=m+1

continue loop = Falsej += 1

Appendix A 43

print matching listOfedgeprint maedge

MA=nxadjacency matrix(ma)print MA

MA=[Rtodense()tolist()[0] for R in MA]print MA

B=[ join(map(strR)) for R in A]MB=[ join(map(strR)) for R in MA]

C=njoin(B)+nMC=njoin(MB)+n

print nprint mprint m1

filea=str(i)+txtwith open(fileaw) as f

fwrite(str(n3+me3))fwrite(n)fwrite(str(n3+me3))fwrite(n)fwrite(str(m))fwrite(n)fwrite(n)fwrite(C)fwrite(n)fwrite(MC)

print nRandom graphs with random matching have been generated

44 Application

RandomGraphGeneratorpy

from future import divisionimport networkx as nxfrom networkxalgorithms import approximationimport collectionsimport randomimport mathif name == main

for i in range(1481)index=1n=randomrandint(100 1000)

n=1000m=0m1=0p=randomrandom()p1=mathlog(n2)np2=13p3=mathlog(n2)n+01p=05t1=randomrandint(0 1)print im2=randomrandint(n2minus1 n2+1)G = nxGraph()ma = nxGraph()print nme1=randomrandint(1 10)me2=randomrandint(2050)me3=randomrandint(50100)if ilt241

if ilt=80G=nxfast gnp random graph(n p1 seed=None directed=False)

elif igt80 and ilt161G=nxfast gnp random graph(n p2 seed=None directed=False)

elseG=nxfast gnp random graph(n p3 seed=None directed=False)

elseif ilt=320

G=nxbarabasi albert graph(n me1 seed=None)elif igt320 and ilt401

G=nxbarabasi albert graph(n me2 seed=None)else

G=nxbarabasi albert graph(n me3 seed=None)A=nxadjacency matrix(G)for ii in range(0n)

maadd node(ii)A=[Rtodense()tolist()[0] for R in A]

rl=randomsample(range(0n) n)m=0

Appendix A 45

done vertices = set()for p in rl

done verticesadd(p)neighbors = []list()for iii in range(0n)

if A[p][iii]==1neighborsappend(iii)

randomshuffle(neighbors)continue loop = Truedegree = len(neighbors)j = 0p2=randomrandom()while continue loop and (jltdegree)

next = neighbors[j]if next not in done vertices and p not in done vertices

done verticesadd(p)done verticesadd(next)if p2gt=00 Larger probability for smaller initial matching

maadd edge(pnext)m=m+1

continue loop = Falsej += 1

print matching listOfedgeprint maedgeMA=nxadjacency matrix(ma)MA=[Rtodense()tolist()[0] for R in MA]print MAB=[ join(map(strR)) for R in A]MB=[ join(map(strR)) for R in MA]

C=njoin(B)+nMC=njoin(MB)+nprint MCprint nprint mprint m1filea=str(i)+txtwith open(fileaw) as f

fwrite(str(n))fwrite(n)fwrite(str(n))fwrite(n)fwrite(str(m))fwrite(n)fwrite(n)fwrite(C)fwrite(n)fwrite(MC)

print nRandom graphs with random matching have been generated

46 Application

kequals3MaximumMatchingpy

from future import divisionimport networkx as nxfrom networkxalgorithms import bipartiteimport matplotlibpyplot as pltimport collectionsimport timeitimport xlwtimport xlrdimport mathimport sys

Case for General Graphsdef forced edges(Gadj dict2matching dict1num nodesforced)

flagg=0for n in range(0num nodes)

for k in adj dict2[n]if ([k]==matching dict1[n])

count=0for l in range(0num nodes)

count=count+adj dict2[l]count(k)if (len(adj dict2[n])==1) or (count==1)

forcedadd edge(nk)Gremove edge(nk)Gremove node(n)Gremove node(k)printforced edgenktemp=kflagg=1for m in range (len(adj dict2[n])minus1minus1minus1)

adj dict2[adj dict2[n][m]]remove(n)adj dict2[n]remove(adj dict2[n][m])

if adj dict2[temp]for l in range(len(adj dict2[temp])minus1minus1minus1)

if (adj dict2[temp][l]=n)adj dict2[adj dict2[temp][l]]remove(temp)adj dict2[temp]remove(adj dict2[temp][l])

break

def useless edges(num nodesadj dict1matching dict1uselessadj dict2G)for n in range(0num nodes)

for k in adj dict1[n]if ([k]=matching dict1[n]) and matching dict1[n] and matching dict1[k]

uselessadd edge(nk)Gremove edge(n k)

Appendix A 47

tempa=kadj dict2[n]remove(k)adj dict2[tempa]remove(n)adj dict1[tempa]remove(n)

return G

def Greedy(num nodesadj dict3matching dict2)

for n in range(0num nodes)if matching dict2[n]

flag2=minus1flag3=minus1for v in adj dict3[n]

if not matching dict2[v]flag2=vbreak

for p in adj dict3[matching dict2[n][0]]if not matching dict2[p]

flag3=pbreak

if (flag2=minus1) and (flag3=minus1) and (flag2=flag3)tempr=matching dict2[n][0]matching dict2[n]=[flag2]matching dict2[flag2]=[n]matching dict2[tempr]=[flag3]matching dict2[flag3]=[tempr]

elsefor k in adj dict3[n]

if not matching dict2[k]matching dict2[n]=[k]matching dict2[k]=[n]break

yo1=0for i in range(0num nodes)

if matching dict2[i] and [i]==matching dict2[matching dict2[i][0]]yo1=yo1+1

greedy size=yo12return greedy size

def General()

INPUTSwb = xlwtWorkbook()ws = wbadd sheet(Results Random)book=xlrdopen workbook(filenames randomxls)

48 Application

style0 = xlwteasyxf(fontbold on)style1 = xlwteasyxf(num format str=0000)INPUTSwswrite(0 0File style0)wswrite(0 1 Nodesstyle0)wswrite(0 2 Initial matchingstyle0)wswrite(0 3 NodesGstyle0)wswrite(0 4 EdgesGstyle0)wswrite(0 5 MaxDegreeGstyle0)wswrite(0 6 NodesG hatstyle0)wswrite(0 7 EdgesG Hatstyle0)wswrite(0 8 Useless edgesstyle0)wswrite(0 9 Forced edgesstyle0)wswrite(0 10 MaxDegreeG Hatstyle0)wswrite(0 11 Classical matchingstyle0)wswrite(0 12 Final matchingstyle0)wswrite(0 13 Greedy matchingstyle0)wswrite(0 14 Time classicalstyle0)wswrite(0 15 Time algorithmstyle0)wswrite(0 16 Time greedystyle0)wswrite(0 17 Perfect matching ratiostyle0)wswrite(0 18 Nodes ratiostyle0)wswrite(0 19 Edges ratiostyle0)wswrite(0 20 Matching ratiostyle0)

print nWelcomeThis is an implementation for general random graphs It uses Edmonds algorithm to compute maximum matching on G Hatn

for index in range (1481)was 481

if (index==482)f=open(Algotel generaltxtr)readlines()

elsefilea=str(booksheet by index(0)cell(index0))s=fileareplace(textu)replace()f=open(sr)readlines()Truewswrite(index 0 s)

print index

num nodes=int([xstrip()split() for x in f][0][0])

num matching=int([xstrip()split() for x in f][2][0])

adj temp = [xstrip()split() for x in f][44+num nodes]adj=[map(intR) for R in adj temp]

matching temp=[xstrip()split() for x in f][4+num nodes+14+2num nodes+1]matching1=[map(intR) for R in matching temp]

adj dict1=i[ii for iix in enumerate(L) if x] for iL in enumerate(adj)adj dict2=i[ii for iix in enumerate(L) if x] for iL in enumerate(adj)

Appendix A 49

adj dict3=i[ii for iix in enumerate(L) if x] for iL in enumerate(adj)

matching dict1=i[ii for iix in enumerate(L) if x] for iL in enumerate(matching1)matching dict2=i[ii for iix in enumerate(L) if x] for iL in enumerate(matching1)print adj dict2print matching dict2wswrite(index 1 num nodes)wswrite(index 2 num matching)

G = nxGraph()

useless= nxGraph()forced = nxGraph()

Fill Graphfor n in range(0num nodes)

for k in adj dict1[n]Gadd edge(nk)

Gt=Gnumber of edges()wswrite(index 3 Gnumber of nodes())wswrite(index 4 Gnumber of edges())wswrite(index 5 max(Gdegree()values()))

Compute Edmonds classical matching on G for comparison

startB = timeitdefault timer()Classical Matching=nxmax weight matching(G maxcardinality=False)stopB = timeitdefault timer()

Compute Gˆ nad MˆstartC = timeitdefault timer()useless edges(num nodesadj dict1matching dict1uselessadj dict2G)forced edges(Gadj dict2matching dict1num nodesforced)Final Matching=nxmax weight matching(G maxcardinality=False)stopC = timeitdefault timer()

GreedystartG = timeitdefault timer()greedy size=Greedy(num nodesadj dict3matching dict2)stopG = timeitdefault timer()

wswrite(index 6 Gnumber of nodes())wswrite(index 7 Gnumber of edges())wswrite(index 8 uselessnumber of edges())wswrite(index 9 forcednumber of edges())if Gdegree()values()

wswrite(index 10 max(Gdegree()values()))else

50 Application

wswrite(index 10 0)wswrite(index 11 len(Classical Matching)2)wswrite(index 12 len(Final Matching)2+forcednumber of edges())wswrite(index 13 greedy size)wswrite(index 14 stopB minus startBstyle1)wswrite(index 15 stopC minus startCstyle1)wswrite(index 16 stopG minus startGstyle1)wswrite(index 17 (len(Final Matching)2+forcednumber of edges())(num nodes2)style1)wswrite(index 18 Gnumber of nodes()Gtstyle1)wswrite(index 19 Gnumber of edges()Gtstyle1)wswrite(index 20 (len(Final Matching)2+forcednumber of edges())(len(Classical Matching)2)style1)

wbsave(AA Results Random Reyni Large Bipartitexls)

Main function Here we must choose the input form of the dataif name == main

startA = timeitdefault timer()General()stopA = timeitdefault timer()

print nThis program has terminatednnRunning time for 480 files stopAminusstartAprint nnPlease open AA Results Random Reyni Largexls file to see the Results

Appendix A 51

Plotmat

clear allclose allload(RN1Lmat)load(RN1Smat)load(RN2Lmat)load(RN2Smat)load(RN3Lmat)load(RN3Smat)

Plotsh(1)=figure(NameHistogram of Matching size difference between Constraint Algorithm and Greedy AlgorithmNumberTitleoff)

RN1L Greedydiff=RN1L Final matchingminusRN1L Greedy matchingRN2L Greedydiff=RN2L Final matchingminusRN2L Greedy matchingRN3L Greedydiff=RN3L Final matchingminusRN3L Greedy matchingRN1S Greedydiff=RN1S Final matchingminusRN1S Greedy matchingRN2S Greedydiff=RN2S Final matchingminusRN2S Greedy matchingRN3S Greedydiff=RN3S Final matchingminusRN3S Greedy matching

RN1L Finaldiff=RN1L Classical matchingminusRN1L Final matchingRN2L Finaldiff=RN2L Classical matchingminusRN2L Final matchingRN3L Finaldiff=RN3L Classical matchingminusRN3L Final matchingRN1S Finaldiff=RN1S Classical matchingminusRN1S Final matchingRN2S Finaldiff=RN2S Classical matchingminusRN2S Final matchingRN3S Finaldiff=RN3S Classical matchingminusRN3S Final matching

RN1L Classicaldiff=(RN1L Nodes2)minusRN1L Classical matchingRN2L Classicaldiff=(RN2L Nodes2)minusRN2L Classical matchingRN3L Classicaldiff=(RN3L Nodes2)minusRN3L Classical matchingRN1S Classicaldiff=(RN1S Nodes2)minusRN1S Classical matchingRN2S Classicaldiff=(RN2S Nodes2)minusRN2S Classical matchingRN3S Classicaldiff=(RN3S Nodes2)minusRN3S Classical matching

subplot(231)hold onhistf(RN1L Greedydiff0110facecolorbfacealpha9edgealpha1)histf(RN1L Finaldiff0110facecolorrfacealpha5edgealpha1)histf(RN1L Classicaldiff0110facecolorgfacealpha5edgealpha1)legalpha(ConminusGreClasminusConPerfminusClasslocationnortheast)legend boxoffaxis tightxlabel(edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN1L)grid on

subplot(232)hold onhistf(RN2L Greedydiff0110facecolorbfacealpha9edgealpha1)

52 Application

histf(RN2L Finaldiff0110facecolorrfacealpha5edgealpha1)histf(RN2L Classicaldiff0110facecolorgfacealpha5edgealpha1)legalpha(ConminusGreClasminusConPerfminusClasslocationnortheast)legend boxoffaxis tightxlabel(edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN2L)grid on

subplot(233)hold onhistf(RN3L Greedydiff0110facecolorbfacealpha5edgealpha1)histf(RN3L Finaldiff0110facecolorrfacealpha5edgealpha1)histf(RN3L Classicaldiff0110facecolorgfacealpha5edgealpha1)legalpha(ConminusGreClasminusConPerfminusClasslocationnortheast)legend boxoffaxis tightxlabel(edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN3L)grid on

subplot(234)hold onhistf(RN1S Greedydiff0110facecolorbfacealpha5edgealpha1)histf(RN1S Finaldiff0110facecolorrfacealpha5edgealpha1)histf(RN1S Classicaldiff0110facecolorgfacealpha5edgealpha1)legalpha(ConminusGreClasminusConPerfminusClasslocationnortheast)legend boxoffaxis tightxlabel(edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(R1NS)grid on

subplot(235)hold onhistf(RN2S Greedydiff0110facecolorbfacealpha5edgealpha1)histf(RN2S Finaldiff0110facecolorrfacealpha5edgealpha1)histf(RN2S Classicaldiff0110facecolorgfacealpha5edgealpha1)legalpha(ConminusGreClasminusConPerfminusClasslocationnortheast)legend boxoffaxis tightxlabel(edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN2S)grid on

subplot(236)hold onhistf(RN3S Greedydiff0110facecolorbfacealpha5edgealpha1)histf(RN3S Finaldiff0110facecolorrfacealpha5edgealpha1)histf(RN3S Classicaldiff0110facecolorgfacealpha5edgealpha1)

Appendix A 53

legalpha(ConminusGreClasminusConPerfminusClasslocationnortheast)legend boxoffaxis tightgrid ontitle(RN3S)xlabel(edges) xminusaxis labelylabel(instances) yminusaxis labelset(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN1png minusr300)h(2)=figure(NameHistogram of Max Degree of G AND G HatNumberTitleoff)RN1L x=RN1L MaxDegreeGminusRN1L MaxDegreeG HatRN2L x=RN2L MaxDegreeGminusRN2L MaxDegreeG HatRN3L x=RN3L MaxDegreeGminusRN3L MaxDegreeG HatRN1S x=RN1S MaxDegreeGminusRN1S MaxDegreeG HatRN2S x=RN2S MaxDegreeGminusRN2S MaxDegreeG HatRN3S x=RN3S MaxDegreeGminusRN3S MaxDegreeG Hatsubplot(231)hold onhistf(RN1L MaxDegreeG0150facecolorbfacealpha5edgealpha1)histf(RN1L MaxDegreeG Hat0150facecolorrfacealpha5edgealpha1)histf(RN1L x0150facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightxlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN1L)grid on

subplot(232)hold onhistf(RN2L MaxDegreeG010500facecolorbfacealpha5edgealpha1)histf(RN2L MaxDegreeG Hat010500facecolorrfacealpha5edgealpha1)histf(RN2L x010500facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightxlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN2L)grid on

subplot(233)hold onhistf(RN3L MaxDegreeG010300facecolorbfacealpha5edgealpha1)histf(RN3L MaxDegreeG Hat010300facecolorrfacealpha5edgealpha1)histf(RN3L x010300facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightxlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN3L)

54 Application

grid on

subplot(234)hold onhistf(RN1S MaxDegreeG0150facecolorbfacealpha5edgealpha1)histf(RN1S MaxDegreeG Hat0150facecolorrfacealpha5edgealpha1)histf(RN1S x0150facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightxlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(R1NS)grid on

subplot(235)hold onhistf(RN2S MaxDegreeG010500facecolorbfacealpha5edgealpha1)histf(RN2S MaxDegreeG Hat010500facecolorrfacealpha5edgealpha1)histf(RN2S x010500facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightxlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN2S)grid on

subplot(236)hold onhistf(RN3S MaxDegreeG05300facecolorbfacealpha5edgealpha1)histf(RN3S MaxDegreeG Hat05300facecolorrfacealpha5edgealpha1)histf(RN3S x05300facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightgrid ontitle(RN3S)xlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labelset(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN2png minusr300)

h(3)=figure(NameComputation time over edgesNumberTitleoff)

subplot(231)hold onstem(RN1L EdgesGRN1L Time classicalg)stem(RN1L EdgesGRN1L Time algorithmro)stem(RN1L EdgesGRN1L Time greedybx)grid on

Appendix A 55

title(RN1L)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)

subplot(232)hold onstem(RN2L EdgesGRN2L Time classicalg)stem(RN2L EdgesGRN2L Time algorithmro)stem(RN2L EdgesGRN2L Time greedybx)grid ontitle(RN2L)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)

subplot(233)hold onstem(RN3L EdgesGRN3L Time classicalg)stem(RN3L EdgesGRN3L Time algorithmro)stem(RN3L EdgesGRN3L Time greedybx)grid ontitle(RN3L)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)

subplot(234)hold onstem(RN1S EdgesGRN1S Time classicalg)stem(RN1S EdgesGRN1S Time algorithmro)stem(RN1S EdgesGRN1S Time greedybx)grid ontitle(RN1S)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)

subplot(235)hold onstem(RN2S EdgesGRN2S Time classicalg)stem(RN2S EdgesGRN2S Time algorithmro)stem(RN2S EdgesGRN2S Time greedybx)grid ontitle(RN2S)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)

subplot(236)hold onstem(RN3S EdgesGRN3S Time classicalg)stem(RN3S EdgesGRN3S Time algorithmro)stem(RN3S EdgesGRN3S Time greedybx)

56 Application

grid ontitle(RN3S)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)set(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN3png minusr300)

h(4)=figure(NameSorted matching sizeNumberTitleoff)RN1L Sorted matching temp(1)=RN1L Classical matchingRN1L Sorted matching temp(2)=RN1L Final matchingRN1L Sorted matching temp(3)=RN1L Greedy matchingRN1L Sorted matching temp(4)=RN1L Initial matchingRN1L Sorted matching=sortrows(RN1L Sorted matching temp)

RN2L Sorted matching temp(1)=RN2L Classical matchingRN2L Sorted matching temp(2)=RN2L Final matchingRN2L Sorted matching temp(3)=RN2L Greedy matchingRN2L Sorted matching temp(4)=RN2L Initial matchingRN2L Sorted matching=sortrows(RN2L Sorted matching temp)

RN3L Sorted matching temp(1)=RN3L Classical matchingRN3L Sorted matching temp(2)=RN3L Final matchingRN3L Sorted matching temp(3)=RN3L Greedy matchingRN3L Sorted matching temp(4)=RN3L Initial matchingRN3L Sorted matching=sortrows(RN3L Sorted matching temp)

RN1S Sorted matching temp(1)=RN1S Classical matchingRN1S Sorted matching temp(2)=RN1S Final matchingRN1S Sorted matching temp(3)=RN1S Greedy matchingRN1S Sorted matching temp(4)=RN1S Initial matchingRN1S Sorted matching=sortrows(RN1S Sorted matching temp)

RN2S Sorted matching temp(1)=RN2S Classical matchingRN2S Sorted matching temp(2)=RN2S Final matchingRN2S Sorted matching temp(3)=RN2S Greedy matchingRN2S Sorted matching temp(4)=RN2S Initial matchingRN2S Sorted matching=sortrows(RN2S Sorted matching temp)

RN3S Sorted matching temp(1)=RN3S Classical matchingRN3S Sorted matching temp(2)=RN3S Final matchingRN3S Sorted matching temp(3)=RN3S Greedy matchingRN3S Sorted matching temp(4)=RN3S Initial matchingRN3S Sorted matching=sortrows(RN3S Sorted matching temp)

subplot(231)hold onplot(RN1L Sorted matching(1)b)plot(RN1L Sorted matching(2)g)plot(RN1L Sorted matching(3)r)plot(RN1L Sorted matching(4)m)

Appendix A 57

grid ontitle(RN1L)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)

subplot(232)hold onplot(RN2L Sorted matching(1)b)plot(RN2L Sorted matching(2)g)plot(RN2L Sorted matching(3)r)plot(RN2L Sorted matching(4)m)grid ontitle(RN2L)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)

subplot(233)hold onplot(RN3L Sorted matching(1)b)plot(RN3L Sorted matching(2)g)plot(RN3L Sorted matching(3)r)plot(RN3L Sorted matching(4)m)grid ontitle(RN3L)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)

subplot(234)hold onplot(RN1S Sorted matching(1)b)plot(RN1S Sorted matching(2)g)plot(RN1S Sorted matching(3)r)plot(RN1S Sorted matching(4)m)grid ontitle(RN1S)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)

subplot(235)hold onplot(RN2S Sorted matching(1)b)plot(RN2S Sorted matching(2)g)plot(RN2S Sorted matching(3)r)plot(RN2S Sorted matching(4)m)grid ontitle(RN2S)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)

58 Application

subplot(236)hold onplot(RN3S Sorted matching(1)b)plot(RN3S Sorted matching(2)g)plot(RN3S Sorted matching(3)r)plot(RN3S Sorted matching(4)m)grid ontitle(RN3S)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)set(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN4png minusr300)h(5)=figure(NameSorted RatiosNumberTitleoff)RN1L ratio1=RN1L NodesG hatRN1L NodesGRN2L ratio1=RN2L NodesG hatRN2L NodesGRN3L ratio1=RN3L NodesG hatRN3L NodesGRN1S ratio1=RN1S NodesG hatRN1S NodesGRN2S ratio1=RN2S NodesG hatRN2S NodesGRN3S ratio1=RN3S NodesG hatRN3S NodesG

RN1L ratio2=RN1L EdgesG HatRN1L EdgesGRN2L ratio2=RN2L EdgesG HatRN2L EdgesGRN3L ratio2=RN3L EdgesG HatRN3L EdgesGRN1S ratio2=RN1S EdgesG HatRN1S EdgesGRN2S ratio2=RN2S EdgesG HatRN2S EdgesGRN3S ratio2=RN3S EdgesG HatRN3S EdgesG

RN1L ratio3=RN1L MaxDegreeG HatRN1L MaxDegreeGRN2L ratio3=RN2L MaxDegreeG HatRN2L MaxDegreeGRN3L ratio3=RN3L MaxDegreeG HatRN3L MaxDegreeGRN1S ratio3=RN1S MaxDegreeG HatRN1S MaxDegreeGRN2S ratio3=RN2S MaxDegreeG HatRN2S MaxDegreeGRN3S ratio3=RN3S MaxDegreeG HatRN3S MaxDegreeG

RN1L ratio(1)=RN1L ratio1RN1L ratio(2)=RN1L ratio2RN1L ratio(3)=RN1L ratio3

RN2L ratio(1)=RN2L ratio1RN2L ratio(2)=RN2L ratio2RN2L ratio(3)=RN2L ratio3

RN3L ratio(1)=RN3L ratio1RN3L ratio(2)=RN3L ratio2RN3L ratio(3)=RN3L ratio3

RN1S ratio(1)=RN1S ratio1RN1S ratio(2)=RN1S ratio2RN1S ratio(3)=RN1S ratio3

RN2S ratio(1)=RN2S ratio1

Appendix A 59

RN2S ratio(2)=RN2S ratio2RN2S ratio(3)=RN2S ratio3

RN3S ratio(1)=RN3S ratio1RN3S ratio(2)=RN3S ratio2RN3S ratio(3)=RN3S ratio3

RN1L ratio sorted=sortrows(RN1L ratio)RN2L ratio sorted=sortrows(RN2L ratio)RN3L ratio sorted=sortrows(RN3L ratio)RN1S ratio sorted=sortrows(RN1S ratio)RN2S ratio sorted=sortrows(RN2S ratio)RN3S ratio sorted=sortrows(RN3S ratio)

subplot(231)hold onplot(RN1L ratio sorted(1)b)plot(RN1L ratio sorted(2)g)plot(RN1L ratio sorted(3)r)grid ontitle(RN1L)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)

subplot(232)hold onplot(RN2L ratio sorted(1)b)plot(RN2L ratio sorted(2)g)plot(RN2L ratio sorted(3)r)grid ontitle(RN2L)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)

subplot(233)hold onplot(RN3L ratio sorted(1)b)plot(RN3L ratio sorted(2)g)plot(RN3L ratio sorted(3)r)grid ontitle(RN3L)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)

subplot(234)hold onplot(RN1S ratio sorted(1)b)plot(RN1S ratio sorted(2)g)plot(RN1S ratio sorted(3)r)grid on

60 Application

title(RN1S)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)

subplot(235)hold onplot(RN2S ratio sorted(1)b)plot(RN2S ratio sorted(2)g)plot(RN2S ratio sorted(3)r)grid ontitle(RN2S)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)

subplot(236)hold onplot(RN3S ratio sorted(1)b)plot(RN3S ratio sorted(2)g)plot(RN3S ratio sorted(3)r)grid ontitle(RN3S)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)set(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN5png minusr300)

h(6)=figure(NameSorted edges over nodesNumberTitleoff)

RN1L DegreeG1=(RN1L EdgesG)(RN1L NodesG)RN1L DegreeG Hat1=(RN1L EdgesG Hat)(RN1L NodesG hat)

RN1L Degree temp1(1)=RN1L DegreeG1RN1L Degree temp1(2)=RN1L DegreeG Hat1RN1L Degree sorted1=sortrows(RN1L Degree temp1)subplot(231)hold on

plot(RN1L Degree sorted1(1)b)plot(RN1L Degree sorted1(2)g)grid ontitle(RN1L)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)

RN2L DegreeG1=(RN2L EdgesG)(RN2L NodesG)RN2L DegreeG Hat1=(RN2L EdgesG Hat)(RN2L NodesG hat)

RN2L Degree temp1(1)=RN2L DegreeG1

Appendix A 61

RN2L Degree temp1(2)=RN2L DegreeG Hat1RN2L Degree sorted1=sortrows(RN2L Degree temp1)

subplot(232)hold onplot(RN2L Degree sorted1(1)b)plot(RN2L Degree sorted1(2)g)grid ontitle(RN2L)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)

RN3L DegreeG1=(RN3L EdgesG)(RN3L NodesG)RN3L DegreeG Hat1=(RN3L EdgesG Hat)(RN3L NodesG hat)

RN3L Degree temp1(1)=RN3L DegreeG1RN3L Degree temp1(2)=RN3L DegreeG Hat1RN3L Degree sorted1=sortrows(RN3L Degree temp1)

subplot(233)hold onplot(RN3L Degree sorted1(1)b)plot(RN3L Degree sorted1(2)g)grid ontitle(RN3L)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)

RN1S DegreeG1=(RN1S EdgesG)(RN1S NodesG)RN1S DegreeG Hat1=(RN1S EdgesG Hat)(RN1S NodesG hat)

RN1S Degree temp1(1)=RN1S DegreeG1RN1S Degree temp1(2)=RN1S DegreeG Hat1RN1S Degree sorted1=sortrows(RN1S Degree temp1)

subplot(234)hold onplot(RN1S Degree sorted1(1)b)plot(RN1S Degree sorted1(2)g)grid ontitle(RN1S)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)

RN2S DegreeG1=(RN2S EdgesG)(RN2S NodesG)RN2S DegreeG Hat1=(RN2S EdgesG Hat)(RN2S NodesG hat)

RN2S Degree temp1(1)=RN2S DegreeG1

62 Application

RN2S Degree temp1(2)=RN2S DegreeG Hat1RN2S Degree sorted1=sortrows(RN2S Degree temp1)

subplot(235)hold onplot(RN2S Degree sorted1(1)b)plot(RN2S Degree sorted1(2)g)grid ontitle(RN2S)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)

RN3S DegreeG1=(RN3S EdgesG)(RN3S NodesG)RN3S DegreeG Hat1=(RN3S EdgesG Hat)(RN3S NodesG hat)

RN3S Degree temp1(1)=RN3S DegreeG1RN3S Degree temp1(2)=RN3S DegreeG Hat1RN3S Degree sorted1=sortrows(RN3S Degree temp1)

subplot(236)hold onplot(RN3S Degree sorted1(1)b)plot(RN3S Degree sorted1(2)g)grid ontitle(RN3S)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)set(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN6png minusr300)h(7)=figure(NameSorted mATCHED DEGREENumberTitleoff)RN1L ratioMax(1)=RN1L MaxDegreeGRN1L ratioMax(2)=RN1L MaxDegreeG Hat

RN1L ratio sortedMax=sortrows(RN1L ratioMax)subplot(231)hold onplot(RN1L ratio sortedMax(1)b)plot(RN1L ratio sortedMax(2)g)grid ontitle(RN1L)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)

RN2L ratioMax(1)=RN2L MaxDegreeGRN2L ratioMax(2)=RN2L MaxDegreeG Hat

RN2L ratio sortedMax=sortrows(RN2L ratioMax)subplot(232)

Appendix A 63

hold onplot(RN2L ratio sortedMax(1)b)plot(RN2L ratio sortedMax(2)g)grid ontitle(RN2L)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)

RN3L ratioMax(1)=RN3L MaxDegreeGRN3L ratioMax(2)=RN3L MaxDegreeG Hat

RN3L ratio sortedMax=sortrows(RN3L ratioMax)subplot(233)hold onplot(RN3L ratio sortedMax(1)b)plot(RN3L ratio sortedMax(2)g)grid ontitle(RN3L)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)

RN1S ratioMax(1)=RN1S MaxDegreeGRN1S ratioMax(2)=RN1S MaxDegreeG Hat

RN1S ratio sortedMax=sortrows(RN1S ratioMax)subplot(234)hold onplot(RN1S ratio sortedMax(1)b)plot(RN1S ratio sortedMax(2)g)grid ontitle(RN1S)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)

RN2S ratioMax(1)=RN2S MaxDegreeGRN2S ratioMax(2)=RN2S MaxDegreeG Hat

RN2S ratio sortedMax=sortrows(RN2S ratioMax)

subplot(235)hold onplot(RN2S ratio sortedMax(1)b)plot(RN2S ratio sortedMax(2)g)grid ontitle(RN2S)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)

RN3S ratioMax(1)=RN3S MaxDegreeGRN3S ratioMax(2)=RN3S MaxDegreeG Hat

64 Application

RN3S ratio sortedMax=sortrows(RN3S ratioMax)subplot(236)hold onplot(RN3S ratio sortedMax(1)b)plot(RN3S ratio sortedMax(2)g)grid ontitle(RN1L)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)set(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN7png minusr300)

tilefigs()(h)

Bibliography

[1] C Berge ldquoTWO THEOREMS IN GRAPH THEORYrdquo Proceedings of the NationalAcademy of Sciences of the United States of America vol 43 no 9 pp 842ndash844Sep 1957

[2] L Bui S Sanghavi and R Srikant ldquoDistributed link scheduling with constantoverheadrdquo IEEEACM Trans Netw vol 17 no 5 pp 1467ndash1480 2009

[3] R Duan and S Pettie ldquoLinear-time approximation for maximum weight matchingrdquoJ ACM vol 61 no 1 2014

[4] J Edmonds ldquoPaths trees and flowersrdquo Canadian Journal of Mathematics vol 17pp 449ndash467 1965

[5] J E Hopcroft and R M Karp ldquoAn n52 algorithm for maximum matchings inbipartite graphsrdquo SIAM J Comput vol 2 no 4 pp 225ndash231 1973

[6] S Micali and V V Vazirani ldquoAn O(radic|V ||E|) algorithm for finding maximum

matching in general graphsrdquo in 21st Symp on Foundations of Comp Sc (FOCS)IEEE 1980 pp 17ndash27

[7] N Nisse A Salch and V Weber ldquoRecovery of disrupted airline operationsrdquo 2015httphalinriafrSomething

[8] X Wu and R Srikant ldquoRegulated maximal matching A distributed schedulingalgorithm for multi-hop wireless networks with nodeexclusive spectrum sharingrdquo inIEEE Conf on Decision and Control 2005

65

  • Contents
  • Introduction
  • Algorithms
    • Maximum matching
    • k-maximum matching
      • k-matching for Airport Slot assignment
      • The case where k=3
      • The case of Paths
      • The case of the Spider
          • Application
            • Description
            • Reyni Erdos
            • Barabaacutesi Albert
            • Amadeus Graphs
            • Bipartite
            • Bipartite with degree seq
            • Appendix A
              • BipartiteGraphGeneratorpy
              • RandomGraphGeneratorpy
              • kequals3MaximumMatchingpy
              • Plotmat
                  • Bibliography
Page 5: Theodoros Alexandros KARAGKIOULES -  · Introduction This work is the result of a 6 months internship, under the supervision of research O cer Nicolas NISSE. The original scope of

6 Algorithms

of length le k that allow to obtain from M a matching of size microk(GM)

In the cases k isin 1 3 it has been proven that the computational complexity of the k-Matching Problem is equivalent to the one of the classical maximum matching problem(without any constraint on the length of paths) Hence for k isin 1 3 it can be solvedin polynomial time

121 k-matching for Airport Slot assignment

The k-maximum matching problem has been found to have an application in the aviationindustry When an aircraft is approaching an airport it is assigned by Air Traffic Controla landing time (called slot) If there is a delay for any reason (weather conditions latearrival priority) it looses its slot and a new slot needs to by reassigned to it Howeverslots for landing are a scarce resource of the airports and to avoid conflicts and forsafety reasons Airline Operation Controllers have to regularly modify the assignment ofthe slots of the aircraft

This modification of the slot-assignment uses only two kinds of operations either assignaircraft A to a free slot or give A the slot of B and assign B to a free slot The problemis then the following

Let k ge 1 be an odd integer and let G be a graph and M be a matching of GWhat is the maximum size of a matching that can be obtained from M by using onlyaugmenting paths of length at most k

Let G = (X cup YE) be a bipartite graph X represents the set of aircraft and Yrepresents the set of available slots There is an edge between a isin X and s isin Y if theslot s is compatible with the schedules of aircraft A Let M be a matching of G thatcorresponds to a pre-established valid assignment of some slots to some aircraft Theproblem of reassignment of slots is equivalent to computing a maximum matching thatcan be obtained from M by augmenting only paths of length at most 3

122 The case where k=3

Let G be a graph and M sube E(G) be a matching of G An edge e isin E(G) M is saiduseless if e is incident to two edges of M ie if each endpoint of e is incident to oneedge of M An edge e isinM is said forced if at least one of its endpoints has degree onein G

Finally let G be the graph obtained from G and the matching M by first removingall useless edges (but keeping their endpoints) and then by removing the forced edgesand their endpoints Let M be the matching resulting from M in G ie M equals Mminus the forced edges Note that M has no useless edges nor forced edges Abusingthe notations we will identify the paths in G with some paths in G

12 k-maximum matching 7

This algorithm has been used to implement the k-maximum matching programme thatcomputes the data provided by Amadeus and also the randomly generated graphs of thefollowing chapter

123 The case of Paths

Let Q = (v1 middot middot middot vi) be the maximum alternating path containing v1 If Q is notaugmenting or if Q has length more than k (ie i gt k) the algorithm is appliedrecursively on P (v1 middot middot middot viminus1) Otherwise Q is augmented (it is added to the desiredsequence of paths) and the algorithm is applied recursively on P Q

Algorithm 1 k-matching(PnM)

Require A path Pn = (v1 middot middot middot vn) a matching M sube E(P ) and an odd integer k ge 1Ensure A sequence (Q1 middot middot middot Qr) of augmenting paths with r = microk(PM)minus |M |1 if n = 1 then return empty2 else3 Let 1 lt i le n be the smallest integer (at least 2) such that vi is exposed4 if v1 is not exposed OR i gt k then5 Let P prime = (vi middot middot middot vn) and M prime = M cap E(P prime) return k-matching(P primeM prime)6 else7 Let P prime = (vi+1 middot middot middot vn) and M prime = M cap E(P prime) return (v1 middot middot middot vi)cup

k-matching(P primeM prime)8 end if9 end if

124 The case of the Spider

Theorem 11 Let S be a spider andM its initial matching and (P1 Pr) a sequenceof augmenting paths of length le k such that microk(SM) = |M |+ r then exist (Q1 Qr)a sequence of augmenting paths of length le k such that at most one such path containsthe center C

Proof Let S be a spider and lets assume that the optimal sequence of augmentingpaths SP is known along with the set of branches Br (those paths of S from a leaf tothe nn of CAssume for contradiction that exist ge 2 augmenting paths that contain the center Cand let Pi and Pj be the first such paths Let Pi = (umi

C uni) and Pj =

(umj C unj

) and let Q = (umi C unj

) be the (augmenting) pathcontaining partially Pi the center C and partially Pj Since [C uni

] sub [C unj] in order

for Pj to be an augmenting path then exist H = (Pj Pi) Q Letrsquos also assume thatthere is a set of paths A = A1 At isin SP between Pi and Pj and A sube Brsuch that forallk isin 1 2 t Ak Pi = empty or Ak Pj = empty Also there is a set of pathsB = B1 Bf isin SP between Pi and Pj and B sube Br such that foralln isin 1 2 fBn is non intersecting with any paths in AQPi Pj and H Then the optimal sequenceof augmenting paths can be the following

8 Algorithms

P1 P2 P3 A1 At QB1 Bf H Pr where augmenting only path Q oncecan lead to the equivalently optimal solution

Algorithm 2 Spider algorithm(SM)

1 M prime = M2 Let there be a set of leaves λ1 λr3 xk is the nn of C in the path C rarr λk4 for i isin 1 r do5 for j 6= i do M primeprime=Path Algorithm(λi rarr λjM)6 for k isin i j do M primeprime=M primeprimecupPath Algorithm(λk rarr xkM)7 end for8 end for9 if M primeprime gt M prime then10 M prime = M primeprime

11 end if12 end for13 return M prime

Proof Let there be an optimal solution that is obtained by the paths in the sequenceQprime = (P prime1 P

primer) for the spider

Let there also be a set of paths from leaf to leaf PLL = Pll1 P lln a set ofbranches BR = Br1 Brm and a sequence of augmenting paths Q = (P1 Pr)such that for j isin 1 r Pj isin PLL and forall i 6= j isin 1 r Pi isin BR

Applying the path algorithm for Pj and then for the r minus 1 paths of Q and due toTheorem 21 it is ensured that the matching produced will lead to a feasible solutionsince C is never exposed

Due to the iterative nature of the algorithm it can be checked that all possible com-binations of Pj and Pi that construct Q are considered and that one of the solutionscomputed as above will be the initial optimal solution Qprime

Thus by induction Spider Algorithm will always produce an optimal matching on aSpider

Chapter 2

Application

21 Description

This chapter aims at providing the picture of analysis on the data provided by Amadeusthe bipartite graphs and the random graphs generated

The random graphs have been generated as purely random graphs based on the ReyniErdos and the Barabasi Albert with different values of connectivity probability or con-nectivity

The bipartite graphs were generated on the density of the Amadeus graphs to simu-late better the results Additionally an extra set of test have been made on bipartitegraphs that simulate the degree distribution of the Amadeus graphs Certain classesof degree distribution were selected and based on those 480 bipartite graphs have beengenerated

At every graph the classical matching is computed based on the Edmonds algorithmthen the k-matching algorithm is used as described in section 122 Lastly a greedyalgorithm is implemented to be used for comparison

The ultimate goal is to explore the efficiency of the k-matching algorithm for the caseof k = 3 and to compare it with the result of the Edmonds algorithm and of course theGreedy implementationThe results follow along with some comments

9

10 Application

22 Reyni Erdos

bull RNxy are randomly generated graphs with a fixed number of 1000 nodes

bull There are 6 categories based on the initial matching and probability p of connection

bull x = L S L When the initial matching is large and S when it is small

bull y = 1 2 3 1 when p = lognn

2 when p = 13

and 3 when p = lognn

+ 01

Computation time over |E|

Computation time over |E| - Comments

bull This is a very straightforward set of figures

22 Reyni Erdos 11

bull When the initial matching is sufficiently large then the forced edges are taken out(a process which takes a fragment of the computation time) and then the classicalmatching algorithm (Edmonds) is applied on a smaller graph(G) This reducessignificantly the computation time

bull When the initial matching is small then the computation time of the constraintalgorithm might be larger than that of Edmonds The reason is that the constraintalgorithm need some time to compute the useless and forced edges and thenEdmonds algorithm is applied on G G Thus the overall processing time issometimes larger

Sorted matching size

Sorted matching size - Comments

12 Application

bull This set of figures represents the ascending order of the Classical matching sizealong with its corresponding Constraint and Greedy equivalent

bull When the probability is sufficiently higher than the threshold lognn

then the threealgorithms produce identical results of optimal matching

bull For lower probability there is a difference between the results of the algorithms

bull the degree of that difference is depicted in the first set of figures presented

bull It is interesting to observe that a change on the Constraint algorithm is associatedwith a even more significant change in the Greedy algorithm

bull There is a difference only when the probability is at the connectedness threshholdlognn

bull The difference is very small compared to the size of the matching ( 500)

bull The difference in matching size appears mostly at the Greedy implementationwhen compared to the constraint algorithm

Sorted Ratios

22 Reyni Erdos 13

Sorted Ratios - Comments

bull This set of figures depicts the ratios VV

EE

∆∆

in ascending order of VV

bull It is evident that when the initial matching is large the amount of forced edges(and their endpoints) removed is high thus the ratio of Nodes and edges is verylow For higher probabilities almost all edges are removed as useless

bull For a smaller initial matching almost no forced edges (and their endpoints) areremoved which we conclude be the node ration being close to 1 There is somesmall amount of useless edges removed though since the ratio of edges is less butclose to 1

bull The ratio of ∆ for large initial matching follows the trend of the node ratio yetfor smaller initial matching it deviates significantly

14 Application

Sorted |E||V |

Sorted |E||V | - Comments

bull Although as graph density the ratio 2|E||V |(|V |minus1)

is considered in this set of figures

we evaluate the correlation of the ratio |E||V | of G and G since the density of G

could acquire values higher than that of G

bull The figures are calculated in ascending order for the ratio of G

bull For the case of large initial matching the two ratios for G and G remain almostconstant ( to the extent of the probability of each graph) since removing forcededges( and their endpoints) alters the |E| and |V | proportionately

22 Reyni Erdos 15

bull For the case of small initial matching we observe some deviation in the valuesof the ration for G and that is explained with the removal of only useless edgeswhich only alters the |E| and keeps |V | in the original values

Sorted ∆

Sorted ∆-Comments

bull In this set of figures the ascending order of the ∆ of G is associated with the ∆of G

bull There is no significant jump of the ∆ for each graph category which tells that thatwe are comparing a uniform distribution of random grapghs for each probabilitycase

16 Application

bull For larger initial matching we observe the difference in the ∆s of G and G giventhe removed forced edges( and their endpoints) At some cases the ∆ of G dropsto 0 since the vast majority of edges have been declared forced and removed alongwith their endpoints

bull For smaller initial matching the ∆s of G and G follow mostly the same trend onlya few number of different instances

23 Barabasi Albert

Graph characteristics Barabasi Albert

bull BAxy are randomly generated graphs with a fixed number of 1000 nodes

bull There are 6 categories based on ini matching and of attached edges m

bull x = L S L When the initial matching is large and S when it is small

bull y = 1 2 3 1 when m = [1 10] 2 when m = [20 50] and 3 m = [50 100]

Computation time over |E|

23 Barabasi Albert 17

Computation time over |E| - Comments

bull When the initial matching is sufficiently large then the forced edges are taken out(a process which takes a fragment of the computation time) and then the classicalmatching algorithm (Edmonds) is applied on a smaller graph(G) This reducessignificantly the computation time

bull When the initial matching is small then the computation time of the constraintalgorithm might be larger than that of Edmonds The reason is that the constraintalgorithm need some time to compute the useless and forced edges and thenEdmonds algorithm is applied on G G Thus the overall processing time issometimes larger

Sorted matching size

18 Application

Sorted matching size-Comments

bull In this graph the matching size of the classical algorithm is depicted in ascendingorder along with the corresponding constraint algorithm and greedy result

bull Here in the case where m is small for both cases of initial matching (small large)the result may vary greatly starting from a value of half the perfect matching withsmall differences between the results of the various algorithm implementations

bull For the other cases of m the results converge

bull This is explained as for small values of m the graph is disconnected

bull In the matching size difference set of figures a very noticing difference value ap-pears For the cases of small m( the number of existing nodes that a new node isconnected to at the creation of the graph) we can see that the difference in the

23 Barabasi Albert 19

matching size compared to that of the perfect matching could be up to 40 ofthat of the matching size So there are occasions where the matching size is 200edges when the perfect matching would have been 500

bull the difference between the Constraint matching and the classical matching andthe difference of the constraint matching and that of the greedy matching do notshow significant values

Sorted Ratios

Sorted Ratio s -Comments

bull This set of figures depicts the ratios VV

EE

∆∆

in ascending order of VV

20 Application

bull It is evident that when the initial matching is large the amount of forced edges(and their endpoints) removed is high thus the ratio of Nodes and edges is verylow For higher probabilities almost all edges are removed as useless

bull For a smaller initial matching almost no forced edges (and their endpoints) areremoved which we conclude be the node ration being close to 1 There is somesmall amount of useless edges removed though since the ratio of edges is less butclose to 1

bull The ratio of ∆ for large initial matching follows the trend of the node ratio yetfor smaller initial matching it deviates significantly

Sorted |E||V |

23 Barabasi Albert 21

Sorted |E||V | - Comments

bull Although as graph density the ratio 2|E||V |(|V |minus1)

is considered in this set of figures

we evaluate the correlation of the ratio |E||V | of G and G since the density of G

could acquire values higher than that of G

bull The figures are calculated in ascending order for the ratio of G

bull For the case of large initial matching the two ratios for G and G remain almostconstant ( to the extent of the edge attraction m of each graph) since removingforced edges( and their endpoints) alters the |E| and |V | proportionately

bull For the case of small initial matching we observe some deviation in the valuesof the ration for G and that is explained with the removal of only useless edgeswhich only alters the |E| and keeps |V | in the original values

Sorted ∆

22 Application

Sorted ∆-Comments

bull In this set of figures the ascending order of the ∆ of G is associated with the ∆of G

bull There is a significant jump of the ∆ for each graph category which tells that thatwe are not comparing a uniform distribution of random graphs and based on theedge attraction m the graphs can vary in form

bull For larger initial matching we observe the difference in the ∆s of G and G giventhe removed forced edges( and their endpoints) At some cases the ∆ of G dropsto 0 since the vast majority of edges have been declared forced and removed alongwith their endpoints What is interesting is that the ∆ of G oscilates within stablelimits

24 Amadeus Graphs 23

bull For smaller initial matching the ∆s of G and G follow mostly the same trend onlya few number of different instances

24 Amadeus Graphs

Graph characteristics Amadeus graphs

bull These are the bipartite graphs provided by Amadeus

Computation time over |E|

Computation time over |E| - Comments

24 Application

bull For every instance the computation time of the classical algorithm is always smallerto that of the constraint matching

bull This allows as to speculate that we always compute a smaller G which also impliesthat we always find a set of forced edges and useless

Sorted matching size

Sorted matching size - Comments

bull Size of matching has an upward trend since the magnitude of the graphs is notthe same for the 160 instances

bull No significant deviation is noticed as per the first graph

24 Amadeus Graphs 25

bull Except from deviation from the perfect matching (number of flights) where some-times it could get up to 40

bull For the Amadeus Bipartite graphs we can see that the difference of the Classicaland the constraint implementation is not more than 1 edge in the matching

bull There appears to be a difference of up to 24 edges between the Classical matchingand the Perfect matching which is computed as the number of flights

bull The greedy algorithm performs well with only a few instances deviating slightlyform the Constraint algorithm result

Sorted Ratios

Sorted Ratios - Comments

26 Application

bull

Sorted |E||V |

Sorted |E||V | - Comments

bull Density of the graphs shows that on average we have 25-3 available time slot perflight

bull The line for the same value for G shows that there is a large deviation for everyinstance which allows for the hypothesis that the amount of useless+forced edgesof G has no obvious correlation to that of G

25 Bipartite 27

Sorted ∆

Sorted ∆-Comments

bull As per the previous related graphs for ∆ there is in significant drop in the ∆ of Gand G

25 Bipartite

Graph characteristics Bipartite random Graphs

bull BIPxy are randomly generated graphs with a fixed number of 1000(n=500 andm=500) nodes

bull There are 6 categories based on ini matching and probability p

28 Application

bull Probability p has been chosen as such in order to simulate the |E||V | 25 of theAmadeus bipartite graphs

bull So in order to have about 2-4 edges for every node we choose accordingly theprobability p to choose one of the n lowastm possible edges

bull x = L S L When the initial matching is large and S when it is small

bull y = 1 2 3 1 when p = 18250

2 when p = 25250

and 3 when p = 34250

Computation time over

Computation time overedges-Comments

bull

25 Bipartite 29

Sorted matching size

Sorted matching size-Comments

bull In these set of graphs one can instantly notice that only a few instances with highprobability can reach a matching size equal to the perfect matching

bull For the case of the initial matching we witness that there is a gap between the lineof the classical matching and those of the constraint and greedy results suggestingsmaller matching sizes of 10-40 edges

bull For the case of the small initial matching the result of the constraint matchingis now close to the result of the classical matching yet the greedy algorithm stillshows a relevantly big difference

30 Application

bull In this set of bipartite graphs we can witness that the result of the Constraintmatching shows a difference with the classical matching when the initial matchingis large The difference is smaller as the probability gets larger

bull For the case of the small initial matching the above phenomenom does not occuryet the greedy results deviates from that of the constraint matching

bull As per the pefrect matching compared to the classical matching a difference of5-10 edges is evident at almost all cases

Sorted Ratios

Sorted Ratios-Comments

bull Great max degree deviation

25 Bipartite 31

bull Regardless of the probability the ration of nodes and edges seems to have similarbehaviour when compared to the respective graphs of the same matching scale

bull Same gap between nodes ration and edges ration for all cases

Sorted |E||V |

Sorted |E||V | - Comments

bull In these set of figures we witness that the |E||V | acquires values relevant to those ofthe amadeus graphs The random graphs were constructed to depict this similarity

bull For smaller initial matching the ratios for G and G show the same upward trendand also they acquire closer values It represents the decrease of the averagenumber of forced edges in comparison to the larger matching cases

32 Application

Sorted ∆

Sorted ∆-Comments

bull ∆ acquires the same min and max values for each probability case (expected)

bull Gap in the case of large initial matching

26 Bipartite with degree seq

Graph characteristics

bull DEQBIPxy are randomly generated graphs based on three different types of degreedistribution of the Amadeus graphs

26 Bipartite with degree seq 33

bull There are 6 categories based on ini matching and degree distribution

bull x = L S L When the initial matching is large and S when it is small

bull y = 1 2 3 1 when degree distribution is based on file 2 when degree distributionis based on file and 3 when degree distribution is based on file

Computation time over

34 Application

Computation time overedges-Comments

bull Greedy algorithm takes minimum amount of time

bull The smaller the initial matching the more smaller the difference in comoutationtime of Constraint and classical algorithm

bull Due to preprocessing and the fact that G and G are the almost identical thetotal time needed to apply the constraint algorithm is in some cases bigger

Sorted matching size

26 Bipartite with degree seq 35

Sorted matching size-Comments

bull Classical matching is equal to perfect matching in every case

bull Constraint and greedy have identical behaviour

bull The larger the spectrum of the degree sequence the more efficient the matching

Sorted Ratios

36 Application

Sorted Ratios-Comments

bull With large initial matching most of the edges are considenred uselles or forced andare removed thus the ratio is close(if not equal to) zero

bull For small matching and large degree sequence sectrum hte max degree remainsthe same Only a few forced edges (and their nodes) are removed apparently nonodes with max degree

Sorted |E||V |

26 Bipartite with degree seq 37

Sorted |E||V | - Comments

bull In these set of figures we witness that the |E||V | acquires values relevant to those ofthe amadeus graphs The random graphs were constructed to depict this similarity

bull For smaller initial matching the ratios for G and G show the same upward trendand also they acquire closer values It repsresent the decrease of the averagenumber of forced edges in comparison to the larger matching cases

Sorted ∆

38 Application

Sorted ∆-Comments

bull Big difference in max degree in large initial matching

bull Almost identical behaviour in the case of small initial matching

Appendix A 39

Appendix A

BipartiteGraphGeneratorpy

from future import divisionimport networkx as nx

from networkxalgorithms import approximationimport collectionsimport randomimport mathfrom networkxalgorithms import bipartiteif name == main

for i in range(1481)waqs 481index=1n=randomrandint(100 1000)

n1=95 was 500me1=118

n2=251 was 500me2=903

n3=165 was 500me3=412

m=0m1=0p=randomrandom()p1=18250p2=25250p3=34250print ip=05t1=randomrandint(0 1)print im2=randomrandint(n2minus1 n2+1)G = nxGraph()ma = nxGraph()

aseq1=[1 2 3 4 5 3]

bseq1=[4 3 3 1 2 2 1]

aseq2=[16 14 14 14 12 11]bseq2=[0 0 0 0 0 0]

aseq3=[8 7 8 8 8 8]bseq3=[0 0 0 0 0 0]

40 Application

print Gnumber of edges()if ilt=160

G=bipartiteconfiguration model(aseq1 bseq1 create using=None seed=None)A=nxadjacency matrix(G)for ii in range(0n1+me1)

maadd node(ii)A=[Rtodense()tolist()[0] for R in A]

printnummanumber of nodes()rl=randomsample(range(0n1+me1) n1+me1)m=0done vertices = set()for p in rlprintin fordone verticesadd(p)

neighbors = []list()for iii in range(0n1+me1)

if A[p][iii]==1neighborsappend(iii)

randomshuffle(neighbors)continue loop = Truedegree = len(neighbors)

print degreej = 0p4=randomrandom()while continue loop and (jltdegree)print in loop

next = neighbors[j]if next not in done vertices and p not in done vertices

done verticesadd(p)done verticesadd(next)if p4gt=07print added edge

maadd edge(pnext)m=m+1

continue loop = Falsej += 1

print matching listOfedgeprint maedge

MA=nxadjacency matrix(ma)print MA

MA=[Rtodense()tolist()[0] for R in MA]print MA

B=[ join(map(strR)) for R in A]MB=[ join(map(strR)) for R in MA]

C=njoin(B)+nMC=njoin(MB)+n

print nprint mprint m1

filea=str(i)+txtwith open(fileaw) as f

Appendix A 41

fwrite(str(n1+me1))fwrite(n)fwrite(str(n1+me1))fwrite(n)fwrite(str(m))fwrite(n)fwrite(n)fwrite(C)fwrite(n)fwrite(MC)

elif igt160 and ilt321G=bipartiteconfiguration model(aseq2 bseq2 create using=None seed=None)A=nxadjacency matrix(G)for ii in range(0n2+me2)

maadd node(ii)A=[Rtodense()tolist()[0] for R in A]

printnummanumber of nodes()rl=randomsample(range(0n2+me2) n2+me2)m=0done vertices = set()for p in rlprintin fordone verticesadd(p)

neighbors = []list()for iii in range(0n2+me2)

if A[p][iii]==1neighborsappend(iii)

randomshuffle(neighbors)continue loop = Truedegree = len(neighbors)

print degreej = 0p4=randomrandom()while continue loop and (jltdegree)

print in loopnext = neighbors[j]if next not in done vertices and p not in done vertices

done verticesadd(p)done verticesadd(next)if p4gt=07

print added edgemaadd edge(pnext)m=m+1

continue loop = Falsej += 1

print matching listOfedgeprint maedge

MA=nxadjacency matrix(ma)print MA

MA=[Rtodense()tolist()[0] for R in MA]print MA

B=[ join(map(strR)) for R in A]MB=[ join(map(strR)) for R in MA]

42 Application

C=njoin(B)+nMC=njoin(MB)+n

print nprint mprint m1

filea=str(i)+txtwith open(fileaw) as f

fwrite(str(n2+me2))fwrite(n)fwrite(str(n2+me2))fwrite(n)fwrite(str(m))fwrite(n)fwrite(n)fwrite(C)fwrite(n)fwrite(MC)

elseG=bipartiteconfiguration model(aseq3 bseq3 create using=None seed=None)A=nxadjacency matrix(G)for ii in range(0n3+me3)

maadd node(ii)A=[Rtodense()tolist()[0] for R in A]

printnummanumber of nodes()rl=randomsample(range(0n3+me3) n3+me3)m=0done vertices = set()for p in rlprintin fordone verticesadd(p)

neighbors = []list()for iii in range(0n3+me3)

if A[p][iii]==1neighborsappend(iii)

randomshuffle(neighbors)continue loop = Truedegree = len(neighbors)

print degreej = 0p4=randomrandom()while continue loop and (jltdegree)

print in loopnext = neighbors[j]if next not in done vertices and p not in done vertices

done verticesadd(p)done verticesadd(next)if p4gt=07print added edge

maadd edge(pnext)m=m+1

continue loop = Falsej += 1

Appendix A 43

print matching listOfedgeprint maedge

MA=nxadjacency matrix(ma)print MA

MA=[Rtodense()tolist()[0] for R in MA]print MA

B=[ join(map(strR)) for R in A]MB=[ join(map(strR)) for R in MA]

C=njoin(B)+nMC=njoin(MB)+n

print nprint mprint m1

filea=str(i)+txtwith open(fileaw) as f

fwrite(str(n3+me3))fwrite(n)fwrite(str(n3+me3))fwrite(n)fwrite(str(m))fwrite(n)fwrite(n)fwrite(C)fwrite(n)fwrite(MC)

print nRandom graphs with random matching have been generated

44 Application

RandomGraphGeneratorpy

from future import divisionimport networkx as nxfrom networkxalgorithms import approximationimport collectionsimport randomimport mathif name == main

for i in range(1481)index=1n=randomrandint(100 1000)

n=1000m=0m1=0p=randomrandom()p1=mathlog(n2)np2=13p3=mathlog(n2)n+01p=05t1=randomrandint(0 1)print im2=randomrandint(n2minus1 n2+1)G = nxGraph()ma = nxGraph()print nme1=randomrandint(1 10)me2=randomrandint(2050)me3=randomrandint(50100)if ilt241

if ilt=80G=nxfast gnp random graph(n p1 seed=None directed=False)

elif igt80 and ilt161G=nxfast gnp random graph(n p2 seed=None directed=False)

elseG=nxfast gnp random graph(n p3 seed=None directed=False)

elseif ilt=320

G=nxbarabasi albert graph(n me1 seed=None)elif igt320 and ilt401

G=nxbarabasi albert graph(n me2 seed=None)else

G=nxbarabasi albert graph(n me3 seed=None)A=nxadjacency matrix(G)for ii in range(0n)

maadd node(ii)A=[Rtodense()tolist()[0] for R in A]

rl=randomsample(range(0n) n)m=0

Appendix A 45

done vertices = set()for p in rl

done verticesadd(p)neighbors = []list()for iii in range(0n)

if A[p][iii]==1neighborsappend(iii)

randomshuffle(neighbors)continue loop = Truedegree = len(neighbors)j = 0p2=randomrandom()while continue loop and (jltdegree)

next = neighbors[j]if next not in done vertices and p not in done vertices

done verticesadd(p)done verticesadd(next)if p2gt=00 Larger probability for smaller initial matching

maadd edge(pnext)m=m+1

continue loop = Falsej += 1

print matching listOfedgeprint maedgeMA=nxadjacency matrix(ma)MA=[Rtodense()tolist()[0] for R in MA]print MAB=[ join(map(strR)) for R in A]MB=[ join(map(strR)) for R in MA]

C=njoin(B)+nMC=njoin(MB)+nprint MCprint nprint mprint m1filea=str(i)+txtwith open(fileaw) as f

fwrite(str(n))fwrite(n)fwrite(str(n))fwrite(n)fwrite(str(m))fwrite(n)fwrite(n)fwrite(C)fwrite(n)fwrite(MC)

print nRandom graphs with random matching have been generated

46 Application

kequals3MaximumMatchingpy

from future import divisionimport networkx as nxfrom networkxalgorithms import bipartiteimport matplotlibpyplot as pltimport collectionsimport timeitimport xlwtimport xlrdimport mathimport sys

Case for General Graphsdef forced edges(Gadj dict2matching dict1num nodesforced)

flagg=0for n in range(0num nodes)

for k in adj dict2[n]if ([k]==matching dict1[n])

count=0for l in range(0num nodes)

count=count+adj dict2[l]count(k)if (len(adj dict2[n])==1) or (count==1)

forcedadd edge(nk)Gremove edge(nk)Gremove node(n)Gremove node(k)printforced edgenktemp=kflagg=1for m in range (len(adj dict2[n])minus1minus1minus1)

adj dict2[adj dict2[n][m]]remove(n)adj dict2[n]remove(adj dict2[n][m])

if adj dict2[temp]for l in range(len(adj dict2[temp])minus1minus1minus1)

if (adj dict2[temp][l]=n)adj dict2[adj dict2[temp][l]]remove(temp)adj dict2[temp]remove(adj dict2[temp][l])

break

def useless edges(num nodesadj dict1matching dict1uselessadj dict2G)for n in range(0num nodes)

for k in adj dict1[n]if ([k]=matching dict1[n]) and matching dict1[n] and matching dict1[k]

uselessadd edge(nk)Gremove edge(n k)

Appendix A 47

tempa=kadj dict2[n]remove(k)adj dict2[tempa]remove(n)adj dict1[tempa]remove(n)

return G

def Greedy(num nodesadj dict3matching dict2)

for n in range(0num nodes)if matching dict2[n]

flag2=minus1flag3=minus1for v in adj dict3[n]

if not matching dict2[v]flag2=vbreak

for p in adj dict3[matching dict2[n][0]]if not matching dict2[p]

flag3=pbreak

if (flag2=minus1) and (flag3=minus1) and (flag2=flag3)tempr=matching dict2[n][0]matching dict2[n]=[flag2]matching dict2[flag2]=[n]matching dict2[tempr]=[flag3]matching dict2[flag3]=[tempr]

elsefor k in adj dict3[n]

if not matching dict2[k]matching dict2[n]=[k]matching dict2[k]=[n]break

yo1=0for i in range(0num nodes)

if matching dict2[i] and [i]==matching dict2[matching dict2[i][0]]yo1=yo1+1

greedy size=yo12return greedy size

def General()

INPUTSwb = xlwtWorkbook()ws = wbadd sheet(Results Random)book=xlrdopen workbook(filenames randomxls)

48 Application

style0 = xlwteasyxf(fontbold on)style1 = xlwteasyxf(num format str=0000)INPUTSwswrite(0 0File style0)wswrite(0 1 Nodesstyle0)wswrite(0 2 Initial matchingstyle0)wswrite(0 3 NodesGstyle0)wswrite(0 4 EdgesGstyle0)wswrite(0 5 MaxDegreeGstyle0)wswrite(0 6 NodesG hatstyle0)wswrite(0 7 EdgesG Hatstyle0)wswrite(0 8 Useless edgesstyle0)wswrite(0 9 Forced edgesstyle0)wswrite(0 10 MaxDegreeG Hatstyle0)wswrite(0 11 Classical matchingstyle0)wswrite(0 12 Final matchingstyle0)wswrite(0 13 Greedy matchingstyle0)wswrite(0 14 Time classicalstyle0)wswrite(0 15 Time algorithmstyle0)wswrite(0 16 Time greedystyle0)wswrite(0 17 Perfect matching ratiostyle0)wswrite(0 18 Nodes ratiostyle0)wswrite(0 19 Edges ratiostyle0)wswrite(0 20 Matching ratiostyle0)

print nWelcomeThis is an implementation for general random graphs It uses Edmonds algorithm to compute maximum matching on G Hatn

for index in range (1481)was 481

if (index==482)f=open(Algotel generaltxtr)readlines()

elsefilea=str(booksheet by index(0)cell(index0))s=fileareplace(textu)replace()f=open(sr)readlines()Truewswrite(index 0 s)

print index

num nodes=int([xstrip()split() for x in f][0][0])

num matching=int([xstrip()split() for x in f][2][0])

adj temp = [xstrip()split() for x in f][44+num nodes]adj=[map(intR) for R in adj temp]

matching temp=[xstrip()split() for x in f][4+num nodes+14+2num nodes+1]matching1=[map(intR) for R in matching temp]

adj dict1=i[ii for iix in enumerate(L) if x] for iL in enumerate(adj)adj dict2=i[ii for iix in enumerate(L) if x] for iL in enumerate(adj)

Appendix A 49

adj dict3=i[ii for iix in enumerate(L) if x] for iL in enumerate(adj)

matching dict1=i[ii for iix in enumerate(L) if x] for iL in enumerate(matching1)matching dict2=i[ii for iix in enumerate(L) if x] for iL in enumerate(matching1)print adj dict2print matching dict2wswrite(index 1 num nodes)wswrite(index 2 num matching)

G = nxGraph()

useless= nxGraph()forced = nxGraph()

Fill Graphfor n in range(0num nodes)

for k in adj dict1[n]Gadd edge(nk)

Gt=Gnumber of edges()wswrite(index 3 Gnumber of nodes())wswrite(index 4 Gnumber of edges())wswrite(index 5 max(Gdegree()values()))

Compute Edmonds classical matching on G for comparison

startB = timeitdefault timer()Classical Matching=nxmax weight matching(G maxcardinality=False)stopB = timeitdefault timer()

Compute Gˆ nad MˆstartC = timeitdefault timer()useless edges(num nodesadj dict1matching dict1uselessadj dict2G)forced edges(Gadj dict2matching dict1num nodesforced)Final Matching=nxmax weight matching(G maxcardinality=False)stopC = timeitdefault timer()

GreedystartG = timeitdefault timer()greedy size=Greedy(num nodesadj dict3matching dict2)stopG = timeitdefault timer()

wswrite(index 6 Gnumber of nodes())wswrite(index 7 Gnumber of edges())wswrite(index 8 uselessnumber of edges())wswrite(index 9 forcednumber of edges())if Gdegree()values()

wswrite(index 10 max(Gdegree()values()))else

50 Application

wswrite(index 10 0)wswrite(index 11 len(Classical Matching)2)wswrite(index 12 len(Final Matching)2+forcednumber of edges())wswrite(index 13 greedy size)wswrite(index 14 stopB minus startBstyle1)wswrite(index 15 stopC minus startCstyle1)wswrite(index 16 stopG minus startGstyle1)wswrite(index 17 (len(Final Matching)2+forcednumber of edges())(num nodes2)style1)wswrite(index 18 Gnumber of nodes()Gtstyle1)wswrite(index 19 Gnumber of edges()Gtstyle1)wswrite(index 20 (len(Final Matching)2+forcednumber of edges())(len(Classical Matching)2)style1)

wbsave(AA Results Random Reyni Large Bipartitexls)

Main function Here we must choose the input form of the dataif name == main

startA = timeitdefault timer()General()stopA = timeitdefault timer()

print nThis program has terminatednnRunning time for 480 files stopAminusstartAprint nnPlease open AA Results Random Reyni Largexls file to see the Results

Appendix A 51

Plotmat

clear allclose allload(RN1Lmat)load(RN1Smat)load(RN2Lmat)load(RN2Smat)load(RN3Lmat)load(RN3Smat)

Plotsh(1)=figure(NameHistogram of Matching size difference between Constraint Algorithm and Greedy AlgorithmNumberTitleoff)

RN1L Greedydiff=RN1L Final matchingminusRN1L Greedy matchingRN2L Greedydiff=RN2L Final matchingminusRN2L Greedy matchingRN3L Greedydiff=RN3L Final matchingminusRN3L Greedy matchingRN1S Greedydiff=RN1S Final matchingminusRN1S Greedy matchingRN2S Greedydiff=RN2S Final matchingminusRN2S Greedy matchingRN3S Greedydiff=RN3S Final matchingminusRN3S Greedy matching

RN1L Finaldiff=RN1L Classical matchingminusRN1L Final matchingRN2L Finaldiff=RN2L Classical matchingminusRN2L Final matchingRN3L Finaldiff=RN3L Classical matchingminusRN3L Final matchingRN1S Finaldiff=RN1S Classical matchingminusRN1S Final matchingRN2S Finaldiff=RN2S Classical matchingminusRN2S Final matchingRN3S Finaldiff=RN3S Classical matchingminusRN3S Final matching

RN1L Classicaldiff=(RN1L Nodes2)minusRN1L Classical matchingRN2L Classicaldiff=(RN2L Nodes2)minusRN2L Classical matchingRN3L Classicaldiff=(RN3L Nodes2)minusRN3L Classical matchingRN1S Classicaldiff=(RN1S Nodes2)minusRN1S Classical matchingRN2S Classicaldiff=(RN2S Nodes2)minusRN2S Classical matchingRN3S Classicaldiff=(RN3S Nodes2)minusRN3S Classical matching

subplot(231)hold onhistf(RN1L Greedydiff0110facecolorbfacealpha9edgealpha1)histf(RN1L Finaldiff0110facecolorrfacealpha5edgealpha1)histf(RN1L Classicaldiff0110facecolorgfacealpha5edgealpha1)legalpha(ConminusGreClasminusConPerfminusClasslocationnortheast)legend boxoffaxis tightxlabel(edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN1L)grid on

subplot(232)hold onhistf(RN2L Greedydiff0110facecolorbfacealpha9edgealpha1)

52 Application

histf(RN2L Finaldiff0110facecolorrfacealpha5edgealpha1)histf(RN2L Classicaldiff0110facecolorgfacealpha5edgealpha1)legalpha(ConminusGreClasminusConPerfminusClasslocationnortheast)legend boxoffaxis tightxlabel(edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN2L)grid on

subplot(233)hold onhistf(RN3L Greedydiff0110facecolorbfacealpha5edgealpha1)histf(RN3L Finaldiff0110facecolorrfacealpha5edgealpha1)histf(RN3L Classicaldiff0110facecolorgfacealpha5edgealpha1)legalpha(ConminusGreClasminusConPerfminusClasslocationnortheast)legend boxoffaxis tightxlabel(edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN3L)grid on

subplot(234)hold onhistf(RN1S Greedydiff0110facecolorbfacealpha5edgealpha1)histf(RN1S Finaldiff0110facecolorrfacealpha5edgealpha1)histf(RN1S Classicaldiff0110facecolorgfacealpha5edgealpha1)legalpha(ConminusGreClasminusConPerfminusClasslocationnortheast)legend boxoffaxis tightxlabel(edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(R1NS)grid on

subplot(235)hold onhistf(RN2S Greedydiff0110facecolorbfacealpha5edgealpha1)histf(RN2S Finaldiff0110facecolorrfacealpha5edgealpha1)histf(RN2S Classicaldiff0110facecolorgfacealpha5edgealpha1)legalpha(ConminusGreClasminusConPerfminusClasslocationnortheast)legend boxoffaxis tightxlabel(edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN2S)grid on

subplot(236)hold onhistf(RN3S Greedydiff0110facecolorbfacealpha5edgealpha1)histf(RN3S Finaldiff0110facecolorrfacealpha5edgealpha1)histf(RN3S Classicaldiff0110facecolorgfacealpha5edgealpha1)

Appendix A 53

legalpha(ConminusGreClasminusConPerfminusClasslocationnortheast)legend boxoffaxis tightgrid ontitle(RN3S)xlabel(edges) xminusaxis labelylabel(instances) yminusaxis labelset(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN1png minusr300)h(2)=figure(NameHistogram of Max Degree of G AND G HatNumberTitleoff)RN1L x=RN1L MaxDegreeGminusRN1L MaxDegreeG HatRN2L x=RN2L MaxDegreeGminusRN2L MaxDegreeG HatRN3L x=RN3L MaxDegreeGminusRN3L MaxDegreeG HatRN1S x=RN1S MaxDegreeGminusRN1S MaxDegreeG HatRN2S x=RN2S MaxDegreeGminusRN2S MaxDegreeG HatRN3S x=RN3S MaxDegreeGminusRN3S MaxDegreeG Hatsubplot(231)hold onhistf(RN1L MaxDegreeG0150facecolorbfacealpha5edgealpha1)histf(RN1L MaxDegreeG Hat0150facecolorrfacealpha5edgealpha1)histf(RN1L x0150facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightxlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN1L)grid on

subplot(232)hold onhistf(RN2L MaxDegreeG010500facecolorbfacealpha5edgealpha1)histf(RN2L MaxDegreeG Hat010500facecolorrfacealpha5edgealpha1)histf(RN2L x010500facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightxlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN2L)grid on

subplot(233)hold onhistf(RN3L MaxDegreeG010300facecolorbfacealpha5edgealpha1)histf(RN3L MaxDegreeG Hat010300facecolorrfacealpha5edgealpha1)histf(RN3L x010300facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightxlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN3L)

54 Application

grid on

subplot(234)hold onhistf(RN1S MaxDegreeG0150facecolorbfacealpha5edgealpha1)histf(RN1S MaxDegreeG Hat0150facecolorrfacealpha5edgealpha1)histf(RN1S x0150facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightxlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(R1NS)grid on

subplot(235)hold onhistf(RN2S MaxDegreeG010500facecolorbfacealpha5edgealpha1)histf(RN2S MaxDegreeG Hat010500facecolorrfacealpha5edgealpha1)histf(RN2S x010500facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightxlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN2S)grid on

subplot(236)hold onhistf(RN3S MaxDegreeG05300facecolorbfacealpha5edgealpha1)histf(RN3S MaxDegreeG Hat05300facecolorrfacealpha5edgealpha1)histf(RN3S x05300facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightgrid ontitle(RN3S)xlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labelset(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN2png minusr300)

h(3)=figure(NameComputation time over edgesNumberTitleoff)

subplot(231)hold onstem(RN1L EdgesGRN1L Time classicalg)stem(RN1L EdgesGRN1L Time algorithmro)stem(RN1L EdgesGRN1L Time greedybx)grid on

Appendix A 55

title(RN1L)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)

subplot(232)hold onstem(RN2L EdgesGRN2L Time classicalg)stem(RN2L EdgesGRN2L Time algorithmro)stem(RN2L EdgesGRN2L Time greedybx)grid ontitle(RN2L)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)

subplot(233)hold onstem(RN3L EdgesGRN3L Time classicalg)stem(RN3L EdgesGRN3L Time algorithmro)stem(RN3L EdgesGRN3L Time greedybx)grid ontitle(RN3L)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)

subplot(234)hold onstem(RN1S EdgesGRN1S Time classicalg)stem(RN1S EdgesGRN1S Time algorithmro)stem(RN1S EdgesGRN1S Time greedybx)grid ontitle(RN1S)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)

subplot(235)hold onstem(RN2S EdgesGRN2S Time classicalg)stem(RN2S EdgesGRN2S Time algorithmro)stem(RN2S EdgesGRN2S Time greedybx)grid ontitle(RN2S)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)

subplot(236)hold onstem(RN3S EdgesGRN3S Time classicalg)stem(RN3S EdgesGRN3S Time algorithmro)stem(RN3S EdgesGRN3S Time greedybx)

56 Application

grid ontitle(RN3S)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)set(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN3png minusr300)

h(4)=figure(NameSorted matching sizeNumberTitleoff)RN1L Sorted matching temp(1)=RN1L Classical matchingRN1L Sorted matching temp(2)=RN1L Final matchingRN1L Sorted matching temp(3)=RN1L Greedy matchingRN1L Sorted matching temp(4)=RN1L Initial matchingRN1L Sorted matching=sortrows(RN1L Sorted matching temp)

RN2L Sorted matching temp(1)=RN2L Classical matchingRN2L Sorted matching temp(2)=RN2L Final matchingRN2L Sorted matching temp(3)=RN2L Greedy matchingRN2L Sorted matching temp(4)=RN2L Initial matchingRN2L Sorted matching=sortrows(RN2L Sorted matching temp)

RN3L Sorted matching temp(1)=RN3L Classical matchingRN3L Sorted matching temp(2)=RN3L Final matchingRN3L Sorted matching temp(3)=RN3L Greedy matchingRN3L Sorted matching temp(4)=RN3L Initial matchingRN3L Sorted matching=sortrows(RN3L Sorted matching temp)

RN1S Sorted matching temp(1)=RN1S Classical matchingRN1S Sorted matching temp(2)=RN1S Final matchingRN1S Sorted matching temp(3)=RN1S Greedy matchingRN1S Sorted matching temp(4)=RN1S Initial matchingRN1S Sorted matching=sortrows(RN1S Sorted matching temp)

RN2S Sorted matching temp(1)=RN2S Classical matchingRN2S Sorted matching temp(2)=RN2S Final matchingRN2S Sorted matching temp(3)=RN2S Greedy matchingRN2S Sorted matching temp(4)=RN2S Initial matchingRN2S Sorted matching=sortrows(RN2S Sorted matching temp)

RN3S Sorted matching temp(1)=RN3S Classical matchingRN3S Sorted matching temp(2)=RN3S Final matchingRN3S Sorted matching temp(3)=RN3S Greedy matchingRN3S Sorted matching temp(4)=RN3S Initial matchingRN3S Sorted matching=sortrows(RN3S Sorted matching temp)

subplot(231)hold onplot(RN1L Sorted matching(1)b)plot(RN1L Sorted matching(2)g)plot(RN1L Sorted matching(3)r)plot(RN1L Sorted matching(4)m)

Appendix A 57

grid ontitle(RN1L)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)

subplot(232)hold onplot(RN2L Sorted matching(1)b)plot(RN2L Sorted matching(2)g)plot(RN2L Sorted matching(3)r)plot(RN2L Sorted matching(4)m)grid ontitle(RN2L)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)

subplot(233)hold onplot(RN3L Sorted matching(1)b)plot(RN3L Sorted matching(2)g)plot(RN3L Sorted matching(3)r)plot(RN3L Sorted matching(4)m)grid ontitle(RN3L)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)

subplot(234)hold onplot(RN1S Sorted matching(1)b)plot(RN1S Sorted matching(2)g)plot(RN1S Sorted matching(3)r)plot(RN1S Sorted matching(4)m)grid ontitle(RN1S)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)

subplot(235)hold onplot(RN2S Sorted matching(1)b)plot(RN2S Sorted matching(2)g)plot(RN2S Sorted matching(3)r)plot(RN2S Sorted matching(4)m)grid ontitle(RN2S)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)

58 Application

subplot(236)hold onplot(RN3S Sorted matching(1)b)plot(RN3S Sorted matching(2)g)plot(RN3S Sorted matching(3)r)plot(RN3S Sorted matching(4)m)grid ontitle(RN3S)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)set(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN4png minusr300)h(5)=figure(NameSorted RatiosNumberTitleoff)RN1L ratio1=RN1L NodesG hatRN1L NodesGRN2L ratio1=RN2L NodesG hatRN2L NodesGRN3L ratio1=RN3L NodesG hatRN3L NodesGRN1S ratio1=RN1S NodesG hatRN1S NodesGRN2S ratio1=RN2S NodesG hatRN2S NodesGRN3S ratio1=RN3S NodesG hatRN3S NodesG

RN1L ratio2=RN1L EdgesG HatRN1L EdgesGRN2L ratio2=RN2L EdgesG HatRN2L EdgesGRN3L ratio2=RN3L EdgesG HatRN3L EdgesGRN1S ratio2=RN1S EdgesG HatRN1S EdgesGRN2S ratio2=RN2S EdgesG HatRN2S EdgesGRN3S ratio2=RN3S EdgesG HatRN3S EdgesG

RN1L ratio3=RN1L MaxDegreeG HatRN1L MaxDegreeGRN2L ratio3=RN2L MaxDegreeG HatRN2L MaxDegreeGRN3L ratio3=RN3L MaxDegreeG HatRN3L MaxDegreeGRN1S ratio3=RN1S MaxDegreeG HatRN1S MaxDegreeGRN2S ratio3=RN2S MaxDegreeG HatRN2S MaxDegreeGRN3S ratio3=RN3S MaxDegreeG HatRN3S MaxDegreeG

RN1L ratio(1)=RN1L ratio1RN1L ratio(2)=RN1L ratio2RN1L ratio(3)=RN1L ratio3

RN2L ratio(1)=RN2L ratio1RN2L ratio(2)=RN2L ratio2RN2L ratio(3)=RN2L ratio3

RN3L ratio(1)=RN3L ratio1RN3L ratio(2)=RN3L ratio2RN3L ratio(3)=RN3L ratio3

RN1S ratio(1)=RN1S ratio1RN1S ratio(2)=RN1S ratio2RN1S ratio(3)=RN1S ratio3

RN2S ratio(1)=RN2S ratio1

Appendix A 59

RN2S ratio(2)=RN2S ratio2RN2S ratio(3)=RN2S ratio3

RN3S ratio(1)=RN3S ratio1RN3S ratio(2)=RN3S ratio2RN3S ratio(3)=RN3S ratio3

RN1L ratio sorted=sortrows(RN1L ratio)RN2L ratio sorted=sortrows(RN2L ratio)RN3L ratio sorted=sortrows(RN3L ratio)RN1S ratio sorted=sortrows(RN1S ratio)RN2S ratio sorted=sortrows(RN2S ratio)RN3S ratio sorted=sortrows(RN3S ratio)

subplot(231)hold onplot(RN1L ratio sorted(1)b)plot(RN1L ratio sorted(2)g)plot(RN1L ratio sorted(3)r)grid ontitle(RN1L)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)

subplot(232)hold onplot(RN2L ratio sorted(1)b)plot(RN2L ratio sorted(2)g)plot(RN2L ratio sorted(3)r)grid ontitle(RN2L)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)

subplot(233)hold onplot(RN3L ratio sorted(1)b)plot(RN3L ratio sorted(2)g)plot(RN3L ratio sorted(3)r)grid ontitle(RN3L)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)

subplot(234)hold onplot(RN1S ratio sorted(1)b)plot(RN1S ratio sorted(2)g)plot(RN1S ratio sorted(3)r)grid on

60 Application

title(RN1S)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)

subplot(235)hold onplot(RN2S ratio sorted(1)b)plot(RN2S ratio sorted(2)g)plot(RN2S ratio sorted(3)r)grid ontitle(RN2S)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)

subplot(236)hold onplot(RN3S ratio sorted(1)b)plot(RN3S ratio sorted(2)g)plot(RN3S ratio sorted(3)r)grid ontitle(RN3S)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)set(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN5png minusr300)

h(6)=figure(NameSorted edges over nodesNumberTitleoff)

RN1L DegreeG1=(RN1L EdgesG)(RN1L NodesG)RN1L DegreeG Hat1=(RN1L EdgesG Hat)(RN1L NodesG hat)

RN1L Degree temp1(1)=RN1L DegreeG1RN1L Degree temp1(2)=RN1L DegreeG Hat1RN1L Degree sorted1=sortrows(RN1L Degree temp1)subplot(231)hold on

plot(RN1L Degree sorted1(1)b)plot(RN1L Degree sorted1(2)g)grid ontitle(RN1L)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)

RN2L DegreeG1=(RN2L EdgesG)(RN2L NodesG)RN2L DegreeG Hat1=(RN2L EdgesG Hat)(RN2L NodesG hat)

RN2L Degree temp1(1)=RN2L DegreeG1

Appendix A 61

RN2L Degree temp1(2)=RN2L DegreeG Hat1RN2L Degree sorted1=sortrows(RN2L Degree temp1)

subplot(232)hold onplot(RN2L Degree sorted1(1)b)plot(RN2L Degree sorted1(2)g)grid ontitle(RN2L)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)

RN3L DegreeG1=(RN3L EdgesG)(RN3L NodesG)RN3L DegreeG Hat1=(RN3L EdgesG Hat)(RN3L NodesG hat)

RN3L Degree temp1(1)=RN3L DegreeG1RN3L Degree temp1(2)=RN3L DegreeG Hat1RN3L Degree sorted1=sortrows(RN3L Degree temp1)

subplot(233)hold onplot(RN3L Degree sorted1(1)b)plot(RN3L Degree sorted1(2)g)grid ontitle(RN3L)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)

RN1S DegreeG1=(RN1S EdgesG)(RN1S NodesG)RN1S DegreeG Hat1=(RN1S EdgesG Hat)(RN1S NodesG hat)

RN1S Degree temp1(1)=RN1S DegreeG1RN1S Degree temp1(2)=RN1S DegreeG Hat1RN1S Degree sorted1=sortrows(RN1S Degree temp1)

subplot(234)hold onplot(RN1S Degree sorted1(1)b)plot(RN1S Degree sorted1(2)g)grid ontitle(RN1S)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)

RN2S DegreeG1=(RN2S EdgesG)(RN2S NodesG)RN2S DegreeG Hat1=(RN2S EdgesG Hat)(RN2S NodesG hat)

RN2S Degree temp1(1)=RN2S DegreeG1

62 Application

RN2S Degree temp1(2)=RN2S DegreeG Hat1RN2S Degree sorted1=sortrows(RN2S Degree temp1)

subplot(235)hold onplot(RN2S Degree sorted1(1)b)plot(RN2S Degree sorted1(2)g)grid ontitle(RN2S)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)

RN3S DegreeG1=(RN3S EdgesG)(RN3S NodesG)RN3S DegreeG Hat1=(RN3S EdgesG Hat)(RN3S NodesG hat)

RN3S Degree temp1(1)=RN3S DegreeG1RN3S Degree temp1(2)=RN3S DegreeG Hat1RN3S Degree sorted1=sortrows(RN3S Degree temp1)

subplot(236)hold onplot(RN3S Degree sorted1(1)b)plot(RN3S Degree sorted1(2)g)grid ontitle(RN3S)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)set(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN6png minusr300)h(7)=figure(NameSorted mATCHED DEGREENumberTitleoff)RN1L ratioMax(1)=RN1L MaxDegreeGRN1L ratioMax(2)=RN1L MaxDegreeG Hat

RN1L ratio sortedMax=sortrows(RN1L ratioMax)subplot(231)hold onplot(RN1L ratio sortedMax(1)b)plot(RN1L ratio sortedMax(2)g)grid ontitle(RN1L)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)

RN2L ratioMax(1)=RN2L MaxDegreeGRN2L ratioMax(2)=RN2L MaxDegreeG Hat

RN2L ratio sortedMax=sortrows(RN2L ratioMax)subplot(232)

Appendix A 63

hold onplot(RN2L ratio sortedMax(1)b)plot(RN2L ratio sortedMax(2)g)grid ontitle(RN2L)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)

RN3L ratioMax(1)=RN3L MaxDegreeGRN3L ratioMax(2)=RN3L MaxDegreeG Hat

RN3L ratio sortedMax=sortrows(RN3L ratioMax)subplot(233)hold onplot(RN3L ratio sortedMax(1)b)plot(RN3L ratio sortedMax(2)g)grid ontitle(RN3L)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)

RN1S ratioMax(1)=RN1S MaxDegreeGRN1S ratioMax(2)=RN1S MaxDegreeG Hat

RN1S ratio sortedMax=sortrows(RN1S ratioMax)subplot(234)hold onplot(RN1S ratio sortedMax(1)b)plot(RN1S ratio sortedMax(2)g)grid ontitle(RN1S)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)

RN2S ratioMax(1)=RN2S MaxDegreeGRN2S ratioMax(2)=RN2S MaxDegreeG Hat

RN2S ratio sortedMax=sortrows(RN2S ratioMax)

subplot(235)hold onplot(RN2S ratio sortedMax(1)b)plot(RN2S ratio sortedMax(2)g)grid ontitle(RN2S)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)

RN3S ratioMax(1)=RN3S MaxDegreeGRN3S ratioMax(2)=RN3S MaxDegreeG Hat

64 Application

RN3S ratio sortedMax=sortrows(RN3S ratioMax)subplot(236)hold onplot(RN3S ratio sortedMax(1)b)plot(RN3S ratio sortedMax(2)g)grid ontitle(RN1L)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)set(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN7png minusr300)

tilefigs()(h)

Bibliography

[1] C Berge ldquoTWO THEOREMS IN GRAPH THEORYrdquo Proceedings of the NationalAcademy of Sciences of the United States of America vol 43 no 9 pp 842ndash844Sep 1957

[2] L Bui S Sanghavi and R Srikant ldquoDistributed link scheduling with constantoverheadrdquo IEEEACM Trans Netw vol 17 no 5 pp 1467ndash1480 2009

[3] R Duan and S Pettie ldquoLinear-time approximation for maximum weight matchingrdquoJ ACM vol 61 no 1 2014

[4] J Edmonds ldquoPaths trees and flowersrdquo Canadian Journal of Mathematics vol 17pp 449ndash467 1965

[5] J E Hopcroft and R M Karp ldquoAn n52 algorithm for maximum matchings inbipartite graphsrdquo SIAM J Comput vol 2 no 4 pp 225ndash231 1973

[6] S Micali and V V Vazirani ldquoAn O(radic|V ||E|) algorithm for finding maximum

matching in general graphsrdquo in 21st Symp on Foundations of Comp Sc (FOCS)IEEE 1980 pp 17ndash27

[7] N Nisse A Salch and V Weber ldquoRecovery of disrupted airline operationsrdquo 2015httphalinriafrSomething

[8] X Wu and R Srikant ldquoRegulated maximal matching A distributed schedulingalgorithm for multi-hop wireless networks with nodeexclusive spectrum sharingrdquo inIEEE Conf on Decision and Control 2005

65

  • Contents
  • Introduction
  • Algorithms
    • Maximum matching
    • k-maximum matching
      • k-matching for Airport Slot assignment
      • The case where k=3
      • The case of Paths
      • The case of the Spider
          • Application
            • Description
            • Reyni Erdos
            • Barabaacutesi Albert
            • Amadeus Graphs
            • Bipartite
            • Bipartite with degree seq
            • Appendix A
              • BipartiteGraphGeneratorpy
              • RandomGraphGeneratorpy
              • kequals3MaximumMatchingpy
              • Plotmat
                  • Bibliography
Page 6: Theodoros Alexandros KARAGKIOULES -  · Introduction This work is the result of a 6 months internship, under the supervision of research O cer Nicolas NISSE. The original scope of

12 k-maximum matching 7

This algorithm has been used to implement the k-maximum matching programme thatcomputes the data provided by Amadeus and also the randomly generated graphs of thefollowing chapter

123 The case of Paths

Let Q = (v1 middot middot middot vi) be the maximum alternating path containing v1 If Q is notaugmenting or if Q has length more than k (ie i gt k) the algorithm is appliedrecursively on P (v1 middot middot middot viminus1) Otherwise Q is augmented (it is added to the desiredsequence of paths) and the algorithm is applied recursively on P Q

Algorithm 1 k-matching(PnM)

Require A path Pn = (v1 middot middot middot vn) a matching M sube E(P ) and an odd integer k ge 1Ensure A sequence (Q1 middot middot middot Qr) of augmenting paths with r = microk(PM)minus |M |1 if n = 1 then return empty2 else3 Let 1 lt i le n be the smallest integer (at least 2) such that vi is exposed4 if v1 is not exposed OR i gt k then5 Let P prime = (vi middot middot middot vn) and M prime = M cap E(P prime) return k-matching(P primeM prime)6 else7 Let P prime = (vi+1 middot middot middot vn) and M prime = M cap E(P prime) return (v1 middot middot middot vi)cup

k-matching(P primeM prime)8 end if9 end if

124 The case of the Spider

Theorem 11 Let S be a spider andM its initial matching and (P1 Pr) a sequenceof augmenting paths of length le k such that microk(SM) = |M |+ r then exist (Q1 Qr)a sequence of augmenting paths of length le k such that at most one such path containsthe center C

Proof Let S be a spider and lets assume that the optimal sequence of augmentingpaths SP is known along with the set of branches Br (those paths of S from a leaf tothe nn of CAssume for contradiction that exist ge 2 augmenting paths that contain the center Cand let Pi and Pj be the first such paths Let Pi = (umi

C uni) and Pj =

(umj C unj

) and let Q = (umi C unj

) be the (augmenting) pathcontaining partially Pi the center C and partially Pj Since [C uni

] sub [C unj] in order

for Pj to be an augmenting path then exist H = (Pj Pi) Q Letrsquos also assume thatthere is a set of paths A = A1 At isin SP between Pi and Pj and A sube Brsuch that forallk isin 1 2 t Ak Pi = empty or Ak Pj = empty Also there is a set of pathsB = B1 Bf isin SP between Pi and Pj and B sube Br such that foralln isin 1 2 fBn is non intersecting with any paths in AQPi Pj and H Then the optimal sequenceof augmenting paths can be the following

8 Algorithms

P1 P2 P3 A1 At QB1 Bf H Pr where augmenting only path Q oncecan lead to the equivalently optimal solution

Algorithm 2 Spider algorithm(SM)

1 M prime = M2 Let there be a set of leaves λ1 λr3 xk is the nn of C in the path C rarr λk4 for i isin 1 r do5 for j 6= i do M primeprime=Path Algorithm(λi rarr λjM)6 for k isin i j do M primeprime=M primeprimecupPath Algorithm(λk rarr xkM)7 end for8 end for9 if M primeprime gt M prime then10 M prime = M primeprime

11 end if12 end for13 return M prime

Proof Let there be an optimal solution that is obtained by the paths in the sequenceQprime = (P prime1 P

primer) for the spider

Let there also be a set of paths from leaf to leaf PLL = Pll1 P lln a set ofbranches BR = Br1 Brm and a sequence of augmenting paths Q = (P1 Pr)such that for j isin 1 r Pj isin PLL and forall i 6= j isin 1 r Pi isin BR

Applying the path algorithm for Pj and then for the r minus 1 paths of Q and due toTheorem 21 it is ensured that the matching produced will lead to a feasible solutionsince C is never exposed

Due to the iterative nature of the algorithm it can be checked that all possible com-binations of Pj and Pi that construct Q are considered and that one of the solutionscomputed as above will be the initial optimal solution Qprime

Thus by induction Spider Algorithm will always produce an optimal matching on aSpider

Chapter 2

Application

21 Description

This chapter aims at providing the picture of analysis on the data provided by Amadeusthe bipartite graphs and the random graphs generated

The random graphs have been generated as purely random graphs based on the ReyniErdos and the Barabasi Albert with different values of connectivity probability or con-nectivity

The bipartite graphs were generated on the density of the Amadeus graphs to simu-late better the results Additionally an extra set of test have been made on bipartitegraphs that simulate the degree distribution of the Amadeus graphs Certain classesof degree distribution were selected and based on those 480 bipartite graphs have beengenerated

At every graph the classical matching is computed based on the Edmonds algorithmthen the k-matching algorithm is used as described in section 122 Lastly a greedyalgorithm is implemented to be used for comparison

The ultimate goal is to explore the efficiency of the k-matching algorithm for the caseof k = 3 and to compare it with the result of the Edmonds algorithm and of course theGreedy implementationThe results follow along with some comments

9

10 Application

22 Reyni Erdos

bull RNxy are randomly generated graphs with a fixed number of 1000 nodes

bull There are 6 categories based on the initial matching and probability p of connection

bull x = L S L When the initial matching is large and S when it is small

bull y = 1 2 3 1 when p = lognn

2 when p = 13

and 3 when p = lognn

+ 01

Computation time over |E|

Computation time over |E| - Comments

bull This is a very straightforward set of figures

22 Reyni Erdos 11

bull When the initial matching is sufficiently large then the forced edges are taken out(a process which takes a fragment of the computation time) and then the classicalmatching algorithm (Edmonds) is applied on a smaller graph(G) This reducessignificantly the computation time

bull When the initial matching is small then the computation time of the constraintalgorithm might be larger than that of Edmonds The reason is that the constraintalgorithm need some time to compute the useless and forced edges and thenEdmonds algorithm is applied on G G Thus the overall processing time issometimes larger

Sorted matching size

Sorted matching size - Comments

12 Application

bull This set of figures represents the ascending order of the Classical matching sizealong with its corresponding Constraint and Greedy equivalent

bull When the probability is sufficiently higher than the threshold lognn

then the threealgorithms produce identical results of optimal matching

bull For lower probability there is a difference between the results of the algorithms

bull the degree of that difference is depicted in the first set of figures presented

bull It is interesting to observe that a change on the Constraint algorithm is associatedwith a even more significant change in the Greedy algorithm

bull There is a difference only when the probability is at the connectedness threshholdlognn

bull The difference is very small compared to the size of the matching ( 500)

bull The difference in matching size appears mostly at the Greedy implementationwhen compared to the constraint algorithm

Sorted Ratios

22 Reyni Erdos 13

Sorted Ratios - Comments

bull This set of figures depicts the ratios VV

EE

∆∆

in ascending order of VV

bull It is evident that when the initial matching is large the amount of forced edges(and their endpoints) removed is high thus the ratio of Nodes and edges is verylow For higher probabilities almost all edges are removed as useless

bull For a smaller initial matching almost no forced edges (and their endpoints) areremoved which we conclude be the node ration being close to 1 There is somesmall amount of useless edges removed though since the ratio of edges is less butclose to 1

bull The ratio of ∆ for large initial matching follows the trend of the node ratio yetfor smaller initial matching it deviates significantly

14 Application

Sorted |E||V |

Sorted |E||V | - Comments

bull Although as graph density the ratio 2|E||V |(|V |minus1)

is considered in this set of figures

we evaluate the correlation of the ratio |E||V | of G and G since the density of G

could acquire values higher than that of G

bull The figures are calculated in ascending order for the ratio of G

bull For the case of large initial matching the two ratios for G and G remain almostconstant ( to the extent of the probability of each graph) since removing forcededges( and their endpoints) alters the |E| and |V | proportionately

22 Reyni Erdos 15

bull For the case of small initial matching we observe some deviation in the valuesof the ration for G and that is explained with the removal of only useless edgeswhich only alters the |E| and keeps |V | in the original values

Sorted ∆

Sorted ∆-Comments

bull In this set of figures the ascending order of the ∆ of G is associated with the ∆of G

bull There is no significant jump of the ∆ for each graph category which tells that thatwe are comparing a uniform distribution of random grapghs for each probabilitycase

16 Application

bull For larger initial matching we observe the difference in the ∆s of G and G giventhe removed forced edges( and their endpoints) At some cases the ∆ of G dropsto 0 since the vast majority of edges have been declared forced and removed alongwith their endpoints

bull For smaller initial matching the ∆s of G and G follow mostly the same trend onlya few number of different instances

23 Barabasi Albert

Graph characteristics Barabasi Albert

bull BAxy are randomly generated graphs with a fixed number of 1000 nodes

bull There are 6 categories based on ini matching and of attached edges m

bull x = L S L When the initial matching is large and S when it is small

bull y = 1 2 3 1 when m = [1 10] 2 when m = [20 50] and 3 m = [50 100]

Computation time over |E|

23 Barabasi Albert 17

Computation time over |E| - Comments

bull When the initial matching is sufficiently large then the forced edges are taken out(a process which takes a fragment of the computation time) and then the classicalmatching algorithm (Edmonds) is applied on a smaller graph(G) This reducessignificantly the computation time

bull When the initial matching is small then the computation time of the constraintalgorithm might be larger than that of Edmonds The reason is that the constraintalgorithm need some time to compute the useless and forced edges and thenEdmonds algorithm is applied on G G Thus the overall processing time issometimes larger

Sorted matching size

18 Application

Sorted matching size-Comments

bull In this graph the matching size of the classical algorithm is depicted in ascendingorder along with the corresponding constraint algorithm and greedy result

bull Here in the case where m is small for both cases of initial matching (small large)the result may vary greatly starting from a value of half the perfect matching withsmall differences between the results of the various algorithm implementations

bull For the other cases of m the results converge

bull This is explained as for small values of m the graph is disconnected

bull In the matching size difference set of figures a very noticing difference value ap-pears For the cases of small m( the number of existing nodes that a new node isconnected to at the creation of the graph) we can see that the difference in the

23 Barabasi Albert 19

matching size compared to that of the perfect matching could be up to 40 ofthat of the matching size So there are occasions where the matching size is 200edges when the perfect matching would have been 500

bull the difference between the Constraint matching and the classical matching andthe difference of the constraint matching and that of the greedy matching do notshow significant values

Sorted Ratios

Sorted Ratio s -Comments

bull This set of figures depicts the ratios VV

EE

∆∆

in ascending order of VV

20 Application

bull It is evident that when the initial matching is large the amount of forced edges(and their endpoints) removed is high thus the ratio of Nodes and edges is verylow For higher probabilities almost all edges are removed as useless

bull For a smaller initial matching almost no forced edges (and their endpoints) areremoved which we conclude be the node ration being close to 1 There is somesmall amount of useless edges removed though since the ratio of edges is less butclose to 1

bull The ratio of ∆ for large initial matching follows the trend of the node ratio yetfor smaller initial matching it deviates significantly

Sorted |E||V |

23 Barabasi Albert 21

Sorted |E||V | - Comments

bull Although as graph density the ratio 2|E||V |(|V |minus1)

is considered in this set of figures

we evaluate the correlation of the ratio |E||V | of G and G since the density of G

could acquire values higher than that of G

bull The figures are calculated in ascending order for the ratio of G

bull For the case of large initial matching the two ratios for G and G remain almostconstant ( to the extent of the edge attraction m of each graph) since removingforced edges( and their endpoints) alters the |E| and |V | proportionately

bull For the case of small initial matching we observe some deviation in the valuesof the ration for G and that is explained with the removal of only useless edgeswhich only alters the |E| and keeps |V | in the original values

Sorted ∆

22 Application

Sorted ∆-Comments

bull In this set of figures the ascending order of the ∆ of G is associated with the ∆of G

bull There is a significant jump of the ∆ for each graph category which tells that thatwe are not comparing a uniform distribution of random graphs and based on theedge attraction m the graphs can vary in form

bull For larger initial matching we observe the difference in the ∆s of G and G giventhe removed forced edges( and their endpoints) At some cases the ∆ of G dropsto 0 since the vast majority of edges have been declared forced and removed alongwith their endpoints What is interesting is that the ∆ of G oscilates within stablelimits

24 Amadeus Graphs 23

bull For smaller initial matching the ∆s of G and G follow mostly the same trend onlya few number of different instances

24 Amadeus Graphs

Graph characteristics Amadeus graphs

bull These are the bipartite graphs provided by Amadeus

Computation time over |E|

Computation time over |E| - Comments

24 Application

bull For every instance the computation time of the classical algorithm is always smallerto that of the constraint matching

bull This allows as to speculate that we always compute a smaller G which also impliesthat we always find a set of forced edges and useless

Sorted matching size

Sorted matching size - Comments

bull Size of matching has an upward trend since the magnitude of the graphs is notthe same for the 160 instances

bull No significant deviation is noticed as per the first graph

24 Amadeus Graphs 25

bull Except from deviation from the perfect matching (number of flights) where some-times it could get up to 40

bull For the Amadeus Bipartite graphs we can see that the difference of the Classicaland the constraint implementation is not more than 1 edge in the matching

bull There appears to be a difference of up to 24 edges between the Classical matchingand the Perfect matching which is computed as the number of flights

bull The greedy algorithm performs well with only a few instances deviating slightlyform the Constraint algorithm result

Sorted Ratios

Sorted Ratios - Comments

26 Application

bull

Sorted |E||V |

Sorted |E||V | - Comments

bull Density of the graphs shows that on average we have 25-3 available time slot perflight

bull The line for the same value for G shows that there is a large deviation for everyinstance which allows for the hypothesis that the amount of useless+forced edgesof G has no obvious correlation to that of G

25 Bipartite 27

Sorted ∆

Sorted ∆-Comments

bull As per the previous related graphs for ∆ there is in significant drop in the ∆ of Gand G

25 Bipartite

Graph characteristics Bipartite random Graphs

bull BIPxy are randomly generated graphs with a fixed number of 1000(n=500 andm=500) nodes

bull There are 6 categories based on ini matching and probability p

28 Application

bull Probability p has been chosen as such in order to simulate the |E||V | 25 of theAmadeus bipartite graphs

bull So in order to have about 2-4 edges for every node we choose accordingly theprobability p to choose one of the n lowastm possible edges

bull x = L S L When the initial matching is large and S when it is small

bull y = 1 2 3 1 when p = 18250

2 when p = 25250

and 3 when p = 34250

Computation time over

Computation time overedges-Comments

bull

25 Bipartite 29

Sorted matching size

Sorted matching size-Comments

bull In these set of graphs one can instantly notice that only a few instances with highprobability can reach a matching size equal to the perfect matching

bull For the case of the initial matching we witness that there is a gap between the lineof the classical matching and those of the constraint and greedy results suggestingsmaller matching sizes of 10-40 edges

bull For the case of the small initial matching the result of the constraint matchingis now close to the result of the classical matching yet the greedy algorithm stillshows a relevantly big difference

30 Application

bull In this set of bipartite graphs we can witness that the result of the Constraintmatching shows a difference with the classical matching when the initial matchingis large The difference is smaller as the probability gets larger

bull For the case of the small initial matching the above phenomenom does not occuryet the greedy results deviates from that of the constraint matching

bull As per the pefrect matching compared to the classical matching a difference of5-10 edges is evident at almost all cases

Sorted Ratios

Sorted Ratios-Comments

bull Great max degree deviation

25 Bipartite 31

bull Regardless of the probability the ration of nodes and edges seems to have similarbehaviour when compared to the respective graphs of the same matching scale

bull Same gap between nodes ration and edges ration for all cases

Sorted |E||V |

Sorted |E||V | - Comments

bull In these set of figures we witness that the |E||V | acquires values relevant to those ofthe amadeus graphs The random graphs were constructed to depict this similarity

bull For smaller initial matching the ratios for G and G show the same upward trendand also they acquire closer values It represents the decrease of the averagenumber of forced edges in comparison to the larger matching cases

32 Application

Sorted ∆

Sorted ∆-Comments

bull ∆ acquires the same min and max values for each probability case (expected)

bull Gap in the case of large initial matching

26 Bipartite with degree seq

Graph characteristics

bull DEQBIPxy are randomly generated graphs based on three different types of degreedistribution of the Amadeus graphs

26 Bipartite with degree seq 33

bull There are 6 categories based on ini matching and degree distribution

bull x = L S L When the initial matching is large and S when it is small

bull y = 1 2 3 1 when degree distribution is based on file 2 when degree distributionis based on file and 3 when degree distribution is based on file

Computation time over

34 Application

Computation time overedges-Comments

bull Greedy algorithm takes minimum amount of time

bull The smaller the initial matching the more smaller the difference in comoutationtime of Constraint and classical algorithm

bull Due to preprocessing and the fact that G and G are the almost identical thetotal time needed to apply the constraint algorithm is in some cases bigger

Sorted matching size

26 Bipartite with degree seq 35

Sorted matching size-Comments

bull Classical matching is equal to perfect matching in every case

bull Constraint and greedy have identical behaviour

bull The larger the spectrum of the degree sequence the more efficient the matching

Sorted Ratios

36 Application

Sorted Ratios-Comments

bull With large initial matching most of the edges are considenred uselles or forced andare removed thus the ratio is close(if not equal to) zero

bull For small matching and large degree sequence sectrum hte max degree remainsthe same Only a few forced edges (and their nodes) are removed apparently nonodes with max degree

Sorted |E||V |

26 Bipartite with degree seq 37

Sorted |E||V | - Comments

bull In these set of figures we witness that the |E||V | acquires values relevant to those ofthe amadeus graphs The random graphs were constructed to depict this similarity

bull For smaller initial matching the ratios for G and G show the same upward trendand also they acquire closer values It repsresent the decrease of the averagenumber of forced edges in comparison to the larger matching cases

Sorted ∆

38 Application

Sorted ∆-Comments

bull Big difference in max degree in large initial matching

bull Almost identical behaviour in the case of small initial matching

Appendix A 39

Appendix A

BipartiteGraphGeneratorpy

from future import divisionimport networkx as nx

from networkxalgorithms import approximationimport collectionsimport randomimport mathfrom networkxalgorithms import bipartiteif name == main

for i in range(1481)waqs 481index=1n=randomrandint(100 1000)

n1=95 was 500me1=118

n2=251 was 500me2=903

n3=165 was 500me3=412

m=0m1=0p=randomrandom()p1=18250p2=25250p3=34250print ip=05t1=randomrandint(0 1)print im2=randomrandint(n2minus1 n2+1)G = nxGraph()ma = nxGraph()

aseq1=[1 2 3 4 5 3]

bseq1=[4 3 3 1 2 2 1]

aseq2=[16 14 14 14 12 11]bseq2=[0 0 0 0 0 0]

aseq3=[8 7 8 8 8 8]bseq3=[0 0 0 0 0 0]

40 Application

print Gnumber of edges()if ilt=160

G=bipartiteconfiguration model(aseq1 bseq1 create using=None seed=None)A=nxadjacency matrix(G)for ii in range(0n1+me1)

maadd node(ii)A=[Rtodense()tolist()[0] for R in A]

printnummanumber of nodes()rl=randomsample(range(0n1+me1) n1+me1)m=0done vertices = set()for p in rlprintin fordone verticesadd(p)

neighbors = []list()for iii in range(0n1+me1)

if A[p][iii]==1neighborsappend(iii)

randomshuffle(neighbors)continue loop = Truedegree = len(neighbors)

print degreej = 0p4=randomrandom()while continue loop and (jltdegree)print in loop

next = neighbors[j]if next not in done vertices and p not in done vertices

done verticesadd(p)done verticesadd(next)if p4gt=07print added edge

maadd edge(pnext)m=m+1

continue loop = Falsej += 1

print matching listOfedgeprint maedge

MA=nxadjacency matrix(ma)print MA

MA=[Rtodense()tolist()[0] for R in MA]print MA

B=[ join(map(strR)) for R in A]MB=[ join(map(strR)) for R in MA]

C=njoin(B)+nMC=njoin(MB)+n

print nprint mprint m1

filea=str(i)+txtwith open(fileaw) as f

Appendix A 41

fwrite(str(n1+me1))fwrite(n)fwrite(str(n1+me1))fwrite(n)fwrite(str(m))fwrite(n)fwrite(n)fwrite(C)fwrite(n)fwrite(MC)

elif igt160 and ilt321G=bipartiteconfiguration model(aseq2 bseq2 create using=None seed=None)A=nxadjacency matrix(G)for ii in range(0n2+me2)

maadd node(ii)A=[Rtodense()tolist()[0] for R in A]

printnummanumber of nodes()rl=randomsample(range(0n2+me2) n2+me2)m=0done vertices = set()for p in rlprintin fordone verticesadd(p)

neighbors = []list()for iii in range(0n2+me2)

if A[p][iii]==1neighborsappend(iii)

randomshuffle(neighbors)continue loop = Truedegree = len(neighbors)

print degreej = 0p4=randomrandom()while continue loop and (jltdegree)

print in loopnext = neighbors[j]if next not in done vertices and p not in done vertices

done verticesadd(p)done verticesadd(next)if p4gt=07

print added edgemaadd edge(pnext)m=m+1

continue loop = Falsej += 1

print matching listOfedgeprint maedge

MA=nxadjacency matrix(ma)print MA

MA=[Rtodense()tolist()[0] for R in MA]print MA

B=[ join(map(strR)) for R in A]MB=[ join(map(strR)) for R in MA]

42 Application

C=njoin(B)+nMC=njoin(MB)+n

print nprint mprint m1

filea=str(i)+txtwith open(fileaw) as f

fwrite(str(n2+me2))fwrite(n)fwrite(str(n2+me2))fwrite(n)fwrite(str(m))fwrite(n)fwrite(n)fwrite(C)fwrite(n)fwrite(MC)

elseG=bipartiteconfiguration model(aseq3 bseq3 create using=None seed=None)A=nxadjacency matrix(G)for ii in range(0n3+me3)

maadd node(ii)A=[Rtodense()tolist()[0] for R in A]

printnummanumber of nodes()rl=randomsample(range(0n3+me3) n3+me3)m=0done vertices = set()for p in rlprintin fordone verticesadd(p)

neighbors = []list()for iii in range(0n3+me3)

if A[p][iii]==1neighborsappend(iii)

randomshuffle(neighbors)continue loop = Truedegree = len(neighbors)

print degreej = 0p4=randomrandom()while continue loop and (jltdegree)

print in loopnext = neighbors[j]if next not in done vertices and p not in done vertices

done verticesadd(p)done verticesadd(next)if p4gt=07print added edge

maadd edge(pnext)m=m+1

continue loop = Falsej += 1

Appendix A 43

print matching listOfedgeprint maedge

MA=nxadjacency matrix(ma)print MA

MA=[Rtodense()tolist()[0] for R in MA]print MA

B=[ join(map(strR)) for R in A]MB=[ join(map(strR)) for R in MA]

C=njoin(B)+nMC=njoin(MB)+n

print nprint mprint m1

filea=str(i)+txtwith open(fileaw) as f

fwrite(str(n3+me3))fwrite(n)fwrite(str(n3+me3))fwrite(n)fwrite(str(m))fwrite(n)fwrite(n)fwrite(C)fwrite(n)fwrite(MC)

print nRandom graphs with random matching have been generated

44 Application

RandomGraphGeneratorpy

from future import divisionimport networkx as nxfrom networkxalgorithms import approximationimport collectionsimport randomimport mathif name == main

for i in range(1481)index=1n=randomrandint(100 1000)

n=1000m=0m1=0p=randomrandom()p1=mathlog(n2)np2=13p3=mathlog(n2)n+01p=05t1=randomrandint(0 1)print im2=randomrandint(n2minus1 n2+1)G = nxGraph()ma = nxGraph()print nme1=randomrandint(1 10)me2=randomrandint(2050)me3=randomrandint(50100)if ilt241

if ilt=80G=nxfast gnp random graph(n p1 seed=None directed=False)

elif igt80 and ilt161G=nxfast gnp random graph(n p2 seed=None directed=False)

elseG=nxfast gnp random graph(n p3 seed=None directed=False)

elseif ilt=320

G=nxbarabasi albert graph(n me1 seed=None)elif igt320 and ilt401

G=nxbarabasi albert graph(n me2 seed=None)else

G=nxbarabasi albert graph(n me3 seed=None)A=nxadjacency matrix(G)for ii in range(0n)

maadd node(ii)A=[Rtodense()tolist()[0] for R in A]

rl=randomsample(range(0n) n)m=0

Appendix A 45

done vertices = set()for p in rl

done verticesadd(p)neighbors = []list()for iii in range(0n)

if A[p][iii]==1neighborsappend(iii)

randomshuffle(neighbors)continue loop = Truedegree = len(neighbors)j = 0p2=randomrandom()while continue loop and (jltdegree)

next = neighbors[j]if next not in done vertices and p not in done vertices

done verticesadd(p)done verticesadd(next)if p2gt=00 Larger probability for smaller initial matching

maadd edge(pnext)m=m+1

continue loop = Falsej += 1

print matching listOfedgeprint maedgeMA=nxadjacency matrix(ma)MA=[Rtodense()tolist()[0] for R in MA]print MAB=[ join(map(strR)) for R in A]MB=[ join(map(strR)) for R in MA]

C=njoin(B)+nMC=njoin(MB)+nprint MCprint nprint mprint m1filea=str(i)+txtwith open(fileaw) as f

fwrite(str(n))fwrite(n)fwrite(str(n))fwrite(n)fwrite(str(m))fwrite(n)fwrite(n)fwrite(C)fwrite(n)fwrite(MC)

print nRandom graphs with random matching have been generated

46 Application

kequals3MaximumMatchingpy

from future import divisionimport networkx as nxfrom networkxalgorithms import bipartiteimport matplotlibpyplot as pltimport collectionsimport timeitimport xlwtimport xlrdimport mathimport sys

Case for General Graphsdef forced edges(Gadj dict2matching dict1num nodesforced)

flagg=0for n in range(0num nodes)

for k in adj dict2[n]if ([k]==matching dict1[n])

count=0for l in range(0num nodes)

count=count+adj dict2[l]count(k)if (len(adj dict2[n])==1) or (count==1)

forcedadd edge(nk)Gremove edge(nk)Gremove node(n)Gremove node(k)printforced edgenktemp=kflagg=1for m in range (len(adj dict2[n])minus1minus1minus1)

adj dict2[adj dict2[n][m]]remove(n)adj dict2[n]remove(adj dict2[n][m])

if adj dict2[temp]for l in range(len(adj dict2[temp])minus1minus1minus1)

if (adj dict2[temp][l]=n)adj dict2[adj dict2[temp][l]]remove(temp)adj dict2[temp]remove(adj dict2[temp][l])

break

def useless edges(num nodesadj dict1matching dict1uselessadj dict2G)for n in range(0num nodes)

for k in adj dict1[n]if ([k]=matching dict1[n]) and matching dict1[n] and matching dict1[k]

uselessadd edge(nk)Gremove edge(n k)

Appendix A 47

tempa=kadj dict2[n]remove(k)adj dict2[tempa]remove(n)adj dict1[tempa]remove(n)

return G

def Greedy(num nodesadj dict3matching dict2)

for n in range(0num nodes)if matching dict2[n]

flag2=minus1flag3=minus1for v in adj dict3[n]

if not matching dict2[v]flag2=vbreak

for p in adj dict3[matching dict2[n][0]]if not matching dict2[p]

flag3=pbreak

if (flag2=minus1) and (flag3=minus1) and (flag2=flag3)tempr=matching dict2[n][0]matching dict2[n]=[flag2]matching dict2[flag2]=[n]matching dict2[tempr]=[flag3]matching dict2[flag3]=[tempr]

elsefor k in adj dict3[n]

if not matching dict2[k]matching dict2[n]=[k]matching dict2[k]=[n]break

yo1=0for i in range(0num nodes)

if matching dict2[i] and [i]==matching dict2[matching dict2[i][0]]yo1=yo1+1

greedy size=yo12return greedy size

def General()

INPUTSwb = xlwtWorkbook()ws = wbadd sheet(Results Random)book=xlrdopen workbook(filenames randomxls)

48 Application

style0 = xlwteasyxf(fontbold on)style1 = xlwteasyxf(num format str=0000)INPUTSwswrite(0 0File style0)wswrite(0 1 Nodesstyle0)wswrite(0 2 Initial matchingstyle0)wswrite(0 3 NodesGstyle0)wswrite(0 4 EdgesGstyle0)wswrite(0 5 MaxDegreeGstyle0)wswrite(0 6 NodesG hatstyle0)wswrite(0 7 EdgesG Hatstyle0)wswrite(0 8 Useless edgesstyle0)wswrite(0 9 Forced edgesstyle0)wswrite(0 10 MaxDegreeG Hatstyle0)wswrite(0 11 Classical matchingstyle0)wswrite(0 12 Final matchingstyle0)wswrite(0 13 Greedy matchingstyle0)wswrite(0 14 Time classicalstyle0)wswrite(0 15 Time algorithmstyle0)wswrite(0 16 Time greedystyle0)wswrite(0 17 Perfect matching ratiostyle0)wswrite(0 18 Nodes ratiostyle0)wswrite(0 19 Edges ratiostyle0)wswrite(0 20 Matching ratiostyle0)

print nWelcomeThis is an implementation for general random graphs It uses Edmonds algorithm to compute maximum matching on G Hatn

for index in range (1481)was 481

if (index==482)f=open(Algotel generaltxtr)readlines()

elsefilea=str(booksheet by index(0)cell(index0))s=fileareplace(textu)replace()f=open(sr)readlines()Truewswrite(index 0 s)

print index

num nodes=int([xstrip()split() for x in f][0][0])

num matching=int([xstrip()split() for x in f][2][0])

adj temp = [xstrip()split() for x in f][44+num nodes]adj=[map(intR) for R in adj temp]

matching temp=[xstrip()split() for x in f][4+num nodes+14+2num nodes+1]matching1=[map(intR) for R in matching temp]

adj dict1=i[ii for iix in enumerate(L) if x] for iL in enumerate(adj)adj dict2=i[ii for iix in enumerate(L) if x] for iL in enumerate(adj)

Appendix A 49

adj dict3=i[ii for iix in enumerate(L) if x] for iL in enumerate(adj)

matching dict1=i[ii for iix in enumerate(L) if x] for iL in enumerate(matching1)matching dict2=i[ii for iix in enumerate(L) if x] for iL in enumerate(matching1)print adj dict2print matching dict2wswrite(index 1 num nodes)wswrite(index 2 num matching)

G = nxGraph()

useless= nxGraph()forced = nxGraph()

Fill Graphfor n in range(0num nodes)

for k in adj dict1[n]Gadd edge(nk)

Gt=Gnumber of edges()wswrite(index 3 Gnumber of nodes())wswrite(index 4 Gnumber of edges())wswrite(index 5 max(Gdegree()values()))

Compute Edmonds classical matching on G for comparison

startB = timeitdefault timer()Classical Matching=nxmax weight matching(G maxcardinality=False)stopB = timeitdefault timer()

Compute Gˆ nad MˆstartC = timeitdefault timer()useless edges(num nodesadj dict1matching dict1uselessadj dict2G)forced edges(Gadj dict2matching dict1num nodesforced)Final Matching=nxmax weight matching(G maxcardinality=False)stopC = timeitdefault timer()

GreedystartG = timeitdefault timer()greedy size=Greedy(num nodesadj dict3matching dict2)stopG = timeitdefault timer()

wswrite(index 6 Gnumber of nodes())wswrite(index 7 Gnumber of edges())wswrite(index 8 uselessnumber of edges())wswrite(index 9 forcednumber of edges())if Gdegree()values()

wswrite(index 10 max(Gdegree()values()))else

50 Application

wswrite(index 10 0)wswrite(index 11 len(Classical Matching)2)wswrite(index 12 len(Final Matching)2+forcednumber of edges())wswrite(index 13 greedy size)wswrite(index 14 stopB minus startBstyle1)wswrite(index 15 stopC minus startCstyle1)wswrite(index 16 stopG minus startGstyle1)wswrite(index 17 (len(Final Matching)2+forcednumber of edges())(num nodes2)style1)wswrite(index 18 Gnumber of nodes()Gtstyle1)wswrite(index 19 Gnumber of edges()Gtstyle1)wswrite(index 20 (len(Final Matching)2+forcednumber of edges())(len(Classical Matching)2)style1)

wbsave(AA Results Random Reyni Large Bipartitexls)

Main function Here we must choose the input form of the dataif name == main

startA = timeitdefault timer()General()stopA = timeitdefault timer()

print nThis program has terminatednnRunning time for 480 files stopAminusstartAprint nnPlease open AA Results Random Reyni Largexls file to see the Results

Appendix A 51

Plotmat

clear allclose allload(RN1Lmat)load(RN1Smat)load(RN2Lmat)load(RN2Smat)load(RN3Lmat)load(RN3Smat)

Plotsh(1)=figure(NameHistogram of Matching size difference between Constraint Algorithm and Greedy AlgorithmNumberTitleoff)

RN1L Greedydiff=RN1L Final matchingminusRN1L Greedy matchingRN2L Greedydiff=RN2L Final matchingminusRN2L Greedy matchingRN3L Greedydiff=RN3L Final matchingminusRN3L Greedy matchingRN1S Greedydiff=RN1S Final matchingminusRN1S Greedy matchingRN2S Greedydiff=RN2S Final matchingminusRN2S Greedy matchingRN3S Greedydiff=RN3S Final matchingminusRN3S Greedy matching

RN1L Finaldiff=RN1L Classical matchingminusRN1L Final matchingRN2L Finaldiff=RN2L Classical matchingminusRN2L Final matchingRN3L Finaldiff=RN3L Classical matchingminusRN3L Final matchingRN1S Finaldiff=RN1S Classical matchingminusRN1S Final matchingRN2S Finaldiff=RN2S Classical matchingminusRN2S Final matchingRN3S Finaldiff=RN3S Classical matchingminusRN3S Final matching

RN1L Classicaldiff=(RN1L Nodes2)minusRN1L Classical matchingRN2L Classicaldiff=(RN2L Nodes2)minusRN2L Classical matchingRN3L Classicaldiff=(RN3L Nodes2)minusRN3L Classical matchingRN1S Classicaldiff=(RN1S Nodes2)minusRN1S Classical matchingRN2S Classicaldiff=(RN2S Nodes2)minusRN2S Classical matchingRN3S Classicaldiff=(RN3S Nodes2)minusRN3S Classical matching

subplot(231)hold onhistf(RN1L Greedydiff0110facecolorbfacealpha9edgealpha1)histf(RN1L Finaldiff0110facecolorrfacealpha5edgealpha1)histf(RN1L Classicaldiff0110facecolorgfacealpha5edgealpha1)legalpha(ConminusGreClasminusConPerfminusClasslocationnortheast)legend boxoffaxis tightxlabel(edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN1L)grid on

subplot(232)hold onhistf(RN2L Greedydiff0110facecolorbfacealpha9edgealpha1)

52 Application

histf(RN2L Finaldiff0110facecolorrfacealpha5edgealpha1)histf(RN2L Classicaldiff0110facecolorgfacealpha5edgealpha1)legalpha(ConminusGreClasminusConPerfminusClasslocationnortheast)legend boxoffaxis tightxlabel(edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN2L)grid on

subplot(233)hold onhistf(RN3L Greedydiff0110facecolorbfacealpha5edgealpha1)histf(RN3L Finaldiff0110facecolorrfacealpha5edgealpha1)histf(RN3L Classicaldiff0110facecolorgfacealpha5edgealpha1)legalpha(ConminusGreClasminusConPerfminusClasslocationnortheast)legend boxoffaxis tightxlabel(edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN3L)grid on

subplot(234)hold onhistf(RN1S Greedydiff0110facecolorbfacealpha5edgealpha1)histf(RN1S Finaldiff0110facecolorrfacealpha5edgealpha1)histf(RN1S Classicaldiff0110facecolorgfacealpha5edgealpha1)legalpha(ConminusGreClasminusConPerfminusClasslocationnortheast)legend boxoffaxis tightxlabel(edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(R1NS)grid on

subplot(235)hold onhistf(RN2S Greedydiff0110facecolorbfacealpha5edgealpha1)histf(RN2S Finaldiff0110facecolorrfacealpha5edgealpha1)histf(RN2S Classicaldiff0110facecolorgfacealpha5edgealpha1)legalpha(ConminusGreClasminusConPerfminusClasslocationnortheast)legend boxoffaxis tightxlabel(edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN2S)grid on

subplot(236)hold onhistf(RN3S Greedydiff0110facecolorbfacealpha5edgealpha1)histf(RN3S Finaldiff0110facecolorrfacealpha5edgealpha1)histf(RN3S Classicaldiff0110facecolorgfacealpha5edgealpha1)

Appendix A 53

legalpha(ConminusGreClasminusConPerfminusClasslocationnortheast)legend boxoffaxis tightgrid ontitle(RN3S)xlabel(edges) xminusaxis labelylabel(instances) yminusaxis labelset(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN1png minusr300)h(2)=figure(NameHistogram of Max Degree of G AND G HatNumberTitleoff)RN1L x=RN1L MaxDegreeGminusRN1L MaxDegreeG HatRN2L x=RN2L MaxDegreeGminusRN2L MaxDegreeG HatRN3L x=RN3L MaxDegreeGminusRN3L MaxDegreeG HatRN1S x=RN1S MaxDegreeGminusRN1S MaxDegreeG HatRN2S x=RN2S MaxDegreeGminusRN2S MaxDegreeG HatRN3S x=RN3S MaxDegreeGminusRN3S MaxDegreeG Hatsubplot(231)hold onhistf(RN1L MaxDegreeG0150facecolorbfacealpha5edgealpha1)histf(RN1L MaxDegreeG Hat0150facecolorrfacealpha5edgealpha1)histf(RN1L x0150facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightxlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN1L)grid on

subplot(232)hold onhistf(RN2L MaxDegreeG010500facecolorbfacealpha5edgealpha1)histf(RN2L MaxDegreeG Hat010500facecolorrfacealpha5edgealpha1)histf(RN2L x010500facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightxlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN2L)grid on

subplot(233)hold onhistf(RN3L MaxDegreeG010300facecolorbfacealpha5edgealpha1)histf(RN3L MaxDegreeG Hat010300facecolorrfacealpha5edgealpha1)histf(RN3L x010300facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightxlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN3L)

54 Application

grid on

subplot(234)hold onhistf(RN1S MaxDegreeG0150facecolorbfacealpha5edgealpha1)histf(RN1S MaxDegreeG Hat0150facecolorrfacealpha5edgealpha1)histf(RN1S x0150facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightxlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(R1NS)grid on

subplot(235)hold onhistf(RN2S MaxDegreeG010500facecolorbfacealpha5edgealpha1)histf(RN2S MaxDegreeG Hat010500facecolorrfacealpha5edgealpha1)histf(RN2S x010500facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightxlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN2S)grid on

subplot(236)hold onhistf(RN3S MaxDegreeG05300facecolorbfacealpha5edgealpha1)histf(RN3S MaxDegreeG Hat05300facecolorrfacealpha5edgealpha1)histf(RN3S x05300facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightgrid ontitle(RN3S)xlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labelset(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN2png minusr300)

h(3)=figure(NameComputation time over edgesNumberTitleoff)

subplot(231)hold onstem(RN1L EdgesGRN1L Time classicalg)stem(RN1L EdgesGRN1L Time algorithmro)stem(RN1L EdgesGRN1L Time greedybx)grid on

Appendix A 55

title(RN1L)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)

subplot(232)hold onstem(RN2L EdgesGRN2L Time classicalg)stem(RN2L EdgesGRN2L Time algorithmro)stem(RN2L EdgesGRN2L Time greedybx)grid ontitle(RN2L)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)

subplot(233)hold onstem(RN3L EdgesGRN3L Time classicalg)stem(RN3L EdgesGRN3L Time algorithmro)stem(RN3L EdgesGRN3L Time greedybx)grid ontitle(RN3L)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)

subplot(234)hold onstem(RN1S EdgesGRN1S Time classicalg)stem(RN1S EdgesGRN1S Time algorithmro)stem(RN1S EdgesGRN1S Time greedybx)grid ontitle(RN1S)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)

subplot(235)hold onstem(RN2S EdgesGRN2S Time classicalg)stem(RN2S EdgesGRN2S Time algorithmro)stem(RN2S EdgesGRN2S Time greedybx)grid ontitle(RN2S)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)

subplot(236)hold onstem(RN3S EdgesGRN3S Time classicalg)stem(RN3S EdgesGRN3S Time algorithmro)stem(RN3S EdgesGRN3S Time greedybx)

56 Application

grid ontitle(RN3S)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)set(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN3png minusr300)

h(4)=figure(NameSorted matching sizeNumberTitleoff)RN1L Sorted matching temp(1)=RN1L Classical matchingRN1L Sorted matching temp(2)=RN1L Final matchingRN1L Sorted matching temp(3)=RN1L Greedy matchingRN1L Sorted matching temp(4)=RN1L Initial matchingRN1L Sorted matching=sortrows(RN1L Sorted matching temp)

RN2L Sorted matching temp(1)=RN2L Classical matchingRN2L Sorted matching temp(2)=RN2L Final matchingRN2L Sorted matching temp(3)=RN2L Greedy matchingRN2L Sorted matching temp(4)=RN2L Initial matchingRN2L Sorted matching=sortrows(RN2L Sorted matching temp)

RN3L Sorted matching temp(1)=RN3L Classical matchingRN3L Sorted matching temp(2)=RN3L Final matchingRN3L Sorted matching temp(3)=RN3L Greedy matchingRN3L Sorted matching temp(4)=RN3L Initial matchingRN3L Sorted matching=sortrows(RN3L Sorted matching temp)

RN1S Sorted matching temp(1)=RN1S Classical matchingRN1S Sorted matching temp(2)=RN1S Final matchingRN1S Sorted matching temp(3)=RN1S Greedy matchingRN1S Sorted matching temp(4)=RN1S Initial matchingRN1S Sorted matching=sortrows(RN1S Sorted matching temp)

RN2S Sorted matching temp(1)=RN2S Classical matchingRN2S Sorted matching temp(2)=RN2S Final matchingRN2S Sorted matching temp(3)=RN2S Greedy matchingRN2S Sorted matching temp(4)=RN2S Initial matchingRN2S Sorted matching=sortrows(RN2S Sorted matching temp)

RN3S Sorted matching temp(1)=RN3S Classical matchingRN3S Sorted matching temp(2)=RN3S Final matchingRN3S Sorted matching temp(3)=RN3S Greedy matchingRN3S Sorted matching temp(4)=RN3S Initial matchingRN3S Sorted matching=sortrows(RN3S Sorted matching temp)

subplot(231)hold onplot(RN1L Sorted matching(1)b)plot(RN1L Sorted matching(2)g)plot(RN1L Sorted matching(3)r)plot(RN1L Sorted matching(4)m)

Appendix A 57

grid ontitle(RN1L)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)

subplot(232)hold onplot(RN2L Sorted matching(1)b)plot(RN2L Sorted matching(2)g)plot(RN2L Sorted matching(3)r)plot(RN2L Sorted matching(4)m)grid ontitle(RN2L)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)

subplot(233)hold onplot(RN3L Sorted matching(1)b)plot(RN3L Sorted matching(2)g)plot(RN3L Sorted matching(3)r)plot(RN3L Sorted matching(4)m)grid ontitle(RN3L)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)

subplot(234)hold onplot(RN1S Sorted matching(1)b)plot(RN1S Sorted matching(2)g)plot(RN1S Sorted matching(3)r)plot(RN1S Sorted matching(4)m)grid ontitle(RN1S)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)

subplot(235)hold onplot(RN2S Sorted matching(1)b)plot(RN2S Sorted matching(2)g)plot(RN2S Sorted matching(3)r)plot(RN2S Sorted matching(4)m)grid ontitle(RN2S)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)

58 Application

subplot(236)hold onplot(RN3S Sorted matching(1)b)plot(RN3S Sorted matching(2)g)plot(RN3S Sorted matching(3)r)plot(RN3S Sorted matching(4)m)grid ontitle(RN3S)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)set(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN4png minusr300)h(5)=figure(NameSorted RatiosNumberTitleoff)RN1L ratio1=RN1L NodesG hatRN1L NodesGRN2L ratio1=RN2L NodesG hatRN2L NodesGRN3L ratio1=RN3L NodesG hatRN3L NodesGRN1S ratio1=RN1S NodesG hatRN1S NodesGRN2S ratio1=RN2S NodesG hatRN2S NodesGRN3S ratio1=RN3S NodesG hatRN3S NodesG

RN1L ratio2=RN1L EdgesG HatRN1L EdgesGRN2L ratio2=RN2L EdgesG HatRN2L EdgesGRN3L ratio2=RN3L EdgesG HatRN3L EdgesGRN1S ratio2=RN1S EdgesG HatRN1S EdgesGRN2S ratio2=RN2S EdgesG HatRN2S EdgesGRN3S ratio2=RN3S EdgesG HatRN3S EdgesG

RN1L ratio3=RN1L MaxDegreeG HatRN1L MaxDegreeGRN2L ratio3=RN2L MaxDegreeG HatRN2L MaxDegreeGRN3L ratio3=RN3L MaxDegreeG HatRN3L MaxDegreeGRN1S ratio3=RN1S MaxDegreeG HatRN1S MaxDegreeGRN2S ratio3=RN2S MaxDegreeG HatRN2S MaxDegreeGRN3S ratio3=RN3S MaxDegreeG HatRN3S MaxDegreeG

RN1L ratio(1)=RN1L ratio1RN1L ratio(2)=RN1L ratio2RN1L ratio(3)=RN1L ratio3

RN2L ratio(1)=RN2L ratio1RN2L ratio(2)=RN2L ratio2RN2L ratio(3)=RN2L ratio3

RN3L ratio(1)=RN3L ratio1RN3L ratio(2)=RN3L ratio2RN3L ratio(3)=RN3L ratio3

RN1S ratio(1)=RN1S ratio1RN1S ratio(2)=RN1S ratio2RN1S ratio(3)=RN1S ratio3

RN2S ratio(1)=RN2S ratio1

Appendix A 59

RN2S ratio(2)=RN2S ratio2RN2S ratio(3)=RN2S ratio3

RN3S ratio(1)=RN3S ratio1RN3S ratio(2)=RN3S ratio2RN3S ratio(3)=RN3S ratio3

RN1L ratio sorted=sortrows(RN1L ratio)RN2L ratio sorted=sortrows(RN2L ratio)RN3L ratio sorted=sortrows(RN3L ratio)RN1S ratio sorted=sortrows(RN1S ratio)RN2S ratio sorted=sortrows(RN2S ratio)RN3S ratio sorted=sortrows(RN3S ratio)

subplot(231)hold onplot(RN1L ratio sorted(1)b)plot(RN1L ratio sorted(2)g)plot(RN1L ratio sorted(3)r)grid ontitle(RN1L)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)

subplot(232)hold onplot(RN2L ratio sorted(1)b)plot(RN2L ratio sorted(2)g)plot(RN2L ratio sorted(3)r)grid ontitle(RN2L)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)

subplot(233)hold onplot(RN3L ratio sorted(1)b)plot(RN3L ratio sorted(2)g)plot(RN3L ratio sorted(3)r)grid ontitle(RN3L)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)

subplot(234)hold onplot(RN1S ratio sorted(1)b)plot(RN1S ratio sorted(2)g)plot(RN1S ratio sorted(3)r)grid on

60 Application

title(RN1S)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)

subplot(235)hold onplot(RN2S ratio sorted(1)b)plot(RN2S ratio sorted(2)g)plot(RN2S ratio sorted(3)r)grid ontitle(RN2S)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)

subplot(236)hold onplot(RN3S ratio sorted(1)b)plot(RN3S ratio sorted(2)g)plot(RN3S ratio sorted(3)r)grid ontitle(RN3S)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)set(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN5png minusr300)

h(6)=figure(NameSorted edges over nodesNumberTitleoff)

RN1L DegreeG1=(RN1L EdgesG)(RN1L NodesG)RN1L DegreeG Hat1=(RN1L EdgesG Hat)(RN1L NodesG hat)

RN1L Degree temp1(1)=RN1L DegreeG1RN1L Degree temp1(2)=RN1L DegreeG Hat1RN1L Degree sorted1=sortrows(RN1L Degree temp1)subplot(231)hold on

plot(RN1L Degree sorted1(1)b)plot(RN1L Degree sorted1(2)g)grid ontitle(RN1L)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)

RN2L DegreeG1=(RN2L EdgesG)(RN2L NodesG)RN2L DegreeG Hat1=(RN2L EdgesG Hat)(RN2L NodesG hat)

RN2L Degree temp1(1)=RN2L DegreeG1

Appendix A 61

RN2L Degree temp1(2)=RN2L DegreeG Hat1RN2L Degree sorted1=sortrows(RN2L Degree temp1)

subplot(232)hold onplot(RN2L Degree sorted1(1)b)plot(RN2L Degree sorted1(2)g)grid ontitle(RN2L)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)

RN3L DegreeG1=(RN3L EdgesG)(RN3L NodesG)RN3L DegreeG Hat1=(RN3L EdgesG Hat)(RN3L NodesG hat)

RN3L Degree temp1(1)=RN3L DegreeG1RN3L Degree temp1(2)=RN3L DegreeG Hat1RN3L Degree sorted1=sortrows(RN3L Degree temp1)

subplot(233)hold onplot(RN3L Degree sorted1(1)b)plot(RN3L Degree sorted1(2)g)grid ontitle(RN3L)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)

RN1S DegreeG1=(RN1S EdgesG)(RN1S NodesG)RN1S DegreeG Hat1=(RN1S EdgesG Hat)(RN1S NodesG hat)

RN1S Degree temp1(1)=RN1S DegreeG1RN1S Degree temp1(2)=RN1S DegreeG Hat1RN1S Degree sorted1=sortrows(RN1S Degree temp1)

subplot(234)hold onplot(RN1S Degree sorted1(1)b)plot(RN1S Degree sorted1(2)g)grid ontitle(RN1S)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)

RN2S DegreeG1=(RN2S EdgesG)(RN2S NodesG)RN2S DegreeG Hat1=(RN2S EdgesG Hat)(RN2S NodesG hat)

RN2S Degree temp1(1)=RN2S DegreeG1

62 Application

RN2S Degree temp1(2)=RN2S DegreeG Hat1RN2S Degree sorted1=sortrows(RN2S Degree temp1)

subplot(235)hold onplot(RN2S Degree sorted1(1)b)plot(RN2S Degree sorted1(2)g)grid ontitle(RN2S)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)

RN3S DegreeG1=(RN3S EdgesG)(RN3S NodesG)RN3S DegreeG Hat1=(RN3S EdgesG Hat)(RN3S NodesG hat)

RN3S Degree temp1(1)=RN3S DegreeG1RN3S Degree temp1(2)=RN3S DegreeG Hat1RN3S Degree sorted1=sortrows(RN3S Degree temp1)

subplot(236)hold onplot(RN3S Degree sorted1(1)b)plot(RN3S Degree sorted1(2)g)grid ontitle(RN3S)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)set(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN6png minusr300)h(7)=figure(NameSorted mATCHED DEGREENumberTitleoff)RN1L ratioMax(1)=RN1L MaxDegreeGRN1L ratioMax(2)=RN1L MaxDegreeG Hat

RN1L ratio sortedMax=sortrows(RN1L ratioMax)subplot(231)hold onplot(RN1L ratio sortedMax(1)b)plot(RN1L ratio sortedMax(2)g)grid ontitle(RN1L)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)

RN2L ratioMax(1)=RN2L MaxDegreeGRN2L ratioMax(2)=RN2L MaxDegreeG Hat

RN2L ratio sortedMax=sortrows(RN2L ratioMax)subplot(232)

Appendix A 63

hold onplot(RN2L ratio sortedMax(1)b)plot(RN2L ratio sortedMax(2)g)grid ontitle(RN2L)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)

RN3L ratioMax(1)=RN3L MaxDegreeGRN3L ratioMax(2)=RN3L MaxDegreeG Hat

RN3L ratio sortedMax=sortrows(RN3L ratioMax)subplot(233)hold onplot(RN3L ratio sortedMax(1)b)plot(RN3L ratio sortedMax(2)g)grid ontitle(RN3L)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)

RN1S ratioMax(1)=RN1S MaxDegreeGRN1S ratioMax(2)=RN1S MaxDegreeG Hat

RN1S ratio sortedMax=sortrows(RN1S ratioMax)subplot(234)hold onplot(RN1S ratio sortedMax(1)b)plot(RN1S ratio sortedMax(2)g)grid ontitle(RN1S)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)

RN2S ratioMax(1)=RN2S MaxDegreeGRN2S ratioMax(2)=RN2S MaxDegreeG Hat

RN2S ratio sortedMax=sortrows(RN2S ratioMax)

subplot(235)hold onplot(RN2S ratio sortedMax(1)b)plot(RN2S ratio sortedMax(2)g)grid ontitle(RN2S)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)

RN3S ratioMax(1)=RN3S MaxDegreeGRN3S ratioMax(2)=RN3S MaxDegreeG Hat

64 Application

RN3S ratio sortedMax=sortrows(RN3S ratioMax)subplot(236)hold onplot(RN3S ratio sortedMax(1)b)plot(RN3S ratio sortedMax(2)g)grid ontitle(RN1L)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)set(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN7png minusr300)

tilefigs()(h)

Bibliography

[1] C Berge ldquoTWO THEOREMS IN GRAPH THEORYrdquo Proceedings of the NationalAcademy of Sciences of the United States of America vol 43 no 9 pp 842ndash844Sep 1957

[2] L Bui S Sanghavi and R Srikant ldquoDistributed link scheduling with constantoverheadrdquo IEEEACM Trans Netw vol 17 no 5 pp 1467ndash1480 2009

[3] R Duan and S Pettie ldquoLinear-time approximation for maximum weight matchingrdquoJ ACM vol 61 no 1 2014

[4] J Edmonds ldquoPaths trees and flowersrdquo Canadian Journal of Mathematics vol 17pp 449ndash467 1965

[5] J E Hopcroft and R M Karp ldquoAn n52 algorithm for maximum matchings inbipartite graphsrdquo SIAM J Comput vol 2 no 4 pp 225ndash231 1973

[6] S Micali and V V Vazirani ldquoAn O(radic|V ||E|) algorithm for finding maximum

matching in general graphsrdquo in 21st Symp on Foundations of Comp Sc (FOCS)IEEE 1980 pp 17ndash27

[7] N Nisse A Salch and V Weber ldquoRecovery of disrupted airline operationsrdquo 2015httphalinriafrSomething

[8] X Wu and R Srikant ldquoRegulated maximal matching A distributed schedulingalgorithm for multi-hop wireless networks with nodeexclusive spectrum sharingrdquo inIEEE Conf on Decision and Control 2005

65

  • Contents
  • Introduction
  • Algorithms
    • Maximum matching
    • k-maximum matching
      • k-matching for Airport Slot assignment
      • The case where k=3
      • The case of Paths
      • The case of the Spider
          • Application
            • Description
            • Reyni Erdos
            • Barabaacutesi Albert
            • Amadeus Graphs
            • Bipartite
            • Bipartite with degree seq
            • Appendix A
              • BipartiteGraphGeneratorpy
              • RandomGraphGeneratorpy
              • kequals3MaximumMatchingpy
              • Plotmat
                  • Bibliography
Page 7: Theodoros Alexandros KARAGKIOULES -  · Introduction This work is the result of a 6 months internship, under the supervision of research O cer Nicolas NISSE. The original scope of

8 Algorithms

P1 P2 P3 A1 At QB1 Bf H Pr where augmenting only path Q oncecan lead to the equivalently optimal solution

Algorithm 2 Spider algorithm(SM)

1 M prime = M2 Let there be a set of leaves λ1 λr3 xk is the nn of C in the path C rarr λk4 for i isin 1 r do5 for j 6= i do M primeprime=Path Algorithm(λi rarr λjM)6 for k isin i j do M primeprime=M primeprimecupPath Algorithm(λk rarr xkM)7 end for8 end for9 if M primeprime gt M prime then10 M prime = M primeprime

11 end if12 end for13 return M prime

Proof Let there be an optimal solution that is obtained by the paths in the sequenceQprime = (P prime1 P

primer) for the spider

Let there also be a set of paths from leaf to leaf PLL = Pll1 P lln a set ofbranches BR = Br1 Brm and a sequence of augmenting paths Q = (P1 Pr)such that for j isin 1 r Pj isin PLL and forall i 6= j isin 1 r Pi isin BR

Applying the path algorithm for Pj and then for the r minus 1 paths of Q and due toTheorem 21 it is ensured that the matching produced will lead to a feasible solutionsince C is never exposed

Due to the iterative nature of the algorithm it can be checked that all possible com-binations of Pj and Pi that construct Q are considered and that one of the solutionscomputed as above will be the initial optimal solution Qprime

Thus by induction Spider Algorithm will always produce an optimal matching on aSpider

Chapter 2

Application

21 Description

This chapter aims at providing the picture of analysis on the data provided by Amadeusthe bipartite graphs and the random graphs generated

The random graphs have been generated as purely random graphs based on the ReyniErdos and the Barabasi Albert with different values of connectivity probability or con-nectivity

The bipartite graphs were generated on the density of the Amadeus graphs to simu-late better the results Additionally an extra set of test have been made on bipartitegraphs that simulate the degree distribution of the Amadeus graphs Certain classesof degree distribution were selected and based on those 480 bipartite graphs have beengenerated

At every graph the classical matching is computed based on the Edmonds algorithmthen the k-matching algorithm is used as described in section 122 Lastly a greedyalgorithm is implemented to be used for comparison

The ultimate goal is to explore the efficiency of the k-matching algorithm for the caseof k = 3 and to compare it with the result of the Edmonds algorithm and of course theGreedy implementationThe results follow along with some comments

9

10 Application

22 Reyni Erdos

bull RNxy are randomly generated graphs with a fixed number of 1000 nodes

bull There are 6 categories based on the initial matching and probability p of connection

bull x = L S L When the initial matching is large and S when it is small

bull y = 1 2 3 1 when p = lognn

2 when p = 13

and 3 when p = lognn

+ 01

Computation time over |E|

Computation time over |E| - Comments

bull This is a very straightforward set of figures

22 Reyni Erdos 11

bull When the initial matching is sufficiently large then the forced edges are taken out(a process which takes a fragment of the computation time) and then the classicalmatching algorithm (Edmonds) is applied on a smaller graph(G) This reducessignificantly the computation time

bull When the initial matching is small then the computation time of the constraintalgorithm might be larger than that of Edmonds The reason is that the constraintalgorithm need some time to compute the useless and forced edges and thenEdmonds algorithm is applied on G G Thus the overall processing time issometimes larger

Sorted matching size

Sorted matching size - Comments

12 Application

bull This set of figures represents the ascending order of the Classical matching sizealong with its corresponding Constraint and Greedy equivalent

bull When the probability is sufficiently higher than the threshold lognn

then the threealgorithms produce identical results of optimal matching

bull For lower probability there is a difference between the results of the algorithms

bull the degree of that difference is depicted in the first set of figures presented

bull It is interesting to observe that a change on the Constraint algorithm is associatedwith a even more significant change in the Greedy algorithm

bull There is a difference only when the probability is at the connectedness threshholdlognn

bull The difference is very small compared to the size of the matching ( 500)

bull The difference in matching size appears mostly at the Greedy implementationwhen compared to the constraint algorithm

Sorted Ratios

22 Reyni Erdos 13

Sorted Ratios - Comments

bull This set of figures depicts the ratios VV

EE

∆∆

in ascending order of VV

bull It is evident that when the initial matching is large the amount of forced edges(and their endpoints) removed is high thus the ratio of Nodes and edges is verylow For higher probabilities almost all edges are removed as useless

bull For a smaller initial matching almost no forced edges (and their endpoints) areremoved which we conclude be the node ration being close to 1 There is somesmall amount of useless edges removed though since the ratio of edges is less butclose to 1

bull The ratio of ∆ for large initial matching follows the trend of the node ratio yetfor smaller initial matching it deviates significantly

14 Application

Sorted |E||V |

Sorted |E||V | - Comments

bull Although as graph density the ratio 2|E||V |(|V |minus1)

is considered in this set of figures

we evaluate the correlation of the ratio |E||V | of G and G since the density of G

could acquire values higher than that of G

bull The figures are calculated in ascending order for the ratio of G

bull For the case of large initial matching the two ratios for G and G remain almostconstant ( to the extent of the probability of each graph) since removing forcededges( and their endpoints) alters the |E| and |V | proportionately

22 Reyni Erdos 15

bull For the case of small initial matching we observe some deviation in the valuesof the ration for G and that is explained with the removal of only useless edgeswhich only alters the |E| and keeps |V | in the original values

Sorted ∆

Sorted ∆-Comments

bull In this set of figures the ascending order of the ∆ of G is associated with the ∆of G

bull There is no significant jump of the ∆ for each graph category which tells that thatwe are comparing a uniform distribution of random grapghs for each probabilitycase

16 Application

bull For larger initial matching we observe the difference in the ∆s of G and G giventhe removed forced edges( and their endpoints) At some cases the ∆ of G dropsto 0 since the vast majority of edges have been declared forced and removed alongwith their endpoints

bull For smaller initial matching the ∆s of G and G follow mostly the same trend onlya few number of different instances

23 Barabasi Albert

Graph characteristics Barabasi Albert

bull BAxy are randomly generated graphs with a fixed number of 1000 nodes

bull There are 6 categories based on ini matching and of attached edges m

bull x = L S L When the initial matching is large and S when it is small

bull y = 1 2 3 1 when m = [1 10] 2 when m = [20 50] and 3 m = [50 100]

Computation time over |E|

23 Barabasi Albert 17

Computation time over |E| - Comments

bull When the initial matching is sufficiently large then the forced edges are taken out(a process which takes a fragment of the computation time) and then the classicalmatching algorithm (Edmonds) is applied on a smaller graph(G) This reducessignificantly the computation time

bull When the initial matching is small then the computation time of the constraintalgorithm might be larger than that of Edmonds The reason is that the constraintalgorithm need some time to compute the useless and forced edges and thenEdmonds algorithm is applied on G G Thus the overall processing time issometimes larger

Sorted matching size

18 Application

Sorted matching size-Comments

bull In this graph the matching size of the classical algorithm is depicted in ascendingorder along with the corresponding constraint algorithm and greedy result

bull Here in the case where m is small for both cases of initial matching (small large)the result may vary greatly starting from a value of half the perfect matching withsmall differences between the results of the various algorithm implementations

bull For the other cases of m the results converge

bull This is explained as for small values of m the graph is disconnected

bull In the matching size difference set of figures a very noticing difference value ap-pears For the cases of small m( the number of existing nodes that a new node isconnected to at the creation of the graph) we can see that the difference in the

23 Barabasi Albert 19

matching size compared to that of the perfect matching could be up to 40 ofthat of the matching size So there are occasions where the matching size is 200edges when the perfect matching would have been 500

bull the difference between the Constraint matching and the classical matching andthe difference of the constraint matching and that of the greedy matching do notshow significant values

Sorted Ratios

Sorted Ratio s -Comments

bull This set of figures depicts the ratios VV

EE

∆∆

in ascending order of VV

20 Application

bull It is evident that when the initial matching is large the amount of forced edges(and their endpoints) removed is high thus the ratio of Nodes and edges is verylow For higher probabilities almost all edges are removed as useless

bull For a smaller initial matching almost no forced edges (and their endpoints) areremoved which we conclude be the node ration being close to 1 There is somesmall amount of useless edges removed though since the ratio of edges is less butclose to 1

bull The ratio of ∆ for large initial matching follows the trend of the node ratio yetfor smaller initial matching it deviates significantly

Sorted |E||V |

23 Barabasi Albert 21

Sorted |E||V | - Comments

bull Although as graph density the ratio 2|E||V |(|V |minus1)

is considered in this set of figures

we evaluate the correlation of the ratio |E||V | of G and G since the density of G

could acquire values higher than that of G

bull The figures are calculated in ascending order for the ratio of G

bull For the case of large initial matching the two ratios for G and G remain almostconstant ( to the extent of the edge attraction m of each graph) since removingforced edges( and their endpoints) alters the |E| and |V | proportionately

bull For the case of small initial matching we observe some deviation in the valuesof the ration for G and that is explained with the removal of only useless edgeswhich only alters the |E| and keeps |V | in the original values

Sorted ∆

22 Application

Sorted ∆-Comments

bull In this set of figures the ascending order of the ∆ of G is associated with the ∆of G

bull There is a significant jump of the ∆ for each graph category which tells that thatwe are not comparing a uniform distribution of random graphs and based on theedge attraction m the graphs can vary in form

bull For larger initial matching we observe the difference in the ∆s of G and G giventhe removed forced edges( and their endpoints) At some cases the ∆ of G dropsto 0 since the vast majority of edges have been declared forced and removed alongwith their endpoints What is interesting is that the ∆ of G oscilates within stablelimits

24 Amadeus Graphs 23

bull For smaller initial matching the ∆s of G and G follow mostly the same trend onlya few number of different instances

24 Amadeus Graphs

Graph characteristics Amadeus graphs

bull These are the bipartite graphs provided by Amadeus

Computation time over |E|

Computation time over |E| - Comments

24 Application

bull For every instance the computation time of the classical algorithm is always smallerto that of the constraint matching

bull This allows as to speculate that we always compute a smaller G which also impliesthat we always find a set of forced edges and useless

Sorted matching size

Sorted matching size - Comments

bull Size of matching has an upward trend since the magnitude of the graphs is notthe same for the 160 instances

bull No significant deviation is noticed as per the first graph

24 Amadeus Graphs 25

bull Except from deviation from the perfect matching (number of flights) where some-times it could get up to 40

bull For the Amadeus Bipartite graphs we can see that the difference of the Classicaland the constraint implementation is not more than 1 edge in the matching

bull There appears to be a difference of up to 24 edges between the Classical matchingand the Perfect matching which is computed as the number of flights

bull The greedy algorithm performs well with only a few instances deviating slightlyform the Constraint algorithm result

Sorted Ratios

Sorted Ratios - Comments

26 Application

bull

Sorted |E||V |

Sorted |E||V | - Comments

bull Density of the graphs shows that on average we have 25-3 available time slot perflight

bull The line for the same value for G shows that there is a large deviation for everyinstance which allows for the hypothesis that the amount of useless+forced edgesof G has no obvious correlation to that of G

25 Bipartite 27

Sorted ∆

Sorted ∆-Comments

bull As per the previous related graphs for ∆ there is in significant drop in the ∆ of Gand G

25 Bipartite

Graph characteristics Bipartite random Graphs

bull BIPxy are randomly generated graphs with a fixed number of 1000(n=500 andm=500) nodes

bull There are 6 categories based on ini matching and probability p

28 Application

bull Probability p has been chosen as such in order to simulate the |E||V | 25 of theAmadeus bipartite graphs

bull So in order to have about 2-4 edges for every node we choose accordingly theprobability p to choose one of the n lowastm possible edges

bull x = L S L When the initial matching is large and S when it is small

bull y = 1 2 3 1 when p = 18250

2 when p = 25250

and 3 when p = 34250

Computation time over

Computation time overedges-Comments

bull

25 Bipartite 29

Sorted matching size

Sorted matching size-Comments

bull In these set of graphs one can instantly notice that only a few instances with highprobability can reach a matching size equal to the perfect matching

bull For the case of the initial matching we witness that there is a gap between the lineof the classical matching and those of the constraint and greedy results suggestingsmaller matching sizes of 10-40 edges

bull For the case of the small initial matching the result of the constraint matchingis now close to the result of the classical matching yet the greedy algorithm stillshows a relevantly big difference

30 Application

bull In this set of bipartite graphs we can witness that the result of the Constraintmatching shows a difference with the classical matching when the initial matchingis large The difference is smaller as the probability gets larger

bull For the case of the small initial matching the above phenomenom does not occuryet the greedy results deviates from that of the constraint matching

bull As per the pefrect matching compared to the classical matching a difference of5-10 edges is evident at almost all cases

Sorted Ratios

Sorted Ratios-Comments

bull Great max degree deviation

25 Bipartite 31

bull Regardless of the probability the ration of nodes and edges seems to have similarbehaviour when compared to the respective graphs of the same matching scale

bull Same gap between nodes ration and edges ration for all cases

Sorted |E||V |

Sorted |E||V | - Comments

bull In these set of figures we witness that the |E||V | acquires values relevant to those ofthe amadeus graphs The random graphs were constructed to depict this similarity

bull For smaller initial matching the ratios for G and G show the same upward trendand also they acquire closer values It represents the decrease of the averagenumber of forced edges in comparison to the larger matching cases

32 Application

Sorted ∆

Sorted ∆-Comments

bull ∆ acquires the same min and max values for each probability case (expected)

bull Gap in the case of large initial matching

26 Bipartite with degree seq

Graph characteristics

bull DEQBIPxy are randomly generated graphs based on three different types of degreedistribution of the Amadeus graphs

26 Bipartite with degree seq 33

bull There are 6 categories based on ini matching and degree distribution

bull x = L S L When the initial matching is large and S when it is small

bull y = 1 2 3 1 when degree distribution is based on file 2 when degree distributionis based on file and 3 when degree distribution is based on file

Computation time over

34 Application

Computation time overedges-Comments

bull Greedy algorithm takes minimum amount of time

bull The smaller the initial matching the more smaller the difference in comoutationtime of Constraint and classical algorithm

bull Due to preprocessing and the fact that G and G are the almost identical thetotal time needed to apply the constraint algorithm is in some cases bigger

Sorted matching size

26 Bipartite with degree seq 35

Sorted matching size-Comments

bull Classical matching is equal to perfect matching in every case

bull Constraint and greedy have identical behaviour

bull The larger the spectrum of the degree sequence the more efficient the matching

Sorted Ratios

36 Application

Sorted Ratios-Comments

bull With large initial matching most of the edges are considenred uselles or forced andare removed thus the ratio is close(if not equal to) zero

bull For small matching and large degree sequence sectrum hte max degree remainsthe same Only a few forced edges (and their nodes) are removed apparently nonodes with max degree

Sorted |E||V |

26 Bipartite with degree seq 37

Sorted |E||V | - Comments

bull In these set of figures we witness that the |E||V | acquires values relevant to those ofthe amadeus graphs The random graphs were constructed to depict this similarity

bull For smaller initial matching the ratios for G and G show the same upward trendand also they acquire closer values It repsresent the decrease of the averagenumber of forced edges in comparison to the larger matching cases

Sorted ∆

38 Application

Sorted ∆-Comments

bull Big difference in max degree in large initial matching

bull Almost identical behaviour in the case of small initial matching

Appendix A 39

Appendix A

BipartiteGraphGeneratorpy

from future import divisionimport networkx as nx

from networkxalgorithms import approximationimport collectionsimport randomimport mathfrom networkxalgorithms import bipartiteif name == main

for i in range(1481)waqs 481index=1n=randomrandint(100 1000)

n1=95 was 500me1=118

n2=251 was 500me2=903

n3=165 was 500me3=412

m=0m1=0p=randomrandom()p1=18250p2=25250p3=34250print ip=05t1=randomrandint(0 1)print im2=randomrandint(n2minus1 n2+1)G = nxGraph()ma = nxGraph()

aseq1=[1 2 3 4 5 3]

bseq1=[4 3 3 1 2 2 1]

aseq2=[16 14 14 14 12 11]bseq2=[0 0 0 0 0 0]

aseq3=[8 7 8 8 8 8]bseq3=[0 0 0 0 0 0]

40 Application

print Gnumber of edges()if ilt=160

G=bipartiteconfiguration model(aseq1 bseq1 create using=None seed=None)A=nxadjacency matrix(G)for ii in range(0n1+me1)

maadd node(ii)A=[Rtodense()tolist()[0] for R in A]

printnummanumber of nodes()rl=randomsample(range(0n1+me1) n1+me1)m=0done vertices = set()for p in rlprintin fordone verticesadd(p)

neighbors = []list()for iii in range(0n1+me1)

if A[p][iii]==1neighborsappend(iii)

randomshuffle(neighbors)continue loop = Truedegree = len(neighbors)

print degreej = 0p4=randomrandom()while continue loop and (jltdegree)print in loop

next = neighbors[j]if next not in done vertices and p not in done vertices

done verticesadd(p)done verticesadd(next)if p4gt=07print added edge

maadd edge(pnext)m=m+1

continue loop = Falsej += 1

print matching listOfedgeprint maedge

MA=nxadjacency matrix(ma)print MA

MA=[Rtodense()tolist()[0] for R in MA]print MA

B=[ join(map(strR)) for R in A]MB=[ join(map(strR)) for R in MA]

C=njoin(B)+nMC=njoin(MB)+n

print nprint mprint m1

filea=str(i)+txtwith open(fileaw) as f

Appendix A 41

fwrite(str(n1+me1))fwrite(n)fwrite(str(n1+me1))fwrite(n)fwrite(str(m))fwrite(n)fwrite(n)fwrite(C)fwrite(n)fwrite(MC)

elif igt160 and ilt321G=bipartiteconfiguration model(aseq2 bseq2 create using=None seed=None)A=nxadjacency matrix(G)for ii in range(0n2+me2)

maadd node(ii)A=[Rtodense()tolist()[0] for R in A]

printnummanumber of nodes()rl=randomsample(range(0n2+me2) n2+me2)m=0done vertices = set()for p in rlprintin fordone verticesadd(p)

neighbors = []list()for iii in range(0n2+me2)

if A[p][iii]==1neighborsappend(iii)

randomshuffle(neighbors)continue loop = Truedegree = len(neighbors)

print degreej = 0p4=randomrandom()while continue loop and (jltdegree)

print in loopnext = neighbors[j]if next not in done vertices and p not in done vertices

done verticesadd(p)done verticesadd(next)if p4gt=07

print added edgemaadd edge(pnext)m=m+1

continue loop = Falsej += 1

print matching listOfedgeprint maedge

MA=nxadjacency matrix(ma)print MA

MA=[Rtodense()tolist()[0] for R in MA]print MA

B=[ join(map(strR)) for R in A]MB=[ join(map(strR)) for R in MA]

42 Application

C=njoin(B)+nMC=njoin(MB)+n

print nprint mprint m1

filea=str(i)+txtwith open(fileaw) as f

fwrite(str(n2+me2))fwrite(n)fwrite(str(n2+me2))fwrite(n)fwrite(str(m))fwrite(n)fwrite(n)fwrite(C)fwrite(n)fwrite(MC)

elseG=bipartiteconfiguration model(aseq3 bseq3 create using=None seed=None)A=nxadjacency matrix(G)for ii in range(0n3+me3)

maadd node(ii)A=[Rtodense()tolist()[0] for R in A]

printnummanumber of nodes()rl=randomsample(range(0n3+me3) n3+me3)m=0done vertices = set()for p in rlprintin fordone verticesadd(p)

neighbors = []list()for iii in range(0n3+me3)

if A[p][iii]==1neighborsappend(iii)

randomshuffle(neighbors)continue loop = Truedegree = len(neighbors)

print degreej = 0p4=randomrandom()while continue loop and (jltdegree)

print in loopnext = neighbors[j]if next not in done vertices and p not in done vertices

done verticesadd(p)done verticesadd(next)if p4gt=07print added edge

maadd edge(pnext)m=m+1

continue loop = Falsej += 1

Appendix A 43

print matching listOfedgeprint maedge

MA=nxadjacency matrix(ma)print MA

MA=[Rtodense()tolist()[0] for R in MA]print MA

B=[ join(map(strR)) for R in A]MB=[ join(map(strR)) for R in MA]

C=njoin(B)+nMC=njoin(MB)+n

print nprint mprint m1

filea=str(i)+txtwith open(fileaw) as f

fwrite(str(n3+me3))fwrite(n)fwrite(str(n3+me3))fwrite(n)fwrite(str(m))fwrite(n)fwrite(n)fwrite(C)fwrite(n)fwrite(MC)

print nRandom graphs with random matching have been generated

44 Application

RandomGraphGeneratorpy

from future import divisionimport networkx as nxfrom networkxalgorithms import approximationimport collectionsimport randomimport mathif name == main

for i in range(1481)index=1n=randomrandint(100 1000)

n=1000m=0m1=0p=randomrandom()p1=mathlog(n2)np2=13p3=mathlog(n2)n+01p=05t1=randomrandint(0 1)print im2=randomrandint(n2minus1 n2+1)G = nxGraph()ma = nxGraph()print nme1=randomrandint(1 10)me2=randomrandint(2050)me3=randomrandint(50100)if ilt241

if ilt=80G=nxfast gnp random graph(n p1 seed=None directed=False)

elif igt80 and ilt161G=nxfast gnp random graph(n p2 seed=None directed=False)

elseG=nxfast gnp random graph(n p3 seed=None directed=False)

elseif ilt=320

G=nxbarabasi albert graph(n me1 seed=None)elif igt320 and ilt401

G=nxbarabasi albert graph(n me2 seed=None)else

G=nxbarabasi albert graph(n me3 seed=None)A=nxadjacency matrix(G)for ii in range(0n)

maadd node(ii)A=[Rtodense()tolist()[0] for R in A]

rl=randomsample(range(0n) n)m=0

Appendix A 45

done vertices = set()for p in rl

done verticesadd(p)neighbors = []list()for iii in range(0n)

if A[p][iii]==1neighborsappend(iii)

randomshuffle(neighbors)continue loop = Truedegree = len(neighbors)j = 0p2=randomrandom()while continue loop and (jltdegree)

next = neighbors[j]if next not in done vertices and p not in done vertices

done verticesadd(p)done verticesadd(next)if p2gt=00 Larger probability for smaller initial matching

maadd edge(pnext)m=m+1

continue loop = Falsej += 1

print matching listOfedgeprint maedgeMA=nxadjacency matrix(ma)MA=[Rtodense()tolist()[0] for R in MA]print MAB=[ join(map(strR)) for R in A]MB=[ join(map(strR)) for R in MA]

C=njoin(B)+nMC=njoin(MB)+nprint MCprint nprint mprint m1filea=str(i)+txtwith open(fileaw) as f

fwrite(str(n))fwrite(n)fwrite(str(n))fwrite(n)fwrite(str(m))fwrite(n)fwrite(n)fwrite(C)fwrite(n)fwrite(MC)

print nRandom graphs with random matching have been generated

46 Application

kequals3MaximumMatchingpy

from future import divisionimport networkx as nxfrom networkxalgorithms import bipartiteimport matplotlibpyplot as pltimport collectionsimport timeitimport xlwtimport xlrdimport mathimport sys

Case for General Graphsdef forced edges(Gadj dict2matching dict1num nodesforced)

flagg=0for n in range(0num nodes)

for k in adj dict2[n]if ([k]==matching dict1[n])

count=0for l in range(0num nodes)

count=count+adj dict2[l]count(k)if (len(adj dict2[n])==1) or (count==1)

forcedadd edge(nk)Gremove edge(nk)Gremove node(n)Gremove node(k)printforced edgenktemp=kflagg=1for m in range (len(adj dict2[n])minus1minus1minus1)

adj dict2[adj dict2[n][m]]remove(n)adj dict2[n]remove(adj dict2[n][m])

if adj dict2[temp]for l in range(len(adj dict2[temp])minus1minus1minus1)

if (adj dict2[temp][l]=n)adj dict2[adj dict2[temp][l]]remove(temp)adj dict2[temp]remove(adj dict2[temp][l])

break

def useless edges(num nodesadj dict1matching dict1uselessadj dict2G)for n in range(0num nodes)

for k in adj dict1[n]if ([k]=matching dict1[n]) and matching dict1[n] and matching dict1[k]

uselessadd edge(nk)Gremove edge(n k)

Appendix A 47

tempa=kadj dict2[n]remove(k)adj dict2[tempa]remove(n)adj dict1[tempa]remove(n)

return G

def Greedy(num nodesadj dict3matching dict2)

for n in range(0num nodes)if matching dict2[n]

flag2=minus1flag3=minus1for v in adj dict3[n]

if not matching dict2[v]flag2=vbreak

for p in adj dict3[matching dict2[n][0]]if not matching dict2[p]

flag3=pbreak

if (flag2=minus1) and (flag3=minus1) and (flag2=flag3)tempr=matching dict2[n][0]matching dict2[n]=[flag2]matching dict2[flag2]=[n]matching dict2[tempr]=[flag3]matching dict2[flag3]=[tempr]

elsefor k in adj dict3[n]

if not matching dict2[k]matching dict2[n]=[k]matching dict2[k]=[n]break

yo1=0for i in range(0num nodes)

if matching dict2[i] and [i]==matching dict2[matching dict2[i][0]]yo1=yo1+1

greedy size=yo12return greedy size

def General()

INPUTSwb = xlwtWorkbook()ws = wbadd sheet(Results Random)book=xlrdopen workbook(filenames randomxls)

48 Application

style0 = xlwteasyxf(fontbold on)style1 = xlwteasyxf(num format str=0000)INPUTSwswrite(0 0File style0)wswrite(0 1 Nodesstyle0)wswrite(0 2 Initial matchingstyle0)wswrite(0 3 NodesGstyle0)wswrite(0 4 EdgesGstyle0)wswrite(0 5 MaxDegreeGstyle0)wswrite(0 6 NodesG hatstyle0)wswrite(0 7 EdgesG Hatstyle0)wswrite(0 8 Useless edgesstyle0)wswrite(0 9 Forced edgesstyle0)wswrite(0 10 MaxDegreeG Hatstyle0)wswrite(0 11 Classical matchingstyle0)wswrite(0 12 Final matchingstyle0)wswrite(0 13 Greedy matchingstyle0)wswrite(0 14 Time classicalstyle0)wswrite(0 15 Time algorithmstyle0)wswrite(0 16 Time greedystyle0)wswrite(0 17 Perfect matching ratiostyle0)wswrite(0 18 Nodes ratiostyle0)wswrite(0 19 Edges ratiostyle0)wswrite(0 20 Matching ratiostyle0)

print nWelcomeThis is an implementation for general random graphs It uses Edmonds algorithm to compute maximum matching on G Hatn

for index in range (1481)was 481

if (index==482)f=open(Algotel generaltxtr)readlines()

elsefilea=str(booksheet by index(0)cell(index0))s=fileareplace(textu)replace()f=open(sr)readlines()Truewswrite(index 0 s)

print index

num nodes=int([xstrip()split() for x in f][0][0])

num matching=int([xstrip()split() for x in f][2][0])

adj temp = [xstrip()split() for x in f][44+num nodes]adj=[map(intR) for R in adj temp]

matching temp=[xstrip()split() for x in f][4+num nodes+14+2num nodes+1]matching1=[map(intR) for R in matching temp]

adj dict1=i[ii for iix in enumerate(L) if x] for iL in enumerate(adj)adj dict2=i[ii for iix in enumerate(L) if x] for iL in enumerate(adj)

Appendix A 49

adj dict3=i[ii for iix in enumerate(L) if x] for iL in enumerate(adj)

matching dict1=i[ii for iix in enumerate(L) if x] for iL in enumerate(matching1)matching dict2=i[ii for iix in enumerate(L) if x] for iL in enumerate(matching1)print adj dict2print matching dict2wswrite(index 1 num nodes)wswrite(index 2 num matching)

G = nxGraph()

useless= nxGraph()forced = nxGraph()

Fill Graphfor n in range(0num nodes)

for k in adj dict1[n]Gadd edge(nk)

Gt=Gnumber of edges()wswrite(index 3 Gnumber of nodes())wswrite(index 4 Gnumber of edges())wswrite(index 5 max(Gdegree()values()))

Compute Edmonds classical matching on G for comparison

startB = timeitdefault timer()Classical Matching=nxmax weight matching(G maxcardinality=False)stopB = timeitdefault timer()

Compute Gˆ nad MˆstartC = timeitdefault timer()useless edges(num nodesadj dict1matching dict1uselessadj dict2G)forced edges(Gadj dict2matching dict1num nodesforced)Final Matching=nxmax weight matching(G maxcardinality=False)stopC = timeitdefault timer()

GreedystartG = timeitdefault timer()greedy size=Greedy(num nodesadj dict3matching dict2)stopG = timeitdefault timer()

wswrite(index 6 Gnumber of nodes())wswrite(index 7 Gnumber of edges())wswrite(index 8 uselessnumber of edges())wswrite(index 9 forcednumber of edges())if Gdegree()values()

wswrite(index 10 max(Gdegree()values()))else

50 Application

wswrite(index 10 0)wswrite(index 11 len(Classical Matching)2)wswrite(index 12 len(Final Matching)2+forcednumber of edges())wswrite(index 13 greedy size)wswrite(index 14 stopB minus startBstyle1)wswrite(index 15 stopC minus startCstyle1)wswrite(index 16 stopG minus startGstyle1)wswrite(index 17 (len(Final Matching)2+forcednumber of edges())(num nodes2)style1)wswrite(index 18 Gnumber of nodes()Gtstyle1)wswrite(index 19 Gnumber of edges()Gtstyle1)wswrite(index 20 (len(Final Matching)2+forcednumber of edges())(len(Classical Matching)2)style1)

wbsave(AA Results Random Reyni Large Bipartitexls)

Main function Here we must choose the input form of the dataif name == main

startA = timeitdefault timer()General()stopA = timeitdefault timer()

print nThis program has terminatednnRunning time for 480 files stopAminusstartAprint nnPlease open AA Results Random Reyni Largexls file to see the Results

Appendix A 51

Plotmat

clear allclose allload(RN1Lmat)load(RN1Smat)load(RN2Lmat)load(RN2Smat)load(RN3Lmat)load(RN3Smat)

Plotsh(1)=figure(NameHistogram of Matching size difference between Constraint Algorithm and Greedy AlgorithmNumberTitleoff)

RN1L Greedydiff=RN1L Final matchingminusRN1L Greedy matchingRN2L Greedydiff=RN2L Final matchingminusRN2L Greedy matchingRN3L Greedydiff=RN3L Final matchingminusRN3L Greedy matchingRN1S Greedydiff=RN1S Final matchingminusRN1S Greedy matchingRN2S Greedydiff=RN2S Final matchingminusRN2S Greedy matchingRN3S Greedydiff=RN3S Final matchingminusRN3S Greedy matching

RN1L Finaldiff=RN1L Classical matchingminusRN1L Final matchingRN2L Finaldiff=RN2L Classical matchingminusRN2L Final matchingRN3L Finaldiff=RN3L Classical matchingminusRN3L Final matchingRN1S Finaldiff=RN1S Classical matchingminusRN1S Final matchingRN2S Finaldiff=RN2S Classical matchingminusRN2S Final matchingRN3S Finaldiff=RN3S Classical matchingminusRN3S Final matching

RN1L Classicaldiff=(RN1L Nodes2)minusRN1L Classical matchingRN2L Classicaldiff=(RN2L Nodes2)minusRN2L Classical matchingRN3L Classicaldiff=(RN3L Nodes2)minusRN3L Classical matchingRN1S Classicaldiff=(RN1S Nodes2)minusRN1S Classical matchingRN2S Classicaldiff=(RN2S Nodes2)minusRN2S Classical matchingRN3S Classicaldiff=(RN3S Nodes2)minusRN3S Classical matching

subplot(231)hold onhistf(RN1L Greedydiff0110facecolorbfacealpha9edgealpha1)histf(RN1L Finaldiff0110facecolorrfacealpha5edgealpha1)histf(RN1L Classicaldiff0110facecolorgfacealpha5edgealpha1)legalpha(ConminusGreClasminusConPerfminusClasslocationnortheast)legend boxoffaxis tightxlabel(edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN1L)grid on

subplot(232)hold onhistf(RN2L Greedydiff0110facecolorbfacealpha9edgealpha1)

52 Application

histf(RN2L Finaldiff0110facecolorrfacealpha5edgealpha1)histf(RN2L Classicaldiff0110facecolorgfacealpha5edgealpha1)legalpha(ConminusGreClasminusConPerfminusClasslocationnortheast)legend boxoffaxis tightxlabel(edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN2L)grid on

subplot(233)hold onhistf(RN3L Greedydiff0110facecolorbfacealpha5edgealpha1)histf(RN3L Finaldiff0110facecolorrfacealpha5edgealpha1)histf(RN3L Classicaldiff0110facecolorgfacealpha5edgealpha1)legalpha(ConminusGreClasminusConPerfminusClasslocationnortheast)legend boxoffaxis tightxlabel(edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN3L)grid on

subplot(234)hold onhistf(RN1S Greedydiff0110facecolorbfacealpha5edgealpha1)histf(RN1S Finaldiff0110facecolorrfacealpha5edgealpha1)histf(RN1S Classicaldiff0110facecolorgfacealpha5edgealpha1)legalpha(ConminusGreClasminusConPerfminusClasslocationnortheast)legend boxoffaxis tightxlabel(edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(R1NS)grid on

subplot(235)hold onhistf(RN2S Greedydiff0110facecolorbfacealpha5edgealpha1)histf(RN2S Finaldiff0110facecolorrfacealpha5edgealpha1)histf(RN2S Classicaldiff0110facecolorgfacealpha5edgealpha1)legalpha(ConminusGreClasminusConPerfminusClasslocationnortheast)legend boxoffaxis tightxlabel(edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN2S)grid on

subplot(236)hold onhistf(RN3S Greedydiff0110facecolorbfacealpha5edgealpha1)histf(RN3S Finaldiff0110facecolorrfacealpha5edgealpha1)histf(RN3S Classicaldiff0110facecolorgfacealpha5edgealpha1)

Appendix A 53

legalpha(ConminusGreClasminusConPerfminusClasslocationnortheast)legend boxoffaxis tightgrid ontitle(RN3S)xlabel(edges) xminusaxis labelylabel(instances) yminusaxis labelset(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN1png minusr300)h(2)=figure(NameHistogram of Max Degree of G AND G HatNumberTitleoff)RN1L x=RN1L MaxDegreeGminusRN1L MaxDegreeG HatRN2L x=RN2L MaxDegreeGminusRN2L MaxDegreeG HatRN3L x=RN3L MaxDegreeGminusRN3L MaxDegreeG HatRN1S x=RN1S MaxDegreeGminusRN1S MaxDegreeG HatRN2S x=RN2S MaxDegreeGminusRN2S MaxDegreeG HatRN3S x=RN3S MaxDegreeGminusRN3S MaxDegreeG Hatsubplot(231)hold onhistf(RN1L MaxDegreeG0150facecolorbfacealpha5edgealpha1)histf(RN1L MaxDegreeG Hat0150facecolorrfacealpha5edgealpha1)histf(RN1L x0150facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightxlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN1L)grid on

subplot(232)hold onhistf(RN2L MaxDegreeG010500facecolorbfacealpha5edgealpha1)histf(RN2L MaxDegreeG Hat010500facecolorrfacealpha5edgealpha1)histf(RN2L x010500facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightxlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN2L)grid on

subplot(233)hold onhistf(RN3L MaxDegreeG010300facecolorbfacealpha5edgealpha1)histf(RN3L MaxDegreeG Hat010300facecolorrfacealpha5edgealpha1)histf(RN3L x010300facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightxlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN3L)

54 Application

grid on

subplot(234)hold onhistf(RN1S MaxDegreeG0150facecolorbfacealpha5edgealpha1)histf(RN1S MaxDegreeG Hat0150facecolorrfacealpha5edgealpha1)histf(RN1S x0150facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightxlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(R1NS)grid on

subplot(235)hold onhistf(RN2S MaxDegreeG010500facecolorbfacealpha5edgealpha1)histf(RN2S MaxDegreeG Hat010500facecolorrfacealpha5edgealpha1)histf(RN2S x010500facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightxlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN2S)grid on

subplot(236)hold onhistf(RN3S MaxDegreeG05300facecolorbfacealpha5edgealpha1)histf(RN3S MaxDegreeG Hat05300facecolorrfacealpha5edgealpha1)histf(RN3S x05300facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightgrid ontitle(RN3S)xlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labelset(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN2png minusr300)

h(3)=figure(NameComputation time over edgesNumberTitleoff)

subplot(231)hold onstem(RN1L EdgesGRN1L Time classicalg)stem(RN1L EdgesGRN1L Time algorithmro)stem(RN1L EdgesGRN1L Time greedybx)grid on

Appendix A 55

title(RN1L)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)

subplot(232)hold onstem(RN2L EdgesGRN2L Time classicalg)stem(RN2L EdgesGRN2L Time algorithmro)stem(RN2L EdgesGRN2L Time greedybx)grid ontitle(RN2L)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)

subplot(233)hold onstem(RN3L EdgesGRN3L Time classicalg)stem(RN3L EdgesGRN3L Time algorithmro)stem(RN3L EdgesGRN3L Time greedybx)grid ontitle(RN3L)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)

subplot(234)hold onstem(RN1S EdgesGRN1S Time classicalg)stem(RN1S EdgesGRN1S Time algorithmro)stem(RN1S EdgesGRN1S Time greedybx)grid ontitle(RN1S)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)

subplot(235)hold onstem(RN2S EdgesGRN2S Time classicalg)stem(RN2S EdgesGRN2S Time algorithmro)stem(RN2S EdgesGRN2S Time greedybx)grid ontitle(RN2S)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)

subplot(236)hold onstem(RN3S EdgesGRN3S Time classicalg)stem(RN3S EdgesGRN3S Time algorithmro)stem(RN3S EdgesGRN3S Time greedybx)

56 Application

grid ontitle(RN3S)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)set(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN3png minusr300)

h(4)=figure(NameSorted matching sizeNumberTitleoff)RN1L Sorted matching temp(1)=RN1L Classical matchingRN1L Sorted matching temp(2)=RN1L Final matchingRN1L Sorted matching temp(3)=RN1L Greedy matchingRN1L Sorted matching temp(4)=RN1L Initial matchingRN1L Sorted matching=sortrows(RN1L Sorted matching temp)

RN2L Sorted matching temp(1)=RN2L Classical matchingRN2L Sorted matching temp(2)=RN2L Final matchingRN2L Sorted matching temp(3)=RN2L Greedy matchingRN2L Sorted matching temp(4)=RN2L Initial matchingRN2L Sorted matching=sortrows(RN2L Sorted matching temp)

RN3L Sorted matching temp(1)=RN3L Classical matchingRN3L Sorted matching temp(2)=RN3L Final matchingRN3L Sorted matching temp(3)=RN3L Greedy matchingRN3L Sorted matching temp(4)=RN3L Initial matchingRN3L Sorted matching=sortrows(RN3L Sorted matching temp)

RN1S Sorted matching temp(1)=RN1S Classical matchingRN1S Sorted matching temp(2)=RN1S Final matchingRN1S Sorted matching temp(3)=RN1S Greedy matchingRN1S Sorted matching temp(4)=RN1S Initial matchingRN1S Sorted matching=sortrows(RN1S Sorted matching temp)

RN2S Sorted matching temp(1)=RN2S Classical matchingRN2S Sorted matching temp(2)=RN2S Final matchingRN2S Sorted matching temp(3)=RN2S Greedy matchingRN2S Sorted matching temp(4)=RN2S Initial matchingRN2S Sorted matching=sortrows(RN2S Sorted matching temp)

RN3S Sorted matching temp(1)=RN3S Classical matchingRN3S Sorted matching temp(2)=RN3S Final matchingRN3S Sorted matching temp(3)=RN3S Greedy matchingRN3S Sorted matching temp(4)=RN3S Initial matchingRN3S Sorted matching=sortrows(RN3S Sorted matching temp)

subplot(231)hold onplot(RN1L Sorted matching(1)b)plot(RN1L Sorted matching(2)g)plot(RN1L Sorted matching(3)r)plot(RN1L Sorted matching(4)m)

Appendix A 57

grid ontitle(RN1L)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)

subplot(232)hold onplot(RN2L Sorted matching(1)b)plot(RN2L Sorted matching(2)g)plot(RN2L Sorted matching(3)r)plot(RN2L Sorted matching(4)m)grid ontitle(RN2L)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)

subplot(233)hold onplot(RN3L Sorted matching(1)b)plot(RN3L Sorted matching(2)g)plot(RN3L Sorted matching(3)r)plot(RN3L Sorted matching(4)m)grid ontitle(RN3L)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)

subplot(234)hold onplot(RN1S Sorted matching(1)b)plot(RN1S Sorted matching(2)g)plot(RN1S Sorted matching(3)r)plot(RN1S Sorted matching(4)m)grid ontitle(RN1S)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)

subplot(235)hold onplot(RN2S Sorted matching(1)b)plot(RN2S Sorted matching(2)g)plot(RN2S Sorted matching(3)r)plot(RN2S Sorted matching(4)m)grid ontitle(RN2S)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)

58 Application

subplot(236)hold onplot(RN3S Sorted matching(1)b)plot(RN3S Sorted matching(2)g)plot(RN3S Sorted matching(3)r)plot(RN3S Sorted matching(4)m)grid ontitle(RN3S)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)set(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN4png minusr300)h(5)=figure(NameSorted RatiosNumberTitleoff)RN1L ratio1=RN1L NodesG hatRN1L NodesGRN2L ratio1=RN2L NodesG hatRN2L NodesGRN3L ratio1=RN3L NodesG hatRN3L NodesGRN1S ratio1=RN1S NodesG hatRN1S NodesGRN2S ratio1=RN2S NodesG hatRN2S NodesGRN3S ratio1=RN3S NodesG hatRN3S NodesG

RN1L ratio2=RN1L EdgesG HatRN1L EdgesGRN2L ratio2=RN2L EdgesG HatRN2L EdgesGRN3L ratio2=RN3L EdgesG HatRN3L EdgesGRN1S ratio2=RN1S EdgesG HatRN1S EdgesGRN2S ratio2=RN2S EdgesG HatRN2S EdgesGRN3S ratio2=RN3S EdgesG HatRN3S EdgesG

RN1L ratio3=RN1L MaxDegreeG HatRN1L MaxDegreeGRN2L ratio3=RN2L MaxDegreeG HatRN2L MaxDegreeGRN3L ratio3=RN3L MaxDegreeG HatRN3L MaxDegreeGRN1S ratio3=RN1S MaxDegreeG HatRN1S MaxDegreeGRN2S ratio3=RN2S MaxDegreeG HatRN2S MaxDegreeGRN3S ratio3=RN3S MaxDegreeG HatRN3S MaxDegreeG

RN1L ratio(1)=RN1L ratio1RN1L ratio(2)=RN1L ratio2RN1L ratio(3)=RN1L ratio3

RN2L ratio(1)=RN2L ratio1RN2L ratio(2)=RN2L ratio2RN2L ratio(3)=RN2L ratio3

RN3L ratio(1)=RN3L ratio1RN3L ratio(2)=RN3L ratio2RN3L ratio(3)=RN3L ratio3

RN1S ratio(1)=RN1S ratio1RN1S ratio(2)=RN1S ratio2RN1S ratio(3)=RN1S ratio3

RN2S ratio(1)=RN2S ratio1

Appendix A 59

RN2S ratio(2)=RN2S ratio2RN2S ratio(3)=RN2S ratio3

RN3S ratio(1)=RN3S ratio1RN3S ratio(2)=RN3S ratio2RN3S ratio(3)=RN3S ratio3

RN1L ratio sorted=sortrows(RN1L ratio)RN2L ratio sorted=sortrows(RN2L ratio)RN3L ratio sorted=sortrows(RN3L ratio)RN1S ratio sorted=sortrows(RN1S ratio)RN2S ratio sorted=sortrows(RN2S ratio)RN3S ratio sorted=sortrows(RN3S ratio)

subplot(231)hold onplot(RN1L ratio sorted(1)b)plot(RN1L ratio sorted(2)g)plot(RN1L ratio sorted(3)r)grid ontitle(RN1L)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)

subplot(232)hold onplot(RN2L ratio sorted(1)b)plot(RN2L ratio sorted(2)g)plot(RN2L ratio sorted(3)r)grid ontitle(RN2L)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)

subplot(233)hold onplot(RN3L ratio sorted(1)b)plot(RN3L ratio sorted(2)g)plot(RN3L ratio sorted(3)r)grid ontitle(RN3L)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)

subplot(234)hold onplot(RN1S ratio sorted(1)b)plot(RN1S ratio sorted(2)g)plot(RN1S ratio sorted(3)r)grid on

60 Application

title(RN1S)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)

subplot(235)hold onplot(RN2S ratio sorted(1)b)plot(RN2S ratio sorted(2)g)plot(RN2S ratio sorted(3)r)grid ontitle(RN2S)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)

subplot(236)hold onplot(RN3S ratio sorted(1)b)plot(RN3S ratio sorted(2)g)plot(RN3S ratio sorted(3)r)grid ontitle(RN3S)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)set(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN5png minusr300)

h(6)=figure(NameSorted edges over nodesNumberTitleoff)

RN1L DegreeG1=(RN1L EdgesG)(RN1L NodesG)RN1L DegreeG Hat1=(RN1L EdgesG Hat)(RN1L NodesG hat)

RN1L Degree temp1(1)=RN1L DegreeG1RN1L Degree temp1(2)=RN1L DegreeG Hat1RN1L Degree sorted1=sortrows(RN1L Degree temp1)subplot(231)hold on

plot(RN1L Degree sorted1(1)b)plot(RN1L Degree sorted1(2)g)grid ontitle(RN1L)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)

RN2L DegreeG1=(RN2L EdgesG)(RN2L NodesG)RN2L DegreeG Hat1=(RN2L EdgesG Hat)(RN2L NodesG hat)

RN2L Degree temp1(1)=RN2L DegreeG1

Appendix A 61

RN2L Degree temp1(2)=RN2L DegreeG Hat1RN2L Degree sorted1=sortrows(RN2L Degree temp1)

subplot(232)hold onplot(RN2L Degree sorted1(1)b)plot(RN2L Degree sorted1(2)g)grid ontitle(RN2L)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)

RN3L DegreeG1=(RN3L EdgesG)(RN3L NodesG)RN3L DegreeG Hat1=(RN3L EdgesG Hat)(RN3L NodesG hat)

RN3L Degree temp1(1)=RN3L DegreeG1RN3L Degree temp1(2)=RN3L DegreeG Hat1RN3L Degree sorted1=sortrows(RN3L Degree temp1)

subplot(233)hold onplot(RN3L Degree sorted1(1)b)plot(RN3L Degree sorted1(2)g)grid ontitle(RN3L)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)

RN1S DegreeG1=(RN1S EdgesG)(RN1S NodesG)RN1S DegreeG Hat1=(RN1S EdgesG Hat)(RN1S NodesG hat)

RN1S Degree temp1(1)=RN1S DegreeG1RN1S Degree temp1(2)=RN1S DegreeG Hat1RN1S Degree sorted1=sortrows(RN1S Degree temp1)

subplot(234)hold onplot(RN1S Degree sorted1(1)b)plot(RN1S Degree sorted1(2)g)grid ontitle(RN1S)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)

RN2S DegreeG1=(RN2S EdgesG)(RN2S NodesG)RN2S DegreeG Hat1=(RN2S EdgesG Hat)(RN2S NodesG hat)

RN2S Degree temp1(1)=RN2S DegreeG1

62 Application

RN2S Degree temp1(2)=RN2S DegreeG Hat1RN2S Degree sorted1=sortrows(RN2S Degree temp1)

subplot(235)hold onplot(RN2S Degree sorted1(1)b)plot(RN2S Degree sorted1(2)g)grid ontitle(RN2S)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)

RN3S DegreeG1=(RN3S EdgesG)(RN3S NodesG)RN3S DegreeG Hat1=(RN3S EdgesG Hat)(RN3S NodesG hat)

RN3S Degree temp1(1)=RN3S DegreeG1RN3S Degree temp1(2)=RN3S DegreeG Hat1RN3S Degree sorted1=sortrows(RN3S Degree temp1)

subplot(236)hold onplot(RN3S Degree sorted1(1)b)plot(RN3S Degree sorted1(2)g)grid ontitle(RN3S)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)set(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN6png minusr300)h(7)=figure(NameSorted mATCHED DEGREENumberTitleoff)RN1L ratioMax(1)=RN1L MaxDegreeGRN1L ratioMax(2)=RN1L MaxDegreeG Hat

RN1L ratio sortedMax=sortrows(RN1L ratioMax)subplot(231)hold onplot(RN1L ratio sortedMax(1)b)plot(RN1L ratio sortedMax(2)g)grid ontitle(RN1L)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)

RN2L ratioMax(1)=RN2L MaxDegreeGRN2L ratioMax(2)=RN2L MaxDegreeG Hat

RN2L ratio sortedMax=sortrows(RN2L ratioMax)subplot(232)

Appendix A 63

hold onplot(RN2L ratio sortedMax(1)b)plot(RN2L ratio sortedMax(2)g)grid ontitle(RN2L)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)

RN3L ratioMax(1)=RN3L MaxDegreeGRN3L ratioMax(2)=RN3L MaxDegreeG Hat

RN3L ratio sortedMax=sortrows(RN3L ratioMax)subplot(233)hold onplot(RN3L ratio sortedMax(1)b)plot(RN3L ratio sortedMax(2)g)grid ontitle(RN3L)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)

RN1S ratioMax(1)=RN1S MaxDegreeGRN1S ratioMax(2)=RN1S MaxDegreeG Hat

RN1S ratio sortedMax=sortrows(RN1S ratioMax)subplot(234)hold onplot(RN1S ratio sortedMax(1)b)plot(RN1S ratio sortedMax(2)g)grid ontitle(RN1S)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)

RN2S ratioMax(1)=RN2S MaxDegreeGRN2S ratioMax(2)=RN2S MaxDegreeG Hat

RN2S ratio sortedMax=sortrows(RN2S ratioMax)

subplot(235)hold onplot(RN2S ratio sortedMax(1)b)plot(RN2S ratio sortedMax(2)g)grid ontitle(RN2S)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)

RN3S ratioMax(1)=RN3S MaxDegreeGRN3S ratioMax(2)=RN3S MaxDegreeG Hat

64 Application

RN3S ratio sortedMax=sortrows(RN3S ratioMax)subplot(236)hold onplot(RN3S ratio sortedMax(1)b)plot(RN3S ratio sortedMax(2)g)grid ontitle(RN1L)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)set(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN7png minusr300)

tilefigs()(h)

Bibliography

[1] C Berge ldquoTWO THEOREMS IN GRAPH THEORYrdquo Proceedings of the NationalAcademy of Sciences of the United States of America vol 43 no 9 pp 842ndash844Sep 1957

[2] L Bui S Sanghavi and R Srikant ldquoDistributed link scheduling with constantoverheadrdquo IEEEACM Trans Netw vol 17 no 5 pp 1467ndash1480 2009

[3] R Duan and S Pettie ldquoLinear-time approximation for maximum weight matchingrdquoJ ACM vol 61 no 1 2014

[4] J Edmonds ldquoPaths trees and flowersrdquo Canadian Journal of Mathematics vol 17pp 449ndash467 1965

[5] J E Hopcroft and R M Karp ldquoAn n52 algorithm for maximum matchings inbipartite graphsrdquo SIAM J Comput vol 2 no 4 pp 225ndash231 1973

[6] S Micali and V V Vazirani ldquoAn O(radic|V ||E|) algorithm for finding maximum

matching in general graphsrdquo in 21st Symp on Foundations of Comp Sc (FOCS)IEEE 1980 pp 17ndash27

[7] N Nisse A Salch and V Weber ldquoRecovery of disrupted airline operationsrdquo 2015httphalinriafrSomething

[8] X Wu and R Srikant ldquoRegulated maximal matching A distributed schedulingalgorithm for multi-hop wireless networks with nodeexclusive spectrum sharingrdquo inIEEE Conf on Decision and Control 2005

65

  • Contents
  • Introduction
  • Algorithms
    • Maximum matching
    • k-maximum matching
      • k-matching for Airport Slot assignment
      • The case where k=3
      • The case of Paths
      • The case of the Spider
          • Application
            • Description
            • Reyni Erdos
            • Barabaacutesi Albert
            • Amadeus Graphs
            • Bipartite
            • Bipartite with degree seq
            • Appendix A
              • BipartiteGraphGeneratorpy
              • RandomGraphGeneratorpy
              • kequals3MaximumMatchingpy
              • Plotmat
                  • Bibliography
Page 8: Theodoros Alexandros KARAGKIOULES -  · Introduction This work is the result of a 6 months internship, under the supervision of research O cer Nicolas NISSE. The original scope of

Chapter 2

Application

21 Description

This chapter aims at providing the picture of analysis on the data provided by Amadeusthe bipartite graphs and the random graphs generated

The random graphs have been generated as purely random graphs based on the ReyniErdos and the Barabasi Albert with different values of connectivity probability or con-nectivity

The bipartite graphs were generated on the density of the Amadeus graphs to simu-late better the results Additionally an extra set of test have been made on bipartitegraphs that simulate the degree distribution of the Amadeus graphs Certain classesof degree distribution were selected and based on those 480 bipartite graphs have beengenerated

At every graph the classical matching is computed based on the Edmonds algorithmthen the k-matching algorithm is used as described in section 122 Lastly a greedyalgorithm is implemented to be used for comparison

The ultimate goal is to explore the efficiency of the k-matching algorithm for the caseof k = 3 and to compare it with the result of the Edmonds algorithm and of course theGreedy implementationThe results follow along with some comments

9

10 Application

22 Reyni Erdos

bull RNxy are randomly generated graphs with a fixed number of 1000 nodes

bull There are 6 categories based on the initial matching and probability p of connection

bull x = L S L When the initial matching is large and S when it is small

bull y = 1 2 3 1 when p = lognn

2 when p = 13

and 3 when p = lognn

+ 01

Computation time over |E|

Computation time over |E| - Comments

bull This is a very straightforward set of figures

22 Reyni Erdos 11

bull When the initial matching is sufficiently large then the forced edges are taken out(a process which takes a fragment of the computation time) and then the classicalmatching algorithm (Edmonds) is applied on a smaller graph(G) This reducessignificantly the computation time

bull When the initial matching is small then the computation time of the constraintalgorithm might be larger than that of Edmonds The reason is that the constraintalgorithm need some time to compute the useless and forced edges and thenEdmonds algorithm is applied on G G Thus the overall processing time issometimes larger

Sorted matching size

Sorted matching size - Comments

12 Application

bull This set of figures represents the ascending order of the Classical matching sizealong with its corresponding Constraint and Greedy equivalent

bull When the probability is sufficiently higher than the threshold lognn

then the threealgorithms produce identical results of optimal matching

bull For lower probability there is a difference between the results of the algorithms

bull the degree of that difference is depicted in the first set of figures presented

bull It is interesting to observe that a change on the Constraint algorithm is associatedwith a even more significant change in the Greedy algorithm

bull There is a difference only when the probability is at the connectedness threshholdlognn

bull The difference is very small compared to the size of the matching ( 500)

bull The difference in matching size appears mostly at the Greedy implementationwhen compared to the constraint algorithm

Sorted Ratios

22 Reyni Erdos 13

Sorted Ratios - Comments

bull This set of figures depicts the ratios VV

EE

∆∆

in ascending order of VV

bull It is evident that when the initial matching is large the amount of forced edges(and their endpoints) removed is high thus the ratio of Nodes and edges is verylow For higher probabilities almost all edges are removed as useless

bull For a smaller initial matching almost no forced edges (and their endpoints) areremoved which we conclude be the node ration being close to 1 There is somesmall amount of useless edges removed though since the ratio of edges is less butclose to 1

bull The ratio of ∆ for large initial matching follows the trend of the node ratio yetfor smaller initial matching it deviates significantly

14 Application

Sorted |E||V |

Sorted |E||V | - Comments

bull Although as graph density the ratio 2|E||V |(|V |minus1)

is considered in this set of figures

we evaluate the correlation of the ratio |E||V | of G and G since the density of G

could acquire values higher than that of G

bull The figures are calculated in ascending order for the ratio of G

bull For the case of large initial matching the two ratios for G and G remain almostconstant ( to the extent of the probability of each graph) since removing forcededges( and their endpoints) alters the |E| and |V | proportionately

22 Reyni Erdos 15

bull For the case of small initial matching we observe some deviation in the valuesof the ration for G and that is explained with the removal of only useless edgeswhich only alters the |E| and keeps |V | in the original values

Sorted ∆

Sorted ∆-Comments

bull In this set of figures the ascending order of the ∆ of G is associated with the ∆of G

bull There is no significant jump of the ∆ for each graph category which tells that thatwe are comparing a uniform distribution of random grapghs for each probabilitycase

16 Application

bull For larger initial matching we observe the difference in the ∆s of G and G giventhe removed forced edges( and their endpoints) At some cases the ∆ of G dropsto 0 since the vast majority of edges have been declared forced and removed alongwith their endpoints

bull For smaller initial matching the ∆s of G and G follow mostly the same trend onlya few number of different instances

23 Barabasi Albert

Graph characteristics Barabasi Albert

bull BAxy are randomly generated graphs with a fixed number of 1000 nodes

bull There are 6 categories based on ini matching and of attached edges m

bull x = L S L When the initial matching is large and S when it is small

bull y = 1 2 3 1 when m = [1 10] 2 when m = [20 50] and 3 m = [50 100]

Computation time over |E|

23 Barabasi Albert 17

Computation time over |E| - Comments

bull When the initial matching is sufficiently large then the forced edges are taken out(a process which takes a fragment of the computation time) and then the classicalmatching algorithm (Edmonds) is applied on a smaller graph(G) This reducessignificantly the computation time

bull When the initial matching is small then the computation time of the constraintalgorithm might be larger than that of Edmonds The reason is that the constraintalgorithm need some time to compute the useless and forced edges and thenEdmonds algorithm is applied on G G Thus the overall processing time issometimes larger

Sorted matching size

18 Application

Sorted matching size-Comments

bull In this graph the matching size of the classical algorithm is depicted in ascendingorder along with the corresponding constraint algorithm and greedy result

bull Here in the case where m is small for both cases of initial matching (small large)the result may vary greatly starting from a value of half the perfect matching withsmall differences between the results of the various algorithm implementations

bull For the other cases of m the results converge

bull This is explained as for small values of m the graph is disconnected

bull In the matching size difference set of figures a very noticing difference value ap-pears For the cases of small m( the number of existing nodes that a new node isconnected to at the creation of the graph) we can see that the difference in the

23 Barabasi Albert 19

matching size compared to that of the perfect matching could be up to 40 ofthat of the matching size So there are occasions where the matching size is 200edges when the perfect matching would have been 500

bull the difference between the Constraint matching and the classical matching andthe difference of the constraint matching and that of the greedy matching do notshow significant values

Sorted Ratios

Sorted Ratio s -Comments

bull This set of figures depicts the ratios VV

EE

∆∆

in ascending order of VV

20 Application

bull It is evident that when the initial matching is large the amount of forced edges(and their endpoints) removed is high thus the ratio of Nodes and edges is verylow For higher probabilities almost all edges are removed as useless

bull For a smaller initial matching almost no forced edges (and their endpoints) areremoved which we conclude be the node ration being close to 1 There is somesmall amount of useless edges removed though since the ratio of edges is less butclose to 1

bull The ratio of ∆ for large initial matching follows the trend of the node ratio yetfor smaller initial matching it deviates significantly

Sorted |E||V |

23 Barabasi Albert 21

Sorted |E||V | - Comments

bull Although as graph density the ratio 2|E||V |(|V |minus1)

is considered in this set of figures

we evaluate the correlation of the ratio |E||V | of G and G since the density of G

could acquire values higher than that of G

bull The figures are calculated in ascending order for the ratio of G

bull For the case of large initial matching the two ratios for G and G remain almostconstant ( to the extent of the edge attraction m of each graph) since removingforced edges( and their endpoints) alters the |E| and |V | proportionately

bull For the case of small initial matching we observe some deviation in the valuesof the ration for G and that is explained with the removal of only useless edgeswhich only alters the |E| and keeps |V | in the original values

Sorted ∆

22 Application

Sorted ∆-Comments

bull In this set of figures the ascending order of the ∆ of G is associated with the ∆of G

bull There is a significant jump of the ∆ for each graph category which tells that thatwe are not comparing a uniform distribution of random graphs and based on theedge attraction m the graphs can vary in form

bull For larger initial matching we observe the difference in the ∆s of G and G giventhe removed forced edges( and their endpoints) At some cases the ∆ of G dropsto 0 since the vast majority of edges have been declared forced and removed alongwith their endpoints What is interesting is that the ∆ of G oscilates within stablelimits

24 Amadeus Graphs 23

bull For smaller initial matching the ∆s of G and G follow mostly the same trend onlya few number of different instances

24 Amadeus Graphs

Graph characteristics Amadeus graphs

bull These are the bipartite graphs provided by Amadeus

Computation time over |E|

Computation time over |E| - Comments

24 Application

bull For every instance the computation time of the classical algorithm is always smallerto that of the constraint matching

bull This allows as to speculate that we always compute a smaller G which also impliesthat we always find a set of forced edges and useless

Sorted matching size

Sorted matching size - Comments

bull Size of matching has an upward trend since the magnitude of the graphs is notthe same for the 160 instances

bull No significant deviation is noticed as per the first graph

24 Amadeus Graphs 25

bull Except from deviation from the perfect matching (number of flights) where some-times it could get up to 40

bull For the Amadeus Bipartite graphs we can see that the difference of the Classicaland the constraint implementation is not more than 1 edge in the matching

bull There appears to be a difference of up to 24 edges between the Classical matchingand the Perfect matching which is computed as the number of flights

bull The greedy algorithm performs well with only a few instances deviating slightlyform the Constraint algorithm result

Sorted Ratios

Sorted Ratios - Comments

26 Application

bull

Sorted |E||V |

Sorted |E||V | - Comments

bull Density of the graphs shows that on average we have 25-3 available time slot perflight

bull The line for the same value for G shows that there is a large deviation for everyinstance which allows for the hypothesis that the amount of useless+forced edgesof G has no obvious correlation to that of G

25 Bipartite 27

Sorted ∆

Sorted ∆-Comments

bull As per the previous related graphs for ∆ there is in significant drop in the ∆ of Gand G

25 Bipartite

Graph characteristics Bipartite random Graphs

bull BIPxy are randomly generated graphs with a fixed number of 1000(n=500 andm=500) nodes

bull There are 6 categories based on ini matching and probability p

28 Application

bull Probability p has been chosen as such in order to simulate the |E||V | 25 of theAmadeus bipartite graphs

bull So in order to have about 2-4 edges for every node we choose accordingly theprobability p to choose one of the n lowastm possible edges

bull x = L S L When the initial matching is large and S when it is small

bull y = 1 2 3 1 when p = 18250

2 when p = 25250

and 3 when p = 34250

Computation time over

Computation time overedges-Comments

bull

25 Bipartite 29

Sorted matching size

Sorted matching size-Comments

bull In these set of graphs one can instantly notice that only a few instances with highprobability can reach a matching size equal to the perfect matching

bull For the case of the initial matching we witness that there is a gap between the lineof the classical matching and those of the constraint and greedy results suggestingsmaller matching sizes of 10-40 edges

bull For the case of the small initial matching the result of the constraint matchingis now close to the result of the classical matching yet the greedy algorithm stillshows a relevantly big difference

30 Application

bull In this set of bipartite graphs we can witness that the result of the Constraintmatching shows a difference with the classical matching when the initial matchingis large The difference is smaller as the probability gets larger

bull For the case of the small initial matching the above phenomenom does not occuryet the greedy results deviates from that of the constraint matching

bull As per the pefrect matching compared to the classical matching a difference of5-10 edges is evident at almost all cases

Sorted Ratios

Sorted Ratios-Comments

bull Great max degree deviation

25 Bipartite 31

bull Regardless of the probability the ration of nodes and edges seems to have similarbehaviour when compared to the respective graphs of the same matching scale

bull Same gap between nodes ration and edges ration for all cases

Sorted |E||V |

Sorted |E||V | - Comments

bull In these set of figures we witness that the |E||V | acquires values relevant to those ofthe amadeus graphs The random graphs were constructed to depict this similarity

bull For smaller initial matching the ratios for G and G show the same upward trendand also they acquire closer values It represents the decrease of the averagenumber of forced edges in comparison to the larger matching cases

32 Application

Sorted ∆

Sorted ∆-Comments

bull ∆ acquires the same min and max values for each probability case (expected)

bull Gap in the case of large initial matching

26 Bipartite with degree seq

Graph characteristics

bull DEQBIPxy are randomly generated graphs based on three different types of degreedistribution of the Amadeus graphs

26 Bipartite with degree seq 33

bull There are 6 categories based on ini matching and degree distribution

bull x = L S L When the initial matching is large and S when it is small

bull y = 1 2 3 1 when degree distribution is based on file 2 when degree distributionis based on file and 3 when degree distribution is based on file

Computation time over

34 Application

Computation time overedges-Comments

bull Greedy algorithm takes minimum amount of time

bull The smaller the initial matching the more smaller the difference in comoutationtime of Constraint and classical algorithm

bull Due to preprocessing and the fact that G and G are the almost identical thetotal time needed to apply the constraint algorithm is in some cases bigger

Sorted matching size

26 Bipartite with degree seq 35

Sorted matching size-Comments

bull Classical matching is equal to perfect matching in every case

bull Constraint and greedy have identical behaviour

bull The larger the spectrum of the degree sequence the more efficient the matching

Sorted Ratios

36 Application

Sorted Ratios-Comments

bull With large initial matching most of the edges are considenred uselles or forced andare removed thus the ratio is close(if not equal to) zero

bull For small matching and large degree sequence sectrum hte max degree remainsthe same Only a few forced edges (and their nodes) are removed apparently nonodes with max degree

Sorted |E||V |

26 Bipartite with degree seq 37

Sorted |E||V | - Comments

bull In these set of figures we witness that the |E||V | acquires values relevant to those ofthe amadeus graphs The random graphs were constructed to depict this similarity

bull For smaller initial matching the ratios for G and G show the same upward trendand also they acquire closer values It repsresent the decrease of the averagenumber of forced edges in comparison to the larger matching cases

Sorted ∆

38 Application

Sorted ∆-Comments

bull Big difference in max degree in large initial matching

bull Almost identical behaviour in the case of small initial matching

Appendix A 39

Appendix A

BipartiteGraphGeneratorpy

from future import divisionimport networkx as nx

from networkxalgorithms import approximationimport collectionsimport randomimport mathfrom networkxalgorithms import bipartiteif name == main

for i in range(1481)waqs 481index=1n=randomrandint(100 1000)

n1=95 was 500me1=118

n2=251 was 500me2=903

n3=165 was 500me3=412

m=0m1=0p=randomrandom()p1=18250p2=25250p3=34250print ip=05t1=randomrandint(0 1)print im2=randomrandint(n2minus1 n2+1)G = nxGraph()ma = nxGraph()

aseq1=[1 2 3 4 5 3]

bseq1=[4 3 3 1 2 2 1]

aseq2=[16 14 14 14 12 11]bseq2=[0 0 0 0 0 0]

aseq3=[8 7 8 8 8 8]bseq3=[0 0 0 0 0 0]

40 Application

print Gnumber of edges()if ilt=160

G=bipartiteconfiguration model(aseq1 bseq1 create using=None seed=None)A=nxadjacency matrix(G)for ii in range(0n1+me1)

maadd node(ii)A=[Rtodense()tolist()[0] for R in A]

printnummanumber of nodes()rl=randomsample(range(0n1+me1) n1+me1)m=0done vertices = set()for p in rlprintin fordone verticesadd(p)

neighbors = []list()for iii in range(0n1+me1)

if A[p][iii]==1neighborsappend(iii)

randomshuffle(neighbors)continue loop = Truedegree = len(neighbors)

print degreej = 0p4=randomrandom()while continue loop and (jltdegree)print in loop

next = neighbors[j]if next not in done vertices and p not in done vertices

done verticesadd(p)done verticesadd(next)if p4gt=07print added edge

maadd edge(pnext)m=m+1

continue loop = Falsej += 1

print matching listOfedgeprint maedge

MA=nxadjacency matrix(ma)print MA

MA=[Rtodense()tolist()[0] for R in MA]print MA

B=[ join(map(strR)) for R in A]MB=[ join(map(strR)) for R in MA]

C=njoin(B)+nMC=njoin(MB)+n

print nprint mprint m1

filea=str(i)+txtwith open(fileaw) as f

Appendix A 41

fwrite(str(n1+me1))fwrite(n)fwrite(str(n1+me1))fwrite(n)fwrite(str(m))fwrite(n)fwrite(n)fwrite(C)fwrite(n)fwrite(MC)

elif igt160 and ilt321G=bipartiteconfiguration model(aseq2 bseq2 create using=None seed=None)A=nxadjacency matrix(G)for ii in range(0n2+me2)

maadd node(ii)A=[Rtodense()tolist()[0] for R in A]

printnummanumber of nodes()rl=randomsample(range(0n2+me2) n2+me2)m=0done vertices = set()for p in rlprintin fordone verticesadd(p)

neighbors = []list()for iii in range(0n2+me2)

if A[p][iii]==1neighborsappend(iii)

randomshuffle(neighbors)continue loop = Truedegree = len(neighbors)

print degreej = 0p4=randomrandom()while continue loop and (jltdegree)

print in loopnext = neighbors[j]if next not in done vertices and p not in done vertices

done verticesadd(p)done verticesadd(next)if p4gt=07

print added edgemaadd edge(pnext)m=m+1

continue loop = Falsej += 1

print matching listOfedgeprint maedge

MA=nxadjacency matrix(ma)print MA

MA=[Rtodense()tolist()[0] for R in MA]print MA

B=[ join(map(strR)) for R in A]MB=[ join(map(strR)) for R in MA]

42 Application

C=njoin(B)+nMC=njoin(MB)+n

print nprint mprint m1

filea=str(i)+txtwith open(fileaw) as f

fwrite(str(n2+me2))fwrite(n)fwrite(str(n2+me2))fwrite(n)fwrite(str(m))fwrite(n)fwrite(n)fwrite(C)fwrite(n)fwrite(MC)

elseG=bipartiteconfiguration model(aseq3 bseq3 create using=None seed=None)A=nxadjacency matrix(G)for ii in range(0n3+me3)

maadd node(ii)A=[Rtodense()tolist()[0] for R in A]

printnummanumber of nodes()rl=randomsample(range(0n3+me3) n3+me3)m=0done vertices = set()for p in rlprintin fordone verticesadd(p)

neighbors = []list()for iii in range(0n3+me3)

if A[p][iii]==1neighborsappend(iii)

randomshuffle(neighbors)continue loop = Truedegree = len(neighbors)

print degreej = 0p4=randomrandom()while continue loop and (jltdegree)

print in loopnext = neighbors[j]if next not in done vertices and p not in done vertices

done verticesadd(p)done verticesadd(next)if p4gt=07print added edge

maadd edge(pnext)m=m+1

continue loop = Falsej += 1

Appendix A 43

print matching listOfedgeprint maedge

MA=nxadjacency matrix(ma)print MA

MA=[Rtodense()tolist()[0] for R in MA]print MA

B=[ join(map(strR)) for R in A]MB=[ join(map(strR)) for R in MA]

C=njoin(B)+nMC=njoin(MB)+n

print nprint mprint m1

filea=str(i)+txtwith open(fileaw) as f

fwrite(str(n3+me3))fwrite(n)fwrite(str(n3+me3))fwrite(n)fwrite(str(m))fwrite(n)fwrite(n)fwrite(C)fwrite(n)fwrite(MC)

print nRandom graphs with random matching have been generated

44 Application

RandomGraphGeneratorpy

from future import divisionimport networkx as nxfrom networkxalgorithms import approximationimport collectionsimport randomimport mathif name == main

for i in range(1481)index=1n=randomrandint(100 1000)

n=1000m=0m1=0p=randomrandom()p1=mathlog(n2)np2=13p3=mathlog(n2)n+01p=05t1=randomrandint(0 1)print im2=randomrandint(n2minus1 n2+1)G = nxGraph()ma = nxGraph()print nme1=randomrandint(1 10)me2=randomrandint(2050)me3=randomrandint(50100)if ilt241

if ilt=80G=nxfast gnp random graph(n p1 seed=None directed=False)

elif igt80 and ilt161G=nxfast gnp random graph(n p2 seed=None directed=False)

elseG=nxfast gnp random graph(n p3 seed=None directed=False)

elseif ilt=320

G=nxbarabasi albert graph(n me1 seed=None)elif igt320 and ilt401

G=nxbarabasi albert graph(n me2 seed=None)else

G=nxbarabasi albert graph(n me3 seed=None)A=nxadjacency matrix(G)for ii in range(0n)

maadd node(ii)A=[Rtodense()tolist()[0] for R in A]

rl=randomsample(range(0n) n)m=0

Appendix A 45

done vertices = set()for p in rl

done verticesadd(p)neighbors = []list()for iii in range(0n)

if A[p][iii]==1neighborsappend(iii)

randomshuffle(neighbors)continue loop = Truedegree = len(neighbors)j = 0p2=randomrandom()while continue loop and (jltdegree)

next = neighbors[j]if next not in done vertices and p not in done vertices

done verticesadd(p)done verticesadd(next)if p2gt=00 Larger probability for smaller initial matching

maadd edge(pnext)m=m+1

continue loop = Falsej += 1

print matching listOfedgeprint maedgeMA=nxadjacency matrix(ma)MA=[Rtodense()tolist()[0] for R in MA]print MAB=[ join(map(strR)) for R in A]MB=[ join(map(strR)) for R in MA]

C=njoin(B)+nMC=njoin(MB)+nprint MCprint nprint mprint m1filea=str(i)+txtwith open(fileaw) as f

fwrite(str(n))fwrite(n)fwrite(str(n))fwrite(n)fwrite(str(m))fwrite(n)fwrite(n)fwrite(C)fwrite(n)fwrite(MC)

print nRandom graphs with random matching have been generated

46 Application

kequals3MaximumMatchingpy

from future import divisionimport networkx as nxfrom networkxalgorithms import bipartiteimport matplotlibpyplot as pltimport collectionsimport timeitimport xlwtimport xlrdimport mathimport sys

Case for General Graphsdef forced edges(Gadj dict2matching dict1num nodesforced)

flagg=0for n in range(0num nodes)

for k in adj dict2[n]if ([k]==matching dict1[n])

count=0for l in range(0num nodes)

count=count+adj dict2[l]count(k)if (len(adj dict2[n])==1) or (count==1)

forcedadd edge(nk)Gremove edge(nk)Gremove node(n)Gremove node(k)printforced edgenktemp=kflagg=1for m in range (len(adj dict2[n])minus1minus1minus1)

adj dict2[adj dict2[n][m]]remove(n)adj dict2[n]remove(adj dict2[n][m])

if adj dict2[temp]for l in range(len(adj dict2[temp])minus1minus1minus1)

if (adj dict2[temp][l]=n)adj dict2[adj dict2[temp][l]]remove(temp)adj dict2[temp]remove(adj dict2[temp][l])

break

def useless edges(num nodesadj dict1matching dict1uselessadj dict2G)for n in range(0num nodes)

for k in adj dict1[n]if ([k]=matching dict1[n]) and matching dict1[n] and matching dict1[k]

uselessadd edge(nk)Gremove edge(n k)

Appendix A 47

tempa=kadj dict2[n]remove(k)adj dict2[tempa]remove(n)adj dict1[tempa]remove(n)

return G

def Greedy(num nodesadj dict3matching dict2)

for n in range(0num nodes)if matching dict2[n]

flag2=minus1flag3=minus1for v in adj dict3[n]

if not matching dict2[v]flag2=vbreak

for p in adj dict3[matching dict2[n][0]]if not matching dict2[p]

flag3=pbreak

if (flag2=minus1) and (flag3=minus1) and (flag2=flag3)tempr=matching dict2[n][0]matching dict2[n]=[flag2]matching dict2[flag2]=[n]matching dict2[tempr]=[flag3]matching dict2[flag3]=[tempr]

elsefor k in adj dict3[n]

if not matching dict2[k]matching dict2[n]=[k]matching dict2[k]=[n]break

yo1=0for i in range(0num nodes)

if matching dict2[i] and [i]==matching dict2[matching dict2[i][0]]yo1=yo1+1

greedy size=yo12return greedy size

def General()

INPUTSwb = xlwtWorkbook()ws = wbadd sheet(Results Random)book=xlrdopen workbook(filenames randomxls)

48 Application

style0 = xlwteasyxf(fontbold on)style1 = xlwteasyxf(num format str=0000)INPUTSwswrite(0 0File style0)wswrite(0 1 Nodesstyle0)wswrite(0 2 Initial matchingstyle0)wswrite(0 3 NodesGstyle0)wswrite(0 4 EdgesGstyle0)wswrite(0 5 MaxDegreeGstyle0)wswrite(0 6 NodesG hatstyle0)wswrite(0 7 EdgesG Hatstyle0)wswrite(0 8 Useless edgesstyle0)wswrite(0 9 Forced edgesstyle0)wswrite(0 10 MaxDegreeG Hatstyle0)wswrite(0 11 Classical matchingstyle0)wswrite(0 12 Final matchingstyle0)wswrite(0 13 Greedy matchingstyle0)wswrite(0 14 Time classicalstyle0)wswrite(0 15 Time algorithmstyle0)wswrite(0 16 Time greedystyle0)wswrite(0 17 Perfect matching ratiostyle0)wswrite(0 18 Nodes ratiostyle0)wswrite(0 19 Edges ratiostyle0)wswrite(0 20 Matching ratiostyle0)

print nWelcomeThis is an implementation for general random graphs It uses Edmonds algorithm to compute maximum matching on G Hatn

for index in range (1481)was 481

if (index==482)f=open(Algotel generaltxtr)readlines()

elsefilea=str(booksheet by index(0)cell(index0))s=fileareplace(textu)replace()f=open(sr)readlines()Truewswrite(index 0 s)

print index

num nodes=int([xstrip()split() for x in f][0][0])

num matching=int([xstrip()split() for x in f][2][0])

adj temp = [xstrip()split() for x in f][44+num nodes]adj=[map(intR) for R in adj temp]

matching temp=[xstrip()split() for x in f][4+num nodes+14+2num nodes+1]matching1=[map(intR) for R in matching temp]

adj dict1=i[ii for iix in enumerate(L) if x] for iL in enumerate(adj)adj dict2=i[ii for iix in enumerate(L) if x] for iL in enumerate(adj)

Appendix A 49

adj dict3=i[ii for iix in enumerate(L) if x] for iL in enumerate(adj)

matching dict1=i[ii for iix in enumerate(L) if x] for iL in enumerate(matching1)matching dict2=i[ii for iix in enumerate(L) if x] for iL in enumerate(matching1)print adj dict2print matching dict2wswrite(index 1 num nodes)wswrite(index 2 num matching)

G = nxGraph()

useless= nxGraph()forced = nxGraph()

Fill Graphfor n in range(0num nodes)

for k in adj dict1[n]Gadd edge(nk)

Gt=Gnumber of edges()wswrite(index 3 Gnumber of nodes())wswrite(index 4 Gnumber of edges())wswrite(index 5 max(Gdegree()values()))

Compute Edmonds classical matching on G for comparison

startB = timeitdefault timer()Classical Matching=nxmax weight matching(G maxcardinality=False)stopB = timeitdefault timer()

Compute Gˆ nad MˆstartC = timeitdefault timer()useless edges(num nodesadj dict1matching dict1uselessadj dict2G)forced edges(Gadj dict2matching dict1num nodesforced)Final Matching=nxmax weight matching(G maxcardinality=False)stopC = timeitdefault timer()

GreedystartG = timeitdefault timer()greedy size=Greedy(num nodesadj dict3matching dict2)stopG = timeitdefault timer()

wswrite(index 6 Gnumber of nodes())wswrite(index 7 Gnumber of edges())wswrite(index 8 uselessnumber of edges())wswrite(index 9 forcednumber of edges())if Gdegree()values()

wswrite(index 10 max(Gdegree()values()))else

50 Application

wswrite(index 10 0)wswrite(index 11 len(Classical Matching)2)wswrite(index 12 len(Final Matching)2+forcednumber of edges())wswrite(index 13 greedy size)wswrite(index 14 stopB minus startBstyle1)wswrite(index 15 stopC minus startCstyle1)wswrite(index 16 stopG minus startGstyle1)wswrite(index 17 (len(Final Matching)2+forcednumber of edges())(num nodes2)style1)wswrite(index 18 Gnumber of nodes()Gtstyle1)wswrite(index 19 Gnumber of edges()Gtstyle1)wswrite(index 20 (len(Final Matching)2+forcednumber of edges())(len(Classical Matching)2)style1)

wbsave(AA Results Random Reyni Large Bipartitexls)

Main function Here we must choose the input form of the dataif name == main

startA = timeitdefault timer()General()stopA = timeitdefault timer()

print nThis program has terminatednnRunning time for 480 files stopAminusstartAprint nnPlease open AA Results Random Reyni Largexls file to see the Results

Appendix A 51

Plotmat

clear allclose allload(RN1Lmat)load(RN1Smat)load(RN2Lmat)load(RN2Smat)load(RN3Lmat)load(RN3Smat)

Plotsh(1)=figure(NameHistogram of Matching size difference between Constraint Algorithm and Greedy AlgorithmNumberTitleoff)

RN1L Greedydiff=RN1L Final matchingminusRN1L Greedy matchingRN2L Greedydiff=RN2L Final matchingminusRN2L Greedy matchingRN3L Greedydiff=RN3L Final matchingminusRN3L Greedy matchingRN1S Greedydiff=RN1S Final matchingminusRN1S Greedy matchingRN2S Greedydiff=RN2S Final matchingminusRN2S Greedy matchingRN3S Greedydiff=RN3S Final matchingminusRN3S Greedy matching

RN1L Finaldiff=RN1L Classical matchingminusRN1L Final matchingRN2L Finaldiff=RN2L Classical matchingminusRN2L Final matchingRN3L Finaldiff=RN3L Classical matchingminusRN3L Final matchingRN1S Finaldiff=RN1S Classical matchingminusRN1S Final matchingRN2S Finaldiff=RN2S Classical matchingminusRN2S Final matchingRN3S Finaldiff=RN3S Classical matchingminusRN3S Final matching

RN1L Classicaldiff=(RN1L Nodes2)minusRN1L Classical matchingRN2L Classicaldiff=(RN2L Nodes2)minusRN2L Classical matchingRN3L Classicaldiff=(RN3L Nodes2)minusRN3L Classical matchingRN1S Classicaldiff=(RN1S Nodes2)minusRN1S Classical matchingRN2S Classicaldiff=(RN2S Nodes2)minusRN2S Classical matchingRN3S Classicaldiff=(RN3S Nodes2)minusRN3S Classical matching

subplot(231)hold onhistf(RN1L Greedydiff0110facecolorbfacealpha9edgealpha1)histf(RN1L Finaldiff0110facecolorrfacealpha5edgealpha1)histf(RN1L Classicaldiff0110facecolorgfacealpha5edgealpha1)legalpha(ConminusGreClasminusConPerfminusClasslocationnortheast)legend boxoffaxis tightxlabel(edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN1L)grid on

subplot(232)hold onhistf(RN2L Greedydiff0110facecolorbfacealpha9edgealpha1)

52 Application

histf(RN2L Finaldiff0110facecolorrfacealpha5edgealpha1)histf(RN2L Classicaldiff0110facecolorgfacealpha5edgealpha1)legalpha(ConminusGreClasminusConPerfminusClasslocationnortheast)legend boxoffaxis tightxlabel(edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN2L)grid on

subplot(233)hold onhistf(RN3L Greedydiff0110facecolorbfacealpha5edgealpha1)histf(RN3L Finaldiff0110facecolorrfacealpha5edgealpha1)histf(RN3L Classicaldiff0110facecolorgfacealpha5edgealpha1)legalpha(ConminusGreClasminusConPerfminusClasslocationnortheast)legend boxoffaxis tightxlabel(edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN3L)grid on

subplot(234)hold onhistf(RN1S Greedydiff0110facecolorbfacealpha5edgealpha1)histf(RN1S Finaldiff0110facecolorrfacealpha5edgealpha1)histf(RN1S Classicaldiff0110facecolorgfacealpha5edgealpha1)legalpha(ConminusGreClasminusConPerfminusClasslocationnortheast)legend boxoffaxis tightxlabel(edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(R1NS)grid on

subplot(235)hold onhistf(RN2S Greedydiff0110facecolorbfacealpha5edgealpha1)histf(RN2S Finaldiff0110facecolorrfacealpha5edgealpha1)histf(RN2S Classicaldiff0110facecolorgfacealpha5edgealpha1)legalpha(ConminusGreClasminusConPerfminusClasslocationnortheast)legend boxoffaxis tightxlabel(edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN2S)grid on

subplot(236)hold onhistf(RN3S Greedydiff0110facecolorbfacealpha5edgealpha1)histf(RN3S Finaldiff0110facecolorrfacealpha5edgealpha1)histf(RN3S Classicaldiff0110facecolorgfacealpha5edgealpha1)

Appendix A 53

legalpha(ConminusGreClasminusConPerfminusClasslocationnortheast)legend boxoffaxis tightgrid ontitle(RN3S)xlabel(edges) xminusaxis labelylabel(instances) yminusaxis labelset(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN1png minusr300)h(2)=figure(NameHistogram of Max Degree of G AND G HatNumberTitleoff)RN1L x=RN1L MaxDegreeGminusRN1L MaxDegreeG HatRN2L x=RN2L MaxDegreeGminusRN2L MaxDegreeG HatRN3L x=RN3L MaxDegreeGminusRN3L MaxDegreeG HatRN1S x=RN1S MaxDegreeGminusRN1S MaxDegreeG HatRN2S x=RN2S MaxDegreeGminusRN2S MaxDegreeG HatRN3S x=RN3S MaxDegreeGminusRN3S MaxDegreeG Hatsubplot(231)hold onhistf(RN1L MaxDegreeG0150facecolorbfacealpha5edgealpha1)histf(RN1L MaxDegreeG Hat0150facecolorrfacealpha5edgealpha1)histf(RN1L x0150facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightxlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN1L)grid on

subplot(232)hold onhistf(RN2L MaxDegreeG010500facecolorbfacealpha5edgealpha1)histf(RN2L MaxDegreeG Hat010500facecolorrfacealpha5edgealpha1)histf(RN2L x010500facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightxlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN2L)grid on

subplot(233)hold onhistf(RN3L MaxDegreeG010300facecolorbfacealpha5edgealpha1)histf(RN3L MaxDegreeG Hat010300facecolorrfacealpha5edgealpha1)histf(RN3L x010300facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightxlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN3L)

54 Application

grid on

subplot(234)hold onhistf(RN1S MaxDegreeG0150facecolorbfacealpha5edgealpha1)histf(RN1S MaxDegreeG Hat0150facecolorrfacealpha5edgealpha1)histf(RN1S x0150facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightxlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(R1NS)grid on

subplot(235)hold onhistf(RN2S MaxDegreeG010500facecolorbfacealpha5edgealpha1)histf(RN2S MaxDegreeG Hat010500facecolorrfacealpha5edgealpha1)histf(RN2S x010500facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightxlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN2S)grid on

subplot(236)hold onhistf(RN3S MaxDegreeG05300facecolorbfacealpha5edgealpha1)histf(RN3S MaxDegreeG Hat05300facecolorrfacealpha5edgealpha1)histf(RN3S x05300facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightgrid ontitle(RN3S)xlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labelset(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN2png minusr300)

h(3)=figure(NameComputation time over edgesNumberTitleoff)

subplot(231)hold onstem(RN1L EdgesGRN1L Time classicalg)stem(RN1L EdgesGRN1L Time algorithmro)stem(RN1L EdgesGRN1L Time greedybx)grid on

Appendix A 55

title(RN1L)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)

subplot(232)hold onstem(RN2L EdgesGRN2L Time classicalg)stem(RN2L EdgesGRN2L Time algorithmro)stem(RN2L EdgesGRN2L Time greedybx)grid ontitle(RN2L)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)

subplot(233)hold onstem(RN3L EdgesGRN3L Time classicalg)stem(RN3L EdgesGRN3L Time algorithmro)stem(RN3L EdgesGRN3L Time greedybx)grid ontitle(RN3L)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)

subplot(234)hold onstem(RN1S EdgesGRN1S Time classicalg)stem(RN1S EdgesGRN1S Time algorithmro)stem(RN1S EdgesGRN1S Time greedybx)grid ontitle(RN1S)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)

subplot(235)hold onstem(RN2S EdgesGRN2S Time classicalg)stem(RN2S EdgesGRN2S Time algorithmro)stem(RN2S EdgesGRN2S Time greedybx)grid ontitle(RN2S)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)

subplot(236)hold onstem(RN3S EdgesGRN3S Time classicalg)stem(RN3S EdgesGRN3S Time algorithmro)stem(RN3S EdgesGRN3S Time greedybx)

56 Application

grid ontitle(RN3S)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)set(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN3png minusr300)

h(4)=figure(NameSorted matching sizeNumberTitleoff)RN1L Sorted matching temp(1)=RN1L Classical matchingRN1L Sorted matching temp(2)=RN1L Final matchingRN1L Sorted matching temp(3)=RN1L Greedy matchingRN1L Sorted matching temp(4)=RN1L Initial matchingRN1L Sorted matching=sortrows(RN1L Sorted matching temp)

RN2L Sorted matching temp(1)=RN2L Classical matchingRN2L Sorted matching temp(2)=RN2L Final matchingRN2L Sorted matching temp(3)=RN2L Greedy matchingRN2L Sorted matching temp(4)=RN2L Initial matchingRN2L Sorted matching=sortrows(RN2L Sorted matching temp)

RN3L Sorted matching temp(1)=RN3L Classical matchingRN3L Sorted matching temp(2)=RN3L Final matchingRN3L Sorted matching temp(3)=RN3L Greedy matchingRN3L Sorted matching temp(4)=RN3L Initial matchingRN3L Sorted matching=sortrows(RN3L Sorted matching temp)

RN1S Sorted matching temp(1)=RN1S Classical matchingRN1S Sorted matching temp(2)=RN1S Final matchingRN1S Sorted matching temp(3)=RN1S Greedy matchingRN1S Sorted matching temp(4)=RN1S Initial matchingRN1S Sorted matching=sortrows(RN1S Sorted matching temp)

RN2S Sorted matching temp(1)=RN2S Classical matchingRN2S Sorted matching temp(2)=RN2S Final matchingRN2S Sorted matching temp(3)=RN2S Greedy matchingRN2S Sorted matching temp(4)=RN2S Initial matchingRN2S Sorted matching=sortrows(RN2S Sorted matching temp)

RN3S Sorted matching temp(1)=RN3S Classical matchingRN3S Sorted matching temp(2)=RN3S Final matchingRN3S Sorted matching temp(3)=RN3S Greedy matchingRN3S Sorted matching temp(4)=RN3S Initial matchingRN3S Sorted matching=sortrows(RN3S Sorted matching temp)

subplot(231)hold onplot(RN1L Sorted matching(1)b)plot(RN1L Sorted matching(2)g)plot(RN1L Sorted matching(3)r)plot(RN1L Sorted matching(4)m)

Appendix A 57

grid ontitle(RN1L)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)

subplot(232)hold onplot(RN2L Sorted matching(1)b)plot(RN2L Sorted matching(2)g)plot(RN2L Sorted matching(3)r)plot(RN2L Sorted matching(4)m)grid ontitle(RN2L)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)

subplot(233)hold onplot(RN3L Sorted matching(1)b)plot(RN3L Sorted matching(2)g)plot(RN3L Sorted matching(3)r)plot(RN3L Sorted matching(4)m)grid ontitle(RN3L)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)

subplot(234)hold onplot(RN1S Sorted matching(1)b)plot(RN1S Sorted matching(2)g)plot(RN1S Sorted matching(3)r)plot(RN1S Sorted matching(4)m)grid ontitle(RN1S)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)

subplot(235)hold onplot(RN2S Sorted matching(1)b)plot(RN2S Sorted matching(2)g)plot(RN2S Sorted matching(3)r)plot(RN2S Sorted matching(4)m)grid ontitle(RN2S)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)

58 Application

subplot(236)hold onplot(RN3S Sorted matching(1)b)plot(RN3S Sorted matching(2)g)plot(RN3S Sorted matching(3)r)plot(RN3S Sorted matching(4)m)grid ontitle(RN3S)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)set(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN4png minusr300)h(5)=figure(NameSorted RatiosNumberTitleoff)RN1L ratio1=RN1L NodesG hatRN1L NodesGRN2L ratio1=RN2L NodesG hatRN2L NodesGRN3L ratio1=RN3L NodesG hatRN3L NodesGRN1S ratio1=RN1S NodesG hatRN1S NodesGRN2S ratio1=RN2S NodesG hatRN2S NodesGRN3S ratio1=RN3S NodesG hatRN3S NodesG

RN1L ratio2=RN1L EdgesG HatRN1L EdgesGRN2L ratio2=RN2L EdgesG HatRN2L EdgesGRN3L ratio2=RN3L EdgesG HatRN3L EdgesGRN1S ratio2=RN1S EdgesG HatRN1S EdgesGRN2S ratio2=RN2S EdgesG HatRN2S EdgesGRN3S ratio2=RN3S EdgesG HatRN3S EdgesG

RN1L ratio3=RN1L MaxDegreeG HatRN1L MaxDegreeGRN2L ratio3=RN2L MaxDegreeG HatRN2L MaxDegreeGRN3L ratio3=RN3L MaxDegreeG HatRN3L MaxDegreeGRN1S ratio3=RN1S MaxDegreeG HatRN1S MaxDegreeGRN2S ratio3=RN2S MaxDegreeG HatRN2S MaxDegreeGRN3S ratio3=RN3S MaxDegreeG HatRN3S MaxDegreeG

RN1L ratio(1)=RN1L ratio1RN1L ratio(2)=RN1L ratio2RN1L ratio(3)=RN1L ratio3

RN2L ratio(1)=RN2L ratio1RN2L ratio(2)=RN2L ratio2RN2L ratio(3)=RN2L ratio3

RN3L ratio(1)=RN3L ratio1RN3L ratio(2)=RN3L ratio2RN3L ratio(3)=RN3L ratio3

RN1S ratio(1)=RN1S ratio1RN1S ratio(2)=RN1S ratio2RN1S ratio(3)=RN1S ratio3

RN2S ratio(1)=RN2S ratio1

Appendix A 59

RN2S ratio(2)=RN2S ratio2RN2S ratio(3)=RN2S ratio3

RN3S ratio(1)=RN3S ratio1RN3S ratio(2)=RN3S ratio2RN3S ratio(3)=RN3S ratio3

RN1L ratio sorted=sortrows(RN1L ratio)RN2L ratio sorted=sortrows(RN2L ratio)RN3L ratio sorted=sortrows(RN3L ratio)RN1S ratio sorted=sortrows(RN1S ratio)RN2S ratio sorted=sortrows(RN2S ratio)RN3S ratio sorted=sortrows(RN3S ratio)

subplot(231)hold onplot(RN1L ratio sorted(1)b)plot(RN1L ratio sorted(2)g)plot(RN1L ratio sorted(3)r)grid ontitle(RN1L)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)

subplot(232)hold onplot(RN2L ratio sorted(1)b)plot(RN2L ratio sorted(2)g)plot(RN2L ratio sorted(3)r)grid ontitle(RN2L)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)

subplot(233)hold onplot(RN3L ratio sorted(1)b)plot(RN3L ratio sorted(2)g)plot(RN3L ratio sorted(3)r)grid ontitle(RN3L)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)

subplot(234)hold onplot(RN1S ratio sorted(1)b)plot(RN1S ratio sorted(2)g)plot(RN1S ratio sorted(3)r)grid on

60 Application

title(RN1S)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)

subplot(235)hold onplot(RN2S ratio sorted(1)b)plot(RN2S ratio sorted(2)g)plot(RN2S ratio sorted(3)r)grid ontitle(RN2S)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)

subplot(236)hold onplot(RN3S ratio sorted(1)b)plot(RN3S ratio sorted(2)g)plot(RN3S ratio sorted(3)r)grid ontitle(RN3S)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)set(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN5png minusr300)

h(6)=figure(NameSorted edges over nodesNumberTitleoff)

RN1L DegreeG1=(RN1L EdgesG)(RN1L NodesG)RN1L DegreeG Hat1=(RN1L EdgesG Hat)(RN1L NodesG hat)

RN1L Degree temp1(1)=RN1L DegreeG1RN1L Degree temp1(2)=RN1L DegreeG Hat1RN1L Degree sorted1=sortrows(RN1L Degree temp1)subplot(231)hold on

plot(RN1L Degree sorted1(1)b)plot(RN1L Degree sorted1(2)g)grid ontitle(RN1L)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)

RN2L DegreeG1=(RN2L EdgesG)(RN2L NodesG)RN2L DegreeG Hat1=(RN2L EdgesG Hat)(RN2L NodesG hat)

RN2L Degree temp1(1)=RN2L DegreeG1

Appendix A 61

RN2L Degree temp1(2)=RN2L DegreeG Hat1RN2L Degree sorted1=sortrows(RN2L Degree temp1)

subplot(232)hold onplot(RN2L Degree sorted1(1)b)plot(RN2L Degree sorted1(2)g)grid ontitle(RN2L)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)

RN3L DegreeG1=(RN3L EdgesG)(RN3L NodesG)RN3L DegreeG Hat1=(RN3L EdgesG Hat)(RN3L NodesG hat)

RN3L Degree temp1(1)=RN3L DegreeG1RN3L Degree temp1(2)=RN3L DegreeG Hat1RN3L Degree sorted1=sortrows(RN3L Degree temp1)

subplot(233)hold onplot(RN3L Degree sorted1(1)b)plot(RN3L Degree sorted1(2)g)grid ontitle(RN3L)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)

RN1S DegreeG1=(RN1S EdgesG)(RN1S NodesG)RN1S DegreeG Hat1=(RN1S EdgesG Hat)(RN1S NodesG hat)

RN1S Degree temp1(1)=RN1S DegreeG1RN1S Degree temp1(2)=RN1S DegreeG Hat1RN1S Degree sorted1=sortrows(RN1S Degree temp1)

subplot(234)hold onplot(RN1S Degree sorted1(1)b)plot(RN1S Degree sorted1(2)g)grid ontitle(RN1S)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)

RN2S DegreeG1=(RN2S EdgesG)(RN2S NodesG)RN2S DegreeG Hat1=(RN2S EdgesG Hat)(RN2S NodesG hat)

RN2S Degree temp1(1)=RN2S DegreeG1

62 Application

RN2S Degree temp1(2)=RN2S DegreeG Hat1RN2S Degree sorted1=sortrows(RN2S Degree temp1)

subplot(235)hold onplot(RN2S Degree sorted1(1)b)plot(RN2S Degree sorted1(2)g)grid ontitle(RN2S)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)

RN3S DegreeG1=(RN3S EdgesG)(RN3S NodesG)RN3S DegreeG Hat1=(RN3S EdgesG Hat)(RN3S NodesG hat)

RN3S Degree temp1(1)=RN3S DegreeG1RN3S Degree temp1(2)=RN3S DegreeG Hat1RN3S Degree sorted1=sortrows(RN3S Degree temp1)

subplot(236)hold onplot(RN3S Degree sorted1(1)b)plot(RN3S Degree sorted1(2)g)grid ontitle(RN3S)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)set(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN6png minusr300)h(7)=figure(NameSorted mATCHED DEGREENumberTitleoff)RN1L ratioMax(1)=RN1L MaxDegreeGRN1L ratioMax(2)=RN1L MaxDegreeG Hat

RN1L ratio sortedMax=sortrows(RN1L ratioMax)subplot(231)hold onplot(RN1L ratio sortedMax(1)b)plot(RN1L ratio sortedMax(2)g)grid ontitle(RN1L)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)

RN2L ratioMax(1)=RN2L MaxDegreeGRN2L ratioMax(2)=RN2L MaxDegreeG Hat

RN2L ratio sortedMax=sortrows(RN2L ratioMax)subplot(232)

Appendix A 63

hold onplot(RN2L ratio sortedMax(1)b)plot(RN2L ratio sortedMax(2)g)grid ontitle(RN2L)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)

RN3L ratioMax(1)=RN3L MaxDegreeGRN3L ratioMax(2)=RN3L MaxDegreeG Hat

RN3L ratio sortedMax=sortrows(RN3L ratioMax)subplot(233)hold onplot(RN3L ratio sortedMax(1)b)plot(RN3L ratio sortedMax(2)g)grid ontitle(RN3L)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)

RN1S ratioMax(1)=RN1S MaxDegreeGRN1S ratioMax(2)=RN1S MaxDegreeG Hat

RN1S ratio sortedMax=sortrows(RN1S ratioMax)subplot(234)hold onplot(RN1S ratio sortedMax(1)b)plot(RN1S ratio sortedMax(2)g)grid ontitle(RN1S)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)

RN2S ratioMax(1)=RN2S MaxDegreeGRN2S ratioMax(2)=RN2S MaxDegreeG Hat

RN2S ratio sortedMax=sortrows(RN2S ratioMax)

subplot(235)hold onplot(RN2S ratio sortedMax(1)b)plot(RN2S ratio sortedMax(2)g)grid ontitle(RN2S)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)

RN3S ratioMax(1)=RN3S MaxDegreeGRN3S ratioMax(2)=RN3S MaxDegreeG Hat

64 Application

RN3S ratio sortedMax=sortrows(RN3S ratioMax)subplot(236)hold onplot(RN3S ratio sortedMax(1)b)plot(RN3S ratio sortedMax(2)g)grid ontitle(RN1L)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)set(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN7png minusr300)

tilefigs()(h)

Bibliography

[1] C Berge ldquoTWO THEOREMS IN GRAPH THEORYrdquo Proceedings of the NationalAcademy of Sciences of the United States of America vol 43 no 9 pp 842ndash844Sep 1957

[2] L Bui S Sanghavi and R Srikant ldquoDistributed link scheduling with constantoverheadrdquo IEEEACM Trans Netw vol 17 no 5 pp 1467ndash1480 2009

[3] R Duan and S Pettie ldquoLinear-time approximation for maximum weight matchingrdquoJ ACM vol 61 no 1 2014

[4] J Edmonds ldquoPaths trees and flowersrdquo Canadian Journal of Mathematics vol 17pp 449ndash467 1965

[5] J E Hopcroft and R M Karp ldquoAn n52 algorithm for maximum matchings inbipartite graphsrdquo SIAM J Comput vol 2 no 4 pp 225ndash231 1973

[6] S Micali and V V Vazirani ldquoAn O(radic|V ||E|) algorithm for finding maximum

matching in general graphsrdquo in 21st Symp on Foundations of Comp Sc (FOCS)IEEE 1980 pp 17ndash27

[7] N Nisse A Salch and V Weber ldquoRecovery of disrupted airline operationsrdquo 2015httphalinriafrSomething

[8] X Wu and R Srikant ldquoRegulated maximal matching A distributed schedulingalgorithm for multi-hop wireless networks with nodeexclusive spectrum sharingrdquo inIEEE Conf on Decision and Control 2005

65

  • Contents
  • Introduction
  • Algorithms
    • Maximum matching
    • k-maximum matching
      • k-matching for Airport Slot assignment
      • The case where k=3
      • The case of Paths
      • The case of the Spider
          • Application
            • Description
            • Reyni Erdos
            • Barabaacutesi Albert
            • Amadeus Graphs
            • Bipartite
            • Bipartite with degree seq
            • Appendix A
              • BipartiteGraphGeneratorpy
              • RandomGraphGeneratorpy
              • kequals3MaximumMatchingpy
              • Plotmat
                  • Bibliography
Page 9: Theodoros Alexandros KARAGKIOULES -  · Introduction This work is the result of a 6 months internship, under the supervision of research O cer Nicolas NISSE. The original scope of

10 Application

22 Reyni Erdos

bull RNxy are randomly generated graphs with a fixed number of 1000 nodes

bull There are 6 categories based on the initial matching and probability p of connection

bull x = L S L When the initial matching is large and S when it is small

bull y = 1 2 3 1 when p = lognn

2 when p = 13

and 3 when p = lognn

+ 01

Computation time over |E|

Computation time over |E| - Comments

bull This is a very straightforward set of figures

22 Reyni Erdos 11

bull When the initial matching is sufficiently large then the forced edges are taken out(a process which takes a fragment of the computation time) and then the classicalmatching algorithm (Edmonds) is applied on a smaller graph(G) This reducessignificantly the computation time

bull When the initial matching is small then the computation time of the constraintalgorithm might be larger than that of Edmonds The reason is that the constraintalgorithm need some time to compute the useless and forced edges and thenEdmonds algorithm is applied on G G Thus the overall processing time issometimes larger

Sorted matching size

Sorted matching size - Comments

12 Application

bull This set of figures represents the ascending order of the Classical matching sizealong with its corresponding Constraint and Greedy equivalent

bull When the probability is sufficiently higher than the threshold lognn

then the threealgorithms produce identical results of optimal matching

bull For lower probability there is a difference between the results of the algorithms

bull the degree of that difference is depicted in the first set of figures presented

bull It is interesting to observe that a change on the Constraint algorithm is associatedwith a even more significant change in the Greedy algorithm

bull There is a difference only when the probability is at the connectedness threshholdlognn

bull The difference is very small compared to the size of the matching ( 500)

bull The difference in matching size appears mostly at the Greedy implementationwhen compared to the constraint algorithm

Sorted Ratios

22 Reyni Erdos 13

Sorted Ratios - Comments

bull This set of figures depicts the ratios VV

EE

∆∆

in ascending order of VV

bull It is evident that when the initial matching is large the amount of forced edges(and their endpoints) removed is high thus the ratio of Nodes and edges is verylow For higher probabilities almost all edges are removed as useless

bull For a smaller initial matching almost no forced edges (and their endpoints) areremoved which we conclude be the node ration being close to 1 There is somesmall amount of useless edges removed though since the ratio of edges is less butclose to 1

bull The ratio of ∆ for large initial matching follows the trend of the node ratio yetfor smaller initial matching it deviates significantly

14 Application

Sorted |E||V |

Sorted |E||V | - Comments

bull Although as graph density the ratio 2|E||V |(|V |minus1)

is considered in this set of figures

we evaluate the correlation of the ratio |E||V | of G and G since the density of G

could acquire values higher than that of G

bull The figures are calculated in ascending order for the ratio of G

bull For the case of large initial matching the two ratios for G and G remain almostconstant ( to the extent of the probability of each graph) since removing forcededges( and their endpoints) alters the |E| and |V | proportionately

22 Reyni Erdos 15

bull For the case of small initial matching we observe some deviation in the valuesof the ration for G and that is explained with the removal of only useless edgeswhich only alters the |E| and keeps |V | in the original values

Sorted ∆

Sorted ∆-Comments

bull In this set of figures the ascending order of the ∆ of G is associated with the ∆of G

bull There is no significant jump of the ∆ for each graph category which tells that thatwe are comparing a uniform distribution of random grapghs for each probabilitycase

16 Application

bull For larger initial matching we observe the difference in the ∆s of G and G giventhe removed forced edges( and their endpoints) At some cases the ∆ of G dropsto 0 since the vast majority of edges have been declared forced and removed alongwith their endpoints

bull For smaller initial matching the ∆s of G and G follow mostly the same trend onlya few number of different instances

23 Barabasi Albert

Graph characteristics Barabasi Albert

bull BAxy are randomly generated graphs with a fixed number of 1000 nodes

bull There are 6 categories based on ini matching and of attached edges m

bull x = L S L When the initial matching is large and S when it is small

bull y = 1 2 3 1 when m = [1 10] 2 when m = [20 50] and 3 m = [50 100]

Computation time over |E|

23 Barabasi Albert 17

Computation time over |E| - Comments

bull When the initial matching is sufficiently large then the forced edges are taken out(a process which takes a fragment of the computation time) and then the classicalmatching algorithm (Edmonds) is applied on a smaller graph(G) This reducessignificantly the computation time

bull When the initial matching is small then the computation time of the constraintalgorithm might be larger than that of Edmonds The reason is that the constraintalgorithm need some time to compute the useless and forced edges and thenEdmonds algorithm is applied on G G Thus the overall processing time issometimes larger

Sorted matching size

18 Application

Sorted matching size-Comments

bull In this graph the matching size of the classical algorithm is depicted in ascendingorder along with the corresponding constraint algorithm and greedy result

bull Here in the case where m is small for both cases of initial matching (small large)the result may vary greatly starting from a value of half the perfect matching withsmall differences between the results of the various algorithm implementations

bull For the other cases of m the results converge

bull This is explained as for small values of m the graph is disconnected

bull In the matching size difference set of figures a very noticing difference value ap-pears For the cases of small m( the number of existing nodes that a new node isconnected to at the creation of the graph) we can see that the difference in the

23 Barabasi Albert 19

matching size compared to that of the perfect matching could be up to 40 ofthat of the matching size So there are occasions where the matching size is 200edges when the perfect matching would have been 500

bull the difference between the Constraint matching and the classical matching andthe difference of the constraint matching and that of the greedy matching do notshow significant values

Sorted Ratios

Sorted Ratio s -Comments

bull This set of figures depicts the ratios VV

EE

∆∆

in ascending order of VV

20 Application

bull It is evident that when the initial matching is large the amount of forced edges(and their endpoints) removed is high thus the ratio of Nodes and edges is verylow For higher probabilities almost all edges are removed as useless

bull For a smaller initial matching almost no forced edges (and their endpoints) areremoved which we conclude be the node ration being close to 1 There is somesmall amount of useless edges removed though since the ratio of edges is less butclose to 1

bull The ratio of ∆ for large initial matching follows the trend of the node ratio yetfor smaller initial matching it deviates significantly

Sorted |E||V |

23 Barabasi Albert 21

Sorted |E||V | - Comments

bull Although as graph density the ratio 2|E||V |(|V |minus1)

is considered in this set of figures

we evaluate the correlation of the ratio |E||V | of G and G since the density of G

could acquire values higher than that of G

bull The figures are calculated in ascending order for the ratio of G

bull For the case of large initial matching the two ratios for G and G remain almostconstant ( to the extent of the edge attraction m of each graph) since removingforced edges( and their endpoints) alters the |E| and |V | proportionately

bull For the case of small initial matching we observe some deviation in the valuesof the ration for G and that is explained with the removal of only useless edgeswhich only alters the |E| and keeps |V | in the original values

Sorted ∆

22 Application

Sorted ∆-Comments

bull In this set of figures the ascending order of the ∆ of G is associated with the ∆of G

bull There is a significant jump of the ∆ for each graph category which tells that thatwe are not comparing a uniform distribution of random graphs and based on theedge attraction m the graphs can vary in form

bull For larger initial matching we observe the difference in the ∆s of G and G giventhe removed forced edges( and their endpoints) At some cases the ∆ of G dropsto 0 since the vast majority of edges have been declared forced and removed alongwith their endpoints What is interesting is that the ∆ of G oscilates within stablelimits

24 Amadeus Graphs 23

bull For smaller initial matching the ∆s of G and G follow mostly the same trend onlya few number of different instances

24 Amadeus Graphs

Graph characteristics Amadeus graphs

bull These are the bipartite graphs provided by Amadeus

Computation time over |E|

Computation time over |E| - Comments

24 Application

bull For every instance the computation time of the classical algorithm is always smallerto that of the constraint matching

bull This allows as to speculate that we always compute a smaller G which also impliesthat we always find a set of forced edges and useless

Sorted matching size

Sorted matching size - Comments

bull Size of matching has an upward trend since the magnitude of the graphs is notthe same for the 160 instances

bull No significant deviation is noticed as per the first graph

24 Amadeus Graphs 25

bull Except from deviation from the perfect matching (number of flights) where some-times it could get up to 40

bull For the Amadeus Bipartite graphs we can see that the difference of the Classicaland the constraint implementation is not more than 1 edge in the matching

bull There appears to be a difference of up to 24 edges between the Classical matchingand the Perfect matching which is computed as the number of flights

bull The greedy algorithm performs well with only a few instances deviating slightlyform the Constraint algorithm result

Sorted Ratios

Sorted Ratios - Comments

26 Application

bull

Sorted |E||V |

Sorted |E||V | - Comments

bull Density of the graphs shows that on average we have 25-3 available time slot perflight

bull The line for the same value for G shows that there is a large deviation for everyinstance which allows for the hypothesis that the amount of useless+forced edgesof G has no obvious correlation to that of G

25 Bipartite 27

Sorted ∆

Sorted ∆-Comments

bull As per the previous related graphs for ∆ there is in significant drop in the ∆ of Gand G

25 Bipartite

Graph characteristics Bipartite random Graphs

bull BIPxy are randomly generated graphs with a fixed number of 1000(n=500 andm=500) nodes

bull There are 6 categories based on ini matching and probability p

28 Application

bull Probability p has been chosen as such in order to simulate the |E||V | 25 of theAmadeus bipartite graphs

bull So in order to have about 2-4 edges for every node we choose accordingly theprobability p to choose one of the n lowastm possible edges

bull x = L S L When the initial matching is large and S when it is small

bull y = 1 2 3 1 when p = 18250

2 when p = 25250

and 3 when p = 34250

Computation time over

Computation time overedges-Comments

bull

25 Bipartite 29

Sorted matching size

Sorted matching size-Comments

bull In these set of graphs one can instantly notice that only a few instances with highprobability can reach a matching size equal to the perfect matching

bull For the case of the initial matching we witness that there is a gap between the lineof the classical matching and those of the constraint and greedy results suggestingsmaller matching sizes of 10-40 edges

bull For the case of the small initial matching the result of the constraint matchingis now close to the result of the classical matching yet the greedy algorithm stillshows a relevantly big difference

30 Application

bull In this set of bipartite graphs we can witness that the result of the Constraintmatching shows a difference with the classical matching when the initial matchingis large The difference is smaller as the probability gets larger

bull For the case of the small initial matching the above phenomenom does not occuryet the greedy results deviates from that of the constraint matching

bull As per the pefrect matching compared to the classical matching a difference of5-10 edges is evident at almost all cases

Sorted Ratios

Sorted Ratios-Comments

bull Great max degree deviation

25 Bipartite 31

bull Regardless of the probability the ration of nodes and edges seems to have similarbehaviour when compared to the respective graphs of the same matching scale

bull Same gap between nodes ration and edges ration for all cases

Sorted |E||V |

Sorted |E||V | - Comments

bull In these set of figures we witness that the |E||V | acquires values relevant to those ofthe amadeus graphs The random graphs were constructed to depict this similarity

bull For smaller initial matching the ratios for G and G show the same upward trendand also they acquire closer values It represents the decrease of the averagenumber of forced edges in comparison to the larger matching cases

32 Application

Sorted ∆

Sorted ∆-Comments

bull ∆ acquires the same min and max values for each probability case (expected)

bull Gap in the case of large initial matching

26 Bipartite with degree seq

Graph characteristics

bull DEQBIPxy are randomly generated graphs based on three different types of degreedistribution of the Amadeus graphs

26 Bipartite with degree seq 33

bull There are 6 categories based on ini matching and degree distribution

bull x = L S L When the initial matching is large and S when it is small

bull y = 1 2 3 1 when degree distribution is based on file 2 when degree distributionis based on file and 3 when degree distribution is based on file

Computation time over

34 Application

Computation time overedges-Comments

bull Greedy algorithm takes minimum amount of time

bull The smaller the initial matching the more smaller the difference in comoutationtime of Constraint and classical algorithm

bull Due to preprocessing and the fact that G and G are the almost identical thetotal time needed to apply the constraint algorithm is in some cases bigger

Sorted matching size

26 Bipartite with degree seq 35

Sorted matching size-Comments

bull Classical matching is equal to perfect matching in every case

bull Constraint and greedy have identical behaviour

bull The larger the spectrum of the degree sequence the more efficient the matching

Sorted Ratios

36 Application

Sorted Ratios-Comments

bull With large initial matching most of the edges are considenred uselles or forced andare removed thus the ratio is close(if not equal to) zero

bull For small matching and large degree sequence sectrum hte max degree remainsthe same Only a few forced edges (and their nodes) are removed apparently nonodes with max degree

Sorted |E||V |

26 Bipartite with degree seq 37

Sorted |E||V | - Comments

bull In these set of figures we witness that the |E||V | acquires values relevant to those ofthe amadeus graphs The random graphs were constructed to depict this similarity

bull For smaller initial matching the ratios for G and G show the same upward trendand also they acquire closer values It repsresent the decrease of the averagenumber of forced edges in comparison to the larger matching cases

Sorted ∆

38 Application

Sorted ∆-Comments

bull Big difference in max degree in large initial matching

bull Almost identical behaviour in the case of small initial matching

Appendix A 39

Appendix A

BipartiteGraphGeneratorpy

from future import divisionimport networkx as nx

from networkxalgorithms import approximationimport collectionsimport randomimport mathfrom networkxalgorithms import bipartiteif name == main

for i in range(1481)waqs 481index=1n=randomrandint(100 1000)

n1=95 was 500me1=118

n2=251 was 500me2=903

n3=165 was 500me3=412

m=0m1=0p=randomrandom()p1=18250p2=25250p3=34250print ip=05t1=randomrandint(0 1)print im2=randomrandint(n2minus1 n2+1)G = nxGraph()ma = nxGraph()

aseq1=[1 2 3 4 5 3]

bseq1=[4 3 3 1 2 2 1]

aseq2=[16 14 14 14 12 11]bseq2=[0 0 0 0 0 0]

aseq3=[8 7 8 8 8 8]bseq3=[0 0 0 0 0 0]

40 Application

print Gnumber of edges()if ilt=160

G=bipartiteconfiguration model(aseq1 bseq1 create using=None seed=None)A=nxadjacency matrix(G)for ii in range(0n1+me1)

maadd node(ii)A=[Rtodense()tolist()[0] for R in A]

printnummanumber of nodes()rl=randomsample(range(0n1+me1) n1+me1)m=0done vertices = set()for p in rlprintin fordone verticesadd(p)

neighbors = []list()for iii in range(0n1+me1)

if A[p][iii]==1neighborsappend(iii)

randomshuffle(neighbors)continue loop = Truedegree = len(neighbors)

print degreej = 0p4=randomrandom()while continue loop and (jltdegree)print in loop

next = neighbors[j]if next not in done vertices and p not in done vertices

done verticesadd(p)done verticesadd(next)if p4gt=07print added edge

maadd edge(pnext)m=m+1

continue loop = Falsej += 1

print matching listOfedgeprint maedge

MA=nxadjacency matrix(ma)print MA

MA=[Rtodense()tolist()[0] for R in MA]print MA

B=[ join(map(strR)) for R in A]MB=[ join(map(strR)) for R in MA]

C=njoin(B)+nMC=njoin(MB)+n

print nprint mprint m1

filea=str(i)+txtwith open(fileaw) as f

Appendix A 41

fwrite(str(n1+me1))fwrite(n)fwrite(str(n1+me1))fwrite(n)fwrite(str(m))fwrite(n)fwrite(n)fwrite(C)fwrite(n)fwrite(MC)

elif igt160 and ilt321G=bipartiteconfiguration model(aseq2 bseq2 create using=None seed=None)A=nxadjacency matrix(G)for ii in range(0n2+me2)

maadd node(ii)A=[Rtodense()tolist()[0] for R in A]

printnummanumber of nodes()rl=randomsample(range(0n2+me2) n2+me2)m=0done vertices = set()for p in rlprintin fordone verticesadd(p)

neighbors = []list()for iii in range(0n2+me2)

if A[p][iii]==1neighborsappend(iii)

randomshuffle(neighbors)continue loop = Truedegree = len(neighbors)

print degreej = 0p4=randomrandom()while continue loop and (jltdegree)

print in loopnext = neighbors[j]if next not in done vertices and p not in done vertices

done verticesadd(p)done verticesadd(next)if p4gt=07

print added edgemaadd edge(pnext)m=m+1

continue loop = Falsej += 1

print matching listOfedgeprint maedge

MA=nxadjacency matrix(ma)print MA

MA=[Rtodense()tolist()[0] for R in MA]print MA

B=[ join(map(strR)) for R in A]MB=[ join(map(strR)) for R in MA]

42 Application

C=njoin(B)+nMC=njoin(MB)+n

print nprint mprint m1

filea=str(i)+txtwith open(fileaw) as f

fwrite(str(n2+me2))fwrite(n)fwrite(str(n2+me2))fwrite(n)fwrite(str(m))fwrite(n)fwrite(n)fwrite(C)fwrite(n)fwrite(MC)

elseG=bipartiteconfiguration model(aseq3 bseq3 create using=None seed=None)A=nxadjacency matrix(G)for ii in range(0n3+me3)

maadd node(ii)A=[Rtodense()tolist()[0] for R in A]

printnummanumber of nodes()rl=randomsample(range(0n3+me3) n3+me3)m=0done vertices = set()for p in rlprintin fordone verticesadd(p)

neighbors = []list()for iii in range(0n3+me3)

if A[p][iii]==1neighborsappend(iii)

randomshuffle(neighbors)continue loop = Truedegree = len(neighbors)

print degreej = 0p4=randomrandom()while continue loop and (jltdegree)

print in loopnext = neighbors[j]if next not in done vertices and p not in done vertices

done verticesadd(p)done verticesadd(next)if p4gt=07print added edge

maadd edge(pnext)m=m+1

continue loop = Falsej += 1

Appendix A 43

print matching listOfedgeprint maedge

MA=nxadjacency matrix(ma)print MA

MA=[Rtodense()tolist()[0] for R in MA]print MA

B=[ join(map(strR)) for R in A]MB=[ join(map(strR)) for R in MA]

C=njoin(B)+nMC=njoin(MB)+n

print nprint mprint m1

filea=str(i)+txtwith open(fileaw) as f

fwrite(str(n3+me3))fwrite(n)fwrite(str(n3+me3))fwrite(n)fwrite(str(m))fwrite(n)fwrite(n)fwrite(C)fwrite(n)fwrite(MC)

print nRandom graphs with random matching have been generated

44 Application

RandomGraphGeneratorpy

from future import divisionimport networkx as nxfrom networkxalgorithms import approximationimport collectionsimport randomimport mathif name == main

for i in range(1481)index=1n=randomrandint(100 1000)

n=1000m=0m1=0p=randomrandom()p1=mathlog(n2)np2=13p3=mathlog(n2)n+01p=05t1=randomrandint(0 1)print im2=randomrandint(n2minus1 n2+1)G = nxGraph()ma = nxGraph()print nme1=randomrandint(1 10)me2=randomrandint(2050)me3=randomrandint(50100)if ilt241

if ilt=80G=nxfast gnp random graph(n p1 seed=None directed=False)

elif igt80 and ilt161G=nxfast gnp random graph(n p2 seed=None directed=False)

elseG=nxfast gnp random graph(n p3 seed=None directed=False)

elseif ilt=320

G=nxbarabasi albert graph(n me1 seed=None)elif igt320 and ilt401

G=nxbarabasi albert graph(n me2 seed=None)else

G=nxbarabasi albert graph(n me3 seed=None)A=nxadjacency matrix(G)for ii in range(0n)

maadd node(ii)A=[Rtodense()tolist()[0] for R in A]

rl=randomsample(range(0n) n)m=0

Appendix A 45

done vertices = set()for p in rl

done verticesadd(p)neighbors = []list()for iii in range(0n)

if A[p][iii]==1neighborsappend(iii)

randomshuffle(neighbors)continue loop = Truedegree = len(neighbors)j = 0p2=randomrandom()while continue loop and (jltdegree)

next = neighbors[j]if next not in done vertices and p not in done vertices

done verticesadd(p)done verticesadd(next)if p2gt=00 Larger probability for smaller initial matching

maadd edge(pnext)m=m+1

continue loop = Falsej += 1

print matching listOfedgeprint maedgeMA=nxadjacency matrix(ma)MA=[Rtodense()tolist()[0] for R in MA]print MAB=[ join(map(strR)) for R in A]MB=[ join(map(strR)) for R in MA]

C=njoin(B)+nMC=njoin(MB)+nprint MCprint nprint mprint m1filea=str(i)+txtwith open(fileaw) as f

fwrite(str(n))fwrite(n)fwrite(str(n))fwrite(n)fwrite(str(m))fwrite(n)fwrite(n)fwrite(C)fwrite(n)fwrite(MC)

print nRandom graphs with random matching have been generated

46 Application

kequals3MaximumMatchingpy

from future import divisionimport networkx as nxfrom networkxalgorithms import bipartiteimport matplotlibpyplot as pltimport collectionsimport timeitimport xlwtimport xlrdimport mathimport sys

Case for General Graphsdef forced edges(Gadj dict2matching dict1num nodesforced)

flagg=0for n in range(0num nodes)

for k in adj dict2[n]if ([k]==matching dict1[n])

count=0for l in range(0num nodes)

count=count+adj dict2[l]count(k)if (len(adj dict2[n])==1) or (count==1)

forcedadd edge(nk)Gremove edge(nk)Gremove node(n)Gremove node(k)printforced edgenktemp=kflagg=1for m in range (len(adj dict2[n])minus1minus1minus1)

adj dict2[adj dict2[n][m]]remove(n)adj dict2[n]remove(adj dict2[n][m])

if adj dict2[temp]for l in range(len(adj dict2[temp])minus1minus1minus1)

if (adj dict2[temp][l]=n)adj dict2[adj dict2[temp][l]]remove(temp)adj dict2[temp]remove(adj dict2[temp][l])

break

def useless edges(num nodesadj dict1matching dict1uselessadj dict2G)for n in range(0num nodes)

for k in adj dict1[n]if ([k]=matching dict1[n]) and matching dict1[n] and matching dict1[k]

uselessadd edge(nk)Gremove edge(n k)

Appendix A 47

tempa=kadj dict2[n]remove(k)adj dict2[tempa]remove(n)adj dict1[tempa]remove(n)

return G

def Greedy(num nodesadj dict3matching dict2)

for n in range(0num nodes)if matching dict2[n]

flag2=minus1flag3=minus1for v in adj dict3[n]

if not matching dict2[v]flag2=vbreak

for p in adj dict3[matching dict2[n][0]]if not matching dict2[p]

flag3=pbreak

if (flag2=minus1) and (flag3=minus1) and (flag2=flag3)tempr=matching dict2[n][0]matching dict2[n]=[flag2]matching dict2[flag2]=[n]matching dict2[tempr]=[flag3]matching dict2[flag3]=[tempr]

elsefor k in adj dict3[n]

if not matching dict2[k]matching dict2[n]=[k]matching dict2[k]=[n]break

yo1=0for i in range(0num nodes)

if matching dict2[i] and [i]==matching dict2[matching dict2[i][0]]yo1=yo1+1

greedy size=yo12return greedy size

def General()

INPUTSwb = xlwtWorkbook()ws = wbadd sheet(Results Random)book=xlrdopen workbook(filenames randomxls)

48 Application

style0 = xlwteasyxf(fontbold on)style1 = xlwteasyxf(num format str=0000)INPUTSwswrite(0 0File style0)wswrite(0 1 Nodesstyle0)wswrite(0 2 Initial matchingstyle0)wswrite(0 3 NodesGstyle0)wswrite(0 4 EdgesGstyle0)wswrite(0 5 MaxDegreeGstyle0)wswrite(0 6 NodesG hatstyle0)wswrite(0 7 EdgesG Hatstyle0)wswrite(0 8 Useless edgesstyle0)wswrite(0 9 Forced edgesstyle0)wswrite(0 10 MaxDegreeG Hatstyle0)wswrite(0 11 Classical matchingstyle0)wswrite(0 12 Final matchingstyle0)wswrite(0 13 Greedy matchingstyle0)wswrite(0 14 Time classicalstyle0)wswrite(0 15 Time algorithmstyle0)wswrite(0 16 Time greedystyle0)wswrite(0 17 Perfect matching ratiostyle0)wswrite(0 18 Nodes ratiostyle0)wswrite(0 19 Edges ratiostyle0)wswrite(0 20 Matching ratiostyle0)

print nWelcomeThis is an implementation for general random graphs It uses Edmonds algorithm to compute maximum matching on G Hatn

for index in range (1481)was 481

if (index==482)f=open(Algotel generaltxtr)readlines()

elsefilea=str(booksheet by index(0)cell(index0))s=fileareplace(textu)replace()f=open(sr)readlines()Truewswrite(index 0 s)

print index

num nodes=int([xstrip()split() for x in f][0][0])

num matching=int([xstrip()split() for x in f][2][0])

adj temp = [xstrip()split() for x in f][44+num nodes]adj=[map(intR) for R in adj temp]

matching temp=[xstrip()split() for x in f][4+num nodes+14+2num nodes+1]matching1=[map(intR) for R in matching temp]

adj dict1=i[ii for iix in enumerate(L) if x] for iL in enumerate(adj)adj dict2=i[ii for iix in enumerate(L) if x] for iL in enumerate(adj)

Appendix A 49

adj dict3=i[ii for iix in enumerate(L) if x] for iL in enumerate(adj)

matching dict1=i[ii for iix in enumerate(L) if x] for iL in enumerate(matching1)matching dict2=i[ii for iix in enumerate(L) if x] for iL in enumerate(matching1)print adj dict2print matching dict2wswrite(index 1 num nodes)wswrite(index 2 num matching)

G = nxGraph()

useless= nxGraph()forced = nxGraph()

Fill Graphfor n in range(0num nodes)

for k in adj dict1[n]Gadd edge(nk)

Gt=Gnumber of edges()wswrite(index 3 Gnumber of nodes())wswrite(index 4 Gnumber of edges())wswrite(index 5 max(Gdegree()values()))

Compute Edmonds classical matching on G for comparison

startB = timeitdefault timer()Classical Matching=nxmax weight matching(G maxcardinality=False)stopB = timeitdefault timer()

Compute Gˆ nad MˆstartC = timeitdefault timer()useless edges(num nodesadj dict1matching dict1uselessadj dict2G)forced edges(Gadj dict2matching dict1num nodesforced)Final Matching=nxmax weight matching(G maxcardinality=False)stopC = timeitdefault timer()

GreedystartG = timeitdefault timer()greedy size=Greedy(num nodesadj dict3matching dict2)stopG = timeitdefault timer()

wswrite(index 6 Gnumber of nodes())wswrite(index 7 Gnumber of edges())wswrite(index 8 uselessnumber of edges())wswrite(index 9 forcednumber of edges())if Gdegree()values()

wswrite(index 10 max(Gdegree()values()))else

50 Application

wswrite(index 10 0)wswrite(index 11 len(Classical Matching)2)wswrite(index 12 len(Final Matching)2+forcednumber of edges())wswrite(index 13 greedy size)wswrite(index 14 stopB minus startBstyle1)wswrite(index 15 stopC minus startCstyle1)wswrite(index 16 stopG minus startGstyle1)wswrite(index 17 (len(Final Matching)2+forcednumber of edges())(num nodes2)style1)wswrite(index 18 Gnumber of nodes()Gtstyle1)wswrite(index 19 Gnumber of edges()Gtstyle1)wswrite(index 20 (len(Final Matching)2+forcednumber of edges())(len(Classical Matching)2)style1)

wbsave(AA Results Random Reyni Large Bipartitexls)

Main function Here we must choose the input form of the dataif name == main

startA = timeitdefault timer()General()stopA = timeitdefault timer()

print nThis program has terminatednnRunning time for 480 files stopAminusstartAprint nnPlease open AA Results Random Reyni Largexls file to see the Results

Appendix A 51

Plotmat

clear allclose allload(RN1Lmat)load(RN1Smat)load(RN2Lmat)load(RN2Smat)load(RN3Lmat)load(RN3Smat)

Plotsh(1)=figure(NameHistogram of Matching size difference between Constraint Algorithm and Greedy AlgorithmNumberTitleoff)

RN1L Greedydiff=RN1L Final matchingminusRN1L Greedy matchingRN2L Greedydiff=RN2L Final matchingminusRN2L Greedy matchingRN3L Greedydiff=RN3L Final matchingminusRN3L Greedy matchingRN1S Greedydiff=RN1S Final matchingminusRN1S Greedy matchingRN2S Greedydiff=RN2S Final matchingminusRN2S Greedy matchingRN3S Greedydiff=RN3S Final matchingminusRN3S Greedy matching

RN1L Finaldiff=RN1L Classical matchingminusRN1L Final matchingRN2L Finaldiff=RN2L Classical matchingminusRN2L Final matchingRN3L Finaldiff=RN3L Classical matchingminusRN3L Final matchingRN1S Finaldiff=RN1S Classical matchingminusRN1S Final matchingRN2S Finaldiff=RN2S Classical matchingminusRN2S Final matchingRN3S Finaldiff=RN3S Classical matchingminusRN3S Final matching

RN1L Classicaldiff=(RN1L Nodes2)minusRN1L Classical matchingRN2L Classicaldiff=(RN2L Nodes2)minusRN2L Classical matchingRN3L Classicaldiff=(RN3L Nodes2)minusRN3L Classical matchingRN1S Classicaldiff=(RN1S Nodes2)minusRN1S Classical matchingRN2S Classicaldiff=(RN2S Nodes2)minusRN2S Classical matchingRN3S Classicaldiff=(RN3S Nodes2)minusRN3S Classical matching

subplot(231)hold onhistf(RN1L Greedydiff0110facecolorbfacealpha9edgealpha1)histf(RN1L Finaldiff0110facecolorrfacealpha5edgealpha1)histf(RN1L Classicaldiff0110facecolorgfacealpha5edgealpha1)legalpha(ConminusGreClasminusConPerfminusClasslocationnortheast)legend boxoffaxis tightxlabel(edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN1L)grid on

subplot(232)hold onhistf(RN2L Greedydiff0110facecolorbfacealpha9edgealpha1)

52 Application

histf(RN2L Finaldiff0110facecolorrfacealpha5edgealpha1)histf(RN2L Classicaldiff0110facecolorgfacealpha5edgealpha1)legalpha(ConminusGreClasminusConPerfminusClasslocationnortheast)legend boxoffaxis tightxlabel(edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN2L)grid on

subplot(233)hold onhistf(RN3L Greedydiff0110facecolorbfacealpha5edgealpha1)histf(RN3L Finaldiff0110facecolorrfacealpha5edgealpha1)histf(RN3L Classicaldiff0110facecolorgfacealpha5edgealpha1)legalpha(ConminusGreClasminusConPerfminusClasslocationnortheast)legend boxoffaxis tightxlabel(edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN3L)grid on

subplot(234)hold onhistf(RN1S Greedydiff0110facecolorbfacealpha5edgealpha1)histf(RN1S Finaldiff0110facecolorrfacealpha5edgealpha1)histf(RN1S Classicaldiff0110facecolorgfacealpha5edgealpha1)legalpha(ConminusGreClasminusConPerfminusClasslocationnortheast)legend boxoffaxis tightxlabel(edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(R1NS)grid on

subplot(235)hold onhistf(RN2S Greedydiff0110facecolorbfacealpha5edgealpha1)histf(RN2S Finaldiff0110facecolorrfacealpha5edgealpha1)histf(RN2S Classicaldiff0110facecolorgfacealpha5edgealpha1)legalpha(ConminusGreClasminusConPerfminusClasslocationnortheast)legend boxoffaxis tightxlabel(edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN2S)grid on

subplot(236)hold onhistf(RN3S Greedydiff0110facecolorbfacealpha5edgealpha1)histf(RN3S Finaldiff0110facecolorrfacealpha5edgealpha1)histf(RN3S Classicaldiff0110facecolorgfacealpha5edgealpha1)

Appendix A 53

legalpha(ConminusGreClasminusConPerfminusClasslocationnortheast)legend boxoffaxis tightgrid ontitle(RN3S)xlabel(edges) xminusaxis labelylabel(instances) yminusaxis labelset(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN1png minusr300)h(2)=figure(NameHistogram of Max Degree of G AND G HatNumberTitleoff)RN1L x=RN1L MaxDegreeGminusRN1L MaxDegreeG HatRN2L x=RN2L MaxDegreeGminusRN2L MaxDegreeG HatRN3L x=RN3L MaxDegreeGminusRN3L MaxDegreeG HatRN1S x=RN1S MaxDegreeGminusRN1S MaxDegreeG HatRN2S x=RN2S MaxDegreeGminusRN2S MaxDegreeG HatRN3S x=RN3S MaxDegreeGminusRN3S MaxDegreeG Hatsubplot(231)hold onhistf(RN1L MaxDegreeG0150facecolorbfacealpha5edgealpha1)histf(RN1L MaxDegreeG Hat0150facecolorrfacealpha5edgealpha1)histf(RN1L x0150facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightxlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN1L)grid on

subplot(232)hold onhistf(RN2L MaxDegreeG010500facecolorbfacealpha5edgealpha1)histf(RN2L MaxDegreeG Hat010500facecolorrfacealpha5edgealpha1)histf(RN2L x010500facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightxlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN2L)grid on

subplot(233)hold onhistf(RN3L MaxDegreeG010300facecolorbfacealpha5edgealpha1)histf(RN3L MaxDegreeG Hat010300facecolorrfacealpha5edgealpha1)histf(RN3L x010300facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightxlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN3L)

54 Application

grid on

subplot(234)hold onhistf(RN1S MaxDegreeG0150facecolorbfacealpha5edgealpha1)histf(RN1S MaxDegreeG Hat0150facecolorrfacealpha5edgealpha1)histf(RN1S x0150facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightxlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(R1NS)grid on

subplot(235)hold onhistf(RN2S MaxDegreeG010500facecolorbfacealpha5edgealpha1)histf(RN2S MaxDegreeG Hat010500facecolorrfacealpha5edgealpha1)histf(RN2S x010500facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightxlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN2S)grid on

subplot(236)hold onhistf(RN3S MaxDegreeG05300facecolorbfacealpha5edgealpha1)histf(RN3S MaxDegreeG Hat05300facecolorrfacealpha5edgealpha1)histf(RN3S x05300facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightgrid ontitle(RN3S)xlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labelset(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN2png minusr300)

h(3)=figure(NameComputation time over edgesNumberTitleoff)

subplot(231)hold onstem(RN1L EdgesGRN1L Time classicalg)stem(RN1L EdgesGRN1L Time algorithmro)stem(RN1L EdgesGRN1L Time greedybx)grid on

Appendix A 55

title(RN1L)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)

subplot(232)hold onstem(RN2L EdgesGRN2L Time classicalg)stem(RN2L EdgesGRN2L Time algorithmro)stem(RN2L EdgesGRN2L Time greedybx)grid ontitle(RN2L)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)

subplot(233)hold onstem(RN3L EdgesGRN3L Time classicalg)stem(RN3L EdgesGRN3L Time algorithmro)stem(RN3L EdgesGRN3L Time greedybx)grid ontitle(RN3L)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)

subplot(234)hold onstem(RN1S EdgesGRN1S Time classicalg)stem(RN1S EdgesGRN1S Time algorithmro)stem(RN1S EdgesGRN1S Time greedybx)grid ontitle(RN1S)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)

subplot(235)hold onstem(RN2S EdgesGRN2S Time classicalg)stem(RN2S EdgesGRN2S Time algorithmro)stem(RN2S EdgesGRN2S Time greedybx)grid ontitle(RN2S)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)

subplot(236)hold onstem(RN3S EdgesGRN3S Time classicalg)stem(RN3S EdgesGRN3S Time algorithmro)stem(RN3S EdgesGRN3S Time greedybx)

56 Application

grid ontitle(RN3S)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)set(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN3png minusr300)

h(4)=figure(NameSorted matching sizeNumberTitleoff)RN1L Sorted matching temp(1)=RN1L Classical matchingRN1L Sorted matching temp(2)=RN1L Final matchingRN1L Sorted matching temp(3)=RN1L Greedy matchingRN1L Sorted matching temp(4)=RN1L Initial matchingRN1L Sorted matching=sortrows(RN1L Sorted matching temp)

RN2L Sorted matching temp(1)=RN2L Classical matchingRN2L Sorted matching temp(2)=RN2L Final matchingRN2L Sorted matching temp(3)=RN2L Greedy matchingRN2L Sorted matching temp(4)=RN2L Initial matchingRN2L Sorted matching=sortrows(RN2L Sorted matching temp)

RN3L Sorted matching temp(1)=RN3L Classical matchingRN3L Sorted matching temp(2)=RN3L Final matchingRN3L Sorted matching temp(3)=RN3L Greedy matchingRN3L Sorted matching temp(4)=RN3L Initial matchingRN3L Sorted matching=sortrows(RN3L Sorted matching temp)

RN1S Sorted matching temp(1)=RN1S Classical matchingRN1S Sorted matching temp(2)=RN1S Final matchingRN1S Sorted matching temp(3)=RN1S Greedy matchingRN1S Sorted matching temp(4)=RN1S Initial matchingRN1S Sorted matching=sortrows(RN1S Sorted matching temp)

RN2S Sorted matching temp(1)=RN2S Classical matchingRN2S Sorted matching temp(2)=RN2S Final matchingRN2S Sorted matching temp(3)=RN2S Greedy matchingRN2S Sorted matching temp(4)=RN2S Initial matchingRN2S Sorted matching=sortrows(RN2S Sorted matching temp)

RN3S Sorted matching temp(1)=RN3S Classical matchingRN3S Sorted matching temp(2)=RN3S Final matchingRN3S Sorted matching temp(3)=RN3S Greedy matchingRN3S Sorted matching temp(4)=RN3S Initial matchingRN3S Sorted matching=sortrows(RN3S Sorted matching temp)

subplot(231)hold onplot(RN1L Sorted matching(1)b)plot(RN1L Sorted matching(2)g)plot(RN1L Sorted matching(3)r)plot(RN1L Sorted matching(4)m)

Appendix A 57

grid ontitle(RN1L)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)

subplot(232)hold onplot(RN2L Sorted matching(1)b)plot(RN2L Sorted matching(2)g)plot(RN2L Sorted matching(3)r)plot(RN2L Sorted matching(4)m)grid ontitle(RN2L)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)

subplot(233)hold onplot(RN3L Sorted matching(1)b)plot(RN3L Sorted matching(2)g)plot(RN3L Sorted matching(3)r)plot(RN3L Sorted matching(4)m)grid ontitle(RN3L)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)

subplot(234)hold onplot(RN1S Sorted matching(1)b)plot(RN1S Sorted matching(2)g)plot(RN1S Sorted matching(3)r)plot(RN1S Sorted matching(4)m)grid ontitle(RN1S)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)

subplot(235)hold onplot(RN2S Sorted matching(1)b)plot(RN2S Sorted matching(2)g)plot(RN2S Sorted matching(3)r)plot(RN2S Sorted matching(4)m)grid ontitle(RN2S)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)

58 Application

subplot(236)hold onplot(RN3S Sorted matching(1)b)plot(RN3S Sorted matching(2)g)plot(RN3S Sorted matching(3)r)plot(RN3S Sorted matching(4)m)grid ontitle(RN3S)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)set(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN4png minusr300)h(5)=figure(NameSorted RatiosNumberTitleoff)RN1L ratio1=RN1L NodesG hatRN1L NodesGRN2L ratio1=RN2L NodesG hatRN2L NodesGRN3L ratio1=RN3L NodesG hatRN3L NodesGRN1S ratio1=RN1S NodesG hatRN1S NodesGRN2S ratio1=RN2S NodesG hatRN2S NodesGRN3S ratio1=RN3S NodesG hatRN3S NodesG

RN1L ratio2=RN1L EdgesG HatRN1L EdgesGRN2L ratio2=RN2L EdgesG HatRN2L EdgesGRN3L ratio2=RN3L EdgesG HatRN3L EdgesGRN1S ratio2=RN1S EdgesG HatRN1S EdgesGRN2S ratio2=RN2S EdgesG HatRN2S EdgesGRN3S ratio2=RN3S EdgesG HatRN3S EdgesG

RN1L ratio3=RN1L MaxDegreeG HatRN1L MaxDegreeGRN2L ratio3=RN2L MaxDegreeG HatRN2L MaxDegreeGRN3L ratio3=RN3L MaxDegreeG HatRN3L MaxDegreeGRN1S ratio3=RN1S MaxDegreeG HatRN1S MaxDegreeGRN2S ratio3=RN2S MaxDegreeG HatRN2S MaxDegreeGRN3S ratio3=RN3S MaxDegreeG HatRN3S MaxDegreeG

RN1L ratio(1)=RN1L ratio1RN1L ratio(2)=RN1L ratio2RN1L ratio(3)=RN1L ratio3

RN2L ratio(1)=RN2L ratio1RN2L ratio(2)=RN2L ratio2RN2L ratio(3)=RN2L ratio3

RN3L ratio(1)=RN3L ratio1RN3L ratio(2)=RN3L ratio2RN3L ratio(3)=RN3L ratio3

RN1S ratio(1)=RN1S ratio1RN1S ratio(2)=RN1S ratio2RN1S ratio(3)=RN1S ratio3

RN2S ratio(1)=RN2S ratio1

Appendix A 59

RN2S ratio(2)=RN2S ratio2RN2S ratio(3)=RN2S ratio3

RN3S ratio(1)=RN3S ratio1RN3S ratio(2)=RN3S ratio2RN3S ratio(3)=RN3S ratio3

RN1L ratio sorted=sortrows(RN1L ratio)RN2L ratio sorted=sortrows(RN2L ratio)RN3L ratio sorted=sortrows(RN3L ratio)RN1S ratio sorted=sortrows(RN1S ratio)RN2S ratio sorted=sortrows(RN2S ratio)RN3S ratio sorted=sortrows(RN3S ratio)

subplot(231)hold onplot(RN1L ratio sorted(1)b)plot(RN1L ratio sorted(2)g)plot(RN1L ratio sorted(3)r)grid ontitle(RN1L)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)

subplot(232)hold onplot(RN2L ratio sorted(1)b)plot(RN2L ratio sorted(2)g)plot(RN2L ratio sorted(3)r)grid ontitle(RN2L)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)

subplot(233)hold onplot(RN3L ratio sorted(1)b)plot(RN3L ratio sorted(2)g)plot(RN3L ratio sorted(3)r)grid ontitle(RN3L)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)

subplot(234)hold onplot(RN1S ratio sorted(1)b)plot(RN1S ratio sorted(2)g)plot(RN1S ratio sorted(3)r)grid on

60 Application

title(RN1S)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)

subplot(235)hold onplot(RN2S ratio sorted(1)b)plot(RN2S ratio sorted(2)g)plot(RN2S ratio sorted(3)r)grid ontitle(RN2S)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)

subplot(236)hold onplot(RN3S ratio sorted(1)b)plot(RN3S ratio sorted(2)g)plot(RN3S ratio sorted(3)r)grid ontitle(RN3S)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)set(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN5png minusr300)

h(6)=figure(NameSorted edges over nodesNumberTitleoff)

RN1L DegreeG1=(RN1L EdgesG)(RN1L NodesG)RN1L DegreeG Hat1=(RN1L EdgesG Hat)(RN1L NodesG hat)

RN1L Degree temp1(1)=RN1L DegreeG1RN1L Degree temp1(2)=RN1L DegreeG Hat1RN1L Degree sorted1=sortrows(RN1L Degree temp1)subplot(231)hold on

plot(RN1L Degree sorted1(1)b)plot(RN1L Degree sorted1(2)g)grid ontitle(RN1L)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)

RN2L DegreeG1=(RN2L EdgesG)(RN2L NodesG)RN2L DegreeG Hat1=(RN2L EdgesG Hat)(RN2L NodesG hat)

RN2L Degree temp1(1)=RN2L DegreeG1

Appendix A 61

RN2L Degree temp1(2)=RN2L DegreeG Hat1RN2L Degree sorted1=sortrows(RN2L Degree temp1)

subplot(232)hold onplot(RN2L Degree sorted1(1)b)plot(RN2L Degree sorted1(2)g)grid ontitle(RN2L)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)

RN3L DegreeG1=(RN3L EdgesG)(RN3L NodesG)RN3L DegreeG Hat1=(RN3L EdgesG Hat)(RN3L NodesG hat)

RN3L Degree temp1(1)=RN3L DegreeG1RN3L Degree temp1(2)=RN3L DegreeG Hat1RN3L Degree sorted1=sortrows(RN3L Degree temp1)

subplot(233)hold onplot(RN3L Degree sorted1(1)b)plot(RN3L Degree sorted1(2)g)grid ontitle(RN3L)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)

RN1S DegreeG1=(RN1S EdgesG)(RN1S NodesG)RN1S DegreeG Hat1=(RN1S EdgesG Hat)(RN1S NodesG hat)

RN1S Degree temp1(1)=RN1S DegreeG1RN1S Degree temp1(2)=RN1S DegreeG Hat1RN1S Degree sorted1=sortrows(RN1S Degree temp1)

subplot(234)hold onplot(RN1S Degree sorted1(1)b)plot(RN1S Degree sorted1(2)g)grid ontitle(RN1S)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)

RN2S DegreeG1=(RN2S EdgesG)(RN2S NodesG)RN2S DegreeG Hat1=(RN2S EdgesG Hat)(RN2S NodesG hat)

RN2S Degree temp1(1)=RN2S DegreeG1

62 Application

RN2S Degree temp1(2)=RN2S DegreeG Hat1RN2S Degree sorted1=sortrows(RN2S Degree temp1)

subplot(235)hold onplot(RN2S Degree sorted1(1)b)plot(RN2S Degree sorted1(2)g)grid ontitle(RN2S)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)

RN3S DegreeG1=(RN3S EdgesG)(RN3S NodesG)RN3S DegreeG Hat1=(RN3S EdgesG Hat)(RN3S NodesG hat)

RN3S Degree temp1(1)=RN3S DegreeG1RN3S Degree temp1(2)=RN3S DegreeG Hat1RN3S Degree sorted1=sortrows(RN3S Degree temp1)

subplot(236)hold onplot(RN3S Degree sorted1(1)b)plot(RN3S Degree sorted1(2)g)grid ontitle(RN3S)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)set(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN6png minusr300)h(7)=figure(NameSorted mATCHED DEGREENumberTitleoff)RN1L ratioMax(1)=RN1L MaxDegreeGRN1L ratioMax(2)=RN1L MaxDegreeG Hat

RN1L ratio sortedMax=sortrows(RN1L ratioMax)subplot(231)hold onplot(RN1L ratio sortedMax(1)b)plot(RN1L ratio sortedMax(2)g)grid ontitle(RN1L)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)

RN2L ratioMax(1)=RN2L MaxDegreeGRN2L ratioMax(2)=RN2L MaxDegreeG Hat

RN2L ratio sortedMax=sortrows(RN2L ratioMax)subplot(232)

Appendix A 63

hold onplot(RN2L ratio sortedMax(1)b)plot(RN2L ratio sortedMax(2)g)grid ontitle(RN2L)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)

RN3L ratioMax(1)=RN3L MaxDegreeGRN3L ratioMax(2)=RN3L MaxDegreeG Hat

RN3L ratio sortedMax=sortrows(RN3L ratioMax)subplot(233)hold onplot(RN3L ratio sortedMax(1)b)plot(RN3L ratio sortedMax(2)g)grid ontitle(RN3L)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)

RN1S ratioMax(1)=RN1S MaxDegreeGRN1S ratioMax(2)=RN1S MaxDegreeG Hat

RN1S ratio sortedMax=sortrows(RN1S ratioMax)subplot(234)hold onplot(RN1S ratio sortedMax(1)b)plot(RN1S ratio sortedMax(2)g)grid ontitle(RN1S)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)

RN2S ratioMax(1)=RN2S MaxDegreeGRN2S ratioMax(2)=RN2S MaxDegreeG Hat

RN2S ratio sortedMax=sortrows(RN2S ratioMax)

subplot(235)hold onplot(RN2S ratio sortedMax(1)b)plot(RN2S ratio sortedMax(2)g)grid ontitle(RN2S)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)

RN3S ratioMax(1)=RN3S MaxDegreeGRN3S ratioMax(2)=RN3S MaxDegreeG Hat

64 Application

RN3S ratio sortedMax=sortrows(RN3S ratioMax)subplot(236)hold onplot(RN3S ratio sortedMax(1)b)plot(RN3S ratio sortedMax(2)g)grid ontitle(RN1L)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)set(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN7png minusr300)

tilefigs()(h)

Bibliography

[1] C Berge ldquoTWO THEOREMS IN GRAPH THEORYrdquo Proceedings of the NationalAcademy of Sciences of the United States of America vol 43 no 9 pp 842ndash844Sep 1957

[2] L Bui S Sanghavi and R Srikant ldquoDistributed link scheduling with constantoverheadrdquo IEEEACM Trans Netw vol 17 no 5 pp 1467ndash1480 2009

[3] R Duan and S Pettie ldquoLinear-time approximation for maximum weight matchingrdquoJ ACM vol 61 no 1 2014

[4] J Edmonds ldquoPaths trees and flowersrdquo Canadian Journal of Mathematics vol 17pp 449ndash467 1965

[5] J E Hopcroft and R M Karp ldquoAn n52 algorithm for maximum matchings inbipartite graphsrdquo SIAM J Comput vol 2 no 4 pp 225ndash231 1973

[6] S Micali and V V Vazirani ldquoAn O(radic|V ||E|) algorithm for finding maximum

matching in general graphsrdquo in 21st Symp on Foundations of Comp Sc (FOCS)IEEE 1980 pp 17ndash27

[7] N Nisse A Salch and V Weber ldquoRecovery of disrupted airline operationsrdquo 2015httphalinriafrSomething

[8] X Wu and R Srikant ldquoRegulated maximal matching A distributed schedulingalgorithm for multi-hop wireless networks with nodeexclusive spectrum sharingrdquo inIEEE Conf on Decision and Control 2005

65

  • Contents
  • Introduction
  • Algorithms
    • Maximum matching
    • k-maximum matching
      • k-matching for Airport Slot assignment
      • The case where k=3
      • The case of Paths
      • The case of the Spider
          • Application
            • Description
            • Reyni Erdos
            • Barabaacutesi Albert
            • Amadeus Graphs
            • Bipartite
            • Bipartite with degree seq
            • Appendix A
              • BipartiteGraphGeneratorpy
              • RandomGraphGeneratorpy
              • kequals3MaximumMatchingpy
              • Plotmat
                  • Bibliography
Page 10: Theodoros Alexandros KARAGKIOULES -  · Introduction This work is the result of a 6 months internship, under the supervision of research O cer Nicolas NISSE. The original scope of

22 Reyni Erdos 11

bull When the initial matching is sufficiently large then the forced edges are taken out(a process which takes a fragment of the computation time) and then the classicalmatching algorithm (Edmonds) is applied on a smaller graph(G) This reducessignificantly the computation time

bull When the initial matching is small then the computation time of the constraintalgorithm might be larger than that of Edmonds The reason is that the constraintalgorithm need some time to compute the useless and forced edges and thenEdmonds algorithm is applied on G G Thus the overall processing time issometimes larger

Sorted matching size

Sorted matching size - Comments

12 Application

bull This set of figures represents the ascending order of the Classical matching sizealong with its corresponding Constraint and Greedy equivalent

bull When the probability is sufficiently higher than the threshold lognn

then the threealgorithms produce identical results of optimal matching

bull For lower probability there is a difference between the results of the algorithms

bull the degree of that difference is depicted in the first set of figures presented

bull It is interesting to observe that a change on the Constraint algorithm is associatedwith a even more significant change in the Greedy algorithm

bull There is a difference only when the probability is at the connectedness threshholdlognn

bull The difference is very small compared to the size of the matching ( 500)

bull The difference in matching size appears mostly at the Greedy implementationwhen compared to the constraint algorithm

Sorted Ratios

22 Reyni Erdos 13

Sorted Ratios - Comments

bull This set of figures depicts the ratios VV

EE

∆∆

in ascending order of VV

bull It is evident that when the initial matching is large the amount of forced edges(and their endpoints) removed is high thus the ratio of Nodes and edges is verylow For higher probabilities almost all edges are removed as useless

bull For a smaller initial matching almost no forced edges (and their endpoints) areremoved which we conclude be the node ration being close to 1 There is somesmall amount of useless edges removed though since the ratio of edges is less butclose to 1

bull The ratio of ∆ for large initial matching follows the trend of the node ratio yetfor smaller initial matching it deviates significantly

14 Application

Sorted |E||V |

Sorted |E||V | - Comments

bull Although as graph density the ratio 2|E||V |(|V |minus1)

is considered in this set of figures

we evaluate the correlation of the ratio |E||V | of G and G since the density of G

could acquire values higher than that of G

bull The figures are calculated in ascending order for the ratio of G

bull For the case of large initial matching the two ratios for G and G remain almostconstant ( to the extent of the probability of each graph) since removing forcededges( and their endpoints) alters the |E| and |V | proportionately

22 Reyni Erdos 15

bull For the case of small initial matching we observe some deviation in the valuesof the ration for G and that is explained with the removal of only useless edgeswhich only alters the |E| and keeps |V | in the original values

Sorted ∆

Sorted ∆-Comments

bull In this set of figures the ascending order of the ∆ of G is associated with the ∆of G

bull There is no significant jump of the ∆ for each graph category which tells that thatwe are comparing a uniform distribution of random grapghs for each probabilitycase

16 Application

bull For larger initial matching we observe the difference in the ∆s of G and G giventhe removed forced edges( and their endpoints) At some cases the ∆ of G dropsto 0 since the vast majority of edges have been declared forced and removed alongwith their endpoints

bull For smaller initial matching the ∆s of G and G follow mostly the same trend onlya few number of different instances

23 Barabasi Albert

Graph characteristics Barabasi Albert

bull BAxy are randomly generated graphs with a fixed number of 1000 nodes

bull There are 6 categories based on ini matching and of attached edges m

bull x = L S L When the initial matching is large and S when it is small

bull y = 1 2 3 1 when m = [1 10] 2 when m = [20 50] and 3 m = [50 100]

Computation time over |E|

23 Barabasi Albert 17

Computation time over |E| - Comments

bull When the initial matching is sufficiently large then the forced edges are taken out(a process which takes a fragment of the computation time) and then the classicalmatching algorithm (Edmonds) is applied on a smaller graph(G) This reducessignificantly the computation time

bull When the initial matching is small then the computation time of the constraintalgorithm might be larger than that of Edmonds The reason is that the constraintalgorithm need some time to compute the useless and forced edges and thenEdmonds algorithm is applied on G G Thus the overall processing time issometimes larger

Sorted matching size

18 Application

Sorted matching size-Comments

bull In this graph the matching size of the classical algorithm is depicted in ascendingorder along with the corresponding constraint algorithm and greedy result

bull Here in the case where m is small for both cases of initial matching (small large)the result may vary greatly starting from a value of half the perfect matching withsmall differences between the results of the various algorithm implementations

bull For the other cases of m the results converge

bull This is explained as for small values of m the graph is disconnected

bull In the matching size difference set of figures a very noticing difference value ap-pears For the cases of small m( the number of existing nodes that a new node isconnected to at the creation of the graph) we can see that the difference in the

23 Barabasi Albert 19

matching size compared to that of the perfect matching could be up to 40 ofthat of the matching size So there are occasions where the matching size is 200edges when the perfect matching would have been 500

bull the difference between the Constraint matching and the classical matching andthe difference of the constraint matching and that of the greedy matching do notshow significant values

Sorted Ratios

Sorted Ratio s -Comments

bull This set of figures depicts the ratios VV

EE

∆∆

in ascending order of VV

20 Application

bull It is evident that when the initial matching is large the amount of forced edges(and their endpoints) removed is high thus the ratio of Nodes and edges is verylow For higher probabilities almost all edges are removed as useless

bull For a smaller initial matching almost no forced edges (and their endpoints) areremoved which we conclude be the node ration being close to 1 There is somesmall amount of useless edges removed though since the ratio of edges is less butclose to 1

bull The ratio of ∆ for large initial matching follows the trend of the node ratio yetfor smaller initial matching it deviates significantly

Sorted |E||V |

23 Barabasi Albert 21

Sorted |E||V | - Comments

bull Although as graph density the ratio 2|E||V |(|V |minus1)

is considered in this set of figures

we evaluate the correlation of the ratio |E||V | of G and G since the density of G

could acquire values higher than that of G

bull The figures are calculated in ascending order for the ratio of G

bull For the case of large initial matching the two ratios for G and G remain almostconstant ( to the extent of the edge attraction m of each graph) since removingforced edges( and their endpoints) alters the |E| and |V | proportionately

bull For the case of small initial matching we observe some deviation in the valuesof the ration for G and that is explained with the removal of only useless edgeswhich only alters the |E| and keeps |V | in the original values

Sorted ∆

22 Application

Sorted ∆-Comments

bull In this set of figures the ascending order of the ∆ of G is associated with the ∆of G

bull There is a significant jump of the ∆ for each graph category which tells that thatwe are not comparing a uniform distribution of random graphs and based on theedge attraction m the graphs can vary in form

bull For larger initial matching we observe the difference in the ∆s of G and G giventhe removed forced edges( and their endpoints) At some cases the ∆ of G dropsto 0 since the vast majority of edges have been declared forced and removed alongwith their endpoints What is interesting is that the ∆ of G oscilates within stablelimits

24 Amadeus Graphs 23

bull For smaller initial matching the ∆s of G and G follow mostly the same trend onlya few number of different instances

24 Amadeus Graphs

Graph characteristics Amadeus graphs

bull These are the bipartite graphs provided by Amadeus

Computation time over |E|

Computation time over |E| - Comments

24 Application

bull For every instance the computation time of the classical algorithm is always smallerto that of the constraint matching

bull This allows as to speculate that we always compute a smaller G which also impliesthat we always find a set of forced edges and useless

Sorted matching size

Sorted matching size - Comments

bull Size of matching has an upward trend since the magnitude of the graphs is notthe same for the 160 instances

bull No significant deviation is noticed as per the first graph

24 Amadeus Graphs 25

bull Except from deviation from the perfect matching (number of flights) where some-times it could get up to 40

bull For the Amadeus Bipartite graphs we can see that the difference of the Classicaland the constraint implementation is not more than 1 edge in the matching

bull There appears to be a difference of up to 24 edges between the Classical matchingand the Perfect matching which is computed as the number of flights

bull The greedy algorithm performs well with only a few instances deviating slightlyform the Constraint algorithm result

Sorted Ratios

Sorted Ratios - Comments

26 Application

bull

Sorted |E||V |

Sorted |E||V | - Comments

bull Density of the graphs shows that on average we have 25-3 available time slot perflight

bull The line for the same value for G shows that there is a large deviation for everyinstance which allows for the hypothesis that the amount of useless+forced edgesof G has no obvious correlation to that of G

25 Bipartite 27

Sorted ∆

Sorted ∆-Comments

bull As per the previous related graphs for ∆ there is in significant drop in the ∆ of Gand G

25 Bipartite

Graph characteristics Bipartite random Graphs

bull BIPxy are randomly generated graphs with a fixed number of 1000(n=500 andm=500) nodes

bull There are 6 categories based on ini matching and probability p

28 Application

bull Probability p has been chosen as such in order to simulate the |E||V | 25 of theAmadeus bipartite graphs

bull So in order to have about 2-4 edges for every node we choose accordingly theprobability p to choose one of the n lowastm possible edges

bull x = L S L When the initial matching is large and S when it is small

bull y = 1 2 3 1 when p = 18250

2 when p = 25250

and 3 when p = 34250

Computation time over

Computation time overedges-Comments

bull

25 Bipartite 29

Sorted matching size

Sorted matching size-Comments

bull In these set of graphs one can instantly notice that only a few instances with highprobability can reach a matching size equal to the perfect matching

bull For the case of the initial matching we witness that there is a gap between the lineof the classical matching and those of the constraint and greedy results suggestingsmaller matching sizes of 10-40 edges

bull For the case of the small initial matching the result of the constraint matchingis now close to the result of the classical matching yet the greedy algorithm stillshows a relevantly big difference

30 Application

bull In this set of bipartite graphs we can witness that the result of the Constraintmatching shows a difference with the classical matching when the initial matchingis large The difference is smaller as the probability gets larger

bull For the case of the small initial matching the above phenomenom does not occuryet the greedy results deviates from that of the constraint matching

bull As per the pefrect matching compared to the classical matching a difference of5-10 edges is evident at almost all cases

Sorted Ratios

Sorted Ratios-Comments

bull Great max degree deviation

25 Bipartite 31

bull Regardless of the probability the ration of nodes and edges seems to have similarbehaviour when compared to the respective graphs of the same matching scale

bull Same gap between nodes ration and edges ration for all cases

Sorted |E||V |

Sorted |E||V | - Comments

bull In these set of figures we witness that the |E||V | acquires values relevant to those ofthe amadeus graphs The random graphs were constructed to depict this similarity

bull For smaller initial matching the ratios for G and G show the same upward trendand also they acquire closer values It represents the decrease of the averagenumber of forced edges in comparison to the larger matching cases

32 Application

Sorted ∆

Sorted ∆-Comments

bull ∆ acquires the same min and max values for each probability case (expected)

bull Gap in the case of large initial matching

26 Bipartite with degree seq

Graph characteristics

bull DEQBIPxy are randomly generated graphs based on three different types of degreedistribution of the Amadeus graphs

26 Bipartite with degree seq 33

bull There are 6 categories based on ini matching and degree distribution

bull x = L S L When the initial matching is large and S when it is small

bull y = 1 2 3 1 when degree distribution is based on file 2 when degree distributionis based on file and 3 when degree distribution is based on file

Computation time over

34 Application

Computation time overedges-Comments

bull Greedy algorithm takes minimum amount of time

bull The smaller the initial matching the more smaller the difference in comoutationtime of Constraint and classical algorithm

bull Due to preprocessing and the fact that G and G are the almost identical thetotal time needed to apply the constraint algorithm is in some cases bigger

Sorted matching size

26 Bipartite with degree seq 35

Sorted matching size-Comments

bull Classical matching is equal to perfect matching in every case

bull Constraint and greedy have identical behaviour

bull The larger the spectrum of the degree sequence the more efficient the matching

Sorted Ratios

36 Application

Sorted Ratios-Comments

bull With large initial matching most of the edges are considenred uselles or forced andare removed thus the ratio is close(if not equal to) zero

bull For small matching and large degree sequence sectrum hte max degree remainsthe same Only a few forced edges (and their nodes) are removed apparently nonodes with max degree

Sorted |E||V |

26 Bipartite with degree seq 37

Sorted |E||V | - Comments

bull In these set of figures we witness that the |E||V | acquires values relevant to those ofthe amadeus graphs The random graphs were constructed to depict this similarity

bull For smaller initial matching the ratios for G and G show the same upward trendand also they acquire closer values It repsresent the decrease of the averagenumber of forced edges in comparison to the larger matching cases

Sorted ∆

38 Application

Sorted ∆-Comments

bull Big difference in max degree in large initial matching

bull Almost identical behaviour in the case of small initial matching

Appendix A 39

Appendix A

BipartiteGraphGeneratorpy

from future import divisionimport networkx as nx

from networkxalgorithms import approximationimport collectionsimport randomimport mathfrom networkxalgorithms import bipartiteif name == main

for i in range(1481)waqs 481index=1n=randomrandint(100 1000)

n1=95 was 500me1=118

n2=251 was 500me2=903

n3=165 was 500me3=412

m=0m1=0p=randomrandom()p1=18250p2=25250p3=34250print ip=05t1=randomrandint(0 1)print im2=randomrandint(n2minus1 n2+1)G = nxGraph()ma = nxGraph()

aseq1=[1 2 3 4 5 3]

bseq1=[4 3 3 1 2 2 1]

aseq2=[16 14 14 14 12 11]bseq2=[0 0 0 0 0 0]

aseq3=[8 7 8 8 8 8]bseq3=[0 0 0 0 0 0]

40 Application

print Gnumber of edges()if ilt=160

G=bipartiteconfiguration model(aseq1 bseq1 create using=None seed=None)A=nxadjacency matrix(G)for ii in range(0n1+me1)

maadd node(ii)A=[Rtodense()tolist()[0] for R in A]

printnummanumber of nodes()rl=randomsample(range(0n1+me1) n1+me1)m=0done vertices = set()for p in rlprintin fordone verticesadd(p)

neighbors = []list()for iii in range(0n1+me1)

if A[p][iii]==1neighborsappend(iii)

randomshuffle(neighbors)continue loop = Truedegree = len(neighbors)

print degreej = 0p4=randomrandom()while continue loop and (jltdegree)print in loop

next = neighbors[j]if next not in done vertices and p not in done vertices

done verticesadd(p)done verticesadd(next)if p4gt=07print added edge

maadd edge(pnext)m=m+1

continue loop = Falsej += 1

print matching listOfedgeprint maedge

MA=nxadjacency matrix(ma)print MA

MA=[Rtodense()tolist()[0] for R in MA]print MA

B=[ join(map(strR)) for R in A]MB=[ join(map(strR)) for R in MA]

C=njoin(B)+nMC=njoin(MB)+n

print nprint mprint m1

filea=str(i)+txtwith open(fileaw) as f

Appendix A 41

fwrite(str(n1+me1))fwrite(n)fwrite(str(n1+me1))fwrite(n)fwrite(str(m))fwrite(n)fwrite(n)fwrite(C)fwrite(n)fwrite(MC)

elif igt160 and ilt321G=bipartiteconfiguration model(aseq2 bseq2 create using=None seed=None)A=nxadjacency matrix(G)for ii in range(0n2+me2)

maadd node(ii)A=[Rtodense()tolist()[0] for R in A]

printnummanumber of nodes()rl=randomsample(range(0n2+me2) n2+me2)m=0done vertices = set()for p in rlprintin fordone verticesadd(p)

neighbors = []list()for iii in range(0n2+me2)

if A[p][iii]==1neighborsappend(iii)

randomshuffle(neighbors)continue loop = Truedegree = len(neighbors)

print degreej = 0p4=randomrandom()while continue loop and (jltdegree)

print in loopnext = neighbors[j]if next not in done vertices and p not in done vertices

done verticesadd(p)done verticesadd(next)if p4gt=07

print added edgemaadd edge(pnext)m=m+1

continue loop = Falsej += 1

print matching listOfedgeprint maedge

MA=nxadjacency matrix(ma)print MA

MA=[Rtodense()tolist()[0] for R in MA]print MA

B=[ join(map(strR)) for R in A]MB=[ join(map(strR)) for R in MA]

42 Application

C=njoin(B)+nMC=njoin(MB)+n

print nprint mprint m1

filea=str(i)+txtwith open(fileaw) as f

fwrite(str(n2+me2))fwrite(n)fwrite(str(n2+me2))fwrite(n)fwrite(str(m))fwrite(n)fwrite(n)fwrite(C)fwrite(n)fwrite(MC)

elseG=bipartiteconfiguration model(aseq3 bseq3 create using=None seed=None)A=nxadjacency matrix(G)for ii in range(0n3+me3)

maadd node(ii)A=[Rtodense()tolist()[0] for R in A]

printnummanumber of nodes()rl=randomsample(range(0n3+me3) n3+me3)m=0done vertices = set()for p in rlprintin fordone verticesadd(p)

neighbors = []list()for iii in range(0n3+me3)

if A[p][iii]==1neighborsappend(iii)

randomshuffle(neighbors)continue loop = Truedegree = len(neighbors)

print degreej = 0p4=randomrandom()while continue loop and (jltdegree)

print in loopnext = neighbors[j]if next not in done vertices and p not in done vertices

done verticesadd(p)done verticesadd(next)if p4gt=07print added edge

maadd edge(pnext)m=m+1

continue loop = Falsej += 1

Appendix A 43

print matching listOfedgeprint maedge

MA=nxadjacency matrix(ma)print MA

MA=[Rtodense()tolist()[0] for R in MA]print MA

B=[ join(map(strR)) for R in A]MB=[ join(map(strR)) for R in MA]

C=njoin(B)+nMC=njoin(MB)+n

print nprint mprint m1

filea=str(i)+txtwith open(fileaw) as f

fwrite(str(n3+me3))fwrite(n)fwrite(str(n3+me3))fwrite(n)fwrite(str(m))fwrite(n)fwrite(n)fwrite(C)fwrite(n)fwrite(MC)

print nRandom graphs with random matching have been generated

44 Application

RandomGraphGeneratorpy

from future import divisionimport networkx as nxfrom networkxalgorithms import approximationimport collectionsimport randomimport mathif name == main

for i in range(1481)index=1n=randomrandint(100 1000)

n=1000m=0m1=0p=randomrandom()p1=mathlog(n2)np2=13p3=mathlog(n2)n+01p=05t1=randomrandint(0 1)print im2=randomrandint(n2minus1 n2+1)G = nxGraph()ma = nxGraph()print nme1=randomrandint(1 10)me2=randomrandint(2050)me3=randomrandint(50100)if ilt241

if ilt=80G=nxfast gnp random graph(n p1 seed=None directed=False)

elif igt80 and ilt161G=nxfast gnp random graph(n p2 seed=None directed=False)

elseG=nxfast gnp random graph(n p3 seed=None directed=False)

elseif ilt=320

G=nxbarabasi albert graph(n me1 seed=None)elif igt320 and ilt401

G=nxbarabasi albert graph(n me2 seed=None)else

G=nxbarabasi albert graph(n me3 seed=None)A=nxadjacency matrix(G)for ii in range(0n)

maadd node(ii)A=[Rtodense()tolist()[0] for R in A]

rl=randomsample(range(0n) n)m=0

Appendix A 45

done vertices = set()for p in rl

done verticesadd(p)neighbors = []list()for iii in range(0n)

if A[p][iii]==1neighborsappend(iii)

randomshuffle(neighbors)continue loop = Truedegree = len(neighbors)j = 0p2=randomrandom()while continue loop and (jltdegree)

next = neighbors[j]if next not in done vertices and p not in done vertices

done verticesadd(p)done verticesadd(next)if p2gt=00 Larger probability for smaller initial matching

maadd edge(pnext)m=m+1

continue loop = Falsej += 1

print matching listOfedgeprint maedgeMA=nxadjacency matrix(ma)MA=[Rtodense()tolist()[0] for R in MA]print MAB=[ join(map(strR)) for R in A]MB=[ join(map(strR)) for R in MA]

C=njoin(B)+nMC=njoin(MB)+nprint MCprint nprint mprint m1filea=str(i)+txtwith open(fileaw) as f

fwrite(str(n))fwrite(n)fwrite(str(n))fwrite(n)fwrite(str(m))fwrite(n)fwrite(n)fwrite(C)fwrite(n)fwrite(MC)

print nRandom graphs with random matching have been generated

46 Application

kequals3MaximumMatchingpy

from future import divisionimport networkx as nxfrom networkxalgorithms import bipartiteimport matplotlibpyplot as pltimport collectionsimport timeitimport xlwtimport xlrdimport mathimport sys

Case for General Graphsdef forced edges(Gadj dict2matching dict1num nodesforced)

flagg=0for n in range(0num nodes)

for k in adj dict2[n]if ([k]==matching dict1[n])

count=0for l in range(0num nodes)

count=count+adj dict2[l]count(k)if (len(adj dict2[n])==1) or (count==1)

forcedadd edge(nk)Gremove edge(nk)Gremove node(n)Gremove node(k)printforced edgenktemp=kflagg=1for m in range (len(adj dict2[n])minus1minus1minus1)

adj dict2[adj dict2[n][m]]remove(n)adj dict2[n]remove(adj dict2[n][m])

if adj dict2[temp]for l in range(len(adj dict2[temp])minus1minus1minus1)

if (adj dict2[temp][l]=n)adj dict2[adj dict2[temp][l]]remove(temp)adj dict2[temp]remove(adj dict2[temp][l])

break

def useless edges(num nodesadj dict1matching dict1uselessadj dict2G)for n in range(0num nodes)

for k in adj dict1[n]if ([k]=matching dict1[n]) and matching dict1[n] and matching dict1[k]

uselessadd edge(nk)Gremove edge(n k)

Appendix A 47

tempa=kadj dict2[n]remove(k)adj dict2[tempa]remove(n)adj dict1[tempa]remove(n)

return G

def Greedy(num nodesadj dict3matching dict2)

for n in range(0num nodes)if matching dict2[n]

flag2=minus1flag3=minus1for v in adj dict3[n]

if not matching dict2[v]flag2=vbreak

for p in adj dict3[matching dict2[n][0]]if not matching dict2[p]

flag3=pbreak

if (flag2=minus1) and (flag3=minus1) and (flag2=flag3)tempr=matching dict2[n][0]matching dict2[n]=[flag2]matching dict2[flag2]=[n]matching dict2[tempr]=[flag3]matching dict2[flag3]=[tempr]

elsefor k in adj dict3[n]

if not matching dict2[k]matching dict2[n]=[k]matching dict2[k]=[n]break

yo1=0for i in range(0num nodes)

if matching dict2[i] and [i]==matching dict2[matching dict2[i][0]]yo1=yo1+1

greedy size=yo12return greedy size

def General()

INPUTSwb = xlwtWorkbook()ws = wbadd sheet(Results Random)book=xlrdopen workbook(filenames randomxls)

48 Application

style0 = xlwteasyxf(fontbold on)style1 = xlwteasyxf(num format str=0000)INPUTSwswrite(0 0File style0)wswrite(0 1 Nodesstyle0)wswrite(0 2 Initial matchingstyle0)wswrite(0 3 NodesGstyle0)wswrite(0 4 EdgesGstyle0)wswrite(0 5 MaxDegreeGstyle0)wswrite(0 6 NodesG hatstyle0)wswrite(0 7 EdgesG Hatstyle0)wswrite(0 8 Useless edgesstyle0)wswrite(0 9 Forced edgesstyle0)wswrite(0 10 MaxDegreeG Hatstyle0)wswrite(0 11 Classical matchingstyle0)wswrite(0 12 Final matchingstyle0)wswrite(0 13 Greedy matchingstyle0)wswrite(0 14 Time classicalstyle0)wswrite(0 15 Time algorithmstyle0)wswrite(0 16 Time greedystyle0)wswrite(0 17 Perfect matching ratiostyle0)wswrite(0 18 Nodes ratiostyle0)wswrite(0 19 Edges ratiostyle0)wswrite(0 20 Matching ratiostyle0)

print nWelcomeThis is an implementation for general random graphs It uses Edmonds algorithm to compute maximum matching on G Hatn

for index in range (1481)was 481

if (index==482)f=open(Algotel generaltxtr)readlines()

elsefilea=str(booksheet by index(0)cell(index0))s=fileareplace(textu)replace()f=open(sr)readlines()Truewswrite(index 0 s)

print index

num nodes=int([xstrip()split() for x in f][0][0])

num matching=int([xstrip()split() for x in f][2][0])

adj temp = [xstrip()split() for x in f][44+num nodes]adj=[map(intR) for R in adj temp]

matching temp=[xstrip()split() for x in f][4+num nodes+14+2num nodes+1]matching1=[map(intR) for R in matching temp]

adj dict1=i[ii for iix in enumerate(L) if x] for iL in enumerate(adj)adj dict2=i[ii for iix in enumerate(L) if x] for iL in enumerate(adj)

Appendix A 49

adj dict3=i[ii for iix in enumerate(L) if x] for iL in enumerate(adj)

matching dict1=i[ii for iix in enumerate(L) if x] for iL in enumerate(matching1)matching dict2=i[ii for iix in enumerate(L) if x] for iL in enumerate(matching1)print adj dict2print matching dict2wswrite(index 1 num nodes)wswrite(index 2 num matching)

G = nxGraph()

useless= nxGraph()forced = nxGraph()

Fill Graphfor n in range(0num nodes)

for k in adj dict1[n]Gadd edge(nk)

Gt=Gnumber of edges()wswrite(index 3 Gnumber of nodes())wswrite(index 4 Gnumber of edges())wswrite(index 5 max(Gdegree()values()))

Compute Edmonds classical matching on G for comparison

startB = timeitdefault timer()Classical Matching=nxmax weight matching(G maxcardinality=False)stopB = timeitdefault timer()

Compute Gˆ nad MˆstartC = timeitdefault timer()useless edges(num nodesadj dict1matching dict1uselessadj dict2G)forced edges(Gadj dict2matching dict1num nodesforced)Final Matching=nxmax weight matching(G maxcardinality=False)stopC = timeitdefault timer()

GreedystartG = timeitdefault timer()greedy size=Greedy(num nodesadj dict3matching dict2)stopG = timeitdefault timer()

wswrite(index 6 Gnumber of nodes())wswrite(index 7 Gnumber of edges())wswrite(index 8 uselessnumber of edges())wswrite(index 9 forcednumber of edges())if Gdegree()values()

wswrite(index 10 max(Gdegree()values()))else

50 Application

wswrite(index 10 0)wswrite(index 11 len(Classical Matching)2)wswrite(index 12 len(Final Matching)2+forcednumber of edges())wswrite(index 13 greedy size)wswrite(index 14 stopB minus startBstyle1)wswrite(index 15 stopC minus startCstyle1)wswrite(index 16 stopG minus startGstyle1)wswrite(index 17 (len(Final Matching)2+forcednumber of edges())(num nodes2)style1)wswrite(index 18 Gnumber of nodes()Gtstyle1)wswrite(index 19 Gnumber of edges()Gtstyle1)wswrite(index 20 (len(Final Matching)2+forcednumber of edges())(len(Classical Matching)2)style1)

wbsave(AA Results Random Reyni Large Bipartitexls)

Main function Here we must choose the input form of the dataif name == main

startA = timeitdefault timer()General()stopA = timeitdefault timer()

print nThis program has terminatednnRunning time for 480 files stopAminusstartAprint nnPlease open AA Results Random Reyni Largexls file to see the Results

Appendix A 51

Plotmat

clear allclose allload(RN1Lmat)load(RN1Smat)load(RN2Lmat)load(RN2Smat)load(RN3Lmat)load(RN3Smat)

Plotsh(1)=figure(NameHistogram of Matching size difference between Constraint Algorithm and Greedy AlgorithmNumberTitleoff)

RN1L Greedydiff=RN1L Final matchingminusRN1L Greedy matchingRN2L Greedydiff=RN2L Final matchingminusRN2L Greedy matchingRN3L Greedydiff=RN3L Final matchingminusRN3L Greedy matchingRN1S Greedydiff=RN1S Final matchingminusRN1S Greedy matchingRN2S Greedydiff=RN2S Final matchingminusRN2S Greedy matchingRN3S Greedydiff=RN3S Final matchingminusRN3S Greedy matching

RN1L Finaldiff=RN1L Classical matchingminusRN1L Final matchingRN2L Finaldiff=RN2L Classical matchingminusRN2L Final matchingRN3L Finaldiff=RN3L Classical matchingminusRN3L Final matchingRN1S Finaldiff=RN1S Classical matchingminusRN1S Final matchingRN2S Finaldiff=RN2S Classical matchingminusRN2S Final matchingRN3S Finaldiff=RN3S Classical matchingminusRN3S Final matching

RN1L Classicaldiff=(RN1L Nodes2)minusRN1L Classical matchingRN2L Classicaldiff=(RN2L Nodes2)minusRN2L Classical matchingRN3L Classicaldiff=(RN3L Nodes2)minusRN3L Classical matchingRN1S Classicaldiff=(RN1S Nodes2)minusRN1S Classical matchingRN2S Classicaldiff=(RN2S Nodes2)minusRN2S Classical matchingRN3S Classicaldiff=(RN3S Nodes2)minusRN3S Classical matching

subplot(231)hold onhistf(RN1L Greedydiff0110facecolorbfacealpha9edgealpha1)histf(RN1L Finaldiff0110facecolorrfacealpha5edgealpha1)histf(RN1L Classicaldiff0110facecolorgfacealpha5edgealpha1)legalpha(ConminusGreClasminusConPerfminusClasslocationnortheast)legend boxoffaxis tightxlabel(edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN1L)grid on

subplot(232)hold onhistf(RN2L Greedydiff0110facecolorbfacealpha9edgealpha1)

52 Application

histf(RN2L Finaldiff0110facecolorrfacealpha5edgealpha1)histf(RN2L Classicaldiff0110facecolorgfacealpha5edgealpha1)legalpha(ConminusGreClasminusConPerfminusClasslocationnortheast)legend boxoffaxis tightxlabel(edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN2L)grid on

subplot(233)hold onhistf(RN3L Greedydiff0110facecolorbfacealpha5edgealpha1)histf(RN3L Finaldiff0110facecolorrfacealpha5edgealpha1)histf(RN3L Classicaldiff0110facecolorgfacealpha5edgealpha1)legalpha(ConminusGreClasminusConPerfminusClasslocationnortheast)legend boxoffaxis tightxlabel(edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN3L)grid on

subplot(234)hold onhistf(RN1S Greedydiff0110facecolorbfacealpha5edgealpha1)histf(RN1S Finaldiff0110facecolorrfacealpha5edgealpha1)histf(RN1S Classicaldiff0110facecolorgfacealpha5edgealpha1)legalpha(ConminusGreClasminusConPerfminusClasslocationnortheast)legend boxoffaxis tightxlabel(edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(R1NS)grid on

subplot(235)hold onhistf(RN2S Greedydiff0110facecolorbfacealpha5edgealpha1)histf(RN2S Finaldiff0110facecolorrfacealpha5edgealpha1)histf(RN2S Classicaldiff0110facecolorgfacealpha5edgealpha1)legalpha(ConminusGreClasminusConPerfminusClasslocationnortheast)legend boxoffaxis tightxlabel(edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN2S)grid on

subplot(236)hold onhistf(RN3S Greedydiff0110facecolorbfacealpha5edgealpha1)histf(RN3S Finaldiff0110facecolorrfacealpha5edgealpha1)histf(RN3S Classicaldiff0110facecolorgfacealpha5edgealpha1)

Appendix A 53

legalpha(ConminusGreClasminusConPerfminusClasslocationnortheast)legend boxoffaxis tightgrid ontitle(RN3S)xlabel(edges) xminusaxis labelylabel(instances) yminusaxis labelset(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN1png minusr300)h(2)=figure(NameHistogram of Max Degree of G AND G HatNumberTitleoff)RN1L x=RN1L MaxDegreeGminusRN1L MaxDegreeG HatRN2L x=RN2L MaxDegreeGminusRN2L MaxDegreeG HatRN3L x=RN3L MaxDegreeGminusRN3L MaxDegreeG HatRN1S x=RN1S MaxDegreeGminusRN1S MaxDegreeG HatRN2S x=RN2S MaxDegreeGminusRN2S MaxDegreeG HatRN3S x=RN3S MaxDegreeGminusRN3S MaxDegreeG Hatsubplot(231)hold onhistf(RN1L MaxDegreeG0150facecolorbfacealpha5edgealpha1)histf(RN1L MaxDegreeG Hat0150facecolorrfacealpha5edgealpha1)histf(RN1L x0150facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightxlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN1L)grid on

subplot(232)hold onhistf(RN2L MaxDegreeG010500facecolorbfacealpha5edgealpha1)histf(RN2L MaxDegreeG Hat010500facecolorrfacealpha5edgealpha1)histf(RN2L x010500facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightxlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN2L)grid on

subplot(233)hold onhistf(RN3L MaxDegreeG010300facecolorbfacealpha5edgealpha1)histf(RN3L MaxDegreeG Hat010300facecolorrfacealpha5edgealpha1)histf(RN3L x010300facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightxlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN3L)

54 Application

grid on

subplot(234)hold onhistf(RN1S MaxDegreeG0150facecolorbfacealpha5edgealpha1)histf(RN1S MaxDegreeG Hat0150facecolorrfacealpha5edgealpha1)histf(RN1S x0150facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightxlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(R1NS)grid on

subplot(235)hold onhistf(RN2S MaxDegreeG010500facecolorbfacealpha5edgealpha1)histf(RN2S MaxDegreeG Hat010500facecolorrfacealpha5edgealpha1)histf(RN2S x010500facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightxlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN2S)grid on

subplot(236)hold onhistf(RN3S MaxDegreeG05300facecolorbfacealpha5edgealpha1)histf(RN3S MaxDegreeG Hat05300facecolorrfacealpha5edgealpha1)histf(RN3S x05300facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightgrid ontitle(RN3S)xlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labelset(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN2png minusr300)

h(3)=figure(NameComputation time over edgesNumberTitleoff)

subplot(231)hold onstem(RN1L EdgesGRN1L Time classicalg)stem(RN1L EdgesGRN1L Time algorithmro)stem(RN1L EdgesGRN1L Time greedybx)grid on

Appendix A 55

title(RN1L)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)

subplot(232)hold onstem(RN2L EdgesGRN2L Time classicalg)stem(RN2L EdgesGRN2L Time algorithmro)stem(RN2L EdgesGRN2L Time greedybx)grid ontitle(RN2L)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)

subplot(233)hold onstem(RN3L EdgesGRN3L Time classicalg)stem(RN3L EdgesGRN3L Time algorithmro)stem(RN3L EdgesGRN3L Time greedybx)grid ontitle(RN3L)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)

subplot(234)hold onstem(RN1S EdgesGRN1S Time classicalg)stem(RN1S EdgesGRN1S Time algorithmro)stem(RN1S EdgesGRN1S Time greedybx)grid ontitle(RN1S)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)

subplot(235)hold onstem(RN2S EdgesGRN2S Time classicalg)stem(RN2S EdgesGRN2S Time algorithmro)stem(RN2S EdgesGRN2S Time greedybx)grid ontitle(RN2S)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)

subplot(236)hold onstem(RN3S EdgesGRN3S Time classicalg)stem(RN3S EdgesGRN3S Time algorithmro)stem(RN3S EdgesGRN3S Time greedybx)

56 Application

grid ontitle(RN3S)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)set(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN3png minusr300)

h(4)=figure(NameSorted matching sizeNumberTitleoff)RN1L Sorted matching temp(1)=RN1L Classical matchingRN1L Sorted matching temp(2)=RN1L Final matchingRN1L Sorted matching temp(3)=RN1L Greedy matchingRN1L Sorted matching temp(4)=RN1L Initial matchingRN1L Sorted matching=sortrows(RN1L Sorted matching temp)

RN2L Sorted matching temp(1)=RN2L Classical matchingRN2L Sorted matching temp(2)=RN2L Final matchingRN2L Sorted matching temp(3)=RN2L Greedy matchingRN2L Sorted matching temp(4)=RN2L Initial matchingRN2L Sorted matching=sortrows(RN2L Sorted matching temp)

RN3L Sorted matching temp(1)=RN3L Classical matchingRN3L Sorted matching temp(2)=RN3L Final matchingRN3L Sorted matching temp(3)=RN3L Greedy matchingRN3L Sorted matching temp(4)=RN3L Initial matchingRN3L Sorted matching=sortrows(RN3L Sorted matching temp)

RN1S Sorted matching temp(1)=RN1S Classical matchingRN1S Sorted matching temp(2)=RN1S Final matchingRN1S Sorted matching temp(3)=RN1S Greedy matchingRN1S Sorted matching temp(4)=RN1S Initial matchingRN1S Sorted matching=sortrows(RN1S Sorted matching temp)

RN2S Sorted matching temp(1)=RN2S Classical matchingRN2S Sorted matching temp(2)=RN2S Final matchingRN2S Sorted matching temp(3)=RN2S Greedy matchingRN2S Sorted matching temp(4)=RN2S Initial matchingRN2S Sorted matching=sortrows(RN2S Sorted matching temp)

RN3S Sorted matching temp(1)=RN3S Classical matchingRN3S Sorted matching temp(2)=RN3S Final matchingRN3S Sorted matching temp(3)=RN3S Greedy matchingRN3S Sorted matching temp(4)=RN3S Initial matchingRN3S Sorted matching=sortrows(RN3S Sorted matching temp)

subplot(231)hold onplot(RN1L Sorted matching(1)b)plot(RN1L Sorted matching(2)g)plot(RN1L Sorted matching(3)r)plot(RN1L Sorted matching(4)m)

Appendix A 57

grid ontitle(RN1L)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)

subplot(232)hold onplot(RN2L Sorted matching(1)b)plot(RN2L Sorted matching(2)g)plot(RN2L Sorted matching(3)r)plot(RN2L Sorted matching(4)m)grid ontitle(RN2L)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)

subplot(233)hold onplot(RN3L Sorted matching(1)b)plot(RN3L Sorted matching(2)g)plot(RN3L Sorted matching(3)r)plot(RN3L Sorted matching(4)m)grid ontitle(RN3L)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)

subplot(234)hold onplot(RN1S Sorted matching(1)b)plot(RN1S Sorted matching(2)g)plot(RN1S Sorted matching(3)r)plot(RN1S Sorted matching(4)m)grid ontitle(RN1S)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)

subplot(235)hold onplot(RN2S Sorted matching(1)b)plot(RN2S Sorted matching(2)g)plot(RN2S Sorted matching(3)r)plot(RN2S Sorted matching(4)m)grid ontitle(RN2S)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)

58 Application

subplot(236)hold onplot(RN3S Sorted matching(1)b)plot(RN3S Sorted matching(2)g)plot(RN3S Sorted matching(3)r)plot(RN3S Sorted matching(4)m)grid ontitle(RN3S)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)set(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN4png minusr300)h(5)=figure(NameSorted RatiosNumberTitleoff)RN1L ratio1=RN1L NodesG hatRN1L NodesGRN2L ratio1=RN2L NodesG hatRN2L NodesGRN3L ratio1=RN3L NodesG hatRN3L NodesGRN1S ratio1=RN1S NodesG hatRN1S NodesGRN2S ratio1=RN2S NodesG hatRN2S NodesGRN3S ratio1=RN3S NodesG hatRN3S NodesG

RN1L ratio2=RN1L EdgesG HatRN1L EdgesGRN2L ratio2=RN2L EdgesG HatRN2L EdgesGRN3L ratio2=RN3L EdgesG HatRN3L EdgesGRN1S ratio2=RN1S EdgesG HatRN1S EdgesGRN2S ratio2=RN2S EdgesG HatRN2S EdgesGRN3S ratio2=RN3S EdgesG HatRN3S EdgesG

RN1L ratio3=RN1L MaxDegreeG HatRN1L MaxDegreeGRN2L ratio3=RN2L MaxDegreeG HatRN2L MaxDegreeGRN3L ratio3=RN3L MaxDegreeG HatRN3L MaxDegreeGRN1S ratio3=RN1S MaxDegreeG HatRN1S MaxDegreeGRN2S ratio3=RN2S MaxDegreeG HatRN2S MaxDegreeGRN3S ratio3=RN3S MaxDegreeG HatRN3S MaxDegreeG

RN1L ratio(1)=RN1L ratio1RN1L ratio(2)=RN1L ratio2RN1L ratio(3)=RN1L ratio3

RN2L ratio(1)=RN2L ratio1RN2L ratio(2)=RN2L ratio2RN2L ratio(3)=RN2L ratio3

RN3L ratio(1)=RN3L ratio1RN3L ratio(2)=RN3L ratio2RN3L ratio(3)=RN3L ratio3

RN1S ratio(1)=RN1S ratio1RN1S ratio(2)=RN1S ratio2RN1S ratio(3)=RN1S ratio3

RN2S ratio(1)=RN2S ratio1

Appendix A 59

RN2S ratio(2)=RN2S ratio2RN2S ratio(3)=RN2S ratio3

RN3S ratio(1)=RN3S ratio1RN3S ratio(2)=RN3S ratio2RN3S ratio(3)=RN3S ratio3

RN1L ratio sorted=sortrows(RN1L ratio)RN2L ratio sorted=sortrows(RN2L ratio)RN3L ratio sorted=sortrows(RN3L ratio)RN1S ratio sorted=sortrows(RN1S ratio)RN2S ratio sorted=sortrows(RN2S ratio)RN3S ratio sorted=sortrows(RN3S ratio)

subplot(231)hold onplot(RN1L ratio sorted(1)b)plot(RN1L ratio sorted(2)g)plot(RN1L ratio sorted(3)r)grid ontitle(RN1L)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)

subplot(232)hold onplot(RN2L ratio sorted(1)b)plot(RN2L ratio sorted(2)g)plot(RN2L ratio sorted(3)r)grid ontitle(RN2L)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)

subplot(233)hold onplot(RN3L ratio sorted(1)b)plot(RN3L ratio sorted(2)g)plot(RN3L ratio sorted(3)r)grid ontitle(RN3L)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)

subplot(234)hold onplot(RN1S ratio sorted(1)b)plot(RN1S ratio sorted(2)g)plot(RN1S ratio sorted(3)r)grid on

60 Application

title(RN1S)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)

subplot(235)hold onplot(RN2S ratio sorted(1)b)plot(RN2S ratio sorted(2)g)plot(RN2S ratio sorted(3)r)grid ontitle(RN2S)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)

subplot(236)hold onplot(RN3S ratio sorted(1)b)plot(RN3S ratio sorted(2)g)plot(RN3S ratio sorted(3)r)grid ontitle(RN3S)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)set(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN5png minusr300)

h(6)=figure(NameSorted edges over nodesNumberTitleoff)

RN1L DegreeG1=(RN1L EdgesG)(RN1L NodesG)RN1L DegreeG Hat1=(RN1L EdgesG Hat)(RN1L NodesG hat)

RN1L Degree temp1(1)=RN1L DegreeG1RN1L Degree temp1(2)=RN1L DegreeG Hat1RN1L Degree sorted1=sortrows(RN1L Degree temp1)subplot(231)hold on

plot(RN1L Degree sorted1(1)b)plot(RN1L Degree sorted1(2)g)grid ontitle(RN1L)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)

RN2L DegreeG1=(RN2L EdgesG)(RN2L NodesG)RN2L DegreeG Hat1=(RN2L EdgesG Hat)(RN2L NodesG hat)

RN2L Degree temp1(1)=RN2L DegreeG1

Appendix A 61

RN2L Degree temp1(2)=RN2L DegreeG Hat1RN2L Degree sorted1=sortrows(RN2L Degree temp1)

subplot(232)hold onplot(RN2L Degree sorted1(1)b)plot(RN2L Degree sorted1(2)g)grid ontitle(RN2L)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)

RN3L DegreeG1=(RN3L EdgesG)(RN3L NodesG)RN3L DegreeG Hat1=(RN3L EdgesG Hat)(RN3L NodesG hat)

RN3L Degree temp1(1)=RN3L DegreeG1RN3L Degree temp1(2)=RN3L DegreeG Hat1RN3L Degree sorted1=sortrows(RN3L Degree temp1)

subplot(233)hold onplot(RN3L Degree sorted1(1)b)plot(RN3L Degree sorted1(2)g)grid ontitle(RN3L)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)

RN1S DegreeG1=(RN1S EdgesG)(RN1S NodesG)RN1S DegreeG Hat1=(RN1S EdgesG Hat)(RN1S NodesG hat)

RN1S Degree temp1(1)=RN1S DegreeG1RN1S Degree temp1(2)=RN1S DegreeG Hat1RN1S Degree sorted1=sortrows(RN1S Degree temp1)

subplot(234)hold onplot(RN1S Degree sorted1(1)b)plot(RN1S Degree sorted1(2)g)grid ontitle(RN1S)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)

RN2S DegreeG1=(RN2S EdgesG)(RN2S NodesG)RN2S DegreeG Hat1=(RN2S EdgesG Hat)(RN2S NodesG hat)

RN2S Degree temp1(1)=RN2S DegreeG1

62 Application

RN2S Degree temp1(2)=RN2S DegreeG Hat1RN2S Degree sorted1=sortrows(RN2S Degree temp1)

subplot(235)hold onplot(RN2S Degree sorted1(1)b)plot(RN2S Degree sorted1(2)g)grid ontitle(RN2S)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)

RN3S DegreeG1=(RN3S EdgesG)(RN3S NodesG)RN3S DegreeG Hat1=(RN3S EdgesG Hat)(RN3S NodesG hat)

RN3S Degree temp1(1)=RN3S DegreeG1RN3S Degree temp1(2)=RN3S DegreeG Hat1RN3S Degree sorted1=sortrows(RN3S Degree temp1)

subplot(236)hold onplot(RN3S Degree sorted1(1)b)plot(RN3S Degree sorted1(2)g)grid ontitle(RN3S)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)set(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN6png minusr300)h(7)=figure(NameSorted mATCHED DEGREENumberTitleoff)RN1L ratioMax(1)=RN1L MaxDegreeGRN1L ratioMax(2)=RN1L MaxDegreeG Hat

RN1L ratio sortedMax=sortrows(RN1L ratioMax)subplot(231)hold onplot(RN1L ratio sortedMax(1)b)plot(RN1L ratio sortedMax(2)g)grid ontitle(RN1L)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)

RN2L ratioMax(1)=RN2L MaxDegreeGRN2L ratioMax(2)=RN2L MaxDegreeG Hat

RN2L ratio sortedMax=sortrows(RN2L ratioMax)subplot(232)

Appendix A 63

hold onplot(RN2L ratio sortedMax(1)b)plot(RN2L ratio sortedMax(2)g)grid ontitle(RN2L)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)

RN3L ratioMax(1)=RN3L MaxDegreeGRN3L ratioMax(2)=RN3L MaxDegreeG Hat

RN3L ratio sortedMax=sortrows(RN3L ratioMax)subplot(233)hold onplot(RN3L ratio sortedMax(1)b)plot(RN3L ratio sortedMax(2)g)grid ontitle(RN3L)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)

RN1S ratioMax(1)=RN1S MaxDegreeGRN1S ratioMax(2)=RN1S MaxDegreeG Hat

RN1S ratio sortedMax=sortrows(RN1S ratioMax)subplot(234)hold onplot(RN1S ratio sortedMax(1)b)plot(RN1S ratio sortedMax(2)g)grid ontitle(RN1S)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)

RN2S ratioMax(1)=RN2S MaxDegreeGRN2S ratioMax(2)=RN2S MaxDegreeG Hat

RN2S ratio sortedMax=sortrows(RN2S ratioMax)

subplot(235)hold onplot(RN2S ratio sortedMax(1)b)plot(RN2S ratio sortedMax(2)g)grid ontitle(RN2S)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)

RN3S ratioMax(1)=RN3S MaxDegreeGRN3S ratioMax(2)=RN3S MaxDegreeG Hat

64 Application

RN3S ratio sortedMax=sortrows(RN3S ratioMax)subplot(236)hold onplot(RN3S ratio sortedMax(1)b)plot(RN3S ratio sortedMax(2)g)grid ontitle(RN1L)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)set(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN7png minusr300)

tilefigs()(h)

Bibliography

[1] C Berge ldquoTWO THEOREMS IN GRAPH THEORYrdquo Proceedings of the NationalAcademy of Sciences of the United States of America vol 43 no 9 pp 842ndash844Sep 1957

[2] L Bui S Sanghavi and R Srikant ldquoDistributed link scheduling with constantoverheadrdquo IEEEACM Trans Netw vol 17 no 5 pp 1467ndash1480 2009

[3] R Duan and S Pettie ldquoLinear-time approximation for maximum weight matchingrdquoJ ACM vol 61 no 1 2014

[4] J Edmonds ldquoPaths trees and flowersrdquo Canadian Journal of Mathematics vol 17pp 449ndash467 1965

[5] J E Hopcroft and R M Karp ldquoAn n52 algorithm for maximum matchings inbipartite graphsrdquo SIAM J Comput vol 2 no 4 pp 225ndash231 1973

[6] S Micali and V V Vazirani ldquoAn O(radic|V ||E|) algorithm for finding maximum

matching in general graphsrdquo in 21st Symp on Foundations of Comp Sc (FOCS)IEEE 1980 pp 17ndash27

[7] N Nisse A Salch and V Weber ldquoRecovery of disrupted airline operationsrdquo 2015httphalinriafrSomething

[8] X Wu and R Srikant ldquoRegulated maximal matching A distributed schedulingalgorithm for multi-hop wireless networks with nodeexclusive spectrum sharingrdquo inIEEE Conf on Decision and Control 2005

65

  • Contents
  • Introduction
  • Algorithms
    • Maximum matching
    • k-maximum matching
      • k-matching for Airport Slot assignment
      • The case where k=3
      • The case of Paths
      • The case of the Spider
          • Application
            • Description
            • Reyni Erdos
            • Barabaacutesi Albert
            • Amadeus Graphs
            • Bipartite
            • Bipartite with degree seq
            • Appendix A
              • BipartiteGraphGeneratorpy
              • RandomGraphGeneratorpy
              • kequals3MaximumMatchingpy
              • Plotmat
                  • Bibliography
Page 11: Theodoros Alexandros KARAGKIOULES -  · Introduction This work is the result of a 6 months internship, under the supervision of research O cer Nicolas NISSE. The original scope of

12 Application

bull This set of figures represents the ascending order of the Classical matching sizealong with its corresponding Constraint and Greedy equivalent

bull When the probability is sufficiently higher than the threshold lognn

then the threealgorithms produce identical results of optimal matching

bull For lower probability there is a difference between the results of the algorithms

bull the degree of that difference is depicted in the first set of figures presented

bull It is interesting to observe that a change on the Constraint algorithm is associatedwith a even more significant change in the Greedy algorithm

bull There is a difference only when the probability is at the connectedness threshholdlognn

bull The difference is very small compared to the size of the matching ( 500)

bull The difference in matching size appears mostly at the Greedy implementationwhen compared to the constraint algorithm

Sorted Ratios

22 Reyni Erdos 13

Sorted Ratios - Comments

bull This set of figures depicts the ratios VV

EE

∆∆

in ascending order of VV

bull It is evident that when the initial matching is large the amount of forced edges(and their endpoints) removed is high thus the ratio of Nodes and edges is verylow For higher probabilities almost all edges are removed as useless

bull For a smaller initial matching almost no forced edges (and their endpoints) areremoved which we conclude be the node ration being close to 1 There is somesmall amount of useless edges removed though since the ratio of edges is less butclose to 1

bull The ratio of ∆ for large initial matching follows the trend of the node ratio yetfor smaller initial matching it deviates significantly

14 Application

Sorted |E||V |

Sorted |E||V | - Comments

bull Although as graph density the ratio 2|E||V |(|V |minus1)

is considered in this set of figures

we evaluate the correlation of the ratio |E||V | of G and G since the density of G

could acquire values higher than that of G

bull The figures are calculated in ascending order for the ratio of G

bull For the case of large initial matching the two ratios for G and G remain almostconstant ( to the extent of the probability of each graph) since removing forcededges( and their endpoints) alters the |E| and |V | proportionately

22 Reyni Erdos 15

bull For the case of small initial matching we observe some deviation in the valuesof the ration for G and that is explained with the removal of only useless edgeswhich only alters the |E| and keeps |V | in the original values

Sorted ∆

Sorted ∆-Comments

bull In this set of figures the ascending order of the ∆ of G is associated with the ∆of G

bull There is no significant jump of the ∆ for each graph category which tells that thatwe are comparing a uniform distribution of random grapghs for each probabilitycase

16 Application

bull For larger initial matching we observe the difference in the ∆s of G and G giventhe removed forced edges( and their endpoints) At some cases the ∆ of G dropsto 0 since the vast majority of edges have been declared forced and removed alongwith their endpoints

bull For smaller initial matching the ∆s of G and G follow mostly the same trend onlya few number of different instances

23 Barabasi Albert

Graph characteristics Barabasi Albert

bull BAxy are randomly generated graphs with a fixed number of 1000 nodes

bull There are 6 categories based on ini matching and of attached edges m

bull x = L S L When the initial matching is large and S when it is small

bull y = 1 2 3 1 when m = [1 10] 2 when m = [20 50] and 3 m = [50 100]

Computation time over |E|

23 Barabasi Albert 17

Computation time over |E| - Comments

bull When the initial matching is sufficiently large then the forced edges are taken out(a process which takes a fragment of the computation time) and then the classicalmatching algorithm (Edmonds) is applied on a smaller graph(G) This reducessignificantly the computation time

bull When the initial matching is small then the computation time of the constraintalgorithm might be larger than that of Edmonds The reason is that the constraintalgorithm need some time to compute the useless and forced edges and thenEdmonds algorithm is applied on G G Thus the overall processing time issometimes larger

Sorted matching size

18 Application

Sorted matching size-Comments

bull In this graph the matching size of the classical algorithm is depicted in ascendingorder along with the corresponding constraint algorithm and greedy result

bull Here in the case where m is small for both cases of initial matching (small large)the result may vary greatly starting from a value of half the perfect matching withsmall differences between the results of the various algorithm implementations

bull For the other cases of m the results converge

bull This is explained as for small values of m the graph is disconnected

bull In the matching size difference set of figures a very noticing difference value ap-pears For the cases of small m( the number of existing nodes that a new node isconnected to at the creation of the graph) we can see that the difference in the

23 Barabasi Albert 19

matching size compared to that of the perfect matching could be up to 40 ofthat of the matching size So there are occasions where the matching size is 200edges when the perfect matching would have been 500

bull the difference between the Constraint matching and the classical matching andthe difference of the constraint matching and that of the greedy matching do notshow significant values

Sorted Ratios

Sorted Ratio s -Comments

bull This set of figures depicts the ratios VV

EE

∆∆

in ascending order of VV

20 Application

bull It is evident that when the initial matching is large the amount of forced edges(and their endpoints) removed is high thus the ratio of Nodes and edges is verylow For higher probabilities almost all edges are removed as useless

bull For a smaller initial matching almost no forced edges (and their endpoints) areremoved which we conclude be the node ration being close to 1 There is somesmall amount of useless edges removed though since the ratio of edges is less butclose to 1

bull The ratio of ∆ for large initial matching follows the trend of the node ratio yetfor smaller initial matching it deviates significantly

Sorted |E||V |

23 Barabasi Albert 21

Sorted |E||V | - Comments

bull Although as graph density the ratio 2|E||V |(|V |minus1)

is considered in this set of figures

we evaluate the correlation of the ratio |E||V | of G and G since the density of G

could acquire values higher than that of G

bull The figures are calculated in ascending order for the ratio of G

bull For the case of large initial matching the two ratios for G and G remain almostconstant ( to the extent of the edge attraction m of each graph) since removingforced edges( and their endpoints) alters the |E| and |V | proportionately

bull For the case of small initial matching we observe some deviation in the valuesof the ration for G and that is explained with the removal of only useless edgeswhich only alters the |E| and keeps |V | in the original values

Sorted ∆

22 Application

Sorted ∆-Comments

bull In this set of figures the ascending order of the ∆ of G is associated with the ∆of G

bull There is a significant jump of the ∆ for each graph category which tells that thatwe are not comparing a uniform distribution of random graphs and based on theedge attraction m the graphs can vary in form

bull For larger initial matching we observe the difference in the ∆s of G and G giventhe removed forced edges( and their endpoints) At some cases the ∆ of G dropsto 0 since the vast majority of edges have been declared forced and removed alongwith their endpoints What is interesting is that the ∆ of G oscilates within stablelimits

24 Amadeus Graphs 23

bull For smaller initial matching the ∆s of G and G follow mostly the same trend onlya few number of different instances

24 Amadeus Graphs

Graph characteristics Amadeus graphs

bull These are the bipartite graphs provided by Amadeus

Computation time over |E|

Computation time over |E| - Comments

24 Application

bull For every instance the computation time of the classical algorithm is always smallerto that of the constraint matching

bull This allows as to speculate that we always compute a smaller G which also impliesthat we always find a set of forced edges and useless

Sorted matching size

Sorted matching size - Comments

bull Size of matching has an upward trend since the magnitude of the graphs is notthe same for the 160 instances

bull No significant deviation is noticed as per the first graph

24 Amadeus Graphs 25

bull Except from deviation from the perfect matching (number of flights) where some-times it could get up to 40

bull For the Amadeus Bipartite graphs we can see that the difference of the Classicaland the constraint implementation is not more than 1 edge in the matching

bull There appears to be a difference of up to 24 edges between the Classical matchingand the Perfect matching which is computed as the number of flights

bull The greedy algorithm performs well with only a few instances deviating slightlyform the Constraint algorithm result

Sorted Ratios

Sorted Ratios - Comments

26 Application

bull

Sorted |E||V |

Sorted |E||V | - Comments

bull Density of the graphs shows that on average we have 25-3 available time slot perflight

bull The line for the same value for G shows that there is a large deviation for everyinstance which allows for the hypothesis that the amount of useless+forced edgesof G has no obvious correlation to that of G

25 Bipartite 27

Sorted ∆

Sorted ∆-Comments

bull As per the previous related graphs for ∆ there is in significant drop in the ∆ of Gand G

25 Bipartite

Graph characteristics Bipartite random Graphs

bull BIPxy are randomly generated graphs with a fixed number of 1000(n=500 andm=500) nodes

bull There are 6 categories based on ini matching and probability p

28 Application

bull Probability p has been chosen as such in order to simulate the |E||V | 25 of theAmadeus bipartite graphs

bull So in order to have about 2-4 edges for every node we choose accordingly theprobability p to choose one of the n lowastm possible edges

bull x = L S L When the initial matching is large and S when it is small

bull y = 1 2 3 1 when p = 18250

2 when p = 25250

and 3 when p = 34250

Computation time over

Computation time overedges-Comments

bull

25 Bipartite 29

Sorted matching size

Sorted matching size-Comments

bull In these set of graphs one can instantly notice that only a few instances with highprobability can reach a matching size equal to the perfect matching

bull For the case of the initial matching we witness that there is a gap between the lineof the classical matching and those of the constraint and greedy results suggestingsmaller matching sizes of 10-40 edges

bull For the case of the small initial matching the result of the constraint matchingis now close to the result of the classical matching yet the greedy algorithm stillshows a relevantly big difference

30 Application

bull In this set of bipartite graphs we can witness that the result of the Constraintmatching shows a difference with the classical matching when the initial matchingis large The difference is smaller as the probability gets larger

bull For the case of the small initial matching the above phenomenom does not occuryet the greedy results deviates from that of the constraint matching

bull As per the pefrect matching compared to the classical matching a difference of5-10 edges is evident at almost all cases

Sorted Ratios

Sorted Ratios-Comments

bull Great max degree deviation

25 Bipartite 31

bull Regardless of the probability the ration of nodes and edges seems to have similarbehaviour when compared to the respective graphs of the same matching scale

bull Same gap between nodes ration and edges ration for all cases

Sorted |E||V |

Sorted |E||V | - Comments

bull In these set of figures we witness that the |E||V | acquires values relevant to those ofthe amadeus graphs The random graphs were constructed to depict this similarity

bull For smaller initial matching the ratios for G and G show the same upward trendand also they acquire closer values It represents the decrease of the averagenumber of forced edges in comparison to the larger matching cases

32 Application

Sorted ∆

Sorted ∆-Comments

bull ∆ acquires the same min and max values for each probability case (expected)

bull Gap in the case of large initial matching

26 Bipartite with degree seq

Graph characteristics

bull DEQBIPxy are randomly generated graphs based on three different types of degreedistribution of the Amadeus graphs

26 Bipartite with degree seq 33

bull There are 6 categories based on ini matching and degree distribution

bull x = L S L When the initial matching is large and S when it is small

bull y = 1 2 3 1 when degree distribution is based on file 2 when degree distributionis based on file and 3 when degree distribution is based on file

Computation time over

34 Application

Computation time overedges-Comments

bull Greedy algorithm takes minimum amount of time

bull The smaller the initial matching the more smaller the difference in comoutationtime of Constraint and classical algorithm

bull Due to preprocessing and the fact that G and G are the almost identical thetotal time needed to apply the constraint algorithm is in some cases bigger

Sorted matching size

26 Bipartite with degree seq 35

Sorted matching size-Comments

bull Classical matching is equal to perfect matching in every case

bull Constraint and greedy have identical behaviour

bull The larger the spectrum of the degree sequence the more efficient the matching

Sorted Ratios

36 Application

Sorted Ratios-Comments

bull With large initial matching most of the edges are considenred uselles or forced andare removed thus the ratio is close(if not equal to) zero

bull For small matching and large degree sequence sectrum hte max degree remainsthe same Only a few forced edges (and their nodes) are removed apparently nonodes with max degree

Sorted |E||V |

26 Bipartite with degree seq 37

Sorted |E||V | - Comments

bull In these set of figures we witness that the |E||V | acquires values relevant to those ofthe amadeus graphs The random graphs were constructed to depict this similarity

bull For smaller initial matching the ratios for G and G show the same upward trendand also they acquire closer values It repsresent the decrease of the averagenumber of forced edges in comparison to the larger matching cases

Sorted ∆

38 Application

Sorted ∆-Comments

bull Big difference in max degree in large initial matching

bull Almost identical behaviour in the case of small initial matching

Appendix A 39

Appendix A

BipartiteGraphGeneratorpy

from future import divisionimport networkx as nx

from networkxalgorithms import approximationimport collectionsimport randomimport mathfrom networkxalgorithms import bipartiteif name == main

for i in range(1481)waqs 481index=1n=randomrandint(100 1000)

n1=95 was 500me1=118

n2=251 was 500me2=903

n3=165 was 500me3=412

m=0m1=0p=randomrandom()p1=18250p2=25250p3=34250print ip=05t1=randomrandint(0 1)print im2=randomrandint(n2minus1 n2+1)G = nxGraph()ma = nxGraph()

aseq1=[1 2 3 4 5 3]

bseq1=[4 3 3 1 2 2 1]

aseq2=[16 14 14 14 12 11]bseq2=[0 0 0 0 0 0]

aseq3=[8 7 8 8 8 8]bseq3=[0 0 0 0 0 0]

40 Application

print Gnumber of edges()if ilt=160

G=bipartiteconfiguration model(aseq1 bseq1 create using=None seed=None)A=nxadjacency matrix(G)for ii in range(0n1+me1)

maadd node(ii)A=[Rtodense()tolist()[0] for R in A]

printnummanumber of nodes()rl=randomsample(range(0n1+me1) n1+me1)m=0done vertices = set()for p in rlprintin fordone verticesadd(p)

neighbors = []list()for iii in range(0n1+me1)

if A[p][iii]==1neighborsappend(iii)

randomshuffle(neighbors)continue loop = Truedegree = len(neighbors)

print degreej = 0p4=randomrandom()while continue loop and (jltdegree)print in loop

next = neighbors[j]if next not in done vertices and p not in done vertices

done verticesadd(p)done verticesadd(next)if p4gt=07print added edge

maadd edge(pnext)m=m+1

continue loop = Falsej += 1

print matching listOfedgeprint maedge

MA=nxadjacency matrix(ma)print MA

MA=[Rtodense()tolist()[0] for R in MA]print MA

B=[ join(map(strR)) for R in A]MB=[ join(map(strR)) for R in MA]

C=njoin(B)+nMC=njoin(MB)+n

print nprint mprint m1

filea=str(i)+txtwith open(fileaw) as f

Appendix A 41

fwrite(str(n1+me1))fwrite(n)fwrite(str(n1+me1))fwrite(n)fwrite(str(m))fwrite(n)fwrite(n)fwrite(C)fwrite(n)fwrite(MC)

elif igt160 and ilt321G=bipartiteconfiguration model(aseq2 bseq2 create using=None seed=None)A=nxadjacency matrix(G)for ii in range(0n2+me2)

maadd node(ii)A=[Rtodense()tolist()[0] for R in A]

printnummanumber of nodes()rl=randomsample(range(0n2+me2) n2+me2)m=0done vertices = set()for p in rlprintin fordone verticesadd(p)

neighbors = []list()for iii in range(0n2+me2)

if A[p][iii]==1neighborsappend(iii)

randomshuffle(neighbors)continue loop = Truedegree = len(neighbors)

print degreej = 0p4=randomrandom()while continue loop and (jltdegree)

print in loopnext = neighbors[j]if next not in done vertices and p not in done vertices

done verticesadd(p)done verticesadd(next)if p4gt=07

print added edgemaadd edge(pnext)m=m+1

continue loop = Falsej += 1

print matching listOfedgeprint maedge

MA=nxadjacency matrix(ma)print MA

MA=[Rtodense()tolist()[0] for R in MA]print MA

B=[ join(map(strR)) for R in A]MB=[ join(map(strR)) for R in MA]

42 Application

C=njoin(B)+nMC=njoin(MB)+n

print nprint mprint m1

filea=str(i)+txtwith open(fileaw) as f

fwrite(str(n2+me2))fwrite(n)fwrite(str(n2+me2))fwrite(n)fwrite(str(m))fwrite(n)fwrite(n)fwrite(C)fwrite(n)fwrite(MC)

elseG=bipartiteconfiguration model(aseq3 bseq3 create using=None seed=None)A=nxadjacency matrix(G)for ii in range(0n3+me3)

maadd node(ii)A=[Rtodense()tolist()[0] for R in A]

printnummanumber of nodes()rl=randomsample(range(0n3+me3) n3+me3)m=0done vertices = set()for p in rlprintin fordone verticesadd(p)

neighbors = []list()for iii in range(0n3+me3)

if A[p][iii]==1neighborsappend(iii)

randomshuffle(neighbors)continue loop = Truedegree = len(neighbors)

print degreej = 0p4=randomrandom()while continue loop and (jltdegree)

print in loopnext = neighbors[j]if next not in done vertices and p not in done vertices

done verticesadd(p)done verticesadd(next)if p4gt=07print added edge

maadd edge(pnext)m=m+1

continue loop = Falsej += 1

Appendix A 43

print matching listOfedgeprint maedge

MA=nxadjacency matrix(ma)print MA

MA=[Rtodense()tolist()[0] for R in MA]print MA

B=[ join(map(strR)) for R in A]MB=[ join(map(strR)) for R in MA]

C=njoin(B)+nMC=njoin(MB)+n

print nprint mprint m1

filea=str(i)+txtwith open(fileaw) as f

fwrite(str(n3+me3))fwrite(n)fwrite(str(n3+me3))fwrite(n)fwrite(str(m))fwrite(n)fwrite(n)fwrite(C)fwrite(n)fwrite(MC)

print nRandom graphs with random matching have been generated

44 Application

RandomGraphGeneratorpy

from future import divisionimport networkx as nxfrom networkxalgorithms import approximationimport collectionsimport randomimport mathif name == main

for i in range(1481)index=1n=randomrandint(100 1000)

n=1000m=0m1=0p=randomrandom()p1=mathlog(n2)np2=13p3=mathlog(n2)n+01p=05t1=randomrandint(0 1)print im2=randomrandint(n2minus1 n2+1)G = nxGraph()ma = nxGraph()print nme1=randomrandint(1 10)me2=randomrandint(2050)me3=randomrandint(50100)if ilt241

if ilt=80G=nxfast gnp random graph(n p1 seed=None directed=False)

elif igt80 and ilt161G=nxfast gnp random graph(n p2 seed=None directed=False)

elseG=nxfast gnp random graph(n p3 seed=None directed=False)

elseif ilt=320

G=nxbarabasi albert graph(n me1 seed=None)elif igt320 and ilt401

G=nxbarabasi albert graph(n me2 seed=None)else

G=nxbarabasi albert graph(n me3 seed=None)A=nxadjacency matrix(G)for ii in range(0n)

maadd node(ii)A=[Rtodense()tolist()[0] for R in A]

rl=randomsample(range(0n) n)m=0

Appendix A 45

done vertices = set()for p in rl

done verticesadd(p)neighbors = []list()for iii in range(0n)

if A[p][iii]==1neighborsappend(iii)

randomshuffle(neighbors)continue loop = Truedegree = len(neighbors)j = 0p2=randomrandom()while continue loop and (jltdegree)

next = neighbors[j]if next not in done vertices and p not in done vertices

done verticesadd(p)done verticesadd(next)if p2gt=00 Larger probability for smaller initial matching

maadd edge(pnext)m=m+1

continue loop = Falsej += 1

print matching listOfedgeprint maedgeMA=nxadjacency matrix(ma)MA=[Rtodense()tolist()[0] for R in MA]print MAB=[ join(map(strR)) for R in A]MB=[ join(map(strR)) for R in MA]

C=njoin(B)+nMC=njoin(MB)+nprint MCprint nprint mprint m1filea=str(i)+txtwith open(fileaw) as f

fwrite(str(n))fwrite(n)fwrite(str(n))fwrite(n)fwrite(str(m))fwrite(n)fwrite(n)fwrite(C)fwrite(n)fwrite(MC)

print nRandom graphs with random matching have been generated

46 Application

kequals3MaximumMatchingpy

from future import divisionimport networkx as nxfrom networkxalgorithms import bipartiteimport matplotlibpyplot as pltimport collectionsimport timeitimport xlwtimport xlrdimport mathimport sys

Case for General Graphsdef forced edges(Gadj dict2matching dict1num nodesforced)

flagg=0for n in range(0num nodes)

for k in adj dict2[n]if ([k]==matching dict1[n])

count=0for l in range(0num nodes)

count=count+adj dict2[l]count(k)if (len(adj dict2[n])==1) or (count==1)

forcedadd edge(nk)Gremove edge(nk)Gremove node(n)Gremove node(k)printforced edgenktemp=kflagg=1for m in range (len(adj dict2[n])minus1minus1minus1)

adj dict2[adj dict2[n][m]]remove(n)adj dict2[n]remove(adj dict2[n][m])

if adj dict2[temp]for l in range(len(adj dict2[temp])minus1minus1minus1)

if (adj dict2[temp][l]=n)adj dict2[adj dict2[temp][l]]remove(temp)adj dict2[temp]remove(adj dict2[temp][l])

break

def useless edges(num nodesadj dict1matching dict1uselessadj dict2G)for n in range(0num nodes)

for k in adj dict1[n]if ([k]=matching dict1[n]) and matching dict1[n] and matching dict1[k]

uselessadd edge(nk)Gremove edge(n k)

Appendix A 47

tempa=kadj dict2[n]remove(k)adj dict2[tempa]remove(n)adj dict1[tempa]remove(n)

return G

def Greedy(num nodesadj dict3matching dict2)

for n in range(0num nodes)if matching dict2[n]

flag2=minus1flag3=minus1for v in adj dict3[n]

if not matching dict2[v]flag2=vbreak

for p in adj dict3[matching dict2[n][0]]if not matching dict2[p]

flag3=pbreak

if (flag2=minus1) and (flag3=minus1) and (flag2=flag3)tempr=matching dict2[n][0]matching dict2[n]=[flag2]matching dict2[flag2]=[n]matching dict2[tempr]=[flag3]matching dict2[flag3]=[tempr]

elsefor k in adj dict3[n]

if not matching dict2[k]matching dict2[n]=[k]matching dict2[k]=[n]break

yo1=0for i in range(0num nodes)

if matching dict2[i] and [i]==matching dict2[matching dict2[i][0]]yo1=yo1+1

greedy size=yo12return greedy size

def General()

INPUTSwb = xlwtWorkbook()ws = wbadd sheet(Results Random)book=xlrdopen workbook(filenames randomxls)

48 Application

style0 = xlwteasyxf(fontbold on)style1 = xlwteasyxf(num format str=0000)INPUTSwswrite(0 0File style0)wswrite(0 1 Nodesstyle0)wswrite(0 2 Initial matchingstyle0)wswrite(0 3 NodesGstyle0)wswrite(0 4 EdgesGstyle0)wswrite(0 5 MaxDegreeGstyle0)wswrite(0 6 NodesG hatstyle0)wswrite(0 7 EdgesG Hatstyle0)wswrite(0 8 Useless edgesstyle0)wswrite(0 9 Forced edgesstyle0)wswrite(0 10 MaxDegreeG Hatstyle0)wswrite(0 11 Classical matchingstyle0)wswrite(0 12 Final matchingstyle0)wswrite(0 13 Greedy matchingstyle0)wswrite(0 14 Time classicalstyle0)wswrite(0 15 Time algorithmstyle0)wswrite(0 16 Time greedystyle0)wswrite(0 17 Perfect matching ratiostyle0)wswrite(0 18 Nodes ratiostyle0)wswrite(0 19 Edges ratiostyle0)wswrite(0 20 Matching ratiostyle0)

print nWelcomeThis is an implementation for general random graphs It uses Edmonds algorithm to compute maximum matching on G Hatn

for index in range (1481)was 481

if (index==482)f=open(Algotel generaltxtr)readlines()

elsefilea=str(booksheet by index(0)cell(index0))s=fileareplace(textu)replace()f=open(sr)readlines()Truewswrite(index 0 s)

print index

num nodes=int([xstrip()split() for x in f][0][0])

num matching=int([xstrip()split() for x in f][2][0])

adj temp = [xstrip()split() for x in f][44+num nodes]adj=[map(intR) for R in adj temp]

matching temp=[xstrip()split() for x in f][4+num nodes+14+2num nodes+1]matching1=[map(intR) for R in matching temp]

adj dict1=i[ii for iix in enumerate(L) if x] for iL in enumerate(adj)adj dict2=i[ii for iix in enumerate(L) if x] for iL in enumerate(adj)

Appendix A 49

adj dict3=i[ii for iix in enumerate(L) if x] for iL in enumerate(adj)

matching dict1=i[ii for iix in enumerate(L) if x] for iL in enumerate(matching1)matching dict2=i[ii for iix in enumerate(L) if x] for iL in enumerate(matching1)print adj dict2print matching dict2wswrite(index 1 num nodes)wswrite(index 2 num matching)

G = nxGraph()

useless= nxGraph()forced = nxGraph()

Fill Graphfor n in range(0num nodes)

for k in adj dict1[n]Gadd edge(nk)

Gt=Gnumber of edges()wswrite(index 3 Gnumber of nodes())wswrite(index 4 Gnumber of edges())wswrite(index 5 max(Gdegree()values()))

Compute Edmonds classical matching on G for comparison

startB = timeitdefault timer()Classical Matching=nxmax weight matching(G maxcardinality=False)stopB = timeitdefault timer()

Compute Gˆ nad MˆstartC = timeitdefault timer()useless edges(num nodesadj dict1matching dict1uselessadj dict2G)forced edges(Gadj dict2matching dict1num nodesforced)Final Matching=nxmax weight matching(G maxcardinality=False)stopC = timeitdefault timer()

GreedystartG = timeitdefault timer()greedy size=Greedy(num nodesadj dict3matching dict2)stopG = timeitdefault timer()

wswrite(index 6 Gnumber of nodes())wswrite(index 7 Gnumber of edges())wswrite(index 8 uselessnumber of edges())wswrite(index 9 forcednumber of edges())if Gdegree()values()

wswrite(index 10 max(Gdegree()values()))else

50 Application

wswrite(index 10 0)wswrite(index 11 len(Classical Matching)2)wswrite(index 12 len(Final Matching)2+forcednumber of edges())wswrite(index 13 greedy size)wswrite(index 14 stopB minus startBstyle1)wswrite(index 15 stopC minus startCstyle1)wswrite(index 16 stopG minus startGstyle1)wswrite(index 17 (len(Final Matching)2+forcednumber of edges())(num nodes2)style1)wswrite(index 18 Gnumber of nodes()Gtstyle1)wswrite(index 19 Gnumber of edges()Gtstyle1)wswrite(index 20 (len(Final Matching)2+forcednumber of edges())(len(Classical Matching)2)style1)

wbsave(AA Results Random Reyni Large Bipartitexls)

Main function Here we must choose the input form of the dataif name == main

startA = timeitdefault timer()General()stopA = timeitdefault timer()

print nThis program has terminatednnRunning time for 480 files stopAminusstartAprint nnPlease open AA Results Random Reyni Largexls file to see the Results

Appendix A 51

Plotmat

clear allclose allload(RN1Lmat)load(RN1Smat)load(RN2Lmat)load(RN2Smat)load(RN3Lmat)load(RN3Smat)

Plotsh(1)=figure(NameHistogram of Matching size difference between Constraint Algorithm and Greedy AlgorithmNumberTitleoff)

RN1L Greedydiff=RN1L Final matchingminusRN1L Greedy matchingRN2L Greedydiff=RN2L Final matchingminusRN2L Greedy matchingRN3L Greedydiff=RN3L Final matchingminusRN3L Greedy matchingRN1S Greedydiff=RN1S Final matchingminusRN1S Greedy matchingRN2S Greedydiff=RN2S Final matchingminusRN2S Greedy matchingRN3S Greedydiff=RN3S Final matchingminusRN3S Greedy matching

RN1L Finaldiff=RN1L Classical matchingminusRN1L Final matchingRN2L Finaldiff=RN2L Classical matchingminusRN2L Final matchingRN3L Finaldiff=RN3L Classical matchingminusRN3L Final matchingRN1S Finaldiff=RN1S Classical matchingminusRN1S Final matchingRN2S Finaldiff=RN2S Classical matchingminusRN2S Final matchingRN3S Finaldiff=RN3S Classical matchingminusRN3S Final matching

RN1L Classicaldiff=(RN1L Nodes2)minusRN1L Classical matchingRN2L Classicaldiff=(RN2L Nodes2)minusRN2L Classical matchingRN3L Classicaldiff=(RN3L Nodes2)minusRN3L Classical matchingRN1S Classicaldiff=(RN1S Nodes2)minusRN1S Classical matchingRN2S Classicaldiff=(RN2S Nodes2)minusRN2S Classical matchingRN3S Classicaldiff=(RN3S Nodes2)minusRN3S Classical matching

subplot(231)hold onhistf(RN1L Greedydiff0110facecolorbfacealpha9edgealpha1)histf(RN1L Finaldiff0110facecolorrfacealpha5edgealpha1)histf(RN1L Classicaldiff0110facecolorgfacealpha5edgealpha1)legalpha(ConminusGreClasminusConPerfminusClasslocationnortheast)legend boxoffaxis tightxlabel(edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN1L)grid on

subplot(232)hold onhistf(RN2L Greedydiff0110facecolorbfacealpha9edgealpha1)

52 Application

histf(RN2L Finaldiff0110facecolorrfacealpha5edgealpha1)histf(RN2L Classicaldiff0110facecolorgfacealpha5edgealpha1)legalpha(ConminusGreClasminusConPerfminusClasslocationnortheast)legend boxoffaxis tightxlabel(edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN2L)grid on

subplot(233)hold onhistf(RN3L Greedydiff0110facecolorbfacealpha5edgealpha1)histf(RN3L Finaldiff0110facecolorrfacealpha5edgealpha1)histf(RN3L Classicaldiff0110facecolorgfacealpha5edgealpha1)legalpha(ConminusGreClasminusConPerfminusClasslocationnortheast)legend boxoffaxis tightxlabel(edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN3L)grid on

subplot(234)hold onhistf(RN1S Greedydiff0110facecolorbfacealpha5edgealpha1)histf(RN1S Finaldiff0110facecolorrfacealpha5edgealpha1)histf(RN1S Classicaldiff0110facecolorgfacealpha5edgealpha1)legalpha(ConminusGreClasminusConPerfminusClasslocationnortheast)legend boxoffaxis tightxlabel(edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(R1NS)grid on

subplot(235)hold onhistf(RN2S Greedydiff0110facecolorbfacealpha5edgealpha1)histf(RN2S Finaldiff0110facecolorrfacealpha5edgealpha1)histf(RN2S Classicaldiff0110facecolorgfacealpha5edgealpha1)legalpha(ConminusGreClasminusConPerfminusClasslocationnortheast)legend boxoffaxis tightxlabel(edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN2S)grid on

subplot(236)hold onhistf(RN3S Greedydiff0110facecolorbfacealpha5edgealpha1)histf(RN3S Finaldiff0110facecolorrfacealpha5edgealpha1)histf(RN3S Classicaldiff0110facecolorgfacealpha5edgealpha1)

Appendix A 53

legalpha(ConminusGreClasminusConPerfminusClasslocationnortheast)legend boxoffaxis tightgrid ontitle(RN3S)xlabel(edges) xminusaxis labelylabel(instances) yminusaxis labelset(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN1png minusr300)h(2)=figure(NameHistogram of Max Degree of G AND G HatNumberTitleoff)RN1L x=RN1L MaxDegreeGminusRN1L MaxDegreeG HatRN2L x=RN2L MaxDegreeGminusRN2L MaxDegreeG HatRN3L x=RN3L MaxDegreeGminusRN3L MaxDegreeG HatRN1S x=RN1S MaxDegreeGminusRN1S MaxDegreeG HatRN2S x=RN2S MaxDegreeGminusRN2S MaxDegreeG HatRN3S x=RN3S MaxDegreeGminusRN3S MaxDegreeG Hatsubplot(231)hold onhistf(RN1L MaxDegreeG0150facecolorbfacealpha5edgealpha1)histf(RN1L MaxDegreeG Hat0150facecolorrfacealpha5edgealpha1)histf(RN1L x0150facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightxlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN1L)grid on

subplot(232)hold onhistf(RN2L MaxDegreeG010500facecolorbfacealpha5edgealpha1)histf(RN2L MaxDegreeG Hat010500facecolorrfacealpha5edgealpha1)histf(RN2L x010500facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightxlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN2L)grid on

subplot(233)hold onhistf(RN3L MaxDegreeG010300facecolorbfacealpha5edgealpha1)histf(RN3L MaxDegreeG Hat010300facecolorrfacealpha5edgealpha1)histf(RN3L x010300facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightxlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN3L)

54 Application

grid on

subplot(234)hold onhistf(RN1S MaxDegreeG0150facecolorbfacealpha5edgealpha1)histf(RN1S MaxDegreeG Hat0150facecolorrfacealpha5edgealpha1)histf(RN1S x0150facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightxlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(R1NS)grid on

subplot(235)hold onhistf(RN2S MaxDegreeG010500facecolorbfacealpha5edgealpha1)histf(RN2S MaxDegreeG Hat010500facecolorrfacealpha5edgealpha1)histf(RN2S x010500facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightxlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN2S)grid on

subplot(236)hold onhistf(RN3S MaxDegreeG05300facecolorbfacealpha5edgealpha1)histf(RN3S MaxDegreeG Hat05300facecolorrfacealpha5edgealpha1)histf(RN3S x05300facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightgrid ontitle(RN3S)xlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labelset(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN2png minusr300)

h(3)=figure(NameComputation time over edgesNumberTitleoff)

subplot(231)hold onstem(RN1L EdgesGRN1L Time classicalg)stem(RN1L EdgesGRN1L Time algorithmro)stem(RN1L EdgesGRN1L Time greedybx)grid on

Appendix A 55

title(RN1L)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)

subplot(232)hold onstem(RN2L EdgesGRN2L Time classicalg)stem(RN2L EdgesGRN2L Time algorithmro)stem(RN2L EdgesGRN2L Time greedybx)grid ontitle(RN2L)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)

subplot(233)hold onstem(RN3L EdgesGRN3L Time classicalg)stem(RN3L EdgesGRN3L Time algorithmro)stem(RN3L EdgesGRN3L Time greedybx)grid ontitle(RN3L)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)

subplot(234)hold onstem(RN1S EdgesGRN1S Time classicalg)stem(RN1S EdgesGRN1S Time algorithmro)stem(RN1S EdgesGRN1S Time greedybx)grid ontitle(RN1S)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)

subplot(235)hold onstem(RN2S EdgesGRN2S Time classicalg)stem(RN2S EdgesGRN2S Time algorithmro)stem(RN2S EdgesGRN2S Time greedybx)grid ontitle(RN2S)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)

subplot(236)hold onstem(RN3S EdgesGRN3S Time classicalg)stem(RN3S EdgesGRN3S Time algorithmro)stem(RN3S EdgesGRN3S Time greedybx)

56 Application

grid ontitle(RN3S)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)set(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN3png minusr300)

h(4)=figure(NameSorted matching sizeNumberTitleoff)RN1L Sorted matching temp(1)=RN1L Classical matchingRN1L Sorted matching temp(2)=RN1L Final matchingRN1L Sorted matching temp(3)=RN1L Greedy matchingRN1L Sorted matching temp(4)=RN1L Initial matchingRN1L Sorted matching=sortrows(RN1L Sorted matching temp)

RN2L Sorted matching temp(1)=RN2L Classical matchingRN2L Sorted matching temp(2)=RN2L Final matchingRN2L Sorted matching temp(3)=RN2L Greedy matchingRN2L Sorted matching temp(4)=RN2L Initial matchingRN2L Sorted matching=sortrows(RN2L Sorted matching temp)

RN3L Sorted matching temp(1)=RN3L Classical matchingRN3L Sorted matching temp(2)=RN3L Final matchingRN3L Sorted matching temp(3)=RN3L Greedy matchingRN3L Sorted matching temp(4)=RN3L Initial matchingRN3L Sorted matching=sortrows(RN3L Sorted matching temp)

RN1S Sorted matching temp(1)=RN1S Classical matchingRN1S Sorted matching temp(2)=RN1S Final matchingRN1S Sorted matching temp(3)=RN1S Greedy matchingRN1S Sorted matching temp(4)=RN1S Initial matchingRN1S Sorted matching=sortrows(RN1S Sorted matching temp)

RN2S Sorted matching temp(1)=RN2S Classical matchingRN2S Sorted matching temp(2)=RN2S Final matchingRN2S Sorted matching temp(3)=RN2S Greedy matchingRN2S Sorted matching temp(4)=RN2S Initial matchingRN2S Sorted matching=sortrows(RN2S Sorted matching temp)

RN3S Sorted matching temp(1)=RN3S Classical matchingRN3S Sorted matching temp(2)=RN3S Final matchingRN3S Sorted matching temp(3)=RN3S Greedy matchingRN3S Sorted matching temp(4)=RN3S Initial matchingRN3S Sorted matching=sortrows(RN3S Sorted matching temp)

subplot(231)hold onplot(RN1L Sorted matching(1)b)plot(RN1L Sorted matching(2)g)plot(RN1L Sorted matching(3)r)plot(RN1L Sorted matching(4)m)

Appendix A 57

grid ontitle(RN1L)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)

subplot(232)hold onplot(RN2L Sorted matching(1)b)plot(RN2L Sorted matching(2)g)plot(RN2L Sorted matching(3)r)plot(RN2L Sorted matching(4)m)grid ontitle(RN2L)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)

subplot(233)hold onplot(RN3L Sorted matching(1)b)plot(RN3L Sorted matching(2)g)plot(RN3L Sorted matching(3)r)plot(RN3L Sorted matching(4)m)grid ontitle(RN3L)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)

subplot(234)hold onplot(RN1S Sorted matching(1)b)plot(RN1S Sorted matching(2)g)plot(RN1S Sorted matching(3)r)plot(RN1S Sorted matching(4)m)grid ontitle(RN1S)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)

subplot(235)hold onplot(RN2S Sorted matching(1)b)plot(RN2S Sorted matching(2)g)plot(RN2S Sorted matching(3)r)plot(RN2S Sorted matching(4)m)grid ontitle(RN2S)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)

58 Application

subplot(236)hold onplot(RN3S Sorted matching(1)b)plot(RN3S Sorted matching(2)g)plot(RN3S Sorted matching(3)r)plot(RN3S Sorted matching(4)m)grid ontitle(RN3S)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)set(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN4png minusr300)h(5)=figure(NameSorted RatiosNumberTitleoff)RN1L ratio1=RN1L NodesG hatRN1L NodesGRN2L ratio1=RN2L NodesG hatRN2L NodesGRN3L ratio1=RN3L NodesG hatRN3L NodesGRN1S ratio1=RN1S NodesG hatRN1S NodesGRN2S ratio1=RN2S NodesG hatRN2S NodesGRN3S ratio1=RN3S NodesG hatRN3S NodesG

RN1L ratio2=RN1L EdgesG HatRN1L EdgesGRN2L ratio2=RN2L EdgesG HatRN2L EdgesGRN3L ratio2=RN3L EdgesG HatRN3L EdgesGRN1S ratio2=RN1S EdgesG HatRN1S EdgesGRN2S ratio2=RN2S EdgesG HatRN2S EdgesGRN3S ratio2=RN3S EdgesG HatRN3S EdgesG

RN1L ratio3=RN1L MaxDegreeG HatRN1L MaxDegreeGRN2L ratio3=RN2L MaxDegreeG HatRN2L MaxDegreeGRN3L ratio3=RN3L MaxDegreeG HatRN3L MaxDegreeGRN1S ratio3=RN1S MaxDegreeG HatRN1S MaxDegreeGRN2S ratio3=RN2S MaxDegreeG HatRN2S MaxDegreeGRN3S ratio3=RN3S MaxDegreeG HatRN3S MaxDegreeG

RN1L ratio(1)=RN1L ratio1RN1L ratio(2)=RN1L ratio2RN1L ratio(3)=RN1L ratio3

RN2L ratio(1)=RN2L ratio1RN2L ratio(2)=RN2L ratio2RN2L ratio(3)=RN2L ratio3

RN3L ratio(1)=RN3L ratio1RN3L ratio(2)=RN3L ratio2RN3L ratio(3)=RN3L ratio3

RN1S ratio(1)=RN1S ratio1RN1S ratio(2)=RN1S ratio2RN1S ratio(3)=RN1S ratio3

RN2S ratio(1)=RN2S ratio1

Appendix A 59

RN2S ratio(2)=RN2S ratio2RN2S ratio(3)=RN2S ratio3

RN3S ratio(1)=RN3S ratio1RN3S ratio(2)=RN3S ratio2RN3S ratio(3)=RN3S ratio3

RN1L ratio sorted=sortrows(RN1L ratio)RN2L ratio sorted=sortrows(RN2L ratio)RN3L ratio sorted=sortrows(RN3L ratio)RN1S ratio sorted=sortrows(RN1S ratio)RN2S ratio sorted=sortrows(RN2S ratio)RN3S ratio sorted=sortrows(RN3S ratio)

subplot(231)hold onplot(RN1L ratio sorted(1)b)plot(RN1L ratio sorted(2)g)plot(RN1L ratio sorted(3)r)grid ontitle(RN1L)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)

subplot(232)hold onplot(RN2L ratio sorted(1)b)plot(RN2L ratio sorted(2)g)plot(RN2L ratio sorted(3)r)grid ontitle(RN2L)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)

subplot(233)hold onplot(RN3L ratio sorted(1)b)plot(RN3L ratio sorted(2)g)plot(RN3L ratio sorted(3)r)grid ontitle(RN3L)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)

subplot(234)hold onplot(RN1S ratio sorted(1)b)plot(RN1S ratio sorted(2)g)plot(RN1S ratio sorted(3)r)grid on

60 Application

title(RN1S)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)

subplot(235)hold onplot(RN2S ratio sorted(1)b)plot(RN2S ratio sorted(2)g)plot(RN2S ratio sorted(3)r)grid ontitle(RN2S)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)

subplot(236)hold onplot(RN3S ratio sorted(1)b)plot(RN3S ratio sorted(2)g)plot(RN3S ratio sorted(3)r)grid ontitle(RN3S)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)set(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN5png minusr300)

h(6)=figure(NameSorted edges over nodesNumberTitleoff)

RN1L DegreeG1=(RN1L EdgesG)(RN1L NodesG)RN1L DegreeG Hat1=(RN1L EdgesG Hat)(RN1L NodesG hat)

RN1L Degree temp1(1)=RN1L DegreeG1RN1L Degree temp1(2)=RN1L DegreeG Hat1RN1L Degree sorted1=sortrows(RN1L Degree temp1)subplot(231)hold on

plot(RN1L Degree sorted1(1)b)plot(RN1L Degree sorted1(2)g)grid ontitle(RN1L)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)

RN2L DegreeG1=(RN2L EdgesG)(RN2L NodesG)RN2L DegreeG Hat1=(RN2L EdgesG Hat)(RN2L NodesG hat)

RN2L Degree temp1(1)=RN2L DegreeG1

Appendix A 61

RN2L Degree temp1(2)=RN2L DegreeG Hat1RN2L Degree sorted1=sortrows(RN2L Degree temp1)

subplot(232)hold onplot(RN2L Degree sorted1(1)b)plot(RN2L Degree sorted1(2)g)grid ontitle(RN2L)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)

RN3L DegreeG1=(RN3L EdgesG)(RN3L NodesG)RN3L DegreeG Hat1=(RN3L EdgesG Hat)(RN3L NodesG hat)

RN3L Degree temp1(1)=RN3L DegreeG1RN3L Degree temp1(2)=RN3L DegreeG Hat1RN3L Degree sorted1=sortrows(RN3L Degree temp1)

subplot(233)hold onplot(RN3L Degree sorted1(1)b)plot(RN3L Degree sorted1(2)g)grid ontitle(RN3L)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)

RN1S DegreeG1=(RN1S EdgesG)(RN1S NodesG)RN1S DegreeG Hat1=(RN1S EdgesG Hat)(RN1S NodesG hat)

RN1S Degree temp1(1)=RN1S DegreeG1RN1S Degree temp1(2)=RN1S DegreeG Hat1RN1S Degree sorted1=sortrows(RN1S Degree temp1)

subplot(234)hold onplot(RN1S Degree sorted1(1)b)plot(RN1S Degree sorted1(2)g)grid ontitle(RN1S)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)

RN2S DegreeG1=(RN2S EdgesG)(RN2S NodesG)RN2S DegreeG Hat1=(RN2S EdgesG Hat)(RN2S NodesG hat)

RN2S Degree temp1(1)=RN2S DegreeG1

62 Application

RN2S Degree temp1(2)=RN2S DegreeG Hat1RN2S Degree sorted1=sortrows(RN2S Degree temp1)

subplot(235)hold onplot(RN2S Degree sorted1(1)b)plot(RN2S Degree sorted1(2)g)grid ontitle(RN2S)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)

RN3S DegreeG1=(RN3S EdgesG)(RN3S NodesG)RN3S DegreeG Hat1=(RN3S EdgesG Hat)(RN3S NodesG hat)

RN3S Degree temp1(1)=RN3S DegreeG1RN3S Degree temp1(2)=RN3S DegreeG Hat1RN3S Degree sorted1=sortrows(RN3S Degree temp1)

subplot(236)hold onplot(RN3S Degree sorted1(1)b)plot(RN3S Degree sorted1(2)g)grid ontitle(RN3S)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)set(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN6png minusr300)h(7)=figure(NameSorted mATCHED DEGREENumberTitleoff)RN1L ratioMax(1)=RN1L MaxDegreeGRN1L ratioMax(2)=RN1L MaxDegreeG Hat

RN1L ratio sortedMax=sortrows(RN1L ratioMax)subplot(231)hold onplot(RN1L ratio sortedMax(1)b)plot(RN1L ratio sortedMax(2)g)grid ontitle(RN1L)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)

RN2L ratioMax(1)=RN2L MaxDegreeGRN2L ratioMax(2)=RN2L MaxDegreeG Hat

RN2L ratio sortedMax=sortrows(RN2L ratioMax)subplot(232)

Appendix A 63

hold onplot(RN2L ratio sortedMax(1)b)plot(RN2L ratio sortedMax(2)g)grid ontitle(RN2L)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)

RN3L ratioMax(1)=RN3L MaxDegreeGRN3L ratioMax(2)=RN3L MaxDegreeG Hat

RN3L ratio sortedMax=sortrows(RN3L ratioMax)subplot(233)hold onplot(RN3L ratio sortedMax(1)b)plot(RN3L ratio sortedMax(2)g)grid ontitle(RN3L)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)

RN1S ratioMax(1)=RN1S MaxDegreeGRN1S ratioMax(2)=RN1S MaxDegreeG Hat

RN1S ratio sortedMax=sortrows(RN1S ratioMax)subplot(234)hold onplot(RN1S ratio sortedMax(1)b)plot(RN1S ratio sortedMax(2)g)grid ontitle(RN1S)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)

RN2S ratioMax(1)=RN2S MaxDegreeGRN2S ratioMax(2)=RN2S MaxDegreeG Hat

RN2S ratio sortedMax=sortrows(RN2S ratioMax)

subplot(235)hold onplot(RN2S ratio sortedMax(1)b)plot(RN2S ratio sortedMax(2)g)grid ontitle(RN2S)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)

RN3S ratioMax(1)=RN3S MaxDegreeGRN3S ratioMax(2)=RN3S MaxDegreeG Hat

64 Application

RN3S ratio sortedMax=sortrows(RN3S ratioMax)subplot(236)hold onplot(RN3S ratio sortedMax(1)b)plot(RN3S ratio sortedMax(2)g)grid ontitle(RN1L)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)set(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN7png minusr300)

tilefigs()(h)

Bibliography

[1] C Berge ldquoTWO THEOREMS IN GRAPH THEORYrdquo Proceedings of the NationalAcademy of Sciences of the United States of America vol 43 no 9 pp 842ndash844Sep 1957

[2] L Bui S Sanghavi and R Srikant ldquoDistributed link scheduling with constantoverheadrdquo IEEEACM Trans Netw vol 17 no 5 pp 1467ndash1480 2009

[3] R Duan and S Pettie ldquoLinear-time approximation for maximum weight matchingrdquoJ ACM vol 61 no 1 2014

[4] J Edmonds ldquoPaths trees and flowersrdquo Canadian Journal of Mathematics vol 17pp 449ndash467 1965

[5] J E Hopcroft and R M Karp ldquoAn n52 algorithm for maximum matchings inbipartite graphsrdquo SIAM J Comput vol 2 no 4 pp 225ndash231 1973

[6] S Micali and V V Vazirani ldquoAn O(radic|V ||E|) algorithm for finding maximum

matching in general graphsrdquo in 21st Symp on Foundations of Comp Sc (FOCS)IEEE 1980 pp 17ndash27

[7] N Nisse A Salch and V Weber ldquoRecovery of disrupted airline operationsrdquo 2015httphalinriafrSomething

[8] X Wu and R Srikant ldquoRegulated maximal matching A distributed schedulingalgorithm for multi-hop wireless networks with nodeexclusive spectrum sharingrdquo inIEEE Conf on Decision and Control 2005

65

  • Contents
  • Introduction
  • Algorithms
    • Maximum matching
    • k-maximum matching
      • k-matching for Airport Slot assignment
      • The case where k=3
      • The case of Paths
      • The case of the Spider
          • Application
            • Description
            • Reyni Erdos
            • Barabaacutesi Albert
            • Amadeus Graphs
            • Bipartite
            • Bipartite with degree seq
            • Appendix A
              • BipartiteGraphGeneratorpy
              • RandomGraphGeneratorpy
              • kequals3MaximumMatchingpy
              • Plotmat
                  • Bibliography
Page 12: Theodoros Alexandros KARAGKIOULES -  · Introduction This work is the result of a 6 months internship, under the supervision of research O cer Nicolas NISSE. The original scope of

22 Reyni Erdos 13

Sorted Ratios - Comments

bull This set of figures depicts the ratios VV

EE

∆∆

in ascending order of VV

bull It is evident that when the initial matching is large the amount of forced edges(and their endpoints) removed is high thus the ratio of Nodes and edges is verylow For higher probabilities almost all edges are removed as useless

bull For a smaller initial matching almost no forced edges (and their endpoints) areremoved which we conclude be the node ration being close to 1 There is somesmall amount of useless edges removed though since the ratio of edges is less butclose to 1

bull The ratio of ∆ for large initial matching follows the trend of the node ratio yetfor smaller initial matching it deviates significantly

14 Application

Sorted |E||V |

Sorted |E||V | - Comments

bull Although as graph density the ratio 2|E||V |(|V |minus1)

is considered in this set of figures

we evaluate the correlation of the ratio |E||V | of G and G since the density of G

could acquire values higher than that of G

bull The figures are calculated in ascending order for the ratio of G

bull For the case of large initial matching the two ratios for G and G remain almostconstant ( to the extent of the probability of each graph) since removing forcededges( and their endpoints) alters the |E| and |V | proportionately

22 Reyni Erdos 15

bull For the case of small initial matching we observe some deviation in the valuesof the ration for G and that is explained with the removal of only useless edgeswhich only alters the |E| and keeps |V | in the original values

Sorted ∆

Sorted ∆-Comments

bull In this set of figures the ascending order of the ∆ of G is associated with the ∆of G

bull There is no significant jump of the ∆ for each graph category which tells that thatwe are comparing a uniform distribution of random grapghs for each probabilitycase

16 Application

bull For larger initial matching we observe the difference in the ∆s of G and G giventhe removed forced edges( and their endpoints) At some cases the ∆ of G dropsto 0 since the vast majority of edges have been declared forced and removed alongwith their endpoints

bull For smaller initial matching the ∆s of G and G follow mostly the same trend onlya few number of different instances

23 Barabasi Albert

Graph characteristics Barabasi Albert

bull BAxy are randomly generated graphs with a fixed number of 1000 nodes

bull There are 6 categories based on ini matching and of attached edges m

bull x = L S L When the initial matching is large and S when it is small

bull y = 1 2 3 1 when m = [1 10] 2 when m = [20 50] and 3 m = [50 100]

Computation time over |E|

23 Barabasi Albert 17

Computation time over |E| - Comments

bull When the initial matching is sufficiently large then the forced edges are taken out(a process which takes a fragment of the computation time) and then the classicalmatching algorithm (Edmonds) is applied on a smaller graph(G) This reducessignificantly the computation time

bull When the initial matching is small then the computation time of the constraintalgorithm might be larger than that of Edmonds The reason is that the constraintalgorithm need some time to compute the useless and forced edges and thenEdmonds algorithm is applied on G G Thus the overall processing time issometimes larger

Sorted matching size

18 Application

Sorted matching size-Comments

bull In this graph the matching size of the classical algorithm is depicted in ascendingorder along with the corresponding constraint algorithm and greedy result

bull Here in the case where m is small for both cases of initial matching (small large)the result may vary greatly starting from a value of half the perfect matching withsmall differences between the results of the various algorithm implementations

bull For the other cases of m the results converge

bull This is explained as for small values of m the graph is disconnected

bull In the matching size difference set of figures a very noticing difference value ap-pears For the cases of small m( the number of existing nodes that a new node isconnected to at the creation of the graph) we can see that the difference in the

23 Barabasi Albert 19

matching size compared to that of the perfect matching could be up to 40 ofthat of the matching size So there are occasions where the matching size is 200edges when the perfect matching would have been 500

bull the difference between the Constraint matching and the classical matching andthe difference of the constraint matching and that of the greedy matching do notshow significant values

Sorted Ratios

Sorted Ratio s -Comments

bull This set of figures depicts the ratios VV

EE

∆∆

in ascending order of VV

20 Application

bull It is evident that when the initial matching is large the amount of forced edges(and their endpoints) removed is high thus the ratio of Nodes and edges is verylow For higher probabilities almost all edges are removed as useless

bull For a smaller initial matching almost no forced edges (and their endpoints) areremoved which we conclude be the node ration being close to 1 There is somesmall amount of useless edges removed though since the ratio of edges is less butclose to 1

bull The ratio of ∆ for large initial matching follows the trend of the node ratio yetfor smaller initial matching it deviates significantly

Sorted |E||V |

23 Barabasi Albert 21

Sorted |E||V | - Comments

bull Although as graph density the ratio 2|E||V |(|V |minus1)

is considered in this set of figures

we evaluate the correlation of the ratio |E||V | of G and G since the density of G

could acquire values higher than that of G

bull The figures are calculated in ascending order for the ratio of G

bull For the case of large initial matching the two ratios for G and G remain almostconstant ( to the extent of the edge attraction m of each graph) since removingforced edges( and their endpoints) alters the |E| and |V | proportionately

bull For the case of small initial matching we observe some deviation in the valuesof the ration for G and that is explained with the removal of only useless edgeswhich only alters the |E| and keeps |V | in the original values

Sorted ∆

22 Application

Sorted ∆-Comments

bull In this set of figures the ascending order of the ∆ of G is associated with the ∆of G

bull There is a significant jump of the ∆ for each graph category which tells that thatwe are not comparing a uniform distribution of random graphs and based on theedge attraction m the graphs can vary in form

bull For larger initial matching we observe the difference in the ∆s of G and G giventhe removed forced edges( and their endpoints) At some cases the ∆ of G dropsto 0 since the vast majority of edges have been declared forced and removed alongwith their endpoints What is interesting is that the ∆ of G oscilates within stablelimits

24 Amadeus Graphs 23

bull For smaller initial matching the ∆s of G and G follow mostly the same trend onlya few number of different instances

24 Amadeus Graphs

Graph characteristics Amadeus graphs

bull These are the bipartite graphs provided by Amadeus

Computation time over |E|

Computation time over |E| - Comments

24 Application

bull For every instance the computation time of the classical algorithm is always smallerto that of the constraint matching

bull This allows as to speculate that we always compute a smaller G which also impliesthat we always find a set of forced edges and useless

Sorted matching size

Sorted matching size - Comments

bull Size of matching has an upward trend since the magnitude of the graphs is notthe same for the 160 instances

bull No significant deviation is noticed as per the first graph

24 Amadeus Graphs 25

bull Except from deviation from the perfect matching (number of flights) where some-times it could get up to 40

bull For the Amadeus Bipartite graphs we can see that the difference of the Classicaland the constraint implementation is not more than 1 edge in the matching

bull There appears to be a difference of up to 24 edges between the Classical matchingand the Perfect matching which is computed as the number of flights

bull The greedy algorithm performs well with only a few instances deviating slightlyform the Constraint algorithm result

Sorted Ratios

Sorted Ratios - Comments

26 Application

bull

Sorted |E||V |

Sorted |E||V | - Comments

bull Density of the graphs shows that on average we have 25-3 available time slot perflight

bull The line for the same value for G shows that there is a large deviation for everyinstance which allows for the hypothesis that the amount of useless+forced edgesof G has no obvious correlation to that of G

25 Bipartite 27

Sorted ∆

Sorted ∆-Comments

bull As per the previous related graphs for ∆ there is in significant drop in the ∆ of Gand G

25 Bipartite

Graph characteristics Bipartite random Graphs

bull BIPxy are randomly generated graphs with a fixed number of 1000(n=500 andm=500) nodes

bull There are 6 categories based on ini matching and probability p

28 Application

bull Probability p has been chosen as such in order to simulate the |E||V | 25 of theAmadeus bipartite graphs

bull So in order to have about 2-4 edges for every node we choose accordingly theprobability p to choose one of the n lowastm possible edges

bull x = L S L When the initial matching is large and S when it is small

bull y = 1 2 3 1 when p = 18250

2 when p = 25250

and 3 when p = 34250

Computation time over

Computation time overedges-Comments

bull

25 Bipartite 29

Sorted matching size

Sorted matching size-Comments

bull In these set of graphs one can instantly notice that only a few instances with highprobability can reach a matching size equal to the perfect matching

bull For the case of the initial matching we witness that there is a gap between the lineof the classical matching and those of the constraint and greedy results suggestingsmaller matching sizes of 10-40 edges

bull For the case of the small initial matching the result of the constraint matchingis now close to the result of the classical matching yet the greedy algorithm stillshows a relevantly big difference

30 Application

bull In this set of bipartite graphs we can witness that the result of the Constraintmatching shows a difference with the classical matching when the initial matchingis large The difference is smaller as the probability gets larger

bull For the case of the small initial matching the above phenomenom does not occuryet the greedy results deviates from that of the constraint matching

bull As per the pefrect matching compared to the classical matching a difference of5-10 edges is evident at almost all cases

Sorted Ratios

Sorted Ratios-Comments

bull Great max degree deviation

25 Bipartite 31

bull Regardless of the probability the ration of nodes and edges seems to have similarbehaviour when compared to the respective graphs of the same matching scale

bull Same gap between nodes ration and edges ration for all cases

Sorted |E||V |

Sorted |E||V | - Comments

bull In these set of figures we witness that the |E||V | acquires values relevant to those ofthe amadeus graphs The random graphs were constructed to depict this similarity

bull For smaller initial matching the ratios for G and G show the same upward trendand also they acquire closer values It represents the decrease of the averagenumber of forced edges in comparison to the larger matching cases

32 Application

Sorted ∆

Sorted ∆-Comments

bull ∆ acquires the same min and max values for each probability case (expected)

bull Gap in the case of large initial matching

26 Bipartite with degree seq

Graph characteristics

bull DEQBIPxy are randomly generated graphs based on three different types of degreedistribution of the Amadeus graphs

26 Bipartite with degree seq 33

bull There are 6 categories based on ini matching and degree distribution

bull x = L S L When the initial matching is large and S when it is small

bull y = 1 2 3 1 when degree distribution is based on file 2 when degree distributionis based on file and 3 when degree distribution is based on file

Computation time over

34 Application

Computation time overedges-Comments

bull Greedy algorithm takes minimum amount of time

bull The smaller the initial matching the more smaller the difference in comoutationtime of Constraint and classical algorithm

bull Due to preprocessing and the fact that G and G are the almost identical thetotal time needed to apply the constraint algorithm is in some cases bigger

Sorted matching size

26 Bipartite with degree seq 35

Sorted matching size-Comments

bull Classical matching is equal to perfect matching in every case

bull Constraint and greedy have identical behaviour

bull The larger the spectrum of the degree sequence the more efficient the matching

Sorted Ratios

36 Application

Sorted Ratios-Comments

bull With large initial matching most of the edges are considenred uselles or forced andare removed thus the ratio is close(if not equal to) zero

bull For small matching and large degree sequence sectrum hte max degree remainsthe same Only a few forced edges (and their nodes) are removed apparently nonodes with max degree

Sorted |E||V |

26 Bipartite with degree seq 37

Sorted |E||V | - Comments

bull In these set of figures we witness that the |E||V | acquires values relevant to those ofthe amadeus graphs The random graphs were constructed to depict this similarity

bull For smaller initial matching the ratios for G and G show the same upward trendand also they acquire closer values It repsresent the decrease of the averagenumber of forced edges in comparison to the larger matching cases

Sorted ∆

38 Application

Sorted ∆-Comments

bull Big difference in max degree in large initial matching

bull Almost identical behaviour in the case of small initial matching

Appendix A 39

Appendix A

BipartiteGraphGeneratorpy

from future import divisionimport networkx as nx

from networkxalgorithms import approximationimport collectionsimport randomimport mathfrom networkxalgorithms import bipartiteif name == main

for i in range(1481)waqs 481index=1n=randomrandint(100 1000)

n1=95 was 500me1=118

n2=251 was 500me2=903

n3=165 was 500me3=412

m=0m1=0p=randomrandom()p1=18250p2=25250p3=34250print ip=05t1=randomrandint(0 1)print im2=randomrandint(n2minus1 n2+1)G = nxGraph()ma = nxGraph()

aseq1=[1 2 3 4 5 3]

bseq1=[4 3 3 1 2 2 1]

aseq2=[16 14 14 14 12 11]bseq2=[0 0 0 0 0 0]

aseq3=[8 7 8 8 8 8]bseq3=[0 0 0 0 0 0]

40 Application

print Gnumber of edges()if ilt=160

G=bipartiteconfiguration model(aseq1 bseq1 create using=None seed=None)A=nxadjacency matrix(G)for ii in range(0n1+me1)

maadd node(ii)A=[Rtodense()tolist()[0] for R in A]

printnummanumber of nodes()rl=randomsample(range(0n1+me1) n1+me1)m=0done vertices = set()for p in rlprintin fordone verticesadd(p)

neighbors = []list()for iii in range(0n1+me1)

if A[p][iii]==1neighborsappend(iii)

randomshuffle(neighbors)continue loop = Truedegree = len(neighbors)

print degreej = 0p4=randomrandom()while continue loop and (jltdegree)print in loop

next = neighbors[j]if next not in done vertices and p not in done vertices

done verticesadd(p)done verticesadd(next)if p4gt=07print added edge

maadd edge(pnext)m=m+1

continue loop = Falsej += 1

print matching listOfedgeprint maedge

MA=nxadjacency matrix(ma)print MA

MA=[Rtodense()tolist()[0] for R in MA]print MA

B=[ join(map(strR)) for R in A]MB=[ join(map(strR)) for R in MA]

C=njoin(B)+nMC=njoin(MB)+n

print nprint mprint m1

filea=str(i)+txtwith open(fileaw) as f

Appendix A 41

fwrite(str(n1+me1))fwrite(n)fwrite(str(n1+me1))fwrite(n)fwrite(str(m))fwrite(n)fwrite(n)fwrite(C)fwrite(n)fwrite(MC)

elif igt160 and ilt321G=bipartiteconfiguration model(aseq2 bseq2 create using=None seed=None)A=nxadjacency matrix(G)for ii in range(0n2+me2)

maadd node(ii)A=[Rtodense()tolist()[0] for R in A]

printnummanumber of nodes()rl=randomsample(range(0n2+me2) n2+me2)m=0done vertices = set()for p in rlprintin fordone verticesadd(p)

neighbors = []list()for iii in range(0n2+me2)

if A[p][iii]==1neighborsappend(iii)

randomshuffle(neighbors)continue loop = Truedegree = len(neighbors)

print degreej = 0p4=randomrandom()while continue loop and (jltdegree)

print in loopnext = neighbors[j]if next not in done vertices and p not in done vertices

done verticesadd(p)done verticesadd(next)if p4gt=07

print added edgemaadd edge(pnext)m=m+1

continue loop = Falsej += 1

print matching listOfedgeprint maedge

MA=nxadjacency matrix(ma)print MA

MA=[Rtodense()tolist()[0] for R in MA]print MA

B=[ join(map(strR)) for R in A]MB=[ join(map(strR)) for R in MA]

42 Application

C=njoin(B)+nMC=njoin(MB)+n

print nprint mprint m1

filea=str(i)+txtwith open(fileaw) as f

fwrite(str(n2+me2))fwrite(n)fwrite(str(n2+me2))fwrite(n)fwrite(str(m))fwrite(n)fwrite(n)fwrite(C)fwrite(n)fwrite(MC)

elseG=bipartiteconfiguration model(aseq3 bseq3 create using=None seed=None)A=nxadjacency matrix(G)for ii in range(0n3+me3)

maadd node(ii)A=[Rtodense()tolist()[0] for R in A]

printnummanumber of nodes()rl=randomsample(range(0n3+me3) n3+me3)m=0done vertices = set()for p in rlprintin fordone verticesadd(p)

neighbors = []list()for iii in range(0n3+me3)

if A[p][iii]==1neighborsappend(iii)

randomshuffle(neighbors)continue loop = Truedegree = len(neighbors)

print degreej = 0p4=randomrandom()while continue loop and (jltdegree)

print in loopnext = neighbors[j]if next not in done vertices and p not in done vertices

done verticesadd(p)done verticesadd(next)if p4gt=07print added edge

maadd edge(pnext)m=m+1

continue loop = Falsej += 1

Appendix A 43

print matching listOfedgeprint maedge

MA=nxadjacency matrix(ma)print MA

MA=[Rtodense()tolist()[0] for R in MA]print MA

B=[ join(map(strR)) for R in A]MB=[ join(map(strR)) for R in MA]

C=njoin(B)+nMC=njoin(MB)+n

print nprint mprint m1

filea=str(i)+txtwith open(fileaw) as f

fwrite(str(n3+me3))fwrite(n)fwrite(str(n3+me3))fwrite(n)fwrite(str(m))fwrite(n)fwrite(n)fwrite(C)fwrite(n)fwrite(MC)

print nRandom graphs with random matching have been generated

44 Application

RandomGraphGeneratorpy

from future import divisionimport networkx as nxfrom networkxalgorithms import approximationimport collectionsimport randomimport mathif name == main

for i in range(1481)index=1n=randomrandint(100 1000)

n=1000m=0m1=0p=randomrandom()p1=mathlog(n2)np2=13p3=mathlog(n2)n+01p=05t1=randomrandint(0 1)print im2=randomrandint(n2minus1 n2+1)G = nxGraph()ma = nxGraph()print nme1=randomrandint(1 10)me2=randomrandint(2050)me3=randomrandint(50100)if ilt241

if ilt=80G=nxfast gnp random graph(n p1 seed=None directed=False)

elif igt80 and ilt161G=nxfast gnp random graph(n p2 seed=None directed=False)

elseG=nxfast gnp random graph(n p3 seed=None directed=False)

elseif ilt=320

G=nxbarabasi albert graph(n me1 seed=None)elif igt320 and ilt401

G=nxbarabasi albert graph(n me2 seed=None)else

G=nxbarabasi albert graph(n me3 seed=None)A=nxadjacency matrix(G)for ii in range(0n)

maadd node(ii)A=[Rtodense()tolist()[0] for R in A]

rl=randomsample(range(0n) n)m=0

Appendix A 45

done vertices = set()for p in rl

done verticesadd(p)neighbors = []list()for iii in range(0n)

if A[p][iii]==1neighborsappend(iii)

randomshuffle(neighbors)continue loop = Truedegree = len(neighbors)j = 0p2=randomrandom()while continue loop and (jltdegree)

next = neighbors[j]if next not in done vertices and p not in done vertices

done verticesadd(p)done verticesadd(next)if p2gt=00 Larger probability for smaller initial matching

maadd edge(pnext)m=m+1

continue loop = Falsej += 1

print matching listOfedgeprint maedgeMA=nxadjacency matrix(ma)MA=[Rtodense()tolist()[0] for R in MA]print MAB=[ join(map(strR)) for R in A]MB=[ join(map(strR)) for R in MA]

C=njoin(B)+nMC=njoin(MB)+nprint MCprint nprint mprint m1filea=str(i)+txtwith open(fileaw) as f

fwrite(str(n))fwrite(n)fwrite(str(n))fwrite(n)fwrite(str(m))fwrite(n)fwrite(n)fwrite(C)fwrite(n)fwrite(MC)

print nRandom graphs with random matching have been generated

46 Application

kequals3MaximumMatchingpy

from future import divisionimport networkx as nxfrom networkxalgorithms import bipartiteimport matplotlibpyplot as pltimport collectionsimport timeitimport xlwtimport xlrdimport mathimport sys

Case for General Graphsdef forced edges(Gadj dict2matching dict1num nodesforced)

flagg=0for n in range(0num nodes)

for k in adj dict2[n]if ([k]==matching dict1[n])

count=0for l in range(0num nodes)

count=count+adj dict2[l]count(k)if (len(adj dict2[n])==1) or (count==1)

forcedadd edge(nk)Gremove edge(nk)Gremove node(n)Gremove node(k)printforced edgenktemp=kflagg=1for m in range (len(adj dict2[n])minus1minus1minus1)

adj dict2[adj dict2[n][m]]remove(n)adj dict2[n]remove(adj dict2[n][m])

if adj dict2[temp]for l in range(len(adj dict2[temp])minus1minus1minus1)

if (adj dict2[temp][l]=n)adj dict2[adj dict2[temp][l]]remove(temp)adj dict2[temp]remove(adj dict2[temp][l])

break

def useless edges(num nodesadj dict1matching dict1uselessadj dict2G)for n in range(0num nodes)

for k in adj dict1[n]if ([k]=matching dict1[n]) and matching dict1[n] and matching dict1[k]

uselessadd edge(nk)Gremove edge(n k)

Appendix A 47

tempa=kadj dict2[n]remove(k)adj dict2[tempa]remove(n)adj dict1[tempa]remove(n)

return G

def Greedy(num nodesadj dict3matching dict2)

for n in range(0num nodes)if matching dict2[n]

flag2=minus1flag3=minus1for v in adj dict3[n]

if not matching dict2[v]flag2=vbreak

for p in adj dict3[matching dict2[n][0]]if not matching dict2[p]

flag3=pbreak

if (flag2=minus1) and (flag3=minus1) and (flag2=flag3)tempr=matching dict2[n][0]matching dict2[n]=[flag2]matching dict2[flag2]=[n]matching dict2[tempr]=[flag3]matching dict2[flag3]=[tempr]

elsefor k in adj dict3[n]

if not matching dict2[k]matching dict2[n]=[k]matching dict2[k]=[n]break

yo1=0for i in range(0num nodes)

if matching dict2[i] and [i]==matching dict2[matching dict2[i][0]]yo1=yo1+1

greedy size=yo12return greedy size

def General()

INPUTSwb = xlwtWorkbook()ws = wbadd sheet(Results Random)book=xlrdopen workbook(filenames randomxls)

48 Application

style0 = xlwteasyxf(fontbold on)style1 = xlwteasyxf(num format str=0000)INPUTSwswrite(0 0File style0)wswrite(0 1 Nodesstyle0)wswrite(0 2 Initial matchingstyle0)wswrite(0 3 NodesGstyle0)wswrite(0 4 EdgesGstyle0)wswrite(0 5 MaxDegreeGstyle0)wswrite(0 6 NodesG hatstyle0)wswrite(0 7 EdgesG Hatstyle0)wswrite(0 8 Useless edgesstyle0)wswrite(0 9 Forced edgesstyle0)wswrite(0 10 MaxDegreeG Hatstyle0)wswrite(0 11 Classical matchingstyle0)wswrite(0 12 Final matchingstyle0)wswrite(0 13 Greedy matchingstyle0)wswrite(0 14 Time classicalstyle0)wswrite(0 15 Time algorithmstyle0)wswrite(0 16 Time greedystyle0)wswrite(0 17 Perfect matching ratiostyle0)wswrite(0 18 Nodes ratiostyle0)wswrite(0 19 Edges ratiostyle0)wswrite(0 20 Matching ratiostyle0)

print nWelcomeThis is an implementation for general random graphs It uses Edmonds algorithm to compute maximum matching on G Hatn

for index in range (1481)was 481

if (index==482)f=open(Algotel generaltxtr)readlines()

elsefilea=str(booksheet by index(0)cell(index0))s=fileareplace(textu)replace()f=open(sr)readlines()Truewswrite(index 0 s)

print index

num nodes=int([xstrip()split() for x in f][0][0])

num matching=int([xstrip()split() for x in f][2][0])

adj temp = [xstrip()split() for x in f][44+num nodes]adj=[map(intR) for R in adj temp]

matching temp=[xstrip()split() for x in f][4+num nodes+14+2num nodes+1]matching1=[map(intR) for R in matching temp]

adj dict1=i[ii for iix in enumerate(L) if x] for iL in enumerate(adj)adj dict2=i[ii for iix in enumerate(L) if x] for iL in enumerate(adj)

Appendix A 49

adj dict3=i[ii for iix in enumerate(L) if x] for iL in enumerate(adj)

matching dict1=i[ii for iix in enumerate(L) if x] for iL in enumerate(matching1)matching dict2=i[ii for iix in enumerate(L) if x] for iL in enumerate(matching1)print adj dict2print matching dict2wswrite(index 1 num nodes)wswrite(index 2 num matching)

G = nxGraph()

useless= nxGraph()forced = nxGraph()

Fill Graphfor n in range(0num nodes)

for k in adj dict1[n]Gadd edge(nk)

Gt=Gnumber of edges()wswrite(index 3 Gnumber of nodes())wswrite(index 4 Gnumber of edges())wswrite(index 5 max(Gdegree()values()))

Compute Edmonds classical matching on G for comparison

startB = timeitdefault timer()Classical Matching=nxmax weight matching(G maxcardinality=False)stopB = timeitdefault timer()

Compute Gˆ nad MˆstartC = timeitdefault timer()useless edges(num nodesadj dict1matching dict1uselessadj dict2G)forced edges(Gadj dict2matching dict1num nodesforced)Final Matching=nxmax weight matching(G maxcardinality=False)stopC = timeitdefault timer()

GreedystartG = timeitdefault timer()greedy size=Greedy(num nodesadj dict3matching dict2)stopG = timeitdefault timer()

wswrite(index 6 Gnumber of nodes())wswrite(index 7 Gnumber of edges())wswrite(index 8 uselessnumber of edges())wswrite(index 9 forcednumber of edges())if Gdegree()values()

wswrite(index 10 max(Gdegree()values()))else

50 Application

wswrite(index 10 0)wswrite(index 11 len(Classical Matching)2)wswrite(index 12 len(Final Matching)2+forcednumber of edges())wswrite(index 13 greedy size)wswrite(index 14 stopB minus startBstyle1)wswrite(index 15 stopC minus startCstyle1)wswrite(index 16 stopG minus startGstyle1)wswrite(index 17 (len(Final Matching)2+forcednumber of edges())(num nodes2)style1)wswrite(index 18 Gnumber of nodes()Gtstyle1)wswrite(index 19 Gnumber of edges()Gtstyle1)wswrite(index 20 (len(Final Matching)2+forcednumber of edges())(len(Classical Matching)2)style1)

wbsave(AA Results Random Reyni Large Bipartitexls)

Main function Here we must choose the input form of the dataif name == main

startA = timeitdefault timer()General()stopA = timeitdefault timer()

print nThis program has terminatednnRunning time for 480 files stopAminusstartAprint nnPlease open AA Results Random Reyni Largexls file to see the Results

Appendix A 51

Plotmat

clear allclose allload(RN1Lmat)load(RN1Smat)load(RN2Lmat)load(RN2Smat)load(RN3Lmat)load(RN3Smat)

Plotsh(1)=figure(NameHistogram of Matching size difference between Constraint Algorithm and Greedy AlgorithmNumberTitleoff)

RN1L Greedydiff=RN1L Final matchingminusRN1L Greedy matchingRN2L Greedydiff=RN2L Final matchingminusRN2L Greedy matchingRN3L Greedydiff=RN3L Final matchingminusRN3L Greedy matchingRN1S Greedydiff=RN1S Final matchingminusRN1S Greedy matchingRN2S Greedydiff=RN2S Final matchingminusRN2S Greedy matchingRN3S Greedydiff=RN3S Final matchingminusRN3S Greedy matching

RN1L Finaldiff=RN1L Classical matchingminusRN1L Final matchingRN2L Finaldiff=RN2L Classical matchingminusRN2L Final matchingRN3L Finaldiff=RN3L Classical matchingminusRN3L Final matchingRN1S Finaldiff=RN1S Classical matchingminusRN1S Final matchingRN2S Finaldiff=RN2S Classical matchingminusRN2S Final matchingRN3S Finaldiff=RN3S Classical matchingminusRN3S Final matching

RN1L Classicaldiff=(RN1L Nodes2)minusRN1L Classical matchingRN2L Classicaldiff=(RN2L Nodes2)minusRN2L Classical matchingRN3L Classicaldiff=(RN3L Nodes2)minusRN3L Classical matchingRN1S Classicaldiff=(RN1S Nodes2)minusRN1S Classical matchingRN2S Classicaldiff=(RN2S Nodes2)minusRN2S Classical matchingRN3S Classicaldiff=(RN3S Nodes2)minusRN3S Classical matching

subplot(231)hold onhistf(RN1L Greedydiff0110facecolorbfacealpha9edgealpha1)histf(RN1L Finaldiff0110facecolorrfacealpha5edgealpha1)histf(RN1L Classicaldiff0110facecolorgfacealpha5edgealpha1)legalpha(ConminusGreClasminusConPerfminusClasslocationnortheast)legend boxoffaxis tightxlabel(edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN1L)grid on

subplot(232)hold onhistf(RN2L Greedydiff0110facecolorbfacealpha9edgealpha1)

52 Application

histf(RN2L Finaldiff0110facecolorrfacealpha5edgealpha1)histf(RN2L Classicaldiff0110facecolorgfacealpha5edgealpha1)legalpha(ConminusGreClasminusConPerfminusClasslocationnortheast)legend boxoffaxis tightxlabel(edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN2L)grid on

subplot(233)hold onhistf(RN3L Greedydiff0110facecolorbfacealpha5edgealpha1)histf(RN3L Finaldiff0110facecolorrfacealpha5edgealpha1)histf(RN3L Classicaldiff0110facecolorgfacealpha5edgealpha1)legalpha(ConminusGreClasminusConPerfminusClasslocationnortheast)legend boxoffaxis tightxlabel(edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN3L)grid on

subplot(234)hold onhistf(RN1S Greedydiff0110facecolorbfacealpha5edgealpha1)histf(RN1S Finaldiff0110facecolorrfacealpha5edgealpha1)histf(RN1S Classicaldiff0110facecolorgfacealpha5edgealpha1)legalpha(ConminusGreClasminusConPerfminusClasslocationnortheast)legend boxoffaxis tightxlabel(edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(R1NS)grid on

subplot(235)hold onhistf(RN2S Greedydiff0110facecolorbfacealpha5edgealpha1)histf(RN2S Finaldiff0110facecolorrfacealpha5edgealpha1)histf(RN2S Classicaldiff0110facecolorgfacealpha5edgealpha1)legalpha(ConminusGreClasminusConPerfminusClasslocationnortheast)legend boxoffaxis tightxlabel(edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN2S)grid on

subplot(236)hold onhistf(RN3S Greedydiff0110facecolorbfacealpha5edgealpha1)histf(RN3S Finaldiff0110facecolorrfacealpha5edgealpha1)histf(RN3S Classicaldiff0110facecolorgfacealpha5edgealpha1)

Appendix A 53

legalpha(ConminusGreClasminusConPerfminusClasslocationnortheast)legend boxoffaxis tightgrid ontitle(RN3S)xlabel(edges) xminusaxis labelylabel(instances) yminusaxis labelset(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN1png minusr300)h(2)=figure(NameHistogram of Max Degree of G AND G HatNumberTitleoff)RN1L x=RN1L MaxDegreeGminusRN1L MaxDegreeG HatRN2L x=RN2L MaxDegreeGminusRN2L MaxDegreeG HatRN3L x=RN3L MaxDegreeGminusRN3L MaxDegreeG HatRN1S x=RN1S MaxDegreeGminusRN1S MaxDegreeG HatRN2S x=RN2S MaxDegreeGminusRN2S MaxDegreeG HatRN3S x=RN3S MaxDegreeGminusRN3S MaxDegreeG Hatsubplot(231)hold onhistf(RN1L MaxDegreeG0150facecolorbfacealpha5edgealpha1)histf(RN1L MaxDegreeG Hat0150facecolorrfacealpha5edgealpha1)histf(RN1L x0150facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightxlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN1L)grid on

subplot(232)hold onhistf(RN2L MaxDegreeG010500facecolorbfacealpha5edgealpha1)histf(RN2L MaxDegreeG Hat010500facecolorrfacealpha5edgealpha1)histf(RN2L x010500facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightxlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN2L)grid on

subplot(233)hold onhistf(RN3L MaxDegreeG010300facecolorbfacealpha5edgealpha1)histf(RN3L MaxDegreeG Hat010300facecolorrfacealpha5edgealpha1)histf(RN3L x010300facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightxlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN3L)

54 Application

grid on

subplot(234)hold onhistf(RN1S MaxDegreeG0150facecolorbfacealpha5edgealpha1)histf(RN1S MaxDegreeG Hat0150facecolorrfacealpha5edgealpha1)histf(RN1S x0150facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightxlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(R1NS)grid on

subplot(235)hold onhistf(RN2S MaxDegreeG010500facecolorbfacealpha5edgealpha1)histf(RN2S MaxDegreeG Hat010500facecolorrfacealpha5edgealpha1)histf(RN2S x010500facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightxlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN2S)grid on

subplot(236)hold onhistf(RN3S MaxDegreeG05300facecolorbfacealpha5edgealpha1)histf(RN3S MaxDegreeG Hat05300facecolorrfacealpha5edgealpha1)histf(RN3S x05300facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightgrid ontitle(RN3S)xlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labelset(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN2png minusr300)

h(3)=figure(NameComputation time over edgesNumberTitleoff)

subplot(231)hold onstem(RN1L EdgesGRN1L Time classicalg)stem(RN1L EdgesGRN1L Time algorithmro)stem(RN1L EdgesGRN1L Time greedybx)grid on

Appendix A 55

title(RN1L)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)

subplot(232)hold onstem(RN2L EdgesGRN2L Time classicalg)stem(RN2L EdgesGRN2L Time algorithmro)stem(RN2L EdgesGRN2L Time greedybx)grid ontitle(RN2L)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)

subplot(233)hold onstem(RN3L EdgesGRN3L Time classicalg)stem(RN3L EdgesGRN3L Time algorithmro)stem(RN3L EdgesGRN3L Time greedybx)grid ontitle(RN3L)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)

subplot(234)hold onstem(RN1S EdgesGRN1S Time classicalg)stem(RN1S EdgesGRN1S Time algorithmro)stem(RN1S EdgesGRN1S Time greedybx)grid ontitle(RN1S)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)

subplot(235)hold onstem(RN2S EdgesGRN2S Time classicalg)stem(RN2S EdgesGRN2S Time algorithmro)stem(RN2S EdgesGRN2S Time greedybx)grid ontitle(RN2S)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)

subplot(236)hold onstem(RN3S EdgesGRN3S Time classicalg)stem(RN3S EdgesGRN3S Time algorithmro)stem(RN3S EdgesGRN3S Time greedybx)

56 Application

grid ontitle(RN3S)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)set(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN3png minusr300)

h(4)=figure(NameSorted matching sizeNumberTitleoff)RN1L Sorted matching temp(1)=RN1L Classical matchingRN1L Sorted matching temp(2)=RN1L Final matchingRN1L Sorted matching temp(3)=RN1L Greedy matchingRN1L Sorted matching temp(4)=RN1L Initial matchingRN1L Sorted matching=sortrows(RN1L Sorted matching temp)

RN2L Sorted matching temp(1)=RN2L Classical matchingRN2L Sorted matching temp(2)=RN2L Final matchingRN2L Sorted matching temp(3)=RN2L Greedy matchingRN2L Sorted matching temp(4)=RN2L Initial matchingRN2L Sorted matching=sortrows(RN2L Sorted matching temp)

RN3L Sorted matching temp(1)=RN3L Classical matchingRN3L Sorted matching temp(2)=RN3L Final matchingRN3L Sorted matching temp(3)=RN3L Greedy matchingRN3L Sorted matching temp(4)=RN3L Initial matchingRN3L Sorted matching=sortrows(RN3L Sorted matching temp)

RN1S Sorted matching temp(1)=RN1S Classical matchingRN1S Sorted matching temp(2)=RN1S Final matchingRN1S Sorted matching temp(3)=RN1S Greedy matchingRN1S Sorted matching temp(4)=RN1S Initial matchingRN1S Sorted matching=sortrows(RN1S Sorted matching temp)

RN2S Sorted matching temp(1)=RN2S Classical matchingRN2S Sorted matching temp(2)=RN2S Final matchingRN2S Sorted matching temp(3)=RN2S Greedy matchingRN2S Sorted matching temp(4)=RN2S Initial matchingRN2S Sorted matching=sortrows(RN2S Sorted matching temp)

RN3S Sorted matching temp(1)=RN3S Classical matchingRN3S Sorted matching temp(2)=RN3S Final matchingRN3S Sorted matching temp(3)=RN3S Greedy matchingRN3S Sorted matching temp(4)=RN3S Initial matchingRN3S Sorted matching=sortrows(RN3S Sorted matching temp)

subplot(231)hold onplot(RN1L Sorted matching(1)b)plot(RN1L Sorted matching(2)g)plot(RN1L Sorted matching(3)r)plot(RN1L Sorted matching(4)m)

Appendix A 57

grid ontitle(RN1L)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)

subplot(232)hold onplot(RN2L Sorted matching(1)b)plot(RN2L Sorted matching(2)g)plot(RN2L Sorted matching(3)r)plot(RN2L Sorted matching(4)m)grid ontitle(RN2L)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)

subplot(233)hold onplot(RN3L Sorted matching(1)b)plot(RN3L Sorted matching(2)g)plot(RN3L Sorted matching(3)r)plot(RN3L Sorted matching(4)m)grid ontitle(RN3L)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)

subplot(234)hold onplot(RN1S Sorted matching(1)b)plot(RN1S Sorted matching(2)g)plot(RN1S Sorted matching(3)r)plot(RN1S Sorted matching(4)m)grid ontitle(RN1S)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)

subplot(235)hold onplot(RN2S Sorted matching(1)b)plot(RN2S Sorted matching(2)g)plot(RN2S Sorted matching(3)r)plot(RN2S Sorted matching(4)m)grid ontitle(RN2S)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)

58 Application

subplot(236)hold onplot(RN3S Sorted matching(1)b)plot(RN3S Sorted matching(2)g)plot(RN3S Sorted matching(3)r)plot(RN3S Sorted matching(4)m)grid ontitle(RN3S)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)set(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN4png minusr300)h(5)=figure(NameSorted RatiosNumberTitleoff)RN1L ratio1=RN1L NodesG hatRN1L NodesGRN2L ratio1=RN2L NodesG hatRN2L NodesGRN3L ratio1=RN3L NodesG hatRN3L NodesGRN1S ratio1=RN1S NodesG hatRN1S NodesGRN2S ratio1=RN2S NodesG hatRN2S NodesGRN3S ratio1=RN3S NodesG hatRN3S NodesG

RN1L ratio2=RN1L EdgesG HatRN1L EdgesGRN2L ratio2=RN2L EdgesG HatRN2L EdgesGRN3L ratio2=RN3L EdgesG HatRN3L EdgesGRN1S ratio2=RN1S EdgesG HatRN1S EdgesGRN2S ratio2=RN2S EdgesG HatRN2S EdgesGRN3S ratio2=RN3S EdgesG HatRN3S EdgesG

RN1L ratio3=RN1L MaxDegreeG HatRN1L MaxDegreeGRN2L ratio3=RN2L MaxDegreeG HatRN2L MaxDegreeGRN3L ratio3=RN3L MaxDegreeG HatRN3L MaxDegreeGRN1S ratio3=RN1S MaxDegreeG HatRN1S MaxDegreeGRN2S ratio3=RN2S MaxDegreeG HatRN2S MaxDegreeGRN3S ratio3=RN3S MaxDegreeG HatRN3S MaxDegreeG

RN1L ratio(1)=RN1L ratio1RN1L ratio(2)=RN1L ratio2RN1L ratio(3)=RN1L ratio3

RN2L ratio(1)=RN2L ratio1RN2L ratio(2)=RN2L ratio2RN2L ratio(3)=RN2L ratio3

RN3L ratio(1)=RN3L ratio1RN3L ratio(2)=RN3L ratio2RN3L ratio(3)=RN3L ratio3

RN1S ratio(1)=RN1S ratio1RN1S ratio(2)=RN1S ratio2RN1S ratio(3)=RN1S ratio3

RN2S ratio(1)=RN2S ratio1

Appendix A 59

RN2S ratio(2)=RN2S ratio2RN2S ratio(3)=RN2S ratio3

RN3S ratio(1)=RN3S ratio1RN3S ratio(2)=RN3S ratio2RN3S ratio(3)=RN3S ratio3

RN1L ratio sorted=sortrows(RN1L ratio)RN2L ratio sorted=sortrows(RN2L ratio)RN3L ratio sorted=sortrows(RN3L ratio)RN1S ratio sorted=sortrows(RN1S ratio)RN2S ratio sorted=sortrows(RN2S ratio)RN3S ratio sorted=sortrows(RN3S ratio)

subplot(231)hold onplot(RN1L ratio sorted(1)b)plot(RN1L ratio sorted(2)g)plot(RN1L ratio sorted(3)r)grid ontitle(RN1L)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)

subplot(232)hold onplot(RN2L ratio sorted(1)b)plot(RN2L ratio sorted(2)g)plot(RN2L ratio sorted(3)r)grid ontitle(RN2L)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)

subplot(233)hold onplot(RN3L ratio sorted(1)b)plot(RN3L ratio sorted(2)g)plot(RN3L ratio sorted(3)r)grid ontitle(RN3L)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)

subplot(234)hold onplot(RN1S ratio sorted(1)b)plot(RN1S ratio sorted(2)g)plot(RN1S ratio sorted(3)r)grid on

60 Application

title(RN1S)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)

subplot(235)hold onplot(RN2S ratio sorted(1)b)plot(RN2S ratio sorted(2)g)plot(RN2S ratio sorted(3)r)grid ontitle(RN2S)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)

subplot(236)hold onplot(RN3S ratio sorted(1)b)plot(RN3S ratio sorted(2)g)plot(RN3S ratio sorted(3)r)grid ontitle(RN3S)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)set(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN5png minusr300)

h(6)=figure(NameSorted edges over nodesNumberTitleoff)

RN1L DegreeG1=(RN1L EdgesG)(RN1L NodesG)RN1L DegreeG Hat1=(RN1L EdgesG Hat)(RN1L NodesG hat)

RN1L Degree temp1(1)=RN1L DegreeG1RN1L Degree temp1(2)=RN1L DegreeG Hat1RN1L Degree sorted1=sortrows(RN1L Degree temp1)subplot(231)hold on

plot(RN1L Degree sorted1(1)b)plot(RN1L Degree sorted1(2)g)grid ontitle(RN1L)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)

RN2L DegreeG1=(RN2L EdgesG)(RN2L NodesG)RN2L DegreeG Hat1=(RN2L EdgesG Hat)(RN2L NodesG hat)

RN2L Degree temp1(1)=RN2L DegreeG1

Appendix A 61

RN2L Degree temp1(2)=RN2L DegreeG Hat1RN2L Degree sorted1=sortrows(RN2L Degree temp1)

subplot(232)hold onplot(RN2L Degree sorted1(1)b)plot(RN2L Degree sorted1(2)g)grid ontitle(RN2L)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)

RN3L DegreeG1=(RN3L EdgesG)(RN3L NodesG)RN3L DegreeG Hat1=(RN3L EdgesG Hat)(RN3L NodesG hat)

RN3L Degree temp1(1)=RN3L DegreeG1RN3L Degree temp1(2)=RN3L DegreeG Hat1RN3L Degree sorted1=sortrows(RN3L Degree temp1)

subplot(233)hold onplot(RN3L Degree sorted1(1)b)plot(RN3L Degree sorted1(2)g)grid ontitle(RN3L)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)

RN1S DegreeG1=(RN1S EdgesG)(RN1S NodesG)RN1S DegreeG Hat1=(RN1S EdgesG Hat)(RN1S NodesG hat)

RN1S Degree temp1(1)=RN1S DegreeG1RN1S Degree temp1(2)=RN1S DegreeG Hat1RN1S Degree sorted1=sortrows(RN1S Degree temp1)

subplot(234)hold onplot(RN1S Degree sorted1(1)b)plot(RN1S Degree sorted1(2)g)grid ontitle(RN1S)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)

RN2S DegreeG1=(RN2S EdgesG)(RN2S NodesG)RN2S DegreeG Hat1=(RN2S EdgesG Hat)(RN2S NodesG hat)

RN2S Degree temp1(1)=RN2S DegreeG1

62 Application

RN2S Degree temp1(2)=RN2S DegreeG Hat1RN2S Degree sorted1=sortrows(RN2S Degree temp1)

subplot(235)hold onplot(RN2S Degree sorted1(1)b)plot(RN2S Degree sorted1(2)g)grid ontitle(RN2S)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)

RN3S DegreeG1=(RN3S EdgesG)(RN3S NodesG)RN3S DegreeG Hat1=(RN3S EdgesG Hat)(RN3S NodesG hat)

RN3S Degree temp1(1)=RN3S DegreeG1RN3S Degree temp1(2)=RN3S DegreeG Hat1RN3S Degree sorted1=sortrows(RN3S Degree temp1)

subplot(236)hold onplot(RN3S Degree sorted1(1)b)plot(RN3S Degree sorted1(2)g)grid ontitle(RN3S)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)set(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN6png minusr300)h(7)=figure(NameSorted mATCHED DEGREENumberTitleoff)RN1L ratioMax(1)=RN1L MaxDegreeGRN1L ratioMax(2)=RN1L MaxDegreeG Hat

RN1L ratio sortedMax=sortrows(RN1L ratioMax)subplot(231)hold onplot(RN1L ratio sortedMax(1)b)plot(RN1L ratio sortedMax(2)g)grid ontitle(RN1L)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)

RN2L ratioMax(1)=RN2L MaxDegreeGRN2L ratioMax(2)=RN2L MaxDegreeG Hat

RN2L ratio sortedMax=sortrows(RN2L ratioMax)subplot(232)

Appendix A 63

hold onplot(RN2L ratio sortedMax(1)b)plot(RN2L ratio sortedMax(2)g)grid ontitle(RN2L)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)

RN3L ratioMax(1)=RN3L MaxDegreeGRN3L ratioMax(2)=RN3L MaxDegreeG Hat

RN3L ratio sortedMax=sortrows(RN3L ratioMax)subplot(233)hold onplot(RN3L ratio sortedMax(1)b)plot(RN3L ratio sortedMax(2)g)grid ontitle(RN3L)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)

RN1S ratioMax(1)=RN1S MaxDegreeGRN1S ratioMax(2)=RN1S MaxDegreeG Hat

RN1S ratio sortedMax=sortrows(RN1S ratioMax)subplot(234)hold onplot(RN1S ratio sortedMax(1)b)plot(RN1S ratio sortedMax(2)g)grid ontitle(RN1S)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)

RN2S ratioMax(1)=RN2S MaxDegreeGRN2S ratioMax(2)=RN2S MaxDegreeG Hat

RN2S ratio sortedMax=sortrows(RN2S ratioMax)

subplot(235)hold onplot(RN2S ratio sortedMax(1)b)plot(RN2S ratio sortedMax(2)g)grid ontitle(RN2S)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)

RN3S ratioMax(1)=RN3S MaxDegreeGRN3S ratioMax(2)=RN3S MaxDegreeG Hat

64 Application

RN3S ratio sortedMax=sortrows(RN3S ratioMax)subplot(236)hold onplot(RN3S ratio sortedMax(1)b)plot(RN3S ratio sortedMax(2)g)grid ontitle(RN1L)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)set(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN7png minusr300)

tilefigs()(h)

Bibliography

[1] C Berge ldquoTWO THEOREMS IN GRAPH THEORYrdquo Proceedings of the NationalAcademy of Sciences of the United States of America vol 43 no 9 pp 842ndash844Sep 1957

[2] L Bui S Sanghavi and R Srikant ldquoDistributed link scheduling with constantoverheadrdquo IEEEACM Trans Netw vol 17 no 5 pp 1467ndash1480 2009

[3] R Duan and S Pettie ldquoLinear-time approximation for maximum weight matchingrdquoJ ACM vol 61 no 1 2014

[4] J Edmonds ldquoPaths trees and flowersrdquo Canadian Journal of Mathematics vol 17pp 449ndash467 1965

[5] J E Hopcroft and R M Karp ldquoAn n52 algorithm for maximum matchings inbipartite graphsrdquo SIAM J Comput vol 2 no 4 pp 225ndash231 1973

[6] S Micali and V V Vazirani ldquoAn O(radic|V ||E|) algorithm for finding maximum

matching in general graphsrdquo in 21st Symp on Foundations of Comp Sc (FOCS)IEEE 1980 pp 17ndash27

[7] N Nisse A Salch and V Weber ldquoRecovery of disrupted airline operationsrdquo 2015httphalinriafrSomething

[8] X Wu and R Srikant ldquoRegulated maximal matching A distributed schedulingalgorithm for multi-hop wireless networks with nodeexclusive spectrum sharingrdquo inIEEE Conf on Decision and Control 2005

65

  • Contents
  • Introduction
  • Algorithms
    • Maximum matching
    • k-maximum matching
      • k-matching for Airport Slot assignment
      • The case where k=3
      • The case of Paths
      • The case of the Spider
          • Application
            • Description
            • Reyni Erdos
            • Barabaacutesi Albert
            • Amadeus Graphs
            • Bipartite
            • Bipartite with degree seq
            • Appendix A
              • BipartiteGraphGeneratorpy
              • RandomGraphGeneratorpy
              • kequals3MaximumMatchingpy
              • Plotmat
                  • Bibliography
Page 13: Theodoros Alexandros KARAGKIOULES -  · Introduction This work is the result of a 6 months internship, under the supervision of research O cer Nicolas NISSE. The original scope of

14 Application

Sorted |E||V |

Sorted |E||V | - Comments

bull Although as graph density the ratio 2|E||V |(|V |minus1)

is considered in this set of figures

we evaluate the correlation of the ratio |E||V | of G and G since the density of G

could acquire values higher than that of G

bull The figures are calculated in ascending order for the ratio of G

bull For the case of large initial matching the two ratios for G and G remain almostconstant ( to the extent of the probability of each graph) since removing forcededges( and their endpoints) alters the |E| and |V | proportionately

22 Reyni Erdos 15

bull For the case of small initial matching we observe some deviation in the valuesof the ration for G and that is explained with the removal of only useless edgeswhich only alters the |E| and keeps |V | in the original values

Sorted ∆

Sorted ∆-Comments

bull In this set of figures the ascending order of the ∆ of G is associated with the ∆of G

bull There is no significant jump of the ∆ for each graph category which tells that thatwe are comparing a uniform distribution of random grapghs for each probabilitycase

16 Application

bull For larger initial matching we observe the difference in the ∆s of G and G giventhe removed forced edges( and their endpoints) At some cases the ∆ of G dropsto 0 since the vast majority of edges have been declared forced and removed alongwith their endpoints

bull For smaller initial matching the ∆s of G and G follow mostly the same trend onlya few number of different instances

23 Barabasi Albert

Graph characteristics Barabasi Albert

bull BAxy are randomly generated graphs with a fixed number of 1000 nodes

bull There are 6 categories based on ini matching and of attached edges m

bull x = L S L When the initial matching is large and S when it is small

bull y = 1 2 3 1 when m = [1 10] 2 when m = [20 50] and 3 m = [50 100]

Computation time over |E|

23 Barabasi Albert 17

Computation time over |E| - Comments

bull When the initial matching is sufficiently large then the forced edges are taken out(a process which takes a fragment of the computation time) and then the classicalmatching algorithm (Edmonds) is applied on a smaller graph(G) This reducessignificantly the computation time

bull When the initial matching is small then the computation time of the constraintalgorithm might be larger than that of Edmonds The reason is that the constraintalgorithm need some time to compute the useless and forced edges and thenEdmonds algorithm is applied on G G Thus the overall processing time issometimes larger

Sorted matching size

18 Application

Sorted matching size-Comments

bull In this graph the matching size of the classical algorithm is depicted in ascendingorder along with the corresponding constraint algorithm and greedy result

bull Here in the case where m is small for both cases of initial matching (small large)the result may vary greatly starting from a value of half the perfect matching withsmall differences between the results of the various algorithm implementations

bull For the other cases of m the results converge

bull This is explained as for small values of m the graph is disconnected

bull In the matching size difference set of figures a very noticing difference value ap-pears For the cases of small m( the number of existing nodes that a new node isconnected to at the creation of the graph) we can see that the difference in the

23 Barabasi Albert 19

matching size compared to that of the perfect matching could be up to 40 ofthat of the matching size So there are occasions where the matching size is 200edges when the perfect matching would have been 500

bull the difference between the Constraint matching and the classical matching andthe difference of the constraint matching and that of the greedy matching do notshow significant values

Sorted Ratios

Sorted Ratio s -Comments

bull This set of figures depicts the ratios VV

EE

∆∆

in ascending order of VV

20 Application

bull It is evident that when the initial matching is large the amount of forced edges(and their endpoints) removed is high thus the ratio of Nodes and edges is verylow For higher probabilities almost all edges are removed as useless

bull For a smaller initial matching almost no forced edges (and their endpoints) areremoved which we conclude be the node ration being close to 1 There is somesmall amount of useless edges removed though since the ratio of edges is less butclose to 1

bull The ratio of ∆ for large initial matching follows the trend of the node ratio yetfor smaller initial matching it deviates significantly

Sorted |E||V |

23 Barabasi Albert 21

Sorted |E||V | - Comments

bull Although as graph density the ratio 2|E||V |(|V |minus1)

is considered in this set of figures

we evaluate the correlation of the ratio |E||V | of G and G since the density of G

could acquire values higher than that of G

bull The figures are calculated in ascending order for the ratio of G

bull For the case of large initial matching the two ratios for G and G remain almostconstant ( to the extent of the edge attraction m of each graph) since removingforced edges( and their endpoints) alters the |E| and |V | proportionately

bull For the case of small initial matching we observe some deviation in the valuesof the ration for G and that is explained with the removal of only useless edgeswhich only alters the |E| and keeps |V | in the original values

Sorted ∆

22 Application

Sorted ∆-Comments

bull In this set of figures the ascending order of the ∆ of G is associated with the ∆of G

bull There is a significant jump of the ∆ for each graph category which tells that thatwe are not comparing a uniform distribution of random graphs and based on theedge attraction m the graphs can vary in form

bull For larger initial matching we observe the difference in the ∆s of G and G giventhe removed forced edges( and their endpoints) At some cases the ∆ of G dropsto 0 since the vast majority of edges have been declared forced and removed alongwith their endpoints What is interesting is that the ∆ of G oscilates within stablelimits

24 Amadeus Graphs 23

bull For smaller initial matching the ∆s of G and G follow mostly the same trend onlya few number of different instances

24 Amadeus Graphs

Graph characteristics Amadeus graphs

bull These are the bipartite graphs provided by Amadeus

Computation time over |E|

Computation time over |E| - Comments

24 Application

bull For every instance the computation time of the classical algorithm is always smallerto that of the constraint matching

bull This allows as to speculate that we always compute a smaller G which also impliesthat we always find a set of forced edges and useless

Sorted matching size

Sorted matching size - Comments

bull Size of matching has an upward trend since the magnitude of the graphs is notthe same for the 160 instances

bull No significant deviation is noticed as per the first graph

24 Amadeus Graphs 25

bull Except from deviation from the perfect matching (number of flights) where some-times it could get up to 40

bull For the Amadeus Bipartite graphs we can see that the difference of the Classicaland the constraint implementation is not more than 1 edge in the matching

bull There appears to be a difference of up to 24 edges between the Classical matchingand the Perfect matching which is computed as the number of flights

bull The greedy algorithm performs well with only a few instances deviating slightlyform the Constraint algorithm result

Sorted Ratios

Sorted Ratios - Comments

26 Application

bull

Sorted |E||V |

Sorted |E||V | - Comments

bull Density of the graphs shows that on average we have 25-3 available time slot perflight

bull The line for the same value for G shows that there is a large deviation for everyinstance which allows for the hypothesis that the amount of useless+forced edgesof G has no obvious correlation to that of G

25 Bipartite 27

Sorted ∆

Sorted ∆-Comments

bull As per the previous related graphs for ∆ there is in significant drop in the ∆ of Gand G

25 Bipartite

Graph characteristics Bipartite random Graphs

bull BIPxy are randomly generated graphs with a fixed number of 1000(n=500 andm=500) nodes

bull There are 6 categories based on ini matching and probability p

28 Application

bull Probability p has been chosen as such in order to simulate the |E||V | 25 of theAmadeus bipartite graphs

bull So in order to have about 2-4 edges for every node we choose accordingly theprobability p to choose one of the n lowastm possible edges

bull x = L S L When the initial matching is large and S when it is small

bull y = 1 2 3 1 when p = 18250

2 when p = 25250

and 3 when p = 34250

Computation time over

Computation time overedges-Comments

bull

25 Bipartite 29

Sorted matching size

Sorted matching size-Comments

bull In these set of graphs one can instantly notice that only a few instances with highprobability can reach a matching size equal to the perfect matching

bull For the case of the initial matching we witness that there is a gap between the lineof the classical matching and those of the constraint and greedy results suggestingsmaller matching sizes of 10-40 edges

bull For the case of the small initial matching the result of the constraint matchingis now close to the result of the classical matching yet the greedy algorithm stillshows a relevantly big difference

30 Application

bull In this set of bipartite graphs we can witness that the result of the Constraintmatching shows a difference with the classical matching when the initial matchingis large The difference is smaller as the probability gets larger

bull For the case of the small initial matching the above phenomenom does not occuryet the greedy results deviates from that of the constraint matching

bull As per the pefrect matching compared to the classical matching a difference of5-10 edges is evident at almost all cases

Sorted Ratios

Sorted Ratios-Comments

bull Great max degree deviation

25 Bipartite 31

bull Regardless of the probability the ration of nodes and edges seems to have similarbehaviour when compared to the respective graphs of the same matching scale

bull Same gap between nodes ration and edges ration for all cases

Sorted |E||V |

Sorted |E||V | - Comments

bull In these set of figures we witness that the |E||V | acquires values relevant to those ofthe amadeus graphs The random graphs were constructed to depict this similarity

bull For smaller initial matching the ratios for G and G show the same upward trendand also they acquire closer values It represents the decrease of the averagenumber of forced edges in comparison to the larger matching cases

32 Application

Sorted ∆

Sorted ∆-Comments

bull ∆ acquires the same min and max values for each probability case (expected)

bull Gap in the case of large initial matching

26 Bipartite with degree seq

Graph characteristics

bull DEQBIPxy are randomly generated graphs based on three different types of degreedistribution of the Amadeus graphs

26 Bipartite with degree seq 33

bull There are 6 categories based on ini matching and degree distribution

bull x = L S L When the initial matching is large and S when it is small

bull y = 1 2 3 1 when degree distribution is based on file 2 when degree distributionis based on file and 3 when degree distribution is based on file

Computation time over

34 Application

Computation time overedges-Comments

bull Greedy algorithm takes minimum amount of time

bull The smaller the initial matching the more smaller the difference in comoutationtime of Constraint and classical algorithm

bull Due to preprocessing and the fact that G and G are the almost identical thetotal time needed to apply the constraint algorithm is in some cases bigger

Sorted matching size

26 Bipartite with degree seq 35

Sorted matching size-Comments

bull Classical matching is equal to perfect matching in every case

bull Constraint and greedy have identical behaviour

bull The larger the spectrum of the degree sequence the more efficient the matching

Sorted Ratios

36 Application

Sorted Ratios-Comments

bull With large initial matching most of the edges are considenred uselles or forced andare removed thus the ratio is close(if not equal to) zero

bull For small matching and large degree sequence sectrum hte max degree remainsthe same Only a few forced edges (and their nodes) are removed apparently nonodes with max degree

Sorted |E||V |

26 Bipartite with degree seq 37

Sorted |E||V | - Comments

bull In these set of figures we witness that the |E||V | acquires values relevant to those ofthe amadeus graphs The random graphs were constructed to depict this similarity

bull For smaller initial matching the ratios for G and G show the same upward trendand also they acquire closer values It repsresent the decrease of the averagenumber of forced edges in comparison to the larger matching cases

Sorted ∆

38 Application

Sorted ∆-Comments

bull Big difference in max degree in large initial matching

bull Almost identical behaviour in the case of small initial matching

Appendix A 39

Appendix A

BipartiteGraphGeneratorpy

from future import divisionimport networkx as nx

from networkxalgorithms import approximationimport collectionsimport randomimport mathfrom networkxalgorithms import bipartiteif name == main

for i in range(1481)waqs 481index=1n=randomrandint(100 1000)

n1=95 was 500me1=118

n2=251 was 500me2=903

n3=165 was 500me3=412

m=0m1=0p=randomrandom()p1=18250p2=25250p3=34250print ip=05t1=randomrandint(0 1)print im2=randomrandint(n2minus1 n2+1)G = nxGraph()ma = nxGraph()

aseq1=[1 2 3 4 5 3]

bseq1=[4 3 3 1 2 2 1]

aseq2=[16 14 14 14 12 11]bseq2=[0 0 0 0 0 0]

aseq3=[8 7 8 8 8 8]bseq3=[0 0 0 0 0 0]

40 Application

print Gnumber of edges()if ilt=160

G=bipartiteconfiguration model(aseq1 bseq1 create using=None seed=None)A=nxadjacency matrix(G)for ii in range(0n1+me1)

maadd node(ii)A=[Rtodense()tolist()[0] for R in A]

printnummanumber of nodes()rl=randomsample(range(0n1+me1) n1+me1)m=0done vertices = set()for p in rlprintin fordone verticesadd(p)

neighbors = []list()for iii in range(0n1+me1)

if A[p][iii]==1neighborsappend(iii)

randomshuffle(neighbors)continue loop = Truedegree = len(neighbors)

print degreej = 0p4=randomrandom()while continue loop and (jltdegree)print in loop

next = neighbors[j]if next not in done vertices and p not in done vertices

done verticesadd(p)done verticesadd(next)if p4gt=07print added edge

maadd edge(pnext)m=m+1

continue loop = Falsej += 1

print matching listOfedgeprint maedge

MA=nxadjacency matrix(ma)print MA

MA=[Rtodense()tolist()[0] for R in MA]print MA

B=[ join(map(strR)) for R in A]MB=[ join(map(strR)) for R in MA]

C=njoin(B)+nMC=njoin(MB)+n

print nprint mprint m1

filea=str(i)+txtwith open(fileaw) as f

Appendix A 41

fwrite(str(n1+me1))fwrite(n)fwrite(str(n1+me1))fwrite(n)fwrite(str(m))fwrite(n)fwrite(n)fwrite(C)fwrite(n)fwrite(MC)

elif igt160 and ilt321G=bipartiteconfiguration model(aseq2 bseq2 create using=None seed=None)A=nxadjacency matrix(G)for ii in range(0n2+me2)

maadd node(ii)A=[Rtodense()tolist()[0] for R in A]

printnummanumber of nodes()rl=randomsample(range(0n2+me2) n2+me2)m=0done vertices = set()for p in rlprintin fordone verticesadd(p)

neighbors = []list()for iii in range(0n2+me2)

if A[p][iii]==1neighborsappend(iii)

randomshuffle(neighbors)continue loop = Truedegree = len(neighbors)

print degreej = 0p4=randomrandom()while continue loop and (jltdegree)

print in loopnext = neighbors[j]if next not in done vertices and p not in done vertices

done verticesadd(p)done verticesadd(next)if p4gt=07

print added edgemaadd edge(pnext)m=m+1

continue loop = Falsej += 1

print matching listOfedgeprint maedge

MA=nxadjacency matrix(ma)print MA

MA=[Rtodense()tolist()[0] for R in MA]print MA

B=[ join(map(strR)) for R in A]MB=[ join(map(strR)) for R in MA]

42 Application

C=njoin(B)+nMC=njoin(MB)+n

print nprint mprint m1

filea=str(i)+txtwith open(fileaw) as f

fwrite(str(n2+me2))fwrite(n)fwrite(str(n2+me2))fwrite(n)fwrite(str(m))fwrite(n)fwrite(n)fwrite(C)fwrite(n)fwrite(MC)

elseG=bipartiteconfiguration model(aseq3 bseq3 create using=None seed=None)A=nxadjacency matrix(G)for ii in range(0n3+me3)

maadd node(ii)A=[Rtodense()tolist()[0] for R in A]

printnummanumber of nodes()rl=randomsample(range(0n3+me3) n3+me3)m=0done vertices = set()for p in rlprintin fordone verticesadd(p)

neighbors = []list()for iii in range(0n3+me3)

if A[p][iii]==1neighborsappend(iii)

randomshuffle(neighbors)continue loop = Truedegree = len(neighbors)

print degreej = 0p4=randomrandom()while continue loop and (jltdegree)

print in loopnext = neighbors[j]if next not in done vertices and p not in done vertices

done verticesadd(p)done verticesadd(next)if p4gt=07print added edge

maadd edge(pnext)m=m+1

continue loop = Falsej += 1

Appendix A 43

print matching listOfedgeprint maedge

MA=nxadjacency matrix(ma)print MA

MA=[Rtodense()tolist()[0] for R in MA]print MA

B=[ join(map(strR)) for R in A]MB=[ join(map(strR)) for R in MA]

C=njoin(B)+nMC=njoin(MB)+n

print nprint mprint m1

filea=str(i)+txtwith open(fileaw) as f

fwrite(str(n3+me3))fwrite(n)fwrite(str(n3+me3))fwrite(n)fwrite(str(m))fwrite(n)fwrite(n)fwrite(C)fwrite(n)fwrite(MC)

print nRandom graphs with random matching have been generated

44 Application

RandomGraphGeneratorpy

from future import divisionimport networkx as nxfrom networkxalgorithms import approximationimport collectionsimport randomimport mathif name == main

for i in range(1481)index=1n=randomrandint(100 1000)

n=1000m=0m1=0p=randomrandom()p1=mathlog(n2)np2=13p3=mathlog(n2)n+01p=05t1=randomrandint(0 1)print im2=randomrandint(n2minus1 n2+1)G = nxGraph()ma = nxGraph()print nme1=randomrandint(1 10)me2=randomrandint(2050)me3=randomrandint(50100)if ilt241

if ilt=80G=nxfast gnp random graph(n p1 seed=None directed=False)

elif igt80 and ilt161G=nxfast gnp random graph(n p2 seed=None directed=False)

elseG=nxfast gnp random graph(n p3 seed=None directed=False)

elseif ilt=320

G=nxbarabasi albert graph(n me1 seed=None)elif igt320 and ilt401

G=nxbarabasi albert graph(n me2 seed=None)else

G=nxbarabasi albert graph(n me3 seed=None)A=nxadjacency matrix(G)for ii in range(0n)

maadd node(ii)A=[Rtodense()tolist()[0] for R in A]

rl=randomsample(range(0n) n)m=0

Appendix A 45

done vertices = set()for p in rl

done verticesadd(p)neighbors = []list()for iii in range(0n)

if A[p][iii]==1neighborsappend(iii)

randomshuffle(neighbors)continue loop = Truedegree = len(neighbors)j = 0p2=randomrandom()while continue loop and (jltdegree)

next = neighbors[j]if next not in done vertices and p not in done vertices

done verticesadd(p)done verticesadd(next)if p2gt=00 Larger probability for smaller initial matching

maadd edge(pnext)m=m+1

continue loop = Falsej += 1

print matching listOfedgeprint maedgeMA=nxadjacency matrix(ma)MA=[Rtodense()tolist()[0] for R in MA]print MAB=[ join(map(strR)) for R in A]MB=[ join(map(strR)) for R in MA]

C=njoin(B)+nMC=njoin(MB)+nprint MCprint nprint mprint m1filea=str(i)+txtwith open(fileaw) as f

fwrite(str(n))fwrite(n)fwrite(str(n))fwrite(n)fwrite(str(m))fwrite(n)fwrite(n)fwrite(C)fwrite(n)fwrite(MC)

print nRandom graphs with random matching have been generated

46 Application

kequals3MaximumMatchingpy

from future import divisionimport networkx as nxfrom networkxalgorithms import bipartiteimport matplotlibpyplot as pltimport collectionsimport timeitimport xlwtimport xlrdimport mathimport sys

Case for General Graphsdef forced edges(Gadj dict2matching dict1num nodesforced)

flagg=0for n in range(0num nodes)

for k in adj dict2[n]if ([k]==matching dict1[n])

count=0for l in range(0num nodes)

count=count+adj dict2[l]count(k)if (len(adj dict2[n])==1) or (count==1)

forcedadd edge(nk)Gremove edge(nk)Gremove node(n)Gremove node(k)printforced edgenktemp=kflagg=1for m in range (len(adj dict2[n])minus1minus1minus1)

adj dict2[adj dict2[n][m]]remove(n)adj dict2[n]remove(adj dict2[n][m])

if adj dict2[temp]for l in range(len(adj dict2[temp])minus1minus1minus1)

if (adj dict2[temp][l]=n)adj dict2[adj dict2[temp][l]]remove(temp)adj dict2[temp]remove(adj dict2[temp][l])

break

def useless edges(num nodesadj dict1matching dict1uselessadj dict2G)for n in range(0num nodes)

for k in adj dict1[n]if ([k]=matching dict1[n]) and matching dict1[n] and matching dict1[k]

uselessadd edge(nk)Gremove edge(n k)

Appendix A 47

tempa=kadj dict2[n]remove(k)adj dict2[tempa]remove(n)adj dict1[tempa]remove(n)

return G

def Greedy(num nodesadj dict3matching dict2)

for n in range(0num nodes)if matching dict2[n]

flag2=minus1flag3=minus1for v in adj dict3[n]

if not matching dict2[v]flag2=vbreak

for p in adj dict3[matching dict2[n][0]]if not matching dict2[p]

flag3=pbreak

if (flag2=minus1) and (flag3=minus1) and (flag2=flag3)tempr=matching dict2[n][0]matching dict2[n]=[flag2]matching dict2[flag2]=[n]matching dict2[tempr]=[flag3]matching dict2[flag3]=[tempr]

elsefor k in adj dict3[n]

if not matching dict2[k]matching dict2[n]=[k]matching dict2[k]=[n]break

yo1=0for i in range(0num nodes)

if matching dict2[i] and [i]==matching dict2[matching dict2[i][0]]yo1=yo1+1

greedy size=yo12return greedy size

def General()

INPUTSwb = xlwtWorkbook()ws = wbadd sheet(Results Random)book=xlrdopen workbook(filenames randomxls)

48 Application

style0 = xlwteasyxf(fontbold on)style1 = xlwteasyxf(num format str=0000)INPUTSwswrite(0 0File style0)wswrite(0 1 Nodesstyle0)wswrite(0 2 Initial matchingstyle0)wswrite(0 3 NodesGstyle0)wswrite(0 4 EdgesGstyle0)wswrite(0 5 MaxDegreeGstyle0)wswrite(0 6 NodesG hatstyle0)wswrite(0 7 EdgesG Hatstyle0)wswrite(0 8 Useless edgesstyle0)wswrite(0 9 Forced edgesstyle0)wswrite(0 10 MaxDegreeG Hatstyle0)wswrite(0 11 Classical matchingstyle0)wswrite(0 12 Final matchingstyle0)wswrite(0 13 Greedy matchingstyle0)wswrite(0 14 Time classicalstyle0)wswrite(0 15 Time algorithmstyle0)wswrite(0 16 Time greedystyle0)wswrite(0 17 Perfect matching ratiostyle0)wswrite(0 18 Nodes ratiostyle0)wswrite(0 19 Edges ratiostyle0)wswrite(0 20 Matching ratiostyle0)

print nWelcomeThis is an implementation for general random graphs It uses Edmonds algorithm to compute maximum matching on G Hatn

for index in range (1481)was 481

if (index==482)f=open(Algotel generaltxtr)readlines()

elsefilea=str(booksheet by index(0)cell(index0))s=fileareplace(textu)replace()f=open(sr)readlines()Truewswrite(index 0 s)

print index

num nodes=int([xstrip()split() for x in f][0][0])

num matching=int([xstrip()split() for x in f][2][0])

adj temp = [xstrip()split() for x in f][44+num nodes]adj=[map(intR) for R in adj temp]

matching temp=[xstrip()split() for x in f][4+num nodes+14+2num nodes+1]matching1=[map(intR) for R in matching temp]

adj dict1=i[ii for iix in enumerate(L) if x] for iL in enumerate(adj)adj dict2=i[ii for iix in enumerate(L) if x] for iL in enumerate(adj)

Appendix A 49

adj dict3=i[ii for iix in enumerate(L) if x] for iL in enumerate(adj)

matching dict1=i[ii for iix in enumerate(L) if x] for iL in enumerate(matching1)matching dict2=i[ii for iix in enumerate(L) if x] for iL in enumerate(matching1)print adj dict2print matching dict2wswrite(index 1 num nodes)wswrite(index 2 num matching)

G = nxGraph()

useless= nxGraph()forced = nxGraph()

Fill Graphfor n in range(0num nodes)

for k in adj dict1[n]Gadd edge(nk)

Gt=Gnumber of edges()wswrite(index 3 Gnumber of nodes())wswrite(index 4 Gnumber of edges())wswrite(index 5 max(Gdegree()values()))

Compute Edmonds classical matching on G for comparison

startB = timeitdefault timer()Classical Matching=nxmax weight matching(G maxcardinality=False)stopB = timeitdefault timer()

Compute Gˆ nad MˆstartC = timeitdefault timer()useless edges(num nodesadj dict1matching dict1uselessadj dict2G)forced edges(Gadj dict2matching dict1num nodesforced)Final Matching=nxmax weight matching(G maxcardinality=False)stopC = timeitdefault timer()

GreedystartG = timeitdefault timer()greedy size=Greedy(num nodesadj dict3matching dict2)stopG = timeitdefault timer()

wswrite(index 6 Gnumber of nodes())wswrite(index 7 Gnumber of edges())wswrite(index 8 uselessnumber of edges())wswrite(index 9 forcednumber of edges())if Gdegree()values()

wswrite(index 10 max(Gdegree()values()))else

50 Application

wswrite(index 10 0)wswrite(index 11 len(Classical Matching)2)wswrite(index 12 len(Final Matching)2+forcednumber of edges())wswrite(index 13 greedy size)wswrite(index 14 stopB minus startBstyle1)wswrite(index 15 stopC minus startCstyle1)wswrite(index 16 stopG minus startGstyle1)wswrite(index 17 (len(Final Matching)2+forcednumber of edges())(num nodes2)style1)wswrite(index 18 Gnumber of nodes()Gtstyle1)wswrite(index 19 Gnumber of edges()Gtstyle1)wswrite(index 20 (len(Final Matching)2+forcednumber of edges())(len(Classical Matching)2)style1)

wbsave(AA Results Random Reyni Large Bipartitexls)

Main function Here we must choose the input form of the dataif name == main

startA = timeitdefault timer()General()stopA = timeitdefault timer()

print nThis program has terminatednnRunning time for 480 files stopAminusstartAprint nnPlease open AA Results Random Reyni Largexls file to see the Results

Appendix A 51

Plotmat

clear allclose allload(RN1Lmat)load(RN1Smat)load(RN2Lmat)load(RN2Smat)load(RN3Lmat)load(RN3Smat)

Plotsh(1)=figure(NameHistogram of Matching size difference between Constraint Algorithm and Greedy AlgorithmNumberTitleoff)

RN1L Greedydiff=RN1L Final matchingminusRN1L Greedy matchingRN2L Greedydiff=RN2L Final matchingminusRN2L Greedy matchingRN3L Greedydiff=RN3L Final matchingminusRN3L Greedy matchingRN1S Greedydiff=RN1S Final matchingminusRN1S Greedy matchingRN2S Greedydiff=RN2S Final matchingminusRN2S Greedy matchingRN3S Greedydiff=RN3S Final matchingminusRN3S Greedy matching

RN1L Finaldiff=RN1L Classical matchingminusRN1L Final matchingRN2L Finaldiff=RN2L Classical matchingminusRN2L Final matchingRN3L Finaldiff=RN3L Classical matchingminusRN3L Final matchingRN1S Finaldiff=RN1S Classical matchingminusRN1S Final matchingRN2S Finaldiff=RN2S Classical matchingminusRN2S Final matchingRN3S Finaldiff=RN3S Classical matchingminusRN3S Final matching

RN1L Classicaldiff=(RN1L Nodes2)minusRN1L Classical matchingRN2L Classicaldiff=(RN2L Nodes2)minusRN2L Classical matchingRN3L Classicaldiff=(RN3L Nodes2)minusRN3L Classical matchingRN1S Classicaldiff=(RN1S Nodes2)minusRN1S Classical matchingRN2S Classicaldiff=(RN2S Nodes2)minusRN2S Classical matchingRN3S Classicaldiff=(RN3S Nodes2)minusRN3S Classical matching

subplot(231)hold onhistf(RN1L Greedydiff0110facecolorbfacealpha9edgealpha1)histf(RN1L Finaldiff0110facecolorrfacealpha5edgealpha1)histf(RN1L Classicaldiff0110facecolorgfacealpha5edgealpha1)legalpha(ConminusGreClasminusConPerfminusClasslocationnortheast)legend boxoffaxis tightxlabel(edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN1L)grid on

subplot(232)hold onhistf(RN2L Greedydiff0110facecolorbfacealpha9edgealpha1)

52 Application

histf(RN2L Finaldiff0110facecolorrfacealpha5edgealpha1)histf(RN2L Classicaldiff0110facecolorgfacealpha5edgealpha1)legalpha(ConminusGreClasminusConPerfminusClasslocationnortheast)legend boxoffaxis tightxlabel(edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN2L)grid on

subplot(233)hold onhistf(RN3L Greedydiff0110facecolorbfacealpha5edgealpha1)histf(RN3L Finaldiff0110facecolorrfacealpha5edgealpha1)histf(RN3L Classicaldiff0110facecolorgfacealpha5edgealpha1)legalpha(ConminusGreClasminusConPerfminusClasslocationnortheast)legend boxoffaxis tightxlabel(edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN3L)grid on

subplot(234)hold onhistf(RN1S Greedydiff0110facecolorbfacealpha5edgealpha1)histf(RN1S Finaldiff0110facecolorrfacealpha5edgealpha1)histf(RN1S Classicaldiff0110facecolorgfacealpha5edgealpha1)legalpha(ConminusGreClasminusConPerfminusClasslocationnortheast)legend boxoffaxis tightxlabel(edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(R1NS)grid on

subplot(235)hold onhistf(RN2S Greedydiff0110facecolorbfacealpha5edgealpha1)histf(RN2S Finaldiff0110facecolorrfacealpha5edgealpha1)histf(RN2S Classicaldiff0110facecolorgfacealpha5edgealpha1)legalpha(ConminusGreClasminusConPerfminusClasslocationnortheast)legend boxoffaxis tightxlabel(edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN2S)grid on

subplot(236)hold onhistf(RN3S Greedydiff0110facecolorbfacealpha5edgealpha1)histf(RN3S Finaldiff0110facecolorrfacealpha5edgealpha1)histf(RN3S Classicaldiff0110facecolorgfacealpha5edgealpha1)

Appendix A 53

legalpha(ConminusGreClasminusConPerfminusClasslocationnortheast)legend boxoffaxis tightgrid ontitle(RN3S)xlabel(edges) xminusaxis labelylabel(instances) yminusaxis labelset(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN1png minusr300)h(2)=figure(NameHistogram of Max Degree of G AND G HatNumberTitleoff)RN1L x=RN1L MaxDegreeGminusRN1L MaxDegreeG HatRN2L x=RN2L MaxDegreeGminusRN2L MaxDegreeG HatRN3L x=RN3L MaxDegreeGminusRN3L MaxDegreeG HatRN1S x=RN1S MaxDegreeGminusRN1S MaxDegreeG HatRN2S x=RN2S MaxDegreeGminusRN2S MaxDegreeG HatRN3S x=RN3S MaxDegreeGminusRN3S MaxDegreeG Hatsubplot(231)hold onhistf(RN1L MaxDegreeG0150facecolorbfacealpha5edgealpha1)histf(RN1L MaxDegreeG Hat0150facecolorrfacealpha5edgealpha1)histf(RN1L x0150facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightxlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN1L)grid on

subplot(232)hold onhistf(RN2L MaxDegreeG010500facecolorbfacealpha5edgealpha1)histf(RN2L MaxDegreeG Hat010500facecolorrfacealpha5edgealpha1)histf(RN2L x010500facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightxlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN2L)grid on

subplot(233)hold onhistf(RN3L MaxDegreeG010300facecolorbfacealpha5edgealpha1)histf(RN3L MaxDegreeG Hat010300facecolorrfacealpha5edgealpha1)histf(RN3L x010300facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightxlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN3L)

54 Application

grid on

subplot(234)hold onhistf(RN1S MaxDegreeG0150facecolorbfacealpha5edgealpha1)histf(RN1S MaxDegreeG Hat0150facecolorrfacealpha5edgealpha1)histf(RN1S x0150facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightxlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(R1NS)grid on

subplot(235)hold onhistf(RN2S MaxDegreeG010500facecolorbfacealpha5edgealpha1)histf(RN2S MaxDegreeG Hat010500facecolorrfacealpha5edgealpha1)histf(RN2S x010500facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightxlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN2S)grid on

subplot(236)hold onhistf(RN3S MaxDegreeG05300facecolorbfacealpha5edgealpha1)histf(RN3S MaxDegreeG Hat05300facecolorrfacealpha5edgealpha1)histf(RN3S x05300facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightgrid ontitle(RN3S)xlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labelset(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN2png minusr300)

h(3)=figure(NameComputation time over edgesNumberTitleoff)

subplot(231)hold onstem(RN1L EdgesGRN1L Time classicalg)stem(RN1L EdgesGRN1L Time algorithmro)stem(RN1L EdgesGRN1L Time greedybx)grid on

Appendix A 55

title(RN1L)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)

subplot(232)hold onstem(RN2L EdgesGRN2L Time classicalg)stem(RN2L EdgesGRN2L Time algorithmro)stem(RN2L EdgesGRN2L Time greedybx)grid ontitle(RN2L)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)

subplot(233)hold onstem(RN3L EdgesGRN3L Time classicalg)stem(RN3L EdgesGRN3L Time algorithmro)stem(RN3L EdgesGRN3L Time greedybx)grid ontitle(RN3L)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)

subplot(234)hold onstem(RN1S EdgesGRN1S Time classicalg)stem(RN1S EdgesGRN1S Time algorithmro)stem(RN1S EdgesGRN1S Time greedybx)grid ontitle(RN1S)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)

subplot(235)hold onstem(RN2S EdgesGRN2S Time classicalg)stem(RN2S EdgesGRN2S Time algorithmro)stem(RN2S EdgesGRN2S Time greedybx)grid ontitle(RN2S)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)

subplot(236)hold onstem(RN3S EdgesGRN3S Time classicalg)stem(RN3S EdgesGRN3S Time algorithmro)stem(RN3S EdgesGRN3S Time greedybx)

56 Application

grid ontitle(RN3S)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)set(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN3png minusr300)

h(4)=figure(NameSorted matching sizeNumberTitleoff)RN1L Sorted matching temp(1)=RN1L Classical matchingRN1L Sorted matching temp(2)=RN1L Final matchingRN1L Sorted matching temp(3)=RN1L Greedy matchingRN1L Sorted matching temp(4)=RN1L Initial matchingRN1L Sorted matching=sortrows(RN1L Sorted matching temp)

RN2L Sorted matching temp(1)=RN2L Classical matchingRN2L Sorted matching temp(2)=RN2L Final matchingRN2L Sorted matching temp(3)=RN2L Greedy matchingRN2L Sorted matching temp(4)=RN2L Initial matchingRN2L Sorted matching=sortrows(RN2L Sorted matching temp)

RN3L Sorted matching temp(1)=RN3L Classical matchingRN3L Sorted matching temp(2)=RN3L Final matchingRN3L Sorted matching temp(3)=RN3L Greedy matchingRN3L Sorted matching temp(4)=RN3L Initial matchingRN3L Sorted matching=sortrows(RN3L Sorted matching temp)

RN1S Sorted matching temp(1)=RN1S Classical matchingRN1S Sorted matching temp(2)=RN1S Final matchingRN1S Sorted matching temp(3)=RN1S Greedy matchingRN1S Sorted matching temp(4)=RN1S Initial matchingRN1S Sorted matching=sortrows(RN1S Sorted matching temp)

RN2S Sorted matching temp(1)=RN2S Classical matchingRN2S Sorted matching temp(2)=RN2S Final matchingRN2S Sorted matching temp(3)=RN2S Greedy matchingRN2S Sorted matching temp(4)=RN2S Initial matchingRN2S Sorted matching=sortrows(RN2S Sorted matching temp)

RN3S Sorted matching temp(1)=RN3S Classical matchingRN3S Sorted matching temp(2)=RN3S Final matchingRN3S Sorted matching temp(3)=RN3S Greedy matchingRN3S Sorted matching temp(4)=RN3S Initial matchingRN3S Sorted matching=sortrows(RN3S Sorted matching temp)

subplot(231)hold onplot(RN1L Sorted matching(1)b)plot(RN1L Sorted matching(2)g)plot(RN1L Sorted matching(3)r)plot(RN1L Sorted matching(4)m)

Appendix A 57

grid ontitle(RN1L)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)

subplot(232)hold onplot(RN2L Sorted matching(1)b)plot(RN2L Sorted matching(2)g)plot(RN2L Sorted matching(3)r)plot(RN2L Sorted matching(4)m)grid ontitle(RN2L)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)

subplot(233)hold onplot(RN3L Sorted matching(1)b)plot(RN3L Sorted matching(2)g)plot(RN3L Sorted matching(3)r)plot(RN3L Sorted matching(4)m)grid ontitle(RN3L)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)

subplot(234)hold onplot(RN1S Sorted matching(1)b)plot(RN1S Sorted matching(2)g)plot(RN1S Sorted matching(3)r)plot(RN1S Sorted matching(4)m)grid ontitle(RN1S)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)

subplot(235)hold onplot(RN2S Sorted matching(1)b)plot(RN2S Sorted matching(2)g)plot(RN2S Sorted matching(3)r)plot(RN2S Sorted matching(4)m)grid ontitle(RN2S)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)

58 Application

subplot(236)hold onplot(RN3S Sorted matching(1)b)plot(RN3S Sorted matching(2)g)plot(RN3S Sorted matching(3)r)plot(RN3S Sorted matching(4)m)grid ontitle(RN3S)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)set(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN4png minusr300)h(5)=figure(NameSorted RatiosNumberTitleoff)RN1L ratio1=RN1L NodesG hatRN1L NodesGRN2L ratio1=RN2L NodesG hatRN2L NodesGRN3L ratio1=RN3L NodesG hatRN3L NodesGRN1S ratio1=RN1S NodesG hatRN1S NodesGRN2S ratio1=RN2S NodesG hatRN2S NodesGRN3S ratio1=RN3S NodesG hatRN3S NodesG

RN1L ratio2=RN1L EdgesG HatRN1L EdgesGRN2L ratio2=RN2L EdgesG HatRN2L EdgesGRN3L ratio2=RN3L EdgesG HatRN3L EdgesGRN1S ratio2=RN1S EdgesG HatRN1S EdgesGRN2S ratio2=RN2S EdgesG HatRN2S EdgesGRN3S ratio2=RN3S EdgesG HatRN3S EdgesG

RN1L ratio3=RN1L MaxDegreeG HatRN1L MaxDegreeGRN2L ratio3=RN2L MaxDegreeG HatRN2L MaxDegreeGRN3L ratio3=RN3L MaxDegreeG HatRN3L MaxDegreeGRN1S ratio3=RN1S MaxDegreeG HatRN1S MaxDegreeGRN2S ratio3=RN2S MaxDegreeG HatRN2S MaxDegreeGRN3S ratio3=RN3S MaxDegreeG HatRN3S MaxDegreeG

RN1L ratio(1)=RN1L ratio1RN1L ratio(2)=RN1L ratio2RN1L ratio(3)=RN1L ratio3

RN2L ratio(1)=RN2L ratio1RN2L ratio(2)=RN2L ratio2RN2L ratio(3)=RN2L ratio3

RN3L ratio(1)=RN3L ratio1RN3L ratio(2)=RN3L ratio2RN3L ratio(3)=RN3L ratio3

RN1S ratio(1)=RN1S ratio1RN1S ratio(2)=RN1S ratio2RN1S ratio(3)=RN1S ratio3

RN2S ratio(1)=RN2S ratio1

Appendix A 59

RN2S ratio(2)=RN2S ratio2RN2S ratio(3)=RN2S ratio3

RN3S ratio(1)=RN3S ratio1RN3S ratio(2)=RN3S ratio2RN3S ratio(3)=RN3S ratio3

RN1L ratio sorted=sortrows(RN1L ratio)RN2L ratio sorted=sortrows(RN2L ratio)RN3L ratio sorted=sortrows(RN3L ratio)RN1S ratio sorted=sortrows(RN1S ratio)RN2S ratio sorted=sortrows(RN2S ratio)RN3S ratio sorted=sortrows(RN3S ratio)

subplot(231)hold onplot(RN1L ratio sorted(1)b)plot(RN1L ratio sorted(2)g)plot(RN1L ratio sorted(3)r)grid ontitle(RN1L)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)

subplot(232)hold onplot(RN2L ratio sorted(1)b)plot(RN2L ratio sorted(2)g)plot(RN2L ratio sorted(3)r)grid ontitle(RN2L)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)

subplot(233)hold onplot(RN3L ratio sorted(1)b)plot(RN3L ratio sorted(2)g)plot(RN3L ratio sorted(3)r)grid ontitle(RN3L)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)

subplot(234)hold onplot(RN1S ratio sorted(1)b)plot(RN1S ratio sorted(2)g)plot(RN1S ratio sorted(3)r)grid on

60 Application

title(RN1S)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)

subplot(235)hold onplot(RN2S ratio sorted(1)b)plot(RN2S ratio sorted(2)g)plot(RN2S ratio sorted(3)r)grid ontitle(RN2S)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)

subplot(236)hold onplot(RN3S ratio sorted(1)b)plot(RN3S ratio sorted(2)g)plot(RN3S ratio sorted(3)r)grid ontitle(RN3S)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)set(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN5png minusr300)

h(6)=figure(NameSorted edges over nodesNumberTitleoff)

RN1L DegreeG1=(RN1L EdgesG)(RN1L NodesG)RN1L DegreeG Hat1=(RN1L EdgesG Hat)(RN1L NodesG hat)

RN1L Degree temp1(1)=RN1L DegreeG1RN1L Degree temp1(2)=RN1L DegreeG Hat1RN1L Degree sorted1=sortrows(RN1L Degree temp1)subplot(231)hold on

plot(RN1L Degree sorted1(1)b)plot(RN1L Degree sorted1(2)g)grid ontitle(RN1L)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)

RN2L DegreeG1=(RN2L EdgesG)(RN2L NodesG)RN2L DegreeG Hat1=(RN2L EdgesG Hat)(RN2L NodesG hat)

RN2L Degree temp1(1)=RN2L DegreeG1

Appendix A 61

RN2L Degree temp1(2)=RN2L DegreeG Hat1RN2L Degree sorted1=sortrows(RN2L Degree temp1)

subplot(232)hold onplot(RN2L Degree sorted1(1)b)plot(RN2L Degree sorted1(2)g)grid ontitle(RN2L)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)

RN3L DegreeG1=(RN3L EdgesG)(RN3L NodesG)RN3L DegreeG Hat1=(RN3L EdgesG Hat)(RN3L NodesG hat)

RN3L Degree temp1(1)=RN3L DegreeG1RN3L Degree temp1(2)=RN3L DegreeG Hat1RN3L Degree sorted1=sortrows(RN3L Degree temp1)

subplot(233)hold onplot(RN3L Degree sorted1(1)b)plot(RN3L Degree sorted1(2)g)grid ontitle(RN3L)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)

RN1S DegreeG1=(RN1S EdgesG)(RN1S NodesG)RN1S DegreeG Hat1=(RN1S EdgesG Hat)(RN1S NodesG hat)

RN1S Degree temp1(1)=RN1S DegreeG1RN1S Degree temp1(2)=RN1S DegreeG Hat1RN1S Degree sorted1=sortrows(RN1S Degree temp1)

subplot(234)hold onplot(RN1S Degree sorted1(1)b)plot(RN1S Degree sorted1(2)g)grid ontitle(RN1S)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)

RN2S DegreeG1=(RN2S EdgesG)(RN2S NodesG)RN2S DegreeG Hat1=(RN2S EdgesG Hat)(RN2S NodesG hat)

RN2S Degree temp1(1)=RN2S DegreeG1

62 Application

RN2S Degree temp1(2)=RN2S DegreeG Hat1RN2S Degree sorted1=sortrows(RN2S Degree temp1)

subplot(235)hold onplot(RN2S Degree sorted1(1)b)plot(RN2S Degree sorted1(2)g)grid ontitle(RN2S)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)

RN3S DegreeG1=(RN3S EdgesG)(RN3S NodesG)RN3S DegreeG Hat1=(RN3S EdgesG Hat)(RN3S NodesG hat)

RN3S Degree temp1(1)=RN3S DegreeG1RN3S Degree temp1(2)=RN3S DegreeG Hat1RN3S Degree sorted1=sortrows(RN3S Degree temp1)

subplot(236)hold onplot(RN3S Degree sorted1(1)b)plot(RN3S Degree sorted1(2)g)grid ontitle(RN3S)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)set(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN6png minusr300)h(7)=figure(NameSorted mATCHED DEGREENumberTitleoff)RN1L ratioMax(1)=RN1L MaxDegreeGRN1L ratioMax(2)=RN1L MaxDegreeG Hat

RN1L ratio sortedMax=sortrows(RN1L ratioMax)subplot(231)hold onplot(RN1L ratio sortedMax(1)b)plot(RN1L ratio sortedMax(2)g)grid ontitle(RN1L)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)

RN2L ratioMax(1)=RN2L MaxDegreeGRN2L ratioMax(2)=RN2L MaxDegreeG Hat

RN2L ratio sortedMax=sortrows(RN2L ratioMax)subplot(232)

Appendix A 63

hold onplot(RN2L ratio sortedMax(1)b)plot(RN2L ratio sortedMax(2)g)grid ontitle(RN2L)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)

RN3L ratioMax(1)=RN3L MaxDegreeGRN3L ratioMax(2)=RN3L MaxDegreeG Hat

RN3L ratio sortedMax=sortrows(RN3L ratioMax)subplot(233)hold onplot(RN3L ratio sortedMax(1)b)plot(RN3L ratio sortedMax(2)g)grid ontitle(RN3L)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)

RN1S ratioMax(1)=RN1S MaxDegreeGRN1S ratioMax(2)=RN1S MaxDegreeG Hat

RN1S ratio sortedMax=sortrows(RN1S ratioMax)subplot(234)hold onplot(RN1S ratio sortedMax(1)b)plot(RN1S ratio sortedMax(2)g)grid ontitle(RN1S)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)

RN2S ratioMax(1)=RN2S MaxDegreeGRN2S ratioMax(2)=RN2S MaxDegreeG Hat

RN2S ratio sortedMax=sortrows(RN2S ratioMax)

subplot(235)hold onplot(RN2S ratio sortedMax(1)b)plot(RN2S ratio sortedMax(2)g)grid ontitle(RN2S)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)

RN3S ratioMax(1)=RN3S MaxDegreeGRN3S ratioMax(2)=RN3S MaxDegreeG Hat

64 Application

RN3S ratio sortedMax=sortrows(RN3S ratioMax)subplot(236)hold onplot(RN3S ratio sortedMax(1)b)plot(RN3S ratio sortedMax(2)g)grid ontitle(RN1L)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)set(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN7png minusr300)

tilefigs()(h)

Bibliography

[1] C Berge ldquoTWO THEOREMS IN GRAPH THEORYrdquo Proceedings of the NationalAcademy of Sciences of the United States of America vol 43 no 9 pp 842ndash844Sep 1957

[2] L Bui S Sanghavi and R Srikant ldquoDistributed link scheduling with constantoverheadrdquo IEEEACM Trans Netw vol 17 no 5 pp 1467ndash1480 2009

[3] R Duan and S Pettie ldquoLinear-time approximation for maximum weight matchingrdquoJ ACM vol 61 no 1 2014

[4] J Edmonds ldquoPaths trees and flowersrdquo Canadian Journal of Mathematics vol 17pp 449ndash467 1965

[5] J E Hopcroft and R M Karp ldquoAn n52 algorithm for maximum matchings inbipartite graphsrdquo SIAM J Comput vol 2 no 4 pp 225ndash231 1973

[6] S Micali and V V Vazirani ldquoAn O(radic|V ||E|) algorithm for finding maximum

matching in general graphsrdquo in 21st Symp on Foundations of Comp Sc (FOCS)IEEE 1980 pp 17ndash27

[7] N Nisse A Salch and V Weber ldquoRecovery of disrupted airline operationsrdquo 2015httphalinriafrSomething

[8] X Wu and R Srikant ldquoRegulated maximal matching A distributed schedulingalgorithm for multi-hop wireless networks with nodeexclusive spectrum sharingrdquo inIEEE Conf on Decision and Control 2005

65

  • Contents
  • Introduction
  • Algorithms
    • Maximum matching
    • k-maximum matching
      • k-matching for Airport Slot assignment
      • The case where k=3
      • The case of Paths
      • The case of the Spider
          • Application
            • Description
            • Reyni Erdos
            • Barabaacutesi Albert
            • Amadeus Graphs
            • Bipartite
            • Bipartite with degree seq
            • Appendix A
              • BipartiteGraphGeneratorpy
              • RandomGraphGeneratorpy
              • kequals3MaximumMatchingpy
              • Plotmat
                  • Bibliography
Page 14: Theodoros Alexandros KARAGKIOULES -  · Introduction This work is the result of a 6 months internship, under the supervision of research O cer Nicolas NISSE. The original scope of

22 Reyni Erdos 15

bull For the case of small initial matching we observe some deviation in the valuesof the ration for G and that is explained with the removal of only useless edgeswhich only alters the |E| and keeps |V | in the original values

Sorted ∆

Sorted ∆-Comments

bull In this set of figures the ascending order of the ∆ of G is associated with the ∆of G

bull There is no significant jump of the ∆ for each graph category which tells that thatwe are comparing a uniform distribution of random grapghs for each probabilitycase

16 Application

bull For larger initial matching we observe the difference in the ∆s of G and G giventhe removed forced edges( and their endpoints) At some cases the ∆ of G dropsto 0 since the vast majority of edges have been declared forced and removed alongwith their endpoints

bull For smaller initial matching the ∆s of G and G follow mostly the same trend onlya few number of different instances

23 Barabasi Albert

Graph characteristics Barabasi Albert

bull BAxy are randomly generated graphs with a fixed number of 1000 nodes

bull There are 6 categories based on ini matching and of attached edges m

bull x = L S L When the initial matching is large and S when it is small

bull y = 1 2 3 1 when m = [1 10] 2 when m = [20 50] and 3 m = [50 100]

Computation time over |E|

23 Barabasi Albert 17

Computation time over |E| - Comments

bull When the initial matching is sufficiently large then the forced edges are taken out(a process which takes a fragment of the computation time) and then the classicalmatching algorithm (Edmonds) is applied on a smaller graph(G) This reducessignificantly the computation time

bull When the initial matching is small then the computation time of the constraintalgorithm might be larger than that of Edmonds The reason is that the constraintalgorithm need some time to compute the useless and forced edges and thenEdmonds algorithm is applied on G G Thus the overall processing time issometimes larger

Sorted matching size

18 Application

Sorted matching size-Comments

bull In this graph the matching size of the classical algorithm is depicted in ascendingorder along with the corresponding constraint algorithm and greedy result

bull Here in the case where m is small for both cases of initial matching (small large)the result may vary greatly starting from a value of half the perfect matching withsmall differences between the results of the various algorithm implementations

bull For the other cases of m the results converge

bull This is explained as for small values of m the graph is disconnected

bull In the matching size difference set of figures a very noticing difference value ap-pears For the cases of small m( the number of existing nodes that a new node isconnected to at the creation of the graph) we can see that the difference in the

23 Barabasi Albert 19

matching size compared to that of the perfect matching could be up to 40 ofthat of the matching size So there are occasions where the matching size is 200edges when the perfect matching would have been 500

bull the difference between the Constraint matching and the classical matching andthe difference of the constraint matching and that of the greedy matching do notshow significant values

Sorted Ratios

Sorted Ratio s -Comments

bull This set of figures depicts the ratios VV

EE

∆∆

in ascending order of VV

20 Application

bull It is evident that when the initial matching is large the amount of forced edges(and their endpoints) removed is high thus the ratio of Nodes and edges is verylow For higher probabilities almost all edges are removed as useless

bull For a smaller initial matching almost no forced edges (and their endpoints) areremoved which we conclude be the node ration being close to 1 There is somesmall amount of useless edges removed though since the ratio of edges is less butclose to 1

bull The ratio of ∆ for large initial matching follows the trend of the node ratio yetfor smaller initial matching it deviates significantly

Sorted |E||V |

23 Barabasi Albert 21

Sorted |E||V | - Comments

bull Although as graph density the ratio 2|E||V |(|V |minus1)

is considered in this set of figures

we evaluate the correlation of the ratio |E||V | of G and G since the density of G

could acquire values higher than that of G

bull The figures are calculated in ascending order for the ratio of G

bull For the case of large initial matching the two ratios for G and G remain almostconstant ( to the extent of the edge attraction m of each graph) since removingforced edges( and their endpoints) alters the |E| and |V | proportionately

bull For the case of small initial matching we observe some deviation in the valuesof the ration for G and that is explained with the removal of only useless edgeswhich only alters the |E| and keeps |V | in the original values

Sorted ∆

22 Application

Sorted ∆-Comments

bull In this set of figures the ascending order of the ∆ of G is associated with the ∆of G

bull There is a significant jump of the ∆ for each graph category which tells that thatwe are not comparing a uniform distribution of random graphs and based on theedge attraction m the graphs can vary in form

bull For larger initial matching we observe the difference in the ∆s of G and G giventhe removed forced edges( and their endpoints) At some cases the ∆ of G dropsto 0 since the vast majority of edges have been declared forced and removed alongwith their endpoints What is interesting is that the ∆ of G oscilates within stablelimits

24 Amadeus Graphs 23

bull For smaller initial matching the ∆s of G and G follow mostly the same trend onlya few number of different instances

24 Amadeus Graphs

Graph characteristics Amadeus graphs

bull These are the bipartite graphs provided by Amadeus

Computation time over |E|

Computation time over |E| - Comments

24 Application

bull For every instance the computation time of the classical algorithm is always smallerto that of the constraint matching

bull This allows as to speculate that we always compute a smaller G which also impliesthat we always find a set of forced edges and useless

Sorted matching size

Sorted matching size - Comments

bull Size of matching has an upward trend since the magnitude of the graphs is notthe same for the 160 instances

bull No significant deviation is noticed as per the first graph

24 Amadeus Graphs 25

bull Except from deviation from the perfect matching (number of flights) where some-times it could get up to 40

bull For the Amadeus Bipartite graphs we can see that the difference of the Classicaland the constraint implementation is not more than 1 edge in the matching

bull There appears to be a difference of up to 24 edges between the Classical matchingand the Perfect matching which is computed as the number of flights

bull The greedy algorithm performs well with only a few instances deviating slightlyform the Constraint algorithm result

Sorted Ratios

Sorted Ratios - Comments

26 Application

bull

Sorted |E||V |

Sorted |E||V | - Comments

bull Density of the graphs shows that on average we have 25-3 available time slot perflight

bull The line for the same value for G shows that there is a large deviation for everyinstance which allows for the hypothesis that the amount of useless+forced edgesof G has no obvious correlation to that of G

25 Bipartite 27

Sorted ∆

Sorted ∆-Comments

bull As per the previous related graphs for ∆ there is in significant drop in the ∆ of Gand G

25 Bipartite

Graph characteristics Bipartite random Graphs

bull BIPxy are randomly generated graphs with a fixed number of 1000(n=500 andm=500) nodes

bull There are 6 categories based on ini matching and probability p

28 Application

bull Probability p has been chosen as such in order to simulate the |E||V | 25 of theAmadeus bipartite graphs

bull So in order to have about 2-4 edges for every node we choose accordingly theprobability p to choose one of the n lowastm possible edges

bull x = L S L When the initial matching is large and S when it is small

bull y = 1 2 3 1 when p = 18250

2 when p = 25250

and 3 when p = 34250

Computation time over

Computation time overedges-Comments

bull

25 Bipartite 29

Sorted matching size

Sorted matching size-Comments

bull In these set of graphs one can instantly notice that only a few instances with highprobability can reach a matching size equal to the perfect matching

bull For the case of the initial matching we witness that there is a gap between the lineof the classical matching and those of the constraint and greedy results suggestingsmaller matching sizes of 10-40 edges

bull For the case of the small initial matching the result of the constraint matchingis now close to the result of the classical matching yet the greedy algorithm stillshows a relevantly big difference

30 Application

bull In this set of bipartite graphs we can witness that the result of the Constraintmatching shows a difference with the classical matching when the initial matchingis large The difference is smaller as the probability gets larger

bull For the case of the small initial matching the above phenomenom does not occuryet the greedy results deviates from that of the constraint matching

bull As per the pefrect matching compared to the classical matching a difference of5-10 edges is evident at almost all cases

Sorted Ratios

Sorted Ratios-Comments

bull Great max degree deviation

25 Bipartite 31

bull Regardless of the probability the ration of nodes and edges seems to have similarbehaviour when compared to the respective graphs of the same matching scale

bull Same gap between nodes ration and edges ration for all cases

Sorted |E||V |

Sorted |E||V | - Comments

bull In these set of figures we witness that the |E||V | acquires values relevant to those ofthe amadeus graphs The random graphs were constructed to depict this similarity

bull For smaller initial matching the ratios for G and G show the same upward trendand also they acquire closer values It represents the decrease of the averagenumber of forced edges in comparison to the larger matching cases

32 Application

Sorted ∆

Sorted ∆-Comments

bull ∆ acquires the same min and max values for each probability case (expected)

bull Gap in the case of large initial matching

26 Bipartite with degree seq

Graph characteristics

bull DEQBIPxy are randomly generated graphs based on three different types of degreedistribution of the Amadeus graphs

26 Bipartite with degree seq 33

bull There are 6 categories based on ini matching and degree distribution

bull x = L S L When the initial matching is large and S when it is small

bull y = 1 2 3 1 when degree distribution is based on file 2 when degree distributionis based on file and 3 when degree distribution is based on file

Computation time over

34 Application

Computation time overedges-Comments

bull Greedy algorithm takes minimum amount of time

bull The smaller the initial matching the more smaller the difference in comoutationtime of Constraint and classical algorithm

bull Due to preprocessing and the fact that G and G are the almost identical thetotal time needed to apply the constraint algorithm is in some cases bigger

Sorted matching size

26 Bipartite with degree seq 35

Sorted matching size-Comments

bull Classical matching is equal to perfect matching in every case

bull Constraint and greedy have identical behaviour

bull The larger the spectrum of the degree sequence the more efficient the matching

Sorted Ratios

36 Application

Sorted Ratios-Comments

bull With large initial matching most of the edges are considenred uselles or forced andare removed thus the ratio is close(if not equal to) zero

bull For small matching and large degree sequence sectrum hte max degree remainsthe same Only a few forced edges (and their nodes) are removed apparently nonodes with max degree

Sorted |E||V |

26 Bipartite with degree seq 37

Sorted |E||V | - Comments

bull In these set of figures we witness that the |E||V | acquires values relevant to those ofthe amadeus graphs The random graphs were constructed to depict this similarity

bull For smaller initial matching the ratios for G and G show the same upward trendand also they acquire closer values It repsresent the decrease of the averagenumber of forced edges in comparison to the larger matching cases

Sorted ∆

38 Application

Sorted ∆-Comments

bull Big difference in max degree in large initial matching

bull Almost identical behaviour in the case of small initial matching

Appendix A 39

Appendix A

BipartiteGraphGeneratorpy

from future import divisionimport networkx as nx

from networkxalgorithms import approximationimport collectionsimport randomimport mathfrom networkxalgorithms import bipartiteif name == main

for i in range(1481)waqs 481index=1n=randomrandint(100 1000)

n1=95 was 500me1=118

n2=251 was 500me2=903

n3=165 was 500me3=412

m=0m1=0p=randomrandom()p1=18250p2=25250p3=34250print ip=05t1=randomrandint(0 1)print im2=randomrandint(n2minus1 n2+1)G = nxGraph()ma = nxGraph()

aseq1=[1 2 3 4 5 3]

bseq1=[4 3 3 1 2 2 1]

aseq2=[16 14 14 14 12 11]bseq2=[0 0 0 0 0 0]

aseq3=[8 7 8 8 8 8]bseq3=[0 0 0 0 0 0]

40 Application

print Gnumber of edges()if ilt=160

G=bipartiteconfiguration model(aseq1 bseq1 create using=None seed=None)A=nxadjacency matrix(G)for ii in range(0n1+me1)

maadd node(ii)A=[Rtodense()tolist()[0] for R in A]

printnummanumber of nodes()rl=randomsample(range(0n1+me1) n1+me1)m=0done vertices = set()for p in rlprintin fordone verticesadd(p)

neighbors = []list()for iii in range(0n1+me1)

if A[p][iii]==1neighborsappend(iii)

randomshuffle(neighbors)continue loop = Truedegree = len(neighbors)

print degreej = 0p4=randomrandom()while continue loop and (jltdegree)print in loop

next = neighbors[j]if next not in done vertices and p not in done vertices

done verticesadd(p)done verticesadd(next)if p4gt=07print added edge

maadd edge(pnext)m=m+1

continue loop = Falsej += 1

print matching listOfedgeprint maedge

MA=nxadjacency matrix(ma)print MA

MA=[Rtodense()tolist()[0] for R in MA]print MA

B=[ join(map(strR)) for R in A]MB=[ join(map(strR)) for R in MA]

C=njoin(B)+nMC=njoin(MB)+n

print nprint mprint m1

filea=str(i)+txtwith open(fileaw) as f

Appendix A 41

fwrite(str(n1+me1))fwrite(n)fwrite(str(n1+me1))fwrite(n)fwrite(str(m))fwrite(n)fwrite(n)fwrite(C)fwrite(n)fwrite(MC)

elif igt160 and ilt321G=bipartiteconfiguration model(aseq2 bseq2 create using=None seed=None)A=nxadjacency matrix(G)for ii in range(0n2+me2)

maadd node(ii)A=[Rtodense()tolist()[0] for R in A]

printnummanumber of nodes()rl=randomsample(range(0n2+me2) n2+me2)m=0done vertices = set()for p in rlprintin fordone verticesadd(p)

neighbors = []list()for iii in range(0n2+me2)

if A[p][iii]==1neighborsappend(iii)

randomshuffle(neighbors)continue loop = Truedegree = len(neighbors)

print degreej = 0p4=randomrandom()while continue loop and (jltdegree)

print in loopnext = neighbors[j]if next not in done vertices and p not in done vertices

done verticesadd(p)done verticesadd(next)if p4gt=07

print added edgemaadd edge(pnext)m=m+1

continue loop = Falsej += 1

print matching listOfedgeprint maedge

MA=nxadjacency matrix(ma)print MA

MA=[Rtodense()tolist()[0] for R in MA]print MA

B=[ join(map(strR)) for R in A]MB=[ join(map(strR)) for R in MA]

42 Application

C=njoin(B)+nMC=njoin(MB)+n

print nprint mprint m1

filea=str(i)+txtwith open(fileaw) as f

fwrite(str(n2+me2))fwrite(n)fwrite(str(n2+me2))fwrite(n)fwrite(str(m))fwrite(n)fwrite(n)fwrite(C)fwrite(n)fwrite(MC)

elseG=bipartiteconfiguration model(aseq3 bseq3 create using=None seed=None)A=nxadjacency matrix(G)for ii in range(0n3+me3)

maadd node(ii)A=[Rtodense()tolist()[0] for R in A]

printnummanumber of nodes()rl=randomsample(range(0n3+me3) n3+me3)m=0done vertices = set()for p in rlprintin fordone verticesadd(p)

neighbors = []list()for iii in range(0n3+me3)

if A[p][iii]==1neighborsappend(iii)

randomshuffle(neighbors)continue loop = Truedegree = len(neighbors)

print degreej = 0p4=randomrandom()while continue loop and (jltdegree)

print in loopnext = neighbors[j]if next not in done vertices and p not in done vertices

done verticesadd(p)done verticesadd(next)if p4gt=07print added edge

maadd edge(pnext)m=m+1

continue loop = Falsej += 1

Appendix A 43

print matching listOfedgeprint maedge

MA=nxadjacency matrix(ma)print MA

MA=[Rtodense()tolist()[0] for R in MA]print MA

B=[ join(map(strR)) for R in A]MB=[ join(map(strR)) for R in MA]

C=njoin(B)+nMC=njoin(MB)+n

print nprint mprint m1

filea=str(i)+txtwith open(fileaw) as f

fwrite(str(n3+me3))fwrite(n)fwrite(str(n3+me3))fwrite(n)fwrite(str(m))fwrite(n)fwrite(n)fwrite(C)fwrite(n)fwrite(MC)

print nRandom graphs with random matching have been generated

44 Application

RandomGraphGeneratorpy

from future import divisionimport networkx as nxfrom networkxalgorithms import approximationimport collectionsimport randomimport mathif name == main

for i in range(1481)index=1n=randomrandint(100 1000)

n=1000m=0m1=0p=randomrandom()p1=mathlog(n2)np2=13p3=mathlog(n2)n+01p=05t1=randomrandint(0 1)print im2=randomrandint(n2minus1 n2+1)G = nxGraph()ma = nxGraph()print nme1=randomrandint(1 10)me2=randomrandint(2050)me3=randomrandint(50100)if ilt241

if ilt=80G=nxfast gnp random graph(n p1 seed=None directed=False)

elif igt80 and ilt161G=nxfast gnp random graph(n p2 seed=None directed=False)

elseG=nxfast gnp random graph(n p3 seed=None directed=False)

elseif ilt=320

G=nxbarabasi albert graph(n me1 seed=None)elif igt320 and ilt401

G=nxbarabasi albert graph(n me2 seed=None)else

G=nxbarabasi albert graph(n me3 seed=None)A=nxadjacency matrix(G)for ii in range(0n)

maadd node(ii)A=[Rtodense()tolist()[0] for R in A]

rl=randomsample(range(0n) n)m=0

Appendix A 45

done vertices = set()for p in rl

done verticesadd(p)neighbors = []list()for iii in range(0n)

if A[p][iii]==1neighborsappend(iii)

randomshuffle(neighbors)continue loop = Truedegree = len(neighbors)j = 0p2=randomrandom()while continue loop and (jltdegree)

next = neighbors[j]if next not in done vertices and p not in done vertices

done verticesadd(p)done verticesadd(next)if p2gt=00 Larger probability for smaller initial matching

maadd edge(pnext)m=m+1

continue loop = Falsej += 1

print matching listOfedgeprint maedgeMA=nxadjacency matrix(ma)MA=[Rtodense()tolist()[0] for R in MA]print MAB=[ join(map(strR)) for R in A]MB=[ join(map(strR)) for R in MA]

C=njoin(B)+nMC=njoin(MB)+nprint MCprint nprint mprint m1filea=str(i)+txtwith open(fileaw) as f

fwrite(str(n))fwrite(n)fwrite(str(n))fwrite(n)fwrite(str(m))fwrite(n)fwrite(n)fwrite(C)fwrite(n)fwrite(MC)

print nRandom graphs with random matching have been generated

46 Application

kequals3MaximumMatchingpy

from future import divisionimport networkx as nxfrom networkxalgorithms import bipartiteimport matplotlibpyplot as pltimport collectionsimport timeitimport xlwtimport xlrdimport mathimport sys

Case for General Graphsdef forced edges(Gadj dict2matching dict1num nodesforced)

flagg=0for n in range(0num nodes)

for k in adj dict2[n]if ([k]==matching dict1[n])

count=0for l in range(0num nodes)

count=count+adj dict2[l]count(k)if (len(adj dict2[n])==1) or (count==1)

forcedadd edge(nk)Gremove edge(nk)Gremove node(n)Gremove node(k)printforced edgenktemp=kflagg=1for m in range (len(adj dict2[n])minus1minus1minus1)

adj dict2[adj dict2[n][m]]remove(n)adj dict2[n]remove(adj dict2[n][m])

if adj dict2[temp]for l in range(len(adj dict2[temp])minus1minus1minus1)

if (adj dict2[temp][l]=n)adj dict2[adj dict2[temp][l]]remove(temp)adj dict2[temp]remove(adj dict2[temp][l])

break

def useless edges(num nodesadj dict1matching dict1uselessadj dict2G)for n in range(0num nodes)

for k in adj dict1[n]if ([k]=matching dict1[n]) and matching dict1[n] and matching dict1[k]

uselessadd edge(nk)Gremove edge(n k)

Appendix A 47

tempa=kadj dict2[n]remove(k)adj dict2[tempa]remove(n)adj dict1[tempa]remove(n)

return G

def Greedy(num nodesadj dict3matching dict2)

for n in range(0num nodes)if matching dict2[n]

flag2=minus1flag3=minus1for v in adj dict3[n]

if not matching dict2[v]flag2=vbreak

for p in adj dict3[matching dict2[n][0]]if not matching dict2[p]

flag3=pbreak

if (flag2=minus1) and (flag3=minus1) and (flag2=flag3)tempr=matching dict2[n][0]matching dict2[n]=[flag2]matching dict2[flag2]=[n]matching dict2[tempr]=[flag3]matching dict2[flag3]=[tempr]

elsefor k in adj dict3[n]

if not matching dict2[k]matching dict2[n]=[k]matching dict2[k]=[n]break

yo1=0for i in range(0num nodes)

if matching dict2[i] and [i]==matching dict2[matching dict2[i][0]]yo1=yo1+1

greedy size=yo12return greedy size

def General()

INPUTSwb = xlwtWorkbook()ws = wbadd sheet(Results Random)book=xlrdopen workbook(filenames randomxls)

48 Application

style0 = xlwteasyxf(fontbold on)style1 = xlwteasyxf(num format str=0000)INPUTSwswrite(0 0File style0)wswrite(0 1 Nodesstyle0)wswrite(0 2 Initial matchingstyle0)wswrite(0 3 NodesGstyle0)wswrite(0 4 EdgesGstyle0)wswrite(0 5 MaxDegreeGstyle0)wswrite(0 6 NodesG hatstyle0)wswrite(0 7 EdgesG Hatstyle0)wswrite(0 8 Useless edgesstyle0)wswrite(0 9 Forced edgesstyle0)wswrite(0 10 MaxDegreeG Hatstyle0)wswrite(0 11 Classical matchingstyle0)wswrite(0 12 Final matchingstyle0)wswrite(0 13 Greedy matchingstyle0)wswrite(0 14 Time classicalstyle0)wswrite(0 15 Time algorithmstyle0)wswrite(0 16 Time greedystyle0)wswrite(0 17 Perfect matching ratiostyle0)wswrite(0 18 Nodes ratiostyle0)wswrite(0 19 Edges ratiostyle0)wswrite(0 20 Matching ratiostyle0)

print nWelcomeThis is an implementation for general random graphs It uses Edmonds algorithm to compute maximum matching on G Hatn

for index in range (1481)was 481

if (index==482)f=open(Algotel generaltxtr)readlines()

elsefilea=str(booksheet by index(0)cell(index0))s=fileareplace(textu)replace()f=open(sr)readlines()Truewswrite(index 0 s)

print index

num nodes=int([xstrip()split() for x in f][0][0])

num matching=int([xstrip()split() for x in f][2][0])

adj temp = [xstrip()split() for x in f][44+num nodes]adj=[map(intR) for R in adj temp]

matching temp=[xstrip()split() for x in f][4+num nodes+14+2num nodes+1]matching1=[map(intR) for R in matching temp]

adj dict1=i[ii for iix in enumerate(L) if x] for iL in enumerate(adj)adj dict2=i[ii for iix in enumerate(L) if x] for iL in enumerate(adj)

Appendix A 49

adj dict3=i[ii for iix in enumerate(L) if x] for iL in enumerate(adj)

matching dict1=i[ii for iix in enumerate(L) if x] for iL in enumerate(matching1)matching dict2=i[ii for iix in enumerate(L) if x] for iL in enumerate(matching1)print adj dict2print matching dict2wswrite(index 1 num nodes)wswrite(index 2 num matching)

G = nxGraph()

useless= nxGraph()forced = nxGraph()

Fill Graphfor n in range(0num nodes)

for k in adj dict1[n]Gadd edge(nk)

Gt=Gnumber of edges()wswrite(index 3 Gnumber of nodes())wswrite(index 4 Gnumber of edges())wswrite(index 5 max(Gdegree()values()))

Compute Edmonds classical matching on G for comparison

startB = timeitdefault timer()Classical Matching=nxmax weight matching(G maxcardinality=False)stopB = timeitdefault timer()

Compute Gˆ nad MˆstartC = timeitdefault timer()useless edges(num nodesadj dict1matching dict1uselessadj dict2G)forced edges(Gadj dict2matching dict1num nodesforced)Final Matching=nxmax weight matching(G maxcardinality=False)stopC = timeitdefault timer()

GreedystartG = timeitdefault timer()greedy size=Greedy(num nodesadj dict3matching dict2)stopG = timeitdefault timer()

wswrite(index 6 Gnumber of nodes())wswrite(index 7 Gnumber of edges())wswrite(index 8 uselessnumber of edges())wswrite(index 9 forcednumber of edges())if Gdegree()values()

wswrite(index 10 max(Gdegree()values()))else

50 Application

wswrite(index 10 0)wswrite(index 11 len(Classical Matching)2)wswrite(index 12 len(Final Matching)2+forcednumber of edges())wswrite(index 13 greedy size)wswrite(index 14 stopB minus startBstyle1)wswrite(index 15 stopC minus startCstyle1)wswrite(index 16 stopG minus startGstyle1)wswrite(index 17 (len(Final Matching)2+forcednumber of edges())(num nodes2)style1)wswrite(index 18 Gnumber of nodes()Gtstyle1)wswrite(index 19 Gnumber of edges()Gtstyle1)wswrite(index 20 (len(Final Matching)2+forcednumber of edges())(len(Classical Matching)2)style1)

wbsave(AA Results Random Reyni Large Bipartitexls)

Main function Here we must choose the input form of the dataif name == main

startA = timeitdefault timer()General()stopA = timeitdefault timer()

print nThis program has terminatednnRunning time for 480 files stopAminusstartAprint nnPlease open AA Results Random Reyni Largexls file to see the Results

Appendix A 51

Plotmat

clear allclose allload(RN1Lmat)load(RN1Smat)load(RN2Lmat)load(RN2Smat)load(RN3Lmat)load(RN3Smat)

Plotsh(1)=figure(NameHistogram of Matching size difference between Constraint Algorithm and Greedy AlgorithmNumberTitleoff)

RN1L Greedydiff=RN1L Final matchingminusRN1L Greedy matchingRN2L Greedydiff=RN2L Final matchingminusRN2L Greedy matchingRN3L Greedydiff=RN3L Final matchingminusRN3L Greedy matchingRN1S Greedydiff=RN1S Final matchingminusRN1S Greedy matchingRN2S Greedydiff=RN2S Final matchingminusRN2S Greedy matchingRN3S Greedydiff=RN3S Final matchingminusRN3S Greedy matching

RN1L Finaldiff=RN1L Classical matchingminusRN1L Final matchingRN2L Finaldiff=RN2L Classical matchingminusRN2L Final matchingRN3L Finaldiff=RN3L Classical matchingminusRN3L Final matchingRN1S Finaldiff=RN1S Classical matchingminusRN1S Final matchingRN2S Finaldiff=RN2S Classical matchingminusRN2S Final matchingRN3S Finaldiff=RN3S Classical matchingminusRN3S Final matching

RN1L Classicaldiff=(RN1L Nodes2)minusRN1L Classical matchingRN2L Classicaldiff=(RN2L Nodes2)minusRN2L Classical matchingRN3L Classicaldiff=(RN3L Nodes2)minusRN3L Classical matchingRN1S Classicaldiff=(RN1S Nodes2)minusRN1S Classical matchingRN2S Classicaldiff=(RN2S Nodes2)minusRN2S Classical matchingRN3S Classicaldiff=(RN3S Nodes2)minusRN3S Classical matching

subplot(231)hold onhistf(RN1L Greedydiff0110facecolorbfacealpha9edgealpha1)histf(RN1L Finaldiff0110facecolorrfacealpha5edgealpha1)histf(RN1L Classicaldiff0110facecolorgfacealpha5edgealpha1)legalpha(ConminusGreClasminusConPerfminusClasslocationnortheast)legend boxoffaxis tightxlabel(edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN1L)grid on

subplot(232)hold onhistf(RN2L Greedydiff0110facecolorbfacealpha9edgealpha1)

52 Application

histf(RN2L Finaldiff0110facecolorrfacealpha5edgealpha1)histf(RN2L Classicaldiff0110facecolorgfacealpha5edgealpha1)legalpha(ConminusGreClasminusConPerfminusClasslocationnortheast)legend boxoffaxis tightxlabel(edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN2L)grid on

subplot(233)hold onhistf(RN3L Greedydiff0110facecolorbfacealpha5edgealpha1)histf(RN3L Finaldiff0110facecolorrfacealpha5edgealpha1)histf(RN3L Classicaldiff0110facecolorgfacealpha5edgealpha1)legalpha(ConminusGreClasminusConPerfminusClasslocationnortheast)legend boxoffaxis tightxlabel(edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN3L)grid on

subplot(234)hold onhistf(RN1S Greedydiff0110facecolorbfacealpha5edgealpha1)histf(RN1S Finaldiff0110facecolorrfacealpha5edgealpha1)histf(RN1S Classicaldiff0110facecolorgfacealpha5edgealpha1)legalpha(ConminusGreClasminusConPerfminusClasslocationnortheast)legend boxoffaxis tightxlabel(edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(R1NS)grid on

subplot(235)hold onhistf(RN2S Greedydiff0110facecolorbfacealpha5edgealpha1)histf(RN2S Finaldiff0110facecolorrfacealpha5edgealpha1)histf(RN2S Classicaldiff0110facecolorgfacealpha5edgealpha1)legalpha(ConminusGreClasminusConPerfminusClasslocationnortheast)legend boxoffaxis tightxlabel(edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN2S)grid on

subplot(236)hold onhistf(RN3S Greedydiff0110facecolorbfacealpha5edgealpha1)histf(RN3S Finaldiff0110facecolorrfacealpha5edgealpha1)histf(RN3S Classicaldiff0110facecolorgfacealpha5edgealpha1)

Appendix A 53

legalpha(ConminusGreClasminusConPerfminusClasslocationnortheast)legend boxoffaxis tightgrid ontitle(RN3S)xlabel(edges) xminusaxis labelylabel(instances) yminusaxis labelset(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN1png minusr300)h(2)=figure(NameHistogram of Max Degree of G AND G HatNumberTitleoff)RN1L x=RN1L MaxDegreeGminusRN1L MaxDegreeG HatRN2L x=RN2L MaxDegreeGminusRN2L MaxDegreeG HatRN3L x=RN3L MaxDegreeGminusRN3L MaxDegreeG HatRN1S x=RN1S MaxDegreeGminusRN1S MaxDegreeG HatRN2S x=RN2S MaxDegreeGminusRN2S MaxDegreeG HatRN3S x=RN3S MaxDegreeGminusRN3S MaxDegreeG Hatsubplot(231)hold onhistf(RN1L MaxDegreeG0150facecolorbfacealpha5edgealpha1)histf(RN1L MaxDegreeG Hat0150facecolorrfacealpha5edgealpha1)histf(RN1L x0150facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightxlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN1L)grid on

subplot(232)hold onhistf(RN2L MaxDegreeG010500facecolorbfacealpha5edgealpha1)histf(RN2L MaxDegreeG Hat010500facecolorrfacealpha5edgealpha1)histf(RN2L x010500facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightxlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN2L)grid on

subplot(233)hold onhistf(RN3L MaxDegreeG010300facecolorbfacealpha5edgealpha1)histf(RN3L MaxDegreeG Hat010300facecolorrfacealpha5edgealpha1)histf(RN3L x010300facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightxlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN3L)

54 Application

grid on

subplot(234)hold onhistf(RN1S MaxDegreeG0150facecolorbfacealpha5edgealpha1)histf(RN1S MaxDegreeG Hat0150facecolorrfacealpha5edgealpha1)histf(RN1S x0150facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightxlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(R1NS)grid on

subplot(235)hold onhistf(RN2S MaxDegreeG010500facecolorbfacealpha5edgealpha1)histf(RN2S MaxDegreeG Hat010500facecolorrfacealpha5edgealpha1)histf(RN2S x010500facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightxlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN2S)grid on

subplot(236)hold onhistf(RN3S MaxDegreeG05300facecolorbfacealpha5edgealpha1)histf(RN3S MaxDegreeG Hat05300facecolorrfacealpha5edgealpha1)histf(RN3S x05300facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightgrid ontitle(RN3S)xlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labelset(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN2png minusr300)

h(3)=figure(NameComputation time over edgesNumberTitleoff)

subplot(231)hold onstem(RN1L EdgesGRN1L Time classicalg)stem(RN1L EdgesGRN1L Time algorithmro)stem(RN1L EdgesGRN1L Time greedybx)grid on

Appendix A 55

title(RN1L)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)

subplot(232)hold onstem(RN2L EdgesGRN2L Time classicalg)stem(RN2L EdgesGRN2L Time algorithmro)stem(RN2L EdgesGRN2L Time greedybx)grid ontitle(RN2L)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)

subplot(233)hold onstem(RN3L EdgesGRN3L Time classicalg)stem(RN3L EdgesGRN3L Time algorithmro)stem(RN3L EdgesGRN3L Time greedybx)grid ontitle(RN3L)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)

subplot(234)hold onstem(RN1S EdgesGRN1S Time classicalg)stem(RN1S EdgesGRN1S Time algorithmro)stem(RN1S EdgesGRN1S Time greedybx)grid ontitle(RN1S)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)

subplot(235)hold onstem(RN2S EdgesGRN2S Time classicalg)stem(RN2S EdgesGRN2S Time algorithmro)stem(RN2S EdgesGRN2S Time greedybx)grid ontitle(RN2S)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)

subplot(236)hold onstem(RN3S EdgesGRN3S Time classicalg)stem(RN3S EdgesGRN3S Time algorithmro)stem(RN3S EdgesGRN3S Time greedybx)

56 Application

grid ontitle(RN3S)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)set(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN3png minusr300)

h(4)=figure(NameSorted matching sizeNumberTitleoff)RN1L Sorted matching temp(1)=RN1L Classical matchingRN1L Sorted matching temp(2)=RN1L Final matchingRN1L Sorted matching temp(3)=RN1L Greedy matchingRN1L Sorted matching temp(4)=RN1L Initial matchingRN1L Sorted matching=sortrows(RN1L Sorted matching temp)

RN2L Sorted matching temp(1)=RN2L Classical matchingRN2L Sorted matching temp(2)=RN2L Final matchingRN2L Sorted matching temp(3)=RN2L Greedy matchingRN2L Sorted matching temp(4)=RN2L Initial matchingRN2L Sorted matching=sortrows(RN2L Sorted matching temp)

RN3L Sorted matching temp(1)=RN3L Classical matchingRN3L Sorted matching temp(2)=RN3L Final matchingRN3L Sorted matching temp(3)=RN3L Greedy matchingRN3L Sorted matching temp(4)=RN3L Initial matchingRN3L Sorted matching=sortrows(RN3L Sorted matching temp)

RN1S Sorted matching temp(1)=RN1S Classical matchingRN1S Sorted matching temp(2)=RN1S Final matchingRN1S Sorted matching temp(3)=RN1S Greedy matchingRN1S Sorted matching temp(4)=RN1S Initial matchingRN1S Sorted matching=sortrows(RN1S Sorted matching temp)

RN2S Sorted matching temp(1)=RN2S Classical matchingRN2S Sorted matching temp(2)=RN2S Final matchingRN2S Sorted matching temp(3)=RN2S Greedy matchingRN2S Sorted matching temp(4)=RN2S Initial matchingRN2S Sorted matching=sortrows(RN2S Sorted matching temp)

RN3S Sorted matching temp(1)=RN3S Classical matchingRN3S Sorted matching temp(2)=RN3S Final matchingRN3S Sorted matching temp(3)=RN3S Greedy matchingRN3S Sorted matching temp(4)=RN3S Initial matchingRN3S Sorted matching=sortrows(RN3S Sorted matching temp)

subplot(231)hold onplot(RN1L Sorted matching(1)b)plot(RN1L Sorted matching(2)g)plot(RN1L Sorted matching(3)r)plot(RN1L Sorted matching(4)m)

Appendix A 57

grid ontitle(RN1L)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)

subplot(232)hold onplot(RN2L Sorted matching(1)b)plot(RN2L Sorted matching(2)g)plot(RN2L Sorted matching(3)r)plot(RN2L Sorted matching(4)m)grid ontitle(RN2L)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)

subplot(233)hold onplot(RN3L Sorted matching(1)b)plot(RN3L Sorted matching(2)g)plot(RN3L Sorted matching(3)r)plot(RN3L Sorted matching(4)m)grid ontitle(RN3L)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)

subplot(234)hold onplot(RN1S Sorted matching(1)b)plot(RN1S Sorted matching(2)g)plot(RN1S Sorted matching(3)r)plot(RN1S Sorted matching(4)m)grid ontitle(RN1S)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)

subplot(235)hold onplot(RN2S Sorted matching(1)b)plot(RN2S Sorted matching(2)g)plot(RN2S Sorted matching(3)r)plot(RN2S Sorted matching(4)m)grid ontitle(RN2S)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)

58 Application

subplot(236)hold onplot(RN3S Sorted matching(1)b)plot(RN3S Sorted matching(2)g)plot(RN3S Sorted matching(3)r)plot(RN3S Sorted matching(4)m)grid ontitle(RN3S)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)set(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN4png minusr300)h(5)=figure(NameSorted RatiosNumberTitleoff)RN1L ratio1=RN1L NodesG hatRN1L NodesGRN2L ratio1=RN2L NodesG hatRN2L NodesGRN3L ratio1=RN3L NodesG hatRN3L NodesGRN1S ratio1=RN1S NodesG hatRN1S NodesGRN2S ratio1=RN2S NodesG hatRN2S NodesGRN3S ratio1=RN3S NodesG hatRN3S NodesG

RN1L ratio2=RN1L EdgesG HatRN1L EdgesGRN2L ratio2=RN2L EdgesG HatRN2L EdgesGRN3L ratio2=RN3L EdgesG HatRN3L EdgesGRN1S ratio2=RN1S EdgesG HatRN1S EdgesGRN2S ratio2=RN2S EdgesG HatRN2S EdgesGRN3S ratio2=RN3S EdgesG HatRN3S EdgesG

RN1L ratio3=RN1L MaxDegreeG HatRN1L MaxDegreeGRN2L ratio3=RN2L MaxDegreeG HatRN2L MaxDegreeGRN3L ratio3=RN3L MaxDegreeG HatRN3L MaxDegreeGRN1S ratio3=RN1S MaxDegreeG HatRN1S MaxDegreeGRN2S ratio3=RN2S MaxDegreeG HatRN2S MaxDegreeGRN3S ratio3=RN3S MaxDegreeG HatRN3S MaxDegreeG

RN1L ratio(1)=RN1L ratio1RN1L ratio(2)=RN1L ratio2RN1L ratio(3)=RN1L ratio3

RN2L ratio(1)=RN2L ratio1RN2L ratio(2)=RN2L ratio2RN2L ratio(3)=RN2L ratio3

RN3L ratio(1)=RN3L ratio1RN3L ratio(2)=RN3L ratio2RN3L ratio(3)=RN3L ratio3

RN1S ratio(1)=RN1S ratio1RN1S ratio(2)=RN1S ratio2RN1S ratio(3)=RN1S ratio3

RN2S ratio(1)=RN2S ratio1

Appendix A 59

RN2S ratio(2)=RN2S ratio2RN2S ratio(3)=RN2S ratio3

RN3S ratio(1)=RN3S ratio1RN3S ratio(2)=RN3S ratio2RN3S ratio(3)=RN3S ratio3

RN1L ratio sorted=sortrows(RN1L ratio)RN2L ratio sorted=sortrows(RN2L ratio)RN3L ratio sorted=sortrows(RN3L ratio)RN1S ratio sorted=sortrows(RN1S ratio)RN2S ratio sorted=sortrows(RN2S ratio)RN3S ratio sorted=sortrows(RN3S ratio)

subplot(231)hold onplot(RN1L ratio sorted(1)b)plot(RN1L ratio sorted(2)g)plot(RN1L ratio sorted(3)r)grid ontitle(RN1L)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)

subplot(232)hold onplot(RN2L ratio sorted(1)b)plot(RN2L ratio sorted(2)g)plot(RN2L ratio sorted(3)r)grid ontitle(RN2L)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)

subplot(233)hold onplot(RN3L ratio sorted(1)b)plot(RN3L ratio sorted(2)g)plot(RN3L ratio sorted(3)r)grid ontitle(RN3L)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)

subplot(234)hold onplot(RN1S ratio sorted(1)b)plot(RN1S ratio sorted(2)g)plot(RN1S ratio sorted(3)r)grid on

60 Application

title(RN1S)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)

subplot(235)hold onplot(RN2S ratio sorted(1)b)plot(RN2S ratio sorted(2)g)plot(RN2S ratio sorted(3)r)grid ontitle(RN2S)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)

subplot(236)hold onplot(RN3S ratio sorted(1)b)plot(RN3S ratio sorted(2)g)plot(RN3S ratio sorted(3)r)grid ontitle(RN3S)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)set(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN5png minusr300)

h(6)=figure(NameSorted edges over nodesNumberTitleoff)

RN1L DegreeG1=(RN1L EdgesG)(RN1L NodesG)RN1L DegreeG Hat1=(RN1L EdgesG Hat)(RN1L NodesG hat)

RN1L Degree temp1(1)=RN1L DegreeG1RN1L Degree temp1(2)=RN1L DegreeG Hat1RN1L Degree sorted1=sortrows(RN1L Degree temp1)subplot(231)hold on

plot(RN1L Degree sorted1(1)b)plot(RN1L Degree sorted1(2)g)grid ontitle(RN1L)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)

RN2L DegreeG1=(RN2L EdgesG)(RN2L NodesG)RN2L DegreeG Hat1=(RN2L EdgesG Hat)(RN2L NodesG hat)

RN2L Degree temp1(1)=RN2L DegreeG1

Appendix A 61

RN2L Degree temp1(2)=RN2L DegreeG Hat1RN2L Degree sorted1=sortrows(RN2L Degree temp1)

subplot(232)hold onplot(RN2L Degree sorted1(1)b)plot(RN2L Degree sorted1(2)g)grid ontitle(RN2L)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)

RN3L DegreeG1=(RN3L EdgesG)(RN3L NodesG)RN3L DegreeG Hat1=(RN3L EdgesG Hat)(RN3L NodesG hat)

RN3L Degree temp1(1)=RN3L DegreeG1RN3L Degree temp1(2)=RN3L DegreeG Hat1RN3L Degree sorted1=sortrows(RN3L Degree temp1)

subplot(233)hold onplot(RN3L Degree sorted1(1)b)plot(RN3L Degree sorted1(2)g)grid ontitle(RN3L)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)

RN1S DegreeG1=(RN1S EdgesG)(RN1S NodesG)RN1S DegreeG Hat1=(RN1S EdgesG Hat)(RN1S NodesG hat)

RN1S Degree temp1(1)=RN1S DegreeG1RN1S Degree temp1(2)=RN1S DegreeG Hat1RN1S Degree sorted1=sortrows(RN1S Degree temp1)

subplot(234)hold onplot(RN1S Degree sorted1(1)b)plot(RN1S Degree sorted1(2)g)grid ontitle(RN1S)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)

RN2S DegreeG1=(RN2S EdgesG)(RN2S NodesG)RN2S DegreeG Hat1=(RN2S EdgesG Hat)(RN2S NodesG hat)

RN2S Degree temp1(1)=RN2S DegreeG1

62 Application

RN2S Degree temp1(2)=RN2S DegreeG Hat1RN2S Degree sorted1=sortrows(RN2S Degree temp1)

subplot(235)hold onplot(RN2S Degree sorted1(1)b)plot(RN2S Degree sorted1(2)g)grid ontitle(RN2S)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)

RN3S DegreeG1=(RN3S EdgesG)(RN3S NodesG)RN3S DegreeG Hat1=(RN3S EdgesG Hat)(RN3S NodesG hat)

RN3S Degree temp1(1)=RN3S DegreeG1RN3S Degree temp1(2)=RN3S DegreeG Hat1RN3S Degree sorted1=sortrows(RN3S Degree temp1)

subplot(236)hold onplot(RN3S Degree sorted1(1)b)plot(RN3S Degree sorted1(2)g)grid ontitle(RN3S)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)set(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN6png minusr300)h(7)=figure(NameSorted mATCHED DEGREENumberTitleoff)RN1L ratioMax(1)=RN1L MaxDegreeGRN1L ratioMax(2)=RN1L MaxDegreeG Hat

RN1L ratio sortedMax=sortrows(RN1L ratioMax)subplot(231)hold onplot(RN1L ratio sortedMax(1)b)plot(RN1L ratio sortedMax(2)g)grid ontitle(RN1L)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)

RN2L ratioMax(1)=RN2L MaxDegreeGRN2L ratioMax(2)=RN2L MaxDegreeG Hat

RN2L ratio sortedMax=sortrows(RN2L ratioMax)subplot(232)

Appendix A 63

hold onplot(RN2L ratio sortedMax(1)b)plot(RN2L ratio sortedMax(2)g)grid ontitle(RN2L)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)

RN3L ratioMax(1)=RN3L MaxDegreeGRN3L ratioMax(2)=RN3L MaxDegreeG Hat

RN3L ratio sortedMax=sortrows(RN3L ratioMax)subplot(233)hold onplot(RN3L ratio sortedMax(1)b)plot(RN3L ratio sortedMax(2)g)grid ontitle(RN3L)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)

RN1S ratioMax(1)=RN1S MaxDegreeGRN1S ratioMax(2)=RN1S MaxDegreeG Hat

RN1S ratio sortedMax=sortrows(RN1S ratioMax)subplot(234)hold onplot(RN1S ratio sortedMax(1)b)plot(RN1S ratio sortedMax(2)g)grid ontitle(RN1S)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)

RN2S ratioMax(1)=RN2S MaxDegreeGRN2S ratioMax(2)=RN2S MaxDegreeG Hat

RN2S ratio sortedMax=sortrows(RN2S ratioMax)

subplot(235)hold onplot(RN2S ratio sortedMax(1)b)plot(RN2S ratio sortedMax(2)g)grid ontitle(RN2S)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)

RN3S ratioMax(1)=RN3S MaxDegreeGRN3S ratioMax(2)=RN3S MaxDegreeG Hat

64 Application

RN3S ratio sortedMax=sortrows(RN3S ratioMax)subplot(236)hold onplot(RN3S ratio sortedMax(1)b)plot(RN3S ratio sortedMax(2)g)grid ontitle(RN1L)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)set(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN7png minusr300)

tilefigs()(h)

Bibliography

[1] C Berge ldquoTWO THEOREMS IN GRAPH THEORYrdquo Proceedings of the NationalAcademy of Sciences of the United States of America vol 43 no 9 pp 842ndash844Sep 1957

[2] L Bui S Sanghavi and R Srikant ldquoDistributed link scheduling with constantoverheadrdquo IEEEACM Trans Netw vol 17 no 5 pp 1467ndash1480 2009

[3] R Duan and S Pettie ldquoLinear-time approximation for maximum weight matchingrdquoJ ACM vol 61 no 1 2014

[4] J Edmonds ldquoPaths trees and flowersrdquo Canadian Journal of Mathematics vol 17pp 449ndash467 1965

[5] J E Hopcroft and R M Karp ldquoAn n52 algorithm for maximum matchings inbipartite graphsrdquo SIAM J Comput vol 2 no 4 pp 225ndash231 1973

[6] S Micali and V V Vazirani ldquoAn O(radic|V ||E|) algorithm for finding maximum

matching in general graphsrdquo in 21st Symp on Foundations of Comp Sc (FOCS)IEEE 1980 pp 17ndash27

[7] N Nisse A Salch and V Weber ldquoRecovery of disrupted airline operationsrdquo 2015httphalinriafrSomething

[8] X Wu and R Srikant ldquoRegulated maximal matching A distributed schedulingalgorithm for multi-hop wireless networks with nodeexclusive spectrum sharingrdquo inIEEE Conf on Decision and Control 2005

65

  • Contents
  • Introduction
  • Algorithms
    • Maximum matching
    • k-maximum matching
      • k-matching for Airport Slot assignment
      • The case where k=3
      • The case of Paths
      • The case of the Spider
          • Application
            • Description
            • Reyni Erdos
            • Barabaacutesi Albert
            • Amadeus Graphs
            • Bipartite
            • Bipartite with degree seq
            • Appendix A
              • BipartiteGraphGeneratorpy
              • RandomGraphGeneratorpy
              • kequals3MaximumMatchingpy
              • Plotmat
                  • Bibliography
Page 15: Theodoros Alexandros KARAGKIOULES -  · Introduction This work is the result of a 6 months internship, under the supervision of research O cer Nicolas NISSE. The original scope of

16 Application

bull For larger initial matching we observe the difference in the ∆s of G and G giventhe removed forced edges( and their endpoints) At some cases the ∆ of G dropsto 0 since the vast majority of edges have been declared forced and removed alongwith their endpoints

bull For smaller initial matching the ∆s of G and G follow mostly the same trend onlya few number of different instances

23 Barabasi Albert

Graph characteristics Barabasi Albert

bull BAxy are randomly generated graphs with a fixed number of 1000 nodes

bull There are 6 categories based on ini matching and of attached edges m

bull x = L S L When the initial matching is large and S when it is small

bull y = 1 2 3 1 when m = [1 10] 2 when m = [20 50] and 3 m = [50 100]

Computation time over |E|

23 Barabasi Albert 17

Computation time over |E| - Comments

bull When the initial matching is sufficiently large then the forced edges are taken out(a process which takes a fragment of the computation time) and then the classicalmatching algorithm (Edmonds) is applied on a smaller graph(G) This reducessignificantly the computation time

bull When the initial matching is small then the computation time of the constraintalgorithm might be larger than that of Edmonds The reason is that the constraintalgorithm need some time to compute the useless and forced edges and thenEdmonds algorithm is applied on G G Thus the overall processing time issometimes larger

Sorted matching size

18 Application

Sorted matching size-Comments

bull In this graph the matching size of the classical algorithm is depicted in ascendingorder along with the corresponding constraint algorithm and greedy result

bull Here in the case where m is small for both cases of initial matching (small large)the result may vary greatly starting from a value of half the perfect matching withsmall differences between the results of the various algorithm implementations

bull For the other cases of m the results converge

bull This is explained as for small values of m the graph is disconnected

bull In the matching size difference set of figures a very noticing difference value ap-pears For the cases of small m( the number of existing nodes that a new node isconnected to at the creation of the graph) we can see that the difference in the

23 Barabasi Albert 19

matching size compared to that of the perfect matching could be up to 40 ofthat of the matching size So there are occasions where the matching size is 200edges when the perfect matching would have been 500

bull the difference between the Constraint matching and the classical matching andthe difference of the constraint matching and that of the greedy matching do notshow significant values

Sorted Ratios

Sorted Ratio s -Comments

bull This set of figures depicts the ratios VV

EE

∆∆

in ascending order of VV

20 Application

bull It is evident that when the initial matching is large the amount of forced edges(and their endpoints) removed is high thus the ratio of Nodes and edges is verylow For higher probabilities almost all edges are removed as useless

bull For a smaller initial matching almost no forced edges (and their endpoints) areremoved which we conclude be the node ration being close to 1 There is somesmall amount of useless edges removed though since the ratio of edges is less butclose to 1

bull The ratio of ∆ for large initial matching follows the trend of the node ratio yetfor smaller initial matching it deviates significantly

Sorted |E||V |

23 Barabasi Albert 21

Sorted |E||V | - Comments

bull Although as graph density the ratio 2|E||V |(|V |minus1)

is considered in this set of figures

we evaluate the correlation of the ratio |E||V | of G and G since the density of G

could acquire values higher than that of G

bull The figures are calculated in ascending order for the ratio of G

bull For the case of large initial matching the two ratios for G and G remain almostconstant ( to the extent of the edge attraction m of each graph) since removingforced edges( and their endpoints) alters the |E| and |V | proportionately

bull For the case of small initial matching we observe some deviation in the valuesof the ration for G and that is explained with the removal of only useless edgeswhich only alters the |E| and keeps |V | in the original values

Sorted ∆

22 Application

Sorted ∆-Comments

bull In this set of figures the ascending order of the ∆ of G is associated with the ∆of G

bull There is a significant jump of the ∆ for each graph category which tells that thatwe are not comparing a uniform distribution of random graphs and based on theedge attraction m the graphs can vary in form

bull For larger initial matching we observe the difference in the ∆s of G and G giventhe removed forced edges( and their endpoints) At some cases the ∆ of G dropsto 0 since the vast majority of edges have been declared forced and removed alongwith their endpoints What is interesting is that the ∆ of G oscilates within stablelimits

24 Amadeus Graphs 23

bull For smaller initial matching the ∆s of G and G follow mostly the same trend onlya few number of different instances

24 Amadeus Graphs

Graph characteristics Amadeus graphs

bull These are the bipartite graphs provided by Amadeus

Computation time over |E|

Computation time over |E| - Comments

24 Application

bull For every instance the computation time of the classical algorithm is always smallerto that of the constraint matching

bull This allows as to speculate that we always compute a smaller G which also impliesthat we always find a set of forced edges and useless

Sorted matching size

Sorted matching size - Comments

bull Size of matching has an upward trend since the magnitude of the graphs is notthe same for the 160 instances

bull No significant deviation is noticed as per the first graph

24 Amadeus Graphs 25

bull Except from deviation from the perfect matching (number of flights) where some-times it could get up to 40

bull For the Amadeus Bipartite graphs we can see that the difference of the Classicaland the constraint implementation is not more than 1 edge in the matching

bull There appears to be a difference of up to 24 edges between the Classical matchingand the Perfect matching which is computed as the number of flights

bull The greedy algorithm performs well with only a few instances deviating slightlyform the Constraint algorithm result

Sorted Ratios

Sorted Ratios - Comments

26 Application

bull

Sorted |E||V |

Sorted |E||V | - Comments

bull Density of the graphs shows that on average we have 25-3 available time slot perflight

bull The line for the same value for G shows that there is a large deviation for everyinstance which allows for the hypothesis that the amount of useless+forced edgesof G has no obvious correlation to that of G

25 Bipartite 27

Sorted ∆

Sorted ∆-Comments

bull As per the previous related graphs for ∆ there is in significant drop in the ∆ of Gand G

25 Bipartite

Graph characteristics Bipartite random Graphs

bull BIPxy are randomly generated graphs with a fixed number of 1000(n=500 andm=500) nodes

bull There are 6 categories based on ini matching and probability p

28 Application

bull Probability p has been chosen as such in order to simulate the |E||V | 25 of theAmadeus bipartite graphs

bull So in order to have about 2-4 edges for every node we choose accordingly theprobability p to choose one of the n lowastm possible edges

bull x = L S L When the initial matching is large and S when it is small

bull y = 1 2 3 1 when p = 18250

2 when p = 25250

and 3 when p = 34250

Computation time over

Computation time overedges-Comments

bull

25 Bipartite 29

Sorted matching size

Sorted matching size-Comments

bull In these set of graphs one can instantly notice that only a few instances with highprobability can reach a matching size equal to the perfect matching

bull For the case of the initial matching we witness that there is a gap between the lineof the classical matching and those of the constraint and greedy results suggestingsmaller matching sizes of 10-40 edges

bull For the case of the small initial matching the result of the constraint matchingis now close to the result of the classical matching yet the greedy algorithm stillshows a relevantly big difference

30 Application

bull In this set of bipartite graphs we can witness that the result of the Constraintmatching shows a difference with the classical matching when the initial matchingis large The difference is smaller as the probability gets larger

bull For the case of the small initial matching the above phenomenom does not occuryet the greedy results deviates from that of the constraint matching

bull As per the pefrect matching compared to the classical matching a difference of5-10 edges is evident at almost all cases

Sorted Ratios

Sorted Ratios-Comments

bull Great max degree deviation

25 Bipartite 31

bull Regardless of the probability the ration of nodes and edges seems to have similarbehaviour when compared to the respective graphs of the same matching scale

bull Same gap between nodes ration and edges ration for all cases

Sorted |E||V |

Sorted |E||V | - Comments

bull In these set of figures we witness that the |E||V | acquires values relevant to those ofthe amadeus graphs The random graphs were constructed to depict this similarity

bull For smaller initial matching the ratios for G and G show the same upward trendand also they acquire closer values It represents the decrease of the averagenumber of forced edges in comparison to the larger matching cases

32 Application

Sorted ∆

Sorted ∆-Comments

bull ∆ acquires the same min and max values for each probability case (expected)

bull Gap in the case of large initial matching

26 Bipartite with degree seq

Graph characteristics

bull DEQBIPxy are randomly generated graphs based on three different types of degreedistribution of the Amadeus graphs

26 Bipartite with degree seq 33

bull There are 6 categories based on ini matching and degree distribution

bull x = L S L When the initial matching is large and S when it is small

bull y = 1 2 3 1 when degree distribution is based on file 2 when degree distributionis based on file and 3 when degree distribution is based on file

Computation time over

34 Application

Computation time overedges-Comments

bull Greedy algorithm takes minimum amount of time

bull The smaller the initial matching the more smaller the difference in comoutationtime of Constraint and classical algorithm

bull Due to preprocessing and the fact that G and G are the almost identical thetotal time needed to apply the constraint algorithm is in some cases bigger

Sorted matching size

26 Bipartite with degree seq 35

Sorted matching size-Comments

bull Classical matching is equal to perfect matching in every case

bull Constraint and greedy have identical behaviour

bull The larger the spectrum of the degree sequence the more efficient the matching

Sorted Ratios

36 Application

Sorted Ratios-Comments

bull With large initial matching most of the edges are considenred uselles or forced andare removed thus the ratio is close(if not equal to) zero

bull For small matching and large degree sequence sectrum hte max degree remainsthe same Only a few forced edges (and their nodes) are removed apparently nonodes with max degree

Sorted |E||V |

26 Bipartite with degree seq 37

Sorted |E||V | - Comments

bull In these set of figures we witness that the |E||V | acquires values relevant to those ofthe amadeus graphs The random graphs were constructed to depict this similarity

bull For smaller initial matching the ratios for G and G show the same upward trendand also they acquire closer values It repsresent the decrease of the averagenumber of forced edges in comparison to the larger matching cases

Sorted ∆

38 Application

Sorted ∆-Comments

bull Big difference in max degree in large initial matching

bull Almost identical behaviour in the case of small initial matching

Appendix A 39

Appendix A

BipartiteGraphGeneratorpy

from future import divisionimport networkx as nx

from networkxalgorithms import approximationimport collectionsimport randomimport mathfrom networkxalgorithms import bipartiteif name == main

for i in range(1481)waqs 481index=1n=randomrandint(100 1000)

n1=95 was 500me1=118

n2=251 was 500me2=903

n3=165 was 500me3=412

m=0m1=0p=randomrandom()p1=18250p2=25250p3=34250print ip=05t1=randomrandint(0 1)print im2=randomrandint(n2minus1 n2+1)G = nxGraph()ma = nxGraph()

aseq1=[1 2 3 4 5 3]

bseq1=[4 3 3 1 2 2 1]

aseq2=[16 14 14 14 12 11]bseq2=[0 0 0 0 0 0]

aseq3=[8 7 8 8 8 8]bseq3=[0 0 0 0 0 0]

40 Application

print Gnumber of edges()if ilt=160

G=bipartiteconfiguration model(aseq1 bseq1 create using=None seed=None)A=nxadjacency matrix(G)for ii in range(0n1+me1)

maadd node(ii)A=[Rtodense()tolist()[0] for R in A]

printnummanumber of nodes()rl=randomsample(range(0n1+me1) n1+me1)m=0done vertices = set()for p in rlprintin fordone verticesadd(p)

neighbors = []list()for iii in range(0n1+me1)

if A[p][iii]==1neighborsappend(iii)

randomshuffle(neighbors)continue loop = Truedegree = len(neighbors)

print degreej = 0p4=randomrandom()while continue loop and (jltdegree)print in loop

next = neighbors[j]if next not in done vertices and p not in done vertices

done verticesadd(p)done verticesadd(next)if p4gt=07print added edge

maadd edge(pnext)m=m+1

continue loop = Falsej += 1

print matching listOfedgeprint maedge

MA=nxadjacency matrix(ma)print MA

MA=[Rtodense()tolist()[0] for R in MA]print MA

B=[ join(map(strR)) for R in A]MB=[ join(map(strR)) for R in MA]

C=njoin(B)+nMC=njoin(MB)+n

print nprint mprint m1

filea=str(i)+txtwith open(fileaw) as f

Appendix A 41

fwrite(str(n1+me1))fwrite(n)fwrite(str(n1+me1))fwrite(n)fwrite(str(m))fwrite(n)fwrite(n)fwrite(C)fwrite(n)fwrite(MC)

elif igt160 and ilt321G=bipartiteconfiguration model(aseq2 bseq2 create using=None seed=None)A=nxadjacency matrix(G)for ii in range(0n2+me2)

maadd node(ii)A=[Rtodense()tolist()[0] for R in A]

printnummanumber of nodes()rl=randomsample(range(0n2+me2) n2+me2)m=0done vertices = set()for p in rlprintin fordone verticesadd(p)

neighbors = []list()for iii in range(0n2+me2)

if A[p][iii]==1neighborsappend(iii)

randomshuffle(neighbors)continue loop = Truedegree = len(neighbors)

print degreej = 0p4=randomrandom()while continue loop and (jltdegree)

print in loopnext = neighbors[j]if next not in done vertices and p not in done vertices

done verticesadd(p)done verticesadd(next)if p4gt=07

print added edgemaadd edge(pnext)m=m+1

continue loop = Falsej += 1

print matching listOfedgeprint maedge

MA=nxadjacency matrix(ma)print MA

MA=[Rtodense()tolist()[0] for R in MA]print MA

B=[ join(map(strR)) for R in A]MB=[ join(map(strR)) for R in MA]

42 Application

C=njoin(B)+nMC=njoin(MB)+n

print nprint mprint m1

filea=str(i)+txtwith open(fileaw) as f

fwrite(str(n2+me2))fwrite(n)fwrite(str(n2+me2))fwrite(n)fwrite(str(m))fwrite(n)fwrite(n)fwrite(C)fwrite(n)fwrite(MC)

elseG=bipartiteconfiguration model(aseq3 bseq3 create using=None seed=None)A=nxadjacency matrix(G)for ii in range(0n3+me3)

maadd node(ii)A=[Rtodense()tolist()[0] for R in A]

printnummanumber of nodes()rl=randomsample(range(0n3+me3) n3+me3)m=0done vertices = set()for p in rlprintin fordone verticesadd(p)

neighbors = []list()for iii in range(0n3+me3)

if A[p][iii]==1neighborsappend(iii)

randomshuffle(neighbors)continue loop = Truedegree = len(neighbors)

print degreej = 0p4=randomrandom()while continue loop and (jltdegree)

print in loopnext = neighbors[j]if next not in done vertices and p not in done vertices

done verticesadd(p)done verticesadd(next)if p4gt=07print added edge

maadd edge(pnext)m=m+1

continue loop = Falsej += 1

Appendix A 43

print matching listOfedgeprint maedge

MA=nxadjacency matrix(ma)print MA

MA=[Rtodense()tolist()[0] for R in MA]print MA

B=[ join(map(strR)) for R in A]MB=[ join(map(strR)) for R in MA]

C=njoin(B)+nMC=njoin(MB)+n

print nprint mprint m1

filea=str(i)+txtwith open(fileaw) as f

fwrite(str(n3+me3))fwrite(n)fwrite(str(n3+me3))fwrite(n)fwrite(str(m))fwrite(n)fwrite(n)fwrite(C)fwrite(n)fwrite(MC)

print nRandom graphs with random matching have been generated

44 Application

RandomGraphGeneratorpy

from future import divisionimport networkx as nxfrom networkxalgorithms import approximationimport collectionsimport randomimport mathif name == main

for i in range(1481)index=1n=randomrandint(100 1000)

n=1000m=0m1=0p=randomrandom()p1=mathlog(n2)np2=13p3=mathlog(n2)n+01p=05t1=randomrandint(0 1)print im2=randomrandint(n2minus1 n2+1)G = nxGraph()ma = nxGraph()print nme1=randomrandint(1 10)me2=randomrandint(2050)me3=randomrandint(50100)if ilt241

if ilt=80G=nxfast gnp random graph(n p1 seed=None directed=False)

elif igt80 and ilt161G=nxfast gnp random graph(n p2 seed=None directed=False)

elseG=nxfast gnp random graph(n p3 seed=None directed=False)

elseif ilt=320

G=nxbarabasi albert graph(n me1 seed=None)elif igt320 and ilt401

G=nxbarabasi albert graph(n me2 seed=None)else

G=nxbarabasi albert graph(n me3 seed=None)A=nxadjacency matrix(G)for ii in range(0n)

maadd node(ii)A=[Rtodense()tolist()[0] for R in A]

rl=randomsample(range(0n) n)m=0

Appendix A 45

done vertices = set()for p in rl

done verticesadd(p)neighbors = []list()for iii in range(0n)

if A[p][iii]==1neighborsappend(iii)

randomshuffle(neighbors)continue loop = Truedegree = len(neighbors)j = 0p2=randomrandom()while continue loop and (jltdegree)

next = neighbors[j]if next not in done vertices and p not in done vertices

done verticesadd(p)done verticesadd(next)if p2gt=00 Larger probability for smaller initial matching

maadd edge(pnext)m=m+1

continue loop = Falsej += 1

print matching listOfedgeprint maedgeMA=nxadjacency matrix(ma)MA=[Rtodense()tolist()[0] for R in MA]print MAB=[ join(map(strR)) for R in A]MB=[ join(map(strR)) for R in MA]

C=njoin(B)+nMC=njoin(MB)+nprint MCprint nprint mprint m1filea=str(i)+txtwith open(fileaw) as f

fwrite(str(n))fwrite(n)fwrite(str(n))fwrite(n)fwrite(str(m))fwrite(n)fwrite(n)fwrite(C)fwrite(n)fwrite(MC)

print nRandom graphs with random matching have been generated

46 Application

kequals3MaximumMatchingpy

from future import divisionimport networkx as nxfrom networkxalgorithms import bipartiteimport matplotlibpyplot as pltimport collectionsimport timeitimport xlwtimport xlrdimport mathimport sys

Case for General Graphsdef forced edges(Gadj dict2matching dict1num nodesforced)

flagg=0for n in range(0num nodes)

for k in adj dict2[n]if ([k]==matching dict1[n])

count=0for l in range(0num nodes)

count=count+adj dict2[l]count(k)if (len(adj dict2[n])==1) or (count==1)

forcedadd edge(nk)Gremove edge(nk)Gremove node(n)Gremove node(k)printforced edgenktemp=kflagg=1for m in range (len(adj dict2[n])minus1minus1minus1)

adj dict2[adj dict2[n][m]]remove(n)adj dict2[n]remove(adj dict2[n][m])

if adj dict2[temp]for l in range(len(adj dict2[temp])minus1minus1minus1)

if (adj dict2[temp][l]=n)adj dict2[adj dict2[temp][l]]remove(temp)adj dict2[temp]remove(adj dict2[temp][l])

break

def useless edges(num nodesadj dict1matching dict1uselessadj dict2G)for n in range(0num nodes)

for k in adj dict1[n]if ([k]=matching dict1[n]) and matching dict1[n] and matching dict1[k]

uselessadd edge(nk)Gremove edge(n k)

Appendix A 47

tempa=kadj dict2[n]remove(k)adj dict2[tempa]remove(n)adj dict1[tempa]remove(n)

return G

def Greedy(num nodesadj dict3matching dict2)

for n in range(0num nodes)if matching dict2[n]

flag2=minus1flag3=minus1for v in adj dict3[n]

if not matching dict2[v]flag2=vbreak

for p in adj dict3[matching dict2[n][0]]if not matching dict2[p]

flag3=pbreak

if (flag2=minus1) and (flag3=minus1) and (flag2=flag3)tempr=matching dict2[n][0]matching dict2[n]=[flag2]matching dict2[flag2]=[n]matching dict2[tempr]=[flag3]matching dict2[flag3]=[tempr]

elsefor k in adj dict3[n]

if not matching dict2[k]matching dict2[n]=[k]matching dict2[k]=[n]break

yo1=0for i in range(0num nodes)

if matching dict2[i] and [i]==matching dict2[matching dict2[i][0]]yo1=yo1+1

greedy size=yo12return greedy size

def General()

INPUTSwb = xlwtWorkbook()ws = wbadd sheet(Results Random)book=xlrdopen workbook(filenames randomxls)

48 Application

style0 = xlwteasyxf(fontbold on)style1 = xlwteasyxf(num format str=0000)INPUTSwswrite(0 0File style0)wswrite(0 1 Nodesstyle0)wswrite(0 2 Initial matchingstyle0)wswrite(0 3 NodesGstyle0)wswrite(0 4 EdgesGstyle0)wswrite(0 5 MaxDegreeGstyle0)wswrite(0 6 NodesG hatstyle0)wswrite(0 7 EdgesG Hatstyle0)wswrite(0 8 Useless edgesstyle0)wswrite(0 9 Forced edgesstyle0)wswrite(0 10 MaxDegreeG Hatstyle0)wswrite(0 11 Classical matchingstyle0)wswrite(0 12 Final matchingstyle0)wswrite(0 13 Greedy matchingstyle0)wswrite(0 14 Time classicalstyle0)wswrite(0 15 Time algorithmstyle0)wswrite(0 16 Time greedystyle0)wswrite(0 17 Perfect matching ratiostyle0)wswrite(0 18 Nodes ratiostyle0)wswrite(0 19 Edges ratiostyle0)wswrite(0 20 Matching ratiostyle0)

print nWelcomeThis is an implementation for general random graphs It uses Edmonds algorithm to compute maximum matching on G Hatn

for index in range (1481)was 481

if (index==482)f=open(Algotel generaltxtr)readlines()

elsefilea=str(booksheet by index(0)cell(index0))s=fileareplace(textu)replace()f=open(sr)readlines()Truewswrite(index 0 s)

print index

num nodes=int([xstrip()split() for x in f][0][0])

num matching=int([xstrip()split() for x in f][2][0])

adj temp = [xstrip()split() for x in f][44+num nodes]adj=[map(intR) for R in adj temp]

matching temp=[xstrip()split() for x in f][4+num nodes+14+2num nodes+1]matching1=[map(intR) for R in matching temp]

adj dict1=i[ii for iix in enumerate(L) if x] for iL in enumerate(adj)adj dict2=i[ii for iix in enumerate(L) if x] for iL in enumerate(adj)

Appendix A 49

adj dict3=i[ii for iix in enumerate(L) if x] for iL in enumerate(adj)

matching dict1=i[ii for iix in enumerate(L) if x] for iL in enumerate(matching1)matching dict2=i[ii for iix in enumerate(L) if x] for iL in enumerate(matching1)print adj dict2print matching dict2wswrite(index 1 num nodes)wswrite(index 2 num matching)

G = nxGraph()

useless= nxGraph()forced = nxGraph()

Fill Graphfor n in range(0num nodes)

for k in adj dict1[n]Gadd edge(nk)

Gt=Gnumber of edges()wswrite(index 3 Gnumber of nodes())wswrite(index 4 Gnumber of edges())wswrite(index 5 max(Gdegree()values()))

Compute Edmonds classical matching on G for comparison

startB = timeitdefault timer()Classical Matching=nxmax weight matching(G maxcardinality=False)stopB = timeitdefault timer()

Compute Gˆ nad MˆstartC = timeitdefault timer()useless edges(num nodesadj dict1matching dict1uselessadj dict2G)forced edges(Gadj dict2matching dict1num nodesforced)Final Matching=nxmax weight matching(G maxcardinality=False)stopC = timeitdefault timer()

GreedystartG = timeitdefault timer()greedy size=Greedy(num nodesadj dict3matching dict2)stopG = timeitdefault timer()

wswrite(index 6 Gnumber of nodes())wswrite(index 7 Gnumber of edges())wswrite(index 8 uselessnumber of edges())wswrite(index 9 forcednumber of edges())if Gdegree()values()

wswrite(index 10 max(Gdegree()values()))else

50 Application

wswrite(index 10 0)wswrite(index 11 len(Classical Matching)2)wswrite(index 12 len(Final Matching)2+forcednumber of edges())wswrite(index 13 greedy size)wswrite(index 14 stopB minus startBstyle1)wswrite(index 15 stopC minus startCstyle1)wswrite(index 16 stopG minus startGstyle1)wswrite(index 17 (len(Final Matching)2+forcednumber of edges())(num nodes2)style1)wswrite(index 18 Gnumber of nodes()Gtstyle1)wswrite(index 19 Gnumber of edges()Gtstyle1)wswrite(index 20 (len(Final Matching)2+forcednumber of edges())(len(Classical Matching)2)style1)

wbsave(AA Results Random Reyni Large Bipartitexls)

Main function Here we must choose the input form of the dataif name == main

startA = timeitdefault timer()General()stopA = timeitdefault timer()

print nThis program has terminatednnRunning time for 480 files stopAminusstartAprint nnPlease open AA Results Random Reyni Largexls file to see the Results

Appendix A 51

Plotmat

clear allclose allload(RN1Lmat)load(RN1Smat)load(RN2Lmat)load(RN2Smat)load(RN3Lmat)load(RN3Smat)

Plotsh(1)=figure(NameHistogram of Matching size difference between Constraint Algorithm and Greedy AlgorithmNumberTitleoff)

RN1L Greedydiff=RN1L Final matchingminusRN1L Greedy matchingRN2L Greedydiff=RN2L Final matchingminusRN2L Greedy matchingRN3L Greedydiff=RN3L Final matchingminusRN3L Greedy matchingRN1S Greedydiff=RN1S Final matchingminusRN1S Greedy matchingRN2S Greedydiff=RN2S Final matchingminusRN2S Greedy matchingRN3S Greedydiff=RN3S Final matchingminusRN3S Greedy matching

RN1L Finaldiff=RN1L Classical matchingminusRN1L Final matchingRN2L Finaldiff=RN2L Classical matchingminusRN2L Final matchingRN3L Finaldiff=RN3L Classical matchingminusRN3L Final matchingRN1S Finaldiff=RN1S Classical matchingminusRN1S Final matchingRN2S Finaldiff=RN2S Classical matchingminusRN2S Final matchingRN3S Finaldiff=RN3S Classical matchingminusRN3S Final matching

RN1L Classicaldiff=(RN1L Nodes2)minusRN1L Classical matchingRN2L Classicaldiff=(RN2L Nodes2)minusRN2L Classical matchingRN3L Classicaldiff=(RN3L Nodes2)minusRN3L Classical matchingRN1S Classicaldiff=(RN1S Nodes2)minusRN1S Classical matchingRN2S Classicaldiff=(RN2S Nodes2)minusRN2S Classical matchingRN3S Classicaldiff=(RN3S Nodes2)minusRN3S Classical matching

subplot(231)hold onhistf(RN1L Greedydiff0110facecolorbfacealpha9edgealpha1)histf(RN1L Finaldiff0110facecolorrfacealpha5edgealpha1)histf(RN1L Classicaldiff0110facecolorgfacealpha5edgealpha1)legalpha(ConminusGreClasminusConPerfminusClasslocationnortheast)legend boxoffaxis tightxlabel(edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN1L)grid on

subplot(232)hold onhistf(RN2L Greedydiff0110facecolorbfacealpha9edgealpha1)

52 Application

histf(RN2L Finaldiff0110facecolorrfacealpha5edgealpha1)histf(RN2L Classicaldiff0110facecolorgfacealpha5edgealpha1)legalpha(ConminusGreClasminusConPerfminusClasslocationnortheast)legend boxoffaxis tightxlabel(edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN2L)grid on

subplot(233)hold onhistf(RN3L Greedydiff0110facecolorbfacealpha5edgealpha1)histf(RN3L Finaldiff0110facecolorrfacealpha5edgealpha1)histf(RN3L Classicaldiff0110facecolorgfacealpha5edgealpha1)legalpha(ConminusGreClasminusConPerfminusClasslocationnortheast)legend boxoffaxis tightxlabel(edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN3L)grid on

subplot(234)hold onhistf(RN1S Greedydiff0110facecolorbfacealpha5edgealpha1)histf(RN1S Finaldiff0110facecolorrfacealpha5edgealpha1)histf(RN1S Classicaldiff0110facecolorgfacealpha5edgealpha1)legalpha(ConminusGreClasminusConPerfminusClasslocationnortheast)legend boxoffaxis tightxlabel(edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(R1NS)grid on

subplot(235)hold onhistf(RN2S Greedydiff0110facecolorbfacealpha5edgealpha1)histf(RN2S Finaldiff0110facecolorrfacealpha5edgealpha1)histf(RN2S Classicaldiff0110facecolorgfacealpha5edgealpha1)legalpha(ConminusGreClasminusConPerfminusClasslocationnortheast)legend boxoffaxis tightxlabel(edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN2S)grid on

subplot(236)hold onhistf(RN3S Greedydiff0110facecolorbfacealpha5edgealpha1)histf(RN3S Finaldiff0110facecolorrfacealpha5edgealpha1)histf(RN3S Classicaldiff0110facecolorgfacealpha5edgealpha1)

Appendix A 53

legalpha(ConminusGreClasminusConPerfminusClasslocationnortheast)legend boxoffaxis tightgrid ontitle(RN3S)xlabel(edges) xminusaxis labelylabel(instances) yminusaxis labelset(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN1png minusr300)h(2)=figure(NameHistogram of Max Degree of G AND G HatNumberTitleoff)RN1L x=RN1L MaxDegreeGminusRN1L MaxDegreeG HatRN2L x=RN2L MaxDegreeGminusRN2L MaxDegreeG HatRN3L x=RN3L MaxDegreeGminusRN3L MaxDegreeG HatRN1S x=RN1S MaxDegreeGminusRN1S MaxDegreeG HatRN2S x=RN2S MaxDegreeGminusRN2S MaxDegreeG HatRN3S x=RN3S MaxDegreeGminusRN3S MaxDegreeG Hatsubplot(231)hold onhistf(RN1L MaxDegreeG0150facecolorbfacealpha5edgealpha1)histf(RN1L MaxDegreeG Hat0150facecolorrfacealpha5edgealpha1)histf(RN1L x0150facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightxlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN1L)grid on

subplot(232)hold onhistf(RN2L MaxDegreeG010500facecolorbfacealpha5edgealpha1)histf(RN2L MaxDegreeG Hat010500facecolorrfacealpha5edgealpha1)histf(RN2L x010500facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightxlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN2L)grid on

subplot(233)hold onhistf(RN3L MaxDegreeG010300facecolorbfacealpha5edgealpha1)histf(RN3L MaxDegreeG Hat010300facecolorrfacealpha5edgealpha1)histf(RN3L x010300facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightxlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN3L)

54 Application

grid on

subplot(234)hold onhistf(RN1S MaxDegreeG0150facecolorbfacealpha5edgealpha1)histf(RN1S MaxDegreeG Hat0150facecolorrfacealpha5edgealpha1)histf(RN1S x0150facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightxlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(R1NS)grid on

subplot(235)hold onhistf(RN2S MaxDegreeG010500facecolorbfacealpha5edgealpha1)histf(RN2S MaxDegreeG Hat010500facecolorrfacealpha5edgealpha1)histf(RN2S x010500facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightxlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN2S)grid on

subplot(236)hold onhistf(RN3S MaxDegreeG05300facecolorbfacealpha5edgealpha1)histf(RN3S MaxDegreeG Hat05300facecolorrfacealpha5edgealpha1)histf(RN3S x05300facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightgrid ontitle(RN3S)xlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labelset(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN2png minusr300)

h(3)=figure(NameComputation time over edgesNumberTitleoff)

subplot(231)hold onstem(RN1L EdgesGRN1L Time classicalg)stem(RN1L EdgesGRN1L Time algorithmro)stem(RN1L EdgesGRN1L Time greedybx)grid on

Appendix A 55

title(RN1L)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)

subplot(232)hold onstem(RN2L EdgesGRN2L Time classicalg)stem(RN2L EdgesGRN2L Time algorithmro)stem(RN2L EdgesGRN2L Time greedybx)grid ontitle(RN2L)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)

subplot(233)hold onstem(RN3L EdgesGRN3L Time classicalg)stem(RN3L EdgesGRN3L Time algorithmro)stem(RN3L EdgesGRN3L Time greedybx)grid ontitle(RN3L)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)

subplot(234)hold onstem(RN1S EdgesGRN1S Time classicalg)stem(RN1S EdgesGRN1S Time algorithmro)stem(RN1S EdgesGRN1S Time greedybx)grid ontitle(RN1S)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)

subplot(235)hold onstem(RN2S EdgesGRN2S Time classicalg)stem(RN2S EdgesGRN2S Time algorithmro)stem(RN2S EdgesGRN2S Time greedybx)grid ontitle(RN2S)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)

subplot(236)hold onstem(RN3S EdgesGRN3S Time classicalg)stem(RN3S EdgesGRN3S Time algorithmro)stem(RN3S EdgesGRN3S Time greedybx)

56 Application

grid ontitle(RN3S)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)set(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN3png minusr300)

h(4)=figure(NameSorted matching sizeNumberTitleoff)RN1L Sorted matching temp(1)=RN1L Classical matchingRN1L Sorted matching temp(2)=RN1L Final matchingRN1L Sorted matching temp(3)=RN1L Greedy matchingRN1L Sorted matching temp(4)=RN1L Initial matchingRN1L Sorted matching=sortrows(RN1L Sorted matching temp)

RN2L Sorted matching temp(1)=RN2L Classical matchingRN2L Sorted matching temp(2)=RN2L Final matchingRN2L Sorted matching temp(3)=RN2L Greedy matchingRN2L Sorted matching temp(4)=RN2L Initial matchingRN2L Sorted matching=sortrows(RN2L Sorted matching temp)

RN3L Sorted matching temp(1)=RN3L Classical matchingRN3L Sorted matching temp(2)=RN3L Final matchingRN3L Sorted matching temp(3)=RN3L Greedy matchingRN3L Sorted matching temp(4)=RN3L Initial matchingRN3L Sorted matching=sortrows(RN3L Sorted matching temp)

RN1S Sorted matching temp(1)=RN1S Classical matchingRN1S Sorted matching temp(2)=RN1S Final matchingRN1S Sorted matching temp(3)=RN1S Greedy matchingRN1S Sorted matching temp(4)=RN1S Initial matchingRN1S Sorted matching=sortrows(RN1S Sorted matching temp)

RN2S Sorted matching temp(1)=RN2S Classical matchingRN2S Sorted matching temp(2)=RN2S Final matchingRN2S Sorted matching temp(3)=RN2S Greedy matchingRN2S Sorted matching temp(4)=RN2S Initial matchingRN2S Sorted matching=sortrows(RN2S Sorted matching temp)

RN3S Sorted matching temp(1)=RN3S Classical matchingRN3S Sorted matching temp(2)=RN3S Final matchingRN3S Sorted matching temp(3)=RN3S Greedy matchingRN3S Sorted matching temp(4)=RN3S Initial matchingRN3S Sorted matching=sortrows(RN3S Sorted matching temp)

subplot(231)hold onplot(RN1L Sorted matching(1)b)plot(RN1L Sorted matching(2)g)plot(RN1L Sorted matching(3)r)plot(RN1L Sorted matching(4)m)

Appendix A 57

grid ontitle(RN1L)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)

subplot(232)hold onplot(RN2L Sorted matching(1)b)plot(RN2L Sorted matching(2)g)plot(RN2L Sorted matching(3)r)plot(RN2L Sorted matching(4)m)grid ontitle(RN2L)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)

subplot(233)hold onplot(RN3L Sorted matching(1)b)plot(RN3L Sorted matching(2)g)plot(RN3L Sorted matching(3)r)plot(RN3L Sorted matching(4)m)grid ontitle(RN3L)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)

subplot(234)hold onplot(RN1S Sorted matching(1)b)plot(RN1S Sorted matching(2)g)plot(RN1S Sorted matching(3)r)plot(RN1S Sorted matching(4)m)grid ontitle(RN1S)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)

subplot(235)hold onplot(RN2S Sorted matching(1)b)plot(RN2S Sorted matching(2)g)plot(RN2S Sorted matching(3)r)plot(RN2S Sorted matching(4)m)grid ontitle(RN2S)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)

58 Application

subplot(236)hold onplot(RN3S Sorted matching(1)b)plot(RN3S Sorted matching(2)g)plot(RN3S Sorted matching(3)r)plot(RN3S Sorted matching(4)m)grid ontitle(RN3S)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)set(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN4png minusr300)h(5)=figure(NameSorted RatiosNumberTitleoff)RN1L ratio1=RN1L NodesG hatRN1L NodesGRN2L ratio1=RN2L NodesG hatRN2L NodesGRN3L ratio1=RN3L NodesG hatRN3L NodesGRN1S ratio1=RN1S NodesG hatRN1S NodesGRN2S ratio1=RN2S NodesG hatRN2S NodesGRN3S ratio1=RN3S NodesG hatRN3S NodesG

RN1L ratio2=RN1L EdgesG HatRN1L EdgesGRN2L ratio2=RN2L EdgesG HatRN2L EdgesGRN3L ratio2=RN3L EdgesG HatRN3L EdgesGRN1S ratio2=RN1S EdgesG HatRN1S EdgesGRN2S ratio2=RN2S EdgesG HatRN2S EdgesGRN3S ratio2=RN3S EdgesG HatRN3S EdgesG

RN1L ratio3=RN1L MaxDegreeG HatRN1L MaxDegreeGRN2L ratio3=RN2L MaxDegreeG HatRN2L MaxDegreeGRN3L ratio3=RN3L MaxDegreeG HatRN3L MaxDegreeGRN1S ratio3=RN1S MaxDegreeG HatRN1S MaxDegreeGRN2S ratio3=RN2S MaxDegreeG HatRN2S MaxDegreeGRN3S ratio3=RN3S MaxDegreeG HatRN3S MaxDegreeG

RN1L ratio(1)=RN1L ratio1RN1L ratio(2)=RN1L ratio2RN1L ratio(3)=RN1L ratio3

RN2L ratio(1)=RN2L ratio1RN2L ratio(2)=RN2L ratio2RN2L ratio(3)=RN2L ratio3

RN3L ratio(1)=RN3L ratio1RN3L ratio(2)=RN3L ratio2RN3L ratio(3)=RN3L ratio3

RN1S ratio(1)=RN1S ratio1RN1S ratio(2)=RN1S ratio2RN1S ratio(3)=RN1S ratio3

RN2S ratio(1)=RN2S ratio1

Appendix A 59

RN2S ratio(2)=RN2S ratio2RN2S ratio(3)=RN2S ratio3

RN3S ratio(1)=RN3S ratio1RN3S ratio(2)=RN3S ratio2RN3S ratio(3)=RN3S ratio3

RN1L ratio sorted=sortrows(RN1L ratio)RN2L ratio sorted=sortrows(RN2L ratio)RN3L ratio sorted=sortrows(RN3L ratio)RN1S ratio sorted=sortrows(RN1S ratio)RN2S ratio sorted=sortrows(RN2S ratio)RN3S ratio sorted=sortrows(RN3S ratio)

subplot(231)hold onplot(RN1L ratio sorted(1)b)plot(RN1L ratio sorted(2)g)plot(RN1L ratio sorted(3)r)grid ontitle(RN1L)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)

subplot(232)hold onplot(RN2L ratio sorted(1)b)plot(RN2L ratio sorted(2)g)plot(RN2L ratio sorted(3)r)grid ontitle(RN2L)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)

subplot(233)hold onplot(RN3L ratio sorted(1)b)plot(RN3L ratio sorted(2)g)plot(RN3L ratio sorted(3)r)grid ontitle(RN3L)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)

subplot(234)hold onplot(RN1S ratio sorted(1)b)plot(RN1S ratio sorted(2)g)plot(RN1S ratio sorted(3)r)grid on

60 Application

title(RN1S)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)

subplot(235)hold onplot(RN2S ratio sorted(1)b)plot(RN2S ratio sorted(2)g)plot(RN2S ratio sorted(3)r)grid ontitle(RN2S)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)

subplot(236)hold onplot(RN3S ratio sorted(1)b)plot(RN3S ratio sorted(2)g)plot(RN3S ratio sorted(3)r)grid ontitle(RN3S)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)set(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN5png minusr300)

h(6)=figure(NameSorted edges over nodesNumberTitleoff)

RN1L DegreeG1=(RN1L EdgesG)(RN1L NodesG)RN1L DegreeG Hat1=(RN1L EdgesG Hat)(RN1L NodesG hat)

RN1L Degree temp1(1)=RN1L DegreeG1RN1L Degree temp1(2)=RN1L DegreeG Hat1RN1L Degree sorted1=sortrows(RN1L Degree temp1)subplot(231)hold on

plot(RN1L Degree sorted1(1)b)plot(RN1L Degree sorted1(2)g)grid ontitle(RN1L)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)

RN2L DegreeG1=(RN2L EdgesG)(RN2L NodesG)RN2L DegreeG Hat1=(RN2L EdgesG Hat)(RN2L NodesG hat)

RN2L Degree temp1(1)=RN2L DegreeG1

Appendix A 61

RN2L Degree temp1(2)=RN2L DegreeG Hat1RN2L Degree sorted1=sortrows(RN2L Degree temp1)

subplot(232)hold onplot(RN2L Degree sorted1(1)b)plot(RN2L Degree sorted1(2)g)grid ontitle(RN2L)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)

RN3L DegreeG1=(RN3L EdgesG)(RN3L NodesG)RN3L DegreeG Hat1=(RN3L EdgesG Hat)(RN3L NodesG hat)

RN3L Degree temp1(1)=RN3L DegreeG1RN3L Degree temp1(2)=RN3L DegreeG Hat1RN3L Degree sorted1=sortrows(RN3L Degree temp1)

subplot(233)hold onplot(RN3L Degree sorted1(1)b)plot(RN3L Degree sorted1(2)g)grid ontitle(RN3L)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)

RN1S DegreeG1=(RN1S EdgesG)(RN1S NodesG)RN1S DegreeG Hat1=(RN1S EdgesG Hat)(RN1S NodesG hat)

RN1S Degree temp1(1)=RN1S DegreeG1RN1S Degree temp1(2)=RN1S DegreeG Hat1RN1S Degree sorted1=sortrows(RN1S Degree temp1)

subplot(234)hold onplot(RN1S Degree sorted1(1)b)plot(RN1S Degree sorted1(2)g)grid ontitle(RN1S)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)

RN2S DegreeG1=(RN2S EdgesG)(RN2S NodesG)RN2S DegreeG Hat1=(RN2S EdgesG Hat)(RN2S NodesG hat)

RN2S Degree temp1(1)=RN2S DegreeG1

62 Application

RN2S Degree temp1(2)=RN2S DegreeG Hat1RN2S Degree sorted1=sortrows(RN2S Degree temp1)

subplot(235)hold onplot(RN2S Degree sorted1(1)b)plot(RN2S Degree sorted1(2)g)grid ontitle(RN2S)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)

RN3S DegreeG1=(RN3S EdgesG)(RN3S NodesG)RN3S DegreeG Hat1=(RN3S EdgesG Hat)(RN3S NodesG hat)

RN3S Degree temp1(1)=RN3S DegreeG1RN3S Degree temp1(2)=RN3S DegreeG Hat1RN3S Degree sorted1=sortrows(RN3S Degree temp1)

subplot(236)hold onplot(RN3S Degree sorted1(1)b)plot(RN3S Degree sorted1(2)g)grid ontitle(RN3S)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)set(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN6png minusr300)h(7)=figure(NameSorted mATCHED DEGREENumberTitleoff)RN1L ratioMax(1)=RN1L MaxDegreeGRN1L ratioMax(2)=RN1L MaxDegreeG Hat

RN1L ratio sortedMax=sortrows(RN1L ratioMax)subplot(231)hold onplot(RN1L ratio sortedMax(1)b)plot(RN1L ratio sortedMax(2)g)grid ontitle(RN1L)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)

RN2L ratioMax(1)=RN2L MaxDegreeGRN2L ratioMax(2)=RN2L MaxDegreeG Hat

RN2L ratio sortedMax=sortrows(RN2L ratioMax)subplot(232)

Appendix A 63

hold onplot(RN2L ratio sortedMax(1)b)plot(RN2L ratio sortedMax(2)g)grid ontitle(RN2L)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)

RN3L ratioMax(1)=RN3L MaxDegreeGRN3L ratioMax(2)=RN3L MaxDegreeG Hat

RN3L ratio sortedMax=sortrows(RN3L ratioMax)subplot(233)hold onplot(RN3L ratio sortedMax(1)b)plot(RN3L ratio sortedMax(2)g)grid ontitle(RN3L)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)

RN1S ratioMax(1)=RN1S MaxDegreeGRN1S ratioMax(2)=RN1S MaxDegreeG Hat

RN1S ratio sortedMax=sortrows(RN1S ratioMax)subplot(234)hold onplot(RN1S ratio sortedMax(1)b)plot(RN1S ratio sortedMax(2)g)grid ontitle(RN1S)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)

RN2S ratioMax(1)=RN2S MaxDegreeGRN2S ratioMax(2)=RN2S MaxDegreeG Hat

RN2S ratio sortedMax=sortrows(RN2S ratioMax)

subplot(235)hold onplot(RN2S ratio sortedMax(1)b)plot(RN2S ratio sortedMax(2)g)grid ontitle(RN2S)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)

RN3S ratioMax(1)=RN3S MaxDegreeGRN3S ratioMax(2)=RN3S MaxDegreeG Hat

64 Application

RN3S ratio sortedMax=sortrows(RN3S ratioMax)subplot(236)hold onplot(RN3S ratio sortedMax(1)b)plot(RN3S ratio sortedMax(2)g)grid ontitle(RN1L)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)set(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN7png minusr300)

tilefigs()(h)

Bibliography

[1] C Berge ldquoTWO THEOREMS IN GRAPH THEORYrdquo Proceedings of the NationalAcademy of Sciences of the United States of America vol 43 no 9 pp 842ndash844Sep 1957

[2] L Bui S Sanghavi and R Srikant ldquoDistributed link scheduling with constantoverheadrdquo IEEEACM Trans Netw vol 17 no 5 pp 1467ndash1480 2009

[3] R Duan and S Pettie ldquoLinear-time approximation for maximum weight matchingrdquoJ ACM vol 61 no 1 2014

[4] J Edmonds ldquoPaths trees and flowersrdquo Canadian Journal of Mathematics vol 17pp 449ndash467 1965

[5] J E Hopcroft and R M Karp ldquoAn n52 algorithm for maximum matchings inbipartite graphsrdquo SIAM J Comput vol 2 no 4 pp 225ndash231 1973

[6] S Micali and V V Vazirani ldquoAn O(radic|V ||E|) algorithm for finding maximum

matching in general graphsrdquo in 21st Symp on Foundations of Comp Sc (FOCS)IEEE 1980 pp 17ndash27

[7] N Nisse A Salch and V Weber ldquoRecovery of disrupted airline operationsrdquo 2015httphalinriafrSomething

[8] X Wu and R Srikant ldquoRegulated maximal matching A distributed schedulingalgorithm for multi-hop wireless networks with nodeexclusive spectrum sharingrdquo inIEEE Conf on Decision and Control 2005

65

  • Contents
  • Introduction
  • Algorithms
    • Maximum matching
    • k-maximum matching
      • k-matching for Airport Slot assignment
      • The case where k=3
      • The case of Paths
      • The case of the Spider
          • Application
            • Description
            • Reyni Erdos
            • Barabaacutesi Albert
            • Amadeus Graphs
            • Bipartite
            • Bipartite with degree seq
            • Appendix A
              • BipartiteGraphGeneratorpy
              • RandomGraphGeneratorpy
              • kequals3MaximumMatchingpy
              • Plotmat
                  • Bibliography
Page 16: Theodoros Alexandros KARAGKIOULES -  · Introduction This work is the result of a 6 months internship, under the supervision of research O cer Nicolas NISSE. The original scope of

23 Barabasi Albert 17

Computation time over |E| - Comments

bull When the initial matching is sufficiently large then the forced edges are taken out(a process which takes a fragment of the computation time) and then the classicalmatching algorithm (Edmonds) is applied on a smaller graph(G) This reducessignificantly the computation time

bull When the initial matching is small then the computation time of the constraintalgorithm might be larger than that of Edmonds The reason is that the constraintalgorithm need some time to compute the useless and forced edges and thenEdmonds algorithm is applied on G G Thus the overall processing time issometimes larger

Sorted matching size

18 Application

Sorted matching size-Comments

bull In this graph the matching size of the classical algorithm is depicted in ascendingorder along with the corresponding constraint algorithm and greedy result

bull Here in the case where m is small for both cases of initial matching (small large)the result may vary greatly starting from a value of half the perfect matching withsmall differences between the results of the various algorithm implementations

bull For the other cases of m the results converge

bull This is explained as for small values of m the graph is disconnected

bull In the matching size difference set of figures a very noticing difference value ap-pears For the cases of small m( the number of existing nodes that a new node isconnected to at the creation of the graph) we can see that the difference in the

23 Barabasi Albert 19

matching size compared to that of the perfect matching could be up to 40 ofthat of the matching size So there are occasions where the matching size is 200edges when the perfect matching would have been 500

bull the difference between the Constraint matching and the classical matching andthe difference of the constraint matching and that of the greedy matching do notshow significant values

Sorted Ratios

Sorted Ratio s -Comments

bull This set of figures depicts the ratios VV

EE

∆∆

in ascending order of VV

20 Application

bull It is evident that when the initial matching is large the amount of forced edges(and their endpoints) removed is high thus the ratio of Nodes and edges is verylow For higher probabilities almost all edges are removed as useless

bull For a smaller initial matching almost no forced edges (and their endpoints) areremoved which we conclude be the node ration being close to 1 There is somesmall amount of useless edges removed though since the ratio of edges is less butclose to 1

bull The ratio of ∆ for large initial matching follows the trend of the node ratio yetfor smaller initial matching it deviates significantly

Sorted |E||V |

23 Barabasi Albert 21

Sorted |E||V | - Comments

bull Although as graph density the ratio 2|E||V |(|V |minus1)

is considered in this set of figures

we evaluate the correlation of the ratio |E||V | of G and G since the density of G

could acquire values higher than that of G

bull The figures are calculated in ascending order for the ratio of G

bull For the case of large initial matching the two ratios for G and G remain almostconstant ( to the extent of the edge attraction m of each graph) since removingforced edges( and their endpoints) alters the |E| and |V | proportionately

bull For the case of small initial matching we observe some deviation in the valuesof the ration for G and that is explained with the removal of only useless edgeswhich only alters the |E| and keeps |V | in the original values

Sorted ∆

22 Application

Sorted ∆-Comments

bull In this set of figures the ascending order of the ∆ of G is associated with the ∆of G

bull There is a significant jump of the ∆ for each graph category which tells that thatwe are not comparing a uniform distribution of random graphs and based on theedge attraction m the graphs can vary in form

bull For larger initial matching we observe the difference in the ∆s of G and G giventhe removed forced edges( and their endpoints) At some cases the ∆ of G dropsto 0 since the vast majority of edges have been declared forced and removed alongwith their endpoints What is interesting is that the ∆ of G oscilates within stablelimits

24 Amadeus Graphs 23

bull For smaller initial matching the ∆s of G and G follow mostly the same trend onlya few number of different instances

24 Amadeus Graphs

Graph characteristics Amadeus graphs

bull These are the bipartite graphs provided by Amadeus

Computation time over |E|

Computation time over |E| - Comments

24 Application

bull For every instance the computation time of the classical algorithm is always smallerto that of the constraint matching

bull This allows as to speculate that we always compute a smaller G which also impliesthat we always find a set of forced edges and useless

Sorted matching size

Sorted matching size - Comments

bull Size of matching has an upward trend since the magnitude of the graphs is notthe same for the 160 instances

bull No significant deviation is noticed as per the first graph

24 Amadeus Graphs 25

bull Except from deviation from the perfect matching (number of flights) where some-times it could get up to 40

bull For the Amadeus Bipartite graphs we can see that the difference of the Classicaland the constraint implementation is not more than 1 edge in the matching

bull There appears to be a difference of up to 24 edges between the Classical matchingand the Perfect matching which is computed as the number of flights

bull The greedy algorithm performs well with only a few instances deviating slightlyform the Constraint algorithm result

Sorted Ratios

Sorted Ratios - Comments

26 Application

bull

Sorted |E||V |

Sorted |E||V | - Comments

bull Density of the graphs shows that on average we have 25-3 available time slot perflight

bull The line for the same value for G shows that there is a large deviation for everyinstance which allows for the hypothesis that the amount of useless+forced edgesof G has no obvious correlation to that of G

25 Bipartite 27

Sorted ∆

Sorted ∆-Comments

bull As per the previous related graphs for ∆ there is in significant drop in the ∆ of Gand G

25 Bipartite

Graph characteristics Bipartite random Graphs

bull BIPxy are randomly generated graphs with a fixed number of 1000(n=500 andm=500) nodes

bull There are 6 categories based on ini matching and probability p

28 Application

bull Probability p has been chosen as such in order to simulate the |E||V | 25 of theAmadeus bipartite graphs

bull So in order to have about 2-4 edges for every node we choose accordingly theprobability p to choose one of the n lowastm possible edges

bull x = L S L When the initial matching is large and S when it is small

bull y = 1 2 3 1 when p = 18250

2 when p = 25250

and 3 when p = 34250

Computation time over

Computation time overedges-Comments

bull

25 Bipartite 29

Sorted matching size

Sorted matching size-Comments

bull In these set of graphs one can instantly notice that only a few instances with highprobability can reach a matching size equal to the perfect matching

bull For the case of the initial matching we witness that there is a gap between the lineof the classical matching and those of the constraint and greedy results suggestingsmaller matching sizes of 10-40 edges

bull For the case of the small initial matching the result of the constraint matchingis now close to the result of the classical matching yet the greedy algorithm stillshows a relevantly big difference

30 Application

bull In this set of bipartite graphs we can witness that the result of the Constraintmatching shows a difference with the classical matching when the initial matchingis large The difference is smaller as the probability gets larger

bull For the case of the small initial matching the above phenomenom does not occuryet the greedy results deviates from that of the constraint matching

bull As per the pefrect matching compared to the classical matching a difference of5-10 edges is evident at almost all cases

Sorted Ratios

Sorted Ratios-Comments

bull Great max degree deviation

25 Bipartite 31

bull Regardless of the probability the ration of nodes and edges seems to have similarbehaviour when compared to the respective graphs of the same matching scale

bull Same gap between nodes ration and edges ration for all cases

Sorted |E||V |

Sorted |E||V | - Comments

bull In these set of figures we witness that the |E||V | acquires values relevant to those ofthe amadeus graphs The random graphs were constructed to depict this similarity

bull For smaller initial matching the ratios for G and G show the same upward trendand also they acquire closer values It represents the decrease of the averagenumber of forced edges in comparison to the larger matching cases

32 Application

Sorted ∆

Sorted ∆-Comments

bull ∆ acquires the same min and max values for each probability case (expected)

bull Gap in the case of large initial matching

26 Bipartite with degree seq

Graph characteristics

bull DEQBIPxy are randomly generated graphs based on three different types of degreedistribution of the Amadeus graphs

26 Bipartite with degree seq 33

bull There are 6 categories based on ini matching and degree distribution

bull x = L S L When the initial matching is large and S when it is small

bull y = 1 2 3 1 when degree distribution is based on file 2 when degree distributionis based on file and 3 when degree distribution is based on file

Computation time over

34 Application

Computation time overedges-Comments

bull Greedy algorithm takes minimum amount of time

bull The smaller the initial matching the more smaller the difference in comoutationtime of Constraint and classical algorithm

bull Due to preprocessing and the fact that G and G are the almost identical thetotal time needed to apply the constraint algorithm is in some cases bigger

Sorted matching size

26 Bipartite with degree seq 35

Sorted matching size-Comments

bull Classical matching is equal to perfect matching in every case

bull Constraint and greedy have identical behaviour

bull The larger the spectrum of the degree sequence the more efficient the matching

Sorted Ratios

36 Application

Sorted Ratios-Comments

bull With large initial matching most of the edges are considenred uselles or forced andare removed thus the ratio is close(if not equal to) zero

bull For small matching and large degree sequence sectrum hte max degree remainsthe same Only a few forced edges (and their nodes) are removed apparently nonodes with max degree

Sorted |E||V |

26 Bipartite with degree seq 37

Sorted |E||V | - Comments

bull In these set of figures we witness that the |E||V | acquires values relevant to those ofthe amadeus graphs The random graphs were constructed to depict this similarity

bull For smaller initial matching the ratios for G and G show the same upward trendand also they acquire closer values It repsresent the decrease of the averagenumber of forced edges in comparison to the larger matching cases

Sorted ∆

38 Application

Sorted ∆-Comments

bull Big difference in max degree in large initial matching

bull Almost identical behaviour in the case of small initial matching

Appendix A 39

Appendix A

BipartiteGraphGeneratorpy

from future import divisionimport networkx as nx

from networkxalgorithms import approximationimport collectionsimport randomimport mathfrom networkxalgorithms import bipartiteif name == main

for i in range(1481)waqs 481index=1n=randomrandint(100 1000)

n1=95 was 500me1=118

n2=251 was 500me2=903

n3=165 was 500me3=412

m=0m1=0p=randomrandom()p1=18250p2=25250p3=34250print ip=05t1=randomrandint(0 1)print im2=randomrandint(n2minus1 n2+1)G = nxGraph()ma = nxGraph()

aseq1=[1 2 3 4 5 3]

bseq1=[4 3 3 1 2 2 1]

aseq2=[16 14 14 14 12 11]bseq2=[0 0 0 0 0 0]

aseq3=[8 7 8 8 8 8]bseq3=[0 0 0 0 0 0]

40 Application

print Gnumber of edges()if ilt=160

G=bipartiteconfiguration model(aseq1 bseq1 create using=None seed=None)A=nxadjacency matrix(G)for ii in range(0n1+me1)

maadd node(ii)A=[Rtodense()tolist()[0] for R in A]

printnummanumber of nodes()rl=randomsample(range(0n1+me1) n1+me1)m=0done vertices = set()for p in rlprintin fordone verticesadd(p)

neighbors = []list()for iii in range(0n1+me1)

if A[p][iii]==1neighborsappend(iii)

randomshuffle(neighbors)continue loop = Truedegree = len(neighbors)

print degreej = 0p4=randomrandom()while continue loop and (jltdegree)print in loop

next = neighbors[j]if next not in done vertices and p not in done vertices

done verticesadd(p)done verticesadd(next)if p4gt=07print added edge

maadd edge(pnext)m=m+1

continue loop = Falsej += 1

print matching listOfedgeprint maedge

MA=nxadjacency matrix(ma)print MA

MA=[Rtodense()tolist()[0] for R in MA]print MA

B=[ join(map(strR)) for R in A]MB=[ join(map(strR)) for R in MA]

C=njoin(B)+nMC=njoin(MB)+n

print nprint mprint m1

filea=str(i)+txtwith open(fileaw) as f

Appendix A 41

fwrite(str(n1+me1))fwrite(n)fwrite(str(n1+me1))fwrite(n)fwrite(str(m))fwrite(n)fwrite(n)fwrite(C)fwrite(n)fwrite(MC)

elif igt160 and ilt321G=bipartiteconfiguration model(aseq2 bseq2 create using=None seed=None)A=nxadjacency matrix(G)for ii in range(0n2+me2)

maadd node(ii)A=[Rtodense()tolist()[0] for R in A]

printnummanumber of nodes()rl=randomsample(range(0n2+me2) n2+me2)m=0done vertices = set()for p in rlprintin fordone verticesadd(p)

neighbors = []list()for iii in range(0n2+me2)

if A[p][iii]==1neighborsappend(iii)

randomshuffle(neighbors)continue loop = Truedegree = len(neighbors)

print degreej = 0p4=randomrandom()while continue loop and (jltdegree)

print in loopnext = neighbors[j]if next not in done vertices and p not in done vertices

done verticesadd(p)done verticesadd(next)if p4gt=07

print added edgemaadd edge(pnext)m=m+1

continue loop = Falsej += 1

print matching listOfedgeprint maedge

MA=nxadjacency matrix(ma)print MA

MA=[Rtodense()tolist()[0] for R in MA]print MA

B=[ join(map(strR)) for R in A]MB=[ join(map(strR)) for R in MA]

42 Application

C=njoin(B)+nMC=njoin(MB)+n

print nprint mprint m1

filea=str(i)+txtwith open(fileaw) as f

fwrite(str(n2+me2))fwrite(n)fwrite(str(n2+me2))fwrite(n)fwrite(str(m))fwrite(n)fwrite(n)fwrite(C)fwrite(n)fwrite(MC)

elseG=bipartiteconfiguration model(aseq3 bseq3 create using=None seed=None)A=nxadjacency matrix(G)for ii in range(0n3+me3)

maadd node(ii)A=[Rtodense()tolist()[0] for R in A]

printnummanumber of nodes()rl=randomsample(range(0n3+me3) n3+me3)m=0done vertices = set()for p in rlprintin fordone verticesadd(p)

neighbors = []list()for iii in range(0n3+me3)

if A[p][iii]==1neighborsappend(iii)

randomshuffle(neighbors)continue loop = Truedegree = len(neighbors)

print degreej = 0p4=randomrandom()while continue loop and (jltdegree)

print in loopnext = neighbors[j]if next not in done vertices and p not in done vertices

done verticesadd(p)done verticesadd(next)if p4gt=07print added edge

maadd edge(pnext)m=m+1

continue loop = Falsej += 1

Appendix A 43

print matching listOfedgeprint maedge

MA=nxadjacency matrix(ma)print MA

MA=[Rtodense()tolist()[0] for R in MA]print MA

B=[ join(map(strR)) for R in A]MB=[ join(map(strR)) for R in MA]

C=njoin(B)+nMC=njoin(MB)+n

print nprint mprint m1

filea=str(i)+txtwith open(fileaw) as f

fwrite(str(n3+me3))fwrite(n)fwrite(str(n3+me3))fwrite(n)fwrite(str(m))fwrite(n)fwrite(n)fwrite(C)fwrite(n)fwrite(MC)

print nRandom graphs with random matching have been generated

44 Application

RandomGraphGeneratorpy

from future import divisionimport networkx as nxfrom networkxalgorithms import approximationimport collectionsimport randomimport mathif name == main

for i in range(1481)index=1n=randomrandint(100 1000)

n=1000m=0m1=0p=randomrandom()p1=mathlog(n2)np2=13p3=mathlog(n2)n+01p=05t1=randomrandint(0 1)print im2=randomrandint(n2minus1 n2+1)G = nxGraph()ma = nxGraph()print nme1=randomrandint(1 10)me2=randomrandint(2050)me3=randomrandint(50100)if ilt241

if ilt=80G=nxfast gnp random graph(n p1 seed=None directed=False)

elif igt80 and ilt161G=nxfast gnp random graph(n p2 seed=None directed=False)

elseG=nxfast gnp random graph(n p3 seed=None directed=False)

elseif ilt=320

G=nxbarabasi albert graph(n me1 seed=None)elif igt320 and ilt401

G=nxbarabasi albert graph(n me2 seed=None)else

G=nxbarabasi albert graph(n me3 seed=None)A=nxadjacency matrix(G)for ii in range(0n)

maadd node(ii)A=[Rtodense()tolist()[0] for R in A]

rl=randomsample(range(0n) n)m=0

Appendix A 45

done vertices = set()for p in rl

done verticesadd(p)neighbors = []list()for iii in range(0n)

if A[p][iii]==1neighborsappend(iii)

randomshuffle(neighbors)continue loop = Truedegree = len(neighbors)j = 0p2=randomrandom()while continue loop and (jltdegree)

next = neighbors[j]if next not in done vertices and p not in done vertices

done verticesadd(p)done verticesadd(next)if p2gt=00 Larger probability for smaller initial matching

maadd edge(pnext)m=m+1

continue loop = Falsej += 1

print matching listOfedgeprint maedgeMA=nxadjacency matrix(ma)MA=[Rtodense()tolist()[0] for R in MA]print MAB=[ join(map(strR)) for R in A]MB=[ join(map(strR)) for R in MA]

C=njoin(B)+nMC=njoin(MB)+nprint MCprint nprint mprint m1filea=str(i)+txtwith open(fileaw) as f

fwrite(str(n))fwrite(n)fwrite(str(n))fwrite(n)fwrite(str(m))fwrite(n)fwrite(n)fwrite(C)fwrite(n)fwrite(MC)

print nRandom graphs with random matching have been generated

46 Application

kequals3MaximumMatchingpy

from future import divisionimport networkx as nxfrom networkxalgorithms import bipartiteimport matplotlibpyplot as pltimport collectionsimport timeitimport xlwtimport xlrdimport mathimport sys

Case for General Graphsdef forced edges(Gadj dict2matching dict1num nodesforced)

flagg=0for n in range(0num nodes)

for k in adj dict2[n]if ([k]==matching dict1[n])

count=0for l in range(0num nodes)

count=count+adj dict2[l]count(k)if (len(adj dict2[n])==1) or (count==1)

forcedadd edge(nk)Gremove edge(nk)Gremove node(n)Gremove node(k)printforced edgenktemp=kflagg=1for m in range (len(adj dict2[n])minus1minus1minus1)

adj dict2[adj dict2[n][m]]remove(n)adj dict2[n]remove(adj dict2[n][m])

if adj dict2[temp]for l in range(len(adj dict2[temp])minus1minus1minus1)

if (adj dict2[temp][l]=n)adj dict2[adj dict2[temp][l]]remove(temp)adj dict2[temp]remove(adj dict2[temp][l])

break

def useless edges(num nodesadj dict1matching dict1uselessadj dict2G)for n in range(0num nodes)

for k in adj dict1[n]if ([k]=matching dict1[n]) and matching dict1[n] and matching dict1[k]

uselessadd edge(nk)Gremove edge(n k)

Appendix A 47

tempa=kadj dict2[n]remove(k)adj dict2[tempa]remove(n)adj dict1[tempa]remove(n)

return G

def Greedy(num nodesadj dict3matching dict2)

for n in range(0num nodes)if matching dict2[n]

flag2=minus1flag3=minus1for v in adj dict3[n]

if not matching dict2[v]flag2=vbreak

for p in adj dict3[matching dict2[n][0]]if not matching dict2[p]

flag3=pbreak

if (flag2=minus1) and (flag3=minus1) and (flag2=flag3)tempr=matching dict2[n][0]matching dict2[n]=[flag2]matching dict2[flag2]=[n]matching dict2[tempr]=[flag3]matching dict2[flag3]=[tempr]

elsefor k in adj dict3[n]

if not matching dict2[k]matching dict2[n]=[k]matching dict2[k]=[n]break

yo1=0for i in range(0num nodes)

if matching dict2[i] and [i]==matching dict2[matching dict2[i][0]]yo1=yo1+1

greedy size=yo12return greedy size

def General()

INPUTSwb = xlwtWorkbook()ws = wbadd sheet(Results Random)book=xlrdopen workbook(filenames randomxls)

48 Application

style0 = xlwteasyxf(fontbold on)style1 = xlwteasyxf(num format str=0000)INPUTSwswrite(0 0File style0)wswrite(0 1 Nodesstyle0)wswrite(0 2 Initial matchingstyle0)wswrite(0 3 NodesGstyle0)wswrite(0 4 EdgesGstyle0)wswrite(0 5 MaxDegreeGstyle0)wswrite(0 6 NodesG hatstyle0)wswrite(0 7 EdgesG Hatstyle0)wswrite(0 8 Useless edgesstyle0)wswrite(0 9 Forced edgesstyle0)wswrite(0 10 MaxDegreeG Hatstyle0)wswrite(0 11 Classical matchingstyle0)wswrite(0 12 Final matchingstyle0)wswrite(0 13 Greedy matchingstyle0)wswrite(0 14 Time classicalstyle0)wswrite(0 15 Time algorithmstyle0)wswrite(0 16 Time greedystyle0)wswrite(0 17 Perfect matching ratiostyle0)wswrite(0 18 Nodes ratiostyle0)wswrite(0 19 Edges ratiostyle0)wswrite(0 20 Matching ratiostyle0)

print nWelcomeThis is an implementation for general random graphs It uses Edmonds algorithm to compute maximum matching on G Hatn

for index in range (1481)was 481

if (index==482)f=open(Algotel generaltxtr)readlines()

elsefilea=str(booksheet by index(0)cell(index0))s=fileareplace(textu)replace()f=open(sr)readlines()Truewswrite(index 0 s)

print index

num nodes=int([xstrip()split() for x in f][0][0])

num matching=int([xstrip()split() for x in f][2][0])

adj temp = [xstrip()split() for x in f][44+num nodes]adj=[map(intR) for R in adj temp]

matching temp=[xstrip()split() for x in f][4+num nodes+14+2num nodes+1]matching1=[map(intR) for R in matching temp]

adj dict1=i[ii for iix in enumerate(L) if x] for iL in enumerate(adj)adj dict2=i[ii for iix in enumerate(L) if x] for iL in enumerate(adj)

Appendix A 49

adj dict3=i[ii for iix in enumerate(L) if x] for iL in enumerate(adj)

matching dict1=i[ii for iix in enumerate(L) if x] for iL in enumerate(matching1)matching dict2=i[ii for iix in enumerate(L) if x] for iL in enumerate(matching1)print adj dict2print matching dict2wswrite(index 1 num nodes)wswrite(index 2 num matching)

G = nxGraph()

useless= nxGraph()forced = nxGraph()

Fill Graphfor n in range(0num nodes)

for k in adj dict1[n]Gadd edge(nk)

Gt=Gnumber of edges()wswrite(index 3 Gnumber of nodes())wswrite(index 4 Gnumber of edges())wswrite(index 5 max(Gdegree()values()))

Compute Edmonds classical matching on G for comparison

startB = timeitdefault timer()Classical Matching=nxmax weight matching(G maxcardinality=False)stopB = timeitdefault timer()

Compute Gˆ nad MˆstartC = timeitdefault timer()useless edges(num nodesadj dict1matching dict1uselessadj dict2G)forced edges(Gadj dict2matching dict1num nodesforced)Final Matching=nxmax weight matching(G maxcardinality=False)stopC = timeitdefault timer()

GreedystartG = timeitdefault timer()greedy size=Greedy(num nodesadj dict3matching dict2)stopG = timeitdefault timer()

wswrite(index 6 Gnumber of nodes())wswrite(index 7 Gnumber of edges())wswrite(index 8 uselessnumber of edges())wswrite(index 9 forcednumber of edges())if Gdegree()values()

wswrite(index 10 max(Gdegree()values()))else

50 Application

wswrite(index 10 0)wswrite(index 11 len(Classical Matching)2)wswrite(index 12 len(Final Matching)2+forcednumber of edges())wswrite(index 13 greedy size)wswrite(index 14 stopB minus startBstyle1)wswrite(index 15 stopC minus startCstyle1)wswrite(index 16 stopG minus startGstyle1)wswrite(index 17 (len(Final Matching)2+forcednumber of edges())(num nodes2)style1)wswrite(index 18 Gnumber of nodes()Gtstyle1)wswrite(index 19 Gnumber of edges()Gtstyle1)wswrite(index 20 (len(Final Matching)2+forcednumber of edges())(len(Classical Matching)2)style1)

wbsave(AA Results Random Reyni Large Bipartitexls)

Main function Here we must choose the input form of the dataif name == main

startA = timeitdefault timer()General()stopA = timeitdefault timer()

print nThis program has terminatednnRunning time for 480 files stopAminusstartAprint nnPlease open AA Results Random Reyni Largexls file to see the Results

Appendix A 51

Plotmat

clear allclose allload(RN1Lmat)load(RN1Smat)load(RN2Lmat)load(RN2Smat)load(RN3Lmat)load(RN3Smat)

Plotsh(1)=figure(NameHistogram of Matching size difference between Constraint Algorithm and Greedy AlgorithmNumberTitleoff)

RN1L Greedydiff=RN1L Final matchingminusRN1L Greedy matchingRN2L Greedydiff=RN2L Final matchingminusRN2L Greedy matchingRN3L Greedydiff=RN3L Final matchingminusRN3L Greedy matchingRN1S Greedydiff=RN1S Final matchingminusRN1S Greedy matchingRN2S Greedydiff=RN2S Final matchingminusRN2S Greedy matchingRN3S Greedydiff=RN3S Final matchingminusRN3S Greedy matching

RN1L Finaldiff=RN1L Classical matchingminusRN1L Final matchingRN2L Finaldiff=RN2L Classical matchingminusRN2L Final matchingRN3L Finaldiff=RN3L Classical matchingminusRN3L Final matchingRN1S Finaldiff=RN1S Classical matchingminusRN1S Final matchingRN2S Finaldiff=RN2S Classical matchingminusRN2S Final matchingRN3S Finaldiff=RN3S Classical matchingminusRN3S Final matching

RN1L Classicaldiff=(RN1L Nodes2)minusRN1L Classical matchingRN2L Classicaldiff=(RN2L Nodes2)minusRN2L Classical matchingRN3L Classicaldiff=(RN3L Nodes2)minusRN3L Classical matchingRN1S Classicaldiff=(RN1S Nodes2)minusRN1S Classical matchingRN2S Classicaldiff=(RN2S Nodes2)minusRN2S Classical matchingRN3S Classicaldiff=(RN3S Nodes2)minusRN3S Classical matching

subplot(231)hold onhistf(RN1L Greedydiff0110facecolorbfacealpha9edgealpha1)histf(RN1L Finaldiff0110facecolorrfacealpha5edgealpha1)histf(RN1L Classicaldiff0110facecolorgfacealpha5edgealpha1)legalpha(ConminusGreClasminusConPerfminusClasslocationnortheast)legend boxoffaxis tightxlabel(edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN1L)grid on

subplot(232)hold onhistf(RN2L Greedydiff0110facecolorbfacealpha9edgealpha1)

52 Application

histf(RN2L Finaldiff0110facecolorrfacealpha5edgealpha1)histf(RN2L Classicaldiff0110facecolorgfacealpha5edgealpha1)legalpha(ConminusGreClasminusConPerfminusClasslocationnortheast)legend boxoffaxis tightxlabel(edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN2L)grid on

subplot(233)hold onhistf(RN3L Greedydiff0110facecolorbfacealpha5edgealpha1)histf(RN3L Finaldiff0110facecolorrfacealpha5edgealpha1)histf(RN3L Classicaldiff0110facecolorgfacealpha5edgealpha1)legalpha(ConminusGreClasminusConPerfminusClasslocationnortheast)legend boxoffaxis tightxlabel(edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN3L)grid on

subplot(234)hold onhistf(RN1S Greedydiff0110facecolorbfacealpha5edgealpha1)histf(RN1S Finaldiff0110facecolorrfacealpha5edgealpha1)histf(RN1S Classicaldiff0110facecolorgfacealpha5edgealpha1)legalpha(ConminusGreClasminusConPerfminusClasslocationnortheast)legend boxoffaxis tightxlabel(edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(R1NS)grid on

subplot(235)hold onhistf(RN2S Greedydiff0110facecolorbfacealpha5edgealpha1)histf(RN2S Finaldiff0110facecolorrfacealpha5edgealpha1)histf(RN2S Classicaldiff0110facecolorgfacealpha5edgealpha1)legalpha(ConminusGreClasminusConPerfminusClasslocationnortheast)legend boxoffaxis tightxlabel(edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN2S)grid on

subplot(236)hold onhistf(RN3S Greedydiff0110facecolorbfacealpha5edgealpha1)histf(RN3S Finaldiff0110facecolorrfacealpha5edgealpha1)histf(RN3S Classicaldiff0110facecolorgfacealpha5edgealpha1)

Appendix A 53

legalpha(ConminusGreClasminusConPerfminusClasslocationnortheast)legend boxoffaxis tightgrid ontitle(RN3S)xlabel(edges) xminusaxis labelylabel(instances) yminusaxis labelset(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN1png minusr300)h(2)=figure(NameHistogram of Max Degree of G AND G HatNumberTitleoff)RN1L x=RN1L MaxDegreeGminusRN1L MaxDegreeG HatRN2L x=RN2L MaxDegreeGminusRN2L MaxDegreeG HatRN3L x=RN3L MaxDegreeGminusRN3L MaxDegreeG HatRN1S x=RN1S MaxDegreeGminusRN1S MaxDegreeG HatRN2S x=RN2S MaxDegreeGminusRN2S MaxDegreeG HatRN3S x=RN3S MaxDegreeGminusRN3S MaxDegreeG Hatsubplot(231)hold onhistf(RN1L MaxDegreeG0150facecolorbfacealpha5edgealpha1)histf(RN1L MaxDegreeG Hat0150facecolorrfacealpha5edgealpha1)histf(RN1L x0150facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightxlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN1L)grid on

subplot(232)hold onhistf(RN2L MaxDegreeG010500facecolorbfacealpha5edgealpha1)histf(RN2L MaxDegreeG Hat010500facecolorrfacealpha5edgealpha1)histf(RN2L x010500facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightxlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN2L)grid on

subplot(233)hold onhistf(RN3L MaxDegreeG010300facecolorbfacealpha5edgealpha1)histf(RN3L MaxDegreeG Hat010300facecolorrfacealpha5edgealpha1)histf(RN3L x010300facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightxlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN3L)

54 Application

grid on

subplot(234)hold onhistf(RN1S MaxDegreeG0150facecolorbfacealpha5edgealpha1)histf(RN1S MaxDegreeG Hat0150facecolorrfacealpha5edgealpha1)histf(RN1S x0150facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightxlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(R1NS)grid on

subplot(235)hold onhistf(RN2S MaxDegreeG010500facecolorbfacealpha5edgealpha1)histf(RN2S MaxDegreeG Hat010500facecolorrfacealpha5edgealpha1)histf(RN2S x010500facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightxlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN2S)grid on

subplot(236)hold onhistf(RN3S MaxDegreeG05300facecolorbfacealpha5edgealpha1)histf(RN3S MaxDegreeG Hat05300facecolorrfacealpha5edgealpha1)histf(RN3S x05300facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightgrid ontitle(RN3S)xlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labelset(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN2png minusr300)

h(3)=figure(NameComputation time over edgesNumberTitleoff)

subplot(231)hold onstem(RN1L EdgesGRN1L Time classicalg)stem(RN1L EdgesGRN1L Time algorithmro)stem(RN1L EdgesGRN1L Time greedybx)grid on

Appendix A 55

title(RN1L)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)

subplot(232)hold onstem(RN2L EdgesGRN2L Time classicalg)stem(RN2L EdgesGRN2L Time algorithmro)stem(RN2L EdgesGRN2L Time greedybx)grid ontitle(RN2L)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)

subplot(233)hold onstem(RN3L EdgesGRN3L Time classicalg)stem(RN3L EdgesGRN3L Time algorithmro)stem(RN3L EdgesGRN3L Time greedybx)grid ontitle(RN3L)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)

subplot(234)hold onstem(RN1S EdgesGRN1S Time classicalg)stem(RN1S EdgesGRN1S Time algorithmro)stem(RN1S EdgesGRN1S Time greedybx)grid ontitle(RN1S)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)

subplot(235)hold onstem(RN2S EdgesGRN2S Time classicalg)stem(RN2S EdgesGRN2S Time algorithmro)stem(RN2S EdgesGRN2S Time greedybx)grid ontitle(RN2S)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)

subplot(236)hold onstem(RN3S EdgesGRN3S Time classicalg)stem(RN3S EdgesGRN3S Time algorithmro)stem(RN3S EdgesGRN3S Time greedybx)

56 Application

grid ontitle(RN3S)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)set(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN3png minusr300)

h(4)=figure(NameSorted matching sizeNumberTitleoff)RN1L Sorted matching temp(1)=RN1L Classical matchingRN1L Sorted matching temp(2)=RN1L Final matchingRN1L Sorted matching temp(3)=RN1L Greedy matchingRN1L Sorted matching temp(4)=RN1L Initial matchingRN1L Sorted matching=sortrows(RN1L Sorted matching temp)

RN2L Sorted matching temp(1)=RN2L Classical matchingRN2L Sorted matching temp(2)=RN2L Final matchingRN2L Sorted matching temp(3)=RN2L Greedy matchingRN2L Sorted matching temp(4)=RN2L Initial matchingRN2L Sorted matching=sortrows(RN2L Sorted matching temp)

RN3L Sorted matching temp(1)=RN3L Classical matchingRN3L Sorted matching temp(2)=RN3L Final matchingRN3L Sorted matching temp(3)=RN3L Greedy matchingRN3L Sorted matching temp(4)=RN3L Initial matchingRN3L Sorted matching=sortrows(RN3L Sorted matching temp)

RN1S Sorted matching temp(1)=RN1S Classical matchingRN1S Sorted matching temp(2)=RN1S Final matchingRN1S Sorted matching temp(3)=RN1S Greedy matchingRN1S Sorted matching temp(4)=RN1S Initial matchingRN1S Sorted matching=sortrows(RN1S Sorted matching temp)

RN2S Sorted matching temp(1)=RN2S Classical matchingRN2S Sorted matching temp(2)=RN2S Final matchingRN2S Sorted matching temp(3)=RN2S Greedy matchingRN2S Sorted matching temp(4)=RN2S Initial matchingRN2S Sorted matching=sortrows(RN2S Sorted matching temp)

RN3S Sorted matching temp(1)=RN3S Classical matchingRN3S Sorted matching temp(2)=RN3S Final matchingRN3S Sorted matching temp(3)=RN3S Greedy matchingRN3S Sorted matching temp(4)=RN3S Initial matchingRN3S Sorted matching=sortrows(RN3S Sorted matching temp)

subplot(231)hold onplot(RN1L Sorted matching(1)b)plot(RN1L Sorted matching(2)g)plot(RN1L Sorted matching(3)r)plot(RN1L Sorted matching(4)m)

Appendix A 57

grid ontitle(RN1L)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)

subplot(232)hold onplot(RN2L Sorted matching(1)b)plot(RN2L Sorted matching(2)g)plot(RN2L Sorted matching(3)r)plot(RN2L Sorted matching(4)m)grid ontitle(RN2L)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)

subplot(233)hold onplot(RN3L Sorted matching(1)b)plot(RN3L Sorted matching(2)g)plot(RN3L Sorted matching(3)r)plot(RN3L Sorted matching(4)m)grid ontitle(RN3L)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)

subplot(234)hold onplot(RN1S Sorted matching(1)b)plot(RN1S Sorted matching(2)g)plot(RN1S Sorted matching(3)r)plot(RN1S Sorted matching(4)m)grid ontitle(RN1S)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)

subplot(235)hold onplot(RN2S Sorted matching(1)b)plot(RN2S Sorted matching(2)g)plot(RN2S Sorted matching(3)r)plot(RN2S Sorted matching(4)m)grid ontitle(RN2S)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)

58 Application

subplot(236)hold onplot(RN3S Sorted matching(1)b)plot(RN3S Sorted matching(2)g)plot(RN3S Sorted matching(3)r)plot(RN3S Sorted matching(4)m)grid ontitle(RN3S)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)set(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN4png minusr300)h(5)=figure(NameSorted RatiosNumberTitleoff)RN1L ratio1=RN1L NodesG hatRN1L NodesGRN2L ratio1=RN2L NodesG hatRN2L NodesGRN3L ratio1=RN3L NodesG hatRN3L NodesGRN1S ratio1=RN1S NodesG hatRN1S NodesGRN2S ratio1=RN2S NodesG hatRN2S NodesGRN3S ratio1=RN3S NodesG hatRN3S NodesG

RN1L ratio2=RN1L EdgesG HatRN1L EdgesGRN2L ratio2=RN2L EdgesG HatRN2L EdgesGRN3L ratio2=RN3L EdgesG HatRN3L EdgesGRN1S ratio2=RN1S EdgesG HatRN1S EdgesGRN2S ratio2=RN2S EdgesG HatRN2S EdgesGRN3S ratio2=RN3S EdgesG HatRN3S EdgesG

RN1L ratio3=RN1L MaxDegreeG HatRN1L MaxDegreeGRN2L ratio3=RN2L MaxDegreeG HatRN2L MaxDegreeGRN3L ratio3=RN3L MaxDegreeG HatRN3L MaxDegreeGRN1S ratio3=RN1S MaxDegreeG HatRN1S MaxDegreeGRN2S ratio3=RN2S MaxDegreeG HatRN2S MaxDegreeGRN3S ratio3=RN3S MaxDegreeG HatRN3S MaxDegreeG

RN1L ratio(1)=RN1L ratio1RN1L ratio(2)=RN1L ratio2RN1L ratio(3)=RN1L ratio3

RN2L ratio(1)=RN2L ratio1RN2L ratio(2)=RN2L ratio2RN2L ratio(3)=RN2L ratio3

RN3L ratio(1)=RN3L ratio1RN3L ratio(2)=RN3L ratio2RN3L ratio(3)=RN3L ratio3

RN1S ratio(1)=RN1S ratio1RN1S ratio(2)=RN1S ratio2RN1S ratio(3)=RN1S ratio3

RN2S ratio(1)=RN2S ratio1

Appendix A 59

RN2S ratio(2)=RN2S ratio2RN2S ratio(3)=RN2S ratio3

RN3S ratio(1)=RN3S ratio1RN3S ratio(2)=RN3S ratio2RN3S ratio(3)=RN3S ratio3

RN1L ratio sorted=sortrows(RN1L ratio)RN2L ratio sorted=sortrows(RN2L ratio)RN3L ratio sorted=sortrows(RN3L ratio)RN1S ratio sorted=sortrows(RN1S ratio)RN2S ratio sorted=sortrows(RN2S ratio)RN3S ratio sorted=sortrows(RN3S ratio)

subplot(231)hold onplot(RN1L ratio sorted(1)b)plot(RN1L ratio sorted(2)g)plot(RN1L ratio sorted(3)r)grid ontitle(RN1L)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)

subplot(232)hold onplot(RN2L ratio sorted(1)b)plot(RN2L ratio sorted(2)g)plot(RN2L ratio sorted(3)r)grid ontitle(RN2L)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)

subplot(233)hold onplot(RN3L ratio sorted(1)b)plot(RN3L ratio sorted(2)g)plot(RN3L ratio sorted(3)r)grid ontitle(RN3L)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)

subplot(234)hold onplot(RN1S ratio sorted(1)b)plot(RN1S ratio sorted(2)g)plot(RN1S ratio sorted(3)r)grid on

60 Application

title(RN1S)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)

subplot(235)hold onplot(RN2S ratio sorted(1)b)plot(RN2S ratio sorted(2)g)plot(RN2S ratio sorted(3)r)grid ontitle(RN2S)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)

subplot(236)hold onplot(RN3S ratio sorted(1)b)plot(RN3S ratio sorted(2)g)plot(RN3S ratio sorted(3)r)grid ontitle(RN3S)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)set(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN5png minusr300)

h(6)=figure(NameSorted edges over nodesNumberTitleoff)

RN1L DegreeG1=(RN1L EdgesG)(RN1L NodesG)RN1L DegreeG Hat1=(RN1L EdgesG Hat)(RN1L NodesG hat)

RN1L Degree temp1(1)=RN1L DegreeG1RN1L Degree temp1(2)=RN1L DegreeG Hat1RN1L Degree sorted1=sortrows(RN1L Degree temp1)subplot(231)hold on

plot(RN1L Degree sorted1(1)b)plot(RN1L Degree sorted1(2)g)grid ontitle(RN1L)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)

RN2L DegreeG1=(RN2L EdgesG)(RN2L NodesG)RN2L DegreeG Hat1=(RN2L EdgesG Hat)(RN2L NodesG hat)

RN2L Degree temp1(1)=RN2L DegreeG1

Appendix A 61

RN2L Degree temp1(2)=RN2L DegreeG Hat1RN2L Degree sorted1=sortrows(RN2L Degree temp1)

subplot(232)hold onplot(RN2L Degree sorted1(1)b)plot(RN2L Degree sorted1(2)g)grid ontitle(RN2L)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)

RN3L DegreeG1=(RN3L EdgesG)(RN3L NodesG)RN3L DegreeG Hat1=(RN3L EdgesG Hat)(RN3L NodesG hat)

RN3L Degree temp1(1)=RN3L DegreeG1RN3L Degree temp1(2)=RN3L DegreeG Hat1RN3L Degree sorted1=sortrows(RN3L Degree temp1)

subplot(233)hold onplot(RN3L Degree sorted1(1)b)plot(RN3L Degree sorted1(2)g)grid ontitle(RN3L)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)

RN1S DegreeG1=(RN1S EdgesG)(RN1S NodesG)RN1S DegreeG Hat1=(RN1S EdgesG Hat)(RN1S NodesG hat)

RN1S Degree temp1(1)=RN1S DegreeG1RN1S Degree temp1(2)=RN1S DegreeG Hat1RN1S Degree sorted1=sortrows(RN1S Degree temp1)

subplot(234)hold onplot(RN1S Degree sorted1(1)b)plot(RN1S Degree sorted1(2)g)grid ontitle(RN1S)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)

RN2S DegreeG1=(RN2S EdgesG)(RN2S NodesG)RN2S DegreeG Hat1=(RN2S EdgesG Hat)(RN2S NodesG hat)

RN2S Degree temp1(1)=RN2S DegreeG1

62 Application

RN2S Degree temp1(2)=RN2S DegreeG Hat1RN2S Degree sorted1=sortrows(RN2S Degree temp1)

subplot(235)hold onplot(RN2S Degree sorted1(1)b)plot(RN2S Degree sorted1(2)g)grid ontitle(RN2S)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)

RN3S DegreeG1=(RN3S EdgesG)(RN3S NodesG)RN3S DegreeG Hat1=(RN3S EdgesG Hat)(RN3S NodesG hat)

RN3S Degree temp1(1)=RN3S DegreeG1RN3S Degree temp1(2)=RN3S DegreeG Hat1RN3S Degree sorted1=sortrows(RN3S Degree temp1)

subplot(236)hold onplot(RN3S Degree sorted1(1)b)plot(RN3S Degree sorted1(2)g)grid ontitle(RN3S)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)set(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN6png minusr300)h(7)=figure(NameSorted mATCHED DEGREENumberTitleoff)RN1L ratioMax(1)=RN1L MaxDegreeGRN1L ratioMax(2)=RN1L MaxDegreeG Hat

RN1L ratio sortedMax=sortrows(RN1L ratioMax)subplot(231)hold onplot(RN1L ratio sortedMax(1)b)plot(RN1L ratio sortedMax(2)g)grid ontitle(RN1L)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)

RN2L ratioMax(1)=RN2L MaxDegreeGRN2L ratioMax(2)=RN2L MaxDegreeG Hat

RN2L ratio sortedMax=sortrows(RN2L ratioMax)subplot(232)

Appendix A 63

hold onplot(RN2L ratio sortedMax(1)b)plot(RN2L ratio sortedMax(2)g)grid ontitle(RN2L)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)

RN3L ratioMax(1)=RN3L MaxDegreeGRN3L ratioMax(2)=RN3L MaxDegreeG Hat

RN3L ratio sortedMax=sortrows(RN3L ratioMax)subplot(233)hold onplot(RN3L ratio sortedMax(1)b)plot(RN3L ratio sortedMax(2)g)grid ontitle(RN3L)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)

RN1S ratioMax(1)=RN1S MaxDegreeGRN1S ratioMax(2)=RN1S MaxDegreeG Hat

RN1S ratio sortedMax=sortrows(RN1S ratioMax)subplot(234)hold onplot(RN1S ratio sortedMax(1)b)plot(RN1S ratio sortedMax(2)g)grid ontitle(RN1S)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)

RN2S ratioMax(1)=RN2S MaxDegreeGRN2S ratioMax(2)=RN2S MaxDegreeG Hat

RN2S ratio sortedMax=sortrows(RN2S ratioMax)

subplot(235)hold onplot(RN2S ratio sortedMax(1)b)plot(RN2S ratio sortedMax(2)g)grid ontitle(RN2S)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)

RN3S ratioMax(1)=RN3S MaxDegreeGRN3S ratioMax(2)=RN3S MaxDegreeG Hat

64 Application

RN3S ratio sortedMax=sortrows(RN3S ratioMax)subplot(236)hold onplot(RN3S ratio sortedMax(1)b)plot(RN3S ratio sortedMax(2)g)grid ontitle(RN1L)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)set(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN7png minusr300)

tilefigs()(h)

Bibliography

[1] C Berge ldquoTWO THEOREMS IN GRAPH THEORYrdquo Proceedings of the NationalAcademy of Sciences of the United States of America vol 43 no 9 pp 842ndash844Sep 1957

[2] L Bui S Sanghavi and R Srikant ldquoDistributed link scheduling with constantoverheadrdquo IEEEACM Trans Netw vol 17 no 5 pp 1467ndash1480 2009

[3] R Duan and S Pettie ldquoLinear-time approximation for maximum weight matchingrdquoJ ACM vol 61 no 1 2014

[4] J Edmonds ldquoPaths trees and flowersrdquo Canadian Journal of Mathematics vol 17pp 449ndash467 1965

[5] J E Hopcroft and R M Karp ldquoAn n52 algorithm for maximum matchings inbipartite graphsrdquo SIAM J Comput vol 2 no 4 pp 225ndash231 1973

[6] S Micali and V V Vazirani ldquoAn O(radic|V ||E|) algorithm for finding maximum

matching in general graphsrdquo in 21st Symp on Foundations of Comp Sc (FOCS)IEEE 1980 pp 17ndash27

[7] N Nisse A Salch and V Weber ldquoRecovery of disrupted airline operationsrdquo 2015httphalinriafrSomething

[8] X Wu and R Srikant ldquoRegulated maximal matching A distributed schedulingalgorithm for multi-hop wireless networks with nodeexclusive spectrum sharingrdquo inIEEE Conf on Decision and Control 2005

65

  • Contents
  • Introduction
  • Algorithms
    • Maximum matching
    • k-maximum matching
      • k-matching for Airport Slot assignment
      • The case where k=3
      • The case of Paths
      • The case of the Spider
          • Application
            • Description
            • Reyni Erdos
            • Barabaacutesi Albert
            • Amadeus Graphs
            • Bipartite
            • Bipartite with degree seq
            • Appendix A
              • BipartiteGraphGeneratorpy
              • RandomGraphGeneratorpy
              • kequals3MaximumMatchingpy
              • Plotmat
                  • Bibliography
Page 17: Theodoros Alexandros KARAGKIOULES -  · Introduction This work is the result of a 6 months internship, under the supervision of research O cer Nicolas NISSE. The original scope of

18 Application

Sorted matching size-Comments

bull In this graph the matching size of the classical algorithm is depicted in ascendingorder along with the corresponding constraint algorithm and greedy result

bull Here in the case where m is small for both cases of initial matching (small large)the result may vary greatly starting from a value of half the perfect matching withsmall differences between the results of the various algorithm implementations

bull For the other cases of m the results converge

bull This is explained as for small values of m the graph is disconnected

bull In the matching size difference set of figures a very noticing difference value ap-pears For the cases of small m( the number of existing nodes that a new node isconnected to at the creation of the graph) we can see that the difference in the

23 Barabasi Albert 19

matching size compared to that of the perfect matching could be up to 40 ofthat of the matching size So there are occasions where the matching size is 200edges when the perfect matching would have been 500

bull the difference between the Constraint matching and the classical matching andthe difference of the constraint matching and that of the greedy matching do notshow significant values

Sorted Ratios

Sorted Ratio s -Comments

bull This set of figures depicts the ratios VV

EE

∆∆

in ascending order of VV

20 Application

bull It is evident that when the initial matching is large the amount of forced edges(and their endpoints) removed is high thus the ratio of Nodes and edges is verylow For higher probabilities almost all edges are removed as useless

bull For a smaller initial matching almost no forced edges (and their endpoints) areremoved which we conclude be the node ration being close to 1 There is somesmall amount of useless edges removed though since the ratio of edges is less butclose to 1

bull The ratio of ∆ for large initial matching follows the trend of the node ratio yetfor smaller initial matching it deviates significantly

Sorted |E||V |

23 Barabasi Albert 21

Sorted |E||V | - Comments

bull Although as graph density the ratio 2|E||V |(|V |minus1)

is considered in this set of figures

we evaluate the correlation of the ratio |E||V | of G and G since the density of G

could acquire values higher than that of G

bull The figures are calculated in ascending order for the ratio of G

bull For the case of large initial matching the two ratios for G and G remain almostconstant ( to the extent of the edge attraction m of each graph) since removingforced edges( and their endpoints) alters the |E| and |V | proportionately

bull For the case of small initial matching we observe some deviation in the valuesof the ration for G and that is explained with the removal of only useless edgeswhich only alters the |E| and keeps |V | in the original values

Sorted ∆

22 Application

Sorted ∆-Comments

bull In this set of figures the ascending order of the ∆ of G is associated with the ∆of G

bull There is a significant jump of the ∆ for each graph category which tells that thatwe are not comparing a uniform distribution of random graphs and based on theedge attraction m the graphs can vary in form

bull For larger initial matching we observe the difference in the ∆s of G and G giventhe removed forced edges( and their endpoints) At some cases the ∆ of G dropsto 0 since the vast majority of edges have been declared forced and removed alongwith their endpoints What is interesting is that the ∆ of G oscilates within stablelimits

24 Amadeus Graphs 23

bull For smaller initial matching the ∆s of G and G follow mostly the same trend onlya few number of different instances

24 Amadeus Graphs

Graph characteristics Amadeus graphs

bull These are the bipartite graphs provided by Amadeus

Computation time over |E|

Computation time over |E| - Comments

24 Application

bull For every instance the computation time of the classical algorithm is always smallerto that of the constraint matching

bull This allows as to speculate that we always compute a smaller G which also impliesthat we always find a set of forced edges and useless

Sorted matching size

Sorted matching size - Comments

bull Size of matching has an upward trend since the magnitude of the graphs is notthe same for the 160 instances

bull No significant deviation is noticed as per the first graph

24 Amadeus Graphs 25

bull Except from deviation from the perfect matching (number of flights) where some-times it could get up to 40

bull For the Amadeus Bipartite graphs we can see that the difference of the Classicaland the constraint implementation is not more than 1 edge in the matching

bull There appears to be a difference of up to 24 edges between the Classical matchingand the Perfect matching which is computed as the number of flights

bull The greedy algorithm performs well with only a few instances deviating slightlyform the Constraint algorithm result

Sorted Ratios

Sorted Ratios - Comments

26 Application

bull

Sorted |E||V |

Sorted |E||V | - Comments

bull Density of the graphs shows that on average we have 25-3 available time slot perflight

bull The line for the same value for G shows that there is a large deviation for everyinstance which allows for the hypothesis that the amount of useless+forced edgesof G has no obvious correlation to that of G

25 Bipartite 27

Sorted ∆

Sorted ∆-Comments

bull As per the previous related graphs for ∆ there is in significant drop in the ∆ of Gand G

25 Bipartite

Graph characteristics Bipartite random Graphs

bull BIPxy are randomly generated graphs with a fixed number of 1000(n=500 andm=500) nodes

bull There are 6 categories based on ini matching and probability p

28 Application

bull Probability p has been chosen as such in order to simulate the |E||V | 25 of theAmadeus bipartite graphs

bull So in order to have about 2-4 edges for every node we choose accordingly theprobability p to choose one of the n lowastm possible edges

bull x = L S L When the initial matching is large and S when it is small

bull y = 1 2 3 1 when p = 18250

2 when p = 25250

and 3 when p = 34250

Computation time over

Computation time overedges-Comments

bull

25 Bipartite 29

Sorted matching size

Sorted matching size-Comments

bull In these set of graphs one can instantly notice that only a few instances with highprobability can reach a matching size equal to the perfect matching

bull For the case of the initial matching we witness that there is a gap between the lineof the classical matching and those of the constraint and greedy results suggestingsmaller matching sizes of 10-40 edges

bull For the case of the small initial matching the result of the constraint matchingis now close to the result of the classical matching yet the greedy algorithm stillshows a relevantly big difference

30 Application

bull In this set of bipartite graphs we can witness that the result of the Constraintmatching shows a difference with the classical matching when the initial matchingis large The difference is smaller as the probability gets larger

bull For the case of the small initial matching the above phenomenom does not occuryet the greedy results deviates from that of the constraint matching

bull As per the pefrect matching compared to the classical matching a difference of5-10 edges is evident at almost all cases

Sorted Ratios

Sorted Ratios-Comments

bull Great max degree deviation

25 Bipartite 31

bull Regardless of the probability the ration of nodes and edges seems to have similarbehaviour when compared to the respective graphs of the same matching scale

bull Same gap between nodes ration and edges ration for all cases

Sorted |E||V |

Sorted |E||V | - Comments

bull In these set of figures we witness that the |E||V | acquires values relevant to those ofthe amadeus graphs The random graphs were constructed to depict this similarity

bull For smaller initial matching the ratios for G and G show the same upward trendand also they acquire closer values It represents the decrease of the averagenumber of forced edges in comparison to the larger matching cases

32 Application

Sorted ∆

Sorted ∆-Comments

bull ∆ acquires the same min and max values for each probability case (expected)

bull Gap in the case of large initial matching

26 Bipartite with degree seq

Graph characteristics

bull DEQBIPxy are randomly generated graphs based on three different types of degreedistribution of the Amadeus graphs

26 Bipartite with degree seq 33

bull There are 6 categories based on ini matching and degree distribution

bull x = L S L When the initial matching is large and S when it is small

bull y = 1 2 3 1 when degree distribution is based on file 2 when degree distributionis based on file and 3 when degree distribution is based on file

Computation time over

34 Application

Computation time overedges-Comments

bull Greedy algorithm takes minimum amount of time

bull The smaller the initial matching the more smaller the difference in comoutationtime of Constraint and classical algorithm

bull Due to preprocessing and the fact that G and G are the almost identical thetotal time needed to apply the constraint algorithm is in some cases bigger

Sorted matching size

26 Bipartite with degree seq 35

Sorted matching size-Comments

bull Classical matching is equal to perfect matching in every case

bull Constraint and greedy have identical behaviour

bull The larger the spectrum of the degree sequence the more efficient the matching

Sorted Ratios

36 Application

Sorted Ratios-Comments

bull With large initial matching most of the edges are considenred uselles or forced andare removed thus the ratio is close(if not equal to) zero

bull For small matching and large degree sequence sectrum hte max degree remainsthe same Only a few forced edges (and their nodes) are removed apparently nonodes with max degree

Sorted |E||V |

26 Bipartite with degree seq 37

Sorted |E||V | - Comments

bull In these set of figures we witness that the |E||V | acquires values relevant to those ofthe amadeus graphs The random graphs were constructed to depict this similarity

bull For smaller initial matching the ratios for G and G show the same upward trendand also they acquire closer values It repsresent the decrease of the averagenumber of forced edges in comparison to the larger matching cases

Sorted ∆

38 Application

Sorted ∆-Comments

bull Big difference in max degree in large initial matching

bull Almost identical behaviour in the case of small initial matching

Appendix A 39

Appendix A

BipartiteGraphGeneratorpy

from future import divisionimport networkx as nx

from networkxalgorithms import approximationimport collectionsimport randomimport mathfrom networkxalgorithms import bipartiteif name == main

for i in range(1481)waqs 481index=1n=randomrandint(100 1000)

n1=95 was 500me1=118

n2=251 was 500me2=903

n3=165 was 500me3=412

m=0m1=0p=randomrandom()p1=18250p2=25250p3=34250print ip=05t1=randomrandint(0 1)print im2=randomrandint(n2minus1 n2+1)G = nxGraph()ma = nxGraph()

aseq1=[1 2 3 4 5 3]

bseq1=[4 3 3 1 2 2 1]

aseq2=[16 14 14 14 12 11]bseq2=[0 0 0 0 0 0]

aseq3=[8 7 8 8 8 8]bseq3=[0 0 0 0 0 0]

40 Application

print Gnumber of edges()if ilt=160

G=bipartiteconfiguration model(aseq1 bseq1 create using=None seed=None)A=nxadjacency matrix(G)for ii in range(0n1+me1)

maadd node(ii)A=[Rtodense()tolist()[0] for R in A]

printnummanumber of nodes()rl=randomsample(range(0n1+me1) n1+me1)m=0done vertices = set()for p in rlprintin fordone verticesadd(p)

neighbors = []list()for iii in range(0n1+me1)

if A[p][iii]==1neighborsappend(iii)

randomshuffle(neighbors)continue loop = Truedegree = len(neighbors)

print degreej = 0p4=randomrandom()while continue loop and (jltdegree)print in loop

next = neighbors[j]if next not in done vertices and p not in done vertices

done verticesadd(p)done verticesadd(next)if p4gt=07print added edge

maadd edge(pnext)m=m+1

continue loop = Falsej += 1

print matching listOfedgeprint maedge

MA=nxadjacency matrix(ma)print MA

MA=[Rtodense()tolist()[0] for R in MA]print MA

B=[ join(map(strR)) for R in A]MB=[ join(map(strR)) for R in MA]

C=njoin(B)+nMC=njoin(MB)+n

print nprint mprint m1

filea=str(i)+txtwith open(fileaw) as f

Appendix A 41

fwrite(str(n1+me1))fwrite(n)fwrite(str(n1+me1))fwrite(n)fwrite(str(m))fwrite(n)fwrite(n)fwrite(C)fwrite(n)fwrite(MC)

elif igt160 and ilt321G=bipartiteconfiguration model(aseq2 bseq2 create using=None seed=None)A=nxadjacency matrix(G)for ii in range(0n2+me2)

maadd node(ii)A=[Rtodense()tolist()[0] for R in A]

printnummanumber of nodes()rl=randomsample(range(0n2+me2) n2+me2)m=0done vertices = set()for p in rlprintin fordone verticesadd(p)

neighbors = []list()for iii in range(0n2+me2)

if A[p][iii]==1neighborsappend(iii)

randomshuffle(neighbors)continue loop = Truedegree = len(neighbors)

print degreej = 0p4=randomrandom()while continue loop and (jltdegree)

print in loopnext = neighbors[j]if next not in done vertices and p not in done vertices

done verticesadd(p)done verticesadd(next)if p4gt=07

print added edgemaadd edge(pnext)m=m+1

continue loop = Falsej += 1

print matching listOfedgeprint maedge

MA=nxadjacency matrix(ma)print MA

MA=[Rtodense()tolist()[0] for R in MA]print MA

B=[ join(map(strR)) for R in A]MB=[ join(map(strR)) for R in MA]

42 Application

C=njoin(B)+nMC=njoin(MB)+n

print nprint mprint m1

filea=str(i)+txtwith open(fileaw) as f

fwrite(str(n2+me2))fwrite(n)fwrite(str(n2+me2))fwrite(n)fwrite(str(m))fwrite(n)fwrite(n)fwrite(C)fwrite(n)fwrite(MC)

elseG=bipartiteconfiguration model(aseq3 bseq3 create using=None seed=None)A=nxadjacency matrix(G)for ii in range(0n3+me3)

maadd node(ii)A=[Rtodense()tolist()[0] for R in A]

printnummanumber of nodes()rl=randomsample(range(0n3+me3) n3+me3)m=0done vertices = set()for p in rlprintin fordone verticesadd(p)

neighbors = []list()for iii in range(0n3+me3)

if A[p][iii]==1neighborsappend(iii)

randomshuffle(neighbors)continue loop = Truedegree = len(neighbors)

print degreej = 0p4=randomrandom()while continue loop and (jltdegree)

print in loopnext = neighbors[j]if next not in done vertices and p not in done vertices

done verticesadd(p)done verticesadd(next)if p4gt=07print added edge

maadd edge(pnext)m=m+1

continue loop = Falsej += 1

Appendix A 43

print matching listOfedgeprint maedge

MA=nxadjacency matrix(ma)print MA

MA=[Rtodense()tolist()[0] for R in MA]print MA

B=[ join(map(strR)) for R in A]MB=[ join(map(strR)) for R in MA]

C=njoin(B)+nMC=njoin(MB)+n

print nprint mprint m1

filea=str(i)+txtwith open(fileaw) as f

fwrite(str(n3+me3))fwrite(n)fwrite(str(n3+me3))fwrite(n)fwrite(str(m))fwrite(n)fwrite(n)fwrite(C)fwrite(n)fwrite(MC)

print nRandom graphs with random matching have been generated

44 Application

RandomGraphGeneratorpy

from future import divisionimport networkx as nxfrom networkxalgorithms import approximationimport collectionsimport randomimport mathif name == main

for i in range(1481)index=1n=randomrandint(100 1000)

n=1000m=0m1=0p=randomrandom()p1=mathlog(n2)np2=13p3=mathlog(n2)n+01p=05t1=randomrandint(0 1)print im2=randomrandint(n2minus1 n2+1)G = nxGraph()ma = nxGraph()print nme1=randomrandint(1 10)me2=randomrandint(2050)me3=randomrandint(50100)if ilt241

if ilt=80G=nxfast gnp random graph(n p1 seed=None directed=False)

elif igt80 and ilt161G=nxfast gnp random graph(n p2 seed=None directed=False)

elseG=nxfast gnp random graph(n p3 seed=None directed=False)

elseif ilt=320

G=nxbarabasi albert graph(n me1 seed=None)elif igt320 and ilt401

G=nxbarabasi albert graph(n me2 seed=None)else

G=nxbarabasi albert graph(n me3 seed=None)A=nxadjacency matrix(G)for ii in range(0n)

maadd node(ii)A=[Rtodense()tolist()[0] for R in A]

rl=randomsample(range(0n) n)m=0

Appendix A 45

done vertices = set()for p in rl

done verticesadd(p)neighbors = []list()for iii in range(0n)

if A[p][iii]==1neighborsappend(iii)

randomshuffle(neighbors)continue loop = Truedegree = len(neighbors)j = 0p2=randomrandom()while continue loop and (jltdegree)

next = neighbors[j]if next not in done vertices and p not in done vertices

done verticesadd(p)done verticesadd(next)if p2gt=00 Larger probability for smaller initial matching

maadd edge(pnext)m=m+1

continue loop = Falsej += 1

print matching listOfedgeprint maedgeMA=nxadjacency matrix(ma)MA=[Rtodense()tolist()[0] for R in MA]print MAB=[ join(map(strR)) for R in A]MB=[ join(map(strR)) for R in MA]

C=njoin(B)+nMC=njoin(MB)+nprint MCprint nprint mprint m1filea=str(i)+txtwith open(fileaw) as f

fwrite(str(n))fwrite(n)fwrite(str(n))fwrite(n)fwrite(str(m))fwrite(n)fwrite(n)fwrite(C)fwrite(n)fwrite(MC)

print nRandom graphs with random matching have been generated

46 Application

kequals3MaximumMatchingpy

from future import divisionimport networkx as nxfrom networkxalgorithms import bipartiteimport matplotlibpyplot as pltimport collectionsimport timeitimport xlwtimport xlrdimport mathimport sys

Case for General Graphsdef forced edges(Gadj dict2matching dict1num nodesforced)

flagg=0for n in range(0num nodes)

for k in adj dict2[n]if ([k]==matching dict1[n])

count=0for l in range(0num nodes)

count=count+adj dict2[l]count(k)if (len(adj dict2[n])==1) or (count==1)

forcedadd edge(nk)Gremove edge(nk)Gremove node(n)Gremove node(k)printforced edgenktemp=kflagg=1for m in range (len(adj dict2[n])minus1minus1minus1)

adj dict2[adj dict2[n][m]]remove(n)adj dict2[n]remove(adj dict2[n][m])

if adj dict2[temp]for l in range(len(adj dict2[temp])minus1minus1minus1)

if (adj dict2[temp][l]=n)adj dict2[adj dict2[temp][l]]remove(temp)adj dict2[temp]remove(adj dict2[temp][l])

break

def useless edges(num nodesadj dict1matching dict1uselessadj dict2G)for n in range(0num nodes)

for k in adj dict1[n]if ([k]=matching dict1[n]) and matching dict1[n] and matching dict1[k]

uselessadd edge(nk)Gremove edge(n k)

Appendix A 47

tempa=kadj dict2[n]remove(k)adj dict2[tempa]remove(n)adj dict1[tempa]remove(n)

return G

def Greedy(num nodesadj dict3matching dict2)

for n in range(0num nodes)if matching dict2[n]

flag2=minus1flag3=minus1for v in adj dict3[n]

if not matching dict2[v]flag2=vbreak

for p in adj dict3[matching dict2[n][0]]if not matching dict2[p]

flag3=pbreak

if (flag2=minus1) and (flag3=minus1) and (flag2=flag3)tempr=matching dict2[n][0]matching dict2[n]=[flag2]matching dict2[flag2]=[n]matching dict2[tempr]=[flag3]matching dict2[flag3]=[tempr]

elsefor k in adj dict3[n]

if not matching dict2[k]matching dict2[n]=[k]matching dict2[k]=[n]break

yo1=0for i in range(0num nodes)

if matching dict2[i] and [i]==matching dict2[matching dict2[i][0]]yo1=yo1+1

greedy size=yo12return greedy size

def General()

INPUTSwb = xlwtWorkbook()ws = wbadd sheet(Results Random)book=xlrdopen workbook(filenames randomxls)

48 Application

style0 = xlwteasyxf(fontbold on)style1 = xlwteasyxf(num format str=0000)INPUTSwswrite(0 0File style0)wswrite(0 1 Nodesstyle0)wswrite(0 2 Initial matchingstyle0)wswrite(0 3 NodesGstyle0)wswrite(0 4 EdgesGstyle0)wswrite(0 5 MaxDegreeGstyle0)wswrite(0 6 NodesG hatstyle0)wswrite(0 7 EdgesG Hatstyle0)wswrite(0 8 Useless edgesstyle0)wswrite(0 9 Forced edgesstyle0)wswrite(0 10 MaxDegreeG Hatstyle0)wswrite(0 11 Classical matchingstyle0)wswrite(0 12 Final matchingstyle0)wswrite(0 13 Greedy matchingstyle0)wswrite(0 14 Time classicalstyle0)wswrite(0 15 Time algorithmstyle0)wswrite(0 16 Time greedystyle0)wswrite(0 17 Perfect matching ratiostyle0)wswrite(0 18 Nodes ratiostyle0)wswrite(0 19 Edges ratiostyle0)wswrite(0 20 Matching ratiostyle0)

print nWelcomeThis is an implementation for general random graphs It uses Edmonds algorithm to compute maximum matching on G Hatn

for index in range (1481)was 481

if (index==482)f=open(Algotel generaltxtr)readlines()

elsefilea=str(booksheet by index(0)cell(index0))s=fileareplace(textu)replace()f=open(sr)readlines()Truewswrite(index 0 s)

print index

num nodes=int([xstrip()split() for x in f][0][0])

num matching=int([xstrip()split() for x in f][2][0])

adj temp = [xstrip()split() for x in f][44+num nodes]adj=[map(intR) for R in adj temp]

matching temp=[xstrip()split() for x in f][4+num nodes+14+2num nodes+1]matching1=[map(intR) for R in matching temp]

adj dict1=i[ii for iix in enumerate(L) if x] for iL in enumerate(adj)adj dict2=i[ii for iix in enumerate(L) if x] for iL in enumerate(adj)

Appendix A 49

adj dict3=i[ii for iix in enumerate(L) if x] for iL in enumerate(adj)

matching dict1=i[ii for iix in enumerate(L) if x] for iL in enumerate(matching1)matching dict2=i[ii for iix in enumerate(L) if x] for iL in enumerate(matching1)print adj dict2print matching dict2wswrite(index 1 num nodes)wswrite(index 2 num matching)

G = nxGraph()

useless= nxGraph()forced = nxGraph()

Fill Graphfor n in range(0num nodes)

for k in adj dict1[n]Gadd edge(nk)

Gt=Gnumber of edges()wswrite(index 3 Gnumber of nodes())wswrite(index 4 Gnumber of edges())wswrite(index 5 max(Gdegree()values()))

Compute Edmonds classical matching on G for comparison

startB = timeitdefault timer()Classical Matching=nxmax weight matching(G maxcardinality=False)stopB = timeitdefault timer()

Compute Gˆ nad MˆstartC = timeitdefault timer()useless edges(num nodesadj dict1matching dict1uselessadj dict2G)forced edges(Gadj dict2matching dict1num nodesforced)Final Matching=nxmax weight matching(G maxcardinality=False)stopC = timeitdefault timer()

GreedystartG = timeitdefault timer()greedy size=Greedy(num nodesadj dict3matching dict2)stopG = timeitdefault timer()

wswrite(index 6 Gnumber of nodes())wswrite(index 7 Gnumber of edges())wswrite(index 8 uselessnumber of edges())wswrite(index 9 forcednumber of edges())if Gdegree()values()

wswrite(index 10 max(Gdegree()values()))else

50 Application

wswrite(index 10 0)wswrite(index 11 len(Classical Matching)2)wswrite(index 12 len(Final Matching)2+forcednumber of edges())wswrite(index 13 greedy size)wswrite(index 14 stopB minus startBstyle1)wswrite(index 15 stopC minus startCstyle1)wswrite(index 16 stopG minus startGstyle1)wswrite(index 17 (len(Final Matching)2+forcednumber of edges())(num nodes2)style1)wswrite(index 18 Gnumber of nodes()Gtstyle1)wswrite(index 19 Gnumber of edges()Gtstyle1)wswrite(index 20 (len(Final Matching)2+forcednumber of edges())(len(Classical Matching)2)style1)

wbsave(AA Results Random Reyni Large Bipartitexls)

Main function Here we must choose the input form of the dataif name == main

startA = timeitdefault timer()General()stopA = timeitdefault timer()

print nThis program has terminatednnRunning time for 480 files stopAminusstartAprint nnPlease open AA Results Random Reyni Largexls file to see the Results

Appendix A 51

Plotmat

clear allclose allload(RN1Lmat)load(RN1Smat)load(RN2Lmat)load(RN2Smat)load(RN3Lmat)load(RN3Smat)

Plotsh(1)=figure(NameHistogram of Matching size difference between Constraint Algorithm and Greedy AlgorithmNumberTitleoff)

RN1L Greedydiff=RN1L Final matchingminusRN1L Greedy matchingRN2L Greedydiff=RN2L Final matchingminusRN2L Greedy matchingRN3L Greedydiff=RN3L Final matchingminusRN3L Greedy matchingRN1S Greedydiff=RN1S Final matchingminusRN1S Greedy matchingRN2S Greedydiff=RN2S Final matchingminusRN2S Greedy matchingRN3S Greedydiff=RN3S Final matchingminusRN3S Greedy matching

RN1L Finaldiff=RN1L Classical matchingminusRN1L Final matchingRN2L Finaldiff=RN2L Classical matchingminusRN2L Final matchingRN3L Finaldiff=RN3L Classical matchingminusRN3L Final matchingRN1S Finaldiff=RN1S Classical matchingminusRN1S Final matchingRN2S Finaldiff=RN2S Classical matchingminusRN2S Final matchingRN3S Finaldiff=RN3S Classical matchingminusRN3S Final matching

RN1L Classicaldiff=(RN1L Nodes2)minusRN1L Classical matchingRN2L Classicaldiff=(RN2L Nodes2)minusRN2L Classical matchingRN3L Classicaldiff=(RN3L Nodes2)minusRN3L Classical matchingRN1S Classicaldiff=(RN1S Nodes2)minusRN1S Classical matchingRN2S Classicaldiff=(RN2S Nodes2)minusRN2S Classical matchingRN3S Classicaldiff=(RN3S Nodes2)minusRN3S Classical matching

subplot(231)hold onhistf(RN1L Greedydiff0110facecolorbfacealpha9edgealpha1)histf(RN1L Finaldiff0110facecolorrfacealpha5edgealpha1)histf(RN1L Classicaldiff0110facecolorgfacealpha5edgealpha1)legalpha(ConminusGreClasminusConPerfminusClasslocationnortheast)legend boxoffaxis tightxlabel(edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN1L)grid on

subplot(232)hold onhistf(RN2L Greedydiff0110facecolorbfacealpha9edgealpha1)

52 Application

histf(RN2L Finaldiff0110facecolorrfacealpha5edgealpha1)histf(RN2L Classicaldiff0110facecolorgfacealpha5edgealpha1)legalpha(ConminusGreClasminusConPerfminusClasslocationnortheast)legend boxoffaxis tightxlabel(edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN2L)grid on

subplot(233)hold onhistf(RN3L Greedydiff0110facecolorbfacealpha5edgealpha1)histf(RN3L Finaldiff0110facecolorrfacealpha5edgealpha1)histf(RN3L Classicaldiff0110facecolorgfacealpha5edgealpha1)legalpha(ConminusGreClasminusConPerfminusClasslocationnortheast)legend boxoffaxis tightxlabel(edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN3L)grid on

subplot(234)hold onhistf(RN1S Greedydiff0110facecolorbfacealpha5edgealpha1)histf(RN1S Finaldiff0110facecolorrfacealpha5edgealpha1)histf(RN1S Classicaldiff0110facecolorgfacealpha5edgealpha1)legalpha(ConminusGreClasminusConPerfminusClasslocationnortheast)legend boxoffaxis tightxlabel(edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(R1NS)grid on

subplot(235)hold onhistf(RN2S Greedydiff0110facecolorbfacealpha5edgealpha1)histf(RN2S Finaldiff0110facecolorrfacealpha5edgealpha1)histf(RN2S Classicaldiff0110facecolorgfacealpha5edgealpha1)legalpha(ConminusGreClasminusConPerfminusClasslocationnortheast)legend boxoffaxis tightxlabel(edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN2S)grid on

subplot(236)hold onhistf(RN3S Greedydiff0110facecolorbfacealpha5edgealpha1)histf(RN3S Finaldiff0110facecolorrfacealpha5edgealpha1)histf(RN3S Classicaldiff0110facecolorgfacealpha5edgealpha1)

Appendix A 53

legalpha(ConminusGreClasminusConPerfminusClasslocationnortheast)legend boxoffaxis tightgrid ontitle(RN3S)xlabel(edges) xminusaxis labelylabel(instances) yminusaxis labelset(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN1png minusr300)h(2)=figure(NameHistogram of Max Degree of G AND G HatNumberTitleoff)RN1L x=RN1L MaxDegreeGminusRN1L MaxDegreeG HatRN2L x=RN2L MaxDegreeGminusRN2L MaxDegreeG HatRN3L x=RN3L MaxDegreeGminusRN3L MaxDegreeG HatRN1S x=RN1S MaxDegreeGminusRN1S MaxDegreeG HatRN2S x=RN2S MaxDegreeGminusRN2S MaxDegreeG HatRN3S x=RN3S MaxDegreeGminusRN3S MaxDegreeG Hatsubplot(231)hold onhistf(RN1L MaxDegreeG0150facecolorbfacealpha5edgealpha1)histf(RN1L MaxDegreeG Hat0150facecolorrfacealpha5edgealpha1)histf(RN1L x0150facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightxlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN1L)grid on

subplot(232)hold onhistf(RN2L MaxDegreeG010500facecolorbfacealpha5edgealpha1)histf(RN2L MaxDegreeG Hat010500facecolorrfacealpha5edgealpha1)histf(RN2L x010500facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightxlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN2L)grid on

subplot(233)hold onhistf(RN3L MaxDegreeG010300facecolorbfacealpha5edgealpha1)histf(RN3L MaxDegreeG Hat010300facecolorrfacealpha5edgealpha1)histf(RN3L x010300facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightxlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN3L)

54 Application

grid on

subplot(234)hold onhistf(RN1S MaxDegreeG0150facecolorbfacealpha5edgealpha1)histf(RN1S MaxDegreeG Hat0150facecolorrfacealpha5edgealpha1)histf(RN1S x0150facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightxlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(R1NS)grid on

subplot(235)hold onhistf(RN2S MaxDegreeG010500facecolorbfacealpha5edgealpha1)histf(RN2S MaxDegreeG Hat010500facecolorrfacealpha5edgealpha1)histf(RN2S x010500facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightxlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN2S)grid on

subplot(236)hold onhistf(RN3S MaxDegreeG05300facecolorbfacealpha5edgealpha1)histf(RN3S MaxDegreeG Hat05300facecolorrfacealpha5edgealpha1)histf(RN3S x05300facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightgrid ontitle(RN3S)xlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labelset(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN2png minusr300)

h(3)=figure(NameComputation time over edgesNumberTitleoff)

subplot(231)hold onstem(RN1L EdgesGRN1L Time classicalg)stem(RN1L EdgesGRN1L Time algorithmro)stem(RN1L EdgesGRN1L Time greedybx)grid on

Appendix A 55

title(RN1L)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)

subplot(232)hold onstem(RN2L EdgesGRN2L Time classicalg)stem(RN2L EdgesGRN2L Time algorithmro)stem(RN2L EdgesGRN2L Time greedybx)grid ontitle(RN2L)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)

subplot(233)hold onstem(RN3L EdgesGRN3L Time classicalg)stem(RN3L EdgesGRN3L Time algorithmro)stem(RN3L EdgesGRN3L Time greedybx)grid ontitle(RN3L)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)

subplot(234)hold onstem(RN1S EdgesGRN1S Time classicalg)stem(RN1S EdgesGRN1S Time algorithmro)stem(RN1S EdgesGRN1S Time greedybx)grid ontitle(RN1S)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)

subplot(235)hold onstem(RN2S EdgesGRN2S Time classicalg)stem(RN2S EdgesGRN2S Time algorithmro)stem(RN2S EdgesGRN2S Time greedybx)grid ontitle(RN2S)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)

subplot(236)hold onstem(RN3S EdgesGRN3S Time classicalg)stem(RN3S EdgesGRN3S Time algorithmro)stem(RN3S EdgesGRN3S Time greedybx)

56 Application

grid ontitle(RN3S)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)set(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN3png minusr300)

h(4)=figure(NameSorted matching sizeNumberTitleoff)RN1L Sorted matching temp(1)=RN1L Classical matchingRN1L Sorted matching temp(2)=RN1L Final matchingRN1L Sorted matching temp(3)=RN1L Greedy matchingRN1L Sorted matching temp(4)=RN1L Initial matchingRN1L Sorted matching=sortrows(RN1L Sorted matching temp)

RN2L Sorted matching temp(1)=RN2L Classical matchingRN2L Sorted matching temp(2)=RN2L Final matchingRN2L Sorted matching temp(3)=RN2L Greedy matchingRN2L Sorted matching temp(4)=RN2L Initial matchingRN2L Sorted matching=sortrows(RN2L Sorted matching temp)

RN3L Sorted matching temp(1)=RN3L Classical matchingRN3L Sorted matching temp(2)=RN3L Final matchingRN3L Sorted matching temp(3)=RN3L Greedy matchingRN3L Sorted matching temp(4)=RN3L Initial matchingRN3L Sorted matching=sortrows(RN3L Sorted matching temp)

RN1S Sorted matching temp(1)=RN1S Classical matchingRN1S Sorted matching temp(2)=RN1S Final matchingRN1S Sorted matching temp(3)=RN1S Greedy matchingRN1S Sorted matching temp(4)=RN1S Initial matchingRN1S Sorted matching=sortrows(RN1S Sorted matching temp)

RN2S Sorted matching temp(1)=RN2S Classical matchingRN2S Sorted matching temp(2)=RN2S Final matchingRN2S Sorted matching temp(3)=RN2S Greedy matchingRN2S Sorted matching temp(4)=RN2S Initial matchingRN2S Sorted matching=sortrows(RN2S Sorted matching temp)

RN3S Sorted matching temp(1)=RN3S Classical matchingRN3S Sorted matching temp(2)=RN3S Final matchingRN3S Sorted matching temp(3)=RN3S Greedy matchingRN3S Sorted matching temp(4)=RN3S Initial matchingRN3S Sorted matching=sortrows(RN3S Sorted matching temp)

subplot(231)hold onplot(RN1L Sorted matching(1)b)plot(RN1L Sorted matching(2)g)plot(RN1L Sorted matching(3)r)plot(RN1L Sorted matching(4)m)

Appendix A 57

grid ontitle(RN1L)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)

subplot(232)hold onplot(RN2L Sorted matching(1)b)plot(RN2L Sorted matching(2)g)plot(RN2L Sorted matching(3)r)plot(RN2L Sorted matching(4)m)grid ontitle(RN2L)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)

subplot(233)hold onplot(RN3L Sorted matching(1)b)plot(RN3L Sorted matching(2)g)plot(RN3L Sorted matching(3)r)plot(RN3L Sorted matching(4)m)grid ontitle(RN3L)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)

subplot(234)hold onplot(RN1S Sorted matching(1)b)plot(RN1S Sorted matching(2)g)plot(RN1S Sorted matching(3)r)plot(RN1S Sorted matching(4)m)grid ontitle(RN1S)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)

subplot(235)hold onplot(RN2S Sorted matching(1)b)plot(RN2S Sorted matching(2)g)plot(RN2S Sorted matching(3)r)plot(RN2S Sorted matching(4)m)grid ontitle(RN2S)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)

58 Application

subplot(236)hold onplot(RN3S Sorted matching(1)b)plot(RN3S Sorted matching(2)g)plot(RN3S Sorted matching(3)r)plot(RN3S Sorted matching(4)m)grid ontitle(RN3S)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)set(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN4png minusr300)h(5)=figure(NameSorted RatiosNumberTitleoff)RN1L ratio1=RN1L NodesG hatRN1L NodesGRN2L ratio1=RN2L NodesG hatRN2L NodesGRN3L ratio1=RN3L NodesG hatRN3L NodesGRN1S ratio1=RN1S NodesG hatRN1S NodesGRN2S ratio1=RN2S NodesG hatRN2S NodesGRN3S ratio1=RN3S NodesG hatRN3S NodesG

RN1L ratio2=RN1L EdgesG HatRN1L EdgesGRN2L ratio2=RN2L EdgesG HatRN2L EdgesGRN3L ratio2=RN3L EdgesG HatRN3L EdgesGRN1S ratio2=RN1S EdgesG HatRN1S EdgesGRN2S ratio2=RN2S EdgesG HatRN2S EdgesGRN3S ratio2=RN3S EdgesG HatRN3S EdgesG

RN1L ratio3=RN1L MaxDegreeG HatRN1L MaxDegreeGRN2L ratio3=RN2L MaxDegreeG HatRN2L MaxDegreeGRN3L ratio3=RN3L MaxDegreeG HatRN3L MaxDegreeGRN1S ratio3=RN1S MaxDegreeG HatRN1S MaxDegreeGRN2S ratio3=RN2S MaxDegreeG HatRN2S MaxDegreeGRN3S ratio3=RN3S MaxDegreeG HatRN3S MaxDegreeG

RN1L ratio(1)=RN1L ratio1RN1L ratio(2)=RN1L ratio2RN1L ratio(3)=RN1L ratio3

RN2L ratio(1)=RN2L ratio1RN2L ratio(2)=RN2L ratio2RN2L ratio(3)=RN2L ratio3

RN3L ratio(1)=RN3L ratio1RN3L ratio(2)=RN3L ratio2RN3L ratio(3)=RN3L ratio3

RN1S ratio(1)=RN1S ratio1RN1S ratio(2)=RN1S ratio2RN1S ratio(3)=RN1S ratio3

RN2S ratio(1)=RN2S ratio1

Appendix A 59

RN2S ratio(2)=RN2S ratio2RN2S ratio(3)=RN2S ratio3

RN3S ratio(1)=RN3S ratio1RN3S ratio(2)=RN3S ratio2RN3S ratio(3)=RN3S ratio3

RN1L ratio sorted=sortrows(RN1L ratio)RN2L ratio sorted=sortrows(RN2L ratio)RN3L ratio sorted=sortrows(RN3L ratio)RN1S ratio sorted=sortrows(RN1S ratio)RN2S ratio sorted=sortrows(RN2S ratio)RN3S ratio sorted=sortrows(RN3S ratio)

subplot(231)hold onplot(RN1L ratio sorted(1)b)plot(RN1L ratio sorted(2)g)plot(RN1L ratio sorted(3)r)grid ontitle(RN1L)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)

subplot(232)hold onplot(RN2L ratio sorted(1)b)plot(RN2L ratio sorted(2)g)plot(RN2L ratio sorted(3)r)grid ontitle(RN2L)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)

subplot(233)hold onplot(RN3L ratio sorted(1)b)plot(RN3L ratio sorted(2)g)plot(RN3L ratio sorted(3)r)grid ontitle(RN3L)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)

subplot(234)hold onplot(RN1S ratio sorted(1)b)plot(RN1S ratio sorted(2)g)plot(RN1S ratio sorted(3)r)grid on

60 Application

title(RN1S)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)

subplot(235)hold onplot(RN2S ratio sorted(1)b)plot(RN2S ratio sorted(2)g)plot(RN2S ratio sorted(3)r)grid ontitle(RN2S)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)

subplot(236)hold onplot(RN3S ratio sorted(1)b)plot(RN3S ratio sorted(2)g)plot(RN3S ratio sorted(3)r)grid ontitle(RN3S)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)set(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN5png minusr300)

h(6)=figure(NameSorted edges over nodesNumberTitleoff)

RN1L DegreeG1=(RN1L EdgesG)(RN1L NodesG)RN1L DegreeG Hat1=(RN1L EdgesG Hat)(RN1L NodesG hat)

RN1L Degree temp1(1)=RN1L DegreeG1RN1L Degree temp1(2)=RN1L DegreeG Hat1RN1L Degree sorted1=sortrows(RN1L Degree temp1)subplot(231)hold on

plot(RN1L Degree sorted1(1)b)plot(RN1L Degree sorted1(2)g)grid ontitle(RN1L)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)

RN2L DegreeG1=(RN2L EdgesG)(RN2L NodesG)RN2L DegreeG Hat1=(RN2L EdgesG Hat)(RN2L NodesG hat)

RN2L Degree temp1(1)=RN2L DegreeG1

Appendix A 61

RN2L Degree temp1(2)=RN2L DegreeG Hat1RN2L Degree sorted1=sortrows(RN2L Degree temp1)

subplot(232)hold onplot(RN2L Degree sorted1(1)b)plot(RN2L Degree sorted1(2)g)grid ontitle(RN2L)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)

RN3L DegreeG1=(RN3L EdgesG)(RN3L NodesG)RN3L DegreeG Hat1=(RN3L EdgesG Hat)(RN3L NodesG hat)

RN3L Degree temp1(1)=RN3L DegreeG1RN3L Degree temp1(2)=RN3L DegreeG Hat1RN3L Degree sorted1=sortrows(RN3L Degree temp1)

subplot(233)hold onplot(RN3L Degree sorted1(1)b)plot(RN3L Degree sorted1(2)g)grid ontitle(RN3L)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)

RN1S DegreeG1=(RN1S EdgesG)(RN1S NodesG)RN1S DegreeG Hat1=(RN1S EdgesG Hat)(RN1S NodesG hat)

RN1S Degree temp1(1)=RN1S DegreeG1RN1S Degree temp1(2)=RN1S DegreeG Hat1RN1S Degree sorted1=sortrows(RN1S Degree temp1)

subplot(234)hold onplot(RN1S Degree sorted1(1)b)plot(RN1S Degree sorted1(2)g)grid ontitle(RN1S)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)

RN2S DegreeG1=(RN2S EdgesG)(RN2S NodesG)RN2S DegreeG Hat1=(RN2S EdgesG Hat)(RN2S NodesG hat)

RN2S Degree temp1(1)=RN2S DegreeG1

62 Application

RN2S Degree temp1(2)=RN2S DegreeG Hat1RN2S Degree sorted1=sortrows(RN2S Degree temp1)

subplot(235)hold onplot(RN2S Degree sorted1(1)b)plot(RN2S Degree sorted1(2)g)grid ontitle(RN2S)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)

RN3S DegreeG1=(RN3S EdgesG)(RN3S NodesG)RN3S DegreeG Hat1=(RN3S EdgesG Hat)(RN3S NodesG hat)

RN3S Degree temp1(1)=RN3S DegreeG1RN3S Degree temp1(2)=RN3S DegreeG Hat1RN3S Degree sorted1=sortrows(RN3S Degree temp1)

subplot(236)hold onplot(RN3S Degree sorted1(1)b)plot(RN3S Degree sorted1(2)g)grid ontitle(RN3S)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)set(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN6png minusr300)h(7)=figure(NameSorted mATCHED DEGREENumberTitleoff)RN1L ratioMax(1)=RN1L MaxDegreeGRN1L ratioMax(2)=RN1L MaxDegreeG Hat

RN1L ratio sortedMax=sortrows(RN1L ratioMax)subplot(231)hold onplot(RN1L ratio sortedMax(1)b)plot(RN1L ratio sortedMax(2)g)grid ontitle(RN1L)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)

RN2L ratioMax(1)=RN2L MaxDegreeGRN2L ratioMax(2)=RN2L MaxDegreeG Hat

RN2L ratio sortedMax=sortrows(RN2L ratioMax)subplot(232)

Appendix A 63

hold onplot(RN2L ratio sortedMax(1)b)plot(RN2L ratio sortedMax(2)g)grid ontitle(RN2L)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)

RN3L ratioMax(1)=RN3L MaxDegreeGRN3L ratioMax(2)=RN3L MaxDegreeG Hat

RN3L ratio sortedMax=sortrows(RN3L ratioMax)subplot(233)hold onplot(RN3L ratio sortedMax(1)b)plot(RN3L ratio sortedMax(2)g)grid ontitle(RN3L)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)

RN1S ratioMax(1)=RN1S MaxDegreeGRN1S ratioMax(2)=RN1S MaxDegreeG Hat

RN1S ratio sortedMax=sortrows(RN1S ratioMax)subplot(234)hold onplot(RN1S ratio sortedMax(1)b)plot(RN1S ratio sortedMax(2)g)grid ontitle(RN1S)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)

RN2S ratioMax(1)=RN2S MaxDegreeGRN2S ratioMax(2)=RN2S MaxDegreeG Hat

RN2S ratio sortedMax=sortrows(RN2S ratioMax)

subplot(235)hold onplot(RN2S ratio sortedMax(1)b)plot(RN2S ratio sortedMax(2)g)grid ontitle(RN2S)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)

RN3S ratioMax(1)=RN3S MaxDegreeGRN3S ratioMax(2)=RN3S MaxDegreeG Hat

64 Application

RN3S ratio sortedMax=sortrows(RN3S ratioMax)subplot(236)hold onplot(RN3S ratio sortedMax(1)b)plot(RN3S ratio sortedMax(2)g)grid ontitle(RN1L)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)set(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN7png minusr300)

tilefigs()(h)

Bibliography

[1] C Berge ldquoTWO THEOREMS IN GRAPH THEORYrdquo Proceedings of the NationalAcademy of Sciences of the United States of America vol 43 no 9 pp 842ndash844Sep 1957

[2] L Bui S Sanghavi and R Srikant ldquoDistributed link scheduling with constantoverheadrdquo IEEEACM Trans Netw vol 17 no 5 pp 1467ndash1480 2009

[3] R Duan and S Pettie ldquoLinear-time approximation for maximum weight matchingrdquoJ ACM vol 61 no 1 2014

[4] J Edmonds ldquoPaths trees and flowersrdquo Canadian Journal of Mathematics vol 17pp 449ndash467 1965

[5] J E Hopcroft and R M Karp ldquoAn n52 algorithm for maximum matchings inbipartite graphsrdquo SIAM J Comput vol 2 no 4 pp 225ndash231 1973

[6] S Micali and V V Vazirani ldquoAn O(radic|V ||E|) algorithm for finding maximum

matching in general graphsrdquo in 21st Symp on Foundations of Comp Sc (FOCS)IEEE 1980 pp 17ndash27

[7] N Nisse A Salch and V Weber ldquoRecovery of disrupted airline operationsrdquo 2015httphalinriafrSomething

[8] X Wu and R Srikant ldquoRegulated maximal matching A distributed schedulingalgorithm for multi-hop wireless networks with nodeexclusive spectrum sharingrdquo inIEEE Conf on Decision and Control 2005

65

  • Contents
  • Introduction
  • Algorithms
    • Maximum matching
    • k-maximum matching
      • k-matching for Airport Slot assignment
      • The case where k=3
      • The case of Paths
      • The case of the Spider
          • Application
            • Description
            • Reyni Erdos
            • Barabaacutesi Albert
            • Amadeus Graphs
            • Bipartite
            • Bipartite with degree seq
            • Appendix A
              • BipartiteGraphGeneratorpy
              • RandomGraphGeneratorpy
              • kequals3MaximumMatchingpy
              • Plotmat
                  • Bibliography
Page 18: Theodoros Alexandros KARAGKIOULES -  · Introduction This work is the result of a 6 months internship, under the supervision of research O cer Nicolas NISSE. The original scope of

23 Barabasi Albert 19

matching size compared to that of the perfect matching could be up to 40 ofthat of the matching size So there are occasions where the matching size is 200edges when the perfect matching would have been 500

bull the difference between the Constraint matching and the classical matching andthe difference of the constraint matching and that of the greedy matching do notshow significant values

Sorted Ratios

Sorted Ratio s -Comments

bull This set of figures depicts the ratios VV

EE

∆∆

in ascending order of VV

20 Application

bull It is evident that when the initial matching is large the amount of forced edges(and their endpoints) removed is high thus the ratio of Nodes and edges is verylow For higher probabilities almost all edges are removed as useless

bull For a smaller initial matching almost no forced edges (and their endpoints) areremoved which we conclude be the node ration being close to 1 There is somesmall amount of useless edges removed though since the ratio of edges is less butclose to 1

bull The ratio of ∆ for large initial matching follows the trend of the node ratio yetfor smaller initial matching it deviates significantly

Sorted |E||V |

23 Barabasi Albert 21

Sorted |E||V | - Comments

bull Although as graph density the ratio 2|E||V |(|V |minus1)

is considered in this set of figures

we evaluate the correlation of the ratio |E||V | of G and G since the density of G

could acquire values higher than that of G

bull The figures are calculated in ascending order for the ratio of G

bull For the case of large initial matching the two ratios for G and G remain almostconstant ( to the extent of the edge attraction m of each graph) since removingforced edges( and their endpoints) alters the |E| and |V | proportionately

bull For the case of small initial matching we observe some deviation in the valuesof the ration for G and that is explained with the removal of only useless edgeswhich only alters the |E| and keeps |V | in the original values

Sorted ∆

22 Application

Sorted ∆-Comments

bull In this set of figures the ascending order of the ∆ of G is associated with the ∆of G

bull There is a significant jump of the ∆ for each graph category which tells that thatwe are not comparing a uniform distribution of random graphs and based on theedge attraction m the graphs can vary in form

bull For larger initial matching we observe the difference in the ∆s of G and G giventhe removed forced edges( and their endpoints) At some cases the ∆ of G dropsto 0 since the vast majority of edges have been declared forced and removed alongwith their endpoints What is interesting is that the ∆ of G oscilates within stablelimits

24 Amadeus Graphs 23

bull For smaller initial matching the ∆s of G and G follow mostly the same trend onlya few number of different instances

24 Amadeus Graphs

Graph characteristics Amadeus graphs

bull These are the bipartite graphs provided by Amadeus

Computation time over |E|

Computation time over |E| - Comments

24 Application

bull For every instance the computation time of the classical algorithm is always smallerto that of the constraint matching

bull This allows as to speculate that we always compute a smaller G which also impliesthat we always find a set of forced edges and useless

Sorted matching size

Sorted matching size - Comments

bull Size of matching has an upward trend since the magnitude of the graphs is notthe same for the 160 instances

bull No significant deviation is noticed as per the first graph

24 Amadeus Graphs 25

bull Except from deviation from the perfect matching (number of flights) where some-times it could get up to 40

bull For the Amadeus Bipartite graphs we can see that the difference of the Classicaland the constraint implementation is not more than 1 edge in the matching

bull There appears to be a difference of up to 24 edges between the Classical matchingand the Perfect matching which is computed as the number of flights

bull The greedy algorithm performs well with only a few instances deviating slightlyform the Constraint algorithm result

Sorted Ratios

Sorted Ratios - Comments

26 Application

bull

Sorted |E||V |

Sorted |E||V | - Comments

bull Density of the graphs shows that on average we have 25-3 available time slot perflight

bull The line for the same value for G shows that there is a large deviation for everyinstance which allows for the hypothesis that the amount of useless+forced edgesof G has no obvious correlation to that of G

25 Bipartite 27

Sorted ∆

Sorted ∆-Comments

bull As per the previous related graphs for ∆ there is in significant drop in the ∆ of Gand G

25 Bipartite

Graph characteristics Bipartite random Graphs

bull BIPxy are randomly generated graphs with a fixed number of 1000(n=500 andm=500) nodes

bull There are 6 categories based on ini matching and probability p

28 Application

bull Probability p has been chosen as such in order to simulate the |E||V | 25 of theAmadeus bipartite graphs

bull So in order to have about 2-4 edges for every node we choose accordingly theprobability p to choose one of the n lowastm possible edges

bull x = L S L When the initial matching is large and S when it is small

bull y = 1 2 3 1 when p = 18250

2 when p = 25250

and 3 when p = 34250

Computation time over

Computation time overedges-Comments

bull

25 Bipartite 29

Sorted matching size

Sorted matching size-Comments

bull In these set of graphs one can instantly notice that only a few instances with highprobability can reach a matching size equal to the perfect matching

bull For the case of the initial matching we witness that there is a gap between the lineof the classical matching and those of the constraint and greedy results suggestingsmaller matching sizes of 10-40 edges

bull For the case of the small initial matching the result of the constraint matchingis now close to the result of the classical matching yet the greedy algorithm stillshows a relevantly big difference

30 Application

bull In this set of bipartite graphs we can witness that the result of the Constraintmatching shows a difference with the classical matching when the initial matchingis large The difference is smaller as the probability gets larger

bull For the case of the small initial matching the above phenomenom does not occuryet the greedy results deviates from that of the constraint matching

bull As per the pefrect matching compared to the classical matching a difference of5-10 edges is evident at almost all cases

Sorted Ratios

Sorted Ratios-Comments

bull Great max degree deviation

25 Bipartite 31

bull Regardless of the probability the ration of nodes and edges seems to have similarbehaviour when compared to the respective graphs of the same matching scale

bull Same gap between nodes ration and edges ration for all cases

Sorted |E||V |

Sorted |E||V | - Comments

bull In these set of figures we witness that the |E||V | acquires values relevant to those ofthe amadeus graphs The random graphs were constructed to depict this similarity

bull For smaller initial matching the ratios for G and G show the same upward trendand also they acquire closer values It represents the decrease of the averagenumber of forced edges in comparison to the larger matching cases

32 Application

Sorted ∆

Sorted ∆-Comments

bull ∆ acquires the same min and max values for each probability case (expected)

bull Gap in the case of large initial matching

26 Bipartite with degree seq

Graph characteristics

bull DEQBIPxy are randomly generated graphs based on three different types of degreedistribution of the Amadeus graphs

26 Bipartite with degree seq 33

bull There are 6 categories based on ini matching and degree distribution

bull x = L S L When the initial matching is large and S when it is small

bull y = 1 2 3 1 when degree distribution is based on file 2 when degree distributionis based on file and 3 when degree distribution is based on file

Computation time over

34 Application

Computation time overedges-Comments

bull Greedy algorithm takes minimum amount of time

bull The smaller the initial matching the more smaller the difference in comoutationtime of Constraint and classical algorithm

bull Due to preprocessing and the fact that G and G are the almost identical thetotal time needed to apply the constraint algorithm is in some cases bigger

Sorted matching size

26 Bipartite with degree seq 35

Sorted matching size-Comments

bull Classical matching is equal to perfect matching in every case

bull Constraint and greedy have identical behaviour

bull The larger the spectrum of the degree sequence the more efficient the matching

Sorted Ratios

36 Application

Sorted Ratios-Comments

bull With large initial matching most of the edges are considenred uselles or forced andare removed thus the ratio is close(if not equal to) zero

bull For small matching and large degree sequence sectrum hte max degree remainsthe same Only a few forced edges (and their nodes) are removed apparently nonodes with max degree

Sorted |E||V |

26 Bipartite with degree seq 37

Sorted |E||V | - Comments

bull In these set of figures we witness that the |E||V | acquires values relevant to those ofthe amadeus graphs The random graphs were constructed to depict this similarity

bull For smaller initial matching the ratios for G and G show the same upward trendand also they acquire closer values It repsresent the decrease of the averagenumber of forced edges in comparison to the larger matching cases

Sorted ∆

38 Application

Sorted ∆-Comments

bull Big difference in max degree in large initial matching

bull Almost identical behaviour in the case of small initial matching

Appendix A 39

Appendix A

BipartiteGraphGeneratorpy

from future import divisionimport networkx as nx

from networkxalgorithms import approximationimport collectionsimport randomimport mathfrom networkxalgorithms import bipartiteif name == main

for i in range(1481)waqs 481index=1n=randomrandint(100 1000)

n1=95 was 500me1=118

n2=251 was 500me2=903

n3=165 was 500me3=412

m=0m1=0p=randomrandom()p1=18250p2=25250p3=34250print ip=05t1=randomrandint(0 1)print im2=randomrandint(n2minus1 n2+1)G = nxGraph()ma = nxGraph()

aseq1=[1 2 3 4 5 3]

bseq1=[4 3 3 1 2 2 1]

aseq2=[16 14 14 14 12 11]bseq2=[0 0 0 0 0 0]

aseq3=[8 7 8 8 8 8]bseq3=[0 0 0 0 0 0]

40 Application

print Gnumber of edges()if ilt=160

G=bipartiteconfiguration model(aseq1 bseq1 create using=None seed=None)A=nxadjacency matrix(G)for ii in range(0n1+me1)

maadd node(ii)A=[Rtodense()tolist()[0] for R in A]

printnummanumber of nodes()rl=randomsample(range(0n1+me1) n1+me1)m=0done vertices = set()for p in rlprintin fordone verticesadd(p)

neighbors = []list()for iii in range(0n1+me1)

if A[p][iii]==1neighborsappend(iii)

randomshuffle(neighbors)continue loop = Truedegree = len(neighbors)

print degreej = 0p4=randomrandom()while continue loop and (jltdegree)print in loop

next = neighbors[j]if next not in done vertices and p not in done vertices

done verticesadd(p)done verticesadd(next)if p4gt=07print added edge

maadd edge(pnext)m=m+1

continue loop = Falsej += 1

print matching listOfedgeprint maedge

MA=nxadjacency matrix(ma)print MA

MA=[Rtodense()tolist()[0] for R in MA]print MA

B=[ join(map(strR)) for R in A]MB=[ join(map(strR)) for R in MA]

C=njoin(B)+nMC=njoin(MB)+n

print nprint mprint m1

filea=str(i)+txtwith open(fileaw) as f

Appendix A 41

fwrite(str(n1+me1))fwrite(n)fwrite(str(n1+me1))fwrite(n)fwrite(str(m))fwrite(n)fwrite(n)fwrite(C)fwrite(n)fwrite(MC)

elif igt160 and ilt321G=bipartiteconfiguration model(aseq2 bseq2 create using=None seed=None)A=nxadjacency matrix(G)for ii in range(0n2+me2)

maadd node(ii)A=[Rtodense()tolist()[0] for R in A]

printnummanumber of nodes()rl=randomsample(range(0n2+me2) n2+me2)m=0done vertices = set()for p in rlprintin fordone verticesadd(p)

neighbors = []list()for iii in range(0n2+me2)

if A[p][iii]==1neighborsappend(iii)

randomshuffle(neighbors)continue loop = Truedegree = len(neighbors)

print degreej = 0p4=randomrandom()while continue loop and (jltdegree)

print in loopnext = neighbors[j]if next not in done vertices and p not in done vertices

done verticesadd(p)done verticesadd(next)if p4gt=07

print added edgemaadd edge(pnext)m=m+1

continue loop = Falsej += 1

print matching listOfedgeprint maedge

MA=nxadjacency matrix(ma)print MA

MA=[Rtodense()tolist()[0] for R in MA]print MA

B=[ join(map(strR)) for R in A]MB=[ join(map(strR)) for R in MA]

42 Application

C=njoin(B)+nMC=njoin(MB)+n

print nprint mprint m1

filea=str(i)+txtwith open(fileaw) as f

fwrite(str(n2+me2))fwrite(n)fwrite(str(n2+me2))fwrite(n)fwrite(str(m))fwrite(n)fwrite(n)fwrite(C)fwrite(n)fwrite(MC)

elseG=bipartiteconfiguration model(aseq3 bseq3 create using=None seed=None)A=nxadjacency matrix(G)for ii in range(0n3+me3)

maadd node(ii)A=[Rtodense()tolist()[0] for R in A]

printnummanumber of nodes()rl=randomsample(range(0n3+me3) n3+me3)m=0done vertices = set()for p in rlprintin fordone verticesadd(p)

neighbors = []list()for iii in range(0n3+me3)

if A[p][iii]==1neighborsappend(iii)

randomshuffle(neighbors)continue loop = Truedegree = len(neighbors)

print degreej = 0p4=randomrandom()while continue loop and (jltdegree)

print in loopnext = neighbors[j]if next not in done vertices and p not in done vertices

done verticesadd(p)done verticesadd(next)if p4gt=07print added edge

maadd edge(pnext)m=m+1

continue loop = Falsej += 1

Appendix A 43

print matching listOfedgeprint maedge

MA=nxadjacency matrix(ma)print MA

MA=[Rtodense()tolist()[0] for R in MA]print MA

B=[ join(map(strR)) for R in A]MB=[ join(map(strR)) for R in MA]

C=njoin(B)+nMC=njoin(MB)+n

print nprint mprint m1

filea=str(i)+txtwith open(fileaw) as f

fwrite(str(n3+me3))fwrite(n)fwrite(str(n3+me3))fwrite(n)fwrite(str(m))fwrite(n)fwrite(n)fwrite(C)fwrite(n)fwrite(MC)

print nRandom graphs with random matching have been generated

44 Application

RandomGraphGeneratorpy

from future import divisionimport networkx as nxfrom networkxalgorithms import approximationimport collectionsimport randomimport mathif name == main

for i in range(1481)index=1n=randomrandint(100 1000)

n=1000m=0m1=0p=randomrandom()p1=mathlog(n2)np2=13p3=mathlog(n2)n+01p=05t1=randomrandint(0 1)print im2=randomrandint(n2minus1 n2+1)G = nxGraph()ma = nxGraph()print nme1=randomrandint(1 10)me2=randomrandint(2050)me3=randomrandint(50100)if ilt241

if ilt=80G=nxfast gnp random graph(n p1 seed=None directed=False)

elif igt80 and ilt161G=nxfast gnp random graph(n p2 seed=None directed=False)

elseG=nxfast gnp random graph(n p3 seed=None directed=False)

elseif ilt=320

G=nxbarabasi albert graph(n me1 seed=None)elif igt320 and ilt401

G=nxbarabasi albert graph(n me2 seed=None)else

G=nxbarabasi albert graph(n me3 seed=None)A=nxadjacency matrix(G)for ii in range(0n)

maadd node(ii)A=[Rtodense()tolist()[0] for R in A]

rl=randomsample(range(0n) n)m=0

Appendix A 45

done vertices = set()for p in rl

done verticesadd(p)neighbors = []list()for iii in range(0n)

if A[p][iii]==1neighborsappend(iii)

randomshuffle(neighbors)continue loop = Truedegree = len(neighbors)j = 0p2=randomrandom()while continue loop and (jltdegree)

next = neighbors[j]if next not in done vertices and p not in done vertices

done verticesadd(p)done verticesadd(next)if p2gt=00 Larger probability for smaller initial matching

maadd edge(pnext)m=m+1

continue loop = Falsej += 1

print matching listOfedgeprint maedgeMA=nxadjacency matrix(ma)MA=[Rtodense()tolist()[0] for R in MA]print MAB=[ join(map(strR)) for R in A]MB=[ join(map(strR)) for R in MA]

C=njoin(B)+nMC=njoin(MB)+nprint MCprint nprint mprint m1filea=str(i)+txtwith open(fileaw) as f

fwrite(str(n))fwrite(n)fwrite(str(n))fwrite(n)fwrite(str(m))fwrite(n)fwrite(n)fwrite(C)fwrite(n)fwrite(MC)

print nRandom graphs with random matching have been generated

46 Application

kequals3MaximumMatchingpy

from future import divisionimport networkx as nxfrom networkxalgorithms import bipartiteimport matplotlibpyplot as pltimport collectionsimport timeitimport xlwtimport xlrdimport mathimport sys

Case for General Graphsdef forced edges(Gadj dict2matching dict1num nodesforced)

flagg=0for n in range(0num nodes)

for k in adj dict2[n]if ([k]==matching dict1[n])

count=0for l in range(0num nodes)

count=count+adj dict2[l]count(k)if (len(adj dict2[n])==1) or (count==1)

forcedadd edge(nk)Gremove edge(nk)Gremove node(n)Gremove node(k)printforced edgenktemp=kflagg=1for m in range (len(adj dict2[n])minus1minus1minus1)

adj dict2[adj dict2[n][m]]remove(n)adj dict2[n]remove(adj dict2[n][m])

if adj dict2[temp]for l in range(len(adj dict2[temp])minus1minus1minus1)

if (adj dict2[temp][l]=n)adj dict2[adj dict2[temp][l]]remove(temp)adj dict2[temp]remove(adj dict2[temp][l])

break

def useless edges(num nodesadj dict1matching dict1uselessadj dict2G)for n in range(0num nodes)

for k in adj dict1[n]if ([k]=matching dict1[n]) and matching dict1[n] and matching dict1[k]

uselessadd edge(nk)Gremove edge(n k)

Appendix A 47

tempa=kadj dict2[n]remove(k)adj dict2[tempa]remove(n)adj dict1[tempa]remove(n)

return G

def Greedy(num nodesadj dict3matching dict2)

for n in range(0num nodes)if matching dict2[n]

flag2=minus1flag3=minus1for v in adj dict3[n]

if not matching dict2[v]flag2=vbreak

for p in adj dict3[matching dict2[n][0]]if not matching dict2[p]

flag3=pbreak

if (flag2=minus1) and (flag3=minus1) and (flag2=flag3)tempr=matching dict2[n][0]matching dict2[n]=[flag2]matching dict2[flag2]=[n]matching dict2[tempr]=[flag3]matching dict2[flag3]=[tempr]

elsefor k in adj dict3[n]

if not matching dict2[k]matching dict2[n]=[k]matching dict2[k]=[n]break

yo1=0for i in range(0num nodes)

if matching dict2[i] and [i]==matching dict2[matching dict2[i][0]]yo1=yo1+1

greedy size=yo12return greedy size

def General()

INPUTSwb = xlwtWorkbook()ws = wbadd sheet(Results Random)book=xlrdopen workbook(filenames randomxls)

48 Application

style0 = xlwteasyxf(fontbold on)style1 = xlwteasyxf(num format str=0000)INPUTSwswrite(0 0File style0)wswrite(0 1 Nodesstyle0)wswrite(0 2 Initial matchingstyle0)wswrite(0 3 NodesGstyle0)wswrite(0 4 EdgesGstyle0)wswrite(0 5 MaxDegreeGstyle0)wswrite(0 6 NodesG hatstyle0)wswrite(0 7 EdgesG Hatstyle0)wswrite(0 8 Useless edgesstyle0)wswrite(0 9 Forced edgesstyle0)wswrite(0 10 MaxDegreeG Hatstyle0)wswrite(0 11 Classical matchingstyle0)wswrite(0 12 Final matchingstyle0)wswrite(0 13 Greedy matchingstyle0)wswrite(0 14 Time classicalstyle0)wswrite(0 15 Time algorithmstyle0)wswrite(0 16 Time greedystyle0)wswrite(0 17 Perfect matching ratiostyle0)wswrite(0 18 Nodes ratiostyle0)wswrite(0 19 Edges ratiostyle0)wswrite(0 20 Matching ratiostyle0)

print nWelcomeThis is an implementation for general random graphs It uses Edmonds algorithm to compute maximum matching on G Hatn

for index in range (1481)was 481

if (index==482)f=open(Algotel generaltxtr)readlines()

elsefilea=str(booksheet by index(0)cell(index0))s=fileareplace(textu)replace()f=open(sr)readlines()Truewswrite(index 0 s)

print index

num nodes=int([xstrip()split() for x in f][0][0])

num matching=int([xstrip()split() for x in f][2][0])

adj temp = [xstrip()split() for x in f][44+num nodes]adj=[map(intR) for R in adj temp]

matching temp=[xstrip()split() for x in f][4+num nodes+14+2num nodes+1]matching1=[map(intR) for R in matching temp]

adj dict1=i[ii for iix in enumerate(L) if x] for iL in enumerate(adj)adj dict2=i[ii for iix in enumerate(L) if x] for iL in enumerate(adj)

Appendix A 49

adj dict3=i[ii for iix in enumerate(L) if x] for iL in enumerate(adj)

matching dict1=i[ii for iix in enumerate(L) if x] for iL in enumerate(matching1)matching dict2=i[ii for iix in enumerate(L) if x] for iL in enumerate(matching1)print adj dict2print matching dict2wswrite(index 1 num nodes)wswrite(index 2 num matching)

G = nxGraph()

useless= nxGraph()forced = nxGraph()

Fill Graphfor n in range(0num nodes)

for k in adj dict1[n]Gadd edge(nk)

Gt=Gnumber of edges()wswrite(index 3 Gnumber of nodes())wswrite(index 4 Gnumber of edges())wswrite(index 5 max(Gdegree()values()))

Compute Edmonds classical matching on G for comparison

startB = timeitdefault timer()Classical Matching=nxmax weight matching(G maxcardinality=False)stopB = timeitdefault timer()

Compute Gˆ nad MˆstartC = timeitdefault timer()useless edges(num nodesadj dict1matching dict1uselessadj dict2G)forced edges(Gadj dict2matching dict1num nodesforced)Final Matching=nxmax weight matching(G maxcardinality=False)stopC = timeitdefault timer()

GreedystartG = timeitdefault timer()greedy size=Greedy(num nodesadj dict3matching dict2)stopG = timeitdefault timer()

wswrite(index 6 Gnumber of nodes())wswrite(index 7 Gnumber of edges())wswrite(index 8 uselessnumber of edges())wswrite(index 9 forcednumber of edges())if Gdegree()values()

wswrite(index 10 max(Gdegree()values()))else

50 Application

wswrite(index 10 0)wswrite(index 11 len(Classical Matching)2)wswrite(index 12 len(Final Matching)2+forcednumber of edges())wswrite(index 13 greedy size)wswrite(index 14 stopB minus startBstyle1)wswrite(index 15 stopC minus startCstyle1)wswrite(index 16 stopG minus startGstyle1)wswrite(index 17 (len(Final Matching)2+forcednumber of edges())(num nodes2)style1)wswrite(index 18 Gnumber of nodes()Gtstyle1)wswrite(index 19 Gnumber of edges()Gtstyle1)wswrite(index 20 (len(Final Matching)2+forcednumber of edges())(len(Classical Matching)2)style1)

wbsave(AA Results Random Reyni Large Bipartitexls)

Main function Here we must choose the input form of the dataif name == main

startA = timeitdefault timer()General()stopA = timeitdefault timer()

print nThis program has terminatednnRunning time for 480 files stopAminusstartAprint nnPlease open AA Results Random Reyni Largexls file to see the Results

Appendix A 51

Plotmat

clear allclose allload(RN1Lmat)load(RN1Smat)load(RN2Lmat)load(RN2Smat)load(RN3Lmat)load(RN3Smat)

Plotsh(1)=figure(NameHistogram of Matching size difference between Constraint Algorithm and Greedy AlgorithmNumberTitleoff)

RN1L Greedydiff=RN1L Final matchingminusRN1L Greedy matchingRN2L Greedydiff=RN2L Final matchingminusRN2L Greedy matchingRN3L Greedydiff=RN3L Final matchingminusRN3L Greedy matchingRN1S Greedydiff=RN1S Final matchingminusRN1S Greedy matchingRN2S Greedydiff=RN2S Final matchingminusRN2S Greedy matchingRN3S Greedydiff=RN3S Final matchingminusRN3S Greedy matching

RN1L Finaldiff=RN1L Classical matchingminusRN1L Final matchingRN2L Finaldiff=RN2L Classical matchingminusRN2L Final matchingRN3L Finaldiff=RN3L Classical matchingminusRN3L Final matchingRN1S Finaldiff=RN1S Classical matchingminusRN1S Final matchingRN2S Finaldiff=RN2S Classical matchingminusRN2S Final matchingRN3S Finaldiff=RN3S Classical matchingminusRN3S Final matching

RN1L Classicaldiff=(RN1L Nodes2)minusRN1L Classical matchingRN2L Classicaldiff=(RN2L Nodes2)minusRN2L Classical matchingRN3L Classicaldiff=(RN3L Nodes2)minusRN3L Classical matchingRN1S Classicaldiff=(RN1S Nodes2)minusRN1S Classical matchingRN2S Classicaldiff=(RN2S Nodes2)minusRN2S Classical matchingRN3S Classicaldiff=(RN3S Nodes2)minusRN3S Classical matching

subplot(231)hold onhistf(RN1L Greedydiff0110facecolorbfacealpha9edgealpha1)histf(RN1L Finaldiff0110facecolorrfacealpha5edgealpha1)histf(RN1L Classicaldiff0110facecolorgfacealpha5edgealpha1)legalpha(ConminusGreClasminusConPerfminusClasslocationnortheast)legend boxoffaxis tightxlabel(edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN1L)grid on

subplot(232)hold onhistf(RN2L Greedydiff0110facecolorbfacealpha9edgealpha1)

52 Application

histf(RN2L Finaldiff0110facecolorrfacealpha5edgealpha1)histf(RN2L Classicaldiff0110facecolorgfacealpha5edgealpha1)legalpha(ConminusGreClasminusConPerfminusClasslocationnortheast)legend boxoffaxis tightxlabel(edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN2L)grid on

subplot(233)hold onhistf(RN3L Greedydiff0110facecolorbfacealpha5edgealpha1)histf(RN3L Finaldiff0110facecolorrfacealpha5edgealpha1)histf(RN3L Classicaldiff0110facecolorgfacealpha5edgealpha1)legalpha(ConminusGreClasminusConPerfminusClasslocationnortheast)legend boxoffaxis tightxlabel(edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN3L)grid on

subplot(234)hold onhistf(RN1S Greedydiff0110facecolorbfacealpha5edgealpha1)histf(RN1S Finaldiff0110facecolorrfacealpha5edgealpha1)histf(RN1S Classicaldiff0110facecolorgfacealpha5edgealpha1)legalpha(ConminusGreClasminusConPerfminusClasslocationnortheast)legend boxoffaxis tightxlabel(edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(R1NS)grid on

subplot(235)hold onhistf(RN2S Greedydiff0110facecolorbfacealpha5edgealpha1)histf(RN2S Finaldiff0110facecolorrfacealpha5edgealpha1)histf(RN2S Classicaldiff0110facecolorgfacealpha5edgealpha1)legalpha(ConminusGreClasminusConPerfminusClasslocationnortheast)legend boxoffaxis tightxlabel(edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN2S)grid on

subplot(236)hold onhistf(RN3S Greedydiff0110facecolorbfacealpha5edgealpha1)histf(RN3S Finaldiff0110facecolorrfacealpha5edgealpha1)histf(RN3S Classicaldiff0110facecolorgfacealpha5edgealpha1)

Appendix A 53

legalpha(ConminusGreClasminusConPerfminusClasslocationnortheast)legend boxoffaxis tightgrid ontitle(RN3S)xlabel(edges) xminusaxis labelylabel(instances) yminusaxis labelset(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN1png minusr300)h(2)=figure(NameHistogram of Max Degree of G AND G HatNumberTitleoff)RN1L x=RN1L MaxDegreeGminusRN1L MaxDegreeG HatRN2L x=RN2L MaxDegreeGminusRN2L MaxDegreeG HatRN3L x=RN3L MaxDegreeGminusRN3L MaxDegreeG HatRN1S x=RN1S MaxDegreeGminusRN1S MaxDegreeG HatRN2S x=RN2S MaxDegreeGminusRN2S MaxDegreeG HatRN3S x=RN3S MaxDegreeGminusRN3S MaxDegreeG Hatsubplot(231)hold onhistf(RN1L MaxDegreeG0150facecolorbfacealpha5edgealpha1)histf(RN1L MaxDegreeG Hat0150facecolorrfacealpha5edgealpha1)histf(RN1L x0150facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightxlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN1L)grid on

subplot(232)hold onhistf(RN2L MaxDegreeG010500facecolorbfacealpha5edgealpha1)histf(RN2L MaxDegreeG Hat010500facecolorrfacealpha5edgealpha1)histf(RN2L x010500facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightxlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN2L)grid on

subplot(233)hold onhistf(RN3L MaxDegreeG010300facecolorbfacealpha5edgealpha1)histf(RN3L MaxDegreeG Hat010300facecolorrfacealpha5edgealpha1)histf(RN3L x010300facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightxlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN3L)

54 Application

grid on

subplot(234)hold onhistf(RN1S MaxDegreeG0150facecolorbfacealpha5edgealpha1)histf(RN1S MaxDegreeG Hat0150facecolorrfacealpha5edgealpha1)histf(RN1S x0150facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightxlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(R1NS)grid on

subplot(235)hold onhistf(RN2S MaxDegreeG010500facecolorbfacealpha5edgealpha1)histf(RN2S MaxDegreeG Hat010500facecolorrfacealpha5edgealpha1)histf(RN2S x010500facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightxlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN2S)grid on

subplot(236)hold onhistf(RN3S MaxDegreeG05300facecolorbfacealpha5edgealpha1)histf(RN3S MaxDegreeG Hat05300facecolorrfacealpha5edgealpha1)histf(RN3S x05300facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightgrid ontitle(RN3S)xlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labelset(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN2png minusr300)

h(3)=figure(NameComputation time over edgesNumberTitleoff)

subplot(231)hold onstem(RN1L EdgesGRN1L Time classicalg)stem(RN1L EdgesGRN1L Time algorithmro)stem(RN1L EdgesGRN1L Time greedybx)grid on

Appendix A 55

title(RN1L)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)

subplot(232)hold onstem(RN2L EdgesGRN2L Time classicalg)stem(RN2L EdgesGRN2L Time algorithmro)stem(RN2L EdgesGRN2L Time greedybx)grid ontitle(RN2L)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)

subplot(233)hold onstem(RN3L EdgesGRN3L Time classicalg)stem(RN3L EdgesGRN3L Time algorithmro)stem(RN3L EdgesGRN3L Time greedybx)grid ontitle(RN3L)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)

subplot(234)hold onstem(RN1S EdgesGRN1S Time classicalg)stem(RN1S EdgesGRN1S Time algorithmro)stem(RN1S EdgesGRN1S Time greedybx)grid ontitle(RN1S)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)

subplot(235)hold onstem(RN2S EdgesGRN2S Time classicalg)stem(RN2S EdgesGRN2S Time algorithmro)stem(RN2S EdgesGRN2S Time greedybx)grid ontitle(RN2S)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)

subplot(236)hold onstem(RN3S EdgesGRN3S Time classicalg)stem(RN3S EdgesGRN3S Time algorithmro)stem(RN3S EdgesGRN3S Time greedybx)

56 Application

grid ontitle(RN3S)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)set(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN3png minusr300)

h(4)=figure(NameSorted matching sizeNumberTitleoff)RN1L Sorted matching temp(1)=RN1L Classical matchingRN1L Sorted matching temp(2)=RN1L Final matchingRN1L Sorted matching temp(3)=RN1L Greedy matchingRN1L Sorted matching temp(4)=RN1L Initial matchingRN1L Sorted matching=sortrows(RN1L Sorted matching temp)

RN2L Sorted matching temp(1)=RN2L Classical matchingRN2L Sorted matching temp(2)=RN2L Final matchingRN2L Sorted matching temp(3)=RN2L Greedy matchingRN2L Sorted matching temp(4)=RN2L Initial matchingRN2L Sorted matching=sortrows(RN2L Sorted matching temp)

RN3L Sorted matching temp(1)=RN3L Classical matchingRN3L Sorted matching temp(2)=RN3L Final matchingRN3L Sorted matching temp(3)=RN3L Greedy matchingRN3L Sorted matching temp(4)=RN3L Initial matchingRN3L Sorted matching=sortrows(RN3L Sorted matching temp)

RN1S Sorted matching temp(1)=RN1S Classical matchingRN1S Sorted matching temp(2)=RN1S Final matchingRN1S Sorted matching temp(3)=RN1S Greedy matchingRN1S Sorted matching temp(4)=RN1S Initial matchingRN1S Sorted matching=sortrows(RN1S Sorted matching temp)

RN2S Sorted matching temp(1)=RN2S Classical matchingRN2S Sorted matching temp(2)=RN2S Final matchingRN2S Sorted matching temp(3)=RN2S Greedy matchingRN2S Sorted matching temp(4)=RN2S Initial matchingRN2S Sorted matching=sortrows(RN2S Sorted matching temp)

RN3S Sorted matching temp(1)=RN3S Classical matchingRN3S Sorted matching temp(2)=RN3S Final matchingRN3S Sorted matching temp(3)=RN3S Greedy matchingRN3S Sorted matching temp(4)=RN3S Initial matchingRN3S Sorted matching=sortrows(RN3S Sorted matching temp)

subplot(231)hold onplot(RN1L Sorted matching(1)b)plot(RN1L Sorted matching(2)g)plot(RN1L Sorted matching(3)r)plot(RN1L Sorted matching(4)m)

Appendix A 57

grid ontitle(RN1L)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)

subplot(232)hold onplot(RN2L Sorted matching(1)b)plot(RN2L Sorted matching(2)g)plot(RN2L Sorted matching(3)r)plot(RN2L Sorted matching(4)m)grid ontitle(RN2L)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)

subplot(233)hold onplot(RN3L Sorted matching(1)b)plot(RN3L Sorted matching(2)g)plot(RN3L Sorted matching(3)r)plot(RN3L Sorted matching(4)m)grid ontitle(RN3L)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)

subplot(234)hold onplot(RN1S Sorted matching(1)b)plot(RN1S Sorted matching(2)g)plot(RN1S Sorted matching(3)r)plot(RN1S Sorted matching(4)m)grid ontitle(RN1S)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)

subplot(235)hold onplot(RN2S Sorted matching(1)b)plot(RN2S Sorted matching(2)g)plot(RN2S Sorted matching(3)r)plot(RN2S Sorted matching(4)m)grid ontitle(RN2S)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)

58 Application

subplot(236)hold onplot(RN3S Sorted matching(1)b)plot(RN3S Sorted matching(2)g)plot(RN3S Sorted matching(3)r)plot(RN3S Sorted matching(4)m)grid ontitle(RN3S)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)set(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN4png minusr300)h(5)=figure(NameSorted RatiosNumberTitleoff)RN1L ratio1=RN1L NodesG hatRN1L NodesGRN2L ratio1=RN2L NodesG hatRN2L NodesGRN3L ratio1=RN3L NodesG hatRN3L NodesGRN1S ratio1=RN1S NodesG hatRN1S NodesGRN2S ratio1=RN2S NodesG hatRN2S NodesGRN3S ratio1=RN3S NodesG hatRN3S NodesG

RN1L ratio2=RN1L EdgesG HatRN1L EdgesGRN2L ratio2=RN2L EdgesG HatRN2L EdgesGRN3L ratio2=RN3L EdgesG HatRN3L EdgesGRN1S ratio2=RN1S EdgesG HatRN1S EdgesGRN2S ratio2=RN2S EdgesG HatRN2S EdgesGRN3S ratio2=RN3S EdgesG HatRN3S EdgesG

RN1L ratio3=RN1L MaxDegreeG HatRN1L MaxDegreeGRN2L ratio3=RN2L MaxDegreeG HatRN2L MaxDegreeGRN3L ratio3=RN3L MaxDegreeG HatRN3L MaxDegreeGRN1S ratio3=RN1S MaxDegreeG HatRN1S MaxDegreeGRN2S ratio3=RN2S MaxDegreeG HatRN2S MaxDegreeGRN3S ratio3=RN3S MaxDegreeG HatRN3S MaxDegreeG

RN1L ratio(1)=RN1L ratio1RN1L ratio(2)=RN1L ratio2RN1L ratio(3)=RN1L ratio3

RN2L ratio(1)=RN2L ratio1RN2L ratio(2)=RN2L ratio2RN2L ratio(3)=RN2L ratio3

RN3L ratio(1)=RN3L ratio1RN3L ratio(2)=RN3L ratio2RN3L ratio(3)=RN3L ratio3

RN1S ratio(1)=RN1S ratio1RN1S ratio(2)=RN1S ratio2RN1S ratio(3)=RN1S ratio3

RN2S ratio(1)=RN2S ratio1

Appendix A 59

RN2S ratio(2)=RN2S ratio2RN2S ratio(3)=RN2S ratio3

RN3S ratio(1)=RN3S ratio1RN3S ratio(2)=RN3S ratio2RN3S ratio(3)=RN3S ratio3

RN1L ratio sorted=sortrows(RN1L ratio)RN2L ratio sorted=sortrows(RN2L ratio)RN3L ratio sorted=sortrows(RN3L ratio)RN1S ratio sorted=sortrows(RN1S ratio)RN2S ratio sorted=sortrows(RN2S ratio)RN3S ratio sorted=sortrows(RN3S ratio)

subplot(231)hold onplot(RN1L ratio sorted(1)b)plot(RN1L ratio sorted(2)g)plot(RN1L ratio sorted(3)r)grid ontitle(RN1L)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)

subplot(232)hold onplot(RN2L ratio sorted(1)b)plot(RN2L ratio sorted(2)g)plot(RN2L ratio sorted(3)r)grid ontitle(RN2L)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)

subplot(233)hold onplot(RN3L ratio sorted(1)b)plot(RN3L ratio sorted(2)g)plot(RN3L ratio sorted(3)r)grid ontitle(RN3L)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)

subplot(234)hold onplot(RN1S ratio sorted(1)b)plot(RN1S ratio sorted(2)g)plot(RN1S ratio sorted(3)r)grid on

60 Application

title(RN1S)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)

subplot(235)hold onplot(RN2S ratio sorted(1)b)plot(RN2S ratio sorted(2)g)plot(RN2S ratio sorted(3)r)grid ontitle(RN2S)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)

subplot(236)hold onplot(RN3S ratio sorted(1)b)plot(RN3S ratio sorted(2)g)plot(RN3S ratio sorted(3)r)grid ontitle(RN3S)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)set(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN5png minusr300)

h(6)=figure(NameSorted edges over nodesNumberTitleoff)

RN1L DegreeG1=(RN1L EdgesG)(RN1L NodesG)RN1L DegreeG Hat1=(RN1L EdgesG Hat)(RN1L NodesG hat)

RN1L Degree temp1(1)=RN1L DegreeG1RN1L Degree temp1(2)=RN1L DegreeG Hat1RN1L Degree sorted1=sortrows(RN1L Degree temp1)subplot(231)hold on

plot(RN1L Degree sorted1(1)b)plot(RN1L Degree sorted1(2)g)grid ontitle(RN1L)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)

RN2L DegreeG1=(RN2L EdgesG)(RN2L NodesG)RN2L DegreeG Hat1=(RN2L EdgesG Hat)(RN2L NodesG hat)

RN2L Degree temp1(1)=RN2L DegreeG1

Appendix A 61

RN2L Degree temp1(2)=RN2L DegreeG Hat1RN2L Degree sorted1=sortrows(RN2L Degree temp1)

subplot(232)hold onplot(RN2L Degree sorted1(1)b)plot(RN2L Degree sorted1(2)g)grid ontitle(RN2L)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)

RN3L DegreeG1=(RN3L EdgesG)(RN3L NodesG)RN3L DegreeG Hat1=(RN3L EdgesG Hat)(RN3L NodesG hat)

RN3L Degree temp1(1)=RN3L DegreeG1RN3L Degree temp1(2)=RN3L DegreeG Hat1RN3L Degree sorted1=sortrows(RN3L Degree temp1)

subplot(233)hold onplot(RN3L Degree sorted1(1)b)plot(RN3L Degree sorted1(2)g)grid ontitle(RN3L)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)

RN1S DegreeG1=(RN1S EdgesG)(RN1S NodesG)RN1S DegreeG Hat1=(RN1S EdgesG Hat)(RN1S NodesG hat)

RN1S Degree temp1(1)=RN1S DegreeG1RN1S Degree temp1(2)=RN1S DegreeG Hat1RN1S Degree sorted1=sortrows(RN1S Degree temp1)

subplot(234)hold onplot(RN1S Degree sorted1(1)b)plot(RN1S Degree sorted1(2)g)grid ontitle(RN1S)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)

RN2S DegreeG1=(RN2S EdgesG)(RN2S NodesG)RN2S DegreeG Hat1=(RN2S EdgesG Hat)(RN2S NodesG hat)

RN2S Degree temp1(1)=RN2S DegreeG1

62 Application

RN2S Degree temp1(2)=RN2S DegreeG Hat1RN2S Degree sorted1=sortrows(RN2S Degree temp1)

subplot(235)hold onplot(RN2S Degree sorted1(1)b)plot(RN2S Degree sorted1(2)g)grid ontitle(RN2S)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)

RN3S DegreeG1=(RN3S EdgesG)(RN3S NodesG)RN3S DegreeG Hat1=(RN3S EdgesG Hat)(RN3S NodesG hat)

RN3S Degree temp1(1)=RN3S DegreeG1RN3S Degree temp1(2)=RN3S DegreeG Hat1RN3S Degree sorted1=sortrows(RN3S Degree temp1)

subplot(236)hold onplot(RN3S Degree sorted1(1)b)plot(RN3S Degree sorted1(2)g)grid ontitle(RN3S)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)set(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN6png minusr300)h(7)=figure(NameSorted mATCHED DEGREENumberTitleoff)RN1L ratioMax(1)=RN1L MaxDegreeGRN1L ratioMax(2)=RN1L MaxDegreeG Hat

RN1L ratio sortedMax=sortrows(RN1L ratioMax)subplot(231)hold onplot(RN1L ratio sortedMax(1)b)plot(RN1L ratio sortedMax(2)g)grid ontitle(RN1L)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)

RN2L ratioMax(1)=RN2L MaxDegreeGRN2L ratioMax(2)=RN2L MaxDegreeG Hat

RN2L ratio sortedMax=sortrows(RN2L ratioMax)subplot(232)

Appendix A 63

hold onplot(RN2L ratio sortedMax(1)b)plot(RN2L ratio sortedMax(2)g)grid ontitle(RN2L)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)

RN3L ratioMax(1)=RN3L MaxDegreeGRN3L ratioMax(2)=RN3L MaxDegreeG Hat

RN3L ratio sortedMax=sortrows(RN3L ratioMax)subplot(233)hold onplot(RN3L ratio sortedMax(1)b)plot(RN3L ratio sortedMax(2)g)grid ontitle(RN3L)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)

RN1S ratioMax(1)=RN1S MaxDegreeGRN1S ratioMax(2)=RN1S MaxDegreeG Hat

RN1S ratio sortedMax=sortrows(RN1S ratioMax)subplot(234)hold onplot(RN1S ratio sortedMax(1)b)plot(RN1S ratio sortedMax(2)g)grid ontitle(RN1S)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)

RN2S ratioMax(1)=RN2S MaxDegreeGRN2S ratioMax(2)=RN2S MaxDegreeG Hat

RN2S ratio sortedMax=sortrows(RN2S ratioMax)

subplot(235)hold onplot(RN2S ratio sortedMax(1)b)plot(RN2S ratio sortedMax(2)g)grid ontitle(RN2S)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)

RN3S ratioMax(1)=RN3S MaxDegreeGRN3S ratioMax(2)=RN3S MaxDegreeG Hat

64 Application

RN3S ratio sortedMax=sortrows(RN3S ratioMax)subplot(236)hold onplot(RN3S ratio sortedMax(1)b)plot(RN3S ratio sortedMax(2)g)grid ontitle(RN1L)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)set(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN7png minusr300)

tilefigs()(h)

Bibliography

[1] C Berge ldquoTWO THEOREMS IN GRAPH THEORYrdquo Proceedings of the NationalAcademy of Sciences of the United States of America vol 43 no 9 pp 842ndash844Sep 1957

[2] L Bui S Sanghavi and R Srikant ldquoDistributed link scheduling with constantoverheadrdquo IEEEACM Trans Netw vol 17 no 5 pp 1467ndash1480 2009

[3] R Duan and S Pettie ldquoLinear-time approximation for maximum weight matchingrdquoJ ACM vol 61 no 1 2014

[4] J Edmonds ldquoPaths trees and flowersrdquo Canadian Journal of Mathematics vol 17pp 449ndash467 1965

[5] J E Hopcroft and R M Karp ldquoAn n52 algorithm for maximum matchings inbipartite graphsrdquo SIAM J Comput vol 2 no 4 pp 225ndash231 1973

[6] S Micali and V V Vazirani ldquoAn O(radic|V ||E|) algorithm for finding maximum

matching in general graphsrdquo in 21st Symp on Foundations of Comp Sc (FOCS)IEEE 1980 pp 17ndash27

[7] N Nisse A Salch and V Weber ldquoRecovery of disrupted airline operationsrdquo 2015httphalinriafrSomething

[8] X Wu and R Srikant ldquoRegulated maximal matching A distributed schedulingalgorithm for multi-hop wireless networks with nodeexclusive spectrum sharingrdquo inIEEE Conf on Decision and Control 2005

65

  • Contents
  • Introduction
  • Algorithms
    • Maximum matching
    • k-maximum matching
      • k-matching for Airport Slot assignment
      • The case where k=3
      • The case of Paths
      • The case of the Spider
          • Application
            • Description
            • Reyni Erdos
            • Barabaacutesi Albert
            • Amadeus Graphs
            • Bipartite
            • Bipartite with degree seq
            • Appendix A
              • BipartiteGraphGeneratorpy
              • RandomGraphGeneratorpy
              • kequals3MaximumMatchingpy
              • Plotmat
                  • Bibliography
Page 19: Theodoros Alexandros KARAGKIOULES -  · Introduction This work is the result of a 6 months internship, under the supervision of research O cer Nicolas NISSE. The original scope of

20 Application

bull It is evident that when the initial matching is large the amount of forced edges(and their endpoints) removed is high thus the ratio of Nodes and edges is verylow For higher probabilities almost all edges are removed as useless

bull For a smaller initial matching almost no forced edges (and their endpoints) areremoved which we conclude be the node ration being close to 1 There is somesmall amount of useless edges removed though since the ratio of edges is less butclose to 1

bull The ratio of ∆ for large initial matching follows the trend of the node ratio yetfor smaller initial matching it deviates significantly

Sorted |E||V |

23 Barabasi Albert 21

Sorted |E||V | - Comments

bull Although as graph density the ratio 2|E||V |(|V |minus1)

is considered in this set of figures

we evaluate the correlation of the ratio |E||V | of G and G since the density of G

could acquire values higher than that of G

bull The figures are calculated in ascending order for the ratio of G

bull For the case of large initial matching the two ratios for G and G remain almostconstant ( to the extent of the edge attraction m of each graph) since removingforced edges( and their endpoints) alters the |E| and |V | proportionately

bull For the case of small initial matching we observe some deviation in the valuesof the ration for G and that is explained with the removal of only useless edgeswhich only alters the |E| and keeps |V | in the original values

Sorted ∆

22 Application

Sorted ∆-Comments

bull In this set of figures the ascending order of the ∆ of G is associated with the ∆of G

bull There is a significant jump of the ∆ for each graph category which tells that thatwe are not comparing a uniform distribution of random graphs and based on theedge attraction m the graphs can vary in form

bull For larger initial matching we observe the difference in the ∆s of G and G giventhe removed forced edges( and their endpoints) At some cases the ∆ of G dropsto 0 since the vast majority of edges have been declared forced and removed alongwith their endpoints What is interesting is that the ∆ of G oscilates within stablelimits

24 Amadeus Graphs 23

bull For smaller initial matching the ∆s of G and G follow mostly the same trend onlya few number of different instances

24 Amadeus Graphs

Graph characteristics Amadeus graphs

bull These are the bipartite graphs provided by Amadeus

Computation time over |E|

Computation time over |E| - Comments

24 Application

bull For every instance the computation time of the classical algorithm is always smallerto that of the constraint matching

bull This allows as to speculate that we always compute a smaller G which also impliesthat we always find a set of forced edges and useless

Sorted matching size

Sorted matching size - Comments

bull Size of matching has an upward trend since the magnitude of the graphs is notthe same for the 160 instances

bull No significant deviation is noticed as per the first graph

24 Amadeus Graphs 25

bull Except from deviation from the perfect matching (number of flights) where some-times it could get up to 40

bull For the Amadeus Bipartite graphs we can see that the difference of the Classicaland the constraint implementation is not more than 1 edge in the matching

bull There appears to be a difference of up to 24 edges between the Classical matchingand the Perfect matching which is computed as the number of flights

bull The greedy algorithm performs well with only a few instances deviating slightlyform the Constraint algorithm result

Sorted Ratios

Sorted Ratios - Comments

26 Application

bull

Sorted |E||V |

Sorted |E||V | - Comments

bull Density of the graphs shows that on average we have 25-3 available time slot perflight

bull The line for the same value for G shows that there is a large deviation for everyinstance which allows for the hypothesis that the amount of useless+forced edgesof G has no obvious correlation to that of G

25 Bipartite 27

Sorted ∆

Sorted ∆-Comments

bull As per the previous related graphs for ∆ there is in significant drop in the ∆ of Gand G

25 Bipartite

Graph characteristics Bipartite random Graphs

bull BIPxy are randomly generated graphs with a fixed number of 1000(n=500 andm=500) nodes

bull There are 6 categories based on ini matching and probability p

28 Application

bull Probability p has been chosen as such in order to simulate the |E||V | 25 of theAmadeus bipartite graphs

bull So in order to have about 2-4 edges for every node we choose accordingly theprobability p to choose one of the n lowastm possible edges

bull x = L S L When the initial matching is large and S when it is small

bull y = 1 2 3 1 when p = 18250

2 when p = 25250

and 3 when p = 34250

Computation time over

Computation time overedges-Comments

bull

25 Bipartite 29

Sorted matching size

Sorted matching size-Comments

bull In these set of graphs one can instantly notice that only a few instances with highprobability can reach a matching size equal to the perfect matching

bull For the case of the initial matching we witness that there is a gap between the lineof the classical matching and those of the constraint and greedy results suggestingsmaller matching sizes of 10-40 edges

bull For the case of the small initial matching the result of the constraint matchingis now close to the result of the classical matching yet the greedy algorithm stillshows a relevantly big difference

30 Application

bull In this set of bipartite graphs we can witness that the result of the Constraintmatching shows a difference with the classical matching when the initial matchingis large The difference is smaller as the probability gets larger

bull For the case of the small initial matching the above phenomenom does not occuryet the greedy results deviates from that of the constraint matching

bull As per the pefrect matching compared to the classical matching a difference of5-10 edges is evident at almost all cases

Sorted Ratios

Sorted Ratios-Comments

bull Great max degree deviation

25 Bipartite 31

bull Regardless of the probability the ration of nodes and edges seems to have similarbehaviour when compared to the respective graphs of the same matching scale

bull Same gap between nodes ration and edges ration for all cases

Sorted |E||V |

Sorted |E||V | - Comments

bull In these set of figures we witness that the |E||V | acquires values relevant to those ofthe amadeus graphs The random graphs were constructed to depict this similarity

bull For smaller initial matching the ratios for G and G show the same upward trendand also they acquire closer values It represents the decrease of the averagenumber of forced edges in comparison to the larger matching cases

32 Application

Sorted ∆

Sorted ∆-Comments

bull ∆ acquires the same min and max values for each probability case (expected)

bull Gap in the case of large initial matching

26 Bipartite with degree seq

Graph characteristics

bull DEQBIPxy are randomly generated graphs based on three different types of degreedistribution of the Amadeus graphs

26 Bipartite with degree seq 33

bull There are 6 categories based on ini matching and degree distribution

bull x = L S L When the initial matching is large and S when it is small

bull y = 1 2 3 1 when degree distribution is based on file 2 when degree distributionis based on file and 3 when degree distribution is based on file

Computation time over

34 Application

Computation time overedges-Comments

bull Greedy algorithm takes minimum amount of time

bull The smaller the initial matching the more smaller the difference in comoutationtime of Constraint and classical algorithm

bull Due to preprocessing and the fact that G and G are the almost identical thetotal time needed to apply the constraint algorithm is in some cases bigger

Sorted matching size

26 Bipartite with degree seq 35

Sorted matching size-Comments

bull Classical matching is equal to perfect matching in every case

bull Constraint and greedy have identical behaviour

bull The larger the spectrum of the degree sequence the more efficient the matching

Sorted Ratios

36 Application

Sorted Ratios-Comments

bull With large initial matching most of the edges are considenred uselles or forced andare removed thus the ratio is close(if not equal to) zero

bull For small matching and large degree sequence sectrum hte max degree remainsthe same Only a few forced edges (and their nodes) are removed apparently nonodes with max degree

Sorted |E||V |

26 Bipartite with degree seq 37

Sorted |E||V | - Comments

bull In these set of figures we witness that the |E||V | acquires values relevant to those ofthe amadeus graphs The random graphs were constructed to depict this similarity

bull For smaller initial matching the ratios for G and G show the same upward trendand also they acquire closer values It repsresent the decrease of the averagenumber of forced edges in comparison to the larger matching cases

Sorted ∆

38 Application

Sorted ∆-Comments

bull Big difference in max degree in large initial matching

bull Almost identical behaviour in the case of small initial matching

Appendix A 39

Appendix A

BipartiteGraphGeneratorpy

from future import divisionimport networkx as nx

from networkxalgorithms import approximationimport collectionsimport randomimport mathfrom networkxalgorithms import bipartiteif name == main

for i in range(1481)waqs 481index=1n=randomrandint(100 1000)

n1=95 was 500me1=118

n2=251 was 500me2=903

n3=165 was 500me3=412

m=0m1=0p=randomrandom()p1=18250p2=25250p3=34250print ip=05t1=randomrandint(0 1)print im2=randomrandint(n2minus1 n2+1)G = nxGraph()ma = nxGraph()

aseq1=[1 2 3 4 5 3]

bseq1=[4 3 3 1 2 2 1]

aseq2=[16 14 14 14 12 11]bseq2=[0 0 0 0 0 0]

aseq3=[8 7 8 8 8 8]bseq3=[0 0 0 0 0 0]

40 Application

print Gnumber of edges()if ilt=160

G=bipartiteconfiguration model(aseq1 bseq1 create using=None seed=None)A=nxadjacency matrix(G)for ii in range(0n1+me1)

maadd node(ii)A=[Rtodense()tolist()[0] for R in A]

printnummanumber of nodes()rl=randomsample(range(0n1+me1) n1+me1)m=0done vertices = set()for p in rlprintin fordone verticesadd(p)

neighbors = []list()for iii in range(0n1+me1)

if A[p][iii]==1neighborsappend(iii)

randomshuffle(neighbors)continue loop = Truedegree = len(neighbors)

print degreej = 0p4=randomrandom()while continue loop and (jltdegree)print in loop

next = neighbors[j]if next not in done vertices and p not in done vertices

done verticesadd(p)done verticesadd(next)if p4gt=07print added edge

maadd edge(pnext)m=m+1

continue loop = Falsej += 1

print matching listOfedgeprint maedge

MA=nxadjacency matrix(ma)print MA

MA=[Rtodense()tolist()[0] for R in MA]print MA

B=[ join(map(strR)) for R in A]MB=[ join(map(strR)) for R in MA]

C=njoin(B)+nMC=njoin(MB)+n

print nprint mprint m1

filea=str(i)+txtwith open(fileaw) as f

Appendix A 41

fwrite(str(n1+me1))fwrite(n)fwrite(str(n1+me1))fwrite(n)fwrite(str(m))fwrite(n)fwrite(n)fwrite(C)fwrite(n)fwrite(MC)

elif igt160 and ilt321G=bipartiteconfiguration model(aseq2 bseq2 create using=None seed=None)A=nxadjacency matrix(G)for ii in range(0n2+me2)

maadd node(ii)A=[Rtodense()tolist()[0] for R in A]

printnummanumber of nodes()rl=randomsample(range(0n2+me2) n2+me2)m=0done vertices = set()for p in rlprintin fordone verticesadd(p)

neighbors = []list()for iii in range(0n2+me2)

if A[p][iii]==1neighborsappend(iii)

randomshuffle(neighbors)continue loop = Truedegree = len(neighbors)

print degreej = 0p4=randomrandom()while continue loop and (jltdegree)

print in loopnext = neighbors[j]if next not in done vertices and p not in done vertices

done verticesadd(p)done verticesadd(next)if p4gt=07

print added edgemaadd edge(pnext)m=m+1

continue loop = Falsej += 1

print matching listOfedgeprint maedge

MA=nxadjacency matrix(ma)print MA

MA=[Rtodense()tolist()[0] for R in MA]print MA

B=[ join(map(strR)) for R in A]MB=[ join(map(strR)) for R in MA]

42 Application

C=njoin(B)+nMC=njoin(MB)+n

print nprint mprint m1

filea=str(i)+txtwith open(fileaw) as f

fwrite(str(n2+me2))fwrite(n)fwrite(str(n2+me2))fwrite(n)fwrite(str(m))fwrite(n)fwrite(n)fwrite(C)fwrite(n)fwrite(MC)

elseG=bipartiteconfiguration model(aseq3 bseq3 create using=None seed=None)A=nxadjacency matrix(G)for ii in range(0n3+me3)

maadd node(ii)A=[Rtodense()tolist()[0] for R in A]

printnummanumber of nodes()rl=randomsample(range(0n3+me3) n3+me3)m=0done vertices = set()for p in rlprintin fordone verticesadd(p)

neighbors = []list()for iii in range(0n3+me3)

if A[p][iii]==1neighborsappend(iii)

randomshuffle(neighbors)continue loop = Truedegree = len(neighbors)

print degreej = 0p4=randomrandom()while continue loop and (jltdegree)

print in loopnext = neighbors[j]if next not in done vertices and p not in done vertices

done verticesadd(p)done verticesadd(next)if p4gt=07print added edge

maadd edge(pnext)m=m+1

continue loop = Falsej += 1

Appendix A 43

print matching listOfedgeprint maedge

MA=nxadjacency matrix(ma)print MA

MA=[Rtodense()tolist()[0] for R in MA]print MA

B=[ join(map(strR)) for R in A]MB=[ join(map(strR)) for R in MA]

C=njoin(B)+nMC=njoin(MB)+n

print nprint mprint m1

filea=str(i)+txtwith open(fileaw) as f

fwrite(str(n3+me3))fwrite(n)fwrite(str(n3+me3))fwrite(n)fwrite(str(m))fwrite(n)fwrite(n)fwrite(C)fwrite(n)fwrite(MC)

print nRandom graphs with random matching have been generated

44 Application

RandomGraphGeneratorpy

from future import divisionimport networkx as nxfrom networkxalgorithms import approximationimport collectionsimport randomimport mathif name == main

for i in range(1481)index=1n=randomrandint(100 1000)

n=1000m=0m1=0p=randomrandom()p1=mathlog(n2)np2=13p3=mathlog(n2)n+01p=05t1=randomrandint(0 1)print im2=randomrandint(n2minus1 n2+1)G = nxGraph()ma = nxGraph()print nme1=randomrandint(1 10)me2=randomrandint(2050)me3=randomrandint(50100)if ilt241

if ilt=80G=nxfast gnp random graph(n p1 seed=None directed=False)

elif igt80 and ilt161G=nxfast gnp random graph(n p2 seed=None directed=False)

elseG=nxfast gnp random graph(n p3 seed=None directed=False)

elseif ilt=320

G=nxbarabasi albert graph(n me1 seed=None)elif igt320 and ilt401

G=nxbarabasi albert graph(n me2 seed=None)else

G=nxbarabasi albert graph(n me3 seed=None)A=nxadjacency matrix(G)for ii in range(0n)

maadd node(ii)A=[Rtodense()tolist()[0] for R in A]

rl=randomsample(range(0n) n)m=0

Appendix A 45

done vertices = set()for p in rl

done verticesadd(p)neighbors = []list()for iii in range(0n)

if A[p][iii]==1neighborsappend(iii)

randomshuffle(neighbors)continue loop = Truedegree = len(neighbors)j = 0p2=randomrandom()while continue loop and (jltdegree)

next = neighbors[j]if next not in done vertices and p not in done vertices

done verticesadd(p)done verticesadd(next)if p2gt=00 Larger probability for smaller initial matching

maadd edge(pnext)m=m+1

continue loop = Falsej += 1

print matching listOfedgeprint maedgeMA=nxadjacency matrix(ma)MA=[Rtodense()tolist()[0] for R in MA]print MAB=[ join(map(strR)) for R in A]MB=[ join(map(strR)) for R in MA]

C=njoin(B)+nMC=njoin(MB)+nprint MCprint nprint mprint m1filea=str(i)+txtwith open(fileaw) as f

fwrite(str(n))fwrite(n)fwrite(str(n))fwrite(n)fwrite(str(m))fwrite(n)fwrite(n)fwrite(C)fwrite(n)fwrite(MC)

print nRandom graphs with random matching have been generated

46 Application

kequals3MaximumMatchingpy

from future import divisionimport networkx as nxfrom networkxalgorithms import bipartiteimport matplotlibpyplot as pltimport collectionsimport timeitimport xlwtimport xlrdimport mathimport sys

Case for General Graphsdef forced edges(Gadj dict2matching dict1num nodesforced)

flagg=0for n in range(0num nodes)

for k in adj dict2[n]if ([k]==matching dict1[n])

count=0for l in range(0num nodes)

count=count+adj dict2[l]count(k)if (len(adj dict2[n])==1) or (count==1)

forcedadd edge(nk)Gremove edge(nk)Gremove node(n)Gremove node(k)printforced edgenktemp=kflagg=1for m in range (len(adj dict2[n])minus1minus1minus1)

adj dict2[adj dict2[n][m]]remove(n)adj dict2[n]remove(adj dict2[n][m])

if adj dict2[temp]for l in range(len(adj dict2[temp])minus1minus1minus1)

if (adj dict2[temp][l]=n)adj dict2[adj dict2[temp][l]]remove(temp)adj dict2[temp]remove(adj dict2[temp][l])

break

def useless edges(num nodesadj dict1matching dict1uselessadj dict2G)for n in range(0num nodes)

for k in adj dict1[n]if ([k]=matching dict1[n]) and matching dict1[n] and matching dict1[k]

uselessadd edge(nk)Gremove edge(n k)

Appendix A 47

tempa=kadj dict2[n]remove(k)adj dict2[tempa]remove(n)adj dict1[tempa]remove(n)

return G

def Greedy(num nodesadj dict3matching dict2)

for n in range(0num nodes)if matching dict2[n]

flag2=minus1flag3=minus1for v in adj dict3[n]

if not matching dict2[v]flag2=vbreak

for p in adj dict3[matching dict2[n][0]]if not matching dict2[p]

flag3=pbreak

if (flag2=minus1) and (flag3=minus1) and (flag2=flag3)tempr=matching dict2[n][0]matching dict2[n]=[flag2]matching dict2[flag2]=[n]matching dict2[tempr]=[flag3]matching dict2[flag3]=[tempr]

elsefor k in adj dict3[n]

if not matching dict2[k]matching dict2[n]=[k]matching dict2[k]=[n]break

yo1=0for i in range(0num nodes)

if matching dict2[i] and [i]==matching dict2[matching dict2[i][0]]yo1=yo1+1

greedy size=yo12return greedy size

def General()

INPUTSwb = xlwtWorkbook()ws = wbadd sheet(Results Random)book=xlrdopen workbook(filenames randomxls)

48 Application

style0 = xlwteasyxf(fontbold on)style1 = xlwteasyxf(num format str=0000)INPUTSwswrite(0 0File style0)wswrite(0 1 Nodesstyle0)wswrite(0 2 Initial matchingstyle0)wswrite(0 3 NodesGstyle0)wswrite(0 4 EdgesGstyle0)wswrite(0 5 MaxDegreeGstyle0)wswrite(0 6 NodesG hatstyle0)wswrite(0 7 EdgesG Hatstyle0)wswrite(0 8 Useless edgesstyle0)wswrite(0 9 Forced edgesstyle0)wswrite(0 10 MaxDegreeG Hatstyle0)wswrite(0 11 Classical matchingstyle0)wswrite(0 12 Final matchingstyle0)wswrite(0 13 Greedy matchingstyle0)wswrite(0 14 Time classicalstyle0)wswrite(0 15 Time algorithmstyle0)wswrite(0 16 Time greedystyle0)wswrite(0 17 Perfect matching ratiostyle0)wswrite(0 18 Nodes ratiostyle0)wswrite(0 19 Edges ratiostyle0)wswrite(0 20 Matching ratiostyle0)

print nWelcomeThis is an implementation for general random graphs It uses Edmonds algorithm to compute maximum matching on G Hatn

for index in range (1481)was 481

if (index==482)f=open(Algotel generaltxtr)readlines()

elsefilea=str(booksheet by index(0)cell(index0))s=fileareplace(textu)replace()f=open(sr)readlines()Truewswrite(index 0 s)

print index

num nodes=int([xstrip()split() for x in f][0][0])

num matching=int([xstrip()split() for x in f][2][0])

adj temp = [xstrip()split() for x in f][44+num nodes]adj=[map(intR) for R in adj temp]

matching temp=[xstrip()split() for x in f][4+num nodes+14+2num nodes+1]matching1=[map(intR) for R in matching temp]

adj dict1=i[ii for iix in enumerate(L) if x] for iL in enumerate(adj)adj dict2=i[ii for iix in enumerate(L) if x] for iL in enumerate(adj)

Appendix A 49

adj dict3=i[ii for iix in enumerate(L) if x] for iL in enumerate(adj)

matching dict1=i[ii for iix in enumerate(L) if x] for iL in enumerate(matching1)matching dict2=i[ii for iix in enumerate(L) if x] for iL in enumerate(matching1)print adj dict2print matching dict2wswrite(index 1 num nodes)wswrite(index 2 num matching)

G = nxGraph()

useless= nxGraph()forced = nxGraph()

Fill Graphfor n in range(0num nodes)

for k in adj dict1[n]Gadd edge(nk)

Gt=Gnumber of edges()wswrite(index 3 Gnumber of nodes())wswrite(index 4 Gnumber of edges())wswrite(index 5 max(Gdegree()values()))

Compute Edmonds classical matching on G for comparison

startB = timeitdefault timer()Classical Matching=nxmax weight matching(G maxcardinality=False)stopB = timeitdefault timer()

Compute Gˆ nad MˆstartC = timeitdefault timer()useless edges(num nodesadj dict1matching dict1uselessadj dict2G)forced edges(Gadj dict2matching dict1num nodesforced)Final Matching=nxmax weight matching(G maxcardinality=False)stopC = timeitdefault timer()

GreedystartG = timeitdefault timer()greedy size=Greedy(num nodesadj dict3matching dict2)stopG = timeitdefault timer()

wswrite(index 6 Gnumber of nodes())wswrite(index 7 Gnumber of edges())wswrite(index 8 uselessnumber of edges())wswrite(index 9 forcednumber of edges())if Gdegree()values()

wswrite(index 10 max(Gdegree()values()))else

50 Application

wswrite(index 10 0)wswrite(index 11 len(Classical Matching)2)wswrite(index 12 len(Final Matching)2+forcednumber of edges())wswrite(index 13 greedy size)wswrite(index 14 stopB minus startBstyle1)wswrite(index 15 stopC minus startCstyle1)wswrite(index 16 stopG minus startGstyle1)wswrite(index 17 (len(Final Matching)2+forcednumber of edges())(num nodes2)style1)wswrite(index 18 Gnumber of nodes()Gtstyle1)wswrite(index 19 Gnumber of edges()Gtstyle1)wswrite(index 20 (len(Final Matching)2+forcednumber of edges())(len(Classical Matching)2)style1)

wbsave(AA Results Random Reyni Large Bipartitexls)

Main function Here we must choose the input form of the dataif name == main

startA = timeitdefault timer()General()stopA = timeitdefault timer()

print nThis program has terminatednnRunning time for 480 files stopAminusstartAprint nnPlease open AA Results Random Reyni Largexls file to see the Results

Appendix A 51

Plotmat

clear allclose allload(RN1Lmat)load(RN1Smat)load(RN2Lmat)load(RN2Smat)load(RN3Lmat)load(RN3Smat)

Plotsh(1)=figure(NameHistogram of Matching size difference between Constraint Algorithm and Greedy AlgorithmNumberTitleoff)

RN1L Greedydiff=RN1L Final matchingminusRN1L Greedy matchingRN2L Greedydiff=RN2L Final matchingminusRN2L Greedy matchingRN3L Greedydiff=RN3L Final matchingminusRN3L Greedy matchingRN1S Greedydiff=RN1S Final matchingminusRN1S Greedy matchingRN2S Greedydiff=RN2S Final matchingminusRN2S Greedy matchingRN3S Greedydiff=RN3S Final matchingminusRN3S Greedy matching

RN1L Finaldiff=RN1L Classical matchingminusRN1L Final matchingRN2L Finaldiff=RN2L Classical matchingminusRN2L Final matchingRN3L Finaldiff=RN3L Classical matchingminusRN3L Final matchingRN1S Finaldiff=RN1S Classical matchingminusRN1S Final matchingRN2S Finaldiff=RN2S Classical matchingminusRN2S Final matchingRN3S Finaldiff=RN3S Classical matchingminusRN3S Final matching

RN1L Classicaldiff=(RN1L Nodes2)minusRN1L Classical matchingRN2L Classicaldiff=(RN2L Nodes2)minusRN2L Classical matchingRN3L Classicaldiff=(RN3L Nodes2)minusRN3L Classical matchingRN1S Classicaldiff=(RN1S Nodes2)minusRN1S Classical matchingRN2S Classicaldiff=(RN2S Nodes2)minusRN2S Classical matchingRN3S Classicaldiff=(RN3S Nodes2)minusRN3S Classical matching

subplot(231)hold onhistf(RN1L Greedydiff0110facecolorbfacealpha9edgealpha1)histf(RN1L Finaldiff0110facecolorrfacealpha5edgealpha1)histf(RN1L Classicaldiff0110facecolorgfacealpha5edgealpha1)legalpha(ConminusGreClasminusConPerfminusClasslocationnortheast)legend boxoffaxis tightxlabel(edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN1L)grid on

subplot(232)hold onhistf(RN2L Greedydiff0110facecolorbfacealpha9edgealpha1)

52 Application

histf(RN2L Finaldiff0110facecolorrfacealpha5edgealpha1)histf(RN2L Classicaldiff0110facecolorgfacealpha5edgealpha1)legalpha(ConminusGreClasminusConPerfminusClasslocationnortheast)legend boxoffaxis tightxlabel(edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN2L)grid on

subplot(233)hold onhistf(RN3L Greedydiff0110facecolorbfacealpha5edgealpha1)histf(RN3L Finaldiff0110facecolorrfacealpha5edgealpha1)histf(RN3L Classicaldiff0110facecolorgfacealpha5edgealpha1)legalpha(ConminusGreClasminusConPerfminusClasslocationnortheast)legend boxoffaxis tightxlabel(edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN3L)grid on

subplot(234)hold onhistf(RN1S Greedydiff0110facecolorbfacealpha5edgealpha1)histf(RN1S Finaldiff0110facecolorrfacealpha5edgealpha1)histf(RN1S Classicaldiff0110facecolorgfacealpha5edgealpha1)legalpha(ConminusGreClasminusConPerfminusClasslocationnortheast)legend boxoffaxis tightxlabel(edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(R1NS)grid on

subplot(235)hold onhistf(RN2S Greedydiff0110facecolorbfacealpha5edgealpha1)histf(RN2S Finaldiff0110facecolorrfacealpha5edgealpha1)histf(RN2S Classicaldiff0110facecolorgfacealpha5edgealpha1)legalpha(ConminusGreClasminusConPerfminusClasslocationnortheast)legend boxoffaxis tightxlabel(edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN2S)grid on

subplot(236)hold onhistf(RN3S Greedydiff0110facecolorbfacealpha5edgealpha1)histf(RN3S Finaldiff0110facecolorrfacealpha5edgealpha1)histf(RN3S Classicaldiff0110facecolorgfacealpha5edgealpha1)

Appendix A 53

legalpha(ConminusGreClasminusConPerfminusClasslocationnortheast)legend boxoffaxis tightgrid ontitle(RN3S)xlabel(edges) xminusaxis labelylabel(instances) yminusaxis labelset(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN1png minusr300)h(2)=figure(NameHistogram of Max Degree of G AND G HatNumberTitleoff)RN1L x=RN1L MaxDegreeGminusRN1L MaxDegreeG HatRN2L x=RN2L MaxDegreeGminusRN2L MaxDegreeG HatRN3L x=RN3L MaxDegreeGminusRN3L MaxDegreeG HatRN1S x=RN1S MaxDegreeGminusRN1S MaxDegreeG HatRN2S x=RN2S MaxDegreeGminusRN2S MaxDegreeG HatRN3S x=RN3S MaxDegreeGminusRN3S MaxDegreeG Hatsubplot(231)hold onhistf(RN1L MaxDegreeG0150facecolorbfacealpha5edgealpha1)histf(RN1L MaxDegreeG Hat0150facecolorrfacealpha5edgealpha1)histf(RN1L x0150facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightxlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN1L)grid on

subplot(232)hold onhistf(RN2L MaxDegreeG010500facecolorbfacealpha5edgealpha1)histf(RN2L MaxDegreeG Hat010500facecolorrfacealpha5edgealpha1)histf(RN2L x010500facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightxlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN2L)grid on

subplot(233)hold onhistf(RN3L MaxDegreeG010300facecolorbfacealpha5edgealpha1)histf(RN3L MaxDegreeG Hat010300facecolorrfacealpha5edgealpha1)histf(RN3L x010300facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightxlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN3L)

54 Application

grid on

subplot(234)hold onhistf(RN1S MaxDegreeG0150facecolorbfacealpha5edgealpha1)histf(RN1S MaxDegreeG Hat0150facecolorrfacealpha5edgealpha1)histf(RN1S x0150facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightxlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(R1NS)grid on

subplot(235)hold onhistf(RN2S MaxDegreeG010500facecolorbfacealpha5edgealpha1)histf(RN2S MaxDegreeG Hat010500facecolorrfacealpha5edgealpha1)histf(RN2S x010500facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightxlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN2S)grid on

subplot(236)hold onhistf(RN3S MaxDegreeG05300facecolorbfacealpha5edgealpha1)histf(RN3S MaxDegreeG Hat05300facecolorrfacealpha5edgealpha1)histf(RN3S x05300facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightgrid ontitle(RN3S)xlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labelset(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN2png minusr300)

h(3)=figure(NameComputation time over edgesNumberTitleoff)

subplot(231)hold onstem(RN1L EdgesGRN1L Time classicalg)stem(RN1L EdgesGRN1L Time algorithmro)stem(RN1L EdgesGRN1L Time greedybx)grid on

Appendix A 55

title(RN1L)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)

subplot(232)hold onstem(RN2L EdgesGRN2L Time classicalg)stem(RN2L EdgesGRN2L Time algorithmro)stem(RN2L EdgesGRN2L Time greedybx)grid ontitle(RN2L)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)

subplot(233)hold onstem(RN3L EdgesGRN3L Time classicalg)stem(RN3L EdgesGRN3L Time algorithmro)stem(RN3L EdgesGRN3L Time greedybx)grid ontitle(RN3L)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)

subplot(234)hold onstem(RN1S EdgesGRN1S Time classicalg)stem(RN1S EdgesGRN1S Time algorithmro)stem(RN1S EdgesGRN1S Time greedybx)grid ontitle(RN1S)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)

subplot(235)hold onstem(RN2S EdgesGRN2S Time classicalg)stem(RN2S EdgesGRN2S Time algorithmro)stem(RN2S EdgesGRN2S Time greedybx)grid ontitle(RN2S)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)

subplot(236)hold onstem(RN3S EdgesGRN3S Time classicalg)stem(RN3S EdgesGRN3S Time algorithmro)stem(RN3S EdgesGRN3S Time greedybx)

56 Application

grid ontitle(RN3S)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)set(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN3png minusr300)

h(4)=figure(NameSorted matching sizeNumberTitleoff)RN1L Sorted matching temp(1)=RN1L Classical matchingRN1L Sorted matching temp(2)=RN1L Final matchingRN1L Sorted matching temp(3)=RN1L Greedy matchingRN1L Sorted matching temp(4)=RN1L Initial matchingRN1L Sorted matching=sortrows(RN1L Sorted matching temp)

RN2L Sorted matching temp(1)=RN2L Classical matchingRN2L Sorted matching temp(2)=RN2L Final matchingRN2L Sorted matching temp(3)=RN2L Greedy matchingRN2L Sorted matching temp(4)=RN2L Initial matchingRN2L Sorted matching=sortrows(RN2L Sorted matching temp)

RN3L Sorted matching temp(1)=RN3L Classical matchingRN3L Sorted matching temp(2)=RN3L Final matchingRN3L Sorted matching temp(3)=RN3L Greedy matchingRN3L Sorted matching temp(4)=RN3L Initial matchingRN3L Sorted matching=sortrows(RN3L Sorted matching temp)

RN1S Sorted matching temp(1)=RN1S Classical matchingRN1S Sorted matching temp(2)=RN1S Final matchingRN1S Sorted matching temp(3)=RN1S Greedy matchingRN1S Sorted matching temp(4)=RN1S Initial matchingRN1S Sorted matching=sortrows(RN1S Sorted matching temp)

RN2S Sorted matching temp(1)=RN2S Classical matchingRN2S Sorted matching temp(2)=RN2S Final matchingRN2S Sorted matching temp(3)=RN2S Greedy matchingRN2S Sorted matching temp(4)=RN2S Initial matchingRN2S Sorted matching=sortrows(RN2S Sorted matching temp)

RN3S Sorted matching temp(1)=RN3S Classical matchingRN3S Sorted matching temp(2)=RN3S Final matchingRN3S Sorted matching temp(3)=RN3S Greedy matchingRN3S Sorted matching temp(4)=RN3S Initial matchingRN3S Sorted matching=sortrows(RN3S Sorted matching temp)

subplot(231)hold onplot(RN1L Sorted matching(1)b)plot(RN1L Sorted matching(2)g)plot(RN1L Sorted matching(3)r)plot(RN1L Sorted matching(4)m)

Appendix A 57

grid ontitle(RN1L)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)

subplot(232)hold onplot(RN2L Sorted matching(1)b)plot(RN2L Sorted matching(2)g)plot(RN2L Sorted matching(3)r)plot(RN2L Sorted matching(4)m)grid ontitle(RN2L)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)

subplot(233)hold onplot(RN3L Sorted matching(1)b)plot(RN3L Sorted matching(2)g)plot(RN3L Sorted matching(3)r)plot(RN3L Sorted matching(4)m)grid ontitle(RN3L)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)

subplot(234)hold onplot(RN1S Sorted matching(1)b)plot(RN1S Sorted matching(2)g)plot(RN1S Sorted matching(3)r)plot(RN1S Sorted matching(4)m)grid ontitle(RN1S)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)

subplot(235)hold onplot(RN2S Sorted matching(1)b)plot(RN2S Sorted matching(2)g)plot(RN2S Sorted matching(3)r)plot(RN2S Sorted matching(4)m)grid ontitle(RN2S)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)

58 Application

subplot(236)hold onplot(RN3S Sorted matching(1)b)plot(RN3S Sorted matching(2)g)plot(RN3S Sorted matching(3)r)plot(RN3S Sorted matching(4)m)grid ontitle(RN3S)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)set(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN4png minusr300)h(5)=figure(NameSorted RatiosNumberTitleoff)RN1L ratio1=RN1L NodesG hatRN1L NodesGRN2L ratio1=RN2L NodesG hatRN2L NodesGRN3L ratio1=RN3L NodesG hatRN3L NodesGRN1S ratio1=RN1S NodesG hatRN1S NodesGRN2S ratio1=RN2S NodesG hatRN2S NodesGRN3S ratio1=RN3S NodesG hatRN3S NodesG

RN1L ratio2=RN1L EdgesG HatRN1L EdgesGRN2L ratio2=RN2L EdgesG HatRN2L EdgesGRN3L ratio2=RN3L EdgesG HatRN3L EdgesGRN1S ratio2=RN1S EdgesG HatRN1S EdgesGRN2S ratio2=RN2S EdgesG HatRN2S EdgesGRN3S ratio2=RN3S EdgesG HatRN3S EdgesG

RN1L ratio3=RN1L MaxDegreeG HatRN1L MaxDegreeGRN2L ratio3=RN2L MaxDegreeG HatRN2L MaxDegreeGRN3L ratio3=RN3L MaxDegreeG HatRN3L MaxDegreeGRN1S ratio3=RN1S MaxDegreeG HatRN1S MaxDegreeGRN2S ratio3=RN2S MaxDegreeG HatRN2S MaxDegreeGRN3S ratio3=RN3S MaxDegreeG HatRN3S MaxDegreeG

RN1L ratio(1)=RN1L ratio1RN1L ratio(2)=RN1L ratio2RN1L ratio(3)=RN1L ratio3

RN2L ratio(1)=RN2L ratio1RN2L ratio(2)=RN2L ratio2RN2L ratio(3)=RN2L ratio3

RN3L ratio(1)=RN3L ratio1RN3L ratio(2)=RN3L ratio2RN3L ratio(3)=RN3L ratio3

RN1S ratio(1)=RN1S ratio1RN1S ratio(2)=RN1S ratio2RN1S ratio(3)=RN1S ratio3

RN2S ratio(1)=RN2S ratio1

Appendix A 59

RN2S ratio(2)=RN2S ratio2RN2S ratio(3)=RN2S ratio3

RN3S ratio(1)=RN3S ratio1RN3S ratio(2)=RN3S ratio2RN3S ratio(3)=RN3S ratio3

RN1L ratio sorted=sortrows(RN1L ratio)RN2L ratio sorted=sortrows(RN2L ratio)RN3L ratio sorted=sortrows(RN3L ratio)RN1S ratio sorted=sortrows(RN1S ratio)RN2S ratio sorted=sortrows(RN2S ratio)RN3S ratio sorted=sortrows(RN3S ratio)

subplot(231)hold onplot(RN1L ratio sorted(1)b)plot(RN1L ratio sorted(2)g)plot(RN1L ratio sorted(3)r)grid ontitle(RN1L)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)

subplot(232)hold onplot(RN2L ratio sorted(1)b)plot(RN2L ratio sorted(2)g)plot(RN2L ratio sorted(3)r)grid ontitle(RN2L)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)

subplot(233)hold onplot(RN3L ratio sorted(1)b)plot(RN3L ratio sorted(2)g)plot(RN3L ratio sorted(3)r)grid ontitle(RN3L)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)

subplot(234)hold onplot(RN1S ratio sorted(1)b)plot(RN1S ratio sorted(2)g)plot(RN1S ratio sorted(3)r)grid on

60 Application

title(RN1S)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)

subplot(235)hold onplot(RN2S ratio sorted(1)b)plot(RN2S ratio sorted(2)g)plot(RN2S ratio sorted(3)r)grid ontitle(RN2S)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)

subplot(236)hold onplot(RN3S ratio sorted(1)b)plot(RN3S ratio sorted(2)g)plot(RN3S ratio sorted(3)r)grid ontitle(RN3S)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)set(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN5png minusr300)

h(6)=figure(NameSorted edges over nodesNumberTitleoff)

RN1L DegreeG1=(RN1L EdgesG)(RN1L NodesG)RN1L DegreeG Hat1=(RN1L EdgesG Hat)(RN1L NodesG hat)

RN1L Degree temp1(1)=RN1L DegreeG1RN1L Degree temp1(2)=RN1L DegreeG Hat1RN1L Degree sorted1=sortrows(RN1L Degree temp1)subplot(231)hold on

plot(RN1L Degree sorted1(1)b)plot(RN1L Degree sorted1(2)g)grid ontitle(RN1L)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)

RN2L DegreeG1=(RN2L EdgesG)(RN2L NodesG)RN2L DegreeG Hat1=(RN2L EdgesG Hat)(RN2L NodesG hat)

RN2L Degree temp1(1)=RN2L DegreeG1

Appendix A 61

RN2L Degree temp1(2)=RN2L DegreeG Hat1RN2L Degree sorted1=sortrows(RN2L Degree temp1)

subplot(232)hold onplot(RN2L Degree sorted1(1)b)plot(RN2L Degree sorted1(2)g)grid ontitle(RN2L)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)

RN3L DegreeG1=(RN3L EdgesG)(RN3L NodesG)RN3L DegreeG Hat1=(RN3L EdgesG Hat)(RN3L NodesG hat)

RN3L Degree temp1(1)=RN3L DegreeG1RN3L Degree temp1(2)=RN3L DegreeG Hat1RN3L Degree sorted1=sortrows(RN3L Degree temp1)

subplot(233)hold onplot(RN3L Degree sorted1(1)b)plot(RN3L Degree sorted1(2)g)grid ontitle(RN3L)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)

RN1S DegreeG1=(RN1S EdgesG)(RN1S NodesG)RN1S DegreeG Hat1=(RN1S EdgesG Hat)(RN1S NodesG hat)

RN1S Degree temp1(1)=RN1S DegreeG1RN1S Degree temp1(2)=RN1S DegreeG Hat1RN1S Degree sorted1=sortrows(RN1S Degree temp1)

subplot(234)hold onplot(RN1S Degree sorted1(1)b)plot(RN1S Degree sorted1(2)g)grid ontitle(RN1S)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)

RN2S DegreeG1=(RN2S EdgesG)(RN2S NodesG)RN2S DegreeG Hat1=(RN2S EdgesG Hat)(RN2S NodesG hat)

RN2S Degree temp1(1)=RN2S DegreeG1

62 Application

RN2S Degree temp1(2)=RN2S DegreeG Hat1RN2S Degree sorted1=sortrows(RN2S Degree temp1)

subplot(235)hold onplot(RN2S Degree sorted1(1)b)plot(RN2S Degree sorted1(2)g)grid ontitle(RN2S)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)

RN3S DegreeG1=(RN3S EdgesG)(RN3S NodesG)RN3S DegreeG Hat1=(RN3S EdgesG Hat)(RN3S NodesG hat)

RN3S Degree temp1(1)=RN3S DegreeG1RN3S Degree temp1(2)=RN3S DegreeG Hat1RN3S Degree sorted1=sortrows(RN3S Degree temp1)

subplot(236)hold onplot(RN3S Degree sorted1(1)b)plot(RN3S Degree sorted1(2)g)grid ontitle(RN3S)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)set(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN6png minusr300)h(7)=figure(NameSorted mATCHED DEGREENumberTitleoff)RN1L ratioMax(1)=RN1L MaxDegreeGRN1L ratioMax(2)=RN1L MaxDegreeG Hat

RN1L ratio sortedMax=sortrows(RN1L ratioMax)subplot(231)hold onplot(RN1L ratio sortedMax(1)b)plot(RN1L ratio sortedMax(2)g)grid ontitle(RN1L)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)

RN2L ratioMax(1)=RN2L MaxDegreeGRN2L ratioMax(2)=RN2L MaxDegreeG Hat

RN2L ratio sortedMax=sortrows(RN2L ratioMax)subplot(232)

Appendix A 63

hold onplot(RN2L ratio sortedMax(1)b)plot(RN2L ratio sortedMax(2)g)grid ontitle(RN2L)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)

RN3L ratioMax(1)=RN3L MaxDegreeGRN3L ratioMax(2)=RN3L MaxDegreeG Hat

RN3L ratio sortedMax=sortrows(RN3L ratioMax)subplot(233)hold onplot(RN3L ratio sortedMax(1)b)plot(RN3L ratio sortedMax(2)g)grid ontitle(RN3L)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)

RN1S ratioMax(1)=RN1S MaxDegreeGRN1S ratioMax(2)=RN1S MaxDegreeG Hat

RN1S ratio sortedMax=sortrows(RN1S ratioMax)subplot(234)hold onplot(RN1S ratio sortedMax(1)b)plot(RN1S ratio sortedMax(2)g)grid ontitle(RN1S)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)

RN2S ratioMax(1)=RN2S MaxDegreeGRN2S ratioMax(2)=RN2S MaxDegreeG Hat

RN2S ratio sortedMax=sortrows(RN2S ratioMax)

subplot(235)hold onplot(RN2S ratio sortedMax(1)b)plot(RN2S ratio sortedMax(2)g)grid ontitle(RN2S)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)

RN3S ratioMax(1)=RN3S MaxDegreeGRN3S ratioMax(2)=RN3S MaxDegreeG Hat

64 Application

RN3S ratio sortedMax=sortrows(RN3S ratioMax)subplot(236)hold onplot(RN3S ratio sortedMax(1)b)plot(RN3S ratio sortedMax(2)g)grid ontitle(RN1L)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)set(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN7png minusr300)

tilefigs()(h)

Bibliography

[1] C Berge ldquoTWO THEOREMS IN GRAPH THEORYrdquo Proceedings of the NationalAcademy of Sciences of the United States of America vol 43 no 9 pp 842ndash844Sep 1957

[2] L Bui S Sanghavi and R Srikant ldquoDistributed link scheduling with constantoverheadrdquo IEEEACM Trans Netw vol 17 no 5 pp 1467ndash1480 2009

[3] R Duan and S Pettie ldquoLinear-time approximation for maximum weight matchingrdquoJ ACM vol 61 no 1 2014

[4] J Edmonds ldquoPaths trees and flowersrdquo Canadian Journal of Mathematics vol 17pp 449ndash467 1965

[5] J E Hopcroft and R M Karp ldquoAn n52 algorithm for maximum matchings inbipartite graphsrdquo SIAM J Comput vol 2 no 4 pp 225ndash231 1973

[6] S Micali and V V Vazirani ldquoAn O(radic|V ||E|) algorithm for finding maximum

matching in general graphsrdquo in 21st Symp on Foundations of Comp Sc (FOCS)IEEE 1980 pp 17ndash27

[7] N Nisse A Salch and V Weber ldquoRecovery of disrupted airline operationsrdquo 2015httphalinriafrSomething

[8] X Wu and R Srikant ldquoRegulated maximal matching A distributed schedulingalgorithm for multi-hop wireless networks with nodeexclusive spectrum sharingrdquo inIEEE Conf on Decision and Control 2005

65

  • Contents
  • Introduction
  • Algorithms
    • Maximum matching
    • k-maximum matching
      • k-matching for Airport Slot assignment
      • The case where k=3
      • The case of Paths
      • The case of the Spider
          • Application
            • Description
            • Reyni Erdos
            • Barabaacutesi Albert
            • Amadeus Graphs
            • Bipartite
            • Bipartite with degree seq
            • Appendix A
              • BipartiteGraphGeneratorpy
              • RandomGraphGeneratorpy
              • kequals3MaximumMatchingpy
              • Plotmat
                  • Bibliography
Page 20: Theodoros Alexandros KARAGKIOULES -  · Introduction This work is the result of a 6 months internship, under the supervision of research O cer Nicolas NISSE. The original scope of

23 Barabasi Albert 21

Sorted |E||V | - Comments

bull Although as graph density the ratio 2|E||V |(|V |minus1)

is considered in this set of figures

we evaluate the correlation of the ratio |E||V | of G and G since the density of G

could acquire values higher than that of G

bull The figures are calculated in ascending order for the ratio of G

bull For the case of large initial matching the two ratios for G and G remain almostconstant ( to the extent of the edge attraction m of each graph) since removingforced edges( and their endpoints) alters the |E| and |V | proportionately

bull For the case of small initial matching we observe some deviation in the valuesof the ration for G and that is explained with the removal of only useless edgeswhich only alters the |E| and keeps |V | in the original values

Sorted ∆

22 Application

Sorted ∆-Comments

bull In this set of figures the ascending order of the ∆ of G is associated with the ∆of G

bull There is a significant jump of the ∆ for each graph category which tells that thatwe are not comparing a uniform distribution of random graphs and based on theedge attraction m the graphs can vary in form

bull For larger initial matching we observe the difference in the ∆s of G and G giventhe removed forced edges( and their endpoints) At some cases the ∆ of G dropsto 0 since the vast majority of edges have been declared forced and removed alongwith their endpoints What is interesting is that the ∆ of G oscilates within stablelimits

24 Amadeus Graphs 23

bull For smaller initial matching the ∆s of G and G follow mostly the same trend onlya few number of different instances

24 Amadeus Graphs

Graph characteristics Amadeus graphs

bull These are the bipartite graphs provided by Amadeus

Computation time over |E|

Computation time over |E| - Comments

24 Application

bull For every instance the computation time of the classical algorithm is always smallerto that of the constraint matching

bull This allows as to speculate that we always compute a smaller G which also impliesthat we always find a set of forced edges and useless

Sorted matching size

Sorted matching size - Comments

bull Size of matching has an upward trend since the magnitude of the graphs is notthe same for the 160 instances

bull No significant deviation is noticed as per the first graph

24 Amadeus Graphs 25

bull Except from deviation from the perfect matching (number of flights) where some-times it could get up to 40

bull For the Amadeus Bipartite graphs we can see that the difference of the Classicaland the constraint implementation is not more than 1 edge in the matching

bull There appears to be a difference of up to 24 edges between the Classical matchingand the Perfect matching which is computed as the number of flights

bull The greedy algorithm performs well with only a few instances deviating slightlyform the Constraint algorithm result

Sorted Ratios

Sorted Ratios - Comments

26 Application

bull

Sorted |E||V |

Sorted |E||V | - Comments

bull Density of the graphs shows that on average we have 25-3 available time slot perflight

bull The line for the same value for G shows that there is a large deviation for everyinstance which allows for the hypothesis that the amount of useless+forced edgesof G has no obvious correlation to that of G

25 Bipartite 27

Sorted ∆

Sorted ∆-Comments

bull As per the previous related graphs for ∆ there is in significant drop in the ∆ of Gand G

25 Bipartite

Graph characteristics Bipartite random Graphs

bull BIPxy are randomly generated graphs with a fixed number of 1000(n=500 andm=500) nodes

bull There are 6 categories based on ini matching and probability p

28 Application

bull Probability p has been chosen as such in order to simulate the |E||V | 25 of theAmadeus bipartite graphs

bull So in order to have about 2-4 edges for every node we choose accordingly theprobability p to choose one of the n lowastm possible edges

bull x = L S L When the initial matching is large and S when it is small

bull y = 1 2 3 1 when p = 18250

2 when p = 25250

and 3 when p = 34250

Computation time over

Computation time overedges-Comments

bull

25 Bipartite 29

Sorted matching size

Sorted matching size-Comments

bull In these set of graphs one can instantly notice that only a few instances with highprobability can reach a matching size equal to the perfect matching

bull For the case of the initial matching we witness that there is a gap between the lineof the classical matching and those of the constraint and greedy results suggestingsmaller matching sizes of 10-40 edges

bull For the case of the small initial matching the result of the constraint matchingis now close to the result of the classical matching yet the greedy algorithm stillshows a relevantly big difference

30 Application

bull In this set of bipartite graphs we can witness that the result of the Constraintmatching shows a difference with the classical matching when the initial matchingis large The difference is smaller as the probability gets larger

bull For the case of the small initial matching the above phenomenom does not occuryet the greedy results deviates from that of the constraint matching

bull As per the pefrect matching compared to the classical matching a difference of5-10 edges is evident at almost all cases

Sorted Ratios

Sorted Ratios-Comments

bull Great max degree deviation

25 Bipartite 31

bull Regardless of the probability the ration of nodes and edges seems to have similarbehaviour when compared to the respective graphs of the same matching scale

bull Same gap between nodes ration and edges ration for all cases

Sorted |E||V |

Sorted |E||V | - Comments

bull In these set of figures we witness that the |E||V | acquires values relevant to those ofthe amadeus graphs The random graphs were constructed to depict this similarity

bull For smaller initial matching the ratios for G and G show the same upward trendand also they acquire closer values It represents the decrease of the averagenumber of forced edges in comparison to the larger matching cases

32 Application

Sorted ∆

Sorted ∆-Comments

bull ∆ acquires the same min and max values for each probability case (expected)

bull Gap in the case of large initial matching

26 Bipartite with degree seq

Graph characteristics

bull DEQBIPxy are randomly generated graphs based on three different types of degreedistribution of the Amadeus graphs

26 Bipartite with degree seq 33

bull There are 6 categories based on ini matching and degree distribution

bull x = L S L When the initial matching is large and S when it is small

bull y = 1 2 3 1 when degree distribution is based on file 2 when degree distributionis based on file and 3 when degree distribution is based on file

Computation time over

34 Application

Computation time overedges-Comments

bull Greedy algorithm takes minimum amount of time

bull The smaller the initial matching the more smaller the difference in comoutationtime of Constraint and classical algorithm

bull Due to preprocessing and the fact that G and G are the almost identical thetotal time needed to apply the constraint algorithm is in some cases bigger

Sorted matching size

26 Bipartite with degree seq 35

Sorted matching size-Comments

bull Classical matching is equal to perfect matching in every case

bull Constraint and greedy have identical behaviour

bull The larger the spectrum of the degree sequence the more efficient the matching

Sorted Ratios

36 Application

Sorted Ratios-Comments

bull With large initial matching most of the edges are considenred uselles or forced andare removed thus the ratio is close(if not equal to) zero

bull For small matching and large degree sequence sectrum hte max degree remainsthe same Only a few forced edges (and their nodes) are removed apparently nonodes with max degree

Sorted |E||V |

26 Bipartite with degree seq 37

Sorted |E||V | - Comments

bull In these set of figures we witness that the |E||V | acquires values relevant to those ofthe amadeus graphs The random graphs were constructed to depict this similarity

bull For smaller initial matching the ratios for G and G show the same upward trendand also they acquire closer values It repsresent the decrease of the averagenumber of forced edges in comparison to the larger matching cases

Sorted ∆

38 Application

Sorted ∆-Comments

bull Big difference in max degree in large initial matching

bull Almost identical behaviour in the case of small initial matching

Appendix A 39

Appendix A

BipartiteGraphGeneratorpy

from future import divisionimport networkx as nx

from networkxalgorithms import approximationimport collectionsimport randomimport mathfrom networkxalgorithms import bipartiteif name == main

for i in range(1481)waqs 481index=1n=randomrandint(100 1000)

n1=95 was 500me1=118

n2=251 was 500me2=903

n3=165 was 500me3=412

m=0m1=0p=randomrandom()p1=18250p2=25250p3=34250print ip=05t1=randomrandint(0 1)print im2=randomrandint(n2minus1 n2+1)G = nxGraph()ma = nxGraph()

aseq1=[1 2 3 4 5 3]

bseq1=[4 3 3 1 2 2 1]

aseq2=[16 14 14 14 12 11]bseq2=[0 0 0 0 0 0]

aseq3=[8 7 8 8 8 8]bseq3=[0 0 0 0 0 0]

40 Application

print Gnumber of edges()if ilt=160

G=bipartiteconfiguration model(aseq1 bseq1 create using=None seed=None)A=nxadjacency matrix(G)for ii in range(0n1+me1)

maadd node(ii)A=[Rtodense()tolist()[0] for R in A]

printnummanumber of nodes()rl=randomsample(range(0n1+me1) n1+me1)m=0done vertices = set()for p in rlprintin fordone verticesadd(p)

neighbors = []list()for iii in range(0n1+me1)

if A[p][iii]==1neighborsappend(iii)

randomshuffle(neighbors)continue loop = Truedegree = len(neighbors)

print degreej = 0p4=randomrandom()while continue loop and (jltdegree)print in loop

next = neighbors[j]if next not in done vertices and p not in done vertices

done verticesadd(p)done verticesadd(next)if p4gt=07print added edge

maadd edge(pnext)m=m+1

continue loop = Falsej += 1

print matching listOfedgeprint maedge

MA=nxadjacency matrix(ma)print MA

MA=[Rtodense()tolist()[0] for R in MA]print MA

B=[ join(map(strR)) for R in A]MB=[ join(map(strR)) for R in MA]

C=njoin(B)+nMC=njoin(MB)+n

print nprint mprint m1

filea=str(i)+txtwith open(fileaw) as f

Appendix A 41

fwrite(str(n1+me1))fwrite(n)fwrite(str(n1+me1))fwrite(n)fwrite(str(m))fwrite(n)fwrite(n)fwrite(C)fwrite(n)fwrite(MC)

elif igt160 and ilt321G=bipartiteconfiguration model(aseq2 bseq2 create using=None seed=None)A=nxadjacency matrix(G)for ii in range(0n2+me2)

maadd node(ii)A=[Rtodense()tolist()[0] for R in A]

printnummanumber of nodes()rl=randomsample(range(0n2+me2) n2+me2)m=0done vertices = set()for p in rlprintin fordone verticesadd(p)

neighbors = []list()for iii in range(0n2+me2)

if A[p][iii]==1neighborsappend(iii)

randomshuffle(neighbors)continue loop = Truedegree = len(neighbors)

print degreej = 0p4=randomrandom()while continue loop and (jltdegree)

print in loopnext = neighbors[j]if next not in done vertices and p not in done vertices

done verticesadd(p)done verticesadd(next)if p4gt=07

print added edgemaadd edge(pnext)m=m+1

continue loop = Falsej += 1

print matching listOfedgeprint maedge

MA=nxadjacency matrix(ma)print MA

MA=[Rtodense()tolist()[0] for R in MA]print MA

B=[ join(map(strR)) for R in A]MB=[ join(map(strR)) for R in MA]

42 Application

C=njoin(B)+nMC=njoin(MB)+n

print nprint mprint m1

filea=str(i)+txtwith open(fileaw) as f

fwrite(str(n2+me2))fwrite(n)fwrite(str(n2+me2))fwrite(n)fwrite(str(m))fwrite(n)fwrite(n)fwrite(C)fwrite(n)fwrite(MC)

elseG=bipartiteconfiguration model(aseq3 bseq3 create using=None seed=None)A=nxadjacency matrix(G)for ii in range(0n3+me3)

maadd node(ii)A=[Rtodense()tolist()[0] for R in A]

printnummanumber of nodes()rl=randomsample(range(0n3+me3) n3+me3)m=0done vertices = set()for p in rlprintin fordone verticesadd(p)

neighbors = []list()for iii in range(0n3+me3)

if A[p][iii]==1neighborsappend(iii)

randomshuffle(neighbors)continue loop = Truedegree = len(neighbors)

print degreej = 0p4=randomrandom()while continue loop and (jltdegree)

print in loopnext = neighbors[j]if next not in done vertices and p not in done vertices

done verticesadd(p)done verticesadd(next)if p4gt=07print added edge

maadd edge(pnext)m=m+1

continue loop = Falsej += 1

Appendix A 43

print matching listOfedgeprint maedge

MA=nxadjacency matrix(ma)print MA

MA=[Rtodense()tolist()[0] for R in MA]print MA

B=[ join(map(strR)) for R in A]MB=[ join(map(strR)) for R in MA]

C=njoin(B)+nMC=njoin(MB)+n

print nprint mprint m1

filea=str(i)+txtwith open(fileaw) as f

fwrite(str(n3+me3))fwrite(n)fwrite(str(n3+me3))fwrite(n)fwrite(str(m))fwrite(n)fwrite(n)fwrite(C)fwrite(n)fwrite(MC)

print nRandom graphs with random matching have been generated

44 Application

RandomGraphGeneratorpy

from future import divisionimport networkx as nxfrom networkxalgorithms import approximationimport collectionsimport randomimport mathif name == main

for i in range(1481)index=1n=randomrandint(100 1000)

n=1000m=0m1=0p=randomrandom()p1=mathlog(n2)np2=13p3=mathlog(n2)n+01p=05t1=randomrandint(0 1)print im2=randomrandint(n2minus1 n2+1)G = nxGraph()ma = nxGraph()print nme1=randomrandint(1 10)me2=randomrandint(2050)me3=randomrandint(50100)if ilt241

if ilt=80G=nxfast gnp random graph(n p1 seed=None directed=False)

elif igt80 and ilt161G=nxfast gnp random graph(n p2 seed=None directed=False)

elseG=nxfast gnp random graph(n p3 seed=None directed=False)

elseif ilt=320

G=nxbarabasi albert graph(n me1 seed=None)elif igt320 and ilt401

G=nxbarabasi albert graph(n me2 seed=None)else

G=nxbarabasi albert graph(n me3 seed=None)A=nxadjacency matrix(G)for ii in range(0n)

maadd node(ii)A=[Rtodense()tolist()[0] for R in A]

rl=randomsample(range(0n) n)m=0

Appendix A 45

done vertices = set()for p in rl

done verticesadd(p)neighbors = []list()for iii in range(0n)

if A[p][iii]==1neighborsappend(iii)

randomshuffle(neighbors)continue loop = Truedegree = len(neighbors)j = 0p2=randomrandom()while continue loop and (jltdegree)

next = neighbors[j]if next not in done vertices and p not in done vertices

done verticesadd(p)done verticesadd(next)if p2gt=00 Larger probability for smaller initial matching

maadd edge(pnext)m=m+1

continue loop = Falsej += 1

print matching listOfedgeprint maedgeMA=nxadjacency matrix(ma)MA=[Rtodense()tolist()[0] for R in MA]print MAB=[ join(map(strR)) for R in A]MB=[ join(map(strR)) for R in MA]

C=njoin(B)+nMC=njoin(MB)+nprint MCprint nprint mprint m1filea=str(i)+txtwith open(fileaw) as f

fwrite(str(n))fwrite(n)fwrite(str(n))fwrite(n)fwrite(str(m))fwrite(n)fwrite(n)fwrite(C)fwrite(n)fwrite(MC)

print nRandom graphs with random matching have been generated

46 Application

kequals3MaximumMatchingpy

from future import divisionimport networkx as nxfrom networkxalgorithms import bipartiteimport matplotlibpyplot as pltimport collectionsimport timeitimport xlwtimport xlrdimport mathimport sys

Case for General Graphsdef forced edges(Gadj dict2matching dict1num nodesforced)

flagg=0for n in range(0num nodes)

for k in adj dict2[n]if ([k]==matching dict1[n])

count=0for l in range(0num nodes)

count=count+adj dict2[l]count(k)if (len(adj dict2[n])==1) or (count==1)

forcedadd edge(nk)Gremove edge(nk)Gremove node(n)Gremove node(k)printforced edgenktemp=kflagg=1for m in range (len(adj dict2[n])minus1minus1minus1)

adj dict2[adj dict2[n][m]]remove(n)adj dict2[n]remove(adj dict2[n][m])

if adj dict2[temp]for l in range(len(adj dict2[temp])minus1minus1minus1)

if (adj dict2[temp][l]=n)adj dict2[adj dict2[temp][l]]remove(temp)adj dict2[temp]remove(adj dict2[temp][l])

break

def useless edges(num nodesadj dict1matching dict1uselessadj dict2G)for n in range(0num nodes)

for k in adj dict1[n]if ([k]=matching dict1[n]) and matching dict1[n] and matching dict1[k]

uselessadd edge(nk)Gremove edge(n k)

Appendix A 47

tempa=kadj dict2[n]remove(k)adj dict2[tempa]remove(n)adj dict1[tempa]remove(n)

return G

def Greedy(num nodesadj dict3matching dict2)

for n in range(0num nodes)if matching dict2[n]

flag2=minus1flag3=minus1for v in adj dict3[n]

if not matching dict2[v]flag2=vbreak

for p in adj dict3[matching dict2[n][0]]if not matching dict2[p]

flag3=pbreak

if (flag2=minus1) and (flag3=minus1) and (flag2=flag3)tempr=matching dict2[n][0]matching dict2[n]=[flag2]matching dict2[flag2]=[n]matching dict2[tempr]=[flag3]matching dict2[flag3]=[tempr]

elsefor k in adj dict3[n]

if not matching dict2[k]matching dict2[n]=[k]matching dict2[k]=[n]break

yo1=0for i in range(0num nodes)

if matching dict2[i] and [i]==matching dict2[matching dict2[i][0]]yo1=yo1+1

greedy size=yo12return greedy size

def General()

INPUTSwb = xlwtWorkbook()ws = wbadd sheet(Results Random)book=xlrdopen workbook(filenames randomxls)

48 Application

style0 = xlwteasyxf(fontbold on)style1 = xlwteasyxf(num format str=0000)INPUTSwswrite(0 0File style0)wswrite(0 1 Nodesstyle0)wswrite(0 2 Initial matchingstyle0)wswrite(0 3 NodesGstyle0)wswrite(0 4 EdgesGstyle0)wswrite(0 5 MaxDegreeGstyle0)wswrite(0 6 NodesG hatstyle0)wswrite(0 7 EdgesG Hatstyle0)wswrite(0 8 Useless edgesstyle0)wswrite(0 9 Forced edgesstyle0)wswrite(0 10 MaxDegreeG Hatstyle0)wswrite(0 11 Classical matchingstyle0)wswrite(0 12 Final matchingstyle0)wswrite(0 13 Greedy matchingstyle0)wswrite(0 14 Time classicalstyle0)wswrite(0 15 Time algorithmstyle0)wswrite(0 16 Time greedystyle0)wswrite(0 17 Perfect matching ratiostyle0)wswrite(0 18 Nodes ratiostyle0)wswrite(0 19 Edges ratiostyle0)wswrite(0 20 Matching ratiostyle0)

print nWelcomeThis is an implementation for general random graphs It uses Edmonds algorithm to compute maximum matching on G Hatn

for index in range (1481)was 481

if (index==482)f=open(Algotel generaltxtr)readlines()

elsefilea=str(booksheet by index(0)cell(index0))s=fileareplace(textu)replace()f=open(sr)readlines()Truewswrite(index 0 s)

print index

num nodes=int([xstrip()split() for x in f][0][0])

num matching=int([xstrip()split() for x in f][2][0])

adj temp = [xstrip()split() for x in f][44+num nodes]adj=[map(intR) for R in adj temp]

matching temp=[xstrip()split() for x in f][4+num nodes+14+2num nodes+1]matching1=[map(intR) for R in matching temp]

adj dict1=i[ii for iix in enumerate(L) if x] for iL in enumerate(adj)adj dict2=i[ii for iix in enumerate(L) if x] for iL in enumerate(adj)

Appendix A 49

adj dict3=i[ii for iix in enumerate(L) if x] for iL in enumerate(adj)

matching dict1=i[ii for iix in enumerate(L) if x] for iL in enumerate(matching1)matching dict2=i[ii for iix in enumerate(L) if x] for iL in enumerate(matching1)print adj dict2print matching dict2wswrite(index 1 num nodes)wswrite(index 2 num matching)

G = nxGraph()

useless= nxGraph()forced = nxGraph()

Fill Graphfor n in range(0num nodes)

for k in adj dict1[n]Gadd edge(nk)

Gt=Gnumber of edges()wswrite(index 3 Gnumber of nodes())wswrite(index 4 Gnumber of edges())wswrite(index 5 max(Gdegree()values()))

Compute Edmonds classical matching on G for comparison

startB = timeitdefault timer()Classical Matching=nxmax weight matching(G maxcardinality=False)stopB = timeitdefault timer()

Compute Gˆ nad MˆstartC = timeitdefault timer()useless edges(num nodesadj dict1matching dict1uselessadj dict2G)forced edges(Gadj dict2matching dict1num nodesforced)Final Matching=nxmax weight matching(G maxcardinality=False)stopC = timeitdefault timer()

GreedystartG = timeitdefault timer()greedy size=Greedy(num nodesadj dict3matching dict2)stopG = timeitdefault timer()

wswrite(index 6 Gnumber of nodes())wswrite(index 7 Gnumber of edges())wswrite(index 8 uselessnumber of edges())wswrite(index 9 forcednumber of edges())if Gdegree()values()

wswrite(index 10 max(Gdegree()values()))else

50 Application

wswrite(index 10 0)wswrite(index 11 len(Classical Matching)2)wswrite(index 12 len(Final Matching)2+forcednumber of edges())wswrite(index 13 greedy size)wswrite(index 14 stopB minus startBstyle1)wswrite(index 15 stopC minus startCstyle1)wswrite(index 16 stopG minus startGstyle1)wswrite(index 17 (len(Final Matching)2+forcednumber of edges())(num nodes2)style1)wswrite(index 18 Gnumber of nodes()Gtstyle1)wswrite(index 19 Gnumber of edges()Gtstyle1)wswrite(index 20 (len(Final Matching)2+forcednumber of edges())(len(Classical Matching)2)style1)

wbsave(AA Results Random Reyni Large Bipartitexls)

Main function Here we must choose the input form of the dataif name == main

startA = timeitdefault timer()General()stopA = timeitdefault timer()

print nThis program has terminatednnRunning time for 480 files stopAminusstartAprint nnPlease open AA Results Random Reyni Largexls file to see the Results

Appendix A 51

Plotmat

clear allclose allload(RN1Lmat)load(RN1Smat)load(RN2Lmat)load(RN2Smat)load(RN3Lmat)load(RN3Smat)

Plotsh(1)=figure(NameHistogram of Matching size difference between Constraint Algorithm and Greedy AlgorithmNumberTitleoff)

RN1L Greedydiff=RN1L Final matchingminusRN1L Greedy matchingRN2L Greedydiff=RN2L Final matchingminusRN2L Greedy matchingRN3L Greedydiff=RN3L Final matchingminusRN3L Greedy matchingRN1S Greedydiff=RN1S Final matchingminusRN1S Greedy matchingRN2S Greedydiff=RN2S Final matchingminusRN2S Greedy matchingRN3S Greedydiff=RN3S Final matchingminusRN3S Greedy matching

RN1L Finaldiff=RN1L Classical matchingminusRN1L Final matchingRN2L Finaldiff=RN2L Classical matchingminusRN2L Final matchingRN3L Finaldiff=RN3L Classical matchingminusRN3L Final matchingRN1S Finaldiff=RN1S Classical matchingminusRN1S Final matchingRN2S Finaldiff=RN2S Classical matchingminusRN2S Final matchingRN3S Finaldiff=RN3S Classical matchingminusRN3S Final matching

RN1L Classicaldiff=(RN1L Nodes2)minusRN1L Classical matchingRN2L Classicaldiff=(RN2L Nodes2)minusRN2L Classical matchingRN3L Classicaldiff=(RN3L Nodes2)minusRN3L Classical matchingRN1S Classicaldiff=(RN1S Nodes2)minusRN1S Classical matchingRN2S Classicaldiff=(RN2S Nodes2)minusRN2S Classical matchingRN3S Classicaldiff=(RN3S Nodes2)minusRN3S Classical matching

subplot(231)hold onhistf(RN1L Greedydiff0110facecolorbfacealpha9edgealpha1)histf(RN1L Finaldiff0110facecolorrfacealpha5edgealpha1)histf(RN1L Classicaldiff0110facecolorgfacealpha5edgealpha1)legalpha(ConminusGreClasminusConPerfminusClasslocationnortheast)legend boxoffaxis tightxlabel(edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN1L)grid on

subplot(232)hold onhistf(RN2L Greedydiff0110facecolorbfacealpha9edgealpha1)

52 Application

histf(RN2L Finaldiff0110facecolorrfacealpha5edgealpha1)histf(RN2L Classicaldiff0110facecolorgfacealpha5edgealpha1)legalpha(ConminusGreClasminusConPerfminusClasslocationnortheast)legend boxoffaxis tightxlabel(edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN2L)grid on

subplot(233)hold onhistf(RN3L Greedydiff0110facecolorbfacealpha5edgealpha1)histf(RN3L Finaldiff0110facecolorrfacealpha5edgealpha1)histf(RN3L Classicaldiff0110facecolorgfacealpha5edgealpha1)legalpha(ConminusGreClasminusConPerfminusClasslocationnortheast)legend boxoffaxis tightxlabel(edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN3L)grid on

subplot(234)hold onhistf(RN1S Greedydiff0110facecolorbfacealpha5edgealpha1)histf(RN1S Finaldiff0110facecolorrfacealpha5edgealpha1)histf(RN1S Classicaldiff0110facecolorgfacealpha5edgealpha1)legalpha(ConminusGreClasminusConPerfminusClasslocationnortheast)legend boxoffaxis tightxlabel(edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(R1NS)grid on

subplot(235)hold onhistf(RN2S Greedydiff0110facecolorbfacealpha5edgealpha1)histf(RN2S Finaldiff0110facecolorrfacealpha5edgealpha1)histf(RN2S Classicaldiff0110facecolorgfacealpha5edgealpha1)legalpha(ConminusGreClasminusConPerfminusClasslocationnortheast)legend boxoffaxis tightxlabel(edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN2S)grid on

subplot(236)hold onhistf(RN3S Greedydiff0110facecolorbfacealpha5edgealpha1)histf(RN3S Finaldiff0110facecolorrfacealpha5edgealpha1)histf(RN3S Classicaldiff0110facecolorgfacealpha5edgealpha1)

Appendix A 53

legalpha(ConminusGreClasminusConPerfminusClasslocationnortheast)legend boxoffaxis tightgrid ontitle(RN3S)xlabel(edges) xminusaxis labelylabel(instances) yminusaxis labelset(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN1png minusr300)h(2)=figure(NameHistogram of Max Degree of G AND G HatNumberTitleoff)RN1L x=RN1L MaxDegreeGminusRN1L MaxDegreeG HatRN2L x=RN2L MaxDegreeGminusRN2L MaxDegreeG HatRN3L x=RN3L MaxDegreeGminusRN3L MaxDegreeG HatRN1S x=RN1S MaxDegreeGminusRN1S MaxDegreeG HatRN2S x=RN2S MaxDegreeGminusRN2S MaxDegreeG HatRN3S x=RN3S MaxDegreeGminusRN3S MaxDegreeG Hatsubplot(231)hold onhistf(RN1L MaxDegreeG0150facecolorbfacealpha5edgealpha1)histf(RN1L MaxDegreeG Hat0150facecolorrfacealpha5edgealpha1)histf(RN1L x0150facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightxlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN1L)grid on

subplot(232)hold onhistf(RN2L MaxDegreeG010500facecolorbfacealpha5edgealpha1)histf(RN2L MaxDegreeG Hat010500facecolorrfacealpha5edgealpha1)histf(RN2L x010500facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightxlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN2L)grid on

subplot(233)hold onhistf(RN3L MaxDegreeG010300facecolorbfacealpha5edgealpha1)histf(RN3L MaxDegreeG Hat010300facecolorrfacealpha5edgealpha1)histf(RN3L x010300facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightxlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN3L)

54 Application

grid on

subplot(234)hold onhistf(RN1S MaxDegreeG0150facecolorbfacealpha5edgealpha1)histf(RN1S MaxDegreeG Hat0150facecolorrfacealpha5edgealpha1)histf(RN1S x0150facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightxlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(R1NS)grid on

subplot(235)hold onhistf(RN2S MaxDegreeG010500facecolorbfacealpha5edgealpha1)histf(RN2S MaxDegreeG Hat010500facecolorrfacealpha5edgealpha1)histf(RN2S x010500facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightxlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN2S)grid on

subplot(236)hold onhistf(RN3S MaxDegreeG05300facecolorbfacealpha5edgealpha1)histf(RN3S MaxDegreeG Hat05300facecolorrfacealpha5edgealpha1)histf(RN3S x05300facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightgrid ontitle(RN3S)xlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labelset(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN2png minusr300)

h(3)=figure(NameComputation time over edgesNumberTitleoff)

subplot(231)hold onstem(RN1L EdgesGRN1L Time classicalg)stem(RN1L EdgesGRN1L Time algorithmro)stem(RN1L EdgesGRN1L Time greedybx)grid on

Appendix A 55

title(RN1L)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)

subplot(232)hold onstem(RN2L EdgesGRN2L Time classicalg)stem(RN2L EdgesGRN2L Time algorithmro)stem(RN2L EdgesGRN2L Time greedybx)grid ontitle(RN2L)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)

subplot(233)hold onstem(RN3L EdgesGRN3L Time classicalg)stem(RN3L EdgesGRN3L Time algorithmro)stem(RN3L EdgesGRN3L Time greedybx)grid ontitle(RN3L)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)

subplot(234)hold onstem(RN1S EdgesGRN1S Time classicalg)stem(RN1S EdgesGRN1S Time algorithmro)stem(RN1S EdgesGRN1S Time greedybx)grid ontitle(RN1S)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)

subplot(235)hold onstem(RN2S EdgesGRN2S Time classicalg)stem(RN2S EdgesGRN2S Time algorithmro)stem(RN2S EdgesGRN2S Time greedybx)grid ontitle(RN2S)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)

subplot(236)hold onstem(RN3S EdgesGRN3S Time classicalg)stem(RN3S EdgesGRN3S Time algorithmro)stem(RN3S EdgesGRN3S Time greedybx)

56 Application

grid ontitle(RN3S)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)set(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN3png minusr300)

h(4)=figure(NameSorted matching sizeNumberTitleoff)RN1L Sorted matching temp(1)=RN1L Classical matchingRN1L Sorted matching temp(2)=RN1L Final matchingRN1L Sorted matching temp(3)=RN1L Greedy matchingRN1L Sorted matching temp(4)=RN1L Initial matchingRN1L Sorted matching=sortrows(RN1L Sorted matching temp)

RN2L Sorted matching temp(1)=RN2L Classical matchingRN2L Sorted matching temp(2)=RN2L Final matchingRN2L Sorted matching temp(3)=RN2L Greedy matchingRN2L Sorted matching temp(4)=RN2L Initial matchingRN2L Sorted matching=sortrows(RN2L Sorted matching temp)

RN3L Sorted matching temp(1)=RN3L Classical matchingRN3L Sorted matching temp(2)=RN3L Final matchingRN3L Sorted matching temp(3)=RN3L Greedy matchingRN3L Sorted matching temp(4)=RN3L Initial matchingRN3L Sorted matching=sortrows(RN3L Sorted matching temp)

RN1S Sorted matching temp(1)=RN1S Classical matchingRN1S Sorted matching temp(2)=RN1S Final matchingRN1S Sorted matching temp(3)=RN1S Greedy matchingRN1S Sorted matching temp(4)=RN1S Initial matchingRN1S Sorted matching=sortrows(RN1S Sorted matching temp)

RN2S Sorted matching temp(1)=RN2S Classical matchingRN2S Sorted matching temp(2)=RN2S Final matchingRN2S Sorted matching temp(3)=RN2S Greedy matchingRN2S Sorted matching temp(4)=RN2S Initial matchingRN2S Sorted matching=sortrows(RN2S Sorted matching temp)

RN3S Sorted matching temp(1)=RN3S Classical matchingRN3S Sorted matching temp(2)=RN3S Final matchingRN3S Sorted matching temp(3)=RN3S Greedy matchingRN3S Sorted matching temp(4)=RN3S Initial matchingRN3S Sorted matching=sortrows(RN3S Sorted matching temp)

subplot(231)hold onplot(RN1L Sorted matching(1)b)plot(RN1L Sorted matching(2)g)plot(RN1L Sorted matching(3)r)plot(RN1L Sorted matching(4)m)

Appendix A 57

grid ontitle(RN1L)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)

subplot(232)hold onplot(RN2L Sorted matching(1)b)plot(RN2L Sorted matching(2)g)plot(RN2L Sorted matching(3)r)plot(RN2L Sorted matching(4)m)grid ontitle(RN2L)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)

subplot(233)hold onplot(RN3L Sorted matching(1)b)plot(RN3L Sorted matching(2)g)plot(RN3L Sorted matching(3)r)plot(RN3L Sorted matching(4)m)grid ontitle(RN3L)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)

subplot(234)hold onplot(RN1S Sorted matching(1)b)plot(RN1S Sorted matching(2)g)plot(RN1S Sorted matching(3)r)plot(RN1S Sorted matching(4)m)grid ontitle(RN1S)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)

subplot(235)hold onplot(RN2S Sorted matching(1)b)plot(RN2S Sorted matching(2)g)plot(RN2S Sorted matching(3)r)plot(RN2S Sorted matching(4)m)grid ontitle(RN2S)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)

58 Application

subplot(236)hold onplot(RN3S Sorted matching(1)b)plot(RN3S Sorted matching(2)g)plot(RN3S Sorted matching(3)r)plot(RN3S Sorted matching(4)m)grid ontitle(RN3S)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)set(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN4png minusr300)h(5)=figure(NameSorted RatiosNumberTitleoff)RN1L ratio1=RN1L NodesG hatRN1L NodesGRN2L ratio1=RN2L NodesG hatRN2L NodesGRN3L ratio1=RN3L NodesG hatRN3L NodesGRN1S ratio1=RN1S NodesG hatRN1S NodesGRN2S ratio1=RN2S NodesG hatRN2S NodesGRN3S ratio1=RN3S NodesG hatRN3S NodesG

RN1L ratio2=RN1L EdgesG HatRN1L EdgesGRN2L ratio2=RN2L EdgesG HatRN2L EdgesGRN3L ratio2=RN3L EdgesG HatRN3L EdgesGRN1S ratio2=RN1S EdgesG HatRN1S EdgesGRN2S ratio2=RN2S EdgesG HatRN2S EdgesGRN3S ratio2=RN3S EdgesG HatRN3S EdgesG

RN1L ratio3=RN1L MaxDegreeG HatRN1L MaxDegreeGRN2L ratio3=RN2L MaxDegreeG HatRN2L MaxDegreeGRN3L ratio3=RN3L MaxDegreeG HatRN3L MaxDegreeGRN1S ratio3=RN1S MaxDegreeG HatRN1S MaxDegreeGRN2S ratio3=RN2S MaxDegreeG HatRN2S MaxDegreeGRN3S ratio3=RN3S MaxDegreeG HatRN3S MaxDegreeG

RN1L ratio(1)=RN1L ratio1RN1L ratio(2)=RN1L ratio2RN1L ratio(3)=RN1L ratio3

RN2L ratio(1)=RN2L ratio1RN2L ratio(2)=RN2L ratio2RN2L ratio(3)=RN2L ratio3

RN3L ratio(1)=RN3L ratio1RN3L ratio(2)=RN3L ratio2RN3L ratio(3)=RN3L ratio3

RN1S ratio(1)=RN1S ratio1RN1S ratio(2)=RN1S ratio2RN1S ratio(3)=RN1S ratio3

RN2S ratio(1)=RN2S ratio1

Appendix A 59

RN2S ratio(2)=RN2S ratio2RN2S ratio(3)=RN2S ratio3

RN3S ratio(1)=RN3S ratio1RN3S ratio(2)=RN3S ratio2RN3S ratio(3)=RN3S ratio3

RN1L ratio sorted=sortrows(RN1L ratio)RN2L ratio sorted=sortrows(RN2L ratio)RN3L ratio sorted=sortrows(RN3L ratio)RN1S ratio sorted=sortrows(RN1S ratio)RN2S ratio sorted=sortrows(RN2S ratio)RN3S ratio sorted=sortrows(RN3S ratio)

subplot(231)hold onplot(RN1L ratio sorted(1)b)plot(RN1L ratio sorted(2)g)plot(RN1L ratio sorted(3)r)grid ontitle(RN1L)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)

subplot(232)hold onplot(RN2L ratio sorted(1)b)plot(RN2L ratio sorted(2)g)plot(RN2L ratio sorted(3)r)grid ontitle(RN2L)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)

subplot(233)hold onplot(RN3L ratio sorted(1)b)plot(RN3L ratio sorted(2)g)plot(RN3L ratio sorted(3)r)grid ontitle(RN3L)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)

subplot(234)hold onplot(RN1S ratio sorted(1)b)plot(RN1S ratio sorted(2)g)plot(RN1S ratio sorted(3)r)grid on

60 Application

title(RN1S)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)

subplot(235)hold onplot(RN2S ratio sorted(1)b)plot(RN2S ratio sorted(2)g)plot(RN2S ratio sorted(3)r)grid ontitle(RN2S)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)

subplot(236)hold onplot(RN3S ratio sorted(1)b)plot(RN3S ratio sorted(2)g)plot(RN3S ratio sorted(3)r)grid ontitle(RN3S)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)set(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN5png minusr300)

h(6)=figure(NameSorted edges over nodesNumberTitleoff)

RN1L DegreeG1=(RN1L EdgesG)(RN1L NodesG)RN1L DegreeG Hat1=(RN1L EdgesG Hat)(RN1L NodesG hat)

RN1L Degree temp1(1)=RN1L DegreeG1RN1L Degree temp1(2)=RN1L DegreeG Hat1RN1L Degree sorted1=sortrows(RN1L Degree temp1)subplot(231)hold on

plot(RN1L Degree sorted1(1)b)plot(RN1L Degree sorted1(2)g)grid ontitle(RN1L)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)

RN2L DegreeG1=(RN2L EdgesG)(RN2L NodesG)RN2L DegreeG Hat1=(RN2L EdgesG Hat)(RN2L NodesG hat)

RN2L Degree temp1(1)=RN2L DegreeG1

Appendix A 61

RN2L Degree temp1(2)=RN2L DegreeG Hat1RN2L Degree sorted1=sortrows(RN2L Degree temp1)

subplot(232)hold onplot(RN2L Degree sorted1(1)b)plot(RN2L Degree sorted1(2)g)grid ontitle(RN2L)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)

RN3L DegreeG1=(RN3L EdgesG)(RN3L NodesG)RN3L DegreeG Hat1=(RN3L EdgesG Hat)(RN3L NodesG hat)

RN3L Degree temp1(1)=RN3L DegreeG1RN3L Degree temp1(2)=RN3L DegreeG Hat1RN3L Degree sorted1=sortrows(RN3L Degree temp1)

subplot(233)hold onplot(RN3L Degree sorted1(1)b)plot(RN3L Degree sorted1(2)g)grid ontitle(RN3L)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)

RN1S DegreeG1=(RN1S EdgesG)(RN1S NodesG)RN1S DegreeG Hat1=(RN1S EdgesG Hat)(RN1S NodesG hat)

RN1S Degree temp1(1)=RN1S DegreeG1RN1S Degree temp1(2)=RN1S DegreeG Hat1RN1S Degree sorted1=sortrows(RN1S Degree temp1)

subplot(234)hold onplot(RN1S Degree sorted1(1)b)plot(RN1S Degree sorted1(2)g)grid ontitle(RN1S)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)

RN2S DegreeG1=(RN2S EdgesG)(RN2S NodesG)RN2S DegreeG Hat1=(RN2S EdgesG Hat)(RN2S NodesG hat)

RN2S Degree temp1(1)=RN2S DegreeG1

62 Application

RN2S Degree temp1(2)=RN2S DegreeG Hat1RN2S Degree sorted1=sortrows(RN2S Degree temp1)

subplot(235)hold onplot(RN2S Degree sorted1(1)b)plot(RN2S Degree sorted1(2)g)grid ontitle(RN2S)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)

RN3S DegreeG1=(RN3S EdgesG)(RN3S NodesG)RN3S DegreeG Hat1=(RN3S EdgesG Hat)(RN3S NodesG hat)

RN3S Degree temp1(1)=RN3S DegreeG1RN3S Degree temp1(2)=RN3S DegreeG Hat1RN3S Degree sorted1=sortrows(RN3S Degree temp1)

subplot(236)hold onplot(RN3S Degree sorted1(1)b)plot(RN3S Degree sorted1(2)g)grid ontitle(RN3S)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)set(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN6png minusr300)h(7)=figure(NameSorted mATCHED DEGREENumberTitleoff)RN1L ratioMax(1)=RN1L MaxDegreeGRN1L ratioMax(2)=RN1L MaxDegreeG Hat

RN1L ratio sortedMax=sortrows(RN1L ratioMax)subplot(231)hold onplot(RN1L ratio sortedMax(1)b)plot(RN1L ratio sortedMax(2)g)grid ontitle(RN1L)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)

RN2L ratioMax(1)=RN2L MaxDegreeGRN2L ratioMax(2)=RN2L MaxDegreeG Hat

RN2L ratio sortedMax=sortrows(RN2L ratioMax)subplot(232)

Appendix A 63

hold onplot(RN2L ratio sortedMax(1)b)plot(RN2L ratio sortedMax(2)g)grid ontitle(RN2L)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)

RN3L ratioMax(1)=RN3L MaxDegreeGRN3L ratioMax(2)=RN3L MaxDegreeG Hat

RN3L ratio sortedMax=sortrows(RN3L ratioMax)subplot(233)hold onplot(RN3L ratio sortedMax(1)b)plot(RN3L ratio sortedMax(2)g)grid ontitle(RN3L)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)

RN1S ratioMax(1)=RN1S MaxDegreeGRN1S ratioMax(2)=RN1S MaxDegreeG Hat

RN1S ratio sortedMax=sortrows(RN1S ratioMax)subplot(234)hold onplot(RN1S ratio sortedMax(1)b)plot(RN1S ratio sortedMax(2)g)grid ontitle(RN1S)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)

RN2S ratioMax(1)=RN2S MaxDegreeGRN2S ratioMax(2)=RN2S MaxDegreeG Hat

RN2S ratio sortedMax=sortrows(RN2S ratioMax)

subplot(235)hold onplot(RN2S ratio sortedMax(1)b)plot(RN2S ratio sortedMax(2)g)grid ontitle(RN2S)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)

RN3S ratioMax(1)=RN3S MaxDegreeGRN3S ratioMax(2)=RN3S MaxDegreeG Hat

64 Application

RN3S ratio sortedMax=sortrows(RN3S ratioMax)subplot(236)hold onplot(RN3S ratio sortedMax(1)b)plot(RN3S ratio sortedMax(2)g)grid ontitle(RN1L)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)set(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN7png minusr300)

tilefigs()(h)

Bibliography

[1] C Berge ldquoTWO THEOREMS IN GRAPH THEORYrdquo Proceedings of the NationalAcademy of Sciences of the United States of America vol 43 no 9 pp 842ndash844Sep 1957

[2] L Bui S Sanghavi and R Srikant ldquoDistributed link scheduling with constantoverheadrdquo IEEEACM Trans Netw vol 17 no 5 pp 1467ndash1480 2009

[3] R Duan and S Pettie ldquoLinear-time approximation for maximum weight matchingrdquoJ ACM vol 61 no 1 2014

[4] J Edmonds ldquoPaths trees and flowersrdquo Canadian Journal of Mathematics vol 17pp 449ndash467 1965

[5] J E Hopcroft and R M Karp ldquoAn n52 algorithm for maximum matchings inbipartite graphsrdquo SIAM J Comput vol 2 no 4 pp 225ndash231 1973

[6] S Micali and V V Vazirani ldquoAn O(radic|V ||E|) algorithm for finding maximum

matching in general graphsrdquo in 21st Symp on Foundations of Comp Sc (FOCS)IEEE 1980 pp 17ndash27

[7] N Nisse A Salch and V Weber ldquoRecovery of disrupted airline operationsrdquo 2015httphalinriafrSomething

[8] X Wu and R Srikant ldquoRegulated maximal matching A distributed schedulingalgorithm for multi-hop wireless networks with nodeexclusive spectrum sharingrdquo inIEEE Conf on Decision and Control 2005

65

  • Contents
  • Introduction
  • Algorithms
    • Maximum matching
    • k-maximum matching
      • k-matching for Airport Slot assignment
      • The case where k=3
      • The case of Paths
      • The case of the Spider
          • Application
            • Description
            • Reyni Erdos
            • Barabaacutesi Albert
            • Amadeus Graphs
            • Bipartite
            • Bipartite with degree seq
            • Appendix A
              • BipartiteGraphGeneratorpy
              • RandomGraphGeneratorpy
              • kequals3MaximumMatchingpy
              • Plotmat
                  • Bibliography
Page 21: Theodoros Alexandros KARAGKIOULES -  · Introduction This work is the result of a 6 months internship, under the supervision of research O cer Nicolas NISSE. The original scope of

22 Application

Sorted ∆-Comments

bull In this set of figures the ascending order of the ∆ of G is associated with the ∆of G

bull There is a significant jump of the ∆ for each graph category which tells that thatwe are not comparing a uniform distribution of random graphs and based on theedge attraction m the graphs can vary in form

bull For larger initial matching we observe the difference in the ∆s of G and G giventhe removed forced edges( and their endpoints) At some cases the ∆ of G dropsto 0 since the vast majority of edges have been declared forced and removed alongwith their endpoints What is interesting is that the ∆ of G oscilates within stablelimits

24 Amadeus Graphs 23

bull For smaller initial matching the ∆s of G and G follow mostly the same trend onlya few number of different instances

24 Amadeus Graphs

Graph characteristics Amadeus graphs

bull These are the bipartite graphs provided by Amadeus

Computation time over |E|

Computation time over |E| - Comments

24 Application

bull For every instance the computation time of the classical algorithm is always smallerto that of the constraint matching

bull This allows as to speculate that we always compute a smaller G which also impliesthat we always find a set of forced edges and useless

Sorted matching size

Sorted matching size - Comments

bull Size of matching has an upward trend since the magnitude of the graphs is notthe same for the 160 instances

bull No significant deviation is noticed as per the first graph

24 Amadeus Graphs 25

bull Except from deviation from the perfect matching (number of flights) where some-times it could get up to 40

bull For the Amadeus Bipartite graphs we can see that the difference of the Classicaland the constraint implementation is not more than 1 edge in the matching

bull There appears to be a difference of up to 24 edges between the Classical matchingand the Perfect matching which is computed as the number of flights

bull The greedy algorithm performs well with only a few instances deviating slightlyform the Constraint algorithm result

Sorted Ratios

Sorted Ratios - Comments

26 Application

bull

Sorted |E||V |

Sorted |E||V | - Comments

bull Density of the graphs shows that on average we have 25-3 available time slot perflight

bull The line for the same value for G shows that there is a large deviation for everyinstance which allows for the hypothesis that the amount of useless+forced edgesof G has no obvious correlation to that of G

25 Bipartite 27

Sorted ∆

Sorted ∆-Comments

bull As per the previous related graphs for ∆ there is in significant drop in the ∆ of Gand G

25 Bipartite

Graph characteristics Bipartite random Graphs

bull BIPxy are randomly generated graphs with a fixed number of 1000(n=500 andm=500) nodes

bull There are 6 categories based on ini matching and probability p

28 Application

bull Probability p has been chosen as such in order to simulate the |E||V | 25 of theAmadeus bipartite graphs

bull So in order to have about 2-4 edges for every node we choose accordingly theprobability p to choose one of the n lowastm possible edges

bull x = L S L When the initial matching is large and S when it is small

bull y = 1 2 3 1 when p = 18250

2 when p = 25250

and 3 when p = 34250

Computation time over

Computation time overedges-Comments

bull

25 Bipartite 29

Sorted matching size

Sorted matching size-Comments

bull In these set of graphs one can instantly notice that only a few instances with highprobability can reach a matching size equal to the perfect matching

bull For the case of the initial matching we witness that there is a gap between the lineof the classical matching and those of the constraint and greedy results suggestingsmaller matching sizes of 10-40 edges

bull For the case of the small initial matching the result of the constraint matchingis now close to the result of the classical matching yet the greedy algorithm stillshows a relevantly big difference

30 Application

bull In this set of bipartite graphs we can witness that the result of the Constraintmatching shows a difference with the classical matching when the initial matchingis large The difference is smaller as the probability gets larger

bull For the case of the small initial matching the above phenomenom does not occuryet the greedy results deviates from that of the constraint matching

bull As per the pefrect matching compared to the classical matching a difference of5-10 edges is evident at almost all cases

Sorted Ratios

Sorted Ratios-Comments

bull Great max degree deviation

25 Bipartite 31

bull Regardless of the probability the ration of nodes and edges seems to have similarbehaviour when compared to the respective graphs of the same matching scale

bull Same gap between nodes ration and edges ration for all cases

Sorted |E||V |

Sorted |E||V | - Comments

bull In these set of figures we witness that the |E||V | acquires values relevant to those ofthe amadeus graphs The random graphs were constructed to depict this similarity

bull For smaller initial matching the ratios for G and G show the same upward trendand also they acquire closer values It represents the decrease of the averagenumber of forced edges in comparison to the larger matching cases

32 Application

Sorted ∆

Sorted ∆-Comments

bull ∆ acquires the same min and max values for each probability case (expected)

bull Gap in the case of large initial matching

26 Bipartite with degree seq

Graph characteristics

bull DEQBIPxy are randomly generated graphs based on three different types of degreedistribution of the Amadeus graphs

26 Bipartite with degree seq 33

bull There are 6 categories based on ini matching and degree distribution

bull x = L S L When the initial matching is large and S when it is small

bull y = 1 2 3 1 when degree distribution is based on file 2 when degree distributionis based on file and 3 when degree distribution is based on file

Computation time over

34 Application

Computation time overedges-Comments

bull Greedy algorithm takes minimum amount of time

bull The smaller the initial matching the more smaller the difference in comoutationtime of Constraint and classical algorithm

bull Due to preprocessing and the fact that G and G are the almost identical thetotal time needed to apply the constraint algorithm is in some cases bigger

Sorted matching size

26 Bipartite with degree seq 35

Sorted matching size-Comments

bull Classical matching is equal to perfect matching in every case

bull Constraint and greedy have identical behaviour

bull The larger the spectrum of the degree sequence the more efficient the matching

Sorted Ratios

36 Application

Sorted Ratios-Comments

bull With large initial matching most of the edges are considenred uselles or forced andare removed thus the ratio is close(if not equal to) zero

bull For small matching and large degree sequence sectrum hte max degree remainsthe same Only a few forced edges (and their nodes) are removed apparently nonodes with max degree

Sorted |E||V |

26 Bipartite with degree seq 37

Sorted |E||V | - Comments

bull In these set of figures we witness that the |E||V | acquires values relevant to those ofthe amadeus graphs The random graphs were constructed to depict this similarity

bull For smaller initial matching the ratios for G and G show the same upward trendand also they acquire closer values It repsresent the decrease of the averagenumber of forced edges in comparison to the larger matching cases

Sorted ∆

38 Application

Sorted ∆-Comments

bull Big difference in max degree in large initial matching

bull Almost identical behaviour in the case of small initial matching

Appendix A 39

Appendix A

BipartiteGraphGeneratorpy

from future import divisionimport networkx as nx

from networkxalgorithms import approximationimport collectionsimport randomimport mathfrom networkxalgorithms import bipartiteif name == main

for i in range(1481)waqs 481index=1n=randomrandint(100 1000)

n1=95 was 500me1=118

n2=251 was 500me2=903

n3=165 was 500me3=412

m=0m1=0p=randomrandom()p1=18250p2=25250p3=34250print ip=05t1=randomrandint(0 1)print im2=randomrandint(n2minus1 n2+1)G = nxGraph()ma = nxGraph()

aseq1=[1 2 3 4 5 3]

bseq1=[4 3 3 1 2 2 1]

aseq2=[16 14 14 14 12 11]bseq2=[0 0 0 0 0 0]

aseq3=[8 7 8 8 8 8]bseq3=[0 0 0 0 0 0]

40 Application

print Gnumber of edges()if ilt=160

G=bipartiteconfiguration model(aseq1 bseq1 create using=None seed=None)A=nxadjacency matrix(G)for ii in range(0n1+me1)

maadd node(ii)A=[Rtodense()tolist()[0] for R in A]

printnummanumber of nodes()rl=randomsample(range(0n1+me1) n1+me1)m=0done vertices = set()for p in rlprintin fordone verticesadd(p)

neighbors = []list()for iii in range(0n1+me1)

if A[p][iii]==1neighborsappend(iii)

randomshuffle(neighbors)continue loop = Truedegree = len(neighbors)

print degreej = 0p4=randomrandom()while continue loop and (jltdegree)print in loop

next = neighbors[j]if next not in done vertices and p not in done vertices

done verticesadd(p)done verticesadd(next)if p4gt=07print added edge

maadd edge(pnext)m=m+1

continue loop = Falsej += 1

print matching listOfedgeprint maedge

MA=nxadjacency matrix(ma)print MA

MA=[Rtodense()tolist()[0] for R in MA]print MA

B=[ join(map(strR)) for R in A]MB=[ join(map(strR)) for R in MA]

C=njoin(B)+nMC=njoin(MB)+n

print nprint mprint m1

filea=str(i)+txtwith open(fileaw) as f

Appendix A 41

fwrite(str(n1+me1))fwrite(n)fwrite(str(n1+me1))fwrite(n)fwrite(str(m))fwrite(n)fwrite(n)fwrite(C)fwrite(n)fwrite(MC)

elif igt160 and ilt321G=bipartiteconfiguration model(aseq2 bseq2 create using=None seed=None)A=nxadjacency matrix(G)for ii in range(0n2+me2)

maadd node(ii)A=[Rtodense()tolist()[0] for R in A]

printnummanumber of nodes()rl=randomsample(range(0n2+me2) n2+me2)m=0done vertices = set()for p in rlprintin fordone verticesadd(p)

neighbors = []list()for iii in range(0n2+me2)

if A[p][iii]==1neighborsappend(iii)

randomshuffle(neighbors)continue loop = Truedegree = len(neighbors)

print degreej = 0p4=randomrandom()while continue loop and (jltdegree)

print in loopnext = neighbors[j]if next not in done vertices and p not in done vertices

done verticesadd(p)done verticesadd(next)if p4gt=07

print added edgemaadd edge(pnext)m=m+1

continue loop = Falsej += 1

print matching listOfedgeprint maedge

MA=nxadjacency matrix(ma)print MA

MA=[Rtodense()tolist()[0] for R in MA]print MA

B=[ join(map(strR)) for R in A]MB=[ join(map(strR)) for R in MA]

42 Application

C=njoin(B)+nMC=njoin(MB)+n

print nprint mprint m1

filea=str(i)+txtwith open(fileaw) as f

fwrite(str(n2+me2))fwrite(n)fwrite(str(n2+me2))fwrite(n)fwrite(str(m))fwrite(n)fwrite(n)fwrite(C)fwrite(n)fwrite(MC)

elseG=bipartiteconfiguration model(aseq3 bseq3 create using=None seed=None)A=nxadjacency matrix(G)for ii in range(0n3+me3)

maadd node(ii)A=[Rtodense()tolist()[0] for R in A]

printnummanumber of nodes()rl=randomsample(range(0n3+me3) n3+me3)m=0done vertices = set()for p in rlprintin fordone verticesadd(p)

neighbors = []list()for iii in range(0n3+me3)

if A[p][iii]==1neighborsappend(iii)

randomshuffle(neighbors)continue loop = Truedegree = len(neighbors)

print degreej = 0p4=randomrandom()while continue loop and (jltdegree)

print in loopnext = neighbors[j]if next not in done vertices and p not in done vertices

done verticesadd(p)done verticesadd(next)if p4gt=07print added edge

maadd edge(pnext)m=m+1

continue loop = Falsej += 1

Appendix A 43

print matching listOfedgeprint maedge

MA=nxadjacency matrix(ma)print MA

MA=[Rtodense()tolist()[0] for R in MA]print MA

B=[ join(map(strR)) for R in A]MB=[ join(map(strR)) for R in MA]

C=njoin(B)+nMC=njoin(MB)+n

print nprint mprint m1

filea=str(i)+txtwith open(fileaw) as f

fwrite(str(n3+me3))fwrite(n)fwrite(str(n3+me3))fwrite(n)fwrite(str(m))fwrite(n)fwrite(n)fwrite(C)fwrite(n)fwrite(MC)

print nRandom graphs with random matching have been generated

44 Application

RandomGraphGeneratorpy

from future import divisionimport networkx as nxfrom networkxalgorithms import approximationimport collectionsimport randomimport mathif name == main

for i in range(1481)index=1n=randomrandint(100 1000)

n=1000m=0m1=0p=randomrandom()p1=mathlog(n2)np2=13p3=mathlog(n2)n+01p=05t1=randomrandint(0 1)print im2=randomrandint(n2minus1 n2+1)G = nxGraph()ma = nxGraph()print nme1=randomrandint(1 10)me2=randomrandint(2050)me3=randomrandint(50100)if ilt241

if ilt=80G=nxfast gnp random graph(n p1 seed=None directed=False)

elif igt80 and ilt161G=nxfast gnp random graph(n p2 seed=None directed=False)

elseG=nxfast gnp random graph(n p3 seed=None directed=False)

elseif ilt=320

G=nxbarabasi albert graph(n me1 seed=None)elif igt320 and ilt401

G=nxbarabasi albert graph(n me2 seed=None)else

G=nxbarabasi albert graph(n me3 seed=None)A=nxadjacency matrix(G)for ii in range(0n)

maadd node(ii)A=[Rtodense()tolist()[0] for R in A]

rl=randomsample(range(0n) n)m=0

Appendix A 45

done vertices = set()for p in rl

done verticesadd(p)neighbors = []list()for iii in range(0n)

if A[p][iii]==1neighborsappend(iii)

randomshuffle(neighbors)continue loop = Truedegree = len(neighbors)j = 0p2=randomrandom()while continue loop and (jltdegree)

next = neighbors[j]if next not in done vertices and p not in done vertices

done verticesadd(p)done verticesadd(next)if p2gt=00 Larger probability for smaller initial matching

maadd edge(pnext)m=m+1

continue loop = Falsej += 1

print matching listOfedgeprint maedgeMA=nxadjacency matrix(ma)MA=[Rtodense()tolist()[0] for R in MA]print MAB=[ join(map(strR)) for R in A]MB=[ join(map(strR)) for R in MA]

C=njoin(B)+nMC=njoin(MB)+nprint MCprint nprint mprint m1filea=str(i)+txtwith open(fileaw) as f

fwrite(str(n))fwrite(n)fwrite(str(n))fwrite(n)fwrite(str(m))fwrite(n)fwrite(n)fwrite(C)fwrite(n)fwrite(MC)

print nRandom graphs with random matching have been generated

46 Application

kequals3MaximumMatchingpy

from future import divisionimport networkx as nxfrom networkxalgorithms import bipartiteimport matplotlibpyplot as pltimport collectionsimport timeitimport xlwtimport xlrdimport mathimport sys

Case for General Graphsdef forced edges(Gadj dict2matching dict1num nodesforced)

flagg=0for n in range(0num nodes)

for k in adj dict2[n]if ([k]==matching dict1[n])

count=0for l in range(0num nodes)

count=count+adj dict2[l]count(k)if (len(adj dict2[n])==1) or (count==1)

forcedadd edge(nk)Gremove edge(nk)Gremove node(n)Gremove node(k)printforced edgenktemp=kflagg=1for m in range (len(adj dict2[n])minus1minus1minus1)

adj dict2[adj dict2[n][m]]remove(n)adj dict2[n]remove(adj dict2[n][m])

if adj dict2[temp]for l in range(len(adj dict2[temp])minus1minus1minus1)

if (adj dict2[temp][l]=n)adj dict2[adj dict2[temp][l]]remove(temp)adj dict2[temp]remove(adj dict2[temp][l])

break

def useless edges(num nodesadj dict1matching dict1uselessadj dict2G)for n in range(0num nodes)

for k in adj dict1[n]if ([k]=matching dict1[n]) and matching dict1[n] and matching dict1[k]

uselessadd edge(nk)Gremove edge(n k)

Appendix A 47

tempa=kadj dict2[n]remove(k)adj dict2[tempa]remove(n)adj dict1[tempa]remove(n)

return G

def Greedy(num nodesadj dict3matching dict2)

for n in range(0num nodes)if matching dict2[n]

flag2=minus1flag3=minus1for v in adj dict3[n]

if not matching dict2[v]flag2=vbreak

for p in adj dict3[matching dict2[n][0]]if not matching dict2[p]

flag3=pbreak

if (flag2=minus1) and (flag3=minus1) and (flag2=flag3)tempr=matching dict2[n][0]matching dict2[n]=[flag2]matching dict2[flag2]=[n]matching dict2[tempr]=[flag3]matching dict2[flag3]=[tempr]

elsefor k in adj dict3[n]

if not matching dict2[k]matching dict2[n]=[k]matching dict2[k]=[n]break

yo1=0for i in range(0num nodes)

if matching dict2[i] and [i]==matching dict2[matching dict2[i][0]]yo1=yo1+1

greedy size=yo12return greedy size

def General()

INPUTSwb = xlwtWorkbook()ws = wbadd sheet(Results Random)book=xlrdopen workbook(filenames randomxls)

48 Application

style0 = xlwteasyxf(fontbold on)style1 = xlwteasyxf(num format str=0000)INPUTSwswrite(0 0File style0)wswrite(0 1 Nodesstyle0)wswrite(0 2 Initial matchingstyle0)wswrite(0 3 NodesGstyle0)wswrite(0 4 EdgesGstyle0)wswrite(0 5 MaxDegreeGstyle0)wswrite(0 6 NodesG hatstyle0)wswrite(0 7 EdgesG Hatstyle0)wswrite(0 8 Useless edgesstyle0)wswrite(0 9 Forced edgesstyle0)wswrite(0 10 MaxDegreeG Hatstyle0)wswrite(0 11 Classical matchingstyle0)wswrite(0 12 Final matchingstyle0)wswrite(0 13 Greedy matchingstyle0)wswrite(0 14 Time classicalstyle0)wswrite(0 15 Time algorithmstyle0)wswrite(0 16 Time greedystyle0)wswrite(0 17 Perfect matching ratiostyle0)wswrite(0 18 Nodes ratiostyle0)wswrite(0 19 Edges ratiostyle0)wswrite(0 20 Matching ratiostyle0)

print nWelcomeThis is an implementation for general random graphs It uses Edmonds algorithm to compute maximum matching on G Hatn

for index in range (1481)was 481

if (index==482)f=open(Algotel generaltxtr)readlines()

elsefilea=str(booksheet by index(0)cell(index0))s=fileareplace(textu)replace()f=open(sr)readlines()Truewswrite(index 0 s)

print index

num nodes=int([xstrip()split() for x in f][0][0])

num matching=int([xstrip()split() for x in f][2][0])

adj temp = [xstrip()split() for x in f][44+num nodes]adj=[map(intR) for R in adj temp]

matching temp=[xstrip()split() for x in f][4+num nodes+14+2num nodes+1]matching1=[map(intR) for R in matching temp]

adj dict1=i[ii for iix in enumerate(L) if x] for iL in enumerate(adj)adj dict2=i[ii for iix in enumerate(L) if x] for iL in enumerate(adj)

Appendix A 49

adj dict3=i[ii for iix in enumerate(L) if x] for iL in enumerate(adj)

matching dict1=i[ii for iix in enumerate(L) if x] for iL in enumerate(matching1)matching dict2=i[ii for iix in enumerate(L) if x] for iL in enumerate(matching1)print adj dict2print matching dict2wswrite(index 1 num nodes)wswrite(index 2 num matching)

G = nxGraph()

useless= nxGraph()forced = nxGraph()

Fill Graphfor n in range(0num nodes)

for k in adj dict1[n]Gadd edge(nk)

Gt=Gnumber of edges()wswrite(index 3 Gnumber of nodes())wswrite(index 4 Gnumber of edges())wswrite(index 5 max(Gdegree()values()))

Compute Edmonds classical matching on G for comparison

startB = timeitdefault timer()Classical Matching=nxmax weight matching(G maxcardinality=False)stopB = timeitdefault timer()

Compute Gˆ nad MˆstartC = timeitdefault timer()useless edges(num nodesadj dict1matching dict1uselessadj dict2G)forced edges(Gadj dict2matching dict1num nodesforced)Final Matching=nxmax weight matching(G maxcardinality=False)stopC = timeitdefault timer()

GreedystartG = timeitdefault timer()greedy size=Greedy(num nodesadj dict3matching dict2)stopG = timeitdefault timer()

wswrite(index 6 Gnumber of nodes())wswrite(index 7 Gnumber of edges())wswrite(index 8 uselessnumber of edges())wswrite(index 9 forcednumber of edges())if Gdegree()values()

wswrite(index 10 max(Gdegree()values()))else

50 Application

wswrite(index 10 0)wswrite(index 11 len(Classical Matching)2)wswrite(index 12 len(Final Matching)2+forcednumber of edges())wswrite(index 13 greedy size)wswrite(index 14 stopB minus startBstyle1)wswrite(index 15 stopC minus startCstyle1)wswrite(index 16 stopG minus startGstyle1)wswrite(index 17 (len(Final Matching)2+forcednumber of edges())(num nodes2)style1)wswrite(index 18 Gnumber of nodes()Gtstyle1)wswrite(index 19 Gnumber of edges()Gtstyle1)wswrite(index 20 (len(Final Matching)2+forcednumber of edges())(len(Classical Matching)2)style1)

wbsave(AA Results Random Reyni Large Bipartitexls)

Main function Here we must choose the input form of the dataif name == main

startA = timeitdefault timer()General()stopA = timeitdefault timer()

print nThis program has terminatednnRunning time for 480 files stopAminusstartAprint nnPlease open AA Results Random Reyni Largexls file to see the Results

Appendix A 51

Plotmat

clear allclose allload(RN1Lmat)load(RN1Smat)load(RN2Lmat)load(RN2Smat)load(RN3Lmat)load(RN3Smat)

Plotsh(1)=figure(NameHistogram of Matching size difference between Constraint Algorithm and Greedy AlgorithmNumberTitleoff)

RN1L Greedydiff=RN1L Final matchingminusRN1L Greedy matchingRN2L Greedydiff=RN2L Final matchingminusRN2L Greedy matchingRN3L Greedydiff=RN3L Final matchingminusRN3L Greedy matchingRN1S Greedydiff=RN1S Final matchingminusRN1S Greedy matchingRN2S Greedydiff=RN2S Final matchingminusRN2S Greedy matchingRN3S Greedydiff=RN3S Final matchingminusRN3S Greedy matching

RN1L Finaldiff=RN1L Classical matchingminusRN1L Final matchingRN2L Finaldiff=RN2L Classical matchingminusRN2L Final matchingRN3L Finaldiff=RN3L Classical matchingminusRN3L Final matchingRN1S Finaldiff=RN1S Classical matchingminusRN1S Final matchingRN2S Finaldiff=RN2S Classical matchingminusRN2S Final matchingRN3S Finaldiff=RN3S Classical matchingminusRN3S Final matching

RN1L Classicaldiff=(RN1L Nodes2)minusRN1L Classical matchingRN2L Classicaldiff=(RN2L Nodes2)minusRN2L Classical matchingRN3L Classicaldiff=(RN3L Nodes2)minusRN3L Classical matchingRN1S Classicaldiff=(RN1S Nodes2)minusRN1S Classical matchingRN2S Classicaldiff=(RN2S Nodes2)minusRN2S Classical matchingRN3S Classicaldiff=(RN3S Nodes2)minusRN3S Classical matching

subplot(231)hold onhistf(RN1L Greedydiff0110facecolorbfacealpha9edgealpha1)histf(RN1L Finaldiff0110facecolorrfacealpha5edgealpha1)histf(RN1L Classicaldiff0110facecolorgfacealpha5edgealpha1)legalpha(ConminusGreClasminusConPerfminusClasslocationnortheast)legend boxoffaxis tightxlabel(edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN1L)grid on

subplot(232)hold onhistf(RN2L Greedydiff0110facecolorbfacealpha9edgealpha1)

52 Application

histf(RN2L Finaldiff0110facecolorrfacealpha5edgealpha1)histf(RN2L Classicaldiff0110facecolorgfacealpha5edgealpha1)legalpha(ConminusGreClasminusConPerfminusClasslocationnortheast)legend boxoffaxis tightxlabel(edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN2L)grid on

subplot(233)hold onhistf(RN3L Greedydiff0110facecolorbfacealpha5edgealpha1)histf(RN3L Finaldiff0110facecolorrfacealpha5edgealpha1)histf(RN3L Classicaldiff0110facecolorgfacealpha5edgealpha1)legalpha(ConminusGreClasminusConPerfminusClasslocationnortheast)legend boxoffaxis tightxlabel(edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN3L)grid on

subplot(234)hold onhistf(RN1S Greedydiff0110facecolorbfacealpha5edgealpha1)histf(RN1S Finaldiff0110facecolorrfacealpha5edgealpha1)histf(RN1S Classicaldiff0110facecolorgfacealpha5edgealpha1)legalpha(ConminusGreClasminusConPerfminusClasslocationnortheast)legend boxoffaxis tightxlabel(edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(R1NS)grid on

subplot(235)hold onhistf(RN2S Greedydiff0110facecolorbfacealpha5edgealpha1)histf(RN2S Finaldiff0110facecolorrfacealpha5edgealpha1)histf(RN2S Classicaldiff0110facecolorgfacealpha5edgealpha1)legalpha(ConminusGreClasminusConPerfminusClasslocationnortheast)legend boxoffaxis tightxlabel(edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN2S)grid on

subplot(236)hold onhistf(RN3S Greedydiff0110facecolorbfacealpha5edgealpha1)histf(RN3S Finaldiff0110facecolorrfacealpha5edgealpha1)histf(RN3S Classicaldiff0110facecolorgfacealpha5edgealpha1)

Appendix A 53

legalpha(ConminusGreClasminusConPerfminusClasslocationnortheast)legend boxoffaxis tightgrid ontitle(RN3S)xlabel(edges) xminusaxis labelylabel(instances) yminusaxis labelset(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN1png minusr300)h(2)=figure(NameHistogram of Max Degree of G AND G HatNumberTitleoff)RN1L x=RN1L MaxDegreeGminusRN1L MaxDegreeG HatRN2L x=RN2L MaxDegreeGminusRN2L MaxDegreeG HatRN3L x=RN3L MaxDegreeGminusRN3L MaxDegreeG HatRN1S x=RN1S MaxDegreeGminusRN1S MaxDegreeG HatRN2S x=RN2S MaxDegreeGminusRN2S MaxDegreeG HatRN3S x=RN3S MaxDegreeGminusRN3S MaxDegreeG Hatsubplot(231)hold onhistf(RN1L MaxDegreeG0150facecolorbfacealpha5edgealpha1)histf(RN1L MaxDegreeG Hat0150facecolorrfacealpha5edgealpha1)histf(RN1L x0150facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightxlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN1L)grid on

subplot(232)hold onhistf(RN2L MaxDegreeG010500facecolorbfacealpha5edgealpha1)histf(RN2L MaxDegreeG Hat010500facecolorrfacealpha5edgealpha1)histf(RN2L x010500facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightxlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN2L)grid on

subplot(233)hold onhistf(RN3L MaxDegreeG010300facecolorbfacealpha5edgealpha1)histf(RN3L MaxDegreeG Hat010300facecolorrfacealpha5edgealpha1)histf(RN3L x010300facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightxlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN3L)

54 Application

grid on

subplot(234)hold onhistf(RN1S MaxDegreeG0150facecolorbfacealpha5edgealpha1)histf(RN1S MaxDegreeG Hat0150facecolorrfacealpha5edgealpha1)histf(RN1S x0150facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightxlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(R1NS)grid on

subplot(235)hold onhistf(RN2S MaxDegreeG010500facecolorbfacealpha5edgealpha1)histf(RN2S MaxDegreeG Hat010500facecolorrfacealpha5edgealpha1)histf(RN2S x010500facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightxlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN2S)grid on

subplot(236)hold onhistf(RN3S MaxDegreeG05300facecolorbfacealpha5edgealpha1)histf(RN3S MaxDegreeG Hat05300facecolorrfacealpha5edgealpha1)histf(RN3S x05300facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightgrid ontitle(RN3S)xlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labelset(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN2png minusr300)

h(3)=figure(NameComputation time over edgesNumberTitleoff)

subplot(231)hold onstem(RN1L EdgesGRN1L Time classicalg)stem(RN1L EdgesGRN1L Time algorithmro)stem(RN1L EdgesGRN1L Time greedybx)grid on

Appendix A 55

title(RN1L)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)

subplot(232)hold onstem(RN2L EdgesGRN2L Time classicalg)stem(RN2L EdgesGRN2L Time algorithmro)stem(RN2L EdgesGRN2L Time greedybx)grid ontitle(RN2L)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)

subplot(233)hold onstem(RN3L EdgesGRN3L Time classicalg)stem(RN3L EdgesGRN3L Time algorithmro)stem(RN3L EdgesGRN3L Time greedybx)grid ontitle(RN3L)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)

subplot(234)hold onstem(RN1S EdgesGRN1S Time classicalg)stem(RN1S EdgesGRN1S Time algorithmro)stem(RN1S EdgesGRN1S Time greedybx)grid ontitle(RN1S)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)

subplot(235)hold onstem(RN2S EdgesGRN2S Time classicalg)stem(RN2S EdgesGRN2S Time algorithmro)stem(RN2S EdgesGRN2S Time greedybx)grid ontitle(RN2S)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)

subplot(236)hold onstem(RN3S EdgesGRN3S Time classicalg)stem(RN3S EdgesGRN3S Time algorithmro)stem(RN3S EdgesGRN3S Time greedybx)

56 Application

grid ontitle(RN3S)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)set(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN3png minusr300)

h(4)=figure(NameSorted matching sizeNumberTitleoff)RN1L Sorted matching temp(1)=RN1L Classical matchingRN1L Sorted matching temp(2)=RN1L Final matchingRN1L Sorted matching temp(3)=RN1L Greedy matchingRN1L Sorted matching temp(4)=RN1L Initial matchingRN1L Sorted matching=sortrows(RN1L Sorted matching temp)

RN2L Sorted matching temp(1)=RN2L Classical matchingRN2L Sorted matching temp(2)=RN2L Final matchingRN2L Sorted matching temp(3)=RN2L Greedy matchingRN2L Sorted matching temp(4)=RN2L Initial matchingRN2L Sorted matching=sortrows(RN2L Sorted matching temp)

RN3L Sorted matching temp(1)=RN3L Classical matchingRN3L Sorted matching temp(2)=RN3L Final matchingRN3L Sorted matching temp(3)=RN3L Greedy matchingRN3L Sorted matching temp(4)=RN3L Initial matchingRN3L Sorted matching=sortrows(RN3L Sorted matching temp)

RN1S Sorted matching temp(1)=RN1S Classical matchingRN1S Sorted matching temp(2)=RN1S Final matchingRN1S Sorted matching temp(3)=RN1S Greedy matchingRN1S Sorted matching temp(4)=RN1S Initial matchingRN1S Sorted matching=sortrows(RN1S Sorted matching temp)

RN2S Sorted matching temp(1)=RN2S Classical matchingRN2S Sorted matching temp(2)=RN2S Final matchingRN2S Sorted matching temp(3)=RN2S Greedy matchingRN2S Sorted matching temp(4)=RN2S Initial matchingRN2S Sorted matching=sortrows(RN2S Sorted matching temp)

RN3S Sorted matching temp(1)=RN3S Classical matchingRN3S Sorted matching temp(2)=RN3S Final matchingRN3S Sorted matching temp(3)=RN3S Greedy matchingRN3S Sorted matching temp(4)=RN3S Initial matchingRN3S Sorted matching=sortrows(RN3S Sorted matching temp)

subplot(231)hold onplot(RN1L Sorted matching(1)b)plot(RN1L Sorted matching(2)g)plot(RN1L Sorted matching(3)r)plot(RN1L Sorted matching(4)m)

Appendix A 57

grid ontitle(RN1L)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)

subplot(232)hold onplot(RN2L Sorted matching(1)b)plot(RN2L Sorted matching(2)g)plot(RN2L Sorted matching(3)r)plot(RN2L Sorted matching(4)m)grid ontitle(RN2L)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)

subplot(233)hold onplot(RN3L Sorted matching(1)b)plot(RN3L Sorted matching(2)g)plot(RN3L Sorted matching(3)r)plot(RN3L Sorted matching(4)m)grid ontitle(RN3L)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)

subplot(234)hold onplot(RN1S Sorted matching(1)b)plot(RN1S Sorted matching(2)g)plot(RN1S Sorted matching(3)r)plot(RN1S Sorted matching(4)m)grid ontitle(RN1S)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)

subplot(235)hold onplot(RN2S Sorted matching(1)b)plot(RN2S Sorted matching(2)g)plot(RN2S Sorted matching(3)r)plot(RN2S Sorted matching(4)m)grid ontitle(RN2S)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)

58 Application

subplot(236)hold onplot(RN3S Sorted matching(1)b)plot(RN3S Sorted matching(2)g)plot(RN3S Sorted matching(3)r)plot(RN3S Sorted matching(4)m)grid ontitle(RN3S)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)set(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN4png minusr300)h(5)=figure(NameSorted RatiosNumberTitleoff)RN1L ratio1=RN1L NodesG hatRN1L NodesGRN2L ratio1=RN2L NodesG hatRN2L NodesGRN3L ratio1=RN3L NodesG hatRN3L NodesGRN1S ratio1=RN1S NodesG hatRN1S NodesGRN2S ratio1=RN2S NodesG hatRN2S NodesGRN3S ratio1=RN3S NodesG hatRN3S NodesG

RN1L ratio2=RN1L EdgesG HatRN1L EdgesGRN2L ratio2=RN2L EdgesG HatRN2L EdgesGRN3L ratio2=RN3L EdgesG HatRN3L EdgesGRN1S ratio2=RN1S EdgesG HatRN1S EdgesGRN2S ratio2=RN2S EdgesG HatRN2S EdgesGRN3S ratio2=RN3S EdgesG HatRN3S EdgesG

RN1L ratio3=RN1L MaxDegreeG HatRN1L MaxDegreeGRN2L ratio3=RN2L MaxDegreeG HatRN2L MaxDegreeGRN3L ratio3=RN3L MaxDegreeG HatRN3L MaxDegreeGRN1S ratio3=RN1S MaxDegreeG HatRN1S MaxDegreeGRN2S ratio3=RN2S MaxDegreeG HatRN2S MaxDegreeGRN3S ratio3=RN3S MaxDegreeG HatRN3S MaxDegreeG

RN1L ratio(1)=RN1L ratio1RN1L ratio(2)=RN1L ratio2RN1L ratio(3)=RN1L ratio3

RN2L ratio(1)=RN2L ratio1RN2L ratio(2)=RN2L ratio2RN2L ratio(3)=RN2L ratio3

RN3L ratio(1)=RN3L ratio1RN3L ratio(2)=RN3L ratio2RN3L ratio(3)=RN3L ratio3

RN1S ratio(1)=RN1S ratio1RN1S ratio(2)=RN1S ratio2RN1S ratio(3)=RN1S ratio3

RN2S ratio(1)=RN2S ratio1

Appendix A 59

RN2S ratio(2)=RN2S ratio2RN2S ratio(3)=RN2S ratio3

RN3S ratio(1)=RN3S ratio1RN3S ratio(2)=RN3S ratio2RN3S ratio(3)=RN3S ratio3

RN1L ratio sorted=sortrows(RN1L ratio)RN2L ratio sorted=sortrows(RN2L ratio)RN3L ratio sorted=sortrows(RN3L ratio)RN1S ratio sorted=sortrows(RN1S ratio)RN2S ratio sorted=sortrows(RN2S ratio)RN3S ratio sorted=sortrows(RN3S ratio)

subplot(231)hold onplot(RN1L ratio sorted(1)b)plot(RN1L ratio sorted(2)g)plot(RN1L ratio sorted(3)r)grid ontitle(RN1L)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)

subplot(232)hold onplot(RN2L ratio sorted(1)b)plot(RN2L ratio sorted(2)g)plot(RN2L ratio sorted(3)r)grid ontitle(RN2L)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)

subplot(233)hold onplot(RN3L ratio sorted(1)b)plot(RN3L ratio sorted(2)g)plot(RN3L ratio sorted(3)r)grid ontitle(RN3L)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)

subplot(234)hold onplot(RN1S ratio sorted(1)b)plot(RN1S ratio sorted(2)g)plot(RN1S ratio sorted(3)r)grid on

60 Application

title(RN1S)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)

subplot(235)hold onplot(RN2S ratio sorted(1)b)plot(RN2S ratio sorted(2)g)plot(RN2S ratio sorted(3)r)grid ontitle(RN2S)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)

subplot(236)hold onplot(RN3S ratio sorted(1)b)plot(RN3S ratio sorted(2)g)plot(RN3S ratio sorted(3)r)grid ontitle(RN3S)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)set(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN5png minusr300)

h(6)=figure(NameSorted edges over nodesNumberTitleoff)

RN1L DegreeG1=(RN1L EdgesG)(RN1L NodesG)RN1L DegreeG Hat1=(RN1L EdgesG Hat)(RN1L NodesG hat)

RN1L Degree temp1(1)=RN1L DegreeG1RN1L Degree temp1(2)=RN1L DegreeG Hat1RN1L Degree sorted1=sortrows(RN1L Degree temp1)subplot(231)hold on

plot(RN1L Degree sorted1(1)b)plot(RN1L Degree sorted1(2)g)grid ontitle(RN1L)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)

RN2L DegreeG1=(RN2L EdgesG)(RN2L NodesG)RN2L DegreeG Hat1=(RN2L EdgesG Hat)(RN2L NodesG hat)

RN2L Degree temp1(1)=RN2L DegreeG1

Appendix A 61

RN2L Degree temp1(2)=RN2L DegreeG Hat1RN2L Degree sorted1=sortrows(RN2L Degree temp1)

subplot(232)hold onplot(RN2L Degree sorted1(1)b)plot(RN2L Degree sorted1(2)g)grid ontitle(RN2L)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)

RN3L DegreeG1=(RN3L EdgesG)(RN3L NodesG)RN3L DegreeG Hat1=(RN3L EdgesG Hat)(RN3L NodesG hat)

RN3L Degree temp1(1)=RN3L DegreeG1RN3L Degree temp1(2)=RN3L DegreeG Hat1RN3L Degree sorted1=sortrows(RN3L Degree temp1)

subplot(233)hold onplot(RN3L Degree sorted1(1)b)plot(RN3L Degree sorted1(2)g)grid ontitle(RN3L)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)

RN1S DegreeG1=(RN1S EdgesG)(RN1S NodesG)RN1S DegreeG Hat1=(RN1S EdgesG Hat)(RN1S NodesG hat)

RN1S Degree temp1(1)=RN1S DegreeG1RN1S Degree temp1(2)=RN1S DegreeG Hat1RN1S Degree sorted1=sortrows(RN1S Degree temp1)

subplot(234)hold onplot(RN1S Degree sorted1(1)b)plot(RN1S Degree sorted1(2)g)grid ontitle(RN1S)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)

RN2S DegreeG1=(RN2S EdgesG)(RN2S NodesG)RN2S DegreeG Hat1=(RN2S EdgesG Hat)(RN2S NodesG hat)

RN2S Degree temp1(1)=RN2S DegreeG1

62 Application

RN2S Degree temp1(2)=RN2S DegreeG Hat1RN2S Degree sorted1=sortrows(RN2S Degree temp1)

subplot(235)hold onplot(RN2S Degree sorted1(1)b)plot(RN2S Degree sorted1(2)g)grid ontitle(RN2S)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)

RN3S DegreeG1=(RN3S EdgesG)(RN3S NodesG)RN3S DegreeG Hat1=(RN3S EdgesG Hat)(RN3S NodesG hat)

RN3S Degree temp1(1)=RN3S DegreeG1RN3S Degree temp1(2)=RN3S DegreeG Hat1RN3S Degree sorted1=sortrows(RN3S Degree temp1)

subplot(236)hold onplot(RN3S Degree sorted1(1)b)plot(RN3S Degree sorted1(2)g)grid ontitle(RN3S)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)set(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN6png minusr300)h(7)=figure(NameSorted mATCHED DEGREENumberTitleoff)RN1L ratioMax(1)=RN1L MaxDegreeGRN1L ratioMax(2)=RN1L MaxDegreeG Hat

RN1L ratio sortedMax=sortrows(RN1L ratioMax)subplot(231)hold onplot(RN1L ratio sortedMax(1)b)plot(RN1L ratio sortedMax(2)g)grid ontitle(RN1L)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)

RN2L ratioMax(1)=RN2L MaxDegreeGRN2L ratioMax(2)=RN2L MaxDegreeG Hat

RN2L ratio sortedMax=sortrows(RN2L ratioMax)subplot(232)

Appendix A 63

hold onplot(RN2L ratio sortedMax(1)b)plot(RN2L ratio sortedMax(2)g)grid ontitle(RN2L)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)

RN3L ratioMax(1)=RN3L MaxDegreeGRN3L ratioMax(2)=RN3L MaxDegreeG Hat

RN3L ratio sortedMax=sortrows(RN3L ratioMax)subplot(233)hold onplot(RN3L ratio sortedMax(1)b)plot(RN3L ratio sortedMax(2)g)grid ontitle(RN3L)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)

RN1S ratioMax(1)=RN1S MaxDegreeGRN1S ratioMax(2)=RN1S MaxDegreeG Hat

RN1S ratio sortedMax=sortrows(RN1S ratioMax)subplot(234)hold onplot(RN1S ratio sortedMax(1)b)plot(RN1S ratio sortedMax(2)g)grid ontitle(RN1S)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)

RN2S ratioMax(1)=RN2S MaxDegreeGRN2S ratioMax(2)=RN2S MaxDegreeG Hat

RN2S ratio sortedMax=sortrows(RN2S ratioMax)

subplot(235)hold onplot(RN2S ratio sortedMax(1)b)plot(RN2S ratio sortedMax(2)g)grid ontitle(RN2S)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)

RN3S ratioMax(1)=RN3S MaxDegreeGRN3S ratioMax(2)=RN3S MaxDegreeG Hat

64 Application

RN3S ratio sortedMax=sortrows(RN3S ratioMax)subplot(236)hold onplot(RN3S ratio sortedMax(1)b)plot(RN3S ratio sortedMax(2)g)grid ontitle(RN1L)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)set(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN7png minusr300)

tilefigs()(h)

Bibliography

[1] C Berge ldquoTWO THEOREMS IN GRAPH THEORYrdquo Proceedings of the NationalAcademy of Sciences of the United States of America vol 43 no 9 pp 842ndash844Sep 1957

[2] L Bui S Sanghavi and R Srikant ldquoDistributed link scheduling with constantoverheadrdquo IEEEACM Trans Netw vol 17 no 5 pp 1467ndash1480 2009

[3] R Duan and S Pettie ldquoLinear-time approximation for maximum weight matchingrdquoJ ACM vol 61 no 1 2014

[4] J Edmonds ldquoPaths trees and flowersrdquo Canadian Journal of Mathematics vol 17pp 449ndash467 1965

[5] J E Hopcroft and R M Karp ldquoAn n52 algorithm for maximum matchings inbipartite graphsrdquo SIAM J Comput vol 2 no 4 pp 225ndash231 1973

[6] S Micali and V V Vazirani ldquoAn O(radic|V ||E|) algorithm for finding maximum

matching in general graphsrdquo in 21st Symp on Foundations of Comp Sc (FOCS)IEEE 1980 pp 17ndash27

[7] N Nisse A Salch and V Weber ldquoRecovery of disrupted airline operationsrdquo 2015httphalinriafrSomething

[8] X Wu and R Srikant ldquoRegulated maximal matching A distributed schedulingalgorithm for multi-hop wireless networks with nodeexclusive spectrum sharingrdquo inIEEE Conf on Decision and Control 2005

65

  • Contents
  • Introduction
  • Algorithms
    • Maximum matching
    • k-maximum matching
      • k-matching for Airport Slot assignment
      • The case where k=3
      • The case of Paths
      • The case of the Spider
          • Application
            • Description
            • Reyni Erdos
            • Barabaacutesi Albert
            • Amadeus Graphs
            • Bipartite
            • Bipartite with degree seq
            • Appendix A
              • BipartiteGraphGeneratorpy
              • RandomGraphGeneratorpy
              • kequals3MaximumMatchingpy
              • Plotmat
                  • Bibliography
Page 22: Theodoros Alexandros KARAGKIOULES -  · Introduction This work is the result of a 6 months internship, under the supervision of research O cer Nicolas NISSE. The original scope of

24 Amadeus Graphs 23

bull For smaller initial matching the ∆s of G and G follow mostly the same trend onlya few number of different instances

24 Amadeus Graphs

Graph characteristics Amadeus graphs

bull These are the bipartite graphs provided by Amadeus

Computation time over |E|

Computation time over |E| - Comments

24 Application

bull For every instance the computation time of the classical algorithm is always smallerto that of the constraint matching

bull This allows as to speculate that we always compute a smaller G which also impliesthat we always find a set of forced edges and useless

Sorted matching size

Sorted matching size - Comments

bull Size of matching has an upward trend since the magnitude of the graphs is notthe same for the 160 instances

bull No significant deviation is noticed as per the first graph

24 Amadeus Graphs 25

bull Except from deviation from the perfect matching (number of flights) where some-times it could get up to 40

bull For the Amadeus Bipartite graphs we can see that the difference of the Classicaland the constraint implementation is not more than 1 edge in the matching

bull There appears to be a difference of up to 24 edges between the Classical matchingand the Perfect matching which is computed as the number of flights

bull The greedy algorithm performs well with only a few instances deviating slightlyform the Constraint algorithm result

Sorted Ratios

Sorted Ratios - Comments

26 Application

bull

Sorted |E||V |

Sorted |E||V | - Comments

bull Density of the graphs shows that on average we have 25-3 available time slot perflight

bull The line for the same value for G shows that there is a large deviation for everyinstance which allows for the hypothesis that the amount of useless+forced edgesof G has no obvious correlation to that of G

25 Bipartite 27

Sorted ∆

Sorted ∆-Comments

bull As per the previous related graphs for ∆ there is in significant drop in the ∆ of Gand G

25 Bipartite

Graph characteristics Bipartite random Graphs

bull BIPxy are randomly generated graphs with a fixed number of 1000(n=500 andm=500) nodes

bull There are 6 categories based on ini matching and probability p

28 Application

bull Probability p has been chosen as such in order to simulate the |E||V | 25 of theAmadeus bipartite graphs

bull So in order to have about 2-4 edges for every node we choose accordingly theprobability p to choose one of the n lowastm possible edges

bull x = L S L When the initial matching is large and S when it is small

bull y = 1 2 3 1 when p = 18250

2 when p = 25250

and 3 when p = 34250

Computation time over

Computation time overedges-Comments

bull

25 Bipartite 29

Sorted matching size

Sorted matching size-Comments

bull In these set of graphs one can instantly notice that only a few instances with highprobability can reach a matching size equal to the perfect matching

bull For the case of the initial matching we witness that there is a gap between the lineof the classical matching and those of the constraint and greedy results suggestingsmaller matching sizes of 10-40 edges

bull For the case of the small initial matching the result of the constraint matchingis now close to the result of the classical matching yet the greedy algorithm stillshows a relevantly big difference

30 Application

bull In this set of bipartite graphs we can witness that the result of the Constraintmatching shows a difference with the classical matching when the initial matchingis large The difference is smaller as the probability gets larger

bull For the case of the small initial matching the above phenomenom does not occuryet the greedy results deviates from that of the constraint matching

bull As per the pefrect matching compared to the classical matching a difference of5-10 edges is evident at almost all cases

Sorted Ratios

Sorted Ratios-Comments

bull Great max degree deviation

25 Bipartite 31

bull Regardless of the probability the ration of nodes and edges seems to have similarbehaviour when compared to the respective graphs of the same matching scale

bull Same gap between nodes ration and edges ration for all cases

Sorted |E||V |

Sorted |E||V | - Comments

bull In these set of figures we witness that the |E||V | acquires values relevant to those ofthe amadeus graphs The random graphs were constructed to depict this similarity

bull For smaller initial matching the ratios for G and G show the same upward trendand also they acquire closer values It represents the decrease of the averagenumber of forced edges in comparison to the larger matching cases

32 Application

Sorted ∆

Sorted ∆-Comments

bull ∆ acquires the same min and max values for each probability case (expected)

bull Gap in the case of large initial matching

26 Bipartite with degree seq

Graph characteristics

bull DEQBIPxy are randomly generated graphs based on three different types of degreedistribution of the Amadeus graphs

26 Bipartite with degree seq 33

bull There are 6 categories based on ini matching and degree distribution

bull x = L S L When the initial matching is large and S when it is small

bull y = 1 2 3 1 when degree distribution is based on file 2 when degree distributionis based on file and 3 when degree distribution is based on file

Computation time over

34 Application

Computation time overedges-Comments

bull Greedy algorithm takes minimum amount of time

bull The smaller the initial matching the more smaller the difference in comoutationtime of Constraint and classical algorithm

bull Due to preprocessing and the fact that G and G are the almost identical thetotal time needed to apply the constraint algorithm is in some cases bigger

Sorted matching size

26 Bipartite with degree seq 35

Sorted matching size-Comments

bull Classical matching is equal to perfect matching in every case

bull Constraint and greedy have identical behaviour

bull The larger the spectrum of the degree sequence the more efficient the matching

Sorted Ratios

36 Application

Sorted Ratios-Comments

bull With large initial matching most of the edges are considenred uselles or forced andare removed thus the ratio is close(if not equal to) zero

bull For small matching and large degree sequence sectrum hte max degree remainsthe same Only a few forced edges (and their nodes) are removed apparently nonodes with max degree

Sorted |E||V |

26 Bipartite with degree seq 37

Sorted |E||V | - Comments

bull In these set of figures we witness that the |E||V | acquires values relevant to those ofthe amadeus graphs The random graphs were constructed to depict this similarity

bull For smaller initial matching the ratios for G and G show the same upward trendand also they acquire closer values It repsresent the decrease of the averagenumber of forced edges in comparison to the larger matching cases

Sorted ∆

38 Application

Sorted ∆-Comments

bull Big difference in max degree in large initial matching

bull Almost identical behaviour in the case of small initial matching

Appendix A 39

Appendix A

BipartiteGraphGeneratorpy

from future import divisionimport networkx as nx

from networkxalgorithms import approximationimport collectionsimport randomimport mathfrom networkxalgorithms import bipartiteif name == main

for i in range(1481)waqs 481index=1n=randomrandint(100 1000)

n1=95 was 500me1=118

n2=251 was 500me2=903

n3=165 was 500me3=412

m=0m1=0p=randomrandom()p1=18250p2=25250p3=34250print ip=05t1=randomrandint(0 1)print im2=randomrandint(n2minus1 n2+1)G = nxGraph()ma = nxGraph()

aseq1=[1 2 3 4 5 3]

bseq1=[4 3 3 1 2 2 1]

aseq2=[16 14 14 14 12 11]bseq2=[0 0 0 0 0 0]

aseq3=[8 7 8 8 8 8]bseq3=[0 0 0 0 0 0]

40 Application

print Gnumber of edges()if ilt=160

G=bipartiteconfiguration model(aseq1 bseq1 create using=None seed=None)A=nxadjacency matrix(G)for ii in range(0n1+me1)

maadd node(ii)A=[Rtodense()tolist()[0] for R in A]

printnummanumber of nodes()rl=randomsample(range(0n1+me1) n1+me1)m=0done vertices = set()for p in rlprintin fordone verticesadd(p)

neighbors = []list()for iii in range(0n1+me1)

if A[p][iii]==1neighborsappend(iii)

randomshuffle(neighbors)continue loop = Truedegree = len(neighbors)

print degreej = 0p4=randomrandom()while continue loop and (jltdegree)print in loop

next = neighbors[j]if next not in done vertices and p not in done vertices

done verticesadd(p)done verticesadd(next)if p4gt=07print added edge

maadd edge(pnext)m=m+1

continue loop = Falsej += 1

print matching listOfedgeprint maedge

MA=nxadjacency matrix(ma)print MA

MA=[Rtodense()tolist()[0] for R in MA]print MA

B=[ join(map(strR)) for R in A]MB=[ join(map(strR)) for R in MA]

C=njoin(B)+nMC=njoin(MB)+n

print nprint mprint m1

filea=str(i)+txtwith open(fileaw) as f

Appendix A 41

fwrite(str(n1+me1))fwrite(n)fwrite(str(n1+me1))fwrite(n)fwrite(str(m))fwrite(n)fwrite(n)fwrite(C)fwrite(n)fwrite(MC)

elif igt160 and ilt321G=bipartiteconfiguration model(aseq2 bseq2 create using=None seed=None)A=nxadjacency matrix(G)for ii in range(0n2+me2)

maadd node(ii)A=[Rtodense()tolist()[0] for R in A]

printnummanumber of nodes()rl=randomsample(range(0n2+me2) n2+me2)m=0done vertices = set()for p in rlprintin fordone verticesadd(p)

neighbors = []list()for iii in range(0n2+me2)

if A[p][iii]==1neighborsappend(iii)

randomshuffle(neighbors)continue loop = Truedegree = len(neighbors)

print degreej = 0p4=randomrandom()while continue loop and (jltdegree)

print in loopnext = neighbors[j]if next not in done vertices and p not in done vertices

done verticesadd(p)done verticesadd(next)if p4gt=07

print added edgemaadd edge(pnext)m=m+1

continue loop = Falsej += 1

print matching listOfedgeprint maedge

MA=nxadjacency matrix(ma)print MA

MA=[Rtodense()tolist()[0] for R in MA]print MA

B=[ join(map(strR)) for R in A]MB=[ join(map(strR)) for R in MA]

42 Application

C=njoin(B)+nMC=njoin(MB)+n

print nprint mprint m1

filea=str(i)+txtwith open(fileaw) as f

fwrite(str(n2+me2))fwrite(n)fwrite(str(n2+me2))fwrite(n)fwrite(str(m))fwrite(n)fwrite(n)fwrite(C)fwrite(n)fwrite(MC)

elseG=bipartiteconfiguration model(aseq3 bseq3 create using=None seed=None)A=nxadjacency matrix(G)for ii in range(0n3+me3)

maadd node(ii)A=[Rtodense()tolist()[0] for R in A]

printnummanumber of nodes()rl=randomsample(range(0n3+me3) n3+me3)m=0done vertices = set()for p in rlprintin fordone verticesadd(p)

neighbors = []list()for iii in range(0n3+me3)

if A[p][iii]==1neighborsappend(iii)

randomshuffle(neighbors)continue loop = Truedegree = len(neighbors)

print degreej = 0p4=randomrandom()while continue loop and (jltdegree)

print in loopnext = neighbors[j]if next not in done vertices and p not in done vertices

done verticesadd(p)done verticesadd(next)if p4gt=07print added edge

maadd edge(pnext)m=m+1

continue loop = Falsej += 1

Appendix A 43

print matching listOfedgeprint maedge

MA=nxadjacency matrix(ma)print MA

MA=[Rtodense()tolist()[0] for R in MA]print MA

B=[ join(map(strR)) for R in A]MB=[ join(map(strR)) for R in MA]

C=njoin(B)+nMC=njoin(MB)+n

print nprint mprint m1

filea=str(i)+txtwith open(fileaw) as f

fwrite(str(n3+me3))fwrite(n)fwrite(str(n3+me3))fwrite(n)fwrite(str(m))fwrite(n)fwrite(n)fwrite(C)fwrite(n)fwrite(MC)

print nRandom graphs with random matching have been generated

44 Application

RandomGraphGeneratorpy

from future import divisionimport networkx as nxfrom networkxalgorithms import approximationimport collectionsimport randomimport mathif name == main

for i in range(1481)index=1n=randomrandint(100 1000)

n=1000m=0m1=0p=randomrandom()p1=mathlog(n2)np2=13p3=mathlog(n2)n+01p=05t1=randomrandint(0 1)print im2=randomrandint(n2minus1 n2+1)G = nxGraph()ma = nxGraph()print nme1=randomrandint(1 10)me2=randomrandint(2050)me3=randomrandint(50100)if ilt241

if ilt=80G=nxfast gnp random graph(n p1 seed=None directed=False)

elif igt80 and ilt161G=nxfast gnp random graph(n p2 seed=None directed=False)

elseG=nxfast gnp random graph(n p3 seed=None directed=False)

elseif ilt=320

G=nxbarabasi albert graph(n me1 seed=None)elif igt320 and ilt401

G=nxbarabasi albert graph(n me2 seed=None)else

G=nxbarabasi albert graph(n me3 seed=None)A=nxadjacency matrix(G)for ii in range(0n)

maadd node(ii)A=[Rtodense()tolist()[0] for R in A]

rl=randomsample(range(0n) n)m=0

Appendix A 45

done vertices = set()for p in rl

done verticesadd(p)neighbors = []list()for iii in range(0n)

if A[p][iii]==1neighborsappend(iii)

randomshuffle(neighbors)continue loop = Truedegree = len(neighbors)j = 0p2=randomrandom()while continue loop and (jltdegree)

next = neighbors[j]if next not in done vertices and p not in done vertices

done verticesadd(p)done verticesadd(next)if p2gt=00 Larger probability for smaller initial matching

maadd edge(pnext)m=m+1

continue loop = Falsej += 1

print matching listOfedgeprint maedgeMA=nxadjacency matrix(ma)MA=[Rtodense()tolist()[0] for R in MA]print MAB=[ join(map(strR)) for R in A]MB=[ join(map(strR)) for R in MA]

C=njoin(B)+nMC=njoin(MB)+nprint MCprint nprint mprint m1filea=str(i)+txtwith open(fileaw) as f

fwrite(str(n))fwrite(n)fwrite(str(n))fwrite(n)fwrite(str(m))fwrite(n)fwrite(n)fwrite(C)fwrite(n)fwrite(MC)

print nRandom graphs with random matching have been generated

46 Application

kequals3MaximumMatchingpy

from future import divisionimport networkx as nxfrom networkxalgorithms import bipartiteimport matplotlibpyplot as pltimport collectionsimport timeitimport xlwtimport xlrdimport mathimport sys

Case for General Graphsdef forced edges(Gadj dict2matching dict1num nodesforced)

flagg=0for n in range(0num nodes)

for k in adj dict2[n]if ([k]==matching dict1[n])

count=0for l in range(0num nodes)

count=count+adj dict2[l]count(k)if (len(adj dict2[n])==1) or (count==1)

forcedadd edge(nk)Gremove edge(nk)Gremove node(n)Gremove node(k)printforced edgenktemp=kflagg=1for m in range (len(adj dict2[n])minus1minus1minus1)

adj dict2[adj dict2[n][m]]remove(n)adj dict2[n]remove(adj dict2[n][m])

if adj dict2[temp]for l in range(len(adj dict2[temp])minus1minus1minus1)

if (adj dict2[temp][l]=n)adj dict2[adj dict2[temp][l]]remove(temp)adj dict2[temp]remove(adj dict2[temp][l])

break

def useless edges(num nodesadj dict1matching dict1uselessadj dict2G)for n in range(0num nodes)

for k in adj dict1[n]if ([k]=matching dict1[n]) and matching dict1[n] and matching dict1[k]

uselessadd edge(nk)Gremove edge(n k)

Appendix A 47

tempa=kadj dict2[n]remove(k)adj dict2[tempa]remove(n)adj dict1[tempa]remove(n)

return G

def Greedy(num nodesadj dict3matching dict2)

for n in range(0num nodes)if matching dict2[n]

flag2=minus1flag3=minus1for v in adj dict3[n]

if not matching dict2[v]flag2=vbreak

for p in adj dict3[matching dict2[n][0]]if not matching dict2[p]

flag3=pbreak

if (flag2=minus1) and (flag3=minus1) and (flag2=flag3)tempr=matching dict2[n][0]matching dict2[n]=[flag2]matching dict2[flag2]=[n]matching dict2[tempr]=[flag3]matching dict2[flag3]=[tempr]

elsefor k in adj dict3[n]

if not matching dict2[k]matching dict2[n]=[k]matching dict2[k]=[n]break

yo1=0for i in range(0num nodes)

if matching dict2[i] and [i]==matching dict2[matching dict2[i][0]]yo1=yo1+1

greedy size=yo12return greedy size

def General()

INPUTSwb = xlwtWorkbook()ws = wbadd sheet(Results Random)book=xlrdopen workbook(filenames randomxls)

48 Application

style0 = xlwteasyxf(fontbold on)style1 = xlwteasyxf(num format str=0000)INPUTSwswrite(0 0File style0)wswrite(0 1 Nodesstyle0)wswrite(0 2 Initial matchingstyle0)wswrite(0 3 NodesGstyle0)wswrite(0 4 EdgesGstyle0)wswrite(0 5 MaxDegreeGstyle0)wswrite(0 6 NodesG hatstyle0)wswrite(0 7 EdgesG Hatstyle0)wswrite(0 8 Useless edgesstyle0)wswrite(0 9 Forced edgesstyle0)wswrite(0 10 MaxDegreeG Hatstyle0)wswrite(0 11 Classical matchingstyle0)wswrite(0 12 Final matchingstyle0)wswrite(0 13 Greedy matchingstyle0)wswrite(0 14 Time classicalstyle0)wswrite(0 15 Time algorithmstyle0)wswrite(0 16 Time greedystyle0)wswrite(0 17 Perfect matching ratiostyle0)wswrite(0 18 Nodes ratiostyle0)wswrite(0 19 Edges ratiostyle0)wswrite(0 20 Matching ratiostyle0)

print nWelcomeThis is an implementation for general random graphs It uses Edmonds algorithm to compute maximum matching on G Hatn

for index in range (1481)was 481

if (index==482)f=open(Algotel generaltxtr)readlines()

elsefilea=str(booksheet by index(0)cell(index0))s=fileareplace(textu)replace()f=open(sr)readlines()Truewswrite(index 0 s)

print index

num nodes=int([xstrip()split() for x in f][0][0])

num matching=int([xstrip()split() for x in f][2][0])

adj temp = [xstrip()split() for x in f][44+num nodes]adj=[map(intR) for R in adj temp]

matching temp=[xstrip()split() for x in f][4+num nodes+14+2num nodes+1]matching1=[map(intR) for R in matching temp]

adj dict1=i[ii for iix in enumerate(L) if x] for iL in enumerate(adj)adj dict2=i[ii for iix in enumerate(L) if x] for iL in enumerate(adj)

Appendix A 49

adj dict3=i[ii for iix in enumerate(L) if x] for iL in enumerate(adj)

matching dict1=i[ii for iix in enumerate(L) if x] for iL in enumerate(matching1)matching dict2=i[ii for iix in enumerate(L) if x] for iL in enumerate(matching1)print adj dict2print matching dict2wswrite(index 1 num nodes)wswrite(index 2 num matching)

G = nxGraph()

useless= nxGraph()forced = nxGraph()

Fill Graphfor n in range(0num nodes)

for k in adj dict1[n]Gadd edge(nk)

Gt=Gnumber of edges()wswrite(index 3 Gnumber of nodes())wswrite(index 4 Gnumber of edges())wswrite(index 5 max(Gdegree()values()))

Compute Edmonds classical matching on G for comparison

startB = timeitdefault timer()Classical Matching=nxmax weight matching(G maxcardinality=False)stopB = timeitdefault timer()

Compute Gˆ nad MˆstartC = timeitdefault timer()useless edges(num nodesadj dict1matching dict1uselessadj dict2G)forced edges(Gadj dict2matching dict1num nodesforced)Final Matching=nxmax weight matching(G maxcardinality=False)stopC = timeitdefault timer()

GreedystartG = timeitdefault timer()greedy size=Greedy(num nodesadj dict3matching dict2)stopG = timeitdefault timer()

wswrite(index 6 Gnumber of nodes())wswrite(index 7 Gnumber of edges())wswrite(index 8 uselessnumber of edges())wswrite(index 9 forcednumber of edges())if Gdegree()values()

wswrite(index 10 max(Gdegree()values()))else

50 Application

wswrite(index 10 0)wswrite(index 11 len(Classical Matching)2)wswrite(index 12 len(Final Matching)2+forcednumber of edges())wswrite(index 13 greedy size)wswrite(index 14 stopB minus startBstyle1)wswrite(index 15 stopC minus startCstyle1)wswrite(index 16 stopG minus startGstyle1)wswrite(index 17 (len(Final Matching)2+forcednumber of edges())(num nodes2)style1)wswrite(index 18 Gnumber of nodes()Gtstyle1)wswrite(index 19 Gnumber of edges()Gtstyle1)wswrite(index 20 (len(Final Matching)2+forcednumber of edges())(len(Classical Matching)2)style1)

wbsave(AA Results Random Reyni Large Bipartitexls)

Main function Here we must choose the input form of the dataif name == main

startA = timeitdefault timer()General()stopA = timeitdefault timer()

print nThis program has terminatednnRunning time for 480 files stopAminusstartAprint nnPlease open AA Results Random Reyni Largexls file to see the Results

Appendix A 51

Plotmat

clear allclose allload(RN1Lmat)load(RN1Smat)load(RN2Lmat)load(RN2Smat)load(RN3Lmat)load(RN3Smat)

Plotsh(1)=figure(NameHistogram of Matching size difference between Constraint Algorithm and Greedy AlgorithmNumberTitleoff)

RN1L Greedydiff=RN1L Final matchingminusRN1L Greedy matchingRN2L Greedydiff=RN2L Final matchingminusRN2L Greedy matchingRN3L Greedydiff=RN3L Final matchingminusRN3L Greedy matchingRN1S Greedydiff=RN1S Final matchingminusRN1S Greedy matchingRN2S Greedydiff=RN2S Final matchingminusRN2S Greedy matchingRN3S Greedydiff=RN3S Final matchingminusRN3S Greedy matching

RN1L Finaldiff=RN1L Classical matchingminusRN1L Final matchingRN2L Finaldiff=RN2L Classical matchingminusRN2L Final matchingRN3L Finaldiff=RN3L Classical matchingminusRN3L Final matchingRN1S Finaldiff=RN1S Classical matchingminusRN1S Final matchingRN2S Finaldiff=RN2S Classical matchingminusRN2S Final matchingRN3S Finaldiff=RN3S Classical matchingminusRN3S Final matching

RN1L Classicaldiff=(RN1L Nodes2)minusRN1L Classical matchingRN2L Classicaldiff=(RN2L Nodes2)minusRN2L Classical matchingRN3L Classicaldiff=(RN3L Nodes2)minusRN3L Classical matchingRN1S Classicaldiff=(RN1S Nodes2)minusRN1S Classical matchingRN2S Classicaldiff=(RN2S Nodes2)minusRN2S Classical matchingRN3S Classicaldiff=(RN3S Nodes2)minusRN3S Classical matching

subplot(231)hold onhistf(RN1L Greedydiff0110facecolorbfacealpha9edgealpha1)histf(RN1L Finaldiff0110facecolorrfacealpha5edgealpha1)histf(RN1L Classicaldiff0110facecolorgfacealpha5edgealpha1)legalpha(ConminusGreClasminusConPerfminusClasslocationnortheast)legend boxoffaxis tightxlabel(edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN1L)grid on

subplot(232)hold onhistf(RN2L Greedydiff0110facecolorbfacealpha9edgealpha1)

52 Application

histf(RN2L Finaldiff0110facecolorrfacealpha5edgealpha1)histf(RN2L Classicaldiff0110facecolorgfacealpha5edgealpha1)legalpha(ConminusGreClasminusConPerfminusClasslocationnortheast)legend boxoffaxis tightxlabel(edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN2L)grid on

subplot(233)hold onhistf(RN3L Greedydiff0110facecolorbfacealpha5edgealpha1)histf(RN3L Finaldiff0110facecolorrfacealpha5edgealpha1)histf(RN3L Classicaldiff0110facecolorgfacealpha5edgealpha1)legalpha(ConminusGreClasminusConPerfminusClasslocationnortheast)legend boxoffaxis tightxlabel(edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN3L)grid on

subplot(234)hold onhistf(RN1S Greedydiff0110facecolorbfacealpha5edgealpha1)histf(RN1S Finaldiff0110facecolorrfacealpha5edgealpha1)histf(RN1S Classicaldiff0110facecolorgfacealpha5edgealpha1)legalpha(ConminusGreClasminusConPerfminusClasslocationnortheast)legend boxoffaxis tightxlabel(edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(R1NS)grid on

subplot(235)hold onhistf(RN2S Greedydiff0110facecolorbfacealpha5edgealpha1)histf(RN2S Finaldiff0110facecolorrfacealpha5edgealpha1)histf(RN2S Classicaldiff0110facecolorgfacealpha5edgealpha1)legalpha(ConminusGreClasminusConPerfminusClasslocationnortheast)legend boxoffaxis tightxlabel(edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN2S)grid on

subplot(236)hold onhistf(RN3S Greedydiff0110facecolorbfacealpha5edgealpha1)histf(RN3S Finaldiff0110facecolorrfacealpha5edgealpha1)histf(RN3S Classicaldiff0110facecolorgfacealpha5edgealpha1)

Appendix A 53

legalpha(ConminusGreClasminusConPerfminusClasslocationnortheast)legend boxoffaxis tightgrid ontitle(RN3S)xlabel(edges) xminusaxis labelylabel(instances) yminusaxis labelset(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN1png minusr300)h(2)=figure(NameHistogram of Max Degree of G AND G HatNumberTitleoff)RN1L x=RN1L MaxDegreeGminusRN1L MaxDegreeG HatRN2L x=RN2L MaxDegreeGminusRN2L MaxDegreeG HatRN3L x=RN3L MaxDegreeGminusRN3L MaxDegreeG HatRN1S x=RN1S MaxDegreeGminusRN1S MaxDegreeG HatRN2S x=RN2S MaxDegreeGminusRN2S MaxDegreeG HatRN3S x=RN3S MaxDegreeGminusRN3S MaxDegreeG Hatsubplot(231)hold onhistf(RN1L MaxDegreeG0150facecolorbfacealpha5edgealpha1)histf(RN1L MaxDegreeG Hat0150facecolorrfacealpha5edgealpha1)histf(RN1L x0150facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightxlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN1L)grid on

subplot(232)hold onhistf(RN2L MaxDegreeG010500facecolorbfacealpha5edgealpha1)histf(RN2L MaxDegreeG Hat010500facecolorrfacealpha5edgealpha1)histf(RN2L x010500facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightxlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN2L)grid on

subplot(233)hold onhistf(RN3L MaxDegreeG010300facecolorbfacealpha5edgealpha1)histf(RN3L MaxDegreeG Hat010300facecolorrfacealpha5edgealpha1)histf(RN3L x010300facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightxlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN3L)

54 Application

grid on

subplot(234)hold onhistf(RN1S MaxDegreeG0150facecolorbfacealpha5edgealpha1)histf(RN1S MaxDegreeG Hat0150facecolorrfacealpha5edgealpha1)histf(RN1S x0150facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightxlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(R1NS)grid on

subplot(235)hold onhistf(RN2S MaxDegreeG010500facecolorbfacealpha5edgealpha1)histf(RN2S MaxDegreeG Hat010500facecolorrfacealpha5edgealpha1)histf(RN2S x010500facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightxlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN2S)grid on

subplot(236)hold onhistf(RN3S MaxDegreeG05300facecolorbfacealpha5edgealpha1)histf(RN3S MaxDegreeG Hat05300facecolorrfacealpha5edgealpha1)histf(RN3S x05300facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightgrid ontitle(RN3S)xlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labelset(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN2png minusr300)

h(3)=figure(NameComputation time over edgesNumberTitleoff)

subplot(231)hold onstem(RN1L EdgesGRN1L Time classicalg)stem(RN1L EdgesGRN1L Time algorithmro)stem(RN1L EdgesGRN1L Time greedybx)grid on

Appendix A 55

title(RN1L)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)

subplot(232)hold onstem(RN2L EdgesGRN2L Time classicalg)stem(RN2L EdgesGRN2L Time algorithmro)stem(RN2L EdgesGRN2L Time greedybx)grid ontitle(RN2L)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)

subplot(233)hold onstem(RN3L EdgesGRN3L Time classicalg)stem(RN3L EdgesGRN3L Time algorithmro)stem(RN3L EdgesGRN3L Time greedybx)grid ontitle(RN3L)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)

subplot(234)hold onstem(RN1S EdgesGRN1S Time classicalg)stem(RN1S EdgesGRN1S Time algorithmro)stem(RN1S EdgesGRN1S Time greedybx)grid ontitle(RN1S)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)

subplot(235)hold onstem(RN2S EdgesGRN2S Time classicalg)stem(RN2S EdgesGRN2S Time algorithmro)stem(RN2S EdgesGRN2S Time greedybx)grid ontitle(RN2S)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)

subplot(236)hold onstem(RN3S EdgesGRN3S Time classicalg)stem(RN3S EdgesGRN3S Time algorithmro)stem(RN3S EdgesGRN3S Time greedybx)

56 Application

grid ontitle(RN3S)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)set(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN3png minusr300)

h(4)=figure(NameSorted matching sizeNumberTitleoff)RN1L Sorted matching temp(1)=RN1L Classical matchingRN1L Sorted matching temp(2)=RN1L Final matchingRN1L Sorted matching temp(3)=RN1L Greedy matchingRN1L Sorted matching temp(4)=RN1L Initial matchingRN1L Sorted matching=sortrows(RN1L Sorted matching temp)

RN2L Sorted matching temp(1)=RN2L Classical matchingRN2L Sorted matching temp(2)=RN2L Final matchingRN2L Sorted matching temp(3)=RN2L Greedy matchingRN2L Sorted matching temp(4)=RN2L Initial matchingRN2L Sorted matching=sortrows(RN2L Sorted matching temp)

RN3L Sorted matching temp(1)=RN3L Classical matchingRN3L Sorted matching temp(2)=RN3L Final matchingRN3L Sorted matching temp(3)=RN3L Greedy matchingRN3L Sorted matching temp(4)=RN3L Initial matchingRN3L Sorted matching=sortrows(RN3L Sorted matching temp)

RN1S Sorted matching temp(1)=RN1S Classical matchingRN1S Sorted matching temp(2)=RN1S Final matchingRN1S Sorted matching temp(3)=RN1S Greedy matchingRN1S Sorted matching temp(4)=RN1S Initial matchingRN1S Sorted matching=sortrows(RN1S Sorted matching temp)

RN2S Sorted matching temp(1)=RN2S Classical matchingRN2S Sorted matching temp(2)=RN2S Final matchingRN2S Sorted matching temp(3)=RN2S Greedy matchingRN2S Sorted matching temp(4)=RN2S Initial matchingRN2S Sorted matching=sortrows(RN2S Sorted matching temp)

RN3S Sorted matching temp(1)=RN3S Classical matchingRN3S Sorted matching temp(2)=RN3S Final matchingRN3S Sorted matching temp(3)=RN3S Greedy matchingRN3S Sorted matching temp(4)=RN3S Initial matchingRN3S Sorted matching=sortrows(RN3S Sorted matching temp)

subplot(231)hold onplot(RN1L Sorted matching(1)b)plot(RN1L Sorted matching(2)g)plot(RN1L Sorted matching(3)r)plot(RN1L Sorted matching(4)m)

Appendix A 57

grid ontitle(RN1L)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)

subplot(232)hold onplot(RN2L Sorted matching(1)b)plot(RN2L Sorted matching(2)g)plot(RN2L Sorted matching(3)r)plot(RN2L Sorted matching(4)m)grid ontitle(RN2L)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)

subplot(233)hold onplot(RN3L Sorted matching(1)b)plot(RN3L Sorted matching(2)g)plot(RN3L Sorted matching(3)r)plot(RN3L Sorted matching(4)m)grid ontitle(RN3L)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)

subplot(234)hold onplot(RN1S Sorted matching(1)b)plot(RN1S Sorted matching(2)g)plot(RN1S Sorted matching(3)r)plot(RN1S Sorted matching(4)m)grid ontitle(RN1S)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)

subplot(235)hold onplot(RN2S Sorted matching(1)b)plot(RN2S Sorted matching(2)g)plot(RN2S Sorted matching(3)r)plot(RN2S Sorted matching(4)m)grid ontitle(RN2S)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)

58 Application

subplot(236)hold onplot(RN3S Sorted matching(1)b)plot(RN3S Sorted matching(2)g)plot(RN3S Sorted matching(3)r)plot(RN3S Sorted matching(4)m)grid ontitle(RN3S)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)set(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN4png minusr300)h(5)=figure(NameSorted RatiosNumberTitleoff)RN1L ratio1=RN1L NodesG hatRN1L NodesGRN2L ratio1=RN2L NodesG hatRN2L NodesGRN3L ratio1=RN3L NodesG hatRN3L NodesGRN1S ratio1=RN1S NodesG hatRN1S NodesGRN2S ratio1=RN2S NodesG hatRN2S NodesGRN3S ratio1=RN3S NodesG hatRN3S NodesG

RN1L ratio2=RN1L EdgesG HatRN1L EdgesGRN2L ratio2=RN2L EdgesG HatRN2L EdgesGRN3L ratio2=RN3L EdgesG HatRN3L EdgesGRN1S ratio2=RN1S EdgesG HatRN1S EdgesGRN2S ratio2=RN2S EdgesG HatRN2S EdgesGRN3S ratio2=RN3S EdgesG HatRN3S EdgesG

RN1L ratio3=RN1L MaxDegreeG HatRN1L MaxDegreeGRN2L ratio3=RN2L MaxDegreeG HatRN2L MaxDegreeGRN3L ratio3=RN3L MaxDegreeG HatRN3L MaxDegreeGRN1S ratio3=RN1S MaxDegreeG HatRN1S MaxDegreeGRN2S ratio3=RN2S MaxDegreeG HatRN2S MaxDegreeGRN3S ratio3=RN3S MaxDegreeG HatRN3S MaxDegreeG

RN1L ratio(1)=RN1L ratio1RN1L ratio(2)=RN1L ratio2RN1L ratio(3)=RN1L ratio3

RN2L ratio(1)=RN2L ratio1RN2L ratio(2)=RN2L ratio2RN2L ratio(3)=RN2L ratio3

RN3L ratio(1)=RN3L ratio1RN3L ratio(2)=RN3L ratio2RN3L ratio(3)=RN3L ratio3

RN1S ratio(1)=RN1S ratio1RN1S ratio(2)=RN1S ratio2RN1S ratio(3)=RN1S ratio3

RN2S ratio(1)=RN2S ratio1

Appendix A 59

RN2S ratio(2)=RN2S ratio2RN2S ratio(3)=RN2S ratio3

RN3S ratio(1)=RN3S ratio1RN3S ratio(2)=RN3S ratio2RN3S ratio(3)=RN3S ratio3

RN1L ratio sorted=sortrows(RN1L ratio)RN2L ratio sorted=sortrows(RN2L ratio)RN3L ratio sorted=sortrows(RN3L ratio)RN1S ratio sorted=sortrows(RN1S ratio)RN2S ratio sorted=sortrows(RN2S ratio)RN3S ratio sorted=sortrows(RN3S ratio)

subplot(231)hold onplot(RN1L ratio sorted(1)b)plot(RN1L ratio sorted(2)g)plot(RN1L ratio sorted(3)r)grid ontitle(RN1L)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)

subplot(232)hold onplot(RN2L ratio sorted(1)b)plot(RN2L ratio sorted(2)g)plot(RN2L ratio sorted(3)r)grid ontitle(RN2L)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)

subplot(233)hold onplot(RN3L ratio sorted(1)b)plot(RN3L ratio sorted(2)g)plot(RN3L ratio sorted(3)r)grid ontitle(RN3L)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)

subplot(234)hold onplot(RN1S ratio sorted(1)b)plot(RN1S ratio sorted(2)g)plot(RN1S ratio sorted(3)r)grid on

60 Application

title(RN1S)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)

subplot(235)hold onplot(RN2S ratio sorted(1)b)plot(RN2S ratio sorted(2)g)plot(RN2S ratio sorted(3)r)grid ontitle(RN2S)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)

subplot(236)hold onplot(RN3S ratio sorted(1)b)plot(RN3S ratio sorted(2)g)plot(RN3S ratio sorted(3)r)grid ontitle(RN3S)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)set(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN5png minusr300)

h(6)=figure(NameSorted edges over nodesNumberTitleoff)

RN1L DegreeG1=(RN1L EdgesG)(RN1L NodesG)RN1L DegreeG Hat1=(RN1L EdgesG Hat)(RN1L NodesG hat)

RN1L Degree temp1(1)=RN1L DegreeG1RN1L Degree temp1(2)=RN1L DegreeG Hat1RN1L Degree sorted1=sortrows(RN1L Degree temp1)subplot(231)hold on

plot(RN1L Degree sorted1(1)b)plot(RN1L Degree sorted1(2)g)grid ontitle(RN1L)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)

RN2L DegreeG1=(RN2L EdgesG)(RN2L NodesG)RN2L DegreeG Hat1=(RN2L EdgesG Hat)(RN2L NodesG hat)

RN2L Degree temp1(1)=RN2L DegreeG1

Appendix A 61

RN2L Degree temp1(2)=RN2L DegreeG Hat1RN2L Degree sorted1=sortrows(RN2L Degree temp1)

subplot(232)hold onplot(RN2L Degree sorted1(1)b)plot(RN2L Degree sorted1(2)g)grid ontitle(RN2L)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)

RN3L DegreeG1=(RN3L EdgesG)(RN3L NodesG)RN3L DegreeG Hat1=(RN3L EdgesG Hat)(RN3L NodesG hat)

RN3L Degree temp1(1)=RN3L DegreeG1RN3L Degree temp1(2)=RN3L DegreeG Hat1RN3L Degree sorted1=sortrows(RN3L Degree temp1)

subplot(233)hold onplot(RN3L Degree sorted1(1)b)plot(RN3L Degree sorted1(2)g)grid ontitle(RN3L)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)

RN1S DegreeG1=(RN1S EdgesG)(RN1S NodesG)RN1S DegreeG Hat1=(RN1S EdgesG Hat)(RN1S NodesG hat)

RN1S Degree temp1(1)=RN1S DegreeG1RN1S Degree temp1(2)=RN1S DegreeG Hat1RN1S Degree sorted1=sortrows(RN1S Degree temp1)

subplot(234)hold onplot(RN1S Degree sorted1(1)b)plot(RN1S Degree sorted1(2)g)grid ontitle(RN1S)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)

RN2S DegreeG1=(RN2S EdgesG)(RN2S NodesG)RN2S DegreeG Hat1=(RN2S EdgesG Hat)(RN2S NodesG hat)

RN2S Degree temp1(1)=RN2S DegreeG1

62 Application

RN2S Degree temp1(2)=RN2S DegreeG Hat1RN2S Degree sorted1=sortrows(RN2S Degree temp1)

subplot(235)hold onplot(RN2S Degree sorted1(1)b)plot(RN2S Degree sorted1(2)g)grid ontitle(RN2S)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)

RN3S DegreeG1=(RN3S EdgesG)(RN3S NodesG)RN3S DegreeG Hat1=(RN3S EdgesG Hat)(RN3S NodesG hat)

RN3S Degree temp1(1)=RN3S DegreeG1RN3S Degree temp1(2)=RN3S DegreeG Hat1RN3S Degree sorted1=sortrows(RN3S Degree temp1)

subplot(236)hold onplot(RN3S Degree sorted1(1)b)plot(RN3S Degree sorted1(2)g)grid ontitle(RN3S)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)set(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN6png minusr300)h(7)=figure(NameSorted mATCHED DEGREENumberTitleoff)RN1L ratioMax(1)=RN1L MaxDegreeGRN1L ratioMax(2)=RN1L MaxDegreeG Hat

RN1L ratio sortedMax=sortrows(RN1L ratioMax)subplot(231)hold onplot(RN1L ratio sortedMax(1)b)plot(RN1L ratio sortedMax(2)g)grid ontitle(RN1L)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)

RN2L ratioMax(1)=RN2L MaxDegreeGRN2L ratioMax(2)=RN2L MaxDegreeG Hat

RN2L ratio sortedMax=sortrows(RN2L ratioMax)subplot(232)

Appendix A 63

hold onplot(RN2L ratio sortedMax(1)b)plot(RN2L ratio sortedMax(2)g)grid ontitle(RN2L)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)

RN3L ratioMax(1)=RN3L MaxDegreeGRN3L ratioMax(2)=RN3L MaxDegreeG Hat

RN3L ratio sortedMax=sortrows(RN3L ratioMax)subplot(233)hold onplot(RN3L ratio sortedMax(1)b)plot(RN3L ratio sortedMax(2)g)grid ontitle(RN3L)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)

RN1S ratioMax(1)=RN1S MaxDegreeGRN1S ratioMax(2)=RN1S MaxDegreeG Hat

RN1S ratio sortedMax=sortrows(RN1S ratioMax)subplot(234)hold onplot(RN1S ratio sortedMax(1)b)plot(RN1S ratio sortedMax(2)g)grid ontitle(RN1S)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)

RN2S ratioMax(1)=RN2S MaxDegreeGRN2S ratioMax(2)=RN2S MaxDegreeG Hat

RN2S ratio sortedMax=sortrows(RN2S ratioMax)

subplot(235)hold onplot(RN2S ratio sortedMax(1)b)plot(RN2S ratio sortedMax(2)g)grid ontitle(RN2S)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)

RN3S ratioMax(1)=RN3S MaxDegreeGRN3S ratioMax(2)=RN3S MaxDegreeG Hat

64 Application

RN3S ratio sortedMax=sortrows(RN3S ratioMax)subplot(236)hold onplot(RN3S ratio sortedMax(1)b)plot(RN3S ratio sortedMax(2)g)grid ontitle(RN1L)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)set(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN7png minusr300)

tilefigs()(h)

Bibliography

[1] C Berge ldquoTWO THEOREMS IN GRAPH THEORYrdquo Proceedings of the NationalAcademy of Sciences of the United States of America vol 43 no 9 pp 842ndash844Sep 1957

[2] L Bui S Sanghavi and R Srikant ldquoDistributed link scheduling with constantoverheadrdquo IEEEACM Trans Netw vol 17 no 5 pp 1467ndash1480 2009

[3] R Duan and S Pettie ldquoLinear-time approximation for maximum weight matchingrdquoJ ACM vol 61 no 1 2014

[4] J Edmonds ldquoPaths trees and flowersrdquo Canadian Journal of Mathematics vol 17pp 449ndash467 1965

[5] J E Hopcroft and R M Karp ldquoAn n52 algorithm for maximum matchings inbipartite graphsrdquo SIAM J Comput vol 2 no 4 pp 225ndash231 1973

[6] S Micali and V V Vazirani ldquoAn O(radic|V ||E|) algorithm for finding maximum

matching in general graphsrdquo in 21st Symp on Foundations of Comp Sc (FOCS)IEEE 1980 pp 17ndash27

[7] N Nisse A Salch and V Weber ldquoRecovery of disrupted airline operationsrdquo 2015httphalinriafrSomething

[8] X Wu and R Srikant ldquoRegulated maximal matching A distributed schedulingalgorithm for multi-hop wireless networks with nodeexclusive spectrum sharingrdquo inIEEE Conf on Decision and Control 2005

65

  • Contents
  • Introduction
  • Algorithms
    • Maximum matching
    • k-maximum matching
      • k-matching for Airport Slot assignment
      • The case where k=3
      • The case of Paths
      • The case of the Spider
          • Application
            • Description
            • Reyni Erdos
            • Barabaacutesi Albert
            • Amadeus Graphs
            • Bipartite
            • Bipartite with degree seq
            • Appendix A
              • BipartiteGraphGeneratorpy
              • RandomGraphGeneratorpy
              • kequals3MaximumMatchingpy
              • Plotmat
                  • Bibliography
Page 23: Theodoros Alexandros KARAGKIOULES -  · Introduction This work is the result of a 6 months internship, under the supervision of research O cer Nicolas NISSE. The original scope of

24 Application

bull For every instance the computation time of the classical algorithm is always smallerto that of the constraint matching

bull This allows as to speculate that we always compute a smaller G which also impliesthat we always find a set of forced edges and useless

Sorted matching size

Sorted matching size - Comments

bull Size of matching has an upward trend since the magnitude of the graphs is notthe same for the 160 instances

bull No significant deviation is noticed as per the first graph

24 Amadeus Graphs 25

bull Except from deviation from the perfect matching (number of flights) where some-times it could get up to 40

bull For the Amadeus Bipartite graphs we can see that the difference of the Classicaland the constraint implementation is not more than 1 edge in the matching

bull There appears to be a difference of up to 24 edges between the Classical matchingand the Perfect matching which is computed as the number of flights

bull The greedy algorithm performs well with only a few instances deviating slightlyform the Constraint algorithm result

Sorted Ratios

Sorted Ratios - Comments

26 Application

bull

Sorted |E||V |

Sorted |E||V | - Comments

bull Density of the graphs shows that on average we have 25-3 available time slot perflight

bull The line for the same value for G shows that there is a large deviation for everyinstance which allows for the hypothesis that the amount of useless+forced edgesof G has no obvious correlation to that of G

25 Bipartite 27

Sorted ∆

Sorted ∆-Comments

bull As per the previous related graphs for ∆ there is in significant drop in the ∆ of Gand G

25 Bipartite

Graph characteristics Bipartite random Graphs

bull BIPxy are randomly generated graphs with a fixed number of 1000(n=500 andm=500) nodes

bull There are 6 categories based on ini matching and probability p

28 Application

bull Probability p has been chosen as such in order to simulate the |E||V | 25 of theAmadeus bipartite graphs

bull So in order to have about 2-4 edges for every node we choose accordingly theprobability p to choose one of the n lowastm possible edges

bull x = L S L When the initial matching is large and S when it is small

bull y = 1 2 3 1 when p = 18250

2 when p = 25250

and 3 when p = 34250

Computation time over

Computation time overedges-Comments

bull

25 Bipartite 29

Sorted matching size

Sorted matching size-Comments

bull In these set of graphs one can instantly notice that only a few instances with highprobability can reach a matching size equal to the perfect matching

bull For the case of the initial matching we witness that there is a gap between the lineof the classical matching and those of the constraint and greedy results suggestingsmaller matching sizes of 10-40 edges

bull For the case of the small initial matching the result of the constraint matchingis now close to the result of the classical matching yet the greedy algorithm stillshows a relevantly big difference

30 Application

bull In this set of bipartite graphs we can witness that the result of the Constraintmatching shows a difference with the classical matching when the initial matchingis large The difference is smaller as the probability gets larger

bull For the case of the small initial matching the above phenomenom does not occuryet the greedy results deviates from that of the constraint matching

bull As per the pefrect matching compared to the classical matching a difference of5-10 edges is evident at almost all cases

Sorted Ratios

Sorted Ratios-Comments

bull Great max degree deviation

25 Bipartite 31

bull Regardless of the probability the ration of nodes and edges seems to have similarbehaviour when compared to the respective graphs of the same matching scale

bull Same gap between nodes ration and edges ration for all cases

Sorted |E||V |

Sorted |E||V | - Comments

bull In these set of figures we witness that the |E||V | acquires values relevant to those ofthe amadeus graphs The random graphs were constructed to depict this similarity

bull For smaller initial matching the ratios for G and G show the same upward trendand also they acquire closer values It represents the decrease of the averagenumber of forced edges in comparison to the larger matching cases

32 Application

Sorted ∆

Sorted ∆-Comments

bull ∆ acquires the same min and max values for each probability case (expected)

bull Gap in the case of large initial matching

26 Bipartite with degree seq

Graph characteristics

bull DEQBIPxy are randomly generated graphs based on three different types of degreedistribution of the Amadeus graphs

26 Bipartite with degree seq 33

bull There are 6 categories based on ini matching and degree distribution

bull x = L S L When the initial matching is large and S when it is small

bull y = 1 2 3 1 when degree distribution is based on file 2 when degree distributionis based on file and 3 when degree distribution is based on file

Computation time over

34 Application

Computation time overedges-Comments

bull Greedy algorithm takes minimum amount of time

bull The smaller the initial matching the more smaller the difference in comoutationtime of Constraint and classical algorithm

bull Due to preprocessing and the fact that G and G are the almost identical thetotal time needed to apply the constraint algorithm is in some cases bigger

Sorted matching size

26 Bipartite with degree seq 35

Sorted matching size-Comments

bull Classical matching is equal to perfect matching in every case

bull Constraint and greedy have identical behaviour

bull The larger the spectrum of the degree sequence the more efficient the matching

Sorted Ratios

36 Application

Sorted Ratios-Comments

bull With large initial matching most of the edges are considenred uselles or forced andare removed thus the ratio is close(if not equal to) zero

bull For small matching and large degree sequence sectrum hte max degree remainsthe same Only a few forced edges (and their nodes) are removed apparently nonodes with max degree

Sorted |E||V |

26 Bipartite with degree seq 37

Sorted |E||V | - Comments

bull In these set of figures we witness that the |E||V | acquires values relevant to those ofthe amadeus graphs The random graphs were constructed to depict this similarity

bull For smaller initial matching the ratios for G and G show the same upward trendand also they acquire closer values It repsresent the decrease of the averagenumber of forced edges in comparison to the larger matching cases

Sorted ∆

38 Application

Sorted ∆-Comments

bull Big difference in max degree in large initial matching

bull Almost identical behaviour in the case of small initial matching

Appendix A 39

Appendix A

BipartiteGraphGeneratorpy

from future import divisionimport networkx as nx

from networkxalgorithms import approximationimport collectionsimport randomimport mathfrom networkxalgorithms import bipartiteif name == main

for i in range(1481)waqs 481index=1n=randomrandint(100 1000)

n1=95 was 500me1=118

n2=251 was 500me2=903

n3=165 was 500me3=412

m=0m1=0p=randomrandom()p1=18250p2=25250p3=34250print ip=05t1=randomrandint(0 1)print im2=randomrandint(n2minus1 n2+1)G = nxGraph()ma = nxGraph()

aseq1=[1 2 3 4 5 3]

bseq1=[4 3 3 1 2 2 1]

aseq2=[16 14 14 14 12 11]bseq2=[0 0 0 0 0 0]

aseq3=[8 7 8 8 8 8]bseq3=[0 0 0 0 0 0]

40 Application

print Gnumber of edges()if ilt=160

G=bipartiteconfiguration model(aseq1 bseq1 create using=None seed=None)A=nxadjacency matrix(G)for ii in range(0n1+me1)

maadd node(ii)A=[Rtodense()tolist()[0] for R in A]

printnummanumber of nodes()rl=randomsample(range(0n1+me1) n1+me1)m=0done vertices = set()for p in rlprintin fordone verticesadd(p)

neighbors = []list()for iii in range(0n1+me1)

if A[p][iii]==1neighborsappend(iii)

randomshuffle(neighbors)continue loop = Truedegree = len(neighbors)

print degreej = 0p4=randomrandom()while continue loop and (jltdegree)print in loop

next = neighbors[j]if next not in done vertices and p not in done vertices

done verticesadd(p)done verticesadd(next)if p4gt=07print added edge

maadd edge(pnext)m=m+1

continue loop = Falsej += 1

print matching listOfedgeprint maedge

MA=nxadjacency matrix(ma)print MA

MA=[Rtodense()tolist()[0] for R in MA]print MA

B=[ join(map(strR)) for R in A]MB=[ join(map(strR)) for R in MA]

C=njoin(B)+nMC=njoin(MB)+n

print nprint mprint m1

filea=str(i)+txtwith open(fileaw) as f

Appendix A 41

fwrite(str(n1+me1))fwrite(n)fwrite(str(n1+me1))fwrite(n)fwrite(str(m))fwrite(n)fwrite(n)fwrite(C)fwrite(n)fwrite(MC)

elif igt160 and ilt321G=bipartiteconfiguration model(aseq2 bseq2 create using=None seed=None)A=nxadjacency matrix(G)for ii in range(0n2+me2)

maadd node(ii)A=[Rtodense()tolist()[0] for R in A]

printnummanumber of nodes()rl=randomsample(range(0n2+me2) n2+me2)m=0done vertices = set()for p in rlprintin fordone verticesadd(p)

neighbors = []list()for iii in range(0n2+me2)

if A[p][iii]==1neighborsappend(iii)

randomshuffle(neighbors)continue loop = Truedegree = len(neighbors)

print degreej = 0p4=randomrandom()while continue loop and (jltdegree)

print in loopnext = neighbors[j]if next not in done vertices and p not in done vertices

done verticesadd(p)done verticesadd(next)if p4gt=07

print added edgemaadd edge(pnext)m=m+1

continue loop = Falsej += 1

print matching listOfedgeprint maedge

MA=nxadjacency matrix(ma)print MA

MA=[Rtodense()tolist()[0] for R in MA]print MA

B=[ join(map(strR)) for R in A]MB=[ join(map(strR)) for R in MA]

42 Application

C=njoin(B)+nMC=njoin(MB)+n

print nprint mprint m1

filea=str(i)+txtwith open(fileaw) as f

fwrite(str(n2+me2))fwrite(n)fwrite(str(n2+me2))fwrite(n)fwrite(str(m))fwrite(n)fwrite(n)fwrite(C)fwrite(n)fwrite(MC)

elseG=bipartiteconfiguration model(aseq3 bseq3 create using=None seed=None)A=nxadjacency matrix(G)for ii in range(0n3+me3)

maadd node(ii)A=[Rtodense()tolist()[0] for R in A]

printnummanumber of nodes()rl=randomsample(range(0n3+me3) n3+me3)m=0done vertices = set()for p in rlprintin fordone verticesadd(p)

neighbors = []list()for iii in range(0n3+me3)

if A[p][iii]==1neighborsappend(iii)

randomshuffle(neighbors)continue loop = Truedegree = len(neighbors)

print degreej = 0p4=randomrandom()while continue loop and (jltdegree)

print in loopnext = neighbors[j]if next not in done vertices and p not in done vertices

done verticesadd(p)done verticesadd(next)if p4gt=07print added edge

maadd edge(pnext)m=m+1

continue loop = Falsej += 1

Appendix A 43

print matching listOfedgeprint maedge

MA=nxadjacency matrix(ma)print MA

MA=[Rtodense()tolist()[0] for R in MA]print MA

B=[ join(map(strR)) for R in A]MB=[ join(map(strR)) for R in MA]

C=njoin(B)+nMC=njoin(MB)+n

print nprint mprint m1

filea=str(i)+txtwith open(fileaw) as f

fwrite(str(n3+me3))fwrite(n)fwrite(str(n3+me3))fwrite(n)fwrite(str(m))fwrite(n)fwrite(n)fwrite(C)fwrite(n)fwrite(MC)

print nRandom graphs with random matching have been generated

44 Application

RandomGraphGeneratorpy

from future import divisionimport networkx as nxfrom networkxalgorithms import approximationimport collectionsimport randomimport mathif name == main

for i in range(1481)index=1n=randomrandint(100 1000)

n=1000m=0m1=0p=randomrandom()p1=mathlog(n2)np2=13p3=mathlog(n2)n+01p=05t1=randomrandint(0 1)print im2=randomrandint(n2minus1 n2+1)G = nxGraph()ma = nxGraph()print nme1=randomrandint(1 10)me2=randomrandint(2050)me3=randomrandint(50100)if ilt241

if ilt=80G=nxfast gnp random graph(n p1 seed=None directed=False)

elif igt80 and ilt161G=nxfast gnp random graph(n p2 seed=None directed=False)

elseG=nxfast gnp random graph(n p3 seed=None directed=False)

elseif ilt=320

G=nxbarabasi albert graph(n me1 seed=None)elif igt320 and ilt401

G=nxbarabasi albert graph(n me2 seed=None)else

G=nxbarabasi albert graph(n me3 seed=None)A=nxadjacency matrix(G)for ii in range(0n)

maadd node(ii)A=[Rtodense()tolist()[0] for R in A]

rl=randomsample(range(0n) n)m=0

Appendix A 45

done vertices = set()for p in rl

done verticesadd(p)neighbors = []list()for iii in range(0n)

if A[p][iii]==1neighborsappend(iii)

randomshuffle(neighbors)continue loop = Truedegree = len(neighbors)j = 0p2=randomrandom()while continue loop and (jltdegree)

next = neighbors[j]if next not in done vertices and p not in done vertices

done verticesadd(p)done verticesadd(next)if p2gt=00 Larger probability for smaller initial matching

maadd edge(pnext)m=m+1

continue loop = Falsej += 1

print matching listOfedgeprint maedgeMA=nxadjacency matrix(ma)MA=[Rtodense()tolist()[0] for R in MA]print MAB=[ join(map(strR)) for R in A]MB=[ join(map(strR)) for R in MA]

C=njoin(B)+nMC=njoin(MB)+nprint MCprint nprint mprint m1filea=str(i)+txtwith open(fileaw) as f

fwrite(str(n))fwrite(n)fwrite(str(n))fwrite(n)fwrite(str(m))fwrite(n)fwrite(n)fwrite(C)fwrite(n)fwrite(MC)

print nRandom graphs with random matching have been generated

46 Application

kequals3MaximumMatchingpy

from future import divisionimport networkx as nxfrom networkxalgorithms import bipartiteimport matplotlibpyplot as pltimport collectionsimport timeitimport xlwtimport xlrdimport mathimport sys

Case for General Graphsdef forced edges(Gadj dict2matching dict1num nodesforced)

flagg=0for n in range(0num nodes)

for k in adj dict2[n]if ([k]==matching dict1[n])

count=0for l in range(0num nodes)

count=count+adj dict2[l]count(k)if (len(adj dict2[n])==1) or (count==1)

forcedadd edge(nk)Gremove edge(nk)Gremove node(n)Gremove node(k)printforced edgenktemp=kflagg=1for m in range (len(adj dict2[n])minus1minus1minus1)

adj dict2[adj dict2[n][m]]remove(n)adj dict2[n]remove(adj dict2[n][m])

if adj dict2[temp]for l in range(len(adj dict2[temp])minus1minus1minus1)

if (adj dict2[temp][l]=n)adj dict2[adj dict2[temp][l]]remove(temp)adj dict2[temp]remove(adj dict2[temp][l])

break

def useless edges(num nodesadj dict1matching dict1uselessadj dict2G)for n in range(0num nodes)

for k in adj dict1[n]if ([k]=matching dict1[n]) and matching dict1[n] and matching dict1[k]

uselessadd edge(nk)Gremove edge(n k)

Appendix A 47

tempa=kadj dict2[n]remove(k)adj dict2[tempa]remove(n)adj dict1[tempa]remove(n)

return G

def Greedy(num nodesadj dict3matching dict2)

for n in range(0num nodes)if matching dict2[n]

flag2=minus1flag3=minus1for v in adj dict3[n]

if not matching dict2[v]flag2=vbreak

for p in adj dict3[matching dict2[n][0]]if not matching dict2[p]

flag3=pbreak

if (flag2=minus1) and (flag3=minus1) and (flag2=flag3)tempr=matching dict2[n][0]matching dict2[n]=[flag2]matching dict2[flag2]=[n]matching dict2[tempr]=[flag3]matching dict2[flag3]=[tempr]

elsefor k in adj dict3[n]

if not matching dict2[k]matching dict2[n]=[k]matching dict2[k]=[n]break

yo1=0for i in range(0num nodes)

if matching dict2[i] and [i]==matching dict2[matching dict2[i][0]]yo1=yo1+1

greedy size=yo12return greedy size

def General()

INPUTSwb = xlwtWorkbook()ws = wbadd sheet(Results Random)book=xlrdopen workbook(filenames randomxls)

48 Application

style0 = xlwteasyxf(fontbold on)style1 = xlwteasyxf(num format str=0000)INPUTSwswrite(0 0File style0)wswrite(0 1 Nodesstyle0)wswrite(0 2 Initial matchingstyle0)wswrite(0 3 NodesGstyle0)wswrite(0 4 EdgesGstyle0)wswrite(0 5 MaxDegreeGstyle0)wswrite(0 6 NodesG hatstyle0)wswrite(0 7 EdgesG Hatstyle0)wswrite(0 8 Useless edgesstyle0)wswrite(0 9 Forced edgesstyle0)wswrite(0 10 MaxDegreeG Hatstyle0)wswrite(0 11 Classical matchingstyle0)wswrite(0 12 Final matchingstyle0)wswrite(0 13 Greedy matchingstyle0)wswrite(0 14 Time classicalstyle0)wswrite(0 15 Time algorithmstyle0)wswrite(0 16 Time greedystyle0)wswrite(0 17 Perfect matching ratiostyle0)wswrite(0 18 Nodes ratiostyle0)wswrite(0 19 Edges ratiostyle0)wswrite(0 20 Matching ratiostyle0)

print nWelcomeThis is an implementation for general random graphs It uses Edmonds algorithm to compute maximum matching on G Hatn

for index in range (1481)was 481

if (index==482)f=open(Algotel generaltxtr)readlines()

elsefilea=str(booksheet by index(0)cell(index0))s=fileareplace(textu)replace()f=open(sr)readlines()Truewswrite(index 0 s)

print index

num nodes=int([xstrip()split() for x in f][0][0])

num matching=int([xstrip()split() for x in f][2][0])

adj temp = [xstrip()split() for x in f][44+num nodes]adj=[map(intR) for R in adj temp]

matching temp=[xstrip()split() for x in f][4+num nodes+14+2num nodes+1]matching1=[map(intR) for R in matching temp]

adj dict1=i[ii for iix in enumerate(L) if x] for iL in enumerate(adj)adj dict2=i[ii for iix in enumerate(L) if x] for iL in enumerate(adj)

Appendix A 49

adj dict3=i[ii for iix in enumerate(L) if x] for iL in enumerate(adj)

matching dict1=i[ii for iix in enumerate(L) if x] for iL in enumerate(matching1)matching dict2=i[ii for iix in enumerate(L) if x] for iL in enumerate(matching1)print adj dict2print matching dict2wswrite(index 1 num nodes)wswrite(index 2 num matching)

G = nxGraph()

useless= nxGraph()forced = nxGraph()

Fill Graphfor n in range(0num nodes)

for k in adj dict1[n]Gadd edge(nk)

Gt=Gnumber of edges()wswrite(index 3 Gnumber of nodes())wswrite(index 4 Gnumber of edges())wswrite(index 5 max(Gdegree()values()))

Compute Edmonds classical matching on G for comparison

startB = timeitdefault timer()Classical Matching=nxmax weight matching(G maxcardinality=False)stopB = timeitdefault timer()

Compute Gˆ nad MˆstartC = timeitdefault timer()useless edges(num nodesadj dict1matching dict1uselessadj dict2G)forced edges(Gadj dict2matching dict1num nodesforced)Final Matching=nxmax weight matching(G maxcardinality=False)stopC = timeitdefault timer()

GreedystartG = timeitdefault timer()greedy size=Greedy(num nodesadj dict3matching dict2)stopG = timeitdefault timer()

wswrite(index 6 Gnumber of nodes())wswrite(index 7 Gnumber of edges())wswrite(index 8 uselessnumber of edges())wswrite(index 9 forcednumber of edges())if Gdegree()values()

wswrite(index 10 max(Gdegree()values()))else

50 Application

wswrite(index 10 0)wswrite(index 11 len(Classical Matching)2)wswrite(index 12 len(Final Matching)2+forcednumber of edges())wswrite(index 13 greedy size)wswrite(index 14 stopB minus startBstyle1)wswrite(index 15 stopC minus startCstyle1)wswrite(index 16 stopG minus startGstyle1)wswrite(index 17 (len(Final Matching)2+forcednumber of edges())(num nodes2)style1)wswrite(index 18 Gnumber of nodes()Gtstyle1)wswrite(index 19 Gnumber of edges()Gtstyle1)wswrite(index 20 (len(Final Matching)2+forcednumber of edges())(len(Classical Matching)2)style1)

wbsave(AA Results Random Reyni Large Bipartitexls)

Main function Here we must choose the input form of the dataif name == main

startA = timeitdefault timer()General()stopA = timeitdefault timer()

print nThis program has terminatednnRunning time for 480 files stopAminusstartAprint nnPlease open AA Results Random Reyni Largexls file to see the Results

Appendix A 51

Plotmat

clear allclose allload(RN1Lmat)load(RN1Smat)load(RN2Lmat)load(RN2Smat)load(RN3Lmat)load(RN3Smat)

Plotsh(1)=figure(NameHistogram of Matching size difference between Constraint Algorithm and Greedy AlgorithmNumberTitleoff)

RN1L Greedydiff=RN1L Final matchingminusRN1L Greedy matchingRN2L Greedydiff=RN2L Final matchingminusRN2L Greedy matchingRN3L Greedydiff=RN3L Final matchingminusRN3L Greedy matchingRN1S Greedydiff=RN1S Final matchingminusRN1S Greedy matchingRN2S Greedydiff=RN2S Final matchingminusRN2S Greedy matchingRN3S Greedydiff=RN3S Final matchingminusRN3S Greedy matching

RN1L Finaldiff=RN1L Classical matchingminusRN1L Final matchingRN2L Finaldiff=RN2L Classical matchingminusRN2L Final matchingRN3L Finaldiff=RN3L Classical matchingminusRN3L Final matchingRN1S Finaldiff=RN1S Classical matchingminusRN1S Final matchingRN2S Finaldiff=RN2S Classical matchingminusRN2S Final matchingRN3S Finaldiff=RN3S Classical matchingminusRN3S Final matching

RN1L Classicaldiff=(RN1L Nodes2)minusRN1L Classical matchingRN2L Classicaldiff=(RN2L Nodes2)minusRN2L Classical matchingRN3L Classicaldiff=(RN3L Nodes2)minusRN3L Classical matchingRN1S Classicaldiff=(RN1S Nodes2)minusRN1S Classical matchingRN2S Classicaldiff=(RN2S Nodes2)minusRN2S Classical matchingRN3S Classicaldiff=(RN3S Nodes2)minusRN3S Classical matching

subplot(231)hold onhistf(RN1L Greedydiff0110facecolorbfacealpha9edgealpha1)histf(RN1L Finaldiff0110facecolorrfacealpha5edgealpha1)histf(RN1L Classicaldiff0110facecolorgfacealpha5edgealpha1)legalpha(ConminusGreClasminusConPerfminusClasslocationnortheast)legend boxoffaxis tightxlabel(edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN1L)grid on

subplot(232)hold onhistf(RN2L Greedydiff0110facecolorbfacealpha9edgealpha1)

52 Application

histf(RN2L Finaldiff0110facecolorrfacealpha5edgealpha1)histf(RN2L Classicaldiff0110facecolorgfacealpha5edgealpha1)legalpha(ConminusGreClasminusConPerfminusClasslocationnortheast)legend boxoffaxis tightxlabel(edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN2L)grid on

subplot(233)hold onhistf(RN3L Greedydiff0110facecolorbfacealpha5edgealpha1)histf(RN3L Finaldiff0110facecolorrfacealpha5edgealpha1)histf(RN3L Classicaldiff0110facecolorgfacealpha5edgealpha1)legalpha(ConminusGreClasminusConPerfminusClasslocationnortheast)legend boxoffaxis tightxlabel(edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN3L)grid on

subplot(234)hold onhistf(RN1S Greedydiff0110facecolorbfacealpha5edgealpha1)histf(RN1S Finaldiff0110facecolorrfacealpha5edgealpha1)histf(RN1S Classicaldiff0110facecolorgfacealpha5edgealpha1)legalpha(ConminusGreClasminusConPerfminusClasslocationnortheast)legend boxoffaxis tightxlabel(edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(R1NS)grid on

subplot(235)hold onhistf(RN2S Greedydiff0110facecolorbfacealpha5edgealpha1)histf(RN2S Finaldiff0110facecolorrfacealpha5edgealpha1)histf(RN2S Classicaldiff0110facecolorgfacealpha5edgealpha1)legalpha(ConminusGreClasminusConPerfminusClasslocationnortheast)legend boxoffaxis tightxlabel(edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN2S)grid on

subplot(236)hold onhistf(RN3S Greedydiff0110facecolorbfacealpha5edgealpha1)histf(RN3S Finaldiff0110facecolorrfacealpha5edgealpha1)histf(RN3S Classicaldiff0110facecolorgfacealpha5edgealpha1)

Appendix A 53

legalpha(ConminusGreClasminusConPerfminusClasslocationnortheast)legend boxoffaxis tightgrid ontitle(RN3S)xlabel(edges) xminusaxis labelylabel(instances) yminusaxis labelset(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN1png minusr300)h(2)=figure(NameHistogram of Max Degree of G AND G HatNumberTitleoff)RN1L x=RN1L MaxDegreeGminusRN1L MaxDegreeG HatRN2L x=RN2L MaxDegreeGminusRN2L MaxDegreeG HatRN3L x=RN3L MaxDegreeGminusRN3L MaxDegreeG HatRN1S x=RN1S MaxDegreeGminusRN1S MaxDegreeG HatRN2S x=RN2S MaxDegreeGminusRN2S MaxDegreeG HatRN3S x=RN3S MaxDegreeGminusRN3S MaxDegreeG Hatsubplot(231)hold onhistf(RN1L MaxDegreeG0150facecolorbfacealpha5edgealpha1)histf(RN1L MaxDegreeG Hat0150facecolorrfacealpha5edgealpha1)histf(RN1L x0150facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightxlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN1L)grid on

subplot(232)hold onhistf(RN2L MaxDegreeG010500facecolorbfacealpha5edgealpha1)histf(RN2L MaxDegreeG Hat010500facecolorrfacealpha5edgealpha1)histf(RN2L x010500facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightxlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN2L)grid on

subplot(233)hold onhistf(RN3L MaxDegreeG010300facecolorbfacealpha5edgealpha1)histf(RN3L MaxDegreeG Hat010300facecolorrfacealpha5edgealpha1)histf(RN3L x010300facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightxlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN3L)

54 Application

grid on

subplot(234)hold onhistf(RN1S MaxDegreeG0150facecolorbfacealpha5edgealpha1)histf(RN1S MaxDegreeG Hat0150facecolorrfacealpha5edgealpha1)histf(RN1S x0150facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightxlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(R1NS)grid on

subplot(235)hold onhistf(RN2S MaxDegreeG010500facecolorbfacealpha5edgealpha1)histf(RN2S MaxDegreeG Hat010500facecolorrfacealpha5edgealpha1)histf(RN2S x010500facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightxlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN2S)grid on

subplot(236)hold onhistf(RN3S MaxDegreeG05300facecolorbfacealpha5edgealpha1)histf(RN3S MaxDegreeG Hat05300facecolorrfacealpha5edgealpha1)histf(RN3S x05300facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightgrid ontitle(RN3S)xlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labelset(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN2png minusr300)

h(3)=figure(NameComputation time over edgesNumberTitleoff)

subplot(231)hold onstem(RN1L EdgesGRN1L Time classicalg)stem(RN1L EdgesGRN1L Time algorithmro)stem(RN1L EdgesGRN1L Time greedybx)grid on

Appendix A 55

title(RN1L)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)

subplot(232)hold onstem(RN2L EdgesGRN2L Time classicalg)stem(RN2L EdgesGRN2L Time algorithmro)stem(RN2L EdgesGRN2L Time greedybx)grid ontitle(RN2L)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)

subplot(233)hold onstem(RN3L EdgesGRN3L Time classicalg)stem(RN3L EdgesGRN3L Time algorithmro)stem(RN3L EdgesGRN3L Time greedybx)grid ontitle(RN3L)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)

subplot(234)hold onstem(RN1S EdgesGRN1S Time classicalg)stem(RN1S EdgesGRN1S Time algorithmro)stem(RN1S EdgesGRN1S Time greedybx)grid ontitle(RN1S)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)

subplot(235)hold onstem(RN2S EdgesGRN2S Time classicalg)stem(RN2S EdgesGRN2S Time algorithmro)stem(RN2S EdgesGRN2S Time greedybx)grid ontitle(RN2S)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)

subplot(236)hold onstem(RN3S EdgesGRN3S Time classicalg)stem(RN3S EdgesGRN3S Time algorithmro)stem(RN3S EdgesGRN3S Time greedybx)

56 Application

grid ontitle(RN3S)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)set(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN3png minusr300)

h(4)=figure(NameSorted matching sizeNumberTitleoff)RN1L Sorted matching temp(1)=RN1L Classical matchingRN1L Sorted matching temp(2)=RN1L Final matchingRN1L Sorted matching temp(3)=RN1L Greedy matchingRN1L Sorted matching temp(4)=RN1L Initial matchingRN1L Sorted matching=sortrows(RN1L Sorted matching temp)

RN2L Sorted matching temp(1)=RN2L Classical matchingRN2L Sorted matching temp(2)=RN2L Final matchingRN2L Sorted matching temp(3)=RN2L Greedy matchingRN2L Sorted matching temp(4)=RN2L Initial matchingRN2L Sorted matching=sortrows(RN2L Sorted matching temp)

RN3L Sorted matching temp(1)=RN3L Classical matchingRN3L Sorted matching temp(2)=RN3L Final matchingRN3L Sorted matching temp(3)=RN3L Greedy matchingRN3L Sorted matching temp(4)=RN3L Initial matchingRN3L Sorted matching=sortrows(RN3L Sorted matching temp)

RN1S Sorted matching temp(1)=RN1S Classical matchingRN1S Sorted matching temp(2)=RN1S Final matchingRN1S Sorted matching temp(3)=RN1S Greedy matchingRN1S Sorted matching temp(4)=RN1S Initial matchingRN1S Sorted matching=sortrows(RN1S Sorted matching temp)

RN2S Sorted matching temp(1)=RN2S Classical matchingRN2S Sorted matching temp(2)=RN2S Final matchingRN2S Sorted matching temp(3)=RN2S Greedy matchingRN2S Sorted matching temp(4)=RN2S Initial matchingRN2S Sorted matching=sortrows(RN2S Sorted matching temp)

RN3S Sorted matching temp(1)=RN3S Classical matchingRN3S Sorted matching temp(2)=RN3S Final matchingRN3S Sorted matching temp(3)=RN3S Greedy matchingRN3S Sorted matching temp(4)=RN3S Initial matchingRN3S Sorted matching=sortrows(RN3S Sorted matching temp)

subplot(231)hold onplot(RN1L Sorted matching(1)b)plot(RN1L Sorted matching(2)g)plot(RN1L Sorted matching(3)r)plot(RN1L Sorted matching(4)m)

Appendix A 57

grid ontitle(RN1L)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)

subplot(232)hold onplot(RN2L Sorted matching(1)b)plot(RN2L Sorted matching(2)g)plot(RN2L Sorted matching(3)r)plot(RN2L Sorted matching(4)m)grid ontitle(RN2L)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)

subplot(233)hold onplot(RN3L Sorted matching(1)b)plot(RN3L Sorted matching(2)g)plot(RN3L Sorted matching(3)r)plot(RN3L Sorted matching(4)m)grid ontitle(RN3L)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)

subplot(234)hold onplot(RN1S Sorted matching(1)b)plot(RN1S Sorted matching(2)g)plot(RN1S Sorted matching(3)r)plot(RN1S Sorted matching(4)m)grid ontitle(RN1S)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)

subplot(235)hold onplot(RN2S Sorted matching(1)b)plot(RN2S Sorted matching(2)g)plot(RN2S Sorted matching(3)r)plot(RN2S Sorted matching(4)m)grid ontitle(RN2S)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)

58 Application

subplot(236)hold onplot(RN3S Sorted matching(1)b)plot(RN3S Sorted matching(2)g)plot(RN3S Sorted matching(3)r)plot(RN3S Sorted matching(4)m)grid ontitle(RN3S)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)set(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN4png minusr300)h(5)=figure(NameSorted RatiosNumberTitleoff)RN1L ratio1=RN1L NodesG hatRN1L NodesGRN2L ratio1=RN2L NodesG hatRN2L NodesGRN3L ratio1=RN3L NodesG hatRN3L NodesGRN1S ratio1=RN1S NodesG hatRN1S NodesGRN2S ratio1=RN2S NodesG hatRN2S NodesGRN3S ratio1=RN3S NodesG hatRN3S NodesG

RN1L ratio2=RN1L EdgesG HatRN1L EdgesGRN2L ratio2=RN2L EdgesG HatRN2L EdgesGRN3L ratio2=RN3L EdgesG HatRN3L EdgesGRN1S ratio2=RN1S EdgesG HatRN1S EdgesGRN2S ratio2=RN2S EdgesG HatRN2S EdgesGRN3S ratio2=RN3S EdgesG HatRN3S EdgesG

RN1L ratio3=RN1L MaxDegreeG HatRN1L MaxDegreeGRN2L ratio3=RN2L MaxDegreeG HatRN2L MaxDegreeGRN3L ratio3=RN3L MaxDegreeG HatRN3L MaxDegreeGRN1S ratio3=RN1S MaxDegreeG HatRN1S MaxDegreeGRN2S ratio3=RN2S MaxDegreeG HatRN2S MaxDegreeGRN3S ratio3=RN3S MaxDegreeG HatRN3S MaxDegreeG

RN1L ratio(1)=RN1L ratio1RN1L ratio(2)=RN1L ratio2RN1L ratio(3)=RN1L ratio3

RN2L ratio(1)=RN2L ratio1RN2L ratio(2)=RN2L ratio2RN2L ratio(3)=RN2L ratio3

RN3L ratio(1)=RN3L ratio1RN3L ratio(2)=RN3L ratio2RN3L ratio(3)=RN3L ratio3

RN1S ratio(1)=RN1S ratio1RN1S ratio(2)=RN1S ratio2RN1S ratio(3)=RN1S ratio3

RN2S ratio(1)=RN2S ratio1

Appendix A 59

RN2S ratio(2)=RN2S ratio2RN2S ratio(3)=RN2S ratio3

RN3S ratio(1)=RN3S ratio1RN3S ratio(2)=RN3S ratio2RN3S ratio(3)=RN3S ratio3

RN1L ratio sorted=sortrows(RN1L ratio)RN2L ratio sorted=sortrows(RN2L ratio)RN3L ratio sorted=sortrows(RN3L ratio)RN1S ratio sorted=sortrows(RN1S ratio)RN2S ratio sorted=sortrows(RN2S ratio)RN3S ratio sorted=sortrows(RN3S ratio)

subplot(231)hold onplot(RN1L ratio sorted(1)b)plot(RN1L ratio sorted(2)g)plot(RN1L ratio sorted(3)r)grid ontitle(RN1L)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)

subplot(232)hold onplot(RN2L ratio sorted(1)b)plot(RN2L ratio sorted(2)g)plot(RN2L ratio sorted(3)r)grid ontitle(RN2L)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)

subplot(233)hold onplot(RN3L ratio sorted(1)b)plot(RN3L ratio sorted(2)g)plot(RN3L ratio sorted(3)r)grid ontitle(RN3L)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)

subplot(234)hold onplot(RN1S ratio sorted(1)b)plot(RN1S ratio sorted(2)g)plot(RN1S ratio sorted(3)r)grid on

60 Application

title(RN1S)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)

subplot(235)hold onplot(RN2S ratio sorted(1)b)plot(RN2S ratio sorted(2)g)plot(RN2S ratio sorted(3)r)grid ontitle(RN2S)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)

subplot(236)hold onplot(RN3S ratio sorted(1)b)plot(RN3S ratio sorted(2)g)plot(RN3S ratio sorted(3)r)grid ontitle(RN3S)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)set(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN5png minusr300)

h(6)=figure(NameSorted edges over nodesNumberTitleoff)

RN1L DegreeG1=(RN1L EdgesG)(RN1L NodesG)RN1L DegreeG Hat1=(RN1L EdgesG Hat)(RN1L NodesG hat)

RN1L Degree temp1(1)=RN1L DegreeG1RN1L Degree temp1(2)=RN1L DegreeG Hat1RN1L Degree sorted1=sortrows(RN1L Degree temp1)subplot(231)hold on

plot(RN1L Degree sorted1(1)b)plot(RN1L Degree sorted1(2)g)grid ontitle(RN1L)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)

RN2L DegreeG1=(RN2L EdgesG)(RN2L NodesG)RN2L DegreeG Hat1=(RN2L EdgesG Hat)(RN2L NodesG hat)

RN2L Degree temp1(1)=RN2L DegreeG1

Appendix A 61

RN2L Degree temp1(2)=RN2L DegreeG Hat1RN2L Degree sorted1=sortrows(RN2L Degree temp1)

subplot(232)hold onplot(RN2L Degree sorted1(1)b)plot(RN2L Degree sorted1(2)g)grid ontitle(RN2L)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)

RN3L DegreeG1=(RN3L EdgesG)(RN3L NodesG)RN3L DegreeG Hat1=(RN3L EdgesG Hat)(RN3L NodesG hat)

RN3L Degree temp1(1)=RN3L DegreeG1RN3L Degree temp1(2)=RN3L DegreeG Hat1RN3L Degree sorted1=sortrows(RN3L Degree temp1)

subplot(233)hold onplot(RN3L Degree sorted1(1)b)plot(RN3L Degree sorted1(2)g)grid ontitle(RN3L)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)

RN1S DegreeG1=(RN1S EdgesG)(RN1S NodesG)RN1S DegreeG Hat1=(RN1S EdgesG Hat)(RN1S NodesG hat)

RN1S Degree temp1(1)=RN1S DegreeG1RN1S Degree temp1(2)=RN1S DegreeG Hat1RN1S Degree sorted1=sortrows(RN1S Degree temp1)

subplot(234)hold onplot(RN1S Degree sorted1(1)b)plot(RN1S Degree sorted1(2)g)grid ontitle(RN1S)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)

RN2S DegreeG1=(RN2S EdgesG)(RN2S NodesG)RN2S DegreeG Hat1=(RN2S EdgesG Hat)(RN2S NodesG hat)

RN2S Degree temp1(1)=RN2S DegreeG1

62 Application

RN2S Degree temp1(2)=RN2S DegreeG Hat1RN2S Degree sorted1=sortrows(RN2S Degree temp1)

subplot(235)hold onplot(RN2S Degree sorted1(1)b)plot(RN2S Degree sorted1(2)g)grid ontitle(RN2S)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)

RN3S DegreeG1=(RN3S EdgesG)(RN3S NodesG)RN3S DegreeG Hat1=(RN3S EdgesG Hat)(RN3S NodesG hat)

RN3S Degree temp1(1)=RN3S DegreeG1RN3S Degree temp1(2)=RN3S DegreeG Hat1RN3S Degree sorted1=sortrows(RN3S Degree temp1)

subplot(236)hold onplot(RN3S Degree sorted1(1)b)plot(RN3S Degree sorted1(2)g)grid ontitle(RN3S)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)set(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN6png minusr300)h(7)=figure(NameSorted mATCHED DEGREENumberTitleoff)RN1L ratioMax(1)=RN1L MaxDegreeGRN1L ratioMax(2)=RN1L MaxDegreeG Hat

RN1L ratio sortedMax=sortrows(RN1L ratioMax)subplot(231)hold onplot(RN1L ratio sortedMax(1)b)plot(RN1L ratio sortedMax(2)g)grid ontitle(RN1L)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)

RN2L ratioMax(1)=RN2L MaxDegreeGRN2L ratioMax(2)=RN2L MaxDegreeG Hat

RN2L ratio sortedMax=sortrows(RN2L ratioMax)subplot(232)

Appendix A 63

hold onplot(RN2L ratio sortedMax(1)b)plot(RN2L ratio sortedMax(2)g)grid ontitle(RN2L)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)

RN3L ratioMax(1)=RN3L MaxDegreeGRN3L ratioMax(2)=RN3L MaxDegreeG Hat

RN3L ratio sortedMax=sortrows(RN3L ratioMax)subplot(233)hold onplot(RN3L ratio sortedMax(1)b)plot(RN3L ratio sortedMax(2)g)grid ontitle(RN3L)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)

RN1S ratioMax(1)=RN1S MaxDegreeGRN1S ratioMax(2)=RN1S MaxDegreeG Hat

RN1S ratio sortedMax=sortrows(RN1S ratioMax)subplot(234)hold onplot(RN1S ratio sortedMax(1)b)plot(RN1S ratio sortedMax(2)g)grid ontitle(RN1S)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)

RN2S ratioMax(1)=RN2S MaxDegreeGRN2S ratioMax(2)=RN2S MaxDegreeG Hat

RN2S ratio sortedMax=sortrows(RN2S ratioMax)

subplot(235)hold onplot(RN2S ratio sortedMax(1)b)plot(RN2S ratio sortedMax(2)g)grid ontitle(RN2S)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)

RN3S ratioMax(1)=RN3S MaxDegreeGRN3S ratioMax(2)=RN3S MaxDegreeG Hat

64 Application

RN3S ratio sortedMax=sortrows(RN3S ratioMax)subplot(236)hold onplot(RN3S ratio sortedMax(1)b)plot(RN3S ratio sortedMax(2)g)grid ontitle(RN1L)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)set(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN7png minusr300)

tilefigs()(h)

Bibliography

[1] C Berge ldquoTWO THEOREMS IN GRAPH THEORYrdquo Proceedings of the NationalAcademy of Sciences of the United States of America vol 43 no 9 pp 842ndash844Sep 1957

[2] L Bui S Sanghavi and R Srikant ldquoDistributed link scheduling with constantoverheadrdquo IEEEACM Trans Netw vol 17 no 5 pp 1467ndash1480 2009

[3] R Duan and S Pettie ldquoLinear-time approximation for maximum weight matchingrdquoJ ACM vol 61 no 1 2014

[4] J Edmonds ldquoPaths trees and flowersrdquo Canadian Journal of Mathematics vol 17pp 449ndash467 1965

[5] J E Hopcroft and R M Karp ldquoAn n52 algorithm for maximum matchings inbipartite graphsrdquo SIAM J Comput vol 2 no 4 pp 225ndash231 1973

[6] S Micali and V V Vazirani ldquoAn O(radic|V ||E|) algorithm for finding maximum

matching in general graphsrdquo in 21st Symp on Foundations of Comp Sc (FOCS)IEEE 1980 pp 17ndash27

[7] N Nisse A Salch and V Weber ldquoRecovery of disrupted airline operationsrdquo 2015httphalinriafrSomething

[8] X Wu and R Srikant ldquoRegulated maximal matching A distributed schedulingalgorithm for multi-hop wireless networks with nodeexclusive spectrum sharingrdquo inIEEE Conf on Decision and Control 2005

65

  • Contents
  • Introduction
  • Algorithms
    • Maximum matching
    • k-maximum matching
      • k-matching for Airport Slot assignment
      • The case where k=3
      • The case of Paths
      • The case of the Spider
          • Application
            • Description
            • Reyni Erdos
            • Barabaacutesi Albert
            • Amadeus Graphs
            • Bipartite
            • Bipartite with degree seq
            • Appendix A
              • BipartiteGraphGeneratorpy
              • RandomGraphGeneratorpy
              • kequals3MaximumMatchingpy
              • Plotmat
                  • Bibliography
Page 24: Theodoros Alexandros KARAGKIOULES -  · Introduction This work is the result of a 6 months internship, under the supervision of research O cer Nicolas NISSE. The original scope of

24 Amadeus Graphs 25

bull Except from deviation from the perfect matching (number of flights) where some-times it could get up to 40

bull For the Amadeus Bipartite graphs we can see that the difference of the Classicaland the constraint implementation is not more than 1 edge in the matching

bull There appears to be a difference of up to 24 edges between the Classical matchingand the Perfect matching which is computed as the number of flights

bull The greedy algorithm performs well with only a few instances deviating slightlyform the Constraint algorithm result

Sorted Ratios

Sorted Ratios - Comments

26 Application

bull

Sorted |E||V |

Sorted |E||V | - Comments

bull Density of the graphs shows that on average we have 25-3 available time slot perflight

bull The line for the same value for G shows that there is a large deviation for everyinstance which allows for the hypothesis that the amount of useless+forced edgesof G has no obvious correlation to that of G

25 Bipartite 27

Sorted ∆

Sorted ∆-Comments

bull As per the previous related graphs for ∆ there is in significant drop in the ∆ of Gand G

25 Bipartite

Graph characteristics Bipartite random Graphs

bull BIPxy are randomly generated graphs with a fixed number of 1000(n=500 andm=500) nodes

bull There are 6 categories based on ini matching and probability p

28 Application

bull Probability p has been chosen as such in order to simulate the |E||V | 25 of theAmadeus bipartite graphs

bull So in order to have about 2-4 edges for every node we choose accordingly theprobability p to choose one of the n lowastm possible edges

bull x = L S L When the initial matching is large and S when it is small

bull y = 1 2 3 1 when p = 18250

2 when p = 25250

and 3 when p = 34250

Computation time over

Computation time overedges-Comments

bull

25 Bipartite 29

Sorted matching size

Sorted matching size-Comments

bull In these set of graphs one can instantly notice that only a few instances with highprobability can reach a matching size equal to the perfect matching

bull For the case of the initial matching we witness that there is a gap between the lineof the classical matching and those of the constraint and greedy results suggestingsmaller matching sizes of 10-40 edges

bull For the case of the small initial matching the result of the constraint matchingis now close to the result of the classical matching yet the greedy algorithm stillshows a relevantly big difference

30 Application

bull In this set of bipartite graphs we can witness that the result of the Constraintmatching shows a difference with the classical matching when the initial matchingis large The difference is smaller as the probability gets larger

bull For the case of the small initial matching the above phenomenom does not occuryet the greedy results deviates from that of the constraint matching

bull As per the pefrect matching compared to the classical matching a difference of5-10 edges is evident at almost all cases

Sorted Ratios

Sorted Ratios-Comments

bull Great max degree deviation

25 Bipartite 31

bull Regardless of the probability the ration of nodes and edges seems to have similarbehaviour when compared to the respective graphs of the same matching scale

bull Same gap between nodes ration and edges ration for all cases

Sorted |E||V |

Sorted |E||V | - Comments

bull In these set of figures we witness that the |E||V | acquires values relevant to those ofthe amadeus graphs The random graphs were constructed to depict this similarity

bull For smaller initial matching the ratios for G and G show the same upward trendand also they acquire closer values It represents the decrease of the averagenumber of forced edges in comparison to the larger matching cases

32 Application

Sorted ∆

Sorted ∆-Comments

bull ∆ acquires the same min and max values for each probability case (expected)

bull Gap in the case of large initial matching

26 Bipartite with degree seq

Graph characteristics

bull DEQBIPxy are randomly generated graphs based on three different types of degreedistribution of the Amadeus graphs

26 Bipartite with degree seq 33

bull There are 6 categories based on ini matching and degree distribution

bull x = L S L When the initial matching is large and S when it is small

bull y = 1 2 3 1 when degree distribution is based on file 2 when degree distributionis based on file and 3 when degree distribution is based on file

Computation time over

34 Application

Computation time overedges-Comments

bull Greedy algorithm takes minimum amount of time

bull The smaller the initial matching the more smaller the difference in comoutationtime of Constraint and classical algorithm

bull Due to preprocessing and the fact that G and G are the almost identical thetotal time needed to apply the constraint algorithm is in some cases bigger

Sorted matching size

26 Bipartite with degree seq 35

Sorted matching size-Comments

bull Classical matching is equal to perfect matching in every case

bull Constraint and greedy have identical behaviour

bull The larger the spectrum of the degree sequence the more efficient the matching

Sorted Ratios

36 Application

Sorted Ratios-Comments

bull With large initial matching most of the edges are considenred uselles or forced andare removed thus the ratio is close(if not equal to) zero

bull For small matching and large degree sequence sectrum hte max degree remainsthe same Only a few forced edges (and their nodes) are removed apparently nonodes with max degree

Sorted |E||V |

26 Bipartite with degree seq 37

Sorted |E||V | - Comments

bull In these set of figures we witness that the |E||V | acquires values relevant to those ofthe amadeus graphs The random graphs were constructed to depict this similarity

bull For smaller initial matching the ratios for G and G show the same upward trendand also they acquire closer values It repsresent the decrease of the averagenumber of forced edges in comparison to the larger matching cases

Sorted ∆

38 Application

Sorted ∆-Comments

bull Big difference in max degree in large initial matching

bull Almost identical behaviour in the case of small initial matching

Appendix A 39

Appendix A

BipartiteGraphGeneratorpy

from future import divisionimport networkx as nx

from networkxalgorithms import approximationimport collectionsimport randomimport mathfrom networkxalgorithms import bipartiteif name == main

for i in range(1481)waqs 481index=1n=randomrandint(100 1000)

n1=95 was 500me1=118

n2=251 was 500me2=903

n3=165 was 500me3=412

m=0m1=0p=randomrandom()p1=18250p2=25250p3=34250print ip=05t1=randomrandint(0 1)print im2=randomrandint(n2minus1 n2+1)G = nxGraph()ma = nxGraph()

aseq1=[1 2 3 4 5 3]

bseq1=[4 3 3 1 2 2 1]

aseq2=[16 14 14 14 12 11]bseq2=[0 0 0 0 0 0]

aseq3=[8 7 8 8 8 8]bseq3=[0 0 0 0 0 0]

40 Application

print Gnumber of edges()if ilt=160

G=bipartiteconfiguration model(aseq1 bseq1 create using=None seed=None)A=nxadjacency matrix(G)for ii in range(0n1+me1)

maadd node(ii)A=[Rtodense()tolist()[0] for R in A]

printnummanumber of nodes()rl=randomsample(range(0n1+me1) n1+me1)m=0done vertices = set()for p in rlprintin fordone verticesadd(p)

neighbors = []list()for iii in range(0n1+me1)

if A[p][iii]==1neighborsappend(iii)

randomshuffle(neighbors)continue loop = Truedegree = len(neighbors)

print degreej = 0p4=randomrandom()while continue loop and (jltdegree)print in loop

next = neighbors[j]if next not in done vertices and p not in done vertices

done verticesadd(p)done verticesadd(next)if p4gt=07print added edge

maadd edge(pnext)m=m+1

continue loop = Falsej += 1

print matching listOfedgeprint maedge

MA=nxadjacency matrix(ma)print MA

MA=[Rtodense()tolist()[0] for R in MA]print MA

B=[ join(map(strR)) for R in A]MB=[ join(map(strR)) for R in MA]

C=njoin(B)+nMC=njoin(MB)+n

print nprint mprint m1

filea=str(i)+txtwith open(fileaw) as f

Appendix A 41

fwrite(str(n1+me1))fwrite(n)fwrite(str(n1+me1))fwrite(n)fwrite(str(m))fwrite(n)fwrite(n)fwrite(C)fwrite(n)fwrite(MC)

elif igt160 and ilt321G=bipartiteconfiguration model(aseq2 bseq2 create using=None seed=None)A=nxadjacency matrix(G)for ii in range(0n2+me2)

maadd node(ii)A=[Rtodense()tolist()[0] for R in A]

printnummanumber of nodes()rl=randomsample(range(0n2+me2) n2+me2)m=0done vertices = set()for p in rlprintin fordone verticesadd(p)

neighbors = []list()for iii in range(0n2+me2)

if A[p][iii]==1neighborsappend(iii)

randomshuffle(neighbors)continue loop = Truedegree = len(neighbors)

print degreej = 0p4=randomrandom()while continue loop and (jltdegree)

print in loopnext = neighbors[j]if next not in done vertices and p not in done vertices

done verticesadd(p)done verticesadd(next)if p4gt=07

print added edgemaadd edge(pnext)m=m+1

continue loop = Falsej += 1

print matching listOfedgeprint maedge

MA=nxadjacency matrix(ma)print MA

MA=[Rtodense()tolist()[0] for R in MA]print MA

B=[ join(map(strR)) for R in A]MB=[ join(map(strR)) for R in MA]

42 Application

C=njoin(B)+nMC=njoin(MB)+n

print nprint mprint m1

filea=str(i)+txtwith open(fileaw) as f

fwrite(str(n2+me2))fwrite(n)fwrite(str(n2+me2))fwrite(n)fwrite(str(m))fwrite(n)fwrite(n)fwrite(C)fwrite(n)fwrite(MC)

elseG=bipartiteconfiguration model(aseq3 bseq3 create using=None seed=None)A=nxadjacency matrix(G)for ii in range(0n3+me3)

maadd node(ii)A=[Rtodense()tolist()[0] for R in A]

printnummanumber of nodes()rl=randomsample(range(0n3+me3) n3+me3)m=0done vertices = set()for p in rlprintin fordone verticesadd(p)

neighbors = []list()for iii in range(0n3+me3)

if A[p][iii]==1neighborsappend(iii)

randomshuffle(neighbors)continue loop = Truedegree = len(neighbors)

print degreej = 0p4=randomrandom()while continue loop and (jltdegree)

print in loopnext = neighbors[j]if next not in done vertices and p not in done vertices

done verticesadd(p)done verticesadd(next)if p4gt=07print added edge

maadd edge(pnext)m=m+1

continue loop = Falsej += 1

Appendix A 43

print matching listOfedgeprint maedge

MA=nxadjacency matrix(ma)print MA

MA=[Rtodense()tolist()[0] for R in MA]print MA

B=[ join(map(strR)) for R in A]MB=[ join(map(strR)) for R in MA]

C=njoin(B)+nMC=njoin(MB)+n

print nprint mprint m1

filea=str(i)+txtwith open(fileaw) as f

fwrite(str(n3+me3))fwrite(n)fwrite(str(n3+me3))fwrite(n)fwrite(str(m))fwrite(n)fwrite(n)fwrite(C)fwrite(n)fwrite(MC)

print nRandom graphs with random matching have been generated

44 Application

RandomGraphGeneratorpy

from future import divisionimport networkx as nxfrom networkxalgorithms import approximationimport collectionsimport randomimport mathif name == main

for i in range(1481)index=1n=randomrandint(100 1000)

n=1000m=0m1=0p=randomrandom()p1=mathlog(n2)np2=13p3=mathlog(n2)n+01p=05t1=randomrandint(0 1)print im2=randomrandint(n2minus1 n2+1)G = nxGraph()ma = nxGraph()print nme1=randomrandint(1 10)me2=randomrandint(2050)me3=randomrandint(50100)if ilt241

if ilt=80G=nxfast gnp random graph(n p1 seed=None directed=False)

elif igt80 and ilt161G=nxfast gnp random graph(n p2 seed=None directed=False)

elseG=nxfast gnp random graph(n p3 seed=None directed=False)

elseif ilt=320

G=nxbarabasi albert graph(n me1 seed=None)elif igt320 and ilt401

G=nxbarabasi albert graph(n me2 seed=None)else

G=nxbarabasi albert graph(n me3 seed=None)A=nxadjacency matrix(G)for ii in range(0n)

maadd node(ii)A=[Rtodense()tolist()[0] for R in A]

rl=randomsample(range(0n) n)m=0

Appendix A 45

done vertices = set()for p in rl

done verticesadd(p)neighbors = []list()for iii in range(0n)

if A[p][iii]==1neighborsappend(iii)

randomshuffle(neighbors)continue loop = Truedegree = len(neighbors)j = 0p2=randomrandom()while continue loop and (jltdegree)

next = neighbors[j]if next not in done vertices and p not in done vertices

done verticesadd(p)done verticesadd(next)if p2gt=00 Larger probability for smaller initial matching

maadd edge(pnext)m=m+1

continue loop = Falsej += 1

print matching listOfedgeprint maedgeMA=nxadjacency matrix(ma)MA=[Rtodense()tolist()[0] for R in MA]print MAB=[ join(map(strR)) for R in A]MB=[ join(map(strR)) for R in MA]

C=njoin(B)+nMC=njoin(MB)+nprint MCprint nprint mprint m1filea=str(i)+txtwith open(fileaw) as f

fwrite(str(n))fwrite(n)fwrite(str(n))fwrite(n)fwrite(str(m))fwrite(n)fwrite(n)fwrite(C)fwrite(n)fwrite(MC)

print nRandom graphs with random matching have been generated

46 Application

kequals3MaximumMatchingpy

from future import divisionimport networkx as nxfrom networkxalgorithms import bipartiteimport matplotlibpyplot as pltimport collectionsimport timeitimport xlwtimport xlrdimport mathimport sys

Case for General Graphsdef forced edges(Gadj dict2matching dict1num nodesforced)

flagg=0for n in range(0num nodes)

for k in adj dict2[n]if ([k]==matching dict1[n])

count=0for l in range(0num nodes)

count=count+adj dict2[l]count(k)if (len(adj dict2[n])==1) or (count==1)

forcedadd edge(nk)Gremove edge(nk)Gremove node(n)Gremove node(k)printforced edgenktemp=kflagg=1for m in range (len(adj dict2[n])minus1minus1minus1)

adj dict2[adj dict2[n][m]]remove(n)adj dict2[n]remove(adj dict2[n][m])

if adj dict2[temp]for l in range(len(adj dict2[temp])minus1minus1minus1)

if (adj dict2[temp][l]=n)adj dict2[adj dict2[temp][l]]remove(temp)adj dict2[temp]remove(adj dict2[temp][l])

break

def useless edges(num nodesadj dict1matching dict1uselessadj dict2G)for n in range(0num nodes)

for k in adj dict1[n]if ([k]=matching dict1[n]) and matching dict1[n] and matching dict1[k]

uselessadd edge(nk)Gremove edge(n k)

Appendix A 47

tempa=kadj dict2[n]remove(k)adj dict2[tempa]remove(n)adj dict1[tempa]remove(n)

return G

def Greedy(num nodesadj dict3matching dict2)

for n in range(0num nodes)if matching dict2[n]

flag2=minus1flag3=minus1for v in adj dict3[n]

if not matching dict2[v]flag2=vbreak

for p in adj dict3[matching dict2[n][0]]if not matching dict2[p]

flag3=pbreak

if (flag2=minus1) and (flag3=minus1) and (flag2=flag3)tempr=matching dict2[n][0]matching dict2[n]=[flag2]matching dict2[flag2]=[n]matching dict2[tempr]=[flag3]matching dict2[flag3]=[tempr]

elsefor k in adj dict3[n]

if not matching dict2[k]matching dict2[n]=[k]matching dict2[k]=[n]break

yo1=0for i in range(0num nodes)

if matching dict2[i] and [i]==matching dict2[matching dict2[i][0]]yo1=yo1+1

greedy size=yo12return greedy size

def General()

INPUTSwb = xlwtWorkbook()ws = wbadd sheet(Results Random)book=xlrdopen workbook(filenames randomxls)

48 Application

style0 = xlwteasyxf(fontbold on)style1 = xlwteasyxf(num format str=0000)INPUTSwswrite(0 0File style0)wswrite(0 1 Nodesstyle0)wswrite(0 2 Initial matchingstyle0)wswrite(0 3 NodesGstyle0)wswrite(0 4 EdgesGstyle0)wswrite(0 5 MaxDegreeGstyle0)wswrite(0 6 NodesG hatstyle0)wswrite(0 7 EdgesG Hatstyle0)wswrite(0 8 Useless edgesstyle0)wswrite(0 9 Forced edgesstyle0)wswrite(0 10 MaxDegreeG Hatstyle0)wswrite(0 11 Classical matchingstyle0)wswrite(0 12 Final matchingstyle0)wswrite(0 13 Greedy matchingstyle0)wswrite(0 14 Time classicalstyle0)wswrite(0 15 Time algorithmstyle0)wswrite(0 16 Time greedystyle0)wswrite(0 17 Perfect matching ratiostyle0)wswrite(0 18 Nodes ratiostyle0)wswrite(0 19 Edges ratiostyle0)wswrite(0 20 Matching ratiostyle0)

print nWelcomeThis is an implementation for general random graphs It uses Edmonds algorithm to compute maximum matching on G Hatn

for index in range (1481)was 481

if (index==482)f=open(Algotel generaltxtr)readlines()

elsefilea=str(booksheet by index(0)cell(index0))s=fileareplace(textu)replace()f=open(sr)readlines()Truewswrite(index 0 s)

print index

num nodes=int([xstrip()split() for x in f][0][0])

num matching=int([xstrip()split() for x in f][2][0])

adj temp = [xstrip()split() for x in f][44+num nodes]adj=[map(intR) for R in adj temp]

matching temp=[xstrip()split() for x in f][4+num nodes+14+2num nodes+1]matching1=[map(intR) for R in matching temp]

adj dict1=i[ii for iix in enumerate(L) if x] for iL in enumerate(adj)adj dict2=i[ii for iix in enumerate(L) if x] for iL in enumerate(adj)

Appendix A 49

adj dict3=i[ii for iix in enumerate(L) if x] for iL in enumerate(adj)

matching dict1=i[ii for iix in enumerate(L) if x] for iL in enumerate(matching1)matching dict2=i[ii for iix in enumerate(L) if x] for iL in enumerate(matching1)print adj dict2print matching dict2wswrite(index 1 num nodes)wswrite(index 2 num matching)

G = nxGraph()

useless= nxGraph()forced = nxGraph()

Fill Graphfor n in range(0num nodes)

for k in adj dict1[n]Gadd edge(nk)

Gt=Gnumber of edges()wswrite(index 3 Gnumber of nodes())wswrite(index 4 Gnumber of edges())wswrite(index 5 max(Gdegree()values()))

Compute Edmonds classical matching on G for comparison

startB = timeitdefault timer()Classical Matching=nxmax weight matching(G maxcardinality=False)stopB = timeitdefault timer()

Compute Gˆ nad MˆstartC = timeitdefault timer()useless edges(num nodesadj dict1matching dict1uselessadj dict2G)forced edges(Gadj dict2matching dict1num nodesforced)Final Matching=nxmax weight matching(G maxcardinality=False)stopC = timeitdefault timer()

GreedystartG = timeitdefault timer()greedy size=Greedy(num nodesadj dict3matching dict2)stopG = timeitdefault timer()

wswrite(index 6 Gnumber of nodes())wswrite(index 7 Gnumber of edges())wswrite(index 8 uselessnumber of edges())wswrite(index 9 forcednumber of edges())if Gdegree()values()

wswrite(index 10 max(Gdegree()values()))else

50 Application

wswrite(index 10 0)wswrite(index 11 len(Classical Matching)2)wswrite(index 12 len(Final Matching)2+forcednumber of edges())wswrite(index 13 greedy size)wswrite(index 14 stopB minus startBstyle1)wswrite(index 15 stopC minus startCstyle1)wswrite(index 16 stopG minus startGstyle1)wswrite(index 17 (len(Final Matching)2+forcednumber of edges())(num nodes2)style1)wswrite(index 18 Gnumber of nodes()Gtstyle1)wswrite(index 19 Gnumber of edges()Gtstyle1)wswrite(index 20 (len(Final Matching)2+forcednumber of edges())(len(Classical Matching)2)style1)

wbsave(AA Results Random Reyni Large Bipartitexls)

Main function Here we must choose the input form of the dataif name == main

startA = timeitdefault timer()General()stopA = timeitdefault timer()

print nThis program has terminatednnRunning time for 480 files stopAminusstartAprint nnPlease open AA Results Random Reyni Largexls file to see the Results

Appendix A 51

Plotmat

clear allclose allload(RN1Lmat)load(RN1Smat)load(RN2Lmat)load(RN2Smat)load(RN3Lmat)load(RN3Smat)

Plotsh(1)=figure(NameHistogram of Matching size difference between Constraint Algorithm and Greedy AlgorithmNumberTitleoff)

RN1L Greedydiff=RN1L Final matchingminusRN1L Greedy matchingRN2L Greedydiff=RN2L Final matchingminusRN2L Greedy matchingRN3L Greedydiff=RN3L Final matchingminusRN3L Greedy matchingRN1S Greedydiff=RN1S Final matchingminusRN1S Greedy matchingRN2S Greedydiff=RN2S Final matchingminusRN2S Greedy matchingRN3S Greedydiff=RN3S Final matchingminusRN3S Greedy matching

RN1L Finaldiff=RN1L Classical matchingminusRN1L Final matchingRN2L Finaldiff=RN2L Classical matchingminusRN2L Final matchingRN3L Finaldiff=RN3L Classical matchingminusRN3L Final matchingRN1S Finaldiff=RN1S Classical matchingminusRN1S Final matchingRN2S Finaldiff=RN2S Classical matchingminusRN2S Final matchingRN3S Finaldiff=RN3S Classical matchingminusRN3S Final matching

RN1L Classicaldiff=(RN1L Nodes2)minusRN1L Classical matchingRN2L Classicaldiff=(RN2L Nodes2)minusRN2L Classical matchingRN3L Classicaldiff=(RN3L Nodes2)minusRN3L Classical matchingRN1S Classicaldiff=(RN1S Nodes2)minusRN1S Classical matchingRN2S Classicaldiff=(RN2S Nodes2)minusRN2S Classical matchingRN3S Classicaldiff=(RN3S Nodes2)minusRN3S Classical matching

subplot(231)hold onhistf(RN1L Greedydiff0110facecolorbfacealpha9edgealpha1)histf(RN1L Finaldiff0110facecolorrfacealpha5edgealpha1)histf(RN1L Classicaldiff0110facecolorgfacealpha5edgealpha1)legalpha(ConminusGreClasminusConPerfminusClasslocationnortheast)legend boxoffaxis tightxlabel(edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN1L)grid on

subplot(232)hold onhistf(RN2L Greedydiff0110facecolorbfacealpha9edgealpha1)

52 Application

histf(RN2L Finaldiff0110facecolorrfacealpha5edgealpha1)histf(RN2L Classicaldiff0110facecolorgfacealpha5edgealpha1)legalpha(ConminusGreClasminusConPerfminusClasslocationnortheast)legend boxoffaxis tightxlabel(edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN2L)grid on

subplot(233)hold onhistf(RN3L Greedydiff0110facecolorbfacealpha5edgealpha1)histf(RN3L Finaldiff0110facecolorrfacealpha5edgealpha1)histf(RN3L Classicaldiff0110facecolorgfacealpha5edgealpha1)legalpha(ConminusGreClasminusConPerfminusClasslocationnortheast)legend boxoffaxis tightxlabel(edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN3L)grid on

subplot(234)hold onhistf(RN1S Greedydiff0110facecolorbfacealpha5edgealpha1)histf(RN1S Finaldiff0110facecolorrfacealpha5edgealpha1)histf(RN1S Classicaldiff0110facecolorgfacealpha5edgealpha1)legalpha(ConminusGreClasminusConPerfminusClasslocationnortheast)legend boxoffaxis tightxlabel(edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(R1NS)grid on

subplot(235)hold onhistf(RN2S Greedydiff0110facecolorbfacealpha5edgealpha1)histf(RN2S Finaldiff0110facecolorrfacealpha5edgealpha1)histf(RN2S Classicaldiff0110facecolorgfacealpha5edgealpha1)legalpha(ConminusGreClasminusConPerfminusClasslocationnortheast)legend boxoffaxis tightxlabel(edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN2S)grid on

subplot(236)hold onhistf(RN3S Greedydiff0110facecolorbfacealpha5edgealpha1)histf(RN3S Finaldiff0110facecolorrfacealpha5edgealpha1)histf(RN3S Classicaldiff0110facecolorgfacealpha5edgealpha1)

Appendix A 53

legalpha(ConminusGreClasminusConPerfminusClasslocationnortheast)legend boxoffaxis tightgrid ontitle(RN3S)xlabel(edges) xminusaxis labelylabel(instances) yminusaxis labelset(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN1png minusr300)h(2)=figure(NameHistogram of Max Degree of G AND G HatNumberTitleoff)RN1L x=RN1L MaxDegreeGminusRN1L MaxDegreeG HatRN2L x=RN2L MaxDegreeGminusRN2L MaxDegreeG HatRN3L x=RN3L MaxDegreeGminusRN3L MaxDegreeG HatRN1S x=RN1S MaxDegreeGminusRN1S MaxDegreeG HatRN2S x=RN2S MaxDegreeGminusRN2S MaxDegreeG HatRN3S x=RN3S MaxDegreeGminusRN3S MaxDegreeG Hatsubplot(231)hold onhistf(RN1L MaxDegreeG0150facecolorbfacealpha5edgealpha1)histf(RN1L MaxDegreeG Hat0150facecolorrfacealpha5edgealpha1)histf(RN1L x0150facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightxlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN1L)grid on

subplot(232)hold onhistf(RN2L MaxDegreeG010500facecolorbfacealpha5edgealpha1)histf(RN2L MaxDegreeG Hat010500facecolorrfacealpha5edgealpha1)histf(RN2L x010500facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightxlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN2L)grid on

subplot(233)hold onhistf(RN3L MaxDegreeG010300facecolorbfacealpha5edgealpha1)histf(RN3L MaxDegreeG Hat010300facecolorrfacealpha5edgealpha1)histf(RN3L x010300facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightxlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN3L)

54 Application

grid on

subplot(234)hold onhistf(RN1S MaxDegreeG0150facecolorbfacealpha5edgealpha1)histf(RN1S MaxDegreeG Hat0150facecolorrfacealpha5edgealpha1)histf(RN1S x0150facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightxlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(R1NS)grid on

subplot(235)hold onhistf(RN2S MaxDegreeG010500facecolorbfacealpha5edgealpha1)histf(RN2S MaxDegreeG Hat010500facecolorrfacealpha5edgealpha1)histf(RN2S x010500facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightxlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN2S)grid on

subplot(236)hold onhistf(RN3S MaxDegreeG05300facecolorbfacealpha5edgealpha1)histf(RN3S MaxDegreeG Hat05300facecolorrfacealpha5edgealpha1)histf(RN3S x05300facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightgrid ontitle(RN3S)xlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labelset(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN2png minusr300)

h(3)=figure(NameComputation time over edgesNumberTitleoff)

subplot(231)hold onstem(RN1L EdgesGRN1L Time classicalg)stem(RN1L EdgesGRN1L Time algorithmro)stem(RN1L EdgesGRN1L Time greedybx)grid on

Appendix A 55

title(RN1L)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)

subplot(232)hold onstem(RN2L EdgesGRN2L Time classicalg)stem(RN2L EdgesGRN2L Time algorithmro)stem(RN2L EdgesGRN2L Time greedybx)grid ontitle(RN2L)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)

subplot(233)hold onstem(RN3L EdgesGRN3L Time classicalg)stem(RN3L EdgesGRN3L Time algorithmro)stem(RN3L EdgesGRN3L Time greedybx)grid ontitle(RN3L)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)

subplot(234)hold onstem(RN1S EdgesGRN1S Time classicalg)stem(RN1S EdgesGRN1S Time algorithmro)stem(RN1S EdgesGRN1S Time greedybx)grid ontitle(RN1S)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)

subplot(235)hold onstem(RN2S EdgesGRN2S Time classicalg)stem(RN2S EdgesGRN2S Time algorithmro)stem(RN2S EdgesGRN2S Time greedybx)grid ontitle(RN2S)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)

subplot(236)hold onstem(RN3S EdgesGRN3S Time classicalg)stem(RN3S EdgesGRN3S Time algorithmro)stem(RN3S EdgesGRN3S Time greedybx)

56 Application

grid ontitle(RN3S)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)set(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN3png minusr300)

h(4)=figure(NameSorted matching sizeNumberTitleoff)RN1L Sorted matching temp(1)=RN1L Classical matchingRN1L Sorted matching temp(2)=RN1L Final matchingRN1L Sorted matching temp(3)=RN1L Greedy matchingRN1L Sorted matching temp(4)=RN1L Initial matchingRN1L Sorted matching=sortrows(RN1L Sorted matching temp)

RN2L Sorted matching temp(1)=RN2L Classical matchingRN2L Sorted matching temp(2)=RN2L Final matchingRN2L Sorted matching temp(3)=RN2L Greedy matchingRN2L Sorted matching temp(4)=RN2L Initial matchingRN2L Sorted matching=sortrows(RN2L Sorted matching temp)

RN3L Sorted matching temp(1)=RN3L Classical matchingRN3L Sorted matching temp(2)=RN3L Final matchingRN3L Sorted matching temp(3)=RN3L Greedy matchingRN3L Sorted matching temp(4)=RN3L Initial matchingRN3L Sorted matching=sortrows(RN3L Sorted matching temp)

RN1S Sorted matching temp(1)=RN1S Classical matchingRN1S Sorted matching temp(2)=RN1S Final matchingRN1S Sorted matching temp(3)=RN1S Greedy matchingRN1S Sorted matching temp(4)=RN1S Initial matchingRN1S Sorted matching=sortrows(RN1S Sorted matching temp)

RN2S Sorted matching temp(1)=RN2S Classical matchingRN2S Sorted matching temp(2)=RN2S Final matchingRN2S Sorted matching temp(3)=RN2S Greedy matchingRN2S Sorted matching temp(4)=RN2S Initial matchingRN2S Sorted matching=sortrows(RN2S Sorted matching temp)

RN3S Sorted matching temp(1)=RN3S Classical matchingRN3S Sorted matching temp(2)=RN3S Final matchingRN3S Sorted matching temp(3)=RN3S Greedy matchingRN3S Sorted matching temp(4)=RN3S Initial matchingRN3S Sorted matching=sortrows(RN3S Sorted matching temp)

subplot(231)hold onplot(RN1L Sorted matching(1)b)plot(RN1L Sorted matching(2)g)plot(RN1L Sorted matching(3)r)plot(RN1L Sorted matching(4)m)

Appendix A 57

grid ontitle(RN1L)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)

subplot(232)hold onplot(RN2L Sorted matching(1)b)plot(RN2L Sorted matching(2)g)plot(RN2L Sorted matching(3)r)plot(RN2L Sorted matching(4)m)grid ontitle(RN2L)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)

subplot(233)hold onplot(RN3L Sorted matching(1)b)plot(RN3L Sorted matching(2)g)plot(RN3L Sorted matching(3)r)plot(RN3L Sorted matching(4)m)grid ontitle(RN3L)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)

subplot(234)hold onplot(RN1S Sorted matching(1)b)plot(RN1S Sorted matching(2)g)plot(RN1S Sorted matching(3)r)plot(RN1S Sorted matching(4)m)grid ontitle(RN1S)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)

subplot(235)hold onplot(RN2S Sorted matching(1)b)plot(RN2S Sorted matching(2)g)plot(RN2S Sorted matching(3)r)plot(RN2S Sorted matching(4)m)grid ontitle(RN2S)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)

58 Application

subplot(236)hold onplot(RN3S Sorted matching(1)b)plot(RN3S Sorted matching(2)g)plot(RN3S Sorted matching(3)r)plot(RN3S Sorted matching(4)m)grid ontitle(RN3S)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)set(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN4png minusr300)h(5)=figure(NameSorted RatiosNumberTitleoff)RN1L ratio1=RN1L NodesG hatRN1L NodesGRN2L ratio1=RN2L NodesG hatRN2L NodesGRN3L ratio1=RN3L NodesG hatRN3L NodesGRN1S ratio1=RN1S NodesG hatRN1S NodesGRN2S ratio1=RN2S NodesG hatRN2S NodesGRN3S ratio1=RN3S NodesG hatRN3S NodesG

RN1L ratio2=RN1L EdgesG HatRN1L EdgesGRN2L ratio2=RN2L EdgesG HatRN2L EdgesGRN3L ratio2=RN3L EdgesG HatRN3L EdgesGRN1S ratio2=RN1S EdgesG HatRN1S EdgesGRN2S ratio2=RN2S EdgesG HatRN2S EdgesGRN3S ratio2=RN3S EdgesG HatRN3S EdgesG

RN1L ratio3=RN1L MaxDegreeG HatRN1L MaxDegreeGRN2L ratio3=RN2L MaxDegreeG HatRN2L MaxDegreeGRN3L ratio3=RN3L MaxDegreeG HatRN3L MaxDegreeGRN1S ratio3=RN1S MaxDegreeG HatRN1S MaxDegreeGRN2S ratio3=RN2S MaxDegreeG HatRN2S MaxDegreeGRN3S ratio3=RN3S MaxDegreeG HatRN3S MaxDegreeG

RN1L ratio(1)=RN1L ratio1RN1L ratio(2)=RN1L ratio2RN1L ratio(3)=RN1L ratio3

RN2L ratio(1)=RN2L ratio1RN2L ratio(2)=RN2L ratio2RN2L ratio(3)=RN2L ratio3

RN3L ratio(1)=RN3L ratio1RN3L ratio(2)=RN3L ratio2RN3L ratio(3)=RN3L ratio3

RN1S ratio(1)=RN1S ratio1RN1S ratio(2)=RN1S ratio2RN1S ratio(3)=RN1S ratio3

RN2S ratio(1)=RN2S ratio1

Appendix A 59

RN2S ratio(2)=RN2S ratio2RN2S ratio(3)=RN2S ratio3

RN3S ratio(1)=RN3S ratio1RN3S ratio(2)=RN3S ratio2RN3S ratio(3)=RN3S ratio3

RN1L ratio sorted=sortrows(RN1L ratio)RN2L ratio sorted=sortrows(RN2L ratio)RN3L ratio sorted=sortrows(RN3L ratio)RN1S ratio sorted=sortrows(RN1S ratio)RN2S ratio sorted=sortrows(RN2S ratio)RN3S ratio sorted=sortrows(RN3S ratio)

subplot(231)hold onplot(RN1L ratio sorted(1)b)plot(RN1L ratio sorted(2)g)plot(RN1L ratio sorted(3)r)grid ontitle(RN1L)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)

subplot(232)hold onplot(RN2L ratio sorted(1)b)plot(RN2L ratio sorted(2)g)plot(RN2L ratio sorted(3)r)grid ontitle(RN2L)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)

subplot(233)hold onplot(RN3L ratio sorted(1)b)plot(RN3L ratio sorted(2)g)plot(RN3L ratio sorted(3)r)grid ontitle(RN3L)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)

subplot(234)hold onplot(RN1S ratio sorted(1)b)plot(RN1S ratio sorted(2)g)plot(RN1S ratio sorted(3)r)grid on

60 Application

title(RN1S)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)

subplot(235)hold onplot(RN2S ratio sorted(1)b)plot(RN2S ratio sorted(2)g)plot(RN2S ratio sorted(3)r)grid ontitle(RN2S)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)

subplot(236)hold onplot(RN3S ratio sorted(1)b)plot(RN3S ratio sorted(2)g)plot(RN3S ratio sorted(3)r)grid ontitle(RN3S)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)set(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN5png minusr300)

h(6)=figure(NameSorted edges over nodesNumberTitleoff)

RN1L DegreeG1=(RN1L EdgesG)(RN1L NodesG)RN1L DegreeG Hat1=(RN1L EdgesG Hat)(RN1L NodesG hat)

RN1L Degree temp1(1)=RN1L DegreeG1RN1L Degree temp1(2)=RN1L DegreeG Hat1RN1L Degree sorted1=sortrows(RN1L Degree temp1)subplot(231)hold on

plot(RN1L Degree sorted1(1)b)plot(RN1L Degree sorted1(2)g)grid ontitle(RN1L)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)

RN2L DegreeG1=(RN2L EdgesG)(RN2L NodesG)RN2L DegreeG Hat1=(RN2L EdgesG Hat)(RN2L NodesG hat)

RN2L Degree temp1(1)=RN2L DegreeG1

Appendix A 61

RN2L Degree temp1(2)=RN2L DegreeG Hat1RN2L Degree sorted1=sortrows(RN2L Degree temp1)

subplot(232)hold onplot(RN2L Degree sorted1(1)b)plot(RN2L Degree sorted1(2)g)grid ontitle(RN2L)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)

RN3L DegreeG1=(RN3L EdgesG)(RN3L NodesG)RN3L DegreeG Hat1=(RN3L EdgesG Hat)(RN3L NodesG hat)

RN3L Degree temp1(1)=RN3L DegreeG1RN3L Degree temp1(2)=RN3L DegreeG Hat1RN3L Degree sorted1=sortrows(RN3L Degree temp1)

subplot(233)hold onplot(RN3L Degree sorted1(1)b)plot(RN3L Degree sorted1(2)g)grid ontitle(RN3L)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)

RN1S DegreeG1=(RN1S EdgesG)(RN1S NodesG)RN1S DegreeG Hat1=(RN1S EdgesG Hat)(RN1S NodesG hat)

RN1S Degree temp1(1)=RN1S DegreeG1RN1S Degree temp1(2)=RN1S DegreeG Hat1RN1S Degree sorted1=sortrows(RN1S Degree temp1)

subplot(234)hold onplot(RN1S Degree sorted1(1)b)plot(RN1S Degree sorted1(2)g)grid ontitle(RN1S)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)

RN2S DegreeG1=(RN2S EdgesG)(RN2S NodesG)RN2S DegreeG Hat1=(RN2S EdgesG Hat)(RN2S NodesG hat)

RN2S Degree temp1(1)=RN2S DegreeG1

62 Application

RN2S Degree temp1(2)=RN2S DegreeG Hat1RN2S Degree sorted1=sortrows(RN2S Degree temp1)

subplot(235)hold onplot(RN2S Degree sorted1(1)b)plot(RN2S Degree sorted1(2)g)grid ontitle(RN2S)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)

RN3S DegreeG1=(RN3S EdgesG)(RN3S NodesG)RN3S DegreeG Hat1=(RN3S EdgesG Hat)(RN3S NodesG hat)

RN3S Degree temp1(1)=RN3S DegreeG1RN3S Degree temp1(2)=RN3S DegreeG Hat1RN3S Degree sorted1=sortrows(RN3S Degree temp1)

subplot(236)hold onplot(RN3S Degree sorted1(1)b)plot(RN3S Degree sorted1(2)g)grid ontitle(RN3S)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)set(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN6png minusr300)h(7)=figure(NameSorted mATCHED DEGREENumberTitleoff)RN1L ratioMax(1)=RN1L MaxDegreeGRN1L ratioMax(2)=RN1L MaxDegreeG Hat

RN1L ratio sortedMax=sortrows(RN1L ratioMax)subplot(231)hold onplot(RN1L ratio sortedMax(1)b)plot(RN1L ratio sortedMax(2)g)grid ontitle(RN1L)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)

RN2L ratioMax(1)=RN2L MaxDegreeGRN2L ratioMax(2)=RN2L MaxDegreeG Hat

RN2L ratio sortedMax=sortrows(RN2L ratioMax)subplot(232)

Appendix A 63

hold onplot(RN2L ratio sortedMax(1)b)plot(RN2L ratio sortedMax(2)g)grid ontitle(RN2L)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)

RN3L ratioMax(1)=RN3L MaxDegreeGRN3L ratioMax(2)=RN3L MaxDegreeG Hat

RN3L ratio sortedMax=sortrows(RN3L ratioMax)subplot(233)hold onplot(RN3L ratio sortedMax(1)b)plot(RN3L ratio sortedMax(2)g)grid ontitle(RN3L)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)

RN1S ratioMax(1)=RN1S MaxDegreeGRN1S ratioMax(2)=RN1S MaxDegreeG Hat

RN1S ratio sortedMax=sortrows(RN1S ratioMax)subplot(234)hold onplot(RN1S ratio sortedMax(1)b)plot(RN1S ratio sortedMax(2)g)grid ontitle(RN1S)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)

RN2S ratioMax(1)=RN2S MaxDegreeGRN2S ratioMax(2)=RN2S MaxDegreeG Hat

RN2S ratio sortedMax=sortrows(RN2S ratioMax)

subplot(235)hold onplot(RN2S ratio sortedMax(1)b)plot(RN2S ratio sortedMax(2)g)grid ontitle(RN2S)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)

RN3S ratioMax(1)=RN3S MaxDegreeGRN3S ratioMax(2)=RN3S MaxDegreeG Hat

64 Application

RN3S ratio sortedMax=sortrows(RN3S ratioMax)subplot(236)hold onplot(RN3S ratio sortedMax(1)b)plot(RN3S ratio sortedMax(2)g)grid ontitle(RN1L)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)set(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN7png minusr300)

tilefigs()(h)

Bibliography

[1] C Berge ldquoTWO THEOREMS IN GRAPH THEORYrdquo Proceedings of the NationalAcademy of Sciences of the United States of America vol 43 no 9 pp 842ndash844Sep 1957

[2] L Bui S Sanghavi and R Srikant ldquoDistributed link scheduling with constantoverheadrdquo IEEEACM Trans Netw vol 17 no 5 pp 1467ndash1480 2009

[3] R Duan and S Pettie ldquoLinear-time approximation for maximum weight matchingrdquoJ ACM vol 61 no 1 2014

[4] J Edmonds ldquoPaths trees and flowersrdquo Canadian Journal of Mathematics vol 17pp 449ndash467 1965

[5] J E Hopcroft and R M Karp ldquoAn n52 algorithm for maximum matchings inbipartite graphsrdquo SIAM J Comput vol 2 no 4 pp 225ndash231 1973

[6] S Micali and V V Vazirani ldquoAn O(radic|V ||E|) algorithm for finding maximum

matching in general graphsrdquo in 21st Symp on Foundations of Comp Sc (FOCS)IEEE 1980 pp 17ndash27

[7] N Nisse A Salch and V Weber ldquoRecovery of disrupted airline operationsrdquo 2015httphalinriafrSomething

[8] X Wu and R Srikant ldquoRegulated maximal matching A distributed schedulingalgorithm for multi-hop wireless networks with nodeexclusive spectrum sharingrdquo inIEEE Conf on Decision and Control 2005

65

  • Contents
  • Introduction
  • Algorithms
    • Maximum matching
    • k-maximum matching
      • k-matching for Airport Slot assignment
      • The case where k=3
      • The case of Paths
      • The case of the Spider
          • Application
            • Description
            • Reyni Erdos
            • Barabaacutesi Albert
            • Amadeus Graphs
            • Bipartite
            • Bipartite with degree seq
            • Appendix A
              • BipartiteGraphGeneratorpy
              • RandomGraphGeneratorpy
              • kequals3MaximumMatchingpy
              • Plotmat
                  • Bibliography
Page 25: Theodoros Alexandros KARAGKIOULES -  · Introduction This work is the result of a 6 months internship, under the supervision of research O cer Nicolas NISSE. The original scope of

26 Application

bull

Sorted |E||V |

Sorted |E||V | - Comments

bull Density of the graphs shows that on average we have 25-3 available time slot perflight

bull The line for the same value for G shows that there is a large deviation for everyinstance which allows for the hypothesis that the amount of useless+forced edgesof G has no obvious correlation to that of G

25 Bipartite 27

Sorted ∆

Sorted ∆-Comments

bull As per the previous related graphs for ∆ there is in significant drop in the ∆ of Gand G

25 Bipartite

Graph characteristics Bipartite random Graphs

bull BIPxy are randomly generated graphs with a fixed number of 1000(n=500 andm=500) nodes

bull There are 6 categories based on ini matching and probability p

28 Application

bull Probability p has been chosen as such in order to simulate the |E||V | 25 of theAmadeus bipartite graphs

bull So in order to have about 2-4 edges for every node we choose accordingly theprobability p to choose one of the n lowastm possible edges

bull x = L S L When the initial matching is large and S when it is small

bull y = 1 2 3 1 when p = 18250

2 when p = 25250

and 3 when p = 34250

Computation time over

Computation time overedges-Comments

bull

25 Bipartite 29

Sorted matching size

Sorted matching size-Comments

bull In these set of graphs one can instantly notice that only a few instances with highprobability can reach a matching size equal to the perfect matching

bull For the case of the initial matching we witness that there is a gap between the lineof the classical matching and those of the constraint and greedy results suggestingsmaller matching sizes of 10-40 edges

bull For the case of the small initial matching the result of the constraint matchingis now close to the result of the classical matching yet the greedy algorithm stillshows a relevantly big difference

30 Application

bull In this set of bipartite graphs we can witness that the result of the Constraintmatching shows a difference with the classical matching when the initial matchingis large The difference is smaller as the probability gets larger

bull For the case of the small initial matching the above phenomenom does not occuryet the greedy results deviates from that of the constraint matching

bull As per the pefrect matching compared to the classical matching a difference of5-10 edges is evident at almost all cases

Sorted Ratios

Sorted Ratios-Comments

bull Great max degree deviation

25 Bipartite 31

bull Regardless of the probability the ration of nodes and edges seems to have similarbehaviour when compared to the respective graphs of the same matching scale

bull Same gap between nodes ration and edges ration for all cases

Sorted |E||V |

Sorted |E||V | - Comments

bull In these set of figures we witness that the |E||V | acquires values relevant to those ofthe amadeus graphs The random graphs were constructed to depict this similarity

bull For smaller initial matching the ratios for G and G show the same upward trendand also they acquire closer values It represents the decrease of the averagenumber of forced edges in comparison to the larger matching cases

32 Application

Sorted ∆

Sorted ∆-Comments

bull ∆ acquires the same min and max values for each probability case (expected)

bull Gap in the case of large initial matching

26 Bipartite with degree seq

Graph characteristics

bull DEQBIPxy are randomly generated graphs based on three different types of degreedistribution of the Amadeus graphs

26 Bipartite with degree seq 33

bull There are 6 categories based on ini matching and degree distribution

bull x = L S L When the initial matching is large and S when it is small

bull y = 1 2 3 1 when degree distribution is based on file 2 when degree distributionis based on file and 3 when degree distribution is based on file

Computation time over

34 Application

Computation time overedges-Comments

bull Greedy algorithm takes minimum amount of time

bull The smaller the initial matching the more smaller the difference in comoutationtime of Constraint and classical algorithm

bull Due to preprocessing and the fact that G and G are the almost identical thetotal time needed to apply the constraint algorithm is in some cases bigger

Sorted matching size

26 Bipartite with degree seq 35

Sorted matching size-Comments

bull Classical matching is equal to perfect matching in every case

bull Constraint and greedy have identical behaviour

bull The larger the spectrum of the degree sequence the more efficient the matching

Sorted Ratios

36 Application

Sorted Ratios-Comments

bull With large initial matching most of the edges are considenred uselles or forced andare removed thus the ratio is close(if not equal to) zero

bull For small matching and large degree sequence sectrum hte max degree remainsthe same Only a few forced edges (and their nodes) are removed apparently nonodes with max degree

Sorted |E||V |

26 Bipartite with degree seq 37

Sorted |E||V | - Comments

bull In these set of figures we witness that the |E||V | acquires values relevant to those ofthe amadeus graphs The random graphs were constructed to depict this similarity

bull For smaller initial matching the ratios for G and G show the same upward trendand also they acquire closer values It repsresent the decrease of the averagenumber of forced edges in comparison to the larger matching cases

Sorted ∆

38 Application

Sorted ∆-Comments

bull Big difference in max degree in large initial matching

bull Almost identical behaviour in the case of small initial matching

Appendix A 39

Appendix A

BipartiteGraphGeneratorpy

from future import divisionimport networkx as nx

from networkxalgorithms import approximationimport collectionsimport randomimport mathfrom networkxalgorithms import bipartiteif name == main

for i in range(1481)waqs 481index=1n=randomrandint(100 1000)

n1=95 was 500me1=118

n2=251 was 500me2=903

n3=165 was 500me3=412

m=0m1=0p=randomrandom()p1=18250p2=25250p3=34250print ip=05t1=randomrandint(0 1)print im2=randomrandint(n2minus1 n2+1)G = nxGraph()ma = nxGraph()

aseq1=[1 2 3 4 5 3]

bseq1=[4 3 3 1 2 2 1]

aseq2=[16 14 14 14 12 11]bseq2=[0 0 0 0 0 0]

aseq3=[8 7 8 8 8 8]bseq3=[0 0 0 0 0 0]

40 Application

print Gnumber of edges()if ilt=160

G=bipartiteconfiguration model(aseq1 bseq1 create using=None seed=None)A=nxadjacency matrix(G)for ii in range(0n1+me1)

maadd node(ii)A=[Rtodense()tolist()[0] for R in A]

printnummanumber of nodes()rl=randomsample(range(0n1+me1) n1+me1)m=0done vertices = set()for p in rlprintin fordone verticesadd(p)

neighbors = []list()for iii in range(0n1+me1)

if A[p][iii]==1neighborsappend(iii)

randomshuffle(neighbors)continue loop = Truedegree = len(neighbors)

print degreej = 0p4=randomrandom()while continue loop and (jltdegree)print in loop

next = neighbors[j]if next not in done vertices and p not in done vertices

done verticesadd(p)done verticesadd(next)if p4gt=07print added edge

maadd edge(pnext)m=m+1

continue loop = Falsej += 1

print matching listOfedgeprint maedge

MA=nxadjacency matrix(ma)print MA

MA=[Rtodense()tolist()[0] for R in MA]print MA

B=[ join(map(strR)) for R in A]MB=[ join(map(strR)) for R in MA]

C=njoin(B)+nMC=njoin(MB)+n

print nprint mprint m1

filea=str(i)+txtwith open(fileaw) as f

Appendix A 41

fwrite(str(n1+me1))fwrite(n)fwrite(str(n1+me1))fwrite(n)fwrite(str(m))fwrite(n)fwrite(n)fwrite(C)fwrite(n)fwrite(MC)

elif igt160 and ilt321G=bipartiteconfiguration model(aseq2 bseq2 create using=None seed=None)A=nxadjacency matrix(G)for ii in range(0n2+me2)

maadd node(ii)A=[Rtodense()tolist()[0] for R in A]

printnummanumber of nodes()rl=randomsample(range(0n2+me2) n2+me2)m=0done vertices = set()for p in rlprintin fordone verticesadd(p)

neighbors = []list()for iii in range(0n2+me2)

if A[p][iii]==1neighborsappend(iii)

randomshuffle(neighbors)continue loop = Truedegree = len(neighbors)

print degreej = 0p4=randomrandom()while continue loop and (jltdegree)

print in loopnext = neighbors[j]if next not in done vertices and p not in done vertices

done verticesadd(p)done verticesadd(next)if p4gt=07

print added edgemaadd edge(pnext)m=m+1

continue loop = Falsej += 1

print matching listOfedgeprint maedge

MA=nxadjacency matrix(ma)print MA

MA=[Rtodense()tolist()[0] for R in MA]print MA

B=[ join(map(strR)) for R in A]MB=[ join(map(strR)) for R in MA]

42 Application

C=njoin(B)+nMC=njoin(MB)+n

print nprint mprint m1

filea=str(i)+txtwith open(fileaw) as f

fwrite(str(n2+me2))fwrite(n)fwrite(str(n2+me2))fwrite(n)fwrite(str(m))fwrite(n)fwrite(n)fwrite(C)fwrite(n)fwrite(MC)

elseG=bipartiteconfiguration model(aseq3 bseq3 create using=None seed=None)A=nxadjacency matrix(G)for ii in range(0n3+me3)

maadd node(ii)A=[Rtodense()tolist()[0] for R in A]

printnummanumber of nodes()rl=randomsample(range(0n3+me3) n3+me3)m=0done vertices = set()for p in rlprintin fordone verticesadd(p)

neighbors = []list()for iii in range(0n3+me3)

if A[p][iii]==1neighborsappend(iii)

randomshuffle(neighbors)continue loop = Truedegree = len(neighbors)

print degreej = 0p4=randomrandom()while continue loop and (jltdegree)

print in loopnext = neighbors[j]if next not in done vertices and p not in done vertices

done verticesadd(p)done verticesadd(next)if p4gt=07print added edge

maadd edge(pnext)m=m+1

continue loop = Falsej += 1

Appendix A 43

print matching listOfedgeprint maedge

MA=nxadjacency matrix(ma)print MA

MA=[Rtodense()tolist()[0] for R in MA]print MA

B=[ join(map(strR)) for R in A]MB=[ join(map(strR)) for R in MA]

C=njoin(B)+nMC=njoin(MB)+n

print nprint mprint m1

filea=str(i)+txtwith open(fileaw) as f

fwrite(str(n3+me3))fwrite(n)fwrite(str(n3+me3))fwrite(n)fwrite(str(m))fwrite(n)fwrite(n)fwrite(C)fwrite(n)fwrite(MC)

print nRandom graphs with random matching have been generated

44 Application

RandomGraphGeneratorpy

from future import divisionimport networkx as nxfrom networkxalgorithms import approximationimport collectionsimport randomimport mathif name == main

for i in range(1481)index=1n=randomrandint(100 1000)

n=1000m=0m1=0p=randomrandom()p1=mathlog(n2)np2=13p3=mathlog(n2)n+01p=05t1=randomrandint(0 1)print im2=randomrandint(n2minus1 n2+1)G = nxGraph()ma = nxGraph()print nme1=randomrandint(1 10)me2=randomrandint(2050)me3=randomrandint(50100)if ilt241

if ilt=80G=nxfast gnp random graph(n p1 seed=None directed=False)

elif igt80 and ilt161G=nxfast gnp random graph(n p2 seed=None directed=False)

elseG=nxfast gnp random graph(n p3 seed=None directed=False)

elseif ilt=320

G=nxbarabasi albert graph(n me1 seed=None)elif igt320 and ilt401

G=nxbarabasi albert graph(n me2 seed=None)else

G=nxbarabasi albert graph(n me3 seed=None)A=nxadjacency matrix(G)for ii in range(0n)

maadd node(ii)A=[Rtodense()tolist()[0] for R in A]

rl=randomsample(range(0n) n)m=0

Appendix A 45

done vertices = set()for p in rl

done verticesadd(p)neighbors = []list()for iii in range(0n)

if A[p][iii]==1neighborsappend(iii)

randomshuffle(neighbors)continue loop = Truedegree = len(neighbors)j = 0p2=randomrandom()while continue loop and (jltdegree)

next = neighbors[j]if next not in done vertices and p not in done vertices

done verticesadd(p)done verticesadd(next)if p2gt=00 Larger probability for smaller initial matching

maadd edge(pnext)m=m+1

continue loop = Falsej += 1

print matching listOfedgeprint maedgeMA=nxadjacency matrix(ma)MA=[Rtodense()tolist()[0] for R in MA]print MAB=[ join(map(strR)) for R in A]MB=[ join(map(strR)) for R in MA]

C=njoin(B)+nMC=njoin(MB)+nprint MCprint nprint mprint m1filea=str(i)+txtwith open(fileaw) as f

fwrite(str(n))fwrite(n)fwrite(str(n))fwrite(n)fwrite(str(m))fwrite(n)fwrite(n)fwrite(C)fwrite(n)fwrite(MC)

print nRandom graphs with random matching have been generated

46 Application

kequals3MaximumMatchingpy

from future import divisionimport networkx as nxfrom networkxalgorithms import bipartiteimport matplotlibpyplot as pltimport collectionsimport timeitimport xlwtimport xlrdimport mathimport sys

Case for General Graphsdef forced edges(Gadj dict2matching dict1num nodesforced)

flagg=0for n in range(0num nodes)

for k in adj dict2[n]if ([k]==matching dict1[n])

count=0for l in range(0num nodes)

count=count+adj dict2[l]count(k)if (len(adj dict2[n])==1) or (count==1)

forcedadd edge(nk)Gremove edge(nk)Gremove node(n)Gremove node(k)printforced edgenktemp=kflagg=1for m in range (len(adj dict2[n])minus1minus1minus1)

adj dict2[adj dict2[n][m]]remove(n)adj dict2[n]remove(adj dict2[n][m])

if adj dict2[temp]for l in range(len(adj dict2[temp])minus1minus1minus1)

if (adj dict2[temp][l]=n)adj dict2[adj dict2[temp][l]]remove(temp)adj dict2[temp]remove(adj dict2[temp][l])

break

def useless edges(num nodesadj dict1matching dict1uselessadj dict2G)for n in range(0num nodes)

for k in adj dict1[n]if ([k]=matching dict1[n]) and matching dict1[n] and matching dict1[k]

uselessadd edge(nk)Gremove edge(n k)

Appendix A 47

tempa=kadj dict2[n]remove(k)adj dict2[tempa]remove(n)adj dict1[tempa]remove(n)

return G

def Greedy(num nodesadj dict3matching dict2)

for n in range(0num nodes)if matching dict2[n]

flag2=minus1flag3=minus1for v in adj dict3[n]

if not matching dict2[v]flag2=vbreak

for p in adj dict3[matching dict2[n][0]]if not matching dict2[p]

flag3=pbreak

if (flag2=minus1) and (flag3=minus1) and (flag2=flag3)tempr=matching dict2[n][0]matching dict2[n]=[flag2]matching dict2[flag2]=[n]matching dict2[tempr]=[flag3]matching dict2[flag3]=[tempr]

elsefor k in adj dict3[n]

if not matching dict2[k]matching dict2[n]=[k]matching dict2[k]=[n]break

yo1=0for i in range(0num nodes)

if matching dict2[i] and [i]==matching dict2[matching dict2[i][0]]yo1=yo1+1

greedy size=yo12return greedy size

def General()

INPUTSwb = xlwtWorkbook()ws = wbadd sheet(Results Random)book=xlrdopen workbook(filenames randomxls)

48 Application

style0 = xlwteasyxf(fontbold on)style1 = xlwteasyxf(num format str=0000)INPUTSwswrite(0 0File style0)wswrite(0 1 Nodesstyle0)wswrite(0 2 Initial matchingstyle0)wswrite(0 3 NodesGstyle0)wswrite(0 4 EdgesGstyle0)wswrite(0 5 MaxDegreeGstyle0)wswrite(0 6 NodesG hatstyle0)wswrite(0 7 EdgesG Hatstyle0)wswrite(0 8 Useless edgesstyle0)wswrite(0 9 Forced edgesstyle0)wswrite(0 10 MaxDegreeG Hatstyle0)wswrite(0 11 Classical matchingstyle0)wswrite(0 12 Final matchingstyle0)wswrite(0 13 Greedy matchingstyle0)wswrite(0 14 Time classicalstyle0)wswrite(0 15 Time algorithmstyle0)wswrite(0 16 Time greedystyle0)wswrite(0 17 Perfect matching ratiostyle0)wswrite(0 18 Nodes ratiostyle0)wswrite(0 19 Edges ratiostyle0)wswrite(0 20 Matching ratiostyle0)

print nWelcomeThis is an implementation for general random graphs It uses Edmonds algorithm to compute maximum matching on G Hatn

for index in range (1481)was 481

if (index==482)f=open(Algotel generaltxtr)readlines()

elsefilea=str(booksheet by index(0)cell(index0))s=fileareplace(textu)replace()f=open(sr)readlines()Truewswrite(index 0 s)

print index

num nodes=int([xstrip()split() for x in f][0][0])

num matching=int([xstrip()split() for x in f][2][0])

adj temp = [xstrip()split() for x in f][44+num nodes]adj=[map(intR) for R in adj temp]

matching temp=[xstrip()split() for x in f][4+num nodes+14+2num nodes+1]matching1=[map(intR) for R in matching temp]

adj dict1=i[ii for iix in enumerate(L) if x] for iL in enumerate(adj)adj dict2=i[ii for iix in enumerate(L) if x] for iL in enumerate(adj)

Appendix A 49

adj dict3=i[ii for iix in enumerate(L) if x] for iL in enumerate(adj)

matching dict1=i[ii for iix in enumerate(L) if x] for iL in enumerate(matching1)matching dict2=i[ii for iix in enumerate(L) if x] for iL in enumerate(matching1)print adj dict2print matching dict2wswrite(index 1 num nodes)wswrite(index 2 num matching)

G = nxGraph()

useless= nxGraph()forced = nxGraph()

Fill Graphfor n in range(0num nodes)

for k in adj dict1[n]Gadd edge(nk)

Gt=Gnumber of edges()wswrite(index 3 Gnumber of nodes())wswrite(index 4 Gnumber of edges())wswrite(index 5 max(Gdegree()values()))

Compute Edmonds classical matching on G for comparison

startB = timeitdefault timer()Classical Matching=nxmax weight matching(G maxcardinality=False)stopB = timeitdefault timer()

Compute Gˆ nad MˆstartC = timeitdefault timer()useless edges(num nodesadj dict1matching dict1uselessadj dict2G)forced edges(Gadj dict2matching dict1num nodesforced)Final Matching=nxmax weight matching(G maxcardinality=False)stopC = timeitdefault timer()

GreedystartG = timeitdefault timer()greedy size=Greedy(num nodesadj dict3matching dict2)stopG = timeitdefault timer()

wswrite(index 6 Gnumber of nodes())wswrite(index 7 Gnumber of edges())wswrite(index 8 uselessnumber of edges())wswrite(index 9 forcednumber of edges())if Gdegree()values()

wswrite(index 10 max(Gdegree()values()))else

50 Application

wswrite(index 10 0)wswrite(index 11 len(Classical Matching)2)wswrite(index 12 len(Final Matching)2+forcednumber of edges())wswrite(index 13 greedy size)wswrite(index 14 stopB minus startBstyle1)wswrite(index 15 stopC minus startCstyle1)wswrite(index 16 stopG minus startGstyle1)wswrite(index 17 (len(Final Matching)2+forcednumber of edges())(num nodes2)style1)wswrite(index 18 Gnumber of nodes()Gtstyle1)wswrite(index 19 Gnumber of edges()Gtstyle1)wswrite(index 20 (len(Final Matching)2+forcednumber of edges())(len(Classical Matching)2)style1)

wbsave(AA Results Random Reyni Large Bipartitexls)

Main function Here we must choose the input form of the dataif name == main

startA = timeitdefault timer()General()stopA = timeitdefault timer()

print nThis program has terminatednnRunning time for 480 files stopAminusstartAprint nnPlease open AA Results Random Reyni Largexls file to see the Results

Appendix A 51

Plotmat

clear allclose allload(RN1Lmat)load(RN1Smat)load(RN2Lmat)load(RN2Smat)load(RN3Lmat)load(RN3Smat)

Plotsh(1)=figure(NameHistogram of Matching size difference between Constraint Algorithm and Greedy AlgorithmNumberTitleoff)

RN1L Greedydiff=RN1L Final matchingminusRN1L Greedy matchingRN2L Greedydiff=RN2L Final matchingminusRN2L Greedy matchingRN3L Greedydiff=RN3L Final matchingminusRN3L Greedy matchingRN1S Greedydiff=RN1S Final matchingminusRN1S Greedy matchingRN2S Greedydiff=RN2S Final matchingminusRN2S Greedy matchingRN3S Greedydiff=RN3S Final matchingminusRN3S Greedy matching

RN1L Finaldiff=RN1L Classical matchingminusRN1L Final matchingRN2L Finaldiff=RN2L Classical matchingminusRN2L Final matchingRN3L Finaldiff=RN3L Classical matchingminusRN3L Final matchingRN1S Finaldiff=RN1S Classical matchingminusRN1S Final matchingRN2S Finaldiff=RN2S Classical matchingminusRN2S Final matchingRN3S Finaldiff=RN3S Classical matchingminusRN3S Final matching

RN1L Classicaldiff=(RN1L Nodes2)minusRN1L Classical matchingRN2L Classicaldiff=(RN2L Nodes2)minusRN2L Classical matchingRN3L Classicaldiff=(RN3L Nodes2)minusRN3L Classical matchingRN1S Classicaldiff=(RN1S Nodes2)minusRN1S Classical matchingRN2S Classicaldiff=(RN2S Nodes2)minusRN2S Classical matchingRN3S Classicaldiff=(RN3S Nodes2)minusRN3S Classical matching

subplot(231)hold onhistf(RN1L Greedydiff0110facecolorbfacealpha9edgealpha1)histf(RN1L Finaldiff0110facecolorrfacealpha5edgealpha1)histf(RN1L Classicaldiff0110facecolorgfacealpha5edgealpha1)legalpha(ConminusGreClasminusConPerfminusClasslocationnortheast)legend boxoffaxis tightxlabel(edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN1L)grid on

subplot(232)hold onhistf(RN2L Greedydiff0110facecolorbfacealpha9edgealpha1)

52 Application

histf(RN2L Finaldiff0110facecolorrfacealpha5edgealpha1)histf(RN2L Classicaldiff0110facecolorgfacealpha5edgealpha1)legalpha(ConminusGreClasminusConPerfminusClasslocationnortheast)legend boxoffaxis tightxlabel(edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN2L)grid on

subplot(233)hold onhistf(RN3L Greedydiff0110facecolorbfacealpha5edgealpha1)histf(RN3L Finaldiff0110facecolorrfacealpha5edgealpha1)histf(RN3L Classicaldiff0110facecolorgfacealpha5edgealpha1)legalpha(ConminusGreClasminusConPerfminusClasslocationnortheast)legend boxoffaxis tightxlabel(edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN3L)grid on

subplot(234)hold onhistf(RN1S Greedydiff0110facecolorbfacealpha5edgealpha1)histf(RN1S Finaldiff0110facecolorrfacealpha5edgealpha1)histf(RN1S Classicaldiff0110facecolorgfacealpha5edgealpha1)legalpha(ConminusGreClasminusConPerfminusClasslocationnortheast)legend boxoffaxis tightxlabel(edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(R1NS)grid on

subplot(235)hold onhistf(RN2S Greedydiff0110facecolorbfacealpha5edgealpha1)histf(RN2S Finaldiff0110facecolorrfacealpha5edgealpha1)histf(RN2S Classicaldiff0110facecolorgfacealpha5edgealpha1)legalpha(ConminusGreClasminusConPerfminusClasslocationnortheast)legend boxoffaxis tightxlabel(edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN2S)grid on

subplot(236)hold onhistf(RN3S Greedydiff0110facecolorbfacealpha5edgealpha1)histf(RN3S Finaldiff0110facecolorrfacealpha5edgealpha1)histf(RN3S Classicaldiff0110facecolorgfacealpha5edgealpha1)

Appendix A 53

legalpha(ConminusGreClasminusConPerfminusClasslocationnortheast)legend boxoffaxis tightgrid ontitle(RN3S)xlabel(edges) xminusaxis labelylabel(instances) yminusaxis labelset(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN1png minusr300)h(2)=figure(NameHistogram of Max Degree of G AND G HatNumberTitleoff)RN1L x=RN1L MaxDegreeGminusRN1L MaxDegreeG HatRN2L x=RN2L MaxDegreeGminusRN2L MaxDegreeG HatRN3L x=RN3L MaxDegreeGminusRN3L MaxDegreeG HatRN1S x=RN1S MaxDegreeGminusRN1S MaxDegreeG HatRN2S x=RN2S MaxDegreeGminusRN2S MaxDegreeG HatRN3S x=RN3S MaxDegreeGminusRN3S MaxDegreeG Hatsubplot(231)hold onhistf(RN1L MaxDegreeG0150facecolorbfacealpha5edgealpha1)histf(RN1L MaxDegreeG Hat0150facecolorrfacealpha5edgealpha1)histf(RN1L x0150facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightxlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN1L)grid on

subplot(232)hold onhistf(RN2L MaxDegreeG010500facecolorbfacealpha5edgealpha1)histf(RN2L MaxDegreeG Hat010500facecolorrfacealpha5edgealpha1)histf(RN2L x010500facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightxlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN2L)grid on

subplot(233)hold onhistf(RN3L MaxDegreeG010300facecolorbfacealpha5edgealpha1)histf(RN3L MaxDegreeG Hat010300facecolorrfacealpha5edgealpha1)histf(RN3L x010300facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightxlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN3L)

54 Application

grid on

subplot(234)hold onhistf(RN1S MaxDegreeG0150facecolorbfacealpha5edgealpha1)histf(RN1S MaxDegreeG Hat0150facecolorrfacealpha5edgealpha1)histf(RN1S x0150facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightxlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(R1NS)grid on

subplot(235)hold onhistf(RN2S MaxDegreeG010500facecolorbfacealpha5edgealpha1)histf(RN2S MaxDegreeG Hat010500facecolorrfacealpha5edgealpha1)histf(RN2S x010500facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightxlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN2S)grid on

subplot(236)hold onhistf(RN3S MaxDegreeG05300facecolorbfacealpha5edgealpha1)histf(RN3S MaxDegreeG Hat05300facecolorrfacealpha5edgealpha1)histf(RN3S x05300facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightgrid ontitle(RN3S)xlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labelset(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN2png minusr300)

h(3)=figure(NameComputation time over edgesNumberTitleoff)

subplot(231)hold onstem(RN1L EdgesGRN1L Time classicalg)stem(RN1L EdgesGRN1L Time algorithmro)stem(RN1L EdgesGRN1L Time greedybx)grid on

Appendix A 55

title(RN1L)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)

subplot(232)hold onstem(RN2L EdgesGRN2L Time classicalg)stem(RN2L EdgesGRN2L Time algorithmro)stem(RN2L EdgesGRN2L Time greedybx)grid ontitle(RN2L)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)

subplot(233)hold onstem(RN3L EdgesGRN3L Time classicalg)stem(RN3L EdgesGRN3L Time algorithmro)stem(RN3L EdgesGRN3L Time greedybx)grid ontitle(RN3L)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)

subplot(234)hold onstem(RN1S EdgesGRN1S Time classicalg)stem(RN1S EdgesGRN1S Time algorithmro)stem(RN1S EdgesGRN1S Time greedybx)grid ontitle(RN1S)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)

subplot(235)hold onstem(RN2S EdgesGRN2S Time classicalg)stem(RN2S EdgesGRN2S Time algorithmro)stem(RN2S EdgesGRN2S Time greedybx)grid ontitle(RN2S)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)

subplot(236)hold onstem(RN3S EdgesGRN3S Time classicalg)stem(RN3S EdgesGRN3S Time algorithmro)stem(RN3S EdgesGRN3S Time greedybx)

56 Application

grid ontitle(RN3S)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)set(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN3png minusr300)

h(4)=figure(NameSorted matching sizeNumberTitleoff)RN1L Sorted matching temp(1)=RN1L Classical matchingRN1L Sorted matching temp(2)=RN1L Final matchingRN1L Sorted matching temp(3)=RN1L Greedy matchingRN1L Sorted matching temp(4)=RN1L Initial matchingRN1L Sorted matching=sortrows(RN1L Sorted matching temp)

RN2L Sorted matching temp(1)=RN2L Classical matchingRN2L Sorted matching temp(2)=RN2L Final matchingRN2L Sorted matching temp(3)=RN2L Greedy matchingRN2L Sorted matching temp(4)=RN2L Initial matchingRN2L Sorted matching=sortrows(RN2L Sorted matching temp)

RN3L Sorted matching temp(1)=RN3L Classical matchingRN3L Sorted matching temp(2)=RN3L Final matchingRN3L Sorted matching temp(3)=RN3L Greedy matchingRN3L Sorted matching temp(4)=RN3L Initial matchingRN3L Sorted matching=sortrows(RN3L Sorted matching temp)

RN1S Sorted matching temp(1)=RN1S Classical matchingRN1S Sorted matching temp(2)=RN1S Final matchingRN1S Sorted matching temp(3)=RN1S Greedy matchingRN1S Sorted matching temp(4)=RN1S Initial matchingRN1S Sorted matching=sortrows(RN1S Sorted matching temp)

RN2S Sorted matching temp(1)=RN2S Classical matchingRN2S Sorted matching temp(2)=RN2S Final matchingRN2S Sorted matching temp(3)=RN2S Greedy matchingRN2S Sorted matching temp(4)=RN2S Initial matchingRN2S Sorted matching=sortrows(RN2S Sorted matching temp)

RN3S Sorted matching temp(1)=RN3S Classical matchingRN3S Sorted matching temp(2)=RN3S Final matchingRN3S Sorted matching temp(3)=RN3S Greedy matchingRN3S Sorted matching temp(4)=RN3S Initial matchingRN3S Sorted matching=sortrows(RN3S Sorted matching temp)

subplot(231)hold onplot(RN1L Sorted matching(1)b)plot(RN1L Sorted matching(2)g)plot(RN1L Sorted matching(3)r)plot(RN1L Sorted matching(4)m)

Appendix A 57

grid ontitle(RN1L)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)

subplot(232)hold onplot(RN2L Sorted matching(1)b)plot(RN2L Sorted matching(2)g)plot(RN2L Sorted matching(3)r)plot(RN2L Sorted matching(4)m)grid ontitle(RN2L)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)

subplot(233)hold onplot(RN3L Sorted matching(1)b)plot(RN3L Sorted matching(2)g)plot(RN3L Sorted matching(3)r)plot(RN3L Sorted matching(4)m)grid ontitle(RN3L)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)

subplot(234)hold onplot(RN1S Sorted matching(1)b)plot(RN1S Sorted matching(2)g)plot(RN1S Sorted matching(3)r)plot(RN1S Sorted matching(4)m)grid ontitle(RN1S)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)

subplot(235)hold onplot(RN2S Sorted matching(1)b)plot(RN2S Sorted matching(2)g)plot(RN2S Sorted matching(3)r)plot(RN2S Sorted matching(4)m)grid ontitle(RN2S)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)

58 Application

subplot(236)hold onplot(RN3S Sorted matching(1)b)plot(RN3S Sorted matching(2)g)plot(RN3S Sorted matching(3)r)plot(RN3S Sorted matching(4)m)grid ontitle(RN3S)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)set(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN4png minusr300)h(5)=figure(NameSorted RatiosNumberTitleoff)RN1L ratio1=RN1L NodesG hatRN1L NodesGRN2L ratio1=RN2L NodesG hatRN2L NodesGRN3L ratio1=RN3L NodesG hatRN3L NodesGRN1S ratio1=RN1S NodesG hatRN1S NodesGRN2S ratio1=RN2S NodesG hatRN2S NodesGRN3S ratio1=RN3S NodesG hatRN3S NodesG

RN1L ratio2=RN1L EdgesG HatRN1L EdgesGRN2L ratio2=RN2L EdgesG HatRN2L EdgesGRN3L ratio2=RN3L EdgesG HatRN3L EdgesGRN1S ratio2=RN1S EdgesG HatRN1S EdgesGRN2S ratio2=RN2S EdgesG HatRN2S EdgesGRN3S ratio2=RN3S EdgesG HatRN3S EdgesG

RN1L ratio3=RN1L MaxDegreeG HatRN1L MaxDegreeGRN2L ratio3=RN2L MaxDegreeG HatRN2L MaxDegreeGRN3L ratio3=RN3L MaxDegreeG HatRN3L MaxDegreeGRN1S ratio3=RN1S MaxDegreeG HatRN1S MaxDegreeGRN2S ratio3=RN2S MaxDegreeG HatRN2S MaxDegreeGRN3S ratio3=RN3S MaxDegreeG HatRN3S MaxDegreeG

RN1L ratio(1)=RN1L ratio1RN1L ratio(2)=RN1L ratio2RN1L ratio(3)=RN1L ratio3

RN2L ratio(1)=RN2L ratio1RN2L ratio(2)=RN2L ratio2RN2L ratio(3)=RN2L ratio3

RN3L ratio(1)=RN3L ratio1RN3L ratio(2)=RN3L ratio2RN3L ratio(3)=RN3L ratio3

RN1S ratio(1)=RN1S ratio1RN1S ratio(2)=RN1S ratio2RN1S ratio(3)=RN1S ratio3

RN2S ratio(1)=RN2S ratio1

Appendix A 59

RN2S ratio(2)=RN2S ratio2RN2S ratio(3)=RN2S ratio3

RN3S ratio(1)=RN3S ratio1RN3S ratio(2)=RN3S ratio2RN3S ratio(3)=RN3S ratio3

RN1L ratio sorted=sortrows(RN1L ratio)RN2L ratio sorted=sortrows(RN2L ratio)RN3L ratio sorted=sortrows(RN3L ratio)RN1S ratio sorted=sortrows(RN1S ratio)RN2S ratio sorted=sortrows(RN2S ratio)RN3S ratio sorted=sortrows(RN3S ratio)

subplot(231)hold onplot(RN1L ratio sorted(1)b)plot(RN1L ratio sorted(2)g)plot(RN1L ratio sorted(3)r)grid ontitle(RN1L)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)

subplot(232)hold onplot(RN2L ratio sorted(1)b)plot(RN2L ratio sorted(2)g)plot(RN2L ratio sorted(3)r)grid ontitle(RN2L)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)

subplot(233)hold onplot(RN3L ratio sorted(1)b)plot(RN3L ratio sorted(2)g)plot(RN3L ratio sorted(3)r)grid ontitle(RN3L)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)

subplot(234)hold onplot(RN1S ratio sorted(1)b)plot(RN1S ratio sorted(2)g)plot(RN1S ratio sorted(3)r)grid on

60 Application

title(RN1S)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)

subplot(235)hold onplot(RN2S ratio sorted(1)b)plot(RN2S ratio sorted(2)g)plot(RN2S ratio sorted(3)r)grid ontitle(RN2S)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)

subplot(236)hold onplot(RN3S ratio sorted(1)b)plot(RN3S ratio sorted(2)g)plot(RN3S ratio sorted(3)r)grid ontitle(RN3S)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)set(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN5png minusr300)

h(6)=figure(NameSorted edges over nodesNumberTitleoff)

RN1L DegreeG1=(RN1L EdgesG)(RN1L NodesG)RN1L DegreeG Hat1=(RN1L EdgesG Hat)(RN1L NodesG hat)

RN1L Degree temp1(1)=RN1L DegreeG1RN1L Degree temp1(2)=RN1L DegreeG Hat1RN1L Degree sorted1=sortrows(RN1L Degree temp1)subplot(231)hold on

plot(RN1L Degree sorted1(1)b)plot(RN1L Degree sorted1(2)g)grid ontitle(RN1L)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)

RN2L DegreeG1=(RN2L EdgesG)(RN2L NodesG)RN2L DegreeG Hat1=(RN2L EdgesG Hat)(RN2L NodesG hat)

RN2L Degree temp1(1)=RN2L DegreeG1

Appendix A 61

RN2L Degree temp1(2)=RN2L DegreeG Hat1RN2L Degree sorted1=sortrows(RN2L Degree temp1)

subplot(232)hold onplot(RN2L Degree sorted1(1)b)plot(RN2L Degree sorted1(2)g)grid ontitle(RN2L)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)

RN3L DegreeG1=(RN3L EdgesG)(RN3L NodesG)RN3L DegreeG Hat1=(RN3L EdgesG Hat)(RN3L NodesG hat)

RN3L Degree temp1(1)=RN3L DegreeG1RN3L Degree temp1(2)=RN3L DegreeG Hat1RN3L Degree sorted1=sortrows(RN3L Degree temp1)

subplot(233)hold onplot(RN3L Degree sorted1(1)b)plot(RN3L Degree sorted1(2)g)grid ontitle(RN3L)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)

RN1S DegreeG1=(RN1S EdgesG)(RN1S NodesG)RN1S DegreeG Hat1=(RN1S EdgesG Hat)(RN1S NodesG hat)

RN1S Degree temp1(1)=RN1S DegreeG1RN1S Degree temp1(2)=RN1S DegreeG Hat1RN1S Degree sorted1=sortrows(RN1S Degree temp1)

subplot(234)hold onplot(RN1S Degree sorted1(1)b)plot(RN1S Degree sorted1(2)g)grid ontitle(RN1S)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)

RN2S DegreeG1=(RN2S EdgesG)(RN2S NodesG)RN2S DegreeG Hat1=(RN2S EdgesG Hat)(RN2S NodesG hat)

RN2S Degree temp1(1)=RN2S DegreeG1

62 Application

RN2S Degree temp1(2)=RN2S DegreeG Hat1RN2S Degree sorted1=sortrows(RN2S Degree temp1)

subplot(235)hold onplot(RN2S Degree sorted1(1)b)plot(RN2S Degree sorted1(2)g)grid ontitle(RN2S)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)

RN3S DegreeG1=(RN3S EdgesG)(RN3S NodesG)RN3S DegreeG Hat1=(RN3S EdgesG Hat)(RN3S NodesG hat)

RN3S Degree temp1(1)=RN3S DegreeG1RN3S Degree temp1(2)=RN3S DegreeG Hat1RN3S Degree sorted1=sortrows(RN3S Degree temp1)

subplot(236)hold onplot(RN3S Degree sorted1(1)b)plot(RN3S Degree sorted1(2)g)grid ontitle(RN3S)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)set(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN6png minusr300)h(7)=figure(NameSorted mATCHED DEGREENumberTitleoff)RN1L ratioMax(1)=RN1L MaxDegreeGRN1L ratioMax(2)=RN1L MaxDegreeG Hat

RN1L ratio sortedMax=sortrows(RN1L ratioMax)subplot(231)hold onplot(RN1L ratio sortedMax(1)b)plot(RN1L ratio sortedMax(2)g)grid ontitle(RN1L)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)

RN2L ratioMax(1)=RN2L MaxDegreeGRN2L ratioMax(2)=RN2L MaxDegreeG Hat

RN2L ratio sortedMax=sortrows(RN2L ratioMax)subplot(232)

Appendix A 63

hold onplot(RN2L ratio sortedMax(1)b)plot(RN2L ratio sortedMax(2)g)grid ontitle(RN2L)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)

RN3L ratioMax(1)=RN3L MaxDegreeGRN3L ratioMax(2)=RN3L MaxDegreeG Hat

RN3L ratio sortedMax=sortrows(RN3L ratioMax)subplot(233)hold onplot(RN3L ratio sortedMax(1)b)plot(RN3L ratio sortedMax(2)g)grid ontitle(RN3L)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)

RN1S ratioMax(1)=RN1S MaxDegreeGRN1S ratioMax(2)=RN1S MaxDegreeG Hat

RN1S ratio sortedMax=sortrows(RN1S ratioMax)subplot(234)hold onplot(RN1S ratio sortedMax(1)b)plot(RN1S ratio sortedMax(2)g)grid ontitle(RN1S)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)

RN2S ratioMax(1)=RN2S MaxDegreeGRN2S ratioMax(2)=RN2S MaxDegreeG Hat

RN2S ratio sortedMax=sortrows(RN2S ratioMax)

subplot(235)hold onplot(RN2S ratio sortedMax(1)b)plot(RN2S ratio sortedMax(2)g)grid ontitle(RN2S)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)

RN3S ratioMax(1)=RN3S MaxDegreeGRN3S ratioMax(2)=RN3S MaxDegreeG Hat

64 Application

RN3S ratio sortedMax=sortrows(RN3S ratioMax)subplot(236)hold onplot(RN3S ratio sortedMax(1)b)plot(RN3S ratio sortedMax(2)g)grid ontitle(RN1L)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)set(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN7png minusr300)

tilefigs()(h)

Bibliography

[1] C Berge ldquoTWO THEOREMS IN GRAPH THEORYrdquo Proceedings of the NationalAcademy of Sciences of the United States of America vol 43 no 9 pp 842ndash844Sep 1957

[2] L Bui S Sanghavi and R Srikant ldquoDistributed link scheduling with constantoverheadrdquo IEEEACM Trans Netw vol 17 no 5 pp 1467ndash1480 2009

[3] R Duan and S Pettie ldquoLinear-time approximation for maximum weight matchingrdquoJ ACM vol 61 no 1 2014

[4] J Edmonds ldquoPaths trees and flowersrdquo Canadian Journal of Mathematics vol 17pp 449ndash467 1965

[5] J E Hopcroft and R M Karp ldquoAn n52 algorithm for maximum matchings inbipartite graphsrdquo SIAM J Comput vol 2 no 4 pp 225ndash231 1973

[6] S Micali and V V Vazirani ldquoAn O(radic|V ||E|) algorithm for finding maximum

matching in general graphsrdquo in 21st Symp on Foundations of Comp Sc (FOCS)IEEE 1980 pp 17ndash27

[7] N Nisse A Salch and V Weber ldquoRecovery of disrupted airline operationsrdquo 2015httphalinriafrSomething

[8] X Wu and R Srikant ldquoRegulated maximal matching A distributed schedulingalgorithm for multi-hop wireless networks with nodeexclusive spectrum sharingrdquo inIEEE Conf on Decision and Control 2005

65

  • Contents
  • Introduction
  • Algorithms
    • Maximum matching
    • k-maximum matching
      • k-matching for Airport Slot assignment
      • The case where k=3
      • The case of Paths
      • The case of the Spider
          • Application
            • Description
            • Reyni Erdos
            • Barabaacutesi Albert
            • Amadeus Graphs
            • Bipartite
            • Bipartite with degree seq
            • Appendix A
              • BipartiteGraphGeneratorpy
              • RandomGraphGeneratorpy
              • kequals3MaximumMatchingpy
              • Plotmat
                  • Bibliography
Page 26: Theodoros Alexandros KARAGKIOULES -  · Introduction This work is the result of a 6 months internship, under the supervision of research O cer Nicolas NISSE. The original scope of

25 Bipartite 27

Sorted ∆

Sorted ∆-Comments

bull As per the previous related graphs for ∆ there is in significant drop in the ∆ of Gand G

25 Bipartite

Graph characteristics Bipartite random Graphs

bull BIPxy are randomly generated graphs with a fixed number of 1000(n=500 andm=500) nodes

bull There are 6 categories based on ini matching and probability p

28 Application

bull Probability p has been chosen as such in order to simulate the |E||V | 25 of theAmadeus bipartite graphs

bull So in order to have about 2-4 edges for every node we choose accordingly theprobability p to choose one of the n lowastm possible edges

bull x = L S L When the initial matching is large and S when it is small

bull y = 1 2 3 1 when p = 18250

2 when p = 25250

and 3 when p = 34250

Computation time over

Computation time overedges-Comments

bull

25 Bipartite 29

Sorted matching size

Sorted matching size-Comments

bull In these set of graphs one can instantly notice that only a few instances with highprobability can reach a matching size equal to the perfect matching

bull For the case of the initial matching we witness that there is a gap between the lineof the classical matching and those of the constraint and greedy results suggestingsmaller matching sizes of 10-40 edges

bull For the case of the small initial matching the result of the constraint matchingis now close to the result of the classical matching yet the greedy algorithm stillshows a relevantly big difference

30 Application

bull In this set of bipartite graphs we can witness that the result of the Constraintmatching shows a difference with the classical matching when the initial matchingis large The difference is smaller as the probability gets larger

bull For the case of the small initial matching the above phenomenom does not occuryet the greedy results deviates from that of the constraint matching

bull As per the pefrect matching compared to the classical matching a difference of5-10 edges is evident at almost all cases

Sorted Ratios

Sorted Ratios-Comments

bull Great max degree deviation

25 Bipartite 31

bull Regardless of the probability the ration of nodes and edges seems to have similarbehaviour when compared to the respective graphs of the same matching scale

bull Same gap between nodes ration and edges ration for all cases

Sorted |E||V |

Sorted |E||V | - Comments

bull In these set of figures we witness that the |E||V | acquires values relevant to those ofthe amadeus graphs The random graphs were constructed to depict this similarity

bull For smaller initial matching the ratios for G and G show the same upward trendand also they acquire closer values It represents the decrease of the averagenumber of forced edges in comparison to the larger matching cases

32 Application

Sorted ∆

Sorted ∆-Comments

bull ∆ acquires the same min and max values for each probability case (expected)

bull Gap in the case of large initial matching

26 Bipartite with degree seq

Graph characteristics

bull DEQBIPxy are randomly generated graphs based on three different types of degreedistribution of the Amadeus graphs

26 Bipartite with degree seq 33

bull There are 6 categories based on ini matching and degree distribution

bull x = L S L When the initial matching is large and S when it is small

bull y = 1 2 3 1 when degree distribution is based on file 2 when degree distributionis based on file and 3 when degree distribution is based on file

Computation time over

34 Application

Computation time overedges-Comments

bull Greedy algorithm takes minimum amount of time

bull The smaller the initial matching the more smaller the difference in comoutationtime of Constraint and classical algorithm

bull Due to preprocessing and the fact that G and G are the almost identical thetotal time needed to apply the constraint algorithm is in some cases bigger

Sorted matching size

26 Bipartite with degree seq 35

Sorted matching size-Comments

bull Classical matching is equal to perfect matching in every case

bull Constraint and greedy have identical behaviour

bull The larger the spectrum of the degree sequence the more efficient the matching

Sorted Ratios

36 Application

Sorted Ratios-Comments

bull With large initial matching most of the edges are considenred uselles or forced andare removed thus the ratio is close(if not equal to) zero

bull For small matching and large degree sequence sectrum hte max degree remainsthe same Only a few forced edges (and their nodes) are removed apparently nonodes with max degree

Sorted |E||V |

26 Bipartite with degree seq 37

Sorted |E||V | - Comments

bull In these set of figures we witness that the |E||V | acquires values relevant to those ofthe amadeus graphs The random graphs were constructed to depict this similarity

bull For smaller initial matching the ratios for G and G show the same upward trendand also they acquire closer values It repsresent the decrease of the averagenumber of forced edges in comparison to the larger matching cases

Sorted ∆

38 Application

Sorted ∆-Comments

bull Big difference in max degree in large initial matching

bull Almost identical behaviour in the case of small initial matching

Appendix A 39

Appendix A

BipartiteGraphGeneratorpy

from future import divisionimport networkx as nx

from networkxalgorithms import approximationimport collectionsimport randomimport mathfrom networkxalgorithms import bipartiteif name == main

for i in range(1481)waqs 481index=1n=randomrandint(100 1000)

n1=95 was 500me1=118

n2=251 was 500me2=903

n3=165 was 500me3=412

m=0m1=0p=randomrandom()p1=18250p2=25250p3=34250print ip=05t1=randomrandint(0 1)print im2=randomrandint(n2minus1 n2+1)G = nxGraph()ma = nxGraph()

aseq1=[1 2 3 4 5 3]

bseq1=[4 3 3 1 2 2 1]

aseq2=[16 14 14 14 12 11]bseq2=[0 0 0 0 0 0]

aseq3=[8 7 8 8 8 8]bseq3=[0 0 0 0 0 0]

40 Application

print Gnumber of edges()if ilt=160

G=bipartiteconfiguration model(aseq1 bseq1 create using=None seed=None)A=nxadjacency matrix(G)for ii in range(0n1+me1)

maadd node(ii)A=[Rtodense()tolist()[0] for R in A]

printnummanumber of nodes()rl=randomsample(range(0n1+me1) n1+me1)m=0done vertices = set()for p in rlprintin fordone verticesadd(p)

neighbors = []list()for iii in range(0n1+me1)

if A[p][iii]==1neighborsappend(iii)

randomshuffle(neighbors)continue loop = Truedegree = len(neighbors)

print degreej = 0p4=randomrandom()while continue loop and (jltdegree)print in loop

next = neighbors[j]if next not in done vertices and p not in done vertices

done verticesadd(p)done verticesadd(next)if p4gt=07print added edge

maadd edge(pnext)m=m+1

continue loop = Falsej += 1

print matching listOfedgeprint maedge

MA=nxadjacency matrix(ma)print MA

MA=[Rtodense()tolist()[0] for R in MA]print MA

B=[ join(map(strR)) for R in A]MB=[ join(map(strR)) for R in MA]

C=njoin(B)+nMC=njoin(MB)+n

print nprint mprint m1

filea=str(i)+txtwith open(fileaw) as f

Appendix A 41

fwrite(str(n1+me1))fwrite(n)fwrite(str(n1+me1))fwrite(n)fwrite(str(m))fwrite(n)fwrite(n)fwrite(C)fwrite(n)fwrite(MC)

elif igt160 and ilt321G=bipartiteconfiguration model(aseq2 bseq2 create using=None seed=None)A=nxadjacency matrix(G)for ii in range(0n2+me2)

maadd node(ii)A=[Rtodense()tolist()[0] for R in A]

printnummanumber of nodes()rl=randomsample(range(0n2+me2) n2+me2)m=0done vertices = set()for p in rlprintin fordone verticesadd(p)

neighbors = []list()for iii in range(0n2+me2)

if A[p][iii]==1neighborsappend(iii)

randomshuffle(neighbors)continue loop = Truedegree = len(neighbors)

print degreej = 0p4=randomrandom()while continue loop and (jltdegree)

print in loopnext = neighbors[j]if next not in done vertices and p not in done vertices

done verticesadd(p)done verticesadd(next)if p4gt=07

print added edgemaadd edge(pnext)m=m+1

continue loop = Falsej += 1

print matching listOfedgeprint maedge

MA=nxadjacency matrix(ma)print MA

MA=[Rtodense()tolist()[0] for R in MA]print MA

B=[ join(map(strR)) for R in A]MB=[ join(map(strR)) for R in MA]

42 Application

C=njoin(B)+nMC=njoin(MB)+n

print nprint mprint m1

filea=str(i)+txtwith open(fileaw) as f

fwrite(str(n2+me2))fwrite(n)fwrite(str(n2+me2))fwrite(n)fwrite(str(m))fwrite(n)fwrite(n)fwrite(C)fwrite(n)fwrite(MC)

elseG=bipartiteconfiguration model(aseq3 bseq3 create using=None seed=None)A=nxadjacency matrix(G)for ii in range(0n3+me3)

maadd node(ii)A=[Rtodense()tolist()[0] for R in A]

printnummanumber of nodes()rl=randomsample(range(0n3+me3) n3+me3)m=0done vertices = set()for p in rlprintin fordone verticesadd(p)

neighbors = []list()for iii in range(0n3+me3)

if A[p][iii]==1neighborsappend(iii)

randomshuffle(neighbors)continue loop = Truedegree = len(neighbors)

print degreej = 0p4=randomrandom()while continue loop and (jltdegree)

print in loopnext = neighbors[j]if next not in done vertices and p not in done vertices

done verticesadd(p)done verticesadd(next)if p4gt=07print added edge

maadd edge(pnext)m=m+1

continue loop = Falsej += 1

Appendix A 43

print matching listOfedgeprint maedge

MA=nxadjacency matrix(ma)print MA

MA=[Rtodense()tolist()[0] for R in MA]print MA

B=[ join(map(strR)) for R in A]MB=[ join(map(strR)) for R in MA]

C=njoin(B)+nMC=njoin(MB)+n

print nprint mprint m1

filea=str(i)+txtwith open(fileaw) as f

fwrite(str(n3+me3))fwrite(n)fwrite(str(n3+me3))fwrite(n)fwrite(str(m))fwrite(n)fwrite(n)fwrite(C)fwrite(n)fwrite(MC)

print nRandom graphs with random matching have been generated

44 Application

RandomGraphGeneratorpy

from future import divisionimport networkx as nxfrom networkxalgorithms import approximationimport collectionsimport randomimport mathif name == main

for i in range(1481)index=1n=randomrandint(100 1000)

n=1000m=0m1=0p=randomrandom()p1=mathlog(n2)np2=13p3=mathlog(n2)n+01p=05t1=randomrandint(0 1)print im2=randomrandint(n2minus1 n2+1)G = nxGraph()ma = nxGraph()print nme1=randomrandint(1 10)me2=randomrandint(2050)me3=randomrandint(50100)if ilt241

if ilt=80G=nxfast gnp random graph(n p1 seed=None directed=False)

elif igt80 and ilt161G=nxfast gnp random graph(n p2 seed=None directed=False)

elseG=nxfast gnp random graph(n p3 seed=None directed=False)

elseif ilt=320

G=nxbarabasi albert graph(n me1 seed=None)elif igt320 and ilt401

G=nxbarabasi albert graph(n me2 seed=None)else

G=nxbarabasi albert graph(n me3 seed=None)A=nxadjacency matrix(G)for ii in range(0n)

maadd node(ii)A=[Rtodense()tolist()[0] for R in A]

rl=randomsample(range(0n) n)m=0

Appendix A 45

done vertices = set()for p in rl

done verticesadd(p)neighbors = []list()for iii in range(0n)

if A[p][iii]==1neighborsappend(iii)

randomshuffle(neighbors)continue loop = Truedegree = len(neighbors)j = 0p2=randomrandom()while continue loop and (jltdegree)

next = neighbors[j]if next not in done vertices and p not in done vertices

done verticesadd(p)done verticesadd(next)if p2gt=00 Larger probability for smaller initial matching

maadd edge(pnext)m=m+1

continue loop = Falsej += 1

print matching listOfedgeprint maedgeMA=nxadjacency matrix(ma)MA=[Rtodense()tolist()[0] for R in MA]print MAB=[ join(map(strR)) for R in A]MB=[ join(map(strR)) for R in MA]

C=njoin(B)+nMC=njoin(MB)+nprint MCprint nprint mprint m1filea=str(i)+txtwith open(fileaw) as f

fwrite(str(n))fwrite(n)fwrite(str(n))fwrite(n)fwrite(str(m))fwrite(n)fwrite(n)fwrite(C)fwrite(n)fwrite(MC)

print nRandom graphs with random matching have been generated

46 Application

kequals3MaximumMatchingpy

from future import divisionimport networkx as nxfrom networkxalgorithms import bipartiteimport matplotlibpyplot as pltimport collectionsimport timeitimport xlwtimport xlrdimport mathimport sys

Case for General Graphsdef forced edges(Gadj dict2matching dict1num nodesforced)

flagg=0for n in range(0num nodes)

for k in adj dict2[n]if ([k]==matching dict1[n])

count=0for l in range(0num nodes)

count=count+adj dict2[l]count(k)if (len(adj dict2[n])==1) or (count==1)

forcedadd edge(nk)Gremove edge(nk)Gremove node(n)Gremove node(k)printforced edgenktemp=kflagg=1for m in range (len(adj dict2[n])minus1minus1minus1)

adj dict2[adj dict2[n][m]]remove(n)adj dict2[n]remove(adj dict2[n][m])

if adj dict2[temp]for l in range(len(adj dict2[temp])minus1minus1minus1)

if (adj dict2[temp][l]=n)adj dict2[adj dict2[temp][l]]remove(temp)adj dict2[temp]remove(adj dict2[temp][l])

break

def useless edges(num nodesadj dict1matching dict1uselessadj dict2G)for n in range(0num nodes)

for k in adj dict1[n]if ([k]=matching dict1[n]) and matching dict1[n] and matching dict1[k]

uselessadd edge(nk)Gremove edge(n k)

Appendix A 47

tempa=kadj dict2[n]remove(k)adj dict2[tempa]remove(n)adj dict1[tempa]remove(n)

return G

def Greedy(num nodesadj dict3matching dict2)

for n in range(0num nodes)if matching dict2[n]

flag2=minus1flag3=minus1for v in adj dict3[n]

if not matching dict2[v]flag2=vbreak

for p in adj dict3[matching dict2[n][0]]if not matching dict2[p]

flag3=pbreak

if (flag2=minus1) and (flag3=minus1) and (flag2=flag3)tempr=matching dict2[n][0]matching dict2[n]=[flag2]matching dict2[flag2]=[n]matching dict2[tempr]=[flag3]matching dict2[flag3]=[tempr]

elsefor k in adj dict3[n]

if not matching dict2[k]matching dict2[n]=[k]matching dict2[k]=[n]break

yo1=0for i in range(0num nodes)

if matching dict2[i] and [i]==matching dict2[matching dict2[i][0]]yo1=yo1+1

greedy size=yo12return greedy size

def General()

INPUTSwb = xlwtWorkbook()ws = wbadd sheet(Results Random)book=xlrdopen workbook(filenames randomxls)

48 Application

style0 = xlwteasyxf(fontbold on)style1 = xlwteasyxf(num format str=0000)INPUTSwswrite(0 0File style0)wswrite(0 1 Nodesstyle0)wswrite(0 2 Initial matchingstyle0)wswrite(0 3 NodesGstyle0)wswrite(0 4 EdgesGstyle0)wswrite(0 5 MaxDegreeGstyle0)wswrite(0 6 NodesG hatstyle0)wswrite(0 7 EdgesG Hatstyle0)wswrite(0 8 Useless edgesstyle0)wswrite(0 9 Forced edgesstyle0)wswrite(0 10 MaxDegreeG Hatstyle0)wswrite(0 11 Classical matchingstyle0)wswrite(0 12 Final matchingstyle0)wswrite(0 13 Greedy matchingstyle0)wswrite(0 14 Time classicalstyle0)wswrite(0 15 Time algorithmstyle0)wswrite(0 16 Time greedystyle0)wswrite(0 17 Perfect matching ratiostyle0)wswrite(0 18 Nodes ratiostyle0)wswrite(0 19 Edges ratiostyle0)wswrite(0 20 Matching ratiostyle0)

print nWelcomeThis is an implementation for general random graphs It uses Edmonds algorithm to compute maximum matching on G Hatn

for index in range (1481)was 481

if (index==482)f=open(Algotel generaltxtr)readlines()

elsefilea=str(booksheet by index(0)cell(index0))s=fileareplace(textu)replace()f=open(sr)readlines()Truewswrite(index 0 s)

print index

num nodes=int([xstrip()split() for x in f][0][0])

num matching=int([xstrip()split() for x in f][2][0])

adj temp = [xstrip()split() for x in f][44+num nodes]adj=[map(intR) for R in adj temp]

matching temp=[xstrip()split() for x in f][4+num nodes+14+2num nodes+1]matching1=[map(intR) for R in matching temp]

adj dict1=i[ii for iix in enumerate(L) if x] for iL in enumerate(adj)adj dict2=i[ii for iix in enumerate(L) if x] for iL in enumerate(adj)

Appendix A 49

adj dict3=i[ii for iix in enumerate(L) if x] for iL in enumerate(adj)

matching dict1=i[ii for iix in enumerate(L) if x] for iL in enumerate(matching1)matching dict2=i[ii for iix in enumerate(L) if x] for iL in enumerate(matching1)print adj dict2print matching dict2wswrite(index 1 num nodes)wswrite(index 2 num matching)

G = nxGraph()

useless= nxGraph()forced = nxGraph()

Fill Graphfor n in range(0num nodes)

for k in adj dict1[n]Gadd edge(nk)

Gt=Gnumber of edges()wswrite(index 3 Gnumber of nodes())wswrite(index 4 Gnumber of edges())wswrite(index 5 max(Gdegree()values()))

Compute Edmonds classical matching on G for comparison

startB = timeitdefault timer()Classical Matching=nxmax weight matching(G maxcardinality=False)stopB = timeitdefault timer()

Compute Gˆ nad MˆstartC = timeitdefault timer()useless edges(num nodesadj dict1matching dict1uselessadj dict2G)forced edges(Gadj dict2matching dict1num nodesforced)Final Matching=nxmax weight matching(G maxcardinality=False)stopC = timeitdefault timer()

GreedystartG = timeitdefault timer()greedy size=Greedy(num nodesadj dict3matching dict2)stopG = timeitdefault timer()

wswrite(index 6 Gnumber of nodes())wswrite(index 7 Gnumber of edges())wswrite(index 8 uselessnumber of edges())wswrite(index 9 forcednumber of edges())if Gdegree()values()

wswrite(index 10 max(Gdegree()values()))else

50 Application

wswrite(index 10 0)wswrite(index 11 len(Classical Matching)2)wswrite(index 12 len(Final Matching)2+forcednumber of edges())wswrite(index 13 greedy size)wswrite(index 14 stopB minus startBstyle1)wswrite(index 15 stopC minus startCstyle1)wswrite(index 16 stopG minus startGstyle1)wswrite(index 17 (len(Final Matching)2+forcednumber of edges())(num nodes2)style1)wswrite(index 18 Gnumber of nodes()Gtstyle1)wswrite(index 19 Gnumber of edges()Gtstyle1)wswrite(index 20 (len(Final Matching)2+forcednumber of edges())(len(Classical Matching)2)style1)

wbsave(AA Results Random Reyni Large Bipartitexls)

Main function Here we must choose the input form of the dataif name == main

startA = timeitdefault timer()General()stopA = timeitdefault timer()

print nThis program has terminatednnRunning time for 480 files stopAminusstartAprint nnPlease open AA Results Random Reyni Largexls file to see the Results

Appendix A 51

Plotmat

clear allclose allload(RN1Lmat)load(RN1Smat)load(RN2Lmat)load(RN2Smat)load(RN3Lmat)load(RN3Smat)

Plotsh(1)=figure(NameHistogram of Matching size difference between Constraint Algorithm and Greedy AlgorithmNumberTitleoff)

RN1L Greedydiff=RN1L Final matchingminusRN1L Greedy matchingRN2L Greedydiff=RN2L Final matchingminusRN2L Greedy matchingRN3L Greedydiff=RN3L Final matchingminusRN3L Greedy matchingRN1S Greedydiff=RN1S Final matchingminusRN1S Greedy matchingRN2S Greedydiff=RN2S Final matchingminusRN2S Greedy matchingRN3S Greedydiff=RN3S Final matchingminusRN3S Greedy matching

RN1L Finaldiff=RN1L Classical matchingminusRN1L Final matchingRN2L Finaldiff=RN2L Classical matchingminusRN2L Final matchingRN3L Finaldiff=RN3L Classical matchingminusRN3L Final matchingRN1S Finaldiff=RN1S Classical matchingminusRN1S Final matchingRN2S Finaldiff=RN2S Classical matchingminusRN2S Final matchingRN3S Finaldiff=RN3S Classical matchingminusRN3S Final matching

RN1L Classicaldiff=(RN1L Nodes2)minusRN1L Classical matchingRN2L Classicaldiff=(RN2L Nodes2)minusRN2L Classical matchingRN3L Classicaldiff=(RN3L Nodes2)minusRN3L Classical matchingRN1S Classicaldiff=(RN1S Nodes2)minusRN1S Classical matchingRN2S Classicaldiff=(RN2S Nodes2)minusRN2S Classical matchingRN3S Classicaldiff=(RN3S Nodes2)minusRN3S Classical matching

subplot(231)hold onhistf(RN1L Greedydiff0110facecolorbfacealpha9edgealpha1)histf(RN1L Finaldiff0110facecolorrfacealpha5edgealpha1)histf(RN1L Classicaldiff0110facecolorgfacealpha5edgealpha1)legalpha(ConminusGreClasminusConPerfminusClasslocationnortheast)legend boxoffaxis tightxlabel(edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN1L)grid on

subplot(232)hold onhistf(RN2L Greedydiff0110facecolorbfacealpha9edgealpha1)

52 Application

histf(RN2L Finaldiff0110facecolorrfacealpha5edgealpha1)histf(RN2L Classicaldiff0110facecolorgfacealpha5edgealpha1)legalpha(ConminusGreClasminusConPerfminusClasslocationnortheast)legend boxoffaxis tightxlabel(edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN2L)grid on

subplot(233)hold onhistf(RN3L Greedydiff0110facecolorbfacealpha5edgealpha1)histf(RN3L Finaldiff0110facecolorrfacealpha5edgealpha1)histf(RN3L Classicaldiff0110facecolorgfacealpha5edgealpha1)legalpha(ConminusGreClasminusConPerfminusClasslocationnortheast)legend boxoffaxis tightxlabel(edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN3L)grid on

subplot(234)hold onhistf(RN1S Greedydiff0110facecolorbfacealpha5edgealpha1)histf(RN1S Finaldiff0110facecolorrfacealpha5edgealpha1)histf(RN1S Classicaldiff0110facecolorgfacealpha5edgealpha1)legalpha(ConminusGreClasminusConPerfminusClasslocationnortheast)legend boxoffaxis tightxlabel(edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(R1NS)grid on

subplot(235)hold onhistf(RN2S Greedydiff0110facecolorbfacealpha5edgealpha1)histf(RN2S Finaldiff0110facecolorrfacealpha5edgealpha1)histf(RN2S Classicaldiff0110facecolorgfacealpha5edgealpha1)legalpha(ConminusGreClasminusConPerfminusClasslocationnortheast)legend boxoffaxis tightxlabel(edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN2S)grid on

subplot(236)hold onhistf(RN3S Greedydiff0110facecolorbfacealpha5edgealpha1)histf(RN3S Finaldiff0110facecolorrfacealpha5edgealpha1)histf(RN3S Classicaldiff0110facecolorgfacealpha5edgealpha1)

Appendix A 53

legalpha(ConminusGreClasminusConPerfminusClasslocationnortheast)legend boxoffaxis tightgrid ontitle(RN3S)xlabel(edges) xminusaxis labelylabel(instances) yminusaxis labelset(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN1png minusr300)h(2)=figure(NameHistogram of Max Degree of G AND G HatNumberTitleoff)RN1L x=RN1L MaxDegreeGminusRN1L MaxDegreeG HatRN2L x=RN2L MaxDegreeGminusRN2L MaxDegreeG HatRN3L x=RN3L MaxDegreeGminusRN3L MaxDegreeG HatRN1S x=RN1S MaxDegreeGminusRN1S MaxDegreeG HatRN2S x=RN2S MaxDegreeGminusRN2S MaxDegreeG HatRN3S x=RN3S MaxDegreeGminusRN3S MaxDegreeG Hatsubplot(231)hold onhistf(RN1L MaxDegreeG0150facecolorbfacealpha5edgealpha1)histf(RN1L MaxDegreeG Hat0150facecolorrfacealpha5edgealpha1)histf(RN1L x0150facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightxlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN1L)grid on

subplot(232)hold onhistf(RN2L MaxDegreeG010500facecolorbfacealpha5edgealpha1)histf(RN2L MaxDegreeG Hat010500facecolorrfacealpha5edgealpha1)histf(RN2L x010500facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightxlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN2L)grid on

subplot(233)hold onhistf(RN3L MaxDegreeG010300facecolorbfacealpha5edgealpha1)histf(RN3L MaxDegreeG Hat010300facecolorrfacealpha5edgealpha1)histf(RN3L x010300facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightxlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN3L)

54 Application

grid on

subplot(234)hold onhistf(RN1S MaxDegreeG0150facecolorbfacealpha5edgealpha1)histf(RN1S MaxDegreeG Hat0150facecolorrfacealpha5edgealpha1)histf(RN1S x0150facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightxlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(R1NS)grid on

subplot(235)hold onhistf(RN2S MaxDegreeG010500facecolorbfacealpha5edgealpha1)histf(RN2S MaxDegreeG Hat010500facecolorrfacealpha5edgealpha1)histf(RN2S x010500facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightxlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN2S)grid on

subplot(236)hold onhistf(RN3S MaxDegreeG05300facecolorbfacealpha5edgealpha1)histf(RN3S MaxDegreeG Hat05300facecolorrfacealpha5edgealpha1)histf(RN3S x05300facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightgrid ontitle(RN3S)xlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labelset(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN2png minusr300)

h(3)=figure(NameComputation time over edgesNumberTitleoff)

subplot(231)hold onstem(RN1L EdgesGRN1L Time classicalg)stem(RN1L EdgesGRN1L Time algorithmro)stem(RN1L EdgesGRN1L Time greedybx)grid on

Appendix A 55

title(RN1L)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)

subplot(232)hold onstem(RN2L EdgesGRN2L Time classicalg)stem(RN2L EdgesGRN2L Time algorithmro)stem(RN2L EdgesGRN2L Time greedybx)grid ontitle(RN2L)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)

subplot(233)hold onstem(RN3L EdgesGRN3L Time classicalg)stem(RN3L EdgesGRN3L Time algorithmro)stem(RN3L EdgesGRN3L Time greedybx)grid ontitle(RN3L)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)

subplot(234)hold onstem(RN1S EdgesGRN1S Time classicalg)stem(RN1S EdgesGRN1S Time algorithmro)stem(RN1S EdgesGRN1S Time greedybx)grid ontitle(RN1S)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)

subplot(235)hold onstem(RN2S EdgesGRN2S Time classicalg)stem(RN2S EdgesGRN2S Time algorithmro)stem(RN2S EdgesGRN2S Time greedybx)grid ontitle(RN2S)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)

subplot(236)hold onstem(RN3S EdgesGRN3S Time classicalg)stem(RN3S EdgesGRN3S Time algorithmro)stem(RN3S EdgesGRN3S Time greedybx)

56 Application

grid ontitle(RN3S)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)set(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN3png minusr300)

h(4)=figure(NameSorted matching sizeNumberTitleoff)RN1L Sorted matching temp(1)=RN1L Classical matchingRN1L Sorted matching temp(2)=RN1L Final matchingRN1L Sorted matching temp(3)=RN1L Greedy matchingRN1L Sorted matching temp(4)=RN1L Initial matchingRN1L Sorted matching=sortrows(RN1L Sorted matching temp)

RN2L Sorted matching temp(1)=RN2L Classical matchingRN2L Sorted matching temp(2)=RN2L Final matchingRN2L Sorted matching temp(3)=RN2L Greedy matchingRN2L Sorted matching temp(4)=RN2L Initial matchingRN2L Sorted matching=sortrows(RN2L Sorted matching temp)

RN3L Sorted matching temp(1)=RN3L Classical matchingRN3L Sorted matching temp(2)=RN3L Final matchingRN3L Sorted matching temp(3)=RN3L Greedy matchingRN3L Sorted matching temp(4)=RN3L Initial matchingRN3L Sorted matching=sortrows(RN3L Sorted matching temp)

RN1S Sorted matching temp(1)=RN1S Classical matchingRN1S Sorted matching temp(2)=RN1S Final matchingRN1S Sorted matching temp(3)=RN1S Greedy matchingRN1S Sorted matching temp(4)=RN1S Initial matchingRN1S Sorted matching=sortrows(RN1S Sorted matching temp)

RN2S Sorted matching temp(1)=RN2S Classical matchingRN2S Sorted matching temp(2)=RN2S Final matchingRN2S Sorted matching temp(3)=RN2S Greedy matchingRN2S Sorted matching temp(4)=RN2S Initial matchingRN2S Sorted matching=sortrows(RN2S Sorted matching temp)

RN3S Sorted matching temp(1)=RN3S Classical matchingRN3S Sorted matching temp(2)=RN3S Final matchingRN3S Sorted matching temp(3)=RN3S Greedy matchingRN3S Sorted matching temp(4)=RN3S Initial matchingRN3S Sorted matching=sortrows(RN3S Sorted matching temp)

subplot(231)hold onplot(RN1L Sorted matching(1)b)plot(RN1L Sorted matching(2)g)plot(RN1L Sorted matching(3)r)plot(RN1L Sorted matching(4)m)

Appendix A 57

grid ontitle(RN1L)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)

subplot(232)hold onplot(RN2L Sorted matching(1)b)plot(RN2L Sorted matching(2)g)plot(RN2L Sorted matching(3)r)plot(RN2L Sorted matching(4)m)grid ontitle(RN2L)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)

subplot(233)hold onplot(RN3L Sorted matching(1)b)plot(RN3L Sorted matching(2)g)plot(RN3L Sorted matching(3)r)plot(RN3L Sorted matching(4)m)grid ontitle(RN3L)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)

subplot(234)hold onplot(RN1S Sorted matching(1)b)plot(RN1S Sorted matching(2)g)plot(RN1S Sorted matching(3)r)plot(RN1S Sorted matching(4)m)grid ontitle(RN1S)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)

subplot(235)hold onplot(RN2S Sorted matching(1)b)plot(RN2S Sorted matching(2)g)plot(RN2S Sorted matching(3)r)plot(RN2S Sorted matching(4)m)grid ontitle(RN2S)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)

58 Application

subplot(236)hold onplot(RN3S Sorted matching(1)b)plot(RN3S Sorted matching(2)g)plot(RN3S Sorted matching(3)r)plot(RN3S Sorted matching(4)m)grid ontitle(RN3S)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)set(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN4png minusr300)h(5)=figure(NameSorted RatiosNumberTitleoff)RN1L ratio1=RN1L NodesG hatRN1L NodesGRN2L ratio1=RN2L NodesG hatRN2L NodesGRN3L ratio1=RN3L NodesG hatRN3L NodesGRN1S ratio1=RN1S NodesG hatRN1S NodesGRN2S ratio1=RN2S NodesG hatRN2S NodesGRN3S ratio1=RN3S NodesG hatRN3S NodesG

RN1L ratio2=RN1L EdgesG HatRN1L EdgesGRN2L ratio2=RN2L EdgesG HatRN2L EdgesGRN3L ratio2=RN3L EdgesG HatRN3L EdgesGRN1S ratio2=RN1S EdgesG HatRN1S EdgesGRN2S ratio2=RN2S EdgesG HatRN2S EdgesGRN3S ratio2=RN3S EdgesG HatRN3S EdgesG

RN1L ratio3=RN1L MaxDegreeG HatRN1L MaxDegreeGRN2L ratio3=RN2L MaxDegreeG HatRN2L MaxDegreeGRN3L ratio3=RN3L MaxDegreeG HatRN3L MaxDegreeGRN1S ratio3=RN1S MaxDegreeG HatRN1S MaxDegreeGRN2S ratio3=RN2S MaxDegreeG HatRN2S MaxDegreeGRN3S ratio3=RN3S MaxDegreeG HatRN3S MaxDegreeG

RN1L ratio(1)=RN1L ratio1RN1L ratio(2)=RN1L ratio2RN1L ratio(3)=RN1L ratio3

RN2L ratio(1)=RN2L ratio1RN2L ratio(2)=RN2L ratio2RN2L ratio(3)=RN2L ratio3

RN3L ratio(1)=RN3L ratio1RN3L ratio(2)=RN3L ratio2RN3L ratio(3)=RN3L ratio3

RN1S ratio(1)=RN1S ratio1RN1S ratio(2)=RN1S ratio2RN1S ratio(3)=RN1S ratio3

RN2S ratio(1)=RN2S ratio1

Appendix A 59

RN2S ratio(2)=RN2S ratio2RN2S ratio(3)=RN2S ratio3

RN3S ratio(1)=RN3S ratio1RN3S ratio(2)=RN3S ratio2RN3S ratio(3)=RN3S ratio3

RN1L ratio sorted=sortrows(RN1L ratio)RN2L ratio sorted=sortrows(RN2L ratio)RN3L ratio sorted=sortrows(RN3L ratio)RN1S ratio sorted=sortrows(RN1S ratio)RN2S ratio sorted=sortrows(RN2S ratio)RN3S ratio sorted=sortrows(RN3S ratio)

subplot(231)hold onplot(RN1L ratio sorted(1)b)plot(RN1L ratio sorted(2)g)plot(RN1L ratio sorted(3)r)grid ontitle(RN1L)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)

subplot(232)hold onplot(RN2L ratio sorted(1)b)plot(RN2L ratio sorted(2)g)plot(RN2L ratio sorted(3)r)grid ontitle(RN2L)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)

subplot(233)hold onplot(RN3L ratio sorted(1)b)plot(RN3L ratio sorted(2)g)plot(RN3L ratio sorted(3)r)grid ontitle(RN3L)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)

subplot(234)hold onplot(RN1S ratio sorted(1)b)plot(RN1S ratio sorted(2)g)plot(RN1S ratio sorted(3)r)grid on

60 Application

title(RN1S)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)

subplot(235)hold onplot(RN2S ratio sorted(1)b)plot(RN2S ratio sorted(2)g)plot(RN2S ratio sorted(3)r)grid ontitle(RN2S)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)

subplot(236)hold onplot(RN3S ratio sorted(1)b)plot(RN3S ratio sorted(2)g)plot(RN3S ratio sorted(3)r)grid ontitle(RN3S)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)set(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN5png minusr300)

h(6)=figure(NameSorted edges over nodesNumberTitleoff)

RN1L DegreeG1=(RN1L EdgesG)(RN1L NodesG)RN1L DegreeG Hat1=(RN1L EdgesG Hat)(RN1L NodesG hat)

RN1L Degree temp1(1)=RN1L DegreeG1RN1L Degree temp1(2)=RN1L DegreeG Hat1RN1L Degree sorted1=sortrows(RN1L Degree temp1)subplot(231)hold on

plot(RN1L Degree sorted1(1)b)plot(RN1L Degree sorted1(2)g)grid ontitle(RN1L)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)

RN2L DegreeG1=(RN2L EdgesG)(RN2L NodesG)RN2L DegreeG Hat1=(RN2L EdgesG Hat)(RN2L NodesG hat)

RN2L Degree temp1(1)=RN2L DegreeG1

Appendix A 61

RN2L Degree temp1(2)=RN2L DegreeG Hat1RN2L Degree sorted1=sortrows(RN2L Degree temp1)

subplot(232)hold onplot(RN2L Degree sorted1(1)b)plot(RN2L Degree sorted1(2)g)grid ontitle(RN2L)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)

RN3L DegreeG1=(RN3L EdgesG)(RN3L NodesG)RN3L DegreeG Hat1=(RN3L EdgesG Hat)(RN3L NodesG hat)

RN3L Degree temp1(1)=RN3L DegreeG1RN3L Degree temp1(2)=RN3L DegreeG Hat1RN3L Degree sorted1=sortrows(RN3L Degree temp1)

subplot(233)hold onplot(RN3L Degree sorted1(1)b)plot(RN3L Degree sorted1(2)g)grid ontitle(RN3L)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)

RN1S DegreeG1=(RN1S EdgesG)(RN1S NodesG)RN1S DegreeG Hat1=(RN1S EdgesG Hat)(RN1S NodesG hat)

RN1S Degree temp1(1)=RN1S DegreeG1RN1S Degree temp1(2)=RN1S DegreeG Hat1RN1S Degree sorted1=sortrows(RN1S Degree temp1)

subplot(234)hold onplot(RN1S Degree sorted1(1)b)plot(RN1S Degree sorted1(2)g)grid ontitle(RN1S)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)

RN2S DegreeG1=(RN2S EdgesG)(RN2S NodesG)RN2S DegreeG Hat1=(RN2S EdgesG Hat)(RN2S NodesG hat)

RN2S Degree temp1(1)=RN2S DegreeG1

62 Application

RN2S Degree temp1(2)=RN2S DegreeG Hat1RN2S Degree sorted1=sortrows(RN2S Degree temp1)

subplot(235)hold onplot(RN2S Degree sorted1(1)b)plot(RN2S Degree sorted1(2)g)grid ontitle(RN2S)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)

RN3S DegreeG1=(RN3S EdgesG)(RN3S NodesG)RN3S DegreeG Hat1=(RN3S EdgesG Hat)(RN3S NodesG hat)

RN3S Degree temp1(1)=RN3S DegreeG1RN3S Degree temp1(2)=RN3S DegreeG Hat1RN3S Degree sorted1=sortrows(RN3S Degree temp1)

subplot(236)hold onplot(RN3S Degree sorted1(1)b)plot(RN3S Degree sorted1(2)g)grid ontitle(RN3S)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)set(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN6png minusr300)h(7)=figure(NameSorted mATCHED DEGREENumberTitleoff)RN1L ratioMax(1)=RN1L MaxDegreeGRN1L ratioMax(2)=RN1L MaxDegreeG Hat

RN1L ratio sortedMax=sortrows(RN1L ratioMax)subplot(231)hold onplot(RN1L ratio sortedMax(1)b)plot(RN1L ratio sortedMax(2)g)grid ontitle(RN1L)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)

RN2L ratioMax(1)=RN2L MaxDegreeGRN2L ratioMax(2)=RN2L MaxDegreeG Hat

RN2L ratio sortedMax=sortrows(RN2L ratioMax)subplot(232)

Appendix A 63

hold onplot(RN2L ratio sortedMax(1)b)plot(RN2L ratio sortedMax(2)g)grid ontitle(RN2L)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)

RN3L ratioMax(1)=RN3L MaxDegreeGRN3L ratioMax(2)=RN3L MaxDegreeG Hat

RN3L ratio sortedMax=sortrows(RN3L ratioMax)subplot(233)hold onplot(RN3L ratio sortedMax(1)b)plot(RN3L ratio sortedMax(2)g)grid ontitle(RN3L)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)

RN1S ratioMax(1)=RN1S MaxDegreeGRN1S ratioMax(2)=RN1S MaxDegreeG Hat

RN1S ratio sortedMax=sortrows(RN1S ratioMax)subplot(234)hold onplot(RN1S ratio sortedMax(1)b)plot(RN1S ratio sortedMax(2)g)grid ontitle(RN1S)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)

RN2S ratioMax(1)=RN2S MaxDegreeGRN2S ratioMax(2)=RN2S MaxDegreeG Hat

RN2S ratio sortedMax=sortrows(RN2S ratioMax)

subplot(235)hold onplot(RN2S ratio sortedMax(1)b)plot(RN2S ratio sortedMax(2)g)grid ontitle(RN2S)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)

RN3S ratioMax(1)=RN3S MaxDegreeGRN3S ratioMax(2)=RN3S MaxDegreeG Hat

64 Application

RN3S ratio sortedMax=sortrows(RN3S ratioMax)subplot(236)hold onplot(RN3S ratio sortedMax(1)b)plot(RN3S ratio sortedMax(2)g)grid ontitle(RN1L)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)set(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN7png minusr300)

tilefigs()(h)

Bibliography

[1] C Berge ldquoTWO THEOREMS IN GRAPH THEORYrdquo Proceedings of the NationalAcademy of Sciences of the United States of America vol 43 no 9 pp 842ndash844Sep 1957

[2] L Bui S Sanghavi and R Srikant ldquoDistributed link scheduling with constantoverheadrdquo IEEEACM Trans Netw vol 17 no 5 pp 1467ndash1480 2009

[3] R Duan and S Pettie ldquoLinear-time approximation for maximum weight matchingrdquoJ ACM vol 61 no 1 2014

[4] J Edmonds ldquoPaths trees and flowersrdquo Canadian Journal of Mathematics vol 17pp 449ndash467 1965

[5] J E Hopcroft and R M Karp ldquoAn n52 algorithm for maximum matchings inbipartite graphsrdquo SIAM J Comput vol 2 no 4 pp 225ndash231 1973

[6] S Micali and V V Vazirani ldquoAn O(radic|V ||E|) algorithm for finding maximum

matching in general graphsrdquo in 21st Symp on Foundations of Comp Sc (FOCS)IEEE 1980 pp 17ndash27

[7] N Nisse A Salch and V Weber ldquoRecovery of disrupted airline operationsrdquo 2015httphalinriafrSomething

[8] X Wu and R Srikant ldquoRegulated maximal matching A distributed schedulingalgorithm for multi-hop wireless networks with nodeexclusive spectrum sharingrdquo inIEEE Conf on Decision and Control 2005

65

  • Contents
  • Introduction
  • Algorithms
    • Maximum matching
    • k-maximum matching
      • k-matching for Airport Slot assignment
      • The case where k=3
      • The case of Paths
      • The case of the Spider
          • Application
            • Description
            • Reyni Erdos
            • Barabaacutesi Albert
            • Amadeus Graphs
            • Bipartite
            • Bipartite with degree seq
            • Appendix A
              • BipartiteGraphGeneratorpy
              • RandomGraphGeneratorpy
              • kequals3MaximumMatchingpy
              • Plotmat
                  • Bibliography
Page 27: Theodoros Alexandros KARAGKIOULES -  · Introduction This work is the result of a 6 months internship, under the supervision of research O cer Nicolas NISSE. The original scope of

28 Application

bull Probability p has been chosen as such in order to simulate the |E||V | 25 of theAmadeus bipartite graphs

bull So in order to have about 2-4 edges for every node we choose accordingly theprobability p to choose one of the n lowastm possible edges

bull x = L S L When the initial matching is large and S when it is small

bull y = 1 2 3 1 when p = 18250

2 when p = 25250

and 3 when p = 34250

Computation time over

Computation time overedges-Comments

bull

25 Bipartite 29

Sorted matching size

Sorted matching size-Comments

bull In these set of graphs one can instantly notice that only a few instances with highprobability can reach a matching size equal to the perfect matching

bull For the case of the initial matching we witness that there is a gap between the lineof the classical matching and those of the constraint and greedy results suggestingsmaller matching sizes of 10-40 edges

bull For the case of the small initial matching the result of the constraint matchingis now close to the result of the classical matching yet the greedy algorithm stillshows a relevantly big difference

30 Application

bull In this set of bipartite graphs we can witness that the result of the Constraintmatching shows a difference with the classical matching when the initial matchingis large The difference is smaller as the probability gets larger

bull For the case of the small initial matching the above phenomenom does not occuryet the greedy results deviates from that of the constraint matching

bull As per the pefrect matching compared to the classical matching a difference of5-10 edges is evident at almost all cases

Sorted Ratios

Sorted Ratios-Comments

bull Great max degree deviation

25 Bipartite 31

bull Regardless of the probability the ration of nodes and edges seems to have similarbehaviour when compared to the respective graphs of the same matching scale

bull Same gap between nodes ration and edges ration for all cases

Sorted |E||V |

Sorted |E||V | - Comments

bull In these set of figures we witness that the |E||V | acquires values relevant to those ofthe amadeus graphs The random graphs were constructed to depict this similarity

bull For smaller initial matching the ratios for G and G show the same upward trendand also they acquire closer values It represents the decrease of the averagenumber of forced edges in comparison to the larger matching cases

32 Application

Sorted ∆

Sorted ∆-Comments

bull ∆ acquires the same min and max values for each probability case (expected)

bull Gap in the case of large initial matching

26 Bipartite with degree seq

Graph characteristics

bull DEQBIPxy are randomly generated graphs based on three different types of degreedistribution of the Amadeus graphs

26 Bipartite with degree seq 33

bull There are 6 categories based on ini matching and degree distribution

bull x = L S L When the initial matching is large and S when it is small

bull y = 1 2 3 1 when degree distribution is based on file 2 when degree distributionis based on file and 3 when degree distribution is based on file

Computation time over

34 Application

Computation time overedges-Comments

bull Greedy algorithm takes minimum amount of time

bull The smaller the initial matching the more smaller the difference in comoutationtime of Constraint and classical algorithm

bull Due to preprocessing and the fact that G and G are the almost identical thetotal time needed to apply the constraint algorithm is in some cases bigger

Sorted matching size

26 Bipartite with degree seq 35

Sorted matching size-Comments

bull Classical matching is equal to perfect matching in every case

bull Constraint and greedy have identical behaviour

bull The larger the spectrum of the degree sequence the more efficient the matching

Sorted Ratios

36 Application

Sorted Ratios-Comments

bull With large initial matching most of the edges are considenred uselles or forced andare removed thus the ratio is close(if not equal to) zero

bull For small matching and large degree sequence sectrum hte max degree remainsthe same Only a few forced edges (and their nodes) are removed apparently nonodes with max degree

Sorted |E||V |

26 Bipartite with degree seq 37

Sorted |E||V | - Comments

bull In these set of figures we witness that the |E||V | acquires values relevant to those ofthe amadeus graphs The random graphs were constructed to depict this similarity

bull For smaller initial matching the ratios for G and G show the same upward trendand also they acquire closer values It repsresent the decrease of the averagenumber of forced edges in comparison to the larger matching cases

Sorted ∆

38 Application

Sorted ∆-Comments

bull Big difference in max degree in large initial matching

bull Almost identical behaviour in the case of small initial matching

Appendix A 39

Appendix A

BipartiteGraphGeneratorpy

from future import divisionimport networkx as nx

from networkxalgorithms import approximationimport collectionsimport randomimport mathfrom networkxalgorithms import bipartiteif name == main

for i in range(1481)waqs 481index=1n=randomrandint(100 1000)

n1=95 was 500me1=118

n2=251 was 500me2=903

n3=165 was 500me3=412

m=0m1=0p=randomrandom()p1=18250p2=25250p3=34250print ip=05t1=randomrandint(0 1)print im2=randomrandint(n2minus1 n2+1)G = nxGraph()ma = nxGraph()

aseq1=[1 2 3 4 5 3]

bseq1=[4 3 3 1 2 2 1]

aseq2=[16 14 14 14 12 11]bseq2=[0 0 0 0 0 0]

aseq3=[8 7 8 8 8 8]bseq3=[0 0 0 0 0 0]

40 Application

print Gnumber of edges()if ilt=160

G=bipartiteconfiguration model(aseq1 bseq1 create using=None seed=None)A=nxadjacency matrix(G)for ii in range(0n1+me1)

maadd node(ii)A=[Rtodense()tolist()[0] for R in A]

printnummanumber of nodes()rl=randomsample(range(0n1+me1) n1+me1)m=0done vertices = set()for p in rlprintin fordone verticesadd(p)

neighbors = []list()for iii in range(0n1+me1)

if A[p][iii]==1neighborsappend(iii)

randomshuffle(neighbors)continue loop = Truedegree = len(neighbors)

print degreej = 0p4=randomrandom()while continue loop and (jltdegree)print in loop

next = neighbors[j]if next not in done vertices and p not in done vertices

done verticesadd(p)done verticesadd(next)if p4gt=07print added edge

maadd edge(pnext)m=m+1

continue loop = Falsej += 1

print matching listOfedgeprint maedge

MA=nxadjacency matrix(ma)print MA

MA=[Rtodense()tolist()[0] for R in MA]print MA

B=[ join(map(strR)) for R in A]MB=[ join(map(strR)) for R in MA]

C=njoin(B)+nMC=njoin(MB)+n

print nprint mprint m1

filea=str(i)+txtwith open(fileaw) as f

Appendix A 41

fwrite(str(n1+me1))fwrite(n)fwrite(str(n1+me1))fwrite(n)fwrite(str(m))fwrite(n)fwrite(n)fwrite(C)fwrite(n)fwrite(MC)

elif igt160 and ilt321G=bipartiteconfiguration model(aseq2 bseq2 create using=None seed=None)A=nxadjacency matrix(G)for ii in range(0n2+me2)

maadd node(ii)A=[Rtodense()tolist()[0] for R in A]

printnummanumber of nodes()rl=randomsample(range(0n2+me2) n2+me2)m=0done vertices = set()for p in rlprintin fordone verticesadd(p)

neighbors = []list()for iii in range(0n2+me2)

if A[p][iii]==1neighborsappend(iii)

randomshuffle(neighbors)continue loop = Truedegree = len(neighbors)

print degreej = 0p4=randomrandom()while continue loop and (jltdegree)

print in loopnext = neighbors[j]if next not in done vertices and p not in done vertices

done verticesadd(p)done verticesadd(next)if p4gt=07

print added edgemaadd edge(pnext)m=m+1

continue loop = Falsej += 1

print matching listOfedgeprint maedge

MA=nxadjacency matrix(ma)print MA

MA=[Rtodense()tolist()[0] for R in MA]print MA

B=[ join(map(strR)) for R in A]MB=[ join(map(strR)) for R in MA]

42 Application

C=njoin(B)+nMC=njoin(MB)+n

print nprint mprint m1

filea=str(i)+txtwith open(fileaw) as f

fwrite(str(n2+me2))fwrite(n)fwrite(str(n2+me2))fwrite(n)fwrite(str(m))fwrite(n)fwrite(n)fwrite(C)fwrite(n)fwrite(MC)

elseG=bipartiteconfiguration model(aseq3 bseq3 create using=None seed=None)A=nxadjacency matrix(G)for ii in range(0n3+me3)

maadd node(ii)A=[Rtodense()tolist()[0] for R in A]

printnummanumber of nodes()rl=randomsample(range(0n3+me3) n3+me3)m=0done vertices = set()for p in rlprintin fordone verticesadd(p)

neighbors = []list()for iii in range(0n3+me3)

if A[p][iii]==1neighborsappend(iii)

randomshuffle(neighbors)continue loop = Truedegree = len(neighbors)

print degreej = 0p4=randomrandom()while continue loop and (jltdegree)

print in loopnext = neighbors[j]if next not in done vertices and p not in done vertices

done verticesadd(p)done verticesadd(next)if p4gt=07print added edge

maadd edge(pnext)m=m+1

continue loop = Falsej += 1

Appendix A 43

print matching listOfedgeprint maedge

MA=nxadjacency matrix(ma)print MA

MA=[Rtodense()tolist()[0] for R in MA]print MA

B=[ join(map(strR)) for R in A]MB=[ join(map(strR)) for R in MA]

C=njoin(B)+nMC=njoin(MB)+n

print nprint mprint m1

filea=str(i)+txtwith open(fileaw) as f

fwrite(str(n3+me3))fwrite(n)fwrite(str(n3+me3))fwrite(n)fwrite(str(m))fwrite(n)fwrite(n)fwrite(C)fwrite(n)fwrite(MC)

print nRandom graphs with random matching have been generated

44 Application

RandomGraphGeneratorpy

from future import divisionimport networkx as nxfrom networkxalgorithms import approximationimport collectionsimport randomimport mathif name == main

for i in range(1481)index=1n=randomrandint(100 1000)

n=1000m=0m1=0p=randomrandom()p1=mathlog(n2)np2=13p3=mathlog(n2)n+01p=05t1=randomrandint(0 1)print im2=randomrandint(n2minus1 n2+1)G = nxGraph()ma = nxGraph()print nme1=randomrandint(1 10)me2=randomrandint(2050)me3=randomrandint(50100)if ilt241

if ilt=80G=nxfast gnp random graph(n p1 seed=None directed=False)

elif igt80 and ilt161G=nxfast gnp random graph(n p2 seed=None directed=False)

elseG=nxfast gnp random graph(n p3 seed=None directed=False)

elseif ilt=320

G=nxbarabasi albert graph(n me1 seed=None)elif igt320 and ilt401

G=nxbarabasi albert graph(n me2 seed=None)else

G=nxbarabasi albert graph(n me3 seed=None)A=nxadjacency matrix(G)for ii in range(0n)

maadd node(ii)A=[Rtodense()tolist()[0] for R in A]

rl=randomsample(range(0n) n)m=0

Appendix A 45

done vertices = set()for p in rl

done verticesadd(p)neighbors = []list()for iii in range(0n)

if A[p][iii]==1neighborsappend(iii)

randomshuffle(neighbors)continue loop = Truedegree = len(neighbors)j = 0p2=randomrandom()while continue loop and (jltdegree)

next = neighbors[j]if next not in done vertices and p not in done vertices

done verticesadd(p)done verticesadd(next)if p2gt=00 Larger probability for smaller initial matching

maadd edge(pnext)m=m+1

continue loop = Falsej += 1

print matching listOfedgeprint maedgeMA=nxadjacency matrix(ma)MA=[Rtodense()tolist()[0] for R in MA]print MAB=[ join(map(strR)) for R in A]MB=[ join(map(strR)) for R in MA]

C=njoin(B)+nMC=njoin(MB)+nprint MCprint nprint mprint m1filea=str(i)+txtwith open(fileaw) as f

fwrite(str(n))fwrite(n)fwrite(str(n))fwrite(n)fwrite(str(m))fwrite(n)fwrite(n)fwrite(C)fwrite(n)fwrite(MC)

print nRandom graphs with random matching have been generated

46 Application

kequals3MaximumMatchingpy

from future import divisionimport networkx as nxfrom networkxalgorithms import bipartiteimport matplotlibpyplot as pltimport collectionsimport timeitimport xlwtimport xlrdimport mathimport sys

Case for General Graphsdef forced edges(Gadj dict2matching dict1num nodesforced)

flagg=0for n in range(0num nodes)

for k in adj dict2[n]if ([k]==matching dict1[n])

count=0for l in range(0num nodes)

count=count+adj dict2[l]count(k)if (len(adj dict2[n])==1) or (count==1)

forcedadd edge(nk)Gremove edge(nk)Gremove node(n)Gremove node(k)printforced edgenktemp=kflagg=1for m in range (len(adj dict2[n])minus1minus1minus1)

adj dict2[adj dict2[n][m]]remove(n)adj dict2[n]remove(adj dict2[n][m])

if adj dict2[temp]for l in range(len(adj dict2[temp])minus1minus1minus1)

if (adj dict2[temp][l]=n)adj dict2[adj dict2[temp][l]]remove(temp)adj dict2[temp]remove(adj dict2[temp][l])

break

def useless edges(num nodesadj dict1matching dict1uselessadj dict2G)for n in range(0num nodes)

for k in adj dict1[n]if ([k]=matching dict1[n]) and matching dict1[n] and matching dict1[k]

uselessadd edge(nk)Gremove edge(n k)

Appendix A 47

tempa=kadj dict2[n]remove(k)adj dict2[tempa]remove(n)adj dict1[tempa]remove(n)

return G

def Greedy(num nodesadj dict3matching dict2)

for n in range(0num nodes)if matching dict2[n]

flag2=minus1flag3=minus1for v in adj dict3[n]

if not matching dict2[v]flag2=vbreak

for p in adj dict3[matching dict2[n][0]]if not matching dict2[p]

flag3=pbreak

if (flag2=minus1) and (flag3=minus1) and (flag2=flag3)tempr=matching dict2[n][0]matching dict2[n]=[flag2]matching dict2[flag2]=[n]matching dict2[tempr]=[flag3]matching dict2[flag3]=[tempr]

elsefor k in adj dict3[n]

if not matching dict2[k]matching dict2[n]=[k]matching dict2[k]=[n]break

yo1=0for i in range(0num nodes)

if matching dict2[i] and [i]==matching dict2[matching dict2[i][0]]yo1=yo1+1

greedy size=yo12return greedy size

def General()

INPUTSwb = xlwtWorkbook()ws = wbadd sheet(Results Random)book=xlrdopen workbook(filenames randomxls)

48 Application

style0 = xlwteasyxf(fontbold on)style1 = xlwteasyxf(num format str=0000)INPUTSwswrite(0 0File style0)wswrite(0 1 Nodesstyle0)wswrite(0 2 Initial matchingstyle0)wswrite(0 3 NodesGstyle0)wswrite(0 4 EdgesGstyle0)wswrite(0 5 MaxDegreeGstyle0)wswrite(0 6 NodesG hatstyle0)wswrite(0 7 EdgesG Hatstyle0)wswrite(0 8 Useless edgesstyle0)wswrite(0 9 Forced edgesstyle0)wswrite(0 10 MaxDegreeG Hatstyle0)wswrite(0 11 Classical matchingstyle0)wswrite(0 12 Final matchingstyle0)wswrite(0 13 Greedy matchingstyle0)wswrite(0 14 Time classicalstyle0)wswrite(0 15 Time algorithmstyle0)wswrite(0 16 Time greedystyle0)wswrite(0 17 Perfect matching ratiostyle0)wswrite(0 18 Nodes ratiostyle0)wswrite(0 19 Edges ratiostyle0)wswrite(0 20 Matching ratiostyle0)

print nWelcomeThis is an implementation for general random graphs It uses Edmonds algorithm to compute maximum matching on G Hatn

for index in range (1481)was 481

if (index==482)f=open(Algotel generaltxtr)readlines()

elsefilea=str(booksheet by index(0)cell(index0))s=fileareplace(textu)replace()f=open(sr)readlines()Truewswrite(index 0 s)

print index

num nodes=int([xstrip()split() for x in f][0][0])

num matching=int([xstrip()split() for x in f][2][0])

adj temp = [xstrip()split() for x in f][44+num nodes]adj=[map(intR) for R in adj temp]

matching temp=[xstrip()split() for x in f][4+num nodes+14+2num nodes+1]matching1=[map(intR) for R in matching temp]

adj dict1=i[ii for iix in enumerate(L) if x] for iL in enumerate(adj)adj dict2=i[ii for iix in enumerate(L) if x] for iL in enumerate(adj)

Appendix A 49

adj dict3=i[ii for iix in enumerate(L) if x] for iL in enumerate(adj)

matching dict1=i[ii for iix in enumerate(L) if x] for iL in enumerate(matching1)matching dict2=i[ii for iix in enumerate(L) if x] for iL in enumerate(matching1)print adj dict2print matching dict2wswrite(index 1 num nodes)wswrite(index 2 num matching)

G = nxGraph()

useless= nxGraph()forced = nxGraph()

Fill Graphfor n in range(0num nodes)

for k in adj dict1[n]Gadd edge(nk)

Gt=Gnumber of edges()wswrite(index 3 Gnumber of nodes())wswrite(index 4 Gnumber of edges())wswrite(index 5 max(Gdegree()values()))

Compute Edmonds classical matching on G for comparison

startB = timeitdefault timer()Classical Matching=nxmax weight matching(G maxcardinality=False)stopB = timeitdefault timer()

Compute Gˆ nad MˆstartC = timeitdefault timer()useless edges(num nodesadj dict1matching dict1uselessadj dict2G)forced edges(Gadj dict2matching dict1num nodesforced)Final Matching=nxmax weight matching(G maxcardinality=False)stopC = timeitdefault timer()

GreedystartG = timeitdefault timer()greedy size=Greedy(num nodesadj dict3matching dict2)stopG = timeitdefault timer()

wswrite(index 6 Gnumber of nodes())wswrite(index 7 Gnumber of edges())wswrite(index 8 uselessnumber of edges())wswrite(index 9 forcednumber of edges())if Gdegree()values()

wswrite(index 10 max(Gdegree()values()))else

50 Application

wswrite(index 10 0)wswrite(index 11 len(Classical Matching)2)wswrite(index 12 len(Final Matching)2+forcednumber of edges())wswrite(index 13 greedy size)wswrite(index 14 stopB minus startBstyle1)wswrite(index 15 stopC minus startCstyle1)wswrite(index 16 stopG minus startGstyle1)wswrite(index 17 (len(Final Matching)2+forcednumber of edges())(num nodes2)style1)wswrite(index 18 Gnumber of nodes()Gtstyle1)wswrite(index 19 Gnumber of edges()Gtstyle1)wswrite(index 20 (len(Final Matching)2+forcednumber of edges())(len(Classical Matching)2)style1)

wbsave(AA Results Random Reyni Large Bipartitexls)

Main function Here we must choose the input form of the dataif name == main

startA = timeitdefault timer()General()stopA = timeitdefault timer()

print nThis program has terminatednnRunning time for 480 files stopAminusstartAprint nnPlease open AA Results Random Reyni Largexls file to see the Results

Appendix A 51

Plotmat

clear allclose allload(RN1Lmat)load(RN1Smat)load(RN2Lmat)load(RN2Smat)load(RN3Lmat)load(RN3Smat)

Plotsh(1)=figure(NameHistogram of Matching size difference between Constraint Algorithm and Greedy AlgorithmNumberTitleoff)

RN1L Greedydiff=RN1L Final matchingminusRN1L Greedy matchingRN2L Greedydiff=RN2L Final matchingminusRN2L Greedy matchingRN3L Greedydiff=RN3L Final matchingminusRN3L Greedy matchingRN1S Greedydiff=RN1S Final matchingminusRN1S Greedy matchingRN2S Greedydiff=RN2S Final matchingminusRN2S Greedy matchingRN3S Greedydiff=RN3S Final matchingminusRN3S Greedy matching

RN1L Finaldiff=RN1L Classical matchingminusRN1L Final matchingRN2L Finaldiff=RN2L Classical matchingminusRN2L Final matchingRN3L Finaldiff=RN3L Classical matchingminusRN3L Final matchingRN1S Finaldiff=RN1S Classical matchingminusRN1S Final matchingRN2S Finaldiff=RN2S Classical matchingminusRN2S Final matchingRN3S Finaldiff=RN3S Classical matchingminusRN3S Final matching

RN1L Classicaldiff=(RN1L Nodes2)minusRN1L Classical matchingRN2L Classicaldiff=(RN2L Nodes2)minusRN2L Classical matchingRN3L Classicaldiff=(RN3L Nodes2)minusRN3L Classical matchingRN1S Classicaldiff=(RN1S Nodes2)minusRN1S Classical matchingRN2S Classicaldiff=(RN2S Nodes2)minusRN2S Classical matchingRN3S Classicaldiff=(RN3S Nodes2)minusRN3S Classical matching

subplot(231)hold onhistf(RN1L Greedydiff0110facecolorbfacealpha9edgealpha1)histf(RN1L Finaldiff0110facecolorrfacealpha5edgealpha1)histf(RN1L Classicaldiff0110facecolorgfacealpha5edgealpha1)legalpha(ConminusGreClasminusConPerfminusClasslocationnortheast)legend boxoffaxis tightxlabel(edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN1L)grid on

subplot(232)hold onhistf(RN2L Greedydiff0110facecolorbfacealpha9edgealpha1)

52 Application

histf(RN2L Finaldiff0110facecolorrfacealpha5edgealpha1)histf(RN2L Classicaldiff0110facecolorgfacealpha5edgealpha1)legalpha(ConminusGreClasminusConPerfminusClasslocationnortheast)legend boxoffaxis tightxlabel(edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN2L)grid on

subplot(233)hold onhistf(RN3L Greedydiff0110facecolorbfacealpha5edgealpha1)histf(RN3L Finaldiff0110facecolorrfacealpha5edgealpha1)histf(RN3L Classicaldiff0110facecolorgfacealpha5edgealpha1)legalpha(ConminusGreClasminusConPerfminusClasslocationnortheast)legend boxoffaxis tightxlabel(edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN3L)grid on

subplot(234)hold onhistf(RN1S Greedydiff0110facecolorbfacealpha5edgealpha1)histf(RN1S Finaldiff0110facecolorrfacealpha5edgealpha1)histf(RN1S Classicaldiff0110facecolorgfacealpha5edgealpha1)legalpha(ConminusGreClasminusConPerfminusClasslocationnortheast)legend boxoffaxis tightxlabel(edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(R1NS)grid on

subplot(235)hold onhistf(RN2S Greedydiff0110facecolorbfacealpha5edgealpha1)histf(RN2S Finaldiff0110facecolorrfacealpha5edgealpha1)histf(RN2S Classicaldiff0110facecolorgfacealpha5edgealpha1)legalpha(ConminusGreClasminusConPerfminusClasslocationnortheast)legend boxoffaxis tightxlabel(edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN2S)grid on

subplot(236)hold onhistf(RN3S Greedydiff0110facecolorbfacealpha5edgealpha1)histf(RN3S Finaldiff0110facecolorrfacealpha5edgealpha1)histf(RN3S Classicaldiff0110facecolorgfacealpha5edgealpha1)

Appendix A 53

legalpha(ConminusGreClasminusConPerfminusClasslocationnortheast)legend boxoffaxis tightgrid ontitle(RN3S)xlabel(edges) xminusaxis labelylabel(instances) yminusaxis labelset(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN1png minusr300)h(2)=figure(NameHistogram of Max Degree of G AND G HatNumberTitleoff)RN1L x=RN1L MaxDegreeGminusRN1L MaxDegreeG HatRN2L x=RN2L MaxDegreeGminusRN2L MaxDegreeG HatRN3L x=RN3L MaxDegreeGminusRN3L MaxDegreeG HatRN1S x=RN1S MaxDegreeGminusRN1S MaxDegreeG HatRN2S x=RN2S MaxDegreeGminusRN2S MaxDegreeG HatRN3S x=RN3S MaxDegreeGminusRN3S MaxDegreeG Hatsubplot(231)hold onhistf(RN1L MaxDegreeG0150facecolorbfacealpha5edgealpha1)histf(RN1L MaxDegreeG Hat0150facecolorrfacealpha5edgealpha1)histf(RN1L x0150facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightxlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN1L)grid on

subplot(232)hold onhistf(RN2L MaxDegreeG010500facecolorbfacealpha5edgealpha1)histf(RN2L MaxDegreeG Hat010500facecolorrfacealpha5edgealpha1)histf(RN2L x010500facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightxlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN2L)grid on

subplot(233)hold onhistf(RN3L MaxDegreeG010300facecolorbfacealpha5edgealpha1)histf(RN3L MaxDegreeG Hat010300facecolorrfacealpha5edgealpha1)histf(RN3L x010300facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightxlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN3L)

54 Application

grid on

subplot(234)hold onhistf(RN1S MaxDegreeG0150facecolorbfacealpha5edgealpha1)histf(RN1S MaxDegreeG Hat0150facecolorrfacealpha5edgealpha1)histf(RN1S x0150facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightxlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(R1NS)grid on

subplot(235)hold onhistf(RN2S MaxDegreeG010500facecolorbfacealpha5edgealpha1)histf(RN2S MaxDegreeG Hat010500facecolorrfacealpha5edgealpha1)histf(RN2S x010500facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightxlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN2S)grid on

subplot(236)hold onhistf(RN3S MaxDegreeG05300facecolorbfacealpha5edgealpha1)histf(RN3S MaxDegreeG Hat05300facecolorrfacealpha5edgealpha1)histf(RN3S x05300facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightgrid ontitle(RN3S)xlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labelset(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN2png minusr300)

h(3)=figure(NameComputation time over edgesNumberTitleoff)

subplot(231)hold onstem(RN1L EdgesGRN1L Time classicalg)stem(RN1L EdgesGRN1L Time algorithmro)stem(RN1L EdgesGRN1L Time greedybx)grid on

Appendix A 55

title(RN1L)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)

subplot(232)hold onstem(RN2L EdgesGRN2L Time classicalg)stem(RN2L EdgesGRN2L Time algorithmro)stem(RN2L EdgesGRN2L Time greedybx)grid ontitle(RN2L)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)

subplot(233)hold onstem(RN3L EdgesGRN3L Time classicalg)stem(RN3L EdgesGRN3L Time algorithmro)stem(RN3L EdgesGRN3L Time greedybx)grid ontitle(RN3L)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)

subplot(234)hold onstem(RN1S EdgesGRN1S Time classicalg)stem(RN1S EdgesGRN1S Time algorithmro)stem(RN1S EdgesGRN1S Time greedybx)grid ontitle(RN1S)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)

subplot(235)hold onstem(RN2S EdgesGRN2S Time classicalg)stem(RN2S EdgesGRN2S Time algorithmro)stem(RN2S EdgesGRN2S Time greedybx)grid ontitle(RN2S)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)

subplot(236)hold onstem(RN3S EdgesGRN3S Time classicalg)stem(RN3S EdgesGRN3S Time algorithmro)stem(RN3S EdgesGRN3S Time greedybx)

56 Application

grid ontitle(RN3S)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)set(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN3png minusr300)

h(4)=figure(NameSorted matching sizeNumberTitleoff)RN1L Sorted matching temp(1)=RN1L Classical matchingRN1L Sorted matching temp(2)=RN1L Final matchingRN1L Sorted matching temp(3)=RN1L Greedy matchingRN1L Sorted matching temp(4)=RN1L Initial matchingRN1L Sorted matching=sortrows(RN1L Sorted matching temp)

RN2L Sorted matching temp(1)=RN2L Classical matchingRN2L Sorted matching temp(2)=RN2L Final matchingRN2L Sorted matching temp(3)=RN2L Greedy matchingRN2L Sorted matching temp(4)=RN2L Initial matchingRN2L Sorted matching=sortrows(RN2L Sorted matching temp)

RN3L Sorted matching temp(1)=RN3L Classical matchingRN3L Sorted matching temp(2)=RN3L Final matchingRN3L Sorted matching temp(3)=RN3L Greedy matchingRN3L Sorted matching temp(4)=RN3L Initial matchingRN3L Sorted matching=sortrows(RN3L Sorted matching temp)

RN1S Sorted matching temp(1)=RN1S Classical matchingRN1S Sorted matching temp(2)=RN1S Final matchingRN1S Sorted matching temp(3)=RN1S Greedy matchingRN1S Sorted matching temp(4)=RN1S Initial matchingRN1S Sorted matching=sortrows(RN1S Sorted matching temp)

RN2S Sorted matching temp(1)=RN2S Classical matchingRN2S Sorted matching temp(2)=RN2S Final matchingRN2S Sorted matching temp(3)=RN2S Greedy matchingRN2S Sorted matching temp(4)=RN2S Initial matchingRN2S Sorted matching=sortrows(RN2S Sorted matching temp)

RN3S Sorted matching temp(1)=RN3S Classical matchingRN3S Sorted matching temp(2)=RN3S Final matchingRN3S Sorted matching temp(3)=RN3S Greedy matchingRN3S Sorted matching temp(4)=RN3S Initial matchingRN3S Sorted matching=sortrows(RN3S Sorted matching temp)

subplot(231)hold onplot(RN1L Sorted matching(1)b)plot(RN1L Sorted matching(2)g)plot(RN1L Sorted matching(3)r)plot(RN1L Sorted matching(4)m)

Appendix A 57

grid ontitle(RN1L)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)

subplot(232)hold onplot(RN2L Sorted matching(1)b)plot(RN2L Sorted matching(2)g)plot(RN2L Sorted matching(3)r)plot(RN2L Sorted matching(4)m)grid ontitle(RN2L)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)

subplot(233)hold onplot(RN3L Sorted matching(1)b)plot(RN3L Sorted matching(2)g)plot(RN3L Sorted matching(3)r)plot(RN3L Sorted matching(4)m)grid ontitle(RN3L)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)

subplot(234)hold onplot(RN1S Sorted matching(1)b)plot(RN1S Sorted matching(2)g)plot(RN1S Sorted matching(3)r)plot(RN1S Sorted matching(4)m)grid ontitle(RN1S)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)

subplot(235)hold onplot(RN2S Sorted matching(1)b)plot(RN2S Sorted matching(2)g)plot(RN2S Sorted matching(3)r)plot(RN2S Sorted matching(4)m)grid ontitle(RN2S)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)

58 Application

subplot(236)hold onplot(RN3S Sorted matching(1)b)plot(RN3S Sorted matching(2)g)plot(RN3S Sorted matching(3)r)plot(RN3S Sorted matching(4)m)grid ontitle(RN3S)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)set(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN4png minusr300)h(5)=figure(NameSorted RatiosNumberTitleoff)RN1L ratio1=RN1L NodesG hatRN1L NodesGRN2L ratio1=RN2L NodesG hatRN2L NodesGRN3L ratio1=RN3L NodesG hatRN3L NodesGRN1S ratio1=RN1S NodesG hatRN1S NodesGRN2S ratio1=RN2S NodesG hatRN2S NodesGRN3S ratio1=RN3S NodesG hatRN3S NodesG

RN1L ratio2=RN1L EdgesG HatRN1L EdgesGRN2L ratio2=RN2L EdgesG HatRN2L EdgesGRN3L ratio2=RN3L EdgesG HatRN3L EdgesGRN1S ratio2=RN1S EdgesG HatRN1S EdgesGRN2S ratio2=RN2S EdgesG HatRN2S EdgesGRN3S ratio2=RN3S EdgesG HatRN3S EdgesG

RN1L ratio3=RN1L MaxDegreeG HatRN1L MaxDegreeGRN2L ratio3=RN2L MaxDegreeG HatRN2L MaxDegreeGRN3L ratio3=RN3L MaxDegreeG HatRN3L MaxDegreeGRN1S ratio3=RN1S MaxDegreeG HatRN1S MaxDegreeGRN2S ratio3=RN2S MaxDegreeG HatRN2S MaxDegreeGRN3S ratio3=RN3S MaxDegreeG HatRN3S MaxDegreeG

RN1L ratio(1)=RN1L ratio1RN1L ratio(2)=RN1L ratio2RN1L ratio(3)=RN1L ratio3

RN2L ratio(1)=RN2L ratio1RN2L ratio(2)=RN2L ratio2RN2L ratio(3)=RN2L ratio3

RN3L ratio(1)=RN3L ratio1RN3L ratio(2)=RN3L ratio2RN3L ratio(3)=RN3L ratio3

RN1S ratio(1)=RN1S ratio1RN1S ratio(2)=RN1S ratio2RN1S ratio(3)=RN1S ratio3

RN2S ratio(1)=RN2S ratio1

Appendix A 59

RN2S ratio(2)=RN2S ratio2RN2S ratio(3)=RN2S ratio3

RN3S ratio(1)=RN3S ratio1RN3S ratio(2)=RN3S ratio2RN3S ratio(3)=RN3S ratio3

RN1L ratio sorted=sortrows(RN1L ratio)RN2L ratio sorted=sortrows(RN2L ratio)RN3L ratio sorted=sortrows(RN3L ratio)RN1S ratio sorted=sortrows(RN1S ratio)RN2S ratio sorted=sortrows(RN2S ratio)RN3S ratio sorted=sortrows(RN3S ratio)

subplot(231)hold onplot(RN1L ratio sorted(1)b)plot(RN1L ratio sorted(2)g)plot(RN1L ratio sorted(3)r)grid ontitle(RN1L)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)

subplot(232)hold onplot(RN2L ratio sorted(1)b)plot(RN2L ratio sorted(2)g)plot(RN2L ratio sorted(3)r)grid ontitle(RN2L)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)

subplot(233)hold onplot(RN3L ratio sorted(1)b)plot(RN3L ratio sorted(2)g)plot(RN3L ratio sorted(3)r)grid ontitle(RN3L)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)

subplot(234)hold onplot(RN1S ratio sorted(1)b)plot(RN1S ratio sorted(2)g)plot(RN1S ratio sorted(3)r)grid on

60 Application

title(RN1S)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)

subplot(235)hold onplot(RN2S ratio sorted(1)b)plot(RN2S ratio sorted(2)g)plot(RN2S ratio sorted(3)r)grid ontitle(RN2S)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)

subplot(236)hold onplot(RN3S ratio sorted(1)b)plot(RN3S ratio sorted(2)g)plot(RN3S ratio sorted(3)r)grid ontitle(RN3S)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)set(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN5png minusr300)

h(6)=figure(NameSorted edges over nodesNumberTitleoff)

RN1L DegreeG1=(RN1L EdgesG)(RN1L NodesG)RN1L DegreeG Hat1=(RN1L EdgesG Hat)(RN1L NodesG hat)

RN1L Degree temp1(1)=RN1L DegreeG1RN1L Degree temp1(2)=RN1L DegreeG Hat1RN1L Degree sorted1=sortrows(RN1L Degree temp1)subplot(231)hold on

plot(RN1L Degree sorted1(1)b)plot(RN1L Degree sorted1(2)g)grid ontitle(RN1L)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)

RN2L DegreeG1=(RN2L EdgesG)(RN2L NodesG)RN2L DegreeG Hat1=(RN2L EdgesG Hat)(RN2L NodesG hat)

RN2L Degree temp1(1)=RN2L DegreeG1

Appendix A 61

RN2L Degree temp1(2)=RN2L DegreeG Hat1RN2L Degree sorted1=sortrows(RN2L Degree temp1)

subplot(232)hold onplot(RN2L Degree sorted1(1)b)plot(RN2L Degree sorted1(2)g)grid ontitle(RN2L)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)

RN3L DegreeG1=(RN3L EdgesG)(RN3L NodesG)RN3L DegreeG Hat1=(RN3L EdgesG Hat)(RN3L NodesG hat)

RN3L Degree temp1(1)=RN3L DegreeG1RN3L Degree temp1(2)=RN3L DegreeG Hat1RN3L Degree sorted1=sortrows(RN3L Degree temp1)

subplot(233)hold onplot(RN3L Degree sorted1(1)b)plot(RN3L Degree sorted1(2)g)grid ontitle(RN3L)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)

RN1S DegreeG1=(RN1S EdgesG)(RN1S NodesG)RN1S DegreeG Hat1=(RN1S EdgesG Hat)(RN1S NodesG hat)

RN1S Degree temp1(1)=RN1S DegreeG1RN1S Degree temp1(2)=RN1S DegreeG Hat1RN1S Degree sorted1=sortrows(RN1S Degree temp1)

subplot(234)hold onplot(RN1S Degree sorted1(1)b)plot(RN1S Degree sorted1(2)g)grid ontitle(RN1S)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)

RN2S DegreeG1=(RN2S EdgesG)(RN2S NodesG)RN2S DegreeG Hat1=(RN2S EdgesG Hat)(RN2S NodesG hat)

RN2S Degree temp1(1)=RN2S DegreeG1

62 Application

RN2S Degree temp1(2)=RN2S DegreeG Hat1RN2S Degree sorted1=sortrows(RN2S Degree temp1)

subplot(235)hold onplot(RN2S Degree sorted1(1)b)plot(RN2S Degree sorted1(2)g)grid ontitle(RN2S)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)

RN3S DegreeG1=(RN3S EdgesG)(RN3S NodesG)RN3S DegreeG Hat1=(RN3S EdgesG Hat)(RN3S NodesG hat)

RN3S Degree temp1(1)=RN3S DegreeG1RN3S Degree temp1(2)=RN3S DegreeG Hat1RN3S Degree sorted1=sortrows(RN3S Degree temp1)

subplot(236)hold onplot(RN3S Degree sorted1(1)b)plot(RN3S Degree sorted1(2)g)grid ontitle(RN3S)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)set(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN6png minusr300)h(7)=figure(NameSorted mATCHED DEGREENumberTitleoff)RN1L ratioMax(1)=RN1L MaxDegreeGRN1L ratioMax(2)=RN1L MaxDegreeG Hat

RN1L ratio sortedMax=sortrows(RN1L ratioMax)subplot(231)hold onplot(RN1L ratio sortedMax(1)b)plot(RN1L ratio sortedMax(2)g)grid ontitle(RN1L)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)

RN2L ratioMax(1)=RN2L MaxDegreeGRN2L ratioMax(2)=RN2L MaxDegreeG Hat

RN2L ratio sortedMax=sortrows(RN2L ratioMax)subplot(232)

Appendix A 63

hold onplot(RN2L ratio sortedMax(1)b)plot(RN2L ratio sortedMax(2)g)grid ontitle(RN2L)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)

RN3L ratioMax(1)=RN3L MaxDegreeGRN3L ratioMax(2)=RN3L MaxDegreeG Hat

RN3L ratio sortedMax=sortrows(RN3L ratioMax)subplot(233)hold onplot(RN3L ratio sortedMax(1)b)plot(RN3L ratio sortedMax(2)g)grid ontitle(RN3L)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)

RN1S ratioMax(1)=RN1S MaxDegreeGRN1S ratioMax(2)=RN1S MaxDegreeG Hat

RN1S ratio sortedMax=sortrows(RN1S ratioMax)subplot(234)hold onplot(RN1S ratio sortedMax(1)b)plot(RN1S ratio sortedMax(2)g)grid ontitle(RN1S)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)

RN2S ratioMax(1)=RN2S MaxDegreeGRN2S ratioMax(2)=RN2S MaxDegreeG Hat

RN2S ratio sortedMax=sortrows(RN2S ratioMax)

subplot(235)hold onplot(RN2S ratio sortedMax(1)b)plot(RN2S ratio sortedMax(2)g)grid ontitle(RN2S)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)

RN3S ratioMax(1)=RN3S MaxDegreeGRN3S ratioMax(2)=RN3S MaxDegreeG Hat

64 Application

RN3S ratio sortedMax=sortrows(RN3S ratioMax)subplot(236)hold onplot(RN3S ratio sortedMax(1)b)plot(RN3S ratio sortedMax(2)g)grid ontitle(RN1L)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)set(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN7png minusr300)

tilefigs()(h)

Bibliography

[1] C Berge ldquoTWO THEOREMS IN GRAPH THEORYrdquo Proceedings of the NationalAcademy of Sciences of the United States of America vol 43 no 9 pp 842ndash844Sep 1957

[2] L Bui S Sanghavi and R Srikant ldquoDistributed link scheduling with constantoverheadrdquo IEEEACM Trans Netw vol 17 no 5 pp 1467ndash1480 2009

[3] R Duan and S Pettie ldquoLinear-time approximation for maximum weight matchingrdquoJ ACM vol 61 no 1 2014

[4] J Edmonds ldquoPaths trees and flowersrdquo Canadian Journal of Mathematics vol 17pp 449ndash467 1965

[5] J E Hopcroft and R M Karp ldquoAn n52 algorithm for maximum matchings inbipartite graphsrdquo SIAM J Comput vol 2 no 4 pp 225ndash231 1973

[6] S Micali and V V Vazirani ldquoAn O(radic|V ||E|) algorithm for finding maximum

matching in general graphsrdquo in 21st Symp on Foundations of Comp Sc (FOCS)IEEE 1980 pp 17ndash27

[7] N Nisse A Salch and V Weber ldquoRecovery of disrupted airline operationsrdquo 2015httphalinriafrSomething

[8] X Wu and R Srikant ldquoRegulated maximal matching A distributed schedulingalgorithm for multi-hop wireless networks with nodeexclusive spectrum sharingrdquo inIEEE Conf on Decision and Control 2005

65

  • Contents
  • Introduction
  • Algorithms
    • Maximum matching
    • k-maximum matching
      • k-matching for Airport Slot assignment
      • The case where k=3
      • The case of Paths
      • The case of the Spider
          • Application
            • Description
            • Reyni Erdos
            • Barabaacutesi Albert
            • Amadeus Graphs
            • Bipartite
            • Bipartite with degree seq
            • Appendix A
              • BipartiteGraphGeneratorpy
              • RandomGraphGeneratorpy
              • kequals3MaximumMatchingpy
              • Plotmat
                  • Bibliography
Page 28: Theodoros Alexandros KARAGKIOULES -  · Introduction This work is the result of a 6 months internship, under the supervision of research O cer Nicolas NISSE. The original scope of

25 Bipartite 29

Sorted matching size

Sorted matching size-Comments

bull In these set of graphs one can instantly notice that only a few instances with highprobability can reach a matching size equal to the perfect matching

bull For the case of the initial matching we witness that there is a gap between the lineof the classical matching and those of the constraint and greedy results suggestingsmaller matching sizes of 10-40 edges

bull For the case of the small initial matching the result of the constraint matchingis now close to the result of the classical matching yet the greedy algorithm stillshows a relevantly big difference

30 Application

bull In this set of bipartite graphs we can witness that the result of the Constraintmatching shows a difference with the classical matching when the initial matchingis large The difference is smaller as the probability gets larger

bull For the case of the small initial matching the above phenomenom does not occuryet the greedy results deviates from that of the constraint matching

bull As per the pefrect matching compared to the classical matching a difference of5-10 edges is evident at almost all cases

Sorted Ratios

Sorted Ratios-Comments

bull Great max degree deviation

25 Bipartite 31

bull Regardless of the probability the ration of nodes and edges seems to have similarbehaviour when compared to the respective graphs of the same matching scale

bull Same gap between nodes ration and edges ration for all cases

Sorted |E||V |

Sorted |E||V | - Comments

bull In these set of figures we witness that the |E||V | acquires values relevant to those ofthe amadeus graphs The random graphs were constructed to depict this similarity

bull For smaller initial matching the ratios for G and G show the same upward trendand also they acquire closer values It represents the decrease of the averagenumber of forced edges in comparison to the larger matching cases

32 Application

Sorted ∆

Sorted ∆-Comments

bull ∆ acquires the same min and max values for each probability case (expected)

bull Gap in the case of large initial matching

26 Bipartite with degree seq

Graph characteristics

bull DEQBIPxy are randomly generated graphs based on three different types of degreedistribution of the Amadeus graphs

26 Bipartite with degree seq 33

bull There are 6 categories based on ini matching and degree distribution

bull x = L S L When the initial matching is large and S when it is small

bull y = 1 2 3 1 when degree distribution is based on file 2 when degree distributionis based on file and 3 when degree distribution is based on file

Computation time over

34 Application

Computation time overedges-Comments

bull Greedy algorithm takes minimum amount of time

bull The smaller the initial matching the more smaller the difference in comoutationtime of Constraint and classical algorithm

bull Due to preprocessing and the fact that G and G are the almost identical thetotal time needed to apply the constraint algorithm is in some cases bigger

Sorted matching size

26 Bipartite with degree seq 35

Sorted matching size-Comments

bull Classical matching is equal to perfect matching in every case

bull Constraint and greedy have identical behaviour

bull The larger the spectrum of the degree sequence the more efficient the matching

Sorted Ratios

36 Application

Sorted Ratios-Comments

bull With large initial matching most of the edges are considenred uselles or forced andare removed thus the ratio is close(if not equal to) zero

bull For small matching and large degree sequence sectrum hte max degree remainsthe same Only a few forced edges (and their nodes) are removed apparently nonodes with max degree

Sorted |E||V |

26 Bipartite with degree seq 37

Sorted |E||V | - Comments

bull In these set of figures we witness that the |E||V | acquires values relevant to those ofthe amadeus graphs The random graphs were constructed to depict this similarity

bull For smaller initial matching the ratios for G and G show the same upward trendand also they acquire closer values It repsresent the decrease of the averagenumber of forced edges in comparison to the larger matching cases

Sorted ∆

38 Application

Sorted ∆-Comments

bull Big difference in max degree in large initial matching

bull Almost identical behaviour in the case of small initial matching

Appendix A 39

Appendix A

BipartiteGraphGeneratorpy

from future import divisionimport networkx as nx

from networkxalgorithms import approximationimport collectionsimport randomimport mathfrom networkxalgorithms import bipartiteif name == main

for i in range(1481)waqs 481index=1n=randomrandint(100 1000)

n1=95 was 500me1=118

n2=251 was 500me2=903

n3=165 was 500me3=412

m=0m1=0p=randomrandom()p1=18250p2=25250p3=34250print ip=05t1=randomrandint(0 1)print im2=randomrandint(n2minus1 n2+1)G = nxGraph()ma = nxGraph()

aseq1=[1 2 3 4 5 3]

bseq1=[4 3 3 1 2 2 1]

aseq2=[16 14 14 14 12 11]bseq2=[0 0 0 0 0 0]

aseq3=[8 7 8 8 8 8]bseq3=[0 0 0 0 0 0]

40 Application

print Gnumber of edges()if ilt=160

G=bipartiteconfiguration model(aseq1 bseq1 create using=None seed=None)A=nxadjacency matrix(G)for ii in range(0n1+me1)

maadd node(ii)A=[Rtodense()tolist()[0] for R in A]

printnummanumber of nodes()rl=randomsample(range(0n1+me1) n1+me1)m=0done vertices = set()for p in rlprintin fordone verticesadd(p)

neighbors = []list()for iii in range(0n1+me1)

if A[p][iii]==1neighborsappend(iii)

randomshuffle(neighbors)continue loop = Truedegree = len(neighbors)

print degreej = 0p4=randomrandom()while continue loop and (jltdegree)print in loop

next = neighbors[j]if next not in done vertices and p not in done vertices

done verticesadd(p)done verticesadd(next)if p4gt=07print added edge

maadd edge(pnext)m=m+1

continue loop = Falsej += 1

print matching listOfedgeprint maedge

MA=nxadjacency matrix(ma)print MA

MA=[Rtodense()tolist()[0] for R in MA]print MA

B=[ join(map(strR)) for R in A]MB=[ join(map(strR)) for R in MA]

C=njoin(B)+nMC=njoin(MB)+n

print nprint mprint m1

filea=str(i)+txtwith open(fileaw) as f

Appendix A 41

fwrite(str(n1+me1))fwrite(n)fwrite(str(n1+me1))fwrite(n)fwrite(str(m))fwrite(n)fwrite(n)fwrite(C)fwrite(n)fwrite(MC)

elif igt160 and ilt321G=bipartiteconfiguration model(aseq2 bseq2 create using=None seed=None)A=nxadjacency matrix(G)for ii in range(0n2+me2)

maadd node(ii)A=[Rtodense()tolist()[0] for R in A]

printnummanumber of nodes()rl=randomsample(range(0n2+me2) n2+me2)m=0done vertices = set()for p in rlprintin fordone verticesadd(p)

neighbors = []list()for iii in range(0n2+me2)

if A[p][iii]==1neighborsappend(iii)

randomshuffle(neighbors)continue loop = Truedegree = len(neighbors)

print degreej = 0p4=randomrandom()while continue loop and (jltdegree)

print in loopnext = neighbors[j]if next not in done vertices and p not in done vertices

done verticesadd(p)done verticesadd(next)if p4gt=07

print added edgemaadd edge(pnext)m=m+1

continue loop = Falsej += 1

print matching listOfedgeprint maedge

MA=nxadjacency matrix(ma)print MA

MA=[Rtodense()tolist()[0] for R in MA]print MA

B=[ join(map(strR)) for R in A]MB=[ join(map(strR)) for R in MA]

42 Application

C=njoin(B)+nMC=njoin(MB)+n

print nprint mprint m1

filea=str(i)+txtwith open(fileaw) as f

fwrite(str(n2+me2))fwrite(n)fwrite(str(n2+me2))fwrite(n)fwrite(str(m))fwrite(n)fwrite(n)fwrite(C)fwrite(n)fwrite(MC)

elseG=bipartiteconfiguration model(aseq3 bseq3 create using=None seed=None)A=nxadjacency matrix(G)for ii in range(0n3+me3)

maadd node(ii)A=[Rtodense()tolist()[0] for R in A]

printnummanumber of nodes()rl=randomsample(range(0n3+me3) n3+me3)m=0done vertices = set()for p in rlprintin fordone verticesadd(p)

neighbors = []list()for iii in range(0n3+me3)

if A[p][iii]==1neighborsappend(iii)

randomshuffle(neighbors)continue loop = Truedegree = len(neighbors)

print degreej = 0p4=randomrandom()while continue loop and (jltdegree)

print in loopnext = neighbors[j]if next not in done vertices and p not in done vertices

done verticesadd(p)done verticesadd(next)if p4gt=07print added edge

maadd edge(pnext)m=m+1

continue loop = Falsej += 1

Appendix A 43

print matching listOfedgeprint maedge

MA=nxadjacency matrix(ma)print MA

MA=[Rtodense()tolist()[0] for R in MA]print MA

B=[ join(map(strR)) for R in A]MB=[ join(map(strR)) for R in MA]

C=njoin(B)+nMC=njoin(MB)+n

print nprint mprint m1

filea=str(i)+txtwith open(fileaw) as f

fwrite(str(n3+me3))fwrite(n)fwrite(str(n3+me3))fwrite(n)fwrite(str(m))fwrite(n)fwrite(n)fwrite(C)fwrite(n)fwrite(MC)

print nRandom graphs with random matching have been generated

44 Application

RandomGraphGeneratorpy

from future import divisionimport networkx as nxfrom networkxalgorithms import approximationimport collectionsimport randomimport mathif name == main

for i in range(1481)index=1n=randomrandint(100 1000)

n=1000m=0m1=0p=randomrandom()p1=mathlog(n2)np2=13p3=mathlog(n2)n+01p=05t1=randomrandint(0 1)print im2=randomrandint(n2minus1 n2+1)G = nxGraph()ma = nxGraph()print nme1=randomrandint(1 10)me2=randomrandint(2050)me3=randomrandint(50100)if ilt241

if ilt=80G=nxfast gnp random graph(n p1 seed=None directed=False)

elif igt80 and ilt161G=nxfast gnp random graph(n p2 seed=None directed=False)

elseG=nxfast gnp random graph(n p3 seed=None directed=False)

elseif ilt=320

G=nxbarabasi albert graph(n me1 seed=None)elif igt320 and ilt401

G=nxbarabasi albert graph(n me2 seed=None)else

G=nxbarabasi albert graph(n me3 seed=None)A=nxadjacency matrix(G)for ii in range(0n)

maadd node(ii)A=[Rtodense()tolist()[0] for R in A]

rl=randomsample(range(0n) n)m=0

Appendix A 45

done vertices = set()for p in rl

done verticesadd(p)neighbors = []list()for iii in range(0n)

if A[p][iii]==1neighborsappend(iii)

randomshuffle(neighbors)continue loop = Truedegree = len(neighbors)j = 0p2=randomrandom()while continue loop and (jltdegree)

next = neighbors[j]if next not in done vertices and p not in done vertices

done verticesadd(p)done verticesadd(next)if p2gt=00 Larger probability for smaller initial matching

maadd edge(pnext)m=m+1

continue loop = Falsej += 1

print matching listOfedgeprint maedgeMA=nxadjacency matrix(ma)MA=[Rtodense()tolist()[0] for R in MA]print MAB=[ join(map(strR)) for R in A]MB=[ join(map(strR)) for R in MA]

C=njoin(B)+nMC=njoin(MB)+nprint MCprint nprint mprint m1filea=str(i)+txtwith open(fileaw) as f

fwrite(str(n))fwrite(n)fwrite(str(n))fwrite(n)fwrite(str(m))fwrite(n)fwrite(n)fwrite(C)fwrite(n)fwrite(MC)

print nRandom graphs with random matching have been generated

46 Application

kequals3MaximumMatchingpy

from future import divisionimport networkx as nxfrom networkxalgorithms import bipartiteimport matplotlibpyplot as pltimport collectionsimport timeitimport xlwtimport xlrdimport mathimport sys

Case for General Graphsdef forced edges(Gadj dict2matching dict1num nodesforced)

flagg=0for n in range(0num nodes)

for k in adj dict2[n]if ([k]==matching dict1[n])

count=0for l in range(0num nodes)

count=count+adj dict2[l]count(k)if (len(adj dict2[n])==1) or (count==1)

forcedadd edge(nk)Gremove edge(nk)Gremove node(n)Gremove node(k)printforced edgenktemp=kflagg=1for m in range (len(adj dict2[n])minus1minus1minus1)

adj dict2[adj dict2[n][m]]remove(n)adj dict2[n]remove(adj dict2[n][m])

if adj dict2[temp]for l in range(len(adj dict2[temp])minus1minus1minus1)

if (adj dict2[temp][l]=n)adj dict2[adj dict2[temp][l]]remove(temp)adj dict2[temp]remove(adj dict2[temp][l])

break

def useless edges(num nodesadj dict1matching dict1uselessadj dict2G)for n in range(0num nodes)

for k in adj dict1[n]if ([k]=matching dict1[n]) and matching dict1[n] and matching dict1[k]

uselessadd edge(nk)Gremove edge(n k)

Appendix A 47

tempa=kadj dict2[n]remove(k)adj dict2[tempa]remove(n)adj dict1[tempa]remove(n)

return G

def Greedy(num nodesadj dict3matching dict2)

for n in range(0num nodes)if matching dict2[n]

flag2=minus1flag3=minus1for v in adj dict3[n]

if not matching dict2[v]flag2=vbreak

for p in adj dict3[matching dict2[n][0]]if not matching dict2[p]

flag3=pbreak

if (flag2=minus1) and (flag3=minus1) and (flag2=flag3)tempr=matching dict2[n][0]matching dict2[n]=[flag2]matching dict2[flag2]=[n]matching dict2[tempr]=[flag3]matching dict2[flag3]=[tempr]

elsefor k in adj dict3[n]

if not matching dict2[k]matching dict2[n]=[k]matching dict2[k]=[n]break

yo1=0for i in range(0num nodes)

if matching dict2[i] and [i]==matching dict2[matching dict2[i][0]]yo1=yo1+1

greedy size=yo12return greedy size

def General()

INPUTSwb = xlwtWorkbook()ws = wbadd sheet(Results Random)book=xlrdopen workbook(filenames randomxls)

48 Application

style0 = xlwteasyxf(fontbold on)style1 = xlwteasyxf(num format str=0000)INPUTSwswrite(0 0File style0)wswrite(0 1 Nodesstyle0)wswrite(0 2 Initial matchingstyle0)wswrite(0 3 NodesGstyle0)wswrite(0 4 EdgesGstyle0)wswrite(0 5 MaxDegreeGstyle0)wswrite(0 6 NodesG hatstyle0)wswrite(0 7 EdgesG Hatstyle0)wswrite(0 8 Useless edgesstyle0)wswrite(0 9 Forced edgesstyle0)wswrite(0 10 MaxDegreeG Hatstyle0)wswrite(0 11 Classical matchingstyle0)wswrite(0 12 Final matchingstyle0)wswrite(0 13 Greedy matchingstyle0)wswrite(0 14 Time classicalstyle0)wswrite(0 15 Time algorithmstyle0)wswrite(0 16 Time greedystyle0)wswrite(0 17 Perfect matching ratiostyle0)wswrite(0 18 Nodes ratiostyle0)wswrite(0 19 Edges ratiostyle0)wswrite(0 20 Matching ratiostyle0)

print nWelcomeThis is an implementation for general random graphs It uses Edmonds algorithm to compute maximum matching on G Hatn

for index in range (1481)was 481

if (index==482)f=open(Algotel generaltxtr)readlines()

elsefilea=str(booksheet by index(0)cell(index0))s=fileareplace(textu)replace()f=open(sr)readlines()Truewswrite(index 0 s)

print index

num nodes=int([xstrip()split() for x in f][0][0])

num matching=int([xstrip()split() for x in f][2][0])

adj temp = [xstrip()split() for x in f][44+num nodes]adj=[map(intR) for R in adj temp]

matching temp=[xstrip()split() for x in f][4+num nodes+14+2num nodes+1]matching1=[map(intR) for R in matching temp]

adj dict1=i[ii for iix in enumerate(L) if x] for iL in enumerate(adj)adj dict2=i[ii for iix in enumerate(L) if x] for iL in enumerate(adj)

Appendix A 49

adj dict3=i[ii for iix in enumerate(L) if x] for iL in enumerate(adj)

matching dict1=i[ii for iix in enumerate(L) if x] for iL in enumerate(matching1)matching dict2=i[ii for iix in enumerate(L) if x] for iL in enumerate(matching1)print adj dict2print matching dict2wswrite(index 1 num nodes)wswrite(index 2 num matching)

G = nxGraph()

useless= nxGraph()forced = nxGraph()

Fill Graphfor n in range(0num nodes)

for k in adj dict1[n]Gadd edge(nk)

Gt=Gnumber of edges()wswrite(index 3 Gnumber of nodes())wswrite(index 4 Gnumber of edges())wswrite(index 5 max(Gdegree()values()))

Compute Edmonds classical matching on G for comparison

startB = timeitdefault timer()Classical Matching=nxmax weight matching(G maxcardinality=False)stopB = timeitdefault timer()

Compute Gˆ nad MˆstartC = timeitdefault timer()useless edges(num nodesadj dict1matching dict1uselessadj dict2G)forced edges(Gadj dict2matching dict1num nodesforced)Final Matching=nxmax weight matching(G maxcardinality=False)stopC = timeitdefault timer()

GreedystartG = timeitdefault timer()greedy size=Greedy(num nodesadj dict3matching dict2)stopG = timeitdefault timer()

wswrite(index 6 Gnumber of nodes())wswrite(index 7 Gnumber of edges())wswrite(index 8 uselessnumber of edges())wswrite(index 9 forcednumber of edges())if Gdegree()values()

wswrite(index 10 max(Gdegree()values()))else

50 Application

wswrite(index 10 0)wswrite(index 11 len(Classical Matching)2)wswrite(index 12 len(Final Matching)2+forcednumber of edges())wswrite(index 13 greedy size)wswrite(index 14 stopB minus startBstyle1)wswrite(index 15 stopC minus startCstyle1)wswrite(index 16 stopG minus startGstyle1)wswrite(index 17 (len(Final Matching)2+forcednumber of edges())(num nodes2)style1)wswrite(index 18 Gnumber of nodes()Gtstyle1)wswrite(index 19 Gnumber of edges()Gtstyle1)wswrite(index 20 (len(Final Matching)2+forcednumber of edges())(len(Classical Matching)2)style1)

wbsave(AA Results Random Reyni Large Bipartitexls)

Main function Here we must choose the input form of the dataif name == main

startA = timeitdefault timer()General()stopA = timeitdefault timer()

print nThis program has terminatednnRunning time for 480 files stopAminusstartAprint nnPlease open AA Results Random Reyni Largexls file to see the Results

Appendix A 51

Plotmat

clear allclose allload(RN1Lmat)load(RN1Smat)load(RN2Lmat)load(RN2Smat)load(RN3Lmat)load(RN3Smat)

Plotsh(1)=figure(NameHistogram of Matching size difference between Constraint Algorithm and Greedy AlgorithmNumberTitleoff)

RN1L Greedydiff=RN1L Final matchingminusRN1L Greedy matchingRN2L Greedydiff=RN2L Final matchingminusRN2L Greedy matchingRN3L Greedydiff=RN3L Final matchingminusRN3L Greedy matchingRN1S Greedydiff=RN1S Final matchingminusRN1S Greedy matchingRN2S Greedydiff=RN2S Final matchingminusRN2S Greedy matchingRN3S Greedydiff=RN3S Final matchingminusRN3S Greedy matching

RN1L Finaldiff=RN1L Classical matchingminusRN1L Final matchingRN2L Finaldiff=RN2L Classical matchingminusRN2L Final matchingRN3L Finaldiff=RN3L Classical matchingminusRN3L Final matchingRN1S Finaldiff=RN1S Classical matchingminusRN1S Final matchingRN2S Finaldiff=RN2S Classical matchingminusRN2S Final matchingRN3S Finaldiff=RN3S Classical matchingminusRN3S Final matching

RN1L Classicaldiff=(RN1L Nodes2)minusRN1L Classical matchingRN2L Classicaldiff=(RN2L Nodes2)minusRN2L Classical matchingRN3L Classicaldiff=(RN3L Nodes2)minusRN3L Classical matchingRN1S Classicaldiff=(RN1S Nodes2)minusRN1S Classical matchingRN2S Classicaldiff=(RN2S Nodes2)minusRN2S Classical matchingRN3S Classicaldiff=(RN3S Nodes2)minusRN3S Classical matching

subplot(231)hold onhistf(RN1L Greedydiff0110facecolorbfacealpha9edgealpha1)histf(RN1L Finaldiff0110facecolorrfacealpha5edgealpha1)histf(RN1L Classicaldiff0110facecolorgfacealpha5edgealpha1)legalpha(ConminusGreClasminusConPerfminusClasslocationnortheast)legend boxoffaxis tightxlabel(edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN1L)grid on

subplot(232)hold onhistf(RN2L Greedydiff0110facecolorbfacealpha9edgealpha1)

52 Application

histf(RN2L Finaldiff0110facecolorrfacealpha5edgealpha1)histf(RN2L Classicaldiff0110facecolorgfacealpha5edgealpha1)legalpha(ConminusGreClasminusConPerfminusClasslocationnortheast)legend boxoffaxis tightxlabel(edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN2L)grid on

subplot(233)hold onhistf(RN3L Greedydiff0110facecolorbfacealpha5edgealpha1)histf(RN3L Finaldiff0110facecolorrfacealpha5edgealpha1)histf(RN3L Classicaldiff0110facecolorgfacealpha5edgealpha1)legalpha(ConminusGreClasminusConPerfminusClasslocationnortheast)legend boxoffaxis tightxlabel(edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN3L)grid on

subplot(234)hold onhistf(RN1S Greedydiff0110facecolorbfacealpha5edgealpha1)histf(RN1S Finaldiff0110facecolorrfacealpha5edgealpha1)histf(RN1S Classicaldiff0110facecolorgfacealpha5edgealpha1)legalpha(ConminusGreClasminusConPerfminusClasslocationnortheast)legend boxoffaxis tightxlabel(edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(R1NS)grid on

subplot(235)hold onhistf(RN2S Greedydiff0110facecolorbfacealpha5edgealpha1)histf(RN2S Finaldiff0110facecolorrfacealpha5edgealpha1)histf(RN2S Classicaldiff0110facecolorgfacealpha5edgealpha1)legalpha(ConminusGreClasminusConPerfminusClasslocationnortheast)legend boxoffaxis tightxlabel(edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN2S)grid on

subplot(236)hold onhistf(RN3S Greedydiff0110facecolorbfacealpha5edgealpha1)histf(RN3S Finaldiff0110facecolorrfacealpha5edgealpha1)histf(RN3S Classicaldiff0110facecolorgfacealpha5edgealpha1)

Appendix A 53

legalpha(ConminusGreClasminusConPerfminusClasslocationnortheast)legend boxoffaxis tightgrid ontitle(RN3S)xlabel(edges) xminusaxis labelylabel(instances) yminusaxis labelset(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN1png minusr300)h(2)=figure(NameHistogram of Max Degree of G AND G HatNumberTitleoff)RN1L x=RN1L MaxDegreeGminusRN1L MaxDegreeG HatRN2L x=RN2L MaxDegreeGminusRN2L MaxDegreeG HatRN3L x=RN3L MaxDegreeGminusRN3L MaxDegreeG HatRN1S x=RN1S MaxDegreeGminusRN1S MaxDegreeG HatRN2S x=RN2S MaxDegreeGminusRN2S MaxDegreeG HatRN3S x=RN3S MaxDegreeGminusRN3S MaxDegreeG Hatsubplot(231)hold onhistf(RN1L MaxDegreeG0150facecolorbfacealpha5edgealpha1)histf(RN1L MaxDegreeG Hat0150facecolorrfacealpha5edgealpha1)histf(RN1L x0150facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightxlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN1L)grid on

subplot(232)hold onhistf(RN2L MaxDegreeG010500facecolorbfacealpha5edgealpha1)histf(RN2L MaxDegreeG Hat010500facecolorrfacealpha5edgealpha1)histf(RN2L x010500facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightxlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN2L)grid on

subplot(233)hold onhistf(RN3L MaxDegreeG010300facecolorbfacealpha5edgealpha1)histf(RN3L MaxDegreeG Hat010300facecolorrfacealpha5edgealpha1)histf(RN3L x010300facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightxlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN3L)

54 Application

grid on

subplot(234)hold onhistf(RN1S MaxDegreeG0150facecolorbfacealpha5edgealpha1)histf(RN1S MaxDegreeG Hat0150facecolorrfacealpha5edgealpha1)histf(RN1S x0150facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightxlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(R1NS)grid on

subplot(235)hold onhistf(RN2S MaxDegreeG010500facecolorbfacealpha5edgealpha1)histf(RN2S MaxDegreeG Hat010500facecolorrfacealpha5edgealpha1)histf(RN2S x010500facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightxlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN2S)grid on

subplot(236)hold onhistf(RN3S MaxDegreeG05300facecolorbfacealpha5edgealpha1)histf(RN3S MaxDegreeG Hat05300facecolorrfacealpha5edgealpha1)histf(RN3S x05300facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightgrid ontitle(RN3S)xlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labelset(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN2png minusr300)

h(3)=figure(NameComputation time over edgesNumberTitleoff)

subplot(231)hold onstem(RN1L EdgesGRN1L Time classicalg)stem(RN1L EdgesGRN1L Time algorithmro)stem(RN1L EdgesGRN1L Time greedybx)grid on

Appendix A 55

title(RN1L)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)

subplot(232)hold onstem(RN2L EdgesGRN2L Time classicalg)stem(RN2L EdgesGRN2L Time algorithmro)stem(RN2L EdgesGRN2L Time greedybx)grid ontitle(RN2L)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)

subplot(233)hold onstem(RN3L EdgesGRN3L Time classicalg)stem(RN3L EdgesGRN3L Time algorithmro)stem(RN3L EdgesGRN3L Time greedybx)grid ontitle(RN3L)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)

subplot(234)hold onstem(RN1S EdgesGRN1S Time classicalg)stem(RN1S EdgesGRN1S Time algorithmro)stem(RN1S EdgesGRN1S Time greedybx)grid ontitle(RN1S)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)

subplot(235)hold onstem(RN2S EdgesGRN2S Time classicalg)stem(RN2S EdgesGRN2S Time algorithmro)stem(RN2S EdgesGRN2S Time greedybx)grid ontitle(RN2S)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)

subplot(236)hold onstem(RN3S EdgesGRN3S Time classicalg)stem(RN3S EdgesGRN3S Time algorithmro)stem(RN3S EdgesGRN3S Time greedybx)

56 Application

grid ontitle(RN3S)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)set(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN3png minusr300)

h(4)=figure(NameSorted matching sizeNumberTitleoff)RN1L Sorted matching temp(1)=RN1L Classical matchingRN1L Sorted matching temp(2)=RN1L Final matchingRN1L Sorted matching temp(3)=RN1L Greedy matchingRN1L Sorted matching temp(4)=RN1L Initial matchingRN1L Sorted matching=sortrows(RN1L Sorted matching temp)

RN2L Sorted matching temp(1)=RN2L Classical matchingRN2L Sorted matching temp(2)=RN2L Final matchingRN2L Sorted matching temp(3)=RN2L Greedy matchingRN2L Sorted matching temp(4)=RN2L Initial matchingRN2L Sorted matching=sortrows(RN2L Sorted matching temp)

RN3L Sorted matching temp(1)=RN3L Classical matchingRN3L Sorted matching temp(2)=RN3L Final matchingRN3L Sorted matching temp(3)=RN3L Greedy matchingRN3L Sorted matching temp(4)=RN3L Initial matchingRN3L Sorted matching=sortrows(RN3L Sorted matching temp)

RN1S Sorted matching temp(1)=RN1S Classical matchingRN1S Sorted matching temp(2)=RN1S Final matchingRN1S Sorted matching temp(3)=RN1S Greedy matchingRN1S Sorted matching temp(4)=RN1S Initial matchingRN1S Sorted matching=sortrows(RN1S Sorted matching temp)

RN2S Sorted matching temp(1)=RN2S Classical matchingRN2S Sorted matching temp(2)=RN2S Final matchingRN2S Sorted matching temp(3)=RN2S Greedy matchingRN2S Sorted matching temp(4)=RN2S Initial matchingRN2S Sorted matching=sortrows(RN2S Sorted matching temp)

RN3S Sorted matching temp(1)=RN3S Classical matchingRN3S Sorted matching temp(2)=RN3S Final matchingRN3S Sorted matching temp(3)=RN3S Greedy matchingRN3S Sorted matching temp(4)=RN3S Initial matchingRN3S Sorted matching=sortrows(RN3S Sorted matching temp)

subplot(231)hold onplot(RN1L Sorted matching(1)b)plot(RN1L Sorted matching(2)g)plot(RN1L Sorted matching(3)r)plot(RN1L Sorted matching(4)m)

Appendix A 57

grid ontitle(RN1L)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)

subplot(232)hold onplot(RN2L Sorted matching(1)b)plot(RN2L Sorted matching(2)g)plot(RN2L Sorted matching(3)r)plot(RN2L Sorted matching(4)m)grid ontitle(RN2L)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)

subplot(233)hold onplot(RN3L Sorted matching(1)b)plot(RN3L Sorted matching(2)g)plot(RN3L Sorted matching(3)r)plot(RN3L Sorted matching(4)m)grid ontitle(RN3L)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)

subplot(234)hold onplot(RN1S Sorted matching(1)b)plot(RN1S Sorted matching(2)g)plot(RN1S Sorted matching(3)r)plot(RN1S Sorted matching(4)m)grid ontitle(RN1S)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)

subplot(235)hold onplot(RN2S Sorted matching(1)b)plot(RN2S Sorted matching(2)g)plot(RN2S Sorted matching(3)r)plot(RN2S Sorted matching(4)m)grid ontitle(RN2S)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)

58 Application

subplot(236)hold onplot(RN3S Sorted matching(1)b)plot(RN3S Sorted matching(2)g)plot(RN3S Sorted matching(3)r)plot(RN3S Sorted matching(4)m)grid ontitle(RN3S)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)set(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN4png minusr300)h(5)=figure(NameSorted RatiosNumberTitleoff)RN1L ratio1=RN1L NodesG hatRN1L NodesGRN2L ratio1=RN2L NodesG hatRN2L NodesGRN3L ratio1=RN3L NodesG hatRN3L NodesGRN1S ratio1=RN1S NodesG hatRN1S NodesGRN2S ratio1=RN2S NodesG hatRN2S NodesGRN3S ratio1=RN3S NodesG hatRN3S NodesG

RN1L ratio2=RN1L EdgesG HatRN1L EdgesGRN2L ratio2=RN2L EdgesG HatRN2L EdgesGRN3L ratio2=RN3L EdgesG HatRN3L EdgesGRN1S ratio2=RN1S EdgesG HatRN1S EdgesGRN2S ratio2=RN2S EdgesG HatRN2S EdgesGRN3S ratio2=RN3S EdgesG HatRN3S EdgesG

RN1L ratio3=RN1L MaxDegreeG HatRN1L MaxDegreeGRN2L ratio3=RN2L MaxDegreeG HatRN2L MaxDegreeGRN3L ratio3=RN3L MaxDegreeG HatRN3L MaxDegreeGRN1S ratio3=RN1S MaxDegreeG HatRN1S MaxDegreeGRN2S ratio3=RN2S MaxDegreeG HatRN2S MaxDegreeGRN3S ratio3=RN3S MaxDegreeG HatRN3S MaxDegreeG

RN1L ratio(1)=RN1L ratio1RN1L ratio(2)=RN1L ratio2RN1L ratio(3)=RN1L ratio3

RN2L ratio(1)=RN2L ratio1RN2L ratio(2)=RN2L ratio2RN2L ratio(3)=RN2L ratio3

RN3L ratio(1)=RN3L ratio1RN3L ratio(2)=RN3L ratio2RN3L ratio(3)=RN3L ratio3

RN1S ratio(1)=RN1S ratio1RN1S ratio(2)=RN1S ratio2RN1S ratio(3)=RN1S ratio3

RN2S ratio(1)=RN2S ratio1

Appendix A 59

RN2S ratio(2)=RN2S ratio2RN2S ratio(3)=RN2S ratio3

RN3S ratio(1)=RN3S ratio1RN3S ratio(2)=RN3S ratio2RN3S ratio(3)=RN3S ratio3

RN1L ratio sorted=sortrows(RN1L ratio)RN2L ratio sorted=sortrows(RN2L ratio)RN3L ratio sorted=sortrows(RN3L ratio)RN1S ratio sorted=sortrows(RN1S ratio)RN2S ratio sorted=sortrows(RN2S ratio)RN3S ratio sorted=sortrows(RN3S ratio)

subplot(231)hold onplot(RN1L ratio sorted(1)b)plot(RN1L ratio sorted(2)g)plot(RN1L ratio sorted(3)r)grid ontitle(RN1L)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)

subplot(232)hold onplot(RN2L ratio sorted(1)b)plot(RN2L ratio sorted(2)g)plot(RN2L ratio sorted(3)r)grid ontitle(RN2L)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)

subplot(233)hold onplot(RN3L ratio sorted(1)b)plot(RN3L ratio sorted(2)g)plot(RN3L ratio sorted(3)r)grid ontitle(RN3L)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)

subplot(234)hold onplot(RN1S ratio sorted(1)b)plot(RN1S ratio sorted(2)g)plot(RN1S ratio sorted(3)r)grid on

60 Application

title(RN1S)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)

subplot(235)hold onplot(RN2S ratio sorted(1)b)plot(RN2S ratio sorted(2)g)plot(RN2S ratio sorted(3)r)grid ontitle(RN2S)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)

subplot(236)hold onplot(RN3S ratio sorted(1)b)plot(RN3S ratio sorted(2)g)plot(RN3S ratio sorted(3)r)grid ontitle(RN3S)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)set(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN5png minusr300)

h(6)=figure(NameSorted edges over nodesNumberTitleoff)

RN1L DegreeG1=(RN1L EdgesG)(RN1L NodesG)RN1L DegreeG Hat1=(RN1L EdgesG Hat)(RN1L NodesG hat)

RN1L Degree temp1(1)=RN1L DegreeG1RN1L Degree temp1(2)=RN1L DegreeG Hat1RN1L Degree sorted1=sortrows(RN1L Degree temp1)subplot(231)hold on

plot(RN1L Degree sorted1(1)b)plot(RN1L Degree sorted1(2)g)grid ontitle(RN1L)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)

RN2L DegreeG1=(RN2L EdgesG)(RN2L NodesG)RN2L DegreeG Hat1=(RN2L EdgesG Hat)(RN2L NodesG hat)

RN2L Degree temp1(1)=RN2L DegreeG1

Appendix A 61

RN2L Degree temp1(2)=RN2L DegreeG Hat1RN2L Degree sorted1=sortrows(RN2L Degree temp1)

subplot(232)hold onplot(RN2L Degree sorted1(1)b)plot(RN2L Degree sorted1(2)g)grid ontitle(RN2L)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)

RN3L DegreeG1=(RN3L EdgesG)(RN3L NodesG)RN3L DegreeG Hat1=(RN3L EdgesG Hat)(RN3L NodesG hat)

RN3L Degree temp1(1)=RN3L DegreeG1RN3L Degree temp1(2)=RN3L DegreeG Hat1RN3L Degree sorted1=sortrows(RN3L Degree temp1)

subplot(233)hold onplot(RN3L Degree sorted1(1)b)plot(RN3L Degree sorted1(2)g)grid ontitle(RN3L)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)

RN1S DegreeG1=(RN1S EdgesG)(RN1S NodesG)RN1S DegreeG Hat1=(RN1S EdgesG Hat)(RN1S NodesG hat)

RN1S Degree temp1(1)=RN1S DegreeG1RN1S Degree temp1(2)=RN1S DegreeG Hat1RN1S Degree sorted1=sortrows(RN1S Degree temp1)

subplot(234)hold onplot(RN1S Degree sorted1(1)b)plot(RN1S Degree sorted1(2)g)grid ontitle(RN1S)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)

RN2S DegreeG1=(RN2S EdgesG)(RN2S NodesG)RN2S DegreeG Hat1=(RN2S EdgesG Hat)(RN2S NodesG hat)

RN2S Degree temp1(1)=RN2S DegreeG1

62 Application

RN2S Degree temp1(2)=RN2S DegreeG Hat1RN2S Degree sorted1=sortrows(RN2S Degree temp1)

subplot(235)hold onplot(RN2S Degree sorted1(1)b)plot(RN2S Degree sorted1(2)g)grid ontitle(RN2S)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)

RN3S DegreeG1=(RN3S EdgesG)(RN3S NodesG)RN3S DegreeG Hat1=(RN3S EdgesG Hat)(RN3S NodesG hat)

RN3S Degree temp1(1)=RN3S DegreeG1RN3S Degree temp1(2)=RN3S DegreeG Hat1RN3S Degree sorted1=sortrows(RN3S Degree temp1)

subplot(236)hold onplot(RN3S Degree sorted1(1)b)plot(RN3S Degree sorted1(2)g)grid ontitle(RN3S)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)set(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN6png minusr300)h(7)=figure(NameSorted mATCHED DEGREENumberTitleoff)RN1L ratioMax(1)=RN1L MaxDegreeGRN1L ratioMax(2)=RN1L MaxDegreeG Hat

RN1L ratio sortedMax=sortrows(RN1L ratioMax)subplot(231)hold onplot(RN1L ratio sortedMax(1)b)plot(RN1L ratio sortedMax(2)g)grid ontitle(RN1L)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)

RN2L ratioMax(1)=RN2L MaxDegreeGRN2L ratioMax(2)=RN2L MaxDegreeG Hat

RN2L ratio sortedMax=sortrows(RN2L ratioMax)subplot(232)

Appendix A 63

hold onplot(RN2L ratio sortedMax(1)b)plot(RN2L ratio sortedMax(2)g)grid ontitle(RN2L)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)

RN3L ratioMax(1)=RN3L MaxDegreeGRN3L ratioMax(2)=RN3L MaxDegreeG Hat

RN3L ratio sortedMax=sortrows(RN3L ratioMax)subplot(233)hold onplot(RN3L ratio sortedMax(1)b)plot(RN3L ratio sortedMax(2)g)grid ontitle(RN3L)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)

RN1S ratioMax(1)=RN1S MaxDegreeGRN1S ratioMax(2)=RN1S MaxDegreeG Hat

RN1S ratio sortedMax=sortrows(RN1S ratioMax)subplot(234)hold onplot(RN1S ratio sortedMax(1)b)plot(RN1S ratio sortedMax(2)g)grid ontitle(RN1S)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)

RN2S ratioMax(1)=RN2S MaxDegreeGRN2S ratioMax(2)=RN2S MaxDegreeG Hat

RN2S ratio sortedMax=sortrows(RN2S ratioMax)

subplot(235)hold onplot(RN2S ratio sortedMax(1)b)plot(RN2S ratio sortedMax(2)g)grid ontitle(RN2S)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)

RN3S ratioMax(1)=RN3S MaxDegreeGRN3S ratioMax(2)=RN3S MaxDegreeG Hat

64 Application

RN3S ratio sortedMax=sortrows(RN3S ratioMax)subplot(236)hold onplot(RN3S ratio sortedMax(1)b)plot(RN3S ratio sortedMax(2)g)grid ontitle(RN1L)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)set(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN7png minusr300)

tilefigs()(h)

Bibliography

[1] C Berge ldquoTWO THEOREMS IN GRAPH THEORYrdquo Proceedings of the NationalAcademy of Sciences of the United States of America vol 43 no 9 pp 842ndash844Sep 1957

[2] L Bui S Sanghavi and R Srikant ldquoDistributed link scheduling with constantoverheadrdquo IEEEACM Trans Netw vol 17 no 5 pp 1467ndash1480 2009

[3] R Duan and S Pettie ldquoLinear-time approximation for maximum weight matchingrdquoJ ACM vol 61 no 1 2014

[4] J Edmonds ldquoPaths trees and flowersrdquo Canadian Journal of Mathematics vol 17pp 449ndash467 1965

[5] J E Hopcroft and R M Karp ldquoAn n52 algorithm for maximum matchings inbipartite graphsrdquo SIAM J Comput vol 2 no 4 pp 225ndash231 1973

[6] S Micali and V V Vazirani ldquoAn O(radic|V ||E|) algorithm for finding maximum

matching in general graphsrdquo in 21st Symp on Foundations of Comp Sc (FOCS)IEEE 1980 pp 17ndash27

[7] N Nisse A Salch and V Weber ldquoRecovery of disrupted airline operationsrdquo 2015httphalinriafrSomething

[8] X Wu and R Srikant ldquoRegulated maximal matching A distributed schedulingalgorithm for multi-hop wireless networks with nodeexclusive spectrum sharingrdquo inIEEE Conf on Decision and Control 2005

65

  • Contents
  • Introduction
  • Algorithms
    • Maximum matching
    • k-maximum matching
      • k-matching for Airport Slot assignment
      • The case where k=3
      • The case of Paths
      • The case of the Spider
          • Application
            • Description
            • Reyni Erdos
            • Barabaacutesi Albert
            • Amadeus Graphs
            • Bipartite
            • Bipartite with degree seq
            • Appendix A
              • BipartiteGraphGeneratorpy
              • RandomGraphGeneratorpy
              • kequals3MaximumMatchingpy
              • Plotmat
                  • Bibliography
Page 29: Theodoros Alexandros KARAGKIOULES -  · Introduction This work is the result of a 6 months internship, under the supervision of research O cer Nicolas NISSE. The original scope of

30 Application

bull In this set of bipartite graphs we can witness that the result of the Constraintmatching shows a difference with the classical matching when the initial matchingis large The difference is smaller as the probability gets larger

bull For the case of the small initial matching the above phenomenom does not occuryet the greedy results deviates from that of the constraint matching

bull As per the pefrect matching compared to the classical matching a difference of5-10 edges is evident at almost all cases

Sorted Ratios

Sorted Ratios-Comments

bull Great max degree deviation

25 Bipartite 31

bull Regardless of the probability the ration of nodes and edges seems to have similarbehaviour when compared to the respective graphs of the same matching scale

bull Same gap between nodes ration and edges ration for all cases

Sorted |E||V |

Sorted |E||V | - Comments

bull In these set of figures we witness that the |E||V | acquires values relevant to those ofthe amadeus graphs The random graphs were constructed to depict this similarity

bull For smaller initial matching the ratios for G and G show the same upward trendand also they acquire closer values It represents the decrease of the averagenumber of forced edges in comparison to the larger matching cases

32 Application

Sorted ∆

Sorted ∆-Comments

bull ∆ acquires the same min and max values for each probability case (expected)

bull Gap in the case of large initial matching

26 Bipartite with degree seq

Graph characteristics

bull DEQBIPxy are randomly generated graphs based on three different types of degreedistribution of the Amadeus graphs

26 Bipartite with degree seq 33

bull There are 6 categories based on ini matching and degree distribution

bull x = L S L When the initial matching is large and S when it is small

bull y = 1 2 3 1 when degree distribution is based on file 2 when degree distributionis based on file and 3 when degree distribution is based on file

Computation time over

34 Application

Computation time overedges-Comments

bull Greedy algorithm takes minimum amount of time

bull The smaller the initial matching the more smaller the difference in comoutationtime of Constraint and classical algorithm

bull Due to preprocessing and the fact that G and G are the almost identical thetotal time needed to apply the constraint algorithm is in some cases bigger

Sorted matching size

26 Bipartite with degree seq 35

Sorted matching size-Comments

bull Classical matching is equal to perfect matching in every case

bull Constraint and greedy have identical behaviour

bull The larger the spectrum of the degree sequence the more efficient the matching

Sorted Ratios

36 Application

Sorted Ratios-Comments

bull With large initial matching most of the edges are considenred uselles or forced andare removed thus the ratio is close(if not equal to) zero

bull For small matching and large degree sequence sectrum hte max degree remainsthe same Only a few forced edges (and their nodes) are removed apparently nonodes with max degree

Sorted |E||V |

26 Bipartite with degree seq 37

Sorted |E||V | - Comments

bull In these set of figures we witness that the |E||V | acquires values relevant to those ofthe amadeus graphs The random graphs were constructed to depict this similarity

bull For smaller initial matching the ratios for G and G show the same upward trendand also they acquire closer values It repsresent the decrease of the averagenumber of forced edges in comparison to the larger matching cases

Sorted ∆

38 Application

Sorted ∆-Comments

bull Big difference in max degree in large initial matching

bull Almost identical behaviour in the case of small initial matching

Appendix A 39

Appendix A

BipartiteGraphGeneratorpy

from future import divisionimport networkx as nx

from networkxalgorithms import approximationimport collectionsimport randomimport mathfrom networkxalgorithms import bipartiteif name == main

for i in range(1481)waqs 481index=1n=randomrandint(100 1000)

n1=95 was 500me1=118

n2=251 was 500me2=903

n3=165 was 500me3=412

m=0m1=0p=randomrandom()p1=18250p2=25250p3=34250print ip=05t1=randomrandint(0 1)print im2=randomrandint(n2minus1 n2+1)G = nxGraph()ma = nxGraph()

aseq1=[1 2 3 4 5 3]

bseq1=[4 3 3 1 2 2 1]

aseq2=[16 14 14 14 12 11]bseq2=[0 0 0 0 0 0]

aseq3=[8 7 8 8 8 8]bseq3=[0 0 0 0 0 0]

40 Application

print Gnumber of edges()if ilt=160

G=bipartiteconfiguration model(aseq1 bseq1 create using=None seed=None)A=nxadjacency matrix(G)for ii in range(0n1+me1)

maadd node(ii)A=[Rtodense()tolist()[0] for R in A]

printnummanumber of nodes()rl=randomsample(range(0n1+me1) n1+me1)m=0done vertices = set()for p in rlprintin fordone verticesadd(p)

neighbors = []list()for iii in range(0n1+me1)

if A[p][iii]==1neighborsappend(iii)

randomshuffle(neighbors)continue loop = Truedegree = len(neighbors)

print degreej = 0p4=randomrandom()while continue loop and (jltdegree)print in loop

next = neighbors[j]if next not in done vertices and p not in done vertices

done verticesadd(p)done verticesadd(next)if p4gt=07print added edge

maadd edge(pnext)m=m+1

continue loop = Falsej += 1

print matching listOfedgeprint maedge

MA=nxadjacency matrix(ma)print MA

MA=[Rtodense()tolist()[0] for R in MA]print MA

B=[ join(map(strR)) for R in A]MB=[ join(map(strR)) for R in MA]

C=njoin(B)+nMC=njoin(MB)+n

print nprint mprint m1

filea=str(i)+txtwith open(fileaw) as f

Appendix A 41

fwrite(str(n1+me1))fwrite(n)fwrite(str(n1+me1))fwrite(n)fwrite(str(m))fwrite(n)fwrite(n)fwrite(C)fwrite(n)fwrite(MC)

elif igt160 and ilt321G=bipartiteconfiguration model(aseq2 bseq2 create using=None seed=None)A=nxadjacency matrix(G)for ii in range(0n2+me2)

maadd node(ii)A=[Rtodense()tolist()[0] for R in A]

printnummanumber of nodes()rl=randomsample(range(0n2+me2) n2+me2)m=0done vertices = set()for p in rlprintin fordone verticesadd(p)

neighbors = []list()for iii in range(0n2+me2)

if A[p][iii]==1neighborsappend(iii)

randomshuffle(neighbors)continue loop = Truedegree = len(neighbors)

print degreej = 0p4=randomrandom()while continue loop and (jltdegree)

print in loopnext = neighbors[j]if next not in done vertices and p not in done vertices

done verticesadd(p)done verticesadd(next)if p4gt=07

print added edgemaadd edge(pnext)m=m+1

continue loop = Falsej += 1

print matching listOfedgeprint maedge

MA=nxadjacency matrix(ma)print MA

MA=[Rtodense()tolist()[0] for R in MA]print MA

B=[ join(map(strR)) for R in A]MB=[ join(map(strR)) for R in MA]

42 Application

C=njoin(B)+nMC=njoin(MB)+n

print nprint mprint m1

filea=str(i)+txtwith open(fileaw) as f

fwrite(str(n2+me2))fwrite(n)fwrite(str(n2+me2))fwrite(n)fwrite(str(m))fwrite(n)fwrite(n)fwrite(C)fwrite(n)fwrite(MC)

elseG=bipartiteconfiguration model(aseq3 bseq3 create using=None seed=None)A=nxadjacency matrix(G)for ii in range(0n3+me3)

maadd node(ii)A=[Rtodense()tolist()[0] for R in A]

printnummanumber of nodes()rl=randomsample(range(0n3+me3) n3+me3)m=0done vertices = set()for p in rlprintin fordone verticesadd(p)

neighbors = []list()for iii in range(0n3+me3)

if A[p][iii]==1neighborsappend(iii)

randomshuffle(neighbors)continue loop = Truedegree = len(neighbors)

print degreej = 0p4=randomrandom()while continue loop and (jltdegree)

print in loopnext = neighbors[j]if next not in done vertices and p not in done vertices

done verticesadd(p)done verticesadd(next)if p4gt=07print added edge

maadd edge(pnext)m=m+1

continue loop = Falsej += 1

Appendix A 43

print matching listOfedgeprint maedge

MA=nxadjacency matrix(ma)print MA

MA=[Rtodense()tolist()[0] for R in MA]print MA

B=[ join(map(strR)) for R in A]MB=[ join(map(strR)) for R in MA]

C=njoin(B)+nMC=njoin(MB)+n

print nprint mprint m1

filea=str(i)+txtwith open(fileaw) as f

fwrite(str(n3+me3))fwrite(n)fwrite(str(n3+me3))fwrite(n)fwrite(str(m))fwrite(n)fwrite(n)fwrite(C)fwrite(n)fwrite(MC)

print nRandom graphs with random matching have been generated

44 Application

RandomGraphGeneratorpy

from future import divisionimport networkx as nxfrom networkxalgorithms import approximationimport collectionsimport randomimport mathif name == main

for i in range(1481)index=1n=randomrandint(100 1000)

n=1000m=0m1=0p=randomrandom()p1=mathlog(n2)np2=13p3=mathlog(n2)n+01p=05t1=randomrandint(0 1)print im2=randomrandint(n2minus1 n2+1)G = nxGraph()ma = nxGraph()print nme1=randomrandint(1 10)me2=randomrandint(2050)me3=randomrandint(50100)if ilt241

if ilt=80G=nxfast gnp random graph(n p1 seed=None directed=False)

elif igt80 and ilt161G=nxfast gnp random graph(n p2 seed=None directed=False)

elseG=nxfast gnp random graph(n p3 seed=None directed=False)

elseif ilt=320

G=nxbarabasi albert graph(n me1 seed=None)elif igt320 and ilt401

G=nxbarabasi albert graph(n me2 seed=None)else

G=nxbarabasi albert graph(n me3 seed=None)A=nxadjacency matrix(G)for ii in range(0n)

maadd node(ii)A=[Rtodense()tolist()[0] for R in A]

rl=randomsample(range(0n) n)m=0

Appendix A 45

done vertices = set()for p in rl

done verticesadd(p)neighbors = []list()for iii in range(0n)

if A[p][iii]==1neighborsappend(iii)

randomshuffle(neighbors)continue loop = Truedegree = len(neighbors)j = 0p2=randomrandom()while continue loop and (jltdegree)

next = neighbors[j]if next not in done vertices and p not in done vertices

done verticesadd(p)done verticesadd(next)if p2gt=00 Larger probability for smaller initial matching

maadd edge(pnext)m=m+1

continue loop = Falsej += 1

print matching listOfedgeprint maedgeMA=nxadjacency matrix(ma)MA=[Rtodense()tolist()[0] for R in MA]print MAB=[ join(map(strR)) for R in A]MB=[ join(map(strR)) for R in MA]

C=njoin(B)+nMC=njoin(MB)+nprint MCprint nprint mprint m1filea=str(i)+txtwith open(fileaw) as f

fwrite(str(n))fwrite(n)fwrite(str(n))fwrite(n)fwrite(str(m))fwrite(n)fwrite(n)fwrite(C)fwrite(n)fwrite(MC)

print nRandom graphs with random matching have been generated

46 Application

kequals3MaximumMatchingpy

from future import divisionimport networkx as nxfrom networkxalgorithms import bipartiteimport matplotlibpyplot as pltimport collectionsimport timeitimport xlwtimport xlrdimport mathimport sys

Case for General Graphsdef forced edges(Gadj dict2matching dict1num nodesforced)

flagg=0for n in range(0num nodes)

for k in adj dict2[n]if ([k]==matching dict1[n])

count=0for l in range(0num nodes)

count=count+adj dict2[l]count(k)if (len(adj dict2[n])==1) or (count==1)

forcedadd edge(nk)Gremove edge(nk)Gremove node(n)Gremove node(k)printforced edgenktemp=kflagg=1for m in range (len(adj dict2[n])minus1minus1minus1)

adj dict2[adj dict2[n][m]]remove(n)adj dict2[n]remove(adj dict2[n][m])

if adj dict2[temp]for l in range(len(adj dict2[temp])minus1minus1minus1)

if (adj dict2[temp][l]=n)adj dict2[adj dict2[temp][l]]remove(temp)adj dict2[temp]remove(adj dict2[temp][l])

break

def useless edges(num nodesadj dict1matching dict1uselessadj dict2G)for n in range(0num nodes)

for k in adj dict1[n]if ([k]=matching dict1[n]) and matching dict1[n] and matching dict1[k]

uselessadd edge(nk)Gremove edge(n k)

Appendix A 47

tempa=kadj dict2[n]remove(k)adj dict2[tempa]remove(n)adj dict1[tempa]remove(n)

return G

def Greedy(num nodesadj dict3matching dict2)

for n in range(0num nodes)if matching dict2[n]

flag2=minus1flag3=minus1for v in adj dict3[n]

if not matching dict2[v]flag2=vbreak

for p in adj dict3[matching dict2[n][0]]if not matching dict2[p]

flag3=pbreak

if (flag2=minus1) and (flag3=minus1) and (flag2=flag3)tempr=matching dict2[n][0]matching dict2[n]=[flag2]matching dict2[flag2]=[n]matching dict2[tempr]=[flag3]matching dict2[flag3]=[tempr]

elsefor k in adj dict3[n]

if not matching dict2[k]matching dict2[n]=[k]matching dict2[k]=[n]break

yo1=0for i in range(0num nodes)

if matching dict2[i] and [i]==matching dict2[matching dict2[i][0]]yo1=yo1+1

greedy size=yo12return greedy size

def General()

INPUTSwb = xlwtWorkbook()ws = wbadd sheet(Results Random)book=xlrdopen workbook(filenames randomxls)

48 Application

style0 = xlwteasyxf(fontbold on)style1 = xlwteasyxf(num format str=0000)INPUTSwswrite(0 0File style0)wswrite(0 1 Nodesstyle0)wswrite(0 2 Initial matchingstyle0)wswrite(0 3 NodesGstyle0)wswrite(0 4 EdgesGstyle0)wswrite(0 5 MaxDegreeGstyle0)wswrite(0 6 NodesG hatstyle0)wswrite(0 7 EdgesG Hatstyle0)wswrite(0 8 Useless edgesstyle0)wswrite(0 9 Forced edgesstyle0)wswrite(0 10 MaxDegreeG Hatstyle0)wswrite(0 11 Classical matchingstyle0)wswrite(0 12 Final matchingstyle0)wswrite(0 13 Greedy matchingstyle0)wswrite(0 14 Time classicalstyle0)wswrite(0 15 Time algorithmstyle0)wswrite(0 16 Time greedystyle0)wswrite(0 17 Perfect matching ratiostyle0)wswrite(0 18 Nodes ratiostyle0)wswrite(0 19 Edges ratiostyle0)wswrite(0 20 Matching ratiostyle0)

print nWelcomeThis is an implementation for general random graphs It uses Edmonds algorithm to compute maximum matching on G Hatn

for index in range (1481)was 481

if (index==482)f=open(Algotel generaltxtr)readlines()

elsefilea=str(booksheet by index(0)cell(index0))s=fileareplace(textu)replace()f=open(sr)readlines()Truewswrite(index 0 s)

print index

num nodes=int([xstrip()split() for x in f][0][0])

num matching=int([xstrip()split() for x in f][2][0])

adj temp = [xstrip()split() for x in f][44+num nodes]adj=[map(intR) for R in adj temp]

matching temp=[xstrip()split() for x in f][4+num nodes+14+2num nodes+1]matching1=[map(intR) for R in matching temp]

adj dict1=i[ii for iix in enumerate(L) if x] for iL in enumerate(adj)adj dict2=i[ii for iix in enumerate(L) if x] for iL in enumerate(adj)

Appendix A 49

adj dict3=i[ii for iix in enumerate(L) if x] for iL in enumerate(adj)

matching dict1=i[ii for iix in enumerate(L) if x] for iL in enumerate(matching1)matching dict2=i[ii for iix in enumerate(L) if x] for iL in enumerate(matching1)print adj dict2print matching dict2wswrite(index 1 num nodes)wswrite(index 2 num matching)

G = nxGraph()

useless= nxGraph()forced = nxGraph()

Fill Graphfor n in range(0num nodes)

for k in adj dict1[n]Gadd edge(nk)

Gt=Gnumber of edges()wswrite(index 3 Gnumber of nodes())wswrite(index 4 Gnumber of edges())wswrite(index 5 max(Gdegree()values()))

Compute Edmonds classical matching on G for comparison

startB = timeitdefault timer()Classical Matching=nxmax weight matching(G maxcardinality=False)stopB = timeitdefault timer()

Compute Gˆ nad MˆstartC = timeitdefault timer()useless edges(num nodesadj dict1matching dict1uselessadj dict2G)forced edges(Gadj dict2matching dict1num nodesforced)Final Matching=nxmax weight matching(G maxcardinality=False)stopC = timeitdefault timer()

GreedystartG = timeitdefault timer()greedy size=Greedy(num nodesadj dict3matching dict2)stopG = timeitdefault timer()

wswrite(index 6 Gnumber of nodes())wswrite(index 7 Gnumber of edges())wswrite(index 8 uselessnumber of edges())wswrite(index 9 forcednumber of edges())if Gdegree()values()

wswrite(index 10 max(Gdegree()values()))else

50 Application

wswrite(index 10 0)wswrite(index 11 len(Classical Matching)2)wswrite(index 12 len(Final Matching)2+forcednumber of edges())wswrite(index 13 greedy size)wswrite(index 14 stopB minus startBstyle1)wswrite(index 15 stopC minus startCstyle1)wswrite(index 16 stopG minus startGstyle1)wswrite(index 17 (len(Final Matching)2+forcednumber of edges())(num nodes2)style1)wswrite(index 18 Gnumber of nodes()Gtstyle1)wswrite(index 19 Gnumber of edges()Gtstyle1)wswrite(index 20 (len(Final Matching)2+forcednumber of edges())(len(Classical Matching)2)style1)

wbsave(AA Results Random Reyni Large Bipartitexls)

Main function Here we must choose the input form of the dataif name == main

startA = timeitdefault timer()General()stopA = timeitdefault timer()

print nThis program has terminatednnRunning time for 480 files stopAminusstartAprint nnPlease open AA Results Random Reyni Largexls file to see the Results

Appendix A 51

Plotmat

clear allclose allload(RN1Lmat)load(RN1Smat)load(RN2Lmat)load(RN2Smat)load(RN3Lmat)load(RN3Smat)

Plotsh(1)=figure(NameHistogram of Matching size difference between Constraint Algorithm and Greedy AlgorithmNumberTitleoff)

RN1L Greedydiff=RN1L Final matchingminusRN1L Greedy matchingRN2L Greedydiff=RN2L Final matchingminusRN2L Greedy matchingRN3L Greedydiff=RN3L Final matchingminusRN3L Greedy matchingRN1S Greedydiff=RN1S Final matchingminusRN1S Greedy matchingRN2S Greedydiff=RN2S Final matchingminusRN2S Greedy matchingRN3S Greedydiff=RN3S Final matchingminusRN3S Greedy matching

RN1L Finaldiff=RN1L Classical matchingminusRN1L Final matchingRN2L Finaldiff=RN2L Classical matchingminusRN2L Final matchingRN3L Finaldiff=RN3L Classical matchingminusRN3L Final matchingRN1S Finaldiff=RN1S Classical matchingminusRN1S Final matchingRN2S Finaldiff=RN2S Classical matchingminusRN2S Final matchingRN3S Finaldiff=RN3S Classical matchingminusRN3S Final matching

RN1L Classicaldiff=(RN1L Nodes2)minusRN1L Classical matchingRN2L Classicaldiff=(RN2L Nodes2)minusRN2L Classical matchingRN3L Classicaldiff=(RN3L Nodes2)minusRN3L Classical matchingRN1S Classicaldiff=(RN1S Nodes2)minusRN1S Classical matchingRN2S Classicaldiff=(RN2S Nodes2)minusRN2S Classical matchingRN3S Classicaldiff=(RN3S Nodes2)minusRN3S Classical matching

subplot(231)hold onhistf(RN1L Greedydiff0110facecolorbfacealpha9edgealpha1)histf(RN1L Finaldiff0110facecolorrfacealpha5edgealpha1)histf(RN1L Classicaldiff0110facecolorgfacealpha5edgealpha1)legalpha(ConminusGreClasminusConPerfminusClasslocationnortheast)legend boxoffaxis tightxlabel(edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN1L)grid on

subplot(232)hold onhistf(RN2L Greedydiff0110facecolorbfacealpha9edgealpha1)

52 Application

histf(RN2L Finaldiff0110facecolorrfacealpha5edgealpha1)histf(RN2L Classicaldiff0110facecolorgfacealpha5edgealpha1)legalpha(ConminusGreClasminusConPerfminusClasslocationnortheast)legend boxoffaxis tightxlabel(edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN2L)grid on

subplot(233)hold onhistf(RN3L Greedydiff0110facecolorbfacealpha5edgealpha1)histf(RN3L Finaldiff0110facecolorrfacealpha5edgealpha1)histf(RN3L Classicaldiff0110facecolorgfacealpha5edgealpha1)legalpha(ConminusGreClasminusConPerfminusClasslocationnortheast)legend boxoffaxis tightxlabel(edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN3L)grid on

subplot(234)hold onhistf(RN1S Greedydiff0110facecolorbfacealpha5edgealpha1)histf(RN1S Finaldiff0110facecolorrfacealpha5edgealpha1)histf(RN1S Classicaldiff0110facecolorgfacealpha5edgealpha1)legalpha(ConminusGreClasminusConPerfminusClasslocationnortheast)legend boxoffaxis tightxlabel(edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(R1NS)grid on

subplot(235)hold onhistf(RN2S Greedydiff0110facecolorbfacealpha5edgealpha1)histf(RN2S Finaldiff0110facecolorrfacealpha5edgealpha1)histf(RN2S Classicaldiff0110facecolorgfacealpha5edgealpha1)legalpha(ConminusGreClasminusConPerfminusClasslocationnortheast)legend boxoffaxis tightxlabel(edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN2S)grid on

subplot(236)hold onhistf(RN3S Greedydiff0110facecolorbfacealpha5edgealpha1)histf(RN3S Finaldiff0110facecolorrfacealpha5edgealpha1)histf(RN3S Classicaldiff0110facecolorgfacealpha5edgealpha1)

Appendix A 53

legalpha(ConminusGreClasminusConPerfminusClasslocationnortheast)legend boxoffaxis tightgrid ontitle(RN3S)xlabel(edges) xminusaxis labelylabel(instances) yminusaxis labelset(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN1png minusr300)h(2)=figure(NameHistogram of Max Degree of G AND G HatNumberTitleoff)RN1L x=RN1L MaxDegreeGminusRN1L MaxDegreeG HatRN2L x=RN2L MaxDegreeGminusRN2L MaxDegreeG HatRN3L x=RN3L MaxDegreeGminusRN3L MaxDegreeG HatRN1S x=RN1S MaxDegreeGminusRN1S MaxDegreeG HatRN2S x=RN2S MaxDegreeGminusRN2S MaxDegreeG HatRN3S x=RN3S MaxDegreeGminusRN3S MaxDegreeG Hatsubplot(231)hold onhistf(RN1L MaxDegreeG0150facecolorbfacealpha5edgealpha1)histf(RN1L MaxDegreeG Hat0150facecolorrfacealpha5edgealpha1)histf(RN1L x0150facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightxlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN1L)grid on

subplot(232)hold onhistf(RN2L MaxDegreeG010500facecolorbfacealpha5edgealpha1)histf(RN2L MaxDegreeG Hat010500facecolorrfacealpha5edgealpha1)histf(RN2L x010500facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightxlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN2L)grid on

subplot(233)hold onhistf(RN3L MaxDegreeG010300facecolorbfacealpha5edgealpha1)histf(RN3L MaxDegreeG Hat010300facecolorrfacealpha5edgealpha1)histf(RN3L x010300facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightxlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN3L)

54 Application

grid on

subplot(234)hold onhistf(RN1S MaxDegreeG0150facecolorbfacealpha5edgealpha1)histf(RN1S MaxDegreeG Hat0150facecolorrfacealpha5edgealpha1)histf(RN1S x0150facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightxlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(R1NS)grid on

subplot(235)hold onhistf(RN2S MaxDegreeG010500facecolorbfacealpha5edgealpha1)histf(RN2S MaxDegreeG Hat010500facecolorrfacealpha5edgealpha1)histf(RN2S x010500facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightxlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN2S)grid on

subplot(236)hold onhistf(RN3S MaxDegreeG05300facecolorbfacealpha5edgealpha1)histf(RN3S MaxDegreeG Hat05300facecolorrfacealpha5edgealpha1)histf(RN3S x05300facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightgrid ontitle(RN3S)xlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labelset(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN2png minusr300)

h(3)=figure(NameComputation time over edgesNumberTitleoff)

subplot(231)hold onstem(RN1L EdgesGRN1L Time classicalg)stem(RN1L EdgesGRN1L Time algorithmro)stem(RN1L EdgesGRN1L Time greedybx)grid on

Appendix A 55

title(RN1L)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)

subplot(232)hold onstem(RN2L EdgesGRN2L Time classicalg)stem(RN2L EdgesGRN2L Time algorithmro)stem(RN2L EdgesGRN2L Time greedybx)grid ontitle(RN2L)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)

subplot(233)hold onstem(RN3L EdgesGRN3L Time classicalg)stem(RN3L EdgesGRN3L Time algorithmro)stem(RN3L EdgesGRN3L Time greedybx)grid ontitle(RN3L)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)

subplot(234)hold onstem(RN1S EdgesGRN1S Time classicalg)stem(RN1S EdgesGRN1S Time algorithmro)stem(RN1S EdgesGRN1S Time greedybx)grid ontitle(RN1S)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)

subplot(235)hold onstem(RN2S EdgesGRN2S Time classicalg)stem(RN2S EdgesGRN2S Time algorithmro)stem(RN2S EdgesGRN2S Time greedybx)grid ontitle(RN2S)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)

subplot(236)hold onstem(RN3S EdgesGRN3S Time classicalg)stem(RN3S EdgesGRN3S Time algorithmro)stem(RN3S EdgesGRN3S Time greedybx)

56 Application

grid ontitle(RN3S)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)set(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN3png minusr300)

h(4)=figure(NameSorted matching sizeNumberTitleoff)RN1L Sorted matching temp(1)=RN1L Classical matchingRN1L Sorted matching temp(2)=RN1L Final matchingRN1L Sorted matching temp(3)=RN1L Greedy matchingRN1L Sorted matching temp(4)=RN1L Initial matchingRN1L Sorted matching=sortrows(RN1L Sorted matching temp)

RN2L Sorted matching temp(1)=RN2L Classical matchingRN2L Sorted matching temp(2)=RN2L Final matchingRN2L Sorted matching temp(3)=RN2L Greedy matchingRN2L Sorted matching temp(4)=RN2L Initial matchingRN2L Sorted matching=sortrows(RN2L Sorted matching temp)

RN3L Sorted matching temp(1)=RN3L Classical matchingRN3L Sorted matching temp(2)=RN3L Final matchingRN3L Sorted matching temp(3)=RN3L Greedy matchingRN3L Sorted matching temp(4)=RN3L Initial matchingRN3L Sorted matching=sortrows(RN3L Sorted matching temp)

RN1S Sorted matching temp(1)=RN1S Classical matchingRN1S Sorted matching temp(2)=RN1S Final matchingRN1S Sorted matching temp(3)=RN1S Greedy matchingRN1S Sorted matching temp(4)=RN1S Initial matchingRN1S Sorted matching=sortrows(RN1S Sorted matching temp)

RN2S Sorted matching temp(1)=RN2S Classical matchingRN2S Sorted matching temp(2)=RN2S Final matchingRN2S Sorted matching temp(3)=RN2S Greedy matchingRN2S Sorted matching temp(4)=RN2S Initial matchingRN2S Sorted matching=sortrows(RN2S Sorted matching temp)

RN3S Sorted matching temp(1)=RN3S Classical matchingRN3S Sorted matching temp(2)=RN3S Final matchingRN3S Sorted matching temp(3)=RN3S Greedy matchingRN3S Sorted matching temp(4)=RN3S Initial matchingRN3S Sorted matching=sortrows(RN3S Sorted matching temp)

subplot(231)hold onplot(RN1L Sorted matching(1)b)plot(RN1L Sorted matching(2)g)plot(RN1L Sorted matching(3)r)plot(RN1L Sorted matching(4)m)

Appendix A 57

grid ontitle(RN1L)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)

subplot(232)hold onplot(RN2L Sorted matching(1)b)plot(RN2L Sorted matching(2)g)plot(RN2L Sorted matching(3)r)plot(RN2L Sorted matching(4)m)grid ontitle(RN2L)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)

subplot(233)hold onplot(RN3L Sorted matching(1)b)plot(RN3L Sorted matching(2)g)plot(RN3L Sorted matching(3)r)plot(RN3L Sorted matching(4)m)grid ontitle(RN3L)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)

subplot(234)hold onplot(RN1S Sorted matching(1)b)plot(RN1S Sorted matching(2)g)plot(RN1S Sorted matching(3)r)plot(RN1S Sorted matching(4)m)grid ontitle(RN1S)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)

subplot(235)hold onplot(RN2S Sorted matching(1)b)plot(RN2S Sorted matching(2)g)plot(RN2S Sorted matching(3)r)plot(RN2S Sorted matching(4)m)grid ontitle(RN2S)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)

58 Application

subplot(236)hold onplot(RN3S Sorted matching(1)b)plot(RN3S Sorted matching(2)g)plot(RN3S Sorted matching(3)r)plot(RN3S Sorted matching(4)m)grid ontitle(RN3S)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)set(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN4png minusr300)h(5)=figure(NameSorted RatiosNumberTitleoff)RN1L ratio1=RN1L NodesG hatRN1L NodesGRN2L ratio1=RN2L NodesG hatRN2L NodesGRN3L ratio1=RN3L NodesG hatRN3L NodesGRN1S ratio1=RN1S NodesG hatRN1S NodesGRN2S ratio1=RN2S NodesG hatRN2S NodesGRN3S ratio1=RN3S NodesG hatRN3S NodesG

RN1L ratio2=RN1L EdgesG HatRN1L EdgesGRN2L ratio2=RN2L EdgesG HatRN2L EdgesGRN3L ratio2=RN3L EdgesG HatRN3L EdgesGRN1S ratio2=RN1S EdgesG HatRN1S EdgesGRN2S ratio2=RN2S EdgesG HatRN2S EdgesGRN3S ratio2=RN3S EdgesG HatRN3S EdgesG

RN1L ratio3=RN1L MaxDegreeG HatRN1L MaxDegreeGRN2L ratio3=RN2L MaxDegreeG HatRN2L MaxDegreeGRN3L ratio3=RN3L MaxDegreeG HatRN3L MaxDegreeGRN1S ratio3=RN1S MaxDegreeG HatRN1S MaxDegreeGRN2S ratio3=RN2S MaxDegreeG HatRN2S MaxDegreeGRN3S ratio3=RN3S MaxDegreeG HatRN3S MaxDegreeG

RN1L ratio(1)=RN1L ratio1RN1L ratio(2)=RN1L ratio2RN1L ratio(3)=RN1L ratio3

RN2L ratio(1)=RN2L ratio1RN2L ratio(2)=RN2L ratio2RN2L ratio(3)=RN2L ratio3

RN3L ratio(1)=RN3L ratio1RN3L ratio(2)=RN3L ratio2RN3L ratio(3)=RN3L ratio3

RN1S ratio(1)=RN1S ratio1RN1S ratio(2)=RN1S ratio2RN1S ratio(3)=RN1S ratio3

RN2S ratio(1)=RN2S ratio1

Appendix A 59

RN2S ratio(2)=RN2S ratio2RN2S ratio(3)=RN2S ratio3

RN3S ratio(1)=RN3S ratio1RN3S ratio(2)=RN3S ratio2RN3S ratio(3)=RN3S ratio3

RN1L ratio sorted=sortrows(RN1L ratio)RN2L ratio sorted=sortrows(RN2L ratio)RN3L ratio sorted=sortrows(RN3L ratio)RN1S ratio sorted=sortrows(RN1S ratio)RN2S ratio sorted=sortrows(RN2S ratio)RN3S ratio sorted=sortrows(RN3S ratio)

subplot(231)hold onplot(RN1L ratio sorted(1)b)plot(RN1L ratio sorted(2)g)plot(RN1L ratio sorted(3)r)grid ontitle(RN1L)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)

subplot(232)hold onplot(RN2L ratio sorted(1)b)plot(RN2L ratio sorted(2)g)plot(RN2L ratio sorted(3)r)grid ontitle(RN2L)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)

subplot(233)hold onplot(RN3L ratio sorted(1)b)plot(RN3L ratio sorted(2)g)plot(RN3L ratio sorted(3)r)grid ontitle(RN3L)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)

subplot(234)hold onplot(RN1S ratio sorted(1)b)plot(RN1S ratio sorted(2)g)plot(RN1S ratio sorted(3)r)grid on

60 Application

title(RN1S)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)

subplot(235)hold onplot(RN2S ratio sorted(1)b)plot(RN2S ratio sorted(2)g)plot(RN2S ratio sorted(3)r)grid ontitle(RN2S)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)

subplot(236)hold onplot(RN3S ratio sorted(1)b)plot(RN3S ratio sorted(2)g)plot(RN3S ratio sorted(3)r)grid ontitle(RN3S)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)set(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN5png minusr300)

h(6)=figure(NameSorted edges over nodesNumberTitleoff)

RN1L DegreeG1=(RN1L EdgesG)(RN1L NodesG)RN1L DegreeG Hat1=(RN1L EdgesG Hat)(RN1L NodesG hat)

RN1L Degree temp1(1)=RN1L DegreeG1RN1L Degree temp1(2)=RN1L DegreeG Hat1RN1L Degree sorted1=sortrows(RN1L Degree temp1)subplot(231)hold on

plot(RN1L Degree sorted1(1)b)plot(RN1L Degree sorted1(2)g)grid ontitle(RN1L)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)

RN2L DegreeG1=(RN2L EdgesG)(RN2L NodesG)RN2L DegreeG Hat1=(RN2L EdgesG Hat)(RN2L NodesG hat)

RN2L Degree temp1(1)=RN2L DegreeG1

Appendix A 61

RN2L Degree temp1(2)=RN2L DegreeG Hat1RN2L Degree sorted1=sortrows(RN2L Degree temp1)

subplot(232)hold onplot(RN2L Degree sorted1(1)b)plot(RN2L Degree sorted1(2)g)grid ontitle(RN2L)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)

RN3L DegreeG1=(RN3L EdgesG)(RN3L NodesG)RN3L DegreeG Hat1=(RN3L EdgesG Hat)(RN3L NodesG hat)

RN3L Degree temp1(1)=RN3L DegreeG1RN3L Degree temp1(2)=RN3L DegreeG Hat1RN3L Degree sorted1=sortrows(RN3L Degree temp1)

subplot(233)hold onplot(RN3L Degree sorted1(1)b)plot(RN3L Degree sorted1(2)g)grid ontitle(RN3L)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)

RN1S DegreeG1=(RN1S EdgesG)(RN1S NodesG)RN1S DegreeG Hat1=(RN1S EdgesG Hat)(RN1S NodesG hat)

RN1S Degree temp1(1)=RN1S DegreeG1RN1S Degree temp1(2)=RN1S DegreeG Hat1RN1S Degree sorted1=sortrows(RN1S Degree temp1)

subplot(234)hold onplot(RN1S Degree sorted1(1)b)plot(RN1S Degree sorted1(2)g)grid ontitle(RN1S)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)

RN2S DegreeG1=(RN2S EdgesG)(RN2S NodesG)RN2S DegreeG Hat1=(RN2S EdgesG Hat)(RN2S NodesG hat)

RN2S Degree temp1(1)=RN2S DegreeG1

62 Application

RN2S Degree temp1(2)=RN2S DegreeG Hat1RN2S Degree sorted1=sortrows(RN2S Degree temp1)

subplot(235)hold onplot(RN2S Degree sorted1(1)b)plot(RN2S Degree sorted1(2)g)grid ontitle(RN2S)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)

RN3S DegreeG1=(RN3S EdgesG)(RN3S NodesG)RN3S DegreeG Hat1=(RN3S EdgesG Hat)(RN3S NodesG hat)

RN3S Degree temp1(1)=RN3S DegreeG1RN3S Degree temp1(2)=RN3S DegreeG Hat1RN3S Degree sorted1=sortrows(RN3S Degree temp1)

subplot(236)hold onplot(RN3S Degree sorted1(1)b)plot(RN3S Degree sorted1(2)g)grid ontitle(RN3S)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)set(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN6png minusr300)h(7)=figure(NameSorted mATCHED DEGREENumberTitleoff)RN1L ratioMax(1)=RN1L MaxDegreeGRN1L ratioMax(2)=RN1L MaxDegreeG Hat

RN1L ratio sortedMax=sortrows(RN1L ratioMax)subplot(231)hold onplot(RN1L ratio sortedMax(1)b)plot(RN1L ratio sortedMax(2)g)grid ontitle(RN1L)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)

RN2L ratioMax(1)=RN2L MaxDegreeGRN2L ratioMax(2)=RN2L MaxDegreeG Hat

RN2L ratio sortedMax=sortrows(RN2L ratioMax)subplot(232)

Appendix A 63

hold onplot(RN2L ratio sortedMax(1)b)plot(RN2L ratio sortedMax(2)g)grid ontitle(RN2L)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)

RN3L ratioMax(1)=RN3L MaxDegreeGRN3L ratioMax(2)=RN3L MaxDegreeG Hat

RN3L ratio sortedMax=sortrows(RN3L ratioMax)subplot(233)hold onplot(RN3L ratio sortedMax(1)b)plot(RN3L ratio sortedMax(2)g)grid ontitle(RN3L)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)

RN1S ratioMax(1)=RN1S MaxDegreeGRN1S ratioMax(2)=RN1S MaxDegreeG Hat

RN1S ratio sortedMax=sortrows(RN1S ratioMax)subplot(234)hold onplot(RN1S ratio sortedMax(1)b)plot(RN1S ratio sortedMax(2)g)grid ontitle(RN1S)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)

RN2S ratioMax(1)=RN2S MaxDegreeGRN2S ratioMax(2)=RN2S MaxDegreeG Hat

RN2S ratio sortedMax=sortrows(RN2S ratioMax)

subplot(235)hold onplot(RN2S ratio sortedMax(1)b)plot(RN2S ratio sortedMax(2)g)grid ontitle(RN2S)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)

RN3S ratioMax(1)=RN3S MaxDegreeGRN3S ratioMax(2)=RN3S MaxDegreeG Hat

64 Application

RN3S ratio sortedMax=sortrows(RN3S ratioMax)subplot(236)hold onplot(RN3S ratio sortedMax(1)b)plot(RN3S ratio sortedMax(2)g)grid ontitle(RN1L)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)set(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN7png minusr300)

tilefigs()(h)

Bibliography

[1] C Berge ldquoTWO THEOREMS IN GRAPH THEORYrdquo Proceedings of the NationalAcademy of Sciences of the United States of America vol 43 no 9 pp 842ndash844Sep 1957

[2] L Bui S Sanghavi and R Srikant ldquoDistributed link scheduling with constantoverheadrdquo IEEEACM Trans Netw vol 17 no 5 pp 1467ndash1480 2009

[3] R Duan and S Pettie ldquoLinear-time approximation for maximum weight matchingrdquoJ ACM vol 61 no 1 2014

[4] J Edmonds ldquoPaths trees and flowersrdquo Canadian Journal of Mathematics vol 17pp 449ndash467 1965

[5] J E Hopcroft and R M Karp ldquoAn n52 algorithm for maximum matchings inbipartite graphsrdquo SIAM J Comput vol 2 no 4 pp 225ndash231 1973

[6] S Micali and V V Vazirani ldquoAn O(radic|V ||E|) algorithm for finding maximum

matching in general graphsrdquo in 21st Symp on Foundations of Comp Sc (FOCS)IEEE 1980 pp 17ndash27

[7] N Nisse A Salch and V Weber ldquoRecovery of disrupted airline operationsrdquo 2015httphalinriafrSomething

[8] X Wu and R Srikant ldquoRegulated maximal matching A distributed schedulingalgorithm for multi-hop wireless networks with nodeexclusive spectrum sharingrdquo inIEEE Conf on Decision and Control 2005

65

  • Contents
  • Introduction
  • Algorithms
    • Maximum matching
    • k-maximum matching
      • k-matching for Airport Slot assignment
      • The case where k=3
      • The case of Paths
      • The case of the Spider
          • Application
            • Description
            • Reyni Erdos
            • Barabaacutesi Albert
            • Amadeus Graphs
            • Bipartite
            • Bipartite with degree seq
            • Appendix A
              • BipartiteGraphGeneratorpy
              • RandomGraphGeneratorpy
              • kequals3MaximumMatchingpy
              • Plotmat
                  • Bibliography
Page 30: Theodoros Alexandros KARAGKIOULES -  · Introduction This work is the result of a 6 months internship, under the supervision of research O cer Nicolas NISSE. The original scope of

25 Bipartite 31

bull Regardless of the probability the ration of nodes and edges seems to have similarbehaviour when compared to the respective graphs of the same matching scale

bull Same gap between nodes ration and edges ration for all cases

Sorted |E||V |

Sorted |E||V | - Comments

bull In these set of figures we witness that the |E||V | acquires values relevant to those ofthe amadeus graphs The random graphs were constructed to depict this similarity

bull For smaller initial matching the ratios for G and G show the same upward trendand also they acquire closer values It represents the decrease of the averagenumber of forced edges in comparison to the larger matching cases

32 Application

Sorted ∆

Sorted ∆-Comments

bull ∆ acquires the same min and max values for each probability case (expected)

bull Gap in the case of large initial matching

26 Bipartite with degree seq

Graph characteristics

bull DEQBIPxy are randomly generated graphs based on three different types of degreedistribution of the Amadeus graphs

26 Bipartite with degree seq 33

bull There are 6 categories based on ini matching and degree distribution

bull x = L S L When the initial matching is large and S when it is small

bull y = 1 2 3 1 when degree distribution is based on file 2 when degree distributionis based on file and 3 when degree distribution is based on file

Computation time over

34 Application

Computation time overedges-Comments

bull Greedy algorithm takes minimum amount of time

bull The smaller the initial matching the more smaller the difference in comoutationtime of Constraint and classical algorithm

bull Due to preprocessing and the fact that G and G are the almost identical thetotal time needed to apply the constraint algorithm is in some cases bigger

Sorted matching size

26 Bipartite with degree seq 35

Sorted matching size-Comments

bull Classical matching is equal to perfect matching in every case

bull Constraint and greedy have identical behaviour

bull The larger the spectrum of the degree sequence the more efficient the matching

Sorted Ratios

36 Application

Sorted Ratios-Comments

bull With large initial matching most of the edges are considenred uselles or forced andare removed thus the ratio is close(if not equal to) zero

bull For small matching and large degree sequence sectrum hte max degree remainsthe same Only a few forced edges (and their nodes) are removed apparently nonodes with max degree

Sorted |E||V |

26 Bipartite with degree seq 37

Sorted |E||V | - Comments

bull In these set of figures we witness that the |E||V | acquires values relevant to those ofthe amadeus graphs The random graphs were constructed to depict this similarity

bull For smaller initial matching the ratios for G and G show the same upward trendand also they acquire closer values It repsresent the decrease of the averagenumber of forced edges in comparison to the larger matching cases

Sorted ∆

38 Application

Sorted ∆-Comments

bull Big difference in max degree in large initial matching

bull Almost identical behaviour in the case of small initial matching

Appendix A 39

Appendix A

BipartiteGraphGeneratorpy

from future import divisionimport networkx as nx

from networkxalgorithms import approximationimport collectionsimport randomimport mathfrom networkxalgorithms import bipartiteif name == main

for i in range(1481)waqs 481index=1n=randomrandint(100 1000)

n1=95 was 500me1=118

n2=251 was 500me2=903

n3=165 was 500me3=412

m=0m1=0p=randomrandom()p1=18250p2=25250p3=34250print ip=05t1=randomrandint(0 1)print im2=randomrandint(n2minus1 n2+1)G = nxGraph()ma = nxGraph()

aseq1=[1 2 3 4 5 3]

bseq1=[4 3 3 1 2 2 1]

aseq2=[16 14 14 14 12 11]bseq2=[0 0 0 0 0 0]

aseq3=[8 7 8 8 8 8]bseq3=[0 0 0 0 0 0]

40 Application

print Gnumber of edges()if ilt=160

G=bipartiteconfiguration model(aseq1 bseq1 create using=None seed=None)A=nxadjacency matrix(G)for ii in range(0n1+me1)

maadd node(ii)A=[Rtodense()tolist()[0] for R in A]

printnummanumber of nodes()rl=randomsample(range(0n1+me1) n1+me1)m=0done vertices = set()for p in rlprintin fordone verticesadd(p)

neighbors = []list()for iii in range(0n1+me1)

if A[p][iii]==1neighborsappend(iii)

randomshuffle(neighbors)continue loop = Truedegree = len(neighbors)

print degreej = 0p4=randomrandom()while continue loop and (jltdegree)print in loop

next = neighbors[j]if next not in done vertices and p not in done vertices

done verticesadd(p)done verticesadd(next)if p4gt=07print added edge

maadd edge(pnext)m=m+1

continue loop = Falsej += 1

print matching listOfedgeprint maedge

MA=nxadjacency matrix(ma)print MA

MA=[Rtodense()tolist()[0] for R in MA]print MA

B=[ join(map(strR)) for R in A]MB=[ join(map(strR)) for R in MA]

C=njoin(B)+nMC=njoin(MB)+n

print nprint mprint m1

filea=str(i)+txtwith open(fileaw) as f

Appendix A 41

fwrite(str(n1+me1))fwrite(n)fwrite(str(n1+me1))fwrite(n)fwrite(str(m))fwrite(n)fwrite(n)fwrite(C)fwrite(n)fwrite(MC)

elif igt160 and ilt321G=bipartiteconfiguration model(aseq2 bseq2 create using=None seed=None)A=nxadjacency matrix(G)for ii in range(0n2+me2)

maadd node(ii)A=[Rtodense()tolist()[0] for R in A]

printnummanumber of nodes()rl=randomsample(range(0n2+me2) n2+me2)m=0done vertices = set()for p in rlprintin fordone verticesadd(p)

neighbors = []list()for iii in range(0n2+me2)

if A[p][iii]==1neighborsappend(iii)

randomshuffle(neighbors)continue loop = Truedegree = len(neighbors)

print degreej = 0p4=randomrandom()while continue loop and (jltdegree)

print in loopnext = neighbors[j]if next not in done vertices and p not in done vertices

done verticesadd(p)done verticesadd(next)if p4gt=07

print added edgemaadd edge(pnext)m=m+1

continue loop = Falsej += 1

print matching listOfedgeprint maedge

MA=nxadjacency matrix(ma)print MA

MA=[Rtodense()tolist()[0] for R in MA]print MA

B=[ join(map(strR)) for R in A]MB=[ join(map(strR)) for R in MA]

42 Application

C=njoin(B)+nMC=njoin(MB)+n

print nprint mprint m1

filea=str(i)+txtwith open(fileaw) as f

fwrite(str(n2+me2))fwrite(n)fwrite(str(n2+me2))fwrite(n)fwrite(str(m))fwrite(n)fwrite(n)fwrite(C)fwrite(n)fwrite(MC)

elseG=bipartiteconfiguration model(aseq3 bseq3 create using=None seed=None)A=nxadjacency matrix(G)for ii in range(0n3+me3)

maadd node(ii)A=[Rtodense()tolist()[0] for R in A]

printnummanumber of nodes()rl=randomsample(range(0n3+me3) n3+me3)m=0done vertices = set()for p in rlprintin fordone verticesadd(p)

neighbors = []list()for iii in range(0n3+me3)

if A[p][iii]==1neighborsappend(iii)

randomshuffle(neighbors)continue loop = Truedegree = len(neighbors)

print degreej = 0p4=randomrandom()while continue loop and (jltdegree)

print in loopnext = neighbors[j]if next not in done vertices and p not in done vertices

done verticesadd(p)done verticesadd(next)if p4gt=07print added edge

maadd edge(pnext)m=m+1

continue loop = Falsej += 1

Appendix A 43

print matching listOfedgeprint maedge

MA=nxadjacency matrix(ma)print MA

MA=[Rtodense()tolist()[0] for R in MA]print MA

B=[ join(map(strR)) for R in A]MB=[ join(map(strR)) for R in MA]

C=njoin(B)+nMC=njoin(MB)+n

print nprint mprint m1

filea=str(i)+txtwith open(fileaw) as f

fwrite(str(n3+me3))fwrite(n)fwrite(str(n3+me3))fwrite(n)fwrite(str(m))fwrite(n)fwrite(n)fwrite(C)fwrite(n)fwrite(MC)

print nRandom graphs with random matching have been generated

44 Application

RandomGraphGeneratorpy

from future import divisionimport networkx as nxfrom networkxalgorithms import approximationimport collectionsimport randomimport mathif name == main

for i in range(1481)index=1n=randomrandint(100 1000)

n=1000m=0m1=0p=randomrandom()p1=mathlog(n2)np2=13p3=mathlog(n2)n+01p=05t1=randomrandint(0 1)print im2=randomrandint(n2minus1 n2+1)G = nxGraph()ma = nxGraph()print nme1=randomrandint(1 10)me2=randomrandint(2050)me3=randomrandint(50100)if ilt241

if ilt=80G=nxfast gnp random graph(n p1 seed=None directed=False)

elif igt80 and ilt161G=nxfast gnp random graph(n p2 seed=None directed=False)

elseG=nxfast gnp random graph(n p3 seed=None directed=False)

elseif ilt=320

G=nxbarabasi albert graph(n me1 seed=None)elif igt320 and ilt401

G=nxbarabasi albert graph(n me2 seed=None)else

G=nxbarabasi albert graph(n me3 seed=None)A=nxadjacency matrix(G)for ii in range(0n)

maadd node(ii)A=[Rtodense()tolist()[0] for R in A]

rl=randomsample(range(0n) n)m=0

Appendix A 45

done vertices = set()for p in rl

done verticesadd(p)neighbors = []list()for iii in range(0n)

if A[p][iii]==1neighborsappend(iii)

randomshuffle(neighbors)continue loop = Truedegree = len(neighbors)j = 0p2=randomrandom()while continue loop and (jltdegree)

next = neighbors[j]if next not in done vertices and p not in done vertices

done verticesadd(p)done verticesadd(next)if p2gt=00 Larger probability for smaller initial matching

maadd edge(pnext)m=m+1

continue loop = Falsej += 1

print matching listOfedgeprint maedgeMA=nxadjacency matrix(ma)MA=[Rtodense()tolist()[0] for R in MA]print MAB=[ join(map(strR)) for R in A]MB=[ join(map(strR)) for R in MA]

C=njoin(B)+nMC=njoin(MB)+nprint MCprint nprint mprint m1filea=str(i)+txtwith open(fileaw) as f

fwrite(str(n))fwrite(n)fwrite(str(n))fwrite(n)fwrite(str(m))fwrite(n)fwrite(n)fwrite(C)fwrite(n)fwrite(MC)

print nRandom graphs with random matching have been generated

46 Application

kequals3MaximumMatchingpy

from future import divisionimport networkx as nxfrom networkxalgorithms import bipartiteimport matplotlibpyplot as pltimport collectionsimport timeitimport xlwtimport xlrdimport mathimport sys

Case for General Graphsdef forced edges(Gadj dict2matching dict1num nodesforced)

flagg=0for n in range(0num nodes)

for k in adj dict2[n]if ([k]==matching dict1[n])

count=0for l in range(0num nodes)

count=count+adj dict2[l]count(k)if (len(adj dict2[n])==1) or (count==1)

forcedadd edge(nk)Gremove edge(nk)Gremove node(n)Gremove node(k)printforced edgenktemp=kflagg=1for m in range (len(adj dict2[n])minus1minus1minus1)

adj dict2[adj dict2[n][m]]remove(n)adj dict2[n]remove(adj dict2[n][m])

if adj dict2[temp]for l in range(len(adj dict2[temp])minus1minus1minus1)

if (adj dict2[temp][l]=n)adj dict2[adj dict2[temp][l]]remove(temp)adj dict2[temp]remove(adj dict2[temp][l])

break

def useless edges(num nodesadj dict1matching dict1uselessadj dict2G)for n in range(0num nodes)

for k in adj dict1[n]if ([k]=matching dict1[n]) and matching dict1[n] and matching dict1[k]

uselessadd edge(nk)Gremove edge(n k)

Appendix A 47

tempa=kadj dict2[n]remove(k)adj dict2[tempa]remove(n)adj dict1[tempa]remove(n)

return G

def Greedy(num nodesadj dict3matching dict2)

for n in range(0num nodes)if matching dict2[n]

flag2=minus1flag3=minus1for v in adj dict3[n]

if not matching dict2[v]flag2=vbreak

for p in adj dict3[matching dict2[n][0]]if not matching dict2[p]

flag3=pbreak

if (flag2=minus1) and (flag3=minus1) and (flag2=flag3)tempr=matching dict2[n][0]matching dict2[n]=[flag2]matching dict2[flag2]=[n]matching dict2[tempr]=[flag3]matching dict2[flag3]=[tempr]

elsefor k in adj dict3[n]

if not matching dict2[k]matching dict2[n]=[k]matching dict2[k]=[n]break

yo1=0for i in range(0num nodes)

if matching dict2[i] and [i]==matching dict2[matching dict2[i][0]]yo1=yo1+1

greedy size=yo12return greedy size

def General()

INPUTSwb = xlwtWorkbook()ws = wbadd sheet(Results Random)book=xlrdopen workbook(filenames randomxls)

48 Application

style0 = xlwteasyxf(fontbold on)style1 = xlwteasyxf(num format str=0000)INPUTSwswrite(0 0File style0)wswrite(0 1 Nodesstyle0)wswrite(0 2 Initial matchingstyle0)wswrite(0 3 NodesGstyle0)wswrite(0 4 EdgesGstyle0)wswrite(0 5 MaxDegreeGstyle0)wswrite(0 6 NodesG hatstyle0)wswrite(0 7 EdgesG Hatstyle0)wswrite(0 8 Useless edgesstyle0)wswrite(0 9 Forced edgesstyle0)wswrite(0 10 MaxDegreeG Hatstyle0)wswrite(0 11 Classical matchingstyle0)wswrite(0 12 Final matchingstyle0)wswrite(0 13 Greedy matchingstyle0)wswrite(0 14 Time classicalstyle0)wswrite(0 15 Time algorithmstyle0)wswrite(0 16 Time greedystyle0)wswrite(0 17 Perfect matching ratiostyle0)wswrite(0 18 Nodes ratiostyle0)wswrite(0 19 Edges ratiostyle0)wswrite(0 20 Matching ratiostyle0)

print nWelcomeThis is an implementation for general random graphs It uses Edmonds algorithm to compute maximum matching on G Hatn

for index in range (1481)was 481

if (index==482)f=open(Algotel generaltxtr)readlines()

elsefilea=str(booksheet by index(0)cell(index0))s=fileareplace(textu)replace()f=open(sr)readlines()Truewswrite(index 0 s)

print index

num nodes=int([xstrip()split() for x in f][0][0])

num matching=int([xstrip()split() for x in f][2][0])

adj temp = [xstrip()split() for x in f][44+num nodes]adj=[map(intR) for R in adj temp]

matching temp=[xstrip()split() for x in f][4+num nodes+14+2num nodes+1]matching1=[map(intR) for R in matching temp]

adj dict1=i[ii for iix in enumerate(L) if x] for iL in enumerate(adj)adj dict2=i[ii for iix in enumerate(L) if x] for iL in enumerate(adj)

Appendix A 49

adj dict3=i[ii for iix in enumerate(L) if x] for iL in enumerate(adj)

matching dict1=i[ii for iix in enumerate(L) if x] for iL in enumerate(matching1)matching dict2=i[ii for iix in enumerate(L) if x] for iL in enumerate(matching1)print adj dict2print matching dict2wswrite(index 1 num nodes)wswrite(index 2 num matching)

G = nxGraph()

useless= nxGraph()forced = nxGraph()

Fill Graphfor n in range(0num nodes)

for k in adj dict1[n]Gadd edge(nk)

Gt=Gnumber of edges()wswrite(index 3 Gnumber of nodes())wswrite(index 4 Gnumber of edges())wswrite(index 5 max(Gdegree()values()))

Compute Edmonds classical matching on G for comparison

startB = timeitdefault timer()Classical Matching=nxmax weight matching(G maxcardinality=False)stopB = timeitdefault timer()

Compute Gˆ nad MˆstartC = timeitdefault timer()useless edges(num nodesadj dict1matching dict1uselessadj dict2G)forced edges(Gadj dict2matching dict1num nodesforced)Final Matching=nxmax weight matching(G maxcardinality=False)stopC = timeitdefault timer()

GreedystartG = timeitdefault timer()greedy size=Greedy(num nodesadj dict3matching dict2)stopG = timeitdefault timer()

wswrite(index 6 Gnumber of nodes())wswrite(index 7 Gnumber of edges())wswrite(index 8 uselessnumber of edges())wswrite(index 9 forcednumber of edges())if Gdegree()values()

wswrite(index 10 max(Gdegree()values()))else

50 Application

wswrite(index 10 0)wswrite(index 11 len(Classical Matching)2)wswrite(index 12 len(Final Matching)2+forcednumber of edges())wswrite(index 13 greedy size)wswrite(index 14 stopB minus startBstyle1)wswrite(index 15 stopC minus startCstyle1)wswrite(index 16 stopG minus startGstyle1)wswrite(index 17 (len(Final Matching)2+forcednumber of edges())(num nodes2)style1)wswrite(index 18 Gnumber of nodes()Gtstyle1)wswrite(index 19 Gnumber of edges()Gtstyle1)wswrite(index 20 (len(Final Matching)2+forcednumber of edges())(len(Classical Matching)2)style1)

wbsave(AA Results Random Reyni Large Bipartitexls)

Main function Here we must choose the input form of the dataif name == main

startA = timeitdefault timer()General()stopA = timeitdefault timer()

print nThis program has terminatednnRunning time for 480 files stopAminusstartAprint nnPlease open AA Results Random Reyni Largexls file to see the Results

Appendix A 51

Plotmat

clear allclose allload(RN1Lmat)load(RN1Smat)load(RN2Lmat)load(RN2Smat)load(RN3Lmat)load(RN3Smat)

Plotsh(1)=figure(NameHistogram of Matching size difference between Constraint Algorithm and Greedy AlgorithmNumberTitleoff)

RN1L Greedydiff=RN1L Final matchingminusRN1L Greedy matchingRN2L Greedydiff=RN2L Final matchingminusRN2L Greedy matchingRN3L Greedydiff=RN3L Final matchingminusRN3L Greedy matchingRN1S Greedydiff=RN1S Final matchingminusRN1S Greedy matchingRN2S Greedydiff=RN2S Final matchingminusRN2S Greedy matchingRN3S Greedydiff=RN3S Final matchingminusRN3S Greedy matching

RN1L Finaldiff=RN1L Classical matchingminusRN1L Final matchingRN2L Finaldiff=RN2L Classical matchingminusRN2L Final matchingRN3L Finaldiff=RN3L Classical matchingminusRN3L Final matchingRN1S Finaldiff=RN1S Classical matchingminusRN1S Final matchingRN2S Finaldiff=RN2S Classical matchingminusRN2S Final matchingRN3S Finaldiff=RN3S Classical matchingminusRN3S Final matching

RN1L Classicaldiff=(RN1L Nodes2)minusRN1L Classical matchingRN2L Classicaldiff=(RN2L Nodes2)minusRN2L Classical matchingRN3L Classicaldiff=(RN3L Nodes2)minusRN3L Classical matchingRN1S Classicaldiff=(RN1S Nodes2)minusRN1S Classical matchingRN2S Classicaldiff=(RN2S Nodes2)minusRN2S Classical matchingRN3S Classicaldiff=(RN3S Nodes2)minusRN3S Classical matching

subplot(231)hold onhistf(RN1L Greedydiff0110facecolorbfacealpha9edgealpha1)histf(RN1L Finaldiff0110facecolorrfacealpha5edgealpha1)histf(RN1L Classicaldiff0110facecolorgfacealpha5edgealpha1)legalpha(ConminusGreClasminusConPerfminusClasslocationnortheast)legend boxoffaxis tightxlabel(edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN1L)grid on

subplot(232)hold onhistf(RN2L Greedydiff0110facecolorbfacealpha9edgealpha1)

52 Application

histf(RN2L Finaldiff0110facecolorrfacealpha5edgealpha1)histf(RN2L Classicaldiff0110facecolorgfacealpha5edgealpha1)legalpha(ConminusGreClasminusConPerfminusClasslocationnortheast)legend boxoffaxis tightxlabel(edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN2L)grid on

subplot(233)hold onhistf(RN3L Greedydiff0110facecolorbfacealpha5edgealpha1)histf(RN3L Finaldiff0110facecolorrfacealpha5edgealpha1)histf(RN3L Classicaldiff0110facecolorgfacealpha5edgealpha1)legalpha(ConminusGreClasminusConPerfminusClasslocationnortheast)legend boxoffaxis tightxlabel(edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN3L)grid on

subplot(234)hold onhistf(RN1S Greedydiff0110facecolorbfacealpha5edgealpha1)histf(RN1S Finaldiff0110facecolorrfacealpha5edgealpha1)histf(RN1S Classicaldiff0110facecolorgfacealpha5edgealpha1)legalpha(ConminusGreClasminusConPerfminusClasslocationnortheast)legend boxoffaxis tightxlabel(edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(R1NS)grid on

subplot(235)hold onhistf(RN2S Greedydiff0110facecolorbfacealpha5edgealpha1)histf(RN2S Finaldiff0110facecolorrfacealpha5edgealpha1)histf(RN2S Classicaldiff0110facecolorgfacealpha5edgealpha1)legalpha(ConminusGreClasminusConPerfminusClasslocationnortheast)legend boxoffaxis tightxlabel(edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN2S)grid on

subplot(236)hold onhistf(RN3S Greedydiff0110facecolorbfacealpha5edgealpha1)histf(RN3S Finaldiff0110facecolorrfacealpha5edgealpha1)histf(RN3S Classicaldiff0110facecolorgfacealpha5edgealpha1)

Appendix A 53

legalpha(ConminusGreClasminusConPerfminusClasslocationnortheast)legend boxoffaxis tightgrid ontitle(RN3S)xlabel(edges) xminusaxis labelylabel(instances) yminusaxis labelset(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN1png minusr300)h(2)=figure(NameHistogram of Max Degree of G AND G HatNumberTitleoff)RN1L x=RN1L MaxDegreeGminusRN1L MaxDegreeG HatRN2L x=RN2L MaxDegreeGminusRN2L MaxDegreeG HatRN3L x=RN3L MaxDegreeGminusRN3L MaxDegreeG HatRN1S x=RN1S MaxDegreeGminusRN1S MaxDegreeG HatRN2S x=RN2S MaxDegreeGminusRN2S MaxDegreeG HatRN3S x=RN3S MaxDegreeGminusRN3S MaxDegreeG Hatsubplot(231)hold onhistf(RN1L MaxDegreeG0150facecolorbfacealpha5edgealpha1)histf(RN1L MaxDegreeG Hat0150facecolorrfacealpha5edgealpha1)histf(RN1L x0150facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightxlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN1L)grid on

subplot(232)hold onhistf(RN2L MaxDegreeG010500facecolorbfacealpha5edgealpha1)histf(RN2L MaxDegreeG Hat010500facecolorrfacealpha5edgealpha1)histf(RN2L x010500facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightxlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN2L)grid on

subplot(233)hold onhistf(RN3L MaxDegreeG010300facecolorbfacealpha5edgealpha1)histf(RN3L MaxDegreeG Hat010300facecolorrfacealpha5edgealpha1)histf(RN3L x010300facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightxlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN3L)

54 Application

grid on

subplot(234)hold onhistf(RN1S MaxDegreeG0150facecolorbfacealpha5edgealpha1)histf(RN1S MaxDegreeG Hat0150facecolorrfacealpha5edgealpha1)histf(RN1S x0150facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightxlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(R1NS)grid on

subplot(235)hold onhistf(RN2S MaxDegreeG010500facecolorbfacealpha5edgealpha1)histf(RN2S MaxDegreeG Hat010500facecolorrfacealpha5edgealpha1)histf(RN2S x010500facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightxlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN2S)grid on

subplot(236)hold onhistf(RN3S MaxDegreeG05300facecolorbfacealpha5edgealpha1)histf(RN3S MaxDegreeG Hat05300facecolorrfacealpha5edgealpha1)histf(RN3S x05300facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightgrid ontitle(RN3S)xlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labelset(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN2png minusr300)

h(3)=figure(NameComputation time over edgesNumberTitleoff)

subplot(231)hold onstem(RN1L EdgesGRN1L Time classicalg)stem(RN1L EdgesGRN1L Time algorithmro)stem(RN1L EdgesGRN1L Time greedybx)grid on

Appendix A 55

title(RN1L)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)

subplot(232)hold onstem(RN2L EdgesGRN2L Time classicalg)stem(RN2L EdgesGRN2L Time algorithmro)stem(RN2L EdgesGRN2L Time greedybx)grid ontitle(RN2L)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)

subplot(233)hold onstem(RN3L EdgesGRN3L Time classicalg)stem(RN3L EdgesGRN3L Time algorithmro)stem(RN3L EdgesGRN3L Time greedybx)grid ontitle(RN3L)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)

subplot(234)hold onstem(RN1S EdgesGRN1S Time classicalg)stem(RN1S EdgesGRN1S Time algorithmro)stem(RN1S EdgesGRN1S Time greedybx)grid ontitle(RN1S)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)

subplot(235)hold onstem(RN2S EdgesGRN2S Time classicalg)stem(RN2S EdgesGRN2S Time algorithmro)stem(RN2S EdgesGRN2S Time greedybx)grid ontitle(RN2S)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)

subplot(236)hold onstem(RN3S EdgesGRN3S Time classicalg)stem(RN3S EdgesGRN3S Time algorithmro)stem(RN3S EdgesGRN3S Time greedybx)

56 Application

grid ontitle(RN3S)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)set(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN3png minusr300)

h(4)=figure(NameSorted matching sizeNumberTitleoff)RN1L Sorted matching temp(1)=RN1L Classical matchingRN1L Sorted matching temp(2)=RN1L Final matchingRN1L Sorted matching temp(3)=RN1L Greedy matchingRN1L Sorted matching temp(4)=RN1L Initial matchingRN1L Sorted matching=sortrows(RN1L Sorted matching temp)

RN2L Sorted matching temp(1)=RN2L Classical matchingRN2L Sorted matching temp(2)=RN2L Final matchingRN2L Sorted matching temp(3)=RN2L Greedy matchingRN2L Sorted matching temp(4)=RN2L Initial matchingRN2L Sorted matching=sortrows(RN2L Sorted matching temp)

RN3L Sorted matching temp(1)=RN3L Classical matchingRN3L Sorted matching temp(2)=RN3L Final matchingRN3L Sorted matching temp(3)=RN3L Greedy matchingRN3L Sorted matching temp(4)=RN3L Initial matchingRN3L Sorted matching=sortrows(RN3L Sorted matching temp)

RN1S Sorted matching temp(1)=RN1S Classical matchingRN1S Sorted matching temp(2)=RN1S Final matchingRN1S Sorted matching temp(3)=RN1S Greedy matchingRN1S Sorted matching temp(4)=RN1S Initial matchingRN1S Sorted matching=sortrows(RN1S Sorted matching temp)

RN2S Sorted matching temp(1)=RN2S Classical matchingRN2S Sorted matching temp(2)=RN2S Final matchingRN2S Sorted matching temp(3)=RN2S Greedy matchingRN2S Sorted matching temp(4)=RN2S Initial matchingRN2S Sorted matching=sortrows(RN2S Sorted matching temp)

RN3S Sorted matching temp(1)=RN3S Classical matchingRN3S Sorted matching temp(2)=RN3S Final matchingRN3S Sorted matching temp(3)=RN3S Greedy matchingRN3S Sorted matching temp(4)=RN3S Initial matchingRN3S Sorted matching=sortrows(RN3S Sorted matching temp)

subplot(231)hold onplot(RN1L Sorted matching(1)b)plot(RN1L Sorted matching(2)g)plot(RN1L Sorted matching(3)r)plot(RN1L Sorted matching(4)m)

Appendix A 57

grid ontitle(RN1L)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)

subplot(232)hold onplot(RN2L Sorted matching(1)b)plot(RN2L Sorted matching(2)g)plot(RN2L Sorted matching(3)r)plot(RN2L Sorted matching(4)m)grid ontitle(RN2L)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)

subplot(233)hold onplot(RN3L Sorted matching(1)b)plot(RN3L Sorted matching(2)g)plot(RN3L Sorted matching(3)r)plot(RN3L Sorted matching(4)m)grid ontitle(RN3L)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)

subplot(234)hold onplot(RN1S Sorted matching(1)b)plot(RN1S Sorted matching(2)g)plot(RN1S Sorted matching(3)r)plot(RN1S Sorted matching(4)m)grid ontitle(RN1S)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)

subplot(235)hold onplot(RN2S Sorted matching(1)b)plot(RN2S Sorted matching(2)g)plot(RN2S Sorted matching(3)r)plot(RN2S Sorted matching(4)m)grid ontitle(RN2S)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)

58 Application

subplot(236)hold onplot(RN3S Sorted matching(1)b)plot(RN3S Sorted matching(2)g)plot(RN3S Sorted matching(3)r)plot(RN3S Sorted matching(4)m)grid ontitle(RN3S)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)set(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN4png minusr300)h(5)=figure(NameSorted RatiosNumberTitleoff)RN1L ratio1=RN1L NodesG hatRN1L NodesGRN2L ratio1=RN2L NodesG hatRN2L NodesGRN3L ratio1=RN3L NodesG hatRN3L NodesGRN1S ratio1=RN1S NodesG hatRN1S NodesGRN2S ratio1=RN2S NodesG hatRN2S NodesGRN3S ratio1=RN3S NodesG hatRN3S NodesG

RN1L ratio2=RN1L EdgesG HatRN1L EdgesGRN2L ratio2=RN2L EdgesG HatRN2L EdgesGRN3L ratio2=RN3L EdgesG HatRN3L EdgesGRN1S ratio2=RN1S EdgesG HatRN1S EdgesGRN2S ratio2=RN2S EdgesG HatRN2S EdgesGRN3S ratio2=RN3S EdgesG HatRN3S EdgesG

RN1L ratio3=RN1L MaxDegreeG HatRN1L MaxDegreeGRN2L ratio3=RN2L MaxDegreeG HatRN2L MaxDegreeGRN3L ratio3=RN3L MaxDegreeG HatRN3L MaxDegreeGRN1S ratio3=RN1S MaxDegreeG HatRN1S MaxDegreeGRN2S ratio3=RN2S MaxDegreeG HatRN2S MaxDegreeGRN3S ratio3=RN3S MaxDegreeG HatRN3S MaxDegreeG

RN1L ratio(1)=RN1L ratio1RN1L ratio(2)=RN1L ratio2RN1L ratio(3)=RN1L ratio3

RN2L ratio(1)=RN2L ratio1RN2L ratio(2)=RN2L ratio2RN2L ratio(3)=RN2L ratio3

RN3L ratio(1)=RN3L ratio1RN3L ratio(2)=RN3L ratio2RN3L ratio(3)=RN3L ratio3

RN1S ratio(1)=RN1S ratio1RN1S ratio(2)=RN1S ratio2RN1S ratio(3)=RN1S ratio3

RN2S ratio(1)=RN2S ratio1

Appendix A 59

RN2S ratio(2)=RN2S ratio2RN2S ratio(3)=RN2S ratio3

RN3S ratio(1)=RN3S ratio1RN3S ratio(2)=RN3S ratio2RN3S ratio(3)=RN3S ratio3

RN1L ratio sorted=sortrows(RN1L ratio)RN2L ratio sorted=sortrows(RN2L ratio)RN3L ratio sorted=sortrows(RN3L ratio)RN1S ratio sorted=sortrows(RN1S ratio)RN2S ratio sorted=sortrows(RN2S ratio)RN3S ratio sorted=sortrows(RN3S ratio)

subplot(231)hold onplot(RN1L ratio sorted(1)b)plot(RN1L ratio sorted(2)g)plot(RN1L ratio sorted(3)r)grid ontitle(RN1L)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)

subplot(232)hold onplot(RN2L ratio sorted(1)b)plot(RN2L ratio sorted(2)g)plot(RN2L ratio sorted(3)r)grid ontitle(RN2L)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)

subplot(233)hold onplot(RN3L ratio sorted(1)b)plot(RN3L ratio sorted(2)g)plot(RN3L ratio sorted(3)r)grid ontitle(RN3L)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)

subplot(234)hold onplot(RN1S ratio sorted(1)b)plot(RN1S ratio sorted(2)g)plot(RN1S ratio sorted(3)r)grid on

60 Application

title(RN1S)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)

subplot(235)hold onplot(RN2S ratio sorted(1)b)plot(RN2S ratio sorted(2)g)plot(RN2S ratio sorted(3)r)grid ontitle(RN2S)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)

subplot(236)hold onplot(RN3S ratio sorted(1)b)plot(RN3S ratio sorted(2)g)plot(RN3S ratio sorted(3)r)grid ontitle(RN3S)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)set(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN5png minusr300)

h(6)=figure(NameSorted edges over nodesNumberTitleoff)

RN1L DegreeG1=(RN1L EdgesG)(RN1L NodesG)RN1L DegreeG Hat1=(RN1L EdgesG Hat)(RN1L NodesG hat)

RN1L Degree temp1(1)=RN1L DegreeG1RN1L Degree temp1(2)=RN1L DegreeG Hat1RN1L Degree sorted1=sortrows(RN1L Degree temp1)subplot(231)hold on

plot(RN1L Degree sorted1(1)b)plot(RN1L Degree sorted1(2)g)grid ontitle(RN1L)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)

RN2L DegreeG1=(RN2L EdgesG)(RN2L NodesG)RN2L DegreeG Hat1=(RN2L EdgesG Hat)(RN2L NodesG hat)

RN2L Degree temp1(1)=RN2L DegreeG1

Appendix A 61

RN2L Degree temp1(2)=RN2L DegreeG Hat1RN2L Degree sorted1=sortrows(RN2L Degree temp1)

subplot(232)hold onplot(RN2L Degree sorted1(1)b)plot(RN2L Degree sorted1(2)g)grid ontitle(RN2L)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)

RN3L DegreeG1=(RN3L EdgesG)(RN3L NodesG)RN3L DegreeG Hat1=(RN3L EdgesG Hat)(RN3L NodesG hat)

RN3L Degree temp1(1)=RN3L DegreeG1RN3L Degree temp1(2)=RN3L DegreeG Hat1RN3L Degree sorted1=sortrows(RN3L Degree temp1)

subplot(233)hold onplot(RN3L Degree sorted1(1)b)plot(RN3L Degree sorted1(2)g)grid ontitle(RN3L)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)

RN1S DegreeG1=(RN1S EdgesG)(RN1S NodesG)RN1S DegreeG Hat1=(RN1S EdgesG Hat)(RN1S NodesG hat)

RN1S Degree temp1(1)=RN1S DegreeG1RN1S Degree temp1(2)=RN1S DegreeG Hat1RN1S Degree sorted1=sortrows(RN1S Degree temp1)

subplot(234)hold onplot(RN1S Degree sorted1(1)b)plot(RN1S Degree sorted1(2)g)grid ontitle(RN1S)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)

RN2S DegreeG1=(RN2S EdgesG)(RN2S NodesG)RN2S DegreeG Hat1=(RN2S EdgesG Hat)(RN2S NodesG hat)

RN2S Degree temp1(1)=RN2S DegreeG1

62 Application

RN2S Degree temp1(2)=RN2S DegreeG Hat1RN2S Degree sorted1=sortrows(RN2S Degree temp1)

subplot(235)hold onplot(RN2S Degree sorted1(1)b)plot(RN2S Degree sorted1(2)g)grid ontitle(RN2S)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)

RN3S DegreeG1=(RN3S EdgesG)(RN3S NodesG)RN3S DegreeG Hat1=(RN3S EdgesG Hat)(RN3S NodesG hat)

RN3S Degree temp1(1)=RN3S DegreeG1RN3S Degree temp1(2)=RN3S DegreeG Hat1RN3S Degree sorted1=sortrows(RN3S Degree temp1)

subplot(236)hold onplot(RN3S Degree sorted1(1)b)plot(RN3S Degree sorted1(2)g)grid ontitle(RN3S)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)set(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN6png minusr300)h(7)=figure(NameSorted mATCHED DEGREENumberTitleoff)RN1L ratioMax(1)=RN1L MaxDegreeGRN1L ratioMax(2)=RN1L MaxDegreeG Hat

RN1L ratio sortedMax=sortrows(RN1L ratioMax)subplot(231)hold onplot(RN1L ratio sortedMax(1)b)plot(RN1L ratio sortedMax(2)g)grid ontitle(RN1L)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)

RN2L ratioMax(1)=RN2L MaxDegreeGRN2L ratioMax(2)=RN2L MaxDegreeG Hat

RN2L ratio sortedMax=sortrows(RN2L ratioMax)subplot(232)

Appendix A 63

hold onplot(RN2L ratio sortedMax(1)b)plot(RN2L ratio sortedMax(2)g)grid ontitle(RN2L)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)

RN3L ratioMax(1)=RN3L MaxDegreeGRN3L ratioMax(2)=RN3L MaxDegreeG Hat

RN3L ratio sortedMax=sortrows(RN3L ratioMax)subplot(233)hold onplot(RN3L ratio sortedMax(1)b)plot(RN3L ratio sortedMax(2)g)grid ontitle(RN3L)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)

RN1S ratioMax(1)=RN1S MaxDegreeGRN1S ratioMax(2)=RN1S MaxDegreeG Hat

RN1S ratio sortedMax=sortrows(RN1S ratioMax)subplot(234)hold onplot(RN1S ratio sortedMax(1)b)plot(RN1S ratio sortedMax(2)g)grid ontitle(RN1S)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)

RN2S ratioMax(1)=RN2S MaxDegreeGRN2S ratioMax(2)=RN2S MaxDegreeG Hat

RN2S ratio sortedMax=sortrows(RN2S ratioMax)

subplot(235)hold onplot(RN2S ratio sortedMax(1)b)plot(RN2S ratio sortedMax(2)g)grid ontitle(RN2S)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)

RN3S ratioMax(1)=RN3S MaxDegreeGRN3S ratioMax(2)=RN3S MaxDegreeG Hat

64 Application

RN3S ratio sortedMax=sortrows(RN3S ratioMax)subplot(236)hold onplot(RN3S ratio sortedMax(1)b)plot(RN3S ratio sortedMax(2)g)grid ontitle(RN1L)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)set(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN7png minusr300)

tilefigs()(h)

Bibliography

[1] C Berge ldquoTWO THEOREMS IN GRAPH THEORYrdquo Proceedings of the NationalAcademy of Sciences of the United States of America vol 43 no 9 pp 842ndash844Sep 1957

[2] L Bui S Sanghavi and R Srikant ldquoDistributed link scheduling with constantoverheadrdquo IEEEACM Trans Netw vol 17 no 5 pp 1467ndash1480 2009

[3] R Duan and S Pettie ldquoLinear-time approximation for maximum weight matchingrdquoJ ACM vol 61 no 1 2014

[4] J Edmonds ldquoPaths trees and flowersrdquo Canadian Journal of Mathematics vol 17pp 449ndash467 1965

[5] J E Hopcroft and R M Karp ldquoAn n52 algorithm for maximum matchings inbipartite graphsrdquo SIAM J Comput vol 2 no 4 pp 225ndash231 1973

[6] S Micali and V V Vazirani ldquoAn O(radic|V ||E|) algorithm for finding maximum

matching in general graphsrdquo in 21st Symp on Foundations of Comp Sc (FOCS)IEEE 1980 pp 17ndash27

[7] N Nisse A Salch and V Weber ldquoRecovery of disrupted airline operationsrdquo 2015httphalinriafrSomething

[8] X Wu and R Srikant ldquoRegulated maximal matching A distributed schedulingalgorithm for multi-hop wireless networks with nodeexclusive spectrum sharingrdquo inIEEE Conf on Decision and Control 2005

65

  • Contents
  • Introduction
  • Algorithms
    • Maximum matching
    • k-maximum matching
      • k-matching for Airport Slot assignment
      • The case where k=3
      • The case of Paths
      • The case of the Spider
          • Application
            • Description
            • Reyni Erdos
            • Barabaacutesi Albert
            • Amadeus Graphs
            • Bipartite
            • Bipartite with degree seq
            • Appendix A
              • BipartiteGraphGeneratorpy
              • RandomGraphGeneratorpy
              • kequals3MaximumMatchingpy
              • Plotmat
                  • Bibliography
Page 31: Theodoros Alexandros KARAGKIOULES -  · Introduction This work is the result of a 6 months internship, under the supervision of research O cer Nicolas NISSE. The original scope of

32 Application

Sorted ∆

Sorted ∆-Comments

bull ∆ acquires the same min and max values for each probability case (expected)

bull Gap in the case of large initial matching

26 Bipartite with degree seq

Graph characteristics

bull DEQBIPxy are randomly generated graphs based on three different types of degreedistribution of the Amadeus graphs

26 Bipartite with degree seq 33

bull There are 6 categories based on ini matching and degree distribution

bull x = L S L When the initial matching is large and S when it is small

bull y = 1 2 3 1 when degree distribution is based on file 2 when degree distributionis based on file and 3 when degree distribution is based on file

Computation time over

34 Application

Computation time overedges-Comments

bull Greedy algorithm takes minimum amount of time

bull The smaller the initial matching the more smaller the difference in comoutationtime of Constraint and classical algorithm

bull Due to preprocessing and the fact that G and G are the almost identical thetotal time needed to apply the constraint algorithm is in some cases bigger

Sorted matching size

26 Bipartite with degree seq 35

Sorted matching size-Comments

bull Classical matching is equal to perfect matching in every case

bull Constraint and greedy have identical behaviour

bull The larger the spectrum of the degree sequence the more efficient the matching

Sorted Ratios

36 Application

Sorted Ratios-Comments

bull With large initial matching most of the edges are considenred uselles or forced andare removed thus the ratio is close(if not equal to) zero

bull For small matching and large degree sequence sectrum hte max degree remainsthe same Only a few forced edges (and their nodes) are removed apparently nonodes with max degree

Sorted |E||V |

26 Bipartite with degree seq 37

Sorted |E||V | - Comments

bull In these set of figures we witness that the |E||V | acquires values relevant to those ofthe amadeus graphs The random graphs were constructed to depict this similarity

bull For smaller initial matching the ratios for G and G show the same upward trendand also they acquire closer values It repsresent the decrease of the averagenumber of forced edges in comparison to the larger matching cases

Sorted ∆

38 Application

Sorted ∆-Comments

bull Big difference in max degree in large initial matching

bull Almost identical behaviour in the case of small initial matching

Appendix A 39

Appendix A

BipartiteGraphGeneratorpy

from future import divisionimport networkx as nx

from networkxalgorithms import approximationimport collectionsimport randomimport mathfrom networkxalgorithms import bipartiteif name == main

for i in range(1481)waqs 481index=1n=randomrandint(100 1000)

n1=95 was 500me1=118

n2=251 was 500me2=903

n3=165 was 500me3=412

m=0m1=0p=randomrandom()p1=18250p2=25250p3=34250print ip=05t1=randomrandint(0 1)print im2=randomrandint(n2minus1 n2+1)G = nxGraph()ma = nxGraph()

aseq1=[1 2 3 4 5 3]

bseq1=[4 3 3 1 2 2 1]

aseq2=[16 14 14 14 12 11]bseq2=[0 0 0 0 0 0]

aseq3=[8 7 8 8 8 8]bseq3=[0 0 0 0 0 0]

40 Application

print Gnumber of edges()if ilt=160

G=bipartiteconfiguration model(aseq1 bseq1 create using=None seed=None)A=nxadjacency matrix(G)for ii in range(0n1+me1)

maadd node(ii)A=[Rtodense()tolist()[0] for R in A]

printnummanumber of nodes()rl=randomsample(range(0n1+me1) n1+me1)m=0done vertices = set()for p in rlprintin fordone verticesadd(p)

neighbors = []list()for iii in range(0n1+me1)

if A[p][iii]==1neighborsappend(iii)

randomshuffle(neighbors)continue loop = Truedegree = len(neighbors)

print degreej = 0p4=randomrandom()while continue loop and (jltdegree)print in loop

next = neighbors[j]if next not in done vertices and p not in done vertices

done verticesadd(p)done verticesadd(next)if p4gt=07print added edge

maadd edge(pnext)m=m+1

continue loop = Falsej += 1

print matching listOfedgeprint maedge

MA=nxadjacency matrix(ma)print MA

MA=[Rtodense()tolist()[0] for R in MA]print MA

B=[ join(map(strR)) for R in A]MB=[ join(map(strR)) for R in MA]

C=njoin(B)+nMC=njoin(MB)+n

print nprint mprint m1

filea=str(i)+txtwith open(fileaw) as f

Appendix A 41

fwrite(str(n1+me1))fwrite(n)fwrite(str(n1+me1))fwrite(n)fwrite(str(m))fwrite(n)fwrite(n)fwrite(C)fwrite(n)fwrite(MC)

elif igt160 and ilt321G=bipartiteconfiguration model(aseq2 bseq2 create using=None seed=None)A=nxadjacency matrix(G)for ii in range(0n2+me2)

maadd node(ii)A=[Rtodense()tolist()[0] for R in A]

printnummanumber of nodes()rl=randomsample(range(0n2+me2) n2+me2)m=0done vertices = set()for p in rlprintin fordone verticesadd(p)

neighbors = []list()for iii in range(0n2+me2)

if A[p][iii]==1neighborsappend(iii)

randomshuffle(neighbors)continue loop = Truedegree = len(neighbors)

print degreej = 0p4=randomrandom()while continue loop and (jltdegree)

print in loopnext = neighbors[j]if next not in done vertices and p not in done vertices

done verticesadd(p)done verticesadd(next)if p4gt=07

print added edgemaadd edge(pnext)m=m+1

continue loop = Falsej += 1

print matching listOfedgeprint maedge

MA=nxadjacency matrix(ma)print MA

MA=[Rtodense()tolist()[0] for R in MA]print MA

B=[ join(map(strR)) for R in A]MB=[ join(map(strR)) for R in MA]

42 Application

C=njoin(B)+nMC=njoin(MB)+n

print nprint mprint m1

filea=str(i)+txtwith open(fileaw) as f

fwrite(str(n2+me2))fwrite(n)fwrite(str(n2+me2))fwrite(n)fwrite(str(m))fwrite(n)fwrite(n)fwrite(C)fwrite(n)fwrite(MC)

elseG=bipartiteconfiguration model(aseq3 bseq3 create using=None seed=None)A=nxadjacency matrix(G)for ii in range(0n3+me3)

maadd node(ii)A=[Rtodense()tolist()[0] for R in A]

printnummanumber of nodes()rl=randomsample(range(0n3+me3) n3+me3)m=0done vertices = set()for p in rlprintin fordone verticesadd(p)

neighbors = []list()for iii in range(0n3+me3)

if A[p][iii]==1neighborsappend(iii)

randomshuffle(neighbors)continue loop = Truedegree = len(neighbors)

print degreej = 0p4=randomrandom()while continue loop and (jltdegree)

print in loopnext = neighbors[j]if next not in done vertices and p not in done vertices

done verticesadd(p)done verticesadd(next)if p4gt=07print added edge

maadd edge(pnext)m=m+1

continue loop = Falsej += 1

Appendix A 43

print matching listOfedgeprint maedge

MA=nxadjacency matrix(ma)print MA

MA=[Rtodense()tolist()[0] for R in MA]print MA

B=[ join(map(strR)) for R in A]MB=[ join(map(strR)) for R in MA]

C=njoin(B)+nMC=njoin(MB)+n

print nprint mprint m1

filea=str(i)+txtwith open(fileaw) as f

fwrite(str(n3+me3))fwrite(n)fwrite(str(n3+me3))fwrite(n)fwrite(str(m))fwrite(n)fwrite(n)fwrite(C)fwrite(n)fwrite(MC)

print nRandom graphs with random matching have been generated

44 Application

RandomGraphGeneratorpy

from future import divisionimport networkx as nxfrom networkxalgorithms import approximationimport collectionsimport randomimport mathif name == main

for i in range(1481)index=1n=randomrandint(100 1000)

n=1000m=0m1=0p=randomrandom()p1=mathlog(n2)np2=13p3=mathlog(n2)n+01p=05t1=randomrandint(0 1)print im2=randomrandint(n2minus1 n2+1)G = nxGraph()ma = nxGraph()print nme1=randomrandint(1 10)me2=randomrandint(2050)me3=randomrandint(50100)if ilt241

if ilt=80G=nxfast gnp random graph(n p1 seed=None directed=False)

elif igt80 and ilt161G=nxfast gnp random graph(n p2 seed=None directed=False)

elseG=nxfast gnp random graph(n p3 seed=None directed=False)

elseif ilt=320

G=nxbarabasi albert graph(n me1 seed=None)elif igt320 and ilt401

G=nxbarabasi albert graph(n me2 seed=None)else

G=nxbarabasi albert graph(n me3 seed=None)A=nxadjacency matrix(G)for ii in range(0n)

maadd node(ii)A=[Rtodense()tolist()[0] for R in A]

rl=randomsample(range(0n) n)m=0

Appendix A 45

done vertices = set()for p in rl

done verticesadd(p)neighbors = []list()for iii in range(0n)

if A[p][iii]==1neighborsappend(iii)

randomshuffle(neighbors)continue loop = Truedegree = len(neighbors)j = 0p2=randomrandom()while continue loop and (jltdegree)

next = neighbors[j]if next not in done vertices and p not in done vertices

done verticesadd(p)done verticesadd(next)if p2gt=00 Larger probability for smaller initial matching

maadd edge(pnext)m=m+1

continue loop = Falsej += 1

print matching listOfedgeprint maedgeMA=nxadjacency matrix(ma)MA=[Rtodense()tolist()[0] for R in MA]print MAB=[ join(map(strR)) for R in A]MB=[ join(map(strR)) for R in MA]

C=njoin(B)+nMC=njoin(MB)+nprint MCprint nprint mprint m1filea=str(i)+txtwith open(fileaw) as f

fwrite(str(n))fwrite(n)fwrite(str(n))fwrite(n)fwrite(str(m))fwrite(n)fwrite(n)fwrite(C)fwrite(n)fwrite(MC)

print nRandom graphs with random matching have been generated

46 Application

kequals3MaximumMatchingpy

from future import divisionimport networkx as nxfrom networkxalgorithms import bipartiteimport matplotlibpyplot as pltimport collectionsimport timeitimport xlwtimport xlrdimport mathimport sys

Case for General Graphsdef forced edges(Gadj dict2matching dict1num nodesforced)

flagg=0for n in range(0num nodes)

for k in adj dict2[n]if ([k]==matching dict1[n])

count=0for l in range(0num nodes)

count=count+adj dict2[l]count(k)if (len(adj dict2[n])==1) or (count==1)

forcedadd edge(nk)Gremove edge(nk)Gremove node(n)Gremove node(k)printforced edgenktemp=kflagg=1for m in range (len(adj dict2[n])minus1minus1minus1)

adj dict2[adj dict2[n][m]]remove(n)adj dict2[n]remove(adj dict2[n][m])

if adj dict2[temp]for l in range(len(adj dict2[temp])minus1minus1minus1)

if (adj dict2[temp][l]=n)adj dict2[adj dict2[temp][l]]remove(temp)adj dict2[temp]remove(adj dict2[temp][l])

break

def useless edges(num nodesadj dict1matching dict1uselessadj dict2G)for n in range(0num nodes)

for k in adj dict1[n]if ([k]=matching dict1[n]) and matching dict1[n] and matching dict1[k]

uselessadd edge(nk)Gremove edge(n k)

Appendix A 47

tempa=kadj dict2[n]remove(k)adj dict2[tempa]remove(n)adj dict1[tempa]remove(n)

return G

def Greedy(num nodesadj dict3matching dict2)

for n in range(0num nodes)if matching dict2[n]

flag2=minus1flag3=minus1for v in adj dict3[n]

if not matching dict2[v]flag2=vbreak

for p in adj dict3[matching dict2[n][0]]if not matching dict2[p]

flag3=pbreak

if (flag2=minus1) and (flag3=minus1) and (flag2=flag3)tempr=matching dict2[n][0]matching dict2[n]=[flag2]matching dict2[flag2]=[n]matching dict2[tempr]=[flag3]matching dict2[flag3]=[tempr]

elsefor k in adj dict3[n]

if not matching dict2[k]matching dict2[n]=[k]matching dict2[k]=[n]break

yo1=0for i in range(0num nodes)

if matching dict2[i] and [i]==matching dict2[matching dict2[i][0]]yo1=yo1+1

greedy size=yo12return greedy size

def General()

INPUTSwb = xlwtWorkbook()ws = wbadd sheet(Results Random)book=xlrdopen workbook(filenames randomxls)

48 Application

style0 = xlwteasyxf(fontbold on)style1 = xlwteasyxf(num format str=0000)INPUTSwswrite(0 0File style0)wswrite(0 1 Nodesstyle0)wswrite(0 2 Initial matchingstyle0)wswrite(0 3 NodesGstyle0)wswrite(0 4 EdgesGstyle0)wswrite(0 5 MaxDegreeGstyle0)wswrite(0 6 NodesG hatstyle0)wswrite(0 7 EdgesG Hatstyle0)wswrite(0 8 Useless edgesstyle0)wswrite(0 9 Forced edgesstyle0)wswrite(0 10 MaxDegreeG Hatstyle0)wswrite(0 11 Classical matchingstyle0)wswrite(0 12 Final matchingstyle0)wswrite(0 13 Greedy matchingstyle0)wswrite(0 14 Time classicalstyle0)wswrite(0 15 Time algorithmstyle0)wswrite(0 16 Time greedystyle0)wswrite(0 17 Perfect matching ratiostyle0)wswrite(0 18 Nodes ratiostyle0)wswrite(0 19 Edges ratiostyle0)wswrite(0 20 Matching ratiostyle0)

print nWelcomeThis is an implementation for general random graphs It uses Edmonds algorithm to compute maximum matching on G Hatn

for index in range (1481)was 481

if (index==482)f=open(Algotel generaltxtr)readlines()

elsefilea=str(booksheet by index(0)cell(index0))s=fileareplace(textu)replace()f=open(sr)readlines()Truewswrite(index 0 s)

print index

num nodes=int([xstrip()split() for x in f][0][0])

num matching=int([xstrip()split() for x in f][2][0])

adj temp = [xstrip()split() for x in f][44+num nodes]adj=[map(intR) for R in adj temp]

matching temp=[xstrip()split() for x in f][4+num nodes+14+2num nodes+1]matching1=[map(intR) for R in matching temp]

adj dict1=i[ii for iix in enumerate(L) if x] for iL in enumerate(adj)adj dict2=i[ii for iix in enumerate(L) if x] for iL in enumerate(adj)

Appendix A 49

adj dict3=i[ii for iix in enumerate(L) if x] for iL in enumerate(adj)

matching dict1=i[ii for iix in enumerate(L) if x] for iL in enumerate(matching1)matching dict2=i[ii for iix in enumerate(L) if x] for iL in enumerate(matching1)print adj dict2print matching dict2wswrite(index 1 num nodes)wswrite(index 2 num matching)

G = nxGraph()

useless= nxGraph()forced = nxGraph()

Fill Graphfor n in range(0num nodes)

for k in adj dict1[n]Gadd edge(nk)

Gt=Gnumber of edges()wswrite(index 3 Gnumber of nodes())wswrite(index 4 Gnumber of edges())wswrite(index 5 max(Gdegree()values()))

Compute Edmonds classical matching on G for comparison

startB = timeitdefault timer()Classical Matching=nxmax weight matching(G maxcardinality=False)stopB = timeitdefault timer()

Compute Gˆ nad MˆstartC = timeitdefault timer()useless edges(num nodesadj dict1matching dict1uselessadj dict2G)forced edges(Gadj dict2matching dict1num nodesforced)Final Matching=nxmax weight matching(G maxcardinality=False)stopC = timeitdefault timer()

GreedystartG = timeitdefault timer()greedy size=Greedy(num nodesadj dict3matching dict2)stopG = timeitdefault timer()

wswrite(index 6 Gnumber of nodes())wswrite(index 7 Gnumber of edges())wswrite(index 8 uselessnumber of edges())wswrite(index 9 forcednumber of edges())if Gdegree()values()

wswrite(index 10 max(Gdegree()values()))else

50 Application

wswrite(index 10 0)wswrite(index 11 len(Classical Matching)2)wswrite(index 12 len(Final Matching)2+forcednumber of edges())wswrite(index 13 greedy size)wswrite(index 14 stopB minus startBstyle1)wswrite(index 15 stopC minus startCstyle1)wswrite(index 16 stopG minus startGstyle1)wswrite(index 17 (len(Final Matching)2+forcednumber of edges())(num nodes2)style1)wswrite(index 18 Gnumber of nodes()Gtstyle1)wswrite(index 19 Gnumber of edges()Gtstyle1)wswrite(index 20 (len(Final Matching)2+forcednumber of edges())(len(Classical Matching)2)style1)

wbsave(AA Results Random Reyni Large Bipartitexls)

Main function Here we must choose the input form of the dataif name == main

startA = timeitdefault timer()General()stopA = timeitdefault timer()

print nThis program has terminatednnRunning time for 480 files stopAminusstartAprint nnPlease open AA Results Random Reyni Largexls file to see the Results

Appendix A 51

Plotmat

clear allclose allload(RN1Lmat)load(RN1Smat)load(RN2Lmat)load(RN2Smat)load(RN3Lmat)load(RN3Smat)

Plotsh(1)=figure(NameHistogram of Matching size difference between Constraint Algorithm and Greedy AlgorithmNumberTitleoff)

RN1L Greedydiff=RN1L Final matchingminusRN1L Greedy matchingRN2L Greedydiff=RN2L Final matchingminusRN2L Greedy matchingRN3L Greedydiff=RN3L Final matchingminusRN3L Greedy matchingRN1S Greedydiff=RN1S Final matchingminusRN1S Greedy matchingRN2S Greedydiff=RN2S Final matchingminusRN2S Greedy matchingRN3S Greedydiff=RN3S Final matchingminusRN3S Greedy matching

RN1L Finaldiff=RN1L Classical matchingminusRN1L Final matchingRN2L Finaldiff=RN2L Classical matchingminusRN2L Final matchingRN3L Finaldiff=RN3L Classical matchingminusRN3L Final matchingRN1S Finaldiff=RN1S Classical matchingminusRN1S Final matchingRN2S Finaldiff=RN2S Classical matchingminusRN2S Final matchingRN3S Finaldiff=RN3S Classical matchingminusRN3S Final matching

RN1L Classicaldiff=(RN1L Nodes2)minusRN1L Classical matchingRN2L Classicaldiff=(RN2L Nodes2)minusRN2L Classical matchingRN3L Classicaldiff=(RN3L Nodes2)minusRN3L Classical matchingRN1S Classicaldiff=(RN1S Nodes2)minusRN1S Classical matchingRN2S Classicaldiff=(RN2S Nodes2)minusRN2S Classical matchingRN3S Classicaldiff=(RN3S Nodes2)minusRN3S Classical matching

subplot(231)hold onhistf(RN1L Greedydiff0110facecolorbfacealpha9edgealpha1)histf(RN1L Finaldiff0110facecolorrfacealpha5edgealpha1)histf(RN1L Classicaldiff0110facecolorgfacealpha5edgealpha1)legalpha(ConminusGreClasminusConPerfminusClasslocationnortheast)legend boxoffaxis tightxlabel(edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN1L)grid on

subplot(232)hold onhistf(RN2L Greedydiff0110facecolorbfacealpha9edgealpha1)

52 Application

histf(RN2L Finaldiff0110facecolorrfacealpha5edgealpha1)histf(RN2L Classicaldiff0110facecolorgfacealpha5edgealpha1)legalpha(ConminusGreClasminusConPerfminusClasslocationnortheast)legend boxoffaxis tightxlabel(edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN2L)grid on

subplot(233)hold onhistf(RN3L Greedydiff0110facecolorbfacealpha5edgealpha1)histf(RN3L Finaldiff0110facecolorrfacealpha5edgealpha1)histf(RN3L Classicaldiff0110facecolorgfacealpha5edgealpha1)legalpha(ConminusGreClasminusConPerfminusClasslocationnortheast)legend boxoffaxis tightxlabel(edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN3L)grid on

subplot(234)hold onhistf(RN1S Greedydiff0110facecolorbfacealpha5edgealpha1)histf(RN1S Finaldiff0110facecolorrfacealpha5edgealpha1)histf(RN1S Classicaldiff0110facecolorgfacealpha5edgealpha1)legalpha(ConminusGreClasminusConPerfminusClasslocationnortheast)legend boxoffaxis tightxlabel(edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(R1NS)grid on

subplot(235)hold onhistf(RN2S Greedydiff0110facecolorbfacealpha5edgealpha1)histf(RN2S Finaldiff0110facecolorrfacealpha5edgealpha1)histf(RN2S Classicaldiff0110facecolorgfacealpha5edgealpha1)legalpha(ConminusGreClasminusConPerfminusClasslocationnortheast)legend boxoffaxis tightxlabel(edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN2S)grid on

subplot(236)hold onhistf(RN3S Greedydiff0110facecolorbfacealpha5edgealpha1)histf(RN3S Finaldiff0110facecolorrfacealpha5edgealpha1)histf(RN3S Classicaldiff0110facecolorgfacealpha5edgealpha1)

Appendix A 53

legalpha(ConminusGreClasminusConPerfminusClasslocationnortheast)legend boxoffaxis tightgrid ontitle(RN3S)xlabel(edges) xminusaxis labelylabel(instances) yminusaxis labelset(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN1png minusr300)h(2)=figure(NameHistogram of Max Degree of G AND G HatNumberTitleoff)RN1L x=RN1L MaxDegreeGminusRN1L MaxDegreeG HatRN2L x=RN2L MaxDegreeGminusRN2L MaxDegreeG HatRN3L x=RN3L MaxDegreeGminusRN3L MaxDegreeG HatRN1S x=RN1S MaxDegreeGminusRN1S MaxDegreeG HatRN2S x=RN2S MaxDegreeGminusRN2S MaxDegreeG HatRN3S x=RN3S MaxDegreeGminusRN3S MaxDegreeG Hatsubplot(231)hold onhistf(RN1L MaxDegreeG0150facecolorbfacealpha5edgealpha1)histf(RN1L MaxDegreeG Hat0150facecolorrfacealpha5edgealpha1)histf(RN1L x0150facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightxlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN1L)grid on

subplot(232)hold onhistf(RN2L MaxDegreeG010500facecolorbfacealpha5edgealpha1)histf(RN2L MaxDegreeG Hat010500facecolorrfacealpha5edgealpha1)histf(RN2L x010500facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightxlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN2L)grid on

subplot(233)hold onhistf(RN3L MaxDegreeG010300facecolorbfacealpha5edgealpha1)histf(RN3L MaxDegreeG Hat010300facecolorrfacealpha5edgealpha1)histf(RN3L x010300facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightxlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN3L)

54 Application

grid on

subplot(234)hold onhistf(RN1S MaxDegreeG0150facecolorbfacealpha5edgealpha1)histf(RN1S MaxDegreeG Hat0150facecolorrfacealpha5edgealpha1)histf(RN1S x0150facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightxlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(R1NS)grid on

subplot(235)hold onhistf(RN2S MaxDegreeG010500facecolorbfacealpha5edgealpha1)histf(RN2S MaxDegreeG Hat010500facecolorrfacealpha5edgealpha1)histf(RN2S x010500facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightxlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN2S)grid on

subplot(236)hold onhistf(RN3S MaxDegreeG05300facecolorbfacealpha5edgealpha1)histf(RN3S MaxDegreeG Hat05300facecolorrfacealpha5edgealpha1)histf(RN3S x05300facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightgrid ontitle(RN3S)xlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labelset(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN2png minusr300)

h(3)=figure(NameComputation time over edgesNumberTitleoff)

subplot(231)hold onstem(RN1L EdgesGRN1L Time classicalg)stem(RN1L EdgesGRN1L Time algorithmro)stem(RN1L EdgesGRN1L Time greedybx)grid on

Appendix A 55

title(RN1L)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)

subplot(232)hold onstem(RN2L EdgesGRN2L Time classicalg)stem(RN2L EdgesGRN2L Time algorithmro)stem(RN2L EdgesGRN2L Time greedybx)grid ontitle(RN2L)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)

subplot(233)hold onstem(RN3L EdgesGRN3L Time classicalg)stem(RN3L EdgesGRN3L Time algorithmro)stem(RN3L EdgesGRN3L Time greedybx)grid ontitle(RN3L)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)

subplot(234)hold onstem(RN1S EdgesGRN1S Time classicalg)stem(RN1S EdgesGRN1S Time algorithmro)stem(RN1S EdgesGRN1S Time greedybx)grid ontitle(RN1S)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)

subplot(235)hold onstem(RN2S EdgesGRN2S Time classicalg)stem(RN2S EdgesGRN2S Time algorithmro)stem(RN2S EdgesGRN2S Time greedybx)grid ontitle(RN2S)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)

subplot(236)hold onstem(RN3S EdgesGRN3S Time classicalg)stem(RN3S EdgesGRN3S Time algorithmro)stem(RN3S EdgesGRN3S Time greedybx)

56 Application

grid ontitle(RN3S)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)set(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN3png minusr300)

h(4)=figure(NameSorted matching sizeNumberTitleoff)RN1L Sorted matching temp(1)=RN1L Classical matchingRN1L Sorted matching temp(2)=RN1L Final matchingRN1L Sorted matching temp(3)=RN1L Greedy matchingRN1L Sorted matching temp(4)=RN1L Initial matchingRN1L Sorted matching=sortrows(RN1L Sorted matching temp)

RN2L Sorted matching temp(1)=RN2L Classical matchingRN2L Sorted matching temp(2)=RN2L Final matchingRN2L Sorted matching temp(3)=RN2L Greedy matchingRN2L Sorted matching temp(4)=RN2L Initial matchingRN2L Sorted matching=sortrows(RN2L Sorted matching temp)

RN3L Sorted matching temp(1)=RN3L Classical matchingRN3L Sorted matching temp(2)=RN3L Final matchingRN3L Sorted matching temp(3)=RN3L Greedy matchingRN3L Sorted matching temp(4)=RN3L Initial matchingRN3L Sorted matching=sortrows(RN3L Sorted matching temp)

RN1S Sorted matching temp(1)=RN1S Classical matchingRN1S Sorted matching temp(2)=RN1S Final matchingRN1S Sorted matching temp(3)=RN1S Greedy matchingRN1S Sorted matching temp(4)=RN1S Initial matchingRN1S Sorted matching=sortrows(RN1S Sorted matching temp)

RN2S Sorted matching temp(1)=RN2S Classical matchingRN2S Sorted matching temp(2)=RN2S Final matchingRN2S Sorted matching temp(3)=RN2S Greedy matchingRN2S Sorted matching temp(4)=RN2S Initial matchingRN2S Sorted matching=sortrows(RN2S Sorted matching temp)

RN3S Sorted matching temp(1)=RN3S Classical matchingRN3S Sorted matching temp(2)=RN3S Final matchingRN3S Sorted matching temp(3)=RN3S Greedy matchingRN3S Sorted matching temp(4)=RN3S Initial matchingRN3S Sorted matching=sortrows(RN3S Sorted matching temp)

subplot(231)hold onplot(RN1L Sorted matching(1)b)plot(RN1L Sorted matching(2)g)plot(RN1L Sorted matching(3)r)plot(RN1L Sorted matching(4)m)

Appendix A 57

grid ontitle(RN1L)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)

subplot(232)hold onplot(RN2L Sorted matching(1)b)plot(RN2L Sorted matching(2)g)plot(RN2L Sorted matching(3)r)plot(RN2L Sorted matching(4)m)grid ontitle(RN2L)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)

subplot(233)hold onplot(RN3L Sorted matching(1)b)plot(RN3L Sorted matching(2)g)plot(RN3L Sorted matching(3)r)plot(RN3L Sorted matching(4)m)grid ontitle(RN3L)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)

subplot(234)hold onplot(RN1S Sorted matching(1)b)plot(RN1S Sorted matching(2)g)plot(RN1S Sorted matching(3)r)plot(RN1S Sorted matching(4)m)grid ontitle(RN1S)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)

subplot(235)hold onplot(RN2S Sorted matching(1)b)plot(RN2S Sorted matching(2)g)plot(RN2S Sorted matching(3)r)plot(RN2S Sorted matching(4)m)grid ontitle(RN2S)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)

58 Application

subplot(236)hold onplot(RN3S Sorted matching(1)b)plot(RN3S Sorted matching(2)g)plot(RN3S Sorted matching(3)r)plot(RN3S Sorted matching(4)m)grid ontitle(RN3S)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)set(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN4png minusr300)h(5)=figure(NameSorted RatiosNumberTitleoff)RN1L ratio1=RN1L NodesG hatRN1L NodesGRN2L ratio1=RN2L NodesG hatRN2L NodesGRN3L ratio1=RN3L NodesG hatRN3L NodesGRN1S ratio1=RN1S NodesG hatRN1S NodesGRN2S ratio1=RN2S NodesG hatRN2S NodesGRN3S ratio1=RN3S NodesG hatRN3S NodesG

RN1L ratio2=RN1L EdgesG HatRN1L EdgesGRN2L ratio2=RN2L EdgesG HatRN2L EdgesGRN3L ratio2=RN3L EdgesG HatRN3L EdgesGRN1S ratio2=RN1S EdgesG HatRN1S EdgesGRN2S ratio2=RN2S EdgesG HatRN2S EdgesGRN3S ratio2=RN3S EdgesG HatRN3S EdgesG

RN1L ratio3=RN1L MaxDegreeG HatRN1L MaxDegreeGRN2L ratio3=RN2L MaxDegreeG HatRN2L MaxDegreeGRN3L ratio3=RN3L MaxDegreeG HatRN3L MaxDegreeGRN1S ratio3=RN1S MaxDegreeG HatRN1S MaxDegreeGRN2S ratio3=RN2S MaxDegreeG HatRN2S MaxDegreeGRN3S ratio3=RN3S MaxDegreeG HatRN3S MaxDegreeG

RN1L ratio(1)=RN1L ratio1RN1L ratio(2)=RN1L ratio2RN1L ratio(3)=RN1L ratio3

RN2L ratio(1)=RN2L ratio1RN2L ratio(2)=RN2L ratio2RN2L ratio(3)=RN2L ratio3

RN3L ratio(1)=RN3L ratio1RN3L ratio(2)=RN3L ratio2RN3L ratio(3)=RN3L ratio3

RN1S ratio(1)=RN1S ratio1RN1S ratio(2)=RN1S ratio2RN1S ratio(3)=RN1S ratio3

RN2S ratio(1)=RN2S ratio1

Appendix A 59

RN2S ratio(2)=RN2S ratio2RN2S ratio(3)=RN2S ratio3

RN3S ratio(1)=RN3S ratio1RN3S ratio(2)=RN3S ratio2RN3S ratio(3)=RN3S ratio3

RN1L ratio sorted=sortrows(RN1L ratio)RN2L ratio sorted=sortrows(RN2L ratio)RN3L ratio sorted=sortrows(RN3L ratio)RN1S ratio sorted=sortrows(RN1S ratio)RN2S ratio sorted=sortrows(RN2S ratio)RN3S ratio sorted=sortrows(RN3S ratio)

subplot(231)hold onplot(RN1L ratio sorted(1)b)plot(RN1L ratio sorted(2)g)plot(RN1L ratio sorted(3)r)grid ontitle(RN1L)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)

subplot(232)hold onplot(RN2L ratio sorted(1)b)plot(RN2L ratio sorted(2)g)plot(RN2L ratio sorted(3)r)grid ontitle(RN2L)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)

subplot(233)hold onplot(RN3L ratio sorted(1)b)plot(RN3L ratio sorted(2)g)plot(RN3L ratio sorted(3)r)grid ontitle(RN3L)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)

subplot(234)hold onplot(RN1S ratio sorted(1)b)plot(RN1S ratio sorted(2)g)plot(RN1S ratio sorted(3)r)grid on

60 Application

title(RN1S)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)

subplot(235)hold onplot(RN2S ratio sorted(1)b)plot(RN2S ratio sorted(2)g)plot(RN2S ratio sorted(3)r)grid ontitle(RN2S)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)

subplot(236)hold onplot(RN3S ratio sorted(1)b)plot(RN3S ratio sorted(2)g)plot(RN3S ratio sorted(3)r)grid ontitle(RN3S)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)set(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN5png minusr300)

h(6)=figure(NameSorted edges over nodesNumberTitleoff)

RN1L DegreeG1=(RN1L EdgesG)(RN1L NodesG)RN1L DegreeG Hat1=(RN1L EdgesG Hat)(RN1L NodesG hat)

RN1L Degree temp1(1)=RN1L DegreeG1RN1L Degree temp1(2)=RN1L DegreeG Hat1RN1L Degree sorted1=sortrows(RN1L Degree temp1)subplot(231)hold on

plot(RN1L Degree sorted1(1)b)plot(RN1L Degree sorted1(2)g)grid ontitle(RN1L)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)

RN2L DegreeG1=(RN2L EdgesG)(RN2L NodesG)RN2L DegreeG Hat1=(RN2L EdgesG Hat)(RN2L NodesG hat)

RN2L Degree temp1(1)=RN2L DegreeG1

Appendix A 61

RN2L Degree temp1(2)=RN2L DegreeG Hat1RN2L Degree sorted1=sortrows(RN2L Degree temp1)

subplot(232)hold onplot(RN2L Degree sorted1(1)b)plot(RN2L Degree sorted1(2)g)grid ontitle(RN2L)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)

RN3L DegreeG1=(RN3L EdgesG)(RN3L NodesG)RN3L DegreeG Hat1=(RN3L EdgesG Hat)(RN3L NodesG hat)

RN3L Degree temp1(1)=RN3L DegreeG1RN3L Degree temp1(2)=RN3L DegreeG Hat1RN3L Degree sorted1=sortrows(RN3L Degree temp1)

subplot(233)hold onplot(RN3L Degree sorted1(1)b)plot(RN3L Degree sorted1(2)g)grid ontitle(RN3L)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)

RN1S DegreeG1=(RN1S EdgesG)(RN1S NodesG)RN1S DegreeG Hat1=(RN1S EdgesG Hat)(RN1S NodesG hat)

RN1S Degree temp1(1)=RN1S DegreeG1RN1S Degree temp1(2)=RN1S DegreeG Hat1RN1S Degree sorted1=sortrows(RN1S Degree temp1)

subplot(234)hold onplot(RN1S Degree sorted1(1)b)plot(RN1S Degree sorted1(2)g)grid ontitle(RN1S)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)

RN2S DegreeG1=(RN2S EdgesG)(RN2S NodesG)RN2S DegreeG Hat1=(RN2S EdgesG Hat)(RN2S NodesG hat)

RN2S Degree temp1(1)=RN2S DegreeG1

62 Application

RN2S Degree temp1(2)=RN2S DegreeG Hat1RN2S Degree sorted1=sortrows(RN2S Degree temp1)

subplot(235)hold onplot(RN2S Degree sorted1(1)b)plot(RN2S Degree sorted1(2)g)grid ontitle(RN2S)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)

RN3S DegreeG1=(RN3S EdgesG)(RN3S NodesG)RN3S DegreeG Hat1=(RN3S EdgesG Hat)(RN3S NodesG hat)

RN3S Degree temp1(1)=RN3S DegreeG1RN3S Degree temp1(2)=RN3S DegreeG Hat1RN3S Degree sorted1=sortrows(RN3S Degree temp1)

subplot(236)hold onplot(RN3S Degree sorted1(1)b)plot(RN3S Degree sorted1(2)g)grid ontitle(RN3S)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)set(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN6png minusr300)h(7)=figure(NameSorted mATCHED DEGREENumberTitleoff)RN1L ratioMax(1)=RN1L MaxDegreeGRN1L ratioMax(2)=RN1L MaxDegreeG Hat

RN1L ratio sortedMax=sortrows(RN1L ratioMax)subplot(231)hold onplot(RN1L ratio sortedMax(1)b)plot(RN1L ratio sortedMax(2)g)grid ontitle(RN1L)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)

RN2L ratioMax(1)=RN2L MaxDegreeGRN2L ratioMax(2)=RN2L MaxDegreeG Hat

RN2L ratio sortedMax=sortrows(RN2L ratioMax)subplot(232)

Appendix A 63

hold onplot(RN2L ratio sortedMax(1)b)plot(RN2L ratio sortedMax(2)g)grid ontitle(RN2L)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)

RN3L ratioMax(1)=RN3L MaxDegreeGRN3L ratioMax(2)=RN3L MaxDegreeG Hat

RN3L ratio sortedMax=sortrows(RN3L ratioMax)subplot(233)hold onplot(RN3L ratio sortedMax(1)b)plot(RN3L ratio sortedMax(2)g)grid ontitle(RN3L)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)

RN1S ratioMax(1)=RN1S MaxDegreeGRN1S ratioMax(2)=RN1S MaxDegreeG Hat

RN1S ratio sortedMax=sortrows(RN1S ratioMax)subplot(234)hold onplot(RN1S ratio sortedMax(1)b)plot(RN1S ratio sortedMax(2)g)grid ontitle(RN1S)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)

RN2S ratioMax(1)=RN2S MaxDegreeGRN2S ratioMax(2)=RN2S MaxDegreeG Hat

RN2S ratio sortedMax=sortrows(RN2S ratioMax)

subplot(235)hold onplot(RN2S ratio sortedMax(1)b)plot(RN2S ratio sortedMax(2)g)grid ontitle(RN2S)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)

RN3S ratioMax(1)=RN3S MaxDegreeGRN3S ratioMax(2)=RN3S MaxDegreeG Hat

64 Application

RN3S ratio sortedMax=sortrows(RN3S ratioMax)subplot(236)hold onplot(RN3S ratio sortedMax(1)b)plot(RN3S ratio sortedMax(2)g)grid ontitle(RN1L)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)set(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN7png minusr300)

tilefigs()(h)

Bibliography

[1] C Berge ldquoTWO THEOREMS IN GRAPH THEORYrdquo Proceedings of the NationalAcademy of Sciences of the United States of America vol 43 no 9 pp 842ndash844Sep 1957

[2] L Bui S Sanghavi and R Srikant ldquoDistributed link scheduling with constantoverheadrdquo IEEEACM Trans Netw vol 17 no 5 pp 1467ndash1480 2009

[3] R Duan and S Pettie ldquoLinear-time approximation for maximum weight matchingrdquoJ ACM vol 61 no 1 2014

[4] J Edmonds ldquoPaths trees and flowersrdquo Canadian Journal of Mathematics vol 17pp 449ndash467 1965

[5] J E Hopcroft and R M Karp ldquoAn n52 algorithm for maximum matchings inbipartite graphsrdquo SIAM J Comput vol 2 no 4 pp 225ndash231 1973

[6] S Micali and V V Vazirani ldquoAn O(radic|V ||E|) algorithm for finding maximum

matching in general graphsrdquo in 21st Symp on Foundations of Comp Sc (FOCS)IEEE 1980 pp 17ndash27

[7] N Nisse A Salch and V Weber ldquoRecovery of disrupted airline operationsrdquo 2015httphalinriafrSomething

[8] X Wu and R Srikant ldquoRegulated maximal matching A distributed schedulingalgorithm for multi-hop wireless networks with nodeexclusive spectrum sharingrdquo inIEEE Conf on Decision and Control 2005

65

  • Contents
  • Introduction
  • Algorithms
    • Maximum matching
    • k-maximum matching
      • k-matching for Airport Slot assignment
      • The case where k=3
      • The case of Paths
      • The case of the Spider
          • Application
            • Description
            • Reyni Erdos
            • Barabaacutesi Albert
            • Amadeus Graphs
            • Bipartite
            • Bipartite with degree seq
            • Appendix A
              • BipartiteGraphGeneratorpy
              • RandomGraphGeneratorpy
              • kequals3MaximumMatchingpy
              • Plotmat
                  • Bibliography
Page 32: Theodoros Alexandros KARAGKIOULES -  · Introduction This work is the result of a 6 months internship, under the supervision of research O cer Nicolas NISSE. The original scope of

26 Bipartite with degree seq 33

bull There are 6 categories based on ini matching and degree distribution

bull x = L S L When the initial matching is large and S when it is small

bull y = 1 2 3 1 when degree distribution is based on file 2 when degree distributionis based on file and 3 when degree distribution is based on file

Computation time over

34 Application

Computation time overedges-Comments

bull Greedy algorithm takes minimum amount of time

bull The smaller the initial matching the more smaller the difference in comoutationtime of Constraint and classical algorithm

bull Due to preprocessing and the fact that G and G are the almost identical thetotal time needed to apply the constraint algorithm is in some cases bigger

Sorted matching size

26 Bipartite with degree seq 35

Sorted matching size-Comments

bull Classical matching is equal to perfect matching in every case

bull Constraint and greedy have identical behaviour

bull The larger the spectrum of the degree sequence the more efficient the matching

Sorted Ratios

36 Application

Sorted Ratios-Comments

bull With large initial matching most of the edges are considenred uselles or forced andare removed thus the ratio is close(if not equal to) zero

bull For small matching and large degree sequence sectrum hte max degree remainsthe same Only a few forced edges (and their nodes) are removed apparently nonodes with max degree

Sorted |E||V |

26 Bipartite with degree seq 37

Sorted |E||V | - Comments

bull In these set of figures we witness that the |E||V | acquires values relevant to those ofthe amadeus graphs The random graphs were constructed to depict this similarity

bull For smaller initial matching the ratios for G and G show the same upward trendand also they acquire closer values It repsresent the decrease of the averagenumber of forced edges in comparison to the larger matching cases

Sorted ∆

38 Application

Sorted ∆-Comments

bull Big difference in max degree in large initial matching

bull Almost identical behaviour in the case of small initial matching

Appendix A 39

Appendix A

BipartiteGraphGeneratorpy

from future import divisionimport networkx as nx

from networkxalgorithms import approximationimport collectionsimport randomimport mathfrom networkxalgorithms import bipartiteif name == main

for i in range(1481)waqs 481index=1n=randomrandint(100 1000)

n1=95 was 500me1=118

n2=251 was 500me2=903

n3=165 was 500me3=412

m=0m1=0p=randomrandom()p1=18250p2=25250p3=34250print ip=05t1=randomrandint(0 1)print im2=randomrandint(n2minus1 n2+1)G = nxGraph()ma = nxGraph()

aseq1=[1 2 3 4 5 3]

bseq1=[4 3 3 1 2 2 1]

aseq2=[16 14 14 14 12 11]bseq2=[0 0 0 0 0 0]

aseq3=[8 7 8 8 8 8]bseq3=[0 0 0 0 0 0]

40 Application

print Gnumber of edges()if ilt=160

G=bipartiteconfiguration model(aseq1 bseq1 create using=None seed=None)A=nxadjacency matrix(G)for ii in range(0n1+me1)

maadd node(ii)A=[Rtodense()tolist()[0] for R in A]

printnummanumber of nodes()rl=randomsample(range(0n1+me1) n1+me1)m=0done vertices = set()for p in rlprintin fordone verticesadd(p)

neighbors = []list()for iii in range(0n1+me1)

if A[p][iii]==1neighborsappend(iii)

randomshuffle(neighbors)continue loop = Truedegree = len(neighbors)

print degreej = 0p4=randomrandom()while continue loop and (jltdegree)print in loop

next = neighbors[j]if next not in done vertices and p not in done vertices

done verticesadd(p)done verticesadd(next)if p4gt=07print added edge

maadd edge(pnext)m=m+1

continue loop = Falsej += 1

print matching listOfedgeprint maedge

MA=nxadjacency matrix(ma)print MA

MA=[Rtodense()tolist()[0] for R in MA]print MA

B=[ join(map(strR)) for R in A]MB=[ join(map(strR)) for R in MA]

C=njoin(B)+nMC=njoin(MB)+n

print nprint mprint m1

filea=str(i)+txtwith open(fileaw) as f

Appendix A 41

fwrite(str(n1+me1))fwrite(n)fwrite(str(n1+me1))fwrite(n)fwrite(str(m))fwrite(n)fwrite(n)fwrite(C)fwrite(n)fwrite(MC)

elif igt160 and ilt321G=bipartiteconfiguration model(aseq2 bseq2 create using=None seed=None)A=nxadjacency matrix(G)for ii in range(0n2+me2)

maadd node(ii)A=[Rtodense()tolist()[0] for R in A]

printnummanumber of nodes()rl=randomsample(range(0n2+me2) n2+me2)m=0done vertices = set()for p in rlprintin fordone verticesadd(p)

neighbors = []list()for iii in range(0n2+me2)

if A[p][iii]==1neighborsappend(iii)

randomshuffle(neighbors)continue loop = Truedegree = len(neighbors)

print degreej = 0p4=randomrandom()while continue loop and (jltdegree)

print in loopnext = neighbors[j]if next not in done vertices and p not in done vertices

done verticesadd(p)done verticesadd(next)if p4gt=07

print added edgemaadd edge(pnext)m=m+1

continue loop = Falsej += 1

print matching listOfedgeprint maedge

MA=nxadjacency matrix(ma)print MA

MA=[Rtodense()tolist()[0] for R in MA]print MA

B=[ join(map(strR)) for R in A]MB=[ join(map(strR)) for R in MA]

42 Application

C=njoin(B)+nMC=njoin(MB)+n

print nprint mprint m1

filea=str(i)+txtwith open(fileaw) as f

fwrite(str(n2+me2))fwrite(n)fwrite(str(n2+me2))fwrite(n)fwrite(str(m))fwrite(n)fwrite(n)fwrite(C)fwrite(n)fwrite(MC)

elseG=bipartiteconfiguration model(aseq3 bseq3 create using=None seed=None)A=nxadjacency matrix(G)for ii in range(0n3+me3)

maadd node(ii)A=[Rtodense()tolist()[0] for R in A]

printnummanumber of nodes()rl=randomsample(range(0n3+me3) n3+me3)m=0done vertices = set()for p in rlprintin fordone verticesadd(p)

neighbors = []list()for iii in range(0n3+me3)

if A[p][iii]==1neighborsappend(iii)

randomshuffle(neighbors)continue loop = Truedegree = len(neighbors)

print degreej = 0p4=randomrandom()while continue loop and (jltdegree)

print in loopnext = neighbors[j]if next not in done vertices and p not in done vertices

done verticesadd(p)done verticesadd(next)if p4gt=07print added edge

maadd edge(pnext)m=m+1

continue loop = Falsej += 1

Appendix A 43

print matching listOfedgeprint maedge

MA=nxadjacency matrix(ma)print MA

MA=[Rtodense()tolist()[0] for R in MA]print MA

B=[ join(map(strR)) for R in A]MB=[ join(map(strR)) for R in MA]

C=njoin(B)+nMC=njoin(MB)+n

print nprint mprint m1

filea=str(i)+txtwith open(fileaw) as f

fwrite(str(n3+me3))fwrite(n)fwrite(str(n3+me3))fwrite(n)fwrite(str(m))fwrite(n)fwrite(n)fwrite(C)fwrite(n)fwrite(MC)

print nRandom graphs with random matching have been generated

44 Application

RandomGraphGeneratorpy

from future import divisionimport networkx as nxfrom networkxalgorithms import approximationimport collectionsimport randomimport mathif name == main

for i in range(1481)index=1n=randomrandint(100 1000)

n=1000m=0m1=0p=randomrandom()p1=mathlog(n2)np2=13p3=mathlog(n2)n+01p=05t1=randomrandint(0 1)print im2=randomrandint(n2minus1 n2+1)G = nxGraph()ma = nxGraph()print nme1=randomrandint(1 10)me2=randomrandint(2050)me3=randomrandint(50100)if ilt241

if ilt=80G=nxfast gnp random graph(n p1 seed=None directed=False)

elif igt80 and ilt161G=nxfast gnp random graph(n p2 seed=None directed=False)

elseG=nxfast gnp random graph(n p3 seed=None directed=False)

elseif ilt=320

G=nxbarabasi albert graph(n me1 seed=None)elif igt320 and ilt401

G=nxbarabasi albert graph(n me2 seed=None)else

G=nxbarabasi albert graph(n me3 seed=None)A=nxadjacency matrix(G)for ii in range(0n)

maadd node(ii)A=[Rtodense()tolist()[0] for R in A]

rl=randomsample(range(0n) n)m=0

Appendix A 45

done vertices = set()for p in rl

done verticesadd(p)neighbors = []list()for iii in range(0n)

if A[p][iii]==1neighborsappend(iii)

randomshuffle(neighbors)continue loop = Truedegree = len(neighbors)j = 0p2=randomrandom()while continue loop and (jltdegree)

next = neighbors[j]if next not in done vertices and p not in done vertices

done verticesadd(p)done verticesadd(next)if p2gt=00 Larger probability for smaller initial matching

maadd edge(pnext)m=m+1

continue loop = Falsej += 1

print matching listOfedgeprint maedgeMA=nxadjacency matrix(ma)MA=[Rtodense()tolist()[0] for R in MA]print MAB=[ join(map(strR)) for R in A]MB=[ join(map(strR)) for R in MA]

C=njoin(B)+nMC=njoin(MB)+nprint MCprint nprint mprint m1filea=str(i)+txtwith open(fileaw) as f

fwrite(str(n))fwrite(n)fwrite(str(n))fwrite(n)fwrite(str(m))fwrite(n)fwrite(n)fwrite(C)fwrite(n)fwrite(MC)

print nRandom graphs with random matching have been generated

46 Application

kequals3MaximumMatchingpy

from future import divisionimport networkx as nxfrom networkxalgorithms import bipartiteimport matplotlibpyplot as pltimport collectionsimport timeitimport xlwtimport xlrdimport mathimport sys

Case for General Graphsdef forced edges(Gadj dict2matching dict1num nodesforced)

flagg=0for n in range(0num nodes)

for k in adj dict2[n]if ([k]==matching dict1[n])

count=0for l in range(0num nodes)

count=count+adj dict2[l]count(k)if (len(adj dict2[n])==1) or (count==1)

forcedadd edge(nk)Gremove edge(nk)Gremove node(n)Gremove node(k)printforced edgenktemp=kflagg=1for m in range (len(adj dict2[n])minus1minus1minus1)

adj dict2[adj dict2[n][m]]remove(n)adj dict2[n]remove(adj dict2[n][m])

if adj dict2[temp]for l in range(len(adj dict2[temp])minus1minus1minus1)

if (adj dict2[temp][l]=n)adj dict2[adj dict2[temp][l]]remove(temp)adj dict2[temp]remove(adj dict2[temp][l])

break

def useless edges(num nodesadj dict1matching dict1uselessadj dict2G)for n in range(0num nodes)

for k in adj dict1[n]if ([k]=matching dict1[n]) and matching dict1[n] and matching dict1[k]

uselessadd edge(nk)Gremove edge(n k)

Appendix A 47

tempa=kadj dict2[n]remove(k)adj dict2[tempa]remove(n)adj dict1[tempa]remove(n)

return G

def Greedy(num nodesadj dict3matching dict2)

for n in range(0num nodes)if matching dict2[n]

flag2=minus1flag3=minus1for v in adj dict3[n]

if not matching dict2[v]flag2=vbreak

for p in adj dict3[matching dict2[n][0]]if not matching dict2[p]

flag3=pbreak

if (flag2=minus1) and (flag3=minus1) and (flag2=flag3)tempr=matching dict2[n][0]matching dict2[n]=[flag2]matching dict2[flag2]=[n]matching dict2[tempr]=[flag3]matching dict2[flag3]=[tempr]

elsefor k in adj dict3[n]

if not matching dict2[k]matching dict2[n]=[k]matching dict2[k]=[n]break

yo1=0for i in range(0num nodes)

if matching dict2[i] and [i]==matching dict2[matching dict2[i][0]]yo1=yo1+1

greedy size=yo12return greedy size

def General()

INPUTSwb = xlwtWorkbook()ws = wbadd sheet(Results Random)book=xlrdopen workbook(filenames randomxls)

48 Application

style0 = xlwteasyxf(fontbold on)style1 = xlwteasyxf(num format str=0000)INPUTSwswrite(0 0File style0)wswrite(0 1 Nodesstyle0)wswrite(0 2 Initial matchingstyle0)wswrite(0 3 NodesGstyle0)wswrite(0 4 EdgesGstyle0)wswrite(0 5 MaxDegreeGstyle0)wswrite(0 6 NodesG hatstyle0)wswrite(0 7 EdgesG Hatstyle0)wswrite(0 8 Useless edgesstyle0)wswrite(0 9 Forced edgesstyle0)wswrite(0 10 MaxDegreeG Hatstyle0)wswrite(0 11 Classical matchingstyle0)wswrite(0 12 Final matchingstyle0)wswrite(0 13 Greedy matchingstyle0)wswrite(0 14 Time classicalstyle0)wswrite(0 15 Time algorithmstyle0)wswrite(0 16 Time greedystyle0)wswrite(0 17 Perfect matching ratiostyle0)wswrite(0 18 Nodes ratiostyle0)wswrite(0 19 Edges ratiostyle0)wswrite(0 20 Matching ratiostyle0)

print nWelcomeThis is an implementation for general random graphs It uses Edmonds algorithm to compute maximum matching on G Hatn

for index in range (1481)was 481

if (index==482)f=open(Algotel generaltxtr)readlines()

elsefilea=str(booksheet by index(0)cell(index0))s=fileareplace(textu)replace()f=open(sr)readlines()Truewswrite(index 0 s)

print index

num nodes=int([xstrip()split() for x in f][0][0])

num matching=int([xstrip()split() for x in f][2][0])

adj temp = [xstrip()split() for x in f][44+num nodes]adj=[map(intR) for R in adj temp]

matching temp=[xstrip()split() for x in f][4+num nodes+14+2num nodes+1]matching1=[map(intR) for R in matching temp]

adj dict1=i[ii for iix in enumerate(L) if x] for iL in enumerate(adj)adj dict2=i[ii for iix in enumerate(L) if x] for iL in enumerate(adj)

Appendix A 49

adj dict3=i[ii for iix in enumerate(L) if x] for iL in enumerate(adj)

matching dict1=i[ii for iix in enumerate(L) if x] for iL in enumerate(matching1)matching dict2=i[ii for iix in enumerate(L) if x] for iL in enumerate(matching1)print adj dict2print matching dict2wswrite(index 1 num nodes)wswrite(index 2 num matching)

G = nxGraph()

useless= nxGraph()forced = nxGraph()

Fill Graphfor n in range(0num nodes)

for k in adj dict1[n]Gadd edge(nk)

Gt=Gnumber of edges()wswrite(index 3 Gnumber of nodes())wswrite(index 4 Gnumber of edges())wswrite(index 5 max(Gdegree()values()))

Compute Edmonds classical matching on G for comparison

startB = timeitdefault timer()Classical Matching=nxmax weight matching(G maxcardinality=False)stopB = timeitdefault timer()

Compute Gˆ nad MˆstartC = timeitdefault timer()useless edges(num nodesadj dict1matching dict1uselessadj dict2G)forced edges(Gadj dict2matching dict1num nodesforced)Final Matching=nxmax weight matching(G maxcardinality=False)stopC = timeitdefault timer()

GreedystartG = timeitdefault timer()greedy size=Greedy(num nodesadj dict3matching dict2)stopG = timeitdefault timer()

wswrite(index 6 Gnumber of nodes())wswrite(index 7 Gnumber of edges())wswrite(index 8 uselessnumber of edges())wswrite(index 9 forcednumber of edges())if Gdegree()values()

wswrite(index 10 max(Gdegree()values()))else

50 Application

wswrite(index 10 0)wswrite(index 11 len(Classical Matching)2)wswrite(index 12 len(Final Matching)2+forcednumber of edges())wswrite(index 13 greedy size)wswrite(index 14 stopB minus startBstyle1)wswrite(index 15 stopC minus startCstyle1)wswrite(index 16 stopG minus startGstyle1)wswrite(index 17 (len(Final Matching)2+forcednumber of edges())(num nodes2)style1)wswrite(index 18 Gnumber of nodes()Gtstyle1)wswrite(index 19 Gnumber of edges()Gtstyle1)wswrite(index 20 (len(Final Matching)2+forcednumber of edges())(len(Classical Matching)2)style1)

wbsave(AA Results Random Reyni Large Bipartitexls)

Main function Here we must choose the input form of the dataif name == main

startA = timeitdefault timer()General()stopA = timeitdefault timer()

print nThis program has terminatednnRunning time for 480 files stopAminusstartAprint nnPlease open AA Results Random Reyni Largexls file to see the Results

Appendix A 51

Plotmat

clear allclose allload(RN1Lmat)load(RN1Smat)load(RN2Lmat)load(RN2Smat)load(RN3Lmat)load(RN3Smat)

Plotsh(1)=figure(NameHistogram of Matching size difference between Constraint Algorithm and Greedy AlgorithmNumberTitleoff)

RN1L Greedydiff=RN1L Final matchingminusRN1L Greedy matchingRN2L Greedydiff=RN2L Final matchingminusRN2L Greedy matchingRN3L Greedydiff=RN3L Final matchingminusRN3L Greedy matchingRN1S Greedydiff=RN1S Final matchingminusRN1S Greedy matchingRN2S Greedydiff=RN2S Final matchingminusRN2S Greedy matchingRN3S Greedydiff=RN3S Final matchingminusRN3S Greedy matching

RN1L Finaldiff=RN1L Classical matchingminusRN1L Final matchingRN2L Finaldiff=RN2L Classical matchingminusRN2L Final matchingRN3L Finaldiff=RN3L Classical matchingminusRN3L Final matchingRN1S Finaldiff=RN1S Classical matchingminusRN1S Final matchingRN2S Finaldiff=RN2S Classical matchingminusRN2S Final matchingRN3S Finaldiff=RN3S Classical matchingminusRN3S Final matching

RN1L Classicaldiff=(RN1L Nodes2)minusRN1L Classical matchingRN2L Classicaldiff=(RN2L Nodes2)minusRN2L Classical matchingRN3L Classicaldiff=(RN3L Nodes2)minusRN3L Classical matchingRN1S Classicaldiff=(RN1S Nodes2)minusRN1S Classical matchingRN2S Classicaldiff=(RN2S Nodes2)minusRN2S Classical matchingRN3S Classicaldiff=(RN3S Nodes2)minusRN3S Classical matching

subplot(231)hold onhistf(RN1L Greedydiff0110facecolorbfacealpha9edgealpha1)histf(RN1L Finaldiff0110facecolorrfacealpha5edgealpha1)histf(RN1L Classicaldiff0110facecolorgfacealpha5edgealpha1)legalpha(ConminusGreClasminusConPerfminusClasslocationnortheast)legend boxoffaxis tightxlabel(edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN1L)grid on

subplot(232)hold onhistf(RN2L Greedydiff0110facecolorbfacealpha9edgealpha1)

52 Application

histf(RN2L Finaldiff0110facecolorrfacealpha5edgealpha1)histf(RN2L Classicaldiff0110facecolorgfacealpha5edgealpha1)legalpha(ConminusGreClasminusConPerfminusClasslocationnortheast)legend boxoffaxis tightxlabel(edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN2L)grid on

subplot(233)hold onhistf(RN3L Greedydiff0110facecolorbfacealpha5edgealpha1)histf(RN3L Finaldiff0110facecolorrfacealpha5edgealpha1)histf(RN3L Classicaldiff0110facecolorgfacealpha5edgealpha1)legalpha(ConminusGreClasminusConPerfminusClasslocationnortheast)legend boxoffaxis tightxlabel(edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN3L)grid on

subplot(234)hold onhistf(RN1S Greedydiff0110facecolorbfacealpha5edgealpha1)histf(RN1S Finaldiff0110facecolorrfacealpha5edgealpha1)histf(RN1S Classicaldiff0110facecolorgfacealpha5edgealpha1)legalpha(ConminusGreClasminusConPerfminusClasslocationnortheast)legend boxoffaxis tightxlabel(edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(R1NS)grid on

subplot(235)hold onhistf(RN2S Greedydiff0110facecolorbfacealpha5edgealpha1)histf(RN2S Finaldiff0110facecolorrfacealpha5edgealpha1)histf(RN2S Classicaldiff0110facecolorgfacealpha5edgealpha1)legalpha(ConminusGreClasminusConPerfminusClasslocationnortheast)legend boxoffaxis tightxlabel(edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN2S)grid on

subplot(236)hold onhistf(RN3S Greedydiff0110facecolorbfacealpha5edgealpha1)histf(RN3S Finaldiff0110facecolorrfacealpha5edgealpha1)histf(RN3S Classicaldiff0110facecolorgfacealpha5edgealpha1)

Appendix A 53

legalpha(ConminusGreClasminusConPerfminusClasslocationnortheast)legend boxoffaxis tightgrid ontitle(RN3S)xlabel(edges) xminusaxis labelylabel(instances) yminusaxis labelset(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN1png minusr300)h(2)=figure(NameHistogram of Max Degree of G AND G HatNumberTitleoff)RN1L x=RN1L MaxDegreeGminusRN1L MaxDegreeG HatRN2L x=RN2L MaxDegreeGminusRN2L MaxDegreeG HatRN3L x=RN3L MaxDegreeGminusRN3L MaxDegreeG HatRN1S x=RN1S MaxDegreeGminusRN1S MaxDegreeG HatRN2S x=RN2S MaxDegreeGminusRN2S MaxDegreeG HatRN3S x=RN3S MaxDegreeGminusRN3S MaxDegreeG Hatsubplot(231)hold onhistf(RN1L MaxDegreeG0150facecolorbfacealpha5edgealpha1)histf(RN1L MaxDegreeG Hat0150facecolorrfacealpha5edgealpha1)histf(RN1L x0150facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightxlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN1L)grid on

subplot(232)hold onhistf(RN2L MaxDegreeG010500facecolorbfacealpha5edgealpha1)histf(RN2L MaxDegreeG Hat010500facecolorrfacealpha5edgealpha1)histf(RN2L x010500facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightxlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN2L)grid on

subplot(233)hold onhistf(RN3L MaxDegreeG010300facecolorbfacealpha5edgealpha1)histf(RN3L MaxDegreeG Hat010300facecolorrfacealpha5edgealpha1)histf(RN3L x010300facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightxlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN3L)

54 Application

grid on

subplot(234)hold onhistf(RN1S MaxDegreeG0150facecolorbfacealpha5edgealpha1)histf(RN1S MaxDegreeG Hat0150facecolorrfacealpha5edgealpha1)histf(RN1S x0150facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightxlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(R1NS)grid on

subplot(235)hold onhistf(RN2S MaxDegreeG010500facecolorbfacealpha5edgealpha1)histf(RN2S MaxDegreeG Hat010500facecolorrfacealpha5edgealpha1)histf(RN2S x010500facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightxlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN2S)grid on

subplot(236)hold onhistf(RN3S MaxDegreeG05300facecolorbfacealpha5edgealpha1)histf(RN3S MaxDegreeG Hat05300facecolorrfacealpha5edgealpha1)histf(RN3S x05300facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightgrid ontitle(RN3S)xlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labelset(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN2png minusr300)

h(3)=figure(NameComputation time over edgesNumberTitleoff)

subplot(231)hold onstem(RN1L EdgesGRN1L Time classicalg)stem(RN1L EdgesGRN1L Time algorithmro)stem(RN1L EdgesGRN1L Time greedybx)grid on

Appendix A 55

title(RN1L)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)

subplot(232)hold onstem(RN2L EdgesGRN2L Time classicalg)stem(RN2L EdgesGRN2L Time algorithmro)stem(RN2L EdgesGRN2L Time greedybx)grid ontitle(RN2L)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)

subplot(233)hold onstem(RN3L EdgesGRN3L Time classicalg)stem(RN3L EdgesGRN3L Time algorithmro)stem(RN3L EdgesGRN3L Time greedybx)grid ontitle(RN3L)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)

subplot(234)hold onstem(RN1S EdgesGRN1S Time classicalg)stem(RN1S EdgesGRN1S Time algorithmro)stem(RN1S EdgesGRN1S Time greedybx)grid ontitle(RN1S)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)

subplot(235)hold onstem(RN2S EdgesGRN2S Time classicalg)stem(RN2S EdgesGRN2S Time algorithmro)stem(RN2S EdgesGRN2S Time greedybx)grid ontitle(RN2S)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)

subplot(236)hold onstem(RN3S EdgesGRN3S Time classicalg)stem(RN3S EdgesGRN3S Time algorithmro)stem(RN3S EdgesGRN3S Time greedybx)

56 Application

grid ontitle(RN3S)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)set(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN3png minusr300)

h(4)=figure(NameSorted matching sizeNumberTitleoff)RN1L Sorted matching temp(1)=RN1L Classical matchingRN1L Sorted matching temp(2)=RN1L Final matchingRN1L Sorted matching temp(3)=RN1L Greedy matchingRN1L Sorted matching temp(4)=RN1L Initial matchingRN1L Sorted matching=sortrows(RN1L Sorted matching temp)

RN2L Sorted matching temp(1)=RN2L Classical matchingRN2L Sorted matching temp(2)=RN2L Final matchingRN2L Sorted matching temp(3)=RN2L Greedy matchingRN2L Sorted matching temp(4)=RN2L Initial matchingRN2L Sorted matching=sortrows(RN2L Sorted matching temp)

RN3L Sorted matching temp(1)=RN3L Classical matchingRN3L Sorted matching temp(2)=RN3L Final matchingRN3L Sorted matching temp(3)=RN3L Greedy matchingRN3L Sorted matching temp(4)=RN3L Initial matchingRN3L Sorted matching=sortrows(RN3L Sorted matching temp)

RN1S Sorted matching temp(1)=RN1S Classical matchingRN1S Sorted matching temp(2)=RN1S Final matchingRN1S Sorted matching temp(3)=RN1S Greedy matchingRN1S Sorted matching temp(4)=RN1S Initial matchingRN1S Sorted matching=sortrows(RN1S Sorted matching temp)

RN2S Sorted matching temp(1)=RN2S Classical matchingRN2S Sorted matching temp(2)=RN2S Final matchingRN2S Sorted matching temp(3)=RN2S Greedy matchingRN2S Sorted matching temp(4)=RN2S Initial matchingRN2S Sorted matching=sortrows(RN2S Sorted matching temp)

RN3S Sorted matching temp(1)=RN3S Classical matchingRN3S Sorted matching temp(2)=RN3S Final matchingRN3S Sorted matching temp(3)=RN3S Greedy matchingRN3S Sorted matching temp(4)=RN3S Initial matchingRN3S Sorted matching=sortrows(RN3S Sorted matching temp)

subplot(231)hold onplot(RN1L Sorted matching(1)b)plot(RN1L Sorted matching(2)g)plot(RN1L Sorted matching(3)r)plot(RN1L Sorted matching(4)m)

Appendix A 57

grid ontitle(RN1L)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)

subplot(232)hold onplot(RN2L Sorted matching(1)b)plot(RN2L Sorted matching(2)g)plot(RN2L Sorted matching(3)r)plot(RN2L Sorted matching(4)m)grid ontitle(RN2L)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)

subplot(233)hold onplot(RN3L Sorted matching(1)b)plot(RN3L Sorted matching(2)g)plot(RN3L Sorted matching(3)r)plot(RN3L Sorted matching(4)m)grid ontitle(RN3L)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)

subplot(234)hold onplot(RN1S Sorted matching(1)b)plot(RN1S Sorted matching(2)g)plot(RN1S Sorted matching(3)r)plot(RN1S Sorted matching(4)m)grid ontitle(RN1S)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)

subplot(235)hold onplot(RN2S Sorted matching(1)b)plot(RN2S Sorted matching(2)g)plot(RN2S Sorted matching(3)r)plot(RN2S Sorted matching(4)m)grid ontitle(RN2S)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)

58 Application

subplot(236)hold onplot(RN3S Sorted matching(1)b)plot(RN3S Sorted matching(2)g)plot(RN3S Sorted matching(3)r)plot(RN3S Sorted matching(4)m)grid ontitle(RN3S)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)set(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN4png minusr300)h(5)=figure(NameSorted RatiosNumberTitleoff)RN1L ratio1=RN1L NodesG hatRN1L NodesGRN2L ratio1=RN2L NodesG hatRN2L NodesGRN3L ratio1=RN3L NodesG hatRN3L NodesGRN1S ratio1=RN1S NodesG hatRN1S NodesGRN2S ratio1=RN2S NodesG hatRN2S NodesGRN3S ratio1=RN3S NodesG hatRN3S NodesG

RN1L ratio2=RN1L EdgesG HatRN1L EdgesGRN2L ratio2=RN2L EdgesG HatRN2L EdgesGRN3L ratio2=RN3L EdgesG HatRN3L EdgesGRN1S ratio2=RN1S EdgesG HatRN1S EdgesGRN2S ratio2=RN2S EdgesG HatRN2S EdgesGRN3S ratio2=RN3S EdgesG HatRN3S EdgesG

RN1L ratio3=RN1L MaxDegreeG HatRN1L MaxDegreeGRN2L ratio3=RN2L MaxDegreeG HatRN2L MaxDegreeGRN3L ratio3=RN3L MaxDegreeG HatRN3L MaxDegreeGRN1S ratio3=RN1S MaxDegreeG HatRN1S MaxDegreeGRN2S ratio3=RN2S MaxDegreeG HatRN2S MaxDegreeGRN3S ratio3=RN3S MaxDegreeG HatRN3S MaxDegreeG

RN1L ratio(1)=RN1L ratio1RN1L ratio(2)=RN1L ratio2RN1L ratio(3)=RN1L ratio3

RN2L ratio(1)=RN2L ratio1RN2L ratio(2)=RN2L ratio2RN2L ratio(3)=RN2L ratio3

RN3L ratio(1)=RN3L ratio1RN3L ratio(2)=RN3L ratio2RN3L ratio(3)=RN3L ratio3

RN1S ratio(1)=RN1S ratio1RN1S ratio(2)=RN1S ratio2RN1S ratio(3)=RN1S ratio3

RN2S ratio(1)=RN2S ratio1

Appendix A 59

RN2S ratio(2)=RN2S ratio2RN2S ratio(3)=RN2S ratio3

RN3S ratio(1)=RN3S ratio1RN3S ratio(2)=RN3S ratio2RN3S ratio(3)=RN3S ratio3

RN1L ratio sorted=sortrows(RN1L ratio)RN2L ratio sorted=sortrows(RN2L ratio)RN3L ratio sorted=sortrows(RN3L ratio)RN1S ratio sorted=sortrows(RN1S ratio)RN2S ratio sorted=sortrows(RN2S ratio)RN3S ratio sorted=sortrows(RN3S ratio)

subplot(231)hold onplot(RN1L ratio sorted(1)b)plot(RN1L ratio sorted(2)g)plot(RN1L ratio sorted(3)r)grid ontitle(RN1L)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)

subplot(232)hold onplot(RN2L ratio sorted(1)b)plot(RN2L ratio sorted(2)g)plot(RN2L ratio sorted(3)r)grid ontitle(RN2L)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)

subplot(233)hold onplot(RN3L ratio sorted(1)b)plot(RN3L ratio sorted(2)g)plot(RN3L ratio sorted(3)r)grid ontitle(RN3L)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)

subplot(234)hold onplot(RN1S ratio sorted(1)b)plot(RN1S ratio sorted(2)g)plot(RN1S ratio sorted(3)r)grid on

60 Application

title(RN1S)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)

subplot(235)hold onplot(RN2S ratio sorted(1)b)plot(RN2S ratio sorted(2)g)plot(RN2S ratio sorted(3)r)grid ontitle(RN2S)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)

subplot(236)hold onplot(RN3S ratio sorted(1)b)plot(RN3S ratio sorted(2)g)plot(RN3S ratio sorted(3)r)grid ontitle(RN3S)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)set(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN5png minusr300)

h(6)=figure(NameSorted edges over nodesNumberTitleoff)

RN1L DegreeG1=(RN1L EdgesG)(RN1L NodesG)RN1L DegreeG Hat1=(RN1L EdgesG Hat)(RN1L NodesG hat)

RN1L Degree temp1(1)=RN1L DegreeG1RN1L Degree temp1(2)=RN1L DegreeG Hat1RN1L Degree sorted1=sortrows(RN1L Degree temp1)subplot(231)hold on

plot(RN1L Degree sorted1(1)b)plot(RN1L Degree sorted1(2)g)grid ontitle(RN1L)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)

RN2L DegreeG1=(RN2L EdgesG)(RN2L NodesG)RN2L DegreeG Hat1=(RN2L EdgesG Hat)(RN2L NodesG hat)

RN2L Degree temp1(1)=RN2L DegreeG1

Appendix A 61

RN2L Degree temp1(2)=RN2L DegreeG Hat1RN2L Degree sorted1=sortrows(RN2L Degree temp1)

subplot(232)hold onplot(RN2L Degree sorted1(1)b)plot(RN2L Degree sorted1(2)g)grid ontitle(RN2L)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)

RN3L DegreeG1=(RN3L EdgesG)(RN3L NodesG)RN3L DegreeG Hat1=(RN3L EdgesG Hat)(RN3L NodesG hat)

RN3L Degree temp1(1)=RN3L DegreeG1RN3L Degree temp1(2)=RN3L DegreeG Hat1RN3L Degree sorted1=sortrows(RN3L Degree temp1)

subplot(233)hold onplot(RN3L Degree sorted1(1)b)plot(RN3L Degree sorted1(2)g)grid ontitle(RN3L)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)

RN1S DegreeG1=(RN1S EdgesG)(RN1S NodesG)RN1S DegreeG Hat1=(RN1S EdgesG Hat)(RN1S NodesG hat)

RN1S Degree temp1(1)=RN1S DegreeG1RN1S Degree temp1(2)=RN1S DegreeG Hat1RN1S Degree sorted1=sortrows(RN1S Degree temp1)

subplot(234)hold onplot(RN1S Degree sorted1(1)b)plot(RN1S Degree sorted1(2)g)grid ontitle(RN1S)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)

RN2S DegreeG1=(RN2S EdgesG)(RN2S NodesG)RN2S DegreeG Hat1=(RN2S EdgesG Hat)(RN2S NodesG hat)

RN2S Degree temp1(1)=RN2S DegreeG1

62 Application

RN2S Degree temp1(2)=RN2S DegreeG Hat1RN2S Degree sorted1=sortrows(RN2S Degree temp1)

subplot(235)hold onplot(RN2S Degree sorted1(1)b)plot(RN2S Degree sorted1(2)g)grid ontitle(RN2S)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)

RN3S DegreeG1=(RN3S EdgesG)(RN3S NodesG)RN3S DegreeG Hat1=(RN3S EdgesG Hat)(RN3S NodesG hat)

RN3S Degree temp1(1)=RN3S DegreeG1RN3S Degree temp1(2)=RN3S DegreeG Hat1RN3S Degree sorted1=sortrows(RN3S Degree temp1)

subplot(236)hold onplot(RN3S Degree sorted1(1)b)plot(RN3S Degree sorted1(2)g)grid ontitle(RN3S)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)set(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN6png minusr300)h(7)=figure(NameSorted mATCHED DEGREENumberTitleoff)RN1L ratioMax(1)=RN1L MaxDegreeGRN1L ratioMax(2)=RN1L MaxDegreeG Hat

RN1L ratio sortedMax=sortrows(RN1L ratioMax)subplot(231)hold onplot(RN1L ratio sortedMax(1)b)plot(RN1L ratio sortedMax(2)g)grid ontitle(RN1L)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)

RN2L ratioMax(1)=RN2L MaxDegreeGRN2L ratioMax(2)=RN2L MaxDegreeG Hat

RN2L ratio sortedMax=sortrows(RN2L ratioMax)subplot(232)

Appendix A 63

hold onplot(RN2L ratio sortedMax(1)b)plot(RN2L ratio sortedMax(2)g)grid ontitle(RN2L)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)

RN3L ratioMax(1)=RN3L MaxDegreeGRN3L ratioMax(2)=RN3L MaxDegreeG Hat

RN3L ratio sortedMax=sortrows(RN3L ratioMax)subplot(233)hold onplot(RN3L ratio sortedMax(1)b)plot(RN3L ratio sortedMax(2)g)grid ontitle(RN3L)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)

RN1S ratioMax(1)=RN1S MaxDegreeGRN1S ratioMax(2)=RN1S MaxDegreeG Hat

RN1S ratio sortedMax=sortrows(RN1S ratioMax)subplot(234)hold onplot(RN1S ratio sortedMax(1)b)plot(RN1S ratio sortedMax(2)g)grid ontitle(RN1S)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)

RN2S ratioMax(1)=RN2S MaxDegreeGRN2S ratioMax(2)=RN2S MaxDegreeG Hat

RN2S ratio sortedMax=sortrows(RN2S ratioMax)

subplot(235)hold onplot(RN2S ratio sortedMax(1)b)plot(RN2S ratio sortedMax(2)g)grid ontitle(RN2S)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)

RN3S ratioMax(1)=RN3S MaxDegreeGRN3S ratioMax(2)=RN3S MaxDegreeG Hat

64 Application

RN3S ratio sortedMax=sortrows(RN3S ratioMax)subplot(236)hold onplot(RN3S ratio sortedMax(1)b)plot(RN3S ratio sortedMax(2)g)grid ontitle(RN1L)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)set(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN7png minusr300)

tilefigs()(h)

Bibliography

[1] C Berge ldquoTWO THEOREMS IN GRAPH THEORYrdquo Proceedings of the NationalAcademy of Sciences of the United States of America vol 43 no 9 pp 842ndash844Sep 1957

[2] L Bui S Sanghavi and R Srikant ldquoDistributed link scheduling with constantoverheadrdquo IEEEACM Trans Netw vol 17 no 5 pp 1467ndash1480 2009

[3] R Duan and S Pettie ldquoLinear-time approximation for maximum weight matchingrdquoJ ACM vol 61 no 1 2014

[4] J Edmonds ldquoPaths trees and flowersrdquo Canadian Journal of Mathematics vol 17pp 449ndash467 1965

[5] J E Hopcroft and R M Karp ldquoAn n52 algorithm for maximum matchings inbipartite graphsrdquo SIAM J Comput vol 2 no 4 pp 225ndash231 1973

[6] S Micali and V V Vazirani ldquoAn O(radic|V ||E|) algorithm for finding maximum

matching in general graphsrdquo in 21st Symp on Foundations of Comp Sc (FOCS)IEEE 1980 pp 17ndash27

[7] N Nisse A Salch and V Weber ldquoRecovery of disrupted airline operationsrdquo 2015httphalinriafrSomething

[8] X Wu and R Srikant ldquoRegulated maximal matching A distributed schedulingalgorithm for multi-hop wireless networks with nodeexclusive spectrum sharingrdquo inIEEE Conf on Decision and Control 2005

65

  • Contents
  • Introduction
  • Algorithms
    • Maximum matching
    • k-maximum matching
      • k-matching for Airport Slot assignment
      • The case where k=3
      • The case of Paths
      • The case of the Spider
          • Application
            • Description
            • Reyni Erdos
            • Barabaacutesi Albert
            • Amadeus Graphs
            • Bipartite
            • Bipartite with degree seq
            • Appendix A
              • BipartiteGraphGeneratorpy
              • RandomGraphGeneratorpy
              • kequals3MaximumMatchingpy
              • Plotmat
                  • Bibliography
Page 33: Theodoros Alexandros KARAGKIOULES -  · Introduction This work is the result of a 6 months internship, under the supervision of research O cer Nicolas NISSE. The original scope of

34 Application

Computation time overedges-Comments

bull Greedy algorithm takes minimum amount of time

bull The smaller the initial matching the more smaller the difference in comoutationtime of Constraint and classical algorithm

bull Due to preprocessing and the fact that G and G are the almost identical thetotal time needed to apply the constraint algorithm is in some cases bigger

Sorted matching size

26 Bipartite with degree seq 35

Sorted matching size-Comments

bull Classical matching is equal to perfect matching in every case

bull Constraint and greedy have identical behaviour

bull The larger the spectrum of the degree sequence the more efficient the matching

Sorted Ratios

36 Application

Sorted Ratios-Comments

bull With large initial matching most of the edges are considenred uselles or forced andare removed thus the ratio is close(if not equal to) zero

bull For small matching and large degree sequence sectrum hte max degree remainsthe same Only a few forced edges (and their nodes) are removed apparently nonodes with max degree

Sorted |E||V |

26 Bipartite with degree seq 37

Sorted |E||V | - Comments

bull In these set of figures we witness that the |E||V | acquires values relevant to those ofthe amadeus graphs The random graphs were constructed to depict this similarity

bull For smaller initial matching the ratios for G and G show the same upward trendand also they acquire closer values It repsresent the decrease of the averagenumber of forced edges in comparison to the larger matching cases

Sorted ∆

38 Application

Sorted ∆-Comments

bull Big difference in max degree in large initial matching

bull Almost identical behaviour in the case of small initial matching

Appendix A 39

Appendix A

BipartiteGraphGeneratorpy

from future import divisionimport networkx as nx

from networkxalgorithms import approximationimport collectionsimport randomimport mathfrom networkxalgorithms import bipartiteif name == main

for i in range(1481)waqs 481index=1n=randomrandint(100 1000)

n1=95 was 500me1=118

n2=251 was 500me2=903

n3=165 was 500me3=412

m=0m1=0p=randomrandom()p1=18250p2=25250p3=34250print ip=05t1=randomrandint(0 1)print im2=randomrandint(n2minus1 n2+1)G = nxGraph()ma = nxGraph()

aseq1=[1 2 3 4 5 3]

bseq1=[4 3 3 1 2 2 1]

aseq2=[16 14 14 14 12 11]bseq2=[0 0 0 0 0 0]

aseq3=[8 7 8 8 8 8]bseq3=[0 0 0 0 0 0]

40 Application

print Gnumber of edges()if ilt=160

G=bipartiteconfiguration model(aseq1 bseq1 create using=None seed=None)A=nxadjacency matrix(G)for ii in range(0n1+me1)

maadd node(ii)A=[Rtodense()tolist()[0] for R in A]

printnummanumber of nodes()rl=randomsample(range(0n1+me1) n1+me1)m=0done vertices = set()for p in rlprintin fordone verticesadd(p)

neighbors = []list()for iii in range(0n1+me1)

if A[p][iii]==1neighborsappend(iii)

randomshuffle(neighbors)continue loop = Truedegree = len(neighbors)

print degreej = 0p4=randomrandom()while continue loop and (jltdegree)print in loop

next = neighbors[j]if next not in done vertices and p not in done vertices

done verticesadd(p)done verticesadd(next)if p4gt=07print added edge

maadd edge(pnext)m=m+1

continue loop = Falsej += 1

print matching listOfedgeprint maedge

MA=nxadjacency matrix(ma)print MA

MA=[Rtodense()tolist()[0] for R in MA]print MA

B=[ join(map(strR)) for R in A]MB=[ join(map(strR)) for R in MA]

C=njoin(B)+nMC=njoin(MB)+n

print nprint mprint m1

filea=str(i)+txtwith open(fileaw) as f

Appendix A 41

fwrite(str(n1+me1))fwrite(n)fwrite(str(n1+me1))fwrite(n)fwrite(str(m))fwrite(n)fwrite(n)fwrite(C)fwrite(n)fwrite(MC)

elif igt160 and ilt321G=bipartiteconfiguration model(aseq2 bseq2 create using=None seed=None)A=nxadjacency matrix(G)for ii in range(0n2+me2)

maadd node(ii)A=[Rtodense()tolist()[0] for R in A]

printnummanumber of nodes()rl=randomsample(range(0n2+me2) n2+me2)m=0done vertices = set()for p in rlprintin fordone verticesadd(p)

neighbors = []list()for iii in range(0n2+me2)

if A[p][iii]==1neighborsappend(iii)

randomshuffle(neighbors)continue loop = Truedegree = len(neighbors)

print degreej = 0p4=randomrandom()while continue loop and (jltdegree)

print in loopnext = neighbors[j]if next not in done vertices and p not in done vertices

done verticesadd(p)done verticesadd(next)if p4gt=07

print added edgemaadd edge(pnext)m=m+1

continue loop = Falsej += 1

print matching listOfedgeprint maedge

MA=nxadjacency matrix(ma)print MA

MA=[Rtodense()tolist()[0] for R in MA]print MA

B=[ join(map(strR)) for R in A]MB=[ join(map(strR)) for R in MA]

42 Application

C=njoin(B)+nMC=njoin(MB)+n

print nprint mprint m1

filea=str(i)+txtwith open(fileaw) as f

fwrite(str(n2+me2))fwrite(n)fwrite(str(n2+me2))fwrite(n)fwrite(str(m))fwrite(n)fwrite(n)fwrite(C)fwrite(n)fwrite(MC)

elseG=bipartiteconfiguration model(aseq3 bseq3 create using=None seed=None)A=nxadjacency matrix(G)for ii in range(0n3+me3)

maadd node(ii)A=[Rtodense()tolist()[0] for R in A]

printnummanumber of nodes()rl=randomsample(range(0n3+me3) n3+me3)m=0done vertices = set()for p in rlprintin fordone verticesadd(p)

neighbors = []list()for iii in range(0n3+me3)

if A[p][iii]==1neighborsappend(iii)

randomshuffle(neighbors)continue loop = Truedegree = len(neighbors)

print degreej = 0p4=randomrandom()while continue loop and (jltdegree)

print in loopnext = neighbors[j]if next not in done vertices and p not in done vertices

done verticesadd(p)done verticesadd(next)if p4gt=07print added edge

maadd edge(pnext)m=m+1

continue loop = Falsej += 1

Appendix A 43

print matching listOfedgeprint maedge

MA=nxadjacency matrix(ma)print MA

MA=[Rtodense()tolist()[0] for R in MA]print MA

B=[ join(map(strR)) for R in A]MB=[ join(map(strR)) for R in MA]

C=njoin(B)+nMC=njoin(MB)+n

print nprint mprint m1

filea=str(i)+txtwith open(fileaw) as f

fwrite(str(n3+me3))fwrite(n)fwrite(str(n3+me3))fwrite(n)fwrite(str(m))fwrite(n)fwrite(n)fwrite(C)fwrite(n)fwrite(MC)

print nRandom graphs with random matching have been generated

44 Application

RandomGraphGeneratorpy

from future import divisionimport networkx as nxfrom networkxalgorithms import approximationimport collectionsimport randomimport mathif name == main

for i in range(1481)index=1n=randomrandint(100 1000)

n=1000m=0m1=0p=randomrandom()p1=mathlog(n2)np2=13p3=mathlog(n2)n+01p=05t1=randomrandint(0 1)print im2=randomrandint(n2minus1 n2+1)G = nxGraph()ma = nxGraph()print nme1=randomrandint(1 10)me2=randomrandint(2050)me3=randomrandint(50100)if ilt241

if ilt=80G=nxfast gnp random graph(n p1 seed=None directed=False)

elif igt80 and ilt161G=nxfast gnp random graph(n p2 seed=None directed=False)

elseG=nxfast gnp random graph(n p3 seed=None directed=False)

elseif ilt=320

G=nxbarabasi albert graph(n me1 seed=None)elif igt320 and ilt401

G=nxbarabasi albert graph(n me2 seed=None)else

G=nxbarabasi albert graph(n me3 seed=None)A=nxadjacency matrix(G)for ii in range(0n)

maadd node(ii)A=[Rtodense()tolist()[0] for R in A]

rl=randomsample(range(0n) n)m=0

Appendix A 45

done vertices = set()for p in rl

done verticesadd(p)neighbors = []list()for iii in range(0n)

if A[p][iii]==1neighborsappend(iii)

randomshuffle(neighbors)continue loop = Truedegree = len(neighbors)j = 0p2=randomrandom()while continue loop and (jltdegree)

next = neighbors[j]if next not in done vertices and p not in done vertices

done verticesadd(p)done verticesadd(next)if p2gt=00 Larger probability for smaller initial matching

maadd edge(pnext)m=m+1

continue loop = Falsej += 1

print matching listOfedgeprint maedgeMA=nxadjacency matrix(ma)MA=[Rtodense()tolist()[0] for R in MA]print MAB=[ join(map(strR)) for R in A]MB=[ join(map(strR)) for R in MA]

C=njoin(B)+nMC=njoin(MB)+nprint MCprint nprint mprint m1filea=str(i)+txtwith open(fileaw) as f

fwrite(str(n))fwrite(n)fwrite(str(n))fwrite(n)fwrite(str(m))fwrite(n)fwrite(n)fwrite(C)fwrite(n)fwrite(MC)

print nRandom graphs with random matching have been generated

46 Application

kequals3MaximumMatchingpy

from future import divisionimport networkx as nxfrom networkxalgorithms import bipartiteimport matplotlibpyplot as pltimport collectionsimport timeitimport xlwtimport xlrdimport mathimport sys

Case for General Graphsdef forced edges(Gadj dict2matching dict1num nodesforced)

flagg=0for n in range(0num nodes)

for k in adj dict2[n]if ([k]==matching dict1[n])

count=0for l in range(0num nodes)

count=count+adj dict2[l]count(k)if (len(adj dict2[n])==1) or (count==1)

forcedadd edge(nk)Gremove edge(nk)Gremove node(n)Gremove node(k)printforced edgenktemp=kflagg=1for m in range (len(adj dict2[n])minus1minus1minus1)

adj dict2[adj dict2[n][m]]remove(n)adj dict2[n]remove(adj dict2[n][m])

if adj dict2[temp]for l in range(len(adj dict2[temp])minus1minus1minus1)

if (adj dict2[temp][l]=n)adj dict2[adj dict2[temp][l]]remove(temp)adj dict2[temp]remove(adj dict2[temp][l])

break

def useless edges(num nodesadj dict1matching dict1uselessadj dict2G)for n in range(0num nodes)

for k in adj dict1[n]if ([k]=matching dict1[n]) and matching dict1[n] and matching dict1[k]

uselessadd edge(nk)Gremove edge(n k)

Appendix A 47

tempa=kadj dict2[n]remove(k)adj dict2[tempa]remove(n)adj dict1[tempa]remove(n)

return G

def Greedy(num nodesadj dict3matching dict2)

for n in range(0num nodes)if matching dict2[n]

flag2=minus1flag3=minus1for v in adj dict3[n]

if not matching dict2[v]flag2=vbreak

for p in adj dict3[matching dict2[n][0]]if not matching dict2[p]

flag3=pbreak

if (flag2=minus1) and (flag3=minus1) and (flag2=flag3)tempr=matching dict2[n][0]matching dict2[n]=[flag2]matching dict2[flag2]=[n]matching dict2[tempr]=[flag3]matching dict2[flag3]=[tempr]

elsefor k in adj dict3[n]

if not matching dict2[k]matching dict2[n]=[k]matching dict2[k]=[n]break

yo1=0for i in range(0num nodes)

if matching dict2[i] and [i]==matching dict2[matching dict2[i][0]]yo1=yo1+1

greedy size=yo12return greedy size

def General()

INPUTSwb = xlwtWorkbook()ws = wbadd sheet(Results Random)book=xlrdopen workbook(filenames randomxls)

48 Application

style0 = xlwteasyxf(fontbold on)style1 = xlwteasyxf(num format str=0000)INPUTSwswrite(0 0File style0)wswrite(0 1 Nodesstyle0)wswrite(0 2 Initial matchingstyle0)wswrite(0 3 NodesGstyle0)wswrite(0 4 EdgesGstyle0)wswrite(0 5 MaxDegreeGstyle0)wswrite(0 6 NodesG hatstyle0)wswrite(0 7 EdgesG Hatstyle0)wswrite(0 8 Useless edgesstyle0)wswrite(0 9 Forced edgesstyle0)wswrite(0 10 MaxDegreeG Hatstyle0)wswrite(0 11 Classical matchingstyle0)wswrite(0 12 Final matchingstyle0)wswrite(0 13 Greedy matchingstyle0)wswrite(0 14 Time classicalstyle0)wswrite(0 15 Time algorithmstyle0)wswrite(0 16 Time greedystyle0)wswrite(0 17 Perfect matching ratiostyle0)wswrite(0 18 Nodes ratiostyle0)wswrite(0 19 Edges ratiostyle0)wswrite(0 20 Matching ratiostyle0)

print nWelcomeThis is an implementation for general random graphs It uses Edmonds algorithm to compute maximum matching on G Hatn

for index in range (1481)was 481

if (index==482)f=open(Algotel generaltxtr)readlines()

elsefilea=str(booksheet by index(0)cell(index0))s=fileareplace(textu)replace()f=open(sr)readlines()Truewswrite(index 0 s)

print index

num nodes=int([xstrip()split() for x in f][0][0])

num matching=int([xstrip()split() for x in f][2][0])

adj temp = [xstrip()split() for x in f][44+num nodes]adj=[map(intR) for R in adj temp]

matching temp=[xstrip()split() for x in f][4+num nodes+14+2num nodes+1]matching1=[map(intR) for R in matching temp]

adj dict1=i[ii for iix in enumerate(L) if x] for iL in enumerate(adj)adj dict2=i[ii for iix in enumerate(L) if x] for iL in enumerate(adj)

Appendix A 49

adj dict3=i[ii for iix in enumerate(L) if x] for iL in enumerate(adj)

matching dict1=i[ii for iix in enumerate(L) if x] for iL in enumerate(matching1)matching dict2=i[ii for iix in enumerate(L) if x] for iL in enumerate(matching1)print adj dict2print matching dict2wswrite(index 1 num nodes)wswrite(index 2 num matching)

G = nxGraph()

useless= nxGraph()forced = nxGraph()

Fill Graphfor n in range(0num nodes)

for k in adj dict1[n]Gadd edge(nk)

Gt=Gnumber of edges()wswrite(index 3 Gnumber of nodes())wswrite(index 4 Gnumber of edges())wswrite(index 5 max(Gdegree()values()))

Compute Edmonds classical matching on G for comparison

startB = timeitdefault timer()Classical Matching=nxmax weight matching(G maxcardinality=False)stopB = timeitdefault timer()

Compute Gˆ nad MˆstartC = timeitdefault timer()useless edges(num nodesadj dict1matching dict1uselessadj dict2G)forced edges(Gadj dict2matching dict1num nodesforced)Final Matching=nxmax weight matching(G maxcardinality=False)stopC = timeitdefault timer()

GreedystartG = timeitdefault timer()greedy size=Greedy(num nodesadj dict3matching dict2)stopG = timeitdefault timer()

wswrite(index 6 Gnumber of nodes())wswrite(index 7 Gnumber of edges())wswrite(index 8 uselessnumber of edges())wswrite(index 9 forcednumber of edges())if Gdegree()values()

wswrite(index 10 max(Gdegree()values()))else

50 Application

wswrite(index 10 0)wswrite(index 11 len(Classical Matching)2)wswrite(index 12 len(Final Matching)2+forcednumber of edges())wswrite(index 13 greedy size)wswrite(index 14 stopB minus startBstyle1)wswrite(index 15 stopC minus startCstyle1)wswrite(index 16 stopG minus startGstyle1)wswrite(index 17 (len(Final Matching)2+forcednumber of edges())(num nodes2)style1)wswrite(index 18 Gnumber of nodes()Gtstyle1)wswrite(index 19 Gnumber of edges()Gtstyle1)wswrite(index 20 (len(Final Matching)2+forcednumber of edges())(len(Classical Matching)2)style1)

wbsave(AA Results Random Reyni Large Bipartitexls)

Main function Here we must choose the input form of the dataif name == main

startA = timeitdefault timer()General()stopA = timeitdefault timer()

print nThis program has terminatednnRunning time for 480 files stopAminusstartAprint nnPlease open AA Results Random Reyni Largexls file to see the Results

Appendix A 51

Plotmat

clear allclose allload(RN1Lmat)load(RN1Smat)load(RN2Lmat)load(RN2Smat)load(RN3Lmat)load(RN3Smat)

Plotsh(1)=figure(NameHistogram of Matching size difference between Constraint Algorithm and Greedy AlgorithmNumberTitleoff)

RN1L Greedydiff=RN1L Final matchingminusRN1L Greedy matchingRN2L Greedydiff=RN2L Final matchingminusRN2L Greedy matchingRN3L Greedydiff=RN3L Final matchingminusRN3L Greedy matchingRN1S Greedydiff=RN1S Final matchingminusRN1S Greedy matchingRN2S Greedydiff=RN2S Final matchingminusRN2S Greedy matchingRN3S Greedydiff=RN3S Final matchingminusRN3S Greedy matching

RN1L Finaldiff=RN1L Classical matchingminusRN1L Final matchingRN2L Finaldiff=RN2L Classical matchingminusRN2L Final matchingRN3L Finaldiff=RN3L Classical matchingminusRN3L Final matchingRN1S Finaldiff=RN1S Classical matchingminusRN1S Final matchingRN2S Finaldiff=RN2S Classical matchingminusRN2S Final matchingRN3S Finaldiff=RN3S Classical matchingminusRN3S Final matching

RN1L Classicaldiff=(RN1L Nodes2)minusRN1L Classical matchingRN2L Classicaldiff=(RN2L Nodes2)minusRN2L Classical matchingRN3L Classicaldiff=(RN3L Nodes2)minusRN3L Classical matchingRN1S Classicaldiff=(RN1S Nodes2)minusRN1S Classical matchingRN2S Classicaldiff=(RN2S Nodes2)minusRN2S Classical matchingRN3S Classicaldiff=(RN3S Nodes2)minusRN3S Classical matching

subplot(231)hold onhistf(RN1L Greedydiff0110facecolorbfacealpha9edgealpha1)histf(RN1L Finaldiff0110facecolorrfacealpha5edgealpha1)histf(RN1L Classicaldiff0110facecolorgfacealpha5edgealpha1)legalpha(ConminusGreClasminusConPerfminusClasslocationnortheast)legend boxoffaxis tightxlabel(edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN1L)grid on

subplot(232)hold onhistf(RN2L Greedydiff0110facecolorbfacealpha9edgealpha1)

52 Application

histf(RN2L Finaldiff0110facecolorrfacealpha5edgealpha1)histf(RN2L Classicaldiff0110facecolorgfacealpha5edgealpha1)legalpha(ConminusGreClasminusConPerfminusClasslocationnortheast)legend boxoffaxis tightxlabel(edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN2L)grid on

subplot(233)hold onhistf(RN3L Greedydiff0110facecolorbfacealpha5edgealpha1)histf(RN3L Finaldiff0110facecolorrfacealpha5edgealpha1)histf(RN3L Classicaldiff0110facecolorgfacealpha5edgealpha1)legalpha(ConminusGreClasminusConPerfminusClasslocationnortheast)legend boxoffaxis tightxlabel(edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN3L)grid on

subplot(234)hold onhistf(RN1S Greedydiff0110facecolorbfacealpha5edgealpha1)histf(RN1S Finaldiff0110facecolorrfacealpha5edgealpha1)histf(RN1S Classicaldiff0110facecolorgfacealpha5edgealpha1)legalpha(ConminusGreClasminusConPerfminusClasslocationnortheast)legend boxoffaxis tightxlabel(edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(R1NS)grid on

subplot(235)hold onhistf(RN2S Greedydiff0110facecolorbfacealpha5edgealpha1)histf(RN2S Finaldiff0110facecolorrfacealpha5edgealpha1)histf(RN2S Classicaldiff0110facecolorgfacealpha5edgealpha1)legalpha(ConminusGreClasminusConPerfminusClasslocationnortheast)legend boxoffaxis tightxlabel(edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN2S)grid on

subplot(236)hold onhistf(RN3S Greedydiff0110facecolorbfacealpha5edgealpha1)histf(RN3S Finaldiff0110facecolorrfacealpha5edgealpha1)histf(RN3S Classicaldiff0110facecolorgfacealpha5edgealpha1)

Appendix A 53

legalpha(ConminusGreClasminusConPerfminusClasslocationnortheast)legend boxoffaxis tightgrid ontitle(RN3S)xlabel(edges) xminusaxis labelylabel(instances) yminusaxis labelset(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN1png minusr300)h(2)=figure(NameHistogram of Max Degree of G AND G HatNumberTitleoff)RN1L x=RN1L MaxDegreeGminusRN1L MaxDegreeG HatRN2L x=RN2L MaxDegreeGminusRN2L MaxDegreeG HatRN3L x=RN3L MaxDegreeGminusRN3L MaxDegreeG HatRN1S x=RN1S MaxDegreeGminusRN1S MaxDegreeG HatRN2S x=RN2S MaxDegreeGminusRN2S MaxDegreeG HatRN3S x=RN3S MaxDegreeGminusRN3S MaxDegreeG Hatsubplot(231)hold onhistf(RN1L MaxDegreeG0150facecolorbfacealpha5edgealpha1)histf(RN1L MaxDegreeG Hat0150facecolorrfacealpha5edgealpha1)histf(RN1L x0150facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightxlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN1L)grid on

subplot(232)hold onhistf(RN2L MaxDegreeG010500facecolorbfacealpha5edgealpha1)histf(RN2L MaxDegreeG Hat010500facecolorrfacealpha5edgealpha1)histf(RN2L x010500facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightxlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN2L)grid on

subplot(233)hold onhistf(RN3L MaxDegreeG010300facecolorbfacealpha5edgealpha1)histf(RN3L MaxDegreeG Hat010300facecolorrfacealpha5edgealpha1)histf(RN3L x010300facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightxlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN3L)

54 Application

grid on

subplot(234)hold onhistf(RN1S MaxDegreeG0150facecolorbfacealpha5edgealpha1)histf(RN1S MaxDegreeG Hat0150facecolorrfacealpha5edgealpha1)histf(RN1S x0150facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightxlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(R1NS)grid on

subplot(235)hold onhistf(RN2S MaxDegreeG010500facecolorbfacealpha5edgealpha1)histf(RN2S MaxDegreeG Hat010500facecolorrfacealpha5edgealpha1)histf(RN2S x010500facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightxlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN2S)grid on

subplot(236)hold onhistf(RN3S MaxDegreeG05300facecolorbfacealpha5edgealpha1)histf(RN3S MaxDegreeG Hat05300facecolorrfacealpha5edgealpha1)histf(RN3S x05300facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightgrid ontitle(RN3S)xlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labelset(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN2png minusr300)

h(3)=figure(NameComputation time over edgesNumberTitleoff)

subplot(231)hold onstem(RN1L EdgesGRN1L Time classicalg)stem(RN1L EdgesGRN1L Time algorithmro)stem(RN1L EdgesGRN1L Time greedybx)grid on

Appendix A 55

title(RN1L)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)

subplot(232)hold onstem(RN2L EdgesGRN2L Time classicalg)stem(RN2L EdgesGRN2L Time algorithmro)stem(RN2L EdgesGRN2L Time greedybx)grid ontitle(RN2L)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)

subplot(233)hold onstem(RN3L EdgesGRN3L Time classicalg)stem(RN3L EdgesGRN3L Time algorithmro)stem(RN3L EdgesGRN3L Time greedybx)grid ontitle(RN3L)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)

subplot(234)hold onstem(RN1S EdgesGRN1S Time classicalg)stem(RN1S EdgesGRN1S Time algorithmro)stem(RN1S EdgesGRN1S Time greedybx)grid ontitle(RN1S)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)

subplot(235)hold onstem(RN2S EdgesGRN2S Time classicalg)stem(RN2S EdgesGRN2S Time algorithmro)stem(RN2S EdgesGRN2S Time greedybx)grid ontitle(RN2S)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)

subplot(236)hold onstem(RN3S EdgesGRN3S Time classicalg)stem(RN3S EdgesGRN3S Time algorithmro)stem(RN3S EdgesGRN3S Time greedybx)

56 Application

grid ontitle(RN3S)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)set(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN3png minusr300)

h(4)=figure(NameSorted matching sizeNumberTitleoff)RN1L Sorted matching temp(1)=RN1L Classical matchingRN1L Sorted matching temp(2)=RN1L Final matchingRN1L Sorted matching temp(3)=RN1L Greedy matchingRN1L Sorted matching temp(4)=RN1L Initial matchingRN1L Sorted matching=sortrows(RN1L Sorted matching temp)

RN2L Sorted matching temp(1)=RN2L Classical matchingRN2L Sorted matching temp(2)=RN2L Final matchingRN2L Sorted matching temp(3)=RN2L Greedy matchingRN2L Sorted matching temp(4)=RN2L Initial matchingRN2L Sorted matching=sortrows(RN2L Sorted matching temp)

RN3L Sorted matching temp(1)=RN3L Classical matchingRN3L Sorted matching temp(2)=RN3L Final matchingRN3L Sorted matching temp(3)=RN3L Greedy matchingRN3L Sorted matching temp(4)=RN3L Initial matchingRN3L Sorted matching=sortrows(RN3L Sorted matching temp)

RN1S Sorted matching temp(1)=RN1S Classical matchingRN1S Sorted matching temp(2)=RN1S Final matchingRN1S Sorted matching temp(3)=RN1S Greedy matchingRN1S Sorted matching temp(4)=RN1S Initial matchingRN1S Sorted matching=sortrows(RN1S Sorted matching temp)

RN2S Sorted matching temp(1)=RN2S Classical matchingRN2S Sorted matching temp(2)=RN2S Final matchingRN2S Sorted matching temp(3)=RN2S Greedy matchingRN2S Sorted matching temp(4)=RN2S Initial matchingRN2S Sorted matching=sortrows(RN2S Sorted matching temp)

RN3S Sorted matching temp(1)=RN3S Classical matchingRN3S Sorted matching temp(2)=RN3S Final matchingRN3S Sorted matching temp(3)=RN3S Greedy matchingRN3S Sorted matching temp(4)=RN3S Initial matchingRN3S Sorted matching=sortrows(RN3S Sorted matching temp)

subplot(231)hold onplot(RN1L Sorted matching(1)b)plot(RN1L Sorted matching(2)g)plot(RN1L Sorted matching(3)r)plot(RN1L Sorted matching(4)m)

Appendix A 57

grid ontitle(RN1L)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)

subplot(232)hold onplot(RN2L Sorted matching(1)b)plot(RN2L Sorted matching(2)g)plot(RN2L Sorted matching(3)r)plot(RN2L Sorted matching(4)m)grid ontitle(RN2L)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)

subplot(233)hold onplot(RN3L Sorted matching(1)b)plot(RN3L Sorted matching(2)g)plot(RN3L Sorted matching(3)r)plot(RN3L Sorted matching(4)m)grid ontitle(RN3L)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)

subplot(234)hold onplot(RN1S Sorted matching(1)b)plot(RN1S Sorted matching(2)g)plot(RN1S Sorted matching(3)r)plot(RN1S Sorted matching(4)m)grid ontitle(RN1S)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)

subplot(235)hold onplot(RN2S Sorted matching(1)b)plot(RN2S Sorted matching(2)g)plot(RN2S Sorted matching(3)r)plot(RN2S Sorted matching(4)m)grid ontitle(RN2S)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)

58 Application

subplot(236)hold onplot(RN3S Sorted matching(1)b)plot(RN3S Sorted matching(2)g)plot(RN3S Sorted matching(3)r)plot(RN3S Sorted matching(4)m)grid ontitle(RN3S)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)set(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN4png minusr300)h(5)=figure(NameSorted RatiosNumberTitleoff)RN1L ratio1=RN1L NodesG hatRN1L NodesGRN2L ratio1=RN2L NodesG hatRN2L NodesGRN3L ratio1=RN3L NodesG hatRN3L NodesGRN1S ratio1=RN1S NodesG hatRN1S NodesGRN2S ratio1=RN2S NodesG hatRN2S NodesGRN3S ratio1=RN3S NodesG hatRN3S NodesG

RN1L ratio2=RN1L EdgesG HatRN1L EdgesGRN2L ratio2=RN2L EdgesG HatRN2L EdgesGRN3L ratio2=RN3L EdgesG HatRN3L EdgesGRN1S ratio2=RN1S EdgesG HatRN1S EdgesGRN2S ratio2=RN2S EdgesG HatRN2S EdgesGRN3S ratio2=RN3S EdgesG HatRN3S EdgesG

RN1L ratio3=RN1L MaxDegreeG HatRN1L MaxDegreeGRN2L ratio3=RN2L MaxDegreeG HatRN2L MaxDegreeGRN3L ratio3=RN3L MaxDegreeG HatRN3L MaxDegreeGRN1S ratio3=RN1S MaxDegreeG HatRN1S MaxDegreeGRN2S ratio3=RN2S MaxDegreeG HatRN2S MaxDegreeGRN3S ratio3=RN3S MaxDegreeG HatRN3S MaxDegreeG

RN1L ratio(1)=RN1L ratio1RN1L ratio(2)=RN1L ratio2RN1L ratio(3)=RN1L ratio3

RN2L ratio(1)=RN2L ratio1RN2L ratio(2)=RN2L ratio2RN2L ratio(3)=RN2L ratio3

RN3L ratio(1)=RN3L ratio1RN3L ratio(2)=RN3L ratio2RN3L ratio(3)=RN3L ratio3

RN1S ratio(1)=RN1S ratio1RN1S ratio(2)=RN1S ratio2RN1S ratio(3)=RN1S ratio3

RN2S ratio(1)=RN2S ratio1

Appendix A 59

RN2S ratio(2)=RN2S ratio2RN2S ratio(3)=RN2S ratio3

RN3S ratio(1)=RN3S ratio1RN3S ratio(2)=RN3S ratio2RN3S ratio(3)=RN3S ratio3

RN1L ratio sorted=sortrows(RN1L ratio)RN2L ratio sorted=sortrows(RN2L ratio)RN3L ratio sorted=sortrows(RN3L ratio)RN1S ratio sorted=sortrows(RN1S ratio)RN2S ratio sorted=sortrows(RN2S ratio)RN3S ratio sorted=sortrows(RN3S ratio)

subplot(231)hold onplot(RN1L ratio sorted(1)b)plot(RN1L ratio sorted(2)g)plot(RN1L ratio sorted(3)r)grid ontitle(RN1L)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)

subplot(232)hold onplot(RN2L ratio sorted(1)b)plot(RN2L ratio sorted(2)g)plot(RN2L ratio sorted(3)r)grid ontitle(RN2L)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)

subplot(233)hold onplot(RN3L ratio sorted(1)b)plot(RN3L ratio sorted(2)g)plot(RN3L ratio sorted(3)r)grid ontitle(RN3L)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)

subplot(234)hold onplot(RN1S ratio sorted(1)b)plot(RN1S ratio sorted(2)g)plot(RN1S ratio sorted(3)r)grid on

60 Application

title(RN1S)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)

subplot(235)hold onplot(RN2S ratio sorted(1)b)plot(RN2S ratio sorted(2)g)plot(RN2S ratio sorted(3)r)grid ontitle(RN2S)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)

subplot(236)hold onplot(RN3S ratio sorted(1)b)plot(RN3S ratio sorted(2)g)plot(RN3S ratio sorted(3)r)grid ontitle(RN3S)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)set(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN5png minusr300)

h(6)=figure(NameSorted edges over nodesNumberTitleoff)

RN1L DegreeG1=(RN1L EdgesG)(RN1L NodesG)RN1L DegreeG Hat1=(RN1L EdgesG Hat)(RN1L NodesG hat)

RN1L Degree temp1(1)=RN1L DegreeG1RN1L Degree temp1(2)=RN1L DegreeG Hat1RN1L Degree sorted1=sortrows(RN1L Degree temp1)subplot(231)hold on

plot(RN1L Degree sorted1(1)b)plot(RN1L Degree sorted1(2)g)grid ontitle(RN1L)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)

RN2L DegreeG1=(RN2L EdgesG)(RN2L NodesG)RN2L DegreeG Hat1=(RN2L EdgesG Hat)(RN2L NodesG hat)

RN2L Degree temp1(1)=RN2L DegreeG1

Appendix A 61

RN2L Degree temp1(2)=RN2L DegreeG Hat1RN2L Degree sorted1=sortrows(RN2L Degree temp1)

subplot(232)hold onplot(RN2L Degree sorted1(1)b)plot(RN2L Degree sorted1(2)g)grid ontitle(RN2L)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)

RN3L DegreeG1=(RN3L EdgesG)(RN3L NodesG)RN3L DegreeG Hat1=(RN3L EdgesG Hat)(RN3L NodesG hat)

RN3L Degree temp1(1)=RN3L DegreeG1RN3L Degree temp1(2)=RN3L DegreeG Hat1RN3L Degree sorted1=sortrows(RN3L Degree temp1)

subplot(233)hold onplot(RN3L Degree sorted1(1)b)plot(RN3L Degree sorted1(2)g)grid ontitle(RN3L)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)

RN1S DegreeG1=(RN1S EdgesG)(RN1S NodesG)RN1S DegreeG Hat1=(RN1S EdgesG Hat)(RN1S NodesG hat)

RN1S Degree temp1(1)=RN1S DegreeG1RN1S Degree temp1(2)=RN1S DegreeG Hat1RN1S Degree sorted1=sortrows(RN1S Degree temp1)

subplot(234)hold onplot(RN1S Degree sorted1(1)b)plot(RN1S Degree sorted1(2)g)grid ontitle(RN1S)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)

RN2S DegreeG1=(RN2S EdgesG)(RN2S NodesG)RN2S DegreeG Hat1=(RN2S EdgesG Hat)(RN2S NodesG hat)

RN2S Degree temp1(1)=RN2S DegreeG1

62 Application

RN2S Degree temp1(2)=RN2S DegreeG Hat1RN2S Degree sorted1=sortrows(RN2S Degree temp1)

subplot(235)hold onplot(RN2S Degree sorted1(1)b)plot(RN2S Degree sorted1(2)g)grid ontitle(RN2S)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)

RN3S DegreeG1=(RN3S EdgesG)(RN3S NodesG)RN3S DegreeG Hat1=(RN3S EdgesG Hat)(RN3S NodesG hat)

RN3S Degree temp1(1)=RN3S DegreeG1RN3S Degree temp1(2)=RN3S DegreeG Hat1RN3S Degree sorted1=sortrows(RN3S Degree temp1)

subplot(236)hold onplot(RN3S Degree sorted1(1)b)plot(RN3S Degree sorted1(2)g)grid ontitle(RN3S)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)set(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN6png minusr300)h(7)=figure(NameSorted mATCHED DEGREENumberTitleoff)RN1L ratioMax(1)=RN1L MaxDegreeGRN1L ratioMax(2)=RN1L MaxDegreeG Hat

RN1L ratio sortedMax=sortrows(RN1L ratioMax)subplot(231)hold onplot(RN1L ratio sortedMax(1)b)plot(RN1L ratio sortedMax(2)g)grid ontitle(RN1L)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)

RN2L ratioMax(1)=RN2L MaxDegreeGRN2L ratioMax(2)=RN2L MaxDegreeG Hat

RN2L ratio sortedMax=sortrows(RN2L ratioMax)subplot(232)

Appendix A 63

hold onplot(RN2L ratio sortedMax(1)b)plot(RN2L ratio sortedMax(2)g)grid ontitle(RN2L)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)

RN3L ratioMax(1)=RN3L MaxDegreeGRN3L ratioMax(2)=RN3L MaxDegreeG Hat

RN3L ratio sortedMax=sortrows(RN3L ratioMax)subplot(233)hold onplot(RN3L ratio sortedMax(1)b)plot(RN3L ratio sortedMax(2)g)grid ontitle(RN3L)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)

RN1S ratioMax(1)=RN1S MaxDegreeGRN1S ratioMax(2)=RN1S MaxDegreeG Hat

RN1S ratio sortedMax=sortrows(RN1S ratioMax)subplot(234)hold onplot(RN1S ratio sortedMax(1)b)plot(RN1S ratio sortedMax(2)g)grid ontitle(RN1S)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)

RN2S ratioMax(1)=RN2S MaxDegreeGRN2S ratioMax(2)=RN2S MaxDegreeG Hat

RN2S ratio sortedMax=sortrows(RN2S ratioMax)

subplot(235)hold onplot(RN2S ratio sortedMax(1)b)plot(RN2S ratio sortedMax(2)g)grid ontitle(RN2S)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)

RN3S ratioMax(1)=RN3S MaxDegreeGRN3S ratioMax(2)=RN3S MaxDegreeG Hat

64 Application

RN3S ratio sortedMax=sortrows(RN3S ratioMax)subplot(236)hold onplot(RN3S ratio sortedMax(1)b)plot(RN3S ratio sortedMax(2)g)grid ontitle(RN1L)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)set(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN7png minusr300)

tilefigs()(h)

Bibliography

[1] C Berge ldquoTWO THEOREMS IN GRAPH THEORYrdquo Proceedings of the NationalAcademy of Sciences of the United States of America vol 43 no 9 pp 842ndash844Sep 1957

[2] L Bui S Sanghavi and R Srikant ldquoDistributed link scheduling with constantoverheadrdquo IEEEACM Trans Netw vol 17 no 5 pp 1467ndash1480 2009

[3] R Duan and S Pettie ldquoLinear-time approximation for maximum weight matchingrdquoJ ACM vol 61 no 1 2014

[4] J Edmonds ldquoPaths trees and flowersrdquo Canadian Journal of Mathematics vol 17pp 449ndash467 1965

[5] J E Hopcroft and R M Karp ldquoAn n52 algorithm for maximum matchings inbipartite graphsrdquo SIAM J Comput vol 2 no 4 pp 225ndash231 1973

[6] S Micali and V V Vazirani ldquoAn O(radic|V ||E|) algorithm for finding maximum

matching in general graphsrdquo in 21st Symp on Foundations of Comp Sc (FOCS)IEEE 1980 pp 17ndash27

[7] N Nisse A Salch and V Weber ldquoRecovery of disrupted airline operationsrdquo 2015httphalinriafrSomething

[8] X Wu and R Srikant ldquoRegulated maximal matching A distributed schedulingalgorithm for multi-hop wireless networks with nodeexclusive spectrum sharingrdquo inIEEE Conf on Decision and Control 2005

65

  • Contents
  • Introduction
  • Algorithms
    • Maximum matching
    • k-maximum matching
      • k-matching for Airport Slot assignment
      • The case where k=3
      • The case of Paths
      • The case of the Spider
          • Application
            • Description
            • Reyni Erdos
            • Barabaacutesi Albert
            • Amadeus Graphs
            • Bipartite
            • Bipartite with degree seq
            • Appendix A
              • BipartiteGraphGeneratorpy
              • RandomGraphGeneratorpy
              • kequals3MaximumMatchingpy
              • Plotmat
                  • Bibliography
Page 34: Theodoros Alexandros KARAGKIOULES -  · Introduction This work is the result of a 6 months internship, under the supervision of research O cer Nicolas NISSE. The original scope of

26 Bipartite with degree seq 35

Sorted matching size-Comments

bull Classical matching is equal to perfect matching in every case

bull Constraint and greedy have identical behaviour

bull The larger the spectrum of the degree sequence the more efficient the matching

Sorted Ratios

36 Application

Sorted Ratios-Comments

bull With large initial matching most of the edges are considenred uselles or forced andare removed thus the ratio is close(if not equal to) zero

bull For small matching and large degree sequence sectrum hte max degree remainsthe same Only a few forced edges (and their nodes) are removed apparently nonodes with max degree

Sorted |E||V |

26 Bipartite with degree seq 37

Sorted |E||V | - Comments

bull In these set of figures we witness that the |E||V | acquires values relevant to those ofthe amadeus graphs The random graphs were constructed to depict this similarity

bull For smaller initial matching the ratios for G and G show the same upward trendand also they acquire closer values It repsresent the decrease of the averagenumber of forced edges in comparison to the larger matching cases

Sorted ∆

38 Application

Sorted ∆-Comments

bull Big difference in max degree in large initial matching

bull Almost identical behaviour in the case of small initial matching

Appendix A 39

Appendix A

BipartiteGraphGeneratorpy

from future import divisionimport networkx as nx

from networkxalgorithms import approximationimport collectionsimport randomimport mathfrom networkxalgorithms import bipartiteif name == main

for i in range(1481)waqs 481index=1n=randomrandint(100 1000)

n1=95 was 500me1=118

n2=251 was 500me2=903

n3=165 was 500me3=412

m=0m1=0p=randomrandom()p1=18250p2=25250p3=34250print ip=05t1=randomrandint(0 1)print im2=randomrandint(n2minus1 n2+1)G = nxGraph()ma = nxGraph()

aseq1=[1 2 3 4 5 3]

bseq1=[4 3 3 1 2 2 1]

aseq2=[16 14 14 14 12 11]bseq2=[0 0 0 0 0 0]

aseq3=[8 7 8 8 8 8]bseq3=[0 0 0 0 0 0]

40 Application

print Gnumber of edges()if ilt=160

G=bipartiteconfiguration model(aseq1 bseq1 create using=None seed=None)A=nxadjacency matrix(G)for ii in range(0n1+me1)

maadd node(ii)A=[Rtodense()tolist()[0] for R in A]

printnummanumber of nodes()rl=randomsample(range(0n1+me1) n1+me1)m=0done vertices = set()for p in rlprintin fordone verticesadd(p)

neighbors = []list()for iii in range(0n1+me1)

if A[p][iii]==1neighborsappend(iii)

randomshuffle(neighbors)continue loop = Truedegree = len(neighbors)

print degreej = 0p4=randomrandom()while continue loop and (jltdegree)print in loop

next = neighbors[j]if next not in done vertices and p not in done vertices

done verticesadd(p)done verticesadd(next)if p4gt=07print added edge

maadd edge(pnext)m=m+1

continue loop = Falsej += 1

print matching listOfedgeprint maedge

MA=nxadjacency matrix(ma)print MA

MA=[Rtodense()tolist()[0] for R in MA]print MA

B=[ join(map(strR)) for R in A]MB=[ join(map(strR)) for R in MA]

C=njoin(B)+nMC=njoin(MB)+n

print nprint mprint m1

filea=str(i)+txtwith open(fileaw) as f

Appendix A 41

fwrite(str(n1+me1))fwrite(n)fwrite(str(n1+me1))fwrite(n)fwrite(str(m))fwrite(n)fwrite(n)fwrite(C)fwrite(n)fwrite(MC)

elif igt160 and ilt321G=bipartiteconfiguration model(aseq2 bseq2 create using=None seed=None)A=nxadjacency matrix(G)for ii in range(0n2+me2)

maadd node(ii)A=[Rtodense()tolist()[0] for R in A]

printnummanumber of nodes()rl=randomsample(range(0n2+me2) n2+me2)m=0done vertices = set()for p in rlprintin fordone verticesadd(p)

neighbors = []list()for iii in range(0n2+me2)

if A[p][iii]==1neighborsappend(iii)

randomshuffle(neighbors)continue loop = Truedegree = len(neighbors)

print degreej = 0p4=randomrandom()while continue loop and (jltdegree)

print in loopnext = neighbors[j]if next not in done vertices and p not in done vertices

done verticesadd(p)done verticesadd(next)if p4gt=07

print added edgemaadd edge(pnext)m=m+1

continue loop = Falsej += 1

print matching listOfedgeprint maedge

MA=nxadjacency matrix(ma)print MA

MA=[Rtodense()tolist()[0] for R in MA]print MA

B=[ join(map(strR)) for R in A]MB=[ join(map(strR)) for R in MA]

42 Application

C=njoin(B)+nMC=njoin(MB)+n

print nprint mprint m1

filea=str(i)+txtwith open(fileaw) as f

fwrite(str(n2+me2))fwrite(n)fwrite(str(n2+me2))fwrite(n)fwrite(str(m))fwrite(n)fwrite(n)fwrite(C)fwrite(n)fwrite(MC)

elseG=bipartiteconfiguration model(aseq3 bseq3 create using=None seed=None)A=nxadjacency matrix(G)for ii in range(0n3+me3)

maadd node(ii)A=[Rtodense()tolist()[0] for R in A]

printnummanumber of nodes()rl=randomsample(range(0n3+me3) n3+me3)m=0done vertices = set()for p in rlprintin fordone verticesadd(p)

neighbors = []list()for iii in range(0n3+me3)

if A[p][iii]==1neighborsappend(iii)

randomshuffle(neighbors)continue loop = Truedegree = len(neighbors)

print degreej = 0p4=randomrandom()while continue loop and (jltdegree)

print in loopnext = neighbors[j]if next not in done vertices and p not in done vertices

done verticesadd(p)done verticesadd(next)if p4gt=07print added edge

maadd edge(pnext)m=m+1

continue loop = Falsej += 1

Appendix A 43

print matching listOfedgeprint maedge

MA=nxadjacency matrix(ma)print MA

MA=[Rtodense()tolist()[0] for R in MA]print MA

B=[ join(map(strR)) for R in A]MB=[ join(map(strR)) for R in MA]

C=njoin(B)+nMC=njoin(MB)+n

print nprint mprint m1

filea=str(i)+txtwith open(fileaw) as f

fwrite(str(n3+me3))fwrite(n)fwrite(str(n3+me3))fwrite(n)fwrite(str(m))fwrite(n)fwrite(n)fwrite(C)fwrite(n)fwrite(MC)

print nRandom graphs with random matching have been generated

44 Application

RandomGraphGeneratorpy

from future import divisionimport networkx as nxfrom networkxalgorithms import approximationimport collectionsimport randomimport mathif name == main

for i in range(1481)index=1n=randomrandint(100 1000)

n=1000m=0m1=0p=randomrandom()p1=mathlog(n2)np2=13p3=mathlog(n2)n+01p=05t1=randomrandint(0 1)print im2=randomrandint(n2minus1 n2+1)G = nxGraph()ma = nxGraph()print nme1=randomrandint(1 10)me2=randomrandint(2050)me3=randomrandint(50100)if ilt241

if ilt=80G=nxfast gnp random graph(n p1 seed=None directed=False)

elif igt80 and ilt161G=nxfast gnp random graph(n p2 seed=None directed=False)

elseG=nxfast gnp random graph(n p3 seed=None directed=False)

elseif ilt=320

G=nxbarabasi albert graph(n me1 seed=None)elif igt320 and ilt401

G=nxbarabasi albert graph(n me2 seed=None)else

G=nxbarabasi albert graph(n me3 seed=None)A=nxadjacency matrix(G)for ii in range(0n)

maadd node(ii)A=[Rtodense()tolist()[0] for R in A]

rl=randomsample(range(0n) n)m=0

Appendix A 45

done vertices = set()for p in rl

done verticesadd(p)neighbors = []list()for iii in range(0n)

if A[p][iii]==1neighborsappend(iii)

randomshuffle(neighbors)continue loop = Truedegree = len(neighbors)j = 0p2=randomrandom()while continue loop and (jltdegree)

next = neighbors[j]if next not in done vertices and p not in done vertices

done verticesadd(p)done verticesadd(next)if p2gt=00 Larger probability for smaller initial matching

maadd edge(pnext)m=m+1

continue loop = Falsej += 1

print matching listOfedgeprint maedgeMA=nxadjacency matrix(ma)MA=[Rtodense()tolist()[0] for R in MA]print MAB=[ join(map(strR)) for R in A]MB=[ join(map(strR)) for R in MA]

C=njoin(B)+nMC=njoin(MB)+nprint MCprint nprint mprint m1filea=str(i)+txtwith open(fileaw) as f

fwrite(str(n))fwrite(n)fwrite(str(n))fwrite(n)fwrite(str(m))fwrite(n)fwrite(n)fwrite(C)fwrite(n)fwrite(MC)

print nRandom graphs with random matching have been generated

46 Application

kequals3MaximumMatchingpy

from future import divisionimport networkx as nxfrom networkxalgorithms import bipartiteimport matplotlibpyplot as pltimport collectionsimport timeitimport xlwtimport xlrdimport mathimport sys

Case for General Graphsdef forced edges(Gadj dict2matching dict1num nodesforced)

flagg=0for n in range(0num nodes)

for k in adj dict2[n]if ([k]==matching dict1[n])

count=0for l in range(0num nodes)

count=count+adj dict2[l]count(k)if (len(adj dict2[n])==1) or (count==1)

forcedadd edge(nk)Gremove edge(nk)Gremove node(n)Gremove node(k)printforced edgenktemp=kflagg=1for m in range (len(adj dict2[n])minus1minus1minus1)

adj dict2[adj dict2[n][m]]remove(n)adj dict2[n]remove(adj dict2[n][m])

if adj dict2[temp]for l in range(len(adj dict2[temp])minus1minus1minus1)

if (adj dict2[temp][l]=n)adj dict2[adj dict2[temp][l]]remove(temp)adj dict2[temp]remove(adj dict2[temp][l])

break

def useless edges(num nodesadj dict1matching dict1uselessadj dict2G)for n in range(0num nodes)

for k in adj dict1[n]if ([k]=matching dict1[n]) and matching dict1[n] and matching dict1[k]

uselessadd edge(nk)Gremove edge(n k)

Appendix A 47

tempa=kadj dict2[n]remove(k)adj dict2[tempa]remove(n)adj dict1[tempa]remove(n)

return G

def Greedy(num nodesadj dict3matching dict2)

for n in range(0num nodes)if matching dict2[n]

flag2=minus1flag3=minus1for v in adj dict3[n]

if not matching dict2[v]flag2=vbreak

for p in adj dict3[matching dict2[n][0]]if not matching dict2[p]

flag3=pbreak

if (flag2=minus1) and (flag3=minus1) and (flag2=flag3)tempr=matching dict2[n][0]matching dict2[n]=[flag2]matching dict2[flag2]=[n]matching dict2[tempr]=[flag3]matching dict2[flag3]=[tempr]

elsefor k in adj dict3[n]

if not matching dict2[k]matching dict2[n]=[k]matching dict2[k]=[n]break

yo1=0for i in range(0num nodes)

if matching dict2[i] and [i]==matching dict2[matching dict2[i][0]]yo1=yo1+1

greedy size=yo12return greedy size

def General()

INPUTSwb = xlwtWorkbook()ws = wbadd sheet(Results Random)book=xlrdopen workbook(filenames randomxls)

48 Application

style0 = xlwteasyxf(fontbold on)style1 = xlwteasyxf(num format str=0000)INPUTSwswrite(0 0File style0)wswrite(0 1 Nodesstyle0)wswrite(0 2 Initial matchingstyle0)wswrite(0 3 NodesGstyle0)wswrite(0 4 EdgesGstyle0)wswrite(0 5 MaxDegreeGstyle0)wswrite(0 6 NodesG hatstyle0)wswrite(0 7 EdgesG Hatstyle0)wswrite(0 8 Useless edgesstyle0)wswrite(0 9 Forced edgesstyle0)wswrite(0 10 MaxDegreeG Hatstyle0)wswrite(0 11 Classical matchingstyle0)wswrite(0 12 Final matchingstyle0)wswrite(0 13 Greedy matchingstyle0)wswrite(0 14 Time classicalstyle0)wswrite(0 15 Time algorithmstyle0)wswrite(0 16 Time greedystyle0)wswrite(0 17 Perfect matching ratiostyle0)wswrite(0 18 Nodes ratiostyle0)wswrite(0 19 Edges ratiostyle0)wswrite(0 20 Matching ratiostyle0)

print nWelcomeThis is an implementation for general random graphs It uses Edmonds algorithm to compute maximum matching on G Hatn

for index in range (1481)was 481

if (index==482)f=open(Algotel generaltxtr)readlines()

elsefilea=str(booksheet by index(0)cell(index0))s=fileareplace(textu)replace()f=open(sr)readlines()Truewswrite(index 0 s)

print index

num nodes=int([xstrip()split() for x in f][0][0])

num matching=int([xstrip()split() for x in f][2][0])

adj temp = [xstrip()split() for x in f][44+num nodes]adj=[map(intR) for R in adj temp]

matching temp=[xstrip()split() for x in f][4+num nodes+14+2num nodes+1]matching1=[map(intR) for R in matching temp]

adj dict1=i[ii for iix in enumerate(L) if x] for iL in enumerate(adj)adj dict2=i[ii for iix in enumerate(L) if x] for iL in enumerate(adj)

Appendix A 49

adj dict3=i[ii for iix in enumerate(L) if x] for iL in enumerate(adj)

matching dict1=i[ii for iix in enumerate(L) if x] for iL in enumerate(matching1)matching dict2=i[ii for iix in enumerate(L) if x] for iL in enumerate(matching1)print adj dict2print matching dict2wswrite(index 1 num nodes)wswrite(index 2 num matching)

G = nxGraph()

useless= nxGraph()forced = nxGraph()

Fill Graphfor n in range(0num nodes)

for k in adj dict1[n]Gadd edge(nk)

Gt=Gnumber of edges()wswrite(index 3 Gnumber of nodes())wswrite(index 4 Gnumber of edges())wswrite(index 5 max(Gdegree()values()))

Compute Edmonds classical matching on G for comparison

startB = timeitdefault timer()Classical Matching=nxmax weight matching(G maxcardinality=False)stopB = timeitdefault timer()

Compute Gˆ nad MˆstartC = timeitdefault timer()useless edges(num nodesadj dict1matching dict1uselessadj dict2G)forced edges(Gadj dict2matching dict1num nodesforced)Final Matching=nxmax weight matching(G maxcardinality=False)stopC = timeitdefault timer()

GreedystartG = timeitdefault timer()greedy size=Greedy(num nodesadj dict3matching dict2)stopG = timeitdefault timer()

wswrite(index 6 Gnumber of nodes())wswrite(index 7 Gnumber of edges())wswrite(index 8 uselessnumber of edges())wswrite(index 9 forcednumber of edges())if Gdegree()values()

wswrite(index 10 max(Gdegree()values()))else

50 Application

wswrite(index 10 0)wswrite(index 11 len(Classical Matching)2)wswrite(index 12 len(Final Matching)2+forcednumber of edges())wswrite(index 13 greedy size)wswrite(index 14 stopB minus startBstyle1)wswrite(index 15 stopC minus startCstyle1)wswrite(index 16 stopG minus startGstyle1)wswrite(index 17 (len(Final Matching)2+forcednumber of edges())(num nodes2)style1)wswrite(index 18 Gnumber of nodes()Gtstyle1)wswrite(index 19 Gnumber of edges()Gtstyle1)wswrite(index 20 (len(Final Matching)2+forcednumber of edges())(len(Classical Matching)2)style1)

wbsave(AA Results Random Reyni Large Bipartitexls)

Main function Here we must choose the input form of the dataif name == main

startA = timeitdefault timer()General()stopA = timeitdefault timer()

print nThis program has terminatednnRunning time for 480 files stopAminusstartAprint nnPlease open AA Results Random Reyni Largexls file to see the Results

Appendix A 51

Plotmat

clear allclose allload(RN1Lmat)load(RN1Smat)load(RN2Lmat)load(RN2Smat)load(RN3Lmat)load(RN3Smat)

Plotsh(1)=figure(NameHistogram of Matching size difference between Constraint Algorithm and Greedy AlgorithmNumberTitleoff)

RN1L Greedydiff=RN1L Final matchingminusRN1L Greedy matchingRN2L Greedydiff=RN2L Final matchingminusRN2L Greedy matchingRN3L Greedydiff=RN3L Final matchingminusRN3L Greedy matchingRN1S Greedydiff=RN1S Final matchingminusRN1S Greedy matchingRN2S Greedydiff=RN2S Final matchingminusRN2S Greedy matchingRN3S Greedydiff=RN3S Final matchingminusRN3S Greedy matching

RN1L Finaldiff=RN1L Classical matchingminusRN1L Final matchingRN2L Finaldiff=RN2L Classical matchingminusRN2L Final matchingRN3L Finaldiff=RN3L Classical matchingminusRN3L Final matchingRN1S Finaldiff=RN1S Classical matchingminusRN1S Final matchingRN2S Finaldiff=RN2S Classical matchingminusRN2S Final matchingRN3S Finaldiff=RN3S Classical matchingminusRN3S Final matching

RN1L Classicaldiff=(RN1L Nodes2)minusRN1L Classical matchingRN2L Classicaldiff=(RN2L Nodes2)minusRN2L Classical matchingRN3L Classicaldiff=(RN3L Nodes2)minusRN3L Classical matchingRN1S Classicaldiff=(RN1S Nodes2)minusRN1S Classical matchingRN2S Classicaldiff=(RN2S Nodes2)minusRN2S Classical matchingRN3S Classicaldiff=(RN3S Nodes2)minusRN3S Classical matching

subplot(231)hold onhistf(RN1L Greedydiff0110facecolorbfacealpha9edgealpha1)histf(RN1L Finaldiff0110facecolorrfacealpha5edgealpha1)histf(RN1L Classicaldiff0110facecolorgfacealpha5edgealpha1)legalpha(ConminusGreClasminusConPerfminusClasslocationnortheast)legend boxoffaxis tightxlabel(edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN1L)grid on

subplot(232)hold onhistf(RN2L Greedydiff0110facecolorbfacealpha9edgealpha1)

52 Application

histf(RN2L Finaldiff0110facecolorrfacealpha5edgealpha1)histf(RN2L Classicaldiff0110facecolorgfacealpha5edgealpha1)legalpha(ConminusGreClasminusConPerfminusClasslocationnortheast)legend boxoffaxis tightxlabel(edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN2L)grid on

subplot(233)hold onhistf(RN3L Greedydiff0110facecolorbfacealpha5edgealpha1)histf(RN3L Finaldiff0110facecolorrfacealpha5edgealpha1)histf(RN3L Classicaldiff0110facecolorgfacealpha5edgealpha1)legalpha(ConminusGreClasminusConPerfminusClasslocationnortheast)legend boxoffaxis tightxlabel(edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN3L)grid on

subplot(234)hold onhistf(RN1S Greedydiff0110facecolorbfacealpha5edgealpha1)histf(RN1S Finaldiff0110facecolorrfacealpha5edgealpha1)histf(RN1S Classicaldiff0110facecolorgfacealpha5edgealpha1)legalpha(ConminusGreClasminusConPerfminusClasslocationnortheast)legend boxoffaxis tightxlabel(edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(R1NS)grid on

subplot(235)hold onhistf(RN2S Greedydiff0110facecolorbfacealpha5edgealpha1)histf(RN2S Finaldiff0110facecolorrfacealpha5edgealpha1)histf(RN2S Classicaldiff0110facecolorgfacealpha5edgealpha1)legalpha(ConminusGreClasminusConPerfminusClasslocationnortheast)legend boxoffaxis tightxlabel(edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN2S)grid on

subplot(236)hold onhistf(RN3S Greedydiff0110facecolorbfacealpha5edgealpha1)histf(RN3S Finaldiff0110facecolorrfacealpha5edgealpha1)histf(RN3S Classicaldiff0110facecolorgfacealpha5edgealpha1)

Appendix A 53

legalpha(ConminusGreClasminusConPerfminusClasslocationnortheast)legend boxoffaxis tightgrid ontitle(RN3S)xlabel(edges) xminusaxis labelylabel(instances) yminusaxis labelset(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN1png minusr300)h(2)=figure(NameHistogram of Max Degree of G AND G HatNumberTitleoff)RN1L x=RN1L MaxDegreeGminusRN1L MaxDegreeG HatRN2L x=RN2L MaxDegreeGminusRN2L MaxDegreeG HatRN3L x=RN3L MaxDegreeGminusRN3L MaxDegreeG HatRN1S x=RN1S MaxDegreeGminusRN1S MaxDegreeG HatRN2S x=RN2S MaxDegreeGminusRN2S MaxDegreeG HatRN3S x=RN3S MaxDegreeGminusRN3S MaxDegreeG Hatsubplot(231)hold onhistf(RN1L MaxDegreeG0150facecolorbfacealpha5edgealpha1)histf(RN1L MaxDegreeG Hat0150facecolorrfacealpha5edgealpha1)histf(RN1L x0150facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightxlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN1L)grid on

subplot(232)hold onhistf(RN2L MaxDegreeG010500facecolorbfacealpha5edgealpha1)histf(RN2L MaxDegreeG Hat010500facecolorrfacealpha5edgealpha1)histf(RN2L x010500facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightxlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN2L)grid on

subplot(233)hold onhistf(RN3L MaxDegreeG010300facecolorbfacealpha5edgealpha1)histf(RN3L MaxDegreeG Hat010300facecolorrfacealpha5edgealpha1)histf(RN3L x010300facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightxlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN3L)

54 Application

grid on

subplot(234)hold onhistf(RN1S MaxDegreeG0150facecolorbfacealpha5edgealpha1)histf(RN1S MaxDegreeG Hat0150facecolorrfacealpha5edgealpha1)histf(RN1S x0150facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightxlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(R1NS)grid on

subplot(235)hold onhistf(RN2S MaxDegreeG010500facecolorbfacealpha5edgealpha1)histf(RN2S MaxDegreeG Hat010500facecolorrfacealpha5edgealpha1)histf(RN2S x010500facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightxlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN2S)grid on

subplot(236)hold onhistf(RN3S MaxDegreeG05300facecolorbfacealpha5edgealpha1)histf(RN3S MaxDegreeG Hat05300facecolorrfacealpha5edgealpha1)histf(RN3S x05300facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightgrid ontitle(RN3S)xlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labelset(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN2png minusr300)

h(3)=figure(NameComputation time over edgesNumberTitleoff)

subplot(231)hold onstem(RN1L EdgesGRN1L Time classicalg)stem(RN1L EdgesGRN1L Time algorithmro)stem(RN1L EdgesGRN1L Time greedybx)grid on

Appendix A 55

title(RN1L)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)

subplot(232)hold onstem(RN2L EdgesGRN2L Time classicalg)stem(RN2L EdgesGRN2L Time algorithmro)stem(RN2L EdgesGRN2L Time greedybx)grid ontitle(RN2L)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)

subplot(233)hold onstem(RN3L EdgesGRN3L Time classicalg)stem(RN3L EdgesGRN3L Time algorithmro)stem(RN3L EdgesGRN3L Time greedybx)grid ontitle(RN3L)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)

subplot(234)hold onstem(RN1S EdgesGRN1S Time classicalg)stem(RN1S EdgesGRN1S Time algorithmro)stem(RN1S EdgesGRN1S Time greedybx)grid ontitle(RN1S)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)

subplot(235)hold onstem(RN2S EdgesGRN2S Time classicalg)stem(RN2S EdgesGRN2S Time algorithmro)stem(RN2S EdgesGRN2S Time greedybx)grid ontitle(RN2S)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)

subplot(236)hold onstem(RN3S EdgesGRN3S Time classicalg)stem(RN3S EdgesGRN3S Time algorithmro)stem(RN3S EdgesGRN3S Time greedybx)

56 Application

grid ontitle(RN3S)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)set(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN3png minusr300)

h(4)=figure(NameSorted matching sizeNumberTitleoff)RN1L Sorted matching temp(1)=RN1L Classical matchingRN1L Sorted matching temp(2)=RN1L Final matchingRN1L Sorted matching temp(3)=RN1L Greedy matchingRN1L Sorted matching temp(4)=RN1L Initial matchingRN1L Sorted matching=sortrows(RN1L Sorted matching temp)

RN2L Sorted matching temp(1)=RN2L Classical matchingRN2L Sorted matching temp(2)=RN2L Final matchingRN2L Sorted matching temp(3)=RN2L Greedy matchingRN2L Sorted matching temp(4)=RN2L Initial matchingRN2L Sorted matching=sortrows(RN2L Sorted matching temp)

RN3L Sorted matching temp(1)=RN3L Classical matchingRN3L Sorted matching temp(2)=RN3L Final matchingRN3L Sorted matching temp(3)=RN3L Greedy matchingRN3L Sorted matching temp(4)=RN3L Initial matchingRN3L Sorted matching=sortrows(RN3L Sorted matching temp)

RN1S Sorted matching temp(1)=RN1S Classical matchingRN1S Sorted matching temp(2)=RN1S Final matchingRN1S Sorted matching temp(3)=RN1S Greedy matchingRN1S Sorted matching temp(4)=RN1S Initial matchingRN1S Sorted matching=sortrows(RN1S Sorted matching temp)

RN2S Sorted matching temp(1)=RN2S Classical matchingRN2S Sorted matching temp(2)=RN2S Final matchingRN2S Sorted matching temp(3)=RN2S Greedy matchingRN2S Sorted matching temp(4)=RN2S Initial matchingRN2S Sorted matching=sortrows(RN2S Sorted matching temp)

RN3S Sorted matching temp(1)=RN3S Classical matchingRN3S Sorted matching temp(2)=RN3S Final matchingRN3S Sorted matching temp(3)=RN3S Greedy matchingRN3S Sorted matching temp(4)=RN3S Initial matchingRN3S Sorted matching=sortrows(RN3S Sorted matching temp)

subplot(231)hold onplot(RN1L Sorted matching(1)b)plot(RN1L Sorted matching(2)g)plot(RN1L Sorted matching(3)r)plot(RN1L Sorted matching(4)m)

Appendix A 57

grid ontitle(RN1L)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)

subplot(232)hold onplot(RN2L Sorted matching(1)b)plot(RN2L Sorted matching(2)g)plot(RN2L Sorted matching(3)r)plot(RN2L Sorted matching(4)m)grid ontitle(RN2L)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)

subplot(233)hold onplot(RN3L Sorted matching(1)b)plot(RN3L Sorted matching(2)g)plot(RN3L Sorted matching(3)r)plot(RN3L Sorted matching(4)m)grid ontitle(RN3L)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)

subplot(234)hold onplot(RN1S Sorted matching(1)b)plot(RN1S Sorted matching(2)g)plot(RN1S Sorted matching(3)r)plot(RN1S Sorted matching(4)m)grid ontitle(RN1S)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)

subplot(235)hold onplot(RN2S Sorted matching(1)b)plot(RN2S Sorted matching(2)g)plot(RN2S Sorted matching(3)r)plot(RN2S Sorted matching(4)m)grid ontitle(RN2S)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)

58 Application

subplot(236)hold onplot(RN3S Sorted matching(1)b)plot(RN3S Sorted matching(2)g)plot(RN3S Sorted matching(3)r)plot(RN3S Sorted matching(4)m)grid ontitle(RN3S)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)set(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN4png minusr300)h(5)=figure(NameSorted RatiosNumberTitleoff)RN1L ratio1=RN1L NodesG hatRN1L NodesGRN2L ratio1=RN2L NodesG hatRN2L NodesGRN3L ratio1=RN3L NodesG hatRN3L NodesGRN1S ratio1=RN1S NodesG hatRN1S NodesGRN2S ratio1=RN2S NodesG hatRN2S NodesGRN3S ratio1=RN3S NodesG hatRN3S NodesG

RN1L ratio2=RN1L EdgesG HatRN1L EdgesGRN2L ratio2=RN2L EdgesG HatRN2L EdgesGRN3L ratio2=RN3L EdgesG HatRN3L EdgesGRN1S ratio2=RN1S EdgesG HatRN1S EdgesGRN2S ratio2=RN2S EdgesG HatRN2S EdgesGRN3S ratio2=RN3S EdgesG HatRN3S EdgesG

RN1L ratio3=RN1L MaxDegreeG HatRN1L MaxDegreeGRN2L ratio3=RN2L MaxDegreeG HatRN2L MaxDegreeGRN3L ratio3=RN3L MaxDegreeG HatRN3L MaxDegreeGRN1S ratio3=RN1S MaxDegreeG HatRN1S MaxDegreeGRN2S ratio3=RN2S MaxDegreeG HatRN2S MaxDegreeGRN3S ratio3=RN3S MaxDegreeG HatRN3S MaxDegreeG

RN1L ratio(1)=RN1L ratio1RN1L ratio(2)=RN1L ratio2RN1L ratio(3)=RN1L ratio3

RN2L ratio(1)=RN2L ratio1RN2L ratio(2)=RN2L ratio2RN2L ratio(3)=RN2L ratio3

RN3L ratio(1)=RN3L ratio1RN3L ratio(2)=RN3L ratio2RN3L ratio(3)=RN3L ratio3

RN1S ratio(1)=RN1S ratio1RN1S ratio(2)=RN1S ratio2RN1S ratio(3)=RN1S ratio3

RN2S ratio(1)=RN2S ratio1

Appendix A 59

RN2S ratio(2)=RN2S ratio2RN2S ratio(3)=RN2S ratio3

RN3S ratio(1)=RN3S ratio1RN3S ratio(2)=RN3S ratio2RN3S ratio(3)=RN3S ratio3

RN1L ratio sorted=sortrows(RN1L ratio)RN2L ratio sorted=sortrows(RN2L ratio)RN3L ratio sorted=sortrows(RN3L ratio)RN1S ratio sorted=sortrows(RN1S ratio)RN2S ratio sorted=sortrows(RN2S ratio)RN3S ratio sorted=sortrows(RN3S ratio)

subplot(231)hold onplot(RN1L ratio sorted(1)b)plot(RN1L ratio sorted(2)g)plot(RN1L ratio sorted(3)r)grid ontitle(RN1L)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)

subplot(232)hold onplot(RN2L ratio sorted(1)b)plot(RN2L ratio sorted(2)g)plot(RN2L ratio sorted(3)r)grid ontitle(RN2L)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)

subplot(233)hold onplot(RN3L ratio sorted(1)b)plot(RN3L ratio sorted(2)g)plot(RN3L ratio sorted(3)r)grid ontitle(RN3L)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)

subplot(234)hold onplot(RN1S ratio sorted(1)b)plot(RN1S ratio sorted(2)g)plot(RN1S ratio sorted(3)r)grid on

60 Application

title(RN1S)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)

subplot(235)hold onplot(RN2S ratio sorted(1)b)plot(RN2S ratio sorted(2)g)plot(RN2S ratio sorted(3)r)grid ontitle(RN2S)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)

subplot(236)hold onplot(RN3S ratio sorted(1)b)plot(RN3S ratio sorted(2)g)plot(RN3S ratio sorted(3)r)grid ontitle(RN3S)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)set(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN5png minusr300)

h(6)=figure(NameSorted edges over nodesNumberTitleoff)

RN1L DegreeG1=(RN1L EdgesG)(RN1L NodesG)RN1L DegreeG Hat1=(RN1L EdgesG Hat)(RN1L NodesG hat)

RN1L Degree temp1(1)=RN1L DegreeG1RN1L Degree temp1(2)=RN1L DegreeG Hat1RN1L Degree sorted1=sortrows(RN1L Degree temp1)subplot(231)hold on

plot(RN1L Degree sorted1(1)b)plot(RN1L Degree sorted1(2)g)grid ontitle(RN1L)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)

RN2L DegreeG1=(RN2L EdgesG)(RN2L NodesG)RN2L DegreeG Hat1=(RN2L EdgesG Hat)(RN2L NodesG hat)

RN2L Degree temp1(1)=RN2L DegreeG1

Appendix A 61

RN2L Degree temp1(2)=RN2L DegreeG Hat1RN2L Degree sorted1=sortrows(RN2L Degree temp1)

subplot(232)hold onplot(RN2L Degree sorted1(1)b)plot(RN2L Degree sorted1(2)g)grid ontitle(RN2L)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)

RN3L DegreeG1=(RN3L EdgesG)(RN3L NodesG)RN3L DegreeG Hat1=(RN3L EdgesG Hat)(RN3L NodesG hat)

RN3L Degree temp1(1)=RN3L DegreeG1RN3L Degree temp1(2)=RN3L DegreeG Hat1RN3L Degree sorted1=sortrows(RN3L Degree temp1)

subplot(233)hold onplot(RN3L Degree sorted1(1)b)plot(RN3L Degree sorted1(2)g)grid ontitle(RN3L)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)

RN1S DegreeG1=(RN1S EdgesG)(RN1S NodesG)RN1S DegreeG Hat1=(RN1S EdgesG Hat)(RN1S NodesG hat)

RN1S Degree temp1(1)=RN1S DegreeG1RN1S Degree temp1(2)=RN1S DegreeG Hat1RN1S Degree sorted1=sortrows(RN1S Degree temp1)

subplot(234)hold onplot(RN1S Degree sorted1(1)b)plot(RN1S Degree sorted1(2)g)grid ontitle(RN1S)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)

RN2S DegreeG1=(RN2S EdgesG)(RN2S NodesG)RN2S DegreeG Hat1=(RN2S EdgesG Hat)(RN2S NodesG hat)

RN2S Degree temp1(1)=RN2S DegreeG1

62 Application

RN2S Degree temp1(2)=RN2S DegreeG Hat1RN2S Degree sorted1=sortrows(RN2S Degree temp1)

subplot(235)hold onplot(RN2S Degree sorted1(1)b)plot(RN2S Degree sorted1(2)g)grid ontitle(RN2S)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)

RN3S DegreeG1=(RN3S EdgesG)(RN3S NodesG)RN3S DegreeG Hat1=(RN3S EdgesG Hat)(RN3S NodesG hat)

RN3S Degree temp1(1)=RN3S DegreeG1RN3S Degree temp1(2)=RN3S DegreeG Hat1RN3S Degree sorted1=sortrows(RN3S Degree temp1)

subplot(236)hold onplot(RN3S Degree sorted1(1)b)plot(RN3S Degree sorted1(2)g)grid ontitle(RN3S)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)set(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN6png minusr300)h(7)=figure(NameSorted mATCHED DEGREENumberTitleoff)RN1L ratioMax(1)=RN1L MaxDegreeGRN1L ratioMax(2)=RN1L MaxDegreeG Hat

RN1L ratio sortedMax=sortrows(RN1L ratioMax)subplot(231)hold onplot(RN1L ratio sortedMax(1)b)plot(RN1L ratio sortedMax(2)g)grid ontitle(RN1L)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)

RN2L ratioMax(1)=RN2L MaxDegreeGRN2L ratioMax(2)=RN2L MaxDegreeG Hat

RN2L ratio sortedMax=sortrows(RN2L ratioMax)subplot(232)

Appendix A 63

hold onplot(RN2L ratio sortedMax(1)b)plot(RN2L ratio sortedMax(2)g)grid ontitle(RN2L)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)

RN3L ratioMax(1)=RN3L MaxDegreeGRN3L ratioMax(2)=RN3L MaxDegreeG Hat

RN3L ratio sortedMax=sortrows(RN3L ratioMax)subplot(233)hold onplot(RN3L ratio sortedMax(1)b)plot(RN3L ratio sortedMax(2)g)grid ontitle(RN3L)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)

RN1S ratioMax(1)=RN1S MaxDegreeGRN1S ratioMax(2)=RN1S MaxDegreeG Hat

RN1S ratio sortedMax=sortrows(RN1S ratioMax)subplot(234)hold onplot(RN1S ratio sortedMax(1)b)plot(RN1S ratio sortedMax(2)g)grid ontitle(RN1S)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)

RN2S ratioMax(1)=RN2S MaxDegreeGRN2S ratioMax(2)=RN2S MaxDegreeG Hat

RN2S ratio sortedMax=sortrows(RN2S ratioMax)

subplot(235)hold onplot(RN2S ratio sortedMax(1)b)plot(RN2S ratio sortedMax(2)g)grid ontitle(RN2S)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)

RN3S ratioMax(1)=RN3S MaxDegreeGRN3S ratioMax(2)=RN3S MaxDegreeG Hat

64 Application

RN3S ratio sortedMax=sortrows(RN3S ratioMax)subplot(236)hold onplot(RN3S ratio sortedMax(1)b)plot(RN3S ratio sortedMax(2)g)grid ontitle(RN1L)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)set(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN7png minusr300)

tilefigs()(h)

Bibliography

[1] C Berge ldquoTWO THEOREMS IN GRAPH THEORYrdquo Proceedings of the NationalAcademy of Sciences of the United States of America vol 43 no 9 pp 842ndash844Sep 1957

[2] L Bui S Sanghavi and R Srikant ldquoDistributed link scheduling with constantoverheadrdquo IEEEACM Trans Netw vol 17 no 5 pp 1467ndash1480 2009

[3] R Duan and S Pettie ldquoLinear-time approximation for maximum weight matchingrdquoJ ACM vol 61 no 1 2014

[4] J Edmonds ldquoPaths trees and flowersrdquo Canadian Journal of Mathematics vol 17pp 449ndash467 1965

[5] J E Hopcroft and R M Karp ldquoAn n52 algorithm for maximum matchings inbipartite graphsrdquo SIAM J Comput vol 2 no 4 pp 225ndash231 1973

[6] S Micali and V V Vazirani ldquoAn O(radic|V ||E|) algorithm for finding maximum

matching in general graphsrdquo in 21st Symp on Foundations of Comp Sc (FOCS)IEEE 1980 pp 17ndash27

[7] N Nisse A Salch and V Weber ldquoRecovery of disrupted airline operationsrdquo 2015httphalinriafrSomething

[8] X Wu and R Srikant ldquoRegulated maximal matching A distributed schedulingalgorithm for multi-hop wireless networks with nodeexclusive spectrum sharingrdquo inIEEE Conf on Decision and Control 2005

65

  • Contents
  • Introduction
  • Algorithms
    • Maximum matching
    • k-maximum matching
      • k-matching for Airport Slot assignment
      • The case where k=3
      • The case of Paths
      • The case of the Spider
          • Application
            • Description
            • Reyni Erdos
            • Barabaacutesi Albert
            • Amadeus Graphs
            • Bipartite
            • Bipartite with degree seq
            • Appendix A
              • BipartiteGraphGeneratorpy
              • RandomGraphGeneratorpy
              • kequals3MaximumMatchingpy
              • Plotmat
                  • Bibliography
Page 35: Theodoros Alexandros KARAGKIOULES -  · Introduction This work is the result of a 6 months internship, under the supervision of research O cer Nicolas NISSE. The original scope of

36 Application

Sorted Ratios-Comments

bull With large initial matching most of the edges are considenred uselles or forced andare removed thus the ratio is close(if not equal to) zero

bull For small matching and large degree sequence sectrum hte max degree remainsthe same Only a few forced edges (and their nodes) are removed apparently nonodes with max degree

Sorted |E||V |

26 Bipartite with degree seq 37

Sorted |E||V | - Comments

bull In these set of figures we witness that the |E||V | acquires values relevant to those ofthe amadeus graphs The random graphs were constructed to depict this similarity

bull For smaller initial matching the ratios for G and G show the same upward trendand also they acquire closer values It repsresent the decrease of the averagenumber of forced edges in comparison to the larger matching cases

Sorted ∆

38 Application

Sorted ∆-Comments

bull Big difference in max degree in large initial matching

bull Almost identical behaviour in the case of small initial matching

Appendix A 39

Appendix A

BipartiteGraphGeneratorpy

from future import divisionimport networkx as nx

from networkxalgorithms import approximationimport collectionsimport randomimport mathfrom networkxalgorithms import bipartiteif name == main

for i in range(1481)waqs 481index=1n=randomrandint(100 1000)

n1=95 was 500me1=118

n2=251 was 500me2=903

n3=165 was 500me3=412

m=0m1=0p=randomrandom()p1=18250p2=25250p3=34250print ip=05t1=randomrandint(0 1)print im2=randomrandint(n2minus1 n2+1)G = nxGraph()ma = nxGraph()

aseq1=[1 2 3 4 5 3]

bseq1=[4 3 3 1 2 2 1]

aseq2=[16 14 14 14 12 11]bseq2=[0 0 0 0 0 0]

aseq3=[8 7 8 8 8 8]bseq3=[0 0 0 0 0 0]

40 Application

print Gnumber of edges()if ilt=160

G=bipartiteconfiguration model(aseq1 bseq1 create using=None seed=None)A=nxadjacency matrix(G)for ii in range(0n1+me1)

maadd node(ii)A=[Rtodense()tolist()[0] for R in A]

printnummanumber of nodes()rl=randomsample(range(0n1+me1) n1+me1)m=0done vertices = set()for p in rlprintin fordone verticesadd(p)

neighbors = []list()for iii in range(0n1+me1)

if A[p][iii]==1neighborsappend(iii)

randomshuffle(neighbors)continue loop = Truedegree = len(neighbors)

print degreej = 0p4=randomrandom()while continue loop and (jltdegree)print in loop

next = neighbors[j]if next not in done vertices and p not in done vertices

done verticesadd(p)done verticesadd(next)if p4gt=07print added edge

maadd edge(pnext)m=m+1

continue loop = Falsej += 1

print matching listOfedgeprint maedge

MA=nxadjacency matrix(ma)print MA

MA=[Rtodense()tolist()[0] for R in MA]print MA

B=[ join(map(strR)) for R in A]MB=[ join(map(strR)) for R in MA]

C=njoin(B)+nMC=njoin(MB)+n

print nprint mprint m1

filea=str(i)+txtwith open(fileaw) as f

Appendix A 41

fwrite(str(n1+me1))fwrite(n)fwrite(str(n1+me1))fwrite(n)fwrite(str(m))fwrite(n)fwrite(n)fwrite(C)fwrite(n)fwrite(MC)

elif igt160 and ilt321G=bipartiteconfiguration model(aseq2 bseq2 create using=None seed=None)A=nxadjacency matrix(G)for ii in range(0n2+me2)

maadd node(ii)A=[Rtodense()tolist()[0] for R in A]

printnummanumber of nodes()rl=randomsample(range(0n2+me2) n2+me2)m=0done vertices = set()for p in rlprintin fordone verticesadd(p)

neighbors = []list()for iii in range(0n2+me2)

if A[p][iii]==1neighborsappend(iii)

randomshuffle(neighbors)continue loop = Truedegree = len(neighbors)

print degreej = 0p4=randomrandom()while continue loop and (jltdegree)

print in loopnext = neighbors[j]if next not in done vertices and p not in done vertices

done verticesadd(p)done verticesadd(next)if p4gt=07

print added edgemaadd edge(pnext)m=m+1

continue loop = Falsej += 1

print matching listOfedgeprint maedge

MA=nxadjacency matrix(ma)print MA

MA=[Rtodense()tolist()[0] for R in MA]print MA

B=[ join(map(strR)) for R in A]MB=[ join(map(strR)) for R in MA]

42 Application

C=njoin(B)+nMC=njoin(MB)+n

print nprint mprint m1

filea=str(i)+txtwith open(fileaw) as f

fwrite(str(n2+me2))fwrite(n)fwrite(str(n2+me2))fwrite(n)fwrite(str(m))fwrite(n)fwrite(n)fwrite(C)fwrite(n)fwrite(MC)

elseG=bipartiteconfiguration model(aseq3 bseq3 create using=None seed=None)A=nxadjacency matrix(G)for ii in range(0n3+me3)

maadd node(ii)A=[Rtodense()tolist()[0] for R in A]

printnummanumber of nodes()rl=randomsample(range(0n3+me3) n3+me3)m=0done vertices = set()for p in rlprintin fordone verticesadd(p)

neighbors = []list()for iii in range(0n3+me3)

if A[p][iii]==1neighborsappend(iii)

randomshuffle(neighbors)continue loop = Truedegree = len(neighbors)

print degreej = 0p4=randomrandom()while continue loop and (jltdegree)

print in loopnext = neighbors[j]if next not in done vertices and p not in done vertices

done verticesadd(p)done verticesadd(next)if p4gt=07print added edge

maadd edge(pnext)m=m+1

continue loop = Falsej += 1

Appendix A 43

print matching listOfedgeprint maedge

MA=nxadjacency matrix(ma)print MA

MA=[Rtodense()tolist()[0] for R in MA]print MA

B=[ join(map(strR)) for R in A]MB=[ join(map(strR)) for R in MA]

C=njoin(B)+nMC=njoin(MB)+n

print nprint mprint m1

filea=str(i)+txtwith open(fileaw) as f

fwrite(str(n3+me3))fwrite(n)fwrite(str(n3+me3))fwrite(n)fwrite(str(m))fwrite(n)fwrite(n)fwrite(C)fwrite(n)fwrite(MC)

print nRandom graphs with random matching have been generated

44 Application

RandomGraphGeneratorpy

from future import divisionimport networkx as nxfrom networkxalgorithms import approximationimport collectionsimport randomimport mathif name == main

for i in range(1481)index=1n=randomrandint(100 1000)

n=1000m=0m1=0p=randomrandom()p1=mathlog(n2)np2=13p3=mathlog(n2)n+01p=05t1=randomrandint(0 1)print im2=randomrandint(n2minus1 n2+1)G = nxGraph()ma = nxGraph()print nme1=randomrandint(1 10)me2=randomrandint(2050)me3=randomrandint(50100)if ilt241

if ilt=80G=nxfast gnp random graph(n p1 seed=None directed=False)

elif igt80 and ilt161G=nxfast gnp random graph(n p2 seed=None directed=False)

elseG=nxfast gnp random graph(n p3 seed=None directed=False)

elseif ilt=320

G=nxbarabasi albert graph(n me1 seed=None)elif igt320 and ilt401

G=nxbarabasi albert graph(n me2 seed=None)else

G=nxbarabasi albert graph(n me3 seed=None)A=nxadjacency matrix(G)for ii in range(0n)

maadd node(ii)A=[Rtodense()tolist()[0] for R in A]

rl=randomsample(range(0n) n)m=0

Appendix A 45

done vertices = set()for p in rl

done verticesadd(p)neighbors = []list()for iii in range(0n)

if A[p][iii]==1neighborsappend(iii)

randomshuffle(neighbors)continue loop = Truedegree = len(neighbors)j = 0p2=randomrandom()while continue loop and (jltdegree)

next = neighbors[j]if next not in done vertices and p not in done vertices

done verticesadd(p)done verticesadd(next)if p2gt=00 Larger probability for smaller initial matching

maadd edge(pnext)m=m+1

continue loop = Falsej += 1

print matching listOfedgeprint maedgeMA=nxadjacency matrix(ma)MA=[Rtodense()tolist()[0] for R in MA]print MAB=[ join(map(strR)) for R in A]MB=[ join(map(strR)) for R in MA]

C=njoin(B)+nMC=njoin(MB)+nprint MCprint nprint mprint m1filea=str(i)+txtwith open(fileaw) as f

fwrite(str(n))fwrite(n)fwrite(str(n))fwrite(n)fwrite(str(m))fwrite(n)fwrite(n)fwrite(C)fwrite(n)fwrite(MC)

print nRandom graphs with random matching have been generated

46 Application

kequals3MaximumMatchingpy

from future import divisionimport networkx as nxfrom networkxalgorithms import bipartiteimport matplotlibpyplot as pltimport collectionsimport timeitimport xlwtimport xlrdimport mathimport sys

Case for General Graphsdef forced edges(Gadj dict2matching dict1num nodesforced)

flagg=0for n in range(0num nodes)

for k in adj dict2[n]if ([k]==matching dict1[n])

count=0for l in range(0num nodes)

count=count+adj dict2[l]count(k)if (len(adj dict2[n])==1) or (count==1)

forcedadd edge(nk)Gremove edge(nk)Gremove node(n)Gremove node(k)printforced edgenktemp=kflagg=1for m in range (len(adj dict2[n])minus1minus1minus1)

adj dict2[adj dict2[n][m]]remove(n)adj dict2[n]remove(adj dict2[n][m])

if adj dict2[temp]for l in range(len(adj dict2[temp])minus1minus1minus1)

if (adj dict2[temp][l]=n)adj dict2[adj dict2[temp][l]]remove(temp)adj dict2[temp]remove(adj dict2[temp][l])

break

def useless edges(num nodesadj dict1matching dict1uselessadj dict2G)for n in range(0num nodes)

for k in adj dict1[n]if ([k]=matching dict1[n]) and matching dict1[n] and matching dict1[k]

uselessadd edge(nk)Gremove edge(n k)

Appendix A 47

tempa=kadj dict2[n]remove(k)adj dict2[tempa]remove(n)adj dict1[tempa]remove(n)

return G

def Greedy(num nodesadj dict3matching dict2)

for n in range(0num nodes)if matching dict2[n]

flag2=minus1flag3=minus1for v in adj dict3[n]

if not matching dict2[v]flag2=vbreak

for p in adj dict3[matching dict2[n][0]]if not matching dict2[p]

flag3=pbreak

if (flag2=minus1) and (flag3=minus1) and (flag2=flag3)tempr=matching dict2[n][0]matching dict2[n]=[flag2]matching dict2[flag2]=[n]matching dict2[tempr]=[flag3]matching dict2[flag3]=[tempr]

elsefor k in adj dict3[n]

if not matching dict2[k]matching dict2[n]=[k]matching dict2[k]=[n]break

yo1=0for i in range(0num nodes)

if matching dict2[i] and [i]==matching dict2[matching dict2[i][0]]yo1=yo1+1

greedy size=yo12return greedy size

def General()

INPUTSwb = xlwtWorkbook()ws = wbadd sheet(Results Random)book=xlrdopen workbook(filenames randomxls)

48 Application

style0 = xlwteasyxf(fontbold on)style1 = xlwteasyxf(num format str=0000)INPUTSwswrite(0 0File style0)wswrite(0 1 Nodesstyle0)wswrite(0 2 Initial matchingstyle0)wswrite(0 3 NodesGstyle0)wswrite(0 4 EdgesGstyle0)wswrite(0 5 MaxDegreeGstyle0)wswrite(0 6 NodesG hatstyle0)wswrite(0 7 EdgesG Hatstyle0)wswrite(0 8 Useless edgesstyle0)wswrite(0 9 Forced edgesstyle0)wswrite(0 10 MaxDegreeG Hatstyle0)wswrite(0 11 Classical matchingstyle0)wswrite(0 12 Final matchingstyle0)wswrite(0 13 Greedy matchingstyle0)wswrite(0 14 Time classicalstyle0)wswrite(0 15 Time algorithmstyle0)wswrite(0 16 Time greedystyle0)wswrite(0 17 Perfect matching ratiostyle0)wswrite(0 18 Nodes ratiostyle0)wswrite(0 19 Edges ratiostyle0)wswrite(0 20 Matching ratiostyle0)

print nWelcomeThis is an implementation for general random graphs It uses Edmonds algorithm to compute maximum matching on G Hatn

for index in range (1481)was 481

if (index==482)f=open(Algotel generaltxtr)readlines()

elsefilea=str(booksheet by index(0)cell(index0))s=fileareplace(textu)replace()f=open(sr)readlines()Truewswrite(index 0 s)

print index

num nodes=int([xstrip()split() for x in f][0][0])

num matching=int([xstrip()split() for x in f][2][0])

adj temp = [xstrip()split() for x in f][44+num nodes]adj=[map(intR) for R in adj temp]

matching temp=[xstrip()split() for x in f][4+num nodes+14+2num nodes+1]matching1=[map(intR) for R in matching temp]

adj dict1=i[ii for iix in enumerate(L) if x] for iL in enumerate(adj)adj dict2=i[ii for iix in enumerate(L) if x] for iL in enumerate(adj)

Appendix A 49

adj dict3=i[ii for iix in enumerate(L) if x] for iL in enumerate(adj)

matching dict1=i[ii for iix in enumerate(L) if x] for iL in enumerate(matching1)matching dict2=i[ii for iix in enumerate(L) if x] for iL in enumerate(matching1)print adj dict2print matching dict2wswrite(index 1 num nodes)wswrite(index 2 num matching)

G = nxGraph()

useless= nxGraph()forced = nxGraph()

Fill Graphfor n in range(0num nodes)

for k in adj dict1[n]Gadd edge(nk)

Gt=Gnumber of edges()wswrite(index 3 Gnumber of nodes())wswrite(index 4 Gnumber of edges())wswrite(index 5 max(Gdegree()values()))

Compute Edmonds classical matching on G for comparison

startB = timeitdefault timer()Classical Matching=nxmax weight matching(G maxcardinality=False)stopB = timeitdefault timer()

Compute Gˆ nad MˆstartC = timeitdefault timer()useless edges(num nodesadj dict1matching dict1uselessadj dict2G)forced edges(Gadj dict2matching dict1num nodesforced)Final Matching=nxmax weight matching(G maxcardinality=False)stopC = timeitdefault timer()

GreedystartG = timeitdefault timer()greedy size=Greedy(num nodesadj dict3matching dict2)stopG = timeitdefault timer()

wswrite(index 6 Gnumber of nodes())wswrite(index 7 Gnumber of edges())wswrite(index 8 uselessnumber of edges())wswrite(index 9 forcednumber of edges())if Gdegree()values()

wswrite(index 10 max(Gdegree()values()))else

50 Application

wswrite(index 10 0)wswrite(index 11 len(Classical Matching)2)wswrite(index 12 len(Final Matching)2+forcednumber of edges())wswrite(index 13 greedy size)wswrite(index 14 stopB minus startBstyle1)wswrite(index 15 stopC minus startCstyle1)wswrite(index 16 stopG minus startGstyle1)wswrite(index 17 (len(Final Matching)2+forcednumber of edges())(num nodes2)style1)wswrite(index 18 Gnumber of nodes()Gtstyle1)wswrite(index 19 Gnumber of edges()Gtstyle1)wswrite(index 20 (len(Final Matching)2+forcednumber of edges())(len(Classical Matching)2)style1)

wbsave(AA Results Random Reyni Large Bipartitexls)

Main function Here we must choose the input form of the dataif name == main

startA = timeitdefault timer()General()stopA = timeitdefault timer()

print nThis program has terminatednnRunning time for 480 files stopAminusstartAprint nnPlease open AA Results Random Reyni Largexls file to see the Results

Appendix A 51

Plotmat

clear allclose allload(RN1Lmat)load(RN1Smat)load(RN2Lmat)load(RN2Smat)load(RN3Lmat)load(RN3Smat)

Plotsh(1)=figure(NameHistogram of Matching size difference between Constraint Algorithm and Greedy AlgorithmNumberTitleoff)

RN1L Greedydiff=RN1L Final matchingminusRN1L Greedy matchingRN2L Greedydiff=RN2L Final matchingminusRN2L Greedy matchingRN3L Greedydiff=RN3L Final matchingminusRN3L Greedy matchingRN1S Greedydiff=RN1S Final matchingminusRN1S Greedy matchingRN2S Greedydiff=RN2S Final matchingminusRN2S Greedy matchingRN3S Greedydiff=RN3S Final matchingminusRN3S Greedy matching

RN1L Finaldiff=RN1L Classical matchingminusRN1L Final matchingRN2L Finaldiff=RN2L Classical matchingminusRN2L Final matchingRN3L Finaldiff=RN3L Classical matchingminusRN3L Final matchingRN1S Finaldiff=RN1S Classical matchingminusRN1S Final matchingRN2S Finaldiff=RN2S Classical matchingminusRN2S Final matchingRN3S Finaldiff=RN3S Classical matchingminusRN3S Final matching

RN1L Classicaldiff=(RN1L Nodes2)minusRN1L Classical matchingRN2L Classicaldiff=(RN2L Nodes2)minusRN2L Classical matchingRN3L Classicaldiff=(RN3L Nodes2)minusRN3L Classical matchingRN1S Classicaldiff=(RN1S Nodes2)minusRN1S Classical matchingRN2S Classicaldiff=(RN2S Nodes2)minusRN2S Classical matchingRN3S Classicaldiff=(RN3S Nodes2)minusRN3S Classical matching

subplot(231)hold onhistf(RN1L Greedydiff0110facecolorbfacealpha9edgealpha1)histf(RN1L Finaldiff0110facecolorrfacealpha5edgealpha1)histf(RN1L Classicaldiff0110facecolorgfacealpha5edgealpha1)legalpha(ConminusGreClasminusConPerfminusClasslocationnortheast)legend boxoffaxis tightxlabel(edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN1L)grid on

subplot(232)hold onhistf(RN2L Greedydiff0110facecolorbfacealpha9edgealpha1)

52 Application

histf(RN2L Finaldiff0110facecolorrfacealpha5edgealpha1)histf(RN2L Classicaldiff0110facecolorgfacealpha5edgealpha1)legalpha(ConminusGreClasminusConPerfminusClasslocationnortheast)legend boxoffaxis tightxlabel(edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN2L)grid on

subplot(233)hold onhistf(RN3L Greedydiff0110facecolorbfacealpha5edgealpha1)histf(RN3L Finaldiff0110facecolorrfacealpha5edgealpha1)histf(RN3L Classicaldiff0110facecolorgfacealpha5edgealpha1)legalpha(ConminusGreClasminusConPerfminusClasslocationnortheast)legend boxoffaxis tightxlabel(edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN3L)grid on

subplot(234)hold onhistf(RN1S Greedydiff0110facecolorbfacealpha5edgealpha1)histf(RN1S Finaldiff0110facecolorrfacealpha5edgealpha1)histf(RN1S Classicaldiff0110facecolorgfacealpha5edgealpha1)legalpha(ConminusGreClasminusConPerfminusClasslocationnortheast)legend boxoffaxis tightxlabel(edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(R1NS)grid on

subplot(235)hold onhistf(RN2S Greedydiff0110facecolorbfacealpha5edgealpha1)histf(RN2S Finaldiff0110facecolorrfacealpha5edgealpha1)histf(RN2S Classicaldiff0110facecolorgfacealpha5edgealpha1)legalpha(ConminusGreClasminusConPerfminusClasslocationnortheast)legend boxoffaxis tightxlabel(edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN2S)grid on

subplot(236)hold onhistf(RN3S Greedydiff0110facecolorbfacealpha5edgealpha1)histf(RN3S Finaldiff0110facecolorrfacealpha5edgealpha1)histf(RN3S Classicaldiff0110facecolorgfacealpha5edgealpha1)

Appendix A 53

legalpha(ConminusGreClasminusConPerfminusClasslocationnortheast)legend boxoffaxis tightgrid ontitle(RN3S)xlabel(edges) xminusaxis labelylabel(instances) yminusaxis labelset(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN1png minusr300)h(2)=figure(NameHistogram of Max Degree of G AND G HatNumberTitleoff)RN1L x=RN1L MaxDegreeGminusRN1L MaxDegreeG HatRN2L x=RN2L MaxDegreeGminusRN2L MaxDegreeG HatRN3L x=RN3L MaxDegreeGminusRN3L MaxDegreeG HatRN1S x=RN1S MaxDegreeGminusRN1S MaxDegreeG HatRN2S x=RN2S MaxDegreeGminusRN2S MaxDegreeG HatRN3S x=RN3S MaxDegreeGminusRN3S MaxDegreeG Hatsubplot(231)hold onhistf(RN1L MaxDegreeG0150facecolorbfacealpha5edgealpha1)histf(RN1L MaxDegreeG Hat0150facecolorrfacealpha5edgealpha1)histf(RN1L x0150facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightxlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN1L)grid on

subplot(232)hold onhistf(RN2L MaxDegreeG010500facecolorbfacealpha5edgealpha1)histf(RN2L MaxDegreeG Hat010500facecolorrfacealpha5edgealpha1)histf(RN2L x010500facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightxlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN2L)grid on

subplot(233)hold onhistf(RN3L MaxDegreeG010300facecolorbfacealpha5edgealpha1)histf(RN3L MaxDegreeG Hat010300facecolorrfacealpha5edgealpha1)histf(RN3L x010300facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightxlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN3L)

54 Application

grid on

subplot(234)hold onhistf(RN1S MaxDegreeG0150facecolorbfacealpha5edgealpha1)histf(RN1S MaxDegreeG Hat0150facecolorrfacealpha5edgealpha1)histf(RN1S x0150facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightxlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(R1NS)grid on

subplot(235)hold onhistf(RN2S MaxDegreeG010500facecolorbfacealpha5edgealpha1)histf(RN2S MaxDegreeG Hat010500facecolorrfacealpha5edgealpha1)histf(RN2S x010500facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightxlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN2S)grid on

subplot(236)hold onhistf(RN3S MaxDegreeG05300facecolorbfacealpha5edgealpha1)histf(RN3S MaxDegreeG Hat05300facecolorrfacealpha5edgealpha1)histf(RN3S x05300facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightgrid ontitle(RN3S)xlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labelset(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN2png minusr300)

h(3)=figure(NameComputation time over edgesNumberTitleoff)

subplot(231)hold onstem(RN1L EdgesGRN1L Time classicalg)stem(RN1L EdgesGRN1L Time algorithmro)stem(RN1L EdgesGRN1L Time greedybx)grid on

Appendix A 55

title(RN1L)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)

subplot(232)hold onstem(RN2L EdgesGRN2L Time classicalg)stem(RN2L EdgesGRN2L Time algorithmro)stem(RN2L EdgesGRN2L Time greedybx)grid ontitle(RN2L)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)

subplot(233)hold onstem(RN3L EdgesGRN3L Time classicalg)stem(RN3L EdgesGRN3L Time algorithmro)stem(RN3L EdgesGRN3L Time greedybx)grid ontitle(RN3L)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)

subplot(234)hold onstem(RN1S EdgesGRN1S Time classicalg)stem(RN1S EdgesGRN1S Time algorithmro)stem(RN1S EdgesGRN1S Time greedybx)grid ontitle(RN1S)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)

subplot(235)hold onstem(RN2S EdgesGRN2S Time classicalg)stem(RN2S EdgesGRN2S Time algorithmro)stem(RN2S EdgesGRN2S Time greedybx)grid ontitle(RN2S)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)

subplot(236)hold onstem(RN3S EdgesGRN3S Time classicalg)stem(RN3S EdgesGRN3S Time algorithmro)stem(RN3S EdgesGRN3S Time greedybx)

56 Application

grid ontitle(RN3S)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)set(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN3png minusr300)

h(4)=figure(NameSorted matching sizeNumberTitleoff)RN1L Sorted matching temp(1)=RN1L Classical matchingRN1L Sorted matching temp(2)=RN1L Final matchingRN1L Sorted matching temp(3)=RN1L Greedy matchingRN1L Sorted matching temp(4)=RN1L Initial matchingRN1L Sorted matching=sortrows(RN1L Sorted matching temp)

RN2L Sorted matching temp(1)=RN2L Classical matchingRN2L Sorted matching temp(2)=RN2L Final matchingRN2L Sorted matching temp(3)=RN2L Greedy matchingRN2L Sorted matching temp(4)=RN2L Initial matchingRN2L Sorted matching=sortrows(RN2L Sorted matching temp)

RN3L Sorted matching temp(1)=RN3L Classical matchingRN3L Sorted matching temp(2)=RN3L Final matchingRN3L Sorted matching temp(3)=RN3L Greedy matchingRN3L Sorted matching temp(4)=RN3L Initial matchingRN3L Sorted matching=sortrows(RN3L Sorted matching temp)

RN1S Sorted matching temp(1)=RN1S Classical matchingRN1S Sorted matching temp(2)=RN1S Final matchingRN1S Sorted matching temp(3)=RN1S Greedy matchingRN1S Sorted matching temp(4)=RN1S Initial matchingRN1S Sorted matching=sortrows(RN1S Sorted matching temp)

RN2S Sorted matching temp(1)=RN2S Classical matchingRN2S Sorted matching temp(2)=RN2S Final matchingRN2S Sorted matching temp(3)=RN2S Greedy matchingRN2S Sorted matching temp(4)=RN2S Initial matchingRN2S Sorted matching=sortrows(RN2S Sorted matching temp)

RN3S Sorted matching temp(1)=RN3S Classical matchingRN3S Sorted matching temp(2)=RN3S Final matchingRN3S Sorted matching temp(3)=RN3S Greedy matchingRN3S Sorted matching temp(4)=RN3S Initial matchingRN3S Sorted matching=sortrows(RN3S Sorted matching temp)

subplot(231)hold onplot(RN1L Sorted matching(1)b)plot(RN1L Sorted matching(2)g)plot(RN1L Sorted matching(3)r)plot(RN1L Sorted matching(4)m)

Appendix A 57

grid ontitle(RN1L)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)

subplot(232)hold onplot(RN2L Sorted matching(1)b)plot(RN2L Sorted matching(2)g)plot(RN2L Sorted matching(3)r)plot(RN2L Sorted matching(4)m)grid ontitle(RN2L)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)

subplot(233)hold onplot(RN3L Sorted matching(1)b)plot(RN3L Sorted matching(2)g)plot(RN3L Sorted matching(3)r)plot(RN3L Sorted matching(4)m)grid ontitle(RN3L)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)

subplot(234)hold onplot(RN1S Sorted matching(1)b)plot(RN1S Sorted matching(2)g)plot(RN1S Sorted matching(3)r)plot(RN1S Sorted matching(4)m)grid ontitle(RN1S)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)

subplot(235)hold onplot(RN2S Sorted matching(1)b)plot(RN2S Sorted matching(2)g)plot(RN2S Sorted matching(3)r)plot(RN2S Sorted matching(4)m)grid ontitle(RN2S)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)

58 Application

subplot(236)hold onplot(RN3S Sorted matching(1)b)plot(RN3S Sorted matching(2)g)plot(RN3S Sorted matching(3)r)plot(RN3S Sorted matching(4)m)grid ontitle(RN3S)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)set(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN4png minusr300)h(5)=figure(NameSorted RatiosNumberTitleoff)RN1L ratio1=RN1L NodesG hatRN1L NodesGRN2L ratio1=RN2L NodesG hatRN2L NodesGRN3L ratio1=RN3L NodesG hatRN3L NodesGRN1S ratio1=RN1S NodesG hatRN1S NodesGRN2S ratio1=RN2S NodesG hatRN2S NodesGRN3S ratio1=RN3S NodesG hatRN3S NodesG

RN1L ratio2=RN1L EdgesG HatRN1L EdgesGRN2L ratio2=RN2L EdgesG HatRN2L EdgesGRN3L ratio2=RN3L EdgesG HatRN3L EdgesGRN1S ratio2=RN1S EdgesG HatRN1S EdgesGRN2S ratio2=RN2S EdgesG HatRN2S EdgesGRN3S ratio2=RN3S EdgesG HatRN3S EdgesG

RN1L ratio3=RN1L MaxDegreeG HatRN1L MaxDegreeGRN2L ratio3=RN2L MaxDegreeG HatRN2L MaxDegreeGRN3L ratio3=RN3L MaxDegreeG HatRN3L MaxDegreeGRN1S ratio3=RN1S MaxDegreeG HatRN1S MaxDegreeGRN2S ratio3=RN2S MaxDegreeG HatRN2S MaxDegreeGRN3S ratio3=RN3S MaxDegreeG HatRN3S MaxDegreeG

RN1L ratio(1)=RN1L ratio1RN1L ratio(2)=RN1L ratio2RN1L ratio(3)=RN1L ratio3

RN2L ratio(1)=RN2L ratio1RN2L ratio(2)=RN2L ratio2RN2L ratio(3)=RN2L ratio3

RN3L ratio(1)=RN3L ratio1RN3L ratio(2)=RN3L ratio2RN3L ratio(3)=RN3L ratio3

RN1S ratio(1)=RN1S ratio1RN1S ratio(2)=RN1S ratio2RN1S ratio(3)=RN1S ratio3

RN2S ratio(1)=RN2S ratio1

Appendix A 59

RN2S ratio(2)=RN2S ratio2RN2S ratio(3)=RN2S ratio3

RN3S ratio(1)=RN3S ratio1RN3S ratio(2)=RN3S ratio2RN3S ratio(3)=RN3S ratio3

RN1L ratio sorted=sortrows(RN1L ratio)RN2L ratio sorted=sortrows(RN2L ratio)RN3L ratio sorted=sortrows(RN3L ratio)RN1S ratio sorted=sortrows(RN1S ratio)RN2S ratio sorted=sortrows(RN2S ratio)RN3S ratio sorted=sortrows(RN3S ratio)

subplot(231)hold onplot(RN1L ratio sorted(1)b)plot(RN1L ratio sorted(2)g)plot(RN1L ratio sorted(3)r)grid ontitle(RN1L)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)

subplot(232)hold onplot(RN2L ratio sorted(1)b)plot(RN2L ratio sorted(2)g)plot(RN2L ratio sorted(3)r)grid ontitle(RN2L)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)

subplot(233)hold onplot(RN3L ratio sorted(1)b)plot(RN3L ratio sorted(2)g)plot(RN3L ratio sorted(3)r)grid ontitle(RN3L)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)

subplot(234)hold onplot(RN1S ratio sorted(1)b)plot(RN1S ratio sorted(2)g)plot(RN1S ratio sorted(3)r)grid on

60 Application

title(RN1S)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)

subplot(235)hold onplot(RN2S ratio sorted(1)b)plot(RN2S ratio sorted(2)g)plot(RN2S ratio sorted(3)r)grid ontitle(RN2S)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)

subplot(236)hold onplot(RN3S ratio sorted(1)b)plot(RN3S ratio sorted(2)g)plot(RN3S ratio sorted(3)r)grid ontitle(RN3S)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)set(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN5png minusr300)

h(6)=figure(NameSorted edges over nodesNumberTitleoff)

RN1L DegreeG1=(RN1L EdgesG)(RN1L NodesG)RN1L DegreeG Hat1=(RN1L EdgesG Hat)(RN1L NodesG hat)

RN1L Degree temp1(1)=RN1L DegreeG1RN1L Degree temp1(2)=RN1L DegreeG Hat1RN1L Degree sorted1=sortrows(RN1L Degree temp1)subplot(231)hold on

plot(RN1L Degree sorted1(1)b)plot(RN1L Degree sorted1(2)g)grid ontitle(RN1L)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)

RN2L DegreeG1=(RN2L EdgesG)(RN2L NodesG)RN2L DegreeG Hat1=(RN2L EdgesG Hat)(RN2L NodesG hat)

RN2L Degree temp1(1)=RN2L DegreeG1

Appendix A 61

RN2L Degree temp1(2)=RN2L DegreeG Hat1RN2L Degree sorted1=sortrows(RN2L Degree temp1)

subplot(232)hold onplot(RN2L Degree sorted1(1)b)plot(RN2L Degree sorted1(2)g)grid ontitle(RN2L)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)

RN3L DegreeG1=(RN3L EdgesG)(RN3L NodesG)RN3L DegreeG Hat1=(RN3L EdgesG Hat)(RN3L NodesG hat)

RN3L Degree temp1(1)=RN3L DegreeG1RN3L Degree temp1(2)=RN3L DegreeG Hat1RN3L Degree sorted1=sortrows(RN3L Degree temp1)

subplot(233)hold onplot(RN3L Degree sorted1(1)b)plot(RN3L Degree sorted1(2)g)grid ontitle(RN3L)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)

RN1S DegreeG1=(RN1S EdgesG)(RN1S NodesG)RN1S DegreeG Hat1=(RN1S EdgesG Hat)(RN1S NodesG hat)

RN1S Degree temp1(1)=RN1S DegreeG1RN1S Degree temp1(2)=RN1S DegreeG Hat1RN1S Degree sorted1=sortrows(RN1S Degree temp1)

subplot(234)hold onplot(RN1S Degree sorted1(1)b)plot(RN1S Degree sorted1(2)g)grid ontitle(RN1S)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)

RN2S DegreeG1=(RN2S EdgesG)(RN2S NodesG)RN2S DegreeG Hat1=(RN2S EdgesG Hat)(RN2S NodesG hat)

RN2S Degree temp1(1)=RN2S DegreeG1

62 Application

RN2S Degree temp1(2)=RN2S DegreeG Hat1RN2S Degree sorted1=sortrows(RN2S Degree temp1)

subplot(235)hold onplot(RN2S Degree sorted1(1)b)plot(RN2S Degree sorted1(2)g)grid ontitle(RN2S)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)

RN3S DegreeG1=(RN3S EdgesG)(RN3S NodesG)RN3S DegreeG Hat1=(RN3S EdgesG Hat)(RN3S NodesG hat)

RN3S Degree temp1(1)=RN3S DegreeG1RN3S Degree temp1(2)=RN3S DegreeG Hat1RN3S Degree sorted1=sortrows(RN3S Degree temp1)

subplot(236)hold onplot(RN3S Degree sorted1(1)b)plot(RN3S Degree sorted1(2)g)grid ontitle(RN3S)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)set(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN6png minusr300)h(7)=figure(NameSorted mATCHED DEGREENumberTitleoff)RN1L ratioMax(1)=RN1L MaxDegreeGRN1L ratioMax(2)=RN1L MaxDegreeG Hat

RN1L ratio sortedMax=sortrows(RN1L ratioMax)subplot(231)hold onplot(RN1L ratio sortedMax(1)b)plot(RN1L ratio sortedMax(2)g)grid ontitle(RN1L)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)

RN2L ratioMax(1)=RN2L MaxDegreeGRN2L ratioMax(2)=RN2L MaxDegreeG Hat

RN2L ratio sortedMax=sortrows(RN2L ratioMax)subplot(232)

Appendix A 63

hold onplot(RN2L ratio sortedMax(1)b)plot(RN2L ratio sortedMax(2)g)grid ontitle(RN2L)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)

RN3L ratioMax(1)=RN3L MaxDegreeGRN3L ratioMax(2)=RN3L MaxDegreeG Hat

RN3L ratio sortedMax=sortrows(RN3L ratioMax)subplot(233)hold onplot(RN3L ratio sortedMax(1)b)plot(RN3L ratio sortedMax(2)g)grid ontitle(RN3L)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)

RN1S ratioMax(1)=RN1S MaxDegreeGRN1S ratioMax(2)=RN1S MaxDegreeG Hat

RN1S ratio sortedMax=sortrows(RN1S ratioMax)subplot(234)hold onplot(RN1S ratio sortedMax(1)b)plot(RN1S ratio sortedMax(2)g)grid ontitle(RN1S)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)

RN2S ratioMax(1)=RN2S MaxDegreeGRN2S ratioMax(2)=RN2S MaxDegreeG Hat

RN2S ratio sortedMax=sortrows(RN2S ratioMax)

subplot(235)hold onplot(RN2S ratio sortedMax(1)b)plot(RN2S ratio sortedMax(2)g)grid ontitle(RN2S)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)

RN3S ratioMax(1)=RN3S MaxDegreeGRN3S ratioMax(2)=RN3S MaxDegreeG Hat

64 Application

RN3S ratio sortedMax=sortrows(RN3S ratioMax)subplot(236)hold onplot(RN3S ratio sortedMax(1)b)plot(RN3S ratio sortedMax(2)g)grid ontitle(RN1L)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)set(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN7png minusr300)

tilefigs()(h)

Bibliography

[1] C Berge ldquoTWO THEOREMS IN GRAPH THEORYrdquo Proceedings of the NationalAcademy of Sciences of the United States of America vol 43 no 9 pp 842ndash844Sep 1957

[2] L Bui S Sanghavi and R Srikant ldquoDistributed link scheduling with constantoverheadrdquo IEEEACM Trans Netw vol 17 no 5 pp 1467ndash1480 2009

[3] R Duan and S Pettie ldquoLinear-time approximation for maximum weight matchingrdquoJ ACM vol 61 no 1 2014

[4] J Edmonds ldquoPaths trees and flowersrdquo Canadian Journal of Mathematics vol 17pp 449ndash467 1965

[5] J E Hopcroft and R M Karp ldquoAn n52 algorithm for maximum matchings inbipartite graphsrdquo SIAM J Comput vol 2 no 4 pp 225ndash231 1973

[6] S Micali and V V Vazirani ldquoAn O(radic|V ||E|) algorithm for finding maximum

matching in general graphsrdquo in 21st Symp on Foundations of Comp Sc (FOCS)IEEE 1980 pp 17ndash27

[7] N Nisse A Salch and V Weber ldquoRecovery of disrupted airline operationsrdquo 2015httphalinriafrSomething

[8] X Wu and R Srikant ldquoRegulated maximal matching A distributed schedulingalgorithm for multi-hop wireless networks with nodeexclusive spectrum sharingrdquo inIEEE Conf on Decision and Control 2005

65

  • Contents
  • Introduction
  • Algorithms
    • Maximum matching
    • k-maximum matching
      • k-matching for Airport Slot assignment
      • The case where k=3
      • The case of Paths
      • The case of the Spider
          • Application
            • Description
            • Reyni Erdos
            • Barabaacutesi Albert
            • Amadeus Graphs
            • Bipartite
            • Bipartite with degree seq
            • Appendix A
              • BipartiteGraphGeneratorpy
              • RandomGraphGeneratorpy
              • kequals3MaximumMatchingpy
              • Plotmat
                  • Bibliography
Page 36: Theodoros Alexandros KARAGKIOULES -  · Introduction This work is the result of a 6 months internship, under the supervision of research O cer Nicolas NISSE. The original scope of

26 Bipartite with degree seq 37

Sorted |E||V | - Comments

bull In these set of figures we witness that the |E||V | acquires values relevant to those ofthe amadeus graphs The random graphs were constructed to depict this similarity

bull For smaller initial matching the ratios for G and G show the same upward trendand also they acquire closer values It repsresent the decrease of the averagenumber of forced edges in comparison to the larger matching cases

Sorted ∆

38 Application

Sorted ∆-Comments

bull Big difference in max degree in large initial matching

bull Almost identical behaviour in the case of small initial matching

Appendix A 39

Appendix A

BipartiteGraphGeneratorpy

from future import divisionimport networkx as nx

from networkxalgorithms import approximationimport collectionsimport randomimport mathfrom networkxalgorithms import bipartiteif name == main

for i in range(1481)waqs 481index=1n=randomrandint(100 1000)

n1=95 was 500me1=118

n2=251 was 500me2=903

n3=165 was 500me3=412

m=0m1=0p=randomrandom()p1=18250p2=25250p3=34250print ip=05t1=randomrandint(0 1)print im2=randomrandint(n2minus1 n2+1)G = nxGraph()ma = nxGraph()

aseq1=[1 2 3 4 5 3]

bseq1=[4 3 3 1 2 2 1]

aseq2=[16 14 14 14 12 11]bseq2=[0 0 0 0 0 0]

aseq3=[8 7 8 8 8 8]bseq3=[0 0 0 0 0 0]

40 Application

print Gnumber of edges()if ilt=160

G=bipartiteconfiguration model(aseq1 bseq1 create using=None seed=None)A=nxadjacency matrix(G)for ii in range(0n1+me1)

maadd node(ii)A=[Rtodense()tolist()[0] for R in A]

printnummanumber of nodes()rl=randomsample(range(0n1+me1) n1+me1)m=0done vertices = set()for p in rlprintin fordone verticesadd(p)

neighbors = []list()for iii in range(0n1+me1)

if A[p][iii]==1neighborsappend(iii)

randomshuffle(neighbors)continue loop = Truedegree = len(neighbors)

print degreej = 0p4=randomrandom()while continue loop and (jltdegree)print in loop

next = neighbors[j]if next not in done vertices and p not in done vertices

done verticesadd(p)done verticesadd(next)if p4gt=07print added edge

maadd edge(pnext)m=m+1

continue loop = Falsej += 1

print matching listOfedgeprint maedge

MA=nxadjacency matrix(ma)print MA

MA=[Rtodense()tolist()[0] for R in MA]print MA

B=[ join(map(strR)) for R in A]MB=[ join(map(strR)) for R in MA]

C=njoin(B)+nMC=njoin(MB)+n

print nprint mprint m1

filea=str(i)+txtwith open(fileaw) as f

Appendix A 41

fwrite(str(n1+me1))fwrite(n)fwrite(str(n1+me1))fwrite(n)fwrite(str(m))fwrite(n)fwrite(n)fwrite(C)fwrite(n)fwrite(MC)

elif igt160 and ilt321G=bipartiteconfiguration model(aseq2 bseq2 create using=None seed=None)A=nxadjacency matrix(G)for ii in range(0n2+me2)

maadd node(ii)A=[Rtodense()tolist()[0] for R in A]

printnummanumber of nodes()rl=randomsample(range(0n2+me2) n2+me2)m=0done vertices = set()for p in rlprintin fordone verticesadd(p)

neighbors = []list()for iii in range(0n2+me2)

if A[p][iii]==1neighborsappend(iii)

randomshuffle(neighbors)continue loop = Truedegree = len(neighbors)

print degreej = 0p4=randomrandom()while continue loop and (jltdegree)

print in loopnext = neighbors[j]if next not in done vertices and p not in done vertices

done verticesadd(p)done verticesadd(next)if p4gt=07

print added edgemaadd edge(pnext)m=m+1

continue loop = Falsej += 1

print matching listOfedgeprint maedge

MA=nxadjacency matrix(ma)print MA

MA=[Rtodense()tolist()[0] for R in MA]print MA

B=[ join(map(strR)) for R in A]MB=[ join(map(strR)) for R in MA]

42 Application

C=njoin(B)+nMC=njoin(MB)+n

print nprint mprint m1

filea=str(i)+txtwith open(fileaw) as f

fwrite(str(n2+me2))fwrite(n)fwrite(str(n2+me2))fwrite(n)fwrite(str(m))fwrite(n)fwrite(n)fwrite(C)fwrite(n)fwrite(MC)

elseG=bipartiteconfiguration model(aseq3 bseq3 create using=None seed=None)A=nxadjacency matrix(G)for ii in range(0n3+me3)

maadd node(ii)A=[Rtodense()tolist()[0] for R in A]

printnummanumber of nodes()rl=randomsample(range(0n3+me3) n3+me3)m=0done vertices = set()for p in rlprintin fordone verticesadd(p)

neighbors = []list()for iii in range(0n3+me3)

if A[p][iii]==1neighborsappend(iii)

randomshuffle(neighbors)continue loop = Truedegree = len(neighbors)

print degreej = 0p4=randomrandom()while continue loop and (jltdegree)

print in loopnext = neighbors[j]if next not in done vertices and p not in done vertices

done verticesadd(p)done verticesadd(next)if p4gt=07print added edge

maadd edge(pnext)m=m+1

continue loop = Falsej += 1

Appendix A 43

print matching listOfedgeprint maedge

MA=nxadjacency matrix(ma)print MA

MA=[Rtodense()tolist()[0] for R in MA]print MA

B=[ join(map(strR)) for R in A]MB=[ join(map(strR)) for R in MA]

C=njoin(B)+nMC=njoin(MB)+n

print nprint mprint m1

filea=str(i)+txtwith open(fileaw) as f

fwrite(str(n3+me3))fwrite(n)fwrite(str(n3+me3))fwrite(n)fwrite(str(m))fwrite(n)fwrite(n)fwrite(C)fwrite(n)fwrite(MC)

print nRandom graphs with random matching have been generated

44 Application

RandomGraphGeneratorpy

from future import divisionimport networkx as nxfrom networkxalgorithms import approximationimport collectionsimport randomimport mathif name == main

for i in range(1481)index=1n=randomrandint(100 1000)

n=1000m=0m1=0p=randomrandom()p1=mathlog(n2)np2=13p3=mathlog(n2)n+01p=05t1=randomrandint(0 1)print im2=randomrandint(n2minus1 n2+1)G = nxGraph()ma = nxGraph()print nme1=randomrandint(1 10)me2=randomrandint(2050)me3=randomrandint(50100)if ilt241

if ilt=80G=nxfast gnp random graph(n p1 seed=None directed=False)

elif igt80 and ilt161G=nxfast gnp random graph(n p2 seed=None directed=False)

elseG=nxfast gnp random graph(n p3 seed=None directed=False)

elseif ilt=320

G=nxbarabasi albert graph(n me1 seed=None)elif igt320 and ilt401

G=nxbarabasi albert graph(n me2 seed=None)else

G=nxbarabasi albert graph(n me3 seed=None)A=nxadjacency matrix(G)for ii in range(0n)

maadd node(ii)A=[Rtodense()tolist()[0] for R in A]

rl=randomsample(range(0n) n)m=0

Appendix A 45

done vertices = set()for p in rl

done verticesadd(p)neighbors = []list()for iii in range(0n)

if A[p][iii]==1neighborsappend(iii)

randomshuffle(neighbors)continue loop = Truedegree = len(neighbors)j = 0p2=randomrandom()while continue loop and (jltdegree)

next = neighbors[j]if next not in done vertices and p not in done vertices

done verticesadd(p)done verticesadd(next)if p2gt=00 Larger probability for smaller initial matching

maadd edge(pnext)m=m+1

continue loop = Falsej += 1

print matching listOfedgeprint maedgeMA=nxadjacency matrix(ma)MA=[Rtodense()tolist()[0] for R in MA]print MAB=[ join(map(strR)) for R in A]MB=[ join(map(strR)) for R in MA]

C=njoin(B)+nMC=njoin(MB)+nprint MCprint nprint mprint m1filea=str(i)+txtwith open(fileaw) as f

fwrite(str(n))fwrite(n)fwrite(str(n))fwrite(n)fwrite(str(m))fwrite(n)fwrite(n)fwrite(C)fwrite(n)fwrite(MC)

print nRandom graphs with random matching have been generated

46 Application

kequals3MaximumMatchingpy

from future import divisionimport networkx as nxfrom networkxalgorithms import bipartiteimport matplotlibpyplot as pltimport collectionsimport timeitimport xlwtimport xlrdimport mathimport sys

Case for General Graphsdef forced edges(Gadj dict2matching dict1num nodesforced)

flagg=0for n in range(0num nodes)

for k in adj dict2[n]if ([k]==matching dict1[n])

count=0for l in range(0num nodes)

count=count+adj dict2[l]count(k)if (len(adj dict2[n])==1) or (count==1)

forcedadd edge(nk)Gremove edge(nk)Gremove node(n)Gremove node(k)printforced edgenktemp=kflagg=1for m in range (len(adj dict2[n])minus1minus1minus1)

adj dict2[adj dict2[n][m]]remove(n)adj dict2[n]remove(adj dict2[n][m])

if adj dict2[temp]for l in range(len(adj dict2[temp])minus1minus1minus1)

if (adj dict2[temp][l]=n)adj dict2[adj dict2[temp][l]]remove(temp)adj dict2[temp]remove(adj dict2[temp][l])

break

def useless edges(num nodesadj dict1matching dict1uselessadj dict2G)for n in range(0num nodes)

for k in adj dict1[n]if ([k]=matching dict1[n]) and matching dict1[n] and matching dict1[k]

uselessadd edge(nk)Gremove edge(n k)

Appendix A 47

tempa=kadj dict2[n]remove(k)adj dict2[tempa]remove(n)adj dict1[tempa]remove(n)

return G

def Greedy(num nodesadj dict3matching dict2)

for n in range(0num nodes)if matching dict2[n]

flag2=minus1flag3=minus1for v in adj dict3[n]

if not matching dict2[v]flag2=vbreak

for p in adj dict3[matching dict2[n][0]]if not matching dict2[p]

flag3=pbreak

if (flag2=minus1) and (flag3=minus1) and (flag2=flag3)tempr=matching dict2[n][0]matching dict2[n]=[flag2]matching dict2[flag2]=[n]matching dict2[tempr]=[flag3]matching dict2[flag3]=[tempr]

elsefor k in adj dict3[n]

if not matching dict2[k]matching dict2[n]=[k]matching dict2[k]=[n]break

yo1=0for i in range(0num nodes)

if matching dict2[i] and [i]==matching dict2[matching dict2[i][0]]yo1=yo1+1

greedy size=yo12return greedy size

def General()

INPUTSwb = xlwtWorkbook()ws = wbadd sheet(Results Random)book=xlrdopen workbook(filenames randomxls)

48 Application

style0 = xlwteasyxf(fontbold on)style1 = xlwteasyxf(num format str=0000)INPUTSwswrite(0 0File style0)wswrite(0 1 Nodesstyle0)wswrite(0 2 Initial matchingstyle0)wswrite(0 3 NodesGstyle0)wswrite(0 4 EdgesGstyle0)wswrite(0 5 MaxDegreeGstyle0)wswrite(0 6 NodesG hatstyle0)wswrite(0 7 EdgesG Hatstyle0)wswrite(0 8 Useless edgesstyle0)wswrite(0 9 Forced edgesstyle0)wswrite(0 10 MaxDegreeG Hatstyle0)wswrite(0 11 Classical matchingstyle0)wswrite(0 12 Final matchingstyle0)wswrite(0 13 Greedy matchingstyle0)wswrite(0 14 Time classicalstyle0)wswrite(0 15 Time algorithmstyle0)wswrite(0 16 Time greedystyle0)wswrite(0 17 Perfect matching ratiostyle0)wswrite(0 18 Nodes ratiostyle0)wswrite(0 19 Edges ratiostyle0)wswrite(0 20 Matching ratiostyle0)

print nWelcomeThis is an implementation for general random graphs It uses Edmonds algorithm to compute maximum matching on G Hatn

for index in range (1481)was 481

if (index==482)f=open(Algotel generaltxtr)readlines()

elsefilea=str(booksheet by index(0)cell(index0))s=fileareplace(textu)replace()f=open(sr)readlines()Truewswrite(index 0 s)

print index

num nodes=int([xstrip()split() for x in f][0][0])

num matching=int([xstrip()split() for x in f][2][0])

adj temp = [xstrip()split() for x in f][44+num nodes]adj=[map(intR) for R in adj temp]

matching temp=[xstrip()split() for x in f][4+num nodes+14+2num nodes+1]matching1=[map(intR) for R in matching temp]

adj dict1=i[ii for iix in enumerate(L) if x] for iL in enumerate(adj)adj dict2=i[ii for iix in enumerate(L) if x] for iL in enumerate(adj)

Appendix A 49

adj dict3=i[ii for iix in enumerate(L) if x] for iL in enumerate(adj)

matching dict1=i[ii for iix in enumerate(L) if x] for iL in enumerate(matching1)matching dict2=i[ii for iix in enumerate(L) if x] for iL in enumerate(matching1)print adj dict2print matching dict2wswrite(index 1 num nodes)wswrite(index 2 num matching)

G = nxGraph()

useless= nxGraph()forced = nxGraph()

Fill Graphfor n in range(0num nodes)

for k in adj dict1[n]Gadd edge(nk)

Gt=Gnumber of edges()wswrite(index 3 Gnumber of nodes())wswrite(index 4 Gnumber of edges())wswrite(index 5 max(Gdegree()values()))

Compute Edmonds classical matching on G for comparison

startB = timeitdefault timer()Classical Matching=nxmax weight matching(G maxcardinality=False)stopB = timeitdefault timer()

Compute Gˆ nad MˆstartC = timeitdefault timer()useless edges(num nodesadj dict1matching dict1uselessadj dict2G)forced edges(Gadj dict2matching dict1num nodesforced)Final Matching=nxmax weight matching(G maxcardinality=False)stopC = timeitdefault timer()

GreedystartG = timeitdefault timer()greedy size=Greedy(num nodesadj dict3matching dict2)stopG = timeitdefault timer()

wswrite(index 6 Gnumber of nodes())wswrite(index 7 Gnumber of edges())wswrite(index 8 uselessnumber of edges())wswrite(index 9 forcednumber of edges())if Gdegree()values()

wswrite(index 10 max(Gdegree()values()))else

50 Application

wswrite(index 10 0)wswrite(index 11 len(Classical Matching)2)wswrite(index 12 len(Final Matching)2+forcednumber of edges())wswrite(index 13 greedy size)wswrite(index 14 stopB minus startBstyle1)wswrite(index 15 stopC minus startCstyle1)wswrite(index 16 stopG minus startGstyle1)wswrite(index 17 (len(Final Matching)2+forcednumber of edges())(num nodes2)style1)wswrite(index 18 Gnumber of nodes()Gtstyle1)wswrite(index 19 Gnumber of edges()Gtstyle1)wswrite(index 20 (len(Final Matching)2+forcednumber of edges())(len(Classical Matching)2)style1)

wbsave(AA Results Random Reyni Large Bipartitexls)

Main function Here we must choose the input form of the dataif name == main

startA = timeitdefault timer()General()stopA = timeitdefault timer()

print nThis program has terminatednnRunning time for 480 files stopAminusstartAprint nnPlease open AA Results Random Reyni Largexls file to see the Results

Appendix A 51

Plotmat

clear allclose allload(RN1Lmat)load(RN1Smat)load(RN2Lmat)load(RN2Smat)load(RN3Lmat)load(RN3Smat)

Plotsh(1)=figure(NameHistogram of Matching size difference between Constraint Algorithm and Greedy AlgorithmNumberTitleoff)

RN1L Greedydiff=RN1L Final matchingminusRN1L Greedy matchingRN2L Greedydiff=RN2L Final matchingminusRN2L Greedy matchingRN3L Greedydiff=RN3L Final matchingminusRN3L Greedy matchingRN1S Greedydiff=RN1S Final matchingminusRN1S Greedy matchingRN2S Greedydiff=RN2S Final matchingminusRN2S Greedy matchingRN3S Greedydiff=RN3S Final matchingminusRN3S Greedy matching

RN1L Finaldiff=RN1L Classical matchingminusRN1L Final matchingRN2L Finaldiff=RN2L Classical matchingminusRN2L Final matchingRN3L Finaldiff=RN3L Classical matchingminusRN3L Final matchingRN1S Finaldiff=RN1S Classical matchingminusRN1S Final matchingRN2S Finaldiff=RN2S Classical matchingminusRN2S Final matchingRN3S Finaldiff=RN3S Classical matchingminusRN3S Final matching

RN1L Classicaldiff=(RN1L Nodes2)minusRN1L Classical matchingRN2L Classicaldiff=(RN2L Nodes2)minusRN2L Classical matchingRN3L Classicaldiff=(RN3L Nodes2)minusRN3L Classical matchingRN1S Classicaldiff=(RN1S Nodes2)minusRN1S Classical matchingRN2S Classicaldiff=(RN2S Nodes2)minusRN2S Classical matchingRN3S Classicaldiff=(RN3S Nodes2)minusRN3S Classical matching

subplot(231)hold onhistf(RN1L Greedydiff0110facecolorbfacealpha9edgealpha1)histf(RN1L Finaldiff0110facecolorrfacealpha5edgealpha1)histf(RN1L Classicaldiff0110facecolorgfacealpha5edgealpha1)legalpha(ConminusGreClasminusConPerfminusClasslocationnortheast)legend boxoffaxis tightxlabel(edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN1L)grid on

subplot(232)hold onhistf(RN2L Greedydiff0110facecolorbfacealpha9edgealpha1)

52 Application

histf(RN2L Finaldiff0110facecolorrfacealpha5edgealpha1)histf(RN2L Classicaldiff0110facecolorgfacealpha5edgealpha1)legalpha(ConminusGreClasminusConPerfminusClasslocationnortheast)legend boxoffaxis tightxlabel(edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN2L)grid on

subplot(233)hold onhistf(RN3L Greedydiff0110facecolorbfacealpha5edgealpha1)histf(RN3L Finaldiff0110facecolorrfacealpha5edgealpha1)histf(RN3L Classicaldiff0110facecolorgfacealpha5edgealpha1)legalpha(ConminusGreClasminusConPerfminusClasslocationnortheast)legend boxoffaxis tightxlabel(edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN3L)grid on

subplot(234)hold onhistf(RN1S Greedydiff0110facecolorbfacealpha5edgealpha1)histf(RN1S Finaldiff0110facecolorrfacealpha5edgealpha1)histf(RN1S Classicaldiff0110facecolorgfacealpha5edgealpha1)legalpha(ConminusGreClasminusConPerfminusClasslocationnortheast)legend boxoffaxis tightxlabel(edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(R1NS)grid on

subplot(235)hold onhistf(RN2S Greedydiff0110facecolorbfacealpha5edgealpha1)histf(RN2S Finaldiff0110facecolorrfacealpha5edgealpha1)histf(RN2S Classicaldiff0110facecolorgfacealpha5edgealpha1)legalpha(ConminusGreClasminusConPerfminusClasslocationnortheast)legend boxoffaxis tightxlabel(edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN2S)grid on

subplot(236)hold onhistf(RN3S Greedydiff0110facecolorbfacealpha5edgealpha1)histf(RN3S Finaldiff0110facecolorrfacealpha5edgealpha1)histf(RN3S Classicaldiff0110facecolorgfacealpha5edgealpha1)

Appendix A 53

legalpha(ConminusGreClasminusConPerfminusClasslocationnortheast)legend boxoffaxis tightgrid ontitle(RN3S)xlabel(edges) xminusaxis labelylabel(instances) yminusaxis labelset(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN1png minusr300)h(2)=figure(NameHistogram of Max Degree of G AND G HatNumberTitleoff)RN1L x=RN1L MaxDegreeGminusRN1L MaxDegreeG HatRN2L x=RN2L MaxDegreeGminusRN2L MaxDegreeG HatRN3L x=RN3L MaxDegreeGminusRN3L MaxDegreeG HatRN1S x=RN1S MaxDegreeGminusRN1S MaxDegreeG HatRN2S x=RN2S MaxDegreeGminusRN2S MaxDegreeG HatRN3S x=RN3S MaxDegreeGminusRN3S MaxDegreeG Hatsubplot(231)hold onhistf(RN1L MaxDegreeG0150facecolorbfacealpha5edgealpha1)histf(RN1L MaxDegreeG Hat0150facecolorrfacealpha5edgealpha1)histf(RN1L x0150facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightxlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN1L)grid on

subplot(232)hold onhistf(RN2L MaxDegreeG010500facecolorbfacealpha5edgealpha1)histf(RN2L MaxDegreeG Hat010500facecolorrfacealpha5edgealpha1)histf(RN2L x010500facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightxlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN2L)grid on

subplot(233)hold onhistf(RN3L MaxDegreeG010300facecolorbfacealpha5edgealpha1)histf(RN3L MaxDegreeG Hat010300facecolorrfacealpha5edgealpha1)histf(RN3L x010300facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightxlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN3L)

54 Application

grid on

subplot(234)hold onhistf(RN1S MaxDegreeG0150facecolorbfacealpha5edgealpha1)histf(RN1S MaxDegreeG Hat0150facecolorrfacealpha5edgealpha1)histf(RN1S x0150facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightxlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(R1NS)grid on

subplot(235)hold onhistf(RN2S MaxDegreeG010500facecolorbfacealpha5edgealpha1)histf(RN2S MaxDegreeG Hat010500facecolorrfacealpha5edgealpha1)histf(RN2S x010500facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightxlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN2S)grid on

subplot(236)hold onhistf(RN3S MaxDegreeG05300facecolorbfacealpha5edgealpha1)histf(RN3S MaxDegreeG Hat05300facecolorrfacealpha5edgealpha1)histf(RN3S x05300facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightgrid ontitle(RN3S)xlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labelset(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN2png minusr300)

h(3)=figure(NameComputation time over edgesNumberTitleoff)

subplot(231)hold onstem(RN1L EdgesGRN1L Time classicalg)stem(RN1L EdgesGRN1L Time algorithmro)stem(RN1L EdgesGRN1L Time greedybx)grid on

Appendix A 55

title(RN1L)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)

subplot(232)hold onstem(RN2L EdgesGRN2L Time classicalg)stem(RN2L EdgesGRN2L Time algorithmro)stem(RN2L EdgesGRN2L Time greedybx)grid ontitle(RN2L)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)

subplot(233)hold onstem(RN3L EdgesGRN3L Time classicalg)stem(RN3L EdgesGRN3L Time algorithmro)stem(RN3L EdgesGRN3L Time greedybx)grid ontitle(RN3L)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)

subplot(234)hold onstem(RN1S EdgesGRN1S Time classicalg)stem(RN1S EdgesGRN1S Time algorithmro)stem(RN1S EdgesGRN1S Time greedybx)grid ontitle(RN1S)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)

subplot(235)hold onstem(RN2S EdgesGRN2S Time classicalg)stem(RN2S EdgesGRN2S Time algorithmro)stem(RN2S EdgesGRN2S Time greedybx)grid ontitle(RN2S)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)

subplot(236)hold onstem(RN3S EdgesGRN3S Time classicalg)stem(RN3S EdgesGRN3S Time algorithmro)stem(RN3S EdgesGRN3S Time greedybx)

56 Application

grid ontitle(RN3S)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)set(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN3png minusr300)

h(4)=figure(NameSorted matching sizeNumberTitleoff)RN1L Sorted matching temp(1)=RN1L Classical matchingRN1L Sorted matching temp(2)=RN1L Final matchingRN1L Sorted matching temp(3)=RN1L Greedy matchingRN1L Sorted matching temp(4)=RN1L Initial matchingRN1L Sorted matching=sortrows(RN1L Sorted matching temp)

RN2L Sorted matching temp(1)=RN2L Classical matchingRN2L Sorted matching temp(2)=RN2L Final matchingRN2L Sorted matching temp(3)=RN2L Greedy matchingRN2L Sorted matching temp(4)=RN2L Initial matchingRN2L Sorted matching=sortrows(RN2L Sorted matching temp)

RN3L Sorted matching temp(1)=RN3L Classical matchingRN3L Sorted matching temp(2)=RN3L Final matchingRN3L Sorted matching temp(3)=RN3L Greedy matchingRN3L Sorted matching temp(4)=RN3L Initial matchingRN3L Sorted matching=sortrows(RN3L Sorted matching temp)

RN1S Sorted matching temp(1)=RN1S Classical matchingRN1S Sorted matching temp(2)=RN1S Final matchingRN1S Sorted matching temp(3)=RN1S Greedy matchingRN1S Sorted matching temp(4)=RN1S Initial matchingRN1S Sorted matching=sortrows(RN1S Sorted matching temp)

RN2S Sorted matching temp(1)=RN2S Classical matchingRN2S Sorted matching temp(2)=RN2S Final matchingRN2S Sorted matching temp(3)=RN2S Greedy matchingRN2S Sorted matching temp(4)=RN2S Initial matchingRN2S Sorted matching=sortrows(RN2S Sorted matching temp)

RN3S Sorted matching temp(1)=RN3S Classical matchingRN3S Sorted matching temp(2)=RN3S Final matchingRN3S Sorted matching temp(3)=RN3S Greedy matchingRN3S Sorted matching temp(4)=RN3S Initial matchingRN3S Sorted matching=sortrows(RN3S Sorted matching temp)

subplot(231)hold onplot(RN1L Sorted matching(1)b)plot(RN1L Sorted matching(2)g)plot(RN1L Sorted matching(3)r)plot(RN1L Sorted matching(4)m)

Appendix A 57

grid ontitle(RN1L)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)

subplot(232)hold onplot(RN2L Sorted matching(1)b)plot(RN2L Sorted matching(2)g)plot(RN2L Sorted matching(3)r)plot(RN2L Sorted matching(4)m)grid ontitle(RN2L)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)

subplot(233)hold onplot(RN3L Sorted matching(1)b)plot(RN3L Sorted matching(2)g)plot(RN3L Sorted matching(3)r)plot(RN3L Sorted matching(4)m)grid ontitle(RN3L)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)

subplot(234)hold onplot(RN1S Sorted matching(1)b)plot(RN1S Sorted matching(2)g)plot(RN1S Sorted matching(3)r)plot(RN1S Sorted matching(4)m)grid ontitle(RN1S)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)

subplot(235)hold onplot(RN2S Sorted matching(1)b)plot(RN2S Sorted matching(2)g)plot(RN2S Sorted matching(3)r)plot(RN2S Sorted matching(4)m)grid ontitle(RN2S)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)

58 Application

subplot(236)hold onplot(RN3S Sorted matching(1)b)plot(RN3S Sorted matching(2)g)plot(RN3S Sorted matching(3)r)plot(RN3S Sorted matching(4)m)grid ontitle(RN3S)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)set(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN4png minusr300)h(5)=figure(NameSorted RatiosNumberTitleoff)RN1L ratio1=RN1L NodesG hatRN1L NodesGRN2L ratio1=RN2L NodesG hatRN2L NodesGRN3L ratio1=RN3L NodesG hatRN3L NodesGRN1S ratio1=RN1S NodesG hatRN1S NodesGRN2S ratio1=RN2S NodesG hatRN2S NodesGRN3S ratio1=RN3S NodesG hatRN3S NodesG

RN1L ratio2=RN1L EdgesG HatRN1L EdgesGRN2L ratio2=RN2L EdgesG HatRN2L EdgesGRN3L ratio2=RN3L EdgesG HatRN3L EdgesGRN1S ratio2=RN1S EdgesG HatRN1S EdgesGRN2S ratio2=RN2S EdgesG HatRN2S EdgesGRN3S ratio2=RN3S EdgesG HatRN3S EdgesG

RN1L ratio3=RN1L MaxDegreeG HatRN1L MaxDegreeGRN2L ratio3=RN2L MaxDegreeG HatRN2L MaxDegreeGRN3L ratio3=RN3L MaxDegreeG HatRN3L MaxDegreeGRN1S ratio3=RN1S MaxDegreeG HatRN1S MaxDegreeGRN2S ratio3=RN2S MaxDegreeG HatRN2S MaxDegreeGRN3S ratio3=RN3S MaxDegreeG HatRN3S MaxDegreeG

RN1L ratio(1)=RN1L ratio1RN1L ratio(2)=RN1L ratio2RN1L ratio(3)=RN1L ratio3

RN2L ratio(1)=RN2L ratio1RN2L ratio(2)=RN2L ratio2RN2L ratio(3)=RN2L ratio3

RN3L ratio(1)=RN3L ratio1RN3L ratio(2)=RN3L ratio2RN3L ratio(3)=RN3L ratio3

RN1S ratio(1)=RN1S ratio1RN1S ratio(2)=RN1S ratio2RN1S ratio(3)=RN1S ratio3

RN2S ratio(1)=RN2S ratio1

Appendix A 59

RN2S ratio(2)=RN2S ratio2RN2S ratio(3)=RN2S ratio3

RN3S ratio(1)=RN3S ratio1RN3S ratio(2)=RN3S ratio2RN3S ratio(3)=RN3S ratio3

RN1L ratio sorted=sortrows(RN1L ratio)RN2L ratio sorted=sortrows(RN2L ratio)RN3L ratio sorted=sortrows(RN3L ratio)RN1S ratio sorted=sortrows(RN1S ratio)RN2S ratio sorted=sortrows(RN2S ratio)RN3S ratio sorted=sortrows(RN3S ratio)

subplot(231)hold onplot(RN1L ratio sorted(1)b)plot(RN1L ratio sorted(2)g)plot(RN1L ratio sorted(3)r)grid ontitle(RN1L)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)

subplot(232)hold onplot(RN2L ratio sorted(1)b)plot(RN2L ratio sorted(2)g)plot(RN2L ratio sorted(3)r)grid ontitle(RN2L)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)

subplot(233)hold onplot(RN3L ratio sorted(1)b)plot(RN3L ratio sorted(2)g)plot(RN3L ratio sorted(3)r)grid ontitle(RN3L)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)

subplot(234)hold onplot(RN1S ratio sorted(1)b)plot(RN1S ratio sorted(2)g)plot(RN1S ratio sorted(3)r)grid on

60 Application

title(RN1S)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)

subplot(235)hold onplot(RN2S ratio sorted(1)b)plot(RN2S ratio sorted(2)g)plot(RN2S ratio sorted(3)r)grid ontitle(RN2S)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)

subplot(236)hold onplot(RN3S ratio sorted(1)b)plot(RN3S ratio sorted(2)g)plot(RN3S ratio sorted(3)r)grid ontitle(RN3S)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)set(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN5png minusr300)

h(6)=figure(NameSorted edges over nodesNumberTitleoff)

RN1L DegreeG1=(RN1L EdgesG)(RN1L NodesG)RN1L DegreeG Hat1=(RN1L EdgesG Hat)(RN1L NodesG hat)

RN1L Degree temp1(1)=RN1L DegreeG1RN1L Degree temp1(2)=RN1L DegreeG Hat1RN1L Degree sorted1=sortrows(RN1L Degree temp1)subplot(231)hold on

plot(RN1L Degree sorted1(1)b)plot(RN1L Degree sorted1(2)g)grid ontitle(RN1L)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)

RN2L DegreeG1=(RN2L EdgesG)(RN2L NodesG)RN2L DegreeG Hat1=(RN2L EdgesG Hat)(RN2L NodesG hat)

RN2L Degree temp1(1)=RN2L DegreeG1

Appendix A 61

RN2L Degree temp1(2)=RN2L DegreeG Hat1RN2L Degree sorted1=sortrows(RN2L Degree temp1)

subplot(232)hold onplot(RN2L Degree sorted1(1)b)plot(RN2L Degree sorted1(2)g)grid ontitle(RN2L)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)

RN3L DegreeG1=(RN3L EdgesG)(RN3L NodesG)RN3L DegreeG Hat1=(RN3L EdgesG Hat)(RN3L NodesG hat)

RN3L Degree temp1(1)=RN3L DegreeG1RN3L Degree temp1(2)=RN3L DegreeG Hat1RN3L Degree sorted1=sortrows(RN3L Degree temp1)

subplot(233)hold onplot(RN3L Degree sorted1(1)b)plot(RN3L Degree sorted1(2)g)grid ontitle(RN3L)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)

RN1S DegreeG1=(RN1S EdgesG)(RN1S NodesG)RN1S DegreeG Hat1=(RN1S EdgesG Hat)(RN1S NodesG hat)

RN1S Degree temp1(1)=RN1S DegreeG1RN1S Degree temp1(2)=RN1S DegreeG Hat1RN1S Degree sorted1=sortrows(RN1S Degree temp1)

subplot(234)hold onplot(RN1S Degree sorted1(1)b)plot(RN1S Degree sorted1(2)g)grid ontitle(RN1S)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)

RN2S DegreeG1=(RN2S EdgesG)(RN2S NodesG)RN2S DegreeG Hat1=(RN2S EdgesG Hat)(RN2S NodesG hat)

RN2S Degree temp1(1)=RN2S DegreeG1

62 Application

RN2S Degree temp1(2)=RN2S DegreeG Hat1RN2S Degree sorted1=sortrows(RN2S Degree temp1)

subplot(235)hold onplot(RN2S Degree sorted1(1)b)plot(RN2S Degree sorted1(2)g)grid ontitle(RN2S)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)

RN3S DegreeG1=(RN3S EdgesG)(RN3S NodesG)RN3S DegreeG Hat1=(RN3S EdgesG Hat)(RN3S NodesG hat)

RN3S Degree temp1(1)=RN3S DegreeG1RN3S Degree temp1(2)=RN3S DegreeG Hat1RN3S Degree sorted1=sortrows(RN3S Degree temp1)

subplot(236)hold onplot(RN3S Degree sorted1(1)b)plot(RN3S Degree sorted1(2)g)grid ontitle(RN3S)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)set(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN6png minusr300)h(7)=figure(NameSorted mATCHED DEGREENumberTitleoff)RN1L ratioMax(1)=RN1L MaxDegreeGRN1L ratioMax(2)=RN1L MaxDegreeG Hat

RN1L ratio sortedMax=sortrows(RN1L ratioMax)subplot(231)hold onplot(RN1L ratio sortedMax(1)b)plot(RN1L ratio sortedMax(2)g)grid ontitle(RN1L)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)

RN2L ratioMax(1)=RN2L MaxDegreeGRN2L ratioMax(2)=RN2L MaxDegreeG Hat

RN2L ratio sortedMax=sortrows(RN2L ratioMax)subplot(232)

Appendix A 63

hold onplot(RN2L ratio sortedMax(1)b)plot(RN2L ratio sortedMax(2)g)grid ontitle(RN2L)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)

RN3L ratioMax(1)=RN3L MaxDegreeGRN3L ratioMax(2)=RN3L MaxDegreeG Hat

RN3L ratio sortedMax=sortrows(RN3L ratioMax)subplot(233)hold onplot(RN3L ratio sortedMax(1)b)plot(RN3L ratio sortedMax(2)g)grid ontitle(RN3L)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)

RN1S ratioMax(1)=RN1S MaxDegreeGRN1S ratioMax(2)=RN1S MaxDegreeG Hat

RN1S ratio sortedMax=sortrows(RN1S ratioMax)subplot(234)hold onplot(RN1S ratio sortedMax(1)b)plot(RN1S ratio sortedMax(2)g)grid ontitle(RN1S)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)

RN2S ratioMax(1)=RN2S MaxDegreeGRN2S ratioMax(2)=RN2S MaxDegreeG Hat

RN2S ratio sortedMax=sortrows(RN2S ratioMax)

subplot(235)hold onplot(RN2S ratio sortedMax(1)b)plot(RN2S ratio sortedMax(2)g)grid ontitle(RN2S)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)

RN3S ratioMax(1)=RN3S MaxDegreeGRN3S ratioMax(2)=RN3S MaxDegreeG Hat

64 Application

RN3S ratio sortedMax=sortrows(RN3S ratioMax)subplot(236)hold onplot(RN3S ratio sortedMax(1)b)plot(RN3S ratio sortedMax(2)g)grid ontitle(RN1L)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)set(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN7png minusr300)

tilefigs()(h)

Bibliography

[1] C Berge ldquoTWO THEOREMS IN GRAPH THEORYrdquo Proceedings of the NationalAcademy of Sciences of the United States of America vol 43 no 9 pp 842ndash844Sep 1957

[2] L Bui S Sanghavi and R Srikant ldquoDistributed link scheduling with constantoverheadrdquo IEEEACM Trans Netw vol 17 no 5 pp 1467ndash1480 2009

[3] R Duan and S Pettie ldquoLinear-time approximation for maximum weight matchingrdquoJ ACM vol 61 no 1 2014

[4] J Edmonds ldquoPaths trees and flowersrdquo Canadian Journal of Mathematics vol 17pp 449ndash467 1965

[5] J E Hopcroft and R M Karp ldquoAn n52 algorithm for maximum matchings inbipartite graphsrdquo SIAM J Comput vol 2 no 4 pp 225ndash231 1973

[6] S Micali and V V Vazirani ldquoAn O(radic|V ||E|) algorithm for finding maximum

matching in general graphsrdquo in 21st Symp on Foundations of Comp Sc (FOCS)IEEE 1980 pp 17ndash27

[7] N Nisse A Salch and V Weber ldquoRecovery of disrupted airline operationsrdquo 2015httphalinriafrSomething

[8] X Wu and R Srikant ldquoRegulated maximal matching A distributed schedulingalgorithm for multi-hop wireless networks with nodeexclusive spectrum sharingrdquo inIEEE Conf on Decision and Control 2005

65

  • Contents
  • Introduction
  • Algorithms
    • Maximum matching
    • k-maximum matching
      • k-matching for Airport Slot assignment
      • The case where k=3
      • The case of Paths
      • The case of the Spider
          • Application
            • Description
            • Reyni Erdos
            • Barabaacutesi Albert
            • Amadeus Graphs
            • Bipartite
            • Bipartite with degree seq
            • Appendix A
              • BipartiteGraphGeneratorpy
              • RandomGraphGeneratorpy
              • kequals3MaximumMatchingpy
              • Plotmat
                  • Bibliography
Page 37: Theodoros Alexandros KARAGKIOULES -  · Introduction This work is the result of a 6 months internship, under the supervision of research O cer Nicolas NISSE. The original scope of

38 Application

Sorted ∆-Comments

bull Big difference in max degree in large initial matching

bull Almost identical behaviour in the case of small initial matching

Appendix A 39

Appendix A

BipartiteGraphGeneratorpy

from future import divisionimport networkx as nx

from networkxalgorithms import approximationimport collectionsimport randomimport mathfrom networkxalgorithms import bipartiteif name == main

for i in range(1481)waqs 481index=1n=randomrandint(100 1000)

n1=95 was 500me1=118

n2=251 was 500me2=903

n3=165 was 500me3=412

m=0m1=0p=randomrandom()p1=18250p2=25250p3=34250print ip=05t1=randomrandint(0 1)print im2=randomrandint(n2minus1 n2+1)G = nxGraph()ma = nxGraph()

aseq1=[1 2 3 4 5 3]

bseq1=[4 3 3 1 2 2 1]

aseq2=[16 14 14 14 12 11]bseq2=[0 0 0 0 0 0]

aseq3=[8 7 8 8 8 8]bseq3=[0 0 0 0 0 0]

40 Application

print Gnumber of edges()if ilt=160

G=bipartiteconfiguration model(aseq1 bseq1 create using=None seed=None)A=nxadjacency matrix(G)for ii in range(0n1+me1)

maadd node(ii)A=[Rtodense()tolist()[0] for R in A]

printnummanumber of nodes()rl=randomsample(range(0n1+me1) n1+me1)m=0done vertices = set()for p in rlprintin fordone verticesadd(p)

neighbors = []list()for iii in range(0n1+me1)

if A[p][iii]==1neighborsappend(iii)

randomshuffle(neighbors)continue loop = Truedegree = len(neighbors)

print degreej = 0p4=randomrandom()while continue loop and (jltdegree)print in loop

next = neighbors[j]if next not in done vertices and p not in done vertices

done verticesadd(p)done verticesadd(next)if p4gt=07print added edge

maadd edge(pnext)m=m+1

continue loop = Falsej += 1

print matching listOfedgeprint maedge

MA=nxadjacency matrix(ma)print MA

MA=[Rtodense()tolist()[0] for R in MA]print MA

B=[ join(map(strR)) for R in A]MB=[ join(map(strR)) for R in MA]

C=njoin(B)+nMC=njoin(MB)+n

print nprint mprint m1

filea=str(i)+txtwith open(fileaw) as f

Appendix A 41

fwrite(str(n1+me1))fwrite(n)fwrite(str(n1+me1))fwrite(n)fwrite(str(m))fwrite(n)fwrite(n)fwrite(C)fwrite(n)fwrite(MC)

elif igt160 and ilt321G=bipartiteconfiguration model(aseq2 bseq2 create using=None seed=None)A=nxadjacency matrix(G)for ii in range(0n2+me2)

maadd node(ii)A=[Rtodense()tolist()[0] for R in A]

printnummanumber of nodes()rl=randomsample(range(0n2+me2) n2+me2)m=0done vertices = set()for p in rlprintin fordone verticesadd(p)

neighbors = []list()for iii in range(0n2+me2)

if A[p][iii]==1neighborsappend(iii)

randomshuffle(neighbors)continue loop = Truedegree = len(neighbors)

print degreej = 0p4=randomrandom()while continue loop and (jltdegree)

print in loopnext = neighbors[j]if next not in done vertices and p not in done vertices

done verticesadd(p)done verticesadd(next)if p4gt=07

print added edgemaadd edge(pnext)m=m+1

continue loop = Falsej += 1

print matching listOfedgeprint maedge

MA=nxadjacency matrix(ma)print MA

MA=[Rtodense()tolist()[0] for R in MA]print MA

B=[ join(map(strR)) for R in A]MB=[ join(map(strR)) for R in MA]

42 Application

C=njoin(B)+nMC=njoin(MB)+n

print nprint mprint m1

filea=str(i)+txtwith open(fileaw) as f

fwrite(str(n2+me2))fwrite(n)fwrite(str(n2+me2))fwrite(n)fwrite(str(m))fwrite(n)fwrite(n)fwrite(C)fwrite(n)fwrite(MC)

elseG=bipartiteconfiguration model(aseq3 bseq3 create using=None seed=None)A=nxadjacency matrix(G)for ii in range(0n3+me3)

maadd node(ii)A=[Rtodense()tolist()[0] for R in A]

printnummanumber of nodes()rl=randomsample(range(0n3+me3) n3+me3)m=0done vertices = set()for p in rlprintin fordone verticesadd(p)

neighbors = []list()for iii in range(0n3+me3)

if A[p][iii]==1neighborsappend(iii)

randomshuffle(neighbors)continue loop = Truedegree = len(neighbors)

print degreej = 0p4=randomrandom()while continue loop and (jltdegree)

print in loopnext = neighbors[j]if next not in done vertices and p not in done vertices

done verticesadd(p)done verticesadd(next)if p4gt=07print added edge

maadd edge(pnext)m=m+1

continue loop = Falsej += 1

Appendix A 43

print matching listOfedgeprint maedge

MA=nxadjacency matrix(ma)print MA

MA=[Rtodense()tolist()[0] for R in MA]print MA

B=[ join(map(strR)) for R in A]MB=[ join(map(strR)) for R in MA]

C=njoin(B)+nMC=njoin(MB)+n

print nprint mprint m1

filea=str(i)+txtwith open(fileaw) as f

fwrite(str(n3+me3))fwrite(n)fwrite(str(n3+me3))fwrite(n)fwrite(str(m))fwrite(n)fwrite(n)fwrite(C)fwrite(n)fwrite(MC)

print nRandom graphs with random matching have been generated

44 Application

RandomGraphGeneratorpy

from future import divisionimport networkx as nxfrom networkxalgorithms import approximationimport collectionsimport randomimport mathif name == main

for i in range(1481)index=1n=randomrandint(100 1000)

n=1000m=0m1=0p=randomrandom()p1=mathlog(n2)np2=13p3=mathlog(n2)n+01p=05t1=randomrandint(0 1)print im2=randomrandint(n2minus1 n2+1)G = nxGraph()ma = nxGraph()print nme1=randomrandint(1 10)me2=randomrandint(2050)me3=randomrandint(50100)if ilt241

if ilt=80G=nxfast gnp random graph(n p1 seed=None directed=False)

elif igt80 and ilt161G=nxfast gnp random graph(n p2 seed=None directed=False)

elseG=nxfast gnp random graph(n p3 seed=None directed=False)

elseif ilt=320

G=nxbarabasi albert graph(n me1 seed=None)elif igt320 and ilt401

G=nxbarabasi albert graph(n me2 seed=None)else

G=nxbarabasi albert graph(n me3 seed=None)A=nxadjacency matrix(G)for ii in range(0n)

maadd node(ii)A=[Rtodense()tolist()[0] for R in A]

rl=randomsample(range(0n) n)m=0

Appendix A 45

done vertices = set()for p in rl

done verticesadd(p)neighbors = []list()for iii in range(0n)

if A[p][iii]==1neighborsappend(iii)

randomshuffle(neighbors)continue loop = Truedegree = len(neighbors)j = 0p2=randomrandom()while continue loop and (jltdegree)

next = neighbors[j]if next not in done vertices and p not in done vertices

done verticesadd(p)done verticesadd(next)if p2gt=00 Larger probability for smaller initial matching

maadd edge(pnext)m=m+1

continue loop = Falsej += 1

print matching listOfedgeprint maedgeMA=nxadjacency matrix(ma)MA=[Rtodense()tolist()[0] for R in MA]print MAB=[ join(map(strR)) for R in A]MB=[ join(map(strR)) for R in MA]

C=njoin(B)+nMC=njoin(MB)+nprint MCprint nprint mprint m1filea=str(i)+txtwith open(fileaw) as f

fwrite(str(n))fwrite(n)fwrite(str(n))fwrite(n)fwrite(str(m))fwrite(n)fwrite(n)fwrite(C)fwrite(n)fwrite(MC)

print nRandom graphs with random matching have been generated

46 Application

kequals3MaximumMatchingpy

from future import divisionimport networkx as nxfrom networkxalgorithms import bipartiteimport matplotlibpyplot as pltimport collectionsimport timeitimport xlwtimport xlrdimport mathimport sys

Case for General Graphsdef forced edges(Gadj dict2matching dict1num nodesforced)

flagg=0for n in range(0num nodes)

for k in adj dict2[n]if ([k]==matching dict1[n])

count=0for l in range(0num nodes)

count=count+adj dict2[l]count(k)if (len(adj dict2[n])==1) or (count==1)

forcedadd edge(nk)Gremove edge(nk)Gremove node(n)Gremove node(k)printforced edgenktemp=kflagg=1for m in range (len(adj dict2[n])minus1minus1minus1)

adj dict2[adj dict2[n][m]]remove(n)adj dict2[n]remove(adj dict2[n][m])

if adj dict2[temp]for l in range(len(adj dict2[temp])minus1minus1minus1)

if (adj dict2[temp][l]=n)adj dict2[adj dict2[temp][l]]remove(temp)adj dict2[temp]remove(adj dict2[temp][l])

break

def useless edges(num nodesadj dict1matching dict1uselessadj dict2G)for n in range(0num nodes)

for k in adj dict1[n]if ([k]=matching dict1[n]) and matching dict1[n] and matching dict1[k]

uselessadd edge(nk)Gremove edge(n k)

Appendix A 47

tempa=kadj dict2[n]remove(k)adj dict2[tempa]remove(n)adj dict1[tempa]remove(n)

return G

def Greedy(num nodesadj dict3matching dict2)

for n in range(0num nodes)if matching dict2[n]

flag2=minus1flag3=minus1for v in adj dict3[n]

if not matching dict2[v]flag2=vbreak

for p in adj dict3[matching dict2[n][0]]if not matching dict2[p]

flag3=pbreak

if (flag2=minus1) and (flag3=minus1) and (flag2=flag3)tempr=matching dict2[n][0]matching dict2[n]=[flag2]matching dict2[flag2]=[n]matching dict2[tempr]=[flag3]matching dict2[flag3]=[tempr]

elsefor k in adj dict3[n]

if not matching dict2[k]matching dict2[n]=[k]matching dict2[k]=[n]break

yo1=0for i in range(0num nodes)

if matching dict2[i] and [i]==matching dict2[matching dict2[i][0]]yo1=yo1+1

greedy size=yo12return greedy size

def General()

INPUTSwb = xlwtWorkbook()ws = wbadd sheet(Results Random)book=xlrdopen workbook(filenames randomxls)

48 Application

style0 = xlwteasyxf(fontbold on)style1 = xlwteasyxf(num format str=0000)INPUTSwswrite(0 0File style0)wswrite(0 1 Nodesstyle0)wswrite(0 2 Initial matchingstyle0)wswrite(0 3 NodesGstyle0)wswrite(0 4 EdgesGstyle0)wswrite(0 5 MaxDegreeGstyle0)wswrite(0 6 NodesG hatstyle0)wswrite(0 7 EdgesG Hatstyle0)wswrite(0 8 Useless edgesstyle0)wswrite(0 9 Forced edgesstyle0)wswrite(0 10 MaxDegreeG Hatstyle0)wswrite(0 11 Classical matchingstyle0)wswrite(0 12 Final matchingstyle0)wswrite(0 13 Greedy matchingstyle0)wswrite(0 14 Time classicalstyle0)wswrite(0 15 Time algorithmstyle0)wswrite(0 16 Time greedystyle0)wswrite(0 17 Perfect matching ratiostyle0)wswrite(0 18 Nodes ratiostyle0)wswrite(0 19 Edges ratiostyle0)wswrite(0 20 Matching ratiostyle0)

print nWelcomeThis is an implementation for general random graphs It uses Edmonds algorithm to compute maximum matching on G Hatn

for index in range (1481)was 481

if (index==482)f=open(Algotel generaltxtr)readlines()

elsefilea=str(booksheet by index(0)cell(index0))s=fileareplace(textu)replace()f=open(sr)readlines()Truewswrite(index 0 s)

print index

num nodes=int([xstrip()split() for x in f][0][0])

num matching=int([xstrip()split() for x in f][2][0])

adj temp = [xstrip()split() for x in f][44+num nodes]adj=[map(intR) for R in adj temp]

matching temp=[xstrip()split() for x in f][4+num nodes+14+2num nodes+1]matching1=[map(intR) for R in matching temp]

adj dict1=i[ii for iix in enumerate(L) if x] for iL in enumerate(adj)adj dict2=i[ii for iix in enumerate(L) if x] for iL in enumerate(adj)

Appendix A 49

adj dict3=i[ii for iix in enumerate(L) if x] for iL in enumerate(adj)

matching dict1=i[ii for iix in enumerate(L) if x] for iL in enumerate(matching1)matching dict2=i[ii for iix in enumerate(L) if x] for iL in enumerate(matching1)print adj dict2print matching dict2wswrite(index 1 num nodes)wswrite(index 2 num matching)

G = nxGraph()

useless= nxGraph()forced = nxGraph()

Fill Graphfor n in range(0num nodes)

for k in adj dict1[n]Gadd edge(nk)

Gt=Gnumber of edges()wswrite(index 3 Gnumber of nodes())wswrite(index 4 Gnumber of edges())wswrite(index 5 max(Gdegree()values()))

Compute Edmonds classical matching on G for comparison

startB = timeitdefault timer()Classical Matching=nxmax weight matching(G maxcardinality=False)stopB = timeitdefault timer()

Compute Gˆ nad MˆstartC = timeitdefault timer()useless edges(num nodesadj dict1matching dict1uselessadj dict2G)forced edges(Gadj dict2matching dict1num nodesforced)Final Matching=nxmax weight matching(G maxcardinality=False)stopC = timeitdefault timer()

GreedystartG = timeitdefault timer()greedy size=Greedy(num nodesadj dict3matching dict2)stopG = timeitdefault timer()

wswrite(index 6 Gnumber of nodes())wswrite(index 7 Gnumber of edges())wswrite(index 8 uselessnumber of edges())wswrite(index 9 forcednumber of edges())if Gdegree()values()

wswrite(index 10 max(Gdegree()values()))else

50 Application

wswrite(index 10 0)wswrite(index 11 len(Classical Matching)2)wswrite(index 12 len(Final Matching)2+forcednumber of edges())wswrite(index 13 greedy size)wswrite(index 14 stopB minus startBstyle1)wswrite(index 15 stopC minus startCstyle1)wswrite(index 16 stopG minus startGstyle1)wswrite(index 17 (len(Final Matching)2+forcednumber of edges())(num nodes2)style1)wswrite(index 18 Gnumber of nodes()Gtstyle1)wswrite(index 19 Gnumber of edges()Gtstyle1)wswrite(index 20 (len(Final Matching)2+forcednumber of edges())(len(Classical Matching)2)style1)

wbsave(AA Results Random Reyni Large Bipartitexls)

Main function Here we must choose the input form of the dataif name == main

startA = timeitdefault timer()General()stopA = timeitdefault timer()

print nThis program has terminatednnRunning time for 480 files stopAminusstartAprint nnPlease open AA Results Random Reyni Largexls file to see the Results

Appendix A 51

Plotmat

clear allclose allload(RN1Lmat)load(RN1Smat)load(RN2Lmat)load(RN2Smat)load(RN3Lmat)load(RN3Smat)

Plotsh(1)=figure(NameHistogram of Matching size difference between Constraint Algorithm and Greedy AlgorithmNumberTitleoff)

RN1L Greedydiff=RN1L Final matchingminusRN1L Greedy matchingRN2L Greedydiff=RN2L Final matchingminusRN2L Greedy matchingRN3L Greedydiff=RN3L Final matchingminusRN3L Greedy matchingRN1S Greedydiff=RN1S Final matchingminusRN1S Greedy matchingRN2S Greedydiff=RN2S Final matchingminusRN2S Greedy matchingRN3S Greedydiff=RN3S Final matchingminusRN3S Greedy matching

RN1L Finaldiff=RN1L Classical matchingminusRN1L Final matchingRN2L Finaldiff=RN2L Classical matchingminusRN2L Final matchingRN3L Finaldiff=RN3L Classical matchingminusRN3L Final matchingRN1S Finaldiff=RN1S Classical matchingminusRN1S Final matchingRN2S Finaldiff=RN2S Classical matchingminusRN2S Final matchingRN3S Finaldiff=RN3S Classical matchingminusRN3S Final matching

RN1L Classicaldiff=(RN1L Nodes2)minusRN1L Classical matchingRN2L Classicaldiff=(RN2L Nodes2)minusRN2L Classical matchingRN3L Classicaldiff=(RN3L Nodes2)minusRN3L Classical matchingRN1S Classicaldiff=(RN1S Nodes2)minusRN1S Classical matchingRN2S Classicaldiff=(RN2S Nodes2)minusRN2S Classical matchingRN3S Classicaldiff=(RN3S Nodes2)minusRN3S Classical matching

subplot(231)hold onhistf(RN1L Greedydiff0110facecolorbfacealpha9edgealpha1)histf(RN1L Finaldiff0110facecolorrfacealpha5edgealpha1)histf(RN1L Classicaldiff0110facecolorgfacealpha5edgealpha1)legalpha(ConminusGreClasminusConPerfminusClasslocationnortheast)legend boxoffaxis tightxlabel(edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN1L)grid on

subplot(232)hold onhistf(RN2L Greedydiff0110facecolorbfacealpha9edgealpha1)

52 Application

histf(RN2L Finaldiff0110facecolorrfacealpha5edgealpha1)histf(RN2L Classicaldiff0110facecolorgfacealpha5edgealpha1)legalpha(ConminusGreClasminusConPerfminusClasslocationnortheast)legend boxoffaxis tightxlabel(edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN2L)grid on

subplot(233)hold onhistf(RN3L Greedydiff0110facecolorbfacealpha5edgealpha1)histf(RN3L Finaldiff0110facecolorrfacealpha5edgealpha1)histf(RN3L Classicaldiff0110facecolorgfacealpha5edgealpha1)legalpha(ConminusGreClasminusConPerfminusClasslocationnortheast)legend boxoffaxis tightxlabel(edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN3L)grid on

subplot(234)hold onhistf(RN1S Greedydiff0110facecolorbfacealpha5edgealpha1)histf(RN1S Finaldiff0110facecolorrfacealpha5edgealpha1)histf(RN1S Classicaldiff0110facecolorgfacealpha5edgealpha1)legalpha(ConminusGreClasminusConPerfminusClasslocationnortheast)legend boxoffaxis tightxlabel(edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(R1NS)grid on

subplot(235)hold onhistf(RN2S Greedydiff0110facecolorbfacealpha5edgealpha1)histf(RN2S Finaldiff0110facecolorrfacealpha5edgealpha1)histf(RN2S Classicaldiff0110facecolorgfacealpha5edgealpha1)legalpha(ConminusGreClasminusConPerfminusClasslocationnortheast)legend boxoffaxis tightxlabel(edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN2S)grid on

subplot(236)hold onhistf(RN3S Greedydiff0110facecolorbfacealpha5edgealpha1)histf(RN3S Finaldiff0110facecolorrfacealpha5edgealpha1)histf(RN3S Classicaldiff0110facecolorgfacealpha5edgealpha1)

Appendix A 53

legalpha(ConminusGreClasminusConPerfminusClasslocationnortheast)legend boxoffaxis tightgrid ontitle(RN3S)xlabel(edges) xminusaxis labelylabel(instances) yminusaxis labelset(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN1png minusr300)h(2)=figure(NameHistogram of Max Degree of G AND G HatNumberTitleoff)RN1L x=RN1L MaxDegreeGminusRN1L MaxDegreeG HatRN2L x=RN2L MaxDegreeGminusRN2L MaxDegreeG HatRN3L x=RN3L MaxDegreeGminusRN3L MaxDegreeG HatRN1S x=RN1S MaxDegreeGminusRN1S MaxDegreeG HatRN2S x=RN2S MaxDegreeGminusRN2S MaxDegreeG HatRN3S x=RN3S MaxDegreeGminusRN3S MaxDegreeG Hatsubplot(231)hold onhistf(RN1L MaxDegreeG0150facecolorbfacealpha5edgealpha1)histf(RN1L MaxDegreeG Hat0150facecolorrfacealpha5edgealpha1)histf(RN1L x0150facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightxlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN1L)grid on

subplot(232)hold onhistf(RN2L MaxDegreeG010500facecolorbfacealpha5edgealpha1)histf(RN2L MaxDegreeG Hat010500facecolorrfacealpha5edgealpha1)histf(RN2L x010500facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightxlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN2L)grid on

subplot(233)hold onhistf(RN3L MaxDegreeG010300facecolorbfacealpha5edgealpha1)histf(RN3L MaxDegreeG Hat010300facecolorrfacealpha5edgealpha1)histf(RN3L x010300facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightxlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN3L)

54 Application

grid on

subplot(234)hold onhistf(RN1S MaxDegreeG0150facecolorbfacealpha5edgealpha1)histf(RN1S MaxDegreeG Hat0150facecolorrfacealpha5edgealpha1)histf(RN1S x0150facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightxlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(R1NS)grid on

subplot(235)hold onhistf(RN2S MaxDegreeG010500facecolorbfacealpha5edgealpha1)histf(RN2S MaxDegreeG Hat010500facecolorrfacealpha5edgealpha1)histf(RN2S x010500facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightxlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN2S)grid on

subplot(236)hold onhistf(RN3S MaxDegreeG05300facecolorbfacealpha5edgealpha1)histf(RN3S MaxDegreeG Hat05300facecolorrfacealpha5edgealpha1)histf(RN3S x05300facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightgrid ontitle(RN3S)xlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labelset(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN2png minusr300)

h(3)=figure(NameComputation time over edgesNumberTitleoff)

subplot(231)hold onstem(RN1L EdgesGRN1L Time classicalg)stem(RN1L EdgesGRN1L Time algorithmro)stem(RN1L EdgesGRN1L Time greedybx)grid on

Appendix A 55

title(RN1L)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)

subplot(232)hold onstem(RN2L EdgesGRN2L Time classicalg)stem(RN2L EdgesGRN2L Time algorithmro)stem(RN2L EdgesGRN2L Time greedybx)grid ontitle(RN2L)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)

subplot(233)hold onstem(RN3L EdgesGRN3L Time classicalg)stem(RN3L EdgesGRN3L Time algorithmro)stem(RN3L EdgesGRN3L Time greedybx)grid ontitle(RN3L)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)

subplot(234)hold onstem(RN1S EdgesGRN1S Time classicalg)stem(RN1S EdgesGRN1S Time algorithmro)stem(RN1S EdgesGRN1S Time greedybx)grid ontitle(RN1S)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)

subplot(235)hold onstem(RN2S EdgesGRN2S Time classicalg)stem(RN2S EdgesGRN2S Time algorithmro)stem(RN2S EdgesGRN2S Time greedybx)grid ontitle(RN2S)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)

subplot(236)hold onstem(RN3S EdgesGRN3S Time classicalg)stem(RN3S EdgesGRN3S Time algorithmro)stem(RN3S EdgesGRN3S Time greedybx)

56 Application

grid ontitle(RN3S)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)set(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN3png minusr300)

h(4)=figure(NameSorted matching sizeNumberTitleoff)RN1L Sorted matching temp(1)=RN1L Classical matchingRN1L Sorted matching temp(2)=RN1L Final matchingRN1L Sorted matching temp(3)=RN1L Greedy matchingRN1L Sorted matching temp(4)=RN1L Initial matchingRN1L Sorted matching=sortrows(RN1L Sorted matching temp)

RN2L Sorted matching temp(1)=RN2L Classical matchingRN2L Sorted matching temp(2)=RN2L Final matchingRN2L Sorted matching temp(3)=RN2L Greedy matchingRN2L Sorted matching temp(4)=RN2L Initial matchingRN2L Sorted matching=sortrows(RN2L Sorted matching temp)

RN3L Sorted matching temp(1)=RN3L Classical matchingRN3L Sorted matching temp(2)=RN3L Final matchingRN3L Sorted matching temp(3)=RN3L Greedy matchingRN3L Sorted matching temp(4)=RN3L Initial matchingRN3L Sorted matching=sortrows(RN3L Sorted matching temp)

RN1S Sorted matching temp(1)=RN1S Classical matchingRN1S Sorted matching temp(2)=RN1S Final matchingRN1S Sorted matching temp(3)=RN1S Greedy matchingRN1S Sorted matching temp(4)=RN1S Initial matchingRN1S Sorted matching=sortrows(RN1S Sorted matching temp)

RN2S Sorted matching temp(1)=RN2S Classical matchingRN2S Sorted matching temp(2)=RN2S Final matchingRN2S Sorted matching temp(3)=RN2S Greedy matchingRN2S Sorted matching temp(4)=RN2S Initial matchingRN2S Sorted matching=sortrows(RN2S Sorted matching temp)

RN3S Sorted matching temp(1)=RN3S Classical matchingRN3S Sorted matching temp(2)=RN3S Final matchingRN3S Sorted matching temp(3)=RN3S Greedy matchingRN3S Sorted matching temp(4)=RN3S Initial matchingRN3S Sorted matching=sortrows(RN3S Sorted matching temp)

subplot(231)hold onplot(RN1L Sorted matching(1)b)plot(RN1L Sorted matching(2)g)plot(RN1L Sorted matching(3)r)plot(RN1L Sorted matching(4)m)

Appendix A 57

grid ontitle(RN1L)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)

subplot(232)hold onplot(RN2L Sorted matching(1)b)plot(RN2L Sorted matching(2)g)plot(RN2L Sorted matching(3)r)plot(RN2L Sorted matching(4)m)grid ontitle(RN2L)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)

subplot(233)hold onplot(RN3L Sorted matching(1)b)plot(RN3L Sorted matching(2)g)plot(RN3L Sorted matching(3)r)plot(RN3L Sorted matching(4)m)grid ontitle(RN3L)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)

subplot(234)hold onplot(RN1S Sorted matching(1)b)plot(RN1S Sorted matching(2)g)plot(RN1S Sorted matching(3)r)plot(RN1S Sorted matching(4)m)grid ontitle(RN1S)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)

subplot(235)hold onplot(RN2S Sorted matching(1)b)plot(RN2S Sorted matching(2)g)plot(RN2S Sorted matching(3)r)plot(RN2S Sorted matching(4)m)grid ontitle(RN2S)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)

58 Application

subplot(236)hold onplot(RN3S Sorted matching(1)b)plot(RN3S Sorted matching(2)g)plot(RN3S Sorted matching(3)r)plot(RN3S Sorted matching(4)m)grid ontitle(RN3S)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)set(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN4png minusr300)h(5)=figure(NameSorted RatiosNumberTitleoff)RN1L ratio1=RN1L NodesG hatRN1L NodesGRN2L ratio1=RN2L NodesG hatRN2L NodesGRN3L ratio1=RN3L NodesG hatRN3L NodesGRN1S ratio1=RN1S NodesG hatRN1S NodesGRN2S ratio1=RN2S NodesG hatRN2S NodesGRN3S ratio1=RN3S NodesG hatRN3S NodesG

RN1L ratio2=RN1L EdgesG HatRN1L EdgesGRN2L ratio2=RN2L EdgesG HatRN2L EdgesGRN3L ratio2=RN3L EdgesG HatRN3L EdgesGRN1S ratio2=RN1S EdgesG HatRN1S EdgesGRN2S ratio2=RN2S EdgesG HatRN2S EdgesGRN3S ratio2=RN3S EdgesG HatRN3S EdgesG

RN1L ratio3=RN1L MaxDegreeG HatRN1L MaxDegreeGRN2L ratio3=RN2L MaxDegreeG HatRN2L MaxDegreeGRN3L ratio3=RN3L MaxDegreeG HatRN3L MaxDegreeGRN1S ratio3=RN1S MaxDegreeG HatRN1S MaxDegreeGRN2S ratio3=RN2S MaxDegreeG HatRN2S MaxDegreeGRN3S ratio3=RN3S MaxDegreeG HatRN3S MaxDegreeG

RN1L ratio(1)=RN1L ratio1RN1L ratio(2)=RN1L ratio2RN1L ratio(3)=RN1L ratio3

RN2L ratio(1)=RN2L ratio1RN2L ratio(2)=RN2L ratio2RN2L ratio(3)=RN2L ratio3

RN3L ratio(1)=RN3L ratio1RN3L ratio(2)=RN3L ratio2RN3L ratio(3)=RN3L ratio3

RN1S ratio(1)=RN1S ratio1RN1S ratio(2)=RN1S ratio2RN1S ratio(3)=RN1S ratio3

RN2S ratio(1)=RN2S ratio1

Appendix A 59

RN2S ratio(2)=RN2S ratio2RN2S ratio(3)=RN2S ratio3

RN3S ratio(1)=RN3S ratio1RN3S ratio(2)=RN3S ratio2RN3S ratio(3)=RN3S ratio3

RN1L ratio sorted=sortrows(RN1L ratio)RN2L ratio sorted=sortrows(RN2L ratio)RN3L ratio sorted=sortrows(RN3L ratio)RN1S ratio sorted=sortrows(RN1S ratio)RN2S ratio sorted=sortrows(RN2S ratio)RN3S ratio sorted=sortrows(RN3S ratio)

subplot(231)hold onplot(RN1L ratio sorted(1)b)plot(RN1L ratio sorted(2)g)plot(RN1L ratio sorted(3)r)grid ontitle(RN1L)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)

subplot(232)hold onplot(RN2L ratio sorted(1)b)plot(RN2L ratio sorted(2)g)plot(RN2L ratio sorted(3)r)grid ontitle(RN2L)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)

subplot(233)hold onplot(RN3L ratio sorted(1)b)plot(RN3L ratio sorted(2)g)plot(RN3L ratio sorted(3)r)grid ontitle(RN3L)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)

subplot(234)hold onplot(RN1S ratio sorted(1)b)plot(RN1S ratio sorted(2)g)plot(RN1S ratio sorted(3)r)grid on

60 Application

title(RN1S)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)

subplot(235)hold onplot(RN2S ratio sorted(1)b)plot(RN2S ratio sorted(2)g)plot(RN2S ratio sorted(3)r)grid ontitle(RN2S)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)

subplot(236)hold onplot(RN3S ratio sorted(1)b)plot(RN3S ratio sorted(2)g)plot(RN3S ratio sorted(3)r)grid ontitle(RN3S)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)set(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN5png minusr300)

h(6)=figure(NameSorted edges over nodesNumberTitleoff)

RN1L DegreeG1=(RN1L EdgesG)(RN1L NodesG)RN1L DegreeG Hat1=(RN1L EdgesG Hat)(RN1L NodesG hat)

RN1L Degree temp1(1)=RN1L DegreeG1RN1L Degree temp1(2)=RN1L DegreeG Hat1RN1L Degree sorted1=sortrows(RN1L Degree temp1)subplot(231)hold on

plot(RN1L Degree sorted1(1)b)plot(RN1L Degree sorted1(2)g)grid ontitle(RN1L)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)

RN2L DegreeG1=(RN2L EdgesG)(RN2L NodesG)RN2L DegreeG Hat1=(RN2L EdgesG Hat)(RN2L NodesG hat)

RN2L Degree temp1(1)=RN2L DegreeG1

Appendix A 61

RN2L Degree temp1(2)=RN2L DegreeG Hat1RN2L Degree sorted1=sortrows(RN2L Degree temp1)

subplot(232)hold onplot(RN2L Degree sorted1(1)b)plot(RN2L Degree sorted1(2)g)grid ontitle(RN2L)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)

RN3L DegreeG1=(RN3L EdgesG)(RN3L NodesG)RN3L DegreeG Hat1=(RN3L EdgesG Hat)(RN3L NodesG hat)

RN3L Degree temp1(1)=RN3L DegreeG1RN3L Degree temp1(2)=RN3L DegreeG Hat1RN3L Degree sorted1=sortrows(RN3L Degree temp1)

subplot(233)hold onplot(RN3L Degree sorted1(1)b)plot(RN3L Degree sorted1(2)g)grid ontitle(RN3L)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)

RN1S DegreeG1=(RN1S EdgesG)(RN1S NodesG)RN1S DegreeG Hat1=(RN1S EdgesG Hat)(RN1S NodesG hat)

RN1S Degree temp1(1)=RN1S DegreeG1RN1S Degree temp1(2)=RN1S DegreeG Hat1RN1S Degree sorted1=sortrows(RN1S Degree temp1)

subplot(234)hold onplot(RN1S Degree sorted1(1)b)plot(RN1S Degree sorted1(2)g)grid ontitle(RN1S)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)

RN2S DegreeG1=(RN2S EdgesG)(RN2S NodesG)RN2S DegreeG Hat1=(RN2S EdgesG Hat)(RN2S NodesG hat)

RN2S Degree temp1(1)=RN2S DegreeG1

62 Application

RN2S Degree temp1(2)=RN2S DegreeG Hat1RN2S Degree sorted1=sortrows(RN2S Degree temp1)

subplot(235)hold onplot(RN2S Degree sorted1(1)b)plot(RN2S Degree sorted1(2)g)grid ontitle(RN2S)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)

RN3S DegreeG1=(RN3S EdgesG)(RN3S NodesG)RN3S DegreeG Hat1=(RN3S EdgesG Hat)(RN3S NodesG hat)

RN3S Degree temp1(1)=RN3S DegreeG1RN3S Degree temp1(2)=RN3S DegreeG Hat1RN3S Degree sorted1=sortrows(RN3S Degree temp1)

subplot(236)hold onplot(RN3S Degree sorted1(1)b)plot(RN3S Degree sorted1(2)g)grid ontitle(RN3S)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)set(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN6png minusr300)h(7)=figure(NameSorted mATCHED DEGREENumberTitleoff)RN1L ratioMax(1)=RN1L MaxDegreeGRN1L ratioMax(2)=RN1L MaxDegreeG Hat

RN1L ratio sortedMax=sortrows(RN1L ratioMax)subplot(231)hold onplot(RN1L ratio sortedMax(1)b)plot(RN1L ratio sortedMax(2)g)grid ontitle(RN1L)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)

RN2L ratioMax(1)=RN2L MaxDegreeGRN2L ratioMax(2)=RN2L MaxDegreeG Hat

RN2L ratio sortedMax=sortrows(RN2L ratioMax)subplot(232)

Appendix A 63

hold onplot(RN2L ratio sortedMax(1)b)plot(RN2L ratio sortedMax(2)g)grid ontitle(RN2L)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)

RN3L ratioMax(1)=RN3L MaxDegreeGRN3L ratioMax(2)=RN3L MaxDegreeG Hat

RN3L ratio sortedMax=sortrows(RN3L ratioMax)subplot(233)hold onplot(RN3L ratio sortedMax(1)b)plot(RN3L ratio sortedMax(2)g)grid ontitle(RN3L)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)

RN1S ratioMax(1)=RN1S MaxDegreeGRN1S ratioMax(2)=RN1S MaxDegreeG Hat

RN1S ratio sortedMax=sortrows(RN1S ratioMax)subplot(234)hold onplot(RN1S ratio sortedMax(1)b)plot(RN1S ratio sortedMax(2)g)grid ontitle(RN1S)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)

RN2S ratioMax(1)=RN2S MaxDegreeGRN2S ratioMax(2)=RN2S MaxDegreeG Hat

RN2S ratio sortedMax=sortrows(RN2S ratioMax)

subplot(235)hold onplot(RN2S ratio sortedMax(1)b)plot(RN2S ratio sortedMax(2)g)grid ontitle(RN2S)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)

RN3S ratioMax(1)=RN3S MaxDegreeGRN3S ratioMax(2)=RN3S MaxDegreeG Hat

64 Application

RN3S ratio sortedMax=sortrows(RN3S ratioMax)subplot(236)hold onplot(RN3S ratio sortedMax(1)b)plot(RN3S ratio sortedMax(2)g)grid ontitle(RN1L)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)set(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN7png minusr300)

tilefigs()(h)

Bibliography

[1] C Berge ldquoTWO THEOREMS IN GRAPH THEORYrdquo Proceedings of the NationalAcademy of Sciences of the United States of America vol 43 no 9 pp 842ndash844Sep 1957

[2] L Bui S Sanghavi and R Srikant ldquoDistributed link scheduling with constantoverheadrdquo IEEEACM Trans Netw vol 17 no 5 pp 1467ndash1480 2009

[3] R Duan and S Pettie ldquoLinear-time approximation for maximum weight matchingrdquoJ ACM vol 61 no 1 2014

[4] J Edmonds ldquoPaths trees and flowersrdquo Canadian Journal of Mathematics vol 17pp 449ndash467 1965

[5] J E Hopcroft and R M Karp ldquoAn n52 algorithm for maximum matchings inbipartite graphsrdquo SIAM J Comput vol 2 no 4 pp 225ndash231 1973

[6] S Micali and V V Vazirani ldquoAn O(radic|V ||E|) algorithm for finding maximum

matching in general graphsrdquo in 21st Symp on Foundations of Comp Sc (FOCS)IEEE 1980 pp 17ndash27

[7] N Nisse A Salch and V Weber ldquoRecovery of disrupted airline operationsrdquo 2015httphalinriafrSomething

[8] X Wu and R Srikant ldquoRegulated maximal matching A distributed schedulingalgorithm for multi-hop wireless networks with nodeexclusive spectrum sharingrdquo inIEEE Conf on Decision and Control 2005

65

  • Contents
  • Introduction
  • Algorithms
    • Maximum matching
    • k-maximum matching
      • k-matching for Airport Slot assignment
      • The case where k=3
      • The case of Paths
      • The case of the Spider
          • Application
            • Description
            • Reyni Erdos
            • Barabaacutesi Albert
            • Amadeus Graphs
            • Bipartite
            • Bipartite with degree seq
            • Appendix A
              • BipartiteGraphGeneratorpy
              • RandomGraphGeneratorpy
              • kequals3MaximumMatchingpy
              • Plotmat
                  • Bibliography
Page 38: Theodoros Alexandros KARAGKIOULES -  · Introduction This work is the result of a 6 months internship, under the supervision of research O cer Nicolas NISSE. The original scope of

Appendix A 39

Appendix A

BipartiteGraphGeneratorpy

from future import divisionimport networkx as nx

from networkxalgorithms import approximationimport collectionsimport randomimport mathfrom networkxalgorithms import bipartiteif name == main

for i in range(1481)waqs 481index=1n=randomrandint(100 1000)

n1=95 was 500me1=118

n2=251 was 500me2=903

n3=165 was 500me3=412

m=0m1=0p=randomrandom()p1=18250p2=25250p3=34250print ip=05t1=randomrandint(0 1)print im2=randomrandint(n2minus1 n2+1)G = nxGraph()ma = nxGraph()

aseq1=[1 2 3 4 5 3]

bseq1=[4 3 3 1 2 2 1]

aseq2=[16 14 14 14 12 11]bseq2=[0 0 0 0 0 0]

aseq3=[8 7 8 8 8 8]bseq3=[0 0 0 0 0 0]

40 Application

print Gnumber of edges()if ilt=160

G=bipartiteconfiguration model(aseq1 bseq1 create using=None seed=None)A=nxadjacency matrix(G)for ii in range(0n1+me1)

maadd node(ii)A=[Rtodense()tolist()[0] for R in A]

printnummanumber of nodes()rl=randomsample(range(0n1+me1) n1+me1)m=0done vertices = set()for p in rlprintin fordone verticesadd(p)

neighbors = []list()for iii in range(0n1+me1)

if A[p][iii]==1neighborsappend(iii)

randomshuffle(neighbors)continue loop = Truedegree = len(neighbors)

print degreej = 0p4=randomrandom()while continue loop and (jltdegree)print in loop

next = neighbors[j]if next not in done vertices and p not in done vertices

done verticesadd(p)done verticesadd(next)if p4gt=07print added edge

maadd edge(pnext)m=m+1

continue loop = Falsej += 1

print matching listOfedgeprint maedge

MA=nxadjacency matrix(ma)print MA

MA=[Rtodense()tolist()[0] for R in MA]print MA

B=[ join(map(strR)) for R in A]MB=[ join(map(strR)) for R in MA]

C=njoin(B)+nMC=njoin(MB)+n

print nprint mprint m1

filea=str(i)+txtwith open(fileaw) as f

Appendix A 41

fwrite(str(n1+me1))fwrite(n)fwrite(str(n1+me1))fwrite(n)fwrite(str(m))fwrite(n)fwrite(n)fwrite(C)fwrite(n)fwrite(MC)

elif igt160 and ilt321G=bipartiteconfiguration model(aseq2 bseq2 create using=None seed=None)A=nxadjacency matrix(G)for ii in range(0n2+me2)

maadd node(ii)A=[Rtodense()tolist()[0] for R in A]

printnummanumber of nodes()rl=randomsample(range(0n2+me2) n2+me2)m=0done vertices = set()for p in rlprintin fordone verticesadd(p)

neighbors = []list()for iii in range(0n2+me2)

if A[p][iii]==1neighborsappend(iii)

randomshuffle(neighbors)continue loop = Truedegree = len(neighbors)

print degreej = 0p4=randomrandom()while continue loop and (jltdegree)

print in loopnext = neighbors[j]if next not in done vertices and p not in done vertices

done verticesadd(p)done verticesadd(next)if p4gt=07

print added edgemaadd edge(pnext)m=m+1

continue loop = Falsej += 1

print matching listOfedgeprint maedge

MA=nxadjacency matrix(ma)print MA

MA=[Rtodense()tolist()[0] for R in MA]print MA

B=[ join(map(strR)) for R in A]MB=[ join(map(strR)) for R in MA]

42 Application

C=njoin(B)+nMC=njoin(MB)+n

print nprint mprint m1

filea=str(i)+txtwith open(fileaw) as f

fwrite(str(n2+me2))fwrite(n)fwrite(str(n2+me2))fwrite(n)fwrite(str(m))fwrite(n)fwrite(n)fwrite(C)fwrite(n)fwrite(MC)

elseG=bipartiteconfiguration model(aseq3 bseq3 create using=None seed=None)A=nxadjacency matrix(G)for ii in range(0n3+me3)

maadd node(ii)A=[Rtodense()tolist()[0] for R in A]

printnummanumber of nodes()rl=randomsample(range(0n3+me3) n3+me3)m=0done vertices = set()for p in rlprintin fordone verticesadd(p)

neighbors = []list()for iii in range(0n3+me3)

if A[p][iii]==1neighborsappend(iii)

randomshuffle(neighbors)continue loop = Truedegree = len(neighbors)

print degreej = 0p4=randomrandom()while continue loop and (jltdegree)

print in loopnext = neighbors[j]if next not in done vertices and p not in done vertices

done verticesadd(p)done verticesadd(next)if p4gt=07print added edge

maadd edge(pnext)m=m+1

continue loop = Falsej += 1

Appendix A 43

print matching listOfedgeprint maedge

MA=nxadjacency matrix(ma)print MA

MA=[Rtodense()tolist()[0] for R in MA]print MA

B=[ join(map(strR)) for R in A]MB=[ join(map(strR)) for R in MA]

C=njoin(B)+nMC=njoin(MB)+n

print nprint mprint m1

filea=str(i)+txtwith open(fileaw) as f

fwrite(str(n3+me3))fwrite(n)fwrite(str(n3+me3))fwrite(n)fwrite(str(m))fwrite(n)fwrite(n)fwrite(C)fwrite(n)fwrite(MC)

print nRandom graphs with random matching have been generated

44 Application

RandomGraphGeneratorpy

from future import divisionimport networkx as nxfrom networkxalgorithms import approximationimport collectionsimport randomimport mathif name == main

for i in range(1481)index=1n=randomrandint(100 1000)

n=1000m=0m1=0p=randomrandom()p1=mathlog(n2)np2=13p3=mathlog(n2)n+01p=05t1=randomrandint(0 1)print im2=randomrandint(n2minus1 n2+1)G = nxGraph()ma = nxGraph()print nme1=randomrandint(1 10)me2=randomrandint(2050)me3=randomrandint(50100)if ilt241

if ilt=80G=nxfast gnp random graph(n p1 seed=None directed=False)

elif igt80 and ilt161G=nxfast gnp random graph(n p2 seed=None directed=False)

elseG=nxfast gnp random graph(n p3 seed=None directed=False)

elseif ilt=320

G=nxbarabasi albert graph(n me1 seed=None)elif igt320 and ilt401

G=nxbarabasi albert graph(n me2 seed=None)else

G=nxbarabasi albert graph(n me3 seed=None)A=nxadjacency matrix(G)for ii in range(0n)

maadd node(ii)A=[Rtodense()tolist()[0] for R in A]

rl=randomsample(range(0n) n)m=0

Appendix A 45

done vertices = set()for p in rl

done verticesadd(p)neighbors = []list()for iii in range(0n)

if A[p][iii]==1neighborsappend(iii)

randomshuffle(neighbors)continue loop = Truedegree = len(neighbors)j = 0p2=randomrandom()while continue loop and (jltdegree)

next = neighbors[j]if next not in done vertices and p not in done vertices

done verticesadd(p)done verticesadd(next)if p2gt=00 Larger probability for smaller initial matching

maadd edge(pnext)m=m+1

continue loop = Falsej += 1

print matching listOfedgeprint maedgeMA=nxadjacency matrix(ma)MA=[Rtodense()tolist()[0] for R in MA]print MAB=[ join(map(strR)) for R in A]MB=[ join(map(strR)) for R in MA]

C=njoin(B)+nMC=njoin(MB)+nprint MCprint nprint mprint m1filea=str(i)+txtwith open(fileaw) as f

fwrite(str(n))fwrite(n)fwrite(str(n))fwrite(n)fwrite(str(m))fwrite(n)fwrite(n)fwrite(C)fwrite(n)fwrite(MC)

print nRandom graphs with random matching have been generated

46 Application

kequals3MaximumMatchingpy

from future import divisionimport networkx as nxfrom networkxalgorithms import bipartiteimport matplotlibpyplot as pltimport collectionsimport timeitimport xlwtimport xlrdimport mathimport sys

Case for General Graphsdef forced edges(Gadj dict2matching dict1num nodesforced)

flagg=0for n in range(0num nodes)

for k in adj dict2[n]if ([k]==matching dict1[n])

count=0for l in range(0num nodes)

count=count+adj dict2[l]count(k)if (len(adj dict2[n])==1) or (count==1)

forcedadd edge(nk)Gremove edge(nk)Gremove node(n)Gremove node(k)printforced edgenktemp=kflagg=1for m in range (len(adj dict2[n])minus1minus1minus1)

adj dict2[adj dict2[n][m]]remove(n)adj dict2[n]remove(adj dict2[n][m])

if adj dict2[temp]for l in range(len(adj dict2[temp])minus1minus1minus1)

if (adj dict2[temp][l]=n)adj dict2[adj dict2[temp][l]]remove(temp)adj dict2[temp]remove(adj dict2[temp][l])

break

def useless edges(num nodesadj dict1matching dict1uselessadj dict2G)for n in range(0num nodes)

for k in adj dict1[n]if ([k]=matching dict1[n]) and matching dict1[n] and matching dict1[k]

uselessadd edge(nk)Gremove edge(n k)

Appendix A 47

tempa=kadj dict2[n]remove(k)adj dict2[tempa]remove(n)adj dict1[tempa]remove(n)

return G

def Greedy(num nodesadj dict3matching dict2)

for n in range(0num nodes)if matching dict2[n]

flag2=minus1flag3=minus1for v in adj dict3[n]

if not matching dict2[v]flag2=vbreak

for p in adj dict3[matching dict2[n][0]]if not matching dict2[p]

flag3=pbreak

if (flag2=minus1) and (flag3=minus1) and (flag2=flag3)tempr=matching dict2[n][0]matching dict2[n]=[flag2]matching dict2[flag2]=[n]matching dict2[tempr]=[flag3]matching dict2[flag3]=[tempr]

elsefor k in adj dict3[n]

if not matching dict2[k]matching dict2[n]=[k]matching dict2[k]=[n]break

yo1=0for i in range(0num nodes)

if matching dict2[i] and [i]==matching dict2[matching dict2[i][0]]yo1=yo1+1

greedy size=yo12return greedy size

def General()

INPUTSwb = xlwtWorkbook()ws = wbadd sheet(Results Random)book=xlrdopen workbook(filenames randomxls)

48 Application

style0 = xlwteasyxf(fontbold on)style1 = xlwteasyxf(num format str=0000)INPUTSwswrite(0 0File style0)wswrite(0 1 Nodesstyle0)wswrite(0 2 Initial matchingstyle0)wswrite(0 3 NodesGstyle0)wswrite(0 4 EdgesGstyle0)wswrite(0 5 MaxDegreeGstyle0)wswrite(0 6 NodesG hatstyle0)wswrite(0 7 EdgesG Hatstyle0)wswrite(0 8 Useless edgesstyle0)wswrite(0 9 Forced edgesstyle0)wswrite(0 10 MaxDegreeG Hatstyle0)wswrite(0 11 Classical matchingstyle0)wswrite(0 12 Final matchingstyle0)wswrite(0 13 Greedy matchingstyle0)wswrite(0 14 Time classicalstyle0)wswrite(0 15 Time algorithmstyle0)wswrite(0 16 Time greedystyle0)wswrite(0 17 Perfect matching ratiostyle0)wswrite(0 18 Nodes ratiostyle0)wswrite(0 19 Edges ratiostyle0)wswrite(0 20 Matching ratiostyle0)

print nWelcomeThis is an implementation for general random graphs It uses Edmonds algorithm to compute maximum matching on G Hatn

for index in range (1481)was 481

if (index==482)f=open(Algotel generaltxtr)readlines()

elsefilea=str(booksheet by index(0)cell(index0))s=fileareplace(textu)replace()f=open(sr)readlines()Truewswrite(index 0 s)

print index

num nodes=int([xstrip()split() for x in f][0][0])

num matching=int([xstrip()split() for x in f][2][0])

adj temp = [xstrip()split() for x in f][44+num nodes]adj=[map(intR) for R in adj temp]

matching temp=[xstrip()split() for x in f][4+num nodes+14+2num nodes+1]matching1=[map(intR) for R in matching temp]

adj dict1=i[ii for iix in enumerate(L) if x] for iL in enumerate(adj)adj dict2=i[ii for iix in enumerate(L) if x] for iL in enumerate(adj)

Appendix A 49

adj dict3=i[ii for iix in enumerate(L) if x] for iL in enumerate(adj)

matching dict1=i[ii for iix in enumerate(L) if x] for iL in enumerate(matching1)matching dict2=i[ii for iix in enumerate(L) if x] for iL in enumerate(matching1)print adj dict2print matching dict2wswrite(index 1 num nodes)wswrite(index 2 num matching)

G = nxGraph()

useless= nxGraph()forced = nxGraph()

Fill Graphfor n in range(0num nodes)

for k in adj dict1[n]Gadd edge(nk)

Gt=Gnumber of edges()wswrite(index 3 Gnumber of nodes())wswrite(index 4 Gnumber of edges())wswrite(index 5 max(Gdegree()values()))

Compute Edmonds classical matching on G for comparison

startB = timeitdefault timer()Classical Matching=nxmax weight matching(G maxcardinality=False)stopB = timeitdefault timer()

Compute Gˆ nad MˆstartC = timeitdefault timer()useless edges(num nodesadj dict1matching dict1uselessadj dict2G)forced edges(Gadj dict2matching dict1num nodesforced)Final Matching=nxmax weight matching(G maxcardinality=False)stopC = timeitdefault timer()

GreedystartG = timeitdefault timer()greedy size=Greedy(num nodesadj dict3matching dict2)stopG = timeitdefault timer()

wswrite(index 6 Gnumber of nodes())wswrite(index 7 Gnumber of edges())wswrite(index 8 uselessnumber of edges())wswrite(index 9 forcednumber of edges())if Gdegree()values()

wswrite(index 10 max(Gdegree()values()))else

50 Application

wswrite(index 10 0)wswrite(index 11 len(Classical Matching)2)wswrite(index 12 len(Final Matching)2+forcednumber of edges())wswrite(index 13 greedy size)wswrite(index 14 stopB minus startBstyle1)wswrite(index 15 stopC minus startCstyle1)wswrite(index 16 stopG minus startGstyle1)wswrite(index 17 (len(Final Matching)2+forcednumber of edges())(num nodes2)style1)wswrite(index 18 Gnumber of nodes()Gtstyle1)wswrite(index 19 Gnumber of edges()Gtstyle1)wswrite(index 20 (len(Final Matching)2+forcednumber of edges())(len(Classical Matching)2)style1)

wbsave(AA Results Random Reyni Large Bipartitexls)

Main function Here we must choose the input form of the dataif name == main

startA = timeitdefault timer()General()stopA = timeitdefault timer()

print nThis program has terminatednnRunning time for 480 files stopAminusstartAprint nnPlease open AA Results Random Reyni Largexls file to see the Results

Appendix A 51

Plotmat

clear allclose allload(RN1Lmat)load(RN1Smat)load(RN2Lmat)load(RN2Smat)load(RN3Lmat)load(RN3Smat)

Plotsh(1)=figure(NameHistogram of Matching size difference between Constraint Algorithm and Greedy AlgorithmNumberTitleoff)

RN1L Greedydiff=RN1L Final matchingminusRN1L Greedy matchingRN2L Greedydiff=RN2L Final matchingminusRN2L Greedy matchingRN3L Greedydiff=RN3L Final matchingminusRN3L Greedy matchingRN1S Greedydiff=RN1S Final matchingminusRN1S Greedy matchingRN2S Greedydiff=RN2S Final matchingminusRN2S Greedy matchingRN3S Greedydiff=RN3S Final matchingminusRN3S Greedy matching

RN1L Finaldiff=RN1L Classical matchingminusRN1L Final matchingRN2L Finaldiff=RN2L Classical matchingminusRN2L Final matchingRN3L Finaldiff=RN3L Classical matchingminusRN3L Final matchingRN1S Finaldiff=RN1S Classical matchingminusRN1S Final matchingRN2S Finaldiff=RN2S Classical matchingminusRN2S Final matchingRN3S Finaldiff=RN3S Classical matchingminusRN3S Final matching

RN1L Classicaldiff=(RN1L Nodes2)minusRN1L Classical matchingRN2L Classicaldiff=(RN2L Nodes2)minusRN2L Classical matchingRN3L Classicaldiff=(RN3L Nodes2)minusRN3L Classical matchingRN1S Classicaldiff=(RN1S Nodes2)minusRN1S Classical matchingRN2S Classicaldiff=(RN2S Nodes2)minusRN2S Classical matchingRN3S Classicaldiff=(RN3S Nodes2)minusRN3S Classical matching

subplot(231)hold onhistf(RN1L Greedydiff0110facecolorbfacealpha9edgealpha1)histf(RN1L Finaldiff0110facecolorrfacealpha5edgealpha1)histf(RN1L Classicaldiff0110facecolorgfacealpha5edgealpha1)legalpha(ConminusGreClasminusConPerfminusClasslocationnortheast)legend boxoffaxis tightxlabel(edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN1L)grid on

subplot(232)hold onhistf(RN2L Greedydiff0110facecolorbfacealpha9edgealpha1)

52 Application

histf(RN2L Finaldiff0110facecolorrfacealpha5edgealpha1)histf(RN2L Classicaldiff0110facecolorgfacealpha5edgealpha1)legalpha(ConminusGreClasminusConPerfminusClasslocationnortheast)legend boxoffaxis tightxlabel(edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN2L)grid on

subplot(233)hold onhistf(RN3L Greedydiff0110facecolorbfacealpha5edgealpha1)histf(RN3L Finaldiff0110facecolorrfacealpha5edgealpha1)histf(RN3L Classicaldiff0110facecolorgfacealpha5edgealpha1)legalpha(ConminusGreClasminusConPerfminusClasslocationnortheast)legend boxoffaxis tightxlabel(edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN3L)grid on

subplot(234)hold onhistf(RN1S Greedydiff0110facecolorbfacealpha5edgealpha1)histf(RN1S Finaldiff0110facecolorrfacealpha5edgealpha1)histf(RN1S Classicaldiff0110facecolorgfacealpha5edgealpha1)legalpha(ConminusGreClasminusConPerfminusClasslocationnortheast)legend boxoffaxis tightxlabel(edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(R1NS)grid on

subplot(235)hold onhistf(RN2S Greedydiff0110facecolorbfacealpha5edgealpha1)histf(RN2S Finaldiff0110facecolorrfacealpha5edgealpha1)histf(RN2S Classicaldiff0110facecolorgfacealpha5edgealpha1)legalpha(ConminusGreClasminusConPerfminusClasslocationnortheast)legend boxoffaxis tightxlabel(edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN2S)grid on

subplot(236)hold onhistf(RN3S Greedydiff0110facecolorbfacealpha5edgealpha1)histf(RN3S Finaldiff0110facecolorrfacealpha5edgealpha1)histf(RN3S Classicaldiff0110facecolorgfacealpha5edgealpha1)

Appendix A 53

legalpha(ConminusGreClasminusConPerfminusClasslocationnortheast)legend boxoffaxis tightgrid ontitle(RN3S)xlabel(edges) xminusaxis labelylabel(instances) yminusaxis labelset(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN1png minusr300)h(2)=figure(NameHistogram of Max Degree of G AND G HatNumberTitleoff)RN1L x=RN1L MaxDegreeGminusRN1L MaxDegreeG HatRN2L x=RN2L MaxDegreeGminusRN2L MaxDegreeG HatRN3L x=RN3L MaxDegreeGminusRN3L MaxDegreeG HatRN1S x=RN1S MaxDegreeGminusRN1S MaxDegreeG HatRN2S x=RN2S MaxDegreeGminusRN2S MaxDegreeG HatRN3S x=RN3S MaxDegreeGminusRN3S MaxDegreeG Hatsubplot(231)hold onhistf(RN1L MaxDegreeG0150facecolorbfacealpha5edgealpha1)histf(RN1L MaxDegreeG Hat0150facecolorrfacealpha5edgealpha1)histf(RN1L x0150facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightxlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN1L)grid on

subplot(232)hold onhistf(RN2L MaxDegreeG010500facecolorbfacealpha5edgealpha1)histf(RN2L MaxDegreeG Hat010500facecolorrfacealpha5edgealpha1)histf(RN2L x010500facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightxlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN2L)grid on

subplot(233)hold onhistf(RN3L MaxDegreeG010300facecolorbfacealpha5edgealpha1)histf(RN3L MaxDegreeG Hat010300facecolorrfacealpha5edgealpha1)histf(RN3L x010300facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightxlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN3L)

54 Application

grid on

subplot(234)hold onhistf(RN1S MaxDegreeG0150facecolorbfacealpha5edgealpha1)histf(RN1S MaxDegreeG Hat0150facecolorrfacealpha5edgealpha1)histf(RN1S x0150facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightxlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(R1NS)grid on

subplot(235)hold onhistf(RN2S MaxDegreeG010500facecolorbfacealpha5edgealpha1)histf(RN2S MaxDegreeG Hat010500facecolorrfacealpha5edgealpha1)histf(RN2S x010500facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightxlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN2S)grid on

subplot(236)hold onhistf(RN3S MaxDegreeG05300facecolorbfacealpha5edgealpha1)histf(RN3S MaxDegreeG Hat05300facecolorrfacealpha5edgealpha1)histf(RN3S x05300facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightgrid ontitle(RN3S)xlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labelset(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN2png minusr300)

h(3)=figure(NameComputation time over edgesNumberTitleoff)

subplot(231)hold onstem(RN1L EdgesGRN1L Time classicalg)stem(RN1L EdgesGRN1L Time algorithmro)stem(RN1L EdgesGRN1L Time greedybx)grid on

Appendix A 55

title(RN1L)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)

subplot(232)hold onstem(RN2L EdgesGRN2L Time classicalg)stem(RN2L EdgesGRN2L Time algorithmro)stem(RN2L EdgesGRN2L Time greedybx)grid ontitle(RN2L)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)

subplot(233)hold onstem(RN3L EdgesGRN3L Time classicalg)stem(RN3L EdgesGRN3L Time algorithmro)stem(RN3L EdgesGRN3L Time greedybx)grid ontitle(RN3L)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)

subplot(234)hold onstem(RN1S EdgesGRN1S Time classicalg)stem(RN1S EdgesGRN1S Time algorithmro)stem(RN1S EdgesGRN1S Time greedybx)grid ontitle(RN1S)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)

subplot(235)hold onstem(RN2S EdgesGRN2S Time classicalg)stem(RN2S EdgesGRN2S Time algorithmro)stem(RN2S EdgesGRN2S Time greedybx)grid ontitle(RN2S)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)

subplot(236)hold onstem(RN3S EdgesGRN3S Time classicalg)stem(RN3S EdgesGRN3S Time algorithmro)stem(RN3S EdgesGRN3S Time greedybx)

56 Application

grid ontitle(RN3S)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)set(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN3png minusr300)

h(4)=figure(NameSorted matching sizeNumberTitleoff)RN1L Sorted matching temp(1)=RN1L Classical matchingRN1L Sorted matching temp(2)=RN1L Final matchingRN1L Sorted matching temp(3)=RN1L Greedy matchingRN1L Sorted matching temp(4)=RN1L Initial matchingRN1L Sorted matching=sortrows(RN1L Sorted matching temp)

RN2L Sorted matching temp(1)=RN2L Classical matchingRN2L Sorted matching temp(2)=RN2L Final matchingRN2L Sorted matching temp(3)=RN2L Greedy matchingRN2L Sorted matching temp(4)=RN2L Initial matchingRN2L Sorted matching=sortrows(RN2L Sorted matching temp)

RN3L Sorted matching temp(1)=RN3L Classical matchingRN3L Sorted matching temp(2)=RN3L Final matchingRN3L Sorted matching temp(3)=RN3L Greedy matchingRN3L Sorted matching temp(4)=RN3L Initial matchingRN3L Sorted matching=sortrows(RN3L Sorted matching temp)

RN1S Sorted matching temp(1)=RN1S Classical matchingRN1S Sorted matching temp(2)=RN1S Final matchingRN1S Sorted matching temp(3)=RN1S Greedy matchingRN1S Sorted matching temp(4)=RN1S Initial matchingRN1S Sorted matching=sortrows(RN1S Sorted matching temp)

RN2S Sorted matching temp(1)=RN2S Classical matchingRN2S Sorted matching temp(2)=RN2S Final matchingRN2S Sorted matching temp(3)=RN2S Greedy matchingRN2S Sorted matching temp(4)=RN2S Initial matchingRN2S Sorted matching=sortrows(RN2S Sorted matching temp)

RN3S Sorted matching temp(1)=RN3S Classical matchingRN3S Sorted matching temp(2)=RN3S Final matchingRN3S Sorted matching temp(3)=RN3S Greedy matchingRN3S Sorted matching temp(4)=RN3S Initial matchingRN3S Sorted matching=sortrows(RN3S Sorted matching temp)

subplot(231)hold onplot(RN1L Sorted matching(1)b)plot(RN1L Sorted matching(2)g)plot(RN1L Sorted matching(3)r)plot(RN1L Sorted matching(4)m)

Appendix A 57

grid ontitle(RN1L)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)

subplot(232)hold onplot(RN2L Sorted matching(1)b)plot(RN2L Sorted matching(2)g)plot(RN2L Sorted matching(3)r)plot(RN2L Sorted matching(4)m)grid ontitle(RN2L)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)

subplot(233)hold onplot(RN3L Sorted matching(1)b)plot(RN3L Sorted matching(2)g)plot(RN3L Sorted matching(3)r)plot(RN3L Sorted matching(4)m)grid ontitle(RN3L)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)

subplot(234)hold onplot(RN1S Sorted matching(1)b)plot(RN1S Sorted matching(2)g)plot(RN1S Sorted matching(3)r)plot(RN1S Sorted matching(4)m)grid ontitle(RN1S)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)

subplot(235)hold onplot(RN2S Sorted matching(1)b)plot(RN2S Sorted matching(2)g)plot(RN2S Sorted matching(3)r)plot(RN2S Sorted matching(4)m)grid ontitle(RN2S)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)

58 Application

subplot(236)hold onplot(RN3S Sorted matching(1)b)plot(RN3S Sorted matching(2)g)plot(RN3S Sorted matching(3)r)plot(RN3S Sorted matching(4)m)grid ontitle(RN3S)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)set(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN4png minusr300)h(5)=figure(NameSorted RatiosNumberTitleoff)RN1L ratio1=RN1L NodesG hatRN1L NodesGRN2L ratio1=RN2L NodesG hatRN2L NodesGRN3L ratio1=RN3L NodesG hatRN3L NodesGRN1S ratio1=RN1S NodesG hatRN1S NodesGRN2S ratio1=RN2S NodesG hatRN2S NodesGRN3S ratio1=RN3S NodesG hatRN3S NodesG

RN1L ratio2=RN1L EdgesG HatRN1L EdgesGRN2L ratio2=RN2L EdgesG HatRN2L EdgesGRN3L ratio2=RN3L EdgesG HatRN3L EdgesGRN1S ratio2=RN1S EdgesG HatRN1S EdgesGRN2S ratio2=RN2S EdgesG HatRN2S EdgesGRN3S ratio2=RN3S EdgesG HatRN3S EdgesG

RN1L ratio3=RN1L MaxDegreeG HatRN1L MaxDegreeGRN2L ratio3=RN2L MaxDegreeG HatRN2L MaxDegreeGRN3L ratio3=RN3L MaxDegreeG HatRN3L MaxDegreeGRN1S ratio3=RN1S MaxDegreeG HatRN1S MaxDegreeGRN2S ratio3=RN2S MaxDegreeG HatRN2S MaxDegreeGRN3S ratio3=RN3S MaxDegreeG HatRN3S MaxDegreeG

RN1L ratio(1)=RN1L ratio1RN1L ratio(2)=RN1L ratio2RN1L ratio(3)=RN1L ratio3

RN2L ratio(1)=RN2L ratio1RN2L ratio(2)=RN2L ratio2RN2L ratio(3)=RN2L ratio3

RN3L ratio(1)=RN3L ratio1RN3L ratio(2)=RN3L ratio2RN3L ratio(3)=RN3L ratio3

RN1S ratio(1)=RN1S ratio1RN1S ratio(2)=RN1S ratio2RN1S ratio(3)=RN1S ratio3

RN2S ratio(1)=RN2S ratio1

Appendix A 59

RN2S ratio(2)=RN2S ratio2RN2S ratio(3)=RN2S ratio3

RN3S ratio(1)=RN3S ratio1RN3S ratio(2)=RN3S ratio2RN3S ratio(3)=RN3S ratio3

RN1L ratio sorted=sortrows(RN1L ratio)RN2L ratio sorted=sortrows(RN2L ratio)RN3L ratio sorted=sortrows(RN3L ratio)RN1S ratio sorted=sortrows(RN1S ratio)RN2S ratio sorted=sortrows(RN2S ratio)RN3S ratio sorted=sortrows(RN3S ratio)

subplot(231)hold onplot(RN1L ratio sorted(1)b)plot(RN1L ratio sorted(2)g)plot(RN1L ratio sorted(3)r)grid ontitle(RN1L)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)

subplot(232)hold onplot(RN2L ratio sorted(1)b)plot(RN2L ratio sorted(2)g)plot(RN2L ratio sorted(3)r)grid ontitle(RN2L)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)

subplot(233)hold onplot(RN3L ratio sorted(1)b)plot(RN3L ratio sorted(2)g)plot(RN3L ratio sorted(3)r)grid ontitle(RN3L)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)

subplot(234)hold onplot(RN1S ratio sorted(1)b)plot(RN1S ratio sorted(2)g)plot(RN1S ratio sorted(3)r)grid on

60 Application

title(RN1S)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)

subplot(235)hold onplot(RN2S ratio sorted(1)b)plot(RN2S ratio sorted(2)g)plot(RN2S ratio sorted(3)r)grid ontitle(RN2S)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)

subplot(236)hold onplot(RN3S ratio sorted(1)b)plot(RN3S ratio sorted(2)g)plot(RN3S ratio sorted(3)r)grid ontitle(RN3S)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)set(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN5png minusr300)

h(6)=figure(NameSorted edges over nodesNumberTitleoff)

RN1L DegreeG1=(RN1L EdgesG)(RN1L NodesG)RN1L DegreeG Hat1=(RN1L EdgesG Hat)(RN1L NodesG hat)

RN1L Degree temp1(1)=RN1L DegreeG1RN1L Degree temp1(2)=RN1L DegreeG Hat1RN1L Degree sorted1=sortrows(RN1L Degree temp1)subplot(231)hold on

plot(RN1L Degree sorted1(1)b)plot(RN1L Degree sorted1(2)g)grid ontitle(RN1L)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)

RN2L DegreeG1=(RN2L EdgesG)(RN2L NodesG)RN2L DegreeG Hat1=(RN2L EdgesG Hat)(RN2L NodesG hat)

RN2L Degree temp1(1)=RN2L DegreeG1

Appendix A 61

RN2L Degree temp1(2)=RN2L DegreeG Hat1RN2L Degree sorted1=sortrows(RN2L Degree temp1)

subplot(232)hold onplot(RN2L Degree sorted1(1)b)plot(RN2L Degree sorted1(2)g)grid ontitle(RN2L)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)

RN3L DegreeG1=(RN3L EdgesG)(RN3L NodesG)RN3L DegreeG Hat1=(RN3L EdgesG Hat)(RN3L NodesG hat)

RN3L Degree temp1(1)=RN3L DegreeG1RN3L Degree temp1(2)=RN3L DegreeG Hat1RN3L Degree sorted1=sortrows(RN3L Degree temp1)

subplot(233)hold onplot(RN3L Degree sorted1(1)b)plot(RN3L Degree sorted1(2)g)grid ontitle(RN3L)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)

RN1S DegreeG1=(RN1S EdgesG)(RN1S NodesG)RN1S DegreeG Hat1=(RN1S EdgesG Hat)(RN1S NodesG hat)

RN1S Degree temp1(1)=RN1S DegreeG1RN1S Degree temp1(2)=RN1S DegreeG Hat1RN1S Degree sorted1=sortrows(RN1S Degree temp1)

subplot(234)hold onplot(RN1S Degree sorted1(1)b)plot(RN1S Degree sorted1(2)g)grid ontitle(RN1S)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)

RN2S DegreeG1=(RN2S EdgesG)(RN2S NodesG)RN2S DegreeG Hat1=(RN2S EdgesG Hat)(RN2S NodesG hat)

RN2S Degree temp1(1)=RN2S DegreeG1

62 Application

RN2S Degree temp1(2)=RN2S DegreeG Hat1RN2S Degree sorted1=sortrows(RN2S Degree temp1)

subplot(235)hold onplot(RN2S Degree sorted1(1)b)plot(RN2S Degree sorted1(2)g)grid ontitle(RN2S)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)

RN3S DegreeG1=(RN3S EdgesG)(RN3S NodesG)RN3S DegreeG Hat1=(RN3S EdgesG Hat)(RN3S NodesG hat)

RN3S Degree temp1(1)=RN3S DegreeG1RN3S Degree temp1(2)=RN3S DegreeG Hat1RN3S Degree sorted1=sortrows(RN3S Degree temp1)

subplot(236)hold onplot(RN3S Degree sorted1(1)b)plot(RN3S Degree sorted1(2)g)grid ontitle(RN3S)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)set(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN6png minusr300)h(7)=figure(NameSorted mATCHED DEGREENumberTitleoff)RN1L ratioMax(1)=RN1L MaxDegreeGRN1L ratioMax(2)=RN1L MaxDegreeG Hat

RN1L ratio sortedMax=sortrows(RN1L ratioMax)subplot(231)hold onplot(RN1L ratio sortedMax(1)b)plot(RN1L ratio sortedMax(2)g)grid ontitle(RN1L)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)

RN2L ratioMax(1)=RN2L MaxDegreeGRN2L ratioMax(2)=RN2L MaxDegreeG Hat

RN2L ratio sortedMax=sortrows(RN2L ratioMax)subplot(232)

Appendix A 63

hold onplot(RN2L ratio sortedMax(1)b)plot(RN2L ratio sortedMax(2)g)grid ontitle(RN2L)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)

RN3L ratioMax(1)=RN3L MaxDegreeGRN3L ratioMax(2)=RN3L MaxDegreeG Hat

RN3L ratio sortedMax=sortrows(RN3L ratioMax)subplot(233)hold onplot(RN3L ratio sortedMax(1)b)plot(RN3L ratio sortedMax(2)g)grid ontitle(RN3L)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)

RN1S ratioMax(1)=RN1S MaxDegreeGRN1S ratioMax(2)=RN1S MaxDegreeG Hat

RN1S ratio sortedMax=sortrows(RN1S ratioMax)subplot(234)hold onplot(RN1S ratio sortedMax(1)b)plot(RN1S ratio sortedMax(2)g)grid ontitle(RN1S)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)

RN2S ratioMax(1)=RN2S MaxDegreeGRN2S ratioMax(2)=RN2S MaxDegreeG Hat

RN2S ratio sortedMax=sortrows(RN2S ratioMax)

subplot(235)hold onplot(RN2S ratio sortedMax(1)b)plot(RN2S ratio sortedMax(2)g)grid ontitle(RN2S)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)

RN3S ratioMax(1)=RN3S MaxDegreeGRN3S ratioMax(2)=RN3S MaxDegreeG Hat

64 Application

RN3S ratio sortedMax=sortrows(RN3S ratioMax)subplot(236)hold onplot(RN3S ratio sortedMax(1)b)plot(RN3S ratio sortedMax(2)g)grid ontitle(RN1L)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)set(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN7png minusr300)

tilefigs()(h)

Bibliography

[1] C Berge ldquoTWO THEOREMS IN GRAPH THEORYrdquo Proceedings of the NationalAcademy of Sciences of the United States of America vol 43 no 9 pp 842ndash844Sep 1957

[2] L Bui S Sanghavi and R Srikant ldquoDistributed link scheduling with constantoverheadrdquo IEEEACM Trans Netw vol 17 no 5 pp 1467ndash1480 2009

[3] R Duan and S Pettie ldquoLinear-time approximation for maximum weight matchingrdquoJ ACM vol 61 no 1 2014

[4] J Edmonds ldquoPaths trees and flowersrdquo Canadian Journal of Mathematics vol 17pp 449ndash467 1965

[5] J E Hopcroft and R M Karp ldquoAn n52 algorithm for maximum matchings inbipartite graphsrdquo SIAM J Comput vol 2 no 4 pp 225ndash231 1973

[6] S Micali and V V Vazirani ldquoAn O(radic|V ||E|) algorithm for finding maximum

matching in general graphsrdquo in 21st Symp on Foundations of Comp Sc (FOCS)IEEE 1980 pp 17ndash27

[7] N Nisse A Salch and V Weber ldquoRecovery of disrupted airline operationsrdquo 2015httphalinriafrSomething

[8] X Wu and R Srikant ldquoRegulated maximal matching A distributed schedulingalgorithm for multi-hop wireless networks with nodeexclusive spectrum sharingrdquo inIEEE Conf on Decision and Control 2005

65

  • Contents
  • Introduction
  • Algorithms
    • Maximum matching
    • k-maximum matching
      • k-matching for Airport Slot assignment
      • The case where k=3
      • The case of Paths
      • The case of the Spider
          • Application
            • Description
            • Reyni Erdos
            • Barabaacutesi Albert
            • Amadeus Graphs
            • Bipartite
            • Bipartite with degree seq
            • Appendix A
              • BipartiteGraphGeneratorpy
              • RandomGraphGeneratorpy
              • kequals3MaximumMatchingpy
              • Plotmat
                  • Bibliography
Page 39: Theodoros Alexandros KARAGKIOULES -  · Introduction This work is the result of a 6 months internship, under the supervision of research O cer Nicolas NISSE. The original scope of

40 Application

print Gnumber of edges()if ilt=160

G=bipartiteconfiguration model(aseq1 bseq1 create using=None seed=None)A=nxadjacency matrix(G)for ii in range(0n1+me1)

maadd node(ii)A=[Rtodense()tolist()[0] for R in A]

printnummanumber of nodes()rl=randomsample(range(0n1+me1) n1+me1)m=0done vertices = set()for p in rlprintin fordone verticesadd(p)

neighbors = []list()for iii in range(0n1+me1)

if A[p][iii]==1neighborsappend(iii)

randomshuffle(neighbors)continue loop = Truedegree = len(neighbors)

print degreej = 0p4=randomrandom()while continue loop and (jltdegree)print in loop

next = neighbors[j]if next not in done vertices and p not in done vertices

done verticesadd(p)done verticesadd(next)if p4gt=07print added edge

maadd edge(pnext)m=m+1

continue loop = Falsej += 1

print matching listOfedgeprint maedge

MA=nxadjacency matrix(ma)print MA

MA=[Rtodense()tolist()[0] for R in MA]print MA

B=[ join(map(strR)) for R in A]MB=[ join(map(strR)) for R in MA]

C=njoin(B)+nMC=njoin(MB)+n

print nprint mprint m1

filea=str(i)+txtwith open(fileaw) as f

Appendix A 41

fwrite(str(n1+me1))fwrite(n)fwrite(str(n1+me1))fwrite(n)fwrite(str(m))fwrite(n)fwrite(n)fwrite(C)fwrite(n)fwrite(MC)

elif igt160 and ilt321G=bipartiteconfiguration model(aseq2 bseq2 create using=None seed=None)A=nxadjacency matrix(G)for ii in range(0n2+me2)

maadd node(ii)A=[Rtodense()tolist()[0] for R in A]

printnummanumber of nodes()rl=randomsample(range(0n2+me2) n2+me2)m=0done vertices = set()for p in rlprintin fordone verticesadd(p)

neighbors = []list()for iii in range(0n2+me2)

if A[p][iii]==1neighborsappend(iii)

randomshuffle(neighbors)continue loop = Truedegree = len(neighbors)

print degreej = 0p4=randomrandom()while continue loop and (jltdegree)

print in loopnext = neighbors[j]if next not in done vertices and p not in done vertices

done verticesadd(p)done verticesadd(next)if p4gt=07

print added edgemaadd edge(pnext)m=m+1

continue loop = Falsej += 1

print matching listOfedgeprint maedge

MA=nxadjacency matrix(ma)print MA

MA=[Rtodense()tolist()[0] for R in MA]print MA

B=[ join(map(strR)) for R in A]MB=[ join(map(strR)) for R in MA]

42 Application

C=njoin(B)+nMC=njoin(MB)+n

print nprint mprint m1

filea=str(i)+txtwith open(fileaw) as f

fwrite(str(n2+me2))fwrite(n)fwrite(str(n2+me2))fwrite(n)fwrite(str(m))fwrite(n)fwrite(n)fwrite(C)fwrite(n)fwrite(MC)

elseG=bipartiteconfiguration model(aseq3 bseq3 create using=None seed=None)A=nxadjacency matrix(G)for ii in range(0n3+me3)

maadd node(ii)A=[Rtodense()tolist()[0] for R in A]

printnummanumber of nodes()rl=randomsample(range(0n3+me3) n3+me3)m=0done vertices = set()for p in rlprintin fordone verticesadd(p)

neighbors = []list()for iii in range(0n3+me3)

if A[p][iii]==1neighborsappend(iii)

randomshuffle(neighbors)continue loop = Truedegree = len(neighbors)

print degreej = 0p4=randomrandom()while continue loop and (jltdegree)

print in loopnext = neighbors[j]if next not in done vertices and p not in done vertices

done verticesadd(p)done verticesadd(next)if p4gt=07print added edge

maadd edge(pnext)m=m+1

continue loop = Falsej += 1

Appendix A 43

print matching listOfedgeprint maedge

MA=nxadjacency matrix(ma)print MA

MA=[Rtodense()tolist()[0] for R in MA]print MA

B=[ join(map(strR)) for R in A]MB=[ join(map(strR)) for R in MA]

C=njoin(B)+nMC=njoin(MB)+n

print nprint mprint m1

filea=str(i)+txtwith open(fileaw) as f

fwrite(str(n3+me3))fwrite(n)fwrite(str(n3+me3))fwrite(n)fwrite(str(m))fwrite(n)fwrite(n)fwrite(C)fwrite(n)fwrite(MC)

print nRandom graphs with random matching have been generated

44 Application

RandomGraphGeneratorpy

from future import divisionimport networkx as nxfrom networkxalgorithms import approximationimport collectionsimport randomimport mathif name == main

for i in range(1481)index=1n=randomrandint(100 1000)

n=1000m=0m1=0p=randomrandom()p1=mathlog(n2)np2=13p3=mathlog(n2)n+01p=05t1=randomrandint(0 1)print im2=randomrandint(n2minus1 n2+1)G = nxGraph()ma = nxGraph()print nme1=randomrandint(1 10)me2=randomrandint(2050)me3=randomrandint(50100)if ilt241

if ilt=80G=nxfast gnp random graph(n p1 seed=None directed=False)

elif igt80 and ilt161G=nxfast gnp random graph(n p2 seed=None directed=False)

elseG=nxfast gnp random graph(n p3 seed=None directed=False)

elseif ilt=320

G=nxbarabasi albert graph(n me1 seed=None)elif igt320 and ilt401

G=nxbarabasi albert graph(n me2 seed=None)else

G=nxbarabasi albert graph(n me3 seed=None)A=nxadjacency matrix(G)for ii in range(0n)

maadd node(ii)A=[Rtodense()tolist()[0] for R in A]

rl=randomsample(range(0n) n)m=0

Appendix A 45

done vertices = set()for p in rl

done verticesadd(p)neighbors = []list()for iii in range(0n)

if A[p][iii]==1neighborsappend(iii)

randomshuffle(neighbors)continue loop = Truedegree = len(neighbors)j = 0p2=randomrandom()while continue loop and (jltdegree)

next = neighbors[j]if next not in done vertices and p not in done vertices

done verticesadd(p)done verticesadd(next)if p2gt=00 Larger probability for smaller initial matching

maadd edge(pnext)m=m+1

continue loop = Falsej += 1

print matching listOfedgeprint maedgeMA=nxadjacency matrix(ma)MA=[Rtodense()tolist()[0] for R in MA]print MAB=[ join(map(strR)) for R in A]MB=[ join(map(strR)) for R in MA]

C=njoin(B)+nMC=njoin(MB)+nprint MCprint nprint mprint m1filea=str(i)+txtwith open(fileaw) as f

fwrite(str(n))fwrite(n)fwrite(str(n))fwrite(n)fwrite(str(m))fwrite(n)fwrite(n)fwrite(C)fwrite(n)fwrite(MC)

print nRandom graphs with random matching have been generated

46 Application

kequals3MaximumMatchingpy

from future import divisionimport networkx as nxfrom networkxalgorithms import bipartiteimport matplotlibpyplot as pltimport collectionsimport timeitimport xlwtimport xlrdimport mathimport sys

Case for General Graphsdef forced edges(Gadj dict2matching dict1num nodesforced)

flagg=0for n in range(0num nodes)

for k in adj dict2[n]if ([k]==matching dict1[n])

count=0for l in range(0num nodes)

count=count+adj dict2[l]count(k)if (len(adj dict2[n])==1) or (count==1)

forcedadd edge(nk)Gremove edge(nk)Gremove node(n)Gremove node(k)printforced edgenktemp=kflagg=1for m in range (len(adj dict2[n])minus1minus1minus1)

adj dict2[adj dict2[n][m]]remove(n)adj dict2[n]remove(adj dict2[n][m])

if adj dict2[temp]for l in range(len(adj dict2[temp])minus1minus1minus1)

if (adj dict2[temp][l]=n)adj dict2[adj dict2[temp][l]]remove(temp)adj dict2[temp]remove(adj dict2[temp][l])

break

def useless edges(num nodesadj dict1matching dict1uselessadj dict2G)for n in range(0num nodes)

for k in adj dict1[n]if ([k]=matching dict1[n]) and matching dict1[n] and matching dict1[k]

uselessadd edge(nk)Gremove edge(n k)

Appendix A 47

tempa=kadj dict2[n]remove(k)adj dict2[tempa]remove(n)adj dict1[tempa]remove(n)

return G

def Greedy(num nodesadj dict3matching dict2)

for n in range(0num nodes)if matching dict2[n]

flag2=minus1flag3=minus1for v in adj dict3[n]

if not matching dict2[v]flag2=vbreak

for p in adj dict3[matching dict2[n][0]]if not matching dict2[p]

flag3=pbreak

if (flag2=minus1) and (flag3=minus1) and (flag2=flag3)tempr=matching dict2[n][0]matching dict2[n]=[flag2]matching dict2[flag2]=[n]matching dict2[tempr]=[flag3]matching dict2[flag3]=[tempr]

elsefor k in adj dict3[n]

if not matching dict2[k]matching dict2[n]=[k]matching dict2[k]=[n]break

yo1=0for i in range(0num nodes)

if matching dict2[i] and [i]==matching dict2[matching dict2[i][0]]yo1=yo1+1

greedy size=yo12return greedy size

def General()

INPUTSwb = xlwtWorkbook()ws = wbadd sheet(Results Random)book=xlrdopen workbook(filenames randomxls)

48 Application

style0 = xlwteasyxf(fontbold on)style1 = xlwteasyxf(num format str=0000)INPUTSwswrite(0 0File style0)wswrite(0 1 Nodesstyle0)wswrite(0 2 Initial matchingstyle0)wswrite(0 3 NodesGstyle0)wswrite(0 4 EdgesGstyle0)wswrite(0 5 MaxDegreeGstyle0)wswrite(0 6 NodesG hatstyle0)wswrite(0 7 EdgesG Hatstyle0)wswrite(0 8 Useless edgesstyle0)wswrite(0 9 Forced edgesstyle0)wswrite(0 10 MaxDegreeG Hatstyle0)wswrite(0 11 Classical matchingstyle0)wswrite(0 12 Final matchingstyle0)wswrite(0 13 Greedy matchingstyle0)wswrite(0 14 Time classicalstyle0)wswrite(0 15 Time algorithmstyle0)wswrite(0 16 Time greedystyle0)wswrite(0 17 Perfect matching ratiostyle0)wswrite(0 18 Nodes ratiostyle0)wswrite(0 19 Edges ratiostyle0)wswrite(0 20 Matching ratiostyle0)

print nWelcomeThis is an implementation for general random graphs It uses Edmonds algorithm to compute maximum matching on G Hatn

for index in range (1481)was 481

if (index==482)f=open(Algotel generaltxtr)readlines()

elsefilea=str(booksheet by index(0)cell(index0))s=fileareplace(textu)replace()f=open(sr)readlines()Truewswrite(index 0 s)

print index

num nodes=int([xstrip()split() for x in f][0][0])

num matching=int([xstrip()split() for x in f][2][0])

adj temp = [xstrip()split() for x in f][44+num nodes]adj=[map(intR) for R in adj temp]

matching temp=[xstrip()split() for x in f][4+num nodes+14+2num nodes+1]matching1=[map(intR) for R in matching temp]

adj dict1=i[ii for iix in enumerate(L) if x] for iL in enumerate(adj)adj dict2=i[ii for iix in enumerate(L) if x] for iL in enumerate(adj)

Appendix A 49

adj dict3=i[ii for iix in enumerate(L) if x] for iL in enumerate(adj)

matching dict1=i[ii for iix in enumerate(L) if x] for iL in enumerate(matching1)matching dict2=i[ii for iix in enumerate(L) if x] for iL in enumerate(matching1)print adj dict2print matching dict2wswrite(index 1 num nodes)wswrite(index 2 num matching)

G = nxGraph()

useless= nxGraph()forced = nxGraph()

Fill Graphfor n in range(0num nodes)

for k in adj dict1[n]Gadd edge(nk)

Gt=Gnumber of edges()wswrite(index 3 Gnumber of nodes())wswrite(index 4 Gnumber of edges())wswrite(index 5 max(Gdegree()values()))

Compute Edmonds classical matching on G for comparison

startB = timeitdefault timer()Classical Matching=nxmax weight matching(G maxcardinality=False)stopB = timeitdefault timer()

Compute Gˆ nad MˆstartC = timeitdefault timer()useless edges(num nodesadj dict1matching dict1uselessadj dict2G)forced edges(Gadj dict2matching dict1num nodesforced)Final Matching=nxmax weight matching(G maxcardinality=False)stopC = timeitdefault timer()

GreedystartG = timeitdefault timer()greedy size=Greedy(num nodesadj dict3matching dict2)stopG = timeitdefault timer()

wswrite(index 6 Gnumber of nodes())wswrite(index 7 Gnumber of edges())wswrite(index 8 uselessnumber of edges())wswrite(index 9 forcednumber of edges())if Gdegree()values()

wswrite(index 10 max(Gdegree()values()))else

50 Application

wswrite(index 10 0)wswrite(index 11 len(Classical Matching)2)wswrite(index 12 len(Final Matching)2+forcednumber of edges())wswrite(index 13 greedy size)wswrite(index 14 stopB minus startBstyle1)wswrite(index 15 stopC minus startCstyle1)wswrite(index 16 stopG minus startGstyle1)wswrite(index 17 (len(Final Matching)2+forcednumber of edges())(num nodes2)style1)wswrite(index 18 Gnumber of nodes()Gtstyle1)wswrite(index 19 Gnumber of edges()Gtstyle1)wswrite(index 20 (len(Final Matching)2+forcednumber of edges())(len(Classical Matching)2)style1)

wbsave(AA Results Random Reyni Large Bipartitexls)

Main function Here we must choose the input form of the dataif name == main

startA = timeitdefault timer()General()stopA = timeitdefault timer()

print nThis program has terminatednnRunning time for 480 files stopAminusstartAprint nnPlease open AA Results Random Reyni Largexls file to see the Results

Appendix A 51

Plotmat

clear allclose allload(RN1Lmat)load(RN1Smat)load(RN2Lmat)load(RN2Smat)load(RN3Lmat)load(RN3Smat)

Plotsh(1)=figure(NameHistogram of Matching size difference between Constraint Algorithm and Greedy AlgorithmNumberTitleoff)

RN1L Greedydiff=RN1L Final matchingminusRN1L Greedy matchingRN2L Greedydiff=RN2L Final matchingminusRN2L Greedy matchingRN3L Greedydiff=RN3L Final matchingminusRN3L Greedy matchingRN1S Greedydiff=RN1S Final matchingminusRN1S Greedy matchingRN2S Greedydiff=RN2S Final matchingminusRN2S Greedy matchingRN3S Greedydiff=RN3S Final matchingminusRN3S Greedy matching

RN1L Finaldiff=RN1L Classical matchingminusRN1L Final matchingRN2L Finaldiff=RN2L Classical matchingminusRN2L Final matchingRN3L Finaldiff=RN3L Classical matchingminusRN3L Final matchingRN1S Finaldiff=RN1S Classical matchingminusRN1S Final matchingRN2S Finaldiff=RN2S Classical matchingminusRN2S Final matchingRN3S Finaldiff=RN3S Classical matchingminusRN3S Final matching

RN1L Classicaldiff=(RN1L Nodes2)minusRN1L Classical matchingRN2L Classicaldiff=(RN2L Nodes2)minusRN2L Classical matchingRN3L Classicaldiff=(RN3L Nodes2)minusRN3L Classical matchingRN1S Classicaldiff=(RN1S Nodes2)minusRN1S Classical matchingRN2S Classicaldiff=(RN2S Nodes2)minusRN2S Classical matchingRN3S Classicaldiff=(RN3S Nodes2)minusRN3S Classical matching

subplot(231)hold onhistf(RN1L Greedydiff0110facecolorbfacealpha9edgealpha1)histf(RN1L Finaldiff0110facecolorrfacealpha5edgealpha1)histf(RN1L Classicaldiff0110facecolorgfacealpha5edgealpha1)legalpha(ConminusGreClasminusConPerfminusClasslocationnortheast)legend boxoffaxis tightxlabel(edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN1L)grid on

subplot(232)hold onhistf(RN2L Greedydiff0110facecolorbfacealpha9edgealpha1)

52 Application

histf(RN2L Finaldiff0110facecolorrfacealpha5edgealpha1)histf(RN2L Classicaldiff0110facecolorgfacealpha5edgealpha1)legalpha(ConminusGreClasminusConPerfminusClasslocationnortheast)legend boxoffaxis tightxlabel(edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN2L)grid on

subplot(233)hold onhistf(RN3L Greedydiff0110facecolorbfacealpha5edgealpha1)histf(RN3L Finaldiff0110facecolorrfacealpha5edgealpha1)histf(RN3L Classicaldiff0110facecolorgfacealpha5edgealpha1)legalpha(ConminusGreClasminusConPerfminusClasslocationnortheast)legend boxoffaxis tightxlabel(edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN3L)grid on

subplot(234)hold onhistf(RN1S Greedydiff0110facecolorbfacealpha5edgealpha1)histf(RN1S Finaldiff0110facecolorrfacealpha5edgealpha1)histf(RN1S Classicaldiff0110facecolorgfacealpha5edgealpha1)legalpha(ConminusGreClasminusConPerfminusClasslocationnortheast)legend boxoffaxis tightxlabel(edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(R1NS)grid on

subplot(235)hold onhistf(RN2S Greedydiff0110facecolorbfacealpha5edgealpha1)histf(RN2S Finaldiff0110facecolorrfacealpha5edgealpha1)histf(RN2S Classicaldiff0110facecolorgfacealpha5edgealpha1)legalpha(ConminusGreClasminusConPerfminusClasslocationnortheast)legend boxoffaxis tightxlabel(edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN2S)grid on

subplot(236)hold onhistf(RN3S Greedydiff0110facecolorbfacealpha5edgealpha1)histf(RN3S Finaldiff0110facecolorrfacealpha5edgealpha1)histf(RN3S Classicaldiff0110facecolorgfacealpha5edgealpha1)

Appendix A 53

legalpha(ConminusGreClasminusConPerfminusClasslocationnortheast)legend boxoffaxis tightgrid ontitle(RN3S)xlabel(edges) xminusaxis labelylabel(instances) yminusaxis labelset(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN1png minusr300)h(2)=figure(NameHistogram of Max Degree of G AND G HatNumberTitleoff)RN1L x=RN1L MaxDegreeGminusRN1L MaxDegreeG HatRN2L x=RN2L MaxDegreeGminusRN2L MaxDegreeG HatRN3L x=RN3L MaxDegreeGminusRN3L MaxDegreeG HatRN1S x=RN1S MaxDegreeGminusRN1S MaxDegreeG HatRN2S x=RN2S MaxDegreeGminusRN2S MaxDegreeG HatRN3S x=RN3S MaxDegreeGminusRN3S MaxDegreeG Hatsubplot(231)hold onhistf(RN1L MaxDegreeG0150facecolorbfacealpha5edgealpha1)histf(RN1L MaxDegreeG Hat0150facecolorrfacealpha5edgealpha1)histf(RN1L x0150facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightxlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN1L)grid on

subplot(232)hold onhistf(RN2L MaxDegreeG010500facecolorbfacealpha5edgealpha1)histf(RN2L MaxDegreeG Hat010500facecolorrfacealpha5edgealpha1)histf(RN2L x010500facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightxlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN2L)grid on

subplot(233)hold onhistf(RN3L MaxDegreeG010300facecolorbfacealpha5edgealpha1)histf(RN3L MaxDegreeG Hat010300facecolorrfacealpha5edgealpha1)histf(RN3L x010300facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightxlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN3L)

54 Application

grid on

subplot(234)hold onhistf(RN1S MaxDegreeG0150facecolorbfacealpha5edgealpha1)histf(RN1S MaxDegreeG Hat0150facecolorrfacealpha5edgealpha1)histf(RN1S x0150facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightxlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(R1NS)grid on

subplot(235)hold onhistf(RN2S MaxDegreeG010500facecolorbfacealpha5edgealpha1)histf(RN2S MaxDegreeG Hat010500facecolorrfacealpha5edgealpha1)histf(RN2S x010500facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightxlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN2S)grid on

subplot(236)hold onhistf(RN3S MaxDegreeG05300facecolorbfacealpha5edgealpha1)histf(RN3S MaxDegreeG Hat05300facecolorrfacealpha5edgealpha1)histf(RN3S x05300facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightgrid ontitle(RN3S)xlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labelset(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN2png minusr300)

h(3)=figure(NameComputation time over edgesNumberTitleoff)

subplot(231)hold onstem(RN1L EdgesGRN1L Time classicalg)stem(RN1L EdgesGRN1L Time algorithmro)stem(RN1L EdgesGRN1L Time greedybx)grid on

Appendix A 55

title(RN1L)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)

subplot(232)hold onstem(RN2L EdgesGRN2L Time classicalg)stem(RN2L EdgesGRN2L Time algorithmro)stem(RN2L EdgesGRN2L Time greedybx)grid ontitle(RN2L)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)

subplot(233)hold onstem(RN3L EdgesGRN3L Time classicalg)stem(RN3L EdgesGRN3L Time algorithmro)stem(RN3L EdgesGRN3L Time greedybx)grid ontitle(RN3L)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)

subplot(234)hold onstem(RN1S EdgesGRN1S Time classicalg)stem(RN1S EdgesGRN1S Time algorithmro)stem(RN1S EdgesGRN1S Time greedybx)grid ontitle(RN1S)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)

subplot(235)hold onstem(RN2S EdgesGRN2S Time classicalg)stem(RN2S EdgesGRN2S Time algorithmro)stem(RN2S EdgesGRN2S Time greedybx)grid ontitle(RN2S)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)

subplot(236)hold onstem(RN3S EdgesGRN3S Time classicalg)stem(RN3S EdgesGRN3S Time algorithmro)stem(RN3S EdgesGRN3S Time greedybx)

56 Application

grid ontitle(RN3S)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)set(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN3png minusr300)

h(4)=figure(NameSorted matching sizeNumberTitleoff)RN1L Sorted matching temp(1)=RN1L Classical matchingRN1L Sorted matching temp(2)=RN1L Final matchingRN1L Sorted matching temp(3)=RN1L Greedy matchingRN1L Sorted matching temp(4)=RN1L Initial matchingRN1L Sorted matching=sortrows(RN1L Sorted matching temp)

RN2L Sorted matching temp(1)=RN2L Classical matchingRN2L Sorted matching temp(2)=RN2L Final matchingRN2L Sorted matching temp(3)=RN2L Greedy matchingRN2L Sorted matching temp(4)=RN2L Initial matchingRN2L Sorted matching=sortrows(RN2L Sorted matching temp)

RN3L Sorted matching temp(1)=RN3L Classical matchingRN3L Sorted matching temp(2)=RN3L Final matchingRN3L Sorted matching temp(3)=RN3L Greedy matchingRN3L Sorted matching temp(4)=RN3L Initial matchingRN3L Sorted matching=sortrows(RN3L Sorted matching temp)

RN1S Sorted matching temp(1)=RN1S Classical matchingRN1S Sorted matching temp(2)=RN1S Final matchingRN1S Sorted matching temp(3)=RN1S Greedy matchingRN1S Sorted matching temp(4)=RN1S Initial matchingRN1S Sorted matching=sortrows(RN1S Sorted matching temp)

RN2S Sorted matching temp(1)=RN2S Classical matchingRN2S Sorted matching temp(2)=RN2S Final matchingRN2S Sorted matching temp(3)=RN2S Greedy matchingRN2S Sorted matching temp(4)=RN2S Initial matchingRN2S Sorted matching=sortrows(RN2S Sorted matching temp)

RN3S Sorted matching temp(1)=RN3S Classical matchingRN3S Sorted matching temp(2)=RN3S Final matchingRN3S Sorted matching temp(3)=RN3S Greedy matchingRN3S Sorted matching temp(4)=RN3S Initial matchingRN3S Sorted matching=sortrows(RN3S Sorted matching temp)

subplot(231)hold onplot(RN1L Sorted matching(1)b)plot(RN1L Sorted matching(2)g)plot(RN1L Sorted matching(3)r)plot(RN1L Sorted matching(4)m)

Appendix A 57

grid ontitle(RN1L)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)

subplot(232)hold onplot(RN2L Sorted matching(1)b)plot(RN2L Sorted matching(2)g)plot(RN2L Sorted matching(3)r)plot(RN2L Sorted matching(4)m)grid ontitle(RN2L)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)

subplot(233)hold onplot(RN3L Sorted matching(1)b)plot(RN3L Sorted matching(2)g)plot(RN3L Sorted matching(3)r)plot(RN3L Sorted matching(4)m)grid ontitle(RN3L)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)

subplot(234)hold onplot(RN1S Sorted matching(1)b)plot(RN1S Sorted matching(2)g)plot(RN1S Sorted matching(3)r)plot(RN1S Sorted matching(4)m)grid ontitle(RN1S)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)

subplot(235)hold onplot(RN2S Sorted matching(1)b)plot(RN2S Sorted matching(2)g)plot(RN2S Sorted matching(3)r)plot(RN2S Sorted matching(4)m)grid ontitle(RN2S)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)

58 Application

subplot(236)hold onplot(RN3S Sorted matching(1)b)plot(RN3S Sorted matching(2)g)plot(RN3S Sorted matching(3)r)plot(RN3S Sorted matching(4)m)grid ontitle(RN3S)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)set(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN4png minusr300)h(5)=figure(NameSorted RatiosNumberTitleoff)RN1L ratio1=RN1L NodesG hatRN1L NodesGRN2L ratio1=RN2L NodesG hatRN2L NodesGRN3L ratio1=RN3L NodesG hatRN3L NodesGRN1S ratio1=RN1S NodesG hatRN1S NodesGRN2S ratio1=RN2S NodesG hatRN2S NodesGRN3S ratio1=RN3S NodesG hatRN3S NodesG

RN1L ratio2=RN1L EdgesG HatRN1L EdgesGRN2L ratio2=RN2L EdgesG HatRN2L EdgesGRN3L ratio2=RN3L EdgesG HatRN3L EdgesGRN1S ratio2=RN1S EdgesG HatRN1S EdgesGRN2S ratio2=RN2S EdgesG HatRN2S EdgesGRN3S ratio2=RN3S EdgesG HatRN3S EdgesG

RN1L ratio3=RN1L MaxDegreeG HatRN1L MaxDegreeGRN2L ratio3=RN2L MaxDegreeG HatRN2L MaxDegreeGRN3L ratio3=RN3L MaxDegreeG HatRN3L MaxDegreeGRN1S ratio3=RN1S MaxDegreeG HatRN1S MaxDegreeGRN2S ratio3=RN2S MaxDegreeG HatRN2S MaxDegreeGRN3S ratio3=RN3S MaxDegreeG HatRN3S MaxDegreeG

RN1L ratio(1)=RN1L ratio1RN1L ratio(2)=RN1L ratio2RN1L ratio(3)=RN1L ratio3

RN2L ratio(1)=RN2L ratio1RN2L ratio(2)=RN2L ratio2RN2L ratio(3)=RN2L ratio3

RN3L ratio(1)=RN3L ratio1RN3L ratio(2)=RN3L ratio2RN3L ratio(3)=RN3L ratio3

RN1S ratio(1)=RN1S ratio1RN1S ratio(2)=RN1S ratio2RN1S ratio(3)=RN1S ratio3

RN2S ratio(1)=RN2S ratio1

Appendix A 59

RN2S ratio(2)=RN2S ratio2RN2S ratio(3)=RN2S ratio3

RN3S ratio(1)=RN3S ratio1RN3S ratio(2)=RN3S ratio2RN3S ratio(3)=RN3S ratio3

RN1L ratio sorted=sortrows(RN1L ratio)RN2L ratio sorted=sortrows(RN2L ratio)RN3L ratio sorted=sortrows(RN3L ratio)RN1S ratio sorted=sortrows(RN1S ratio)RN2S ratio sorted=sortrows(RN2S ratio)RN3S ratio sorted=sortrows(RN3S ratio)

subplot(231)hold onplot(RN1L ratio sorted(1)b)plot(RN1L ratio sorted(2)g)plot(RN1L ratio sorted(3)r)grid ontitle(RN1L)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)

subplot(232)hold onplot(RN2L ratio sorted(1)b)plot(RN2L ratio sorted(2)g)plot(RN2L ratio sorted(3)r)grid ontitle(RN2L)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)

subplot(233)hold onplot(RN3L ratio sorted(1)b)plot(RN3L ratio sorted(2)g)plot(RN3L ratio sorted(3)r)grid ontitle(RN3L)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)

subplot(234)hold onplot(RN1S ratio sorted(1)b)plot(RN1S ratio sorted(2)g)plot(RN1S ratio sorted(3)r)grid on

60 Application

title(RN1S)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)

subplot(235)hold onplot(RN2S ratio sorted(1)b)plot(RN2S ratio sorted(2)g)plot(RN2S ratio sorted(3)r)grid ontitle(RN2S)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)

subplot(236)hold onplot(RN3S ratio sorted(1)b)plot(RN3S ratio sorted(2)g)plot(RN3S ratio sorted(3)r)grid ontitle(RN3S)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)set(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN5png minusr300)

h(6)=figure(NameSorted edges over nodesNumberTitleoff)

RN1L DegreeG1=(RN1L EdgesG)(RN1L NodesG)RN1L DegreeG Hat1=(RN1L EdgesG Hat)(RN1L NodesG hat)

RN1L Degree temp1(1)=RN1L DegreeG1RN1L Degree temp1(2)=RN1L DegreeG Hat1RN1L Degree sorted1=sortrows(RN1L Degree temp1)subplot(231)hold on

plot(RN1L Degree sorted1(1)b)plot(RN1L Degree sorted1(2)g)grid ontitle(RN1L)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)

RN2L DegreeG1=(RN2L EdgesG)(RN2L NodesG)RN2L DegreeG Hat1=(RN2L EdgesG Hat)(RN2L NodesG hat)

RN2L Degree temp1(1)=RN2L DegreeG1

Appendix A 61

RN2L Degree temp1(2)=RN2L DegreeG Hat1RN2L Degree sorted1=sortrows(RN2L Degree temp1)

subplot(232)hold onplot(RN2L Degree sorted1(1)b)plot(RN2L Degree sorted1(2)g)grid ontitle(RN2L)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)

RN3L DegreeG1=(RN3L EdgesG)(RN3L NodesG)RN3L DegreeG Hat1=(RN3L EdgesG Hat)(RN3L NodesG hat)

RN3L Degree temp1(1)=RN3L DegreeG1RN3L Degree temp1(2)=RN3L DegreeG Hat1RN3L Degree sorted1=sortrows(RN3L Degree temp1)

subplot(233)hold onplot(RN3L Degree sorted1(1)b)plot(RN3L Degree sorted1(2)g)grid ontitle(RN3L)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)

RN1S DegreeG1=(RN1S EdgesG)(RN1S NodesG)RN1S DegreeG Hat1=(RN1S EdgesG Hat)(RN1S NodesG hat)

RN1S Degree temp1(1)=RN1S DegreeG1RN1S Degree temp1(2)=RN1S DegreeG Hat1RN1S Degree sorted1=sortrows(RN1S Degree temp1)

subplot(234)hold onplot(RN1S Degree sorted1(1)b)plot(RN1S Degree sorted1(2)g)grid ontitle(RN1S)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)

RN2S DegreeG1=(RN2S EdgesG)(RN2S NodesG)RN2S DegreeG Hat1=(RN2S EdgesG Hat)(RN2S NodesG hat)

RN2S Degree temp1(1)=RN2S DegreeG1

62 Application

RN2S Degree temp1(2)=RN2S DegreeG Hat1RN2S Degree sorted1=sortrows(RN2S Degree temp1)

subplot(235)hold onplot(RN2S Degree sorted1(1)b)plot(RN2S Degree sorted1(2)g)grid ontitle(RN2S)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)

RN3S DegreeG1=(RN3S EdgesG)(RN3S NodesG)RN3S DegreeG Hat1=(RN3S EdgesG Hat)(RN3S NodesG hat)

RN3S Degree temp1(1)=RN3S DegreeG1RN3S Degree temp1(2)=RN3S DegreeG Hat1RN3S Degree sorted1=sortrows(RN3S Degree temp1)

subplot(236)hold onplot(RN3S Degree sorted1(1)b)plot(RN3S Degree sorted1(2)g)grid ontitle(RN3S)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)set(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN6png minusr300)h(7)=figure(NameSorted mATCHED DEGREENumberTitleoff)RN1L ratioMax(1)=RN1L MaxDegreeGRN1L ratioMax(2)=RN1L MaxDegreeG Hat

RN1L ratio sortedMax=sortrows(RN1L ratioMax)subplot(231)hold onplot(RN1L ratio sortedMax(1)b)plot(RN1L ratio sortedMax(2)g)grid ontitle(RN1L)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)

RN2L ratioMax(1)=RN2L MaxDegreeGRN2L ratioMax(2)=RN2L MaxDegreeG Hat

RN2L ratio sortedMax=sortrows(RN2L ratioMax)subplot(232)

Appendix A 63

hold onplot(RN2L ratio sortedMax(1)b)plot(RN2L ratio sortedMax(2)g)grid ontitle(RN2L)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)

RN3L ratioMax(1)=RN3L MaxDegreeGRN3L ratioMax(2)=RN3L MaxDegreeG Hat

RN3L ratio sortedMax=sortrows(RN3L ratioMax)subplot(233)hold onplot(RN3L ratio sortedMax(1)b)plot(RN3L ratio sortedMax(2)g)grid ontitle(RN3L)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)

RN1S ratioMax(1)=RN1S MaxDegreeGRN1S ratioMax(2)=RN1S MaxDegreeG Hat

RN1S ratio sortedMax=sortrows(RN1S ratioMax)subplot(234)hold onplot(RN1S ratio sortedMax(1)b)plot(RN1S ratio sortedMax(2)g)grid ontitle(RN1S)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)

RN2S ratioMax(1)=RN2S MaxDegreeGRN2S ratioMax(2)=RN2S MaxDegreeG Hat

RN2S ratio sortedMax=sortrows(RN2S ratioMax)

subplot(235)hold onplot(RN2S ratio sortedMax(1)b)plot(RN2S ratio sortedMax(2)g)grid ontitle(RN2S)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)

RN3S ratioMax(1)=RN3S MaxDegreeGRN3S ratioMax(2)=RN3S MaxDegreeG Hat

64 Application

RN3S ratio sortedMax=sortrows(RN3S ratioMax)subplot(236)hold onplot(RN3S ratio sortedMax(1)b)plot(RN3S ratio sortedMax(2)g)grid ontitle(RN1L)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)set(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN7png minusr300)

tilefigs()(h)

Bibliography

[1] C Berge ldquoTWO THEOREMS IN GRAPH THEORYrdquo Proceedings of the NationalAcademy of Sciences of the United States of America vol 43 no 9 pp 842ndash844Sep 1957

[2] L Bui S Sanghavi and R Srikant ldquoDistributed link scheduling with constantoverheadrdquo IEEEACM Trans Netw vol 17 no 5 pp 1467ndash1480 2009

[3] R Duan and S Pettie ldquoLinear-time approximation for maximum weight matchingrdquoJ ACM vol 61 no 1 2014

[4] J Edmonds ldquoPaths trees and flowersrdquo Canadian Journal of Mathematics vol 17pp 449ndash467 1965

[5] J E Hopcroft and R M Karp ldquoAn n52 algorithm for maximum matchings inbipartite graphsrdquo SIAM J Comput vol 2 no 4 pp 225ndash231 1973

[6] S Micali and V V Vazirani ldquoAn O(radic|V ||E|) algorithm for finding maximum

matching in general graphsrdquo in 21st Symp on Foundations of Comp Sc (FOCS)IEEE 1980 pp 17ndash27

[7] N Nisse A Salch and V Weber ldquoRecovery of disrupted airline operationsrdquo 2015httphalinriafrSomething

[8] X Wu and R Srikant ldquoRegulated maximal matching A distributed schedulingalgorithm for multi-hop wireless networks with nodeexclusive spectrum sharingrdquo inIEEE Conf on Decision and Control 2005

65

  • Contents
  • Introduction
  • Algorithms
    • Maximum matching
    • k-maximum matching
      • k-matching for Airport Slot assignment
      • The case where k=3
      • The case of Paths
      • The case of the Spider
          • Application
            • Description
            • Reyni Erdos
            • Barabaacutesi Albert
            • Amadeus Graphs
            • Bipartite
            • Bipartite with degree seq
            • Appendix A
              • BipartiteGraphGeneratorpy
              • RandomGraphGeneratorpy
              • kequals3MaximumMatchingpy
              • Plotmat
                  • Bibliography
Page 40: Theodoros Alexandros KARAGKIOULES -  · Introduction This work is the result of a 6 months internship, under the supervision of research O cer Nicolas NISSE. The original scope of

Appendix A 41

fwrite(str(n1+me1))fwrite(n)fwrite(str(n1+me1))fwrite(n)fwrite(str(m))fwrite(n)fwrite(n)fwrite(C)fwrite(n)fwrite(MC)

elif igt160 and ilt321G=bipartiteconfiguration model(aseq2 bseq2 create using=None seed=None)A=nxadjacency matrix(G)for ii in range(0n2+me2)

maadd node(ii)A=[Rtodense()tolist()[0] for R in A]

printnummanumber of nodes()rl=randomsample(range(0n2+me2) n2+me2)m=0done vertices = set()for p in rlprintin fordone verticesadd(p)

neighbors = []list()for iii in range(0n2+me2)

if A[p][iii]==1neighborsappend(iii)

randomshuffle(neighbors)continue loop = Truedegree = len(neighbors)

print degreej = 0p4=randomrandom()while continue loop and (jltdegree)

print in loopnext = neighbors[j]if next not in done vertices and p not in done vertices

done verticesadd(p)done verticesadd(next)if p4gt=07

print added edgemaadd edge(pnext)m=m+1

continue loop = Falsej += 1

print matching listOfedgeprint maedge

MA=nxadjacency matrix(ma)print MA

MA=[Rtodense()tolist()[0] for R in MA]print MA

B=[ join(map(strR)) for R in A]MB=[ join(map(strR)) for R in MA]

42 Application

C=njoin(B)+nMC=njoin(MB)+n

print nprint mprint m1

filea=str(i)+txtwith open(fileaw) as f

fwrite(str(n2+me2))fwrite(n)fwrite(str(n2+me2))fwrite(n)fwrite(str(m))fwrite(n)fwrite(n)fwrite(C)fwrite(n)fwrite(MC)

elseG=bipartiteconfiguration model(aseq3 bseq3 create using=None seed=None)A=nxadjacency matrix(G)for ii in range(0n3+me3)

maadd node(ii)A=[Rtodense()tolist()[0] for R in A]

printnummanumber of nodes()rl=randomsample(range(0n3+me3) n3+me3)m=0done vertices = set()for p in rlprintin fordone verticesadd(p)

neighbors = []list()for iii in range(0n3+me3)

if A[p][iii]==1neighborsappend(iii)

randomshuffle(neighbors)continue loop = Truedegree = len(neighbors)

print degreej = 0p4=randomrandom()while continue loop and (jltdegree)

print in loopnext = neighbors[j]if next not in done vertices and p not in done vertices

done verticesadd(p)done verticesadd(next)if p4gt=07print added edge

maadd edge(pnext)m=m+1

continue loop = Falsej += 1

Appendix A 43

print matching listOfedgeprint maedge

MA=nxadjacency matrix(ma)print MA

MA=[Rtodense()tolist()[0] for R in MA]print MA

B=[ join(map(strR)) for R in A]MB=[ join(map(strR)) for R in MA]

C=njoin(B)+nMC=njoin(MB)+n

print nprint mprint m1

filea=str(i)+txtwith open(fileaw) as f

fwrite(str(n3+me3))fwrite(n)fwrite(str(n3+me3))fwrite(n)fwrite(str(m))fwrite(n)fwrite(n)fwrite(C)fwrite(n)fwrite(MC)

print nRandom graphs with random matching have been generated

44 Application

RandomGraphGeneratorpy

from future import divisionimport networkx as nxfrom networkxalgorithms import approximationimport collectionsimport randomimport mathif name == main

for i in range(1481)index=1n=randomrandint(100 1000)

n=1000m=0m1=0p=randomrandom()p1=mathlog(n2)np2=13p3=mathlog(n2)n+01p=05t1=randomrandint(0 1)print im2=randomrandint(n2minus1 n2+1)G = nxGraph()ma = nxGraph()print nme1=randomrandint(1 10)me2=randomrandint(2050)me3=randomrandint(50100)if ilt241

if ilt=80G=nxfast gnp random graph(n p1 seed=None directed=False)

elif igt80 and ilt161G=nxfast gnp random graph(n p2 seed=None directed=False)

elseG=nxfast gnp random graph(n p3 seed=None directed=False)

elseif ilt=320

G=nxbarabasi albert graph(n me1 seed=None)elif igt320 and ilt401

G=nxbarabasi albert graph(n me2 seed=None)else

G=nxbarabasi albert graph(n me3 seed=None)A=nxadjacency matrix(G)for ii in range(0n)

maadd node(ii)A=[Rtodense()tolist()[0] for R in A]

rl=randomsample(range(0n) n)m=0

Appendix A 45

done vertices = set()for p in rl

done verticesadd(p)neighbors = []list()for iii in range(0n)

if A[p][iii]==1neighborsappend(iii)

randomshuffle(neighbors)continue loop = Truedegree = len(neighbors)j = 0p2=randomrandom()while continue loop and (jltdegree)

next = neighbors[j]if next not in done vertices and p not in done vertices

done verticesadd(p)done verticesadd(next)if p2gt=00 Larger probability for smaller initial matching

maadd edge(pnext)m=m+1

continue loop = Falsej += 1

print matching listOfedgeprint maedgeMA=nxadjacency matrix(ma)MA=[Rtodense()tolist()[0] for R in MA]print MAB=[ join(map(strR)) for R in A]MB=[ join(map(strR)) for R in MA]

C=njoin(B)+nMC=njoin(MB)+nprint MCprint nprint mprint m1filea=str(i)+txtwith open(fileaw) as f

fwrite(str(n))fwrite(n)fwrite(str(n))fwrite(n)fwrite(str(m))fwrite(n)fwrite(n)fwrite(C)fwrite(n)fwrite(MC)

print nRandom graphs with random matching have been generated

46 Application

kequals3MaximumMatchingpy

from future import divisionimport networkx as nxfrom networkxalgorithms import bipartiteimport matplotlibpyplot as pltimport collectionsimport timeitimport xlwtimport xlrdimport mathimport sys

Case for General Graphsdef forced edges(Gadj dict2matching dict1num nodesforced)

flagg=0for n in range(0num nodes)

for k in adj dict2[n]if ([k]==matching dict1[n])

count=0for l in range(0num nodes)

count=count+adj dict2[l]count(k)if (len(adj dict2[n])==1) or (count==1)

forcedadd edge(nk)Gremove edge(nk)Gremove node(n)Gremove node(k)printforced edgenktemp=kflagg=1for m in range (len(adj dict2[n])minus1minus1minus1)

adj dict2[adj dict2[n][m]]remove(n)adj dict2[n]remove(adj dict2[n][m])

if adj dict2[temp]for l in range(len(adj dict2[temp])minus1minus1minus1)

if (adj dict2[temp][l]=n)adj dict2[adj dict2[temp][l]]remove(temp)adj dict2[temp]remove(adj dict2[temp][l])

break

def useless edges(num nodesadj dict1matching dict1uselessadj dict2G)for n in range(0num nodes)

for k in adj dict1[n]if ([k]=matching dict1[n]) and matching dict1[n] and matching dict1[k]

uselessadd edge(nk)Gremove edge(n k)

Appendix A 47

tempa=kadj dict2[n]remove(k)adj dict2[tempa]remove(n)adj dict1[tempa]remove(n)

return G

def Greedy(num nodesadj dict3matching dict2)

for n in range(0num nodes)if matching dict2[n]

flag2=minus1flag3=minus1for v in adj dict3[n]

if not matching dict2[v]flag2=vbreak

for p in adj dict3[matching dict2[n][0]]if not matching dict2[p]

flag3=pbreak

if (flag2=minus1) and (flag3=minus1) and (flag2=flag3)tempr=matching dict2[n][0]matching dict2[n]=[flag2]matching dict2[flag2]=[n]matching dict2[tempr]=[flag3]matching dict2[flag3]=[tempr]

elsefor k in adj dict3[n]

if not matching dict2[k]matching dict2[n]=[k]matching dict2[k]=[n]break

yo1=0for i in range(0num nodes)

if matching dict2[i] and [i]==matching dict2[matching dict2[i][0]]yo1=yo1+1

greedy size=yo12return greedy size

def General()

INPUTSwb = xlwtWorkbook()ws = wbadd sheet(Results Random)book=xlrdopen workbook(filenames randomxls)

48 Application

style0 = xlwteasyxf(fontbold on)style1 = xlwteasyxf(num format str=0000)INPUTSwswrite(0 0File style0)wswrite(0 1 Nodesstyle0)wswrite(0 2 Initial matchingstyle0)wswrite(0 3 NodesGstyle0)wswrite(0 4 EdgesGstyle0)wswrite(0 5 MaxDegreeGstyle0)wswrite(0 6 NodesG hatstyle0)wswrite(0 7 EdgesG Hatstyle0)wswrite(0 8 Useless edgesstyle0)wswrite(0 9 Forced edgesstyle0)wswrite(0 10 MaxDegreeG Hatstyle0)wswrite(0 11 Classical matchingstyle0)wswrite(0 12 Final matchingstyle0)wswrite(0 13 Greedy matchingstyle0)wswrite(0 14 Time classicalstyle0)wswrite(0 15 Time algorithmstyle0)wswrite(0 16 Time greedystyle0)wswrite(0 17 Perfect matching ratiostyle0)wswrite(0 18 Nodes ratiostyle0)wswrite(0 19 Edges ratiostyle0)wswrite(0 20 Matching ratiostyle0)

print nWelcomeThis is an implementation for general random graphs It uses Edmonds algorithm to compute maximum matching on G Hatn

for index in range (1481)was 481

if (index==482)f=open(Algotel generaltxtr)readlines()

elsefilea=str(booksheet by index(0)cell(index0))s=fileareplace(textu)replace()f=open(sr)readlines()Truewswrite(index 0 s)

print index

num nodes=int([xstrip()split() for x in f][0][0])

num matching=int([xstrip()split() for x in f][2][0])

adj temp = [xstrip()split() for x in f][44+num nodes]adj=[map(intR) for R in adj temp]

matching temp=[xstrip()split() for x in f][4+num nodes+14+2num nodes+1]matching1=[map(intR) for R in matching temp]

adj dict1=i[ii for iix in enumerate(L) if x] for iL in enumerate(adj)adj dict2=i[ii for iix in enumerate(L) if x] for iL in enumerate(adj)

Appendix A 49

adj dict3=i[ii for iix in enumerate(L) if x] for iL in enumerate(adj)

matching dict1=i[ii for iix in enumerate(L) if x] for iL in enumerate(matching1)matching dict2=i[ii for iix in enumerate(L) if x] for iL in enumerate(matching1)print adj dict2print matching dict2wswrite(index 1 num nodes)wswrite(index 2 num matching)

G = nxGraph()

useless= nxGraph()forced = nxGraph()

Fill Graphfor n in range(0num nodes)

for k in adj dict1[n]Gadd edge(nk)

Gt=Gnumber of edges()wswrite(index 3 Gnumber of nodes())wswrite(index 4 Gnumber of edges())wswrite(index 5 max(Gdegree()values()))

Compute Edmonds classical matching on G for comparison

startB = timeitdefault timer()Classical Matching=nxmax weight matching(G maxcardinality=False)stopB = timeitdefault timer()

Compute Gˆ nad MˆstartC = timeitdefault timer()useless edges(num nodesadj dict1matching dict1uselessadj dict2G)forced edges(Gadj dict2matching dict1num nodesforced)Final Matching=nxmax weight matching(G maxcardinality=False)stopC = timeitdefault timer()

GreedystartG = timeitdefault timer()greedy size=Greedy(num nodesadj dict3matching dict2)stopG = timeitdefault timer()

wswrite(index 6 Gnumber of nodes())wswrite(index 7 Gnumber of edges())wswrite(index 8 uselessnumber of edges())wswrite(index 9 forcednumber of edges())if Gdegree()values()

wswrite(index 10 max(Gdegree()values()))else

50 Application

wswrite(index 10 0)wswrite(index 11 len(Classical Matching)2)wswrite(index 12 len(Final Matching)2+forcednumber of edges())wswrite(index 13 greedy size)wswrite(index 14 stopB minus startBstyle1)wswrite(index 15 stopC minus startCstyle1)wswrite(index 16 stopG minus startGstyle1)wswrite(index 17 (len(Final Matching)2+forcednumber of edges())(num nodes2)style1)wswrite(index 18 Gnumber of nodes()Gtstyle1)wswrite(index 19 Gnumber of edges()Gtstyle1)wswrite(index 20 (len(Final Matching)2+forcednumber of edges())(len(Classical Matching)2)style1)

wbsave(AA Results Random Reyni Large Bipartitexls)

Main function Here we must choose the input form of the dataif name == main

startA = timeitdefault timer()General()stopA = timeitdefault timer()

print nThis program has terminatednnRunning time for 480 files stopAminusstartAprint nnPlease open AA Results Random Reyni Largexls file to see the Results

Appendix A 51

Plotmat

clear allclose allload(RN1Lmat)load(RN1Smat)load(RN2Lmat)load(RN2Smat)load(RN3Lmat)load(RN3Smat)

Plotsh(1)=figure(NameHistogram of Matching size difference between Constraint Algorithm and Greedy AlgorithmNumberTitleoff)

RN1L Greedydiff=RN1L Final matchingminusRN1L Greedy matchingRN2L Greedydiff=RN2L Final matchingminusRN2L Greedy matchingRN3L Greedydiff=RN3L Final matchingminusRN3L Greedy matchingRN1S Greedydiff=RN1S Final matchingminusRN1S Greedy matchingRN2S Greedydiff=RN2S Final matchingminusRN2S Greedy matchingRN3S Greedydiff=RN3S Final matchingminusRN3S Greedy matching

RN1L Finaldiff=RN1L Classical matchingminusRN1L Final matchingRN2L Finaldiff=RN2L Classical matchingminusRN2L Final matchingRN3L Finaldiff=RN3L Classical matchingminusRN3L Final matchingRN1S Finaldiff=RN1S Classical matchingminusRN1S Final matchingRN2S Finaldiff=RN2S Classical matchingminusRN2S Final matchingRN3S Finaldiff=RN3S Classical matchingminusRN3S Final matching

RN1L Classicaldiff=(RN1L Nodes2)minusRN1L Classical matchingRN2L Classicaldiff=(RN2L Nodes2)minusRN2L Classical matchingRN3L Classicaldiff=(RN3L Nodes2)minusRN3L Classical matchingRN1S Classicaldiff=(RN1S Nodes2)minusRN1S Classical matchingRN2S Classicaldiff=(RN2S Nodes2)minusRN2S Classical matchingRN3S Classicaldiff=(RN3S Nodes2)minusRN3S Classical matching

subplot(231)hold onhistf(RN1L Greedydiff0110facecolorbfacealpha9edgealpha1)histf(RN1L Finaldiff0110facecolorrfacealpha5edgealpha1)histf(RN1L Classicaldiff0110facecolorgfacealpha5edgealpha1)legalpha(ConminusGreClasminusConPerfminusClasslocationnortheast)legend boxoffaxis tightxlabel(edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN1L)grid on

subplot(232)hold onhistf(RN2L Greedydiff0110facecolorbfacealpha9edgealpha1)

52 Application

histf(RN2L Finaldiff0110facecolorrfacealpha5edgealpha1)histf(RN2L Classicaldiff0110facecolorgfacealpha5edgealpha1)legalpha(ConminusGreClasminusConPerfminusClasslocationnortheast)legend boxoffaxis tightxlabel(edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN2L)grid on

subplot(233)hold onhistf(RN3L Greedydiff0110facecolorbfacealpha5edgealpha1)histf(RN3L Finaldiff0110facecolorrfacealpha5edgealpha1)histf(RN3L Classicaldiff0110facecolorgfacealpha5edgealpha1)legalpha(ConminusGreClasminusConPerfminusClasslocationnortheast)legend boxoffaxis tightxlabel(edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN3L)grid on

subplot(234)hold onhistf(RN1S Greedydiff0110facecolorbfacealpha5edgealpha1)histf(RN1S Finaldiff0110facecolorrfacealpha5edgealpha1)histf(RN1S Classicaldiff0110facecolorgfacealpha5edgealpha1)legalpha(ConminusGreClasminusConPerfminusClasslocationnortheast)legend boxoffaxis tightxlabel(edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(R1NS)grid on

subplot(235)hold onhistf(RN2S Greedydiff0110facecolorbfacealpha5edgealpha1)histf(RN2S Finaldiff0110facecolorrfacealpha5edgealpha1)histf(RN2S Classicaldiff0110facecolorgfacealpha5edgealpha1)legalpha(ConminusGreClasminusConPerfminusClasslocationnortheast)legend boxoffaxis tightxlabel(edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN2S)grid on

subplot(236)hold onhistf(RN3S Greedydiff0110facecolorbfacealpha5edgealpha1)histf(RN3S Finaldiff0110facecolorrfacealpha5edgealpha1)histf(RN3S Classicaldiff0110facecolorgfacealpha5edgealpha1)

Appendix A 53

legalpha(ConminusGreClasminusConPerfminusClasslocationnortheast)legend boxoffaxis tightgrid ontitle(RN3S)xlabel(edges) xminusaxis labelylabel(instances) yminusaxis labelset(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN1png minusr300)h(2)=figure(NameHistogram of Max Degree of G AND G HatNumberTitleoff)RN1L x=RN1L MaxDegreeGminusRN1L MaxDegreeG HatRN2L x=RN2L MaxDegreeGminusRN2L MaxDegreeG HatRN3L x=RN3L MaxDegreeGminusRN3L MaxDegreeG HatRN1S x=RN1S MaxDegreeGminusRN1S MaxDegreeG HatRN2S x=RN2S MaxDegreeGminusRN2S MaxDegreeG HatRN3S x=RN3S MaxDegreeGminusRN3S MaxDegreeG Hatsubplot(231)hold onhistf(RN1L MaxDegreeG0150facecolorbfacealpha5edgealpha1)histf(RN1L MaxDegreeG Hat0150facecolorrfacealpha5edgealpha1)histf(RN1L x0150facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightxlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN1L)grid on

subplot(232)hold onhistf(RN2L MaxDegreeG010500facecolorbfacealpha5edgealpha1)histf(RN2L MaxDegreeG Hat010500facecolorrfacealpha5edgealpha1)histf(RN2L x010500facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightxlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN2L)grid on

subplot(233)hold onhistf(RN3L MaxDegreeG010300facecolorbfacealpha5edgealpha1)histf(RN3L MaxDegreeG Hat010300facecolorrfacealpha5edgealpha1)histf(RN3L x010300facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightxlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN3L)

54 Application

grid on

subplot(234)hold onhistf(RN1S MaxDegreeG0150facecolorbfacealpha5edgealpha1)histf(RN1S MaxDegreeG Hat0150facecolorrfacealpha5edgealpha1)histf(RN1S x0150facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightxlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(R1NS)grid on

subplot(235)hold onhistf(RN2S MaxDegreeG010500facecolorbfacealpha5edgealpha1)histf(RN2S MaxDegreeG Hat010500facecolorrfacealpha5edgealpha1)histf(RN2S x010500facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightxlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN2S)grid on

subplot(236)hold onhistf(RN3S MaxDegreeG05300facecolorbfacealpha5edgealpha1)histf(RN3S MaxDegreeG Hat05300facecolorrfacealpha5edgealpha1)histf(RN3S x05300facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightgrid ontitle(RN3S)xlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labelset(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN2png minusr300)

h(3)=figure(NameComputation time over edgesNumberTitleoff)

subplot(231)hold onstem(RN1L EdgesGRN1L Time classicalg)stem(RN1L EdgesGRN1L Time algorithmro)stem(RN1L EdgesGRN1L Time greedybx)grid on

Appendix A 55

title(RN1L)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)

subplot(232)hold onstem(RN2L EdgesGRN2L Time classicalg)stem(RN2L EdgesGRN2L Time algorithmro)stem(RN2L EdgesGRN2L Time greedybx)grid ontitle(RN2L)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)

subplot(233)hold onstem(RN3L EdgesGRN3L Time classicalg)stem(RN3L EdgesGRN3L Time algorithmro)stem(RN3L EdgesGRN3L Time greedybx)grid ontitle(RN3L)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)

subplot(234)hold onstem(RN1S EdgesGRN1S Time classicalg)stem(RN1S EdgesGRN1S Time algorithmro)stem(RN1S EdgesGRN1S Time greedybx)grid ontitle(RN1S)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)

subplot(235)hold onstem(RN2S EdgesGRN2S Time classicalg)stem(RN2S EdgesGRN2S Time algorithmro)stem(RN2S EdgesGRN2S Time greedybx)grid ontitle(RN2S)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)

subplot(236)hold onstem(RN3S EdgesGRN3S Time classicalg)stem(RN3S EdgesGRN3S Time algorithmro)stem(RN3S EdgesGRN3S Time greedybx)

56 Application

grid ontitle(RN3S)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)set(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN3png minusr300)

h(4)=figure(NameSorted matching sizeNumberTitleoff)RN1L Sorted matching temp(1)=RN1L Classical matchingRN1L Sorted matching temp(2)=RN1L Final matchingRN1L Sorted matching temp(3)=RN1L Greedy matchingRN1L Sorted matching temp(4)=RN1L Initial matchingRN1L Sorted matching=sortrows(RN1L Sorted matching temp)

RN2L Sorted matching temp(1)=RN2L Classical matchingRN2L Sorted matching temp(2)=RN2L Final matchingRN2L Sorted matching temp(3)=RN2L Greedy matchingRN2L Sorted matching temp(4)=RN2L Initial matchingRN2L Sorted matching=sortrows(RN2L Sorted matching temp)

RN3L Sorted matching temp(1)=RN3L Classical matchingRN3L Sorted matching temp(2)=RN3L Final matchingRN3L Sorted matching temp(3)=RN3L Greedy matchingRN3L Sorted matching temp(4)=RN3L Initial matchingRN3L Sorted matching=sortrows(RN3L Sorted matching temp)

RN1S Sorted matching temp(1)=RN1S Classical matchingRN1S Sorted matching temp(2)=RN1S Final matchingRN1S Sorted matching temp(3)=RN1S Greedy matchingRN1S Sorted matching temp(4)=RN1S Initial matchingRN1S Sorted matching=sortrows(RN1S Sorted matching temp)

RN2S Sorted matching temp(1)=RN2S Classical matchingRN2S Sorted matching temp(2)=RN2S Final matchingRN2S Sorted matching temp(3)=RN2S Greedy matchingRN2S Sorted matching temp(4)=RN2S Initial matchingRN2S Sorted matching=sortrows(RN2S Sorted matching temp)

RN3S Sorted matching temp(1)=RN3S Classical matchingRN3S Sorted matching temp(2)=RN3S Final matchingRN3S Sorted matching temp(3)=RN3S Greedy matchingRN3S Sorted matching temp(4)=RN3S Initial matchingRN3S Sorted matching=sortrows(RN3S Sorted matching temp)

subplot(231)hold onplot(RN1L Sorted matching(1)b)plot(RN1L Sorted matching(2)g)plot(RN1L Sorted matching(3)r)plot(RN1L Sorted matching(4)m)

Appendix A 57

grid ontitle(RN1L)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)

subplot(232)hold onplot(RN2L Sorted matching(1)b)plot(RN2L Sorted matching(2)g)plot(RN2L Sorted matching(3)r)plot(RN2L Sorted matching(4)m)grid ontitle(RN2L)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)

subplot(233)hold onplot(RN3L Sorted matching(1)b)plot(RN3L Sorted matching(2)g)plot(RN3L Sorted matching(3)r)plot(RN3L Sorted matching(4)m)grid ontitle(RN3L)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)

subplot(234)hold onplot(RN1S Sorted matching(1)b)plot(RN1S Sorted matching(2)g)plot(RN1S Sorted matching(3)r)plot(RN1S Sorted matching(4)m)grid ontitle(RN1S)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)

subplot(235)hold onplot(RN2S Sorted matching(1)b)plot(RN2S Sorted matching(2)g)plot(RN2S Sorted matching(3)r)plot(RN2S Sorted matching(4)m)grid ontitle(RN2S)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)

58 Application

subplot(236)hold onplot(RN3S Sorted matching(1)b)plot(RN3S Sorted matching(2)g)plot(RN3S Sorted matching(3)r)plot(RN3S Sorted matching(4)m)grid ontitle(RN3S)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)set(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN4png minusr300)h(5)=figure(NameSorted RatiosNumberTitleoff)RN1L ratio1=RN1L NodesG hatRN1L NodesGRN2L ratio1=RN2L NodesG hatRN2L NodesGRN3L ratio1=RN3L NodesG hatRN3L NodesGRN1S ratio1=RN1S NodesG hatRN1S NodesGRN2S ratio1=RN2S NodesG hatRN2S NodesGRN3S ratio1=RN3S NodesG hatRN3S NodesG

RN1L ratio2=RN1L EdgesG HatRN1L EdgesGRN2L ratio2=RN2L EdgesG HatRN2L EdgesGRN3L ratio2=RN3L EdgesG HatRN3L EdgesGRN1S ratio2=RN1S EdgesG HatRN1S EdgesGRN2S ratio2=RN2S EdgesG HatRN2S EdgesGRN3S ratio2=RN3S EdgesG HatRN3S EdgesG

RN1L ratio3=RN1L MaxDegreeG HatRN1L MaxDegreeGRN2L ratio3=RN2L MaxDegreeG HatRN2L MaxDegreeGRN3L ratio3=RN3L MaxDegreeG HatRN3L MaxDegreeGRN1S ratio3=RN1S MaxDegreeG HatRN1S MaxDegreeGRN2S ratio3=RN2S MaxDegreeG HatRN2S MaxDegreeGRN3S ratio3=RN3S MaxDegreeG HatRN3S MaxDegreeG

RN1L ratio(1)=RN1L ratio1RN1L ratio(2)=RN1L ratio2RN1L ratio(3)=RN1L ratio3

RN2L ratio(1)=RN2L ratio1RN2L ratio(2)=RN2L ratio2RN2L ratio(3)=RN2L ratio3

RN3L ratio(1)=RN3L ratio1RN3L ratio(2)=RN3L ratio2RN3L ratio(3)=RN3L ratio3

RN1S ratio(1)=RN1S ratio1RN1S ratio(2)=RN1S ratio2RN1S ratio(3)=RN1S ratio3

RN2S ratio(1)=RN2S ratio1

Appendix A 59

RN2S ratio(2)=RN2S ratio2RN2S ratio(3)=RN2S ratio3

RN3S ratio(1)=RN3S ratio1RN3S ratio(2)=RN3S ratio2RN3S ratio(3)=RN3S ratio3

RN1L ratio sorted=sortrows(RN1L ratio)RN2L ratio sorted=sortrows(RN2L ratio)RN3L ratio sorted=sortrows(RN3L ratio)RN1S ratio sorted=sortrows(RN1S ratio)RN2S ratio sorted=sortrows(RN2S ratio)RN3S ratio sorted=sortrows(RN3S ratio)

subplot(231)hold onplot(RN1L ratio sorted(1)b)plot(RN1L ratio sorted(2)g)plot(RN1L ratio sorted(3)r)grid ontitle(RN1L)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)

subplot(232)hold onplot(RN2L ratio sorted(1)b)plot(RN2L ratio sorted(2)g)plot(RN2L ratio sorted(3)r)grid ontitle(RN2L)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)

subplot(233)hold onplot(RN3L ratio sorted(1)b)plot(RN3L ratio sorted(2)g)plot(RN3L ratio sorted(3)r)grid ontitle(RN3L)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)

subplot(234)hold onplot(RN1S ratio sorted(1)b)plot(RN1S ratio sorted(2)g)plot(RN1S ratio sorted(3)r)grid on

60 Application

title(RN1S)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)

subplot(235)hold onplot(RN2S ratio sorted(1)b)plot(RN2S ratio sorted(2)g)plot(RN2S ratio sorted(3)r)grid ontitle(RN2S)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)

subplot(236)hold onplot(RN3S ratio sorted(1)b)plot(RN3S ratio sorted(2)g)plot(RN3S ratio sorted(3)r)grid ontitle(RN3S)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)set(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN5png minusr300)

h(6)=figure(NameSorted edges over nodesNumberTitleoff)

RN1L DegreeG1=(RN1L EdgesG)(RN1L NodesG)RN1L DegreeG Hat1=(RN1L EdgesG Hat)(RN1L NodesG hat)

RN1L Degree temp1(1)=RN1L DegreeG1RN1L Degree temp1(2)=RN1L DegreeG Hat1RN1L Degree sorted1=sortrows(RN1L Degree temp1)subplot(231)hold on

plot(RN1L Degree sorted1(1)b)plot(RN1L Degree sorted1(2)g)grid ontitle(RN1L)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)

RN2L DegreeG1=(RN2L EdgesG)(RN2L NodesG)RN2L DegreeG Hat1=(RN2L EdgesG Hat)(RN2L NodesG hat)

RN2L Degree temp1(1)=RN2L DegreeG1

Appendix A 61

RN2L Degree temp1(2)=RN2L DegreeG Hat1RN2L Degree sorted1=sortrows(RN2L Degree temp1)

subplot(232)hold onplot(RN2L Degree sorted1(1)b)plot(RN2L Degree sorted1(2)g)grid ontitle(RN2L)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)

RN3L DegreeG1=(RN3L EdgesG)(RN3L NodesG)RN3L DegreeG Hat1=(RN3L EdgesG Hat)(RN3L NodesG hat)

RN3L Degree temp1(1)=RN3L DegreeG1RN3L Degree temp1(2)=RN3L DegreeG Hat1RN3L Degree sorted1=sortrows(RN3L Degree temp1)

subplot(233)hold onplot(RN3L Degree sorted1(1)b)plot(RN3L Degree sorted1(2)g)grid ontitle(RN3L)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)

RN1S DegreeG1=(RN1S EdgesG)(RN1S NodesG)RN1S DegreeG Hat1=(RN1S EdgesG Hat)(RN1S NodesG hat)

RN1S Degree temp1(1)=RN1S DegreeG1RN1S Degree temp1(2)=RN1S DegreeG Hat1RN1S Degree sorted1=sortrows(RN1S Degree temp1)

subplot(234)hold onplot(RN1S Degree sorted1(1)b)plot(RN1S Degree sorted1(2)g)grid ontitle(RN1S)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)

RN2S DegreeG1=(RN2S EdgesG)(RN2S NodesG)RN2S DegreeG Hat1=(RN2S EdgesG Hat)(RN2S NodesG hat)

RN2S Degree temp1(1)=RN2S DegreeG1

62 Application

RN2S Degree temp1(2)=RN2S DegreeG Hat1RN2S Degree sorted1=sortrows(RN2S Degree temp1)

subplot(235)hold onplot(RN2S Degree sorted1(1)b)plot(RN2S Degree sorted1(2)g)grid ontitle(RN2S)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)

RN3S DegreeG1=(RN3S EdgesG)(RN3S NodesG)RN3S DegreeG Hat1=(RN3S EdgesG Hat)(RN3S NodesG hat)

RN3S Degree temp1(1)=RN3S DegreeG1RN3S Degree temp1(2)=RN3S DegreeG Hat1RN3S Degree sorted1=sortrows(RN3S Degree temp1)

subplot(236)hold onplot(RN3S Degree sorted1(1)b)plot(RN3S Degree sorted1(2)g)grid ontitle(RN3S)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)set(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN6png minusr300)h(7)=figure(NameSorted mATCHED DEGREENumberTitleoff)RN1L ratioMax(1)=RN1L MaxDegreeGRN1L ratioMax(2)=RN1L MaxDegreeG Hat

RN1L ratio sortedMax=sortrows(RN1L ratioMax)subplot(231)hold onplot(RN1L ratio sortedMax(1)b)plot(RN1L ratio sortedMax(2)g)grid ontitle(RN1L)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)

RN2L ratioMax(1)=RN2L MaxDegreeGRN2L ratioMax(2)=RN2L MaxDegreeG Hat

RN2L ratio sortedMax=sortrows(RN2L ratioMax)subplot(232)

Appendix A 63

hold onplot(RN2L ratio sortedMax(1)b)plot(RN2L ratio sortedMax(2)g)grid ontitle(RN2L)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)

RN3L ratioMax(1)=RN3L MaxDegreeGRN3L ratioMax(2)=RN3L MaxDegreeG Hat

RN3L ratio sortedMax=sortrows(RN3L ratioMax)subplot(233)hold onplot(RN3L ratio sortedMax(1)b)plot(RN3L ratio sortedMax(2)g)grid ontitle(RN3L)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)

RN1S ratioMax(1)=RN1S MaxDegreeGRN1S ratioMax(2)=RN1S MaxDegreeG Hat

RN1S ratio sortedMax=sortrows(RN1S ratioMax)subplot(234)hold onplot(RN1S ratio sortedMax(1)b)plot(RN1S ratio sortedMax(2)g)grid ontitle(RN1S)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)

RN2S ratioMax(1)=RN2S MaxDegreeGRN2S ratioMax(2)=RN2S MaxDegreeG Hat

RN2S ratio sortedMax=sortrows(RN2S ratioMax)

subplot(235)hold onplot(RN2S ratio sortedMax(1)b)plot(RN2S ratio sortedMax(2)g)grid ontitle(RN2S)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)

RN3S ratioMax(1)=RN3S MaxDegreeGRN3S ratioMax(2)=RN3S MaxDegreeG Hat

64 Application

RN3S ratio sortedMax=sortrows(RN3S ratioMax)subplot(236)hold onplot(RN3S ratio sortedMax(1)b)plot(RN3S ratio sortedMax(2)g)grid ontitle(RN1L)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)set(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN7png minusr300)

tilefigs()(h)

Bibliography

[1] C Berge ldquoTWO THEOREMS IN GRAPH THEORYrdquo Proceedings of the NationalAcademy of Sciences of the United States of America vol 43 no 9 pp 842ndash844Sep 1957

[2] L Bui S Sanghavi and R Srikant ldquoDistributed link scheduling with constantoverheadrdquo IEEEACM Trans Netw vol 17 no 5 pp 1467ndash1480 2009

[3] R Duan and S Pettie ldquoLinear-time approximation for maximum weight matchingrdquoJ ACM vol 61 no 1 2014

[4] J Edmonds ldquoPaths trees and flowersrdquo Canadian Journal of Mathematics vol 17pp 449ndash467 1965

[5] J E Hopcroft and R M Karp ldquoAn n52 algorithm for maximum matchings inbipartite graphsrdquo SIAM J Comput vol 2 no 4 pp 225ndash231 1973

[6] S Micali and V V Vazirani ldquoAn O(radic|V ||E|) algorithm for finding maximum

matching in general graphsrdquo in 21st Symp on Foundations of Comp Sc (FOCS)IEEE 1980 pp 17ndash27

[7] N Nisse A Salch and V Weber ldquoRecovery of disrupted airline operationsrdquo 2015httphalinriafrSomething

[8] X Wu and R Srikant ldquoRegulated maximal matching A distributed schedulingalgorithm for multi-hop wireless networks with nodeexclusive spectrum sharingrdquo inIEEE Conf on Decision and Control 2005

65

  • Contents
  • Introduction
  • Algorithms
    • Maximum matching
    • k-maximum matching
      • k-matching for Airport Slot assignment
      • The case where k=3
      • The case of Paths
      • The case of the Spider
          • Application
            • Description
            • Reyni Erdos
            • Barabaacutesi Albert
            • Amadeus Graphs
            • Bipartite
            • Bipartite with degree seq
            • Appendix A
              • BipartiteGraphGeneratorpy
              • RandomGraphGeneratorpy
              • kequals3MaximumMatchingpy
              • Plotmat
                  • Bibliography
Page 41: Theodoros Alexandros KARAGKIOULES -  · Introduction This work is the result of a 6 months internship, under the supervision of research O cer Nicolas NISSE. The original scope of

42 Application

C=njoin(B)+nMC=njoin(MB)+n

print nprint mprint m1

filea=str(i)+txtwith open(fileaw) as f

fwrite(str(n2+me2))fwrite(n)fwrite(str(n2+me2))fwrite(n)fwrite(str(m))fwrite(n)fwrite(n)fwrite(C)fwrite(n)fwrite(MC)

elseG=bipartiteconfiguration model(aseq3 bseq3 create using=None seed=None)A=nxadjacency matrix(G)for ii in range(0n3+me3)

maadd node(ii)A=[Rtodense()tolist()[0] for R in A]

printnummanumber of nodes()rl=randomsample(range(0n3+me3) n3+me3)m=0done vertices = set()for p in rlprintin fordone verticesadd(p)

neighbors = []list()for iii in range(0n3+me3)

if A[p][iii]==1neighborsappend(iii)

randomshuffle(neighbors)continue loop = Truedegree = len(neighbors)

print degreej = 0p4=randomrandom()while continue loop and (jltdegree)

print in loopnext = neighbors[j]if next not in done vertices and p not in done vertices

done verticesadd(p)done verticesadd(next)if p4gt=07print added edge

maadd edge(pnext)m=m+1

continue loop = Falsej += 1

Appendix A 43

print matching listOfedgeprint maedge

MA=nxadjacency matrix(ma)print MA

MA=[Rtodense()tolist()[0] for R in MA]print MA

B=[ join(map(strR)) for R in A]MB=[ join(map(strR)) for R in MA]

C=njoin(B)+nMC=njoin(MB)+n

print nprint mprint m1

filea=str(i)+txtwith open(fileaw) as f

fwrite(str(n3+me3))fwrite(n)fwrite(str(n3+me3))fwrite(n)fwrite(str(m))fwrite(n)fwrite(n)fwrite(C)fwrite(n)fwrite(MC)

print nRandom graphs with random matching have been generated

44 Application

RandomGraphGeneratorpy

from future import divisionimport networkx as nxfrom networkxalgorithms import approximationimport collectionsimport randomimport mathif name == main

for i in range(1481)index=1n=randomrandint(100 1000)

n=1000m=0m1=0p=randomrandom()p1=mathlog(n2)np2=13p3=mathlog(n2)n+01p=05t1=randomrandint(0 1)print im2=randomrandint(n2minus1 n2+1)G = nxGraph()ma = nxGraph()print nme1=randomrandint(1 10)me2=randomrandint(2050)me3=randomrandint(50100)if ilt241

if ilt=80G=nxfast gnp random graph(n p1 seed=None directed=False)

elif igt80 and ilt161G=nxfast gnp random graph(n p2 seed=None directed=False)

elseG=nxfast gnp random graph(n p3 seed=None directed=False)

elseif ilt=320

G=nxbarabasi albert graph(n me1 seed=None)elif igt320 and ilt401

G=nxbarabasi albert graph(n me2 seed=None)else

G=nxbarabasi albert graph(n me3 seed=None)A=nxadjacency matrix(G)for ii in range(0n)

maadd node(ii)A=[Rtodense()tolist()[0] for R in A]

rl=randomsample(range(0n) n)m=0

Appendix A 45

done vertices = set()for p in rl

done verticesadd(p)neighbors = []list()for iii in range(0n)

if A[p][iii]==1neighborsappend(iii)

randomshuffle(neighbors)continue loop = Truedegree = len(neighbors)j = 0p2=randomrandom()while continue loop and (jltdegree)

next = neighbors[j]if next not in done vertices and p not in done vertices

done verticesadd(p)done verticesadd(next)if p2gt=00 Larger probability for smaller initial matching

maadd edge(pnext)m=m+1

continue loop = Falsej += 1

print matching listOfedgeprint maedgeMA=nxadjacency matrix(ma)MA=[Rtodense()tolist()[0] for R in MA]print MAB=[ join(map(strR)) for R in A]MB=[ join(map(strR)) for R in MA]

C=njoin(B)+nMC=njoin(MB)+nprint MCprint nprint mprint m1filea=str(i)+txtwith open(fileaw) as f

fwrite(str(n))fwrite(n)fwrite(str(n))fwrite(n)fwrite(str(m))fwrite(n)fwrite(n)fwrite(C)fwrite(n)fwrite(MC)

print nRandom graphs with random matching have been generated

46 Application

kequals3MaximumMatchingpy

from future import divisionimport networkx as nxfrom networkxalgorithms import bipartiteimport matplotlibpyplot as pltimport collectionsimport timeitimport xlwtimport xlrdimport mathimport sys

Case for General Graphsdef forced edges(Gadj dict2matching dict1num nodesforced)

flagg=0for n in range(0num nodes)

for k in adj dict2[n]if ([k]==matching dict1[n])

count=0for l in range(0num nodes)

count=count+adj dict2[l]count(k)if (len(adj dict2[n])==1) or (count==1)

forcedadd edge(nk)Gremove edge(nk)Gremove node(n)Gremove node(k)printforced edgenktemp=kflagg=1for m in range (len(adj dict2[n])minus1minus1minus1)

adj dict2[adj dict2[n][m]]remove(n)adj dict2[n]remove(adj dict2[n][m])

if adj dict2[temp]for l in range(len(adj dict2[temp])minus1minus1minus1)

if (adj dict2[temp][l]=n)adj dict2[adj dict2[temp][l]]remove(temp)adj dict2[temp]remove(adj dict2[temp][l])

break

def useless edges(num nodesadj dict1matching dict1uselessadj dict2G)for n in range(0num nodes)

for k in adj dict1[n]if ([k]=matching dict1[n]) and matching dict1[n] and matching dict1[k]

uselessadd edge(nk)Gremove edge(n k)

Appendix A 47

tempa=kadj dict2[n]remove(k)adj dict2[tempa]remove(n)adj dict1[tempa]remove(n)

return G

def Greedy(num nodesadj dict3matching dict2)

for n in range(0num nodes)if matching dict2[n]

flag2=minus1flag3=minus1for v in adj dict3[n]

if not matching dict2[v]flag2=vbreak

for p in adj dict3[matching dict2[n][0]]if not matching dict2[p]

flag3=pbreak

if (flag2=minus1) and (flag3=minus1) and (flag2=flag3)tempr=matching dict2[n][0]matching dict2[n]=[flag2]matching dict2[flag2]=[n]matching dict2[tempr]=[flag3]matching dict2[flag3]=[tempr]

elsefor k in adj dict3[n]

if not matching dict2[k]matching dict2[n]=[k]matching dict2[k]=[n]break

yo1=0for i in range(0num nodes)

if matching dict2[i] and [i]==matching dict2[matching dict2[i][0]]yo1=yo1+1

greedy size=yo12return greedy size

def General()

INPUTSwb = xlwtWorkbook()ws = wbadd sheet(Results Random)book=xlrdopen workbook(filenames randomxls)

48 Application

style0 = xlwteasyxf(fontbold on)style1 = xlwteasyxf(num format str=0000)INPUTSwswrite(0 0File style0)wswrite(0 1 Nodesstyle0)wswrite(0 2 Initial matchingstyle0)wswrite(0 3 NodesGstyle0)wswrite(0 4 EdgesGstyle0)wswrite(0 5 MaxDegreeGstyle0)wswrite(0 6 NodesG hatstyle0)wswrite(0 7 EdgesG Hatstyle0)wswrite(0 8 Useless edgesstyle0)wswrite(0 9 Forced edgesstyle0)wswrite(0 10 MaxDegreeG Hatstyle0)wswrite(0 11 Classical matchingstyle0)wswrite(0 12 Final matchingstyle0)wswrite(0 13 Greedy matchingstyle0)wswrite(0 14 Time classicalstyle0)wswrite(0 15 Time algorithmstyle0)wswrite(0 16 Time greedystyle0)wswrite(0 17 Perfect matching ratiostyle0)wswrite(0 18 Nodes ratiostyle0)wswrite(0 19 Edges ratiostyle0)wswrite(0 20 Matching ratiostyle0)

print nWelcomeThis is an implementation for general random graphs It uses Edmonds algorithm to compute maximum matching on G Hatn

for index in range (1481)was 481

if (index==482)f=open(Algotel generaltxtr)readlines()

elsefilea=str(booksheet by index(0)cell(index0))s=fileareplace(textu)replace()f=open(sr)readlines()Truewswrite(index 0 s)

print index

num nodes=int([xstrip()split() for x in f][0][0])

num matching=int([xstrip()split() for x in f][2][0])

adj temp = [xstrip()split() for x in f][44+num nodes]adj=[map(intR) for R in adj temp]

matching temp=[xstrip()split() for x in f][4+num nodes+14+2num nodes+1]matching1=[map(intR) for R in matching temp]

adj dict1=i[ii for iix in enumerate(L) if x] for iL in enumerate(adj)adj dict2=i[ii for iix in enumerate(L) if x] for iL in enumerate(adj)

Appendix A 49

adj dict3=i[ii for iix in enumerate(L) if x] for iL in enumerate(adj)

matching dict1=i[ii for iix in enumerate(L) if x] for iL in enumerate(matching1)matching dict2=i[ii for iix in enumerate(L) if x] for iL in enumerate(matching1)print adj dict2print matching dict2wswrite(index 1 num nodes)wswrite(index 2 num matching)

G = nxGraph()

useless= nxGraph()forced = nxGraph()

Fill Graphfor n in range(0num nodes)

for k in adj dict1[n]Gadd edge(nk)

Gt=Gnumber of edges()wswrite(index 3 Gnumber of nodes())wswrite(index 4 Gnumber of edges())wswrite(index 5 max(Gdegree()values()))

Compute Edmonds classical matching on G for comparison

startB = timeitdefault timer()Classical Matching=nxmax weight matching(G maxcardinality=False)stopB = timeitdefault timer()

Compute Gˆ nad MˆstartC = timeitdefault timer()useless edges(num nodesadj dict1matching dict1uselessadj dict2G)forced edges(Gadj dict2matching dict1num nodesforced)Final Matching=nxmax weight matching(G maxcardinality=False)stopC = timeitdefault timer()

GreedystartG = timeitdefault timer()greedy size=Greedy(num nodesadj dict3matching dict2)stopG = timeitdefault timer()

wswrite(index 6 Gnumber of nodes())wswrite(index 7 Gnumber of edges())wswrite(index 8 uselessnumber of edges())wswrite(index 9 forcednumber of edges())if Gdegree()values()

wswrite(index 10 max(Gdegree()values()))else

50 Application

wswrite(index 10 0)wswrite(index 11 len(Classical Matching)2)wswrite(index 12 len(Final Matching)2+forcednumber of edges())wswrite(index 13 greedy size)wswrite(index 14 stopB minus startBstyle1)wswrite(index 15 stopC minus startCstyle1)wswrite(index 16 stopG minus startGstyle1)wswrite(index 17 (len(Final Matching)2+forcednumber of edges())(num nodes2)style1)wswrite(index 18 Gnumber of nodes()Gtstyle1)wswrite(index 19 Gnumber of edges()Gtstyle1)wswrite(index 20 (len(Final Matching)2+forcednumber of edges())(len(Classical Matching)2)style1)

wbsave(AA Results Random Reyni Large Bipartitexls)

Main function Here we must choose the input form of the dataif name == main

startA = timeitdefault timer()General()stopA = timeitdefault timer()

print nThis program has terminatednnRunning time for 480 files stopAminusstartAprint nnPlease open AA Results Random Reyni Largexls file to see the Results

Appendix A 51

Plotmat

clear allclose allload(RN1Lmat)load(RN1Smat)load(RN2Lmat)load(RN2Smat)load(RN3Lmat)load(RN3Smat)

Plotsh(1)=figure(NameHistogram of Matching size difference between Constraint Algorithm and Greedy AlgorithmNumberTitleoff)

RN1L Greedydiff=RN1L Final matchingminusRN1L Greedy matchingRN2L Greedydiff=RN2L Final matchingminusRN2L Greedy matchingRN3L Greedydiff=RN3L Final matchingminusRN3L Greedy matchingRN1S Greedydiff=RN1S Final matchingminusRN1S Greedy matchingRN2S Greedydiff=RN2S Final matchingminusRN2S Greedy matchingRN3S Greedydiff=RN3S Final matchingminusRN3S Greedy matching

RN1L Finaldiff=RN1L Classical matchingminusRN1L Final matchingRN2L Finaldiff=RN2L Classical matchingminusRN2L Final matchingRN3L Finaldiff=RN3L Classical matchingminusRN3L Final matchingRN1S Finaldiff=RN1S Classical matchingminusRN1S Final matchingRN2S Finaldiff=RN2S Classical matchingminusRN2S Final matchingRN3S Finaldiff=RN3S Classical matchingminusRN3S Final matching

RN1L Classicaldiff=(RN1L Nodes2)minusRN1L Classical matchingRN2L Classicaldiff=(RN2L Nodes2)minusRN2L Classical matchingRN3L Classicaldiff=(RN3L Nodes2)minusRN3L Classical matchingRN1S Classicaldiff=(RN1S Nodes2)minusRN1S Classical matchingRN2S Classicaldiff=(RN2S Nodes2)minusRN2S Classical matchingRN3S Classicaldiff=(RN3S Nodes2)minusRN3S Classical matching

subplot(231)hold onhistf(RN1L Greedydiff0110facecolorbfacealpha9edgealpha1)histf(RN1L Finaldiff0110facecolorrfacealpha5edgealpha1)histf(RN1L Classicaldiff0110facecolorgfacealpha5edgealpha1)legalpha(ConminusGreClasminusConPerfminusClasslocationnortheast)legend boxoffaxis tightxlabel(edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN1L)grid on

subplot(232)hold onhistf(RN2L Greedydiff0110facecolorbfacealpha9edgealpha1)

52 Application

histf(RN2L Finaldiff0110facecolorrfacealpha5edgealpha1)histf(RN2L Classicaldiff0110facecolorgfacealpha5edgealpha1)legalpha(ConminusGreClasminusConPerfminusClasslocationnortheast)legend boxoffaxis tightxlabel(edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN2L)grid on

subplot(233)hold onhistf(RN3L Greedydiff0110facecolorbfacealpha5edgealpha1)histf(RN3L Finaldiff0110facecolorrfacealpha5edgealpha1)histf(RN3L Classicaldiff0110facecolorgfacealpha5edgealpha1)legalpha(ConminusGreClasminusConPerfminusClasslocationnortheast)legend boxoffaxis tightxlabel(edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN3L)grid on

subplot(234)hold onhistf(RN1S Greedydiff0110facecolorbfacealpha5edgealpha1)histf(RN1S Finaldiff0110facecolorrfacealpha5edgealpha1)histf(RN1S Classicaldiff0110facecolorgfacealpha5edgealpha1)legalpha(ConminusGreClasminusConPerfminusClasslocationnortheast)legend boxoffaxis tightxlabel(edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(R1NS)grid on

subplot(235)hold onhistf(RN2S Greedydiff0110facecolorbfacealpha5edgealpha1)histf(RN2S Finaldiff0110facecolorrfacealpha5edgealpha1)histf(RN2S Classicaldiff0110facecolorgfacealpha5edgealpha1)legalpha(ConminusGreClasminusConPerfminusClasslocationnortheast)legend boxoffaxis tightxlabel(edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN2S)grid on

subplot(236)hold onhistf(RN3S Greedydiff0110facecolorbfacealpha5edgealpha1)histf(RN3S Finaldiff0110facecolorrfacealpha5edgealpha1)histf(RN3S Classicaldiff0110facecolorgfacealpha5edgealpha1)

Appendix A 53

legalpha(ConminusGreClasminusConPerfminusClasslocationnortheast)legend boxoffaxis tightgrid ontitle(RN3S)xlabel(edges) xminusaxis labelylabel(instances) yminusaxis labelset(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN1png minusr300)h(2)=figure(NameHistogram of Max Degree of G AND G HatNumberTitleoff)RN1L x=RN1L MaxDegreeGminusRN1L MaxDegreeG HatRN2L x=RN2L MaxDegreeGminusRN2L MaxDegreeG HatRN3L x=RN3L MaxDegreeGminusRN3L MaxDegreeG HatRN1S x=RN1S MaxDegreeGminusRN1S MaxDegreeG HatRN2S x=RN2S MaxDegreeGminusRN2S MaxDegreeG HatRN3S x=RN3S MaxDegreeGminusRN3S MaxDegreeG Hatsubplot(231)hold onhistf(RN1L MaxDegreeG0150facecolorbfacealpha5edgealpha1)histf(RN1L MaxDegreeG Hat0150facecolorrfacealpha5edgealpha1)histf(RN1L x0150facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightxlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN1L)grid on

subplot(232)hold onhistf(RN2L MaxDegreeG010500facecolorbfacealpha5edgealpha1)histf(RN2L MaxDegreeG Hat010500facecolorrfacealpha5edgealpha1)histf(RN2L x010500facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightxlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN2L)grid on

subplot(233)hold onhistf(RN3L MaxDegreeG010300facecolorbfacealpha5edgealpha1)histf(RN3L MaxDegreeG Hat010300facecolorrfacealpha5edgealpha1)histf(RN3L x010300facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightxlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN3L)

54 Application

grid on

subplot(234)hold onhistf(RN1S MaxDegreeG0150facecolorbfacealpha5edgealpha1)histf(RN1S MaxDegreeG Hat0150facecolorrfacealpha5edgealpha1)histf(RN1S x0150facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightxlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(R1NS)grid on

subplot(235)hold onhistf(RN2S MaxDegreeG010500facecolorbfacealpha5edgealpha1)histf(RN2S MaxDegreeG Hat010500facecolorrfacealpha5edgealpha1)histf(RN2S x010500facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightxlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN2S)grid on

subplot(236)hold onhistf(RN3S MaxDegreeG05300facecolorbfacealpha5edgealpha1)histf(RN3S MaxDegreeG Hat05300facecolorrfacealpha5edgealpha1)histf(RN3S x05300facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightgrid ontitle(RN3S)xlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labelset(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN2png minusr300)

h(3)=figure(NameComputation time over edgesNumberTitleoff)

subplot(231)hold onstem(RN1L EdgesGRN1L Time classicalg)stem(RN1L EdgesGRN1L Time algorithmro)stem(RN1L EdgesGRN1L Time greedybx)grid on

Appendix A 55

title(RN1L)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)

subplot(232)hold onstem(RN2L EdgesGRN2L Time classicalg)stem(RN2L EdgesGRN2L Time algorithmro)stem(RN2L EdgesGRN2L Time greedybx)grid ontitle(RN2L)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)

subplot(233)hold onstem(RN3L EdgesGRN3L Time classicalg)stem(RN3L EdgesGRN3L Time algorithmro)stem(RN3L EdgesGRN3L Time greedybx)grid ontitle(RN3L)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)

subplot(234)hold onstem(RN1S EdgesGRN1S Time classicalg)stem(RN1S EdgesGRN1S Time algorithmro)stem(RN1S EdgesGRN1S Time greedybx)grid ontitle(RN1S)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)

subplot(235)hold onstem(RN2S EdgesGRN2S Time classicalg)stem(RN2S EdgesGRN2S Time algorithmro)stem(RN2S EdgesGRN2S Time greedybx)grid ontitle(RN2S)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)

subplot(236)hold onstem(RN3S EdgesGRN3S Time classicalg)stem(RN3S EdgesGRN3S Time algorithmro)stem(RN3S EdgesGRN3S Time greedybx)

56 Application

grid ontitle(RN3S)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)set(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN3png minusr300)

h(4)=figure(NameSorted matching sizeNumberTitleoff)RN1L Sorted matching temp(1)=RN1L Classical matchingRN1L Sorted matching temp(2)=RN1L Final matchingRN1L Sorted matching temp(3)=RN1L Greedy matchingRN1L Sorted matching temp(4)=RN1L Initial matchingRN1L Sorted matching=sortrows(RN1L Sorted matching temp)

RN2L Sorted matching temp(1)=RN2L Classical matchingRN2L Sorted matching temp(2)=RN2L Final matchingRN2L Sorted matching temp(3)=RN2L Greedy matchingRN2L Sorted matching temp(4)=RN2L Initial matchingRN2L Sorted matching=sortrows(RN2L Sorted matching temp)

RN3L Sorted matching temp(1)=RN3L Classical matchingRN3L Sorted matching temp(2)=RN3L Final matchingRN3L Sorted matching temp(3)=RN3L Greedy matchingRN3L Sorted matching temp(4)=RN3L Initial matchingRN3L Sorted matching=sortrows(RN3L Sorted matching temp)

RN1S Sorted matching temp(1)=RN1S Classical matchingRN1S Sorted matching temp(2)=RN1S Final matchingRN1S Sorted matching temp(3)=RN1S Greedy matchingRN1S Sorted matching temp(4)=RN1S Initial matchingRN1S Sorted matching=sortrows(RN1S Sorted matching temp)

RN2S Sorted matching temp(1)=RN2S Classical matchingRN2S Sorted matching temp(2)=RN2S Final matchingRN2S Sorted matching temp(3)=RN2S Greedy matchingRN2S Sorted matching temp(4)=RN2S Initial matchingRN2S Sorted matching=sortrows(RN2S Sorted matching temp)

RN3S Sorted matching temp(1)=RN3S Classical matchingRN3S Sorted matching temp(2)=RN3S Final matchingRN3S Sorted matching temp(3)=RN3S Greedy matchingRN3S Sorted matching temp(4)=RN3S Initial matchingRN3S Sorted matching=sortrows(RN3S Sorted matching temp)

subplot(231)hold onplot(RN1L Sorted matching(1)b)plot(RN1L Sorted matching(2)g)plot(RN1L Sorted matching(3)r)plot(RN1L Sorted matching(4)m)

Appendix A 57

grid ontitle(RN1L)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)

subplot(232)hold onplot(RN2L Sorted matching(1)b)plot(RN2L Sorted matching(2)g)plot(RN2L Sorted matching(3)r)plot(RN2L Sorted matching(4)m)grid ontitle(RN2L)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)

subplot(233)hold onplot(RN3L Sorted matching(1)b)plot(RN3L Sorted matching(2)g)plot(RN3L Sorted matching(3)r)plot(RN3L Sorted matching(4)m)grid ontitle(RN3L)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)

subplot(234)hold onplot(RN1S Sorted matching(1)b)plot(RN1S Sorted matching(2)g)plot(RN1S Sorted matching(3)r)plot(RN1S Sorted matching(4)m)grid ontitle(RN1S)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)

subplot(235)hold onplot(RN2S Sorted matching(1)b)plot(RN2S Sorted matching(2)g)plot(RN2S Sorted matching(3)r)plot(RN2S Sorted matching(4)m)grid ontitle(RN2S)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)

58 Application

subplot(236)hold onplot(RN3S Sorted matching(1)b)plot(RN3S Sorted matching(2)g)plot(RN3S Sorted matching(3)r)plot(RN3S Sorted matching(4)m)grid ontitle(RN3S)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)set(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN4png minusr300)h(5)=figure(NameSorted RatiosNumberTitleoff)RN1L ratio1=RN1L NodesG hatRN1L NodesGRN2L ratio1=RN2L NodesG hatRN2L NodesGRN3L ratio1=RN3L NodesG hatRN3L NodesGRN1S ratio1=RN1S NodesG hatRN1S NodesGRN2S ratio1=RN2S NodesG hatRN2S NodesGRN3S ratio1=RN3S NodesG hatRN3S NodesG

RN1L ratio2=RN1L EdgesG HatRN1L EdgesGRN2L ratio2=RN2L EdgesG HatRN2L EdgesGRN3L ratio2=RN3L EdgesG HatRN3L EdgesGRN1S ratio2=RN1S EdgesG HatRN1S EdgesGRN2S ratio2=RN2S EdgesG HatRN2S EdgesGRN3S ratio2=RN3S EdgesG HatRN3S EdgesG

RN1L ratio3=RN1L MaxDegreeG HatRN1L MaxDegreeGRN2L ratio3=RN2L MaxDegreeG HatRN2L MaxDegreeGRN3L ratio3=RN3L MaxDegreeG HatRN3L MaxDegreeGRN1S ratio3=RN1S MaxDegreeG HatRN1S MaxDegreeGRN2S ratio3=RN2S MaxDegreeG HatRN2S MaxDegreeGRN3S ratio3=RN3S MaxDegreeG HatRN3S MaxDegreeG

RN1L ratio(1)=RN1L ratio1RN1L ratio(2)=RN1L ratio2RN1L ratio(3)=RN1L ratio3

RN2L ratio(1)=RN2L ratio1RN2L ratio(2)=RN2L ratio2RN2L ratio(3)=RN2L ratio3

RN3L ratio(1)=RN3L ratio1RN3L ratio(2)=RN3L ratio2RN3L ratio(3)=RN3L ratio3

RN1S ratio(1)=RN1S ratio1RN1S ratio(2)=RN1S ratio2RN1S ratio(3)=RN1S ratio3

RN2S ratio(1)=RN2S ratio1

Appendix A 59

RN2S ratio(2)=RN2S ratio2RN2S ratio(3)=RN2S ratio3

RN3S ratio(1)=RN3S ratio1RN3S ratio(2)=RN3S ratio2RN3S ratio(3)=RN3S ratio3

RN1L ratio sorted=sortrows(RN1L ratio)RN2L ratio sorted=sortrows(RN2L ratio)RN3L ratio sorted=sortrows(RN3L ratio)RN1S ratio sorted=sortrows(RN1S ratio)RN2S ratio sorted=sortrows(RN2S ratio)RN3S ratio sorted=sortrows(RN3S ratio)

subplot(231)hold onplot(RN1L ratio sorted(1)b)plot(RN1L ratio sorted(2)g)plot(RN1L ratio sorted(3)r)grid ontitle(RN1L)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)

subplot(232)hold onplot(RN2L ratio sorted(1)b)plot(RN2L ratio sorted(2)g)plot(RN2L ratio sorted(3)r)grid ontitle(RN2L)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)

subplot(233)hold onplot(RN3L ratio sorted(1)b)plot(RN3L ratio sorted(2)g)plot(RN3L ratio sorted(3)r)grid ontitle(RN3L)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)

subplot(234)hold onplot(RN1S ratio sorted(1)b)plot(RN1S ratio sorted(2)g)plot(RN1S ratio sorted(3)r)grid on

60 Application

title(RN1S)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)

subplot(235)hold onplot(RN2S ratio sorted(1)b)plot(RN2S ratio sorted(2)g)plot(RN2S ratio sorted(3)r)grid ontitle(RN2S)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)

subplot(236)hold onplot(RN3S ratio sorted(1)b)plot(RN3S ratio sorted(2)g)plot(RN3S ratio sorted(3)r)grid ontitle(RN3S)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)set(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN5png minusr300)

h(6)=figure(NameSorted edges over nodesNumberTitleoff)

RN1L DegreeG1=(RN1L EdgesG)(RN1L NodesG)RN1L DegreeG Hat1=(RN1L EdgesG Hat)(RN1L NodesG hat)

RN1L Degree temp1(1)=RN1L DegreeG1RN1L Degree temp1(2)=RN1L DegreeG Hat1RN1L Degree sorted1=sortrows(RN1L Degree temp1)subplot(231)hold on

plot(RN1L Degree sorted1(1)b)plot(RN1L Degree sorted1(2)g)grid ontitle(RN1L)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)

RN2L DegreeG1=(RN2L EdgesG)(RN2L NodesG)RN2L DegreeG Hat1=(RN2L EdgesG Hat)(RN2L NodesG hat)

RN2L Degree temp1(1)=RN2L DegreeG1

Appendix A 61

RN2L Degree temp1(2)=RN2L DegreeG Hat1RN2L Degree sorted1=sortrows(RN2L Degree temp1)

subplot(232)hold onplot(RN2L Degree sorted1(1)b)plot(RN2L Degree sorted1(2)g)grid ontitle(RN2L)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)

RN3L DegreeG1=(RN3L EdgesG)(RN3L NodesG)RN3L DegreeG Hat1=(RN3L EdgesG Hat)(RN3L NodesG hat)

RN3L Degree temp1(1)=RN3L DegreeG1RN3L Degree temp1(2)=RN3L DegreeG Hat1RN3L Degree sorted1=sortrows(RN3L Degree temp1)

subplot(233)hold onplot(RN3L Degree sorted1(1)b)plot(RN3L Degree sorted1(2)g)grid ontitle(RN3L)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)

RN1S DegreeG1=(RN1S EdgesG)(RN1S NodesG)RN1S DegreeG Hat1=(RN1S EdgesG Hat)(RN1S NodesG hat)

RN1S Degree temp1(1)=RN1S DegreeG1RN1S Degree temp1(2)=RN1S DegreeG Hat1RN1S Degree sorted1=sortrows(RN1S Degree temp1)

subplot(234)hold onplot(RN1S Degree sorted1(1)b)plot(RN1S Degree sorted1(2)g)grid ontitle(RN1S)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)

RN2S DegreeG1=(RN2S EdgesG)(RN2S NodesG)RN2S DegreeG Hat1=(RN2S EdgesG Hat)(RN2S NodesG hat)

RN2S Degree temp1(1)=RN2S DegreeG1

62 Application

RN2S Degree temp1(2)=RN2S DegreeG Hat1RN2S Degree sorted1=sortrows(RN2S Degree temp1)

subplot(235)hold onplot(RN2S Degree sorted1(1)b)plot(RN2S Degree sorted1(2)g)grid ontitle(RN2S)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)

RN3S DegreeG1=(RN3S EdgesG)(RN3S NodesG)RN3S DegreeG Hat1=(RN3S EdgesG Hat)(RN3S NodesG hat)

RN3S Degree temp1(1)=RN3S DegreeG1RN3S Degree temp1(2)=RN3S DegreeG Hat1RN3S Degree sorted1=sortrows(RN3S Degree temp1)

subplot(236)hold onplot(RN3S Degree sorted1(1)b)plot(RN3S Degree sorted1(2)g)grid ontitle(RN3S)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)set(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN6png minusr300)h(7)=figure(NameSorted mATCHED DEGREENumberTitleoff)RN1L ratioMax(1)=RN1L MaxDegreeGRN1L ratioMax(2)=RN1L MaxDegreeG Hat

RN1L ratio sortedMax=sortrows(RN1L ratioMax)subplot(231)hold onplot(RN1L ratio sortedMax(1)b)plot(RN1L ratio sortedMax(2)g)grid ontitle(RN1L)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)

RN2L ratioMax(1)=RN2L MaxDegreeGRN2L ratioMax(2)=RN2L MaxDegreeG Hat

RN2L ratio sortedMax=sortrows(RN2L ratioMax)subplot(232)

Appendix A 63

hold onplot(RN2L ratio sortedMax(1)b)plot(RN2L ratio sortedMax(2)g)grid ontitle(RN2L)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)

RN3L ratioMax(1)=RN3L MaxDegreeGRN3L ratioMax(2)=RN3L MaxDegreeG Hat

RN3L ratio sortedMax=sortrows(RN3L ratioMax)subplot(233)hold onplot(RN3L ratio sortedMax(1)b)plot(RN3L ratio sortedMax(2)g)grid ontitle(RN3L)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)

RN1S ratioMax(1)=RN1S MaxDegreeGRN1S ratioMax(2)=RN1S MaxDegreeG Hat

RN1S ratio sortedMax=sortrows(RN1S ratioMax)subplot(234)hold onplot(RN1S ratio sortedMax(1)b)plot(RN1S ratio sortedMax(2)g)grid ontitle(RN1S)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)

RN2S ratioMax(1)=RN2S MaxDegreeGRN2S ratioMax(2)=RN2S MaxDegreeG Hat

RN2S ratio sortedMax=sortrows(RN2S ratioMax)

subplot(235)hold onplot(RN2S ratio sortedMax(1)b)plot(RN2S ratio sortedMax(2)g)grid ontitle(RN2S)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)

RN3S ratioMax(1)=RN3S MaxDegreeGRN3S ratioMax(2)=RN3S MaxDegreeG Hat

64 Application

RN3S ratio sortedMax=sortrows(RN3S ratioMax)subplot(236)hold onplot(RN3S ratio sortedMax(1)b)plot(RN3S ratio sortedMax(2)g)grid ontitle(RN1L)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)set(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN7png minusr300)

tilefigs()(h)

Bibliography

[1] C Berge ldquoTWO THEOREMS IN GRAPH THEORYrdquo Proceedings of the NationalAcademy of Sciences of the United States of America vol 43 no 9 pp 842ndash844Sep 1957

[2] L Bui S Sanghavi and R Srikant ldquoDistributed link scheduling with constantoverheadrdquo IEEEACM Trans Netw vol 17 no 5 pp 1467ndash1480 2009

[3] R Duan and S Pettie ldquoLinear-time approximation for maximum weight matchingrdquoJ ACM vol 61 no 1 2014

[4] J Edmonds ldquoPaths trees and flowersrdquo Canadian Journal of Mathematics vol 17pp 449ndash467 1965

[5] J E Hopcroft and R M Karp ldquoAn n52 algorithm for maximum matchings inbipartite graphsrdquo SIAM J Comput vol 2 no 4 pp 225ndash231 1973

[6] S Micali and V V Vazirani ldquoAn O(radic|V ||E|) algorithm for finding maximum

matching in general graphsrdquo in 21st Symp on Foundations of Comp Sc (FOCS)IEEE 1980 pp 17ndash27

[7] N Nisse A Salch and V Weber ldquoRecovery of disrupted airline operationsrdquo 2015httphalinriafrSomething

[8] X Wu and R Srikant ldquoRegulated maximal matching A distributed schedulingalgorithm for multi-hop wireless networks with nodeexclusive spectrum sharingrdquo inIEEE Conf on Decision and Control 2005

65

  • Contents
  • Introduction
  • Algorithms
    • Maximum matching
    • k-maximum matching
      • k-matching for Airport Slot assignment
      • The case where k=3
      • The case of Paths
      • The case of the Spider
          • Application
            • Description
            • Reyni Erdos
            • Barabaacutesi Albert
            • Amadeus Graphs
            • Bipartite
            • Bipartite with degree seq
            • Appendix A
              • BipartiteGraphGeneratorpy
              • RandomGraphGeneratorpy
              • kequals3MaximumMatchingpy
              • Plotmat
                  • Bibliography
Page 42: Theodoros Alexandros KARAGKIOULES -  · Introduction This work is the result of a 6 months internship, under the supervision of research O cer Nicolas NISSE. The original scope of

Appendix A 43

print matching listOfedgeprint maedge

MA=nxadjacency matrix(ma)print MA

MA=[Rtodense()tolist()[0] for R in MA]print MA

B=[ join(map(strR)) for R in A]MB=[ join(map(strR)) for R in MA]

C=njoin(B)+nMC=njoin(MB)+n

print nprint mprint m1

filea=str(i)+txtwith open(fileaw) as f

fwrite(str(n3+me3))fwrite(n)fwrite(str(n3+me3))fwrite(n)fwrite(str(m))fwrite(n)fwrite(n)fwrite(C)fwrite(n)fwrite(MC)

print nRandom graphs with random matching have been generated

44 Application

RandomGraphGeneratorpy

from future import divisionimport networkx as nxfrom networkxalgorithms import approximationimport collectionsimport randomimport mathif name == main

for i in range(1481)index=1n=randomrandint(100 1000)

n=1000m=0m1=0p=randomrandom()p1=mathlog(n2)np2=13p3=mathlog(n2)n+01p=05t1=randomrandint(0 1)print im2=randomrandint(n2minus1 n2+1)G = nxGraph()ma = nxGraph()print nme1=randomrandint(1 10)me2=randomrandint(2050)me3=randomrandint(50100)if ilt241

if ilt=80G=nxfast gnp random graph(n p1 seed=None directed=False)

elif igt80 and ilt161G=nxfast gnp random graph(n p2 seed=None directed=False)

elseG=nxfast gnp random graph(n p3 seed=None directed=False)

elseif ilt=320

G=nxbarabasi albert graph(n me1 seed=None)elif igt320 and ilt401

G=nxbarabasi albert graph(n me2 seed=None)else

G=nxbarabasi albert graph(n me3 seed=None)A=nxadjacency matrix(G)for ii in range(0n)

maadd node(ii)A=[Rtodense()tolist()[0] for R in A]

rl=randomsample(range(0n) n)m=0

Appendix A 45

done vertices = set()for p in rl

done verticesadd(p)neighbors = []list()for iii in range(0n)

if A[p][iii]==1neighborsappend(iii)

randomshuffle(neighbors)continue loop = Truedegree = len(neighbors)j = 0p2=randomrandom()while continue loop and (jltdegree)

next = neighbors[j]if next not in done vertices and p not in done vertices

done verticesadd(p)done verticesadd(next)if p2gt=00 Larger probability for smaller initial matching

maadd edge(pnext)m=m+1

continue loop = Falsej += 1

print matching listOfedgeprint maedgeMA=nxadjacency matrix(ma)MA=[Rtodense()tolist()[0] for R in MA]print MAB=[ join(map(strR)) for R in A]MB=[ join(map(strR)) for R in MA]

C=njoin(B)+nMC=njoin(MB)+nprint MCprint nprint mprint m1filea=str(i)+txtwith open(fileaw) as f

fwrite(str(n))fwrite(n)fwrite(str(n))fwrite(n)fwrite(str(m))fwrite(n)fwrite(n)fwrite(C)fwrite(n)fwrite(MC)

print nRandom graphs with random matching have been generated

46 Application

kequals3MaximumMatchingpy

from future import divisionimport networkx as nxfrom networkxalgorithms import bipartiteimport matplotlibpyplot as pltimport collectionsimport timeitimport xlwtimport xlrdimport mathimport sys

Case for General Graphsdef forced edges(Gadj dict2matching dict1num nodesforced)

flagg=0for n in range(0num nodes)

for k in adj dict2[n]if ([k]==matching dict1[n])

count=0for l in range(0num nodes)

count=count+adj dict2[l]count(k)if (len(adj dict2[n])==1) or (count==1)

forcedadd edge(nk)Gremove edge(nk)Gremove node(n)Gremove node(k)printforced edgenktemp=kflagg=1for m in range (len(adj dict2[n])minus1minus1minus1)

adj dict2[adj dict2[n][m]]remove(n)adj dict2[n]remove(adj dict2[n][m])

if adj dict2[temp]for l in range(len(adj dict2[temp])minus1minus1minus1)

if (adj dict2[temp][l]=n)adj dict2[adj dict2[temp][l]]remove(temp)adj dict2[temp]remove(adj dict2[temp][l])

break

def useless edges(num nodesadj dict1matching dict1uselessadj dict2G)for n in range(0num nodes)

for k in adj dict1[n]if ([k]=matching dict1[n]) and matching dict1[n] and matching dict1[k]

uselessadd edge(nk)Gremove edge(n k)

Appendix A 47

tempa=kadj dict2[n]remove(k)adj dict2[tempa]remove(n)adj dict1[tempa]remove(n)

return G

def Greedy(num nodesadj dict3matching dict2)

for n in range(0num nodes)if matching dict2[n]

flag2=minus1flag3=minus1for v in adj dict3[n]

if not matching dict2[v]flag2=vbreak

for p in adj dict3[matching dict2[n][0]]if not matching dict2[p]

flag3=pbreak

if (flag2=minus1) and (flag3=minus1) and (flag2=flag3)tempr=matching dict2[n][0]matching dict2[n]=[flag2]matching dict2[flag2]=[n]matching dict2[tempr]=[flag3]matching dict2[flag3]=[tempr]

elsefor k in adj dict3[n]

if not matching dict2[k]matching dict2[n]=[k]matching dict2[k]=[n]break

yo1=0for i in range(0num nodes)

if matching dict2[i] and [i]==matching dict2[matching dict2[i][0]]yo1=yo1+1

greedy size=yo12return greedy size

def General()

INPUTSwb = xlwtWorkbook()ws = wbadd sheet(Results Random)book=xlrdopen workbook(filenames randomxls)

48 Application

style0 = xlwteasyxf(fontbold on)style1 = xlwteasyxf(num format str=0000)INPUTSwswrite(0 0File style0)wswrite(0 1 Nodesstyle0)wswrite(0 2 Initial matchingstyle0)wswrite(0 3 NodesGstyle0)wswrite(0 4 EdgesGstyle0)wswrite(0 5 MaxDegreeGstyle0)wswrite(0 6 NodesG hatstyle0)wswrite(0 7 EdgesG Hatstyle0)wswrite(0 8 Useless edgesstyle0)wswrite(0 9 Forced edgesstyle0)wswrite(0 10 MaxDegreeG Hatstyle0)wswrite(0 11 Classical matchingstyle0)wswrite(0 12 Final matchingstyle0)wswrite(0 13 Greedy matchingstyle0)wswrite(0 14 Time classicalstyle0)wswrite(0 15 Time algorithmstyle0)wswrite(0 16 Time greedystyle0)wswrite(0 17 Perfect matching ratiostyle0)wswrite(0 18 Nodes ratiostyle0)wswrite(0 19 Edges ratiostyle0)wswrite(0 20 Matching ratiostyle0)

print nWelcomeThis is an implementation for general random graphs It uses Edmonds algorithm to compute maximum matching on G Hatn

for index in range (1481)was 481

if (index==482)f=open(Algotel generaltxtr)readlines()

elsefilea=str(booksheet by index(0)cell(index0))s=fileareplace(textu)replace()f=open(sr)readlines()Truewswrite(index 0 s)

print index

num nodes=int([xstrip()split() for x in f][0][0])

num matching=int([xstrip()split() for x in f][2][0])

adj temp = [xstrip()split() for x in f][44+num nodes]adj=[map(intR) for R in adj temp]

matching temp=[xstrip()split() for x in f][4+num nodes+14+2num nodes+1]matching1=[map(intR) for R in matching temp]

adj dict1=i[ii for iix in enumerate(L) if x] for iL in enumerate(adj)adj dict2=i[ii for iix in enumerate(L) if x] for iL in enumerate(adj)

Appendix A 49

adj dict3=i[ii for iix in enumerate(L) if x] for iL in enumerate(adj)

matching dict1=i[ii for iix in enumerate(L) if x] for iL in enumerate(matching1)matching dict2=i[ii for iix in enumerate(L) if x] for iL in enumerate(matching1)print adj dict2print matching dict2wswrite(index 1 num nodes)wswrite(index 2 num matching)

G = nxGraph()

useless= nxGraph()forced = nxGraph()

Fill Graphfor n in range(0num nodes)

for k in adj dict1[n]Gadd edge(nk)

Gt=Gnumber of edges()wswrite(index 3 Gnumber of nodes())wswrite(index 4 Gnumber of edges())wswrite(index 5 max(Gdegree()values()))

Compute Edmonds classical matching on G for comparison

startB = timeitdefault timer()Classical Matching=nxmax weight matching(G maxcardinality=False)stopB = timeitdefault timer()

Compute Gˆ nad MˆstartC = timeitdefault timer()useless edges(num nodesadj dict1matching dict1uselessadj dict2G)forced edges(Gadj dict2matching dict1num nodesforced)Final Matching=nxmax weight matching(G maxcardinality=False)stopC = timeitdefault timer()

GreedystartG = timeitdefault timer()greedy size=Greedy(num nodesadj dict3matching dict2)stopG = timeitdefault timer()

wswrite(index 6 Gnumber of nodes())wswrite(index 7 Gnumber of edges())wswrite(index 8 uselessnumber of edges())wswrite(index 9 forcednumber of edges())if Gdegree()values()

wswrite(index 10 max(Gdegree()values()))else

50 Application

wswrite(index 10 0)wswrite(index 11 len(Classical Matching)2)wswrite(index 12 len(Final Matching)2+forcednumber of edges())wswrite(index 13 greedy size)wswrite(index 14 stopB minus startBstyle1)wswrite(index 15 stopC minus startCstyle1)wswrite(index 16 stopG minus startGstyle1)wswrite(index 17 (len(Final Matching)2+forcednumber of edges())(num nodes2)style1)wswrite(index 18 Gnumber of nodes()Gtstyle1)wswrite(index 19 Gnumber of edges()Gtstyle1)wswrite(index 20 (len(Final Matching)2+forcednumber of edges())(len(Classical Matching)2)style1)

wbsave(AA Results Random Reyni Large Bipartitexls)

Main function Here we must choose the input form of the dataif name == main

startA = timeitdefault timer()General()stopA = timeitdefault timer()

print nThis program has terminatednnRunning time for 480 files stopAminusstartAprint nnPlease open AA Results Random Reyni Largexls file to see the Results

Appendix A 51

Plotmat

clear allclose allload(RN1Lmat)load(RN1Smat)load(RN2Lmat)load(RN2Smat)load(RN3Lmat)load(RN3Smat)

Plotsh(1)=figure(NameHistogram of Matching size difference between Constraint Algorithm and Greedy AlgorithmNumberTitleoff)

RN1L Greedydiff=RN1L Final matchingminusRN1L Greedy matchingRN2L Greedydiff=RN2L Final matchingminusRN2L Greedy matchingRN3L Greedydiff=RN3L Final matchingminusRN3L Greedy matchingRN1S Greedydiff=RN1S Final matchingminusRN1S Greedy matchingRN2S Greedydiff=RN2S Final matchingminusRN2S Greedy matchingRN3S Greedydiff=RN3S Final matchingminusRN3S Greedy matching

RN1L Finaldiff=RN1L Classical matchingminusRN1L Final matchingRN2L Finaldiff=RN2L Classical matchingminusRN2L Final matchingRN3L Finaldiff=RN3L Classical matchingminusRN3L Final matchingRN1S Finaldiff=RN1S Classical matchingminusRN1S Final matchingRN2S Finaldiff=RN2S Classical matchingminusRN2S Final matchingRN3S Finaldiff=RN3S Classical matchingminusRN3S Final matching

RN1L Classicaldiff=(RN1L Nodes2)minusRN1L Classical matchingRN2L Classicaldiff=(RN2L Nodes2)minusRN2L Classical matchingRN3L Classicaldiff=(RN3L Nodes2)minusRN3L Classical matchingRN1S Classicaldiff=(RN1S Nodes2)minusRN1S Classical matchingRN2S Classicaldiff=(RN2S Nodes2)minusRN2S Classical matchingRN3S Classicaldiff=(RN3S Nodes2)minusRN3S Classical matching

subplot(231)hold onhistf(RN1L Greedydiff0110facecolorbfacealpha9edgealpha1)histf(RN1L Finaldiff0110facecolorrfacealpha5edgealpha1)histf(RN1L Classicaldiff0110facecolorgfacealpha5edgealpha1)legalpha(ConminusGreClasminusConPerfminusClasslocationnortheast)legend boxoffaxis tightxlabel(edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN1L)grid on

subplot(232)hold onhistf(RN2L Greedydiff0110facecolorbfacealpha9edgealpha1)

52 Application

histf(RN2L Finaldiff0110facecolorrfacealpha5edgealpha1)histf(RN2L Classicaldiff0110facecolorgfacealpha5edgealpha1)legalpha(ConminusGreClasminusConPerfminusClasslocationnortheast)legend boxoffaxis tightxlabel(edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN2L)grid on

subplot(233)hold onhistf(RN3L Greedydiff0110facecolorbfacealpha5edgealpha1)histf(RN3L Finaldiff0110facecolorrfacealpha5edgealpha1)histf(RN3L Classicaldiff0110facecolorgfacealpha5edgealpha1)legalpha(ConminusGreClasminusConPerfminusClasslocationnortheast)legend boxoffaxis tightxlabel(edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN3L)grid on

subplot(234)hold onhistf(RN1S Greedydiff0110facecolorbfacealpha5edgealpha1)histf(RN1S Finaldiff0110facecolorrfacealpha5edgealpha1)histf(RN1S Classicaldiff0110facecolorgfacealpha5edgealpha1)legalpha(ConminusGreClasminusConPerfminusClasslocationnortheast)legend boxoffaxis tightxlabel(edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(R1NS)grid on

subplot(235)hold onhistf(RN2S Greedydiff0110facecolorbfacealpha5edgealpha1)histf(RN2S Finaldiff0110facecolorrfacealpha5edgealpha1)histf(RN2S Classicaldiff0110facecolorgfacealpha5edgealpha1)legalpha(ConminusGreClasminusConPerfminusClasslocationnortheast)legend boxoffaxis tightxlabel(edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN2S)grid on

subplot(236)hold onhistf(RN3S Greedydiff0110facecolorbfacealpha5edgealpha1)histf(RN3S Finaldiff0110facecolorrfacealpha5edgealpha1)histf(RN3S Classicaldiff0110facecolorgfacealpha5edgealpha1)

Appendix A 53

legalpha(ConminusGreClasminusConPerfminusClasslocationnortheast)legend boxoffaxis tightgrid ontitle(RN3S)xlabel(edges) xminusaxis labelylabel(instances) yminusaxis labelset(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN1png minusr300)h(2)=figure(NameHistogram of Max Degree of G AND G HatNumberTitleoff)RN1L x=RN1L MaxDegreeGminusRN1L MaxDegreeG HatRN2L x=RN2L MaxDegreeGminusRN2L MaxDegreeG HatRN3L x=RN3L MaxDegreeGminusRN3L MaxDegreeG HatRN1S x=RN1S MaxDegreeGminusRN1S MaxDegreeG HatRN2S x=RN2S MaxDegreeGminusRN2S MaxDegreeG HatRN3S x=RN3S MaxDegreeGminusRN3S MaxDegreeG Hatsubplot(231)hold onhistf(RN1L MaxDegreeG0150facecolorbfacealpha5edgealpha1)histf(RN1L MaxDegreeG Hat0150facecolorrfacealpha5edgealpha1)histf(RN1L x0150facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightxlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN1L)grid on

subplot(232)hold onhistf(RN2L MaxDegreeG010500facecolorbfacealpha5edgealpha1)histf(RN2L MaxDegreeG Hat010500facecolorrfacealpha5edgealpha1)histf(RN2L x010500facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightxlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN2L)grid on

subplot(233)hold onhistf(RN3L MaxDegreeG010300facecolorbfacealpha5edgealpha1)histf(RN3L MaxDegreeG Hat010300facecolorrfacealpha5edgealpha1)histf(RN3L x010300facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightxlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN3L)

54 Application

grid on

subplot(234)hold onhistf(RN1S MaxDegreeG0150facecolorbfacealpha5edgealpha1)histf(RN1S MaxDegreeG Hat0150facecolorrfacealpha5edgealpha1)histf(RN1S x0150facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightxlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(R1NS)grid on

subplot(235)hold onhistf(RN2S MaxDegreeG010500facecolorbfacealpha5edgealpha1)histf(RN2S MaxDegreeG Hat010500facecolorrfacealpha5edgealpha1)histf(RN2S x010500facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightxlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN2S)grid on

subplot(236)hold onhistf(RN3S MaxDegreeG05300facecolorbfacealpha5edgealpha1)histf(RN3S MaxDegreeG Hat05300facecolorrfacealpha5edgealpha1)histf(RN3S x05300facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightgrid ontitle(RN3S)xlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labelset(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN2png minusr300)

h(3)=figure(NameComputation time over edgesNumberTitleoff)

subplot(231)hold onstem(RN1L EdgesGRN1L Time classicalg)stem(RN1L EdgesGRN1L Time algorithmro)stem(RN1L EdgesGRN1L Time greedybx)grid on

Appendix A 55

title(RN1L)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)

subplot(232)hold onstem(RN2L EdgesGRN2L Time classicalg)stem(RN2L EdgesGRN2L Time algorithmro)stem(RN2L EdgesGRN2L Time greedybx)grid ontitle(RN2L)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)

subplot(233)hold onstem(RN3L EdgesGRN3L Time classicalg)stem(RN3L EdgesGRN3L Time algorithmro)stem(RN3L EdgesGRN3L Time greedybx)grid ontitle(RN3L)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)

subplot(234)hold onstem(RN1S EdgesGRN1S Time classicalg)stem(RN1S EdgesGRN1S Time algorithmro)stem(RN1S EdgesGRN1S Time greedybx)grid ontitle(RN1S)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)

subplot(235)hold onstem(RN2S EdgesGRN2S Time classicalg)stem(RN2S EdgesGRN2S Time algorithmro)stem(RN2S EdgesGRN2S Time greedybx)grid ontitle(RN2S)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)

subplot(236)hold onstem(RN3S EdgesGRN3S Time classicalg)stem(RN3S EdgesGRN3S Time algorithmro)stem(RN3S EdgesGRN3S Time greedybx)

56 Application

grid ontitle(RN3S)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)set(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN3png minusr300)

h(4)=figure(NameSorted matching sizeNumberTitleoff)RN1L Sorted matching temp(1)=RN1L Classical matchingRN1L Sorted matching temp(2)=RN1L Final matchingRN1L Sorted matching temp(3)=RN1L Greedy matchingRN1L Sorted matching temp(4)=RN1L Initial matchingRN1L Sorted matching=sortrows(RN1L Sorted matching temp)

RN2L Sorted matching temp(1)=RN2L Classical matchingRN2L Sorted matching temp(2)=RN2L Final matchingRN2L Sorted matching temp(3)=RN2L Greedy matchingRN2L Sorted matching temp(4)=RN2L Initial matchingRN2L Sorted matching=sortrows(RN2L Sorted matching temp)

RN3L Sorted matching temp(1)=RN3L Classical matchingRN3L Sorted matching temp(2)=RN3L Final matchingRN3L Sorted matching temp(3)=RN3L Greedy matchingRN3L Sorted matching temp(4)=RN3L Initial matchingRN3L Sorted matching=sortrows(RN3L Sorted matching temp)

RN1S Sorted matching temp(1)=RN1S Classical matchingRN1S Sorted matching temp(2)=RN1S Final matchingRN1S Sorted matching temp(3)=RN1S Greedy matchingRN1S Sorted matching temp(4)=RN1S Initial matchingRN1S Sorted matching=sortrows(RN1S Sorted matching temp)

RN2S Sorted matching temp(1)=RN2S Classical matchingRN2S Sorted matching temp(2)=RN2S Final matchingRN2S Sorted matching temp(3)=RN2S Greedy matchingRN2S Sorted matching temp(4)=RN2S Initial matchingRN2S Sorted matching=sortrows(RN2S Sorted matching temp)

RN3S Sorted matching temp(1)=RN3S Classical matchingRN3S Sorted matching temp(2)=RN3S Final matchingRN3S Sorted matching temp(3)=RN3S Greedy matchingRN3S Sorted matching temp(4)=RN3S Initial matchingRN3S Sorted matching=sortrows(RN3S Sorted matching temp)

subplot(231)hold onplot(RN1L Sorted matching(1)b)plot(RN1L Sorted matching(2)g)plot(RN1L Sorted matching(3)r)plot(RN1L Sorted matching(4)m)

Appendix A 57

grid ontitle(RN1L)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)

subplot(232)hold onplot(RN2L Sorted matching(1)b)plot(RN2L Sorted matching(2)g)plot(RN2L Sorted matching(3)r)plot(RN2L Sorted matching(4)m)grid ontitle(RN2L)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)

subplot(233)hold onplot(RN3L Sorted matching(1)b)plot(RN3L Sorted matching(2)g)plot(RN3L Sorted matching(3)r)plot(RN3L Sorted matching(4)m)grid ontitle(RN3L)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)

subplot(234)hold onplot(RN1S Sorted matching(1)b)plot(RN1S Sorted matching(2)g)plot(RN1S Sorted matching(3)r)plot(RN1S Sorted matching(4)m)grid ontitle(RN1S)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)

subplot(235)hold onplot(RN2S Sorted matching(1)b)plot(RN2S Sorted matching(2)g)plot(RN2S Sorted matching(3)r)plot(RN2S Sorted matching(4)m)grid ontitle(RN2S)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)

58 Application

subplot(236)hold onplot(RN3S Sorted matching(1)b)plot(RN3S Sorted matching(2)g)plot(RN3S Sorted matching(3)r)plot(RN3S Sorted matching(4)m)grid ontitle(RN3S)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)set(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN4png minusr300)h(5)=figure(NameSorted RatiosNumberTitleoff)RN1L ratio1=RN1L NodesG hatRN1L NodesGRN2L ratio1=RN2L NodesG hatRN2L NodesGRN3L ratio1=RN3L NodesG hatRN3L NodesGRN1S ratio1=RN1S NodesG hatRN1S NodesGRN2S ratio1=RN2S NodesG hatRN2S NodesGRN3S ratio1=RN3S NodesG hatRN3S NodesG

RN1L ratio2=RN1L EdgesG HatRN1L EdgesGRN2L ratio2=RN2L EdgesG HatRN2L EdgesGRN3L ratio2=RN3L EdgesG HatRN3L EdgesGRN1S ratio2=RN1S EdgesG HatRN1S EdgesGRN2S ratio2=RN2S EdgesG HatRN2S EdgesGRN3S ratio2=RN3S EdgesG HatRN3S EdgesG

RN1L ratio3=RN1L MaxDegreeG HatRN1L MaxDegreeGRN2L ratio3=RN2L MaxDegreeG HatRN2L MaxDegreeGRN3L ratio3=RN3L MaxDegreeG HatRN3L MaxDegreeGRN1S ratio3=RN1S MaxDegreeG HatRN1S MaxDegreeGRN2S ratio3=RN2S MaxDegreeG HatRN2S MaxDegreeGRN3S ratio3=RN3S MaxDegreeG HatRN3S MaxDegreeG

RN1L ratio(1)=RN1L ratio1RN1L ratio(2)=RN1L ratio2RN1L ratio(3)=RN1L ratio3

RN2L ratio(1)=RN2L ratio1RN2L ratio(2)=RN2L ratio2RN2L ratio(3)=RN2L ratio3

RN3L ratio(1)=RN3L ratio1RN3L ratio(2)=RN3L ratio2RN3L ratio(3)=RN3L ratio3

RN1S ratio(1)=RN1S ratio1RN1S ratio(2)=RN1S ratio2RN1S ratio(3)=RN1S ratio3

RN2S ratio(1)=RN2S ratio1

Appendix A 59

RN2S ratio(2)=RN2S ratio2RN2S ratio(3)=RN2S ratio3

RN3S ratio(1)=RN3S ratio1RN3S ratio(2)=RN3S ratio2RN3S ratio(3)=RN3S ratio3

RN1L ratio sorted=sortrows(RN1L ratio)RN2L ratio sorted=sortrows(RN2L ratio)RN3L ratio sorted=sortrows(RN3L ratio)RN1S ratio sorted=sortrows(RN1S ratio)RN2S ratio sorted=sortrows(RN2S ratio)RN3S ratio sorted=sortrows(RN3S ratio)

subplot(231)hold onplot(RN1L ratio sorted(1)b)plot(RN1L ratio sorted(2)g)plot(RN1L ratio sorted(3)r)grid ontitle(RN1L)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)

subplot(232)hold onplot(RN2L ratio sorted(1)b)plot(RN2L ratio sorted(2)g)plot(RN2L ratio sorted(3)r)grid ontitle(RN2L)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)

subplot(233)hold onplot(RN3L ratio sorted(1)b)plot(RN3L ratio sorted(2)g)plot(RN3L ratio sorted(3)r)grid ontitle(RN3L)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)

subplot(234)hold onplot(RN1S ratio sorted(1)b)plot(RN1S ratio sorted(2)g)plot(RN1S ratio sorted(3)r)grid on

60 Application

title(RN1S)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)

subplot(235)hold onplot(RN2S ratio sorted(1)b)plot(RN2S ratio sorted(2)g)plot(RN2S ratio sorted(3)r)grid ontitle(RN2S)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)

subplot(236)hold onplot(RN3S ratio sorted(1)b)plot(RN3S ratio sorted(2)g)plot(RN3S ratio sorted(3)r)grid ontitle(RN3S)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)set(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN5png minusr300)

h(6)=figure(NameSorted edges over nodesNumberTitleoff)

RN1L DegreeG1=(RN1L EdgesG)(RN1L NodesG)RN1L DegreeG Hat1=(RN1L EdgesG Hat)(RN1L NodesG hat)

RN1L Degree temp1(1)=RN1L DegreeG1RN1L Degree temp1(2)=RN1L DegreeG Hat1RN1L Degree sorted1=sortrows(RN1L Degree temp1)subplot(231)hold on

plot(RN1L Degree sorted1(1)b)plot(RN1L Degree sorted1(2)g)grid ontitle(RN1L)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)

RN2L DegreeG1=(RN2L EdgesG)(RN2L NodesG)RN2L DegreeG Hat1=(RN2L EdgesG Hat)(RN2L NodesG hat)

RN2L Degree temp1(1)=RN2L DegreeG1

Appendix A 61

RN2L Degree temp1(2)=RN2L DegreeG Hat1RN2L Degree sorted1=sortrows(RN2L Degree temp1)

subplot(232)hold onplot(RN2L Degree sorted1(1)b)plot(RN2L Degree sorted1(2)g)grid ontitle(RN2L)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)

RN3L DegreeG1=(RN3L EdgesG)(RN3L NodesG)RN3L DegreeG Hat1=(RN3L EdgesG Hat)(RN3L NodesG hat)

RN3L Degree temp1(1)=RN3L DegreeG1RN3L Degree temp1(2)=RN3L DegreeG Hat1RN3L Degree sorted1=sortrows(RN3L Degree temp1)

subplot(233)hold onplot(RN3L Degree sorted1(1)b)plot(RN3L Degree sorted1(2)g)grid ontitle(RN3L)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)

RN1S DegreeG1=(RN1S EdgesG)(RN1S NodesG)RN1S DegreeG Hat1=(RN1S EdgesG Hat)(RN1S NodesG hat)

RN1S Degree temp1(1)=RN1S DegreeG1RN1S Degree temp1(2)=RN1S DegreeG Hat1RN1S Degree sorted1=sortrows(RN1S Degree temp1)

subplot(234)hold onplot(RN1S Degree sorted1(1)b)plot(RN1S Degree sorted1(2)g)grid ontitle(RN1S)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)

RN2S DegreeG1=(RN2S EdgesG)(RN2S NodesG)RN2S DegreeG Hat1=(RN2S EdgesG Hat)(RN2S NodesG hat)

RN2S Degree temp1(1)=RN2S DegreeG1

62 Application

RN2S Degree temp1(2)=RN2S DegreeG Hat1RN2S Degree sorted1=sortrows(RN2S Degree temp1)

subplot(235)hold onplot(RN2S Degree sorted1(1)b)plot(RN2S Degree sorted1(2)g)grid ontitle(RN2S)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)

RN3S DegreeG1=(RN3S EdgesG)(RN3S NodesG)RN3S DegreeG Hat1=(RN3S EdgesG Hat)(RN3S NodesG hat)

RN3S Degree temp1(1)=RN3S DegreeG1RN3S Degree temp1(2)=RN3S DegreeG Hat1RN3S Degree sorted1=sortrows(RN3S Degree temp1)

subplot(236)hold onplot(RN3S Degree sorted1(1)b)plot(RN3S Degree sorted1(2)g)grid ontitle(RN3S)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)set(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN6png minusr300)h(7)=figure(NameSorted mATCHED DEGREENumberTitleoff)RN1L ratioMax(1)=RN1L MaxDegreeGRN1L ratioMax(2)=RN1L MaxDegreeG Hat

RN1L ratio sortedMax=sortrows(RN1L ratioMax)subplot(231)hold onplot(RN1L ratio sortedMax(1)b)plot(RN1L ratio sortedMax(2)g)grid ontitle(RN1L)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)

RN2L ratioMax(1)=RN2L MaxDegreeGRN2L ratioMax(2)=RN2L MaxDegreeG Hat

RN2L ratio sortedMax=sortrows(RN2L ratioMax)subplot(232)

Appendix A 63

hold onplot(RN2L ratio sortedMax(1)b)plot(RN2L ratio sortedMax(2)g)grid ontitle(RN2L)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)

RN3L ratioMax(1)=RN3L MaxDegreeGRN3L ratioMax(2)=RN3L MaxDegreeG Hat

RN3L ratio sortedMax=sortrows(RN3L ratioMax)subplot(233)hold onplot(RN3L ratio sortedMax(1)b)plot(RN3L ratio sortedMax(2)g)grid ontitle(RN3L)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)

RN1S ratioMax(1)=RN1S MaxDegreeGRN1S ratioMax(2)=RN1S MaxDegreeG Hat

RN1S ratio sortedMax=sortrows(RN1S ratioMax)subplot(234)hold onplot(RN1S ratio sortedMax(1)b)plot(RN1S ratio sortedMax(2)g)grid ontitle(RN1S)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)

RN2S ratioMax(1)=RN2S MaxDegreeGRN2S ratioMax(2)=RN2S MaxDegreeG Hat

RN2S ratio sortedMax=sortrows(RN2S ratioMax)

subplot(235)hold onplot(RN2S ratio sortedMax(1)b)plot(RN2S ratio sortedMax(2)g)grid ontitle(RN2S)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)

RN3S ratioMax(1)=RN3S MaxDegreeGRN3S ratioMax(2)=RN3S MaxDegreeG Hat

64 Application

RN3S ratio sortedMax=sortrows(RN3S ratioMax)subplot(236)hold onplot(RN3S ratio sortedMax(1)b)plot(RN3S ratio sortedMax(2)g)grid ontitle(RN1L)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)set(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN7png minusr300)

tilefigs()(h)

Bibliography

[1] C Berge ldquoTWO THEOREMS IN GRAPH THEORYrdquo Proceedings of the NationalAcademy of Sciences of the United States of America vol 43 no 9 pp 842ndash844Sep 1957

[2] L Bui S Sanghavi and R Srikant ldquoDistributed link scheduling with constantoverheadrdquo IEEEACM Trans Netw vol 17 no 5 pp 1467ndash1480 2009

[3] R Duan and S Pettie ldquoLinear-time approximation for maximum weight matchingrdquoJ ACM vol 61 no 1 2014

[4] J Edmonds ldquoPaths trees and flowersrdquo Canadian Journal of Mathematics vol 17pp 449ndash467 1965

[5] J E Hopcroft and R M Karp ldquoAn n52 algorithm for maximum matchings inbipartite graphsrdquo SIAM J Comput vol 2 no 4 pp 225ndash231 1973

[6] S Micali and V V Vazirani ldquoAn O(radic|V ||E|) algorithm for finding maximum

matching in general graphsrdquo in 21st Symp on Foundations of Comp Sc (FOCS)IEEE 1980 pp 17ndash27

[7] N Nisse A Salch and V Weber ldquoRecovery of disrupted airline operationsrdquo 2015httphalinriafrSomething

[8] X Wu and R Srikant ldquoRegulated maximal matching A distributed schedulingalgorithm for multi-hop wireless networks with nodeexclusive spectrum sharingrdquo inIEEE Conf on Decision and Control 2005

65

  • Contents
  • Introduction
  • Algorithms
    • Maximum matching
    • k-maximum matching
      • k-matching for Airport Slot assignment
      • The case where k=3
      • The case of Paths
      • The case of the Spider
          • Application
            • Description
            • Reyni Erdos
            • Barabaacutesi Albert
            • Amadeus Graphs
            • Bipartite
            • Bipartite with degree seq
            • Appendix A
              • BipartiteGraphGeneratorpy
              • RandomGraphGeneratorpy
              • kequals3MaximumMatchingpy
              • Plotmat
                  • Bibliography
Page 43: Theodoros Alexandros KARAGKIOULES -  · Introduction This work is the result of a 6 months internship, under the supervision of research O cer Nicolas NISSE. The original scope of

44 Application

RandomGraphGeneratorpy

from future import divisionimport networkx as nxfrom networkxalgorithms import approximationimport collectionsimport randomimport mathif name == main

for i in range(1481)index=1n=randomrandint(100 1000)

n=1000m=0m1=0p=randomrandom()p1=mathlog(n2)np2=13p3=mathlog(n2)n+01p=05t1=randomrandint(0 1)print im2=randomrandint(n2minus1 n2+1)G = nxGraph()ma = nxGraph()print nme1=randomrandint(1 10)me2=randomrandint(2050)me3=randomrandint(50100)if ilt241

if ilt=80G=nxfast gnp random graph(n p1 seed=None directed=False)

elif igt80 and ilt161G=nxfast gnp random graph(n p2 seed=None directed=False)

elseG=nxfast gnp random graph(n p3 seed=None directed=False)

elseif ilt=320

G=nxbarabasi albert graph(n me1 seed=None)elif igt320 and ilt401

G=nxbarabasi albert graph(n me2 seed=None)else

G=nxbarabasi albert graph(n me3 seed=None)A=nxadjacency matrix(G)for ii in range(0n)

maadd node(ii)A=[Rtodense()tolist()[0] for R in A]

rl=randomsample(range(0n) n)m=0

Appendix A 45

done vertices = set()for p in rl

done verticesadd(p)neighbors = []list()for iii in range(0n)

if A[p][iii]==1neighborsappend(iii)

randomshuffle(neighbors)continue loop = Truedegree = len(neighbors)j = 0p2=randomrandom()while continue loop and (jltdegree)

next = neighbors[j]if next not in done vertices and p not in done vertices

done verticesadd(p)done verticesadd(next)if p2gt=00 Larger probability for smaller initial matching

maadd edge(pnext)m=m+1

continue loop = Falsej += 1

print matching listOfedgeprint maedgeMA=nxadjacency matrix(ma)MA=[Rtodense()tolist()[0] for R in MA]print MAB=[ join(map(strR)) for R in A]MB=[ join(map(strR)) for R in MA]

C=njoin(B)+nMC=njoin(MB)+nprint MCprint nprint mprint m1filea=str(i)+txtwith open(fileaw) as f

fwrite(str(n))fwrite(n)fwrite(str(n))fwrite(n)fwrite(str(m))fwrite(n)fwrite(n)fwrite(C)fwrite(n)fwrite(MC)

print nRandom graphs with random matching have been generated

46 Application

kequals3MaximumMatchingpy

from future import divisionimport networkx as nxfrom networkxalgorithms import bipartiteimport matplotlibpyplot as pltimport collectionsimport timeitimport xlwtimport xlrdimport mathimport sys

Case for General Graphsdef forced edges(Gadj dict2matching dict1num nodesforced)

flagg=0for n in range(0num nodes)

for k in adj dict2[n]if ([k]==matching dict1[n])

count=0for l in range(0num nodes)

count=count+adj dict2[l]count(k)if (len(adj dict2[n])==1) or (count==1)

forcedadd edge(nk)Gremove edge(nk)Gremove node(n)Gremove node(k)printforced edgenktemp=kflagg=1for m in range (len(adj dict2[n])minus1minus1minus1)

adj dict2[adj dict2[n][m]]remove(n)adj dict2[n]remove(adj dict2[n][m])

if adj dict2[temp]for l in range(len(adj dict2[temp])minus1minus1minus1)

if (adj dict2[temp][l]=n)adj dict2[adj dict2[temp][l]]remove(temp)adj dict2[temp]remove(adj dict2[temp][l])

break

def useless edges(num nodesadj dict1matching dict1uselessadj dict2G)for n in range(0num nodes)

for k in adj dict1[n]if ([k]=matching dict1[n]) and matching dict1[n] and matching dict1[k]

uselessadd edge(nk)Gremove edge(n k)

Appendix A 47

tempa=kadj dict2[n]remove(k)adj dict2[tempa]remove(n)adj dict1[tempa]remove(n)

return G

def Greedy(num nodesadj dict3matching dict2)

for n in range(0num nodes)if matching dict2[n]

flag2=minus1flag3=minus1for v in adj dict3[n]

if not matching dict2[v]flag2=vbreak

for p in adj dict3[matching dict2[n][0]]if not matching dict2[p]

flag3=pbreak

if (flag2=minus1) and (flag3=minus1) and (flag2=flag3)tempr=matching dict2[n][0]matching dict2[n]=[flag2]matching dict2[flag2]=[n]matching dict2[tempr]=[flag3]matching dict2[flag3]=[tempr]

elsefor k in adj dict3[n]

if not matching dict2[k]matching dict2[n]=[k]matching dict2[k]=[n]break

yo1=0for i in range(0num nodes)

if matching dict2[i] and [i]==matching dict2[matching dict2[i][0]]yo1=yo1+1

greedy size=yo12return greedy size

def General()

INPUTSwb = xlwtWorkbook()ws = wbadd sheet(Results Random)book=xlrdopen workbook(filenames randomxls)

48 Application

style0 = xlwteasyxf(fontbold on)style1 = xlwteasyxf(num format str=0000)INPUTSwswrite(0 0File style0)wswrite(0 1 Nodesstyle0)wswrite(0 2 Initial matchingstyle0)wswrite(0 3 NodesGstyle0)wswrite(0 4 EdgesGstyle0)wswrite(0 5 MaxDegreeGstyle0)wswrite(0 6 NodesG hatstyle0)wswrite(0 7 EdgesG Hatstyle0)wswrite(0 8 Useless edgesstyle0)wswrite(0 9 Forced edgesstyle0)wswrite(0 10 MaxDegreeG Hatstyle0)wswrite(0 11 Classical matchingstyle0)wswrite(0 12 Final matchingstyle0)wswrite(0 13 Greedy matchingstyle0)wswrite(0 14 Time classicalstyle0)wswrite(0 15 Time algorithmstyle0)wswrite(0 16 Time greedystyle0)wswrite(0 17 Perfect matching ratiostyle0)wswrite(0 18 Nodes ratiostyle0)wswrite(0 19 Edges ratiostyle0)wswrite(0 20 Matching ratiostyle0)

print nWelcomeThis is an implementation for general random graphs It uses Edmonds algorithm to compute maximum matching on G Hatn

for index in range (1481)was 481

if (index==482)f=open(Algotel generaltxtr)readlines()

elsefilea=str(booksheet by index(0)cell(index0))s=fileareplace(textu)replace()f=open(sr)readlines()Truewswrite(index 0 s)

print index

num nodes=int([xstrip()split() for x in f][0][0])

num matching=int([xstrip()split() for x in f][2][0])

adj temp = [xstrip()split() for x in f][44+num nodes]adj=[map(intR) for R in adj temp]

matching temp=[xstrip()split() for x in f][4+num nodes+14+2num nodes+1]matching1=[map(intR) for R in matching temp]

adj dict1=i[ii for iix in enumerate(L) if x] for iL in enumerate(adj)adj dict2=i[ii for iix in enumerate(L) if x] for iL in enumerate(adj)

Appendix A 49

adj dict3=i[ii for iix in enumerate(L) if x] for iL in enumerate(adj)

matching dict1=i[ii for iix in enumerate(L) if x] for iL in enumerate(matching1)matching dict2=i[ii for iix in enumerate(L) if x] for iL in enumerate(matching1)print adj dict2print matching dict2wswrite(index 1 num nodes)wswrite(index 2 num matching)

G = nxGraph()

useless= nxGraph()forced = nxGraph()

Fill Graphfor n in range(0num nodes)

for k in adj dict1[n]Gadd edge(nk)

Gt=Gnumber of edges()wswrite(index 3 Gnumber of nodes())wswrite(index 4 Gnumber of edges())wswrite(index 5 max(Gdegree()values()))

Compute Edmonds classical matching on G for comparison

startB = timeitdefault timer()Classical Matching=nxmax weight matching(G maxcardinality=False)stopB = timeitdefault timer()

Compute Gˆ nad MˆstartC = timeitdefault timer()useless edges(num nodesadj dict1matching dict1uselessadj dict2G)forced edges(Gadj dict2matching dict1num nodesforced)Final Matching=nxmax weight matching(G maxcardinality=False)stopC = timeitdefault timer()

GreedystartG = timeitdefault timer()greedy size=Greedy(num nodesadj dict3matching dict2)stopG = timeitdefault timer()

wswrite(index 6 Gnumber of nodes())wswrite(index 7 Gnumber of edges())wswrite(index 8 uselessnumber of edges())wswrite(index 9 forcednumber of edges())if Gdegree()values()

wswrite(index 10 max(Gdegree()values()))else

50 Application

wswrite(index 10 0)wswrite(index 11 len(Classical Matching)2)wswrite(index 12 len(Final Matching)2+forcednumber of edges())wswrite(index 13 greedy size)wswrite(index 14 stopB minus startBstyle1)wswrite(index 15 stopC minus startCstyle1)wswrite(index 16 stopG minus startGstyle1)wswrite(index 17 (len(Final Matching)2+forcednumber of edges())(num nodes2)style1)wswrite(index 18 Gnumber of nodes()Gtstyle1)wswrite(index 19 Gnumber of edges()Gtstyle1)wswrite(index 20 (len(Final Matching)2+forcednumber of edges())(len(Classical Matching)2)style1)

wbsave(AA Results Random Reyni Large Bipartitexls)

Main function Here we must choose the input form of the dataif name == main

startA = timeitdefault timer()General()stopA = timeitdefault timer()

print nThis program has terminatednnRunning time for 480 files stopAminusstartAprint nnPlease open AA Results Random Reyni Largexls file to see the Results

Appendix A 51

Plotmat

clear allclose allload(RN1Lmat)load(RN1Smat)load(RN2Lmat)load(RN2Smat)load(RN3Lmat)load(RN3Smat)

Plotsh(1)=figure(NameHistogram of Matching size difference between Constraint Algorithm and Greedy AlgorithmNumberTitleoff)

RN1L Greedydiff=RN1L Final matchingminusRN1L Greedy matchingRN2L Greedydiff=RN2L Final matchingminusRN2L Greedy matchingRN3L Greedydiff=RN3L Final matchingminusRN3L Greedy matchingRN1S Greedydiff=RN1S Final matchingminusRN1S Greedy matchingRN2S Greedydiff=RN2S Final matchingminusRN2S Greedy matchingRN3S Greedydiff=RN3S Final matchingminusRN3S Greedy matching

RN1L Finaldiff=RN1L Classical matchingminusRN1L Final matchingRN2L Finaldiff=RN2L Classical matchingminusRN2L Final matchingRN3L Finaldiff=RN3L Classical matchingminusRN3L Final matchingRN1S Finaldiff=RN1S Classical matchingminusRN1S Final matchingRN2S Finaldiff=RN2S Classical matchingminusRN2S Final matchingRN3S Finaldiff=RN3S Classical matchingminusRN3S Final matching

RN1L Classicaldiff=(RN1L Nodes2)minusRN1L Classical matchingRN2L Classicaldiff=(RN2L Nodes2)minusRN2L Classical matchingRN3L Classicaldiff=(RN3L Nodes2)minusRN3L Classical matchingRN1S Classicaldiff=(RN1S Nodes2)minusRN1S Classical matchingRN2S Classicaldiff=(RN2S Nodes2)minusRN2S Classical matchingRN3S Classicaldiff=(RN3S Nodes2)minusRN3S Classical matching

subplot(231)hold onhistf(RN1L Greedydiff0110facecolorbfacealpha9edgealpha1)histf(RN1L Finaldiff0110facecolorrfacealpha5edgealpha1)histf(RN1L Classicaldiff0110facecolorgfacealpha5edgealpha1)legalpha(ConminusGreClasminusConPerfminusClasslocationnortheast)legend boxoffaxis tightxlabel(edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN1L)grid on

subplot(232)hold onhistf(RN2L Greedydiff0110facecolorbfacealpha9edgealpha1)

52 Application

histf(RN2L Finaldiff0110facecolorrfacealpha5edgealpha1)histf(RN2L Classicaldiff0110facecolorgfacealpha5edgealpha1)legalpha(ConminusGreClasminusConPerfminusClasslocationnortheast)legend boxoffaxis tightxlabel(edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN2L)grid on

subplot(233)hold onhistf(RN3L Greedydiff0110facecolorbfacealpha5edgealpha1)histf(RN3L Finaldiff0110facecolorrfacealpha5edgealpha1)histf(RN3L Classicaldiff0110facecolorgfacealpha5edgealpha1)legalpha(ConminusGreClasminusConPerfminusClasslocationnortheast)legend boxoffaxis tightxlabel(edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN3L)grid on

subplot(234)hold onhistf(RN1S Greedydiff0110facecolorbfacealpha5edgealpha1)histf(RN1S Finaldiff0110facecolorrfacealpha5edgealpha1)histf(RN1S Classicaldiff0110facecolorgfacealpha5edgealpha1)legalpha(ConminusGreClasminusConPerfminusClasslocationnortheast)legend boxoffaxis tightxlabel(edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(R1NS)grid on

subplot(235)hold onhistf(RN2S Greedydiff0110facecolorbfacealpha5edgealpha1)histf(RN2S Finaldiff0110facecolorrfacealpha5edgealpha1)histf(RN2S Classicaldiff0110facecolorgfacealpha5edgealpha1)legalpha(ConminusGreClasminusConPerfminusClasslocationnortheast)legend boxoffaxis tightxlabel(edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN2S)grid on

subplot(236)hold onhistf(RN3S Greedydiff0110facecolorbfacealpha5edgealpha1)histf(RN3S Finaldiff0110facecolorrfacealpha5edgealpha1)histf(RN3S Classicaldiff0110facecolorgfacealpha5edgealpha1)

Appendix A 53

legalpha(ConminusGreClasminusConPerfminusClasslocationnortheast)legend boxoffaxis tightgrid ontitle(RN3S)xlabel(edges) xminusaxis labelylabel(instances) yminusaxis labelset(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN1png minusr300)h(2)=figure(NameHistogram of Max Degree of G AND G HatNumberTitleoff)RN1L x=RN1L MaxDegreeGminusRN1L MaxDegreeG HatRN2L x=RN2L MaxDegreeGminusRN2L MaxDegreeG HatRN3L x=RN3L MaxDegreeGminusRN3L MaxDegreeG HatRN1S x=RN1S MaxDegreeGminusRN1S MaxDegreeG HatRN2S x=RN2S MaxDegreeGminusRN2S MaxDegreeG HatRN3S x=RN3S MaxDegreeGminusRN3S MaxDegreeG Hatsubplot(231)hold onhistf(RN1L MaxDegreeG0150facecolorbfacealpha5edgealpha1)histf(RN1L MaxDegreeG Hat0150facecolorrfacealpha5edgealpha1)histf(RN1L x0150facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightxlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN1L)grid on

subplot(232)hold onhistf(RN2L MaxDegreeG010500facecolorbfacealpha5edgealpha1)histf(RN2L MaxDegreeG Hat010500facecolorrfacealpha5edgealpha1)histf(RN2L x010500facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightxlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN2L)grid on

subplot(233)hold onhistf(RN3L MaxDegreeG010300facecolorbfacealpha5edgealpha1)histf(RN3L MaxDegreeG Hat010300facecolorrfacealpha5edgealpha1)histf(RN3L x010300facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightxlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN3L)

54 Application

grid on

subplot(234)hold onhistf(RN1S MaxDegreeG0150facecolorbfacealpha5edgealpha1)histf(RN1S MaxDegreeG Hat0150facecolorrfacealpha5edgealpha1)histf(RN1S x0150facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightxlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(R1NS)grid on

subplot(235)hold onhistf(RN2S MaxDegreeG010500facecolorbfacealpha5edgealpha1)histf(RN2S MaxDegreeG Hat010500facecolorrfacealpha5edgealpha1)histf(RN2S x010500facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightxlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN2S)grid on

subplot(236)hold onhistf(RN3S MaxDegreeG05300facecolorbfacealpha5edgealpha1)histf(RN3S MaxDegreeG Hat05300facecolorrfacealpha5edgealpha1)histf(RN3S x05300facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightgrid ontitle(RN3S)xlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labelset(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN2png minusr300)

h(3)=figure(NameComputation time over edgesNumberTitleoff)

subplot(231)hold onstem(RN1L EdgesGRN1L Time classicalg)stem(RN1L EdgesGRN1L Time algorithmro)stem(RN1L EdgesGRN1L Time greedybx)grid on

Appendix A 55

title(RN1L)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)

subplot(232)hold onstem(RN2L EdgesGRN2L Time classicalg)stem(RN2L EdgesGRN2L Time algorithmro)stem(RN2L EdgesGRN2L Time greedybx)grid ontitle(RN2L)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)

subplot(233)hold onstem(RN3L EdgesGRN3L Time classicalg)stem(RN3L EdgesGRN3L Time algorithmro)stem(RN3L EdgesGRN3L Time greedybx)grid ontitle(RN3L)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)

subplot(234)hold onstem(RN1S EdgesGRN1S Time classicalg)stem(RN1S EdgesGRN1S Time algorithmro)stem(RN1S EdgesGRN1S Time greedybx)grid ontitle(RN1S)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)

subplot(235)hold onstem(RN2S EdgesGRN2S Time classicalg)stem(RN2S EdgesGRN2S Time algorithmro)stem(RN2S EdgesGRN2S Time greedybx)grid ontitle(RN2S)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)

subplot(236)hold onstem(RN3S EdgesGRN3S Time classicalg)stem(RN3S EdgesGRN3S Time algorithmro)stem(RN3S EdgesGRN3S Time greedybx)

56 Application

grid ontitle(RN3S)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)set(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN3png minusr300)

h(4)=figure(NameSorted matching sizeNumberTitleoff)RN1L Sorted matching temp(1)=RN1L Classical matchingRN1L Sorted matching temp(2)=RN1L Final matchingRN1L Sorted matching temp(3)=RN1L Greedy matchingRN1L Sorted matching temp(4)=RN1L Initial matchingRN1L Sorted matching=sortrows(RN1L Sorted matching temp)

RN2L Sorted matching temp(1)=RN2L Classical matchingRN2L Sorted matching temp(2)=RN2L Final matchingRN2L Sorted matching temp(3)=RN2L Greedy matchingRN2L Sorted matching temp(4)=RN2L Initial matchingRN2L Sorted matching=sortrows(RN2L Sorted matching temp)

RN3L Sorted matching temp(1)=RN3L Classical matchingRN3L Sorted matching temp(2)=RN3L Final matchingRN3L Sorted matching temp(3)=RN3L Greedy matchingRN3L Sorted matching temp(4)=RN3L Initial matchingRN3L Sorted matching=sortrows(RN3L Sorted matching temp)

RN1S Sorted matching temp(1)=RN1S Classical matchingRN1S Sorted matching temp(2)=RN1S Final matchingRN1S Sorted matching temp(3)=RN1S Greedy matchingRN1S Sorted matching temp(4)=RN1S Initial matchingRN1S Sorted matching=sortrows(RN1S Sorted matching temp)

RN2S Sorted matching temp(1)=RN2S Classical matchingRN2S Sorted matching temp(2)=RN2S Final matchingRN2S Sorted matching temp(3)=RN2S Greedy matchingRN2S Sorted matching temp(4)=RN2S Initial matchingRN2S Sorted matching=sortrows(RN2S Sorted matching temp)

RN3S Sorted matching temp(1)=RN3S Classical matchingRN3S Sorted matching temp(2)=RN3S Final matchingRN3S Sorted matching temp(3)=RN3S Greedy matchingRN3S Sorted matching temp(4)=RN3S Initial matchingRN3S Sorted matching=sortrows(RN3S Sorted matching temp)

subplot(231)hold onplot(RN1L Sorted matching(1)b)plot(RN1L Sorted matching(2)g)plot(RN1L Sorted matching(3)r)plot(RN1L Sorted matching(4)m)

Appendix A 57

grid ontitle(RN1L)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)

subplot(232)hold onplot(RN2L Sorted matching(1)b)plot(RN2L Sorted matching(2)g)plot(RN2L Sorted matching(3)r)plot(RN2L Sorted matching(4)m)grid ontitle(RN2L)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)

subplot(233)hold onplot(RN3L Sorted matching(1)b)plot(RN3L Sorted matching(2)g)plot(RN3L Sorted matching(3)r)plot(RN3L Sorted matching(4)m)grid ontitle(RN3L)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)

subplot(234)hold onplot(RN1S Sorted matching(1)b)plot(RN1S Sorted matching(2)g)plot(RN1S Sorted matching(3)r)plot(RN1S Sorted matching(4)m)grid ontitle(RN1S)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)

subplot(235)hold onplot(RN2S Sorted matching(1)b)plot(RN2S Sorted matching(2)g)plot(RN2S Sorted matching(3)r)plot(RN2S Sorted matching(4)m)grid ontitle(RN2S)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)

58 Application

subplot(236)hold onplot(RN3S Sorted matching(1)b)plot(RN3S Sorted matching(2)g)plot(RN3S Sorted matching(3)r)plot(RN3S Sorted matching(4)m)grid ontitle(RN3S)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)set(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN4png minusr300)h(5)=figure(NameSorted RatiosNumberTitleoff)RN1L ratio1=RN1L NodesG hatRN1L NodesGRN2L ratio1=RN2L NodesG hatRN2L NodesGRN3L ratio1=RN3L NodesG hatRN3L NodesGRN1S ratio1=RN1S NodesG hatRN1S NodesGRN2S ratio1=RN2S NodesG hatRN2S NodesGRN3S ratio1=RN3S NodesG hatRN3S NodesG

RN1L ratio2=RN1L EdgesG HatRN1L EdgesGRN2L ratio2=RN2L EdgesG HatRN2L EdgesGRN3L ratio2=RN3L EdgesG HatRN3L EdgesGRN1S ratio2=RN1S EdgesG HatRN1S EdgesGRN2S ratio2=RN2S EdgesG HatRN2S EdgesGRN3S ratio2=RN3S EdgesG HatRN3S EdgesG

RN1L ratio3=RN1L MaxDegreeG HatRN1L MaxDegreeGRN2L ratio3=RN2L MaxDegreeG HatRN2L MaxDegreeGRN3L ratio3=RN3L MaxDegreeG HatRN3L MaxDegreeGRN1S ratio3=RN1S MaxDegreeG HatRN1S MaxDegreeGRN2S ratio3=RN2S MaxDegreeG HatRN2S MaxDegreeGRN3S ratio3=RN3S MaxDegreeG HatRN3S MaxDegreeG

RN1L ratio(1)=RN1L ratio1RN1L ratio(2)=RN1L ratio2RN1L ratio(3)=RN1L ratio3

RN2L ratio(1)=RN2L ratio1RN2L ratio(2)=RN2L ratio2RN2L ratio(3)=RN2L ratio3

RN3L ratio(1)=RN3L ratio1RN3L ratio(2)=RN3L ratio2RN3L ratio(3)=RN3L ratio3

RN1S ratio(1)=RN1S ratio1RN1S ratio(2)=RN1S ratio2RN1S ratio(3)=RN1S ratio3

RN2S ratio(1)=RN2S ratio1

Appendix A 59

RN2S ratio(2)=RN2S ratio2RN2S ratio(3)=RN2S ratio3

RN3S ratio(1)=RN3S ratio1RN3S ratio(2)=RN3S ratio2RN3S ratio(3)=RN3S ratio3

RN1L ratio sorted=sortrows(RN1L ratio)RN2L ratio sorted=sortrows(RN2L ratio)RN3L ratio sorted=sortrows(RN3L ratio)RN1S ratio sorted=sortrows(RN1S ratio)RN2S ratio sorted=sortrows(RN2S ratio)RN3S ratio sorted=sortrows(RN3S ratio)

subplot(231)hold onplot(RN1L ratio sorted(1)b)plot(RN1L ratio sorted(2)g)plot(RN1L ratio sorted(3)r)grid ontitle(RN1L)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)

subplot(232)hold onplot(RN2L ratio sorted(1)b)plot(RN2L ratio sorted(2)g)plot(RN2L ratio sorted(3)r)grid ontitle(RN2L)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)

subplot(233)hold onplot(RN3L ratio sorted(1)b)plot(RN3L ratio sorted(2)g)plot(RN3L ratio sorted(3)r)grid ontitle(RN3L)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)

subplot(234)hold onplot(RN1S ratio sorted(1)b)plot(RN1S ratio sorted(2)g)plot(RN1S ratio sorted(3)r)grid on

60 Application

title(RN1S)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)

subplot(235)hold onplot(RN2S ratio sorted(1)b)plot(RN2S ratio sorted(2)g)plot(RN2S ratio sorted(3)r)grid ontitle(RN2S)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)

subplot(236)hold onplot(RN3S ratio sorted(1)b)plot(RN3S ratio sorted(2)g)plot(RN3S ratio sorted(3)r)grid ontitle(RN3S)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)set(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN5png minusr300)

h(6)=figure(NameSorted edges over nodesNumberTitleoff)

RN1L DegreeG1=(RN1L EdgesG)(RN1L NodesG)RN1L DegreeG Hat1=(RN1L EdgesG Hat)(RN1L NodesG hat)

RN1L Degree temp1(1)=RN1L DegreeG1RN1L Degree temp1(2)=RN1L DegreeG Hat1RN1L Degree sorted1=sortrows(RN1L Degree temp1)subplot(231)hold on

plot(RN1L Degree sorted1(1)b)plot(RN1L Degree sorted1(2)g)grid ontitle(RN1L)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)

RN2L DegreeG1=(RN2L EdgesG)(RN2L NodesG)RN2L DegreeG Hat1=(RN2L EdgesG Hat)(RN2L NodesG hat)

RN2L Degree temp1(1)=RN2L DegreeG1

Appendix A 61

RN2L Degree temp1(2)=RN2L DegreeG Hat1RN2L Degree sorted1=sortrows(RN2L Degree temp1)

subplot(232)hold onplot(RN2L Degree sorted1(1)b)plot(RN2L Degree sorted1(2)g)grid ontitle(RN2L)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)

RN3L DegreeG1=(RN3L EdgesG)(RN3L NodesG)RN3L DegreeG Hat1=(RN3L EdgesG Hat)(RN3L NodesG hat)

RN3L Degree temp1(1)=RN3L DegreeG1RN3L Degree temp1(2)=RN3L DegreeG Hat1RN3L Degree sorted1=sortrows(RN3L Degree temp1)

subplot(233)hold onplot(RN3L Degree sorted1(1)b)plot(RN3L Degree sorted1(2)g)grid ontitle(RN3L)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)

RN1S DegreeG1=(RN1S EdgesG)(RN1S NodesG)RN1S DegreeG Hat1=(RN1S EdgesG Hat)(RN1S NodesG hat)

RN1S Degree temp1(1)=RN1S DegreeG1RN1S Degree temp1(2)=RN1S DegreeG Hat1RN1S Degree sorted1=sortrows(RN1S Degree temp1)

subplot(234)hold onplot(RN1S Degree sorted1(1)b)plot(RN1S Degree sorted1(2)g)grid ontitle(RN1S)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)

RN2S DegreeG1=(RN2S EdgesG)(RN2S NodesG)RN2S DegreeG Hat1=(RN2S EdgesG Hat)(RN2S NodesG hat)

RN2S Degree temp1(1)=RN2S DegreeG1

62 Application

RN2S Degree temp1(2)=RN2S DegreeG Hat1RN2S Degree sorted1=sortrows(RN2S Degree temp1)

subplot(235)hold onplot(RN2S Degree sorted1(1)b)plot(RN2S Degree sorted1(2)g)grid ontitle(RN2S)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)

RN3S DegreeG1=(RN3S EdgesG)(RN3S NodesG)RN3S DegreeG Hat1=(RN3S EdgesG Hat)(RN3S NodesG hat)

RN3S Degree temp1(1)=RN3S DegreeG1RN3S Degree temp1(2)=RN3S DegreeG Hat1RN3S Degree sorted1=sortrows(RN3S Degree temp1)

subplot(236)hold onplot(RN3S Degree sorted1(1)b)plot(RN3S Degree sorted1(2)g)grid ontitle(RN3S)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)set(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN6png minusr300)h(7)=figure(NameSorted mATCHED DEGREENumberTitleoff)RN1L ratioMax(1)=RN1L MaxDegreeGRN1L ratioMax(2)=RN1L MaxDegreeG Hat

RN1L ratio sortedMax=sortrows(RN1L ratioMax)subplot(231)hold onplot(RN1L ratio sortedMax(1)b)plot(RN1L ratio sortedMax(2)g)grid ontitle(RN1L)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)

RN2L ratioMax(1)=RN2L MaxDegreeGRN2L ratioMax(2)=RN2L MaxDegreeG Hat

RN2L ratio sortedMax=sortrows(RN2L ratioMax)subplot(232)

Appendix A 63

hold onplot(RN2L ratio sortedMax(1)b)plot(RN2L ratio sortedMax(2)g)grid ontitle(RN2L)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)

RN3L ratioMax(1)=RN3L MaxDegreeGRN3L ratioMax(2)=RN3L MaxDegreeG Hat

RN3L ratio sortedMax=sortrows(RN3L ratioMax)subplot(233)hold onplot(RN3L ratio sortedMax(1)b)plot(RN3L ratio sortedMax(2)g)grid ontitle(RN3L)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)

RN1S ratioMax(1)=RN1S MaxDegreeGRN1S ratioMax(2)=RN1S MaxDegreeG Hat

RN1S ratio sortedMax=sortrows(RN1S ratioMax)subplot(234)hold onplot(RN1S ratio sortedMax(1)b)plot(RN1S ratio sortedMax(2)g)grid ontitle(RN1S)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)

RN2S ratioMax(1)=RN2S MaxDegreeGRN2S ratioMax(2)=RN2S MaxDegreeG Hat

RN2S ratio sortedMax=sortrows(RN2S ratioMax)

subplot(235)hold onplot(RN2S ratio sortedMax(1)b)plot(RN2S ratio sortedMax(2)g)grid ontitle(RN2S)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)

RN3S ratioMax(1)=RN3S MaxDegreeGRN3S ratioMax(2)=RN3S MaxDegreeG Hat

64 Application

RN3S ratio sortedMax=sortrows(RN3S ratioMax)subplot(236)hold onplot(RN3S ratio sortedMax(1)b)plot(RN3S ratio sortedMax(2)g)grid ontitle(RN1L)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)set(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN7png minusr300)

tilefigs()(h)

Bibliography

[1] C Berge ldquoTWO THEOREMS IN GRAPH THEORYrdquo Proceedings of the NationalAcademy of Sciences of the United States of America vol 43 no 9 pp 842ndash844Sep 1957

[2] L Bui S Sanghavi and R Srikant ldquoDistributed link scheduling with constantoverheadrdquo IEEEACM Trans Netw vol 17 no 5 pp 1467ndash1480 2009

[3] R Duan and S Pettie ldquoLinear-time approximation for maximum weight matchingrdquoJ ACM vol 61 no 1 2014

[4] J Edmonds ldquoPaths trees and flowersrdquo Canadian Journal of Mathematics vol 17pp 449ndash467 1965

[5] J E Hopcroft and R M Karp ldquoAn n52 algorithm for maximum matchings inbipartite graphsrdquo SIAM J Comput vol 2 no 4 pp 225ndash231 1973

[6] S Micali and V V Vazirani ldquoAn O(radic|V ||E|) algorithm for finding maximum

matching in general graphsrdquo in 21st Symp on Foundations of Comp Sc (FOCS)IEEE 1980 pp 17ndash27

[7] N Nisse A Salch and V Weber ldquoRecovery of disrupted airline operationsrdquo 2015httphalinriafrSomething

[8] X Wu and R Srikant ldquoRegulated maximal matching A distributed schedulingalgorithm for multi-hop wireless networks with nodeexclusive spectrum sharingrdquo inIEEE Conf on Decision and Control 2005

65

  • Contents
  • Introduction
  • Algorithms
    • Maximum matching
    • k-maximum matching
      • k-matching for Airport Slot assignment
      • The case where k=3
      • The case of Paths
      • The case of the Spider
          • Application
            • Description
            • Reyni Erdos
            • Barabaacutesi Albert
            • Amadeus Graphs
            • Bipartite
            • Bipartite with degree seq
            • Appendix A
              • BipartiteGraphGeneratorpy
              • RandomGraphGeneratorpy
              • kequals3MaximumMatchingpy
              • Plotmat
                  • Bibliography
Page 44: Theodoros Alexandros KARAGKIOULES -  · Introduction This work is the result of a 6 months internship, under the supervision of research O cer Nicolas NISSE. The original scope of

Appendix A 45

done vertices = set()for p in rl

done verticesadd(p)neighbors = []list()for iii in range(0n)

if A[p][iii]==1neighborsappend(iii)

randomshuffle(neighbors)continue loop = Truedegree = len(neighbors)j = 0p2=randomrandom()while continue loop and (jltdegree)

next = neighbors[j]if next not in done vertices and p not in done vertices

done verticesadd(p)done verticesadd(next)if p2gt=00 Larger probability for smaller initial matching

maadd edge(pnext)m=m+1

continue loop = Falsej += 1

print matching listOfedgeprint maedgeMA=nxadjacency matrix(ma)MA=[Rtodense()tolist()[0] for R in MA]print MAB=[ join(map(strR)) for R in A]MB=[ join(map(strR)) for R in MA]

C=njoin(B)+nMC=njoin(MB)+nprint MCprint nprint mprint m1filea=str(i)+txtwith open(fileaw) as f

fwrite(str(n))fwrite(n)fwrite(str(n))fwrite(n)fwrite(str(m))fwrite(n)fwrite(n)fwrite(C)fwrite(n)fwrite(MC)

print nRandom graphs with random matching have been generated

46 Application

kequals3MaximumMatchingpy

from future import divisionimport networkx as nxfrom networkxalgorithms import bipartiteimport matplotlibpyplot as pltimport collectionsimport timeitimport xlwtimport xlrdimport mathimport sys

Case for General Graphsdef forced edges(Gadj dict2matching dict1num nodesforced)

flagg=0for n in range(0num nodes)

for k in adj dict2[n]if ([k]==matching dict1[n])

count=0for l in range(0num nodes)

count=count+adj dict2[l]count(k)if (len(adj dict2[n])==1) or (count==1)

forcedadd edge(nk)Gremove edge(nk)Gremove node(n)Gremove node(k)printforced edgenktemp=kflagg=1for m in range (len(adj dict2[n])minus1minus1minus1)

adj dict2[adj dict2[n][m]]remove(n)adj dict2[n]remove(adj dict2[n][m])

if adj dict2[temp]for l in range(len(adj dict2[temp])minus1minus1minus1)

if (adj dict2[temp][l]=n)adj dict2[adj dict2[temp][l]]remove(temp)adj dict2[temp]remove(adj dict2[temp][l])

break

def useless edges(num nodesadj dict1matching dict1uselessadj dict2G)for n in range(0num nodes)

for k in adj dict1[n]if ([k]=matching dict1[n]) and matching dict1[n] and matching dict1[k]

uselessadd edge(nk)Gremove edge(n k)

Appendix A 47

tempa=kadj dict2[n]remove(k)adj dict2[tempa]remove(n)adj dict1[tempa]remove(n)

return G

def Greedy(num nodesadj dict3matching dict2)

for n in range(0num nodes)if matching dict2[n]

flag2=minus1flag3=minus1for v in adj dict3[n]

if not matching dict2[v]flag2=vbreak

for p in adj dict3[matching dict2[n][0]]if not matching dict2[p]

flag3=pbreak

if (flag2=minus1) and (flag3=minus1) and (flag2=flag3)tempr=matching dict2[n][0]matching dict2[n]=[flag2]matching dict2[flag2]=[n]matching dict2[tempr]=[flag3]matching dict2[flag3]=[tempr]

elsefor k in adj dict3[n]

if not matching dict2[k]matching dict2[n]=[k]matching dict2[k]=[n]break

yo1=0for i in range(0num nodes)

if matching dict2[i] and [i]==matching dict2[matching dict2[i][0]]yo1=yo1+1

greedy size=yo12return greedy size

def General()

INPUTSwb = xlwtWorkbook()ws = wbadd sheet(Results Random)book=xlrdopen workbook(filenames randomxls)

48 Application

style0 = xlwteasyxf(fontbold on)style1 = xlwteasyxf(num format str=0000)INPUTSwswrite(0 0File style0)wswrite(0 1 Nodesstyle0)wswrite(0 2 Initial matchingstyle0)wswrite(0 3 NodesGstyle0)wswrite(0 4 EdgesGstyle0)wswrite(0 5 MaxDegreeGstyle0)wswrite(0 6 NodesG hatstyle0)wswrite(0 7 EdgesG Hatstyle0)wswrite(0 8 Useless edgesstyle0)wswrite(0 9 Forced edgesstyle0)wswrite(0 10 MaxDegreeG Hatstyle0)wswrite(0 11 Classical matchingstyle0)wswrite(0 12 Final matchingstyle0)wswrite(0 13 Greedy matchingstyle0)wswrite(0 14 Time classicalstyle0)wswrite(0 15 Time algorithmstyle0)wswrite(0 16 Time greedystyle0)wswrite(0 17 Perfect matching ratiostyle0)wswrite(0 18 Nodes ratiostyle0)wswrite(0 19 Edges ratiostyle0)wswrite(0 20 Matching ratiostyle0)

print nWelcomeThis is an implementation for general random graphs It uses Edmonds algorithm to compute maximum matching on G Hatn

for index in range (1481)was 481

if (index==482)f=open(Algotel generaltxtr)readlines()

elsefilea=str(booksheet by index(0)cell(index0))s=fileareplace(textu)replace()f=open(sr)readlines()Truewswrite(index 0 s)

print index

num nodes=int([xstrip()split() for x in f][0][0])

num matching=int([xstrip()split() for x in f][2][0])

adj temp = [xstrip()split() for x in f][44+num nodes]adj=[map(intR) for R in adj temp]

matching temp=[xstrip()split() for x in f][4+num nodes+14+2num nodes+1]matching1=[map(intR) for R in matching temp]

adj dict1=i[ii for iix in enumerate(L) if x] for iL in enumerate(adj)adj dict2=i[ii for iix in enumerate(L) if x] for iL in enumerate(adj)

Appendix A 49

adj dict3=i[ii for iix in enumerate(L) if x] for iL in enumerate(adj)

matching dict1=i[ii for iix in enumerate(L) if x] for iL in enumerate(matching1)matching dict2=i[ii for iix in enumerate(L) if x] for iL in enumerate(matching1)print adj dict2print matching dict2wswrite(index 1 num nodes)wswrite(index 2 num matching)

G = nxGraph()

useless= nxGraph()forced = nxGraph()

Fill Graphfor n in range(0num nodes)

for k in adj dict1[n]Gadd edge(nk)

Gt=Gnumber of edges()wswrite(index 3 Gnumber of nodes())wswrite(index 4 Gnumber of edges())wswrite(index 5 max(Gdegree()values()))

Compute Edmonds classical matching on G for comparison

startB = timeitdefault timer()Classical Matching=nxmax weight matching(G maxcardinality=False)stopB = timeitdefault timer()

Compute Gˆ nad MˆstartC = timeitdefault timer()useless edges(num nodesadj dict1matching dict1uselessadj dict2G)forced edges(Gadj dict2matching dict1num nodesforced)Final Matching=nxmax weight matching(G maxcardinality=False)stopC = timeitdefault timer()

GreedystartG = timeitdefault timer()greedy size=Greedy(num nodesadj dict3matching dict2)stopG = timeitdefault timer()

wswrite(index 6 Gnumber of nodes())wswrite(index 7 Gnumber of edges())wswrite(index 8 uselessnumber of edges())wswrite(index 9 forcednumber of edges())if Gdegree()values()

wswrite(index 10 max(Gdegree()values()))else

50 Application

wswrite(index 10 0)wswrite(index 11 len(Classical Matching)2)wswrite(index 12 len(Final Matching)2+forcednumber of edges())wswrite(index 13 greedy size)wswrite(index 14 stopB minus startBstyle1)wswrite(index 15 stopC minus startCstyle1)wswrite(index 16 stopG minus startGstyle1)wswrite(index 17 (len(Final Matching)2+forcednumber of edges())(num nodes2)style1)wswrite(index 18 Gnumber of nodes()Gtstyle1)wswrite(index 19 Gnumber of edges()Gtstyle1)wswrite(index 20 (len(Final Matching)2+forcednumber of edges())(len(Classical Matching)2)style1)

wbsave(AA Results Random Reyni Large Bipartitexls)

Main function Here we must choose the input form of the dataif name == main

startA = timeitdefault timer()General()stopA = timeitdefault timer()

print nThis program has terminatednnRunning time for 480 files stopAminusstartAprint nnPlease open AA Results Random Reyni Largexls file to see the Results

Appendix A 51

Plotmat

clear allclose allload(RN1Lmat)load(RN1Smat)load(RN2Lmat)load(RN2Smat)load(RN3Lmat)load(RN3Smat)

Plotsh(1)=figure(NameHistogram of Matching size difference between Constraint Algorithm and Greedy AlgorithmNumberTitleoff)

RN1L Greedydiff=RN1L Final matchingminusRN1L Greedy matchingRN2L Greedydiff=RN2L Final matchingminusRN2L Greedy matchingRN3L Greedydiff=RN3L Final matchingminusRN3L Greedy matchingRN1S Greedydiff=RN1S Final matchingminusRN1S Greedy matchingRN2S Greedydiff=RN2S Final matchingminusRN2S Greedy matchingRN3S Greedydiff=RN3S Final matchingminusRN3S Greedy matching

RN1L Finaldiff=RN1L Classical matchingminusRN1L Final matchingRN2L Finaldiff=RN2L Classical matchingminusRN2L Final matchingRN3L Finaldiff=RN3L Classical matchingminusRN3L Final matchingRN1S Finaldiff=RN1S Classical matchingminusRN1S Final matchingRN2S Finaldiff=RN2S Classical matchingminusRN2S Final matchingRN3S Finaldiff=RN3S Classical matchingminusRN3S Final matching

RN1L Classicaldiff=(RN1L Nodes2)minusRN1L Classical matchingRN2L Classicaldiff=(RN2L Nodes2)minusRN2L Classical matchingRN3L Classicaldiff=(RN3L Nodes2)minusRN3L Classical matchingRN1S Classicaldiff=(RN1S Nodes2)minusRN1S Classical matchingRN2S Classicaldiff=(RN2S Nodes2)minusRN2S Classical matchingRN3S Classicaldiff=(RN3S Nodes2)minusRN3S Classical matching

subplot(231)hold onhistf(RN1L Greedydiff0110facecolorbfacealpha9edgealpha1)histf(RN1L Finaldiff0110facecolorrfacealpha5edgealpha1)histf(RN1L Classicaldiff0110facecolorgfacealpha5edgealpha1)legalpha(ConminusGreClasminusConPerfminusClasslocationnortheast)legend boxoffaxis tightxlabel(edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN1L)grid on

subplot(232)hold onhistf(RN2L Greedydiff0110facecolorbfacealpha9edgealpha1)

52 Application

histf(RN2L Finaldiff0110facecolorrfacealpha5edgealpha1)histf(RN2L Classicaldiff0110facecolorgfacealpha5edgealpha1)legalpha(ConminusGreClasminusConPerfminusClasslocationnortheast)legend boxoffaxis tightxlabel(edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN2L)grid on

subplot(233)hold onhistf(RN3L Greedydiff0110facecolorbfacealpha5edgealpha1)histf(RN3L Finaldiff0110facecolorrfacealpha5edgealpha1)histf(RN3L Classicaldiff0110facecolorgfacealpha5edgealpha1)legalpha(ConminusGreClasminusConPerfminusClasslocationnortheast)legend boxoffaxis tightxlabel(edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN3L)grid on

subplot(234)hold onhistf(RN1S Greedydiff0110facecolorbfacealpha5edgealpha1)histf(RN1S Finaldiff0110facecolorrfacealpha5edgealpha1)histf(RN1S Classicaldiff0110facecolorgfacealpha5edgealpha1)legalpha(ConminusGreClasminusConPerfminusClasslocationnortheast)legend boxoffaxis tightxlabel(edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(R1NS)grid on

subplot(235)hold onhistf(RN2S Greedydiff0110facecolorbfacealpha5edgealpha1)histf(RN2S Finaldiff0110facecolorrfacealpha5edgealpha1)histf(RN2S Classicaldiff0110facecolorgfacealpha5edgealpha1)legalpha(ConminusGreClasminusConPerfminusClasslocationnortheast)legend boxoffaxis tightxlabel(edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN2S)grid on

subplot(236)hold onhistf(RN3S Greedydiff0110facecolorbfacealpha5edgealpha1)histf(RN3S Finaldiff0110facecolorrfacealpha5edgealpha1)histf(RN3S Classicaldiff0110facecolorgfacealpha5edgealpha1)

Appendix A 53

legalpha(ConminusGreClasminusConPerfminusClasslocationnortheast)legend boxoffaxis tightgrid ontitle(RN3S)xlabel(edges) xminusaxis labelylabel(instances) yminusaxis labelset(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN1png minusr300)h(2)=figure(NameHistogram of Max Degree of G AND G HatNumberTitleoff)RN1L x=RN1L MaxDegreeGminusRN1L MaxDegreeG HatRN2L x=RN2L MaxDegreeGminusRN2L MaxDegreeG HatRN3L x=RN3L MaxDegreeGminusRN3L MaxDegreeG HatRN1S x=RN1S MaxDegreeGminusRN1S MaxDegreeG HatRN2S x=RN2S MaxDegreeGminusRN2S MaxDegreeG HatRN3S x=RN3S MaxDegreeGminusRN3S MaxDegreeG Hatsubplot(231)hold onhistf(RN1L MaxDegreeG0150facecolorbfacealpha5edgealpha1)histf(RN1L MaxDegreeG Hat0150facecolorrfacealpha5edgealpha1)histf(RN1L x0150facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightxlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN1L)grid on

subplot(232)hold onhistf(RN2L MaxDegreeG010500facecolorbfacealpha5edgealpha1)histf(RN2L MaxDegreeG Hat010500facecolorrfacealpha5edgealpha1)histf(RN2L x010500facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightxlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN2L)grid on

subplot(233)hold onhistf(RN3L MaxDegreeG010300facecolorbfacealpha5edgealpha1)histf(RN3L MaxDegreeG Hat010300facecolorrfacealpha5edgealpha1)histf(RN3L x010300facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightxlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN3L)

54 Application

grid on

subplot(234)hold onhistf(RN1S MaxDegreeG0150facecolorbfacealpha5edgealpha1)histf(RN1S MaxDegreeG Hat0150facecolorrfacealpha5edgealpha1)histf(RN1S x0150facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightxlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(R1NS)grid on

subplot(235)hold onhistf(RN2S MaxDegreeG010500facecolorbfacealpha5edgealpha1)histf(RN2S MaxDegreeG Hat010500facecolorrfacealpha5edgealpha1)histf(RN2S x010500facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightxlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN2S)grid on

subplot(236)hold onhistf(RN3S MaxDegreeG05300facecolorbfacealpha5edgealpha1)histf(RN3S MaxDegreeG Hat05300facecolorrfacealpha5edgealpha1)histf(RN3S x05300facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightgrid ontitle(RN3S)xlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labelset(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN2png minusr300)

h(3)=figure(NameComputation time over edgesNumberTitleoff)

subplot(231)hold onstem(RN1L EdgesGRN1L Time classicalg)stem(RN1L EdgesGRN1L Time algorithmro)stem(RN1L EdgesGRN1L Time greedybx)grid on

Appendix A 55

title(RN1L)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)

subplot(232)hold onstem(RN2L EdgesGRN2L Time classicalg)stem(RN2L EdgesGRN2L Time algorithmro)stem(RN2L EdgesGRN2L Time greedybx)grid ontitle(RN2L)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)

subplot(233)hold onstem(RN3L EdgesGRN3L Time classicalg)stem(RN3L EdgesGRN3L Time algorithmro)stem(RN3L EdgesGRN3L Time greedybx)grid ontitle(RN3L)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)

subplot(234)hold onstem(RN1S EdgesGRN1S Time classicalg)stem(RN1S EdgesGRN1S Time algorithmro)stem(RN1S EdgesGRN1S Time greedybx)grid ontitle(RN1S)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)

subplot(235)hold onstem(RN2S EdgesGRN2S Time classicalg)stem(RN2S EdgesGRN2S Time algorithmro)stem(RN2S EdgesGRN2S Time greedybx)grid ontitle(RN2S)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)

subplot(236)hold onstem(RN3S EdgesGRN3S Time classicalg)stem(RN3S EdgesGRN3S Time algorithmro)stem(RN3S EdgesGRN3S Time greedybx)

56 Application

grid ontitle(RN3S)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)set(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN3png minusr300)

h(4)=figure(NameSorted matching sizeNumberTitleoff)RN1L Sorted matching temp(1)=RN1L Classical matchingRN1L Sorted matching temp(2)=RN1L Final matchingRN1L Sorted matching temp(3)=RN1L Greedy matchingRN1L Sorted matching temp(4)=RN1L Initial matchingRN1L Sorted matching=sortrows(RN1L Sorted matching temp)

RN2L Sorted matching temp(1)=RN2L Classical matchingRN2L Sorted matching temp(2)=RN2L Final matchingRN2L Sorted matching temp(3)=RN2L Greedy matchingRN2L Sorted matching temp(4)=RN2L Initial matchingRN2L Sorted matching=sortrows(RN2L Sorted matching temp)

RN3L Sorted matching temp(1)=RN3L Classical matchingRN3L Sorted matching temp(2)=RN3L Final matchingRN3L Sorted matching temp(3)=RN3L Greedy matchingRN3L Sorted matching temp(4)=RN3L Initial matchingRN3L Sorted matching=sortrows(RN3L Sorted matching temp)

RN1S Sorted matching temp(1)=RN1S Classical matchingRN1S Sorted matching temp(2)=RN1S Final matchingRN1S Sorted matching temp(3)=RN1S Greedy matchingRN1S Sorted matching temp(4)=RN1S Initial matchingRN1S Sorted matching=sortrows(RN1S Sorted matching temp)

RN2S Sorted matching temp(1)=RN2S Classical matchingRN2S Sorted matching temp(2)=RN2S Final matchingRN2S Sorted matching temp(3)=RN2S Greedy matchingRN2S Sorted matching temp(4)=RN2S Initial matchingRN2S Sorted matching=sortrows(RN2S Sorted matching temp)

RN3S Sorted matching temp(1)=RN3S Classical matchingRN3S Sorted matching temp(2)=RN3S Final matchingRN3S Sorted matching temp(3)=RN3S Greedy matchingRN3S Sorted matching temp(4)=RN3S Initial matchingRN3S Sorted matching=sortrows(RN3S Sorted matching temp)

subplot(231)hold onplot(RN1L Sorted matching(1)b)plot(RN1L Sorted matching(2)g)plot(RN1L Sorted matching(3)r)plot(RN1L Sorted matching(4)m)

Appendix A 57

grid ontitle(RN1L)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)

subplot(232)hold onplot(RN2L Sorted matching(1)b)plot(RN2L Sorted matching(2)g)plot(RN2L Sorted matching(3)r)plot(RN2L Sorted matching(4)m)grid ontitle(RN2L)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)

subplot(233)hold onplot(RN3L Sorted matching(1)b)plot(RN3L Sorted matching(2)g)plot(RN3L Sorted matching(3)r)plot(RN3L Sorted matching(4)m)grid ontitle(RN3L)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)

subplot(234)hold onplot(RN1S Sorted matching(1)b)plot(RN1S Sorted matching(2)g)plot(RN1S Sorted matching(3)r)plot(RN1S Sorted matching(4)m)grid ontitle(RN1S)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)

subplot(235)hold onplot(RN2S Sorted matching(1)b)plot(RN2S Sorted matching(2)g)plot(RN2S Sorted matching(3)r)plot(RN2S Sorted matching(4)m)grid ontitle(RN2S)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)

58 Application

subplot(236)hold onplot(RN3S Sorted matching(1)b)plot(RN3S Sorted matching(2)g)plot(RN3S Sorted matching(3)r)plot(RN3S Sorted matching(4)m)grid ontitle(RN3S)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)set(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN4png minusr300)h(5)=figure(NameSorted RatiosNumberTitleoff)RN1L ratio1=RN1L NodesG hatRN1L NodesGRN2L ratio1=RN2L NodesG hatRN2L NodesGRN3L ratio1=RN3L NodesG hatRN3L NodesGRN1S ratio1=RN1S NodesG hatRN1S NodesGRN2S ratio1=RN2S NodesG hatRN2S NodesGRN3S ratio1=RN3S NodesG hatRN3S NodesG

RN1L ratio2=RN1L EdgesG HatRN1L EdgesGRN2L ratio2=RN2L EdgesG HatRN2L EdgesGRN3L ratio2=RN3L EdgesG HatRN3L EdgesGRN1S ratio2=RN1S EdgesG HatRN1S EdgesGRN2S ratio2=RN2S EdgesG HatRN2S EdgesGRN3S ratio2=RN3S EdgesG HatRN3S EdgesG

RN1L ratio3=RN1L MaxDegreeG HatRN1L MaxDegreeGRN2L ratio3=RN2L MaxDegreeG HatRN2L MaxDegreeGRN3L ratio3=RN3L MaxDegreeG HatRN3L MaxDegreeGRN1S ratio3=RN1S MaxDegreeG HatRN1S MaxDegreeGRN2S ratio3=RN2S MaxDegreeG HatRN2S MaxDegreeGRN3S ratio3=RN3S MaxDegreeG HatRN3S MaxDegreeG

RN1L ratio(1)=RN1L ratio1RN1L ratio(2)=RN1L ratio2RN1L ratio(3)=RN1L ratio3

RN2L ratio(1)=RN2L ratio1RN2L ratio(2)=RN2L ratio2RN2L ratio(3)=RN2L ratio3

RN3L ratio(1)=RN3L ratio1RN3L ratio(2)=RN3L ratio2RN3L ratio(3)=RN3L ratio3

RN1S ratio(1)=RN1S ratio1RN1S ratio(2)=RN1S ratio2RN1S ratio(3)=RN1S ratio3

RN2S ratio(1)=RN2S ratio1

Appendix A 59

RN2S ratio(2)=RN2S ratio2RN2S ratio(3)=RN2S ratio3

RN3S ratio(1)=RN3S ratio1RN3S ratio(2)=RN3S ratio2RN3S ratio(3)=RN3S ratio3

RN1L ratio sorted=sortrows(RN1L ratio)RN2L ratio sorted=sortrows(RN2L ratio)RN3L ratio sorted=sortrows(RN3L ratio)RN1S ratio sorted=sortrows(RN1S ratio)RN2S ratio sorted=sortrows(RN2S ratio)RN3S ratio sorted=sortrows(RN3S ratio)

subplot(231)hold onplot(RN1L ratio sorted(1)b)plot(RN1L ratio sorted(2)g)plot(RN1L ratio sorted(3)r)grid ontitle(RN1L)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)

subplot(232)hold onplot(RN2L ratio sorted(1)b)plot(RN2L ratio sorted(2)g)plot(RN2L ratio sorted(3)r)grid ontitle(RN2L)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)

subplot(233)hold onplot(RN3L ratio sorted(1)b)plot(RN3L ratio sorted(2)g)plot(RN3L ratio sorted(3)r)grid ontitle(RN3L)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)

subplot(234)hold onplot(RN1S ratio sorted(1)b)plot(RN1S ratio sorted(2)g)plot(RN1S ratio sorted(3)r)grid on

60 Application

title(RN1S)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)

subplot(235)hold onplot(RN2S ratio sorted(1)b)plot(RN2S ratio sorted(2)g)plot(RN2S ratio sorted(3)r)grid ontitle(RN2S)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)

subplot(236)hold onplot(RN3S ratio sorted(1)b)plot(RN3S ratio sorted(2)g)plot(RN3S ratio sorted(3)r)grid ontitle(RN3S)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)set(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN5png minusr300)

h(6)=figure(NameSorted edges over nodesNumberTitleoff)

RN1L DegreeG1=(RN1L EdgesG)(RN1L NodesG)RN1L DegreeG Hat1=(RN1L EdgesG Hat)(RN1L NodesG hat)

RN1L Degree temp1(1)=RN1L DegreeG1RN1L Degree temp1(2)=RN1L DegreeG Hat1RN1L Degree sorted1=sortrows(RN1L Degree temp1)subplot(231)hold on

plot(RN1L Degree sorted1(1)b)plot(RN1L Degree sorted1(2)g)grid ontitle(RN1L)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)

RN2L DegreeG1=(RN2L EdgesG)(RN2L NodesG)RN2L DegreeG Hat1=(RN2L EdgesG Hat)(RN2L NodesG hat)

RN2L Degree temp1(1)=RN2L DegreeG1

Appendix A 61

RN2L Degree temp1(2)=RN2L DegreeG Hat1RN2L Degree sorted1=sortrows(RN2L Degree temp1)

subplot(232)hold onplot(RN2L Degree sorted1(1)b)plot(RN2L Degree sorted1(2)g)grid ontitle(RN2L)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)

RN3L DegreeG1=(RN3L EdgesG)(RN3L NodesG)RN3L DegreeG Hat1=(RN3L EdgesG Hat)(RN3L NodesG hat)

RN3L Degree temp1(1)=RN3L DegreeG1RN3L Degree temp1(2)=RN3L DegreeG Hat1RN3L Degree sorted1=sortrows(RN3L Degree temp1)

subplot(233)hold onplot(RN3L Degree sorted1(1)b)plot(RN3L Degree sorted1(2)g)grid ontitle(RN3L)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)

RN1S DegreeG1=(RN1S EdgesG)(RN1S NodesG)RN1S DegreeG Hat1=(RN1S EdgesG Hat)(RN1S NodesG hat)

RN1S Degree temp1(1)=RN1S DegreeG1RN1S Degree temp1(2)=RN1S DegreeG Hat1RN1S Degree sorted1=sortrows(RN1S Degree temp1)

subplot(234)hold onplot(RN1S Degree sorted1(1)b)plot(RN1S Degree sorted1(2)g)grid ontitle(RN1S)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)

RN2S DegreeG1=(RN2S EdgesG)(RN2S NodesG)RN2S DegreeG Hat1=(RN2S EdgesG Hat)(RN2S NodesG hat)

RN2S Degree temp1(1)=RN2S DegreeG1

62 Application

RN2S Degree temp1(2)=RN2S DegreeG Hat1RN2S Degree sorted1=sortrows(RN2S Degree temp1)

subplot(235)hold onplot(RN2S Degree sorted1(1)b)plot(RN2S Degree sorted1(2)g)grid ontitle(RN2S)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)

RN3S DegreeG1=(RN3S EdgesG)(RN3S NodesG)RN3S DegreeG Hat1=(RN3S EdgesG Hat)(RN3S NodesG hat)

RN3S Degree temp1(1)=RN3S DegreeG1RN3S Degree temp1(2)=RN3S DegreeG Hat1RN3S Degree sorted1=sortrows(RN3S Degree temp1)

subplot(236)hold onplot(RN3S Degree sorted1(1)b)plot(RN3S Degree sorted1(2)g)grid ontitle(RN3S)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)set(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN6png minusr300)h(7)=figure(NameSorted mATCHED DEGREENumberTitleoff)RN1L ratioMax(1)=RN1L MaxDegreeGRN1L ratioMax(2)=RN1L MaxDegreeG Hat

RN1L ratio sortedMax=sortrows(RN1L ratioMax)subplot(231)hold onplot(RN1L ratio sortedMax(1)b)plot(RN1L ratio sortedMax(2)g)grid ontitle(RN1L)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)

RN2L ratioMax(1)=RN2L MaxDegreeGRN2L ratioMax(2)=RN2L MaxDegreeG Hat

RN2L ratio sortedMax=sortrows(RN2L ratioMax)subplot(232)

Appendix A 63

hold onplot(RN2L ratio sortedMax(1)b)plot(RN2L ratio sortedMax(2)g)grid ontitle(RN2L)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)

RN3L ratioMax(1)=RN3L MaxDegreeGRN3L ratioMax(2)=RN3L MaxDegreeG Hat

RN3L ratio sortedMax=sortrows(RN3L ratioMax)subplot(233)hold onplot(RN3L ratio sortedMax(1)b)plot(RN3L ratio sortedMax(2)g)grid ontitle(RN3L)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)

RN1S ratioMax(1)=RN1S MaxDegreeGRN1S ratioMax(2)=RN1S MaxDegreeG Hat

RN1S ratio sortedMax=sortrows(RN1S ratioMax)subplot(234)hold onplot(RN1S ratio sortedMax(1)b)plot(RN1S ratio sortedMax(2)g)grid ontitle(RN1S)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)

RN2S ratioMax(1)=RN2S MaxDegreeGRN2S ratioMax(2)=RN2S MaxDegreeG Hat

RN2S ratio sortedMax=sortrows(RN2S ratioMax)

subplot(235)hold onplot(RN2S ratio sortedMax(1)b)plot(RN2S ratio sortedMax(2)g)grid ontitle(RN2S)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)

RN3S ratioMax(1)=RN3S MaxDegreeGRN3S ratioMax(2)=RN3S MaxDegreeG Hat

64 Application

RN3S ratio sortedMax=sortrows(RN3S ratioMax)subplot(236)hold onplot(RN3S ratio sortedMax(1)b)plot(RN3S ratio sortedMax(2)g)grid ontitle(RN1L)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)set(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN7png minusr300)

tilefigs()(h)

Bibliography

[1] C Berge ldquoTWO THEOREMS IN GRAPH THEORYrdquo Proceedings of the NationalAcademy of Sciences of the United States of America vol 43 no 9 pp 842ndash844Sep 1957

[2] L Bui S Sanghavi and R Srikant ldquoDistributed link scheduling with constantoverheadrdquo IEEEACM Trans Netw vol 17 no 5 pp 1467ndash1480 2009

[3] R Duan and S Pettie ldquoLinear-time approximation for maximum weight matchingrdquoJ ACM vol 61 no 1 2014

[4] J Edmonds ldquoPaths trees and flowersrdquo Canadian Journal of Mathematics vol 17pp 449ndash467 1965

[5] J E Hopcroft and R M Karp ldquoAn n52 algorithm for maximum matchings inbipartite graphsrdquo SIAM J Comput vol 2 no 4 pp 225ndash231 1973

[6] S Micali and V V Vazirani ldquoAn O(radic|V ||E|) algorithm for finding maximum

matching in general graphsrdquo in 21st Symp on Foundations of Comp Sc (FOCS)IEEE 1980 pp 17ndash27

[7] N Nisse A Salch and V Weber ldquoRecovery of disrupted airline operationsrdquo 2015httphalinriafrSomething

[8] X Wu and R Srikant ldquoRegulated maximal matching A distributed schedulingalgorithm for multi-hop wireless networks with nodeexclusive spectrum sharingrdquo inIEEE Conf on Decision and Control 2005

65

  • Contents
  • Introduction
  • Algorithms
    • Maximum matching
    • k-maximum matching
      • k-matching for Airport Slot assignment
      • The case where k=3
      • The case of Paths
      • The case of the Spider
          • Application
            • Description
            • Reyni Erdos
            • Barabaacutesi Albert
            • Amadeus Graphs
            • Bipartite
            • Bipartite with degree seq
            • Appendix A
              • BipartiteGraphGeneratorpy
              • RandomGraphGeneratorpy
              • kequals3MaximumMatchingpy
              • Plotmat
                  • Bibliography
Page 45: Theodoros Alexandros KARAGKIOULES -  · Introduction This work is the result of a 6 months internship, under the supervision of research O cer Nicolas NISSE. The original scope of

46 Application

kequals3MaximumMatchingpy

from future import divisionimport networkx as nxfrom networkxalgorithms import bipartiteimport matplotlibpyplot as pltimport collectionsimport timeitimport xlwtimport xlrdimport mathimport sys

Case for General Graphsdef forced edges(Gadj dict2matching dict1num nodesforced)

flagg=0for n in range(0num nodes)

for k in adj dict2[n]if ([k]==matching dict1[n])

count=0for l in range(0num nodes)

count=count+adj dict2[l]count(k)if (len(adj dict2[n])==1) or (count==1)

forcedadd edge(nk)Gremove edge(nk)Gremove node(n)Gremove node(k)printforced edgenktemp=kflagg=1for m in range (len(adj dict2[n])minus1minus1minus1)

adj dict2[adj dict2[n][m]]remove(n)adj dict2[n]remove(adj dict2[n][m])

if adj dict2[temp]for l in range(len(adj dict2[temp])minus1minus1minus1)

if (adj dict2[temp][l]=n)adj dict2[adj dict2[temp][l]]remove(temp)adj dict2[temp]remove(adj dict2[temp][l])

break

def useless edges(num nodesadj dict1matching dict1uselessadj dict2G)for n in range(0num nodes)

for k in adj dict1[n]if ([k]=matching dict1[n]) and matching dict1[n] and matching dict1[k]

uselessadd edge(nk)Gremove edge(n k)

Appendix A 47

tempa=kadj dict2[n]remove(k)adj dict2[tempa]remove(n)adj dict1[tempa]remove(n)

return G

def Greedy(num nodesadj dict3matching dict2)

for n in range(0num nodes)if matching dict2[n]

flag2=minus1flag3=minus1for v in adj dict3[n]

if not matching dict2[v]flag2=vbreak

for p in adj dict3[matching dict2[n][0]]if not matching dict2[p]

flag3=pbreak

if (flag2=minus1) and (flag3=minus1) and (flag2=flag3)tempr=matching dict2[n][0]matching dict2[n]=[flag2]matching dict2[flag2]=[n]matching dict2[tempr]=[flag3]matching dict2[flag3]=[tempr]

elsefor k in adj dict3[n]

if not matching dict2[k]matching dict2[n]=[k]matching dict2[k]=[n]break

yo1=0for i in range(0num nodes)

if matching dict2[i] and [i]==matching dict2[matching dict2[i][0]]yo1=yo1+1

greedy size=yo12return greedy size

def General()

INPUTSwb = xlwtWorkbook()ws = wbadd sheet(Results Random)book=xlrdopen workbook(filenames randomxls)

48 Application

style0 = xlwteasyxf(fontbold on)style1 = xlwteasyxf(num format str=0000)INPUTSwswrite(0 0File style0)wswrite(0 1 Nodesstyle0)wswrite(0 2 Initial matchingstyle0)wswrite(0 3 NodesGstyle0)wswrite(0 4 EdgesGstyle0)wswrite(0 5 MaxDegreeGstyle0)wswrite(0 6 NodesG hatstyle0)wswrite(0 7 EdgesG Hatstyle0)wswrite(0 8 Useless edgesstyle0)wswrite(0 9 Forced edgesstyle0)wswrite(0 10 MaxDegreeG Hatstyle0)wswrite(0 11 Classical matchingstyle0)wswrite(0 12 Final matchingstyle0)wswrite(0 13 Greedy matchingstyle0)wswrite(0 14 Time classicalstyle0)wswrite(0 15 Time algorithmstyle0)wswrite(0 16 Time greedystyle0)wswrite(0 17 Perfect matching ratiostyle0)wswrite(0 18 Nodes ratiostyle0)wswrite(0 19 Edges ratiostyle0)wswrite(0 20 Matching ratiostyle0)

print nWelcomeThis is an implementation for general random graphs It uses Edmonds algorithm to compute maximum matching on G Hatn

for index in range (1481)was 481

if (index==482)f=open(Algotel generaltxtr)readlines()

elsefilea=str(booksheet by index(0)cell(index0))s=fileareplace(textu)replace()f=open(sr)readlines()Truewswrite(index 0 s)

print index

num nodes=int([xstrip()split() for x in f][0][0])

num matching=int([xstrip()split() for x in f][2][0])

adj temp = [xstrip()split() for x in f][44+num nodes]adj=[map(intR) for R in adj temp]

matching temp=[xstrip()split() for x in f][4+num nodes+14+2num nodes+1]matching1=[map(intR) for R in matching temp]

adj dict1=i[ii for iix in enumerate(L) if x] for iL in enumerate(adj)adj dict2=i[ii for iix in enumerate(L) if x] for iL in enumerate(adj)

Appendix A 49

adj dict3=i[ii for iix in enumerate(L) if x] for iL in enumerate(adj)

matching dict1=i[ii for iix in enumerate(L) if x] for iL in enumerate(matching1)matching dict2=i[ii for iix in enumerate(L) if x] for iL in enumerate(matching1)print adj dict2print matching dict2wswrite(index 1 num nodes)wswrite(index 2 num matching)

G = nxGraph()

useless= nxGraph()forced = nxGraph()

Fill Graphfor n in range(0num nodes)

for k in adj dict1[n]Gadd edge(nk)

Gt=Gnumber of edges()wswrite(index 3 Gnumber of nodes())wswrite(index 4 Gnumber of edges())wswrite(index 5 max(Gdegree()values()))

Compute Edmonds classical matching on G for comparison

startB = timeitdefault timer()Classical Matching=nxmax weight matching(G maxcardinality=False)stopB = timeitdefault timer()

Compute Gˆ nad MˆstartC = timeitdefault timer()useless edges(num nodesadj dict1matching dict1uselessadj dict2G)forced edges(Gadj dict2matching dict1num nodesforced)Final Matching=nxmax weight matching(G maxcardinality=False)stopC = timeitdefault timer()

GreedystartG = timeitdefault timer()greedy size=Greedy(num nodesadj dict3matching dict2)stopG = timeitdefault timer()

wswrite(index 6 Gnumber of nodes())wswrite(index 7 Gnumber of edges())wswrite(index 8 uselessnumber of edges())wswrite(index 9 forcednumber of edges())if Gdegree()values()

wswrite(index 10 max(Gdegree()values()))else

50 Application

wswrite(index 10 0)wswrite(index 11 len(Classical Matching)2)wswrite(index 12 len(Final Matching)2+forcednumber of edges())wswrite(index 13 greedy size)wswrite(index 14 stopB minus startBstyle1)wswrite(index 15 stopC minus startCstyle1)wswrite(index 16 stopG minus startGstyle1)wswrite(index 17 (len(Final Matching)2+forcednumber of edges())(num nodes2)style1)wswrite(index 18 Gnumber of nodes()Gtstyle1)wswrite(index 19 Gnumber of edges()Gtstyle1)wswrite(index 20 (len(Final Matching)2+forcednumber of edges())(len(Classical Matching)2)style1)

wbsave(AA Results Random Reyni Large Bipartitexls)

Main function Here we must choose the input form of the dataif name == main

startA = timeitdefault timer()General()stopA = timeitdefault timer()

print nThis program has terminatednnRunning time for 480 files stopAminusstartAprint nnPlease open AA Results Random Reyni Largexls file to see the Results

Appendix A 51

Plotmat

clear allclose allload(RN1Lmat)load(RN1Smat)load(RN2Lmat)load(RN2Smat)load(RN3Lmat)load(RN3Smat)

Plotsh(1)=figure(NameHistogram of Matching size difference between Constraint Algorithm and Greedy AlgorithmNumberTitleoff)

RN1L Greedydiff=RN1L Final matchingminusRN1L Greedy matchingRN2L Greedydiff=RN2L Final matchingminusRN2L Greedy matchingRN3L Greedydiff=RN3L Final matchingminusRN3L Greedy matchingRN1S Greedydiff=RN1S Final matchingminusRN1S Greedy matchingRN2S Greedydiff=RN2S Final matchingminusRN2S Greedy matchingRN3S Greedydiff=RN3S Final matchingminusRN3S Greedy matching

RN1L Finaldiff=RN1L Classical matchingminusRN1L Final matchingRN2L Finaldiff=RN2L Classical matchingminusRN2L Final matchingRN3L Finaldiff=RN3L Classical matchingminusRN3L Final matchingRN1S Finaldiff=RN1S Classical matchingminusRN1S Final matchingRN2S Finaldiff=RN2S Classical matchingminusRN2S Final matchingRN3S Finaldiff=RN3S Classical matchingminusRN3S Final matching

RN1L Classicaldiff=(RN1L Nodes2)minusRN1L Classical matchingRN2L Classicaldiff=(RN2L Nodes2)minusRN2L Classical matchingRN3L Classicaldiff=(RN3L Nodes2)minusRN3L Classical matchingRN1S Classicaldiff=(RN1S Nodes2)minusRN1S Classical matchingRN2S Classicaldiff=(RN2S Nodes2)minusRN2S Classical matchingRN3S Classicaldiff=(RN3S Nodes2)minusRN3S Classical matching

subplot(231)hold onhistf(RN1L Greedydiff0110facecolorbfacealpha9edgealpha1)histf(RN1L Finaldiff0110facecolorrfacealpha5edgealpha1)histf(RN1L Classicaldiff0110facecolorgfacealpha5edgealpha1)legalpha(ConminusGreClasminusConPerfminusClasslocationnortheast)legend boxoffaxis tightxlabel(edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN1L)grid on

subplot(232)hold onhistf(RN2L Greedydiff0110facecolorbfacealpha9edgealpha1)

52 Application

histf(RN2L Finaldiff0110facecolorrfacealpha5edgealpha1)histf(RN2L Classicaldiff0110facecolorgfacealpha5edgealpha1)legalpha(ConminusGreClasminusConPerfminusClasslocationnortheast)legend boxoffaxis tightxlabel(edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN2L)grid on

subplot(233)hold onhistf(RN3L Greedydiff0110facecolorbfacealpha5edgealpha1)histf(RN3L Finaldiff0110facecolorrfacealpha5edgealpha1)histf(RN3L Classicaldiff0110facecolorgfacealpha5edgealpha1)legalpha(ConminusGreClasminusConPerfminusClasslocationnortheast)legend boxoffaxis tightxlabel(edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN3L)grid on

subplot(234)hold onhistf(RN1S Greedydiff0110facecolorbfacealpha5edgealpha1)histf(RN1S Finaldiff0110facecolorrfacealpha5edgealpha1)histf(RN1S Classicaldiff0110facecolorgfacealpha5edgealpha1)legalpha(ConminusGreClasminusConPerfminusClasslocationnortheast)legend boxoffaxis tightxlabel(edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(R1NS)grid on

subplot(235)hold onhistf(RN2S Greedydiff0110facecolorbfacealpha5edgealpha1)histf(RN2S Finaldiff0110facecolorrfacealpha5edgealpha1)histf(RN2S Classicaldiff0110facecolorgfacealpha5edgealpha1)legalpha(ConminusGreClasminusConPerfminusClasslocationnortheast)legend boxoffaxis tightxlabel(edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN2S)grid on

subplot(236)hold onhistf(RN3S Greedydiff0110facecolorbfacealpha5edgealpha1)histf(RN3S Finaldiff0110facecolorrfacealpha5edgealpha1)histf(RN3S Classicaldiff0110facecolorgfacealpha5edgealpha1)

Appendix A 53

legalpha(ConminusGreClasminusConPerfminusClasslocationnortheast)legend boxoffaxis tightgrid ontitle(RN3S)xlabel(edges) xminusaxis labelylabel(instances) yminusaxis labelset(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN1png minusr300)h(2)=figure(NameHistogram of Max Degree of G AND G HatNumberTitleoff)RN1L x=RN1L MaxDegreeGminusRN1L MaxDegreeG HatRN2L x=RN2L MaxDegreeGminusRN2L MaxDegreeG HatRN3L x=RN3L MaxDegreeGminusRN3L MaxDegreeG HatRN1S x=RN1S MaxDegreeGminusRN1S MaxDegreeG HatRN2S x=RN2S MaxDegreeGminusRN2S MaxDegreeG HatRN3S x=RN3S MaxDegreeGminusRN3S MaxDegreeG Hatsubplot(231)hold onhistf(RN1L MaxDegreeG0150facecolorbfacealpha5edgealpha1)histf(RN1L MaxDegreeG Hat0150facecolorrfacealpha5edgealpha1)histf(RN1L x0150facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightxlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN1L)grid on

subplot(232)hold onhistf(RN2L MaxDegreeG010500facecolorbfacealpha5edgealpha1)histf(RN2L MaxDegreeG Hat010500facecolorrfacealpha5edgealpha1)histf(RN2L x010500facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightxlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN2L)grid on

subplot(233)hold onhistf(RN3L MaxDegreeG010300facecolorbfacealpha5edgealpha1)histf(RN3L MaxDegreeG Hat010300facecolorrfacealpha5edgealpha1)histf(RN3L x010300facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightxlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN3L)

54 Application

grid on

subplot(234)hold onhistf(RN1S MaxDegreeG0150facecolorbfacealpha5edgealpha1)histf(RN1S MaxDegreeG Hat0150facecolorrfacealpha5edgealpha1)histf(RN1S x0150facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightxlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(R1NS)grid on

subplot(235)hold onhistf(RN2S MaxDegreeG010500facecolorbfacealpha5edgealpha1)histf(RN2S MaxDegreeG Hat010500facecolorrfacealpha5edgealpha1)histf(RN2S x010500facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightxlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN2S)grid on

subplot(236)hold onhistf(RN3S MaxDegreeG05300facecolorbfacealpha5edgealpha1)histf(RN3S MaxDegreeG Hat05300facecolorrfacealpha5edgealpha1)histf(RN3S x05300facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightgrid ontitle(RN3S)xlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labelset(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN2png minusr300)

h(3)=figure(NameComputation time over edgesNumberTitleoff)

subplot(231)hold onstem(RN1L EdgesGRN1L Time classicalg)stem(RN1L EdgesGRN1L Time algorithmro)stem(RN1L EdgesGRN1L Time greedybx)grid on

Appendix A 55

title(RN1L)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)

subplot(232)hold onstem(RN2L EdgesGRN2L Time classicalg)stem(RN2L EdgesGRN2L Time algorithmro)stem(RN2L EdgesGRN2L Time greedybx)grid ontitle(RN2L)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)

subplot(233)hold onstem(RN3L EdgesGRN3L Time classicalg)stem(RN3L EdgesGRN3L Time algorithmro)stem(RN3L EdgesGRN3L Time greedybx)grid ontitle(RN3L)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)

subplot(234)hold onstem(RN1S EdgesGRN1S Time classicalg)stem(RN1S EdgesGRN1S Time algorithmro)stem(RN1S EdgesGRN1S Time greedybx)grid ontitle(RN1S)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)

subplot(235)hold onstem(RN2S EdgesGRN2S Time classicalg)stem(RN2S EdgesGRN2S Time algorithmro)stem(RN2S EdgesGRN2S Time greedybx)grid ontitle(RN2S)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)

subplot(236)hold onstem(RN3S EdgesGRN3S Time classicalg)stem(RN3S EdgesGRN3S Time algorithmro)stem(RN3S EdgesGRN3S Time greedybx)

56 Application

grid ontitle(RN3S)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)set(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN3png minusr300)

h(4)=figure(NameSorted matching sizeNumberTitleoff)RN1L Sorted matching temp(1)=RN1L Classical matchingRN1L Sorted matching temp(2)=RN1L Final matchingRN1L Sorted matching temp(3)=RN1L Greedy matchingRN1L Sorted matching temp(4)=RN1L Initial matchingRN1L Sorted matching=sortrows(RN1L Sorted matching temp)

RN2L Sorted matching temp(1)=RN2L Classical matchingRN2L Sorted matching temp(2)=RN2L Final matchingRN2L Sorted matching temp(3)=RN2L Greedy matchingRN2L Sorted matching temp(4)=RN2L Initial matchingRN2L Sorted matching=sortrows(RN2L Sorted matching temp)

RN3L Sorted matching temp(1)=RN3L Classical matchingRN3L Sorted matching temp(2)=RN3L Final matchingRN3L Sorted matching temp(3)=RN3L Greedy matchingRN3L Sorted matching temp(4)=RN3L Initial matchingRN3L Sorted matching=sortrows(RN3L Sorted matching temp)

RN1S Sorted matching temp(1)=RN1S Classical matchingRN1S Sorted matching temp(2)=RN1S Final matchingRN1S Sorted matching temp(3)=RN1S Greedy matchingRN1S Sorted matching temp(4)=RN1S Initial matchingRN1S Sorted matching=sortrows(RN1S Sorted matching temp)

RN2S Sorted matching temp(1)=RN2S Classical matchingRN2S Sorted matching temp(2)=RN2S Final matchingRN2S Sorted matching temp(3)=RN2S Greedy matchingRN2S Sorted matching temp(4)=RN2S Initial matchingRN2S Sorted matching=sortrows(RN2S Sorted matching temp)

RN3S Sorted matching temp(1)=RN3S Classical matchingRN3S Sorted matching temp(2)=RN3S Final matchingRN3S Sorted matching temp(3)=RN3S Greedy matchingRN3S Sorted matching temp(4)=RN3S Initial matchingRN3S Sorted matching=sortrows(RN3S Sorted matching temp)

subplot(231)hold onplot(RN1L Sorted matching(1)b)plot(RN1L Sorted matching(2)g)plot(RN1L Sorted matching(3)r)plot(RN1L Sorted matching(4)m)

Appendix A 57

grid ontitle(RN1L)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)

subplot(232)hold onplot(RN2L Sorted matching(1)b)plot(RN2L Sorted matching(2)g)plot(RN2L Sorted matching(3)r)plot(RN2L Sorted matching(4)m)grid ontitle(RN2L)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)

subplot(233)hold onplot(RN3L Sorted matching(1)b)plot(RN3L Sorted matching(2)g)plot(RN3L Sorted matching(3)r)plot(RN3L Sorted matching(4)m)grid ontitle(RN3L)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)

subplot(234)hold onplot(RN1S Sorted matching(1)b)plot(RN1S Sorted matching(2)g)plot(RN1S Sorted matching(3)r)plot(RN1S Sorted matching(4)m)grid ontitle(RN1S)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)

subplot(235)hold onplot(RN2S Sorted matching(1)b)plot(RN2S Sorted matching(2)g)plot(RN2S Sorted matching(3)r)plot(RN2S Sorted matching(4)m)grid ontitle(RN2S)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)

58 Application

subplot(236)hold onplot(RN3S Sorted matching(1)b)plot(RN3S Sorted matching(2)g)plot(RN3S Sorted matching(3)r)plot(RN3S Sorted matching(4)m)grid ontitle(RN3S)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)set(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN4png minusr300)h(5)=figure(NameSorted RatiosNumberTitleoff)RN1L ratio1=RN1L NodesG hatRN1L NodesGRN2L ratio1=RN2L NodesG hatRN2L NodesGRN3L ratio1=RN3L NodesG hatRN3L NodesGRN1S ratio1=RN1S NodesG hatRN1S NodesGRN2S ratio1=RN2S NodesG hatRN2S NodesGRN3S ratio1=RN3S NodesG hatRN3S NodesG

RN1L ratio2=RN1L EdgesG HatRN1L EdgesGRN2L ratio2=RN2L EdgesG HatRN2L EdgesGRN3L ratio2=RN3L EdgesG HatRN3L EdgesGRN1S ratio2=RN1S EdgesG HatRN1S EdgesGRN2S ratio2=RN2S EdgesG HatRN2S EdgesGRN3S ratio2=RN3S EdgesG HatRN3S EdgesG

RN1L ratio3=RN1L MaxDegreeG HatRN1L MaxDegreeGRN2L ratio3=RN2L MaxDegreeG HatRN2L MaxDegreeGRN3L ratio3=RN3L MaxDegreeG HatRN3L MaxDegreeGRN1S ratio3=RN1S MaxDegreeG HatRN1S MaxDegreeGRN2S ratio3=RN2S MaxDegreeG HatRN2S MaxDegreeGRN3S ratio3=RN3S MaxDegreeG HatRN3S MaxDegreeG

RN1L ratio(1)=RN1L ratio1RN1L ratio(2)=RN1L ratio2RN1L ratio(3)=RN1L ratio3

RN2L ratio(1)=RN2L ratio1RN2L ratio(2)=RN2L ratio2RN2L ratio(3)=RN2L ratio3

RN3L ratio(1)=RN3L ratio1RN3L ratio(2)=RN3L ratio2RN3L ratio(3)=RN3L ratio3

RN1S ratio(1)=RN1S ratio1RN1S ratio(2)=RN1S ratio2RN1S ratio(3)=RN1S ratio3

RN2S ratio(1)=RN2S ratio1

Appendix A 59

RN2S ratio(2)=RN2S ratio2RN2S ratio(3)=RN2S ratio3

RN3S ratio(1)=RN3S ratio1RN3S ratio(2)=RN3S ratio2RN3S ratio(3)=RN3S ratio3

RN1L ratio sorted=sortrows(RN1L ratio)RN2L ratio sorted=sortrows(RN2L ratio)RN3L ratio sorted=sortrows(RN3L ratio)RN1S ratio sorted=sortrows(RN1S ratio)RN2S ratio sorted=sortrows(RN2S ratio)RN3S ratio sorted=sortrows(RN3S ratio)

subplot(231)hold onplot(RN1L ratio sorted(1)b)plot(RN1L ratio sorted(2)g)plot(RN1L ratio sorted(3)r)grid ontitle(RN1L)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)

subplot(232)hold onplot(RN2L ratio sorted(1)b)plot(RN2L ratio sorted(2)g)plot(RN2L ratio sorted(3)r)grid ontitle(RN2L)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)

subplot(233)hold onplot(RN3L ratio sorted(1)b)plot(RN3L ratio sorted(2)g)plot(RN3L ratio sorted(3)r)grid ontitle(RN3L)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)

subplot(234)hold onplot(RN1S ratio sorted(1)b)plot(RN1S ratio sorted(2)g)plot(RN1S ratio sorted(3)r)grid on

60 Application

title(RN1S)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)

subplot(235)hold onplot(RN2S ratio sorted(1)b)plot(RN2S ratio sorted(2)g)plot(RN2S ratio sorted(3)r)grid ontitle(RN2S)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)

subplot(236)hold onplot(RN3S ratio sorted(1)b)plot(RN3S ratio sorted(2)g)plot(RN3S ratio sorted(3)r)grid ontitle(RN3S)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)set(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN5png minusr300)

h(6)=figure(NameSorted edges over nodesNumberTitleoff)

RN1L DegreeG1=(RN1L EdgesG)(RN1L NodesG)RN1L DegreeG Hat1=(RN1L EdgesG Hat)(RN1L NodesG hat)

RN1L Degree temp1(1)=RN1L DegreeG1RN1L Degree temp1(2)=RN1L DegreeG Hat1RN1L Degree sorted1=sortrows(RN1L Degree temp1)subplot(231)hold on

plot(RN1L Degree sorted1(1)b)plot(RN1L Degree sorted1(2)g)grid ontitle(RN1L)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)

RN2L DegreeG1=(RN2L EdgesG)(RN2L NodesG)RN2L DegreeG Hat1=(RN2L EdgesG Hat)(RN2L NodesG hat)

RN2L Degree temp1(1)=RN2L DegreeG1

Appendix A 61

RN2L Degree temp1(2)=RN2L DegreeG Hat1RN2L Degree sorted1=sortrows(RN2L Degree temp1)

subplot(232)hold onplot(RN2L Degree sorted1(1)b)plot(RN2L Degree sorted1(2)g)grid ontitle(RN2L)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)

RN3L DegreeG1=(RN3L EdgesG)(RN3L NodesG)RN3L DegreeG Hat1=(RN3L EdgesG Hat)(RN3L NodesG hat)

RN3L Degree temp1(1)=RN3L DegreeG1RN3L Degree temp1(2)=RN3L DegreeG Hat1RN3L Degree sorted1=sortrows(RN3L Degree temp1)

subplot(233)hold onplot(RN3L Degree sorted1(1)b)plot(RN3L Degree sorted1(2)g)grid ontitle(RN3L)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)

RN1S DegreeG1=(RN1S EdgesG)(RN1S NodesG)RN1S DegreeG Hat1=(RN1S EdgesG Hat)(RN1S NodesG hat)

RN1S Degree temp1(1)=RN1S DegreeG1RN1S Degree temp1(2)=RN1S DegreeG Hat1RN1S Degree sorted1=sortrows(RN1S Degree temp1)

subplot(234)hold onplot(RN1S Degree sorted1(1)b)plot(RN1S Degree sorted1(2)g)grid ontitle(RN1S)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)

RN2S DegreeG1=(RN2S EdgesG)(RN2S NodesG)RN2S DegreeG Hat1=(RN2S EdgesG Hat)(RN2S NodesG hat)

RN2S Degree temp1(1)=RN2S DegreeG1

62 Application

RN2S Degree temp1(2)=RN2S DegreeG Hat1RN2S Degree sorted1=sortrows(RN2S Degree temp1)

subplot(235)hold onplot(RN2S Degree sorted1(1)b)plot(RN2S Degree sorted1(2)g)grid ontitle(RN2S)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)

RN3S DegreeG1=(RN3S EdgesG)(RN3S NodesG)RN3S DegreeG Hat1=(RN3S EdgesG Hat)(RN3S NodesG hat)

RN3S Degree temp1(1)=RN3S DegreeG1RN3S Degree temp1(2)=RN3S DegreeG Hat1RN3S Degree sorted1=sortrows(RN3S Degree temp1)

subplot(236)hold onplot(RN3S Degree sorted1(1)b)plot(RN3S Degree sorted1(2)g)grid ontitle(RN3S)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)set(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN6png minusr300)h(7)=figure(NameSorted mATCHED DEGREENumberTitleoff)RN1L ratioMax(1)=RN1L MaxDegreeGRN1L ratioMax(2)=RN1L MaxDegreeG Hat

RN1L ratio sortedMax=sortrows(RN1L ratioMax)subplot(231)hold onplot(RN1L ratio sortedMax(1)b)plot(RN1L ratio sortedMax(2)g)grid ontitle(RN1L)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)

RN2L ratioMax(1)=RN2L MaxDegreeGRN2L ratioMax(2)=RN2L MaxDegreeG Hat

RN2L ratio sortedMax=sortrows(RN2L ratioMax)subplot(232)

Appendix A 63

hold onplot(RN2L ratio sortedMax(1)b)plot(RN2L ratio sortedMax(2)g)grid ontitle(RN2L)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)

RN3L ratioMax(1)=RN3L MaxDegreeGRN3L ratioMax(2)=RN3L MaxDegreeG Hat

RN3L ratio sortedMax=sortrows(RN3L ratioMax)subplot(233)hold onplot(RN3L ratio sortedMax(1)b)plot(RN3L ratio sortedMax(2)g)grid ontitle(RN3L)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)

RN1S ratioMax(1)=RN1S MaxDegreeGRN1S ratioMax(2)=RN1S MaxDegreeG Hat

RN1S ratio sortedMax=sortrows(RN1S ratioMax)subplot(234)hold onplot(RN1S ratio sortedMax(1)b)plot(RN1S ratio sortedMax(2)g)grid ontitle(RN1S)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)

RN2S ratioMax(1)=RN2S MaxDegreeGRN2S ratioMax(2)=RN2S MaxDegreeG Hat

RN2S ratio sortedMax=sortrows(RN2S ratioMax)

subplot(235)hold onplot(RN2S ratio sortedMax(1)b)plot(RN2S ratio sortedMax(2)g)grid ontitle(RN2S)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)

RN3S ratioMax(1)=RN3S MaxDegreeGRN3S ratioMax(2)=RN3S MaxDegreeG Hat

64 Application

RN3S ratio sortedMax=sortrows(RN3S ratioMax)subplot(236)hold onplot(RN3S ratio sortedMax(1)b)plot(RN3S ratio sortedMax(2)g)grid ontitle(RN1L)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)set(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN7png minusr300)

tilefigs()(h)

Bibliography

[1] C Berge ldquoTWO THEOREMS IN GRAPH THEORYrdquo Proceedings of the NationalAcademy of Sciences of the United States of America vol 43 no 9 pp 842ndash844Sep 1957

[2] L Bui S Sanghavi and R Srikant ldquoDistributed link scheduling with constantoverheadrdquo IEEEACM Trans Netw vol 17 no 5 pp 1467ndash1480 2009

[3] R Duan and S Pettie ldquoLinear-time approximation for maximum weight matchingrdquoJ ACM vol 61 no 1 2014

[4] J Edmonds ldquoPaths trees and flowersrdquo Canadian Journal of Mathematics vol 17pp 449ndash467 1965

[5] J E Hopcroft and R M Karp ldquoAn n52 algorithm for maximum matchings inbipartite graphsrdquo SIAM J Comput vol 2 no 4 pp 225ndash231 1973

[6] S Micali and V V Vazirani ldquoAn O(radic|V ||E|) algorithm for finding maximum

matching in general graphsrdquo in 21st Symp on Foundations of Comp Sc (FOCS)IEEE 1980 pp 17ndash27

[7] N Nisse A Salch and V Weber ldquoRecovery of disrupted airline operationsrdquo 2015httphalinriafrSomething

[8] X Wu and R Srikant ldquoRegulated maximal matching A distributed schedulingalgorithm for multi-hop wireless networks with nodeexclusive spectrum sharingrdquo inIEEE Conf on Decision and Control 2005

65

  • Contents
  • Introduction
  • Algorithms
    • Maximum matching
    • k-maximum matching
      • k-matching for Airport Slot assignment
      • The case where k=3
      • The case of Paths
      • The case of the Spider
          • Application
            • Description
            • Reyni Erdos
            • Barabaacutesi Albert
            • Amadeus Graphs
            • Bipartite
            • Bipartite with degree seq
            • Appendix A
              • BipartiteGraphGeneratorpy
              • RandomGraphGeneratorpy
              • kequals3MaximumMatchingpy
              • Plotmat
                  • Bibliography
Page 46: Theodoros Alexandros KARAGKIOULES -  · Introduction This work is the result of a 6 months internship, under the supervision of research O cer Nicolas NISSE. The original scope of

Appendix A 47

tempa=kadj dict2[n]remove(k)adj dict2[tempa]remove(n)adj dict1[tempa]remove(n)

return G

def Greedy(num nodesadj dict3matching dict2)

for n in range(0num nodes)if matching dict2[n]

flag2=minus1flag3=minus1for v in adj dict3[n]

if not matching dict2[v]flag2=vbreak

for p in adj dict3[matching dict2[n][0]]if not matching dict2[p]

flag3=pbreak

if (flag2=minus1) and (flag3=minus1) and (flag2=flag3)tempr=matching dict2[n][0]matching dict2[n]=[flag2]matching dict2[flag2]=[n]matching dict2[tempr]=[flag3]matching dict2[flag3]=[tempr]

elsefor k in adj dict3[n]

if not matching dict2[k]matching dict2[n]=[k]matching dict2[k]=[n]break

yo1=0for i in range(0num nodes)

if matching dict2[i] and [i]==matching dict2[matching dict2[i][0]]yo1=yo1+1

greedy size=yo12return greedy size

def General()

INPUTSwb = xlwtWorkbook()ws = wbadd sheet(Results Random)book=xlrdopen workbook(filenames randomxls)

48 Application

style0 = xlwteasyxf(fontbold on)style1 = xlwteasyxf(num format str=0000)INPUTSwswrite(0 0File style0)wswrite(0 1 Nodesstyle0)wswrite(0 2 Initial matchingstyle0)wswrite(0 3 NodesGstyle0)wswrite(0 4 EdgesGstyle0)wswrite(0 5 MaxDegreeGstyle0)wswrite(0 6 NodesG hatstyle0)wswrite(0 7 EdgesG Hatstyle0)wswrite(0 8 Useless edgesstyle0)wswrite(0 9 Forced edgesstyle0)wswrite(0 10 MaxDegreeG Hatstyle0)wswrite(0 11 Classical matchingstyle0)wswrite(0 12 Final matchingstyle0)wswrite(0 13 Greedy matchingstyle0)wswrite(0 14 Time classicalstyle0)wswrite(0 15 Time algorithmstyle0)wswrite(0 16 Time greedystyle0)wswrite(0 17 Perfect matching ratiostyle0)wswrite(0 18 Nodes ratiostyle0)wswrite(0 19 Edges ratiostyle0)wswrite(0 20 Matching ratiostyle0)

print nWelcomeThis is an implementation for general random graphs It uses Edmonds algorithm to compute maximum matching on G Hatn

for index in range (1481)was 481

if (index==482)f=open(Algotel generaltxtr)readlines()

elsefilea=str(booksheet by index(0)cell(index0))s=fileareplace(textu)replace()f=open(sr)readlines()Truewswrite(index 0 s)

print index

num nodes=int([xstrip()split() for x in f][0][0])

num matching=int([xstrip()split() for x in f][2][0])

adj temp = [xstrip()split() for x in f][44+num nodes]adj=[map(intR) for R in adj temp]

matching temp=[xstrip()split() for x in f][4+num nodes+14+2num nodes+1]matching1=[map(intR) for R in matching temp]

adj dict1=i[ii for iix in enumerate(L) if x] for iL in enumerate(adj)adj dict2=i[ii for iix in enumerate(L) if x] for iL in enumerate(adj)

Appendix A 49

adj dict3=i[ii for iix in enumerate(L) if x] for iL in enumerate(adj)

matching dict1=i[ii for iix in enumerate(L) if x] for iL in enumerate(matching1)matching dict2=i[ii for iix in enumerate(L) if x] for iL in enumerate(matching1)print adj dict2print matching dict2wswrite(index 1 num nodes)wswrite(index 2 num matching)

G = nxGraph()

useless= nxGraph()forced = nxGraph()

Fill Graphfor n in range(0num nodes)

for k in adj dict1[n]Gadd edge(nk)

Gt=Gnumber of edges()wswrite(index 3 Gnumber of nodes())wswrite(index 4 Gnumber of edges())wswrite(index 5 max(Gdegree()values()))

Compute Edmonds classical matching on G for comparison

startB = timeitdefault timer()Classical Matching=nxmax weight matching(G maxcardinality=False)stopB = timeitdefault timer()

Compute Gˆ nad MˆstartC = timeitdefault timer()useless edges(num nodesadj dict1matching dict1uselessadj dict2G)forced edges(Gadj dict2matching dict1num nodesforced)Final Matching=nxmax weight matching(G maxcardinality=False)stopC = timeitdefault timer()

GreedystartG = timeitdefault timer()greedy size=Greedy(num nodesadj dict3matching dict2)stopG = timeitdefault timer()

wswrite(index 6 Gnumber of nodes())wswrite(index 7 Gnumber of edges())wswrite(index 8 uselessnumber of edges())wswrite(index 9 forcednumber of edges())if Gdegree()values()

wswrite(index 10 max(Gdegree()values()))else

50 Application

wswrite(index 10 0)wswrite(index 11 len(Classical Matching)2)wswrite(index 12 len(Final Matching)2+forcednumber of edges())wswrite(index 13 greedy size)wswrite(index 14 stopB minus startBstyle1)wswrite(index 15 stopC minus startCstyle1)wswrite(index 16 stopG minus startGstyle1)wswrite(index 17 (len(Final Matching)2+forcednumber of edges())(num nodes2)style1)wswrite(index 18 Gnumber of nodes()Gtstyle1)wswrite(index 19 Gnumber of edges()Gtstyle1)wswrite(index 20 (len(Final Matching)2+forcednumber of edges())(len(Classical Matching)2)style1)

wbsave(AA Results Random Reyni Large Bipartitexls)

Main function Here we must choose the input form of the dataif name == main

startA = timeitdefault timer()General()stopA = timeitdefault timer()

print nThis program has terminatednnRunning time for 480 files stopAminusstartAprint nnPlease open AA Results Random Reyni Largexls file to see the Results

Appendix A 51

Plotmat

clear allclose allload(RN1Lmat)load(RN1Smat)load(RN2Lmat)load(RN2Smat)load(RN3Lmat)load(RN3Smat)

Plotsh(1)=figure(NameHistogram of Matching size difference between Constraint Algorithm and Greedy AlgorithmNumberTitleoff)

RN1L Greedydiff=RN1L Final matchingminusRN1L Greedy matchingRN2L Greedydiff=RN2L Final matchingminusRN2L Greedy matchingRN3L Greedydiff=RN3L Final matchingminusRN3L Greedy matchingRN1S Greedydiff=RN1S Final matchingminusRN1S Greedy matchingRN2S Greedydiff=RN2S Final matchingminusRN2S Greedy matchingRN3S Greedydiff=RN3S Final matchingminusRN3S Greedy matching

RN1L Finaldiff=RN1L Classical matchingminusRN1L Final matchingRN2L Finaldiff=RN2L Classical matchingminusRN2L Final matchingRN3L Finaldiff=RN3L Classical matchingminusRN3L Final matchingRN1S Finaldiff=RN1S Classical matchingminusRN1S Final matchingRN2S Finaldiff=RN2S Classical matchingminusRN2S Final matchingRN3S Finaldiff=RN3S Classical matchingminusRN3S Final matching

RN1L Classicaldiff=(RN1L Nodes2)minusRN1L Classical matchingRN2L Classicaldiff=(RN2L Nodes2)minusRN2L Classical matchingRN3L Classicaldiff=(RN3L Nodes2)minusRN3L Classical matchingRN1S Classicaldiff=(RN1S Nodes2)minusRN1S Classical matchingRN2S Classicaldiff=(RN2S Nodes2)minusRN2S Classical matchingRN3S Classicaldiff=(RN3S Nodes2)minusRN3S Classical matching

subplot(231)hold onhistf(RN1L Greedydiff0110facecolorbfacealpha9edgealpha1)histf(RN1L Finaldiff0110facecolorrfacealpha5edgealpha1)histf(RN1L Classicaldiff0110facecolorgfacealpha5edgealpha1)legalpha(ConminusGreClasminusConPerfminusClasslocationnortheast)legend boxoffaxis tightxlabel(edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN1L)grid on

subplot(232)hold onhistf(RN2L Greedydiff0110facecolorbfacealpha9edgealpha1)

52 Application

histf(RN2L Finaldiff0110facecolorrfacealpha5edgealpha1)histf(RN2L Classicaldiff0110facecolorgfacealpha5edgealpha1)legalpha(ConminusGreClasminusConPerfminusClasslocationnortheast)legend boxoffaxis tightxlabel(edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN2L)grid on

subplot(233)hold onhistf(RN3L Greedydiff0110facecolorbfacealpha5edgealpha1)histf(RN3L Finaldiff0110facecolorrfacealpha5edgealpha1)histf(RN3L Classicaldiff0110facecolorgfacealpha5edgealpha1)legalpha(ConminusGreClasminusConPerfminusClasslocationnortheast)legend boxoffaxis tightxlabel(edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN3L)grid on

subplot(234)hold onhistf(RN1S Greedydiff0110facecolorbfacealpha5edgealpha1)histf(RN1S Finaldiff0110facecolorrfacealpha5edgealpha1)histf(RN1S Classicaldiff0110facecolorgfacealpha5edgealpha1)legalpha(ConminusGreClasminusConPerfminusClasslocationnortheast)legend boxoffaxis tightxlabel(edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(R1NS)grid on

subplot(235)hold onhistf(RN2S Greedydiff0110facecolorbfacealpha5edgealpha1)histf(RN2S Finaldiff0110facecolorrfacealpha5edgealpha1)histf(RN2S Classicaldiff0110facecolorgfacealpha5edgealpha1)legalpha(ConminusGreClasminusConPerfminusClasslocationnortheast)legend boxoffaxis tightxlabel(edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN2S)grid on

subplot(236)hold onhistf(RN3S Greedydiff0110facecolorbfacealpha5edgealpha1)histf(RN3S Finaldiff0110facecolorrfacealpha5edgealpha1)histf(RN3S Classicaldiff0110facecolorgfacealpha5edgealpha1)

Appendix A 53

legalpha(ConminusGreClasminusConPerfminusClasslocationnortheast)legend boxoffaxis tightgrid ontitle(RN3S)xlabel(edges) xminusaxis labelylabel(instances) yminusaxis labelset(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN1png minusr300)h(2)=figure(NameHistogram of Max Degree of G AND G HatNumberTitleoff)RN1L x=RN1L MaxDegreeGminusRN1L MaxDegreeG HatRN2L x=RN2L MaxDegreeGminusRN2L MaxDegreeG HatRN3L x=RN3L MaxDegreeGminusRN3L MaxDegreeG HatRN1S x=RN1S MaxDegreeGminusRN1S MaxDegreeG HatRN2S x=RN2S MaxDegreeGminusRN2S MaxDegreeG HatRN3S x=RN3S MaxDegreeGminusRN3S MaxDegreeG Hatsubplot(231)hold onhistf(RN1L MaxDegreeG0150facecolorbfacealpha5edgealpha1)histf(RN1L MaxDegreeG Hat0150facecolorrfacealpha5edgealpha1)histf(RN1L x0150facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightxlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN1L)grid on

subplot(232)hold onhistf(RN2L MaxDegreeG010500facecolorbfacealpha5edgealpha1)histf(RN2L MaxDegreeG Hat010500facecolorrfacealpha5edgealpha1)histf(RN2L x010500facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightxlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN2L)grid on

subplot(233)hold onhistf(RN3L MaxDegreeG010300facecolorbfacealpha5edgealpha1)histf(RN3L MaxDegreeG Hat010300facecolorrfacealpha5edgealpha1)histf(RN3L x010300facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightxlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN3L)

54 Application

grid on

subplot(234)hold onhistf(RN1S MaxDegreeG0150facecolorbfacealpha5edgealpha1)histf(RN1S MaxDegreeG Hat0150facecolorrfacealpha5edgealpha1)histf(RN1S x0150facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightxlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(R1NS)grid on

subplot(235)hold onhistf(RN2S MaxDegreeG010500facecolorbfacealpha5edgealpha1)histf(RN2S MaxDegreeG Hat010500facecolorrfacealpha5edgealpha1)histf(RN2S x010500facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightxlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN2S)grid on

subplot(236)hold onhistf(RN3S MaxDegreeG05300facecolorbfacealpha5edgealpha1)histf(RN3S MaxDegreeG Hat05300facecolorrfacealpha5edgealpha1)histf(RN3S x05300facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightgrid ontitle(RN3S)xlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labelset(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN2png minusr300)

h(3)=figure(NameComputation time over edgesNumberTitleoff)

subplot(231)hold onstem(RN1L EdgesGRN1L Time classicalg)stem(RN1L EdgesGRN1L Time algorithmro)stem(RN1L EdgesGRN1L Time greedybx)grid on

Appendix A 55

title(RN1L)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)

subplot(232)hold onstem(RN2L EdgesGRN2L Time classicalg)stem(RN2L EdgesGRN2L Time algorithmro)stem(RN2L EdgesGRN2L Time greedybx)grid ontitle(RN2L)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)

subplot(233)hold onstem(RN3L EdgesGRN3L Time classicalg)stem(RN3L EdgesGRN3L Time algorithmro)stem(RN3L EdgesGRN3L Time greedybx)grid ontitle(RN3L)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)

subplot(234)hold onstem(RN1S EdgesGRN1S Time classicalg)stem(RN1S EdgesGRN1S Time algorithmro)stem(RN1S EdgesGRN1S Time greedybx)grid ontitle(RN1S)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)

subplot(235)hold onstem(RN2S EdgesGRN2S Time classicalg)stem(RN2S EdgesGRN2S Time algorithmro)stem(RN2S EdgesGRN2S Time greedybx)grid ontitle(RN2S)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)

subplot(236)hold onstem(RN3S EdgesGRN3S Time classicalg)stem(RN3S EdgesGRN3S Time algorithmro)stem(RN3S EdgesGRN3S Time greedybx)

56 Application

grid ontitle(RN3S)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)set(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN3png minusr300)

h(4)=figure(NameSorted matching sizeNumberTitleoff)RN1L Sorted matching temp(1)=RN1L Classical matchingRN1L Sorted matching temp(2)=RN1L Final matchingRN1L Sorted matching temp(3)=RN1L Greedy matchingRN1L Sorted matching temp(4)=RN1L Initial matchingRN1L Sorted matching=sortrows(RN1L Sorted matching temp)

RN2L Sorted matching temp(1)=RN2L Classical matchingRN2L Sorted matching temp(2)=RN2L Final matchingRN2L Sorted matching temp(3)=RN2L Greedy matchingRN2L Sorted matching temp(4)=RN2L Initial matchingRN2L Sorted matching=sortrows(RN2L Sorted matching temp)

RN3L Sorted matching temp(1)=RN3L Classical matchingRN3L Sorted matching temp(2)=RN3L Final matchingRN3L Sorted matching temp(3)=RN3L Greedy matchingRN3L Sorted matching temp(4)=RN3L Initial matchingRN3L Sorted matching=sortrows(RN3L Sorted matching temp)

RN1S Sorted matching temp(1)=RN1S Classical matchingRN1S Sorted matching temp(2)=RN1S Final matchingRN1S Sorted matching temp(3)=RN1S Greedy matchingRN1S Sorted matching temp(4)=RN1S Initial matchingRN1S Sorted matching=sortrows(RN1S Sorted matching temp)

RN2S Sorted matching temp(1)=RN2S Classical matchingRN2S Sorted matching temp(2)=RN2S Final matchingRN2S Sorted matching temp(3)=RN2S Greedy matchingRN2S Sorted matching temp(4)=RN2S Initial matchingRN2S Sorted matching=sortrows(RN2S Sorted matching temp)

RN3S Sorted matching temp(1)=RN3S Classical matchingRN3S Sorted matching temp(2)=RN3S Final matchingRN3S Sorted matching temp(3)=RN3S Greedy matchingRN3S Sorted matching temp(4)=RN3S Initial matchingRN3S Sorted matching=sortrows(RN3S Sorted matching temp)

subplot(231)hold onplot(RN1L Sorted matching(1)b)plot(RN1L Sorted matching(2)g)plot(RN1L Sorted matching(3)r)plot(RN1L Sorted matching(4)m)

Appendix A 57

grid ontitle(RN1L)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)

subplot(232)hold onplot(RN2L Sorted matching(1)b)plot(RN2L Sorted matching(2)g)plot(RN2L Sorted matching(3)r)plot(RN2L Sorted matching(4)m)grid ontitle(RN2L)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)

subplot(233)hold onplot(RN3L Sorted matching(1)b)plot(RN3L Sorted matching(2)g)plot(RN3L Sorted matching(3)r)plot(RN3L Sorted matching(4)m)grid ontitle(RN3L)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)

subplot(234)hold onplot(RN1S Sorted matching(1)b)plot(RN1S Sorted matching(2)g)plot(RN1S Sorted matching(3)r)plot(RN1S Sorted matching(4)m)grid ontitle(RN1S)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)

subplot(235)hold onplot(RN2S Sorted matching(1)b)plot(RN2S Sorted matching(2)g)plot(RN2S Sorted matching(3)r)plot(RN2S Sorted matching(4)m)grid ontitle(RN2S)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)

58 Application

subplot(236)hold onplot(RN3S Sorted matching(1)b)plot(RN3S Sorted matching(2)g)plot(RN3S Sorted matching(3)r)plot(RN3S Sorted matching(4)m)grid ontitle(RN3S)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)set(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN4png minusr300)h(5)=figure(NameSorted RatiosNumberTitleoff)RN1L ratio1=RN1L NodesG hatRN1L NodesGRN2L ratio1=RN2L NodesG hatRN2L NodesGRN3L ratio1=RN3L NodesG hatRN3L NodesGRN1S ratio1=RN1S NodesG hatRN1S NodesGRN2S ratio1=RN2S NodesG hatRN2S NodesGRN3S ratio1=RN3S NodesG hatRN3S NodesG

RN1L ratio2=RN1L EdgesG HatRN1L EdgesGRN2L ratio2=RN2L EdgesG HatRN2L EdgesGRN3L ratio2=RN3L EdgesG HatRN3L EdgesGRN1S ratio2=RN1S EdgesG HatRN1S EdgesGRN2S ratio2=RN2S EdgesG HatRN2S EdgesGRN3S ratio2=RN3S EdgesG HatRN3S EdgesG

RN1L ratio3=RN1L MaxDegreeG HatRN1L MaxDegreeGRN2L ratio3=RN2L MaxDegreeG HatRN2L MaxDegreeGRN3L ratio3=RN3L MaxDegreeG HatRN3L MaxDegreeGRN1S ratio3=RN1S MaxDegreeG HatRN1S MaxDegreeGRN2S ratio3=RN2S MaxDegreeG HatRN2S MaxDegreeGRN3S ratio3=RN3S MaxDegreeG HatRN3S MaxDegreeG

RN1L ratio(1)=RN1L ratio1RN1L ratio(2)=RN1L ratio2RN1L ratio(3)=RN1L ratio3

RN2L ratio(1)=RN2L ratio1RN2L ratio(2)=RN2L ratio2RN2L ratio(3)=RN2L ratio3

RN3L ratio(1)=RN3L ratio1RN3L ratio(2)=RN3L ratio2RN3L ratio(3)=RN3L ratio3

RN1S ratio(1)=RN1S ratio1RN1S ratio(2)=RN1S ratio2RN1S ratio(3)=RN1S ratio3

RN2S ratio(1)=RN2S ratio1

Appendix A 59

RN2S ratio(2)=RN2S ratio2RN2S ratio(3)=RN2S ratio3

RN3S ratio(1)=RN3S ratio1RN3S ratio(2)=RN3S ratio2RN3S ratio(3)=RN3S ratio3

RN1L ratio sorted=sortrows(RN1L ratio)RN2L ratio sorted=sortrows(RN2L ratio)RN3L ratio sorted=sortrows(RN3L ratio)RN1S ratio sorted=sortrows(RN1S ratio)RN2S ratio sorted=sortrows(RN2S ratio)RN3S ratio sorted=sortrows(RN3S ratio)

subplot(231)hold onplot(RN1L ratio sorted(1)b)plot(RN1L ratio sorted(2)g)plot(RN1L ratio sorted(3)r)grid ontitle(RN1L)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)

subplot(232)hold onplot(RN2L ratio sorted(1)b)plot(RN2L ratio sorted(2)g)plot(RN2L ratio sorted(3)r)grid ontitle(RN2L)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)

subplot(233)hold onplot(RN3L ratio sorted(1)b)plot(RN3L ratio sorted(2)g)plot(RN3L ratio sorted(3)r)grid ontitle(RN3L)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)

subplot(234)hold onplot(RN1S ratio sorted(1)b)plot(RN1S ratio sorted(2)g)plot(RN1S ratio sorted(3)r)grid on

60 Application

title(RN1S)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)

subplot(235)hold onplot(RN2S ratio sorted(1)b)plot(RN2S ratio sorted(2)g)plot(RN2S ratio sorted(3)r)grid ontitle(RN2S)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)

subplot(236)hold onplot(RN3S ratio sorted(1)b)plot(RN3S ratio sorted(2)g)plot(RN3S ratio sorted(3)r)grid ontitle(RN3S)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)set(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN5png minusr300)

h(6)=figure(NameSorted edges over nodesNumberTitleoff)

RN1L DegreeG1=(RN1L EdgesG)(RN1L NodesG)RN1L DegreeG Hat1=(RN1L EdgesG Hat)(RN1L NodesG hat)

RN1L Degree temp1(1)=RN1L DegreeG1RN1L Degree temp1(2)=RN1L DegreeG Hat1RN1L Degree sorted1=sortrows(RN1L Degree temp1)subplot(231)hold on

plot(RN1L Degree sorted1(1)b)plot(RN1L Degree sorted1(2)g)grid ontitle(RN1L)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)

RN2L DegreeG1=(RN2L EdgesG)(RN2L NodesG)RN2L DegreeG Hat1=(RN2L EdgesG Hat)(RN2L NodesG hat)

RN2L Degree temp1(1)=RN2L DegreeG1

Appendix A 61

RN2L Degree temp1(2)=RN2L DegreeG Hat1RN2L Degree sorted1=sortrows(RN2L Degree temp1)

subplot(232)hold onplot(RN2L Degree sorted1(1)b)plot(RN2L Degree sorted1(2)g)grid ontitle(RN2L)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)

RN3L DegreeG1=(RN3L EdgesG)(RN3L NodesG)RN3L DegreeG Hat1=(RN3L EdgesG Hat)(RN3L NodesG hat)

RN3L Degree temp1(1)=RN3L DegreeG1RN3L Degree temp1(2)=RN3L DegreeG Hat1RN3L Degree sorted1=sortrows(RN3L Degree temp1)

subplot(233)hold onplot(RN3L Degree sorted1(1)b)plot(RN3L Degree sorted1(2)g)grid ontitle(RN3L)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)

RN1S DegreeG1=(RN1S EdgesG)(RN1S NodesG)RN1S DegreeG Hat1=(RN1S EdgesG Hat)(RN1S NodesG hat)

RN1S Degree temp1(1)=RN1S DegreeG1RN1S Degree temp1(2)=RN1S DegreeG Hat1RN1S Degree sorted1=sortrows(RN1S Degree temp1)

subplot(234)hold onplot(RN1S Degree sorted1(1)b)plot(RN1S Degree sorted1(2)g)grid ontitle(RN1S)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)

RN2S DegreeG1=(RN2S EdgesG)(RN2S NodesG)RN2S DegreeG Hat1=(RN2S EdgesG Hat)(RN2S NodesG hat)

RN2S Degree temp1(1)=RN2S DegreeG1

62 Application

RN2S Degree temp1(2)=RN2S DegreeG Hat1RN2S Degree sorted1=sortrows(RN2S Degree temp1)

subplot(235)hold onplot(RN2S Degree sorted1(1)b)plot(RN2S Degree sorted1(2)g)grid ontitle(RN2S)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)

RN3S DegreeG1=(RN3S EdgesG)(RN3S NodesG)RN3S DegreeG Hat1=(RN3S EdgesG Hat)(RN3S NodesG hat)

RN3S Degree temp1(1)=RN3S DegreeG1RN3S Degree temp1(2)=RN3S DegreeG Hat1RN3S Degree sorted1=sortrows(RN3S Degree temp1)

subplot(236)hold onplot(RN3S Degree sorted1(1)b)plot(RN3S Degree sorted1(2)g)grid ontitle(RN3S)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)set(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN6png minusr300)h(7)=figure(NameSorted mATCHED DEGREENumberTitleoff)RN1L ratioMax(1)=RN1L MaxDegreeGRN1L ratioMax(2)=RN1L MaxDegreeG Hat

RN1L ratio sortedMax=sortrows(RN1L ratioMax)subplot(231)hold onplot(RN1L ratio sortedMax(1)b)plot(RN1L ratio sortedMax(2)g)grid ontitle(RN1L)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)

RN2L ratioMax(1)=RN2L MaxDegreeGRN2L ratioMax(2)=RN2L MaxDegreeG Hat

RN2L ratio sortedMax=sortrows(RN2L ratioMax)subplot(232)

Appendix A 63

hold onplot(RN2L ratio sortedMax(1)b)plot(RN2L ratio sortedMax(2)g)grid ontitle(RN2L)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)

RN3L ratioMax(1)=RN3L MaxDegreeGRN3L ratioMax(2)=RN3L MaxDegreeG Hat

RN3L ratio sortedMax=sortrows(RN3L ratioMax)subplot(233)hold onplot(RN3L ratio sortedMax(1)b)plot(RN3L ratio sortedMax(2)g)grid ontitle(RN3L)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)

RN1S ratioMax(1)=RN1S MaxDegreeGRN1S ratioMax(2)=RN1S MaxDegreeG Hat

RN1S ratio sortedMax=sortrows(RN1S ratioMax)subplot(234)hold onplot(RN1S ratio sortedMax(1)b)plot(RN1S ratio sortedMax(2)g)grid ontitle(RN1S)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)

RN2S ratioMax(1)=RN2S MaxDegreeGRN2S ratioMax(2)=RN2S MaxDegreeG Hat

RN2S ratio sortedMax=sortrows(RN2S ratioMax)

subplot(235)hold onplot(RN2S ratio sortedMax(1)b)plot(RN2S ratio sortedMax(2)g)grid ontitle(RN2S)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)

RN3S ratioMax(1)=RN3S MaxDegreeGRN3S ratioMax(2)=RN3S MaxDegreeG Hat

64 Application

RN3S ratio sortedMax=sortrows(RN3S ratioMax)subplot(236)hold onplot(RN3S ratio sortedMax(1)b)plot(RN3S ratio sortedMax(2)g)grid ontitle(RN1L)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)set(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN7png minusr300)

tilefigs()(h)

Bibliography

[1] C Berge ldquoTWO THEOREMS IN GRAPH THEORYrdquo Proceedings of the NationalAcademy of Sciences of the United States of America vol 43 no 9 pp 842ndash844Sep 1957

[2] L Bui S Sanghavi and R Srikant ldquoDistributed link scheduling with constantoverheadrdquo IEEEACM Trans Netw vol 17 no 5 pp 1467ndash1480 2009

[3] R Duan and S Pettie ldquoLinear-time approximation for maximum weight matchingrdquoJ ACM vol 61 no 1 2014

[4] J Edmonds ldquoPaths trees and flowersrdquo Canadian Journal of Mathematics vol 17pp 449ndash467 1965

[5] J E Hopcroft and R M Karp ldquoAn n52 algorithm for maximum matchings inbipartite graphsrdquo SIAM J Comput vol 2 no 4 pp 225ndash231 1973

[6] S Micali and V V Vazirani ldquoAn O(radic|V ||E|) algorithm for finding maximum

matching in general graphsrdquo in 21st Symp on Foundations of Comp Sc (FOCS)IEEE 1980 pp 17ndash27

[7] N Nisse A Salch and V Weber ldquoRecovery of disrupted airline operationsrdquo 2015httphalinriafrSomething

[8] X Wu and R Srikant ldquoRegulated maximal matching A distributed schedulingalgorithm for multi-hop wireless networks with nodeexclusive spectrum sharingrdquo inIEEE Conf on Decision and Control 2005

65

  • Contents
  • Introduction
  • Algorithms
    • Maximum matching
    • k-maximum matching
      • k-matching for Airport Slot assignment
      • The case where k=3
      • The case of Paths
      • The case of the Spider
          • Application
            • Description
            • Reyni Erdos
            • Barabaacutesi Albert
            • Amadeus Graphs
            • Bipartite
            • Bipartite with degree seq
            • Appendix A
              • BipartiteGraphGeneratorpy
              • RandomGraphGeneratorpy
              • kequals3MaximumMatchingpy
              • Plotmat
                  • Bibliography
Page 47: Theodoros Alexandros KARAGKIOULES -  · Introduction This work is the result of a 6 months internship, under the supervision of research O cer Nicolas NISSE. The original scope of

48 Application

style0 = xlwteasyxf(fontbold on)style1 = xlwteasyxf(num format str=0000)INPUTSwswrite(0 0File style0)wswrite(0 1 Nodesstyle0)wswrite(0 2 Initial matchingstyle0)wswrite(0 3 NodesGstyle0)wswrite(0 4 EdgesGstyle0)wswrite(0 5 MaxDegreeGstyle0)wswrite(0 6 NodesG hatstyle0)wswrite(0 7 EdgesG Hatstyle0)wswrite(0 8 Useless edgesstyle0)wswrite(0 9 Forced edgesstyle0)wswrite(0 10 MaxDegreeG Hatstyle0)wswrite(0 11 Classical matchingstyle0)wswrite(0 12 Final matchingstyle0)wswrite(0 13 Greedy matchingstyle0)wswrite(0 14 Time classicalstyle0)wswrite(0 15 Time algorithmstyle0)wswrite(0 16 Time greedystyle0)wswrite(0 17 Perfect matching ratiostyle0)wswrite(0 18 Nodes ratiostyle0)wswrite(0 19 Edges ratiostyle0)wswrite(0 20 Matching ratiostyle0)

print nWelcomeThis is an implementation for general random graphs It uses Edmonds algorithm to compute maximum matching on G Hatn

for index in range (1481)was 481

if (index==482)f=open(Algotel generaltxtr)readlines()

elsefilea=str(booksheet by index(0)cell(index0))s=fileareplace(textu)replace()f=open(sr)readlines()Truewswrite(index 0 s)

print index

num nodes=int([xstrip()split() for x in f][0][0])

num matching=int([xstrip()split() for x in f][2][0])

adj temp = [xstrip()split() for x in f][44+num nodes]adj=[map(intR) for R in adj temp]

matching temp=[xstrip()split() for x in f][4+num nodes+14+2num nodes+1]matching1=[map(intR) for R in matching temp]

adj dict1=i[ii for iix in enumerate(L) if x] for iL in enumerate(adj)adj dict2=i[ii for iix in enumerate(L) if x] for iL in enumerate(adj)

Appendix A 49

adj dict3=i[ii for iix in enumerate(L) if x] for iL in enumerate(adj)

matching dict1=i[ii for iix in enumerate(L) if x] for iL in enumerate(matching1)matching dict2=i[ii for iix in enumerate(L) if x] for iL in enumerate(matching1)print adj dict2print matching dict2wswrite(index 1 num nodes)wswrite(index 2 num matching)

G = nxGraph()

useless= nxGraph()forced = nxGraph()

Fill Graphfor n in range(0num nodes)

for k in adj dict1[n]Gadd edge(nk)

Gt=Gnumber of edges()wswrite(index 3 Gnumber of nodes())wswrite(index 4 Gnumber of edges())wswrite(index 5 max(Gdegree()values()))

Compute Edmonds classical matching on G for comparison

startB = timeitdefault timer()Classical Matching=nxmax weight matching(G maxcardinality=False)stopB = timeitdefault timer()

Compute Gˆ nad MˆstartC = timeitdefault timer()useless edges(num nodesadj dict1matching dict1uselessadj dict2G)forced edges(Gadj dict2matching dict1num nodesforced)Final Matching=nxmax weight matching(G maxcardinality=False)stopC = timeitdefault timer()

GreedystartG = timeitdefault timer()greedy size=Greedy(num nodesadj dict3matching dict2)stopG = timeitdefault timer()

wswrite(index 6 Gnumber of nodes())wswrite(index 7 Gnumber of edges())wswrite(index 8 uselessnumber of edges())wswrite(index 9 forcednumber of edges())if Gdegree()values()

wswrite(index 10 max(Gdegree()values()))else

50 Application

wswrite(index 10 0)wswrite(index 11 len(Classical Matching)2)wswrite(index 12 len(Final Matching)2+forcednumber of edges())wswrite(index 13 greedy size)wswrite(index 14 stopB minus startBstyle1)wswrite(index 15 stopC minus startCstyle1)wswrite(index 16 stopG minus startGstyle1)wswrite(index 17 (len(Final Matching)2+forcednumber of edges())(num nodes2)style1)wswrite(index 18 Gnumber of nodes()Gtstyle1)wswrite(index 19 Gnumber of edges()Gtstyle1)wswrite(index 20 (len(Final Matching)2+forcednumber of edges())(len(Classical Matching)2)style1)

wbsave(AA Results Random Reyni Large Bipartitexls)

Main function Here we must choose the input form of the dataif name == main

startA = timeitdefault timer()General()stopA = timeitdefault timer()

print nThis program has terminatednnRunning time for 480 files stopAminusstartAprint nnPlease open AA Results Random Reyni Largexls file to see the Results

Appendix A 51

Plotmat

clear allclose allload(RN1Lmat)load(RN1Smat)load(RN2Lmat)load(RN2Smat)load(RN3Lmat)load(RN3Smat)

Plotsh(1)=figure(NameHistogram of Matching size difference between Constraint Algorithm and Greedy AlgorithmNumberTitleoff)

RN1L Greedydiff=RN1L Final matchingminusRN1L Greedy matchingRN2L Greedydiff=RN2L Final matchingminusRN2L Greedy matchingRN3L Greedydiff=RN3L Final matchingminusRN3L Greedy matchingRN1S Greedydiff=RN1S Final matchingminusRN1S Greedy matchingRN2S Greedydiff=RN2S Final matchingminusRN2S Greedy matchingRN3S Greedydiff=RN3S Final matchingminusRN3S Greedy matching

RN1L Finaldiff=RN1L Classical matchingminusRN1L Final matchingRN2L Finaldiff=RN2L Classical matchingminusRN2L Final matchingRN3L Finaldiff=RN3L Classical matchingminusRN3L Final matchingRN1S Finaldiff=RN1S Classical matchingminusRN1S Final matchingRN2S Finaldiff=RN2S Classical matchingminusRN2S Final matchingRN3S Finaldiff=RN3S Classical matchingminusRN3S Final matching

RN1L Classicaldiff=(RN1L Nodes2)minusRN1L Classical matchingRN2L Classicaldiff=(RN2L Nodes2)minusRN2L Classical matchingRN3L Classicaldiff=(RN3L Nodes2)minusRN3L Classical matchingRN1S Classicaldiff=(RN1S Nodes2)minusRN1S Classical matchingRN2S Classicaldiff=(RN2S Nodes2)minusRN2S Classical matchingRN3S Classicaldiff=(RN3S Nodes2)minusRN3S Classical matching

subplot(231)hold onhistf(RN1L Greedydiff0110facecolorbfacealpha9edgealpha1)histf(RN1L Finaldiff0110facecolorrfacealpha5edgealpha1)histf(RN1L Classicaldiff0110facecolorgfacealpha5edgealpha1)legalpha(ConminusGreClasminusConPerfminusClasslocationnortheast)legend boxoffaxis tightxlabel(edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN1L)grid on

subplot(232)hold onhistf(RN2L Greedydiff0110facecolorbfacealpha9edgealpha1)

52 Application

histf(RN2L Finaldiff0110facecolorrfacealpha5edgealpha1)histf(RN2L Classicaldiff0110facecolorgfacealpha5edgealpha1)legalpha(ConminusGreClasminusConPerfminusClasslocationnortheast)legend boxoffaxis tightxlabel(edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN2L)grid on

subplot(233)hold onhistf(RN3L Greedydiff0110facecolorbfacealpha5edgealpha1)histf(RN3L Finaldiff0110facecolorrfacealpha5edgealpha1)histf(RN3L Classicaldiff0110facecolorgfacealpha5edgealpha1)legalpha(ConminusGreClasminusConPerfminusClasslocationnortheast)legend boxoffaxis tightxlabel(edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN3L)grid on

subplot(234)hold onhistf(RN1S Greedydiff0110facecolorbfacealpha5edgealpha1)histf(RN1S Finaldiff0110facecolorrfacealpha5edgealpha1)histf(RN1S Classicaldiff0110facecolorgfacealpha5edgealpha1)legalpha(ConminusGreClasminusConPerfminusClasslocationnortheast)legend boxoffaxis tightxlabel(edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(R1NS)grid on

subplot(235)hold onhistf(RN2S Greedydiff0110facecolorbfacealpha5edgealpha1)histf(RN2S Finaldiff0110facecolorrfacealpha5edgealpha1)histf(RN2S Classicaldiff0110facecolorgfacealpha5edgealpha1)legalpha(ConminusGreClasminusConPerfminusClasslocationnortheast)legend boxoffaxis tightxlabel(edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN2S)grid on

subplot(236)hold onhistf(RN3S Greedydiff0110facecolorbfacealpha5edgealpha1)histf(RN3S Finaldiff0110facecolorrfacealpha5edgealpha1)histf(RN3S Classicaldiff0110facecolorgfacealpha5edgealpha1)

Appendix A 53

legalpha(ConminusGreClasminusConPerfminusClasslocationnortheast)legend boxoffaxis tightgrid ontitle(RN3S)xlabel(edges) xminusaxis labelylabel(instances) yminusaxis labelset(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN1png minusr300)h(2)=figure(NameHistogram of Max Degree of G AND G HatNumberTitleoff)RN1L x=RN1L MaxDegreeGminusRN1L MaxDegreeG HatRN2L x=RN2L MaxDegreeGminusRN2L MaxDegreeG HatRN3L x=RN3L MaxDegreeGminusRN3L MaxDegreeG HatRN1S x=RN1S MaxDegreeGminusRN1S MaxDegreeG HatRN2S x=RN2S MaxDegreeGminusRN2S MaxDegreeG HatRN3S x=RN3S MaxDegreeGminusRN3S MaxDegreeG Hatsubplot(231)hold onhistf(RN1L MaxDegreeG0150facecolorbfacealpha5edgealpha1)histf(RN1L MaxDegreeG Hat0150facecolorrfacealpha5edgealpha1)histf(RN1L x0150facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightxlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN1L)grid on

subplot(232)hold onhistf(RN2L MaxDegreeG010500facecolorbfacealpha5edgealpha1)histf(RN2L MaxDegreeG Hat010500facecolorrfacealpha5edgealpha1)histf(RN2L x010500facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightxlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN2L)grid on

subplot(233)hold onhistf(RN3L MaxDegreeG010300facecolorbfacealpha5edgealpha1)histf(RN3L MaxDegreeG Hat010300facecolorrfacealpha5edgealpha1)histf(RN3L x010300facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightxlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN3L)

54 Application

grid on

subplot(234)hold onhistf(RN1S MaxDegreeG0150facecolorbfacealpha5edgealpha1)histf(RN1S MaxDegreeG Hat0150facecolorrfacealpha5edgealpha1)histf(RN1S x0150facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightxlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(R1NS)grid on

subplot(235)hold onhistf(RN2S MaxDegreeG010500facecolorbfacealpha5edgealpha1)histf(RN2S MaxDegreeG Hat010500facecolorrfacealpha5edgealpha1)histf(RN2S x010500facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightxlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN2S)grid on

subplot(236)hold onhistf(RN3S MaxDegreeG05300facecolorbfacealpha5edgealpha1)histf(RN3S MaxDegreeG Hat05300facecolorrfacealpha5edgealpha1)histf(RN3S x05300facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightgrid ontitle(RN3S)xlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labelset(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN2png minusr300)

h(3)=figure(NameComputation time over edgesNumberTitleoff)

subplot(231)hold onstem(RN1L EdgesGRN1L Time classicalg)stem(RN1L EdgesGRN1L Time algorithmro)stem(RN1L EdgesGRN1L Time greedybx)grid on

Appendix A 55

title(RN1L)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)

subplot(232)hold onstem(RN2L EdgesGRN2L Time classicalg)stem(RN2L EdgesGRN2L Time algorithmro)stem(RN2L EdgesGRN2L Time greedybx)grid ontitle(RN2L)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)

subplot(233)hold onstem(RN3L EdgesGRN3L Time classicalg)stem(RN3L EdgesGRN3L Time algorithmro)stem(RN3L EdgesGRN3L Time greedybx)grid ontitle(RN3L)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)

subplot(234)hold onstem(RN1S EdgesGRN1S Time classicalg)stem(RN1S EdgesGRN1S Time algorithmro)stem(RN1S EdgesGRN1S Time greedybx)grid ontitle(RN1S)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)

subplot(235)hold onstem(RN2S EdgesGRN2S Time classicalg)stem(RN2S EdgesGRN2S Time algorithmro)stem(RN2S EdgesGRN2S Time greedybx)grid ontitle(RN2S)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)

subplot(236)hold onstem(RN3S EdgesGRN3S Time classicalg)stem(RN3S EdgesGRN3S Time algorithmro)stem(RN3S EdgesGRN3S Time greedybx)

56 Application

grid ontitle(RN3S)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)set(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN3png minusr300)

h(4)=figure(NameSorted matching sizeNumberTitleoff)RN1L Sorted matching temp(1)=RN1L Classical matchingRN1L Sorted matching temp(2)=RN1L Final matchingRN1L Sorted matching temp(3)=RN1L Greedy matchingRN1L Sorted matching temp(4)=RN1L Initial matchingRN1L Sorted matching=sortrows(RN1L Sorted matching temp)

RN2L Sorted matching temp(1)=RN2L Classical matchingRN2L Sorted matching temp(2)=RN2L Final matchingRN2L Sorted matching temp(3)=RN2L Greedy matchingRN2L Sorted matching temp(4)=RN2L Initial matchingRN2L Sorted matching=sortrows(RN2L Sorted matching temp)

RN3L Sorted matching temp(1)=RN3L Classical matchingRN3L Sorted matching temp(2)=RN3L Final matchingRN3L Sorted matching temp(3)=RN3L Greedy matchingRN3L Sorted matching temp(4)=RN3L Initial matchingRN3L Sorted matching=sortrows(RN3L Sorted matching temp)

RN1S Sorted matching temp(1)=RN1S Classical matchingRN1S Sorted matching temp(2)=RN1S Final matchingRN1S Sorted matching temp(3)=RN1S Greedy matchingRN1S Sorted matching temp(4)=RN1S Initial matchingRN1S Sorted matching=sortrows(RN1S Sorted matching temp)

RN2S Sorted matching temp(1)=RN2S Classical matchingRN2S Sorted matching temp(2)=RN2S Final matchingRN2S Sorted matching temp(3)=RN2S Greedy matchingRN2S Sorted matching temp(4)=RN2S Initial matchingRN2S Sorted matching=sortrows(RN2S Sorted matching temp)

RN3S Sorted matching temp(1)=RN3S Classical matchingRN3S Sorted matching temp(2)=RN3S Final matchingRN3S Sorted matching temp(3)=RN3S Greedy matchingRN3S Sorted matching temp(4)=RN3S Initial matchingRN3S Sorted matching=sortrows(RN3S Sorted matching temp)

subplot(231)hold onplot(RN1L Sorted matching(1)b)plot(RN1L Sorted matching(2)g)plot(RN1L Sorted matching(3)r)plot(RN1L Sorted matching(4)m)

Appendix A 57

grid ontitle(RN1L)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)

subplot(232)hold onplot(RN2L Sorted matching(1)b)plot(RN2L Sorted matching(2)g)plot(RN2L Sorted matching(3)r)plot(RN2L Sorted matching(4)m)grid ontitle(RN2L)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)

subplot(233)hold onplot(RN3L Sorted matching(1)b)plot(RN3L Sorted matching(2)g)plot(RN3L Sorted matching(3)r)plot(RN3L Sorted matching(4)m)grid ontitle(RN3L)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)

subplot(234)hold onplot(RN1S Sorted matching(1)b)plot(RN1S Sorted matching(2)g)plot(RN1S Sorted matching(3)r)plot(RN1S Sorted matching(4)m)grid ontitle(RN1S)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)

subplot(235)hold onplot(RN2S Sorted matching(1)b)plot(RN2S Sorted matching(2)g)plot(RN2S Sorted matching(3)r)plot(RN2S Sorted matching(4)m)grid ontitle(RN2S)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)

58 Application

subplot(236)hold onplot(RN3S Sorted matching(1)b)plot(RN3S Sorted matching(2)g)plot(RN3S Sorted matching(3)r)plot(RN3S Sorted matching(4)m)grid ontitle(RN3S)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)set(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN4png minusr300)h(5)=figure(NameSorted RatiosNumberTitleoff)RN1L ratio1=RN1L NodesG hatRN1L NodesGRN2L ratio1=RN2L NodesG hatRN2L NodesGRN3L ratio1=RN3L NodesG hatRN3L NodesGRN1S ratio1=RN1S NodesG hatRN1S NodesGRN2S ratio1=RN2S NodesG hatRN2S NodesGRN3S ratio1=RN3S NodesG hatRN3S NodesG

RN1L ratio2=RN1L EdgesG HatRN1L EdgesGRN2L ratio2=RN2L EdgesG HatRN2L EdgesGRN3L ratio2=RN3L EdgesG HatRN3L EdgesGRN1S ratio2=RN1S EdgesG HatRN1S EdgesGRN2S ratio2=RN2S EdgesG HatRN2S EdgesGRN3S ratio2=RN3S EdgesG HatRN3S EdgesG

RN1L ratio3=RN1L MaxDegreeG HatRN1L MaxDegreeGRN2L ratio3=RN2L MaxDegreeG HatRN2L MaxDegreeGRN3L ratio3=RN3L MaxDegreeG HatRN3L MaxDegreeGRN1S ratio3=RN1S MaxDegreeG HatRN1S MaxDegreeGRN2S ratio3=RN2S MaxDegreeG HatRN2S MaxDegreeGRN3S ratio3=RN3S MaxDegreeG HatRN3S MaxDegreeG

RN1L ratio(1)=RN1L ratio1RN1L ratio(2)=RN1L ratio2RN1L ratio(3)=RN1L ratio3

RN2L ratio(1)=RN2L ratio1RN2L ratio(2)=RN2L ratio2RN2L ratio(3)=RN2L ratio3

RN3L ratio(1)=RN3L ratio1RN3L ratio(2)=RN3L ratio2RN3L ratio(3)=RN3L ratio3

RN1S ratio(1)=RN1S ratio1RN1S ratio(2)=RN1S ratio2RN1S ratio(3)=RN1S ratio3

RN2S ratio(1)=RN2S ratio1

Appendix A 59

RN2S ratio(2)=RN2S ratio2RN2S ratio(3)=RN2S ratio3

RN3S ratio(1)=RN3S ratio1RN3S ratio(2)=RN3S ratio2RN3S ratio(3)=RN3S ratio3

RN1L ratio sorted=sortrows(RN1L ratio)RN2L ratio sorted=sortrows(RN2L ratio)RN3L ratio sorted=sortrows(RN3L ratio)RN1S ratio sorted=sortrows(RN1S ratio)RN2S ratio sorted=sortrows(RN2S ratio)RN3S ratio sorted=sortrows(RN3S ratio)

subplot(231)hold onplot(RN1L ratio sorted(1)b)plot(RN1L ratio sorted(2)g)plot(RN1L ratio sorted(3)r)grid ontitle(RN1L)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)

subplot(232)hold onplot(RN2L ratio sorted(1)b)plot(RN2L ratio sorted(2)g)plot(RN2L ratio sorted(3)r)grid ontitle(RN2L)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)

subplot(233)hold onplot(RN3L ratio sorted(1)b)plot(RN3L ratio sorted(2)g)plot(RN3L ratio sorted(3)r)grid ontitle(RN3L)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)

subplot(234)hold onplot(RN1S ratio sorted(1)b)plot(RN1S ratio sorted(2)g)plot(RN1S ratio sorted(3)r)grid on

60 Application

title(RN1S)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)

subplot(235)hold onplot(RN2S ratio sorted(1)b)plot(RN2S ratio sorted(2)g)plot(RN2S ratio sorted(3)r)grid ontitle(RN2S)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)

subplot(236)hold onplot(RN3S ratio sorted(1)b)plot(RN3S ratio sorted(2)g)plot(RN3S ratio sorted(3)r)grid ontitle(RN3S)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)set(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN5png minusr300)

h(6)=figure(NameSorted edges over nodesNumberTitleoff)

RN1L DegreeG1=(RN1L EdgesG)(RN1L NodesG)RN1L DegreeG Hat1=(RN1L EdgesG Hat)(RN1L NodesG hat)

RN1L Degree temp1(1)=RN1L DegreeG1RN1L Degree temp1(2)=RN1L DegreeG Hat1RN1L Degree sorted1=sortrows(RN1L Degree temp1)subplot(231)hold on

plot(RN1L Degree sorted1(1)b)plot(RN1L Degree sorted1(2)g)grid ontitle(RN1L)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)

RN2L DegreeG1=(RN2L EdgesG)(RN2L NodesG)RN2L DegreeG Hat1=(RN2L EdgesG Hat)(RN2L NodesG hat)

RN2L Degree temp1(1)=RN2L DegreeG1

Appendix A 61

RN2L Degree temp1(2)=RN2L DegreeG Hat1RN2L Degree sorted1=sortrows(RN2L Degree temp1)

subplot(232)hold onplot(RN2L Degree sorted1(1)b)plot(RN2L Degree sorted1(2)g)grid ontitle(RN2L)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)

RN3L DegreeG1=(RN3L EdgesG)(RN3L NodesG)RN3L DegreeG Hat1=(RN3L EdgesG Hat)(RN3L NodesG hat)

RN3L Degree temp1(1)=RN3L DegreeG1RN3L Degree temp1(2)=RN3L DegreeG Hat1RN3L Degree sorted1=sortrows(RN3L Degree temp1)

subplot(233)hold onplot(RN3L Degree sorted1(1)b)plot(RN3L Degree sorted1(2)g)grid ontitle(RN3L)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)

RN1S DegreeG1=(RN1S EdgesG)(RN1S NodesG)RN1S DegreeG Hat1=(RN1S EdgesG Hat)(RN1S NodesG hat)

RN1S Degree temp1(1)=RN1S DegreeG1RN1S Degree temp1(2)=RN1S DegreeG Hat1RN1S Degree sorted1=sortrows(RN1S Degree temp1)

subplot(234)hold onplot(RN1S Degree sorted1(1)b)plot(RN1S Degree sorted1(2)g)grid ontitle(RN1S)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)

RN2S DegreeG1=(RN2S EdgesG)(RN2S NodesG)RN2S DegreeG Hat1=(RN2S EdgesG Hat)(RN2S NodesG hat)

RN2S Degree temp1(1)=RN2S DegreeG1

62 Application

RN2S Degree temp1(2)=RN2S DegreeG Hat1RN2S Degree sorted1=sortrows(RN2S Degree temp1)

subplot(235)hold onplot(RN2S Degree sorted1(1)b)plot(RN2S Degree sorted1(2)g)grid ontitle(RN2S)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)

RN3S DegreeG1=(RN3S EdgesG)(RN3S NodesG)RN3S DegreeG Hat1=(RN3S EdgesG Hat)(RN3S NodesG hat)

RN3S Degree temp1(1)=RN3S DegreeG1RN3S Degree temp1(2)=RN3S DegreeG Hat1RN3S Degree sorted1=sortrows(RN3S Degree temp1)

subplot(236)hold onplot(RN3S Degree sorted1(1)b)plot(RN3S Degree sorted1(2)g)grid ontitle(RN3S)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)set(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN6png minusr300)h(7)=figure(NameSorted mATCHED DEGREENumberTitleoff)RN1L ratioMax(1)=RN1L MaxDegreeGRN1L ratioMax(2)=RN1L MaxDegreeG Hat

RN1L ratio sortedMax=sortrows(RN1L ratioMax)subplot(231)hold onplot(RN1L ratio sortedMax(1)b)plot(RN1L ratio sortedMax(2)g)grid ontitle(RN1L)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)

RN2L ratioMax(1)=RN2L MaxDegreeGRN2L ratioMax(2)=RN2L MaxDegreeG Hat

RN2L ratio sortedMax=sortrows(RN2L ratioMax)subplot(232)

Appendix A 63

hold onplot(RN2L ratio sortedMax(1)b)plot(RN2L ratio sortedMax(2)g)grid ontitle(RN2L)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)

RN3L ratioMax(1)=RN3L MaxDegreeGRN3L ratioMax(2)=RN3L MaxDegreeG Hat

RN3L ratio sortedMax=sortrows(RN3L ratioMax)subplot(233)hold onplot(RN3L ratio sortedMax(1)b)plot(RN3L ratio sortedMax(2)g)grid ontitle(RN3L)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)

RN1S ratioMax(1)=RN1S MaxDegreeGRN1S ratioMax(2)=RN1S MaxDegreeG Hat

RN1S ratio sortedMax=sortrows(RN1S ratioMax)subplot(234)hold onplot(RN1S ratio sortedMax(1)b)plot(RN1S ratio sortedMax(2)g)grid ontitle(RN1S)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)

RN2S ratioMax(1)=RN2S MaxDegreeGRN2S ratioMax(2)=RN2S MaxDegreeG Hat

RN2S ratio sortedMax=sortrows(RN2S ratioMax)

subplot(235)hold onplot(RN2S ratio sortedMax(1)b)plot(RN2S ratio sortedMax(2)g)grid ontitle(RN2S)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)

RN3S ratioMax(1)=RN3S MaxDegreeGRN3S ratioMax(2)=RN3S MaxDegreeG Hat

64 Application

RN3S ratio sortedMax=sortrows(RN3S ratioMax)subplot(236)hold onplot(RN3S ratio sortedMax(1)b)plot(RN3S ratio sortedMax(2)g)grid ontitle(RN1L)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)set(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN7png minusr300)

tilefigs()(h)

Bibliography

[1] C Berge ldquoTWO THEOREMS IN GRAPH THEORYrdquo Proceedings of the NationalAcademy of Sciences of the United States of America vol 43 no 9 pp 842ndash844Sep 1957

[2] L Bui S Sanghavi and R Srikant ldquoDistributed link scheduling with constantoverheadrdquo IEEEACM Trans Netw vol 17 no 5 pp 1467ndash1480 2009

[3] R Duan and S Pettie ldquoLinear-time approximation for maximum weight matchingrdquoJ ACM vol 61 no 1 2014

[4] J Edmonds ldquoPaths trees and flowersrdquo Canadian Journal of Mathematics vol 17pp 449ndash467 1965

[5] J E Hopcroft and R M Karp ldquoAn n52 algorithm for maximum matchings inbipartite graphsrdquo SIAM J Comput vol 2 no 4 pp 225ndash231 1973

[6] S Micali and V V Vazirani ldquoAn O(radic|V ||E|) algorithm for finding maximum

matching in general graphsrdquo in 21st Symp on Foundations of Comp Sc (FOCS)IEEE 1980 pp 17ndash27

[7] N Nisse A Salch and V Weber ldquoRecovery of disrupted airline operationsrdquo 2015httphalinriafrSomething

[8] X Wu and R Srikant ldquoRegulated maximal matching A distributed schedulingalgorithm for multi-hop wireless networks with nodeexclusive spectrum sharingrdquo inIEEE Conf on Decision and Control 2005

65

  • Contents
  • Introduction
  • Algorithms
    • Maximum matching
    • k-maximum matching
      • k-matching for Airport Slot assignment
      • The case where k=3
      • The case of Paths
      • The case of the Spider
          • Application
            • Description
            • Reyni Erdos
            • Barabaacutesi Albert
            • Amadeus Graphs
            • Bipartite
            • Bipartite with degree seq
            • Appendix A
              • BipartiteGraphGeneratorpy
              • RandomGraphGeneratorpy
              • kequals3MaximumMatchingpy
              • Plotmat
                  • Bibliography
Page 48: Theodoros Alexandros KARAGKIOULES -  · Introduction This work is the result of a 6 months internship, under the supervision of research O cer Nicolas NISSE. The original scope of

Appendix A 49

adj dict3=i[ii for iix in enumerate(L) if x] for iL in enumerate(adj)

matching dict1=i[ii for iix in enumerate(L) if x] for iL in enumerate(matching1)matching dict2=i[ii for iix in enumerate(L) if x] for iL in enumerate(matching1)print adj dict2print matching dict2wswrite(index 1 num nodes)wswrite(index 2 num matching)

G = nxGraph()

useless= nxGraph()forced = nxGraph()

Fill Graphfor n in range(0num nodes)

for k in adj dict1[n]Gadd edge(nk)

Gt=Gnumber of edges()wswrite(index 3 Gnumber of nodes())wswrite(index 4 Gnumber of edges())wswrite(index 5 max(Gdegree()values()))

Compute Edmonds classical matching on G for comparison

startB = timeitdefault timer()Classical Matching=nxmax weight matching(G maxcardinality=False)stopB = timeitdefault timer()

Compute Gˆ nad MˆstartC = timeitdefault timer()useless edges(num nodesadj dict1matching dict1uselessadj dict2G)forced edges(Gadj dict2matching dict1num nodesforced)Final Matching=nxmax weight matching(G maxcardinality=False)stopC = timeitdefault timer()

GreedystartG = timeitdefault timer()greedy size=Greedy(num nodesadj dict3matching dict2)stopG = timeitdefault timer()

wswrite(index 6 Gnumber of nodes())wswrite(index 7 Gnumber of edges())wswrite(index 8 uselessnumber of edges())wswrite(index 9 forcednumber of edges())if Gdegree()values()

wswrite(index 10 max(Gdegree()values()))else

50 Application

wswrite(index 10 0)wswrite(index 11 len(Classical Matching)2)wswrite(index 12 len(Final Matching)2+forcednumber of edges())wswrite(index 13 greedy size)wswrite(index 14 stopB minus startBstyle1)wswrite(index 15 stopC minus startCstyle1)wswrite(index 16 stopG minus startGstyle1)wswrite(index 17 (len(Final Matching)2+forcednumber of edges())(num nodes2)style1)wswrite(index 18 Gnumber of nodes()Gtstyle1)wswrite(index 19 Gnumber of edges()Gtstyle1)wswrite(index 20 (len(Final Matching)2+forcednumber of edges())(len(Classical Matching)2)style1)

wbsave(AA Results Random Reyni Large Bipartitexls)

Main function Here we must choose the input form of the dataif name == main

startA = timeitdefault timer()General()stopA = timeitdefault timer()

print nThis program has terminatednnRunning time for 480 files stopAminusstartAprint nnPlease open AA Results Random Reyni Largexls file to see the Results

Appendix A 51

Plotmat

clear allclose allload(RN1Lmat)load(RN1Smat)load(RN2Lmat)load(RN2Smat)load(RN3Lmat)load(RN3Smat)

Plotsh(1)=figure(NameHistogram of Matching size difference between Constraint Algorithm and Greedy AlgorithmNumberTitleoff)

RN1L Greedydiff=RN1L Final matchingminusRN1L Greedy matchingRN2L Greedydiff=RN2L Final matchingminusRN2L Greedy matchingRN3L Greedydiff=RN3L Final matchingminusRN3L Greedy matchingRN1S Greedydiff=RN1S Final matchingminusRN1S Greedy matchingRN2S Greedydiff=RN2S Final matchingminusRN2S Greedy matchingRN3S Greedydiff=RN3S Final matchingminusRN3S Greedy matching

RN1L Finaldiff=RN1L Classical matchingminusRN1L Final matchingRN2L Finaldiff=RN2L Classical matchingminusRN2L Final matchingRN3L Finaldiff=RN3L Classical matchingminusRN3L Final matchingRN1S Finaldiff=RN1S Classical matchingminusRN1S Final matchingRN2S Finaldiff=RN2S Classical matchingminusRN2S Final matchingRN3S Finaldiff=RN3S Classical matchingminusRN3S Final matching

RN1L Classicaldiff=(RN1L Nodes2)minusRN1L Classical matchingRN2L Classicaldiff=(RN2L Nodes2)minusRN2L Classical matchingRN3L Classicaldiff=(RN3L Nodes2)minusRN3L Classical matchingRN1S Classicaldiff=(RN1S Nodes2)minusRN1S Classical matchingRN2S Classicaldiff=(RN2S Nodes2)minusRN2S Classical matchingRN3S Classicaldiff=(RN3S Nodes2)minusRN3S Classical matching

subplot(231)hold onhistf(RN1L Greedydiff0110facecolorbfacealpha9edgealpha1)histf(RN1L Finaldiff0110facecolorrfacealpha5edgealpha1)histf(RN1L Classicaldiff0110facecolorgfacealpha5edgealpha1)legalpha(ConminusGreClasminusConPerfminusClasslocationnortheast)legend boxoffaxis tightxlabel(edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN1L)grid on

subplot(232)hold onhistf(RN2L Greedydiff0110facecolorbfacealpha9edgealpha1)

52 Application

histf(RN2L Finaldiff0110facecolorrfacealpha5edgealpha1)histf(RN2L Classicaldiff0110facecolorgfacealpha5edgealpha1)legalpha(ConminusGreClasminusConPerfminusClasslocationnortheast)legend boxoffaxis tightxlabel(edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN2L)grid on

subplot(233)hold onhistf(RN3L Greedydiff0110facecolorbfacealpha5edgealpha1)histf(RN3L Finaldiff0110facecolorrfacealpha5edgealpha1)histf(RN3L Classicaldiff0110facecolorgfacealpha5edgealpha1)legalpha(ConminusGreClasminusConPerfminusClasslocationnortheast)legend boxoffaxis tightxlabel(edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN3L)grid on

subplot(234)hold onhistf(RN1S Greedydiff0110facecolorbfacealpha5edgealpha1)histf(RN1S Finaldiff0110facecolorrfacealpha5edgealpha1)histf(RN1S Classicaldiff0110facecolorgfacealpha5edgealpha1)legalpha(ConminusGreClasminusConPerfminusClasslocationnortheast)legend boxoffaxis tightxlabel(edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(R1NS)grid on

subplot(235)hold onhistf(RN2S Greedydiff0110facecolorbfacealpha5edgealpha1)histf(RN2S Finaldiff0110facecolorrfacealpha5edgealpha1)histf(RN2S Classicaldiff0110facecolorgfacealpha5edgealpha1)legalpha(ConminusGreClasminusConPerfminusClasslocationnortheast)legend boxoffaxis tightxlabel(edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN2S)grid on

subplot(236)hold onhistf(RN3S Greedydiff0110facecolorbfacealpha5edgealpha1)histf(RN3S Finaldiff0110facecolorrfacealpha5edgealpha1)histf(RN3S Classicaldiff0110facecolorgfacealpha5edgealpha1)

Appendix A 53

legalpha(ConminusGreClasminusConPerfminusClasslocationnortheast)legend boxoffaxis tightgrid ontitle(RN3S)xlabel(edges) xminusaxis labelylabel(instances) yminusaxis labelset(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN1png minusr300)h(2)=figure(NameHistogram of Max Degree of G AND G HatNumberTitleoff)RN1L x=RN1L MaxDegreeGminusRN1L MaxDegreeG HatRN2L x=RN2L MaxDegreeGminusRN2L MaxDegreeG HatRN3L x=RN3L MaxDegreeGminusRN3L MaxDegreeG HatRN1S x=RN1S MaxDegreeGminusRN1S MaxDegreeG HatRN2S x=RN2S MaxDegreeGminusRN2S MaxDegreeG HatRN3S x=RN3S MaxDegreeGminusRN3S MaxDegreeG Hatsubplot(231)hold onhistf(RN1L MaxDegreeG0150facecolorbfacealpha5edgealpha1)histf(RN1L MaxDegreeG Hat0150facecolorrfacealpha5edgealpha1)histf(RN1L x0150facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightxlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN1L)grid on

subplot(232)hold onhistf(RN2L MaxDegreeG010500facecolorbfacealpha5edgealpha1)histf(RN2L MaxDegreeG Hat010500facecolorrfacealpha5edgealpha1)histf(RN2L x010500facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightxlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN2L)grid on

subplot(233)hold onhistf(RN3L MaxDegreeG010300facecolorbfacealpha5edgealpha1)histf(RN3L MaxDegreeG Hat010300facecolorrfacealpha5edgealpha1)histf(RN3L x010300facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightxlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN3L)

54 Application

grid on

subplot(234)hold onhistf(RN1S MaxDegreeG0150facecolorbfacealpha5edgealpha1)histf(RN1S MaxDegreeG Hat0150facecolorrfacealpha5edgealpha1)histf(RN1S x0150facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightxlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(R1NS)grid on

subplot(235)hold onhistf(RN2S MaxDegreeG010500facecolorbfacealpha5edgealpha1)histf(RN2S MaxDegreeG Hat010500facecolorrfacealpha5edgealpha1)histf(RN2S x010500facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightxlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN2S)grid on

subplot(236)hold onhistf(RN3S MaxDegreeG05300facecolorbfacealpha5edgealpha1)histf(RN3S MaxDegreeG Hat05300facecolorrfacealpha5edgealpha1)histf(RN3S x05300facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightgrid ontitle(RN3S)xlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labelset(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN2png minusr300)

h(3)=figure(NameComputation time over edgesNumberTitleoff)

subplot(231)hold onstem(RN1L EdgesGRN1L Time classicalg)stem(RN1L EdgesGRN1L Time algorithmro)stem(RN1L EdgesGRN1L Time greedybx)grid on

Appendix A 55

title(RN1L)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)

subplot(232)hold onstem(RN2L EdgesGRN2L Time classicalg)stem(RN2L EdgesGRN2L Time algorithmro)stem(RN2L EdgesGRN2L Time greedybx)grid ontitle(RN2L)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)

subplot(233)hold onstem(RN3L EdgesGRN3L Time classicalg)stem(RN3L EdgesGRN3L Time algorithmro)stem(RN3L EdgesGRN3L Time greedybx)grid ontitle(RN3L)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)

subplot(234)hold onstem(RN1S EdgesGRN1S Time classicalg)stem(RN1S EdgesGRN1S Time algorithmro)stem(RN1S EdgesGRN1S Time greedybx)grid ontitle(RN1S)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)

subplot(235)hold onstem(RN2S EdgesGRN2S Time classicalg)stem(RN2S EdgesGRN2S Time algorithmro)stem(RN2S EdgesGRN2S Time greedybx)grid ontitle(RN2S)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)

subplot(236)hold onstem(RN3S EdgesGRN3S Time classicalg)stem(RN3S EdgesGRN3S Time algorithmro)stem(RN3S EdgesGRN3S Time greedybx)

56 Application

grid ontitle(RN3S)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)set(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN3png minusr300)

h(4)=figure(NameSorted matching sizeNumberTitleoff)RN1L Sorted matching temp(1)=RN1L Classical matchingRN1L Sorted matching temp(2)=RN1L Final matchingRN1L Sorted matching temp(3)=RN1L Greedy matchingRN1L Sorted matching temp(4)=RN1L Initial matchingRN1L Sorted matching=sortrows(RN1L Sorted matching temp)

RN2L Sorted matching temp(1)=RN2L Classical matchingRN2L Sorted matching temp(2)=RN2L Final matchingRN2L Sorted matching temp(3)=RN2L Greedy matchingRN2L Sorted matching temp(4)=RN2L Initial matchingRN2L Sorted matching=sortrows(RN2L Sorted matching temp)

RN3L Sorted matching temp(1)=RN3L Classical matchingRN3L Sorted matching temp(2)=RN3L Final matchingRN3L Sorted matching temp(3)=RN3L Greedy matchingRN3L Sorted matching temp(4)=RN3L Initial matchingRN3L Sorted matching=sortrows(RN3L Sorted matching temp)

RN1S Sorted matching temp(1)=RN1S Classical matchingRN1S Sorted matching temp(2)=RN1S Final matchingRN1S Sorted matching temp(3)=RN1S Greedy matchingRN1S Sorted matching temp(4)=RN1S Initial matchingRN1S Sorted matching=sortrows(RN1S Sorted matching temp)

RN2S Sorted matching temp(1)=RN2S Classical matchingRN2S Sorted matching temp(2)=RN2S Final matchingRN2S Sorted matching temp(3)=RN2S Greedy matchingRN2S Sorted matching temp(4)=RN2S Initial matchingRN2S Sorted matching=sortrows(RN2S Sorted matching temp)

RN3S Sorted matching temp(1)=RN3S Classical matchingRN3S Sorted matching temp(2)=RN3S Final matchingRN3S Sorted matching temp(3)=RN3S Greedy matchingRN3S Sorted matching temp(4)=RN3S Initial matchingRN3S Sorted matching=sortrows(RN3S Sorted matching temp)

subplot(231)hold onplot(RN1L Sorted matching(1)b)plot(RN1L Sorted matching(2)g)plot(RN1L Sorted matching(3)r)plot(RN1L Sorted matching(4)m)

Appendix A 57

grid ontitle(RN1L)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)

subplot(232)hold onplot(RN2L Sorted matching(1)b)plot(RN2L Sorted matching(2)g)plot(RN2L Sorted matching(3)r)plot(RN2L Sorted matching(4)m)grid ontitle(RN2L)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)

subplot(233)hold onplot(RN3L Sorted matching(1)b)plot(RN3L Sorted matching(2)g)plot(RN3L Sorted matching(3)r)plot(RN3L Sorted matching(4)m)grid ontitle(RN3L)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)

subplot(234)hold onplot(RN1S Sorted matching(1)b)plot(RN1S Sorted matching(2)g)plot(RN1S Sorted matching(3)r)plot(RN1S Sorted matching(4)m)grid ontitle(RN1S)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)

subplot(235)hold onplot(RN2S Sorted matching(1)b)plot(RN2S Sorted matching(2)g)plot(RN2S Sorted matching(3)r)plot(RN2S Sorted matching(4)m)grid ontitle(RN2S)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)

58 Application

subplot(236)hold onplot(RN3S Sorted matching(1)b)plot(RN3S Sorted matching(2)g)plot(RN3S Sorted matching(3)r)plot(RN3S Sorted matching(4)m)grid ontitle(RN3S)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)set(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN4png minusr300)h(5)=figure(NameSorted RatiosNumberTitleoff)RN1L ratio1=RN1L NodesG hatRN1L NodesGRN2L ratio1=RN2L NodesG hatRN2L NodesGRN3L ratio1=RN3L NodesG hatRN3L NodesGRN1S ratio1=RN1S NodesG hatRN1S NodesGRN2S ratio1=RN2S NodesG hatRN2S NodesGRN3S ratio1=RN3S NodesG hatRN3S NodesG

RN1L ratio2=RN1L EdgesG HatRN1L EdgesGRN2L ratio2=RN2L EdgesG HatRN2L EdgesGRN3L ratio2=RN3L EdgesG HatRN3L EdgesGRN1S ratio2=RN1S EdgesG HatRN1S EdgesGRN2S ratio2=RN2S EdgesG HatRN2S EdgesGRN3S ratio2=RN3S EdgesG HatRN3S EdgesG

RN1L ratio3=RN1L MaxDegreeG HatRN1L MaxDegreeGRN2L ratio3=RN2L MaxDegreeG HatRN2L MaxDegreeGRN3L ratio3=RN3L MaxDegreeG HatRN3L MaxDegreeGRN1S ratio3=RN1S MaxDegreeG HatRN1S MaxDegreeGRN2S ratio3=RN2S MaxDegreeG HatRN2S MaxDegreeGRN3S ratio3=RN3S MaxDegreeG HatRN3S MaxDegreeG

RN1L ratio(1)=RN1L ratio1RN1L ratio(2)=RN1L ratio2RN1L ratio(3)=RN1L ratio3

RN2L ratio(1)=RN2L ratio1RN2L ratio(2)=RN2L ratio2RN2L ratio(3)=RN2L ratio3

RN3L ratio(1)=RN3L ratio1RN3L ratio(2)=RN3L ratio2RN3L ratio(3)=RN3L ratio3

RN1S ratio(1)=RN1S ratio1RN1S ratio(2)=RN1S ratio2RN1S ratio(3)=RN1S ratio3

RN2S ratio(1)=RN2S ratio1

Appendix A 59

RN2S ratio(2)=RN2S ratio2RN2S ratio(3)=RN2S ratio3

RN3S ratio(1)=RN3S ratio1RN3S ratio(2)=RN3S ratio2RN3S ratio(3)=RN3S ratio3

RN1L ratio sorted=sortrows(RN1L ratio)RN2L ratio sorted=sortrows(RN2L ratio)RN3L ratio sorted=sortrows(RN3L ratio)RN1S ratio sorted=sortrows(RN1S ratio)RN2S ratio sorted=sortrows(RN2S ratio)RN3S ratio sorted=sortrows(RN3S ratio)

subplot(231)hold onplot(RN1L ratio sorted(1)b)plot(RN1L ratio sorted(2)g)plot(RN1L ratio sorted(3)r)grid ontitle(RN1L)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)

subplot(232)hold onplot(RN2L ratio sorted(1)b)plot(RN2L ratio sorted(2)g)plot(RN2L ratio sorted(3)r)grid ontitle(RN2L)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)

subplot(233)hold onplot(RN3L ratio sorted(1)b)plot(RN3L ratio sorted(2)g)plot(RN3L ratio sorted(3)r)grid ontitle(RN3L)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)

subplot(234)hold onplot(RN1S ratio sorted(1)b)plot(RN1S ratio sorted(2)g)plot(RN1S ratio sorted(3)r)grid on

60 Application

title(RN1S)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)

subplot(235)hold onplot(RN2S ratio sorted(1)b)plot(RN2S ratio sorted(2)g)plot(RN2S ratio sorted(3)r)grid ontitle(RN2S)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)

subplot(236)hold onplot(RN3S ratio sorted(1)b)plot(RN3S ratio sorted(2)g)plot(RN3S ratio sorted(3)r)grid ontitle(RN3S)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)set(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN5png minusr300)

h(6)=figure(NameSorted edges over nodesNumberTitleoff)

RN1L DegreeG1=(RN1L EdgesG)(RN1L NodesG)RN1L DegreeG Hat1=(RN1L EdgesG Hat)(RN1L NodesG hat)

RN1L Degree temp1(1)=RN1L DegreeG1RN1L Degree temp1(2)=RN1L DegreeG Hat1RN1L Degree sorted1=sortrows(RN1L Degree temp1)subplot(231)hold on

plot(RN1L Degree sorted1(1)b)plot(RN1L Degree sorted1(2)g)grid ontitle(RN1L)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)

RN2L DegreeG1=(RN2L EdgesG)(RN2L NodesG)RN2L DegreeG Hat1=(RN2L EdgesG Hat)(RN2L NodesG hat)

RN2L Degree temp1(1)=RN2L DegreeG1

Appendix A 61

RN2L Degree temp1(2)=RN2L DegreeG Hat1RN2L Degree sorted1=sortrows(RN2L Degree temp1)

subplot(232)hold onplot(RN2L Degree sorted1(1)b)plot(RN2L Degree sorted1(2)g)grid ontitle(RN2L)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)

RN3L DegreeG1=(RN3L EdgesG)(RN3L NodesG)RN3L DegreeG Hat1=(RN3L EdgesG Hat)(RN3L NodesG hat)

RN3L Degree temp1(1)=RN3L DegreeG1RN3L Degree temp1(2)=RN3L DegreeG Hat1RN3L Degree sorted1=sortrows(RN3L Degree temp1)

subplot(233)hold onplot(RN3L Degree sorted1(1)b)plot(RN3L Degree sorted1(2)g)grid ontitle(RN3L)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)

RN1S DegreeG1=(RN1S EdgesG)(RN1S NodesG)RN1S DegreeG Hat1=(RN1S EdgesG Hat)(RN1S NodesG hat)

RN1S Degree temp1(1)=RN1S DegreeG1RN1S Degree temp1(2)=RN1S DegreeG Hat1RN1S Degree sorted1=sortrows(RN1S Degree temp1)

subplot(234)hold onplot(RN1S Degree sorted1(1)b)plot(RN1S Degree sorted1(2)g)grid ontitle(RN1S)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)

RN2S DegreeG1=(RN2S EdgesG)(RN2S NodesG)RN2S DegreeG Hat1=(RN2S EdgesG Hat)(RN2S NodesG hat)

RN2S Degree temp1(1)=RN2S DegreeG1

62 Application

RN2S Degree temp1(2)=RN2S DegreeG Hat1RN2S Degree sorted1=sortrows(RN2S Degree temp1)

subplot(235)hold onplot(RN2S Degree sorted1(1)b)plot(RN2S Degree sorted1(2)g)grid ontitle(RN2S)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)

RN3S DegreeG1=(RN3S EdgesG)(RN3S NodesG)RN3S DegreeG Hat1=(RN3S EdgesG Hat)(RN3S NodesG hat)

RN3S Degree temp1(1)=RN3S DegreeG1RN3S Degree temp1(2)=RN3S DegreeG Hat1RN3S Degree sorted1=sortrows(RN3S Degree temp1)

subplot(236)hold onplot(RN3S Degree sorted1(1)b)plot(RN3S Degree sorted1(2)g)grid ontitle(RN3S)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)set(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN6png minusr300)h(7)=figure(NameSorted mATCHED DEGREENumberTitleoff)RN1L ratioMax(1)=RN1L MaxDegreeGRN1L ratioMax(2)=RN1L MaxDegreeG Hat

RN1L ratio sortedMax=sortrows(RN1L ratioMax)subplot(231)hold onplot(RN1L ratio sortedMax(1)b)plot(RN1L ratio sortedMax(2)g)grid ontitle(RN1L)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)

RN2L ratioMax(1)=RN2L MaxDegreeGRN2L ratioMax(2)=RN2L MaxDegreeG Hat

RN2L ratio sortedMax=sortrows(RN2L ratioMax)subplot(232)

Appendix A 63

hold onplot(RN2L ratio sortedMax(1)b)plot(RN2L ratio sortedMax(2)g)grid ontitle(RN2L)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)

RN3L ratioMax(1)=RN3L MaxDegreeGRN3L ratioMax(2)=RN3L MaxDegreeG Hat

RN3L ratio sortedMax=sortrows(RN3L ratioMax)subplot(233)hold onplot(RN3L ratio sortedMax(1)b)plot(RN3L ratio sortedMax(2)g)grid ontitle(RN3L)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)

RN1S ratioMax(1)=RN1S MaxDegreeGRN1S ratioMax(2)=RN1S MaxDegreeG Hat

RN1S ratio sortedMax=sortrows(RN1S ratioMax)subplot(234)hold onplot(RN1S ratio sortedMax(1)b)plot(RN1S ratio sortedMax(2)g)grid ontitle(RN1S)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)

RN2S ratioMax(1)=RN2S MaxDegreeGRN2S ratioMax(2)=RN2S MaxDegreeG Hat

RN2S ratio sortedMax=sortrows(RN2S ratioMax)

subplot(235)hold onplot(RN2S ratio sortedMax(1)b)plot(RN2S ratio sortedMax(2)g)grid ontitle(RN2S)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)

RN3S ratioMax(1)=RN3S MaxDegreeGRN3S ratioMax(2)=RN3S MaxDegreeG Hat

64 Application

RN3S ratio sortedMax=sortrows(RN3S ratioMax)subplot(236)hold onplot(RN3S ratio sortedMax(1)b)plot(RN3S ratio sortedMax(2)g)grid ontitle(RN1L)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)set(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN7png minusr300)

tilefigs()(h)

Bibliography

[1] C Berge ldquoTWO THEOREMS IN GRAPH THEORYrdquo Proceedings of the NationalAcademy of Sciences of the United States of America vol 43 no 9 pp 842ndash844Sep 1957

[2] L Bui S Sanghavi and R Srikant ldquoDistributed link scheduling with constantoverheadrdquo IEEEACM Trans Netw vol 17 no 5 pp 1467ndash1480 2009

[3] R Duan and S Pettie ldquoLinear-time approximation for maximum weight matchingrdquoJ ACM vol 61 no 1 2014

[4] J Edmonds ldquoPaths trees and flowersrdquo Canadian Journal of Mathematics vol 17pp 449ndash467 1965

[5] J E Hopcroft and R M Karp ldquoAn n52 algorithm for maximum matchings inbipartite graphsrdquo SIAM J Comput vol 2 no 4 pp 225ndash231 1973

[6] S Micali and V V Vazirani ldquoAn O(radic|V ||E|) algorithm for finding maximum

matching in general graphsrdquo in 21st Symp on Foundations of Comp Sc (FOCS)IEEE 1980 pp 17ndash27

[7] N Nisse A Salch and V Weber ldquoRecovery of disrupted airline operationsrdquo 2015httphalinriafrSomething

[8] X Wu and R Srikant ldquoRegulated maximal matching A distributed schedulingalgorithm for multi-hop wireless networks with nodeexclusive spectrum sharingrdquo inIEEE Conf on Decision and Control 2005

65

  • Contents
  • Introduction
  • Algorithms
    • Maximum matching
    • k-maximum matching
      • k-matching for Airport Slot assignment
      • The case where k=3
      • The case of Paths
      • The case of the Spider
          • Application
            • Description
            • Reyni Erdos
            • Barabaacutesi Albert
            • Amadeus Graphs
            • Bipartite
            • Bipartite with degree seq
            • Appendix A
              • BipartiteGraphGeneratorpy
              • RandomGraphGeneratorpy
              • kequals3MaximumMatchingpy
              • Plotmat
                  • Bibliography
Page 49: Theodoros Alexandros KARAGKIOULES -  · Introduction This work is the result of a 6 months internship, under the supervision of research O cer Nicolas NISSE. The original scope of

50 Application

wswrite(index 10 0)wswrite(index 11 len(Classical Matching)2)wswrite(index 12 len(Final Matching)2+forcednumber of edges())wswrite(index 13 greedy size)wswrite(index 14 stopB minus startBstyle1)wswrite(index 15 stopC minus startCstyle1)wswrite(index 16 stopG minus startGstyle1)wswrite(index 17 (len(Final Matching)2+forcednumber of edges())(num nodes2)style1)wswrite(index 18 Gnumber of nodes()Gtstyle1)wswrite(index 19 Gnumber of edges()Gtstyle1)wswrite(index 20 (len(Final Matching)2+forcednumber of edges())(len(Classical Matching)2)style1)

wbsave(AA Results Random Reyni Large Bipartitexls)

Main function Here we must choose the input form of the dataif name == main

startA = timeitdefault timer()General()stopA = timeitdefault timer()

print nThis program has terminatednnRunning time for 480 files stopAminusstartAprint nnPlease open AA Results Random Reyni Largexls file to see the Results

Appendix A 51

Plotmat

clear allclose allload(RN1Lmat)load(RN1Smat)load(RN2Lmat)load(RN2Smat)load(RN3Lmat)load(RN3Smat)

Plotsh(1)=figure(NameHistogram of Matching size difference between Constraint Algorithm and Greedy AlgorithmNumberTitleoff)

RN1L Greedydiff=RN1L Final matchingminusRN1L Greedy matchingRN2L Greedydiff=RN2L Final matchingminusRN2L Greedy matchingRN3L Greedydiff=RN3L Final matchingminusRN3L Greedy matchingRN1S Greedydiff=RN1S Final matchingminusRN1S Greedy matchingRN2S Greedydiff=RN2S Final matchingminusRN2S Greedy matchingRN3S Greedydiff=RN3S Final matchingminusRN3S Greedy matching

RN1L Finaldiff=RN1L Classical matchingminusRN1L Final matchingRN2L Finaldiff=RN2L Classical matchingminusRN2L Final matchingRN3L Finaldiff=RN3L Classical matchingminusRN3L Final matchingRN1S Finaldiff=RN1S Classical matchingminusRN1S Final matchingRN2S Finaldiff=RN2S Classical matchingminusRN2S Final matchingRN3S Finaldiff=RN3S Classical matchingminusRN3S Final matching

RN1L Classicaldiff=(RN1L Nodes2)minusRN1L Classical matchingRN2L Classicaldiff=(RN2L Nodes2)minusRN2L Classical matchingRN3L Classicaldiff=(RN3L Nodes2)minusRN3L Classical matchingRN1S Classicaldiff=(RN1S Nodes2)minusRN1S Classical matchingRN2S Classicaldiff=(RN2S Nodes2)minusRN2S Classical matchingRN3S Classicaldiff=(RN3S Nodes2)minusRN3S Classical matching

subplot(231)hold onhistf(RN1L Greedydiff0110facecolorbfacealpha9edgealpha1)histf(RN1L Finaldiff0110facecolorrfacealpha5edgealpha1)histf(RN1L Classicaldiff0110facecolorgfacealpha5edgealpha1)legalpha(ConminusGreClasminusConPerfminusClasslocationnortheast)legend boxoffaxis tightxlabel(edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN1L)grid on

subplot(232)hold onhistf(RN2L Greedydiff0110facecolorbfacealpha9edgealpha1)

52 Application

histf(RN2L Finaldiff0110facecolorrfacealpha5edgealpha1)histf(RN2L Classicaldiff0110facecolorgfacealpha5edgealpha1)legalpha(ConminusGreClasminusConPerfminusClasslocationnortheast)legend boxoffaxis tightxlabel(edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN2L)grid on

subplot(233)hold onhistf(RN3L Greedydiff0110facecolorbfacealpha5edgealpha1)histf(RN3L Finaldiff0110facecolorrfacealpha5edgealpha1)histf(RN3L Classicaldiff0110facecolorgfacealpha5edgealpha1)legalpha(ConminusGreClasminusConPerfminusClasslocationnortheast)legend boxoffaxis tightxlabel(edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN3L)grid on

subplot(234)hold onhistf(RN1S Greedydiff0110facecolorbfacealpha5edgealpha1)histf(RN1S Finaldiff0110facecolorrfacealpha5edgealpha1)histf(RN1S Classicaldiff0110facecolorgfacealpha5edgealpha1)legalpha(ConminusGreClasminusConPerfminusClasslocationnortheast)legend boxoffaxis tightxlabel(edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(R1NS)grid on

subplot(235)hold onhistf(RN2S Greedydiff0110facecolorbfacealpha5edgealpha1)histf(RN2S Finaldiff0110facecolorrfacealpha5edgealpha1)histf(RN2S Classicaldiff0110facecolorgfacealpha5edgealpha1)legalpha(ConminusGreClasminusConPerfminusClasslocationnortheast)legend boxoffaxis tightxlabel(edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN2S)grid on

subplot(236)hold onhistf(RN3S Greedydiff0110facecolorbfacealpha5edgealpha1)histf(RN3S Finaldiff0110facecolorrfacealpha5edgealpha1)histf(RN3S Classicaldiff0110facecolorgfacealpha5edgealpha1)

Appendix A 53

legalpha(ConminusGreClasminusConPerfminusClasslocationnortheast)legend boxoffaxis tightgrid ontitle(RN3S)xlabel(edges) xminusaxis labelylabel(instances) yminusaxis labelset(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN1png minusr300)h(2)=figure(NameHistogram of Max Degree of G AND G HatNumberTitleoff)RN1L x=RN1L MaxDegreeGminusRN1L MaxDegreeG HatRN2L x=RN2L MaxDegreeGminusRN2L MaxDegreeG HatRN3L x=RN3L MaxDegreeGminusRN3L MaxDegreeG HatRN1S x=RN1S MaxDegreeGminusRN1S MaxDegreeG HatRN2S x=RN2S MaxDegreeGminusRN2S MaxDegreeG HatRN3S x=RN3S MaxDegreeGminusRN3S MaxDegreeG Hatsubplot(231)hold onhistf(RN1L MaxDegreeG0150facecolorbfacealpha5edgealpha1)histf(RN1L MaxDegreeG Hat0150facecolorrfacealpha5edgealpha1)histf(RN1L x0150facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightxlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN1L)grid on

subplot(232)hold onhistf(RN2L MaxDegreeG010500facecolorbfacealpha5edgealpha1)histf(RN2L MaxDegreeG Hat010500facecolorrfacealpha5edgealpha1)histf(RN2L x010500facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightxlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN2L)grid on

subplot(233)hold onhistf(RN3L MaxDegreeG010300facecolorbfacealpha5edgealpha1)histf(RN3L MaxDegreeG Hat010300facecolorrfacealpha5edgealpha1)histf(RN3L x010300facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightxlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN3L)

54 Application

grid on

subplot(234)hold onhistf(RN1S MaxDegreeG0150facecolorbfacealpha5edgealpha1)histf(RN1S MaxDegreeG Hat0150facecolorrfacealpha5edgealpha1)histf(RN1S x0150facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightxlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(R1NS)grid on

subplot(235)hold onhistf(RN2S MaxDegreeG010500facecolorbfacealpha5edgealpha1)histf(RN2S MaxDegreeG Hat010500facecolorrfacealpha5edgealpha1)histf(RN2S x010500facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightxlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN2S)grid on

subplot(236)hold onhistf(RN3S MaxDegreeG05300facecolorbfacealpha5edgealpha1)histf(RN3S MaxDegreeG Hat05300facecolorrfacealpha5edgealpha1)histf(RN3S x05300facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightgrid ontitle(RN3S)xlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labelset(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN2png minusr300)

h(3)=figure(NameComputation time over edgesNumberTitleoff)

subplot(231)hold onstem(RN1L EdgesGRN1L Time classicalg)stem(RN1L EdgesGRN1L Time algorithmro)stem(RN1L EdgesGRN1L Time greedybx)grid on

Appendix A 55

title(RN1L)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)

subplot(232)hold onstem(RN2L EdgesGRN2L Time classicalg)stem(RN2L EdgesGRN2L Time algorithmro)stem(RN2L EdgesGRN2L Time greedybx)grid ontitle(RN2L)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)

subplot(233)hold onstem(RN3L EdgesGRN3L Time classicalg)stem(RN3L EdgesGRN3L Time algorithmro)stem(RN3L EdgesGRN3L Time greedybx)grid ontitle(RN3L)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)

subplot(234)hold onstem(RN1S EdgesGRN1S Time classicalg)stem(RN1S EdgesGRN1S Time algorithmro)stem(RN1S EdgesGRN1S Time greedybx)grid ontitle(RN1S)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)

subplot(235)hold onstem(RN2S EdgesGRN2S Time classicalg)stem(RN2S EdgesGRN2S Time algorithmro)stem(RN2S EdgesGRN2S Time greedybx)grid ontitle(RN2S)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)

subplot(236)hold onstem(RN3S EdgesGRN3S Time classicalg)stem(RN3S EdgesGRN3S Time algorithmro)stem(RN3S EdgesGRN3S Time greedybx)

56 Application

grid ontitle(RN3S)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)set(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN3png minusr300)

h(4)=figure(NameSorted matching sizeNumberTitleoff)RN1L Sorted matching temp(1)=RN1L Classical matchingRN1L Sorted matching temp(2)=RN1L Final matchingRN1L Sorted matching temp(3)=RN1L Greedy matchingRN1L Sorted matching temp(4)=RN1L Initial matchingRN1L Sorted matching=sortrows(RN1L Sorted matching temp)

RN2L Sorted matching temp(1)=RN2L Classical matchingRN2L Sorted matching temp(2)=RN2L Final matchingRN2L Sorted matching temp(3)=RN2L Greedy matchingRN2L Sorted matching temp(4)=RN2L Initial matchingRN2L Sorted matching=sortrows(RN2L Sorted matching temp)

RN3L Sorted matching temp(1)=RN3L Classical matchingRN3L Sorted matching temp(2)=RN3L Final matchingRN3L Sorted matching temp(3)=RN3L Greedy matchingRN3L Sorted matching temp(4)=RN3L Initial matchingRN3L Sorted matching=sortrows(RN3L Sorted matching temp)

RN1S Sorted matching temp(1)=RN1S Classical matchingRN1S Sorted matching temp(2)=RN1S Final matchingRN1S Sorted matching temp(3)=RN1S Greedy matchingRN1S Sorted matching temp(4)=RN1S Initial matchingRN1S Sorted matching=sortrows(RN1S Sorted matching temp)

RN2S Sorted matching temp(1)=RN2S Classical matchingRN2S Sorted matching temp(2)=RN2S Final matchingRN2S Sorted matching temp(3)=RN2S Greedy matchingRN2S Sorted matching temp(4)=RN2S Initial matchingRN2S Sorted matching=sortrows(RN2S Sorted matching temp)

RN3S Sorted matching temp(1)=RN3S Classical matchingRN3S Sorted matching temp(2)=RN3S Final matchingRN3S Sorted matching temp(3)=RN3S Greedy matchingRN3S Sorted matching temp(4)=RN3S Initial matchingRN3S Sorted matching=sortrows(RN3S Sorted matching temp)

subplot(231)hold onplot(RN1L Sorted matching(1)b)plot(RN1L Sorted matching(2)g)plot(RN1L Sorted matching(3)r)plot(RN1L Sorted matching(4)m)

Appendix A 57

grid ontitle(RN1L)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)

subplot(232)hold onplot(RN2L Sorted matching(1)b)plot(RN2L Sorted matching(2)g)plot(RN2L Sorted matching(3)r)plot(RN2L Sorted matching(4)m)grid ontitle(RN2L)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)

subplot(233)hold onplot(RN3L Sorted matching(1)b)plot(RN3L Sorted matching(2)g)plot(RN3L Sorted matching(3)r)plot(RN3L Sorted matching(4)m)grid ontitle(RN3L)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)

subplot(234)hold onplot(RN1S Sorted matching(1)b)plot(RN1S Sorted matching(2)g)plot(RN1S Sorted matching(3)r)plot(RN1S Sorted matching(4)m)grid ontitle(RN1S)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)

subplot(235)hold onplot(RN2S Sorted matching(1)b)plot(RN2S Sorted matching(2)g)plot(RN2S Sorted matching(3)r)plot(RN2S Sorted matching(4)m)grid ontitle(RN2S)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)

58 Application

subplot(236)hold onplot(RN3S Sorted matching(1)b)plot(RN3S Sorted matching(2)g)plot(RN3S Sorted matching(3)r)plot(RN3S Sorted matching(4)m)grid ontitle(RN3S)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)set(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN4png minusr300)h(5)=figure(NameSorted RatiosNumberTitleoff)RN1L ratio1=RN1L NodesG hatRN1L NodesGRN2L ratio1=RN2L NodesG hatRN2L NodesGRN3L ratio1=RN3L NodesG hatRN3L NodesGRN1S ratio1=RN1S NodesG hatRN1S NodesGRN2S ratio1=RN2S NodesG hatRN2S NodesGRN3S ratio1=RN3S NodesG hatRN3S NodesG

RN1L ratio2=RN1L EdgesG HatRN1L EdgesGRN2L ratio2=RN2L EdgesG HatRN2L EdgesGRN3L ratio2=RN3L EdgesG HatRN3L EdgesGRN1S ratio2=RN1S EdgesG HatRN1S EdgesGRN2S ratio2=RN2S EdgesG HatRN2S EdgesGRN3S ratio2=RN3S EdgesG HatRN3S EdgesG

RN1L ratio3=RN1L MaxDegreeG HatRN1L MaxDegreeGRN2L ratio3=RN2L MaxDegreeG HatRN2L MaxDegreeGRN3L ratio3=RN3L MaxDegreeG HatRN3L MaxDegreeGRN1S ratio3=RN1S MaxDegreeG HatRN1S MaxDegreeGRN2S ratio3=RN2S MaxDegreeG HatRN2S MaxDegreeGRN3S ratio3=RN3S MaxDegreeG HatRN3S MaxDegreeG

RN1L ratio(1)=RN1L ratio1RN1L ratio(2)=RN1L ratio2RN1L ratio(3)=RN1L ratio3

RN2L ratio(1)=RN2L ratio1RN2L ratio(2)=RN2L ratio2RN2L ratio(3)=RN2L ratio3

RN3L ratio(1)=RN3L ratio1RN3L ratio(2)=RN3L ratio2RN3L ratio(3)=RN3L ratio3

RN1S ratio(1)=RN1S ratio1RN1S ratio(2)=RN1S ratio2RN1S ratio(3)=RN1S ratio3

RN2S ratio(1)=RN2S ratio1

Appendix A 59

RN2S ratio(2)=RN2S ratio2RN2S ratio(3)=RN2S ratio3

RN3S ratio(1)=RN3S ratio1RN3S ratio(2)=RN3S ratio2RN3S ratio(3)=RN3S ratio3

RN1L ratio sorted=sortrows(RN1L ratio)RN2L ratio sorted=sortrows(RN2L ratio)RN3L ratio sorted=sortrows(RN3L ratio)RN1S ratio sorted=sortrows(RN1S ratio)RN2S ratio sorted=sortrows(RN2S ratio)RN3S ratio sorted=sortrows(RN3S ratio)

subplot(231)hold onplot(RN1L ratio sorted(1)b)plot(RN1L ratio sorted(2)g)plot(RN1L ratio sorted(3)r)grid ontitle(RN1L)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)

subplot(232)hold onplot(RN2L ratio sorted(1)b)plot(RN2L ratio sorted(2)g)plot(RN2L ratio sorted(3)r)grid ontitle(RN2L)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)

subplot(233)hold onplot(RN3L ratio sorted(1)b)plot(RN3L ratio sorted(2)g)plot(RN3L ratio sorted(3)r)grid ontitle(RN3L)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)

subplot(234)hold onplot(RN1S ratio sorted(1)b)plot(RN1S ratio sorted(2)g)plot(RN1S ratio sorted(3)r)grid on

60 Application

title(RN1S)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)

subplot(235)hold onplot(RN2S ratio sorted(1)b)plot(RN2S ratio sorted(2)g)plot(RN2S ratio sorted(3)r)grid ontitle(RN2S)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)

subplot(236)hold onplot(RN3S ratio sorted(1)b)plot(RN3S ratio sorted(2)g)plot(RN3S ratio sorted(3)r)grid ontitle(RN3S)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)set(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN5png minusr300)

h(6)=figure(NameSorted edges over nodesNumberTitleoff)

RN1L DegreeG1=(RN1L EdgesG)(RN1L NodesG)RN1L DegreeG Hat1=(RN1L EdgesG Hat)(RN1L NodesG hat)

RN1L Degree temp1(1)=RN1L DegreeG1RN1L Degree temp1(2)=RN1L DegreeG Hat1RN1L Degree sorted1=sortrows(RN1L Degree temp1)subplot(231)hold on

plot(RN1L Degree sorted1(1)b)plot(RN1L Degree sorted1(2)g)grid ontitle(RN1L)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)

RN2L DegreeG1=(RN2L EdgesG)(RN2L NodesG)RN2L DegreeG Hat1=(RN2L EdgesG Hat)(RN2L NodesG hat)

RN2L Degree temp1(1)=RN2L DegreeG1

Appendix A 61

RN2L Degree temp1(2)=RN2L DegreeG Hat1RN2L Degree sorted1=sortrows(RN2L Degree temp1)

subplot(232)hold onplot(RN2L Degree sorted1(1)b)plot(RN2L Degree sorted1(2)g)grid ontitle(RN2L)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)

RN3L DegreeG1=(RN3L EdgesG)(RN3L NodesG)RN3L DegreeG Hat1=(RN3L EdgesG Hat)(RN3L NodesG hat)

RN3L Degree temp1(1)=RN3L DegreeG1RN3L Degree temp1(2)=RN3L DegreeG Hat1RN3L Degree sorted1=sortrows(RN3L Degree temp1)

subplot(233)hold onplot(RN3L Degree sorted1(1)b)plot(RN3L Degree sorted1(2)g)grid ontitle(RN3L)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)

RN1S DegreeG1=(RN1S EdgesG)(RN1S NodesG)RN1S DegreeG Hat1=(RN1S EdgesG Hat)(RN1S NodesG hat)

RN1S Degree temp1(1)=RN1S DegreeG1RN1S Degree temp1(2)=RN1S DegreeG Hat1RN1S Degree sorted1=sortrows(RN1S Degree temp1)

subplot(234)hold onplot(RN1S Degree sorted1(1)b)plot(RN1S Degree sorted1(2)g)grid ontitle(RN1S)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)

RN2S DegreeG1=(RN2S EdgesG)(RN2S NodesG)RN2S DegreeG Hat1=(RN2S EdgesG Hat)(RN2S NodesG hat)

RN2S Degree temp1(1)=RN2S DegreeG1

62 Application

RN2S Degree temp1(2)=RN2S DegreeG Hat1RN2S Degree sorted1=sortrows(RN2S Degree temp1)

subplot(235)hold onplot(RN2S Degree sorted1(1)b)plot(RN2S Degree sorted1(2)g)grid ontitle(RN2S)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)

RN3S DegreeG1=(RN3S EdgesG)(RN3S NodesG)RN3S DegreeG Hat1=(RN3S EdgesG Hat)(RN3S NodesG hat)

RN3S Degree temp1(1)=RN3S DegreeG1RN3S Degree temp1(2)=RN3S DegreeG Hat1RN3S Degree sorted1=sortrows(RN3S Degree temp1)

subplot(236)hold onplot(RN3S Degree sorted1(1)b)plot(RN3S Degree sorted1(2)g)grid ontitle(RN3S)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)set(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN6png minusr300)h(7)=figure(NameSorted mATCHED DEGREENumberTitleoff)RN1L ratioMax(1)=RN1L MaxDegreeGRN1L ratioMax(2)=RN1L MaxDegreeG Hat

RN1L ratio sortedMax=sortrows(RN1L ratioMax)subplot(231)hold onplot(RN1L ratio sortedMax(1)b)plot(RN1L ratio sortedMax(2)g)grid ontitle(RN1L)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)

RN2L ratioMax(1)=RN2L MaxDegreeGRN2L ratioMax(2)=RN2L MaxDegreeG Hat

RN2L ratio sortedMax=sortrows(RN2L ratioMax)subplot(232)

Appendix A 63

hold onplot(RN2L ratio sortedMax(1)b)plot(RN2L ratio sortedMax(2)g)grid ontitle(RN2L)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)

RN3L ratioMax(1)=RN3L MaxDegreeGRN3L ratioMax(2)=RN3L MaxDegreeG Hat

RN3L ratio sortedMax=sortrows(RN3L ratioMax)subplot(233)hold onplot(RN3L ratio sortedMax(1)b)plot(RN3L ratio sortedMax(2)g)grid ontitle(RN3L)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)

RN1S ratioMax(1)=RN1S MaxDegreeGRN1S ratioMax(2)=RN1S MaxDegreeG Hat

RN1S ratio sortedMax=sortrows(RN1S ratioMax)subplot(234)hold onplot(RN1S ratio sortedMax(1)b)plot(RN1S ratio sortedMax(2)g)grid ontitle(RN1S)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)

RN2S ratioMax(1)=RN2S MaxDegreeGRN2S ratioMax(2)=RN2S MaxDegreeG Hat

RN2S ratio sortedMax=sortrows(RN2S ratioMax)

subplot(235)hold onplot(RN2S ratio sortedMax(1)b)plot(RN2S ratio sortedMax(2)g)grid ontitle(RN2S)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)

RN3S ratioMax(1)=RN3S MaxDegreeGRN3S ratioMax(2)=RN3S MaxDegreeG Hat

64 Application

RN3S ratio sortedMax=sortrows(RN3S ratioMax)subplot(236)hold onplot(RN3S ratio sortedMax(1)b)plot(RN3S ratio sortedMax(2)g)grid ontitle(RN1L)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)set(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN7png minusr300)

tilefigs()(h)

Bibliography

[1] C Berge ldquoTWO THEOREMS IN GRAPH THEORYrdquo Proceedings of the NationalAcademy of Sciences of the United States of America vol 43 no 9 pp 842ndash844Sep 1957

[2] L Bui S Sanghavi and R Srikant ldquoDistributed link scheduling with constantoverheadrdquo IEEEACM Trans Netw vol 17 no 5 pp 1467ndash1480 2009

[3] R Duan and S Pettie ldquoLinear-time approximation for maximum weight matchingrdquoJ ACM vol 61 no 1 2014

[4] J Edmonds ldquoPaths trees and flowersrdquo Canadian Journal of Mathematics vol 17pp 449ndash467 1965

[5] J E Hopcroft and R M Karp ldquoAn n52 algorithm for maximum matchings inbipartite graphsrdquo SIAM J Comput vol 2 no 4 pp 225ndash231 1973

[6] S Micali and V V Vazirani ldquoAn O(radic|V ||E|) algorithm for finding maximum

matching in general graphsrdquo in 21st Symp on Foundations of Comp Sc (FOCS)IEEE 1980 pp 17ndash27

[7] N Nisse A Salch and V Weber ldquoRecovery of disrupted airline operationsrdquo 2015httphalinriafrSomething

[8] X Wu and R Srikant ldquoRegulated maximal matching A distributed schedulingalgorithm for multi-hop wireless networks with nodeexclusive spectrum sharingrdquo inIEEE Conf on Decision and Control 2005

65

  • Contents
  • Introduction
  • Algorithms
    • Maximum matching
    • k-maximum matching
      • k-matching for Airport Slot assignment
      • The case where k=3
      • The case of Paths
      • The case of the Spider
          • Application
            • Description
            • Reyni Erdos
            • Barabaacutesi Albert
            • Amadeus Graphs
            • Bipartite
            • Bipartite with degree seq
            • Appendix A
              • BipartiteGraphGeneratorpy
              • RandomGraphGeneratorpy
              • kequals3MaximumMatchingpy
              • Plotmat
                  • Bibliography
Page 50: Theodoros Alexandros KARAGKIOULES -  · Introduction This work is the result of a 6 months internship, under the supervision of research O cer Nicolas NISSE. The original scope of

Appendix A 51

Plotmat

clear allclose allload(RN1Lmat)load(RN1Smat)load(RN2Lmat)load(RN2Smat)load(RN3Lmat)load(RN3Smat)

Plotsh(1)=figure(NameHistogram of Matching size difference between Constraint Algorithm and Greedy AlgorithmNumberTitleoff)

RN1L Greedydiff=RN1L Final matchingminusRN1L Greedy matchingRN2L Greedydiff=RN2L Final matchingminusRN2L Greedy matchingRN3L Greedydiff=RN3L Final matchingminusRN3L Greedy matchingRN1S Greedydiff=RN1S Final matchingminusRN1S Greedy matchingRN2S Greedydiff=RN2S Final matchingminusRN2S Greedy matchingRN3S Greedydiff=RN3S Final matchingminusRN3S Greedy matching

RN1L Finaldiff=RN1L Classical matchingminusRN1L Final matchingRN2L Finaldiff=RN2L Classical matchingminusRN2L Final matchingRN3L Finaldiff=RN3L Classical matchingminusRN3L Final matchingRN1S Finaldiff=RN1S Classical matchingminusRN1S Final matchingRN2S Finaldiff=RN2S Classical matchingminusRN2S Final matchingRN3S Finaldiff=RN3S Classical matchingminusRN3S Final matching

RN1L Classicaldiff=(RN1L Nodes2)minusRN1L Classical matchingRN2L Classicaldiff=(RN2L Nodes2)minusRN2L Classical matchingRN3L Classicaldiff=(RN3L Nodes2)minusRN3L Classical matchingRN1S Classicaldiff=(RN1S Nodes2)minusRN1S Classical matchingRN2S Classicaldiff=(RN2S Nodes2)minusRN2S Classical matchingRN3S Classicaldiff=(RN3S Nodes2)minusRN3S Classical matching

subplot(231)hold onhistf(RN1L Greedydiff0110facecolorbfacealpha9edgealpha1)histf(RN1L Finaldiff0110facecolorrfacealpha5edgealpha1)histf(RN1L Classicaldiff0110facecolorgfacealpha5edgealpha1)legalpha(ConminusGreClasminusConPerfminusClasslocationnortheast)legend boxoffaxis tightxlabel(edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN1L)grid on

subplot(232)hold onhistf(RN2L Greedydiff0110facecolorbfacealpha9edgealpha1)

52 Application

histf(RN2L Finaldiff0110facecolorrfacealpha5edgealpha1)histf(RN2L Classicaldiff0110facecolorgfacealpha5edgealpha1)legalpha(ConminusGreClasminusConPerfminusClasslocationnortheast)legend boxoffaxis tightxlabel(edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN2L)grid on

subplot(233)hold onhistf(RN3L Greedydiff0110facecolorbfacealpha5edgealpha1)histf(RN3L Finaldiff0110facecolorrfacealpha5edgealpha1)histf(RN3L Classicaldiff0110facecolorgfacealpha5edgealpha1)legalpha(ConminusGreClasminusConPerfminusClasslocationnortheast)legend boxoffaxis tightxlabel(edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN3L)grid on

subplot(234)hold onhistf(RN1S Greedydiff0110facecolorbfacealpha5edgealpha1)histf(RN1S Finaldiff0110facecolorrfacealpha5edgealpha1)histf(RN1S Classicaldiff0110facecolorgfacealpha5edgealpha1)legalpha(ConminusGreClasminusConPerfminusClasslocationnortheast)legend boxoffaxis tightxlabel(edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(R1NS)grid on

subplot(235)hold onhistf(RN2S Greedydiff0110facecolorbfacealpha5edgealpha1)histf(RN2S Finaldiff0110facecolorrfacealpha5edgealpha1)histf(RN2S Classicaldiff0110facecolorgfacealpha5edgealpha1)legalpha(ConminusGreClasminusConPerfminusClasslocationnortheast)legend boxoffaxis tightxlabel(edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN2S)grid on

subplot(236)hold onhistf(RN3S Greedydiff0110facecolorbfacealpha5edgealpha1)histf(RN3S Finaldiff0110facecolorrfacealpha5edgealpha1)histf(RN3S Classicaldiff0110facecolorgfacealpha5edgealpha1)

Appendix A 53

legalpha(ConminusGreClasminusConPerfminusClasslocationnortheast)legend boxoffaxis tightgrid ontitle(RN3S)xlabel(edges) xminusaxis labelylabel(instances) yminusaxis labelset(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN1png minusr300)h(2)=figure(NameHistogram of Max Degree of G AND G HatNumberTitleoff)RN1L x=RN1L MaxDegreeGminusRN1L MaxDegreeG HatRN2L x=RN2L MaxDegreeGminusRN2L MaxDegreeG HatRN3L x=RN3L MaxDegreeGminusRN3L MaxDegreeG HatRN1S x=RN1S MaxDegreeGminusRN1S MaxDegreeG HatRN2S x=RN2S MaxDegreeGminusRN2S MaxDegreeG HatRN3S x=RN3S MaxDegreeGminusRN3S MaxDegreeG Hatsubplot(231)hold onhistf(RN1L MaxDegreeG0150facecolorbfacealpha5edgealpha1)histf(RN1L MaxDegreeG Hat0150facecolorrfacealpha5edgealpha1)histf(RN1L x0150facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightxlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN1L)grid on

subplot(232)hold onhistf(RN2L MaxDegreeG010500facecolorbfacealpha5edgealpha1)histf(RN2L MaxDegreeG Hat010500facecolorrfacealpha5edgealpha1)histf(RN2L x010500facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightxlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN2L)grid on

subplot(233)hold onhistf(RN3L MaxDegreeG010300facecolorbfacealpha5edgealpha1)histf(RN3L MaxDegreeG Hat010300facecolorrfacealpha5edgealpha1)histf(RN3L x010300facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightxlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN3L)

54 Application

grid on

subplot(234)hold onhistf(RN1S MaxDegreeG0150facecolorbfacealpha5edgealpha1)histf(RN1S MaxDegreeG Hat0150facecolorrfacealpha5edgealpha1)histf(RN1S x0150facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightxlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(R1NS)grid on

subplot(235)hold onhistf(RN2S MaxDegreeG010500facecolorbfacealpha5edgealpha1)histf(RN2S MaxDegreeG Hat010500facecolorrfacealpha5edgealpha1)histf(RN2S x010500facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightxlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN2S)grid on

subplot(236)hold onhistf(RN3S MaxDegreeG05300facecolorbfacealpha5edgealpha1)histf(RN3S MaxDegreeG Hat05300facecolorrfacealpha5edgealpha1)histf(RN3S x05300facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightgrid ontitle(RN3S)xlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labelset(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN2png minusr300)

h(3)=figure(NameComputation time over edgesNumberTitleoff)

subplot(231)hold onstem(RN1L EdgesGRN1L Time classicalg)stem(RN1L EdgesGRN1L Time algorithmro)stem(RN1L EdgesGRN1L Time greedybx)grid on

Appendix A 55

title(RN1L)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)

subplot(232)hold onstem(RN2L EdgesGRN2L Time classicalg)stem(RN2L EdgesGRN2L Time algorithmro)stem(RN2L EdgesGRN2L Time greedybx)grid ontitle(RN2L)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)

subplot(233)hold onstem(RN3L EdgesGRN3L Time classicalg)stem(RN3L EdgesGRN3L Time algorithmro)stem(RN3L EdgesGRN3L Time greedybx)grid ontitle(RN3L)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)

subplot(234)hold onstem(RN1S EdgesGRN1S Time classicalg)stem(RN1S EdgesGRN1S Time algorithmro)stem(RN1S EdgesGRN1S Time greedybx)grid ontitle(RN1S)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)

subplot(235)hold onstem(RN2S EdgesGRN2S Time classicalg)stem(RN2S EdgesGRN2S Time algorithmro)stem(RN2S EdgesGRN2S Time greedybx)grid ontitle(RN2S)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)

subplot(236)hold onstem(RN3S EdgesGRN3S Time classicalg)stem(RN3S EdgesGRN3S Time algorithmro)stem(RN3S EdgesGRN3S Time greedybx)

56 Application

grid ontitle(RN3S)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)set(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN3png minusr300)

h(4)=figure(NameSorted matching sizeNumberTitleoff)RN1L Sorted matching temp(1)=RN1L Classical matchingRN1L Sorted matching temp(2)=RN1L Final matchingRN1L Sorted matching temp(3)=RN1L Greedy matchingRN1L Sorted matching temp(4)=RN1L Initial matchingRN1L Sorted matching=sortrows(RN1L Sorted matching temp)

RN2L Sorted matching temp(1)=RN2L Classical matchingRN2L Sorted matching temp(2)=RN2L Final matchingRN2L Sorted matching temp(3)=RN2L Greedy matchingRN2L Sorted matching temp(4)=RN2L Initial matchingRN2L Sorted matching=sortrows(RN2L Sorted matching temp)

RN3L Sorted matching temp(1)=RN3L Classical matchingRN3L Sorted matching temp(2)=RN3L Final matchingRN3L Sorted matching temp(3)=RN3L Greedy matchingRN3L Sorted matching temp(4)=RN3L Initial matchingRN3L Sorted matching=sortrows(RN3L Sorted matching temp)

RN1S Sorted matching temp(1)=RN1S Classical matchingRN1S Sorted matching temp(2)=RN1S Final matchingRN1S Sorted matching temp(3)=RN1S Greedy matchingRN1S Sorted matching temp(4)=RN1S Initial matchingRN1S Sorted matching=sortrows(RN1S Sorted matching temp)

RN2S Sorted matching temp(1)=RN2S Classical matchingRN2S Sorted matching temp(2)=RN2S Final matchingRN2S Sorted matching temp(3)=RN2S Greedy matchingRN2S Sorted matching temp(4)=RN2S Initial matchingRN2S Sorted matching=sortrows(RN2S Sorted matching temp)

RN3S Sorted matching temp(1)=RN3S Classical matchingRN3S Sorted matching temp(2)=RN3S Final matchingRN3S Sorted matching temp(3)=RN3S Greedy matchingRN3S Sorted matching temp(4)=RN3S Initial matchingRN3S Sorted matching=sortrows(RN3S Sorted matching temp)

subplot(231)hold onplot(RN1L Sorted matching(1)b)plot(RN1L Sorted matching(2)g)plot(RN1L Sorted matching(3)r)plot(RN1L Sorted matching(4)m)

Appendix A 57

grid ontitle(RN1L)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)

subplot(232)hold onplot(RN2L Sorted matching(1)b)plot(RN2L Sorted matching(2)g)plot(RN2L Sorted matching(3)r)plot(RN2L Sorted matching(4)m)grid ontitle(RN2L)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)

subplot(233)hold onplot(RN3L Sorted matching(1)b)plot(RN3L Sorted matching(2)g)plot(RN3L Sorted matching(3)r)plot(RN3L Sorted matching(4)m)grid ontitle(RN3L)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)

subplot(234)hold onplot(RN1S Sorted matching(1)b)plot(RN1S Sorted matching(2)g)plot(RN1S Sorted matching(3)r)plot(RN1S Sorted matching(4)m)grid ontitle(RN1S)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)

subplot(235)hold onplot(RN2S Sorted matching(1)b)plot(RN2S Sorted matching(2)g)plot(RN2S Sorted matching(3)r)plot(RN2S Sorted matching(4)m)grid ontitle(RN2S)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)

58 Application

subplot(236)hold onplot(RN3S Sorted matching(1)b)plot(RN3S Sorted matching(2)g)plot(RN3S Sorted matching(3)r)plot(RN3S Sorted matching(4)m)grid ontitle(RN3S)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)set(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN4png minusr300)h(5)=figure(NameSorted RatiosNumberTitleoff)RN1L ratio1=RN1L NodesG hatRN1L NodesGRN2L ratio1=RN2L NodesG hatRN2L NodesGRN3L ratio1=RN3L NodesG hatRN3L NodesGRN1S ratio1=RN1S NodesG hatRN1S NodesGRN2S ratio1=RN2S NodesG hatRN2S NodesGRN3S ratio1=RN3S NodesG hatRN3S NodesG

RN1L ratio2=RN1L EdgesG HatRN1L EdgesGRN2L ratio2=RN2L EdgesG HatRN2L EdgesGRN3L ratio2=RN3L EdgesG HatRN3L EdgesGRN1S ratio2=RN1S EdgesG HatRN1S EdgesGRN2S ratio2=RN2S EdgesG HatRN2S EdgesGRN3S ratio2=RN3S EdgesG HatRN3S EdgesG

RN1L ratio3=RN1L MaxDegreeG HatRN1L MaxDegreeGRN2L ratio3=RN2L MaxDegreeG HatRN2L MaxDegreeGRN3L ratio3=RN3L MaxDegreeG HatRN3L MaxDegreeGRN1S ratio3=RN1S MaxDegreeG HatRN1S MaxDegreeGRN2S ratio3=RN2S MaxDegreeG HatRN2S MaxDegreeGRN3S ratio3=RN3S MaxDegreeG HatRN3S MaxDegreeG

RN1L ratio(1)=RN1L ratio1RN1L ratio(2)=RN1L ratio2RN1L ratio(3)=RN1L ratio3

RN2L ratio(1)=RN2L ratio1RN2L ratio(2)=RN2L ratio2RN2L ratio(3)=RN2L ratio3

RN3L ratio(1)=RN3L ratio1RN3L ratio(2)=RN3L ratio2RN3L ratio(3)=RN3L ratio3

RN1S ratio(1)=RN1S ratio1RN1S ratio(2)=RN1S ratio2RN1S ratio(3)=RN1S ratio3

RN2S ratio(1)=RN2S ratio1

Appendix A 59

RN2S ratio(2)=RN2S ratio2RN2S ratio(3)=RN2S ratio3

RN3S ratio(1)=RN3S ratio1RN3S ratio(2)=RN3S ratio2RN3S ratio(3)=RN3S ratio3

RN1L ratio sorted=sortrows(RN1L ratio)RN2L ratio sorted=sortrows(RN2L ratio)RN3L ratio sorted=sortrows(RN3L ratio)RN1S ratio sorted=sortrows(RN1S ratio)RN2S ratio sorted=sortrows(RN2S ratio)RN3S ratio sorted=sortrows(RN3S ratio)

subplot(231)hold onplot(RN1L ratio sorted(1)b)plot(RN1L ratio sorted(2)g)plot(RN1L ratio sorted(3)r)grid ontitle(RN1L)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)

subplot(232)hold onplot(RN2L ratio sorted(1)b)plot(RN2L ratio sorted(2)g)plot(RN2L ratio sorted(3)r)grid ontitle(RN2L)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)

subplot(233)hold onplot(RN3L ratio sorted(1)b)plot(RN3L ratio sorted(2)g)plot(RN3L ratio sorted(3)r)grid ontitle(RN3L)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)

subplot(234)hold onplot(RN1S ratio sorted(1)b)plot(RN1S ratio sorted(2)g)plot(RN1S ratio sorted(3)r)grid on

60 Application

title(RN1S)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)

subplot(235)hold onplot(RN2S ratio sorted(1)b)plot(RN2S ratio sorted(2)g)plot(RN2S ratio sorted(3)r)grid ontitle(RN2S)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)

subplot(236)hold onplot(RN3S ratio sorted(1)b)plot(RN3S ratio sorted(2)g)plot(RN3S ratio sorted(3)r)grid ontitle(RN3S)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)set(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN5png minusr300)

h(6)=figure(NameSorted edges over nodesNumberTitleoff)

RN1L DegreeG1=(RN1L EdgesG)(RN1L NodesG)RN1L DegreeG Hat1=(RN1L EdgesG Hat)(RN1L NodesG hat)

RN1L Degree temp1(1)=RN1L DegreeG1RN1L Degree temp1(2)=RN1L DegreeG Hat1RN1L Degree sorted1=sortrows(RN1L Degree temp1)subplot(231)hold on

plot(RN1L Degree sorted1(1)b)plot(RN1L Degree sorted1(2)g)grid ontitle(RN1L)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)

RN2L DegreeG1=(RN2L EdgesG)(RN2L NodesG)RN2L DegreeG Hat1=(RN2L EdgesG Hat)(RN2L NodesG hat)

RN2L Degree temp1(1)=RN2L DegreeG1

Appendix A 61

RN2L Degree temp1(2)=RN2L DegreeG Hat1RN2L Degree sorted1=sortrows(RN2L Degree temp1)

subplot(232)hold onplot(RN2L Degree sorted1(1)b)plot(RN2L Degree sorted1(2)g)grid ontitle(RN2L)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)

RN3L DegreeG1=(RN3L EdgesG)(RN3L NodesG)RN3L DegreeG Hat1=(RN3L EdgesG Hat)(RN3L NodesG hat)

RN3L Degree temp1(1)=RN3L DegreeG1RN3L Degree temp1(2)=RN3L DegreeG Hat1RN3L Degree sorted1=sortrows(RN3L Degree temp1)

subplot(233)hold onplot(RN3L Degree sorted1(1)b)plot(RN3L Degree sorted1(2)g)grid ontitle(RN3L)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)

RN1S DegreeG1=(RN1S EdgesG)(RN1S NodesG)RN1S DegreeG Hat1=(RN1S EdgesG Hat)(RN1S NodesG hat)

RN1S Degree temp1(1)=RN1S DegreeG1RN1S Degree temp1(2)=RN1S DegreeG Hat1RN1S Degree sorted1=sortrows(RN1S Degree temp1)

subplot(234)hold onplot(RN1S Degree sorted1(1)b)plot(RN1S Degree sorted1(2)g)grid ontitle(RN1S)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)

RN2S DegreeG1=(RN2S EdgesG)(RN2S NodesG)RN2S DegreeG Hat1=(RN2S EdgesG Hat)(RN2S NodesG hat)

RN2S Degree temp1(1)=RN2S DegreeG1

62 Application

RN2S Degree temp1(2)=RN2S DegreeG Hat1RN2S Degree sorted1=sortrows(RN2S Degree temp1)

subplot(235)hold onplot(RN2S Degree sorted1(1)b)plot(RN2S Degree sorted1(2)g)grid ontitle(RN2S)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)

RN3S DegreeG1=(RN3S EdgesG)(RN3S NodesG)RN3S DegreeG Hat1=(RN3S EdgesG Hat)(RN3S NodesG hat)

RN3S Degree temp1(1)=RN3S DegreeG1RN3S Degree temp1(2)=RN3S DegreeG Hat1RN3S Degree sorted1=sortrows(RN3S Degree temp1)

subplot(236)hold onplot(RN3S Degree sorted1(1)b)plot(RN3S Degree sorted1(2)g)grid ontitle(RN3S)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)set(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN6png minusr300)h(7)=figure(NameSorted mATCHED DEGREENumberTitleoff)RN1L ratioMax(1)=RN1L MaxDegreeGRN1L ratioMax(2)=RN1L MaxDegreeG Hat

RN1L ratio sortedMax=sortrows(RN1L ratioMax)subplot(231)hold onplot(RN1L ratio sortedMax(1)b)plot(RN1L ratio sortedMax(2)g)grid ontitle(RN1L)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)

RN2L ratioMax(1)=RN2L MaxDegreeGRN2L ratioMax(2)=RN2L MaxDegreeG Hat

RN2L ratio sortedMax=sortrows(RN2L ratioMax)subplot(232)

Appendix A 63

hold onplot(RN2L ratio sortedMax(1)b)plot(RN2L ratio sortedMax(2)g)grid ontitle(RN2L)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)

RN3L ratioMax(1)=RN3L MaxDegreeGRN3L ratioMax(2)=RN3L MaxDegreeG Hat

RN3L ratio sortedMax=sortrows(RN3L ratioMax)subplot(233)hold onplot(RN3L ratio sortedMax(1)b)plot(RN3L ratio sortedMax(2)g)grid ontitle(RN3L)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)

RN1S ratioMax(1)=RN1S MaxDegreeGRN1S ratioMax(2)=RN1S MaxDegreeG Hat

RN1S ratio sortedMax=sortrows(RN1S ratioMax)subplot(234)hold onplot(RN1S ratio sortedMax(1)b)plot(RN1S ratio sortedMax(2)g)grid ontitle(RN1S)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)

RN2S ratioMax(1)=RN2S MaxDegreeGRN2S ratioMax(2)=RN2S MaxDegreeG Hat

RN2S ratio sortedMax=sortrows(RN2S ratioMax)

subplot(235)hold onplot(RN2S ratio sortedMax(1)b)plot(RN2S ratio sortedMax(2)g)grid ontitle(RN2S)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)

RN3S ratioMax(1)=RN3S MaxDegreeGRN3S ratioMax(2)=RN3S MaxDegreeG Hat

64 Application

RN3S ratio sortedMax=sortrows(RN3S ratioMax)subplot(236)hold onplot(RN3S ratio sortedMax(1)b)plot(RN3S ratio sortedMax(2)g)grid ontitle(RN1L)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)set(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN7png minusr300)

tilefigs()(h)

Bibliography

[1] C Berge ldquoTWO THEOREMS IN GRAPH THEORYrdquo Proceedings of the NationalAcademy of Sciences of the United States of America vol 43 no 9 pp 842ndash844Sep 1957

[2] L Bui S Sanghavi and R Srikant ldquoDistributed link scheduling with constantoverheadrdquo IEEEACM Trans Netw vol 17 no 5 pp 1467ndash1480 2009

[3] R Duan and S Pettie ldquoLinear-time approximation for maximum weight matchingrdquoJ ACM vol 61 no 1 2014

[4] J Edmonds ldquoPaths trees and flowersrdquo Canadian Journal of Mathematics vol 17pp 449ndash467 1965

[5] J E Hopcroft and R M Karp ldquoAn n52 algorithm for maximum matchings inbipartite graphsrdquo SIAM J Comput vol 2 no 4 pp 225ndash231 1973

[6] S Micali and V V Vazirani ldquoAn O(radic|V ||E|) algorithm for finding maximum

matching in general graphsrdquo in 21st Symp on Foundations of Comp Sc (FOCS)IEEE 1980 pp 17ndash27

[7] N Nisse A Salch and V Weber ldquoRecovery of disrupted airline operationsrdquo 2015httphalinriafrSomething

[8] X Wu and R Srikant ldquoRegulated maximal matching A distributed schedulingalgorithm for multi-hop wireless networks with nodeexclusive spectrum sharingrdquo inIEEE Conf on Decision and Control 2005

65

  • Contents
  • Introduction
  • Algorithms
    • Maximum matching
    • k-maximum matching
      • k-matching for Airport Slot assignment
      • The case where k=3
      • The case of Paths
      • The case of the Spider
          • Application
            • Description
            • Reyni Erdos
            • Barabaacutesi Albert
            • Amadeus Graphs
            • Bipartite
            • Bipartite with degree seq
            • Appendix A
              • BipartiteGraphGeneratorpy
              • RandomGraphGeneratorpy
              • kequals3MaximumMatchingpy
              • Plotmat
                  • Bibliography
Page 51: Theodoros Alexandros KARAGKIOULES -  · Introduction This work is the result of a 6 months internship, under the supervision of research O cer Nicolas NISSE. The original scope of

52 Application

histf(RN2L Finaldiff0110facecolorrfacealpha5edgealpha1)histf(RN2L Classicaldiff0110facecolorgfacealpha5edgealpha1)legalpha(ConminusGreClasminusConPerfminusClasslocationnortheast)legend boxoffaxis tightxlabel(edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN2L)grid on

subplot(233)hold onhistf(RN3L Greedydiff0110facecolorbfacealpha5edgealpha1)histf(RN3L Finaldiff0110facecolorrfacealpha5edgealpha1)histf(RN3L Classicaldiff0110facecolorgfacealpha5edgealpha1)legalpha(ConminusGreClasminusConPerfminusClasslocationnortheast)legend boxoffaxis tightxlabel(edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN3L)grid on

subplot(234)hold onhistf(RN1S Greedydiff0110facecolorbfacealpha5edgealpha1)histf(RN1S Finaldiff0110facecolorrfacealpha5edgealpha1)histf(RN1S Classicaldiff0110facecolorgfacealpha5edgealpha1)legalpha(ConminusGreClasminusConPerfminusClasslocationnortheast)legend boxoffaxis tightxlabel(edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(R1NS)grid on

subplot(235)hold onhistf(RN2S Greedydiff0110facecolorbfacealpha5edgealpha1)histf(RN2S Finaldiff0110facecolorrfacealpha5edgealpha1)histf(RN2S Classicaldiff0110facecolorgfacealpha5edgealpha1)legalpha(ConminusGreClasminusConPerfminusClasslocationnortheast)legend boxoffaxis tightxlabel(edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN2S)grid on

subplot(236)hold onhistf(RN3S Greedydiff0110facecolorbfacealpha5edgealpha1)histf(RN3S Finaldiff0110facecolorrfacealpha5edgealpha1)histf(RN3S Classicaldiff0110facecolorgfacealpha5edgealpha1)

Appendix A 53

legalpha(ConminusGreClasminusConPerfminusClasslocationnortheast)legend boxoffaxis tightgrid ontitle(RN3S)xlabel(edges) xminusaxis labelylabel(instances) yminusaxis labelset(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN1png minusr300)h(2)=figure(NameHistogram of Max Degree of G AND G HatNumberTitleoff)RN1L x=RN1L MaxDegreeGminusRN1L MaxDegreeG HatRN2L x=RN2L MaxDegreeGminusRN2L MaxDegreeG HatRN3L x=RN3L MaxDegreeGminusRN3L MaxDegreeG HatRN1S x=RN1S MaxDegreeGminusRN1S MaxDegreeG HatRN2S x=RN2S MaxDegreeGminusRN2S MaxDegreeG HatRN3S x=RN3S MaxDegreeGminusRN3S MaxDegreeG Hatsubplot(231)hold onhistf(RN1L MaxDegreeG0150facecolorbfacealpha5edgealpha1)histf(RN1L MaxDegreeG Hat0150facecolorrfacealpha5edgealpha1)histf(RN1L x0150facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightxlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN1L)grid on

subplot(232)hold onhistf(RN2L MaxDegreeG010500facecolorbfacealpha5edgealpha1)histf(RN2L MaxDegreeG Hat010500facecolorrfacealpha5edgealpha1)histf(RN2L x010500facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightxlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN2L)grid on

subplot(233)hold onhistf(RN3L MaxDegreeG010300facecolorbfacealpha5edgealpha1)histf(RN3L MaxDegreeG Hat010300facecolorrfacealpha5edgealpha1)histf(RN3L x010300facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightxlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN3L)

54 Application

grid on

subplot(234)hold onhistf(RN1S MaxDegreeG0150facecolorbfacealpha5edgealpha1)histf(RN1S MaxDegreeG Hat0150facecolorrfacealpha5edgealpha1)histf(RN1S x0150facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightxlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(R1NS)grid on

subplot(235)hold onhistf(RN2S MaxDegreeG010500facecolorbfacealpha5edgealpha1)histf(RN2S MaxDegreeG Hat010500facecolorrfacealpha5edgealpha1)histf(RN2S x010500facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightxlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN2S)grid on

subplot(236)hold onhistf(RN3S MaxDegreeG05300facecolorbfacealpha5edgealpha1)histf(RN3S MaxDegreeG Hat05300facecolorrfacealpha5edgealpha1)histf(RN3S x05300facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightgrid ontitle(RN3S)xlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labelset(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN2png minusr300)

h(3)=figure(NameComputation time over edgesNumberTitleoff)

subplot(231)hold onstem(RN1L EdgesGRN1L Time classicalg)stem(RN1L EdgesGRN1L Time algorithmro)stem(RN1L EdgesGRN1L Time greedybx)grid on

Appendix A 55

title(RN1L)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)

subplot(232)hold onstem(RN2L EdgesGRN2L Time classicalg)stem(RN2L EdgesGRN2L Time algorithmro)stem(RN2L EdgesGRN2L Time greedybx)grid ontitle(RN2L)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)

subplot(233)hold onstem(RN3L EdgesGRN3L Time classicalg)stem(RN3L EdgesGRN3L Time algorithmro)stem(RN3L EdgesGRN3L Time greedybx)grid ontitle(RN3L)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)

subplot(234)hold onstem(RN1S EdgesGRN1S Time classicalg)stem(RN1S EdgesGRN1S Time algorithmro)stem(RN1S EdgesGRN1S Time greedybx)grid ontitle(RN1S)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)

subplot(235)hold onstem(RN2S EdgesGRN2S Time classicalg)stem(RN2S EdgesGRN2S Time algorithmro)stem(RN2S EdgesGRN2S Time greedybx)grid ontitle(RN2S)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)

subplot(236)hold onstem(RN3S EdgesGRN3S Time classicalg)stem(RN3S EdgesGRN3S Time algorithmro)stem(RN3S EdgesGRN3S Time greedybx)

56 Application

grid ontitle(RN3S)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)set(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN3png minusr300)

h(4)=figure(NameSorted matching sizeNumberTitleoff)RN1L Sorted matching temp(1)=RN1L Classical matchingRN1L Sorted matching temp(2)=RN1L Final matchingRN1L Sorted matching temp(3)=RN1L Greedy matchingRN1L Sorted matching temp(4)=RN1L Initial matchingRN1L Sorted matching=sortrows(RN1L Sorted matching temp)

RN2L Sorted matching temp(1)=RN2L Classical matchingRN2L Sorted matching temp(2)=RN2L Final matchingRN2L Sorted matching temp(3)=RN2L Greedy matchingRN2L Sorted matching temp(4)=RN2L Initial matchingRN2L Sorted matching=sortrows(RN2L Sorted matching temp)

RN3L Sorted matching temp(1)=RN3L Classical matchingRN3L Sorted matching temp(2)=RN3L Final matchingRN3L Sorted matching temp(3)=RN3L Greedy matchingRN3L Sorted matching temp(4)=RN3L Initial matchingRN3L Sorted matching=sortrows(RN3L Sorted matching temp)

RN1S Sorted matching temp(1)=RN1S Classical matchingRN1S Sorted matching temp(2)=RN1S Final matchingRN1S Sorted matching temp(3)=RN1S Greedy matchingRN1S Sorted matching temp(4)=RN1S Initial matchingRN1S Sorted matching=sortrows(RN1S Sorted matching temp)

RN2S Sorted matching temp(1)=RN2S Classical matchingRN2S Sorted matching temp(2)=RN2S Final matchingRN2S Sorted matching temp(3)=RN2S Greedy matchingRN2S Sorted matching temp(4)=RN2S Initial matchingRN2S Sorted matching=sortrows(RN2S Sorted matching temp)

RN3S Sorted matching temp(1)=RN3S Classical matchingRN3S Sorted matching temp(2)=RN3S Final matchingRN3S Sorted matching temp(3)=RN3S Greedy matchingRN3S Sorted matching temp(4)=RN3S Initial matchingRN3S Sorted matching=sortrows(RN3S Sorted matching temp)

subplot(231)hold onplot(RN1L Sorted matching(1)b)plot(RN1L Sorted matching(2)g)plot(RN1L Sorted matching(3)r)plot(RN1L Sorted matching(4)m)

Appendix A 57

grid ontitle(RN1L)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)

subplot(232)hold onplot(RN2L Sorted matching(1)b)plot(RN2L Sorted matching(2)g)plot(RN2L Sorted matching(3)r)plot(RN2L Sorted matching(4)m)grid ontitle(RN2L)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)

subplot(233)hold onplot(RN3L Sorted matching(1)b)plot(RN3L Sorted matching(2)g)plot(RN3L Sorted matching(3)r)plot(RN3L Sorted matching(4)m)grid ontitle(RN3L)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)

subplot(234)hold onplot(RN1S Sorted matching(1)b)plot(RN1S Sorted matching(2)g)plot(RN1S Sorted matching(3)r)plot(RN1S Sorted matching(4)m)grid ontitle(RN1S)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)

subplot(235)hold onplot(RN2S Sorted matching(1)b)plot(RN2S Sorted matching(2)g)plot(RN2S Sorted matching(3)r)plot(RN2S Sorted matching(4)m)grid ontitle(RN2S)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)

58 Application

subplot(236)hold onplot(RN3S Sorted matching(1)b)plot(RN3S Sorted matching(2)g)plot(RN3S Sorted matching(3)r)plot(RN3S Sorted matching(4)m)grid ontitle(RN3S)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)set(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN4png minusr300)h(5)=figure(NameSorted RatiosNumberTitleoff)RN1L ratio1=RN1L NodesG hatRN1L NodesGRN2L ratio1=RN2L NodesG hatRN2L NodesGRN3L ratio1=RN3L NodesG hatRN3L NodesGRN1S ratio1=RN1S NodesG hatRN1S NodesGRN2S ratio1=RN2S NodesG hatRN2S NodesGRN3S ratio1=RN3S NodesG hatRN3S NodesG

RN1L ratio2=RN1L EdgesG HatRN1L EdgesGRN2L ratio2=RN2L EdgesG HatRN2L EdgesGRN3L ratio2=RN3L EdgesG HatRN3L EdgesGRN1S ratio2=RN1S EdgesG HatRN1S EdgesGRN2S ratio2=RN2S EdgesG HatRN2S EdgesGRN3S ratio2=RN3S EdgesG HatRN3S EdgesG

RN1L ratio3=RN1L MaxDegreeG HatRN1L MaxDegreeGRN2L ratio3=RN2L MaxDegreeG HatRN2L MaxDegreeGRN3L ratio3=RN3L MaxDegreeG HatRN3L MaxDegreeGRN1S ratio3=RN1S MaxDegreeG HatRN1S MaxDegreeGRN2S ratio3=RN2S MaxDegreeG HatRN2S MaxDegreeGRN3S ratio3=RN3S MaxDegreeG HatRN3S MaxDegreeG

RN1L ratio(1)=RN1L ratio1RN1L ratio(2)=RN1L ratio2RN1L ratio(3)=RN1L ratio3

RN2L ratio(1)=RN2L ratio1RN2L ratio(2)=RN2L ratio2RN2L ratio(3)=RN2L ratio3

RN3L ratio(1)=RN3L ratio1RN3L ratio(2)=RN3L ratio2RN3L ratio(3)=RN3L ratio3

RN1S ratio(1)=RN1S ratio1RN1S ratio(2)=RN1S ratio2RN1S ratio(3)=RN1S ratio3

RN2S ratio(1)=RN2S ratio1

Appendix A 59

RN2S ratio(2)=RN2S ratio2RN2S ratio(3)=RN2S ratio3

RN3S ratio(1)=RN3S ratio1RN3S ratio(2)=RN3S ratio2RN3S ratio(3)=RN3S ratio3

RN1L ratio sorted=sortrows(RN1L ratio)RN2L ratio sorted=sortrows(RN2L ratio)RN3L ratio sorted=sortrows(RN3L ratio)RN1S ratio sorted=sortrows(RN1S ratio)RN2S ratio sorted=sortrows(RN2S ratio)RN3S ratio sorted=sortrows(RN3S ratio)

subplot(231)hold onplot(RN1L ratio sorted(1)b)plot(RN1L ratio sorted(2)g)plot(RN1L ratio sorted(3)r)grid ontitle(RN1L)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)

subplot(232)hold onplot(RN2L ratio sorted(1)b)plot(RN2L ratio sorted(2)g)plot(RN2L ratio sorted(3)r)grid ontitle(RN2L)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)

subplot(233)hold onplot(RN3L ratio sorted(1)b)plot(RN3L ratio sorted(2)g)plot(RN3L ratio sorted(3)r)grid ontitle(RN3L)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)

subplot(234)hold onplot(RN1S ratio sorted(1)b)plot(RN1S ratio sorted(2)g)plot(RN1S ratio sorted(3)r)grid on

60 Application

title(RN1S)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)

subplot(235)hold onplot(RN2S ratio sorted(1)b)plot(RN2S ratio sorted(2)g)plot(RN2S ratio sorted(3)r)grid ontitle(RN2S)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)

subplot(236)hold onplot(RN3S ratio sorted(1)b)plot(RN3S ratio sorted(2)g)plot(RN3S ratio sorted(3)r)grid ontitle(RN3S)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)set(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN5png minusr300)

h(6)=figure(NameSorted edges over nodesNumberTitleoff)

RN1L DegreeG1=(RN1L EdgesG)(RN1L NodesG)RN1L DegreeG Hat1=(RN1L EdgesG Hat)(RN1L NodesG hat)

RN1L Degree temp1(1)=RN1L DegreeG1RN1L Degree temp1(2)=RN1L DegreeG Hat1RN1L Degree sorted1=sortrows(RN1L Degree temp1)subplot(231)hold on

plot(RN1L Degree sorted1(1)b)plot(RN1L Degree sorted1(2)g)grid ontitle(RN1L)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)

RN2L DegreeG1=(RN2L EdgesG)(RN2L NodesG)RN2L DegreeG Hat1=(RN2L EdgesG Hat)(RN2L NodesG hat)

RN2L Degree temp1(1)=RN2L DegreeG1

Appendix A 61

RN2L Degree temp1(2)=RN2L DegreeG Hat1RN2L Degree sorted1=sortrows(RN2L Degree temp1)

subplot(232)hold onplot(RN2L Degree sorted1(1)b)plot(RN2L Degree sorted1(2)g)grid ontitle(RN2L)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)

RN3L DegreeG1=(RN3L EdgesG)(RN3L NodesG)RN3L DegreeG Hat1=(RN3L EdgesG Hat)(RN3L NodesG hat)

RN3L Degree temp1(1)=RN3L DegreeG1RN3L Degree temp1(2)=RN3L DegreeG Hat1RN3L Degree sorted1=sortrows(RN3L Degree temp1)

subplot(233)hold onplot(RN3L Degree sorted1(1)b)plot(RN3L Degree sorted1(2)g)grid ontitle(RN3L)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)

RN1S DegreeG1=(RN1S EdgesG)(RN1S NodesG)RN1S DegreeG Hat1=(RN1S EdgesG Hat)(RN1S NodesG hat)

RN1S Degree temp1(1)=RN1S DegreeG1RN1S Degree temp1(2)=RN1S DegreeG Hat1RN1S Degree sorted1=sortrows(RN1S Degree temp1)

subplot(234)hold onplot(RN1S Degree sorted1(1)b)plot(RN1S Degree sorted1(2)g)grid ontitle(RN1S)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)

RN2S DegreeG1=(RN2S EdgesG)(RN2S NodesG)RN2S DegreeG Hat1=(RN2S EdgesG Hat)(RN2S NodesG hat)

RN2S Degree temp1(1)=RN2S DegreeG1

62 Application

RN2S Degree temp1(2)=RN2S DegreeG Hat1RN2S Degree sorted1=sortrows(RN2S Degree temp1)

subplot(235)hold onplot(RN2S Degree sorted1(1)b)plot(RN2S Degree sorted1(2)g)grid ontitle(RN2S)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)

RN3S DegreeG1=(RN3S EdgesG)(RN3S NodesG)RN3S DegreeG Hat1=(RN3S EdgesG Hat)(RN3S NodesG hat)

RN3S Degree temp1(1)=RN3S DegreeG1RN3S Degree temp1(2)=RN3S DegreeG Hat1RN3S Degree sorted1=sortrows(RN3S Degree temp1)

subplot(236)hold onplot(RN3S Degree sorted1(1)b)plot(RN3S Degree sorted1(2)g)grid ontitle(RN3S)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)set(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN6png minusr300)h(7)=figure(NameSorted mATCHED DEGREENumberTitleoff)RN1L ratioMax(1)=RN1L MaxDegreeGRN1L ratioMax(2)=RN1L MaxDegreeG Hat

RN1L ratio sortedMax=sortrows(RN1L ratioMax)subplot(231)hold onplot(RN1L ratio sortedMax(1)b)plot(RN1L ratio sortedMax(2)g)grid ontitle(RN1L)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)

RN2L ratioMax(1)=RN2L MaxDegreeGRN2L ratioMax(2)=RN2L MaxDegreeG Hat

RN2L ratio sortedMax=sortrows(RN2L ratioMax)subplot(232)

Appendix A 63

hold onplot(RN2L ratio sortedMax(1)b)plot(RN2L ratio sortedMax(2)g)grid ontitle(RN2L)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)

RN3L ratioMax(1)=RN3L MaxDegreeGRN3L ratioMax(2)=RN3L MaxDegreeG Hat

RN3L ratio sortedMax=sortrows(RN3L ratioMax)subplot(233)hold onplot(RN3L ratio sortedMax(1)b)plot(RN3L ratio sortedMax(2)g)grid ontitle(RN3L)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)

RN1S ratioMax(1)=RN1S MaxDegreeGRN1S ratioMax(2)=RN1S MaxDegreeG Hat

RN1S ratio sortedMax=sortrows(RN1S ratioMax)subplot(234)hold onplot(RN1S ratio sortedMax(1)b)plot(RN1S ratio sortedMax(2)g)grid ontitle(RN1S)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)

RN2S ratioMax(1)=RN2S MaxDegreeGRN2S ratioMax(2)=RN2S MaxDegreeG Hat

RN2S ratio sortedMax=sortrows(RN2S ratioMax)

subplot(235)hold onplot(RN2S ratio sortedMax(1)b)plot(RN2S ratio sortedMax(2)g)grid ontitle(RN2S)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)

RN3S ratioMax(1)=RN3S MaxDegreeGRN3S ratioMax(2)=RN3S MaxDegreeG Hat

64 Application

RN3S ratio sortedMax=sortrows(RN3S ratioMax)subplot(236)hold onplot(RN3S ratio sortedMax(1)b)plot(RN3S ratio sortedMax(2)g)grid ontitle(RN1L)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)set(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN7png minusr300)

tilefigs()(h)

Bibliography

[1] C Berge ldquoTWO THEOREMS IN GRAPH THEORYrdquo Proceedings of the NationalAcademy of Sciences of the United States of America vol 43 no 9 pp 842ndash844Sep 1957

[2] L Bui S Sanghavi and R Srikant ldquoDistributed link scheduling with constantoverheadrdquo IEEEACM Trans Netw vol 17 no 5 pp 1467ndash1480 2009

[3] R Duan and S Pettie ldquoLinear-time approximation for maximum weight matchingrdquoJ ACM vol 61 no 1 2014

[4] J Edmonds ldquoPaths trees and flowersrdquo Canadian Journal of Mathematics vol 17pp 449ndash467 1965

[5] J E Hopcroft and R M Karp ldquoAn n52 algorithm for maximum matchings inbipartite graphsrdquo SIAM J Comput vol 2 no 4 pp 225ndash231 1973

[6] S Micali and V V Vazirani ldquoAn O(radic|V ||E|) algorithm for finding maximum

matching in general graphsrdquo in 21st Symp on Foundations of Comp Sc (FOCS)IEEE 1980 pp 17ndash27

[7] N Nisse A Salch and V Weber ldquoRecovery of disrupted airline operationsrdquo 2015httphalinriafrSomething

[8] X Wu and R Srikant ldquoRegulated maximal matching A distributed schedulingalgorithm for multi-hop wireless networks with nodeexclusive spectrum sharingrdquo inIEEE Conf on Decision and Control 2005

65

  • Contents
  • Introduction
  • Algorithms
    • Maximum matching
    • k-maximum matching
      • k-matching for Airport Slot assignment
      • The case where k=3
      • The case of Paths
      • The case of the Spider
          • Application
            • Description
            • Reyni Erdos
            • Barabaacutesi Albert
            • Amadeus Graphs
            • Bipartite
            • Bipartite with degree seq
            • Appendix A
              • BipartiteGraphGeneratorpy
              • RandomGraphGeneratorpy
              • kequals3MaximumMatchingpy
              • Plotmat
                  • Bibliography
Page 52: Theodoros Alexandros KARAGKIOULES -  · Introduction This work is the result of a 6 months internship, under the supervision of research O cer Nicolas NISSE. The original scope of

Appendix A 53

legalpha(ConminusGreClasminusConPerfminusClasslocationnortheast)legend boxoffaxis tightgrid ontitle(RN3S)xlabel(edges) xminusaxis labelylabel(instances) yminusaxis labelset(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN1png minusr300)h(2)=figure(NameHistogram of Max Degree of G AND G HatNumberTitleoff)RN1L x=RN1L MaxDegreeGminusRN1L MaxDegreeG HatRN2L x=RN2L MaxDegreeGminusRN2L MaxDegreeG HatRN3L x=RN3L MaxDegreeGminusRN3L MaxDegreeG HatRN1S x=RN1S MaxDegreeGminusRN1S MaxDegreeG HatRN2S x=RN2S MaxDegreeGminusRN2S MaxDegreeG HatRN3S x=RN3S MaxDegreeGminusRN3S MaxDegreeG Hatsubplot(231)hold onhistf(RN1L MaxDegreeG0150facecolorbfacealpha5edgealpha1)histf(RN1L MaxDegreeG Hat0150facecolorrfacealpha5edgealpha1)histf(RN1L x0150facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightxlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN1L)grid on

subplot(232)hold onhistf(RN2L MaxDegreeG010500facecolorbfacealpha5edgealpha1)histf(RN2L MaxDegreeG Hat010500facecolorrfacealpha5edgealpha1)histf(RN2L x010500facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightxlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN2L)grid on

subplot(233)hold onhistf(RN3L MaxDegreeG010300facecolorbfacealpha5edgealpha1)histf(RN3L MaxDegreeG Hat010300facecolorrfacealpha5edgealpha1)histf(RN3L x010300facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightxlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN3L)

54 Application

grid on

subplot(234)hold onhistf(RN1S MaxDegreeG0150facecolorbfacealpha5edgealpha1)histf(RN1S MaxDegreeG Hat0150facecolorrfacealpha5edgealpha1)histf(RN1S x0150facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightxlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(R1NS)grid on

subplot(235)hold onhistf(RN2S MaxDegreeG010500facecolorbfacealpha5edgealpha1)histf(RN2S MaxDegreeG Hat010500facecolorrfacealpha5edgealpha1)histf(RN2S x010500facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightxlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN2S)grid on

subplot(236)hold onhistf(RN3S MaxDegreeG05300facecolorbfacealpha5edgealpha1)histf(RN3S MaxDegreeG Hat05300facecolorrfacealpha5edgealpha1)histf(RN3S x05300facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightgrid ontitle(RN3S)xlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labelset(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN2png minusr300)

h(3)=figure(NameComputation time over edgesNumberTitleoff)

subplot(231)hold onstem(RN1L EdgesGRN1L Time classicalg)stem(RN1L EdgesGRN1L Time algorithmro)stem(RN1L EdgesGRN1L Time greedybx)grid on

Appendix A 55

title(RN1L)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)

subplot(232)hold onstem(RN2L EdgesGRN2L Time classicalg)stem(RN2L EdgesGRN2L Time algorithmro)stem(RN2L EdgesGRN2L Time greedybx)grid ontitle(RN2L)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)

subplot(233)hold onstem(RN3L EdgesGRN3L Time classicalg)stem(RN3L EdgesGRN3L Time algorithmro)stem(RN3L EdgesGRN3L Time greedybx)grid ontitle(RN3L)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)

subplot(234)hold onstem(RN1S EdgesGRN1S Time classicalg)stem(RN1S EdgesGRN1S Time algorithmro)stem(RN1S EdgesGRN1S Time greedybx)grid ontitle(RN1S)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)

subplot(235)hold onstem(RN2S EdgesGRN2S Time classicalg)stem(RN2S EdgesGRN2S Time algorithmro)stem(RN2S EdgesGRN2S Time greedybx)grid ontitle(RN2S)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)

subplot(236)hold onstem(RN3S EdgesGRN3S Time classicalg)stem(RN3S EdgesGRN3S Time algorithmro)stem(RN3S EdgesGRN3S Time greedybx)

56 Application

grid ontitle(RN3S)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)set(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN3png minusr300)

h(4)=figure(NameSorted matching sizeNumberTitleoff)RN1L Sorted matching temp(1)=RN1L Classical matchingRN1L Sorted matching temp(2)=RN1L Final matchingRN1L Sorted matching temp(3)=RN1L Greedy matchingRN1L Sorted matching temp(4)=RN1L Initial matchingRN1L Sorted matching=sortrows(RN1L Sorted matching temp)

RN2L Sorted matching temp(1)=RN2L Classical matchingRN2L Sorted matching temp(2)=RN2L Final matchingRN2L Sorted matching temp(3)=RN2L Greedy matchingRN2L Sorted matching temp(4)=RN2L Initial matchingRN2L Sorted matching=sortrows(RN2L Sorted matching temp)

RN3L Sorted matching temp(1)=RN3L Classical matchingRN3L Sorted matching temp(2)=RN3L Final matchingRN3L Sorted matching temp(3)=RN3L Greedy matchingRN3L Sorted matching temp(4)=RN3L Initial matchingRN3L Sorted matching=sortrows(RN3L Sorted matching temp)

RN1S Sorted matching temp(1)=RN1S Classical matchingRN1S Sorted matching temp(2)=RN1S Final matchingRN1S Sorted matching temp(3)=RN1S Greedy matchingRN1S Sorted matching temp(4)=RN1S Initial matchingRN1S Sorted matching=sortrows(RN1S Sorted matching temp)

RN2S Sorted matching temp(1)=RN2S Classical matchingRN2S Sorted matching temp(2)=RN2S Final matchingRN2S Sorted matching temp(3)=RN2S Greedy matchingRN2S Sorted matching temp(4)=RN2S Initial matchingRN2S Sorted matching=sortrows(RN2S Sorted matching temp)

RN3S Sorted matching temp(1)=RN3S Classical matchingRN3S Sorted matching temp(2)=RN3S Final matchingRN3S Sorted matching temp(3)=RN3S Greedy matchingRN3S Sorted matching temp(4)=RN3S Initial matchingRN3S Sorted matching=sortrows(RN3S Sorted matching temp)

subplot(231)hold onplot(RN1L Sorted matching(1)b)plot(RN1L Sorted matching(2)g)plot(RN1L Sorted matching(3)r)plot(RN1L Sorted matching(4)m)

Appendix A 57

grid ontitle(RN1L)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)

subplot(232)hold onplot(RN2L Sorted matching(1)b)plot(RN2L Sorted matching(2)g)plot(RN2L Sorted matching(3)r)plot(RN2L Sorted matching(4)m)grid ontitle(RN2L)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)

subplot(233)hold onplot(RN3L Sorted matching(1)b)plot(RN3L Sorted matching(2)g)plot(RN3L Sorted matching(3)r)plot(RN3L Sorted matching(4)m)grid ontitle(RN3L)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)

subplot(234)hold onplot(RN1S Sorted matching(1)b)plot(RN1S Sorted matching(2)g)plot(RN1S Sorted matching(3)r)plot(RN1S Sorted matching(4)m)grid ontitle(RN1S)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)

subplot(235)hold onplot(RN2S Sorted matching(1)b)plot(RN2S Sorted matching(2)g)plot(RN2S Sorted matching(3)r)plot(RN2S Sorted matching(4)m)grid ontitle(RN2S)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)

58 Application

subplot(236)hold onplot(RN3S Sorted matching(1)b)plot(RN3S Sorted matching(2)g)plot(RN3S Sorted matching(3)r)plot(RN3S Sorted matching(4)m)grid ontitle(RN3S)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)set(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN4png minusr300)h(5)=figure(NameSorted RatiosNumberTitleoff)RN1L ratio1=RN1L NodesG hatRN1L NodesGRN2L ratio1=RN2L NodesG hatRN2L NodesGRN3L ratio1=RN3L NodesG hatRN3L NodesGRN1S ratio1=RN1S NodesG hatRN1S NodesGRN2S ratio1=RN2S NodesG hatRN2S NodesGRN3S ratio1=RN3S NodesG hatRN3S NodesG

RN1L ratio2=RN1L EdgesG HatRN1L EdgesGRN2L ratio2=RN2L EdgesG HatRN2L EdgesGRN3L ratio2=RN3L EdgesG HatRN3L EdgesGRN1S ratio2=RN1S EdgesG HatRN1S EdgesGRN2S ratio2=RN2S EdgesG HatRN2S EdgesGRN3S ratio2=RN3S EdgesG HatRN3S EdgesG

RN1L ratio3=RN1L MaxDegreeG HatRN1L MaxDegreeGRN2L ratio3=RN2L MaxDegreeG HatRN2L MaxDegreeGRN3L ratio3=RN3L MaxDegreeG HatRN3L MaxDegreeGRN1S ratio3=RN1S MaxDegreeG HatRN1S MaxDegreeGRN2S ratio3=RN2S MaxDegreeG HatRN2S MaxDegreeGRN3S ratio3=RN3S MaxDegreeG HatRN3S MaxDegreeG

RN1L ratio(1)=RN1L ratio1RN1L ratio(2)=RN1L ratio2RN1L ratio(3)=RN1L ratio3

RN2L ratio(1)=RN2L ratio1RN2L ratio(2)=RN2L ratio2RN2L ratio(3)=RN2L ratio3

RN3L ratio(1)=RN3L ratio1RN3L ratio(2)=RN3L ratio2RN3L ratio(3)=RN3L ratio3

RN1S ratio(1)=RN1S ratio1RN1S ratio(2)=RN1S ratio2RN1S ratio(3)=RN1S ratio3

RN2S ratio(1)=RN2S ratio1

Appendix A 59

RN2S ratio(2)=RN2S ratio2RN2S ratio(3)=RN2S ratio3

RN3S ratio(1)=RN3S ratio1RN3S ratio(2)=RN3S ratio2RN3S ratio(3)=RN3S ratio3

RN1L ratio sorted=sortrows(RN1L ratio)RN2L ratio sorted=sortrows(RN2L ratio)RN3L ratio sorted=sortrows(RN3L ratio)RN1S ratio sorted=sortrows(RN1S ratio)RN2S ratio sorted=sortrows(RN2S ratio)RN3S ratio sorted=sortrows(RN3S ratio)

subplot(231)hold onplot(RN1L ratio sorted(1)b)plot(RN1L ratio sorted(2)g)plot(RN1L ratio sorted(3)r)grid ontitle(RN1L)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)

subplot(232)hold onplot(RN2L ratio sorted(1)b)plot(RN2L ratio sorted(2)g)plot(RN2L ratio sorted(3)r)grid ontitle(RN2L)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)

subplot(233)hold onplot(RN3L ratio sorted(1)b)plot(RN3L ratio sorted(2)g)plot(RN3L ratio sorted(3)r)grid ontitle(RN3L)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)

subplot(234)hold onplot(RN1S ratio sorted(1)b)plot(RN1S ratio sorted(2)g)plot(RN1S ratio sorted(3)r)grid on

60 Application

title(RN1S)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)

subplot(235)hold onplot(RN2S ratio sorted(1)b)plot(RN2S ratio sorted(2)g)plot(RN2S ratio sorted(3)r)grid ontitle(RN2S)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)

subplot(236)hold onplot(RN3S ratio sorted(1)b)plot(RN3S ratio sorted(2)g)plot(RN3S ratio sorted(3)r)grid ontitle(RN3S)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)set(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN5png minusr300)

h(6)=figure(NameSorted edges over nodesNumberTitleoff)

RN1L DegreeG1=(RN1L EdgesG)(RN1L NodesG)RN1L DegreeG Hat1=(RN1L EdgesG Hat)(RN1L NodesG hat)

RN1L Degree temp1(1)=RN1L DegreeG1RN1L Degree temp1(2)=RN1L DegreeG Hat1RN1L Degree sorted1=sortrows(RN1L Degree temp1)subplot(231)hold on

plot(RN1L Degree sorted1(1)b)plot(RN1L Degree sorted1(2)g)grid ontitle(RN1L)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)

RN2L DegreeG1=(RN2L EdgesG)(RN2L NodesG)RN2L DegreeG Hat1=(RN2L EdgesG Hat)(RN2L NodesG hat)

RN2L Degree temp1(1)=RN2L DegreeG1

Appendix A 61

RN2L Degree temp1(2)=RN2L DegreeG Hat1RN2L Degree sorted1=sortrows(RN2L Degree temp1)

subplot(232)hold onplot(RN2L Degree sorted1(1)b)plot(RN2L Degree sorted1(2)g)grid ontitle(RN2L)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)

RN3L DegreeG1=(RN3L EdgesG)(RN3L NodesG)RN3L DegreeG Hat1=(RN3L EdgesG Hat)(RN3L NodesG hat)

RN3L Degree temp1(1)=RN3L DegreeG1RN3L Degree temp1(2)=RN3L DegreeG Hat1RN3L Degree sorted1=sortrows(RN3L Degree temp1)

subplot(233)hold onplot(RN3L Degree sorted1(1)b)plot(RN3L Degree sorted1(2)g)grid ontitle(RN3L)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)

RN1S DegreeG1=(RN1S EdgesG)(RN1S NodesG)RN1S DegreeG Hat1=(RN1S EdgesG Hat)(RN1S NodesG hat)

RN1S Degree temp1(1)=RN1S DegreeG1RN1S Degree temp1(2)=RN1S DegreeG Hat1RN1S Degree sorted1=sortrows(RN1S Degree temp1)

subplot(234)hold onplot(RN1S Degree sorted1(1)b)plot(RN1S Degree sorted1(2)g)grid ontitle(RN1S)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)

RN2S DegreeG1=(RN2S EdgesG)(RN2S NodesG)RN2S DegreeG Hat1=(RN2S EdgesG Hat)(RN2S NodesG hat)

RN2S Degree temp1(1)=RN2S DegreeG1

62 Application

RN2S Degree temp1(2)=RN2S DegreeG Hat1RN2S Degree sorted1=sortrows(RN2S Degree temp1)

subplot(235)hold onplot(RN2S Degree sorted1(1)b)plot(RN2S Degree sorted1(2)g)grid ontitle(RN2S)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)

RN3S DegreeG1=(RN3S EdgesG)(RN3S NodesG)RN3S DegreeG Hat1=(RN3S EdgesG Hat)(RN3S NodesG hat)

RN3S Degree temp1(1)=RN3S DegreeG1RN3S Degree temp1(2)=RN3S DegreeG Hat1RN3S Degree sorted1=sortrows(RN3S Degree temp1)

subplot(236)hold onplot(RN3S Degree sorted1(1)b)plot(RN3S Degree sorted1(2)g)grid ontitle(RN3S)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)set(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN6png minusr300)h(7)=figure(NameSorted mATCHED DEGREENumberTitleoff)RN1L ratioMax(1)=RN1L MaxDegreeGRN1L ratioMax(2)=RN1L MaxDegreeG Hat

RN1L ratio sortedMax=sortrows(RN1L ratioMax)subplot(231)hold onplot(RN1L ratio sortedMax(1)b)plot(RN1L ratio sortedMax(2)g)grid ontitle(RN1L)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)

RN2L ratioMax(1)=RN2L MaxDegreeGRN2L ratioMax(2)=RN2L MaxDegreeG Hat

RN2L ratio sortedMax=sortrows(RN2L ratioMax)subplot(232)

Appendix A 63

hold onplot(RN2L ratio sortedMax(1)b)plot(RN2L ratio sortedMax(2)g)grid ontitle(RN2L)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)

RN3L ratioMax(1)=RN3L MaxDegreeGRN3L ratioMax(2)=RN3L MaxDegreeG Hat

RN3L ratio sortedMax=sortrows(RN3L ratioMax)subplot(233)hold onplot(RN3L ratio sortedMax(1)b)plot(RN3L ratio sortedMax(2)g)grid ontitle(RN3L)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)

RN1S ratioMax(1)=RN1S MaxDegreeGRN1S ratioMax(2)=RN1S MaxDegreeG Hat

RN1S ratio sortedMax=sortrows(RN1S ratioMax)subplot(234)hold onplot(RN1S ratio sortedMax(1)b)plot(RN1S ratio sortedMax(2)g)grid ontitle(RN1S)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)

RN2S ratioMax(1)=RN2S MaxDegreeGRN2S ratioMax(2)=RN2S MaxDegreeG Hat

RN2S ratio sortedMax=sortrows(RN2S ratioMax)

subplot(235)hold onplot(RN2S ratio sortedMax(1)b)plot(RN2S ratio sortedMax(2)g)grid ontitle(RN2S)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)

RN3S ratioMax(1)=RN3S MaxDegreeGRN3S ratioMax(2)=RN3S MaxDegreeG Hat

64 Application

RN3S ratio sortedMax=sortrows(RN3S ratioMax)subplot(236)hold onplot(RN3S ratio sortedMax(1)b)plot(RN3S ratio sortedMax(2)g)grid ontitle(RN1L)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)set(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN7png minusr300)

tilefigs()(h)

Bibliography

[1] C Berge ldquoTWO THEOREMS IN GRAPH THEORYrdquo Proceedings of the NationalAcademy of Sciences of the United States of America vol 43 no 9 pp 842ndash844Sep 1957

[2] L Bui S Sanghavi and R Srikant ldquoDistributed link scheduling with constantoverheadrdquo IEEEACM Trans Netw vol 17 no 5 pp 1467ndash1480 2009

[3] R Duan and S Pettie ldquoLinear-time approximation for maximum weight matchingrdquoJ ACM vol 61 no 1 2014

[4] J Edmonds ldquoPaths trees and flowersrdquo Canadian Journal of Mathematics vol 17pp 449ndash467 1965

[5] J E Hopcroft and R M Karp ldquoAn n52 algorithm for maximum matchings inbipartite graphsrdquo SIAM J Comput vol 2 no 4 pp 225ndash231 1973

[6] S Micali and V V Vazirani ldquoAn O(radic|V ||E|) algorithm for finding maximum

matching in general graphsrdquo in 21st Symp on Foundations of Comp Sc (FOCS)IEEE 1980 pp 17ndash27

[7] N Nisse A Salch and V Weber ldquoRecovery of disrupted airline operationsrdquo 2015httphalinriafrSomething

[8] X Wu and R Srikant ldquoRegulated maximal matching A distributed schedulingalgorithm for multi-hop wireless networks with nodeexclusive spectrum sharingrdquo inIEEE Conf on Decision and Control 2005

65

  • Contents
  • Introduction
  • Algorithms
    • Maximum matching
    • k-maximum matching
      • k-matching for Airport Slot assignment
      • The case where k=3
      • The case of Paths
      • The case of the Spider
          • Application
            • Description
            • Reyni Erdos
            • Barabaacutesi Albert
            • Amadeus Graphs
            • Bipartite
            • Bipartite with degree seq
            • Appendix A
              • BipartiteGraphGeneratorpy
              • RandomGraphGeneratorpy
              • kequals3MaximumMatchingpy
              • Plotmat
                  • Bibliography
Page 53: Theodoros Alexandros KARAGKIOULES -  · Introduction This work is the result of a 6 months internship, under the supervision of research O cer Nicolas NISSE. The original scope of

54 Application

grid on

subplot(234)hold onhistf(RN1S MaxDegreeG0150facecolorbfacealpha5edgealpha1)histf(RN1S MaxDegreeG Hat0150facecolorrfacealpha5edgealpha1)histf(RN1S x0150facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightxlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(R1NS)grid on

subplot(235)hold onhistf(RN2S MaxDegreeG010500facecolorbfacealpha5edgealpha1)histf(RN2S MaxDegreeG Hat010500facecolorrfacealpha5edgealpha1)histf(RN2S x010500facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightxlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labeltitle(RN2S)grid on

subplot(236)hold onhistf(RN3S MaxDegreeG05300facecolorbfacealpha5edgealpha1)histf(RN3S MaxDegreeG Hat05300facecolorrfacealpha5edgealpha1)histf(RN3S x05300facecolorcfacealpha5edgealpha1)legalpha(GGHatdifflocationnortheast)legend boxoffaxis tightgrid ontitle(RN3S)xlabel(MAX edges) xminusaxis labelylabel(instances) yminusaxis labelset(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN2png minusr300)

h(3)=figure(NameComputation time over edgesNumberTitleoff)

subplot(231)hold onstem(RN1L EdgesGRN1L Time classicalg)stem(RN1L EdgesGRN1L Time algorithmro)stem(RN1L EdgesGRN1L Time greedybx)grid on

Appendix A 55

title(RN1L)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)

subplot(232)hold onstem(RN2L EdgesGRN2L Time classicalg)stem(RN2L EdgesGRN2L Time algorithmro)stem(RN2L EdgesGRN2L Time greedybx)grid ontitle(RN2L)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)

subplot(233)hold onstem(RN3L EdgesGRN3L Time classicalg)stem(RN3L EdgesGRN3L Time algorithmro)stem(RN3L EdgesGRN3L Time greedybx)grid ontitle(RN3L)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)

subplot(234)hold onstem(RN1S EdgesGRN1S Time classicalg)stem(RN1S EdgesGRN1S Time algorithmro)stem(RN1S EdgesGRN1S Time greedybx)grid ontitle(RN1S)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)

subplot(235)hold onstem(RN2S EdgesGRN2S Time classicalg)stem(RN2S EdgesGRN2S Time algorithmro)stem(RN2S EdgesGRN2S Time greedybx)grid ontitle(RN2S)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)

subplot(236)hold onstem(RN3S EdgesGRN3S Time classicalg)stem(RN3S EdgesGRN3S Time algorithmro)stem(RN3S EdgesGRN3S Time greedybx)

56 Application

grid ontitle(RN3S)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)set(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN3png minusr300)

h(4)=figure(NameSorted matching sizeNumberTitleoff)RN1L Sorted matching temp(1)=RN1L Classical matchingRN1L Sorted matching temp(2)=RN1L Final matchingRN1L Sorted matching temp(3)=RN1L Greedy matchingRN1L Sorted matching temp(4)=RN1L Initial matchingRN1L Sorted matching=sortrows(RN1L Sorted matching temp)

RN2L Sorted matching temp(1)=RN2L Classical matchingRN2L Sorted matching temp(2)=RN2L Final matchingRN2L Sorted matching temp(3)=RN2L Greedy matchingRN2L Sorted matching temp(4)=RN2L Initial matchingRN2L Sorted matching=sortrows(RN2L Sorted matching temp)

RN3L Sorted matching temp(1)=RN3L Classical matchingRN3L Sorted matching temp(2)=RN3L Final matchingRN3L Sorted matching temp(3)=RN3L Greedy matchingRN3L Sorted matching temp(4)=RN3L Initial matchingRN3L Sorted matching=sortrows(RN3L Sorted matching temp)

RN1S Sorted matching temp(1)=RN1S Classical matchingRN1S Sorted matching temp(2)=RN1S Final matchingRN1S Sorted matching temp(3)=RN1S Greedy matchingRN1S Sorted matching temp(4)=RN1S Initial matchingRN1S Sorted matching=sortrows(RN1S Sorted matching temp)

RN2S Sorted matching temp(1)=RN2S Classical matchingRN2S Sorted matching temp(2)=RN2S Final matchingRN2S Sorted matching temp(3)=RN2S Greedy matchingRN2S Sorted matching temp(4)=RN2S Initial matchingRN2S Sorted matching=sortrows(RN2S Sorted matching temp)

RN3S Sorted matching temp(1)=RN3S Classical matchingRN3S Sorted matching temp(2)=RN3S Final matchingRN3S Sorted matching temp(3)=RN3S Greedy matchingRN3S Sorted matching temp(4)=RN3S Initial matchingRN3S Sorted matching=sortrows(RN3S Sorted matching temp)

subplot(231)hold onplot(RN1L Sorted matching(1)b)plot(RN1L Sorted matching(2)g)plot(RN1L Sorted matching(3)r)plot(RN1L Sorted matching(4)m)

Appendix A 57

grid ontitle(RN1L)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)

subplot(232)hold onplot(RN2L Sorted matching(1)b)plot(RN2L Sorted matching(2)g)plot(RN2L Sorted matching(3)r)plot(RN2L Sorted matching(4)m)grid ontitle(RN2L)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)

subplot(233)hold onplot(RN3L Sorted matching(1)b)plot(RN3L Sorted matching(2)g)plot(RN3L Sorted matching(3)r)plot(RN3L Sorted matching(4)m)grid ontitle(RN3L)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)

subplot(234)hold onplot(RN1S Sorted matching(1)b)plot(RN1S Sorted matching(2)g)plot(RN1S Sorted matching(3)r)plot(RN1S Sorted matching(4)m)grid ontitle(RN1S)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)

subplot(235)hold onplot(RN2S Sorted matching(1)b)plot(RN2S Sorted matching(2)g)plot(RN2S Sorted matching(3)r)plot(RN2S Sorted matching(4)m)grid ontitle(RN2S)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)

58 Application

subplot(236)hold onplot(RN3S Sorted matching(1)b)plot(RN3S Sorted matching(2)g)plot(RN3S Sorted matching(3)r)plot(RN3S Sorted matching(4)m)grid ontitle(RN3S)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)set(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN4png minusr300)h(5)=figure(NameSorted RatiosNumberTitleoff)RN1L ratio1=RN1L NodesG hatRN1L NodesGRN2L ratio1=RN2L NodesG hatRN2L NodesGRN3L ratio1=RN3L NodesG hatRN3L NodesGRN1S ratio1=RN1S NodesG hatRN1S NodesGRN2S ratio1=RN2S NodesG hatRN2S NodesGRN3S ratio1=RN3S NodesG hatRN3S NodesG

RN1L ratio2=RN1L EdgesG HatRN1L EdgesGRN2L ratio2=RN2L EdgesG HatRN2L EdgesGRN3L ratio2=RN3L EdgesG HatRN3L EdgesGRN1S ratio2=RN1S EdgesG HatRN1S EdgesGRN2S ratio2=RN2S EdgesG HatRN2S EdgesGRN3S ratio2=RN3S EdgesG HatRN3S EdgesG

RN1L ratio3=RN1L MaxDegreeG HatRN1L MaxDegreeGRN2L ratio3=RN2L MaxDegreeG HatRN2L MaxDegreeGRN3L ratio3=RN3L MaxDegreeG HatRN3L MaxDegreeGRN1S ratio3=RN1S MaxDegreeG HatRN1S MaxDegreeGRN2S ratio3=RN2S MaxDegreeG HatRN2S MaxDegreeGRN3S ratio3=RN3S MaxDegreeG HatRN3S MaxDegreeG

RN1L ratio(1)=RN1L ratio1RN1L ratio(2)=RN1L ratio2RN1L ratio(3)=RN1L ratio3

RN2L ratio(1)=RN2L ratio1RN2L ratio(2)=RN2L ratio2RN2L ratio(3)=RN2L ratio3

RN3L ratio(1)=RN3L ratio1RN3L ratio(2)=RN3L ratio2RN3L ratio(3)=RN3L ratio3

RN1S ratio(1)=RN1S ratio1RN1S ratio(2)=RN1S ratio2RN1S ratio(3)=RN1S ratio3

RN2S ratio(1)=RN2S ratio1

Appendix A 59

RN2S ratio(2)=RN2S ratio2RN2S ratio(3)=RN2S ratio3

RN3S ratio(1)=RN3S ratio1RN3S ratio(2)=RN3S ratio2RN3S ratio(3)=RN3S ratio3

RN1L ratio sorted=sortrows(RN1L ratio)RN2L ratio sorted=sortrows(RN2L ratio)RN3L ratio sorted=sortrows(RN3L ratio)RN1S ratio sorted=sortrows(RN1S ratio)RN2S ratio sorted=sortrows(RN2S ratio)RN3S ratio sorted=sortrows(RN3S ratio)

subplot(231)hold onplot(RN1L ratio sorted(1)b)plot(RN1L ratio sorted(2)g)plot(RN1L ratio sorted(3)r)grid ontitle(RN1L)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)

subplot(232)hold onplot(RN2L ratio sorted(1)b)plot(RN2L ratio sorted(2)g)plot(RN2L ratio sorted(3)r)grid ontitle(RN2L)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)

subplot(233)hold onplot(RN3L ratio sorted(1)b)plot(RN3L ratio sorted(2)g)plot(RN3L ratio sorted(3)r)grid ontitle(RN3L)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)

subplot(234)hold onplot(RN1S ratio sorted(1)b)plot(RN1S ratio sorted(2)g)plot(RN1S ratio sorted(3)r)grid on

60 Application

title(RN1S)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)

subplot(235)hold onplot(RN2S ratio sorted(1)b)plot(RN2S ratio sorted(2)g)plot(RN2S ratio sorted(3)r)grid ontitle(RN2S)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)

subplot(236)hold onplot(RN3S ratio sorted(1)b)plot(RN3S ratio sorted(2)g)plot(RN3S ratio sorted(3)r)grid ontitle(RN3S)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)set(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN5png minusr300)

h(6)=figure(NameSorted edges over nodesNumberTitleoff)

RN1L DegreeG1=(RN1L EdgesG)(RN1L NodesG)RN1L DegreeG Hat1=(RN1L EdgesG Hat)(RN1L NodesG hat)

RN1L Degree temp1(1)=RN1L DegreeG1RN1L Degree temp1(2)=RN1L DegreeG Hat1RN1L Degree sorted1=sortrows(RN1L Degree temp1)subplot(231)hold on

plot(RN1L Degree sorted1(1)b)plot(RN1L Degree sorted1(2)g)grid ontitle(RN1L)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)

RN2L DegreeG1=(RN2L EdgesG)(RN2L NodesG)RN2L DegreeG Hat1=(RN2L EdgesG Hat)(RN2L NodesG hat)

RN2L Degree temp1(1)=RN2L DegreeG1

Appendix A 61

RN2L Degree temp1(2)=RN2L DegreeG Hat1RN2L Degree sorted1=sortrows(RN2L Degree temp1)

subplot(232)hold onplot(RN2L Degree sorted1(1)b)plot(RN2L Degree sorted1(2)g)grid ontitle(RN2L)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)

RN3L DegreeG1=(RN3L EdgesG)(RN3L NodesG)RN3L DegreeG Hat1=(RN3L EdgesG Hat)(RN3L NodesG hat)

RN3L Degree temp1(1)=RN3L DegreeG1RN3L Degree temp1(2)=RN3L DegreeG Hat1RN3L Degree sorted1=sortrows(RN3L Degree temp1)

subplot(233)hold onplot(RN3L Degree sorted1(1)b)plot(RN3L Degree sorted1(2)g)grid ontitle(RN3L)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)

RN1S DegreeG1=(RN1S EdgesG)(RN1S NodesG)RN1S DegreeG Hat1=(RN1S EdgesG Hat)(RN1S NodesG hat)

RN1S Degree temp1(1)=RN1S DegreeG1RN1S Degree temp1(2)=RN1S DegreeG Hat1RN1S Degree sorted1=sortrows(RN1S Degree temp1)

subplot(234)hold onplot(RN1S Degree sorted1(1)b)plot(RN1S Degree sorted1(2)g)grid ontitle(RN1S)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)

RN2S DegreeG1=(RN2S EdgesG)(RN2S NodesG)RN2S DegreeG Hat1=(RN2S EdgesG Hat)(RN2S NodesG hat)

RN2S Degree temp1(1)=RN2S DegreeG1

62 Application

RN2S Degree temp1(2)=RN2S DegreeG Hat1RN2S Degree sorted1=sortrows(RN2S Degree temp1)

subplot(235)hold onplot(RN2S Degree sorted1(1)b)plot(RN2S Degree sorted1(2)g)grid ontitle(RN2S)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)

RN3S DegreeG1=(RN3S EdgesG)(RN3S NodesG)RN3S DegreeG Hat1=(RN3S EdgesG Hat)(RN3S NodesG hat)

RN3S Degree temp1(1)=RN3S DegreeG1RN3S Degree temp1(2)=RN3S DegreeG Hat1RN3S Degree sorted1=sortrows(RN3S Degree temp1)

subplot(236)hold onplot(RN3S Degree sorted1(1)b)plot(RN3S Degree sorted1(2)g)grid ontitle(RN3S)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)set(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN6png minusr300)h(7)=figure(NameSorted mATCHED DEGREENumberTitleoff)RN1L ratioMax(1)=RN1L MaxDegreeGRN1L ratioMax(2)=RN1L MaxDegreeG Hat

RN1L ratio sortedMax=sortrows(RN1L ratioMax)subplot(231)hold onplot(RN1L ratio sortedMax(1)b)plot(RN1L ratio sortedMax(2)g)grid ontitle(RN1L)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)

RN2L ratioMax(1)=RN2L MaxDegreeGRN2L ratioMax(2)=RN2L MaxDegreeG Hat

RN2L ratio sortedMax=sortrows(RN2L ratioMax)subplot(232)

Appendix A 63

hold onplot(RN2L ratio sortedMax(1)b)plot(RN2L ratio sortedMax(2)g)grid ontitle(RN2L)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)

RN3L ratioMax(1)=RN3L MaxDegreeGRN3L ratioMax(2)=RN3L MaxDegreeG Hat

RN3L ratio sortedMax=sortrows(RN3L ratioMax)subplot(233)hold onplot(RN3L ratio sortedMax(1)b)plot(RN3L ratio sortedMax(2)g)grid ontitle(RN3L)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)

RN1S ratioMax(1)=RN1S MaxDegreeGRN1S ratioMax(2)=RN1S MaxDegreeG Hat

RN1S ratio sortedMax=sortrows(RN1S ratioMax)subplot(234)hold onplot(RN1S ratio sortedMax(1)b)plot(RN1S ratio sortedMax(2)g)grid ontitle(RN1S)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)

RN2S ratioMax(1)=RN2S MaxDegreeGRN2S ratioMax(2)=RN2S MaxDegreeG Hat

RN2S ratio sortedMax=sortrows(RN2S ratioMax)

subplot(235)hold onplot(RN2S ratio sortedMax(1)b)plot(RN2S ratio sortedMax(2)g)grid ontitle(RN2S)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)

RN3S ratioMax(1)=RN3S MaxDegreeGRN3S ratioMax(2)=RN3S MaxDegreeG Hat

64 Application

RN3S ratio sortedMax=sortrows(RN3S ratioMax)subplot(236)hold onplot(RN3S ratio sortedMax(1)b)plot(RN3S ratio sortedMax(2)g)grid ontitle(RN1L)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)set(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN7png minusr300)

tilefigs()(h)

Bibliography

[1] C Berge ldquoTWO THEOREMS IN GRAPH THEORYrdquo Proceedings of the NationalAcademy of Sciences of the United States of America vol 43 no 9 pp 842ndash844Sep 1957

[2] L Bui S Sanghavi and R Srikant ldquoDistributed link scheduling with constantoverheadrdquo IEEEACM Trans Netw vol 17 no 5 pp 1467ndash1480 2009

[3] R Duan and S Pettie ldquoLinear-time approximation for maximum weight matchingrdquoJ ACM vol 61 no 1 2014

[4] J Edmonds ldquoPaths trees and flowersrdquo Canadian Journal of Mathematics vol 17pp 449ndash467 1965

[5] J E Hopcroft and R M Karp ldquoAn n52 algorithm for maximum matchings inbipartite graphsrdquo SIAM J Comput vol 2 no 4 pp 225ndash231 1973

[6] S Micali and V V Vazirani ldquoAn O(radic|V ||E|) algorithm for finding maximum

matching in general graphsrdquo in 21st Symp on Foundations of Comp Sc (FOCS)IEEE 1980 pp 17ndash27

[7] N Nisse A Salch and V Weber ldquoRecovery of disrupted airline operationsrdquo 2015httphalinriafrSomething

[8] X Wu and R Srikant ldquoRegulated maximal matching A distributed schedulingalgorithm for multi-hop wireless networks with nodeexclusive spectrum sharingrdquo inIEEE Conf on Decision and Control 2005

65

  • Contents
  • Introduction
  • Algorithms
    • Maximum matching
    • k-maximum matching
      • k-matching for Airport Slot assignment
      • The case where k=3
      • The case of Paths
      • The case of the Spider
          • Application
            • Description
            • Reyni Erdos
            • Barabaacutesi Albert
            • Amadeus Graphs
            • Bipartite
            • Bipartite with degree seq
            • Appendix A
              • BipartiteGraphGeneratorpy
              • RandomGraphGeneratorpy
              • kequals3MaximumMatchingpy
              • Plotmat
                  • Bibliography
Page 54: Theodoros Alexandros KARAGKIOULES -  · Introduction This work is the result of a 6 months internship, under the supervision of research O cer Nicolas NISSE. The original scope of

Appendix A 55

title(RN1L)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)

subplot(232)hold onstem(RN2L EdgesGRN2L Time classicalg)stem(RN2L EdgesGRN2L Time algorithmro)stem(RN2L EdgesGRN2L Time greedybx)grid ontitle(RN2L)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)

subplot(233)hold onstem(RN3L EdgesGRN3L Time classicalg)stem(RN3L EdgesGRN3L Time algorithmro)stem(RN3L EdgesGRN3L Time greedybx)grid ontitle(RN3L)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)

subplot(234)hold onstem(RN1S EdgesGRN1S Time classicalg)stem(RN1S EdgesGRN1S Time algorithmro)stem(RN1S EdgesGRN1S Time greedybx)grid ontitle(RN1S)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)

subplot(235)hold onstem(RN2S EdgesGRN2S Time classicalg)stem(RN2S EdgesGRN2S Time algorithmro)stem(RN2S EdgesGRN2S Time greedybx)grid ontitle(RN2S)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)

subplot(236)hold onstem(RN3S EdgesGRN3S Time classicalg)stem(RN3S EdgesGRN3S Time algorithmro)stem(RN3S EdgesGRN3S Time greedybx)

56 Application

grid ontitle(RN3S)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)set(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN3png minusr300)

h(4)=figure(NameSorted matching sizeNumberTitleoff)RN1L Sorted matching temp(1)=RN1L Classical matchingRN1L Sorted matching temp(2)=RN1L Final matchingRN1L Sorted matching temp(3)=RN1L Greedy matchingRN1L Sorted matching temp(4)=RN1L Initial matchingRN1L Sorted matching=sortrows(RN1L Sorted matching temp)

RN2L Sorted matching temp(1)=RN2L Classical matchingRN2L Sorted matching temp(2)=RN2L Final matchingRN2L Sorted matching temp(3)=RN2L Greedy matchingRN2L Sorted matching temp(4)=RN2L Initial matchingRN2L Sorted matching=sortrows(RN2L Sorted matching temp)

RN3L Sorted matching temp(1)=RN3L Classical matchingRN3L Sorted matching temp(2)=RN3L Final matchingRN3L Sorted matching temp(3)=RN3L Greedy matchingRN3L Sorted matching temp(4)=RN3L Initial matchingRN3L Sorted matching=sortrows(RN3L Sorted matching temp)

RN1S Sorted matching temp(1)=RN1S Classical matchingRN1S Sorted matching temp(2)=RN1S Final matchingRN1S Sorted matching temp(3)=RN1S Greedy matchingRN1S Sorted matching temp(4)=RN1S Initial matchingRN1S Sorted matching=sortrows(RN1S Sorted matching temp)

RN2S Sorted matching temp(1)=RN2S Classical matchingRN2S Sorted matching temp(2)=RN2S Final matchingRN2S Sorted matching temp(3)=RN2S Greedy matchingRN2S Sorted matching temp(4)=RN2S Initial matchingRN2S Sorted matching=sortrows(RN2S Sorted matching temp)

RN3S Sorted matching temp(1)=RN3S Classical matchingRN3S Sorted matching temp(2)=RN3S Final matchingRN3S Sorted matching temp(3)=RN3S Greedy matchingRN3S Sorted matching temp(4)=RN3S Initial matchingRN3S Sorted matching=sortrows(RN3S Sorted matching temp)

subplot(231)hold onplot(RN1L Sorted matching(1)b)plot(RN1L Sorted matching(2)g)plot(RN1L Sorted matching(3)r)plot(RN1L Sorted matching(4)m)

Appendix A 57

grid ontitle(RN1L)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)

subplot(232)hold onplot(RN2L Sorted matching(1)b)plot(RN2L Sorted matching(2)g)plot(RN2L Sorted matching(3)r)plot(RN2L Sorted matching(4)m)grid ontitle(RN2L)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)

subplot(233)hold onplot(RN3L Sorted matching(1)b)plot(RN3L Sorted matching(2)g)plot(RN3L Sorted matching(3)r)plot(RN3L Sorted matching(4)m)grid ontitle(RN3L)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)

subplot(234)hold onplot(RN1S Sorted matching(1)b)plot(RN1S Sorted matching(2)g)plot(RN1S Sorted matching(3)r)plot(RN1S Sorted matching(4)m)grid ontitle(RN1S)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)

subplot(235)hold onplot(RN2S Sorted matching(1)b)plot(RN2S Sorted matching(2)g)plot(RN2S Sorted matching(3)r)plot(RN2S Sorted matching(4)m)grid ontitle(RN2S)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)

58 Application

subplot(236)hold onplot(RN3S Sorted matching(1)b)plot(RN3S Sorted matching(2)g)plot(RN3S Sorted matching(3)r)plot(RN3S Sorted matching(4)m)grid ontitle(RN3S)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)set(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN4png minusr300)h(5)=figure(NameSorted RatiosNumberTitleoff)RN1L ratio1=RN1L NodesG hatRN1L NodesGRN2L ratio1=RN2L NodesG hatRN2L NodesGRN3L ratio1=RN3L NodesG hatRN3L NodesGRN1S ratio1=RN1S NodesG hatRN1S NodesGRN2S ratio1=RN2S NodesG hatRN2S NodesGRN3S ratio1=RN3S NodesG hatRN3S NodesG

RN1L ratio2=RN1L EdgesG HatRN1L EdgesGRN2L ratio2=RN2L EdgesG HatRN2L EdgesGRN3L ratio2=RN3L EdgesG HatRN3L EdgesGRN1S ratio2=RN1S EdgesG HatRN1S EdgesGRN2S ratio2=RN2S EdgesG HatRN2S EdgesGRN3S ratio2=RN3S EdgesG HatRN3S EdgesG

RN1L ratio3=RN1L MaxDegreeG HatRN1L MaxDegreeGRN2L ratio3=RN2L MaxDegreeG HatRN2L MaxDegreeGRN3L ratio3=RN3L MaxDegreeG HatRN3L MaxDegreeGRN1S ratio3=RN1S MaxDegreeG HatRN1S MaxDegreeGRN2S ratio3=RN2S MaxDegreeG HatRN2S MaxDegreeGRN3S ratio3=RN3S MaxDegreeG HatRN3S MaxDegreeG

RN1L ratio(1)=RN1L ratio1RN1L ratio(2)=RN1L ratio2RN1L ratio(3)=RN1L ratio3

RN2L ratio(1)=RN2L ratio1RN2L ratio(2)=RN2L ratio2RN2L ratio(3)=RN2L ratio3

RN3L ratio(1)=RN3L ratio1RN3L ratio(2)=RN3L ratio2RN3L ratio(3)=RN3L ratio3

RN1S ratio(1)=RN1S ratio1RN1S ratio(2)=RN1S ratio2RN1S ratio(3)=RN1S ratio3

RN2S ratio(1)=RN2S ratio1

Appendix A 59

RN2S ratio(2)=RN2S ratio2RN2S ratio(3)=RN2S ratio3

RN3S ratio(1)=RN3S ratio1RN3S ratio(2)=RN3S ratio2RN3S ratio(3)=RN3S ratio3

RN1L ratio sorted=sortrows(RN1L ratio)RN2L ratio sorted=sortrows(RN2L ratio)RN3L ratio sorted=sortrows(RN3L ratio)RN1S ratio sorted=sortrows(RN1S ratio)RN2S ratio sorted=sortrows(RN2S ratio)RN3S ratio sorted=sortrows(RN3S ratio)

subplot(231)hold onplot(RN1L ratio sorted(1)b)plot(RN1L ratio sorted(2)g)plot(RN1L ratio sorted(3)r)grid ontitle(RN1L)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)

subplot(232)hold onplot(RN2L ratio sorted(1)b)plot(RN2L ratio sorted(2)g)plot(RN2L ratio sorted(3)r)grid ontitle(RN2L)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)

subplot(233)hold onplot(RN3L ratio sorted(1)b)plot(RN3L ratio sorted(2)g)plot(RN3L ratio sorted(3)r)grid ontitle(RN3L)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)

subplot(234)hold onplot(RN1S ratio sorted(1)b)plot(RN1S ratio sorted(2)g)plot(RN1S ratio sorted(3)r)grid on

60 Application

title(RN1S)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)

subplot(235)hold onplot(RN2S ratio sorted(1)b)plot(RN2S ratio sorted(2)g)plot(RN2S ratio sorted(3)r)grid ontitle(RN2S)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)

subplot(236)hold onplot(RN3S ratio sorted(1)b)plot(RN3S ratio sorted(2)g)plot(RN3S ratio sorted(3)r)grid ontitle(RN3S)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)set(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN5png minusr300)

h(6)=figure(NameSorted edges over nodesNumberTitleoff)

RN1L DegreeG1=(RN1L EdgesG)(RN1L NodesG)RN1L DegreeG Hat1=(RN1L EdgesG Hat)(RN1L NodesG hat)

RN1L Degree temp1(1)=RN1L DegreeG1RN1L Degree temp1(2)=RN1L DegreeG Hat1RN1L Degree sorted1=sortrows(RN1L Degree temp1)subplot(231)hold on

plot(RN1L Degree sorted1(1)b)plot(RN1L Degree sorted1(2)g)grid ontitle(RN1L)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)

RN2L DegreeG1=(RN2L EdgesG)(RN2L NodesG)RN2L DegreeG Hat1=(RN2L EdgesG Hat)(RN2L NodesG hat)

RN2L Degree temp1(1)=RN2L DegreeG1

Appendix A 61

RN2L Degree temp1(2)=RN2L DegreeG Hat1RN2L Degree sorted1=sortrows(RN2L Degree temp1)

subplot(232)hold onplot(RN2L Degree sorted1(1)b)plot(RN2L Degree sorted1(2)g)grid ontitle(RN2L)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)

RN3L DegreeG1=(RN3L EdgesG)(RN3L NodesG)RN3L DegreeG Hat1=(RN3L EdgesG Hat)(RN3L NodesG hat)

RN3L Degree temp1(1)=RN3L DegreeG1RN3L Degree temp1(2)=RN3L DegreeG Hat1RN3L Degree sorted1=sortrows(RN3L Degree temp1)

subplot(233)hold onplot(RN3L Degree sorted1(1)b)plot(RN3L Degree sorted1(2)g)grid ontitle(RN3L)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)

RN1S DegreeG1=(RN1S EdgesG)(RN1S NodesG)RN1S DegreeG Hat1=(RN1S EdgesG Hat)(RN1S NodesG hat)

RN1S Degree temp1(1)=RN1S DegreeG1RN1S Degree temp1(2)=RN1S DegreeG Hat1RN1S Degree sorted1=sortrows(RN1S Degree temp1)

subplot(234)hold onplot(RN1S Degree sorted1(1)b)plot(RN1S Degree sorted1(2)g)grid ontitle(RN1S)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)

RN2S DegreeG1=(RN2S EdgesG)(RN2S NodesG)RN2S DegreeG Hat1=(RN2S EdgesG Hat)(RN2S NodesG hat)

RN2S Degree temp1(1)=RN2S DegreeG1

62 Application

RN2S Degree temp1(2)=RN2S DegreeG Hat1RN2S Degree sorted1=sortrows(RN2S Degree temp1)

subplot(235)hold onplot(RN2S Degree sorted1(1)b)plot(RN2S Degree sorted1(2)g)grid ontitle(RN2S)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)

RN3S DegreeG1=(RN3S EdgesG)(RN3S NodesG)RN3S DegreeG Hat1=(RN3S EdgesG Hat)(RN3S NodesG hat)

RN3S Degree temp1(1)=RN3S DegreeG1RN3S Degree temp1(2)=RN3S DegreeG Hat1RN3S Degree sorted1=sortrows(RN3S Degree temp1)

subplot(236)hold onplot(RN3S Degree sorted1(1)b)plot(RN3S Degree sorted1(2)g)grid ontitle(RN3S)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)set(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN6png minusr300)h(7)=figure(NameSorted mATCHED DEGREENumberTitleoff)RN1L ratioMax(1)=RN1L MaxDegreeGRN1L ratioMax(2)=RN1L MaxDegreeG Hat

RN1L ratio sortedMax=sortrows(RN1L ratioMax)subplot(231)hold onplot(RN1L ratio sortedMax(1)b)plot(RN1L ratio sortedMax(2)g)grid ontitle(RN1L)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)

RN2L ratioMax(1)=RN2L MaxDegreeGRN2L ratioMax(2)=RN2L MaxDegreeG Hat

RN2L ratio sortedMax=sortrows(RN2L ratioMax)subplot(232)

Appendix A 63

hold onplot(RN2L ratio sortedMax(1)b)plot(RN2L ratio sortedMax(2)g)grid ontitle(RN2L)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)

RN3L ratioMax(1)=RN3L MaxDegreeGRN3L ratioMax(2)=RN3L MaxDegreeG Hat

RN3L ratio sortedMax=sortrows(RN3L ratioMax)subplot(233)hold onplot(RN3L ratio sortedMax(1)b)plot(RN3L ratio sortedMax(2)g)grid ontitle(RN3L)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)

RN1S ratioMax(1)=RN1S MaxDegreeGRN1S ratioMax(2)=RN1S MaxDegreeG Hat

RN1S ratio sortedMax=sortrows(RN1S ratioMax)subplot(234)hold onplot(RN1S ratio sortedMax(1)b)plot(RN1S ratio sortedMax(2)g)grid ontitle(RN1S)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)

RN2S ratioMax(1)=RN2S MaxDegreeGRN2S ratioMax(2)=RN2S MaxDegreeG Hat

RN2S ratio sortedMax=sortrows(RN2S ratioMax)

subplot(235)hold onplot(RN2S ratio sortedMax(1)b)plot(RN2S ratio sortedMax(2)g)grid ontitle(RN2S)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)

RN3S ratioMax(1)=RN3S MaxDegreeGRN3S ratioMax(2)=RN3S MaxDegreeG Hat

64 Application

RN3S ratio sortedMax=sortrows(RN3S ratioMax)subplot(236)hold onplot(RN3S ratio sortedMax(1)b)plot(RN3S ratio sortedMax(2)g)grid ontitle(RN1L)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)set(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN7png minusr300)

tilefigs()(h)

Bibliography

[1] C Berge ldquoTWO THEOREMS IN GRAPH THEORYrdquo Proceedings of the NationalAcademy of Sciences of the United States of America vol 43 no 9 pp 842ndash844Sep 1957

[2] L Bui S Sanghavi and R Srikant ldquoDistributed link scheduling with constantoverheadrdquo IEEEACM Trans Netw vol 17 no 5 pp 1467ndash1480 2009

[3] R Duan and S Pettie ldquoLinear-time approximation for maximum weight matchingrdquoJ ACM vol 61 no 1 2014

[4] J Edmonds ldquoPaths trees and flowersrdquo Canadian Journal of Mathematics vol 17pp 449ndash467 1965

[5] J E Hopcroft and R M Karp ldquoAn n52 algorithm for maximum matchings inbipartite graphsrdquo SIAM J Comput vol 2 no 4 pp 225ndash231 1973

[6] S Micali and V V Vazirani ldquoAn O(radic|V ||E|) algorithm for finding maximum

matching in general graphsrdquo in 21st Symp on Foundations of Comp Sc (FOCS)IEEE 1980 pp 17ndash27

[7] N Nisse A Salch and V Weber ldquoRecovery of disrupted airline operationsrdquo 2015httphalinriafrSomething

[8] X Wu and R Srikant ldquoRegulated maximal matching A distributed schedulingalgorithm for multi-hop wireless networks with nodeexclusive spectrum sharingrdquo inIEEE Conf on Decision and Control 2005

65

  • Contents
  • Introduction
  • Algorithms
    • Maximum matching
    • k-maximum matching
      • k-matching for Airport Slot assignment
      • The case where k=3
      • The case of Paths
      • The case of the Spider
          • Application
            • Description
            • Reyni Erdos
            • Barabaacutesi Albert
            • Amadeus Graphs
            • Bipartite
            • Bipartite with degree seq
            • Appendix A
              • BipartiteGraphGeneratorpy
              • RandomGraphGeneratorpy
              • kequals3MaximumMatchingpy
              • Plotmat
                  • Bibliography
Page 55: Theodoros Alexandros KARAGKIOULES -  · Introduction This work is the result of a 6 months internship, under the supervision of research O cer Nicolas NISSE. The original scope of

56 Application

grid ontitle(RN3S)xlabel(Edges of G) xminusaxis labelylabel(Computation time (s)) yminusaxis labellegend(ClassicalConstraintGreedyLocationnorthoutsideOrientationhorizontal)set(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN3png minusr300)

h(4)=figure(NameSorted matching sizeNumberTitleoff)RN1L Sorted matching temp(1)=RN1L Classical matchingRN1L Sorted matching temp(2)=RN1L Final matchingRN1L Sorted matching temp(3)=RN1L Greedy matchingRN1L Sorted matching temp(4)=RN1L Initial matchingRN1L Sorted matching=sortrows(RN1L Sorted matching temp)

RN2L Sorted matching temp(1)=RN2L Classical matchingRN2L Sorted matching temp(2)=RN2L Final matchingRN2L Sorted matching temp(3)=RN2L Greedy matchingRN2L Sorted matching temp(4)=RN2L Initial matchingRN2L Sorted matching=sortrows(RN2L Sorted matching temp)

RN3L Sorted matching temp(1)=RN3L Classical matchingRN3L Sorted matching temp(2)=RN3L Final matchingRN3L Sorted matching temp(3)=RN3L Greedy matchingRN3L Sorted matching temp(4)=RN3L Initial matchingRN3L Sorted matching=sortrows(RN3L Sorted matching temp)

RN1S Sorted matching temp(1)=RN1S Classical matchingRN1S Sorted matching temp(2)=RN1S Final matchingRN1S Sorted matching temp(3)=RN1S Greedy matchingRN1S Sorted matching temp(4)=RN1S Initial matchingRN1S Sorted matching=sortrows(RN1S Sorted matching temp)

RN2S Sorted matching temp(1)=RN2S Classical matchingRN2S Sorted matching temp(2)=RN2S Final matchingRN2S Sorted matching temp(3)=RN2S Greedy matchingRN2S Sorted matching temp(4)=RN2S Initial matchingRN2S Sorted matching=sortrows(RN2S Sorted matching temp)

RN3S Sorted matching temp(1)=RN3S Classical matchingRN3S Sorted matching temp(2)=RN3S Final matchingRN3S Sorted matching temp(3)=RN3S Greedy matchingRN3S Sorted matching temp(4)=RN3S Initial matchingRN3S Sorted matching=sortrows(RN3S Sorted matching temp)

subplot(231)hold onplot(RN1L Sorted matching(1)b)plot(RN1L Sorted matching(2)g)plot(RN1L Sorted matching(3)r)plot(RN1L Sorted matching(4)m)

Appendix A 57

grid ontitle(RN1L)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)

subplot(232)hold onplot(RN2L Sorted matching(1)b)plot(RN2L Sorted matching(2)g)plot(RN2L Sorted matching(3)r)plot(RN2L Sorted matching(4)m)grid ontitle(RN2L)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)

subplot(233)hold onplot(RN3L Sorted matching(1)b)plot(RN3L Sorted matching(2)g)plot(RN3L Sorted matching(3)r)plot(RN3L Sorted matching(4)m)grid ontitle(RN3L)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)

subplot(234)hold onplot(RN1S Sorted matching(1)b)plot(RN1S Sorted matching(2)g)plot(RN1S Sorted matching(3)r)plot(RN1S Sorted matching(4)m)grid ontitle(RN1S)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)

subplot(235)hold onplot(RN2S Sorted matching(1)b)plot(RN2S Sorted matching(2)g)plot(RN2S Sorted matching(3)r)plot(RN2S Sorted matching(4)m)grid ontitle(RN2S)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)

58 Application

subplot(236)hold onplot(RN3S Sorted matching(1)b)plot(RN3S Sorted matching(2)g)plot(RN3S Sorted matching(3)r)plot(RN3S Sorted matching(4)m)grid ontitle(RN3S)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)set(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN4png minusr300)h(5)=figure(NameSorted RatiosNumberTitleoff)RN1L ratio1=RN1L NodesG hatRN1L NodesGRN2L ratio1=RN2L NodesG hatRN2L NodesGRN3L ratio1=RN3L NodesG hatRN3L NodesGRN1S ratio1=RN1S NodesG hatRN1S NodesGRN2S ratio1=RN2S NodesG hatRN2S NodesGRN3S ratio1=RN3S NodesG hatRN3S NodesG

RN1L ratio2=RN1L EdgesG HatRN1L EdgesGRN2L ratio2=RN2L EdgesG HatRN2L EdgesGRN3L ratio2=RN3L EdgesG HatRN3L EdgesGRN1S ratio2=RN1S EdgesG HatRN1S EdgesGRN2S ratio2=RN2S EdgesG HatRN2S EdgesGRN3S ratio2=RN3S EdgesG HatRN3S EdgesG

RN1L ratio3=RN1L MaxDegreeG HatRN1L MaxDegreeGRN2L ratio3=RN2L MaxDegreeG HatRN2L MaxDegreeGRN3L ratio3=RN3L MaxDegreeG HatRN3L MaxDegreeGRN1S ratio3=RN1S MaxDegreeG HatRN1S MaxDegreeGRN2S ratio3=RN2S MaxDegreeG HatRN2S MaxDegreeGRN3S ratio3=RN3S MaxDegreeG HatRN3S MaxDegreeG

RN1L ratio(1)=RN1L ratio1RN1L ratio(2)=RN1L ratio2RN1L ratio(3)=RN1L ratio3

RN2L ratio(1)=RN2L ratio1RN2L ratio(2)=RN2L ratio2RN2L ratio(3)=RN2L ratio3

RN3L ratio(1)=RN3L ratio1RN3L ratio(2)=RN3L ratio2RN3L ratio(3)=RN3L ratio3

RN1S ratio(1)=RN1S ratio1RN1S ratio(2)=RN1S ratio2RN1S ratio(3)=RN1S ratio3

RN2S ratio(1)=RN2S ratio1

Appendix A 59

RN2S ratio(2)=RN2S ratio2RN2S ratio(3)=RN2S ratio3

RN3S ratio(1)=RN3S ratio1RN3S ratio(2)=RN3S ratio2RN3S ratio(3)=RN3S ratio3

RN1L ratio sorted=sortrows(RN1L ratio)RN2L ratio sorted=sortrows(RN2L ratio)RN3L ratio sorted=sortrows(RN3L ratio)RN1S ratio sorted=sortrows(RN1S ratio)RN2S ratio sorted=sortrows(RN2S ratio)RN3S ratio sorted=sortrows(RN3S ratio)

subplot(231)hold onplot(RN1L ratio sorted(1)b)plot(RN1L ratio sorted(2)g)plot(RN1L ratio sorted(3)r)grid ontitle(RN1L)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)

subplot(232)hold onplot(RN2L ratio sorted(1)b)plot(RN2L ratio sorted(2)g)plot(RN2L ratio sorted(3)r)grid ontitle(RN2L)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)

subplot(233)hold onplot(RN3L ratio sorted(1)b)plot(RN3L ratio sorted(2)g)plot(RN3L ratio sorted(3)r)grid ontitle(RN3L)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)

subplot(234)hold onplot(RN1S ratio sorted(1)b)plot(RN1S ratio sorted(2)g)plot(RN1S ratio sorted(3)r)grid on

60 Application

title(RN1S)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)

subplot(235)hold onplot(RN2S ratio sorted(1)b)plot(RN2S ratio sorted(2)g)plot(RN2S ratio sorted(3)r)grid ontitle(RN2S)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)

subplot(236)hold onplot(RN3S ratio sorted(1)b)plot(RN3S ratio sorted(2)g)plot(RN3S ratio sorted(3)r)grid ontitle(RN3S)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)set(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN5png minusr300)

h(6)=figure(NameSorted edges over nodesNumberTitleoff)

RN1L DegreeG1=(RN1L EdgesG)(RN1L NodesG)RN1L DegreeG Hat1=(RN1L EdgesG Hat)(RN1L NodesG hat)

RN1L Degree temp1(1)=RN1L DegreeG1RN1L Degree temp1(2)=RN1L DegreeG Hat1RN1L Degree sorted1=sortrows(RN1L Degree temp1)subplot(231)hold on

plot(RN1L Degree sorted1(1)b)plot(RN1L Degree sorted1(2)g)grid ontitle(RN1L)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)

RN2L DegreeG1=(RN2L EdgesG)(RN2L NodesG)RN2L DegreeG Hat1=(RN2L EdgesG Hat)(RN2L NodesG hat)

RN2L Degree temp1(1)=RN2L DegreeG1

Appendix A 61

RN2L Degree temp1(2)=RN2L DegreeG Hat1RN2L Degree sorted1=sortrows(RN2L Degree temp1)

subplot(232)hold onplot(RN2L Degree sorted1(1)b)plot(RN2L Degree sorted1(2)g)grid ontitle(RN2L)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)

RN3L DegreeG1=(RN3L EdgesG)(RN3L NodesG)RN3L DegreeG Hat1=(RN3L EdgesG Hat)(RN3L NodesG hat)

RN3L Degree temp1(1)=RN3L DegreeG1RN3L Degree temp1(2)=RN3L DegreeG Hat1RN3L Degree sorted1=sortrows(RN3L Degree temp1)

subplot(233)hold onplot(RN3L Degree sorted1(1)b)plot(RN3L Degree sorted1(2)g)grid ontitle(RN3L)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)

RN1S DegreeG1=(RN1S EdgesG)(RN1S NodesG)RN1S DegreeG Hat1=(RN1S EdgesG Hat)(RN1S NodesG hat)

RN1S Degree temp1(1)=RN1S DegreeG1RN1S Degree temp1(2)=RN1S DegreeG Hat1RN1S Degree sorted1=sortrows(RN1S Degree temp1)

subplot(234)hold onplot(RN1S Degree sorted1(1)b)plot(RN1S Degree sorted1(2)g)grid ontitle(RN1S)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)

RN2S DegreeG1=(RN2S EdgesG)(RN2S NodesG)RN2S DegreeG Hat1=(RN2S EdgesG Hat)(RN2S NodesG hat)

RN2S Degree temp1(1)=RN2S DegreeG1

62 Application

RN2S Degree temp1(2)=RN2S DegreeG Hat1RN2S Degree sorted1=sortrows(RN2S Degree temp1)

subplot(235)hold onplot(RN2S Degree sorted1(1)b)plot(RN2S Degree sorted1(2)g)grid ontitle(RN2S)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)

RN3S DegreeG1=(RN3S EdgesG)(RN3S NodesG)RN3S DegreeG Hat1=(RN3S EdgesG Hat)(RN3S NodesG hat)

RN3S Degree temp1(1)=RN3S DegreeG1RN3S Degree temp1(2)=RN3S DegreeG Hat1RN3S Degree sorted1=sortrows(RN3S Degree temp1)

subplot(236)hold onplot(RN3S Degree sorted1(1)b)plot(RN3S Degree sorted1(2)g)grid ontitle(RN3S)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)set(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN6png minusr300)h(7)=figure(NameSorted mATCHED DEGREENumberTitleoff)RN1L ratioMax(1)=RN1L MaxDegreeGRN1L ratioMax(2)=RN1L MaxDegreeG Hat

RN1L ratio sortedMax=sortrows(RN1L ratioMax)subplot(231)hold onplot(RN1L ratio sortedMax(1)b)plot(RN1L ratio sortedMax(2)g)grid ontitle(RN1L)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)

RN2L ratioMax(1)=RN2L MaxDegreeGRN2L ratioMax(2)=RN2L MaxDegreeG Hat

RN2L ratio sortedMax=sortrows(RN2L ratioMax)subplot(232)

Appendix A 63

hold onplot(RN2L ratio sortedMax(1)b)plot(RN2L ratio sortedMax(2)g)grid ontitle(RN2L)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)

RN3L ratioMax(1)=RN3L MaxDegreeGRN3L ratioMax(2)=RN3L MaxDegreeG Hat

RN3L ratio sortedMax=sortrows(RN3L ratioMax)subplot(233)hold onplot(RN3L ratio sortedMax(1)b)plot(RN3L ratio sortedMax(2)g)grid ontitle(RN3L)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)

RN1S ratioMax(1)=RN1S MaxDegreeGRN1S ratioMax(2)=RN1S MaxDegreeG Hat

RN1S ratio sortedMax=sortrows(RN1S ratioMax)subplot(234)hold onplot(RN1S ratio sortedMax(1)b)plot(RN1S ratio sortedMax(2)g)grid ontitle(RN1S)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)

RN2S ratioMax(1)=RN2S MaxDegreeGRN2S ratioMax(2)=RN2S MaxDegreeG Hat

RN2S ratio sortedMax=sortrows(RN2S ratioMax)

subplot(235)hold onplot(RN2S ratio sortedMax(1)b)plot(RN2S ratio sortedMax(2)g)grid ontitle(RN2S)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)

RN3S ratioMax(1)=RN3S MaxDegreeGRN3S ratioMax(2)=RN3S MaxDegreeG Hat

64 Application

RN3S ratio sortedMax=sortrows(RN3S ratioMax)subplot(236)hold onplot(RN3S ratio sortedMax(1)b)plot(RN3S ratio sortedMax(2)g)grid ontitle(RN1L)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)set(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN7png minusr300)

tilefigs()(h)

Bibliography

[1] C Berge ldquoTWO THEOREMS IN GRAPH THEORYrdquo Proceedings of the NationalAcademy of Sciences of the United States of America vol 43 no 9 pp 842ndash844Sep 1957

[2] L Bui S Sanghavi and R Srikant ldquoDistributed link scheduling with constantoverheadrdquo IEEEACM Trans Netw vol 17 no 5 pp 1467ndash1480 2009

[3] R Duan and S Pettie ldquoLinear-time approximation for maximum weight matchingrdquoJ ACM vol 61 no 1 2014

[4] J Edmonds ldquoPaths trees and flowersrdquo Canadian Journal of Mathematics vol 17pp 449ndash467 1965

[5] J E Hopcroft and R M Karp ldquoAn n52 algorithm for maximum matchings inbipartite graphsrdquo SIAM J Comput vol 2 no 4 pp 225ndash231 1973

[6] S Micali and V V Vazirani ldquoAn O(radic|V ||E|) algorithm for finding maximum

matching in general graphsrdquo in 21st Symp on Foundations of Comp Sc (FOCS)IEEE 1980 pp 17ndash27

[7] N Nisse A Salch and V Weber ldquoRecovery of disrupted airline operationsrdquo 2015httphalinriafrSomething

[8] X Wu and R Srikant ldquoRegulated maximal matching A distributed schedulingalgorithm for multi-hop wireless networks with nodeexclusive spectrum sharingrdquo inIEEE Conf on Decision and Control 2005

65

  • Contents
  • Introduction
  • Algorithms
    • Maximum matching
    • k-maximum matching
      • k-matching for Airport Slot assignment
      • The case where k=3
      • The case of Paths
      • The case of the Spider
          • Application
            • Description
            • Reyni Erdos
            • Barabaacutesi Albert
            • Amadeus Graphs
            • Bipartite
            • Bipartite with degree seq
            • Appendix A
              • BipartiteGraphGeneratorpy
              • RandomGraphGeneratorpy
              • kequals3MaximumMatchingpy
              • Plotmat
                  • Bibliography
Page 56: Theodoros Alexandros KARAGKIOULES -  · Introduction This work is the result of a 6 months internship, under the supervision of research O cer Nicolas NISSE. The original scope of

Appendix A 57

grid ontitle(RN1L)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)

subplot(232)hold onplot(RN2L Sorted matching(1)b)plot(RN2L Sorted matching(2)g)plot(RN2L Sorted matching(3)r)plot(RN2L Sorted matching(4)m)grid ontitle(RN2L)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)

subplot(233)hold onplot(RN3L Sorted matching(1)b)plot(RN3L Sorted matching(2)g)plot(RN3L Sorted matching(3)r)plot(RN3L Sorted matching(4)m)grid ontitle(RN3L)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)

subplot(234)hold onplot(RN1S Sorted matching(1)b)plot(RN1S Sorted matching(2)g)plot(RN1S Sorted matching(3)r)plot(RN1S Sorted matching(4)m)grid ontitle(RN1S)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)

subplot(235)hold onplot(RN2S Sorted matching(1)b)plot(RN2S Sorted matching(2)g)plot(RN2S Sorted matching(3)r)plot(RN2S Sorted matching(4)m)grid ontitle(RN2S)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)

58 Application

subplot(236)hold onplot(RN3S Sorted matching(1)b)plot(RN3S Sorted matching(2)g)plot(RN3S Sorted matching(3)r)plot(RN3S Sorted matching(4)m)grid ontitle(RN3S)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)set(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN4png minusr300)h(5)=figure(NameSorted RatiosNumberTitleoff)RN1L ratio1=RN1L NodesG hatRN1L NodesGRN2L ratio1=RN2L NodesG hatRN2L NodesGRN3L ratio1=RN3L NodesG hatRN3L NodesGRN1S ratio1=RN1S NodesG hatRN1S NodesGRN2S ratio1=RN2S NodesG hatRN2S NodesGRN3S ratio1=RN3S NodesG hatRN3S NodesG

RN1L ratio2=RN1L EdgesG HatRN1L EdgesGRN2L ratio2=RN2L EdgesG HatRN2L EdgesGRN3L ratio2=RN3L EdgesG HatRN3L EdgesGRN1S ratio2=RN1S EdgesG HatRN1S EdgesGRN2S ratio2=RN2S EdgesG HatRN2S EdgesGRN3S ratio2=RN3S EdgesG HatRN3S EdgesG

RN1L ratio3=RN1L MaxDegreeG HatRN1L MaxDegreeGRN2L ratio3=RN2L MaxDegreeG HatRN2L MaxDegreeGRN3L ratio3=RN3L MaxDegreeG HatRN3L MaxDegreeGRN1S ratio3=RN1S MaxDegreeG HatRN1S MaxDegreeGRN2S ratio3=RN2S MaxDegreeG HatRN2S MaxDegreeGRN3S ratio3=RN3S MaxDegreeG HatRN3S MaxDegreeG

RN1L ratio(1)=RN1L ratio1RN1L ratio(2)=RN1L ratio2RN1L ratio(3)=RN1L ratio3

RN2L ratio(1)=RN2L ratio1RN2L ratio(2)=RN2L ratio2RN2L ratio(3)=RN2L ratio3

RN3L ratio(1)=RN3L ratio1RN3L ratio(2)=RN3L ratio2RN3L ratio(3)=RN3L ratio3

RN1S ratio(1)=RN1S ratio1RN1S ratio(2)=RN1S ratio2RN1S ratio(3)=RN1S ratio3

RN2S ratio(1)=RN2S ratio1

Appendix A 59

RN2S ratio(2)=RN2S ratio2RN2S ratio(3)=RN2S ratio3

RN3S ratio(1)=RN3S ratio1RN3S ratio(2)=RN3S ratio2RN3S ratio(3)=RN3S ratio3

RN1L ratio sorted=sortrows(RN1L ratio)RN2L ratio sorted=sortrows(RN2L ratio)RN3L ratio sorted=sortrows(RN3L ratio)RN1S ratio sorted=sortrows(RN1S ratio)RN2S ratio sorted=sortrows(RN2S ratio)RN3S ratio sorted=sortrows(RN3S ratio)

subplot(231)hold onplot(RN1L ratio sorted(1)b)plot(RN1L ratio sorted(2)g)plot(RN1L ratio sorted(3)r)grid ontitle(RN1L)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)

subplot(232)hold onplot(RN2L ratio sorted(1)b)plot(RN2L ratio sorted(2)g)plot(RN2L ratio sorted(3)r)grid ontitle(RN2L)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)

subplot(233)hold onplot(RN3L ratio sorted(1)b)plot(RN3L ratio sorted(2)g)plot(RN3L ratio sorted(3)r)grid ontitle(RN3L)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)

subplot(234)hold onplot(RN1S ratio sorted(1)b)plot(RN1S ratio sorted(2)g)plot(RN1S ratio sorted(3)r)grid on

60 Application

title(RN1S)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)

subplot(235)hold onplot(RN2S ratio sorted(1)b)plot(RN2S ratio sorted(2)g)plot(RN2S ratio sorted(3)r)grid ontitle(RN2S)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)

subplot(236)hold onplot(RN3S ratio sorted(1)b)plot(RN3S ratio sorted(2)g)plot(RN3S ratio sorted(3)r)grid ontitle(RN3S)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)set(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN5png minusr300)

h(6)=figure(NameSorted edges over nodesNumberTitleoff)

RN1L DegreeG1=(RN1L EdgesG)(RN1L NodesG)RN1L DegreeG Hat1=(RN1L EdgesG Hat)(RN1L NodesG hat)

RN1L Degree temp1(1)=RN1L DegreeG1RN1L Degree temp1(2)=RN1L DegreeG Hat1RN1L Degree sorted1=sortrows(RN1L Degree temp1)subplot(231)hold on

plot(RN1L Degree sorted1(1)b)plot(RN1L Degree sorted1(2)g)grid ontitle(RN1L)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)

RN2L DegreeG1=(RN2L EdgesG)(RN2L NodesG)RN2L DegreeG Hat1=(RN2L EdgesG Hat)(RN2L NodesG hat)

RN2L Degree temp1(1)=RN2L DegreeG1

Appendix A 61

RN2L Degree temp1(2)=RN2L DegreeG Hat1RN2L Degree sorted1=sortrows(RN2L Degree temp1)

subplot(232)hold onplot(RN2L Degree sorted1(1)b)plot(RN2L Degree sorted1(2)g)grid ontitle(RN2L)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)

RN3L DegreeG1=(RN3L EdgesG)(RN3L NodesG)RN3L DegreeG Hat1=(RN3L EdgesG Hat)(RN3L NodesG hat)

RN3L Degree temp1(1)=RN3L DegreeG1RN3L Degree temp1(2)=RN3L DegreeG Hat1RN3L Degree sorted1=sortrows(RN3L Degree temp1)

subplot(233)hold onplot(RN3L Degree sorted1(1)b)plot(RN3L Degree sorted1(2)g)grid ontitle(RN3L)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)

RN1S DegreeG1=(RN1S EdgesG)(RN1S NodesG)RN1S DegreeG Hat1=(RN1S EdgesG Hat)(RN1S NodesG hat)

RN1S Degree temp1(1)=RN1S DegreeG1RN1S Degree temp1(2)=RN1S DegreeG Hat1RN1S Degree sorted1=sortrows(RN1S Degree temp1)

subplot(234)hold onplot(RN1S Degree sorted1(1)b)plot(RN1S Degree sorted1(2)g)grid ontitle(RN1S)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)

RN2S DegreeG1=(RN2S EdgesG)(RN2S NodesG)RN2S DegreeG Hat1=(RN2S EdgesG Hat)(RN2S NodesG hat)

RN2S Degree temp1(1)=RN2S DegreeG1

62 Application

RN2S Degree temp1(2)=RN2S DegreeG Hat1RN2S Degree sorted1=sortrows(RN2S Degree temp1)

subplot(235)hold onplot(RN2S Degree sorted1(1)b)plot(RN2S Degree sorted1(2)g)grid ontitle(RN2S)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)

RN3S DegreeG1=(RN3S EdgesG)(RN3S NodesG)RN3S DegreeG Hat1=(RN3S EdgesG Hat)(RN3S NodesG hat)

RN3S Degree temp1(1)=RN3S DegreeG1RN3S Degree temp1(2)=RN3S DegreeG Hat1RN3S Degree sorted1=sortrows(RN3S Degree temp1)

subplot(236)hold onplot(RN3S Degree sorted1(1)b)plot(RN3S Degree sorted1(2)g)grid ontitle(RN3S)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)set(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN6png minusr300)h(7)=figure(NameSorted mATCHED DEGREENumberTitleoff)RN1L ratioMax(1)=RN1L MaxDegreeGRN1L ratioMax(2)=RN1L MaxDegreeG Hat

RN1L ratio sortedMax=sortrows(RN1L ratioMax)subplot(231)hold onplot(RN1L ratio sortedMax(1)b)plot(RN1L ratio sortedMax(2)g)grid ontitle(RN1L)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)

RN2L ratioMax(1)=RN2L MaxDegreeGRN2L ratioMax(2)=RN2L MaxDegreeG Hat

RN2L ratio sortedMax=sortrows(RN2L ratioMax)subplot(232)

Appendix A 63

hold onplot(RN2L ratio sortedMax(1)b)plot(RN2L ratio sortedMax(2)g)grid ontitle(RN2L)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)

RN3L ratioMax(1)=RN3L MaxDegreeGRN3L ratioMax(2)=RN3L MaxDegreeG Hat

RN3L ratio sortedMax=sortrows(RN3L ratioMax)subplot(233)hold onplot(RN3L ratio sortedMax(1)b)plot(RN3L ratio sortedMax(2)g)grid ontitle(RN3L)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)

RN1S ratioMax(1)=RN1S MaxDegreeGRN1S ratioMax(2)=RN1S MaxDegreeG Hat

RN1S ratio sortedMax=sortrows(RN1S ratioMax)subplot(234)hold onplot(RN1S ratio sortedMax(1)b)plot(RN1S ratio sortedMax(2)g)grid ontitle(RN1S)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)

RN2S ratioMax(1)=RN2S MaxDegreeGRN2S ratioMax(2)=RN2S MaxDegreeG Hat

RN2S ratio sortedMax=sortrows(RN2S ratioMax)

subplot(235)hold onplot(RN2S ratio sortedMax(1)b)plot(RN2S ratio sortedMax(2)g)grid ontitle(RN2S)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)

RN3S ratioMax(1)=RN3S MaxDegreeGRN3S ratioMax(2)=RN3S MaxDegreeG Hat

64 Application

RN3S ratio sortedMax=sortrows(RN3S ratioMax)subplot(236)hold onplot(RN3S ratio sortedMax(1)b)plot(RN3S ratio sortedMax(2)g)grid ontitle(RN1L)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)set(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN7png minusr300)

tilefigs()(h)

Bibliography

[1] C Berge ldquoTWO THEOREMS IN GRAPH THEORYrdquo Proceedings of the NationalAcademy of Sciences of the United States of America vol 43 no 9 pp 842ndash844Sep 1957

[2] L Bui S Sanghavi and R Srikant ldquoDistributed link scheduling with constantoverheadrdquo IEEEACM Trans Netw vol 17 no 5 pp 1467ndash1480 2009

[3] R Duan and S Pettie ldquoLinear-time approximation for maximum weight matchingrdquoJ ACM vol 61 no 1 2014

[4] J Edmonds ldquoPaths trees and flowersrdquo Canadian Journal of Mathematics vol 17pp 449ndash467 1965

[5] J E Hopcroft and R M Karp ldquoAn n52 algorithm for maximum matchings inbipartite graphsrdquo SIAM J Comput vol 2 no 4 pp 225ndash231 1973

[6] S Micali and V V Vazirani ldquoAn O(radic|V ||E|) algorithm for finding maximum

matching in general graphsrdquo in 21st Symp on Foundations of Comp Sc (FOCS)IEEE 1980 pp 17ndash27

[7] N Nisse A Salch and V Weber ldquoRecovery of disrupted airline operationsrdquo 2015httphalinriafrSomething

[8] X Wu and R Srikant ldquoRegulated maximal matching A distributed schedulingalgorithm for multi-hop wireless networks with nodeexclusive spectrum sharingrdquo inIEEE Conf on Decision and Control 2005

65

  • Contents
  • Introduction
  • Algorithms
    • Maximum matching
    • k-maximum matching
      • k-matching for Airport Slot assignment
      • The case where k=3
      • The case of Paths
      • The case of the Spider
          • Application
            • Description
            • Reyni Erdos
            • Barabaacutesi Albert
            • Amadeus Graphs
            • Bipartite
            • Bipartite with degree seq
            • Appendix A
              • BipartiteGraphGeneratorpy
              • RandomGraphGeneratorpy
              • kequals3MaximumMatchingpy
              • Plotmat
                  • Bibliography
Page 57: Theodoros Alexandros KARAGKIOULES -  · Introduction This work is the result of a 6 months internship, under the supervision of research O cer Nicolas NISSE. The original scope of

58 Application

subplot(236)hold onplot(RN3S Sorted matching(1)b)plot(RN3S Sorted matching(2)g)plot(RN3S Sorted matching(3)r)plot(RN3S Sorted matching(4)m)grid ontitle(RN3S)xlabel(instances) xminusaxis labelylabel(size of matching) yminusaxis labellegend(ClassicalConstraintGreedyInitialLocationnorthoutsideOrientationhorizontal)set(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN4png minusr300)h(5)=figure(NameSorted RatiosNumberTitleoff)RN1L ratio1=RN1L NodesG hatRN1L NodesGRN2L ratio1=RN2L NodesG hatRN2L NodesGRN3L ratio1=RN3L NodesG hatRN3L NodesGRN1S ratio1=RN1S NodesG hatRN1S NodesGRN2S ratio1=RN2S NodesG hatRN2S NodesGRN3S ratio1=RN3S NodesG hatRN3S NodesG

RN1L ratio2=RN1L EdgesG HatRN1L EdgesGRN2L ratio2=RN2L EdgesG HatRN2L EdgesGRN3L ratio2=RN3L EdgesG HatRN3L EdgesGRN1S ratio2=RN1S EdgesG HatRN1S EdgesGRN2S ratio2=RN2S EdgesG HatRN2S EdgesGRN3S ratio2=RN3S EdgesG HatRN3S EdgesG

RN1L ratio3=RN1L MaxDegreeG HatRN1L MaxDegreeGRN2L ratio3=RN2L MaxDegreeG HatRN2L MaxDegreeGRN3L ratio3=RN3L MaxDegreeG HatRN3L MaxDegreeGRN1S ratio3=RN1S MaxDegreeG HatRN1S MaxDegreeGRN2S ratio3=RN2S MaxDegreeG HatRN2S MaxDegreeGRN3S ratio3=RN3S MaxDegreeG HatRN3S MaxDegreeG

RN1L ratio(1)=RN1L ratio1RN1L ratio(2)=RN1L ratio2RN1L ratio(3)=RN1L ratio3

RN2L ratio(1)=RN2L ratio1RN2L ratio(2)=RN2L ratio2RN2L ratio(3)=RN2L ratio3

RN3L ratio(1)=RN3L ratio1RN3L ratio(2)=RN3L ratio2RN3L ratio(3)=RN3L ratio3

RN1S ratio(1)=RN1S ratio1RN1S ratio(2)=RN1S ratio2RN1S ratio(3)=RN1S ratio3

RN2S ratio(1)=RN2S ratio1

Appendix A 59

RN2S ratio(2)=RN2S ratio2RN2S ratio(3)=RN2S ratio3

RN3S ratio(1)=RN3S ratio1RN3S ratio(2)=RN3S ratio2RN3S ratio(3)=RN3S ratio3

RN1L ratio sorted=sortrows(RN1L ratio)RN2L ratio sorted=sortrows(RN2L ratio)RN3L ratio sorted=sortrows(RN3L ratio)RN1S ratio sorted=sortrows(RN1S ratio)RN2S ratio sorted=sortrows(RN2S ratio)RN3S ratio sorted=sortrows(RN3S ratio)

subplot(231)hold onplot(RN1L ratio sorted(1)b)plot(RN1L ratio sorted(2)g)plot(RN1L ratio sorted(3)r)grid ontitle(RN1L)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)

subplot(232)hold onplot(RN2L ratio sorted(1)b)plot(RN2L ratio sorted(2)g)plot(RN2L ratio sorted(3)r)grid ontitle(RN2L)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)

subplot(233)hold onplot(RN3L ratio sorted(1)b)plot(RN3L ratio sorted(2)g)plot(RN3L ratio sorted(3)r)grid ontitle(RN3L)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)

subplot(234)hold onplot(RN1S ratio sorted(1)b)plot(RN1S ratio sorted(2)g)plot(RN1S ratio sorted(3)r)grid on

60 Application

title(RN1S)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)

subplot(235)hold onplot(RN2S ratio sorted(1)b)plot(RN2S ratio sorted(2)g)plot(RN2S ratio sorted(3)r)grid ontitle(RN2S)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)

subplot(236)hold onplot(RN3S ratio sorted(1)b)plot(RN3S ratio sorted(2)g)plot(RN3S ratio sorted(3)r)grid ontitle(RN3S)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)set(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN5png minusr300)

h(6)=figure(NameSorted edges over nodesNumberTitleoff)

RN1L DegreeG1=(RN1L EdgesG)(RN1L NodesG)RN1L DegreeG Hat1=(RN1L EdgesG Hat)(RN1L NodesG hat)

RN1L Degree temp1(1)=RN1L DegreeG1RN1L Degree temp1(2)=RN1L DegreeG Hat1RN1L Degree sorted1=sortrows(RN1L Degree temp1)subplot(231)hold on

plot(RN1L Degree sorted1(1)b)plot(RN1L Degree sorted1(2)g)grid ontitle(RN1L)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)

RN2L DegreeG1=(RN2L EdgesG)(RN2L NodesG)RN2L DegreeG Hat1=(RN2L EdgesG Hat)(RN2L NodesG hat)

RN2L Degree temp1(1)=RN2L DegreeG1

Appendix A 61

RN2L Degree temp1(2)=RN2L DegreeG Hat1RN2L Degree sorted1=sortrows(RN2L Degree temp1)

subplot(232)hold onplot(RN2L Degree sorted1(1)b)plot(RN2L Degree sorted1(2)g)grid ontitle(RN2L)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)

RN3L DegreeG1=(RN3L EdgesG)(RN3L NodesG)RN3L DegreeG Hat1=(RN3L EdgesG Hat)(RN3L NodesG hat)

RN3L Degree temp1(1)=RN3L DegreeG1RN3L Degree temp1(2)=RN3L DegreeG Hat1RN3L Degree sorted1=sortrows(RN3L Degree temp1)

subplot(233)hold onplot(RN3L Degree sorted1(1)b)plot(RN3L Degree sorted1(2)g)grid ontitle(RN3L)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)

RN1S DegreeG1=(RN1S EdgesG)(RN1S NodesG)RN1S DegreeG Hat1=(RN1S EdgesG Hat)(RN1S NodesG hat)

RN1S Degree temp1(1)=RN1S DegreeG1RN1S Degree temp1(2)=RN1S DegreeG Hat1RN1S Degree sorted1=sortrows(RN1S Degree temp1)

subplot(234)hold onplot(RN1S Degree sorted1(1)b)plot(RN1S Degree sorted1(2)g)grid ontitle(RN1S)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)

RN2S DegreeG1=(RN2S EdgesG)(RN2S NodesG)RN2S DegreeG Hat1=(RN2S EdgesG Hat)(RN2S NodesG hat)

RN2S Degree temp1(1)=RN2S DegreeG1

62 Application

RN2S Degree temp1(2)=RN2S DegreeG Hat1RN2S Degree sorted1=sortrows(RN2S Degree temp1)

subplot(235)hold onplot(RN2S Degree sorted1(1)b)plot(RN2S Degree sorted1(2)g)grid ontitle(RN2S)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)

RN3S DegreeG1=(RN3S EdgesG)(RN3S NodesG)RN3S DegreeG Hat1=(RN3S EdgesG Hat)(RN3S NodesG hat)

RN3S Degree temp1(1)=RN3S DegreeG1RN3S Degree temp1(2)=RN3S DegreeG Hat1RN3S Degree sorted1=sortrows(RN3S Degree temp1)

subplot(236)hold onplot(RN3S Degree sorted1(1)b)plot(RN3S Degree sorted1(2)g)grid ontitle(RN3S)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)set(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN6png minusr300)h(7)=figure(NameSorted mATCHED DEGREENumberTitleoff)RN1L ratioMax(1)=RN1L MaxDegreeGRN1L ratioMax(2)=RN1L MaxDegreeG Hat

RN1L ratio sortedMax=sortrows(RN1L ratioMax)subplot(231)hold onplot(RN1L ratio sortedMax(1)b)plot(RN1L ratio sortedMax(2)g)grid ontitle(RN1L)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)

RN2L ratioMax(1)=RN2L MaxDegreeGRN2L ratioMax(2)=RN2L MaxDegreeG Hat

RN2L ratio sortedMax=sortrows(RN2L ratioMax)subplot(232)

Appendix A 63

hold onplot(RN2L ratio sortedMax(1)b)plot(RN2L ratio sortedMax(2)g)grid ontitle(RN2L)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)

RN3L ratioMax(1)=RN3L MaxDegreeGRN3L ratioMax(2)=RN3L MaxDegreeG Hat

RN3L ratio sortedMax=sortrows(RN3L ratioMax)subplot(233)hold onplot(RN3L ratio sortedMax(1)b)plot(RN3L ratio sortedMax(2)g)grid ontitle(RN3L)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)

RN1S ratioMax(1)=RN1S MaxDegreeGRN1S ratioMax(2)=RN1S MaxDegreeG Hat

RN1S ratio sortedMax=sortrows(RN1S ratioMax)subplot(234)hold onplot(RN1S ratio sortedMax(1)b)plot(RN1S ratio sortedMax(2)g)grid ontitle(RN1S)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)

RN2S ratioMax(1)=RN2S MaxDegreeGRN2S ratioMax(2)=RN2S MaxDegreeG Hat

RN2S ratio sortedMax=sortrows(RN2S ratioMax)

subplot(235)hold onplot(RN2S ratio sortedMax(1)b)plot(RN2S ratio sortedMax(2)g)grid ontitle(RN2S)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)

RN3S ratioMax(1)=RN3S MaxDegreeGRN3S ratioMax(2)=RN3S MaxDegreeG Hat

64 Application

RN3S ratio sortedMax=sortrows(RN3S ratioMax)subplot(236)hold onplot(RN3S ratio sortedMax(1)b)plot(RN3S ratio sortedMax(2)g)grid ontitle(RN1L)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)set(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN7png minusr300)

tilefigs()(h)

Bibliography

[1] C Berge ldquoTWO THEOREMS IN GRAPH THEORYrdquo Proceedings of the NationalAcademy of Sciences of the United States of America vol 43 no 9 pp 842ndash844Sep 1957

[2] L Bui S Sanghavi and R Srikant ldquoDistributed link scheduling with constantoverheadrdquo IEEEACM Trans Netw vol 17 no 5 pp 1467ndash1480 2009

[3] R Duan and S Pettie ldquoLinear-time approximation for maximum weight matchingrdquoJ ACM vol 61 no 1 2014

[4] J Edmonds ldquoPaths trees and flowersrdquo Canadian Journal of Mathematics vol 17pp 449ndash467 1965

[5] J E Hopcroft and R M Karp ldquoAn n52 algorithm for maximum matchings inbipartite graphsrdquo SIAM J Comput vol 2 no 4 pp 225ndash231 1973

[6] S Micali and V V Vazirani ldquoAn O(radic|V ||E|) algorithm for finding maximum

matching in general graphsrdquo in 21st Symp on Foundations of Comp Sc (FOCS)IEEE 1980 pp 17ndash27

[7] N Nisse A Salch and V Weber ldquoRecovery of disrupted airline operationsrdquo 2015httphalinriafrSomething

[8] X Wu and R Srikant ldquoRegulated maximal matching A distributed schedulingalgorithm for multi-hop wireless networks with nodeexclusive spectrum sharingrdquo inIEEE Conf on Decision and Control 2005

65

  • Contents
  • Introduction
  • Algorithms
    • Maximum matching
    • k-maximum matching
      • k-matching for Airport Slot assignment
      • The case where k=3
      • The case of Paths
      • The case of the Spider
          • Application
            • Description
            • Reyni Erdos
            • Barabaacutesi Albert
            • Amadeus Graphs
            • Bipartite
            • Bipartite with degree seq
            • Appendix A
              • BipartiteGraphGeneratorpy
              • RandomGraphGeneratorpy
              • kequals3MaximumMatchingpy
              • Plotmat
                  • Bibliography
Page 58: Theodoros Alexandros KARAGKIOULES -  · Introduction This work is the result of a 6 months internship, under the supervision of research O cer Nicolas NISSE. The original scope of

Appendix A 59

RN2S ratio(2)=RN2S ratio2RN2S ratio(3)=RN2S ratio3

RN3S ratio(1)=RN3S ratio1RN3S ratio(2)=RN3S ratio2RN3S ratio(3)=RN3S ratio3

RN1L ratio sorted=sortrows(RN1L ratio)RN2L ratio sorted=sortrows(RN2L ratio)RN3L ratio sorted=sortrows(RN3L ratio)RN1S ratio sorted=sortrows(RN1S ratio)RN2S ratio sorted=sortrows(RN2S ratio)RN3S ratio sorted=sortrows(RN3S ratio)

subplot(231)hold onplot(RN1L ratio sorted(1)b)plot(RN1L ratio sorted(2)g)plot(RN1L ratio sorted(3)r)grid ontitle(RN1L)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)

subplot(232)hold onplot(RN2L ratio sorted(1)b)plot(RN2L ratio sorted(2)g)plot(RN2L ratio sorted(3)r)grid ontitle(RN2L)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)

subplot(233)hold onplot(RN3L ratio sorted(1)b)plot(RN3L ratio sorted(2)g)plot(RN3L ratio sorted(3)r)grid ontitle(RN3L)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)

subplot(234)hold onplot(RN1S ratio sorted(1)b)plot(RN1S ratio sorted(2)g)plot(RN1S ratio sorted(3)r)grid on

60 Application

title(RN1S)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)

subplot(235)hold onplot(RN2S ratio sorted(1)b)plot(RN2S ratio sorted(2)g)plot(RN2S ratio sorted(3)r)grid ontitle(RN2S)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)

subplot(236)hold onplot(RN3S ratio sorted(1)b)plot(RN3S ratio sorted(2)g)plot(RN3S ratio sorted(3)r)grid ontitle(RN3S)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)set(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN5png minusr300)

h(6)=figure(NameSorted edges over nodesNumberTitleoff)

RN1L DegreeG1=(RN1L EdgesG)(RN1L NodesG)RN1L DegreeG Hat1=(RN1L EdgesG Hat)(RN1L NodesG hat)

RN1L Degree temp1(1)=RN1L DegreeG1RN1L Degree temp1(2)=RN1L DegreeG Hat1RN1L Degree sorted1=sortrows(RN1L Degree temp1)subplot(231)hold on

plot(RN1L Degree sorted1(1)b)plot(RN1L Degree sorted1(2)g)grid ontitle(RN1L)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)

RN2L DegreeG1=(RN2L EdgesG)(RN2L NodesG)RN2L DegreeG Hat1=(RN2L EdgesG Hat)(RN2L NodesG hat)

RN2L Degree temp1(1)=RN2L DegreeG1

Appendix A 61

RN2L Degree temp1(2)=RN2L DegreeG Hat1RN2L Degree sorted1=sortrows(RN2L Degree temp1)

subplot(232)hold onplot(RN2L Degree sorted1(1)b)plot(RN2L Degree sorted1(2)g)grid ontitle(RN2L)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)

RN3L DegreeG1=(RN3L EdgesG)(RN3L NodesG)RN3L DegreeG Hat1=(RN3L EdgesG Hat)(RN3L NodesG hat)

RN3L Degree temp1(1)=RN3L DegreeG1RN3L Degree temp1(2)=RN3L DegreeG Hat1RN3L Degree sorted1=sortrows(RN3L Degree temp1)

subplot(233)hold onplot(RN3L Degree sorted1(1)b)plot(RN3L Degree sorted1(2)g)grid ontitle(RN3L)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)

RN1S DegreeG1=(RN1S EdgesG)(RN1S NodesG)RN1S DegreeG Hat1=(RN1S EdgesG Hat)(RN1S NodesG hat)

RN1S Degree temp1(1)=RN1S DegreeG1RN1S Degree temp1(2)=RN1S DegreeG Hat1RN1S Degree sorted1=sortrows(RN1S Degree temp1)

subplot(234)hold onplot(RN1S Degree sorted1(1)b)plot(RN1S Degree sorted1(2)g)grid ontitle(RN1S)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)

RN2S DegreeG1=(RN2S EdgesG)(RN2S NodesG)RN2S DegreeG Hat1=(RN2S EdgesG Hat)(RN2S NodesG hat)

RN2S Degree temp1(1)=RN2S DegreeG1

62 Application

RN2S Degree temp1(2)=RN2S DegreeG Hat1RN2S Degree sorted1=sortrows(RN2S Degree temp1)

subplot(235)hold onplot(RN2S Degree sorted1(1)b)plot(RN2S Degree sorted1(2)g)grid ontitle(RN2S)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)

RN3S DegreeG1=(RN3S EdgesG)(RN3S NodesG)RN3S DegreeG Hat1=(RN3S EdgesG Hat)(RN3S NodesG hat)

RN3S Degree temp1(1)=RN3S DegreeG1RN3S Degree temp1(2)=RN3S DegreeG Hat1RN3S Degree sorted1=sortrows(RN3S Degree temp1)

subplot(236)hold onplot(RN3S Degree sorted1(1)b)plot(RN3S Degree sorted1(2)g)grid ontitle(RN3S)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)set(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN6png minusr300)h(7)=figure(NameSorted mATCHED DEGREENumberTitleoff)RN1L ratioMax(1)=RN1L MaxDegreeGRN1L ratioMax(2)=RN1L MaxDegreeG Hat

RN1L ratio sortedMax=sortrows(RN1L ratioMax)subplot(231)hold onplot(RN1L ratio sortedMax(1)b)plot(RN1L ratio sortedMax(2)g)grid ontitle(RN1L)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)

RN2L ratioMax(1)=RN2L MaxDegreeGRN2L ratioMax(2)=RN2L MaxDegreeG Hat

RN2L ratio sortedMax=sortrows(RN2L ratioMax)subplot(232)

Appendix A 63

hold onplot(RN2L ratio sortedMax(1)b)plot(RN2L ratio sortedMax(2)g)grid ontitle(RN2L)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)

RN3L ratioMax(1)=RN3L MaxDegreeGRN3L ratioMax(2)=RN3L MaxDegreeG Hat

RN3L ratio sortedMax=sortrows(RN3L ratioMax)subplot(233)hold onplot(RN3L ratio sortedMax(1)b)plot(RN3L ratio sortedMax(2)g)grid ontitle(RN3L)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)

RN1S ratioMax(1)=RN1S MaxDegreeGRN1S ratioMax(2)=RN1S MaxDegreeG Hat

RN1S ratio sortedMax=sortrows(RN1S ratioMax)subplot(234)hold onplot(RN1S ratio sortedMax(1)b)plot(RN1S ratio sortedMax(2)g)grid ontitle(RN1S)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)

RN2S ratioMax(1)=RN2S MaxDegreeGRN2S ratioMax(2)=RN2S MaxDegreeG Hat

RN2S ratio sortedMax=sortrows(RN2S ratioMax)

subplot(235)hold onplot(RN2S ratio sortedMax(1)b)plot(RN2S ratio sortedMax(2)g)grid ontitle(RN2S)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)

RN3S ratioMax(1)=RN3S MaxDegreeGRN3S ratioMax(2)=RN3S MaxDegreeG Hat

64 Application

RN3S ratio sortedMax=sortrows(RN3S ratioMax)subplot(236)hold onplot(RN3S ratio sortedMax(1)b)plot(RN3S ratio sortedMax(2)g)grid ontitle(RN1L)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)set(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN7png minusr300)

tilefigs()(h)

Bibliography

[1] C Berge ldquoTWO THEOREMS IN GRAPH THEORYrdquo Proceedings of the NationalAcademy of Sciences of the United States of America vol 43 no 9 pp 842ndash844Sep 1957

[2] L Bui S Sanghavi and R Srikant ldquoDistributed link scheduling with constantoverheadrdquo IEEEACM Trans Netw vol 17 no 5 pp 1467ndash1480 2009

[3] R Duan and S Pettie ldquoLinear-time approximation for maximum weight matchingrdquoJ ACM vol 61 no 1 2014

[4] J Edmonds ldquoPaths trees and flowersrdquo Canadian Journal of Mathematics vol 17pp 449ndash467 1965

[5] J E Hopcroft and R M Karp ldquoAn n52 algorithm for maximum matchings inbipartite graphsrdquo SIAM J Comput vol 2 no 4 pp 225ndash231 1973

[6] S Micali and V V Vazirani ldquoAn O(radic|V ||E|) algorithm for finding maximum

matching in general graphsrdquo in 21st Symp on Foundations of Comp Sc (FOCS)IEEE 1980 pp 17ndash27

[7] N Nisse A Salch and V Weber ldquoRecovery of disrupted airline operationsrdquo 2015httphalinriafrSomething

[8] X Wu and R Srikant ldquoRegulated maximal matching A distributed schedulingalgorithm for multi-hop wireless networks with nodeexclusive spectrum sharingrdquo inIEEE Conf on Decision and Control 2005

65

  • Contents
  • Introduction
  • Algorithms
    • Maximum matching
    • k-maximum matching
      • k-matching for Airport Slot assignment
      • The case where k=3
      • The case of Paths
      • The case of the Spider
          • Application
            • Description
            • Reyni Erdos
            • Barabaacutesi Albert
            • Amadeus Graphs
            • Bipartite
            • Bipartite with degree seq
            • Appendix A
              • BipartiteGraphGeneratorpy
              • RandomGraphGeneratorpy
              • kequals3MaximumMatchingpy
              • Plotmat
                  • Bibliography
Page 59: Theodoros Alexandros KARAGKIOULES -  · Introduction This work is the result of a 6 months internship, under the supervision of research O cer Nicolas NISSE. The original scope of

60 Application

title(RN1S)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)

subplot(235)hold onplot(RN2S ratio sorted(1)b)plot(RN2S ratio sorted(2)g)plot(RN2S ratio sorted(3)r)grid ontitle(RN2S)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)

subplot(236)hold onplot(RN3S ratio sorted(1)b)plot(RN3S ratio sorted(2)g)plot(RN3S ratio sorted(3)r)grid ontitle(RN3S)ylabel(Nodes Ratio) xminusaxis labelxlabel(Instances) yminusaxis labellegend(NodesEdgesMax DegreeLocationnorthoutsideOrientationhorizontal)set(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN5png minusr300)

h(6)=figure(NameSorted edges over nodesNumberTitleoff)

RN1L DegreeG1=(RN1L EdgesG)(RN1L NodesG)RN1L DegreeG Hat1=(RN1L EdgesG Hat)(RN1L NodesG hat)

RN1L Degree temp1(1)=RN1L DegreeG1RN1L Degree temp1(2)=RN1L DegreeG Hat1RN1L Degree sorted1=sortrows(RN1L Degree temp1)subplot(231)hold on

plot(RN1L Degree sorted1(1)b)plot(RN1L Degree sorted1(2)g)grid ontitle(RN1L)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)

RN2L DegreeG1=(RN2L EdgesG)(RN2L NodesG)RN2L DegreeG Hat1=(RN2L EdgesG Hat)(RN2L NodesG hat)

RN2L Degree temp1(1)=RN2L DegreeG1

Appendix A 61

RN2L Degree temp1(2)=RN2L DegreeG Hat1RN2L Degree sorted1=sortrows(RN2L Degree temp1)

subplot(232)hold onplot(RN2L Degree sorted1(1)b)plot(RN2L Degree sorted1(2)g)grid ontitle(RN2L)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)

RN3L DegreeG1=(RN3L EdgesG)(RN3L NodesG)RN3L DegreeG Hat1=(RN3L EdgesG Hat)(RN3L NodesG hat)

RN3L Degree temp1(1)=RN3L DegreeG1RN3L Degree temp1(2)=RN3L DegreeG Hat1RN3L Degree sorted1=sortrows(RN3L Degree temp1)

subplot(233)hold onplot(RN3L Degree sorted1(1)b)plot(RN3L Degree sorted1(2)g)grid ontitle(RN3L)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)

RN1S DegreeG1=(RN1S EdgesG)(RN1S NodesG)RN1S DegreeG Hat1=(RN1S EdgesG Hat)(RN1S NodesG hat)

RN1S Degree temp1(1)=RN1S DegreeG1RN1S Degree temp1(2)=RN1S DegreeG Hat1RN1S Degree sorted1=sortrows(RN1S Degree temp1)

subplot(234)hold onplot(RN1S Degree sorted1(1)b)plot(RN1S Degree sorted1(2)g)grid ontitle(RN1S)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)

RN2S DegreeG1=(RN2S EdgesG)(RN2S NodesG)RN2S DegreeG Hat1=(RN2S EdgesG Hat)(RN2S NodesG hat)

RN2S Degree temp1(1)=RN2S DegreeG1

62 Application

RN2S Degree temp1(2)=RN2S DegreeG Hat1RN2S Degree sorted1=sortrows(RN2S Degree temp1)

subplot(235)hold onplot(RN2S Degree sorted1(1)b)plot(RN2S Degree sorted1(2)g)grid ontitle(RN2S)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)

RN3S DegreeG1=(RN3S EdgesG)(RN3S NodesG)RN3S DegreeG Hat1=(RN3S EdgesG Hat)(RN3S NodesG hat)

RN3S Degree temp1(1)=RN3S DegreeG1RN3S Degree temp1(2)=RN3S DegreeG Hat1RN3S Degree sorted1=sortrows(RN3S Degree temp1)

subplot(236)hold onplot(RN3S Degree sorted1(1)b)plot(RN3S Degree sorted1(2)g)grid ontitle(RN3S)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)set(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN6png minusr300)h(7)=figure(NameSorted mATCHED DEGREENumberTitleoff)RN1L ratioMax(1)=RN1L MaxDegreeGRN1L ratioMax(2)=RN1L MaxDegreeG Hat

RN1L ratio sortedMax=sortrows(RN1L ratioMax)subplot(231)hold onplot(RN1L ratio sortedMax(1)b)plot(RN1L ratio sortedMax(2)g)grid ontitle(RN1L)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)

RN2L ratioMax(1)=RN2L MaxDegreeGRN2L ratioMax(2)=RN2L MaxDegreeG Hat

RN2L ratio sortedMax=sortrows(RN2L ratioMax)subplot(232)

Appendix A 63

hold onplot(RN2L ratio sortedMax(1)b)plot(RN2L ratio sortedMax(2)g)grid ontitle(RN2L)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)

RN3L ratioMax(1)=RN3L MaxDegreeGRN3L ratioMax(2)=RN3L MaxDegreeG Hat

RN3L ratio sortedMax=sortrows(RN3L ratioMax)subplot(233)hold onplot(RN3L ratio sortedMax(1)b)plot(RN3L ratio sortedMax(2)g)grid ontitle(RN3L)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)

RN1S ratioMax(1)=RN1S MaxDegreeGRN1S ratioMax(2)=RN1S MaxDegreeG Hat

RN1S ratio sortedMax=sortrows(RN1S ratioMax)subplot(234)hold onplot(RN1S ratio sortedMax(1)b)plot(RN1S ratio sortedMax(2)g)grid ontitle(RN1S)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)

RN2S ratioMax(1)=RN2S MaxDegreeGRN2S ratioMax(2)=RN2S MaxDegreeG Hat

RN2S ratio sortedMax=sortrows(RN2S ratioMax)

subplot(235)hold onplot(RN2S ratio sortedMax(1)b)plot(RN2S ratio sortedMax(2)g)grid ontitle(RN2S)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)

RN3S ratioMax(1)=RN3S MaxDegreeGRN3S ratioMax(2)=RN3S MaxDegreeG Hat

64 Application

RN3S ratio sortedMax=sortrows(RN3S ratioMax)subplot(236)hold onplot(RN3S ratio sortedMax(1)b)plot(RN3S ratio sortedMax(2)g)grid ontitle(RN1L)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)set(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN7png minusr300)

tilefigs()(h)

Bibliography

[1] C Berge ldquoTWO THEOREMS IN GRAPH THEORYrdquo Proceedings of the NationalAcademy of Sciences of the United States of America vol 43 no 9 pp 842ndash844Sep 1957

[2] L Bui S Sanghavi and R Srikant ldquoDistributed link scheduling with constantoverheadrdquo IEEEACM Trans Netw vol 17 no 5 pp 1467ndash1480 2009

[3] R Duan and S Pettie ldquoLinear-time approximation for maximum weight matchingrdquoJ ACM vol 61 no 1 2014

[4] J Edmonds ldquoPaths trees and flowersrdquo Canadian Journal of Mathematics vol 17pp 449ndash467 1965

[5] J E Hopcroft and R M Karp ldquoAn n52 algorithm for maximum matchings inbipartite graphsrdquo SIAM J Comput vol 2 no 4 pp 225ndash231 1973

[6] S Micali and V V Vazirani ldquoAn O(radic|V ||E|) algorithm for finding maximum

matching in general graphsrdquo in 21st Symp on Foundations of Comp Sc (FOCS)IEEE 1980 pp 17ndash27

[7] N Nisse A Salch and V Weber ldquoRecovery of disrupted airline operationsrdquo 2015httphalinriafrSomething

[8] X Wu and R Srikant ldquoRegulated maximal matching A distributed schedulingalgorithm for multi-hop wireless networks with nodeexclusive spectrum sharingrdquo inIEEE Conf on Decision and Control 2005

65

  • Contents
  • Introduction
  • Algorithms
    • Maximum matching
    • k-maximum matching
      • k-matching for Airport Slot assignment
      • The case where k=3
      • The case of Paths
      • The case of the Spider
          • Application
            • Description
            • Reyni Erdos
            • Barabaacutesi Albert
            • Amadeus Graphs
            • Bipartite
            • Bipartite with degree seq
            • Appendix A
              • BipartiteGraphGeneratorpy
              • RandomGraphGeneratorpy
              • kequals3MaximumMatchingpy
              • Plotmat
                  • Bibliography
Page 60: Theodoros Alexandros KARAGKIOULES -  · Introduction This work is the result of a 6 months internship, under the supervision of research O cer Nicolas NISSE. The original scope of

Appendix A 61

RN2L Degree temp1(2)=RN2L DegreeG Hat1RN2L Degree sorted1=sortrows(RN2L Degree temp1)

subplot(232)hold onplot(RN2L Degree sorted1(1)b)plot(RN2L Degree sorted1(2)g)grid ontitle(RN2L)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)

RN3L DegreeG1=(RN3L EdgesG)(RN3L NodesG)RN3L DegreeG Hat1=(RN3L EdgesG Hat)(RN3L NodesG hat)

RN3L Degree temp1(1)=RN3L DegreeG1RN3L Degree temp1(2)=RN3L DegreeG Hat1RN3L Degree sorted1=sortrows(RN3L Degree temp1)

subplot(233)hold onplot(RN3L Degree sorted1(1)b)plot(RN3L Degree sorted1(2)g)grid ontitle(RN3L)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)

RN1S DegreeG1=(RN1S EdgesG)(RN1S NodesG)RN1S DegreeG Hat1=(RN1S EdgesG Hat)(RN1S NodesG hat)

RN1S Degree temp1(1)=RN1S DegreeG1RN1S Degree temp1(2)=RN1S DegreeG Hat1RN1S Degree sorted1=sortrows(RN1S Degree temp1)

subplot(234)hold onplot(RN1S Degree sorted1(1)b)plot(RN1S Degree sorted1(2)g)grid ontitle(RN1S)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)

RN2S DegreeG1=(RN2S EdgesG)(RN2S NodesG)RN2S DegreeG Hat1=(RN2S EdgesG Hat)(RN2S NodesG hat)

RN2S Degree temp1(1)=RN2S DegreeG1

62 Application

RN2S Degree temp1(2)=RN2S DegreeG Hat1RN2S Degree sorted1=sortrows(RN2S Degree temp1)

subplot(235)hold onplot(RN2S Degree sorted1(1)b)plot(RN2S Degree sorted1(2)g)grid ontitle(RN2S)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)

RN3S DegreeG1=(RN3S EdgesG)(RN3S NodesG)RN3S DegreeG Hat1=(RN3S EdgesG Hat)(RN3S NodesG hat)

RN3S Degree temp1(1)=RN3S DegreeG1RN3S Degree temp1(2)=RN3S DegreeG Hat1RN3S Degree sorted1=sortrows(RN3S Degree temp1)

subplot(236)hold onplot(RN3S Degree sorted1(1)b)plot(RN3S Degree sorted1(2)g)grid ontitle(RN3S)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)set(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN6png minusr300)h(7)=figure(NameSorted mATCHED DEGREENumberTitleoff)RN1L ratioMax(1)=RN1L MaxDegreeGRN1L ratioMax(2)=RN1L MaxDegreeG Hat

RN1L ratio sortedMax=sortrows(RN1L ratioMax)subplot(231)hold onplot(RN1L ratio sortedMax(1)b)plot(RN1L ratio sortedMax(2)g)grid ontitle(RN1L)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)

RN2L ratioMax(1)=RN2L MaxDegreeGRN2L ratioMax(2)=RN2L MaxDegreeG Hat

RN2L ratio sortedMax=sortrows(RN2L ratioMax)subplot(232)

Appendix A 63

hold onplot(RN2L ratio sortedMax(1)b)plot(RN2L ratio sortedMax(2)g)grid ontitle(RN2L)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)

RN3L ratioMax(1)=RN3L MaxDegreeGRN3L ratioMax(2)=RN3L MaxDegreeG Hat

RN3L ratio sortedMax=sortrows(RN3L ratioMax)subplot(233)hold onplot(RN3L ratio sortedMax(1)b)plot(RN3L ratio sortedMax(2)g)grid ontitle(RN3L)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)

RN1S ratioMax(1)=RN1S MaxDegreeGRN1S ratioMax(2)=RN1S MaxDegreeG Hat

RN1S ratio sortedMax=sortrows(RN1S ratioMax)subplot(234)hold onplot(RN1S ratio sortedMax(1)b)plot(RN1S ratio sortedMax(2)g)grid ontitle(RN1S)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)

RN2S ratioMax(1)=RN2S MaxDegreeGRN2S ratioMax(2)=RN2S MaxDegreeG Hat

RN2S ratio sortedMax=sortrows(RN2S ratioMax)

subplot(235)hold onplot(RN2S ratio sortedMax(1)b)plot(RN2S ratio sortedMax(2)g)grid ontitle(RN2S)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)

RN3S ratioMax(1)=RN3S MaxDegreeGRN3S ratioMax(2)=RN3S MaxDegreeG Hat

64 Application

RN3S ratio sortedMax=sortrows(RN3S ratioMax)subplot(236)hold onplot(RN3S ratio sortedMax(1)b)plot(RN3S ratio sortedMax(2)g)grid ontitle(RN1L)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)set(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN7png minusr300)

tilefigs()(h)

Bibliography

[1] C Berge ldquoTWO THEOREMS IN GRAPH THEORYrdquo Proceedings of the NationalAcademy of Sciences of the United States of America vol 43 no 9 pp 842ndash844Sep 1957

[2] L Bui S Sanghavi and R Srikant ldquoDistributed link scheduling with constantoverheadrdquo IEEEACM Trans Netw vol 17 no 5 pp 1467ndash1480 2009

[3] R Duan and S Pettie ldquoLinear-time approximation for maximum weight matchingrdquoJ ACM vol 61 no 1 2014

[4] J Edmonds ldquoPaths trees and flowersrdquo Canadian Journal of Mathematics vol 17pp 449ndash467 1965

[5] J E Hopcroft and R M Karp ldquoAn n52 algorithm for maximum matchings inbipartite graphsrdquo SIAM J Comput vol 2 no 4 pp 225ndash231 1973

[6] S Micali and V V Vazirani ldquoAn O(radic|V ||E|) algorithm for finding maximum

matching in general graphsrdquo in 21st Symp on Foundations of Comp Sc (FOCS)IEEE 1980 pp 17ndash27

[7] N Nisse A Salch and V Weber ldquoRecovery of disrupted airline operationsrdquo 2015httphalinriafrSomething

[8] X Wu and R Srikant ldquoRegulated maximal matching A distributed schedulingalgorithm for multi-hop wireless networks with nodeexclusive spectrum sharingrdquo inIEEE Conf on Decision and Control 2005

65

  • Contents
  • Introduction
  • Algorithms
    • Maximum matching
    • k-maximum matching
      • k-matching for Airport Slot assignment
      • The case where k=3
      • The case of Paths
      • The case of the Spider
          • Application
            • Description
            • Reyni Erdos
            • Barabaacutesi Albert
            • Amadeus Graphs
            • Bipartite
            • Bipartite with degree seq
            • Appendix A
              • BipartiteGraphGeneratorpy
              • RandomGraphGeneratorpy
              • kequals3MaximumMatchingpy
              • Plotmat
                  • Bibliography
Page 61: Theodoros Alexandros KARAGKIOULES -  · Introduction This work is the result of a 6 months internship, under the supervision of research O cer Nicolas NISSE. The original scope of

62 Application

RN2S Degree temp1(2)=RN2S DegreeG Hat1RN2S Degree sorted1=sortrows(RN2S Degree temp1)

subplot(235)hold onplot(RN2S Degree sorted1(1)b)plot(RN2S Degree sorted1(2)g)grid ontitle(RN2S)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)

RN3S DegreeG1=(RN3S EdgesG)(RN3S NodesG)RN3S DegreeG Hat1=(RN3S EdgesG Hat)(RN3S NodesG hat)

RN3S Degree temp1(1)=RN3S DegreeG1RN3S Degree temp1(2)=RN3S DegreeG Hat1RN3S Degree sorted1=sortrows(RN3S Degree temp1)

subplot(236)hold onplot(RN3S Degree sorted1(1)b)plot(RN3S Degree sorted1(2)g)grid ontitle(RN3S)ylabel(Graph density) xminusaxis labelxlabel(Instances) yminusaxis labellegend(GG hatLocationnorthoutsideOrientationhorizontal)set(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN6png minusr300)h(7)=figure(NameSorted mATCHED DEGREENumberTitleoff)RN1L ratioMax(1)=RN1L MaxDegreeGRN1L ratioMax(2)=RN1L MaxDegreeG Hat

RN1L ratio sortedMax=sortrows(RN1L ratioMax)subplot(231)hold onplot(RN1L ratio sortedMax(1)b)plot(RN1L ratio sortedMax(2)g)grid ontitle(RN1L)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)

RN2L ratioMax(1)=RN2L MaxDegreeGRN2L ratioMax(2)=RN2L MaxDegreeG Hat

RN2L ratio sortedMax=sortrows(RN2L ratioMax)subplot(232)

Appendix A 63

hold onplot(RN2L ratio sortedMax(1)b)plot(RN2L ratio sortedMax(2)g)grid ontitle(RN2L)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)

RN3L ratioMax(1)=RN3L MaxDegreeGRN3L ratioMax(2)=RN3L MaxDegreeG Hat

RN3L ratio sortedMax=sortrows(RN3L ratioMax)subplot(233)hold onplot(RN3L ratio sortedMax(1)b)plot(RN3L ratio sortedMax(2)g)grid ontitle(RN3L)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)

RN1S ratioMax(1)=RN1S MaxDegreeGRN1S ratioMax(2)=RN1S MaxDegreeG Hat

RN1S ratio sortedMax=sortrows(RN1S ratioMax)subplot(234)hold onplot(RN1S ratio sortedMax(1)b)plot(RN1S ratio sortedMax(2)g)grid ontitle(RN1S)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)

RN2S ratioMax(1)=RN2S MaxDegreeGRN2S ratioMax(2)=RN2S MaxDegreeG Hat

RN2S ratio sortedMax=sortrows(RN2S ratioMax)

subplot(235)hold onplot(RN2S ratio sortedMax(1)b)plot(RN2S ratio sortedMax(2)g)grid ontitle(RN2S)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)

RN3S ratioMax(1)=RN3S MaxDegreeGRN3S ratioMax(2)=RN3S MaxDegreeG Hat

64 Application

RN3S ratio sortedMax=sortrows(RN3S ratioMax)subplot(236)hold onplot(RN3S ratio sortedMax(1)b)plot(RN3S ratio sortedMax(2)g)grid ontitle(RN1L)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)set(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN7png minusr300)

tilefigs()(h)

Bibliography

[1] C Berge ldquoTWO THEOREMS IN GRAPH THEORYrdquo Proceedings of the NationalAcademy of Sciences of the United States of America vol 43 no 9 pp 842ndash844Sep 1957

[2] L Bui S Sanghavi and R Srikant ldquoDistributed link scheduling with constantoverheadrdquo IEEEACM Trans Netw vol 17 no 5 pp 1467ndash1480 2009

[3] R Duan and S Pettie ldquoLinear-time approximation for maximum weight matchingrdquoJ ACM vol 61 no 1 2014

[4] J Edmonds ldquoPaths trees and flowersrdquo Canadian Journal of Mathematics vol 17pp 449ndash467 1965

[5] J E Hopcroft and R M Karp ldquoAn n52 algorithm for maximum matchings inbipartite graphsrdquo SIAM J Comput vol 2 no 4 pp 225ndash231 1973

[6] S Micali and V V Vazirani ldquoAn O(radic|V ||E|) algorithm for finding maximum

matching in general graphsrdquo in 21st Symp on Foundations of Comp Sc (FOCS)IEEE 1980 pp 17ndash27

[7] N Nisse A Salch and V Weber ldquoRecovery of disrupted airline operationsrdquo 2015httphalinriafrSomething

[8] X Wu and R Srikant ldquoRegulated maximal matching A distributed schedulingalgorithm for multi-hop wireless networks with nodeexclusive spectrum sharingrdquo inIEEE Conf on Decision and Control 2005

65

  • Contents
  • Introduction
  • Algorithms
    • Maximum matching
    • k-maximum matching
      • k-matching for Airport Slot assignment
      • The case where k=3
      • The case of Paths
      • The case of the Spider
          • Application
            • Description
            • Reyni Erdos
            • Barabaacutesi Albert
            • Amadeus Graphs
            • Bipartite
            • Bipartite with degree seq
            • Appendix A
              • BipartiteGraphGeneratorpy
              • RandomGraphGeneratorpy
              • kequals3MaximumMatchingpy
              • Plotmat
                  • Bibliography
Page 62: Theodoros Alexandros KARAGKIOULES -  · Introduction This work is the result of a 6 months internship, under the supervision of research O cer Nicolas NISSE. The original scope of

Appendix A 63

hold onplot(RN2L ratio sortedMax(1)b)plot(RN2L ratio sortedMax(2)g)grid ontitle(RN2L)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)

RN3L ratioMax(1)=RN3L MaxDegreeGRN3L ratioMax(2)=RN3L MaxDegreeG Hat

RN3L ratio sortedMax=sortrows(RN3L ratioMax)subplot(233)hold onplot(RN3L ratio sortedMax(1)b)plot(RN3L ratio sortedMax(2)g)grid ontitle(RN3L)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)

RN1S ratioMax(1)=RN1S MaxDegreeGRN1S ratioMax(2)=RN1S MaxDegreeG Hat

RN1S ratio sortedMax=sortrows(RN1S ratioMax)subplot(234)hold onplot(RN1S ratio sortedMax(1)b)plot(RN1S ratio sortedMax(2)g)grid ontitle(RN1S)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)

RN2S ratioMax(1)=RN2S MaxDegreeGRN2S ratioMax(2)=RN2S MaxDegreeG Hat

RN2S ratio sortedMax=sortrows(RN2S ratioMax)

subplot(235)hold onplot(RN2S ratio sortedMax(1)b)plot(RN2S ratio sortedMax(2)g)grid ontitle(RN2S)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)

RN3S ratioMax(1)=RN3S MaxDegreeGRN3S ratioMax(2)=RN3S MaxDegreeG Hat

64 Application

RN3S ratio sortedMax=sortrows(RN3S ratioMax)subplot(236)hold onplot(RN3S ratio sortedMax(1)b)plot(RN3S ratio sortedMax(2)g)grid ontitle(RN1L)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)set(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN7png minusr300)

tilefigs()(h)

Bibliography

[1] C Berge ldquoTWO THEOREMS IN GRAPH THEORYrdquo Proceedings of the NationalAcademy of Sciences of the United States of America vol 43 no 9 pp 842ndash844Sep 1957

[2] L Bui S Sanghavi and R Srikant ldquoDistributed link scheduling with constantoverheadrdquo IEEEACM Trans Netw vol 17 no 5 pp 1467ndash1480 2009

[3] R Duan and S Pettie ldquoLinear-time approximation for maximum weight matchingrdquoJ ACM vol 61 no 1 2014

[4] J Edmonds ldquoPaths trees and flowersrdquo Canadian Journal of Mathematics vol 17pp 449ndash467 1965

[5] J E Hopcroft and R M Karp ldquoAn n52 algorithm for maximum matchings inbipartite graphsrdquo SIAM J Comput vol 2 no 4 pp 225ndash231 1973

[6] S Micali and V V Vazirani ldquoAn O(radic|V ||E|) algorithm for finding maximum

matching in general graphsrdquo in 21st Symp on Foundations of Comp Sc (FOCS)IEEE 1980 pp 17ndash27

[7] N Nisse A Salch and V Weber ldquoRecovery of disrupted airline operationsrdquo 2015httphalinriafrSomething

[8] X Wu and R Srikant ldquoRegulated maximal matching A distributed schedulingalgorithm for multi-hop wireless networks with nodeexclusive spectrum sharingrdquo inIEEE Conf on Decision and Control 2005

65

  • Contents
  • Introduction
  • Algorithms
    • Maximum matching
    • k-maximum matching
      • k-matching for Airport Slot assignment
      • The case where k=3
      • The case of Paths
      • The case of the Spider
          • Application
            • Description
            • Reyni Erdos
            • Barabaacutesi Albert
            • Amadeus Graphs
            • Bipartite
            • Bipartite with degree seq
            • Appendix A
              • BipartiteGraphGeneratorpy
              • RandomGraphGeneratorpy
              • kequals3MaximumMatchingpy
              • Plotmat
                  • Bibliography
Page 63: Theodoros Alexandros KARAGKIOULES -  · Introduction This work is the result of a 6 months internship, under the supervision of research O cer Nicolas NISSE. The original scope of

64 Application

RN3S ratio sortedMax=sortrows(RN3S ratioMax)subplot(236)hold onplot(RN3S ratio sortedMax(1)b)plot(RN3S ratio sortedMax(2)g)grid ontitle(RN1L)ylabel(Max Degree) xminusaxis labelxlabel(Instances) yminusaxis labellegend(Max degree GMax degree G hatLocationnorthoutsideOrientationhorizontal)set(gcfPaperUnitscentimetersPaperPosition[0 0 50 30])print(minusdpng RN7png minusr300)

tilefigs()(h)

Bibliography

[1] C Berge ldquoTWO THEOREMS IN GRAPH THEORYrdquo Proceedings of the NationalAcademy of Sciences of the United States of America vol 43 no 9 pp 842ndash844Sep 1957

[2] L Bui S Sanghavi and R Srikant ldquoDistributed link scheduling with constantoverheadrdquo IEEEACM Trans Netw vol 17 no 5 pp 1467ndash1480 2009

[3] R Duan and S Pettie ldquoLinear-time approximation for maximum weight matchingrdquoJ ACM vol 61 no 1 2014

[4] J Edmonds ldquoPaths trees and flowersrdquo Canadian Journal of Mathematics vol 17pp 449ndash467 1965

[5] J E Hopcroft and R M Karp ldquoAn n52 algorithm for maximum matchings inbipartite graphsrdquo SIAM J Comput vol 2 no 4 pp 225ndash231 1973

[6] S Micali and V V Vazirani ldquoAn O(radic|V ||E|) algorithm for finding maximum

matching in general graphsrdquo in 21st Symp on Foundations of Comp Sc (FOCS)IEEE 1980 pp 17ndash27

[7] N Nisse A Salch and V Weber ldquoRecovery of disrupted airline operationsrdquo 2015httphalinriafrSomething

[8] X Wu and R Srikant ldquoRegulated maximal matching A distributed schedulingalgorithm for multi-hop wireless networks with nodeexclusive spectrum sharingrdquo inIEEE Conf on Decision and Control 2005

65

  • Contents
  • Introduction
  • Algorithms
    • Maximum matching
    • k-maximum matching
      • k-matching for Airport Slot assignment
      • The case where k=3
      • The case of Paths
      • The case of the Spider
          • Application
            • Description
            • Reyni Erdos
            • Barabaacutesi Albert
            • Amadeus Graphs
            • Bipartite
            • Bipartite with degree seq
            • Appendix A
              • BipartiteGraphGeneratorpy
              • RandomGraphGeneratorpy
              • kequals3MaximumMatchingpy
              • Plotmat
                  • Bibliography
Page 64: Theodoros Alexandros KARAGKIOULES -  · Introduction This work is the result of a 6 months internship, under the supervision of research O cer Nicolas NISSE. The original scope of

Bibliography

[1] C Berge ldquoTWO THEOREMS IN GRAPH THEORYrdquo Proceedings of the NationalAcademy of Sciences of the United States of America vol 43 no 9 pp 842ndash844Sep 1957

[2] L Bui S Sanghavi and R Srikant ldquoDistributed link scheduling with constantoverheadrdquo IEEEACM Trans Netw vol 17 no 5 pp 1467ndash1480 2009

[3] R Duan and S Pettie ldquoLinear-time approximation for maximum weight matchingrdquoJ ACM vol 61 no 1 2014

[4] J Edmonds ldquoPaths trees and flowersrdquo Canadian Journal of Mathematics vol 17pp 449ndash467 1965

[5] J E Hopcroft and R M Karp ldquoAn n52 algorithm for maximum matchings inbipartite graphsrdquo SIAM J Comput vol 2 no 4 pp 225ndash231 1973

[6] S Micali and V V Vazirani ldquoAn O(radic|V ||E|) algorithm for finding maximum

matching in general graphsrdquo in 21st Symp on Foundations of Comp Sc (FOCS)IEEE 1980 pp 17ndash27

[7] N Nisse A Salch and V Weber ldquoRecovery of disrupted airline operationsrdquo 2015httphalinriafrSomething

[8] X Wu and R Srikant ldquoRegulated maximal matching A distributed schedulingalgorithm for multi-hop wireless networks with nodeexclusive spectrum sharingrdquo inIEEE Conf on Decision and Control 2005

65

  • Contents
  • Introduction
  • Algorithms
    • Maximum matching
    • k-maximum matching
      • k-matching for Airport Slot assignment
      • The case where k=3
      • The case of Paths
      • The case of the Spider
          • Application
            • Description
            • Reyni Erdos
            • Barabaacutesi Albert
            • Amadeus Graphs
            • Bipartite
            • Bipartite with degree seq
            • Appendix A
              • BipartiteGraphGeneratorpy
              • RandomGraphGeneratorpy
              • kequals3MaximumMatchingpy
              • Plotmat
                  • Bibliography