Coronavirus (Covid-19): Latest updates and information
Skip to main content Skip to navigation

Lab 4: Basic mechanics of modelling with definitive scripts

Preliminaries

First create a personal directory called lab4 within the cs405practical directory you set up in Lab 3. Make a copy of the directory

/dcs/emp/empublic/projects/roomviewerYung1991/

  within your lab4 subdirectory. On Linux, you can do this by making lab4 your current directory and typing

cp -r /dcs/emp/empublic/projects/roomviewerYung1991 .

Also copy the contents of the ~empublic/teaching/cs405/lab4 directory into your lab4 directory, using:

cp ~empublic/teaching/cs405/lab4/* .

For background references relevant to this lab, refer to the online material associated with Lectures 5 and 6.


Exercise 1: Tracing and interpreting specified interactions with the roomviewerYung1991 model

Within your lab4 directory, launch the EDEN interpreter from the command line:

~empublic/bin/tkeden

This sets up an input window.

  • At any given time, the current state of the interpreter is specified by a script. Initially, you can think of this script as empty: it has no (modeller-supplied) definitions in it.
  • When modelling state in the most primitive way, you enter the definitions by hand via the input window. At any stage, you can enter new definitions or change existing definitions, and press Accept.
  • Each definition has an observable on its LHS, and a formula as its RHS. It specifies a dependency.
  • Definitions in Eden are specified using the keyword: is. If you want to define the value of an observable to be the current value of a formula (as in traditional programming assignment), you replace is by =.
  • At any stage, you can inspect the current set of values of observables and dependencies by invoking writeln() and ? with the name of an Eden observable. You can also inspect definitions in the Donald and Scout notations via the View option on the EDEN input window, and find additional information about Scout observables by using ? in conjunction with %scout.

Using the File menu in the Eden input window, navigate to the roomviewerYung1991 subdirectory, and execute the file Run.e. Briefly explore some of the simple changes that can be made to the state of the model through button interaction.

The files scout1.s, donald2.d, sde3.eden and sde4.eden in your lab4 durectory record the history of short instructive interactions with the roomviewerYung1991 model. Open each of these files in your favourite editor in turn, paste their contents definition-by-definition into the Eden Input window, remembering to press Accept or the keyboard shortcut Alt-a. Interpret the results.


Exercise 2: Furthering your understanding of the roomviewerYung1991 script

Reload the roomviewerYung1991 model into EDEN. By examining the observables in the roomviewer.s script through interaction via the EDEN interface or otherwise, answer the following questions:

  • What is the current definition of table/SW?
  • How would you print out the current value of desk/drawer/k every time that it is changed?
  • Why is the line that represents the cable for the table lamp dashed?
  • The observable cableIsShort is set to true when the distance between the socket and the lamp exceeds the length of the cable. What observables affect the value of cableIsShort? Give representative examples of redefinitions that resolve the problem of the short cable, together with their interpretations in the referent.

Exercise 3: Making changes to the roomviewerYung1991 script

  • Adapt the model so that:
    • the cable is coloured red when it is not long enough
    • the door is coloured green when open and red when shut
    • the door is a sliding door
    • the door is a sliding door which can be opened and closed by passing through intermediate states
  • Introduce the filing cabinet construal that was the subject of Lab 3 into the model.
  • Place a small circle at the centre of the lamp to indicate a bulb, and set its attributes so that it is coloured solid yellow or black according to whether the lamp is on or off.
  • Attach to the centre of the table a Donald label that displays its current coordinates.
  • Explain why nothing happens if you modify the roomviewerYung1991 model by introducing the definition of the rotated table in the Appendix to this labsheet. How do you resolve this problem? [Hint: you may need to make use of Eden to define some Donald observables.]

Appendix to Labsheet 4

%donald

## first redefine coordinates of table relative to its centre

within table {
        point centre
        SW = centre - {width div 2, length div 2}
        NW = centre - {width div 2, -length div 2}
        SE = centre + {width div 2, -length div 2}
        NE = centre + {width div 2, length div 2}
}

## now define the rotation

within table {
        point centre
        real tablerotangle
        SW = centre - rot({width div 2, length div 2}, {0,0}, tablerotangle)
        NW = centre - rot({width div 2, -length div 2}, {0,0}, tablerotangle)
        SE = centre + rot({width div 2, -length div 2}, {0,0}, tablerotangle)
        NE = centre + rot({width div 2, length div 2}, {0,0}, tablerotangle)
}

## specify angles in radians - as floating point numbers

table/tablerotangle = pi div 4