SOLA
Loading...
Searching...
No Matches
stn_task_management.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_H_
18#define DAISI_CPPS_LOGICAL_TASK_MANAGEMENT_STN_TASK_MANAGEMENT_H_
19
20#include <memory>
21
22#include "auction_based_task_management.h"
23#include "cpps/amr/amr_mobility_helper.h"
24#include "cpps/amr/physical/material_flow_functionality_mapping.h"
25#include "datastructure/simple_temporal_network.tpp"
26#include "stn_task_management_components.h"
27
28namespace daisi::cpps::logical {
29
32 private daisi::datastructure::SimpleTemporalNetwork<StnTaskManagementVertex,
33 StnTaskManagementEdge> {
34public:
36 StnTaskManagementVertex previous_finish;
37 std::optional<StnTaskManagementVertex> next_start;
38 int new_index;
39 };
40
41 StnTaskManagement(const AmrDescription &amr_description, const Topology &topology,
42 const daisi::util::Pose &pose);
43
44 ~StnTaskManagement() override = default;
45
47 bool hasTasks() const override;
48
51
54 bool setNextTask() override;
55
61 std::shared_ptr<InsertionPoint> insertion_point = nullptr) override;
62
67 bool addTask(const daisi::material_flow::Task &task,
68 std::shared_ptr<InsertionPoint> insertion_point = nullptr) override;
72 std::pair<MetricsComposition, std::shared_ptr<InsertionPoint>> getLatestCalculatedInsertionInfo()
73 const override;
74
77 void setCurrentTime(const daisi::util::Duration &now);
78
79 using VertexIterator = std::vector<StnTaskManagementVertex>::iterator;
80
84
85 // for each order their location at the end of their execution
86 std::vector<daisi::material_flow::Location> end_locations;
87
88 MetricsComposition metrics_composition;
89 };
90
91protected:
95 std::optional<daisi::material_flow::Task> current_task_;
96
97 std::optional<daisi::material_flow::Location> current_task_end_location_;
98
99 daisi::util::Duration current_task_expected_finish_time_ = 0.0;
100
101 std::vector<TaskInsertInfo> current_ordering_;
102
103 Metrics current_total_metrics_;
104
105 std::vector<TaskInsertInfo>::iterator newest_task_insert_info_;
106
107 daisi::util::Duration time_now_ = 0;
108
109 std::optional<std::pair<MetricsComposition, std::shared_ptr<InsertionPoint>>>
110 latest_calculated_insertion_info_;
111
112 bool solve() override;
113
114 void addPrecedenceConstraintBetweenTask(const StnTaskManagementVertex &start_vertex,
115 const std::string &precedence_task_name);
116
117 void addDurationConstraints(const StnTaskManagementVertex &start_vertex,
118 const StnTaskManagementVertex &finish_vertex,
119 const daisi::material_flow::Order &order,
120 const TaskInsertInfo &task_insert_info);
121
122 void updateGetToStartDurationConstraint(int task_index_to_update);
123
124 util::Duration calcGetToStartDuration(int task_index_to_update);
125
126 void addOrderingConstraintBetweenTasks(StnInsertionPoint insertion_point,
127 TaskInsertInfo &task_insert_info);
128
129 std::optional<std::pair<MetricsComposition, std::shared_ptr<StnInsertionPoint>>> addBestOrdering(
130 StnTaskManagement::TaskInsertInfo &task_insert_info);
131
132 std::vector<StnInsertionPoint> calcInsertionPoints();
133
137
138 daisi::util::Position getLastPositionBefore(int task_index);
139
140 daisi::util::Duration calcOrderDurationForInsert(const daisi::material_flow::Order &order,
141 const TaskInsertInfo &task_insert_info) const;
142
150 void insertOrderPropertiesIntoMetrics(const daisi::material_flow::Order &order, Metrics &metrics,
151 const TaskInsertInfo &task_insert_info,
152 int task_ordering_index);
153
154 // simple helper
155 VertexIterator getVertexIteratorOfOrder(const daisi::material_flow::Order &order, bool start);
156 int getVertexIndexOfOrder(const daisi::material_flow::Order &order, bool start);
157 const StnTaskManagementVertex &getVertexOfOrder(const daisi::material_flow::Order &order,
158 bool start);
159
160private:
161 void updateOriginConstraints(const daisi::util::Duration &time_difference);
162};
163
164} // namespace daisi::cpps::logical
165
166#endif
Definition amr_description.h:27
Definition amr_topology.h:26
Definition auction_based_task_management.h:25
Definition metrics_composition.h:25
Definition metrics.h:28
Definition stn_task_management.h:33
std::optional< daisi::material_flow::Task > current_task_
Definition stn_task_management.h:95
bool addTask(const daisi::material_flow::Task &task, std::shared_ptr< InsertionPoint > insertion_point=nullptr) override
assign a new task to the management
Definition stn_task_management.cpp:136
bool hasTasks() const override
check wether the task management has a current task assigned
Definition stn_task_management.cpp:84
void setCurrentTime(const daisi::util::Duration &now)
set the management's current time
Definition stn_task_management.cpp:38
bool setNextTask() override
set the current task to the first task that is currently queued
Definition stn_task_management.cpp:93
void updateCurrentOrdering()
update the metrics compositions of all currently queued tasks as well as the total metrics....
Definition stn_task_management.cpp:294
bool canAddTask(const daisi::material_flow::Task &task, std::shared_ptr< InsertionPoint > insertion_point=nullptr) override
check wether a new task can be assigned to the management
Definition stn_task_management.cpp:120
std::pair< MetricsComposition, std::shared_ptr< InsertionPoint > > getLatestCalculatedInsertionInfo() const override
get infos about the latest task insertion (also includes the check wether a task can be inserted)
Definition stn_task_management.cpp:572
daisi::material_flow::Task getCurrentTask() const override
get the current task
Definition stn_task_management.cpp:86
void insertOrderPropertiesIntoMetrics(const daisi::material_flow::Order &order, Metrics &metrics, const TaskInsertInfo &task_insert_info, int task_ordering_index)
calculate the metrics for the given order of the given task and insert them into the given metrics.
Definition stn_task_management.cpp:463
Definition simple_temporal_network.h:27
Definition task.h:34
Modified Round Robin Algorithm that centrally assigns tasks of incoming material flows to the corresp...
Definition algorithm_config.h:22
Definition auction_based_task_management.h:27
Definition stn_task_management_components.h:29
contains a task, the end locations, and metrics compositions for the single orders
Definition stn_task_management.h:82
Definition structure_helpers.h:64