Ejemplo n.º 1
0
// The ctor should read, parse, and build the graph from the given fileName
Graph::Graph(std::string fileName)
{
	// complete me
	G = new int[SIZE][SIZE];
	P = new int[SIZE][COL];

	fillG();


	file_to_graph(fileName);

	//printG();
	//printV();

	//MyshortestPath(1);
}
Ejemplo n.º 2
0
Archivo: main.c Proyecto: hvarg/Memoria
int main(int argc, const char * args[])
{
  if (argc < 2) {
    printf("Modo de uso: ./centrality archivo.sg [#threads]\n");
    printf("Si #threads es menor a 1 no se calculara la intermediacion.\n");
    return EXIT_SUCCESS;
  }
  char  *filename = (char*) args[1]; 
  printf("File: %s\n", filename);
  int   NT = (argc > 2) ? atoi(args[2]) : 4,
        i, j, gap;
  float *BC;
  struct data  **D;
  struct p_th  *P;

  if ( (G = file_to_graph(filename)) == NULL) 
    return EXIT_FAILURE;
  if (NT > 1) {
    printf("Threads: %d\n", NT);
    gap = (G->size%NT == 0) ? G->size/NT : (G->size/NT)+1;
    BC  = (float*) malloc(sizeof(float) * G->size);
    D   = (struct data**) malloc(sizeof(struct data*)*NT);
    P   = pth_create(NT);

    for (i = 0; i < NT; i++) {
      D[i] = (struct data*) malloc(sizeof(struct data));
      D[i]->init = i*gap;
      D[i]->end  = (i+1)*gap;
      D[i]->bc   = (float*) malloc(sizeof(float) * G->size);
    }

    for (i = 0; i < NT; i++) {
      pth_send_job(P, __cent, D[i]);
    }
    pth_wait(P);

    for (i = 0; i < G->size; i++) { //se puede acumular todo en el primero.
      BC[i] = 0.0;
      for (j = 0; j < NT; j++) {
        BC[i] += D[j]->bc[i];
      }
    }
    pth_del(P);
    for (i = 0; i < NT; i++) {
      free(D[i]->bc);
      free(D[i]);
    }
    free(D);
  } else if (NT == 1) {
    printf("Threads: Single core\n");
    BC = betweenness_centrality(G);
  } else {
    printf("Calculando solo centralidad de grado.\n");
    BC = (float *) calloc(G->size, sizeof(float));
  }

  /* Guardando los resultados en archivos. */
  short fn_size = strlen(filename);
  char *bc_out  = (char *) malloc(sizeof(char) * (fn_size + 11)),
       *idc_out = (char *) malloc(sizeof(char) * (fn_size + 12)),
       *odc_out = (char *) malloc(sizeof(char) * (fn_size + 12));
  strcpy(bc_out, filename);
  strcpy(idc_out, filename);
  strcpy(odc_out, filename);
  strcat(bc_out, ".bc.result");
  strcat(idc_out, ".idc.result");
  strcat(odc_out, ".odc.result");
  FILE *fbc = fopen(bc_out, "w"),
       *fidc = fopen(idc_out, "w"),
       *fodc = fopen(odc_out, "w");
  for (i=0; i< G->size; i++){
    fprintf(fbc,"%d: %f\n", i, BC[i]);
    fprintf(fidc,"%d: %d\n", i, IDC[i]);
    fprintf(fodc,"%d: %d\n", i, ODC[i]);
  }
  fclose(fbc);
  fclose(fidc);
  fclose(fodc);
  free(bc_out);
  free(idc_out);
  free(odc_out);

  graph_del(G);
  free(BC);
  free(IDC);
  free(ODC);
  return EXIT_SUCCESS;
}