Particle filtering concurrent sampling method and device based on thread pool and computer equipment

By adopting the thread pool-based concurrent sampling method of particle filtering based on thread pool in microscopic simulation, the problem of complex and low efficiency of particle filtering sampling process is solved, concurrent execution of computing tasks is realized, and simulation efficiency and real-time performance are improved.

CN120045342AActive Publication Date: 2025-05-27NAT UNIV OF DEFENSE TECH
View PDF 7 Cites 0 Cited by

Patent Information

Application Number
CN202510540463.5
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-04-27
Publication Date
2025-05-27
Estimated Expiration
2045-04-27

AI Technical Summary

Technical Problem

In microscopic simulation, the particle filtering sampling process is complex and asynchronous. The existing fallback method is difficult to ensure the logical sequence of calculation steps, and the serial execution efficiency is low, resource consumption is large, making it difficult to meet the real-time requirements of dynamic data-driven simulation.

Method used

The particle filtering concurrent sampling method based on thread pool is adopted. By creating thread pools and task queues, the computing tasks are abstracted into a multi-service desk single-queue queuing system, and dynamically dispatch and allocate idle threads to execute computing tasks to realize concurrent execution of computing tasks.

Benefits of technology

Ensure that each calculation step of particle filtering is performed in the correct logical order, which improves the execution efficiency of particle filtering sampling and the operation efficiency of microscopic simulation, reduces resource consumption and calculation amount, and meets the real-time requirements of dynamic data-driven simulation.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120045342A_ABST
    Figure CN120045342A_ABST
Patent Text Reader

Abstract

The invention relates to a particle filtering concurrent sampling method and device based on a thread pool and computer equipment. The method comprises the following steps: in an initialization stage, creating a thread pool and a task queue by a main thread; after initialization is completed, a plurality of calculation tasks are created by a main thread, the calculation tasks, task queues and threads are abstracted into a multi-service-desk single-queue queuing system which is described in a normative and formalized mode by adopting a discrete event system, and the multi-service-desk single-queue queuing system is based on the states of calculation task queues and thread request queues in the task queues. Idle threads are dynamically dispatched and allocated to execute the calculation tasks, and concurrent execution of the calculation tasks is achieved; wherein the calculation task is a particle filtering sampling task in microscopic simulation. According to the method, the execution efficiency of particle filtering sampling and the operation efficiency of microscopic simulation are improved through concurrent execution of calculation tasks, certain resource consumption and calculation amount are reduced, the real-time requirement of dynamic data driving simulation is guaranteed, and therefore better simulation performance is achieved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the technical field of simulation task scheduling, and in particular to a particle filter concurrent sampling method, device and computer equipment based on a thread pool. Background Art

[0002] Dynamic data-driven simulation is a simulation paradigm that "combines models and data". It continuously injects observations (data) of the real system into the simulation (model) and allows the data to dynamically correct the simulation (state, parameters) to improve the estimation and prediction capabilities based on simulation. Since dynamic data-driven simulation combines 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. It is precisely because of this advantage that 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 dynamic correction simulation" is achieved by data assimilation technology. Data assimilation is a method that combines the observation data of the real system with the simulation prediction to estimate the state of the real system. Commonly used data assimilation algorithms include variational assimilation (for example, 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, while the particle filter algorithm uses a set of Monte Carlo samples (particles) and corresponding weights to approximate the probability distribution, replacing the integral operation with the sample mean, so it has no restrictions on the model and error. Since the "simulation" in dynamic data-driven simulation generally refers to microscopic simulation, its state evolution process has highly nonlinear / non-Gaussian characteristics, therefore, 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 the prerequisite and basic support for dynamic data-driven simulation. However, the implementation of particle filter data assimilation in micro-simulation is not as simple and intuitive as in ordinary real vector state equations. In micro-simulation, the particle filter sampling process is a cyclic simulation operation process, which repeatedly runs the simulation model for a period of time with the simulation model state at the previous moment as the initial value to obtain the simulation model state at the next moment. The sampling process not only involves the simulation experiment operation, but 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 micro-simulation to ensure that each calculation step in the particle filter is executed in the correct logical order.

[0004] Existing methods use a fallback approach to implement the particle filter sampling step in micro-simulation. In the fallback-based sampling process, the fallback simulation requires operations such as model state saving and recovery, resetting the simulator's future event table, etc. These operations are closely related to specific applications and are prone to errors. In addition, the fallback-based sampling process is executed serially. For applications with high real-time requirements such as dynamic data-driven simulation, the operating efficiency and resource consumption of serial execution will become a bottleneck for simulation performance. Summary of the invention

[0005] Based on this, it is necessary to provide a thread pool-based particle filter concurrent sampling method, device and computer equipment to address the above technical problems. While ensuring that the various calculation steps of the particle filter in the micro-simulation are executed in the correct logical order, it can improve the execution efficiency of the particle filter sampling and the operation efficiency of the micro-simulation through the concurrent execution of calculation tasks, and reduce certain resource consumption and calculation amount, ensure the real-time requirements of dynamic data-driven simulation, and thus achieve better simulation performance.

[0006] A particle filtering concurrent sampling method based on a thread pool, the method comprising: In the initialization phase, the main thread creates a thread pool and a task queue; the task queue includes a sorted and stored computing task queue and a thread request queue; After initialization, the main thread creates several computing tasks and abstracts the computing tasks, task queues and threads into a multi-server single-queue queuing system formally described by the Discrete Event System Specification (DEVS). 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, thereby realizing concurrent execution of computing tasks; among them, the computing tasks are particle filter sampling tasks in microscopic simulation.

[0007] In one embodiment, computing tasks, task queues and threads are abstracted into a multi-server single-queue queuing system formally described using a discrete event system specification, including: The computing tasks, task queues and threads are abstracted into a multi-server single-queue queuing system. Each computing task acts as a customer in the system and receives computing services from each thread as a server. After the multi-server single-queue queuing system is formally described using the discrete event system specification, the computing tasks, task queues and threads in the multi-server single-queue queuing system are described based on the discrete event system specification atomic model, and each is coupled and exchanges information through input and output ports.

[0008] 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 to achieve concurrent execution of computing tasks, including: The task queue receives the computing task processing requests of each thread through its own request port, and sorts them in the order in which the requests are issued to form a thread request queue; at the same time, after receiving the computing tasks submitted by the main thread through its own arrival port, the task queue determines whether there are threads in the thread request queue that are idle; If yes, send the computing task to the input port of the idle thread through the output port of the task queue, and use the idle thread to execute the computing task; otherwise, sort the computing tasks in the order in which they were submitted to form a computing task queue and wait for execution; When the thread completes the computing task, it interacts with the computing task's end port through its own end port to notify the computing task that it has been completed and that the computing task can continue to perform subsequent operations; at the same time, the thread becomes idle and resends a computing task processing request to the task queue through its own request port to query whether there are computing tasks waiting to be executed in the computing 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.

[0009] 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: ; in, Represents a task queue, Represents the input of the task queue; where, Represents the input port set of the task queue, including the arrival port and request port ; 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 the task queue to allocate computing tasks; Represents the output of the task queue; where, Represents the output port set of the task queue, which contains only one output port ; Output port Output Indicates the ID of the computational task that the thread will perform; Indicates the status of the task queue; among them, the calculation task queue and thread request queue Both are FIFO queues, storing the IDs of computing tasks waiting to be executed and the IDs of threads waiting to be assigned computing tasks. Represents the internal state transfer function of the task queue. The internal state transfer function of the task queue describes the task queue in the absence of external input, only in the time advancement function How the state changes under the control of 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; where the set ,The external state transfer function of the task queue describes how the state of the task queue changes under the stimulation of external input, and is specifically defined as: ; Among them, "+" means inserting to the end of the queue; Represents the output function of the task queue, which defines what information should be output when the task queue undergoes an internal state transition. The specific definition is: ; in, In It is a 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 computational tasks; Represents the time advancement function of the task queue, which defines the state that the task queue remains in without external input influence The duration of 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 transfer function of the task queue, and assigning 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.

