Esempio n. 1
0
TEST(UX, BigRandom){
  UX ux(10);
  for(int i = 0; i < 1000; i ++){
    Individual a(20);
    a.randomize();

    Individual b(20);
    b.randomize();

    Crossover::Result res = ux(&a, &b);
    ASSERT_TRUE(res.first.valid());
    ASSERT_TRUE(res.second.valid());
  }
}
Esempio n. 2
0
void xadicor_(double* u_, double* g_, double& deltah, double& deltat, int& nx, int& ny, int& nz, double* ux_,

double* a3_, double* a2_, double* a1xyz, double*cxyz
){
    Mat u(u_, nx,ny,nz), ux(ux_, nx,ny,nz), g(g_, nx,ny,nz), a3(a3_, nx,ny,nz), a2(a2_, nx,ny,nz);
//    valarray<double> a1xyz(), cxyz();
    double a = 2.0*deltah, b = a*a;
    for(int k=2; k<nz; ++k){
    for(int i=2; i<ny; ++i){
    for(int j=2; j<nx; ++j){
        int m = (k-1)*nx*ny + nx*(i-1) + j;

        double phix = (u(k,i,j+1) - u(k,i,j-1))/a;
        double phiy = (u(k,i+1,j) - u(k,i-1,j))/a;
        double phiz = (u(k+1,i,j) - u(k-1,i,j))/a;

        double phixy = (u(k,i+1,j+1) - u(k,i+1,j-1) - u(k,i-1,j+1) + u(k,i-1,j-1))/b;
        double phixz = (u(k+1,i,j+1) - u(k+1,i,j-1) - u(k-1,i,j+1) + u(k-1,i,j-1))/b;
        double phiyz = (u(k+1,i+1,j) - u(k+1,i-1,j) - u(k-1,i+1,j) + u(k-1,i-1,j))/b;

        double de = (1 + dot(phix,phiy,phiz));
        a3(k,i,j) = g(k,i,j)*(1 + phix*phix + phiy*phiy)*deltat/de;
        a2(k,i,j) = g(k,i,j)*(1 + phix*phix + phiz*phiz)*deltat/de;
        a1xyz[m] = g(k,i,j)*(1 + phiy*phiy + phiz*phiz)*deltat/de;
        cxyz[m] = g(k,i,j)*( 2.0*(phix*phiy*phixy + phix*phiy*phixz + phiy*phiz*phiyz)/de - ux(k,i,j)*sqrt(de))*deltat;
    }}}
}
Esempio n. 3
0
    QVector<double> upsconv(const QVector<double>& x,
                            const QVector<double>& g,
                            int lx)
    {
        // Dyadic upsampling
        int p = 0;
        int rem2 = p - ((p / 2) * 2);
        int addLEN = 2 * rem2 - 1;
        int lux = 2 * x.size() + addLEN;
        QVector<double> ux(lux, 0.0);
        QVector<double>::const_iterator iter = x.begin();
        for(int index = 0 + rem2; index < ux.size(); index += 2)
            ux[index] = *iter++;

        // Convolution with recompose filter
        QVector<double> y = conv1(ux, g, true);

        // Crop boundries
        int ly = y.size();
        double d = double(ly - lx) / 2.0;
        int first = int(floor(d));
        int last = ly - int(ceil(d));

        QVector<double> z(last - first);
        qCopy(y.begin() + first, y.begin() + last, z.begin());

        return z;
    }
  void FindObjectOnPlane::generateAngles(
    const cv::Mat& blob_image, const cv::Point2f& test_point,
    std::vector<double>& angles,
    std::vector<double>& max_x,
    std::vector<double>& max_y,
    const image_geometry::PinholeCameraModel& model,
    const jsk_recognition_utils::Plane::Ptr& plane)
  {
    angles.clear();
    const double angle_step = 3;
    std::vector<cv::Point> indices;
    for (int j = 0; j < blob_image.rows; j++) {
        for (int i = 0; i < blob_image.cols; i++) {
          if (blob_image.at<uchar>(j, i) != 0) { // need to check
            indices.push_back(cv::Point(i, j));
          }
        }
    }
    for (double angle = -180; angle < 180; angle += angle_step) {
      Eigen::Vector2f ux(cos(angle/180*M_PI), sin(angle/180*M_PI));
      //Eigen::Vector2f uy(sin(angle/180*M_PI), -cos(angle/180*M_PI));
      cv::Point2d uy_end = getUyEnd(test_point, cv::Point2d(test_point.x + ux[0], test_point.y + ux[1]),
                                    model,
                                    plane);
      Eigen::Vector2f uy(uy_end.x - test_point.x, uy_end.y - test_point.y);

      Eigen::Matrix2f A;
      A << ux[0], uy[0],
        ux[1], uy[1];
      bool excluded = false;
      double max_alpha = -DBL_MAX;
      double max_beta = -DBL_MAX;
      for (size_t i = 0; i < indices.size(); i++) {
        Eigen::Vector2f p_q = Eigen::Vector2f(indices[i].x, indices[i].y) - Eigen::Vector2f(test_point.x, test_point.y);
        Eigen::Vector2f a_b = A.inverse() * p_q;
        double alpha = a_b[0];
        double beta = a_b[1];
        if (alpha < 0 || beta < 0) {
          excluded = true;
          break;
        }
        if (alpha > max_alpha) {
          max_alpha = alpha;
        }
        if (beta > max_beta) {
          max_beta = beta;
        }
        
      }
      if (!excluded) {
        angles.push_back(angle);
        max_x.push_back(max_alpha);
        max_y.push_back(max_beta);
      }
    }
  }
