41 #ifndef SHARK_OBJECTIVEFUNCTIONS_BENCHMARKS_POLE_SUTTON_ANDERSON 42 #define SHARK_OBJECTIVEFUNCTIONS_BENCHMARKS_POLE_SUTTON_ANDERSON 55 return x * M_PI / 180;
68 this->m_isMarkov = markovian;
74 this->m_normal_cart = 4.8;
75 this->m_normal_pole = 0.52;
76 this->m_normal_velo = 2;
79 this->m_normal_cart = 1.;
80 this->m_normal_pole = 1.;
81 this->m_normal_velo = 1.;
88 init(state2init * M_PI / 180);
94 void init(
double state2init = 0.07) {
95 m_state[0] = m_state[1] = m_state[3] = 0.0;
96 m_state[2] = state2init;
104 void init(
double a,
double b,
double c,
double d) {
116 v(0) = m_state[0] / m_normal_cart;
117 v(1) = m_state[1] / m_normal_velo;
118 v(2) = m_state[2] / m_normal_pole;
119 v(3) = m_state[3] / m_normal_velo;
122 v(0) = m_state[0] / m_normal_cart;
123 v(1) = m_state[2] / m_normal_pole;
129 const double twelve_degrees =
degrad(12);
130 if (m_state[0] < -2.4 || m_state[0] > 2.4 || m_state[2] < -twelve_degrees ||
131 m_state[2] > twelve_degrees)
return true;
143 for(
int i = 0; i < 2; i++) {
144 dydx[0] = m_state[1];
145 dydx[2] = m_state[3];
146 step(output,m_state,dydx);
147 rk4(output,m_state,dydx,m_state);
152 void step(
double output,
double *st,
double *derivs) {
154 const double MUP = 0.0;
155 const double GRAVITY = -9.8;
156 const double MASSCART = 1.0;
157 const double MASSPOLE = 0.1;
158 const double LENGTH = 0.5;
159 const double FORCE_MAG = 10.0;
161 double force = (output -0.5) * FORCE_MAG * 2;
162 double costheta = cos(st[2]);
163 double sintheta = sin(st[2]);
164 double gsintheta = GRAVITY * sintheta;
166 double ml = LENGTH * MASSPOLE;
167 double temp = MUP * st[3] / ml;
168 double fi = (ml * st[3] * st[3] * sintheta) + (0.75 * MASSPOLE * costheta * (temp + gsintheta));
169 double mi = MASSPOLE * (1 - (0.75 * costheta * costheta));
171 derivs[1] = (force + fi) / (mi + MASSCART);
173 derivs[3] = -0.75 * (derivs[1] * costheta + gsintheta + temp) / LENGTH;
176 void rk4(
double f,
double y[],
double dydx[],
double yout[]) {
177 const double TAU = 0.01;
179 double dym[4],dyt[4],yt[4];
183 for (
int i = 0; i <= 3; i++) {
184 yt[i] = y[i]+hh*dydx[i];
189 for (
int i = 0; i <= 3; i++) {
190 yt[i] = y[i]+hh*dyt[i];
195 for (
int i = 0; i <= 3; i++) {
196 yt[i] = y[i] + TAU * dym[i];
202 for (
int i = 0; i <= 3; i++) {
203 yout[i] = y[i]+h6*(dydx[i]+dyt[i]+2.0*dym[i]);
209 double m_normal_cart;
210 double m_normal_pole;
211 double m_normal_velo;