constraint animation using an object-oriented declarative language jeff gray and stephen schach...

25
Constraint Animation Using an Object-Oriented Declarative Language Jeff Gray and Stephen Schach Vanderbilt University {jgray, srs}@vuse.vanderbilt.edu ACM Southeast Conference 2000 April 7-8, 2000 Clemson, SC

Upload: alfred-jefferson

Post on 03-Jan-2016

225 views

Category:

Documents


0 download

TRANSCRIPT

Constraint Animation Using an Object-Oriented Declarative

Language

Jeff Gray and Stephen SchachVanderbilt University

{jgray, srs}@vuse.vanderbilt.edu

ACM Southeast Conference 2000April 7-8, 2000Clemson, SC

Overview

• Problem Motivation• Specification Animation• UML/OCL• Prolog++• Mapping UML/OCL to Prolog++• Example• Using the Intelligence Server to construct a

simple animation environment• Ideas for Improvement

Problem Motivation

• Fact: Our words are pregnant with meaning– Oxford English Dictionary

• 500 words used most have an average of 23 meanings• “set” has 430 different meanings; 25 pgs. and 60k

words

• The Resulting Problem: Ambiguity – Humorous statements– Military disasters (Tennyson’s poem on Crimean War)

– Large Software Requirements Specification

• Other Problems: Inconsistency & Confusing Verbiage

An Example

“The Landing Pilot is the Non-Handling Pilot until the ‘decision altitude’ call, when the Handling Non-Landing Pilot hands the handling to the Non-Handling Landing Pilot, unless the latter calls ‘go around,’ in which case the Handling Non-Landing Pilot continues handling and the Non-Handling Landing Pilot continues non-handling until the next call of ‘land’ or ‘go around’ as appropriate. In view of recent confusions over these rules, it was deemed necessary to restate them clearly.”

British Airways Memorandum, quoted in Pilot Magazine, December 1996.

Natural Language Problem

• The “Humpty-Dumpty” Syndrome

“When I use a word,” Humpty Dumpty said, in a rather scornful tone,

“it means just what I choose it to mean - nothing more nor less.”

“The question is,” said Alice,

“whether you can make words mean so many different things.”

Lewis Carroll

Collection of Ambiguous or Inconsistent/Incomplete

Statements

“I will bring my bike tomorrow if it looks nice in the morning”“I found a smoldering cigarette left by a horse”

•Check it out:

http://www.vuse.vanderbilt.edu/~jgray/ambig.html

Levels of Formalism

• Categories of formalism:– Informal natural language– Semi-formal notations– Formal specification languages

Familiarity

Mathematical Rigor

Informal

Semi-formal

Formal

• Semi-formal specifications lack the formality for rigorous mathematical verification

• Formal specifications are not customer friendly

“This returns us to the underlying tension in the software process: that between the subjective and the objective, between the holistic mental view and the rigorous formal model. The first describes what is needed: the second ensures that what was requested is delivered.”Blum, Bruce, “A Taxonomy of Software Development Methods,” Communications of the ACM, vol. 37, no. 11, November 1994, pp. 8294.

Levels of Formalism

Graphical Notations

• Petre, Marian, “Why Looking Isn’t Always Seeing: Readership Skills and Graphical Programming,” Communications of the ACM, June 1995, pp. 3344.

UML/OCL

• Enriching a UML diagram with OCL constraints can aid in improving the common understanding of the underlying model (natural language is not used to describe the effect of the constraint)

• Several groups are working hard to rigorously define the UML semantics using formal languages (“The Precise UML Group”); several workshops exist

• A rigorous semantics would permit a type of “executable specification” to be performed

Specification Animation

• Offers a type of throw-away prototype resulting from an executable specification

• Can aid in making the underlying formalism transparent to end-user

• Wide body of literature:– Debate between tradeoff of expressiveness with

the speed of executability– Most efforts focus on animating Z– Declarative programming languages are often

used to aid in the mapping from the specification(Prolog is the language used with most frequency)

Prolog++

• Vendor: Logic Programming Associates• Combines the declarative power and inference

