Ejemplo n.º 1
0
void RegApp::featuresCurrentHandler(const lcm::ReceiveBuffer* rbuf, const std::string& channel, const  reg::features_t* msg){
  if (registeration_mode_!= 2){
    return;
  }
  //cout << "\n\ngot current features @ "<< msg->utime<<"\n";
  
  // now find the corresponding image and pair it
  bool feat_image_matched_ = false;
  for(int i=0; i < image_queue_->size(); i++){
    //cout << image_queue_->at(i).utime << " " << i << "\n";
    if (msg->utime == image_queue_->at(i).utime){
      cur_features_ = getFeaturesFromLCM(msg,cur_pose_);
      cur_image_ = image_queue_->at(i);
      //cout << "image and features matched: " << i << " " << image_queue_->at(i).utime << " ("<< cur_features_.size()<<"f)\n"; 
      feat_image_matched_ = true;

      break;
    }
  }
  
  // If the registartation have been activated, do it live:
  if (feat_image_matched_ ){
    doReg();
  }else{
   cout << "didn't find a matching current image - make image deque bigger\n";  // not fatal... just continue
  }
}
Ejemplo n.º 2
0
void GridDisplay::setGridVec(deque<deque<double> > gridVec) {
	this->setGridSize(Size(gridVec.at(0).size(),gridVec.size()));
	for(int i=0; i<this->gridSize.height; i++) {
		for(int j=0; j<this->gridSize.width; j++) {
			this->gridMat.at<float>(i,j) = gridVec.at(i).at(j);
		}
	}
}
Ejemplo n.º 3
0
void printDeque(deque< pair<String, int> > d)
{
	cout << "PRINT DEQUE" << endl;
	for (int i=0; i < d.size(); i++)
	{
		cout << d.at(i).first << " " << d.at(i).second << endl;
	}
	cout << "----" << endl;
}
Ejemplo n.º 4
0
void RegApp::featuresReferenceHandler(const lcm::ReceiveBuffer* rbuf, const std::string& channel, const  reg::features_t* msg){
  
  if (registeration_mode_ != 1){ // ignore features if we havent just been asked to track to them
    return;
  }

  cout << "\n\ngot reference features @ "<< msg->utime<<"\n";

  // now find the corresponding image and pair it
  bool feat_image_matched_ = false;
  for(int i=0; i < image_queue_->size(); i++){
    //cout << image_queue_->at(i).utime << " " << i << "\n";
    if (msg->utime == image_queue_->at(i).utime){
      cur_features_ = getFeaturesFromLCM(msg,cur_pose_);
      cur_image_ = image_queue_->at(i);
      cout << "image and features matched: " << i << " " << image_queue_->at(i).utime << " ("<< cur_features_.size()<<"f)\n"; 
      feat_image_matched_ = true;

      break;
    }
  }
  
  if (!feat_image_matched_){
     cout <<"didn't find a matching reference image - make image deque bigger\n";
     exit(-1);
  } 

  ref_features_ = cur_features_;
  ref_image_ = cur_image_;
  ref_pose_ = cur_pose_;

  // set the reference image
  cout << "Will now register to " << ref_features_.size() << " features\n";
  
  // Send the pose we will try to register back to:
  Isometry3dTime ref_poseT = Isometry3dTime(ref_image_.utime, ref_pose_);
  pc_vis_->pose_to_lcm_from_list(70000, ref_poseT);

  deque_to_cloud(laser_queue_, botframes_, accum_cloud);

  Isometry3dTime null_poseT = Isometry3dTime(ref_image_.utime, Eigen::Isometry3d::Identity()  );
  pc_vis_->pose_to_lcm_from_list(70001, null_poseT);
  pc_vis_->ptcld_to_lcm_from_list(70002, *accum_cloud, ref_image_.utime, ref_image_.utime);

  std::stringstream ss2;
  print_Isometry3d(ref_pose_, ss2);
  std::cout << "Received refpose: " << ss2.str() << "\n";

  Eigen::Isometry3f pose_f = ref_pose_.inverse().cast<float>();
  Eigen::Quaternionf pose_quat(pose_f.rotation());
  pcl::transformPointCloud (*accum_cloud, *accum_cloud,
      pose_f.translation(), pose_quat); // !! modifies accum_cloud
  pc_vis_->ptcld_to_lcm_from_list(70003, *accum_cloud, ref_image_.utime, ref_image_.utime);

  registeration_mode_ = 2;
}
Ejemplo n.º 5
0
void clean_fit_all() {
  deque<int> idx;
  for (int i =0; i<rem.size(); ++i) {
    if (!clean_fit(words[rem.at(i)])) {
      idx.push_back(rem.at(i));
    }
  }
  rem.clear();
  rem = idx;
}
Ejemplo n.º 6
0
void fill_grid() {
  string w;
  int size;
  deque<int> idx, leftover, backup = rem;
  vector<Entry> fitted; //successfully fitted words
  bool done = false;
  char optimal[SIZE][SIZE];  
  int prev = WORD_LIST;      
  
  int limit = SIZE - words[rem.at(0)].length();
  
  for (int i=0; i<SIZE && !done; ++i) {
    for (int j=0; j<limit && !done; ++j) {                  
      if (!fit_word(words[rem.at(0)], i, j, true)) continue;
            
      rem.pop_front();
      clean_fit_all();
      size = rem.size();

      for (int k=0; k<size; ++k) {
        w = words[rem.at(k)];
        if (clean_fit(w) || force_fit(w)) continue;
        else {          
          idx.push_back(rem.at(k));
        }
      }               
      size = idx.size();
      
      if (size < prev) {
        prev = size;
        leftover = idx;
        fitted = placed;
        //TODO: must optimize using pointers if grid is large. 
        //optimization: point optimal to grid and allocate a new space for grid
        for(int i=0; i < SIZE; ++i) for(int j=0; j<SIZE; ++j) optimal[i][j] = grid[i][j];
        done = prev == 0;
      }
      
      if (!done) {
        rem = backup;
        idx.clear();
        clear_grid();
        placed.clear();        
      }
    }
  }
  rem = leftover;
  placed = fitted;
  for(int i=0; i < SIZE; ++i) for(int j=0; j<SIZE; ++j) grid[i][j] = optimal[i][j];  
}
Ejemplo n.º 7
0
void calculateLastLikelyPerson()
{
	for(int i=0; i < lastTenSeen.size(); i++)
	{
		int answer = dequeContains(lastTenSeenOutput, lastTenSeen.at(i).first);
		if (answer >= 0)
		{
			lastTenSeenOutput[answer].second += lastTenSeen.at(i).second;
		}
		else
		{
			lastTenSeenOutput.push_back(lastTenSeen.at(i));
		}
	}
}
Ejemplo n.º 8
0
//路径
deque<Situation> Situation::showWay(deque<Situation> &closed){
    //cout << closed.size() << endl;
    deque<Situation> dequeList;
    Situation temp = closed.back();
    dequeList.push_back(temp);
    
    //closed表从后往前,根据father值找到路径
    for (int i = closed.size()-1; i >= 0;i--){
        if (temp.father==closed.at(i).code){
            dequeList.push_back(closed.at(i));
            temp = closed.at(i);
        }
    }
    //cout << dequeList.size() << endl;
    return dequeList;
}
pair <Float_t,Float_t> TPedestalCalculation::calculateFirstPedestalDia(int ch,deque<Int_t> adcQueue, float meanChannel, float sigmaChannel,int iterations,float maxSigma){
	diaSUM[ch]=0;
	diaSUM2[ch]=0;
	diaEventsInSum[ch]=0;
	this->diaEventUsed[ch].clear();
	for(UInt_t nEvent=0;nEvent<adcQueue.size();nEvent++){
		Float_t adc = (Float_t) adcQueue.at(nEvent);
		if(   (adc >= getLowLimitPedestal(meanChannel,sigmaChannel,maxSigma)  )
				&& (adc <= getHighLimitPedestal(meanChannel,sigmaChannel,maxSigma) ) ){
			diaEventUsed[ch].push_back(true);
			diaSUM[ch]+=adc;
			diaSUM2[ch]+=adc*adc;
			diaEventsInSum[ch]++;
		}//end if
		else
			diaEventUsed[ch].push_back(false);
	}//end for nEvent
	if(diaEventsInSum[ch]<0.1*adcQueue.size())
		cout<<"For the calculation of first pedestals in diamond and ch "<<ch<<"there were only "<<diaEventsInSum[ch]<<" Events used..."<<endl;
	Float_t mean=diaSUM[ch]/(Float_t)diaEventsInSum[ch];
	Float_t sigma=TMath::Sqrt( diaSUM2[ch]/(Float_t)diaEventsInSum[ch]-mean*mean);

	diaPedestalMean[ch]=RoundFloat(mean);
	diaPedestalSigma[ch]=RoundFloat(sigma);
	pair<Float_t,Float_t> output = make_pair(mean,sigma);
	//	if(verbosity>4&& ch ==103)
	//		cout<<"diamond ch "<<ch<<", it "<<iterations<<", usedEvents " <<diaEventsInSum[ch]<<"\t"<<mean<<"+/-"<<sigma<<endl;
	if(iterations==0)return output;
	else return this->calculateFirstPedestalDia(ch,adcQueue,mean,sigma,iterations-1,maxSigma);
}
pair <Float_t,Float_t> TPedestalCalculation::calculateFirstPedestalDet(int det,int ch,deque<Int_t> adcQueue, float meanChannel, float sigmaChannel,int iterations,float maxSigma){
	detSUM[det][ch]=0;
	detSUM2[det][ch]=0;
	detEventsInSum[det][ch]=0;

	this->detEventUsed[det][ch].clear();
	for(nEvent=0;nEvent<adcQueue.size();nEvent++){
		Float_t adc = (Float_t)adcQueue.at(nEvent);
		//mean - maxSigma*sigma<=adc<= mean + maxSigma*sigma <-- Than it is no hit/seed
		if(  ( adc >= getLowLimitPedestal(meanChannel,sigmaChannel,maxSigma) )
				&&( adc <= getHighLimitPedestal(meanChannel,sigmaChannel,maxSigma) ) ){
			detEventUsed[det][ch].push_back(true);
			detSUM[det][ch]+=adc;
			detSUM2[det][ch]+=adc*adc;
			detEventsInSum[det][ch]++;
		}//end if
		else
			detEventUsed[det][ch].push_back(false);
	}//end for nEvent
	if(detEventsInSum[det][ch]<0.1*adcQueue.size())
		cout<<"For the calculation of first pedestals in det "<<det<<" and ch "<<ch<<"there were only "<<detEventsInSum[det][ch]<<" Events used..."<<endl;
	Float_t mean  = detSUM[det][ch]/(Float_t)detEventsInSum[det][ch];
	Float_t sigma = TMath::Sqrt(detSUM2[det][ch]/(Float_t)detEventsInSum[det][ch]-mean*mean);
	pair<Float_t,Float_t> output = make_pair(mean,sigma);
	if(iterations==0)return output;
	else return this->calculateFirstPedestalDet(det,ch,adcQueue,mean,sigma,iterations-1,maxSigma);
}
pair<Float_t, Float_t> TPedestalCalculation::calculateFirstPedestalDiaCMN(int ch, deque<Float_t> adcQueue, float meanCMN, float sigmaCMN, int iterations, float maxSigma) {
	diaSUMCmn[ch]=0;
	diaSUM2Cmn[ch]=0;
	diaEventsInSumCMN[ch]=0;
	//  if(ch==7)cout<<"calcFirstPedCMN:"<<ch<<" "<<meanCMN<<" "<<sigmaCMN<<" "<<diaEventsInSumCMN[ch]<<endl;
	this->diaEventUsedCMN[ch].clear();
	for(nEvent=0;nEvent<adcQueue.size();nEvent++){
		Float_t adc = adcQueue.at(nEvent);
		if(   (adc >= getLowLimitPedestal(meanCMN,sigmaCMN,maxSigma))
				&& (adc <= getHighLimitPedestal(meanCMN,sigmaCMN,maxSigma)) ){
			diaEventUsedCMN[ch].push_back(true);
			diaSUMCmn[ch]+=adc;
			diaSUM2Cmn[ch]+=adc*adc;
			diaEventsInSumCMN[ch]++;
		}//end if
		else
			diaEventUsedCMN[ch].push_back(false);
	}//end for nEvent
	//TODO!!! FIX!!! PROBLEM!!!!!!!!
	///WORK HERE!!!!!!!
	if(diaEventsInSumCMN[ch]==0)
		cout<<"events in sum=0: "<<nEvent<<" "<<ch<<" "<<diaEventsInSumCMN[ch]<<" "<<diaEventsInSum[ch]<<endl;
	meanCMN=diaSUMCmn[ch]/(Float_t)diaEventsInSumCMN[ch];
	//  if(ch==7)cout<<diaSUMCmn[ch]<<" "<<diaSUM2Cmn[ch]<<" "<<diaEventsInSumCMN[ch]<<" "<<meanCMN<<endl;
	sigmaCMN=TMath::Sqrt( (diaSUM2Cmn[ch]/(Float_t)diaEventsInSumCMN[ch])-meanCMN*meanCMN);

	diaPedestalMeanCMN[ch]=RoundFloat(meanCMN);
	diaPedestalSigmaCMN[ch]=RoundFloat(sigmaCMN);
	pair<Float_t,Float_t> output = make_pair(meanCMN,sigmaCMN);
	if(iterations==0)return output;
	else return this->calculateFirstPedestalDiaCMN(ch,adcQueue,meanCMN,sigmaCMN,iterations-1,maxSigma);
}
Ejemplo n.º 12
0
/* called from layer 3, when a packet arrives for layer 4
 * If the ack packet is for a packet inside the window, then that particular packet
 * is marked as acknowledged. If it is the base packet then the window gets shifted
 * by number of consecutive acked packets.
 * For correctly received ack packets(for non retransmitted packets), an RTT is
 * calculated and sent to estimateRTT for timeout estimation.
 *
 * */
