HOG2
MountainCar.h
Go to the documentation of this file.
1 /*
2  * MountainCar.h
3  * hog2
4  *
5  * Created by Nathan Sturtevant on 11/29/10.
6  * Copyright 2010 University of Denver. All rights reserved.
7  *
8  */
9 
10 #ifndef MOUNTAINCAR_H
11 #define MOUNTAINCAR_H
12 
13 #include "SearchEnvironment.h"
14 
16 public:
18  :loc(-0.5), speed(0)
19  {}
20  double loc;
21  double speed;
22 };
23 
24 static bool operator==(const MountainCarState &l1, const MountainCarState &l2) {
25  return fequal(l1.loc, l2.loc) && fequal(l1.speed, l2.speed);
26 }
27 
28 typedef int MountainCarAction;
29 
30 class MountainCarEnvironment : public SearchEnvironment<MountainCarState, MountainCarAction>
31 {
32 public:
34  virtual void GetSuccessors(const MountainCarState &nodeID, std::vector<MountainCarState> &neighbors) const;
35  virtual void GetActions(const MountainCarState &nodeID, std::vector<MountainCarAction> &actions) const;
36  //virtual int GetNumSuccessors(const MountainCarState &stateID) const;
37  virtual MountainCarAction GetAction(const MountainCarState &s1, const MountainCarState &s2) const;
38  virtual void ApplyAction(MountainCarState &s, MountainCarAction a) const;
39 
40  virtual void GetNextState(const MountainCarState &, MountainCarAction , MountainCarState &) const;
41 
42  virtual bool InvertAction(MountainCarAction &a) const;
43 
45  virtual double HCost(const MountainCarState &node1, const MountainCarState &node2) const;
46 
49  virtual double HCost(const MountainCarState &node) const
50  { assert(bValidSearchGoal); return HCost(node, searchGoal); }
51 
52  virtual double GCost(const MountainCarState &node1, const MountainCarState &node2) const;
53  virtual double GCost(const MountainCarState &node, const MountainCarAction &act) const;
54  virtual bool GoalTest(const MountainCarState &node, const MountainCarState &goal) const;
55 
57  virtual bool GoalTest(const MountainCarState &node) const
58  { return bValidSearchGoal&&(node == searchGoal); }
59 
60  virtual uint64_t GetStateHash(const MountainCarState &node) const;
61  virtual uint64_t GetActionHash(MountainCarAction act) const;
62 
63  virtual void OpenGLDraw() const;
64  virtual void OpenGLDraw(const MountainCarState&) const;
65  virtual void OpenGLDraw(const MountainCarState&, const MountainCarState&, float) const;
66  virtual void OpenGLDraw(const MountainCarState&, const MountainCarAction&) const;
67 private:
68  double GetHeightAtPosition(double queryPosition) const;
69  double GetSlope(double queryPosition) const;
70 
71  double minPosition;
72  double maxPosition;
73  double minVelocity;
74  double maxVelocity;
75  double goalPosition;
77  double gravityFactor;
79 };
80 
81 #endif
MountainCarEnvironment::HCost
virtual double HCost(const MountainCarState &node) const
Heuristic value between node and the stored goal.
Definition: MountainCar.h:49
MountainCarState::speed
double speed
Definition: MountainCar.h:21
MountainCarEnvironment::GetAction
virtual MountainCarAction GetAction(const MountainCarState &s1, const MountainCarState &s2) const
Definition: MountainCar.cpp:44
MountainCarState::loc
double loc
Definition: MountainCar.h:20
MountainCarEnvironment::maxPosition
double maxPosition
Definition: MountainCar.h:72
MountainCarEnvironment::GoalTest
virtual bool GoalTest(const MountainCarState &node, const MountainCarState &goal) const
Definition: MountainCar.cpp:114
MountainCarEnvironment::hillPeakFrequency
double hillPeakFrequency
Definition: MountainCar.h:78
operator==
static bool operator==(const MountainCarState &l1, const MountainCarState &l2)
Definition: MountainCar.h:24
MountainCarEnvironment::HCost
virtual double HCost(const MountainCarState &node1, const MountainCarState &node2) const
Heuristic value between two arbitrary nodes.
Definition: MountainCar.cpp:101
MountainCarEnvironment::MountainCarEnvironment
MountainCarEnvironment()
Definition: MountainCar.cpp:13
MountainCarEnvironment::InvertAction
virtual bool InvertAction(MountainCarAction &a) const
Definition: MountainCar.cpp:94
MountainCarEnvironment::GetStateHash
virtual uint64_t GetStateHash(const MountainCarState &node) const
Definition: MountainCar.cpp:119
MountainCarEnvironment::goalPosition
double goalPosition
Definition: MountainCar.h:75
MountainCarEnvironment::GetHeightAtPosition
double GetHeightAtPosition(double queryPosition) const
Definition: MountainCar.cpp:74
MountainCarEnvironment::minPosition
double minPosition
Definition: MountainCar.h:71
loc
Definition: MapGenerators.cpp:296
SearchEnvironment< MountainCarState, MountainCarAction >::searchGoal
MountainCarState searchGoal
Definition: SearchEnvironment.h:113
SearchEnvironment< MountainCarState, MountainCarAction >::bValidSearchGoal
bool bValidSearchGoal
Definition: SearchEnvironment.h:112
MountainCarEnvironment::maxVelocity
double maxVelocity
Definition: MountainCar.h:74
MountainCarEnvironment::minVelocity
double minVelocity
Definition: MountainCar.h:73
MountainCarEnvironment
Definition: MountainCar.h:30
MountainCarEnvironment::ApplyAction
virtual void ApplyAction(MountainCarState &s, MountainCarAction a) const
Definition: MountainCar.cpp:49
MountainCarEnvironment::GetSuccessors
virtual void GetSuccessors(const MountainCarState &nodeID, std::vector< MountainCarState > &neighbors) const
Definition: MountainCar.cpp:25
MountainCarEnvironment::GetActions
virtual void GetActions(const MountainCarState &nodeID, std::vector< MountainCarAction > &actions) const
Definition: MountainCar.cpp:36
MountainCarEnvironment::GoalTest
virtual bool GoalTest(const MountainCarState &node) const
Goal Test if the goal is stored.
Definition: MountainCar.h:57
MountainCarEnvironment::GetActionHash
virtual uint64_t GetActionHash(MountainCarAction act) const
Definition: MountainCar.cpp:124
MountainCarEnvironment::OpenGLDraw
virtual void OpenGLDraw() const
Definition: MountainCar.cpp:129
MountainCarState
Definition: MountainCar.h:15
MountainCarAction
int MountainCarAction
Definition: MountainCar.h:28
MountainCarEnvironment::accelerationFactor
double accelerationFactor
Definition: MountainCar.h:76
MountainCarEnvironment::GCost
virtual double GCost(const MountainCarState &node1, const MountainCarState &node2) const
Definition: MountainCar.cpp:104
MountainCarEnvironment::GetNextState
virtual void GetNextState(const MountainCarState &, MountainCarAction, MountainCarState &) const
Definition: MountainCar.cpp:88
MountainCarState::MountainCarState
MountainCarState()
Definition: MountainCar.h:17
MountainCarEnvironment::GetSlope
double GetSlope(double queryPosition) const
Definition: MountainCar.cpp:79
MountainCarEnvironment::gravityFactor
double gravityFactor
Definition: MountainCar.h:77
fequal
bool fequal(double a, double b, double tolerance=TOLERANCE)
Definition: FPUtil.h:32
SearchEnvironment
Definition: SearchEnvironment.h:30
node
Nodes to be stored within a Graph.
Definition: Graph.h:170
SearchEnvironment.h