forked from bonetblai/mini-gpt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
planners.h
178 lines (149 loc) · 4.51 KB
/
planners.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
#ifndef PLANNERS_H
#define PLANNERS_H
#include "algorithms.h"
#include "actions.h"
#include <iostream>
class problem_t;
class hash_t;
class heuristic_t;
/*******************************************************************************
*
* planner (abstract class)
*
******************************************************************************/
class planner_t
{
protected:
const problem_t &problem_;
heuristic_t &heur_;
hash_t *hash_table_;
algorithm_t *algorithm_;
public:
planner_t( const problem_t &problem, heuristic_t &heur )
: problem_(problem), heur_(heur), hash_table_(0), algorithm_(0) { }
virtual ~planner_t() { }
enum { VI, LRTDP, ASP, HDPZJ };
virtual void initRound( void ) { }
virtual void endRound( void ) { }
virtual const action_t* decideAction( const state_t &state )
{
return( algorithm_->next( state ) );
}
bool dead_end( const state_t &state ) const
{
if( hash_table_ == 0 )
return( false );
else {
hashEntry_t *entry = hash_table_->get( state );
return( entry->value() == gpt::dead_end_value );
}
}
void print( std::ostream &os, const action_t &action ) const
{
action.print( os );
}
virtual void statistics( std::ostream &os, int level ) const = 0;
};
/*******************************************************************************
*
* planner RANDOM
*
******************************************************************************/
class plannerRANDOM_t : public planner_t
{
public:
plannerRANDOM_t( const problem_t &problem, heuristic_t &heur )
: planner_t(problem,heur)
{
algorithm_ = new random_t( problem );
}
virtual ~plannerRANDOM_t()
{
delete algorithm_;
}
virtual void statistics( std::ostream &os, int level ) const { }
};
/*******************************************************************************
*
* planner VI
*
******************************************************************************/
class plannerVI_t : public planner_t
{
public:
plannerVI_t( const problem_t &problem, heuristic_t &heur, double epsilon );
virtual ~plannerVI_t();
virtual void statistics( std::ostream &os, int level ) const;
};
/*******************************************************************************
*
* planner LRTDP
*
******************************************************************************/
class plannerLRTDP_t : public planner_t
{
public:
plannerLRTDP_t( const problem_t &problem, heuristic_t &heur, double epsilon );
virtual ~plannerLRTDP_t();
virtual void statistics( std::ostream &os, int level ) const;
};
/*******************************************************************************
*
* planner ASP
*
******************************************************************************/
class plannerASP_t : public planner_t
{
public:
plannerASP_t( const problem_t &problem, heuristic_t &heur, int simulations );
virtual ~plannerASP_t();
virtual void statistics( std::ostream &os, int level ) const;
};
/*******************************************************************************
*
* planner HDP(0,j)
*
******************************************************************************/
class plannerHDPZJ_t : public planner_t
{
unsigned J_;
unsigned kappa_;
hashEntryX_t *last_state_;
const action_t *last_action_;
hdpzj_t *hdp_algorithm_;
public:
plannerHDPZJ_t( const problem_t &problem, heuristic_t &heur, double epsilon, int J );
virtual ~plannerHDPZJ_t();
virtual void initRound( void ) { last_state_ = 0; last_action_ = 0; }
virtual const action_t* decideAction( const state_t &state )
{
// update kappa cost
if( !last_action_ )
kappa_ = 0;
else
kappa_ += hdp_algorithm_->transition_kappa( *last_state_->state(), *last_action_, state );
last_state_ = hdp_algorithm_->get( state );
if( gpt::verbosity >= 200 )
{
std::cout << "<hdp(0," << J_ << ")>: ";
state.print( std::cout );
std::cout << ": kappa cost = " << kappa_
<< ", bits = " << last_state_->bits() << std::endl;
}
if( !last_action_ || (!(last_state_->bits() & hdpzj_t::MARK) && (kappa_ >= J_)) )
{
if( gpt::verbosity >= 150 )
{
std::cout << "<hdp(0," << J_ << ")>: replanning for state ";
state.print( std::cout );
std::cout << std::endl;
}
hdp_algorithm_->solve( last_state_ );
kappa_ = 0;
}
last_action_ = hdp_algorithm_->next( state );
return( last_action_ );
}
virtual void statistics( std::ostream &os, int level ) const;
};
#endif // PLANNERS_H