Repository navigation
Expand file tree
/
Copy pathuserdefined.cpp
More file actions
212 lines (166 loc) · 3.32 KB
/
Copy pathuserdefined.cpp
File metadata and controls
212 lines (166 loc) · 3.32 KB
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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
#include "state.h"
#include "usefullibs.h"
//#include "Action.h"
bool issorted2(vector<int> &list) {
for (int i = 0; i < list.size()-1; i++) if (list[i] > list[i+1]) return false;
return true;
}
// Below are all user defined actions.
bool NOOPaction(state &curstate)
{
return false;
}
bool NOOPcanAct(state &curstate)
{
return true;
}
int NOOPreward(state &curstate)
{
return 0;
}
bool INCIaction(state &curstate)
{
curstate.data.i++;
if (curstate.data.i > curstate.data.list.size())
curstate.data.i = curstate.data.list.size();
return false;
}
bool INCIcanAct(state &curstate)
{
return curstate.data.i != curstate.data.list.size();
}
int INCIreward(state &curstate)
{
return 0;
}
bool INCJaction(state &curstate)
{
curstate.data.j++;
if (curstate.data.j > curstate.data.list.size())
curstate.data.j = curstate.data.list.size();
return false;
}
bool INCJcanAct(state &curstate)
{
return curstate.data.j != curstate.data.list.size();
}
int INCJreward(state &curstate)
{
return 0;
}
bool INCKaction(state &curstate)
{
curstate.data.k++;
if (curstate.data.k > curstate.data.list.size())
curstate.data.k = curstate.data.list.size();
return false;
}
bool INCKcanAct(state &curstate)
{
return curstate.data.k != curstate.data.list.size();
}
int INCKreward(state &curstate)
{
return 0;
}
bool SETIZEROaction(state &curstate)
{
curstate.data.i = 0;
if (curstate.getLastActionID() == 3) //SETJZERO)
curstate.data.distance = 0;
return false;
}
bool SETIZEROcanAct(state &curstate)
{
return curstate.data.i != 0;
}
int SETIZEROreward(state &curstate)
{
return 0;
}
bool SETJZEROaction(state &curstate)
{
curstate.data.j = 0;
if (curstate.getLastActionID() == 2) //SETIZERO)
curstate.data.distance = 0;
return false;
}
bool SETJZEROcanAct(state &curstate)
{
return curstate.data.j != 0;
}
int SETJZEROreward(state &curstate)
{
return 0;
}
bool SETKZEROaction(state &curstate)
{
curstate.data.k = 0;
return false;
}
bool SETKZEROcanAct(state &curstate)
{
return curstate.data.k != 0;
}
int SETKZEROreward(state &curstate)
{
return 0;
}
bool SWAPaction(state &curstate)
{
if (curstate.data.j < curstate.data.list.size() &&
curstate.data.i < curstate.data.list.size())
{
int temp = curstate.data.list[curstate.data.i];
int temp2 = curstate.data.list[curstate.data.j];
curstate.data.list[curstate.data.i] = curstate.data.list[curstate.data.j];
curstate.data.list[curstate.data.j] = temp;
}
return false;
}
bool SWAPcanAct(state &curstate)
{
return true;
}
int SWAPreward(state &curstate)
{
int SWAPREWARD = 40;
int SWAPPENALTY = -40;
int reward = 0;
if (curstate.data.i == curstate.data.j || curstate.getConditions().ilen || curstate.getConditions().jlen)
{
reward = SWAPPENALTY;
}
else if (!curstate.getConditions().sorted || curstate.getConditions().igtj)
{
reward = SWAPPENALTY;
}
else
{
reward = SWAPREWARD;
}
return reward;
}
bool TERMINATEaction(state &curstate)
{
return true;
}
bool TERMINATEcanAct(state &curstate)
{
return drand48() < 0.9;
}
int TERMINATEreward(state &curstate)
{
int TERMREWARD = 400;
int TERMPENALTY = -400;
int reward = 0;
if (curstate.isgoal() && issorted2(curstate.data.list))
{
reward = TERMREWARD;
}
else
{
reward = TERMPENALTY;
}
return reward;
}