solver  1.0
Exceptions.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_EXCEPTIONS_H
19 #define HLIDAC_PES_EXCEPTIONS_H
20 
27 #include <algorithm>
28 #include <iterator>
29 #include <stdexcept>
30 #include <string>
31 #include <vector>
32 #include <stdint.h>
33 
40 std::vector<std::string> split(const std::string& toSplit, const char& delim);
41 
49 std::string concat(const std::vector<std::string>& toConcat, const std::string& beforeItem, const std::string& afterItem);
50 
51 
58 class SolverException : public std::exception {
59  public:
66  SolverException(const std::string& caller, const std::string& msg) {
67  std::vector<std::string> splitCaller = split(caller, '\n'), splitMsg = split(msg, '\n');
68  std::copy(splitCaller.cbegin(), splitCaller.cend(), std::back_inserter(mWhat));
69  std::copy(splitMsg.cbegin(), splitMsg.cend(), std::back_inserter(mWhat));
70  mWhatStr = concat(mWhat, "", "\n");
71  }
72 
74  virtual const char* what() const throw() { return mWhatStr.c_str(); }
80  virtual std::string whatIndented(uint32_t level = 0) const throw() {
81  return concat(mWhat, std::string(level, '\t'), "\n");
82  }
83 
85  virtual ~SolverException() throw() { }
86  protected:
88  std::string mWhatStr;
90  std::vector<std::string> mWhat;
91 };
92 
100  public:
108  InvalidDatasetFile(const std::string& caller, const std::string& msg, int64_t lineNumber = -1) : SolverException(caller, msg), mLineNumber(lineNumber) {
109  if (mLineNumber != -1)
110  mWhat.push_back("The error occured around the line "+std::to_string(mLineNumber)+" in the input dataset file!");
111  }
112 
113  virtual ~InvalidDatasetFile() throw() { }
114  protected:
116  int64_t mLineNumber;
117 };
118 
121  public:
122  InvalidArgument(const std::string& caller, const std::string& msg) : SolverException(caller, msg) { }
123  virtual ~InvalidArgument() throw() { }
124 };
125 
128  public:
129  ILPSolverException(const std::string& caller, const std::string& msg) : SolverException(caller, msg) { }
130  virtual ~ILPSolverException() throw() { }
131 };
132 
135  public:
136  NoFeasibleSolutionExists(const std::string& caller, const std::string& msg) : SolverException(caller, msg) { }
137  virtual ~NoFeasibleSolutionExists() throw() { }
138 };
139 
142  public:
143  EmptySolutionPool(const std::string& caller, const std::string& msg) : SolverException(caller, msg) { }
144  virtual ~EmptySolutionPool() throw() { }
145 };
146 
153 std::string exceptionToString(const std::exception& e, uint32_t level = 0);
154 
155 #endif
std::string mWhatStr
The formated error message without an indentation.
Definition: Exceptions.h:88
virtual ~SolverException()
Virtual destructor is mandatory due to the polymorphism.
Definition: Exceptions.h:85
InvalidDatasetFile(const std::string &caller, const std::string &msg, int64_t lineNumber=-1)
Constructs a specialized exception for error handling of ill-specified datasets.
Definition: Exceptions.h:108
std::string exceptionToString(const std::exception &e, uint32_t level=0)
The recursive method creates the formatted error message for the given exception and their nested sub...
Definition: Exceptions.cpp:49
A general exception of the program.
Definition: Exceptions.h:58
Thrown if the dataset file contains ill-specified robotic cells.
Definition: Exceptions.h:99
std::vector< std::string > split(const std::string &toSplit, const char &delim)
It splits the input string, e.g. split("abc ab c", ' ') -> {"abc", "ab", "c"}.
Definition: Exceptions.cpp:24
Exception is thrown if a method is given invalid parameters or a user provides invalid program argume...
Definition: Exceptions.h:120
Exception dedicated to problems with Integer Linear Programming solvers.
Definition: Exceptions.h:127
Thrown if no feasible solution is found by the heuristic.
Definition: Exceptions.h:134
std::vector< std::string > mWhat
Individual lines of the error message.
Definition: Exceptions.h:90
int64_t mLineNumber
Error occurred at this line in the XML file.
Definition: Exceptions.h:116
virtual std::string whatIndented(uint32_t level=0) const
Virtual function returning the formatted error message.
Definition: Exceptions.h:80
SolverException(const std::string &caller, const std::string &msg)
Constructs the exception, it comprises building of the error string and vector of lines...
Definition: Exceptions.h:66
std::string concat(const std::vector< std::string > &toConcat, const std::string &beforeItem, const std::string &afterItem)
Method concatenates the given strings, e.g. concat({"abc", "ab"}, "\t", "\n") -> "\tabc\n\tab".
Definition: Exceptions.cpp:34
virtual const char * what() const
Virtual method returns the error message without an indentation.
Definition: Exceptions.h:74
Thrown if the best solution of the heuristic cannot be returned since the solution pool is empty...
Definition: Exceptions.h:141