BPMN-OS
BPMN for optimization and simulation
Loading...
Searching...
No Matches
ChoiceDecision.cpp
Go to the documentation of this file.
1#include "ChoiceDecision.h"
4
5using namespace BPMNOS::Execution;
6
7ChoiceDecision::ChoiceDecision(const Token* token, Values choices, Evaluator* evaluator)
8 : Event(token)
9 , ChoiceEvent(token, choices)
10 , Decision(evaluator)
11{
13}
14
15std::optional<double> ChoiceDecision::evaluate() {
17 return evaluation;
18}
19
20nlohmann::ordered_json ChoiceDecision::jsonify() const {
21 nlohmann::ordered_json jsonObject;
22
23
24 jsonObject["decision"] = "choice";
25 jsonObject["processId"] = token->owner->process->id;
26 jsonObject["instanceId"] = BPMNOS::to_string((*token->data)[BPMNOS::Model::ExtensionElements::Index::Instance].get().value(),STRING);
27 jsonObject["nodeId"] = token->node->id;
28
29 jsonObject["choices"] = nlohmann::ordered_json();
30 auto extensionElements = token->node->extensionElements->as<BPMNOS::Model::ExtensionElements>();
31 for (size_t i = 0; i < extensionElements->choices.size(); i++) {
32 auto attribute = extensionElements->choices[i]->attribute;
33 if ( !choices[i].has_value() ) {
34 jsonObject["choices"][attribute->name] = nullptr ;
35 }
36 else if ( attribute->type == BOOLEAN) {
37 bool value = (bool)choices[i].value();
38 jsonObject["choices"][attribute->name] = value ;
39 }
40 else if ( attribute->type == INTEGER) {
41 int value = (int)choices[i].value();
42 jsonObject["choices"][attribute->name] = value ;
43 }
44 else if ( attribute->type == DECIMAL) {
45 double value = (double)choices[i].value();
46 jsonObject["choices"][attribute->name] = value ;
47 }
48 else if ( attribute->type == STRING) {
49 std::string value = BPMNOS::to_string(choices[i].value(),attribute->type);
50 jsonObject["choices"][attribute->name] = value ;
51 }
52 else if ( attribute->type == COLLECTION) {
53 std::string value = BPMNOS::to_string(choices[i].value(),attribute->type);
54 jsonObject["choices"][attribute->name] = value ;
55 }
56 }
57
58 if ( evaluation.has_value() ) {
59 jsonObject["evaluation"] = (double)evaluation.value();
60 }
61
62 return jsonObject;
63}
Represents an abstract base class for a pending decision.
Definition Decision.h:15
std::optional< double > evaluation
Latest evaluation or null if decision has not been evaluated or evaluation is no longer valid.
Definition Decision.h:20
void determineDependencies(const std::set< const BPMNOS::Model::Attribute * > &dependencies)
Definition Decision.cpp:12
Represents an abstract base class for a pending Evaluator.
Definition Evaluator.h:15
virtual std::optional< double > evaluate(EntryDecision *decision)=0
virtual std::set< const BPMNOS::Model::Attribute * > getDependencies(EntryDecision *decision)=0
const BPMN::Process * process
Pointer to the top-level process.
Represents a token running through a (sub)process.
Definition Token.h:35
const BPMN::FlowNode * node
Definition Token.h:46
const StateMachine * owner
State machine owning the token.
Definition Token.h:44
SharedValues * data
Pointer to the data of the owner or owned state machine subprocesses)
Definition Token.h:58
Class holding extension elements representing execution data for nodes.
std::unique_ptr< ExtensionElements > extensionElements
Definition bpmn++.h:16299
std::string id
Id of element.
Definition bpmn++.h:16298
std::string to_string(number numericValue, const ValueType &type)
Converts a number to a string.
Definition Number.cpp:150
@ INTEGER
Definition Value.h:9
@ STRING
Definition Value.h:9
@ BOOLEAN
Definition Value.h:9
@ COLLECTION
Definition Value.h:9
@ DECIMAL
Definition Value.h:9
nlohmann::ordered_json jsonify() const override
std::optional< double > evaluate() override
Evaluates the reward for the decision. Returns null if decision is infeasible.
ChoiceDecision(const Token *token, Values choices, Evaluator *evaluator)
Represents the event that choices are made for a DecisionTask.
Definition ChoiceEvent.h:15
const Token * token
Definition Event.h:18