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

Revert optimized version to use attribute for resolving monitoredBy.

parent ff631d60
No related branches found
No related tags found
No related merge requests found
Showing
with 46 additions and 30 deletions
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
......@@ -435,13 +435,13 @@ public class Json4AgRefSerializer extends ModelSerializer<Json4AgRefGeneratorCon
n.createListChild(Children.MONITOREDELEMENT);
break;
case SEGMENT:
n.createListChild(Children.CONNECTSTO).createListChild(Children.MONITOREDBY).createListChild(Children.SEMAPHORE);
n.createListChild(Children.CONNECTSTO).createListChild(Children.SEMAPHORE);
if (attributes.get(LENGTH) != null) {
n.addChild(Children.LENGTH, new ASTTerminal("int", attributes.get(LENGTH)));
}
break;
case SWITCH:
n.createListChild(Children.CONNECTSTO).createListChild(Children.MONITOREDBY);
n.createListChild(Children.CONNECTSTO);
break;
default:
System.err.println(String.format("Unknown type of vertex: %s", type));
......@@ -457,8 +457,6 @@ public class Json4AgRefSerializer extends ModelSerializer<Json4AgRefGeneratorCon
ASTNonterminal from_nt = (ASTNonterminal) from;
ASTList listNode = (ASTList) to_nt.getChildren().get(Children.MONITOREDELEMENT);
listNode.addChild(makeRef(from_nt, Grammar.TRACKELEMENT_REF));
listNode = (ASTList) from_nt.getChildren().get(Children.MONITOREDBY);
listNode.addChild(makeRef(to_nt, Grammar.SENSOR_REF));
} else if (STRUCTURE_EDGE_MAP.containsKey(label)) {
String realEdgeLabel = STRUCTURE_EDGE_MAP.get(label);
ASTNonterminal n = (ASTNonterminal) from;
......
......@@ -145,11 +145,11 @@ aspect TreeNavigation {
}
syn Map<Integer,Set<Route>> RailwayContainer.requiringRoutesMap() {
Map<Integer,Set<Route>> routeMap = new java.util.HashMap<Integer,Set<Route>>();
Map<Integer,Set<Route>> routeMap = new java.util.HashMap<>();
// fill the keys
for (Sensor sensor: sensors()) {
routeMap.put(sensor.id(), new java.util.HashSet());
routeMap.put(sensor.id(), new java.util.HashSet<>());
}
// update the values
......@@ -162,4 +162,30 @@ aspect TreeNavigation {
return routeMap;
}
syn Collection<Sensor> TrackElement.monitoredBy() {
return getRoot().monitoredByMap().get(this.id());
}
syn Map<Integer, Set<Sensor>> RailwayContainer.monitoredByMap() {
Map<Integer, Set<Sensor>> result = new java.util.HashMap<>();
// fill the keys
for (Region region : getRegionList()) {
for (TrackElement trackElement : region.getTrackElementList()) {
result.put(trackElement.id(), new java.util.HashSet<>());
}
}
// update the values
for (Region region : getRegionList()) {
for (Sensor sensor : region.getSensorList()) {
for (TrackElementRef trackElementRef : sensor.getMonitoredElementList()) {
result.get(trackElementRef.getValue()).add(sensor);
}
}
}
return result;
}
}
......@@ -15,16 +15,16 @@ aspect Queries {
Collection<Sensor> requiredSensors = requiredSensors();
for (SwitchPosition sp : getSwitchPositionList()) {
Switch sw = sp.target();
for (SensorRef sensorRef : sw.getMonitoredByList()) {
for (Sensor sensor : sw.monitoredBy()) {
boolean validSensor = false;
for (Sensor sensor2 : requiredSensors) {
if (sensor2 == sensorRef.getSensor()) {
if (sensor2 == sensor) {
validSensor = true;
break;
}
}
if(!validSensor) {
matches.add(new JastaddRouteSensorMatch(this, sensorRef.getSensor(), sp, sw));
matches.add(new JastaddRouteSensorMatch(this, sensor, sp, sw));
}
}
}
......
......@@ -21,8 +21,7 @@ aspect Queries {
for (Sensor sensor1 : this.requiredSensors()) {
for (TrackElement te1 : sensor1.monitoredElements()) {
for (TrackElement te2 : te1.connectsTos()) {
for (SensorRef sensorRef2 : te2.getMonitoredByList()) {
Sensor sensor2 = sensorRef2.getSensor();
for (Sensor sensor2 : te2.monitoredBy()) {
for (Route route2 : sensor2.requiringRoutes()) {
if (this != route2) {
if (!route2.hasEntry() || route2.getEntry().getValue() != exitRef.getValue()) {
......
......@@ -11,7 +11,7 @@ aspect Queries {
syn java.util.Collection<Switch> Region.switchMonitoredMatches() {
java.util.List<Switch> matches = new java.util.ArrayList<>();
for (Switch sw : switches()) {
if (sw.getMonitoredByList().numChildren() == 0) {
if (sw.monitoredBy().size() == 0) {
matches.add(sw);
}
}
......
......@@ -8,7 +8,7 @@ Route:RailwayElement ::= <Active:boolean> SwitchPosition* RequiredSensor:SensorR
SwitchPosition:RailwayElement ::= <Position:Position> Target:SwitchRef ;
Sensor:RailwayElement ::= MonitoredElement:TrackElementRef* ;
abstract TrackElement:RailwayElement ::= MonitoredBy:SensorRef* ConnectsTo:TrackElementRef* ;
abstract TrackElement:RailwayElement ::= ConnectsTo:TrackElementRef* ;
Segment:TrackElement ::= <Length:int> Semaphore* ;
Switch:TrackElement ::= <CurrentPosition:Position> ;
......
......@@ -21,9 +21,8 @@ public class JastaddTransformationInjectConnectedSegments<TJastaddDriver extends
// create segment2
List<TrackElementRef> connectedSegments = new List<>();
connectedSegments.add(new TrackElementRef(match.getSegment3().id(), match.getSegment3()));
List<SensorRef> monitoredBy = new List<>();
List<Semaphore> semaphores = new List<>();
Segment segment2 = new Segment(new Id(driver.nextId()), monitoredBy, connectedSegments, TrainBenchmarkConstants.DEFAULT_SEGMENT_LENGTH, semaphores);
Segment segment2 = new Segment(new Id(driver.nextId()), connectedSegments, TrainBenchmarkConstants.DEFAULT_SEGMENT_LENGTH, semaphores);
match.getSegment1().containingRegion().addTrackElement(segment2);
......
package de.tudresden.inf.st.train.jastadd.transformations.inject;
import de.tudresden.inf.st.train.jastadd.ast.List;
import de.tudresden.inf.st.train.jastadd.ast.SensorRef;
import de.tudresden.inf.st.train.jastadd.ast.TrackElementRef;
import de.tudresden.inf.st.train.jastadd.ast.Switch;
import de.tudresden.inf.st.train.jastadd.ast.*;
import de.tudresden.inf.st.train.jastadd.ast.TrackElementRef;
import de.tudresden.inf.st.train.jastadd.driver.JastaddDriver;
import de.tudresden.inf.st.train.jastadd.matches.JastaddSwitchMonitoredInjectMatch;
......@@ -24,14 +21,13 @@ public class JastaddTransformationInjectSwitchMonitored<TJastaddDriver extends J
java.util.List<TrackElementRef> refsToBeRemoved = new ArrayList<>();
for (final JastaddSwitchMonitoredInjectMatch match : matches) {
for (final SensorRef sensorRef : match.getSw().getMonitoredByList()) {
for (TrackElementRef trackElementRef : sensorRef.getSensor().getMonitoredElements()) {
for (final Sensor sensor : match.getSw().monitoredBy()) {
for (TrackElementRef trackElementRef : sensor.getMonitoredElements()) {
if (trackElementRef.getTrackElement() == match.getSw()) {
refsToBeRemoved.add(trackElementRef);
}
}
}
match.getSw().setMonitoredByList(new List<>());
}
for(TrackElementRef ref : refsToBeRemoved) {
......
......@@ -27,8 +27,6 @@ public class JastaddTransformationRepairSwitchMonitored<TJastaddDriver extends J
Sensor sensor = new Sensor(id, refList);
ssnm.getSw().containingRegion().getSensorList().add(sensor);
ssnm.getSw().addMonitoredBy(new SensorRef(id.getValue(), sensor));
}
driver.flushCache();
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment