예제 #1
0
파일: Node.hpp 프로젝트: atripathy86/srn
inline bool greater_than_strict(std::multiset< int > multiset1, std::multiset< int > multiset2, unsigned int id1, unsigned int id2){

			std::multiset< int >::iterator multiset1_itr = multiset1.begin(), multiset2_itr = multiset2.begin();
			int fi,fj;

 			for ( fi = multiset1.size(),fj = multiset2.size(); fi>0 && fj>0 ;fi--,fj--)
			{
 
				if (*multiset1_itr == *multiset2_itr)
				{
					multiset1_itr++ , multiset2_itr++;
				}
				else {
				
 					//return *multiset1_itr < *multiset2_itr ; //ascending
					return *multiset1_itr > *multiset2_itr ;//descending
				}
			}

			//Haven't returned yet and the foor loop exited, so that means the two input multiset have equal entries atleast the common portions 
 			if (fi==fj)
 			{
				//If they are equal, that means the relevance multiset is exactly the same, in that case we need to enforce stricter ordering based on node ids
				return id1> id2; //Descending
 			}
			//return (fi<fj);//asecending
			return (fi>fj);//descending

};
예제 #2
0
bool Serialization::save(std::multiset<Event *, Cmp_event_day> &events)
{
    //Save file to disk
    QFile file("events.txt");
    if(!file.open(QIODevice::WriteOnly))
    {
        qDebug() << "Could not open file";
        return false;
    }

    //create output stream
    QDataStream out (&file);
    //set output version
    out.setVersion(QDataStream::Qt_4_8);

    //iteration
    std::multiset<Event *>::iterator it;
    for ( it=events.begin() ; it != events.end(); it++ )
        out << **it;

    //Finito! flush the stream to the file and close
    file.flush();
    file.close();
    return true;
}
예제 #3
0
/**
 A = x1 or x2 or ... xn
 create cnf to create an Equility.
 * @brief Solver::SatBaseClass::createTseitinOr
 * @param vars x1, ..., xn
 * @return A
*/
uint Solver::SatBaseClass::createTseitinOr(std::multiset<literal>& vars){
    if(vars.size() == 0) return getFalseVar();
    if(vars.size() == 1) return (*vars.begin()).varId;
    uint A(++countVars);
// if A is true, then one of the xi must be true
    result << "-" << A << " ";
    for(const literal& t: vars){
        if(t.positiv){
            result << t.varId << " ";
        }else {
            result << "-" << t.varId << " ";
        }
    }
    result << "0" << std::endl;
    countClausel++;

// if one of the xi is true then A is true
    for(const literal& t: vars){
        result << A << " ";
        if(t.positiv){
            result << "-" << t.varId << " 0" << std::endl;
        } else {
            result << t.varId << " 0" << std::endl;
        }
        countClausel++;
    }
    return A;
}
void populateMultiset(std::multiset<sdEvent*, sdEventCompare> eventSet) {
    std::multiset <sdEvent*, sdEventCompare>::iterator eit = eventSet.begin();
    while(eit != eventSet.end()) {
        sdEvent* event = *eit;
        std::cout << "   " << event->getTime() << ":" << event->getDescriptorAsString() << " " << event->getValueAsString() << std::endl;
        eit++;
    }
}
예제 #5
0
int main()
{
    typedef test_compare<std::less<int> > C;
    const std::multiset<int, C> m(C(3));
    assert(m.empty());
    assert(m.begin() == m.end());
    assert(m.key_comp() == C(3));
    assert(m.value_comp() == C(3));
}
예제 #6
0
파일: Node.hpp 프로젝트: atripathy86/srn
//if return is 0 then neither greater or equal, if returned 1 then equal, if 2 then greater
inline int equal_and_greater(std::multiset< int > multiset1, std::multiset< int > multiset2){

			std::multiset< int >::iterator multiset1_itr = multiset1.begin(), multiset2_itr = multiset2.begin();
			int fi,fj;
 
			for ( fi = multiset1.size(),fj = multiset2.size(); fi>0 && fj>0 ;fi--,fj--)
			{
				if (*multiset1_itr == *multiset2_itr)
				{
					multiset1_itr++ ; multiset2_itr++;  
				}
				else {
					return ((*multiset1_itr > *multiset2_itr) ? 2 : (*multiset1_itr == *multiset2_itr)?  1 : 0) ;
				}
 			}
			
			return (fi < fj) ? 0: (fi > fj) ? 2: 1;

};
예제 #7
0
 inline std::string PrettyPrint(const std::multiset<T>& settoprint, const bool add_delimiters=false, const std::string& separator=", ")
 {
     std::ostringstream strm;
     if (settoprint.size() > 0)
     {
         if (add_delimiters)
         {
             strm << "(";
             typename std::multiset<T, Compare, Allocator>::const_iterator itr;
             for (itr = settoprint.begin(); itr != settoprint.end(); ++itr)
             {
                 if (itr != settoprint.begin())
                 {
                     strm << separator << PrettyPrint(*itr, add_delimiters, separator);
                 }
                 else
                 {
                     strm << PrettyPrint(*itr, add_delimiters, separator);
                 }
             }
             strm << ")";
         }
         else
         {
             typename std::multiset<T, Compare, Allocator>::const_iterator itr;
             for (itr = settoprint.begin(); itr != settoprint.end(); ++itr)
             {
                 if (itr != settoprint.begin())
                 {
                     strm << separator << PrettyPrint(*itr, add_delimiters, separator);
                 }
                 else
                 {
                     strm << PrettyPrint(*itr, add_delimiters, separator);
                 }
             }
         }
     }
     return strm.str();
 }
