Esempio n. 1
0
void Model::construct_feedback_matrix(Eigen::MatrixXd &S,
                                      const Eigen::MatrixXd &M,
                                      const Parameter &parameter) {
  S.setZero();

  Eigen::Matrix2d T;
  T.setConstant(1.0 / sqrt(2));
  T(0, 0) = -1 * T(0, 0);

  Eigen::DiagonalMatrix<double, 2> W(1, parameter.wgt);

  Eigen::MatrixXd DV(n_dimensions, 1);

  double s;
  for (unsigned int i = 0; i < n_alternatives; i++) {
    for (unsigned int j = 0; j < n_alternatives; j++) {

      for (unsigned int k = 0; k < n_dimensions; k++) {
        DV(k, 0) = M(i, k) - M(j, k);
      }
      DV = T * DV;
      s = (DV.transpose() * W * DV)(0, 0);
      S(i, j) = parameter.phi2 * exp(-1 * parameter.phi1 * s * s);
    }
  }

  S = Eigen::MatrixXd::Identity(n_alternatives, n_alternatives) - S;
}
Esempio n. 2
0
/*
static void undo_check_modified_step(GtkTextBuffer *buffer)
{
	if (modified_step == g_list_length(undo_list))
		gtk_text_buffer_set_modified(buffer, FALSE);
}
*//* // ????? "modified-changed" signal isn't emitted properly...
#include "window.h"
static void undo_check_modified_step(GtkTextBuffer *buffer)
{
	if (modified_step == g_list_length(undo_list)) {
		gtk_text_buffer_set_modified(buffer, FALSE);
		set_main_window_title();
	}
}
*/
static void cb_begin_user_action(GtkTextBuffer *buffer)
{
	g_signal_handlers_unblock_by_func(G_OBJECT(buffer), 
		G_CALLBACK(cb_insert_text), NULL);
	g_signal_handlers_unblock_by_func(G_OBJECT(buffer),
		G_CALLBACK(cb_delete_range), NULL);
DV(g_print("begin-user-action(unblock_func)"));
DV(g_print(": keyval = 0x%X\n", get_current_keyval()));
}
Esempio n. 3
0
File: state.c Progetto: 4mig4/mbusd
/*
 * Set tty device to STATE
 */
