formation_bpn.h

説明を見る。
00001 // -*-c++-*-
00002 
00008 /*
00009  *Copyright:
00010 
00011  Copyright (C) Hidehisa AKIYAMA
00012 
00013  This code is free software; you can redistribute it and/or
00014  modify it under the terms of the GNU Lesser General Public
00015  License as published by the Free Software Foundation; either
00016  version 2.1 of the License, or (at your option) any later version.
00017 
00018  This library is distributed in the hope that it will be useful,
00019  but WITHOUT ANY WARRANTY; without even the implied warranty of
00020  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00021  Lesser General Public License for more details.
00022 
00023  You should have received a copy of the GNU Lesser General Public
00024  License along with this library; if not, write to the Free Software
00025  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00026 
00027  *EndCopyright:
00028  */
00029 
00031 
00032 #ifndef RCSC_FORMATION_FORMATION_BPN_H
00033 #define RCSC_FORMATION_FORMATION_BPN_H
00034 
00035 #include <rcsc/formation/formation.h>
00036 #include <rcsc/ann/bpn1.h>
00037 
00038 #include <boost/shared_ptr.hpp>
00039 
00040 #include <map>
00041 
00042 namespace rcsc {
00043 
00048 class FormationBPN
00049     : public Formation {
00050 public:
00051 
00056     class Param {
00057     public:
00058         static const double PITCH_LENGTH;
00059         static const double PITCH_WIDTH;
00060 
00061         //typedef BPNetwork1< 2, 4, 2 > PosNet;  // bad
00062         //typedef BPNetwork1< 2, 5, 2 > PosNet;  // not bad
00063         //typedef BPNetwork1< 2, 6, 2 > PosNet;   // not bad
00064         //typedef BPNetwork1< 2, 7, 2 > PosNet;   // good?
00065         //typedef BPNetwork1< 2, 8, 2 > PosNet;   // good?
00066         typedef BPNetwork1< 2, 10, 2 > PosNet; // good
00067         //typedef BPNetwork1< 2, 12, 2 > PosNet;   // good
00068     private:
00069 
00070         std::string M_role_name;
00071 
00072         PosNet M_param;
00073 
00074     public:
00075 
00079         Param();
00080 
00084         void randomize();
00085 
00090         const
00091         std::string & roleName() const
00092           {
00093               return M_role_name;
00094           }
00095 
00100         PosNet & getParam()
00101           {
00102               return M_param;
00103           }
00104 
00109         const
00110         PosNet & param() const
00111           {
00112               return M_param;
00113           }
00114 
00121         Vector2D getPosition( const Vector2D & ball_pos,
00122                               const Formation::SideType type ) const;
00123 
00128         void setRoleName( const std::string & name )
00129           {
00130               M_role_name = name;
00131           }
00132 
00138         bool read( std::istream & is );
00139 
00145         std::ostream & print( std::ostream & os ) const;
00146 
00147     private:
00153         bool readRoleName( std::istream & is );
00154 
00160         bool readParam( std::istream & is );
00161 
00167         std::ostream & printRoleName( std::ostream & os ) const;
00168 
00174         std::ostream & printParam( std::ostream & os ) const;
00175 
00176     };
00177 
00178 
00179 private:
00180 
00182     std::map< int, boost::shared_ptr< Param > > M_param_map;
00183 
00184 public:
00185 
00189     FormationBPN();
00190 
00191 
00196     static
00197     std::string name()
00198       {
00199           return std::string( "BPN" );
00200       }
00201 
00206     static
00207     Formation * create()
00208       {
00209           return ( new FormationBPN );
00210       }
00211 
00212     //--------------------------------------------------------------
00213 
00218     virtual
00219     std::string methodName() const
00220       {
00221           return FormationBPN::name();
00222       }
00223 
00228     virtual
00229     Snapshot createDefaultParam();
00230 
00231 protected:
00232 
00239     virtual
00240     void createNewRole( const int unum,
00241                         const std::string & role_name,
00242                         const SideType type );
00243 
00249     virtual
00250     void setRoleName( const int unum,
00251                       const std::string & name );
00252 
00253 public:
00254 
00261     virtual
00262     std::string getRoleName( const int unum ) const;
00263 
00269     virtual
00270     Vector2D getPosition( const int unum,
00271                           const Vector2D & focus_point ) const;
00272 
00273     /*
00274       \brief get all positions for the current focus point
00275       \param focus_point current focus point, usually ball position
00276       \param positions contaner to store the result
00277      */
00278     virtual
00279     void getPositions( const Vector2D & focus_point,
00280                        std::vector< Vector2D > & positions ) const;
00281 
00286     virtual
00287     void train( const std::list< Snapshot > & train_data );
00288 
00294     bool read( std::istream & is );
00295 
00301     std::ostream & print( std::ostream & os ) const;
00302 
00303 
00304 private:
00305 
00311     bool readPlayers( std::istream & is );
00312 
00318     boost::shared_ptr< Param > getParam( const int unum );
00319 
00325     boost::shared_ptr< const Param > param( const int unum ) const;
00326 
00327 };
00328 
00329 }
00330 
00331 #endif

librcscに対してThu May 1 15:41:20 2008に生成されました。  doxygen 1.5.0