bool TrajectoryEvaluator::checkTrajectoriesForCollision(const std::multiset<PolyTraj2D, PolyTraj2D::CompPolyTraj2D>& traj_set,
    const std::map<int, Vehicle>& predicted_obstacles, const std::string set_name,
    std::multiset<PolyTraj2D>::const_iterator& best_traj, double& longest_time_to_collision) {

  bool collision = true, found_maybe = false;
  double collision_time;
  longest_time_to_collision = 0;
  std::multiset<PolyTraj2D>::const_iterator it_traj;
  uint32_t j = 0;
  for (it_traj = traj_set.begin(), j = 0; it_traj != traj_set.end(); it_traj++, j++) {

    TrjOccupancyState_t static_collision = TRJ_BLOCKED;
    if (obstacle_map_) {
      pthread_mutex_lock(&obstacle_map_mutex_);
      static_collision = checkCollisionStatic(it_traj->trajectory2D_); // TODO: add collision_time and longest_time_to_collision to static check
      pthread_mutex_unlock(&obstacle_map_mutex_);

      if (static_collision==TRJ_BLOCKED) {
        continue;
      }
//      std::vector<driving_common::TrajectoryPoint2D>::const_iterator tit = it_traj->trajectory2D_.begin(), tit_end = it_traj->trajectory2D_.end();
//      bool zero_velocity=true;
//      for(; tit!=tit_end; tit++) {
//      if(std::abs((*tit).v)>.01) {zero_velocity=false; break;}
//      }
//      if(zero_velocity) {continue;}
    }

    if (!checkCollisionOfTrajectoriesDynamic(it_traj->trajectory2D_, predicted_obstacles, collision_time)) {
      if (j != 0) {std::cout << j << "th trajectory (" << set_name << ") of " << traj_set.size() << " is free.\n";}
      longest_time_to_collision = std::numeric_limits<double>::infinity();
        // we found a collision-free trajectory regardless if it's in maybe range or not
      collision = false;
        // if we did not find any free before or we found a free now and had a maybe before => update best trajectory
      if(!found_maybe || static_collision==TRJ_FREE) {best_traj = it_traj;}
        // if there are only maybes we want the one that was found first since it's the best :-)
        // otherwise we found a free one and are done
      if(static_collision==TRJ_MAYBE_BLOCKED) {found_maybe=true;}
      else {
        break;
      }
    }
    else {
      if (collision_time > longest_time_to_collision) {
        longest_time_to_collision = collision_time;
        best_traj = it_traj;
      }
    }
  }

  return collision;
}
double Basket::total() const
{
    double sum = 0.0;

    for(const_iter i = items.begin() ;  i != items.end() ; i = items.upper_bound(*i))
    {
        sum += (*i)->net_price(items.count(*i));
    }


    return sum;

}
예제 #10
0
파일: daemon.cpp 프로젝트: roastduck/YAUJ
		virtual Json::Value judgeStatus()
		{
			Json::Value ret;
			ret["runningCnt"]=runningCnt;
			ret["totDumpCmdCnt"]=totCnt;
			ret["preserveCnt"]=preserveCnt;
			ret["boardingPass"]=Json::Value();
			pthread_mutex_lock(&cntLock);
			for (std::multiset<int>::iterator i=boardingPass.begin(); i!=boardingPass.end(); i++)
				ret["boardingPass"].append(*i);
			pthread_mutex_unlock(&cntLock);
			return ret;
		}