void A_input(struct pkt packet)
{
	cout<<"*************************Inside A_input start*************************"<<endl;

	int indexOfPacketsAck=0;
	timerPacket* tempTimerPacket;
	if(!isCorrupt(&packet)){
			if((senderBuffer.size()>=(a_base+1))&&senderBuffer.at(a_base)->packet->seqnum<=packet.acknum){

			//		cout<<"A->Ack recevied for packet "<<packet.acknum<<endl;//<<" a_nextseqnum:"<<(senderBuffer.size()>=0 ? senderBuffer.at(a_nextseqnum)->seqnum:0)<<endl;
			indexOfPacketsAck=packet.acknum - senderBuffer.at(a_base)->packet->seqnum;
			//senderBuffer.erase(senderBuffer.begin(),senderBuffer.begin()+numOfPacketsAck);
			//	cout<<"indexOfPacketsAck:"<<indexOfPacketsAck<<" size:"<<senderBuffer.size()<<endl;
			cout<<"A->Packet with Seq num:"<<senderBuffer.at(indexOfPacketsAck)->packet->seqnum<<" is Ackowledged. Sender Buffer size:"<<senderBuffer.size()<<endl;
			senderBuffer.at(indexOfPacketsAck)->ackedFlag=true;
			/*Added for timeout Estimation*/
			cout<<"Before estimate call"<<endl;
			if(!senderBuffer.at(indexOfPacketsAck)->retransmitFlag){
				//This is not for a retransmission
				estimateTimeout(time_local-senderBuffer.at(indexOfPacketsAck)->start_time);
			}else{
				cout<<" Packet received is a retransmission"<<endl;
			}


			int i=a_base;
			int count=0;
			timerPacket * tempTimerPacket;
			while((count<a_windowSize)&&(senderBuffer.size()>=(a_base+1)&&senderBuffer.at(a_base)->ackedFlag==true)){
				tempTimerPacket=senderBuffer.at(i);
				cout<<"A->Remove Packet Seq:"<<tempTimerPacket->packet->seqnum<<endl;
				fflush(stdout);
				senderBuffer.pop_front();
				count++;
				a_nextseqnum--;
			}
			//	a_nextseqnum-=count;
			//Added as an Optimization.Possible a better approach for SR
			if(count!=0){
				cout<<"A->Window Shifted by "<<count<<" packets. Sending more packets now"<<endl;
				sendPacketsinBulk();
			}else{
				cout<<"A->Since base packet was not Acknowledged, Window was not shifted."<<endl;
			}
		}else{
			//acknum is less than base. So this is a delayed, duplicate Ack packet.
			//Ignore it
			cout<<"A->Base sequence:"/*<<senderBuffer.at(a_base)->seqnum*/<<" Ack Received:"<<packet.acknum<<". Received a delayed, duplicate Ack. Ignoring it"<<endl;
			return;
		}
	}else{
		cout<<"A-> Corrupt Ack Received. Ignoring this"<<endl;
	}
	cout<<"*************************Inside A_input end*************************"<<endl;

}
Ejemplo n.º 13
0
//customize calcuation of hue avg
double Hsl::calcHueAvg(deque<int> &vec) {
	double hue=0;
	double total=0;
	for(unsigned int i=0; i<vec.size(); i++) {
		hue = (vec.at(i)+180)%360;
		total += hue;
	}
	total /= vec.size();
	total /= 360;
	return total;
}
Ejemplo n.º 14
0
/*
 * Check that what gets written is what we expected
 */
