# An Algorithm for Nutrient Mixing Optimization in Aquaponics
## 4 Discussion  
The performance of the program was tested in multiple scenarios. In the first scenario, where costs of resources were neglected, the post-mixing concentrations were very close to the reference (average relative error \(<\) 0.1%). For the given resources and chosen weights, the program indeed found the optimal solution. To mix it, however, primarily resources \begin{table}
\begin{tabular}{c c c c} \hline \hline \multirow{2}{*}{**Water Source**} & **Used Amounts for** & \multirow{2}{*}{**Fertillizer**} & **Used Amounts for** \\  & **Mixing in L** & & **Mixing in g** \\ \hline FW & 255.303 & Ca(NO\({}_{3}\))\({}_{2}\) & 0.208 \\  & & KNO\({}_{3}\) & 153.415 \\ PW & 96.202 & K\({}_{5}\)SO\({}_{4}\) & 0 \\  & & NH\({}_{4}\)NO\({}_{3}\) & 89.377 \\ RW & 446.495 & MgSO\({}_{4}\) & 32.91 \\  & & Fe-Chelat & 1.787 \\ TW & 0 & KH\({}_{3}\)PO\({}_{4}\) & 0 \\ \hline Total & 798 & Total & 277.697 \\ \hline \hline \end{tabular}
\end{table} 
Table 6: Nutrient sources used in a sunnier and drier environment. Figure 6: Resulting normalized concentrations of nutrients in the solution in a sunnier and drier environment. such as RW, TW, and fertilizers were used, which are not available free of cost or, in the case of RW, in limitless amounts. PW was underutilized, and overall, only a small amount of resources were recycled. In the second scenario, the cost of resources was no longer neglected. The solution found by the algorithm now had a greatly reduced usage of fertilizers, TW and RW. This came at the cost of reduced tracking accuracy (average relative error 7.7%), with \(\text{PO}_{4}-\text{P}\) being 32.4% above its reference. In the third scenario, additional constraints for the post-mixing concentration were included. Note that this could also be achieved by increasing the weight for the tracking error of these nutrients. Constraints, however, are easier to interpret and will not allow undesirable solutions. This comes at the risk of infeasibility of the optimization problem. The addition of the constraints prevented any nutrient being lower than 95% of the reference value. Achieving the desired amount of PW consumption in the latter two scenarios came at the cost of higher \(\text{PO}_{4}-\text{P}\) concentration. This is not an immediate problem, since this is still far below critical values. Note, however, that in the following mixing cycles, the plant drain water will have increased \(\text{PO}_{4}-\text{P}\) values. In the fourth and last scenario, the reference values of the nutrient concentrations in the post-mix solution were halved. This adjustment was carried out to demonstrate that the proposed algorithm can be used to adapt the nutrient solution in response to different weather conditions. The results of this simulation show that the algorithm has no problem adjusting the various inputs to adapt the properties of the post-mix solution. This was achieved by halving the consumption of resources with high nutrient contents, e.g., FW, PW, and fertilizers, and by replacing the required water volume through the increased use of RW. The objective function defined in Equation (8) and the constraints in Equation (16) to Equation (23) are convex, which means the algorithm will always find a global minimum. Note that this property depends on \(J\). Even for non-convex problems, a solution can be found; however, there are no guarantees for global optimality. The program has a fast computation time. On an ordinary laptop with an i5-10210U CPU @ 1.6 GHz, for the given number of nutrients, water sources, and fertilizers, the program took less than ten seconds to read the optimization parameters from the xml files, calculate the optimal solution, and store the results in another xml file. With the algorithm being that fast, the user can perform multiple iterations with varying weights for the objective function.