Ejemplo n.º 1
0
int count_total_edges( link *graph_base, int graph_base_size)
{
  int i, total_edges;
  for( total_edges = 0, i = 1; i <= graph_base_size; i++)
    total_edges += count_edges( graph_base[i]);

  return total_edges;
}
Ejemplo n.º 2
0
str_grid_edge_data_t* str_grid_edge_data_with_buffer(str_grid_t* grid, 
                                                     int num_components,
                                                     void* buffer)
{
  ASSERT(num_components > 0);

  // Allocate storage.
  int num_patches = 3 * str_grid_num_patches(grid);
  size_t patches_size = sizeof(str_grid_patch_t*) * num_patches;
  size_t edge_data_size = sizeof(str_grid_edge_data_t) + patches_size;
  str_grid_edge_data_t* edge_data = polymec_malloc(edge_data_size);
  edge_data->grid = grid;
  edge_data->nc = num_components;

  str_grid_get_extents(grid, &edge_data->nx, &edge_data->ny, &edge_data->nz);
  edge_data->x_patches = int_ptr_unordered_map_new();
  edge_data->y_patches = int_ptr_unordered_map_new();
  edge_data->z_patches = int_ptr_unordered_map_new();
  edge_data->patch_offsets = polymec_malloc(sizeof(int) * (3*num_patches+1));
  edge_data->buffer = NULL;

  // Now populate the patches for x-, y-, and z-edges.
  int px, py, pz;
  str_grid_get_patch_size(grid, &px, &py, &pz);
  edge_data->patch_lx = 1.0 / edge_data->nx;
  edge_data->patch_ly = 1.0 / edge_data->ny;
  edge_data->patch_lz = 1.0 / edge_data->nz;
  int pos = 0, i, j, k;
  while (str_grid_next_patch(grid, &pos, &i, &j, &k))
  {
    int index = patch_index(edge_data, i, j, k);

    int_ptr_unordered_map_insert_with_v_dtor(edge_data->x_patches, index, 
                                             str_grid_patch_with_buffer(px+1, py, pz, num_components, 0, NULL),
                                             DTOR(str_grid_patch_free));

    int_ptr_unordered_map_insert_with_v_dtor(edge_data->y_patches, index, 
                                             str_grid_patch_with_buffer(px, py+1, pz, num_components, 0, NULL),
                                             DTOR(str_grid_patch_free));

    int_ptr_unordered_map_insert_with_v_dtor(edge_data->z_patches, index, 
                                             str_grid_patch_with_buffer(px, py, pz+1, num_components, 0, NULL),
                                             DTOR(str_grid_patch_free));
  }
  count_edges(edge_data);

  // Set the buffer.
  str_grid_edge_data_set_buffer(edge_data, buffer, false);

  return edge_data;
}
Ejemplo n.º 3
0
void print_vertices_degree( link *graph_base, int graph_base_size)
{
  int i, j, n;
  printf( "Outdegree os vertices:\t\t\tIndegree os vertices:\n");
  for( i = 1; i <= graph_base_size; i++)
  {
    /* Outdegree: */
    printf( "\tdeg+(%3d) = %d", i, count_edges( graph_base[i]));

    printf( "\t\t\t");
    /* Indegree: */
    for( n = 0, j = 1; j <= graph_base_size; j++)
      n += search( graph_base[j], i);

    printf( "\tdeg-(%3d) = %d\n", i, n);
  }
}
Ejemplo n.º 4
0
	void Best::localSearch(
		const std::vector<Graph> &graphs,
		Solution &solution
	) {
		size_t m = solution.alignment.size1();
		size_t n = solution.alignment.size2();

		// Create reverse alignment mapping
		std::vector<std::vector<size_t>> map;
		create_map(graphs, solution, map);

		// Count number of graphs each edge is covered in
		edge_count_matrix edges;
		count_edges(graphs, map, solution, edges);

		// Build neighbor lists
		std::vector<neighbor_list> neighbors;
		create_neighbor_lists(graphs, map, solution, neighbors);

		// Active index map
		std::vector<int> active(m, 0);

		std::random_device rd;
		std::minstd_rand rand_gen(rd());

		int iteration = 0;
		bool repeat;

		do {
			repeat = false;

			for(size_t g = 0; g < n-1; ++g) {
				int best_delta = 0;
				size_t best_i = 0;
				size_t best_j = 0;

				#pragma omp parallel
				{
					int prv_best_delta = 0;
					size_t prv_best_i = 0;
					size_t prv_best_j = 0;

					#pragma omp for schedule(static, 1)
					for(size_t i = 0; i < m; ++i) {
						for(size_t j = i+1; j < m; ++j) {
							if(active[i] < iteration && active[j] < iteration) continue;

							int delta = get_delta(i, j, g, neighbors, edges);

							if(delta > 0) {
								active[i] = iteration+1;
								active[j] = iteration+1;
							}

							if(delta > prv_best_delta) {
								prv_best_delta = delta;
								prv_best_i = i;
								prv_best_j = j;
							}
						}
					}

					#pragma omp critical
					{
						if(prv_best_delta > best_delta) {
							best_delta = prv_best_delta;
							best_i = prv_best_i;
							best_j = prv_best_j;
						}
					}
				}

				if(best_delta > 0) {
					repeat = true;
					swap(best_i, best_j, g, iteration, neighbors, edges, solution, active);
				}
			}

			iteration++;
		} while(repeat);

		// Extract LCS and solution quality
		finalize(edges, solution);
	}
