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