void MockLogDestination::Write(log_level level, const string &log_line) {
  vector<string> tokens;
  ola::StringSplit(log_line, tokens, ":");
  vector<string>::iterator iter;
  OLA_ASSERT_EQ(tokens.size() , (size_t) 3);
  OLA_ASSERT_GT(m_log_lines.size(), 0);
  std::pair<log_level, string> expected_result = m_log_lines.at(0);
  m_log_lines.pop_front();
  OLA_ASSERT_EQ(expected_result.first, level);
  OLA_ASSERT_EQ(expected_result.second, tokens.at(2));
}
Ejemplo n.º 15
0
void Situation::show_deque(deque<Situation> &m_deque) const{
    /*deque<Situation>::iterator it = m_deque.begin();
     while (it!=m_deque.end())
     {
     (*it).show();
     it++;
     }*/
    for (int i = 0; i < m_deque.size();i++){
        m_deque.at(i).show();
    }
}
Ejemplo n.º 16
0
int dequeContains(deque< pair<String, int> > d, String s)
{
	for (int i=0; i < d.size(); i++)
	{
		if (d.at(i).first == s)
		{
			return i;
		}
	}
	return -1;
}
Ejemplo n.º 17
0
/**
 * Compare the given query spectrum to all library spectra.  Create a
 * match for each and add to matches.
 */
