BPMN-OS
BPMN for optimization and simulation
Loading...
Searching...
No Matches
Scenario.h
Go to the documentation of this file.
1#ifndef BPMNOS_Model_Scenario_H
2#define BPMNOS_Model_Scenario_H
3
4#include <string>
5#include <memory>
6#include <map>
7#include <unordered_map>
8#include <bpmn++.h>
13
14namespace BPMNOS::Model {
15
16typedef std::unordered_map< const BPMN::Process*, std::unordered_map< std::string, const Attribute* > > DataInput;
17
18/**
19 * @brief Abstract base class for scenarios holding data for all BPMN instances.
20 */
21class Scenario {
22public:
23 struct InstanceData {
25 size_t id; ///< Instance identifier.
26 BPMNOS::number instantiationTime; ///< Time at which the instance is instantiated.
27 std::unordered_map< const Attribute*, std::optional<BPMNOS::number> > values; ///< Attribute values.
28 };
29
30 virtual ~Scenario() = default;
31
32 static constexpr char delimiters[] = {'^','#'}; ///< Delimiters used for disambiguation of identifiers of non-interrupting event subprocesses and multi-instance activities
33
34 /**
35 * @brief Method returning the model.
36 */
37 const Model* getModel() const { return model; }
38
39 /**
40 * @brief Method returning the time of the earliest instantiation.
41 */
43
44 /**
45 * @brief Method returning true if the currentTime exceeds the completion time.
46 */
47 virtual bool isCompleted(const BPMNOS::number currentTime) const = 0;
48
49 /**
50 * @brief Method returning a vector of all instances that are known to be instantiated at the given time.
51 */
52 virtual std::vector< std::tuple<const BPMN::Process*, BPMNOS::Values, BPMNOS::Values> > getCurrentInstantiations(const BPMNOS::number currentTime) const = 0;
53
54 /**
55 * @brief Method returning a vector of all instances that have been created until the given time.
56 */
57 virtual std::vector< const InstanceData* > getCreatedInstances(const BPMNOS::number currentTime) const = 0;
58
59 /**
60 * @brief Method returning a vector of all instances that have been created or are known for sure until the given time.
61 */
62 virtual std::vector< const InstanceData* > getKnownInstances(const BPMNOS::number currentTime) const = 0;
63
64 /**
65 * @brief Method returning a known value of an attribute.
66 *
67 * If the attribute value is not yet known, the method returns std::nullopt.
68 */
69 virtual std::optional<BPMNOS::number> getKnownValue(const Scenario::InstanceData* instance, const BPMNOS::Model::Attribute* attribute, const BPMNOS::number currentTime) const = 0;
70
71 /**
72 * @brief Method returning a known value of an attribute.
73 *
74 * If the attribute value is not yet known, the method returns std::nullopt.
75 */
76 virtual std::optional<BPMNOS::number> getKnownValue(const BPMNOS::number instanceId, const BPMNOS::Model::Attribute* attribute, const BPMNOS::number currentTime) const = 0;
77
78 /**
79 * @brief Method returning all known values of new attributes.
80 *
81 * If at least one attribute value is not yet known, the method returns std::nullopt.
82 */
83 virtual std::optional<BPMNOS::Values> getKnownValues(const BPMNOS::number instanceId, const BPMN::Node* node, const BPMNOS::number currentTime) const = 0;
84
85 /**
86 * @brief Method returning all known values of new attributes.
87 *
88 * If at least one attribute value is not yet known, the method returns std::nullopt.
89 */
90 virtual std::optional<BPMNOS::Values> getKnownData(const BPMNOS::number instanceId, const BPMN::Node* node, const BPMNOS::number currentTime) const = 0;
91
92 /**
93 * @brief Store the completion status when a task enters BUSY state.
94 *
95 * @param instanceId The instance identifier.
96 * @param task The task node entering BUSY state.
97 * @param status The predicted completion status values.
98 */
100 const BPMNOS::number instanceId,
101 const BPMN::Node* task,
102 BPMNOS::Values status
103 ) const {
104 taskCompletionStatus[{(size_t)instanceId, task}] = std::move(status);
105 }
106
107 /**
108 * @brief Get the completion status for a task.
109 *
110 * For deterministic scenarios, returns the value stored by setTaskCompletionStatus().
111 * For stochastic scenarios, evaluates COMPLETION expressions and returns updated status.
112 *
113 * @param instanceId The instance identifier.
114 * @param task The task node that is completing.
115 * @return Completion status values.
116 */
118 const BPMNOS::number instanceId,
119 const BPMN::Node* task
120 ) const {
121 return taskCompletionStatus.at({(size_t)instanceId, task});
122 }
123
124 /**
125 * @brief Initialize arrival data when a token arrives at an activity.
126 *
127 * Evaluates ARRIVAL expressions using the parent scope's context.
128 * Default implementation does nothing - only StochasticScenario evaluates ARRIVAL.
129 *
130 * @param instanceId The instance identifier.
131 * @param node The activity node being entered.
132 * @param status Parent scope's status attributes.
133 * @param data Parent scope's data attributes.
134 * @param globals Global attributes.
135 */
137 [[maybe_unused]] BPMNOS::number instanceId,
138 [[maybe_unused]] const BPMN::Node* node,
139 [[maybe_unused]] const Values& status,
140 [[maybe_unused]] const Values& data,
141 [[maybe_unused]] const Values& globals
142 ) const {}
143
145
146 /// Stored completion status per (instanceId, task)
147 mutable std::map<std::pair<size_t, const BPMN::Node*>, BPMNOS::Values> taskCompletionStatus;
148 const Model* model; ///< Pointer to the BPMN model.
149
150protected:
151 /**
152 * @brief Method returning the initial status attributes for process instantiation.
153 *
154 * Used internally by getCurrentInstantiations to get process-level status attributes.
155 */
156 virtual Values getKnownInitialStatus(const InstanceData*, const BPMNOS::number time) const = 0;
157
158 /**
159 * @brief Method returning the initial data attributes for process instantiation.
160 *
161 * Used internally by getCurrentInstantiations to get process-level data attributes.
162 */
163 virtual Values getKnownInitialData(const InstanceData*, const BPMNOS::number time) const = 0;
164};
165
166} // namespace BPMNOS::Model
167
168#endif // BPMNOS_Model_Scenario_H
Represents a BPMN model with all its processes.
Definition Model.h:22
Abstract base class for scenarios holding data for all BPMN instances.
Definition Scenario.h:21
virtual std::optional< BPMNOS::number > getKnownValue(const BPMNOS::number instanceId, const BPMNOS::Model::Attribute *attribute, const BPMNOS::number currentTime) const =0
Method returning a known value of an attribute.
virtual BPMNOS::number getEarliestInstantiationTime() const =0
Method returning the time of the earliest instantiation.
static constexpr char delimiters[]
Delimiters used for disambiguation of identifiers of non-interrupting event subprocesses and multi-in...
Definition Scenario.h:32
virtual std::vector< const InstanceData * > getCreatedInstances(const BPMNOS::number currentTime) const =0
Method returning a vector of all instances that have been created until the given time.
virtual std::optional< BPMNOS::Values > getKnownValues(const BPMNOS::number instanceId, const BPMN::Node *node, const BPMNOS::number currentTime) const =0
Method returning all known values of new attributes.
virtual void setTaskCompletionStatus(const BPMNOS::number instanceId, const BPMN::Node *task, BPMNOS::Values status) const
Store the completion status when a task enters BUSY state.
Definition Scenario.h:99
virtual BPMNOS::Values getTaskCompletionStatus(const BPMNOS::number instanceId, const BPMN::Node *task) const
Get the completion status for a task.
Definition Scenario.h:117
virtual ~Scenario()=default
const Model * getModel() const
Method returning the model.
Definition Scenario.h:37
virtual void initializeArrivalData(BPMNOS::number instanceId, const BPMN::Node *node, const Values &status, const Values &data, const Values &globals) const
Initialize arrival data when a token arrives at an activity.
Definition Scenario.h:136
std::map< std::pair< size_t, const BPMN::Node * >, BPMNOS::Values > taskCompletionStatus
Stored completion status per (instanceId, task)
Definition Scenario.h:147
virtual std::vector< const InstanceData * > getKnownInstances(const BPMNOS::number currentTime) const =0
Method returning a vector of all instances that have been created or are known for sure until the giv...
virtual bool isCompleted(const BPMNOS::number currentTime) const =0
Method returning true if the currentTime exceeds the completion time.
virtual Values getKnownInitialData(const InstanceData *, const BPMNOS::number time) const =0
Method returning the initial data attributes for process instantiation.
virtual std::vector< std::tuple< const BPMN::Process *, BPMNOS::Values, BPMNOS::Values > > getCurrentInstantiations(const BPMNOS::number currentTime) const =0
Method returning a vector of all instances that are known to be instantiated at the given time.
const Model * model
Pointer to the BPMN model.
Definition Scenario.h:148
virtual std::optional< BPMNOS::number > getKnownValue(const Scenario::InstanceData *instance, const BPMNOS::Model::Attribute *attribute, const BPMNOS::number currentTime) const =0
Method returning a known value of an attribute.
virtual std::optional< BPMNOS::Values > getKnownData(const BPMNOS::number instanceId, const BPMN::Node *node, const BPMNOS::number currentTime) const =0
Method returning all known values of new attributes.
BPMNOS::Values globals
Definition Scenario.h:144
virtual Values getKnownInitialStatus(const InstanceData *, const BPMNOS::number time) const =0
Method returning the initial status attributes for process instantiation.
Base class for all nodes in a BPMN model.
Definition bpmn++.h:16444
std::unordered_map< const BPMN::Process *, std::unordered_map< std::string, const Attribute * > > DataInput
Definition Scenario.h:16
BPMNOS_NUMBER_TYPE number
Definition Number.h:50
std::unordered_map< const Attribute *, std::optional< BPMNOS::number > > values
Attribute values.
Definition Scenario.h:27
const BPMN::Process * process
Definition Scenario.h:24
BPMNOS::number instantiationTime
Time at which the instance is instantiated.
Definition Scenario.h:26
size_t id
Instance identifier.
Definition Scenario.h:25