Esempio n. 1
0
void fasper(float x[], float y[], unsigned long n, float ofac, float hifac,
	float wk1[], float wk2[], unsigned long nwk, unsigned long *nout,
	unsigned long *jmax, float *prob)
{
	void avevar(float data[], unsigned long n, float *ave, float *var);
	void realft(float data[], unsigned long n, int isign);
	void spread(float y, float yy[], unsigned long n, float x, int m);
	unsigned long j,k,ndim,nfreq,nfreqt;
	float ave,ck,ckk,cterm,cwt,den,df,effm,expy,fac,fndim,hc2wt;
	float hs2wt,hypo,pmax,sterm,swt,var,xdif,xmax,xmin;

	*nout=0.5*ofac*hifac*n;
	nfreqt=ofac*hifac*n*MACC;
	nfreq=64;
	while (nfreq < nfreqt) nfreq <<= 1;
	ndim=nfreq << 1;
	if (ndim > nwk) nrerror("workspaces too small in fasper");
	avevar(y,n,&ave,&var);
	if (var == 0.0) nrerror("zero variance in fasper");
	xmin=x[1];
	xmax=xmin;
	for (j=2;j<=n;j++) {
		if (x[j] < xmin) xmin=x[j];
		if (x[j] > xmax) xmax=x[j];
	}
	xdif=xmax-xmin;
	for (j=1;j<=ndim;j++) wk1[j]=wk2[j]=0.0;
	fac=ndim/(xdif*ofac);
	fndim=ndim;
	for (j=1;j<=n;j++) {
		ck=(x[j]-xmin)*fac;
		MOD(ck,fndim)
		ckk=2.0*(ck++);
		MOD(ckk,fndim)
		++ckk;
		spread(y[j]-ave,wk1,ndim,ck,MACC);
		spread(1.0,wk2,ndim,ckk,MACC);
	}
	realft(wk1,ndim,1);
	realft(wk2,ndim,1);
	df=1.0/(xdif*ofac);
	pmax = -1.0;
	for (k=3,j=1;j<=(*nout);j++,k+=2) {
		hypo=sqrt(wk2[k]*wk2[k]+wk2[k+1]*wk2[k+1]);
		hc2wt=0.5*wk2[k]/hypo;
		hs2wt=0.5*wk2[k+1]/hypo;
		cwt=sqrt(0.5+hc2wt);
		swt=SIGN(sqrt(0.5-hc2wt),hs2wt);
		den=0.5*n+hc2wt*wk2[k]+hs2wt*wk2[k+1];
		cterm=SQR(cwt*wk1[k]+swt*wk1[k+1])/den;
		sterm=SQR(cwt*wk1[k+1]-swt*wk1[k])/(n-den);
		wk1[j]=j*df;
		wk2[j]=(cterm+sterm)/(2.0*var);
		if (wk2[j] > pmax) pmax=wk2[(*jmax=j)];
	}
	expy=exp(-pmax);
	effm=2.0*(*nout)/ofac;
	*prob=effm*expy;
	if (*prob > 0.01) *prob=1.0-pow(1.0-expy,effm);
}
Esempio n. 2
0
int spread(int* matrix, int s_rows, int s_cols, int source_x, int source_y) {
    int x,y,left_x,left_y,right_x,right_y;

    left_x=source_x-1;
    if ( left_x < 0 )
        left_x=source_x;

    left_y=source_y-1;
    if ( left_y < 0 )
        left_y=source_y;

    right_x=source_x+1;
    if (right_x>=s_rows-1)
        right_x=source_x;

    right_y=source_y+1;
    if (right_y>=s_cols-1)
        right_y=source_y;


    display(matrix,s_rows,s_cols);

    /* Vertical & horizontal spreading only */
    x=source_x;
    for (y=left_y;y<=right_y;y++) {
        if ( ( matrix[2*(x+y*s_rows)+1] == 0 ) &&
           ( matrix[2*(x+y*s_rows)] == matrix[2*(source_x+source_y*s_rows)] ) ) {
            matrix[2*(x+y*s_rows)+1] = matrix[2*(source_x+source_y*s_rows)+1];
            spread(matrix,s_rows,s_cols,x,y); 
        }
    }

    y=source_y;
    for (x=left_x-1;x<=right_x;x++) {
        if ( ( matrix[2*(x+y*s_rows)+1] == 0 ) &&
           ( matrix[2*(x+y*s_rows)] == matrix[2*(source_x+source_y*s_rows)] ) ) {
            matrix[2*(x+y*s_rows)+1] = matrix[2*(source_x+source_y*s_rows)+1];
            spread(matrix,s_rows,s_cols,x,y); 
        }
    }

    /* Vertical & horizontal & diagonal spreading */
    /*for (y=left_y;y<=right_y;y++) {
        for (x=left_x-1;x<=right_x;x++) {
            if ( ( matrix[2*(x+y*s_rows)+1] == 0 ) &&
                 ( matrix[2*(x+y*s_rows)] == matrix[2*(source_x+source_y*s_rows)] ) ) {
                matrix[2*(x+y*s_rows)+1] = matrix[2*(source_x+source_y*s_rows)+1];
                spread(matrix,s_rows,s_cols,x,y); 
            }
        }
    }*/

    return 0;
}
Esempio n. 3
0
int  DBG::spread(avl_node_base* node, int w)
{
  if (node == 0) {
    return w;
  }
  w = spread(node->left, w);
  ((data_node*)node)->data.w = w;
  w = spread(node->right, w + MIN_W);

  return w;
}
Esempio n. 4
0
 int spread(int x, int y, vector<vector<char>>& grid)
 {
     if(grid[x][y] == '0') return 0;
     
     grid[x][y] = '0';
     if(x>0) spread(x-1,y,grid);
     if(y>0) spread(x,y-1,grid);
     if(x<xlen-1) spread(x+1,y,grid);
     if(y<ylen-1) spread(x,y+1,grid);
     
     return 1;
 }
