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

Add model extension solution

parent 9e5b53f8
Branches
Tags
No related merge requests found
<?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"/>
</roadnetworks>
<roadnetworks identifier="DL/3" length="20.0" source="//@locations.0" target="//@locations.5">
<roads identifier="A4" length="20.0"/>
</roadnetworks>
<roadnetworks identifier="DL/2" length="67.0" source="//@locations.5" target="//@locations.6">
<roads identifier="A14" length="67.0"/>
</roadnetworks>
<roadnetworks identifier="DL/1" length="15.0" source="//@locations.6" 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>
<roadnetworks identifier="LC/1" length="69.0" source="//@locations.2" target="//@locations.1">
<roads identifier="A72" length="69.0"/>
</roadnetworks>
<locations name="Dresden">
<pois xsi:type="transportation_network:RestStop"/>
<pois xsi:type="transportation_network:GasStation">
<fueltypes>PETROL</fueltypes>
<fueltypes>DIESEL</fueltypes>
<fueltypes>ELECTRICITY</fueltypes>
</pois>
<pois xsi:type="transportation_network:CompanyWarehouse" name="A1"/>
</locations>
<locations name="Chemnitz">
<pois xsi:type="transportation_network:CustomerWarehouse" name="OG-01" customerName="Office GmbH"/>
<pois xsi:type="transportation_network:Other" name="Owner`s Home" type="Private House"/>
</locations>
<locations name="Leipzig">
<pois xsi:type="transportation_network:CustomerWarehouse" name="DA-01" customerName="Delivery AG"/>
<pois xsi:type="transportation_network:RestStop"/>
</locations>
<locations name="Görlitz">
<pois xsi:type="transportation_network:RestStop"/>
<pois xsi:type="transportation_network:GasStation">
<fueltypes>PETROL</fueltypes>
<fueltypes>DIESEL</fueltypes>
</pois>
</locations>
<locations/>
<locations/>
<locations/>
<locations/>
<locations/>
<locations/>
<routes identifier="R1" start="//@locations.0" end="//@locations.1">
<vehicle identifier="V03" location="//@locations.0" model="eTruck" fuelCapacity="150.0"/>
</routes>
<carPark identifier="V01" location="//@locations.0" model="eTruck" fuelCapacity="150.0"/>
<carPark identifier="V02" location="//@locations.2" model="eTruck" fuelCapacity="150.0"/>
</transportation_network:TransportationNetwork>
<?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"/>
</roadnetworks>
<roadnetworks identifier="DL" length="102.0" source="//@locations.0" target="//@locations.2">
<roads identifier="A4" 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"/>
</roadnetworks>
<roadnetworks identifier="LC" length="69.0" source="//@locations.2" target="//@locations.1">
<roads identifier="A72" length="69.0"/>
</roadnetworks>
<locations name="Dresden">
<pois xsi:type="transportation_network:RestStop"/>
<pois xsi:type="transportation_network:GasStation">
<fueltypes>PETROL</fueltypes>
<fueltypes>DIESEL</fueltypes>
<fueltypes>ELECTRICITY</fueltypes>
</pois>
<pois xsi:type="transportation_network:CompanyWarehouse" name="A1"/>
</locations>
<locations name="Chemnitz">
<pois xsi:type="transportation_network:CustomerWarehouse" name="OG-01" customerName="Office GmbH"/>
<pois xsi:type="transportation_network:Other" name="Owner`s Home" type="Private House"/>
</locations>
<locations name="Leipzig">
<pois xsi:type="transportation_network:CustomerWarehouse" name="DA-01" customerName="Delivery AG"/>
<pois xsi:type="transportation_network:RestStop"/>
</locations>
<locations name="Görlitz">
<pois xsi:type="transportation_network:RestStop"/>
<pois xsi:type="transportation_network:GasStation">
<fueltypes>PETROL</fueltypes>
<fueltypes>DIESEL</fueltypes>
</pois>
</locations>
<routes identifier="R1" networkList="//@roadnetworks.1 //@roadnetworks.3" start="//@locations.0" end="//@locations.1">
<vehicle identifier="V03" location="//@locations.0" model="eTruck" fuelCapacity="150.0"/>
</routes>
<carPark identifier="V01" location="//@locations.0" model="eTruck" fuelCapacity="150.0"/>
<carPark identifier="V02" location="//@locations.2" model="eTruck" fuelCapacity="150.0"/>
</transportation_network:TransportationNetwork>
/*
* Example of extending by rewriting a model.
* Here: Splitting a road network if the network
* use multiple roads.
*/
/*
* Normal configuration:
* Source model: Read=true, Write=true
* Target model: Read=false, Write=false
*/
pre {
"Model Extending/Rewrite Example".println();
"-------------------------------------".println();
"Start of transformation...".println();
}
post {
"... End of transformation.".println();
}
/*
* Option 1: Have a rule for the model elements which need to be extended.
* Write the extended elements in your source model.
*/
rule SplitRoadNetworks
transform s : source!Road
to l : source!Location,
rn : source!RoadNetwork
{
var originalRN:source!RoadNetwork = s.eContainer();
var network:source!TransportationNetwork = originalRN.eContainer();
rn.identifier = originalRN.identifier + "/" + originalRN.roads.size();
rn.roads.add(s);
rn.length = s.length;
rn.source = originalRN.source;
if (originalRN.roads.isEmpty()){
rn.target = originalRN.target;
delete l;
} else{
rn.target = l;
}
originalRN.source = l;
network.roadnetworks.add(rn);
network.locations.add(l);
}
rule deleteEmptyRoadNetworks
transform s : source!RoadNetwork
to t : target!EObject
{
guard: not s.roads.isEmpty()
delete s;
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment