Exemplo n.º 1
0
    static inline void apply(Point const& point,
                             iterator_type first,
                             iterator_type last,
                             Strategy const& strategy,
                             iterator_type& it_min1,
                             iterator_type& it_min2,
                             Distance& dist_min)
    {
        BOOST_ASSERT( first != last );

        base_type::apply(point, first, last, strategy,
                         it_min1, it_min2, dist_min);

        iterator_type it_back = --last;
        Distance const zero = Distance(0);
        Distance dist = strategy.apply(point, *it_back, *first);

        if (geometry::math::equals(dist, zero))
        {
            dist_min = zero;
            it_min1 = it_back;
            it_min2 = first;
        }
        else if (dist < dist_min)
        {
            dist_min = dist;
            it_min1 = it_back;
            it_min2 = first;
        }
    }    
Exemplo n.º 2
0
void Engine::addStrategy(string name)
{
    removeStrategy(name);

    Strategy* strategy = aiObjectContext->GetStrategy(name);
    if (strategy)
    {
        set<string> siblings = aiObjectContext->GetSiblingStrategy(name);
        for (set<string>::iterator i = siblings.begin(); i != siblings.end(); i++)
            removeStrategy(*i);

        LogAction("S:+%s", strategy->getName().c_str());
        strategies[strategy->getName()] = strategy;
    }
    Init();
}
Exemplo n.º 3
0
    static inline void apply(Ring const& ring,
                             PointTransformer const& transformer,
                             Strategy const& strategy,
                             typename Strategy::state_type& state)
    {
        geofeatures_boost::ignore_unused(strategy);

        typedef typename geometry::point_type<Ring const>::type point_type;
        typedef typename closeable_view<Ring const, Closure>::type view_type;

        typedef typename geofeatures_boost::range_iterator<view_type const>::type iterator_type;

        view_type view(ring);
        iterator_type it = geofeatures_boost::begin(view);
        iterator_type end = geofeatures_boost::end(view);

        typename PointTransformer::result_type
            previous_pt = transformer.apply(*it);

        for ( ++it ; it != end ; ++it)
        {
            typename PointTransformer::result_type
                pt = transformer.apply(*it);

            strategy.apply(static_cast<point_type const&>(previous_pt),
                           static_cast<point_type const&>(pt),
                           state);
            
            previous_pt = pt;
        }
    }
Exemplo n.º 4
0
    static inline bool apply(Multi const& multi,
                             Point& centroid,
                             Strategy const& strategy)
    {
#if ! defined(BOOST_GEOMETRY_CENTROID_NO_THROW)
        // If there is nothing in any of the ranges, it is not possible
        // to calculate the centroid
        if (geometry::is_empty(multi))
        {
            throw centroid_exception();
        }
#endif

        // prepare translation transformer
        translating_transformer<Multi> transformer(multi);

        typename Strategy::state_type state;

        for (typename geofeatures_boost::range_iterator<Multi const>::type
                it = geofeatures_boost::begin(multi);
            it != geofeatures_boost::end(multi);
            ++it)
        {
            Policy::apply(*it, transformer, strategy, state);
        }

        if ( strategy.result(state, centroid) )
        {
            // translate the result back
            transformer.apply_reverse(centroid);
            return true;
        }
        
        return false;
    }
Exemplo n.º 5
0
    static inline return_type apply(
            Range const& range, Strategy const& strategy)
    {
        boost::ignore_unused_variable_warning(strategy);
        typedef typename closeable_view<Range const, Closure>::type view_type;
        typedef typename boost::range_iterator
            <
                view_type const
            >::type iterator_type;

        return_type sum = return_type();
        view_type view(range);
        iterator_type it = boost::begin(view), end = boost::end(view);
        if(it != end)
        {
            for(iterator_type previous = it++;
                    it != end;
                    ++previous, ++it)
            {
                // Add point-point distance using the return type belonging
                // to strategy
                sum += strategy.apply(*previous, *it);
            }
        }

        return sum;
    }
    static inline
    typename distance_result
        <
            typename point_type<Point>::type,
            typename point_type<Range>::type,
            Strategy
        >::type
    apply(Point const& pnt, Range const& rng, Strategy const& strategy)
    {
        typedef typename distance_result
            <
                typename point_type<Point>::type,
                typename point_type<Range>::type,
                Strategy
            >::type result_type;
        typedef typename boost::range_size<Range>::type size_type;

        size_type const n = boost::size(rng);
        result_type dis_min = 0;
        bool is_dis_min_set = false;

        for (size_type i = 0 ; i < n ; i++)
        {
            result_type dis_temp = strategy.apply(pnt, range::at(rng, i));
            if (! is_dis_min_set || dis_temp < dis_min)
            {
                dis_min = dis_temp;
                is_dis_min_set = true;
            }
        }
        return dis_min;
    }
