# Data Transmission in Wireless Sensor Networks Based on Ant Colony Optimization Technique
## 2 Materials and Methods
### WSN Shortest Distance
#### 2.2.3. Step 3  
Record the path from the current point to the starting point, which can be represented as a matrix of 2 rows and 2 columns in Matlab [(2,2), (3,2)].  
Figure 3: Turtle’s 2 nd position.  
Figure 2: Turtle displacement.  
Next, determine whether the current node is the endpoint. If it is not the endpoint, continue with step 1 and search for the next point that can be explored out of (3,3), (4,2), and (2,1).  
As shown in Figure 4, the next step is to find the points that the little turtle can go to in the next round and check whether the surrounding points are in the explored array alreadyfrontier. If they are, ignore them, and then check whether these points are already in the explored array frontier. If they are, compare the current cost G of the point with the current cost G2 required to reach the current position after passing through the little turtle's current position. If G > G2, change the previous node of the point (which can be understood as the parent node) to the node where the little turtle is currently located, and update its current cost to G2.  
As shown in Figure 5, By searching for the points to be explored in the order of bottom left to top right, the minimum cost obtained in the first two selections is (3,2) and (4,2). If you follow the order of top right to bottom left, as shown in Figure 6, the minimum cost obtained will be (2,3) and (2,4). This does not affect the final shorte st path length, but the paths are different. By repeating the above three steps, you can obtain the shortest path. The green dots in the figure represent the shortest path.  
Figure 4: Turtle’s second position representing cost.  
Figure 5: Turtle’s 3 rd position.  
Figure 6: Turtle’s path to finish line.  
2. Implementation of steps in WSN shortest distance algorithm.  
1. Add the WSN's starting node to the frontier array to be explored, with a cost of 0.
2. Identify the node with the lowest cost F in the frontier, remove it from the frontier, and add it to the explored array already_frontier.
3. Determine if the point is the endpoint; if not, continue.
4. Identify the four points around the WSN node and determine if they are in the already'frontier array. If they are, ignore them (of course, these four points cannot exceed the map range or be located in obstacles).
5. Determine whether these points are already in the frontier of the array to be explored. If they are in the frontier of the array to be explored, compare the current cost G of the point with the current cost G2 of reaching the point through the current node. If G > G2, change the previous node of the point to the current node, update its current cost to G2, and update its cost F.
6. Add the remaining points that meet the requirements to the frontier, calculate the cost F, and arrange the frontier array according to the cost F.
7. Simultaneously record the path, that is, each node should record its previous node to facilitate the final backtracking of the path and find the shortest path. Repeat steps (2) to (7) until reaching the endpoint to terminate the loop.