Next Article in Journal
Extraction of Garlic in the North China Plain Using Multi-Feature Combinations from Active and Passive Time Series Data
Previous Article in Journal
An Environmentally Sustainable Approach for Raw Whey Treatment through Sequential Cultivation of Macrophytes and Microalgae
Previous Article in Special Issue
From Feed to Fish—Nutrients’ Fate in Aquaculture Systems
 
 
Font Type:
Arial Georgia Verdana
Font Size:
Aa Aa Aa
Line Spacing:
Column Width:
Background:
Article

An Algorithm for Nutrient Mixing Optimization in Aquaponics

1
Automatic Control and System Dynamics Lab, Technische Universität Chemnitz, Straße der Nationen 62, 09111 Chemnitz, Germany
2
Division Biosystems Engineering, Albrecht Daniel Thaer-Institute of Agricultural and Horticultural Sciences, Humboldt-Universität zu Berlin, Albrecht-Thaer-Weg 3, 14195 Berlin, Germany
3
Fachbereich V—Life Science and Technology, Berliner Hochschule für Technik, Luxemburger Str. 10, 13353 Berlin, Germany
4
Department of Bioresources, Fraunhofer Institute for Molecular Biology and Applied Ecology, Ohlebergsweg 12, 35392 Giessen, Germany
*
Author to whom correspondence should be addressed.
Appl. Sci. 2024, 14(18), 8140; https://doi.org/10.3390/app14188140
Submission received: 31 July 2024 / Revised: 4 September 2024 / Accepted: 6 September 2024 / Published: 10 September 2024

Abstract

:

Featured Application

The algorithms provided in this work can be applied in most scenarios where fluids and water-soluble substances, e.g., salts, are mixed to meet certain requirements. Examples include hydroponics and aquaponics.

Abstract

Controlled environment agriculture is a promising alternative to conventional production methods, as it is less affected by climate change and is often more sustainable, especially in circular and recycling frameworks such as aquaponics. A major cost factor in such facilities, however, is the need for skilled labor. Depending on available resources, there are endless possibilities on how to choose ingredients to realize a desired nutrient solution. At the same time, the composition of the desired solution is subject to fluctuations in fish water quality, fertilizer availability, weather, and plant development. In high-evaporation scenarios, e.g., summer, nutrient solutions might be mixed multiple times per day. This results in a complex, multi-variable task that is time-consuming to solve manually, yet requires frequent resolution. This work aims to help solve this challenge by providing methods to automate the nutrient mixing procedure. A simple mass-balance-based model of a nutrient mixing tank with connections to different water sources, drains, and fertilizers is provided. Using methods of static optimization, a program was developed which, in consideration of various process constraints and optimization variables, is able to calculate the necessary steps to mix the desired solution. The program code is provided in an open-source repository. The flexibility of the method is demonstrated in simulation scenarios. The program is easy to use and to adapt, and all necessary steps are explained in this paper. This work contributes to a higher automation level in CEA.

1. Introduction

In the field of recirculating hydroponics and aquaponics, analyses of hydroponic drainage water and fish waste water are essential to correctly mix plant nutrient solutions. Historically, colorimetric, spectrophotometric, and chromatographic laboratory methods are used and commercial producers still mostly rely on these robust and accurate measurements of weekly samples. Recently, the development of sensors or systems capable of measuring concentrations of individual ions in the nutrient solution on-site and in real time (e.g., ion-selective electrodes (ISEs), ion-sensitive field-effect transistors (ISFETs), or capillary electrophoresis (CE)) has represented a significant advancement in nutrient solution monitoring. CE systems [1] have recently been implemented in Dutch greenhouses, allow for several measurements a day, and are reported to have a comparable accuracy to standard laboratory methods. ISE and ISFET systems [2] are more cost-effective and measure on-line, but are only available for certain macronutrients and can be less accurate and robust than traditional analytical methods.
In the wake of these technological innovations, automated nutrient solution mixing strategies and systems have been developed for hydroponic plant production [3,4,5,6,7]. These aforementioned studies integrated ion-selective electrodes into control systems to maintain ideal nutrient concentrations and pH levels, which are crucial for maximizing plant growth and health [8]. In coupled aquaponic systems, these requirements have to be considered together with the requirements of the fish culture, and optimization is thus very limited. In this study, the focus is on a decoupled aquaponic system, i.e., the double recirculating aquaponic system (DRAPS) [9,10].
The integration of Internet of Things (IoT) technology has further enhanced the efficiency of automated systems, allowing for remote monitoring and management of nutrient solutions. This capability is particularly beneficial for large-scale operations where constant manual monitoring would be impractical. IoT connectivity also facilitates data accumulation across multiple systems and locations, enabling predictive analytics to forecast nutrient deficiencies before they affect plant health.
Recent research has focused on the algorithms needed to process the data and decision-making processes regarding the recycling of excess nutrients in drainage water [11,12]. Savvas et al. [12] present an extensive work combining mass balance models with databases of nutrient solution recipes. Cho et al. [11], on the other hand, developed a decision-tree model, which also accounts for nutrients that can not be analyzed. As the mentioned studies focus on hydroponic systems, they only consider the nutrient sources, plant drain water and fertilizer stock solutions. As a consequence, these algorithms have been restricted to iterative calculations without the possibility of weighting the options. In aquaponic systems, this aspect is more critical because fluctuations in fish drain water, plant drain water, rain water and tap water must be considered, and the option for different constraints and varying importance (i.e., weight) of optimization targets should be possible. For example, rapid fluctuations in plant drainage water can be caused by weather-induced changes in photosynthesis and transpiration rates or fluctuations in nitrogen concentration in fish waste water can be expected. To the authors’ knowledge, no algorithm that takes these important aspects into account has been developed so far.
Control engineering and optimization theory provide tools, methods, and solutions for such decision-making problems. In this work, the system, i.e., its inputs, outputs, states, and process constraints, are described mathematically using modeling methods. A goal for the mixing is then formulated and translated into a mathematical objective function, e.g., with a focus on the precision of target solution concentration or economic factors. An algorithm then calculates the necessary actions to fulfill that goal in an optimal way, such that it does not violate constraints. A program is developed that automates most of the necessary steps for mixing nutrient solutions. This program is easily adaptable, and the necessary steps are explained in this work.
The aim of this work is to advance automation in (closed-environment) agriculture and to introduce and establish automatic optimization and operation research methods in this field.

