fsm/builder/sphere.hpp

Go to the documentation of this file.
00001 
00027 #ifndef MSMAZES_CORE_FSM_BUILDER_SPHERE_HPP
00028 #define MSMAZES_CORE_FSM_BUILDER_SPHERE_HPP
00029 
00030 #define MSMAZES_CORE_FSM_ARITY 13
00031 
00032 // BOOST_PP_LESS
00033 #include <boost/preprocessor/comparison/less.hpp>
00034 // boost::remove_const
00035 #include <boost/type_traits/remove_const.hpp>
00036 // boost::remove_reference
00037 #include <boost/type_traits/remove_reference.hpp>
00038 // boost::mpl::apply1
00039 #include <boost/mpl/apply.hpp>
00040 // sgdk::ZeroChecker
00041 #include <swiss_gd_knife/math/zero_checker.hpp>
00042 // sgdk::PositiveRotation
00043 #include <swiss_gd_knife/math/geom/compass.hpp>
00044 // Boost.Parameter keyword objects used by the Core FSM Layer
00045 #include <msmazes/core/fsm/keywords.hpp>
00046 
00047 #if BOOST_PP_LESS(BOOST_PARAMETER_MAX_ARITY, MSMAZES_CORE_FSM_ARITY)
00048 #error Set BOOST_PARAMETER_MAX_ARITY to 13 or higher.
00049 #endif
00050 
00051 // msmazes::FSMInputMakerTraits
00052 #include <msmazes/core/fsm/input/traits_maker.hpp>
00053 // msmazes::FSMBuilder
00054 #include <msmazes/core/fsm/builder.hpp>
00055 // msmazes::MazeMakerTraits
00056 #include <msmazes/core/maze/traits_maker.hpp>
00057 // msmazes::SpherePattern
00058 #include <msmazes/core/pattern/sphere.hpp>
00059 
00060 namespace msmazes {
00061   namespace _sphere_builder {
00062 
00067     template <
00068         typename Coordinate
00069     >
00070     struct ArgumentValidationPolicy
00071     {
00072         template <
00073             typename MazeMaker
00074           , typename FSMInputMaker
00075           , typename MazePolicy
00076           , typename ArgumentPack
00077         >
00078         static bool
00079             areValidArguments(
00080                 const MazeMaker& maze_maker
00081               , const FSMInputMaker& input_maker
00082               , const MazePolicy& policy
00083               , const ArgumentPack& p
00084             )
00085         {
00086             typedef typename FSMInputMakerTraits<
00087                         FSMInputMaker
00088                     >::RequiresSingleLayer
00089                     FSMInputMakerRequiresSingleLayer;
00090 
00091             if (FSMInputMakerRequiresSingleLayer::value)
00092             {
00093                 const Coordinate r_min = p[init_radius_minimum_arg];
00094                 const Coordinate r_max = p[init_radius_maximum_arg];
00095 
00096                 sgdk::ZeroChecker<Coordinate>
00097                     zero_checker(p[init_radial_increment_arg] - 0.00001);
00098 
00099                 if (!zero_checker.isZero(r_max - r_min))
00100                 {
00101                     return false;
00102                 }
00103             }
00104 
00105             return true;
00106         }
00107     };
00108 
00113     struct parameters
00114       : boost::parameter::parameters<
00115             boost::parameter::required<
00116                 keyword_tag::rng_engine_arg
00117             >
00118           , boost::parameter::required<
00119                 keyword_tag::maze_maker_arg
00120             >
00121           , boost::parameter::required<
00122                 keyword_tag::fsm_input_maker_arg
00123             >
00124           , boost::parameter::required<
00125                 keyword_tag::init_tesselation_selector_arg
00126             >
00127           , boost::parameter::required<
00128                 keyword_tag::init_centroid_arg
00129             >
00130           , boost::parameter::required<
00131                 keyword_tag::init_radius_minimum_arg
00132             >
00133           , boost::parameter::required<
00134                 keyword_tag::init_radius_maximum_arg
00135             >
00136           , boost::parameter::required<
00137                 keyword_tag::init_radial_increment_arg
00138             >
00139           , boost::parameter::required<
00140                 keyword_tag::init_entrance_cell_arg
00141             >
00142           , boost::parameter::required<
00143                 keyword_tag::init_exit_cell_arg
00144             >
00145           , boost::parameter::optional<
00146                 keyword_tag::maze_policy_arg
00147             >
00148           , boost::parameter::optional<
00149                 keyword_tag::init_positive_rotation_arg
00150             >
00151           , boost::parameter::optional<
00152                 keyword_tag::init_zero_tolerance_arg
00153             >
00154         >
00155     {
00156     };
00157   }  // namespace _sphere_builder
00158 
00160 
00264 template <
00265 #ifndef MSMAZES_DOX
00266     typename CoordinateType = double
00267   , typename DirectionChangeType = int
00268   , typename CellContainerSelector = boost::vecS
00269 #endif  /* MSMAZES_DOX */
00270 >
00271 class SphereFSMBuilder
00272 #ifndef MSMAZES_DOX
00273   : public FSMBuilder<
00274                SpherePattern<
00275                    CoordinateType
00276                  , DirectionChangeType
00277                  , CellContainerSelector
00278                >
00279              , _sphere_builder::ArgumentValidationPolicy<CoordinateType>
00280            >
00281 #endif  /* MSMAZES_DOX */
00282 {
00283 #ifndef MSMAZES_DOX
00284  private:
00285     typedef FSMBuilder<
00286                 SpherePattern<
00287                     CoordinateType
00288                   , DirectionChangeType
00289                   , CellContainerSelector
00290                 >
00291               , _sphere_builder::ArgumentValidationPolicy<CoordinateType>
00292             >
00293             ParentBuilder;
00294 #endif  /* MSMAZES_DOX */
00295 
00296  public:
00302 #ifdef MSMAZES_DOX
00303     typedef implementation_defined StateIndex;
00304 #else
00305     typedef typename ParentBuilder::StateIndex
00306             StateIndex;
00307 #endif  /* MSMAZES_DOX */
00308 
00314 #ifdef MSMAZES_DOX
00315     typedef implementation_defined InputIndex;
00316 #else
00317     typedef typename ParentBuilder::InputIndex
00318             InputIndex;
00319 #endif  /* MSMAZES_DOX */
00320 
00326 #ifdef MSMAZES_DOX
00327     typedef implementation_defined MazeGraph;
00328 #else
00329     typedef typename ParentBuilder::MazeGraph
00330             MazeGraph;
00331 #endif  /* MSMAZES_DOX */
00332 
00338 #ifdef MSMAZES_DOX
00339     typedef implementation_defined Pattern;
00340 #else
00341     typedef typename ParentBuilder::Pattern
00342             Pattern;
00343 #endif  /* MSMAZES_DOX */
00344 
00350 #ifdef MSMAZES_DOX
00351     typedef implementation_defined Cell;
00352 #else
00353     typedef typename ParentBuilder::Cell
00354             Cell;
00355 #endif  /* MSMAZES_DOX */
00356 
00363 #ifdef MSMAZES_DOX
00364     typedef implementation_defined Direction;
00365 #else
00366     typedef typename ParentBuilder::Direction
00367             Direction;
00368 #endif  /* MSMAZES_DOX */
00369 
00376 #ifdef MSMAZES_DOX
00377     typedef implementation_defined ArgumentValidationPolicy;
00378 #else
00379     typedef typename ParentBuilder::ArgumentValidationPolicy
00380             ArgumentValidationPolicy;
00381 #endif  /* MSMAZES_DOX */
00382 
00383  private:
00384     SphereFSMBuilder(const SphereFSMBuilder& copy)
00385     {
00386     }
00387 
00388  public:
00390 
00394     SphereFSMBuilder()
00395       : ParentBuilder()
00396     {
00397     }
00398 
00400 
00403     virtual ~SphereFSMBuilder()
00404     {
00405     }
00406 
00407 #ifdef MSMAZES_DOX
00408 
00555     template <
00556         typename RNGEngine
00557       , typename MazeMaker
00558       , typename FSMInputMaker
00559       , typename TesselationSelector
00560       , typename MazePolicy
00561     >
00562     bool initialize(
00563         RNGEngine& rng_engine_arg
00564       , const MazeMaker& maze_maker_arg
00565       , const FSMInputMaker& fsm_input_maker_arg
00566       , const TesselationSelector& init_tesselation_selector_arg
00567       , const Cell& init_centroid_arg
00568       , const typename Pattern::Coordinate init_radial_increment_arg
00569       , const typename Pattern::Coordinate init_radius_maximum_arg
00570       , const typename Pattern::Coordinate init_radius_minimum_arg
00571       , const Cell& init_entrance_cell_arg
00572       , const Cell& init_exit_cell_arg
00573       , const MazePolicy& maze_policy_arg
00574       , const sgdk::PositiveRotation& init_positive_rotation_arg
00575       , const typename Pattern::Coordinate init_zero_tolerance_arg
00576     );
00577 
00584     template <typename Params>
00585     bool initialize_with_named_params(Params& p)
00586 #else
00587     BOOST_PARAMETER_MEMFUN(
00588         bool
00589       , initialize
00590       , 9
00591       , MSMAZES_CORE_FSM_ARITY
00592       , _sphere_builder::parameters
00593     )
00594 #endif  /* MSMAZES_DOX */
00595     {
00596         typedef typename boost::remove_const<
00597                     typename boost::remove_reference<
00598                         typename boost::parameter::binding<
00599                             Params
00600                           , keyword_tag::rng_engine_arg
00601                         >::type
00602                     >::type
00603                 >::type
00604                 RNGEngine;
00605         typedef typename boost::remove_const<
00606                     typename boost::remove_reference<
00607                         typename boost::parameter::binding<
00608                             Params
00609                           , keyword_tag::maze_maker_arg
00610                         >::type
00611                     >::type
00612                 >::type
00613                 MazeMaker;
00614 
00615         RNGEngine& rng_engine = p[rng_engine_arg];
00616 
00617         return
00618             ParentBuilder::initialize(
00619                 rng_engine
00620               , p[maze_maker_arg]
00621               , p[fsm_input_maker_arg]
00622               , p[
00623                     maze_policy_arg
00624                   | typename MazeMakerTraits<MazeMaker>::DefaultPolicy()
00625                 ]
00626               , (
00627                     init_tesselation_selector_arg
00628                       = p[init_tesselation_selector_arg]
00629                   , init_zero_tolerance_arg
00630                       = p[init_zero_tolerance_arg | 0.00001]
00631                   , init_positive_rotation_arg
00632                       = p[
00633                             init_positive_rotation_arg
00634                           | sgdk::PositiveRotation::CLOCKWISE
00635                         ]
00636                   , init_centroid_arg = p[init_centroid_arg]
00637                   , init_radial_increment_arg = p[init_radial_increment_arg]
00638                   , init_radius_minimum_arg = p[init_radius_minimum_arg]
00639                   , init_radius_maximum_arg = p[init_radius_maximum_arg]
00640                   , init_entrance_cell_arg = p[init_entrance_cell_arg]
00641                   , init_exit_cell_arg = p[init_exit_cell_arg]
00642                 )
00643             );
00644     }
00645 
00651     inline const Pattern& getPattern() const
00652     {
00653         return ParentBuilder::getPattern();
00654     }
00655 
00661     inline const MazeGraph& getMazeGraph() const
00662     {
00663         return ParentBuilder::getMazeGraph();
00664     }
00665 
00671     inline bool isReady() const
00672     {
00673         return ParentBuilder::isReady();
00674     }
00675 
00682     template <typename TransitionFunction>
00683     void
00684         buildTransitionFunction(
00685             TransitionFunction& transition_function
00686         ) const
00687     {
00688         ParentBuilder::buildTransitionFunction(transition_function);
00689     }
00690 
00696     inline StateIndex getSourceState() const
00697     {
00698         return ParentBuilder::getSourceState();
00699     }
00700 
00706     inline StateIndex getTargetState() const
00707     {
00708         return ParentBuilder::getTargetState();
00709     }
00710 
00717     bool hasSolutionFromState(const StateIndex source_state) const
00718     {
00719         return ParentBuilder::hasSolutionFromState(source_state);
00720     }
00721 
00727     InputIndex getCorrectInput(const StateIndex source_state) const
00728     {
00729         return ParentBuilder::getCorrectInput(source_state);
00730     }
00731 
00737     const Cell& getStateCell(const StateIndex state) const
00738     {
00739         return ParentBuilder::getStateCell(state);
00740     }
00741 
00748     Direction getStateDirection(const StateIndex state) const
00749     {
00750         return ParentBuilder::getStateDirection(state);
00751     }
00752 };
00753 }  // namespace msmazes
00754 
00755 #undef MSMAZES_CORE_FSM_ARITY
00756 
00757 #endif  /* MSMAZES_CORE_FSM_BUILDER_SPHERE_HPP */

Multi-State Mazes in C++ is hosted by SourceForge.net. Use the Table of Contents for navigation.