Exemple #1
0
/* of interpreted points to generate.				   */
static int
s_spline(Poly *poly, Vector dotout, Vector vecout, int closed, int ir,
		Poly *filledp)
{
fpoint *newx, *newy;
int ptcount;
LLpoint *p;
int i;

ptcount = poly->pt_count;
if ((newx = begmem(ptcount*sizeof(fpoint) )) == NULL)
	return(0);
if ((newy = begmem(ptcount*sizeof(fpoint) )) == NULL)
	{
	freemem(newx);
	return(0);
	}
p = poly->clipped_list;
for (i=0; i<ptcount; i++)
	{
	newx[i] = FVAL(p->x);
	newy[i] = FVAL(p->y);
	p = p->next;
	}
if (alloc_spline_tab(ptcount))
	{
	do_spline(newx,newy,ptcount,ir,closed,
		dotout,vecout, filledp);
	free_spline_tab();
	}
freemem(newx);
freemem(newy);
return(1);
}
Exemple #2
0
void my_float_listener (PluginParam *param) {
  GtkProgressBar *progress;

  if (sdlGoom->config_win == 0) return;
  progress = GTK_PROGRESS_BAR(param->user_data);

  if (progress) {
    if (FVAL(*param)<FMIN(*param))
      FVAL(*param) = FMIN(*param);
    if (FVAL(*param)>FMAX(*param))
      FVAL(*param) = FMAX(*param);
    gtk_progress_bar_update (progress, FVAL(*param));
  }
}
Exemple #3
0
/**
 * Main methode of the FX.
 */
static void fs_apply(VisualFX *_this, Pixel *src, Pixel *dest, PluginInfo *info) {

	int i;
	int col;
	FSData *data = (FSData*)_this->fx_data;

	/* Get the new parameters values */
	data->min_age = 1.0f - (float)IVAL(data->min_age_p)/100.0f;
	data->max_age = 1.0f - (float)IVAL(data->max_age_p)/100.0f;
	FVAL(data->nbStars_p) = (float)data->nbStars / (float)data->maxStars;
	data->nbStars_p.change_listener(&data->nbStars_p);
	data->maxStars = IVAL(data->nbStars_limit_p);
	data->fx_mode = IVAL(data->fx_mode_p);

	/* look for events */
	if (info->sound.timeSinceLastGoom < 1) {
		fs_sound_event_occured(_this, info);
		if (goom_irand(info->gRandom,20)==1) {
			IVAL(data->fx_mode_p) = goom_irand(info->gRandom,(LAST_FX*3));
			data->fx_mode_p.change_listener(&data->fx_mode_p);
		}
	}

	/* update particules */
	for (i=0;i<data->nbStars;++i) {
		updateStar(&data->stars[i]);

		/* dead particule */
		if (data->stars[i].age>=NCOL)
			continue;

		/* choose the color of the particule */
		col = colval[(int)data->stars[i].age];

		/* draws the particule */
		info->methods.draw_line(dest,(int)data->stars[i].x,(int)data->stars[i].y,
				(int)(data->stars[i].x-data->stars[i].vx*6),
				(int)(data->stars[i].y-data->stars[i].vy*6),
				col,
				(int)info->screen.width, (int)info->screen.height);
		info->methods.draw_line(dest,(int)data->stars[i].x,(int)data->stars[i].y,
				(int)(data->stars[i].x-data->stars[i].vx*2),
				(int)(data->stars[i].y-data->stars[i].vy*2),
				col,
				(int)info->screen.width, (int)info->screen.height);
	}

	/* look for dead particules */
	for (i=0;i<data->nbStars;) {

		if ((data->stars[i].x > info->screen.width + 64)
				||((data->stars[i].vy>=0)&&(data->stars[i].y - 16*data->stars[i].vy > info->screen.height))
				||(data->stars[i].x < -64)
				||(data->stars[i].age>=NCOL)) {
			data->stars[i] = data->stars[data->nbStars-1];
			data->nbStars--;
		}
		else ++i;
	}
}
Exemple #4
0
Fichier : lisp.c Projet : qyqx/wisp
object_t *eql (object_t * lst)
{
  DOC ("Return t if both arguments are similar.");
  REQ (lst, 2, c_sym ("eql"));
  object_t *a = CAR (lst);
  object_t *b = CAR (CDR (lst));
  if (a->type != b->type)
    return NIL;
  switch (a->type)
    {
    case INT:
    case FLOAT:
      return num_eq (lst);
      break;
    case SYMBOL:
    case CONS:
      if (a == b)
	return T;
      break;
    case STRING:
      if (OSTRLEN (a) == OSTRLEN (b))
	if (memcmp (OSTR (a), OSTR (b), OSTRLEN (a)) == 0)
	  return T;
      break;
    case VECTOR:
      return NIL;
      break;
    case DETACH:
      if (a == b)
	return T;
      break;
    case CFUNC:
    case SPECIAL:
      if (FVAL (a) == FVAL (b))
	return T;
      break;
    }
  return NIL;
}
 static void output()
 {
     // nRF51 refman 13.1 p.56: "Pin direction can be configured both in
     // the DIR register as well as through the individual PIN_CNF[n]
     // registers. A change in one register will automatically be
     // reflected in the other register.
     port::ptr()->DIRSET = bit::value;
     // nRF51 refman 13.1 p.55: "The input buffer of a GPIO pin can be
     // disconnected from the pin to enable power savings when the pin is
     // not used as an input. Inputs must be connected in order to get a
     // valid input value in the IN register and for the sense mechanism
     // to get access to the pin.
     SET_BITFIELD(port::ptr()->PIN_CNF[bit::shift], FVAL(GPIO_PIN_CNF_INPUT, DISCONNECT));
 }
