Sei sulla pagina 1di 35

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-based system:
Collects the related facts
Represents them as slots within a single frame structure

Frame Boiler
Temprature
Pressure
Water level
Condition

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

50

60

70

Setting
Temperature
50

60

70

Mode
Heat

Furnace

Air

Air conditioner

Task 2 : Analyze the domain


define objects, Features,Events,Architecture

Objects

Room ,
Furnace, Air conditioner,
Thermostat, Room temperature,
Sensor

Object features
ROOM Features
Thermostat
Furnace
AC
Sensor
occupancy

FURNACE
Room
State
Thermostat

THERMOSTAT
Room
Furnace
AC
Sensor
Mode
Setting
temperature

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

Architecture
Generalization
Aggregation
Association

: Kind of relationship
: Part of relationship
: Semantic relationship

Thermostat

Thermostat 1

Thermostat 2

Thermostat 3

Room

Livingroom

Kitchen

Bedroom

Task3 : Define the classes

Define the problem


Kappa:
Analyze the domain
MakeClass(THERMOSTAT,Root)
Define the classes
Also possible via graphical menu
Define
the instances
Define the rules
Define object communications
Kappas advantage:
window-based
Design
the interface
development feature , includes message
Evaluate
the system
passing
Expand the system

Class name:

Properties:

Room

Furnace
Occupancy
Thermostat
AC

Methods:

Unoccupied

Class name:

Thermostat
Furnace

Properties:

AC
Mode

Heat

Setting

68

Temperature

65

Room

Methods:

Class name:

AC

Properties:
Room

State
Thermostat

Methods:

off

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
Furnace

Furnace1

Kitchen
Furnace

Furnace2

Bedroom
Furnace

Furnace3

occupancy unoccupied

occupancy unoccupied

occupancy unoccupied

thermostat thermostat1

thermostat thermostat2

thermostat thermostat3

AC

AC1

AC

AC2

AC

AC3

Task5 : Define the Rules


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.
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
number of objects!
- overuse of methods
- methods are not appropriate for representing heuristics

a large

Task6 : Define object communcations


Demons:

IF-NEEDED
IF-CHANGED

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)

Class name:

Thermostat
IF-CHANGED

Properties:

Methods:

Mode

heat

Unit-Control

Setting

68

Unit-Control

Temperature

65

Unit-Control

Air

Self:Mode=Air;

Heat

Self:Mode=Heat;

Init

forAll (x|Thermostat)
|ResetValue(x:setting);
RestValue(x:mode);
ResetValue(x:Temperature);

Class name:

Thermostat

Methods:

Body:

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 ..; };

Furnace

Class name:

IF-CHANGED

Room
State

OFF

Heat

Thermostat

Methods:
Name

Body

OFF

SetValue (Self:State,OFF)

ON

SetValue (Self:State,ON)

Init

resetvalue

Heat

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

Task7 : Design the interface


Most shells offer a toolkit of graphical objects
- Observable displays
- Control displays

Task8 : Evaluate the system


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

Trace of operation
1.
2.

3.
4.
5.

User increases thermostat handler in interface


With each increment, setting slot of thermostat1
increments. Each increment causes the IF-CHANGED
method unit control to fire.
When setting reaches temperature + 5, unit control
sends an On msg to Furnace1
Change of furnace state, causes Heat to fire

Task9 : Expand the system


Deepening knowledge
By adding new objects related to existed
use of generalization and part of and.

Broadening knowledge
Addition of new events or objects

ones

Potrebbero piacerti anche