Пример #1
0
int main(void)
{    
	MGraph G;    
	CreateMGraph(&G);
	
	return 0;
}
int main(void)
{
	MGraph G;
	CreateMGraph(&G);
	MiniSpanTree_Kruskal(G);
	return 0;
}
Пример #3
0
int main()
{
    CreateQueue();
    CreateMGraph();
    ListComponents();
    return 0;
}
void test(void)
{
	MGraph G;
	CreateMGraph(&G);
//	DFSTraverse(G);
	BFSTraverse(G);
	MiniSpanTree_Prim(G);
}
int main(void)
{    
	MGraph G;    
	GraphAdjList GL;    
	CreateMGraph(&G);
	CreateALGraph(G,&GL);
	CriticalPath(GL);
	return 0;
}
int main(void)
{
	MGraph G;
	CreateMGraph(&G);
	MiniSpanTree_Prim(G);
  
	return 0;
 
}
int main(void)
{    
	MGraph G;
	CreateMGraph(&G);
	printf("\n深度遍历:");
	DFSTraverse(G);
	printf("\n广度遍历:");
	BFSTraverse(G);
	return 0;
}
int main(void)
{    
	MGraph G;  
	GraphAdjList GL; 
	int result;   
	CreateMGraph(&G);
	CreateALGraph(G,&GL);
	result=TopologicalSort(GL);
	printf("result:%d",result);

	return 0;
}
Пример #9
0
int main()
{
    int N, E, i, p, j;
    VertexType n1, n2;


    scanf("%d %d", &N, &E);
    MGraph G = CreateMGraph(N, E);
    while (E--)
    {
        scanf("%d %d %d", &n1, &n2, &p);
        SetEdge(G, n1 - 1, n2 - 1, p);
    }

    Floyd(G);
    int min = INFINITY, index = N;
    int flag = 0;
    for (int i = 0;i < G->numNodes; i++)
    {
        int t = 0;
        for (int j = 0; j < G->numNodes; j++)
        {
            if (i != j && D[i][j] == INFINITY)
            {
                flag = 1;
                break;
            }
            if (i != j && D[i][j] > t)
            {
                t = D[i][j];
            }
        }
        if (t < min)
        {
            min = t;
            index = i;
        }
    }
    if (flag)
        printf("0\n");
    else
        printf("%d %d",index + 1,min);

    return 0;
}
void main()
{
	MTGraph G;
	IniMGraph(&G);

	VertexData v[5]={'a', 'b', 'c', 'd', 'e'};
	EdgeData e[5][NumVertices]={
								{0, 1, 0, 1, 1},
								{1, 0, 1, 0, 0},
								{0, 1, 0, 0, 1},
								{1, 0, 0, 0, 1},
								{1, 0, 1, 1, 0}};
	CreateMGraph(&G, v, e, 5);
	PrintMT(&G);

	DFSTraverse(G);
	cout<<endl;

}
Пример #11
0
int main()
{
    int N, E, i, p, fee;
    VertexType n1, n2, v0, vf;
    int rescue[MAXVEX];

    scanf("%d %d %d %d", &N, &E, &v0, &vf);
    MGraph G = CreateMGraph(N, E);

    for (i = 0; i < N; i++)
        scanf("%d", &rescue[i]);

    while (E--)
    {
        scanf("%d %d %d", &n1, &n2, &p);
        SetEdge(G, n1, n2, p);
    }

    Dijkstra(G, v0, vf, rescue);

    return 0;
}
Пример #12
0
int main(int argc, char** argv)
{
	
	MGraph G;
	GraphAdjList GL;
	int i,j,s;
	int VertexNum;
	int Edge_num;
	int flag;
	int num_CNFSAT;
	int num_APPROX1;
	int num_APPROX2;
	float ratio1,ratio2;

	pthread_t thread_CNFSAT;
	pthread_t thread_APPROX1;
	pthread_t thread_APPROX2;

	clockid_t cid_CNFSAT;
	clockid_t cid_APPROX1;
	clockid_t cid_APPROX2;

	char str[10000];

    while (fgets(str,10000,stdin))
    {
	/*if (str[0] != 's')
        	printf("%s",str);
		fflush(stdout);*/
        if (str[0]=='V')
        {
           VertexNum = VStr(str);
	   //printf("%d \n",VertexNum);
        }
        else if (str[0]=='E')
        {
            Edge_num = ENum(str);
            flag = CreateMGraph(&G, Edge_num, VertexNum, str);
            CreateALGraph(G,&GL);	    
	    if (Edge_num > 0 && flag == 1)
	    {
		s = pthread_create (&thread_CNFSAT,NULL,&VerCover_CNFSAT,&G);
		if (s != 0)
               		handle_error_en(s, "pthread_create");
		/*s = pthread_getcpuclockid(thread_CNFSAT, &cid_CNFSAT);
		if (s != 0)
               		handle_error_en(s, "pthread_getcpuclockid");*/
		pthread_join(thread_CNFSAT,NULL);
		/*char ms1[] = "CNF-SAT-VC's CPU time:  ";
		pclock(ms1, cid_CNFSAT);
		sleep(1);*/
		
		s = pthread_create (&thread_APPROX1,NULL,&VerCover_APPROX1,&G);
		if (s != 0)
               		handle_error_en(s, "pthread_create");
		/*s = pthread_getcpuclockid(thread_APPROX1, &cid_APPROX1);
		if (s != 0)
               		handle_error_en(s, "pthread_getcpuclockid"); */
		pthread_join(thread_APPROX1,NULL);
		/*char ms2[] = "APPROX-VC-1's CPU time:  ";
		pclock(ms2, cid_APPROX1);
		sleep(1);*/
		
		s = pthread_create (&thread_APPROX2,NULL,&VerCover_APPROX2,&G);
		if (s != 0)
               		handle_error_en(s, "pthread_create");
		/*s = pthread_getcpuclockid(thread_APPROX2, &cid_APPROX2);
		if (s != 0)
               		handle_error_en(s, "pthread_getcpuclockid"); 
		char ms3[] = "APPROX-VC-2's CPU time:  ";*/		
		pthread_join(thread_APPROX2,NULL);	
		/*pclock(ms3, cid_APPROX2); 
		sleep(1);*/

		
		/*calculate the approximate ratio*/
		/*float x1, x2, x3;
		x1 = (float) g[0].vNum;
		x2 = (float) g[1].vNum;
		x3 = (float) g[2].vNum;

		char msg1[] = "Approximation ratio of APPROX1: ";
		char msg2[] = "Approximation ratio of APPROX2: ";

		ratio1 = x2/x1;
		pratio(msg1, ratio1);
		ratio2 = x3/x1;
		pratio(msg2, ratio2);*/

		//free(g);
		//g = NULL;
		
	    }
		//free(g);
		//g = NULL;
        }
        else if (str[0]=='s')
        {
            int str_size1;
            int str_size;
            int s_flag;
	    
            for (str_size = 0;str[str_size]!='\0';str_size++)
                {
                    str_size1 = str_size;
                }

            s_flag = 0;

            int flag1 = 1;

            while(str[s_flag]!= ' ')
            {
                s_flag++;
            }

            while(str[s_flag+flag1]!=' ')
            {
                flag1++;
            }

            int s1,s2;
            int firstNode = 0;
            int lastNode = 0;
            for (s1 = s_flag+1; s1 < s_flag + flag1; s1++)
            {
                firstNode = (int)(firstNode + (str[s1]-'0') * pow(10,s_flag + flag1-1-s1));
            }

            for (s2 = s_flag + flag1 + 1; s2 < str_size1;s2++)
            {
                lastNode = (int)(lastNode + (str[s2]-'0') * pow(10,str_size1-1-s2));
//                printf("%d %d %d\n",s2,str[s2]-'0',str_size1-1-s2);
            }
//            printf("%d %d\n",firstNode,lastNode);

            if(firstNode>=VertexNum || lastNode>=VertexNum)
            {
                printf("Error: one or more vertexes do not exist\n");
                continue;
            }

            if(firstNode == lastNode)
            {
                printf("%d-%d\n",firstNode,lastNode);		
                continue;
            }


            CreateALGraph(G,&GL);
            BFSTraverse(GL,firstNode,lastNode);
//	    VerCover(G, VertexNum); 
        }
    }
	return 0;
}
Пример #13
0
int main()
{
    MGraph G = CreateMGraph(10, 40);

    return 0;
}