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

chierarchiccontroller.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 C_Hierarchical_CONTROLLER
00033 #define C_Hierarchical_CONTROLLER
00034 
00035 #include "cagentcontroller.h" 
00036 #include "cagentlistener.h"
00037 
00038 class CStateCollection;
00039 class CStateProperties;
00040 class CState;
00041 class CAction;
00042 class CActionSet;
00043 class CActionDataSet;
00044 class CActionList;
00045 class CExtendedAction;
00046 
00047 #include <list>
00048 #include <vector>
00049 
00050 class CHierarchicalStack;
00051 
00053 
00055 class CHierarchicalStackListener
00056 {
00057 public:
00058         virtual ~CHierarchicalStackListener() {};
00059 
00060         virtual void nextStep(CStateCollection *oldState, CHierarchicalStack *actionStack, CStateCollection *newState) = 0;
00061         virtual void newEpisode() {};
00062 };
00063 
00065 class CHierarchicalStackSender
00066 {
00067 protected:
00068         std::list<CHierarchicalStackListener *> *stackListeners;
00069 public:
00070         CHierarchicalStackSender();
00071         virtual ~CHierarchicalStackSender();
00072 
00073         void addHierarchicalStackListener(CHierarchicalStackListener *listener);
00074         void removeHierarchicalStackListener(CHierarchicalStackListener *listener);
00075 
00076         virtual void startNewEpisode();
00077         virtual void sendNextStep(CStateCollection *oldState, CHierarchicalStack *actionStack, CStateCollection *newState);
00078 };
00079 
00081 
00083 class CHierarchicalStackEpisode : public CHierarchicalStackListener
00084 {
00085 protected:
00086         std::vector<CActionList *> *actionStacks;
00087         CActionSet *behaviors;
00088 public:
00089         CHierarchicalStackEpisode(CActionSet *behaviors);
00090         virtual ~CHierarchicalStackEpisode();
00091 
00092         virtual void nextStep(CHierarchicalStack *actionStack);
00093         virtual void newEpisode();
00094 
00095         void loadASCII(FILE *stream);
00096         void saveASCII(FILE *stream);
00097 
00098         void saveAction(int index, FILE *stream);
00099 
00100         void getHierarchicalStack(unsigned int index, CHierarchicalStack *actionStack, bool clearStack = true);
00101         virtual int getNumSteps();
00102 };
00103 
00105 
00126 class CHierarchicalController : public CAgentController, public CHierarchicalStackSender, public CSemiMDPListener
00127 {
00128 protected:
00130         CActionSet *agentActions;
00132         CHierarchicalStack *actionStack;
00134         CExtendedAction *rootAction;
00135 
00136         CActionDataSet *hierarchichActionDataSet;
00137 
00139         virtual CAction* getAgentAction(CHierarchicalStack *stack, CActionDataSet *actionDataSet);
00140 public:
00142 
00143         CHierarchicalController(CActionSet *agentActions, CActionSet *allActions, CExtendedAction *rootAction);
00144         ~CHierarchicalController();
00146         int getMaxHierarchicalExecution();
00148         void setMaxHierarchicalExecution(int maxExec);
00149 
00151 
00152         virtual CAction *getNextAction(CStateCollection *state, CActionDataSet *actionDataSet);
00153 
00155 
00162         virtual void nextStep(CStateCollection *oldState, CAction *action, CStateCollection *newState);
00164         virtual void intermediateStep(CStateCollection *oldState, CAction *action, CStateCollection *newState);
00165 
00166         virtual void newEpisode();
00167 };
00168 
00169 #endif
00170