Open Access
This article is

- freely available
- re-usable

*Algorithms*
**2017**,
*10*(1),
1;
https://doi.org/10.3390/a10010001

Article

MultiAspect Graphs: Algebraic Representation and Algorithms

^{1}

National Laboratory for Scientific Computing (LNCC), Av. Getúlio Vargas 333, 25651-075 Petrópolis, Brazil

^{2}

Institut national de recherche en informatique et en automatique (INRIA), Centre national de la recherche scientifique (CNRS), Université de Lyon, École normale supérieure de Lyon, UCB Lyon 1, LIP UMR 5668, F-69342, 46, Alleé d’Italie, 69364 Lyon, France

^{*}

Authors to whom correspondence should be addressed.

Academic Editor:
Natarajan Meghanathan

Received: 25 September 2016 / Accepted: 19 December 2016 / Published: 25 December 2016

## Abstract

**:**

We present the algebraic representation and basic algorithms for MultiAspect Graphs (MAGs). A MAG is a structure capable of representing multilayer and time-varying networks, as well as higher-order 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 graphs. We also make available Python implementations of all the algorithms presented in this paper.

Keywords:

complex network; multilayer network; time-varying network; high order network; graph algorithms## 1. 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, allow the development of more sophisticated algorithms for the analysis of specific properties of complex networks, such as algorithms for computing some shortest-path-based network centralities or algorithms for analyzing network robustness [6,7,8,9]. Additionally, these basic graph algorithms also allow the analysis of dynamic processes in complex networks, such as network generative processes or information diffusion [10,11,12,13]. Moreover, several generalizations of the basic graph concept have been proposed for modelling complex systems that can be represented by layers of distinct networks [14,15] and also complex systems in which the network itself evolves with time [16,17].

In our previous work [18], 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 [18], 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 [19,20]. Examples of such networks include face-to-face in-person contact networks [21], mobile phone networks [22,23], gene regulatory networks [24], urban transportation networks [25], brain networks [26,27], social networks [28], among many others. In particular, we have previously applied the MAG abstraction from [18] to different purposes, such as modeling time-varying graphs [29], studying time centrality in dynamic complex networks [30], and investigating social events based on mobile phone networks [31]. 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 [18] 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. 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,32]. 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. Given that a MAG is isomorphic to a directed graph as shown in [18], the algebraic representation and algorithms for MAGs discussed in this paper closely resemble those for directed graphs. This isomorphism between MAGs and directed graphs constitutes an important theoretical result from [18] that 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, as we discuss in this paper. Therefore, the particular contribution of this paper is to discuss and to show how to build algebraic representations and algorithms for the MAG abstraction (topics that are not covered in the original MAG paper), bringing theoretical results related to these contributions. 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 [18] 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.

## 2. 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 [18].

#### 2.1. MAG Definition

We define a MAG as $H=(A,E)$, where E is a set of edges and A is a finite list of aspects. Each aspect $\phi \in A$ is a finite set, and the number of aspects $p=\left|A\right|$ is called the order of H. Each edge $e\in E$ is a tuple with $2\times p$ elements. All edges are constructed so that they are of the form $({a}_{1},\cdots ,{a}_{p},{b}_{1},\cdots ,{b}_{p})$, 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 sequence as the aspects are defined on the list A.

As a matter of notation, we say that $A\left(H\right)$ is the aspect list of H and $E\left(H\right)$ is the edge set of H. Further, $A\left(H\right)\left[n\right]$ is the n-th aspect in $A\left(H\right)$, $\left|A\left(H\right)\left[n\right]\right|={\tau}_{n}$ is the number of elements in $A\left(H\right)\left[n\right]$, and $p=\left|A\right(H\left)\right|$ 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
which is the set of all possible edges in the MAG H, so that $E\left(H\right)\subseteq \mathbb{E}\left(H\right)$.

$$\mathbb{V}\left(H\right)=\underset{n=1}{\overset{p}{\u2715}}A\left(H\right)\left[n\right],$$

$$\mathbb{E}\left(H\right)=\underset{n=1}{\overset{2p}{\u2715}}A\left(H\right)[(n-1)\left(mod\phantom{\rule{4pt}{0ex}}p\right)+1],$$

