Esempio n. 1
0
int main(){
  int num_vertices = 5;

  Graph* undir = create_graph(num_vertices, UNDIRECTED);
  Graph* dir = create_graph(num_vertices, DIRECTED);

  add_edge(undir,0,1);
  add_edge(undir,0,4);
  add_edge(undir,1,2);
  add_edge(undir,1,3);
  add_edge(undir,1,4);
  add_edge(undir,2,3);
  add_edge(undir,3,4);

  add_edge(dir,0,1);
  add_edge(dir,0,4);
  add_edge(dir,1,2);
  add_edge(dir,1,3);
  add_edge(dir,1,4);
  add_edge(dir,2,3);
  add_edge(dir,3,4);

  printf("\nUndirected Graph");
  display_graph(undir);

  printf("\nDirected Graph");
  display_graph(dir);

  return 0;
}
Esempio n. 2
0
int main( int argc, char **argv )
{
    char   *param;
    int     sensornum;
    int     subaddr;
    int     days;
    int     type;

    cgi_init();
    cgi_process_form();

    param = cgi_param("sensor");
    sensornum = param ? atoi(param) : 255;

    param = cgi_param("type");
    type = param ? atoi(param) : S_RECEIVER;

    param = cgi_param("subaddr");
    subaddr = param ? atoi(param) : 1;

    param = cgi_param("days");
    days = param ? atoi(param) : 1;

    load_data(sensornum, subaddr, type, days );
    create_graph();

    cgi_redirect(graphuri);

    cgi_end();
    return( 0 );
}
Esempio n. 3
0
int main(int argc, char *argv[]){
  int vertex_num;
  int connection_num;
  int from, to;
  Info *table;
  Graph G;

  scanf("%d", &vertex_num);
  G = create_graph(vertex_num);
  scanf("%d", &connection_num);
  for (int i = 0; i < connection_num; i++){
    scanf("%d%d", &from, &to);
    connect_to(G, from, to);
  }
  scanf("%d", &from);
  table = unweighted(G, from);
  for (int i = 1; i <= vertex_num; i++){
    if (i != from){
      if (table[i].dist == INF)
	printf("No path from %d to %d\n", from, i);
      else{
	printf("To vertex %d: distance %d ", i, table[i].dist);
	print_path(table, i);
	putchar('\n');
      }
    }
  }

  dispose_graph(G);
  dispose_table(table);
}
Esempio n. 4
0
int main()
{
	int i,v,choice;
	create_graph();
	while(1)
	{
		printf("\n");
		printf("1. Adjacency matrix\n");
		printf("2. Breadth First Search\n");
		printf("3. Exit\n");
		printf("Enter your choice : ");
		scanf("%d",&choice);
		switch(choice)
		{
			case 1:
				printf("Adjacency Matrix\n");
				display();
				break;
			case 2:
				printf("Enter starting node for Breadth First Search : ");
				scanf("%d", &v);
				for(i=1;i<=n;i++)
					visited[i]=false;
				bfs(v);
				break;
			case 3:
				exit(1);
			default:
				printf("Wrong choice\n");
				break;
		}
	}
	return 0;
}
Esempio n. 5
0
int
main(void)
{
  GSGraphSnapshot* graph;
  GSGraphNode* node;

  node = create_graph();
  graph = g_sgraph_snapshot_new_from_node(node, G_SGRAPH_TRAVERSE_BFS);
  g_print("BFS from `A':");
  g_sgraph_snapshot_foreach_node(graph, (GFunc)print_node_desc, NULL);
  g_sgraph_snapshot_free(graph, FALSE);
  graph = g_sgraph_snapshot_new_from_node(node, G_SGRAPH_TRAVERSE_DFS);
  g_print("\nDFS from `A':");
  g_sgraph_snapshot_foreach_node(graph, (GFunc)print_node_desc, NULL);
  node = g_sgraph_snapshot_find_node_custom(graph, "I", (GEqualFunc)find_node);
  g_sgraph_snapshot_free(graph, FALSE);
  graph = g_sgraph_snapshot_new_from_node(node, G_SGRAPH_TRAVERSE_BFS);
  g_print("\nBFS from `I':");
  g_sgraph_snapshot_foreach_node(graph, (GFunc)print_node_desc, NULL);
  g_sgraph_snapshot_free(graph, FALSE);
  graph = g_sgraph_snapshot_new_from_node(node, G_SGRAPH_TRAVERSE_DFS);
  g_print("\nDFS from `I':");
  g_sgraph_snapshot_foreach_node(graph, (GFunc)print_node_desc, NULL);
  g_print("\n");
  g_sgraph_snapshot_foreach_node(graph, (GFunc)free_node_desc, NULL);
  g_sgraph_snapshot_free(graph, TRUE);
  return 0;
}
main()
{
	int s,v;

	create_graph();
	
	printf("Enter source vertex : ");
	scanf("%d",&s);
	
	Dijkstra(s);

	while(1)
	{
		printf("Enter destination vertex(-1 to quit): ");
		scanf("%d",&v);
		if(v == -1)
			break;
		if(v < 0 || v >= n )
			printf("This vertex does not exist\n");
		else if(v == s)
			printf("Source and destination vertices are same\n");
		else if( pathLength[v] == infinity )
            printf("There is no path from source to destination vertex\n");
		else
			findPath(s,v);
	}
}/*End of main()*/
void* populate_domain_data(int argc, char** argv) {
	assert(argc == 2);
	FILE* fp = fopen(argv[1], "r");

	assert(fp != NULL);

	int num_vertices, num_edges;
	NEW(graph_color_data, data);

	fscanf(fp, "%d %d", &num_vertices, &num_edges);
	graph* g = create_graph(num_vertices);

	int from, to, discard;

	for (int i = 0; i < num_edges; i++) {
		fscanf(fp, "%d %d %d", &from, &to, &discard);
		assert(from != to);
		add_edge(g, from, to, 0);
//		add_edge(g, to, from, 0);
	}

	data->g = g;
	data->max_colors = g->num_vertices;

	solution_vector_size = sizeof(float) + sizeof(int) + data->max_colors * sizeof(int);

	return (void*) data;
}
Esempio n. 8
0
int
main ()
{
  printf ("Creating a directed graph: \n");
  graph_t graph = create_graph (V);

  add_edge (graph, 0, 1);
  add_edge (graph, 0, 4);
  add_edge (graph, 1, 2);
  add_edge (graph, 1, 3);
  add_edge (graph, 1, 4);
  add_edge (graph, 2, 3);
  add_edge (graph, 3, 4);
  add_edge (graph, 4, 0);
  add_edge (graph, 5, 0);
  add_edge (graph, 6, 0);

  display_graph (graph);

  printf ("Removing edges from vertix 1:\n");
  remove_edge (graph, 1, 2);
  remove_edge (graph, 1, 3);
  remove_edge (graph, 1, 4);

  display_graph (graph);
  destroy_graph (graph);

  return 0;
}
Esempio n. 9
0
int		main(int ac, char **av)
{
  int		v;
  t_map		map;
  t_graph	**pile;

  if (ac != 2)
    return (1);
  if (load_map(&map, av[1]) == -1 ||
      create_graph(&map) == -1 ||
      link_room(&map) == -1)
    return (1);
  if ((pile = malloc(sizeof(t_graph *))) == NULL)
    return (1);
  *pile = NULL;
  if ((v = search_path(map.start, map.end, &pile)) == 0)
    {
      printf("No solution found\n");
      return (1);
    }
  else if (v == -1)
    return (2);
  set_path(map.end);
  show_map(&map);
  free(pile);
  free_all(&map);
  return (0);
}
Esempio n. 10
0
int main(int argc, char *argv[]){
	char filename[MAX_FILE_NAME];
	int vertex_num;
	int origin_num;
	char line[MAX_LINE];
	
	FILE *in;
	if(argc != 2){
		printf("Usage: ./%s [filename]\n", argv[0]);
		exit(1);
	}
	strcpy(filename, argv[1]);
	if((in = fopen(filename, "r")) == NULL){
		fprintf(stderr, "failed to open the file\n");
	}
	while(fgets(line, MAX_LINE, in)!=NULL){
		int vertex[MAX_NODES_NUM];
		int matrix[MAX_NODES_NUM][MAX_NODES_NUM];
		int num = parse(line,vertex);
		decode(matrix, vertex, num);
		//print_matrix(matrix, num);
		graph *graph_ptr = create_graph(matrix,num);
		//print_graph(graph_ptr);
		DFSTraversal(graph_ptr);
		BFSTraversal(graph_ptr);
	}
	if(fclose(in)!=0){
		fprintf(stderr, "failed to close the file\n");
	}

}
Esempio n. 11
0
// 1 color a 3 node, 2 edge graph
// the node with the most edges should be spilled
void test_chaitin_spill() {
    DEBUG_PRINT("\ntest_chaitin_spill:\n");
    DEBUG_PRINT("  creating graph...\n");

    graph* g = create_graph();

    vertex* a = graph_add_vertex(g, 'a');
    vertex* b = graph_add_vertex(g, 'b');
    vertex* c = graph_add_vertex(g, 'c');

    graph_add_edge(a, b);
    graph_add_edge(a, c);
    
    assert(a->color == -1);
    assert(b->color == -1);
    assert(c->color == -1);

    DEBUG_PRINT("  coloring graph...\n");

    color_graph(g, 1);

    #ifdef DEBUG
    print_graph(g);
    #endif

    assert(a->color == -1); // spilled node
    assert(b->color == 0);
    assert(c->color == 0);

    destroy_graph(g);

    printf("+ algorithm test (spill) passed!\n");
}
int
main ()
{
  printf ("Creating a directed graph: \n");
  graph_t *graph = create_graph (10, DIRECTED);
  add_edge (graph, 0, 2);
  add_edge (graph, 1, 6);
  add_edge (graph, 1, 5);
  add_edge (graph, 2, 1);
  add_edge (graph, 2, 3);
  add_edge (graph, 2, 4);
  add_edge (graph, 6, 7);
  add_edge (graph, 7, 8);
  add_edge (graph, 8, 9);

  display_graph (*graph);

  int c = 2, d = 1;
  printf ("%d and %d directly connected? %s\n", c, d, direct_connection (graph,
          c, d) ? "yes" : "no");
  c = 1, d = 7;
  printf ("%d and %d directly connected? %s\n", c, d, direct_connection (graph,
          c, d) ? "yes" : "no");

  c = 1, d = 7;
  printf ("%d and %d connected? %s\n", c, d, vertices_connected (graph,
          graph->list[c].head, &c, d) ? "yes" : "no");
  c = 1, d = 0;
  printf ("%d and %d connected? %s\n", c, d, vertices_connected (graph,
          graph->list[c].head, &c, d) ? "yes" : "no");

  return 0;
}
Esempio n. 13
0
void CGameGraphBuilder::build_graph			(
#ifdef PRIQUEL
		LPCSTR graph_name,
		LPCSTR cross_table_name,
#endif // PRIQUEL
		LPCSTR level_name
	)
{
	Phase					("Building level game graph");
	Msg						("level \"%s\"",level_name);

#ifdef PRIQUEL
	m_graph_name			= graph_name;
	m_cross_table_name		= cross_table_name;
#endif // PRIQUEL
	m_level_name			= level_name;
	
//	CTimer					timer;
//	timer.Start				();

	create_graph			(0.000000f,0.000047f);
//	Msg						("%f",timer.GetElapsed_sec());
	load_level_graph		(0.000047f,0.002470f);
//	Msg						("%f",timer.GetElapsed_sec());
	load_graph_points		(0.002517f,0.111812f);
//	Msg						("%f",timer.GetElapsed_sec());
	build_cross_table		(0.114329f,0.773423f);
//	Msg						("%f",timer.GetElapsed_sec());
	build_graph				(0.887752f,0.112248f);
//	Msg						("%f",timer.GetElapsed_sec());

	Msg						("Level graph is generated successfully");
}
Esempio n. 14
0
int main () {
    create_graph(5);
    print_graph();
    path = malloc(n * sizeof (int));
    set = calloc(n, sizeof (int));
    hamiltonian(0);
    return 0;
}
Esempio n. 15
0
  // simple fmap case, fsmap case
  void create_graph(const paracel::list_type<paracel::str_type> & linelst,
                paracel::bigraph & grp,
  		paracel::dict_type<size_t, paracel::str_type> & rm,
		paracel::dict_type<size_t, paracel::str_type> & cm) {
    paracel::dict_type<size_t, int> dm;
    paracel::dict_type<size_t, int> col_dm;
    create_graph(linelst, grp, rm, cm, dm, col_dm);
  }