[0010] In one embodiment, the execution logic of the thread described based on the atomic model of the discrete event system specification is expressed as: ; in, Represents a thread, Represents the input of the thread; where, Represents the input port set of the thread, which contains only one input port ; Input port Input Indicates the ID of the computing task assigned to this thread by the task queue; Represents the output of a thread; where Represents the thread's output port set, including the end port and request port ; End port Output Indicates the ID of the computing task that the thread has completed, request port Output Indicates the thread ID; Indicates the state of the thread; among them, In Represents the ID of the computational task currently being executed by the thread. Indicates the time required for the thread to complete the calculation task; if , it means that the thread is currently in an idle state. ; Represents the internal state transfer function of the thread, which is specifically defined as: ; Represents the external state transfer function of the thread, which is specifically defined as: ; in, Indicates the time required for the thread to perform the computing task; it should be noted that only when the thread is Only when the task queue is in idle state can the ID of the computing task output by the task queue be received; Represents the output function of the thread; when the thread completes the computing task, on the one hand, The output port notifies that the computing task has been completed; on the other hand, The output port sends a request to the task queue to allocate a new computing task; therefore, the output function of the thread The specific definition is: ; in, Refers to the ID of the thread itself; Represents the time advancement function of the thread, which is specifically defined as: .

[0011] In one of the embodiments, the computing task is specifically defined as: a simulation run process when performing particle filter sampling in a microscopic simulation, the simulation run 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.

[0012] In one of the embodiments, 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 the entities, including simulation experiments, simulation models, simulators and operation control conditions; wherein 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 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.

[0013] In one of the embodiments, when particle filter sampling is performed in a 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 includes 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 includes 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.

[0014] A particle filtering concurrent sampling device based on a thread pool, the device comprising: The initialization module is 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 is formally described using the discrete event system specification. 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, thereby realizing concurrent execution of computing tasks; wherein the computing tasks are particle filter sampling tasks in microscopic simulation.

[0015] A computer device comprises a memory and a processor, wherein the memory stores a computer program, and when the processor executes the computer program, the following steps are implemented: In the initialization phase, the main thread creates a thread pool and a task queue; the task queue includes a sorted and stored computing task queue and a thread request queue; After initialization, the main thread creates several computing tasks and abstracts the computing tasks, task queues and threads into a multi-server single-queue queuing system that is formally described using a discrete event system specification. 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, thereby realizing concurrent execution of computing tasks; among them, the computing tasks are particle filter sampling tasks in microscopic simulation.

[0016] The above-mentioned particle filter concurrent sampling method, device and computer equipment based on thread pool have the following beneficial effects: 1. The thread pool maintains, manages and schedules the threads. Since the execution of each computing task is independent and does not interfere with each other, an idle thread is assigned to each computing task. The thread executes the computing task, and multiple threads can execute computing tasks concurrently, thereby realizing concurrent sampling of particle filters in micro-simulation, ensuring that the various computing steps of particle filters in micro-simulation are executed in the correct logical order, and improving the execution efficiency of particle filter sampling and the operation efficiency of micro-simulation through the concurrent execution of computing tasks.

[0017] 2. After completing the computing task, the threads in the thread pool will not be destroyed, but will become idle and wait for the next computing task. By reusing the already created threads, the thread pool can reduce the operating system resource overhead and computing workload caused by frequent creation and destruction of threads, ensuring the real-time requirements of dynamic data-driven simulation, thereby achieving better simulation performance. BRIEF DESCRIPTION OF THE DRAWINGS

[0018] Figure 1 It is a flowchart of a particle filtering concurrent sampling method based on a thread pool in one embodiment; Figure 2A schematic diagram of a multi-server single-queue queuing system formally described using a discrete event system specification in one embodiment; Figure 3 Schematic diagram of the internal structure of a computer device in one embodiment. DETAILED DESCRIPTION