engine of Prolog with the benefits of OOP• Supports:

– structural organization of Prolog predicates in classes– single/group of messages can be sent to single/group

of objects– data driven programming - allows daemons to be

attached to crucial events (construction/destruction, value changes)

– multiple inheritance and polymorphism

• Drawback: Very primitive environment; costly

Mapping UML/OCL to Prolog++

• UML class diagrams provide:– the corresponding class structure for the Prolog++ code– attributes/types and method names for Prolog++ code– aggregation/relations that must be Prolog++ parts

• Many OCL collection operations have direct mappings to Prolog++ predicates (we get these free!)– OCL forall can often be mapped to Prolog++ all instance

– OCL select -> all instance sucthat...

• An important asset is a library of Prolog++ predicates that emulate standard OCL operations– e.g., oclIsTypeOf, oclType, oclIsKindOf, size

Mapping UML/OCL to Prolog++

• oclIsTypeOf:– A reflective class attribute must be defined, e.g.:

class attributes

class_type = ‘outputPort’.

– operator then defined in Prolog++ as:oclIsTypeOf(AType) :- self@class_type = AType.

• size:– A class attribute called size_att must be defined for each class– Define a simple library function to increment size_att:

size_func :- size_att += 1.– Generic size is then defined as:

size(S) :- size_att := 0, (all instance class) <- size_func, S = @size_att.

Example

Preamp PowerAmp

1

Mic

1

OutputPort

Z_out : int

1 IO_Device

1

1

Speaker

1

InputPort

Z_in : int1

1

dst0..*Port 0..*

0..* src0..*Connection

Example Constraint 1

• It is invalid to connect an input port to another input port, or an output port to another output port

• In OCL, this can expressed as:

Connection->forAll(c | c.src.oclIsTypeOf(OutputPort) and c.dst.oclIsTypeOf(InputPort))

• In Prolog++:

inv_Connection :- (all instance class)<- (@src<-oclIsTypeOf('outputPort'), @dst<-oclIsTypeOf(‘inputPort’)).

Example Constraint 2

• Microphones can only connect to preamps; preamp outputs can only connect to poweramps; poweramp outputs only to speakers

• In OCL, this can expressed as (Microphone->Preamp):

Mic->forAll(m | m.OutputPort.dst.oclIsTypeOf(PreAmp))

• In Prolog++:

inv_Mic_Dst :- (all instance class)<-(outputPort@dst<- oclIsTypeOf(’preAmp')).

Example Constraint 3

• At least one poweramp must exist in an audio system• In OCL, this can expressed as (Microphone->Preamp):

PowerAmp.allInstances->size >= 1.

• In Prolog++:

inv_powerAmp_existence :- size(S), S >= 1.

Using the Intelligence Server

Prolog++

IntelligenceServer

Customer

Animation Environment

Developers

Query Result

Intelligence Server

Front End

Intelligence Server

Server.DLL Server.OVL

Server.PC

Win-Prolog

User definedProlog code

PRO386W.EXE(runtime kernel)

Intelligence Server

• Six Interface Functions of Server.DLL:– LoadProlog

• initialize/configure WinProlog

– HaltProlog• shut down WinProlog

– InitGoal• initialize a Prolog goal

– CallGoal• call previous goal, return solution, backtrack

– ExitGoal• exit a goal once solutions are no longer needed

– TellGoal• send textual info back to a goal that requires input

Intelligence Server

Front End

Intelligence Server

Server.DLL Server.OVL

Server.PC

Win-Prolog

User definedProlog code

PRO386W.EXE(runtime kernel)

Animation Environment

Translated OCL

Simple Animation Environment

Other Related Applications

Ideas for Improvement

• Current work is very primitive - core functions of an animator are still needed

• Automated Mapping to Prolog++– Retrieve model from Rose (using COM)– Build on current OCL parsers

• Incorporate Interaction (Sequence) Diagrams– an existing sequence diagram can be used as an

example script to drive an animation session– the interactions among objects in an animation

session could be captured to construct a sequence diagram

• Support for pre/post-conditions