2. Materials and Methods

This section gives an introduction on how to mathematically describe systems and optimization problems to enable the reader to make adjustments to the program for their specific setup.

2.1. Mathematical Description of the System

The general system structure of a double-recirculation aquaponic system (DRAPS) will be similar across all implementations: multiple tanks and a fertilizer injection system, all connected to one mixing tank (MW) (Figure 1). It is a simple and precisely specified system, both in dimensions and other parameters, which allows for a mechanistic modeling approach using mass and volume balance equations. Note, that mixing dynamics are not included in the model; it is assumed that after adding ingredients, the system has enough time to mix homogeneously. Additionally, sedimentation is neglected.
Two properties describe the so-called states of the system: liquid volume V in [L] and nutrient mass N in [g]. Instead of using concentrations, the absolute mass of a nutrient is used, as this simplifies the process of adding liquids with different concentrations and is overall more practical. Any number of tanks and water sources can be considered, but for this work, we chose a mixing tank, fish drain water tank (FW), plant drain/re-flow water tank (PW), rain water tank (RW), and tap water (TW), each with their respective volume V i , where I is a set of size i max with
i I : = { FW , PW , RW , TW } .
The mixed nutrient solution can then be used for plant fertigation. All solved ions that are found relevant by the user may be considered. In this work, we consider N q with
q Q : = { N O 3 N , N H 4 N , P O 4 P , S O 4 S , K + , C a 2 + , M g 2 + , F e 2 + , C l , N a + } .
However, not all ions need to be accumulated in the system. Sodium and chloride in particular are harmful to plants at higher concentrations. Therefore we introduce two subsets of ions, the first being
Q nut : = { N O 3 N , N H 4 N , P O 4 P , S O 4 S , K + , C a 2 + , M g 2 + , F e 2 + } ,
which is the set of nutrients that usually contribute positively to plant nutrition and that the user gives reference values for, and the second being
Q harm : = { C l , N a + } ,
which contains ions that are harmful to plants at higher concentrations and that the user does not define a non-zero reference value for. Note that there might be beneficial interactions and compound effects between the two classes of ions, i.e., the meanings of harmful and beneficial are more in the sense of ‘minimize in the solution’ and ‘accumulate in the solution’, respectively. In the resulting solution, the concentrations of the nutrients q nut Q nut should be as close to a reference as possible and the concentrations of q harm Q harm should be minimized or not exceed a specific maximum concentration.
Next, the inputs u to the system are described, where the term input in control engineering refers to a variable that can influence the system and can be chosen at will. Two types of inputs are considered: water flows and fertilizers. Water flows, denoted as u V , i , describe the water volume in [L] that is transferred from source i to the mixing tank in one mixing cycle. Fertilizers, denoted as u N , f , describe how much of a fertilizer f is added to the system in [g]. Possible fertilizers are
f F : = { C a ( N O 3 ) 2 , K N O 3 , K 2 S O 4 , N H 4 N O 3 , M g S O 4 , Fe Chelat , K H 3 P O 4 } .
Once they are added to the mixing tank, they dissociate into their respective ions q.
After mixing, the resulting states can be calculated using
V MW , post = V MW , pre + i I u V , i
N MW , q , post = N MW , q , pre + i I c i , q u V , i + f F c f , q u N , f ,
where V MW , pre and N MW , q , pre are the initial volume and nutrients pre-mixing, respectively, c i , q is the concentration of ion q in water source i and c f , q is the proportion of ion q in fertilizer f.

2.2. Method of Optimization

In this section, only a brief overview of the optimization methodology is provided. This will later enable the reader to understand and adapt the algorithm. For more information on optimization, refer to, e.g., [13,14].
The optimization problem is formulated as a static optimization problem. Its underlying principle is the optimization of an objective function under the consideration of constraints. This is achieved by choice of a variable u, i.e., the inputs of the system (water sources and fertilizers). The objective function J is designed by the user in such a way that its optimization—if feasible—leads to a desired solution, e.g., minimizing waste and/or cost. Constraints refer to certain conditions which restrict the solution to a subset, e.g., maximum concentrations of a nutrient or maximum volume in a tank. A common mathematical representation of a static optimization problem is
min u J ( u ) s . t . h ( u ) 0 ,
with h ( u ) inequality constraints. Note that it is in principle also possible to use equality constraints, which can lead, however, to numerically more demanding optimization problems. Also, equality constraints can be approximated through two narrow inequality constraints that bound the solution from above and below.
This mathematical problem can in certain cases be solved analytically. In most cases, however, the optimum can only be approximated numerically using already available solvers, like IPOPT [15], which uses an interior point method. In the presented program, this exact solver was used to find the solution of the set up static optimization problem.

2.2.1. Static Objective Function of the Optimization Problem

