示例#1
0
inline std::map<std::string, typename boost::graph_traits<Graph>::vertex_descriptor>
read_graph(Graph& g, InputStream& is)
{
    typedef typename boost::graph_traits<Graph>::vertex_descriptor Vertex;
    typedef boost::null_property_map<Vertex, std::string> NameMap;
    return read_graph(g, NameMap(), is);
}
int main(int argc,char *argv[])
{
  read_graph(argv[1]);

  printf("Main print\n");
  print_graph();

  
  int smallestOutDegree = smallestOutDegreeSearch(getAllNodeIndexs());
  char *name = mygraph->table[smallestOutDegree].name;
  
  int largestOutDegree = largestOutDegreeSearch(getAllNodeIndexs());
  char *name1 = mygraph->table[largestOutDegree].name;

  
  int smallestInDegree = smallestInDegreeSearch(getAllNodeIndexs());
  char *name2 = mygraph->table[smallestInDegree].name;
  
  int largestInDegree = largestInDegreeSearch(getAllNodeIndexs());
  char *name3 = mygraph->table[largestInDegree].name;
  
  printf("The smallest outdegree: %d \t Name: %s(%dth)\n"
         , mygraph->table[smallestOutDegree].outdegree, name, smallestOutDegree);
  printf("The largest outdegree: %d \t Name: %s(%dth)\n\n"
         , mygraph->table[largestOutDegree].outdegree , name1, largestOutDegree);
  
  printf("The smallest indegree: %d \t Name: %s(%dth)\n"
         , mygraph->table[smallestInDegree].indegree  , name2, smallestInDegree);
  printf("The largest  indegree: %d \t Name: %s(%dth)\n"
         , mygraph->table[largestInDegree].indegree   , name3, largestInDegree );
  
  return(0);
}//main
示例#3
0
int main()
{
    graph g;
    read_graph(&g, 0);
    dijkstra(&g, 0);
    print_graph(&g);
}
示例#4
0
文件: main.c 项目: ZhihuiYe/C-code
int main(int argc,char *argv[])
{
  read_graph(argv[1]);

  printf("\nPath Distance from %s to %s: %d\n", argv[2], argv[3], heuristicPathFinder(atoi(argv[2]), atoi(argv[3])));
  return(0);
}
示例#5
0
int main(void) {
	graph g;

	read_graph(&g, TRUE);
	print_graph(&g);
	strong_components(&g);
	return 0;
}
示例#6
0
struct roadmap *read_input(const char *input_filename){
  struct buffer file_buf = read_input_into_buffer(input_filename);
  if(file_buf.mem == NULL){
    return NULL;
  }
  struct roadmap *map = read_graph(file_buf);
  return map;
}
示例#7
0
int main(void) {
  graph g;

  read_graph(&g, FALSE);
  print_graph(&g);
  articulation_vertices(&g);
  
  return 0;
}
示例#8
0
文件: connected.c 项目: fannix/poj
main()
{
	graph g;

	read_graph(&g,FALSE);
	print_graph(&g);

	connected_components(&g);
}
示例#9
0
int main(int argc, char *argv[])
{
	FILE *fp;
	graph g;
	int i;
	int total_colors[] = {0, 0, 0};
	int max, min;
	
	if (argc != 2) {
		fprintf(stderr, "Usage: %s filename\n", argv[0]);
		exit(1);
	}
	
	fp = fopen(argv[1], "r");

	if (fp == NULL) {
		fprintf(stderr, "Can't open file %s\n", argv[1]);
		exit(1);
	}

	read_graph(fp, &g, TRUE);
	//print_graph(&g);
	twocolor(&g);

	for (i=1; i<=(g.nvertices); i++) {
		//printf(" %d",color[i]);
		switch (color[i]) {
		case UNCOLORED:
			total_colors[0]++;
			break;
		
		case WHITE:
			total_colors[1]++;
			break;
			
		case BLACK:
			total_colors[2]++;
			break;
			
		}
	}
#ifdef DEBUG
	printf("TOTAL: %d\n", g.nvertices);
	printf("WHITE: %d\n", total_colors[1]);
	printf("BLACK: %d\n", total_colors[2]);
	printf("UNCOLORED: %d\n", total_colors[0]);
#endif

	max = (total_colors[1] > total_colors[2]) ? total_colors[1] : total_colors[2];
	min = (total_colors[1] > total_colors[2]) ? total_colors[2] : total_colors[1];
	
	printf("%d %d\n", max, min);
        
    return 0;
}
示例#10
0
void init()		//read all the needed input files
{
	read_place_name();
	read_place_belong();
	read_tag();
	read_Person_location();
	read_study_org();
	read_work_org();
	read_org_location();
	read_graph();
}
示例#11
0
文件: wgraph.c 项目: ZhepingYang/misc
int
main(int argn, char *argv[])
{
    graph_t g;

    read_graph(&g, FALSE);
    print_graph(&g);
    dijkstra(&g, 0);
    if(argn > 1) {
        find_path(0, atoi(argv[1]));
    }
}
示例#12
0
文件: dijkstra.c 项目: LihuaWu/recipe
main()
{
	graph g;
	int i;

	read_graph(&g,FALSE);
	dijkstra(&g,1);

        for (i=1; i<=g.nvertices; i++)
                find_path(1,i,parent);
        printf("\n");

}
示例#13
0
int main() {
	int n_problems, vertex_id, max_flow;
	t_node vertex;
	read_graph();

	initialize_preflow(graph, graph->vertexs[0]);

	scanf("%d", &n_problems);

	while (n_problems > 0) {
		links_to_cut = -1;
		reset_crit_points(graph);
		if (read_problem(graph) == 0) { /* menos de 2 pontos criticos */
			printf("0\n");
			--n_problems;
			continue;
		}
		for (vertex_id = 0; vertex_id < graph->max_vertex; ++vertex_id) {
			vertex = graph->vertexs[vertex_id];
			if (vertex->is_critical) {
				max_flow = relabel_to_front(graph, vertex);
				if (max_flow == 0) {
					links_to_cut = 0;
					break;
				} else if (max_flow < links_to_cut || links_to_cut < 0) {
					links_to_cut = max_flow;
				}
			}

		}
		--n_problems;
		printf("%d\n", links_to_cut);
	}

	/*n_problems = read the problem line count

	 for each line (problem)
	 reset critic points
	 read_problem(); <- set the critic points
	 for each V in critics
	 maxflow = relabel_to_front()
	 if maxflow == 0
	 links_to_cut < 2;
	 break;
	 else if maxflow < links_to_cut
	 links_to_cut = maxflow

	 print links_to_cute*/

	return 0;
}
int main()
{
  int a[NMAX];
  int i;
  read_graph(&g, FALSE);
  print_graph(&g);

  for (i=1; i<=g.nvertices; ++i) {
    printf("\nPaths from 1 to %d: ", i);
    backtrack(a, 0, i);
  }

  return 0;
}
int main(int argc, char** argv) {
   FILE *input = fopen(FNAME,"r");
   graph* g = read_graph(input);
   fclose(input);

   int path_len;
   ll_node* path = longest_path_da(g,&path_len);
   print_path(path);
   printf("%i\n",path_len);

   /*
   graph* f = flip(g);

   ll_node* cyc = cycles(g);
   print_graph(g);
   printf("\n\n");
   print_graph(f);
   printf("\n\n");

   cycle_counter counter = build_cycle_counter(cyc,g,f);

   print_cycle_counter(counter);
   init_cut_cycles(counter, g, f);
   print_cycle_counter(counter);
   print_graph(g);
   printf("\n\n");
   print_graph(f);
   printf("\n\n");

   inc_cycles(counter,g,f);
   print_graph(g);
   printf("\n\n");
   print_graph(f);
   */

   /*

   print_cycle_counter(cycle_counter);

   ll_node* cur = cyc;
   while(cur != NULL) {
      print_path(cur->data);
      cur = cur->next;
   }

   free_ll(cyc);
   free_graph(g);
   free_graph(f);
   */
}
示例#16
0
int RDFParser::read_rules(stringstream & stream) {
	int ret=0;
	string rulename;
	string rulestr;
	Rule * rule;
	rdfg->graph->resolve();
	while (ret >= 0) {
		ret = check_str(stream, "rule");
		if (ret<0)
			break;
		stream >> rulename;
		rule = new Rule(rulename);
		ret = read_str(stream, "{");
		if (ret < 0)
			return ret;
		ret = read_str(stream, "left");
		if (ret < 0)
			return ret;
		ret = read_graph(stream, rule->left());
		if (ret < 0)
			return ret;
		ret = read_str(stream, "right");
		if (ret < 0)
			return ret;
		ret = read_graph(stream, rule->right());
		if (ret < 0)
			return ret;
		ret = read_str(stream, "}");
		if (ret < 0)
			return ret;

		rule->preprocess();
		rdfg->add_rule(rule);		
	}
	return 0;
}
int main(int argc,char *argv[]) 
{
  // define graph  
  Graph mygraph;

  // read graph from command line argument
  read_graph(&mygraph,argv[1]);
  
  //print_graph(&mygraph);
 
  // send graph to dfs function
  DFS(&mygraph);
  
  return(0);
}
示例#18
0
void run_testcase()
{
        int start_point;
        graph g;
        graph *graphptr = &g;

        initialize_graph(graphptr, false);
        read_graph(graphptr, false);
        initialize_search(graphptr);

        scanf("%d", &start_point);
        init_distances(start_point);

        bfs(graphptr, start_point);
        print_distances(graphptr, start_point);
}
示例#19
0
文件: topsort.c 项目: LihuaWu/recipe
main()
{
	graph g;
	int out[MAXV];
	int i;

	read_graph(&g,TRUE);
	print_graph(&g);

	topsort(&g,out);

	for (i=1; i<=g.nvertices; i++)
		printf(" %d",out[i]);
	printf("\n");

}
int main()
{
  graph g;
  int i;

  read_graph(&g,FALSE);
  print_graph(&g);

  twocolor(&g);

  printf("the color of nodes\n");
  for (i=1; i<=(g.nvertices); i++)
    printf("%d: %d\n", i, color[i]);
  printf("\n");

  return 0;
}
示例#21
0
DNNModel *ff_dnn_load_model_tf(const char *model_filename)
{
    DNNModel *model = NULL;
    TFModel *tf_model = NULL;
    TF_Buffer *graph_def;
    TF_ImportGraphDefOptions *graph_opts;

    model = av_malloc(sizeof(DNNModel));
    if (!model){
        return NULL;
    }

    tf_model = av_malloc(sizeof(TFModel));
    if (!tf_model){
        av_freep(&model);
        return NULL;
    }
    tf_model->session = NULL;
    tf_model->input_tensor = NULL;
    tf_model->output_data = NULL;

    graph_def = read_graph(model_filename);
    if (!graph_def){
        av_freep(&tf_model);
        av_freep(&model);
        return NULL;
    }
    tf_model->graph = TF_NewGraph();
    tf_model->status = TF_NewStatus();
    graph_opts = TF_NewImportGraphDefOptions();
    TF_GraphImportGraphDef(tf_model->graph, graph_def, graph_opts, tf_model->status);
    TF_DeleteImportGraphDefOptions(graph_opts);
    TF_DeleteBuffer(graph_def);
    if (TF_GetCode(tf_model->status) != TF_OK){
        TF_DeleteGraph(tf_model->graph);
        TF_DeleteStatus(tf_model->status);
        av_freep(&tf_model);
        av_freep(&model);
        return NULL;
    }

    model->model = (void *)tf_model;
    model->set_input_output = &set_input_output_tf;

    return model;
}
void city_tour()
{
  graph h; 
  edge *elist; 
  int nedge; 
  init_graph(&h); 
  h.read_node_attr = read_cityname;
  h.write_node_attr = write_cityname;
  h.read_edge_attr = read_distance;
  h.write_edge_attr = write_distance;

  if (read_graph(FILENAME, &h)) {
	print_graph(stdout, &h); 
	elist = (edge *) malloc(sizeof(edge) * (number_of_nodes(&h) - 1));
	nedge = mst_kruskal(&h, elist, get_distance);
  }
}
示例#23
0
文件: bfs-demo.c 项目: LihuaWu/recipe
main()
{
	graph g;
	int i;

	read_graph(&g,FALSE);
	print_graph(&g);
	initialize_search(&g);
	bfs(&g,1);
	for (i=1; i<=g.nvertices; i++)
		printf(" %d",parent[i]);
	printf("\n");

	for (i=1; i<=g.nvertices; i++) 
		find_path(1,i,parent);
	printf("\n");
}
示例#24
0
文件: check.c 项目: fromeroj/iimas
int main ( int argc, char *argv[] ){
  int i,j,size=argc-2;
  int* nums;
  printf( "Called with %d elements\n", argc-2 );
  if ( argc < 2 ){
    printf( "usage: %s filename [elements]", argv[0] );
    exit(1);
  }
  nums=calloc(size,sizeof(int));
  for(i=0;i<size;i++)nums[i]=atoi(argv[i+2]);
  read_graph(argv[1]);
  int errors=0;
  for(i=0;i<size-1;i++)
    for(j=i+1;j<size;j++)
      if(!has_edge(nums[i],nums[j]))
	printf("Error[%d] doesn't contain, %d %d\n",++errors,nums[i],nums[j]);
  if(!errors)printf("Checked!\n");
  return 0;
}
示例#25
0
int main(int argc, char** argv) {
  bool is_valid = true;
  if (argc < 2 || argc > 3) {
    std::cerr << "Usage: " << argv[0] << " input.gr [input.td]" << std::endl;
    std::cerr << std::endl;
    std::cerr << "Validates syntactical and semantical correctness of .gr and .td files. If only a .gr file is given, it validates the syntactical correctness of that file." << std::endl;
    exit(1);
  }
  tree_decomposition T;
  graph g;

  std::ifstream fin(argv[1]);
  try {
    read_graph(fin,g);
  } catch (const std::invalid_argument& e) {
    std::cerr << "Invalid format in " << argv[1] << ": " << e.what() << std::endl;
    is_valid = false;
  }
  fin.close();

  if(argc==3 && is_valid) {
    fin.open(argv[2]);
    try {
      read_tree_decomposition(fin, T);
    } catch (const std::invalid_argument& e) {
      std::cerr << "Invalid format in " << argv[2] << ": " << e.what() << std::endl;
      is_valid = false;
    }
    fin.close();

    if (is_valid) {
      is_valid = is_valid_decomposition(T,g);
    }
  }

  if (is_valid) {
    std::cerr << "valid" << std::endl;
    return 0;
  } else {
    std::cerr << "invalid" << std::endl;
    return 1;
  }
}
示例#26
0
int main(int argc , char * argv[])
{
//    if(argc !=4 ){        printf("\nUSAGE : simuation graph_data car_data time_step");exit(0);}
    GRAPH G; 
    CARS C;
    EDGES E;
    time_step =1;// atof(argv[3]);
    read_graph(&G, "input");//argv[1]); 
    read_cars(&C, "car_input");//argv[2]);
    print_graph(&G);
    print_cars(&C);
    init(&G,&C,&E);
   // print_edges(&E);
    printf(" \n time_step : %f\n",time_step);
    start_simulation(&G,&C,&E);
    print_collisons();
    print_path_history(&C);
    print_edge_history(&E);
    return 1;
}
示例#27
0
void read_graph_file(char *edgefile,
		     char *graphfile,
		     int *num_vertex,
		     NODES ***vertex,
		     int *num_edge,
		     EDGE ***edge)
{
  FILE *fp;
  FILE *fp1;

  fp = ckopen(edgefile, "r");
  fp1 = ckopen(graphfile, "r");
  *vertex = (NODES **) ckalloc(MAX_NODES * sizeof(NODES *));
  *edge = (EDGE **) ckalloc(MAX_EDGE * sizeof(EDGE *));
  *num_vertex = read_graph(*vertex, *edge, num_edge, fp, fp1);
  printf("Input graph ... done. %d vertices and %d edges.\n",
	 *num_vertex, *num_edge);
  fclose(fp1);
  fclose(fp);
}
int main()
{
  graph g;
  int i;

  read_graph(&g, FALSE);
  print_graph(&g);
  initialize_search(&g);
  bfs(&g, 1);
  printf("nodes parents:\n");
  for (i=1; i<=g.nvertices; ++i) 
    printf("%d: %d\n", i, parent[i]);
  printf("\n");

  printf("path from root to every node\n");
  for (i=0; i<=g.nvertices; ++i)
    find_path(1, i, parent);
  printf("\n");

  return 0;
}
示例#29
0
int main(int argc, char* argv[])
{
  /*
  std::vector<std::thread> workers;

  for (int i=0; i<9; ++i){
    auto th = std::thread(&hello, i);
    workers.push_back(std::move(th));

  }

  std::cout << "Hi from main\n" ;

  std::for_each(workers.begin(),workers.end(), [](std::thread & th){th.join();});*/


  read_graph(argv[1]);


  return 0;
}
static int
bench(FibHeap<size_t, size_t> *pq,
      const struct settings &settings)
{

    int ret = 0;
    size_t number_of_nodes;
    vertex_t *graph = read_graph(settings.graph_file,
                                 settings.max_generated_random_weight != 0,
                                 settings.max_generated_random_weight,
                                 number_of_nodes,
                                 settings.seed);


    /* Our initial node is graph[0]. */

    graph[0].n = pq->push((size_t)0, (size_t)0);

    graph[0].distance = 0;


    struct timespec start, end;
    clock_gettime(CLOCK_MONOTONIC, &start);

    start_sssp(pq, graph);

    clock_gettime(CLOCK_MONOTONIC, &end);
    /* End benchmark. */

    //verify_graph(graph, number_of_nodes);
    print_graph(graph,
                number_of_nodes,
                settings.output_file);

    const double elapsed = timediff_in_s(start, end);
    fprintf(stdout, "%f", elapsed);

    delete_graph(graph, number_of_nodes);
    return ret;
}