summaryrefslogtreecommitdiff
path: root/SA_POP/SA_PlanStrategy.h
blob: 61969a7ae8fe63444a4929cb89f6bd8720dee5a1 (plain)
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
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
// -*- C++ -*-
// $Id$

//=============================================================================
/**
 * @file  SA_PlanStrategy.h
 *
 * This file contains the definition of the SA_PlanStrategy concrete class,
 * which implements a PlanStrategy for use with spreading activation networks
 * and precedence graphs.
 *
 * @author  John S. Kinnebrew <john.s.kinnebrew@vanderbilt.edu>
 */
//=============================================================================

#ifndef SA_POP_SA_PLAN_STRATEGY_H_
#define SA_POP_SA_PLAN_STRATEGY_H_

#include <set>
#include "SA_POP_Types.h"
#include "PlanStrategy.h"
#include "PlanHeuristics.h"
#include "PlanCommands.h"
#include "SA_PlanCommands.h"

namespace SA_POP {

  /**
   * @class SA_PlanStrategy
   *
   * @brief PlanStrategy concrete class for the high-level
   *        planning/scheduling algorithm for use with spreading activation
   *        networks and precedence graphs.
   */
  class SA_PlanStrategy : public PlanStrategy {
  public:
    /// Constructor.
    /**
     * @param planner  Planner object to use.
     *
     * @param cond_choice  Strategy for choosing open condition to satisfy.
     *
     * @param task_choice  Strategy for choosing/ordering tasks to satisfy
     *                     an open condition.
     *
     * @param impl_choice  Strategy for choosing an implementation of a task.
     */
    SA_PlanStrategy (SA_POP::Planner *planner, CondStrategy *cond_choice,
      TaskStrategy *task_choice, ImplStrategy *impl_choice);

    /// Destructor.
    virtual ~SA_PlanStrategy (void);

    /// Set command prototypes to use in planning.
    /**
     * @param assoc_impl_cmd  Prototype of command for associating an
     *                        implementation with a task instance in the plan.
     *
     * @param add_task_cmd  Prototype of command for adding a task to the plan.
     *
     * @param resolve_threat_cmd  Prototype of command for resolving causal
     *                            link threats.
     */
    virtual void set_commands (AddTaskCmd *add_task_cmd,
      AssocTaskImplCmd *assoc_impl_cmd,
      ResolveCLThreatCmd *resolve_threat_cmd);



    // ************************************************************************
    // Planning methods.
    // ************************************************************************

    /// Set goals.
    /**
     * @param goals  Set of goals and associated utilities.
     */
    virtual void set_goals (GoalMap goals);

    /// Get command ID to use for next command.
    /**
     * @return  Command ID to use for next command.
     */
    virtual CommandID get_next_cmd_id (void);

    /// Recursively satisfy all open conditions (including recursive
    /// scheduling constraint satisfaction through call back).
    /**
     * @return  True if all open conditions were satisfied, false otherwise.
     */
    virtual bool satisfy_open_conds (void);


    // ************************************************************************
    // Methods for obtaining prototypes of commands that work on this strategy.
    // ************************************************************************

    /// Get a PlanCommand prototype for adding open conditions,
    /// which works on this strategy.
    /**
     * @return  An AddOpenCondsCmd prototype for this strategy.
     */
    virtual AddOpenCondsCmd *get_AddOpenCondsCmd (void);

    /// Get a PlanCommand prototype for removing open conditions,
    /// which works on this strategy.
    /**
     * @return  A RemoveOpenCondsCmd prototype for this strategy.
     */
    virtual RemoveOpenCondsCmd *get_RemoveOpenCondsCmd (void);

    /// Get an command prototype for adding causal link threats, which works on
    /// this strategy.
    /**
     * @return  An AddOpenThreatsCmd prototype for this strategy.
     */
    virtual AddOpenThreatsCmd *get_AddOpenThreatsCmd (void);

    /// Get a PlanCommand prototype for removing causal link threats,
    /// which works on this strategy.
    /**
     * @return  A RemoveOpenThreatsCmd prototype for this strategy.
     */
    virtual RemoveOpenThreatsCmd *get_RemoveOpenThreatsCmd (void);



    // ************************************************************************
    // Methods for executing and undoing commands.
    // ************************************************************************

    /// Execute a command to add open conditions to planning.
    /**
     * @param cmd  Command object.
     */
    virtual void execute (SA_AddOpenCondsCmd *cmd);

    /// Undo a command to add open conditions to planning.
    /**
     * @param cmd  Command object.
     */
    virtual void undo (SA_AddOpenCondsCmd *cmd);

    /// Execute a command to remove open conditions from planning.
    /**
     * @param cmd  Command object.
     */
    virtual void execute (SA_RemoveOpenCondsCmd *cmd);

    /// Undo a command to remove open conditions from planning.
    /**
     * @param cmd  Command object.
     */
    virtual void undo (SA_RemoveOpenCondsCmd *cmd);

    /// Execute a command to add causal link threats to planning.
    /**
     * @param cmd  Command object.
     */
    virtual void execute (SA_AddOpenThreatsCmd *cmd);

    /// Undo a command to add causal link threats to planning.
    /**
     * @param cmd  Command object.
     */
    virtual void undo (SA_AddOpenThreatsCmd *cmd);

    /// Execute a command to remove causal link threats from planning.
    /**
     * @param cmd  Command object.
     */
    virtual void execute (SA_RemoveOpenThreatsCmd *cmd);

    /// Undo a command to remove causal link threats from planning.
    /**
     * @param cmd  Command object.
     */
    virtual void undo (SA_RemoveOpenThreatsCmd *cmd);

  protected:
    // ************************************************************************
    // State information.
    // ************************************************************************

    /// Flag for whether command prototypes have been set.
    bool has_cmds_;

    /// Set of open conditions with associated task instances that require
    /// them as preconditions.
    OpenCondMap open_conds_;

    /// Set of open causal link threats.
    CLThreatSet open_threats_;

    /// ID of current task being tried (to satisfy an open condition).
    TaskID cur_task_;

    /// ID of instance of current task being tried.
    TaskInstID cur_task_inst_;

    /// Current step number.
    int cur_step_;

    /// Current decision point.
    int cur_decision_pt_;

    /// Current sequence number for commands in this decision point.
    int cur_seq_num_;



    // ************************************************************************
    // Decision point numbers.
    // ************************************************************************

    /// Task choice is first decision point.
    static const int  TASK_DECISION = 1;

    /// Causal link threat handling is second decision point.
    static const int THREAT_DECISION = 2;

    /// Task implementation choice is third decision point.
    static const int IMPL_DECISION = 3;

    /// Scheduling is fourth decision point.
    static const int SCHEDULE_DECISION = 3;



    // ************************************************************************
    // Decision point heuristic strategies.
    // ************************************************************************

    /// Strategy for choosing open condition to satisfy.
    CondStrategy *cond_choice_;

    /// Strategy for choosing tasks to satisfy an open condition.
    TaskStrategy *task_choice_;

    /// Strategy for choosing task implementation.
    ImplStrategy *impl_choice_;



    // ************************************************************************
    // Prototypes of commands that work on this object.
    // ************************************************************************

    /// PlanCommand prototype to add open conditions.
    SA_AddOpenCondsCmd *add_conds_cmd_;

    /// PlanCommand prototype to remove open conditions.
    SA_RemoveOpenCondsCmd *rmv_conds_cmd_;

    /// PlanCommand prototype to add open causal link threats.
    SA_AddOpenThreatsCmd *add_threats_cmd_;

    /// PlanCommand prototype to remove open causal link threats.
    SA_RemoveOpenThreatsCmd *rmv_threats_cmd_;



    // ************************************************************************
    // Prototypes of commands that work on other objects.
    // ************************************************************************

    /// PlanCommand prototype for adding a task to the plan.
    AddTaskCmd *add_task_cmd_;

    /// PlanCommand prototype for associating an implementation with a
    /// task instance in the plan.
    AssocTaskImplCmd *assoc_impl_cmd_;

    /// PlanCommand prototype for resolving a causal link threat in the
    /// plan (with promotion or demotion).
    ResolveCLThreatCmd *resolve_threat_cmd_;



    // ************************************************************************
    // Internal helper methods.
    // ************************************************************************

    /// Recursively satisfy all open causal link threats and continue planning.
    /**
     * @return  True if planning succeeded, false otherwise.
     */
    virtual bool satisfy_open_threats (void);

    /// Satisfy an open condition with an appropriate task.
    /**
     * @param open_cond  Open condition to be satisfied.
     *
     * @return  Pointer to command passed to planner.
     */
    virtual AddTaskCmd *satisfy_cond (Condition open_cond);

    /// Add open conditions.
    /**
     * @param open_conds  Set of open conditions to add.
     *
     * @param task_inst  The task instance for which these are preconditions.
     *
     * @return  ID of command passed to planner to add open conditions.
     */
    virtual CommandID add_open_conds (const CondSet &open_conds,
      TaskInstID task_inst);

    /// Remove open condition.
    /**
     * @param open_cond  Open condition to remove.
     *
     * @return  ID of command passed to planner to remove open condition.
     */
    virtual CommandID rmv_open_cond (Condition open_cond);

    /// Add open causal link threats.
    /**
     * @param threats  Set of open causal link threats to add.
     *
     * @return  ID of command passed to planner to add open threats.
     */
    virtual CommandID add_open_threats (const CLThreatSet &threats);

    /// Remove open causal link threat.
    /**
     * @param threat  Open causal link threat to remove.
     *
     * @return  ID of command passed to planner to remove open threat.
     */
    virtual CommandID rmv_open_threat (CLThreat threat);

  };

};  /* SA_POP namespace */

#endif /* SA_POP_SA_PLAN_STRATEGY_H_ */