BPMN-OS
BPMN for optimization and simulation
Loading...
Searching...
No Matches
CPSolutionObserver.h
Go to the documentation of this file.
1#ifndef BPMNOS_Execution_CPSolutionObserver_H
2#define BPMNOS_Execution_CPSolutionObserver_H
3
4#ifdef USE_CP
5
6#include <bpmn++.h>
16#include <unordered_map>
17#include <utility>
18#include <memory>
19
20
21namespace BPMNOS::Execution {
22
23/**
24 * @brief An observer creating a solution of a constraint program matching process execution
25 */
26class CPSolutionObserver : public Observer {
27public:
28 using Vertex = FlattenedGraph::Vertex;
29
30 CPSolutionObserver(const CPModel* cp);
31 void notice(const Observable* observable) override;
32 void subscribe(Engine* engine);
33 void unsubscribe(Engine* engine);
34 void synchronize(const Token* token);
35 void synchronize(const Event* event);
36 const CPModel* cp;
37 const FlattenedGraph* flattenedGraph;
38 CP::Solution _solution;
39 size_t lastPosition;
40 const CP::Model& getModel() const { return cp->getModel(); }
41 const CP::Solution& getSolution() const { return _solution; }
42
43 void unvisitEntry(const Vertex* vertex);
44 void unvisitExit(const Vertex* vertex);
45
46 void synchronizeStatus(const BPMNOS::Values& status, const Vertex* vertex);
47 void synchronizeData(const BPMNOS::SharedValues& data, const Vertex* vertex);
48 void synchronizeGlobals(const BPMNOS::Values& globals, const Vertex* vertex);
49
50 std::vector<size_t> getSequence() const; /// Method providing the vertex sequence in the solution
51 size_t getPosition(const Vertex* vertex) const;
52 void initializePositions(const std::vector<double>& positions);
53 void setPosition(const Vertex* vertex, size_t position);
54 void finalizePosition(const Vertex* vertex);
55 void finalizeUnvisitedSubsequentPositions(const Vertex* vertex);
56
57 bool isVisited(const Vertex* vertex) const;
58 bool isUnvisited(const Vertex* vertex) const;
59
60 void setTriggeredEvent( const Vertex* gateway, const Vertex* event );
61 void setMessageDeliveryVariableValues( const Vertex* sender, const Vertex* recipient, BPMNOS::number timestamp );
62 bool messageFlows( const Vertex* sender, const Vertex* recipient );
63
64 std::optional< BPMN::Activity::LoopCharacteristics > getLoopCharacteristics(const Vertex* vertex) const;
65 std::optional< BPMNOS::number > getTimestamp( const Vertex* vertex ) const;
66 void setTimestamp( const Vertex* vertex, BPMNOS::number timestamp );
67 std::optional< BPMNOS::number > getStatusValue( const Vertex* vertex, size_t attributeIndex ) const;
68 void setLocalStatusValue( const Vertex* vertex, size_t attributeIndex, BPMNOS::number value );
69 std::pair< CP::Expression, CP::Expression > getAttributeVariables( const Vertex* vertex, const Model::Attribute* attribute);
70
71public:
72 const Vertex* entry(const Vertex* vertex) const { return flattenedGraph->entry(vertex); };
73 const Vertex* exit(const Vertex* vertex) const { return flattenedGraph->exit(vertex); };
74 bool complete() const { return _solution.complete(); };
75 std::optional<double> getObjectiveValue() const { return _solution.getObjectiveValue(); };
76 std::string errors() const { return _solution.errors(); };
77 std::string stringify() const { return _solution.stringify(); };
78protected:
79 std::set<std::pair<const Vertex*, const Vertex*>> markedFlows; /// Set of flows that have been tracked and no longer need to be cosnidered
80};
81
82} // namespace BPMNOS::Execution
83
84#endif // USE_CP
85
86#endif // BPMNOS_Execution_CPSolutionObserver_H
87
BPMNOS_NUMBER_TYPE number
Definition Number.h:50