Ejemplo n.º 1
0
void * _create_int_hashtable_on_column(struct Block * block, const char * column_name)
{
  int row_id, column_id = get_column_id_by_name_or_exit(block, column_name);
  struct hashtable * ht = create_hashtable(16, hash_from_int_fn, ints_equal_fn);
  
  num_metas++;
  metas = (struct hashtable_meta *)realloc(metas, sizeof(struct hashtable_meta)*num_metas);
  struct hashtable_meta * meta = &metas[num_metas-1];
  
  meta->ht = ht;
  meta->block = block;
  meta->row_ids = NULL;
  
  int dups = 0;
  for (row_id = 0 ; row_id < block->num_rows ; row_id++)
  {
    if (hashtable_search(ht, get_cell(block, row_id, column_id)) == NULL)
    {
      hashtable_insert(ht, get_cell(block, row_id, column_id), get_row(block, row_id));
    }
    else dups++;
  }
  if (dups > 0) fprintf(stderr, "%s('%s'), there are %d duplicate rows (ignored) of total: %d\n", __func__, column_name, dups, block->num_rows);
  return (void*)ht;
}
Ejemplo n.º 2
0
void algorithms::KDDecomposer<IROBOT>::AdaptiveDecompose(double larg_radius, double min_radius)
{
    this->ShallowDecompose(larg_radius);
    algorithms::Analyzer<IROBOT> analyzer( *this );
    //importance = analyzer.build_simple_weighted_centrality_matrix(M_PI/8, M_PI/64);
    std::vector<double> importance = analyzer.build_path_importance_matrix(larg_radius * 7, larg_radius);
    // node_index --> importance
    std::unordered_map<int, double> impt_map;
    std::stack<int> stack;
    for( int i = 0; i < this->cells.size(); i++ )
    {
        double cell_radius = get_cell(i).radius();
        if(cell_radius > larg_radius*2)
            continue;
        stack.push(get_cell(i).node_id);
        impt_map[get_cell(i).node_id] = importance[i];
    }
    this->cells.clear();
    
    this->DecomposeSubspaces( stack, larg_radius, min_radius, impt_map );
    this->cells.reserve(nodes.size());
    nodes.shrink_to_fit();
    cells.shrink_to_fit();
    clean_tree();
    build_edges();
}
Ejemplo n.º 3
0
//frontier for hegemony
int frontier (char * b, char color) {
  int f = 0;
  int in_frontier = 0;
  int i;
  int j;
  for (i = 0; i<BOARD_SIZE; i++) {
    for (j = 0; j<BOARD_SIZE; j++) {
      in_frontier = 0;
      if (get_cell(i,j,b) != color) {
	if (in_board(i,j+1)) {
	  if (get_cell(i,j+1,b)==color) {
	    in_frontier = 1;
	  }}
	if (in_board(i,j-1)) {
	  if (get_cell(i,j-1,b)==color) {
	    in_frontier = 1;
	    }}
	if (in_board(i+1,j)) {
	  if (get_cell(i+1,j,b)==color) {
	    in_frontier = 1;
	    }}
	if (in_board(i-1,j)) {
	  if (get_cell(i-1,j,b)==color) {
	    in_frontier = 1;
	    }}
	f += in_frontier;
      }
    }
  }
  return f;
}
Ejemplo n.º 4
0
void
check_result(matrix * cc, matrix * aa)
{
    /* Checks that each element in cc is twice the
     * coresponding element in aa.
     *
     * This assumes square matrixes, an identity matrix
     * for bb, and a spin value of 2.
     */

    const DTYPE EPS = 0.001;

    for (size_t ii = 0; ii < cc->rows; ++ii) {
        for (size_t jj = 1; jj < cc->cols; ++jj) {
            DTYPE xx = get_cell(aa, ii, jj);
            DTYPE yy = get_cell(cc, ii, jj);

            if (abs(SPIN*xx - yy) > EPS) {
                printf("ERROR - Incorrect result.\n");
                printf("At %ld, %ld got %f instead of %f\n",
                       ii, jj, yy, xx);
                return;
            }
        }
    }

    printf("Result is correct.\n");
    printf("[cake: OK]\n");
}
Ejemplo n.º 5
0
    void test_write_height()
    {
		auto ws = wb_.create_sheet();
        ws.get_cell("F1").set_value(10);
        ws.get_row_properties(ws.get_cell("F1").get_row()).set_height(30);
        auto content = xlnt::writer::write_worksheet(ws, {}, {});
        TS_ASSERT(Helper::EqualsFileContent(PathHelper::GetDataDirectory() + "/writer/expected/sheet1_height.xml", content));
    }
