Skip to content
Snippets Groups Projects
Commit 6eee1b92 authored by René Schöne's avatar René Schöne
Browse files

begin with extension to multi-robot handling

parent ce746b07
No related branches found
No related tags found
1 merge request!1Multiple scenes, multiple robots and more
Pipeline #9967 passed
...@@ -27,7 +27,7 @@ ext.sharedJastAddDir = 'src/main/jastadd/shared' ...@@ -27,7 +27,7 @@ ext.sharedJastAddDir = 'src/main/jastadd/shared'
ext.ragConnectInputGrammar = 'src/main/jastadd/WorldModelB.relast' ext.ragConnectInputGrammar = 'src/main/jastadd/WorldModelB.relast'
ext.ragConnectInputConnect = 'src/main/jastadd/WorldModelB.connect' ext.ragConnectInputConnect = 'src/main/jastadd/WorldModelB.connect'
ext.ragConnectRootNode = 'WorldModelB' ext.ragConnectRootNode = 'WorldModelB'
ext.relastFiles = ["src/gen/jastadd/WorldModelB.relast", "src/gen/jastadd/RagConnect.relast"] ext.relastFiles = ["src/gen/jastadd/WorldModelB.relast", "src/main/jastadd/BFS/BFS.relast", "src/gen/jastadd/RagConnect.relast"]
ext.jastaddAstPackage = 'de.tudresden.inf.st.placeB.ast' ext.jastaddAstPackage = 'de.tudresden.inf.st.placeB.ast'
apply from: '../ros3rag.common/src/main/resources/tasks.gradle' apply from: '../ros3rag.common/src/main/resources/tasks.gradle'
import java.util.*;
aspect BFS {
syn List<Vertex> Vertex.BFS(Vertex goal) {
Map<Vertex, Vertex> pred = new HashMap<>();
Queue<Vertex> Q = new LinkedList<>();
Set<Vertex> seen = new HashSet<>();
seen.add(this);
Q.add(this);
while (!Q.isEmpty()) {
Vertex v = Q.remove();
if (v.equals(goal)) {
return reconstructFrom(goal, pred);
}
for (Edge e : v.getOutgoingList()) {
Vertex w = e.getTo();
if (seen.contains(w)) {
continue;
}
seen.add(w);
pred.put(w, v);
Q.add(w);
}
// uncomment following for-loop if edges are bidirectional
for (Edge e : v.getIncomingList()) {
Vertex w = e.getFrom();
if (seen.contains(w)) {
continue;
}
seen.add(w);
pred.put(w, v);
Q.add(w);
}
}
// failure
return Collections.emptyList();
}
private List<Vertex> Vertex.reconstructFrom(Vertex goal, Map<Vertex, Vertex> pred) {
List<Vertex> result = new ArrayList<>();
System.out.println(pred);
Vertex current = goal;
while (!current.equals(this)) {
result.add(current);
current = pred.get(current);
}
result.add(this);
Collections.reverse(result);
return result;
}
}
Graph ::= Vertex* Edge* ;
Vertex ;
Edge ;
rel Edge.From <-> Vertex.Outgoing* ;
rel Edge.To <-> Vertex.Incoming* ;
aspect RobotReachabilityToBFS {
syn nta Graph WorldModelB.toReachabilityGraph() {
Graph result = new Graph();
if (!hasMyScene()) {
return result;
}
Map<LogicalDropOffLocation, Vertex> mapping = new HashMap<>();
for (LogicalDropOffLocation loc : getMyScene().getLogicalScene().getLogicalDropOffLocationList()) {
Vertex vertex = new Vertex();
result.addVertex(vertex);
mapping.put(loc, vertex);
}
for (Robot robot : getRobotList()) {
List<LogicalObjectOfInterest> reachableLocations = robot.reachableObjects().stream()
.filter(LogicalObjectOfInterest::isLogicalDropOffLocation)
.collect(java.util.stream.Collectors.toList());
for (LogicalObjectOfInterest obj : reachableLocations) {
for (LogicalObjectOfInterest other : reachableLocations) {
if (obj == other) { continue; }
Edge edge = new Edge();
edge.setFrom(mapping.get(obj));
edge.setTo(mapping.get(other));
result.addEdge(edge);
}
}
}
return result;
}
}
rel Vertex.Location -> LogicalDropOffLocation ;
rel Edge.Robot -> Robot ;
...@@ -156,6 +156,17 @@ aspect Computation { ...@@ -156,6 +156,17 @@ aspect Computation {
} }
return false; return false;
} }
syn List<LogicalObjectOfInterest> Robot.reachableObjects() {
if (!worldModelB().hasMyScene()) {
return Collections.emptyList();
}
List<LogicalObjectOfInterest> result = new ArrayList<>();
for (var canReachObj : getCanReachObjectOfInterestWrapper().getCanReachObjectOfInterestList()) {
worldModelB().getMyScene().getLogicalScene().resolveLogicalObjectOfInterest(canReachObj.getObjectName());
}
return result;
}
} }
//aspect RelationsByReference { //aspect RelationsByReference {
......
...@@ -37,7 +37,51 @@ public class SimpleMainB { ...@@ -37,7 +37,51 @@ public class SimpleMainB {
// testReceivingModelB(); // testReceivingModelB();
// testReachability(); // testReachability();
// testWeirdBehaviour(); // testWeirdBehaviour();
printReachability(); // printReachability();
testBFS();
}
private void testBFS() {
/*
A B
| \ |
C - D
*/
Graph g = new Graph();
Vertex a = makeVertex("a");
Vertex b = makeVertex("b");
Vertex c = makeVertex("c");
Vertex d = makeVertex("d");
Edge ac = makeEdge(a, c);
Edge ad = makeEdge(a, d);
Edge cd = makeEdge(c, d);
Edge db = makeEdge(d, b);
g.addVertex(a);
g.addVertex(b);
g.addVertex(c);
g.addVertex(d);
g.addEdge(ac);
g.addEdge(ad);
g.addEdge(cd);
g.addEdge(db);
System.out.println(a.BFS(b));
}
private Vertex makeVertex(String name) {
return new Vertex() {
@Override
public String toString() {
return name;
}
};
}
private Edge makeEdge(Vertex from, Vertex to) {
Edge result = new Edge();
result.setFrom(from);
result.setTo(to);
return result;
} }
private void printReachability() throws Exception { private void printReachability() throws Exception {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment