solver  1.0
VariableMappingLP.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 "SolverConfig.h"
19 #include "Shared/Utils.h"
20 #include "Shared/Exceptions.h"
22 
23 using namespace std;
24 
26  addActivities(r->activities(), true);
27 }
28 
30  for (Robot* r : l.robots())
31  addActivities(r->activities(), true);
32 }
33 
34 void VariableMappingLP::addActivities(const vector<Activity*>& activities, bool mandatory, bool mapW) {
35  uint32_t idx = numberOfVariables();
36  for (Activity *a : activities) {
37  if ((mandatory == true && a->mandatory()) || (mandatory == false && a->optional())) {
38  try {
39  // Boolean mapW is useful for Gurobi criterion where variables 'W' can be omitted.
40  if (mapW == true) {
41  variables.emplace_back(FLT, 0.0);
42  varDesc.emplace_back("W_{"+to_string(a->aid())+"}");
43  W.emplace(a->aid(), idx++);
44  }
45 
46  RoboticLine* l = a->parent()->parent();
47  const vector<Robot*>& robots = l->robots();
48  variables.emplace_back(FLT, 0.0, l->productionCycleTime()*robots.size());
49  varDesc.emplace_back("s_{"+to_string(a->aid())+"}");
50  s.emplace(a->aid(), idx++);
51 
52  variables.emplace_back(FLT, a->minAbsDuration(), a->maxAbsDuration());
53  varDesc.emplace_back("d_{"+to_string(a->aid())+"}");
54  d.emplace(a->aid(), idx++);
55  } catch (...) {
56  throw_with_nested(SolverException(caller(), "Activity identifications are not unique!"));
57  }
58  }
59  }
60 }
61 
62 map<uint32_t, double> inverseMapping(const vector<double>& solution, const map1to1& mapping) {
63  map<uint32_t, double> m;
64  for (const auto& p : mapping) {
65  const auto& ret = m.emplace(p.first, solution[p.second]);
66  if (ret.second != true)
67  throw SolverException(caller(), "Inverse mapping is not unique!");
68  }
69 
70  return m;
71 }
72 
The base class incorporating common properties of robot operations and movements. ...
Definition: RoboticLine.h:68
Instance of this class includes all the data structures and methods related to a robot.
Definition: RoboticLine.h:432
void addActivities(const std::vector< Activity * > &activities, bool mandatory, bool mapW=true)
It adds the mapping for extra activities.
Mapping of continuous variables of the energy optimization problem.
STL namespace.
A general exception of the program.
Definition: Exceptions.h:58
Various auxiliary functions used across the program.
The file defines extended exceptions for the better error handling in the program.
VariableMappingLP(Robot *r)
Constructs the mapping of the continuous variables.
std::map< uint32_t, uint32_t > inverseMapping(const std::vector< double > &solution, const map2to1 &mapping)
It extracts the variables set to true and returns the ,,selected" indices.
std::map< uint32_t, uint32_t > map1to1
Identification of the activity is mapped to the index of the variable.
The robotic cell corresponds to an instance of this class.
Definition: RoboticLine.h:563