Beispiel #1
0
int main(int argc, char* argv[]) {

  if (argc == 5) {

    double prob = atof(argv[2]);
    int size = atoi(argv[1]);
    long int seed = atol(argv[3]);

    srand(seed);
    graph* g = create_graph(size, prob);
    print_graph(g);
  }
  else if (argc == 4) {
    char filename[50];
    sprintf(filename, "%s.gra", argv[2]);
    graph* g = graph_from_file(filename, atoi(argv[3]));
    sprintf(filename, "%s.dot", argv[2]);
    graph_to_dot(g, filename);
  } 
  else if (argc == 3) {
    double prob = atof(argv[2]);
    int size = atoi(argv[1]);

    srand(time(NULL));
    graph* g = create_graph(size, prob);
    print_graph(g);
  } else if (argc == 2) {
    printf("%lu", time(NULL));
  } else {

    puts("usage: \t print <graphname> <size> prints dot version");
    puts("\t <size> <prob> makes new graph");
  } 

  
  return 0;
}
Beispiel #2
0
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);
}
string_vec graph_to_dot::to_string_vector(abstract_graph_sptr g, bool skip_index_node)
{
    return graph_to_dot(g).graph_to_string_vector(skip_index_node);
}