priority_scheduler.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2017, <copyright holder> <email>
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  * * Redistributions of source code must retain the above copyright
8  * notice, this list of conditions and the following disclaimer.
9  * * Redistributions in binary form must reproduce the above copyright
10  * notice, this list of conditions and the following disclaimer in the
11  * documentation and/or other materials provided with the distribution.
12  * * Neither the name of the <organization> nor the
13  * names of its contributors may be used to endorse or promote products
14  * derived from this software without specific prior written permission.
15  *
16  * THIS SOFTWARE IS PROVIDED BY <copyright holder> <email> ''AS IS'' AND ANY
17  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19  * DISCLAIMED. IN NO EVENT SHALL <copyright holder> <email> BE LIABLE FOR ANY
20  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26  *
27  */
28 
30 
31 namespace multi_robot_router
32 {
33 PriorityScheduler::PriorityScheduler(const uint32_t _nrRobots)
34 {
35  reset(_nrRobots);
36 }
37 
38 void PriorityScheduler::reset(const uint32_t _nrRobots)
39 {
40  checkedSchedules_.clear();
42 
43  for (uint32_t i = 0; i < _nrRobots; i++)
44  {
45  actualPrioritySchedule_.emplace_back(i);
46  }
47 
49 }
50 
51 const std::vector<uint32_t> &PriorityScheduler::getActualSchedule() const
52 {
54 }
55 
56 bool PriorityScheduler::reschedulePriorities(const uint32_t _collidingRobot, std::vector<uint32_t> _collisions, std::vector<uint32_t> &_newSchedule, uint32_t &_firstRobotToReplan)
57 {
58  _collisions.resize(_newSchedule.size(), 0);
59 
60  auto it = std::find(actualPrioritySchedule_.begin(), actualPrioritySchedule_.end(), _collidingRobot);
61 
62  if (it == actualPrioritySchedule_.end())
63  return false;
64 
65  uint32_t priorityCollidingRobot = std::distance(actualPrioritySchedule_.begin(), it);
66 
67  bool found;
68  uint32_t count = 0;
69  std::vector<uint32_t> newSchedule = actualPrioritySchedule_;
70 
71  do
72  {
73  found = true;
74  uint32_t maxCollisions = 0;
75  bool robotFound = false;
76  _firstRobotToReplan = 0;
77 
78  for (uint32_t i = 0; i < priorityCollidingRobot; i++)
79  {
80  uint32_t robot = newSchedule[i];
81 
82  if (_collisions[robot] > maxCollisions)
83  {
84  maxCollisions = _collisions[robot];
85  _firstRobotToReplan = i;
86  robotFound = true;
87  }
88  }
89 
90  if (!robotFound)
91  return false;
92 
93  std::swap(newSchedule[_firstRobotToReplan], newSchedule[priorityCollidingRobot]);
94 
95  for (const std::vector<uint32_t> &schedule : checkedSchedules_)
96  {
97  bool neq = false;
98 
99  for (uint32_t i = 0; i < newSchedule.size(); i++)
100  {
101  if (newSchedule[i] != schedule[i])
102  {
103  neq = true;
104  break;
105  }
106  }
107 
108  if (neq == false)
109  {
110  found = false;
111  //Swap back
112  std::swap(newSchedule[_firstRobotToReplan], newSchedule[priorityCollidingRobot]);
113  _collisions[newSchedule[_firstRobotToReplan]] = 0; //Remove robot from potential exchange list
114  break;
115  }
116  }
117 
118  count++;
119  } while (count < priorityCollidingRobot && !found);
120 
121  if (found)
122  {
123  actualPrioritySchedule_ = newSchedule;
124  _newSchedule = newSchedule;
126  return true;
127  }
128 
129  return false;
130 }
131 } // namespace multi_robot_router
void reset(const uint32_t _nrRobots)
resets the Priority schedule with an initial priority schedule
PriorityScheduler(const uint32_t _nrRobots)
constructor
std::vector< uint32_t > actualPrioritySchedule_
bool reschedulePriorities(const uint32_t _collidingRobot, std::vector< uint32_t > _collsisions, std::vector< uint32_t > &_newSchedule, uint32_t &_firstRobotToReplan)
rescedules priorities depending on the ound collisions and allready tried schedules ...
std::vector< std::vector< uint32_t > > checkedSchedules_
const std::vector< uint32_t > & getActualSchedule() const
returns the currently produced speed schedule


tuw_multi_robot_router
Author(s): Benjamin Binder
autogenerated on Mon Jun 10 2019 15:42:49