Greenhouse Modeling Using Continuous Timed Petri Nets

This paper presents a continuous timed Petri nets (ContPNs) based greenhouse modeling methodology. The presented methodology is based on the definition of elementary ContPNmodules which are designed to capture the components of a general energy and mass balance differential equation, like parts that are reducing or increasing variables, such as heat, CO 2 concentration, and humidity.The semantics of ContPN is also extended in order to deal with variables depending on external greenhouse variables, such as solar radiation. Each external variable is represented by a place whose marking depends on an a priori known function, for instance, the solar radiation function of the greenhouse site, which can be obtained statistically. The modeling methodology is illustrated with a greenhouse modeling example.


Introduction
Greenhouses allow increasing the quantity and improve the quality of the crops produced inside them.The automation of greenhouses has been one of the main topics regarding greenhouse functioning and production, since using control loops, tuned as the agronomist and biologist researchers propose, improves the use of water, energy, and fertilizers.Simultaneously, the volume and quality of crops are increased.
One of the main problems in controlling greenhouses is obtaining a fine mathematical greenhouse model capturing the actual greenhouse behavior since the models are represented by nonlinear differential equations including disturbances where the parameters are time variant.The derived models lead to very complex differential equations and they are hard to obtain.
In order to obtain a greenhouse model, researchers use many approaches; most of them are based on heat and mass balance equations.In [1], a greenhouse model, including natural ventilation and evaporative cooling, is presented.The authors use heat and mass balance equations to derive the model.Since that approach includes a linearization stage, the model is valid only around the operating point.Another approach deals with linear and nonlinear identification of the greenhouse behavior using neural networks [2].This method uses, however, a large amount of data samples due to their large number of degrees of freedom, and it also requires a large computation time for training the neuronal network.In [3] a robust method for nonlinear identification of a climate system using evolutionary algorithms was proposed.Although the model is validated, the convergence of the algorithm could be too long.In [4] a fuzzy model of a greenhouse by taking heat and water measurements is proposed.However, the number of fuzzy rules needed to compute an actual greenhouse model is too large and it is not clear how to find out the rules.
The approach herein presented uses continuous timed Petri nets (ContPNs) [5,6] to capture the greenhouse dynamics.We propose a bottom-up modeling methodology: first, ContPN elementary modules (balance, generation, consumption, and fluid balance) are defined to represent the basic components of an energy and mass balance equation such as storage, source, loss, generation, and consumption of mass or energy.A balance module representing any energy or mass balance equation is obtained by merging these elementary  The greenhouse ContPN modeling methodology presented in this paper provides a pictorial representation of variables which allows easy understanding of the interaction between places (variables).Also, the ContPN model allows having a modular model where elements can be added or removed as necessary.The lack of negative values in Petri nets does not affect the system modeling because the greenhouse climate (temperature, water vapor concentration, and CO 2 concentration) is a positive system.This work is organized as follows.In Section 2, some concepts about Petri nets are presented and the extended semantics is proposed.In Section 3, a Petri net modeling procedure for greenhouses is proposed.Section 4 presents an example of a greenhouse modeled with ContPN.Finally, in Section 5 some conclusions are given.

Petri Nets Concepts.
This subsection introduces basic concepts on continuous timed Petri nets.In order to have more detailed information, an interested reader may also consult [7][8][9][10].Each place   has a marking denoted by A transition   ∈  is enabled at marking m if and only if, for all   ∈ •  ,   > 0. Its enabling degree is given by enab (  , m) = min The enabling degree determines the maximum amount of   that can be fired at marking m leading to a new marking; thus m  = m + [•, ] where 0 <  < enab(  , m).
If m is reachable from m 0 by firing the finite sequence  of enabled transitions, then m = m 0 + C ⃗  is named the CPN state equation, where ⃗  ∈ {R + ∪ 0} || is the firing count vector; that is, ⃗   is the cumulative amount of firing of   in the sequence .
The set of all reachable markings from m 0 is called the reachability set and it is denoted by RS(, m 0 ).In the case of a CPN system, RS(, m 0 ) is a convex set [11].
A CPN is bounded when every place is bounded; that is, for all  ∈ , ∃  ∈ R s.t.[] ≤   at every reachable marking m, and it is live when every transition is live (it can ultimately be fired from every reachable marking) [8].Definition 2. A continuous timed Petri net is a 3-tuple ContPN = (,,m 0 ), where (, m 0 ) is a CPN and  :  → {R + } || is a function associating a firing rate with each transition.
The state equation of a ContPN is where  is the time variable, f() = σ ().
where   is the flow of transition   and the th entry of the vector f.Notice that ContPN under infinite server semantics can actually be considered as a piecewise linear system (a class of hybrid systems) due to the  operator that appears in the enabling function in the flow definition.Equation ( 2) can be expressed as a piecewise linear system given by The firing rate matrix is denoted by Λ = diag( 1 , . . .,  || ).A configuration of a ContPN at  is a set of (, ) arcs describing the effective flow of all transitions: In order to apply a control action in (2), a subtracting term u, such that 0 ≤   ≤   , is added to every transition   to indicate that its flow can be reduced.This control action is adequate because it captures the real behavior that the maximum machine throughput can only be reduced.Thus, the controlled flow of transition In order to obtain a simplified version of the state equation, the input vector u is rewritten as u = I  ΛΠ(m) ⋅ m, where I  = diag(  1 , . . .,   || ) and 0 ≤    ≤ 1.Then the matrix I  = I − I  is constructed and the state equation can be rewritten as  Notice that 0 ≤    ≤ 1.A transition is called noncontrollable when its flow cannot be reduced.Every non-controllable transition   has associated a constant input control    = 1.

ContPN with Extended
Semantics.Regular ContPN models do not include disturbances and nonlinearities; therefore it is required to add semantics that allow us to incorporate them.
Definition 5. A place is called a function place if its marking at time  is determined by the actual marking of other places or external disturbances.Thus, the marking of a function place  is described by where []() is the marking of place  at time , ℎ(•) is a known function, and  is a measurable disturbance.Notice that the marking of function places is not determined directly by the differential equations.Also, since function places are mainly seen as disturbances, their markings do not represent controllable variables.Definition 6.A ContPN that includes function places is called a ContPN with extended semantics.
From now on, all ContPNs in this paper are considered with extended semantics.

Mass and Energy Balance Equations.
From experience, it is well known that matter and energy may change their form, but they cannot be created or destroyed.This notion is expressed in the general mass and energy balance equation: where  is the accumulated quantity (final amount of quantity minus initial amount of quantity) inside the system boundary during the time interval [ 0 ,   ],  in is the amount of quantity entering the system through the system boundary,  out is the amount of quantity leaving the system through the system boundary,  gen is the amount of quantity generated (i.e., formed) inside the system boundary,  con is the amount of quantity consumed (i.e., converted to another form) inside the system boundary, and a quantity may be in any mass or heat unit.Nevertheless, all environmental influences over a greenhouse, manipulated or not, fulfill the energy and mass balance equation (10).For example, a simple heat balance equation is depicted in Figure 1, where the heat source, for instance, solar radiation, is the heat entering ( in ) into a greenhouse system; the heat storage, the greenhouse itself, is the heat absorbed () by the greenhouse system; and the heat to surroundings, for instance by ventilation, is the heat loss ( out ) outside the greenhouse system.

Modeling Methodology
For the generated and consumed flows, some examples are as follows: the energy gained from condensation is part of the generated heat  gen ; the energy consumed by evaporative cooling is part of the heat consumed  con .
Therefore, we propose a modeling approach based on the construction of ContPN modules that represent each component of the balance equation.

Elementary
Modules.Some modules are defined in order to represent the flows in the balance equation.A first approach to a balance module is obtained from Figure 2.
The ContPN of Figure 2 has the following matrices: Thus, the marking equations are given by The balance of the marking is given when the steady state markings of  1 and  2 are equal.So, the equilibrium points of the previous equations must be  1 =  2 .Thus, the required relationships are Replacing the latter relationships, the equations of the marking are For example, given a temperature in  1 and a different temperature in  2 , the difference between  1 and  2 is given by the heat capacity of each system.
In order to prove that the equilibrium points are stable, the Lyapunov function (m) = (1/2 1 ) 2  1 + (1/2 2 ) 2 2 is used, where the derivative of (m) is given by which is negative for any  1 ̸ =  2 , so the equilibrium points are stable.
The number of tokens in the steady state depends on the initial values  1 (0) and  2 (0).The marking at the equilibrium point can be separated in three cases:  1 <  2 ,  1 >  2 , and  1 =  2 .
If  1 <  2 ,  1 gains (or losses) tokens faster than  2 losses (or gains) them, so the steady state marking value is closer to  1 (0).If  1 >  2 ,  1 gains (or losses) tokens faster than  2 losses (or gains) them, so the steady state marking value is closer to  2 (0).In case  1 =  2 , the steady state marking is given by ( 1 (0) +  2 (0))/2.The balance module as presented in Figure 2 with restrictions (13) can be represented as the ContPN of Figure 3 when one of the variables is measured (  is a function place) and its dynamics are not modeled.In order to represent a balance, the transitions   1 and   2 have the same firing rate   1 =   2 .Thus, the equation of the ContPN of Figure 3 is For generation and consumption flows, the ContPNs of Figures 4 and 5 are used, respectively.
The heat and mass balance can be carried out by a fluid that affects proportionally the transfer between variables.In that case, a ContPN as in Figure 6 is used.This ContPN is defined with product semantics in order to represent the product of the fluid  conv with the variables  var and   .
There are modules dependent on a device, but the device dynamics is considered to be faster than the greenhouse dynamics, so the dynamics of the devices are not modeled.The only difference is that transitions related to devices are controllable; that is, the transitions of a device module have the form      as stated in Section 2.

Greenhouse ContPN Model.
Since every greenhouse physical variable fulfills the energy and mass balance equation, we propose a modeling approach based on the construction of modules as described in the following.

Modeling Procedure
(1) Create places for variables and function places for disturbances.
Variable places capture the greenhouse variables (such as soil temperature, air temeprature, and CO 2 concentration) and function places capture external variables (such as solar radiation and external temperature) (2) Construct a module for each variable of interest in the greenhouse.
(2a) A balance module is associated with each physical exchange (heat or mass) affecting the corresponding variable (e.g., ventilation, conduction).(2b) A generator module is associated to each physical transformation inside the greenhouse which increases the corresponding variable (e.g., evapotranspiration). (2c) A consumption module is associated with each physical transformation inside the greenhouse which decreases the corresponding variable (e.g., condensation, evapotranspiration). (2d) A fluid balance module is associated with each physical exchange (heat or mass) affecting the corresponding variable with the proportional effect of a fluid (e.g., natural ventilation).
Following the previous procedure we obtain the greenhouse  model.For a practical illustration, we show in the next section the greenhouse ContPN modeling of two climate variables: temperature and water vapor concentration.