Exemplo n.º 7
0
    void Request::process( int attempt ) {
        init();
        int op = _m.operation();
        verify( op > dbMsg );

        int msgId = (int)(_m.header()->id);

        Timer t;
        LOG(3) << "Request::process begin ns: " << getns()
               << " msg id: " << msgId
               << " op: " << op
               << " attempt: " << attempt
               << endl;

        Strategy * s = SHARDED;

        _d.markSet();

        bool iscmd = false;
        if ( op == dbKillCursors ) {
            cursorCache.gotKillCursors( _m );
        }
        else if ( op == dbQuery ) {
            iscmd = isCommand();
            if (iscmd) {
                SINGLE->queryOp(*this);
            }
            else {
                s->queryOp( *this );
            }
        }
        else if ( op == dbGetMore ) {
            s->getMore( *this );
        }
        else {
            s->writeOp( op, *this );
        }

        LOG(3) << "Request::process end ns: " << getns()
               << " msg id: " << msgId
               << " op: " << op
               << " attempt: " << attempt
               << " " << t.millis() << "ms"
               << endl;

        globalOpCounters.gotOp( op , iscmd );
    }
Exemplo n.º 8
0
StrategyChoice::InsertResult
StrategyChoice::insert(const Name& prefix, const Name& strategyName)
{
  if (prefix.size() > NameTree::getMaxDepth()) {
    return InsertResult::DEPTH_EXCEEDED;
  }

  unique_ptr<Strategy> strategy;
  try {
    strategy = Strategy::create(strategyName, m_forwarder);
  }
  catch (const std::invalid_argument& e) {
    NFD_LOG_ERROR("insert(" << prefix << "," << strategyName << ") cannot create strategy: " << e.what());
    return InsertResult(InsertResult::EXCEPTION, e.what());
  }

  if (strategy == nullptr) {
    NFD_LOG_ERROR("insert(" << prefix << "," << strategyName << ") strategy not registered");
    return InsertResult::NOT_REGISTERED;
  }

  name_tree::Entry& nte = m_nameTree.lookup(prefix);
  Entry* entry = nte.getStrategyChoiceEntry();
  Strategy* oldStrategy = nullptr;
  if (entry != nullptr) {
    if (entry->getStrategyInstanceName() == strategy->getInstanceName()) {
      NFD_LOG_TRACE("insert(" << prefix << ") not changing " << strategy->getInstanceName());
      return InsertResult::OK;
    }
    oldStrategy = &entry->getStrategy();
    NFD_LOG_TRACE("insert(" << prefix << ") changing from " << oldStrategy->getInstanceName() <<
                  " to " << strategy->getInstanceName());
  }
  else {
    oldStrategy = &this->findEffectiveStrategy(prefix);
    auto newEntry = make_unique<Entry>(prefix);
    entry = newEntry.get();
    nte.setStrategyChoiceEntry(std::move(newEntry));
    ++m_nItems;
    NFD_LOG_TRACE("insert(" << prefix << ") new entry " << strategy->getInstanceName());
  }

  this->changeStrategy(*entry, *oldStrategy, *strategy);
  entry->setStrategy(std::move(strategy));
  return InsertResult::OK;
}
Exemplo n.º 9
0
    static inline void apply(Point const& point,
                             iterator_type first,
                             iterator_type last,
                             Strategy const& strategy,
                             iterator_type& it_min1,
                             iterator_type& it_min2,
                             Distance& dist_min)
    {
        BOOST_GEOMETRY_ASSERT( first != last );

        Distance const zero = Distance(0);

        iterator_type it = first;
        iterator_type prev = it++;
        if (it == last)
        {
            it_min1 = it_min2 = first;
            dist_min = strategy.apply(point, *first, *first);
            return;
        }

        // start with first segment distance
        dist_min = strategy.apply(point, *prev, *it);
        iterator_type prev_min_dist = prev;

        // check if other segments are closer
        for (++prev, ++it; it != last; ++prev, ++it)
        {
            Distance dist = strategy.apply(point, *prev, *it);
            if (geometry::math::equals(dist, zero))
            {
                dist_min = zero;
                it_min1 = prev;
                it_min2 = it;
                return;
            }
            else if (dist < dist_min)
            {
                dist_min = dist;
                prev_min_dist = prev;
            }
        }

        it_min1 = it_min2 = prev_min_dist;
        ++it_min2;
    }
