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 inbox.clear();
19/*
20 tokensAwaitingBoundaryEvent.clear();
21 tokenAtAssociatedActivity.clear();
22 tokensAwaitingStateMachineCompletion.clear();
23 tokensAwaitingGatewayActivation.clear();
24 tokensAwaitingJobEntryEvent.clear();
25*/
26}
27
31
33 if ( !scenario->isCompleted(getTime()) ) {
34 return true;
35 }
36 return !instances.empty();
37};
38
40 auto result = contributionsToObjective;
41
42 for ( auto& attribute : scenario->getModel()->attributes ) {
43 assert( attribute->category == BPMNOS::Model::Attribute::Category::GLOBAL );
44 auto value = globals[attribute->index];
45 if ( value.has_value() ) {
46 result += attribute->weight * value.value();
47 }
48 }
49
50 return result;
51}
52
53std::vector< std::tuple<const BPMN::Process*, BPMNOS::Values, BPMNOS::Values> > SystemState::getInstantiations() const {
55}
56
57std::optional<BPMNOS::Values> SystemState::getStatusAttributes(const StateMachine* root, const BPMN::Node* node) const {
58 return scenario->getKnownValues(root->instance.value(), node, currentTime);
59}
60
61std::optional<BPMNOS::Values> SystemState::getDataAttributes(const StateMachine* root, const BPMN::Node* node) const {
62 return scenario->getKnownData(root->instance.value(), node, currentTime);
63}
64
65void SystemState::incrementTimeBy(BPMNOS::number duration) {
66 currentTime += duration;
67}
68
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 current time.
BPMNOS::number contributionsToObjective
All contributions that have already been added to the objective.
Definition SystemState.h:64
std::unordered_map< StateMachine *, auto_list< std::weak_ptr< Message > > > inbox
Map holding the undelivered correspondence associated with a state machine which will be withdrawn wh...
Definition SystemState.h:87
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...
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
Abstract base class for scenarios holding data for all BPMN instances.
Definition Scenario.h:21
virtual std::optional< BPMNOS::Values > getKnownValues(const BPMNOS::number instanceId, const BPMN::Node *node, const BPMNOS::number currentTime) const =0
Method returning all known values of new attributes.
const Model * getModel() const
Method returning the model.
Definition Scenario.h:37
virtual bool isCompleted(const BPMNOS::number currentTime) const =0
Method returning true if the currentTime exceeds the completion time.
virtual std::vector< std::tuple< const BPMN::Process *, BPMNOS::Values, BPMNOS::Values > > getCurrentInstantiations(const BPMNOS::number currentTime) const =0
Method returning a vector of all instances that are known to be instantiated at the given time.
virtual std::optional< BPMNOS::Values > getKnownData(const BPMNOS::number instanceId, const BPMN::Node *node, const BPMNOS::number currentTime) const =0
Method returning all known values of new attributes.
Base class for all nodes in a BPMN model.
Definition bpmn++.h:16444
BPMNOS_NUMBER_TYPE number
Definition Number.h:50