# Formal Modeling and Improvement in the Random Path Routing Network Scheme Using Colored Petri Nets
## 3 Material and Methods
### Hieratical Colored Petri Nets
#### 3.1.2 Token Passing  
There are two equations utilized for token passing shown below as follows:  
1. Pin (path routing) = [] (Pin input for the module, and [] is the empty list)
2. Pout (calculated distance) = [list of all paths distance] (Pout is the module's output that contains paths distance)  
Figure 3: Root finding.  
The above equations show that the input for this module's route finding is the list of the calculated distances from a source node to a sink node. When the token is passed through the source node to the sink node, it follows the same path provided by the route-finding module in Figure 4, token passing.  
In Figure 4 the node, 16, has the calculated path in the form of a list. The data type of Node 16 is li = list. It transfers the list to the N17. Here the reverse of the whole list takes place. Now at the head of the list, which is the following path to be traversed, Node 17 will pass the head value of the list to node N 31. Having had the list whose values are li = {5, 13, 7, and 34}. After reversing this list, the list becomes li = {34, 7, 13, and 5}. The model has calculated the head of the list by the function (x. HD, x). As the token will move forward, the next transition has a guard value of p = 34. The head of the list is where the next transition is processed, and the guard value matches. So, the token is passed along this route. Here again, Node 31 will pass the token to Node 31.  
The list value that the list had now becomes li = {5, 13, 7} as the head of the list has been removed. In between Node 31 and Node 32, the same process is repeated. The list is reversed and pass the head value of the list, and now the next token is ready to be sent. After reversing the list becomes li = {7,13,5}. By using a head function, the model has calculated the head of the list.  
The guard value of the transition VV is 7, and the head value of the list is the same, so the token is passed from N 31 to N 33. The new value of the list is now li = {5, 13} after the removal of the head value. The head value of the list and the transition's guard value  
Figure 4: Token passing.  
validate the token to be passed on the right path. If the head value and the guard value are different, the transition is no longer active.  
So, the system has passed two nodes by validating the guard value of each transition. Now the list value is li = [5, 13]. The same process is repeated, and the model has reversed the list between Node 33 and Node 34. The list value becomes li = {13,5}. The head of the list is calculated here to validate the head value and the guard value. As the guard value of transition RR is 13 and the head value of the list is 13, the model can move the token from Node 34 to Node 35. After transferring the value to Node 35, the list values become li = [5]. So, for this token, as the model moves forward from Node 35 to Node 36, again, the same process is repeated, and the list is traversed, and it becomes li = [5]. When the system has found the head value of the list, the result is 5. The transition NN has the guard value of 5, so the system has validated, and a token is passed from the transition NN. After the transition is active, the list value becomes li = {}, which means it is empty. This means that this is the end of the path, and the token has reached the destination sink node--the system a calculated specific path and the different routes to be available to send tokens. The system has automatically traversed all the nodes and transitions followed by the list, which shows the validation of the system and path that has been traversed.