void
state_tty_set(ttydata_t *mod, int state)
{
  switch (state)
  {
    case TTY_PAUSE:
      mod->trynum = 0;
      mod->timer = (unsigned long)cfg.rqstpause * 1000l;
#ifdef DEBUG
      logw(5, "tty: state now is TTY_PAUSE");
#endif
      break;
    case TTY_READY:
      mod->trynum = 0;
      mod->timer = 0l;
#ifdef DEBUG
      logw(5, "tty: state now is TTY_READY");
#endif
      break;
    case TTY_RQST:
      mod->ptrbuf = 0;
      mod->timer = 0l;
      mod->trynum = mod->trynum ? mod->trynum - 1 : (unsigned)cfg.maxtry;
#ifdef DEBUG
      logw(5, "tty: state now is TTY_RQST");
#endif
#ifndef NOSILENT
      tty_delay(DV(2, cfg.ttyspeed));
#endif
      break;
    case TTY_RESP:
      mod->ptrbuf = 0;
      mod->rxoffset = 0;
      /* XXX need real recv length? */
      mod->rxlen = TTY_BUFSIZE;
      mod->timer = cfg.respwait * 1000l + DV(mod->txlen, mod->speed);
#ifdef DEBUG
      logw(5, "tty: state now is TTY_RESP");
#endif
      break;
    case TTY_PROC:
#ifdef DEBUG
      logw(5, "tty: state now is TTY_PROC");
#endif
      break;
    default:
      /* unknown state, exiting */
#ifdef DEBUG
      logw(5, "tty_set_state() - invalid state (%d)", state);
#endif
      exit (-1);
  }
  mod->state = state;
}
Esempio n. 4
0
File: main.c Progetto: mattjakob/s3d
int main(int argc, char **argv)
{
  Poly *l, *p, *q = poly_alloc(3);
  Hpoly *t = hpoly_alloc(3);
  Item *i;

  init_sdl();
  s = scene_read();
  init_render();

  for (o = s->objs; o != NULL; o = o->next) {
    for (l = prim_uv_decomp(o->u.prim, 1.); l != NULL; l = l->next) {
      p = poly_transform(prim_polys(o->u.prim, l), mclip);
      if (!is_backfacing(p, v3_unit(v3_scale(-1, poly_centr(p)))))
	hither_clip(0, p, z_store, plist_free);
    }
  }
  z = z_sort(z);

  for (i = z->head; i != NULL; i = i->next) {
    t = hpoly_polyxform(t, S(i), mdpy);
    q = poly_wz_hpoly(q, W(i), t);
    texture_wscale(W(i), T(i));
    scan_spoly3(q, 2, texture_shadepaint,
             texture_set(td,W(i),T(i),P(i),N(i),DU(i),DV(i),rc,M(i)));
  }
  img_write(s->img, "stdout", 0);
  exit(0);
}
Esempio n. 5
0
gboolean undo_redo_real(GtkTextBuffer *buffer)
{
	GtkTextIter start_iter, end_iter;
	UndoInfo *ri;
	
	if (g_list_length(redo_list)) {
//		undo_block_signal(buffer);
		ri = g_list_last(redo_list)->data;
		gtk_text_buffer_get_iter_at_offset(buffer, &start_iter, ri->start);
		switch (ri->command) {
		case INS:
			gtk_text_buffer_insert(buffer, &start_iter, ri->str, -1);
			break;
		default:
			gtk_text_buffer_get_iter_at_offset(buffer, &end_iter, ri->end);
			gtk_text_buffer_delete(buffer, &start_iter, &end_iter);
		}
		undo_list = g_list_append(undo_list, ri);
		redo_list = g_list_delete_link(redo_list, g_list_last(redo_list));
DV(g_print("cb_edit_redo: undo left = %d, redo left = %d\n",
g_list_length(undo_list), g_list_length(redo_list)));
//		undo_unblock_signal(buffer);
		if (ri->seq) {
			undo_set_sequency(TRUE);
			return TRUE;
		}
		if (!g_list_length(redo_list))
			gtk_widget_set_sensitive(redo_w, FALSE);
		gtk_widget_set_sensitive(undo_w, TRUE);
		gtk_text_buffer_place_cursor(buffer, &start_iter);
		scroll_to_cursor(buffer, 0.05);
	}
	undo_check_modified_step(buffer);
	return FALSE;
}
Esempio n. 6
0
static void cb_end_user_action(GtkTextBuffer *buffer)
{
	g_signal_handlers_block_by_func(G_OBJECT(buffer), 
		G_CALLBACK(cb_insert_text), NULL);
	g_signal_handlers_block_by_func(G_OBJECT(buffer),
		G_CALLBACK(cb_delete_range), NULL);
DV(g_print("end-user-action(block_func)\n"));
}
Esempio n. 7
0
static void dnd_drag_data_recieved_handler(GtkWidget *widget,
	GdkDragContext *context, gint x, gint y,
	GtkSelectionData *selection_data, guint info, guint time)
{
	static gboolean flag_called_once = FALSE;
	gchar **files;
	gchar *filename;
	gchar *comline;
	gint i = 0, j = 0;
	gchar *filename_sh;
	gchar **strs;
#ifdef ENABLE_CSDI
	j = 1;
#endif
DV(g_print("DND start!\n"));

	if (g_ascii_strcasecmp(gdk_atom_name(context->targets->data),
	    "GTK_TEXT_BUFFER_CONTENTS") != 0) {
		if (flag_called_once) {
			flag_called_once = FALSE;
			g_signal_stop_emission_by_name(widget, "drag_data_received");
DV(g_print("second drop signal killed.\n"));
			return;
		} else
			flag_called_once = TRUE;
	}

DV({
	g_print("info                      = %d\n", info);
	g_print("time                      = %d\n", time);
	g_print("context->protocol         = %d\n", context->protocol);
	g_print("context->is_source        = %d\n", context->is_source);
	g_print("context->targets          = %d\n", g_list_length(context->targets));
	g_print("context->target           = %s\n", gdk_atom_name(context->targets->data));
/*	g_print("context->target           = %s\n", gdk_atom_name(context->targets->next->data));
	g_print("context->target           = %s\n", gdk_atom_name(context->targets->next->next->data));
	g_print("context->actions          = %d\n", context->actions);
	g_print("context->suggested_action = %d\n", context->suggested_action);
	g_print("context->action           = %d\n", context->action);
	g_print("selection_data->selection = %s\n", gdk_atom_name(selection_data->selection));
	g_print("selection_data->target    = %s\n", gdk_atom_name(selection_data->target));
*/	g_print("selection_data->type      = %s\n", gdk_atom_name(selection_data->type));
	g_print("selection_data->format    = %d\n", selection_data->format);
	g_print("selection_data->length    = %d\n", selection_data->length);
	g_print("%s\n", selection_data->data);
});
Esempio n. 8
0
void
SMove(void *p, int x, int y)
{
    GXHEADER local;

    GV(&local, 160, 100);
    memcpy(local.vptr, p, 160 * 100);
    gxPutImage(&local, gxSET, x, y, 0);
    DV(&local);
}
Esempio n. 9
0
static void cb_insert_text(GtkTextBuffer *buffer, GtkTextIter *iter, gchar *str,
gint len)
{
	gint start, end;
	
DV(	g_print("insert-text\n"));
	end = gtk_text_iter_get_offset(iter);
	start = end - g_utf8_strlen(str, -1);
	
	undo_create_undo_info(buffer, INS, start, end);
}
Esempio n. 10
0
void
LMove(void *p)
{
    GXHEADER local;

    memset(screen, 0, 320 * 200);

    GV(&local, 160, 100);
    memcpy(local.vptr, p, 160 * 100);
    gxPutImage(&local, gxSET, 320 / 4, 200 / 4, 0);
    DV(&local);
}
Esempio n. 11
0
void PokePersonal::controlGender()
{
    if (PokemonInfo::Gender(num()) == Pokemon::MaleAndFemaleAvail) {
        int rate = PokemonInfo::GenderRate(num());

        if (DV(Attack) < (8-rate) * 2) {
            gender() = Pokemon::Female;
        } else {
            gender() = Pokemon::Male;
        }
    }
}
Esempio n. 12
0
int copy_judySL_typed(judys_llref* src, judys_llref** dest) {

    // use the assignment operator
    **dest = *src;

#if 0
    *dest = 0; // default value, if we don't finish
    Pvoid_t   newJArray = 0;         // new JudyL array to ppopulate

    Word_t * PValue = 0;                // pointer to array element value
    Word_t * PValueIns = 0;                // pointer to array element value

    volatile int complete = 0;
    complete = 0;

    uint8_t      Index[BUFSIZ];            // string to sort.

    Index[0] = '\0';                    // start with smallest string.

    XTRY
     case XCODE:

     JSLF(PValue, src, Index);
     if (PValue == PJERR) { l3throw(XARRAYDUP_FAILURE); }

     while (PValue != NULL)
      {
          DV(printf("%s   -> %.06f\n", Index, *((double*)PValue)));
          JSLI(PValueIns, newJArray, Index);
          if (PValueIns == PJERR) { l3throw(XARRAYDUP_FAILURE); }
          *PValueIns = *PValue;
          JSLN(PValue, src, Index);
          
          if (PValue == NULL) {
              complete = 1;
              break;
          }
      }

     break;
     case XFINALLY:
         if (complete) {
             *dest = newJArray;
         }
         break;
    XENDX

#endif

   return 0;

}
Esempio n. 13
0
int main(int argc, char *argv[])
{
    #define NO_CONTROL
    #include "postProcess.H"

    #include "setRootCase.H"
    #include "createTime.H"
    #include "createMesh.H"
    #include "createFields.H"

    // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

    Info<< nl << "Calculating value(price of comodities)" << endl;

    surfaceScalarField phi("phi", (sigmaSqr - r)*(Pf & mesh.Sf()));

    volScalarField DV("DV", 0.5*sigmaSqr*sqr(P.component(Foam::vector::X)));

    Info<< "Starting time loop\n" << endl;

    while (runTime.loop())
    {
        delta == fvc::grad(V)().component(Foam::vector::X);

        solve
        (
            fvm::ddt(V)
          + fvm::div(phi, V)
          - fvm::Sp(fvc::div(phi), V)
          - fvm::laplacian(DV, V)
         ==
          - fvm::Sp(r, V)
        );

        runTime.write();

        if (runTime.writeTime())
        {
            writeCellGraph(V, runTime.graphFormat());
            writeCellGraph(delta, runTime.graphFormat());
        }

        Info<< "ExecutionTime = " << runTime.elapsedCpuTime() << " s"
            << "  ClockTime = " << runTime.elapsedClockTime() << " s"
            << nl << endl;
    }

    Info<< "End\n" << endl;

    return 0;
}
Esempio n. 14
0
static void cb_delete_range(GtkTextBuffer *buffer, GtkTextIter *start_iter, GtkTextIter *end_iter)
{
	gint start, end;
	gchar command;
	
DV(	g_print("delete-range\n"));
	start = gtk_text_iter_get_offset(start_iter);
	end = gtk_text_iter_get_offset(end_iter);
	
	if (get_current_keyval() == GDK_BackSpace)
		command = BS;
	else
		command = DEL;
	undo_create_undo_info(buffer, command, start, end);
}
Esempio n. 15
0
static PJ_LP s_inverse (PJ_XY xy, PJ *P) {           /* Spheroidal, inverse */
    PJ_LP lp = {0.0,0.0};
    long i;
    double t, t1;
    struct COEFS T;
    int iters;

    lp.lam = xy.x / FXC;
    lp.phi = fabs(xy.y / FYC);
    if (lp.phi >= 1.) { /* simple pathologic cases */
        if (lp.phi > ONEEPS) {
            proj_errno_set(P, PJD_ERR_TOLERANCE_CONDITION);
            return lp;
        }
        else {
            lp.phi = xy.y < 0. ? -M_HALFPI : M_HALFPI;
            lp.lam /= X[NODES].c0;
        }
    } else { /* general problem */
        /* in Y space, reduce to table interval */
        i = isnan(lp.phi) ? -1 : lround(floor(lp.phi * NODES));
        if( i < 0 || i >= NODES ) {
            proj_errno_set(P, PJD_ERR_TOLERANCE_CONDITION);
            return lp;
        }
        for (;;) {
            if (Y[i].c0 > lp.phi) --i;
            else if (Y[i+1].c0 <= lp.phi) ++i;
            else break;
        }
        T = Y[i];
        /* first guess, linear interp */
        t = 5. * (lp.phi - T.c0)/(Y[i+1].c0 - T.c0);
        /* make into root */
        T.c0 = (float)(T.c0 - lp.phi);
        for (iters = MAX_ITER; iters ; --iters) { /* Newton-Raphson */
            t -= t1 = V(T,t) / DV(T,t);
            if (fabs(t1) < EPS)
                break;
        }
        if( iters == 0 )
            pj_ctx_set_errno( P->ctx, PJD_ERR_NON_CONVERGENT );
        lp.phi = (5 * i + t) * DEG_TO_RAD;
        if (xy.y < 0.) lp.phi = -lp.phi;
        lp.lam /= V(X[i], t);
    }
    return lp;
}
Esempio n. 16
0
static void undo_append_undo_info(GtkTextBuffer *buffer, gchar command, gint start, gint end, gchar *str)
{
	UndoInfo *ui = g_malloc(sizeof(UndoInfo));
	
	ui->command = command;
	ui->start = start;
	ui->end = end;
//	ui->seq = FALSE;
	ui->seq = seq_reserve;
	ui->str = str;
	
	seq_reserve = FALSE;
	
	undo_list = g_list_append(undo_list, ui);
DV(g_print("undo_cb: %d %s (%d-%d)\n", command, str, start, end));
}
Esempio n. 17
0
QDomElement & PokeTeam::toXml(QDomElement &el) const
{
    const_cast<PokeTeam*>(this)->sanityCheck();

    QDomDocument doc;

    el.setAttribute("Nickname", nickname());
    el.setAttribute("Num", num().pokenum);
    el.setAttribute("Item", item());
    el.setAttribute("Ability", ability());
    el.setAttribute("Nature", nature());
    el.setAttribute("Gender", gender());
    el.setAttribute("Shiny", shiny());
    el.setAttribute("Happiness", happiness());
    el.setAttribute("Forme", num().subnum);
    el.setAttribute("Lvl", level());
    el.setAttribute("Gen", gen().num);
    el.setAttribute("SubGen", gen().subnum);

    for(int i = 0; i < 4; i++)
    {
        QDomElement move = doc.createElement("Move");
        el.appendChild(move);

        QDomText name = doc.createTextNode(QString("%1").arg(this->move(i)));
        move.appendChild(name);
    }
    for(int i = 0; i < 6; i++)
    {
        QDomElement Dv = doc.createElement("DV");
        el.appendChild(Dv);

        QDomText Dvname = doc.createTextNode(QString("%1").arg(DV(i)));
        Dv.appendChild(Dvname);
    }
    for(int i = 0; i < 6; i++)
    {
        QDomElement Ev = doc.createElement("EV");
        el.appendChild(Ev);

        QDomText Evname = doc.createTextNode(QString("%1").arg(EV(i)));
        Ev.appendChild(Evname);
    }

    return el;
}
Esempio n. 18
0
double GhostGridField<T>::DVn(double x,double y,double z) const{
    Vector3 normal = _levelset->getNormal(x, y, z);
    double norm = normal.norm();
    assert(norm < 1.01);
    double val;
    if (_direction == UDIR) {
        val =  normal.x;
    }else if (_direction == VDIR){
        val =  normal.y;
    }else if (_direction == WDIR){
        val =  normal.z;
    }else{
        assert(false);
    }

	double returnval = val*DV();
    
	return returnval;
}
Esempio n. 19
0
void PresPict(char poff)
{
    GXHEADER local;
    SimpleHdr table;
    FILE *in;
    in = sOpen("PRESR.BUT", "rb", 0);
    fseek(in, poff * sizeof_SimpleHdr, SEEK_SET);
    fread_SimpleHdr(&table, 1, in);
    fseek(in, table.offset, SEEK_SET);
    fread(&pal[96], 672, 1, in);
    fread(buffer, table.size, 1, in);
    fclose(in);
    GV(&local, 126, 84);
    RLED_img(buffer, local.vptr, table.size, local.w, local.h);

    gxPutImage(&local, gxSET, 183, 33, 0);

    DV(&local);
    return;
}
Esempio n. 20
0
gboolean undo_undo_real(GtkTextBuffer *buffer)
{
	GtkTextIter start_iter, end_iter;
	UndoInfo *ui;
	
	undo_flush_temporal_buffer(buffer);
	if (g_list_length(undo_list)) {
//		undo_block_signal(buffer);
		ui = g_list_last(undo_list)->data;
		gtk_text_buffer_get_iter_at_offset(buffer, &start_iter, ui->start);
		switch (ui->command) {
		case INS:
			gtk_text_buffer_get_iter_at_offset(buffer, &end_iter, ui->end);
			gtk_text_buffer_delete(buffer, &start_iter, &end_iter);
			break;
		default:
			gtk_text_buffer_insert(buffer, &start_iter, ui->str, -1);
		}
		redo_list = g_list_append(redo_list, ui);
		undo_list = g_list_delete_link(undo_list, g_list_last(undo_list));
DV(g_print("cb_edit_undo: undo left = %d, redo left = %d\n",
g_list_length(undo_list), g_list_length(redo_list)));
//		undo_unblock_signal(buffer);
		if (g_list_length(undo_list)) {
			if (((UndoInfo *)g_list_last(undo_list)->data)->seq)
				return TRUE;
		} else
			gtk_widget_set_sensitive(undo_w, FALSE);
		gtk_widget_set_sensitive(redo_w, TRUE);
		if (ui->command == DEL)
			gtk_text_buffer_get_iter_at_offset(buffer, &start_iter, ui->start);
		gtk_text_buffer_place_cursor(buffer, &start_iter);
		scroll_to_cursor(buffer, 0.05);
	}
	undo_check_modified_step(buffer);
	return FALSE;
}
Esempio n. 21
0
 inline void inv(cartesian_type& xy_x, cartesian_type& xy_y, geographic_type& lp_lon, geographic_type& lp_lat) const
 {
     int i;
     double t, t1;
     struct COEFS T;
 
     lp_lon = xy_x / FXC;
     lp_lat = fabs(xy_y / FYC);
     if (lp_lat >= 1.) { /* simple pathologic cases */
         if (lp_lat > ONEEPS) throw proj_exception();
         else {
             lp_lat = xy_y < 0. ? -HALFPI : HALFPI;
             lp_lon /= X[NODES].c0;
         }
     } else { /* general problem */
         /* in Y space, reduce to table interval */
         for (i = int_floor(lp_lat * NODES);;) {
             if (Y[i].c0 > lp_lat) --i;
             else if (Y[i+1].c0 <= lp_lat) ++i;
             else break;
         }
         T = Y[i];
         /* first guess, linear interp */
         t = 5. * (lp_lat - T.c0)/(Y[i+1].c0 - T.c0);
         /* make into root */
         T.c0 -= lp_lat;
         for (;;) { /* Newton-Raphson reduction */
             t -= t1 = V(T,t) / DV(T,t);
             if (fabs(t1) < EPS)
                 break;
         }
         lp_lat = (5 * i + t) * DEG_TO_RAD;
         if (xy_y < 0.) lp_lat = -lp_lat;
         lp_lon /= V(X[i], t);
     }
 }
Esempio n. 22
0
void PokePersonal::controlShininess()
{
    shiny() = DV(Defense) == 10 && DV(Speed) == 10 && DV(SpAttack) == 10 && DV(Attack) % 4 >= 2;
}
Esempio n. 23
0
void PokePersonal::runCheck()
{
    if (!PokemonInfo::Exists(num(), gen())) {
        reset();
        return;
    }

    if (!PokemonInfo::AFormesShown(num())) {
        num() = num().original();
    }

    if (gen() <= 2) {
        ability() = 0;
        nature() = 0;
    } else {
        AbilityGroup ab = PokemonInfo::Abilities(num(), gen());

        if (ability() == 0 || (ability() != ab.ab(2) && ability() != ab.ab(1)))
            ability() = ab.ab(0);
    }

    if (gen().num == 2)
        controlGender();

    if (!ItemInfo::Exists(item(), gen())) {
        item() = 0;
    }

    for (int i = 0; i < 6; i++)
        controlEVs(i);

    if (gen() <= 2) {
        for (int i = 0; i < 6; i++) {
            if (DV(i) >= 15)
                setDV(i, 15);
        }
    }

    if (gen().num == 2) {
        setEV(SpDefense, EV(SpAttack));
        setDV(SpDefense, DV(SpAttack));
    }

    int avail = PokemonInfo::Gender(num());

    if (avail != Pokemon::MaleAndFemaleAvail) {
        gender() = avail;
    } else if (gender() == Pokemon::Neutral){
        gender() = Pokemon::Male;
    }

    int minLevel = PokemonInfo::AbsoluteMinLevel(num(), gen());

    if (MoveSetChecker::enforceMinLevels && level() < minLevel) {
        level() = minLevel;
    }

    QSet<int> invalidMoves;

    MoveSetChecker::isValid(num(), gen(), move(0), move(1), move(2), move(3), ability(), gender(), level(), false, &invalidMoves);

    while (invalidMoves.size() > 0) {
        for (int i = 0; i < 4; i++) {
            if (invalidMoves.contains(move(i))) {
                setMove(0, i, false);
            }
        }
        invalidMoves.clear();

        MoveSetChecker::isValid(num(), gen(), move(0), move(1), move(2), move(3), ability(), gender(), level(), false, &invalidMoves);
    }

    if (num().pokenum == Pokemon::Keldeo) {
        if (move(0) == Move::SecretSword || move(1) == Move::SecretSword || move(2) == Move::SecretSword || move(3) == Move::SecretSword) {
            num() = Pokemon::Keldeo_R;
        } else {
            num() = num().original();
        }
    }
}
Esempio n. 24
0
std::string mga_incipit_cstrs::pretty(const std::vector<double> &x) const {
  
	// We set the std output format
	std::ostringstream s;
	s.precision(15);
	s << std::scientific;
	
	double d,ra,d2,ra2;

	double common_mu = m_seq[0]->get_mu_central_body();
	// 1 -  we 'decode' the chromosome recording the various times of flight (days) in the list T
	std::vector<double> T(m_seq.size(),0.0);
	
	for (size_t i = 0; i<m_seq.size(); ++i) {
		T[i] = x[4*i+3];
	}
	// 2 - We compute the epochs and ephemerides of the planetary encounters
	std::vector<kep_toolbox::epoch>   t_P(m_seq.size());
	std::vector<kep_toolbox::array3D> r_P(m_seq.size());
	std::vector<kep_toolbox::array3D> v_P(m_seq.size());
	std::vector<double> DV(m_seq.size());
	for (size_t i = 0; i<r_P.size(); ++i) {
		t_P[i] = kep_toolbox::epoch(x[0] + std::accumulate(T.begin(),T.begin()+1+i,0.0));
		m_seq[i]->eph(t_P[i], r_P[i], v_P[i]);
	}

	// 3 - We start with the first leg
	double theta = 2*boost::math::constants::pi<double>()*x[1];
	double phi = acos(2*x[2]-1)-boost::math::constants::pi<double>() / 2;
	kep_toolbox::array3D r = { {ASTRO_JR * 1000*cos(phi)*sin(theta), ASTRO_JR * 1000*cos(phi)*cos(theta), ASTRO_JR * 1000*sin(phi)} };
	kep_toolbox::array3D v;
	
	kep_toolbox::lambert_problem l(r,r_P[0],T[0]*ASTRO_DAY2SEC,common_mu,false,false);
	kep_toolbox::array3D v_beg_l = l.get_v1()[0];
	kep_toolbox::array3D v_end_l = l.get_v2()[0];
	kep_toolbox::closest_distance(d,ra,r,v_beg_l, r_P[0], v_end_l, common_mu);

	DV[0] = std::abs(kep_toolbox::norm(v_beg_l)-3400.0);
	kep_toolbox::array3D v_out,mem_vin,mem_vout,mem_vP;
	
	s << "\nFirst Leg: 1000JR to " << m_seq[0]->get_name() << std::endl; 
	s << "\tDeparture: " << kep_toolbox::epoch(x[0]) << " (" << x[0] << " mjd2000) " << std::endl; 
	s << "\tDuration: " << T[0] << "days" << std::endl; 
	s << "\tInitial Velocity Increment (m/s): " << DV[0] << std::endl; 
	kep_toolbox::diff(v_out, v_end_l, v_P[0]);
	s << "\tArrival relative velocity at " << m_seq[0]->get_name() << " (m/s): " << kep_toolbox::norm(v_out)  << std::endl; 
	s << "\tClosest distance: " << d / ASTRO_JR;
	
	// 4 - And we proceed with each successive leg (if any)
	for (size_t i = 1; i<m_seq.size(); ++i) {
		// Fly-by
		kep_toolbox::fb_prop(v_out, v_end_l, v_P[i-1], x[4*i+1] * m_seq[i-1]->get_radius(), x[4*i], m_seq[i-1]->get_mu_self());
		// s/c propagation before the DSM
		r = r_P[i-1];
		v = v_out;
		mem_vout = v_out;
		mem_vin = v_end_l;
		mem_vP = v_P[i-1];
		
		kep_toolbox::propagate_lagrangian(r,v,x[4*i+2]*T[i]*ASTRO_DAY2SEC,common_mu);
		kep_toolbox::closest_distance(d, ra, r_P[i-1], v_out, r, v, common_mu);
		
		// Lambert arc to reach Earth during (1-nu2)*T2 (second segment)
		double dt = (1-x[4*i+2])*T[i]*ASTRO_DAY2SEC;
		kep_toolbox::lambert_problem l2(r,r_P[i],dt,common_mu,false,false);
		v_end_l = l2.get_v2()[0];
		v_beg_l = l2.get_v1()[0];
		kep_toolbox::closest_distance(d2,ra2,r,v_beg_l, r_P[i], v_end_l, common_mu);
		
		if (d < d2)
		{
			d = d/ASTRO_JR;
			ra = ra/ASTRO_JR;
		} else {
			d = d2/ASTRO_JR;
			ra = ra2/ASTRO_JR;
		}
		// DSM occuring at time nu2*T2
		kep_toolbox::diff(v_out, v_beg_l, v);
		DV[i] = kep_toolbox::norm(v_out);
		s <<  "\nleg no. " << i+1 << ": " << m_seq[i-1]->get_name() << " to " << m_seq[i]->get_name() << std::endl; 
		s <<  "\tDuration: (days)" << T[i] << std::endl; 
		s <<  "\tFly-by epoch: " << t_P[i-1] << " (" << t_P[i-1].mjd2000() << " mjd2000) " << std::endl; 
		s <<  "\tFly-by altitude (km): " << (x[4*i+1]*m_seq[i-1]->get_radius()-m_seq[i-1]->get_radius())/1000.0 << std::endl; 
		s <<  "\tPlanet position (m): " << r_P[i-1] << std::endl; 
		s <<  "\tPlanet velocity (m/s): " << mem_vP << std::endl; 
		s <<  "\tV in (m/s): " << mem_vin << std::endl; 
		s <<  "\tV out (m/s): " << mem_vout << std::endl << std::endl;

		s <<  "\tDSM after (days): "  << x[4*i+2]*T[i] << std::endl; 
		s <<  "\tDSM magnitude (m/s): " << DV[i] << std::endl; 
		s <<  "\tClosest distance (JR): " << d << std::endl; 
		s <<  "\tApoapsis at closest distance (JR): " << ra << std::endl; 
 	}
	
	s << "\nArrival at " << m_seq[m_seq.size()-1]->get_name() << std::endl; 
	kep_toolbox::diff(v_out, v_end_l, v_P[m_seq.size()-1]);
	s <<  "Arrival epoch: "  << t_P[m_seq.size()-1] << " (" << t_P[m_seq.size()-1].mjd2000() << " mjd2000) " << std::endl; 
	s <<  "Arrival Vinf (m/s): " << v_out << " - " << kep_toolbox::norm(v_out) << std::endl; 
	s <<  "Total mission time (days): " << std::accumulate(T.begin(),T.end(),0.0) << std::endl; 
	return s.str();
}
Esempio n. 25
0
/// Implementation of the objective function.
void mga_incipit_cstrs::compute_constraints_impl(constraint_vector &c, const decision_vector &x) const
{
try {
	double common_mu = m_seq[0]->get_mu_central_body();
	// 1 -  we 'decode' the chromosome recording the various times of flight (days) in the list T
	std::vector<double> T(m_seq.size(),0.0);

	for (size_t i = 0; i<m_seq.size(); ++i) {
		T[i] = x[4*i+3];
	}
	// 2 - We compute the epochs and ephemerides of the planetary encounters
	std::vector<kep_toolbox::epoch>   t_P(m_seq.size());
	std::vector<kep_toolbox::array3D> r_P(m_seq.size());
	std::vector<kep_toolbox::array3D> v_P(m_seq.size());
	std::vector<double> DV(m_seq.size());
	for (size_t i = 0; i<r_P.size(); ++i) {
		t_P[i] = kep_toolbox::epoch(x[0] + std::accumulate(T.begin(),T.begin()+1+i,0.0));
		m_seq[i]->eph(t_P[i], r_P[i], v_P[i]);
	}

	// 3 - We start with the first leg
	double theta = 2*boost::math::constants::pi<double>()*x[1];
	double phi = acos(2*x[2]-1)-boost::math::constants::pi<double>() / 2;
	double d,d2,ra,ra2;
	kep_toolbox::array3D r = { {ASTRO_JR*1000*cos(phi)*sin(theta), ASTRO_JR*1000*cos(phi)*cos(theta), ASTRO_JR*1000*sin(phi)} };
	kep_toolbox::array3D v;
	kep_toolbox::lambert_problem l(r,r_P[0],T[0]*ASTRO_DAY2SEC,common_mu,false,false);
	kep_toolbox::array3D v_beg_l = l.get_v1()[0];
	kep_toolbox::array3D v_end_l = l.get_v2()[0];

	DV[0] = std::abs(kep_toolbox::norm(v_beg_l)-3400.0);

	// 4 - And we proceed with each successive leg (if any)
	kep_toolbox::array3D v_out;
	for (size_t i = 1; i<m_seq.size(); ++i) {
		// Fly-by
		kep_toolbox::fb_prop(v_out, v_end_l, v_P[i-1], x[4*i+1] * m_seq[i-1]->get_radius(), x[4*i], m_seq[i-1]->get_mu_self());
		r = r_P[i-1];
		v = v_out;
		// s/c propagation before the DSM
		kep_toolbox::propagate_lagrangian(r,v,x[4*i+2]*T[i]*ASTRO_DAY2SEC,common_mu);
		kep_toolbox::closest_distance(d, ra, r_P[i-1], v_out, r, v, common_mu);

		// Lambert arc to reach Earth during (1-nu2)*T2 (second segment)
		double dt = (1-x[4*i+2])*T[i]*ASTRO_DAY2SEC;
		kep_toolbox::lambert_problem l2(r,r_P[i],dt,common_mu,false,false);
		v_end_l = l2.get_v2()[0];
		v_beg_l = l2.get_v1()[0];
		kep_toolbox::closest_distance(d2,ra2,r,v_beg_l, r_P[i], v_end_l, common_mu);
		if (d < d2)
		{
			d = d/ASTRO_JR;
		} else {
			d = d2/ASTRO_JR;
		}

		// DSM occuring at time nu2*T2
		kep_toolbox::diff(v_out, v_beg_l, v);
		DV[i] = kep_toolbox::norm(v_out) + std::max((2.0-d),0.0) * 1000.0;
	}
	// Now we return the constraints
	c[0] = std::accumulate(T.begin(),T.end(),0.0) - m_tmax;
	c[1] = m_dmin - d;
//Here the lambert solver or the lagrangian propagator went wrong
} catch (...) {
	c[0] = boost::numeric::bounds<double>::highest();
	c[1] = boost::numeric::bounds<double>::highest();
}
}
Esempio n. 26
0
void PokePersonal::controlHPDV()
{
    m_DVs[Hp] = ((DV(Attack) & 1) << 3) + ((DV(Defense) & 1) << 2) + ((DV(Speed) & 1) << 1) + (DV(SpAttack) & 1);
}
Esempio n. 27
0
int PokeTeam::stat(int statno) const
{
    return PokemonInfo::FullStat(num(), gen(), nature(), statno, level(),DV(statno),EV(statno));
}
Esempio n. 28
0
void CodeGenFunction::EmitFunctionDecls(const DeclContext *DC) {
  FuncDeclEmitter DV(*this);
  DV.Visit(DC);
}
void
Future(char plr)
{
    /** \todo the whole Future()-function is 500 >lines and unreadable */
    TRACE1("->Future(plr)");
	int MisNum = 0, DuraType = 0, MaxDur = 6, i, ii;
	int setting = -1, prev_setting = -1;
	int Ok, NewType;
	GXHEADER local, local2;

	GV(&local, 166, 9);
	GV(&local2, 177, 197);
    GV(&vh,240,90);                  /* global variable */
  begfut:
	MisNum = FutureCheck(plr, 0);
	if (MisNum == 5)
	{
		DV(&local);
		DV(&local2);
        DV(&vh);
		return;
	}

	F1 = F2 = F3 = F4 = FMen = F5 = 0;
	// memset(buffer, 0x00, 20000);
	for (i = 0; i < 5; i++)
		lck[i] = status[i] = 0;
	SetParameters();
	strcpy(IDT, "i011");
	Pad = MisNum;
	DuraType = FMen = MisType = 0;
	ClrFut(plr, MisNum);
	DrawFuture(plr, MisType, MisNum);
begfut_noredraw:
  
//  for (i=0;i<5;i++) ClearRX(i+1);
	while (1)
	{
		GetMouse();
		if (mousebuttons == 0)
			break;
	}
	while (1)
	{
		GetMouse();

		prev_setting = setting;
		setting = -1;

		if (key == '-' && SEG > 1)
			SEG--;

		if (key == '+' && SEG < 500)
			SEG++;

		if (key >= 65 && key < Bub_Count + 65)
			setting = key - 65;

		for (ii = 0; ii < Bub_Count; ii++)
		{
			if (x >= StepBub[ii].x_cor && x <= StepBub[ii].x_cor + 7
				&& y >= StepBub[ii].y_cor && y <= StepBub[ii].y_cor + 7)
				setting = ii;
		}

		if (setting >= 0)
		{
			if (prev_setting < 0)
				gxGetImage(&local, 18, 186, 183, 194, 0);

			if (prev_setting != setting)
			{
				ShBox(18, 186, 183, 194);
				grSetColor(1);
				MisStep(21, 192, Mev[setting].loc);
			}
		}
		else if (setting < 0 && prev_setting >= 0)
		{
			gxPutImage(&local, gxSET, 18, 186, 0);
		}

		if (Mis.Dur <= V[MisType].E && ((x >= 244 && y >= 5 && x <= 313
					&& y <= 17 && mousebuttons > 0) || key == K_ENTER))
		{
			InBox(244, 5, 313, 17);
			WaitForMouseUp();
			if (key > 0)
				delay(300);
			key = 0;
			OutBox(244, 5, 313, 17);
			gxGetImage(&local2, 74, 3, 250, 199, 0);
			NewType = V[MisType].X;
			Data->P[plr].Future[MisNum].Duration = DuraType;

			Ok = HardCrewAssign(plr, Pad, MisType, NewType);

			gxPutImage(&local2, gxSET, 74, 3, 0);
			// DV(&local2);
			if (Ok == 1)
			{
				Data->P[plr].Future[MisNum].Duration = DuraType;
				goto begfut;	   // return to loop
			}
			else
			{
				ClrFut(plr, MisNum);
				// DuraType = FMen = MisType = 0;
				key = 0;
                goto begfut_noredraw;
				// DrawFuture(plr, MisType, MisNum);
			}
			key = 0;
		};
		// continue

		if ((((x >= 5 && y >= 49 && x <= 53 && y <= 72) || (x >= 43
						&& y >= 74 && x <= 53 && y <= 82))
				&& mousebuttons > 0) || (key == '!' || key == '1'))
		{
			if ((x >= 43 && y >= 74 && x <= 53 && y <= 82) || key == '!')
			{

				lck[0] = abs(lck[0] - 1);
				if (lck[0] == 1)
					InBox(43, 74, 53, 82);
				else
					OutBox(43, 74, 53, 82);
				if (lck[0] == 1)
					F5 = (status[0] == 0) ? -1 : status[0];
				if (lck[0] == 1)
					PlaceRX(1);
				else
					ClearRX(1);
				if (lck[0] == 0)
				{
					F5 = 0;
					status[0] = 0;
				}

				while (1)
				{
					GetMouse();
					if (mousebuttons == 0)
						break;
				}
			}
			else if (lck[0] != 1)
			{
				InBox(5, 49, 53, 72);

				if (DuraType == MaxDur)
					DuraType = 0;
				else
					DuraType++;
				Data->P[plr].Future[MisNum].Duration = DuraType;

				if (DuraType == 0)
					Toggle(5, 0);
				else if (DuraType == 1)
					Toggle(5, 1);
				if (DuraType != 0)
					draw_Pie(DuraType);

				status[0] = DuraType;

				while (1)
				{
					GetMouse();
					if (mousebuttons == 0)
						break;
				}
				grSetColor(34);
				OutBox(5, 49, 53, 72);
			};
			key = 0;
			/* Duration */
		};
		if ((x >= 5 && y >= 74 && x <= 41 && y <= 82 && mousebuttons > 0)
			|| (key == K_ESCAPE))
		{
			InBox(5, 74, 41, 82);
			while (1)
			{
				GetMouse();
				if (mousebuttons == 0)
					break;
			}
			MisType = 0;
			if (DuraType != 0)
				Toggle(5, 0);
			FMen = DuraType = F1 = F2 = F3 = F4 = F5 = 0;
			for (i = 1; i < 4; i++)
				if (status[i] != 0)
					Toggle(i, 1);
			if (JointFlag == 0)
			{
				F4 = 2;
				lck[4] = 1;
				Toggle(4, 1);
				InBox(191, 74, 201, 82);
				PlaceRX(5);
				TogBox(166, 49, 1);
			}
			else
			{
				F4 = 0;
				lck[4] = 0;
				status[4] = 0;
				Toggle(4, 1);
				OutBox(191, 74, 201, 82);
				ClearRX(5);
				TogBox(166, 49, 0);
			};
			for (i = 0; i < 4; i++)
			{
				lck[i] = status[i] = 0;
			}
			OutBox(5, 49, 53, 72);
			OutBox(43, 74, 53, 82);
			TogBox(55, 49, 0);
			OutBox(80, 74, 90, 82);
			TogBox(92, 49, 0);
			OutBox(117, 74, 127, 82);
			TogBox(129, 49, 0);
			OutBox(154, 74, 164, 82);

			ClrFut(plr, MisNum);
			Data->P[plr].Future[MisNum].Duration = 0;
			Missions(plr, 8, 37, MisType, 1);
			GetMinus(plr);
			OutBox(5, 74, 41, 82);
			key = 0;
			/* Reset */
		};
		if ((x >= 55 && y >= 49 && x <= 90 && y <= 82 && mousebuttons > 0)
			|| (key == '2' || key == '@'))
		{
			if ((x >= 80 && y >= 74 && x <= 90 && y <= 82) || (key == '@'))
			{

				if (lck[1] == 0)
					InBox(80, 74, 90, 82);
				else
					OutBox(80, 74, 90, 82);
				lck[1] = abs(lck[1] - 1);
				if (lck[1] == 1)
					PlaceRX(2);
				else
					ClearRX(2);
				if ((status[1] == 0) && (lck[1] == 1))
					F1 = 2;
				else if ((status[1] == 1) && (lck[1] == 1))
					F1 = 1;
				else
					F1 = 0;

				while (1)
				{
					GetMouse();
					if (mousebuttons == 0)
						break;
				}
			}
			else if (lck[1] != 1)
			{

				TogBox(55, 49, 1);
				if (status[1] == 0)
					Toggle(1, 1);
				else
					Toggle(1, 0);
				status[1] = abs(status[1] - 1);

				while (1)
				{
					GetMouse();
					if (mousebuttons == 0)
						break;
				}
				TogBox(55, 49, 0);
			};					   /* Docking */
			key = 0;
		};

		if ((x >= 92 && y >= 49 && x <= 127 && y <= 82 && mousebuttons > 0)
			|| (key == '3' || key == '#'))
		{
			if ((x >= 117 && y >= 74 && x <= 127 && y <= 82) || (key == '#'))
			{

				if (lck[2] == 0)
					InBox(117, 74, 127, 82);
				else
					OutBox(117, 74, 127, 82);
				lck[2] = abs(lck[2] - 1);
				if (lck[2] == 1)
					PlaceRX(3);
				else
					ClearRX(3);
				if ((status[2] == 0) && (lck[2] == 1))
					F2 = 2;
				else if ((status[2] == 1) && (lck[2] == 1))
					F2 = 1;
				else
					F2 = 0;

				while (1)
				{
					GetMouse();
					if (mousebuttons == 0)
						break;
				}
			}
			else if (lck[2] != 1)
			{

				TogBox(92, 49, 1);
				if (status[2] == 0)
					Toggle(2, 1);
				else
				{
					Toggle(2, 0);
				};
				status[2] = abs(status[2] - 1);

				while (1)
				{
					GetMouse();
					if (mousebuttons == 0)
						break;
				}
				TogBox(92, 49, 0);
			};					   /* EVA */
			key = 0;
		};

		if ((x >= 129 && y >= 49 && x <= 164 && y <= 82 && mousebuttons > 0)
			|| (key == '4' || key == '$'))
		{
			if ((x >= 154 && y >= 74 && x <= 164 && y <= 82) || (key == '$'))
			{

				if (lck[3] == 0)
					InBox(154, 74, 164, 82);
				else
					OutBox(154, 74, 164, 82);
				lck[3] = abs(lck[3] - 1);	// F3=lck[3];
				if (lck[3] == 1)
					PlaceRX(4);
				else
					ClearRX(4);
				if ((status[3] == 0) && (lck[3] == 1))
					F3 = 2;
				else if ((status[3] == 1) && (lck[3] == 1))
					F3 = 1;
				else
					F3 = 0;

				while (1)
				{
					GetMouse();
					if (mousebuttons == 0)
						break;
				}
			}
			else if (lck[3] != 1)
			{

				TogBox(129, 49, 1);
				if (status[3] == 0)
					Toggle(3, 1);
				else
				{
					Toggle(3, 0);
				};
				status[3] = abs(status[3] - 1);

				while (1)
				{
					GetMouse();
					if (mousebuttons == 0)
						break;
				}
				TogBox(129, 49, 0);
			};					   /* LEM */
			key = 0;
		};
		if (((x >= 166 && y >= 49 && x <= 201 && y <= 82 && mousebuttons > 0)
				|| (key == '5' || key == '%')) && (JointFlag == 1))
		{
			if ((x > 191 && y >= 74 && x <= 201 && y <= 82) || (key == '%'))
			{

				if (lck[4] == 0)
					InBox(191, 74, 201, 82);
				else
					OutBox(191, 74, 201, 82);
				lck[4] = abs(lck[4] - 1);
				if (lck[4] == 1)
					PlaceRX(5);
				else
					ClearRX(5);

				if ((status[4] == 0) && (lck[4] == 1))
					F4 = 2;
				else if ((status[4] == 1) && (lck[4] == 1))
					F4 = 1;
				else
					F4 = 0;

				while (1)
				{
					GetMouse();
					if (mousebuttons == 0)
						break;
				}
			}
			else if (lck[4] != 1)
			{

				TogBox(166, 49, 1);

				status[4] = abs(status[4] - 1);
				if (status[4] == 0)
				{
					Toggle(4, 1);
				}
				else
				{
					Toggle(4, 0);
				}

				while (1)
				{
					GetMouse();
					if (mousebuttons == 0)
						break;
				}
				TogBox(166, 49, 0);
			};					   /* Joint Launch */
			key = 0;
		};
		if ((x >= 5 && y >= 84 && x <= 16 && y <= 130 && mousebuttons > 0)
			|| (key == UP_ARROW))
		{
			InBox(5, 84, 16, 130);
			for (i = 0; i < 50; i++)
			{
				key = 0;
				GetMouse();
				delay(10);
				if (mousebuttons == 0)
				{
					MisType = UpSearchRout(MisType, plr);
					Data->P[plr].Future[MisNum].MissionCode = MisType;
					i = 51;
				}
			}
			while (mousebuttons == 1 || key == UP_ARROW)
			{
				MisType = UpSearchRout(MisType, plr);
				Data->P[plr].Future[MisNum].MissionCode = MisType;
				Missions(plr, 8, 37, MisType, 3);
				DuraType = status[0];
				delay(100);
				key = 0;
				GetMouse();
			}
            Missions(plr, 8, 37, MisType, 3);
			DuraType = status[0];
			OutBox(5, 84, 16, 130);
			key = 0;
			/* Mission Type plus */
		};
		if ((x >= 5 && y >= 132 && x < 16 && y <= 146 && mousebuttons > 0)
			|| (key == K_SPACE))
		{
			InBox(5, 132, 16, 146);
			WaitForMouseUp();
			delay(50);
  		    MisType = Data->P[plr].Future[MisNum].MissionCode;
  		    assert(0 <= MisType);
			if (MisType != 0){
                Missions(plr, 8, 37, MisType, 1);
			}
			else{
                Missions(plr, 8, 37, MisType, 3);
			}
			OutBox(5, 132, 16, 146);
			key = 0;
		}
		if ((x >= 5 && y >= 148 && x <= 16 && y <= 194 && mousebuttons > 0)
			|| (key == DN_ARROW))
		{
			InBox(5, 148, 16, 194);
			for (i = 0; i < 50; i++)
			{
				key = 0;
				GetMouse();
				delay(10);
				if (mousebuttons == 0)
				{
					MisType = DownSearchRout(MisType, plr);
					Data->P[plr].Future[MisNum].MissionCode = MisType;
					i = 51;
				}
				key = 0;
			}
			while (mousebuttons == 1 || key == DN_ARROW)
			{
				MisType = DownSearchRout(MisType, plr);
				Data->P[plr].Future[MisNum].MissionCode = MisType;
                Missions(plr, 8, 37, MisType, 3);
				DuraType = status[0];
				delay(100);
				key = 0;
				GetMouse();
			}
            Missions(plr, 8, 37, MisType, 3);
			DuraType = status[0];
			OutBox(5, 148, 16, 194);
			key = 0;
			/* Mission Type minus */

		};
	}							   // while
  TRACE1("<-Future()");
}
Esempio n. 30
0
void CodeGenFunction::EmitSavedVarInitializers(const DeclContext *DC) {
  VarInitEmitter DV(*this, true);
  DV.Visit(DC);
}