summaryrefslogtreecommitdiff
path: root/SA_SchedStrategy.h
blob: 95b9e74fd2af78c71c155175a5881ab1cc63f8f7 (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
// -*- C++ -*-
// $Id$

//=============================================================================
/**
 * @file  SA_SchedStrategy.h
 *
 * This file contains the SA_SchedStrategy concrete class definition, which
 * implements a SchedStrategy for the high-level scheduling algorithm.
 *
 * @author  John S. Kinnebrew <john.s.kinnebrew@vanderbilt.edu>
 */
//=============================================================================

#ifndef SA_POP_SA_SCHED_STRATEGY_H_
#define SA_POP_SA_SCHED_STRATEGY_H_

#include<map>
#include "SA_POP_Types.h"
#include "SchedStrategy.h"
#include "PlanCommands.h"

namespace SA_POP {

  /**
   * @class SA_SchedStrategy
   *
   * @brief  Concrete class of SchedStrategy for the high-level scheduling
   *         algorithm.
   */
  class SA_SchedStrategy : public SchedStrategy {
  public:
    /// Constructor.
    /**
     * @param planner  Planner object to use.
     */
    SA_SchedStrategy (SA_POP::Planner *planner);

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


    /// reset the object
    virtual void reset();

    /// Set command prototypes to use in scheduling.
    /**
     * @param resolve_sched_cmd  Prototype of command for resolving a
     *                           scheduling conflict between two task
     *                           instances in the plan.
     *
     * @param adj_min_times_cmd  Prototype of command for adjusting the
     *                           min times of a task instance in the plan.
     *
     * @param adj_max_times_cmd  Prototype of command for adjusting the
     *                         max times of a task instance in the plan.
     */
    virtual void set_commands (ResolveSchedOrderCmd *resolve_sched_cmd,
      AdjustMinTimesCmd *adj_min_times_cmd,
      AdjustMaxTimesCmd *adj_max_times_cmd);


    /// 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 scheduling constraints (and continue
    /// satisfaction of open conditions by recursive call back to planning).
    /**
     * @param task_inst  Current task instance being tried in the plan.
     *
     * @return  True if fully satisfied plan found, false otherwise.
     */
    virtual bool satisfy_sched (TaskInstID task_inst);

    /// Satisfy fully instantiated plan.
    /**
     * @param task_inst  Current task instance being tried in the plan.
     *
     * @return  True if fully satisfied plan found, false otherwise.
     */
    virtual bool satisfy_full_sched ();

	///Energy Constraint Propogation
	/**
	 * @param task_inst Current task instance being tried in the plan
	 *
	 * @return True if the energy constraint propogation is successfull
	 */
	virtual bool energy_prop (TaskInstID task_inst);
	///Energy Constraint Propogation Helper functions
	/**
	 * @param task_inst Current task instance being tried in the plan
	 *
	 * @return True if the energy constraint propogation is successfull
	 */
	virtual bool energy_prop_after (TaskInstID task_inst);
	///Energy Constraint Propogation Helper functions
	/**
	 * @param task_inst Current task instance being tried in the plan
	 *
	 * @return True if the energy constraint propogation is successfull
	 */
	virtual bool energy_prop_before (TaskInstID task_inst);
	///Time Based Balance Constraint Propogation 5.3.3 (labourie paper)
	/**
	 * @param task_inst Current task instance being tried in the plan
	 *
	 * @return True if the balance constraint propogation is successfull
	 */
	virtual bool time_balance_prop (TaskInstID task_inst);
	///Precedence Link Based Balance Constraint Propogation 5.3.4 (labourie paper)
	/**
	 * @param task_inst Current task instance being tried in the plan
	 *
	 * @return True if the balance constraint propogation is successfull
	 */
	virtual bool prec_balance_prop (TaskInstID task_inst);
	///Commitment of an ordering
	/**
	 * @param first_task_inst The task_instance scheduled before the second one.
	 *
	 * @param second_task_inst The task instance schedules after the first one.
	 *
	 * @return The value of the commitment of this order.
	 */
	virtual double commit(TaskInstID first_task_inst, TaskInstID second_task_inst);
	///Criticality of the consumer of a task instance
	/**
	 * @param task_inst The task instance.
	 *
	 * @return The value of the criticality of the task instance.
	 */
	virtual Criticality crit(TaskInstID task_inst);
	/// Calculate the min and max levels
	virtual void calculate_levels(TaskInstID task_inst);
	/// Perform the search till the ctiricality goes below a certain value
	/**
	 * @param min_crit The threshold criticality value
	 *
	 * @return True if it succeds
	 */
	virtual bool search(double min_crit);
  protected:
    
    /// Flag for whether command prototypes have been set.
    bool has_cmds_;

    /// Current decision point.
    int cur_decision_pt_;

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

	/// Type of a map from task instance to its level
	typedef std::map<TaskInstID,ResourceValue> LevelMap;
	/// Type of a map from the Resource ID to the minimum levels
	typedef std::map<ResourceID,LevelMap> MinimumLevels;
	/// Type of a map from the Resource ID to the maximum levels
	typedef std::map<ResourceID,LevelMap> MaximumLevels;
	
	MinimumLevels min_cons_levels_;
	MaximumLevels max_cons_levels_;
    // ************************************************************************
    // Decision point numbers.
    // ************************************************************************

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

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

    /// PlanCommand prototype for resolving a scheduling conflict (i.e.
    /// non-causal-link ordering constraint (with promotion or demotion)
    /// between two task instances in the plan.
    ResolveSchedOrderCmd *resolve_sched_cmd_;

    /// PlanCommand prototype for adjusting the min times of a
    /// task instance in the plan.
    AdjustMinTimesCmd *adj_min_times_cmd_;

    /// PlanCommand prototype for adjusting the max times of a
    /// task instance in the plan.
    AdjustMaxTimesCmd *adj_max_times_cmd_;
  };

};  /* SA_POP namespace */

#endif /* SA_POP_SA_SCHED_STRATEGY_H_ */