15 , constraintProgramm(flattenedGraph)
19void CPController::setSolution(CP::Solution sol) {
20 solution = std::make_unique<CP::Solution>(std::move(sol));
21 if (&solution->model != &constraintProgramm.getModel()) {
22 throw std::invalid_argument(
"CPController: Solution model mismatch");
24 initializeFromSolution();
27void CPController::initializeFromSolution() {
29 std::vector<size_t> sequence(flattenedGraph->vertices.size());
30 for (
size_t i = 0; i < flattenedGraph->vertices.size(); i++) {
31 auto& vertex = flattenedGraph->vertices[i];
32 auto pos = solution->getVariableValue(
33 constraintProgramm.position.at(vertex.get())
35 sequence[(size_t)pos - 1] = i + 1;
40bool CPController::isVisited(
const Vertex* vertex)
const {
41 return solution->evaluate(
42 constraintProgramm.visit.at(vertex)
46BPMNOS::number CPController::getTimestamp(
const Vertex* vertex)
const {
47 auto result = solution->evaluate(
50 assert(result.has_value());
51 return result.value();
54void CPController::notice(
const Observable* observable) {
55 SeededController::notice(observable);
57 auto message =
static_cast<const Message*
>(observable);
58 if (message->state == Message::State::CREATED) {
61 auto& [senderEntry, senderExit] = flattenedGraph->vertexMap.at({senderId, {}, message->origin});
62 messages.emplace_back(message->weak_from_this(), senderEntry);
67std::shared_ptr<Event> CPController::createEntryEvent(
const SystemState* systemState, [[maybe_unused]]
const Token* token,
const Vertex* vertex) {
68 if (!isVisited(vertex)) {
69 throw std::runtime_error(
"CPController: Cannot enter unvisited vertex");
71 if (systemState->
getTime() < getTimestamp(vertex)) {
74 return std::make_shared<EntryEvent>(token);
77std::shared_ptr<Event> CPController::createExitEvent(
const SystemState* systemState,
const Token* token,
const Vertex* vertex) {
78 if (!isVisited(vertex)) {
79 throw std::runtime_error(
"CPController: Cannot exit unvisited vertex");
81 if (systemState->
getTime() < getTimestamp(vertex)) {
84 return std::make_shared<ExitEvent>(token);
87std::shared_ptr<Event> CPController::createChoiceEvent([[maybe_unused]]
const SystemState* systemState,
const Token* token,
const Vertex* vertex) {
88 if (!isVisited(vertex)) {
89 throw std::runtime_error(
"CPController: Cannot make choice for unvisited vertex");
95 std::vector<number> choices;
96 choices.reserve(extensionElements->choices.size());
98 auto& statusVars = constraintProgramm.status.at(vertex);
99 for (
auto& choice : extensionElements->choices) {
100 auto& attrVars = statusVars[choice->attribute->index];
101 auto value = solution->evaluate(attrVars.value);
102 assert(value.has_value());
103 choices.push_back(value.value());
106 return std::make_shared<ChoiceEvent>(token, std::move(choices));
109std::shared_ptr<Event> CPController::createMessageDeliveryEvent([[maybe_unused]]
const SystemState* systemState,
const Token* token,
const Vertex* vertex) {
110 if (!isVisited(vertex)) {
111 throw std::runtime_error(
"CPController: Cannot deliver message to unvisited vertex");
115 const Vertex* sender =
nullptr;
116 for (
auto candidate : vertex->senders) {
117 auto& messageFlowVar = constraintProgramm.messageFlow.at({candidate, vertex});
118 if (solution->evaluate(messageFlowVar).value_or(
false)) {
125 throw std::runtime_error(
"CPController: No sender found in solution for message delivery");
129 for (
auto& [message_ptr, senderVertex] : messages) {
130 if (
auto message = message_ptr.lock();
131 message && senderVertex == sender)
133 return std::make_shared<MessageDeliveryEvent>(token, message.get());
Represents a graph containing all BPMN nodes that may receive a token during execution of a scenario.
A controller dispatching decisions in the order derived from a given seed.
A class representing the state that the execution or simulation of a given scenario is in.
BPMNOS::number getTime() const
Function returning the current time.
Represents a token running through a (sub)process.
const BPMN::FlowNode * node
Class holding extension elements representing execution data for nodes.
std::unique_ptr< ExtensionElements > extensionElements
BPMNOS_NUMBER_TYPE number
virtual constexpr Type getObservableType() const =0
static constexpr size_t Timestamp