Skip to content
Snippets Groups Projects
Commit 1be5c3ec authored by Markus Hamann's avatar Markus Hamann
Browse files

Add optional merging part to solution

parent b9294084
No related branches found
No related tags found
No related merge requests found
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<transportation_network:TransportationNetwork xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:transportation_network="http://www.stgroup.org/transportation_network" identifier="saxony"> <transportation_network:TransportationNetwork xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:transportation_network="http://www.stgroup.org/transportation_network" identifier="saxony">
<roadnetworks identifier="DG/1" length="95.0" source="//@locations.0" target="//@locations.3"> <roadnetworks identifier="DG/1" length="95.0" source="//@locations.0" target="//@locations.3">
<roads identifier="A4" length="95.0"/> <roads identifier="A4-E" length="95.0"/>
</roadnetworks> </roadnetworks>
<roadnetworks identifier="DL/3" length="20.0" source="//@locations.0" target="//@locations.4"> <roadnetworks identifier="DL/3" length="20.0" source="//@locations.0" target="//@locations.4">
<roads identifier="A4" length="20.0"/> <roads identifier="A4-W" length="20.0"/>
</roadnetworks> </roadnetworks>
<roadnetworks identifier="DL/2" length="67.0" source="//@locations.4" target="//@locations.5"> <roadnetworks identifier="DL/2" length="67.0" source="//@locations.4" target="//@locations.5">
<roads identifier="A14" length="67.0"/> <roads identifier="A14" length="67.0"/>
...@@ -12,8 +12,8 @@ ...@@ -12,8 +12,8 @@
<roadnetworks identifier="DL/1" length="15.0" source="//@locations.5" target="//@locations.2"> <roadnetworks identifier="DL/1" length="15.0" source="//@locations.5" target="//@locations.2">
<roads identifier="A38" length="15.0"/> <roads identifier="A38" length="15.0"/>
</roadnetworks> </roadnetworks>
<roadnetworks identifier="DC/1" length="64.0" source="//@locations.0" target="//@locations.1"> <roadnetworks identifier="DC/1" length="44.0" source="//@locations.4" target="//@locations.1">
<roads identifier="A4" length="64.0"/> <roads identifier="A4-W" length="44.0"/>
</roadnetworks> </roadnetworks>
<roadnetworks identifier="LC/1" length="69.0" source="//@locations.2" target="//@locations.1"> <roadnetworks identifier="LC/1" length="69.0" source="//@locations.2" target="//@locations.1">
<roads identifier="A72" length="69.0"/> <roads identifier="A72" length="69.0"/>
......
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<transportation_network:TransportationNetwork xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:transportation_network="http://www.stgroup.org/transportation_network" identifier="saxony"> <transportation_network:TransportationNetwork xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:transportation_network="http://www.stgroup.org/transportation_network" identifier="saxony">
<roadnetworks identifier="DG" length="95.0" source="//@locations.0" target="//@locations.3"> <roadnetworks identifier="DG" length="95.0" source="//@locations.0" target="//@locations.3">
<roads identifier="A4" length="95.0"/> <roads identifier="A4-E" length="95.0"/>
</roadnetworks> </roadnetworks>
<roadnetworks identifier="DL" length="102.0" source="//@locations.0" target="//@locations.2"> <roadnetworks identifier="DL" length="102.0" source="//@locations.0" target="//@locations.2">
<roads identifier="A4" length="20.0"/> <roads identifier="A4-W" length="20.0"/>
<roads identifier="A14" length="67.0"/> <roads identifier="A14" length="67.0"/>
<roads identifier="A38" length="15.0"/> <roads identifier="A38" length="15.0"/>
</roadnetworks> </roadnetworks>
<roadnetworks identifier="DC" length="64.0" source="//@locations.0" target="//@locations.1"> <roadnetworks identifier="DC" length="64.0" source="//@locations.0" target="//@locations.1">
<roads identifier="A4" length="64.0"/> <roads identifier="A4-W" length="64.0"/>
</roadnetworks> </roadnetworks>
<roadnetworks identifier="LC" length="69.0" source="//@locations.2" target="//@locations.1"> <roadnetworks identifier="LC" length="69.0" source="//@locations.2" target="//@locations.1">
<roads identifier="A72" length="69.0"/> <roads identifier="A72" length="69.0"/>
......
...@@ -51,12 +51,49 @@ rule SplitRoadNetworks ...@@ -51,12 +51,49 @@ rule SplitRoadNetworks
} }
rule deleteEmptyRoadNetworks rule deleteEmptyRoadNetworks
transform s : source!RoadNetwork transform s : source!RoadNetwork
to t : target!EObject to t : target!EObject
{ {
guard: not s.roads.isEmpty() if(s.roads.isEmpty()){
delete s; delete s;
} }
}
/*
* Optional Part for merging Road Networks with the help of an operation
*/
rule mergeRoadNetworks
transform s : source!TransportationNetwork
to t : target!EObject{
for (r in s.roadNetworks) {
var toBeMergeRNs = r.RNtoMerge();
if(not toBeMergeRNs.isEmpty()){
toBeMergeRNs.add(r);
var minRoad = toBeMergeRNs.sortBy(rn | rn.roads.first().length).first();
toBeMergeRNs.remove(minRoad);
for (mergingRN in toBeMergeRNs) {
mergingRN.source = minRoad.target;
mergingRN.roads.first().length -= minRoad.roads.first().length;
mergingRN.length = mergingRN.roads.first().length;
}
}
}
}
operation source!RoadNetwork RNtoMerge() : Set {
if(self.eContainer() <> null){
return self.eContainer().roadNetworks.select(rn | rn.source.equals(self.source)
and not (rn == self))
.select(rn | (rn.roads.size() == 1)
and (rn.roads.first().identifier == self.roads.first().identifier));
} else{
return new Set;
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment