JACK——PaintRobot Exercise6

来源:http://aosgrp.com/

 

Exercise 6

Provide the robot agent with a Painting capability.

 

Introduction

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.

 

Instructions

1. Add a new design diagram called Painting_DEP. This will be the DEP diagram for a new Painting capability. Then

  • Drag a new capability from the design palette onto the new canvas. Call this new capability Painting and add it to the robot package.
  • Drag the three painting plans from the browser onto the Painting_DEP design diagram.
  • Drag the Paint event from the browser onto the Painting_DEP design diagram.
  • Create links from the Painting capability icon to each of the plans.
  • Create a handles link from the Paint event to the Painting capability.
  • The diagram becomes quite cluttered if we keep the capability on its DEP diagram. It is useful to have it on the diagram to make the links and to check the links. However, when this task is complete, the capability icon can be removed from the diagram without changing the links. This is achieved by using the design tool in Selection mode, selecting the capability icon on the canvas and then selecting the Remove selected objects from diagram button. Use this procedure to remove the capability from the Painting_DEP design diagram. Your Painting_DEP diagram should be similar to the following diagram.

clip_image001

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:

  •  deleting the uses links between the Robot agent and each of the painting plans on the Robot_AD design diagram. Take care that you do not delete the link that corresponds to the #uses interface Robot self declaration in each of the plans. An alternative mechanism for removing the links from the Robot to the plans is to edit the Robot type definition using the Edit as JACK File option.
  •  deleting the handles link between the Paint event and the Robot agent on the Robot_AD design diagram.
  • removing the components no longer required on the Robot_AD design diagram (i.e. remove the three painting plans from the design diagram). Your Robot_AD diagram should be similar to the following diagram:

clip_image002

Figure 7: The Robot_AD design diagram with the Robot agent and Paint event

  • creating a new design canvas called Robot_cap_hier, dragging the Robot agent and Painting capability onto the new design diagram, then creating a has link from the Robot agent to the Painting capability. The Robot_cap_hier should appear similar to the following diagram:

clip_image003

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

你可能感兴趣的:(paint)