sample_simple_graph.cpp
Go to the documentation of this file.
1 // -*- mode: c++ -*-
2 /*********************************************************************
3  * Software License Agreement (BSD License)
4  *
5  * Copyright (c) 2015, JSK Lab
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  *
12  * * Redistributions of source code must retain the above copyright
13  * notice, this list of conditions and the following disclaimer.
14  * * Redistributions in binary form must reproduce the above
15  * copyright notice, this list of conditions and the following
16  * disclaimer in the documentation and/o2r other materials provided
17  * with the distribution.
18  * * Neither the name of the JSK Lab nor the names of its
19  * contributors may be used to endorse or promote products derived
20  * from this software without specific prior written permission.
21  *
22  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
25  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
26  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
27  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
28  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
29  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
30  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
32  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33  * POSSIBILITY OF SUCH DAMAGE.
34  *********************************************************************/
35 #include <ros/ros.h>
36 
42 #include <iostream>
43 #include <boost/format.hpp>
44 #include <jsk_topic_tools/time_accumulator.h>
45 
46 using namespace jsk_footstep_planner;
47 
48 int main(int argc, char** argv)
49 {
50  ros::init(argc, argv, "sample_simple_graph");
51  std::cout << "usage: rosrun jsk_footstep_planner sample_astar config/map.txt" << std::endl;
53 
54  // node name: depth_num
55  const int width = 10;
56  const int depth = 1000;
57  for (size_t d = 0; d < depth; d++) {
58  for (size_t w = 0; w < width; w++) {
59  SimpleNeighboredNode::Ptr a(new SimpleNeighboredNode((boost::format("%lu_%lu") % d % w).str()));
60  graph->addNode(a);
61  if (w != 0) {
62  graph->findNode((boost::format("%lu_%lu") % d % (w - 1)).str())->addNeighbor(graph->findNode((boost::format("%lu_%lu") % d % w).str()));
63  graph->findNode((boost::format("%lu_%lu") % d % w).str())->addNeighbor(graph->findNode((boost::format("%lu_%lu") % d % (w - 1)).str()));
64  }
65  if (d != 0) {
66  graph->findNode((boost::format("%lu_%lu") % (d - 1) % w).str())->addNeighbor(graph->findNode((boost::format("%lu_%lu") % d % w).str()));
67  }
68  }
69  }
70 
71  std::cout << "done building graph" << std::endl;
72  graph->setStartState(graph->findNode("0_0"));
73  graph->setGoalState(graph->findNode((boost::format("%lu_%lu") % (depth - 1) % (width - 1)).str()));
74  const int trials = 10;
75  {
76  jsk_topic_tools::TimeAccumulator acc;
77  for (size_t i = 0; i < trials; i++) {
78  jsk_topic_tools::ScopedTimer timer = acc.scopedTimer();
80  std::vector<SolverNode<SimpleNeighboredNode, SimpleNeighboredGraph>::Ptr> path = solver->solve();
81  std::cout << "path: " << path.size() << std::endl;
82  //std::cout << i << "/" << trials << std::endl;
83  }
84  std::cout << "braedth first time to solve:" << acc.mean() << std::endl;
85  }
86 
87  {
88  jsk_topic_tools::TimeAccumulator acc;
89  for (size_t i = 0; i < trials; i++) {
90  jsk_topic_tools::ScopedTimer timer = acc.scopedTimer();
92  std::vector<SolverNode<SimpleNeighboredNode, SimpleNeighboredGraph>::Ptr> path = solver->solve();
93  std::cout << "path: " << path.size() << std::endl;
94  //std::cout << i << "/" << trials << std::endl;
95  }
96  std::cout << "depth first time to solve:" << acc.mean() << std::endl;
97  }
98 
99  {
100  jsk_topic_tools::TimeAccumulator acc;
101  for (size_t i = 0; i < trials; i++) {
102  jsk_topic_tools::ScopedTimer timer = acc.scopedTimer();
104  std::vector<SolverNode<SimpleNeighboredNode, SimpleNeighboredGraph>::Ptr> path = solver->solve();
105  std::cout << "path: " << path.size() << std::endl;
106  //std::cout << i << "/" << trials << std::endl;
107  }
108  std::cout << "best first time to solve:" << acc.mean() << std::endl;
109  }
110 
112  std::vector<SolverNode<SimpleNeighboredNode, SimpleNeighboredGraph>::Ptr> path = solver->solve();
113  std::cout << "number of nodes: " << graph->numNodes() << std::endl;
114  std::cout << "start node: " << graph->getStartState()->getName() << std::endl;
115  std::cout << "goal node: " << graph->getGoalState()->getName() << std::endl;
116  std::cout << "path: " << path.size() << std::endl;
117  for (size_t i = 0; i < path.size(); i++) {
118  std::cout << " " << i << " - " << path[i]->getState()->getName() << std::endl;
119  }
120  return 0;
121 }
jsk_footstep_planner::BreadthFirstSearchSolver
Definition: breadth_first_search_solver.h:78
astar_solver.h
boost::shared_ptr
i
int i
w
w
ros::init
ROSCPP_DECL void init(const M_string &remappings, const std::string &name, uint32_t options=0)
ros.h
jsk_footstep_planner::DepthFirstSearchSolver
Definition: depth_first_search_solver.h:78
jsk_footstep_planner::SimpleNeighboredNode
Definition: simple_neighbored_graph.h:77
jsk_footstep_planner::SimpleNeighboredGraph
Definition: simple_neighbored_graph.h:112
str
string str
depth_first_search_solver.h
jsk_footstep_planner
Definition: ann_grid.h:50
best_first_search_solver.h
argv
ROS_INFO ROS_ERROR int pointer * argv
graph
FootstepGraph::Ptr graph
Definition: footstep_planning_2d_interactive_demo.cpp:51
d
d
breadth_first_search_solver.h
main
int main(int argc, char **argv)
Definition: sample_simple_graph.cpp:48
simple_neighbored_graph.h
jsk_footstep_planner::BestFirstSearchSolver
Definition: best_first_search_solver.h:78
width
width
a
char a[26]


jsk_footstep_planner
Author(s): Ryohei Ueda
autogenerated on Wed Jan 24 2024 04:05:30