## 2 Materials and Methods
### Problem Formalization and Proposed Method
For this reason, we need to define the notion of measurement context as follows. **Definition 7** (Context). : _Given a measurement \(x\in\mathbb{R}\) performed on a greenhouse at a given temporal instant \(i\in\mathbb{T}\), we define the context \(\rho\) in which the measurement is performed as a tuple of values of dimensions \(\delta=\langle d_{1},\ldots,d_{n}\rangle\) as follows: \(\rho=\langle w_{1},\ldots,w_{n}\rangle\), where each \(w_{h}\in\rho\) is the value of the contextual dimension \(d_{h}\in\delta\)._  
For our problem, three main types of contextual dimensions are of interest: (i) the time instant \(i\) in which the measurement is performed, (ii) the general climatic conditions inside the greenhouse, represented by the values collected by the central climatic station \(cs\) in Figure 3, (iii) the relative position of a PoI with respect to the current position of the robot, which is important in terms of travel time and required charge to get there, (iv) the battery level of the robot and its position relative to the nearest charging station, which is important to choose next PoI to visit. With reference to the DRL terminology, the agent is represented by the agricultural robot, and the notion of state is represented by its current node occupied inside the environment graph, together with the specific current context. For our purposes, the robot can be formalized as follows:  
**Definition 8** (Robot agent). : _The robot agent is a tuple \(\langle\varsigma,\ell\rangle\) where \(\varsigma:\mathbb{T}\rightarrow\mathbb{N}\) is a function returning for each temporal instant \(i\in\mathbb{T}\) the charging level of the robot battery, while \(\ell:\mathbb{T}\to V\) is a function returning for each temporal instant \(i\in\mathbb{T}\) the PoI \(p\in\mathcal{P}\) currently occupied by the robot._  
The final ingredient we need to formalize is the notion of reward used during the learning process to provide prompt feedback and encourage the agent to take the most suitable action. **Definition 9** (Reward). : _Given a PoI \(p\in\mathcal{P}\) representing the current position \(\ell(i)\) of the robot at time \(i\in\mathbb{T}\), the reward associated with stopping in a subsequent PoI \(q\in\mathcal{P}\) is defined as follows:_  
\[r(p,q)=\Delta_{q}(i+m_{pq})-\sigma(p,q)-e_{pq}-\Gamma_{pq}(t) \tag{5}\]  
_This reward function is designed with two main priorities:_  
1. _Promote safety and avoid critical conditions_ * _Avoiding Stagnation: A significant penalty is applied if the agent stays in the same place. This is captured by_ \(\sigma(p,q)\) _in Equation (_5_), which checks if_ \(p\) _and_ \(q\) _represent the same PoI._ * _Battery Management: Severe penalties are given for critical battery levels (i.e., it is too low to reach a charger, or it is empty). Conversely, a positive reward is provided for successfully reaching a charging station, especially when the battery is low. A penalty is also applied when the battery drops below a warning threshold, prompting the agent to seek charging early. These considerations about the battery level are captured by the term \(\Gamma_{pq}(t)\) in Equation (5), which is based on the value returned by the function \(\varsigma(t)\) in Definition 8. 2. Performance Optimization * Temperature Considerations: The reward for visiting a new location is based on the difference between the temperature that was previously measured or estimated there and the temperature that is expected at that location when the agent arrives. A larger difference in temperature indicates a greater importance of visiting that specific location, thus resulting in a higher reward for its selection. This is captured by the term \(\Delta_{q}(i+m_{pq})\) in Equation (5). * Time and Resource Efficiency: The agent is penalized for the time taken for actions and the resources consumed, encouraging faster and more efficient operations. This is captured by the term \(e_{pq}\) in Equation (5), which measures the energy required to move from \(p\) to \(q\).