As already stated, the objective function is a part of the design process and can be chosen in any form necessary. As an example, we select the goal of getting close to a target concentration at low costs. A mathematical description is stated below:
J ( u ) = ω bal , ref · e N MW , ref ( u ) + ω bal , min · e N MW , min ( u ) + ω bal , V · e water ( u V ) + ω bal , N · e fertil ( u N ) .
The error terms are explained in the following paragraphs. Overall, the objective function consists of two linear and two quadratic error terms e that are added up and, in that way, realize the function value. Furthermore, the errors are multiplied by weights ω bal that balance the influence of the respective terms due to different mathematical formulations and different dimensions as well as units of the inputs u that realize the optimization variables. In our example, the balancing is conducted as follows:
-
ω bal , ref · e N MW , ref ( u ) sums up to 100 if the relative error between N MW , q nut , post and the reference N MW , q nut , ref for each nutrient q nut Q nut equals 10 % . Note that this term scales quadratic to the error, i.e., higher deviations are punished more strongly.
-
ω bal , min · e N MW , min ( u ) sums up to 100 if the concentration of every undesired ion q harm Q harm is equal to 50 % of the maximum level. Note that this term also scales quadratic to the error, i.e., higher deviations are punished more strongly.
-
ω bal , V · e water ( u V ) increases linearly by 100 for every 25 % of missing water added to fill the tank.
-
ω bal , N · e fertil ( u N ) compares the missing nutrient mass required to realize c MW , ref at V MW , post , appr for every nutrient to the amount of used fertilizers. If the cumulative mass of consumed fertilizers is equal to the missing nutrient mass, ω bal , N · e fertil ( u N ) linearly increases to 100. Note that since fertilizers only partially consist of the required nutrient, fertilizer mass will exceed the required nutrient mass. This is to punish fertilizer usage and encourage adding nutrients through FW and PW.
To achieve this, the balancing weights ω bal are chosen as stated below:
ω bal , ref = 100 ( 1 0.1 ) 2 q nut , max = 10000 q nut , max , ω bal , min = 100 ( 1 0.5 ) 2 q harm , max = 400 q harm , max , ω bal , V = ( 1 0.25 ) · 100 V MW , post , appr V MW , pre , ω bal , N = 100 V MW , post , appr · c MW , ref 1 V MW , pre · c MW , pre 1 ,
where q nut , max are the number of beneficial nutrients that should be close to a given reference and q harm , max are the number of ions that should be minimized. The balancing weights of water and fertilizer consumption are chosen to be relative to the missing water volume and the missing nutrient mass to realize the reference concentration of the final volume V MW , post . However, V MW , post cannot be directly used for the weights, because for V MW , pre = V MW , post a division through zero would occur in the objective function, which would lead to a failing of the solver. To increase the numeric stability of the program, V MW , post , appr is used instead:
V MW , post , appr = V MW , post , max + V MW , post , min 2 ,
with V MW , post , max and V MW , post , min being the upper and lower bounds of the constraint on the water volume that is stored in the mixing tank after the mixing procedure. Note that in the software implementations, errors caused by division by zero are caught and the user is advised to reformulate the optimization task.
By generalizing the balancing weights, the program can be used for different systems and use cases without the need to edit the source code. The weights in this example are chosen such that they are mechanistically interpretable, e.g., increasing ω bal , N will punish the usage of fertilizer more. A general approach for choosing weights is to first balance them out such that they are in the same magnitude at a common operation point of the system, and then the user can fine-tune the parameters through expert knowledge. Note that the balancing weights presented in this paper are still just a suggestion and can be adjusted to one’s needs.
The first term e N MW , ref of the objective function considers the sum of errors between the concentration of beneficial nutrients in the prepared solution and the corresponding reference concentration. Since the reference values for individual nutrients q can range over wide magnitudes, e N MW , ref is set such that the relative error is minimized. The equation describing this part of the objective function is given as
e N MW , ref ( u ) = q nut Q nut ω N ref , q nut · N MW , q nut , post ( u ) N MW , q nut , ref N MW , q nut , ref 2
where N MW , q nut , post is calculated in Equation (7) and N MW , q nut , ref is the product of V MW , post , appr (see Equation (6)) and the given reference concentration of every nutrient
N MW , q nut , ref = c q nut , ref · V MW , post , appr .
Furthermore, the relative error of every nutrient is multiplied with an additional weight factor ω N ref , q nut to specify the priority of each nutrient. Note that Equation (11) fails if the reference concentration is chosen equal to zero; hence, the error of nutrients whose concentration is to be minimized must be calculated separately. For that, the second error-term e N MW , min is introduced:
e N MW , min ( u ) = q harm Q harm ω N min , q harm · N MW , q harm , post ( u ) N MW , q harm , ref c q harm , max V MW , post , appr 2 ,
which penalizes the relative difference between the ion concentration of the resulting solution and the reference N MW , q harm , ref = 0 . The resulting error for an individual ion can again be modified by the weights ω N min , q harm .
The purpose of the two remaining terms, e water and e fertil , is to regulate the use of the available water sources and fertilizers. Resources that increase the running costs of the system, e.g., TW and fertilizers, should only be used as little as possible and therefore, high values of u N , f and u V , TW should be avoided. Water that is stored in the fish drain and in the plant drain tank, on the other hand, should be used as much as possible, since both are waste products that should be recycled in the plant irrigation of an aquaponics system. RW is usually free, but in summer, it might be scarce and thus, its usage could be limited with respect to the volume left in storage. The respective error terms are given as
e water ( u V ) = i I ω water , i · u V , i ,
e fertil ( u N ) = f F ω fertil , f · u N , f ,
where ω water , i and ω fertil , f are adjustable weights, e.g., to punish or reward using specific resources.
Note that there are usually no ‘correct’ values for the weights, and finding values involves bringing them into similar magnitudes by comparing units; fine-tuning is usually a mix of expert knowledge and trial and error. Another method involves using economics, e.g., costs of water and fertilizers, as the basis for the weights. However, in our specific setup, for example, how to convert the deviation of the post-mixing concentrations into economical value is not intuitive. For example, it is almost impossible to predict the influence on plant growth and harvest quantity and quality caused by a deviation of nitrogen concentration in the post-mixing solution.

