Пример #1
0
//---------------------------------------------------------------
// get cut-points
void getcutpoints(int nc, int n_cov, int n_samp,
                 std::vector<std::vector<double> >& X, xinfo& xi){
   double xinc; //increments
   double xx;


   std::vector<double> minx(n_cov,R_PosInf); // to store the minimum of each of the individual specific pred
   std::vector<double> maxx(n_cov,R_NegInf);// to store the max of each of the individual specific pred

      for(int j=0;j<n_cov;j++) {
      for(int i=0;i<n_samp;i++) {
         xx = X[i][j];
         if(xx < minx[j]) minx[j]=xx;
         if(xx > maxx[j]) maxx[j]=xx;
      }
   }



   //make grid of nc cutpoints between min and max for each x.
   xi.resize(n_cov);
   for(int i=0;i<n_cov;i++) {
      xinc = (maxx[i]-minx[i])/(nc+1.0);
      xi[i].resize(nc);
      for(int j=0;j<nc;j++) xi[i][j] = minx[i] + (j+1)*xinc;
   }


}
Пример #2
0
	bool intersects(PRECISION x, PRECISION y) const {
		if (x < minx() || maxx() < x || y < miny() || maxy() < y) {
			return false;
		} else {
			return true;
		}
	}
Пример #3
0
void eu066(char *ans) {
  const int N = 1000;
  int d_of_max = 0;
  mpz_t x, max;

  mpz_init(x);
  mpz_init(max);
  mpz_set_ui(max, 0);

  for (int d = 1; d < N; d++) {
    if (issquare(d)) continue;

    minx(d, x);

    if (mpz_cmp(x, max) > 0) {
      mpz_set(max, x);
      d_of_max = d;
    }
  }

  mpz_clear(x);
  mpz_clear(max);

  sprintf(ans, "%d", d_of_max);
}
Пример #4
0
bool Rect::intersects(const Rect& other) const {
    if (other.maxx() < minx() || other.minx() > maxx() ||
            other.maxy() < miny() || other.miny() > maxy()) {
        return false;
    } else {
        return true;
    }
}
Пример #5
0
 // Offsets member bound box at [i] and align with (x, y), in direction <x_dir, y_dir>
 // stores corresponding offset, and returns modified bounding box
 bound_box box_offset_align(size_t i, double x, double y, int x_dir, int y_dir) const
 {
     auto box = member_boxes_[i];
     auto & offset = member_offsets_[i];
     offset.x = x - (x_dir == 0 ? input_origin_.x : (x_dir < 0 ? box.maxx() : box.minx()));
     offset.y = y - (y_dir == 0 ? input_origin_.y : (y_dir < 0 ? box.maxy() : box.miny()));
     box.move(offset.x, offset.y);
     return box;
 }
char* longestPalindrome(char* s) 
{
	int len = strlen(s);
	if (len <= 1)return s;
	char *str = (char *)calloc(2 * len + 3, sizeof(char));
	int *p = (int *)calloc(2 * len + 3, sizeof(int));

	int id = 0, mx = 1;
	str[0] = '$', str[2 * len + 1] = '#', str[2 * len + 2] = '\0';

	for (int i = 0; i < len; ++i)
	{
		str[2 * i + 2] = s[i];
		str[2 * i + 1] = '#';
	}

	int res = -1, mid = 0;
	for (int i = 2; i <= 2 * len; ++i)
	{
		if (i < mx)
		{
			p[i] = minx(p[2 * id - i], mx - i);
		}
		else
		{
			p[i] = 1;
		}

		while (str[i + p[i]] == str[i - p[i]])++p[i];
		if (p[i] > res)
		{
			res = p[i];
			mid = i;
		}
		if (i + p[i] > mx)
		{
			id = i;
			mx = i + p[i];
		}
	}
	char *dest = (char *)calloc(res, sizeof(char));
	strncpy(dest, s + (mid - res) / 2, res - 1);
	free(p);
	free(str);
	return dest;
}
Пример #7
0
/*
 * Intoarce coordonata x a centrului figurii.
 */
