31 #include <unordered_map> 34 #include <boost/thread.hpp> 38 #include <gtest/gtest.h> 49 omp_set_num_threads(2);
54 std::vector<std::vector<Vec>> search_;
63 for (
int i = 1; i <= 14; ++i)
65 search_[0].push_back(
Vec(i));
66 for (
int j = 1; j <= 15; ++j)
70 search_[i].push_back(
Vec(j - i));
74 float cost(
const Vec&,
const Vec&,
const std::vector<VecWithCost>&,
const Vec&)
const final 78 float costEstim(
const Vec&
s,
const Vec& e)
const final 82 const std::vector<Vec>& searchGrids(
const Vec& p,
const std::vector<VecWithCost>&,
const Vec&)
const final 87 Model::Ptr model(
new Model());
89 const auto cb_progress = [](
const std::list<Vec>&,
const SearchStats&) ->
bool 94 for (
int i = 0; i < 1000; ++i)
97 std::vector<Model::VecWithCost> starts;
98 starts.emplace_back(
Vec(0));
101 starts,
Vec(15), path,
105 ASSERT_EQ(path.size(), 3u);
106 ASSERT_EQ(path.front(),
Vec(0));
107 ASSERT_EQ(path.back(),
Vec(15));
116 omp_set_num_threads(2);
121 std::vector<std::vector<Vec>> search_;
127 search_[0].push_back(
Vec(1));
128 search_[1].push_back(
Vec(2));
130 float cost(
const Vec&,
const Vec&,
const std::vector<VecWithCost>&,
const Vec&)
const final 134 float costEstim(
const Vec&
s,
const Vec& e)
const final 138 const std::vector<Vec>& searchGrids(
const Vec& p,
const std::vector<VecWithCost>&,
const Vec&)
const final 140 return search_[p[0]];
143 Model::Ptr model(
new Model());
146 const auto cb_progress = [&cnt](
const std::list<Vec>& ,
const SearchStats& stats) ->
bool 151 EXPECT_EQ(1u, stats.num_loop);
152 EXPECT_EQ(1u, stats.num_search_queue);
153 EXPECT_EQ(0u, stats.num_prev_updates);
154 EXPECT_EQ(0u, stats.num_total_updates);
157 EXPECT_EQ(2u, stats.num_loop);
158 EXPECT_EQ(1u, stats.num_search_queue);
159 EXPECT_EQ(1u, stats.num_prev_updates);
160 EXPECT_EQ(1u, stats.num_total_updates);
163 EXPECT_TRUE(
false) <<
"Search was not aborted";
168 std::vector<Model::VecWithCost> starts;
169 starts.emplace_back(
Vec(0));
170 ASSERT_FALSE(as.
search(starts,
Vec(2), path, model, cb_progress, 0, 0.0));
182 std::vector<std::vector<Vec>> search_;
192 for (
int i = 2; i <= 14; ++i)
194 search_[0].push_back(
Vec(i));
195 search_[1].push_back(
Vec(i - 1));
196 for (
int j = 2; j <= 15; ++j)
200 search_[i].push_back(
Vec(j - i));
204 float cost(
const Vec&,
const Vec&,
const std::vector<VecWithCost>&,
const Vec&)
const final 208 float costEstim(
const Vec&
s,
const Vec& e)
const final 212 const std::vector<Vec>& searchGrids(
const Vec& p,
const std::vector<VecWithCost>&,
const Vec&)
const final 214 return search_[p[0]];
217 Model::Ptr model(
new Model());
219 const auto cb_progress = [](
const std::list<Vec>&,
const SearchStats&) ->
bool 224 for (
int add_cost_to = 0; add_cost_to < 2; ++add_cost_to)
226 std::vector<GridAstar<1, 1>::VecWithCost> starts;
227 starts.emplace_back(
Vec(0));
228 starts.emplace_back(
Vec(1));
229 starts[add_cost_to].c_ = 0.1;
234 starts,
Vec(15), path,
238 ASSERT_EQ(path.size(), 3u);
239 ASSERT_EQ(path.back(),
Vec(15));
240 if (add_cost_to == 0)
241 ASSERT_EQ(path.front(),
Vec(1));
243 ASSERT_EQ(path.front(),
Vec(0));
258 bool findPath(
const std::vector<VecWithCost>& ss,
const Vec& e, std::list<Vec>& path)
const 274 const auto timeout_func = []()
278 boost::this_thread::sleep(boost::posix_time::milliseconds(1000));
280 catch (boost::thread_interrupted&)
284 EXPECT_TRUE(
false) <<
"Looks entered endless loop. Test will be aborted.";
287 boost::thread timeout(timeout_func);
288 std::vector<GridAstarTestWrapper::VecWithCost> starts;
289 starts.emplace_back(
Vec(0));
302 std::vector<GridAstarTestWrapper::VecWithCost> starts;
303 starts.emplace_back(
Vec(0));
316 for (
int i = 0; i < 2; ++i)
319 std::vector<GridAstarTestWrapper::VecWithCost> starts;
320 starts.emplace_back(
Vec(0));
322 ASSERT_EQ(path.size(), 3u);
323 auto it = path.cbegin();
324 ASSERT_EQ(*(it++),
Vec(0));
325 ASSERT_EQ(*(it++),
Vec(1));
326 ASSERT_EQ(*it,
Vec(2));
331 int main(
int argc,
char** argv)
333 testing::InitGoogleTest(&argc, argv);
335 return RUN_ALL_TESTS();
TEST(BlockmemGridmap, BlockWidth)
void setSearchTaskNum(const size_t &search_task_num)
bool search(const std::vector< VecWithCost > &ss, const Vec &e, std::list< Vec > &path, const typename GridAstarModelBase< DIM, NONCYCLIC >::Ptr &model, ProgressCallback cb_progress, const float cost_leave, const float progress_interval, const bool return_best=false)
CyclicVecInt< DIM, NONCYCLIC > Vec
GridAstarTestWrapper(const Vec &size)
MotionPrimitiveBuilder::Vec Vec
std::unordered_map< Vec, Vec, Vec > & parentMap()
int main(int argc, char **argv)
bool findPath(const std::vector< VecWithCost > &ss, const Vec &e, std::list< Vec > &path) const
bool findPath(const std::vector< VecWithCost > &ss, const Vec &e, std::list< Vec > &path) const