Esempio n. 5
0
void boid()
{
    if (cond) {
#ifdef URANIUM_PU36
        ux();
#else
        ix();
#endif
    }
}
Esempio n. 6
0
Tube& Tube::ctcBwd(const Function& f) {
	assert((f.nb_var()==1)&&(f.nb_arg()==1));
	IntervalVector lx(1);
	IntervalVector ux(1);
	for(int i=(*this).size()-1;i>=1;i--){
		lx[0]= Interval(_t0+i*_deltaT,_t0+(i+1)*_deltaT);
		ux[0]= Interval(_t0+i*_deltaT,_t0+(i+1)*_deltaT);
// Euler formulation  TODO replace it by RK4 or VNODES
		(*this)[i-1] &= (*this)[i]-Interval(f.eval_vector(lx)[0].lb(),f.eval_vector(ux)[0].ub())*_deltaT;
	}
	return *this;
}
Esempio n. 7
0
Tube::Tube(double t0, double tf, double step, const Function& fmin, const Function& fmax) :
                				IntervalVector((int)round(((tf - t0) / step)), Interval::ALL_REALS),_t0(t0), _tf(tf), _deltaT(step) {

	IntervalVector lx(1);
	IntervalVector ux(1);

	for(int i=0;i<size();i++) {
		lx[0]= Interval(t0+i*step,t0+(i+1)*step);// FIXME A corriger pas robuste, idee stocke les temps dans un tableau pour eviter de les recalculer et d'accumuler des erreurs
		ux[0]= Interval(t0+i*step,t0+(i+1)*step);

		(*this)[i]=Interval(fmin.eval_vector(lx)[0].lb(),fmax.eval_vector(ux)[0].ub());
	}
}
Esempio n. 8
0
void load_fields_on_fft( const Triangulation& T , CH_FFT& fft  ) {

  int Nb = fft.Nx();

  size_t align=fft.alignment();

  c_array ux( Nb , Nb , align );
  c_array uy( Nb , Nb , align );

  for(F_v_it vit=T.vertices_begin();
      vit != T.vertices_end();
      vit++) {

    int nx = vit->nx.val();
    int ny = vit->ny.val();

    // "right" ordering 
    int i = ( Nb - 1 ) - ny ;
    int j = nx;

    // "wrong" ordering
    // int i = nx;
    // int j = ny;
    
    Vector_2 vv =  vit->Uold.val();
    //FT val =  vit->alpha.val();

    ux(i,j) = vv.x();
    uy(i,j) = vv.y();

  }

  fft.set_u( ux , uy );
  
  return;
}
Esempio n. 9
0
TEST(UX, Crossover){
  Individual mom("02134");
  Individual dad("41302");

  std::vector<int> indices;
  indices.push_back(1);
  indices.push_back(3);

  UX ux(2);
  Individual child = ux.cross(indices, &dad, &mom);
  
  ASSERT_EQ(Individual("31204"), child);
  ASSERT_EQ(&dad, child.parent(0));
  ASSERT_EQ(&mom, child.parent(1));
}
Esempio n. 10
0
void PenWindow::layout()
{
   CEGUI::UDim ux(0,10);
   CEGUI::UDim uy(0,0);
   CEGUI::UDim uw(0,0);
   CEGUI::UDim uh(0,0);

   CEGUI::Size size = getPixelSize();

   {
      CEGUI::UVector2 bsize;
      bsize.d_x = CEGUI::UDim(0,BUTTON_SIZE);
      bsize.d_y = CEGUI::UDim(0,BUTTON_SIZE);

      const int cellsize = (BUTTON_SIZE + SPACE_SIZE);
      int nx = (int)(size.d_width - (2*MARGIN_SIZE)) / cellsize;
      if (nx < 1) { nx = 1; }

      int xi = 0;
      int yi = 0;
      CEGUI::UDim x(0,0),y(0,0);
      for (size_t i=0; i<_button.size(); ++i) {
         for (size_t j=0; j<_button[i].size(); ++j) {
            x.d_offset = MARGIN_SIZE + (0.5f * SPACE_SIZE) + xi*cellsize;
            y.d_offset = MARGIN_SIZE + (0.5f * SPACE_SIZE) + yi*cellsize;
            _button[i][j]->setSize(bsize);
            _button[i][j]->setPosition(CEGUI::UVector2(x,y));

            xi++;
            if (xi == nx) {
               xi = 0;
               yi++;
            }
         }
         yi++;
         xi = 0;
      }
   }
}
int main()
{
	X x;

	// 1- Check pass by reference mechanism
	std::thread t(setX, 1, std::ref(x));
	t.join();
	std::cout<<"x int value: "<<x.get()<<std::endl;

	t = std::thread(setX_ptr, 2, &x);
    t.join();
	std::cout<<"x int value: "<<x.get()<<std::endl;

	t = std::thread(&X::set, &x, 3);
	t.join();
	std::cout<<"x int value: "<<x.get()<<std::endl;

	// 2 - Move only argument type
	std::unique_ptr<X> ux(new X);
	ux->set(-3);
	t = std::thread(setX_move,23,std::move(ux));
	assert(!ux);
	t.join();
}
 double FindObjectOnPlane::drawAngle(
   cv::Mat& out_image, const cv::Point2f& test_point, const double angle,
   const double max_x, const double max_y,
   const image_geometry::PinholeCameraModel& model,
   const jsk_recognition_utils::Plane::Ptr& plane,
   cv::Scalar color)
 {
   Eigen::Vector2f ux(cos(angle/180*M_PI), sin(angle/180*M_PI));
   cv::Point2d uy_end = getUyEnd(
     test_point, cv::Point2d(test_point.x + ux[0], test_point.y + ux[1]),
     model, plane);
   Eigen::Vector2f uy(uy_end.x - test_point.x, uy_end.y - test_point.y);
   //Eigen::Vector2f uy(sin(angle/180*M_PI), -cos(angle/180*M_PI));
   Eigen::Vector2f to_point = ux * max_x + Eigen::Vector2f(test_point.x, test_point.y);
   Eigen::Vector2f to_point2 = uy * max_y + Eigen::Vector2f(test_point.x, test_point.y);
   cv::Point2f to_point_cv(to_point[0], to_point[1]);
   cv::Point2f to_point2_cv(to_point2[0], to_point2[1]);
   cv::Point2f to_point3_cv = to_point_cv + to_point2_cv - test_point;
   cv::line(out_image, test_point, to_point_cv, color, 4);
   cv::line(out_image, test_point, to_point2_cv, color, 4);
   cv::line(out_image, to_point_cv, to_point3_cv, color, 4);
   cv::line(out_image, to_point2_cv, to_point3_cv, color, 4);
   return max_x * max_y;       // TODO: it's not correct!
 }
