00001
00002
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
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
00209
00210
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