-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdomain.hh
100 lines (74 loc) · 2.23 KB
/
domain.hh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
/*
* Code by Chris Mansley
*/
#ifndef DOMAIN_HH
#define DOMAIN_HH
/* Definition dependencies */
#include <vector>
#include <gsl/gsl_rng.h>
#include <gsl/gsl_randist.h>
#include "sars.hh"
#include "state.hh"
#include "action.hh"
class Domain
{
public:
/** Constructor */
Domain()
{
/* Initialize random elements */
rng = gsl_rng_alloc(gsl_rng_taus);
gsl_rng_set(rng, rand());
/* Initialize number of samples */
numSamples = 0;
}
/** Destructor */
virtual ~Domain() { }
/** Simulate an interaction with the environment */
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;
/** Get starting state from domain */
virtual State getInitialState( ) = 0;
/** Get discount factor for domain */
virtual double getDiscountFactor( ) = 0;
/** Get maximum range for action features */
virtual std::vector<double> getMaximumActionRange( ) = 0;
/** Get minimum range for action features */
virtual std::vector<double> getMinimumActionRange( ) = 0;
/** Get maximum range for state features */
virtual std::vector<double> getMaximumStateRange( ) = 0;
/** Get maximum range for state features */
virtual std::vector<double> getMinimumStateRange( ) = 0;
/** Get number of state dimensions */
virtual int getStateDimension( ) = 0;
/** Get number of action dimensions */
virtual int getActionDimension( ) = 0;
/** Get maximum reward */
virtual double getRmax( ) = 0;
/** Get minimum reward */
virtual double getRmin( ) = 0;
/** Set domain parameters */ /* This is ugly? */
virtual void setParam(double d, int i) = 0;
/** Return number of samples */
int getNumSamples() { return numSamples; }
/** Reset number of samples */
void resetSamples() { numSamples = 0; }
protected:
/** For randomness */
gsl_rng *rng;
/** Book-keeping */
int numSamples;
/*
* Note: I have made the conscious decision here to allow the
* compiler to do its thing. This also goes for passing by value,
* which could be force-optimized as follows
*
* State function(const State &s)
*
* instead of
*
* State function(State s)
*/
};
#endif // DOMAIN_HH