35
Frame-Based System Design

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

Embed Size (px)

Citation preview

Page 1: Frame-Based System Design. Fames vs. Rules General design methodology Define the problem Analyze the domain Define the classes Define the instances Define

Frame-Based System Design

Page 2: Frame-Based System Design. Fames vs. Rules General design methodology Define the problem Analyze the domain Define the classes Define the instances Define

• 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

Page 3: Frame-Based System Design. Fames vs. Rules General design methodology Define the problem Analyze the domain Define the classes Define the instances Define

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

Page 4: Frame-Based System Design. Fames vs. Rules General design methodology Define the problem Analyze the domain Define the classes Define the instances Define

Frame – Boiler

Temprature

Pressure

Water level

Condition

Frame-based system:

Collects the related facts

Represents them as slots within a single frame structure

Page 5: Frame-Based System Design. Fames vs. Rules General design methodology Define the problem Analyze the domain Define the classes Define the instances Define

• 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

Page 6: Frame-Based System Design. Fames vs. Rules General design methodology Define the problem Analyze the domain Define the classes Define the instances Define

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

Page 7: Frame-Based System Design. Fames vs. Rules General design methodology Define the problem Analyze the domain Define the classes Define the instances Define

• 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

Page 8: Frame-Based System Design. Fames vs. Rules General design methodology Define the problem Analyze the domain Define the classes Define the instances Define

Infrared Senor

ModeHeat Air

Furnace Air conditioner

Setting

Temperature

50 60 70

50 60 70

Page 9: Frame-Based System Design. Fames vs. Rules General design methodology Define the problem Analyze the domain Define the classes Define the instances Define

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

Room ,

Furnace, Air conditioner,

Thermostat, Room temperature,

Sensor

Objects

Page 10: Frame-Based System Design. Fames vs. Rules General design methodology Define the problem Analyze the domain Define the classes Define the instances Define

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

Page 11: Frame-Based System Design. Fames vs. Rules General design methodology Define the problem Analyze the domain Define the classes Define the instances Define

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

Page 12: Frame-Based System Design. Fames vs. Rules General design methodology Define the problem Analyze the domain Define the classes Define the instances Define

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

Architecture

Page 13: Frame-Based System Design. Fames vs. Rules General design methodology Define the problem Analyze the domain Define the classes Define the instances Define

Thermostat

Thermostat 1 Thermostat 2 Thermostat 3

Room

Livingroom Kitchen Bedroom

Page 14: Frame-Based System Design. Fames vs. Rules General design methodology Define the problem Analyze the domain Define the classes Define the instances Define

•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

Page 15: Frame-Based System Design. Fames vs. Rules General design methodology Define the problem Analyze the domain Define the classes Define the instances Define

Room

Furnace

UnoccupiedOccupancy

Thermostat

AC

Class name:

Properties:

Methods:

Page 16: Frame-Based System Design. Fames vs. Rules General design methodology Define the problem Analyze the domain Define the classes Define the instances Define

Thermostat

Furnace

HeatMode

Setting 68

65Temperature

Class name:

Properties:

Methods:

AC

Room

Page 17: Frame-Based System Design. Fames vs. Rules General design methodology Define the problem Analyze the domain Define the classes Define the instances Define

AC

Room

State off

Class name:

Properties:

Methods:

Thermostat

Page 18: Frame-Based System Design. Fames vs. Rules General design methodology Define the problem Analyze the domain Define the classes Define the instances Define

•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)

Page 19: Frame-Based System Design. Fames vs. Rules General design methodology Define the problem Analyze the domain Define the classes Define the instances Define

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

Page 20: Frame-Based System Design. Fames vs. Rules General design methodology Define the problem Analyze the domain Define the classes Define the instances Define

• 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

Page 21: Frame-Based System Design. Fames vs. Rules General design methodology Define the problem Analyze the domain Define the classes Define the instances Define

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

Page 22: Frame-Based System Design. Fames vs. Rules General design methodology Define the problem Analyze the domain Define the classes Define the instances Define

• 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

Page 23: Frame-Based System Design. Fames vs. Rules General design methodology Define the problem Analyze the domain Define the classes Define the instances Define

• 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

Page 24: Frame-Based System Design. Fames vs. Rules General design methodology Define the problem Analyze the domain Define the classes Define the instances Define

• 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

Page 25: Frame-Based System Design. Fames vs. Rules General design methodology Define the problem Analyze the domain Define the classes Define the instances Define

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

Page 26: Frame-Based System Design. Fames vs. Rules General design methodology Define the problem Analyze the domain Define the classes Define the instances Define

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

While ((Self:State #=ON))

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

Page 27: Frame-Based System Design. Fames vs. Rules General design methodology Define the problem Analyze the domain Define the classes Define the instances Define

• 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)

Page 28: Frame-Based System Design. Fames vs. Rules General design methodology Define the problem Analyze the domain Define the classes Define the instances Define

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);

Page 29: Frame-Based System Design. Fames vs. Rules General design methodology Define the problem Analyze the domain Define the classes Define the instances Define

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:

Page 30: Frame-Based System Design. Fames vs. Rules General design methodology Define the problem Analyze the domain Define the classes Define the instances Define

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

Page 31: Frame-Based System Design. Fames vs. Rules General design methodology Define the problem Analyze the domain Define the classes Define the instances Define

• Most shells offer a toolkit of graphical objects

- Observable displays

- Control displays

•Task7 : Design the interface

Page 32: Frame-Based System Design. Fames vs. Rules General design methodology Define the problem Analyze the domain Define the classes Define the instances Define

• 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

Page 33: Frame-Based System Design. Fames vs. Rules General design methodology Define the problem Analyze the domain Define the classes Define the instances Define

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. …

Page 34: Frame-Based System Design. Fames vs. Rules General design methodology Define the problem Analyze the domain Define the classes Define the instances Define

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

Page 35: Frame-Based System Design. Fames vs. Rules General design methodology Define the problem Analyze the domain Define the classes Define the instances Define