March 24 2018 icon2 Desktop0 Desktop1 cut icon3 Desktop2 paste icon3 icon1 icon3 Its time to model software In the previous examples there was just one or a small number of solutions instances satisfying the constraints ID: 782757
Download The PPT/PDF document "Desktop model Roger L. Costello" is the property of its rightful owner. Permission is granted to download and print the materials on this web site for personal, non-commercial use only, and to display it on your personal computer provided you do not modify the materials and that you retain all copyright notices contained in the materials. By downloading content from our website, you accept the terms of this agreement.
Slide1
Desktop model
Roger L. CostelloMarch 24, 2018
icon2
Desktop0
Desktop1
cut
icon3
Desktop2
paste
icon3
icon1
icon3
Slide2It’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.
Slide3Model 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.
Slide4Problem 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.
Slide5Version #1: Simple Model
Let’s model a desktop that has just two icons named A and B, and a cut operation that removes B.
A
B
Desktop (first)
A
Desktop (second)
cut
Slide6A 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
).
Desktop0
Desktop0
Desktop1
A
B
A
icons
Desktop0 is mapped to this set: {A, B}
Desktop1 is mapped to this (singleton) set: {A}
Slide7Order 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.
Slide8There are two icons, A and B
abstract
sig
Icon {}
one
sig A
extends Icon {}
one
sig B
extends Icon {}
enum
Icon { A, B }
Alternatively:
Slide9Constrain the first desktop to contain both icons, the second desktop to contain just A
fact
{
first.icons = A + B
first.next.icons = A
}
Slide10Specify in the
run command that the instance is to contain 2 Desktops.
run {} for
3 but
2 Desktop
Slide11open
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
Slide12Version #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, orThe third Desktop = d + j (where j is an icon not on d)And so forth.
Slide13Here is one of the instances that Alloy generated:
icon2
Desktop0
Desktop1
cut
icon3
Desktop2
paste
icon3
icon1
icon3
Desktop3
icon3
icon1
icon0
paste
Desktop4
cut
icon3
icon1
Slide14Desktop signature is same as before
open
util/ordering[Desktop]sig
Desktop {
icons: set
Icon
}
Slide15Instead of enumerating the icons, have a set of icons:
sig
Icon {}
Slide16The first Desktop contains a set of icons:
fact
init {
some
i: set
Icon | first.icons = i
}
Slide17A 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)
}
Slide18open
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