Exemplo n.º 10
0
/// Method invoked upon receipt a message routed through comlib.
void *strategyHandler(void *msg) {
    CmiMsgHeaderExt *conv_header = (CmiMsgHeaderExt *) msg;
    int instid = conv_header->stratid;

#ifndef CMK_OPTIMIZE
    // check that the instid is not zero, meaning a possibly uninitialized value
    if (instid == 0) {
      CmiAbort("Comlib strategy ID is zero, did you forget to initialize a variable?\n");
    }
#endif
    
    // when handling a message always call the lowest level
    Strategy *strat = ConvComlibGetStrategy(instid);
    
    strat->handleMessage(msg);
    return NULL;
}
Exemplo n.º 11
0
void SocketMonitor::block( Strategy& strategy, bool poll, double timeout )
{
  while ( m_dropped.size() )
  {
    strategy.onError( *this, m_dropped.front() );
    m_dropped.pop();
    if ( m_dropped.size() == 0 )
      return ;
  }

  fd_set readSet;
  FD_ZERO( &readSet );
  buildSet( m_readSockets, readSet );
  fd_set writeSet;
  FD_ZERO( &writeSet );
  buildSet( m_connectSockets, writeSet );
  buildSet( m_writeSockets, writeSet );
  fd_set exceptSet;
  FD_ZERO( &exceptSet );
  buildSet( m_connectSockets, exceptSet );

  if ( sleepIfEmpty(poll) )
  {
    strategy.onTimeout( *this );
    return;
  }

  int result = select( FD_SETSIZE, &readSet, &writeSet, &exceptSet, getTimeval(poll, timeout) );

  if ( result == 0 )
  {
    strategy.onTimeout( *this );
    return;
  }
  else if ( result > 0 )
  {
    processExceptSet( strategy, exceptSet );
    processWriteSet( strategy, writeSet );
    processReadSet( strategy, readSet );
  }
  else
  {
    strategy.onError( *this );
  }
}
Exemplo n.º 12
0
bool
StrategyChoice::insert(const Name& prefix, const Name& strategyName)
{
  Strategy* strategy = this->getStrategy(strategyName);
  if (strategy == nullptr) {
    NFD_LOG_ERROR("insert(" << prefix << "," << strategyName << ") strategy not installed");
    return false;
  }

  shared_ptr<name_tree::Entry> nte = m_nameTree.lookup(prefix);
  shared_ptr<Entry> entry = nte->getStrategyChoiceEntry();
  Strategy* oldStrategy = nullptr;
  if (entry != nullptr) {
    if (entry->getStrategy().getName() == strategy->getName()) {
      NFD_LOG_TRACE("insert(" << prefix << ") not changing " << strategy->getName());
      return true;
    }
    oldStrategy = &entry->getStrategy();
    NFD_LOG_TRACE("insert(" << prefix << ") changing from " << oldStrategy->getName() <<
                  " to " << strategy->getName());
  }

  if (entry == nullptr) {
    oldStrategy = &this->findEffectiveStrategy(prefix);
    entry = make_shared<Entry>(prefix);
    nte->setStrategyChoiceEntry(entry);
    ++m_nItems;
    NFD_LOG_TRACE("insert(" << prefix << ") new entry " << strategy->getName());
  }

  this->changeStrategy(*entry, *oldStrategy, *strategy);
  entry->setStrategy(*strategy);
  return true;
}
Exemplo n.º 13
0
 static inline typename default_length_result<Segment>::type apply(
         Segment const& segment, Strategy const& strategy)
 {
     typedef typename point_type<Segment>::type point_type;
     point_type p1, p2;
     geometry::detail::assign_point_from_index<0>(segment, p1);
     geometry::detail::assign_point_from_index<1>(segment, p2);
     return strategy.apply(p1, p2);
 }
