MultiAspect Graphs: Algebraic representation and algorithms

We present the algebraic representation and basic algorithms of MultiAspect Graphs~(MAGs), a structure capable of representing multilayer and time-varying networks while also having the property of being isomorphic to a directed graph. In particular, we show that, as a consequence of the properties associated with the MAG structure, a MAG can be represented in matrix form. Moreover, we also show that any possible MAG function (algorithm) can be obtained from this matrix-based representation. This is an important theoretical result since it paves the way for adapting well-known graph algorithms for application in MAGs. We present a set of basic MAG algorithms, constructed from well-known graph algorithms, such as degree computing, Breadth First Search (BFS), and Depth First Search (DFS). These algorithms adapted to the MAG context can be used as primitives for building other more sophisticated MAG algorithms. Therefore, such examples can be seen as guidelines on how to properly derive MAG algorithms from basic algorithms on directed graph. We also make available python implementations of all the algorithms presented in this paper.


Introduction
Graph theory finds many applications in the representation and analysis of complex networked systems [1][2][3]. In most cases, the utility of the graph abstraction comes from its inherent ability to represent binary transitive relations (i.e. transitive relations between two objects), which due to the transitivity property gives raise to key concepts, such as walks, paths, and connectivity. This graph conceptual framework allowed the emergence of basic algorithms, such as Breadth First Search (BFS) and Depth First Search (DFS) [4,5]. These basic graph algorithms, in their turn, made possible the development of more sophisticated algorithms for the analysis of specific properties of complex networks, such as network centrality or network robustness [6][7][8][9], and also the analysis of dynamic processes in complex networks, such as network generative processes or information diffusion [10][11][12][13][14]. Several generalizations of the basic graph concept have been proposed for modelling complex systems that can be represented by layers of distinct networks [15,16] and also complex systems in which the network itself evolves with time [17,18].
In our previous work [19], we formalize the MultiAspect Graph (MAG) structure, while also stating and proving its main properties. The adopted adjacency concept in MAGs is similar to the one found in simple directed graphs, where the adjacency is expressed between two vertices, leading to a structure in which an edge represents a binary relation between two composite objects. Moreover, in [19], we show that MAGs are closely related to simple directed graphs, as we prove that each MAG has a simple directed graph, which is isomorphic to it. This isomorphism relation between MAGs and directed graphs is a consequence of the fact that both MAGs and directed graphs share a similar adjacency relation.
MAGs find application in the representation and analysis of dynamic complex networks, such as multilayer or time-varying networks; or even networks that are both multilayer and time-varying as well as higher-order networks [20,21]. Examples of such networks include face-to-face in-person contact networks [22], mobile phone networks [23,24], gene regulatory networks [25], urban transportation networks [26], brain networks [27,28], social networks [29], among many others. In particular, we have previously applied the MAG abstraction from [19] to different purposes, such as modeling time-varying graphs [30], studying time centrality in dynamic complex networks [31], and investigating social events based on mobile phone networks [32]. To illustrate the MAG concept in more details in this paper, we present in Section 3 an example of modeling a simple illustrative multimodal urban transportation network.
In this paper, we build upon the basic MAG properties presented in [19] and show that MAGs can be represented by matrices in a form similar to those used for simple directed graphs (i.e., those with no multiple edges). Moreover, we here show that any algorithm (function) on a MAG can be obtained from its matrix representation. This is an important theoretical result since it paves the way for adapting well-known graph algorithms for application in MAGs, thus easing the effort to develop the analysis and application of MAGs for modelling complex networked systems. We then present the most common matrix representations that can be applied to MAGs, although we do not detail all the properties of these matrices, since they are well established in the literature [5,33]. Further, we introduce in detail the construction of MAG algorithms for computing degree, BFS, and DFS to exemplify how MAG algorithms can be derived from traditional graph algorithms, thus providing an illustrative guideline for developing other more sophisticated MAG algorithms in a similar way. As a further contribution, we also make available Python implementations of all the algorithms presented in this paper at the following URL: http://github.com/wehmuthklaus/MAG_ Algorithms.
This paper is organized as follows. Section 2 briefly presents the basic MAG definitions and properties derived from [19] in order to allow enough background of the current paper. Section 2 also presents illustrative examples of MAGs and its adjacency notion. Section 3 shows the representation of MAGs by means of algebraic structures, such as matrices. Emphasis is given to matrix representations, which are derived from the isomorphism relation between MAGs and simple directed graphs. In particular, we also introduce in Section 3.1 the companion tuple, which is a complement to the MAG matrix representations. In Section 4, we present basic MAG algorithms which are derived from well-known simple graph algorithms. Further, in Section 4.2, we show that any algorithm (function) that can be defined for a MAG can be also obtained from its adjacency matrix and companion tuple, establishing the theoretical basis for deriving MAG algorithms from well-known simple graph algorithms. Finally, Section 5 presents our final remarks and perspectives for future work.

MultiAspect Graph (MAG)
In this section, we present a formal definition of a MAG, as well as some key properties, which are formally stated and proved in [19].

