aGrUM
3.1.1
a C++ library for (probabilistic) graphical models
factorySimulator.cpp
Go to the documentation of this file.
1
/****************************************************************************
2
* This file is part of the aGrUM/pyAgrum library. *
3
* *
4
* Copyright (c) 2005-2026 by *
5
* - Pierre-Henri WUILLEMIN(_at_LIP6) *
6
* - Christophe GONZALES(_at_AMU) *
7
* *
8
* The aGrUM/pyAgrum library is free software; you can redistribute it *
9
* and/or modify it under the terms of either : *
10
* *
11
* - the GNU Lesser General Public License as published by *
12
* the Free Software Foundation, either version 3 of the License, *
13
* or (at your option) any later version, *
14
* - the MIT license (MIT), *
15
* - or both in dual license, as here. *
16
* *
17
* (see https://agrum.gitlab.io/articles/dual-licenses-lgplv3mit.html) *
18
* *
19
* This aGrUM/pyAgrum library is distributed in the hope that it will be *
20
* useful, but WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, *
21
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES MERCHANTABILITY or FITNESS *
22
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE *
23
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *
24
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, *
25
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR *
26
* OTHER DEALINGS IN THE SOFTWARE. *
27
* *
28
* See LICENCES for more details. *
29
* *
30
* SPDX-FileCopyrightText: Copyright 2005-2026 *
31
* - Pierre-Henri WUILLEMIN(_at_LIP6) *
32
* - Christophe GONZALES(_at_AMU) *
33
* SPDX-License-Identifier: LGPL-3.0-or-later OR MIT *
34
* *
35
* Contact : info_at_agrum_dot_org *
36
* homepage : http://agrum.gitlab.io *
37
* gitlab : https://gitlab.com/agrumery/agrum *
38
* *
39
****************************************************************************/
40
41
43
// * @file
44
// * @brief Sources of
45
// *
46
// * @author Pierre-Henri WUILLEMIN(_at_LIP6) and Jean-Christophe MAGNAN and
47
// Christophe GONZALES(_at_AMU)
48
// *
49
// */
50
52
// #include <agrum/FMDP/simulation/factorySimulator.h>
54
55
// namespace gum {
56
57
// FactorySimulator::FactorySimulator():AbstractSimulator(){
58
// GUM_CONSTRUCTOR(FactorySimulator);
59
60
// //
61
// *****************************************************************************************
62
// // Défintion des variables du problème
63
64
// // Position FactorySimulator
65
// _xPos_ = new LabelizedVariable("xPos", "Position horizontale du
66
// FactorySimulator");
67
// _yPos_ = new LabelizedVariable("yPos", "Position verticale du
68
// FactorySimulator");
69
// _xPos_->eraseLabels();
70
// _yPos_->eraseLabels();
71
// for( Idx pos = 0; pos < 5; pos++){
72
// _xPos_->addLabel(std::to_string(pos));
73
// _yPos_->addLabel(std::to_string(pos));
74
// }
75
76
// // Position et destination passager
77
// _passengerPos_ = new LabelizedVariable("PassengerPos", "Position du
78
// Passager", 5);
79
// _passengerDest_ = new LabelizedVariable("PassengerDest", "Destination du
80
// Passager", 4);
81
// _passengerPos_->changeLabel(HOME, "Home");
82
// _passengerDest_->changeLabel(HOME, "Home");
83
// _passengerPos_->changeLabel(WORK, "Work");
84
// _passengerDest_->changeLabel(WORK, "Work");
85
// _passengerPos_->changeLabel(THEATER, "Theater");
86
// _passengerDest_->changeLabel(THEATER, "Theater");
87
// _passengerPos_->changeLabel(CLUB, "Club");
88
// _passengerDest_->changeLabel(CLUB, "Club");
89
// _passengerPos_->changeLabel(Factory, "Factory");
90
93
94
// // Ajout à séquence
95
// _FactoryVars_.insert( _xPos_);
96
// _FactoryVars_.insert( _yPos_);
97
// _FactoryVars_.insert( _passengerPos_);
98
// _FactoryVars_.insert( _passengerDest_);
100
101
// // Prime version creation
102
// for( SequenceIteratorSafe<const DiscreteVariable*> varIter =
103
// this->beginVariables(); varIter != this->endVariables(); ++varIter){
104
// DiscreteVariable* primeVar = (*varIter)->clone();
105
// primeVar->setName((*varIter)->name() + "'");
106
// _primeMap_.insert((*varIter), primeVar);
107
// }
108
109
// //
110
// *****************************************************************************************
111
112
// //
113
// *****************************************************************************************
114
// // Défintion des actions du problème
115
// _FactoryActions_.insert(GoNorth);
116
// _actionMap_.insert(GoNorth, new std::string ("Go North"));
117
// _FactoryActions_.insert(GoEast);
118
// _actionMap_.insert(GoEast, new std::string ("Go East"));
119
// _FactoryActions_.insert(GoSouth);
120
// _actionMap_.insert(GoSouth, new std::string ("Go South"));
121
// _FactoryActions_.insert(GoWest);
122
// _actionMap_.insert(GoWest, new std::string ("Go West"));
123
// _FactoryActions_.insert(PickUp);
124
// _actionMap_.insert(PickUp, new std::string ("Pick Up"));
125
// _FactoryActions_.insert(PutDown);
126
// _actionMap_.insert(PutDown, new std::string ("Put Down"));
129
// }
130
131
// FactorySimulator::~FactorySimulator(){
132
// GUM_DESTRUCTOR(FactorySimulator);
133
134
// for( BijectionIteratorSafe<const DiscreteVariable*, const
135
// DiscreteVariable*> varIter = _primeMap_.beginSafe();
136
// varIter != _primeMap_.endSafe(); ++varIter ){
137
// delete varIter.first();
138
// delete varIter.second();
139
// }
140
141
// }
142
143
144
// //
145
// ==================================================================================================================
146
// // Reward according to the situation
147
// //
148
// ==================================================================================================================
149
// Instantiation FactorySimulator::randomState_(){
150
// Instantiation randy = AbstractSimulator::randomState_();
156
157
// FactorySimulationLandmark passPos = (FactorySimulationLandmark)
158
// randy.valFromPtr( _passengerPos_);
159
// FactorySimulationLandmark passDest = (FactorySimulationLandmark)
160
// randy.valFromPtr( _passengerDest_);
161
// while( passPos == passDest || passPos == Factory )
162
// passPos = (FactorySimulationLandmark) (((double)std::rand( ) /
163
// (double)RAND_MAX) * 3.0);
164
// randy.chgVal( _passengerPos_, passPos);
165
166
// return randy;
167
// }
168
169
170
// //
171
// ==================================================================================================================
172
// // Reward according to the situation
173
// //
174
// ==================================================================================================================
175
// bool FactorySimulator::hasReachEnd(){
176
// if( currentState_.valFromPtr( _passengerPos_) ==
177
// currentState_.valFromPtr( _passengerDest_) )
178
// return true;
179
182
183
// return false;
184
// }
185
186
187
// //
188
// ==================================================================================================================
189
// // Reward according to the situation
190
// //
191
// ==================================================================================================================
192
// double FactorySimulator::reward(){
193
// if( currentState_.valFromPtr( _passengerPos_) ==
194
// currentState_.valFromPtr( _passengerDest_) ) {
195
// return 20.0;
196
// }
197
198
// if( _lastAction_ == PickUp ){
199
// if( currentState_.valFromPtr( _passengerPos_) != Factory )
200
// return -10.0;
201
// else
202
// return 10.0;
203
// }
204
205
// if( _lastAction_ == PutDown )
206
// return -10.0;
207
210
211
// return 0.0;//-1.0;
212
// }
213
214
// //
215
// ==================================================================================================================
216
// // Reward according to the situation
217
// //
218
// ==================================================================================================================
219
// void FactorySimulator::perform(Idx actionId){
220
221
// _lastAction_ = (FactorySimulationAction) actionId;
222
226
227
// switch(actionId){
228
// case GoNorth : return _goNorth_( );
229
// case GoEast : return _goEast_( );
230
// case GoSouth : return _goSouth_( );
231
// case GoWest : return _goWest_( );
232
// case PickUp : return _pickUp_( );
233
// case PutDown : return _putDown_( );
234
// case FillUp : return _fillUp_( );
235
// }
236
// }
237
238
239
// //
240
// ==================================================================================================================
241
// // Transition if you go North
242
// //
243
// ==================================================================================================================
244
// void FactorySimulator:: _goNorth_(){
245
// Idx curPos = this->currentState_.valFromPtr( _yPos_);
246
// if( curPos < 4 )
247
// currentState_.chgVal( _yPos_, ++curPos);
248
// }
249
250
251
// //
252
// ==================================================================================================================
253
// // Transition if you go east
254
// //
255
// ==================================================================================================================
256
// void FactorySimulator:: _goEast_(){
257
// Idx xCurPos = this->currentState_.valFromPtr( _xPos_);
258
// Idx yCurPos = this->currentState_.valFromPtr( _yPos_);
259
260
// if(xCurPos == 4)
261
// return;
262
// if(xCurPos == 0 || xCurPos == 2)
263
// if(yCurPos == 0 || yCurPos == 1)
264
// return;
265
// if(xCurPos == 1)
266
// if(yCurPos == 3 || yCurPos == 4)
267
// return;
268
269
// currentState_.chgVal( _xPos_, ++xCurPos);
270
// }
271
272
273
// //
274
// ==================================================================================================================
275
// // Transition if you go south
276
// //
277
// ==================================================================================================================
278
// void FactorySimulator:: _goSouth_(){
279
// Idx curPos = this->currentState_.valFromPtr( _yPos_);
280
// if( curPos > 0 )
281
// currentState_.chgVal( _yPos_, --curPos);
282
// }
283
284
285
// //
286
// ==================================================================================================================
287
// // Transition if you go west
288
// //
289
// ==================================================================================================================
290
// void FactorySimulator:: _goWest_(){
291
// Idx xCurPos = this->currentState_.valFromPtr( _xPos_);
292
// Idx yCurPos = this->currentState_.valFromPtr( _yPos_);
293
294
// if(xCurPos == 0)
295
// return;
296
// if(xCurPos == 1 || xCurPos == 3)
297
// if(yCurPos == 0 || yCurPos == 1)
298
// return;
299
// if(xCurPos == 2)
300
// if(yCurPos == 3 || yCurPos == 4)
301
// return;
302
303
// currentState_.chgVal( _xPos_, --xCurPos);
304
// }
305
306
307
// //
308
// ==================================================================================================================
309
// // Transition if you go pick up sb
310
// //
311
// ==================================================================================================================
312
// void FactorySimulator:: _pickUp_(){
313
// FactorySimulationLandmarkX xCurPos = (FactorySimulationLandmarkX)
314
// this->currentState_.valFromPtr( _xPos_);
315
// FactorySimulationLandmarkY yCurPos = (FactorySimulationLandmarkY)
316
// this->currentState_.valFromPtr( _yPos_);
317
// FactorySimulationLandmark passPos = (FactorySimulationLandmark)
318
// this->currentState_.valFromPtr( _passengerPos_);
319
// switch(passPos){
320
// case HOME : {
321
// if( xCurPos == HOMEX && yCurPos == HOMEY )
322
// currentState_.chgVal( _passengerPos_, Factory);
323
// return;
324
// }
325
// case WORK : {
326
// if( xCurPos == WORKX && yCurPos == WORKY )
327
// currentState_.chgVal( _passengerPos_, Factory);
328
// return;
329
// }
330
// case THEATER : {
331
// if( xCurPos == THEATERX && yCurPos == THEATERY )
332
// currentState_.chgVal( _passengerPos_, Factory);
333
// return;
334
// }
335
// case CLUB : {
336
// if( xCurPos == CLUBX && yCurPos == CLUBY )
337
// currentState_.chgVal( _passengerPos_, Factory);
338
// return;
339
// }
340
// case Factory : return;
341
// }
342
// }
343
344
345
// //
346
// ==================================================================================================================
347
// // Transition if you go put down sb
348
// //
349
// ==================================================================================================================
350
// void FactorySimulator:: _putDown_(){
351
// FactorySimulationLandmarkX xCurPos = (FactorySimulationLandmarkX)
352
// this->currentState_.valFromPtr( _xPos_);
353
// FactorySimulationLandmarkY yCurPos = (FactorySimulationLandmarkY)
354
// this->currentState_.valFromPtr( _yPos_);
355
// FactorySimulationLandmark passPos = (FactorySimulationLandmark)
356
// this->currentState_.valFromPtr( _passengerPos_);
357
// FactorySimulationLandmark passDest = (FactorySimulationLandmark)
358
// this->currentState_.valFromPtr( _passengerDest_);
359
// if(passPos == Factory ){
360
// switch(passDest){
361
// case HOME : {
362
// if( xCurPos == HOMEX && yCurPos == HOMEY )
363
// currentState_.chgVal( _passengerPos_, HOME);
364
// return;
365
// }
366
// case WORK : {
367
// if( xCurPos == WORKX && yCurPos == WORKY )
368
// currentState_.chgVal( _passengerPos_, WORK);
369
// return;
370
// }
371
// case THEATER : {
372
// if( xCurPos == THEATERX && yCurPos == THEATERY )
373
// currentState_.chgVal( _passengerPos_, THEATER);
374
// return;
375
// }
376
// case CLUB : {
377
// if( xCurPos == CLUBX && yCurPos == CLUBY )
378
// currentState_.chgVal( _passengerPos_, CLUB);
379
// return;
380
// }
381
// case Factory : return;
382
// }
383
384
// }
385
// }
386
387
388
// //
389
// ==================================================================================================================
390
// // Transition if you go reffill
391
// //
392
// ==================================================================================================================
393
// void FactorySimulator:: _fillUp_(){
394
// FactorySimulationLandmarkX xCurPos = (FactorySimulationLandmarkX)
395
// this->currentState_.valFromPtr( _xPos_);
396
// FactorySimulationLandmarkY yCurPos = (FactorySimulationLandmarkY)
397
// this->currentState_.valFromPtr( _yPos_);
398
399
// if( xCurPos == STATIONX && yCurPos == STATIONY )
400
// currentState_.chgVal( _fuelLevel_, 13);
401
// }
402
//} // End of namespace gum
403
404
#ifdef GUM_NO_INLINE
405
# include <
agrum/FMDP/simulation/factorySimulator_inl.h
>
406
#endif
// GUM_NO_INLINE
factorySimulator_inl.h