Presentation is loading. Please wait.

Presentation is loading. Please wait.

Desktop model Roger L. Costello March 24, 2018 Desktop0 Desktop1

Similar presentations


Presentation on theme: "Desktop model Roger L. Costello March 24, 2018 Desktop0 Desktop1"— Presentation transcript:

1 Desktop model Roger L. Costello March 24, 2018 Desktop0 Desktop1
cut paste icon1 icon3 icon2 icon3 icon3 Roger L. Costello March 24, 2018

2 It’s time to model software
In the previous examples there was just one or a small number of solutions (instances) satisfying the constraints. With software there are usually many solutions.

3 Model a desktop and two operations
In this example we model software that allows users to add and remove icons from a desktop. A cut operation removes one icon from the desktop. A paste operation adds one icon to the desktop.

4 Problem Statement Model a desktop, its icons, and cut and paste operations. We will create two versions of the model: Version #1: Hardcode the icons. Version #2: Arbitrary set of icons.

5 Version #1: Simple Model
Let’s model a desktop that has just two icons named A and B, and a cut operation that removes B. Desktop (first) Desktop (second) cut A B A

6 A set of Desktops, each with a set of icons
sig Desktop { icons: set Icon } The set keyword means that icons maps each Desktop to a set of Icon (an Icon is either A or B). icons Desktop0 A Desktop0 is mapped to this set: {A, B} Desktop0 B Desktop1 A Desktop1 is mapped to this (singleton) set: {A}

7 Order the Desktops -- there is a first Desktop, a second Desktop, etc.
open util/ordering[Desktop] “first” denotes the first Desktop. “first.icons” denotes the icons on the first Desktop. “prev” denotes the previous Desktop. Suppose d denotes one of the Desktops, then d.prev.icons denotes the icons on the previous Desktop. “last” denotes the last Desktop. “next” denotes the next Desktop.

8 There are two icons, A and B
abstract sig Icon {} one sig A extends Icon {} one sig B extends Icon {} Alternatively: enum Icon { A, B }

9 Constrain the first desktop to contain both icons, the second desktop to contain just A
fact { first.icons = A + B first.next.icons = A }

10 Specify in the run command that the instance is to contain 2 Desktops.
run {} for 3 but 2 Desktop

11 open util/ordering[Desktop]
sig Desktop { icons: set Icon } enum Icon { A, B } fact { first.icons = A + B first.next.icons = A } run {} for 3 but 2 Desktop

12 Version #2: Arbitrary icons, cut/paste operations
We want the model to represent any set of icons on the first Desktop. Let d = the first Desktop and i = an icon on the first Desktop. The second Desktop = d - i, or The second Desktop = d + j (where j is an icon not on d) Let d = the second Desktop and i = an icon on the second Desktop. The third Desktop = d - i, or The third Desktop = d + j (where j is an icon not on d) And so forth.

13 Here is one of the instances that Alloy generated:
Desktop0 Desktop1 Desktop2 cut paste icon1 icon3 icon2 icon3 icon3 paste Desktop4 Desktop3 cut icon1 icon0 icon1 icon3 icon3

14 Desktop signature is same as before
open util/ordering[Desktop] sig Desktop { icons: set Icon }

15 Instead of enumerating the icons, have a set of icons:
sig Icon {}

16 The first Desktop contains a set of icons:
fact init { some i: set Icon | first.icons = i }

17 A Desktop cannot hold just any set of icons, a Desktop is derived from its previous Desktop: it has the icons on the previous Desktop, plus or minus one icon fact Desktops_through_cut_and_paste { all d: Desktop - first | (some i: d.prev.icons | d.icons = d.prev.icons - i) or (some i: Icon - d.prev.icons | d.icons = d.prev.icons + i) }

18 open util/ordering[Desktop] sig Desktop { icons: set Icon }
sig Icon {} fact init { some i: set Icon | first.icons = i } fact Desktops_through_cut_and_paste { all d: Desktop - first | (some i: d.prev.icons | d.icons = d.prev.icons - i) or (some i: Icon - d.prev.icons | d.icons = d.prev.icons + i) } run {} for 5 Do Lab3


Download ppt "Desktop model Roger L. Costello March 24, 2018 Desktop0 Desktop1"

Similar presentations


Ads by Google