Esempio n. 16
0
int main(int argc, char** argv){
    if (argc > 1){
        Graph *graph;
        graph = create_graph();
        read_file_on_graph(graph, argv[1]);
        check_result(graph);
    }
    else printf("Insert file name.\n");
    return 0;
}
Esempio n. 17
0
void run_vm() {
  graph = create_graph();
  ip = (WORD*) code;
  run_thread();
  while (1) {
    read_inputs();
    update_signals();
    write_outputs();
  }
}
Esempio n. 18
0
void glp_erase_graph(glp_graph *G, int v_size, int a_size)
{     if (!(0 <= v_size && v_size <= 256))
         xerror("glp_erase_graph: v_size = %d; invalid size of vertex d"
            "ata\n", v_size);
      if (!(0 <= a_size && a_size <= 256))
         xerror("glp_erase_graph: a_size = %d; invalid size of arc data"
            "\n", a_size);
      delete_graph(G);
      create_graph(G, v_size, a_size);
      return;
}
Esempio n. 19
0
int
main (int argc, char **argv)
{
  int opt;
  int command_number = 1;
  int print_tree = 0;
  int time_travel = 0;
  program_name = argv[0];

  for (;;)
    switch (getopt (argc, argv, "pt"))
      {
      case 'p': print_tree = 1; break;
      case 't': time_travel = 1; break;
      default: usage (); break;
      case -1: goto options_exhausted;
      }
 options_exhausted:;

  // There must be exactly one file argument.
  if (optind != argc - 1)
    usage ();

  script_name = argv[optind];
  FILE *script_stream = fopen (script_name, "r");
  if (! script_stream)
    error (1, errno, "%s: cannot open", script_name);
  command_stream_t command_stream =
    make_command_stream (get_next_byte, script_stream);

  command_t last_command = NULL;
  command_t command;
  
  if (time_travel) {
	 graph_t g = create_graph(command_stream);
	 execute_graph(g);
  } else {
	while ((command = read_command_stream (command_stream)))
		{
		if (print_tree)
		{
		printf ("# %d\n", command_number++);
		print_command (command);
		}
		else
		{
		last_command = command;
		execute_command (command);
		}
	}
  }

  return print_tree || !last_command ? 0 : command_status (last_command);
}
Esempio n. 20
0
glp_graph *glp_create_graph(int v_size, int a_size)
{     glp_graph *G;
      if (!(0 <= v_size && v_size <= 256))
         xerror("glp_create_graph: v_size = %d; invalid size of vertex "
            "data\n", v_size);
      if (!(0 <= a_size && a_size <= 256))
         xerror("glp_create_graph: a_size = %d; invalid size of arc dat"
            "a\n", a_size);
      G = xmalloc(sizeof(glp_graph));
      create_graph(G, v_size, a_size);
      return G;
}
Esempio n. 21
0
main()
{
	int choice;
	int node,origin,destin;

	create_graph();
	while(1)
	{
		printf("1.Insert a node\n");
		printf("2.Insert an edge\n");
		printf("3.Delete a node\n");
		printf("4.Delete an edge\n");
		printf("5.Dispaly\n");
		printf("6.Exit\n");
		printf("Enter your choice : ");
		scanf("%d",&choice);

		switch(choice)
		{
		 case 1:
			insert_node();
			break;
		 case 2:
			printf("Enter an edge to be inserted : ");
			fflush(stdin);
			scanf("%d %d",&origin,&destin);
			insert_edge(origin,destin);
			break;
		 case 3:
			printf("Enter a node to be deleted : ");
			fflush(stdin);
			scanf("%d",&node);
			delete_node(node);
			break;
		 case 4:
			printf("Enter an edge to be deleted : ");
			fflush(stdin);
			scanf("%d %d",&origin,&destin);
			del_edge(origin,destin);
			break;
		 case 5:
			display();
			break;
		 case 6:
			exit();
		 default:
			printf("Wrong choice\n");
			break;
		 }/*End of switch*/
	}/*End of while*/
}/*End of main()*/
Esempio n. 22
0
int main(){
	nd** G;
	int V,E,u,v;
	scanf("%d",&V);
	G = create_graph(V);
	scanf("%d",&E);
	while(E--){
		scanf("%d%d",&u,&v);
		add_edge(G,u,v);
	}	
	display_graph(G,V);
	degree(G,V);	
	return 0;
}
main()
{
  int G[20][20],no_of_nodes,mst[20][20];

  printf("Enter no.of nodes:");
  scanf("%d",&no_of_nodes);
  create_graph(G,no_of_nodes);
  printf("---Original graph---\n");
  print_graph(G,no_of_nodes);

  MST_kruskal(G,no_of_nodes,mst);
  printf("----Mst---\n");
  print_graph(mst,no_of_nodes);
}
Esempio n. 24
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;
}
Esempio n. 25
0
int main()
{
	int v;
	
	printf("enter the number of vertices:  ");
	scanf("%d", &v);

	int adjMatrix[v][v];
	int i = 0, j = 0;

	printf("give connections:\n");

	while(i < v)
	{
		printf("vertex %d:\n", (i+1));

		while(j < v)
		{
			scanf("%d", &adjMatrix[i][j]);
			j++;
		}
		j = 0;
		i++;
	}

	printf("Adjacency Matrix:\n");
	for(i = 0; i < v; i++)
	{
		for(j = 0; j <v; j++)
			printf("%d", adjMatrix[i][j]);	
		printf("\n");
	}

	graph *head;

	head = create_graph(v, adjMatrix);

	display(head);	
	
//	graph *root = head;
	
//	while(root != NULL)
//	{
//		printf("%d >> ", root->v_name);
//		root = root->next;
//	}
//	printf("end\n");
}
Esempio n. 26
0
main()
{
	 int i,j,path[10],wt_tree,count;
	 struct edge tree[10];
	 create_graph();
	 printf("\n adjacency matrix\n");
	 display();
	count=maketree(tree,&wt_tree);
	printf("\n weight of spanning tree is : %d \t\n",wt_tree);
	printf("\n edges in spanning tree\n");
	for(i=1;i<n;i++)
	{
		 printf( " %d -> ",tree[i].u);
		 printf("%d\n",tree[i].v);
	}
}
Esempio n. 27
0
int main(int argc, char *argv[])
{
    /* creating graph */
    graph* g = create_graph(5);
    add_edge(g, 0, 1);
    add_edge(g, 0, 4);
    add_edge(g, 1, 2);
    add_edge(g, 1, 4);
    add_edge(g, 2, 3);
    add_edge(g, 3, 4);

    print_graph(g);
    printf("%d",g->array[0].head->next->key);
    return 0;

}
Esempio n. 28
0
void mg_V2()
{
    int size = strlen(string);
    
    CELL* inicio = create_graph(size);
    CELL* aux = inicio, *aux2, *aux3;
    int i;
    int imprimirGrafo = 0;
    int reductible = 1;
    CELL* vetor[] = {NULL, NULL, NULL, NULL}, *a, *b, *c, *d, *op, *cauda, *f, *g, *x, *y, *par1, *par2;
    int counter = 0;
    
    inicio = reduct(inicio);
    printf("antes do GC: \n");
    //print_graph(inicio);
    while(garbage == 1)
    {
        printf("chegou aqui\n");
    
        if(heapUsado == 0){
            
            heapUsado = 1;
            heap = heap2;
            GC_cheney(inicio, heap);
            inicio = heap;
            
            //ptrRaiz = heap;
        }
        else
        {
            heapUsado = 0;
            heap=heap1;
            GC_cheney(inicio, heap);
            
            //lastPos = 0;
            inicio = heap;
            printf("SAIU DO GARBAGE\n");
        }
        garbage = 0;
        free_pilha(pilha);
         printf("depois do GC do GC: \n");
        //print_graph(inicio);
        printf("\n");
        inicio = reduct(inicio);
    }
    print_graph(inicio);
}
Esempio n. 29
0
static int process(char *base, unsigned int size, void *text_base)
{
	struct bina_context *ctx;
	struct bina_trace *trace;
	FILE *graph;
	int i;
	
	ctx = bina_create(&x86_32_arch, base, size);
	if (!ctx) {
		printf("error: unable to create context\n");
		return -1;
	}
	
	bina_detect_basic_blocks(ctx);
	create_graph(ctx);
	
	bina_analyse_loops(ctx);
	
	printf("starting trace\n");
	
	trace = bina_trace_init(ctx, binary_file, text_base, break_handler);
	if (!trace) {
		bina_destroy(ctx);
		printf("error: couldn't setup trace.\n");
		return -1;
	}
	
	graph = fopen("./trace.dot", "wt");
	fprintf(graph, "digraph g {\n");

	
	for (i = 0; i < ctx->nr_basic_blocks; i++) {
		bina_install_breakpoint(trace, ctx->blocks[i].instructions, graph);
	}
	
	bina_trace_run(trace);
	
	fprintf(graph, "}\n");
	fclose(graph);
	
	printf("trace complete\n");
	
	bina_trace_destroy(trace);
	bina_destroy(ctx);
	return 0;
}
int main(){
     int i, n ,output[100];
     graph g = create_graph();
     add_edge(g, 0, 1);
     add_edge(g, 0, 2);
     add_edge(g, 1, 2);
     add_edge(g, 1, 3);
#define PRINT_ADJACENT_VERTIES(v) {                                 \
          n = get_adjacent_vertices(g, v, output);                  \
          if(n == 0)                                                \
               printf("No adjacent vertices of node" #v " \n");     \
          else{                                                     \
               printf("Adjacent vertices of node "#v": ");          \
               for(i = 0; i < n; i++)                               \
                    printf("%5d", output[i]);                       \
               printf("\n");                                        \
          }                                                         \
     }                                                              

     PRINT_ADJACENT_VERTIES(0);
     PRINT_ADJACENT_VERTIES(1);
     PRINT_ADJACENT_VERTIES(2);
     PRINT_ADJACENT_VERTIES(3);
#undef PRINT_ADJACENT_VERTIES


     printf("\n");
     printf("\n\nTest drop !\n");

     drop_graph(&g);

     n = get_adjacent_vertices(g, 1, output);
 
     if(n == 0)
          printf("No adjacent vertices of node 1 \n");
     else{
          printf("Adjacent vertices of node 1: ");
          for(i = 0; i < n; i++)
               printf("%5d", output[i]);
     }
     printf("\n");
     
     
     return 0;
}