예제 #11
0
파일: Node.hpp 프로젝트: atripathy86/srn
inline bool greater_than(std::multiset< int > multiset1, std::multiset< int > multiset2){

			std::multiset< int >::iterator multiset1_itr = multiset1.begin(), multiset2_itr = multiset2.begin();
			int fi,fj;

 			for ( fi = multiset1.size(),fj = multiset2.size(); fi>0 && fj>0 ;fi--,fj--)
			{
 
				if (*multiset1_itr == *multiset2_itr)
				{
					multiset1_itr++ , multiset2_itr++;
				}
				else {
				
 					//return *multiset1_itr < *multiset2_itr ; //ascending
					return *multiset1_itr > *multiset2_itr ;//descending
				}
			}

			//Haven't returned yet and the foor loop exited, so that means the two input multiset have equal entries atleast the common portions 
 			//return (fi<fj);//asecending
			return (fi>fj);//descending
};
예제 #12
0
inline void converter<point_t>::knot_insertion(
    point_container_t& P,
    std::multiset<typename point_t::value_type>& knots,
    std::size_t order) const {
  //typedef typename point_t::value_type value_type;
  std::set<value_type> unique(knots.begin(), knots.end());

  for (typename std::set<value_type>::const_iterator i = unique.begin();
       i != unique.end();
       ++i) {
    if (knots.count(*i) < order - 1) {
      knot_insertion(P, knots, order, *i);
    }
  }
}
예제 #13
0
void ExpMapGenerator::RemoveNeighbours( ExpMapParticle * pParticle, std::multiset< ParticleQueueWrapper > & pq )
{
	ExpMapParticle::ListEntry * pCur = GetNeighbourList( pParticle );
	if ( pCur == NULL ) lgBreakToDebugger();
	while ( pCur != NULL ) {

		ExpMapParticle * pCurParticle = pCur->pParticle;
		pCur = pCur->pNext;

		if ( pCurParticle->State() != ExpMapParticle::Active )
			continue;

		// find entry in pq
#if 1
		std::multiset<ParticleQueueWrapper>::iterator found( 
			pq.find( ParticleQueueWrapper( pCurParticle->SurfaceDistance() ) ) );
		if ( found != pq.end() ) {

			while ( (*found).Particle() != pCurParticle &&
						(*found).QueueValue() == pCurParticle->SurfaceDistance() )
				++found;

			// [RMS: this should always happen...]
			lgASSERT( (*found).Particle() == pCurParticle );
			if ( (*found).Particle() == pCurParticle ) {
				pq.erase( found );
			}
		} else {
			lgASSERT( found != pq.end() );
		}

#else 
		std::multiset<ParticleQueueWrapper>::iterator cur( pq.begin() );
		bool bFound = false;
		while ( !bFound && cur != pq.end() ) {
			if ( (*cur).Particle() == pCurParticle ) {
				pq.erase( cur );
				bFound = true;
			} else
				++cur;
		}
		lgASSERT( bFound );
#endif

	}
}
예제 #14
0
파일: set.hpp 프로젝트: rpclib/rpclib
 void operator()(clmdep_msgpack::object::with_zone& o, const std::multiset<T, Compare, Alloc>& v) const {
     o.type = clmdep_msgpack::type::ARRAY;
     if (v.empty()) {
         o.via.array.ptr = nullptr;
         o.via.array.size = 0;
     } else {
         uint32_t size = checked_get_container_size(v.size());
         clmdep_msgpack::object* p = static_cast<clmdep_msgpack::object*>(o.zone.allocate_align(sizeof(clmdep_msgpack::object)*size));
         clmdep_msgpack::object* const pend = p + size;
         o.via.array.ptr = p;
         o.via.array.size = size;
         typename std::multiset<T, Compare, Alloc>::const_iterator it(v.begin());
         do {
             *p = clmdep_msgpack::object(*it, o.zone);
             ++p;
             ++it;
         } while(p < pend);
     }
 }