[0019] In order to make the purpose, technical solution and advantages of the present application more clearly understood, the present application is 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 application and are not used to limit the present application.

[0020] In one embodiment, Figure 1 As shown, a particle filtering concurrent sampling method based on a thread pool is provided, comprising the following steps: Step S1, in the initialization phase, the main thread creates a thread pool and a task queue; wherein the task queue includes a sorted and stored computing task queue and a thread request queue.

[0021] Step S2, after the 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 that is formally described using a discrete event system specification. 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, thereby realizing concurrent execution of computing tasks; wherein the computing tasks are particle filter sampling tasks in microscopic simulations.

[0022] The computing tasks, task queues and threads are abstracted into a multi-server single-queue queuing system formally described by discrete event system specifications, including: The computing tasks, task queues and threads are abstracted into a multi-service station single-queue queuing system. Each computing task acts as a customer in the system and accepts computing services from each thread as a service station. After the multi-service station single-queue queuing system is formally described using the discrete event system specification, the computing tasks, task queues and threads in the multi-service station single-queue queuing system are described based on the discrete event system specification atomic model, and each is coupled through input and output ports to exchange information.

[0023] The structure of a multi-server single-queue queuing system described by the discrete event system specification is as follows: Figure 2 As shown, the 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. The specific steps for implementing concurrent execution of computing tasks include: The task queue receives the computing task processing requests of each thread through its own request port, and sorts them in the order in which the requests are issued to form a thread request queue; at the same time, after receiving the computing tasks submitted by the main thread through its own arrival port, the task queue determines whether there are threads in the thread request queue that are idle; If yes, send the computing task to the input port of the idle thread through the output port of the task queue, and use the idle thread to execute the computing task; otherwise, sort the computing tasks in the order in which they were submitted to form a computing task queue and wait for execution; When the thread completes the computing task, it interacts with the computing task's end port through its own end port to notify that the computing task has been completed and the computing task can continue to perform subsequent operations (for example, obtaining the simulation model status and obtaining predicted observation data). At the same time, the thread turns to the idle state and resends the computing task processing request to the task queue through its own request port to query whether there are computing tasks waiting to be executed in the computing 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.

[0024] The above steps allocate idle threads to concurrently execute computing tasks according to the thread pool and task queue scheduling, so as to realize concurrent sampling of particle filters in micro-simulation, ensure that each computing step of particle filters in micro-simulation is executed in the correct logical order, and improve the execution efficiency of particle filter sampling and the operation efficiency of micro-simulation through concurrent execution of computing tasks. Moreover, the threads in the thread pool will not be destroyed after executing the computing tasks, but will be turned into an idle state to wait for the execution of the next computing task. The thread pool can reduce the operating system resource overhead and computing amount caused by frequent creation and destruction of threads by reusing the threads that have been created, and ensure the real-time requirements of dynamic data-driven simulation, so as to achieve better simulation performance.

[0025] Specifically, the execution logic of the task queue described by the discrete event system specification atomic model is expressed as: ; in, Represents a task queue, Represents the input of the task queue; where, Represents the input port set of the task queue, including the arrival port and request port ; 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 the task queue to allocate computing tasks; Represents the output of the task queue; where, Represents the output port set of the task queue, which contains only one output port ; Output port Output Indicates the ID of the computational task that the thread will perform; Indicates the status of the task queue; among them, the calculation task queue and thread request queue Both are FIFO queues, storing the IDs of computing tasks waiting to be executed and the IDs of threads waiting to be assigned computing tasks. Represents the internal state transfer function of the task queue. The internal state transfer function of the task queue describes the task queue in the absence of external input, only in the time advancement function How the state changes under the control of 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; where the set ,The external state transfer function of the task queue describes how the state of the task queue changes under the stimulation of external input, and is specifically defined as: ; Among them, "+" means inserting to the end of the queue; Represents the output function of the task queue, which defines what information should be output when the task queue undergoes an internal state transition. The specific definition is: ; in, In It is a 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 computational tasks; Represents the time advancement function of the task queue, which defines the state that the task queue remains in without external input influence The duration of 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 transfer function of the task queue, and assigning 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 (continuously assigning computing tasks to idle threads) until one of the queues is empty (there are no idle threads or no queued computing tasks).

