Microcosmic traffic simulation engine plug-in hot update system
By designing a plug-in hot update system in the traffic simulation system, real-time update of the plug-in is achieved, the problem of cumbersome plug-in modification in the existing technology is solved, the flexibility and scalability of the simulation system are improved, and the continuity of the experiment is ensured and efficiency.
Patent Information
- Application Number
- CN202411320548.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-09-23
- Publication Date
- 2024-12-06
AI Technical Summary
The existing traffic simulation system plug-in framework lacks thermal update characteristics, which leads to cumbersome modification of plug-in in large-scale simulation experiments and cannot be applied in real time, affecting the continuity and efficiency of the experiment.
A micro-traffic simulation engine plug-in hot update system was designed, using logical takeover service units, file systems, plug-in life cycle management service units, preload error handling units and plug-in monitoring service units to realize lazy loading and real-time update of plug-in. Regularly monitor file description changes, trigger update unit work, and avoid restarting the main program.
Real-time update of plug-ins is realized, the flexibility and scalability of the simulation system is improved, memory resources are saved, engine initialization speed and stability are improved, and time waste and experimental interruptions are avoided due to plug-in modification.
Smart Images

Figure CN119088474A_ABST
Abstract
Description
Technical Field
[0001] The invention relates to a plug-in update system, in particular to a microscopic traffic simulation engine plug-in hot update system. Background Art
[0002] There are many ways to implement plug-in, such as compiling the plug-in into a dynamic link library, and the main program loads these libraries at runtime. Or through object-oriented design patterns, such as factory pattern, strategy pattern, etc., the plug-in is encapsulated as a class, and the plug-in interface is implemented through base class and virtual function. The plug-in framework of the existing traffic simulation system basically does not implement the hot update feature. Most of the processes are to load the plug-in code at startup or load the plug-in code at the first run, but once the loading is completed, the modification of the plug-in code will not be applied to the main program. It is necessary to close the main program and reload the plug-in to apply the updated content, which is quite cumbersome. In large-scale simulation experiments, this method has great disadvantages. A large-scale simulation experiment is continuous and takes a long time. In many cases, the plug-in content needs to be modified in real time and the simulation cannot be interrupted. Therefore, the hot update plug-in framework is very necessary. Summary of the invention
[0003] The purpose of the present invention is to provide a solution to the above-mentioned problem, to provide a plug-in framework that can perform real-time hot update, and to provide a micro traffic simulation engine plug-in hot update system that can perform hot update on plug-ins.
[0004] In order to achieve the above-mentioned purpose, the technical solution adopted by the present invention is as follows: a micro traffic simulation engine plug-in hot update system, applied to a micro traffic simulation engine written in C++ and a plug-in written in Python, the micro traffic simulation engine includes a functional module, the plug-in includes a file description and code, and also includes a logic takeover service unit, a file system, a plug-in life cycle management service unit, a preload error handling unit, and a plug-in monitoring service unit, wherein; Logic takeover service unit: used to modify the internal operation logic of the function module to the external plug-in operation logic when executing the function module; File system: used to store file descriptions and codes of plug-ins, and mark file descriptions stored in the file system as internal file descriptions and file descriptions in plug-ins as external file descriptions; Plug-in lifecycle management service unit: including registration unit, loading unit, unloading unit and update unit; Registration unit: used to register the plug-in. During registration, only the file description of the plug-in is read and saved in the file system. Loading unit: used to lazily load the plug-in. The lazy loading is to load only the external file description when the plug-in is not running, load its code when it is first run, and save the version in memory; Uninstall unit: used to uninstall the plug-in and delete the corresponding file description and code of the file system; Update unit: used to uninstall the old version and register and load the new version when the plug-in changes; Preloading error handling unit: used to test-run the code of the loaded plug-in for syntax checking after lazy loading the plug-in. If the code is correct, the code snapshot is retained, and the plug-in code is uninstalled to only retain the plug-in description information; If the code is wrong, check whether there is a code snapshot. If so, roll back to the previous version through the code snapshot. If not, report an error. Plugin monitoring service unit: used to regularly monitor whether the external file description has changed. If it has changed, it triggers the update unit to work.
[0005] The functional modules include a vehicle module, a road network module, a control module, a phase update module, a simulation model switching module and a persistence module.
[0006] In the plug-in monitoring service unit, the external file description is monitored regularly for changes. Specifically, when the plug-in description file is loaded for the first time, a modification timestamp is recorded to the internal file description, and the plug-in code's most recent modification timestamp is checked regularly. If it is different from the internal description file, it is judged to be a change, and the modification timestamp of the internal file description is updated.
[0007] The file system includes a directory for storing file descriptions, and the directory is a relative path or an absolute path.
[0008] The functional modules and plug-ins are provided with a logic interface for establishing communication between C++ and Python.
[0009] Compared with the prior art, the advantages of the present invention are: (1) The product of the present invention adopts the method of embedding a script language interpreter in the project to achieve plug-in, which has the following advantages: quick start, low learning cost, low development difficulty; rich ecology, Python has various packaged third-party libraries; low coupling, convenient cross-platform, etc.
[0010] (2) The present invention performs lazy loading of the plug-in. When the plug-in is not running, only the external file description is loaded. When the plug-in is first run, its code is loaded and the version is saved in the memory. However, the preload error handling unit is used to perform syntax check on the code. If the code is correct, the code snapshot is retained, and the plug-in code is uninstalled, leaving only the plug-in description information. Lazy loading can save memory resources and increase the engine initialization speed. Code snapshots can increase fault tolerance and enhance engine stability.
[0011] (3) The present invention uses a plug-in monitoring service unit to regularly check the file description. If it finds that the file description has changed, it will trigger the update unit to work; when the update unit is working, the micro traffic simulation engine will uninstall the old version, re-register and load the new version. In this way, the plug-in update can be applied in real time without closing the main program.
[0012] In summary, the hot update feature of the present invention improves the flexibility and scalability of regional microscopic traffic simulation. BRIEF DESCRIPTION OF THE DRAWINGS
[0013] Figure 1 It is a schematic diagram of the system of the present invention; Figure 2 Memory and time graph for directly loading plugins when starting the engine; Figure 3 The lazy loading method of the present invention is used to load the plug-in memory and time map. DETAILED DESCRIPTION
[0014] The present invention will be further described below in conjunction with the accompanying drawings.
[0015] Example 1: See Figure 1 , a micro traffic simulation engine plug-in hot update system, applied to a micro traffic simulation engine written in C++ and a plug-in written in Python, the micro traffic simulation engine includes a functional module, the plug-in includes a file description and code, and also includes a logic takeover service unit, a file system, a plug-in life cycle management service unit, a preload error handling unit, and a plug-in monitoring service unit, wherein; Logic takeover service unit: used to modify the internal operation logic of the function module to the external plug-in operation logic when executing the function module; in the present invention, regarding the logic takeover service unit, taking the vehicle module as an example, the module is used to generate a vehicle at a certain location according to the inherent logic, and the plug-in is an extension of the function of the module. When the plug-in is loaded and a vehicle needs to be generated, the internal operation logic of the function module will be replaced by the external plug-in operation logic, and the vehicle will be generated according to the logic of the plug-in; File system: used to store file descriptions and codes of plug-ins, and mark file descriptions stored in the file system as internal file descriptions and file descriptions in plug-ins as external file descriptions; the file system includes a directory for storing file descriptions, and the directory is a relative path or an absolute path; Plug-in lifecycle management service unit: including registration unit, loading unit, unloading unit and update unit; Registration unit: used to register the plug-in. During registration, only the file description of the plug-in is read and saved in the file system. Loading unit: used to lazily load the plug-in. The lazy loading is to load only the external file description when the plug-in is not running, load its code when it is first run, and save the version in memory; Uninstall unit: used to uninstall the plug-in and delete the corresponding file description and code of the file system; Update unit: used to uninstall the old version and register and load the new version when the plug-in changes; Preloading error handling unit: used to test-run the code of the loaded plug-in for syntax checking after lazy loading the plug-in. If the code is correct, the code snapshot is retained, and the plug-in code is uninstalled to only retain the plug-in description information; If the code is wrong, check whether there is a code snapshot. If so, roll back to the previous version through the code snapshot. If not, report an error. Plugin monitoring service unit: used to regularly monitor whether the external file description has changed. If it has changed, it triggers the update unit to work.
[0016] The functional modules include a vehicle module, a road network module, a control module, a phase update module, a simulation model switching module and a persistence module.
[0017] The functional modules and plug-ins are provided with a logic interface for establishing communication between C++ and Python.
[0018] In the plug-in monitoring service unit, the external file description is monitored regularly for changes. Specifically, when the plug-in description file is loaded for the first time, a modification timestamp is recorded to the internal file description, and the plug-in code's most recent modification timestamp is checked regularly. If it is different from the internal description file, it is judged to be a change, and the modification timestamp of the internal file description is updated.
[0019] Example 2: See Figure 2 and Figure 3 By comparing the memory and startup time of directly loading the plug-in when starting the engine and using the lazy loading method, it can be seen intuitively that when the engine is started using these two methods, the memory usage when the engine is just started is 98M and 95M respectively, and the startup time is about 17s and 12s respectively.
[0020] In addition, when simulating a simple intersection and simulating 50 steps, it takes about 7 seconds, so starting the simulation and running to a specific simulation state takes about 30 seconds or more. If a complex road network is simulated and a continuous large-scale experiment is simulated, it takes several minutes to initialize the simulation. Therefore, if the plug-in logic is modified in a simulation system that does not have the hot update plug-in feature, each time the code is modified, the simulation engine needs to be restarted to apply the updated plug-in logic. Each change requires waiting for several minutes, which not only wastes a lot of time but also destroys the continuity of the experiment. The present invention solves this pain point. The plug-in logic update no longer needs to restart the simulation engine, but can be applied in real time.
[0021] The above description is only 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 protection scope of the present invention.
Claims
1. A micro traffic simulation engine plug-in hot update system, applied to a micro traffic simulation engine written in C++ and a plug-in written in Python, the micro traffic simulation engine includes a functional module, the plug-in includes a file description and a code, characterized in that: It also includes a logic takeover service unit, a file system, a plug-in lifecycle management service unit, a preload error handling unit, and a plug-in monitoring service unit, among which; Logic takeover service unit: used to modify the internal operation logic of the function module to the external plug-in operation logic when executing the function module; File system: used to store file descriptions and codes of plug-ins, and mark file descriptions stored in the file system as internal file descriptions and file descriptions in plug-ins as external file descriptions; Plug-in lifecycle management service unit: including registration unit, loading unit, unloading unit and update unit; Registration unit: used to register the plug-in. During registration, only the file description of the plug-in is read and saved in the file system. Loading unit: used to lazily load the plug-in. The lazy loading is to load only the external file description when the plug-in is not running, load its code when it is first run, and save the version in memory; Uninstall unit: used to uninstall the plug-in and delete the corresponding file description and code of the file system; Update unit: used to uninstall the old version and register and load the new version when the plug-in changes; Preloading error handling unit: used to test-run the code of the loaded plug-in for syntax checking after lazy loading the plug-in. If the code is correct, the code snapshot is retained, and the plug-in code is uninstalled to only retain the plug-in description information; If the code is wrong, check whether there is a code snapshot. If so, roll back to the previous version through the code snapshot. If not, report an error. Plugin monitoring service unit: used to regularly monitor whether the external file description has changed. If it has changed, it triggers the update unit to work.
2. A micro traffic simulation engine plug-in hot update system according to claim 1, characterized in that: The functional modules include a vehicle module, a road network module, a control module, a phase update module, a simulation model switching module and a persistence module.
3. A micro traffic simulation engine plug-in hot update system according to claim 1, characterized in that: In the plug-in monitoring service unit, the external file description is monitored regularly for changes. Specifically, when the plug-in description file is loaded for the first time, a modification timestamp is recorded to the internal file description, and the plug-in code's most recent modification timestamp is checked regularly. If it is different from the internal description file, it is judged to be a change, and the modification timestamp of the internal file description is updated.
4. A micro traffic simulation engine plug-in hot update system according to claim 1, characterized in that: The file system includes a directory for storing file descriptions, and the directory is a relative path or an absolute path.
5. A micro traffic simulation engine plug-in hot update system according to claim 1, characterized in that: The functional modules and plug-ins are provided with a logic interface for establishing communication between C++ and Python.
Citation Information
Patent Citations
Plug-in management method, device and equipment and storage medium
CN109597623A
Application program access method and device and storage medium
CN110162345A
Real-time processing method and real-time processing system based on hot update
CN111970140A
Plug-in updating method and device, electronic equipment and computer readable storage medium
CN115964061A
