Skip to content

Commit 75dd16e

Browse files
committed
stogo: avoid old C macros
1 parent ab0fd1c commit 75dd16e

File tree

6 files changed

+23
-35
lines changed

6 files changed

+23
-35
lines changed

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ if (NLOPT_CXX)
244244
src/algs/ags/ags.h
245245
src/algs/ags/ags.cc)
246246

247-
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
247+
set_property(SOURCE src/algs/ags/solver.cc src/algs/ags/local_optimizer.cc src/algs/ags/ags.cc src/algs/slsqp/slsqp.c
248248
PROPERTY SKIP_UNITY_BUILD_INCLUSION ON)
249249
endif ()
250250

src/algs/stogo/global.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -213,11 +213,11 @@ void Global::Search(int axis, RCRVector x_av){
213213
ReduceOrSubdivide(box, axis, x_av);
214214

215215
if (!NoMinimizers() && OneMinimizer(x) < stop->minf_max) {
216-
done = TRUE;
216+
done = true;
217217
break;
218218
}
219219
if (!InTime()) {
220-
done=TRUE;
220+
done=true;
221221
if (stogo_verbose)
222222
cout << "The program has run out of time or function evaluations\n";
223223
break;

src/algs/stogo/linalg.cc

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
*/
55

66
#include <iostream>
7-
#include <math.h> // for sqrt()
7+
#include <cmath> // for sqrt()
88

99
#include "linalg.h"
1010

@@ -32,7 +32,9 @@ RVector::RVector() {
3232
RVector::RVector(int n) {
3333
// Constructor
3434
len=n;
35-
elements=new double[len]; (*this)=0.;
35+
if (n > 0)
36+
elements = new double[len];
37+
(*this)=0.;
3638
}
3739

3840
RVector::RVector(RCRVector vect)

src/algs/stogo/linalg.h

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88

99
#include <iostream>
1010
using namespace std;
11-
#include <math.h> // for sqrt()
12-
#include <float.h>
11+
#include <cmath> // for sqrt()
12+
#include <cfloat>
1313

1414
typedef const class RVector CRVector;
1515
typedef CRVector& RCRVector;
@@ -18,17 +18,14 @@ typedef CRMatrix& RCRMatrix;
1818

1919
double eps() ;
2020

21-
#define max(A,B) ((A) > (B) ? (A):(B))
22-
#define min(A,B) ((A) < (B) ? (A):(B))
23-
2421
/********************* Class RVector *********************/
2522

2623
class RVector{
2724
protected:
2825

2926
public:
30-
int len; // size of array
31-
double* elements; // array of values
27+
int len = 0; // size of array
28+
double* elements = nullptr; // array of values
3229

3330
RVector() ;
3431
RVector(int); // Constructor

src/algs/stogo/tools.cc

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ double TBox::GetMin() {
9696
}
9797

9898
bool TBox::EmptyBox() {
99-
// Returns TRUE if the list of Trials is empty
99+
// Returns true if the list of Trials is empty
100100
return TList.empty() ;
101101
}
102102

@@ -137,7 +137,7 @@ void TBox::ClearBox() {
137137
}
138138

139139
bool TBox::CloseToMin(RVector &vec, double *objval, double eps_cl) {
140-
// Returns TRUE if 'vec' is close to some of the trials in the box,
140+
// Returns true if 'vec' is close to some of the trials in the box,
141141
// in this case, 'vec' and 'objval' are overwritten by the Trial data
142142
// otherwise 'vec' and 'objval' are not affected.
143143
//
@@ -155,10 +155,10 @@ bool TBox::CloseToMin(RVector &vec, double *objval, double eps_cl) {
155155
if (norm2(y)<=eps_cl) {
156156
vec=x;
157157
*objval=(*itr).objval;
158-
return TRUE;
158+
return true;
159159
}
160160
}
161-
return FALSE;
161+
return false;
162162
}
163163

164164
int TBox::NStationary() {
@@ -247,11 +247,11 @@ ostream & operator << (ostream & os, const TBox & B) {
247247
}
248248

249249
bool TBox::InsideBox(RCRVector x) {
250-
// Returns TRUE if the point X lies inside BOX, FALSE otherwise
250+
// Returns true if the point X lies inside BOX, false otherwise
251251
int n=GetDim();
252252
for (int i=0 ; i<n ; i++)
253-
if (x(i)<lb(i) || x(i)>ub(i)) return FALSE;
254-
return TRUE;
253+
if (x(i)<lb(i) || x(i)>ub(i)) return false;
254+
return true;
255255
}
256256

257257
int TBox::OutsideBox(RCRVector x, RCTBox domain) {
@@ -349,16 +349,16 @@ bool TBox::Intersection(RCRVector x, RCRVector h, RCRVector z) {
349349
// Due to round of errors the algorithm can fail to find an intersection
350350
// The caller is notified and should act accordingly
351351
//
352-
// The routine returns FALSE if no intersection was found, TRUE otherwise
352+
// The routine returns false if no intersection was found, true otherwise
353353

354354
int n=GetDim();
355355
RVector tmpV(n);
356356
bool done;
357357
int i, j, k, isect;
358358
double alpha, gamma;
359359

360-
i=0; done=FALSE;
361-
while (i<n && done==FALSE) {
360+
i=0; done=false;
361+
while (i<n && done==false) {
362362
if (h(i)==0) {
363363
z(i)=x(i);
364364
break;
@@ -382,7 +382,7 @@ bool TBox::Intersection(RCRVector x, RCRVector h, RCRVector z) {
382382
}
383383
copy(z,tmpV); axpy(-1.0,x,tmpV); // tmpV=z-x
384384
if (isect==1 && dot(tmpV,h)>0) {
385-
done=TRUE; break;
385+
done=true; break;
386386
}
387387
}
388388
i++;

src/algs/stogo/tools.h

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
#ifndef TOOLS_H
55
#define TOOLS_H
66

7-
#include <float.h>
7+
#include <cfloat>
88
#include <iostream>
99

1010
#include <algorithm>
@@ -13,13 +13,6 @@
1313

1414
#include "linalg.h"
1515

16-
#ifndef FALSE
17-
const int FALSE=(1==0); // boolean FALSE
18-
#endif
19-
#ifndef FALSE
20-
const int TRUE=(1==1); // boolean TRUE
21-
#endif
22-
2316
typedef const class Trial CTrial;
2417
typedef CTrial& RCTrial;
2518
typedef CTrial* PCTrial;
@@ -36,11 +29,7 @@ class Trial{
3629
friend ostream & operator << (ostream &, RCTrial) ;
3730
};
3831

39-
#if (!defined(_MSC_VER) && (__cplusplus < 201103L)) || (defined(_MSC_VER) && (_MSVC_LANG < 201103L))
40-
class TrialGT : public unary_function<Trial, bool>
41-
#else
4232
class TrialGT
43-
#endif
4433
// Predicate for Trial (needed for remove_if)
4534
{
4635
public:

0 commit comments

Comments
 (0)