2.2.2. Static Constraints of the Optimization Problem

Another major part of the static optimization problem is the constraints h ( u ) . As an example, there are three sets of inequality constraints implemented as part of the optimization problem. The first set of constraints is given by the nutrient concentrations in the solution after the mixing, which can be limited by an upper bound c q , max and a lower bound c q , min . The inequality constraints are
c q , max N MW , q , post V MW , post ,
c q , min N MW , q , post V MW , post ,
with V MW , post and N MW , q , post given in Equations (6) and (7). To linearize these constraints (and thereby simplify the optimization problem), both sides of the inequalities are multiplied by V MW , post . The resulting linear constraints are
c q , max · V MW , post N MW , q , post ,
c q , min · V MW , post N MW , q , post .
The second set of constraints is given by the upper and lower bounds of V MW , post . These bounds result in two linear inequality constraints that can be stated as
V MW , post , max V MW , post ,
V MW , post , min V MW , post ,
with V MW , post , max being the upper and V MW , post , min being the lower bound of the water volume that is stored in the mixing tank after mixing a new nutrient solution. The last set of constraints is given by the upper and lower bounds of every input u. These can be stated as
u max u ,
u min u ,
where u max are the upper and u min are the lower bounds of every input.
Note that, in theory, one might also use equality constraints for V MW , post . However, it is usually more stable to use a set of upper and lower inequality constraints to avoid infeasibility and numerical issues while solving the optimization problem.

2.3. Algorithm Implementation

This section gives a brief overview of the structure and functionality of the implemented optimization program. For a more detailed explanation, see the extensive program documentation in the Supplementary Materials.
The static optimization problem was implemented in Python and only open-source tools were used. The Python API of CasADi [16], a framework for modeling and solving optimization problems, was utilized to set up and solve the static optimization problem as it offers a straightforward way to implement optimization problems symbolically as well as initialize and call an according solver, e.g., IPOPT. The structure of the program is given in Figure 2. The first step is to collect the parameters of the optimization problem using pre-built functions of the Python library pandas [17]. The parameters are given in tables and are located in four .xml files:
-
Nutrient_Concentrations.xml
-
Water_Use.xml
-
Fertilizers.xml
-
Mix_Tank_Parameters.xml.
Figure 2. Flow chart of the program.
Figure 2. Flow chart of the program.
Applsci 14 08140 g002
A detailed explanation of the contents of each file is given in the documentation of the program. From these files, the parameters get extracted into separate Python dictionaries (structs in Python) where the columns of the xml files are stored as an object with the key being the header of the xml table and the value being a list of parameters that are associated with the respective header. To easily manage the access to the data stored in each dictionary, every element of the lists is labeled with an identifier that is stated in the first column of every xml table (except Mix_Tank_Parameters.xml), e.g., Na, KNO3, or Tap.
With the parameters loaded, the next step is to set up the optimization problem using the syntax and pre-built functions of CasADi to symbolically calculate the equations from (8) to (23). The contents of the xml files determine which nutrients and inputs are considered for the optimization problem. The user can adjust those as needed. Furthermore, reference values and constraints do not have to be given for every nutrient, e.g., the concentration of a certain nutrient can be limited by a maximum bound but does not have to appear in the objective function when there is no reference value available. The constraints can also be adjusted to the user’s preferences.
After the optimization problem is built, the symbolically stated optimization variables and the symbolically generated objective function and constraints are used to initialize the solver IPOPT. Right after the initialization, the solver is called by passing the initial guess u 0 , the right-hand side of the implemented constraints, and the bounds of every optimization variable. See Section 3.1 for information regarding u 0 . IPOPT then tries to find a solution to the optimization problem. In the last step, the result is visualized and written to the output file Output_Values.xml.

3. Results

The results of the optimization are calculated iteratively via the solver IPOPT. Initially, a starting guess for the values of the optimization variables has to be stated. For the optimization variables that are associated with the fertilizers, the starting values are chosen to be equal to zero. For the water sources, the starting values are
u 0 , i = V MW , post , max i max .
Once the solution has been calculated, the resulting values of the optimization variables are displayed by the solver. Note that all optimization values are rounded to three decimal places, i.e., fertilizers are realized with an accuracy of one m g and water sources with an accuracy of one m L , as lower values could not be practically realized. Note that for the resulting nutrient concentrations in the post-mixing solution, the actually realizable rounded values of u N and u V are used. This results in errors for the post-mixing concentrations. These errors, however, only become noticeable when mixing small solutions, e.g., when the calculated fertilizer input is in the < 100   m g range.

3.1. Simulation Studies

