Methods for running R language and deploying machine learning algorithms in AnyLogic software environment
By building a Java SE platform Jar package in AnyLogic, seamless interaction between R and Java was achieved, solving the complexity of running R in AnyLogic, improving the performance and predictive capabilities of simulation models, and promoting the integration of simulation and machine learning.
Patent Information
- Application Number
- CN202411664984.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-11-20
- Publication Date
- 2025-09-12
- Estimated Expiration
- 2044-11-20
AI Technical Summary
The inability to run R directly in the AnyLogic software environment made the deployment of machine learning algorithms complex and inefficient. Furthermore, the differences between R and Java, as well as their varying user bases, made technical integration difficult. Existing bridging technologies, such as the Pypeline library, had complex operational processes and a steep learning curve.
A Java SE platform-based Jar package containing multiple Java class packages was built to run the R language and deploy machine learning algorithms in the AnyLogic software environment. By bridging Java and R languages, seamless interaction and exception handling were provided, forming a plug-in library that was integrated into the AnyLogic software.
It enables the direct execution of the R language within AnyLogic software, improving the predictive capabilities and overall performance of simulation models, lowering the learning and usage barriers, promoting the integration of simulation and machine learning, and expanding the data analysis and predictive capabilities of simulation models.
Smart Images

Figure CN119739457B_ABST
Abstract
Description
Technical Field
[0001] The present invention belongs to the field of simulation and machine learning software development and secondary development. Specifically, it relates to a method for running R language and deploying machine learning algorithms in the AnyLogic software environment. Background Art
[0002] Currently, there is no dedicated plugin library in China or internationally that supports running R language in AnyLogic, a specific simulation software environment. The main reasons for this situation are:
[0003] One is the technical complexity of bridging R and Java and integrating them into AnyLogic software.
[0004] First, the underlying code of the original AnyLogic software is Java, making it impossible to call, recognize, and run R within the software environment without the help of third-party plug-ins. Inputting R code would result in runtime errors, even program crashes, syntax errors, or invisible agents. These errors highlight the significant differences between R and the simulation-oriented Java language, and also demonstrate that without bridging technology and plug-in-based implementations, there is simply no way to execute R code directly within the AnyLogic environment.
[0005] Therefore, given the complexity and difficulty of bridging between different assembly languages, API interface compatibility, and data structure matching, almost no developers are willing to invest in research and development.
[0006] The second is the huge differences in user groups and application fields between AnyLogic software and R language.
[0007] Currently, AnyLogic software is primarily a third-paradigm simulation and digital twin software, while R is primarily a fourth-paradigm data mining and machine learning tool. AnyLogic software uses a high-priced license sales strategy, primarily targeting high-end commercial customers. This has directly led to AnyLogic still not being as well-known and popular as mathematical software like MATLAB, and remaining in a niche software community ecosystem. R, on the other hand, is an open-source, free, and highly recognizable academic software and programming language. Consequently, there are significant differences in their user groups and application areas. There is little cross-disciplinary talent and integrated R&D needs between the two fields, and there is also insufficient community support and R&D funding.
[0008] CN202311765205.4 discloses a method for interacting with AnyLogic and Python reinforcement learning algorithms. The proposed method uses Python as the underlying language for deploying reinforcement learning algorithms in AnyLogic software. This method, based on the already developed internal library Pypeline provided by AnyLogic and encapsulated using the Alpyne library, builds an information framework for RL experiments. This is essentially an application integration innovation or usage process innovation. Both the Pypeline library (provided by Tyler Wolfe-Adam) and the Alpyne library (provided by Tyler Wolfe-Adam) are plug-in libraries that have been released and promoted internationally.
[0009] Developed by Tyler Wolfe-Adam, Chief AI Project Support Specialist at AnyLogic's North American headquarters, the Pypeline library is an API library plug-in specifically for interoperating between AnyLogic and Python. It connects to a locally installed Python installation, facilitates the use of Python libraries, and invokes functions such as reinforcement learning, data processing, and data presentation. The Pypeline library is not only a major technological leap forward for AnyLogic model development, but also offers unlimited creative possibilities for R&D teams striving for efficiency and innovation.
[0010] However, the Pypeline library still does not solve the following important problems:
[0011] First, using the Pypeline library to bridge the Python language for deploying machine learning or reinforcement learning in AnyLogic simulation models cannot be executed directly in AnyLogic, but rather indirectly by compatible platforms (such as Alpyne, Pathmind, or Bonsai). This results in a complex operational process and a high barrier to entry.
[0012] Secondly, for machine learning or reinforcement learning tasks, the learning curve of Python is usually steeper than that of R, and the rate of return is also lower. On the one hand, Python's syntax is more complex than R, and more code is required to achieve the same functions as R, while R is more intuitive to use and more suitable for rapid prototyping. On the other hand, from the perspective of the language ecosystem and community support, R has more unified tools and packages for statistical analysis and machine learning, as well as more centralized learning resource support, and many models and methods have been encapsulated into easy-to-use functions. However, many of Python's libraries and frameworks in the field of machine learning have different usages and practices. Users need to master a lot of basic knowledge to use different Python libraries and frameworks, and the size of Python libraries and frameworks is often much larger than the corresponding function libraries of R, which affects its popularity. Summary of the Invention
[0013] The technical problem to be solved by this invention is to provide a method for running R language and deploying machine learning algorithms in the AnyLogic software environment. This method overcomes the complexity and technical challenges of effectively integrating and using R language machine learning methods in AnyLogic, thereby improving the predictive capabilities and overall performance of simulation models.
[0014] To solve the above technical problems, the technical solution adopted by the present invention is: a method for running R language and deploying machine learning algorithms in the AnyLogic software environment, comprising the following steps:
[0015] S1. Build a Java SE platform-based Jar package to host the subpackages and their relationships for running R language and deploying machine learning algorithms in the AnyLogic software environment.
[0016] S2. Build the project main package to define global variables and parameters, centralize debugging and testing logic, and provide a centralized entry point for potential future modifications and extensions.
[0017] The main project package includes two first-level sub-packages, namely the first-level sub-package and the second-level sub-package. The first-level sub-package includes several core Java classes and consists of two second-level sub-packages. One of the second-level sub-packages is used for statistical simulation, sample generation, and data analysis, and the other is used to handle various exceptions that may occur when interacting between Java and R. The second-level sub-package is used to provide themes, styles, and format management for R language plots in the Java environment for simulation.
[0018] S3. Port the project code generated in steps S1 and S2 into the AnyLogic environment. Use AnyLogic to package the active objects contained in the project into a plug-in library that complies with the AnyLogic communication specification. Export the plug-in library to the AnyLogic environment as a separate Jar file.
[0019] S4. Inserting the exported plug-in library into AnyLogic IDE for testing and use;
[0020] S5. Conduct R code pre-experiments in the R language environment and bridge the AnyLogic environment with mainstream R language machine learning packages through first-level sub-packages to build a paradigm ecosystem for the new "machine learning + simulation" research method.
[0021] The present invention provides a method for running R language and deploying machine learning algorithms in the AnyLogic software environment, which has the following beneficial effects:
[0022] 1. This invention promotes the disciplinary convergence and paradigm shift between the third paradigm of simulation, represented by AnyLogic software, and the fourth paradigm of machine learning and data mining in the big data era (R language machine learning). Third paradigm simulation often relies on physical laws and empirical models, while the fourth paradigm's data-driven approach emphasizes data-based, rather than rule-based, analysis and mining. This combination ensures model reliability while leveraging the rich information of big data to improve simulation accuracy and predictability. Simulation allows for testing and verification before actual implementation, while machine learning assesses uncertainty through probabilistic models. This combination further reduces the cost and risk of projecting experimental scenarios into reality. Traditional simulation methods often struggle to capture the complex nonlinear relationships of the real world, while machine learning can effectively handle these complex nonlinear relationships, making simulation results more realistic.
[0023] 2. This invention improves model development efficiency for the new simulation paradigm featuring machine learning, exemplified by AnyLogic software. AnyLogic's underlying language is Java, but Java is not particularly adept at machine learning and reinforcement learning algorithmic tasks, especially compared to Python and R. Both Python and R boast large and active machine learning ecosystems. While Java also has a small number of machine learning libraries (such as Weka and Deeplearning4j), its overall ecosystem is relatively weak, with slow updates and a lack of the rich resources and support offered by Python and R. This limits the development efficiency of models with high performance requirements for machine learning. Python and R offer a wealth of machine learning libraries and frameworks, such as Scikit-learn, TensorFlow, Keras, and PyTorch (Python), and libraries like caret, randomForest, mlr3verse, and tidymodels (R), providing advanced yet user-friendly APIs for rapid development and experimentation. In contrast, Java's limited number of machine learning libraries are relatively low-level in design, requiring more code to accomplish the same tasks and resulting in relatively low development efficiency.
[0024] 3. This invention has successfully developed a dedicated bridging technology for the simulation-oriented Java language in AnyLogic. This technology overcomes the integration complexity challenges between high-level assembly languages, such as runtime environment and interface design, and significantly reduces the learning and application threshold for modelers of the new "simulation + machine learning" paradigm.
[0025] 4. This invention utilizes assembly language bridging technology to enable the use of R within AnyLogic's Java environment. Leveraging R's powerful machine learning capabilities, it amplifies the inherent capabilities of simulation modeling in predictive optimization and digital twins. Machine learning expands the data-driven intelligence of traditional simulation models and can continuously update the model's prediction parameters based on real-time data, improving forecast accuracy. Machine learning can discover underlying patterns in data that traditional methods haven't yet identified, generate new hypotheses or theories, and influence the operation of simulation models through parameter transfer, thereby enhancing the simulation model's data analysis, mining, and prediction capabilities, raising the paradigm dimension of simulation and expanding the boundaries of digital twin insight.
[0026] 5. This invention introduces R language machine learning into the AnyLogic simulation modeling environment. Leveraging R's community support, ecosystem, development efficiency, and learning resources, this approach enables AnyLogic simulations to achieve nearly unlimited scalability and upgradeability.
[0027] 6. The method and plug-in library provided by this invention can be deployed locally without relying on the internet. That is, simulation models with the characteristics of the new machine learning paradigm can be quickly built in AnyLogic software in an offline manner, meeting data confidentiality requirements. BRIEF DESCRIPTION OF THE DRAWINGS
[0028] The present invention will be further described below with reference to the accompanying drawings and examples:
[0029] Figure 1 It is the dependency interaction diagram between the classes and methods of each sub-package of the plug-in library;
[0030] Figure 2 The potential mechanisms for combining simulation with machine learning and typical ways to deploy the new AnyLogic paradigm;
[0031] Figure 3 The detailed editing interface for the new library and the software copyright information of the ALRcaller plug-in;
[0032] Figure 4 3D reconstruction of the physical model of a certain type of aircraft hangar reinforcement and maintenance support scene;
[0033] Figure 5 An aviation maintenance simulation framework with R language machine learning features;
[0034] Figure 6 Provide real-time parameter feedback and scene 3D animation for the operation of the smart fighter bunker maintenance support system;
[0035] Figure 7 Provide performance evaluation indicators and visualization for the operation of the smart fighter bunker maintenance support system;
[0036] Figure 8 To strengthen the 3D model and state diagram parameter settings of the aircraft hangar intelligent body;
[0037] Figure 9 Set the 3D model and state diagram parameters for the maintenance personnel agent;
[0038] Figure 10 To optimize the characteristic curve of the number of decision trees and misclassification rate of the random forest model based on out-of-bag observations before the experiment;
[0039] Figure 11 Results of the first-stage optimization experiment for the 4-parameter random forest model based on the OptQuest engine;
[0040] Figure 12 Experimental results for the second stage optimization of the 4-parameter random forest model based on the OptQuest engine. DETAILED DESCRIPTION
[0041] In order to make the purpose, technical solutions and advantages of the present invention more clearly understood, the present invention will be further described in detail below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present invention and are not intended to limit the present invention.
[0042] Example 1:
[0043] A method to run R language and deploy machine learning algorithms in AnyLogic software environment. The steps are as follows:
[0044] S1. Build a Jar package for a project based on the Java SE platform. The dependency interaction diagram within the package is as follows: Figure 1 As shown, the specific decomposition steps are as follows:
[0045] S11. Complete the download and installation of the Java toolkit and configure the Java environment variables in the control panel.
[0046] S12. Build a Jar package based on the Java SE platform. In this embodiment, download and install the Java Tool Kit (JDK) in the Windows 10 environment. Configure the Java environment variables in the control panel to make Java global and run in any file directory. Build a Jar package based on the JDK 22 version development core and JRE 8u421 runtime environment of the Java SE platform. The project name is ALRcaller, and the package name is edu.ctgu.sh-alrcaller-1.0.1.jar. Eclipse Jee 2023-12 version software is used as the development tool.
[0047] The Jar package is used to carry the subpackages and their relationships for running the R language and deploying machine learning algorithms in the AnyLogic software environment, serving as the carrier of the method proposed in this patent.
[0048] S2. Build the main project package to define global variables and parameters, centralize debugging and testing logic, and provide a centralized entry point for potential future modifications and extensions.
[0049] The main package of the project includes two first-level sub-packages, namely the first-level sub-package and the second-level sub-package. The first-level sub-package includes several core Java classes, including CodeUtils, EventHandler, Globals, JavaObject, RCaller, RCode, ROutputParser, RPlotViewer and RstreamHandler. Among them:
[0050] The CodeUtils class provides the main methods that support the interaction between Java and R languages, especially methods for data transfer and conversion, and generating or processing code snippets, enabling modelers to generate directly executable R code in a Java environment.
[0051] The EventHandler class provides the main methods for processing interactive messages between Java and R languages and managing the output streams of both, enabling Java to communicate with R languages effectively.
[0052] The Globals class provides R language configuration and constant support in the Java environment, so that R language-related environment settings, version information, and graphic themes can be managed more flexibly and conveniently when calling the R language from Java.
[0053] The JavaObject class provides Java property processing and R code generation, using specific methods to convert the fields of Java objects into R code.
[0054] The RCaller class provides methods for executing R scripts, parsing R output, and redirecting R output. This greatly expands the data analysis and machine learning capabilities of AnyLogic software and its Java code, opening up new paradigms for simulation research.
[0055] The RCode class provides methods for dynamically building and executing R language code, supporting various functions necessary for R language machine learning, such as data transmission, plotting, and package management.
[0056] The ROutputParser class provides methods for extracting and processing data from R language output. It can parse numerical data in R language output and obtain structured document information, supporting dynamic updating of files.
[0057] The RPlotViewer class provides methods for displaying graphics generated by the R language in Java. It serves as a graphical user interface (GUI) window that displays high-level graphics generated by the R language in Java.
[0058] The RStreamHandler class provides methods for processing input streams for calling the R language in a Java environment, reading data from the input stream and passing it to registered event handlers, and implementing complex message processing logic.
[0059] The first-level sub-package consists of two second-level sub-packages, one of which is used for statistical simulation, sample generation, and data analysis, and the other is used to handle various exceptions that may occur during the interaction between Java and R languages.
[0060] In this embodiment, the main package RCMain of the ALRcaller project is constructed. It is mainly used to define global variables and parameters, centrally handle debugging and testing logic, and provide a centralized entry point for potential future modifications and extensions.
[0061] The main package RCMain includes two first-level subpackages: ALRcaller and ALGraphics. The first-level subpackage ALRcaller integrates several core Java classes and provides a series of efficient, flexible and powerful functions, aiming to achieve seamless interaction and integration between Java and R for simulation.
[0062] The two second-level sub-packages of the first-level sub-package ALRcaller are the first and second-level sub-packages, namely ALStatistics and ALException.
[0063] The second-level subpackage ALStatistics of the first-level subpackage ALRcaller is mainly used for statistical simulation, sample generation, and data analysis. This second-level subpackage provides a seamless integration, allowing users to create more complex and generalized probability simulation experiments and perform data analysis, or test the effectiveness of statistical methods. This makes statistical analysis in the AnyLogic environment more convenient and powerful thanks to the support of the R language.
[0064] The second-level subpackage ALException of the first-level subpackage ALRcaller is mainly used to handle various exceptions that may occur during the interaction between Java and R language. This second-level subpackage enables modelers to capture and handle specific errors to ensure that problems that arise during the interaction with R can be handled gracefully in the Java environment, thereby improving the robustness of the overall program and user experience.
[0065] The second-level subpackage, ALGraphics, is primarily used to manage themes, styles, and formats for R language graphics in a Java environment for simulations. This subpackage provides users with flexible graphics presentation methods, greatly expanding Java's graphics capabilities with the support of the R language. The specific operations for building this package are as follows:
[0066] In Eclipse IDE 2023-12, click "File → New → Project → Java Project" to prepare for creating a Java project. The "New Java Project - Create a Java Project" dialog box will pop up. Type "ALRcaller" in the Project Name field, use the default configuration, and click "Finish" to create the project from scratch.
[0067] In the ALRcaller Java project, use "File→New→Other→Package" to first create a hierarchical structure of various sub-packages. The main package of the project is RCMain, which is mainly used to define global variables and parameters, centrally handle debugging and testing logic, and provide a centralized entry point for potential future modifications and extensions. The main package RCMain includes two first-level sub-packages, ALRcaller and ALGraphics, and two second-level sub-packages, ALStatistics and ALException, under the ALRcaller sub-package. The steps to build the first-level sub-package are as follows:
[0068] 1) Build the CodeUtils class to provide the main methods supporting the interaction between Java and R, especially methods for data transfer and conversion, and generating or processing code snippets, so that modelers can generate code in the Java environment that can be directly executed in the R language;
[0069] The constructed CodeUtils class contains main functions such as addDoubleArray(StringBuffer, String, doublell,boolean): void and addIntArray(StringBuffer, String, int[], boolean): void, and has the foundation and interface for functional expansion.
[0070] 2) Build the EventHandler class to provide the main methods for processing interactive messages between Java and R and managing the output streams of both, so that Java can communicate with R effectively;
[0071] The constructed EventHandler class relies on the Java basic class java.io.OutputStream, and includes main functions such as getO(): OutputStream, messageReceived(String, String): void and setO(OutputStream): void, and has the foundation and interface for functional expansion.
[0072] 3) Build the Globals class to provide R language configuration and constant support in the Java environment, so that when calling R language from Java, you can more flexibly and conveniently manage R language-related environment settings, version information, and graphics themes;
[0073] The constructed Globals class depends on the two subclasses of ALGraphics, DefaultTheme and GraphicsTheme. It contains the main functions such as Globals() and detect_current_rscript(), and has the foundation and interface for functional expansion.
[0074] 4) Build the JavaObject class to provide Java property processing and R code generation, using specific methods to convert Java object fields into R code;
[0075] The constructed JavaObject class relies on the Java basic class java.lang.reflect.Field, contains major functions such as produceRCode(boolean):String, and has the foundation and interface for functional extension.
[0076] 5) Building the RCaller class, which provides methods for executing R scripts, parsing R output, and redirecting R output, greatly expanding the capabilities of AnyLogic software and its Java code for data analysis and machine learning.
[0077] The constructed RCaller class depends on Java basic classes such as java.io.BufferedWriter, java.io.File, the ALGraphics subpackage, and ALException classes such as ExecutionException and ParseException. It contains main functional functions such as getCranRepos(): String, getRCode(): RCode, runAndReturnResult(String): void, and has the foundation and interface for functional expansion.
[0078] 6) Build the RCode class to provide methods for dynamically building and executing R code, supporting various R machine learning functions such as data transfer, plotting, and package management;
[0079] The constructed RCode class depends on Java basic classes such as java.io.File, java.io.IOException, and the GraphicsType subclass of ALGraphics. It contains main functional functions such as R_require(String): void, addRCode(String): void, and has the foundation and interface for functional expansion.
[0080] 7) Build the ROutputParser class to provide methods for extracting and processing data from R language output. It can parse numerical data in R language output and obtain structured document information, supporting dynamic file updates.
[0081] The constructed ROutputParser class depends on Java basic classes such as java.io.File, java.io.IOException, and Java interface classes such as org.w3c.dom.Document, org.w3c.dom.Node. It also depends on the ALException subpackage, which includes main functional functions such as getAsDoubleArray(String) : double[], getDocument() : Document, and has the foundation and interface for functional expansion.
[0082] 8) Build the RPlotViewer class to provide methods for displaying R-generated graphics in Java. This class serves as a graphical user interface (GUI) window that can display advanced graphics generated by R in Java.
[0083] The constructed RPlotViewer class depends on Java basic classes such as java.awt.Graphics, javax.swing.ImageIcon, etc., and includes main functional functions such as getImg(): ImageIcon and setImg(ImageIcon): void, and has the foundation and interface for functional expansion.
[0084] 9) Build the RStreamHandler class and provide methods for processing input streams for calling R language in the Java language environment, reading data from the input stream and passing it to the registered event handler, and implementing complex message processing logic;
[0085] The constructed RStreamHandler class relies on Java basic classes such as java.io.BufferedReader, java.io.InputStream, etc., and contains main functional functions such as isAlive(): boolean and setStream(InputStream): void. It is mainly used to: read input stream data, identify and log it; add a new handler to the event handler list so that it can be called when a message is received; check whether the processing thread is still running and feedback the current status of the thread; set a shutdown signal to determine and control whether the run() method loop continues, etc.; and has the foundation and interface for functional expansion.
[0086] The construction steps of the first and second level subpackages ALStatistics are:
[0087] 1) Configure the runtime environment and main parameters of the first and second-level subpackages, including the ALRcaller.Rcaller (RCaller class) dependency that implements R script parsing, execution, and output, and the ALRcaller.Rcode (RCode class) dependency that provides a method for dynamically building R language code.
[0088] 2) Set the main functional functions of the secondary subpackage ALStatistics of the subpackage ALRcaller, mainly to set the functional functions of the RandomNumberGenerator (RCaller) program block, including, for example: the randomBeta(int, double, double): double[] function for generating Beta distributed random numbers, the randomBinom(int, int, double): double[] function for generating Bernoulli distributed random numbers, etc.
[0089] The construction steps of the second level subpackage ALException are:
[0090] 1) Configure the runtime environment and main parameters of the second-level subpackage, including the superclass java.lang.Exception (JDK base package) that can be used to code Java exceptions as a dependency;
[0091] 2) Set up the main functions of the second-level subpackage. These include, for example, the ExecutionException(String) function, which provides a descriptive message when creating an exception and passes it along; the ParseException(String) function, which provides a descriptive message when parsing an exception; and the RscriptExecutableNotFoundException(String) function, which provides a detailed message when the Rscript executable file is not found.
[0092] The second-level subpackage ALGraphics is used to provide themes, styles, and format management for R language graphics in the Java environment for simulation. The steps to build the second-level subpackage are as follows:
[0093] 1) Configure the runtime environment and main parameters of the second-level subpackage, including the JDK base package java.awt.Color, which provides classes and interfaces for managing and manipulating colors, as a dependency;
[0094] 2) Set up the main functions of the second-level subpackage. These include, for example, the generateRCode() : String function, which generates R code based on the current color and line width, and the getAxisColor() : Color function, which returns the current axis color.
[0095] S3. Port the project code generated in steps S1 and S2 to the AnyLogic environment. Use AnyLogic to package the project's active objects into a plug-in library that complies with AnyLogic's communication specifications. Export the plug-in library to AnyLogic. The steps are as follows:
[0096] S31: Port the project to the AnyLogic software environment. Convert all main packages, first-level subpackages, and second-level subpackages to AnyLogic "agent types." Also transfer the Java classes within each subpackage to the corresponding agent type. Complete the Java package structure and content construction in steps S1 and S2 in the AnyLogic environment, and click "Build Model (F7)" on the menu bar to confirm that all code compiles correctly.
[0097] S32. In the AnyLogic development environment, select the top-level ALRcaller.alp model in the Project column, click "File → New → Library", and in the pop-up "New AnyLogic Library" dialog box, fill in the corresponding information of the dedicated library. In the "Name" field, fill in "ALRcaller Library" and in the "Description" field, fill in "A library for running R code in AnyLogic software to deploy Machine Learning and Deep Reinforcement Learning in simulation experiments." After clicking "Finish", the "Library" type icon will be generated in the Project column and the name "ALRcaller Library" will be displayed. Then, the detailed editing interface of the library will pop up, as shown in the following figure. Figure 3 ;
[0098] S33. Continue filling in information and improving the interaction in the detailed editing interface of the new library. In the "Panel", upload the library icon specified to appear in the panel, which is divided into two formats: 16×16pix and 32×32pix. Design the line drawings of the corresponding icons according to the functional characteristics of the RCMain, ALRcaller, ALStatistics, ALException and ALGraphics modules. You can use the icon production website to assist in generating icons in the required format. Finally, upload the two formats of icons corresponding to the above five important modules from the local path.
[0099] In the "Export" module of the newly created library's detailed editing interface, select "Export Library" to export the professional library that complies with the communication specifications of AnyLogic 8.9.0 and above. The file name is edu.ctgu.sh-alrcaller-1.0.1.jar.
[0100] S4. Insert the exported plugin library into the AnyLogic IDE for testing and use. In the AnyLogic software environment, click "Panel → (+Add) → Manage Libraries." The library addition interface will pop up. Click "Add." The file "Open" interface will pop up. Select edu.ctgu.sh-alrcaller-1.0.1.jar from the specified local path (preferably an all-English path). After selecting, click "Open → OK." The library file will now be added to the library list. Click "OK" on the library addition interface to complete the import of the ALRcaller library. Restart AnyLogic to ensure that the setting changes are correctly recognized and the plugin installation is correctly loaded.
[0101] S5. Conduct R code pre-experiments in the R language environment and bridge the AnyLogic environment with the mainstream R language machine learning packages through the first-level sub-packages to build the paradigm ecology and main technical forms of the new research method of "machine learning + simulation", such as Figure 2 The decomposition steps are as follows:
[0102] S51. Prepare the algorithm model on paper, and then install the required R language packages using the install.packages() function in RGui (64-bit) version R 4.3.2.
[0103] S52: In the RGui graphical user interface or RStudio integrated development environment (IDE), reference the installed R language package to conduct preliminary experiments on the R language machine learning algorithm to achieve the expected experimental results;
[0104] S53: In AnyLogic, complete the migration of the pre-experimental R language code to the Java environment. This is done primarily by using the code.addRCode("R language code") function statement to add the R script to the simulation environment. For complex R codes (especially those containing double quotes), consider using the Java escape character "\" to avoid syntax errors.
[0105] S6. Combine the plug-in library with AnyLogic's native libraries (e.g., the Process Modeling Library, the Material Handling Library, the Pedestrian Library, the Rail Library, the Road Traffic Library, the Fluid Library, and the System Dynamics Library) to seamlessly integrate intelligent algorithms with simulations and achieve the paradigm shift resulting from the fusion of the Third Paradigm and the Fourth Paradigm. The steps are as follows:
[0106] S61. Utilize the nested model of "R script functions + conditional trigger events" or "native library function blocks + R script parameter passing" to organically integrate machine learning methods supported by the R language into simulation methods based on discrete events, system dynamics, and agents. Machine learning methods include reinforcement learning, supervised learning, semi-supervised learning, and unsupervised learning.
[0107] S62. Use the delay time value predicted by the R language machine learning method at the delay time of the Delay or Service component of the process modeling library; use the queue capacity predicted by the R language machine learning method at the capacity of the Queue component of the process modeling library; use the storage capacity predicted by the R language machine learning method at the capacity of the Pipeline component of the fluid library, etc.
[0108] Example 2:
[0109] This example demonstrates how the ALRcaller plug-in library, independently developed by our team, can call the computational results of R algorithms and functions within the AnyLogic environment to control the logic and behavior of an agent within the environment. Specifically, a black-box process in R is used to provide behavioral instruction parameters to the finite state machine of an AnyLogic agent. This process simulates different maintenance conditions within an aircraft hangar constructed within the AnyLogic environment, controlling the hangar's maintenance status and door opening and closing. Consequently, a corresponding number of maintenance personnel are dispatched to participate in aircraft maintenance or to standby and prepare in the rest area in a lean and flexible manner. This example combines machine learning with traditional simulation methods, applying agent-based and system dynamics approaches. It also applies to a business application in the aviation maintenance field. Overall, it is an experiment (codenamed "CtrlTest.R2A") using this plug-in library to optimize and control AnyLogic simulation processes using R.
[0110] Specifically, this example simulates a maintenance crew experimenting with lean and flexible maintenance during a special overhaul mission, leveraging the operating conditions of a new hangar. The hangar contains 10 workstations, each consisting of a team of 10 maintenance personnel. The new equipment is used intermittently, requiring some on-call maintenance personnel to travel to a rest area during the equipment's cooldown period to prepare materials. The simulation simulates the process of using a black-box algorithm to optimize the intermittent cooldown period for the 10 workstations and instruct maintenance personnel to proceed to the hangar to perform maintenance operations.
[0111] In the preferred solution, a random black box algorithm is simulated with 10 normally distributed 0-1 variables as output, and the sum of these 10 0-1 variables is used as the decision variable. The formula is:
[0112] ;
[0113] The simulation experiment of this embodiment designs four performance evaluation indicators, namely: real-time equipment operating time, real-time maintenance work time, real-time standby maintenance personnel (number) and the work efficiency of a single maintenance personnel.
[0114] Use Finite State Machine (FSM) models to drive the actions of agents in a simulation environment:
[0115] ;
[0116] a. State transition function of Deterministic Finite Automation (DFA):
[0117] ;
[0118] b. State transition function of Nondeterministic Finite Automaton (NFA):
[0119] ;
[0120] Where: Represents the state set, including all possible states of the system; Represents the input signal set, including all input signals received by the system; Represents the output signal set, including all output signals generated by the system; Represents the transfer function, which describes the rules of state transition; Represents the initial state, as the initial state of the system; Represents the empty transfer symbol, which is the empty transfer in the NFA method; Represents the Cartesian product between sets; express The power set (including ), is to convert the set All elements of are converted into combinations of binary numbers, reflecting the possibilities of all subsets.
[0121] Gate-control theory, originally a term from the medical field, has been applied to simulation. Simulation gate control technology involves intelligently controlling the simulation environment and its agents by identifying the open and close states of control gates (threshold signals released by a mechanism or algorithm). This implementation will deploy a finite state machine architecture for a reinforced hangar agent and a maintenance agent, based on gate-control theory and incorporating machine learning algorithms.
[0122] In AnyLogic, we used the independently developed ALRcaller plug-in library to call the R language. Using the calculation results of R algorithms and functions, we controlled the logic and behavior of the AnyLogic agent. This simulation enabled us to simulate different maintenance conditions in a hangar of a certain type of aircraft, control the hangar maintenance status and door opening and closing, and, in a lean and flexible manner, call a corresponding number of maintenance personnel to participate in aircraft maintenance or to stand by and prepare in the rest area. The process included the following steps:
[0123] E2S1: Install the R package on your local computer, based on the existing R environment. Currently, it is no longer possible to download the package directly from the official R support website or install it using the install.packages() method within the R environment. Instead, you can use the devtools::install_local() method to install the package from a local .zip file.
[0124] E2S2: In AnyLogic 8.9.0 Professional and above, navigate to Panel → Manage Libraries → Add and select the AnyLogic professional library Jar file (edu.ctgu.sh.alrcaller.testtype.101.jar) developed by our R&D team. After the library is successfully loaded, the system displays the newly loaded library name: ALRcaller Library, provided by Hang Shao, version 1.0.1, and the local file path.
[0125] E2S3: Create a new simulation experiment in AnyLogic and name it ALRcallerCase2.alp.
[0126] E2S4: After creating a new simulation experiment and successfully loading the ALRcaller Library, drag the library's RCmain, ALRcaller, ALStatistics, ALGraphics, and ALException components (a total of five components) into the AnyLogic runtime environment, beautify and layout the R WORKING PANEL workspace, and import the Java class that "converts Java to R and passes parameters" into the underlying Java environment of AnyLogic, such as Figure 5 shown.
[0127] E2S5: Configure the dependency environment for the ALRcaller plugin library. Given that this experiment involves accessing and outputting data visualization images, locate "Advanced Java" in the Main agent at the top level of the simulation and import Java libraries such as java.io.File and javax.swing.ImageIcon in the "Imports" section.
[0128] E2S6: Drag and drop the "Excel File" plug-in component into the AnyLogic environment, following the "Panel → Connect → Excel File" menu. This will import sensor data files in Excel format into the simulation environment for subsequent simulation and prediction.
[0129] E2S7: Based on the real hangar floor plan, a simulated virtual physical environment is built for subsequent simulation and prediction. At the same time, intelligent agents and intelligent agent groups of the hangar, dormitory and maintenance personnel physical models are established, such as Figure 4 shown.
[0130] Furthermore, drag the "Agent" component from the "Agent" library to the simulation environment interface, use the default process to create the maintenance crew group agent groundCrews and the hangar single agent flightHangar, then select the appropriate maintenance crew and hangar 3D models in .dae format, adjust the additional scale of the 3D model to the appropriate size, and use them as the agent animations of the above-mentioned group agent groundCrews and single agent flightHangar;
[0131] Furthermore, for the hangar single agent flightHangar, it is necessary to specifically select the animations and prompt icons for the two states of the hangar door, "open" and "closed", and type "Open" in the visibility parameters of the hangar in the "Opening" state, and type "Close" in the visibility parameters of the hangar in the "Closing" state.
[0132] E2S8: Based on the agent and state diagram library, a logical template for the operation of each unit in the airport is constructed.
[0133] The hangar single agent flightHangar is controlled by a three-state transition state diagram to control its basic operation, such as Figure 8 As shown, the statechart entry point is statechart, and the state branches are connected to "Open", "Close" and "Normal". Then, drag three "Parameter" components from the "Panel → System Dynamics" library to the flightHangar design panel, name them "OpenTime1", "OpenTime2" and "OpenDuration" respectively, and specify them as double type;
[0134] Set the transition condition at the fromIndicator transition to main.Indicator()>5 and point it to the "Open" state; use the time transition countdown1 to point from the "Open" state to the "Normal" state, and set the time to 9 minutes; use the time transition countdown2 to point from the "Normal" state to the state branch connection, and set the time to 1 minute; extend the non-true trigger branch whileFalse from the state branch connection and point it to the "Close" state, which is a marked state with no code; use the time transition countdown3 to point from the "Close" state to the "Normal" state, and set the time to 9 minutes; complete the state diagram construction of the hangar single agent flightHangar;
[0135] The basic operation of the maintenance personnel group agent groundCrews is controlled by a three-state transition state diagram, such as Figure 9 As shown, the statechart entry point is statechart, and the state branches are set to connect "Work", "Wait" and "Normal". Drag three "Parameter" components from the "Panel → System Dynamics" library to the flightHangar design panel, name them "WorkTime1", "WorkTime2" and "WorkDuration" respectively, and specify them as double type;
[0136] Set the transition condition at the fromIndicator transition to main.Indicator()>5 and point it to the "Work" state; use the on-time transition countdown1 to point from the "Work" state to the "Normal" state, and set the on-time to 9 minutes; use the on-time transition countdown2 to point from the "Normal" state to the state branch connection, and set the on-time to 1 minute; extend the non-true trigger branch whileFalse from the state branch connection and point it to the "Wait" state; use the on-time transition countdown3 to point from the "Wait" state to the "Normal" state, and set the on-time to 9 minutes; complete the state diagram construction of the maintenance personnel group intelligent agent groundCrews;
[0137] E2S9: Based on the analysis library, a data analysis and visualization module for the simulation model is constructed. The time line chart and time stack chart in the "Panel → Analysis Library" are used to visualize real-time maintenance performance evaluation data, including:
[0138] The title of the time line chart plot1 is "Real-time equipment operation time", the value is getOpenDuration(), and the appropriate dot-line format is selected for drawing to show the difference; the title of the time line chart plot2 is "Real-time maintenance work time", the value is getWorkDuration(), and the appropriate dot-line format is selected for drawing to show the difference; the title of the time line chart plot3 is "Real-time standby maintenance personnel", the value is getRestCrews(), and the appropriate dot-line format is selected for drawing to show the difference; the title of the time line chart chart1 is "Single maintenance personnel work efficiency", and the appropriate dot-line format is selected for drawing to show the difference. Among them, the rationalization formula for the work efficiency of a single maintenance personnel is:
[0139] ;
[0140] Where: Indicates the work efficiency of a single maintenance personnel; Indicates the working hours of the maintenance personnel intelligent group; represents the real-time running time of the hangar and its maintenance equipment agent group; Indicates the total number of maintenance team members; Indicates the number of maintenance personnel on standby; Represents a high-order infinitesimal quantity, which is an auxiliary parameter set to prevent division by zero errors in iterative calculations. In this example, the value is 0.001;
[0141] E2S10: Use R language to simulate a black-box algorithm with randomness, pass the decision parameters into the finite state machine, and control the people, machines, and environment of the virtual airport in the AnyLogic environment. Specifically, during a special overhaul mission, the maintenance personnel relied on the operating conditions of a new hangar to try out lean maintenance and flexible maintenance models. There are 10 workstations in the hangar, and the corresponding team has 10 maintenance personnel; the use frequency of the new equipment is intermittent, so not all personnel are required to be at the workstation all the time. Instead, some maintenance personnel on standby need to go to the rest area to prepare materials during the cooling time of the machine operation; the simulation experiment simulates the process of optimizing the intermittent cooling time of the 10 workstations through a black-box algorithm, and guiding the corresponding maintenance personnel to go to the hangar to carry out maintenance operations through indicators; the overall top-level architecture of the model can be seen. Figure 5 ;
[0142] E2S11: Run the simulation model and conduct an efficiency evaluation of the model's performance. Click "ALRcallerCase2 / Simulation" in AnyLogic to run the simulation model and its embedded R language machine learning code in the AnyLogic Java environment. The 3D window will display the simulation status in real time, including the opening and closing of the hangar, the operation of personnel, and the scheduling and work of personnel. The console will display the real-time parameter arrays and gate thresholds, such as Figure 6 As shown; the data visualization area will update the performance indicator visualization chart in real time, such as Figure 7 shown.
[0143] Example 3:
[0144] This example demonstrates how the ALRcaller plug-in library, independently developed by our team, calls the Random Forest algorithm in R within the AnyLogic environment. This library processes sensor data in Excel format imported into AnyLogic. Using AnyLogic's optimization experiment functionality, the algorithm iteratively optimizes four key parameters of the Random Forest algorithm: the number of decision trees (ntree), the number of variables considered per split (mtry), the minimum number of leaf nodes (nodesize), and the maximum number of nodes in a decision tree (maxnodes), with the goal of minimizing the model's root mean square error (RMSE). The algorithm then finds the four-parameter combination that minimizes the RMSE within the specified number of iterations. This example combines machine learning with traditional simulation methods, applying system dynamics and the OptQuest approach. It also addresses the application of electrical science and engineering. Overall, this example demonstrates an experiment using AnyLogic to optimize and control R using this plug-in library (codenamed "CtrlTest.A2R").
[0145] In actual major engineering experiments and applications, it's often impossible to conduct large sampling (or obtain a large number of samples for training). Therefore, developing prediction methods for small samples has become a critical scientific challenge. The gap breakdown voltage test for positive polarity gases is one such experiment, characterized by high difficulty, high risk, and high material costs.
[0146] The data set used in this embodiment is the real data of a gap breakdown voltage experiment of a positive polarity gas. The field information of the positive polarity gas gap breakdown voltage experiment data is as follows:
[0147]
[0148] The local file name of the above experimental data is breakdownData.xlsx, and its data content is shown as follows:
[0149]
[0150] There is currently evidence that tree-based models are more likely to achieve good predictions for tabular data than various deep learning methods. Given this, this study intends to use the random forest algorithm to analyze and process the breakdownData.xlsx data above.
[0151] In the preferred solution, for the growth stage of the random forest decision tree, information gain is used to select the partitioning attributes of the decision tree. Information gain and optimal partitioning properties Defined as:
[0152] ;
[0153] Where: Represents a sample set The information entropy of Represents the current sample set Middle The proportion of class samples, usually The higher the purity, the The smaller the value of ; Representing discrete attributes The value space of , represents the optimal partitioning attribute, Indicates the sample value range.
[0154] Preferably, for numerical tasks, the voting stage adopts the weighted averaging principle, that is:
[0155] ;
[0156] Where: Indicates the sample predictions, T represents the number of individual learners in the ensemble, Represents an individual learner The weight is usually required ;when When , the method becomes simple averaging.
[0157] Preferably, for categorized tasks, the Plurality Voting principle is adopted during the voting phase, namely:
[0158] ;
[0159] Where: Indicates the sample predictions, N dimensional vector Representation Learner In the sample The predicted output on express In category tag collection The output on T represents the number of individual learners in the ensemble.
[0160] In AnyLogic, we used the independently developed ALRcaller plug-in library to call the R language random forest algorithm to simulate and predict the breakdownData.xlsx dataset (predicting the voltage at gas breakdown). We also used the AnyLogic software's optimization experiment function to iteratively optimize the four key parameters of the random forest algorithm. Finally, we obtained the model parameters that minimized the RMSE indicator. This involved the following steps:
[0161] E3S1: Refer to steps E2S1 to E2S6 of Example 2 to build the operating environment of the ALRcaller plug-in library, create a new simulation experiment named ALRcallerCase3.alp, and import the Excel format sensor data file breakdownData.xlsx for subsequent simulation and prediction.
[0162] E3S2: Drag four "Parameter" components from the "Panels → System Dynamics" library to the R WORKINGPANEL workspace in Main. Name them: ntree, mtry, nodesize, and maxnodes. The default values are 500, 10, 5, and 5, respectively. The type of these parameters is double. Detailed descriptions of these parameters are shown in the following table:
[0163]
[0164] In this embodiment, in order to control the time complexity and space complexity of the model, ensure that the calculation does not overflow, prevent overfitting, and ensure that the decision tree must have splits, the minimum value of ntree is 3, the maximum value of mtry is 10, the minimum value of nodesize is 2, and the minimum value of maxnodes is 2.
[0165] E3S3: Drag a "Function" component from the "Panel → Agent" library to the R WORKING PANEL workspace in Main, name it "randomForestRMSE", set the "Return Value" item to TRUE, and write the Java code in the function body to call the R language to read the experimental data and train the random forest model;
[0166] E3S4: In a pure R language environment, use the random forest algorithm in the randomForest package to conduct a preliminary experiment on the above dataset. By checking the min_index parameter of data items such as rf$mse, the optimal parameter value estimated by the randomForest package's own method is obtained;
[0167] The above process is essentially to use the plot() function to visualize the changing characteristics of the misclassification rate based on out-of-bag observations with the number of decision trees in the random forest, and then obtain intuitive observation conclusions, see Figure 10 The plot data of the plot() function is the overall prediction error rate err.rate of the random forest model for out-of-bag observations. The OOB error rate data is actually calculated by modelA.rf$mse when calling the plot() function.
[0168] The above preliminary experiments show that when other parameters remain the same, the overall error rate err.rate is the smallest when the number of decision trees is 42. Therefore, the parameter ntree in this embodiment can be set to 42 for reference. Figure 10 .
[0169] Furthermore, a single simulation experiment was conducted in AnyLogic. Drag an "Event" component from the "Panel → Agent" library to the R WORKING PANEL workspace in the Main window, name it "calcRMSE," set the trigger type to "When," and the mode to "Occur once." In the action of this "Event," call the model's RMSE calculation function, randomForestRMSE().
[0170] Next, click "ALRcallerCase3 / Simulation" in AnyLogic to run the simulation experiment and its included R code in AnyLogic. When the simulation is complete, the calculation results and status update labels are printed in the AnyLogic Config console.
[0171] E3S5: Deploy and run the first phase of the parameter optimization experiment in AnyLogic. Right-click Project → ALRcallerCase3, select New → Experiment, and in the New Experiment dialog box that pops up, enter "Optimization" in the Name field, "Main" in the Top-Level Agent field, and "Optimization" in the Experiment Type field. Leave the remaining options as default and click Finish to create the optimization experiment.
[0172] In the parameter optimization experiment "Optimization", select "OptQuest DEMO" as the optimization engine, select "Minimize" as the objective, and fill in root.randomForestRMSE() as the target value;
[0173] Select the iteration mode as "Fixed", its value as 200, and the maximum available memory as 512MB. Click "Create Default User Interface" to display the optimization experiment appearance. In the parameter settings, set the parameters as shown in the following table:
[0174]
[0175] Click "Build Model (F7)" in the menu bar to confirm that all codes are compiled correctly. Then click "Run (F5) → ALRcallerCase3 / Optimization" to get the following Figure 11 The results of the first stage optimization experiment are shown:
[0176] After 107.04 seconds and 207 iterations, the optimal iteration within this range was found to be step 177, with a minimum RMSE of 7.017. At this point, ntree = 3, mtry = 9, nodesize = 2, and maxnodes = 46. During these iterations, we found that, under the objective function of minimizing the RMSE (model evaluation metric), the number of decision trees (ntree) and the minimum number of leaf node samples (nodesize) tended to be minimized, the number of input variables for fission (mtry) tended to be maximized, and the decision tree depth (maxnodes) tended to find a moderately optimal value. This is related to the characteristics of the dataset and computing resources.
[0177] E3S6: Deploy and run the second phase of the parameter optimization experiment in AnyLogic. Based on the knowledge gained from the first phase of the parameter optimization experiment, create a new parameter optimization experiment named "Optimization1" with the iteration mode set to "Fixed", the value set to 200, and the maximum available memory set to 512MB. The optimization objective remains unchanged, and the parameter settings are as shown in the following table:
[0178]
[0179] Click "Build Model (F7)" in the menu bar to confirm that all codes are compiled correctly. Then click "Run (F5) → ALRcallerCase3 / Optimization1" to get Figure 12 The results of the second stage optimization experiment are shown:
[0180] After 26.05 seconds and 49 iterations, the optimal iteration within the range was found to be step 28, with a minimum RMSE of 6.822. At this point, ntree = 3, mtry = 9, nodesize = 2, and maxnodes = 23. This further simplifies the calculation steps and saves computing resources.
[0181] E3S7: Post-processing is performed to correct the predicted values based on the second phase of parameter optimization experiments. This is a data processing technique that uses special computational methods to adjust the model output to better match the statistical characteristics of the actual observed data. According to the definition of RMSE, there are:
[0182] ;
[0183] In practice, for example, if RMSE = 5, it can be considered that the regression effect differs from the true value by an average of ±5.
[0184] This patented invention innovatively designs and proposes a prediction value correction post-processing toolbox called the Flexible Corrector. It currently provides two original prediction value correction post-processing methods: Flexible Difference Addition (FDA) and Flexible Difference Multiplication (FDM), which are defined as follows:
[0185] Let the predicted value vector be , the true value vector is , the root mean square error of the model is The predicted value vector after FDA method processing is It can be expressed as:
[0186] ;
[0187] Let the scaling weight be , then:
[0188] ;
[0189] Then use the FDM method, based on the predicted value and the true value , and obtain the adjusted predicted value Expressed as:
[0190] ;
[0191] The patent of this invention refers to the definition of "year-on-year economic growth rate" in economics, and designs and defines the use of a certain algorithm or post-processing method to reconcile the predicted value. RMSE convergence speed , the formula is:
[0192] ;
[0193] Where: represents the root mean square error before applying some output correction method, Represents the root mean square error after applying a certain output correction method.
[0194]
[0195] This demonstrates that by calling R from the AnyLogic environment using the ALRcaller plug-in library, using the R Random Forest algorithm, processing sensor data in Excel format imported into AnyLogic, and optimizing the parameters of the Random Forest algorithm using AnyLogic's optimization experiment functionality (particularly the OptQuest optimizer), the computational performance of the R randomForest package can be improved by nearly 50% (44.23% in this case). This is currently not possible with the parameter optimization methods included with the randomForest package on the official R support website.
[0196] It will be easily understood by those skilled in the art that the above description is merely a preferred embodiment of the present invention and is not intended to limit the present invention. Any modifications, equivalent substitutions, and improvements made within the spirit and principles of the present invention should be included in the scope of protection of the present invention.
Claims
1. A method for running R language and deploying machine learning algorithms in the AnyLogic software environment, characterized by: The steps include: S1. Build a Java SE platform-based Jar package to host the subpackages and their relationships for running R language and deploying machine learning algorithms in the AnyLogic software environment. S2. Build the project main package to define global variables and parameters, centralize debugging and testing logic, and provide a centralized entry point for potential future modifications and extensions. The main project package includes two first-level sub-packages, namely the first-level sub-package and the second-level sub-package. The first-level sub-package includes several core Java classes and consists of two second-level sub-packages. One of the second-level sub-packages is used for statistical simulation, sample generation, and data analysis, and the other is used to handle various exceptions that may occur when interacting between Java and R. The second-level sub-package is used to provide themes, styles, and format management for R language plots in the Java environment for simulation. S3. Port the project code generated in steps S1 and S2 into the AnyLogic environment. Use AnyLogic to package the active objects contained in the project into a plug-in library that complies with the AnyLogic communication specification. Export the plug-in library to the AnyLogic environment as a separate Jar file. S4. Inserting the exported plug-in library into AnyLogic IDE for testing and use; S5. Conduct R code pre-experiments in the R language environment and bridge the AnyLogic environment with mainstream R machine learning packages through first-level subpackages, building a paradigm ecosystem for the new "machine learning + simulation" research method.
2. The method of running R language and deploying machine learning algorithms in AnyLogic software environment according to claim 1, characterized in that: The process also includes step S6: combining the plug-in library with the native library of AnyLogic software to seamlessly integrate intelligent algorithms with simulations, thereby achieving a paradigm shift resulting from the fusion of the third and fourth paradigms.
3. The method of running R language and deploying machine learning algorithms in AnyLogic software environment according to claim 1, characterized in that: In step S1, the decomposition steps are as follows: S11. Complete the download and installation of the Java toolkit and configure the Java environment variables in the control panel. S12. Build a Jar package based on the Java SE platform.
4. The method of running R language and deploying machine learning algorithms in AnyLogic software environment according to claim 1, characterized in that: In step S2, the first level subpackage includes nine Java classes: CodeUtils, EventHandler, Globals, JavaObject, RCaller, RCode, ROutputParser, RPlotViewer and RstreamHandler.
5. The method of running R language and deploying machine learning algorithms in AnyLogic software environment according to claim 1, characterized in that: In step S2, the two second-level sub-packets of the first first-level sub-packet are the first second-level sub-packet and the second second-level sub-packet, and the steps for constructing the first and second second-level sub-packets are: 1) Configure the runtime environment and main parameters of the first and second-level subpackages, including the Java dependency of the RCaller class that implements R script parsing, execution, and output, and the Java dependency of the RCode class that provides a method for dynamically building R language code; 2) Set the main functional functions of the first and second level sub-packages and their relationships.
6. The method of running R language and deploying machine learning algorithms in AnyLogic software environment according to claim 5, characterized in that: The steps for constructing the second-level sub-package are: 1) Configure the runtime environment and main parameters of the second-level subpackage, including the JDK base package java.lang.Exception, the superclass of Java exceptions that can be coded and resolved, as a dependency; 2) Set the main functional functions of the second and second-level sub-packages.
7. The method of running R language and deploying machine learning algorithms in AnyLogic software environment according to claim 1, characterized in that: In step S2, the steps for constructing the second level sub-package are as follows: 1) Configure the runtime environment and main parameters of the second-level subpackage, including the JDK base package java.awt.Color, which provides classes and interfaces for managing and manipulating colors, as a dependency; 2) Set the main functional functions of the second-level sub-package.
8. The method of running R language and deploying machine learning algorithms in AnyLogic software environment according to claim 1, characterized in that: In step S3, the decomposition steps are as follows: S31: Port the project to the AnyLogic software environment. Convert all main packages, first-level subpackages, and second-level subpackages to "agent types" in the AnyLogic environment. Transfer the Java classes within each subpackage to the corresponding agent type. Complete the construction of the Java package structure and content in steps S1 and S2 in the AnyLogic environment. S32. Create a library in AnyLogic software to run R code to deploy machine learning and deep reinforcement learning in simulation experiments. S33. Use the AnyLogic software interface to export the constructed plug-in library as an independent Jar package.
9. The method of running R language and deploying machine learning algorithms in AnyLogic software environment according to claim 1, characterized in that: In step S5, the decomposition steps are as follows: S51. Prepare the algorithm model on paper and then install the required R language packages; S52: In the RGui graphical user interface or RStudio integrated development environment, reference the installed R language package to conduct preliminary experiments on the R language machine learning algorithm to achieve the expected experimental results; S53: In AnyLogic software, complete the porting of the pre-experimental R language code to the Java environment and add the R script to the simulation environment using the function statement form of the R code reference in the plug-in library.
10. The method of running R language and deploying machine learning algorithms in AnyLogic software environment according to claim 2, characterized in that: In step S6, the decomposition steps are as follows: S61. Utilize the nested model of "R script function + conditional trigger event" or "native library function block + R script parameter transfer" to organically integrate the machine learning methods carried by the R language into simulation methods based on discrete events, system dynamics, and intelligent agents. S62. Using the R language-based machine learning method to predict the delay time of the Delay or Service component in the process modeling library; The queue capacity is predicted using R-based machine learning methods in the Queue component of the process modeling library. The storage capacity is predicted using R-based machine learning methods in the Pipeline component of the fluid library. The key parameter values are predicted using R-based machine learning methods in the Equation Mode - Customization section of the Stock component of the system dynamics library. The dynamic variable values obtained are predicted using R language-based machine learning methods at the assignment of dynamic variable components in the system dynamics library.
Citation Information
Patent Citations
Anylogic and python reinforcement learning algorithm interaction method
CN117807869A
Cited By
Method for introducing multiple physical field dimensions in AnyLogic software environment and carrying out physical-logic hybrid simulation
CN121615542A