-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathgeneral_problem_solver.h
85 lines (76 loc) · 2.76 KB
/
general_problem_solver.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#ifndef GPS_H
#define GPS_H
#include <iostream>
#include <vector>
#include <stack>
#include <string>
#include <algorithm>
struct Operator {
std::string action;
std::vector<std::string> preconds;
std::vector<std::string> add;
std::vector<std::string> remove;
};
/**
* Check whether a string starts with "Executing". True, if yes.
*/
class prefixed_state {
public:
bool operator()( std::string s ) {
if (s.find("Executing ") == 0)
{
return true;
}
else {
std::cout << "it's false " + s << '\n';
return false;
}
}
};
/**
* Find a sequence of operators that will achieve all of the goal states.
*
* Returns a list of actions that will achieve all of the goal states, or
* None if no such sequence exists. Each operator is specified by an action name,
* list of preconditions, and add-list, and a delete-list.
*/
std::vector<std::string> gps( std::vector<std::string> init_states,
std::vector<std::string> goal_states,
std::vector<Operator>& operators );
/**
* Achieve each state in goals and make sure they still hold at then end.
*
* The goal stack keeps track of our recursion: which preconditions are we
* trying to satisfy by achieving the specified goals?
*/
std::vector<std::string> achieve_all( std::vector<std::string> states,
std::vector<Operator>& ops,
std::vector<std::string> goals,
std::vector<std::string>& goal_stack );
/**
* Achieve the goal state using means-ends analysis.
*
* Identifies an appropiate and applicable operator --one that contains the goal
* state in its add-list and has all its preconditions satisfied.
* Applies the operator and returns the result. Returns None if no such
* operator is found or infinite recursion is detected in the goal stack.
*/
std::vector<std::string> achieve( std::vector<std::string> states,
std::vector<Operator> operators,
std::string goal,
std::vector<std::string>& goal_stack );
// USING OPERATORS //
/**
* Applies operator and returns the resulting states.
*
* Achieves all of the operator's preconditions and returns the states that hold
* after processing its add-list and delete-list. If any of its preconditions
* cannot be satisfied, returns None.
*
*/
std::vector<std::string> apply_operator( Operator op,
std::vector<std::string> states,
std::vector<Operator> ops,
std::string goal,
std::vector<std::string>& goal_stack );
#endif