Ejemplo n.º 1
0
/*
        This is what moves our fireflies towards the most attractive flies.
*/
static void
move_fflies(ffly_population *pop, const ffly_population *pop_old, obj_func f,
            double alpha, const double gamma, const double mins[], const double maxs[])
{
    size_t i = 0, j = 0, k = 0;
    int moved = 0;
    const size_t nflies = pop->nfflies;
    const size_t nparams = pop->nparams;

    for (i=0; i < nflies; i++)
    {   	    
        for (j = 0; j < nflies; j++)
        {
            moved |= move_fly(&pop->flies[i], &pop_old->flies[j], nparams, alpha, gamma, mins, maxs);
        }

        /* we never moved, so move a lil bit randomly*/
        if (!moved)
        {
            double val = 0.0;
            for (k = 0; k < nparams; k++)
            {
                val = pop->flies[i].params[k] + (alpha * (drand48() - 0.5));
                pop->flies[i].params[k] = (val < mins[k]) ? mins[k] : (val > maxs[k]) ? maxs[k] : val;
            }
        }
        moved = 0;
        //re-evaluate our current brightness
        pop->flies[i].val = (*f)(&pop->flies[i], nparams);
    }
};
Ejemplo n.º 2
0
void
draw_eyes(ModeInfo * mi)
{
	int         i;
	EyeScrInfo *ep;

	if (eye_info == NULL)
		return;
	ep = &eye_info[MI_SCREEN(mi)];
	if (ep->flypix == None)
		return;

	MI_IS_DRAWN(mi) = True;

	move_fly(mi, &(ep->fly));
	ep->time++;
	for (i = 0; i < ep->num_eyes; i++) {
		paint_eyes(mi, &(ep->eyes[i]), &(ep->fly), ep->eyes, ep->num_eyes);
	}

	paint_fly(mi, &(ep->fly));
}