double get_centerx()
{
    return minx()+(maxx()-minx())/2;
}
Пример #8
0
bool Rect::containsPoint(Point point) const {
    return point.x >= minx() && point.x <= maxx() && point.y >= miny() &&
           point.y <= maxy();
}
Пример #9
0
int main (int argc, char** argv)
{
    //using namespace mapnik;
    namespace po = boost::program_options;
    bool verbose = false;
    bool validate_features = false;
    unsigned int depth = DEFAULT_DEPTH;
    double ratio = DEFAULT_RATIO;
    std::vector<std::string> files;
    char separator = 0;
    char quote = 0;
    std::string manual_headers;
    try
    {
        po::options_description desc("Mapnik CSV/GeoJSON index utility");
        desc.add_options()
            ("help,h", "produce usage message")
            ("version,V","print version string")
            ("verbose,v","verbose output")
            ("depth,d", po::value<unsigned int>(), "max tree depth\n(default 8)")
            ("ratio,r",po::value<double>(),"split ratio (default 0.55)")
            ("separator,s", po::value<char>(), "CSV columns separator")
            ("quote,q", po::value<char>(), "CSV columns quote")
            ("manual-headers,H", po::value<std::string>(), "CSV manual headers string")
            ("files",po::value<std::vector<std::string> >(),"Files to index: file1 file2 ...fileN")
            ("validate-features", "Validate GeoJSON features")
            ;

        po::positional_options_description p;
        p.add("files",-1);
        po::variables_map vm;
        po::store(po::command_line_parser(argc, argv).options(desc).positional(p).run(), vm);
        po::notify(vm);

        if (vm.count("version"))
        {
            std::clog << "version 1.0.0" << std::endl;
            return 1;
        }
        if (vm.count("help"))
        {
            std::clog << desc << std::endl;
            return 1;
        }
        if (vm.count("verbose"))
        {
            verbose = true;
        }
        if (vm.count("validate-features"))
        {
            validate_features = true;
        }
        if (vm.count("depth"))
        {
            depth = vm["depth"].as<unsigned int>();
        }
        if (vm.count("ratio"))
        {
            ratio = vm["ratio"].as<double>();
        }
        if (vm.count("separator"))
        {
            separator = vm["separator"].as<char>();
        }
        if (vm.count("quote"))
        {
            quote = vm["quote"].as<char>();
        }
        if (vm.count("manual-headers"))
        {
            manual_headers = vm["manual-headers"].as<std::string>();
        }
        if (vm.count("files"))
        {
            files=vm["files"].as<std::vector<std::string> >();
        }
    }
    catch (std::exception const& ex)
    {
        std::clog << "Error: " << ex.what() << std::endl;
        return EXIT_FAILURE;
    }

    std::vector<std::string> files_to_process;

    for (auto const& filename : files)
    {
        if (!mapnik::util::exists(filename))
        {
            continue;
        }

        if (mapnik::detail::is_csv(filename) || mapnik::detail::is_geojson(filename))
        {
            files_to_process.push_back(filename);
        }
    }

    if (files_to_process.size() == 0)
    {
        std::clog << "no files to index" << std::endl;
        return EXIT_FAILURE;
    }

    std::clog << "max tree depth:" << depth << std::endl;
    std::clog << "split ratio:" << ratio << std::endl;

    using box_type = mapnik::box2d<float>;
    using item_type = std::pair<box_type, std::pair<std::size_t, std::size_t>>;

    for (auto const& filename : files_to_process)
    {
        if (!mapnik::util::exists(filename))
        {
            std::clog << "Error : file " << filename << " does not exist" << std::endl;
            continue;
        }

        std::vector<item_type> boxes;
        box_type extent;
        if (mapnik::detail::is_csv(filename))
        {
            std::clog << "processing '" << filename << "' as CSV\n";
            auto result = mapnik::detail::process_csv_file(boxes, filename, manual_headers, separator, quote);
            if (!result.first) continue;
            extent = result.second;
        }
        else if (mapnik::detail::is_geojson(filename))
        {
            std::clog << "processing '" << filename << "' as GeoJSON\n";
            auto result = mapnik::detail::process_geojson_file(boxes, filename, validate_features, verbose);
            if (!result.first)
            {
                std::clog << "Error: failed to process " << filename << std::endl;
                continue;
            }
            extent = result.second;
        }

        if (extent.valid())
        {
            std::clog << extent << std::endl;
            mapnik::box2d<double> extent_d(extent.minx(), extent.miny(), extent.maxx(), extent.maxy());
            mapnik::quad_tree<std::pair<std::size_t, std::size_t>> tree(extent_d, depth, ratio);
            for (auto const& item : boxes)
            {
                auto ext_f = std::get<0>(item);
                tree.insert(std::get<1>(item), mapnik::box2d<double>(ext_f.minx(), ext_f.miny(), ext_f.maxx(), ext_f.maxy()));
            }

            std::fstream file((filename + ".index").c_str(),
                              std::ios::in | std::ios::out | std::ios::trunc | std::ios::binary);
            if (!file)
            {
                std::clog << "cannot open index file for writing file \""
                          << (filename + ".index") << "\"" << std::endl;
            }
            else
            {
                tree.trim();
                std::clog <<  "number nodes=" << tree.count() << std::endl;
                std::clog <<  "number element=" << tree.count_items() << std::endl;
                file.exceptions(std::ios::failbit | std::ios::badbit);
                tree.write(file);
                file.flush();
                file.close();
            }
        }
    }
    std::clog << "done!" << std::endl;
    return EXIT_SUCCESS;
}
Пример #10
0
char twotail_exact(struct tw *m, double *cp, double *sp)
#define PR (*cp)
#define FT (*sp)
  {
  char k;
  struct entry em;
  double sec_prob, check, orig_p;
  int orig_cross;
        em=copy_entry(m);
        if( !(em.x1 * em.x4 - em.x2 * em.x3) ) {
	  printf("exact fit -> det = 0\n");
          *cp=1.;
          *sp=0.5;
          exactfit=1;
          return 1;
        }

                            /* probability of the original table */
        if((PR=hypergeom(&em)) < 0.0) {
	   PR=FT=DMY;
	   return -1;
        }

        k=minx(&em);
    orig_p=PR;
    switch (k) {   /* first tail */

      case 1:
        while( em.x1 && em.x4 ) {
           --em.x1;       /* decrement 11-22 diagonal */
           --em.x4;
           ++em.x2;
           ++em.x3;
           if((check=hypergeom(&em)) < 0.0) {
                        PR=FT=DMY;
			return -1;
           }
           PR+=check;
        }
      break;

      case 2:
        while( em.x2 && em.x3 ) {
           --em.x2;        /* decrement 12-21 diagonal */
           --em.x3;
           ++em.x1;
           ++em.x4;
           if((check=hypergeom(&em)) < 0.0) {
			PR=FT=DMY;
                        return -1;
           }
           PR+=check;
        }
      break;
    }
#define X1 em.x1
#define X2 em.x2
#define X3 em.x3
#define X4 em.x4


    /* second tail */

    em=copy_entry(m);
    orig_cross = ABS( X1*X4 - X2*X3 );
    sec_prob=0.0;
    switch (k) {

        case 1:
        while( em.x2 && em.x3 ) {
           --em.x2;        /* decrement 12-21 diagonal */
           --em.x3;
           ++em.x1;
           ++em.x4;
	   if ( ABS( X1*X4 - X2*X3 ) < orig_cross ) continue;
           if((check=hypergeom(&em)) < 0.0) {
                        PR=FT=DMY;
                        return -1;
           }
           if(check > orig_p) continue;
           sec_prob+=check;
        }
        break;

        case 2:
        while( em.x1 && em.x4 ) {
           --em.x1;        /* decrement  11-22 diagonal */
	   --em.x4;
           ++em.x2;
           ++em.x3;
           if ( ABS( X1*X4 - X2*X3 ) < orig_cross  ) continue;
           if((check=hypergeom(&em)) < 0.0) {
                        PR=FT=DMY;
                        return -1;
           }
           if(check > orig_p) continue;
           sec_prob+=check;
        }
        break;
    }

    /* probabilities  */
    FT=PR;         /* first tail (closest) */
    PR+=sec_prob;  /* both tails */
    return 1;

    #undef PR
    #undef FT
    #undef X1
    #undef X2
    #undef X3
    #undef X4
  }
Пример #11
0
	/**
	 * Calculate and return the width/height
	 * ie. maxx/maxy - minx/miny respectively.
	 */
	PRECISION get_width()  const { return maxx() - minx(); }
Пример #12
0
	/**
	 * Calculate and return the center
	 */
	PRECISION get_xcenter() const { return (maxx() + minx()) / 2; }