float KMeansClustering<T, TTraits>::doClusterAssignmentForAllItems(
                                                                   const std::vector<T> &items,
                                                                   const std::vector<T> &clusterCenters,
                                                                   std::vector<int> &clusterAssignment,
                                                                   std::deque<float> &squaredErrorForItems
                                                                   ) {
    const size_t nItems = items.size();
    const size_t k = clusterCenters.size();
    float curSSEForAllItems = 0.0f;
    squaredErrorForItems.assign(nItems, -1.0);
    for(int j=0; j < nItems; ++j) {
        assert(TTraits::validate(items[j]));
        squaredErrorForItems[j] = 0.0f;
        float minDistSoFar = std::numeric_limits<float>::max();
        int clusterWithMinDist = -1;
        for(int m=0; m < k; ++m) {
            float curDist = TTraits::dist(clusterCenters[m], items[j]);
            if(curDist < minDistSoFar) {
                clusterWithMinDist = m;
                minDistSoFar = curDist;
            }
        }
        clusterAssignment[j] = clusterWithMinDist;
        squaredErrorForItems[j] = minDistSoFar;
        curSSEForAllItems += minDistSoFar;
    }

    //verification that each valid contour is assigned to a cluster
    for(int j =0; j < clusterAssignment.size(); ++j) {
        assert(clusterAssignment[j] >= 0);
    }

    return curSSEForAllItems;
}
	void setup_players(std::deque<player_t *> &tournament_players) {
		tournament_players.assign(this->players.begin(), this->players.end());
		std::random_shuffle(tournament_players.begin(), tournament_players.end());

		/** Define o 1o elemento como "bye", se necessário" */
		if(tournament_players.size() % 2)
			tournament_players.push_front(nullptr);
	}
void
test(std::deque<int>& c1, int size, int v)
{
    typedef std::deque<int> C;
    typedef C::const_iterator CI;
    std::size_t c1_osize = c1.size();
    c1.assign(size, v);
    assert(c1.size() == size);
    assert(distance(c1.begin(), c1.end()) == c1.size());
    for (CI i = c1.begin(); i != c1.end(); ++i)
        assert(*i == v);
}
Exemple #4
0
bool CWizDatabase::GetAllObjectsNeedToBeDownloaded(std::deque<WIZOBJECTDATA>& arrayData)
{
    CWizDocumentDataArray arrayDocument;
    CWizDocumentAttachmentDataArray arrayAttachment;
    GetNeedToBeDownloadedDocuments(arrayDocument);
    GetNeedToBeDownloadedAttachments(arrayAttachment);

    arrayData.assign(arrayAttachment.begin(), arrayAttachment.end());
    arrayData.insert(arrayData.begin(), arrayDocument.begin(), arrayDocument.end());

    return true;
}
void plan(){
	ROS_INFO("planning");
	//if((ros::Time::now()-local_map->header.stamp)>ros::Duration(5.0))
	//	return;
	if(keepMoving){
		if(planned && current_path.size()>0){
			//look for farther free space straighline of previous trajectory
			int i=0;
			while(i<current_path.size() && segmentFeasibility(startState,current_path[i])){
				++i;
			}
			--i;
			State<2> s=startState+(current_path[i]-startState)*std::min((current_path[i]-startState).norm(),1.0f)*(1/(current_path[i]-startState).norm());
			//set and send the waypoint
			setWaypoint(s);
			//plan from that waypoint
			startState=s;
		}
	}else{
		stop();
	}
	planned=false;
	planning=true;

	//Run the desired planner
	//RRTstar_planning();
	//MSPP_planning();
	Astar_planning();

	if(planned){
		current_path=std::deque<State<2>>();
		current_path.assign(current_path_raw.begin(),current_path_raw.end());
		//*
		std::cout << "smoothed solution" <<std::endl;
		//for(int i=0;i<current_path_raw.size();++i)
		for(int i=0;i<1;++i)
			smoothTraj();
		if(waypointMaxDistance>0)
			densifyWaypoints();
		/*std::cout << "Path length: " << current_path.size() << std::endl;
		for(std::deque<State<2>>::iterator it=current_path.begin(),end=current_path.end();it!=end;++it){
			std::cout << (*it) << " -- ";}
		std::cout << std::endl << "raw:" <<std::endl;
		for(std::deque<State<2>>::iterator it=current_path_raw.begin(),end=current_path_raw.end();it!=end;++it){
			std::cout << (*it) << " -- ";
		}
		std::cout << std::endl;*/
		//*/
		setWaypoint(current_path.front());
	}
	planning=false;
}
Exemple #6
0
		void clear(){
			Data[0].front=&Data[0];
			Data[0].back=&Data[0];
			if(Data.size()==1){
				Ptrs.clear();
				return;
			}else{
				Ptrs.assign(Data.size()-1,0);
				std::deque<Datum*>::iterator itr=Ptrs.begin(),enditr=Ptrs.end();
				array<Datum>::iterator ditr=Data.begin();
				++ditr;	//Nullデータ部をよける
				while(itr!=enditr){
					(*itr)=&(*ditr);
					++ditr;
					++itr;
				}
			}
		}
void bad_assign_deque1(std::deque<int> &D, int n) {
  auto i0 = D.cbegin();
  D.assign(10, n);
  *i0; // expected-warning{{Invalidated iterator accessed}}
}