Esempio n. 5
0
static void
getLocalThreshold(tuplen **    const inrows,
                  unsigned int const windowWidth,
                  unsigned int const x,
                  unsigned int const localWidth,
                  unsigned int const localHeight,
                  float        const darkness,
                  float        const minSpread,
                  samplen      const defaultThreshold,
                  samplen *    const thresholdP) {
/*----------------------------------------------------------------------------
  Find a suitable threshold in local area around one pixel.

  inrows[][] is a an array of 'windowWidth' pixels by 'localHeight'.

  'x' is a column number within the window.

  We look at the rectangle consisting of the 'localWidth' columns
  surrounding x, all rows.  If x is near the left or right edge, we truncate
  the window as needed.

  We base the threshold on the local spread (difference between minimum
  and maximum sample values in the local areas) and the 'darkness'
  factor.  A higher 'darkness' gets a higher threshold.

  If the spread is less than 'minSpread', we return 'defaultThreshold' and
  'darkness' is irrelevant.

  'localWidth' must be odd.
-----------------------------------------------------------------------------*/
    unsigned int const startCol = x >= localWidth/2 ? x - localWidth/2 : 0;

    unsigned int col;
    struct range localRange;

    assert(localWidth % 2 == 1);  /* entry condition */

    initRange(&localRange);

    for (col = startCol; col <= x + localWidth/2 && col < windowWidth; ++col) {
        unsigned int row;

        for (row = 0; row < localHeight; ++row)
            addToRange(&localRange, inrows[row][col][0]);
    }

    if (spread(localRange) < minSpread)
        *thresholdP = defaultThreshold;
    else
        *thresholdP = localRange.min + darkness * spread(localRange);
}
Esempio n. 6
0
int containVirus(int**grid, int gridSz, int grid0sz){
    n = gridSz;
    m = grid0sz;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            a[i][j] = grid[i][j];
        }
    }
    int ans = 0;
    memset(hasWall, 0, sizeof(hasWall));
    while (1) {
        memset(visit, 0, sizeof(visit));
        int maxCnt = -1;
        int x0 = 0, y0 = 0;
        int visitId = 0;
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                if (!visit[i][j] && a[i][j]) {
                    int cnt = dfs(i, j, ++visitId);
                    if (cnt > maxCnt) {
                        maxCnt = cnt;
                        x0 = i, y0 = j;
                    }
                }
            }
        }
        if (maxCnt <= 0) {
            break;
        }
        ans += addWalls(visit[x0][y0]);
        spread();
    }
    return ans;
}
Esempio n. 7
0
ostream&  DBG::print(ostream& os, data_tree& tree)
{
  if (!tree.root()) {
    return  os << "\n{<empty-tree>}";
  }

  spread(tree.root(), 0);

  for (int i = tree.root()->len; 0 < i; i--) {
    int pos = 0;
    os << '\n';
    for (data_tree::iterator data  = tree.begin();
                             data != tree.end();
                           ++data) {
      if (data.node->len == i) {
        while (pos < (*data).w) {
          os << ' ';
          pos++;
        }
        char  buf[16];
        pos += sprintf(buf, ((*data).ping ? "%d<%d>" : "%d[%d]"),
                             (*data).i, data.node->len);
        os << buf;
      }
    }
  }
  return os;
}
Esempio n. 8
0
int expand(int index, int cluster_id, point_s *points, int num_points, double epsilon, int minpts,  distance dist)
{
	int return_value = NOT_CORE_POINT;
	epsilon_neighbours_s *seeds = get_epsilon_neighbours(index, points, num_points, epsilon, dist);
	if (seeds == NULL) return FAILURE;

	if (seeds->num_members < minpts)
	{
		points[index].cluster_id = NOISE;
	} else
	{
		points[index].cluster_id = cluster_id;
		node_s *h = seeds->head;
		while (h)
		{
			points[h->index].cluster_id = cluster_id;
			h = h->next;
		}

		h = seeds->head;
		while (h)
		{
			spread(h->index, seeds, cluster_id, points, num_points, epsilon, minpts, dist);
			h = h->next;
		}
		return_value = CORE_POINT;
	}
	destroy_epsilon_neighbours(seeds);
	return return_value;
} // expand(..)
Esempio n. 9
0
bool bolt_vs_hero(MagicBolt* bolt, Coord start)
{
    if (save(VS_MAGIC)) {
        msg("the %s whizzes by you", bolt->name().c_str());
        return false;
    }

    if (bolt->is_frost())
    {
        msg("You are frozen by a blast of frost.");
        if (game->hero().get_sleep_turns() < 20)
            game->hero().increase_sleep_turns(spread(7));
    }
    else {
        game->log("battle", "Flame 6d6 damage to player");
        if (!game->hero().decrease_hp(roll(6, 6), true)) {
            if (bolt->from_player)
                death('b');
            else
                death(game->level().monster_at(start)->m_type);
        }
        msg("you are hit by the %s", bolt->name().c_str());
    }

    return true;
}
Esempio n. 10
0
main() {


	int i, j;
	char s[102];
	scanf("%d %d", &row, &col);
	while (row!=0) {

		for (i=1;i<=row;i++) {
			scanf("%s", s);
			for (j=1;j<=col;j++)
				if (s[j-1] == '*') grid[i][j] = -1;
				else grid[i][j] = 0;
			}

      count = 0;
		for (i=1;i<=row;i++)
			for (j=1;j<=col;j++)
				if (grid[i][j] == 0) {
					count++;
					grid[i][j] = count;
					spread(i,j);
				}

		printf("%d\n", count);
		scanf("%d %d", &row, &col);
	}
}
Esempio n. 11
0
static int
mget(Map *map, uint64_t addr, void *buf, int size)
{
	uint64_t off;
	int i, j, k;
	struct segment *s;

	s = reloc(map, addr, (int64_t*)&off);
	if (!s)
		return -1;
	if (s->fd < 0) {
		werrstr("unreadable map");
		return -1;
	}
	for (i = j = 0; i < 2; i++) {	/* in case read crosses page */
		k = spread(s, (void*)((uint8_t *)buf+j), size-j, off+j);
		if (k < 0) {
			werrstr("can't read address %p: %r", addr);
			return -1;
		}
		j += k;
		if (j == size)
			return j;
	}
	werrstr("partial read at address %p (size %d j %d)", addr, size, j);
	return -1;
}
Esempio n. 12
0
int main()
{
	printf("\nTree:%d\nBurning:%d\n\n",TREE, BURNING);
	
	// Seed the random number. Always!!!! 
  	srand(time(NULL));

  	int i,j;
  	int **forest=(int**)calloc(NROWS+2,sizeof(int*));
  	for(i=0;i<NROWS+2;i++)
  		forest[i] = (int*)calloc(NCOLS+2,sizeof(int));
  	double per_forest_burned = 0;
	for(i=0;i<num_experiments;i++)
	{	
		initForest(forest);
		//print_forest(forest);

		for(j=0;j<num_steps;j++)
		{
			fillBoundary(forest);
			spread(forest,forest);
			//print_forest(forest);
		}
		per_forest_burned += per_of_forest_burned(forest); 
	}
	printf("\n%lf\n",(per_forest_burned/num_experiments));
}
Esempio n. 13
0
 void collectable::phantomize_ref(
     unsigned int w, hpx::id_type parent, hpx::id_type cid)
 {
     if (cd == nullptr)
     {
         cd = new collector_data;
         cd->cid = cid;
         cd->parent = parent;
     }
     else if (cid > cd->cid)
     {
         cd->cid = cid;
         cd->parent = parent;
     }
     generate_output("Phantomized ref");
     state();
     if (w < weight)
     {
         strong_count--;
         HPX_ASSERT(strong_count >= 0);
     }
     else
     {
         weak_count--;
         HPX_ASSERT(weak_count >= 0);
     }
     cd->phantom_count++;
     state();
     spread(weight);
     hpx::apply<collectable::done_action>(parent, this->get_id());
 }
