JACK——BOM Exercise1

来源:http://aosgrp.com/

 

Exercise 1

Set up a Bill of Materials (BOM) beliefset.

 

Introduction

In this exercise you will create a simplified BOM beliefset to be used within a Planner agent. A BOM is a data structure used in manufacturing to describe the component/subcomponent structure of part assemblies. In this tutorial, the BOM will only capture the component/subcomponent structure: in practice, it will contain much more information, such as the number of a particular component that is required, whether the component is made internally or is outsourced etc.

You will also create a main program to read BOM data provided by the user. This information will be stored in a JACK beliefset which is private to the Planner agent. An alternative mechanism for initialising the beliefset is to use a JACOB file. This alternative is used in Exercise 5.

 

Instructions

1. Create a directory called practical2/ex1. In this directory, start the JDE and open a new project called BOM.

2. Create a beliefset type called BOM:

  • Open the Data Model container in the browser.
  • Right-click on the Beliefset Types folder and select Add New Beliefset Type from the pop-up menu. Call the beliefset BOM and add it to the bom package. It is to have two key fields of type String. One field is used to store a component type, and the other field is used to store a subcomponent type. This means that in this beliefset there will be n entries per component, where n is the number of subcomponent types that are used to build that component. Note that we distinguish between subcomponent types and subcomponents. For example, a table may have two subcomponent types (top and leg) but five subcomponents (one top and four legs).
  • Use the Edit as JACK File option to add the two key fields and a getSubcomponent query to the beliefset. In Exercise 2 the getSubcomponent query will be used to find a subcomponent of a given component. This means that the subcomponent field is to be an output field in the query. Although this query is not required until Exercise 2, it is added now because a JACK beliefset must have at least one query. Your BOM beliefset should be similar to the following:

package bom;

public beliefset BOM extends OpenWorld {

#key field String component;

#key field String subcomponent;

#indexed query getSubcomponent(String component,

logical String subcomponent);

}

3. We will now use the design tool to define an agent, Planner, that will store component/subcomponent tuples in a private beliefset of type BOM:

  • Create a new design diagram called Planner_AD.
  • Drag a new agent onto the Planner_AD design canvas. It is to be called Planner and it is to be in the bom package.
  • Drag the Named Data icon from the design palette onto the design canvas. The named data is to be called bom and is to be of type bom.BOM.
  • Create a private link from the Planner agent to the bom named data on the design canvas.

4. The beliefset will be populated at agent construction time. Consequently the agent's constructor will be passed two strings – the agent's name and the name of a file containing component-subcomponent details. The constructor must read each component-subcomponent relation from the file, and add the information to the agent's BOM beliefset. The code to achieve this can be added to the agent by using the browser to edit the agent as a JACK file. Sample code for the constructor follows:

public Planner(String name, String filename)

{

super(name);

StringTokenizer tokens;

String record;

String t1,t2;

BufferedReader datafile = null;

try {

datafile = new BufferedReader(new FileReader(filename));

}

catch (FileNotFoundException e) {

System.err.println("unable to open file "+e.toString());

System.exit(1);

}

try {

while ((record = datafile.readLine())!=null) {

tokens = new StringTokenizer(record);

t1 = tokens.nextToken();

t2 = tokens.nextToken();

bom.add(t1,t2);

}

}

catch (Exception e) {

System.err.println("error reading bom data into beliefset");

System.exit(1);

}

}

Make sure that the Planner agent has the following import statements:

import java.io.*;

import java.util.*;

5. Add a new file called Program.java to the Other Files folder in the browser. It will create a Planner agent, perhaps as follows:

import java.io.*;

import bom.Planner;

public class Program {

public static void main( String args[] )

{

Planner planner = new Planner("planner1","bom.dat");

System.exit(0);

}

}

If you wish to run the project from within the JDE make sure that you use the full pathname for bom.dat.

6. Create the file bom.dat and populate it with component/subcomponent records. It could contain:

chair back

chair seat

chair leg

chair arm

table top

table leg

cupboard door

cupboard drawer

cupboard leg

cupboard cabinet

7. Compile and run the program. No output is generated by the program at this stage, but it provides the basis for the remaining exercises.

 

示例程序

转载于:https://www.cnblogs.com/6DAN_HUST/archive/2011/06/15/2081262.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值