CS195Y Lecture 8

2/15/16

Announcement: Alloy 2 is due Thursday
Note about Homework: You’re using Events to model what’s happening in the system. But you need to choose which events are actually relevant. You could model getting on and off the boat, for example, but you don’t really need to (and if you do, you will need up to 30 or so Events). All you need is a Cross event, which covers getting on, crossing the river, and getting off the boat.

Modeling Banner Continued
sig Trace {
...
}
{
...
}

is the same as

sig Trace {
...
}

fact {
  all t : Trace | ...
}
Ordering Module

Import util/ordering to get a total ordering on all instances of a sig (in this case Event) by including the line open util/ordering[Event] at the top.
You get first, which gives you the first Event, and next which is a relation from each event to the next event.
Total ordering: An exact order of every single item exactly once. It’s different than a sequence, because you can have a sequence that only has some events, and you can have a sequence that repeats an element.
When using the ordering module, we need two facts:
In the first fact, we’re trying to give a fact that constrains the first state, but we have an ordering on events, so we use first.pre to get the first state. Now we want to say that there is no student in any class (because we haven’t had an AddStudent events yet), so we say no first.pre.roster
When looking at instances with Events, it can be helpful to Projet over Event (in the visualizer), which will show only a pair of states at a time that you can cycle through.

fact initial {
  no first.pre.roster
}
fact transition {
  all e : Event - last |
    e.next.pre = e.post
}

The transition fact is unsatisfiable. Why?
When looking at an unsatisfiable instance, you can change your SAT solver in Options to “MiniSat with Unsat Core”. This will give you a minimum set of constraints in your model that are unsatisfiable, which can be helpful to try to narrow down your error.
Important Note about Ordering Module: The ordering module will force you to have exactly the number of instances possible up to the bound for that sig. So in our example, we say run {} for 4, but under the hood, the Ordering Module turns that into exactly 4 Event. This is why we get no instance found, because there is no instance with 4 Events and 4 States. We need 5 States to exist in order to have exactly 4 Events. (Note: this is one of the advantages to using seq instead of util/ordering).
You can also write and use your own modules. Just save stuff into a separate file, and then open it the same way you would util/ordering. Note that this makes the visualizer more complicated because it shows you which sigs came from the module and which are in your file.
finalgrades : Student -> Grade defaults to a set of Student -> Grade rows
finalgrades : Student -> one grade is a set where every Student has exactly one grade.
finalgrades : Student -> lone grade allows the option of incompletes (or Students without grades)