Exemplo n.º 14
0
        static void apply()
        {
            Strategy *str = 0;
            state_type *st = 0;

            // 4) must implement a static method apply,
            // getting two segment-points
            spoint_type const* sp = 0;
            str->apply(*sp, *sp, *st);

            // 5) must implement a static method result
            //  getting the centroid
            point_type *c = 0;
            bool r = str->result(*st, *c);

            boost::ignore_unused_variable_warning(str);
            boost::ignore_unused_variable_warning(r);
        }
Exemplo n.º 15
0
 static inline typename return_type<Strategy>::type apply(Point const& point,
             Segment const& segment, Strategy const& strategy)
 {
     
     typename point_type<Segment>::type p[2];
     geometry::detail::assign_point_from_index<0>(segment, p[0]);
     geometry::detail::assign_point_from_index<1>(segment, p[1]);
     return strategy.apply(point, p[0], p[1]);
 }
Exemplo n.º 16
0
void time_compare_s(int const n)
{
    boost::timer t;
    P p1, p2;
    bg::assign_values(p1, 1, 1);
    bg::assign_values(p2, 2, 2);
    Strategy strategy;
    typename bg::strategy::distance::services::return_type<Strategy, P, P>::type s = 0;
    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < n; j++)
        {
            bg::set<0>(p2, bg::get<0>(p2) + 0.001);
            s += strategy.apply(p1, p2);
        }
    }
    std::cout << "s: " << s << " t: " << t.elapsed() << std::endl;
}
Exemplo n.º 17
0
 static inline void apply(Point const& point,
                          PointTransformer const& transformer,
                          Strategy const& strategy,
                          typename Strategy::state_type& state)
 {
     boost::ignore_unused(strategy);
     strategy.apply(static_cast<Point const&>(transformer.apply(point)),
                    state);
 }
Exemplo n.º 18
0
    void Request::process( int attempt ) {
        init();
        int op = _m.operation();
        assert( op > dbMsg );

        if ( op == dbKillCursors ) {
            cursorCache.gotKillCursors( _m );
            return;
        }


        MONGO_LOG(3) << "Request::process ns: " << getns() << " msg id:" << (int)(_m.header()->id) << " attempt: " << attempt << endl;

        Strategy * s = SHARDED;
        _counter = &opsNonSharded;

        _d.markSet();

        bool iscmd = false;
        if ( op == dbQuery ) {
            try {
                iscmd = isCommand();
                s->queryOp( *this );
            }
            catch ( RecvStaleConfigException& stale ) {
                _d.markReset();
                log( attempt == 0 ) << "got RecvStaleConfigException at top level: " << stale.toString() << " attempt: " << attempt << endl;
                massert( 16062 , "too many attemps to handle RecvStaleConfigException at top level" , attempt <= 5 );
                process( attempt + 1 );
                return;
            }
        }
        else if ( op == dbGetMore ) {
            checkAuth( Auth::READ ); // this is important so someone can't steal a cursor
            s->getMore( *this );
        }
        else {
            checkAuth( Auth::WRITE );
            s->writeOp( op, *this );
        }

        globalOpCounters.gotOp( op , iscmd );
        _counter->gotOp( op , iscmd );
    }
Exemplo n.º 19
0
 static inline void apply(Polygon const& poly, Point& centroid,
         Strategy const& strategy)
 {
     if (range_ok(exterior_ring(poly), centroid))
     {
         typename Strategy::state_type state;
         centroid_polygon_state::apply(poly, strategy, state);
         strategy.result(state, centroid);
     }
 }
