1 #ifndef GRAPHSEARCH_HPP_INCLUDED
2 #define GRAPHSEARCH_HPP_INCLUDED
15 template <
class StateType,
class ActionType>
31 double c2 = _problem->getPathCost(&p2);
43 template <
class StateType,
class ActionType>
46 set<StateType> expanded;
47 stack< Path<StateType, ActionType> > frontier;
55 while(!frontier.empty())
60 if( expanded.find(path.
getLastState()) == expanded.end() )
71 for(
typename list<ActionType>::iterator it = legalActions.begin(); it != legalActions.end(); it++)
73 ActionType action = (*it);
74 StateType result = problem.
getResult(last, action);
79 frontier.push(newPath);
84 cout << __func__ <<
" Error: Could not find a solution." << endl;
90 template <
class StateType,
class ActionType>
93 set<StateType> expanded;
94 queue< Path<StateType, ActionType> > frontier;
102 while(!frontier.empty())
107 if( expanded.find(path.
getLastState()) == expanded.end() )
119 for(
typename list<ActionType>::iterator it = legalActions.begin(); it != legalActions.end(); it++)
121 ActionType action = (*it);
122 StateType result = problem.
getResult(last, action);
127 frontier.push(newPath);
132 cout << __func__ <<
" Error: Could not find a solution." << endl;
138 template <
class StateType,
class ActionType>
142 set<StateType> expanded;
151 while(!frontier.empty())
156 if( expanded.find(path.
getLastState()) == expanded.end() )
159 expanded.insert(last);
165 list<ActionType> legalActions = problem.
getActions(last);
167 for(
typename list<ActionType>::iterator it = legalActions.begin(); it != legalActions.end(); it++)
169 ActionType action = (*it);
170 StateType result = problem.
getResult(last, action);
174 frontier.push(newPath);
179 cout << __func__ <<
" Error: Could not find a solution." << endl;
185 #endif // GRAPHSEARCH_HPP_INCLUDED
static Path< StateType, ActionType > BFS(SearchProblem< StateType, ActionType > &problem)
void addAction(ActionType action)
void newPath(const action_pathConstPtr &msg)
virtual StateType getStartState()=0
virtual bool isGoal(StateType tate)=0
static Path< StateType, ActionType > AStar(SearchProblem< StateType, ActionType > &problem)
virtual StateType getResult(StateType state, ActionType action)=0
SearchProblem< StateType, ActionType > * _problem
void addState(StateType state)
static Path< StateType, ActionType > DFS(SearchProblem< StateType, ActionType > &problem)
virtual std::list< ActionType > getActions(StateType state)=0
double getPathCost(Path< StateType, ActionType > *path)
PathComparator(SearchProblem< StateType, ActionType > *problem)