-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCotroneDeCiechiDeidier.als
More file actions
355 lines (279 loc) · 12.9 KB
/
CotroneDeCiechiDeidier.als
File metadata and controls
355 lines (279 loc) · 12.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
-- All possible Tournament Status
abstract sig TournamentStatus {}
one sig SUBSCRIPTION_TOURNAMENT extends TournamentStatus {}
one sig ACTIVE_TOURNAMENT extends TournamentStatus {}
one sig NON_ENDABLE extends TournamentStatus {}
one sig ENDED_TOURNAMENT extends TournamentStatus {}
-- All possible Battle Status
abstract sig BattleStatus {}
one sig SUBSCRIPTION_BATTLE extends BattleStatus {}
one sig ACTIVE_BATTLE extends BattleStatus {}
one sig CONSOLIDATION_STAGE extends BattleStatus {}
one sig ENDED_BATTLE extends BattleStatus {}
-- All possible Badge Status
abstract sig BadgeStatus {}
one sig CREATED extends BadgeStatus {}
one sig ASSIGNED extends BadgeStatus {}
one sig BADGE_INVALID extends BadgeStatus {}
--Boolean definition
abstract sig Bool {}
one sig True, False extends Bool {}
--Simplified Account view: only Username and Password
sig Username {}
sig Password {}
abstract sig Account {
username : one Username,
password : one Password
}
sig Educator extends Account {
createdTournaments : set Tournament
}
sig Student extends Account {}
sig Tournament {
status : one TournamentStatus,
battles : set Battle,
educators : some Educator,
participants : set Student,
creation_date : one Int,
registration_deadline : one Int,
badges : set Badge
} { registration_deadline > creation_date and creation_date >= 0 }
sig Battle {
status : one BattleStatus,
creation_date : one Int,
registration_deadline : one Int,
submission_deadline : one Int,
creator : one Educator,
participants : set Team,
min_team_dim : one Int,
max_team_dim : one Int,
needs_manual_eval : one Bool,
manual_eval_inserted : one Bool
} { registration_deadline > creation_date and
submission_deadline > registration_deadline and
max_team_dim >= min_team_dim and
min_team_dim > 0 and
creation_date >= 0
}
sig Badge {
status : one BadgeStatus,
creator : one Educator,
owner : lone Student,
creation_date : one Int
} { creation_date >= 0 }
sig Team{
members : some Student,
subscription_date : one Int
} { subscription_date >= 0 }
-- Used to model current time
sig currTime {
time : one Int
} { time > 0 }
-- FACTS
-- Account:
-- No duplicate Usernames
fact {no disj a1, a2 : Account | a1.username = a2.username }
-- All Passwords belong to an Account
fact {all p : Password | one a : Account | a.password = p }
-- Tournament:
-- No two tournaments are equal
fact { no disj t1, t2 : Tournament | t1 = t2 }
-- All battles of one tournament has the creator that is one educator in that tournament
fact { all b : Battle | all t : Tournament | b in t.battles implies
( one e : Educator | e = b.creator and ( e in t.educators )) }
-- If there is at least one battle not ended the tournament can't be closed
fact { all t : Tournament | ( t.status = NON_ENDABLE ) iff ( one b : Battle | b in t.battles and
b.status != ENDED_BATTLE ) }
-- One tournament has subscriptions open if and only if the deadline for subscriptions has not been reached yet
fact { all t : Tournament | t.status = SUBSCRIPTION_TOURNAMENT iff
t.registration_deadline > currTime.time }
-- If a tournament has been closed, it will be always closed
fact { all t : Tournament | always( t.status = ENDED_TOURNAMENT implies
after always t.status = ENDED_TOURNAMENT ) }
-- During the subscription phase a tournament can't have battles
fact { all t : Tournament | t.status = SUBSCRIPTION_TOURNAMENT implies
# t.battles = 0 }
-- If and only if a tournament is active or ended it has no battle that are not ended
fact { all t : Tournament | ( t.status = ACTIVE_TOURNAMENT or t.status = ENDED_TOURNAMENT ) iff
no b : Battle | b in t.battles and b.status != ENDED_BATTLE }
-- For all tournaments exists only one creator
fact { all t : Tournament | one e : Educator | e in t.educators and t in e.createdTournaments }
-- All the battles in a tournament are created after the tournament creation
fact { all t : Tournament | all b : Battle | b in t.battles implies
b.creation_date >= t.creation_date }
-- There are no tournaments created by two or more educators
fact { no disj e1, e2 : Educator | all t : Tournament | e1 != e2 and
t in e1.createdTournaments and t in e2.createdTournaments }
-- A battle can be part only of one tournament
fact { no disj t1, t2 : Tournament | all b : Battle | t1 != t2 and
b in t1.battles and b in t2.battles }
-- A tournament will be closed if after the registration deadline there are no students registrated
fact { all t : Tournament | currTime.time >= t.registration_deadline and
# t.participants = 0 implies t.status = ENDED_TOURNAMENT }
-- Battle:
-- No two battles are equal
fact { no disj b1, b2 : Battle | b1 = b2 }
-- All battles belong to a tournament
fact { all b : Battle | one t : Tournament | b in t.battles }
-- One battle has subscriptions open if and only if the deadline for subscriptions has not been reached yet
fact { all b : Battle | b.status = SUBSCRIPTION_BATTLE iff
b.registration_deadline > currTime.time }
-- A team can't register in a battle after the subscription phase
fact { all b : Battle | all t : Team | t in b.participants implies
t.subscription_date < b.registration_deadline }
-- One battle is active if and only if the deadline for submissions has not been reached yet
fact { all b : Battle | b.status = ACTIVE_BATTLE iff
b.submission_deadline > currTime.time and currTime.time >= b.registration_deadline }
-- One battle is in consolidation phase if and only if the deadline for submissions has been reached and it needs the manual evaluation
fact { all b : Battle | b.status = CONSOLIDATION_STAGE iff
b.submission_deadline <= currTime.time and b.needs_manual_eval = True }
-- One battle is ended if and only if the deadline for submissions has been reached and it doesn't need the manual evaluation or
-- the manual evaluation is inserted
fact { all b : Battle | b.status = ENDED_BATTLE iff
b.submission_deadline <= currTime.time and ( b.needs_manual_eval = False or
( b.needs_manual_eval = True and b.manual_eval_inserted = True )) }
-- If a battle has ended, it will be always ended
fact { all b : Battle | always( b.status = ENDED_BATTLE implies
after always b.status = ENDED_BATTLE ) }
-- All the teams in a battle satisfy the members count constraints
fact { all b : Battle | all t : Team | t in b.participants implies
( # t.members >= b.min_team_dim ) and ( # t.members =< b.max_team_dim ) }
-- If in a battle there are no registered teams, it will be closed automatically
fact { all b : Battle | ( b.registration_deadline <= currTime.time and # b.participants = 0 ) implies
b.status = ENDED_BATTLE }
-- If a battle don't need a manual evaluation, a manual evaluation can not be inserted
fact { all b : Battle | b.needs_manual_eval = False implies
b.manual_eval_inserted = False}
-- There are no battles created before the tournament subscription phase
fact { all t : Tournament | no b : Battle | b in t.battles and b.creation_date <= t.registration_deadline }
-- Badge:
-- No two badges are equal
fact { no disj b1, b2 : Badge | b1 = b2 }
-- All badges belong to a tournament
fact { all b : Badge | one t : Tournament | b in t.badges }
-- A badge can be created only by the educator that has created the tournament
fact { all e : Educator | all t : Tournament | all b : Badge | ( t in e.createdTournaments and
b in t.badges ) iff e = b.creator }
-- A badge can be created only when a tournament is created
fact { all b : Badge | all t : Tournament | b in t.badges implies
b.creation_date = t.creation_date }
-- If and only if a badge is not already linked to a student, it's CREATED
fact { all b : Badge | # b.owner = 0 iff
( b.status = CREATED or b.status = BADGE_INVALID ) }
-- A badge is assigned if and only if there is a student of the closed tournament that has been linked to the badge
fact { all b : Badge | all t : Tournament | b.status = ASSIGNED iff
( b in t.badges and t.status = ENDED_TOURNAMENT and # b.owner = 1 and b.owner in t.participants ) }
-- If and only if the tournament is closed and there are no battles in it, the badge is invalid
fact { all b : Badge | all t : Tournament | ( b in t.badges and
t.status = ENDED_TOURNAMENT and # t.battles = 0 ) iff
b.status = BADGE_INVALID }
-- If the badge is assigned it will always be that
fact { all b : Badge | always( b.status = ASSIGNED implies
after always b.status = ASSIGNED ) }
-- If the badge is invalid it will always be that
fact { all b : Badge | always( b.status = BADGE_INVALID implies
after always b.status = BADGE_INVALID ) }
-- If a badge is invalid it can't have an owner
fact { all b : Badge | no s : Student | b.status = BADGE_INVALID and s = b.owner }
-- If a tournament is closed and has at least one battle all the badges are valid and must be assigned to a student in the tournament
fact { all t : Tournament | ( t.status = ENDED_TOURNAMENT and # t.battles > 0 ) implies
( all b : Badge | one s : Student | b in t.badges and b.status = ASSIGNED and s = b.owner and s in t.participants ) }
-- Team:
-- No two teams are equal
fact { no disj t1, t2 : Team | t1 = t2 }
-- All the teams are registered at least in one battle
fact { all t : Team | one b : Battle | t in b.participants }
-- All the teams are made up by only students that are registered in the tournament of that battle
fact { all t : Tournament | all b : Battle | all team : Team | all s : Student |
b in t.battles and team in b.participants and s in team.members implies
s in t.participants }
-- If a student is in a team for a battle, it can't be also a member of another team in the same battle
fact { all b : Battle | all s : Student | no disj t1, t2 : Team | t1 != t2 and (t1 in b.participants and t2 in b.participants ) and
( s in t1.members and s in t2.members ) }
-- A team can be registered in a battle only after the battle creation and before the deadline
fact { all b : Battle | all t : Team | t in b.participants implies
( t.subscription_date > b.creation_date and t.subscription_date < b.registration_deadline ) }
-- ASSERTIONS
-- Check that every active battle are in a not closed tournament and they are created by an educator that can manage that tournament and that
-- all the teams in that battle are formed by students registered in the tournament
assert activeBattle {
all b : Battle | ( b.status = ACTIVE_BATTLE implies (( one t : Tournament | b in t.battles and t.status = NON_ENDABLE and
( one e : Educator | e = b.creator and e in t.educators ) and ( some team : Team | team in b.participants and
( all s : team.members | s in t.participants )))))
}
check activeBattle
-- Check that all the closed tournament are those with no registrations at the end of the subscription time and those without active battle
assert closeTournament {
all t : Tournament | ( t.status = ENDED_TOURNAMENT implies (( currTime.time >= t.registration_deadline and
# t.participants = 0 ) or ( no b : Battle | b in t.battles and b.status != ENDED_BATTLE )))
}
check closeTournament
-- Check that in every closed tournament all the badges are invalid or all the badges are assigned at one student
assert assignedBadges {
all t : Tournament | ( t.status = ENDED_TOURNAMENT implies
(( all b : t.badges | b.status = BADGE_INVALID ) or
( all b : t.badges | one s : t.participants | b.status = ASSIGNED and s = b.owner )))
}
check assignedBadges
-- Check that if a tournament is not endable is because there are active battles or battles that are waiting for a manual evaluation
-- or battle that are in subscription phase
assert nonClosableTournaments {
all t : Tournament | ( t.status = NON_ENDABLE implies
( some b : Battle | b.status = ACTIVE_BATTLE or ( b.needs_manual_eval = True and b.manual_eval_inserted = False ) or
b.status = SUBSCRIPTION_BATTLE ))
}
check nonClosableTournaments
-- Check that if a badge has not an owner is because the badge is invalid or because it's a badge of a tournament that is not already closed
assert notAssignedBadges {
all b : Badge | ( # b.owner = 0 implies
(( b.status = BADGE_INVALID ) or ( one t : Tournament | t.status != ENDED_TOURNAMENT and b in t.badges )))
}
check notAssignedBadges
-- PREDICATES
-- Generate a World to show the system's Tournament
pred tournamentWorld {
# Tournament = 1
# Battle = 2
# Badge = 3
# Team = 1
# Student = 1
# Educator = 1
all t : Tournament | t.status = NON_ENDABLE
}
run tournamentWorld
-- Generate a World to show the system's Battle
pred battleWorld {
# Tournament = 1
# Battle = 3
# Badge = 0
# Team = 3
}
run battleWorld
-- Generate a World to show the system's Educator
pred educatorWorld {
# Battle = 0
# Badge = 0
# Educator = 3
one t : Tournament | all e : Educator | e in t.educators
}
run educatorWorld
-- Generate a World to show the system's Student
pred studentWorld {
# Student = 3
# Battle = 1
# Team = 2
one t : Tournament | all s : Student | s in t.participants
all s : Student | one t : Team | s in t.members
}
run studentWorld for 4
-- Generate a complete Worlds
pred completeWorld {
# Tournament = 1
# Battle = 3
# Badge = 3
# Student = 3
# Educator = 3
# Team = 2
all s : Student | one t : Team | s in t.members
}
run completeWorld for 6