00001
00002
00008 #if !defined(__numerical_Exception_h__)
00009 #define __numerical_Exception_h__
00010
00011
00012 #if defined(DEBUG_numerical) && !defined(DEBUG_Exception)
00013 #define DEBUG_Exception
00014 #endif
00015
00016 #include "../defs.h"
00017
00018 #include "../../ads/array/FixedArray.h"
00019
00020 #include <iostream>
00021 #include <string>
00022
00023 BEGIN_NAMESPACE_NUMERICAL
00024
00026 template<int N,
00027 typename T = double,
00028 typename Point = ads::FixedArray<N> >
00029 class OptimizationException {
00030 public:
00031
00032
00033
00034
00035
00037 typedef T number_type;
00039 typedef Point point_type;
00040
00041 private:
00042
00043
00044
00045
00046
00047 std::string _message;
00048 point_type _location;
00049 number_type _value;
00050 int _num_function_calls;
00051
00052
00053
00054
00055
00056
00057 OptimizationException();
00058
00059
00060 OptimizationException&
00061 operator=(const OptimizationException&);
00062
00063 public:
00064
00065
00066
00067
00068
00070 OptimizationException(const char* message, const point_type& location,
00071 const number_type value,
00072 const int num_function_calls) :
00073 _message(message),
00074 _location(location),
00075 _value(value),
00076 _num_function_calls(num_function_calls)
00077 {}
00078
00080 virtual
00081 ~OptimizationException()
00082 {}
00083
00085 virtual
00086 void
00087 print() {
00088 std::cerr << message() << '\n'
00089 << "location = " << location() << '\n'
00090 << "function value = " << value() << '\n'
00091 << "number of function calls = " << num_function_calls()
00092 << '\n';
00093 }
00094
00095
00096
00097
00098
00100 const std::string&
00101 message() const {
00102 return _message;
00103 }
00104
00106 const point_type&
00107 location() const {
00108 return _location;
00109 }
00110
00112 number_type
00113 value() const {
00114 return _value;
00115 }
00116
00118 int
00119 num_function_calls() const {
00120 return _num_function_calls;
00121 }
00122
00123 };
00124
00125
00126
00128 template<int N,
00129 typename T = double,
00130 typename Point = ads::FixedArray<N> >
00131 class PenaltyException {
00132 public:
00133
00134
00135
00136
00137
00139 typedef T number_type;
00141 typedef Point point_type;
00142
00143 private:
00144
00145
00146
00147
00148
00149 std::string _message;
00150 point_type _location;
00151 number_type _function;
00152 number_type _constraint;
00153 number_type _step_size;
00154 number_type _max_constraint_error;
00155 number_type _penalty_parameter;
00156
00157
00158
00159
00160
00161
00162 PenaltyException();
00163
00164
00165 PenaltyException&
00166 operator=(const PenaltyException&);
00167
00168 public:
00169
00170
00171
00172
00173
00175 PenaltyException(const char* message,
00176 const point_type& location,
00177 const number_type function,
00178 const number_type constraint,
00179 const number_type step_size,
00180 const number_type max_constraint_error,
00181 const number_type penalty_parameter) :
00182 _message(message),
00183 _location(location),
00184 _function(function),
00185 _constraint(constraint),
00186 _step_size(step_size),
00187 _max_constraint_error(max_constraint_error),
00188 _penalty_parameter(penalty_parameter)
00189 {}
00190
00192 virtual
00193 ~PenaltyException()
00194 {}
00195
00197 virtual
00198 void
00199 print() {
00200 std::cerr << _message << '\n'
00201 << "location = " << _location << '\n'
00202 << "function value = " << _function << '\n'
00203 << "constraint value = " << _constraint << '\n'
00204 << "step size = " << _step_size << '\n'
00205 << "max constraint error = " << _max_constraint_error
00206 << '\n'
00207 << "penalty parameter = " << _penalty_parameter << '\n'
00208 << '\n';
00209 }
00210
00211 };
00212
00213 END_NAMESPACE_NUMERICAL
00214
00215 #endif