Ejemplo n.º 6
0
    void test_write_hyperlink()
    {
		auto ws = wb_.create_sheet();
        ws.get_cell("A1").set_value("test");
        ws.get_cell("A1").set_hyperlink("http://test.com");
        auto content = xlnt::writer::write_worksheet(ws, {"test"}, {});
        TS_ASSERT(Helper::EqualsFileContent(PathHelper::GetDataDirectory() + "/writer/expected/sheet1_hyperlink.xml", content));
    }
Ejemplo n.º 7
0
    void test_hyperlink_value()
    {
		auto ws = wb_.create_sheet();
        ws.get_cell("A1").set_hyperlink("http://test.com");
        TS_ASSERT_EQUALS("http://test.com", ws.get_cell("A1").get_value());
        ws.get_cell("A1").set_value("test");
        TS_ASSERT_EQUALS("test", ws.get_cell("A1").get_value());
    }
Ejemplo n.º 8
0
 void test_write_bool()
 {
     auto ws = wb_.create_sheet();
     ws.get_cell("F42").set_value(false);
     ws.get_cell("F43").set_value(true);
     auto content = xlnt::writer::write_worksheet(ws, {}, {});
     TS_ASSERT(Helper::EqualsFileContent(PathHelper::GetDataDirectory() + "/writer/expected/sheet1_bool.xml", content));
 }
void recalculate_grid_cpu
(
    unsigned char* output_cell_grid,
    const unsigned char* input_cell_grid,
    unsigned width,
    unsigned height
) {

    // 1) Any live cell with fewer than two live neighbours dies, as if caused by under-population.
    // 2) Any live cell with two or three live neighbours lives on to the next generation.
    // 3) Any live cell with more than three live neighbours dies, as if by over-population.
    // 4) Any dead cell with exactly three live neighbours becomes a live cell, as if by reproduction.
    //
    // and...
    //
    // if a cell is on a boundary, non-existent neighbors should be counted as dead cells.

    // Loop through every x and y, count the number of alive neighbors,
    // apply the rule, fill in output_cell_grid

    for (int x = 0; x < (int)width; x++) {
        for (int y = 0; y < (int)height; y++) {
            int neighbor_sum = 0;
            bool curr_cell_alive = get_cell(input_cell_grid, x, y, width, height);
            bool next_cell_alive = curr_cell_alive;
            //get sum of neighbors
            for(int j = -1; j < 2; j++) {
                for(int i = -1; i < 2; i++) {
                    if (i != 0 || j != 0)
                    {
                        if (get_cell(input_cell_grid, x+i, y+j, width, height)) {
                            neighbor_sum++;
                        }
                    }
                }
            }
            //check rules
            if(curr_cell_alive)
            {
                if(neighbor_sum < 2)//under-population rule
                    next_cell_alive = false;
                else if(neighbor_sum < 4)
                    next_cell_alive = true;
                else
                    next_cell_alive = false;
            }
            else
            {
                if(neighbor_sum == 3)
                    next_cell_alive = true;
                else
                    next_cell_alive = false;
            }
            write_cell(next_cell_alive, x, y, width, height, output_cell_grid);
        }
    }

}
Ejemplo n.º 10
0
int algorithms::Planner<IROBOT>::find_next_owner(int cell, const CONFIG& bnd_cfg ) const
{
    for (int index : get_cell(cell).get_boundaries()) {
        int neighbor = get_boundary(index).otherside(cell);
        if(get_cell(neighbor).on_boundary(bnd_cfg.vector(), 1e-15))
            return neighbor;
    }
    return NOT_FOUND;
}
Ejemplo n.º 11
0
    void test_write_formula()
    {
		auto ws = wb_.create_sheet();
        ws.get_cell("F1").set_value(10);
        ws.get_cell("F2").set_value(32);
        ws.get_cell("F3").set_formula("F1+F2");
        auto content = xlnt::writer::write_worksheet(ws, {}, {});
        TS_ASSERT(Helper::EqualsFileContent(PathHelper::GetDataDirectory() + "/writer/expected/sheet1_formula.xml", content));
    }
