5
5
6
6
using namespace std ;
7
7
8
- namespace __gnu_cxx {
9
- template <> class hash <state15_t > {
10
- public:
11
- size_t operator ()( const state15_t &s ) const { return (s.p1_ ^s.p2_ ); }
12
- };
13
- };
14
-
15
- class hash_t : public __gnu_cxx ::hash_map<state15_t , node_t > { }; // class
16
-
17
8
void pdb_gen18 (state15_t state, unsigned *pt1, unsigned *pt2) {
18
9
*pt1 = ZERO; *pt2 = ZERO;
19
10
for (int i = 7 ; i >= ZERO; --i) {
@@ -32,17 +23,6 @@ void pdb_gen915(state15_t state, unsigned *pt1, unsigned *pt2) {
32
23
}
33
24
}
34
25
35
- int construct_initial (char ** input, state15_t *state) {
36
- int nums[NUM_TILES];
37
- for (int i = ZERO; i < NUM_TILES; i++) {
38
- nums[i] = atoi (input[i+1 ]);
39
- if (nums[i] < 0 || nums[i] > 15 )
40
- return (0 );
41
- }
42
- state->set_state (nums);
43
- return (1 );
44
- }
45
-
46
26
int pdb_bfs (state15_t *state, int cost, hash_t *closed) {
47
27
// Insert this state into the pattern database
48
28
unsigned int pt_state1 = ZERO, pt_state2 = ZERO;
@@ -63,27 +43,83 @@ int pdb_bfs(state15_t *state, int cost, hash_t *closed) {
63
43
return (0 );
64
44
}
65
45
66
- void print (unsigned p1_, unsigned p2_) {
67
- unsigned p = p1_;
68
- for ( int i = ZERO; i < NUM_TILES; ++i ) {
69
- cout << std::setw (2 ) << (p&0xF ) << ' ' ;
70
- p = p>>TILE_SIZE;
71
- if ( i%4 == 3 ) cout << endl;
72
- if ( i == 7 ) p = p2_;
46
+ void successors18 (state15_t state, state15_t ** scs, bool * is_important) {
47
+ memset (scs, ZERO, sizeof (scs));
48
+ memset (is_important, ZERO, sizeof (bool ));
49
+
50
+ short as = state.allowed_steps (), k = ZERO;
51
+ for (int i = ZERO; i < BR; i++, as = as >> 1 ) {
52
+ scs[i] = NULL ;
53
+ if (as & 1 == 1 ) {
54
+ // Clone the current state
55
+ state15_t * clone = (state15_t *)malloc (sizeof (state15_t ));
56
+ bool important = false ;
57
+ clone->p1_ = state.p1_ ; clone->p2_ = state.p2_ ;
58
+ if (i == 0 ) {
59
+ is_important[k] = (clone->cont (clone->bpos ()-HSTEP) <= HALF_NUM_TILES ? true : false );
60
+ clone->left ();
61
+ }
62
+ else if (i == 1 ) {
63
+ is_important[k] = (clone->cont (clone->bpos ()+HSTEP) <= HALF_NUM_TILES ? true : false );
64
+ clone->right ();
65
+ }
66
+ else if (i == 2 ) {
67
+ is_important[k] = (clone->cont (clone->bpos ()-VSTEP) <= HALF_NUM_TILES ? true : false );
68
+ clone->up ();
69
+ }
70
+ else if (i == 3 ) {
71
+ is_important[k] = (clone->cont (clone->bpos ()+VSTEP) <= HALF_NUM_TILES ? true : false );
72
+ clone->down ();
73
+ }
74
+ scs[k] = clone; k++;
75
+ }
76
+ }
77
+ }
78
+
79
+ void successors915 (state15_t state, state15_t ** scs, bool *is_important) {
80
+ memset (scs, ZERO, sizeof (scs));
81
+ memset (is_important, ZERO, sizeof (bool ));
82
+
83
+ short as = state.allowed_steps (), k = ZERO;
84
+ for (int i = ZERO; i < BR; i++, as = as >> 1 ) {
85
+ scs[i] = NULL ;
86
+ if (as & 1 == 1 ) {
87
+ // Clone the current state
88
+ state15_t * clone = (state15_t *)malloc (sizeof (state15_t ));
89
+ bool important = false ;
90
+ clone->p1_ = state.p1_ ; clone->p2_ = state.p2_ ;
91
+ if (i == 0 ) {
92
+ is_important[k] = (clone->cont (clone->bpos ()-HSTEP) > HALF_NUM_TILES ? true : false );
93
+ clone->left ();
94
+ }
95
+ else if (i == 1 ) {
96
+ is_important[k] = (clone->cont (clone->bpos ()+HSTEP) > HALF_NUM_TILES ? true : false );
97
+ clone->right ();
98
+ }
99
+ else if (i == 2 ) {
100
+ is_important[k] = (clone->cont (clone->bpos ()-VSTEP) > HALF_NUM_TILES ? true : false );
101
+ clone->up ();
102
+ }
103
+ else if (i == 3 ) {
104
+ is_important[k] = (clone->cont (clone->bpos ()+VSTEP) > HALF_NUM_TILES ? true : false );
105
+ clone->down ();
106
+ }
107
+ scs[k] = clone; k++;
108
+ }
73
109
}
74
110
}
75
111
76
- int main (int argc, char **argv) {
77
- state15_t state;
78
- hash_t closed;
112
+ // int main(int argc, char **argv) {
113
+ // state15_t state;
114
+ // hash_t closed;
79
115
80
- if (!construct_initial (argv, &state)) { std::cout << " Error initializing" << std::endl; return (0 ); }
116
+ // if (!construct_initial(argv, &state)) { std::cout << "Error initializing" << std::endl; return(0); }
81
117
82
- // pdb_bfs(&state, 0, &closed);
83
- unsigned pt1, pt2;
84
- pdb_gen915 (state, &pt1, &pt2);
85
- print (pt1, pt2);
86
- cout << endl << endl;
87
- cout << state;
88
- return (0 );
89
- }
118
+ // //pdb_bfs(&state, 0, &closed);
119
+ // unsigned pt1, pt2;
120
+ // pdb_gen915(state, &pt1, &pt2);
121
+ // print(pt1, pt2);
122
+ // cout << endl << endl;
123
+ // cout << state;
124
+ // return(0);
125
+ // }
0 commit comments