solver  1.0
RoboticLine.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_ROBOTIC_LINE_H
19 #define HLIDAC_PES_ROBOTIC_LINE_H
20 
27 #include <cassert>
28 #include <algorithm>
29 #include <iostream>
30 #include <stdint.h>
31 #include <map>
32 #include <set>
33 #include <string>
34 #include <vector>
35 #include <unordered_set>
36 #include <utility>
37 #include "SolverConfig.h"
38 #include "Shared/Exceptions.h"
39 
40 class Activity;
41 class Location;
42 class DynamicActivity;
43 class StaticActivity;
44 class RobotPowerMode;
46 class Robot;
47 class RoboticLine;
48 
54 class ActivityMode {
55  public:
56  ActivityMode() { };
57  virtual uint32_t id() const = 0;
58  virtual Activity* baseParent() const = 0;
59  virtual ~ActivityMode() { };
60 };
61 
68 class Activity {
69  public:
70  Activity(const uint32_t& aid) : mAid(aid), mLastInCycle(false), mParent(nullptr) { }
71  uint32_t aid() const { return mAid; }
72  std::string name() const { return mName; }
73  std::string description() const { return mDescription; }
74  bool lastInCycle() const { return mLastInCycle; }
75  std::vector<Activity*> successors() const { return mSuccessors; }
76  std::vector<Activity*> predecessors() const { return mPredecessors; }
77  double minAbsDuration() const { return mMinAbsDuration; }
78  double maxAbsDuration() const { return mMaxAbsDuration; }
79  virtual bool mandatory() const = 0;
80  virtual bool optional() const = 0;
81  virtual size_t numberOfModes() const = 0;
82  virtual Robot* parent() const = 0;
83  virtual ~Activity() { }
84  protected:
85  void name(const std::string& name) { mName = name; }
86  void description(const std::string& description) { mDescription = description; }
87  void lastInCycle(const bool& lastInCycle) { mLastInCycle = lastInCycle; }
88  void addSuccessor(Activity* successor) { mSuccessors.push_back(successor); }
89  void addPredecessor(Activity* predecessor) { mPredecessors.push_back(predecessor); }
90  void minAbsDuration(const double& minAbsDuration) { mMinAbsDuration = minAbsDuration; }
91  void maxAbsDuration(const double& maxAbsDuration) { mMaxAbsDuration = maxAbsDuration; }
92 
93  virtual void parent(Robot* parent) = 0;
94  virtual void freeAllocatedMemory() = 0;
95 
97  uint32_t mAid;
101  std::string mName;
103  std::string mDescription;
105  std::vector<Activity*> mSuccessors;
107  std::vector<Activity*> mPredecessors;
112 
115 
117  friend class Robot;
118 };
119 
125 struct Monomial {
126  int32_t degree;
127  double coeff;
128 };
129 
133 class Movement : public ActivityMode {
134  public:
135  Movement(const uint32_t& mid) : mMid(mid), mFrom(nullptr), mTo(nullptr), mParent(nullptr) { }
136  virtual uint32_t id() const { return mMid; }
137  uint32_t mid() const { return mMid; }
138  Location* from() const { return mFrom; }
139  Location* to() const { return mTo; }
140  double minDuration() const { return mMinDuration; }
141  double maxDuration() const { return mMaxDuration; }
142  std::vector<Monomial> energyFunction() const { return mEnergyFunction; }
147  double energyConsumption(const double& duration) const;
148  DynamicActivity* parent() const { return mParent; }
149  virtual Activity* baseParent() const { return (Activity*) mParent; }
150  virtual ~Movement() = default;
151  private:
152  void from(Location* from) { mFrom = from; }
153  void to(Location* to) { mTo = to; }
154  void minDuration(const double& minDuration) { mMinDuration = minDuration; }
155  void maxDuration(const double& maxDuration) { mMaxDuration = maxDuration; }
156  void addMonomial(const Monomial& m) { mEnergyFunction.push_back(m); }
157  void parent(DynamicActivity* parent) { mParent = parent; }
158 
160  uint32_t mMid;
166  double mMinDuration;
168  double mMaxDuration;
173  std::vector<Monomial> mEnergyFunction;
174 
177 
179  friend class XmlReader;
181  friend class DynamicActivity;
183  friend class Robot;
184 };
185 
192 class Location : public ActivityMode {
193  public:
194  Location(const uint32_t& lid = 0) : mLid(lid), mParent(nullptr) { }
195  virtual uint32_t id() const { return mLid; }
196  uint32_t lid() const { return mLid; }
197  uint32_t point() const { return mPoint; }
198  std::vector<LocationDependentPowerConsumption> locationDependentPowerConsumption() const {
200  }
201  std::vector<Movement*> enteringMovements() const { return mEnteringMovements; }
202  std::vector<Movement*> leavingMovements() const { return mLeavingMovements; }
207  double inputPower(RobotPowerMode* m) const;
213  double energyConsumption(const double& duration, RobotPowerMode* m) const;
214  StaticActivity* parent() const { return mParent; }
215  virtual Activity* baseParent() const { return (Activity*) mParent; }
216  virtual ~Location() = default;
217  private:
218  void lid(const uint32_t& lid) { mLid = lid; }
219  void point(const uint32_t& point) { mPoint = point; }
220  void addLocationDependentPowerConsumption(const LocationDependentPowerConsumption& ldpc) {
221  mLocationDependentPowerConsumption.push_back(ldpc);
222  }
223  void enteringMovements(const std::vector<Movement*>& enteringMovements) { mEnteringMovements = enteringMovements; }
224  void leavingMovements(const std::vector<Movement*>& leavingMovements) { mLeavingMovements = leavingMovements; }
225  void parent(StaticActivity *parent);
226 
228  uint32_t mLid;
234  uint32_t mPoint;
240  std::vector<LocationDependentPowerConsumption> mLocationDependentPowerConsumption;
242  std::vector<Movement*> mEnteringMovements;
244  std::vector<Movement*> mLeavingMovements;
245 
248 
250  friend class XmlReader;
252  friend class StaticActivity;
253 };
254 
261 class DynamicActivity: public Activity {
262  public:
263  DynamicActivity(const uint32_t& aid) : Activity(aid) { }
264  std::vector<Movement*> movements() const { return mMovements; }
271  Movement* findMovement(const uint32_t& mid) const;
272  StaticActivity* predecessor() const { return cessor("prede"); }
273  StaticActivity* successor() const { return cessor("suc"); }
275  virtual bool mandatory() const;
277  virtual bool optional() const { return !mandatory(); }
278  virtual size_t numberOfModes() const { return mMovements.size(); }
279  virtual Robot* parent() const { return mParent; }
280  virtual ~DynamicActivity() = default;
281  private:
282  void addMovement(Movement* mv) { mMovements.push_back(mv); }
283  virtual void parent(Robot* parent);
288  StaticActivity* cessor(const std::string& prefix) const;
289  virtual void freeAllocatedMemory();
290 
292  std::vector<Movement*> mMovements;
293 
295  friend class XmlReader;
296 };
297 
304 class StaticActivity : public Activity {
305  public:
306  StaticActivity(const uint32_t& aid) : Activity(aid) { }
307  std::vector<Location*> locations() const { return mLocations; }
314  Location* findLocation(const uint32_t& lid) const;
320  double inputPower(const uint32_t& lid, const uint32_t& pid) const;
327  double energyConsumption(double duration, const uint32_t& lid, const uint32_t& pid) const;
329  virtual bool mandatory() const { return true; }
331  virtual bool optional() const { return false; }
332  virtual size_t numberOfModes() const { return mLocations.size(); }
333  virtual Robot* parent() const { return mParent; }
334  virtual ~StaticActivity() = default;
335  private:
336  void addLocation(Location* p) { mLocations.push_back(p); }
337  virtual void parent(Robot* parent);
340  virtual void freeAllocatedMemory();
341 
343  std::vector<Location*> mLocations;
344 
346  friend class XmlReader;
348  friend class Robot;
351 };
352 
360  public:
361  RobotPowerMode(const uint32_t& pid) : mPid(pid), mExpectedInputPower(-1), mParent(nullptr) { }
362  uint32_t pid() const { return mPid; }
363  std::string name() const { return mName; }
364  std::string description() const { return mDescription; }
365  double minimalDelay() const { return mMinimalDelay; }
366  double expectedInputPower() const { return mExpectedInputPower; }
367  Robot* parent() const { return mParent; }
368  private:
369  void pid(const uint32_t& pid) { mPid = pid; }
370  void name(const std::string& name) { mName = name; }
371  void description(const std::string& description) { mDescription = description; }
372  void minimalDelay(const double& delay) { mMinimalDelay = delay; }
373  void expectedInputPower(const double& expectedInputPower) { mExpectedInputPower = expectedInputPower; }
374  void parent(Robot *parent) { mParent = parent; }
375 
377  uint32_t mPid;
379  std::string mName;
381  std::string mDescription;
386 
389 
391  friend class XmlReader;
393  friend class Robot;
394 };
395 
404  public:
405  LocationDependentPowerConsumption(const RobotPowerMode * rpm) : mPowerMode(rpm), mParent(nullptr) { }
406  const RobotPowerMode* robotPowerMode() const { return mPowerMode; }
407  double inputPower() const { return mInputPower; }
408  Location *parent() const { return mParent; }
409  private:
410  void inputPower(const double& inputPower) { mInputPower = inputPower; }
411  void parent(Location *parent) { mParent = parent; }
412 
416  double mInputPower;
417 
420 
422  friend class XmlReader;
424  friend class Location;
425 };
426 
432 class Robot {
433  public:
434  Robot() : mParent(nullptr) { }
435  std::string name() const { return mName; }
436  std::string description() const { return mDescription; }
437  std::vector<Activity*> activities() const { return mActivities; }
438  std::vector<RobotPowerMode*> powerModes() const { return mRobotModes; }
441  RoboticLine* parent() const { return mParent; }
442  private:
443  void name(const std::string& name) { mName = name; }
444  void description(const std::string& description) { mDescription = description; }
445  void addActivity(Activity *a) { mActivities.push_back(a); }
446  void addPowerMode(RobotPowerMode* m) { mRobotModes.push_back(m); }
447  void parent(RoboticLine* parent);
453  void setActivitiesRelations(const std::map<uint32_t, Location*>& pointToLocation,
454  const std::map<Movement*, std::pair<uint32_t, uint32_t>>& movementToPoints);
455  void freeAllocatedMemory();
456 
458  std::string mName;
460  std::string mDescription;
462  std::vector<Activity*> mActivities;
464  std::vector<RobotPowerMode*> mRobotModes;
465 
468 
470  friend class XmlReader;
472  friend class RoboticLine;
473 };
474 
481 class TimeLag {
482  public:
491  TimeLag(Activity* f, Activity* t, double l, int32_t h) : mFrom(f), mTo(t), mLength(l), mHeight(h) { }
492  Activity* from() const { return mFrom; }
493  Activity* to() const { return mTo; }
494  double length() const { return mLength; }
495  int32_t height() const { return mHeight; }
496  private:
497  void from(Activity* from) { mFrom = from; }
498  void to(Activity* to) { mTo = to; }
499  void length(const double& length) { mLength = length; }
500  void height(const int32_t& height) { mHeight = height; }
501 
507  double mLength;
509  int32_t mHeight;
510 };
511 
519  public:
520  InterRobotOperation(const uint32_t& oid) : mOid(oid), mParent(nullptr) { }
521  uint32_t oid() const { return mOid; }
522  std::string name() const { return mName; }
523  std::string description() const { return mDescription; }
524  std::vector<TimeLag> timeLags() const { return mTimeLags; }
525  std::vector<std::pair<Location*, Location*>> spatialCompatibility() const { return mSpatialCompatibility; }
526  RoboticLine* parent() const { return mParent; }
527  private:
528  void name(const std::string& name) { mName = name; }
529  void description(const std::string& description) { mDescription = description; }
530  void addTimeLag(const TimeLag& lag) { mTimeLags.push_back(lag); }
531  void addSpatialCompatibilityPair(Location *l1, Location *l2) { mSpatialCompatibility.emplace_back(l1, l2); }
532  void parent(RoboticLine* parent) { mParent = parent; }
533 
535  uint32_t mOid;
537  std::string mName;
539  std::string mDescription;
541  std::vector<TimeLag> mTimeLags;
546  std::vector<std::pair<Location*, Location*>> mSpatialCompatibility;
547 
550 
552  friend class XmlReader;
554  friend class RoboticLine;
555 };
556 
563 class RoboticLine {
564  public:
565  RoboticLine();
566  RoboticLine(const RoboticLine& l);
567  RoboticLine& operator=(const RoboticLine& l);
568  std::string name() const { return mName; }
569  std::string description() const { return mDescription; }
570  std::vector<Robot*> robots() const { return mRobots; }
571  std::vector<InterRobotOperation*> interRobotOperations() const { return mInterRobotOperations; }
572  std::vector<std::pair<ActivityMode*, ActivityMode*>> collisions() const { return mCollisions; }
573  double productionCycleTime() const { return mProductionCycleTime; }
574  ~RoboticLine();
575  private:
576  void name(const std::string& name) { mName = name; }
577  void description(const std::string& description) { mDescription = description; }
578  void addRobot(Robot* r) { mRobots.push_back(r); }
579  void addInterRobotOperation(InterRobotOperation* op) { mInterRobotOperations.push_back(op); }
580  void addCollision(const std::pair<ActivityMode*, ActivityMode*>& collision) { mCollisions.push_back(collision); }
581  void productionCycleTime(const double& productionCycleTime) { mProductionCycleTime = productionCycleTime; }
582 
593  void initialiseDataStructures(const std::map<uint32_t, Location*>& pointToLocation,
594  const std::map<Movement*, std::pair<uint32_t, uint32_t>>& movementToPoints);
595  void copyDataStructures(const RoboticLine& r);
596  void freeAllocatedMemory();
597 
599  int64_t *mRefCounter;
601  std::string mName;
603  std::string mDescription;
605  std::vector<Robot*> mRobots;
607  std::vector<InterRobotOperation*> mInterRobotOperations;
609  std::vector<std::pair<ActivityMode*, ActivityMode*>> mCollisions;
612 
614  static std::map<int64_t*, std::set<RoboticLine*>> liveInstances;
615 
617  friend class XmlReader;
618 };
619 
620 #endif
The instance of the class corresponds to a robot movement between two coordinates.
Definition: RoboticLine.h:133
double mProductionCycleTime
Production cycle time, also called robot cycle time.
Definition: RoboticLine.h:611
std::vector< Movement * > mLeavingMovements
The movements leaving from this location.
Definition: RoboticLine.h:244
virtual bool optional() const
None of static activities is optional since all of them have to be performed.
Definition: RoboticLine.h:331
The base class incorporating common properties of robot operations and movements. ...
Definition: RoboticLine.h:68
uint32_t mMid
Movement identification.
Definition: RoboticLine.h:160
The instance of this class specifies input power of the robot for a particular robot configuration an...
Definition: RoboticLine.h:403
uint32_t mAid
Identification of the activity.
Definition: RoboticLine.h:97
std::vector< Movement * > mEnteringMovements
The movements entering to this location.
Definition: RoboticLine.h:242
double inputPower(RobotPowerMode *m) const
Definition: RoboticLine.cpp:41
std::vector< std::pair< ActivityMode *, ActivityMode * > > mCollisions
Collisions between robots defined as time disjunctive pairs.
Definition: RoboticLine.h:609
Instance of this class includes all the data structures and methods related to a robot.
Definition: RoboticLine.h:432
Activity * mFrom
The activity from which the arc is leaving.
Definition: RoboticLine.h:503
virtual bool optional() const
It returns whether this dynamic activity is optional, i.e. may or may not be performed.
Definition: RoboticLine.h:277
std::string mDescription
Description of the robotic cell.
Definition: RoboticLine.h:603
std::vector< Location * > mLocations
Each static activity consists of possible robot positions, i.e. locations.
Definition: RoboticLine.h:343
double mExpectedInputPower
Expected input power of the robot (see mParent) for this power saving mode.
Definition: RoboticLine.h:385
Collection of movements between two static activities.
Definition: RoboticLine.h:261
std::string mName
Name of the robot.
Definition: RoboticLine.h:458
TimeLag(Activity *f, Activity *t, double l, int32_t h)
It constructs an instance corresponding to equation where and are start times of activity t and f ...
Definition: RoboticLine.h:491
uint32_t mOid
Identification of this inter-robot operation.
Definition: RoboticLine.h:535
Robot * mParent
A robot that is equipped with this power saving mode.
Definition: RoboticLine.h:388
std::vector< RobotPowerMode * > mRobotModes
Applicable power saving modes for this robot.
Definition: RoboticLine.h:464
uint32_t mPid
Identification of the power saving mode.
Definition: RoboticLine.h:377
bool mLastInCycle
It determines whether the activity closes the robot cycle.
Definition: RoboticLine.h:99
std::vector< Robot * > mRobots
Robots located in this cell.
Definition: RoboticLine.h:605
uint32_t mPoint
Definition: RoboticLine.h:234
std::string mDescription
Description of this inter-robot operation.
Definition: RoboticLine.h:539
void findMovementsForLocations()
Method assigns entering and leaving movements to each location in mLocations.
int64_t * mRefCounter
Counter of references, the number of shallow copies sharing the same data.
Definition: RoboticLine.h:599
std::vector< std::pair< Location *, Location * > > mSpatialCompatibility
List of compatible location pairs for the handover(s).
Definition: RoboticLine.h:546
Movement * findMovement(const uint32_t &mid) const
It finds a movement according to its identification.
Definition: RoboticLine.cpp:67
std::string mName
Name of the activity.
Definition: RoboticLine.h:101
StaticActivity * mParent
A parent of the location, i.e. static activity.
Definition: RoboticLine.h:247
The file defines extended exceptions for the better error handling in the program.
std::vector< InterRobotOperation * > mInterRobotOperations
Inter-robot operations between robots.
Definition: RoboticLine.h:607
double mLength
The time offset of the inter-robot arc.
Definition: RoboticLine.h:507
Collection of locations in which a robot operation (or waiting) can be performed. ...
Definition: RoboticLine.h:304
Robot * mParent
Pointer to the parent, i.e. a robot performing this activity.
Definition: RoboticLine.h:114
RoboticLine * mParent
Robotic cell in which this robot is located.
Definition: RoboticLine.h:467
Activity * mTo
The activity to which the arc is entering.
Definition: RoboticLine.h:505
static std::map< int64_t *, std::set< RoboticLine * > > liveInstances
Track of dynamically created instances, needed for managing the memory.
Definition: RoboticLine.h:614
A part of the energy function of a movement.
Definition: RoboticLine.h:125
double energyConsumption(double duration, const uint32_t &lid, const uint32_t &pid) const
It represents the power saving mode of the robot.
Definition: RoboticLine.h:359
double mMaxAbsDuration
Maximal possible duration of the activity.
Definition: RoboticLine.h:111
double mMinDuration
The minimal possible duration of the robot movement.
Definition: RoboticLine.h:166
std::string mDescription
Description of the robot.
Definition: RoboticLine.h:460
std::vector< Activity * > mSuccessors
Successors of the activity.
Definition: RoboticLine.h:105
std::string mName
Name of the robotic cell.
Definition: RoboticLine.h:601
Instance of TimeLag class defines a time relation between two different robots.
Definition: RoboticLine.h:481
int32_t mHeight
The time offset in the number of cycles.
Definition: RoboticLine.h:509
A parallel heuristic for the energy optimization of robotic cells.
std::string mName
Name of this inter-robot operation.
Definition: RoboticLine.h:537
std::string mDescription
Description of the activity.
Definition: RoboticLine.h:103
std::vector< LocationDependentPowerConsumption > mLocationDependentPowerConsumption
Definition: RoboticLine.h:240
StaticActivity * cessor(const std::string &prefix) const
Definition: RoboticLine.cpp:77
std::vector< Activity * > mPredecessors
Predecessors of the activity.
Definition: RoboticLine.h:107
double inputPower(const uint32_t &lid, const uint32_t &pid) const
virtual bool mandatory() const
Each static activity is mandatory since it has to be performed.
Definition: RoboticLine.h:329
std::string mDescription
Description of this power saving mode.
Definition: RoboticLine.h:381
double mMaxDuration
The maximal duration of the movement.
Definition: RoboticLine.h:168
double energyConsumption(const double &duration) const
Definition: RoboticLine.cpp:31
Location * findLocation(const uint32_t &lid) const
It finds a location according to its identification.
uint32_t mLid
Identification of this location.
Definition: RoboticLine.h:228
std::vector< Monomial > mEnergyFunction
Definition: RoboticLine.h:173
The inter-robot operation corresponding to the workpiece/weldment handling.
Definition: RoboticLine.h:518
Location * mParent
Parent of this class is the related location for which the input power is calculated.
Definition: RoboticLine.h:419
virtual bool mandatory() const
It returns whether this dynamic activity has to be performed.
Definition: RoboticLine.cpp:95
double mInputPower
Location dependent input power.
Definition: RoboticLine.h:416
Either a movement or location.
Definition: RoboticLine.h:54
Parser of XML datasets.
Definition: XmlReader.h:45
const RobotPowerMode * mPowerMode
The power saving mode which input power is location dependent.
Definition: RoboticLine.h:414
void initialiseDataStructures(const std::map< uint32_t, Location * > &pointToLocation, const std::map< Movement *, std::pair< uint32_t, uint32_t >> &movementToPoints)
It recursively sets parents and initializes relations between activities.
DynamicActivity * mParent
Parent of the movement, i.e. a dynamic activity.
Definition: RoboticLine.h:176
double mMinAbsDuration
Minimal possible duration of the activity.
Definition: RoboticLine.h:109
void setActivitiesRelations(const std::map< uint32_t, Location * > &pointToLocation, const std::map< Movement *, std::pair< uint32_t, uint32_t >> &movementToPoints)
It initializes precedences between activities (successors, predecessors).
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
RobotPowerMode * fastestPowerSavingMode() const
The power saving mode with the minimal time for an application is returned.
double mMinimalDelay
Minimal time needed for an application of this power saving mode.
Definition: RoboticLine.h:383
std::vector< Activity * > mActivities
Static (operations, waiting) and dynamic (movements) activities of the robot.
Definition: RoboticLine.h:462
double energyConsumption(const double &duration, RobotPowerMode *m) const
Definition: RoboticLine.cpp:56
Location * mFrom
Location representing the start coordinate of the movement.
Definition: RoboticLine.h:162
Location * mTo
Location representing the end coordinate of the movement.
Definition: RoboticLine.h:164
std::string mName
Name of this power saving mode, e.g. 'brakes', 'motors', 'bus-power-off', ...
Definition: RoboticLine.h:379
void setParentOfChildren(RoboticLine *rl)
This method is propagated through all the parts of the robotic cell in order to set parents...
RoboticLine * mParent
A parent of the inter-robot operation is the robotic cell.
Definition: RoboticLine.h:549
std::vector< Movement * > mMovements
The movements of this dynamic activity.
Definition: RoboticLine.h:292
std::vector< TimeLag > mTimeLags
Time lags ensuring desired time synchronizations.
Definition: RoboticLine.h:541