Ejemplo n.º 12
0
 void test_read_worksheet()
 {
     auto wb = standard_workbook();
     auto sheet2 = wb.get_sheet_by_name("Sheet2 - Numbers");
     TS_ASSERT_DIFFERS(sheet2, nullptr);
     TS_ASSERT_EQUALS("This is cell G5", sheet2.get_cell("G5").get_value<std::string>());
     TS_ASSERT_EQUALS(18, sheet2.get_cell("D18").get_value<int>());
     TS_ASSERT_EQUALS(true, sheet2.get_cell("G9").get_value<bool>());
     TS_ASSERT_EQUALS(false, sheet2.get_cell("G10").get_value<bool>());
 }
Ejemplo n.º 13
0
void algorithms::Planner<IROBOT>::find_next_owners(int cell, const CONFIG& bnd_cfg, std::vector<int>& result) const
{
    result.clear();
    for (int index : get_cell(cell).get_boundaries()) {
        int neighbor = get_boundary(index).otherside(cell);
        if(get_cell(neighbor).on_boundary(bnd_cfg, 1e-15))
            result.emplace_back( neighbor );
        
    }
}
Ejemplo n.º 14
0
 void test_read_compare_mac_win_dates()
 {
     auto wb_mac = date_mac_1904();
     auto ws_mac = wb_mac["Sheet1"];
     auto wb_win = date_std_1900();
     auto ws_win = wb_win["Sheet1"];
     xlnt::datetime dt(2011, 10, 31);
     TS_ASSERT_EQUALS(ws_mac.get_cell("A1").get_value<xlnt::datetime>(), dt);
     TS_ASSERT_EQUALS(ws_win.get_cell("A1").get_value<xlnt::datetime>(), dt);
     TS_ASSERT_EQUALS(ws_mac.get_cell("A1").get_value<xlnt::datetime>(), ws_win.get_cell("A1").get_value<xlnt::datetime>());
 }
Ejemplo n.º 15
0
Archivo: smoke.c Proyecto: jinjoh/NOOR
static void smoke_calc_transparency(float *result, float *input, float *p0, float *p1, int res[3], float dx, float *light, bresenham_callback cb, float correct)
{
	int x, y, z;
	float bv[6];

	memset(result, -1, sizeof(float)*res[0]*res[1]*res[2]);	// x
	bv[0] = p0[0];
	bv[1] = p1[0];
	// y
	bv[2] = p0[1];
	bv[3] = p1[1];
	// z
	bv[4] = p0[2];
	bv[5] = p1[2];

#pragma omp parallel for schedule(static) private(y, z)
	for(x = 0; x < res[0]; x++)
		for(y = 0; y < res[1]; y++)
			for(z = 0; z < res[2]; z++)
			{
				float voxelCenter[3];
				size_t index;
				float pos[3];
				int cell[3];
				float tRay = 1.0;

				index = smoke_get_index(x, res[0], y, res[1], z);

				if(result[index] >= 0.0f)					
					continue;								
				voxelCenter[0] = p0[0] + dx *  x + dx * 0.5;
				voxelCenter[1] = p0[1] + dx *  y + dx * 0.5;
				voxelCenter[2] = p0[2] + dx *  z + dx * 0.5;

				// get starting position (in voxel coords)
				if(BLI_bvhtree_bb_raycast(bv, light, voxelCenter, pos) > FLT_EPSILON)
				{
					// we're ouside
					get_cell(p0, res, dx, pos, cell, 1);
				}
				else
				{
					// we're inside
					get_cell(p0, res, dx, light, cell, 1);
				}

				bresenham_linie_3D(cell[0], cell[1], cell[2], x, y, z, &tRay, cb, result, input, res, correct);

				// convention -> from a RGBA float array, use G value for tRay
// #pragma omp critical
				result[index] = tRay;			
			}
}
Ejemplo n.º 16
0
    void test_write_hyperlink_rels()
    {
		auto ws = wb_.create_sheet();
        TS_ASSERT_EQUALS(0, ws.get_relationships().size());
        ws.get_cell("A1").set_value("test");
        ws.get_cell("A1").set_hyperlink("http://test.com/");
        TS_ASSERT_EQUALS(1, ws.get_relationships().size());
        ws.get_cell("A2").set_value("test");
        ws.get_cell("A2").set_hyperlink("http://test2.com/");
        TS_ASSERT_EQUALS(2, ws.get_relationships().size());
        auto content = xlnt::writer::write_worksheet_rels(ws);
        TS_ASSERT(Helper::EqualsFileContent(PathHelper::GetDataDirectory() + "/writer/expected/sheet1_hyperlink.xml.rels", content));
    }