void SearchLibrary::scoreMatches(Spectrum& s, deque<RefSpectrum*>& spectra,
                                 vector<Match>& matches ){
    Verbosity::debug("Scoring %d matches.", spectra.size());
    // get the charge states we will search
    const vector<int>& charges = s.getPossibleCharges();
    
    // compare all ref spec to query, create match for each
    for(size_t i=0; i< spectra.size(); i++) {
        // is there a better place to check this?
        if(spectra.at(i)->getNumProcessedPeaks() == 0 ){ 
            Verbosity::debug("Skipping library spectrum %d.  No peaks.", 
                             spectra.at(i)->getLibSpecID());
            continue;
        }
        
        if( ! checkCharge(charges, spectra.at(i)->getCharge()) ){
            continue;
        }
        
        Match thisMatch(&s, spectra.at(i));  
        
        thisMatch.setMatchLibID(spectra.at(i)->getLibID());
        
        Verbosity::comment(V_ALL, "Comparing query spec %d and library spec %d",
                           s.getScanNumber(), spectra.at(i)->getLibSpecID());
        
        DotProduct::compare(thisMatch); //static method
        
        // save match for reporting
        matches.push_back(thisMatch);
    }  
}
Ejemplo n.º 18
0
// Takes in a deque<string>, and uses those strings
// to build an s-expression.
// Example: input   <"foobar", "1", "3">
//          returns "(foobar 1 3)"
string create_sexpr(deque<string> parts) {

	string buffer;
	buffer = "(";
	for(unsigned int i = 0; i < parts.size(); i++) {
		buffer += parts.at(i);
		if(i != parts.size()-1)
			buffer += " ";
	}
	buffer += ")";
	
	return buffer;

}
Ejemplo n.º 19
0
deque<int> normal_sieve(deque<int> &numbers) {
  unordered_map<int, bool> isNotPrime;
  deque<int> primes;
  auto max = numbers.at(numbers.size() - 1);
  cout << max << '\n';
  for (auto &number: numbers) {
    if (isNotPrime.find(number) == isNotPrime.end()) {
      primes.push_back(number);
      for (int i = number * number; i <= max; i += number) {
        isNotPrime[i] = true;
      }
    }
  }
  return primes;
}
Ejemplo n.º 20
0
bool Situation::isInClosed(deque<Situation> &closed){
    /*deque<Situation>::iterator it = closed.begin();
     while (it!=closed.end()){
     if (code == (*it).code){
     return true;
     }
     it++;
     }*/
    for (int i = 0; i < closed.size(); i++){
        if (code == closed.at(i).code){
            return true;
        }
    }
    return false;
}
Ejemplo n.º 21
0
bool Situation::isInOpen(deque<Situation> &open){
    /*deque<Situation>::iterator it = open.begin();
     while (it != open.end()){
     if (code == (*it).code){
     return true;
     }
     it++;
     }*/
    for (int i = 0; i < open.size();i++){
        if (code==open.at(i).code){
            return true;
        }
    }
    return false;
}
Ejemplo n.º 22
0
/* called when A's timer goes off
 * THis is used to implement multiple timers.
 * A default timeout is set initally.
 * A time_offset(which is equal to the time_local at transmission) is stored with
 * every packet. When there is a timeout, each time_offset field unacked packets in the window
 * compared with the current time_local time. It is within -1 to 1,then we say that
 * a timeout has occurred for the particular packet.
 * At the same time, we calculate the lowest timeout for the remaining packets
 * and use this to set the next timeout at which A_timerinterrrupt gets called again.
 * */
