HOG2
ConfigEnvironment.h
Go to the documentation of this file.
1 /*
2  * ConfigEnvironment.h
3  * hog2
4  *
5  * Created by Nathan Sturtevant on 1/9/09.
6  * Copyright 2009 NS Software. All rights reserved.
7  *
8  */
9 
10 #include "GLUtil.h"
11 #include "SearchEnvironment.h"
12 #include <stdlib.h>
13 #include <stdio.h>
14 
15 class ConfigEnvironment : public SearchEnvironment<recVec, line2d>
16 {
17 public:
19  virtual ~ConfigEnvironment();
20 
21  void AddObstacle(line2d obs) { obstacles.push_back(obs); }
22  void PopObstacle() { obstacles.pop_back(); }
23  void GetSuccessors(const recVec &nodeID, std::vector<recVec> &neighbors) const;
24  void GetActions(const recVec &nodeID, std::vector<line2d> &actions) const;
25  line2d GetAction(const recVec &s1, const recVec &s2) const;
26  virtual void ApplyAction(recVec &s, line2d dir) const;
27 
28  virtual bool InvertAction(line2d &a) const;
29 
30  virtual double HCost(const recVec &) const {
31  printf("Single State HCost Failure: method not implemented for ConfigEnvironment\n");
32  exit(0); return -1.0;}
33 
34  virtual double HCost(const recVec &node1, const recVec &node2) const;
35  virtual double GCost(const recVec &node1, const recVec &node2) const;
36  virtual double GCost(const recVec &node1, const line2d &act) const;
37  bool GoalTest(const recVec &node, const recVec &goal) const;
38 
39  bool GoalTest(const recVec &) const {
40  printf("Single State Goal Test Failure: method not implemented for ConfigEnvironment\n");
41  exit(0); return false;}
42 
43  uint64_t GetStateHash(const recVec &node) const;
44  uint64_t GetActionHash(line2d act) const;
45 
46  virtual void OpenGLDraw() const;
47  virtual void OpenGLDraw(const recVec &l) const;
48  virtual void OpenGLDraw(const recVec &, const line2d &) const;
49  virtual void OpenGLDraw(const recVec&, const recVec&, float) const {}
50 
51  virtual void GetNextState(const recVec &currents, line2d dir, recVec &news) const;
52 
53  void StoreGoal(recVec &g) { goal = g; goal_stored = true;} // stores the locations for the given goal state
54  void ClearGoal() {goal_stored = false;}
55  bool IsGoalStored() const {return false;}
56 
57 
58 // bool LegalState(line2d &a);
59 // bool LegalArmConfig(line2d &a);
60 private:
61  bool Legal(const recVec &a, const recVec &b) const;
63  void DrawLine(line2d l) const;
64  std::vector<line2d> obstacles;
65 
67 };
ConfigEnvironment::DrawLine
void DrawLine(line2d l) const
Definition: ConfigEnvironment.cpp:211
ConfigEnvironment
Definition: ConfigEnvironment.h:15
ConfigEnvironment::PopObstacle
void PopObstacle()
Definition: ConfigEnvironment.h:22
recVec
A generic vector (essentially the same as a point, but offers normalization)
Definition: GLUtil.h:78
ConfigEnvironment::HCost
virtual double HCost(const recVec &) const
Heuristic value between node and the stored goal.
Definition: ConfigEnvironment.h:30
ConfigEnvironment::goal_stored
bool goal_stored
Definition: ConfigEnvironment.h:66
ConfigEnvironment::GetStateHash
uint64_t GetStateHash(const recVec &node) const
Definition: ConfigEnvironment.cpp:159
ConfigEnvironment::AddObstacle
void AddObstacle(line2d obs)
Definition: ConfigEnvironment.h:21
ConfigEnvironment::obstacles
std::vector< line2d > obstacles
Definition: ConfigEnvironment.h:64
ConfigEnvironment::GetSuccessors
void GetSuccessors(const recVec &nodeID, std::vector< recVec > &neighbors) const
Definition: ConfigEnvironment.cpp:24
ConfigEnvironment::goal
recVec goal
Definition: ConfigEnvironment.h:62
line2d
‍**
Definition: GLUtil.h:155
ConfigEnvironment::GCost
virtual double GCost(const recVec &node1, const recVec &node2) const
Definition: ConfigEnvironment.cpp:140
GLUtil.h
ConfigEnvironment::~ConfigEnvironment
virtual ~ConfigEnvironment()
Definition: ConfigEnvironment.cpp:20
ConfigEnvironment::GoalTest
bool GoalTest(const recVec &node, const recVec &goal) const
Definition: ConfigEnvironment.cpp:154
ConfigEnvironment::ApplyAction
virtual void ApplyAction(recVec &s, line2d dir) const
Definition: ConfigEnvironment.cpp:118
ConfigEnvironment::GoalTest
bool GoalTest(const recVec &) const
Goal Test if the goal is stored.
Definition: ConfigEnvironment.h:39
ConfigEnvironment::ClearGoal
void ClearGoal()
Clears the goal from memory.
Definition: ConfigEnvironment.h:54
ConfigEnvironment::StoreGoal
void StoreGoal(recVec &g)
Stores the goal for use by single-state HCost.
Definition: ConfigEnvironment.h:53
ConfigEnvironment::GetActionHash
uint64_t GetActionHash(line2d act) const
Definition: ConfigEnvironment.cpp:173
ConfigEnvironment::OpenGLDraw
virtual void OpenGLDraw() const
Definition: ConfigEnvironment.cpp:179
ConfigEnvironment::IsGoalStored
bool IsGoalStored() const
Definition: ConfigEnvironment.h:55
ConfigEnvironment::GetActions
void GetActions(const recVec &nodeID, std::vector< line2d > &actions) const
Definition: ConfigEnvironment.cpp:69
ConfigEnvironment::Legal
bool Legal(const recVec &a, const recVec &b) const
Definition: ConfigEnvironment.cpp:89
ConfigEnvironment::InvertAction
virtual bool InvertAction(line2d &a) const
Definition: ConfigEnvironment.cpp:124
ConfigEnvironment::GetAction
line2d GetAction(const recVec &s1, const recVec &s2) const
Definition: ConfigEnvironment.cpp:110
ConfigEnvironment::OpenGLDraw
virtual void OpenGLDraw(const recVec &, const recVec &, float) const
Draw the transition at some percentage 0...1 between two states.
Definition: ConfigEnvironment.h:49
SearchEnvironment
Definition: SearchEnvironment.h:30
node
Nodes to be stored within a Graph.
Definition: Graph.h:170
SearchEnvironment.h
ConfigEnvironment::GetNextState
virtual void GetNextState(const recVec &currents, line2d dir, recVec &news) const
Definition: ConfigEnvironment.cpp:206
ConfigEnvironment::ConfigEnvironment
ConfigEnvironment()
Definition: ConfigEnvironment.cpp:15