MAG definition
We define a MAG as H " pA, Eq, where E is a set of edges and A is a finite list of aspects. Each aspect ϕ P A is a finite set, and the number of aspects p " |A| is called the order of H. Each edge e P E is a tuple with 2ˆp elements. All edges are constructed so that they are of the form pa 1 , . . . , a p , b 1 , . . . , b p q, where a 1 , b 1 are elements of the first aspect of H, a 2 , b 2 are elements of the second aspect of H, and so on, until a p , b p which are elements of the p-th aspect of H. Note that the ordered tuple that represents each MAG edge is constructed so that their elements are divided into two distinct groups, each having exactly one element of each aspect, in the same order as the aspects are defined on the list A.
As a matter of notation, we say that ApHq is the aspect list of H and EpHq is the edge set of H. Further, ApHqrns is the n-th aspect in ApHq, |ApHqrns| " τ n is the number of elements in ApHqrns, and p " |ApHq| is the order of H.
In addition to the former definition, we define the following two sets constructed from the cartesian products of aspects of an order p MAG: the cartesian product of all the aspects of the MAG H, and EpHq " 2p ą n"1 ApHqrpn´1qpmod pq`1s, which is the set of all possible edges in the MAG H, so that EpHq Ď EpHq.
We call u P VpHq a composite vertex of MAG H. As a matter of notation, a composite vertex is always represented as a bold lowercase letter, as in u, for instance. From the properties stated for the MAG edge in our definition, it follows that an MAG edge is closely related to an ordered pair of composite vertices. For any given MAG H, every MAG edge e P EpHq has the form pa 1 , . . . , a p , b 1 , . . . , b p q, so that pa 1 , . . . , a p q P VpHq and pb 1 , . . . , b p q P VpHq are composite vertices of this given MAG H. From this, we can define two functions (3) e " pa 1 , a 2 , . . . , a p , b 1 , b 2 , . . . , b p q Þ Ñ pa 1 , a 2 , . . . , a p q " u, and π d : EpHq Ñ VpHq (4) e " pa 1 , a 2 , . . . , a p , b 1 , b 2 , . . . , b p q Þ Ñ pb 1 , b 2 , . . . , b p q " v.
We call π o peq the origin composite vertex of e and π d peq the destination composite vertex of e. Moreover, we can define the function ψ : EpHq Ñ VpHq ą VpHq (5) e Þ Ñ pπ o peq, π d peqq " ppa 1 , . . . , a p q, pb 1 , . . . , b p qq " pu, vq, from which we can construct a directed graph G H " pV pHq, ψpEpHqq. In [19], we demonstrate that the directed graph G H " pV pHq, ψpEpHqq is isomorphic to the MAG H from which it was originated. At this point, we can therefore define the function g : pApHq, EpHqq Ñ pVpHq, VpHq ą VpHqq (6) H Þ Ñ pVpHq, ψpEpHqq, which maps every MAG H to its isomorphic directed graph gpHq. Further, we define the set of functions π i : VpHq Ñ ApHqris pa 1 , a 2 , . . . , a p q Þ Ñ a i , which extracts the n-th element of a composite vertex tuple.

MAG sub-determination
The sub-determination is a generalization of the aggregation concept applied to multilayer or time-varying graphs, in which all layers can be aggregated, resulting in a traditional graph. Since a MAG can have more than 2 aspects, the subdetermination can be done in more ways than the aggregation. A given MAG H of order p, can be sub-determined in 2 p´2 ways. For each of these 2 p´2 ways, we have a list A C pHq Ă ApHq of the aspects used to determine an equivalence class. Note that in a MAG of order p " 1 (i.e. a traditional graph), a vertex can not be sub-determined, since 2 p´2 " 0.

Sub-determined composite vertices
Let ζ , with 1 ď ζ ď 2 p´2 , be an index for one of the possible ways to construct a proper nonempty sublist of aspects. From this, we can define a canonical representation of the sub-determination directly defined by ζ . For any given ζ , we consider the p-bit binary expansion of ζ that is used as an indicator showing which aspects of the original MAG are present on the sub-determination. More specifically, the least significant bit indicates the presence or absence of the first aspect and the most significant bit indicates the presence or absence of the last aspect. By this convention, in a MAG with p " 3 aspects, we have that ζ " 001 2 corresponds to the sub-determination where only the first aspect is present, ζ " 010 2 corresponds to the sub-determination where only the second aspect is present, ζ " 101 2 corresponds to the sub-determination where both the first and the third aspects are present, and so on. By using this convention, we can directly associate a given ζ to its corresponding aspect sublist.
Therefore, for each ζ , we have a unique sublist A ζ pHq of aspects, such that p ζ " |A ζ pHq| is the order of the sub-determination ζ . We now define the set where V ζ pHq is the cartesian product of all the aspects in the sublist A ζ pHq of aspects, according to the index ζ . We call u ζ P V ζ pHq a sub-determined vertex, according to the sub-determination ζ .
We can now define the function pa 1 , a 2 , . . . , a p q Þ Ñ pa ζ 1 , a ζ 2 , . . . , a ζ m q, where m " p ζ . S ζ maps a composite vertex u P VpHq to the corresponding subdetermined composite vertex u ζ P V ζ pHq, according to the sub-determination ζ . As pa ζ 1 , a ζ 2 , . . . , a ζ m q P V ζ pHq, it follows that a ζ 1 P A ζ pHqr1s, . . . , a ζ m P A ζ pHqrms. From the definition, it can be seen that the function S ζ is not injective. Hence, the function S ζ for a given sub-determination can be used to define a equivalence relation " ζ in VpHq, where for any given composite vertices u, v P VpHq, we have that u " ζ v if and only if S ζ puq " S ζ pvq.

Sub-determined edges
From the sub-determination ζ of order p ζ , we can also construct the set where p ζ " |A ζ pHq| is the order of the sub-determination ζ , and E ζ pHq is the set of all possible sub-determined edges according to ζ . We then define the function where m " p ζ and a ζ 1 , b ζ 1 P A ζ pHqr1s, a ζ 2 , 2 ζ 2 P A ζ pHqr2s, . . . , a ζ m , b ζ m P A ζ pHqrms. This function takes an edge to its sub-determined form according to ζ in a similar way as defined above for composite vertices. In general, the function E ζ is not injective. Consider two distinct edges e 1 , e 2 P EpHq, such that e 1 and e 2 differ only in aspects which are not in A ζ pHq. Since E ζ p¨q only contains values for aspects present in A ζ pHq, it follows that E ζ pe 1 q " E ζ pe 2 q, and therefore E ζ is not injective. Further, consider an edge e P EpHq and its sub-determined edge e ζ " E ζ peq, such that π o pe ζ q " π d pe ζ q, i.e. e ζ is a self-loop. Since self-loops are not allowed to be present on a MAG, it follows that e ζ R E ζ pEpHqq. As consequence, we have that |E ζ pEpHqq| ď |EpHq|.

Sub-determined MAGs
For a given sub-determination ζ we have the sublist A ζ pHq of considered aspects and also the sub-determined edges obtained from ζ . Based on them, we can now obtain a sub-determined MAG. For a given sub-determination ζ we define the function M ζ : pApHq, EpHqq Ñ pA ζ pHq, E ζ pHqq H Þ Ñ pA ζ pHq, E ζ pEpHqqq.
Since A ζ pHq is the sublist of aspects of H prescribed by ζ and E ζ pEpHqq is the set of all sub-determined edges according to the sub-determination ζ , it follows that pA ζ pHq, E ζ pEpHqqq is a MAG obtained from H according to the subdetermination ζ . As |A ζ pHq| ă |ApHq|, it follows that the order of M ζ pHq is lower than the order of H. Further, since self-loops may be created by edge subdetermination and discarded, and also since E ζ is not injective, it follows that |E ζ pEpHqq| ď |EpHq|. u P VpHq such that u P tπ o pe 1 q, π d pe 1 qu and u P tπ o pe 2 q, π d pe 2 qu. Figure 1 shows an illustrative example of three MAG edges. The figure depicts a four aspects MAG, where each set of colored circles represents one aspect, and each edge has two elements of each aspect.
Although the structure of a MAG edge is similar to an even uniform hypergraph edge, the adjacency definition used on MAGs is not the usual one adopted on hypergraphs. The adjacency concept found on a MAG is close to the one associated with traditional directed graphs, where a MAG edge can be seen as a relation between two composite vertices, which are composite objects constructed from aspect elements. Therefore, a MAG edge expresses a relationship between two (composite) objects in the same way as a directed graph edge. This concept leads to the isomorphism between MAGs and directed graphs, as well as the close relation between walks, trails, and paths on MAGs and directed graphs.

MAG isomorphism
In order to define MAG isomorphism it is necessary to define the concept an aspect list bijection. Given two MAGs H and K, both with p aspects, an aspect list bijection F : ApHq Ñ ApKq is defined as a set of p bijective functions, f 1 , f 2 , . . . , f p , such that each aspect of the MAG H is the domain of exactly one of these functions and each aspect of MAG K is the codomain of exactly one of these functions. It follows from this definition that given a composite vertex u P VpHq, the aspect list bijection F takes u to a composite vertex Fpuq P VpKq.
Two MAGs of order p, H and K, are isomorphic if there is an aspect list bijection F : ApHq Ñ ApKq such that an edge e P EpHq if and only if the edge pFpπ o peqq, Fpπ d peqqq P EpKq.

MAG walks, trails, and paths
There is a close relation between walks, trails, and paths on a MAG and their counterparts in the isomorphic directed graph gpHq.
A walk on a MAG H is defined as an alternating sequence W " ru 1 , e 1 , u 2 , e 2 , u 3 , . . . , u k´1 , e k´1 , u k s of composite vertices u n P VpHq and edges e m P EpHq, such that u n " π o pe n q and u n`1 " π d pe n q for 1 ď n ă k. It follows from this definition that in a walk, consecutive composite vertices as well as consecutive MAG edges are adjacent.
From the concept that walks, trails, and paths on a MAG have a isomorphism relation to their counterparts on the directed graph gpHq, it follows that analysis and algorithms based on walks, trails, and paths can be formulated on the directed graph gpHq. These properties will be extensively used in the current work.

Algebraic Representation
In this section, we discuss ways to represent MAGs [19] by means of algebraic structures. As a consequence to the isomorphism between MAGs and traditional directed graphs, it is straightforward to construct matrix-based representations of MAGs. This section addresses these representations, using the MAG depicted in Figure 2 as an illustrative example. Figure 2 shows an example of a three aspect MAG T . It can be seen as the representation of a time-varying multilayer network, showing a small and simplified section of an urban transit system. More specifically, Figure 2 depicts the MAG T in its composite vertices representation, gpT q, which is the directed graph defined in Expression (6).
Aligned with this view, the aspects of MAG T can be interpreted in the following way: The first aspect represents three distinct locations, labeled 1, 2 and 3. Specifically, location 1 represents a subway station, location 2 a subway station with a bus stop, and location 3 a bus stop. The second aspect represents two distinct urban transit modes depicted as layers, namely Bus and Subway. Finally, the third aspect represents three time instants. The MAG edges can be seen with the following meaning: Location 1 has no edges on the bus transit mode, since it is a subway station. Similarly, location 3 has no edges on the subway mode, since it is a bus stop. The eight black edges represent bus and subway trips between locations. As a simplification all trips are assumed to have the same duration. The red (dotted) edges represent the possibility of staying at a bus stop or subway station and not taking a transit. The six blue (dashed) edges show that it is possible to change between bus and subway layers at all times at location 2. As a simplification, the connection between the bus and subway layers is assumed to take no time. We recognize that the decision of making these edges with 0 time length generates cycles of length 0 in instances of location 2. In real network analysis, 0 length cycles (and also negative length cycles) can cause problems. However, we choose to let these cycles present in this toy example since they will cause no harm for the analysis conducted in this thesis, and also, they make the toy example more compact and readable. Further, we remark that if desired, these 0 length cycles could be broken by adding new composite vertices, or by making the subway/bus transition to have the same length as a subway/bus trip.
In this model, walks represent the ways the urban transit system can be used to travel from one location to another. For instance, starting at location 1 on the subway layer at time t1, it is possible to reach location 3 on the bus layer at time t3. It can be done by taking a subway trip to location 2 at time t2, switching from subway to bus layer at location 2, time t2 and finally taking a bus trip from location 2 bus layer arriving at location 3 on the bus layer at time t3.
The presence of unconnected occurrences of location 1 at bus layer and location 3 at subway layer can be viewed as artefacts of the MAG construction. We call these vertices trivial components of the MAG. This subject will be further addressed in this section.
We remark that a Python implementation of all the algorithms presented in this section is available at the following URL: http://github.com/wehmuthklaus/ MAG_Algorithms.

