Optimized Planning of Different Crops in a Field Using Optimal Control in Portugal

: Climate change is a proven fact. In the report of 2007 from IPCC, one can read that global warming is an issue to be dealt with urgently. In many parts of the world, the estimated rise of temperature (in a very near future) is signiﬁcant. One of the most affected regions is the Iberian Peninsula, where the increasing need for water will very soon be a problem. Therefore, it is necessary that decision makers are able to decide on all issues related to water management. In this paper, we show a couple of mathematical models that can aid the decision making in the management of an agricultural ﬁeld at a given location. Having a ﬁeld, in which different crops can be produced, the solution of the ﬁrst model indicates the area that should be used for each crop so that the proﬁt is as large as possible, while the water spent is the smallest possible guaranteeing the water requirements of each crop. Using known data for these crops in Portugal, including costs of labour, machines, energy and water, as well as the estimated value of the products obtained, the ﬁrst mathematical model developed, via optimal control theory, obtains the best management solution. It allows creating different scenarios, thus it can be a valuable tool to help the farmer/decision maker decide the crop and its area to be cultivated. A second mathematical model was developed. It improves the ﬁrst one, in the sense that it allows considering that water from the rainfall can be collected in a reservoir with a given capacity. The contribution of the collected water from the rainfall in the proﬁt obtained for some different scenarios is also shown.


Introduction
Climate change is a proven fact. In the report of 2007 from IPCC [1], one can read that global warming is an issue to be dealt with urgently. Temperature will raise, and longer and more frequent draught periods will occur. One of the most affected regions will be the Iberian Peninsula. In the south of Iberia, extreme draught periods are already very frequent. Our study considered Portugal, but it could easily be adapted to another part of the world. In this scenario, it is necessary that the decision makers are able to decide on all issues related to water management.
Irrigation of crop fields spends the most water resources in Portugal annually. Thus, it becomes crucial that a proper irrigation plan can maximize the profits of a crop field, while spending the least water resources possible, with the highest efficiency [2]. In this paper, the authors contribute to achieving such an objective. plan the percentage of area for each crop in such a way that the profit is maximum, while minimizing the water spent and assuring the water requirements of each crop. The optimal control theory allows defining an objective function that is the sum of the profits obtained for each crop, taking into account the value of the crop, the costs of production, the costs of water, and the type of weather conditions.The dynamic equation considered guarantees the water balance (taking into account rainfall, irrigation, humidity in the soil, evapotranspiration and losses due to infiltration), the constraints considered guarantee that the crops have their needs of water fulfilled. Therefore, this model is better than others based on GA, and assures that water balance is never broken. On the other hand, optimal control is able to guarantee a smoother solution, not present in "on-off" type irrigation systems, since the weather and an economic forecast are used.
The possibility for the farmer to build a reservoir (also considered in [17]) of a given capacity to collect rainwater was considered, and it was the basis for the second mathematical model proposed in this paper. Since climate change is showing us that water availability is going to drop, planning a proper reservoir to collect rainfall is crucial to preserve the crops and increase profit. It is possible to use the second model to solve the problem where there is no reservoir. However, the number of variables involved double, and the CPU time to solve it is greatly increased.
This paper is divided into five sections. The Introduction is presented in the Section 1. In Section 2, two models for optimized management of a field with several crops are presented. Data for the numerical model are introduced in Section 3. Results for each model are shown and discussed in Section 4. Finally, conclusions are presented in Section 5. Two appendixes are also included at the end of the paper.

Mathematical Models Considered
In this section, two mathematical models in the same framework are presented. The first model maximizes the profit of a field with several crops while minimizing the water consumption in irrigation and keeping the crops safe. It also gives the farmer information on which percentage of the area should be allocated to each crop. A second model considers the possibility that the farmer builds a reservoir of a given capacity to collect rainwater.