Esempio n. 14
0
int main()
{
	std::srand(std::time(0)); //  Para que cada vez que se use el método random tenga una piscina de números randoms diferentes.
	auto BNUD = std::make_unique < NEAT::BasicNeuronUserDefinitions > ( "./BN_userdef" );
	auto BN1 = std::make_shared < NEAT::BasicNeuron > ( *BNUD );
	auto L1 = std::make_unique < NEAT::Layer> ( BN1 , 0 );

	BN1->printInfo();
	std::cout << "=======" << std::endl;

	for (uint i = 0; i < 5; ++i)
	{
		L1->addNewNeuron();
	}

	L1->printInfo();

	for (uint i = 0; i < L1->neurons.size(); ++i)
	{
		L1->neurons.at(i)->sumIncomingVoltage( rand()/(double)RAND_MAX );
	}

	L1->spread();
	L1->printInfo();


	return 0;

}
Esempio n. 15
0
static void
thresholdLocalRow(struct pam *       const inpamP,
                  tuplen **          const inrows,
                  unsigned int       const localWidth,
                  unsigned int       const windowHeight,
                  unsigned int       const row,
                  struct cmdlineInfo const cmdline,
                  struct range       const globalRange,
                  samplen            const globalThreshold,
                  struct pam *       const outpamP,
                  tuple *            const outrow) {

    tuplen * const inrow = inrows[row % windowHeight];

    float minSpread;
    unsigned int col;

    if (cmdline.dual)
        minSpread = cmdline.contrast * spread(globalRange);
    else
        minSpread = 0.0;

    for (col = 0; col < inpamP->width; ++col) {
        samplen threshold;

        getLocalThreshold(inrows, inpamP->width, col, localWidth, windowHeight,
                          cmdline.threshold, minSpread, globalThreshold,
                          &threshold);
        
        thresholdPixel(outpamP, inrow[col], outrow[col], threshold);
    }
}
Esempio n. 16
0
bool KoStopGradient::save()
{
    QFile fileOut(filename());
    if (! fileOut.open(QIODevice::WriteOnly))
        return false;

    QTextStream stream(&fileOut);

    const QString spreadMethod[3] = {
        QString("spreadMethod=\"pad\" "),
        QString("spreadMethod=\"reflect\" "),
        QString("spreadMethod=\"repeat\" ")
    };

    const QString indent = "    ";

    stream << "<svg>" << endl;

    stream << indent;
    stream << "<linearGradient id=\"" << name() << "\" ";
    stream << "gradientUnits=\"objectBoundingBox\" ";
    stream << spreadMethod[spread()];
    stream << ">" << endl;

    QColor color;

    // color stops
    foreach(const KoGradientStop & stop, m_stops) {
        stop.second.toQColor(&color);
        stream << indent << indent;
        stream << "<stop stop-color=\"";
        stream << color.name();
        stream << "\" offset=\"" << QString().setNum(stop.first);
        stream << "\" stop-opacity=\"" << static_cast<float>(color.alpha()) / 255.0f << "\"" << " />" << endl;
    }
Esempio n. 17
0
spread(int r, int c) {
	int i;
	for (i=0;i<=7;i++)
		if ((r+dirrow[i]>=1) && (r+dirrow[i]<=row) && (c+dircol[i]>=1) && (c+dircol[i]<=col))
			if (grid[r+dirrow[i]][c+dircol[i]] == 0) {
				grid[r+dirrow[i]][c+dircol[i]] = count;
				spread(r+dirrow[i], c+dircol[i]);
			}
}
ShadowData ShadowData::blend(const ShadowData& from, double progress, const Color& currentColor) const
{
    ASSERT(style() == from.style());
    return ShadowData(blink::blend(from.location(), location(), progress),
        clampTo(blink::blend(from.blur(), blur(), progress), 0.0f),
        blink::blend(from.spread(), spread(), progress),
        style(),
        blink::blend(from.color().resolve(currentColor), color().resolve(currentColor), progress));
}
Esempio n. 19
0
ShadowData ShadowData::blend(const ShadowData& from, double progress) const
{
    if (style() != from.style())
        return *this;

    return ShadowData(WebCore::blend(from.location(), location(), progress),
        clampTo<int>(WebCore::blend(from.blur(), blur(), progress), 0),
        WebCore::blend(from.spread(), spread(), progress),
        style(),
        WebCore::blend(from.color(), color(), progress));
}
void runEmitter()
{
    vec3f vel = vec3f(0, emitterVel, 0);
    vec3f vx(1, 0, 0);
    vec3f vy(0, 0, 1);
	vec3f spread(emitterSpread, 0.0f, emitterSpread);

    psystem->sphereEmitter(emitterIndex, cursorPosLag, vel, spread, emitterRadius, (int) emitterRate*timestep, particleLifetime, particleLifetime*0.1);

    if (emitterIndex > numParticles-1)
        emitterIndex = 0;
}
Esempio n. 21
0
int maxSpread(int** matrix, int size, int dim){
	int max = -1;
	int maxIndex = -1;
	int dimSpread;
	for(int i=0;i<dim;i++){
		dimSpread = spread(matrix[i],size);
		if(dimSpread > max){
			max = dimSpread;
			maxIndex = i;
		}
	}
	return maxIndex;
}
Esempio n. 22
0
void spread(costmap_2d::Costmap2D &gradient_, costmap_2d::Costmap2D &original_, int value, int i, int j, int startCellI, int startCellJ)
{

	gradient_.setCost(i, j, value);

	//ROS_INFO("(%d, %d) <- %d", i, j, value);

	value = value + 5;
	if(value>254)
		value=254;

	if(go(gradient_, original_, i-1,j, value))
		spread(gradient_, original_, value, i-1, j, startCellI, startCellJ);
	if(go(gradient_, original_, i,j-1, value))
		spread(gradient_, original_, value, i, j-1, startCellI, startCellJ);
	if(go(gradient_, original_, i+1,j, value))
		spread(gradient_, original_, value, i+1, j, startCellI, startCellJ);
	if(go(gradient_, original_, i,j+1, value))
		spread(gradient_, original_, value, i, j+1, startCellI, startCellJ);


}
Esempio n. 23
0
void partInc(int *result, int size)
{
    int remainder;
    int prev;
    int length = 0;
    spread(result, size, 0, &length);
    printResult(result, length);
    while(length!=1)
    {
	length--;
	prev = ++(result[length - 1]);
	remainder = result[length] - 1;
	if(remainder > prev)
	{
	    spread(result+length, remainder, prev, &length);
	}
	else
	{
	    (result[length - 1]) += remainder;
	}
    	printResult(result, length);
    }
}
Esempio n. 24
0
 int numIslands(vector<vector<char>>& grid) {
     xlen = grid.size();
     
     if(xlen == 0) return 0;
     
     ylen = grid[0].size();
     
     int cnt = 0;
     for(int x = 0; x < xlen; x++)
         for(int y = 0; y < ylen; y++)
             cnt += spread(x,y,grid);
     
     return cnt;
 }
Esempio n. 25
0
bool CSUROGlobalPlanner::makePlan(const geometry_msgs::PoseStamped& start, const geometry_msgs::PoseStamped& goal,  std::vector<geometry_msgs::PoseStamped>& plan )
{

	ROS_INFO("CSURO Global Planner making plan");

	float startX = start.pose.position.x;
	float startY = start.pose.position.y;
	float goalX = goal.pose.position.x;
	float goalY = goal.pose.position.y;

	ROS_INFO("New Goal coordinate (%lf, %lf) in %s", goalX, goalY, goal.header.frame_id.c_str());
	ROS_INFO("Coords vals in ([%lf, %lf], [%lf, %lf])",
			original_costmap_.getOriginX(), original_costmap_.getOriginY(),
			original_costmap_.getOriginX() + original_costmap_.getSizeInMetersX(),
			original_costmap_.getOriginY() + original_costmap_.getSizeInMetersY());

	if(!isCoordInMap(original_costmap_, goalX, goalY))
	{
		ROS_ERROR("Coordinate (%lf, %lf) is outside of the map", goalX, goalY);
		return false;
	}

	int startCellI, startCellJ;
	int goalCellI, goalCellJ;


	original_costmap_.worldToMapEnforceBounds(goalX, goalY, goalCellI, goalCellJ);
	original_costmap_.worldToMapEnforceBounds(startX, startY, startCellI, startCellJ);

	//Compute gradient
	ROS_INFO("SET (%d, %d) [%d]", goalCellI, goalCellJ, static_cast<int>(gradient_.getCost(goalCellI, goalCellJ)));
	//ROS_INFO("SIZEMAP = [%d x %d]", gradient_.getSizeInCellsX(), gradient_.getSizeInCellsY());
	gradient_ = original_costmap_;
	upTo(gradient_);
	spread(gradient_, original_costmap_, 0, goalCellI, goalCellJ, startCellI, startCellJ);
	gradient_pub_.publishCostmap();
	fillPlan(gradient_, plan, start, goal, startCellI, startCellJ, goalCellI, goalCellJ);

	ROS_INFO("Plan ========================");
	std::vector<geometry_msgs::PoseStamped>::iterator it;
	for(it=plan.begin(); it<plan.end(); ++it)
	{
		ROS_INFO("%lf %lf", it->pose.position.x, it->pose.position.y);
	}
	ROS_INFO("=============================");

	ROS_INFO("CSURO Global Plann done");

	return true;
}
Esempio n. 26
0
void partitionDecreasing(int size)
{
    int remainder, prev;
    int length = 0;
    int *result = malloc(sizeof(int) * (size / 2 + 2));
    spread(result, size, 0, &length);
    printResultBack(result, length);
    while(length != 1)
    {
	length--;
	prev = ++(result[length - 1]);
        remainder = result[length] - 1;
        if(remainder > prev)
        {
            spread(result+length, remainder, prev, &length);
        }
        else
        {
            (result[length - 1]) += remainder;
        }
        printResultBack(result, length);
    }
    free(result);
}
Esempio n. 27
0
void
LauncherApplication::activate()
{
    if (urgent()) {
        show();
    } else if (active()) {
        if (windowCountOnCurrentWorkspace() > 0 && windowCount() > 1) {
            spread(windowCount() > windowCountOnCurrentWorkspace());
        }
    } else if (running() && has_visible_window()) {
        show();
    } else {
        launch();
    }
}
Esempio n. 28
0
int main(int c, char *v[])
{
	if (c != 1 && c != 2) {
		fprintf(stderr, "usage:\n\t%s [img]\n", *v);
		//                          0  1
		return 1;
	}
	char *in_img = c > 1 ? v[1] : "-";
	int w, h;
	float *x = iio_read_image_float(in_img, &w, &h);
	float s = spread(x, w, h);
	printf("%.25lf\n", s);
	free(x);
	return 0;
}
Esempio n. 29
0
void KMCentersTree::split_by_mid_point(
  int start_ind, int end_ind, int &cut_dim, double &cut_val, int &n_lo) {
  KMPoint *lo,*hi;
  lo = bnd_box_->get_point(0);
  hi = bnd_box_->get_point(1);
  // find the long side with the largest spread (the cutting dimension)
  double max_length = bnd_box_->max_length();
  double max_spread = -1;
  for (int d = 0; d < data_points_->get_dim(); d++) {
    if (std::abs((*hi)[d] - (*lo)[d]-max_length) <1E-6){
      double spr = spread(start_ind,end_ind,d);
      if (spr > max_spread) {
        max_spread = spr;
        cut_dim = d;
      }
    }
  }
  // find the splitting value
  double ideal_cut_val = ((*lo)[cut_dim] + (*hi)[cut_dim])/2;
  //min_max represent the minimal and maximal
  //values of points along the cutting dimension
  std::pair<double,double> min_max =
    limits_along_dimension(start_ind,end_ind, cut_dim);
  //slide to min or max as needed
  if (ideal_cut_val < min_max.first)
    cut_val = min_max.first;
  else if (ideal_cut_val > min_max.second)
    cut_val = min_max.second;
  else
    cut_val = ideal_cut_val;
  // permute points accordingly
  std::pair<int,int>
    break_ind = split_by_plane(start_ind,end_ind,cut_dim, cut_val);
  IMP_LOG(VERBOSE, "split by mid point for indexes: "
          << start_ind << " to " << end_ind << "break index: "
          << break_ind.first << " to " << break_ind.second << std::endl);
  //set n_lo such that each side of the split will contain at least one point
  n_lo = (start_ind+end_ind)/2;
  // if ideal_cut_val < min (y >= 1), we set n_lo = 1 (so there is one
  // point on left)
  if (ideal_cut_val < min_max.first) n_lo = start_ind+1;
  // if ideal_cut_val > max (x <= n-1), we set n_lo = n-1 (so there is one
  // point on right).
  else if (ideal_cut_val > min_max.second) n_lo = end_ind;
  // Otherwise, we select n_lo as close to the middle of  [x..y] as possbile
  else if (break_ind.first > n_lo) n_lo = break_ind.first;
  else if (break_ind.second < n_lo) n_lo = break_ind.second;
}
Esempio n. 30
0
void generateMatrix(int ***forest, int rows, int cols, int iterations, int simulations, float pTree, float pBurning, float pGrow, float pImmune, float pLightning, int spread_type, int neighbourhood_type, int boundary_type){
		
    int i,j,k,l,count;
    FILE* fptr;
    fptr=fopen("bell_please.tr","w");
    if(fptr==NULL){
      printf("Error! File not opened\n");
    }	
    for(i = 0; i<simulations; i++)
      {
	printf("%d\n", i);
	initForest(forest[0], rows, cols, pTree, pBurning);
	count = 0;
	/*		for(k = 1; k<=rows; k++)
			{
			for(l = 1; l<=cols; l++)
			{
			if((forest[0][k][l]/10<=2) && (forest[0][k][l]!=EMPTY_BURNING))
			{
			count++;
			}							
			}
			}
			fprintf(fptr,"%Lf ",(long double)(count/(rows*cols)));
	*/
	for(j = 1; j<iterations; j++)
	  {
	    fillBoundary(forest[j-1],rows, cols, boundary_type);
	    spread(forest[j-1],forest[j],rows, cols, pImmune, pLightning, pGrow, spread_type, neighbourhood_type);
	    count = 0;
	    for(k = 1; k<=rows; k++)
	      {
		for(l = 1; l<=cols; l++)
		  {
		    if((forest[j][k][l]/10==2) && (forest[j][k][l]!=EMPTY_BURNING))
		      {
			count++;
		      }							
		  }
	      }
	    fprintf(fptr,"%f ",((float)count/(rows*cols)));
	  }
	fprintf(fptr, "\n");
      }
		
    fclose(fptr);
  }