Frame-Based System Design. Fames vs. Rules General design methodology Define the problem Analyze the...

Preview:

Citation preview

Frame-Based System Design

• Fames vs. Rules• General design methodology• Define the problem• Analyze the domain• Define the classes• Define the instances• Define the rules• Object communications• Interface• Evaluate and expand the system

Rule 1

IF Boiler temprature>300

AND Boiler water level>5

THEN Boiler condition normal

Rule 2

IF Boiler pressure<50

AND Boiler water level>3

THEN add water to boiler

Rule-based system:

Unrelated facts scattered throughout the knowledge base

Frame – Boiler

Temprature

Pressure

Water level

Condition

Frame-based system:

Collects the related facts

Represents them as slots within a single frame structure

• Better way to manage the knowledge base• Eases system coding and maintenance when working

with similar types of objects (through inheritance)• Pattern matching include rules :

IF <Boiler>.Temprature > 300

AND <Boiler>.Water_level > 5

THEN <Boiler>.Condition = normal

• Another benefit: object communications through message-passing

General Design Methodology

• Define the problem• Analyze the domain• Define the classes• Define the instances• Define the rules• Define object communications• Design the interface• Evaluate the system• Expand the system

• Task 1 :Define the problem

A system for controling the house temperature

Usually one thermostat- inefficient

- large temperature variations between rooms

Solution:- We have 3 rooms: living room, kitchen, bedroom

- It can be extended

- Each room has a cooling and heating unit, and a thermostat

- Rooms can be occupied or unoccupied

Infrared Senor

ModeHeat Air

Furnace Air conditioner

Setting

Temperature

50 60 70

50 60 70

• Task 2 : Analyze the domaindefine objects, Features,Events,Architecture

Room ,

Furnace, Air conditioner,

Thermostat, Room temperature,

Sensor

Objects

Object features

ROOM Features

Thermostat

Furnace

AC

Sensor

occupancy

THERMOSTAT

Room

Furnace

AC

Sensor

Mode

Setting

temperature

FURNACE

Room

State

Thermostat

Sensor

Occupancy

Room

Thermostat

Events

• Thermostat mode of operation for each room is either heat or cool

• When a given room is occupied, temperature should be adjusted toward the thermostat setting

• When a given room is unoccupied, and operation mode is heat, then room temperature should be adjusted toward the thermostat setting minus 5 degree

• When a given room is unoccupied, and operation mode is cool, then room temperature should be adjusted toward the thermostat setting plus 5 degree

• Generalization : “Kind of” relationship• Aggregation : “Part of” relationship• Association : “Semantic” relationship

Architecture

Thermostat

Thermostat 1 Thermostat 2 Thermostat 3

Room

Livingroom Kitchen Bedroom

•Task3 : Define the classes

• Define the problem

• Analyze the domain

• Define the classes

• Define the instances

• Define the rules

• Define object communications

• Design the interface

• Evaluate the system

• Expand the system

MakeClass(THERMOSTAT,Root)

Also possible via graphical menu

Kappa:

Kappa’s advantage: window-based development feature , includes message passing

Room

Furnace

UnoccupiedOccupancy

Thermostat

AC

Class name:

Properties:

Methods:

Thermostat

Furnace

HeatMode

Setting 68

65Temperature

Class name:

Properties:

Methods:

AC

Room

AC

Room

State off

Class name:

Properties:

Methods:

Thermostat

•Task4 : Define the Instances

MakeInstance(THERMOSTAT1,THERMOSTAT)

Room instances:

we have 3 rooms and we need to create instances .

Then we assign the appropriate values in each instance (Furnace name, etc)

Room

Livingroom Kitchen Bedroom

Furnace Furnace1

occupancy unoccupied

thermostat thermostat1

AC AC1

Furnace Furnace2

occupancy unoccupied

thermostat thermostat2

AC AC2

Furnace Furnace3

occupancy unoccupied

thermostat thermostat3

AC AC3

• Example:

