JACK——BOM Exercise2

来源:http://aosgrp.com/

 

Exercise 2

Use the indexed query to find a component's subcomponents.

 

Introduction

This step involves the use of indexed queries and a plan with a context() method to print out one of the subcomponents of a component. Initially we use a BDIGoalEvent so that only the first successful applicable plan is executed. This means that if we post only one event (e.g. find a subcomponent of component X), the first plan to have a context that finds a binding for a subcomponent of X will be executed. In that case we will only find (at most) one subcomponent.

 

Instructions

1. Open the Planner_AD design diagram and

  • Drag a new event from the design palette onto the design canvas. This event is to be called FindSubcomponent and is to be added to the bom package.
  • Create the following links with the Planner agent:

§ A handles link from the FindSubcomponent event;

§ A posts link to the FindSubcomponent event;

2. In the Planner_AD design diagram:

  • Add a new plan called FindSubcomponentPlan that is in the bom package.
  • Create a handles link between the FindSubcomponent event and the FindSubcomponentPlan plan.
  • Create a uses link from the plan to the bom named data.
  • Create a uses link from the Planner agent to the FindSubcomponentPlan plan.

3. Edit the FindSubcomponent event so that it:

  • extends BDIGoalEvent;
  • has a String data member component; and
  • includes a posting method findSubcomponent(String component) that assigns data to the component data member.

4. Edit the FindSubcomponentPlan plan so that it

  • Has a logical variable logical String $subcomp;
  • Includes a context method that uses the BOM beliefset's getSubcomponent() query to find a subcomponent for the component passed in with the event. $subcomp is passed into the query. (Note: the plan will only be applicable if the getSubcomponent() query can find an entry for the component in the BOM beliefset);
  • Includes a print statement similar to the following in the body of the plan:

System.out.println($subcomp.getValue()+" is a subcomponent of "

+ev.component);

5. Modify the Planner agent so that it contains a findSubcomponent(String component) method which will post a FindSubcomponent event using postEventAndWait().

6. Modify the main program so that it makes several invocations of the Planner agent's findSubcomponent() method with the name of a component that is in the agent's BOM beliefset. Ensure that for at least one of the invocations the component is composed of several subcomponent types.

7. Compile and run the program.

 

示例程序

 

运行结果:

(1) seat is a subcomponent of chair

(2) seat is a subcomponent of chair

 

运行结果分析:

在mian方法中调用了planner Agent的findSubcomponent(”chair”)两遍,返回chair的子部件seat两遍,输出(1)和(2)。

 

Questions

1. Why aren't all the component's subcomponents printed out?

 

Answers

1. FindSubcomponent Event设置为BDIGoalEvent,那么只会选择第一个匹配的规划去执行,而在FindSubcomponentPlan规划中只设定一个子部件的逻辑变量$subcomp,因此一次查询只获取一个子部件。

你可能感兴趣的:(bom)