本文整理汇总了C++中createGraph函数的典型用法代码示例。如果您正苦于以下问题:C++ createGraph函数的具体用法?C++ createGraph怎么用?C++ createGraph使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了createGraph函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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));
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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();
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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();
}
示例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;
}
示例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;
}
示例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]);
}
}
}
示例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;
}