Companion tuple
Although we show that every MAG H is isomorphic to a directed graph designated gpHq, it is important to note that the set of vertices of this graph is VpHq, as shown in Expression (6). Since the set VpHq is the cartesian product of all the aspects in the MAG H, it is possible to reconstruct the MAG's aspect list from VpHq, which is a step necessary to obtain the MAG H from the directed graph gpHq. When the vertices of the directed graph G associated with a given MAG H are not the composite vertices themselves, it is necessary to provide a mechanism to link each vertex of the directed graph to its corresponding composite vertex on the MAG. This mechanism can be, for instance, a bijective function between VpHq and V pGq.
In the current work, we construct representations for gpHq, such as matrices, which do not directly carry the tuples that characterize the MAG's composite vertices. In this kind of representation, a vertex is associated with a row or column of a matrix. Therefore, additional information has to be provided in order to properly link each row (column) of a matrix to its corresponding composite vertex on the MAG represented by this matrix. This is done by a bijective function D, defined in Section 3.2, where D takes a composite vertex to a natural number, which is the row (column) number in the matrix.
The implementation of D presented in this work is based on the concept of a companion tuple, which complements the matrix representation of a given MAG. For a MAG H with p aspects, its companion tuple has the form p|ApHqr1s|, |ApHqr2s|, . . . , |ApHqrps|q, so that the number of elements on it equals the order of H and each element represents the number of elements of an aspect of H. As a matter of notation, we represent the companion tuple of a given MAG H as where p is the order of H. When there is no ambiguity in relation to which MAG we are referring to, we may use the notation τ instead of τpHq. For instance, the companion tuple of the MAG T shown in Figure 2 is τpT q " p3, 2, 3q, since T has 3 aspects, of which the first has 3 elements, the second 2 elements, and the third 3 elements. Algorithm 1 shows the building of the companion tuple for a given MAG H. Assuming that the size of the aspect list ApHq and the size of each of the aspect sets contained in ApHq are known from the computational representation of ApHq, the time complexity for building the companion tuple is Oppq, where p is the number of aspects on MAG H. If, however, these sizes are unknown, then the time complexity is Opsq, where s " ř p i"1 |ApHqris|, since each element of each aspect has to be counted. We remark that, in either case, the time complexity for building the companion tuple is less than OpVpHqq, which is the order of the set of composite vertices of the MAG. For a given MAG H and a sub-determination ζ , we also define the subdetermined companion tuple τ ζ pHq, which is obtained by multiplying each entry of the original companion tuple by the equivalent entry of the tuple representation of ζ , as shown in Algorithm 2. The sub-determined companion tuple has the same value as the original companion tuple for the aspects that have value 1 in ζ and 0 otherwise.

Order of composite vertices and aspects
In general, the order of the composite vertices and aspects on a MAG is not relevant. That is, changing the order in which the aspects or their elements are presented does not affect the result of any algorithm or analysis performed on a MAG, since the MAG obtained by such changes is isomorphic to the original one. The definition of the MAG isomorphism adopted in this work can be found in Section 2.4. However, in order to show the MAG's algebraic representation in a consistent way, it is necessary to link the MAG's composite vertices to rows and columns of matrices, which is achieved by the bijective function D, defined in this section at Equation (15). We now show the preliminary steps necessary for the definition of function D, as implemented in this work.
The aspect order is adopted as the same in which the aspects are placed on the MAG's companion tuple. For the ordering of composite vertices, we define the numerical representation of each composite vertex from its tuple. In order to obtain the composite vertex numerical representation, we first translate the composite vertex into a numerical tuple. This is done by applying a family of indices, one for each aspect on the composite vertex, where for every aspect i the corresponding index ranges from 0 to τ i´1 , where τ i is the number of elements on the i-th aspect of the MAG. Since this is a simple index substitution, we do not use a distinct notation for the composite vertex on its numerical tuple form. We, however, reserve the notation uris to express the i-th element of the composite vertex on its numerical form.
To calculate the numerical representation of a composite vertex, we define the weight of each position on the composite vertex tuple of a MAG H with p aspects as where i is the position in the tuple varying from 1 to p, τ is the MAG's companion tuple, and τ j is the j-th element of the MAG's companion tuple. Note that |τ| " p meaning that the length of the companion tuple is the order of the MAG, i.e. the number of its aspects. Finally, we define the composite vertex numerical representation as where |τ| " p is the MAG's order, and vris is the i-th component of the composite vertex. Figure 3 shows the MAG T with its composite vertices, and their numerical representations ranging from p1q to p18q. In order to illustrate how the numerical representations are obtained, we show examples based on the MAG T . For this representation, we adopt aspect indices such that for aspect 1 we have Idxp1q " 0, Idxp2q " 1 and Idxp3q " 2. For aspect 2, we have IdxpBusq " 0 and IdxpSubwayq " 1, while for aspect 3, Idxpt 1 q " 0, Idxpt 2 q " 1 and Idxpt 3 q " 2.
Algorithm 3 determines the numerical representation of a composite vertex v represented by its numerical tuple. The presented implementation extends the concepts presented in Equations (14) and (15), so that this algorithm can also be used to determine the numerical representation of sub-determined composite vertices. In order to determine the numerical representation of a sub-determined vertex, function D shown in Algorithm 3 receives the full composite vertex tuple (not sub-determined) and the sub-determined companion tuple. The if seen at line 7 of Algorithm 3 makes that the 0 entries found in a sub-determined companion tuple are discarded for the construction of the sub-determined numerical Given the numerical representation of any composite vertex, it is possible to reconstruct its tuple. In order to do this, we calculate the numerical value of the index of each element on the tuple, as where d is the composite numerical representation, i is the position of the composite vertex tuple to be calculated, τ is the MAG's companion tuple, mod is the modulus (division remainder) operation and txu is the floor operator, which for any x P R corresponds to the largest integer i P Z such that i ď x. Note that for calculating Npd, p, τq for a MAG with p aspects, it is necessary to calculate W pp`1, τq. Considering the definition of W from Equation (14), it follows that W pp`1, τq " ś p j"1 " |VpHq|, the number of composite vertices on the MAG. For instance, taking the composite vertex with numerical representation 14 of the MAG T , we have that We can therefore define the inverse of function D as D´1pd, τq " pNpd, 1, τq, Npd, 2, τq, . . . , Npd, |τ|, τqq, which reconstructs the composite vertex tuple in its numerical form. From this, we can see that, for instance, D´1p14, p3, 2, 3qq " p1, 0, 2q, which corresponds to the composite vertex p2, Bus,t 3 q. Algorithm 4 shows the implementation of D´1.
The relation between the composite vertex numerical representation and its tuple can also be seen as a consequence of the natural isomorphism between the MAG H and its composite vertices representation, gpHq. The role of this relation will become clear in Sections 3.4 to 3.6, where the matrix forms of the MAG are presented.

Elimination of trivial components
In the MAG T shown in Figure 3 the composite vertices of numerical representation p1q, p6q, p7q, p12q, p13q, and p18q are trivial components (i.e. unconnected composite vertices). They are created in consequence of the regularity needed on the MAG H to build the set VpHq. This type of padding is not necessary in a directed graph and its algebraic representation. Therefore, it is possible to remove the trivial components from the composite vertices representation and its associated matrices. However, it is important to bear in mind that the graph resulting from this transformation may no longer be isomorphic to the MAG and neither are the matrices associated with it. The only case in which the isomorphism is preserved is when there are no trivial components on the MAG and nothing is removed. Nevertheless, this kind of transformation can be helpful for application, by reducing the number of composite vertices present on the graph and so simplifying its construction and manipulation.
The same sort of padding is discussed in [16], where authors suggest that this padding may cause problems in the computing of some metrics, such as mean degree or clustering coefficients, unless one accounts for the padding scheme in an appropriate way. In this subsection, we show that the padding with the trivial components may be eliminated, if desired. Anyway, if needed, it suffices to be cautious in computing the metrics of interest on MAGs by considering the existence of the padding scheme, as suggested by [16]. In particular, the MAG algorithms we discuss in Section 4 remain unaffected by this padding issue.
For a given MAG H, we define its main components graph mpHq as the MAG's composite vertices representation with all its trivial components removed. Figure 4 shows the main components graph mpT q for the MAG T . It is worth noting that numerical representations are not defined for mpT q. This can be achieved algebraically for any MAG H with the help of a matrix RpHq constructed from the identity I P R nˆn , where n " |VpHq| is the number of composite vertices on the MAG. The matrix RpHq is obtained from this nˆn identity by removing the columns which match the numerical representations of the trivial components of the MAG. Therefore, assuming that the MAG H has r trivial components, the matrix RpHq P R nˆn´r has n rows and n´r columns. In particular, in the cases where the MAG H has no trivial components, we have that RpHq " I P R nˆn .
It is also worth noting that the matrix I m pHq " RpHq RpHq T P R nˆn is a matrix akin to the identity I P R nˆn , but the diagonal entries corresponding to the trivial components (removed in RpHq) have value 0. Therefore, multiplying a nˆn matrix by I m pHq to the left has the effect of turning all entries on the rows corresponding to the trivial components to 0s. Similarly, multiplying by I m pHq to the right has the effect of turning the entries of the columns corresponding to the trivial elements to 0s.
As an example, we show the matrix RpT q P R 18ˆ12 , which is obtained from the 18ˆ18 identity matrix by removing the columns 1, 6, 7, 12, 13, and 18 that correspond to the trivial components of the MAG T .

Adjacency matrix
As a direct consequence of the isomorphism between MAGs and traditional directed graphs, it is expected that a MAG can be represented in matrix form. In fact, such representations can be achieved directly by the composite vertices representation of MAGs, presented in Section 2.1. Since for any given MAG H its composite vertices representation is a traditional directed graph, it can be represented in matrix form.
One of such representations is the MAG's adjacency matrix. This matrix is obtained from the MAG's composite vertices representation, gpHq, and its companion tuple τpHq. In fact, the MAG's adjacency matrix is the adjacency matrix of the composite vertices representation, where the order of the rows and columns is given by the numerical representation of the composite vertices of gpHq.
Since the set VpHq of composite vertices of a given MAG H is obtained by the cartesian product of all aspects of the MAG (as shown in Expression (1)), it follows that the number of composite vertices on a given MAG H with p aspects is where τ i is the i-th element of the MAG's companion tuple, i.e. the number of elements on the MAG's i-th aspect.
The general form of any entry of the matrix JpHq is given by where pu, vq P EpgpHqq means that pu, vq is an edge on the composite vertices representation gpHq of the MAG H, so that u, v P VpHq are composite vertices of H. It follows from the definition of gpHq and its natural isomorphism to H, that pu, vq P EpgpHqq if and only if there is an edge e P EpHq such that u " π o peq and v " π d peq. It is important to note, however, that the notation j u,v is in fact a shorthand for j Dpu,τq,Dpv,τq , where Dpu, τq is the row number and Dpv, τq the column number of the matrix entry. This ties the construction of the adjacency matrix of a MAG with its companion tuple, since it is used in the determination of the numerical representation of a composite vertex (Dpu, τq). Therefore, the adjacency matrix of any given MAG is always presented with its companion tuple. The adjacency matrix of a given MAG H is constructed by Algorithm 5, where |VpHq| is the number of composite vertices in H, which can be calculated using Equation (19), Dpπ o peq, τq and Dpπ d peq, τq are the numerical representation of the origin and destination composite vertices of edge e P EpHq, respectively, as defined in Section 3.2. Considering that a sparse matrix with all entries 0 can be created in constant time, and that both functions CompTuple and D (see Algorithm 1 and Algorithm 3) have time complexity Oppq, we conclude that Algorithm 5 has time complexity Opp˚|EpHq|q, where p is the number of aspects of MAG H and |EpHq| the number of edges.
As an example, the adjacency matrix of the MAG T is shown in Expression (21). This adjacency matrix JpT q P R 18ˆ18 has 324 entries, of which just 22 are non-zero. JpT q " It is important to note that the order of the columns and rows of JpT q is given by the numerical representation of the composite vertices. Thus, for instance, the 1 at row 2, column 8 represents the edge between the composite vertices with numerical representations 2 and 8, witch in turn represents the edge p2, Bus,t 1 , 2, Bus,t 2 q of the MAG T . In this way, although JpT q is presented in matrix form, together with the companion tuple τpT q, it fully represents the MAG T , carrying the proper adjacency notion used to define transitive constructions, such as walks and paths on the MAG.
For an arbitrary MAG H, its main components graph mpHq is obtained by removing the MAG's trivial components, as stated in Section 3.3. The matrix JpmpHqq is then obtained with the use of the matrix RpHq, presented in Section 3.3. JpmpHqq is obtained as where JpmpHqq P R n´rˆn´r is the adjacency matrix containing only the main components of the MAG. It is also possible to obtain the adjacency matrix JpHq from JpmpHqq. This follows from the fact that on the adjacency matrix JpHq the rows and columns corresponding to trivial components are already zero. Therefore, where I m pHq " RpHq RpHq T . Then, we have that " I m pHq JpHq I m pHq " JpHq.
Expression (25) shows JpmpT qq, the adjacency matrix of mpT q. This matrix is obtained from the adjacency matrix JpT q by removing the rows and columns which represent the trivial components of the MAG T . In this case, the trivial components are the composite vertices with numerical representations 1, 6, 7, 12, 13, and 18. This matrix is calculated as JpmpT qq " RpT q T JpT q RpT q, so that In general, the adjacency matrices associated with a MAG are sparse, meaning that for an nˆn adjacency matrix the number of non-zero entries of the matrix is of the order Opnq. Since the non-zero entries on the MAG adjacency matrix corresponds to the edges present on the MAG, the adjacency matrix being sparse means that the number of edges m on the MAG is of the same order of the number of composite vertices n, i.e. m is of order Opnq. Therefore, these matrices can be stored efficiently using sparse matrices representations, such as Compressed Sparse Column (CSC) or Compressed Sparse Row (CSR) [34]. Assuming that the number of edges is larger than the number of composite vertices, these representations provide a space complexity of Opmq for storing the MAG's adjacency matrices. Further, they also provide efficient matrix operations, which will be explored in the algorithms presented in Section 4.

