A task control method and device based on state machine
By adopting the state machine-based task control method in the simulation and training system, the problems of slow task status update and high logical scheduling complexity are solved, the task execution efficiency and system reliability are improved, and the automatic management and real-time management of the task status are realized. response.
Patent Information
- Application Number
- CN202410822511.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-06-25
- Publication Date
- 2024-09-27
- Estimated Expiration
- 2044-06-25
AI Technical Summary
Traditional task status management methods in complex simulation and training systems result in slow task status updates and high logical scheduling complexity, which affects the task execution efficiency of the simulation system.
Adopting a state machine-based task control method, by abstracting the business process into task node data, defining the temporal logical relationship between task data, creating a task state machine, and using the state transition function and task execution sequence control function to manage the task state, the implementation Automated management of task status and real-time response.
It improves the efficiency of task execution, ensures that tasks are executed in the correct order and conditions, enhances the reliability, maintainability and scalability of the system, reduces manual intervention, and achieves flexible management of task status and real-time response.
Smart Images

Figure CN118377604B
Abstract
Description
Technical Field
[0001] The present application relates to the field of task control technology, and in particular to a task control method and device based on a state machine. Background Art
[0002] In the simulation and training system, the training and exercise mission planning environment is an indispensable component. This environment needs to support users in distributed training and exercise mission planning, form a hierarchical task structure by building the subordinate relationship of tasks, and form a smooth task execution business flow by setting the timing relationship between tasks. In complex simulation and training business activities, the tasks in the business flow are often mutually constrained and interdependent, forming a tight task network.
[0003] However, as the number of tasks in the business flow continues to increase, the traditional task status management method gradually exposes its limitations. Due to design limitations, the update speed of task status often becomes slow, and the complexity of logical scheduling also increases. This not only affects the execution efficiency of tasks in the simulation system, but may also have a negative impact on the training effect.
[0004] In simulation and training systems, how to effectively manage and control task status has become an urgent problem to be solved. Summary of the invention
[0005] In an embodiment of the present application, a state machine-based task control method is provided to solve the problem that the task status update is slow due to design limitations, the logic scheduling complexity is high, and thus the execution efficiency of tasks in the simulation system is limited.
[0006] In the first aspect, an embodiment of the present application provides a task control method based on a state machine, the method comprising: abstracting business process steps into instantiated task node data according to a simulation and training business process diagram, and planning task data and defining task participant objects; defining the temporal logic relationship between task data, creating a timing representation diagram to represent the temporal logic relationship of task execution, and abstracting it into a task execution sequence mapping table; defining a task state machine based on the task data, abstracting and managing the state transition logic inside the task state machine through a state transition diagram and a task state transition mapping table; creating and defining the state transition logic and task control logic of the task state machine; wherein the state transition logic is defined by a state transition function, and the task control logic is defined by a task execution sequence control function; using the state transition function and the task execution sequence control function to jointly manage the execution process of a new task state machine instance; continuously monitoring changes in task status through a task status listener, and triggering corresponding processing logic.
[0007] In a possible implementation, before abstracting the business process steps into instantiated task node data according to the simulation training business process diagram, it includes: planning simulation training task scenario elements according to the simulation training requirements, and formulating a simulation training business process diagram; wherein the simulation training task scenario elements include: training scenario weather and time, equipment elements, and load elements.
[0008] In a possible implementation, the business process steps are abstracted into instantiated task node data according to the simulation and training business process diagram, and the task data is planned and the task participants are defined, including: defining the task data according to the simulation and training business process diagram, setting the task start time, task end time and task type, thereby abstracting the business process steps into instantiated task node data; the planning of task data includes: planning the task execution process, planning the equipment action route and setting the task execution script.
[0009] In a possible implementation, the definition of the temporal logical relationship between task data includes: selecting one or more tasks as source tasks of the temporal relationship; selecting other tasks as target tasks of the temporal relationship; defining the temporal logical relationship between the task data according to the dependency relationship between the source tasks and the target tasks; the temporal logical relationship includes a parallel start relationship, a pre-start and post-end relationship, a post-start relationship and a synchronous end relationship; the parallel start relationship means that when the source task starts, the target task must also start; the pre-start and post-end relationship means that when the source task starts, the target task must immediately end; the post-start relationship means that when the source task ends, the target task must start; the synchronous end relationship means that when the source task ends, the target task must also end at a certain time point.
[0010] In one possible implementation, the creation of a timing representation diagram represents the timing logical relationship of task execution, and abstracts it into a task execution sequence mapping table, including: representing the task execution sequence mapping table in the form of a two-dimensional array, each row of the two-dimensional array describes a timing logical relationship, including a source task, a timing relationship type, and a target task.
[0011] In a possible implementation, the task state machine is defined based on task data, and the state transition logic inside the task state machine is abstracted and managed through a state transition diagram and a task state transition mapping table, including: defining the task states contained in the task state machine; the task states include not having a start condition, not started, in progress, ended, and terminated; setting functions for the task state machine to enter and leave a state node, and determining a legal transition path between each state; defining a state transition function, which describes how the task state machine transitions to the next state when a transition trigger condition is met in different states; defining a specific state to which the task state machine will transfer when the transition trigger condition is met; using a state transition diagram to describe the state transition process of the task state machine; wherein each node in the state transition diagram represents a state; adding arrows in the state transition diagram to indicate transitions between states, and marking the transition trigger conditions and possible outputs on the arrows; abstracting the information in the state transition diagram into a task state transition mapping table; the state transition mapping table is represented in the form of an array, and each array element contains three fields, namely, the current state, the trigger action, and the next state.
[0012] In one possible implementation, the state transition function includes an event trigger and a state transition method; when the event trigger detects that an event satisfies the state transition condition, the state transition method is called; the state transition method includes: obtaining the next state information corresponding to the current state from the task state transition mapping table; executing the execution action of the current state node and recording the execution result; if the execution result satisfies the state transition condition, start traversing the task state transition mapping table to find the information of the next state; after finding the next state, update the current state variable to the next state, and destroy the resources related to the previous state in the memory; when all states in the task state transition mapping table are processed, it means that the execution of this task is completed.
[0013] In a possible implementation, the task execution sequence control function includes a state control function constructor and a task state listener; the task state listener is used to continuously monitor changes in task states and trigger corresponding processing logic when the state changes; when the task state listener monitors the state change, the state control function constructor starts working; the working steps of the state control function constructor are: obtaining a task execution sequence mapping table, which defines the logic of task execution sequence and state transition; traversing the task execution sequence mapping table, and searching for a task execution sequence that meets the conditions according to the current state; wherein, the task execution sequence that meets the conditions is a task execution sequence that matches the current state; if a task execution sequence that meets the conditions is found, a new task state machine instance is constructed and started.
[0014] In the second aspect, an embodiment of the present application provides a task control device based on a state machine, which includes: a planning module, which is used to abstract business process steps into instantiated task node data according to a simulation and training business process diagram, and to plan task data and define task participating objects; a creation module, which is used to define the temporal logical relationship between task data, create a timing representation diagram to represent the temporal logical relationship of task execution, and abstract it into a task execution sequence mapping table; a management module, which is used to define a task state machine based on the task data, and abstract and manage the state transition logic inside the task state machine through a state transition diagram and a task state transition mapping table; a logic definition module, which is used to create and define the state transition logic and task control logic of the task state machine; wherein the state transition logic is defined by a state transition function, and the task control logic is defined by a task execution sequence control function; a joint management module, which is used to use the state transition function and the task execution sequence control function to jointly manage the execution process of a new task state machine instance; a trigger module, which is used to continuously monitor changes in task status through a task status listener, and trigger corresponding processing logic.
[0015] One or more technical solutions provided in the embodiments of the present application have at least the following technical effects:
[0016] The embodiment of the present application provides a task control method based on a state machine. By abstracting the simulation training business process diagram into instantiated task node data, the standardization and instantiation of the business process are realized, so that complex business processes can be clearly represented and managed, and the maintainability and reusability of the business process are improved. Planning task data and defining task participants so that each task node has clear data support and participating objects helps to ensure the accuracy and consistency of task execution, and facilitates coordination and cooperation between tasks. By defining the temporal logical relationship between task data and creating a temporal representation diagram, the temporal logical relationship of task execution can be clearly expressed, so that the dependencies and triggering conditions between tasks are clear at a glance, which helps to ensure that tasks are executed in the correct order and conditions. Based on the task data, the task state machine is defined, and the state transition logic inside the task state machine is abstracted and managed through the state transition diagram and the task state transition mapping table. This method makes the management of the task state machine more flexible and efficient, and can be customized and expanded according to actual needs. By creating and defining the state transition logic and task control logic of the task state machine, the automation of state transition and task control is realized. The state transition function and the task execution sequence control function jointly manage the execution process of the new task state machine instance, reducing the need for manual intervention and improving the automation level of the system. By continuously monitoring the changes in the task state through the task state listener and triggering the corresponding processing logic, real-time response to the task state changes can be achieved. This real-time response mechanism helps to discover and handle problems in a timely manner to ensure the smooth execution of tasks. In summary, the above-mentioned state machine-based task control method can achieve technical effects such as standardization of business processes in simulation and training systems, precise planning of task data, clear expression of temporal logical relationships, flexible management of task state machines, automation of state transition and task control, and real-time response to task state changes, thereby improving the reliability, maintainability and scalability of the system. It solves the problem that the task state update is slow due to design limitations, the logic scheduling complexity is high, and thus the execution efficiency of tasks in the simulation system is limited. BRIEF DESCRIPTION OF THE DRAWINGS
[0017] In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the drawings required for use in the embodiments of the present application or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative work.
[0018] Figure 1 A flowchart of a state machine-based task control method provided in an embodiment of the present application;
[0019] Figure 2A specific flow chart for defining the temporal logic relationship between task data provided in the embodiment of the present application;
[0020] Figure 3 A specific flow chart of defining a task state machine based on task data provided in an embodiment of the present application, abstracting and managing the state transition logic inside the task state machine through a state transition diagram and a task state transition mapping table;
[0021] Figure 4 A specific flow chart of the state conversion method provided in the embodiment of the present application;
[0022] Figure 5 A specific flow chart of the working steps of the state control function constructor provided in the embodiment of the present application;
[0023] Figure 6 A timing logic diagram provided for an embodiment of the present application;
[0024] Figure 7 A schematic diagram of state transition provided for an embodiment of the present application;
[0025] Figure 8 A schematic diagram of a state machine-based task control device provided in an embodiment of the present application;
[0026] Fig. 9 A schematic diagram of a state machine-based task control server provided in an embodiment of the present application. DETAILED DESCRIPTION
[0027] The technical solutions in the embodiments of the present application will be described clearly and completely below in conjunction with the drawings in the embodiments of the present application. Obviously, the described embodiments are part of the embodiments of the present application, rather than all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of this application.
[0028] The following describes some of the techniques involved in the embodiments of the present application to facilitate understanding, and they should be considered as merely exemplary. Therefore, it should be appreciated by those of ordinary skill in the art that various changes and modifications may be made to the embodiments described herein without departing from the scope and spirit of the present application. Similarly, for the sake of clarity and conciseness, some descriptions of well-known functions and structures are omitted in the following description.
[0029] The present application embodiment provides a task control method based on a state machine, such as Figure 1 As shown, the method includes steps S101 to S106. Among them, Figure 1This is only an execution order shown in the embodiment of the present application, and does not represent the only execution order of a task control method based on a state machine. Figure 1 The steps shown may be performed in parallel or reversed.
[0030] S101: Abstracting the business process steps into instantiated task node data according to the simulation training business process diagram, planning the task data and defining the task participants.
[0031] Specifically, the business process steps are abstracted into instantiated task node data according to the simulation training business process diagram, and the task data is planned and the task participants are defined, including: defining the task data according to the simulation training business process diagram, setting the task start time, task end time and task type, so as to abstract the business process steps into instantiated task node data. Planning task data includes: planning the task execution process, planning the equipment action route and setting the task execution script.
[0032] Furthermore, according to the simulation training business process diagram, each step in the business process is abstracted and converted into instantiated task node data. The core of this process is to define the task data according to the business process diagram, including setting the start time, end time and task type of the task, so as to map each step of the business process to a specific task node to form instantiated task node data. Next, the task data is planned. The planning process includes detailed planning of the execution process of the task, which involves possible events during the task execution, the action route of the equipment, etc. For example, according to the task requirements, the action route of the equipment is planned to ensure that the equipment can complete the task according to the predetermined path and time. At the same time, it is also necessary to set up the task execution script to guide the specific operations and decisions during the task execution process. Finally, the task participants are defined. According to the specific requirements of the task, determine which objects will participate in the task. These objects may include various types of equipment, personnel, etc. By defining the task participants, the roles and responsibilities of each object in the task can be clarified, providing a clear personnel and equipment configuration plan for task execution.
[0033] Specifically, before abstracting the business process steps into instantiated task node data according to the simulation training business process diagram, it includes: planning simulation training task scenario elements according to the simulation training requirements, and formulating the simulation training business process diagram. Among them, the simulation training task scenario elements include: training scenario weather and time, equipment elements and load elements.
[0034] First, according to the specific requirements of the simulation training, it is necessary to plan the appropriate weather conditions for the training scene, such as rainy days, sunny days, cloudy days, etc., and set the corresponding training scene time, such as early morning, noon, evening, night, etc. These weather and time settings will directly affect the authenticity and complexity of the simulation training. Next, it is necessary to plan the various equipment elements that will be used in the training scene. These equipment elements include manned aircraft, unmanned aircraft, early warning aircraft, ground missile vehicles, load vehicles, tanks, etc. Each type of equipment has its specific functions and performance parameters, which need to be defined and configured in detail during the planning stage. In addition to the equipment elements, it is also necessary to plan the load elements in the training scene. These load elements may include detection radars, optoelectronic pods, air-to-ground missiles, air-to-air missiles, ground-to-ground missiles, and ground-to-air missiles. The selection and configuration of the load will directly affect the actual combat effectiveness of the equipment. After completing the planning of the above scene elements, it is necessary to integrate these elements to create a business process diagram for the simulation training task. This flowchart will define each step of the business process in detail, including the expected execution process and the expected execution results. This will provide important guidance and basis for the subsequent abstraction of business process steps into instantiated task node data.
[0035] S102: Define the temporal logic relationship between task data, create a temporal representation diagram to represent the temporal logic relationship of task execution, and abstract it into a task execution sequence mapping table.
[0036] Figure 2 A specific flow chart of the temporal logical relationship between the definition task data provided in the embodiment of the present application, such as Figure 2 As shown, it includes steps S201 to S203.
[0037] S201: Select one or more tasks as source tasks of a timing relationship.
[0038] Specifically, source objects (Source) are usually key tasks in a business process, and their execution status will affect the start or end of other tasks.
[0039] S202: Select other tasks as target tasks of the temporal relationship.
[0040] Specifically, target objects are tasks that depend on the execution status of source objects, and their start or end time will be affected by the source objects.
[0041] S203: According to the dependency relationship between the source task and the target task, define the temporal logic relationship between the task data.
[0042] Specifically, the sequential logic relationship includes a parallel start relationship (start-start), a pre-start and post-end relationship (start-end), a post-start relationship (end-start), and a synchronous end relationship (end-end). Among them, start-start can be abbreviated as SS, start-end can be abbreviated as SF, end-start can be abbreviated as FS, and end-end can be abbreviated as FF.
[0043] Furthermore, dependency refers to the interaction and mutual influence between different tasks in a system. It is used to indicate how the execution status of one task (source task) affects the execution of another task (target task).
[0044] Specifically, the parallel start relationship (SS) means that when the source task starts, the target task must also start. It means that the two tasks have a time dependency relationship of synchronous start. The predecessor start and the end relationship (SF) means that when the source task starts, the target task must end immediately. It means that the start of the source task has a restrictive effect on the end of the target task. The post-start relationship (FS) means that when the source task ends, the target task must start. It means that after one task is completed, the other task can start. The synchronous end relationship (FF) means that when the source task ends, the target task must also end at a certain time point. It means that the two tasks have a time dependency relationship of synchronous end.
[0045] Specifically, a timing representation diagram is created to represent the timing logic relationship of task execution, and it is abstracted into a task execution sequence mapping table, including: representing the task execution sequence mapping table in the form of a two-dimensional array, each row of the two-dimensional array describes a timing logic relationship, including a source task, a timing relationship type, and a target task. In order to intuitively express the timing logic relationship of task execution, the timing representation diagram can be created as a Gantt Chart. The Gantt chart graphically displays the schedule and progress of tasks, and can clearly show the timing relationship between tasks. At the logical implementation level, the task execution timing relationship expressed in the Gantt chart is abstracted into a task execution sequence mapping table. The task execution sequence mapping table stores the timing relationship between tasks in the form of a matrix or list, which is convenient for computer programs to process and schedule.
[0046] Figure 6 A timing logic diagram provided in the embodiment of the present application. Figure 6As shown, the task execution sequence mapping table can be expressed as: TaskGraph[] = [[T1, FS, T2], [T2, SS, T3], [T2, FS, T4], [T3, FS, T4], [T4, FS, T5], [T5, FF, T6]]. Specifically, TaskGraph[] is a list that includes multiple triples, each of which contains three elements, representing the temporal logic relationship between two tasks. The first element (such as T1, T2, etc.) is the identifier of the source task. The second element (such as FS, SS, etc.) is the type of the temporal logic relationship. The third element (such as T2, T3, etc.) is the identifier of the target task. [T1, FS, T2] means that when task T1 ends, task T2 must start. [T2, SS, T3] means that when task T2 starts, task T3 must also start. [T2, FS, T4] means that when task T2 ends, task T4 must start. [T3, FS, T4] means that when task T3 ends, task T4 must start. [T4, FS, T5] means that when task T4 ends, task T5 must start. [T5, FF, T6] means that when task T5 ends, task T6 must also end at a certain time point. This task execution sequence mapping table provides the system with sufficient information to determine the execution order of tasks and possible parallel execution opportunities, thereby optimizing resource usage and improving overall efficiency. Of course, the task execution sequence mapping table can also be expressed in other forms, and this application is not limited to the above examples.
[0047] S103: Define a task state machine based on the task data, and abstract and manage the state transition logic inside the task state machine through a state transition diagram and a task state transition mapping table.
[0048] Specifically, the task state machine defined in the present application is a Mealy-type task state machine. Of course, it can also be other types of task state machines, and the present application is not limited to the above-mentioned types of task state machines.
[0049] Figure 3 The specific flow chart of the state transition logic inside the task state machine is abstracted and managed through the state transition diagram and the task state transition mapping table provided in the embodiment of the present application, such as Figure 3 As shown, it includes steps S301 to S307.
[0050] S301: define the task states included in the task state machine. The task states include not meeting the start condition, not started, in progress, finished, and terminated.
[0051] Specifically, the state of not meeting the start condition indicates that the task does not currently meet the conditions for starting execution. This may be because the predecessor task is not completed, the resources are not ready, the time is not up, etc. In this state, the task will not be executed until all the start conditions are met. The state of not starting indicates that when all the start conditions of the task are met, but the execution has not started, the task is in the state of not starting. This may be because it is waiting for execution resources, manual triggering, or timer triggering. The state of in progress indicates that the task has started to execute but has not yet been completed. The task is occupying resources and may produce intermediate results or progress updates. The state of ended indicates that when the task is successfully executed, all work has been completed, and the expected results have been achieved, the task is in the state of ended. This is a normal end point in the task life cycle. The state of terminated indicates that if the task is forced to stop during execution due to some reason (such as errors, cancellation requests, insufficient resources, etc.), the task will enter the state of terminated. This is an abnormal end point in the task life cycle. Defining these states helps to clearly understand the position and state of a task in its life cycle, and also provides a basis for state transition and task management. These states and their transition logic are the core part of the task state machine, which defines how the task responds to external events and changes in internal conditions.
[0052] S302: Setting the functions of entering and leaving the state node of the task state machine, and determining the legal transition path between each state.
[0053] Specifically, when a task moves from the current state to a new state, a function to enter the new state, namely the state node function, will be triggered. This function is usually used to perform initialization work related to the new state, such as resource allocation, setting flags, triggering notifications, etc. Before the task leaves the current state, a function to leave the current state, namely the state node function, will be triggered. This function is usually used to perform cleanup work related to the old state, such as releasing resources, updating status flags, sending completion notifications, etc. The state machine defines which state transitions are legal, that is, which events can trigger a transition from the current state to another state. These transition paths are usually determined based on business logic and rules.
[0054] S303: define a state transition function, which describes how the task state machine transitions to the next state when a transition trigger condition is met in different states.
[0055] Specifically, each state transition requires one or more transition trigger conditions, which are determined based on time, external events (such as user requests, system notifications), internal events (such as task completion, resource availability), task progress, resource status, etc. The state transition function receives the current state, transition trigger event or transition trigger condition as input, and then determines whether the state transition needs to be executed according to the predetermined rules, and executes the corresponding transition logic.
[0056] S304: Define the specific state to which the task state machine will transfer when the transition trigger condition is met.
[0057] Specifically, for each trigger condition, it is necessary to specify which state the task state machine should transition to when the condition is met. The specific state that the task state machine will transition to, i.e., the target state, must be one of the predefined states and a state that can be legally transitioned to from the current state. For example, the following state transitions of the task state machine and their target states can be defined based on the task states contained in the previously defined task state machine. When all transition trigger conditions are met and the user or system decides to start the task, the task state machine transitions from not having the start condition to not starting (target state). When the task state machine is in the not starting state and is started for execution, it transitions from not starting to in progress (target state). When the task state machine is in the in progress state and all work is successfully completed, it transitions from in progress to ended (target state). If an error occurs during the execution of the task or the user requests to terminate the task, the task state machine transitions from in progress to terminated (target state).
[0058] S305: Use a state transition diagram to describe the state transition process of the task state machine, wherein each node in the state transition diagram represents a state.
[0059] S306: Add arrows in the state transition diagram to indicate transitions between states, and mark the transition triggering conditions and possible outputs on the arrows.
[0060] Specifically, a state transition diagram is a graphical representation used to show the transition process of a system or task between different states. The state transition diagram contains four key elements, including the current state (CurrentState), the next state (NextState), the action (Action), and the transition (Transition).
[0061] S307: Abstract the information of the state transition diagram into a task state transition mapping table. The state transition mapping table is represented in the form of an array, and each array element contains three fields, namely, the current state, the trigger action, and the next state.
[0062] Figure 7The state transition diagram provided in the embodiment of the present application is shown in FIG. Figure 7 As shown, the task state transition mapping table can be expressed as: FsmGraph[] = [[1,A,2], [1,B,3], [1,C,4], [1,D,5], [2,E,2], [2,I,6], [3,F,3], [3,J,6], [3,M,4], [4,G,4], [4,K,6], [5,H,5], [5,L,6], [5,O,2], [5,N,4]]. Specifically, FsmGraph is a list that includes multiple triples, each of which contains three elements to describe the transition between states. The first element is the identifier of the current state, which is used to indicate the current state in the state machine. The second element is the trigger action that causes the state transition. The third element is the next state (target state) to which the state machine will transition when the trigger action occurs. For example, [1, A, 2] means that when the task state machine is in state 1 and receives input A, it will transfer to state 2. [1, B, 3] means that when the task state machine is in state 1 and receives input B, it will transfer to state 3. [1, C, 4] means that when the task state machine is in state 1 and receives input C, it will transfer to state 4. Other state transition rules in the task state transition mapping table are omitted here, and so on. Of course, the task state transition mapping table can also be expressed in other forms, and the present application is not limited to the above examples.
[0063] S104: Create and define the state transition logic and task control logic of the task state machine, wherein the state transition logic is defined by the state transition function, and the task control logic is defined by the task execution sequence control function.
[0064] Furthermore, the state transition logic describes the rules for how the task state machine transitions between different states, and is usually defined by one or more state transition functions. The state transition function receives the current state, the transition trigger event, or the transition trigger condition as input, and then outputs a new state, indicating the new position to which the state machine should transfer. The task control logic defines the order and dependencies of task execution, and is usually implemented through the task execution sequence control function. The task execution sequence control function determines the next task to be executed based on the task execution sequence mapping table.
[0065] S105: Use the state transition function and the task execution sequence control function to jointly manage the execution process of the new task state machine instance.
[0066] Specifically, the state transition function includes an event trigger and a state transition method. When the event trigger detects that an event meets the state transition condition, the state transition method is called.
[0067] Specifically, the event trigger is responsible for monitoring and detecting external events. When an event occurs, the event trigger determines whether the event meets the state transition condition in the current state. When the event trigger detects an event that meets the state transition condition, the state transition method will be called to perform the actual state transition operation.
[0068] Figure 4 A specific flow chart of the state conversion method provided in the embodiment of the present application, such as Figure 4 As shown, it includes steps S401 to S405.
[0069] S401: Acquire next state information corresponding to the current state from the task state transition mapping table.
[0070] Specifically, when the event trigger detects an event that meets the state transition condition, the state transition method first obtains the next state information corresponding to the current state from the task state transition mapping table. This task state transition mapping table contains all possible state transition rules, that is, the correspondence between the current state, the triggering action that causes the state transition, and the next state.
[0071] S402: Execute the execution action of the current state node and record the execution result.
[0072] Specifically, before the state transition is performed, the actions defined by the current state node need to be executed. These actions include executing a task, updating data, sending messages, etc. After the action is executed, the execution result needs to be recorded in order to determine whether the state transition conditions are met later.
[0073] S403: If the execution result satisfies the state transition condition, start traversing the task state transition mapping table to search for the next state information.
[0074] Specifically, according to the execution result, it is determined whether the state transition condition is met. If it is met, the task state transition mapping table is traversed to find the next state information that matches the current state and the triggering event. If it is not met, the current state is stayed or other logic is executed.
[0075] Furthermore, assume that the overview of the task state machine is: initial state: state 1 (task T1 starts execution), end state: state 6 (task T1 ends, state machine is destroyed), intermediate states: state 2, state 3, state 4, state 5, triggering events: A, B, C, D, E, I, F, M, J, G, K, H, L.
[0076] Assume that the initial state of task T1 is state 1. When the task starts executing, the following situations may occur: A. When event A occurs during task execution, the state switches from state 1 to state 2; B. When event B occurs during task execution, the state switches from state 1 to state 3; C. When event C occurs during task execution, the state switches from state 1 to state 4; D. When event D occurs during task execution, the state switches from state 1 to state 5.
[0077] Assuming that task T1 is executed to state 2, the following situations may occur: 1. When event E occurs during task execution, the original state is maintained; 2. When event I occurs during task execution, the state switches from state 2 to state 6.
[0078] Assuming that when task T1 is executed to state 3, the following situations may occur: 1. When event F occurs during task execution, the original state is maintained; 2. When event M occurs during task execution, the state switches from state 3 to state 4; C. When event J occurs during task execution, the state switches from state 3 to state 6.
[0079] Assuming that when task T1 is executed to state 4, the following situations may occur: 1. When event G occurs during task execution, the original state is maintained; 2. When event K occurs during task execution, the state switches from state 4 to state 6.
[0080] Assuming that when task T1 is executed to state 5, the following situations may occur: 1. When event H occurs during task execution, the original state is maintained; 2. When event L occurs during task execution, the state switches from state 5 to state 6.
[0081] Assume that task T1 is executed to state 6, the task ends and the state machine is destroyed.
[0082] It should be noted that this is only exemplary, and the present application is not limited to the overview of the above-mentioned hypothetical task state machine and possible situations.
[0083] S404: After finding the next state, the current state variable is updated to the next state, and the resources related to the previous state in the memory are destroyed.
[0084] Specifically, in order to save memory and avoid resource leakage, resources related to the previous state need to be destroyed or released.
[0085] S405: When all states in the task state conversion mapping table are processed, it means that the task execution is completed.
[0086] Specifically, the above steps are continued until all states in the task state transition mapping table are processed. When all states are processed, it means that the task has been completed.
[0087] Furthermore, the task execution sequence control function includes a state control function constructor and a task state listener. The task state listener is used to continuously monitor changes in task states and trigger corresponding processing logic when the state changes. When the task state listener monitors the state change, the state control function constructor starts working.
[0088] Figure 5 A specific flow chart of the working steps of the state control function constructor provided in the embodiment of the present application, such as Figure 5 As shown, it includes steps S501 to S503.
[0089] S501: Obtain a task execution sequence mapping table, which defines the logic of task execution sequence and state transition.
[0090] Specifically, when the task state changes, the first step of the state control function constructor is to obtain the task execution sequence mapping table. The task execution sequence mapping table defines the logic of the task execution sequence and state transition. It tells the system which tasks should be executed in different states, as well as the dependencies and execution order between these tasks.
[0091] S502: Traverse the task execution sequence mapping table and search for a task execution sequence that meets the conditions according to the current state. The task execution sequence that meets the conditions is a task execution sequence that matches the current state.
[0092] Specifically, the state control function constructor will traverse the entire task execution sequence mapping table and search for a task execution sequence that meets the conditions according to the current state. This process is actually looking for a task execution sequence that matches the current state. Once such a sequence is found, the constructor will know which tasks should be executed next.
[0093] S503: If a task execution sequence that meets the conditions is found, a new task state machine instance is constructed and started.
[0094] Specifically, if the state control function constructor finds a task execution sequence that meets the conditions, it will start to construct a new task state machine instance. This new instance will execute the corresponding tasks according to the found task execution sequence and update the state of the task state machine. At the same time, the new instance will also inherit some properties or configurations of the previous instance to ensure the continuity and consistency of task execution.
[0095] Furthermore, the state control function constructor constructs and starts a new task state machine instance, and the following situations may occur. Assuming that T1 starts to execute, the global current state variable of T1 becomes start, but the task state listener does not meet the conditions; assuming that T1 ends, the global current state variable of T1 becomes end, the task state listener meets the conditions, and T2 starts to execute; assuming that T2 starts, the global current state variable of T2 becomes start, the task state listener meets the conditions, and T3 starts to execute; assuming that T2 ends, the global current state variable of T2 becomes end, the task state listener meets the conditions, and T4 can start to execute, but T4 starts only when T3 ends. If the conditions are not fully met, T4 cannot start to execute; assuming that T3 starts, the global current state variable of T3 becomes start, and the task state listener does not meet the conditions; assuming that T3 ends, the global current state variable of T3 becomes end, and any The task state listener meets the conditions. At this time, T2 and T3 have ended, and T4 can start; assuming that T4 starts, the global current state variable of T4 becomes ended, and the task state listener does not meet the conditions; assuming that T4 ends, the global current state variable of T4 becomes ended, the task state listener meets the conditions, and T5 and T6 can start; assuming that T5 starts, the global current state variable of T5 becomes started, and the task state listener does not meet the conditions; assuming that T5 ends, the global current state variable of T5 becomes ended, the task state listener meets the conditions, and T6 can end; assuming that T6 starts, the global current state variable of T6 becomes started, and the task state listener does not meet the conditions; assuming that T6 ends, the global current state variable of T6 becomes ended, and the task state listener does not meet the conditions. It should be noted that this is only exemplary, and the present application is not limited to the above-mentioned construction and starting of a new task state machine instance.
[0096] It should be noted that each task (T1, T2, T3, ..., T6) has its own state machine, which is used to describe the state changes of the task from start to end. There may be dependencies between tasks, that is, the start or end of a task may depend on the completion of another task. For example, the condition for T4 to start execution is that both T2 and T3 have ended. Each task will go through different states (such as start, end, etc.) during execution. When the state of a task changes, the task state listener will check whether there are subsequent tasks that meet the conditions and need to be triggered. The task state machine is used to manage the life cycle of a single task, while the task state listener and the state control function constructor are used to manage the dependencies and triggering relationships between tasks to ensure that tasks are executed in the correct order and conditions.
[0097] S106: Continuously monitor changes in task status through the task status listener and trigger corresponding processing logic.
[0098] Specifically, the processing logic includes task start logic, task execution logic, task completion logic, error handling logic and dependent task triggering logic.
[0099] The present application embodiment also provides a task control device 800 based on a state machine, such as Figure 8 As shown, the device includes: a planning module 801 , a creation module 802 , a management module 803 , a definition logic module 804 , a common management module 805 and a trigger module 806 .
[0100] The planning module 801 is used to abstract the business process steps into instantiated task node data according to the simulation training business process diagram, and to plan the task data and define the task participating objects.
[0101] The creation module 802 is used to define the temporal logic relationship between task data, create a temporal representation diagram to represent the temporal logic relationship of task execution, and abstract it into a task execution sequence mapping table.
[0102] The management module 803 is used to define a task state machine based on task data, and abstract and manage the state transition logic inside the task state machine through a state transition diagram and a task state transition mapping table.
[0103] The definition logic module 804 is used to create and define the state transition logic and task control logic of the task state machine, wherein the state transition logic is defined by the state transition function, and the task control logic is defined by the task execution sequence control function.
[0104] The co-management module 805 is used to co-manage the execution process of the new task state machine instance using the state transition function and the task execution sequence control function.
[0105] The trigger module 806 is used to continuously monitor the changes of the task status through the task status listener and trigger the corresponding processing logic.
[0106] Some modules in the apparatus described in the present application can be described in the general context of computer executable instructions executed by a computer, such as program modules. Generally, program modules include routines, programs, objects, components, data structures, classes, etc. that perform specific tasks or implement specific abstract data types. The present application can also be practiced in distributed computing environments, in which tasks are performed by remote processing devices connected through a communication network. In a distributed computing environment, program modules can be located in local and remote computer storage media including storage devices.
[0107] The devices or modules described in the above application embodiments can be implemented by computer chips or entities, or by products with certain functions. For the convenience of description, the above devices are described in various modules according to their functions. When implementing the embodiments of the present application, the functions of each module can be implemented in the same or multiple software and / or hardware. Of course, the module that implements a certain function can also be implemented by combining multiple sub-modules or sub-units.
[0108] The methods, devices or modules described in this application can be implemented in the form of computer-readable program codes. The controller can be implemented in any appropriate manner. For example, the controller can take the form of a microprocessor or processor and a computer-readable medium storing computer-readable program codes (such as software or firmware) that can be executed by the (micro)processor, logic gates, switches, application-specific integrated circuits (English: Application Specific Integrated Circuit, referred to as: ASIC), programmable logic controllers and embedded microcontrollers. Examples of controllers include but are not limited to the following microcontrollers: ARC 625D, Atmel AT91SAM, Microchip PIC18F26K20 and Silicone Labs C8051F320. The memory controller can also be implemented as part of the control logic of the memory. Those skilled in the art also know that in addition to implementing the controller in the form of pure computer-readable program codes, the controller can be implemented in the form of logic gates, switches, application-specific integrated circuits, programmable logic controllers and embedded microcontrollers by logically programming the method steps. Therefore, this controller can be considered as a hardware component, and the devices included in it for implementing various functions can also be regarded as structures within the hardware component. Or even, the means for realizing various functions may be regarded as both a software module for realizing the method and a structure within a hardware component.
[0109] like Fig. 9 As shown, the embodiment of the present application also provides a task control server based on a state machine, including a memory 901 and a processor 902; the memory 901 is used to store computer executable instructions; the processor 902 is used to execute computer executable instructions to implement the above-mentioned task control method based on a state machine in the embodiment of the present application. The memory of the present application is also used to store a task state transition mapping table and a task execution sequence mapping table of the state machine.
[0110] An embodiment of the present application also provides a computer-readable storage medium, which stores executable instructions. When a computer executes the executable instructions, it can implement the state machine-based task control method described above in the embodiment of the present application.
[0111] It can be seen from the description of the above implementation methods that those skilled in the art can clearly understand that the present application can be implemented by means of software plus necessary hardware. Based on this understanding, the technical solution of the present application can be essentially or partly contributed to the prior art in the form of a software product, or it can be reflected in the implementation process of data migration. The computer software product can be stored in a storage medium, such as ROM / RAM, a disk, an optical disk, etc., including a number of instructions for a computer device (which can be a personal computer, a mobile terminal, a server, or a network device, etc.) to execute the method described in the embodiment of the present application.
[0112] The various embodiments in this specification are described in a progressive manner, and the same or similar parts between the various embodiments can be referred to each other, and each embodiment focuses on the differences from other embodiments. All or part of this application can be used in many general or special computer system environments or configurations.
[0113] The above embodiments are only used to illustrate the technical solutions of the present application, rather than to limit the present application. Although the present application has been described in detail with reference to the aforementioned embodiments, a person of ordinary skill in the art should understand that the technical solutions described in the aforementioned embodiments may still be modified, or some or all of the technical features thereof may be replaced by equivalents. However, these modifications or replacements do not cause the essence of the corresponding technical solutions to deviate from the scope of the technical solutions of the present application.
Claims
1. A task control method based on a state machine, characterized in that: include: According to the simulation training business process diagram, the business process steps are abstracted into instantiated task node data, and the task data is planned and the task participants are defined; Define the temporal logic relationship between task data, create a temporal representation diagram to represent the temporal logic relationship of task execution, and abstract it into a task execution sequence mapping table; Based on the task data, a task state machine is defined, the state transition logic inside the task state machine is abstracted and managed through a state transition diagram and a task state transition mapping table, and a task control logic is created and defined; wherein the state transition logic is defined by a state transition function, and the task control logic is defined by a task execution sequence control function; The task state machine is defined based on the task data, and the state transition logic inside the task state machine is abstracted and managed through a state transition diagram and a task state transition mapping table, including: defining the task states contained in the task state machine; the task states include not having a start condition, not started, in progress, ended, and terminated; setting functions for the task state machine to enter a state node and leave a state node, and determining a legal transition path between each state; defining a state transition function, which describes how the task state machine transitions to the next state when a transition trigger condition is met under different states; defining a specific state to which the task state machine will transfer when the transition trigger condition is met; using a state transition diagram to describe the state transition process of the task state machine; wherein each node in the state transition diagram represents a state; adding arrows in the state transition diagram to indicate transitions between states, and marking the transition trigger conditions and possible outputs on the arrows; abstracting the information in the state transition diagram into a task state transition mapping table; the state transition mapping table is represented in the form of an array, and each array element contains three fields, namely, the current state, the trigger action, and the next state; The task execution sequence control function includes a state control function constructor and a task state listener; the task state listener is used to continuously monitor changes in task states and trigger corresponding processing logic when the state changes; when the task state listener monitors the state change, the state control function constructor starts working; The working steps of the state control function constructor are as follows: obtaining a task execution sequence mapping table, wherein the task execution sequence mapping table defines the logic of the task execution sequence and the state transition; traversing the task execution sequence mapping table, and searching for a task execution sequence that meets the conditions according to the current state; wherein the task execution sequence that meets the conditions is a task execution sequence that matches the current state; if a task execution sequence that meets the conditions is found, constructing and starting a new task state machine instance; Use the state transition function and the task execution sequence control function to jointly manage the execution process of the new task state machine instance; The task status listener continuously monitors changes in task status and triggers corresponding processing logic.
2. The task control method based on the state machine according to claim 1 is characterized in that: Before abstracting the business process steps into instantiated task node data according to the simulation training business process diagram, the method includes: According to the needs of simulation training, plan the simulation training mission scenario elements and develop a simulation training business process diagram; wherein the simulation training mission scenario elements include: training scenario weather and time, equipment elements and load elements.
3. The task control method based on a state machine according to claim 1, characterized in that: The process of abstracting the business process steps into instantiated task node data according to the simulation training business process diagram, planning the task data and defining the task participants includes: Define task data according to the simulation training business process diagram, set the task start time, task end time and task type, so as to abstract the business process steps into instantiated task node data; The planning task data includes: planning the task execution process, planning the equipment action route and setting the task execution script.
4. The task control method based on the state machine according to claim 1, characterized in that: Defining the temporal logic relationship between task data includes: Select one or more tasks as source tasks of the temporal relationship; Select other tasks as the target tasks of the temporal relationship; Define the temporal logic relationship between task data based on the dependency relationship between source tasks and target tasks; The temporal logic relationship includes a parallel start relationship, a pre-start and post-end relationship, a post-start relationship and a synchronous end relationship; The parallel start relationship is that when the source task starts, the target task must also start; The preceding start-after-end relationship is that when the source task starts, the target task must end immediately; The post-start relationship is that when the source task ends, the target task must start; The synchronous termination relationship is that when the source task is terminated, the target task must also be terminated at a certain time point.
5. The task control method based on the state machine according to claim 4 is characterized in that: The creation of a timing representation diagram represents the timing logical relationship of task execution, and abstracts it into a task execution sequence mapping table, including: The task execution sequence mapping table is represented in the form of a two-dimensional array, and each row of the two-dimensional array describes a temporal logic relationship, including a source task, a temporal relationship type, and a target task.
6. The task control method based on the state machine according to claim 1, characterized in that: The state transition function includes an event trigger and a state transition method; When the event trigger detects that a certain event meets the state transition condition, the state transition method is called; The state conversion method comprises: Get the next state information corresponding to the current state from the task state transition mapping table; Execute the execution action of the current state node and record the execution result; If the execution result meets the state transition condition, start traversing the task state transition mapping table to find the next state information; After finding the next state, update the current state variable to the next state and destroy the resources related to the previous state in memory; When all states in the task state transition mapping table are processed, it means that the task execution is completed.
7. A task control device based on a state machine, characterized in that: include: The planning module is used to abstract the business process steps into instantiated task node data according to the simulation training business process diagram, and to plan the task data and define the task participants; Create a module to define the temporal logic relationship between task data, create a temporal representation diagram to represent the temporal logic relationship of task execution, and abstract it into a task execution sequence mapping table; A management module is used to define a task state machine based on the task data, abstract and manage the state transition logic inside the task state machine through a state transition diagram and a task state transition mapping table, and create and define a task control logic; wherein, the state transition logic is defined by a state transition function, and the task control logic is defined by a task execution sequence control function; the task state machine is defined based on the task data, and the state transition logic inside the task state machine is abstracted and managed through a state transition diagram and a task state transition mapping table, including: defining the task states contained in the task state machine; the task states include not having a start condition, not starting, in progress, ended, and terminated; setting functions for the task state machine to enter a state node and leave a state node, and determining a legal transition path between each state; defining a state transition function, wherein the state transition function describes how the task state machine transitions to the next state when a transition trigger condition is met in different states; defining a specific state to which the task state machine will transfer when the transition trigger condition is met; using a state transition diagram to describe the state transition process of the task state machine; wherein each node in the state transition diagram represents Table a state; add arrows in the state transition diagram to indicate the transition between states, and mark the transition trigger conditions and possible outputs on the arrows; abstract the information of the state transition diagram into a task state transition mapping table; the state transition mapping table is represented in the form of an array, and each array element contains three fields, namely the current state, the trigger action, and the next state; the task execution sequence control function includes a state control function constructor and a task state listener; the task state listener is used to continuously monitor the changes in the task state, and trigger the corresponding processing logic when the state changes; when the task state listener monitors the state change, the state control function constructor starts working; the working steps of the state control function constructor are: obtain the task execution sequence mapping table, the task execution sequence mapping table defines the logic of the task execution sequence and the state transition; traverse the task execution sequence mapping table, and search for the task execution sequence that meets the conditions according to the current state; wherein, the task execution sequence that meets the conditions is the task execution sequence that matches the current state; if a task execution sequence that meets the conditions is found, a new task state machine instance is constructed and started; A co-management module, used to co-manage a new task state machine instance execution process using the state transition function and the task execution sequence control function; The trigger module is used to continuously monitor changes in task status through the task status listener and trigger corresponding processing logic.
