BPMN-OS
BPMN for optimization and simulation
Loading...
Searching...
No Matches
SystemState.h
Go to the documentation of this file.
1#ifndef BPMNOS_Execution_SystemState_H
2#define BPMNOS_Execution_SystemState_H
3
4#include "StateMachine.h"
5#include "DecisionRequest.h"
10#include <set>
11#include <queue>
12
13namespace BPMNOS::Execution {
14
15class Engine;
16
17
18/**
19 * @brief A class representing the state that the execution or simulation of a given scenario is in.
20 */
22private:
23 const Engine* engine;
24
25public:
28
29 /**
30 * @brief Pointer to the corresponding scenario.
31 */
33
34 /**
35 * @brief Timestamp holding the point in time that the engine is in (this is usually representing now).
36 */
38
39 /**
40 * @brief Timestamp holding the point in time that the simulation is in (this could be a future point in time).
41 */
42 std::optional<BPMNOS::number> assumedTime;
43
44 /**
45 * @brief Function returning the assumed time time if available or the current time otherwise.
46 */
47 BPMNOS::number getTime() const;
48
49 /**
50 * @brief Function returning true if there are tokens in the system or if there may be new instantiations of tokens.
51 */
52 bool isAlive() const;
53
54 /**
55 * @brief Returns the total objective value (assuming maximization) accumulated during execution.
56 *
57 * Global attributes are evaluated upon each call of the method.
58 *
59 * Attributes declared for activities, event-subprocesses, and processes contribute to the objective when
60 * - the activity is exited,
61 * - a compensation activity is completed,
62 * - the event-subprocess shuts down without failure, or
63 * - the process shuts down without failure.
64 *
65 * In all other cases values of attributes declared to contribute to the objective will be ignored.
66 */
68
69 BPMNOS::number contributionsToObjective; ///< All contributions that have already been added to the objective.
70
71 auto_list< std::weak_ptr<Token>, std::weak_ptr<DecisionRequest> > pendingEntryDecisions;
73 auto_list< std::weak_ptr<Token>, std::weak_ptr<DecisionRequest> > pendingExitDecisions;
75
76 auto_list< std::weak_ptr<Token> > tokensAwaitingReadyEvent; ///< Container holding all tokens awaiting a ready event
77 auto_set< BPMNOS::number, std::weak_ptr<Token> > tokensAwaitingCompletionEvent; ///< Sorted container holding all tokens awaiting a task completion event
78
79 /**
80 * @brief Container holding instance identifier and corresponding state machine pointer for each instantiation.
81 */
82 std::unordered_map< long unsigned int, std::weak_ptr<StateMachine> > archive;
83
84 /**
85 * @brief Map holding unsent messages with recipient that isn't instantiated yet.
86 */
87 std::unordered_map<long unsigned int, auto_list< std::weak_ptr<Message> > > unsent;
88
89 /**
90 * @brief Map holding the undelivered correspondence associated with a state machine which will be withdrawn when the state machine goes out of scope.
91 */
92 std::unordered_map<StateMachine*, auto_list< std::weak_ptr<Message> > > inbox;
93
94 /**
95 * @brief Map holding messages sent from given node.
96 */
97 std::unordered_map<const BPMN::FlowNode*, auto_list< std::weak_ptr<Message> > > outbox;
98
99 //TODO: move below to StateMachine or Token?
100 //TODO: make sure that elements are deleted when no longer required
101 std::unordered_map< Token*, std::vector<Token*> > tokensAwaitingBoundaryEvent; ///< Map holding a container of all tokens at a boundary event awaiting to be triggered for each token at an activity
102 std::unordered_map< Token*, Token* > tokenAssociatedToBoundaryEventToken; ///< Map holding the token residing at the associated activity for each token at a boundary event
103
104 auto_set<BPMNOS::number, std::weak_ptr<Token>> tokensAwaitingTimer; ///< Sorted container holding holding all tokens awaiting a timer event
105
106 std::unordered_map< BPMNOS::number, auto_list< std::weak_ptr<Token> > > tokensAwaitingSignal; ///< Map holding a container of all tokens at a signal event awaiting a signal with a given name
107
108 std::unordered_map< BPMNOS::number, auto_list< std::weak_ptr<Token> > > tokensAwaitingCondition; ///< Map holding a container of all tokens at a conditional event belonginge to a process instance
109
110 std::unordered_map< Token*, std::weak_ptr<Message> > messageAwaitingDelivery; ///< Container holding message awaiting delivery for tokens at send tasks
111
112 std::unordered_map< Token*, Token* > tokenAtMultiInstanceActivity; ///< Map holding the main token waiting at a multi-instance (or loop) activity.
113 std::unordered_map< Token*, Token* > tokenAwaitingMultiInstanceExit; ///< Map holding the token waiting for the exit of an instantiation of a multi-instance (or loop) activity.
114 std::unordered_map< Token*, std::vector<Token*> > tokensAtActivityInstance; ///< Map holding all tokens representing an active instance of a multi-instance (or loop) activity for each token waiting at the multi-instance (or loop) activity.
115 std::unordered_map< Token*, std::vector<BPMNOS::Values> > exitStatusAtActivityInstance; ///< Map holding the exit status of all instances of a multi-instance (or loop) activity for each token waiting at the multi-instance (or loop) activity.
116
117 std::unordered_map< Token*, Token* > tokenAtEventBasedGateway; ///< Map holding the token at the relevant event-based gateway
118 std::unordered_map< Token*, std::vector<Token*> > tokensAwaitingEvent; ///< Map holding all tokens at catching events subsequent to an event-based gateway
119
120 std::unordered_map< StateMachine*, std::map<const BPMN::FlowNode*, std::vector<Token*> > > tokensAwaitingGatewayActivation; ///< Map holding tokens awaiting activation of a converging gateway
121
122// std::unordered_map< StateMachine*, std::map<const BPMN::Node*, Token* > > tokensAwaitingCompensation; ///< Map holding tokens awaiting completion of a compensation
123
124 std::unordered_map< Token*, Token* > tokenAwaitingCompensationActivity; ///< Map holding a token that waits for completion of another
125 std::unordered_map< StateMachine*, Token* > tokenAwaitingCompensationEventSubProcess; ///< Map holding a token that waits for completion of an event subprocess
126
128
129 /**
130 * @brief Container holding a state machine for each running instance.
131 */
133
134 /**
135 * @brief Container holding all messages created by a throwing message event.
136 */
138
139 std::optional<BPMNOS::Values> getStatusAttributes(const StateMachine* root, const BPMN::Node* node) const;
140 std::optional<BPMNOS::Values> getDataAttributes(const StateMachine* root, const BPMN::Node* node) const;
141
142 /**
143 * @brief Method returning a vector of all instantiations at the given time.
144 *
145 * A vector representing an instantiation contains a reference to the process, the initial status, and the initial data attribute value
146 */
147 std::vector< std::tuple<const BPMN::Process*, BPMNOS::Values, BPMNOS::Values> > getInstantiations() const;
148
149private:
150 friend class Engine;
151 friend class StateMachine;
152 friend class Token;
154
155 SystemState() = delete;
156
157
158 void incrementTimeBy(BPMNOS::number duration);
159 size_t instantiationCounter;
160};
161
162} // namespace BPMNOS::Execution
163
164#endif // BPMNOS_Execution_SystemState_H
Represents a state machine for BPMN execution of a scope in the model.
A class representing the state that the execution or simulation of a given scenario is in.
Definition SystemState.h:21
std::unordered_map< Token *, Token * > tokenAtMultiInstanceActivity
Map holding the main token waiting at a multi-instance (or loop) activity.
std::unordered_map< Token *, std::vector< Token * > > tokensAtActivityInstance
Map holding all tokens representing an active instance of a multi-instance (or loop) activity for eac...
StateMachines instances
Container holding a state machine for each running instance.
BPMNOS::number currentTime
Timestamp holding the point in time that the engine is in (this is usually representing now).
Definition SystemState.h:37
auto_list< std::weak_ptr< Token >, std::weak_ptr< DecisionRequest > > pendingEntryDecisions
Definition SystemState.h:71
auto_list< std::weak_ptr< Token >, std::weak_ptr< DecisionRequest > > pendingExitDecisions
Definition SystemState.h:73
std::unordered_map< BPMNOS::number, auto_list< std::weak_ptr< Token > > > tokensAwaitingSignal
Map holding a container of all tokens at a signal event awaiting a signal with a given name.
std::optional< BPMNOS::Values > getStatusAttributes(const StateMachine *root, const BPMN::Node *node) const
BPMNOS::number getTime() const
Function returning the assumed time time if available or the current time otherwise.
Messages messages
Container holding all messages created by a throwing message event.
BPMNOS::number contributionsToObjective
All contributions that have already been added to the objective.
Definition SystemState.h:69
std::unordered_map< StateMachine *, auto_list< std::weak_ptr< Message > > > inbox
Map holding the undelivered correspondence associated with a state machine which will be withdrawn wh...
Definition SystemState.h:92
std::unordered_map< Token *, std::vector< Token * > > tokensAwaitingBoundaryEvent
Map holding a container of all tokens at a boundary event awaiting to be triggered for each token at ...
std::unordered_map< Token *, Token * > tokenAwaitingCompensationActivity
Map holding a token that waits for completion of another.
const BPMNOS::Model::Scenario * scenario
Pointer to the corresponding scenario.
Definition SystemState.h:32
std::optional< BPMNOS::Values > getDataAttributes(const StateMachine *root, const BPMN::Node *node) const
auto_set< BPMNOS::number, std::weak_ptr< Token > > tokensAwaitingCompletionEvent
Sorted container holding all tokens awaiting a task completion event.
Definition SystemState.h:77
std::unordered_map< long unsigned int, std::weak_ptr< StateMachine > > archive
Container holding instance identifier and corresponding state machine pointer for each instantiation.
Definition SystemState.h:82
auto_list< std::weak_ptr< Token > > tokensAwaitingReadyEvent
Container holding all tokens awaiting a ready event.
Definition SystemState.h:76
auto_list< std::weak_ptr< Token >, std::weak_ptr< DecisionRequest > > pendingMessageDeliveryDecisions
Definition SystemState.h:74
auto_set< BPMNOS::number, std::weak_ptr< Token > > tokensAwaitingTimer
Sorted container holding holding all tokens awaiting a timer event.
auto_list< std::weak_ptr< Token >, std::weak_ptr< DecisionRequest > > pendingChoiceDecisions
Definition SystemState.h:72
std::unordered_map< Token *, std::vector< Token * > > tokensAwaitingEvent
Map holding all tokens at catching events subsequent to an event-based gateway.
bool isAlive() const
Function returning true if there are tokens in the system or if there may be new instantiations of to...
std::unordered_map< Token *, Token * > tokenAtEventBasedGateway
Map holding the token at the relevant event-based gateway.
std::unordered_map< StateMachine *, std::map< const BPMN::FlowNode *, std::vector< Token * > > > tokensAwaitingGatewayActivation
Map holding tokens awaiting activation of a converging gateway.
std::optional< BPMNOS::number > assumedTime
Timestamp holding the point in time that the simulation is in (this could be a future point in time).
Definition SystemState.h:42
std::unordered_map< Token *, Token * > tokenAwaitingMultiInstanceExit
Map holding the token waiting for the exit of an instantiation of a multi-instance (or loop) activity...
BPMNOS::number getObjective() const
Returns the total objective value (assuming maximization) accumulated during execution.
std::vector< std::tuple< const BPMN::Process *, BPMNOS::Values, BPMNOS::Values > > getInstantiations() const
Method returning a vector of all instantiations at the given time.
std::unordered_map< BPMNOS::number, auto_list< std::weak_ptr< Token > > > tokensAwaitingCondition
Map holding a container of all tokens at a conditional event belonginge to a process instance.
std::unordered_map< const BPMN::FlowNode *, auto_list< std::weak_ptr< Message > > > outbox
Map holding messages sent from given node.
Definition SystemState.h:97
std::unordered_map< Token *, Token * > tokenAssociatedToBoundaryEventToken
Map holding the token residing at the associated activity for each token at a boundary event.
std::unordered_map< StateMachine *, Token * > tokenAwaitingCompensationEventSubProcess
Map holding a token that waits for completion of an event subprocess.
std::unordered_map< Token *, std::weak_ptr< Message > > messageAwaitingDelivery
Container holding message awaiting delivery for tokens at send tasks.
std::unordered_map< long unsigned int, auto_list< std::weak_ptr< Message > > > unsent
Map holding unsent messages with recipient that isn't instantiated yet.
Definition SystemState.h:87
std::unordered_map< Token *, std::vector< BPMNOS::Values > > exitStatusAtActivityInstance
Map holding the exit status of all instances of a multi-instance (or loop) activity for each token wa...
Represents a token running through a (sub)process.
Definition Token.h:35
List of tuples with automatic removal of tuples containing an expired weak_ptr.
Definition auto_list.h:15
Set of tuples ordered in increasing order of the first component with automatic removal of tuples con...
Definition auto_set.h:15
The Scenario class holds data for all BPMN instances.
Definition Scenario.h:20
Base class for all nodes in a BPMN model.
Definition bpmn++.h:16444
std::vector< std::shared_ptr< Message > > Messages
Definition Message.h:18
std::vector< std::shared_ptr< StateMachine > > StateMachines
BPMNOS_NUMBER_TYPE number
Definition Number.h:42