Skip to content

Commit

Permalink
stogo: avoid old C macros
Browse files Browse the repository at this point in the history
  • Loading branch information
jschueller committed Nov 14, 2024
1 parent ab0fd1c commit 75dd16e
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 35 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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 ()

Expand Down
4 changes: 2 additions & 2 deletions src/algs/stogo/global.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 4 additions & 2 deletions src/algs/stogo/linalg.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*/

#include <iostream>
#include <math.h> // for sqrt()
#include <cmath> // for sqrt()

#include "linalg.h"

Expand Down Expand Up @@ -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)
Expand Down
11 changes: 4 additions & 7 deletions src/algs/stogo/linalg.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@

#include <iostream>
using namespace std;
#include <math.h> // for sqrt()
#include <float.h>
#include <cmath> // for sqrt()
#include <cfloat>

typedef const class RVector CRVector;
typedef CRVector& RCRVector;
Expand All @@ -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
Expand Down
22 changes: 11 additions & 11 deletions src/algs/stogo/tools.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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() ;
}

Expand Down Expand Up @@ -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.
//
Expand All @@ -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() {
Expand Down Expand Up @@ -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 ; i<n ; i++)
if (x(i)<lb(i) || x(i)>ub(i)) return FALSE;
return TRUE;
if (x(i)<lb(i) || x(i)>ub(i)) return false;
return true;
}

int TBox::OutsideBox(RCRVector x, RCTBox domain) {
Expand Down Expand Up @@ -349,16 +349,16 @@ 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);
bool done;
int i, j, k, isect;
double alpha, gamma;

i=0; done=FALSE;
while (i<n && done==FALSE) {
i=0; done=false;
while (i<n && done==false) {
if (h(i)==0) {
z(i)=x(i);
break;
Expand All @@ -382,7 +382,7 @@ bool TBox::Intersection(RCRVector x, RCRVector h, RCRVector z) {
}
copy(z,tmpV); axpy(-1.0,x,tmpV); // tmpV=z-x
if (isect==1 && dot(tmpV,h)>0) {
done=TRUE; break;
done=true; break;
}
}
i++;
Expand Down
13 changes: 1 addition & 12 deletions src/algs/stogo/tools.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#ifndef TOOLS_H
#define TOOLS_H

#include <float.h>
#include <cfloat>
#include <iostream>

#include <algorithm>
Expand All @@ -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;
Expand All @@ -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<Trial, bool>
#else
class TrialGT
#endif
// Predicate for Trial (needed for remove_if)
{
public:
Expand Down

0 comments on commit 75dd16e

Please sign in to comment.