aGrUM  0.20.2
a C++ library for (probabilistic) graphical models
factorySimulator.cpp
Go to the documentation of this file.
1 /**
2  *
3  * Copyright 2005-2020 Pierre-Henri WUILLEMIN(@LIP6) & Christophe GONZALES(@AMU)
4  * info_at_agrum_dot_org
5  *
6  * This library is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU Lesser General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public License
17  * along with this library. If not, see <http://www.gnu.org/licenses/>.
18  *
19  */
20 
21 
22 ///**
23 // * @file
24 // * @brief Sources of
25 // *
26 // * @author Pierre-Henri WUILLEMIN(@LIP6) and Jean-Christophe MAGNAN and
27 // Christophe GONZALES(@AMU)
28 // *
29 // */
30 //// =====================================================================
31 //#include <random>
32 //#include <cstdlib>
33 ////======================================================================
34 //#include <agrum/FMDP/simulation/factorySimulator.h>
35 ////======================================================================
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 
75 //// fuelLevel__ = new LabelizedVariable("FuelLevel", "Niveau du réservoir",
76 /// 14);
77 
78 // // Ajout à séquence
79 // FactoryVars__.insert(xPos__);
80 // FactoryVars__.insert(yPos__);
81 // FactoryVars__.insert(passengerPos__);
82 // FactoryVars__.insert(passengerDest__);
83 //// FactoryVars__.insert(fuelLevel__);
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"));
111 //// FactoryActions__.insert(FillUp);
112 //// actionMap__.insert(FillUp, new std::string ("FillUp"));
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_();
135 //// Idx curFuelLevel = randy.valFromPtr(fuelLevel__);
136 //// while(curFuelLevel > 12 || curFuelLevel < 5)
137 //// curFuelLevel = (Idx)(((double)std::rand( ) / (double)RAND_MAX) * 7.0)
138 ///+ 5;
139 //// randy.chgVal(fuelLevel__, curFuelLevel);
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 
164 //// if( currentState_.valFromPtr(fuelLevel__) == 0 )
165 //// return true;
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 
192 //// if( currentState_.valFromPtr(fuelLevel__) == 0 )
193 //// return -10.0;
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 
207 //// Idx curFuelLevel = currentState_.valFromPtr(fuelLevel__);
208 //// if( curFuelLevel > 0 )
209 //// currentState_.chgVal(fuelLevel__, --curFuelLevel);
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