[0026] Specifically, the execution logic of the thread described based on the atomic model of the discrete event system specification is expressed as: ; in, Represents a thread, Represents the input of the thread; where, Represents the input port set of a thread, which contains only one input port ; Input port Input Indicates the ID of the computing task assigned to this thread by the task queue; Represents the output of a thread; where Represents the thread's output port set, including the end port and request port ; End port Output Indicates the ID of the computing task that the thread has completed, request port Output Indicates the thread ID; Indicates the state of the thread; among them, In Represents the ID of the computational task currently being executed by the thread. Indicates the time required for the thread to complete the calculation task; if , it means that the thread is currently in an idle state. ; Represents the internal state transfer function of the thread, which is specifically defined as: ; Represents the external state transfer function of the thread, which is specifically defined as: ; in, Indicates the time required for the thread to perform the computing task; it should be noted that only when the thread is Only when the task queue is in idle state can the ID of the computing task output by the task queue be received; Represents the output function of the thread; when the thread completes the computing task, on the one hand, The output port notifies that the computing task has been completed; on the other hand, The output port sends a request to the task queue to allocate a new computing task; therefore, the output function of the thread The specific definition is: ; in, Refers to the ID of the thread itself; Represents the time advancement function of the thread, which is specifically defined as: .

[0027] Furthermore, the above-mentioned computing task is specifically defined as: a simulation operation process when performing particle filter sampling in microscopic simulation, the simulation operation process takes 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.

[0028] Moreover, the simulation running process is carried out under the constraints of the simulation experiment framework, which defines the entities involved in the modeling and simulation activities and the relationships between the entities, including simulation experiments (Experiment), simulation models (SimulationModel), simulators (Simulator) and run control conditions (RunControl); wherein, 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 the simulation start time (startTime), warm-up time (warmupTime) and run length (runLength); a simulation experiment needs to be run multiple times under the same run control conditions, each run is called a sample (Replication), and each run needs to use a different random number seed (seed).

[0029] Therefore, 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 (SimulationRun) class; the simulation run class contains five attributes, namely the simulation model, simulator, initial state (initialState), warm-up time and running time required for the sample run, where the simulation start time is implicit in the initial state; the simulation run 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 running time; 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 out the first event in the simulator's future event table and execute the event processing function until the future event table is empty or the preset running time is reached.

