# Replicating File Segments between Multi-Cloud Nodes in a Smart City: A Machine Learning Approach
## 5 Using Machine Learning for Partial Replication and Selecting the Candidate Node
### Example of Using the Topology Operator
#### 5.4.2 Over All Algorithm  
The algorithm finds paths that include diversity of different types of nodes. In other words, the path is a mix between links that bind clouds, edge servers, or clouds and edge servers together. The formula for the algorithm is defined to be:  
\[\forall p\in\mathbb{P},p\in\Xi((\underset{\Xi}{\overset{k}{\rightleftarrow}} \;\Xi)(\Phi^{*}\cup\Omega^{*}\cup\Psi^{*}\cup(\Psi^{T})^{*})^{+})^{*} \tag{47}\]  
The equation means that there are paths such that every path has a minimum of one connection that could be:  
1. Connection from a cloud to a cloud
2. Connection from an edge server to an edge
3. Connection from a cloud to edge server
4. Connection from edge server to a cloud Mathematically, let us assume that we have a path from cloud \(c_{1}\) to cloud \(c_{2}\), then to edge \(e_{1}\), then to edge server \(e_{2}\) and finally to cloud \(c_{4}\). This will be represented as follows:  
\[((\Phi[1]\wedge\Phi[2])\wedge\Psi^{T}[1])\wedge\Omega[2]\wedge\Phi[4]) \tag{48}\]  
While matrices here have different dimensionality, what matters here is the dimensional equality of every two consecutive matrices since every operation verifies whether there is a path or not. Note that the simplest way is to directly use \(\Xi\) in the format given in Equation (15) shown in Equations (21) and (22) because it is a square matrix and the application of the algorithm and the operator becomes very straightforward without the need to use Equation (47) which deal with heterogeneous non-uniform matrix cases. Algorithm 1 takes incident matrix \(\Xi\), the source node \(s\) and the destination node \(d\) as inputs and returns all possible paths \(s\) to \(d\). Note that every path has the information of transmission cost in seconds between every two successive nodes per bit. This means that the longer the data to be transmitted are, the higher the cost is. The transmission cost differs from node to node and the total cost when transmitting \(b\) bits from source \(s\) to destination \(d\) through path \(p\) is presented as follows:  
\[cost=\Sigma\tau(c_{i},c_{j})\times b\|(c_{i},c_{j})\in p,\text{ and }c_{j}=c_{i} \bullet,s=c_{i}\|i=0\text{ and }d=c_{j}\|j=\|p\| \tag{49}\]  
where \(c_{i}\bullet\) is the successor of \(c_{i}\). After acquiring the different paths, we pick the path with the shortest cost, and note that the cost here is not just transmission cost, it is also the replication cost of replication cost. The minimum cost now is presented as follows:  
\[min(cost)=min(\tau(c_{s},c_{j})+\pi(c_{j})+\rho(c_{j})+\Sigma_{i=1}^{t}\tau(c_ {s},c_{j})) \tag{50}\]  
where \(t\) is the number of times node \(c_{d}\) will communicate with node \(c_{j}\). The proposed algorithm is an algorithm that finds the cost of different paths from one node to another. The algorithm is divided into two phases: The topology recognition phase and the dynamic behaviour phase. The topology phase literally builds the graph while the dynamic behaviour phase keeps watching costs and finds the minimum path accordingly. When comparing this algorithm to the traditional Dijkstra graph minimisation [52]. We can see the following:  
1. The objective of Dijkstra is learning the path with the minimum cost and the cost is considered static and if cost changes, the algorithm is being applied again from the starting point until reaching the destination. The objective of the proposed algorithm is to learn the topology and then assign dynamic costs that varies from one point of time to another and according to changes that occurs, file segments begin to be replicated or deleted from certain nodes. 2. While the Dijkstra algorithm works on undirected graphs, it is not guaranteed to be sound when weights are negative. In the proposed algorithm, this cannot happen since nodes that have been visited before cannot be visited again. This is guaranteed by the algorithm itself and verified by theory Section 5.3. 3.