-
Notifications
You must be signed in to change notification settings - Fork 0
/
Environment.h
134 lines (98 loc) · 3.42 KB
/
Environment.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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
//
// Created by Marco Matarese on 18/06/2019.
//
#ifndef ROBOT_GOVERNANCE_PROJECT_ENVIRONMENT_H
#define ROBOT_GOVERNANCE_PROJECT_ENVIRONMENT_H
#include "Predicate.h"
#include "Action.h"
#include <set>
class Environment {
private:
int noStates,
noBlocks,
acceptingStateCode;
std::set<Predicate> currState;
public:
Environment(int noBls) {
this->currState = std::set<Predicate>();// empty set of predicate
this->noStates = 1; // at the beginning we know only one world configuration
this->noBlocks = noBls;
this->acceptingStateCode = -1; // we set it when the final state will be encountered
this->initCurrState();
}
~Environment() {
this->currState.clear();
}
/* ---------------------------------------------------------------- */
/* -------------------------GETTER-SETTER-------------------------- */
/* ---------------------------------------------------------------- */
inline int getNoStates() {
return this->noStates;
}
inline void setNoStates(int n) {
this->noStates = n;
}
inline int getAcceptingStateCode() {
return this->acceptingStateCode;
}
inline void setAcceptingStateCode(int code) {
this->acceptingStateCode = code;
}
inline std::set<Predicate> getCurrState() {
return this->currState;
}
inline int getNoBlocks() {
return this->noBlocks;
}
/* ---------------------------------------------------------------- */
/* ----------------------------METHODS----------------------------- */
/* ---------------------------------------------------------------- */
inline void addPredicateToCurrState(Predicate p) {
std::set<Predicate>::iterator it = this->currState.begin();
it = this->currState.insert(it, p);
}
inline void delPredicateToCurrState(Predicate p) {
this->currState.erase(p);
}
/**
* Initialize this->currState to the initial configuration: all blocks on the table and the hand empty.
*/
void initCurrState();
/**
* Check if this->currState is a final configuration. The check is based on the number of predicates in
* this->currState and their type.
* @return false if there are a wrong number of predicates or there is much more than one block clear or
* there is much more than one block on table; true otherwise.
*/
bool isCurrStateAFinalState();
/**
*
* @return
*/
bool isCurrStateTheAcceptingState();
/**
*
* @param pred
*/
void addToCurrState(Predicate pred);
/**
*
* @param pred
*/
void removeToCurrState(Predicate pred);
/**
* Search in this->currState 'predName', but I have only partial info.
* @param predName predicate's name
* @param argIndx predName.args[argIndx] = arg
* @param arg arguments I have
* @return (the first occurrence of) the predicate I'm searching for, an empty predicate if it do not exists
*/
Predicate findPredWithPartialInfoInCurrState(std::string predName, int argIndx, int arg);
/**
*
* @param action
* @return
*/
bool currStateSatisfyPrecondsOf(Action action);
};
#endif //ROBOT_GOVERNANCE_PROJECT_ENVIRONMENT_H