BPMN-OS
BPMN for optimization and simulation
Loading...
Searching...
No Matches
GreedyController.cpp
Go to the documentation of this file.
1#include "GreedyController.h"
2//#include "dispatcher/greedy/BestFirstParallelEntry.h"
3//#include "dispatcher/greedy/BestFirstSequentialEntry.h"
8#include <iostream>
9
10using namespace BPMNOS::Execution;
11
13 : evaluator(evaluator)
14{
15 // add event dispatcher
16 eventDispatchers.push_back( std::make_unique<BestFirstEntry>(evaluator) );
17 eventDispatchers.push_back( std::make_unique<BestFirstExit>(evaluator) );
18 eventDispatchers.push_back( std::make_unique<BestLimitedChoice>(evaluator) );
19 eventDispatchers.push_back( std::make_unique<BestMatchingMessageDelivery>(evaluator) );
20}
21
23 for ( auto& eventDispatcher : eventDispatchers ) {
24 eventDispatcher->connect(this);
25 }
26 Controller::connect(mediator);
27}
28
29std::shared_ptr<Event> GreedyController::dispatchEvent(const SystemState* systemState) {
30 std::shared_ptr<Decision> best = nullptr;
31 for ( auto& eventDispatcher : eventDispatchers ) {
32 if ( auto event = eventDispatcher->dispatchEvent(systemState) ) {
33 if ( auto decision = dynamic_pointer_cast<Decision>(event) ) {
34 if ( decision->evaluation.has_value() ) {
35 if ( !best ) {
36 // first feasible decision is used as best
37 best = decision;
38 }
39 else if ( decision->evaluation.value() < best->evaluation.value() ) {
40 // decision has less costly evaluation than current best
41 best = decision;
42 }
43 }
44 }
45 else {
46 // events are immediately forwarded
47//std::cerr << "\nEvent " << event->jsonify() << " without evaluation" << std::endl;
48 return event;
49 }
50 }
51 }
52
53//if ( best ) std::cerr << "\nGreedyController: Best decision " << best->jsonify() << " evaluated with " << best->evaluation.value_or(-999) << std::endl;
54
55 return best;
56}
virtual void connect(Mediator *mediator)
Definition Controller.cpp:9
Represents an abstract base class for a pending Evaluator.
Definition Evaluator.h:15
std::vector< std::unique_ptr< EventDispatcher > > eventDispatchers
std::shared_ptr< Event > dispatchEvent(const SystemState *systemState)
A class representing the state that the execution or simulation of a given scenario is in.
Definition SystemState.h:21
Represents an abstract base class for a class that is an event listener and notifier.
Definition Mediator.h:13