Use the indexed query to find a component's subcomponents.
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.
1. Open the Planner_AD design diagram and
§ A handles link from the FindSubcomponent event;
§ A posts link to the FindSubcomponent event;
2. In the Planner_AD design diagram:
3. Edit the FindSubcomponent event so that it:
4. Edit the FindSubcomponentPlan plan so that it
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)。
1. Why aren't all the component's subcomponents printed out?
Answers
1. FindSubcomponent Event设置为BDIGoalEvent,那么只会选择第一个匹配的规划去执行,而在FindSubcomponentPlan规划中只设定一个子部件的逻辑变量$subcomp,因此一次查询只获取一个子部件。