コード例 #1
0
ファイル: bon_file.cpp プロジェクト: azat-archive/bonnie
int COpenTest::delete_random(BonTimer &timer)
{
  random_sort(timer.random_source);
  timer.start();
  int i;
  Duration dur;
  for(i = 0; i < m_number; i++)
  {
    dur.start();
    if(unlink(m_file_names[i]))
    {
      fprintf(stderr, "Can't delete file %s\n", m_file_names[i]);
      return -1;
    }
    if(m_sync && m_sync_dir)
    {
      if(fsync(m_directoryHandles[m_dirIndex[i]]))
      {
        fprintf(stderr, "Can't sync directory, turning off dir-sync.\n");
        m_sync_dir = false;
      }
    }
    dur.stop();
  }
  if(m_number_directories > 1)
  {
    char buf[6];
    for(i = 0; i < m_number_directories; i++)
    {
      sprintf(buf, "%05d", i);
      if(m_sync)
      {
        close(m_directoryHandles[i]);
      }
      if(rmdir(buf))
      {
        io_error("rmdir");
        return -1;
      }
    }
  }
  else
  {
    if(m_sync)
    {
      close(m_directoryHandles[0]);
    }
  }
  if(chdir("..") || rmdir(m_dirname))
  {
    io_error("rmdir");
    return -1;
  }
  delete m_dirname;
  m_dirname = NULL;
  sync();
  timer.stop_and_record(DelRand);
  timer.add_latency(DelRand, dur.getMax());
  return 0;
}
コード例 #2
0
ファイル: bon_file.cpp プロジェクト: azat-archive/bonnie
int COpenTest::stat_random(BonTimer &timer)
{
  random_sort(timer.random_source);
  timer.start();

  int i;
  Duration dur;
  for(i = 0; i < m_number; i++)
  {
    dur.start();
    if(-1 == stat_file(m_file_names[i]))
      return -1;
    dur.stop();
  }
  timer.stop_and_record(StatRand);
  timer.add_latency(StatRand, dur.getMax());
  return 0;
}
コード例 #3
0
ファイル: joker2.c プロジェクト: marvelliu/lilacsrc
//char * joker2q[9]= {"一张", "一对", "三张", "四张" , "五张", "六张", "七张", "八张", "九张"};
void start_game_joker2()
{
    int total;
    int i,j;
    int joker2[JOKER2_NUM];
    char buf[80];
    total=start_game_preparation();
    if (total<4 || total >4)
    {
        send_msg (-1,"桥牌只能4个人玩");
        kill_msg (-1);
        return;
    }
    //分拨
    j=0;
//	RINFO.deadnum=0;//标记出完人数
//	RINFO.deadpointer=0;
//	RINFO.mulenum=-1; //标记头供是哪一方的
    for (i=0; i<MAX_PLAYER; i++)
    {
        PINFO(i).flag=PEOPLE_ALIVE;
        if (j%2)
        {
            PINFO(i).flag |=PEOPLE_POLICE;
            RINFO.polices[(int)(j/2)]=i;
        }
        else
        {
            PINFO(i).flag |=PEOPLE_KILLER;
            RINFO.killers[(int)(j/2)]=i;
        }
        RINFO.mulelist[i]=j;//mulelist标记人的顺序号,对应牌堆 mulelist 编号->座位
        RINFO.secretvotelist[j]=i; //secretvotelist, 座位->编号
        j++;
        RINFO.deadlist[i]=-1; //deadlist记录出完顺序
    }
    //发牌
    for (i=0; i<JOKER2_NUM; i++)
        joker2[i]=i;
    random_sort (joker2, JOKER2_NUM);
    for (j=0; j<JOKER2_PER_PERSON; j++)
    {
        for (i=0; i<JOKER2_PERSON; i++)
        {
            RINFO.seq_action[i][j]=(char)joker2[i*JOKER2_PER_PERSON+j];
//红桃4在谁手里?
            if (joker2[i*JOKER2_PER_PERSON+j] == 16 )
                RINFO.numvoted=i;
        }

    }
    send_msg(mypos, "注意,设定杀手数为1可以禁止聊天, 设置警察数可以控制超时时间为10(n+1)秒");
    kill_msg(mypos);
    send_msg(-1,"\33[31;1m游戏开始了,人群中出现了52张扑克牌。\33[m");
    send_msg(-1, "\33[31;1m请双方看牌。\33[m");
//	send_msg(-1, "   出牌方法是直接输入字符串并回车。例如,单个的\"3\"代");
//	send_msg(-1, "表一张3,\"qq\"代表一对Q,\"239\"则代表用百搭2和3与9组");
//	send_msg(-1, "成的三张9。特殊的,用e表示小王,r代表大王, t或者0则代");
//	send_msg(-1, "表10。大小写可以任意。");
//	send_msg(-1, "\33[31;1m下面请红桃4先出牌。\33[m");
    kill_msg(-1);
    for(i=0; i<JOKER2_PERSON; i++)
    {
//		PINFO(i).vnum=JOKER2_PER_PERSON;
        joker2_sort_by_suit(RINFO.seq_action[i], PINFO(RINFO.secretvotelist[i]).vnum);
        joker2_showdeck(i, RINFO.secretvotelist[i]);
    }
//	RINFO.lastturntime=bbstime(NULL);
    goto_check();
}
コード例 #4
0
ファイル: jokerpig.c プロジェクト: marvelliu/lilacsrc
void start_game_jokerpig()
{
	int total;
	int i,j;
	int joker1[JOKERPIG_NUM];
	total=start_game_preparation();
	if (total<4 || total >4)
	{
		send_msg (-1,"拱猪目前只能4个人玩");
		kill_msg (-1);
		return;
	}
	MAX_JOKER_PLAYER=JOKERPIG_PERSON;
	JOKER_VALUE_STYLE=JOKER_VALUE_TOP_A;
	JOKER_VALUE_LEVEL=0;
	JOKER_VALID_STYLE=JOKER_VALID_NOJOKER_FULL;
	JOKER_TYPE_STYLE=JOKER_TYPE_BY_SUIT;
	//分拨
	j=0;
	ONTABLE_NUM=0;//标记出完人数
	for (i=0;i<MAX_PLAYER;i++)
	{
		if (PINFO(i).style !=-1)
		{
			PINFO(i).flag=PEOPLE_ALIVE;
			TABLE_POS_LIST[i]=j;//mulelist标记人的顺序号,对应牌堆 mulelist 编号->座位
			POS_LIST[j]=i; //secretvotelist, 座位->编号
			j++;
			JOKER_POINT_RECORD_TMP[i]=0;
		}
	}
	//发牌
	for (i=0;i<JOKERPIG_NUM;i++)
		joker1[i]=i;
	random_sort (joker1, JOKERPIG_NUM);
	for (j=0;j<JOKERPIG_PER_PERSON;j++)
	{
		for (i=0;i<MAX_JOKER_PLAYER;i++)
		{
			RDECKS[i][j]=(char)joker1[i*JOKERPIG_PER_PERSON+j];
//红桃2在谁手里?
			if (joker1[i*JOKERPIG_PER_PERSON+j] == 14 )
					CURRENT_TABLEPOS=i;
		}
		
	}
	//send_msg(mypos, "注意,设定杀手数为1可以禁止聊天, 设置警察数可以控制超时时间为10(n+1)秒");
	//kill_msg(mypos);
	send_msg(-1,"\33[31;1m游戏开始了,人群中出现了52张扑克牌。\33[m");
	send_msg(-1, "\33[31;1m请双方看牌。\33[m");
	send_msg(-1, "   出牌方法是直接输入字符串并回车。例如,\"H3\"代");
	send_msg(-1, "表红桃3,\"DA\"代表方块,\"cq\"代表草花Q,\"ST\"就是黑桃10");
	send_msg(-1, "t或者0代表10。大小写可以任意。");
	send_msg(-1, "按Ctrl-T可以查看累计得分。");
	kill_msg(-1);
	for(i=0;i<MAX_JOKER_PLAYER;i++)
	{
		RDECKS_COUNT(POS_LIST[i])=JOKERPIG_PER_PERSON;
	}
	set_turn_time();
	goto_night();
}
コード例 #5
0
ファイル: slpa.cpp プロジェクト: yxl3210230/GitHubVS2013
int main()
{
	NETWORK *net;
	//MEMORY_SLPA *mem;	
	PROCESSING_QUEUE *que;
	NEIGHBOR_VERTICES *nei;
	LABEL_PROBABILITIES *pro,*pro1;
	SEND_LIST *sendlist;
	RESULT_VERTEX *result1, *comp1;
	RESULT_COMMUNITY *result2, *comp2;
	COEFFICIENT1 *co1;
	COEFFICIENT2 *co2;
	DELETE_LIST *dellist;

	int i,j,iterator,c,k,*synlist;
	float nmi;

	//int MAX_T;

	FILE *fp,*fout;
	//if((fp=fopen("dolphins.gml","r"))==NULL)
	if((fp=fopen("network0.dat","r"))==NULL)
	{
		printf("can not open file\n");
		system("pause");
		exit(0);
	}

	if((fout=fopen("output.txt","w"))==NULL)
	{
		printf("can not open file\n");
		system("pause");
		exit(0);
	}

	net=(NETWORK *)malloc(sizeof(NETWORK));
	//mem=(MEMORY_SLPA *)malloc(sizeof(MEMORY_SLPA));
	que=(PROCESSING_QUEUE *)malloc(sizeof(PROCESSING_QUEUE));
	nei=(NEIGHBOR_VERTICES *)malloc(sizeof(NEIGHBOR_VERTICES));
	pro=(LABEL_PROBABILITIES *)malloc(sizeof(LABEL_PROBABILITIES));
	pro1=(LABEL_PROBABILITIES *)malloc(sizeof(LABEL_PROBABILITIES));
	//pro->index=NULL;
	//pro->probability=NULL;

	sendlist=(SEND_LIST *)malloc(sizeof(SEND_LIST));
	result1=(RESULT_VERTEX *)malloc(sizeof(RESULT_VERTEX));
	comp1=(RESULT_VERTEX *)malloc(sizeof(RESULT_VERTEX));
	result2=(RESULT_COMMUNITY *)malloc(sizeof(RESULT_COMMUNITY));
	comp2=(RESULT_COMMUNITY *)malloc(sizeof(RESULT_COMMUNITY));
	co1=(COEFFICIENT1 *)malloc(sizeof(COEFFICIENT1));
	co2=(COEFFICIENT2 *)malloc(sizeof(COEFFICIENT2));
	dellist=(DELETE_LIST *)malloc(sizeof(DELETE_LIST));

	MEMORY_VERTEX *mem1;
	mem1=(MEMORY_VERTEX *)malloc(sizeof(MEMORY_VERTEX));

	printf("Reading network...");
	read_network_bn(net,fp);
	//read_network(net,fp);
	//show_network(net,fout);
	printf("finish!\n");

	fclose(fp);

	if((fp=fopen("community0.dat","r"))==NULL)
	{
		printf("can not open file\n");
		system("pause");
		exit(0);
	}
	
	printf("Reading communities of BN...");
	read_communities(comp1,fp);
	community_statistics(comp1,comp2);
	//show_result_vertex(comp1,fout);
	//show_result_community(comp2,fout);
	printf("finish!\n");

	//sort_network(net,1);
	printf("Calculating coefficients...");
	calculate_coefficient(net,co1,co2);
	printf("finish!\n");

	dellist->nvertices=net->nvertices;
	dellist->nlabels=(int *)calloc(dellist->nvertices,sizeof(int));
	dellist->label=(int **)malloc(dellist->nvertices*sizeof(int *));

	//for(i=0;i<co1->nvertices;i++){
	//	
	//	fprintf(fout,"%d %f\n",i,co1->coefficients[i]);
	//}
	//fprintf(fout,"asdasdasdd\n");
	//for(i=0;i<co2->nvertices;i++){
	//	for (j=0;j<co2->degrees[i];j++)
	//	{
	//		fprintf(fout,"%f ",co2->coefficients[i][j]);
	//	}
	//	fprintf(fout,"\n");
	//}
	//
	//MAX_T=0;
	//while(MAX_T<100){
	//	MAX_T++;
	c=10;
	while(c--){

	synlist=(int *)malloc(net->nvertices*sizeof(int));
	printf("Initialing memory...");
	//initial_memory(mem, net->nvertices);
	//show_memory(mem,fout);
	initial_memory1(mem1, net->nvertices);
	//show_memory1(mem1,fout);
	printf("finish!\n");

	initial_queue(que, net->nvertices);

	iterator=MAX_T;

	printf("Calculating...");
	while(iterator--){

		//处理队列随机排序
		random_sort(que);
		//show_queue(que);

		for(i=0;i<que->length;i++){
			//查找邻节点
			find_neighbor(net,nei,que->queue[i]);
			//printf("%d ",que->queue[i]);
			//show_neighbor(nei);

			sendlist->num=nei->degree;
			sendlist->list=(SL_ELEMENT *)malloc(nei->degree*sizeof(SL_ELEMENT));

			for(j=0;j<nei->degree;j++){
				//计算概率
				//count_probabilities(pro,mem,nei->neighbor[j],MAX_T-iterator);
				count_probabilities1(pro1,mem1,nei->neighbor[j]);
				//printf("pro1: ");
				//for(k=0;k<pro->numlabel;k++){
				//	printf("%d %f ",pro->index[k],pro->probability[k]);
				//}
				//printf("\npro2: ");
				//for(k=0;k<pro1->numlabel;k++){
				//	printf("%d %f ",pro1->index[k],pro1->probability[k]);
				//}
				//printf("\n");
				//if(!pro_compare(pro,pro1)){
				//	printf("%d %d %d %d",iterator,i,j,nei->neighbor[j]);
				//	system("pause");
				//}

				//根据概率发送标签至sendlist
				k=send_label(pro1,&sendlist->list[j].index);
				sendlist->list[j].weight=(1+co2->coefficients[que->queue[i]][j])*pro1->probability[k];
				//sendlist->list[j].weight=1+co2->coefficients[que->queue[i]][j];
				sendlist->list[j].weight2=co1->coefficients[nei->neighbor[j]];

				//send_label(pro1,&sendlist->list[j].index);

				free(pro1->index);
				free(pro1->probability);

			}
			//show_sendlist(sendlist,fout);
			free(nei->neighbor);

			//记录dellist
			//count_delete_vertices(mem1,sendlist,dellist,que->queue[i]);

			//从sendlist中选择标签
			//j=receive_label(sendlist);
			j=receive_label_old(sendlist);

			//异步写入memory
			//mem->memory[que->queue[i]][MAX_T-iterator]=j;
			//add_label(mem1,que->queue[i],j);

			//记录同步列表synlist
			synlist[que->queue[i]]=j;
			free(sendlist->list);
		}
		//同步接收标签
		add_label_syn(mem1,synlist);

		//删除dellist中的标签
		//delete_vertices(mem1,dellist);

		//重置dellist
		//reset_delete_list(dellist);
	}
	free(synlist);
	free(que->queue);

	show_memory1(mem1,fout);
	printf("finish!\n");

	result1->nvertices=mem1->nvertices;
	result1->numbelong=(int *)malloc(result1->nvertices*sizeof(int));
	result1->communities=(int **)malloc(result1->nvertices*sizeof(int*));

	printf("Post processing...");
	for(i=0;i<result1->nvertices;i++){
		//count_probabilities(pro,mem,net->vertex[i].id,MAX_T+1);
		count_probabilities1(pro,mem1,net->vertex[i].id);
		post_processing(pro,result1,i,0.05);
	}
	printf("finish!\n");

	free(pro->index);
	free(pro->probability);

	//for(i=0;i<mem->nvertices;i++){
	//	free(mem->memory[i]);
	//}
	//free(mem->memory);
	destroy_memory(mem1);

	//printf("Output results...");
	//show_result_vertex(result1,fout);
	community_statistics(result1,result2);
	//show_result_community(result2,fout);

	nmi=1-(result_comparison(comp2,result2,net->nvertices)+result_comparison(result2,comp2,net->nvertices))/2;
	fprintf(fout,"%f\t",nmi);

	//删除被完全包含的社区
	result_processing(result1,result2);
	//show_result_community(result2,fout);
	//printf("finish!\n");

	
	printf("Calculating NMI...");
	//log((float)exp((float)1));
	nmi=1-(result_comparison(comp2,result2,net->nvertices)+result_comparison(result2,comp2,net->nvertices))/2;
	printf("finish!\n");

	fprintf(fout,"%f\n",nmi);

	for(i=0;i<result1->nvertices;i++){
		free(result1->communities[i]);
	}
	free(result1->communities);
	free(result1->numbelong);
		
	for(i=0;i<result2->ncommunities;i++){
		free(result2->vertices[i]);
	}
	free(result2->vertices);
	free(result2->nvertices);

	}
//}

	for(i=0;i<comp1->nvertices;i++){
		free(comp1->communities[i]);
	}
	free(comp1->communities);
	free(comp1->numbelong);

	for(i=0;i<comp2->ncommunities;i++){
		free(comp2->vertices[i]);
	}
	free(comp2->vertices);
	free(comp2->nvertices);

	free(dellist->label);
	free(dellist->nlabels);
	free(dellist);

	free(mem1);
	free(que);
	free(nei);
	free(sendlist);
	free_network(net);
	fclose(fout);
	fclose(fp);
	//printf("hello world!!");
	system("pause");
	return 0;
}