Model Validation
We now wish to write EVL constraints for the Conference DSL, which check that:
- C1: The speaker and the discussant of a talk are two different persons
- C2: The duration of a talk is a positive number
- C3: The start time of a slot (i.e. break, track) is before its end time
Constraints C1-C3
Below are reference implementations of these constraints.
conference-constraints.evl
import "conference-queries.eol";
context Talk {
constraint C1 {
check : self.speaker <> self.discussant
message : "The speaker and the discussant of talk "
+ self.`title` + " are the same person"
}
constraint C2 {
check : self.duration > 0
message : "The duration of talk " + self.`title` +
" is not a positive number"
}
}
context Slot {
constraint C3 {
check : self.start.isBefore(self.end)
message {
var msg = "";
if (self.isTypeOf(Break)) {
msg = "Break " + self.reason;
}
else {
msg = "Track " + self.`title`;
}
msg = msg + " on " + Day.all.selectOne(d|d.slots.includes(self)).name;
msg = msg + " ends before it starts";
return msg;
}
}
}
- Both
C1andC2check the validity ofTalkmodel elements. As such they can be placed under the sameTalkcontext. - The property
titleappears between back-ticks in the expressionself.`title`because it is a reserved word (keyword) in EVL - In C3 we need to compare two
HH:MM-encoded dates. We’ve already written code that does this in the first part of this practical, which we reuse here by importingconference-queries.eol.
conference-queries.eol
// Get the hours part of the string
// and convert it to an integer
// e.g. for 15:45 it returns 15
operation String getHours() {
return self.split(":").at(0).asInteger();
}
// Same for the minutes part
operation String getMinutes() {
return self.split(":").at(1).asInteger();
}
// Compares the string on which it is invoked
// with its time parameter e.g.
// "15:15".isBefore("18:00") returns true
operation String isBefore(time : String) {
return (self.getHours() < time.getHours()) or
(self.getHours() == time.getHours() and
self.getMinutes() < time.getMinutes());
}
Evaluating constraints
- Create a new text file with the name
conference-constraints.evlin yourconference-dslproject and type/copy the implementation of constraints C1-C3 in it.

- Create an
EVL Validationrun configuration to execute the constraints against theconference.modelmodel. The process of setting up the run configuration is very similar to the process you followed to run your EOL program, so we won’t repeat the instructions alongside the following screenshots.









- Running the EVL program should report three unsatisfied constraints in the
Validationview of Eclipse.

- Fix these issues in
conference.modeland re-run the EVL constraints until no errors are reported in theValidationview.
Exercise
Write and run the following constraints for the Conference DSL similarly to C1-C3 demonstrated above:
- C4: A track is long enough to accommodate the talks it contains
- e.g. a track that is one hour long cannot accommodate three 30-minute talks
- C5: Breaks don’t overlap with tracks
- C6: Slots that overlap in time do not use the same room
Solutions
Model solutions for the exercises are available in this ZIP file.