formation_knn.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_KNN_H
00033 #define RCSC_FORMATION_FORMATION_KNN_H
00034 
00035 #include <iostream>
00036 #include <map>
00037 
00038 #include <rcsc/geom/vector_2d.h>
00039 #include <rcsc/formation/formation.h>
00040 
00041 namespace rcsc {
00042 
00047 class FormationKNN
00048     : public Formation {
00049 public:
00050 
00055     struct Data {
00056         Vector2D ball_; 
00057         std::vector< Vector2D > players_; 
00058 
00062         Data();
00063 
00067         Data( const Snapshot & snapshot );
00068 
00074         Data( const Vector2D & ball,
00075               const std::vector< Vector2D > & players );
00082         const
00083         Data & assign( const Vector2D & ball,
00084                        const std::vector< Vector2D > & players );
00085 
00091         Vector2D getPosition( const int unum ) const;
00092 
00093     };
00094 
00095 
00096 private:
00097 
00099     size_t M_k;
00100 
00102     std::string M_role_name[11];
00103 
00105     std::vector< Data > M_data;
00106 
00108     mutable std::vector< Data * > M_data_ptr;
00109 
00110 public:
00114     FormationKNN();
00115 
00120     static
00121     std::string name()
00122       {
00123           return std::string( "k-NN" );
00124       }
00125 
00130     static
00131     Formation * create()
00132       {
00133           return ( new FormationKNN );
00134       }
00135 
00136     //--------------------------------------------------------------
00137 
00142     virtual
00143     std::string methodName() const
00144       {
00145           return FormationKNN::name();
00146       }
00147 
00152     virtual
00153     Snapshot createDefaultParam();
00154 
00159     const
00160     std::vector< Data > & data() const
00161       {
00162           return M_data;
00163       }
00164 
00165 protected:
00166 
00173     virtual
00174     void createNewRole( const int unum,
00175                         const std::string & role_name,
00176                         const SideType type );
00177 
00183     virtual
00184     void setRoleName( const int unum,
00185                       const std::string & name );
00186 
00187 public:
00188 
00195     virtual
00196     std::string getRoleName( const int unum ) const;
00197 
00203     virtual
00204     Vector2D getPosition( const int unum,
00205                           const Vector2D & focus_point ) const;
00206 
00207     /*
00208       \brief get all positions for the current focus point
00209       \param focus_point current focus point, usually ball position
00210       \param positions contaner to store the result
00211      */
00212     virtual
00213     void getPositions( const Vector2D & focus_point,
00214                        std::vector< Vector2D > & positions ) const;
00215 
00220     virtual
00221     void train( const std::list< Snapshot > & train_data );
00222 
00228     virtual
00229     bool read( std::istream & is );
00230 
00236     virtual
00237     std::ostream & print( std::ostream & os ) const;
00238 
00239 private:
00240 
00241 
00247     bool readPlayers( std::istream & is );
00248 
00254     bool readRoles( std::istream & is );
00255 
00261     bool readSamples( std::istream & is );
00262 
00263 };
00264 
00265 }
00266 
00267 #endif

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