solver  1.0
PrecalculatedMapping.cpp
1 /*
2  This file is part of the EnergyOptimizatorOfRoboticCells program.
3 
4  EnergyOptimizatorOfRoboticCells is free software: you can redistribute it and/or modify
5  it under the terms of the GNU General Public License as published by
6  the Free Software Foundation, either version 3 of the License, or
7  (at your option) any later version.
8 
9  EnergyOptimizatorOfRoboticCells is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  GNU General Public License for more details.
13 
14  You should have received a copy of the GNU General Public License
15  along with EnergyOptimizatorOfRoboticCells. If not, see <http://www.gnu.org/licenses/>.
16 */
17 
18 #include <algorithm>
19 #include <iterator>
20 #include <string>
21 #include "SolverConfig.h"
23 
24 using namespace std;
25 
27  try {
28  StaticActivity *pred = da->predecessor(), *suc = da->successor();
29  auto p1 = getValue(s.pointAndPowerMode, pred->aid(), caller()), p2 = getValue(s.pointAndPowerMode, suc->aid(), caller());
30  return getValue(m.pointsToMovement, {p1.first, p2.first}, caller());
31  } catch (...) {
32  throw_with_nested(SolverException(caller(), "Either incomplete solution or flawed PrecalculatedMapping data-structure!"));
33  }
34 }
35 
36 vector<Location*> getLocations(Location* loc) {
37  return { loc };
38 }
39 
40 vector<Location*> getLocations(StaticActivity* act) {
41  return act->locations();
42 }
43 
44 template <class X, class Y>
45 vector<Movement*> findMovements(X from, Y to) {
46 
47  vector<Movement*> foundMvs, leavMvs, entMvs;
48 
49  const vector<Location*> &f = getLocations(from), &t = getLocations(to);
50  for (Location *loc : f) {
51  const vector<Movement*>& sortedRange1 = leavMvs, &sortedRange2 = loc->leavingMovements();
52  vector<Movement*> sortedRange(sortedRange1.size()+sortedRange2.size());
53  merge(sortedRange1.cbegin(), sortedRange1.cend(), sortedRange2.cbegin(), sortedRange2.cend(), sortedRange.begin());
54  leavMvs = move(sortedRange);
55  }
56 
57  for (Location *loc : t) {
58  const vector<Movement*>& sortedRange1 = entMvs, &sortedRange2 = loc->enteringMovements();
59  vector<Movement*> sortedRange(sortedRange1.size()+sortedRange2.size());
60  merge(sortedRange1.cbegin(), sortedRange1.cend(), sortedRange2.cbegin(), sortedRange2.cend(), sortedRange.begin());
61  entMvs = move(sortedRange);
62  }
63 
64  set_intersection(leavMvs.cbegin(), leavMvs.cend(), entMvs.cbegin(), entMvs.cend(), back_inserter(foundMvs));
65 
66  return foundMvs;
67 }
68 
69 template vector<Movement*> findMovements<StaticActivity*, Location*>(StaticActivity*, Location*);
70 template vector<Movement*> findMovements<Location*, StaticActivity*>(Location*, StaticActivity*);
71 template vector<Movement*> findMovements<StaticActivity*, StaticActivity*>(StaticActivity*, StaticActivity*);
The instance of the class corresponds to a robot movement between two coordinates.
Definition: RoboticLine.h:133
The structure representing a solution found by an algorithm.
Definition: Solution.h:50
Collection of movements between two static activities.
Definition: RoboticLine.h:261
STL namespace.
A general exception of the program.
Definition: Exceptions.h:58
The structures and methods suitable for fast searching in the data structure of the robotic cell...
std::vector< Movement * > findMovements(X from, Y to)
It finds all the movements located between from and to and returns them in the vector.
std::map< uint32_t, std::pair< uint32_t, uint32_t > > pointAndPowerMode
It maps the identification of a static activity to its assigned coordinate and used power saving mode...
Definition: Solution.h:67
Collection of locations in which a robot operation (or waiting) can be performed. ...
Definition: RoboticLine.h:304
Movement * getSelectedMovement(const Solution &s, const PrecalculatedMapping &m, DynamicActivity *da)
It extracts the selected movement of the given dynamic activity from the solution.
Location of the robot used either during work (welding) or waiting.
Definition: RoboticLine.h:192
The structure contains the maps for fast searching in the robotic cell.
std::unordered_map< std::pair< uint32_t, uint32_t >, Movement * > pointsToMovement
Two coordinates are mapped to the movement starting/ending at the first/second coordinate, respectively.