Ejemplo n.º 17
0
//available space for starve strategy
int available(char* b, char color) {
  int matrix[BOARD_SIZE * BOARD_SIZE] = {0};
  int av = 0;
  int otherPlayer = other(color);
  char change = 1;
  int i = 0;
  int j = 0;
  for (i = 0; i<BOARD_SIZE; i++) {
    for (j = 0; j<BOARD_SIZE; j++) {
      if (get_cell(i,j,b) == color) {
        matrix[j*BOARD_SIZE + i] = 1;
        av += 1;
      }
    }
  }
  while (change) {
    change = 0;
    for (i = 0; i < BOARD_SIZE; i++) {
      for (j = 0; j < BOARD_SIZE; j++) {
        if (get_cell(i,j,b) != otherPlayer && !matrix[j*BOARD_SIZE + i]){
          if (in_board(i+1, j)) {
            if (matrix[j*BOARD_SIZE + i+1]){
              matrix[j*BOARD_SIZE + i] = 1;
              change = 1;
            }
          }
          if (in_board(i-1, j)) {
            if (matrix[j*BOARD_SIZE + i-1]){
              matrix[j*BOARD_SIZE + i] = 1;
              change = 1;
            }
          }
          if (in_board(i, j+1)) {
              if (matrix[(j+1)*BOARD_SIZE + i]) {
                matrix[j*BOARD_SIZE + i] = 1;
                change = 1;
              }
          }
          if (in_board(i, j-1)) {
            if (matrix[(j-1)*BOARD_SIZE + i]) {
              matrix[j*BOARD_SIZE + i] = 1;
              change = 1;
            }
          }
        av += matrix[j*BOARD_SIZE + i];
      }
    }
  }
}
return av;
}
Ejemplo n.º 18
0
//update, given player, choice and board
void update_board(char player, char color, char * b) {
  int i,j;
  int change = 0;
  for (i=0; i<BOARD_SIZE; i++) {
    for (j=0; j<BOARD_SIZE; j++) {
      if (get_cell(i,j,b) == color) {
	if (in_board(i-1,j)) {if (get_cell(i-1,j,b) == player) {set_cell(i,j,player,b); change = 1;}}
	if (in_board(i+1,j)) {if (get_cell(i+1,j,b) == player) {set_cell(i,j,player,b); change = 1;}}
	if (in_board(i,j-1)) {if (get_cell(i,j-1,b) == player) {set_cell(i,j,player,b); change = 1;}}
	if (in_board(i,j+1)) {if (get_cell(i,j+1,b) == player) {set_cell(i,j,player,b); change = 1;}}
      }
    }
  }
  if (change) {update_board(player, color, b );}
}
Ejemplo n.º 19
0
/*
** Set the map to default food = 0 & rocks[type_rock] = 0
*/
void			set_initialize_map(int x, int y)
{
  t_map_elt		*map_elt;
  int			cpt;
  int			cpt_2;
  int			int_rocks;

  cpt = 0;
  while (cpt < x)
    {
      cpt_2 = 0;
      while (cpt_2 < y)
	{
	  map_elt = get_cell(cpt, cpt_2);
	  map_elt->food = 0;
	  int_rocks = 0;
	  while (int_rocks < NB_ROCKS)
	    {
	      map_elt->rocks[int_rocks] = 0;
	      int_rocks++;
	    }
	  cpt_2++;
	}
      cpt++;
    }
}
Ejemplo n.º 20
0
int open_map(MAPS* rast) {
	
	int row, col;
	int fd;
	char* mapset;
	struct Cell_head cellhd;
	int bufsize;
	void* tmp_buf;
	
    mapset = (char*)G_find_raster2(rast->elevname, "");	
	
	    if (mapset == NULL)
		G_fatal_error(_("Raster map <%s> not found"), rast->elevname);
	
		rast->fd = Rast_open_old(rast->elevname, mapset);
		Rast_get_cellhd(rast->elevname, mapset, &cellhd);
		rast->raster_type = Rast_map_type(rast->elevname, mapset);

    if (window.ew_res < cellhd.ew_res || window.ns_res < cellhd.ns_res)
	G_warning(_("Region resolution shoudn't be lesser than map %s resolution. Run g.region rast=%s to set proper resolution"),
		      rast->elevname, rast->elevname);

		tmp_buf=Rast_allocate_buf(rast->raster_type);
		rast->elev = (FCELL**) G_malloc((row_buffer_size+1) * sizeof(FCELL*));
	
	for (row = 0; row < row_buffer_size+1; ++row) {
		rast->elev[row] = Rast_allocate_buf(FCELL_TYPE);
		Rast_get_row(rast->fd, tmp_buf,row, rast->raster_type);
				for (col=0;col<ncols;++col)
			get_cell(col, rast->elev[row], tmp_buf, rast->raster_type);
  } /* end elev */

G_free(tmp_buf);
return 0;
}
Ejemplo n.º 21
0
int set_cell(char *cell_id, char *cell_str, size_t size)
{
    if (cell_str == NULL || cgc_strlen(cell_str) == 0 || cgc_strlen(cell_str) >= size)
        return -1;

    cell_t *cell = get_cell(cell_id);
    if (cell == NULL)
        return -1;

    if (cell->cell_type != UNUSED) {
        free(cell->str);
        cell->str = NULL;
        cell->cell_type = UNUSED;
        cell->formula = NULL;
    }

    cell->str = malloc(cgc_strlen(cell_str) + 1);
    if(cell->str == NULL)
        return -1;

    strcpy(cell->str, cell_str);
    if (cgc_strlen(cell_str) >= 2 && cell_str[0] == '=') {
        cell->formula = &cell->str[1];
        cell->cell_type = FORMULA;
    } else {
        // Non functions can only be a double or a string
        cell->cell_type = parsearg(cell->str);
        if (cell->cell_type != DOUBLE)
            cell->cell_type = STRING;
    }

    return 0;
}
Ejemplo n.º 22
0
char *show_cell(char *cell_id, int is_repr, char* val_str, size_t size)
{
    int is_bad_formula;
    double val = 0.0;
    cell_t *cell = get_cell(cell_id);

    if (cell == NULL)
        return NULL;

    if (cell->cell_type == UNUSED)
        return "";
    if (cell->cell_type == BAD_CELL)
        return "!VALUE";

    if (is_repr)
        return cell->str;

    if (cell->formula != NULL) {
        stack_t *cir_ref = NULL;
        val = eval_formula(cell->formula, &is_bad_formula, &cir_ref, cell->id);
        if (is_bad_formula) {
            return "!FORMULA: CIRREF/STR/DIV0";
        }

        ftoa(val, val_str, size);
        return val_str;
    } else {
        return cell->str;
    }
}
Ejemplo n.º 23
0
 void test_read_cell_formulae()
 {
     xlnt::workbook wb;
     auto ws = wb.get_active_sheet();
     auto path = PathHelper::GetDataDirectory("/reader/worksheet_formula.xml");
     std::ifstream ws_stream(path);
     xlnt::read_worksheet(ws, ws_stream, { "string", "string2" }, {}, {});
     
     auto b1 = ws.get_cell("B1");
     TS_ASSERT(b1.has_formula());
     TS_ASSERT_EQUALS(b1.get_formula(), "CONCATENATE(A1,A2)");
     
     auto a6 = ws.get_cell("A6");
     TS_ASSERT(a6.has_formula());
     TS_ASSERT_EQUALS(a6.get_formula(), "SUM(A4:A5)");
 }