void A_timerinterrupt() //ram's comment - changed the return type to void.
{
	cout<<"*************************Inside A_timerinterrupt start*************************"<<endl;
	//Find the packets with timeouts...retransmit them
	//Find the timeout for the least timeoffset packet. use this to set the new timeoffset
	bool flag=true;
	timerPacket * tempTimerPacket;
	float currentTime=time_local;
	float remainingTime=0.0;
	float leastTimeout=getTimeout();
	int packetWithLeastTimeout=-1;
	for(int i=a_base;i<senderBuffer.size()&&i<a_base+a_windowSize;i++){
		tempTimerPacket=senderBuffer.at(i);
		remainingTime=tempTimerPacket->timeOffset - currentTime;
		if(tempTimerPacket->ackedFlag==false){
			if((remainingTime>=0.0 && remainingTime <=1.0)||(remainingTime < 0.0 && remainingTime >=-1.0)){

				if(flag){
					//Timeout occured. Retransmit the last packet sent
					cout<<"A->Timeout occured. Retransmitting previous packets"<<endl;
					flag=false;
					leastTimeout=999;
				}

				if(i==a_base){
						timeout=a_static_timeout;
						estimateTimeout(estimatedRTT);
					}

				//We have packet which must be retransmitted
				tempTimerPacket->timeOffset=currentTime+getTimeout();
				/*Added for timeout Estimation*/
				tempTimerPacket->retransmitFlag=true;
				cout<<"A->Retransmitting packet with Sequence number:"<<tempTimerPacket->packet->seqnum<<endl;
				a_totalPacketsSentFromTran++;
				tolayer3(0,*(tempTimerPacket->packet));
			}
			if(leastTimeout>(tempTimerPacket->timeOffset-currentTime)){
				leastTimeout=tempTimerPacket->timeOffset-currentTime;
				packetWithLeastTimeout=i;
			}
		}
	}
	cout<<"Next timeout set after "<<leastTimeout<<" time units for packet:"<<(packetWithLeastTimeout==-1?-1:senderBuffer.at(packetWithLeastTimeout)->packet->seqnum)<<endl;
	starttimer(0,leastTimeout);
	cout<<"*************************Inside A_timerinterrupt end*************************"<<endl;

}
void TrainNodeList::build(deque<char*> &modelnames)
	{
	if(!train)	return;	//return if there is no train

	nodelist.clear();

	for(int i=0;i<train->cars.size();i++)
		{
		if(modelnames.size()>i)		//ie there are enough model names
			{
			CarNode carnode(smgr);
			carnode.setCar(&(train->cars.at(i)));
			carnode.loadmodel(modelnames.at(i));
			nodelist.push_back(carnode);
			}
		}
	}
