solver  1.0
ConstraintsGenerator.h
Go to the documentation of this file.
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 #ifndef HLIDAC_PES_CONSTRAINTS_GENERATOR_H
19 #define HLIDAC_PES_CONSTRAINTS_GENERATOR_H
20 
27 #include <cassert>
28 #include <map>
29 #include <vector>
30 #include <utility>
31 #include "RoboticLine.h"
33 #include "ILPModel/ILPModel.h"
35 
43  public:
45  ConstraintsGenerator() : mCycleTime(0.0), mConstraintsCounter(0ul), mLine(nullptr), mMapping(nullptr) { }
50 
52  void reset();
54  void reset(Robot* r, const PrecalculatedMapping* m);
56  void reset(const RoboticLine& l, const PrecalculatedMapping* m);
57 
59  uint64_t moveConstraintsToModel(ILPModel& m);
60 
68  void addEnergyFunctions1(const map1to1& d, const map1to1& W, const map2to1& x, const map2to1& z);
75  void addEnergyFunctions2(const map1to1& d, const map1to1& W, const map2to1& y);
77  void addEnergyFunctions(const map1to1& d, const map1to1& W, const map2to1& x, const map2to1& z, const map2to1& y);
78 
83  void addUniquePointSelection(const map2to1& x);
88  void addUniquePowerModeSelection(const map2to1& z);
90  void addUniqueModeSelection(const map2to1& x, map2to1& z);
91 
97  void addFlowConstraints(const map2to1& x, const map2to1& y);
98 
104  void addFixedPrecedences(const map1to1& s, const map1to1& d);
110  void addPrecedenceSelectionConstraints(const map2to1& y, const map2to1& w);
117  void addSelectablePrecedences(const map1to1& s, const map1to1& d, const map2to1& w);
119  void addAllPrecedences(const map1to1& s, const map1to1& d, const map2to1& y, const map2to1& w);
120 
126  void addMinimalDurationConstraints1(const map1to1& d, const map2to1& z);
132  void addMinimalDurationConstraints2(const map1to1& d, const map2to1& y);
138  void addMaximalDurationConstraints2(const map1to1& d, const map2to1& y);
140  void addDurationConstraints(const map1to1& d, const map2to1& z, const map2to1& y);
141 
147  void addTimeLags(const map1to1& s, bool allRequired = true);
162  void addCollisions(const map1to1& s, const map1to1& d, const map2to1& x, const map2to1& y, const map4toN& c);
164  void addGlobalConstraints(const map1to1& s, const map1to1& d, const map2to1& x, const map2to1& y, const map4toN& c);
165 
173  void addEnergyFunction(const map1to1& d, const map1to1& W, Location *loc, RobotPowerMode *pwrm);
180  void addEnergyFunction(const map1to1& d, const map1to1& W, Movement* mv);
187  void addSelectedPrecedences(const map1to1& s, const map1to1& d, const std::vector<Movement*>& mvs);
196  void addCollisionResolution(const map1to1& s, const map1to1& d, uint32_t i, uint32_t j, int32_t multipleOfCycleTime);
197 
198  private:
208  void addConstraint(SparseMatrix<double>::Row& row, Operator op, const double& b, std::string conDesc = "");
209 
211  double mCycleTime;
214 
218  std::vector<Robot*> mRobots;
222  std::vector<StaticActivity*> mStaticActivities;
224  std::vector<DynamicActivity*> mDynamicActivities;
225 
229  std::vector<Operator> mOp;
231  std::vector<double> mB;
233  std::vector<std::string> mConDesc;
234 };
235 
236 #endif
void addEnergyFunctions1(const map1to1 &d, const map1to1 &W, const map2to1 &x, const map2to1 &z)
Add the constraints propagating the consumption of static activities to the criterion.
The instance of the class corresponds to a robot movement between two coordinates.
Definition: RoboticLine.h:133
void addPrecedenceSelectionConstraints(const map2to1 &y, const map2to1 &w)
According to the selected movements it decides which optional dynamic activities are performed...
void addEnergyFunction(const map1to1 &d, const map1to1 &W, Location *loc, RobotPowerMode *pwrm)
Adds energy function for a static activity, its location, and its applied power saving mode...
Generation of the (I)LP constraints.
Instance of this class includes all the data structures and methods related to a robot.
Definition: RoboticLine.h:432
const PrecalculatedMapping * mMapping
Mapping calculated for the robotic cell.
void addCollisionResolution(const map1to1 &s, const map1to1 &d, uint32_t i, uint32_t j, int32_t multipleOfCycleTime)
It adds a constraint to resolve a collision, i.e. it adds a precedence for a given multiple of the r...
std::vector< Operator > mOp
Operators of constraints.
void addMinimalDurationConstraints1(const map1to1 &d, const map2to1 &z)
Constraints restricting the minimal duration of static activities with respect to their assigned powe...
void addUniqueModeSelection(const map2to1 &x, map2to1 &z)
It calls addUniquePointSelection and addUniquePowerModeSelection methods.
void addEnergyFunctions2(const map1to1 &d, const map1to1 &W, const map2to1 &y)
Add the constraints propagating the consumption of dynamic activities to the criterion.
std::vector< StaticActivity * > mStaticActivities
Static activities filtered from the robotic cell.
Integer Linear Programming problem is stored in this data structure.
Definition: ILPModel.h:69
std::vector< Robot * > mRobots
Robots located in the robotic cell.
The structures and methods suitable for fast searching in the data structure of the robotic cell...
void addSpatialCompatibilityConstraints(const map2to1 &x)
It defines the spatial compatibility between robots, in other words a workpice is taken from the same...
void addTimeLags(const map1to1 &s, bool allRequired=true)
Time lags enforcing correct time synchronizations between robots are added.
std::map< std::pair< uint64_t, uint64_t >, std::vector< uint32_t > > map4toN
Mapping of variables indexed by four numbers.
void addUniquePowerModeSelection(const map2to1 &z)
Just one power saving mode (including the dummy one - motors) is applied for each static activity...
void addEnergyFunctions(const map1to1 &d, const map1to1 &W, const map2to1 &x, const map2to1 &z, const map2to1 &y)
It adds the energy functions of both the static and dynamic activities.
void reset()
All the generated constraints are removed.
void addSelectedPrecedences(const map1to1 &s, const map1to1 &d, const std::vector< Movement * > &mvs)
Each has-to-be movement imposes a fixed precedence that is added to the formulation in the form of a ...
std::vector< double > mB
Right-hand side constants.
void addFlowConstraints(const map2to1 &x, const map2to1 &y)
Add flow preservation constraints ensuring that robot leaves the same location as it enters...
std::vector< std::string > mConDesc
Description of the constraints.
Memory efficient storage of the constraint matrix.
Definition: SparseMatrix.h:43
uint64_t mConstraintsCounter
The number of constraints generated by an instance of this class.
void addFixedPrecedences(const map1to1 &s, const map1to1 &d)
Adds fixed precedences, i.e. enforces the have-to-be order of some activities.
std::vector< DynamicActivity * > mDynamicActivities
Dynamic activities filtered from the robotic cell.
General model for Integer Linear Programming problem.
It represents the power saving mode of the robot.
Definition: RoboticLine.h:359
RoboticLine const * mLine
Pointer to an active robotic cell.
void addSelectablePrecedences(const map1to1 &s, const map1to1 &d, const map2to1 &w)
It adds selectable precedences which model alternative orders of activities.
void addCollisions(const map1to1 &s, const map1to1 &d, const map2to1 &x, const map2to1 &y, const map4toN &c)
Adds constraints that enforce a collision-free solution.
ConstraintsGenerator(Robot *r, const PrecalculatedMapping *m)
Generation of the constraints for a given robot.
SparseMatrix< double > mA
Constraint matrix.
std::map< uint32_t, uint32_t > map1to1
Identification of the activity is mapped to the index of the variable.
void addAllPrecedences(const map1to1 &s, const map1to1 &d, const map2to1 &y, const map2to1 &w)
It calls all the methods related to the order of activities.
void initializeDataStructures()
It initializes the member variables and removes all the constraints.
void addGlobalConstraints(const map1to1 &s, const map1to1 &d, const map2to1 &x, const map2to1 &y, const map4toN &c)
Adds all the global constraints, i.e. time lags, spatial compatibility, and collision resolution...
void addMaximalDurationConstraints2(const map1to1 &d, const map2to1 &y)
Constraints restricting the maximal duration of dynamic activities with respect to their selected mov...
double mCycleTime
Copied robot cycle time.
void addDurationConstraints(const map1to1 &d, const map2to1 &z, const map2to1 &y)
It constructs all the constraints that limit the duration of activities.
ConstraintsGenerator()
Empty constructor, the object needs to be assigned a robot or robotic cell later. ...
ConstraintsGenerator(const RoboticLine &l, const PrecalculatedMapping *m)
Generation of the constraints for a given robotic cell.
void addMinimalDurationConstraints2(const map1to1 &d, const map2to1 &y)
Constraints restricting the minimal duration of dynamic activities with respect to their selected mov...
void addUniquePointSelection(const map2to1 &x)
Just one location, i.e. coordinate, is selected for each static activity.
Location of the robot used either during work (welding) or waiting.
Definition: RoboticLine.h:192
The robotic cell corresponds to an instance of this class.
Definition: RoboticLine.h:563
The structure contains the maps for fast searching in the robotic cell.
void addConstraint(SparseMatrix< double >::Row &row, Operator op, const double &b, std::string conDesc="")
Add constraint "row'*vars op b" into the formulation.
Mapping of integer, to be more precise binary, variables of the energy optimization problem...
The file contains various classes devoted to abstract representation of the robotic cell...
std::map< std::pair< uint32_t, uint32_t >, uint32_t > map2to1
Mapping of variables indexed by two numbers.
uint64_t moveConstraintsToModel(ILPModel &m)
It efficiently moves all the generated constraints to the given model.
Operator
Constants for operators '<=', '=', and '>=', respectively.
Definition: ILPModel.h:43