Skip to content

Commit

Permalink
Codacy-suggested fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Dimitri Rusin committed Nov 13, 2023
1 parent cbfb3fb commit a19c1f3
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 30 deletions.
1 change: 0 additions & 1 deletion include/ioh/problem/cec/hybrid_function_1.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ namespace ioh::problem::cec
int nx = x.size();
std::vector<double> z(nx);
std::vector<double> y(nx);
std::vector<double> fit(cf_num);
std::vector<int> G(cf_num);
std::vector<int> G_nx(cf_num);
std::vector<double> Gp = {0.4, 0.4, 0.2};
Expand Down
1 change: 0 additions & 1 deletion include/ioh/problem/cec/hybrid_function_3.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ namespace ioh::problem::cec
auto&& S = this->input_permutation_;

const int cf_num = 5;
std::vector<double> fit(cf_num, 0);
std::vector<int> G_nx(cf_num);
std::vector<int> G(cf_num);
std::vector<double> Gp = {0.3, 0.2, 0.2, 0.1, 0.2};
Expand Down
3 changes: 1 addition & 2 deletions include/ioh/problem/functions/real.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,6 @@ inline double zakharov(const std::vector<double> &x) {
*/
inline double schaffer_F7(const std::vector<double> &y) {
std::vector<double> z(y.size());
double tmp;

double result = 0;
for (size_t i = 0; i < z.size() - 1; ++i) {
Expand All @@ -163,7 +162,7 @@ inline double schaffer_F7(const std::vector<double> &y) {

auto pow_val = std::pow(z[i], 0.2);

tmp = std::sin(50.0 * pow_val);
double tmp = std::sin(50.0 * pow_val);

auto tmp_squared = tmp * tmp;

Expand Down
44 changes: 21 additions & 23 deletions tests/cpp/problem/set_cec_problems.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ int ini_flag,n_flag,func_flag,*SS;
void cec22_test_func(double *x, double *f, int nx, int mx,int func_num)
{

int cf_num=12,i,j;
int cf_num=12,i;
if (func_num<1||func_num>12)
{
printf("\nError: Test function %d is not defined.\n", func_num);
Expand All @@ -127,9 +127,9 @@ void cec22_test_func(double *x, double *f, int nx, int mx,int func_num)
free(y);
free(z);
free(x_bound);
y=(double *)malloc(sizeof(double) * nx);
z=(double *)malloc(sizeof(double) * nx);
x_bound=(double *)malloc(sizeof(double) * nx);
y = static_cast<double*>(malloc(nx * sizeof(double)));
z = static_cast<double*>(malloc(nx * sizeof(double)));
x_bound = static_cast<double*>(malloc(nx * sizeof(double)));
for (i=0; i<nx; i++)
x_bound[i]=100.0;

Expand All @@ -151,7 +151,7 @@ void cec22_test_func(double *x, double *f, int nx, int mx,int func_num)
}
if (func_num<9)
{
M=(double*)malloc(nx*nx*sizeof(double));
M = static_cast<double*>(malloc(nx * nx * sizeof(double)));
if (M==NULL)
printf("\nError: there is insufficient memory available!\n");
for (i=0; i<nx*nx; i++)
Expand All @@ -161,7 +161,7 @@ void cec22_test_func(double *x, double *f, int nx, int mx,int func_num)
}
else
{
M=(double*)malloc(cf_num*nx*nx*sizeof(double));
M = static_cast<double*>(malloc(cf_num * nx * nx * sizeof(double)));
if (M==NULL)
printf("\nError: there is insufficient memory available!\n");
for (i=0; i<cf_num*nx*nx; i++)
Expand All @@ -181,7 +181,7 @@ void cec22_test_func(double *x, double *f, int nx, int mx,int func_num)

if (func_num<9)
{
OShift=(double *)malloc(nx*sizeof(double));
OShift = static_cast<double*>(malloc(nx * sizeof(double)));
if (OShift==NULL)
printf("\nError: there is insufficient memory available!\n");
for(i=0;i<nx;i++)
Expand All @@ -192,19 +192,19 @@ void cec22_test_func(double *x, double *f, int nx, int mx,int func_num)
else
{
//OShift=(double *)malloc(nx*sizeof(double));
OShift=(double *)malloc(nx*cf_num*sizeof(double));
OShift = static_cast<double*>(malloc(nx * cf_num * sizeof(double)));
if (OShift==NULL)
printf("\nError: there is insufficient memory available!\n");
for(i=0;i<cf_num-1;i++)
{
for (j=0;j<nx;j++)
for (int j=0;j<nx;j++)
{
fscanf(fpt,"%lf",&OShift[i*nx+j]);

}
fscanf(fpt,"%*[^\n]%*c");
}
for (j=0;j<nx;j++)
for (int j=0;j<nx;j++)
{
fscanf(fpt,"%lf",&OShift[nx*(cf_num-1)+j]);

Expand All @@ -224,7 +224,7 @@ void cec22_test_func(double *x, double *f, int nx, int mx,int func_num)
{
printf("\n Error: Cannot open shuffle_data_%d_D%d.txt for reading \n", func_num, nx);
}
SS=(int *)malloc(nx*sizeof(int));
SS = static_cast<int*>(malloc(nx * sizeof(int)));
if (SS==NULL)
printf("\nError: there is insufficient memory available!\n");
for(i=0;i<nx;i++)
Expand Down Expand Up @@ -346,15 +346,14 @@ void discus_func (double *x, double *f, int nx, double *Os,double *Mr, int s_fla
void rosenbrock_func (double *x, double *f, int nx, double *Os,double *Mr,int s_flag, int r_flag) /* Rosenbrock's */
{
int i;
double tmp1,tmp2;
f[0] = 0.0;
sr_func (x, z, nx, Os, Mr, 2.048/100.0, s_flag, r_flag); /* shift and rotate */
z[0] += 1.0;//shift to orgin
for (i=0; i<nx-1; i++)
{
z[i+1] += 1.0;//shift to orgin
tmp1=z[i]*z[i]-z[i+1];
tmp2=z[i]-1.0;
double tmp1=z[i]*z[i]-z[i+1];
double tmp2=z[i]-1.0;
f[0] += 100.0*tmp1*tmp1 +tmp2*tmp2;
}
}
Expand Down Expand Up @@ -536,13 +535,12 @@ void hgbat_func (double *x, double *f, int nx, double *Os,double *Mr,int s_flag,
void schaffer_F7_func (double *x, double *f, int nx, double *Os,double *Mr,int s_flag, int r_flag) /* Schwefel's 1.2 */
{
int i;
double tmp;
f[0] = 0.0;
sr_func (x, z, nx, Os, Mr, 0.5/100, s_flag, r_flag); /* shift and rotate */
for (i=0; i<nx-1; i++)
{
z[i]=pow(y[i]*y[i]+y[i+1]*y[i+1],0.5);
tmp=sin(50.0*pow(z[i],0.2));
double tmp=sin(50.0*pow(z[i],0.2));
f[0] += pow(z[i],0.5)+pow(z[i],0.5)*tmp*tmp ;
}
f[0] = f[0]*f[0]/(nx-1)/(nx-1);
Expand Down Expand Up @@ -573,7 +571,7 @@ void levy_func (double *x, double *f, int nx, double *Os,double *Mr, int s_flag,
sr_func (x, z, nx, Os, Mr,5.12/100, s_flag, r_flag); /* shift and rotate */

double *w;
w=(double *)malloc(sizeof(double) * nx);
w = static_cast<double*>(malloc(sizeof(double) * nx));

for (i=0; i<nx; i++)
{
Expand Down Expand Up @@ -616,19 +614,19 @@ void zakharov_func (double *x, double *f, int nx, double *Os,double *Mr, int s_f
void katsuura_func (double *x, double *f, int nx, double *Os,double *Mr,int s_flag, int r_flag) /* Katsuura */
{
int i,j;
double temp,tmp1,tmp2,tmp3;
double tmp1;
f[0]=1.0;
tmp3=pow(1.0*nx,1.2);
double tmp3=pow(1.0*nx,1.2);

sr_func (x, z, nx, Os, Mr, 5.0/100.0, s_flag, r_flag); /* shift and rotate */

for (i=0; i<nx; i++)
{
temp=0.0;
double temp=0.0;
for (j=1; j<=32; j++)
{
tmp1=pow(2.0,j);
tmp2=tmp1*z[i];
double tmp2=tmp1*z[i];
temp += fabs(tmp2-floor(tmp2+0.5))/tmp1;
}
f[0] *= pow(1.0+(i+1)*temp,10.0/tmp3);
Expand Down Expand Up @@ -979,7 +977,7 @@ void cf_cal(double *x, double *f, int nx, double *Os,double * delta,double * bia
int i,j;
double *w;
double w_max=0,w_sum=0;
w=(double *)malloc(cf_num * sizeof(double));
w = static_cast<double*>(malloc(cf_num * sizeof(double))); // Re-allocation for w
for (i=0; i<cf_num; i++)
{
fit[i]+=bias[i];
Expand Down Expand Up @@ -1036,7 +1034,7 @@ int main(void)
int nx = instance_input.size();
if (nx == 2 && (func_num == 6 || func_num == 7 || func_num == 8)) { continue; }

double *f = (double *)malloc(sizeof(double) * 1);
double* f = static_cast<double*>(malloc(sizeof(double)));
cec22_test_func(instance_input.data(), f, nx, 1, func_num);

std::stringstream ss;
Expand Down
4 changes: 1 addition & 3 deletions workflows.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@


You might get this error message:
```sh
CMake Error at CMakeLists.txt:52 (add_subdirectory):
Expand Down Expand Up @@ -76,7 +74,7 @@ g++ -o one_max -g -std=c++17 -I$fmt_include_path -I$ioh_include_path one_max.cpp
```

g++ version
```
```sh
g++ 9.4.0
```

Expand Down

0 comments on commit a19c1f3

Please sign in to comment.