To verify that the implemented program for the optimization of nutrient mixing is working as intended, three simulation scenarios were investigated.
In the first study, the weights ω bal , V and ω bal , N are set equal to zero such that only the error between N MW , q , post ( u ) and N MW , q , ref is minimized in the objective function. The purpose of this scenario is to show how close the concentrations of the post-mixing solution can be to the reference values, when the costs of resources are neglected.
In the second study, the complete objective function is taken into account by setting ω bal , V and ω bal , N to the values given in Equation (9). The aim of this scenario is to show if the use of external nutrient and water sources, e.g., fertilizers and TW, can be significantly reduced by increasing their respective weights ω water , i and ω fert , f in the objective function, while the mixed nutrient solution is still sufficiently close to the reference.
In practical applications, it is often more important that all nutrients q nut are available at a minimum level, while overshooting below an upper bound causes little problems. To showcase how constraints can be utilized to ensure minimum concentration levels, a third simulation with such constraints is investigated. For that, the bound for c q nut , min (see Equation (19)) of the post-mixing solution is set to
c q nut , min = 0.95 · c q nut , ref .
In real-world systems, varying weather conditions demand the properties of the nutrient solution to (dynamically) adapt to these disturbances. In a hot and dry climate, the plants of a hydroponic system take up more water than those in a cold and humid environment, while the nutrient uptake remains nearly unaffected. Therefore, the nutrient concentrations that are achieved in a solution should be significantly lower at the former scenario. To account for this demand, the user of the presented program can set the reference concentrations accordingly in the respective xml file. To investigate this scenario, a fourth simulation study is taken into account, where new reference concentrations are set to
c q nut , ref , new = 0.5 · c q nut , ref .
The intention of this last study is to prove that the proposed algorithm is able to operate in different environmental conditions.
An overview of the nutrient composition of water sources and fertilizers is given in Table 1 and Table 2, as well as starting and target concentrations [18]. Constraints for nutrient concentrations can be found in [19]. Starting and reference values of nutrient masses can be calculated by multiplying their concentrations with the pre- and post-mixing water volume in the mixing tank. In the example, it is assumed that in the beginning, the mixing tank is filled by 1 % , i.e., V MW , pre is 10   L to avoid numerical issues.
Values for plant drain represent a mean of multiple measurements that were taken weekly between May and June 2024. Plant drain samples were analyzed via inductively coupled plasma–optical emission spectrometry (ICP-OES) regarding C a 2 + , F e 2 + , K + , M g 2 + , N a + , P O 4 P , and S O 4 S concentrations and via continuous flow analysis (CFA) regarding the N O 3 N and N H 4 N concentrations.
Note that reference concentrations are not given for chloride and sodium since we do not consider them to be beneficial nutrients, and therefore, the goal of the optimization is to keep the concentration of these two beneath the maximum concentrations of 276   m g   L 1 and 425   m g   L 1 for Na+ and Cl, respectively.

3.1.1. Focus on Minimizing the Error to the Reference

In the first simulation study, the objective function of the static optimization problem is reduced to the term ω bal , ref · e N MW , ref ( u ) + ω bal , min · e N MW , min ( u ) , i.e., costs are neglected and only reaching the target concentration is considered. The concentrations of the post-mixing nutrient solution can be seen in Figure 3. Furthermore, the resources used are shown in Table 3.
If the solver has a free and unconstrained choice of resources, it is able to set the concentrations of the post-mixing solution very accurately. Both the average and the maximum relative error are less than 0.1 % .
To achieve this accurate solution, the solver chose to use large amounts of FW. TW and RW were consumed at an intermediate level and the use of PW was the lowest compared to the other sources. Furthermore, a high amount of fertilizers was added to the solution.
In the following simulation scenario, aspects of sustainability and recycling are incorporated in the optimization problem by reinstating the error terms e water ( u V ) and e fertil ( u N ) and therefore reducing the consumption of RW, TW and fertilizers and increasing the use of PW.

3.1.2. Minimizing Error to Reference under Optimal Resource Usage

The second simulation study aims to improve the resource management of the mixing tank system in comparison to the previous scenario. To achieve this, the balancing weights of the objective function are now set to their respective values given in Equation (9). Furthermore, the weights ω fertil are set to be equal to one and the weights of the water sources are set as follows:
ω water = 0 ; 1 ; 1 ; 10 ,
which strongly encourages the use of PW while the use of RW, TW, and fertilizers is discouraged. The respective weight of FW is set to zero because the consumption of this source was already high in the first scenario. The results of the optimization are shown in Figure 4 and Table 4.
Due to the penalization of the use of fertilizers, RW, and TW, the consumption of all three resources was greatly reduced. RW consumption was reduced by 53.3 % , TW usage was reduced by 100 % , and fertilizer consumption was reduced by 36.4 % . The main source of water remains the FW, with a consumption of 519.071   L . However, the PW now also provides a substantial share of the total water used. The consumed volume is 210.401   L and therefore 287.7 % higher than in the first scenario.
The adequate consumption of PW was only possible due to a high rewarding weight in the objective function. The main reason for the limited use of this resource is the high sulfate and phosphate concentrations, which greatly exceed the reference value for both nutrients. This can also be seen in in Figure 4, where the post-mixing concentrations are presented. The use of PW resulted in high concentrations of P O 4 P ( 32.4 % higher than the reference). Generally, the new mixing procedure focused on improving resource consumption leads to a higher error—compared to the first scenario—between the nutrient concentrations in the post-mixing solution and the reference value (average relative error 7.7 % ).

3.1.3. Resource Optimization and Additional Constraints on Tracking Accuracy

The results of the previous simulation study show a high concentration of P O 4 P and a minor lack of M g 2 + and N O 3 N . Assuming that a lack of nutrients causes more problems than an oversupply (that does not violate any concentration constraints), this scenario aims to prevent too-low concentrations for each nutrient. For this, the bounds for the minimum ion concentrations in the post-mixing solution are set to the value seen in Equation (25). The new optimization results are shown in Figure 5 and Table 5.
In Figure 5, it can be seen that the concentration of every nutrient in the solution is at least at 95 % of the reference concentration. Thus, the algorithm was able to set the required minimum level and prevent a lack of any nutrient in the prepared solution. However, the higher concentrations of magnesium and nitrogen also lead to an increased consumption of fertilizers. Furthermore, the average relative error increases slightly to a value of 7.8 % .

3.1.4. Resource and Tracking Accuracy Optimization in Different Environmental Conditions

In the fourth simulation scenario, reference concentrations are halved, e.g., in response to a change in weather conditions. The new references are therefore set according to (26). Simulation results are presented in Figure 6 and Table 6. Note that the remaining parameters of the optimization, e.g., constraints and weights, remain the same as in the third scenario.
Figure 6 reveals that the algorithm was able to set the new reference concentrations and that it also incorporates the constraints into the tracking accuracy, because the lowest concentrations relative to the reference in the post-mix solution are given for NO3-N and Mg, which are exactly at 95 % . The highest deviation from the reference is again given for PO4-P, which exceeds the set point by 16.7 % . The average error of the tracking accuracy is 5.2%.
To achieve this adapted nutrient solution, the algorithm now utilizes a high amount of RW, because it contains the lowest concentrations of nutrients. In contrast to that, the consumption of FW was reduced by 51.1 % , the consumption of PW by 54 % and the usage of fertilizer by 49.1 % due to the lower amount of nutrient mass that is needed to realize the new solution.

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 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 PO4-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 P O 4 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 P O 4 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.6GHz, 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. As there is no way to ‘correctly’ calculate the weights ω water , i and ω 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-fertilizer 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., H3PO4) 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. The program’s basic prerequisites are the concentrations of input resources and a standard PC to run the algorithm. There are limitations in operation range of the algorithm. Interactions between ions and consideration of pH and EC values are currently not part of the algorithm. Additionally, precipitation of ion crystals at high concentrations is also not considered. However, by carefully choosing set points for the target solution, the user is able circumvent these limitations. The Outlook describes how future implementations can automate setting concentration reference values.

5. Outlook

A comprehensive dynamic plant nutrient uptake model must be developed to further automate greenhouse and aquaponics operation. This model is necessary to dynamically set reference concentrations of the mixing tank in response to environmental factors like temperature, humidity, irradiance, and the growth status of plants. Such a model can also be used to estimate plant drain re-flow (concentrations and volume), as there may be setups where frequent measurements are not an option, e.g., due to costs. It is also planned to allow the nutrient solution to be replaced multiple times per day, which automates the scheduling of operations. Additionally, it is of interest to also consider EC and pH values. This, however, necessitates further modeling efforts, e.g., for the interactions between nutrients and fertilizers and the pH value. This extension may also account for sedimentation processes.
In the discussion of scenario 3, we remarked that the increase in P O 4 P will eventually, after a few cycles, lead to critical values and make recycling the plant drain water undesirable. A possible extension could thus be a predictive component that estimates the plant uptake and the resulting plant drain, to inform the user of long-term ion accumulations inside the system. This can also be combined with the aforementioned automatic set point calculation.

Supplementary Materials

Supplementary material includes the algorithm, i.e., the Python script (Version 3.11) and xml files, as well as the documentation. It is available in the public repository https://github.com/TUCACSD/NutrientMixingAlgorithm on GitHub.

Author Contributions

Conceptualization, A.K., S.S. and T.R.; methodology, P.N. and A.K.; software, P.N. and A.K.; validation, P.N.; investigation, M.M. and P.N.; resources, S.S.; writing—original draft preparation, A.K., P.N. and M.M.; writing—review and editing, T.R., U.S. and S.S.; visualization, P.N.; funding acquisition, S.S. and U.S. All authors have read and agreed to the published version of the manuscript.

Funding

This research was funded by the Federal Ministry of Education and Research of Germany (BMBF, Germany; grant number 031B0733D; project CUBEScircles).

Institutional Review Board Statement

Not applicable.

Informed Consent Statement

Not applicable.

Data Availability Statement

The raw data supporting the conclusions of this article will be made available by the authors on request. Note: Plant drain nutrient concentration measurements can be made available upon request, but are not necessary to replicate the study. The simulation studies can be replicated using data included in the article and the software provided in the Supplementary Material.

Acknowledgments

We thank Morgan Uland for proof reading and her help in improving readability of this work.

Conflicts of Interest

The authors declare no conflicts of interest.

Abbreviations

The following abbreviations are used in this manuscript:
CEcapillary electrophoresis
CEAcontrolled environment agriculture
CFAcontinuous flow analysis
DRAPSdouble recirculating aquaponic system
FWfish water (drain tank)
IDEintegrated development environment
IoTinternet of things
ISEion-selective electrodes
ISFETion-sensitive field-effect transistors
MWmixing water (tank)
PWplant water (drain tank)
RWrain water (tank)
TWtap water

