# A Simulation of Contact Graph Routing for Mars-Earth Data Communication
## 2 Model of CGR
### Plotting the Graph  
For plotting directed graphs, the variable \(x\) must be transformed into certain routes in various time intervals. Let us see an example for minute \(t\). Matrix \(x\) has zero entries except in the following positions and their representation.  
1. \(x(1,2,1,1)=1\) means \(r=2\), and \(x(2,19,1,1)=1\) means \(r=19\), so packet-1 is delivered in routes \(1\to 3\to 7\);\(x(1,3,2,1)=1\) means \(r=3\), and \(x(2,26,2,1)=1\) means \(r=26\), so packet-2 is delivered in routes \(1\to 4\to 9\);
3. \(x\ (2,24,3,1)=1\) means \(r=24\), so packet-3 is delivered in route \(4\to 7\);
4. \(x(2,26,4,1)=1\) where \(r=26\), so packet-3 is delivered in route \(4\to 9\). No. 3 and 4 are deliveries of stored data from the previous minutes. To plot a directed graph, we must specify two collections of edges. The nodes that indicate routes from a satellite and a rover are collected by _frstedges_, and the nodes that indicate paths from a satellite and a DSN antenna are collected by _scndedges_. First, we collect all the indices of rows and columns of \(x\) which have non-zero entries, or one to be specific. Note that the first dimension of \(x\) is \(p\), and its second dimension is the route label owned by data packet-1 to data packet-\(n_{d}(t)\). The resulting information is defined as a matrix _ldxmat_. So, this matrix has two columns; the first column is the step of \(p\) and the accumulated label of the route being considered. From the example in the above paragraphs \[ldxmat=\begin{pmatrix}1&2\\ 2&19\\ 1&39\\ 2&62\\ 2&96\\ 2&98\end{pmatrix}\] (14) Remember that we have \(r\) with \(r=1,2,dots,36\). Packet-2, in the example, or no.2, has \(r=3\) and \(r=26\). The indices become \(r=3+36=39\) and \(r=26+36=62\), respectively, in rows 3 and 4 of the matrix. The accumulated labels of packet-3 have an additional \(36\times 2=72\) for the labels \(r=24\) and \(r=26\), respectively. To transform them into the original value of a route label between 1 and 36, we first use the command _mod_ to compute the remainder when the value is divided by 36. Later, they are interpreted as the indices of rovers \(i=1,2\) and satellites \(j=3,4,5,6\) using Equation (13), and indices of DSN antennas \(k=7,8,9\), using the following equation. \[k=r+j-ids(j),\text{ if }ids(j)\leq r<ids(j+1).\] (15)  
Now, let \(r_{one}\) be a vector containing indices of _ldxmax_ in (14) whose first column entry is 1, which means routes between a rover and a satellite. Also, define \(r_{two}\) to be a vector containing indices of _ldxmax_ in (14) whose first column entry is 2, which means routes between a satellite and a DSN antenna. If the size of \(r_{one}\) is greater than the size of \(r_{two}\), then there are data being sent and stored to some satellites. If the size of \(r_{one}\) is less than the size of \(r_{two}\), then there are additional routes for delivering stored data. Finally, we put all \(r_{one}\) in _frstedges_, and all \(r_{two}\) in _scndedges_. From the example above, we have  
\[\text{frstedges}=\begin{pmatrix}1&3\\ 1&4\end{pmatrix},\text{ \ }\text{\sc scndedges}=\begin{pmatrix}3&7\\ 4&9\\ 4&7\\ 4&9\end{pmatrix}, \tag{16}\]  
and the plot is in Figure 1. It shows that the edges in the left part come from _frstedges_ and the edges on the right part come from _scndedges_.