aGrUM
0.16.0
factorySimulator.cpp
Go to the documentation of this file.
1
23
// * @file
25
// * @brief Sources of
26
// *
27
// * @author Jean-Christophe MAGNAN and Pierre-Henri WUILLEMIN
28
// *
29
// */
31
//#include <random>
32
//#include <cstdlib>
34
//#include <agrum/FMDP/simulation/factorySimulator.h>
36
37
// namespace gum {
38
39
// FactorySimulator::FactorySimulator():AbstractSimulator(){
40
// GUM_CONSTRUCTOR(FactorySimulator)
41
42
// //
43
// *****************************************************************************************
44
// // Défintion des variables du problème
45
46
// // Position FactorySimulator
47
// __xPos = new LabelizedVariable("xPos", "Position horizontale du
48
// FactorySimulator");
49
// __yPos = new LabelizedVariable("yPos", "Position verticale du
50
// FactorySimulator");
51
// __xPos->eraseLabels();
52
// __yPos->eraseLabels();
53
// for( Idx pos = 0; pos < 5; pos++){
54
// std::stringstream ss;
55
// ss << pos;
56
// __xPos->addLabel(ss.str());
57
// __yPos->addLabel(ss.str());
58
// }
59
60
// // Position et destination passager
61
// __passengerPos = new LabelizedVariable("PassengerPos", "Position du
62
// Passager", 5);
63
// __passengerDest = new LabelizedVariable("PassengerDest", "Destination du
64
// Passager", 4);
65
// __passengerPos->changeLabel(HOME, "Home");
66
// __passengerDest->changeLabel(HOME, "Home");
67
// __passengerPos->changeLabel(WORK, "Work");
68
// __passengerDest->changeLabel(WORK, "Work");
69
// __passengerPos->changeLabel(THEATER, "Theater");
70
// __passengerDest->changeLabel(THEATER, "Theater");
71
// __passengerPos->changeLabel(CLUB, "Club");
72
// __passengerDest->changeLabel(CLUB, "Club");
73
// __passengerPos->changeLabel(Factory, "Factory");
74
77
78
// // Ajout à séquence
79
// __FactoryVars.insert(__xPos);
80
// __FactoryVars.insert(__yPos);
81
// __FactoryVars.insert(__passengerPos);
82
// __FactoryVars.insert(__passengerDest);
84
85
// // Prime version creation
86
// for( SequenceIteratorSafe<const DiscreteVariable*> varIter =
87
// this->beginVariables(); varIter != this->endVariables(); ++varIter){
88
// DiscreteVariable* primeVar = (*varIter)->clone();
89
// primeVar->setName((*varIter)->name() + "'");
90
// __primeMap.insert((*varIter), primeVar);
91
// }
92
93
// //
94
// *****************************************************************************************
95
96
// //
97
// *****************************************************************************************
98
// // Défintion des actions du problème
99
// __FactoryActions.insert(GoNorth);
100
// __actionMap.insert(GoNorth, new std::string ("Go North"));
101
// __FactoryActions.insert(GoEast);
102
// __actionMap.insert(GoEast, new std::string ("Go East"));
103
// __FactoryActions.insert(GoSouth);
104
// __actionMap.insert(GoSouth, new std::string ("Go South"));
105
// __FactoryActions.insert(GoWest);
106
// __actionMap.insert(GoWest, new std::string ("Go West"));
107
// __FactoryActions.insert(PickUp);
108
// __actionMap.insert(PickUp, new std::string ("Pick Up"));
109
// __FactoryActions.insert(PutDown);
110
// __actionMap.insert(PutDown, new std::string ("Put Down"));
113
// }
114
115
// FactorySimulator::~FactorySimulator(){
116
// GUM_DESTRUCTOR(FactorySimulator)
117
118
// for( BijectionIteratorSafe<const DiscreteVariable*, const
119
// DiscreteVariable*> varIter = __primeMap.beginSafe();
120
// varIter != __primeMap.endSafe(); ++varIter ){
121
// delete varIter.first();
122
// delete varIter.second();
123
// }
124
125
// }
126
127
128
// //
129
// ==================================================================================================================
130
// // Reward according to the situation
131
// //
132
// ==================================================================================================================
133
// Instantiation FactorySimulator::_randomState(){
134
// Instantiation randy = AbstractSimulator::_randomState();
140
141
// FactorySimulationLandmark passPos = (FactorySimulationLandmark)
142
// randy.valFromPtr(__passengerPos);
143
// FactorySimulationLandmark passDest = (FactorySimulationLandmark)
144
// randy.valFromPtr(__passengerDest);
145
// while( passPos == passDest || passPos == Factory )
146
// passPos = (FactorySimulationLandmark) (((double)std::rand( ) /
147
// (double)RAND_MAX) * 3.0);
148
// randy.chgVal(__passengerPos, passPos);
149
150
// return randy;
151
// }
152
153
154
// //
155
// ==================================================================================================================
156
// // Reward according to the situation
157
// //
158
// ==================================================================================================================
159
// bool FactorySimulator::hasReachEnd(){
160
// if( _currentState.valFromPtr(__passengerPos) ==
161
// _currentState.valFromPtr(__passengerDest) )
162
// return true;
163
166
167
// return false;
168
// }
169
170
171
// //
172
// ==================================================================================================================
173
// // Reward according to the situation
174
// //
175
// ==================================================================================================================
176
// double FactorySimulator::reward(){
177
// if( _currentState.valFromPtr(__passengerPos) ==
178
// _currentState.valFromPtr(__passengerDest) ) {
179
// return 20.0;
180
// }
181
182
// if( __lastAction == PickUp ){
183
// if( _currentState.valFromPtr(__passengerPos) != Factory )
184
// return -10.0;
185
// else
186
// return 10.0;
187
// }
188
189
// if( __lastAction == PutDown )
190
// return -10.0;
191
194
195
// return 0.0;//-1.0;
196
// }
197
198
// //
199
// ==================================================================================================================
200
// // Reward according to the situation
201
// //
202
// ==================================================================================================================
203
// void FactorySimulator::perform(Idx actionId){
204
205
// __lastAction = (FactorySimulationAction) actionId;
206
210
211
// switch(actionId){
212
// case GoNorth : return __goNorth( );
213
// case GoEast : return __goEast( );
214
// case GoSouth : return __goSouth( );
215
// case GoWest : return __goWest( );
216
// case PickUp : return __pickUp( );
217
// case PutDown : return __putDown( );
218
// case FillUp : return __fillUp( );
219
// }
220
// }
221
222
223
// //
224
// ==================================================================================================================
225
// // Transition if you go North
226
// //
227
// ==================================================================================================================
228
// void FactorySimulator::__goNorth(){
229
// Idx curPos = this->_currentState.valFromPtr(__yPos);
230
// if( curPos < 4 )
231
// _currentState.chgVal(__yPos, ++curPos);
232
// }
233
234
235
// //
236
// ==================================================================================================================
237
// // Transition if you go east
238
// //
239
// ==================================================================================================================
240
// void FactorySimulator::__goEast(){
241
// Idx xCurPos = this->_currentState.valFromPtr(__xPos);
242
// Idx yCurPos = this->_currentState.valFromPtr(__yPos);
243
244
// if(xCurPos == 4)
245
// return;
246
// if(xCurPos == 0 || xCurPos == 2)
247
// if(yCurPos == 0 || yCurPos == 1)
248
// return;
249
// if(xCurPos == 1)
250
// if(yCurPos == 3 || yCurPos == 4)
251
// return;
252
253
// _currentState.chgVal(__xPos, ++xCurPos);
254
// }
255
256
257
// //
258
// ==================================================================================================================
259
// // Transition if you go south
260
// //
261
// ==================================================================================================================
262
// void FactorySimulator::__goSouth(){
263
// Idx curPos = this->_currentState.valFromPtr(__yPos);
264
// if( curPos > 0 )
265
// _currentState.chgVal(__yPos, --curPos);
266
// }
267
268
269
// //
270
// ==================================================================================================================
271
// // Transition if you go west
272
// //
273
// ==================================================================================================================
274
// void FactorySimulator::__goWest(){
275
// Idx xCurPos = this->_currentState.valFromPtr(__xPos);
276
// Idx yCurPos = this->_currentState.valFromPtr(__yPos);
277
278
// if(xCurPos == 0)
279
// return;
280
// if(xCurPos == 1 || xCurPos == 3)
281
// if(yCurPos == 0 || yCurPos == 1)
282
// return;
283
// if(xCurPos == 2)
284
// if(yCurPos == 3 || yCurPos == 4)
285
// return;
286
287
// _currentState.chgVal(__xPos, --xCurPos);
288
// }
289
290
291
// //
292
// ==================================================================================================================
293
// // Transition if you go pick up sb
294
// //
295
// ==================================================================================================================
296
// void FactorySimulator::__pickUp(){
297
// FactorySimulationLandmarkX xCurPos = (FactorySimulationLandmarkX)
298
// this->_currentState.valFromPtr(__xPos);
299
// FactorySimulationLandmarkY yCurPos = (FactorySimulationLandmarkY)
300
// this->_currentState.valFromPtr(__yPos);
301
// FactorySimulationLandmark passPos = (FactorySimulationLandmark)
302
// this->_currentState.valFromPtr(__passengerPos);
303
// switch(passPos){
304
// case HOME : {
305
// if( xCurPos == HOMEX && yCurPos == HOMEY )
306
// _currentState.chgVal(__passengerPos, Factory);
307
// return;
308
// }
309
// case WORK : {
310
// if( xCurPos == WORKX && yCurPos == WORKY )
311
// _currentState.chgVal(__passengerPos, Factory);
312
// return;
313
// }
314
// case THEATER : {
315
// if( xCurPos == THEATERX && yCurPos == THEATERY )
316
// _currentState.chgVal(__passengerPos, Factory);
317
// return;
318
// }
319
// case CLUB : {
320
// if( xCurPos == CLUBX && yCurPos == CLUBY )
321
// _currentState.chgVal(__passengerPos, Factory);
322
// return;
323
// }
324
// case Factory : return;
325
// }
326
// }
327
328
329
// //
330
// ==================================================================================================================
331
// // Transition if you go put down sb
332
// //
333
// ==================================================================================================================
334
// void FactorySimulator::__putDown(){
335
// FactorySimulationLandmarkX xCurPos = (FactorySimulationLandmarkX)
336
// this->_currentState.valFromPtr(__xPos);
337
// FactorySimulationLandmarkY yCurPos = (FactorySimulationLandmarkY)
338
// this->_currentState.valFromPtr(__yPos);
339
// FactorySimulationLandmark passPos = (FactorySimulationLandmark)
340
// this->_currentState.valFromPtr(__passengerPos);
341
// FactorySimulationLandmark passDest = (FactorySimulationLandmark)
342
// this->_currentState.valFromPtr(__passengerDest);
343
// if(passPos == Factory ){
344
// switch(passDest){
345
// case HOME : {
346
// if( xCurPos == HOMEX && yCurPos == HOMEY )
347
// _currentState.chgVal(__passengerPos, HOME);
348
// return;
349
// }
350
// case WORK : {
351
// if( xCurPos == WORKX && yCurPos == WORKY )
352
// _currentState.chgVal(__passengerPos, WORK);
353
// return;
354
// }
355
// case THEATER : {
356
// if( xCurPos == THEATERX && yCurPos == THEATERY )
357
// _currentState.chgVal(__passengerPos, THEATER);
358
// return;
359
// }
360
// case CLUB : {
361
// if( xCurPos == CLUBX && yCurPos == CLUBY )
362
// _currentState.chgVal(__passengerPos, CLUB);
363
// return;
364
// }
365
// case Factory : return;
366
// }
367
368
// }
369
// }
370
371
372
// //
373
// ==================================================================================================================
374
// // Transition if you go reffill
375
// //
376
// ==================================================================================================================
377
// void FactorySimulator::__fillUp(){
378
// FactorySimulationLandmarkX xCurPos = (FactorySimulationLandmarkX)
379
// this->_currentState.valFromPtr(__xPos);
380
// FactorySimulationLandmarkY yCurPos = (FactorySimulationLandmarkY)
381
// this->_currentState.valFromPtr(__yPos);
382
383
// if( xCurPos == STATIONX && yCurPos == STATIONY )
384
// _currentState.chgVal(__fuelLevel, 13);
385
// }
386
//} // End of namespace gum