aGrUM
2.3.2
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-2025 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-2025 *
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
// std::stringstream ss;
73
// ss << pos;
74
// _xPos_->addLabel(ss.str());
75
// _yPos_->addLabel(ss.str());
76
// }
77
78
// // Position et destination passager
79
// _passengerPos_ = new LabelizedVariable("PassengerPos", "Position du
80
// Passager", 5);
81
// _passengerDest_ = new LabelizedVariable("PassengerDest", "Destination du
82
// Passager", 4);
83
// _passengerPos_->changeLabel(HOME, "Home");
84
// _passengerDest_->changeLabel(HOME, "Home");
85
// _passengerPos_->changeLabel(WORK, "Work");
86
// _passengerDest_->changeLabel(WORK, "Work");
87
// _passengerPos_->changeLabel(THEATER, "Theater");
88
// _passengerDest_->changeLabel(THEATER, "Theater");
89
// _passengerPos_->changeLabel(CLUB, "Club");
90
// _passengerDest_->changeLabel(CLUB, "Club");
91
// _passengerPos_->changeLabel(Factory, "Factory");
92
95
96
// // Ajout à séquence
97
// _FactoryVars_.insert( _xPos_);
98
// _FactoryVars_.insert( _yPos_);
99
// _FactoryVars_.insert( _passengerPos_);
100
// _FactoryVars_.insert( _passengerDest_);
102
103
// // Prime version creation
104
// for( SequenceIteratorSafe<const DiscreteVariable*> varIter =
105
// this->beginVariables(); varIter != this->endVariables(); ++varIter){
106
// DiscreteVariable* primeVar = (*varIter)->clone();
107
// primeVar->setName((*varIter)->name() + "'");
108
// _primeMap_.insert((*varIter), primeVar);
109
// }
110
111
// //
112
// *****************************************************************************************
113
114
// //
115
// *****************************************************************************************
116
// // Défintion des actions du problème
117
// _FactoryActions_.insert(GoNorth);
118
// _actionMap_.insert(GoNorth, new std::string ("Go North"));
119
// _FactoryActions_.insert(GoEast);
120
// _actionMap_.insert(GoEast, new std::string ("Go East"));
121
// _FactoryActions_.insert(GoSouth);
122
// _actionMap_.insert(GoSouth, new std::string ("Go South"));
123
// _FactoryActions_.insert(GoWest);
124
// _actionMap_.insert(GoWest, new std::string ("Go West"));
125
// _FactoryActions_.insert(PickUp);
126
// _actionMap_.insert(PickUp, new std::string ("Pick Up"));
127
// _FactoryActions_.insert(PutDown);
128
// _actionMap_.insert(PutDown, new std::string ("Put Down"));
131
// }
132
133
// FactorySimulator::~FactorySimulator(){
134
// GUM_DESTRUCTOR(FactorySimulator);
135
136
// for( BijectionIteratorSafe<const DiscreteVariable*, const
137
// DiscreteVariable*> varIter = _primeMap_.beginSafe();
138
// varIter != _primeMap_.endSafe(); ++varIter ){
139
// delete varIter.first();
140
// delete varIter.second();
141
// }
142
143
// }
144
145
146
// //
147
// ==================================================================================================================
148
// // Reward according to the situation
149
// //
150
// ==================================================================================================================
151
// Instantiation FactorySimulator::randomState_(){
152
// Instantiation randy = AbstractSimulator::randomState_();
158
159
// FactorySimulationLandmark passPos = (FactorySimulationLandmark)
160
// randy.valFromPtr( _passengerPos_);
161
// FactorySimulationLandmark passDest = (FactorySimulationLandmark)
162
// randy.valFromPtr( _passengerDest_);
163
// while( passPos == passDest || passPos == Factory )
164
// passPos = (FactorySimulationLandmark) (((double)std::rand( ) /
165
// (double)RAND_MAX) * 3.0);
166
// randy.chgVal( _passengerPos_, passPos);
167
168
// return randy;
169
// }
170
171
172
// //
173
// ==================================================================================================================
174
// // Reward according to the situation
175
// //
176
// ==================================================================================================================
177
// bool FactorySimulator::hasReachEnd(){
178
// if( currentState_.valFromPtr( _passengerPos_) ==
179
// currentState_.valFromPtr( _passengerDest_) )
180
// return true;
181
184
185
// return false;
186
// }
187
188
189
// //
190
// ==================================================================================================================
191
// // Reward according to the situation
192
// //
193
// ==================================================================================================================
194
// double FactorySimulator::reward(){
195
// if( currentState_.valFromPtr( _passengerPos_) ==
196
// currentState_.valFromPtr( _passengerDest_) ) {
197
// return 20.0;
198
// }
199
200
// if( _lastAction_ == PickUp ){
201
// if( currentState_.valFromPtr( _passengerPos_) != Factory )
202
// return -10.0;
203
// else
204
// return 10.0;
205
// }
206
207
// if( _lastAction_ == PutDown )
208
// return -10.0;
209
212
213
// return 0.0;//-1.0;
214
// }
215
216
// //
217
// ==================================================================================================================
218
// // Reward according to the situation
219
// //
220
// ==================================================================================================================
221
// void FactorySimulator::perform(Idx actionId){
222
223
// _lastAction_ = (FactorySimulationAction) actionId;
224
228
229
// switch(actionId){
230
// case GoNorth : return _goNorth_( );
231
// case GoEast : return _goEast_( );
232
// case GoSouth : return _goSouth_( );
233
// case GoWest : return _goWest_( );
234
// case PickUp : return _pickUp_( );
235
// case PutDown : return _putDown_( );
236
// case FillUp : return _fillUp_( );
237
// }
238
// }
239
240
241
// //
242
// ==================================================================================================================
243
// // Transition if you go North
244
// //
245
// ==================================================================================================================
246
// void FactorySimulator:: _goNorth_(){
247
// Idx curPos = this->currentState_.valFromPtr( _yPos_);
248
// if( curPos < 4 )
249
// currentState_.chgVal( _yPos_, ++curPos);
250
// }
251
252
253
// //
254
// ==================================================================================================================
255
// // Transition if you go east
256
// //
257
// ==================================================================================================================
258
// void FactorySimulator:: _goEast_(){
259
// Idx xCurPos = this->currentState_.valFromPtr( _xPos_);
260
// Idx yCurPos = this->currentState_.valFromPtr( _yPos_);
261
262
// if(xCurPos == 4)
263
// return;
264
// if(xCurPos == 0 || xCurPos == 2)
265
// if(yCurPos == 0 || yCurPos == 1)
266
// return;
267
// if(xCurPos == 1)
268
// if(yCurPos == 3 || yCurPos == 4)
269
// return;
270
271
// currentState_.chgVal( _xPos_, ++xCurPos);
272
// }
273
274
275
// //
276
// ==================================================================================================================
277
// // Transition if you go south
278
// //
279
// ==================================================================================================================
280
// void FactorySimulator:: _goSouth_(){
281
// Idx curPos = this->currentState_.valFromPtr( _yPos_);
282
// if( curPos > 0 )
283
// currentState_.chgVal( _yPos_, --curPos);
284
// }
285
286
287
// //
288
// ==================================================================================================================
289
// // Transition if you go west
290
// //
291
// ==================================================================================================================
292
// void FactorySimulator:: _goWest_(){
293
// Idx xCurPos = this->currentState_.valFromPtr( _xPos_);
294
// Idx yCurPos = this->currentState_.valFromPtr( _yPos_);
295
296
// if(xCurPos == 0)
297
// return;
298
// if(xCurPos == 1 || xCurPos == 3)
299
// if(yCurPos == 0 || yCurPos == 1)
300
// return;
301
// if(xCurPos == 2)
302
// if(yCurPos == 3 || yCurPos == 4)
303
// return;
304
305
// currentState_.chgVal( _xPos_, --xCurPos);
306
// }
307
308
309
// //
310
// ==================================================================================================================
311
// // Transition if you go pick up sb
312
// //
313
// ==================================================================================================================
314
// void FactorySimulator:: _pickUp_(){
315
// FactorySimulationLandmarkX xCurPos = (FactorySimulationLandmarkX)
316
// this->currentState_.valFromPtr( _xPos_);
317
// FactorySimulationLandmarkY yCurPos = (FactorySimulationLandmarkY)
318
// this->currentState_.valFromPtr( _yPos_);
319
// FactorySimulationLandmark passPos = (FactorySimulationLandmark)
320
// this->currentState_.valFromPtr( _passengerPos_);
321
// switch(passPos){
322
// case HOME : {
323
// if( xCurPos == HOMEX && yCurPos == HOMEY )
324
// currentState_.chgVal( _passengerPos_, Factory);
325
// return;
326
// }
327
// case WORK : {
328
// if( xCurPos == WORKX && yCurPos == WORKY )
329
// currentState_.chgVal( _passengerPos_, Factory);
330
// return;
331
// }
332
// case THEATER : {
333
// if( xCurPos == THEATERX && yCurPos == THEATERY )
334
// currentState_.chgVal( _passengerPos_, Factory);
335
// return;
336
// }
337
// case CLUB : {
338
// if( xCurPos == CLUBX && yCurPos == CLUBY )
339
// currentState_.chgVal( _passengerPos_, Factory);
340
// return;
341
// }
342
// case Factory : return;
343
// }
344
// }
345
346
347
// //
348
// ==================================================================================================================
349
// // Transition if you go put down sb
350
// //
351
// ==================================================================================================================
352
// void FactorySimulator:: _putDown_(){
353
// FactorySimulationLandmarkX xCurPos = (FactorySimulationLandmarkX)
354
// this->currentState_.valFromPtr( _xPos_);
355
// FactorySimulationLandmarkY yCurPos = (FactorySimulationLandmarkY)
356
// this->currentState_.valFromPtr( _yPos_);
357
// FactorySimulationLandmark passPos = (FactorySimulationLandmark)
358
// this->currentState_.valFromPtr( _passengerPos_);
359
// FactorySimulationLandmark passDest = (FactorySimulationLandmark)
360
// this->currentState_.valFromPtr( _passengerDest_);
361
// if(passPos == Factory ){
362
// switch(passDest){
363
// case HOME : {
364
// if( xCurPos == HOMEX && yCurPos == HOMEY )
365
// currentState_.chgVal( _passengerPos_, HOME);
366
// return;
367
// }
368
// case WORK : {
369
// if( xCurPos == WORKX && yCurPos == WORKY )
370
// currentState_.chgVal( _passengerPos_, WORK);
371
// return;
372
// }
373
// case THEATER : {
374
// if( xCurPos == THEATERX && yCurPos == THEATERY )
375
// currentState_.chgVal( _passengerPos_, THEATER);
376
// return;
377
// }
378
// case CLUB : {
379
// if( xCurPos == CLUBX && yCurPos == CLUBY )
380
// currentState_.chgVal( _passengerPos_, CLUB);
381
// return;
382
// }
383
// case Factory : return;
384
// }
385
386
// }
387
// }
388
389
390
// //
391
// ==================================================================================================================
392
// // Transition if you go reffill
393
// //
394
// ==================================================================================================================
395
// void FactorySimulator:: _fillUp_(){
396
// FactorySimulationLandmarkX xCurPos = (FactorySimulationLandmarkX)
397
// this->currentState_.valFromPtr( _xPos_);
398
// FactorySimulationLandmarkY yCurPos = (FactorySimulationLandmarkY)
399
// this->currentState_.valFromPtr( _yPos_);
400
401
// if( xCurPos == STATIONX && yCurPos == STATIONY )
402
// currentState_.chgVal( _fuelLevel_, 13);
403
// }
404
//} // End of namespace gum