POMDP.h
Go to the documentation of this file.
00001 /********** tell emacs we use -*- c++ -*- style comments *******************
00002  $Revision: 2.28 $  $Author: duyanzhu $  $Date: 2009/01/07 05:10:04 $
00003    
00004  @file    POMDP.h
00005  @brief   Describes data structure of POMDP object which defines the
00006  @        pomdp problems
00007 
00008  Copyright (c) 2002-2005, Trey Smith. All rights reserved.
00009 
00010  Licensed under the Apache License, Version 2.0 (the "License"); you may
00011  not use this file except in compliance with the License.  You may
00012  obtain a copy of the License at
00013 
00014    http://www.apache.org/licenses/LICENSE-2.0
00015 
00016  Unless required by applicable law or agreed to in writing, software
00017  distributed under the License is distributed on an "AS IS" BASIS,
00018  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
00019  implied.  See the License for the specific language governing
00020  permissions and limitations under the License.
00021 
00022  ***************************************************************************/
00023 
00024 #ifndef POMDP_H
00025 #define POMDP_H
00026 
00027 #include <iostream>
00028 #include <string>
00029 #include <vector>
00030 
00031 #include "Const.h"
00032 #include "MDP.h"
00033 #include "SparseMatrix.h"
00034 #include "SparseVector.h"
00035 
00036 namespace momdp 
00037 {
00038 
00039 class POMDP : public MDP 
00040 {
00041 public:
00042   int numStates, numObservations;
00043   std::string fileName;//added Xan 12082007
00044 
00045   // initialBelief(s)
00046   SparseVector initialBelief;
00047 
00048   // R(s,a)
00049   SparseMatrix R;
00050   // T[a](s,s'), Ttr[a](s',s), O[a](s',o)
00051   std::vector<SparseMatrix> T, Ttr, O, Otr;
00052   //std::vector<bool> isPOMDPTerminalState;
00053   std::vector<int> isPOMDPTerminalState;
00054 
00055   POMDP(void) {}
00056   POMDP( std::string& fileName, bool useFastParser = false);
00057 
00058   void readFromFile( std::string& fileName, bool useFastParser = false);
00059   
00068   void getPossibleObservations(std::vector<int>& result, std::vector<REAL_VALUE>& resultProbs,  belief_vector& bel, int act) ;
00069 
00076   void getPossibleActions(std::vector<int>& result,  belief_vector bel) ;
00077 
00078   //*******added on 30/03/2007 rn
00079   //    for the access methods
00080   //returns the transition matrix for action a
00081    SparseMatrix& getTransitionMatrix(int a)  ;
00082 
00083   //returns the transposed transition matrix for action a
00084    SparseMatrix& getTransposedTransitionMatrix(int a) ;
00085 
00086   //returns the observation matrix for action a
00087    SparseMatrix& getObservationMatrix(int a) ;
00088 
00089   //returns the transposed observation matrix for action a
00090    SparseMatrix& getTransposedObservationMatrix(int a) ;
00091 
00092   //returns the reward matrix
00093     SparseMatrix& getRewardMatrix() ;
00094 
00095   //returns the max reward value 24/04/2007
00096          REAL_VALUE getMaxReward();
00097   //*******end added
00098 
00099   // returns the initial belief
00100    belief_vector& getInitialBelief(void) ;
00101 
00102   // sets result to be the vector of observation probabilities when from
00103   // belief b action a is selected
00104   obs_prob_vector& getObsProbVector(obs_prob_vector& result,  belief_vector& b,
00105                                     int a) ;
00106 
00107   // sets result to be the next belief when from belief b action a is
00108   // selected and observation o is observed
00109   belief_vector& getNextBelief(belief_vector& result,  belief_vector& b,
00110                                int a, int o) ;
00111 
00112   // returns the expected immediate reward when from belief b action a is selected
00113   REAL_VALUE getReward( belief_vector& b, int a) ;
00114 
00115   //AbstractBound* newLowerBound(void) ;
00116   //AbstractBound* newUpperBound(void) ;
00117 
00118   // POMDP-as-belief-MDP aliases for functions implemented in MDP
00119   int getBeliefSize(void)  { return getNumStateDimensions(); }
00120   int getNumObservations(void)  { return numObservations; }
00121   void setBeliefSize(int beliefSize) { numStateDimensions = beliefSize; }
00122   void setNumObservations(int _numObservations) { numObservations = _numObservations; }
00123 
00124   // POMDP-as-belief-MDP implementations for virtual functions declared in MDP
00125    belief_vector& getInitialState(void)  { return getInitialBelief(); }
00126   bool getIsTerminalState( belief_vector& s) ;
00127   outcome_prob_vector& getOutcomeProbVector(outcome_prob_vector& result,  belief_vector& b,
00128                                             int a) 
00129     { return getObsProbVector(result,b,a); }
00130   state_vector& getNextState(state_vector& result,  belief_vector& s,
00131                              int a, int o) 
00132     { return getNextBelief(result,s,a,o); }
00133   
00134 protected:
00135   void readFromFileCassandra( std::string& fileName);
00136   void readFromFileFast( std::string& fileName);
00137   void readFromFileFast2( std::string& fileName);
00138 
00139   void debugDensity(void);
00140 };
00141 
00142 }; // namespace momdp
00143 
00144 #endif // INCPOMDP_h
00145 
00146 /***************************************************************************
00147  * REVISION HISTORY:
00148  * $Log: POMDP.h,v $
00149  * Revision 2.28  2009/01/07 05:10:04  duyanzhu
00150  * added GES.h
00151  *
00152  * Revision 2.26  2009/01/07 05:05:59  duyanzhu
00153  * added evaluator_win
00154  *
00155  * Revision 2.24  2009/01/07 05:01:32  duyanzhu
00156  * add GES
00157  *
00158  * Revision 2.22  2009/01/07 04:59:00  duyanzhu
00159  * adding in UniqueBeliefHeap
00160  *
00161  * Revision 2.20  2009/01/07 04:33:54  duyanzhu
00162  * APPL 0.3, added Policy Evaluator, added Memory Limit option
00163  *
00164  * Revision 2.18  2008/09/17 14:08:36  duyanzhu
00165  * Fix: Prune now only starts 5 seconds after initialization
00166  *
00167  * Revision 2.16  2008/07/16 13:27:45  duyanzhu
00168  * Bring everything to version 2.16
00169  *
00170  * Revision 2.12  2008/07/16 08:38:15  duyanzhu
00171  * Add CPMemUtils class
00172  *
00173  * Revision 2.11  2008/07/16 08:34:48  duyanzhu
00174  * Added parser memory allocation check. Added release script
00175  *
00176  * Revision 2.10  2008/06/14 01:41:17  duyanzhu
00177  * 14 Jun 08 by Du Yanzhu. Added command line option percentageThreshold
00178  *
00179  * Revision 1.5  2007/08/17 01:44:35  duyanzhu
00180  * Change Alpha vector to DenseVector. Xan adds dump functions. Xan's bound propagation code is also included, but not added to Makefile
00181  *
00182  * Revision 1.4  2007/08/16 14:06:41  duyanzhu
00183  * Undo last commit
00184  *
00185  * Revision 1.2  2007/08/10 06:03:05  duyanzhu
00186  * *** empty log message ***
00187  *
00188  * Revision 1.1.1.1  2007/07/24 13:17:50  dyhsu
00189  * Approximate POMDP Planning Library (APPL)
00190  *
00191  * Revision 1.6  2007/06/04 07:58:50  jman
00192  * compiling error fixed and the runtime error handled...
00193  * now to get the tests to run ...
00194  *
00195  * Revision 1.5  2007/04/24 14:37:37  elern
00196  * added 'getMaxReward' method for CA maxDepth and delta computations
00197  *
00198  * Revision 1.4  2007/03/30 14:23:13  elern
00199  * Added 'getTransposedObservationMatrix' for POMDP
00200  *
00201  * Revision 1.3  2007/03/30 05:44:34  elern
00202  * the access methods changed to  type
00203  *
00204  * Revision 1.2  2007/03/30 03:25:16  elern
00205  * added access methods for POMDP
00206  *
00207  * Revision 1.1  2007/03/22 07:19:16  elern
00208  * initial revision
00209  *
00210  * Revision 1.6  2006/04/28 17:57:41  trey
00211  * changed to use apache license
00212  *
00213  * Revision 1.5  2006/02/17 18:36:35  trey
00214  * fixed getIsTerminalState() function so RTDP can be used
00215  *
00216  * Revision 1.4  2006/02/06 19:26:09  trey
00217  * removed numOutcomes from MDP class because some MDPs have a varying number of outcomes depending on state; replaced with numObservations in POMDP class
00218  *
00219  * Revision 1.3  2006/02/01 01:09:38  trey
00220  * renamed pomdpCore
00221  *
00222  * Revision 1.7  2006/01/29 00:18:36  trey
00223  * added POMDP() ructor that calls readFromFile()
00224  *
00225  * Revision 1.6  2006/01/28 03:03:23  trey
00226  * replaced BeliefMDP -> MDP, corresponding changes in API
00227  *
00228  * Revision 1.5  2005/11/03 17:45:30  trey
00229  * moved transition dynamics from HSVI implementation to POMDP
00230  *
00231  * Revision 1.4  2005/10/28 03:50:32  trey
00232  * simplified license
00233  *
00234  * Revision 1.3  2005/10/28 02:51:40  trey
00235  * added copyright headers
00236  *
00237  * Revision 1.2  2005/10/27 22:29:12  trey
00238  * removed dependence on SmartRef header
00239  *
00240  * Revision 1.1  2005/10/27 21:38:16  trey
00241  * renamed POMDPM to POMDP
00242  *
00243  * Revision 1.7  2005/10/21 20:08:41  trey
00244  * added namespace momdp
00245  *
00246  * Revision 1.6  2005/03/10 22:53:32  trey
00247  * now initialize T matrix even when using sla
00248  *
00249  * Revision 1.5  2005/01/27 05:32:02  trey
00250  * switched to use Ttr instead of T under sla
00251  *
00252  * Revision 1.4  2005/01/26 04:10:48  trey
00253  * modified problem reading to work with sla
00254  *
00255  * Revision 1.3  2005/01/21 15:21:19  trey
00256  * added readFromFileFast
00257  *
00258  * Revision 1.2  2004/11/24 20:50:16  trey
00259  * switched POMDPP to be a pointer, not a SmartRef
00260  *
00261  * Revision 1.1  2004/11/13 23:29:44  trey
00262  * moved many files from hsvi to common
00263  *
00264  * Revision 1.2  2004/11/09 21:31:59  trey
00265  * got pomdp source tree into a building state again
00266  *
00267  * Revision 1.1.1.1  2004/11/09 16:18:56  trey
00268  * imported hsvi into new repository
00269  *
00270  * Revision 1.5  2003/09/16 00:57:02  trey
00271  * lots of performance tuning, mostly fixed rising upper bound problem
00272  *
00273  * Revision 1.4  2003/09/11 01:46:42  trey
00274  * completed conversion to compressed matrices
00275  *
00276  * Revision 1.3  2003/09/07 02:28:07  trey
00277  * started to adapt for boost matrix library
00278  *
00279  * Revision 1.2  2003/07/16 16:07:36  trey
00280  * added isTerminalState
00281  *
00282  * Revision 1.1  2003/06/26 15:41:22  trey
00283  * C++ version of pomdp solver functional
00284  *
00285  *
00286  ***************************************************************************/


appl
Author(s): petercai
autogenerated on Tue Jan 7 2014 11:02:29