Provide the robot agent with a Painting capability.
The capability concept is a means of structuring reasoning elements of agents into 'clusters' that implement selected reasoning capabilities. This technique simplifies agent system design and allows code reuse and encapsulation of agent functionality. In this example, we encapsulate both the set of plans you have written so far and the Paint event into a Painting capability.
Capabilities are described in the Introduction to JACK notes. If necessary, read through the notes before beginning the exercise.
1. Add a new design diagram called Painting_DEP. This will be the DEP diagram for a new Painting capability. Then
Figure 6: The Painting_DEP design diagram with the PaintSpecifiedCurrentColour, PaintAnyColour and PaintSpecifiedNewColour plans
2. Now that the plans and event are encapsulated in the new capability, we should remove the links from the agent to the plans and declare that the Robot agent has the Painting capability. This can be achieved by:
Figure 7: The Robot_AD design diagram with the Robot agent and Paint event
Figure 8: The Robot_cap_hier design diagram with the Robot agent and Painting capability
3. Edit the Painting capability and check that the #uses plan declarations are declared in the the following order:
#uses plan PaintSpecifiedCurrentColour;
#uses plan PaintSpecifiedNewColour;
#uses plan PaintAnyColour;
This is the same order as they were previously declared in the agent declaration. If editing the file as a JACK file, save and close the file before continuing.
4. Save the project.
5. Compile and run the application. Check that the output is correct. It should be similar to the following:
test with red
Painting part the requested colour: red
PaintSpecifiedNewColour plan failed
painting the part the current colour: red
test with no specified colour
No specified colour. Painting the part red
test with green
Painting part the requested colour (1st coat) green
PaintSpecifiedNewColour plan failed
painting the part the current colour: green
test with green again
painting the part the current colour: green
运行结果:
(1) test with red
(2) Painting part the requested colour (1st coat) red
(3) PaintSpecifiedNewColour plan failed
(4) Painting the part the requested colour: red
(5) test with no specified colour (null)
(6) No specified colour. Painting the part: red
(7) test with green
(8) Painting part the requested colour (1st coat) green
(9) PaintSpecifiedNewColour plan failed
(10) Painting the part the requested colour: green
(11) test with green again
(12) Painting the part the requested colour: green