Esempio n. 13
0
	/// Get right unit vector
	Vec3d ur() const { return ux(); }
Esempio n. 14
0
void MMS(vector<myData> & F_out, vector<myData> & Ftt_out, FDM::baseSolver& sol, const vector<myData>& u,int step,double t, void * args){
    double x = 0;
    double y = 0;
    double z = 0;
    
    int LN_X = sol.X_LayerNumber();
    int LN_Y = sol.Y_LayerNumber();
    int LN_Z = sol.Z_LayerNumber();
    
    int Nx,Ny,Nz;
    int index = 0;
    for (int lz = 0; lz < LN_Z; lz++) {
        for (int ly = 0; ly < LN_Y; ly++) {
            for (int lx = 0; lx < LN_X; lx++) {
                
                index = idx(lx, ly, lz);
                Nx = u[index].Nx();
                Ny = u[index].Ny();
                Nz = u[index].Nz();
                
                myData ux(Nx,Ny,Nz);
                myData uy(Nx,Ny,Nz);
                myData uz(Nx,Ny,Nz);
                
                myData Bux(Nx,Ny,Nz);
                myData Buy(Nx,Ny,Nz);
                myData Buz(Nx,Ny,Nz);
                
                for (int k = 0; k < Nz; k++) {
                    z = sol.Z(k,lz);
                    for (int j = 0; j < Ny; j++) {
                        y = sol.Y(j,ly);
                        for (int i = 0; i < Nx; i++) {
                            x = sol.X(i,lx);
                            
                            
                            F_out[index](i,j,k)     =  8*M_PI*M_PI*cos(2*M_PI*t)*cos(2*M_PI*x)*cos(2*M_PI*y)*cos(2*M_PI*z);
                            Ftt_out[index](i,j,k)   = -4*M_PI*M_PI*F_out[index](i,j,k);
                            
                            ux(i,j,k)               = -2*M_PI*cos(2*M_PI*t)*sin(2*M_PI*x)*cos(2*M_PI*y)*cos(2*M_PI*z);//ux boundary
                            uy(i,j,k)               = -2*M_PI*cos(2*M_PI*t)*cos(2*M_PI*x)*sin(2*M_PI*y)*cos(2*M_PI*z);//uy
                            uz(i,j,k)               = -2*M_PI*cos(2*M_PI*t)*cos(2*M_PI*x)*cos(2*M_PI*y)*sin(2*M_PI*z);//uz
                        }
                    }
                }
                
                //Bux setup
                if (lx == 0) {
                    for (int k = 0; k < Nz; k++) {
                        for (int j = 0; j < Ny; j++) {
                            Bux(0,j,k) = -1;
                        }
                    }
                }
                
                if (lx == LN_X - 1) {
                    for (int k = 0; k < Nz; k++) {
                        for (int j = 0; j < Ny; j++) {
                            Bux(Nx - 1,j,k) = 1;
                        }
                    }
                }
                //
                
                ///Buy setup
                if (ly == 0) {
                    for (int k = 0; k < Nz; k++) {
                        for (int i = 0; i < Nx; i++) {
                            Buy(i,0,k) = -1;
                        }
                    }
                }
                
                if (ly == LN_Y - 1) {
                    for (int k = 0; k < Nz; k++) {
                        for (int i = 0; i < Nx; i++) {
                            Buy(i,Ny - 1,k) = 1;
                        }
                    }
                }
                //
                
                //Buz setup
                if (lz == 0) {
                    for (int j = 0; j < Ny; j++) {
                        for (int i = 0; i < Nx; i++) {
                            Buz(i,j,0) = -1;
                        }
                    }
                }
                
                if (lz == LN_Z - 1) {
                    for (int j = 0; j < Ny; j++) {
                        for (int i = 0; i < Nx; i++) {
                            Buz(i,j,Nz - 1) = 1;
                        }
                    }
                }
                //
                
                F_out[index] += sol.H_INV()*(Bux*ux + Buy*uy + Buz*uz);
            }
        }
    }
}