Main MRPT website > C++ reference for MRPT 1.9.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-2018, 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 "math-precomp.h" // Precompiled headers
11 
12 #include <mrpt/math/model_search.h>
14 
15 using namespace mrpt;
16 using namespace mrpt::math;
17 
18 
19 //----------------------------------------------------------------------
20 //! Select random (unique) indices from the 0..p_size sequence
22  size_t p_size, size_t p_pick, std::vector<size_t>& p_ind)
23 {
24  ASSERT_(p_size >= p_pick);
25 
26  std::vector<size_t> a(p_size);
27  for (size_t i = 0; i < p_size; i++) a[i] = i;
28 
29  mrpt::random::shuffle(a.begin(), a.end());
30  p_ind.resize(p_pick);
31  for (size_t i = 0; i < p_pick; i++) p_ind[i] = a[i];
32 }
33 
34 //----------------------------------------------------------------------
35 //! Select random (unique) indices from the set.
36 //! The set is destroyed during pick
38  std::set<size_t> p_set, size_t p_pick, std::vector<size_t>& p_ind)
39 {
40  p_ind.resize(p_pick);
41  std::vector<size_t> inds(p_set.begin(), p_set.end());
42 
43  mrpt::random::shuffle(inds.begin(), inds.end());
44  p_ind.resize(p_pick);
45  for (size_t i = 0; i < p_pick; i++) p_ind[i] = inds[i];
46 }
mrpt::math::ModelSearch::pickRandomIndex
void pickRandomIndex(size_t p_size, size_t p_pick, std::vector< size_t > &p_ind)
Select random (unique) indices from the 0..p_size sequence.
Definition: model_search.cpp:21
model_search.h
math-precomp.h
mrpt
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
Definition: CKalmanFilterCapable.h:30
ASSERT_
#define ASSERT_(f)
Defines an assertion mechanism.
Definition: exceptions.h:113
random_shuffle.h
mrpt::random::shuffle
void shuffle(RandomIt first, RandomIt last, URBG &&g)
Uniform shuffle a sequence.
Definition: random_shuffle.h:23
mrpt::math
This base provides a set of functions for maths stuff.
Definition: math/include/mrpt/math/bits_math.h:13
a
GLubyte GLubyte GLubyte a
Definition: glext.h:6279



Page generated by Doxygen 1.8.17 for MRPT 1.9.9 Git: ad3a9d8ae Tue May 1 23:10:22 2018 -0700 at miƩ 12 jul 2023 10:03:34 CEST