SOLA
Loading...
Searching...
No Matches
stn_task_management_components.h
1// Copyright 2023 The SOLA authors
2//
3// This file is part of DAISI.
4//
5// DAISI is free software: you can redistribute it and/or modify it under the terms of the GNU
6// General Public License as published by the Free Software Foundation; version 2.
7//
8// DAISI is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
9// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
10// Public License for more details.
11//
12// You should have received a copy of the GNU General Public License along with DAISI. If not, see
13// <https://www.gnu.org/licenses/>.
14//
15// SPDX-License-Identifier: GPL-2.0-only
16
17#ifndef DAISI_CPPS_LOGICAL_TASK_MANAGEMENT_STN_TASK_MANAGEMENT_COMPONENTS_H_
18#define DAISI_CPPS_LOGICAL_TASK_MANAGEMENT_STN_TASK_MANAGEMENT_COMPONENTS_H_
19
20#include <optional>
21#include <string>
22
23#include "material_flow/model/task.h"
24#include "metrics_composition.h"
25#include "utils/structure_helpers.h"
26
27namespace daisi::cpps::logical {
28
30 StnTaskManagementVertex(daisi::material_flow::Order order, bool is_start);
31
32 static StnTaskManagementVertex createOrigin();
33
34 const daisi::material_flow::Order &getOrder() const;
35 bool isStart() const;
36 bool isOrigin() const;
37
38 friend bool operator==(const StnTaskManagementVertex &v1, const StnTaskManagementVertex &v2);
39
40 void setLastPosition(const daisi::util::Position &position);
41
42 const daisi::util::Position &getLastPosition() const;
43
44 Metrics initial_insert_metrics;
45 Metrics current_metrics;
46
47private:
48 daisi::material_flow::Order order_;
49 bool is_start_; // otherwise is finish
50 bool is_origin_ = false;
51 daisi::util::Position position_;
52};
53
55 explicit StnTaskManagementEdge(const bool all_positive) : all_positive_(all_positive){};
56
57 void addWeight(double weight) {
58 if (weight >= 0 && all_positive_) {
59 weights_.push_back(weight);
60 } else if (weight <= 0 && !all_positive_) {
61 weights_.push_back(weight);
62 } else {
63 throw std::invalid_argument("Weight does not fit to the edge type");
64 }
65 }
66
67 double getWeight() const {
68 if (all_positive_) {
69 return *std::max_element(weights_.begin(), weights_.end());
70 }
71 return *std::min_element(weights_.begin(), weights_.end());
72 }
73
74 void removeLastWeight() { weights_.pop_back(); }
75
76 int getNumberOfWeights() const { return weights_.size(); }
77
78 void updateWeight(const int index, const double &weight) {
79 if (index >= weights_.size()) {
80 throw std::invalid_argument("Index out of range");
81 }
82
83 if (weight >= 0 && all_positive_) {
84 weights_[index] = weight;
85 } else if (weight < 0 && !all_positive_) {
86 weights_[index] = weight;
87 } else {
88 throw std::invalid_argument("Weight does not fit to the edge type");
89 }
90 }
91
92private:
93 std::vector<double> weights_;
94 bool all_positive_;
95};
96
97} // namespace daisi::cpps::logical
98
99namespace std {
100
101template <> struct hash<daisi::cpps::logical::StnTaskManagementVertex> {
102 std::size_t operator()(const daisi::cpps::logical::StnTaskManagementVertex &v) const {
103 std::string repr;
104
105 if (auto move_order_pval = std::get_if<daisi::material_flow::MoveOrder>(&v.getOrder())) {
106 repr = move_order_pval->getUuid();
107 } else if (auto action_order_pval =
108 std::get_if<daisi::material_flow::ActionOrder>(&v.getOrder())) {
109 repr = action_order_pval->getUuid();
110 } else if (auto transport_order_pval =
111 std::get_if<daisi::material_flow::TransportOrder>(&v.getOrder())) {
112 repr = transport_order_pval->getUuid();
113 } else {
114 throw std::runtime_error("Order type not supported");
115 }
116
117 repr += v.isStart() ? "start" : "finish";
118 return hash<string>()(repr);
119 }
120};
121
122} // namespace std
123
124#endif
Definition metrics.h:28
Modified Round Robin Algorithm that centrally assigns tasks of incoming material flows to the corresp...
Definition algorithm_config.h:22
Definition stn_task_management_components.h:54
Definition stn_task_management_components.h:29