Exemple #6
0
char *va_to_string(Value value)
{
    switch (value.type) {
        case VAL_TYPE_STR:
            return strdup(SVAL(value));
        case VAL_TYPE_BOOL:
            return strdup(IVAL(value) ? "true" : "false");
        case VAL_TYPE_INT:
            {
                char *num_str = malloc(VALUE_STR_CONVERT_SIZE);

                if (num_str == NULL) {
                    return NULL;
                }

                snprintf(num_str, VALUE_STR_CONVERT_SIZE, "%ld", IVAL(value));

                return num_str;
            }
        case VAL_TYPE_FLOAT:
            {
                char *num_str = malloc(VALUE_STR_CONVERT_SIZE);

                if (num_str == NULL) {
                    return NULL;
                }

                snprintf(num_str, VALUE_STR_CONVERT_SIZE, "%f", FVAL(value));

                return num_str;
            }
        case VAL_TYPE_REGEX:
            return strdup(RVAL(value).regex_pattern);
        case VAL_TYPE_SHELL_COMMAND:
            return strdup(CVAL(value));
        default:
            assert(!"Invalid value type");
            break;
    }

    return NULL;
}
Exemple #7
0
Fichier : lisp.c Projet : qyqx/wisp
object_t *cdoc_string (object_t * lst)
{
  DOC ("Return doc-string for CFUNC or SPECIAL.");
  REQ (lst, 1, c_sym ("cdoc-string"));
  object_t *fo = CAR (lst);
  int evaled = 0;
  if (SYMBOLP (fo))
    {
      evaled = 1;
      fo = eval (fo);
    }
  if (fo->type != CFUNC && fo->type != SPECIAL)
    {
      if (evaled)
	obj_destroy (fo);
      THROW (wrong_type, UPREF (fo));
    }
  cfunc_t f = FVAL (fo);
  object_t *str = f (doc_string);
  if (evaled)
    obj_destroy (fo);
  return str;
}
void evaluate_sound(gint16 data[2][512], SoundInfo *info) {

	int i;
	float difaccel;
	float prevspeed;

	/* find the max */
	int incvar = 0;
	for (i = 0; i < 512; i+=2) {
		if (incvar < data[0][i])
			incvar = data[0][i];
	}

	if (incvar > info->allTimesMax)
		info->allTimesMax = incvar;

	/* volume sonore */
	info->volume = (float)incvar / (float)info->allTimesMax;
	visual_mem_copy(info->samples[0], data[0], 512 * sizeof(short));
	visual_mem_copy(info->samples[1], data[1], 512 * sizeof(short));

	difaccel = info->accelvar;
	info->accelvar = info->volume; /* accel entre 0 et 1 */

	/* transformations sur la vitesse du son */
	if (info->speedvar > 1.0f)
		info->speedvar = 1.0f;

	if (info->speedvar < 0.1f)
		info->accelvar *= (1.0f - (float)info->speedvar);
	else if (info->speedvar < 0.3f)
		info->accelvar *= (0.9f - (float)(info->speedvar-0.1f)/2.0f);
	else
		info->accelvar *= (0.8f - (float)(info->speedvar-0.3f)/4.0f);

	/* adoucissement de l'acceleration */
	info->accelvar *= ACCEL_MULT;
	if (info->accelvar < 0)
		info->accelvar = 0;

	difaccel = info->accelvar - difaccel;
	if (difaccel < 0)
		difaccel = - difaccel;

	/* mise a jour de la vitesse */
  prevspeed = info->speedvar;
	info->speedvar = (info->speedvar + difaccel * 0.5f) / 2;
	info->speedvar *= SPEED_MULT;
  info->speedvar = (info->speedvar + 3.0f * prevspeed) / 4.0f;
	if (info->speedvar < 0)
		info->speedvar = 0;
	if (info->speedvar > 1)
		info->speedvar = 1;

	/* temps du goom */
	info->timeSinceLastGoom++;
	info->timeSinceLastBigGoom++;
	info->cycle++;

	/* detection des nouveaux gooms */
	if ((info->speedvar > (float)IVAL(info->biggoom_speed_limit_p)/100.0f)
			&& (info->accelvar > info->bigGoomLimit)
			&& (info->timeSinceLastBigGoom > BIG_GOOM_DURATION)) {
		info->timeSinceLastBigGoom = 0;
	}

	if (info->accelvar > info->goom_limit) {
		/* TODO: tester && (info->timeSinceLastGoom > 20)) { */
		info->totalgoom ++;
		info->timeSinceLastGoom = 0;
		info->goomPower = info->accelvar - info->goom_limit;    
	}

	if (info->accelvar > info->prov_max)
		info->prov_max = info->accelvar;

	if (info->goom_limit>1)
		info->goom_limit=1;

	/* toute les 2 secondes : vérifier si le taux de goom est correct
	 * et le modifier sinon.. */
	if (info->cycle % 64 == 0) {
		if (info->speedvar<0.01f)
			info->goom_limit *= 0.91;
		if (info->totalgoom > 4) {
			info->goom_limit+=0.02;
		}
		if (info->totalgoom > 7) {
			info->goom_limit*=1.03f;
			info->goom_limit+=0.03;
		}
		if (info->totalgoom > 16) {
			info->goom_limit*=1.05f;
			info->goom_limit+=0.04;
		}
		if (info->totalgoom == 0) {
			info->goom_limit = info->prov_max - 0.02;
		}
		if ((info->totalgoom == 1) && (info->goom_limit > 0.02))
			info->goom_limit-=0.01;
		info->totalgoom = 0;
		info->bigGoomLimit = info->goom_limit * (1.0f + (float)IVAL(info->biggoom_factor_p)/500.0f);
		info->prov_max = 0;
	}

	/* mise a jour des parametres pour la GUI */
	FVAL(info->volume_p) = info->volume;
	info->volume_p.change_listener(&info->volume_p);
	FVAL(info->speed_p) = info->speedvar * 4;
	info->speed_p.change_listener(&info->speed_p);
	FVAL(info->accel_p) = info->accelvar;
	info->accel_p.change_listener(&info->accel_p);

	FVAL(info->goom_limit_p) = info->goom_limit;
	info->goom_limit_p.change_listener(&info->goom_limit_p);
        FVAL(info->goom_power_p) = info->goomPower;
        info->goom_power_p.change_listener(&info->goom_power_p);
	FVAL(info->last_goom_p) = 1.0-((float)info->timeSinceLastGoom/20.0f);
	info->last_goom_p.change_listener(&info->last_goom_p);
	FVAL(info->last_biggoom_p) = 1.0-((float)info->timeSinceLastBigGoom/40.0f);
	info->last_biggoom_p.change_listener(&info->last_biggoom_p);

	/* bigGoomLimit ==goomLimit*9/8+7 ? */
	}
