Symphony 1.0
Loading...
Searching...
No Matches
TaskScheduler Class Reference

#include <task_scheduler.h>

Inheritance diagram for TaskScheduler:
Collaboration diagram for TaskScheduler:

Public Member Functions

 TaskScheduler ()
 Represents the task scheduler problem. This class defines the initial state, goal test, actions, and heuristics for the task scheduler problem. The problem is to complete a set of tasks with different priorities and deadlines. The goal is to complete all tasks.
 
 ~TaskScheduler ()
 
bool goal_test (State *state) override
 Tests if a given state satisfies the goal condition.
 
std::vector< std::shared_ptr< Action > > actions (std::shared_ptr< State > state) override
 Retrieves the set of actions applicable to a given state.
 
double heuristic (State *state) override
 Computes a heuristic estimate for a given state.
 
- Public Member Functions inherited from Problem
 Problem ()
 Constructor for the Problem class.
 
virtual ~Problem ()
 Virtual destructor for the Problem class.
 
virtual Stateinitial_state ()
 Retrieves the initial state of the problem.
 

Additional Inherited Members

- Public Attributes inherited from Problem
Stateinitial_state_
 Pointer to the initial state of the problem.
 

Detailed Description

Definition at line 53 of file task_scheduler.h.

Constructor & Destructor Documentation

◆ TaskScheduler()

TaskScheduler::TaskScheduler ( )
inline

Represents the task scheduler problem. This class defines the initial state, goal test, actions, and heuristics for the task scheduler problem. The problem is to complete a set of tasks with different priorities and deadlines. The goal is to complete all tasks.

Definition at line 60 of file task_scheduler.h.

60 {
62 }
State * initial_state_
Pointer to the initial state of the problem.
Represents the state of the task scheduler problem.

References Problem::initial_state_.

◆ ~TaskScheduler()

TaskScheduler::~TaskScheduler ( )
inline

Definition at line 63 of file task_scheduler.h.

63 {
64 }

Member Function Documentation

◆ actions()

std::vector< std::shared_ptr< Action > > TaskScheduler::actions ( std::shared_ptr< State state)
inlineoverridevirtual

Retrieves the set of actions applicable to a given state.

This method must be implemented by the user to define the available actions for a specific state.

Parameters
stateThe current state.
Returns
A vector of actions applicable to the given state.

Implements Problem.

Definition at line 69 of file task_scheduler.h.

69 {
70 auto scheduler_state = std::dynamic_pointer_cast<TaskSchedulerState>(state);
71 std::vector<std::shared_ptr<Action>> actions;
72
73 for (const auto &task : scheduler_state->tasks) {
74 auto new_state = std::make_shared<TaskSchedulerState>(*scheduler_state);
75 // Remove the task from the new state
76 int index = 0;
77 for (const auto &t : new_state->tasks) {
78 if (t == task) {
79 new_state->tasks.erase(new_state->tasks.begin() + index);
80 break;
81 }
82 index++;
83 }
84 actions.push_back(std::make_shared<Action>("Complete " + task.name, 1, state, new_state));
85 }
86
87 return actions;
88 }
std::vector< std::shared_ptr< Action > > actions(std::shared_ptr< State > state) override
Retrieves the set of actions applicable to a given state.

References actions().

Referenced by actions().

◆ goal_test()

bool TaskScheduler::goal_test ( State state)
inlineoverridevirtual

Tests if a given state satisfies the goal condition.

This method must be implemented by the user to define the goal state criteria.

Parameters
stateThe state to test.
Returns
True if the state satisfies the goal condition, false otherwise.

Implements Problem.

Definition at line 65 of file task_scheduler.h.

65 {
66 auto *scheduler_state = dynamic_cast<TaskSchedulerState *>(state);
67 return scheduler_state && scheduler_state->tasks.empty();
68 }
std::vector< Task > tasks

References TaskSchedulerState::tasks.

◆ heuristic()

double TaskScheduler::heuristic ( State state)
inlineoverridevirtual

Computes a heuristic estimate for a given state.

This method must be implemented by the user to define a heuristic function for the problem.

Parameters
stateThe state for which to compute the heuristic.
Returns
A heuristic estimate of the cost to reach the goal from the given state.

Implements Problem.

Definition at line 89 of file task_scheduler.h.

89 {
90 auto *scheduler_state = dynamic_cast<TaskSchedulerState *>(state);
91 int total_priority = 0;
92 for (const auto &task : scheduler_state->tasks) {
93 total_priority += task.priority;
94 }
95 return total_priority;
96 }

The documentation for this class was generated from the following file: