-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathccl.cc
66 lines (54 loc) · 1.07 KB
/
ccl.cc
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
/* Implementation dependencies */
#include <iostream>
#include <algorithm>
#include <cmath>
#include <gsl/gsl_rng.h>
#include <gsl/gsl_randist.h>
#include "ccl.hh"
/*!
*
*/
CCL::CCL(double gamma)
{
/* Initialize our initial state */
initialState.resize(stateDimension);
std::fill(initialState.begin(), initialState.end(), 0.0);
/* Create max and min range */
maxRange.resize(stateDimension);
minRange.resize(stateDimension);
maxRange[0] = 1;
minRange[0] = 0;
/* Initialize gamma */
this->gamma = gamma;
}
/*!
*
*/
SARS *CCL::simulate(State s, Action a)
{
//bookkeeping
return step(s, a);
}
/*!
*
*/
SARS *CCL::step(State s, Action a)
{
SARS *sars = new SARS(stateDimension, actionDimension);
sars->s = s;
sars->a = a;
sars->reward = -1.0;
/* Perform action */
if(sars->a[0] == 0) {
sars->s_prime[0] = 0.0;
} else {
sars->s_prime[0] = s[0] + 0.02 + gsl_ran_gaussian(rng, 0.005);
}
/* Check reward */
if(sars->s_prime[0] > 0.98) {
sars->terminal = true;
} else {
sars->terminal = false;
}
return sars;
}