Incidence matrix
Given that every MAG is isomorphic to a directed graph, it follows that it can be represented by an incidence matrix (and its companion tuple). For any given MAG H, this matrix is constructed from the composite vertices gpHq and the companion tuple τpHq, adopting the vertex order induced by the numerical representation presented in Section 3.2. The MAG's incidence matrix CpHq P R mˆn , where m " |EpHq| is the number of edges in the MAG and n " |VpHq| is the number of composite vertices on the MAG, is defined then as where e P EpgpHqq is an edge in MAG H and u P VpHq is a composite vertex in MAG H. Here, the notation c e,u is a shorthand for c I d peq,Dpu,τq , where I d peq is an numerical index for each edge and Dpu, τq is the numerical representation of the composite vertex u. Note that the use of the composite vertex numerical representation ties the incidence matrix to the MAG's companion tuple.
Although the order of the composite vertices is defined by each composite vertex numerical representation, the order used to represent the MAG edges in the incidence matrix is not relevant. The incidence matrix of a directed graph has several well-known properties [35], among which, the property that the incidence matrix of a directed graph with k connected components has rank n´k, where n is the number of vertices of the graph. This property is useful for defining other matrices based on the incidence matrix. Given the incidence matrix CpHq of a MAG H, it is possible to obtain the incidence matrix of the main components graph CpmpHqq using the matrix RpHq P R nˆn´r defined in Section 3.4. The incidence matrix of mpHq is given by Further, given the incidence matrix of the MAG's main components graph and the matrix RpHq, it is possible to recover the MAG's incidence matrix, as " CpHq I m pHq " CpHq.
This is only possible because the columns of CpHq, which are forced to 0 by the multiplication by I m pHq, were already 0, as the composite vertices represented by them have no edges incident to them. The incidence matrix CpT q of the example MAG T is shown in Expression (29). The vertices (columns) order is determined by the vertices numerical representation, while the edge order remains unconstrained. The trivial components correspond to columns 1, 6, 7, 12, 13, and 18, which have all entries with value 0.
CpT q " The main components incidence matrix CpmpT qq is depicted in Expression (30). It is obtained from the matrix CpT q by removing the trivial components, as shown in Expression (28).
In general, the incidence matrices related to MAGs are sparse, and therefore can be efficiently stored using sparse matrices representations, such as CSC or CSR [34]. Assuming that the number of edges on the MAG is larger than the number of composite vertices, the use of these representation lead to a memory complexity of Opmq, where m " |EpHq| is the number of edges on the MAG H.

Combinational Laplacian
We construct the combinational Laplacian matrix of a given MAG H from its incidence matrix CpHq, as Since CpHq is an mˆn matrix, it follows from this construction that, as expected, the Laplacian LpHq is a positive semidefinite nˆn matrix. Further, since the rank of CpHq is n´k, where k is the number of connected components of H, it follows that the rank of LpHq is also n´k. Consequently, the dimension of the nullspace of LpHq is k, the number of connected components on the MAG H, a well-known property of the Laplacian matrix.
In the case of the Laplacian LpHq, each one of the trivial components of the MAG counts as a distinct connected component. Therefore, for a MAG with t trivial components, we have that k ě t, the equality happening in the case where the MAG only has trivial components, i.e. when the MAG has no edges.
The Laplacian LpT q of the example MAG T is given by

32)
Since the sum of all columns of LpT q is 0 and six of the columns are 0, it follows that the dimension of the nullspace of LpT q is 7, which is the expected value, as the MAG T has 6 trivial components and a single main component. The entries with value´2 reflect the fact that in this directed graph there are pairs of opposing directed edges, which can be interpreted as a bi-directional connection. As is shown in Section 3.6.2, this can also be seen as the weight associated with this connection.
The Laplacian can also be constructed for the main components of a given MAG H. In this case, the Laplacian is constructed as or LpmpHqq " CpmpHqq T CpmpHqq.
The main component Laplacian for the MAG T is Since the six trivial components were eliminated, the dimension of the nullspace of LpmpT qq is 1.

Weighted Laplacian
The weighted Laplacian matrix of a MAG H is obtained in a similar way to the combinational Laplacian. However, an additional diagonal weights matrix is used to associate a weight to each of the edges of H. We denote a weights matrix for a given MAG H as WpHq P R mˆm , where m " |EpHq| is the number of edges in H. Given a MAG H and a weights matrix WpHq, the weighted Laplacian is defined as L pHq " CpHq T WpHq CpHq.
In general, the entries on the main diagonal of a weights matrix WpHq are positive real values. In this case, WpHq is a symmetric positive-definite matrix and, therefore, L pHq is symmetric positive-semidefinite. Hence, the rank of L pHq is the same as the rank of CpHq, so that the nullspace of L pHq has the same dimension as the nullspace of LpHq. It can be seen that this matrix represents the same object as the supra-laplacian described in [36]. Nevertheless, here it is obtained directly from the MAG's representation by matrices and further, distinct weights can be directly assigned to each edge if the application needs it.
As an example of weighted Laplacian for the MAG T , consider a weight matrix WpT q, where the values of the entries on the main diagonal are given by DiagpWpT qq " r0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1s. (37) This weights matrix assigns weight 0.5 to all six edges that form the bidirectional connection between layers on the example MAG T . This effectively converts this edge pairs into a undirected edge. By doing this, the obtained weighted Laplacian matrix has the more familiar structure associated with the Laplacian of undirected graphs. For this weights matrix, we have If considering only the main components mpHq of a given MAG H, we have L pmpHqq " RpHq T CpHq T WpHq CpHq RpHq " RpHq T L pHq RpHq. (39) For the case of the example MAG T and the weights matrix described by Equation (37),

Normalized Laplacian
Another form of applying weights to the Laplacian matrix on a given MAG H leads to the equivalent of the normalized Laplacian matrix [37]. In this case, the weights are applied to the composite vertices instead of the edges, as in the weighted Laplacian. In order to obtain the normalized Laplacian, weights are applied to the non-zero columns of the incidence matrix CpHq, which correspond to the composite vertices of H that are not trivial components (i.e. unconnected composite vertices). The weights applied to the non-zero columns are such that the vector represented by each column becomes an unitary vector. This leads to a diagonal weights matrix NpHq P R nˆn , where n " |VpHq|, for which where c i is the i-th column of the incidence matrix CpHq and c i is the Euclidean norm of c i . The normalized Laplacian is then obtained by LpHq " pCpHq NpHqq T pCpHq NpHqq (42) " NpHq T CpHq T CpHq NpHq " NpHq LpHq NpHq.
Since c i " 1{ ? d i , where d i is the degree of the composite vertex corresponding to column c i , it follows that the formulation for LpHq shown in Equation (42) coincides with the one proposed in [37].
As with the other kinds of Laplacian matrices, the trivial components of LpHq can be eliminated using the matrix RpHq as LpmpHqq " RpHq T LpHq RpHq. (43)

MAG Algorithms
The MAG algorithms covered in this section are based on the MAG's adjacency matrix or on its adjacency list. Since in general we expect the adjacency matrix to be represented using sparse CSR ou CSC formats [34], it follows, due to the structure of the CSR and CSC formats, that the adjacency matrix and adjacency list can be seen as very closely related representations. The algorithms used in MAGs are directly derived from the basic well-known algorithms used with directed graphs [1,5,33,34]. In this sense, the purpose of this section is not to propose new algorithms, but to show how known algorithms may be adapted for application in MAGs. We remark that a Python implementation of all the algorithms presented in this section is available at the following URL: http://github.com/wehmuthklaus/ MAG_Algorithms.

Auxiliary matrices and vectors
When operating upon a matrix representation, a few auxiliary matrices and vectors are necessary to express the desired operations. We now define these vectors, which are used on the remainder of this section:

All 0s
We denote 0 the column vector with all entries equal to 0. Usually we assume that 0 has the right dimension (i.e. number of rows) for the indicated operation. When necessary to improve readability, we indicate the dimension by sub-script as in 0 n .

