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

more work to get relations converted to terminals

parent a13921e8
No related branches found
No related tags found
No related merge requests found
Pipeline #13517 failed
...@@ -103,7 +103,7 @@ aspect Computation { ...@@ -103,7 +103,7 @@ aspect Computation {
logicalRegion.setName(region.getName()); logicalRegion.setName(region.getName());
result.addLogicalRegion(logicalRegion); result.addLogicalRegion(logicalRegion);
for (MovableObject movableObject : getMovableObjectList()) { for (MovableObject movableObject : getMovableObjectList()) {
for (DropOffLocation location : region.getLocationList()) { for (DropOffLocation location : region.locationList()) {
if (movableObject.isLocatedAt(location)) { if (movableObject.isLocatedAt(location)) {
LogicalMovableObject logicalObject = objects.get(movableObject); LogicalMovableObject logicalObject = objects.get(movableObject);
logicalRegion.addContainedObject(logicalObject); logicalRegion.addContainedObject(logicalObject);
...@@ -168,6 +168,26 @@ aspect Navigation { ...@@ -168,6 +168,26 @@ aspect Navigation {
// must be "implemented" in concrete world models, i.e., an equation must be defined // must be "implemented" in concrete world models, i.e., an equation must be defined
inh JastAddList<Region> Scene.regionList(); inh JastAddList<Region> Scene.regionList();
syn List<Region> DropOffLocation.containedInRegion() {
List<Region> result = new ArrayList<>();
for (Region region : containingScene().regionList()) {
List<String> locationNames = Arrays.asList(region.getLocationNames().split(","));
if (locationNames.contains(getName())) {
result.add(region);
}
}
return result;
}
protected static List<String> ASTNode.arrayAsList(String array) {
if (array == null || array.length() == 0) {
return new ArrayList<>();
}
return new ArrayList<>(Arrays.asList(array.split(",")));
}
syn List<String> Region.locationNamesAsList() = arrayAsList(getLocationNames()) ;
syn List<DropOffLocation> Region.locationList();
} }
aspect Printing { aspect Printing {
......
...@@ -23,8 +23,8 @@ rel LogicalRegion.ContainedObject* <-> LogicalMovableObject.LocatedAt* ; ...@@ -23,8 +23,8 @@ rel LogicalRegion.ContainedObject* <-> LogicalMovableObject.LocatedAt* ;
// TODO could lead to problems when including this information and sending it // TODO could lead to problems when including this information and sending it
//rel LogicalMovableObject.MyLocation? -> DropOffLocation ; //rel LogicalMovableObject.MyLocation? -> DropOffLocation ;
Region ::= <Name:String> ; Region ::= <Name:String> <LocationNames> ;
rel Region.Location* <-> DropOffLocation.ContainedInRegion* ; //rel Region.Location* <-> DropOffLocation.ContainedInRegion* ;
// TODO should this be only in site-B?? // TODO should this be only in site-B??
CollaborationZone : DropOffLocation ; CollaborationZone : DropOffLocation ;
...@@ -3,7 +3,7 @@ receive WorldModelB.MyScene using ParseScene, ConvertScene ; ...@@ -3,7 +3,7 @@ receive WorldModelB.MyScene using ParseScene, ConvertScene ;
receive indexed WorldModelB.OtherScene ; receive indexed WorldModelB.OtherScene ;
receive WorldModelB.TestingOtherScene ; receive WorldModelB.TestingOtherScene ;
receive Robot.CanReachObjectOfInterestWrapper using ParseReachability, ConvertReachability ; receive Robot.CanReachObjectOfInterestWrapper using ParseReachability, ConvertReachability ;
receive Robot.DummyOwnedCollaborationZone using ConfigChangeCommandCheckForOwnedCollaborationZone ; receive Robot.OwnedCollaborationZoneNames using ConfigChangeCommandCheckForOwnedCollaborationZone ;
receive Robot.Busy using ConfigChangeCommandCheckForBusy ; receive Robot.Busy using ConfigChangeCommandCheckForBusy ;
// --- sending --- // --- sending ---
...@@ -35,18 +35,20 @@ ConfigChangeCommandCheckForOwnedCollaborationZone maps byte[] bytes to String {: ...@@ -35,18 +35,20 @@ ConfigChangeCommandCheckForOwnedCollaborationZone maps byte[] bytes to String {:
DropOffLocation loc = obj.asDropOffLocation(); DropOffLocation loc = obj.asDropOffLocation();
CollaborationZone cz = loc.asCollaborationZone(); CollaborationZone cz = loc.asCollaborationZone();
Robot thisRobot = (Robot) this; Robot thisRobot = (Robot) this;
if (thisRobot.getName().equals(cc.getIdRobotNewOwner()) && !thisRobot.getOwnedCollaborationZoneList().contains(cz)) { List<String> collaborationZoneNames = thisRobot.ownedCollaborationZonesAsList();
boolean robotIsNewOwner = thisRobot.getName().equals(cc.getIdRobotNewOwner());
boolean collaborationZoneAlreadyOwned = collaborationZoneNames.contains(cc.getIdCollaborationZone());
if (robotIsNewOwner && !collaborationZoneAlreadyOwned) {
// config change is for this robot, add collaboration zone // config change is for this robot, add collaboration zone
thisRobot.addOwnedCollaborationZone(cz); collaborationZoneNames.add(cc.getIdCollaborationZone());
reject(); } else if (!robotIsNewOwner && collaborationZoneAlreadyOwned) {
}
if (!thisRobot.getName().equals(cc.getIdRobotNewOwner()) && thisRobot.getOwnedCollaborationZoneList().contains(cz)) {
// config change is for another robot, remove collaboration zone // config change is for another robot, remove collaboration zone
thisRobot.removeOwnedCollaborationZone(cz); collaborationZoneNames.remove(cc.getIdCollaborationZone());
} else {
// otherwise don't change
reject(); reject();
} }
// need return to make compiler happy return String.join(",", collaborationZoneNames);
return "";
:} :}
ConfigChangeCommandCheckForBusy maps byte[] bytes to boolean {: ConfigChangeCommandCheckForBusy maps byte[] bytes to boolean {:
......
...@@ -138,7 +138,7 @@ aspect Computation { ...@@ -138,7 +138,7 @@ aspect Computation {
try { try {
previousLocation.correspondingVertex(); previousLocation.correspondingVertex();
} catch (NullPointerException e) { } catch (NullPointerException e) {
return error("Could not resolve WorldModelB"); return error("Could not resolve WorldModelB linked to previousLocation " + previousLocation.nameAndHash());
} }
return previousLocation.correspondingVertex().map(previousVertex -> { return previousLocation.correspondingVertex().map(previousVertex -> {
Region region = getNewRegion().realRegion(); Region region = getNewRegion().realRegion();
...@@ -146,10 +146,16 @@ aspect Computation { ...@@ -146,10 +146,16 @@ aspect Computation {
return error("No region found for " + getNewRegion().nameAndHash()); return error("No region found for " + getNewRegion().nameAndHash());
} }
// pick location from newRegion, that is free // pick location from newRegion, that is free
return region.getLocationList().stream() return region.locationList().stream()
.filter(location -> location.getObjectLocatedHere() == null) .filter(location -> location.getObjectLocatedHere() == null)
.findFirst() .findFirst()
.map(newLocation -> { .map(newLocation -> {
// (workaround) check if WorldModelB is not null ... could happen if scene has no parent
try {
newLocation.correspondingVertex();
} catch (NullPointerException e) {
return error("Could not resolve WorldModelB linked to newLocation " + newLocation.nameAndHash());
}
return newLocation.correspondingVertex().map(newVertex -> { return newLocation.correspondingVertex().map(newVertex -> {
List<Edge> shortestPath = previousVertex.BFS(newVertex); List<Edge> shortestPath = previousVertex.BFS(newVertex);
if (shortestPath == null || shortestPath.isEmpty()) { if (shortestPath == null || shortestPath.isEmpty()) {
...@@ -170,10 +176,10 @@ aspect Computation { ...@@ -170,10 +176,10 @@ aspect Computation {
*/ */
CollaborationZone cz = targetLocation.asCollaborationZone(); CollaborationZone cz = targetLocation.asCollaborationZone();
// order is important here, first add Evacuate, then ConfigChange // order is important here, first add Evacuate, then ConfigChange
if (cz.hasOccupient() && !cz.getOccupient().equals(executingRobot)) { if (cz.hasOccupient() && !cz.occupient().equals(executingRobot)) {
result.add(Evacuate.of(cz.getOccupient(), cz)); result.add(Evacuate.of(cz.occupient(), cz));
} }
if (!cz.hasOwner() || (cz.hasOwner() && !cz.getOwner().equals(executingRobot))) { if (!cz.hasOwner() || (cz.hasOwner() && !cz.owner().equals(executingRobot))) {
result.add(ConfigChange.of(executingRobot, cz)); result.add(ConfigChange.of(executingRobot, cz));
} }
} }
...@@ -259,7 +265,7 @@ aspect Computation { ...@@ -259,7 +265,7 @@ aspect Computation {
} }
syn DropOffLocation Region.firstFreeDropOffLocation() { syn DropOffLocation Region.firstFreeDropOffLocation() {
for (DropOffLocation location : getLocationList()) { for (DropOffLocation location : locationList()) {
if (location.getObjectLocatedHere() == null) { if (location.getObjectLocatedHere() == null) {
return location; return location;
} }
...@@ -346,6 +352,33 @@ aspect Navigation { ...@@ -346,6 +352,33 @@ aspect Navigation {
//--- allMappings --- //--- allMappings ---
// inh LocationMapping LogicalDropOffLocation.allMappings(); // inh LocationMapping LogicalDropOffLocation.allMappings();
// eq WorldModelB.getChild().allMappings() = getLocationMapping(); // eq WorldModelB.getChild().allMappings() = getLocationMapping();
syn boolean CollaborationZone.hasOccupient() = occupient() != null;
syn Robot CollaborationZone.occupient() {
for (Robot robot : worldModelB().getRobotList()) {
if (getName().equals(robot.getOccupiedCollaborationZoneName())) {
return robot;
}
}
return null;
}
syn boolean CollaborationZone.hasOwner() = owner() != null;
syn Robot CollaborationZone.owner() {
for (Robot robot : worldModelB().getRobotList()) {
List<String> collaborationZoneNames = Arrays.asList(robot.getOwnedCollaborationZoneNames().split(","));
if (collaborationZoneNames.contains(getName())) {
return robot;
}
}
return null;
}
syn List<String> Robot.ownedCollaborationZonesAsList() = arrayAsList(getOwnedCollaborationZoneNames());
eq Region.locationList() {
List<DropOffLocation> result = new ArrayList<>();
for (String locationName : locationNamesAsList()) {
result.add(worldModelB().getMyScene().resolveObjectOfInterest(locationName).asDropOffLocation());
}
return result;
}
} }
aspect GlueForShared { aspect GlueForShared {
......
WorldModelB ::= Region* Robot* [MyScene:Scene] OtherScene:LogicalScene* /NextOperation:Operation/ TestingOtherScene:LogicalScene* ; WorldModelB ::= Region* Robot* [MyScene:Scene] OtherScene:LogicalScene* /NextOperation:Operation/ TestingOtherScene:LogicalScene* ;
Robot ::= <Name:String> CanReachObjectOfInterestWrapper <Busy:boolean> <DummyOwnedCollaborationZone> ; // FIXME inline CanReachObjectOfInterestWrapper
rel Robot.OwnedCollaborationZone* <-> CollaborationZone.Owner? ; Robot ::= <Name:String> CanReachObjectOfInterestWrapper <Busy:boolean> <OwnedCollaborationZoneNames> <OccupiedCollaborationZoneName> ;
rel Robot.OccupiedCollaborationZone? <-> CollaborationZone.Occupient? ; // relations into nodes received by RagConnect are not allowed
//rel Robot.OwnedCollaborationZone* <-> CollaborationZone.Owner? ;
//rel Robot.OccupiedCollaborationZone? <-> CollaborationZone.Occupient? ;
abstract Difference ; abstract Difference ;
rel Difference.Object -> LogicalMovableObject ; rel Difference.Object -> LogicalMovableObject ;
......
...@@ -113,7 +113,7 @@ public class SimpleMainB { ...@@ -113,7 +113,7 @@ public class SimpleMainB {
model.connectMyScene(Util.mqttUri(topicSceneUpdateB, config)); model.connectMyScene(Util.mqttUri(topicSceneUpdateB, config));
for (Robot robot : model.getRobotList()) { for (Robot robot : model.getRobotList()) {
robot.connectBusy(Util.mqttUri(topicCommand, config)); robot.connectBusy(Util.mqttUri(topicCommand, config));
robot.connectDummyOwnedCollaborationZone(Util.mqttUri(topicCommand, config)); robot.connectOwnedCollaborationZoneNames(Util.mqttUri(topicCommand, config));
} }
model.connectNextOperation(Util.mqttUri(topicCommand, config), true); model.connectNextOperation(Util.mqttUri(topicCommand, config), true);
......
...@@ -12,6 +12,7 @@ import org.apache.logging.log4j.Logger; ...@@ -12,6 +12,7 @@ import org.apache.logging.log4j.Logger;
import java.io.IOException; import java.io.IOException;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.Path; import java.nio.file.Path;
import java.util.stream.Collectors;
/** /**
* Static utility methods used only for place B. * Static utility methods used only for place B.
...@@ -143,9 +144,7 @@ public class UtilB { ...@@ -143,9 +144,7 @@ public class UtilB {
for (RegionDefinition def : config.regions) { for (RegionDefinition def : config.regions) {
Region region = new Region(); Region region = new Region();
region.setName(def.name); region.setName(def.name);
for (String position : def.positions) { region.setLocationNames(String.join(",", def.positions));
region.addLocation(model.getMyScene().resolveObjectOfInterest(position).asDropOffLocation());
}
result.add(region); result.add(region);
} }
model.setRegionList(result); model.setRegionList(result);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment