Main MRPT website > C++ reference for MRPT 1.5.9
model_search.cpp
Go to the documentation of this file.
1 /* +---------------------------------------------------------------------------+
2  | Mobile Robot Programming Toolkit (MRPT) |
3  | http://www.mrpt.org/ |
4  | |
5  | Copyright (c) 2005-2017, Individual contributors, see AUTHORS file |
6  | See: http://www.mrpt.org/Authors - All rights reserved. |
7  | Released under BSD License. See details in http://www.mrpt.org/License |
8  +---------------------------------------------------------------------------+ */
9 
10 #include "base-precomp.h" // Precompiled headers
11 
12 #include <mrpt/math/model_search.h>
13 
14 using namespace mrpt;
15 using namespace mrpt::math;
16 
17 //----------------------------------------------------------------------
18 //! Select random (unique) indices from the 0..p_size sequence
19 void ModelSearch::pickRandomIndex( size_t p_size, size_t p_pick, vector_size_t& p_ind )
20 {
21  ASSERT_( p_size >= p_pick );
22 
23  vector_size_t a( p_size );
24  for( size_t i = 0; i < p_size; i++ )
25  a[i] = i;
26 
27  std::random_shuffle( a.begin(), a.end() );
28  p_ind.resize( p_pick );
29  for( size_t i = 0 ; i < p_pick; i++ )
30  p_ind[i] = a[i];
31 }
32 
33 //----------------------------------------------------------------------
34 //! Select random (unique) indices from the set.
35 //! The set is destroyed during pick
36 void ModelSearch::pickRandomIndex( std::set<size_t> p_set, size_t p_pick, vector_size_t& p_ind )
37 {
38  p_ind.resize( p_pick );
39  vector_size_t inds( p_set.begin(), p_set.end() );
40 
41  std::random_shuffle( inds.begin(), inds.end() );
42  p_ind.resize( p_pick );
43  for( size_t i = 0 ; i < p_pick; i++ )
44  p_ind[i] = inds[i];
45 }
46 
This base provides a set of functions for maths stuff.
Definition: CArrayNumeric.h:19
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
void pickRandomIndex(size_t p_size, size_t p_pick, vector_size_t &p_ind)
Select random (unique) indices from the 0..p_size sequence.
#define ASSERT_(f)
std::vector< size_t > vector_size_t
Definition: types_simple.h:25
GLubyte GLubyte GLubyte a
Definition: glext.h:5575



Page generated by Doxygen 1.8.14 for MRPT 1.5.9 Git: 690a4699f Wed Apr 15 19:29:53 2020 +0200 at miƩ abr 15 19:30:12 CEST 2020