Greenhouse Modeling Example
Consider the greenhouse climate system of Figure 7.We want to obtain the greenhouse temperature and water vapor concentration model.According to step 1 of the modeling procedure, we have to associate places for the involved variables: greenhouse temperature   , soil temperature   , and one for the vapor concentration  H 2 O as shown in Table 1.
The function places associated with the other variables are  4 to solar radiation   ,  5 to outside temperature   ,  6 to subsoil temperature  ss ,  7 to outside water vapor concentration  H 2 O, ,  8 for wind speed V,  9 to humidifier maximum water flow  hum , and  10 to water condensation  cons .
Following step 2, for the greenhouse temperature   we construct generation module for solar radiation ( ); and fluid balance module for leaks dependent on wind ( Since soil temperature is also modeled, we construct balance module for greenhouse temperature   (   bal ) and subsoil temperature (  ss bal ).Then, modules for each variable are constructed as shown in Table 2.
Then, we merge all constructed modules.Thus, we obtain the ContPN depicted in Figure 8, with state equations: these environmental variables are changing; nevertheless, we can add sensors in order to measure them.It has to be noted that the energy balance between  1 and  2 is related by − 7  1 + 8  2 and, since a balance module is used,  7 =  8 , so the balance can be referred to as  8 ( 2 − 1 ) which is an energy exchange.
A similar procedure can be done for the remaining terms of ṁ1 ,  4 , and  1 are related by a balance module,  5 and  1 by two-fluid balance module (one is controllable, but the other is not); it gains energy from  4 ; it also gains and loses water because of   and   , respectively.It has to be noted that, for a greenhouse temperature above 273 ∘ K, the tokens in  1 will be higher than the tokens in  9 and  10 .
In the case of ṁ2 , the relations are only balance modules between  2 and  1 or  6 .For ṁ3 , there is a balance module between  3 and  7 ;  7 and  3 are related by two-fluid balance module (one is controllable, but the other is not); it gains and loses water because of   and   , respectively.
The identification of the model parameters can be carried out according to the preferred method.In this example, the least square method is used.The model proposed in [12] is taken as the real system and the ContPN model depicted in Figure 8 will be the identified model.In order to simplify the method, the identification is carried out in two steps.In the first one the firing of controllable transitions is avoided (i.e., the parameters associated with noncontrollable transitions are computed).These parameters are fed to the second identification step.In this step the parameters associated with controllable transitions are derived and the whole ContPN model is obtained.
We are using the parameters values presented in [12, Chapter 7, pp.135-150] without any crop inside the greenhouse and heating pipes are not considered.Besides, we add humidifier dynamics and external weather variables are considered as a sine function at different frequencies and amplitudes.The identification was carried out using the least squares method.The simulation time for the original model is 8 hours, so the functions used to approximate the external variables are positive during the simulation time.The following external variables were considered for the identification: The percentage of use of the actuators is presented as follows: 1 = 0.5 + 0.5sin (0.001) ,  2 = 0.133sin (0.00011) . ( The initial conditions are In order to validate the proposed modeling methodology, we now present a comparison between our model and the one proposed by [12].All the simulations and identification were carried out in MATLAB and Simulink. In Figure 9, a comparison between the ContPN greenhouse temperature model and the one used by [12] is presented.In Figure 10, a comparison between the ContPN greenhouse humidity model and the one used by [12] is presented.From these figures, it can be seen that the proposed modeling methodology shows a good agreement with the original system, capturing in an accurate way the dynamic behavior of the greenhouses variables.The error (   =  ,or −  ,id and   H 2 O =  H 2 O,or −  H 2 O,id ) between the original system and the identified system is less than 10 −3 .
In order to demonstrate the accuracy of the proposed modeling methodology under a real and severe scenario, another identification is carried out using real data for   ,   ,  H 2 O, , and V (see Figure 11), in the winter of 2012, from a greenhouse prototype located in Jalisco, Mexico.The other external disturbances  cons ,  1 , and  2 are taken as in (18) and (19).The initial conditions are the same as in (20).It can be seen in Figures 12 and 13 that the identified model has a small error in comparison to the original model which is still less than 10 −3 .

Conclusions
The greenhouse ContPN modeling methodology presented in this paper provides a pictorial representation of variables which allows easy understanding of the interaction between them.The bounds in actuators are represented naturally by the marking of a place as in the case of the humidifier.In the case of the humidifier, although the tokens flow from its place can be reduced with the control, the representing place is a source place because the tokens are constant and they represent the maximum capacity of water flow.
The most important point is that it allows having a modular model.Thus, elements can be added or removed as necessary.Also, the lack of negative values in PN do not affect the system modeling because the greenhouse climate (temperature, water vapor concentration, and CO 2 concentration) is a positive system.
The simulation contains fixed parameters for the original system, but a greenhouse parameter may change according to certain variables which will provide bigger variations in the model and the need to identify constantly in order to change the model parameters that represent better the greenhouse.Future work will include the identification of a real greenhouse prototype and its control design.

Definition 3 .
A ContPN is called infinite server semantic ContPN if the flow of a transition   is
3.1.GreenhouseSystem.A greenhouse is a building which isolates the crop from the outside environment, preventing it from hazards such as extreme climate changes and plagues.Also, it improves the crop production by means of the greenhouse climate manipulation, provided through some components that can be added: temperature can be manipulated by means of ventilation, heating systems, and water sprinklers; water concentration can be manipulated by means of humidifiers, water sprinklers, ventilation, and fans; luminosity can be manipulated by means of shaded mesh and light bulbs; carbon dioxide concentration can be manipulated by means of CO 2 injectors.Notice that some components affect more than one climate variable.The selection of components varies depending on the geographical area and economical factors.
For the greenhouse humidity  H 2 O we construct: generation module for humidifier  hum ( hum in ); consumption module for condensation  cons ( cond con ); balance module for outside humidity  H 2 O, leaks nondependent on wind (  H 2 O, bal

Table 2 :
Relation between variables and function places.