예제 #1
0
파일: mc_worker.c 프로젝트: lmntal/slim
static void workers_gen(LmnWorkerGroup *owner,
                        unsigned int   worker_num,
                        AutomataRef       a,
                        Vector         *psyms,
                        BOOL           flags)
{
  unsigned int i;
  owner->workers = LMN_NALLOC(LmnWorker *, worker_num);
  for (i = 0; i < worker_num; i++) {
    LmnWorker *w;
    StateSpaceRef states;

    if (i == 0) {
      states = worker_num > 1 ? statespace_make_for_parallel(worker_num, a, psyms)
                              : statespace_make(a, psyms);
    } else {
      states = worker_states(workers_get_worker(owner, 0));
    }

    w = lmn_worker_make(states, i, flags);
    owner->workers[i] = w;
    w->group = owner;

    if (owner->do_search) {
      w->invalid_seeds = vec_make(4);
      w->cycles = vec_make(4);
    }

    /* アルゴリズムの割り当てと初期化 */
    worker_set_env(w);
    worker_init(w);
  }
}
예제 #2
0
/* Evaluate the Maclaurin series of the direction differential equation
 * to a given order. This also computes the integral of the direction
 * series over the time interval to compute the Maclaurin series for the
 * velocity, and integrates that over the time interval to compute the
 * Maclaurin series for the position.
 *
 *  t       The time at which to evaluate the polynomial
 *  n       The number of terms to evaluate
 *  d       The initial direction
 *  v       The initial velocity
 *  p       The initial position
 *  l       The left thrust
 *  r       The right thrust
 *  omega   The initial angular velocity
 *  mass    The mass of the object
 *  radius  The radius of the object
 *  d_out   The variable to receive the final direction
 *  v_out   The variable to receive the final velocity
 *  p_out   The variable to receive the final position
 */
static void maclaurin(double t, int n, vec_t d, vec_t v, vec_t p, double l,
        double r, double omega, double mass, double radius, vec_t *d_out,
        vec_t *v_out, vec_t *p_out)
{
    static double a[30], b[30]; /* max 30 terms */
    vec_t dd, dv, dp;
    int i;

    a[0] = d.x;         b[0] = d.y;
    a[1] = -b[0]*omega; b[1] = a[0]*omega;
    for (i = 2; i < n; i++) {
        a[i] = (-b[i-1] / i * omega - b[i-2] / (i-1) * 2*(l-r)/(mass * radius));
        b[i] = ( a[i-1] / i * omega + a[i-2] / (i-1) * 2*(l-r)/(mass * radius));
    }

    dd = vec_make(0, 0);
    dv = vec_make(0, 0);
    dp = vec_make(0, 0);
    for (i = n-1; i >= 0; i--) {
        /* Add term to direction */
        dd.x = dd.x * t + a[i];
        dd.y = dd.y * t + b[i];

        /* Add term to velocity */
        dv.x = dv.x * t + a[i] / (i+1);
        dv.y = dv.y * t + b[i] / (i+1);

        /* Add term to position */
        dp.x = dp.x * t + a[i] / ((i+1)*(i+2));
        dp.y = dp.y * t + b[i] / ((i+1)*(i+2));
    }

    /* Correct velocity */
    dv = vec_scale(t * (l+r)/mass, dv);
    /* Correct position */
    dp = vec_scale(t*t, dp);

    *d_out = dd;
    *v_out = vec_add(v, dv);
    *p_out = vec_add(vec_add(vec_scale(t, v), p), dp);
}
예제 #3
0
파일: translate.c 프로젝트: onmsr/slim
static void translate_rule(LmnRule rule, const char *header)
{
  Vector *jump_points = vec_make(4);
  int i;

  vec_push(jump_points, (LmnWord)lmn_rule_get_inst_seq(rule));

  for (i = 0; i < vec_num(jump_points) /*変換中にjump_pointsは増えていく*/; i++){
    BYTE *p = (BYTE*)vec_get(jump_points, i);
    fprintf(OUT, "BOOL %s_%d(LmnReactCxt* rc, LmnMembrane* thisisrootmembutnotused, LmnRule rule)\n", header, i); /* TODO m=wt[0]なのでmは多分いらない */
    fprintf(OUT, "{\n");
    /* (変換するスタート地点, 変換する必要のある部分の記録, ルールのシグネチャ:trans_**_**_**, 成功時コード, 失敗時コード, インデント) */
    translate_instructions(p, jump_points, header, "return TRUE", "return FALSE", 1);
    fprintf(OUT, "}\n");
  }

  /* 各関数の前方宣言をすることができないので,関数を呼ぶ時には自分で前方宣言をする */
  /* trans_***(); ではなく { extern trans_***(); trans_***(); } と書くだけ */
}
예제 #4
0
파일: integer.c 프로젝트: onmsr/slim
/**
 * ($start, $end, $g)
 * where
 *  start, end = integer
 *  g = ground
 *
 * Creates a (multi)set $g[$a], $g[$a+1], ..., $g[$b].
 */
void integer_set(LmnReactCxt *rc,
                 LmnMembrane *mem,
                 LmnAtom a0, LmnLinkAttr t0,
                 LmnAtom a1, LmnLinkAttr t1,
                 LmnAtom a2, LmnLinkAttr t2)
{
  Vector *srcvec;
  int i, j, n;
  int start, end;

  start  = (int)a0;
  end    = (int)a1;
  srcvec = vec_make(16);
  vec_push(srcvec, (LmnWord)LinkObj_make(a2, t2));

  for (i = 0, n = start; n <= end; i++, n++) {
    Vector *dstlovec;
    ProcessTbl atommap;
    LinkObj l;

    lmn_mem_copy_ground(mem, srcvec, &dstlovec, &atommap);

    l = (LinkObj)vec_get(dstlovec, 0);
    lmn_mem_newlink(mem, n, LMN_INT_ATTR, 0,
                    l->ap, t2, LMN_ATTR_GET_VALUE(l->pos));
    lmn_mem_push_atom(mem, n, LMN_INT_ATTR);

    for (j = 0; j < vec_num(dstlovec); j++) LMN_FREE(vec_get(dstlovec, j));
    vec_free(dstlovec);
    proc_tbl_free(atommap);
  }

  lmn_mem_delete_atom(mem, a0, t0);
  lmn_mem_delete_atom(mem, a1, t1);

  lmn_mem_delete_ground(mem, srcvec);

  for (i = 0; i < vec_num(srcvec); i++) LMN_FREE(vec_get(srcvec, i));
  vec_free(srcvec);
}
예제 #5
0
파일: memstack.c 프로젝트: ysm001/slim
inline LmnMemStack lmn_memstack_make()
{
  return vec_make(64);
}
예제 #6
0
파일: special_atom.c 프로젝트: lmntal/slim
void sp_atom_init()
{
  sp_atom_callback_tbl = vec_make(64);
}