Ejemplo n.º 5
0
Archivo: main.c Proyecto: bernied/mutti
int
main(int argc, char** argv)
{
  int result;
  struct stat sb;
  char* file_name;
  char name[100] = "permutation";
  int len = strlen(name);
  uint32* histogram =NULL;
  uint32 gs, hgs;

  // Handle arguments
  convert_card_permutation(args.u, args.i); // LAMb: calculate hi/low from args!
  file_name = handle_arguments(argc, argv, &args);

  int size = args.s;
  uint32* permutation;
  uint32* graph = alloc_graph(size);
  gs = GRAPH_SIZE(size);
  hgs = gs + 1;

  if (args.i || args.a) {
    histogram = (uint32*) calloc(hgs, sizeof(uint32));
  }

  if (args.p)
  {
    permutation = alloc_permutation(size, false);
    str_to_permutation(args.p, permutation, false);
    if (args._2)
    {
      uint32* p2 = alloc_permutation(size, false);
      str_to_permutation(args._2, p2, false);
      apply_permutation(p2, permutation);
      free(p2);
    }

    map_perm_to_graph(permutation, graph);
    if (args.d) {
      graph_to_dot(graph, permutation, name, args.c, args.e);
    }
    if (histogram) {
      count_edges(graph, histogram, size);
    }
  }
  else if (args.l <= 0)
  {
    if (size > 7) {
      error("Can not generate more then 7! files.");
    }
    permutation = alloc_permutation(size, true);
    uint32 numPerms = factorial(size);
    for (int i=0; i < numPerms; i++)
    {
      map_perm_to_graph(permutation, graph);
      if (args.d) {
        graph_to_dot(graph, permutation, make_name(name, i), args.c, args.e);
      }
      if (histogram) {
        count_edges(graph, histogram, size);
      }
      name[len] = '\0';
      lex_permute(permutation+1, size);
    }
  }
  else
  {
    permutation = alloc_permutation(size, true);
    uint32 numPerms = factorial(size);
    for (int i=0; i < numPerms; i++)
    {
      if (i == args.l)
      {
        map_perm_to_graph(permutation, graph);
        if (args.d) {
          graph_to_dot(graph, permutation, make_name(name, i), args.c, args.e);
        }
        name[len] = '\0';
        break;
      }
      lex_permute(permutation+1, size);
    }
  }

  if (args.i)
  {
    for (int i=0; i < hgs; i++) {
      printf("%i\t", i);
    }
    printf("\n");
    for (int i=0; i < hgs; i++) {
      printf("%i\t", histogram[i]);
    }
    printf("\n");
  }

  if (args.a)
  {
    uint64 sum =0, count =0;
    for (int i=0; i < hgs; i++) {
      sum += histogram[i] * i;
      count += histogram[i];
    }
    double d = sum / (double) count;
    printf("average: %llu, %llu, %f\n", sum, count, d);
  }

  if (histogram) free(histogram);
  free(permutation);
  free(graph);
  exit(result);
}