Management of a Field with Several Crops Using the Profit as Objective Function
In optimal control problems, there are two types of variables: the state and the control variables. The state variables are defined through differential equations and the control variables are the decision variables to minimize (or maximize) an objective function.
The state variables are the following: x i is the amount of water in the soil (m 3 per m 2 ) for the sub-field i. The control variables are defined as: u i is the water (m 3 /month per m 2 ) introduced in sub-field i via its irrigation system and A i is the percentage of the area of each sub-field i. It is assumed that in each sub-field exists only one crop.
The objective function is the sum of the revenue of each crop: where T is the number of months considered in the model, N is the number of sub-fields with a certain crop, C C is the value of that crop (euro/hectare), P W is the price of water per m 3 , 10,000 u i is the irrigation per hectare, and C P is the cost of production (euro/hectare) of the crop (including labour, machines, and energy, among others) [18][19][20] defined as: where K i is a constant that ensures that the average cost of crop i (AVC i ) has a certain value per hectare, which can be consulted in literature ( . This function assumes the costs are greater for smaller areas, then decreases until a certain area value, and finally increases again, as shown in Figure 1. The function is a mathematical attempt to describe this behavior for the cost. The constants present in the above formula are such that the costs of the crop as function of its area are a continuous function. Note that data on average cost values as function of the area are not available. We note that this function can be easily replaced by the real cost values per area for each crop in the Matlab programme that was developed. The variation of the water in the soil is given by the water balance equation [21]. Water enters from irrigation systems (u) and precipitation (g in m 3 /month per m 2 ), water exits via evapotranspiration (h in m 3 /month per m 2 ) and percolation (βx in in m 3 /month per m 2 ). β (in percentage/month) is a parameter that depends on the type of soil. The model of percolation has been defined in order that the humidity of the soil decreases exponentially, as in Horton's equation [22].
Therefore, for each sub-field i, the water balance equation is given by: We note that each sub-field has only one crop. To ensure that the crop does not die because of lack of water, the water in the soil has to be greater or equal to the hydric needs of each crop x min i .
A i is the percentage of the total area that is devoted to crop i. It is assumed that at least two crops exist, meaning that A i is never 0. In our programme. we considered that Note that the sum of all A i is equal to 1.
The control variable is bounded by, where M i is the maximum value of irrigation. In theory, it could be infinite, but the model demands it to be finite. It was considered to be a very large number. The initial values of the water in the soil for each culture x 0 i are given as

Using Reservoir for Rainwater Collection
The model presented in this section improves the last one. This model contemplates the possibility that the farmer intends to build a reservoir to collect water from rainfall. In this new model, the state variables are the following: x i is the water in the soil of sub-field i and y is the total of amount of water stored in reservoir (in m 3 per m 2 ). The control variables are defined as: u i is the water flow introduced in sub-field i via its irrigation system (in this case the water comes from the tank), A i is the percentage of the area of each sub-field i and v is the water flow coming from the water supply network ( in m 3 /month per m 2 ).
The objective function is the sum of the revenue of each crop: where T 0 v(t)dt is the total amount of water from the water supply network to fill the tank if necessary. The equation that stands for the water balance in the field does not change.
The variation of water in reservoir is equal to the water flow coming from the water supply network (v), plus the water that is collected from the precipitation Pg(t) ( in m 3 /month per m 2 ), minus the water used in the irrigation systems for each sub-field ∑ N i=1 A i u i (t). The variation of water in reservoir is written as:ẏ where P is the percentage of water from rainfall that is collected, and g is the precipitation (in m 3 /month per m 2 ) at the time t.
The maximum amount of water in the tank is y max , where y max is the maximum amount of water in the reservoir. The value of the flux of water taken from the water supply network is limited, where V max is necessary to impose in order to obtain a limited interval for v(t).
The initial amount of water in the tank is, where y 0 is a given value. The detailed optimal control formulations of the problems described in Sections 2.1 and 2.2 are in Appendices A and B.

Data for the Numerical Model
The models presented in the previous section allow considering many crops. Since we chose Portugal as the study site, we had to use crops that are widely cultivated there, and for which we had enough data. We considered only two crops so that the results are easier to present. The crops considered in our study were olive trees and vines. Using known data from these cultures in Portugal, including cost of labour, machines, energy and water, as well as the estimated value of the products obtained per hectare, it was possible to determine the cost function of each crop per hectare. The cost function used, as explained in previous sections, takes into account these data.
In the rural region of the Lisbon district, the values of olives and grapes are in the interval of [750, 1760] euro/ hectare and [2700, 3300] euro /hectare, respectively. The price of water is 0.07 euro/m 3 , the cost of labour, machines, energy and services are on average 700 euro/hectare for olive trees and 2780/hectare for vines [18][19][20].
We also considered the rainfall to be the average of the rainfall in the last 10 years for each month of the year, as shown in Table 1 [23]. To create the possibility of different weather scenarios, the above table is multiplied by a precipitation factor: rain f all(t i ) = precipitation factor × rain monthly average(t i ), (14) where the precipitation factor allowed us to consider a typical year if this factor is 1, a drought year if it is less that 1 and a rainy year if it is above 1 [24]. The Pennman-Monteith methodology [25] was used to calculate evapotranspiration of the cultures along the year, from the following equation where K c is the culture coefficient for the evapotranspiration and ET 0 is the tabulated reference value of evapotranspiration from [26] for the Lisbon region. The evapotranspiration of the cultures in Lisbon is given in Table 2. The following data were also considered to perform simulations in Section 4:

Results
In this section, the results from the models described in Sections 2.1 and 2.2 are presented for a set of different scenarios. Here, it is possible to see how changes in weather conditions, economic conditions, etc. can affect the value of the profit obtained.

Results for the Model Presented in Section 2.1
In this subsection, we start by presenting the results of the model in Section 2.1, for medium scenario, called base scenario. We considered the following parameters for the base scenario: value of olives is V 1 = 1100 euro/hectare, value of grapes is V 2 = 3100 euro/hectare, price of the water os CW = 0.07 euros/m 3 , the cost of labour, machines, energy and services (production costs) are on average Apc 1 = 700 euro/hectare for olive trees and Apc 2 = 2780 euro/hectare for grapes, defined in a cost function dependent on the area, as explained in Section 2.1. Using the base scenario, we obtained the results in Table 3. We also created weather scenarios with the precipitation factor (F). It is considered an average precipitation when precipitation factor (F) is 1, while, if it is above 1, it means a rainy year, and, if is is below 1, it means a drought year.
We created many possible scenarios (S), which gave completely different results, as it can be read in Table 4. Note in Scenarios 1-4 the only data that change are the values of product 1 (olives, obtained from olive trees) and product 2 (grapes, obtained from vines). In Scenarios 5 and 6, everything is equal to the base scenario, except the price of water (CW = 0.07 euros/m 3 versus CW = 0.14 euros/m 3 ). In Scenario 7, the only difference to the base scenario is that the production costs of olives grew by 10% and the production costs of vine grew by 20%. In Scenarios 8 and 9, the only differences with the base scenario are the value of the precipitation factor (F = 1.2 versus F = 0.25) and the price of water (only in Scenario 9, CW = 0.14 euros/m 3 ). In Scenario 8, we have a rainy year, and, in Scenario 9, we have a very severe draught year. In Scenario 9, the price of water increases because the country is facing a severe draught. In Figure 2, we may see the results for water in the soil (blue line is the trajectory) and the irrigation needed (red line is the control) per m 2 in each month, for each crop for the base scenario. As expected, irrigation starts in May/June and ends in September of the year in study. This is a normal result since we are considering an average year in Portugal. The months where rain becomes scarce are May, June, July and August. In Scenarios 1-4, we see that the profit (Prf in Table 4) is highly dependent on the value of the products. In Scenarios 5 and 6, the influence of price of water was studied. Once again, we verify that, if the price of water increases (which is expected in the near future), the profit results drop significantly. In Scenario 7, we studied the influence of growing costs of production. In such a case, the profit can become loss very easily. To obtain a better model, provided enough data are available, a time series study could be used to better estimate the costs of production. In Scenario 8 (see Table 4), the rainfall is 20% above normal year rainfall, so the irrigation will be less used. Note the area below the red line and above the time axis is smaller in Figure 3 than the one in Figure 2. This means that less water is spent in Scenario 8 than is the base scenario. Once again, this is not a surprise since, if it rains more, irrigation needs are smaller. In Scenario 9 (see Table 4), the rainfall is 75 % below normal year rainfall, so irrigation will increase greatly, and, consequently, the price of water will increase. This is a drought year. Note the area below the red line and above the time axis is much larger in Figure 4 than the one in Figure 2. In addition, irrigation starts earlier and ends later in the year. Studying the pattern of the precipitation and its tendency along the years to come is very important.
In Table 4, one may see that, by changing the scenario, the expected profit changes greatly, as does the area dedicated for each crop. As expected, the value of the crops that the farmer obtains for each crop is essential for a good profit. The most important conclusion is that, by changing the price of water (that will increase for sure in a near future) or the precipitation factor (F) for a smaller value (draughts are expected to be more severe and occur more often in Portugal), the profit transforms into loss very easily. This tells us that any means of increasing the efficiency of water used in irrigation, or by collecting the rainfall into a reservoir is essential. In addition, by running our programme, the decision maker may decide to consider other types of crops that may not need so much water. All he has to do is to change a few parameters that are associated to the crops and rerun the programme.

Results for the Model Presented in Section 2.2-With a Reservoir to Collect Rainfall
To test the second mathematical model, the base scenario used is the same as for the first mathematical model. As expected, the numerical results are the same (see Tables 3 and 5).
In the case that water from the rainfall is collected, it is important to know how the profit changes. Two scenarios were simulated. In the first one, 1% of water from rainfall is collected and, in the second one, 5% of water from rainfall is collected. In the first case, the profit increased to 235 euro/hectare and in the second one the profit increased to 250 euro/hectare. The total water used decreased to 0.2613 m 3 per m 2 of area and 0.2393 m 3 per m 2 of area, respectively, in the first and second scenarios. In Figure 5, it is possible to see the variation of the water in the reservoir and the amount of water used from the water supply network.  Another important issue is to study how a drought year affects the farmer's results if he builds a reservoir to collect rainwater with a certain capacity. To do so, we considered the factor precipitation F = 0.25. Different situations are considered. The percentage of water that is collected in the reservoir is P = 1% or P = 5% of the rainwater, and the price of water is CW = 0.07 or CW = 0.14 euros. Results can be seen in Table 6.
Note that, in the near future, severe draughts will occur with a higher frequency. Chances are that governments will no longer be able to subsidise the price of water. This means we could face a situation such as the one in the fourth column of Table 6.

Conclusions
Climate change and global warming are facts and are here to stay. In many parts of the world, the estimated rise of temperature for a very near future is significant, and water shortages will happen. One of the most affected regions is the Iberian Peninsula. In Portugal, most water is spent in agriculture, thus a proper irrigation plan is crucial. It is necessary that the crops chosen are the best fit for the farm field, the least amount of water (keeping the crops safe) is spent, the economic results are good and the efficiency in the use of water is as high as possible.
A first mathematical model, based on optimal control theory was implemented in Matlab. Its inputs were the weather variables, the location (the results presented consider the area of Lisbon in Portugal), the type of soil, the value of the crops, the costs of the crops, and the cost of water. The outputs were profit, the percentage of the area to be allocated to each crop, and an irrigation plan for the farm that guarantees the crops are safe.
A second model (also implemented in MatLab and based on optimal control theory) improved the first one, by giving the farmer the possibility of building a reservoir of a given capacity to collect rainwater, and therefore improving the profits and spending less water. The outputs were the profit, the percentage of the area to be allocated to each crop, the amount of water in the tank, and an irrigation plan for the farm that guarantees the crops are safe.
We believe the models developed can help to make the best management decisions when designing (partially designing) a crop field. The developed Matlab application can be easily adapted to a different location or crops.
The presented mathematical models can be improved, taking into account a prediction of the weather variables and economic variables, using for example time series.

Appendix A
The optimal control formulation of the problem for the model presented in Section 2.1 is as follows: where the constant parameters involved are the following: N : number of crops; C C : value of the crop to the farmer; C P : cost of production; P W : price of water; β : the percentage of water losses in the soil; x min i : hydric needs of crop i; M i : maximum water flow coming from the irrigation system for crop i; and x 0 i : the initial humidity of the soil for crop i.
The state variables are (x i ) and the control variables are (u i , A i ) for i = 1, . . . , N.
x i (t) : water in the soil of crop i at time t; u i (t) : water flow introduced in crop i via its irrigation systems at time t; A i : percentage of the total area that sub-field where crop i has; g(t) : the precipitation at time t; and h i (t) : the evapotranspiration at time t of crop i;

Appendix B
The optimal control formulation of the problem for the model presented in Section 2.2 is as follows: subject to: where the constant parameters involved are the following: N : number of crops; P : percentage from rainfall that is collected in the reservoir; C C : value of the crop to the farmer; C P : cost of the production; P W : price of water; β : the percentage of water losses in the soil; x min i : hydric needs of crop i; y max : the maximum amount of water in the reservoir; V max : the maximum value of the flux of water taken from the water supply system; M i : maximum water flow coming from the water supply network for crop i; x 0 i : the initial humidity of the soil in crop i; and y 0 : the amount of water in the reservoir at initial time.
The state variables are (x i , y) and the control variables are (u i , A i , v) for i = 1, . . . , N.
x i (t) : water in the soil of crop i at time t; u i (t) : water flow introduced in crop i via its irrigation systems at time t; y(t) : total of amount of water stored in reservoir at time t (maximum capacity y max ); A i : percentage of the total area that sub-field i has; v(t) : total water flow coming from the water supply network at time t; g(t) : the precipitation at time t; and h i (t) : the evapotranspiration at time t of crop i;