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 <deque>
6#include <vector>
7#include <list>
8#include <string>
9#include <bpmn++.h>
11
12namespace BPMNOS::Execution {
13
14/**
15 * @brief Represents a graph containing all BPMN nodes that may receive a token during execution of a scenario.
16 *
17 * 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.
18 */
20public:
23
24 class Vertex {
25 public:
26 enum class Type { ENTRY, EXIT };
27 Vertex(size_t index, BPMNOS::number rootId, BPMNOS::number instanceId, const BPMN::Node* node, Type type, std::optional< std::pair<Vertex&, Vertex&> > parent);
28 // Delete other constructors and assignment operators
29 Vertex() = delete; // Prevents default construction
30 Vertex(const Vertex&) = delete; // Non-copyable
31 Vertex& operator=(const Vertex&) = delete; // Non-copy-assignable
32 Vertex(Vertex&&) = delete; // Non-movable
33 Vertex& operator=(Vertex&&) = delete; // Non-move-assignable
34 const size_t index;
38 const Type type;
39 std::optional< std::pair<Vertex&, Vertex&> > parent; /// Parent vertices
40 std::vector< std::pair<const BPMN::SequenceFlow*, Vertex&> > inflows; /// Container holding vertices connecting by an incoming sequence flow
41 std::vector< std::pair<const BPMN::SequenceFlow*, Vertex&> > outflows; /// Container holding vertices connecting by an outgoing sequence flow
42 std::vector< std::reference_wrapper<Vertex> > predecessors; /// Container holding predecessors according to the execution logic (excl. sequence flows)
43 std::vector< std::reference_wrapper<Vertex> > successors; /// Container holding successors according to the execution logic (excl. sequence flows)
44 std::vector< std::reference_wrapper<Vertex> > senders; /// Container holding all possible vertices sending a message (or the message delivery notfication for a SendTask)
45 std::vector< std::reference_wrapper<Vertex> > recipients; /// Container holding all possible vertices receiving a message (or the message delivery notfication for a SendTask)
46 std::vector< std::reference_wrapper<Vertex> > dataOwners; /// Container holding all entry vertices of nodes owning at least one data attribute
47// std::pair<const Vertex&, const Vertex&> parent() const; /// Returns the vertices of the parent
48 std::pair<const Vertex&, const Vertex&> performer() const ; /// Returns the vertices of the performer of a sequential activity vertex
49 std::pair<const Vertex&, const Vertex&> dataOwner( const BPMNOS::Model::Attribute* attribute ) const; /// Returns the vertices of the owner of a data attribute
50 std::string reference() const; /// Returns a unique reference of the vertex
51 template<typename T>
52 bool entry() const { return (type == Type::ENTRY) && node->represents<T>(); }
53 template<typename T>
54 bool exit() const { return (type == Type::EXIT) && node->represents<T>(); }
55 };
56
57 std::vector< std::reference_wrapper<Vertex> > initialVertices; /// Container holding entry vertices of all process instances
58 std::deque< Vertex > vertices; /// Container holding entry and exit vertices of each possible instantiation of a node
59 std::unordered_map< const BPMN::Node*, std::unordered_map< BPMNOS::number, std::vector< std::reference_wrapper<Vertex> > > > vertexMap; /// Map holding entry and exit vertices of each possible instantiation of a node
60
62private:
63 void addNonInterruptingEventSubProcess( const BPMN::EventSubProcess* eventSubProcess, Vertex& parentEntry, Vertex& parentExit );
64 void addSender( const BPMN::MessageThrowEvent* messageThrowEvent, Vertex& senderEntry, Vertex& senderExit );
65 void addRecipient( const BPMN::MessageCatchEvent* messageCatchEvent, Vertex& recipientEntry, Vertex& recipientExit );
66
67 std::pair<Vertex&, Vertex&> createVertexPair(BPMNOS::number rootId, BPMNOS::number instanceId, const BPMN::Node* node, std::optional< std::pair<Vertex&, Vertex&> > parent);
68 void createLoopVertices(BPMNOS::number rootId, BPMNOS::number instanceId, const BPMN::Activity* node, std::optional< std::pair<Vertex&, Vertex&> > parent);
69 void flatten(BPMNOS::number instanceId, const BPMN::Scope* scope, Vertex& scopeEntry, Vertex& scopeExit);
70
71 std::vector< std::tuple<const BPMN::EventSubProcess*, Vertex&, Vertex&, unsigned int, Vertex*> > nonInterruptingEventSubProcesses;
72 std::unordered_map<const BPMN::FlowNode*, std::vector< std::pair<Vertex&, Vertex&> > > sendingVertices;
73 std::unordered_map<const BPMN::FlowNode*, std::vector< std::pair<Vertex&, Vertex&> > > receivingVertices;
74
75public:
76 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
77 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
78 std::vector< std::pair<const Vertex&, const Vertex&> > globalModifiers; /// Container holding vertices of tasks modifying global attributes
79};
80
81} // namespace BPMNOS::Execution
82
83#endif // BPMNOS_Execution_FlattenedGraph_H
std::pair< const Vertex &, 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< std::pair< const BPMN::SequenceFlow *, Vertex & > > inflows
Parent vertices.
std::vector< std::reference_wrapper< Vertex > > successors
Container holding predecessors according to the execution logic (excl. sequence flows)
std::vector< std::reference_wrapper< Vertex > > recipients
Container holding all possible vertices sending a message (or the message delivery notfication for a ...
std::vector< std::reference_wrapper< Vertex > > dataOwners
Container holding all possible vertices receiving a message (or the message delivery notfication for ...
Vertex & operator=(Vertex &&)=delete
Vertex & operator=(const Vertex &)=delete
bool entry() const
Returns a unique reference of the vertex.
std::pair< const Vertex &, const Vertex & > dataOwner(const BPMNOS::Model::Attribute *attribute) const
Returns the vertices of the performer of a sequential activity vertex.
std::vector< std::pair< const BPMN::SequenceFlow *, Vertex & > > outflows
Container holding vertices connecting by an incoming sequence flow.
std::string reference() const
Returns the vertices of the owner of a data attribute.
std::vector< std::reference_wrapper< Vertex > > predecessors
Container holding vertices connecting by an outgoing sequence flow.
std::vector< std::reference_wrapper< Vertex > > senders
Container holding successors according to the execution logic (excl. sequence flows)
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.
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::deque< Vertex > vertices
Container holding entry vertices of all process instances.
std::unordered_map< const Vertex *, std::vector< std::pair< const Vertex &, const Vertex & > > > sequentialActivities
const BPMNOS::Model::Scenario * scenario
std::vector< std::reference_wrapper< Vertex > > initialVertices
std::unordered_map< const BPMN::Node *, std::unordered_map< BPMNOS::number, std::vector< std::reference_wrapper< Vertex > > > > vertexMap
Container holding entry and exit vertices of each possible instantiation of a node.
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...
FlattenedGraph(const BPMNOS::Model::Scenario *scenario)
The Scenario class holds data for all BPMN instances.
Definition Scenario.h:20
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:42