Thread Pool-Based Particle Filter Concurrent Sampling Method, Device and Computer Equipment
Through the particle filtering concurrent sampling method based on thread pool, the problem of low particle filtering sampling efficiency in microscopic simulation is solved, efficient concurrent execution of computing tasks is achieved, real-time requirements of dynamic data-driven simulation are met, and simulation performance is improved.
Patent Information
- Application Number
- CN202510540463.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-04-27
- Publication Date
- 2025-07-18
- Estimated Expiration
- 2045-04-27
AI Technical Summary
In microscopic simulation, the particle filtering sampling process is performed serially, resulting in low operational efficiency and high resource consumption, which cannot meet the real-time requirements of dynamic data-driven simulation.
The particle filtering concurrent sampling method based on thread pool is adopted. By creating thread pools and task queues, the computing tasks, task queues and threads are abstracted into a multi-service desk single-queue queuing system standardized formally described by discrete event systems, and dynamically dispatch and allocate idle threads to execute computing tasks to realize concurrent execution of computing tasks.
It improves the execution efficiency of particle filter sampling and the operation efficiency of microscopic simulation, reduces resource consumption, ensures real-time performance of dynamic data-driven simulation, and achieves better simulation performance.
Smart Images

Figure CN120045342B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the technical field of simulation task scheduling, and particularly to a particle filter concurrent sampling method, device, and computer device based on a thread pool. Background Art
[0002] Dynamic data-driven simulation is a "model and data combination" simulation paradigm that continuously injects observations (data) of the real system into the simulation (model), allowing the data to dynamically correct the simulation (state, parameters) to improve simulation-based estimation and prediction capabilities. Since dynamic data-driven simulation integrates information from both model prediction and real-time observation, it can more accurately estimate the state of the real system and predict the future evolution of the state. Due to such advantages, dynamic data-driven simulation has been successfully applied to scenarios such as forest fire spread prediction, pedestrian movement trajectory prediction, and vehicle trajectory reconstruction in urban traffic systems. In dynamic data-driven simulation, "data dynamically correcting the simulation" is achieved by data assimilation technology. Data assimilation is a method of combining observed data of the real system and simulation predictions to estimate the state of the real system. Common data assimilation algorithms include variational assimilation methods (e.g., three-dimensional variational method 3D-VAR and four-dimensional variational method 4D-VAR), Kalman filter, extended Kalman filter, ensemble Kalman filter, particle filter, etc. Most data assimilation algorithms rely on certain assumptions, such as assuming that the system / observation model is a linear model or assuming that the system / observation error is a Gaussian error. The particle filter algorithm uses a set of Monte Carlo samples (particles) and corresponding weights to approximate the probability distribution and replaces the integral operation with the sample mean. Therefore, it has no restrictions on the model and error. Since the "simulation" in dynamic data-driven simulation generally refers to microscopic simulation and its state evolution process has highly nonlinear / non-Gaussian characteristics, the most commonly used data assimilation method in dynamic data-driven simulation is the particle filter algorithm.
[0003] The particle filter data assimilation software system is a prerequisite and basic support for carrying out dynamic data-driven simulation. However, implementing particle filter data assimilation in microscopic simulation is not as simple and intuitive as in ordinary real vector state equations. In microscopic simulation, the particle filter sampling process is a cyclic simulation operation process that repeatedly runs the simulation model for a period of time with the state of the simulation model at the previous moment as the initial value to obtain the state of the simulation model at the next moment. The sampling process not only involves the operation of simulation experiments but is also an asynchronous call process (in ordinary real vector state equations, this process is generally a synchronous call process). Therefore, it is necessary to design a particle filter sampling method suitable for microscopic simulation to ensure that each calculation step in the particle filter is executed in the correct logical order.
[0004] Existing methods implement the particle filter sampling step in microscopic simulation by means of rollback. During the sampling process based on rollback, operations such as saving and restoring the model state and resetting the future event table of the simulator need to be performed in the rollback simulation. These operations are closely related to the specific application and are error-prone. In addition, the sampling process based on rollback is executed serially. For applications with high real-time requirements such as dynamic data-driven simulation, the running efficiency and resource consumption of serial execution will become bottlenecks in simulation performance. Summary of the Invention
[0005] Based on this, in view of the above technical problems, it is necessary to provide a particle filter concurrent sampling method, device and computer device based on a thread pool, which can ensure that each calculation step of the particle filter in microscopic simulation is executed in the correct logical order, improve the execution efficiency of particle filter sampling and the running efficiency of microscopic simulation through the concurrent execution of calculation tasks, reduce certain resource consumption and computational amount, ensure the real-time requirements of dynamic data-driven simulation, and thus achieve better simulation performance.
[0006] A particle filter concurrent sampling method based on a thread pool, the method comprising:
[0007] In the initialization stage, the main thread creates a thread pool and a task queue; wherein, the task queue includes a calculation task queue and a thread request queue stored in sequence.
[0008] After initialization is completed, the main thread creates a number of calculation tasks, and abstracts the calculation tasks, the task queue and the threads into a multi-server single-queue queuing system formalized by the Discrete Event System Specification (DEVS). The multi-server single-queue queuing system dynamically schedules and allocates idle threads to execute the calculation tasks based on the states of the calculation task queue and the thread request queue, so as to realize the concurrent execution of the calculation tasks; wherein, the calculation tasks are particle filter sampling tasks in microscopic simulation.
[0009] In one embodiment, abstracting the calculation tasks, the task queue and the threads into a multi-server single-queue queuing system formalized by the Discrete Event System Specification includes:
[0010] Abstracting the calculation tasks, the task queue and the threads into a multi-server single-queue queuing system, each calculation task serves as a customer in the system and receives the calculation service of each thread serving as a service desk.
[0011] After formalizing the multi-server single-queue queuing system using Discrete Event System Specification, the computing tasks, task queues, and threads in the multi-server single-queue queuing system are all described based on the atomic model of the Discrete Event System Specification, and they are coupled and interact with each other through input and output ports.
[0012] In one embodiment, the multi-server single-queue queuing system dynamically schedules and allocates idle threads to execute computing tasks based on the status of the computing task queue and the thread request queue, achieving concurrent execution of computing tasks, including:
[0013] The task queue receives the computing task processing requests from each thread through its own request port, and sorts them in the order of the requests being issued to form a thread request queue; at the same time, after the task queue receives the computing tasks submitted by the main thread through its arrival port, it determines whether there are idle threads in the thread request queue;
[0014] If there are, it sends the computing task to the input port of the idle thread through the output port of the task queue, and uses the idle thread to execute the computing task; otherwise, it sorts the computing tasks in the order of their submission to form a computing task queue and waits for execution;
[0015] When the thread finishes executing the computing task, it interacts with the end port of the computing task through its own end port to notify that the computing task has been executed, and the computing task can continue with subsequent operations; at the same time, the thread becomes idle and sends a computing task processing request to the task queue again through its own request port to query whether there are computing tasks waiting to be executed in the computing task queue;
[0016] If there are, it takes out the computing task at the head of the computing task queue and executes it; otherwise, it continues to remain idle and waits for the main thread to submit new computing tasks;
[0017] When all computing tasks have been executed, all threads in the thread pool become idle and wait to execute the computing tasks generated by particle filter sampling in the next round of microscopic simulation.
[0018] In one embodiment, the execution logic of the task queue described based on the atomic model of the Discrete Event System Specification is expressed as:
[0019] ;
[0020] Where, represents the task queue, represents the input of the task queue; where, represents the set of input ports of the task queue, including the arrival port and the request port ; The arrival port Input Represents the ID of the computing task submitted by the main thread, request port Input Represents the ID of the thread that requests to allocate a computing task from the task queue;
[0021] Indicates the output of the task queue; among them, Indicates the set of output ports of the task queue, which contains only one output port ; Output port Output Represents the ID of the computing task that the thread is about to execute;
[0022] Indicates the state of the task queue; among them, the computing task queue And the thread request queue Are both FIFO queues, which store the IDs of the computing tasks waiting in line to be executed and the IDs of the threads waiting in line to be allocated computing tasks respectively;
[0023] Represents the internal state transition function of the task queue. The internal state transition function of the task queue describes how the state of the task queue changes under the control of only the time advancement function Without external input, specifically defined as:
[0024] ;
[0025] Among them, "-1" means removing the head element from the queue;
[0026] Represents the external state transition function of the task queue; among them, the set , The external state transition function of the task queue describes how the state of the task queue changes under the excitation of external input, specifically defined as:
[0027] ;
[0028] Among them, "+" means inserting at the end of the queue;
[0029] Represents the output function of the task queue, which defines what information should be output when the task queue undergoes an internal state transition, specifically defined as:
[0030] ;
[0031] Among them, In Is the computing task queue The ID of the computing task at the head of the queue; it should be noted that the thread ID in the thread pool is equal to the thread request queue The thread with the thread ID at the head of the queue will be responsible for executing the computing task with the ID ;
[0032] Represents the time advancement function of the task queue, which defines the duration for which the task queue remains in the state in the absence of external input influences, and is specifically defined as:
[0033] ;
[0034] The above formula indicates that when both the computing task queue and the thread request queue are not empty, the time advancement value is set to 0, thereby immediately triggering the internal state transition function of the task queue to allocate the computing task at the head of the computing task queue to the idle thread at the head of the thread request queue for execution; the above process is repeated until one of the queues is empty.
[0035] In one of the embodiments, the execution logic of the thread described based on the discrete event system specification atomic model is expressed as:
[0036] ;
[0037] Among them, represents the thread, represents the input of the thread; among them, represents the set of input ports of the thread, which only contains one input port ; The input of the input port represents the ID of the computing task assigned to this thread by the task queue;
[0038] represents the output of the thread; among them, represents the set of output ports of the thread, including the end port and the request port ; The output of the end port represents the ID of the computing task completed by the thread, and the output of the request port represents the ID of the thread;
[0039] represents the state of the thread; among them, in represents the ID of the computing task currently being executed by this thread, represents the time remaining for this thread to complete this computing task; if , it indicates that the thread is currently in an idle state, and at this time, set ;
[0040] represents the internal state transition function of the thread, and the specific definition is:
[0041] ;
[0042] represents the external state transition function of the thread, and the specific definition is:
[0043] ;
[0044] Among them, represents the time required for the thread to execute the computing task; it should be noted that only when the thread is in state, that is, in the idle state, it is possible to receive the ID of the computing task output by the task queue;
[0045] represents the output function of the thread; when the thread finishes executing the computing task, on the one hand, it notifies through the output port that the computing task has been executed; on the other hand, it also sends a request to the task queue to allocate a new computing task through the output port; therefore, the output function of the thread is specifically defined as:
[0046] ;
[0047] Among them, refers to the ID of the thread itself;
[0048] represents the time advancement function of the thread, and the specific definition is:
[0049] .
[0050] In one embodiment, the computing task is specifically defined as: a simulation running process during particle filter sampling in microscopic simulation. This simulation running process uses the particle state at the previous moment as the initial value, and after running the simulation model for a period of time, the particle state at the next moment is obtained.
[0051] In one embodiment, the simulation running process is carried out under the constraint of a simulation experiment framework, which defines the entities participating in the modeling and simulation activities and the relationships between the entities, including simulation experiments, simulation models, simulators, and running control conditions; among them, the simulation experiment is carried out on the simulation model, and the execution of the simulation model requires a simulator; the simulation experiment needs to be carried out under given running control conditions, and the running control conditions include the simulation start time, warm-up time, and running duration; one simulation experiment needs to be run multiple times under the same running control conditions, and each run is called a sample, and different random number seeds need to be used for each run.
[0052] In one embodiment, when performing particle filter sampling in microscopic simulation, the computing task is further defined as a sample run in a simulation experiment and abstracted into a simulation running class; among them, the simulation running class contains five attributes, namely the simulation model, simulator, initial state, warm-up time, and running duration required for the sample run, where the simulation start time is implicit in the initial state; the simulation running class also contains a constructor and a running function, where the constructor is used to complete the initialization of the simulation according to the simulation model, simulator, initial state, warm-up time, and running duration; the running function is used to drive the simulation to run according to the simulation model type and the simulation platform running mechanism.
[0053] A particle filter concurrent sampling device based on a thread pool, the device includes:
[0054] An initialization module, used to create a thread pool and a task queue by the main thread during the initialization phase; among them, the task queue contains a computing task queue and a thread request queue stored in sequence;
[0055] A task scheduling module, used to create several computing tasks by the main thread after the initialization is completed, and abstract the computing tasks, task queue, and threads into a multi-server single-queue queuing system formalized by the discrete event system specification. This multi-server single-queue queuing system dynamically schedules and allocates idle threads to execute computing tasks based on the status of the computing task queue and the thread request queue, realizing the concurrent execution of computing tasks; among them, the computing task is a particle filter sampling task in microscopic simulation.
[0056] A computer device, including a memory and a processor, the memory stores a computer program, and when the processor executes the computer program, the following steps are implemented:
[0057] In the initialization phase, create a thread pool and a task queue by the main thread; among them, the task queue contains a computing task queue and a thread request queue stored in sequence;
[0058] After initialization is completed, the main thread creates several computing tasks, and abstracts the computing tasks, task queues, and threads into a multi-server single-queue queuing system formalized in the form of a discrete event system specification. This multi-server single-queue queuing system dynamically schedules and allocates idle threads to execute computing tasks based on the states of the computing task queue and the thread request queue, realizing the concurrent execution of computing tasks; among them, the computing task is the particle filter sampling task in the microscopic simulation.
[0059] The above particle filter concurrent sampling method, device, and computer device based on a thread pool have the following beneficial effects:
[0060] 1. The thread pool maintains, manages, schedules, and runs the threads. Since the execution of each computing task is independent and does not interfere with each other, and an idle thread is assigned to each computing task, and multiple threads can concurrently execute the computing tasks, thus realizing the particle filter concurrent sampling in the microscopic simulation, ensuring that each computing step in the particle filter in the microscopic simulation is executed in the correct logical order, and improving the execution efficiency of the particle filter sampling and the running efficiency of the microscopic simulation through the concurrent execution of the computing tasks.
[0061] 2. After the threads in the thread pool complete the computing tasks, they are not destroyed but turned into an idle state waiting to execute the next computing task. By reusing the already created threads, the thread pool can reduce the operating system resource overhead and computing volume brought by the frequent creation and destruction of threads, ensuring the real-time requirements of the dynamic data-driven simulation, and thus achieving better simulation performance. Description of the Drawings
[0062] Figure 1 It is a schematic flowchart of the particle filter concurrent sampling method based on a thread pool in an embodiment;
[0063] Figure 2 It is a schematic diagram of a multi-server single-queue queuing system formalized in the form of a discrete event system specification in an embodiment;
[0064] Figure 3 It is a schematic internal structure diagram of a computer device in an embodiment. Detailed Embodiments
[0065] In order to make the purpose, technical solutions, and advantages of this application clearer, the following further details this application in conjunction with the drawings and embodiments. It should be understood that the specific embodiments described here are only used to explain this application and are not used to limit this application.
[0066] In one embodiment, as Figure 1 shown, a particle filter concurrent sampling method based on a thread pool is provided, including the following steps:
[0067] Step S1, in the initialization phase, the main thread creates a thread pool and a task queue; among them, the task queue includes a calculation task queue and a thread request queue stored in a sorted manner.
[0068] Step S2, after the initialization is completed, the main thread creates several calculation tasks, and abstracts the calculation tasks, the task queue, and the threads into a multi-server single-queue queuing system formalized by the discrete event system specification. This multi-server single-queue queuing system dynamically schedules and allocates idle threads to execute the calculation tasks based on the states of the calculation task queue and the thread request queue, realizing the concurrent execution of the calculation tasks; among them, the calculation task is the particle filter sampling task in the microscopic simulation.
[0069] Among them, abstracting the calculation tasks, the task queue, and the threads into a multi-server single-queue queuing system formalized by the discrete event system specification includes:
[0070] Abstracting the calculation tasks, the task queue, and the threads into a multi-server single-queue queuing system, each calculation task is regarded as a customer in the system and receives the calculation service of each thread as a service desk; after formalizing the multi-server single-queue queuing system by using the discrete event system specification, the calculation tasks, the task queue, and the threads in this multi-server single-queue queuing system are all described based on the atomic model of the discrete event system specification, and they are coupled and interact with each other through input and output ports.
[0071] The structure of the multi-server single-queue queuing system formalized by the discrete event system specification is as Figure 2 shown. The specific steps for this system to dynamically schedule and allocate idle threads to execute the calculation tasks based on the states of the calculation task queue and the thread request queue, and realize the concurrent execution of the calculation tasks include:
[0072] The task queue receives the calculation task processing requests of each thread through its own request port, sorts them in the order of the requests being sent, and forms a thread request queue; at the same time, after the task queue receives the calculation tasks submitted by the main thread through its arrival port, it judges whether there are any idle threads in the thread request queue;
[0073] If there are, the calculation task is sent to the input port of the idle thread through the output port of the task queue, and the idle thread is used to execute the calculation task; otherwise, they are sorted in the order of the calculation tasks being submitted, form a calculation task queue and wait to be executed;
[0074] After the thread finishes executing the computing task, it interacts with the end port of the computing task through its own end port to notify that the computing task has been executed, and the computing task can continue to perform subsequent operations (such as obtaining the simulation model state and obtaining predicted observation data, etc.); meanwhile, the thread transitions to the idle state and sends a computing task processing request to the task queue again through its own request port to query whether there is a computing task waiting to be executed in the computing task queue;
[0075] If there is, take out the computing task at the head of the computing task queue and execute it; otherwise, continue to remain in the idle state waiting for the main thread to submit a new computing task;
[0076] After all computing tasks are executed, all threads in the thread pool transition to the idle state, waiting to execute the computing tasks generated by particle filter sampling in the next round of microscopic simulation.
[0077] The above steps schedule and allocate idle threads to concurrently execute computing tasks according to the thread pool and the task queue, so as to realize the concurrent sampling of particle filter in microscopic simulation, ensure that each computing step of particle filter in microscopic simulation is executed in the correct logical order, and improve the execution efficiency of particle filter sampling and the running efficiency of microscopic simulation through the concurrent execution of computing tasks. And the threads in the thread pool will not be destroyed after executing the computing tasks, but transition to the idle state waiting to execute the next computing task. The thread pool can reduce the operating system resource overhead and computing volume brought by frequent creation and destruction of threads by reusing the already created threads, ensure the real-time requirements of dynamic data-driven simulation, and thus achieve better simulation performance.
[0078] Specifically, the execution logic of the task queue described based on the discrete event system specification atomic model is expressed as:
[0079] ;
[0080] Among them, represents the task queue, represents the input of the task queue; among them, represents the set of input ports of the task queue, including the arrival port and the request port ; the input of the arrival port represents the ID of the computing task submitted by the main thread, and the input of the request port represents the ID of the thread that requests to allocate a computing task to the task queue;
[0081] represents the output of the task queue; among them, The set of output ports representing the task queue, which contains only one output port ; The output port Output represents the ID of the computational task that the thread is about to execute;
[0082] represents the status of the task queue; among them, the computational task queue and the thread request queue are both FIFO queues, storing respectively the IDs of the computational tasks waiting in line to be executed and the IDs of the threads waiting in line to be assigned computational tasks;
[0083] represents the internal state transition function of the task queue. The internal state transition function of the task queue describes how the state of the task queue changes under the control of only the time advancement function in the absence of external input, and is specifically defined as:
[0084] ;
[0085] where, "-1" means removing the head element from the queue;
[0086] represents the external state transition function of the task queue; among them, the set , the external state transition function of the task queue describes how the state of the task queue changes under the excitation of external input, and is specifically defined as:
[0087] ;
[0088] where, "+" means inserting at the tail of the queue;
[0089] represents the output function of the task queue, which defines what information should be output when the task queue undergoes an internal state transition, and is specifically defined as:
[0090] ;
[0091] where, in is the ID of the computational task at the head of the computational task queue ; It should be noted that the thread in the thread pool whose thread ID is equal to the thread ID at the head of the thread request queue will be responsible for executing the computational task with ID ;
[0092] The time advancement function representing the task queue, which defines the duration for which the task queue remains in the state without the influence of external inputs, is specifically defined as:
[0093] ;
[0094] The above equation indicates that when both the computation task queue and the thread request queue are not empty, the time advancement value is set to 0, thereby immediately triggering the internal state transition function of the task queue to allocate the computation task at the head of the computation task queue to the idle thread at the head of the thread request queue for execution; the above process is repeated continuously (constantly allocating computation tasks to idle threads) until one of the queues becomes empty (there are no idle threads or no queued computation tasks).
[0095] Specifically, the execution logic of the thread described based on the atomic model of the discrete event system specification is expressed as:
[0096] ;
[0097] where represents the thread, represents the input of the thread; among them, represents the set of input ports of the thread, which contains only one input port ; The input of the input port represents the ID of the computation task allocated to this thread by the task queue;
[0098] represents the output of the thread; among them, represents the set of output ports of the thread, including the end port and the request port ; The output of the end port represents the ID of the computation task completed by the thread, and the output of the request port represents the ID of the thread;
[0099] represents the state of the thread; among them, in represents the ID of the computation task currently being executed by this thread, represents the remaining time required for this thread to complete this computation task; if , it indicates that the thread is currently in an idle state, and at this time, set ;
[0100] represents the internal state transition function of the thread, which is specifically defined as:
[0101] ;
[0102] Represents the external state transition function of the thread, and is specifically defined as:
[0103] ;
[0104] Among them, represents the time required for the thread to execute the computing task; it should be noted that only when the thread is in state, that is, in the idle state, can it possibly receive the ID of the computing task output by the task queue;
[0105] represents the output function of the thread; when the thread finishes executing the computing task, on the one hand, it notifies through the output port that the computing task has been executed; on the other hand, it also sends a request to allocate a new computing task to the task queue through the output port; therefore, the output function of the thread is specifically defined as:
[0106] ;
[0107] Among them, refers to the ID of the thread itself;
[0108] Represents the time advancement function of the thread, and is specifically defined as:
[0109] .
[0110] Furthermore, the above-mentioned computing task is specifically defined as: a simulation running process during particle filter sampling in microscopic simulation. This simulation running process takes the particle state at the previous moment as the initial value, and after running the simulation model for a period of time, obtains the particle state at the next moment.
[0111] Moreover, the simulation running process is carried out under the constraints of a simulation experiment framework, which defines the entities participating in the modeling and simulation activities and the relationships between the entities, including simulation experiment (Experiment), simulation model (SimulationModel), simulator (Simulator), and run control conditions (RunControl); among them, the simulation experiment is carried out on the simulation model, and the execution of the simulation model requires a simulator; the simulation experiment needs to be carried out under given run control conditions, and the run control conditions include simulation start time (startTime), warm-up time (warmupTime), and run duration (runLength); a simulation experiment needs to be run multiple times under the same run control conditions, and each run is called a replication, and different random number seeds (seed) need to be used for each run.
[0112] Therefore, when performing particle filter sampling in microscopic simulation, the computing task is further defined as a sample run in the simulation experiment and abstracted into a SimulationRun class; among them, the SimulationRun class contains five attributes, namely the simulation model, simulator, initial state (initialState), warm-up time, and run duration required for the sample run, where the simulation start time is implicitly contained in the initial state; the SimulationRun class also contains a constructor and a run function, where the constructor is used to complete the initialization of the simulation according to the simulation model, simulator, initial state, warm-up time, and run duration; the run function is used to drive the simulation run according to the simulation model type and the simulation platform operation mechanism. For example, when using the event scheduling method to execute a discrete event model, it is necessary to loop through and take out the first event in the simulator's future event table and execute the event handling function until the future event table is empty or the preset run duration is reached.
[0113] After the computing task is completed, it is also necessary to obtain the simulation model state and the predicted observation data (i.e., to implement the mapping from state to observation) to support the update of particle weights. Therefore, the simulation model needs to implement the DataAssimilationModelInterface interface, which supports users to initialize the simulation model based on the given state (setInitialModelState), and obtain the state of the simulation model (getModelState), as well as the predicted observation data (getPredictedMeasurement).
[0114] Furthermore, the above particle filter concurrent sampling method based on a thread pool can be implemented based on Java concurrent programming. The Java Development Kit (JDK) is a software development environment for developing and testing Java programs. Since its design, the JDK has supported concurrent programming, and since version 5.0, the java.util.concurrent package has been added to the toolkit, which can greatly simplify the development of Java concurrent (multi-threaded) applications. Users can use the Executor interface and its implementation classes in the java.util.concurrent package for concurrent programming. Executor provides an intermediate layer between the user side and task execution: the user side does not directly execute tasks but executes tasks through an intermediate object. Executor allows developers to manage the execution of asynchronous tasks without explicitly managing the thread lifecycle. Developers can create different types of thread pools (e.g., FixedThreadPool and CachedThreadPool) by calling the factory methods of the Executors class in the java.util.concurrent package; when calling the factory method, an ExecutorService object (a type of Executor with a lifecycle) is created, and users submit, execute, and manage tasks through this object.
[0115] Users can define tasks by implementing the Runnable or Callable interfaces in the java.util.concurrent package: Runnable tasks do not return a value after execution, while Callable tasks can return a value after execution. The Callable interface is a generic interface, and its type parameter represents the return value type after calling the call method of the Callable interface. Also, Callable tasks must be submitted through the submit method of the ExecutorService interface. After calling the submit method, a Future object is generated, which is used to represent the result of the asynchronous calculation. Future is also a generic interface, which is parameterized according to the result type returned by Callable. The Future interface provides corresponding methods to check whether the calculation task is completed (isDone) and obtain the calculation result (get). When calling the get method of the Future object, this method will block until the task is completed and a result is produced.
[0116] In one embodiment, a particle filter concurrent sampling device based on a thread pool is provided, including:
[0117] An initialization module, configured to create a thread pool and a task queue by a main thread during an initialization phase; wherein, the task queue includes a calculation task queue stored in a sorted manner and a thread request queue;
[0118] A task scheduling module, configured to create a plurality of calculation tasks by a main thread after initialization, and abstract the calculation tasks, the task queue, and threads into a multi-server single-queue queuing system formalized and described in the form of a discrete event system specification. The multi-server single-queue queuing system dynamically schedules and allocates idle threads to execute the calculation tasks based on the states of the calculation task queue and the thread request queue, so as to implement concurrent execution of the calculation tasks; wherein, the calculation task is a particle filter sampling task in microscopic simulation.
[0119] For the specific limitations of the particle filter concurrent sampling device based on a thread pool, reference can be made to the limitations of the particle filter concurrent sampling method based on a thread pool in the foregoing text, which will not be elaborated herein. Each module in the above-mentioned particle filter concurrent sampling device based on a thread pool can be implemented in whole or in part by software, hardware, and their combination. The above-mentioned modules can be embedded in the processor of the computer device in a hardware form or be independent of it, or be stored in the memory of the computer device in a software form, so that the processor can call and execute the operations corresponding to each of the above-mentioned modules.
[0120] In one embodiment, a computer device is provided. The computer device can be a server, and its internal structural diagram can be as Figure 3 shown. The computer device includes a processor, a memory, a network interface, and a database connected through a system bus. Among them, the processor of the computer device is used to provide computing and control capabilities. The memory of the computer device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system, a computer program, and a database. The internal memory provides an environment for the operation of the operating system and the computer program in the non-volatile storage medium. The database of the computer device is used to store data. The network interface of the computer device is used to communicate with an external terminal through a network connection. When the computer program is executed by the processor, it implements a particle filter concurrent sampling method based on a thread pool.
[0121] Those skilled in the art can understand that Figure 3 the structure shown in
[0122] is only a block diagram of some structures related to the solution of the present application, and does not constitute a limitation on the computer device to which the solution of the present application is applied. The specific computer device may include more or fewer components than those shown in the figure, or combine some components, or have different component arrangements. In one embodiment, a computer device is provided, including a memory and a processor. The memory stores a computer program, and when the processor executes the computer program, the following steps are implemented:
[0123] In the initialization phase, the main thread creates a thread pool and a task queue; among them, the task queue includes a calculation task queue and a thread request queue stored in sorted order.
[0124] After the initialization is completed, the main thread creates several calculation tasks, and abstracts the calculation tasks, the task queue, and the threads into a multi-server single-queue queuing system formalized by the discrete event system specification. The multi-server single-queue queuing system dynamically schedules and allocates idle threads to execute the calculation tasks based on the states of the calculation task queue and the thread request queue, so as to realize the concurrent execution of the calculation tasks; among them, the calculation task is the particle filter sampling task in the microscopic simulation.
[0125] The technical features of the above embodiments can be combined arbitrarily. For the sake of brevity of description, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, it should be considered as the scope recorded in this specification.
[0126] The above-described embodiments only represent several implementation manners of the present application, and their descriptions are relatively specific and detailed, but they should not be understood as limiting the scope of the present application. It should be noted that for those of ordinary skill in the art, without departing from the concept of the present application, several deformations and improvements can still be made, and these all belong to the protection scope of the present application. Therefore, the protection scope of the present application should be determined by the appended claims.
Claims
1. A particle filter concurrent sampling method based on a thread pool, characterized in that, The method includes: In the initialization phase, the main thread creates a thread pool and a task queue; wherein, the task queue includes a calculation task queue and a thread request queue that are sorted and stored; After the initialization is completed, the main thread creates several calculation tasks, and abstracts the calculation tasks, the task queue, and the threads into a multi-server single-queue queuing system formalized by the discrete event system specification. This multi-server single-queue queuing system dynamically schedules and allocates idle threads to execute the calculation tasks based on the states of the calculation task queue and the thread request queue, realizing the concurrent execution of the calculation tasks; wherein, the calculation task is a particle filter sampling task in microscopic simulation; In the multi-server single-queue queuing system, the execution logic of the task queue described based on the discrete event system specification atomic model is expressed as: ; Among them, represents the task queue, denotes the input of the task queue; among them, represents the set of input ports of the task queue, including the arrival port and the request port ; the input of the arrival port represents the ID of the computing task submitted by the main thread, and the input of the request port represents the ID of the thread that requests the allocation of a computing task from the task queue; the input of represents the ID of the thread that requests the allocation of a computing task from the task queue; Represents the output of the task queue; wherein, Represents the set of output ports of the task queue, which contains only one output port ; The output port Output Represents the ID of the computational task to be executed by the thread; Indicates the status of the task queue; among them, the computing task queue and the thread request queue are both FIFO queues, which store the IDs of computing tasks that are queuing up waiting to be executed, and the IDs of threads that are queuing up waiting to be assigned computing tasks respectively; Represents the internal state transition function of the task queue. The internal state transition function of the task queue describes how the state of the task queue changes under the control of only the time advancement function without external input. It is specifically defined as: ; wherein, "-1" means removing the head element from the queue; Represents the external state transition function of the task queue; among them, the set , the external state transition function of the task queue describes how the state of the task queue changes under the excitation of external inputs, and is specifically defined as: ; wherein, "+" means inserting at the end of the queue; The output function representing the task queue, which defines what information should be output when an internal state transition occurs in the task queue, is specifically defined as follows: ; Among them, in is the ID of the computing task at the head of the computing task queue ; It should be noted that the thread in the thread pool whose thread ID is equal to the thread ID at the head of the thread request queue will be responsible for executing the computing task with the ID of . The time advancement function representing the task queue, which defines the duration for which the task queue remains in the state without being affected by external inputs, is specifically defined as: ; The above formula means that when both the calculation task queue and the thread request queue are not empty, the time advancement value is set to 0, thereby immediately triggering the internal state transition function of the task queue, and allocating the calculation task at the head of the calculation task queue to the idle thread at the head of the thread request queue for execution; the above process is repeated until one of the queues is empty.
2. The method according to claim 1, characterized in that, Abstracting the calculation tasks, the task queue, and the threads into a multi-server single-queue queuing system formalized by the discrete event system specification includes: Abstracting the calculation tasks, the task queue, and the threads into a multi-server single-queue queuing system, each calculation task serves as a customer in the system and receives the calculation service of each thread serving as a server; After formalizing the multi-server single-queue queuing system using the discrete event system specification, the calculation tasks, the task queue, and the threads in this multi-server single-queue queuing system are all described based on the discrete event system specification atomic model, and they are coupled and interact with each other through input and output ports.
3. The method according to claim 2, wherein This multi-server single-queue queuing system dynamically schedules and allocates idle threads to execute the calculation tasks based on the states of the calculation task queue and the thread request queue, realizing the concurrent execution of the calculation tasks, including: The task queue receives the calculation task processing requests of each thread through its own request port, and sorts them in the order of the requests being sent, forming a thread request queue; at the same time, after the task queue receives the calculation tasks submitted by the main thread through its arrival port, it judges whether there are idle threads in the thread request queue; If there are, the calculation task is sent to the input port of the idle thread through the output port of the task queue, and the idle thread is used to execute the calculation task; otherwise, it is sorted in the order of the calculation tasks being submitted, forming a calculation task queue and waiting to be executed; When the thread finishes executing the calculation task, it interacts with the end port of the calculation task through its own end port to notify that the calculation task has been executed, and the calculation task can continue to execute subsequent operations; at the same time, the thread becomes idle, and sends a calculation task processing request to the task queue again through its own request port to query whether there are calculation tasks waiting to be executed in the calculation task queue; If there is one, take out the computing task at the head of the computing task queue and execute it; otherwise, continue to remain idle and wait for the main thread to submit a new computing task; When all computing tasks are completed, all threads in the thread pool become idle, waiting to execute computing tasks generated by particle filter sampling in the next round of micro-simulation.
4. The method according to claim 1, wherein The execution logic of the thread described by the atomic model of discrete event system specification is expressed as: ; Among them, represents a thread, represents the input of the thread; among them, represents the set of input ports of the thread, which only contains one input port ; the input port input represents the ID of the computing task assigned to this thread by the task queue; Represents the output of the thread; among them, Represents the set of output ports of the thread, including the end port and the request port ; The output of the end port Represents the ID of the computational task completed by the thread execution, and the output of the request port Represents the ID of the computational task completed by the thread execution, and the output of the request port Represents the ID of the thread; Represents the ID of the thread; Indicates the state of the thread; among them, in represents the ID of the computing task that the thread is currently executing, indicates the time remaining for the thread to complete the computing task; if , it means that the thread is currently in an idle state, and at this time, set ; Represents the internal state transition function of a thread, specifically defined as: ; Represents the external state transition function of the thread, and is specifically defined as: ; Among them, represents the time required for the thread to execute the computing task; it should be noted that only when the thread is in the state, that is, in the idle state, it is possible to receive the ID of the computing task output by the task queue; Represents the output function of the thread; when the thread finishes the computing task, on the one hand, it notifies that the computing task has been completed through the output port; on the other hand, it also sends a request to allocate a new computing task to the task queue through the output port; therefore, the output function of the thread is specifically defined as: ; Among them, refers to the ID of the thread itself; A time advancement function representing a thread, specifically defined as: 。 5. The method according to any one of claims 1 to 4, characterized in that The computing task is specifically defined as: a simulation running process when performing particle filter sampling in microscopic simulation, the simulation running process takes the particle state at the previous moment as the initial value, and after running the simulation model for a period of time, obtains the particle state at the next moment.
6. The method according to claim 5, wherein The simulation operation process is carried out under the constraints of a simulation experiment framework, which defines the entities involved in modeling and simulation activities and the relationships between entities, including simulation experiments, simulation models, simulators, and operation control conditions; wherein, the simulation experiment is carried out on a simulation model, and the execution of the simulation model requires a simulator; the simulation experiment needs to be carried out under given operation control conditions, and the operation control conditions include simulation start time, warm-up time, and operation duration; a simulation experiment needs to be run multiple times under the same operation control conditions, each run is called a sample, and each run needs to use a different random number seed.
7. The method according to claim 6, characterized in that, When performing particle filter sampling in micro-simulation, the computing task is further defined as a sample run in the simulation experiment and abstracted into a simulation run class; wherein the simulation run class contains five attributes, namely the simulation model, simulator, initial state, warm-up time and running time required for the sample run, wherein the simulation start time is implicit in the initial state; the simulation run class also contains a constructor and a run function, wherein the constructor is used to complete the initialization of the simulation according to the simulation model, simulator, initial state, warm-up time and running time; the run function is used to drive the simulation run according to the simulation model type and the simulation platform running mechanism.
8. A particle filter concurrent sampling device based on a thread pool, characterized in that, The device comprises: An initialization module, used to create a thread pool and a task queue by the main thread during the initialization phase; wherein the task queue includes a sorted and stored computing task queue and a thread request queue; The task scheduling module is used to create several computing tasks by the main thread after initialization is completed, and abstract the computing tasks, task queues and threads into a multi-server single-queue queuing system that adopts the formal description of the discrete event system specification. The multi-server single-queue queuing system dynamically schedules and allocates idle threads to perform computing tasks based on the status of the computing task queue and the thread request queue, so as to realize the concurrent execution of computing tasks; wherein the computing task is a particle filter sampling task in microscopic simulation; In a multi-server single-queue queuing system, the execution logic of the task queue described by the discrete event system specification atomic model is expressed as follows: ; Among them, represents the task queue, indicating the input of the task queue; among them, represents the set of input ports of the task queue, including the arrival port and the request port ; the input of the arrival port represents the ID of the computing task submitted by the main thread, and the input of the request port represents the ID of the thread that requests to allocate a computing task to the task queue; the input of represents the ID of the thread that requests to allocate a computing task to the task queue; Represents the output of the task queue; wherein, Represents the set of output ports of the task queue, including only one output port ; Output port Output of Represents the ID of the computational task to be executed by the thread; Indicates the status of the task queue; among them, the computing task queue and the thread request queue are both FIFO queues, storing the IDs of computing tasks that are queuing up waiting to be executed and the IDs of threads that are queuing up waiting to be assigned computing tasks respectively; Represents the internal state transition function of the task queue. The internal state transition function of the task queue describes how the state of the task queue changes under the control of only the time advancement function without external input, and is specifically defined as: ; Among them, "-1" means removing the first element from the queue; Represents the external state transition function of the task queue; among them, the set , the external state transition function of the task queue describes how the state of the task queue changes under the excitation of external inputs, and is specifically defined as: ; Among them, "+" means inserting to the end of the queue; The output function representing the task queue, which defines what information should be output when an internal state transition occurs in the task queue. The specific definition is as follows: ; Among them, in is the computing task queue The ID of the computing task at the head of the queue; it should be noted that the thread ID in the thread pool is equal to the thread ID at the head of the thread request queue The thread whose ID is equal to the thread ID at the head of the queue will be responsible for executing the computing task with the ID of . The time advancement function representing the task queue, which defines the duration for which the task queue remains in the state without being affected by external inputs, is specifically defined as: ; The above formula indicates that when both the computing task queue and the thread request queue are not empty, the time advancement value is set to 0, thereby immediately triggering the internal state transition function of the task queue, and allocating the computing task at the head of the computing task queue to the idle thread at the head of the thread request queue for execution; the above process is repeated until one of the queues becomes empty.
9. A computer device, comprising a memory and a processor, the memory storing a computer program, characterized in that, When the processor executes the computer program, it implements the steps of the method according to any one of claims 1 to 7.