All 1s
We denote 1 the column vector with all entries equal to 1. Usually we assume that 1 has the right dimension (i.e. number of rows) for the indicated operation. When necessary to improve readability, we indicate the dimension by sub-script as in 1 n .
In all cases, we assume the vectors have the dimension necessary for the operation where they is applied.
Moreover, specially constructed matrices are used to build sub-determined algebraic algorithms for MAGs. These matrices provide reduction/aggregation operations needed for sub-determined algorithms. Although these matrices are specially constructed for the MAG and the sub-determination in question, they have distinct properties and can be constructed by a general algorithm. In fact, the construction of sub-determined algorithms relies on the use of functions to aggregate/reduce results according to the applied sub-determination. In some cases, this function can be as simple as just summing up values obtained in composite vertices, which are reduced to the same sub-determined vertex. However, depending on the algorithm being constructed, this aggregation may need a more elaborate function, which may not be expressed in terms of matrix multiplications.
Given a MAG H and a sub-determination ζ , the sub-determination matrix M ζ pHq P R mˆn is a rectangular matrix, where n " |VpHq| is the number of composite vertices of H and m " |V ζ pHq| is the number of composite vertices of the sub-determination ζ applied to the MAG H. Since a sub-determination is a (proper) subset of the aspects of a MAG, it follows that m|n, i.e. the number of composite vertices of a MAG is a multiple of the number of composite vertices in any of its sub-determinations. Further, M ζ pHq has the property of having exactly one non-zero entry in each column, and the position of this entry is determined by the numerical value of the sub-determined composite vertex.
Algorithm 7 shows the construction of the sub-determination matrix M ζ pHq for a given MAG H and sub-determination ζ . The function D takes a composite vertex to its numerical representation and the function S ζ takes a composite vertex to its sub-determined form, i.e. it drops the aspects not present in the subdetermination. To determine the time complexity of Algorithm 7, we consider that the count of composite vertices in line 3 is Op|VpHq|q, the same is the case for the count on line 4, the construction of companion tuple at line 2 is Oppq, the construction of an empty sparse matrix at line 5 is Op1q, and, finally, the for loop initiated at line 6 is also Op|VpHq|q. Since the number of aspects p ! |VpHq|, we conclude that the time complexity of Algorithm 7 is Op|VpHq|q.
For instance, consider the example MAG T and a sub-determination ζ t " 011 2 , which drops the third aspect of T . The aspect dropped is the aspect of time instants and, therefore, the two aspects present in ζ t are location and tran- As a further example, consider the MAG T and a sub-determination ζ T " 100 2 , which drops the location and transit layer aspects, leaving only the time instants aspects. Since there are 3 time instants in T , it follows that M ζ T pT q P R 3ˆ18 is M ζ T pT q " Note that in these cases the multiplication by the sub-determination matrices performs the sum of the distinct composite vertices that are reduced to a same subdetermined vertex. For instance, given the sub-determination ζ t " 011 2 , the matrix M ζ t pT q is used to aggregate values found in 3 composite vertices into a single sub-determined vertex. The aggregation function in this case is a simple sum. The same is done by the matrix M ζ T pT q for the sub-determination ζ T " 100 2 , where in this case each sub-determined result is the sum of values obtained for 6 composite vertices.

Universality of matrix algorithms
In this section, we show that every function that can be obtained from a MAG to a given co-domain set can also be obtained from a matrix representation of the MAG. Here the set H is the quotient set of finite MAGs under isomorphism defined in Section 2.1. Note that a permutation σ of a given adjacency matrix JpHq, together with the function D σ , represents the same MAG H as JpHq, so that permutations of adjacency matrices are isomorphic. Thus, we have the set J, which is a quotient set of pairs pJ σ , D σ q of adjacency matrices and association functions D, under adjacency matrix permutations. Therefore, an element of J is an equivalence class of adjacency matrices and D functions. Since we consider the pair pJpHq, τpHqq as the canonical adjacency matrix representation of the MAG H, we assign this pair as the class representative of the MAG H in J. Proof. We show that Algorithm 5 can be seen as a function that takes a given MAG H to its adjacency matrix and companion tuple, and that this function preserves the adjacency structure of the original MAG. Further, we show that, from the adjacency matrix JpHq and companion tuple τpHq, we can construct a MAĜ H that is isomorphic to MAG H.
• ùñ Given the sets H and J, Algorithm 5 can be seen as a function Considering the loop depicted at lines 5 to 9 in Algorithm 5, it can be seen that every edge e P EpHq is converted in a pair of composite vertices (u and v) and then represented as an edge on the adjacency matrix JpHq. Therefore, if the composite vertices u and v are adjacent in MAG H, then a entry 1 is present at the intersection of row Dpu, τpHqq and column Dpv, τpHqq of JpHq, indicating the corresponding adjacency in the matrix. Hence, the adjacency structure of the MAG H is preserved by the function ϒ.

• ðù
Given the adjacency matrix JpHq and companion tuple τpHq, we construct MAGĤ, which we then show to be isomorphic to the MAG H. We obtain ApĤq from τpHq by constructing a list ApĤq with p " |τpHq| elements, in which every element i of this list is a set such that |ApĤqris| " τris. Without loss of generality, we can assume that the elements of each aspect ApĤqris are natural numbers ranging from 1 to τris. We then construct the edge set EpĤq, by starting with an empty set and then inserting an edge for each entry with value 1 in JpHq. For constructing each of these edges, we take an entry of value 1, make r equal to its row number, and c equal to its column number. We then build the edge e " pD´1pr, τpHqq, D´1pc, τpHqq, which is a tuple of length 2p, where the first p entries correspond to the origin composite vertex and the last p entries correspond to the destination composite vertex of the edge. Note that function D´1 simply retrieves the original composite vertex entries from the row and column numbers of the adjacency matrix. Further, we construct the set VpĤq of composite vertices, which is the cartesian product of the sets in ApĤq, so that where p " |τpHq| is the number of aspects in the MAG H.
Since |VpHq| " |VpĤq|, we know that there is a bijective function from VpĤq to VpHq. Further, we also have the bijective function D, which takes a composite vertex into a natural number, assigning a unique and distinct natural number to each element of VpHq and VpĤq. Moreover, since τpĤq " τpHq and by construction of D, we have that the range of D for VpHq and VpĤq is the same, i.e. DpVpHq, τpHqq " DpVpĤq, τpĤqq. From this, we conclude that, for every composite vertex u P VpHq, there is one unique composite vertexû P VpĤq such that Dpu, τpHqq " Dpû, τpĤqq. We thus define the bijective function u Þ Ñ u, such that Dpû, τpĤqq " Dpu, τpHqq.
As the function f is bijective, for every edgeê PĤ, we have an edge e " p f pπ o pêqq, f pπ d pêqqq P EpHq, and also, for every edge e P EpHq, we have the corresponding edgeê " p f´1pπ o peqq, f´1pπ d peqqq P EpĤq. This fulfils the conditions for isomorphism betweenĤ and H.
Since H is a quotient set under the MAG isomorphism relation andĤ is isomorphic to H, it follows thatĤ and H correspond to the same element in H, making the function ϒ bijective. Also, since each entry with value 1 in the adjacency matrix JpHq corresponds to an edge in the MAG H, it follows that ϒ´1 also preserves the MAGs adjacency structure, establishing the isomorphism relation as desired.
Theorem 2. Every function that can be obtained from a MAG to a given codomain set can also be obtained from a matrix representation of the MAG.
Proof. Consider the diagram depicted in Figure 5. In this figure, H is the set of all MAGs (up to isomorphism), J is the set of pairs of adjacency matrices and companion tuples (up to permutation), F is an arbitrary function from H to X, where X is a codomain consistent with the definition of function F, and I is the identity function in X. Since the function F is arbitrary, it can represent any function or algorithm, such as searches or centrality computations, which take MAGs to a result expected from this function. As both functions ϒ (Equation (46) in Theorem 1) and I represent isomorphisms, it follows that the depicted diagram commutes, so that for every function F : H Ñ X there is a functionF : J Ñ X, which produces the same result.
As a consequence of Theorem 2, it follows that, from the adjacency matrix and companion tuple of a MAG, one can obtain any possible outcome that can be obtained from a MAG or from any other representation equivalent to it, such as high order tensors, as those presented in recent related works [16,38,39].

Degree
The definition of degree in a traditional graph stems from the number of edges incident to a given vertex. This concept can be generalized for MAGs, so that degrees can be defined for composite vertices, sub-determinations, or elements of a given aspect. Further, since MAG edges are considered to be directed, the degrees are also divided into out-degree and in-degree. In this section, we present algorithms for calculating these distinct degree definitions.

Degree of composite vertices
The degree of composite vertices of a given MAG H can be obtained directly from its composite vertices representation, gpHq. Since the composite vertices representation is a traditional directed graph isomorphic to the MAG H, it follows that the degree determination is done with the traditional algorithm for directed graphs with minor changes. For a given MAG H and its companion tuple τpHq, the degrees of the composite vertices can be determined by Algorithm 8, where Dpπ o peq, τpHqq and Dpπ d peq, τpHqq stand for the numerical representation of the origin and destination composite vertices of edge e P EpHq, as defined in Section 3.2.
Another way for calculating the degrees of the composite vertices is computing it algebraically from the adjacency matrix of the MAG, as given by and outdegree " JpHq 1. MAG, so that p ! |VpHq|. Finally, since the determination of the numerical representation of vertices has complexity Oppq, we have that the for loop initiated at line 6 has complexity Opp˚|EpHq|q, so that the time complexity of Algorithm 8 is Op|VpHq|`p˚|EpHq|q. If we consider that in a given case the order of the MAG does not vary, so that p is a constant, then the algorithm's time complexity is Op|VpHq|`|EpHq|q.

