HOG2
NQueens.h
Go to the documentation of this file.
1 //
2 // NQueens.h
3 // hog2 glut
4 //
5 // Created by Nathan Sturtevant on 9/18/11.
6 // Copyright 2011 University of Denver. All rights reserved.
7 //
8 
9 #ifndef NQUEENS_H
10 #define NQUEENS_H
11 
12 #include "SearchEnvironment.h"
13 #include "FPUtil.h"
14 #include <vector>
15 
17 {
18 public:
19  NQueenState(int numQueens = 8)
20  {
21  locs.resize(numQueens);
22  for (int x = 0; x < numQueens; x++)
23  locs[x] = random()%numQueens;
24  }
25  std::vector<int> locs;
26 };
27 
28 static bool operator==(const NQueenState &l1, const NQueenState &l2)
29 {
30  if (l1.locs.size() != l2.locs.size())
31  return false;
32 
33  for (unsigned int x = 0; x < l1.locs.size(); x++)
34  if (l1.locs[x] != l2.locs[x])
35  return false;
36  return true;
37 }
38 
39 
41 {
42 public:
43  int loc, value;
44 };
45 
46 static std::ostream &operator<<(std::ostream &out, const NQueenAction &a)
47 {
48  out << "(" << a.loc << ": " << a.value << ")";
49  return out;
50 }
51 
52 class NQueens : public SearchEnvironment<NQueenState, NQueenAction>
53 {
54 public:
55  NQueens() { }
56  ~NQueens() {}
57  virtual void GetSuccessors(const NQueenState &nodeID, std::vector<NQueenState> &neighbors) const;
58  virtual void GetActions(const NQueenState &nodeID, std::vector<NQueenAction> &actions) const;
59  //virtual int GetNumSuccessors(const NQueenState &stateID) const;
60  virtual NQueenAction GetAction(const NQueenState &s1, const NQueenState &s2) const;
61  virtual void ApplyAction(NQueenState &s, NQueenAction a) const;
62 
63  virtual void GetNextState(const NQueenState &, NQueenAction , NQueenState &) const;
64 
65  virtual bool InvertAction(NQueenAction &a) const { return false; }
66 
68  virtual double HCost(const NQueenState &node1, const NQueenState &node2) const { return 0; }
69 
72  virtual double HCost(const NQueenState &node) const
73  { return 0; }
74 
75  virtual double GCost(const NQueenState &node1, const NQueenState &node2) const { return 1.0; }
76  virtual double GCost(const NQueenState &node, const NQueenAction &act) const { return 1.0; }
77  virtual bool GoalTest(const NQueenState &node, const NQueenState &goal) const { return GoalTest(node); }
78 
80  virtual bool GoalTest(const NQueenState &node) const;
81 
82  virtual uint64_t GetStateHash(const NQueenState &node) const { return 0; }
83  virtual uint64_t GetActionHash(NQueenAction act) const { return 0; }
84 
85  int NumCollisions(const NQueenState &node) const;
86  int NumCollisions(const NQueenState &node, int row) const;
87  int NumCollisions(const NQueenState &node, int row, int column) const;
88 
89  //virtual double GetPathLength(std::vector<NQueenState> &neighbors);
90 
91  virtual void OpenGLDraw() const;
92  virtual void OpenGLDraw(const NQueenState&) const;
94  virtual void OpenGLDraw(const NQueenState&, const NQueenState&, float) const;
95  virtual void OpenGLDraw(const NQueenState&, const NQueenAction&) const;
96  void GLLabelState(const NQueenState &s, int x, int y, int number) const;
97 
98  void OpenGLDrawBackground(float r, float g, float b);
99  void OpenGLDrawBackground(const NQueenState&, float r, float g, float b, int firstRow, int lastRow);
100  void OpenGLDrawConflicts(const NQueenState&s) const;
101 
102 private:
103 };
104 
105 #endif
operator==
static bool operator==(const NQueenState &l1, const NQueenState &l2)
Definition: NQueens.h:28
NQueens::GetActionHash
virtual uint64_t GetActionHash(NQueenAction act) const
Definition: NQueens.h:83
NQueens::GetSuccessors
virtual void GetSuccessors(const NQueenState &nodeID, std::vector< NQueenState > &neighbors) const
Definition: NQueens.cpp:12
NQueens::GCost
virtual double GCost(const NQueenState &node, const NQueenAction &act) const
Definition: NQueens.h:76
NQueenAction
Definition: NQueens.h:40
FPUtil.h
NQueens::HCost
virtual double HCost(const NQueenState &node1, const NQueenState &node2) const
Heuristic value between two arbitrary nodes.
Definition: NQueens.h:68
NQueens
Definition: NQueens.h:52
NQueenState::NQueenState
NQueenState(int numQueens=8)
Definition: NQueens.h:19
NQueens::ApplyAction
virtual void ApplyAction(NQueenState &s, NQueenAction a) const
Definition: NQueens.cpp:42
NQueens::GCost
virtual double GCost(const NQueenState &node1, const NQueenState &node2) const
Definition: NQueens.h:75
NQueenState
Definition: NQueens.h:16
NQueens::GetStateHash
virtual uint64_t GetStateHash(const NQueenState &node) const
Definition: NQueens.h:82
NQueens::HCost
virtual double HCost(const NQueenState &node) const
Heuristic value between node and the stored goal.
Definition: NQueens.h:72
NQueens::InvertAction
virtual bool InvertAction(NQueenAction &a) const
Definition: NQueens.h:65
NQueens::OpenGLDrawBackground
void OpenGLDrawBackground(float r, float g, float b)
Definition: NQueens.cpp:216
NQueens::GoalTest
virtual bool GoalTest(const NQueenState &node, const NQueenState &goal) const
Definition: NQueens.h:77
NQueens::OpenGLDraw
virtual void OpenGLDraw() const
Definition: NQueens.cpp:211
NQueens::NQueens
NQueens()
Definition: NQueens.h:55
NQueenState::locs
std::vector< int > locs
Definition: NQueens.h:25
NQueens::GetNextState
virtual void GetNextState(const NQueenState &, NQueenAction, NQueenState &) const
Definition: NQueens.cpp:47
NQueens::GetActions
virtual void GetActions(const NQueenState &nodeID, std::vector< NQueenAction > &actions) const
Definition: NQueens.cpp:17
operator<<
static std::ostream & operator<<(std::ostream &out, const NQueenAction &a)
Definition: NQueens.h:46
NQueens::~NQueens
~NQueens()
Definition: NQueens.h:56
NQueens::NumCollisions
int NumCollisions(const NQueenState &node) const
Definition: NQueens.cpp:172
NQueenAction::value
int value
Definition: NQueens.h:43
NQueens::GLLabelState
void GLLabelState(const NQueenState &s, int x, int y, int number) const
Definition: NQueens.cpp:343
NQueens::OpenGLDrawConflicts
void OpenGLDrawConflicts(const NQueenState &s) const
Definition: NQueens.cpp:325
SearchEnvironment
Definition: SearchEnvironment.h:30
NQueens::GetAction
virtual NQueenAction GetAction(const NQueenState &s1, const NQueenState &s2) const
Definition: NQueens.cpp:35
NQueenAction::loc
int loc
Definition: NQueens.h:43
node
Nodes to be stored within a Graph.
Definition: Graph.h:170
SearchEnvironment.h