diff --git a/model_examples/model_extension/saxony.transportation_network b/model_examples/model_extension/saxony.transportation_network index bc072bf9a4511f970db33972e0b1dc344b4f3765..5a0fa462bc3497289599665cf1681cdb4072ead9 100644 --- a/model_examples/model_extension/saxony.transportation_network +++ b/model_examples/model_extension/saxony.transportation_network @@ -1,10 +1,10 @@ <?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"> <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 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 identifier="DL/2" length="67.0" source="//@locations.4" target="//@locations.5"> <roads identifier="A14" length="67.0"/> @@ -12,8 +12,8 @@ <roadnetworks identifier="DL/1" length="15.0" source="//@locations.5" target="//@locations.2"> <roads identifier="A38" length="15.0"/> </roadnetworks> - <roadnetworks identifier="DC/1" length="64.0" source="//@locations.0" target="//@locations.1"> - <roads identifier="A4" length="64.0"/> + <roadnetworks identifier="DC/1" length="44.0" source="//@locations.4" target="//@locations.1"> + <roads identifier="A4-W" length="44.0"/> </roadnetworks> <roadnetworks identifier="LC/1" length="69.0" source="//@locations.2" target="//@locations.1"> <roads identifier="A72" length="69.0"/> diff --git a/model_examples/model_extension/saxony_original.transportation_network b/model_examples/model_extension/saxony_original.transportation_network index bfce3809907559867d10dd80ce27a8e71323ff2e..7e0b4b265a23ebf10aa2b98873634b56a7b50802 100644 --- a/model_examples/model_extension/saxony_original.transportation_network +++ b/model_examples/model_extension/saxony_original.transportation_network @@ -1,15 +1,15 @@ <?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"> <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 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="A38" length="15.0"/> </roadnetworks> <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 identifier="LC" length="69.0" source="//@locations.2" target="//@locations.1"> <roads identifier="A72" length="69.0"/> diff --git a/stgroup.mdsd.transportation_network.transformation/model_extension/model_extension.etl b/stgroup.mdsd.transportation_network.transformation/model_extension/model_extension.etl index dfc5bf7efc312ad2a2aa52654c487c49be97a3c5..44b42112f1335a87933715109d4b52f365715d72 100644 --- a/stgroup.mdsd.transportation_network.transformation/model_extension/model_extension.etl +++ b/stgroup.mdsd.transportation_network.transformation/model_extension/model_extension.etl @@ -30,7 +30,7 @@ rule SplitRoadNetworks to l : source!Location, rn : source!RoadNetwork { - + var originalRN:source!RoadNetwork = s.eContainer(); var network:source!TransportationNetwork = originalRN.eContainer(); @@ -51,12 +51,49 @@ rule SplitRoadNetworks } + rule deleteEmptyRoadNetworks transform s : source!RoadNetwork to t : target!EObject { - guard: not s.roads.isEmpty() + if(s.roads.isEmpty()){ + 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; + } - delete s; -} \ No newline at end of file +}