BPMN-OS
BPMN for optimization and simulation
Loading...
Searching...
No Matches
BisectionalChoice.h
Go to the documentation of this file.
1#ifndef BPMNOS_Execution_BisectionalChoice_H
2#define BPMNOS_Execution_BisectionalChoice_H
3
4#include <bpmn++.h>
5#include <functional>
6#include <tuple>
12
13namespace BPMNOS::Execution {
14
15/**
16 * @brief Class creating a choice decision for a token at a decision task using bisection.
17 *
18 * The BisectionalChoice dispatcher uses bisection for attributes with bounds and a multipleOf
19 * discretizer. For attributes with explicit enumeration, enumeration is used.
20 */
21class BisectionalChoice : public GreedyDispatcher< std::weak_ptr<const Token>, std::weak_ptr<const DecisionRequest> > {
22public:
24 void connect(Mediator* mediator) override;
25 void notice(const Observable* observable) override;
26 std::shared_ptr<Event> dispatchEvent( const SystemState* systemState ) override;
27 std::shared_ptr<Decision> determineBestChoices(std::shared_ptr<const DecisionRequest> request);
28
29private:
30 BestEnumeratedChoice enumeratedChoice;
31 std::shared_ptr<Decision> discreteBisection(std::shared_ptr<const DecisionRequest> request, const BPMNOS::Model::Choice* choice);
32
33 // Helper types
34 struct Candidate {
35 size_t index;
36 std::shared_ptr<ChoiceDecision> decision;
37
38 bool isFeasible() const { return decision && decision->reward.has_value(); }
39 double reward() const { return decision->reward.value(); }
40 };
41
42 // State for current search (set by discreteBisection)
43 const Token* token;
44 std::vector<BPMNOS::number> values;
45 Candidate best;
46
47 // Helper methods for discreteBisection
48 Candidate evaluate(size_t index);
49
50 // Find any feasible solution using BFS, returns (leftInfeasible, candidate, rightInfeasible)
51 std::tuple<size_t, Candidate, size_t> findFeasible(size_t first, size_t last);
52
53 // Search functions for different boundary conditions
54 void findBetweenFeasibleAndFeasible(Candidate left, Candidate right);
55 void findBetweenFeasibleAndInfeasible(Candidate feasible, size_t infeasibleIndex);
56 void findBetweenInfeasibleAndFeasible(size_t infeasibleIndex, Candidate feasible);
57};
58
59} // namespace BPMNOS::Execution
60
61#endif // BPMNOS_Execution_BisectionalChoice_H
62
Class creating a choice decision for a token at a decision task.
Class creating a choice decision for a token at a decision task using bisection.
std::shared_ptr< Decision > determineBestChoices(std::shared_ptr< const DecisionRequest > request)
std::shared_ptr< Event > dispatchEvent(const SystemState *systemState) override
void notice(const Observable *observable) override
void connect(Mediator *mediator) override
Represents an abstract base class for an evaluator determining feasibility and reward of a decision.
Definition Evaluator.h:15
Class for dispatching the event with the best evaluation.
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
Class representing a choice to be made within a BPMNOS::Model::DecisionTask.
Definition Choice.h:21
Represents an abstract base class for a class that is an event listener and notifier.
Definition Mediator.h:13