Ejemplo n.º 24
0
bool GxlHandler::handleData(const wstring &data)
{
	if (_elements.size() < 2)
		return true;

	const wstring &element = _elements.back();
	const wstring &parent = _elements.at(_elements.size() - 2);

	if (isAtomicAttribute(element)) {
		if (isCompositeAttribute(parent) && !_data.empty())
			_data += compositeDelimiter + data;
		else
			_data = data;
	}

	return true;
}
Ejemplo n.º 25
0
deque<int> linear_sieve(deque<int> &numbers) {
  unordered_map<int, bool> isNotPrime;
  deque<int> primes;
  auto max = numbers.at(numbers.size() - 1);
  cout << max << '\n';
  for (auto &number: numbers) {
    if (isNotPrime.find(number) == isNotPrime.end()) {
      primes.push_back(number);
    }
    auto prime_size = primes.size();
    for (int i = 0, product; i < prime_size && (product = primes.at(i) * number) <= max; i++) {
      isNotPrime[product] = true;
      if (number % primes.at(i) == 0) break;
    }
  }
  return primes;
}
bool appendTxtToOutput(string content){
	if (outputPath.compare("") == 0){
		MessageBox(hWnd, "Save log failed. Please set up output file and try to save again!", "WARNING", MB_OK);
		return false;
	}

	outputStream << content << endl;
	outputLog.push_back(content);
	while (outputLog.size() > SHOW_LOG_SIZE){
		outputLog.pop_front();
	}

	string log = "";
	for (int i = 0; i < outputLog.size(); i++){
		log += " " + outputLog.at(i) + "\n";
	}
	Set_Text(result_handle, (char*)log.c_str());
	return true;
}
Ejemplo n.º 27
0
/*This function sends multiple packets(inside the window) in Bulk
 * */
