aboutsummaryrefslogtreecommitdiffstats
path: root/Domains/simpleScenario/queries/simpleScenarioQueries.vql
diff options
context:
space:
mode:
Diffstat (limited to 'Domains/simpleScenario/queries/simpleScenarioQueries.vql')
-rw-r--r--Domains/simpleScenario/queries/simpleScenarioQueries.vql392
1 files changed, 357 insertions, 35 deletions
diff --git a/Domains/simpleScenario/queries/simpleScenarioQueries.vql b/Domains/simpleScenario/queries/simpleScenarioQueries.vql
index a59715c7..735abdc5 100644
--- a/Domains/simpleScenario/queries/simpleScenarioQueries.vql
+++ b/Domains/simpleScenario/queries/simpleScenarioQueries.vql
@@ -1,11 +1,87 @@
1package queries 1package queries
2 2
3import "http://www.example.com/simpleScenario" 3import "http://www.example.com/simpleScenario"
4import "http://www.eclipse.org/emf/2002/Ecore"
4 5
6//Minimal Failing Example
7@Constraint(severity = "error", key = {l}, message = "this defines the placedOn relation")
8pattern patterThatOnlyWorksWithInt(l : Lane) {
9 Lane.referenceCoord(l, w);
10 check(w <= 2.0);
11}
12
13//////////////
14//Lane
15//////////////
16
17/////////width, numWidth
18@Constraint(severity="error", key={l}, message="x")
19pattern define_numWidth_small(l : Lane) {
20 Lane.width(l, Size::Small);
21 Lane.numWidth(l, nw);
22 check(nw <= 5);
23} or {
24 Lane.width(l, Size::Small);
25 Lane.numWidth(l, nw);
26 check(nw >= 10);
27}
28
29@Constraint(severity="error", key={l}, message="x")
30pattern define_numWidth_medium(l : Lane) {
31 Lane.width(l, Size::Medium);
32 Lane.numWidth(l, nw);
33 check(nw <= 10);
34} or {
35 Lane.width(l, Size::Medium);
36 Lane.numWidth(l, nw);
37 check(nw >= 15);
38}
39
40@Constraint(severity="error", key={l}, message="x")
41pattern define_numWidth_large(l : Lane) {
42 Lane.width(l, Size::Large);
43 Lane.numWidth(l, nw);
44 check(nw <= 15);
45} or {
46 Lane.width(l, Size::Large);
47 Lane.numWidth(l, nw);
48 check(nw >= 20);
49}
50
51/////////referenceCoord
52@Constraint(severity="error", key={l}, message="x")
53pattern define_referenceCoord_horizontalAtOrigin(l:Lane) {
54 1 == count find find_horizontalLaneAtOrigin(l);
55}
56
57private pattern find_horizontalLaneAtOrigin(l:Lane){
58 Lane.orientation(l, Orientation::Horizontal);
59 Lane.referenceCoord(l, rc);
60 Lane.prevLane(l, prev);
61 rc != 0.0;
62}
63
64@Constraint(severity="error", key={l}, message="x")
65pattern define_referenceCoord_verticalAtOrigin(l:Lane) {
66 1 == count find find_verticalLaneAtOrigin(l);
67}
68
69private pattern find_verticalLaneAtOrigin(l:Lane){
70 Lane.orientation(l, Orientation::Vertical);
71 Lane.referenceCoord(l, rc);
72 rc == 0.0;
73}
5 74
6//lanes and lane+widths are in simpleScenarioBoundingBox 75pattern define_referenceCoord_VerticalifMultipleLanes(l1:Lane, l2:Lane) {
76 //calculated risk???
77 Lane.orientation(l1, Orientation::Vertical);
78 Lane.orientation(l2, Orientation::Vertical);
79 Lane.referenceCoord(l1, rc1);
80 Lane.numWidth(l1, nw1);
81 Lane.referenceCoord(l2, rc2);
82 check(rc2 == rc1 + nw1);
83}
7 84
8// actor coords within simpleScenarioBoundingBox
9 85
10//@Constraint(severity = "error", key = {a}, message = "this defines the placedOn relation for vertical lanes") 86//@Constraint(severity = "error", key = {a}, message = "this defines the placedOn relation for vertical lanes")
11//pattern actorOnVerticalLane(a : Actor) { 87//pattern actorOnVerticalLane(a : Actor) {
@@ -19,7 +95,7 @@ import "http://www.example.com/simpleScenario"
19// Lane.orientation(l, Orientation::Vertical); 95// Lane.orientation(l, Orientation::Vertical);
20// Actor.xPos(a, x); 96// Actor.xPos(a, x);
21// Lane.referenceCoord(l, r); 97// Lane.referenceCoord(l, r);
22// Lane.widthNum(l, w); 98// Lane.numWidth(l, w);
23// check(x >= (r + w)); 99// check(x >= (r + w));
24//} 100//}
25// 101//
@@ -35,44 +111,290 @@ import "http://www.example.com/simpleScenario"
35// Lane.orientation(l, Orientation::Horizontal); 111// Lane.orientation(l, Orientation::Horizontal);
36// Actor.yPos(a, y); 112// Actor.yPos(a, y);
37// Lane.referenceCoord(l, r); 113// Lane.referenceCoord(l, r);
38// Lane.widthNum(l, w); 114// Lane.numWidth(l, w);
39// check(y >= (r + w)); 115// check(y >= (r + w));
40//} 116//}
41 117
42@Constraint(severity = "error", key = {a}, message = "this defines the placedOn relation") 118//@Constraint(severity = "error", key = {a}, message = "this defines the placedOn relation")
43pattern actorOnLane(a : Actor) { 119//pattern actorOnLane(a : Actor) {
44 find actorOnVerticalLane(a); 120// find actorOnVerticalLane(a);
45// neg find actorOnHorizontalLane(a); 121//// neg find actorOnHorizontalLane(a);
122//}
123//
124//private pattern actorOnVerticalLane(a : Actor) {
125// Actor.placedOn(a, l);
126// Lane.orientation(l, Orientation::Vertical);
127// Actor.xPos(a, x);
128// Lane.referenceCoord(l, r);
129// Lane.numWidth(l, w);
130// check(x >= r);
131// check(x <= (r + w));
132//}
133
134//@Constraint(severity = "error", key = {l}, message = "this defines the placedOn relation")
135//pattern widthSpec(l : Lane) {
136// Lane.numWidth(l, w);
137// check(w != 5);
138//}
139
140//private pattern actorOnHorizontalLane(a : Actor) {
141// Actor.placedOn(a, l);
142// Lane.orientation(l, Orientation::Vertical);
143// Actor.yPos(a, y);
144// Lane.referenceCoord(l, r);
145// Lane.widthNum(l, w);
146// check(y >= r);
147// check(y <= (r + w));
148//}
149
150//////////////
151//CollisionExists
152//////////////
153
154@Constraint(severity="error", key={c}, message="x")
155pattern collisionExists_timeWithinBound(ss:SimpleScenario, c:CollisionExists) {
156 SimpleScenario.actors.relations(ss, c);
157 SimpleScenario.maxTime(ss, maxTime);
158 CollisionExists. collisionTime(c, cTime);
159 check(cTime >= maxTime);}
160
161@Constraint(severity="error", key={c}, message="x")
162pattern collisionExists_timeNotNegative(c:CollisionExists) {
163 CollisionExists. collisionTime(c, cTime);
164 check(cTime <= 0);}
165
166@Constraint(severity="error", key={a1, c}, message="x")
167pattern collisionExists_defineCollision_y1(a1:Actor, a2:Actor, c:CollisionExists) {
168 Actor.relations(a1, c);
169 CollisionExists.target(c, a2);
170
171 Actor.length(a1, l1);
172 Actor.yPos(a1, yPos1);
173 Actor.ySpeed(a1, ySpeed1);
174 Actor.length(a2, l2);
175 Actor.yPos(a2, yPos2);
176 Actor.ySpeed(a2, ySpeed2);
177 CollisionExists. collisionTime(c, cTime);
178 //check(y_1_bottom > y_2_top
179 check((yPos1 + (ySpeed1 * cTime)) - (l1/2) > (yPos2 + (ySpeed2 * cTime)) + (l2/2));
46} 180}
47 181
48private pattern actorOnVerticalLane(a : Actor) { 182@Constraint(severity="error", key={a1, c}, message="x")
49 Actor.placedOn(a, l); 183pattern collisionExists_defineCollision_y2(a1:Actor, a2:Actor, c:CollisionExists) {
50 Lane.orientation(l, Orientation::Vertical); 184 //This second one is required because we do not want to enforce both a1->c->a2 and a2->c->a1
51 Actor.xPos(a, x); 185 Actor.relations(a1, c);
52 Lane.referenceCoord(l, r); 186 CollisionExists.target(c, a2);
53 Lane.widthNum(l, w); 187
54 check(x >= r); 188 Actor.length(a1, l1);
55 check(x <= (r + w)); 189 Actor.yPos(a1, yPos1);
190 Actor.ySpeed(a1, ySpeed1);
191 Actor.length(a2, l2);
192 Actor.yPos(a2, yPos2);
193 Actor.ySpeed(a2, ySpeed2);
194 CollisionExists. collisionTime(c, cTime);
195 //check(y_1_top < y_2_bottom)
196 check((yPos1 + (ySpeed1 * cTime)) + (l1/2) < (yPos2 + (ySpeed2 * cTime)) - (l2/2));
56} 197}
57 198
58@Constraint(severity = "error", key = {l}, message = "this defines the placedOn relation") 199@Constraint(severity="error", key={a1, c}, message="x")
59pattern widthSpec(l : Lane) { 200pattern collisionExists_defineCollision_x1(a1:Actor, a2:Actor, c:CollisionExists) {
60 Lane.widthNum(l, w); 201 Actor.relations(a1, c);
61 check(w != 5); 202 CollisionExists.target(c, a2);
203
204 Actor.width(a1, w1);
205 Actor.xPos(a1, xPos1);
206 Actor.xSpeed(a1, xSpeed1);
207 Actor.width(a2, w2);
208 Actor.xPos(a2, xPos2);
209 Actor.xSpeed(a2, xSpeed2);
210 CollisionExists. collisionTime(c, cTime);
211 //check(x_1_left > x_2_right)
212 check((xPos1 + (xSpeed1 * cTime)) - (w1/2) > (xPos2 + (xSpeed2 * cTime)) + (w2/2));
62} 213}
63 214
64@Constraint(severity = "error", key = {l}, message = "this defines the placedOn relation") 215@Constraint(severity="error", key={a1, c}, message="x")
65pattern refSpec(l : Lane) { 216pattern collisionExists_defineCollision_x2(a1:Actor, a2:Actor, c:CollisionExists) {
66 Lane.referenceCoord(l, w); 217 //This second one is required because we do not want to enforce both a1->c->a2 and a2->c->a1
67 check(w != 2); 218 Actor.relations(a1, c);
68} 219 CollisionExists.target(c, a2);
69 220
70private pattern actorOnHorizontalLane(a : Actor) { 221 Actor.width(a1, w1);
71 Actor.placedOn(a, l); 222 Actor.xPos(a1, xPos1);
72 Lane.orientation(l, Orientation::Vertical); 223 Actor.xSpeed(a1, xSpeed1);
73 Actor.yPos(a, y); 224 Actor.width(a2, w2);
74 Lane.referenceCoord(l, r); 225 Actor.xPos(a2, xPos2);
75 Lane.widthNum(l, w); 226 Actor.xSpeed(a2, xSpeed2);
76 check(y >= r); 227 CollisionExists. collisionTime(c, cTime);
77 check(y <= (r + w)); 228 //check(x_1_right < x_2_left)
78} \ No newline at end of file 229 check((xPos1 + (xSpeed1 * cTime)) + (w1/2) < (xPos2 + (xSpeed2 * cTime)) - (w2/2));
230}
231
232//////////////
233//SeparationDistance
234//////////////
235@Constraint(severity="error", key={a1, c}, message="x")
236pattern SeparationDistance_near_lb(a1:Actor, a2:Actor, sd:SeparationDistance) {
237 //This second one is required because we do not want to enforce both a1->c->a2 and a2->c->a1
238 Actor.relations(a1, sd);
239 SeparationDistance.target(sd, a2);
240 SeparationDistance.distance(sd, Distance::Near);
241
242 Actor.xPos(a1, x1);
243 Actor.yPos(a1, y1);
244 Actor.xPos(a2, x2);
245 Actor.yPos(a2, y2);
246 //check(dx^2 + dy^2 < 5^2)
247 check((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2) < 5*5);
248}
249
250@Constraint(severity="error", key={a1, c}, message="x")
251pattern SeparationDistance_near_ub(a1:Actor, a2:Actor, sd:SeparationDistance) {
252 //This second one is required because we do not want to enforce both a1->c->a2 and a2->c->a1
253 Actor.relations(a1, sd);
254 SeparationDistance.target(sd, a2);
255 SeparationDistance.distance(sd, Distance::Near);
256
257 Actor.xPos(a1, x1);
258 Actor.yPos(a1, y1);
259 Actor.xPos(a2, x2);
260 Actor.yPos(a2, y2);
261 //check(dx^2 + dy^2 > 10^2)
262 check((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2) > 10*10);
263}
264
265@Constraint(severity="error", key={a1, c}, message="x")
266pattern SeparationDistance_medium_lb(a1:Actor, a2:Actor, sd:SeparationDistance) {
267 //This second one is required because we do not want to enforce both a1->c->a2 and a2->c->a1
268 Actor.relations(a1, sd);
269 SeparationDistance.target(sd, a2);
270 SeparationDistance.distance(sd, Distance::Medium);
271
272 Actor.xPos(a1, x1);
273 Actor.yPos(a1, y1);
274 Actor.xPos(a2, x2);
275 Actor.yPos(a2, y2);
276 //check(dx^2 + dy^2 < 10^2)
277 check((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2) < 10*10);
278}
279
280@Constraint(severity="error", key={a1, c}, message="x")
281pattern SeparationDistance_medium_ub(a1:Actor, a2:Actor, sd:SeparationDistance) {
282 //This second one is required because we do not want to enforce both a1->c->a2 and a2->c->a1
283 Actor.relations(a1, sd);
284 SeparationDistance.target(sd, a2);
285 SeparationDistance.distance(sd, Distance::Medium);
286
287 Actor.xPos(a1, x1);
288 Actor.yPos(a1, y1);
289 Actor.xPos(a2, x2);
290 Actor.yPos(a2, y2);
291 //check(dx^2 + dy^2 > 1^2)
292 check((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2) > 15*15);
293}
294
295@Constraint(severity="error", key={a1, c}, message="x")
296pattern SeparationDistance_far_lb(a1:Actor, a2:Actor, sd:SeparationDistance) {
297 //This second one is required because we do not want to enforce both a1->c->a2 and a2->c->a1
298 Actor.relations(a1, sd);
299 SeparationDistance.target(sd, a2);
300 SeparationDistance.distance(sd, Distance::Far);
301
302 Actor.xPos(a1, x1);
303 Actor.yPos(a1, y1);
304 Actor.xPos(a2, x2);
305 Actor.yPos(a2, y2);
306 //check(dx^2 + dy^2 < 15^2)
307 check((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2) < 15*15);
308}
309
310//////////////
311//CollisionDoesNotExist
312//////////////
313
314@Constraint(severity="error", key={a1, c}, message="x")
315pattern collisionDoesNotExist(a1:Actor, a2:Actor, ss:SimpleScenario, cdne:CollisionDoesNotExist) {
316 //This second one is required because we do not want to enforce both a1->c->a2 and a2->c->a1
317
318 SimpleScenario.actors(ss, a1);
319 SimpleScenario.actors(ss, a2);
320 Actor.relations(a1, cdne);
321 CollisionDoesNotExist.target(cdne, a2);
322 SimpleScenario.maxTime(ss, maxTime);
323
324 Actor.width(a1, w1);
325 Actor.length(a1, l1);
326 Actor.xPos(a1, xPos1);
327 Actor.yPos(a1, yPos1);
328 Actor.xSpeed(a1, xSpeed1);
329 Actor.ySpeed(a1, ySpeed1);
330
331 Actor.width(a2, w2);
332 Actor.length(a2, l2);
333 Actor.xPos(a2, xPos2);
334 Actor.yPos(a2, yPos2);
335 Actor.xSpeed(a2, xSpeed2);
336 Actor.ySpeed(a2, ySpeed2);
337 //check(dx^2 + dy^2 < 15^2)
338 check((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2) < 15*15);
339}
340
341//////////////
342//VisionBlocked
343//////////////
344
345//OPTIONS 1: everything is from a single check expression containing ITEs
346//Currently unhandled bygenerator
347pattern visionBlocked_ites_top(a1:Actor, a2:Actor, vb:VisionBlocked) {
348 //This second one is required because we do not want to enforce both a1->c->a2 and a2->c->a1
349 Actor.relations(a1, vb);
350 VisionBlocked.target(vb, a2);
351 VisionBlocked.blockedBy(vb, aBlocker);
352
353 Actor.xPos(a1, x1);
354 Actor.yPos(a1, y1);
355 Actor.xPos(a2, x2);
356 Actor.yPos(a2, y2);
357 Actor.xPos(aBlocker, xBlocker);
358 Actor.yPos(aBlocker, yBlocker);
359 Actor.length(aBlocker, lenBlocker);
360 Actor.width(aBlocker, widBlocker);
361
362 //check(slope of a1-to-BlockerTop < slope of a1-to-a2)
363 check(
364 ( yBlocker - y1 + (if(xBlocker > x1){lenBlocker/2}else{0-lenBlocker/2})) /
365 ( xBlocker - x1 + (if(yBlocker > y1){0-widBlocker/2}else{widBlocker/2}))
366 < ((y1-y2)/(x1-x2)));
367}
368
369pattern visionBlocked_ites_bottom(a1:Actor, a2:Actor, vb:VisionBlocked) {
370 //This second one is required because we do not want to enforce both a1->c->a2 and a2->c->a1
371 Actor.relations(a1, vb);
372 VisionBlocked.target(vb, a2);
373 VisionBlocked.blockedBy(vb, aBlocker);
374
375 Actor.xPos(a1, x1);
376 Actor.yPos(a1, y1);
377 Actor.xPos(a2, x2);
378 Actor.yPos(a2, y2);
379 Actor.xPos(aBlocker, xBlocker);
380 Actor.yPos(aBlocker, yBlocker);
381 Actor.length(aBlocker, lenBlocker);
382 Actor.width(aBlocker, widBlocker);
383
384 //check(slope of a1-to-BlockerBottom > slope of a1-to-a2)
385 check(
386 ( yBlocker - y1 + (if(xBlocker > x1){0-lenBlocker/2}else{lenBlocker/2})) /
387 ( xBlocker - x1 + (if(yBlocker > y1){widBlocker/2}else{0-widBlocker/2}))
388 > ((y1-y2)/(x1-x2)));
389}
390
391//OPTION 2:
392//we handle ITE by seperating the constraints
393
394//This will involve 1 constarint for each decision path, but will require multiple check expressions within the same pattern
395
396//OPTION 3:
397//If this is nott working still, we will have to add some strctural components to the MM
398//to differentiate the different cases and reduce the requirements of if, then, else
399
400//This will involve more patterns, and some that are pstructural as well. \ No newline at end of file