Degree of sub-determined vertices
We can determine the degree for sub-determined composite vertices in a similar way to the degree of composite vertices. Given a MAG H and a sub-determination ζ , the degree of the sub-determined composite vertices can be obtained by Algorithm 9, where |V ζ pHq| is the number of ζ sub-determined composite vertices on MAG H, S ζ is the function that takes a composite vertex to its subdetermined form, and D ζ is the function that takes the sub-determined composite vertex to its numerical representation. It can be seen that the time complexity of Algorithm 9 is the same as the time complexity of Algorithm 8.
input : H " pA, Eq, and ζ output: indegree, outdegree It is important to note that two distinct composite vertices may have the same sub-determined form. This happens when the two composite vertices differ only on aspects which are dropped by the sub-determination. In this case, the degree of each of these composite vertices is summed for obtain the sub-determined degree. From this, it can also be seen that some edges in the sub-determined form may become self-loops. The degrees calculated by Algorithm 9 include the self-loop edges. This algorithm can be modified to count the self-loops separately, as shown in Algorithm 10. This algorithm is similar to Algorithm 8 and has the same time complexity.
The sub-determined composite vertices degree can also be determined algebraically with and outdegree " M ζ pHq JpHq 1, input : H " pA, Eq, and ζ output: indegree, outdegree, sel f degree This follows from the fact that since M ζ pHq T is a nˆm rectangular matrix and has the property that each row has exactly one non-zero entry of value 1.
Furthermore, note that the matrix M ζ pHq JpHq M ζ pHq T is the adjacency matrix of the sub-determined MAG H ζ . Since the composite vertices representation of a sub-determined MAG is a multigraph, each non-zero entry shows the number of superposed edges in the sub-determination. Therefore, the main diagonal of M ζ pHq JpHq M ζ pHq T has the self-loop degree of each vertex. Hence, For example, consider the example MAG T (Figure 3) and the sub-determination ζ t " 011 2 defined in Section 4.1. We have that outdegree " M ζ t pT q JpT q 1 " and This means that, for instance, the sub-determined composite vertex p2, Subwayq has outdegree 7, indegree 7, and 2 self-loops. This sub-determination corresponds to the aggregation of all 3 time instants, which means that the edges in which only the time instant changes become self-loops. These edges are shown in red (dotted) in Figure 3. Note that τ ζ t " p2, 3q, so that Dpp2, Subwayq, p2, 3qq " 2, making it correspond to the second element of the degree column vector.

Single aspect degree
The single aspect degree is a particular case of sub-determined degree in which the sub-determination applied is such that only a single aspect remains. Therefore, the determination of single aspect degrees is done in the same way presented in Section 4.3.2.
We, however, present an additional example illustrating the time instant degree, which is obtained by the sub-determination ζ T " 100 2 defined in Section 4.1. This sub-determination has only the third aspect of the MAG T (Figure 3), which corresponds to the three time instants present on MAG T . In this case, we have that outdegree " M ζ T pT q JpT q 1 " and sel f degree " DiagpM ζ T pT q JpT q M ζ T pT q T q " Therefore, we have that τ ζ T " p3q, so that Dppt 1 q, p3qq " 1, Dppt 2 q, p3qq " 2, and Dppt 3 q, p3qq " 3. Considering the composite vertices representation of MAG T , depicted in Figure 3, it can be seen that each time instant has 2 self-loop edges (in blue-dashed), which is consistent with Equation (63). Further, there are 8 edges from t 1 to t 2 (in red-dotted and black) and 8 edges from t 2 to t 3 . This is consistent with the adjacency matrix shown in Equation (62). Further, the indegrees and outdegrees of each time instant are consistent with Equations (60) and (61).

Breadth-First Search (BFS)
The Breadth-First Search (BFS) is an important graph algorithm that can be seen as a primitive for building many other algorithms [5]. The goal of this section is to illustrate how the BFS algorithm can be adapted for being used in MAGs, both in its full composite vertices representation and in its sub-determined forms. In the not sub-determined form, the adaptation is very simple, since the composite vertices representation of a MAG is a directed graph. In this case, all that is needed is to convert the composite vertices representation from its tuple to numerical form, and then apply the traditional BFS algorithm. The adaptation to the subdetermined forms also does not require major changes on the algorithm. As with many graph algorithms, BFS can be expressed in combinational or in algebraic forms, which are presented in the following related subsections.

