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

Represents the vacuum cleaner problem. This class defines the initial state, goal test, actions, and heuristics for the vacuum cleaner problem. The problem is to clean two dirty rooms with a vacuum cleaner. The goal is to clean both rooms. More...

#include <vacuum.h>

Inheritance diagram for VacuumCleaner:
Collaboration diagram for VacuumCleaner:

Public Member Functions

 VacuumCleaner ()
 
 ~VacuumCleaner ()
 
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
 Returns the possible actions for the given state.
 
double heuristic (State *state) override
 Returns the heuristic value for the 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

Represents the vacuum cleaner problem. This class defines the initial state, goal test, actions, and heuristics for the vacuum cleaner problem. The problem is to clean two dirty rooms with a vacuum cleaner. The goal is to clean both rooms.

Definition at line 36 of file vacuum.h.

Constructor & Destructor Documentation

◆ VacuumCleaner()

VacuumCleaner::VacuumCleaner ( )
inline

Definition at line 38 of file vacuum.h.

38 {
40 }
State * initial_state_
Pointer to the initial state of the problem.
Represents the state of the vacuum cleaner problem.
Definition vacuum.h:18

References Problem::initial_state_.

◆ ~VacuumCleaner()

VacuumCleaner::~VacuumCleaner ( )
inline

Definition at line 41 of file vacuum.h.

41 {
42 }

Member Function Documentation

◆ actions()

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

Returns the possible actions for the given state.

Parameters
stateThe current state.
Returns
A vector of shared pointers to Action objects.

Implements Problem.

Definition at line 56 of file vacuum.h.

56 {
57 auto vacuum_state = std::dynamic_pointer_cast<VacuumState>(state);
58 std::vector<std::shared_ptr<Action>> actions;
59
60 auto create_state = [&](int x, bool dirty0, bool dirty1) {
61 return std::make_shared<VacuumState>(x, dirty0, dirty1);
62 };
63
64 // Add possible actions with smart pointers
65 if (vacuum_state->x == 0) {
66 if (vacuum_state->dirty0) {
67 actions.push_back(std::make_shared<Action>("Suck", 1, state, create_state(0, false, vacuum_state->dirty1)));
68 } else {
69 actions.push_back(std::make_shared<Action>("Right", 1, state, create_state(1, vacuum_state->dirty0, vacuum_state->dirty1)));
70 }
71 } else {
72 if (vacuum_state->dirty1) {
73 actions.push_back(std::make_shared<Action>("Suck", 1, state, create_state(1, vacuum_state->dirty0, false)));
74 } else {
75 actions.push_back(std::make_shared<Action>("Left", 1, state, create_state(0, vacuum_state->dirty0, vacuum_state->dirty1)));
76 }
77 }
78
79 return actions;
80 }
std::vector< std::shared_ptr< Action > > actions(std::shared_ptr< State > state) override
Returns the possible actions for the given state.
Definition vacuum.h:56

References actions().

Referenced by actions().

◆ goal_test()

bool VacuumCleaner::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.

nul.l check

Implements Problem.

Definition at line 43 of file vacuum.h.

43 {
44 auto *vacuum_state = dynamic_cast<VacuumState *>(state);
46 if (vacuum_state == nullptr) {
47 return false;
48 }
49 return !vacuum_state->dirty0 && !vacuum_state->dirty1;
50 }
bool dirty0
Definition vacuum.h:23

References VacuumState::dirty0.

◆ heuristic()

double VacuumCleaner::heuristic ( State state)
inlineoverridevirtual

Returns the heuristic value for the given state.

Parameters
stateThe current state.
Returns
The heuristic value.

Implements Problem.

Definition at line 87 of file vacuum.h.

87 {
88 auto *vacuum_state = dynamic_cast<VacuumState *>(state);
89 return vacuum_state->dirty0 + vacuum_state->dirty1;
90 }

References VacuumState::dirty0.


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