Desktop model Desktop 0 cut icon 3 icon

  • Slides: 18
Download presentation
Desktop model Desktop 0 cut icon 3 icon 2 Desktop 1 paste icon 3

Desktop model Desktop 0 cut icon 3 icon 2 Desktop 1 paste icon 3 icon 1 icon 3 Roger L. Costello March 24, 2018

It’s time to model software • In the previous examples there was just one

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.

Model a desktop and two operations • In this example we model software that

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.

Problem Statement • Model a desktop, its icons, and cut and paste operations. •

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.

Version #1: Simple Model • Let’s model a desktop that has just two icons

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

A set of Desktops, each with a set of icons sig Desktop { icons:

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 Desktop 0 A Desktop 0 B Desktop 1 A Desktop 0 is mapped to this set: {A, B} Desktop 1 is mapped to this (singleton) set: {A}

Order the Desktops -- there is a first Desktop, a second Desktop, etc. open

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.

There are two icons, A and B abstract sig Icon {} one sig A

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 }

Constrain the first desktop to contain both icons, the second desktop to contain just

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

Specify in the run command that the instance is to contain 2 Desktops. run

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

open util/ordering[Desktop] sig Desktop { icons: set Icon } enum Icon { A, B

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

Version #2: Arbitrary icons, cut/paste operations • We want the model to represent any

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.

Here is one of the instances that Alloy generated: Desktop 0 cut icon 3

Here is one of the instances that Alloy generated: Desktop 0 cut icon 3 icon 2 Desktop 1 paste icon 3 icon 1 icon 3 paste Desktop 3 Desktop 4 icon 1 icon 3 cut icon 0 icon 3 icon 1

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

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

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

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

The first Desktop contains a set of icons: fact init { some i: set

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

A Desktop cannot hold just any set of icons, a Desktop is derived from

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

open util/ordering[Desktop] sig Desktop { icons: set Icon } sig Icon {} fact init

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 Lab 3