blob: 115690ad6bde1b9f489559600d822135b7c4a904 (
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
|
// -*- C++ -*-
// $Id$
//=============================================================================
/**
* @file SA_PlanHeuristics.cpp
*
* This file contains the implementations of concrete classes,
* which implement plan heuristic strategies.
*
* @author John S. Kinnebrew <john.s.kinnebrew@vanderbilt.edu>
*/
//=============================================================================
#include "SA_POP_Types.h"
#include "SA_PlanHeuristics.h"
#include "Planner.h"
using namespace SA_POP;
// Constructor.
SA_CondStrategy::SA_CondStrategy (SA_POP::Planner *planner)
: CondStrategy (planner)
{
// Nothing to do.
};
// Destructor.
SA_CondStrategy::~SA_CondStrategy (void)
{
// Nothing to do.
};
// Choose the next open condition to satisfy.
Condition SA_CondStrategy::choose_cond (const OpenCondMap &open_conds)
{
if (open_conds.empty ())
throw "SA_POP::SA_CondStrategy::choose_cond (): Empty condition list.";
// Return first data condition.
for (OpenCondMap::const_iterator iter = open_conds.begin ();
iter != open_conds.end (); iter++)
{
if (iter->first.kind == SA_POP::DATA)
return iter->first;
}
// If no data conditions, just return first condition.
return open_conds.begin ()->first;
};
// Constructor.
SA_TaskStrategy::SA_TaskStrategy (SA_POP::Planner *planner)
: TaskStrategy (planner)
{
// Nothing to do.
};
// Destructor.
SA_TaskStrategy::~SA_TaskStrategy (void)
{
// Nothing to do.
};
// Choose the (ordering of) task(s) to satisfy an open condition.
TaskList SA_TaskStrategy::choose_task (Condition open_cond)
{
TaskSet tasks = this->planner_->get_satisfying_tasks (open_cond);
// Add tasks to map with EU (to sort).
std::map<EUCalc, TaskID> task_map;
task_map.clear ();
for (TaskSet::iterator iter = tasks.begin (); iter != tasks.end (); iter++)
{
task_map.insert (std::make_pair (
this->planner_->get_task_future_eu (*iter), *iter));
}
// Add tasks to list in reverse order of map (highest EU first).
TaskList task_list;
task_list.clear ();
for (std::map<EUCalc, TaskID>::reverse_iterator iter = task_map.rbegin ();
iter != task_map.rend (); iter++)
{
task_list.push_back (iter->second);
}
return task_list;
};
// Constructor.
SA_ImplStrategy::SA_ImplStrategy (SA_POP::Planner *planner)
: ImplStrategy (planner)
{
// Nothing to do.
};
// Destructor.
SA_ImplStrategy::~SA_ImplStrategy (void)
{
// Nothing to do.
};
// Choose the (ordering of) task implementation(s) for a task instance.
TaskImplList SA_ImplStrategy::choose_impl (TaskInstID task_inst)
{
TaskID task = this->planner_->get_task_from_inst (task_inst);
TaskImplSet impls = this->planner_->get_all_impls (task);
//****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP****TEMP
// Order by resource impact score.
TaskImplList impl_list;
impl_list.clear ();
for (TaskImplSet::iterator iter = impls.begin ();
iter != impls.end (); iter++)
{
impl_list.push_back (*iter);
}
return impl_list;
};
|