batching_pomp  1.0
This is an implementation of an algorithmic framework for anytime motion planning on large dense roadmaps.
BisectPerm.hpp
1 /***********************************************************************
2 Copyright (c) 2015, Carnegie Mellon University
3 All rights reserved.
4 Authors: Chris Dellin <cdellin@gmail.com>
5 
6 Redistribution and use in source and binary forms, with or without
7 modification, are permitted provided that the following conditions are
8 met:
9  Redistributions of source code must retain the above copyright
10  notice, this list of conditions and the following disclaimer.
11  Redistributions in binary form must reproduce the above copyright
12  notice, this list of conditions and the following disclaimer in the
13  documentation and/or other materials provided with the distribution.
14 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
15 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
16 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
17 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
18 HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
19 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
20 LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
24 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 *************************************************************************/
26 
27 #ifndef BATCHING_POMP_UTIL_BISECTPERM_HPP_
28 #define BATCHING_POMP_UTIL_BISECTPERM_HPP_
29 
30 namespace batching_pomp {
31 namespace util {
32 
34 
36 {
37 public:
38  BisectPerm() {}
39 
45  const std::vector< std::pair<int,int> > & get(int n)
46  {
47  std::map<int, const std::vector< std::pair<int,int> > >::iterator it;
48  it = cache.find(n);
49  if (it != cache.end())
50  return it->second;
51 
52  int i;
53  int last_true;
54  int max_i;
55  int max_val;
56  std::vector< std::pair<int,int> > perm;
57  std::vector<bool> done(n, false);
58  std::vector<int> dist(n);
59 
60  for (;;)
61  {
62  last_true = -1;
63  for (i=0; i<n; i++)
64  {
65  if (done[i]) last_true = i;
66  dist[i] = (i-last_true);
67  }
68  last_true = n;
69  for (i=n-1; i>=0; i--)
70  {
71  if (done[i]) last_true = i;
72  dist[i] = (last_true-i) < dist[i] ? (last_true-i) : dist[i];
73  }
74  max_val = 0;
75  max_i = 0;
76  for (i=0; i<n; i++) if (max_val < dist[i])
77  {
78  max_val = dist[i];
79  max_i = i;
80  }
81  if (!max_val)
82  break;
83  perm.push_back(std::make_pair(max_i,max_val));
84  done[max_i] = true;
85  }
86 
87  cache.insert(std::make_pair(n,perm));
88  return cache[n];
89  }
90 
91 private:
92 
93  std::map<int, const std::vector< std::pair<int,int> > > cache;
94 };
95 
96 } // namespace util
97 } // namespace batching_pomp
98 
99 #endif // BATCHING_POMP_UTIL_BISECTPERM_HPP_
Generates a Van Der Corput sequence ordering for states to check along an edge.
Definition: BisectPerm.hpp:35
Definition: BatchingManager.hpp:36