[0030] After the calculation task is completed, it is also necessary to obtain the simulation model state and the predicted observation data (that is, to realize 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 a given state (setInitialModelState), and obtain the state of the simulation model (getModelState), as well as the predicted observation data (getPredictedMeasurement).

[0031] Furthermore, the above-mentioned particle filter concurrent sampling method based on thread pool can be implemented based on Java concurrent programming. Java Development Kit (JDK) is a software development environment for developing and testing Java programs. The Java Development Kit has supported concurrent programming since its design, 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 class in the java.util.concurrent package for concurrent programming. Executor provides an intermediate layer between the user end and task execution: the user end does not execute tasks directly, but executes tasks through intermediate objects. Executor allows developers to manage the execution of asynchronous tasks without explicitly managing the life cycle of threads. Developers can create different types of thread pools (for example, fixed-size thread pools (FixedThreadPool) and cached thread pools (CachedThreadPool)) by calling the factory method of the Executors class in the java.util.concurrent package. When the factory method is called, an ExecutorService object (an Executor with a life cycle) is created, through which users submit, execute, and manage tasks.

[0032] Users can define tasks by implementing the Runnable interface or the Callable interface in the java.util.concurrent package: Runnable tasks do not return values ​​after execution, while Callable tasks can return values ​​after execution. The Callable interface is a generic interface whose type parameter represents the return value type after calling the call method of the Callable interface, and the Callable task must be submitted through the submit method of the ExecutorService interface. After calling the submit method, a Future object is generated 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 the get method of the Future object is called, the method will block until the task is completed and the result is generated.

[0033] In one embodiment, a particle filtering concurrent sampling device based on a thread pool is provided, comprising: The initialization module is 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 is formally described using the discrete event system specification. 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, thereby realizing concurrent execution of computing tasks; wherein the computing tasks are particle filter sampling tasks in microscopic simulation.

[0034] For the specific definition of the particle filter concurrent sampling device based on thread pool, please refer to the definition of the particle filter concurrent sampling method based on thread pool in the above text, which will not be repeated here. Each module in the above-mentioned particle filter concurrent sampling device based on thread pool can be implemented in whole or in part by software, hardware and a combination thereof. The above-mentioned modules can be embedded in or independent of the processor in the computer device in the form of hardware, or can be stored in the memory in the computer device in the form of software, so that the processor can call and execute the operations corresponding to the above modules.

[0035] In one embodiment, a computer device is provided. The computer device may be a server, and its internal structure diagram may be as follows: Figure 3 As 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, a particle filtering concurrent sampling method based on a thread pool is implemented.

[0036] Those skilled in the art will understand that Figure 3 The structure shown in the figure is only a block diagram of a part of the structure 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 certain components, or have a different arrangement of components.

[0037] In one embodiment, a computer device is provided, including a memory and a processor, wherein the memory stores a computer program, and when the processor executes the computer program, the following steps are implemented: In the initialization phase, the main thread creates a thread pool and a task queue; the task queue includes a sorted and stored computing task queue and a thread request queue; After initialization, the main thread creates several computing tasks and abstracts the computing tasks, task queues and threads into a multi-server single-queue queuing system that is formally described using a discrete event system specification. 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, thereby realizing concurrent execution of computing tasks; among them, the computing tasks are particle filter sampling tasks in microscopic simulation.

[0038] The technical features of the above embodiments may be combined arbitrarily. To make the description concise, 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, they should be considered to be within the scope of this specification.

[0039] The above-described embodiments only express several implementation methods of the present application, and the descriptions thereof are relatively specific and detailed, but they cannot be understood as limiting the scope of the present application. It should be pointed out that, for a person of ordinary skill in the art, several variations and improvements can be made without departing from the concept of the present application, and these all belong to the protection scope of the present application. Therefore, the protection scope of the present application shall be subject to the attached claims.

Claims

1. A particle filter concurrent sampling method based on thread pool, characterized in that: The method comprises: In the initialization phase, the main thread creates a thread pool and a task queue; wherein the task queue includes a sorted and stored computing task queue and a thread request queue; 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 that is formally described using a discrete event system specification. 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, thereby realizing concurrent execution of computing tasks; wherein the computing task is a particle filter sampling task in a microscopic simulation.

2. The method according to claim 1, characterized in that The computing tasks, task queues and threads are abstracted into a multi-server single-queue queuing system formally described by discrete event system specifications, including: The computing tasks, task queues and threads are abstracted into a multi-server single-queue queuing system. Each computing task acts as a customer in the system and receives computing services from each thread as a server. After the multi-server single-queue queuing system is formally described using the discrete event system specification, the computing tasks, task queues and threads in the multi-server single-queue queuing system are described based on the discrete event system specification atomic model, and each is coupled and exchanges information through input and output ports.

3. The method according to claim 2, characterized in that The multi-server single queue queuing system dynamically schedules and allocates idle threads to perform computing tasks based on the status of computing task queues and thread request queues, realizing concurrent execution of computing tasks, including: The task queue receives computing task processing requests of each thread through its own request port, and sorts the requests in the order in which they are issued to form a thread request queue; at the same time, after receiving the computing tasks submitted by the main thread through its own arrival port, the task queue determines whether there is an idle thread in the thread request queue; If yes, send the computing task to the input port of the idle thread through the output port of the task queue, and use the idle thread to execute the computing task; otherwise, sort the computing tasks in the order in which they were submitted to form a computing task queue and wait for execution; When the thread completes the computing task, it interacts with the computing task's end port through its own end port to notify the computing task that it has been completed and that the computing task can continue to perform subsequent operations; at the same time, the thread becomes idle and resends a computing task processing request to the task queue through its own request port to query whether there are computing tasks waiting to be executed in the computing 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 3, characterized in that The execution logic of the task queue described by the atomic model of discrete event system specification is expressed as: ; in, Represents a task queue, Represents the input of the task queue; where, Represents the input port set of the task queue, including the arrival port and request port ; 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 the task queue to allocate computing tasks; Represents the output of the task queue; where, Represents the output port set of the task queue, which contains only one output port ; Output port Output Indicates the ID of the computational task that the thread will perform; Indicates the status of the task queue; among them, the calculation task queue and thread request queue Both are FIFO queues, storing the IDs of computing tasks waiting to be executed and the IDs of threads waiting to be assigned computing tasks. Represents the internal state transfer function of the task queue. The internal state transfer function of the task queue describes the task queue in the absence of external input, only in the time advancement function How the state changes under the control of 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; where the set ,The external state transfer function of the task queue describes how the state of the task queue changes under the stimulation of external input, and is specifically defined as: ; Among them, "+" means inserting to the end of the queue; Represents the output function of the task queue, which defines what information should be output when the task queue undergoes an internal state transition. The specific definition is: ; in, In It is a 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 computational tasks; Represents the time advancement function of the task queue, which defines the state that the task queue remains in without external input influence The duration of 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 transfer function of the task queue, and assigning 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.

5. The method according to claim 4, characterized in that The execution logic of the thread described by the atomic model of discrete event system specification is expressed as: ; in, Represents a thread, Represents the input of the thread; where, Represents the input port set of the thread, which contains only one input port ; Input port Input Indicates the ID of the computing task assigned to this thread by the task queue; Represents the output of a thread; where Represents the thread's output port set, including the end port and request port ; End port Output Indicates the ID of the computing task that the thread has completed, request port Output Indicates the thread ID; Indicates the state of the thread; among them, In Represents the ID of the computational task currently being executed by the thread. Indicates the time required for the thread to complete the calculation task; if , it means that the thread is currently in an idle state. ; Represents the internal state transfer function of the thread, which is specifically defined as: ; Represents the external state transfer function of the thread, which is specifically defined as: ; in, Indicates the time required for the thread to perform the computing task; it should be noted that only when the thread is Only when the task queue is in idle state can the ID of the computing task output by the task queue be received; Represents the output function of the thread; when the thread completes the computing task, on the one hand, The output port notifies that the computing task has been completed; on the other hand, The output port sends a request to the task queue to allocate a new computing task; therefore, the output function of the thread The specific definition is: ; in, Refers to the ID of the thread itself; Represents the time advancement function of the thread, which is specifically defined as: 。 6. The method according to any one of claims 1 to 5, 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.

7. The method according to claim 6, characterized in that 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.

8. The method according to claim 7, 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.

9. A particle filter concurrent sampling device based on 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 is formally described using the discrete event system specification. 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, thereby realizing concurrent execution of computing tasks; wherein the computing task is a particle filter sampling task in microscopic simulation.

10. A computer device comprising a memory and a processor, wherein the memory stores a computer program, characterized in that: When the processor executes the computer program, the steps of the method according to any one of claims 1 to 8 are implemented.

Citation Information

Patent Citations

  • Multi-thread finite state machine switching method and multi-thread finite state machine switching device based on thread pool

    CN103218264A

  • Method and device for predicting confidence intervals of waiting and response duration for G / G / m queuing system

    CN113610322A

  • Multi-thread time synchronization event scheduling system based on thread pool and Avl tree

    CN116414581A

  • Discrete event simulation data assimilation method, device and equipment based on particle filtering

    CN118313226A

  • Discrete event system simulation interface

    US20080126054A1