BPMN-OS
BPMN for optimization and simulation
Loading...
Searching...
No Matches
SystemState.cpp
Go to the documentation of this file.
1#include "SystemState.h"
2#include "Engine.h"
4
5using namespace BPMNOS::Execution;
6
7SystemState::SystemState(const Engine* engine, const BPMNOS::Model::Scenario* scenario, BPMNOS::number currentTime)
8 : engine(engine)
9 , scenario(scenario)
10 , currentTime(currentTime)
11 , contributionsToObjective(0)
12 , globals(scenario->globals)
13{
14}
15
17//std::cerr << "~SystemState()" << std::endl;
18/*
19 tokensAwaitingBoundaryEvent.clear();
20 tokenAtAssociatedActivity.clear();
21 tokensAwaitingStateMachineCompletion.clear();
22 tokensAwaitingGatewayActivation.clear();
23 tokensAwaitingJobEntryEvent.clear();
24*/
25}
26
30
32 if ( !scenario->isCompleted(getTime()) ) {
33 return true;
34 }
35 return !instances.empty();
36};
37
39 auto result = contributionsToObjective;
40
41 for ( auto& attribute : scenario->getModel()->attributes ) {
42 assert( attribute->category == BPMNOS::Model::Attribute::Category::GLOBAL );
43 auto value = globals[attribute->index];
44 if ( value.has_value() ) {
45 result += attribute->weight * value.value();
46 }
47 }
48
49 return result;
50}
51
52std::vector< std::tuple<const BPMN::Process*, BPMNOS::Values, BPMNOS::Values> > SystemState::getInstantiations() const {
53 if ( assumedTime ) {
55 }
56 else {
58 }
59}
60
61std::optional<BPMNOS::Values> SystemState::getStatusAttributes(const StateMachine* root, const BPMN::Node* node) const {
62 if ( assumedTime ) {
63 return scenario->getAnticipatedValues(root->instance.value(), node, currentTime);
64 }
65 else {
66 auto knownValues = scenario->getKnownValues(root->instance.value(), node, currentTime);
67 if ( knownValues ) {
68 return std::move( knownValues.value() );
69 }
70 }
71 return std::nullopt;
72}
73
74std::optional<BPMNOS::Values> SystemState::getDataAttributes(const StateMachine* root, const BPMN::Node* node) const {
75 if ( assumedTime ) {
76 return scenario->getAnticipatedData(root->instance.value(), node, currentTime);
77 }
78 else {
79 auto knownData = scenario->getKnownData(root->instance.value(), node, currentTime);
80 if ( knownData ) {
81 return std::move( knownData.value() );
82 }
83 }
84 return std::nullopt;
85}
86
87void SystemState::incrementTimeBy(BPMNOS::number duration) {
88 if ( assumedTime ) {
89 assumedTime = assumedTime.value() + duration;
90 }
91 else {
92 currentTime += duration;
93 }
94}
95
Represents a state machine for BPMN execution of a scope in the model.
std::optional< BPMNOS::number > instance
Numeric representation of instance id (TODO: can we const this?)
StateMachines instances
Container holding a state machine for each running instance.
BPMNOS::number currentTime
Timestamp holding the point in time that the engine is in (this is usually representing now).
Definition SystemState.h:37
std::optional< BPMNOS::Values > getStatusAttributes(const StateMachine *root, const BPMN::Node *node) const
BPMNOS::number getTime() const
Function returning the assumed time time if available or the current time otherwise.
BPMNOS::number contributionsToObjective
All contributions that have already been added to the objective.
Definition SystemState.h:69
const BPMNOS::Model::Scenario * scenario
Pointer to the corresponding scenario.
Definition SystemState.h:32
std::optional< BPMNOS::Values > getDataAttributes(const StateMachine *root, const BPMN::Node *node) const
bool isAlive() const
Function returning true if there are tokens in the system or if there may be new instantiations of to...
std::optional< BPMNOS::number > assumedTime
Timestamp holding the point in time that the simulation is in (this could be a future point in time).
Definition SystemState.h:42
BPMNOS::number getObjective() const
Returns the total objective value (assuming maximization) accumulated during execution.
std::vector< std::tuple< const BPMN::Process *, BPMNOS::Values, BPMNOS::Values > > getInstantiations() const
Method returning a vector of all instantiations at the given time.
std::vector< std::unique_ptr< Attribute > > attributes
Vector containing new global attributes declared for the model.
Definition Model.h:70
The Scenario class holds data for all BPMN instances.
Definition Scenario.h:20
std::vector< std::tuple< const BPMN::Process *, BPMNOS::Values, BPMNOS::Values > > getCurrentInstantiations(const BPMNOS::number currentTime) const
Method returning a vector of all instances that are known to be instantiated at the given time.
Definition Scenario.cpp:129
std::optional< BPMNOS::Values > getKnownData(const BPMNOS::number instanceId, const BPMN::Node *node, const BPMNOS::number currentTime) const
Method returning all known values of new attributes.
Definition Scenario.cpp:231
bool isCompleted(const BPMNOS::number currentTime) const
Method returning true if the currentTime exceeds the completion time.
Definition Scenario.cpp:78
const Model * getModel() const
Definition Scenario.cpp:70
std::optional< BPMNOS::Values > getKnownValues(const BPMNOS::number instanceId, const BPMN::Node *node, const BPMNOS::number currentTime) const
Method returning all known values of new attributes.
Definition Scenario.cpp:218
std::vector< std::tuple< const BPMN::Process *, BPMNOS::Values, BPMNOS::Values > > getAnticipatedInstantiations(const BPMNOS::number currentTime, const BPMNOS::number assumedTime) const
Method returning a vector of all instances that are anticipated to be instantiated at the assumed tim...
Definition Scenario.cpp:143
BPMNOS::Values getAnticipatedData(const BPMNOS::number instanceId, const BPMN::Node *node, const BPMNOS::number currentTime) const
Method returning the disclosed values of new attributes.
Definition Scenario.cpp:294
BPMNOS::Values getAnticipatedValues(const BPMNOS::number instanceId, const BPMN::Node *node, const BPMNOS::number currentTime) const
Method returning the disclosed values of new attributes.
Definition Scenario.cpp:282
Base class for all nodes in a BPMN model.
Definition bpmn++.h:16444
BPMNOS_NUMBER_TYPE number
Definition Number.h:42