diff --git a/CMakeLists.txt b/CMakeLists.txt index fb370f05..9fcac2a1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -244,7 +244,7 @@ if (NLOPT_CXX) src/algs/ags/ags.h src/algs/ags/ags.cc) -set_property(SOURCE src/algs/ags/solver.cc src/algs/ags/local_optimizer.cc src/algs/ags/ags.cc src/algs/slsqp/slsqp.c src/algs/stogo/linalg.cc +set_property(SOURCE src/algs/ags/solver.cc src/algs/ags/local_optimizer.cc src/algs/ags/ags.cc src/algs/slsqp/slsqp.c PROPERTY SKIP_UNITY_BUILD_INCLUSION ON) endif () diff --git a/src/algs/stogo/global.cc b/src/algs/stogo/global.cc index 8b572152..b8e8d0ac 100644 --- a/src/algs/stogo/global.cc +++ b/src/algs/stogo/global.cc @@ -213,11 +213,11 @@ void Global::Search(int axis, RCRVector x_av){ ReduceOrSubdivide(box, axis, x_av); if (!NoMinimizers() && OneMinimizer(x) < stop->minf_max) { - done = TRUE; + done = true; break; } if (!InTime()) { - done=TRUE; + done=true; if (stogo_verbose) cout << "The program has run out of time or function evaluations\n"; break; diff --git a/src/algs/stogo/linalg.cc b/src/algs/stogo/linalg.cc index 04916cf0..7111eb95 100644 --- a/src/algs/stogo/linalg.cc +++ b/src/algs/stogo/linalg.cc @@ -4,7 +4,7 @@ */ #include -#include // for sqrt() +#include // for sqrt() #include "linalg.h" @@ -32,7 +32,9 @@ RVector::RVector() { RVector::RVector(int n) { // Constructor len=n; - elements=new double[len]; (*this)=0.; + if (n > 0) + elements = new double[len]; + (*this)=0.; } RVector::RVector(RCRVector vect) diff --git a/src/algs/stogo/linalg.h b/src/algs/stogo/linalg.h index d5b8d7bb..b8b8b345 100644 --- a/src/algs/stogo/linalg.h +++ b/src/algs/stogo/linalg.h @@ -8,8 +8,8 @@ #include using namespace std; -#include // for sqrt() -#include +#include // for sqrt() +#include typedef const class RVector CRVector; typedef CRVector& RCRVector; @@ -18,17 +18,14 @@ typedef CRMatrix& RCRMatrix; double eps() ; -#define max(A,B) ((A) > (B) ? (A):(B)) -#define min(A,B) ((A) < (B) ? (A):(B)) - /********************* Class RVector *********************/ class RVector{ protected: public: - int len; // size of array - double* elements; // array of values + int len = 0; // size of array + double* elements = nullptr; // array of values RVector() ; RVector(int); // Constructor diff --git a/src/algs/stogo/tools.cc b/src/algs/stogo/tools.cc index 5b49be4f..92c3cb2b 100644 --- a/src/algs/stogo/tools.cc +++ b/src/algs/stogo/tools.cc @@ -96,7 +96,7 @@ double TBox::GetMin() { } bool TBox::EmptyBox() { - // Returns TRUE if the list of Trials is empty + // Returns true if the list of Trials is empty return TList.empty() ; } @@ -137,7 +137,7 @@ void TBox::ClearBox() { } bool TBox::CloseToMin(RVector &vec, double *objval, double eps_cl) { - // Returns TRUE if 'vec' is close to some of the trials in the box, + // Returns true if 'vec' is close to some of the trials in the box, // in this case, 'vec' and 'objval' are overwritten by the Trial data // otherwise 'vec' and 'objval' are not affected. // @@ -155,10 +155,10 @@ bool TBox::CloseToMin(RVector &vec, double *objval, double eps_cl) { if (norm2(y)<=eps_cl) { vec=x; *objval=(*itr).objval; - return TRUE; + return true; } } - return FALSE; + return false; } int TBox::NStationary() { @@ -247,11 +247,11 @@ ostream & operator << (ostream & os, const TBox & B) { } bool TBox::InsideBox(RCRVector x) { - // Returns TRUE if the point X lies inside BOX, FALSE otherwise + // Returns true if the point X lies inside BOX, false otherwise int n=GetDim(); for (int i=0 ; iub(i)) return FALSE; - return TRUE; + if (x(i)ub(i)) return false; + return true; } int TBox::OutsideBox(RCRVector x, RCTBox domain) { @@ -349,7 +349,7 @@ bool TBox::Intersection(RCRVector x, RCRVector h, RCRVector z) { // Due to round of errors the algorithm can fail to find an intersection // The caller is notified and should act accordingly // -// The routine returns FALSE if no intersection was found, TRUE otherwise +// The routine returns false if no intersection was found, true otherwise int n=GetDim(); RVector tmpV(n); @@ -357,8 +357,8 @@ bool TBox::Intersection(RCRVector x, RCRVector h, RCRVector z) { int i, j, k, isect; double alpha, gamma; - i=0; done=FALSE; - while (i0) { - done=TRUE; break; + done=true; break; } } i++; diff --git a/src/algs/stogo/tools.h b/src/algs/stogo/tools.h index dd8dbafc..29f0563c 100644 --- a/src/algs/stogo/tools.h +++ b/src/algs/stogo/tools.h @@ -4,7 +4,7 @@ #ifndef TOOLS_H #define TOOLS_H -#include +#include #include #include @@ -13,13 +13,6 @@ #include "linalg.h" -#ifndef FALSE -const int FALSE=(1==0); // boolean FALSE -#endif -#ifndef FALSE -const int TRUE=(1==1); // boolean TRUE -#endif - typedef const class Trial CTrial; typedef CTrial& RCTrial; typedef CTrial* PCTrial; @@ -36,11 +29,7 @@ class Trial{ friend ostream & operator << (ostream &, RCTrial) ; }; -#if (!defined(_MSC_VER) && (__cplusplus < 201103L)) || (defined(_MSC_VER) && (_MSVC_LANG < 201103L)) -class TrialGT : public unary_function -#else class TrialGT -#endif // Predicate for Trial (needed for remove_if) { public: