aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLibravatar Aren Babikian <aren.babikian@mail.mcgill.ca>2021-01-22 06:17:04 +0100
committerLibravatar Aren Babikian <aren.babikian@mail.mcgill.ca>2021-01-22 06:17:04 +0100
commit75adda0234c582bb178a31cde758064e1d3ac72d (patch)
treea7333ed414a86d775db665655a81bba7dc65b179
parentIssue where blocker is not between source and target (diff)
downloadVIATRA-Generator-75adda0234c582bb178a31cde758064e1d3ac72d.tar.gz
VIATRA-Generator-75adda0234c582bb178a31cde758064e1d3ac72d.tar.zst
VIATRA-Generator-75adda0234c582bb178a31cde758064e1d3ac72d.zip
Almost done implementing collision correctly
-rw-r--r--Domains/crossingScenario/queries/crossingScenarioQueries.vql65
-rw-r--r--Domains/crossingScenario/src/crossingScenario/run/DrawScenario.java127
-rw-r--r--Framework/hu.bme.mit.inf.dslreasoner.viatra2logic/src/hu/bme/mit/inf/dslreasoner/viatra2logic/NumericDrealProblemSolver.java4
3 files changed, 75 insertions, 121 deletions
diff --git a/Domains/crossingScenario/queries/crossingScenarioQueries.vql b/Domains/crossingScenario/queries/crossingScenarioQueries.vql
index d1c72820..6c94a702 100644
--- a/Domains/crossingScenario/queries/crossingScenarioQueries.vql
+++ b/Domains/crossingScenario/queries/crossingScenarioQueries.vql
@@ -463,30 +463,41 @@ pattern collisionExists_qualAbstr(a1:Actor, a2:Actor) {
463} 463}
464 464
465//<<END QUALITATIF ABSTRACTION>> 465//<<END QUALITATIF ABSTRACTION>>
466/* 466
467//// 467////
468//VS VisionBlocked 468//VS VisionBlocked
469//// 469////
470//TODO Very prone to corner cases 470//TODO Very prone to corner cases
471 471/*
472@Constraint(severity="error", key={a1, a2}, message="x") 472@Constraint(severity="error", key={a1}, message="x")
473pattern collisionExists_vsVisionBlocked(a1:Actor, a2:Actor) { 473pattern collisionExists_vsVisionBlocked(a1:Actor) {
474 VisionBlocked.source(vb, a1); 474 VisionBlocked.source(vb, a1);
475 VisionBlocked.target(vb, a2); 475 VisionBlocked.target(vb, a2);
476 neg find helper_collidingActors(a1, a2); 476 CollisionExists.source(ce, a1);
477 CollisionExists.target(ce, a3);
478 a2 != a3;
477} or { 479} or {
478 VisionBlocked.source(vb, a1); 480 VisionBlocked.source(vb, a1);
479 VisionBlocked.target(vb, a2); 481 VisionBlocked.target(vb, a2);
480 neg find helper_collidingActors(a2, a1); 482 CollisionExists.source(ce, a3);
481} 483 CollisionExists.target(ce, a1);
482 484 a2 != a3;
483private pattern helper_collidingActors(a1:Actor, a2:Actor){ 485} or {
484 CollisionExists.source(vb, a1); 486 VisionBlocked.source(vb, a2);
485 CollisionExists.target(vb, a2); 487 VisionBlocked.target(vb, a1);
488 CollisionExists.source(ce, a3);
489 CollisionExists.target(ce, a1);
490 a2 != a3;
491} or {
492 VisionBlocked.source(vb, a2);
493 VisionBlocked.target(vb, a1);
494 CollisionExists.source(ce, a1);
495 CollisionExists.target(ce, a3);
496 a2 != a3;
486} 497}
487 498*/
488//<<END QUALITATIF ABSTRACTION>> 499//<<END QUALITATIF ABSTRACTION>>
489 500/*
490//// 501////
491//CollisionExists - Time 502//CollisionExists - Time
492//// 503////
@@ -592,7 +603,7 @@ pattern collisionExists_defineCollision_x2(a1:Actor, a2:Actor) {
592 check((xPos1 + (xSpeed1 * cTime)) + (w1/2) < (xPos2 + (xSpeed2 * cTime)) - (w2/2)); 603 check((xPos1 + (xSpeed1 * cTime)) + (w1/2) < (xPos2 + (xSpeed2 * cTime)) - (w2/2));
593} 604}
594 605
595*/ 606
596///////*-_-*-_-*-_-*-_-*-_-*-_-*-_-*-_-*-_-*-_-*-_-*-_-*-_-*-_-*-_-*-_-*-_-*-_-*-_-*-_-*////// 607///////*-_-*-_-*-_-*-_-*-_-*-_-*-_-*-_-*-_-*-_-*-_-*-_-*-_-*-_-*-_-*-_-*-_-*-_-*-_-*-_-*//////
597//VisionBlocked 608//VisionBlocked
598///////*-_-*-_-*-_-*-_-*-_-*-_-*-_-*-_-*-_-*-_-*-_-*-_-*-_-*-_-*-_-*-_-*-_-*-_-*-_-*-_-*////// 609///////*-_-*-_-*-_-*-_-*-_-*-_-*-_-*-_-*-_-*-_-*-_-*-_-*-_-*-_-*-_-*-_-*-_-*-_-*-_-*-_-*//////
@@ -708,8 +719,10 @@ pattern visionBlocked_ites_bottom(a1:Actor, a2:Actor, vb:VisionBlocked) {
708 > ((y1-y2)/(x1-x2))); 719 > ((y1-y2)/(x1-x2)));
709} 720}
710 721
711@Constraint(severity="error", key={a1, a2}, message="x") 722//TODO refactor?
712pattern visionBlocked_blockerNotToRightOfBoth(a1:Actor, a2:Actor) { 723//TODO CORNER CASES
724@Constraint(severity="error", key={a1, vb}, message="x")
725pattern visionBlocked_xdistBSlargerThanxdistTS(a1:Actor, a2:Actor, vb:VisionBlocked) {
713 //This second one is required because we do not want to enforce both a1->c->a2 and a2->c->a1 726 //This second one is required because we do not want to enforce both a1->c->a2 and a2->c->a1
714 VisionBlocked.source(vb, a1); 727 VisionBlocked.source(vb, a1);
715 VisionBlocked.target(vb, a2); 728 VisionBlocked.target(vb, a2);
@@ -719,23 +732,31 @@ pattern visionBlocked_blockerNotToRightOfBoth(a1:Actor, a2:Actor) {
719 Actor.xPos(a2, x2); 732 Actor.xPos(a2, x2);
720 Actor.xPos(aBlocker, xBlocker); 733 Actor.xPos(aBlocker, xBlocker);
721 734
722 check( x1 < xBlocker && x2 < xBlocker); 735 //check(slope of a1-to-BlockerBottom > slope of a1-to-a2)
736 //TODO implement ABSOLUTE VALUE or MULTI-CHECK
737 check((x1-xBlocker)*(x1-xBlocker) > (x1-x2)*(x1-x2));
723} 738}
724 739
725@Constraint(severity="error", key={a1, a2}, message="x") 740//TODO refactor?
726pattern visionBlocked_blockerNotToLeftOfBoth(a1:Actor, a2:Actor) { 741//TODO CORNER CASES
742@Constraint(severity="error", key={a1, vb}, message="x")
743pattern visionBlocked_xdistBTlargerThanxdistST(a1:Actor, a2:Actor, vb:VisionBlocked) {
727 //This second one is required because we do not want to enforce both a1->c->a2 and a2->c->a1 744 //This second one is required because we do not want to enforce both a1->c->a2 and a2->c->a1
728 VisionBlocked.source(vb, a1); 745 VisionBlocked.source(vb, a2);
729 VisionBlocked.target(vb, a2); 746 VisionBlocked.target(vb, a1);
730 VisionBlocked.blockedBy(vb, aBlocker); 747 VisionBlocked.blockedBy(vb, aBlocker);
731 748
732 Actor.xPos(a1, x1); 749 Actor.xPos(a1, x1);
733 Actor.xPos(a2, x2); 750 Actor.xPos(a2, x2);
734 Actor.xPos(aBlocker, xBlocker); 751 Actor.xPos(aBlocker, xBlocker);
735 752
736 check( x1 > xBlocker && x2 > xBlocker); 753 //check(slope of a1-to-BlockerBottom > slope of a1-to-a2)
754 //TODO implement ABSOLUTE VALUE or MULTI-CHECK
755 check((x1-xBlocker)*(x1-xBlocker) > (x1-x2)*(x1-x2));
737} 756}
738 757
758//TODO same as above for Y???
759//TODO same as above for Y ????
739 760
740/////*-_-*-_-*-_-*-_-*-_-*-_-*-_-*-_-*-_-*-_-*-_-*-_-*-_-*-_-*-_-*-_-*-_-*-_-*-_-*-_-*////// 761/////*-_-*-_-*-_-*-_-*-_-*-_-*-_-*-_-*-_-*-_-*-_-*-_-*-_-*-_-*-_-*-_-*-_-*-_-*-_-*-_-*//////
741//SeparationDistance 762//SeparationDistance
diff --git a/Domains/crossingScenario/src/crossingScenario/run/DrawScenario.java b/Domains/crossingScenario/src/crossingScenario/run/DrawScenario.java
index 0ccfc4a1..7f90beb2 100644
--- a/Domains/crossingScenario/src/crossingScenario/run/DrawScenario.java
+++ b/Domains/crossingScenario/src/crossingScenario/run/DrawScenario.java
@@ -18,18 +18,20 @@ import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
18import org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl; 18import org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl;
19 19
20import crossingScenario.Actor; 20import crossingScenario.Actor;
21import crossingScenario.CollisionExists;
21import crossingScenario.CrossingScenario; 22import crossingScenario.CrossingScenario;
22import crossingScenario.CrossingScenarioPackage; 23import crossingScenario.CrossingScenarioPackage;
23import crossingScenario.Lane; 24import crossingScenario.Lane;
24import crossingScenario.Lane_Horizontal; 25import crossingScenario.Lane_Horizontal;
25import crossingScenario.Lane_Vertical; 26import crossingScenario.Lane_Vertical;
27import crossingScenario.Relation;
26import crossingScenario.VisionBlocked; 28import crossingScenario.VisionBlocked;
27 29
28public class DrawScenario { 30public class DrawScenario {
29 public static final int SIZE = 1000; 31 public static final int SIZE = 1000;
30 32
31 public static void main(String[] args) throws IOException { 33 public static void main(String[] args) throws IOException {
32 drawScenario("outputs/models/1.xmi"); 34 drawScenario("outputs/models/4.xmi");
33 } 35 }
34 36
35 public static File drawScenario(String pathToXmi) throws IOException { 37 public static File drawScenario(String pathToXmi) throws IOException {
@@ -100,68 +102,36 @@ public class DrawScenario {
100 g.setPaint(Color.GREEN); 102 g.setPaint(Color.GREEN);
101 103
102 g.drawRect(left, bot, width, length); 104 g.drawRect(left, bot, width, length);
105 }
106
107 g.setPaint(Color.BLUE);
108 for (Relation ce : cs.getRelations().stream().
109 filter(r -> r instanceof CollisionExists).collect(Collectors.toList())) {
110 Actor a1 = ce.getSource();
111 Actor a2 = ce.getTarget();
112 Double t = ((CollisionExists) ce).getCollisionTime();
113
114 for (Actor a : new Actor[] {a1, a2}) {
115 //Draw final pos
116 g.setStroke(new BasicStroke(3));
117 int left = (int) (((a.getXPos() + (t * a.getXSpeed()))-a.getWidth()/2) * multiplier);
118 int bot = (int) (((a.getYPos() + (t * a.getYSpeed()))-a.getLength()/2) * multiplier);
119 int width = (int) (a.getWidth() * multiplier);
120 int length = (int) (a.getLength() * multiplier);
121
122
103 123
104 //Draw Speed? 124 //Draw line
125 g.drawRect(left, bot, width, length);
126 g.setStroke(new BasicStroke(1));
127 int x1 = (int) (a.getXPos() * multiplier);
128 int y1 = (int) (a.getYPos() * multiplier);
129 int x2 = (int) ((a.getXPos() + (t * a.getXSpeed())) * multiplier);
130 int y2 = (int) ((a.getYPos() + (t * a.getYSpeed())) * multiplier);
131 g.drawLine(x1, y1, x2, y2);
105 132
106 //Draw location at collision? 133 }
107 } 134 }
108
109// int numVars = vals.size();
110// final int numActors = (numVars - 1) / 4;
111//
112// double time = 0;
113// if (!is3)
114// time = vals.get(numVars - 1);
115// else
116// time = vals.get(numVars / 2);
117//
118// for (int i = 0; i < numActors; i++) {
119//
120// int x = 0, y = 0, vx = 0, vy = 0;
121// if (!is3) {
122// int first = i * 4;
123// x = (int) (vals.get(first) * 100);
124// y = (int) (vals.get(first + 1) * 100);
125// vx = (int) (vals.get(first + 2) * 100);
126// vy = (int) (vals.get(first + 3) * 100);
127// } else {
128// int first = i * 2;
129// x = (int) (vals.get(first) * 100);
130// y = (int) (vals.get(first + 1) * 100);
131// vx = (int) (vals.get(first + 1 + numVars / 2) * 100);
132// vy = (int) (vals.get(first + 2 + numVars / 2) * 100);
133// }
134// g.setStroke(new BasicStroke(10));
135// g.setPaint(Color.BLACK);
136// g.drawOval(x - 2, y - 2, 4, 4);
137// boolean isEGO = (!is3 && i == 0) || (is3 && i == numActors - 2);
138// boolean isPED = (i == numActors - 1);
139// if (isEGO) {
140// // EGO
141// g.drawRect(x - 50, y - 150, 100, 300);
142// g.setPaint(Color.PINK);
143// if (acceleration)
144// g.drawRect((int) (x + (vx * time * time) - 50), (int) (y + (vy * time * time) - 150), 100, 300);
145// else
146// g.drawRect((int) (x + (vx * time) - 50), (int) (y + (vy * time) - 150), 100, 300);
147// } else if (isPED) {
148// // PED
149// g.drawRect(x - 50, y - 50, 100, 100);
150// g.setPaint(Color.PINK);
151// if (acceleration)
152// g.drawRect((int) (x + (vx * time * time) - 50), (int) (y + (vy * time * time) - 50), 100, 100);
153// else
154// g.drawRect((int) (x + (vx * time) - 50), (int) (y + (vy * time) - 50), 100, 100);
155// } else {
156// // CAR
157// g.drawRect(x - 50, y - 150, 100, 300);
158// }
159//
160// g.setStroke(new BasicStroke(4));
161// g.setPaint(Color.GREEN);
162// g.drawLine(x, y, x + vx, y + vy);
163//
164// }
165 g.dispose(); 135 g.dispose();
166 136
167 File f = new File("outputs/drawnModel.png"); 137 File f = new File("outputs/drawnModel.png");
@@ -174,42 +144,5 @@ public class DrawScenario {
174// Desktop.getDesktop().open(f); 144// Desktop.getDesktop().open(f);
175 System.out.println("finished!"); 145 System.out.println("finished!");
176 return f; 146 return f;
177
178// CrossingScenario cs = ((CrossingScenario) res.getContents().get(0));
179//
180// for (Actor o : cs.getActors()) {
181// String nodeName = "A(" + rndbl(o.getXPos(), 1) + "," + rndbl(o.getYPos(), 1) + ")";
182// printer.println(o.hashCode() + " " + nodeName);
183// }
184//
185// for (Lane o : cs.getLanes()) {
186// String prefix = "";
187// if (cs.getHorizontal_head().equals(o) || cs.getVertical_head().equals(o)) {
188// prefix = "HEAD";
189// }
190// String nodeName = prefix + "L(" + rndbl(o.getReferenceCoord(), 3) + ")"
191// + o.eClass().getName().substring(5, 9);
192// printer.println(o.hashCode() + " " + nodeName);
193// }
194// printer.println("#");
195// for (Lane o : cs.getLanes()) {
196// if (o.getPrevLane() != null) {
197// int curName = o.hashCode();
198// int curPrev = o.getPrevLane().hashCode();
199// double edgeLabel = rndbl(o.getPrevLane().getNumWidth(), 1);
200// printer.println(curName + " " + curPrev + " " + edgeLabel);
201// }
202// }
203//
204// for (Actor o : cs.getActors()) {
205// int actName = o.hashCode();
206// int lanName = o.getPlacedOn().hashCode();
207// printer.println(actName + " " + lanName);
208// }
209//
210// printer.flush();
211// printer.close();
212// System.out.println("TGF CREATED");
213
214 } 147 }
215} 148}
diff --git a/Framework/hu.bme.mit.inf.dslreasoner.viatra2logic/src/hu/bme/mit/inf/dslreasoner/viatra2logic/NumericDrealProblemSolver.java b/Framework/hu.bme.mit.inf.dslreasoner.viatra2logic/src/hu/bme/mit/inf/dslreasoner/viatra2logic/NumericDrealProblemSolver.java
index b8ab8e95..e3bb2cbe 100644
--- a/Framework/hu.bme.mit.inf.dslreasoner.viatra2logic/src/hu/bme/mit/inf/dslreasoner/viatra2logic/NumericDrealProblemSolver.java
+++ b/Framework/hu.bme.mit.inf.dslreasoner.viatra2logic/src/hu/bme/mit/inf/dslreasoner/viatra2logic/NumericDrealProblemSolver.java
@@ -437,8 +437,8 @@ public class NumericDrealProblemSolver extends NumericProblemSolver{
437 437
438 //DEBUG - Print things 438 //DEBUG - Print things
439 System.out.println("Getting Solution!"); 439 System.out.println("Getting Solution!");
440 printOutput(numProbContent); 440// printOutput(numProbContent);
441 printOutput(outputs.get(0)); 441// printOutput(outputs.get(0));
442// System.out.println(result); 442// System.out.println(result);
443 //END DEBUG 443 //END DEBUG
444 444