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 }
void shuffle(RandomIt first, RandomIt last, URBG &&g)
Uniform shuffle a sequence.
#define ASSERT_(f)
Defines an assertion mechanism.
Definition: exceptions.h:113
This base provides a set of functions for maths stuff.
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.
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
GLubyte GLubyte GLubyte a
Definition: glext.h:6279



Page generated by Doxygen 1.8.14 for MRPT 1.9.9 Git: 7d5e6d718 Fri Aug 24 01:51:28 2018 +0200 at lun nov 2 08:35:50 CET 2020