References

  1. Gao, Z.; Zhong, W. Recent (2018–2020) development in capillary electrophoresis. Anal. Bioanal. Chem. 2022, 414, 115–130. [Google Scholar] [CrossRef] [PubMed]
  2. Gieling, T.; van Straten, G.; Janssen, H.; Wouters, H. ISE and Chemfet sensors in greenhouse cultivation. Sens. Actuators B Chem. 2005, 105, 74–80. [Google Scholar] [CrossRef]
  3. Chowdhury, M.; Ali, M.; Rasool, K.; Jeong, J.H.; Choi, C.H.; Han, M.W.; Ko, H.J.; Chung, S.O. Identification of PID parameters for system-specific nutrient mixing control for ISE-based hydroponic nutrient management. Acta Hortic. 2021, 1312, 567–574. [Google Scholar] [CrossRef]
  4. Cho, W.J.; Kim, H.J.; Jung, D.H.; Kim, D.W.; Ahn, T.I.; Son, J.E. On-site ion monitoring system for precision hydroponic nutrient management. Comput. Electron. Agric. 2018, 146, 51–58. [Google Scholar] [CrossRef]
  5. Tandil, R.; Yapson, J.; Atmadja, W.; Liawatimena, S.; Susanto, R. Hydroponic Nutrient Mixing System Based on STM32; Institute of Physics Publishing: Bristol, UK, 2018; Volume 195. [Google Scholar] [CrossRef]
  6. Xin, L.; Guang, L.; Ming, Y. Design on the Precise Regulating Control System for Moisture and Nutrient of Plants Based on PLC. Phys. Procedia 2012, 33, 429–436. [Google Scholar] [CrossRef]
  7. Rocksch, T.; Schmidt, U.; Kläring, H.P. Development of an optimal model-based ion-specific nutrition control system for horticultural crops. Acta Hortic. 2019, 1242, 605–611. [Google Scholar] [CrossRef]
  8. Tsukagoshi, S.; Shinohara, Y. Nutrition and Nutrient Uptake in Soilless Culture Systems; Academic Press: Cambridge, MA, USA, 2020; pp. 221–229. [Google Scholar] [CrossRef]
  9. Goddek, S.; Espinal, C.A.; Delaide, B.; Jijakli, M.H.; Schmautz, Z.; Wuertz, S.; Keesman, K.J. Navigating towards Decoupled Aquaponic Systems: A System Dynamics Design Approach. Water 2016, 8, 303. [Google Scholar] [CrossRef]
  10. Suhl, J.; Dannehl, D.; Kloas, W.; Baganz, D.; Jobs, S.; Scheibe, G.; Schmidt, U. Advanced aquaponics: Evaluation of intensive tomato production in aquaponics vs. conventional hydroponics. Agric. Water Manag. 2016, 178, 335–344. [Google Scholar] [CrossRef]
  11. Cho, W.J.; Gang, M.S.; Kim, D.W.; Kim, J.; Jung, D.H.; Kim, H.J. Decision-tree-based ion-specific dosing algorithm for enhancing closed hydroponic efficiency and reducing carbon emissions. Front. Plant Sci. 2023, 14, 1301490. [Google Scholar] [CrossRef] [PubMed]
  12. Savvas, D.; Giannothanasis, E.; Ntanasi, T.; Karavidas, I.; Drakatos, S.; Panagiotakis, I.; Neocleous, D.; Ntatsi, G. Improvement and validation of a decision support system to maintain optimal nutrient levels in crops grown in closed-loop soilless systems. Agric. Water Manag. 2023, 285, 108373. [Google Scholar] [CrossRef]
  13. Nocedal, J.; Wright, S. Numerical Optimization; Springer Series in Operations Research and Financial Engineering; Springer: New York, NY, USA, 2006. [Google Scholar]
  14. Papageorgiou, M.; Leibold, M.; Buss, M. Optimierung: Statische, Dynamische, Stochastische Verfahren für die Anwendung; Springer: Berlin/Heidelberg, Germany, 1996. [Google Scholar]
  15. Waechter, A.; Biegler, L.T. On the implementation of a primal-dual interior point filter line search algorithm for large-scale nonlinear programming. Math. Program. 2006, 106, 25–57. [Google Scholar] [CrossRef]
  16. Andersson, J.A.E.; Gillis, J.; Horn, G.; Rawlings, J.B.; Diehl, M. CasADi: A software framework for nonlinear optimization and optimal control. Math. Program. Comput. 2018, 11, 1–36. [Google Scholar] [CrossRef]
  17. McKinney, W. Data Structures for Statistical Computing in Python. In Proceedings of the 9th Python in Science Conference, Austin, TX, USA, 28 June–3 July 2010; Volume 445, pp. 51–56. [Google Scholar]
  18. Lattauschke, G. Nachtschattengewächse-Solanaceae; Eugen-Ulmer-Verlag: Stuttgart, Germany, 2023; pp. 456–486. [Google Scholar]
  19. Chrétien, S.; Gosselin, A.; Dorais, M. High electrical conductivity and radiation-based water management improve fruit quality of greenhouse tomatoes grown in rockwool. HortScience 2000, 35, 627–631. [Google Scholar] [CrossRef]
  20. Delaide, B.; Teerlinck, S.; Decombel, A.; Bleyaert, P. Effect of wastewater from a pikeperch (Sander lucioperca L.) recirculated aquaculture system on hydroponic tomato production and quality. Agric. Water Manag. 2019, 226, 105814. [Google Scholar] [CrossRef]
  21. Wetterdienst, D. Chemical Composition of Precipitation. Available online: https://www.dwd.de/EN/research/observing_atmosphere/composition_atmosphere/aerosol/cont_nav/chemical_composition_of_precipitation_node.html (accessed on 15 July 2024).
  22. ZweckverbandFernwasserSuedsachsen. Trinkwasser-Analyse nach DIN 50930, Mischwasser aus Einsiedel und Burkersdorf—Jahresauswertung 2023. Available online: https://www.eins.de/_Resources/Persistent/4/2/d/a/42dad36fea920787251d2ec5116472a50972c820/Mischwasser2023.pdf (accessed on 15 July 2024).
