void WMat::GatherToRowSrc(WMat &rhs) { Trace __trace("WMat::GatherToCol(WMat &rhs)"); // Gather rhs to col dist of this { std::vector<UInt> distd, dists; this->GetRowSrcGIDS(distd); rhs.GetRowGIDS(dists); Migrator mig(distd.size(), distd.size() > 0 ? &distd[0] : NULL, 0, dists.size(), dists.size() > 0 ? &dists[0] : NULL); mig.Migrate(rhs); } }
// Migrate WMat based on mesh's element ids //void WMat::Migrate(CommRel &crel) { void WMat::MigrateToElem(Mesh &mesh) { Trace __trace("WMat::Migrate(Mesh &mesh)"); // Gather pole constraints { std::vector<UInt> mesh_dist, iw_dist; Context c; c.set(Attr::ACTIVE_ID); Attr a(MeshObj::ELEMENT, c); getMeshGIDS(mesh, a, mesh_dist); GetRowGIDS(iw_dist); Migrator mig(mesh_dist.size(), mesh_dist.size() > 0 ? &mesh_dist[0] : NULL, 0, iw_dist.size(), iw_dist.size() > 0 ? &iw_dist[0] : NULL); mig.Migrate(*this); //#define CHECK_WEIGHT_MIG #ifdef CHECK_WEIGHT_MIG // Check something: should have 1 to 1 coresp ids and entries for (UInt i = 0; i < mesh_dist.size(); i++) { Entry ent(mesh_dist[i]); WeightMap::iterator wi = weights.lower_bound(ent); if (wi == weights.end() || wi->first.id != ent.id) Throw() << "Did not find id:" << ent.id << std::endl; } // And the other way std::sort(mesh_dist.begin(), mesh_dist.end()); WeightMap::iterator wi = weights.begin(), we = weights.end(); for (; wi != we; ++wi) { std::vector<UInt>::iterator lb = std::lower_bound(mesh_dist.begin(), mesh_dist.end(), wi->first.id); if (lb == mesh_dist.end() || *lb != wi->first.id) Throw() << "Weight entry:" << wi->first.id << " not a mesh id!"; } #endif } return; }
int main (int __argc, char *__argv[]) { peo :: init( __argc, __argv ); if (getNodeRank()==1) std::cout<<"\n\nTest : PSO Global Best\n\n"; rng.reseed (10); RingTopology topologyMig; eoGenContinue < Indi > genContPara (10); eoCombinedContinue <Indi> continuatorPara (genContPara); eoCheckPoint<Indi> checkpoint(continuatorPara); peoEvalFunc<Indi, double, const Indi& > plainEval(f); peoPopEval< Indi > eval(plainEval); eoUniformGenerator < double >uGen (0, 1.); eoInitFixedLength < Indi > random (2, uGen); eoUniformGenerator < double >sGen (-1., 1.); eoVelocityInitFixedLength < Indi > veloRandom (2, sGen); eoFirstIsBestInit < Indi > localInit; eoRealVectorBounds bndsFlight(2,0,1.); eoStandardFlight < Indi > flight(bndsFlight); eoPop < Indi > pop; pop.append (10, random); eoLinearTopology<Indi> topology(2); eoRealVectorBounds bnds(2,-1.,1.); eoStandardVelocity < Indi > velocity (topology,1,0.5,2.,bnds); eoInitializer <Indi> init(eval,veloRandom,localInit,topology,pop); eoPeriodicContinue< Indi > mig_cont( 2 ); peoPSOSelect<Indi> mig_selec(topology); peoGlobalBestVelocity<Indi> mig_replac (2.,velocity); eoContinuator<Indi> cont(mig_cont, pop); eoSelector <Indi, eoPop<Indi> > mig_select (mig_selec,1,pop); eoReplace <Indi, eoPop<Indi> > mig_replace (mig_replac,pop); eoGenContinue < Indi > genContPara2 (10); eoCombinedContinue <Indi> continuatorPara2 (genContPara2); eoCheckPoint<Indi> checkpoint2(continuatorPara2); peoEvalFunc<Indi, double, const Indi& > plainEval2(f); peoPopEval< Indi > eval2(plainEval2); eoUniformGenerator < double >uGen2 (0, 1.); eoInitFixedLength < Indi > random2 (2, uGen2); eoUniformGenerator < double >sGen2 (-1., 1.); eoVelocityInitFixedLength < Indi > veloRandom2 (2, sGen2); eoFirstIsBestInit < Indi > localInit2; eoRealVectorBounds bndsFlight2(2,0,1.); eoStandardFlight < Indi > flight2(bndsFlight2); eoPop < Indi > pop2; pop2.append (10, random2); eoLinearTopology<Indi> topology2(2); eoRealVectorBounds bnds2(2,-1.,1.); eoStandardVelocity < Indi > velocity2 (topology2,1,0.5,2.,bnds2); eoInitializer <Indi> init2(eval2,veloRandom2,localInit2,topology2,pop2); eoPeriodicContinue< Indi > mig_cont2( 2 ); peoPSOSelect<Indi> mig_selec2(topology2); peoGlobalBestVelocity<Indi> mig_replac2 (2.,velocity2); eoContinuator<Indi> cont2(mig_cont2,pop2); eoSelector <Indi, eoPop<Indi> > mig_select2 (mig_selec2,1,pop2); eoReplace <Indi, eoPop<Indi> > mig_replace2 (mig_replac2,pop2); peoAsyncIslandMig< eoPop<Indi>, eoPop<Indi> > mig(cont,mig_select, mig_replace, topologyMig); checkpoint.add( mig ); peoAsyncIslandMig< eoPop<Indi>, eoPop<Indi> > mig2(cont2,mig_select2, mig_replace2, topologyMig); checkpoint2.add( mig2 ); eoSyncEasyPSO <Indi> psa(init,checkpoint,eval, velocity, flight); peoWrapper parallelPSO( psa, pop); eval.setOwner(parallelPSO); mig.setOwner(parallelPSO); eoSyncEasyPSO <Indi> psa2(init2,checkpoint2,eval2, velocity2, flight2); peoWrapper parallelPSO2( psa2, pop2); eval2.setOwner(parallelPSO2); mig2.setOwner(parallelPSO2); peo :: run(); peo :: finalize(); if (getNodeRank()==1) { pop.sort(); pop2.sort(); std::cout << "Final population :\n" << pop << std::endl; std::cout << "Final population :\n" << pop2 << std::endl; } }
int main() { Rat a(2,5); Rat b(10/5); Interval X(a,b); Interval Degen(2,2); Interval A(1,2); Interval B(-5,90); Interval C(-4,-3); //=============================================================================== std::cout << "Check for associativity and commutativity" << std::endl; std::cout << "A = " << A << " B = " << B << " C = " << C << std::endl; std::cout << "A + B = " << A + B << std::endl; std::cout << "(A + B) - B = " << (A + B) - B << std::endl; std::cout << "A + (B - B) = " << A + (B - B) << std::endl; std::cout << "A + B - B = " << A + B - B << std::endl; std::cout << "A * B = " << A * B << std::endl; std::cout << "B * A = " << B * A << std::endl; std::cout << "(A * B) * C = " << (A * B) * C << std::endl; std::cout << "A * (B * C) = " << A * (B * C) << std::endl; std::cout << "The test interval X: " << X << std::endl << std::endl; //=============================================================================== std::cout << "Degenerate interval test" << std::endl; std::cout << "The degenerate interval [2,2]: " << Degen << std::endl << std::endl; //=============================================================================== std::cout << "Left and Right endpoint test" << std::endl; std::cout << "Left endpoint of X is: " << X.lower() << std::endl; std::cout << "Right endpoint of X is: " << X.upper() << std::endl; //=============================================================================== std::cout << "Interval positive/negative test" << std::endl; if(X >= 0) std::cout << "X is positive" << std::endl; else std::cout << "X is not positive" << std::endl; if(X > 0) std::cout << "X is strictly positive" << std::endl; else std::cout << "X is not strictly positive" << std::endl; if(X <= 0) std::cout << "X is negative" << std::endl; else std::cout << "X is not negative" << std::endl; if(X < 0) std::cout << "X is strictly negative" << std::endl; else std::cout << "X is not strictly negative" << std::endl << std::endl; //============================================================================= std::cout << "Interval comparison test" << std::endl; Interval Y(3,5); if(X < Y) std::cout << X << " is less than " << Y << std::endl; else std::cout << X << " is not less than " << Y << std::endl; Y.assign(8,10); if(X <= Y) std::cout << X << " is less than or equal to " << Y << std::endl; else std::cout << X << " is not less than or equal to " << Y << std::endl; if(X > Y) std::cout << X << " is greater than " << Y << std::endl; else std::cout << X << " is not greater than " << Y << std::endl; if(X >= Y) std::cout << X << " is greater than or equal to " << Y << std::endl; else std::cout << X << " is not greater than or equal to " << Y << std::endl << std::endl; //============================================================================ std::cout << "Arithmetic test" << std::endl; std::cout << X << " + " << Y << " = " << X + Y << std::endl << std::endl; std::cout << X << " - " << Y << " = " << X - Y << std::endl << std::endl; X.assign(2,3); Y.assign(5,6); std::cout << X << " * " << Y << " = " << X * Y << std::endl; X.assign(a,b); Y.assign(-3,5); std::cout << X << " * " << Y << " = " << X * Y << std::endl; Y.assign(-3,-2); std::cout << X << " * " << Y << " = " << X * Y << std::endl; X.assign(-a,b); Y.assign(3,5); std::cout << X << " * " << Y << " = " << X * Y << std::endl << std::endl; X.assign(a,b); std::cout << "X = " << X << " 1/X = " << 1/X << std::endl; std::cout << X << "/" << Y << " = " << X/Y << std::endl << std::endl; std::cout << "X = " << X << " X^0 = " << boost::numeric::pow(X,0) << std::endl; std::cout << "X = " << X << " X^2 = " << boost::numeric::pow(X,2) << std::endl; X.assign(-5,3); std::cout << "X = " << X << " X^(3) = " << boost::numeric::pow(X,3) << std::endl; X.assign(-5,-3); std::cout << "X = " << X << " X^4 = " << boost::numeric::pow(X,4) << std::endl; X.assign(-8,9); std::cout << "X = " << X << " X^2 = " << boost::numeric::pow(X,2) << std::endl << std::endl; X.assign(-5,-2); Y.assign(-4,0); std::cout << X << "/" << Y << " = " << X/Y << std::endl; X.assign(-10,4); std::cout << X << "/" << Y << " = " << X/Y << std::endl; std::cout << "Y = " << Y << " 1/Y = " << 1/Y << std::endl << std::endl; //======================================================================== std::cout << "Interval Functions test" << std::endl; X.assign(2,100); std::cout << "X = " << X << std::endl; std::cout << "Midpoint of X, m(X) = " << boost::numeric::median(X) << std::endl; std::cout << "Width of X, w(X) = " << boost::numeric::width(X) << std::endl; std::cout << "The absolute value of X, |X| = " << boost::numeric::norm(X) << std::endl; std::cout << "The mignitude of X, mig(X) = " << mig(X) << std::endl; Interval test(-11,11); Interval test1(0,5); Interval ans; ans = test1/test; std::cout << ans << std::endl; return 0; }