Overview
For my contribution to the project, I worked on integrating the medium-term forecasting system into the application through the RConnector Java class and the accompanying General Additive Model (GAM) scripts written in RStudio. This portion of the project focused on forecasting energy demand on a monthly basis over a 1–3 year planning horizon.
Code Review
The forecasting pipeline combined Java and R by allowing the Vaadin application to execute external R scripts directly from the Java backend. The RConnector class was responsible for managing communication between the application and the R environment. Using Java’s ProcessBuilder, the class launched the R scripts, passed input dataset locations as command-line arguments, and captured the resulting prediction output files for use inside the application interface.
ProcessBuilder pb = new ProcessBuilder( “C:\Program Files\R\R-4.5.1\bin\Rscript.exe”, scriptPath, inputFile, outputFile );
The GAM models themselves were developed in RStudio using the mgcv package. General Additive Models were selected because they are effective at modeling nonlinear relationships and seasonal trends commonly found in energy demand data. The scripts used historical monthly energy and economic data to train smoothing functions that could capture long-term trends without forcing the data into a strictly linear relationship.
The R scripts first loaded the input CSV datasets, cleaned missing values, and then constructed the GAM model using smooth predictor functions. After training, predictions were generated and written back to a CSV file so they could be read into Java and displayed in the Vaadin interface.
model <- gam(TotalCost ~ s(cooling degree days) + s(heating degree days) + s(price total) + s(industrial production), data = model_data)
Challenges
One of the largest challenges during development was establishing reliable communication between Java and R across multiple systems. Since the project depended on external R packages such as mgcv and readr, installation and environment configuration issues occasionally caused execution failures when running the scripts from IntelliJ. Additional debugging was required to ensure file paths, package loading, and CSV formatting remained consistent between the Java application and the R environment.
Another challenge involved preparing the model for future forecasting. Since future predictor values were not available in the dataset, the scripts had to be extended to generate future monthly prediction outputs while maintaining realistic trends in the input variables. This required modifying the GAM workflow so the prediction pipeline could extend forecasts beyond the final historical observation.
The completed forecasting system successfully generated monthly energy demand predictions that were then passed back into the shared optimization model used throughout the application. These predictions were integrated directly into the Vaadin interface, allowing users to select forecast horizons and immediately visualize how predicted demand affected the optimal energy generation mix.
In addition to the forecasting integration itself, I also contributed to improving the overall usability of the interface by helping integrate the prediction outputs into the shared UI workflow and ensuring the forecasting results updated dynamically when users changed planning selections.
Screenshots

