TrilinosMatrixAdapter::TrilinosMatrixAdapter(escript::JMPI mpiInfo, int blocksize, const escript::FunctionSpace& fs, const_TrilinosGraph_ptr graph, bool isComplex, bool unroll) : AbstractSystemMatrix(blocksize, fs, blocksize, fs), m_mpiInfo(mpiInfo), m_isComplex(isComplex) { if (isComplex) { if (blocksize == 1) { cmat = rcp(new CrsMatrixWrapper<cplx_t>(graph)); } else if (unroll) { const_TrilinosGraph_ptr newGraph(util::unrollCrsGraph(graph, blocksize)); cmat = rcp(new UnrolledBlockCrsMatrixWrapper<cplx_t>(newGraph, blocksize)); } else { cmat = rcp(new BlockCrsMatrixWrapper<cplx_t>(graph, blocksize)); } } else { if (blocksize == 1) { mat = rcp(new CrsMatrixWrapper<real_t>(graph)); } else if (unroll) { const_TrilinosGraph_ptr newGraph(util::unrollCrsGraph(graph, blocksize)); mat = rcp(new UnrolledBlockCrsMatrixWrapper<real_t>(newGraph, blocksize)); } else { mat = rcp(new BlockCrsMatrixWrapper<real_t>(graph, blocksize)); } } }
Graph mkTestGraph(int graphNum) { Graph g = NULL; if (graphNum == 0) { g = newGraph(0); assert(numV(g) == 0); assert(numE(g) == 0); } else if (graphNum == 1) { g = newGraph(1); assert(numV(g) == 1); assert(numE(g) == 0); } else if (graphNum == 2) { g = newGraph(2); assert(numV(g) == 2); assert(numE(g) == 0); } else if (graphNum == 3) { g = newGraph(5); Edge e301 = mkEdge(0, 1, 7); Edge e302 = mkEdge(0, 2, 6); Edge e303 = mkEdge(0, 3, 5); Edge e304 = mkEdge(0, 4, 4); Edge e312 = mkEdge(1, 2, 3); Edge e323 = mkEdge(2, 3, 2); Edge e334 = mkEdge(3, 4, 1); insertE(g, e301); insertE(g, e302); insertE(g, e303); insertE(g, e304); insertE(g, e312); insertE(g, e323); insertE(g, e334); assert(numV(g) == 5); assert(numE(g) == 7); } return g; }
void ShaderEditor::onGUIMenu() { if(ImGui::BeginMenuBar()) { if(ImGui::BeginMenu("File")) { if (ImGui::MenuItem("New")) newGraph(); if (ImGui::MenuItem("Open")) load(); if (ImGui::MenuItem("Save", nullptr, false, m_path.isValid())) save(m_path.c_str()); if (ImGui::MenuItem("Save as")) { getSavePath(); if (m_path.isValid()) save(m_path.c_str()); } ImGui::EndMenu(); } if (ImGui::BeginMenu("Edit")) { if (ImGui::MenuItem("Undo", nullptr, false, canUndo())) undo(); if (ImGui::MenuItem("Redo", nullptr, false, canRedo())) redo(); ImGui::EndMenu(); } if (ImGui::MenuItem("Generate", nullptr, false, m_path.isValid())) { generate(m_path.c_str(), ShaderType::VERTEX); generate(m_path.c_str(), ShaderType::FRAGMENT); generateMain(m_path.c_str()); } ImGui::EndMenuBar(); } }
int main(){ Graph G; G = NULL; G = newGraph (6); if(G){ printf("Graph Created\n"); }else{ printf("Graph Not Created\n"); } addEdge(G,0,1); addEdge(G,1,2); addEdge(G,1,3); addEdge(G,3,4); addEdge(G,4,2); doBFS(G,0); printf("%d\n", getDistance(G,0)); printf("%d\n", getDistance(G,1)); printf("%d\n", getDistance(G,2)); printf("%d\n", getDistance(G,3)); printf("%d\n", getDistance(G,4)); printf("%d\n", getDistance(G,5)); printList(stdout,getPathTo(G,4)); /* freeGraph(&G); */ return(0); }
int main(int argc, char* argv[]){ int i, s, max, min, d, n=35; Graph G = NULL; // Build graph G G = newGraph(n); for(i=1; i<n; i++){ if( i%7!=0 ) addEdge(G, i, i+1); if( i<=28 ) addEdge(G, i, i+7); } addEdge(G, 9, 31); addEdge(G, 17, 13); addEdge(G, 14, 33); // Print adjacency list representation of G printGraph(stdout, G); // Properties of this graph printf("Number of vertices %d", getOrder(G)); printf("Number of edges: %d", getSize(G)); // Free objects freeGraph(&G); return(0); }
void Automaton::run() { int line = 0; while(true) { // Read first line state std::vector<std::string> numbers = parseString(lines[line]," "); int C = stoi(numbers[0]), S = stoi(numbers[1]), Q = stoi(numbers[2]); if( C == 0 && S == 0 && Q == 0) { break; } line++; // Create state delete state; state = new StateCreateGraph(); newGraph(C); graph.setE(S); for(int i = 0; i < S; i++, line++) { state->run(lines[line], graph); } // Find state delete state; state = new StateFindPath(); for(int i = 0; i < Q; i++, line++) { state->run(lines[line], graph); } } }
int main(){ int arcos, vertices, i, vertice1, vertice2; Graph *grafo, *grafoTransposto; scanf("%d %d", &vertices, &arcos); grafo = newGraph(vertices); temp_fin_aux = (int*) malloc(sizeof(int)*vertices*2); sccBit = (int*)malloc(sizeof(int)*vertices); verticeSCC= (int*)malloc(sizeof(int)*vertices); for(i=0; i<vertices; i++){ temp_fin_aux[i] = -1; sccBit[i]=0; temp_fin_aux[i+vertices]=-1; } for(i=0;i<arcos;i++){ scanf("%d %d", &vertice1, &vertice2); addToList(grafo->listaAdjac[vertice1-1],vertice2); } dfs(grafo, 0); grafoTransposto = reverseGraph(grafo); dfs(grafoTransposto, 1); printf("%d\n", scc); printf("%d\n", SCCBigger); printf("%d\n", scc-GtconnectSCC); return 0; }
BayesNet* newBayesNet() { BayesNet* bayesnet = malloc(sizeof(BayesNet)); bayesnet->graph = newGraph(DIRECTED_GRAPH); bayesnet->variables = NULL; bayesnet->potentials = NULL; return bayesnet; }
// Constrói o Moral Graph Graph* buildBNMoralGraph (int nxr, int* xr, BayesNet* bayesnet) { Graph* subgraph; Graph* moral; // Variáveis auxiliares Vertex* vertex; VertexNode* current; VertexLinkedList* children; int* varmap; // Mapea as variáveis da rede antiga para a subrede int i,j; // Aloca o espaço para o mapa de variáveis varmap = malloc(bnsize(bayesnet)*sizeof(int)); // Inicializa o mapa de variáveis for (i=0;i<bnsize(bayesnet);i++) varmap[i] = 0; // 1. Constroi o subgrafo - mantendo os ids dos nós // Inicializa o subgraph subgraph = newGraph(DIRECTED_GRAPH); // Percore o vetor de variáveis requireds e cria os vértices da subrede for (i=0;i<nxr;i++) { // Atualiza o mapa de variáveis indicando que o nó/variável é requirida varmap[xr[i]] = 1; // inclui o nó na rede vertex = buildVertex(xr[i],bayesnet->variables[xr[i]]->name); addVertex(&subgraph,&vertex); } for (i=0;i<nxr;i++) { // Estabelece as ligações vertex = getVertex(&bayesnet->graph,xr[i]); current = getVertexChildren(vertex)->first; while (current!=NULL) { if (varmap[current->vertex->id]==1) addArcByIds(&subgraph,xr[i],current->vertex->id); current = current->next; } } // 2. Gera o Moral Graph para o subgraph moral = buildMoralGraph(subgraph); // Desloca os espaços da memória; // Mapa de variáveis free(varmap); varmap = NULL; // Destroy o subgraph destroyGraph(&subgraph); subgraph = NULL; return moral; }
void testGraph(void) { printf("Testing graph 1...\n"); Location path[NUM_MAP_LOCATIONS]; int a = findShortestPath(NANTES, MARSEILLES, path, ANY,0); assert(a == 3); assert(path[0] == NANTES); assert(path[1] == CLERMONT_FERRAND); assert(path[2] == MARSEILLES); printf("Test passed!\n"); printf("Testing graph 2...\n"); a = findShortestPath(NANTES, MARSEILLES, path, ANY,0); assert(a == 3); assert(path[0] == NANTES); assert(path[1] == CLERMONT_FERRAND); assert(path[2] == MARSEILLES); printf("Test passed!\n"); printf("Testing graph by rail...\n"); a = findShortestPath(MADRID, BARCELONA, path, ANY,2); assert(a == 2); assert(path[0] == MADRID); assert(path[1] == BARCELONA); printf("Passed by rail test\n"); a = findShortestPath(MARSEILLES, COLOGNE, path, ANY,3); assert(a == 2); assert(path[0] == MARSEILLES); assert(path[1] == COLOGNE); printf("Passed second rail test\n"); a = findShortestPath(MARSEILLES, AMSTERDAM, path, ANY,3); assert(a == 3); assert(path[0] == MARSEILLES); assert(path[1] == COLOGNE); assert(path[2] == AMSTERDAM); printf("Passed final rail test\n"); printf("Testing fail cases\n"); printf("Testing Strassburg to CD\n"); a = findShortestPath(STRASBOURG, CASTLE_DRACULA, path, ANY, 3); int i = 0; int correct[5] = {51,6,10,21,13}; for (i = 0; i < a; i++) { assert(path[i] == correct[i]); } printf("Passed\nNow testing same path but without rail (ie round rem 4 equal to 0 )"); printf("Passed\nNow testing same path but without rail"); a = findShortestPath(STRASBOURG, CASTLE_DRACULA, path, ANY, 0); int correct2[6] = {51,38,58,10,28,13}; for (i = 0; i < a; i++) { assert(path[i] == correct2[i]); } printf("\nTest Passed\nNow to test the results of connected locs Klaus (expecting CD to be there)\n"); Graph g = newGraph(); LocationID *b = connectedLocations(&a, KLAUSENBURG, 0, 0, ANY, g); for (i=0; i<a; i++) { printf("[%d]",b[i]); } free(b); destroyGraph(g); printf("\nDone\n"); }
int main(int argc, char* argv[]){ int i, n=8; List S = newList(); Graph G = newGraph(n); Graph T=NULL, C=NULL; for(i=1; i<=n; i++) append(S, i); addArc(G, 1,2); addArc(G, 1,5); addArc(G, 2,5); addArc(G, 2,6); addArc(G, 3,2); addArc(G, 3,4); addArc(G, 3,6); addArc(G, 3,7); addArc(G, 3,8); addArc(G, 6,5); addArc(G, 6,7); addArc(G, 8,4); addArc(G, 8,7); printGraph(stdout, G); DFS(G, S); fprintf(stdout, "\n"); fprintf(stdout, "x: d f p\n"); for(i=1; i<=n; i++){ fprintf(stdout, "%d: %2d %2d %2d\n", i, getDiscover(G, i), getFinish(G, i), getParent(G, i)); } fprintf(stdout, "\n"); printList(stdout, S); fprintf(stdout, "\n"); T = transpose(G); C = copyGraph(G); fprintf(stdout, "\n"); printGraph(stdout, C); fprintf(stdout, "\n"); printGraph(stdout, T); fprintf(stdout, "\n"); DFS(T, S); fprintf(stdout, "\n"); fprintf(stdout, "x: d f p\n"); for(i=1; i<=n; i++){ fprintf(stdout, "%d: %2d %2d %2d\n", i, getDiscover(T, i), getFinish(T, i), getParent(T, i)); } fprintf(stdout, "\n"); printList(stdout, S); fprintf(stdout, "\n"); freeList(&S); freeGraph(&G); freeGraph(&T); freeGraph(&C); return(0); }
CrsGraph_View::NewTypeRef CrsGraph_View:: operator()( OriginalTypeRef orig ) { origObj_ = &orig; //Error, must be local indices assert( !orig.IndicesAreGlobal() ); //test maps, new std::map must be left subset of old const Epetra_BlockMap & oRowMap = orig.RowMap(); const Epetra_BlockMap & oColMap = orig.ColMap(); int nNumRows = NewRowMap_->NumMyElements(); int nNumCols = 0; if( NewColMap_ ) nNumCols = NewColMap_->NumMyElements(); bool matched = true; for( int i = 0; i < nNumRows; ++i ) matched = matched && ( oRowMap.GID(i) == NewRowMap_->GID(i) ); if( nNumCols ) for( int i = 0; i < nNumCols; ++i ) matched = matched && ( oColMap.GID(i) == NewColMap_->GID(i) ); if( !matched ) std::cout << "EDT_CrsGraph_View: Bad Row or Col Mapping\n"; assert( matched ); //intial construction of graph std::vector<int> numIndices( nNumRows ); std::vector<int*> indices( nNumRows ); for( int i = 0; i < nNumRows; ++i ) { orig.ExtractMyRowView( i, numIndices[i], indices[i] ); int j = 0; if( nNumCols ) { while( j < numIndices[i] && NewColMap_->GID(indices[i][j]) != -1 ) ++j; numIndices[i] = j; } } Epetra_CrsGraph * newGraph( new Epetra_CrsGraph( View, *NewRowMap_, *NewColMap_, &numIndices[0] ) ); //insert views of row indices for( int i = 0; i < nNumRows; ++i ) newGraph->InsertMyIndices( i, numIndices[i], indices[i] ); newGraph->FillComplete(); newObj_ = newGraph; return *newGraph; }
int main(int argc, char * argv[]){ FILE *in, *out; if(argc!=3){ printf("Usage Error: FindPath [inputFile] [outputFile]\n"); exit(1); } in = fopen(argv[1], "r"); out = fopen(argv[2], "w"); if(in==NULL){ printf("Unable to read the input file\n"); exit(1); } if(out==NULL){ printf("Unable to write to output file\n"); exit(1); } int size; int source; int vertex; fscanf(in, "%d", &size); Graph G = newGraph(size); while(1){ fscanf(in, "%d %d", &source, &vertex);; if(source==0 && vertex==0) break; addEdge(G, source, vertex); } printGraph(out, G); fprintf(out, "\n"); while(1){ fscanf(in, "%d %d", &source, &vertex); if(source==0 && vertex==0) break; BFS(G, source); if(getDist(G, vertex)==INF){ fprintf(out, "The distance from %d to %d is infinity\nNo %d - %d path exists\n\n", source, vertex, source, vertex); continue; } List L = newList(); getPath(L, G, vertex); fprintf(out, "The distance from %d to %d is %d\nThe shortest %d - %d path is: ", source, vertex, getDist(G, vertex), source, vertex); printList(out, L); fprintf(out, "\n\n"); freeList(&L); } freeGraph(&G); fclose(in); fclose(out); }
/* transpose() * Pos: none * Pre: transfers the tranpose of G to Graph T */ GraphRef transpose(GraphRef G){ int i; GraphRef T = newGraph(getOrder(G)); for(i=1; i<=getOrder(G); i++){ if(!isEmpty(G->adj[i])){ transposeHelp(T,G->adj[i],i); } } return T; }
/* copyGraph() * Pre: none * Pos: calls ListCopy to copy the adj list to a new graph */ GraphRef copyGraph(GraphRef G){ int i; GraphRef C = newGraph(getOrder(G)); for(i=1; i <= getOrder(G); i++){ if(!isEmpty(G->adj[i])){ C->adj[i] = copyList(G->adj[i]); } } return C; }
graphAlgorithms::graphAlgorithms(int vertCount): title(""), topoCount(0), vertexCount(0) { dist = NULL; topoNodes = NULL; graphMatrix = NULL; if(vertCount != 0) newGraph(vertCount); }
Graph* init() { Graph* g = newGraph(0); loadGraph(g, "mst.txt"); parent = (int*) malloc((g->nvertices+1) * sizeof(int)); int i; for (i = 0; i <= g->nvertices; i++) { parent[i] = -1; } return g; }
bool AbstractTwoLevelAgreement::readAnnotation(QString tagFileName,OutputDataList & tags,AbstractGraph * globalGraph) { AbstractGraph * dummyLocalGraph=newGraph(false); QFile file(tagFileName.toStdString().data()); if (file.open(QIODevice::ReadOnly)) { QDataStream in(&file); // we will serialize the data into the file tags.readFromStream(in,dummyLocalGraph); //HadithChainGraph provided but will not be in use after call just duplicated globalGraph->readFromStream(in); file.close(); delete dummyLocalGraph; return true; } return false; }
ShaderEditor::ShaderEditor(Lumix::IAllocator& allocator) : m_fragment_nodes(allocator) , m_vertex_nodes(allocator) , m_allocator(allocator) , m_undo_stack(allocator) , m_undo_stack_idx(-1) , m_current_node_id(-1) , m_is_focused(false) , m_is_opened(false) , m_current_shader_type(ShaderType::VERTEX) { newGraph(); }
/*main------------------------------------------------------------------------*/ int main(int argc, char* argv[]) { //input validation if (argc != 2) { printf("Usage: %s output\n", argv[0]); exit(1); } //open file FILE *out; out = fopen(argv[1], "w"); //new graph Graph G = newGraph(10); Graph T; List S = newList(); int i; for (i = 1; i <= 9; i++) { addArc(G, i, i + 1); } addArc(G, 1, 2); //add graph and print out the adjacency fields for (i = 1; i <= getOrder(G); i++) { append(S, i); } fprintf(out, "\nThe adjacency list of G is:\n"); printGraph(out, G); //Run DFS and get the transpose DFS(G, S); T = transpose(G); fprintf(out, "\nTranspose of G is:\n"); printGraph(out, T); //print out fields fprintf(out, "Order of G is %d\n", getOrder(G)); fprintf(out, "Size of G is %d.\n", getSize(G)); fprintf(out, "Parent of 10 is %d.\n", getParent(G, 10)); fprintf(out, "Parent of 3 is %d.\n", getParent(G, 3)); fprintf(out, "Discover time of 1 is %d.\n", getDiscover(G, 1)); fprintf(out, "Finish time of 1 is %d.\n", getFinish(G, 1)); fprintf(out, "Discover time of 9 is %d.\n", getDiscover(G, 9)); fprintf(out, "Finish time of 9 is %d.\n", getFinish(G, 9)); //close file fclose(out); //exit return (0); }
int main(int argc, char** argv) { int numVerts; int numQueries; int from; char edge[1024]; int to; int start; int end; char *filename = argv[1]; FILE *input = fopen(filename, "r"); int i = 0; char *c; if(input != NULL) { fscanf(input, "%d", &numVerts); fscanf(input, "%d", &numQueries); /*printf("%d %d\n", numVerts, numQueries);*/ Graph G = newGraph(numVerts); for(i = 0; i < numVerts; i++) { fscanf(input, "%d", &from); /*printf("%d ", from);*/ fgets(edge, 1024, input); c = strtok(edge, " \n"); while(c != NULL) { addEdge(G, from, atoi(c)); c = strtok(NULL, " \n"); } } for(i = 0; i < numQueries; i++) { fscanf(input, "%d", &start); fscanf(input, "%d", &end); doBFS(G, start); if(getDistance(G, end) > 0) { printf("The shortest path from %d to %d requires %d edges:\n", start, end, getDistance(G, end)); ListHndl L = getPathTo(G, end); } else { printf("No path from %d to %d exists.\n", start, end); } } } fclose(input); return(0); }
Graph shortestPath(Graph g, Vertex v) { Graph mst = newGraph(g->nV); // create a new mst graph Queue q = newQueue(); // create a new queue int *visitedVertices = malloc(sizeof(Vertex) * g->nV); int *dist = malloc(sizeof(int) * g->nV); // create the distance array int *pred = malloc(sizeof(int) * g->nV); // create the predecessor array, stores vertices passed through int total = 0, i = 0; Vertex curV = 0, w = 0; assert(visitedVertices != NULL && dist != NULL && pred != NULL); // clear all the memory blocks setArray(visitedVertices, UNVISITED, g->nV); setArray(dist, INF, g->nV); setArray(pred, -1, g->nV); visitedVertices[v] = VISITED; // mark the starting vertex as visited dist[v] = 0; enQueue(q, v); // add the starting vertex to the queue while ( !isEmptyQueue(q) ){ curV = deQueue(q); // remvoe first element from queue for (w = 0; w < getnV(g); w++){ if (g->wt[curV][w] == NO_WEIGHT) continue; if (dist[curV] + g->wt[curV][w] < dist[w]){ // edge relaxation dist[w] = dist[curV] + g->wt[curV][w]; pred[w] = curV; enQueue(q,w); } } } // add the appropriate edges for (i = 0; i < g->nV; i++){ if (pred[i] != NOT_ASSIGNED){ addEdge(mst, pred[i], i); total += dist[i]; } } deleteQueue(q); free(dist); free(pred); printf("Total = %d.\n", total); return mst; }
/* Note: * change priority queue implementation */ Graph shortestPathPQ(Graph g, Vertex v) { Graph mst = newGraph(g->nV); int *dist = malloc(sizeof(int) * g->nV); // create the distance array int *pred = malloc(sizeof(int) * g->nV); // create the predecessor array, stores vertices passed through PQueue q = newPQueue(); // create a new priority queue Vertex currentVertex = 0, w = 0; int i = 0; int total = 0; assert(dist != NULL && pred != NULL); // clear all the memory blocks setArray(dist, INF, g->nV); setArray(pred, -1, g->nV); dist[v] = 0; for (i = 0; i < g->nV; i++){ joinPQueue(q, i, dist[i]); } reorder(q, NO_UPDATE, NO_UPDATE); while ( !isEmptyPQ(q) ){ // while priority queue is not empty currentVertex = leavePQueue(q); for (w = 0; w < getnV(g); w++){ if (g->wt[currentVertex][w] == NO_WEIGHT) continue; if (g->wt[currentVertex][w] + dist[currentVertex] < dist[w]){ dist[w] = g->wt[currentVertex][w] + dist[currentVertex]; pred[w] = currentVertex; reorder(q, w, dist[w]); // updates the priority of vertex w as well } } reorder(q, NO_UPDATE, NO_UPDATE); } // construct the mst graph for (i = 0; i < getnV(g); i++){ if (pred[i] != NOT_ASSIGNED){ addEdge(mst, pred[i], i); total += dist[i]; } } printf("Total = %d.\n", total); deletePQueue(q); free(dist); free(pred); return mst; }
/* main program*/ int main(int argc, char *argv[]){ for(int i = 1; i < argc; i++){ // open file and read in numVerts and numQueries FILE* in = fopen(argv[i], "r"); int numVerts, numQueries; char tempLine[1024]; fgets(tempLine, 1024, in); sscanf(tempLine, "%d %d", &numVerts, &numQueries); // read in and make graph Graph Map = newGraph(numVerts); for(int i = 0; i < numVerts; i++){ fgets(tempLine, 1024, in); int vert = atoi(strtok(tempLine, " ")); char *tempTo = strtok(NULL, " "); while(tempTo != NULL){ addEdge(Map, vert, atoi(tempTo)); tempTo = strtok(NULL, " "); } } // process queries for(int i = 0; i < numQueries; i++){ int from, to; fscanf(in, "%d %d", &from, &to); doBFS(Map, from); if(getDistance(Map, to) == -1) printf("No path from %d to %d exists.\n\n", from, to); else{ printf("The shortest path from %d to %d requires %d edges: \n", from, to, getDistance(Map, to)); ListHndl L = getPathTo(Map, to); moveFirst(L); while(!atLast(L)){ printf("%d -> ", getCurrent(L)); moveNext(L); } printf("%d \n\n", getCurrent(L)); freeList(&L); } } /*free everythingggggggggggg*/ freeGraph(&Map); fclose(in); } /* end program */ return 0; }
int main(int argc, char **argv) { int v = 5; struct Graph *graph = newGraph(v); addEdge(graph, 0, 1); addEdge(graph, 0, 4); addEdge(graph, 1, 2); addEdge(graph, 1, 3); addEdge(graph, 1, 4); addEdge(graph, 2, 3); addEdge(graph, 3, 4); printGraph(graph); bfs(graph, 2); }
bool AbstractTwoLevelAgreement::readAnnotations() { annotatedGraph=newGraph(true); if (!readAnnotation(fileName+".tags",tags,annotatedGraph)){ _error << "Annotation File does not exist\n"; QFile file(QString("%1.tags").arg(fileName).toStdString().data()); if (file.open(QIODevice::WriteOnly)) { QDataStream out(&file); // we will serialize the data into the file out << outputList; generatedGraph->writeToStream(out);; file.close(); _error << "Annotation File has been written from current detected expressions, Correct it before use.\n"; } return false; } return true; }
int main(int argc, char * argv[]){ Graph g; printf("Test newGraph\n"); g = newGraph(); showGraph(g); assert(numV(g) == NUM_MAP_LOCATIONS); assert(numE(g,LAND) == 17); assert(numE(g, SEA) == 8); showIsAdjacent(g); printf("Passed\n"); printf("Destroying graph\n"); destroyGraph(g); printf("Finished destroy \n"); return 0; }
Graph* reverseGraph(Graph* g){ int i; List *aux; Graph *grafo = newGraph(g->nVertices); for(i=0;i<grafo->nVertices;i++){ aux=g->listaAdjac[i]; while(aux!=NULL){ if(aux->value != -1){ /*para ignorar a lista de adjacencias vazia*/ addToList(grafo->listaAdjac[(aux->value)-1],i+1); } aux=aux->next; } } return grafo; }
void DotFileGenerator::generate(SMDescription smDesc) { newGraph(smDesc.title); for( int i=0; i < smDesc.stateList.size(); i++) { addState(smDesc.stateList.at(i)); } out << endl; for( int i=0; i < smDesc.transitionList.size(); i++) { addTransition(smDesc.transitionList.at(i)); } endGraph(); }
int main() { FILE * in = fopen("input.txt", "r"); int numVerticies; fscanf(in,"%d", &numVerticies); Graph G = newGraph(numVerticies); buildGraph(in,G); Prim(G, 1); fclose(in); printf("\n\n\t***** COJ : 1480 - Dota Warlock Power *****\n\n"); system("PAUSE"); return 0; }