Skip to content

Commit

Permalink
Added basic logging capability to bicycle domain
Browse files Browse the repository at this point in the history
  • Loading branch information
cmansley committed Nov 15, 2010
1 parent bca97c3 commit 5e30a6b
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 4 deletions.
7 changes: 5 additions & 2 deletions Makefile
Expand Up @@ -2,8 +2,8 @@ CFLAGS=-Wall -g #-pg
INCLUDES=-I/home/cmansley/boost_1_41_0 #-I /koko/rl3/cmansley/boost_1_41_0 -I/koko/rl3/cmansley/local/include
LIBS= #-L/koko/rl3/cmansley/local/lib

plan: main.o ccl.o ss.o ip.o uct.o lander.o hoo.o node.o gaussian.o hoot.o mcplanner.o chopper.o di.o lqr.o ddi.o bicycle.o
g++ $(CFLAGS) -o plan main.o ccl.o ss.o ip.o uct.o lander.o hoo.o node.o hoot.o mcplanner.o chopper.o di.o lqr.o ddi.o bicycle.o $(LIBS) -lgsl -lgslcblas -lm -lgflags
plan: main.o ccl.o ss.o ip.o uct.o lander.o hoo.o node.o gaussian.o hoot.o mcplanner.o chopper.o di.o lqr.o ddi.o bicycle.o sars.o
g++ $(CFLAGS) -o plan main.o ccl.o ss.o ip.o uct.o lander.o hoo.o node.o hoot.o mcplanner.o chopper.o di.o lqr.o ddi.o bicycle.o sars.o $(LIBS) -lgsl -lgslcblas -lm -lgflags

temp: temp.o gaussian.o hoo.o node.o chopper.o ip.o ddi.o
g++ $(CFLAGS) -o temp temp.o gaussian.o hoo.o node.o ip.o chopper.o ddi.o -lgsl -lgslcblas -lm
Expand Down Expand Up @@ -59,5 +59,8 @@ lqr.o: lqr.cc lqr.hh
bicycle.o: bicycle.cc bicycle.hh
g++ -c $(CFLAGS) bicycle.cc $(INCLUDES)

sars.o: sars.cc sars.hh
g++ -c $(CFLAGS) sars.cc $(INCLUDES)

clean:
rm -f *~ *.o plan temp
3 changes: 3 additions & 0 deletions bicycle.cc
Expand Up @@ -62,6 +62,9 @@ Bicycle::Bicycle(double gamma) : stateDimension(5), actionDimension(2)

/* Initialize gamma */
this->gamma = gamma;

/* Open logfile */
logfile.open("log.txt");
}

/*!
Expand Down
20 changes: 19 additions & 1 deletion bicycle.hh
Expand Up @@ -19,7 +19,22 @@ public:
Bicycle(double gamma);

/** Destructor */
~Bicycle() { }
~Bicycle() { logfile.close(); }

/** Simulate an interaction with the environment */
SARS *simulate(State s, Action a)
{
/* Simulate step */
SARS *sars = step(s,a);

/* Track samples */
numSamples++;

/* Log samples */
logfile << *sars << std::endl;

return sars;
}

/** Perform an interaction with the environment */
SARS *step(State s, Action a);
Expand Down Expand Up @@ -74,6 +89,9 @@ private:
/** Domain Properties */
double gamma;

/** Logging */
std::ofstream logfile;

/** Domain Specific */
static const double dt;
double noise;
Expand Down
2 changes: 1 addition & 1 deletion domain.hh
Expand Up @@ -33,7 +33,7 @@ public:
virtual ~Domain() { }

/** Simulate an interaction with the environment */
SARS *simulate(State s, Action a) { numSamples++; return step(s,a); }
virtual SARS *simulate(State s, Action a) { numSamples++; return step(s,a); }

/** Perform an interaction with the environment */
virtual SARS *step(State s, Action a) = 0;
Expand Down
33 changes: 33 additions & 0 deletions sars.cc
@@ -0,0 +1,33 @@
/*
* Code by Chris Mansley
*/
#include "sars.hh"

/*!
* Output operator for the SARS class
*/
std::ostream& operator<<(std::ostream &out, const SARS &sars)
{
/* Print state */
for(State::const_iterator it = sars.s.begin(); it != sars.s.end(); ++it) {
out << *it << ",";
}

/* Print action */
for(Action::const_iterator it = sars.a.begin(); it != sars.a.end(); ++it) {
out << *it << ",";
}

/* Print reward */
out << sars.reward << ",";

/* Print next state */
for(State::const_iterator it = sars.s_prime.begin(); it != sars.s_prime.end(); ++it) {
out << *it << ",";
}

/* Print out terminal */
out << sars.terminal;

return out;
}
3 changes: 3 additions & 0 deletions sars.hh
Expand Up @@ -7,6 +7,7 @@

/* Definition dependencies */
#include <string>
#include <fstream>

#include "state.hh"
#include "action.hh"
Expand Down Expand Up @@ -35,6 +36,8 @@ public:
/** Is this a terminal state */
bool terminal;

/** Overload output operator */
friend std::ostream& operator<<(std::ostream &out, const SARS &sars);
};

#endif //SARS_HH

0 comments on commit 5e30a6b

Please sign in to comment.