Exemple #1
0
void search_cycle(CA *ca, char *graph, UINT starting_state)
{
  UINT actual_state = starting_state;
  int is_new_cycle = 0;

  while (!flags_test(graph, actual_state, STATE_HAS_BEEN_VISITED))
  {
    flags_set(graph, actual_state, STATE_HAS_BEEN_VISITED | STATE_IS_BEING_VISITED);
    actual_state = next_state(ca, actual_state);
  }

  is_new_cycle = flags_test(graph, actual_state, STATE_IS_BEING_VISITED);

  if (is_new_cycle)
  {
    UINT cycle_len = 0;

    while (flags_test(graph, actual_state, STATE_IS_BEING_VISITED))
    {
      flags_unset(graph, actual_state, STATE_IS_BEING_VISITED);

      actual_state = next_state(ca, actual_state);

      cycle_len ++;
    }

    /* printf("len %u seed %u start %u ", cycle_len, actual_state, starting_state); */
    printf("%" UFM  "\n", cycle_len);
    fflush(stdout);
  }

  for  (actual_state = starting_state;
        flags_test(graph, actual_state, STATE_IS_BEING_VISITED);
        actual_state = next_state(ca, actual_state))
  {
     flags_unset(graph, actual_state, STATE_IS_BEING_VISITED);
  }
}
Exemple #2
0
int
main(int argc, char *argv[])
{
  UINT i;

  unsigned int N;
  UINT NSTATES;

  unsigned int rule;
  CA *ca;

  char *graph;

  if (argc != 3)
  {
    fprintf(stderr, "usage: %s rule ca-size\n", PROGRAM_NAME);
    exit(EXIT_FAILURE);
  }

  sscanf(argv[1], "%u", &rule);

  sscanf(argv[2], "%u", &N);

  if (DEBUG)
    fprintf(stderr, "rule %u\nN=%u\n", rule, N);

  ca = ca_create(N, rule);

  NSTATES =  2;
  NSTATES <<= (N - 1);

  graph = create_graph(NSTATES);

  for (i = 0; i < NSTATES; ++i)
    flags_unset(graph, i, STATE_ALL_SET_MASK);

  for (i = 0; i < NSTATES; ++i)
    if (!flags_test(graph, i, STATE_HAS_BEEN_VISITED))
      search_cycle(ca, graph, i);

  free_graph(graph);
  ca_destroy(ca);

  return EXIT_SUCCESS;
}
Exemple #3
0
/** Unsets an individual flag on the widget. */
int bbwidget_unflag(BBWidget * self, int flag) {
  register int wflags = self->flags;
  return flags_unset(&self->flags, flag);
}
Exemple #4
0
/** Sets or unsets an individual flag on the self. 
If set is true the flag is set, if false it's unset. */
int flags_put(int * self, int flag, int set) {
  if (set) { return flags_set(self, flag); }
  else { return flags_unset(self, flag); }
}
Exemple #5
0
/** Unsets an individual flag on the Camera. */
int camera_unsetflag(Camera * self, int flag) {
  register int wflags = self->flags;
  return flags_unset(&self->flags, flag);
}
Exemple #6
0
/** Unsets an individual flag on the Thing. */
int thing_unsetflag(Thing * self, int flag) {
  register int wflags = self->flags;
  return flags_unset(&self->flags, flag);
}