// Constructors F19_rotated_hybrid_composition_2_narrow_basin_global_opt::F19_rotated_hybrid_composition_2_narrow_basin_global_opt (int dimension, double bias) { m_dimension = dimension; m_bias = bias; m_func_name = FUNCTION_NAME19; // Note: dimension starts from 0 m_o = new double*[NUM_FUNC]; for(int i=0;i<NUM_FUNC;++i) m_o[i] = new double[m_dimension]; m_M = new double**[NUM_FUNC]; for(int i=0;i<NUM_FUNC;++i) { m_M[i] = new double*[m_dimension]; for(int j=0;j<m_dimension;++j) m_M[i][j] = new double[m_dimension]; } m_testPoint = new double[m_dimension]; m_testPointM = new double[m_dimension]; m_fmax = new double[NUM_FUNC]; m_w = new double[NUM_FUNC]; m_z = new double*[NUM_FUNC]; for(int i=0;i<NUM_FUNC;++i) m_z[i] = new double[m_dimension]; m_zM = new double*[NUM_FUNC]; for(int i=0;i<NUM_FUNC;++i) m_zM[i] = new double[m_dimension]; // Load the shifted global optimum loadMatrixFromFile(DEFAULT_FILE_DATA19, NUM_FUNC, m_dimension, m_o); for (int i = 0 ; i < m_dimension ; i ++) { m_o[9][i] = 0.0; } // Load the matrix char tmp[4]; sprintf(tmp,"%d",m_dimension); loadNMatrixFromFile(DEFAULT_FILE_MX_PREFIX19 + tmp + DEFAULT_FILE_MX_SUFFIX19, NUM_FUNC, m_dimension, m_dimension, m_M); // Initialize the hybrid composition job object theJob.num_func = NUM_FUNC; theJob.num_dim = m_dimension; theJob.C = 2000.0; theJob.sigma = m_sigma19; theJob.biases = m_func_biases19; theJob.lambda = m_lambda19; theJob.o = m_o; theJob.M = m_M; theJob.w = m_w; theJob.z = m_z; theJob.zM = m_zM; // Calculate/estimate the fmax for all the functions involved for (int i = 0 ; i < NUM_FUNC ; i ++) { for (int j = 0 ; j < m_dimension ; j ++) { m_testPoint[j] = (5.0 / m_lambda19[i]); } rotate(m_testPointM, m_testPoint, m_M[i],m_dimension); m_fmax[i] = fabs(theJob.basic_func(i, m_testPointM,m_dimension)); } theJob.fmax = m_fmax; }
// Constructors F05_schwefel_global_opt_bound::F05_schwefel_global_opt_bound (int dimension, double bias) { m_dimension = dimension; m_bias = bias; m_func_name = DEFAULT_FILE_DATA5; // Note: dimension starts from 0 m_o = new double[m_dimension]; m_A = new double*[m_dimension]; for(int i=0;i<m_dimension;++i) m_A[i]=new double[m_dimension]; m_B = new double[m_dimension]; m_z = new double[m_dimension]; double **m_data = new double*[m_dimension+1]; for(int i=0;i<m_dimension+1;++i) m_data[i]=new double[m_dimension]; // Load the shifted global optimum loadMatrixFromFile(DEFAULT_FILE_DATA5, m_dimension+1, m_dimension, m_data); for (int i = 0 ; i < m_dimension ; i ++) { if ((i+1) <= ceil(m_dimension / 4.0)) m_o[i] = -100.0; else if ((i+1) >= floor((3.0 * m_dimension) / 4.0)) m_o[i] = 100.0; else m_o[i] = m_data[0][i]; } for (int i = 0 ; i < m_dimension ; i ++) { for (int j = 0 ; j < m_dimension ; j ++) { m_A[i][j] = m_data[i+1][j]; } } Ax(m_B, m_A, m_o,m_dimension); }
F24_rotated_hybrid_composition_4::F24_rotated_hybrid_composition_4 (int dimension, double bias, string file_data, string file_m) { m_dimension = dimension; m_bias = bias; m_func_name = FUNCTION_NAME24; // Note: dimension starts from 0 m_o = new double*[NUM_FUNC]; for(int i=0;i<NUM_FUNC;++i) m_o[i] = new double[m_dimension]; m_M = new double**[NUM_FUNC]; for(int i=0;i<NUM_FUNC;++i) { m_M[i] = new double*[m_dimension]; for(int j=0;j<m_dimension;++j) m_M[i][j] = new double[m_dimension]; } m_testPoint = new double[m_dimension]; m_testPointM = new double[m_dimension]; m_fmax = new double[NUM_FUNC]; m_w = new double[NUM_FUNC]; m_z = new double*[NUM_FUNC]; for(int i=0;i<NUM_FUNC;++i) m_z[i] = new double[m_dimension]; m_zM = new double*[NUM_FUNC]; for(int i=0;i<NUM_FUNC;++i) m_zM[i] = new double[m_dimension]; // Load the shifted global optimum loadMatrixFromFile(file_data, NUM_FUNC, m_dimension, m_o); // Load the matrix loadNMatrixFromFile(file_m, NUM_FUNC, m_dimension, m_dimension, m_M); // Initialize the hybrid composition job object theJob.num_func = NUM_FUNC; theJob.num_dim = m_dimension; theJob.C = 2000.0; theJob.sigma = m_sigma24; theJob.biases = m_func_biases24; theJob.lambda = m_lambda24; theJob.o = m_o; theJob.M = m_M; theJob.w = m_w; theJob.z = m_z; theJob.zM = m_zM; // Calculate/estimate the fmax for all the functions involved for (int i = 0 ; i < NUM_FUNC ; i ++) { for (int j = 0 ; j < m_dimension ; j ++) { m_testPoint[j] = (5.0 / m_lambda24[i]); } rotate(m_testPointM, m_testPoint, m_M[i],m_dimension); m_fmax[i] = fabs(theJob.basic_func(i, m_testPointM,m_dimension)); } theJob.fmax = m_fmax; }
int main(){ vector<short> *vec = new vector<short>(); loadMatrixFromFile("Lab9.txt", 100000, vec); Timer a_timer = Timer(); quickSort(vec); double elapsed = a_timer.elapsed_time(); vector<short>::iterator it; cout << "Elapsed Time: " << elapsed << endl; return 0; }
F11_shifted_rotated_weierstrass::F11_shifted_rotated_weierstrass (int dimension, double bias, string file_data, string file_m) { m_dimension = dimension; m_bias = bias; m_func_name = FUNCTION_NAME11; // Note: dimension starts from 0 m_o = new double[m_dimension]; m_matrix = new double*[m_dimension]; for(int i=0;i<m_dimension;++i) m_matrix[i] = new double[m_dimension]; m_z = new double[m_dimension]; m_zM = new double[m_dimension]; // Load the shifted global optimum loadRowVectorFromFile(file_data, m_dimension, m_o); // Load the matrix loadMatrixFromFile(file_m, m_dimension, m_dimension, m_matrix); }
// Constructors F11_shifted_rotated_weierstrass::F11_shifted_rotated_weierstrass (int dimension, double bias) { m_dimension = dimension; m_bias = bias; m_func_name = FUNCTION_NAME11; // Note: dimension starts from 0 m_o = new double[m_dimension]; m_matrix = new double*[m_dimension]; for(int i=0;i<m_dimension;++i) m_matrix[i] = new double[m_dimension]; m_z = new double[m_dimension]; m_zM = new double[m_dimension]; // Load the shifted global optimum loadRowVectorFromFile(DEFAULT_FILE_DATA11, m_dimension, m_o); // Load the matrix char tmp[8]; sprintf(tmp,"%d",dimension); loadMatrixFromFile(DEFAULT_FILE_MX_PREFIX11 + tmp + DEFAULT_FILE_MX_SUFFIX11, m_dimension, m_dimension, m_matrix); }
int main (){ vector<vector<short> >*mat = new vector<vector<short> >(); //r int row = 4000; //s int column = 25; //load the matrix loadMatrixFromFile("Lab9.txt", row, column, mat); Matrix *matrx = new Matrix(mat, row, column); ColumnSorter *cols = new ColumnSorter(matrx); //start the timer Timer a_timer = Timer(); //sort cols->sort(); //calc the elapsed time double elapsed = a_timer.elapsed_time(); //if sorted print the matrix and time elapsed if(sortCheck(cols->mat)){ print_matrix(cols->mat, "result.txt", elapsed); }else{ cout << "The matrix is not sorted" << endl; } return 0; }