void sendPacketsinBulk(){
	bool flag=true;
	/*	int count=0; */
	timerPacket* senderPacket=NULL;
	while((a_nextseqnum < senderBuffer.size())&&(a_nextseqnum < a_base + a_windowSize)){
		if(flag){
			flag=false;
			cout<<"A->Sending packets in Bulk."<<endl;
		}

		senderPacket=senderBuffer.at(a_nextseqnum);
		senderPacket->timeOffset=time_local+getTimeout();
		senderPacket->start_time=time_local;
		a_nextseqnum++;
		tolayer3(0,*(senderPacket->packet));
		cout<<"A->Packet with Sequence number "<<senderPacket->packet->seqnum<<". checksum:"<<senderPacket->packet->checksum<<" sent from A time:"<<time_local<<endl;
		fflush(stdout);
		a_totalPacketsSentFromTran++;
	}
}
Ejemplo n.º 28
0
bool GxlHandler::handleElement(const wstring &element)
{
	Vertex *vertex;
	Edge *edge;

	if (element == NODE) {
		if (!(vertex = addVertex(_nodeAttributes.id)))
			return false;

		for (list_iterator it = _nodeAttributes.attributes.begin();
		  it != _nodeAttributes.attributes.end(); it++)
			vertex->addAttribute(*it);
		vertex->addAttribute(wstring_pair(L"id", _nodeAttributes.id));

		clearNodeAttributes();
	} else if (element == EDGE) {
		if (!(edge = addEdge(_edgeAttributes.from, _edgeAttributes.to)))
			return false;

		for (list_iterator it = _edgeAttributes.attributes.begin();
		  it != _edgeAttributes.attributes.end(); it++)
			edge->addAttribute(*it);
		if (!_edgeAttributes.id.empty())
			edge->addAttribute(wstring_pair(L"id", _edgeAttributes.id));

		clearEdgeAttributes();
	} else if (element == ATTR) {
		const wstring &parent = _elements.at(_elements.size() - 2);
		if (parent == NODE)
			_nodeAttributes.attributes.push_back(
			  wstring_pair(_attrAttributes.name, _data));
		if (parent == EDGE)
			_edgeAttributes.attributes.push_back(
			  wstring_pair(_attrAttributes.name, _data));
		_data.clear();
	}

	return true;
}
Ejemplo n.º 29
0
int printLines(string filestring,deque<string> v,unsigned long beg,unsigned long count)
{
	//getting count
	string f = filestring + COUNTSTRING;
	string s = "0";
	fstream file (f, ios::in | ios::out);
	if(!file.is_open())
		return -1;
	getline(file,s);
	int lines = Str2Int(s);
	file.close();
	//storing values
	f = filestring + NUMBERSTRING;
	file.open(f, ios::in | ios::out | ios::app);
	f = filestring + POSITIONSTRING;
	fstream file2(f,ios::in | ios::out | ios::app);
	if(!file.is_open() || !file2.is_open())
		return -2;
	for(unsigned long i = beg;i<beg+count;i++)
	{
		file << endl;
		if((i+lines-beg+1)%CHUNKSIZE == 1)
		{
			file2 << endl << file.tellp();
		}
		file << v.at(i);
	}
	file.close();
	file2.close();

	//setting count
	f = filestring + COUNTSTRING;
	file.open(f,ios::in | ios::out | ios::trunc);
	if(!file.is_open())
		return -3;
	file << (count+lines);
	file.close();
	return 0;
}
 static void SortByFrequency(deque<CharacterNode*>& results){
     bool isSorted = false;
     while (!isSorted) {
         int sCount = 0;
         for (int i = 1; i < results.size(); i++) {
             if (results.at(i - 1)->count < results.at(i)->count) {
                 sCount++;
                 CharacterNode* temp = results.at(i);
                 results.at(i) = results.at(i - 1);
                 results.at(i - 1) = temp;
             }
         }
         if (sCount == 0) {
             isSorted = true;
         }
     }
 }