24 #include "SolverConfig.h"
41 size_t numOfRobots = l.robots().size();
52 high_resolution_clock::time_point start = high_resolution_clock::now();
54 s.
runTime = duration_cast<duration<double>>(high_resolution_clock::now()-start).count();
57 if (sLP.
status == ILP_OPTIMAL) {
62 double minStartTime = F64_MAX;
66 if (idToStart.size() != idToDuration.size())
69 for (
const auto& p : idToStart)
70 minStartTime = min(minStartTime, p.second);
72 for (
const auto& p : idToStart) {
73 uint32_t aid = p.first;
74 double start = p.second-minStartTime, duration = getValue(idToDuration, aid, caller());
79 for (uint32_t r = 0; r < numberOfRobots; ++r) {
82 for (uint32_t i = 0; i+1 < min(circuit.size(), modes.size()); ++i) {
85 assert(l !=
nullptr && m !=
nullptr && l->parent() !=
nullptr &&
"Pointers should be initialized!");
86 uint32_t point = l->point(), pid = m->pid(), aid = l->parent()->aid();
92 throw_with_nested(
SolverException(caller(),
"Cannot map LP solution to the problem solution!\nCheck the validity of the model..."));
105 vector<Activity*> selDynActs;
108 assert(mv !=
nullptr && mv->parent() !=
nullptr &&
"Invalid initialization of the RoboticLine data-structure!");
111 selDynActs.push_back(da);
124 uint64_t numVars =
mMapper.numberOfVariables();
126 assert(!
mModel.
c.empty() &&
"Default coefficient values must be set even for Gurobi!");
136 for (uint32_t r = 0; r < numberOfRobots; ++r) {
139 for (uint32_t i = 0; i+1 < locs.size(); ++i) {
140 assert(locs[i] !=
nullptr && locs[i]->parent() !=
nullptr && pwrms[i] !=
nullptr &&
"Invalid data structures!");
144 const auto& dit =
mMapper.
d.find(sa->aid());
146 mappedIdx = dit->second;
155 throw SolverException(caller(),
"Cannot find the discretized energy function for the location and power saving mode!");
167 for (uint32_t r = 0; r < numberOfRobots; ++r) {
170 assert(mv->parent() !=
nullptr &&
"Movement should belong to a dynamic activity!");
174 const auto& dit =
mMapper.
d.find(da->aid());
176 mappedIdx = dit->second;
185 throw SolverException(caller(),
"Cannot find discretized movement "+to_string(mv->mid())+
"!");
204 string msg =
"Cannot add constraints to the LP model!\nEither variable mapping or RoboticLine data-structure is corrupted!";
218 if (ps.
locs.size() != numberOfRobots || ps.
pwrms.size() != numberOfRobots || ps.
mvs.size() != numberOfRobots)
219 throw InvalidArgument(caller(),
"Invalid argument 'ps', dimensions mismatch!");
221 for (uint32_t r = 0; r < numberOfRobots; ++r) {
222 if (ps.
locs[r].size() != ps.
pwrms[r].size() || ps.
locs[r].empty())
223 throw InvalidArgument(caller(),
"The number of locations must be the same as the number of power saving modes!");
224 if (ps.
locs[r].size() != ps.
mvs[r].size()+1 || ps.
mvs[r].empty())
225 throw InvalidArgument(caller(),
"The number of movements should be about one less than the number of locations!");
227 const vector<Location*>& locs = ps.
locs[r];
228 const vector<RobotPowerMode*>& pwrms = ps.
pwrms[r];
229 const vector<Movement*>& mvs = ps.
mvs[r];
230 if (count(locs.cbegin(), locs.cend(),
nullptr) != 0 || count(pwrms.cbegin(), pwrms.cend(),
nullptr) != 0 || count(mvs.cbegin(), mvs.cend(),
nullptr) != 0)
231 throw InvalidArgument(caller(),
"Null pointer in the given PartialSolution data-structure!");
234 for (uint32_t i = 0; i+1 < locs.size(); ++i) {
235 Location *from = locs[i], *to = locs[i+1];
239 throw InvalidArgument(caller(),
"Given invalid partial solution to the LP solver!");
244 throw_with_nested(
InvalidArgument(caller(),
"Invalid partial solution, a non-existing movement between two locations!"));
The instance of the class corresponds to a robot movement between two coordinates.
void construct(const PrecalculatedMapping &m, bool addTimeLags=true)
Complete construction of the Linear Programming problem for the energy optimization.
double totalEnergy
The amount of energy required per robot cycle.
void addCollisionResolution(Activity *i, Activity *j, const int32_t &multipleOfCycleTime)
It adds a constraint to resolve a collision where and are start time and duration of the activity ...
The base class incorporating common properties of robot operations and movements. ...
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...
The structure representing a solution found by an algorithm.
Instance of this class includes all the data structures and methods related to a robot.
std::vector< std::vector< Location * > > locs
Selected locations for each robot, time ordered.
ConstraintsGenerator mGenerator
Generator of the constraints.
void addActivities(const std::vector< Activity * > &activities, bool mandatory, bool mapW=true)
It adds the mapping for extra activities.
std::vector< Variable > variables
Continuous variables of the problem with the well-specified domains.
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::map< std::pair< Location *, RobotPowerMode * >, std::tuple< std::vector< double >, std::vector< double > > > locToEnergyFunc
Location and the selected power saving mode are mapped to the linear energy function, i.e. the size of each vector in the tuple is 2.
std::vector< std::vector< RobotPowerMode * > > pwrms
Selected power saving modes of related locations.
Collection of movements between two static activities.
double runTime
Run time (seconds) of the optimization algorithm required for obtaining this solution.
PartialSolution mPartialSolution
Partially fixed problem, or in other words, a partial solution.
Declares LP solver which deals with partially fixed energy optimization problems created by the paral...
State convert(const Status &ilpStatus)
Conversion between the ILP solver status and the solution state.
A general exception of the program.
std::vector< std::string > varDesc
Description of the continuous variables.
std::vector< double > solution
The best found solution.
void addTimeLags(const map1to1 &s, bool allRequired=true)
Time lags enforcing correct time synchronizations between robots are added.
Various auxiliary functions used across the program.
Structure storing a solution of an Integer Linear Programming problem.
std::vector< std::string > varDesc
Optional description of the variables.
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< const std::tuple< std::vector< double >, std::vector< double > > * > gurobiC
Convex functions in the criterion in the format suitable for Gurobi solver.
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...
Solver-independent interface for solving Integer Linear Programming problems.
map1to1 s
Maps activity identification to the index of variable corresponding to the start time of this activit...
Exception is thrown if a method is given invalid parameters or a user provides invalid program argume...
Collection of locations in which a robot operation (or waiting) can be performed. ...
State status
Enum specifying whether the solution is optimal, feasible, or infeasible...
double criterion
The criterion value of the solution.
Fixed locations, power saving modes, and movements.
RoboticLineSolverLP(Robot *r, const PartialSolution &ps, const PrecalculatedMapping &m)
It builds a Linear Programming problem (variables, constraints, criterion) to be solved.
VariableMappingLP mMapper
Mapping of the continuous variables.
It represents the power saving mode of the robot.
It declares the namespace for program settings.
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::vector< double > c
Vector of the criterion coefficients.
std::map< Movement *, std::tuple< std::vector< double >, std::vector< double > > > mvToEnergyFunc
It takes a pointer to a movement and returns the vector of precalculated coordinates corresponding to...
void addVariablesForSelectedDynamicActivities()
It adds additional float variables for optional activities.
ILPModel mModel
Linear Programming problem to be solved.
double upperBound
The maximal value of the variable.
Solution solve() const
The energy optimal timing is determined by solving Linear Programming problem and the solution is ret...
map1to1 W
Maps activity identification to the index of variable corresponding to the energy consumption of this...
map1to1 d
Maps activity identification to the index of variable corresponding to the duration of this activity...
Status status
Solution status, see Status enum.
std::vector< Variable > x
Variables of the problem.
std::vector< std::vector< Movement * > > mvs
Selected movements, implied from the selected locations and their order.
SolutionILP solveILP(const ILPModel &m, bool verbose, double gap=0.0, double timeLimit=0.0, int numberOfThreads=1, int threadId=0)
Integer Linear Programming solver is called to solve the problem and the solution is returned...
void checkFormulation() const
It checks that sizes of vectors and the matrix are valid.
Location of the robot used either during work (welding) or waiting.
The robotic cell corresponds to an instance of this class.
The structure contains the maps for fast searching in the robotic cell.
double lowerBound
The minimal value of the variable.
void checkArguments(const PrecalculatedMapping &m, const uint32_t &numberOfRobots=1u) const
It checks that the arguments passed to the constructor are valid and correct.
Structure containing information about the variable.
std::unordered_map< std::pair< Location *, Location * >, Movement * > locationsToMovement
It finds the movement between two locations if exists.
uint64_t moveConstraintsToModel(ILPModel &m)
It efficiently moves all the generated constraints to the given model.
std::map< uint32_t, std::pair< double, double > > startTimeAndDuration
Mapping of the activity identification to its start time and duration.