Exemplo n.º 20
0
    static inline void apply(Point const& point, Segment const& segment,
                    Strategy const& strategy, Result& result)
    {
       
        typename point_type<Segment>::type p[2];
        geometry::detail::assign_point_from_index<0>(segment, p[0]);
        geometry::detail::assign_point_from_index<1>(segment, p[1]);

        strategy.apply(point, p[0], p[1], result);
    }
Exemplo n.º 21
0
 static inline void apply(Range const& range, Point& centroid,
         Strategy const& strategy)
 {
     if (range_ok(range, centroid))
     {
         typename Strategy::state_type state;
         centroid_range_state<Closure>::apply(range, strategy, state);
         strategy.result(state, centroid);
     }
 }
Exemplo n.º 22
0
void SocketMonitor::processExceptSet( Strategy& strategy, fd_set& exceptSet )
{
#ifdef _MSC_VER
  for ( unsigned i = 0; i < exceptSet.fd_count; ++i )
  {
    int s = exceptSet.fd_array[ i ];
    strategy.onError( *this, s );
  }
#else
    Sockets::iterator i;
    Sockets sockets = m_connectSockets;
    for ( i = sockets.begin(); i != sockets.end(); ++i )
    {
      int s = *i;
      if ( !FD_ISSET( *i, &exceptSet ) )
        continue;
      strategy.onError( *this, s );
    }
#endif
}
 static inline typename strategy::distance::services::return_type
     <
         Strategy,
         typename point_type<Box1>::type,
         typename point_type<Box2>::type
     >::type
 apply(Box1 const& box1, Box2 const& box2, Strategy const& strategy)
 {
     boost::ignore_unused(strategy);
     return strategy.apply(box1, box2);
 }
Exemplo n.º 24
0
 static inline void apply(Point1 const& point1, Point2 const& point2, Strategy const& strategy, Result& result)
 {
     result.real_distance 
         = result.projected_distance1 
         = result.projected_distance2 
         = strategy.apply_point_point(point1, point2);
     // The projected point makes not really sense in point-point.
     // We just assign one on the other
     geometry::convert(point1, result.projected_point2);
     geometry::convert(point2, result.projected_point1);
 }
Exemplo n.º 25
0
void Engine::Init()
{
    Reset();

    for (map<string, Strategy*>::iterator i = strategies.begin(); i != strategies.end(); i++)
    {
        Strategy* strategy = i->second;
        strategy->InitMultipliers(multipliers);
        strategy->InitTriggers(triggers);
        Event emptyEvent;
        MultiplyAndPush(strategy->getDefaultActions(), 0.0f, false, emptyEvent, "default");
    }

	if (testMode)
	{
        FILE* file = fopen("test.log", "w");
        fprintf(file, "\n");
        fclose(file);
	}
}
Exemplo n.º 26
0
    static inline bool apply(Geometry1 const& source, Geometry2& target,
                Strategy const& strategy)
    {
        typedef typename point_type<Geometry1>::type point_type1;
        typedef typename point_type<Geometry2>::type point_type2;

        point_type1 source_point[2];
        geometry::detail::assign_point_from_index<0>(source, source_point[0]);
        geometry::detail::assign_point_from_index<1>(source, source_point[1]);

        point_type2 target_point[2];
        if (strategy.apply(source_point[0], target_point[0])
            && strategy.apply(source_point[1], target_point[1]))
        {
            geometry::detail::assign_point_to_index<0>(target_point[0], target);
            geometry::detail::assign_point_to_index<1>(target_point[1], target);
            return true;
        }
        return false;
    }
