jamhurijamal
New Member
- Joined
- May 5, 2021
- Messages
- 1
- Office Version
- 365
- Platform
- Windows
Hye,
I'm having trouble converting the C++ coding.
Could anyone please help me in converting the C++ to VBA?
Thank you.
// Definition of Fitness Functions
double func(double x[][pop], int i)
{
NumOfEvalCounter++;
double y ;
y = x[0] * (pow(x[1], 4) - 0.8*pow(x[2], 4) - 0.0000000263396);
//y = -y;
return y;
}
double randfunc(double xs, double xe) // Definition of Random number Generator Function
{
double randnum;
randnum = rand();
randnum = xs + randnum*(xe - xs) / RAND_MAX;
return randnum;
}
double myrandom()
{
double r;
int M, x;
M = 10000;
x = M - 2;
r = (1.0 + (rand() % x)) / M;
return r;
}
void funcSort(double inP1[], double oP1[], double inP2[][pop], double oP2[][pop], int size)
{
// double temp1=inP1[0];
int temp2;
double temp1 = -INT_MAX;
for (int j = 0; j<size; j++) //sort
{
for (int k = 0; k<size; k++)
if (inP1[k]> temp1)
{
temp1 = inP1[k];
temp2 = k;
}
oP1[j] = temp1;
for (int d = 0; d<dim; d++)
oP2[d][j] = inP2[d][temp2];
temp1 = -INT_MAX;
inP1[temp2] = -INT_MAX;
} //end sort
}
I'm having trouble converting the C++ coding.
Could anyone please help me in converting the C++ to VBA?
Thank you.
// Definition of Fitness Functions
double func(double x[][pop], int i)
{
NumOfEvalCounter++;
double y ;
y = x[0] * (pow(x[1], 4) - 0.8*pow(x[2], 4) - 0.0000000263396);
//y = -y;
return y;
}
double randfunc(double xs, double xe) // Definition of Random number Generator Function
{
double randnum;
randnum = rand();
randnum = xs + randnum*(xe - xs) / RAND_MAX;
return randnum;
}
double myrandom()
{
double r;
int M, x;
M = 10000;
x = M - 2;
r = (1.0 + (rand() % x)) / M;
return r;
}
void funcSort(double inP1[], double oP1[], double inP2[][pop], double oP2[][pop], int size)
{
// double temp1=inP1[0];
int temp2;
double temp1 = -INT_MAX;
for (int j = 0; j<size; j++) //sort
{
for (int k = 0; k<size; k++)
if (inP1[k]> temp1)
{
temp1 = inP1[k];
temp2 = k;
}
oP1[j] = temp1;
for (int d = 0; d<dim; d++)
oP2[d][j] = inP2[d][temp2];
temp1 = -INT_MAX;
inP1[temp2] = -INT_MAX;
} //end sort
}