When a room is unoccupied,the mode of operation is heat, and the thermostat setting is 5 degree greater than the room temperature,then turn on the room furnace.

•Task5 : Define the Rules

ForAll x|THERMOSTAT

IF x:Room:Occupancy #= Unoccupied

AND x:Mode #= Heat

AND x:Setting – x:Temperature >5

THEN x:furnace:State = ON

Object communications vs. Rules

We should decide when to use rules

and when to use interobject communication techniques

Usually it is personal preference of the designer

• Advantages of rules

- takes a set of evidence and inferes new informaion

- deep inferencing: general information

- using variables, all instances are scanned

• Disadvantages of rules

- an inefficient means for capturing knowledge that is largely procedural

- limited in the type of functions they can perform

- quickly become unreadable and difficult to maintain

- difficult to write a set of rules that account for the propagation of changes in information

• Advantages of object communications- it is natural to define interactions and behaviour of an

object in addition to its properties- Encapsulation of methods within a frame instead of being spread around the rules- easy to maintain and debug- applications such as simulation or control rely on objects interactions

• Disadvantages of object communications

- might be difficult to debug when actions ripple through a large number of objects!

- overuse of methods

- methods are not appropriate for representing heuristics

• Demons: IF-NEEDED IF-CHANGED

•Task6 : Define object communcations

• We want to write a method that enables the frame THERMOSTAT1 to respond to a question about its location

we can write this method and attach it to the IF-NEEDED facet of the property “Room” of the frame:

THERMOSTAT1:Room

This method is simple but not efficient because it can be used only by THERMOSTAT1

We need a variable that can be bound to each thermostat:

Self:Room

• An IF-CHANGED facet method is executed whenever some property value is changed

While ((Self:State #=ON))

Self:Thermostat:Temperature= Self:Thermostat:Temperature +1

• IF-NEEDED and IF-CHANGED provide means for objects to exchange and change information

• Some shells like Kappa also provide message passing

SendMessage(objName,methodName,<arg1,arg2,…>)

SendMessage(Self:Fornace,On)

SetValue(Self:State,On)

Thermostat

Mode heat

Air

Class name:

Properties:

Methods:

Setting 68

Unit-Control

Unit-Control

IF-CHANGED

Temperature 65 Unit-Control

Self:Mode=Air;

Heat Self:Mode=Heat;

Init

forAll (x|Thermostat)|ResetValue(x:setting);

RestValue(x:mode);ResetValue(x:Temperature);

ThermostatClass name:

Methods:Unit-Control

{ If ((Self:Temprature <Self:Setting) And(Self:Furnace:State #= OFF) And(Self:Mode #= Heat) And(Self:Room:Occupancy #=Occupied))Then SendMessage (Self:Furnace,ON);

If …….Then …..;

If …….Then …..; };

Body:

FurnaceClass name:

Methods:

Room

OFF

ON

Init

Heat

State

Thermostat

OFF Heat

IF-CHANGED

Name Body

SetValue (Self:State,OFF)

SetValue (Self:State,ON)

resetvalue…

While((Self:State #=ON))Self:Thermostat:Temperature == … +1

• Most shells offer a toolkit of graphical objects

- Observable displays

- Control displays

•Task7 : Design the interface

• Test case:

1. Increase living room Thermostat setting in 1 degree increments

2. Continue this process until setting is at 75 degrees

Room temperature = 65

Furnace and AC are off

Mode is heat

Thermo setting = 68

Room is Unoccupied

•Task8 : Evaluate the system

Trace of operation

1. User increases thermostat handler in interface

2. With each increment, “setting” slot of thermostat1 increments. Each increment causes the IF-CHANGED method “unit control” to fire.

3. When setting reaches temperature + 5, “unit control” sends an On msg to Furnace1

4. Change of furnace state, causes “Heat” to fire

5. …

Task9 : Expand the system

• Deepening knowledge

By adding new objects related to existed ones

use of generalization and part of and….

• Broadening knowledgeAddition of new events or objects

Recommended