MRPT  1.9.9
model_search.cpp
Go to the documentation of this file.
1 /* +------------------------------------------------------------------------+
2  | Mobile Robot Programming Toolkit (MRPT) |
3  | https://www.mrpt.org/ |
4  | |
5  | Copyright (c) 2005-2020, Individual contributors, see AUTHORS file |
6  | See: https://www.mrpt.org/Authors - All rights reserved. |
7  | Released under BSD License. See: https://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 //! Select random (unique) indices from the 0..p_size sequence
21  size_t p_size, size_t p_pick, std::vector<size_t>& p_ind)
22 {
23  ASSERT_(p_size >= p_pick);
24 
25  std::vector<size_t> a(p_size);
26  for (size_t i = 0; i < p_size; i++) a[i] = i;
27 
28  mrpt::random::shuffle(a.begin(), a.end());
29  p_ind.resize(p_pick);
30  for (size_t i = 0; i < p_pick; i++) p_ind[i] = a[i];
31 }
32 
33 //----------------------------------------------------------------------
34 //! Select random (unique) indices from the set.
35 //! The set is destroyed during pick
37  std::set<size_t> p_set, size_t p_pick, std::vector<size_t>& p_ind)
38 {
39  p_ind.resize(p_pick);
40  std::vector<size_t> inds(p_set.begin(), p_set.end());
41 
42  mrpt::random::shuffle(inds.begin(), inds.end());
43  p_ind.resize(p_pick);
44  for (size_t i = 0; i < p_pick; i++) p_ind[i] = inds[i];
45 }
void shuffle(RandomIt first, RandomIt last, URBG &&g)
Uniform shuffle a sequence.
#define ASSERT_(f)
Defines an assertion mechanism.
Definition: exceptions.h:120
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.



Page generated by Doxygen 1.8.14 for MRPT 1.9.9 Git: c7a3bec24 Sun Mar 29 18:33:13 2020 +0200 at dom mar 29 18:50:38 CEST 2020