void
MAST::GCMMAOptimizationInterface::optimize() {
#if MAST_ENABLE_GCMMA == 1

    // make sure that all processes have the same problem setup
    _feval->sanitize_parallel();
    
    int
    N                  = _feval->n_vars(),
    M                  = _feval->n_eq() + _feval->n_ineq(),
    n_rel_change_iters = _feval->n_iters_relative_change();
    
    libmesh_assert_greater(N, 0);
    
    std::vector<Real>  XVAL(N, 0.), XOLD1(N, 0.), XOLD2(N, 0.),
    XMMA(N, 0.), XMIN(N, 0.), XMAX(N, 0.), XLOW(N, 0.), XUPP(N, 0.),
    ALFA(N, 0.), BETA(N, 0.), DF0DX(N, 0.),
    A(M, 0.), B(M, 0.), C(M, 0.), Y(M, 0.), RAA(M, 0.), ULAM(M, 0.),
    FVAL(M, 0.), FAPP(M, 0.), FNEW(M, 0.), FMAX(M, 0.),
    DFDX(M*N, 0.), P(M*N, 0.), Q(M*N, 0.), P0(N, 0.), Q0(N, 0.),
    UU(M, 0.), GRADF(M, 0.), DSRCH(M, 0.), HESSF(M*(M+1)/2, 0.),
    f0_iters(n_rel_change_iters);
    
    std::vector<int> IYFREE(M, 0);
    std::vector<bool> eval_grads(M, false);
    
    Real
    ALBEFA  = 0.1,
    GHINIT  = 0.5,
    GHDECR  = 0.7,
    GHINCR  = 1.2,
    F0VAL   = 0.,
    F0NEW   = 0.,
    F0APP   = 0.,
    RAA0    = 0.,
    Z       = 0.,
    GEPS    =_feval->tolerance();
    
    
    /*C********+*********+*********+*********+*********+*********+*********+
     C
     C  The meaning of some of the scalars and vectors in the program:
     C
     C     N  = Complex of variables x_j in the problem.
     C     M  = Complex of constraints in the problem (not including
     C          the simple upper and lower bounds on the variables).
     C ALBEFA = Relative spacing between asymptote and mode limit. Lower value
     C          will cause the move limit (alpha,beta) to move closer to asymptote
     C          values (l, u).
     C GHINIT = Initial asymptote setting. For the first two iterations the
     C          asymptotes (l, u) are defined based on offsets from the design
     C          point as this fraction of the design variable bounds, ie.
     C              l_j   =   x_j^k  - GHINIT * (x_j^max - x_j^min)
     C              u_j   =   x_j^k  + GHINIT * (x_j^max - x_j^min)
     C GHDECR = Fraction by which the asymptote is reduced for oscillating
     C          changes in design variables based on three consecutive iterations
     C GHINCR = Fraction by which the asymptote is increased for non-oscillating
     C          changes in design variables based on three consecutive iterations
     C INNMAX = Maximal number of inner iterations within each outer iter.
     C          A reasonable choice is INNMAX=10.
     C  ITER  = Current outer iteration number ( =1 the first iteration).
     C  GEPS  = Tolerance parameter for the constraints.
     C          (Used in the termination criteria for the subproblem.)
     C
     C   XVAL(j) = Current value of the variable x_j.
     C  XOLD1(j) = Value of the variable x_j one iteration ago.
     C  XOLD2(j) = Value of the variable x_j two iterations ago.
     C   XMMA(j) = Optimal value of x_j in the MMA subproblem.
     C   XMIN(j) = Original lower bound for the variable x_j.
     C   XMAX(j) = Original upper bound for the variable x_j.
     C   XLOW(j) = Value of the lower asymptot l_j.
     C   XUPP(j) = Value of the upper asymptot u_j.
     C   ALFA(j) = Lower bound for x_j in the MMA subproblem.
     C   BETA(j) = Upper bound for x_j in the MMA subproblem.
     C    F0VAL  = Value of the objective function f_0(x)
     C   FVAL(i) = Value of the i:th constraint function f_i(x).
     C  DF0DX(j) = Derivative of f_0(x) with respect to x_j.
     C   FMAX(i) = Right hand side of the i:th constraint.
     C   DFDX(k) = Derivative of f_i(x) with respect to x_j,
     C             where k = (j-1)*M + i.
     C      P(k) = Coefficient p_ij in the MMA subproblem, where
     C             k = (j-1)*M + i.
     C      Q(k) = Coefficient q_ij in the MMA subproblem, where
     C             k = (j-1)*M + i.
     C     P0(j) = Coefficient p_0j in the MMA subproblem.
     C     Q0(j) = Coefficient q_0j in the MMA subproblem.
     C      B(i) = Right hand side b_i in the MMA subproblem.
     C    F0APP  = Value of the approximating objective function
     C             at the optimal soultion of the MMA subproblem.
     C   FAPP(i) = Value of the approximating i:th constraint function
     C             at the optimal soultion of the MMA subproblem.
     C    RAA0   = Parameter raa_0 in the MMA subproblem.
     C    RAA(i) = Parameter raa_i in the MMA subproblem.
     C      Y(i) = Value of the "artificial" variable y_i.
     C      Z    = Value of the "minimax" variable z.
     C      A(i) = Coefficient a_i for the variable z.
     C      C(i) = Coefficient c_i for the variable y_i.
     C   ULAM(i) = Value of the dual variable lambda_i.
     C  GRADF(i) = Gradient component of the dual objective function.
     C  DSRCH(i) = Search direction component in the dual subproblem.
     C  HESSF(k) = Hessian matrix component of the dual function.
     C IYFREE(i) = 0 for dual variables which are fixed to zero in
     C               the current subspace of the dual subproblem,
     C           = 1 for dual variables which are "free" in
     C               the current subspace of the dual subproblem.
     C
     C********+*********+*********+*********+*********+*********+*********+*/
    
    
    /*
     *  The USER should now give values to the parameters
     *  M, N, GEPS, XVAL (starting point),
     *  XMIN, XMAX, FMAX, A and C.
     */
    // _initi(M,N,GEPS,XVAL,XMIN,XMAX,FMAX,A,C);
    // Assumed:  FMAX == A
    _feval->_init_dvar_wrapper(XVAL, XMIN, XMAX);
    // set the value of C[i] to be very large numbers
    Real max_x = 0.;
    for (unsigned int i=0; i<N; i++)
        if (max_x < fabs(XVAL[i]))
            max_x = fabs(XVAL[i]);
    std::fill(C.begin(), C.end(), std::max(1.e0*max_x, _constr_penalty));
    
    int INNMAX=_max_inner_iters, ITER=0, ITE=0, INNER=0, ICONSE=0;
    /*
     *  The outer iterative process starts.
     */
    bool terminate = false, inner_terminate=false;
    while (!terminate) {
        
        ITER=ITER+1;
        ITE=ITE+1;
        /*
         *  The USER should now calculate function values and gradients
         *  at XVAL. The result should be put in F0VAL,DF0DX,FVAL,DFDX.
         */
        std::fill(eval_grads.begin(), eval_grads.end(), true);
        _feval->_evaluate_wrapper(XVAL,
                                  F0VAL, true, DF0DX,
                                  FVAL, eval_grads, DFDX);
        if (ITER == 1)
            // output the very first iteration
            _feval->_output_wrapper(0, XVAL, F0VAL, FVAL, true);
        
        /*
         *  RAA0,RAA,XLOW,XUPP,ALFA and BETA are calculated.
         */
        raasta_(&M, &N, &RAA0, &RAA[0], &XMIN[0], &XMAX[0], &DF0DX[0], &DFDX[0]);
        asympg_(&ITER, &M, &N, &ALBEFA, &GHINIT, &GHDECR, &GHINCR,
                &XVAL[0], &XMIN[0], &XMAX[0], &XOLD1[0], &XOLD2[0],
                &XLOW[0], &XUPP[0], &ALFA[0], &BETA[0]);
        /*
         *  The inner iterative process starts.
         */
        
        // write the asymptote data for the inneriterations
        _output_iteration_data(ITER, XVAL, XMIN, XMAX, XLOW, XUPP, ALFA, BETA);

        INNER=0;
        inner_terminate = false;
        while (!inner_terminate) {
            
            /*
             *  The subproblem is generated and solved.
             */
            mmasug_(&ITER, &M, &N, &GEPS, &IYFREE[0], &XVAL[0], &XMMA[0],
                    &XMIN[0], &XMAX[0], &XLOW[0], &XUPP[0], &ALFA[0], &BETA[0],
                    &A[0], &B[0], &C[0], &Y[0], &Z, &RAA0, &RAA[0], &ULAM[0],
                    &F0VAL, &FVAL[0], &F0APP, &FAPP[0], &FMAX[0], &DF0DX[0], &DFDX[0],
                    &P[0], &Q[0], &P0[0], &Q0[0], &UU[0], &GRADF[0], &DSRCH[0], &HESSF[0]);
            /*
             *  The USER should now calculate function values at XMMA.
             *  The result should be put in F0NEW and FNEW.
             */
            std::fill(eval_grads.begin(), eval_grads.end(), false);
            _feval->_evaluate_wrapper(XMMA,
                                      F0NEW, false, DF0DX,
                                      FNEW, eval_grads, DFDX);
            
            if (INNER >= INNMAX) {
                libMesh::out
                << "** Max Inner Iter Reached: Terminating! Inner Iter = "
                << INNER << std::endl;
                inner_terminate = true;
            }
            else {
                /*
                 *  It is checked if the approximations were conservative.
                 */
                conser_( &M, &ICONSE, &GEPS, &F0NEW, &F0APP, &FNEW[0], &FAPP[0]);
                if (ICONSE == 1) {
                    libMesh::out
                    << "** Conservative Solution: Terminating! Inner Iter = "
                    << INNER << std::endl;
                    inner_terminate = true;
                }
                else {
                    /*
                     *  The approximations were not conservative, so RAA0 and RAA
                     *  are updated and one more inner iteration is started.
                     */
                    INNER=INNER+1;
                    raaupd_( &M, &N, &GEPS, &XMMA[0], &XVAL[0],
                            &XMIN[0], &XMAX[0], &XLOW[0], &XUPP[0],
                            &F0NEW, &FNEW[0], &F0APP, &FAPP[0], &RAA0, &RAA[0]);
                }
            }
        }
        
        /*
         *  The inner iterative process has terminated, which means
         *  that an outer iteration has been completed.
         *  The variables are updated so that XVAL stands for the new
         *  outer iteration point. The fuction values are also updated.
         */
        xupdat_( &N, &ITER, &XMMA[0], &XVAL[0], &XOLD1[0], &XOLD2[0]);
        fupdat_( &M, &F0NEW, &FNEW[0], &F0VAL, &FVAL[0]);
        /*
         *  The USER may now write the current solution.
         */
        _feval->_output_wrapper(ITER, XVAL, F0VAL, FVAL, true);
        f0_iters[(ITE-1)%n_rel_change_iters] = F0VAL;
        
        /*
         *  One more outer iteration is started as long as
         *  ITE is less than MAXITE:
         */
        if (ITE == _feval->max_iters()) {
            libMesh::out
            << "GCMMA: Reached maximum iterations, terminating! "
            << std::endl;
            terminate = true;
        }
        
        // relative change in objective
        bool rel_change_conv = true;
        Real f0_curr = f0_iters[n_rel_change_iters-1];
        
        for (unsigned int i=0; i<n_rel_change_iters-1; i++) {
            if (f0_curr > sqrt(GEPS))
                rel_change_conv = (rel_change_conv &&
                                   fabs(f0_iters[i]-f0_curr)/fabs(f0_curr) < GEPS);
            else
                rel_change_conv = (rel_change_conv &&
                                   fabs(f0_iters[i]-f0_curr) < GEPS);
        }
        if (rel_change_conv) {
            libMesh::out
            << "GCMMA: Converged relative change tolerance, terminating! "
            << std::endl;
            terminate = true;
        }
        
    }
    
#endif //MAST_ENABLE_GCMMA == 1
}
 static void pulldown()
 {
     volatile uint32_t *reg = &port::ptr()->PIN_CNF[bit::shift];
     SET_BITFIELD(*reg, FVAL(GPIO_PIN_CNF_PULL, PULLDOWN));
 }
 static void pulloff()
 {
     volatile uint32_t *reg = &port::ptr()->PIN_CNF[bit::shift];
     SET_BITFIELD(*reg, FVAL(GPIO_PIN_CNF_PULL, DISABLED));
 }
 static void input()
 {
     // See output() comments
     SET_BITFIELD(port::ptr()->PIN_CNF[bit::shift], FVAL(GPIO_PIN_CNF_INPUT, CONNECT));
     port::ptr()->DIRCLR = bit::value;
 }