| 1 |
#include "SimpleBoundCons.hpp"
|
| 2 |
|
| 3 |
SimpleBoundCons::SimpleBoundCons(int index, double b, bool flag)
|
| 4 |
: ConstraintBase(){
|
| 5 |
|
| 6 |
bound = b;
|
| 7 |
|
| 8 |
consType = simpleBound;
|
| 9 |
|
| 10 |
if (flag){
|
| 11 |
boundType = btUpper;
|
| 12 |
}
|
| 13 |
else{
|
| 14 |
boundType = btLower;
|
| 15 |
}
|
| 16 |
}
|
| 17 |
|
| 18 |
SimpleBoundCons::SimpleBoundCons(int ndim, int index, double b, bool flag)
|
| 19 |
: ConstraintBase(ndim){
|
| 20 |
|
| 21 |
bound = b;
|
| 22 |
|
| 23 |
consType = simpleBound;
|
| 24 |
|
| 25 |
if (flag){
|
| 26 |
boundType = btUpper;
|
| 27 |
}
|
| 28 |
else{
|
| 29 |
boundType = btLower;
|
| 30 |
}
|
| 31 |
}
|
| 32 |
double SimpleBoundCons::calcResidual(vector<double>& x){
|
| 33 |
double residual;
|
| 34 |
|
| 35 |
residual = x[index] - bound;
|
| 36 |
|
| 37 |
if(boundType == btLower)
|
| 38 |
return -residual;
|
| 39 |
else if (boundType == btUpper)
|
| 40 |
return residual;
|
| 41 |
else{
|
| 42 |
cout << "SimpleBoundCons Error: BoundType of SimpleBoundCons can not be btEqu" << endl;
|
| 43 |
exit(ERROR_CONSTRAINT);
|
| 44 |
}
|
| 45 |
}
|
| 46 |
|
| 47 |
vector<double> SimpleBoundCons::calcConsGrad(vector<double>& x){
|
| 48 |
vector<double> result(ndim, 0);
|
| 49 |
|
| 50 |
if(boundType == btLower)
|
| 51 |
result[index] = -1.0;
|
| 52 |
else if (boundType == btUpper)
|
| 53 |
result[index] = 1.0;
|
| 54 |
else{
|
| 55 |
cout << "SimpleBoundCons Error: BoundType of SimpleBoundCons can not be btEqu" << endl;
|
| 56 |
exit(ERROR_CONSTRAINT);
|
| 57 |
}
|
| 58 |
|
| 59 |
return result;
|
| 60 |
}
|
| 61 |
SymMatrix SimpleBoundCons::calcConsHessian(vector<double>& x){
|
| 62 |
SymMatrix H(ndim);
|
| 63 |
H = 0;
|
| 64 |
return H;
|
| 65 |
}
|