//gcc router.c -o router graph.c socket_open_read_write.c -w message_encode_decode.c -w //./router port_number int main(int argc, char *argv[]){ /*Initializing globals*/ memset(message_history_table,0,TABLE_SIZE); ROUTER_ID=atoi(argv[1]); message_count=0; //Setting up socket int port_number=ROUTER_BASE_PORT+ROUTER_ID; int my_socket=set_up_socket(port_number); char *msg_string; char c; msg *received_message; //listening now listen_again: initialize_graph(); msg_string=read_from_socket(my_socket); received_message=decode_message(msg_string); // free(msg_string); do_stuff(received_message); // printf("Press y to continue listening(you may have to press twice for assurance).n to kill the socket and exit.\n"); // c=getchar(); // c=getchar(); //if(c=='y') goto listen_again; close(my_socket); return 0; }
distance[start] = 0; v = start; while (intree[v] == false) { intree[v] = true; p = g->edges[v]; while (p != NULL) { w = p->y; weight = p->weight; if ((distance[w] > weight) && (intree[w] == false)) { distance[w] = weight; parent[w] = v; } p = p->next; } v = 1; dist = INT_MAX; for (i = 0; i < g->nvertices; i++) if ((intree[i] == false) && (dist > distance[i])) { dist = distance[i]; v = i; } } } /* ------------------------------- Main ------------------------------- */ int main() { int i, dist, m, n, x, y, weight, total;
int read_graph (char *filename) /* * Reads in graph from FILE *filename which is of .gx format. * Stores it as Graph in *mygraph. * Returns an error if file does not start with MAX command, * or if any subsequent line is not a NODE or EDGE command. * Does not check that node numbers do not exceed the maximum number * Defined by the MAX command. */ { FILE *fp; char command[80], name[80]; int i, s, t; fp= fopen (filename, "r"); if (fp==NULL) { fprintf(stderr,"cannot open file %s\n", filename); return -1; }//if printf ("Reading graph from %s\n", filename); fscanf (fp,"%s", command); if (strcmp (command, "MAX")!=0) { fprintf (stderr, "Error in graphics file format\n"); return -1; }//if else { fscanf (fp, "%d", &i); initialize_graph(i+1); // +1 so nodes can be numbered 1..MAX while (fscanf(fp, "%s", command)!=EOF) { if (strcmp(command, "NODE")==0) { fscanf(fp, "%d %s", &i, name); insert_graph_node(i, name); }//if else if (strcmp(command, "EDGE")==0) { fscanf(fp, "%d %d", &s, &t); insert_graph_link(s, t); }//else if else return -1; }//while }//else return 0; }//read_graph
read_graph(graph *g, bool directed) { int i; /* counter */ int m; /* number of edges */ int x, y; /* vertices in edge (x,y) */ initialize_graph(g); scanf("%d %d",&(g->nvertices),&m); for (i=1; i<=m; i++) { scanf("%d %d",&x,&y); insert_edge(g,x,y,directed); } }
void read_graph(graph_t *g, bool directed) { int i, m; int x, y, w; initialize_graph(g, directed); scanf("%d %d", &(g->nvertices), &m); for(i = 0; i < m; ++i) { scanf("%d %d %d", &x, &y, &w); insert_edge(g, x, y, directed, w); } }
void read_graph(graph *graph, bool directed) { int i; /* counter */ int nedges; int x, y; /* vertices in edge (x, y) */ initialize_graph(graph, directed); scanf("%d %d",&(graph->nvertices), &nedges); for (i=1; i<=nedges; i++) { scanf("%d %d", &x, &y); insert_edge(graph, x, y, directed); } }
read_graph(graph *g, bool directed) { int i; /* counter */ int m; /* number of edges */ int x, y; /* vertices in edge (x, y) */ initialize_graph(g, directed); printf("Enter the number of vertices\n"); scanf("%d %d", &(g->nvertices), &m); for(i=1;i<=m;i++) { printf("enter the next coordinates: "); scanf("%d %d", &x, &y); insert_edge(g, x, y, directed); } }
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); }
int main(){ int i,j; initialize_graph(3,2); add_edge(0,1); add_edge(1,2); //add_edge(2,0); //add_edge(0,3); //add_edge(3,4); dfs_main(); return 0; }
void read_graph(graph *g, bool directed) { initialize_graph(g, directed); int m; scanf("%d %d", &(g->nvertices), &m); // number of vertices and edges in the graph for (int i = 1; i <= m; i++) { int x; int y; int w; scanf("%d %d %d\n", &x, &y, &w); insert_edge(g, x, y, directed, w); } }
int read_graph (char *filename) { FILE *fp; char command[80], name[80]; int i, s, t; fp= fopen (filename, "r"); if (fp==NULL) { fprintf(stderr,"cannot open file %s\n", filename); return -1; }//if printf ("Reading graph from %s\n", filename); fscanf (fp,"%s", command); if (strcmp (command, "MAX")!=0) { fprintf (stderr, "Error in graphics file format\n"); return -1; }//if else { fscanf (fp, "%d", &i); initialize_graph(i+1); // +1 so nodes can be numbered 1..MAX while (fscanf(fp, "%s", command)!=EOF) { if (strcmp(command, "NODE")==0) { fscanf(fp, "%d %s", &i, name); insert_graph_node(i, name); }//if else if (strcmp(command, "EDGE")==0) { fscanf(fp, "%d %d", &s, &t); insert_graph_link(s, t); }//else if else return -1; }//while }//else return 0; }//read_graph
int peos_create_instance(char *model_file,peos_resource_t *resources,int num_resources) { peos_context_t *context; if ((context = find_free_entry()) == NULL) { return -1; } if ((context->process_graph = makegraph(model_file)) != NULL) { context->pid = peos_get_pid(context); context->num_resources = num_resources; context -> resources = resources; strcpy(context->model, model_file); context->status = PEOS_READY; initialize_graph(context->process_graph, context->pid); return (context->pid); } return -1; }