39 #include <boost/format.hpp>
40 #include <jsk_topic_tools/time_accumulator.h>
49 Grid2DNode(
int x,
int y,
bool occupied): x_(
x), y_(
y), occupied_(occupied) {}
52 return x_ == other.
x_ && y_ == other.
y_ ;
72 std::vector<Grid2DGraph::StatePtr> ret;
73 if (target_state->getX() - 1 > 0) {
74 if (state_map_[target_state->getX() - 1][target_state->getY()] &&
75 !state_map_[target_state->getX() - 1][target_state->getY()]->isOccupied()) {
76 ret.push_back(state_map_[target_state->getX() - 1][target_state->getY()]);
79 if (target_state->getX() + 1 < 1024) {
80 if (state_map_[target_state->getX() + 1][target_state->getY()] &&
81 !state_map_[target_state->getX() + 1][target_state->getY()]->isOccupied()) {
82 ret.push_back(state_map_[target_state->getX() + 1][target_state->getY()]);
85 if (target_state->getY() - 1 > 0) {
86 if (state_map_[target_state->getX()][target_state->getY() - 1] &&
87 !state_map_[target_state->getX()][target_state->getY() - 1]->isOccupied()) {
88 ret.push_back(state_map_[target_state->getX()][target_state->getY() - 1]);
91 if (target_state->getY() + 1 < 1024) {
92 if (state_map_[target_state->getX()][target_state->getY() + 1] &&
93 !state_map_[target_state->getX()][target_state->getY() + 1]->isOccupied()) {
94 ret.push_back(state_map_[target_state->getX()][target_state->getY() + 1]);
102 return prev_cost + 1;
107 return goal_state_ ==
state;
118 return state_map_[
x][
y];
132 int main(
int argc,
char** argv)
137 std::string map_file =
argv[1];
138 std::ifstream map_stream(map_file.c_str());
141 while (std::getline(map_stream,
input)) {
142 for (
size_t i = 0;
i <
input.length();
i++) {
145 graph->addNode(node);
152 jsk_topic_tools::TimeAccumulator acc;
153 const size_t trials = 1000;
154 for (
size_t i = 0;
i < trials;
i++) {
155 jsk_topic_tools::ScopedTimer timer = acc.scopedTimer();
158 std::vector<SolverNode<Grid2DNode, Grid2DGraph>::Ptr> path
161 std::cout <<
"A* time to solve:" << acc.mean() << std::endl;
165 std::vector<SolverNode<Grid2DNode, Grid2DGraph>::Ptr> path
168 std::set<Grid2DNode::Ptr> path_states;
169 for (
size_t i = 0;
i < path.size();
i++) {
170 path_states.insert(path[
i]->getState());
173 for (
size_t j = 0; j < 1024; j++) {
174 bool is_valid_line =
false;
175 for (
size_t i = 0;
i < 1024;
i++) {
178 if (node->isOccupied()) {
181 else if (*(
graph->getStartState()) == *node) {
184 else if (*(
graph->getGoalState()) == *node) {
187 else if (path_states.find(node) != path_states.end()) {
193 is_valid_line =
true;
197 std::cout << std::endl;