int main(void) {
	GraphAdjList G;
	CreateALGraph(&G);

	system("pause");
	return 0;
}
int main(void)
{    
	MGraph G;    
	GraphAdjList GL;    
	CreateMGraph(&G);
	CreateALGraph(G,&GL);
	CriticalPath(GL);
	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;
}
Exemplo n.º 4
0
main()
{
 /* 此处添加你自己的代码 */
 int i;
 ALGraph alg;
 CreateALGraph(&alg);
 //PrintGraph(&alg);
 //for(i=0;i<alg.n;i++)
// finished[i]=-1;
 printf("深度优先遍历搜索图:\n");
 DFSTraAL(&alg);
 //for(i=0;i<alg.n;i++)
 //printf("\n%d",finished[i]);
getch();
}
Exemplo n.º 5
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;
}