BPMN-OS
BPMN for optimization and simulation
Loading...
Searching...
No Matches
FlattenedGraph.h
Go to the documentation of this file.
1#ifndef BPMNOS_Execution_FlattenedGraph_H
2#define BPMNOS_Execution_FlattenedGraph_H
3
4#include <unordered_map>
5#include <vector>
6#include <list>
7#include <string>
8#include <unordered_set>
9#include <bpmn++.h>
10#include <nlohmann/json.hpp>
13
14namespace BPMNOS::Execution {
15
16class Token;
17
18/**
19 * @brief Represents a graph containing all BPMN nodes that may receive a token during execution of a scenario.
20 *
21 * For a given @ref BPMNOS::Model::Scenario "scenario", the `FlattenedGraph` class encapsulates a graph containing a vertex for each entry and each exit of a @ref BPMN::Node "node" in a BPMN model. The flattened graph includes all instances known at time zero.
22 */
24public:
27 nlohmann::ordered_json jsonify() const;
28
29 class Vertex {
30 public:
31 enum class Type { ENTRY, EXIT };
32 Vertex(FlattenedGraph* graph, BPMNOS::number rootId, BPMNOS::number instanceId, std::vector< size_t > loopIndices, const BPMN::Node* node, Type type, std::optional< std::pair<Vertex*, Vertex*> > parent);
33 // Delete other constructors and assignment operators
34 Vertex() = delete; // Prevents default construction
35 Vertex(const Vertex&) = delete; // Non-copyable
36 Vertex& operator=(const Vertex&) = delete; // Non-copy-assignable
37 Vertex(Vertex&&) = delete; // Non-movable
38 Vertex& operator=(Vertex&&) = delete; // Non-move-assignable
40 const size_t index; // Zero-based index allowing to access the vertex
43 const std::vector< size_t > loopIndices; // Container holding all loop indices (if any)
45 const Type type;
46 std::optional< std::pair<Vertex*, Vertex*> > parent; /// Parent vertices
47 std::vector< std::pair<const BPMN::SequenceFlow*, Vertex*> > inflows; /// Container holding vertices connecting by an incoming sequence flow, for loop activities the sequence flow may be a nullptr
48 std::vector< std::pair<const BPMN::SequenceFlow*, Vertex*> > outflows; /// Container holding vertices connecting by an outgoing sequence flow, for loop activities the sequence flow may be a nullptr
49 std::vector< Vertex* > predecessors; /// Container holding predecessors according to the execution logic (excl. sequence flows)
50 std::vector< Vertex* > successors; /// Container holding successors according to the execution logic (excl. sequence flows)
51 std::vector< Vertex* > senders; /// Container holding all possible vertices sending a message (or the message delivery notification for a SendTask)
52 std::vector< Vertex* > recipients; /// Container holding all possible vertices receiving a message (or the message delivery notification for a SendTask)
53 std::vector< Vertex* > dataOwners; /// Container holding all entry vertices of nodes owning at least one data attribute
54 const Vertex* performer() const ; /// Returns the entry vertex of the performer of a sequential activity vertex
55 size_t dataOwnerIndex( const BPMNOS::Model::Attribute* attribute ) const; /// Returns the index of the data owner of an attribute
56 std::pair<const Vertex*, const Vertex*> dataOwner( const BPMNOS::Model::Attribute* attribute ) const; /// Returns the vertices of the owner of a data attribute
57 std::string reference() const; /// Returns a unique reference of the vertex
58 std::string shortReference() const; /// Returns a reference of the vertex excluding the type
59 nlohmann::ordered_json jsonify() const;
60 template<typename T>
61 bool entry() const { return (type == Type::ENTRY) && node->represents<T>(); }
62 template<typename T>
63 bool exit() const { return (type == Type::EXIT) && node->represents<T>(); }
64 };
65
66 std::vector< const Vertex* > initialVertices; /// Container holding entry vertices of all process instances
67 std::vector< const Vertex* > sortVertices() const; /// Returns a topologically sorted vector of all vertices reachable from the initial vertices
68 std::vector< std::unique_ptr<Vertex> > vertices; /// Container holding entry and exit vertices of each possible instantiation of a node
69 std::unordered_set< const Vertex* > dummies; /// Container holding dummy vertices for loop & multi-instance activities
70
72 std::unordered_map< const BPMN::Node*, std::vector< const BPMNOS::Model::Attribute* > > loopIndexAttributes; // Container holding all attributes representing loop indices for a given node
73 tuple_map< std::tuple<BPMNOS::number, std::vector< size_t >, const BPMN::Node* >, std::pair<Vertex*, Vertex*> > vertexMap; /// Map holding entry and exit vertices of each possible instantiation of a node
74
76private:
77 void addNonInterruptingEventSubProcess( const BPMN::EventSubProcess* eventSubProcess, Vertex* parentEntry, Vertex* parentExit );
78 void addSender( const BPMN::MessageThrowEvent* messageThrowEvent, Vertex* senderEntry, Vertex* senderExit );
79 void addRecipient( const BPMN::MessageCatchEvent* messageCatchEvent, Vertex* recipientEntry, Vertex* recipientExit );
80
81 std::pair<Vertex*, Vertex*> createVertexPair(BPMNOS::number rootId, BPMNOS::number instanceId, std::vector< size_t > loopIndices, const BPMN::Node* node, std::optional< std::pair<Vertex*, Vertex*> > parent);
82 void createLoopVertices(BPMNOS::number rootId, BPMNOS::number instanceId, std::vector< size_t > loopIndices, const BPMN::Activity* node, std::optional< std::pair<Vertex*, Vertex*> > parent);
83 void flatten(BPMNOS::number instanceId, const BPMN::Scope* scope, Vertex* scopeEntry, Vertex* scopeExit);
84
85 std::vector< std::tuple<const BPMN::EventSubProcess*, Vertex*, Vertex*, unsigned int, Vertex*> > nonInterruptingEventSubProcesses;
86 std::unordered_map<const BPMN::FlowNode*, std::vector< std::pair<Vertex*, Vertex*> > > sendingVertices;
87 std::unordered_map<const BPMN::FlowNode*, std::vector< std::pair<Vertex*, Vertex*> > > receivingVertices;
88
89public:
90 std::unordered_map<const Vertex*, std::vector< std::pair<const Vertex*, const Vertex*> > > sequentialActivities; /// Container allowing to look up vertices of sequential activities given a pointer to the entry vertex of a performer
91 std::unordered_map<const Vertex*, std::vector< std::pair<const Vertex*, const Vertex*> > > dataModifiers; /// Container allowing to look up vertices of tasks modifying data attributes given a pointer to the entry vertex of the node owning the data
92 std::vector< std::pair<const Vertex*, const Vertex*> > globalModifiers; /// Container holding vertices of tasks modifying global attributes
93 bool modifiesData(const Vertex* vertex, const Vertex* dataOwner) const; /// Method returning true if the vertex modifies a data attribute of the given owner
94 bool modifiesGlobals(const Vertex* vertex) const; /// Method returning true if the vertex modifies a global attribute
95
96 const Vertex* getVertex( const Token* token ) const;
97
98 const Vertex* entry(const Vertex* vertex) const;
99 const Vertex* exit(const Vertex* vertex) const;
100};
101
102} // namespace BPMNOS::Execution
103
104#endif // BPMNOS_Execution_FlattenedGraph_H
std::pair< const Vertex *, const Vertex * > dataOwner(const BPMNOS::Model::Attribute *attribute) const
Returns the index of the data owner of an attribute.
std::vector< std::pair< const BPMN::SequenceFlow *, Vertex * > > outflows
Container holding vertices connecting by an incoming sequence flow, for loop activities the sequence ...
std::vector< Vertex * > senders
Container holding successors according to the execution logic (excl. sequence flows)
std::vector< Vertex * > successors
Container holding predecessors according to the execution logic (excl. sequence flows)
nlohmann::ordered_json jsonify() const
Returns a reference of the vertex excluding the type.
std::vector< std::pair< const BPMN::SequenceFlow *, Vertex * > > inflows
Parent vertices.
Vertex & operator=(Vertex &&)=delete
Vertex & operator=(const Vertex &)=delete
size_t dataOwnerIndex(const BPMNOS::Model::Attribute *attribute) const
Returns the entry vertex of the performer of a sequential activity vertex.
std::string shortReference() const
Returns a unique reference of the vertex.
std::vector< Vertex * > predecessors
Container holding vertices connecting by an outgoing sequence flow, for loop activities the sequence ...
const Vertex * performer() const
Container holding all entry vertices of nodes owning at least one data attribute.
std::optional< std::pair< Vertex *, Vertex * > > parent
std::vector< Vertex * > recipients
Container holding all possible vertices sending a message (or the message delivery notification for a...
const std::vector< size_t > loopIndices
std::vector< Vertex * > dataOwners
Container holding all possible vertices receiving a message (or the message delivery notification for...
std::string reference() const
Returns the vertices of the owner of a data attribute.
Represents a graph containing all BPMN nodes that may receive a token during execution of a scenario.
void addInstance(const BPMNOS::Model::Scenario::InstanceData *instance)
Map holding entry and exit vertices of each possible instantiation of a node.
nlohmann::ordered_json jsonify() const
std::unordered_set< const Vertex * > dummies
Container holding entry and exit vertices of each possible instantiation of a node.
const Vertex * getVertex(const Token *token) const
Method returning true if the vertex modifies a global attribute.
const BPMNOS::Model::Attribute * getLoopIndexAttribute(const BPMN::Activity *activity) const
Container holding dummy vertices for loop & multi-instance activities.
const BPMNOS::Model::Scenario * scenario
const Vertex * exit(const Vertex *vertex) const
std::vector< const Vertex * > sortVertices() const
Container holding entry vertices of all process instances.
const Vertex * entry(const Vertex *vertex) const
std::vector< std::pair< const Vertex *, const Vertex * > > globalModifiers
Container allowing to look up vertices of tasks modifying data attributes given a pointer to the entr...
std::vector< const Vertex * > initialVertices
std::unordered_map< const Vertex *, std::vector< std::pair< const Vertex *, const Vertex * > > > sequentialActivities
tuple_map< std::tuple< BPMNOS::number, std::vector< size_t >, const BPMN::Node * >, std::pair< Vertex *, Vertex * > > vertexMap
bool modifiesGlobals(const Vertex *vertex) const
Method returning true if the vertex modifies a data attribute of the given owner.
std::unordered_map< const Vertex *, std::vector< std::pair< const Vertex *, const Vertex * > > > dataModifiers
Container allowing to look up vertices of sequential activities given a pointer to the entry vertex o...
std::unordered_map< const BPMN::Node *, std::vector< const BPMNOS::Model::Attribute * > > loopIndexAttributes
bool modifiesData(const Vertex *vertex, const Vertex *dataOwner) const
Container holding vertices of tasks modifying global attributes.
std::vector< std::unique_ptr< Vertex > > vertices
Returns a topologically sorted vector of all vertices reachable from the initial vertices.
FlattenedGraph(const BPMNOS::Model::Scenario *scenario)
Represents a token running through a (sub)process.
Definition Token.h:35
Abstract base class for scenarios holding data for all BPMN instances.
Definition Scenario.h:21
Wrapper class around std::unordered_map for maps with tuple keys.
Definition tuple_map.h:35
T * represents()
Attempts to cast the element to the specified type T.
Definition bpmn++.h:16236
Base class for all nodes in a BPMN model.
Definition bpmn++.h:16444
Base class for BPMN elements that may contain a ChildNode elements.
Definition bpmn++.h:16510
BPMNOS_NUMBER_TYPE number
Definition Number.h:50