• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C++ deque类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C++中deque的典型用法代码示例。如果您正苦于以下问题:C++ deque类的具体用法?C++ deque怎么用?C++ deque使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了deque类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。

示例1: printTour

void printTour(deque<int> tour) {
	printf("Tour: ");
	for(deque<int>::iterator it=tour.begin(); it!=tour.end(); it++) printf("%d ",*it);
	printf("\n");
}
开发者ID:czajkovsky,项目名称:tsp,代码行数:5,代码来源:farthestInsertion.cpp


示例2: build_subgraph

int build_subgraph(deque<set<int> > & E, const deque<int> & nodes, const deque<int> & degrees) {
	
	
	/*
	cout<<"nodes"<<endl;
	prints(nodes);
	
	cout<<"degrees"<<endl;
	prints(degrees);
	*/
	

	
	if(degrees.size()<3) {
		
		cerr<<"it seems that some communities should have only 2 nodes! This does not make much sense (in my opinion) Please change some parameters!"<<endl;
		return -1;
	
	}
	
	// this function is to build a network with the labels stored in nodes and the degree seq in degrees (correspondence is based on the vectorial index)
	// the only complication is that you don't want the nodes to have neighbors they already have
	
	
	
	// labels will be placed in the end
	deque<set<int> > en; // this is the E of the subgraph

	{
		set<int> first;
		for(int i=0; i<nodes.size(); i++) 
			en.push_back(first);
	}
	
	
	
	multimap <int, int> degree_node;
	
	for(int i=0; i<degrees.size(); i++)
		degree_node.insert(degree_node.end(), make_pair(degrees[i], i));
	
	int var=0;

	while (degree_node.size() > 0) {
		
		multimap<int, int>::iterator itlast= degree_node.end();
		itlast--;
		
		multimap <int, int>::iterator itit= itlast;
		deque <multimap<int, int>::iterator> erasenda;
		
		int inserted=0;
		
		for (int i=0; i<itlast->first; i++) {
			
			if(itit!=degree_node.begin()) {
			
				itit--;
				
				
				en[itlast->second].insert(itit->second);
				en[itit->second].insert(itlast->second);
				inserted++;
				
				erasenda.push_back(itit);				
				
			}
			
			else
				break;
		
		}
		
		
		for (int i=0; i<erasenda.size(); i++) {
			
			
			if(erasenda[i]->first>1)
				degree_node.insert(make_pair(erasenda[i]->first - 1, erasenda[i]->second));
	
			degree_node.erase(erasenda[i]);
		
		}

		var+= itlast->first - inserted;
		degree_node.erase(itlast);
		
	}
    
    
    // ----------------------------------------------------------
    deque<int> degree_list;
    for(int kk=0; kk<degrees.size(); kk++)
        for(int k2=0; k2<degrees[kk]; k2++)
            degree_list.push_back(kk); 
	
    
	// this is to randomize the subgraph -------------------------------------------------------------------
	
	for(int run=0; run<10; run++) for(int node_a=0; node_a<degrees.size(); node_a++) for(int krm=0; krm<en[node_a].size(); krm++) {
//.........这里部分代码省略.........
开发者ID:BB90,项目名称:CommunityDetectionCodes,代码行数:101,代码来源:standard_bench.cpp


示例3: while

Segment*
Segment::new_segment(MorphoStream &ms, TransferRules* tr,  TaggerData &td) {
  TaggerWord *word=NULL;
  set<TTag> tags;
  set<TTag>::iterator itag;
  vector<TTag> auxvec;

  static int index_start=1;
  static deque<TaggerWord> wordsbuffer;
  static bool first_call=true;
  static bool end_of_corpus_reached=false;


  if (first_call) {
    TaggerWord eosword;
    eosword.add_tag(td.getTagIndex()[L"TAG_SENT"], L"", td.getPreferRules());
    wordsbuffer.push_back(eosword);

    //Fill the buffer of words
    while (wordsbuffer.size()<TAGGER_WORD_BUFFER_SIZE) {
      word=ms.get_next_word();
            
      if(word==NULL) {
	end_of_corpus_reached=true;
	break;
      }

      wordsbuffer.push_back(*word);
      delete word;
    }

    first_call=false;
  }

  /*
    cerr<<"BUFFER (begining): ";
    for (int i=0; i<wordsbuffer.size(); i++) {
    cerr<<"["<<wordsbuffer[i].get_superficial_form()<<"] ";
    }
    cerr<<"\n";
    cerr<<"Buffer size (begining): "<<wordsbuffer.size()<<"\n";
    cerr<<"Index start (begining): "<<index_start<<"\n";
  */

  Segment* seg=new Segment();
  int number_of_paths=1; 
   
  int segmentation_point=-1;
  int advance; //Number of word that can be skipped when looking for a segmentation point
  for(size_t i=index_start; i<wordsbuffer.size(); i++) {
    if (tr->is_segmentation_point(tag_index[L"TAG_kEOF"], wordsbuffer, i, advance)) {
      segmentation_point=i;
      break;
    } else{
      i+=advance;
    }
  }

  if ((segmentation_point==-1) && (!end_of_corpus_reached)) {
    cerr<<"Error: No segmentation point was found.\n";
    cerr<<"Try making the buffer longer, current maximum size is "<<TAGGER_WORD_BUFFER_SIZE<<"\n";
    cerr<<"See Segment.H, TAGGER_WORD_BUFFER_SIZE constant\n";
    exit(EXIT_FAILURE);
  }

  //cerr<<"Segmentation point: "<<segmentation_point<<"\n";

  //The segment to return is from index_start to segmentation_point
  for(int i=index_start; i<=segmentation_point; i++) {
    tags=wordsbuffer[i].get_tags();
    seg->contador_caminos.push_back(auxvec);
    if (tags.size()>0) {
      number_of_paths*=tags.size();
      for(itag=tags.begin(); itag!=tags.end(); itag++)
	seg->contador_caminos.back().push_back(*itag);
    } else {
      //seg->contador_caminos.back().push_back(-1); //Palabra desconocida

      tags=td.getOpenClass();
      number_of_paths*=tags.size();

      for(itag=tags.begin(); itag!=tags.end(); itag++)
	seg->contador_caminos.back().push_back(*itag);
    }
    seg->vwords.push_back(wordsbuffer[i]);
  }
  
  //Calculate which words can be removed from the buffer, we need some
  //words before the segment being return, more concretely, from the
  //last non-ambiguous word until the first word of the segment being
  //returned
  int preserve_word_from=-1;
  for (int i=(index_start-1); i>=0; i--) {
    if (wordsbuffer[i].get_tags().size()==1) {
      preserve_word_from=i;
      break;
    }
  }

  //cerr<<"Preserve words from index: "<<preserve_word_from<<"\n";
//.........这里部分代码省略.........
开发者ID:tuxskar,项目名称:apertium-code-challenge,代码行数:101,代码来源:Segment.C


示例4: erase_links

int erase_links(deque<set<int> > & E, const deque<deque<int> > & member_list, const bool excess, const bool defect, const double mixing_parameter) {

	
	int num_nodes= member_list.size();
	
	int eras_add_times=0;
	
	if (excess) {
		
		for (int i=0; i<num_nodes; i++) {
			
			
			while ( (E[i].size()>1) &&  double(internal_kin(E, member_list, i))/E[i].size() < 1 - mixing_parameter) {
			
			//---------------------------------------------------------------------------------
				
				
				cout<<"degree sequence changed to respect the option -sup ... "<<++eras_add_times<<endl;
				
				deque<int> deqar;
				for (set<int>::iterator it_est=E[i].begin(); it_est!=E[i].end(); it_est++)
					if (!they_are_mate(i, *it_est, member_list))
						deqar.push_back(*it_est);
				
				
				if(deqar.size()==E[i].size()) {	// this shouldn't happen...
				
					cerr<<"sorry, something went wrong: there is a node which does not respect the constraints. (option -sup)"<<endl;
					return -1;
				
				}
				
				int random_mate=deqar[irand(deqar.size()-1)];
				
				E[i].erase(random_mate);
				E[random_mate].erase(i);
				
		
			}
		}
	
	}
	
	
	
	if (defect) {
			
		for (int i=0; i<num_nodes; i++)
			while ( (E[i].size()<E.size()) &&  double(internal_kin(E, member_list, i))/E[i].size() > 1 - mixing_parameter) {
				
				//---------------------------------------------------------------------------------
					
				
				cout<<"degree sequence changed to respect the option -inf ... "<<++eras_add_times<<endl;


				int stopper_here=num_nodes;
				int stopper_=0;
				
				int random_mate=irand(num_nodes-1);
				while ( (    (they_are_mate(i, random_mate, member_list)) || E[i].find(random_mate)!=E[i].end())      &&      (stopper_<stopper_here) ) {
					
					random_mate=irand(num_nodes-1);
					stopper_++;
				
				
				}
				
				if(stopper_==stopper_here) {	// this shouldn't happen...
				
					cerr<<"sorry, something went wrong: there is a node which does not respect the constraints. (option -inf)"<<endl;
					return -1;
				
				}
				
				
				
				E[i].insert(random_mate);
				E[random_mate].insert(i);
				
								
		
			}
			
		
	}

	//------------------------------------ Erasing links   ------------------------------------------------------

	


	return 0;
	
}
开发者ID:BB90,项目名称:CommunityDetectionCodes,代码行数:95,代码来源:standard_bench.cpp


示例5: build_bipartite_network

int build_bipartite_network(deque<deque<int> >  & member_matrix, const deque<int> & member_numbers, const deque<int> &num_seq) {

	
	
	// this function builds a bipartite network with num_seq and member_numbers which are the degree sequences. in member matrix links of the communities are stored
	// this means member_matrix has num_seq.size() rows and each row has num_seq[i] elements
	
	
	
	deque<set<int> > en_in;			// this is the Ein of the subgraph
	deque<set<int> > en_out;		// this is the Eout of the subgraph
	
	
	{
		set<int> first;
		for(int i=0; i<member_numbers.size(); i++) {
			en_in.push_back(first);
		}
	}
	
	{
		set<int> first;
		for(int i=0; i<num_seq.size(); i++) {
			en_out.push_back(first);
		}
	}

	
	
	multimap <int, int> degree_node_out;
	deque<pair<int, int> > degree_node_in;
	
	for(int i=0; i<num_seq.size(); i++)
		degree_node_out.insert(make_pair(num_seq[i], i));
	
	for(int i=0; i<member_numbers.size(); i++)
		degree_node_in.push_back(make_pair(member_numbers[i], i));
	
	
	sort(degree_node_in.begin(), degree_node_in.end());
	
	
	
	deque<pair<int, int> >::iterator itlast = degree_node_in.end();
	
	/*
	for (int i=0; i<degree_node_in.size(); i++)
		cout<<degree_node_in[i].first<<" "<<degree_node_in[i].second<<endl;
	*/
	
	
	
	while (itlast != degree_node_in.begin()) {
		
		itlast--;
		
		
		multimap <int, int>::iterator itit= degree_node_out.end();
		deque <multimap<int, int>::iterator> erasenda;
		
		for (int i=0; i<itlast->first; i++) {
			
			if(itit!=degree_node_out.begin()) {
				
				itit--;
				
					
				en_in[itlast->second].insert(itit->second);
				en_out[itit->second].insert(itlast->second);
					
				erasenda.push_back(itit);
				
			}
			
			else
				return -1;
		
		}
		
		
		//cout<<"degree node out before"<<endl;
		//prints(degree_node_out);
		
		for (int i=0; i<erasenda.size(); i++) {
			
			
			if(erasenda[i]->first>1)
				degree_node_out.insert(make_pair(erasenda[i]->first - 1, erasenda[i]->second));
	
			
			degree_node_out.erase(erasenda[i]);

			
		
		}
		
		//cout<<"degree node out after"<<endl;
		//prints(degree_node_out);
		
	}
//.........这里部分代码省略.........
开发者ID:BB90,项目名称:CommunityDetectionCodes,代码行数:101,代码来源:standard_bench.cpp


示例6: push

void push(deque<p>& q,uc x,uc y){
    p p1;p1.x=x;p1.y=y;q.push_back(p1);
}
开发者ID:mdyang,项目名称:oj-solutions,代码行数:3,代码来源:main.cpp


示例7: ridgeIdsForFacet

void convexHull4d::createNewFacets(deque<long>& horizonRidges, vertex4d* furthest, vector<long>& facetIdList, deque<long>& bucketLessVertices, double testNormal[4])
{
//	cout<<"size of horizon ridgeS when creating:"<<horizonRidges.size()<<endl;
	for(deque<long>::iterator hrit=horizonRidges.begin(); hrit!= horizonRidges.end(); hrit++)
	{
		vector<long> vertexIndices;
		vector<long> ridgeIdsForFacet(4);
		vertexIndices.push_back(tempRidges.find((*hrit))->second.getVertexList()[0]);
		vertexIndices.push_back(tempRidges.find((*hrit))->second.getVertexList()[1]);
		vertexIndices.push_back(tempRidges.find((*hrit))->second.getVertexList()[2]);
		vertexIndices.push_back(furthest->getId());
		sort(vertexIndices.begin(), vertexIndices.end());
		long facetId = generateId(&vertexIndices);
		vertexIndices.clear();
		facet *newFacet = new facet();
		newFacet->setId(facetId);
		tempFacets.insert(pair<long,facet>(facetId, *newFacet));
		newFacet=&tempFacets.find(facetId)->second;
		if(tempRidges.find((*hrit))->second.getNeighbour1())
		{
			tempRidges.find((*hrit))->second.setNeighbour2(newFacet->getId());
			newFacet->insertContaining2dSimplex(*hrit);
		}
		else
		{
			tempRidges.find((*hrit))->second.setNeighbour1(newFacet->getId());
			newFacet->insertContaining2dSimplex(*hrit);
		}
		for(int i=0; i<3; i++)
		{
			for(int j=0,k=0; k<2; j++,k++)
			{
				if(j==i)
				{
					k--;
					continue;
				}
				vertexIndices.push_back(tempRidges.find((*hrit))->second.getVertexList()[j]);
			}
			vertexIndices.push_back(furthest->getId());
			sort(vertexIndices.begin(),vertexIndices.end());
			ridge *newRidge;
//			newRidge->setId(&vertexIndices);
			long tempId = generateId(&vertexIndices);

			if(tempRidges.find(tempId)==tempRidges.end())
			{
				newRidge = new ridge();
				newRidge->setId(tempId);
				tempRidges.insert(pair<long,ridge>(tempId,*newRidge));
				newRidge = &tempRidges.find(tempId)->second;
				for(vector<long>::iterator viter = vertexIndices.begin(); viter!=vertexIndices.end(); viter++)
				{
					newRidge->getVertexList().push_back(*viter);
				}
			}
			else
			{
				newRidge = &tempRidges.find(tempId)->second;
			}
			vertexIndices.clear();
			if(newRidge->getNeighbour1()==0)
				newRidge->setNeighbour1(newFacet->getId());
			else
				newRidge->setNeighbour2(newFacet->getId());
			newFacet->insertContaining2dSimplex(newRidge->getId());
		}
		deque<vertex4d>::pointer v[4];
		v[0]= &(verticesOfHull.find(furthest->getId())->second);
		for(int i=1; i<4; i++)
		{
			v[i]=&(verticesOfHull.find(tempRidges.find(*hrit)->second.getVertexList()[i-1])->second);
		}
		newFacet->calcNormOffset(v, centroid);
		facetIdList.push_back(newFacet->getId());
		for(deque<long>::iterator blvit=bucketLessVertices.begin(); blvit!=bucketLessVertices.end(); blvit++)
		{
			if(!verticesOfHull.find(*blvit)->second.getBucketAssignmentStatus() &&verticesOfHull.find(*blvit)->second.isAbove(newFacet))
			{
				newFacet->putInBucket((*blvit));
				verticesOfHull.find(*blvit)->second.insertVisibleFacet(newFacet->getId());
				verticesOfHull.find(*blvit)->second.setAssignedToBucket(true);
			}
		}
		setFurthestPoint(newFacet->getId());
	}
	for(deque<long>::iterator blvit=bucketLessVertices.begin(); blvit!=bucketLessVertices.end(); blvit++)
	{
		if(verticesOfHull.find(*blvit)->second.getBucketAssignmentStatus()==false)
		{
			verticesOfHull.find(*blvit)->second.getVisibleFacets().clear();
			verticesOfHull.find(*blvit)->second.setAssignedToBucket(true);
		}
	}
}
开发者ID:pH-,项目名称:Vartet,代码行数:95,代码来源:quickhull.cpp


示例8: center_mat

deque<deque<int>> center_mat(deque<deque<int>> src_mat){
    deque<deque<int>> t_mat;
    deque<int> vec_zero;
    int marge_gauche=0;
    int marge_droite=0;
    int marge_haut=0;
    int marge_bas=0;
    int delta_x = 0;
    int delta_y = 0;
    int temp_size;
    bool stop;
    stop = false;
    //Marge Gauche
    for(int i=0;i<src_mat.size();i++){
        for(int j=0;j<src_mat[i].size();j++){
            if(!stop && src_mat[j][i]){
                marge_gauche = i;
                stop = true;
            }
        }
    }
    stop = false;
    //Marge Droite
    for(int i=src_mat.size()-1;i>=0;i--){
        for(int j=0;j<src_mat[i].size();j++){
            if(!stop && src_mat[j][i]){
                marge_droite = src_mat.size()-i;
                stop = true;
            }
        }
    }
    stop = false;
    //Marge Haut
    for(int i=0;i<src_mat.size();i++){
        for(int j=0;j<src_mat[i].size();j++){
            if(!stop && src_mat[i][j]){
                marge_haut = i;
                stop = true;
            }
        }
    }
    stop = false;
    //Marge Bas
    for(int i=src_mat.size()-1;i>=0;i--){
        for(int j=0;j<src_mat[i].size();j++){
            if(!stop && src_mat[i][j]){
                marge_bas = src_mat.size()-i;
                stop = true;
            }
        }
    }

    delta_x = (marge_droite-marge_gauche)/2;
    delta_y = (marge_bas-marge_haut)/2;
    cout << delta_x << endl;
    cout << delta_y << endl;
    vec_zero.resize(src_mat.size());
    temp_size = src_mat.size();
    // Lignes de zeros
    if(delta_y>0){
        for(int i=0;i<delta_y;i++){
            src_mat.push_front(vec_zero);
        }
        src_mat.resize(temp_size);
    }else{
        for(int i=0;i<-delta_y+1;i++){
            src_mat.push_back(vec_zero);
        }
        src_mat.erase(src_mat.begin(),src_mat.begin()-delta_y);
    }
    
    // Colonnes de zeros
    if(delta_x>0){
        for (int i=0; i<src_mat.size(); i++){
            for(int j=0;j<delta_x;j++){
                src_mat[i].push_front(0);
            }
            src_mat[i].resize(temp_size);
        }
    }else{
        for (int i=0; i<src_mat.size(); i++){
            for(int j=0;j<-delta_x+1;j++){
                src_mat[i].push_back(0);
                src_mat[i].erase(src_mat[i].begin());
            }
        }
        
    }
    

    return src_mat;
}
开发者ID:wimacod,项目名称:Draw-n-Guess,代码行数:92,代码来源:toolbox.cpp


示例9: waypoints_loop1

/*
 *	flightLoop
 *		1) Initialise copter systems
 *		2) Wait for user allowance to fly.
 *		3) Read in list of waypoints
 *		4) Fly to first waypoint, wait, fly to next, etc..
 *		5) If the end is reached, stop.
 *		
 *		The user may stop the flight at any time. It will continue if the user resumes. At any
 *		point, the user may stop the current flight path and change the waypoint configuration. Upon
 *		resuming flight, the copter will read in the new list of waypoints and start at the
 *		beginning.
 */
void waypoints_loop1(hardware &hardware_list, Logger &log, deque<coord> &waypoints_list, string config_filename) {	
	cout << "\033[1;32m[WAYPTS]\033[0m Waypoints thread initiated, travelling to the following waypoints:" << endl;
	char str_buf[BUFSIZ];
	log.clearLog();
	
	time_t start, now, last_displayed;
	time(&start);
    time(&now);
    time(&last_displayed);
	
	//Grab references to hardware
	FlightBoard *fb	= hardware_list.fb;
	GPS *gps		= hardware_list.gps;
	IMU *imu		= hardware_list.imu;
	
	bool useimu = hardware_list.IMU_Working;
	double yaw = 0;
	
	//Configure configurable variables (if file is given)
	if(!config_filename.empty()) {
		loadParameters(config_filename);
	}
	
	//Construct PID controller
	PID controller = PID(-Kp, -Ki, -Kd, MAIN_LOOP_DELAY, 3, 0.95);
	
	//Construct buzzer
	Buzzer cowbell;
	cowbell.needs_more();
	usleep((int)(BUZZER_DURATION*1.1)*1000*1000);
	
	//Print list of waypoints
	for(size_t i = 0; i != waypoints_list.size(); i++) {
		cout << "         " << i+1 << ": (" << setprecision(6) << waypoints_list[i].lat << ", " << setprecision(6) << waypoints_list[i].lon << ")" << endl;
	}
	
	//Wait here for auto mode and conduct bearing test if necessary
	state = 6;
    cout << "\033[1;33m[WAYPTS]\033[0m Waiting for auto mode." << endl;
	while ( !gpio::isAutoMode() && !exitProgram) usleep(500*1000);
    cout << "\033[1;31m[WAYPTS]\033[0m Auto mode engaged." << endl;
	
	if (!useimu && !exitProgram) {
		cowbell.playBuzzer(0.25, 10, 100);
        cout << "\033[1;31m[WAYPTS]\033[0m Conducting bearing test..." << endl;
		state = 5;
		yaw = inferBearing(fb, gps);
        cout << "\033[1;31m[WAYPTS]\033[0m Bearing test complete." << endl;
	}
	state = 1;
	
	
	//Initialise loop variables
	coord		currentCoord = {-1, -1};
	double		distanceToNextWaypoint;
	double		bearingToNextWaypoint;
	FB_Data		course = {0, 0, 0, 0};
	int			pastState = -1;
	velocity 	flightVector = {-1, -1};
    
    
    cout << "\033[1;32m[WAYPTS]\033[0m Starting main loop." << endl;
    
	try {	// Check for any errors, and stop the copter.
		while(!exitProgram) {
			currentCoord = getCoord(gps);
			
			//Write data for Michael
			time(&now);
			if (!waypoints_list.empty()) {
				sprintf(str_buf, "%.f,%3.6f,%3.6f,%3.6f,%3.6f", difftime(now, start), currentCoord.lat, currentCoord.lon, waypoints_list[wp_it].lat, waypoints_list[wp_it].lon);
			} else {
				sprintf(str_buf, "%.f,%3.6f,%3.6f,,", difftime(now, start), currentCoord.lat, currentCoord.lon);
			}
			log.writeLogLine(str_buf, false);
			
			
			if(!waypoints_list.empty()) {
				distanceToNextWaypoint = calculate_distance(currentCoord, waypoints_list[wp_it]);
				bearingToNextWaypoint = calculate_bearing(currentCoord, waypoints_list[wp_it]);
			}
			
			if (useimu) yaw = getYaw(imu);

			/* State 4: Manual mode. */
			if (!gpio::isAutoMode()) {
				state = 4;
//.........这里部分代码省略.........
开发者ID:picopter,项目名称:picopter,代码行数:101,代码来源:waypoints_loop1.cpp


示例10: extract_variables

vector<float> extract_variables(deque<deque<int>> img){
    vector<float> variables;
    vector<float> variables_temp_pi;
    deque<deque<int>> m_img = mirror_mat_horizontal(img);
    int sumHist = 0;

    //Horizontal Histogram
    for(int i=0;i<img.size();i++){
        for(int j=0;j<img.size();j++){
            sumHist+=img[i][j];
        }
        variables.push_back(sumHist);
        sumHist = 0;
    }
    //Vertical Histogram
    for(int i=0;i<img.size();i++){
        for(int j=0;j<img.size();j++){
            sumHist+=img[j][i];
        }
        variables.push_back(sumHist);
        sumHist = 0;
    }
    //+pi/4 Histogram
    for (int i = 0; i < 2 * 8 - 1; ++i) {
        int z = i < 8 ? 0 : i - 8 + 1;
        for (int j = z; j <= i - z; ++j) {
            sumHist+=img[j][i - j];
        }
        variables_temp_pi.push_back(sumHist);
        sumHist = 0;
    }
    reverse(variables_temp_pi.begin(),variables_temp_pi.end());
    variables.insert(variables.end(),variables_temp_pi.begin(),variables_temp_pi.end());
    variables_temp_pi.clear();
    //-pi/4 Histogram
    for (int i = 0; i < 2 * 8 - 1; ++i) {
        int z = i < 8 ? 0 : i - 8 + 1;
        for (int j = z; j <= i - z; ++j) {
            sumHist+=m_img[j][i - j];
        }
        variables_temp_pi.push_back(sumHist);
        sumHist = 0;
    }
    reverse(variables_temp_pi.begin(),variables_temp_pi.end());
    variables.insert(variables.end(),variables_temp_pi.begin(),variables_temp_pi.end());

    //quadrans
    for(int i=0;i<2;i++){
        for(int j=0;j<2;j++){
            for(int k=0;k<4;k++){
                for(int l=0;l<4;l++){
                    sumHist+=img[4*i+k][4*j+l];
                }
            }
            variables.push_back(sumHist);
            sumHist = 0;
        }
    }
    //taux de presence
    for(int i=0;i<img.size();i++){
        for(int j=0;j<img.size();j++){
            if(img[i][j]){
                sumHist+=img[i][j];
            }
        }
    }
    variables.push_back(sumHist/1024.0);

    //Deletes useless variables (all zero)

    variables.erase(variables.begin() + 45);
    variables.erase(variables.begin() + 39);
    variables.erase(variables.begin() + 31);
    variables.erase(variables.begin() + 30);
    variables.erase(variables.begin() + 17);
    variables.erase(variables.begin() + 16);
    variables.erase(variables.begin() + 15);
    variables.erase(variables.begin() + 7);


    return variables;
}
开发者ID:wimacod,项目名称:Draw-n-Guess,代码行数:82,代码来源:toolbox.cpp


示例11: f

void f(deque<Card>& dc, My_rand& r)
{
	random_shuffle(dc.begin(), dc.end(), r);
}
开发者ID:sasaki-seiji,项目名称:ProgrammingLanguageCPP4th,代码行数:4,代码来源:random_shuffle.cpp


示例12: printRegions

void LinkMap::printRegions(ostream &os, deque<Region *> &regions, Offset globalOffset) {
    deque<Region *>::iterator reg_it;
    for(reg_it = regions.begin(); reg_it != regions.end(); ++reg_it) {
        printRegion(os, *reg_it, globalOffset);
    }
}
开发者ID:Zirkon,项目名称:dyninst,代码行数:6,代码来源:LinkMap.C


示例13: connect_all_the_parts

int connect_all_the_parts(deque<set<int> > & E, const deque<deque<int> > & member_list, const deque<deque<int> > & link_list) {

	
	deque<int> degrees;
	for(int i=0; i<link_list.size(); i++)
		degrees.push_back(link_list[i][link_list[i].size()-1]);
	
	
		
	
	deque<set<int> > en; // this is the en of the subgraph

	{
		set<int> first;
		for(int i=0; i<member_list.size(); i++) 
			en.push_back(first);
	}
	
	
	
	multimap <int, int> degree_node;
	
	for(int i=0; i<degrees.size(); i++)
		degree_node.insert(degree_node.end(), make_pair(degrees[i], i));
	
	int var=0;

	while (degree_node.size() > 0) {
		
		multimap<int, int>::iterator itlast= degree_node.end();
		itlast--;
		
		multimap <int, int>::iterator itit= itlast;
		deque <multimap<int, int>::iterator> erasenda;
		
		int inserted=0;
		
		for (int i=0; i<itlast->first; i++) {
			
			if(itit!=degree_node.begin()) {
			
				itit--;
				
				
				en[itlast->second].insert(itit->second);
				en[itit->second].insert(itlast->second);
				inserted++;
				
				erasenda.push_back(itit);				
				
			}
			
			else
				break;
		
		}
		
		
		for (int i=0; i<erasenda.size(); i++) {
			
			
			if(erasenda[i]->first>1)
				degree_node.insert(make_pair(erasenda[i]->first - 1, erasenda[i]->second));
	
			degree_node.erase(erasenda[i]);
		
		}

		
		var+= itlast->first - inserted;
		degree_node.erase(itlast);
		
	}

		
	// this is to randomize the subgraph -------------------------------------------------------------------
	
    // ----------------------------------------------------------
    deque<int> degree_list;
    for(int kk=0; kk<degrees.size(); kk++)
        for(int k2=0; k2<degrees[kk]; k2++)
            degree_list.push_back(kk); 

    
	for(int run=0; run<10; run++) for(int node_a=0; node_a<degrees.size(); node_a++) for(int krm=0; krm<en[node_a].size(); krm++) {
        
        
		int random_mate=degree_list[irand(degree_list.size()-1)];
		while (random_mate==node_a)
			random_mate=degree_list[irand(degree_list.size()-1)];
		
		
		
		if (en[node_a].insert(random_mate).second) {
			
			deque <int> out_nodes;
			for (set<int>::iterator it_est=en[node_a].begin(); it_est!=en[node_a].end(); it_est++) if ((*it_est)!=random_mate)
				out_nodes.push_back(*it_est);
						
										
//.........这里部分代码省略.........
开发者ID:BB90,项目名称:CommunityDetectionCodes,代码行数:101,代码来源:standard_bench.cpp


示例14: expand_queue

pair<bi_node, bi_node> expand_queue(
		deque<bi_node>& q_expand,
		deque<bi_node>& q_exist,
		bi_node **s, int m, int n,
		int **visited, int flag)
{//对q_expand队列的头节点的所有邻节点进行扩展
 //在将某个邻节点加入队列q_expand之前,先检查该点是否已经被q_expand队列访问过
 //或者查找该点是否已经存在于q_exist队列中
 //若已经存在,则q_expand的头节点与q_exist中该邻节点是相邻的,即两队列相遇
 //用flag标志这两个队列中哪个是q_beg,哪个是q_end
 //返回两相遇节点,first是q_beg中节点,second是q_end中节点
	deque<bi_node>::iterator pos;
	bi_node p = q_expand.front(); q_expand.pop_front();
	//扩展q_expand头节点的四个方向上的邻节点
	if(p.b_x - 1 >= 0 && !visited[p.b_y][p.b_x - 1]){
		//判断矩阵边界与是否已经被访问过	
		//C++算法find需要结构体bi_node提供比较操作operator==
		//在search.h中该操作操作定义两节点的xy坐标相等即为同一点,不考虑父节点指针
		if((pos = find(q_exist.begin(),
						q_exist.end(),
						s[p.b_y][p.b_x - 1])) !=
					q_exist.end()){
			//若在q_exist中找到q_expand头节点的该邻节点,则返回相遇的两节点
			//flag == 1标志本次扩展的队列是q_beg
			//返回的pair中first是q_beg中节点,second是q_end中节点
			if(flag == 1)
				return(pair<bi_node, bi_node>(p, *pos));
			//flag == 2标志本次扩展的队列是q_end
			//返回的节点顺序与flag == 1是相反的
			if(flag == 2)
				return(pair<bi_node, bi_node>(*pos, p));
		}
		//若没有在q_exist中找到该邻节点则两队列未在此节点处相遇
		//将q_expand队列扩展至该邻节点,并标记其父节点指针
		s[p.b_y][p.b_x - 1].b_fa.first = p.b_x;
		s[p.b_y][p.b_x - 1].b_fa.second = p.b_y;
		q_expand.push_back(s[p.b_y][p.b_x - 1]);
		visited[p.b_y][p.b_x - 1] = 1;
	}
	if(p.b_x + 1 < n && !visited[p.b_y][p.b_x + 1]){
		if((pos = find(q_exist.begin(),
						q_exist.end(),
						s[p.b_y][p.b_x + 1])) !=
					q_exist.end()){
			if(flag == 1)
				return(pair<bi_node, bi_node>(p, *pos));
			if(flag == 2)
				return(pair<bi_node, bi_node>(*pos, p));
		}
		s[p.b_y][p.b_x + 1].b_fa.first = p.b_x;
		s[p.b_y][p.b_x + 1].b_fa.second = p.b_y;
		q_expand.push_back(s[p.b_y][p.b_x + 1]);
		visited[p.b_y][p.b_x + 1] = 1;
	}
	if(p.b_y - 1 >= 0 && !visited[p.b_y - 1][p.b_x]){
		if((pos = find(q_exist.begin(),
						q_exist.end(),
						s[p.b_y - 1][p.b_x])) !=
					q_exist.end()){
			if(flag == 1)
				return(pair<bi_node, bi_node>(p, *pos));
			if(flag == 2)
				return(pair<bi_node, bi_node>(*pos, p));
		}
		s[p.b_y - 1][p.b_x].b_fa.first = p.b_x;
		s[p.b_y - 1][p.b_x].b_fa.second = p.b_y;
		q_expand.push_back(s[p.b_y - 1][p.b_x]);
		visited[p.b_y - 1][p.b_x] = 1;
	}
	if(p.b_y + 1 < m && !visited[p.b_y + 1][p.b_x]){
		if((pos = find(q_exist.begin(),
						q_exist.end(),
						s[p.b_y + 1][p.b_x])) !=
					q_exist.end()){
			if(flag == 1)
				return(pair<bi_node, bi_node>(p, *pos));
			if(flag == 2)
				return(pair<bi_node, bi_node>(*pos, p));
		}
		s[p.b_y + 1][p.b_x].b_fa.first = p.b_x;
		s[p.b_y + 1][p.b_x].b_fa.second = p.b_y;
		q_expand.push_back(s[p.b_y + 1][p.b_x]);
		visited[p.b_y + 1][p.b_x] = 1;
	}
	//一次扩展只是从q_expand队列的头节点向外扩展四个邻节点
	//若这次扩展中两队列未相遇则返回q_expand的尾部迭代器
	return(pair<bi_node, bi_node>(*q_expand.end(), *q_expand.end()));
}
开发者ID:Zhouxiaoqing,项目名称:Way_to_Algorithm,代码行数:88,代码来源:4_bidirection_breadth_search.cpp


示例15: print_network

int print_network(deque<set<int> > & E, const deque<deque<int> > & member_list, const deque<deque<int> > & member_matrix, deque<int> & num_seq) {

	
	int edges=0;

		
	int num_nodes=member_list.size();
	
	deque<double> double_mixing;
	for (int i=0; i<E.size(); i++) {
		
		double one_minus_mu = double(internal_kin(E, member_list, i))/E[i].size();
		
		double_mixing.push_back(1.- one_minus_mu);
				
		edges+=E[i].size();
		
	}
	
	
	//cout<<"\n----------------------------------------------------------"<<endl;
	//cout<<endl;
	
	
	
	double density=0; 
	double sparsity=0;
	
	for (int i=0; i<member_matrix.size(); i++) {

		double media_int=0;
		double media_est=0;
		
		for (int j=0; j<member_matrix[i].size(); j++) {
			
			
			double kinj = double(internal_kin_only_one(E[member_matrix[i][j]], member_matrix[i]));
			media_int+= kinj;
			media_est+=E[member_matrix[i][j]].size() - double(internal_kin_only_one(E[member_matrix[i][j]], member_matrix[i]));
					
		}
		
		double pair_num=(member_matrix[i].size()*(member_matrix[i].size()-1));
		double pair_num_e=((num_nodes-member_matrix[i].size())*(member_matrix[i].size()));
		
		if(pair_num!=0)
			density+=media_int/pair_num;
		if(pair_num_e!=0)
			sparsity+=media_est/pair_num_e;
		
		
	
	}
	
	density=density/member_matrix.size();
	sparsity=sparsity/member_matrix.size();
	
	
	


	ofstream out1("network.dat");
	for (int u=0; u<E.size(); u++) {

		set<int>::iterator itb=E[u].begin();
	
		while (itb!=E[u].end())
			out1<<u+1<<"\t"<<*(itb++)+1<<endl;
		
		

	}
	out1.close();	

	
	ofstream out2("community.dat");

	for (int i=0; i<member_list.size(); i++) {
		
		out2<<i+1<<"\t";
		for (int j=0; j<member_list[i].size(); j++)
			out2<<member_list[i][j]+1<<" ";
		out2<<endl;
	
	}
    out2.close();
    
	cout<<"\n\n---------------------------------------------------------------------------"<<endl;
	
	
	cout<<"network of "<<num_nodes<<" vertices and "<<edges/2<<" edges"<<";\t average degree = "<<double(edges)/num_nodes<<endl;
	cout<<"\naverage mixing parameter: "<<average_func(double_mixing)<<" +/- "<<sqrt(variance_func(double_mixing))<<endl;
	cout<<"p_in: "<<density<<"\tp_out: "<<sparsity<<endl;

	
	
	ofstream statout("statistics.dat");
	
	deque<int> degree_seq;
	for (int i=0; i<E.size(); i++)
//.........这里部分代码省略.........
开发者ID:BB90,项目名称:CommunityDetectionCodes,代码行数:101,代码来源:standard_bench.cpp


示例16: internal_degree_and_membership

int internal_degree_and_membership (double mixing_parameter, int overlapping_nodes, int max_mem_num, int num_nodes, deque<deque<int> >  & member_matrix, 
bool excess, bool defect,  deque<int> & degree_seq, deque<int> &num_seq, deque<int> &internal_degree_seq, bool fixed_range, int nmin, int nmax, double tau2) {
	
	
	
	
	
	if(num_nodes< overlapping_nodes) {
		
		cerr<<"\n***********************\nERROR: there are more overlapping nodes than nodes in the whole network! Please, decrease the former ones or increase the latter ones"<<endl;
		return -1;
	}
	
	
	// 
	member_matrix.clear();
	internal_degree_seq.clear();
	
	deque<double> cumulative;
	
	// it assigns the internal degree to each node -------------------------------------------------------------------------
	int max_degree_actual=0;		// maximum internal degree

	for (int i=0; i<degree_seq.size(); i++) {
		
		double interno=(1-mixing_parameter)*degree_seq[i];
		int int_interno=int(interno);
		
		
		if (ran4()<(interno-int_interno))
			int_interno++;
		
		if (excess) {
			
			while (   (  double(int_interno)/degree_seq[i] < (1-mixing_parameter) )  &&   (int_interno<degree_seq[i])   )
				int_interno++;
				
		
		}
		
		
		if (defect) {
			
			while (   (  double(int_interno)/degree_seq[i] > (1-mixing_parameter) )  &&   (int_interno>0)   )
				int_interno--;
				
		
		}

		
		
		
		internal_degree_seq.push_back(int_interno);
		
		
		if (int_interno>max_degree_actual)
			max_degree_actual=int_interno;
		
			
	}
	
	
	// it assigns the community size sequence -----------------------------------------------------------------------------
	
	powerlaw(nmax, nmin, tau2, cumulative);
	
	
	if (num_seq.empty()) {
		
		int _num_=0;
		if (!fixed_range && (max_degree_actual+1)>nmin) {
		
			_num_=max_degree_actual+1;			// this helps the assignment of the memberships (it assures that at least one module is big enough to host each node)
			num_seq.push_back(max_degree_actual+1);
		
		}
		
		
		while (true) {
			
			
			int nn=lower_bound(cumulative.begin(), cumulative.end(), ran4())-cumulative.begin()+nmin;
			
			if (nn+_num_<=num_nodes + overlapping_nodes * (max_mem_num-1) ) {
				
				num_seq.push_back(nn);				
				_num_+=nn;
			
			}
			else
				break;
			
			
		}
		
		num_seq[min_element(num_seq.begin(), num_seq.end()) - num_seq.begin()]+=num_nodes + overlapping_nodes * (max_mem_num-1) - _num_;
		
	}
	
	
//.........这里部分代码省略.........
开发者ID:BB90,项目名称:CommunityDetectionCodes,代码行数:101,代码来源:standard_bench.cpp


示例17: build_subgraphs

int build_subgraphs(deque<set<int> > & E, const deque<deque<int> > & member_matrix, deque<deque<int> > & member_list, 
	deque<deque<int> > & link_list, const deque<int> & internal_degree_seq, const deque<int> & degree_seq, const bool excess, const bool defect) {
	
	
	
	E.clear();
	member_list.clear();
	link_list.clear();
	
	int num_nodes=degree_seq.size();
	
	//printm(member_matrix);

	
	
	
	{
		
		deque<int> first;
		for (int i=0; i<num_nodes; i++)
			member_list.push_back(first);
	
	}
	
	
	
	for (int i=0; i<member_matrix.size(); i++)
		for (int j=0; j<member_matrix[i].size(); j++)
			member_list[member_matrix[i][j]].push_back(i);
	
	
	//printm(member_list);
	
	for (int i=0; i<member_list.size(); i++) {
		
		deque<int> liin;

		
		for (int j=0; j<member_list[i].size(); j++) {
			
			compute_internal_degree_per_node(internal_degree_seq[i], member_list[i].size(), liin);
			liin.push_back(degree_seq[i] - internal_degree_seq[i]);
		
		}
		
		link_list.push_back(liin);
		
	}
			
	
	

	// now there is the check for the even node (it means that the internal degree of each group has to be even and we want to assure that, otherwise the degree_seq has to change) ----------------------------

	
	
	
	// ------------------------ this is done to check if the sum of the internal degree is an even number. if not, the program will change it in such a way to assure that. 
	
	
			
	for (int i=0; i<member_matrix.size(); i++) {
	
		
		int internal_cluster=0;
		for (int j=0; j<member_matrix[i].size(); j++) {
			
			int right_index= lower_bound(member_list[member_matrix[i][j]].begin(), member_list[member_matrix[i][j]].end(), i) - member_list[member_matrix[i][j]].begin();
			
				
			
			internal_cluster+=link_list[member_matrix[i][j]][right_index];
		}
		
		
		if(internal_cluster % 2 != 0) {
			
			
			
			bool default_flag=false;
			
			if(excess)
				default_flag=true;
			else if(defect)
				default_flag=false;
			else if (ran4()>0.5)
				default_flag=true;
			
			if(default_flag) {
				
				// if this does not work in a reasonable time the degree sequence will be changed
				
				for (int j=0; j<member_matrix[i].size(); j++) {		
					
					
					int random_mate=member_matrix[i][irand(member_matrix[i].size()-1)];
					
					int right_index= lower_bound(member_list[random_mate].begin(), member_list[random_mate].end(), i) - member_list[random_mate].begin();
					
					
//.........这里部分代码省略.........
开发者ID:BB90,项目名称:CommunityDetectionCodes,代码行数:101,代码来源:standard_bench.cpp


示例18: if

int 
main(int argc, char* argv[]) {
	const int test_case = 2;
	signal(SIGINT, &signal_handler);
#ifndef WIN32
	void* (*AppServer[test_case])(void*);
#else
	DWORD (WINAPI *AppServer[test_case])(LPVOID);
#endif
	AppServer[0] = AppServer_TCP;
	AppServer[1] = AppServer_UDT;
	cout << "Start AppServer Mode # Callee" << endl;
	UDT::startup();
#ifndef WIN32
	pthread_t srv_udt, srv_tcp;
	pthread_create(&srv_tcp, NULL, AppServer[0], NULL);
	pthread_create(&srv_udt, NULL, AppServer[1], NULL);

	//pthread_join(srv_udt, NULL);
	//pthread_join(srv_tcp, NULL);
#else
	HANDLE srv_udt, srv_tcp;
	srv_tcp = CreateThread(NULL, 0, AppServer[0], NULL, 0, NULL);
	srv_udt = CreateThread(NULL, 0, AppServer[1], NULL, 0, NULL);

	//WaitForSingleObject(srv_udt, INFINITE);
	//WaitForSingleObject(srv_tcp, INFINITE);
#endif
	////////////////////////////////////////////////////////////////
	////////////////////////////////////////////////////////////////
	////////////////////////////////////////////////////////////////
	cout << "Run Task loop ...\n";
	main_running = 1;
	while (main_running) 
	{
		if (!taskQueue.empty())
		{
			switch (taskQueue.front()->header.cmd)
			{
			case CMD_C_DISCONNECT:
			{
				connectMap_iter = connectMapKeyC.find(taskQueue.front()->header.cliFD);
				if (connectMap_iter != connectMapKeyC.end())
				{
					UDT::epoll_remove_ssock(tcp_eid, connectMap_iter->second);
#ifndef WIN32
					close(connectMap_iter-&g 

鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ descriptor_table类代码示例发布时间:2022-05-31
下一篇:
C++ dependent类代码示例发布时间:2022-05-31
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap