1 /**
2  *
3  *   Copyright (c) 2005-2021 by Pierre-Henri WUILLEMIN(_at_LIP6) & Christophe GONZALES(_at_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(_at_LIP6) and Jean-Christophe MAGNAN and
27 // Christophe GONZALES(_at_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
387