Reinforcement Learning Toolbox 2.0
last updated:
General
Documentation
Manual
Tutorial
Class Reference
Master Thesis
Examples
Related Papers
Downloads
Links
News
mailto:webmaster
Main Page     Class Hierarchy   Compound List   File List   Compound Members   File Members

caction.h

Go to the documentation of this file.
00001 // Copyright (C) 2003
00002 // Gerhard Neumann (gneumann@gmx.net)
00003 // Stephan Neumann (sneumann@gmx.net) 
00004 //                
00005 // This file is part of RL Toolbox.
00006 // http://www.igi.tugraz.at/ril_toolbox
00007 //
00008 // All rights reserved.
00009 // 
00010 // Redistribution and use in source and binary forms, with or without
00011 // modification, are permitted provided that the following conditions
00012 // are met:
00013 // 1. Redistributions of source code must retain the above copyright
00014 //    notice, this list of conditions and the following disclaimer.
00015 // 2. Redistributions in binary form must reproduce the above copyright
00016 //    notice, this list of conditions and the following disclaimer in the
00017 //    documentation and/or other materials provided with the distribution.
00018 // 3. The name of the author may not be used to endorse or promote products
00019 //    derived from this software without specific prior written permission.
00020 // 
00021 // THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
00022 // IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
00023 // OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
00024 // IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
00025 // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
00026 // NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
00027 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
00028 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00029 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
00030 // THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00031 
00032 #ifndef CACTION_H
00033 #define CACTION_H
00034 
00035 #include <stdio.h> 
00036 #include <vector>
00037 #include <list>
00038 #include <map>
00039 
00040 #include "cbaseobjects.h"
00041 
00042 class CStateCollection;
00043 class CStateProperties;
00044 
00045 #define EXTENDEDACTION 1
00046 #define MULTISTEPACTION 2
00047 #define PRIMITIVEACTION 4
00048 #define CONTINUOUSACTION 16
00049 #define CONTINUOUSSTATICACTION 32
00050 
00052 
00060 class CActionData
00061 {
00062 protected:
00063         bool bIsChangeAble;
00064 public:
00065         CActionData();
00066         virtual ~CActionData() {};
00067         
00068         virtual void saveASCII(FILE *stream) = 0;
00069         virtual void loadASCII(FILE *stream) = 0;
00070 
00071         virtual void saveBIN(FILE *stream) = 0;
00072         virtual void loadBIN(FILE *stream) = 0;
00073 
00075         virtual void setData(CActionData *actionData) = 0;
00076 
00077         bool isChangeAble();
00078         void setIsChangeAble(bool changeAble);
00079 };
00080 
00081 
00083 
00086 class CMultiStepActionData : public CActionData
00087 {
00088 public:
00089         CMultiStepActionData();
00090         virtual ~CMultiStepActionData() {};
00091 
00092         int duration;
00093         bool finished;
00094 
00095         virtual void saveASCII(FILE *stream);
00096         virtual void loadASCII(FILE *stream);
00097 
00098         virtual void saveBIN(FILE *stream);
00099         virtual void loadBIN(FILE *stream);
00100 
00102         virtual void setData(CActionData *actionData);
00103 
00104 };
00105 
00106 
00107 
00108 class CContinuousActionProperties;
00109 class CActionDataSet;
00110 
00111 
00113 
00137 class CAction
00138 {
00139 protected:
00145         int type;
00146         CActionData *actionData;
00147 
00148         CAction(CActionData *actionData);
00149 
00150 public:
00151     CAction();
00152         virtual ~CAction();
00153         
00154     int getType();
00155         bool isType(int type);
00156 
00158 
00162         void addType(int Type);
00163 
00164         
00166 
00169         virtual CActionData *getNewActionData();
00170 
00171         
00173         virtual void loadActionData(CActionData *actionData);
00175 
00178         virtual CActionData * getActionData();
00179 
00180         
00181 
00182         virtual bool isAvailable(CStateCollection *) {return true ;};//return isAvailable(state->getState());};
00183         //virtual bool isAvailable(CState *state) {return true;};
00184 
00186         virtual int getDuration() {return 1;};
00187 
00189         virtual bool equals(CAction *action);
00190 
00192         virtual bool isSameAction(CAction *action, CActionData *data);
00193 
00194 
00195 };
00196 
00198 
00201 class CHierarchicalStack: public std::list<CAction *> 
00202 {
00203 protected:
00204         
00205 public:
00206         CHierarchicalStack();
00207         virtual ~CHierarchicalStack();
00208         
00209         void clearAndDelete();
00210 };
00211 
00212 
00213 // An action which can long for several steps.
00224 class CMultiStepAction :  public CAction
00225 {
00226 protected:
00227         CMultiStepActionData *multiStepData;
00228 
00229         CMultiStepAction(CMultiStepActionData *multiStepData);
00230 public:
00231         CMultiStepAction();
00232         virtual ~CMultiStepAction(){};
00233 
00239         virtual bool isFinished(CStateCollection *oldState, CStateCollection *newState) = 0;
00240 
00241         virtual CActionData *getNewActionData();
00242 
00243         virtual CMultiStepActionData *getMultiStepActionData() {return multiStepData;};
00244 
00246         virtual int getDuration() {return multiStepData->duration;};
00247 };
00248 
00249 // Represents a primitive Action
00258 class CPrimitiveAction : public CAction
00259 {
00260 protected:
00261         CPrimitiveAction(CMultiStepActionData *actionData);
00262 public:
00263         CPrimitiveAction();
00264         virtual ~CPrimitiveAction();
00265         
00266         virtual int getDuration() {return 1;};
00267 };
00268 
00270 
00284 class CExtendedAction : public CMultiStepAction
00285 {
00286 protected:
00287         CExtendedAction(CMultiStepActionData *actionData);
00288 
00289 
00290 public:
00292         CAction *nextHierarchyLevel;
00293 
00294         CExtendedAction();
00295         virtual ~CExtendedAction(){};
00296 
00298         virtual CAction* getNextHierarchyLevel(CStateCollection *state, CActionDataSet *actionDataSet = NULL) = 0;
00300         void getHierarchicalStack(CHierarchicalStack *actionStack);
00302         bool sendIntermediateSteps;
00303 };
00304 
00305 
00306 
00307 
00309 
00318 class CActionSet : public std::list<CAction *>
00319 {
00320 
00321 public:
00322         CActionSet();
00323         virtual ~CActionSet();
00324 
00326         int getIndex(CAction *action);
00327 
00329         CAction *get(unsigned int index);
00330 
00332         void add(CAction *action);
00333 
00335         void add(CActionSet *actions);
00336 
00338         void getAvailableActions(CActionSet *availableActions, CStateCollection *state);
00339 
00340 //      returns wether the given action is member of the actionset
00341         bool isMember(CAction *action);
00342 };
00343 
00344 
00346 
00348 class CActionDataSet //: public CActionObject
00349 {
00350 protected:
00351         std::map<CAction *, CActionData *> *actionDatas;
00352 public:
00353         CActionDataSet(CActionSet *actions);
00354         CActionDataSet();
00355         virtual ~CActionDataSet();
00356 
00357         CActionData *getActionData(CAction *action);
00358         void setActionData(CAction *action, CActionData *data);
00359 
00360         void addActionData(CAction *action);
00361         void removeActionData(CAction *action);
00362 };
00363 
00365 
00372 class CActionList : public CActionObject
00373 {
00374 protected:
00375         // vector for the action indices
00376         std::vector<int> *actionIndices;
00378         std::map<int, CActionData *> *actionDatas;
00379 public:
00380         CActionList(CActionSet *actions);
00381         virtual ~CActionList();
00382 
00383 
00384         void addAction(CAction *action);
00385         CAction *getAction(unsigned int num, CActionDataSet *l_data);
00386 
00387         virtual void loadBIN(FILE *stream);
00388         virtual void saveBIN(FILE *stream);
00389 
00390         virtual void loadASCII(FILE *stream);
00391         virtual void saveASCII(FILE *stream);
00392         
00394         unsigned int getSize();
00395         unsigned int getNumActions();
00396         
00397 
00398         void clear();
00399 };
00400 
00401 
00402 
00403 #endif
00404 
00405 
00406