# A Smart and Mechanized Agricultural Application: From Cultivation to Harvest
## 3 Materials and Methods
### Harvesting Phase
In the classical ACO algorithm, the ants make the path selections according to Equation (6), \[P_{i,j}^{k}(t)=\frac{[\tau_{i,j}(t)]^{\alpha}[\varphi_{i,j}(t)]^{\beta}}{\sum_{ k\text{-}k\text{-}l\text{-}o}[\tau_{i,k}(t)]^{\alpha}[\varphi_{i,j}(t)]^{\beta}};j \text{-}j\text{-}k\text{-}l\text{-}o}\] (6) where '\(k\)' represents the number of ants used in the algorithm. The '\(i\)' and '\(j\)' denote the source and destination station, respectively, which indicate the points of each autonomous robot. \(\tau_{i,j}\) is represented as a matrix and shows the instantaneous states of the crops. The \(\varphi_{i,j}\) is the heuristic cost between the edges '\(i\)' and '\(j\)'. The '\(\alpha\)' and '\(\beta\)' are related to the importance of trail and heuristic cost. In the proposed RACO, the related mathematical equations are defined as follows (Equations (7)-(12)), based on the problem in this study: \[Profit^{K}\left(MaxProfit\right)=\sum_{1}^{D}SelectedCrop^{K}\] (7) \[Power^{K}=\left(BatteryCapacity*\ DeliverCapacityPercentage\right)-\sum_{i}^{j}( distance*BatteryConsumed)\] (8) \[Time^{K}(MinTime)=\sum_{i}^{j}(distance*TimeConsumed)\] (9) where '_SelectedStatus_' shows the drop collected by each ant. The goal here is to get the most profit. '_BatteryCapacity_' indicates the maximum power capacity of the autonomous robots, generally related to _Ah_ and \(V\). '_DeliverCapacityPercentage_' represents the maximum amount of power each robot can use. The '_distance_' is the distance between two points in meters. '_BatteryConsumed_' is the amount of energy used between both points. In this study, battery capacity is assumed 8 _Wh_ and the maximum battery usage rate is accepted as 90%. The amount of '_Power_' obtained here indicates the amount of energy that each robot will use, and this is desired to be minimum. It is worth mentioning that at the end of the algorithm, a route will be assigned for each of the robots. Since the concept of power is meaningful to them, autonomous robot is expressed here, but it actually means ant. The '\(D\)' represents the total number of crops in the field. The '\(Time\)' and '\(TimeConsumed\)' parameters represent the total time used by each ant and the elapsed time between both points, respectively. \[CostFunction^{K}=\frac{C_{2}*Power^{K}+C_{3}*Time^{K}}{C_{1}*Profit^{K}};\ C_{1}+C_{2}+C_{3}=1,\ \ \ C_{1}>C_{2}\geq C_{3}\] (10) \[BestCost=Min(CostFunction)\] (11) where \(C_{i}\) are coefficients that can be adjusted according to the requirements of the problem. Optimal values for these constants can also be found by a metaheuristic method. In this study, the method in [58] is used to tune the values of these coefficients. Since these weights (coefficients) are not defined in the classical ACO, they are assumed to be of equal value. The relationship to \(C_{i}\) may differ depending on the purpose of the problem. For example, \(C_{1}\) should be bigger than the others if we want the minimum answer, and vice versa if we are looking for the maximum. This proves the flexibility of the relevant cost function. Atthe end of each iteration, '_CostFunction_' is calculated for each ant and the minimum among them is accepted as the best solution. \[\Delta\tau_{i,j}=\frac{CropStatus-SelectedCrop}{\sum_{1}^{D}Crops} \tag{12}\]  
\[\tau_{i,j}=(1+\rho)*\tau_{i,j}+\Delta\tau_{i,j} \tag{13}\]  
where \(\rho\) is a coefficient that affects and controls the rate of the crops' status. '_CropStatus_' shows the latest status of each crop. '_Crops_' indicates the total number of crops in the field. The working mechanism of the proposed algorithm for finding the optimal path for each autonomous robot is shown in Figure 3. It is worth remembering that the starting and ending points of each ant do not have to be the same. At the end of each iteration the best solution is chosen. When the iterations are over, the best solution is given as a path to the relevant autonomous robot (IoV), and in this way each robot is assigned a task to collect crops in the real field.