# Determining the Optimal Positions of Infill Balise Groups for ERTMS/ETCS Level 1 Applications
## 2 Materials and Methods
### Implementation  
The algorithm was implemented using Python in version 3.11.9. Additional Packages used--in alphabetical order--are enum, json, logging*, math, matplotlib, numpy, os*, pandas, progress*, and time*. The packages indicated by an asterisk are not necessary for the actual computation but rather provide comfort features and additional user-facing information. The source code of around 1100 source lines of code is split into five modules:  
* optimize_infill.py: main function with input, iterative optimization, and output of the results;
* checks.py: performs checks on the input data provided to raise errors on implausible parameters;
* calc_movements.py: contains the functions which each calculate one specific type of movement;
* trajectory.py: calculates granular time-distance data to be used to plot the trajectories;
* plots.py: prepares the plots described in Section 2.3. Each of the modules may contain several functions specifically designed to handle small parts of the calculation to ensure readability and maintainability. The source code with comments in German in the version used to prepare this article is publicly available under the GNU General Public License 2.0 [47]. As the result of preparatory research, we decided not to use an optimizer, but focused on an iterative approach. Considerations on processing times as well as complexity led to this decision. We landed on a two-iteration process in which first, all possible and allowed positions of the infill balise groups to be optimized are tested with a larger step size (defaults to 10 m). In the second iteration, a precise localization with an accuracy of 1 m in the vicinity of the former, less accurate optimum is performed. Both times, the iteration starts at the EOA and progressively shifts the infill balise groups towards the IP opposite to the direction of running. A criterion to terminate the iterations early is not implemented to date, as it would deny valuable insights on how the system behaves in a specific scenario. It can be added when the algorithm shall be used outside of science in a production environment. The program is based on basic physics and the laws of motion to calculate the runtimes. We explicitly did not want to design a complex runtime calculator. To model non-constant accelerations and decelerations, we chose an approximation of sectional constant values. Hence, the driving dynamics are to be provided as step functions of the acceleration and deceleration values dependent on the train's speed. The effect of rotating masses \(f_{p}\) is taken into account with the standard gravity \(g_{0}\) when a non-zero gradient \(i\) is applied and changes the input nominal acceleration and deceleration \(a_{nominal}\) to the corresponding effective acceleration and deceleration \(a_{effective}\):  
\[a_{effective}=a_{nominal}-\frac{g_{0}\cdot i}{1+f_{p}}. \tag{3}\]  
Table 2 expands Table 1 and presents the input parameters of the current implementation of the algorithm. Additionally, technical parameters to customize the program are included. Due to Python's nature of dynamic typing, some variables are either processed as an integer or a float depending on the input provided. All input parameters are held structured in a JavaScript Object Notation (JSON) file and therefore are easily accessible and customizable, even to a future overlaid automation to batch-process different scenarios. This might be used to automate the planning process of all infill balise groups of one station or larger portions of an infrastructure. When the number of fixed infill balise  
groups matches the total number of infill balise groups, no optimization is possible. Rather, an evaluation of the specified positions regarding the reference train is performed. This enables users to compare different scenarios from other sources in a common application. The parameters of the category \"Tech\" are used to control parts of the program as well as the desired outputs.