Skip to content

Commit

Permalink
Get rid of unused code
Browse files Browse the repository at this point in the history
  • Loading branch information
sovrasov committed Jul 17, 2018
1 parent 038f607 commit fca7b8f
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 184 deletions.
2 changes: 1 addition & 1 deletion src/algs/ags/ags.cc
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ int ags_minimize(unsigned n, nlopt_func func, void *data, unsigned m, nlopt_cons
try
{
auto external_stop_func = [stop, &ret_code](){
if (nlopt_stop_evalstime(stop)) {
if (nlopt_stop_time(stop)) {
ret_code = NLOPT_MAXTIME_REACHED;
return true;
}
Expand Down
173 changes: 2 additions & 171 deletions src/algs/ags/evolvent.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ Copyright (C) 2018 Sovrasov V. - All Rights Reserved
using namespace ags;

void mapd(double x, int m, double* y, int n, int key = 1); /* map x to y */
void invmad(int, double [], int, int *, double [], int, int); /* map y to x */
void xyd(double *xx, int m, double y[], int n); /* get preimage */

Evolvent::Evolvent()
{
Expand All @@ -25,15 +23,13 @@ Evolvent::~Evolvent()
{
}

Evolvent::Evolvent(int dimension, int tightness, const double* lb, const double* ub, MapType type)
Evolvent::Evolvent(int dimension, int tightness, const double* lb, const double* ub)
{
assert(tightness > 2);

mDimension = dimension;
mTightness = tightness;
mMapType = type;

p2.resize(mDimension);
mShiftScalars.resize(mDimension);
mRho.resize(mDimension);
for (int i = 0; i < mDimension; i++)
Expand All @@ -42,19 +38,6 @@ Evolvent::Evolvent(int dimension, int tightness, const double* lb, const double*
mShiftScalars[i] = 0.5*(lb[i] + ub[i]);
}

switch (mMapType)
{
case Simple:
mMapKey = 1;
break;
case Linear:
mMapKey = 2;
break;
case Noninjective:
mMapKey = 3;
break;
}

mIsInitialized = true;
}

Expand All @@ -73,165 +56,13 @@ void Evolvent::TransformToSearchDomain(const double *y, double *z)
void Evolvent::GetImage(double x, double y[])
{
if(mDimension != 1)
mapd(x, mTightness, y, mDimension, mMapKey);
mapd(x, mTightness, y, mDimension);
else
y[0] = x - 0.5;

TransformToSearchDomain(y, y);
}

int Evolvent::GetAllPreimages(const double *p, double xp[])
{
int preimNumber = 1;
TransformToStandardCube(p, p2.data());
if(mMapType == Noninjective)
invmad(mTightness, xp, noninjectiveMaxPreimages, &preimNumber, p2.data(), mDimension, 4);
else
xyd(xp, mTightness, p2.data(), mDimension);

return preimNumber;
}

void xyd(double *xx, int m, double y[], int n)
{
/* calculate preimage x for nearest level m center to y */
/* (x - left boundary point of level m interval) */
int n1, nexp, l, iu[10], iv[10];

double x, r1;
double r;
int iw[11];
int i, j, it, is;
void numbr(int *, const int, const int, int&, int*, int*);

n1 = n - 1;
for (nexp = 1, i = 0; i<n; i++) {
nexp *= 2; iw[i] = 1;
}
r = 0.5;
r1 = 1.0;
x = 0.0;
it = 0;
for (j = 0; j<m; j++) {
r *= 0.5;
for (i = 0; i<n; i++) {
iu[i] = (y[i]<0) ? -1 : 1;
y[i] -= r*iu[i];
iu[i] *= iw[i];
}
i = iu[0];
iu[0] = iu[it];
iu[it] = i;
numbr(&is, n1, nexp, l, iu, iv);
i = iv[0];
iv[0] = iv[it];
iv[it] = i;
for (i = 0; i<n; i++)
iw[i] = -iw[i] * iv[i];
if (l == 0) l = it;
else if (l == it) l = 0;
it = l;
r1 = r1 / nexp;
x += r1*is;
}
*xx = x;
}
void numbr(int *iss, const int n1, const int nexp, int& l, int* iu, int* iv)
{
/* calculate s(u)=is,l(u)=l,v(u)=iv by u=iu */

int i, n, is, iff, k1, k2, l1;

n = n1 + 1;
iff = nexp;
is = 0;
k1 = -1;
for (i = 0; i<n; i++) {
iff = iff / 2;
k2 = -k1*iu[i];
iv[i] = iu[i];
k1 = k2;
if (k2<0) l1 = i;
else { is += iff; l = i; }
}
if (is == 0) l = n1;
else {
iv[n1] = -iv[n1];
if (is == (nexp - 1)) l = n1;
else if (l1 == n1) iv[l] = -iv[l];
else l = l1;
}
*iss = is;
}

void invmad(int m, double xp[], int kp,
int *kxx, double p[], int n, int incr)
{
/* calculate kx preimage p node */
/* node type mapping m level */

double mne, d1, dd, x, dr, del;// , convers;
double r, d, u[10], y[10];
int i, k, kx, nexp;
void xyd(double *, int, double *, int);

kx = 0;
kp--;
for (nexp = 1, i = 0; i<n; i++) {
nexp *= 2; u[i] = -1.0;
}
dr = nexp;
for (mne = 1, r = 0.5, i = 0; i<m; i++) {
mne *= dr; r *= 0.5;
}
dr = mne / nexp;

dr = dr - fmod(dr, 1.0);
//dr = (dr>0) ? floor(dr) : ceil(dr);

del = 1. / (mne - dr);
d1 = del*(incr + 0.5);
for (kx = -1; kx<kp;) {
for (i = 0; i<n; i++) { /* label 2 */
d = p[i];
y[i] = d - r*u[i];
}
for (i = 0; (i<n) && (fabs(y[i]) < 0.5); i++);
if (i >= n) {
xyd(&x, m, y, n);
dr = x*mne;
dd = dr - fmod(dr, 1.0);
//dd = (dr>0) ? floor(dr) : ceil(dr);
dr = dd / nexp;
dd = dd - dr + fmod(dr, 1.0);
//dd = dd - ((dr>0) ? floor(dr) : ceil(dr));
x = dd*del;
if (kx>kp) break;
k = kx++; /* label 9 */
if (kx == 0) xp[0] = x;
else {
while (k >= 0) {
dr = fabs(x - xp[k]); /* label 11 */
if (dr <= d1) {
for (kx--; k<kx; k++, xp[k] = xp[k + 1]);
goto m6;
}
else
if (x <= xp[k]) {
xp[k + 1] = xp[k]; k--;
}
else break;
}
xp[k + 1] = x;
}
}
m6: for (i = n - 1; (i >= 0) && (u[i] = (u[i] <= 0.0) ? 1 : -1)<0; i--);
if (i<0)break;
}
*kxx = ++kx;

}

void mapd(double x, int m, double* y, int n, int key)
{
/* mapping y(x) : 1 - center, 2 - line, 3 - node */
Expand Down
13 changes: 1 addition & 12 deletions src/algs/ags/evolvent.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,6 @@ Copyright (C) 2018 Sovrasov V. - All Rights Reserved
namespace ags
{

enum MapType {
Simple = 1, Linear = 2, Noninjective = 3
};

constexpr int noninjectiveMaxPreimages = 32;

class Evolvent
{
protected:
Expand All @@ -26,23 +20,18 @@ class Evolvent

std::vector<double> mRho;
std::vector<double> mShiftScalars;
std::vector<double> p2;

void TransformToStandardCube(const double *y, double *z);
void TransformToSearchDomain(const double *y, double *z);

bool mIsInitialized;
private:
MapType mMapType;
int mMapKey;

public:
Evolvent();
Evolvent(int dimension, int tightness, const double* lb, const double* ub, MapType type = Simple);
Evolvent(int dimension, int tightness, const double* lb, const double* ub);
~Evolvent();

virtual void GetImage(double x, double y[]);
virtual int GetAllPreimages(const double* p, double xp[]);
};

}

0 comments on commit fca7b8f

Please sign in to comment.