Пример #1
0
boost::tuple<int, operator_container_t::iterator, operator_container_t::iterator>
pick_up_pair(R &rng,
             const operator_container_t &c_operators,
             const operator_container_t &a_operators,
             int flavor_ins,
             int flavor_rem,
             double t1,
             double t2,
             double distance,
             double BETA) {
  namespace bll = boost::lambda;

  typedef operator_container_t::iterator it_t;

  //get views to operators in the window
  double tau_low = std::min(t1, t2);
  double tau_high = std::max(t1, t2);
  std::pair<operator_container_t::iterator, operator_container_t::iterator>
      crange = c_operators.range(tau_low <= bll::_1, bll::_1 <= tau_high);
  std::pair<operator_container_t::iterator, operator_container_t::iterator>
      arange = a_operators.range(tau_low <= bll::_1, bll::_1 <= tau_high);

  typedef std::list<std::pair<it_t, it_t> > pairs_t;
  pairs_t pairs;
  int num_pairs = 0;

  for (operator_container_t::iterator it_c = crange.first; it_c != crange.second; ++it_c) {
    if (it_c->flavor() != flavor_ins) {
      continue;
    }
    for (operator_container_t::iterator it_a = arange.first; it_a != arange.second; ++it_a) {
      if (it_a->flavor() != flavor_rem) {
        continue;
      }
      if (std::abs(it_c->time() - it_a->time()) <= distance) {
        pairs.push_back(std::make_pair(it_c, it_a));
        ++num_pairs;
      }
    }
  }

  if (num_pairs > 0) {
    int pos = (int) (rng() * num_pairs);
    pairs_t::iterator it_p = pairs.begin();
    std::advance(it_p, pos);
    return boost::make_tuple(num_pairs, (*it_p).first, (*it_p).second);
  } else {
    return boost::make_tuple(0, c_operators.end(), a_operators.end());
  }
}
Пример #2
0
int num_operators_in_range_open(const operator_container_t &operators, T t1, T t2) {
  namespace bll = boost::lambda;
  typedef operator_container_t::iterator Iterator;

  std::pair<Iterator, Iterator> ops_range
      = operators.range(
          std::min(t1, t2) < bll::_1, bll::_1 < std::max(t1, t2)
      );
  return std::distance(ops_range.first, ops_range.second);
}