Ejemplo n.º 1
0
void simulation (int numOfTellers) {
    printf("\nSimulation started with %d tellers:\n", numOfTellers);
    Queue waitline;
    initialize(&waitline);
    initializeStats();
    int x, time, data[100];
    double tellers[numOfTellers];
    readArrivingCustData(data);

    // Main simulation loop that iterates through a day by the minute
    for (time = 1; time < WORK_DAY; time++) {
        //Add arriving customers
        int a = arrivingCustomers(data);
        updateNumCustServed(a);
        for (a = a; a > 0; a--)
            push(time, &waitline);
        // Loop through the tellers and update wait and assign customers
        for (x = 0; x < numOfTellers; x++)
            // If a teller is not busy and there are people waiting, service them
            if((tellers[x] < 0 || (tellers[x] -=1.0) < 0) && !empty(&waitline)) {
                int arTime = pop(&waitline);
                updateCustWaitTime(((double)(time-arTime))-tellers[x]);
                tellers[x] += expdist(AVG_SERVICE);
            }
        updateWaitLine(waitline.cnt);
    }
    // Simulation is done, print the statistics for the session
    printStats();
}
Ejemplo n.º 2
0
frequent_species pick_appropriate_frequent_species(
  list *sp_list,
  block substrate,
  ptrdiff_t seed
) {
  float weight;
  float total_weight = 0;
  float choice;
  float rare_smoothing;
  size_t i;
  frequent_species fqsp = 0;
  list *weights = create_list();

  if (l_is_empty(sp_list)) {
    // Return an invalid species...
    frequent_species_set_species_type(&fqsp, SPT_NO_SPECIES);
    frequent_species_set_species(&fqsp, SP_INVALID);
    frequent_species_set_frequency(&fqsp, 0.0);
    return fqsp;
  }

  rare_smoothing = expdist(ptrf(seed + 31376), BIO_RARE_SPECIES_SMOOTHING_EXP);
  rare_smoothing *= BIO_RARE_SPECIES_SMOOTHING_ADJUST;

  for (i = 0; i < l_get_length(sp_list); ++i) {
    fqsp = (frequent_species) l_get_item(sp_list, i);
    weight = (
      species_compatability(fqsp, substrate)
    * frequent_species_frequency(fqsp)
    ) + rare_smoothing;
    l_append_element(weights, f_as_p(weight));
    total_weight += weight;
  }

  choice = ptrf(prng(seed + 866859)) * total_weight;

  for (i = 0; i < l_get_length(sp_list); ++i) {
    fqsp = (frequent_species) l_get_item(sp_list, i);
    choice -= p_as_f(l_get_item(weights, i));
    if (choice < 0) {
      cleanup_list(weights);
      return fqsp;
    }
  }
  cleanup_list(weights);
#ifdef DEBUG
  printf("Error: Ran out of appropriate species to pick from!\n");
  exit(EXIT_FAILURE);
#endif
  // Just arbitrarily return the first item (this shouldn't be reachable):
  return (frequent_species) l_get_item(sp_list, 0);
}
Ejemplo n.º 3
0
void add_ridges_to_sheet(
  tectonic_sheet *ts,
  float strength,
  float scale,
  float dstr,
  float dscale,
  float mscale,
  ptrdiff_t seed,
  ptrdiff_t mseed
) {
  size_t i, j, idx;
  size_t pw, ph;
  float fx, fy;
  float mx, my;
  float xphase, yphase;
  float modulation;
  float ignore;
  vector *p;
  ptrdiff_t dxseed, dyseed;

  dxseed = prng(seed + 13392);
  dyseed = prng(dxseed);

  pw = sheet_pwidth(ts);
  ph = sheet_pwidth(ts);

  seed = prng(seed + 5448);
  xphase = ptrf(seed);
  seed = prng(seed + 88166);
  yphase = ptrf(seed);

  // Only pass: add ridge height
  for (i = 0; i < pw; ++i) {
    for (j = 0; j < ph; ++j) {
      idx = sheet_pidx(ts, i, j);
      p = &(ts->points[idx]);
      fx = p->x;
      fy = p->y;
      mx = p->x;
      my = p->y;

      // distortion
      fx += dstr * sxnoise_2d(
        p->x * dscale,
        p->y * dscale,
        dxseed
      );
      fy += dstr * sxnoise_2d(
        p->x * dscale,
        p->y * dscale,
        dyseed
      );

      // scaling:
      fx *= scale;
      fy *= scale;
      mx *= mscale;
      my *= mscale;

      // phase offset:
      fx += xphase;
      fy += yphase;

      // modulation:
      modulation = sxnoise_2d(mx, my, mseed);
      modulation = 0.5 * (1 + modulation);
      modulation = strict_sigmoid(modulation, TECT_RMOD_SIGSHAPE);
      modulation = expdist(modulation, TECT_RMOD_EXPSHAPE);

      // worley ridges:
      p->z += strength * modulation * wrnoise_2d_fancy(
        fx, fy,
        seed,
        0, 0,
        &ignore, &ignore,
        0
      );
    }
  }
}