BFS for composite vertices
The non sub-determined BFS in its combinational form is constructed directly upon the MAG's adjacency matrix, JpHq.
Considering Algorithm 11 and the standard form of the BFS algorithm encountered in [5], it can be seen that the difference is that the starting composite vertex s has to be transformed from its tuple representation to its numerical representation, as shown in lines 8,9 and 10 of Algorithm 11. Therefore, from the analysis provided in [5], we can conclude that the time complexity of Algorithm 11 is Op|VpHq|`|EpHq|q.
BFS is also closely related to matrix multiplication. This stems from the wellknown property of the powers of the adjacency matrix, in which the pi, jq entry of the n-th power of the adjacency matrix shows the number of existing walks of length n from vertex i to vertex j [34]. From this, we could think that for a given MAG H, the series would produce a matrix B, such that the entry B i, j indicates the number of walks of any length from vertex i to vertex j. This is indeed the case when H happens to be an acyclic MAG, making JpHq a nilpotent matrix. The existence of cycles in H makes that, for some vertices, there will exist walks of arbitrary length connecting them (namely, the cycles), making the series of Equation (64) divergent. However, since the objective is not to know the number of walks between each pair of vertices, but simply to know which vertices are reachable from each other (i.e. there is at least a path between them), this technical problem can be solved by multiplying the adjacency matrix JpHq by a scalar ρ H , such that input : JpHq, τpHq, and s P VpHq output: vertices, distance, pred where ρpJpHqq is the spectral radius of the matrix JpHq. This leads to the matrix so that the spectral radius of the matrix J ρ pHq ă 1. This results that Equation (64) constructed with the matrix J ρ pHq converges. Since the convergence of the series is assured, Equation (64) can be re-expressed as The matrix B defined in Equation (67) has the property that, for any given composite vertex v P VpHq, the row Dpvq of B has non-zero entries in every column that corresponds to a composite vertex u P VpHq, such that u is reachable from v. Hence, for a given composite vertex v, the row Dpvq corresponds to the result of a BFS started at that composite vertex. Although the matrix B carries the BFS of all composite vertices of the MAG H, it is important to note that this matrix may not be sparse, which for large MAGs can lead to difficulties in memory allocation. In order to avoid such difficulties, it is also possible to express a BFS for a single composite vertex v as where r v is the row vector with n entries for which all entries except Dpv, τq are 0 and the entry Dpv, τq is 1.
Considering the example MAG T , shown in Figure 3, the result of the BFS using Algorithm 11 for the composite vertex p2, Bus,t 1 q, whose numerical representation is Dpp2, Bus,t 1 q, p3, 2, 3qq " 2, is vertices " r2, 5, 8, 9, 10, 11, 14, 15, 16, 17s (69) distances " r8, 0, where the list vertices shows the composite vertices accessible from p2, Bus,t 1 q, which in this example represent all locations, transit modals, and time instants reachable from this initial point. The list distances carries the distances in hops from the initial composite vertex p2, Bus,t 1 q to all possible destinations (with 8 meaning that a destination is not reachable). The list pred shows the predecessors of each composite vertex, making possible to construct a BFS tree.

Sub-determined BFS
It is possible to obtain a sub-determined form of the BFS algorithm for MAGs. It is important, however, to realize that this sub-determined BFS algorithm is not equivalent to applying the BFS algorithms presented in Section 4.4.1 to a subdetermined MAG. A sub-determination is a generalization of the idea of aggregating multilayer and time-varying graphs, as shown in Section 2.2. As with the aggregation process, the sub-determination of a MAG can cause the presence of (a) MAG R (b) Sub-determined form Figure 6: MAG R and its sub-determined form.
paths and walks on the sub-determined MAG that do not actually exist on the original MAG. To illustrate this, we present Figures 6a and 6b, which show a small two aspects MAG and its sub-determined form, obtained by the sub-determination ζ R " 01 2 . First, note that, in the MAG R shown in Figure 6a, there is no path originating from the composite vertices p1, 1q or p1, 2q to the composite vertices p3, 1q or p3, 2q. Nevertheless, in Figure 6b, there is a path connecting the sub-determined vertex p1q to the sub-determined vertex p3q, even though such connection is not possible on the original MAG shown in Figure 6a. Therefore, in order to obtain the proper result, the sub-determined BFS should not be evaluated directly using the sub-determined MAG. Such a case can be seen algebraically by noting that given a MAG H and a sub-determination ζ , in general To see that the Inequality (70) holds, note that an arbitrary power of the matrix M ζ pHq J ρ pHq M ζ pHq T is given bỳ where`M ζ pHq J ρ pHq M ζ pHq T˘i s multiplied n times. Note, however, that since M ζ pHq P R mˆn is a retangular matrix and m ă n, so that the rank of the matrix M ζ pHq T M ζ pHq is less or equal to m, while the rank of the identity I n is n ą m. Since Inequality (72) holds, so does the Inequality (70).
Here, the left hand side of the Inequality (70) corresponds to the sub-determination of the BFS calculated for the MAG H, while the right hand side corresponds to the BFS calculated for the sub-determined MAG H ζ .
In the case of the MAG R, shown in Figure 6a, we have that the sub-determination is given by ζ R " 01 2 and the adjacency and sub-determination matrices are M ζ R pRq " and Therefore, we have that and`I 3´Jζ R pRq˘´1 " Remembering that the entries of the matrices in Equations (76), (77), and (78) are to be considered only as zero or non-zero, it can be seen that the matrix at Equation (76) has a 0 at entry p1, 3q, while the matrices at Equations (77) and (78) have a non-zero entry at this same position. This illustrates the situation in which a BFS is done on the sub-determined (aggregated) MAG, as in Equations (77) and (78), i.e. paths that are not present on the original MAG can appear on the sub-determined form, potentially altering the results obtained by algorithms applied to it. For instance, considering the MAG T , depicted in Figure 3, for a sub-determination ζ t " 011 2 , which drops the time aspect, and considering ρ H " 0.5 so that J ρ pT q " 0.5 JpT q, we have that After applying Algorithm 12 to the MAG R with initial vertex s " 1 and subdetemination ζ R " 01 2 , the obtained result is vertices " r1, 2s (80) distances " r0, 1, 8s pred " rNil, 1, Nils, which is consistent with the result obtained by Equation (76). Further, applying Algorithm 12 to MAG T , shown in Figure 3, with starting composite vertex s " p2, Busq and applying the sub-determination ζ t " 011 2 , which drops the time aspect, the obtained result is vertices " r2, 5, 3, 4s (81) distances " r8, 0, 1, 2, 1, 8s pred " rNil, Nil, 2, 5, 2, Nils.

Single aspect BFS
The single aspect BFS is a special case of the sub-determined BFS. As such, it is evaluated using the same algorithms presented in Section 4.4.2 for the subdetermined case.
Considering the example MAG T (Figure 3), a sub-determination ζ L " 001 2 , which drops the time and transit mode aspects (thus leaving only the locations aspect), and making ρ H " 0.5 so that J ρ pT q " 0.5 JpT q, we have that M ζ L pT q˜8 indicating that disregarding the aspects of time instants and transit modes, all locations can be reached from any location. Applying Algorithm 12 to the MAG T , with starting composite vertex s " p1q and employing the sub-determination ζ L " 001 2 , which drops the aspects of the transit mode and time instants, the obtained result is vertices " r1, 2, 3s (83) distances " r0, 1, 2s pred " rNil, 1, 2s, which is consistent with the result obtained by Equation (82).

Depth-First Search (DFS)
In this section, we show the adaptation of the Depth-First Search (DFS) algorithm for use with MAGs. The DFS algorithm exposes many properties of the MAG structure and can be used as a primitive for the construction of many other algorithms [5]. We present DFS algorithms for both the full composite vertices representation of the MAG as well as for the sub-determined form. We remark that in the sub-determined algorithm the full information of the MAG is used, in the sense of preventing the use of paths that may exist in the sub-determined form of the MAG, while not actually existing in the original MAG.

DFS for composite vertices
The composite vertices implementation is constructed using the MAG's adjacency matrix JpHq and companion tuple τpHq. The implementation shown is very similar to the traditional implementation presented in [5], which is expected since the composite vertices representation of the MAG is indeed a directed graph, so that the original algorithm applies. The proposed implementation can be seen in Algorithm 13 is similar to the original implementation. Therefore, considering the analysis provided in [5], we conclude that the time complexity of Algorithm 13 is Op|VpHq|`|EpHq|q.

Sub-determined DFS
The sub-determined DFS algorithm is presented in Algorithm 14 and is similar to the non sub-determined one. The main differences are at the Procedure Visit-DFS-Sub and the call to a sub-determined BFS at line 15 of the DFS-Sub function. This version for a sub-determined BFS is considered in order to determine reachability Sub. An example of this is provided in Equation (86). The difference in Procedure Visit-DFS-Sub is that in addition to the root vertex for the DFS tree it also receives the reachability vector produced by the BFS. This reachability vector has one entry for each sub-determined vertex. This entry has value 1 when corresponding to a reachable vertex, while entries corresponding to unreachable vertices carry value 0.
In order to determine the time complexity of Algorithm 14, we consider that the sub-determined BFS executed at line 15 of Function DFS-Sub is done once for the root vertex of each sub-determined DFS tree. Since it is executed only once for each DFS tree, we conclude that the total time expended in the subdetermined BFS algorithm is Op|VpHq|`|EpHq|q. Since the reachability check included in Function Visit-DFS-Sub is done by verifying the content of one entry of the reachability vector, it is done in Op1q and therefore does not affect the overall time complexity of the Visit-DFS-Sub Function. Therefore, since the DFS is run upon the sub-determined MAG, it follows that the time complexity of doing the DFS part of the Algorithm is Op|V ζ pHq|`|E ζ pHq|q. Since |V ζ pHq| ă |VpHq| and |E ζ pHq| ă |EpHq|, we conclude that the time complexity is dominated by the BFS used for the reachability determination, making the overall time complexity of Algorithm 14 to be Op|VpHq|`|EpHq|q.
It can be seen that even though in the MAG R sub-determined by ζ R " 01 2 (see Figure 6b) there is a path from vertex 1 to 3, vertex 3 is not in the same DFS connecting the composite vertex 1 to the composite vertex 3.

Single aspect DFS
The single aspect DFS is a special case of the sub-determined DFS. As such, it is evaluated using the same algorithms presented for the sub-determined case in Section 4.5.2.
Applying Algorithm 14 to MAG T (Figure 3), and employing the sub-determination ζ L " 001 2 , which drops the aspects of transit modes and time instants, the obtained result is d " r0, 1, 2s (87) f " r5, 4, 3s pred " rNil, 1, 2s, where the list d carries the discovery time of each sub-determined composite vertex, the list f its finish time, and pred its predecessor.

Final remarks
In this paper, we have presented the algebraic representation and basic algorithms of MultiAspect Graphs (MAGs). The key contribution has been to show that models based on the MAG abstraction (formally defined in [19]) can be represented by a matrix and a companion tuple. Furthermore, we have also shown that any possible MAG function (algorithm) can be obtained from this matrix-based representation. This is an important theoretical result because it paves the way for adapting well-known graph algorithms for application in MAGs. In this sense, we have presented the adaptation for the MAG context of basic graph algorithms, such as computing degree, BFS, and DFS. In particular, we have also presented the sub-determined versions of the same basic algorithms, showing that such versions disregard spurious paths that usually result from the sub-determination process, thus avoiding the pollution of the results with the consideration of such paths.
As future work, we intend to build upon the results here obtained for the algebraic representation and basic algorithms of MAGs to analyze MAG properties, such as the centrality of edges, composite vertices, and aspects. We also intend to consider the dynamics encountered in these properties in the cases where one of the MAG aspects represents time. Finally, we are also targeting the application of the MAG concept for the better understanding, modeling, and analysis of different complex networked systems found in real-world applications.