HOG2
TopSpinGraph.h
Go to the documentation of this file.
1 /*
2  * TopSpinGraph.h
3  * hog2
4  *
5  * Created by Nathan Sturtevant on 4/1/08.
6  * Copyright 2008 __MyCompanyName__. All rights reserved.
7  *
8  */
9 
10 //#include <unordered_map>
11 #include "GraphEnvironment.h"
12 
13 //#include "ts.h"
14 #ifndef TopSpinGraph_H
15 #define TopSpinGraph_H
16 
17 class TopSpinGraph;
18 
20 public:
21  TopSpinGraphHeuristic(int psize, int spin, int pdb);
23  Graph *GetGraph() { return 0; }
24  void SetState(TopSpinGraph *tss) { ts = tss; }
25  virtual ~TopSpinGraphHeuristic() { }
26  virtual double HCost(const graphState &state1, const graphState &state2) const;
27 
28  static int THmode;
29 private:
31  int pdb;
32  std::vector<uint8_t> DB;
33 };
34 
36 public:
37  bool expanded;
38  unsigned long hashKey;
39  std::vector<int> config;
40  //int zeroLoc; // get rid of this & just normalize
41 };
42 
44 public:
45  TopSpinGraph(int m, int k, TopSpinGraphHeuristic *tsh);
46  TopSpinGraph(int m, int k);
47  ~TopSpinGraph();
48  void GetSuccessors(const graphState &stateID, std::vector<graphState> &neighbors) const;
49  void GetActions(const graphState &stateID, std::vector<graphMove> &actions) const;
50  bool GoalTest(const graphState &state, const graphState &goal) const;
51  virtual bool GoalTest(graphState &) const { assert(false); return false; }
52 
54  graphState GetState(const std::vector<int> &configuration) const;
55  graphState GetState(const std::vector<int> &configuration, int zeroLoc) const;
56  std::vector<int> &GetState(graphState g) const;
57 
58  uint64_t GetStateHash(const graphState &state) const;
59  uint64_t GetStateHash(const std::vector<int> &config) const;
60  uint64_t GetStateHash(const int *config, int config_size) const;
61  uint64_t GetPDBHash(const std::vector<int> &config, int pdb_size) const;
62  uint64_t GetPDBHash(const graphState &state, int pdb_size) const;
63  uint64_t GetPDBSize(int puzzle_size, int pdb_size) const;
64 private:
65  typedef std::unordered_map<uint64_t, unsigned long, Hash64> TopSpinHashTable;
66 
67  void ExpandNode(const graphState &stateID) const;
68  void Flip(std::vector<int> &arrangement, int index, int radius) const;
69  // these store the actual graph of the state space
70  mutable Graph *g2;
72  mutable std::vector<TopSpinGraphData> data;
74 };
75 
76 #endif
TopSpinGraphHeuristic
Definition: TopSpinGraph.h:19
TopSpinGraph::GetStateHash
uint64_t GetStateHash(const graphState &state) const
Definition: TopSpinGraph.cpp:142
TopSpinGraph::hashTable
TopSpinHashTable hashTable
Definition: TopSpinGraph.h:71
TopSpinGraphHeuristic::HCost
virtual double HCost(const graphState &state1, const graphState &state2) const
Definition: TopSpinGraph.cpp:274
TopSpinGraphHeuristic::SetState
void SetState(TopSpinGraph *tss)
Definition: TopSpinGraph.h:24
graphState
unsigned long graphState
Definition: GraphEnvironment.h:32
TopSpinGraphData::expanded
bool expanded
Definition: TopSpinGraph.h:37
TopSpinGraph::flipSize
int flipSize
Definition: TopSpinGraph.h:73
TopSpinGraphHeuristic::pdb
int pdb
Definition: TopSpinGraph.h:31
TopSpinGraph::GetPDBSize
uint64_t GetPDBSize(int puzzle_size, int pdb_size) const
Definition: TopSpinGraph.cpp:238
TopSpinGraph::Dual
graphState Dual(graphState s)
Definition: TopSpinGraph.cpp:149
GraphEnvironment::m
Map * m
Definition: GraphEnvironment.h:359
TopSpinGraphHeuristic::DB
std::vector< uint8_t > DB
Definition: TopSpinGraph.h:32
Graph
A generic Graph class.
Definition: Graph.h:66
GraphEnvironment::g
Graph * g
Definition: GraphEnvironment.h:360
TopSpinGraph::length
int length
Definition: TopSpinGraph.h:73
TopSpinGraphHeuristic::ts
TopSpinGraph * ts
Definition: TopSpinGraph.h:30
TopSpinGraph::GetPDBHash
uint64_t GetPDBHash(const std::vector< int > &config, int pdb_size) const
Definition: TopSpinGraph.cpp:206
TopSpinGraphHeuristic::GetGraph
Graph * GetGraph()
Definition: TopSpinGraph.h:23
TopSpinGraphData::hashKey
unsigned long hashKey
Definition: TopSpinGraph.h:38
TopSpinGraphData
Definition: TopSpinGraph.h:35
TopSpinGraph::data
std::vector< TopSpinGraphData > data
Definition: TopSpinGraph.h:72
TopSpinGraphHeuristic::~TopSpinGraphHeuristic
virtual ~TopSpinGraphHeuristic()
Definition: TopSpinGraph.h:25
TopSpinGraph::ExpandNode
void ExpandNode(const graphState &stateID) const
Definition: TopSpinGraph.cpp:113
TopSpinGraphHeuristic::TopSpinGraphHeuristic
TopSpinGraphHeuristic()
Definition: TopSpinGraph.cpp:251
TopSpinGraph::~TopSpinGraph
~TopSpinGraph()
Definition: TopSpinGraph.cpp:41
TopSpinGraph::TopSpinHashTable
std::unordered_map< uint64_t, unsigned long, Hash64 > TopSpinHashTable
Definition: TopSpinGraph.h:65
TopSpinGraph::GoalTest
virtual bool GoalTest(graphState &) const
Definition: TopSpinGraph.h:51
TopSpinGraph::GetState
graphState GetState(const std::vector< int > &configuration) const
Definition: TopSpinGraph.cpp:75
TopSpinGraph::TopSpinGraph
TopSpinGraph(int m, int k, TopSpinGraphHeuristic *tsh)
Definition: TopSpinGraph.cpp:15
TopSpinGraph::GoalTest
bool GoalTest(const graphState &state, const graphState &goal) const
Definition: TopSpinGraph.cpp:65
TopSpinGraph::Flip
void Flip(std::vector< int > &arrangement, int index, int radius) const
Definition: TopSpinGraph.cpp:129
TopSpinGraphHeuristic::THmode
static int THmode
Definition: TopSpinGraph.h:28
TopSpinGraph
Definition: TopSpinGraph.h:43
TopSpinGraphData::config
std::vector< int > config
Definition: TopSpinGraph.h:39
TopSpinGraph::g2
Graph * g2
Definition: TopSpinGraph.h:70
GraphEnvironment
Definition: GraphEnvironment.h:291
TopSpinGraph::GetSuccessors
void GetSuccessors(const graphState &stateID, std::vector< graphState > &neighbors) const
Definition: TopSpinGraph.cpp:45
GraphHeuristic
Definition: GraphEnvironment.h:77
GraphEnvironment.h
TopSpinGraph::GetActions
void GetActions(const graphState &stateID, std::vector< graphMove > &actions) const
Definition: TopSpinGraph.cpp:55