SOLA
Loading...
Searching...
No Matches
metrics_composition.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_METRICS_COMPOSITION_H_
18#define DAISI_CPPS_LOGICAL_TASK_MANAGEMENT_METRICS_COMPOSITION_H_
19
20#include "metrics.h"
21#include "solanet/serializer/serialize.h"
22
23namespace daisi::cpps::logical {
24
26public:
27 MetricsComposition() = default;
28
29 explicit MetricsComposition(const Metrics &current_metrics)
30 : current_metrics_(current_metrics),
31 insertion_metrics_(current_metrics),
32 diff_insertion_metrics_(current_metrics) {}
33
34 MetricsComposition(const Metrics &current_metrics, const Metrics &insertion_metrics,
35 const Metrics &diff_insertion_metrics)
36 : current_metrics_(current_metrics),
37 insertion_metrics_(insertion_metrics),
38 insertion_metrics_set_(true),
39 diff_insertion_metrics_(diff_insertion_metrics),
40 diff_insertion_metrics_set_(true) {}
41
42 const Metrics &getCurrentMetrics() const { return current_metrics_; }
43
44 void updateCurrentMetrics(const Metrics &updated_current_metrics) {
45 current_metrics_ = updated_current_metrics;
46 }
47
48 void setDiffInsertionMetrics(const Metrics &diff_insertion_metrics) {
49 if (!diff_insertion_metrics_set_) {
50 diff_insertion_metrics_ = diff_insertion_metrics;
51 diff_insertion_metrics_set_ = true;
52 } else {
53 throw std::logic_error("diff insertion metrics already set");
54 }
55 }
56
57 const Metrics &getInsertionMetrics() const { return insertion_metrics_; }
58
59 const Metrics &getDiffInsertionMetrics() const { return diff_insertion_metrics_; }
60
61 const Metrics &getMetricsForAuction() const { return getDiffInsertionMetrics(); }
62
63 bool hasDiffInsertionMetrics() const { return diff_insertion_metrics_set_; }
64
65 void fixInsertionMetrics() {
66 if (!insertion_metrics_set_) {
67 insertion_metrics_ = current_metrics_;
68 insertion_metrics_set_ = true;
69 } else {
70 throw std::logic_error("insertion metrics already set");
71 }
72 }
73
74 bool operator<(const MetricsComposition &other) const {
75 return getMetricsForAuction() < other.getMetricsForAuction();
76 }
77
78 bool operator<=(const MetricsComposition &other) const {
79 return getMetricsForAuction() <= other.getMetricsForAuction();
80 }
81
82 bool operator>(const MetricsComposition &other) const {
83 return getMetricsForAuction() > other.getMetricsForAuction();
84 }
85
86 bool operator>=(const MetricsComposition &other) const {
87 return getMetricsForAuction() >= other.getMetricsForAuction();
88 }
89
90 bool operator==(const MetricsComposition &other) const {
91 return getMetricsForAuction() == other.getMetricsForAuction();
92 }
93
94 bool operator!=(const MetricsComposition &other) const {
95 return getMetricsForAuction() != other.getMetricsForAuction();
96 }
97
98 MetricsComposition operator-(const MetricsComposition &other) const {
99 return MetricsComposition{current_metrics_, insertion_metrics_,
100 current_metrics_ - other.current_metrics_};
101 }
102
103 SERIALIZE(current_metrics_, insertion_metrics_, insertion_metrics_set_, diff_insertion_metrics_,
104 diff_insertion_metrics_set_);
105
106private:
107 // the current costs
108 // always updated when something got inserted
109 Metrics current_metrics_;
110
111 // metrics when the task got inserted
112 Metrics insertion_metrics_;
113 bool insertion_metrics_set_ = false;
114
115 // metric difference when the task got inserted
116 Metrics diff_insertion_metrics_;
117 bool diff_insertion_metrics_set_ = false;
118};
119
120} // namespace daisi::cpps::logical
121
122#endif
Definition metrics_composition.h:25
Definition metrics.h:28
Modified Round Robin Algorithm that centrally assigns tasks of incoming material flows to the corresp...
Definition algorithm_config.h:22