void		put_items(int x, int y,
			t_sdl *sdl, SDL_Rect *pos)
{
  t_map_elt	*map_elt;
  int		cpt;
  int		flag;

  flag = 0;
  map_elt = get_cell(x, y);
  if (map_elt->food != 0)
    flag += 1;
  cpt = 0;
  while (cpt < NB_ROCKS)
    {
      if (map_elt->rocks[cpt] != 0)
	flag += 1;
      cpt++;
    }
  if (flag > 0)
    {
      put_sprite_item(&sdl->game.pos_item, pos, 0);
      sdl_update_item(&sdl->game.rect_item, 0, 0);
      xSDL_BlitSurface(sdl->game.item, &sdl->game.rect_item,
		      sdl->screen, &sdl->game.pos_item);
    }
}
Ejemplo n.º 25
0
    void test_short_number()
    {
		auto ws = wb_.create_sheet();
        ws.get_cell("A1").set_value(1234567890);
        auto content = xlnt::writer::write_worksheet(ws, {}, {});
        TS_ASSERT(Helper::EqualsFileContent(PathHelper::GetDataDirectory() + "/writer/expected/short_number.xml", content));
    }
Ejemplo n.º 26
0
/*!
	Extracts the neighbours of the specified cell for the given face.

	\param id is the id of the cell
	\param face is a face of the cell
	\param blackList is a list of cells that are excluded from the search
	\result The neighbours of the specified cell for the given face.
*/
std::vector<long> Patch::extract_cell_face_neighs(const long &id, const int &face, const std::vector<long> &blackList) const
{
	std::vector<long> neighs;
	const Cell &cell = get_cell(id);
	for (int i = 0; i < cell.get_interface_count(face); ++i) {
		long interfaceId = cell.get_interface(face, i);
		const Interface &interface = get_interface(interfaceId);
		if (interface.is_border()) {
			continue;
		}

		long neighId = interface.get_neigh();
		if (neighId == cell.get_id()) {
			neighId = interface.get_owner();
		}

		if (std::find(blackList.begin(), blackList.end(), neighId) != blackList.end()) {
			continue;
		}

		// Add the cell to the negihbour list
		utils::add_to_ordered_vector<long>(neighId, neighs);
	}

	return neighs;
}
Ejemplo n.º 27
0
pointer mk_string(char *string)
{
        pointer x = get_cell(NULL, NULL);
        type(x) = T_STRING;
        str(x) = string;
        return x;
} 
Ejemplo n.º 28
0
pointer mk_number(int number)
{
        pointer x = get_cell(NULL, NULL);
        type(x) = T_NUMBER;
        num(x) = number;
        return x;
}
Ejemplo n.º 29
0
void FillArrayWithIsosurface(void)
{
	int n, total = 0;
	// Make room for 12 triangles
	triangle *triangles = malloc(12 * sizeof(triangle));
	if(triangles == NULL){
		perror("Triangles array NULL");
		return;
	}
	
	for(int k = 0; k < nz - 1; k++) {
		for(int j = 0; j < ny - 1; j++) {
			for(int i = 0; i < nx - 1; i++) {
				// For each cell generate the triangles
				n = generate_cell_triangles(triangles, get_cell(i, j, k), isovalue);
				
				for(int c = 0; c < n; c++){
					// Add alle the vertices from the triangle
					AddVertexToArray(triangles[c].p[0], triangles[c].n[0]);
					AddVertexToArray(triangles[c].p[1], triangles[c].n[1]);
					AddVertexToArray(triangles[c].p[2], triangles[c].n[2]);
				}
				
				total += n;
			}
		}
	}
	
	printf("Num triangles generated for isosurface: %d\n", total);
	
	free(triangles);
}
/*
** Function TEST: View the map
*/
void		show_map(int x, int y)
{
  int		cpt;
  int		cpt_2;
  t_map_elt	*map_elt;
  
  cpt = 0;
  while (cpt < x)
    {
      cpt_2 = 0;
      while (cpt_2 < y)
        {
	  if (cpt_2 % 10 == 0)
	    my_putchar('\n');
          map_elt = get_cell(cpt, cpt_2);
          my_printf("%d %d %d %d %d %d %d|", map_elt->food,
		    map_elt->rocks[0], map_elt->rocks[1],
		    map_elt->rocks[2], map_elt->rocks[3],
		    map_elt->rocks[4],map_elt->rocks[5]); 
          cpt_2++;
        }
      cpt++;
    }
  my_putchar('\n');
}