void psi_interp_trilinear(psi_rvec* in, psi_rvec* out) { psi_int i, j, k, ax; for(ax = 0; ax < PSI_NDIM; ++ax) { #if PSI_NDIM == 3 for(i = 0; i < 2; ++i) for(j = 0; j < 2; ++j) for(k = 0; k < 2; ++k) out[ind3(2*i, 2*j, 2*k)].xyz[ax] = in[ind2(i, j, k)].xyz[ax]; for(j = 0; j < 3; j += 2) for(k = 0; k < 3; k += 2) out[ind3(1, j, k)].xyz[ax] = 0.5*(out[ind3(0, j, k)].xyz[ax] + out[ind3(2, j, k)].xyz[ax]); for(i = 0; i < 3; i += 1) for(k = 0; k < 3; k += 2) out[ind3(i, 1, k)].xyz[ax] = 0.5*(out[ind3(i, 0, k)].xyz[ax] + out[ind3(i, 2, k)].xyz[ax]); for(i = 0; i < 3; i += 1) for(j = 0; j < 3; j += 1) out[ind3(i, j, 1)].xyz[ax] = 0.5*(out[ind3(i, j, 0)].xyz[ax] + out[ind3(i, j, 2)].xyz[ax]); #elif PSI_NDIM == 2 for(i = 0; i < 2; ++i) for(j = 0; j < 2; ++j) out[ind3(2*i, 2*j)].xyz[ax] = in[ind2(i, j)].xyz[ax]; for(j = 0; j < 3; j += 2) out[ind3(1, j)].xyz[ax] = 0.5*(out[ind3(0, j)].xyz[ax] + out[ind3(2, j)].xyz[ax]); for(i = 0; i < 3; i += 1) out[ind3(i, 1)].xyz[ax] = 0.5*(out[ind3(i, 0)].xyz[ax] + out[ind3(i, 2)].xyz[ax]); #endif } }
//! Output formatted description of stopping test to output stream. void print(std::ostream& os, int indent = 0) const { std::string ind(indent,' '); std::string starLine(55,'*'); std::string starFront(5,'*'); os.setf(std::ios::scientific, std::ios::floatfield); os.precision(6); // Print header if this is the first call to this output status test. if (!headerPrinted_) { os << std::endl << ind << starLine << std::endl; os << ind << starFront << " Belos Iterative Solver: " << solverDesc_ << std::endl; if (precondDesc_ != "") os << ind << starFront << " Preconditioner: " << precondDesc_ << std::endl; os << ind << starFront << " Maximum Iterations: " << iterTest_->getMaxIters() << std::endl; os << ind << starFront << " Block Size: " << blockSize_ << std::endl; if (numResTests_ > 1) { os << ind << starFront << " Residual Tests (" << ((comboType_ == StatusTestCombo_t::OR) ? "OR" : (comboType_ == StatusTestCombo_t::AND) ? "AND" :"SEQ") << "): " << std::endl; } else { os << ind << starFront << " Residual Test: " << std::endl; } for (int i=0; i<numResTests_; ++i) { os << ind << starFront << " Test " << i+1 << " : " << resTestVec_[i]->description() << std::endl; } os << ind << starLine << std::endl; headerPrinted_ = true; } // Print out residuals for each residual test. os.setf(std::ios_base::right, std::ios_base::adjustfield); std::string ind2( 7 + numIterDgts_, ' ' ); os << ind << "Iter " << std::setw(numIterDgts_) << iterTest_->getNumIters() << ", "; for (int i=0; i<currNumRHS_; ++i) { if ( i > 0 && currIdx_[i]!=-1 ) { // Put in space where 'Iter :' is in the previous lines os << ind << ind2; } os << "[" << std::setw(numLSDgts_) << currIdx_[i]+1 << "] : "; for (int j=0; j<numResTests_; ++j) { if ( resTestVec_[j]->getStatus() != Undefined && currIdx_[i]!=-1 ) { os << std::setw(15) << (*resTestVec_[j]->getTestValue())[currIdx_[i]]; } else { os << std::setw(15) << "---"; } } os << std::endl; } }
void GA::TestMethod(void) { // initialize individual Individual ind1(15, 20), ind2(15, 20); ind1.initGenotype(15, 20); ind2.initGenotype(15, 20); std::cout << "========== Initial Individual ==========" << std::endl; std::cout << "Individual 1: "; ind1.print(); std::cout << "individual 2: "; ind2.print(); // swap chromosome GeneticOperator::swap(&ind1, &ind2); std::cout << "========== After Swap ==========" << std::endl; std::cout << "Individual 1: "; ind1.print(); std::cout << "individual 2: "; ind2.print(); // mutation ind1.mutate(); ind2.mutate(); std::cout << "========== After Mutation ==========" << std::endl; std::cout << "Individual 1: "; ind1.print(); std::cout << "individual 2: "; ind2.print(); // crossover Individual child1, child2; GeneticOperator::uniform_crossover(ind1, ind2, &child1, &child2); std::cout << "========== After Uniform CrossOver ==========" << std::endl; std::cout << "Individual 1: "; ind1.print(); std::cout << "individual 2: "; ind2.print(); std::cout << "child 1: "; child1.print(); std::cout << "child 2: "; child2.print(); }
RTC::ReturnCode_t sh_MT::onExecute(RTC::UniqueId ec_id) { if(!m_input2In.isNew()){ return RTC::RTC_OK; } m_input2In.read(); //データの復元 printf("データの復元_インデックスの読み込み(MT)\n"); double c = m_input2.pop_length;//18522 double d = m_input2.pop_width;//28 printf("pop_x = %f pop_y = %f \n", c, d);//popのインデックス double a = m_input2.ind_length;//2 double b = m_input2.ind_width;//4 printf("ind_x = %f ind_y = %f \n", a, b);//indのインデックス printf("データの復元_popの読み込み(MT)\n"); double test=0; int num = 0; mwArray pop_copy(18522, 28, mxDOUBLE_CLASS);//pop_copyの入れ物の型宣言 /////////////////////////////////////////////////////////// double *data_copy_pop = new double [m_input2.pop_length * m_input2.pop_width]; for (num = 0; num < m_input2.pop_length * m_input2.pop_width ; num++) { data_copy_pop[num] = m_input2.pop[num]; } pop_copy.SetData(data_copy_pop, m_input2.pop_length * m_input2.pop_width);//pop /////////////////////////////////////////////////////////// printf("データの復元_indの読み込み(MT)\n"); mwArray ind_copy(m_input2.ind_length, m_input2.ind_width, mxDOUBLE_CLASS); /////////////////////////////////////////////////////////// double *data_copy_ind = new double [m_input2.pop_length * m_input2.pop_width]; for (num = 0; num < m_input2.ind_length * m_input2.ind_width ; num++) { data_copy_ind[num] = m_input2.ind[num]; } ind_copy.SetData(data_copy_ind, m_input2.ind_length * m_input2.ind_width);//ind /////////////////////////////////////////////////////////// //pop,indの復元が終わったはず printf("復元完了(MT)\n"); /////////////////////////////////////////////////////////// //デフォルトパラメータの読み込み mwArray pars; shPars(1, pars);//デフォルトパラメータを.matから読み込みparsに入れる /////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////// //SHmodel本体_MT //MT野の処理 mwArray output(1, 2, mxCELL_CLASS);//出力の入れ物 mwArray pop = pop_copy; mwArray ind = ind_copy; printf("モデル本体の処理開始(MT)\n"); mwArray inputMT_a(1, 3, mxCELL_CLASS);//出力の入れ物 inputMT_a.Get(1,1).Set(pop);// inputMT_a.Get(1,2).Set(ind);// inputMT_a.Get(1,3).Set(pars);// shModelMtLinear(2, output, inputMT_a); pop = output.Get(2, 1, 1); ind = output.Get(2, 1, 2); printf("MT野の処理shModelMtLinear終了(MT)\n"); mwArray inputMT_b(1, 3, mxCELL_CLASS);//出力の入れ物 inputMT_b.Get(1,1).Set(pop);// inputMT_b.Get(1,2).Set(ind);// inputMT_b.Get(1,3).Set(pars);// shModelMtPreThresholdBlur(2, output, inputMT_b); pop = output.Get(2, 1, 1); ind = output.Get(2, 1, 2); printf("MT野の処理shModelMtPreThresholdBlur終了(MT)\n"); mwArray inputMT_c(1, 3, mxCELL_CLASS);//出力の入れ物 inputMT_c.Get(1,1).Set(pop);// inputMT_c.Get(1,2).Set(ind);// inputMT_c.Get(1,3).Set(pars);// shModelHalfWaveRectification(2, output, inputMT_c); pop = output.Get(2, 1, 1); ind = output.Get(2, 1, 2); printf("MT野の処理shModelHalfWaveRectification終了(MT)\n"); mwArray inputMT_d(1, 3, mxCELL_CLASS);//出力の入れ物 inputMT_d.Get(1,1).Set(pop);// inputMT_d.Get(1,2).Set(ind);// inputMT_d.Get(1,3).Set(pars);// shModelMtPostThresholdBlur(2, output, inputMT_d); pop = output.Get(2, 1, 1); ind = output.Get(2, 1, 2); printf("MT野の処理shModelMtPostThresholdBlur終了(MT)\n"); mwArray inputMT_e(1, 3, mxCELL_CLASS);//出力の入れ物 inputMT_e.Get(1,1).Set(pop);// inputMT_e.Get(1,2).Set(ind);// inputMT_e.Get(1,3).Set(pars);// mwArray outputMT(1, 4, mxCELL_CLASS);//出力の入れ物 mwArray nume; mwArray deno; shModelMtNormalization(4, outputMT, inputMT_e); printf("MT野の処理shModelMtNormalization終了(MT)\n"); //計算結果の表示(仮) a =0; ////////////////////////////////////////////////////////////// printf("\npop(MT)\n"); mwArray pop2(outputMT.Get(2, 1, 1));//popの確保(2, 1, 2)がind_outputMT printf("NumberOfDimensions(MT) : %d\n", pop2.NumberOfDimensions()); mwArray pop2_dims = pop2.GetDimensions(); int pop2_dim1 = pop2_dims.Get(1, 1);//int型に変換する必要あり int pop2_dim2 = pop2_dims.Get(1, 2); printf("1 : (MT)%d\n", pop2_dim1);//378 printf("2 : (MT)%d\n", pop2_dim2);//19 printf("NumberOfElements(MT) : %d\n", pop2.NumberOfElements()); for(int y = 1; y <= pop2_dim2; y++) { for(int x = 1; x <= pop2_dim1; x++) { //縦長に保存されている a = pop2.Get((mwSize)2, x, y);//mwArrayの呼び出し } } printf("pop_last(MT) = %f\n", a); printf("\n"); /////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////// printf("ind(MT)\n"); mwArray ind2(outputMT.Get(2, 1, 2));//indの確保_outputMT printf("NumberOfDimensions(MT) : %d\n", ind2.NumberOfDimensions()); mwArray ind2_dims = ind2.GetDimensions(); int ind2_dim1 = ind2_dims.Get(1, 1);//int型に変換する必要あり int ind2_dim2 = ind2_dims.Get(1, 2); printf("1 : (MT)%d\n", ind2_dim1);//378 printf("2 : (MT)%d\n", ind2_dim2);//19 printf("NumberOfElements(MT) : %d\n", ind2.NumberOfElements()); for(int y = 1; y <= ind2_dim2; y++) { //printf("\n"); for(int x = 1; x <= ind2_dim1; x++) { a = ind2.Get((mwSize)2, x, y);//mwArrayの呼び出し printf("%f ", a); } printf("\n"); } printf("\n"); /////////////////////////////////////////////////////////////// //出力部分 m_output2.pop_length = pop2_dim1;///////////////////// m_output2.pop_width = pop2_dim2;///////////////////////// m_output2.pop.length(pop2_dim1 * pop2_dim2);//popの配列の確保 num = 0; double *data_copy_pop2 = new double [pop2_dim1 * pop2_dim2]; pop.GetData(data_copy_pop2, pop2_dim1 * pop2_dim2); for (num = 0; num < pop2_dim1 * pop2_dim2 ; num++) { m_output2.pop[num] = data_copy_pop2[num]; } //ind_2*4/ m_output2.ind_length = ind2_dim1;//////////////// m_output2.ind_width = ind2_dim2;///////////////// m_output2.ind.length(ind2_dim1 * ind2_dim2);//popの配列の確保 double *data_copy_ind2 = new double [ind2_dim1 * ind2_dim2]; ind.GetData(data_copy_ind2, ind2_dim1 * ind2_dim2); for (num = 0; num < ind2_dim1 * ind2_dim2; num++) { m_output2.ind[num] = data_copy_ind2[num]; } m_output2Out.write();//書き出し_異常発生の場合接続カット /////////////////////////////////////////////////////////////////////////////////////////////////////// printf("MT_end\n"); delete[] data_copy_pop;//data_copyのデリート delete[] data_copy_ind; return RTC::RTC_OK; }
RTC::ReturnCode_t sh_V1::onExecute(RTC::UniqueId ec_id) { if(!m_input2In.isNew()){ return RTC::RTC_OK; } m_input2In.read(); mwArray input(1, 4, mxCELL_CLASS); mwArray range(1, 3, mxDOUBLE_CLASS);//作る画像のサイズ range(1,1) = m_input2.width;//39 range(1,2) = m_input2.length;//39 range(1,3) = m_input2.time;//50 double xrange = range(1,1); double yrange = range(1,2); double trange = range(1,3); std::cerr << "x = " << xrange << std::endl; std::cerr << "y = " << yrange << std::endl; std::cerr << "t = " << trange << std::endl; ///////////////////////////////////////////////////////////////////// std::cerr << "データの復元_sの読み込み(V1)" << std::endl; mwSize dims[3] = {m_input2.width, m_input2.length, m_input2.time}; mwArray s_copy(3, dims, mxDOUBLE_CLASS); int num = 0; double *data_s_copy = new double [m_input2.time * m_input2.length * m_input2.width]; for (num = 0; num < m_input2.time * m_input2.length * m_input2.width ; num++) { data_s_copy[num] = m_input2.s_data[num]; } s_copy.SetData(data_s_copy, m_input2.time * m_input2.length * m_input2.width); ////////////////////////////////////////////////////////////////////////// std::cerr << "デフォルトパラメータの読み込み(V1)" << std::endl; //デフォルトパラメータの読み込み mwArray pars; shPars(1, pars);//デフォルトパラメータを.matから読み込みparsに入れる /////////////////////////////////////////////////////////// std::cerr << pars << std::endl; std::cerr << "モデル本体の処理開始(V1)" << std::endl; //outputここから mwArray output(1, 2, mxCELL_CLASS);//出力の入れ物 mwArray pop;//細胞のポピュレーションpop mwArray ind;//インデックス //outputここまで mwArray type("mtPattern");//文字列の宣言_どの段階まで処理を行うか mwArray stimulus = s_copy; mwArray stageName = type; mwArray inputV1_a(1, 2, mxCELL_CLASS);//出力の入れ物 inputV1_a.Get(1,1).Set(stimulus);// inputV1_a.Get(1,2).Set(pars);// shModelV1Linear(2, output, inputV1_a); pop = output.Get(2, 1, 1); ind = output.Get(2, 1, 2); std::cerr << "V1野の処理shModelV1Linear終了(V1)" << std::endl; mwArray inputV1_b(1, 3, mxCELL_CLASS);// inputV1_b.Get(1,1).Set(pop);//pop inputV1_b.Get(1,2).Set(ind);//ind inputV1_b.Get(1,3).Set(pars);// shModelFullWaveRectification(2, output, inputV1_b); pop = output.Get(2, 1, 1); ind = output.Get(2, 1, 2); std::cerr << "V1野の処理shModelFullWaveRectification終了(V1)" << std::endl; mwArray inputV1_c(1, 3, mxCELL_CLASS); inputV1_c.Get(1,1).Set(pop); inputV1_c.Get(1,2).Set(ind); inputV1_c.Get(1,3).Set(pars); shModelV1Blur(2, output, inputV1_c); pop = output.Get(2, 1, 1); ind = output.Get(2, 1, 2); std::cerr << "V1野の処理shModelV1Blur終了(V1)" << std::endl; mwArray inputV1_d(1, 3, mxCELL_CLASS); inputV1_d.Get(1,1).Set(pop); inputV1_d.Get(1,2).Set(ind); inputV1_d.Get(1,3).Set(pars); shModelV1Normalization(2, output, inputV1_d); pop = output.Get(2, 1, 1); ind = output.Get(2, 1, 2); std::cerr << "V1野の処理shModelV1Normalization終了(V1)" << std::endl; double a = 0; ///////////////////////// std::cerr << "pop(V1)" << std::endl; mwArray pop2(output.Get(2, 1, 1));//popの確保(2, 1, 2)がind std::cerr << "NumberOfDimensions(V1) : " << pop2.NumberOfDimensions() << std::endl; mwArray pop2_dims = pop2.GetDimensions(); int pop2_dim1 = pop2_dims.Get(1, 1);//int型に変換する必要あり int pop2_dim2 = pop2_dims.Get(1, 2); std::cerr << "1 : (V1)" << pop2_dim1 << std::endl;//18522 std::cerr << "2 : (V1)" << pop2_dim2 << std::endl;//28 std::cerr << "NumberOfElements(V1) : " << pop2.NumberOfElements() << std::endl; std::cerr << "ind(V1)" << std::endl; mwArray ind2(output.Get(2, 1, 2));//indの確保 std::cerr << "NumberOfDimensions(V1) : " << ind2.NumberOfDimensions() << std::endl; mwArray ind2_dims = ind2.GetDimensions(); int ind2_dim1 = ind2_dims.Get(1, 1);//int型に変換する必要あり int ind2_dim2 = ind2_dims.Get(1, 2); std::cerr << "1 : (V1)" << ind2_dim1 << std::endl;//18522 std::cerr << "2 : (V1)" << ind2_dim2 << std::endl;//28 std::cerr << "NumberOfElements(V1) : " << ind2.NumberOfElements() << std::endl;//28 for(int y = 1; y <= ind2_dim2; y++) { for(int x = 1; x <= ind2_dim1; x++) { a = ind2.Get((mwSize)2, x, y);//mwArrayの呼び出し std::cerr << a << std::endl; } } ////////////////////////// //pop_18522*28 m_output2.pop_length = pop2_dim1; m_output2.pop_width = pop2_dim2; std::cerr << "popをsequence型に変換(V1)" << std::endl; // std::cerr << pop2_dim1 * pop2_dim2 << std::endl; // m_output2.pop.length(518616); m_output2.pop.length(pop2_dim1 * pop2_dim2);//popの配列の確保 num = 0; double *data_copy_pop = new double [pop2_dim1 * pop2_dim2]; pop.GetData(data_copy_pop, pop2_dim1 * pop2_dim2); for (num = 0; num < pop2_dim1 * pop2_dim2 ; num++) { m_output2.pop[num] = data_copy_pop[num]; } std::cerr << "indをsequence型に変換(V1)" << std::endl; //ind_2*4/ m_output2.ind_length = ind2_dim1; m_output2.ind_width = ind2_dim2; m_output2.ind.length(ind2_dim1 * ind2_dim2);//popの配列の確保 double *data_copy_ind = new double [ind2_dim1 * ind2_dim2]; ind.GetData(data_copy_ind, ind2_dim1 * ind2_dim2); for (num = 0; num < ind2_dim1 * ind2_dim2; num++) { m_output2.ind[num] = data_copy_ind[num]; } std::cerr << "MT野への書き出し(V1)" << std::endl; m_output2Out.write();//書き出し_異常発生..接続カット std::cerr << "V1_end" << std::endl; delete[] data_s_copy; delete[] data_copy_pop; delete[] data_copy_ind; return RTC::RTC_OK; }
void psi_refine_trilinear(psi_rvec* pos, psi_rvec* vel, psi_real mass, psi_tet_buffer* tetbuf, psi_int lvl) { // TODO: these are different for the 48-tet connectivity! #if PSI_NDIM == 3 // all unique tet edges across the 3-cube. Order is first, midpoint, second. const static psi_int edges3TL[7][3] = { { 2 , 4 , 6 }, { 2 , 10 , 18 }, { 6 , 12 , 18 }, { 8 , 13 , 18 }, { 8 , 14 , 20 }, { 8 , 16 , 24 }, { 20 , 22 , 24 } }; const static psi_int nedges3TL = 7; #elif PSI_NDIM == 2 const static psi_int edges3TL[5][3] = {{0,1,2}, {0,3,6}, {2,4,6}, {2,5,8}, {6,7,8}}; const static psi_int nedges3TL = 5; #endif psi_int e, i, j, k, ii, jj, kk; psi_rvec tmppos[27]; psi_rvec tmpvel[27]; psi_rvec childpos[8]; psi_rvec childvel[8]; psi_real midpt_tet, midpt_lin, err2; // check to see if all of the tet edges are within tolerance if(lvl < tetbuf->max_lvl) for(e = 0; e < nedges3TL; ++e) { err2 = 0.0; for(i = 0; i < PSI_NDIM; ++i) { midpt_tet = 0.5*(pos[edges3TL[e][0]].xyz[i] + pos[edges3TL[e][2]].xyz[i]); midpt_lin = pos[edges3TL[e][1]].xyz[i]; err2 += (midpt_tet - midpt_lin)*(midpt_tet - midpt_lin); } // if this edge gives too large an error in position, stop and recurse if(err2 > tetbuf->ptol2) { #if PSI_NDIM == 3 for(i = 0; i < 2; ++i) for(j = 0; j < 2; ++j) for(k = 0; k < 2; ++k) { for(ii = 0; ii < 2; ++ii) for(jj = 0; jj < 2; ++jj) for(kk = 0; kk < 2; ++kk) { childpos[ind2(ii,jj,kk)] = pos[ind3(ii+i,jj+j,kk+k)]; childvel[ind2(ii,jj,kk)] = vel[ind3(ii+i,jj+j,kk+k)]; } psi_interp_trilinear(childpos, tmppos); psi_interp_trilinear(childvel, tmpvel); psi_refine_trilinear(tmppos, tmpvel, 0.125*mass, tetbuf, lvl+1); } #elif PSI_NDIM == 2 for(i = 0; i < 2; ++i) for(j = 0; j < 2; ++j) { for(ii = 0; ii < 2; ++ii) for(jj = 0; jj < 2; ++jj) { childpos[ind2(ii,jj)] = pos[ind3(ii+i,jj+j)]; childvel[ind2(ii,jj)] = vel[ind3(ii+i,jj+j)]; } psi_interp_trilinear(childpos, tmppos); psi_interp_trilinear(childvel, tmpvel); psi_refine_trilinear(tmppos, tmpvel, 0.25*mass, tetbuf, lvl+1); } #endif return; } } // if we have passed the tolerance test, refine to the buffer psi_tets_from_3cube(pos, vel, mass, tetbuf); }
int main(int argc, char * argv[]) { ProblemDefinitionsSPtr dummy_defs(new ProblemDefinitions(2,2,0,0)); PopulationSPtr myPop(new Population); IndividualSPtr ind1(new Individual(dummy_defs)); std::vector<double> dvs1 {1.0, 0.0}; ind1->setRealDVs(dvs1); ind1->setObjectives(std::vector<double>{1.0, 0.0}); myPop->push_back(ind1); IndividualSPtr ind2(new Individual(dummy_defs)); ind2->setRealDVs(std::vector<double>{0.7, 0.15}); ind2->setObjectives(std::vector<double>{0.49, 0.0225}); myPop->push_back(ind2); IndividualSPtr ind3(new Individual(dummy_defs)); ind3->setRealDVs(std::vector<double>{0.5, 0.26}); ind3->setObjectives(std::vector<double>{0.25, 0.0676}); myPop->push_back(ind3); IndividualSPtr ind4(new Individual(dummy_defs)); ind4->setRealDVs(std::vector<double>{0.44, 0.3}); ind4->setObjectives(std::vector<double>{0.1936, 0.09}); myPop->push_back(ind4); IndividualSPtr ind5(new Individual(dummy_defs)); ind5->setRealDVs(std::vector<double>{0.4, 0.37}); ind5->setObjectives(std::vector<double>{0.16, 0.1369}); myPop->push_back(ind5); IndividualSPtr ind6(new Individual(dummy_defs)); ind6->setRealDVs(std::vector<double>{0.2, 0.7}); ind6->setObjectives(std::vector<double>{0.04, 0.49}); myPop->push_back(ind6); IndividualSPtr ind7(new Individual(dummy_defs)); ind7->setRealDVs(std::vector<double>{0.0, 1.0}); ind7->setObjectives(std::vector<double>{0, 1}); myPop->push_back(ind7); IndividualSPtr ind1_(new Individual(dummy_defs)); ind1_->setRealDVs(std::vector<double> {1.0, 0.0}); ind1_->setObjectives(std::vector<double>{1.2, 0.2}); myPop->push_back(ind1_); IndividualSPtr ind2_(new Individual(dummy_defs)); ind2_->setRealDVs(std::vector<double>{0.7, 0.15}); ind2_->setObjectives(std::vector<double>{0.69, 0.2225}); myPop->push_back(ind2_); IndividualSPtr ind3_(new Individual(dummy_defs)); ind3_->setRealDVs(std::vector<double>{0.5, 0.26}); ind3_->setObjectives(std::vector<double>{0.45, 0.2676}); myPop->push_back(ind3_); IndividualSPtr ind4_(new Individual(dummy_defs)); ind4_->setRealDVs(std::vector<double>{0.44, 0.3}); ind4_->setObjectives(std::vector<double>{0.3936, 0.29}); myPop->push_back(ind4_); IndividualSPtr ind5_(new Individual(dummy_defs)); ind5_->setRealDVs(std::vector<double>{0.4, 0.37}); ind5_->setObjectives(std::vector<double>{0.36, 0.3369}); myPop->push_back(ind5_); IndividualSPtr ind6_(new Individual(dummy_defs)); ind6_->setRealDVs(std::vector<double>{0.2, 0.7}); ind6_->setObjectives(std::vector<double>{0.24, 0.69}); myPop->push_back(ind6_); IndividualSPtr ind7_(new Individual(dummy_defs)); ind7_->setRealDVs(std::vector<double>{0.0, 1.0}); ind7_->setObjectives(std::vector<double>{0.2, 1.2}); myPop->push_back(ind7_); std::vector< std::vector<std::pair<IndividualSPtr, double > > > values1 = DebsCrowdingDistance::calculate(myPop); FrontsSPtr values2 = myPop->getFronts(); // typedef std::pair<IndividualSPtr, double> IndDistPair; // FrontsSPtr values2(new Fronts(values1.size())); // boost::shared_ptr<std::vector<std::vector<IndividualSPtr> > > values2(new std::vector<std::vector<IndividualSPtr> >(values1.size())); // for (int i = 0; i < values2->size(); ++i) // { // BOOST_FOREACH(IndDistPair ind, values1[i]) // { // (*values2)[i].push_back(ind.first); // } // } #ifdef WITH_VTK PlotFrontVTK plot; plot(myPop); #endif }
Gradient::Gradient(Grid * g){ //cout << "Trying to create gradient with h = " << g->getH() << endl; this->g = g; double h = g->getH(); constantTerm.resize(g->faces.size()); constantTerm = 0; for(int i = g->iMin; i <= g->iMax; i++){ for(int j = g->jMin; j <= g->jMax; j++){ if(g->cells(i,j)->isUncovered()){ //cout << " is uncovered." << endl; CellIndex cellIndex(i,j); TinyVector<Face*,5> faces = g->cells(i,j)->faces; if(g->isFaceUncovered(i,j,B)){ FaceIndex faceIndex = faces(B)->getIndex(); Coord centroid = faces(B)->getCentroid(); TinyVector<double,2> n = faces(B)->getNormal(); double x, y, r; x = centroid(0); y = centroid(1); r = sqrt(pow2(x) + pow2(y)); TinyVector<double,2> gradU; double pi = acos(-1); //gradU(0) = 3*pow(x,2)*pow(y-2,2)+sin(2*(x-pow(y,2))); //gradU(1) = 2*pow(x,3)*(y-2) - 2*y*sin(2*(x-pow(y,2))); gradU(0) = 0;//-2*pi*sin(2*pi*r)*x/r; gradU(1) = 0;//-2*pi*sin(2*pi*r)*y/r; constantTerm(faceIndex) += gradU(0)*n(0) + gradU(1)*n(1); //cout << "\tAdding boundary condition to constant term." << endl; } if(faces(N) != 0){ FaceIndex faceIndex = faces(N)->getIndex(); if(faces(N)->isRegular()){ coefficients[faceIndex][cellIndex] = -1/h; } else if(faces(N)->isIrregular()){ if(coefficients[faceIndex].count(cellIndex) == 0){ double alpha = g->cells(i,j)->getFace(N)->getArea(); if(g->isFaceUncovered(i+1,j,N)){ CellIndex ind1(i,j); CellIndex ind2(i,j+1); CellIndex ind3(i+1,j); CellIndex ind4(i+1,j+1); interpolateIrregularFace(alpha,ind1,ind2,ind3,ind4,faceIndex); } else if(g->isFaceUncovered(i-1,j,N)){ CellIndex ind1(i,j); CellIndex ind2(i,j+1); CellIndex ind3(i-1,j); CellIndex ind4(i-1,j+1); interpolateIrregularFace(alpha,ind1,ind2,ind3,ind4,faceIndex); } } } //cout << "\tDid north face" << endl; } if(faces(S) != 0){ FaceIndex faceIndex = faces(S)->getIndex(); if(faces(S)->isRegular()){ coefficients[faceIndex][cellIndex] = 1/h; } else if(faces(S)->isIrregular()){ if(coefficients[faceIndex].count(cellIndex) == 0){ double alpha = g->cells(i,j)->getFace(S)->getArea(); if(g->isFaceUncovered(i+1,j,S)){ CellIndex ind1(i,j-1); CellIndex ind2(i,j); CellIndex ind3(i+1,j-1); CellIndex ind4(i+1,j); interpolateIrregularFace(alpha,ind1,ind2,ind3,ind4,faceIndex); } else if(g->isFaceUncovered(i-1,j,S)){ CellIndex ind1(i,j-1); CellIndex ind2(i,j); CellIndex ind3(i-1,j-1); CellIndex ind4(i-1,j); interpolateIrregularFace(alpha,ind1,ind2,ind3,ind4,faceIndex); } } } //cout << "\tDid south face" << endl; } if(faces(E) != 0){ FaceIndex faceIndex = faces(E)->getIndex(); CellIndex cellIndex(i,j); if(faces(E)->isRegular()){ coefficients[faceIndex][cellIndex] = -1/h; } else if(faces(E)->isIrregular()){ if(coefficients[faceIndex].count(cellIndex) == 0){ double alpha = g->cells(i,j)->getFace(E)->getArea(); if(g->isFaceUncovered(i,j+1,E)){ CellIndex ind1(i,j); CellIndex ind2(i+1,j); CellIndex ind3(i,j+1); CellIndex ind4(i+1,j+1); interpolateIrregularFace(alpha,ind1,ind2,ind3,ind4,faceIndex); } else if(g->isFaceUncovered(i,j-1,E)){ CellIndex ind1(i,j); CellIndex ind2(i+1,j); CellIndex ind3(i,j-1); CellIndex ind4(i+1,j-1); interpolateIrregularFace(alpha,ind1,ind2,ind3,ind4,faceIndex); } } } //cout << "\tDid east face" << endl; } if(faces(W) != 0){ FaceIndex faceIndex = faces(W)->getIndex(); CellIndex cellIndex(i,j); if(faces(W)->isRegular()){ coefficients[faceIndex][cellIndex] = 1/h; } else if(faces(W)->isIrregular()){ if(coefficients[faceIndex].count(cellIndex) == 0){ double alpha = g->cells(i,j)->getFace(W)->getArea(); if(g->isFaceUncovered(i,j+1,W)){ CellIndex ind1(i+1,j); CellIndex ind2(i,j); CellIndex ind3(i+1,j+1); CellIndex ind4(i,j+1); interpolateIrregularFace(alpha,ind1,ind2,ind3,ind4,faceIndex); } else if(g->isFaceUncovered(i,j-1,W)){ CellIndex ind1(i+1,j); CellIndex ind2(i,j); CellIndex ind3(i+1,j-1); CellIndex ind4(i,j-1); interpolateIrregularFace(alpha,ind1,ind2,ind3,ind4,faceIndex); } } } //cout << "\tDid west face" << endl; } } } } //cout << "Resized" << endl; /* for(int i = g->iMin; i <= g->iMax; i++){ for(int j = g->jMin; j <= g->jMax; j++){ cout << "i = " << i << " j = " << j << endl; if(g->cells(i,j)->isUncovered()){ cout << "Uncovered" << endl; double c = 1; CellIndex index(i,j); TinyVector<Face*,5> faces = g->cells(i,j)->faces; cout << "Got faces" << endl; for(int k = 0; k < 5; k++){ cout << "Testing face " << k << endl; if(faces(k) != 0 && faces(k)->isUncovered()){ cout << "Face " << k << " is uncovered "; cout << "and has index " << faces(k)->getIndex() << endl; cout << coefficients(faces(k)->getIndex()).empty() << endl; coefficients(faces(k)->getIndex())[index] = c; } } } } }*/ }