本文整理汇总了C++中createGraph函数的典型用法代码示例。如果您正苦于以下问题:C++ createGraph函数的具体用法?C++ createGraph怎么用?C++ createGraph使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了createGraph函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: main
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));
}
开发者ID:ciaranm,项目名称:cp2015-subgraph-isomorphism,代码行数:56,代码来源:main.c
示例2: main
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;
}
开发者ID:ksksaurav,项目名称:performer,代码行数:56,代码来源:t.c
示例3: test_createGraph
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;
}
开发者ID:tanerius,项目名称:graph_db,代码行数:14,代码来源:test.cpp
示例4: main
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;
}
开发者ID:irakr,项目名称:My-safety-locker,代码行数:26,代码来源:graph_adj_list.cpp
示例5: main
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;
}
开发者ID:somnath-saha,项目名称:Algorithms-Design-and-Analysis-Part-1,代码行数:29,代码来源:graphSCC_dev.c
示例6: createGraph
//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();
}
开发者ID:mountassir,项目名称:gmonitor,代码行数:9,代码来源:gpu.cpp
示例7: kargerMinCut
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;
}
开发者ID:jneighbs,项目名称:algorithms,代码行数:16,代码来源:graph.c
示例8: buildTrustGraph
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;
}
开发者ID:Tmichailidis,项目名称:Software-Development,代码行数:30,代码来源:Query4.c
示例9: makeGraphFromArray
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;
}
开发者ID:sreejithmm,项目名称:AlgorithmDS,代码行数:25,代码来源:snakesandladder.c
示例10: main
// 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;
}
开发者ID:valiok98,项目名称:Algorithms-asm-etc,代码行数:30,代码来源:unionfind.cpp
示例11: main
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();
}
开发者ID:kratitripathi,项目名称:Bellman-Ford-Algorithm,代码行数:27,代码来源:programCode.cpp
示例12: main
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;
}
开发者ID:rickchung,项目名称:OnlineJudgePool,代码行数:33,代码来源:Q315_Network.c
示例13: main
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;
}
开发者ID:rhobernardi,项目名称:Trabalhos_Grafos,代码行数:35,代码来源:main.c
示例14: main
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]);
}
}
}
开发者ID:luongli,项目名称:Cprograming,代码行数:31,代码来源:testcase2.c
示例15: createMinSpanningTree
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;
}
开发者ID:AlbertMukhammadiev,项目名称:University,代码行数:32,代码来源:graph.cpp
示例16: main
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;
}
开发者ID:arjunvijayvargiya,项目名称:DataStructureAndAlgorithmNK,代码行数:26,代码来源:topologicalsortermyversion.cpp
示例17: fileRead
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;
}
开发者ID:ben-nakash,项目名称:Communication-Laboratory,代码行数:60,代码来源:ex2.c
示例18: main
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;}
开发者ID:devarsh13,项目名称:Parallel-Travelling-Salesman-Problem,代码行数:29,代码来源:TSP_serial.c
示例19: readFile
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);
}
开发者ID:djornada,项目名称:dangerous-relationships,代码行数:29,代码来源:main.c
示例20: main
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");
}
开发者ID:Parlefan,项目名称:cpp,代码行数:29,代码来源:MGraph.cpp
注:本文中的createGraph函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论