We call $\mathbf{u}\in \mathbb{V}\left(H\right)$ a composite vertex of MAG H. As a matter of notation, a composite vertex is always represented as a bold lowercase letter, as in $\mathbf{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\in E\left(H\right)$ has the form $({a}_{1},\cdots ,{a}_{p},{b}_{1},\cdots ,{b}_{p})$, so that $({a}_{1},\cdots ,{a}_{p})\in \mathbb{V}\left(H\right)$ and $({b}_{1},\cdots ,{b}_{p})\in \mathbb{V}\left(H\right)$ are composite vertices of this given MAG H. From this, we can define two functions
and

$$\begin{array}{c}\phantom{\rule{3.33333pt}{0ex}}\phantom{\rule{3.33333pt}{0ex}}\phantom{\rule{3.33333pt}{0ex}}\phantom{\rule{3.33333pt}{0ex}}\phantom{\rule{3.33333pt}{0ex}}\phantom{\rule{3.33333pt}{0ex}}\phantom{\rule{3.33333pt}{0ex}}\phantom{\rule{3.33333pt}{0ex}}\phantom{\rule{3.33333pt}{0ex}}\phantom{\rule{3.33333pt}{0ex}}\phantom{\rule{3.33333pt}{0ex}}\phantom{\rule{3.33333pt}{0ex}}\phantom{\rule{3.33333pt}{0ex}}\phantom{\rule{3.33333pt}{0ex}}\phantom{\rule{3.33333pt}{0ex}}\phantom{\rule{3.33333pt}{0ex}}\phantom{\rule{3.33333pt}{0ex}}\phantom{\rule{3.33333pt}{0ex}}\phantom{\rule{3.33333pt}{0ex}}\phantom{\rule{3.33333pt}{0ex}}\phantom{\rule{3.33333pt}{0ex}}\phantom{\rule{3.33333pt}{0ex}}\phantom{\rule{3.33333pt}{0ex}}\phantom{\rule{3.33333pt}{0ex}}\phantom{\rule{3.33333pt}{0ex}}\phantom{\rule{3.33333pt}{0ex}}\phantom{\rule{3.33333pt}{0ex}}\phantom{\rule{3.33333pt}{0ex}}\phantom{\rule{3.33333pt}{0ex}}{\pi}_{o}:\mathbb{E}\left(H\right)\to \mathbb{V}\left(H\right)\phantom{\rule{3.0pt}{0ex}}\hfill \\ e=({a}_{1},{a}_{2},\cdots ,{a}_{p},{b}_{1},{b}_{2},\cdots ,{b}_{p})\mapsto ({a}_{1},{a}_{2},\cdots ,{a}_{p})=\mathbf{u},\hfill \end{array}$$

$$\begin{array}{c}\phantom{\rule{3.33333pt}{0ex}}\phantom{\rule{3.33333pt}{0ex}}\phantom{\rule{3.33333pt}{0ex}}\phantom{\rule{3.33333pt}{0ex}}\phantom{\rule{3.33333pt}{0ex}}\phantom{\rule{3.33333pt}{0ex}}\phantom{\rule{3.33333pt}{0ex}}\phantom{\rule{3.33333pt}{0ex}}\phantom{\rule{3.33333pt}{0ex}}\phantom{\rule{3.33333pt}{0ex}}\phantom{\rule{3.33333pt}{0ex}}\phantom{\rule{3.33333pt}{0ex}}\phantom{\rule{3.33333pt}{0ex}}\phantom{\rule{3.33333pt}{0ex}}\phantom{\rule{3.33333pt}{0ex}}\phantom{\rule{3.33333pt}{0ex}}\phantom{\rule{3.33333pt}{0ex}}\phantom{\rule{3.33333pt}{0ex}}\phantom{\rule{3.33333pt}{0ex}}\phantom{\rule{3.33333pt}{0ex}}\phantom{\rule{3.33333pt}{0ex}}\phantom{\rule{3.33333pt}{0ex}}\phantom{\rule{3.33333pt}{0ex}}\phantom{\rule{3.33333pt}{0ex}}\phantom{\rule{3.33333pt}{0ex}}\phantom{\rule{3.33333pt}{0ex}}\phantom{\rule{3.33333pt}{0ex}}\phantom{\rule{3.33333pt}{0ex}}\phantom{\rule{3.33333pt}{0ex}}{\pi}_{d}:\mathbb{E}\left(H\right)\to \mathbb{V}\left(H\right)\phantom{\rule{3.0pt}{0ex}}\hfill \\ e=({a}_{1},{a}_{2},\cdots ,{a}_{p},{b}_{1},{b}_{2},\cdots ,{b}_{p})\mapsto ({b}_{1},{b}_{2},\cdots ,{b}_{p})=\mathbf{v}.\hfill \end{array}$$

We call ${\pi}_{o}\left(e\right)$ the origin composite vertex of e and ${\pi}_{d}\left(e\right)$ the destination composite vertex of e. Moreover, we can define the function
from which we can construct a directed graph ${G}_{H}=(V\left(H\right),\psi \left(E\left(H\right)\right)$. In [18], we demonstrate that the directed graph ${G}_{H}=(V\left(H\right),\psi \left(E\left(H\right)\right)$ is isomorphic to the MAG H from which it was originated. At this point, we can therefore define the function
which maps every MAG H to its isomorphic directed graph $g\left(H\right)$. Further, we define the set of functions
which extracts the n-th element of a composite vertex tuple.

$$\begin{array}{c}\psi :\mathbb{E}\left(H\right)\to \mathbb{V}\left(H\right)\u2715\mathbb{V}\left(H\right)\phantom{\rule{3.0pt}{0ex}}\hfill \\ \phantom{\rule{3.33333pt}{0ex}}\phantom{\rule{3.33333pt}{0ex}}\phantom{\rule{3.33333pt}{0ex}}\phantom{\rule{3.33333pt}{0ex}}\phantom{\rule{3.33333pt}{0ex}}\phantom{\rule{3.33333pt}{0ex}}\phantom{\rule{3.33333pt}{0ex}}\phantom{\rule{3.33333pt}{0ex}}\phantom{\rule{3.33333pt}{0ex}}\phantom{\rule{3.33333pt}{0ex}}e\mapsto ({\pi}_{o}\left(e\right),{\pi}_{d}\left(e\right))=(({a}_{1},\cdots ,{a}_{p}),({b}_{1},\cdots ,{b}_{p}))=(\mathbf{u},\mathbf{v}),\hfill \end{array}$$

$$\begin{array}{c}g:\left(A\right(H),E(H\left)\right)\to \left(\mathbb{V}\right(H),\mathbb{V}(H)\u2715\mathbb{V}(H\left)\right)\phantom{\rule{3.0pt}{0ex}}\hfill \\ \phantom{\rule{3.33333pt}{0ex}}\phantom{\rule{3.33333pt}{0ex}}\phantom{\rule{3.33333pt}{0ex}}\phantom{\rule{3.33333pt}{0ex}}\phantom{\rule{3.33333pt}{0ex}}\phantom{\rule{3.33333pt}{0ex}}\phantom{\rule{3.33333pt}{0ex}}\phantom{\rule{3.33333pt}{0ex}}\phantom{\rule{3.33333pt}{0ex}}\phantom{\rule{3.33333pt}{0ex}}\phantom{\rule{3.33333pt}{0ex}}\phantom{\rule{3.33333pt}{0ex}}\phantom{\rule{3.33333pt}{0ex}}\phantom{\rule{3.33333pt}{0ex}}\phantom{\rule{3.33333pt}{0ex}}\phantom{\rule{3.33333pt}{0ex}}\phantom{\rule{3.33333pt}{0ex}}\phantom{\rule{3.33333pt}{0ex}}\phantom{\rule{3.33333pt}{0ex}}\phantom{\rule{3.33333pt}{0ex}}H\mapsto \left(\mathbb{V}\right(H),\psi (E\left(H\right)),\hfill \end{array}$$

$$\begin{array}{c}\phantom{\rule{3.33333pt}{0ex}}\phantom{\rule{3.33333pt}{0ex}}\phantom{\rule{3.33333pt}{0ex}}\phantom{\rule{3.33333pt}{0ex}}\phantom{\rule{3.33333pt}{0ex}}\phantom{\rule{3.33333pt}{0ex}}{\pi}_{i}:\mathbb{V}\left(H\right)\to A\left(H\right)\left[i\right]\phantom{\rule{3.0pt}{0ex}}\hfill \\ ({a}_{1},{a}_{2},\cdots ,{a}_{p})\mapsto {a}_{i},\hfill \end{array}$$

#### 2.2. 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 two aspects, the sub-determination 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}\left(H\right)\subset A\left(H\right)$ 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$.

#### 2.2.1. Sub-Determined Composite Vertices

Let ζ, with $1\le \zeta \le {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 $\zeta ={\mathtt{001}}_{2}$ corresponds to the sub-determination where only the first aspect is present, $\zeta ={\mathtt{010}}_{2}$ corresponds to the sub-determination where only the second aspect is present, $\zeta ={\mathtt{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}_{\zeta}\left(H\right)$ of aspects, such that ${p}_{\zeta}=\left|{A}_{\zeta}\left(H\right)\right|$ is the order of the sub-determination ζ. We now define the set
where ${\mathbb{V}}_{\zeta}\left(H\right)$ is the cartesian product of all the aspects in the sublist ${A}_{\zeta}\left(H\right)$ of aspects, according to the index ζ. We call ${\mathbf{u}}_{\zeta}\in {\mathbb{V}}_{\zeta}\left(H\right)$ a sub-determined vertex, according to the sub-determination ζ.

$${\mathbb{V}}_{\zeta}\left(H\right)=\underset{n=1}{\overset{{p}_{\zeta}}{\u2715}}{A}_{\zeta}\left(H\right)\left[n\right],$$

We can now define the function
where $m={p}_{\zeta}$. ${S}_{\zeta}$ maps a composite vertex $\mathbf{u}\in \mathbb{V}\left(H\right)$ to the corresponding sub-determined composite vertex ${\mathbf{u}}_{\zeta}\in {\mathbb{V}}_{\zeta}\left(H\right)$, according to the sub-determination ζ. As $({a}_{{\zeta}_{1}},{a}_{{\zeta}_{2}},$$\cdots ,{a}_{{\zeta}_{m}})$$\in {\mathbb{V}}_{\zeta}\left(H\right)$, it follows that ${a}_{{\zeta}_{1}}\in {A}_{\zeta}\left(H\right)\left[1\right],\cdots ,{a}_{{\zeta}_{m}}\in {A}_{\zeta}\left(H\right)\left[m\right]$. From the definition, it can be seen that the function ${S}_{\zeta}$ is not injective. Hence, the function ${S}_{\zeta}$ for a given sub-determination can be used to define a equivalence relation ${\equiv}_{\zeta}$ in $\mathbb{V}\left(H\right)$, where for any given composite vertices $\mathbf{u},\mathbf{v}\in \mathbb{V}\left(H\right)$, we have that $\mathbf{u}{\equiv}_{\zeta}\mathbf{v}$ if and only if ${S}_{\zeta}\left(\mathbf{u}\right)={S}_{\zeta}\left(\mathbf{v}\right)$.

$$\begin{array}{c}\phantom{\rule{3.33333pt}{0ex}}\phantom{\rule{3.33333pt}{0ex}}\phantom{\rule{3.33333pt}{0ex}}\phantom{\rule{3.33333pt}{0ex}}\phantom{\rule{3.33333pt}{0ex}}\phantom{\rule{3.33333pt}{0ex}}{S}_{\zeta}:\mathbb{V}\left(H\right)\to {\mathbb{V}}_{\zeta}\left(H\right)\phantom{\rule{3.0pt}{0ex}}\hfill \\ ({a}_{1},{a}_{2},\cdots ,{a}_{p})\mapsto ({a}_{{\zeta}_{1}},{a}_{{\zeta}_{2}},\cdots ,{a}_{{\zeta}_{m}}),\hfill \end{array}$$

#### 2.2.2. Sub-Determined Edges

From the sub-determination ζ of order ${p}_{\zeta}$, we can also construct the set
where ${p}_{\zeta}=\left|{A}_{\zeta}\left(H\right)\right|$ is the order of the sub-determination ζ, and ${\mathbb{E}}_{\zeta}\left(H\right)$ is the set of all possible sub-determined edges according to ζ. We then define the function
where $m={p}_{\zeta}$ and ${a}_{{\zeta}_{1}},{b}_{{\zeta}_{1}}\in {A}_{\zeta}\left(H\right)\left[1\right],{a}_{{\zeta}_{2}},{2}_{{\zeta}_{2}}\in {A}_{\zeta}\left(H\right)\left[2\right],\cdots ,{a}_{{\zeta}_{m}},{b}_{{\zeta}_{m}}\in {A}_{\zeta}\left(H\right)\left[m\right]$. 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}_{\zeta}$ is not injective. Consider two distinct edges ${e}_{1},{e}_{2}\in E\left(H\right)$, such that ${e}_{1}$ and ${e}_{2}$ differ only in aspects which are not in ${A}_{\zeta}\left(H\right)$. Since ${E}_{\zeta}(\xb7)$ only contains values for aspects present in ${A}_{\zeta}\left(H\right)$, it follows that ${E}_{\zeta}\left({e}_{1}\right)={E}_{\zeta}\left({e}_{2}\right)$, and therefore ${E}_{\zeta}$ is not injective. Further, consider an edge $e\in E\left(H\right)$ and its sub-determined edge ${e}_{\zeta}={E}_{\zeta}\left(e\right)$, such that ${\pi}_{o}\left({e}_{\zeta}\right)={\pi}_{d}\left({e}_{\zeta}\right)$, i.e., ${e}_{\zeta}$ is a self-loop. Since self-loops are not allowed to be present on a MAG, it follows that ${e}_{\zeta}\notin {E}_{\zeta}\left(E\left(H\right)\right)$. As consequence, we have that $|{E}_{\zeta}\left(E\left(H\right)\right)|\le |E\left(H\right)|$.

$${\mathbb{E}}_{\zeta}\left(H\right)=\underset{n=1}{\overset{2\times {p}_{\zeta}}{\u2715}}{A}_{\zeta}\left(H\right)[(n-1)\left(mod\phantom{\rule{4pt}{0ex}}{p}_{\zeta}\right)+1],$$

$$\begin{array}{c}\phantom{\rule{3.33333pt}{0ex}}\phantom{\rule{3.33333pt}{0ex}}\phantom{\rule{3.33333pt}{0ex}}\phantom{\rule{3.33333pt}{0ex}}\phantom{\rule{3.33333pt}{0ex}}\phantom{\rule{3.33333pt}{0ex}}\phantom{\rule{3.33333pt}{0ex}}\phantom{\rule{3.33333pt}{0ex}}\phantom{\rule{3.33333pt}{0ex}}\phantom{\rule{3.33333pt}{0ex}}\phantom{\rule{3.33333pt}{0ex}}\phantom{\rule{3.33333pt}{0ex}}\phantom{\rule{3.33333pt}{0ex}}\phantom{\rule{3.33333pt}{0ex}}\phantom{\rule{3.33333pt}{0ex}}\phantom{\rule{3.33333pt}{0ex}}\phantom{\rule{3.33333pt}{0ex}}\phantom{\rule{3.33333pt}{0ex}}\phantom{\rule{3.33333pt}{0ex}}\phantom{\rule{3.33333pt}{0ex}}\phantom{\rule{3.33333pt}{0ex}}\phantom{\rule{3.33333pt}{0ex}}\phantom{\rule{3.33333pt}{0ex}}\phantom{\rule{3.33333pt}{0ex}}\phantom{\rule{3.33333pt}{0ex}}\phantom{\rule{3.33333pt}{0ex}}{E}_{\zeta}:\mathbb{E}\left(H\right)\to {\mathbb{E}}_{\zeta}\left(H\right)\phantom{\rule{3.0pt}{0ex}}\hfill \\ ({a}_{1},{a}_{2},\cdots ,{a}_{p},{b}_{1},{b}_{2},\cdots ,{b}_{p})\mapsto ({a}_{{\zeta}_{1}},{a}_{{\zeta}_{2}},\cdots ,{a}_{{\zeta}_{m}},{b}_{{\zeta}_{1}},{b}_{{\zeta}_{2}},\cdots ,{b}_{{\zeta}_{m}}),\hfill \end{array}$$

#### 2.2.3. Sub-Determined MAGs

For a given sub-determination ζ we have the sublist ${A}_{\zeta}\left(H\right)$ 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

$$\begin{array}{c}{M}_{\zeta}:(A\left(H\right),E\left(H\right))\to ({A}_{\zeta}\left(H\right),{\mathbb{E}}_{\zeta}\left(H\right))\phantom{\rule{3.0pt}{0ex}}\hfill \\ \phantom{\rule{3.33333pt}{0ex}}\phantom{\rule{3.33333pt}{0ex}}\phantom{\rule{3.33333pt}{0ex}}\phantom{\rule{3.33333pt}{0ex}}\phantom{\rule{3.33333pt}{0ex}}\phantom{\rule{3.33333pt}{0ex}}\phantom{\rule{3.33333pt}{0ex}}\phantom{\rule{3.33333pt}{0ex}}\phantom{\rule{3.33333pt}{0ex}}\phantom{\rule{3.33333pt}{0ex}}\phantom{\rule{3.33333pt}{0ex}}\phantom{\rule{3.33333pt}{0ex}}\phantom{\rule{3.33333pt}{0ex}}\phantom{\rule{3.33333pt}{0ex}}\phantom{\rule{3.33333pt}{0ex}}\phantom{\rule{3.33333pt}{0ex}}\phantom{\rule{3.33333pt}{0ex}}\phantom{\rule{3.33333pt}{0ex}}\phantom{\rule{3.33333pt}{0ex}}\phantom{\rule{3.33333pt}{0ex}}\phantom{\rule{3.33333pt}{0ex}}\phantom{\rule{3.33333pt}{0ex}}\phantom{\rule{3.33333pt}{0ex}}\phantom{\rule{3.33333pt}{0ex}}H\mapsto ({A}_{\zeta}\left(H\right),{E}_{\zeta}\left(E\left(H\right)\right)).\hfill \end{array}$$

Since ${A}_{\zeta}\left(H\right)$ is the sublist of aspects of H prescribed by ζ and ${E}_{\zeta}\left(E\left(H\right)\right)$ is the set of all sub-determined edges according to the sub-determination ζ, it follows that $({A}_{\zeta}\left(H\right),{E}_{\zeta}\left(E\left(H\right)\right))$ is a MAG obtained from H according to the sub-determination ζ. As $|{A}_{\zeta}\left(H\right)|<|A\left(H\right)|$, it follows that the order of ${M}_{\zeta}\left(H\right)$ is lower than the order of H. Further, since self-loops may be created by edge sub-determination and discarded, and also since ${E}_{\zeta}$ is not injective, it follows that $|{E}_{\zeta}\left(E\left(H\right)\right)|\le |E\left(H\right)|$.

#### 2.3. MAG Adjacency

Two composite vertices are considered adjacent if they share the same MAG edge, i.e., given two composite vertices $\mathbf{u},\mathbf{v}\in \mathbb{V}\left(H\right)$ are adjacent if and only if there is a MAG edge $e\in E\left(H\right)$ such that $\mathbf{u},\mathbf{v}\in \{{\pi}_{o}\left(e\right),{\pi}_{d}\left(e\right)\}$. Similarly, two MAG edges are considered adjacent if and only if they share a same composite vertex, i.e., two given edges ${e}_{1},{e}_{2}\in E\left(H\right)$ are adjacent if and only if there is a composite vertex $\mathbf{u}\in \mathbb{V}\left(H\right)$ such that $\mathbf{u}\in \{{\pi}_{o}\left({e}_{1}\right),{\pi}_{d}\left({e}_{1}\right)\}$ and $\mathbf{u}\in \{{\pi}_{o}\left({e}_{2}\right),{\pi}_{d}\left({e}_{2}\right)\}$.

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.

The isolated edge $(A1,A2,A3,A4,C1,C2,C3,C4)$ on the leftmost side of Figure 1 exemplifies the composite vertex adjacency concept. In this case the composite vertices $(A1,A2,A3,A4)$ and $(C1,C2,C3,C4)$ are adjacent. The two edges $(E1,E2,E3,E4,H1,H2,H3,H4)$ and $(H1,H2,H3,H4,K1,K2,K3,K4)$ exemplify a case of edge adjacency. Since the composite vertex $(H1,H2,$$H3,H4)$ is shared by both edges, they are adjacent.

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.

#### 2.4. MAG Isomorphism

Before formally defining the 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:A\left(H\right)\to A\left(K\right)$ is defined as a set of p bijective functions, ${f}_{1},{f}_{2},\cdots ,{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 $\mathbf{u}\in \mathbb{V}\left(H\right)$, the aspect list bijection F takes $\mathbf{u}$ to a composite vertex $F\left(\mathbf{u}\right)\in \mathbb{V}\left(K\right)$.

Two MAGs of order p, H and K, are isomorphic if there is an aspect list bijection $F:A\left(H\right)\to A\left(K\right)$ such that an edge $e\in E\left(H\right)$ if and only if the edge $(F\left({\pi}_{o}\left(e\right)\right),F\left({\pi}_{d}\left(e\right)\right))\in E\left(K\right)$.

#### 2.5. 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 $g\left(H\right)$.

A walk on a MAG H is defined as an alternating sequence $W=[{\mathbf{u}}_{1},{e}_{1},{\mathbf{u}}_{2},{e}_{2},{\mathbf{u}}_{3},$$\cdots ,{\mathbf{u}}_{k-1},{e}_{k-1},{\mathbf{u}}_{k}]$ of composite vertices ${\mathbf{u}}_{n}\in \mathbb{V}\left(H\right)$ and edges ${e}_{m}\in E\left(H\right)$, such that ${\mathbf{u}}_{n}={\pi}_{o}\left({e}_{n}\right)$ and ${\mathbf{u}}_{n+1}={\pi}_{d}\left({e}_{n}\right)$ for $1\le n<k$. It follows from this definition that in a walk, consecutive composite vertices as well as consecutive MAG edges are adjacent.

We show in [18] that an alternating sequence W of composite vertices and edges in a MAG H is a walk on H if and only if there is a corresponding walk ${G}_{W}$ in the composite vertices representation of H. This means that a walk on a MAG H has a isomorphic walk on the directed graph $g\left(H\right)$. Since trails and paths also are walks, we also show that the same isomorphism concept extends to them as well.

Figure 1 can also exemplify a MAG path. The two edges $(E1,E2,E3,E4,H1,$$H2,H3,H4)$ and $(H1,H2,$$H3,H4,K1,K2,K3,K4)$ can also be seen as part of the alternating sequence $P=(E1,$, which characterizes a two-hops path from the composite vertex $(E1,E2,E3,E4)$ to the composite vertex $(K1,K2,K3,K4)$.

From the concept that walks, trails, and paths on a MAG have a isomorphism relation to their counterparts on the directed graph $g\left(H\right)$, it follows that analysis and algorithms based on walks, trails, and paths can be formulated on the directed graph $g\left(H\right)$. These properties will be extensively used in the current work.

## 3. Algebraic Representation

In this section, we discuss ways to represent MAGs [18] 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 illustrative example of a three aspect MAG T. It can be seen as a representation of a time-varying multilayer network, showing a hypothetical simple urban transit system. More specifically, Figure 2 depicts the MAG T in its composite vertices representation, $g\left(T\right)$, 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.

#### 3.1. Companion Tuple

Although we show that every MAG H is isomorphic to a directed graph designated $g\left(H\right)$, it is important to note that the set of vertices of this graph is $\mathbb{V}\left(H\right)$, as shown in Expression (6). Since the set $\mathbb{V}\left(H\right)$ is the cartesian product of all the aspects in the MAG H, it is possible to reconstruct the MAG’s aspect list from $\mathbb{V}\left(H\right)$, which is a step necessary to obtain the MAG H from the directed graph $g\left(H\right)$. 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 $\mathbb{V}\left(H\right)$ and $V\left(G\right)$.

In the current work, we construct representations for $g\left(H\right)$, 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 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 $\left(\right|A\left(H\right)\left[1\right]|$, $\left|A\right(H\left)\right[2\left]\right|,\cdots ,$$\left|A\right(H\left)\right[p\left]\right|)$, 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 $\tau \left(H\right)$. For instance, the companion tuple of the MAG T shown in Figure 2 is $\tau \left(T\right)=(3,2,3)$, since T has 3 aspects, of which the first has 3 elements, the second 2 elements, and the third 3 elements.

$$\tau \left(H\right)=\left(\right|A\left(H\right)\left[1\right]|,|A\left(H\right)\left[2\right]|,\cdots ,|A\left(H\right)\left[p\right]\left|\right),$$

Algorithm 1 shows the building of the companion tuple for a given MAG H. Assuming that the size of the aspect list $A\left(H\right)$ and the size of each of the aspect sets contained in $A\left(H\right)$ are known from the computational representation of $A\left(H\right)$, the time complexity for building the companion tuple is $O\left(p\right)$, where p is the number of aspects on MAG H. If, however, these sizes are unknown, then the time complexity is $O\left(s\right)$, where $s={\sum}_{i=1}^{p}\left|A\left(H\right)\left[i\right]\right|$, 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 $O\left(\mathbb{V}\right(H\left)\right)$, which is the cardinality of the set of composite vertices of the MAG.

Algorithm 1: Construction of the companion tuple of a MAG. |

For a given MAG H and a sub-determination ζ, we also define the sub-determined companion tuple ${\tau}_{\zeta}\left(H\right)$, 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.

Algorithm 2: Construction of sub-determined companion tuple. |

#### 3.2. Ordering of Composite Vertices and Aspects

In general, the sequence in which the composite vertices and aspects are organized on a MAG is not relevant. That is, changing the sequence 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, 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 sequence 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. 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 ${\tau}_{i}-1$, where ${\tau}_{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 $\mathbf{u}\left[i\right]$ 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 ${\tau}_{j}$ is the j-th element of the MAG’s companion tuple. Note that $\left|\tau \right|=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 $\left|\tau \right|=p$ is the MAG’s order, and $\mathbf{v}\left[i\right]$ 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 (1) to (18). To illustrate how the numerical representations are obtained, we show examples based on the MAG T.

$$W(i,\tau )=\left\{\begin{array}{cc}1\hfill & \mathrm{if}\phantom{\rule{4.pt}{0ex}}i=1,\hfill \\ {\prod}_{j=1}^{i-1}{\tau}_{j}\hfill & \mathrm{otherwise},\hfill \end{array}\right.$$

$$D(\mathbf{u},\tau )=1+\sum _{i=1}^{\left|\tau \right|}W(i,\tau )\times \mathbf{u}\left[i\right],$$

For this representation, we adopt aspect indices such that for aspect 1 we have $Idx\left(1\right)=0,Idx\left(2\right)=1$ and $Idx\left(3\right)=2$. For aspect 2, we have $Idx\left(Bus\right)=0$ and $Idx\left(Subway\right)=1$, while for aspect 3, $Idx\left({t}_{1}\right)=0,Idx\left({t}_{2}\right)=1$ and $Idx\left({t}_{3}\right)=2$. Since the companion tuple of MAG T is $\tau \left(T\right)=(3,2,3)=\tau $, the weights are $W(1,\tau )=1$, $W(2,\tau )={\tau}_{1}=3$ and $W(3,\tau )={\tau}_{1}\times {\tau}_{2}=6$. Therefore, the composite vertex $\mathbf{v}=(1,Bus,{t}_{1})$ has numerical representation $D(\mathbf{v},\tau )=1+1\times 0+3\times 0+6\times 0=1$, while $D((2,Subway,{t}_{2}),\tau )=1+1\times 1+3\times 1+6\times 1=11$ and $D((2,Bus,{t}_{3}),\tau )=1+1\times 1+3\times 0+6\times 2=14$.

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. 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 $\mathbf{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 representation of the composite vertex. The time complexity for this algorithm is $O\left(p\right)$, where p is the number of aspects on the MAG in question.

Algorithm 3: Determination of the numerical representation of a composite vertex. |

Given the numerical representation of any composite vertex, it is possible to reconstruct its tuple. 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 $\lfloor x\rfloor $ is the floor operator, which for any $x\in \mathbb{R}$ corresponds to the largest integer $i\in \mathbb{Z}$ such that $i\le x$. Note that for calculating $N(d,p,\tau )$ for a MAG with p aspects, it is necessary to calculate $W(p+1,\tau )$. Considering the definition of W from Equation (14), it follows that $W(p+1,\tau )={\prod}_{j=1}^{p}=\left|\mathbb{V}\left(H\right)\right|$, the number of composite vertices on the MAG.

$$N(d,i,\tau )=\lfloor \left((d-1)\phantom{\rule{0.277778em}{0ex}}mod\phantom{\rule{0.277778em}{0ex}}W(i+1,\tau )\right)\phantom{\rule{4pt}{0ex}}/\phantom{\rule{4pt}{0ex}}W(i,\tau )\rfloor ,$$

For instance, taking the composite vertex with numerical representation 14 of the MAG T, we have that

$$\begin{array}{cc}\hfill N(14,1,(3,2,3\left)\right)=& \phantom{\rule{3.33333pt}{0ex}}\lfloor \left(\right(14-1\left)\phantom{\rule{0.277778em}{0ex}}mod\phantom{\rule{0.277778em}{0ex}}3\right)/1\rfloor =\lfloor 1/1\rfloor =1\hfill \\ \hfill N(14,2,(3,2,3\left)\right)=& \phantom{\rule{3.33333pt}{0ex}}\lfloor \left(\right(14-1\left)\phantom{\rule{0.277778em}{0ex}}mod\phantom{\rule{0.277778em}{0ex}}6\right)/3\rfloor =\lfloor 1/3\rfloor =0\hfill \\ \hfill N(14,3,(3,2,3\left)\right)=& \phantom{\rule{3.33333pt}{0ex}}\lfloor \left(\right(14-1\left)\phantom{\rule{0.277778em}{0ex}}mod\phantom{\rule{0.277778em}{0ex}}18\right)/6\rfloor =\lfloor 13/6\rfloor =2.\hfill \end{array}$$

We can therefore define the inverse of function D as
which reconstructs the composite vertex tuple in its numerical form. From this, we can see that, for instance, ${D}^{-1}(14,(3,2,3))=(1,0,2)$, which corresponds to the composite vertex $(2,Bus,{t}_{3})$. Algorithm 4 shows the implementation of ${D}^{-1}$.

$${D}^{-1}(d,\tau )=(N(d,1,\tau ),N(d,2,\tau ),\cdots ,N(d,\left|\tau \right|,\tau \left)\right),$$

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, $g\left(H\right)$. The role of this relation will become clear in Section 3.4 and Section 3.5, where the matrix forms of the MAG are presented.

Algorithm 4: Determination of the composite vertex from its numerical representation. |

#### 3.3. Elimination of Trivial Components

In the MAG T shown in Figure 3 the composite vertices of numerical representation $\left(1\right),\left(6\right),\left(7\right),$ $\left(12\right),\left(13\right),$ and $\left(18\right)$ 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 $\mathbb{V}\left(H\right)$. 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 [15], 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 [15]. 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 $m\left(H\right)$ as the MAG’s composite vertices representation with all its trivial components removed. Figure 4 shows the main components graph $m\left(T\right)$ for the MAG T. It is worth noting that numerical representations are not defined for $m\left(T\right)$.

This can be achieved algebraically for any MAG H with the help of a matrix $\mathbf{R}\left(H\right)$ constructed from the identity $\mathbf{I}\in {\mathbb{R}}^{n\times n}$, where $n=\left|\mathbb{V}\right(H\left)\right|$ is the number of composite vertices on the MAG. The matrix $\mathbf{R}\left(H\right)$ is obtained from this $n\times 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 $\mathbf{R}\left(H\right)\in {\mathbb{R}}^{n\times 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 $\mathbf{R}\left(H\right)=\mathbf{I}\in {\mathbb{R}}^{n\times n}$.

It is also worth noting that the matrix ${\mathbf{I}}_{m}\left(H\right)=\mathbf{R}\left(H\right)\phantom{\rule{4pt}{0ex}}\mathbf{R}{\left(H\right)}^{T}\in {\mathbb{R}}^{n\times n}$ is a matrix akin to the identity $\mathbf{I}\in {\mathbb{R}}^{n\times n}$, but the diagonal entries corresponding to the trivial components (removed in $\mathbf{R}\left(H\right)$) have value 0. Therefore, multiplying a $n\times n$ matrix by ${\mathbf{I}}_{m}\left(H\right)$ to the left has the effect of turning all entries on the rows corresponding to the trivial components to 0 s. Similarly, multiplying by ${\mathbf{I}}_{m}\left(H\right)$ to the right has the effect of turning the entries of the columns corresponding to the trivial elements to 0 s.

As an example, we show the matrix $\mathbf{R}\left(T\right)\in {\mathbb{R}}^{18\times 12}$,
which is obtained from the $18\times 18$ identity matrix by removing the columns $1,6,7,12,13,$ and 18 that correspond to the trivial components of the MAG T.

$$\mathbf{R}\left(T\right)=\left[\begin{array}{cccccccccccc}0& 0& 0& 0& 0& 0& 0& 0& 0& 0& 0& 0\\ \mathbf{1}& 0& 0& 0& 0& 0& 0& 0& 0& 0& 0& 0\\ 0& \mathbf{1}& 0& 0& 0& 0& 0& 0& 0& 0& 0& 0\\ 0& 0& \mathbf{1}& 0& 0& 0& 0& 0& 0& 0& 0& 0\\ 0& 0& 0& \mathbf{1}& 0& 0& 0& 0& 0& 0& 0& 0\\ 0& 0& 0& 0& 0& 0& 0& 0& 0& 0& 0& 0\\ 0& 0& 0& 0& 0& 0& 0& 0& 0& 0& 0& 0\\ 0& 0& 0& 0& \mathbf{1}& 0& 0& 0& 0& 0& 0& 0\\ 0& 0& 0& 0& 0& \mathbf{1}& 0& 0& 0& 0& 0& 0\\ 0& 0& 0& 0& 0& 0& \mathbf{1}& 0& 0& 0& 0& 0\\ 0& 0& 0& 0& 0& 0& 0& \mathbf{1}& 0& 0& 0& 0\\ 0& 0& 0& 0& 0& 0& 0& 0& 0& 0& 0& 0\\ 0& 0& 0& 0& 0& 0& 0& 0& 0& 0& 0& 0\\ 0& 0& 0& 0& 0& 0& 0& 0& \mathbf{1}& 0& 0& 0\\ 0& 0& 0& 0& 0& 0& 0& 0& 0& \mathbf{1}& 0& 0\\ 0& 0& 0& 0& 0& 0& 0& 0& 0& 0& \mathbf{1}& 0\\ 0& 0& 0& 0& 0& 0& 0& 0& 0& 0& 0& \mathbf{1}\\ 0& 0& 0& 0& 0& 0& 0& 0& 0& 0& 0& 0\end{array}\right],$$

The algebraic form of the elimination of the trivial components is presented in Equation (22) in Section 3.4, after the required definition of adjacency matrix.

#### 3.4. 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, $g\left(H\right)$, and its companion tuple $\tau \left(H\right)$. In fact, the MAG’s adjacency matrix is the adjacency matrix of the composite vertices representation, where the sequence of the rows and columns is given by the numerical representation of the composite vertices of $g\left(H\right)$.

Since the set $\mathbb{V}\left(H\right)$ 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 ${\tau}_{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.

$$n=\left|\mathbb{V}\left(H\right)\right|=\prod _{i=1}^{p}{\tau}_{i},$$

The general form of any entry of the matrix $\mathbf{J}\left(H\right)$ is given by
where $(\mathbf{u},\mathbf{v})\in E\left(g\right(H\left)\right)$ means that $(\mathbf{u},\mathbf{v})$ is an edge on the composite vertices representation $g\left(H\right)$ of the MAG H, so that $\mathbf{u},\mathbf{v}\in \mathbb{V}\left(H\right)$ are composite vertices of H. It follows from the definition of $g\left(H\right)$ and its natural isomorphism to H, that $(\mathbf{u},\mathbf{v})\in E\left(g\right(H\left)\right)$ if and only if there is an edge $e\in E\left(H\right)$ such that $\mathbf{u}={\pi}_{o}\left(e\right)$ and $\mathbf{v}={\pi}_{d}\left(e\right)$. It is important to note, however, that the notation ${j}_{\mathbf{u},\mathbf{v}}$ is in fact a shorthand for ${j}_{D(\mathbf{u},\tau ),D(\mathbf{v},\tau )}$, where $D(\mathbf{u},\tau )$ is the row number and $D(\mathbf{v},\tau )$ 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 ($D(\mathbf{u},\tau )$). Therefore, the adjacency matrix of any given MAG is always presented with its companion tuple.

$${j}_{\mathbf{u},\mathbf{v}}=\left\{\begin{array}{cc}\hfill 1& \mathrm{if}\phantom{\rule{4.pt}{0ex}}(\mathbf{u},\mathbf{v})\in E\left(g\right(H\left)\right),\hfill \\ \hfill 0& \mathrm{otherwise},\hfill \end{array}\right.$$

The adjacency matrix of a given MAG H is constructed by Algorithm 5, where $\left|\mathbb{V}\right(H\left)\right|$ is the number of composite vertices in H, which can be calculated using Equation (19), $D({\pi}_{o}\left(e\right),\tau )$ and $D({\pi}_{d}\left(e\right),\tau )$ are the numerical representation of the origin and destination composite vertices of edge $e\in E\left(H\right)$, respectively, as defined in Section 3.2.

Algorithm 5: Building $\mathbf{J}\left(H\right)$ from MAG H. |

Considering that a sparse matrix with all entries 0 can be created in constant time, and that both functions $CompTuple$ and D (see Algorithms 1 and 3) have time complexity $O\left(p\right)$, we conclude that Algorithm 5 has time complexity $O(p*|E\left(H\right)\left|\right)$, where p is the number of aspects of MAG H and $\left|E\right(H\left)\right|$ the number of edges.

As an example, the adjacency matrix of the MAG T is shown in Expression (21). This adjacency matrix $\mathbf{J}\left(T\right)\in {\mathbb{R}}^{18\times 18}$ has 324 entries, of which just 22 are non-zero.

$$\mathbf{J}\left(T\right)=\left[\begin{array}{cccccccccccccccccc}\hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0\\ \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill \mathbf{1}& \hfill 0& \hfill 0& \hfill \mathbf{1}& \hfill \mathbf{1}& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0\\ \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill \mathbf{1}& \hfill \mathbf{1}& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0\\ \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill \mathbf{1}& \hfill \mathbf{1}& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0\\ \hfill 0& \hfill \mathbf{1}& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill \mathbf{1}& \hfill \mathbf{1}& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0\\ \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0\\ \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0\\ \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill \mathbf{1}& \hfill 0& \hfill 0& \hfill \mathbf{1}& \hfill \mathbf{1}& \hfill 0& \hfill 0& \hfill 0\\ \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill \mathbf{1}& \hfill \mathbf{1}& \hfill 0& \hfill 0& \hfill 0\\ \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill \mathbf{1}& \hfill \mathbf{1}& \hfill 0\\ \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill \mathbf{1}& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill \mathbf{1}& \hfill \mathbf{1}& \hfill 0\\ \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0\\ \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0\\ \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill \mathbf{1}& \hfill 0\\ \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0\\ \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0\\ \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill \mathbf{1}& \hfill 0& \hfill 0& \hfill 0& \hfill 0\\ \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0\end{array}\right]$$

It is important to note that the sequence of the columns and rows of $\mathbf{J}\left(T\right)$ 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 $(2,Bus,{t}_{1},2,Bus,{t}_{2})$ of the MAG T. In this way, although $\mathbf{J}\left(T\right)$ is presented in matrix form, together with the companion tuple $\tau \left(T\right)$, 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 $m\left(H\right)$ is obtained by removing the MAG’s trivial components, as stated in Section 3.3. The matrix $\mathbf{J}\left(m\right(H\left)\right)$ is then obtained with the use of the matrix $\mathbf{R}\left(H\right)$, presented in Section 3.3. $\mathbf{J}\left(m\right(H\left)\right)$ is obtained as
where $\mathbf{J}\left(m\left(H\right)\right)\in {\mathbb{R}}^{n-r\times n-r}$ is the adjacency matrix containing only the main components of the MAG.

$$\mathbf{J}\left(m\left(H\right)\right)=\mathbf{R}{\left(H\right)}^{T}\phantom{\rule{4pt}{0ex}}\mathbf{J}\left(H\right)\phantom{\rule{4pt}{0ex}}\mathbf{R}\left(H\right),$$

It is also possible to obtain the adjacency matrix $\mathbf{J}\left(H\right)$ from $\mathbf{J}\left(m\right(H\left)\right)$. This follows from the fact that on the adjacency matrix $\mathbf{J}\left(H\right)$ the rows and columns corresponding to trivial components are already zero. Therefore,
where ${\mathbf{I}}_{m}\left(H\right)=\mathbf{R}\left(H\right)\phantom{\rule{4pt}{0ex}}\mathbf{R}{\left(H\right)}^{T}$. Then, we have that

$$\mathbf{J}\left(H\right)={\mathbf{I}}_{m}\left(H\right)\phantom{\rule{4pt}{0ex}}\mathbf{J}\left(H\right)\phantom{\rule{4pt}{0ex}}{\mathbf{I}}_{m}\left(H\right),$$

$$\begin{array}{c}\mathbf{R}\left(H\right)\phantom{\rule{4pt}{0ex}}\mathbf{J}\left(m\left(H\right)\right)\phantom{\rule{4pt}{0ex}}\mathbf{R}{\left(H\right)}^{T}=\mathbf{R}\left(H\right)\phantom{\rule{4pt}{0ex}}\mathbf{R}{\left(H\right)}^{T}\phantom{\rule{4pt}{0ex}}\mathbf{J}\left(H\right)\phantom{\rule{4pt}{0ex}}\mathbf{R}\left(H\right)\phantom{\rule{4pt}{0ex}}\mathbf{R}{\left(H\right)}^{T}\phantom{\rule{3.0pt}{0ex}}\hfill \\ \phantom{\rule{3.33333pt}{0ex}}\phantom{\rule{3.33333pt}{0ex}}\phantom{\rule{3.33333pt}{0ex}}\phantom{\rule{3.33333pt}{0ex}}\phantom{\rule{3.33333pt}{0ex}}\phantom{\rule{3.33333pt}{0ex}}\phantom{\rule{3.33333pt}{0ex}}\phantom{\rule{3.33333pt}{0ex}}\phantom{\rule{3.33333pt}{0ex}}\phantom{\rule{3.33333pt}{0ex}}\phantom{\rule{3.33333pt}{0ex}}\phantom{\rule{3.33333pt}{0ex}}\phantom{\rule{3.33333pt}{0ex}}\phantom{\rule{3.33333pt}{0ex}}\phantom{\rule{3.33333pt}{0ex}}\phantom{\rule{3.33333pt}{0ex}}\phantom{\rule{3.33333pt}{0ex}}\phantom{\rule{3.33333pt}{0ex}}\phantom{\rule{3.33333pt}{0ex}}\phantom{\rule{3.33333pt}{0ex}}\phantom{\rule{3.33333pt}{0ex}}\phantom{\rule{3.33333pt}{0ex}}\phantom{\rule{3.33333pt}{0ex}}\phantom{\rule{3.33333pt}{0ex}}\phantom{\rule{3.33333pt}{0ex}}\phantom{\rule{3.33333pt}{0ex}}\phantom{\rule{3.33333pt}{0ex}}\phantom{\rule{3.33333pt}{0ex}}\phantom{\rule{3.33333pt}{0ex}}\phantom{\rule{3.33333pt}{0ex}}\phantom{\rule{3.33333pt}{0ex}}\phantom{\rule{3.33333pt}{0ex}}\phantom{\rule{3.33333pt}{0ex}}\phantom{\rule{3.33333pt}{0ex}}={\mathbf{I}}_{m}\left(H\right)\phantom{\rule{4pt}{0ex}}\mathbf{J}\left(H\right)\phantom{\rule{4pt}{0ex}}{\mathbf{I}}_{m}\left(H\right)\phantom{\rule{3.0pt}{0ex}}\hfill \\ \phantom{\rule{3.33333pt}{0ex}}\phantom{\rule{3.33333pt}{0ex}}\phantom{\rule{3.33333pt}{0ex}}\phantom{\rule{3.33333pt}{0ex}}\phantom{\rule{3.33333pt}{0ex}}\phantom{\rule{3.33333pt}{0ex}}\phantom{\rule{3.33333pt}{0ex}}\phantom{\rule{3.33333pt}{0ex}}\phantom{\rule{3.33333pt}{0ex}}\phantom{\rule{3.33333pt}{0ex}}\phantom{\rule{3.33333pt}{0ex}}\phantom{\rule{3.33333pt}{0ex}}\phantom{\rule{3.33333pt}{0ex}}\phantom{\rule{3.33333pt}{0ex}}\phantom{\rule{3.33333pt}{0ex}}\phantom{\rule{3.33333pt}{0ex}}\phantom{\rule{3.33333pt}{0ex}}\phantom{\rule{3.33333pt}{0ex}}\phantom{\rule{3.33333pt}{0ex}}\phantom{\rule{3.33333pt}{0ex}}\phantom{\rule{3.33333pt}{0ex}}\phantom{\rule{3.33333pt}{0ex}}\phantom{\rule{3.33333pt}{0ex}}\phantom{\rule{3.33333pt}{0ex}}\phantom{\rule{3.33333pt}{0ex}}\phantom{\rule{3.33333pt}{0ex}}\phantom{\rule{3.33333pt}{0ex}}\phantom{\rule{3.33333pt}{0ex}}\phantom{\rule{3.33333pt}{0ex}}\phantom{\rule{3.33333pt}{0ex}}\phantom{\rule{3.33333pt}{0ex}}\phantom{\rule{3.33333pt}{0ex}}\phantom{\rule{3.33333pt}{0ex}}\phantom{\rule{3.33333pt}{0ex}}=\mathbf{J}\left(H\right).\hfill \end{array}$$

Expression (25) shows $\mathbf{J}\left(m\right(T\left)\right)$, the adjacency matrix of $m\left(T\right)$. This matrix is obtained from the adjacency matrix $\mathbf{J}\left(T\right)$ 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 $\mathbf{J}\left(m\left(T\right)\right)=\mathbf{R}{\left(T\right)}^{T}\phantom{\rule{4pt}{0ex}}\mathbf{J}\left(T\right)\phantom{\rule{4pt}{0ex}}\mathbf{R}\left(T\right)$, so that

$$\mathbf{J}\left(m\left(T\right)\right)=\left[\begin{array}{cccccccccccc}\hfill 0& \hfill 0& \hfill 0& \hfill \mathbf{1}& \hfill \mathbf{1}& \hfill \mathbf{1}& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0\\ \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill \mathbf{1}& \hfill \mathbf{1}& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0\\ \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill \mathbf{1}& \hfill \mathbf{1}& \hfill 0& \hfill 0& \hfill 0& \hfill 0\\ \hfill \mathbf{1}& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill \mathbf{1}& \hfill \mathbf{1}& \hfill 0& \hfill 0& \hfill 0& \hfill 0\\ \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill \mathbf{1}& \hfill \mathbf{1}& \hfill \mathbf{1}& \hfill 0& \hfill 0\\ \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill \mathbf{1}& \hfill \mathbf{1}& \hfill 0& \hfill 0\\ \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill \mathbf{1}& \hfill \mathbf{1}\\ \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill \mathbf{1}& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill \mathbf{1}& \hfill \mathbf{1}\\ \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill \mathbf{1}\\ \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0\\ \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0\\ \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill \mathbf{1}& \hfill 0& \hfill 0& \hfill 0\end{array}\right].$$

In general, the adjacency matrices associated with a MAG are sparse, meaning that for an $n\times n$ adjacency matrix the number of non-zero entries of the matrix is of the order $O\left(n\right)$. 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 $O\left(n\right)$. Therefore, these matrices can be stored efficiently using sparse matrices representations, such as Compressed Sparse Column (CSC) or Compressed Sparse Row (CSR) [33], because such representations omit all entries of value zero. Assuming that the number of edges is larger than the number of composite vertices, these representations provide a space complexity of $O\left(m\right)$ 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.

#### 3.5. 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 $g\left(H\right)$ and the companion tuple $\tau \left(H\right)$, adopting the vertex sequence induced by the numerical representation presented in Section 3.2. The MAG’s incidence matrix $\mathbf{C}\left(H\right)\in {\mathbb{R}}^{m\times n}$, where $m=\left|E\right(H\left)\right|$ is the number of edges in the MAG and $n=\left|\mathbb{V}\right(H\left)\right|$ is the number of composite vertices on the MAG, is defined then as
where $e\in E\left(g\right(H\left)\right)$ is an edge in MAG H and $\mathbf{u}\in \mathbb{V}\left(H\right)$ is a composite vertex in MAG H. Here, the notation ${c}_{e,\mathbf{u}}$ is a shorthand for ${c}_{{I}_{d}\left(e\right),D(\mathbf{u},\tau )}$, where ${I}_{d}\left(e\right)$ is an numerical index for each edge and $D(\mathbf{u},\tau )$ is the numerical representation of the composite vertex $\mathbf{u}$. Note that the use of the composite vertex numerical representation ties the incidence matrix to the MAG’s companion tuple.

$${c}_{e,\mathbf{u}}=\left\{\begin{array}{cc}\hfill 1& \mathrm{if}\phantom{\rule{4.pt}{0ex}}\mathbf{u}={\pi}_{o}\left(e\right),\hfill \\ \hfill -1& \mathrm{if}\phantom{\rule{4.pt}{0ex}}\mathbf{u}={\pi}_{d}\left(e\right),\hfill \\ \hfill 0& \mathrm{otherwise},\hfill \end{array}\right.$$

Although the sequence of the composite vertices is defined by each composite vertex numerical representation, the sequence used to present the MAG edges in the incidence matrix is not relevant. The incidence matrix of a directed graph has several well-known properties [34], 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.

For a given MAG H, the incidence matrix $\mathbf{C}\left(H\right)$ is built by Algorithm 6, where $D({\pi}_{o}\left(e\right),T)$ and $D({\pi}_{d}\left(e\right),T)$ are the numerical representation of the origin and destination composite vertices of edge $e\in E\left(H\right)$, respectively, as defined in Section 3.2, and ${I}_{d}\left(e\right)$ is a unique numerical index for the edge $e\in E\left(H\right)$, ranging from 1 to m. Considering that a sparse matrix with all entries 0 can be created in constant time, and that both functions $CompTuple$ and D (see Algorithms 1 and 3) have time complexity of $O\left(p\right)$, we conclude that Algorithm 6 has time complexity of $O(p*|E\left(H\right)\left|\right)$, where p is the number of aspects of MAG H and $\left|E\right(H\left)\right|$ the number of edges.

Algorithm 6: Building $\mathbf{C}\left(H\right)$ from MAG H. |

Given the incidence matrix $\mathbf{C}\left(H\right)$ of a MAG H, it is possible to obtain the incidence matrix of the main components graph $\mathbf{C}\left(m\right(H\left)\right)$ using the matrix $\mathbf{R}\left(H\right)\in {\mathbb{R}}^{n\times n-r}$ defined in Section 3.4. The incidence matrix of $m\left(H\right)$ is given by

$$\mathbf{C}\left(m\right(H\left)\right)=\mathbf{C}\left(H\right)\phantom{\rule{4pt}{0ex}}\mathbf{R}\left(H\right).$$

Further, given the incidence matrix of the MAG’s main components graph and the matrix $\mathbf{R}\left(H\right)$, it is possible to recover the MAG’s incidence matrix, as

$$\begin{array}{c}\mathbf{C}\left(m\left(H\right)\right)\phantom{\rule{4pt}{0ex}}\mathbf{R}{\left(H\right)}^{T}=\mathbf{C}\left(H\right)\phantom{\rule{4pt}{0ex}}\mathbf{R}\left(H\right)\phantom{\rule{4pt}{0ex}}\mathbf{R}{\left(H\right)}^{T}\phantom{\rule{3.0pt}{0ex}}\hfill \\ \phantom{\rule{3.33333pt}{0ex}}\phantom{\rule{3.33333pt}{0ex}}\phantom{\rule{3.33333pt}{0ex}}\phantom{\rule{3.33333pt}{0ex}}\phantom{\rule{3.33333pt}{0ex}}\phantom{\rule{3.33333pt}{0ex}}\phantom{\rule{3.33333pt}{0ex}}\phantom{\rule{3.33333pt}{0ex}}\phantom{\rule{3.33333pt}{0ex}}\phantom{\rule{3.33333pt}{0ex}}\phantom{\rule{3.33333pt}{0ex}}\phantom{\rule{3.33333pt}{0ex}}\phantom{\rule{3.33333pt}{0ex}}\phantom{\rule{3.33333pt}{0ex}}\phantom{\rule{3.33333pt}{0ex}}\phantom{\rule{3.33333pt}{0ex}}\phantom{\rule{3.33333pt}{0ex}}\phantom{\rule{3.33333pt}{0ex}}\phantom{\rule{3.33333pt}{0ex}}\phantom{\rule{3.33333pt}{0ex}}\phantom{\rule{3.33333pt}{0ex}}\phantom{\rule{3.33333pt}{0ex}}\phantom{\rule{3.33333pt}{0ex}}\phantom{\rule{3.33333pt}{0ex}}\phantom{\rule{3.33333pt}{0ex}}\phantom{\rule{3.33333pt}{0ex}}=\mathbf{C}\left(H\right)\phantom{\rule{4pt}{0ex}}{\mathbf{I}}_{m}\left(H\right)\phantom{\rule{3.0pt}{0ex}}\hfill \\ \phantom{\rule{3.33333pt}{0ex}}\phantom{\rule{3.33333pt}{0ex}}\phantom{\rule{3.33333pt}{0ex}}\phantom{\rule{3.33333pt}{0ex}}\phantom{\rule{3.33333pt}{0ex}}\phantom{\rule{3.33333pt}{0ex}}\phantom{\rule{3.33333pt}{0ex}}\phantom{\rule{3.33333pt}{0ex}}\phantom{\rule{3.33333pt}{0ex}}\phantom{\rule{3.33333pt}{0ex}}\phantom{\rule{3.33333pt}{0ex}}\phantom{\rule{3.33333pt}{0ex}}\phantom{\rule{3.33333pt}{0ex}}\phantom{\rule{3.33333pt}{0ex}}\phantom{\rule{3.33333pt}{0ex}}\phantom{\rule{3.33333pt}{0ex}}\phantom{\rule{3.33333pt}{0ex}}\phantom{\rule{3.33333pt}{0ex}}\phantom{\rule{3.33333pt}{0ex}}\phantom{\rule{3.33333pt}{0ex}}\phantom{\rule{3.33333pt}{0ex}}\phantom{\rule{3.33333pt}{0ex}}\phantom{\rule{3.33333pt}{0ex}}\phantom{\rule{3.33333pt}{0ex}}\phantom{\rule{3.33333pt}{0ex}}\phantom{\rule{3.33333pt}{0ex}}=\mathbf{C}\left(H\right).\hfill \end{array}$$

This is only possible because the columns of $\mathbf{C}\left(H\right)$, which are forced to $\mathbf{0}$ by the multiplication by ${\mathbf{I}}_{m}\left(H\right)$, were already $\mathbf{0}$, as the composite vertices represented by them have no edges incident to them.

The incidence matrix $\mathbf{C}\left(T\right)$ of the example MAG T is shown in Expression (29). The vertices (columns) sequence is determined by the vertices numerical representation, while the edge sequence remains unconstrained. The trivial components correspond to columns $1,6,7,12,13,$ and 18, which have all entries with value 0.

$$\mathbf{C}\left(T\right)=\left[\begin{array}{cccccccccccccccccc}\hfill 0& \hfill \mathbf{1}& \hfill 0& \hfill 0& \hfill -\mathbf{1}& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0\\ \hfill 0& \hfill -\mathbf{1}& \hfill 0& \hfill 0& \hfill \mathbf{1}& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0\\ \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill \mathbf{1}& \hfill 0& \hfill 0& \hfill -\mathbf{1}& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0\\ \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill -\mathbf{1}& \hfill 0& \hfill 0& \hfill \mathbf{1}& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0\\ \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill \mathbf{1}& \hfill 0& \hfill 0& \hfill -\mathbf{1}& \hfill 0\\ \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill -\mathbf{1}& \hfill 0& \hfill 0& \hfill \mathbf{1}& \hfill 0\\ \hfill 0& \hfill \mathbf{1}& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill -\mathbf{1}& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0\\ \hfill 0& \hfill 0& \hfill \mathbf{1}& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill -\mathbf{1}& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0\\ \hfill 0& \hfill 0& \hfill 0& \hfill \mathbf{1}& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill -\mathbf{1}& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0\\ \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill \mathbf{1}& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill -\mathbf{1}& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0\\ \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill \mathbf{1}& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill -\mathbf{1}& \hfill 0& \hfill 0& \hfill 0& \hfill 0\\ \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill \mathbf{1}& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill -\mathbf{1}& \hfill 0& \hfill 0& \hfill 0\\ \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill \mathbf{1}& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill -\mathbf{1}& \hfill 0& \hfill 0\\ \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill \mathbf{1}& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill -\mathbf{1}& \hfill 0\\ \hfill 0& \hfill \mathbf{1}& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill -\mathbf{1}& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0\\ \hfill 0& \hfill 0& \hfill \mathbf{1}& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill -\mathbf{1}& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0\\ \hfill 0& \hfill 0& \hfill 0& \hfill \mathbf{1}& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill -\mathbf{1}& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0\\ \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill \mathbf{1}& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill -\mathbf{1}& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0\\ \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill \mathbf{1}& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill -\mathbf{1}& \hfill 0& \hfill 0& \hfill 0\\ \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill \mathbf{1}& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill -\mathbf{1}& \hfill 0& \hfill 0& \hfill 0& \hfill 0\\ \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill \mathbf{1}& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill -\mathbf{1}& \hfill 0\\ \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill \mathbf{1}& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill -\mathbf{1}& \hfill 0& \hfill 0\end{array}\right]$$

The main components incidence matrix $\mathbf{C}\left(m\right(T\left)\right)$ is depicted in Expression (30). It is obtained from the matrix $\mathbf{C}\left(T\right)$ by removing the trivial components, as shown in Expression (28).

$$\mathbf{C}\left(m\left(T\right)\right)=\left[\begin{array}{cccccccccccc}\hfill \mathbf{1}& \hfill 0& \hfill 0& \hfill -\mathbf{1}& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0\\ \hfill -\mathbf{1}& \hfill 0& \hfill 0& \hfill \mathbf{1}& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0\\ \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill \mathbf{1}& \hfill 0& \hfill 0& \hfill -\mathbf{1}& \hfill 0& \hfill 0& \hfill 0& \hfill 0\\ \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill -\mathbf{1}& \hfill 0& \hfill 0& \hfill \mathbf{1}& \hfill 0& \hfill 0& \hfill 0& \hfill 0\\ \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill \mathbf{1}& \hfill 0& \hfill 0& \hfill -\mathbf{1}\\ \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill -\mathbf{1}& \hfill 0& \hfill 0& \hfill \mathbf{1}\\ \hfill \mathbf{1}& \hfill 0& \hfill 0& \hfill 0& \hfill -\mathbf{1}& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0\\ \hfill 0& \hfill \mathbf{1}& \hfill 0& \hfill 0& \hfill 0& \hfill -\mathbf{1}& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0\\ \hfill 0& \hfill 0& \hfill \mathbf{1}& \hfill 0& \hfill 0& \hfill 0& \hfill -\mathbf{1}& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0\\ \hfill 0& \hfill 0& \hfill 0& \hfill \mathbf{1}& \hfill 0& \hfill 0& \hfill 0& \hfill -\mathbf{1}& \hfill 0& \hfill 0& \hfill 0& \hfill 0\\ \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill \mathbf{1}& \hfill 0& \hfill 0& \hfill 0& \hfill -\mathbf{1}& \hfill 0& \hfill 0& \hfill 0\\ \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill \mathbf{1}& \hfill 0& \hfill 0& \hfill 0& \hfill -\mathbf{1}& \hfill 0& \hfill 0\\ \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill \mathbf{1}& \hfill 0& \hfill 0& \hfill 0& \hfill -\mathbf{1}& \hfill 0\\ \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill \mathbf{1}& \hfill 0& \hfill 0& \hfill 0& \hfill -\mathbf{1}\\ \hfill \mathbf{1}& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill -\mathbf{1}& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0\\ \hfill 0& \hfill \mathbf{1}& \hfill 0& \hfill 0& \hfill -\mathbf{1}& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0\\ \hfill 0& \hfill 0& \hfill \mathbf{1}& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill -\mathbf{1}& \hfill 0& \hfill 0& \hfill 0& \hfill 0\\ \hfill 0& \hfill 0& \hfill 0& \hfill \mathbf{1}& \hfill 0& \hfill 0& \hfill -\mathbf{1}& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0\\ \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill \mathbf{1}& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill -\mathbf{1}& \hfill 0& \hfill 0\\ \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill \mathbf{1}& \hfill 0& \hfill 0& \hfill -\mathbf{1}& \hfill 0& \hfill 0& \hfill 0\\ \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill \mathbf{1}& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill -\mathbf{1}\\ \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill \mathbf{1}& \hfill 0& \hfill 0& \hfill -\mathbf{1}& \hfill 0\end{array}\right]$$

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 [33]. 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 $O\left(m\right)$, where $m=\left|E\right(H\left)\right|$ is the number of edges on the MAG H.

## 4. 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 [33], 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,32,33]. In this section, we discuss algorithms for degree computation, BFS, and DFS in MAGs, since these algorithms are well-known and fairly simple, being thus convenient for the intended didactical purpose of this work. Furthermore, these basic algorithms also constitute building blocks for more sophisticated graph algorithms. 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 the presented BFS and DFS algorithms follow the same implementation shown in [5].

#### 4.1. 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. We denote $\mathbf{0}$ and $\mathbf{1}$ the column vectors with all entries equal to 0 and 1, respectively. In all cases, we assume the vectors have the dimension necessary for the operation where they are applied. When necessary to improve readability, we indicate the dimension by a sub-script as in ${\mathbf{0}}_{n}$ or ${\mathbf{1}}_{n}$.

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 ${\mathbf{M}}_{\zeta}\left(H\right)$$\in {\mathbb{R}}^{{n}_{\zeta}\times n}$ is a rectangular matrix, where $n=\left|\mathbb{V}\right(H\left)\right|$ is the number of composite vertices of H and ${n}_{\zeta}=\left|{\mathbb{V}}_{\zeta}\left(H\right)\right|$ 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 ${n}_{\zeta}\phantom{\rule{3.33333pt}{0ex}}|\phantom{\rule{3.33333pt}{0ex}}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, ${\mathbf{M}}_{\zeta}\left(H\right)$ 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 ${\mathbf{M}}_{\zeta}\left(H\right)$ for a given MAG H and sub-determination ζ. The function D takes a composite vertex to its numerical representation and the function ${S}_{\zeta}$ takes a composite vertex to its sub-determined form, i.e., it drops the aspects not present in the sub-determination. To determine the time complexity of Algorithm 7, we consider that the count of composite vertices in line 3 is $O\left(\right|\mathbb{V}\left(H\right)\left|\right)$, the same is the case for the count on line 4, the construction of companion tuple at line 2 is $O\left(p\right)$, the construction of an empty sparse matrix at line 5 is $O\left(1\right)$, and, finally, the

**for**loop initiated at line 6 is also $O\left(\right|\mathbb{V}\left(H\right)\left|\right)$. Since the number of aspects $p\ll \left|\mathbb{V}\right(H\left)\right|$, we conclude that the time complexity of Algorithm 7 is $O\left(\right|\mathbb{V}\left(H\right)\left|\right)$.Algorithm 7: Construction of ${\mathbf{M}}_{\zeta}$. |

For instance, consider the example MAG T and a sub-determination ${\zeta}_{t}={\mathtt{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 ${\zeta}_{t}$ are location and transit layers. Since in T there are 3 locations and 2 transit layers, it follows that $|{\mathbb{V}}_{\zeta t}\left(T\right)|=6$. Hence, ${\mathbf{M}}_{\zeta t}\left(T\right)\in {\mathbb{R}}^{6\times 18}$ constructed according to Algorithm 7 is given by

$${\mathbf{M}}_{\zeta t}\left(T\right)=\left[\begin{array}{cccccccccccccccccc}\hfill \mathbf{1}& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill \mathbf{1}& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill \mathbf{1}& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0\\ \hfill 0& \hfill \mathbf{1}& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill \mathbf{1}& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill \mathbf{1}& \hfill 0& \hfill 0& \hfill 0& \hfill 0\\ \hfill 0& \hfill 0& \hfill \mathbf{1}& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill \mathbf{1}& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill \mathbf{1}& \hfill 0& \hfill 0& \hfill 0\\ \hfill 0& \hfill 0& \hfill 0& \hfill \mathbf{1}& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill \mathbf{1}& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill \mathbf{1}& \hfill 0& \hfill 0\\ \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill \mathbf{1}& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill \mathbf{1}& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill \mathbf{1}& \hfill 0\\ \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill \mathbf{1}& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill \mathbf{1}& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill \mathbf{1}\end{array}\right].$$

As a further example, consider the MAG T and a sub-determination ${\zeta}_{T}={\mathtt{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}_{\zeta T}\left(T\right)\in {\mathbb{R}}^{3\times 18}$ is

$${\mathbf{M}}_{\zeta T}\left(T\right)=\left[\begin{array}{cccccccccccccccccc}\hfill \mathbf{1}& \hfill \mathbf{1}& \hfill \mathbf{1}& \hfill \mathbf{1}& \hfill \mathbf{1}& \hfill \mathbf{1}& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0\\ \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill \mathbf{1}& \hfill \mathbf{1}& \hfill \mathbf{1}& \hfill \mathbf{1}& \hfill \mathbf{1}& \hfill \mathbf{1}& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0\\ \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill \mathbf{1}& \hfill \mathbf{1}& \hfill \mathbf{1}& \hfill \mathbf{1}& \hfill \mathbf{1}& \hfill \mathbf{1}\end{array}\right].$$

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 sub-determined vertex. For instance, given the sub-determination ${\zeta}_{t}={\mathtt{011}}_{2}$, the matrix ${\mathbf{M}}_{\zeta t}\left(T\right)$ 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 ${\mathbf{M}}_{\zeta T}\left(T\right)$ for the sub-determination ${\zeta}_{T}={\mathtt{100}}_{2}$, where in this case each sub-determined result is the sum of values obtained for 6 composite vertices.

#### 4.2. 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 $\mathbb{H}$ is the quotient set of finite MAGs under isomorphism defined in Section 2.1. Note that a permutation σ of a given adjacency matrix $\mathbf{J}\left(H\right)$, together with the function ${D}_{\sigma}$, represents the same MAG H as $\mathbf{J}\left(H\right)$, so that permutations of adjacency matrices are isomorphic. Thus, we have the set $\mathbb{J}$, which is a quotient set of pairs $({\mathbf{J}}_{\sigma},{D}_{\sigma})$ of adjacency matrices and association functions D, under adjacency matrix permutations. Therefore, an element of $\mathbb{J}$ is an equivalence class of adjacency matrices and D functions. Since we consider the pair $\left(\mathbf{J}\right(H),\tau (H\left)\right)$ as the canonical adjacency matrix representation of the MAG H, we assign this pair as the class representative of the MAG H in $\mathbb{J}$.

**Theorem**

**1.**

The adjacency matrix $\mathbf{J}\left(H\right)$ and companion tuple $\tau \left(H\right)$ obtained from the MAG H by Algorithm 5 are isomorphic to the MAG H.

**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 $\mathbf{J}\left(H\right)$ and companion tuple $\tau \left(H\right)$, we can construct a MAG $\widehat{H}$ that is isomorphic to MAG H.

- ⟹Given the sets $\mathbb{H}$ and $\mathbb{J}$, Algorithm 5 can be seen as a function$$\begin{array}{c}\mathsf{{\rm Y}}:\mathbb{H}\to \mathbb{J}\phantom{\rule{3.0pt}{0ex}}\hfill \\ \phantom{\rule{3.33333pt}{0ex}}\phantom{\rule{3.33333pt}{0ex}}\phantom{\rule{3.33333pt}{0ex}}\phantom{\rule{3.33333pt}{0ex}}H\mapsto \left(\mathbf{J}\right(H),\tau (H\left)\right).\hfill \end{array}$$Considering the loop depicted at lines 5 to 9 in Algorithm 5, it can be seen that every edge $e\in E\left(H\right)$ is converted in a pair of composite vertices ($\mathbf{u}$ and $\mathbf{v}$) and then represented as an edge on the adjacency matrix $\mathbf{J}\left(H\right)$. Therefore, if the composite vertices $\mathbf{u}$ and $\mathbf{v}$ are adjacent in MAG H, then a entry 1 is present at the intersection of row $D(\mathbf{u},\tau (H\left)\right)$ and column $D(\mathbf{v},\tau (H\left)\right)$ of $\mathbf{J}\left(H\right)$, indicating the corresponding adjacency in the matrix. Hence, the adjacency structure of the MAG H is preserved by the function Υ.
- ⟸Given the adjacency matrix $\mathbf{J}\left(H\right)$ and companion tuple $\tau \left(H\right)$, we construct MAG $\widehat{H}$, which we then show to be isomorphic to the MAG H. We obtain $A(\widehat{H})$ from $\tau \left(H\right)$ by constructing a list $A(\widehat{H})$ with $p=\left|\tau \right(H\left)\right|$ elements, in which every element i of this list is a set such that $|A(\widehat{H})\left[i\right]|=\tau \left[i\right]$. Without loss of generality, we can assume that the elements of each aspect $A(\widehat{H})\left[i\right]$ are natural numbers ranging from 1 to $\tau \left[i\right]$. We then construct the edge set $E(\widehat{H})$, by starting with an empty set and then inserting an edge for each entry with value 1 in $\mathbf{J}\left(H\right)$. 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=({D}^{-1}(r,\tau \left(H\right)),{D}^{-1}(c,\tau \left(H\right))$, 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 $\mathbb{V}(\widehat{H})$ of composite vertices, which is the cartesian product of the sets in $A(\widehat{H})$, so that$$\mathbb{V}(\widehat{H})=\underset{n=1}{\overset{p}{\u2715}}A(\widehat{H})\left[n\right],$$We now show that the MAG $\widehat{H}$, constructed from $\mathbf{J}\left(H\right)$ and $\tau \left(H\right)$, is isomorphic to the original MAG H. Note that by construction of $\widehat{H}$ we have that $|E(\widehat{H})|=|E\left(H\right)|$; $|A(\widehat{H})|=|A\left(H\right)|=p$; for $1\le i\le p,|A(\widehat{H})\left[i\right]|=|A\left(H\right)\left[i\right]|$; $|\mathbb{V}(\widehat{H})|=|\mathbb{V}\left(H\right)|$; and $\tau (\widehat{H})=\tau \left(H\right)$.Since $\left|\mathbb{V}\left(H\right)\right|=|\mathbb{V}(\widehat{H})|$, we know that there is a bijective function from $\mathbb{V}(\widehat{H})$ to $\mathbb{V}\left(H\right)$. 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 $\mathbb{V}\left(H\right)$ and $\mathbb{V}(\widehat{H})$. Moreover, since $\tau (\widehat{H})=\tau \left(H\right)$ and by construction of D, we have that the range of D for $\mathbb{V}\left(H\right)$ and $\mathbb{V}(\widehat{H})$ is the same, i.e., $D(\mathbb{V}\left(H\right),\tau \left(H\right))=D(\mathbb{V}(\widehat{H}),\tau (\widehat{H}))$. From this, we conclude that, for every composite vertex $\mathbf{u}\in \mathbb{V}\left(H\right)$, there is one unique composite vertex $\widehat{\mathbf{u}}\in \mathbb{V}(\widehat{H})$ such that $D(\mathbf{u},\tau \left(H\right))=D(\widehat{\mathbf{u}},\tau (\widehat{H}))$. We thus define the bijective function$$\begin{array}{c}f:\mathbb{V}(\widehat{H})\to \mathbb{V}\left(H\right)\phantom{\rule{3.0pt}{0ex}}\hfill \\ \phantom{\rule{3.33333pt}{0ex}}\phantom{\rule{3.33333pt}{0ex}}\phantom{\rule{3.33333pt}{0ex}}\phantom{\rule{3.33333pt}{0ex}}\phantom{\rule{3.33333pt}{0ex}}\phantom{\rule{3.33333pt}{0ex}}\phantom{\rule{3.33333pt}{0ex}}\phantom{\rule{3.33333pt}{0ex}}\phantom{\rule{3.33333pt}{0ex}}\phantom{\rule{3.33333pt}{0ex}}\widehat{\mathbf{u}}\mapsto \mathbf{u},\phantom{\rule{4.pt}{0ex}}\mathrm{such}\phantom{\rule{4.pt}{0ex}}\mathrm{that}\phantom{\rule{4.pt}{0ex}}D(\widehat{\mathbf{u}},\tau (\widehat{H}))=D(\mathbf{u},\tau \left(H\right)).\hfill \end{array}$$As the function f is bijective, for every edge $\widehat{e}\in \widehat{H}$, we have an edge $e=(f\left({\pi}_{o}(\widehat{e})\right),$ $f\left({\pi}_{d}(\widehat{e})\right))\in E\left(H\right)$, and also, for every edge $e\in E\left(H\right)$, we have the corresponding edge $\widehat{e}=({f}^{-1}\left({\pi}_{o}\left(e\right)\right),{f}^{-1}\left({\pi}_{d}\left(e\right)\right))\in E(\widehat{H})$. This fulfils the conditions for isomorphism between $\widehat{H}$ and H.Since $\mathbb{H}$ is a quotient set under the MAG isomorphism relation and $\widehat{H}$ is isomorphic to H, it follows that $\widehat{H}$ and H correspond to the same element in $\mathbb{H}$, making the function Υ bijective. Also, since each entry with value 1 in the adjacency matrix $\mathbf{J}\left(H\right)$ corresponds to an edge in the MAG H, it follows that ${\mathsf{{\rm Y}}}^{-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 co-domain set can also be obtained from a matrix representation of the MAG.

**Proof.**

Consider the diagram depicted in Figure 5. In this figure, $\mathbb{H}$ is the set of all MAGs (up to isomorphism), $\mathbb{J}$ is the set of pairs of adjacency matrices and companion tuples (up to permutation), F is an arbitrary function from $\mathbb{H}$ to $\mathbb{X}$, where $\mathbb{X}$ is a codomain consistent with the definition of function F, and I is the identity function in $\mathbb{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 (33) in Theorem 1) and I represent isomorphisms, it follows that the depicted diagram commutes, so that for every function $F:\mathbb{H}\to \mathbb{X}$ there is a function $\widehat{F}:\mathbb{J}\to \mathbb{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 [15,35,36]. Therefore, Theorem 2 actually shows that any possible MAG function (algorithm) can be obtained from a matrix-based representation of a MAG. This is an important theoretical result since it paves the way for adapting well-known graph algorithms for application in MAGs. In the next subsections, we show examples of basic algorithms and functions that can be obtained from the matrix-based representation of a MAG.

#### 4.3. 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.

#### 4.3.1. Degree of Composite Vertices

The degree of composite vertices of a given MAG H can be obtained directly from its composite vertices representation, $g\left(H\right)$. 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 $\tau \left(H\right)$, the degrees of the composite vertices can be determined by Algorithm 8, where $D({\pi}_{o}\left(e\right),\tau \left(H\right))$ and $D({\pi}_{d}\left(e\right),\tau \left(H\right))$ stand for the numerical representation of the origin and destination composite vertices of edge $e\in E\left(H\right)$, as defined in Section 3.2.

Algorithm 8: Determination of the degree of composite vertices. |

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

$$indegree=\mathbf{J}{\left(H\right)}^{T}\phantom{\rule{4pt}{0ex}}\mathbf{1},$$

$$outdegree=\mathbf{J}\left(H\right)\phantom{\rule{4pt}{0ex}}\mathbf{1}.$$

Further, the total degree of the composite vertices can be obtained by summing up their indegrees and outdegrees.

To determine the time complexity of Algorithm 8, we consider that lines 2, 4, and 5 have each time complexity $O\left(\right|\mathbb{V}\left(H\right)\left|\right)$, the determination of the companion tuple at line 3 has complexity $O\left(p\right)$, where p is the number of aspects of the MAG, so that $p\ll \left|\mathbb{V}\right(H\left)\right|$. Finally, since the determination of the numerical representation of vertices has complexity $O\left(p\right)$, we have that the

**for**loop initiated at line 6 has complexity $O(p*|E\left(H\right)\left|\right)$, so that the time complexity of Algorithm 8 is $O\left(\right|\mathbb{V}\left(H\right)|+p*|E\left(H\right)\left|\right)$. 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 $O\left(\right|\mathbb{V}\left(H\right)|+|E\left(H\right)\left|\right)$.In the case of the example MAG T (Figure 3), whose companion tuple is $\tau =(3,2,3)$, it can be seen that the composite vertex $(2,Bus,t1)$ has outdegree 3 and indegree 1, while the composite vertex $(1,Subway,t2)$ has outdegree 2 and indegree 2. Since $D\left(\right(2,Bus,t1),\tau )=2$ and $D\left(\right(1,Subway,t2),\tau )=10$, it follows that $indegree\left[2\right]=1$, $outdegree\left[2\right]=3$, $indegree\left[10\right]=2$ and $outdegree\left[10\right]=2$.

#### 4.3.2. 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 $|{\mathbb{V}}_{\zeta}\left(H\right)|$ is the number of ζ sub-determined composite vertices on MAG H, ${S}_{\zeta}$ is the function that takes a composite vertex to its sub-determined form, and ${D}_{\zeta}$ 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.

Algorithm 9: Sub-determined degree. |

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
where ${\mathbf{M}}_{\zeta}\left(H\right)$ is the sub-determination matrix and $\mathbf{1}$ is the all 1s column vector, both defined in Section 4.1. Note that the multiplication by ${\mathbf{M}}_{\zeta}\left(H\right)$ adds the degrees of the composite vertices that are collapsed to the same sub-determined vertex.

$$indegree={\mathbf{M}}_{\zeta}\left(H\right)\phantom{\rule{4pt}{0ex}}\mathbf{J}{\left(H\right)}^{T}\phantom{\rule{4pt}{0ex}}\mathbf{1},$$

$$outdegree={\mathbf{M}}_{\zeta}\left(H\right)\phantom{\rule{4pt}{0ex}}\mathbf{J}\left(H\right)\phantom{\rule{4pt}{0ex}}\mathbf{1},$$

Algorithm 10: Sub-determined degree, separating self-loops |

The degrees calculated by Equations (38) and (39) include the self-loop edges. To obtain the separate self-loop degrees, first note that

$${\mathbf{M}}_{\zeta}\left(H\right)\phantom{\rule{4pt}{0ex}}\mathbf{J}\left(H\right)\phantom{\rule{4pt}{0ex}}{\mathbf{1}}_{n}={\mathbf{M}}_{\zeta}\left(H\right)\phantom{\rule{4pt}{0ex}}\mathbf{J}\left(H\right)\phantom{\rule{4pt}{0ex}}{\mathbf{M}}_{\zeta}{\left(H\right)}^{T}\phantom{\rule{4pt}{0ex}}{\mathbf{1}}_{m}.$$

This follows from the fact that
since ${\mathbf{M}}_{\zeta}{\left(H\right)}^{T}$ is a $n\times m$ rectangular matrix and has the property that each row has exactly one non-zero entry of value 1.

$${\mathbf{M}}_{\zeta}{\left(H\right)}^{T}\phantom{\rule{4pt}{0ex}}{\mathbf{1}}_{m}={\mathbf{1}}_{n},$$

Furthermore, note that the matrix ${\mathbf{M}}_{\zeta}\left(H\right)\phantom{\rule{4pt}{0ex}}\mathbf{J}\left(H\right)\phantom{\rule{4pt}{0ex}}{\mathbf{M}}_{\zeta}{\left(H\right)}^{T}$ is the adjacency matrix of the sub-determined MAG ${H}_{\zeta}$. 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 ${\mathbf{M}}_{\zeta}\left(H\right)\phantom{\rule{4pt}{0ex}}\mathbf{J}\left(H\right)\phantom{\rule{4pt}{0ex}}{\mathbf{M}}_{\zeta}{\left(H\right)}^{T}$ has the self-loop degree of each vertex. Hence,

$$selfdegree=Diag\left({\mathbf{M}}_{\zeta}\left(H\right)\phantom{\rule{4pt}{0ex}}\mathbf{J}\left(H\right)\phantom{\rule{4pt}{0ex}}{\mathbf{M}}_{\zeta}{\left(H\right)}^{T}\right).$$

For example, consider the example MAG T (Figure 3) and the sub-determination ${\zeta}_{t}={\mathtt{011}}_{2}$ defined in Section 4.1. We have that
and

$$indegree={\mathbf{M}}_{\zeta t}\left(T\right)\phantom{\rule{4pt}{0ex}}\mathbf{J}{\left(T\right)}^{T}\phantom{\rule{4pt}{0ex}}\mathbf{1}=\left[\begin{array}{c}\hfill 0\\ \hfill 7\\ \hfill 4\\ \hfill 4\\ \hfill 7\\ \hfill 0\end{array}\right],$$

$$outdegree={\mathbf{M}}_{\zeta t}\left(T\right)\phantom{\rule{4pt}{0ex}}\mathbf{J}\left(T\right)\phantom{\rule{4pt}{0ex}}\mathbf{1}=\left[\begin{array}{c}\hfill 0\\ \hfill 7\\ \hfill 4\\ \hfill 4\\ \hfill 7\\ \hfill 0\end{array}\right],$$

$${\mathbf{M}}_{\zeta t}\left(T\right)\phantom{\rule{4pt}{0ex}}\mathbf{J}\left(T\right)\phantom{\rule{4pt}{0ex}}{\mathbf{M}}_{\zeta t}{\left(T\right)}^{T}=\left[\begin{array}{cccccc}\hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0\\ \hfill 0& \hfill 2& \hfill 2& \hfill 0& \hfill 3& \hfill 0\\ \hfill 0& \hfill 2& \hfill 2& \hfill 0& \hfill 0& \hfill 0\\ \hfill 0& \hfill 0& \hfill 0& \hfill 2& \hfill 2& \hfill 0\\ \hfill 0& \hfill 3& \hfill 0& \hfill 2& \hfill 2& \hfill 0\\ \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0\end{array}\right],$$

$$selfdegree=Diag\left({\mathbf{M}}_{\zeta t}\left(T\right)\phantom{\rule{4pt}{0ex}}\mathbf{J}\left(T\right)\phantom{\rule{4pt}{0ex}}{\mathbf{M}}_{\zeta t}{\left(T\right)}^{T}\right)=\left[\begin{array}{c}\hfill 0\\ \hfill 2\\ \hfill 2\\ \hfill 2\\ \hfill 2\\ \hfill 0\end{array}\right].$$

This means that, for instance, the sub-determined composite vertex $(2,Subway)$ 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 ${\tau}_{{\zeta}_{t}}=(2,3)$, so that $D\left(\right(2,Subway),(2,3\left)\right)=\phantom{\rule{3.33333pt}{0ex}}2$, making it correspond to the second element of the degree column vector.

#### 4.3.3. 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 ${\zeta}_{T}={\mathtt{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
and

$$indegree={\mathbf{M}}_{\zeta T}\left(T\right)\phantom{\rule{4pt}{0ex}}\mathbf{J}{\left(T\right)}^{T}\phantom{\rule{4pt}{0ex}}\mathbf{1}=\left[\begin{array}{c}\hfill 2\\ \hfill 10\\ \hfill 10\end{array}\right],$$

$$outdegree={\mathbf{M}}_{\zeta T}\left(T\right)\phantom{\rule{4pt}{0ex}}\mathbf{J}\left(T\right)\phantom{\rule{4pt}{0ex}}\mathbf{1}=\left[\begin{array}{c}\hfill 10\\ \hfill 10\\ \hfill 2\end{array}\right],$$

$${\mathbf{M}}_{\zeta T}\left(T\right)\phantom{\rule{4pt}{0ex}}\mathbf{J}\left(T\right)\phantom{\rule{4pt}{0ex}}{\mathbf{M}}_{\zeta T}{\left(T\right)}^{T}=\left[\begin{array}{ccc}\hfill 2& \hfill 8& \hfill 0\\ \hfill 0& \hfill 2& \hfill 8\\ \hfill 0& \hfill 0& \hfill 2\end{array}\right],$$

$$selfdegree=Diag({\mathbf{M}}_{\zeta T}\left(T\right)\phantom{\rule{4pt}{0ex}}\mathbf{J}\left(T\right)\phantom{\rule{4pt}{0ex}}{\mathbf{M}}_{\zeta T}{\left(T\right)}^{T})=\left[\begin{array}{c}\hfill 2\\ \hfill 2\\ \hfill 2\end{array}\right].$$

Therefore, we have that ${\tau}_{{\zeta}_{T}}=\left(3\right)$, so that $D(\left({t}_{1}\right),\left(3\right))=1$, $D(\left({t}_{2}\right),\left(3\right))=2$, and $D(\left({t}_{3}\right),$ $\left(3\right))=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 (50). 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 (49). Further, the indegrees and outdegrees of each time instant are consistent with Equations (47) and (48).

#### 4.4. 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 sub-determined 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.

#### 4.4.1. BFS for Composite Vertices

The non sub-determined BFS in its combinational form is constructed directly upon the MAG’s adjacency matrix, $\mathbf{J}\left(H\right)$.

Algorithm 11: BFS for composite vertices. |

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 $\mathbf{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 $O\left(\right|\mathbb{V}\left(H\right)|+|E\left(H\right)\left|\right)$.

BFS is also closely related to matrix multiplication. This stems from the well-known property of the powers of the adjacency matrix, in which the $(i,j)$ 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 [33]. From this, we could think that for a given MAG H, the series
would produce a matrix $\mathbf{B}$, such that the entry ${\mathbf{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 $\mathbf{J}\left(H\right)$ a nilpotent matrix.

$$\mathbf{B}=\sum _{i=0}^{\infty}\mathbf{J}{\left(H\right)}^{i}=\mathbf{I}+\mathbf{J}\left(H\right)+\mathbf{J}{\left(H\right)}^{2}+\mathbf{J}{\left(H\right)}^{3}+\mathbf{J}{\left(H\right)}^{4}+\cdots $$

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 (51) 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 $\mathbf{J}\left(H\right)$ by a scalar ${\rho}_{H}$, such that
where $\rho \left(\mathbf{J}\right(H\left)\right)$ is the spectral radius of the matrix $\mathbf{J}\left(H\right)$. This leads to the matrix
so that the spectral radius of the matrix ${\mathbf{J}}_{\rho}\left(H\right)<1$. This results that Equation (51) constructed with the matrix ${\mathbf{J}}_{\rho}\left(H\right)$ converges. Since the convergence of the series is assured, Equation (51) can be re-expressed as

$${\rho}_{H}<\frac{1}{\rho \left(\mathbf{J}\right(H\left)\right)},$$

$${\mathbf{J}}_{\rho}\left(H\right)={\rho}_{H}\phantom{\rule{4pt}{0ex}}\mathbf{J}\left(H\right),$$

$$\mathbf{B}={(I-{\mathbf{J}}_{\rho}\left(H\right))}^{-1}.$$

The matrix $\mathbf{B}$ defined in Equation (54) has the property that, for any given composite vertex $\mathbf{v}\in \mathbb{V}\left(H\right)$, the row $D\left(\mathbf{v}\right)$ of $\mathbf{B}$ has non-zero entries in every column that corresponds to a composite vertex $\mathbf{u}\in \mathbb{V}\left(H\right)$, such that $\mathbf{u}$ is reachable from $\mathbf{v}$. Hence, for a given composite vertex $\mathbf{v}$, the row $D\left(\mathbf{v}\right)$ corresponds to the result of a BFS started at that composite vertex. Although the matrix $\mathbf{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. To avoid such difficulties, it is also possible to express a BFS for a single composite vertex $\mathbf{v}$ as
where ${r}_{\mathbf{v}}$ is the row vector with n entries for which all entries except $D(\mathbf{v},\tau )$ are 0 and the entry $D(\mathbf{v},\tau )$ is 1.

$$\mathbf{B}={r}_{\mathbf{v}}\mathbf{I}+{r}_{\mathbf{v}}{\mathbf{J}}_{\rho}\left(H\right)+{r}_{\mathbf{v}}{\mathbf{J}}_{\rho}{\left(H\right)}^{2}+{r}_{\mathbf{v}}{\mathbf{J}}_{\rho}{\left(H\right)}^{3}+{r}_{\mathbf{v}}{\mathbf{J}}_{\rho}{\left(H\right)}^{4}+\cdots ,$$

Considering the example MAG T, shown in Figure 3, the result of the BFS using Algorithm 11 for the composite vertex $(2,Bus,{t}_{1})$, whose numerical representation is $D((2,Bus,{t}_{1}),(3,2,3))=2$, is
where the list $vertices$ shows the composite vertices accessible from $(2,Bus,{t}_{1})$, 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 $(2,Bus,{t}_{1})$ to all possible destinations (with ∞ meaning that a destination is not reachable). The list $pred$ shows the predecessors of each composite vertex, making possible to construct a BFS tree.

$$\begin{array}{c}\phantom{\rule{3.33333pt}{0ex}}\phantom{\rule{3.33333pt}{0ex}}vertices=[2,5,8,9,10,11,14,15,16,17]\phantom{\rule{3.0pt}{0ex}}\hfill \\ distances=[\infty ,0,\infty ,\infty ,1,\infty ,\infty ,1,1,2,2,\infty ,\infty ,2,2,3,3,\infty ]\phantom{\rule{3.0pt}{0ex}}\hfill \\ \phantom{\rule{3.33333pt}{0ex}}\phantom{\rule{3.33333pt}{0ex}}\phantom{\rule{3.33333pt}{0ex}}\phantom{\rule{3.33333pt}{0ex}}\phantom{\rule{3.33333pt}{0ex}}\phantom{\rule{3.33333pt}{0ex}}pred=[Nil,Nil,Nil,Nil,2,Nil,Nil,2,2,5,5,Nil,Nil,8,8,10,10,Nil],\hfill \end{array}$$

#### 4.4.2. 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 sub-determined 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 paths and walks on the sub-determined MAG that do not actually exist on the original MAG. To illustrate this, we present Figure 6a,b, which show a small two aspects MAG and its sub-determined form, obtained by the sub-determination ${\zeta}_{R}={\mathtt{01}}_{2}$. First, note that, in the MAG R shown in Figure 6a, there is no path originating from the composite vertices $(1,1)$ or $(1,2)$ to the composite vertices $(3,1)$ or $(3,2)$. Nevertheless, in Figure 6b, there is a path connecting the sub-determined vertex $\left(1\right)$ to the sub-determined vertex $\left(3\right)$, even though such connection is not possible on the original MAG shown in Figure 6a. Therefore, 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

$${\mathbf{M}}_{\zeta}\left(H\right)\phantom{\rule{4pt}{0ex}}\left(\sum _{i=0}^{\infty}{\mathbf{J}}_{\rho}{\left(H\right)}^{i}\right)\phantom{\rule{4pt}{0ex}}{\mathbf{M}}_{\zeta}{\left(H\right)}^{T}\ne \sum _{i=0}^{\infty}{\left({\mathbf{M}}_{\zeta}\left(H\right)\phantom{\rule{4pt}{0ex}}{\mathbf{J}}_{\rho}\left(H\right)\phantom{\rule{4pt}{0ex}}{\mathbf{M}}_{\zeta}{\left(H\right)}^{T}\right)}^{i}.$$

To see that the Inequality (57) holds, note that an arbitrary power of the matrix $\phantom{\rule{4pt}{0ex}}{\mathbf{M}}_{\zeta}\left(H\right)$ $\phantom{\rule{4pt}{0ex}}{\mathbf{J}}_{\rho}\left(H\right)\phantom{\rule{4pt}{0ex}}{\mathbf{M}}_{\zeta}{\left(H\right)}^{T}$ is given by
where $\left({\mathbf{M}}_{\zeta}\left(H\right)\phantom{\rule{4pt}{0ex}}{\mathbf{J}}_{\rho}\left(H\right)\phantom{\rule{4pt}{0ex}}{\mathbf{M}}_{\zeta}{\left(H\right)}^{T}\right)$ is multiplied n times. Note, however, that
since ${\mathbf{M}}_{\zeta}\left(H\right)\in {\mathbb{R}}^{m\times n}$ is a retangular matrix and $m<n$, so that the rank of the matrix ${\mathbf{M}}_{\zeta}{\left(H\right)}^{T}\phantom{\rule{4pt}{0ex}}{\mathbf{M}}_{\zeta}\left(H\right)$ is less or equal to m, while the rank of the identity ${\mathbf{I}}_{n}$ is $n>m$. Since Inequality (59) holds, so does the Inequality (57).

$${\left({\mathbf{M}}_{\zeta}\left(H\right){\mathbf{J}}_{\rho}\left(H\right){\mathbf{M}}_{\zeta}{\left(H\right)}^{T}\right)}^{n}=\underset{\mathrm{n}\mathrm{times}}{\underbrace{{\mathbf{M}}_{\zeta}\left(H\right){\mathbf{J}}_{\rho}\left(H\right){\mathbf{M}}_{\zeta}{\left(H\right)}^{T}\phantom{\rule{4pt}{0ex}}{\mathbf{M}}_{\zeta}\left(H\right){\mathbf{J}}_{\rho}\left(H\right){\mathbf{M}}_{\zeta}{\left(H\right)}^{T}\cdots}},$$

$${\mathbf{M}}_{\zeta}{\left(H\right)}^{T}\phantom{\rule{4pt}{0ex}}{\mathbf{M}}_{\zeta}\left(H\right)\ne {\mathbf{I}}_{n},$$

Here, the left hand side of the Inequality (57) 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}_{\zeta}$.

In the case of the MAG R, shown in Figure 6a, we have that the sub-determination is given by ${\zeta}_{R}={\mathtt{01}}_{2}$ and the adjacency and sub-determination matrices are
and

$$\mathbf{J}\left(R\right)=\left[\begin{array}{cccccc}\hfill 0& \hfill 0& \hfill 0& \hfill \mathbf{1}& \hfill 0& \hfill 0\\ \hfill 0& \hfill 0& \hfill \mathbf{1}& \hfill 0& \hfill \mathbf{1}& \hfill 0\\ \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill \mathbf{1}\\ \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill \mathbf{1}& \hfill 0\\ \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0\\ \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0\end{array}\right],$$

$${\mathbf{M}}_{{\zeta}_{R}}\left(R\right)=\left[\begin{array}{cccccc}\hfill \mathbf{1}& \hfill 0& \hfill 0& \hfill \mathbf{1}& \hfill 0& \hfill 0\\ \hfill 0& \hfill \mathbf{1}& \hfill 0& \hfill 0& \hfill \mathbf{1}& \hfill 0\\ \hfill 0& \hfill 0& \hfill \mathbf{1}& \hfill 0& \hfill 0& \hfill \mathbf{1}\end{array}\right],$$

$${\mathbf{J}}_{{\zeta}_{R}}\left(R\right)=\left[\begin{array}{ccc}\hfill 0& \hfill \mathbf{1}& \hfill 0\\ \hfill 0& \hfill 0& \hfill \mathbf{1}\\ \hfill 0& \hfill 0& \hfill 0\end{array}\right].$$

Therefore, we have that
while
and

$${\mathbf{M}}_{{\zeta}_{R}}\left(R\right)\phantom{\rule{4pt}{0ex}}\left(\sum _{i=0}^{\infty}{\mathbf{J}}_{\rho}{\left(R\right)}^{i}\right)\phantom{\rule{4pt}{0ex}}{\mathbf{M}}_{{\zeta}_{R}}{\left(R\right)}^{T}=\left[\begin{array}{ccc}\hfill 3& \hfill 2& \hfill \mathbf{0}\\ \hfill 0& \hfill 3& \hfill 2\\ \hfill 0& \hfill 0& \hfill 3\end{array}\right],$$

$$\sum _{i=0}^{\infty}{\left({\mathbf{M}}_{{\zeta}_{R}}\left(R\right)\phantom{\rule{4pt}{0ex}}{\mathbf{J}}_{\rho}\left(R\right)\phantom{\rule{4pt}{0ex}}{\mathbf{M}}_{{\zeta}_{R}}{\left(R\right)}^{T}\right)}^{i}=\left[\begin{array}{ccc}\hfill 2& \hfill 2& \hfill \mathbf{2}\\ \hfill 0& \hfill 2& \hfill 2\\ \hfill 0& \hfill 0& \hfill 2\end{array}\right]$$

$${\left({\mathbf{I}}_{3}-{\mathbf{J}}_{{\zeta}_{R}}\left(R\right)\right)}^{-1}=\left[\begin{array}{ccc}\hfill 1& \hfill 1& \hfill \mathbf{1}\\ \hfill 0& \hfill 1& \hfill 1\\ \hfill 0& \hfill 0& \hfill 1\end{array}\right].$$

Remembering that the entries of the matrices in Equations (63)–(65) are to be considered only as zero or non-zero, it can be seen that the matrix at Equation (63) has a 0 at entry $(1,3)$, while the matrices at Equations (64) and (65) 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 (64) and (65), 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 ${\zeta}_{t}={\mathtt{011}}_{2}$, which drops the time aspect, and considering ${\rho}_{H}=0.5$ so that ${\mathbf{J}}_{\rho}\left(T\right)=0.5\phantom{\rule{4pt}{0ex}}\mathbf{J}\left(T\right)$, we have that

$${\mathbf{M}}_{\zeta t}\left(T\right)\phantom{\rule{4pt}{0ex}}\left(\sum _{i=0}^{\infty}{\mathbf{J}}_{\rho}{\left(T\right)}^{i}\right)\phantom{\rule{4pt}{0ex}}{\mathbf{M}}_{\zeta t}{\left(T\right)}^{T}=\left[\begin{array}{cccccc}\hfill 3& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0\\ \hfill 0& \hfill 7.8& \hfill 2.2& \hfill 1.3& \hfill 5.2& \hfill 0\\ \hfill 0& \hfill 2.2& \hfill 4.6& \hfill 0.2& \hfill 1.3& \hfill 0\\ \hfill 0& \hfill 1.3& \hfill 0.2& \hfill 4.6& \hfill 2.2& \hfill 0\\ \hfill 0& \hfill 5.2& \hfill 1.3& \hfill 2.2& \hfill 7.8& \hfill 0\\ \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 0& \hfill 3\end{array}\right].$$

Algorithm 12 shows a combinational version of the sub-determined BFS. This procedure ensures that only paths present on the original MAG are considered on the sub-determined BFS. The sub-determination of the results obtained from the BFS is done in the internal

**if**, comprising lines 21 to 25 of Algorithm 12.Algorithm 12: Sub-determined BFS. |

After applying Algorithm 12 to the MAG R with initial vertex $s=1$ and sub-detemination ${\zeta}_{R}={\mathtt{01}}_{2}$, the obtained result is
which is consistent with the result obtained by Equation (63).

$$\begin{array}{c}\phantom{\rule{3.33333pt}{0ex}}\phantom{\rule{3.33333pt}{0ex}}\phantom{\rule{3.33333pt}{0ex}}vertices=[1,2]\phantom{\rule{3.0pt}{0ex}}\hfill \\ distances=[0,1,\infty ]\phantom{\rule{3.0pt}{0ex}}\hfill \\ \phantom{\rule{3.33333pt}{0ex}}\phantom{\rule{3.33333pt}{0ex}}\phantom{\rule{3.33333pt}{0ex}}\phantom{\rule{3.33333pt}{0ex}}\phantom{\rule{3.33333pt}{0ex}}\phantom{\rule{3.33333pt}{0ex}}\phantom{\rule{3.33333pt}{0ex}}pred=[Nil,1,Nil],\hfill \end{array}$$

Further, applying Algorithm 12 to MAG T, shown in Figure 3, with starting composite vertex $s=(2,Bus)$ and applying the sub-determination ${\zeta}_{t}={\mathtt{011}}_{2}$, which drops the time aspect, the obtained result is

$$\begin{array}{c}\phantom{\rule{3.33333pt}{0ex}}\phantom{\rule{3.33333pt}{0ex}}vertices=[2,5,3,4]\phantom{\rule{3.0pt}{0ex}}\hfill \\ distances=[\infty ,0,1,2,1,\infty ]\phantom{\rule{3.0pt}{0ex}}\hfill \\ \phantom{\rule{3.33333pt}{0ex}}\phantom{\rule{3.33333pt}{0ex}}\phantom{\rule{3.33333pt}{0ex}}\phantom{\rule{3.33333pt}{0ex}}\phantom{\rule{3.33333pt}{0ex}}\phantom{\rule{3.33333pt}{0ex}}\phantom{\rule{3.33333pt}{0ex}}pred=[Nil,Nil,2,5,2,Nil].\hfill \end{array}$$

Considering that ${\tau}_{{\zeta}_{t}}=(3,2)$ and $2=D\left(\right(2,Bus),(3,2\left)\right),5=D\left(\right(2,Subway),(3,2\left)\right)$, $3\phantom{\rule{3.33333pt}{0ex}}=\phantom{\rule{3.33333pt}{0ex}}D\left(\right(3,Bus),(3,2\left)\right)$, and $1=D\left(\right(1,Subway),(3,2\left)\right)$, this means that disregarding time, starting from $(2,Bus)$ it is possible to reach $(2,Subway)$ in 1 step, $(1,Subway)$ in 2 steps, and $(3,Bus)$ in 1 step. It is not possible to reach $(1,Bus)$ because there is no bus stop at location 1, neither $(3,Subway)$ because there is no subway station at location 3. From the predecessor list ($pred$) it is possible to build a BFS tree, where $(2,Bus)$ is the root, $(2,Subway)$ and $(3,Bus)$ are children of $(2,Bus)$, and $(1,Subway)$ is a child of $(2,Subway)$. Note that $(1,Subway)$ and $(3,Bus)$ are leaves. It can be seen that the result obtained in Equation (66) is consistent with the results obtained by Algorithm 12. Comparing Algorithm 12 to Algorithm 11, it can be seen that the main difference is the additional

**for**loop at line 12 of Algorithm 12. Since the time complexity of this loop is $O\left(\right|\mathbb{V}\left(H\right)\left|\right)$, we then conclude that the time complexity of Algorithm 12 is $O\left(\right|\mathbb{V}\left(H\right)|+|E\left(H\right)\left|\right)$.#### 4.5. 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.

#### 4.5.1. DFS for Composite Vertices

The composite vertices implementation is constructed using the MAG’s adjacency matrix $\mathbf{J}\left(H\right)$ and companion tuple $\tau \left(H\right)$. 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 $O\left(\right|\mathbb{V}\left(H\right)|+|E\left(H\right)\left|\right)$.

When applied to MAG T, shown in Figure 3, the DFS algorithm generates the result
where the list d carries the discovery time of each composite vertex, the list f the respective finish time of each composite vertex, and $pred$ the predecessor list of each composite vertex.

$$\begin{array}{c}\phantom{\rule{3.33333pt}{0ex}}\phantom{\rule{3.33333pt}{0ex}}\phantom{\rule{3.33333pt}{0ex}}\phantom{\rule{3.33333pt}{0ex}}\phantom{\rule{3.33333pt}{0ex}}d=[0,2,22,24,3,26,28,13,19,4,12,30,32,8,14,5,7,34]\phantom{\rule{3.0pt}{0ex}}\hfill \\ \phantom{\rule{3.33333pt}{0ex}}\phantom{\rule{3.33333pt}{0ex}}\phantom{\rule{3.33333pt}{0ex}}\phantom{\rule{3.33333pt}{0ex}}\phantom{\rule{3.33333pt}{0ex}}f=[1,21,23,25,18,27,29,16,20,11,17,31,33,9,15,6,10,35]\phantom{\rule{3.0pt}{0ex}}\hfill \\ pred=[Nil,Nil,Nil,Nil,2,Nil,Nil,11,2,5,5,Nil,Nil,17,8,10,10,Nil],\hfill \end{array}$$

#### 4.5.2. 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 to determine the reachability of sub-determined vertices from the root of each sub-determined DFS tree. This is necessary to prevent including vertices not reachable from the tree root in the non sub-determined MAG into the DFS trees constructed by Procedure Visit-DFS-Sub. An example of this is provided in Equation (71). 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.

Algorithm 13: DFS for composite vertices. |

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 sub-determined BFS algorithm is $O\left(\right|\mathbb{V}\left(H\right)|+|E\left(H\right)\left|\right)$. 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 $O\left(1\right)$ 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 $O\left(\right|{\mathbb{V}}_{\zeta}\left(H\right)|+|{E}_{\zeta}\left(H\right)\left|\right)$. Since $|{\mathbb{V}}_{\zeta}\left(H\right)|<|\mathbb{V}\left(H\right)|$ and $|{E}_{\zeta}\left(H\right)|<|E\left(H\right)|$, 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 $O\left(\right|\mathbb{V}\left(H\right)|+|E\left(H\right)\left|\right)$.

Algorithm 14: Sub-determined DFS. |

When applying the sub-determined DFS algorithm to the example MAG T shown in Figure 3 with a sub-determination ${\zeta}_{t}={\mathtt{011}}_{2}$, which drops the time aspect, the obtained result is
where the list d carries the discovery time of each sub-determined composite vertex, the list f its finish time and $pred$ its predecessor.

$$\begin{array}{c}\phantom{\rule{3.33333pt}{0ex}}\phantom{\rule{3.33333pt}{0ex}}\phantom{\rule{3.33333pt}{0ex}}\phantom{\rule{3.33333pt}{0ex}}d=[0,2,3,6,5,10]\phantom{\rule{3.0pt}{0ex}}\hfill \\ \phantom{\rule{3.33333pt}{0ex}}\phantom{\rule{3.33333pt}{0ex}}\phantom{\rule{3.33333pt}{0ex}}\phantom{\rule{3.33333pt}{0ex}}f=[1,9,4,7,8,11]\phantom{\rule{3.0pt}{0ex}}\hfill \\ pred=[Nil,Nil,2,5,2,Nil],\hfill \end{array}$$

Considering the MAG R shown in Figure 6a with a sub-determination ${\zeta}_{R}={\mathtt{01}}_{2}$, the result obtained by Algorithm 14 is

$$\begin{array}{c}\phantom{\rule{3.33333pt}{0ex}}\phantom{\rule{3.33333pt}{0ex}}\phantom{\rule{3.33333pt}{0ex}}\phantom{\rule{3.33333pt}{0ex}}\phantom{\rule{3.33333pt}{0ex}}d=[0,1,4]\phantom{\rule{3.0pt}{0ex}}\hfill \\ \phantom{\rule{3.33333pt}{0ex}}\phantom{\rule{3.33333pt}{0ex}}\phantom{\rule{3.33333pt}{0ex}}\phantom{\rule{3.33333pt}{0ex}}\phantom{\rule{3.33333pt}{0ex}}f=[3,2,5]\phantom{\rule{3.0pt}{0ex}}\hfill \\ pred=[Nil,1,Nil].\hfill \end{array}$$

It can be seen that even though in the MAG R sub-determined by ${\zeta}_{R}={\mathtt{01}}_{2}$ (see Figure 6b) there is a path from vertex 1 to 3, vertex 3 is not in the same DFS tree as vertices 1 and 2, even with the DFS starting at vertex 1, as can be seen in $d\left[0\right]$. This occurs because in MAG R (with no sub-determination) there is no path connecting the composite vertex 1 to the composite vertex 3.

## 5. 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 [18]) 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. We have chosen to present the algebraic representation in matrix form since it is well accepted and known, thus contributing to the readability of the paper. Nevertheless, given the isomorphism property of MAGs, any representation form available for directed graphs can also be used for MAGs, including matrices as used here for convenience or sorted adjacency lists, for instance, that are a common representation of graphs in existing network analysis packages. 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. These basic graph 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 graphs. 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.

The discussed basic algorithms can be used as building blocks for other purposes, thus allowing the extension of the MAG applicability. Concerning algorithm complexity, given the isomorphism between a MAG and a traditional directed graph, we expect MAG algorithms to have the same complexity as the equivalent algorithms for traditional directed graphs. For instance, if the MAG algorithm is derived from a given traditional algorithm that is polynomial for traditional graphs, the resulting algorithm for MAGs will be polynomial in the size of the composite vertices representation of the MAG.

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 real-world applications represented by high order complex networked systems.

## Acknowledgments

This work was partially funded by the Brazilian funding agencies CAPES (STIC-AmSud Program), CNPq, FINEP, and FAPERJ as well as the Brazilian Ministry of Science, Technology, Innovations, and Communications (MCTIC).

## Author Contributions

The problem definition, theoretical analysis, and algorithm design were performed jointly by all authors; Klaus Wehmuth derived the theorems and implemented the algorithms depicted in the paper. All authors read and approved the final manuscript.

## Conflicts of Interest

The authors declare no conflict of interest.

## References

- Distel, R. Graph Theory, 4th ed.; Springer: Berlin/Heidelberg, Germany, 2010. [Google Scholar]
- Jansson, J. Special Issue on Graph Algorithms. Algorithms
**2013**, 6, 457–458. [Google Scholar] [CrossRef] - Deo, N. Graph Theory with Applications to Engineering and Computer Science, 1st ed.; Dover Publications: Mineola, NY, USA, 2016. [Google Scholar]
- Tarjan, R. Depth-First Search and Linear Graph Algorithms. SIAM J. Comput.
**1972**, 1, 146–160. [Google Scholar] [CrossRef] - Cormen, T.H.; Stein, C.; Rivest, R.L.; Leiserson, C.E. Introduction to Algorithms, 3rd ed.; MIT Press: Cambridge, MA, USA, 2009. [Google Scholar]
- Friedkin, N.E. Theoretical foundations for centrality measures. Am. J. Sociol.
**1991**, 96, 1478–1504. [Google Scholar] [CrossRef] - Wehmuth, K.; Ziviani, A. Distributed location of the critical nodes to network robustness based on spectral analysis. In Proceedings of the IEEE Latin American Network Operations and Management Symposium (LANOMS), João Pessoa, Brazil, 1–3 October 2011; pp. 1–8.
- Takes, F.W.; Kosters, W.A. Computing the Eccentricity Distribution of Large Graphs. Algorithms
**2013**, 6, 100–118. [Google Scholar] [CrossRef] - Wehmuth, K.; Ziviani, A. DACCER: Distributed Assessment of the Closeness CEntrality Ranking in complex networks. Comput. Netw.
**2013**, 57, 2536–2548. [Google Scholar] [CrossRef] - Watts, D.; Strogatz, S.H. Collective dynamics of small-world networks. Nature
**1998**, 393, 440–442. [Google Scholar] [CrossRef] [PubMed] - Barabási, A.L.; Albert, R. Emergence of Scaling in Random Networks. Science
**1999**, 286, 509–512. [Google Scholar] [PubMed] - Pastor-Satorras, R.; Vespignani, A. Epidemic Spreading in Scale-Free Networks. Phys. Rev. Lett.
**2001**, 86, 3200–3203. [Google Scholar] [CrossRef] [PubMed] - Guimarães, A.; Vieira, A.B.; da Silva, A.P.C.; Ziviani, A. Fast Centrality-driven Diffusion in Dynamic Networks. In Proceedings of the 5th Annual Workshop on Simplifying Complex Networks for Practitioners, Rio de Janeiro, Brazil, 13–17 May 2013; pp. 821–828.
- Kurant, M.; Thiran, P. Layered Complex Networks. Phys. Rev. Lett.
**2006**, 96. [Google Scholar] [CrossRef] [PubMed] - Kivelä, M.; Arenas, A.; Barthelemy, M.; Gleeson, J.P.; Moreno, Y.; Porter, M.A. Multilayer networks. J. Complex Netw.
**2014**, 2, 203–271. [Google Scholar] [CrossRef] - Leskovec, J.; Kleinberg, J.; Faloutsos, C. Graphs over Time: Densification Laws, Shrinking Diameters and Possible Explanations. In Proceedings of the 22nd SIGKDD Conference on Knowledge Discovery and Data Mining, San Francisco, CA, USA, 13–17 August 2016; pp. 177–187.
- Holme, P.; Saramäki, J. Temporal networks. Phys. Rep.
**2012**, 519, 97–125. [Google Scholar] [CrossRef] - Wehmuth, K.; Fleury, E.; Ziviani, A. On MultiAspect graphs. Theor. Comput. Sci.
**2016**, 651, 50–61. [Google Scholar] [CrossRef] - Scholtes, I.; Wider, N.; Garas, A. Higher-order aggregate networks in the analysis of temporal networks: Path structures and centralities. Eur. Phys. J. B
**2016**, 89, 1–15. [Google Scholar] [CrossRef] - Benson, A.R.; Gleich, D.F.; Leskovec, J. Higher-order organization of complex networks. Science
**2016**, 353, 163–166. [Google Scholar] [CrossRef] [PubMed] - Lucet, J.C.; Laouenan, C.; Chelius, G.; Veziris, N.; Lepelletier, D.; Friggeri, A.; Abiteboul, D.; Bouvet, E.; Mentre, F.; Fleury, E. Electronic Sensors for Assessing Interactions between Healthcare Workers and Patients under Airborne Precautions. PLoS ONE
**2012**, 7. [Google Scholar] [CrossRef] [PubMed] - Xavier, F.H.Z.; Silveira, L.M.; Almeida, J.M.; Ziviani, A.; Malab, C.H.S.; Marques-Neto, H.T. Analyzing the Workload Dynamics of a Mobile Phone Network in Large Scale Events. In Proceedings of the First Workshop on Urban Networking (UrbaNe), Nice, France, 10–13 December 2012; pp. 37–42.
- Blondel, V.D.; Decuyper, A.; Krings, G. A survey of results on mobile phone datasets analysis. EPJ Data Sci.
**2015**, 4, 1–55. [Google Scholar] [CrossRef] - Karlebach, G.; Shamir, R. Modelling and analysis of gene regulatory networks. Nat. Rev. Mol. Cell Biol.
**2008**, 9, 770–780. [Google Scholar] [CrossRef] [PubMed] - Yang, H.; Bell, M.G.; Meng, Q. Modeling the capacity and level of service of urban transportation networks. Transp. Res. Part B Methodol.
**2000**, 34, 255–275. [Google Scholar] [CrossRef] - Bullmore, E.; Sporns, O. Complex brain networks: graph theoretical analysis of structural and functional systems. Nat. Rev. Neurosci.
**2009**, 10, 186–198. [Google Scholar] [CrossRef] [PubMed] - De Domenico, M.; Sasai, S.; Arenas, A. Mapping Multiplex Hubs in Human Functional Brain Networks. Front. Neurosci.
**2016**, 10. [Google Scholar] [CrossRef] [PubMed] - Szell, M.; Lambiotte, R.; Thurner, S. Multirelational organization of large-scale social networks in an online world. Proc. Natl. Acad. Sci. USA
**2010**, 107, 13636–13641. [Google Scholar] [CrossRef] [PubMed] - Wehmuth, K.; Ziviani, A.; Fleury, E. A unifying model for representing time-varying graphs. In Proceedings of the IEEE International Conference on Data Science and Advanced Analytics (DSAA), Paris, France, 19–21 October 2015; pp. 1–10.
- Costa, E.C.; Vieira, A.B.; Wehmuth, K.; Ziviani, A.; da Silva, A.P.C. Time Centrality in Dynamic Complex Networks. Adv. Complex Syst.
**2015**, 18. [Google Scholar] [CrossRef] - Sarraute, C.; Brea, J.; Burroni, J.; Wehmuth, K.; Ziviani, A.; Alvarez-Hamelin, J.I. Social Events in a Time-Varying Mobile Phone Graph. In Proceedings of the International Conference on the Scientific Analysis of Mobile Phone Datasets (NetMob), Cambridge, MA, USA, 8–10 April 2015.
- Bang-Jensen, J.; Gutin, G.Z. Digraphs: Theory, Algorithms and Applications, 2nd ed.; Springer: London, UK, 2009. [Google Scholar]
- Kepner, J.; Gilbert, J. Graph Algorithms in the Language of Linear Algebra; SIAM: Philadelphia, PA, USA, 2011. [Google Scholar]
- Bapat, R.B. Graphs and Matrices, 2nd ed.; Springer: London, UK, 2014. [Google Scholar]
- De Domenico, M.; Solé-Ribalta, A.; Cozzo, E.; Kivelä, M.; Moreno, Y.; Porter, M.; Gómez, S.; Arenas, A. Mathematical Formulation of Multilayer Networks. Phys. Rev. X
**2013**, 3. [Google Scholar] [CrossRef] - Domenico, M.D.; Granell, C.; Porter, M.A.; Arenas, A. The physics of spreading processes in multilayer networks. Nat. Phys.
**2016**, 12, 901–906. [Google Scholar] [CrossRef]

© 2016 by the authors. Licensee MDPI, Basel, Switzerland. This article is an open access article distributed under the terms and conditions of the Creative Commons Attribution (CC BY) license ( http://creativecommons.org/licenses/by/4.0/).