Figure 1. Schematic description of the multi-tank system for mixing nutrient solutions.
Figure 1. Schematic description of the multi-tank system for mixing nutrient solutions.
Applsci 14 08140 g001
Figure 3. Resulting normalized concentrations of nutrients in the solution when only the reference error is minimized.
Figure 3. Resulting normalized concentrations of nutrients in the solution when only the reference error is minimized.
Applsci 14 08140 g003
Figure 4. Resulting normalized concentrations of nutrients in the solution when the reference error and consumption of resources are optimized.
Figure 4. Resulting normalized concentrations of nutrients in the solution when the reference error and consumption of resources are optimized.
Applsci 14 08140 g004
Figure 5. Resulting normalized concentrations of nutrients in the solution when the concentrations of the final solution are constrained by (25).
Figure 5. Resulting normalized concentrations of nutrients in the solution when the concentrations of the final solution are constrained by (25).
Applsci 14 08140 g005
Figure 6. Resulting normalized concentrations of nutrients in the solution in a sunnier and drier environment.
Figure 6. Resulting normalized concentrations of nutrients in the solution in a sunnier and drier environment.
Applsci 14 08140 g006
Table 1. Nutrient concentrations of water sources and starting and reference values of concentrations in mixing tank in 10 3 g   L 1 .
Table 1. Nutrient concentrations of water sources and starting and reference values of concentrations in mixing tank in 10 3 g   L 1 .
Nutrient PW FW [20] RW [21] TW [22] c MW , q , pre c MW , q , ref
N O 3 N 37210.41.4122.5122.5
N H 4 N 240.60.0240.340.3
K + 231120.11.6207.2207.2
C a 2 + 1491440.219.2124.2124.2
N a + 244880.1110.6276-
C l 3001270.1517.4425-
P O 4 P 19820.30.00242.642.6
S O 4 S 236330.3985.985.9
M g 2 + 92170.053.543.843.8
F e 2 + 20.0600.0120.80.8
Table 2. Nutrient composition of fertilizers in %.
Table 2. Nutrient composition of fertilizers in %.
Nutrient Ca ( NO 3 ) 2 K N O 3 K 2 S O 4 N H 4 N O 3 M g S O 4 Fe-Chelat K H 3 P O 4
N O 3 N 15.513.7017.5000
N H 4 N 00017.5000
K + 038.44500028.2
C a 2 + 19.9000000
P O 4 P 00000022.7
S O 4 S 0018012.500
M g 2 + 00009.600
F e 2 + 0000060
Table 3. Nutrient sources used for mixing when only the reference error is minimized.
Table 3. Nutrient sources used for mixing when only the reference error is minimized.
Water SourceUsed Amounts for Mixing in LFertilizerUsed Amounts for Mixing in g
FW 424.812 C a ( N O 3 ) 2 117.09
K N O 3 256.594
PW 73.125 K 2 S O 4 50.164
N H 4 N O 3 180.962
RW 146.616 M g S O 4 210.046
Fe-Chelat7.651
TW 146.145 K H 3 P O 4 72.654
Total790.698Total822.507
Table 4. Nutrient sources used when optimizing the reference error and the consumption of resources.
Table 4. Nutrient sources used when optimizing the reference error and the consumption of resources.
Water SourceUsed Amounts for Mixing in LFertilizerUsed Amounts for Mixing in g
FW 519.071 C a ( N O 3 ) 2 0
K N O 3 292.758
PW 210.401 K 2 S O 4 0
N H 4 N O 3 181.379
RW 68.529 M g S O 4 46.181
Fe-Chelat3.099
TW 0 K H 3 P O 4 0
Total798Total523.417
Table 5. Nutrient sources used when the concentrations of the final solution are constrained by (25).
Table 5. Nutrient sources used when the concentrations of the final solution are constrained by (25).
Water SourceUsed Amounts for Mixing in LFertilizerUsed Amounts for Mixing in g
FW 522.608 C a ( N O 3 ) 2 0
K N O 3 305.106
PW 209.241 K 2 S O 4 0
N H 4 N O 3 184.362
RW 66.151 M g S O 4 52.553
Fe-Chelat3.134
TW 0 K H 3 P O 4 0
Total798Total545.155
Table 6. Nutrient sources used in a sunnier and drier environment.
Table 6. Nutrient sources used in a sunnier and drier environment.
Water SourceUsed Amounts for Mixing in LFertilizerUsed Amounts for Mixing in g
FW 255.303 C a ( N O 3 ) 2 0.208
K N O 3 153.415
PW 96.202 K 2 S O 4 0
N H 4 N O 3 89.377
RW 446.495 M g S O 4 32.91
Fe-Chelat1.787
TW 0 K H 3 P O 4 0
Total798Total277.697
Disclaimer/Publisher’s Note: The statements, opinions and data contained in all publications are solely those of the individual author(s) and contributor(s) and not of MDPI and/or the editor(s). MDPI and/or the editor(s) disclaim responsibility for any injury to people or property resulting from any ideas, methods, instructions or products referred to in the content.

Share and Cite

MDPI and ACS Style

Kobelski, A.; Nestler, P.; Mauerer, M.; Rocksch, T.; Schmidt, U.; Streif, S. An Algorithm for Nutrient Mixing Optimization in Aquaponics. Appl. Sci. 2024, 14, 8140. https://doi.org/10.3390/app14188140

AMA Style

Kobelski A, Nestler P, Mauerer M, Rocksch T, Schmidt U, Streif S. An Algorithm for Nutrient Mixing Optimization in Aquaponics. Applied Sciences. 2024; 14(18):8140. https://doi.org/10.3390/app14188140

Chicago/Turabian Style

Kobelski, Alexander, Patrick Nestler, Mareike Mauerer, Thorsten Rocksch, Uwe Schmidt, and Stefan Streif. 2024. "An Algorithm for Nutrient Mixing Optimization in Aquaponics" Applied Sciences 14, no. 18: 8140. https://doi.org/10.3390/app14188140

Note that from the first issue of 2016, this journal uses article numbers instead of page numbers. See further details here.

Article Metrics

Back to TopTop