void f_multiset() {
  std::multiset<int> C;
  std::multiset<int>::iterator MSetI1 = C.begin();
  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use auto when declaring iterators
  // CHECK-FIXES: auto MSetI1 = C.begin();

  std::multiset<int>::reverse_iterator MSetI2 = C.rbegin();
  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use auto when declaring iterators
  // CHECK-FIXES: auto MSetI2 = C.rbegin();

  const std::multiset<int> D;
  std::multiset<int>::const_iterator MSetI3 = D.begin();
  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use auto when declaring iterators
  // CHECK-FIXES: auto MSetI3 = D.begin();

  std::multiset<int>::const_reverse_iterator MSetI4 = D.rbegin();
  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use auto when declaring iterators
  // CHECK-FIXES: auto MSetI4 = D.rbegin();
}
예제 #16
0
파일: TimerQueue.hpp 프로젝트: DRIZO/xcsoar
 /**
  * Does the specified time stamp occur before the first scheduled
  * timer?  If this returns true, then adding a timer at the
  * specified time stamp will require adjusting the poll timeout,
  * i.e. the event thread must be woken up.
  */
 bool IsBefore(uint64_t t) const {
   return timers.empty() || t < timers.begin()->due_us;
 }
예제 #17
0
void record_sim(int i)
{
	std::deque<str_and_Bond>::iterator iter;
	double temp_x;
	double temp_y;
	double temp_r_sq;

	for(iter=growth.begin(); iter!=growth.end(); iter++)
	{
		temp_x = iter->second.second.first;
		temp_y = iter->second.second.second;
		temp_r_sq = temp_x*temp_x+temp_y*temp_y;
		r_squared_array.insert(temp_r_sq);
	}

	long int count = 0;

	std::multiset<long long int>::iterator iter2 = r_squared_array.begin();

	for(int j=0; j<num_r_values; j++)
	{

		while(count<growth.size() && *iter2 < r[j]*r[j])
		{
			count++;
			iter2++;
		}
		M_array[i][j] = count;
	}

	for(iter=removed.begin(); iter!=removed.end(); iter++)
	{
		temp_x = iter->second.second.first;
		temp_y = iter->second.second.second;
		temp_r_sq = temp_x*temp_x+temp_y*temp_y;
		r_squared_array.insert(temp_r_sq);
	}

	count = 0;
	iter2 = r_squared_array.begin();

	for(int j=0; j<num_r_values; j++)
	{

		while(count<growth.size() + removed.size() && *iter2 < r[j]*r[j])
		{
			count++;
			iter2++;
		}
		Both_array[i][j] = count;
	}

	r_squared_array.clear();

	for(iter=removed.begin(); iter!=removed.end(); iter++)
	{
		temp_x = iter->second.second.first;
				temp_y = iter->second.second.second;
				temp_r_sq = temp_x*temp_x+temp_y*temp_y;
				r_squared_array.insert(temp_r_sq);
	}

	count = 0;
	iter2 = r_squared_array.begin();

	for(int j=0; j<num_r_values; j++)
	{

		while(count<removed.size() && *iter2 < r[j]*r[j])
		{
			count++;
			iter2++;
		}
		Removed_array[i][j] = count;
	}

	std::map<Site, int>::iterator iter3;

	for(iter3 = chem_level_list.begin(); iter3 != chem_level_list.end(); iter3++)
	{
		if(iter3->second < chem_level_cutoff)
		{
			chem_level_array[i][iter3->second]++;
		}
	}

	std::deque<boost::tuple<int, int, long int> >::iterator burst_iter = burst_list.begin();
	std::deque<boost::tuple<int, int, long int> >::iterator burst_list_end = burst_list.end();

	int burst_x;
	int burst_y;
	long int burst_size;

	while(burst_iter != burst_list_end)
	{
		burst_x = burst_iter->get<0>();
		burst_y = burst_iter->get<1>();
		burst_size = burst_iter->get<2>();

		burst_array.push_back(boost::make_tuple(i, burst_x, burst_y, burst_size));

		burst_iter++;
	}
}
예제 #18
0
		inline BOSTREAM2(const std::multiset<T, C, A> &a) { return itwrite(out, a.size(), a.begin()); }
예제 #19
0
int main()
{
    {
        typedef int V;
        V ar[] =
        {
            1,
            1,
            1,
            2,
            2,
            2,
            3,
            3,
            3,
            4,
            4,
            4,
            5,
            5,
            5,
            6,
            6,
            6,
            7,
            7,
            7,
            8,
            8,
            8
        };
        std::multiset<int> m(ar, ar+sizeof(ar)/sizeof(ar[0]));
        assert(std::distance(m.begin(), m.end()) == m.size());
        assert(std::distance(m.rbegin(), m.rend()) == m.size());
        std::multiset<int>::iterator i;
        i = m.begin();
        std::multiset<int>::const_iterator k = i;
        assert(i == k);
        for (int j = 1; j <= 8; ++j)
            for (int k = 0; k < 3; ++k, ++i)
                assert(*i == j);
    }
    {
        typedef int V;
        V ar[] =
        {
            1,
            1,
            1,
            2,
            2,
            2,
            3,
            3,
            3,
            4,
            4,
            4,
            5,
            5,
            5,
            6,
            6,
            6,
            7,
            7,
            7,
            8,
            8,
            8
        };
        const std::multiset<int> m(ar, ar+sizeof(ar)/sizeof(ar[0]));
        assert(std::distance(m.begin(), m.end()) == m.size());
        assert(std::distance(m.cbegin(), m.cend()) == m.size());
        assert(std::distance(m.rbegin(), m.rend()) == m.size());
        assert(std::distance(m.crbegin(), m.crend()) == m.size());
        std::multiset<int, double>::const_iterator i;
        i = m.begin();
        for (int j = 1; j <= 8; ++j)
            for (int k = 0; k < 3; ++k, ++i)
                assert(*i == j);
    }
}
예제 #20
0
inline void converter<point_t>::knot_insertion(point_container_t& P,
                                               std::multiset<value_type>& knots,
                                               std::size_t order,
                                               value_type t) const {
  typedef typename point_t::value_type value_type;

  // copy knotvector for subscript [] access
  std::vector<value_type> kv_cpy(knots.begin(), knots.end());
  // get parameter
  std::size_t p = order - 1;                        // degree
  std::size_t s = knots.count(t);                   // multiplicity
  std::size_t r = std::max(std::size_t(0), p - s);  // number of insertions

  // get knotspan
  std::size_t k = std::distance(knots.begin(), knots.upper_bound(t));
  std::size_t np = P.size();  // number of control points

  // start computation
  std::size_t nq = np + r;

  // helper arrays
  std::vector<point_t> Qw(nq);
  std::vector<point_t> Rw(p - s + 1);

  // copy unaffected points and transform into homogenous coords
  for (size_t i = 0; i <= k - p; ++i) {
    Qw[i] = P[i].as_homogenous();
  }
  for (size_t i = k - s - 1; i <= np - 1; ++i) {
    Qw[i + r] = P[i].as_homogenous();
  }

  // helper points
  for (size_t i = 0; i <= p - s; ++i) {
    Rw[i] = P[k - p + i - 1].as_homogenous();
  }

  // do knot insertion itself
  std::size_t L = 0;
  for (std::size_t j = 1; j <= r; ++j) {
    L = k - p + j;
    for (std::size_t i = 0; i <= p - j - s; ++i) {
      value_type alpha =
          (t - kv_cpy[L + i - 1]) / (kv_cpy[i + k] - kv_cpy[L + i - 1]);
      Rw[i] = alpha * Rw[i + 1] + value_type(1.0 - alpha) * Rw[i];
    }
    Qw[L - 1] = Rw[0];
    Qw[k + r - j - s - 1] = Rw[p - j - s];
  }

  // insert knots
  for (std::size_t i = 0; i < r; ++i) {
    knots.insert(t);
  }

  // copy new control points
  P.clear();

  // transform back to euclidian space
  for (typename std::vector<point_t>::iterator i = Qw.begin(); i != Qw.end();
       ++i) {
    P.push_back((*i).as_euclidian());
  }
}
예제 #21
0
 matrix<T> const diag( const std::multiset<T,C,A>& v, const std::ptrdiff_t offset = 0 )
 {
     return diag_private::impl_diag( v.begin(), v.end(), offset );
 }
예제 #22
0
파일: set.hpp 프로젝트: 4eek/xtractorfan
 std::size_t hash_value(std::multiset<K, C, A> const& v)
 {
     return hash_range(v.begin(), v.end());
 }