Exemplo n.º 27
0
void test_distance_point_point(Strategy const& strategy,
                               bool is_comparable_strategy = false)
{
#ifdef BOOST_GEOMETRY_TEST_DEBUG
    std::cout << std::endl;
    std::cout << "point/point distance tests" << std::endl;
#endif
    typedef test_distance_of_geometries<point_type, point_type> tester;

    tester::apply("p-p-01",
                  "POINT(10 10)",
                  "POINT(0 0)",
                  (is_comparable_strategy
                   ? 0.0150768448035229
                   : (0.24619691677893202 * strategy.radius())),
                  0.0150768448035229,
                  strategy);
    tester::apply("p-p-02",
                  "POINT(10 10)",
                  "POINT(10 10)",
                  0,
                  strategy);

    // antipodal points
    tester::apply("p-p-03",
                  "POINT(0 10)",
                  "POINT(180 -10)",
                  (is_comparable_strategy
                   ? 1.0
                   : (180.0 * bg::math::d2r * strategy.radius())),
                  1.0,
                  strategy);
    tester::apply("p-p-04",
                  "POINT(0 0)",
                  "POINT(180 0)",
                  (is_comparable_strategy
                   ? 1.0
                   : (180.0 * bg::math::d2r * strategy.radius())),
                  1.0,
                  strategy);
}
Exemplo n.º 28
0
 static inline void apply(Range const& range, OutputIterator out,
                          Distance const& max_distance, Strategy const& strategy)
 {
     if (pdalboost::size(range) <= 2 || max_distance < 0)
     {
         std::copy(pdalboost::begin(range), pdalboost::end(range), out);
     }
     else
     {
         strategy.apply(range, out, max_distance);
     }
 }
Exemplo n.º 29
0
    static inline OutputIterator apply(UniqueSubRange1 const& range_p,
                UniqueSubRange2 const& range_q,
                TurnInfo const& ,
                Strategy const& strategy,
                RobustPolicy const& robust_policy,
                OutputIterator out)
    {
        typedef typename TurnInfo::point_type turn_point_type;

        typedef policies::relate::segments_intersection_points
            <
                segment_intersection_points
                    <
                        turn_point_type,
                        typename geometry::segment_ratio_type
                            <
                                turn_point_type, RobustPolicy
                            >::type
                    >
            > policy_type;

        typedef model::referring_segment<Point1 const> segment_type1;
        typedef model::referring_segment<Point2 const> segment_type2;
        Point1 const& pi = range_p.at(0);
        Point1 const& pj = range_p.at(1);
        Point2 const& qi = range_q.at(0);
        Point2 const& qj = range_q.at(1);
        segment_type1 p1(pi, pj);
        segment_type2 q1(qi, qj);

        typedef typename geometry::robust_point_type
            <
                Point1, RobustPolicy
            >::type robust_point_type;

        robust_point_type pi_rob, pj_rob, qi_rob, qj_rob;
        geometry::recalculate(pi_rob, pi, robust_policy);
        geometry::recalculate(pj_rob, pj, robust_policy);
        geometry::recalculate(qi_rob, qi, robust_policy);
        geometry::recalculate(qj_rob, qj, robust_policy);
        typename policy_type::return_type result
            = strategy.apply(p1, q1, policy_type(), robust_policy,
                             pi_rob, pj_rob, qi_rob, qj_rob);

        for (std::size_t i = 0; i < result.count; i++)
        {
            TurnInfo tp;
            geometry::convert(result.intersections[i], tp.point);
            *out++ = tp;
        }

        return out;
    }
Exemplo n.º 30
0
    static inline typename Strategy::return_type
    apply(Ring const& ring, Strategy const& strategy)
    {
        BOOST_CONCEPT_ASSERT( (geometry::concept::AreaStrategy<Strategy>) );
        assert_dimension<Ring, 2>();

        // Ignore warning (because using static method sometimes) on strategy
        boost::ignore_unused_variable_warning(strategy);

        // An open ring has at least three points,
        // A closed ring has at least four points,
        // if not, there is no (zero) area
        if (int(boost::size(ring))
                < core_detail::closure::minimum_ring_size<Closure>::value)
        {
            return typename Strategy::return_type();
        }

        typedef typename reversible_view<Ring const, Direction>::type rview_type;
        typedef typename closeable_view
            <
                rview_type const, Closure
            >::type view_type;
        typedef typename boost::range_iterator<view_type const>::type iterator_type;

        rview_type rview(ring);
        view_type view(rview);
        typename Strategy::state_type state;
        iterator_type it = boost::begin(view);
        iterator_type end = boost::end(view);

        for (iterator_type previous = it++;
            it != end;
            ++previous, ++it)
        {
            strategy.apply(*previous, *it, state);
        }

        return strategy.result(state);
    }