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

cagentlogger.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 CAGENTLOGGER_H
00033 #define CAGENTLOGGER_H
00034 
00035 #include "cagentlistener.h"
00036 #include "cepisodehistory.h"
00037 #include "cbaseobjects.h"
00038 
00039 #include <stdio.h>
00040 #include <list>
00041 
00042 class CEpisode;
00043 class CStateModifier;
00045 
00056 class CAgentLogger: public CSemiMDPListener, public CEpisodeHistory
00057 {
00058 protected:
00060     char filename[512];
00062     FILE* file;
00063 
00064         char loadFileName[512];
00065         std::list<CStateModifier *> *loadModifiers;
00067         int holdMemory;
00068 
00070         std::list<CEpisode *> *episodes;
00072         CEpisode *currentEpisode;
00073         
00074         void init();
00075 public:
00077         CAgentLogger(CStateProperties *model, CActionSet *actions, char* autoSavefile, int holdMemory);
00079         CAgentLogger(CStateProperties *model, CActionSet *actions);
00081         CAgentLogger(char *loadFile, CStateProperties *model, CActionSet *actions, std::list<CStateModifier *> *modifiers);
00082 
00083         virtual ~CAgentLogger();
00084 
00086         virtual void nextStep(CStateCollection *oldState, CAction *action, CStateCollection *nextState);
00088         virtual void newEpisode();
00089 
00091         void setAutoSaveFile(char *filename);
00092 
00094         virtual void saveBIN(FILE *stream);
00096         virtual void saveData(FILE *stream);
00098 
00099         void loadBIN(FILE *stream, std::list<CStateModifier *> *modifiers, int episodes = -1);
00101 
00102         virtual void loadData(FILE *stream, int episodes = -1);
00103         virtual void loadData(FILE *stream);
00104 
00106         virtual int getNumEpisodes();
00107 
00109         virtual void addStateModifier(CStateModifier *modifier);
00111         virtual void removeStateModifier(CStateModifier *modifier);
00112 
00114         virtual CEpisode* getCurrentEpisode();
00115 
00117         virtual CEpisode* getEpisode(int index);
00118 
00120         void clearAutoSaveFile();
00121         
00122         void setLoadDataFile(char *loadData, std::list<CStateModifier *> *modifiers = NULL);
00123 
00125 
00126         virtual void resetData();
00127 };
00128 
00130 
00135 class CEpisodeOutput : public CSemiMDPRewardListener, public CActionObject, public CStateObject
00136 {
00137 protected:
00138         FILE *stream;
00139 
00140         int nEpisodes;
00141         int nSteps;
00142 
00143 public:
00144         CEpisodeOutput(CStateProperties *featCalc, CRewardFunction *rewardFunction, CActionSet *actions, FILE *output); 
00145         virtual ~CEpisodeOutput();
00146 
00147         virtual void nextStep(CStateCollection *oldState, CAction *action, double reward, CStateCollection *nextState);
00148         virtual void intermediateStep(CStateCollection *oldState, CAction *action, double reward, CStateCollection *nextState);
00149         virtual void newEpisode();
00150 };
00151 
00152 class CEpisodeMatlabOutput : public CSemiMDPRewardListener, public CActionObject, public CStateObject
00153 {
00154 protected:
00155         FILE *stream;
00156 
00157         
00158         int nSteps;
00159 
00160 public:
00161         int nEpisodes;
00162         
00163         CEpisodeMatlabOutput(CStateProperties *featCalc, CRewardFunction *rewardFunction, CActionSet *actions, FILE *output); 
00164         virtual ~CEpisodeMatlabOutput();
00165 
00166         virtual void nextStep(CStateCollection *oldState, CAction *action, double reward, CStateCollection *nextState);
00167         virtual void newEpisode();
00168         
00169         void setOutputFile(FILE *stream);
00170 };
00171 
00173 
00176 class CEpisodeOutputStateChanged : public CEpisodeOutput
00177 {
00178 public:
00179         CEpisodeOutputStateChanged(CStateProperties *featCalc, CRewardFunction *rewardFunction, CActionSet *actions, FILE *output); 
00180         virtual ~CEpisodeOutputStateChanged() {};
00181 
00182         virtual void nextStep(CStateCollection *oldState, CAction *action, double reward, CStateCollection *nextState);
00183 };
00184 
00185 class CStateOutput : public CSemiMDPListener, public CStateObject
00186 {
00187 protected:
00188         FILE *stream;
00189 
00190 public:
00191         CStateOutput(CStateProperties *featCalc, FILE *output); 
00192         virtual ~CStateOutput();
00193 
00194         virtual void nextStep(CStateCollection *oldState, CAction *action, CStateCollection *nextState);
00195 };
00196 
00197 class CActionOutput : public CSemiMDPListener, public CActionObject
00198 {
00199 protected:
00200         FILE *stream;
00201 
00202 public:
00203         CActionOutput(CActionSet *actions, FILE *output); 
00204         virtual ~CActionOutput();
00205 
00206         virtual void nextStep(CStateCollection *oldState, CAction *action, CStateCollection *nextState);
00207 };
00208 
00209 #endif