BPMN-OS
BPMN for optimization and simulation
Loading...
Searching...
No Matches
SeededController.h
Go to the documentation of this file.
1#ifndef BPMNOS_Execution_SeededController_H
2#define BPMNOS_Execution_SeededController_H
3
4#include <bpmn++.h>
5#include "Controller.h"
6#include "Evaluator.h"
17#include <unordered_map>
18#include <utility>
19#include <memory>
20
21
22
23namespace BPMNOS::Execution {
24
25/**
26 * @brief A controller dispatching decisions in the order derived from a given seed
27 */
29public:
32
33 struct Config {
34 bool instantEntry = false;
35 bool instantExit = false;
36 };
37 static Config default_config() { return {}; } // Work around for compiler bug see: https://stackoverflow.com/questions/53408962/try-to-understand-compiler-error-message-default-member-initializer-required-be/75691051#75691051
39 bool setSeed(const std::vector<size_t> initialSeed);
40 void connect(Mediator* mediator);
41 void subscribe(Engine* engine);
42 void notice(const Observable* observable) override;
43 void synchronizeSolution(const Token* token);
44
45protected:
47 std::shared_ptr<TerminationEvent> terminationEvent;
48 std::shared_ptr<Event> dispatchEvent(const SystemState* systemState);
50public:
52protected:
53 std::vector<size_t> seed;
54 std::unordered_map< const Vertex*, const Vertex* > performing; /// Map holding the entry vertex of a sequential activity performed by a sequential performer
55
56 struct pair_hash {
57 template <class T1, class T2>
58 std::size_t operator () (const std::pair<T1,T2> &p) const {
59 auto h1 = std::hash<T1>{}(p.first);
60 auto h2 = std::hash<T2>{}(p.second);
61 // Mainly for demonstration purposes, i.e. works but is overly simple
62 // In the real world, use sth. like boost.hash_combine
63 // return h1 ^ h2;
64 // return h1 * 31 + h2; // Prime multiplication
65 return h1 ^ (h2 * 2654435761u); // Uses a large prime for better distribution
66 }
67 };
68
69
70 std::list< const Vertex* > pendingVertices; /// The list of vertices to be processed
71 std::list< const Vertex* > processedVertices; /// The list of vertices already processed
72 bool hasPendingPredecessor(const Vertex* vertex) const;
73 bool hasPendingRecipient(const Vertex* vertex) const;
74 void finalizePredecessorPositions(const Vertex* vertex);
75 void fetchPendingPredecessors(std::unordered_set<const Vertex*>& predecessors, const Vertex* vertex) const;
76 std::list< const Vertex* >::iterator finalizeVertexPosition(const Vertex* vertex); /// Method finalizing the sequence position of a pending vertex and removing it from the list
77 std::list< const Vertex* >::iterator finalizeUnvisited(const Vertex* vertex);
78 void finalizeUnvisitedChildren(const Vertex* vertex);
79 std::list< const Vertex* >::iterator finalizeUnvisitedTypedStartEvents(std::list< const Vertex* >::iterator it); /// Method finalizing the sequence position of a unvisited vertices belonging to typed start events
80 bool withdrawableEntry(const BPMN::Node* node) const; /// Method return true if a token entering a catch event node may be withdrawn
81public:
82 std::vector<size_t> getSequence() const; /// Method providing the vertex sequence in the solution
83 size_t getProgress() const; /// Method returning the number of processed vertices
84 void initializePendingVertices(); /// Method creating an initial sequence of vertices
85
86 virtual std::shared_ptr<Event> createEntryEvent(const SystemState* systemState, const Token* token, const Vertex* vertex) = 0; /// Method creating a choice event
87 virtual std::shared_ptr<Event> createExitEvent(const SystemState* systemState, const Token* token, const Vertex* vertex) = 0; /// Method creating a choice event
88 virtual std::shared_ptr<Event> createChoiceEvent(const SystemState* systemState, const Token* token, const Vertex* vertex) = 0; /// Method creating a choice event
89 virtual std::shared_ptr<Event> createMessageDeliveryEvent(const SystemState* systemState, const Token* token, const Vertex* vertex) = 0; /// Method creating a message delivery event
90public:
91 const Vertex* entry(const Vertex* vertex) const { return flattenedGraph->entry(vertex); };
92 const Vertex* exit(const Vertex* vertex) const { return flattenedGraph->exit(vertex); };
93};
94
95} // namespace BPMNOS::Execution
96
97#endif // BPMNOS_Execution_SeededController_H
98
Base class for an execution controller which dispatches events to the engine and listens to notificat...
Definition Controller.h:15
Represents an abstract base class for an evaluator determining feasibility and reward of a decision.
Definition Evaluator.h:15
Represents a graph containing all BPMN nodes that may receive a token during execution of a scenario.
const Vertex * exit(const Vertex *vertex) const
const Vertex * entry(const Vertex *vertex) const
A controller dispatching decisions in the order derived from a given seed.
std::list< constVertex * >::iterator finalizeUnvisitedTypedStartEvents(std::list< const Vertex * >::iterator it)
bool withdrawableEntry(const BPMN::Node *node) const
Method finalizing the sequence position of a unvisited vertices belonging to typed start events.
void synchronizeSolution(const Token *token)
const FlattenedGraph * flattenedGraph
const Vertex * entry(const Vertex *vertex) const
Method creating a message delivery event.
virtual std::shared_ptr< Event > createChoiceEvent(const SystemState *systemState, const Token *token, const Vertex *vertex)=0
Method creating a choice event.
virtual std::shared_ptr< Event > createExitEvent(const SystemState *systemState, const Token *token, const Vertex *vertex)=0
Method creating a choice event.
void finalizePredecessorPositions(const Vertex *vertex)
std::list< const Vertex * > pendingVertices
void initializePendingVertices()
Method returning the number of processed vertices.
void fetchPendingPredecessors(std::unordered_set< const Vertex * > &predecessors, const Vertex *vertex) const
bool setSeed(const std::vector< size_t > initialSeed)
size_t getProgress() const
Method providing the vertex sequence in the solution.
void notice(const Observable *observable) override
std::unordered_map< const Vertex *, const Vertex * > performing
std::vector< size_t > getSequence() const
Method return true if a token entering a catch event node may be withdrawn.
std::shared_ptr< Event > dispatchEvent(const SystemState *systemState)
virtual std::shared_ptr< Event > createEntryEvent(const SystemState *systemState, const Token *token, const Vertex *vertex)=0
Method creating an initial sequence of vertices.
bool hasPendingRecipient(const Vertex *vertex) const
std::shared_ptr< TerminationEvent > terminationEvent
std::list< const Vertex * > processedVertices
The list of vertices to be processed.
const Vertex * exit(const Vertex *vertex) const
std::list< constVertex * >::iterator finalizeVertexPosition(const Vertex *vertex)
std::list< constVertex * >::iterator finalizeUnvisited(const Vertex *vertex)
Method finalizing the sequence position of a pending vertex and removing it from the list.
void finalizeUnvisitedChildren(const Vertex *vertex)
SeededController(const BPMNOS::Execution::FlattenedGraph *flattenedGraph, Config config=default_config())
virtual std::shared_ptr< Event > createMessageDeliveryEvent(const SystemState *systemState, const Token *token, const Vertex *vertex)=0
Method creating a choice event.
bool hasPendingPredecessor(const Vertex *vertex) const
The list of vertices already processed.
A class representing the state that the execution or simulation of a given scenario is in.
Definition SystemState.h:21
Represents a token running through a (sub)process.
Definition Token.h:35
Base class for all nodes in a BPMN model.
Definition bpmn++.h:16444
Represents an abstract base class for a class that is an event listener and notifier.
Definition Mediator.h:13
Map holding the entry vertex of a sequential activity performed by a sequential performer.
std::size_t operator()(const std::pair< T1, T2 > &p) const