示例#1
0
void create_table(cube *(*construct_cube)(cube*),
                      hash_cube_t (*hash_cube)(cube*),
                      cube *(*reconstruct_stickers)(hash_cube_t*),
                      int total_count
                      ) {
  hash_set_t hash_set = new_hash_set(hash_cube_index, hash_cube_equals);
  queue q = new_queue();

  cube *c0 = construct_cube(init_cube());
  hash_cube_t h0 = hash_cube(c0);
  delete_cube(c0);

  enqueue(&q, h0);
  insert(&hash_set, &h0);

  int count = 0;
  int depth = 0;
  while (queue_size(&q) != 0) {
    int n = queue_size(&q);
    for (int i = 0; i < n; ++i) {
      ++count;
      if (count % 1000 == 0) {
        fprintf(stderr, "%f\n", (float) count / total_count);
      }

      hash_cube_t val = dequeue(&q);
      cube *c1 = reconstruct_stickers(&val);
      print_cube_flat(c1);
      printf(",%d\n", depth);

      for (int i = 0; i < 18; ++i) {
        cube *c2 = cube_expand[i](c1);
        hash_cube_t h1 = hash_cube(c2);
        if (!contains(&hash_set, &h1)) {
          enqueue(&q, h1);
          insert(&hash_set, &h1);
        }
        delete_cube(c2);
      }
      delete_cube(c1);
    }
    ++depth;
  }

  free_queue(&q);
  free_hash_set(&hash_set);
}
示例#2
0
main()
#endif
{
	FILE			*fp = stdin;	  /* File pointer, default stdin */
	CRITICALS		*tuples, *lower_dim_tuples;
	int				i, temp;
	BOUNDARY		**boundary;
	CUBE			*cube;
	int				n, num_rows, num_cols;
	MATRIX			matrix, tmatrix;

	printf("\ncmat - version %1.2f\n\n", VERSION_NUM);

#ifndef NO_CMD_LINE
	/* Check the command line and open file if required */
	command_line(&fp,argc, argv, &n);
#else
	/* Read command info from standard input */
	command_input(&fp, &n);
#endif

	/* Read in info from the file, setting up Fsa and so on... */
	switch (read_file_info(fp)) {
		case FORMAT_ERROR:
			ERROR(FORMAT);
		case NOT_A_GEN:
			ERROR(GEN_ERR);
	}
	fclose(fp);	/* No more reading required */

	tuples = find_n_criticals(n);
	/* remove_inverse_criticals(&tuples);  We are ignoring inverse tuples */

	/* Calc boundaries and store in an array */
	boundary = NEW(BOUNDARY *, tuples->num);

	for (i = 0; i < tuples->num; i++) {
		boundary[i] = calc_bound(cube =
					create_n_cube(tuples->info[i]->word,
					tuples->info[i]->vert, n), TRIVIAL | RETAIN_INV_TUPLES);
					/* We are ignoring inverse tuples */
		delete_cube(cube);
	}

	lower_dim_tuples = find_n_criticals(n-1);
	/* remove_inverse_criticals(&lower_dim_tuples);  Ignoring inverse tuples */

	num_rows = tuples->num;
	/* Create the matrix */
	matrix = make_matrix_n(boundary, lower_dim_tuples, &num_rows);
	num_cols = lower_dim_tuples->num;

	/* It is often useful to have rows and columns the other way */
	/* Get transpose, and swap rows and cols */
	tmatrix = transpose(matrix, num_cols, num_rows);
	temp = num_rows;
	num_rows = num_cols;
	num_cols = temp;

	/* Display....for now */
	printf("\nMatrix: rows = %d, cols = %d\n\n", num_rows, num_cols);
	show_matrix(stdout, tmatrix, num_cols, num_rows, 20);

	/*printf("\nMatrix after Gaussian Elimination...\n");
	gaussian_elim(matrix, num_cols, num_rows);
	show_matrix(stdout, matrix, num_cols, num_rows);

	rank_criticals_n = count_non_zero_rows(matrix, num_cols, num_rows);*/

	/* Clean up */
	for (i=0; i < tuples->num - Num_gens; i++)
	delete_boundary(boundary[i]);
	free(boundary);
	delete_criticals(tuples);
	delete_criticals(lower_dim_tuples);
	
	delete_matrix(matrix, num_cols);
	delete_matrix(tmatrix, num_rows);

	return 0;
}