# An Algorithm for Nutrient Mixing Optimization in Aquaponics
## 4 Discussion
As there is no way to 'correctly' calculate the weights \(\omega_{\text{water},i}\) and \(\omega_{\text{fertil},f}\), finding good values through trial and error is relatively comfortable thanks to the fast computation time. Input values for the input xml files can be collected in a flexible manner. In most commercial production plants that use hydroponic systems, nutrient solution samples are taken for laboratory analysis on a weekly basis. On-line sensors, such as ion-selective electrodes, allow for a much more accurate assessment of current ion concentrations, but are not available for all ions. A combination of different analytic methods is also possible. The calculated output values can be added to the mixing tank in the form of pre-mixed single-fertilic stock solutions or as fertilizer salts. When adding fertilizer salts, of course, the specific solubilities of these salts have to be considered, which are also dependent on the solution temperature in the mixing tank. In most setups, controlling the ambient temperature of the mixing tank is enough to avoid solubility issues that result from temperature fluctuations. The pH value in the mixing tank is critical for the availability of ions for the uptake by plants [8]. For hydroponic production, the pH is usually adjusted to a value between 5.5 and 6.5 by adding acid (e.g., \(\text{H}_{3}\text{PO}_{4}\)) or base (e.g., KOH) to the mixing tank. The pH values which fall outside these ranges can also result in the formation of precipitates. These additions of acid or base, which are made after mixing in our example, can alter the nutrient composition and can be estimated in the input values or included in a future model (see outlook section). The formation of precipitates equals a loss of nutrients to the system and thus an economical loss. Precipitates can also form if high concentrations of precipitate forming ions are mixed. This is not the case when mixing standard plant nutrient solutions but should be considered when using the model to mix highly concentrated solutions, e.g., stock solutions. The costs of implementation are low, as the developed software has no proprietary dependencies, and works even on low-end hardware. There are costs, since the concentrations of all input resources are required and need to be recalibrated regularly. However, this information is required for any method. The algorithm also works well in low-tech environments with infrequent measurements. On-line sensors in the mixing tank will improve performance, but the algorithm will produce accurate solutions even without constant sensor feedback. In the Outlook, we describe how, using model based observers, the plant drain re-flow can be estimated, further decreasing costs for measurements. Installation instructions and a detailed explanation of the algorithm and its implementation in Python can be found in the Supplementary Material. The integration of the program into already existing systems is rather simple, since the program works stand-alone and interfaces are well defined through the xml files. The code can also be easily adjusted to instead use csv files or directly communicate with other machines. The program is highly flexible and easy to use and does not require in-depth programming knowledge. Many parameters, reference values, and constraints can be adjusted by modifying the xml files using any text editor. More advanced adjustments to the objective function require basic understanding of static optimization, which was provided in the Methods and Materials section. The algorithm has a wide range of application cases, such as the featured mixing of nutrient solutions for complex DRAPS as well as simpler non-automated aquaponic or hydroponic systems. Mixing dynamics are neglected; it is assumed that enough time can pass such that ions can fully solve in the nutrient solution. Solubility of mineral fertilizer salts is not a relevant problem in the concentration ranges of nutrient solution recipes for crop production.