int main(int argc, char* argv[]){ // Parameters char fileNameGp[1024]; // Name of the file that contains the pattern graph char fileNameGt[1024]; // Name of the file that contains the target graph int timeLimit=60; // Default: CPU time limit set to 60 seconds int verbose = 0; // Default: non verbose execution bool induced = false; // Default: search for partial subgraph bool firstSol = false; // Default: search for all solutions bool isLabelled = false; // Default: non labelled graphs fileNameGp[0] = 0; fileNameGt[0] = 0; parse(&isLabelled, &timeLimit, &firstSol, &induced, &verbose, fileNameGp, fileNameGt, argv, argc); if (verbose >= 2) printf("Parameters: isLabelled=%d induced=%d firstSol=%d timeLimit=%d verbose=%d fileNameGp=%s fileNameGt=%s\n", isLabelled, induced,firstSol,timeLimit,verbose,fileNameGp,fileNameGt); // Initialize graphs Tgraph *Gp = createGraph(fileNameGp, isLabelled); // Pattern graph Tgraph *Gt = createGraph(fileNameGt, isLabelled); // Target graph if (verbose >= 2){ printf("Pattern graph:\n"); printGraph(Gp); printf("Target graph:\n"); printGraph(Gt); } // Initialize domains Tdomain *D = createDomains(Gp, Gt); if (!initDomains(induced, D, Gp, Gt)) return printStats(false); if (verbose >= 2) printDomains(D, Gp->nbVertices); // Check the global all different constraint if ((!updateMatching(Gp->nbVertices,Gt->nbVertices,D->nbVal,D->firstVal,D->val,D->globalMatchingP)) || (!ensureGACallDiff(induced,Gp,Gt,D))){ nbFail++; return printStats(false); } // Math all vertices with singleton domains int u; int nbToMatch = 0; int toMatch[Gp->nbVertices]; for (u=0; u<Gp->nbVertices; u++){ D->globalMatchingT[D->globalMatchingP[u]] = u; if (D->nbVal[u] == 1) toMatch[nbToMatch++] = u; } if (!matchVertices(nbToMatch,toMatch,induced,D,Gp,Gt)){ nbFail++; return printStats(false); } // Solve return printStats(!solve(timeLimit,firstSol, induced, verbose, D, Gp, Gt)); }
int main() { int V; scanf ("%d", &V); // struct Graph* graph = createGraph(V+1); graph = createGraph(V+1); int i; for (i = 0; i < V; i++) { int vert, no_neghs; scanf("%d%d", &vert, &no_neghs); int j; for (j = 0; j < no_neghs; j++) { int neigh; scanf("%d", &neigh); addEdge(graph, vert, neigh); } } //printGraph(graph); graph2 = createGraph(V+1); int root, M; scanf("%d%d", &root, &M); for (i = 0; i < M; i++) { int u, v; scanf("%d%d", &u,&v); addEdge (graph2, u, v); } //printGraph(graph2); BFSG(root); BFST(root); // printf("%d ", V); for(i = 1; i < V+1; i++) { printf("%d ", distG[i]); } for(i = 1; i < V+1; i++) { printf("%d ", distT[i]); } return 0; }
Graph_p test_createGraph(Gdb_graph_t t){ Graph_p p; if(t==UNDIRECTED){ printf("\nTesting createGraph(UNDIRECTED): "); p = createGraph(t,"./default_u_db.gdb"); } else{ printf("\nTesting createGraph(DIRECTED): "); p = createGraph(t,"./default_d_db.gdb"); } assert(p != NULL); printf("PASS"); return p; }
int main(){ Graph *G = NULL; int n; printf("Enter the number of nodes in the graph: "); scanf("%d",&n); //Generate a graph consisting of n nodes. G = createGraph(n,DIRECTED); //Add new edges addEdge(G,0,4); addEdge(G,0,1); addEdge(G,1,3); addEdge(G,1,2); addEdge(G,1,4); addEdge(G,1,0); addEdge(G,2,3); addEdge(G,2,1); addEdge(G,3,2); addEdge(G,3,4); addEdge(G,3,1); addEdge(G,4,1); addEdge(G,4,0); addEdge(G,4,3); displayGraph(G); system("pause"); return 0; }
int main() { long t0=time(NULL); createGraph(); printf("\nTime taken = %lds. Starting SCC subroutine...", time(NULL)-t0); //display(); getch(); scc(); //display(); /*5ms to travel entire loop int i, j,k=0; t0=time(NULL); for(j=1;j<1000;++j) for(i=1; i<=NO_OF_VERTICES;++i) { if(g[i].x==NO_OF_VERTICES) { k++; } } printf("\nTime taken to traverse = %lds.", time(NULL)-t0); * */ return 0; }
//constructor, set the gpu id, name and create //an empty list of states Gpu::Gpu(const std::string &id, const std::string &name) { gpuId = id; gpuName = name; createGraph(); }
int kargerMinCut(FILE *inputFile, int numIterations) { // seed the random number generator time_t t; srand((unsigned)time(&t)); Graph *g = createGraph(inputFile); int bestSolution = g->numEdges; for(int i = 0; i < numIterations; i++){ int newSolution = runKarger(g); free(g); if(newSolution < bestSolution) bestSolution = newSolution; g = createGraph(inputFile); } return bestSolution; }
Graph* buildTrustGraph(int forum, Graph* g) { Graph * trustGraph = createGraph(M,C); char buffer[200]; Node * n; FILE * fp = fopen("forum_hasMember_person.csv","r"); if (fp == NULL) { perror ("Error opening file"); exit(-1); } fgets(buffer,200,fp); while(fgets(buffer,200,fp)!= NULL) //insert users of the forum { if (forum == atoi(strtok (buffer,"|"))) { n = createPerson(atoi(strtok (NULL,"|")),NULL); insertNode(n,trustGraph); } } fclose(fp); Graph * PostGraph = createPostForum("forum_containerOf_post.csv","post_hasCreator_person.csv",forum); //creating posts hash_map Graph * CommentGraph = CreateComments("comment_replyOf_post.csv","comment_hasCreator_person.csv",PostGraph); insertLikes("person_likes_post.csv", PostGraph, trustGraph,g); insertComments("comment_replyOf_post.csv", CommentGraph, PostGraph, trustGraph, g); addTrust(trustGraph,g); freePCGraph(PostGraph); freePCGraph(CommentGraph); return trustGraph; }
graph* makeGraphFromArray(int arr[],int size,int board[]) { graph* gr; int i,j; int k; gr= createGraph(101); gr->num=101; for(i=0;i<size;i++) { for(j=i+1;j<size;j++) { k = getMaxMoves(arr[i],arr[j],board); #ifdef DEBUG printf("addVertice: %d->%d: %d\n",arr[i],arr[j],k); #endif addVertices(gr,arr[i],arr[j],1,k); } } #ifdef DEBUG // printGraph(gr); #endif return gr; }
// Driver program to test above functions int main() { /* Let us create following graph 0 | \ | \ 1-----2 */ int V = 3, E = 3; struct Graph* graph = createGraph(V, E); // add edge 0-1 graph->edge[0].src = 0; graph->edge[0].dest = 1; // add edge 1-2 graph->edge[1].src = 1; graph->edge[1].dest = 2; // add edge 0-2 graph->edge[2].src = 0; graph->edge[2].dest = 2; if (isCycle(graph)) printf( "graph contains cycle" ); else printf( "graph doesn't contain cycle" ); return 0; }
void main()//User interface { cout<<"BELLMAN FORD SHORTEST PATH GRAPH ALGORITHM\n"; int num,edges,source,dest,weight; cout<<"\nEnter the number of NODES in the graph: "; cin>>num; cout<<"\nEnter the number of EDGES in the graph: "; cin>>edges; struct Graph* graph = createGraph(num, edges); cout<<"\nEnter details of the edges: \n"; for(int i=0; i<edges; i++) { cout<<"\nEDGE "<<i+1; cout<<"\nSouce node: "; cin>>graph->edge[i].source; cout<<"Destination node: "; cin>>graph->edge[i].dest; cout<<"Weight: "; cin>>graph->edge[i].weight; } int s; cout<<"\nEnter the starting node: "; cin>>s; cout << "\n\nFollowing are shortest distances to all other nodes from source node "<<s<<": \n"; BellmanFord(graph, s); getch(); }
void p3() { struct flowNetwork * fN =createGraph(); maximizeFlowNetwork(fN, 0, 8); printAdjMat(fN->adjMatrix); deleteFlowNetwork(fN); }
int main(void) { char numString[MAX_STRING]; int numArray[MAX_STRING]; int graph[MAX_MATRIX][MAX_MATRIX]; int limit, i; char N[10]; /* clear the graph */ clearGraph(graph); while (fgets(N, 10, stdin) != NULL) { int n = atoi(N); if (n == 0) break; for (i = 0; i < n; i++) { getNumString(numString); limit = split(numString, numArray); if (numArray[0] == 0) break; createGraph(numArray, graph); } /* find out how many cirtical nodes the graph have */ findCriticalNode(graph, limit); clearGraph(graph); } return 0; }
int main(int argc, char* argv[]) { char tipo1, tipo2; int numeroV, numeroA, vertice1, vertice2, peso = 1, i = 0, j = 0; tipo1 = 'D'; tipo2 = 'M'; scanf("%d %d", &numeroV, &numeroA); createGraph(G, tipo1, tipo2, numeroV, numeroA); //IG(G); for(i = 0; i < numeroA; i++) { scanf("%d %d", &vertice1, &vertice2); AA(G, vertice1, vertice2, peso); } int origem, destino; /*for(i = 0; i < numeroA; i++) { scanf("%d %d", &origem, &destino); }*/ while(scanf("%d %d", &origem, &destino) != EOF) { path(G, origem, destino); printf("%d %d\n", origem, destino); } return 0; }
int main() { Graph g = createGraph(); int i, num; int adjlist[100]={0}; addEdgeI(g, 1, 2); addEdgeI(g, 1, 3); addEdgeI(g, 1, 4); addEdgeI(g, 2, 1); addEdgeI(g, 2, 3); addEdgeI(g, 2, 4); addEdgeI(g, 3, 4); addEdgeI(g, 2, 1); addEdgeI(g, 3, 1); if(adjacentI(g, 4, 3)) printf("4 and 3 is adjacent: true\n"); else printf("4 and 3 is adjacent: false\n"); num = getAdjVerticesI(g, ji(4), adjlist, &cmpInt); if(num == 0){ printf("Num == 0\n"); }else{ printf("Adjlist of %d is: ", 4); for(i = 0; i < num; i++){ printf("%d, ", adjlist[i]); } } }
Graph* createMinSpanningTree(List *list, int size) { int *id = new int[size] { 0 }; for (int i = 0; i < size; ++i) { id[i] = i; } Graph* graph = createGraph(size); while (!isEmpty(list)) { Road road = getValue(list); pop(list); int from = road.from; int to = road.to; int weight = road.weight; if (id[from] != id[to]) { for (int i = 0; i < size; ++i) { if (id[i] == id[to]) { id[i] = id[from]; } } setWeight(graph, from, to, weight); } } delete[] id; return graph; }
int main() { /*graph *g=createGraph(8); addEdge(g,1,2); addEdge(g,2,3); addEdge(g,8,2); addEdge(g,3,4); addEdge(g,3,5); addEdge(g,5,6); addEdge(g,5,7); addEdge(g,5,8);*/ graph *g=createGraph(6); addEdge(g,6,3); addEdge(g,6,1); addEdge(g,4,1); addEdge(g,5,2); addEdge(g,3,4); addEdge(g,4,2); DFSTraversal(g); printf("\n"); head=NULL; BFSTraversal(g); printf("\n"); topologicalsort(g); return 0; }
Graph* fileRead(FILE* file) { char *token; char line[MAX_LENGTH], src[MAX_LENGTH], dst[MAX_LENGTH]; int numOfVertex, edgeWeight, numOfEdges=0; Graph *graph; Vertex *newVer1, *newVer2; Edge *newEdge1, *newEdge2; // Checking how many edges we have. while (fgets(line, MAX_LENGTH, file) != NULL) numOfEdges++; numOfEdges = (numOfEdges-1)*2; // numOfEdges = number of lines in file -1 (first line not included) * 2 // because an edge needed to be in both ways. rewind(file); // Re-positioning to the begining of the file. // Reading the first line if (fgets(line, MAX_LENGTH, file) != NULL) { token = strtok(line, " "); numOfVertex = atoi(token); } // Creating Graph struct graph = createGraph(numOfVertex, numOfEdges); if (graph == NULL) { printf("ERROR creating the Graph\n"); return NULL; } // Continue reading the rest of the file, while creating, checking if exists and // add new vertices and new edges to the graph. while (fgets(line, MAX_LENGTH, file) != NULL) { // Reading a line and put each parameter to a different temporary variable. token = strtok(line, " "); strcpy(src, token); token = strtok(NULL, " "); strcpy(dst, token); token = strtok(NULL, " "); edgeWeight = atoi(token); // Create 2 vertices. newVer1 = createVertex(src); newVer2 = createVertex(dst); // Checking if those vertices exists within the graph and adds them if needed. newVer1 = addVertexToGraph(newVer1, graph); newVer2 = addVertexToGraph(newVer2, graph); // Creating 2 edges, the given one and its vice versa. newEdge1 = createEdge(newVer1, newVer2, edgeWeight); newEdge2 = createEdge(newVer2, newVer1, edgeWeight); // Adding the edges to the graph. addEdgeToGraph(newEdge1, graph); addEdgeToGraph(newEdge2, graph); } return graph; }
int main() { // create the graph given in above fugure int V = 0; int src; //printf("Enter the number of nodes\n"); scanf("%d",&V); int *costMatrix=(int *) malloc(sizeof(int)*V*V); struct Graph* graph = createGraph(V); //printf("Enter the Number of Edges you want to add\n"); int i=0,E=0; scanf("%d",&E); //printf("Enter the links and their costs\n"); int n1,n2,cost; for(i=0;i<E;i++) { scanf("%d %d %d",&n1,&n2,&cost); addEdge(graph,n1,n2,cost,costMatrix,V); } //printf("Enter the source Node\n"); scanf("%d",&src); int k=0,l=0; double x=omp_get_wtime(); TreeSearch(graph,src,V,costMatrix); double y=omp_get_wtime(); printf("%f\n",y-x); return 0;}
void readFile(const char *fileName) { FILE *f; char line[10]; char rel; int r1,r2, c=0,max=0; f = fopen(fileName ,"r"); fgets(line,10,f); sscanf(line,"%d", &SIZE); int from[SIZE]; int to[SIZE]; char r[SIZE]; while(fgets(line,10,f) != NULL){ sscanf(line, "%d %c %d", &r1, &rel, &r2); if(r1 > max) max = r1; if(r2 > max) max = r2; if(rel == '<'){ rel = '>'; int aux = r1; r1 = r2; r2=aux; } from[c] = r1; r[c] = rel; to[c] = r2; c++; } createGraph(from,r,to,c); }
void main() { int prev[MAX] = {0}; int dist[MAX] = {0}; MGraph* pG; // 创造一个图 pG = createGraph();; // 打印图 //printGraph(*pG); // 深度优先遍历 //DFSTraverse(*pG); // 广度优先遍历 //BFSTraverse(*pG); // prim算法生成最小生成树 prim(*pG, 0); // kruskal算法生成最小生成树 kruskal(*pG); // dijkstra算法获取"第4个顶点"到其它各个顶点的最短距离 // dijkstra(*pG, 3, prev, dist); system("pause"); }
int main(int argc, char **argv) { srand(time(NULL)); if (argc < 2) { printf("Mandatory parameter is missing. 0 - Generate Kruskal testcase; 1 - Generate Trading Salesman testcase.\n"); } else if (atoi(argv[1]) == 0) { if (argc != 7) printf("Usage: 0 nbNodes nbEdges minWeight maxWeight outputName.\n"); else { graph graph = createGraph(atoi(argv[2]), atoi(argv[3]), atof(argv[4]), atof(argv[5])); printGraph(&graph, argv[6]); //printDot(&graph, 1); destroyGraph(&graph); } } else if (atoi(argv[1]) == 1) { if (argc != 4) printf("Usage: 1 nbNodes outputName.\n"); else { point *points = generatePoints(atoi(argv[2])); printGraphOfPoints(points, atoi(argv[2]), argv[3]); destroyPoints(points); } } else { printf("Illegal job id.\n"); return 0; } return 0; }
// Driver program to test above functions int main() { // create the graph given in above fugure int V = 9; struct Graph* graph = createGraph(V); addEdge(graph, 0, 1, 4); addEdge(graph, 0, 7, 8); addEdge(graph, 1, 2, 8); addEdge(graph, 1, 7, 11); addEdge(graph, 2, 3, 7); addEdge(graph, 2, 8, 2); addEdge(graph, 2, 5, 4); addEdge(graph, 3, 4, 9); addEdge(graph, 3, 5, 14); addEdge(graph, 4, 5, 10); addEdge(graph, 5, 6, 2); addEdge(graph, 6, 7, 1); addEdge(graph, 6, 8, 6); addEdge(graph, 7, 8, 7); dijkstra(graph, 0); system("pause"); return 0; }
int main(){ int V = 10; Graph *graph = createGraph(V); if(graph == NULL) return -1; geraGrafo(graph); printGraph(graph); /* addEdge(graph, 0, 1, 5); addEdge(graph, 0, 4, 2); addEdge(graph, 1, 2, 3); addEdge(graph, 1, 3, 8); addEdge(graph, 1, 4, 1); addEdge(graph, 2, 3, 2); addEdge(graph, 3, 4, 1); addEdge(graph, 4, 2, 4); */ listaHeap *cm = NULL; cm = (listaHeap*) dijkstra(graph, 0); int i; printf("%d:", cm->tam); for (i = 0; i < cm->tam; i++) { printf("id:%d, idNo:%d, peso:%d\n", i, cm[i].idNo, cm[i].peso); } printf("ok\n"); return 0; }
int main() { // create the graph FILE *f; int V; f=fopen("matrix.txt.","r"); fscanf(f,"%d",&V); int** adjMat=getMatrix(f,V); struct Graph* graph = createGraph(V); int i,j; printf(" The matrix is : \n\n"); printMatrix(adjMat,V); //for a un-oriented graph for(i=0;i<V;i++) for(j=i;j<V;j++) if(adjMat[i][j]==1) addEdge(graph, i,j); printGraph(graph);// print the adjacency list representation of the above graph //create adjacency graph from adjacency list printf("\n\n"); int** adjMatFromList=createAdjMatFromList(graph, V); printMatrix(adjMatFromList,V); return 0; }
int main() { //CREATE GRAPH FROM A SORTED EDGE LIST FILE createGraph(); int i=0, flg=0; for(i=1;i<NO_OF_ENTRIES;++i) { if(list[i]->w>list[i+1]->w) { printf("\n%d) %d %d %d\n", i, list[i]->s, list[i]->d, list[i]->w); flg++; } } if(flg==0) { printf("\nArray is sorted. Now to apply clustering..."); getch(); } else return -1; i=cluster(4); printf("\nMaximum spacing=%d. (At edge no.=%d)", list[i]->w, i); return 0; }
Graph* createGraph(char* filename) { std::fstream in; in.open(filename); if (!in.is_open()) { return NULL; } int vertices = 0; in >> vertices; int edges = 0; in >> edges; Graph *graph = createGraph(vertices); for (int k = 0; k < edges; ++k) { int i = 0; in >> i; int j = 0; in >> j; int weight = 0; in >> weight; if (i <= graph->vertices && j <= graph->vertices) { graph->a[i][j] = weight; graph->a[j][i] = weight; } } in.close(); return graph; }
int main() { int V; scanf ("%d", &V); struct Graph* graph = createGraph(V); int i; for (i = 0; i < V; i++) { int vert, no_neghs; scanf("%d%d", &vert, &no_neghs); int j; for (j = 0; j < no_neghs; j++) { int neigh; scanf("%d", &neigh); addEdge(graph, vert, neigh); } } printGraph(graph); return 0; }
void* createForum(void *arg){ Graph* currentG; Edge* current; Node* n; create_args* args = (create_args*)arg; Forum* forum = args->forum; Graph* gforum = args->gforum; Graph* graph = args->g; Node* node = lookupNode(forum->id,gforum); //printf("%s\n",forum->name); currentG = createGraph(5, 10 , forum->name); currentG->next = NULL; insertEdgeProperty(currentG,"knows"); if ( node->edges==NULL || node->edges->size < 0) current = NULL; else current = node->edges->edge[0]; while (current!=NULL){ n = setNodeProperties(current->endID,NULL,NULL,0); insertNode(n,currentG); current = current->next; } find_copy_edges(graph,currentG,"knows","knows"); pthread_exit(currentG); }
int main() { int V; int choice = 1; int src, dest; printf("\nHow many nodes you want to have in your graph\n"); scanf("%d",&V); GRAPH *graph = createGraph(V); printf("\nEnter an Edge like SRC DEST : ex- 0 1\n"); while(choice) { printf("\nENter Edge\n"); scanf("%d %d",&src,&dest); addEdge(graph, src, dest); printf("\nContinue?"); scanf("%d",&choice); } printGraph(graph); return 0; }