Commit 85cf7286 authored by Dinh-An Ho's avatar Dinh-An Ho

Merge remote-tracking branch 'origin/ML_clustering' into ML_clustering

parents 21635365 c801070a
Pipeline #98809 failed with stages
in 35 seconds
...@@ -10,9 +10,9 @@ for your new MiddlewareSymbol. Make sure to load all your tags before starting g ...@@ -10,9 +10,9 @@ for your new MiddlewareSymbol. Make sure to load all your tags before starting g
## Generator ## Generator
The new middleware generator needs to the following methods The new middleware generator needs to the following methods
* `setGenerationTargetPath(String path)`: Sets the directory the generated files are written to. * `setGenerationTargetPath(String path)`: Sets the directory the generated files are written to.
* `boolean willAccept(ExpandedComponentInstanceSymbol componentInstanceSymbol)`: Signals the DistributedTargetGenerator if the middleware generator will generate useful files for the given component. * `boolean willAccept(EMAComponentInstanceSymbol componentInstanceSymbol)`: Signals the DistributedTargetGenerator if the middleware generator will generate useful files for the given component.
* Example: If a Component without RosConnections is passed to the ROS generator, it will reject it. * Example: If a Component without RosConnections is passed to the ROS generator, it will reject it.
* `List<File> generate(ExpandedComponentInstanceSymbol componentInstanceSymbol, TaggingResolver taggingResolver)`: Generates all files(Adapter + CMake) for the given Component. * `List<File> generate(EMAComponentInstanceSymbol componentInstanceSymbol, TaggingResolver taggingResolver)`: Generates all files(Adapter + CMake) for the given Component.
These 3 methods are combined in the Interface [GeneratorImpl](https://git.rwth-aachen.de/monticore/EmbeddedMontiArc/generators/EMAM2Middleware/blob/master/src/main/java/de/monticore/lang/monticar/generator/middleware/impls/GeneratorImpl.java). These 3 methods are combined in the Interface [GeneratorImpl](https://git.rwth-aachen.de/monticore/EmbeddedMontiArc/generators/EMAM2Middleware/blob/master/src/main/java/de/monticore/lang/monticar/generator/middleware/impls/GeneratorImpl.java).
To avoid a cyclic dependency between the new middleware generator and EMAM2Middleware, it is advised to write a small wrapper in EMAM2Middleware instead of implementing the Interface directly. See [RosCppGenImpl](https://git.rwth-aachen.de/monticore/EmbeddedMontiArc/generators/EMAM2Middleware/blob/master/src/main/java/de/monticore/lang/monticar/generator/middleware/impls/RosCppGenImpl.java) for an example. To avoid a cyclic dependency between the new middleware generator and EMAM2Middleware, it is advised to write a small wrapper in EMAM2Middleware instead of implementing the Interface directly. See [RosCppGenImpl](https://git.rwth-aachen.de/monticore/EmbeddedMontiArc/generators/EMAM2Middleware/blob/master/src/main/java/de/monticore/lang/monticar/generator/middleware/impls/RosCppGenImpl.java) for an example.
......
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
<groupId>de.monticore.lang.monticar</groupId> <groupId>de.monticore.lang.monticar</groupId>
<artifactId>embedded-montiarc-math-middleware-generator</artifactId> <artifactId>embedded-montiarc-math-middleware-generator</artifactId>
<version>0.0.13-SNAPSHOT</version> <version>0.0.14-SNAPSHOT</version>
<!-- == PROJECT DEPENDENCIES ============================================= --> <!-- == PROJECT DEPENDENCIES ============================================= -->
...@@ -18,14 +18,13 @@ ...@@ -18,14 +18,13 @@
<!-- .. SE-Libraries .................................................. --> <!-- .. SE-Libraries .................................................. -->
<se-commons.version>1.7.7</se-commons.version> <se-commons.version>1.7.7</se-commons.version>
<Embedded-montiarc-math-generator.version>0.0.26-SNAPSHOT</Embedded-montiarc-math-generator.version>
<Embedded-montiarc-math-roscpp-generator.version>0.0.4-SNAPSHOT</Embedded-montiarc-math-roscpp-generator.version> <embedded-montiarc.version>0.1.9-SNAPSHOT</embedded-montiarc.version>
<Embedded-montiarc-math-rosmsg-generator.version>0.0.3-SNAPSHOT</Embedded-montiarc-math-rosmsg-generator.version> <Embedded-montiarc-math-generator.version>0.1.3-SNAPSHOT</Embedded-montiarc-math-generator.version>
<EMADL.version>0.2.3</EMADL.version> <Embedded-montiarc-math-roscpp-generator.version>0.1.1-SNAPSHOT</Embedded-montiarc-math-roscpp-generator.version>
<EMADL2CPP.version>0.2.4</EMADL2CPP.version> <EMADL.version>0.2.4</EMADL.version>
<EMADL2CPP.version>0.2.6-SNAPSHOT</EMADL2CPP.version>
<!--TODO: remove with update to new emam version-->
<Tagging.version>0.0.6</Tagging.version>
<!-- .. Libraries .................................................. --> <!-- .. Libraries .................................................. -->
<guava.version>18.0</guava.version> <guava.version>18.0</guava.version>
<junit.version>4.12</junit.version> <junit.version>4.12</junit.version>
...@@ -52,6 +51,12 @@ ...@@ -52,6 +51,12 @@
</properties> </properties>
<dependencies> <dependencies>
<dependency>
<groupId>de.monticore.lang.monticar</groupId>
<artifactId>embedded-montiarc</artifactId>
<version>${embedded-montiarc.version}</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.google.code.gson/gson --> <!-- https://mvnrepository.com/artifact/com.google.code.gson/gson -->
<dependency> <dependency>
<groupId>com.google.code.gson</groupId> <groupId>com.google.code.gson</groupId>
...@@ -119,9 +124,17 @@ ...@@ -119,9 +124,17 @@
</dependency> </dependency>
<dependency> <dependency>
<groupId>de.monticore.lang.monticar</groupId> <groupId>org.graphstream</groupId>
<artifactId>embedded-montiarc-math-rosmsg-generator</artifactId> <artifactId>gs-core</artifactId>
<version>${Embedded-montiarc-math-rosmsg-generator.version}</version> <version>1.3</version>
<optional>false</optional>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-math</artifactId>
<version>2.1</version>
<optional>false</optional>
</dependency> </dependency>
<!-- EMADL Dependencies --> <!-- EMADL Dependencies -->
...@@ -137,13 +150,6 @@ ...@@ -137,13 +150,6 @@
</dependency> </dependency>
<!-- MontiCore Dependencies --> <!-- MontiCore Dependencies -->
<dependency>
<groupId>de.monticore.lang</groupId>
<artifactId>Tagging</artifactId>
<version>${Tagging.version}</version>
</dependency>
<dependency> <dependency>
<groupId>de.se_rwth.commons</groupId> <groupId>de.se_rwth.commons</groupId>
<artifactId>se-commons-groovy</artifactId> <artifactId>se-commons-groovy</artifactId>
......
package de.monticore.lang.monticar.generator.middleware; package de.monticore.lang.monticar.generator.middleware;
import de.monticore.lang.embeddedmontiarc.embeddedmontiarc._symboltable.ExpandedComponentInstanceSymbol; import de.monticore.lang.embeddedmontiarc.embeddedmontiarc._symboltable.instanceStructure.EMAComponentInstanceSymbol;
import de.monticore.lang.monticar.generator.FileContent; import de.monticore.lang.monticar.generator.FileContent;
import de.monticore.lang.monticar.generator.middleware.helpers.FileHelper; import de.monticore.lang.monticar.generator.middleware.helpers.FileHelper;
import de.monticore.lang.tagging._symboltable.TaggingResolver; import de.monticore.lang.tagging._symboltable.TaggingResolver;
...@@ -15,7 +15,7 @@ import java.util.Objects; ...@@ -15,7 +15,7 @@ import java.util.Objects;
public class CMakeGenerator extends StarBridgeGenerator { public class CMakeGenerator extends StarBridgeGenerator {
@Override @Override
public List<File> generate(ExpandedComponentInstanceSymbol componentInstanceSymbol, TaggingResolver taggingResolver) throws IOException { public List<File> generate(EMAComponentInstanceSymbol componentInstanceSymbol, TaggingResolver taggingResolver) throws IOException {
long notInSubdirs = getGeneratorImpls().stream() long notInSubdirs = getGeneratorImpls().stream()
.map(this::getImplSubdir) .map(this::getImplSubdir)
.filter(Objects::isNull) .filter(Objects::isNull)
...@@ -31,7 +31,7 @@ public class CMakeGenerator extends StarBridgeGenerator { ...@@ -31,7 +31,7 @@ public class CMakeGenerator extends StarBridgeGenerator {
return res; return res;
} }
protected File generateCMake(ExpandedComponentInstanceSymbol componentInstanceSymbol) throws IOException { protected File generateCMake(EMAComponentInstanceSymbol componentInstanceSymbol) throws IOException {
FileContent fileContent = new FileContent(); FileContent fileContent = new FileContent();
fileContent.setFileName("CMakeLists.txt"); fileContent.setFileName("CMakeLists.txt");
StringBuilder content = new StringBuilder(); StringBuilder content = new StringBuilder();
......
package de.monticore.lang.monticar.generator.middleware; package de.monticore.lang.monticar.generator.middleware;
import de.monticore.lang.embeddedmontiarc.embeddedmontiarc._symboltable.ExpandedComponentInstanceSymbol; import de.monticore.lang.embeddedmontiarc.embeddedmontiarc._symboltable.instanceStructure.EMAComponentInstanceSymbol;
import de.monticore.lang.monticar.generator.FileContent; import de.monticore.lang.monticar.generator.FileContent;
import de.monticore.lang.monticar.generator.middleware.clustering.ClusterFromTagsHelper; import de.monticore.lang.monticar.generator.middleware.clustering.ClusterFromTagsHelper;
import de.monticore.lang.monticar.generator.middleware.helpers.*; import de.monticore.lang.monticar.generator.middleware.helpers.*;
...@@ -36,12 +36,12 @@ public class DistributedTargetGenerator extends CMakeGenerator { ...@@ -36,12 +36,12 @@ public class DistributedTargetGenerator extends CMakeGenerator {
} }
@Override @Override
public List<File> generate(ExpandedComponentInstanceSymbol componentInstanceSymbol, TaggingResolver taggingResolver) throws IOException { public List<File> generate(EMAComponentInstanceSymbol componentInstanceSymbol, TaggingResolver taggingResolver) throws IOException {
Map<ExpandedComponentInstanceSymbol, GeneratorImpl> generatorMap = new HashMap<>(); Map<EMAComponentInstanceSymbol, GeneratorImpl> generatorMap = new HashMap<>();
fixComponentInstance(componentInstanceSymbol); fixComponentInstance(componentInstanceSymbol);
List<ExpandedComponentInstanceSymbol> clusterSubcomponents = ClusterFromTagsHelper.getClusterSubcomponents(componentInstanceSymbol); List<EMAComponentInstanceSymbol> clusterSubcomponents = ClusterFromTagsHelper.getClusterSubcomponents(componentInstanceSymbol);
if (clusterSubcomponents.size() > 0) { if (clusterSubcomponents.size() > 0) {
clusterSubcomponents.forEach(clusterECIS -> { clusterSubcomponents.forEach(clusterECIS -> {
String nameTargetLanguage = NameHelper.getNameTargetLanguage(clusterECIS.getFullName()); String nameTargetLanguage = NameHelper.getNameTargetLanguage(clusterECIS.getFullName());
...@@ -54,7 +54,7 @@ public class DistributedTargetGenerator extends CMakeGenerator { ...@@ -54,7 +54,7 @@ public class DistributedTargetGenerator extends CMakeGenerator {
List<File> files = new ArrayList<>(); List<File> files = new ArrayList<>();
for (ExpandedComponentInstanceSymbol comp : generatorMap.keySet()) { for (EMAComponentInstanceSymbol comp : generatorMap.keySet()) {
files.addAll(generatorMap.get(comp).generate(comp, taggingResolver)); files.addAll(generatorMap.get(comp).generate(comp, taggingResolver));
//add empty generator to subDirs so that CMakeLists.txt will be generated correctly //add empty generator to subDirs so that CMakeLists.txt will be generated correctly
subDirs.add(NameHelper.getNameTargetLanguage(comp.getFullName())); subDirs.add(NameHelper.getNameTargetLanguage(comp.getFullName()));
...@@ -91,12 +91,12 @@ public class DistributedTargetGenerator extends CMakeGenerator { ...@@ -91,12 +91,12 @@ public class DistributedTargetGenerator extends CMakeGenerator {
return res; return res;
} }
private void fixComponentInstance(ExpandedComponentInstanceSymbol componentInstanceSymbol) { private void fixComponentInstance(EMAComponentInstanceSymbol componentInstanceSymbol) {
RosHelper.fixRosConnectionSymbols(componentInstanceSymbol); RosHelper.fixRosConnectionSymbols(componentInstanceSymbol);
} }
@Override @Override
protected File generateCMake(ExpandedComponentInstanceSymbol componentInstanceSymbol) throws IOException { protected File generateCMake(EMAComponentInstanceSymbol componentInstanceSymbol) throws IOException {
FileContent fileContent = new FileContent(); FileContent fileContent = new FileContent();
fileContent.setFileName("CMakeLists.txt"); fileContent.setFileName("CMakeLists.txt");
StringBuilder content = new StringBuilder(); StringBuilder content = new StringBuilder();
......
...@@ -2,7 +2,7 @@ package de.monticore.lang.monticar.generator.middleware; ...@@ -2,7 +2,7 @@ package de.monticore.lang.monticar.generator.middleware;
import com.google.gson.Gson; import com.google.gson.Gson;
import com.google.gson.stream.JsonReader; import com.google.gson.stream.JsonReader;
import de.monticore.lang.embeddedmontiarc.embeddedmontiarc._symboltable.ExpandedComponentInstanceSymbol; import de.monticore.lang.embeddedmontiarc.embeddedmontiarc._symboltable.instanceStructure.EMAComponentInstanceSymbol;
import de.monticore.lang.embeddedmontiarc.tagging.middleware.ros.RosToEmamTagSchema; import de.monticore.lang.embeddedmontiarc.tagging.middleware.ros.RosToEmamTagSchema;
import de.monticore.lang.monticar.emadl.generator.EMADLAbstractSymtab; import de.monticore.lang.monticar.emadl.generator.EMADLAbstractSymtab;
import de.monticore.lang.monticar.emadl.generator.EMADLGeneratorCli; import de.monticore.lang.monticar.emadl.generator.EMADLGeneratorCli;
...@@ -127,7 +127,7 @@ public final class DistributedTargetGeneratorCli { ...@@ -127,7 +127,7 @@ public final class DistributedTargetGeneratorCli {
} }
}); });
ExpandedComponentInstanceSymbol componentInstanceSymbol = taggingResolver.<ExpandedComponentInstanceSymbol>resolve(cliParameters.getRootModel(), ExpandedComponentInstanceSymbol.KIND).orElse(null); EMAComponentInstanceSymbol componentInstanceSymbol = taggingResolver.<EMAComponentInstanceSymbol>resolve(cliParameters.getRootModel(), EMAComponentInstanceSymbol.KIND).orElse(null);
if (componentInstanceSymbol == null) { if (componentInstanceSymbol == null) {
Log.error("0x5FFAE: The given component cannot be resolved."); Log.error("0x5FFAE: The given component cannot be resolved.");
......
package de.monticore.lang.monticar.generator.middleware; package de.monticore.lang.monticar.generator.middleware;
import de.monticore.lang.embeddedmontiarc.embeddedmontiarc._symboltable.ExpandedComponentInstanceSymbol; import de.monticore.lang.embeddedmontiarc.embeddedmontiarc._symboltable.instanceStructure.EMAComponentInstanceSymbol;
import de.monticore.lang.monticar.generator.FileContent; import de.monticore.lang.monticar.generator.FileContent;
import de.monticore.lang.monticar.generator.cpp.converter.ComponentConverter; import de.monticore.lang.monticar.generator.cpp.converter.ComponentConverter;
import de.monticore.lang.monticar.generator.middleware.helpers.FileHelper; import de.monticore.lang.monticar.generator.middleware.helpers.FileHelper;
...@@ -17,7 +17,7 @@ import java.util.stream.Collectors; ...@@ -17,7 +17,7 @@ import java.util.stream.Collectors;
public class MiddlewareGenerator extends CMakeGenerator { public class MiddlewareGenerator extends CMakeGenerator {
@Override @Override
public List<File> generate(ExpandedComponentInstanceSymbol componentInstanceSymbol, TaggingResolver taggingResolver) throws IOException { public List<File> generate(EMAComponentInstanceSymbol componentInstanceSymbol, TaggingResolver taggingResolver) throws IOException {
//Add dummy GeneratorImpl for the subdir //Add dummy GeneratorImpl for the subdir
String subdir = "coordinator/"; String subdir = "coordinator/";
this.add(new GeneratorImpl() { this.add(new GeneratorImpl() {
...@@ -30,7 +30,7 @@ public class MiddlewareGenerator extends CMakeGenerator { ...@@ -30,7 +30,7 @@ public class MiddlewareGenerator extends CMakeGenerator {
return files; return files;
} }
private FileContent generateIAdapter(ExpandedComponentInstanceSymbol componentInstanceSymbol) { private FileContent generateIAdapter(EMAComponentInstanceSymbol componentInstanceSymbol) {
FileContent res = new FileContent(); FileContent res = new FileContent();
String name = NameHelper.getNameTargetLanguage(componentInstanceSymbol.getFullName()); String name = NameHelper.getNameTargetLanguage(componentInstanceSymbol.getFullName());
res.setFileName("IAdapter_" + name + ".h"); res.setFileName("IAdapter_" + name + ".h");
...@@ -39,7 +39,7 @@ public class MiddlewareGenerator extends CMakeGenerator { ...@@ -39,7 +39,7 @@ public class MiddlewareGenerator extends CMakeGenerator {
} }
private FileContent generateCoordinator(ExpandedComponentInstanceSymbol componentInstanceSymbol, List<File> files) { private FileContent generateCoordinator(EMAComponentInstanceSymbol componentInstanceSymbol, List<File> files) {
String name = NameHelper.getNameTargetLanguage(componentInstanceSymbol.getFullName()); String name = NameHelper.getNameTargetLanguage(componentInstanceSymbol.getFullName());
...@@ -80,7 +80,7 @@ public class MiddlewareGenerator extends CMakeGenerator { ...@@ -80,7 +80,7 @@ public class MiddlewareGenerator extends CMakeGenerator {
} }
private FileContent generateCoordinatorCMakeList(ExpandedComponentInstanceSymbol componentInstanceSymbol, List<File> files) { private FileContent generateCoordinatorCMakeList(EMAComponentInstanceSymbol componentInstanceSymbol, List<File> files) {
FileContent res = new FileContent(); FileContent res = new FileContent();
String name = NameHelper.getNameTargetLanguage(componentInstanceSymbol.getFullName()); String name = NameHelper.getNameTargetLanguage(componentInstanceSymbol.getFullName());
......
package de.monticore.lang.monticar.generator.middleware; package de.monticore.lang.monticar.generator.middleware;
import de.monticore.lang.embeddedmontiarc.embeddedmontiarc._symboltable.ExpandedComponentInstanceSymbol; import de.monticore.lang.embeddedmontiarc.embeddedmontiarc._symboltable.instanceStructure.EMAComponentInstanceSymbol;
import de.monticore.lang.monticar.generator.middleware.impls.GeneratorImpl; import de.monticore.lang.monticar.generator.middleware.impls.GeneratorImpl;
import de.monticore.lang.tagging._symboltable.TaggingResolver; import de.monticore.lang.tagging._symboltable.TaggingResolver;
import de.se_rwth.commons.logging.Log; import de.se_rwth.commons.logging.Log;
...@@ -34,7 +34,7 @@ public class StarBridgeGenerator implements GeneratorImpl { ...@@ -34,7 +34,7 @@ public class StarBridgeGenerator implements GeneratorImpl {
this.generationTargetPath = path.endsWith("/") ? path : path + "/"; this.generationTargetPath = path.endsWith("/") ? path : path + "/";
} }
public List<File> generate(ExpandedComponentInstanceSymbol componentInstanceSymbol, TaggingResolver taggingResolver) throws IOException { public List<File> generate(EMAComponentInstanceSymbol componentInstanceSymbol, TaggingResolver taggingResolver) throws IOException {
List<File> result = new ArrayList<>(); List<File> result = new ArrayList<>();
generatorImpls.forEach((key, value) -> { generatorImpls.forEach((key, value) -> {
if (key.willAccept(componentInstanceSymbol)) { if (key.willAccept(componentInstanceSymbol)) {
......
...@@ -2,6 +2,9 @@ package de.monticore.lang.monticar.generator.middleware.clustering; ...@@ -2,6 +2,9 @@ package de.monticore.lang.monticar.generator.middleware.clustering;
import de.monticore.expressionsbasis._ast.ASTExpression; import de.monticore.expressionsbasis._ast.ASTExpression;
import de.monticore.lang.embeddedmontiarc.embeddedmontiarc._symboltable.*; import de.monticore.lang.embeddedmontiarc.embeddedmontiarc._symboltable.*;
import de.monticore.lang.embeddedmontiarc.embeddedmontiarc._symboltable.cncModel.EMAPortSymbol;
import de.monticore.lang.embeddedmontiarc.embeddedmontiarc._symboltable.instanceStructure.EMAComponentInstanceSymbol;
import de.monticore.lang.embeddedmontiarc.embeddedmontiarc._symboltable.instanceStructure.EMAConnectorInstanceSymbol;
import de.monticore.lang.embeddedmontiarc.tagging.middleware.ros.RosConnectionSymbol; import de.monticore.lang.embeddedmontiarc.tagging.middleware.ros.RosConnectionSymbol;
import de.monticore.lang.math._ast.ASTNumberExpression; import de.monticore.lang.math._ast.ASTNumberExpression;
import de.monticore.lang.monticar.common2._ast.ASTCommonMatrixType; import de.monticore.lang.monticar.common2._ast.ASTCommonMatrixType;
...@@ -19,27 +22,22 @@ import java.util.stream.Collectors; ...@@ -19,27 +22,22 @@ import java.util.stream.Collectors;
public class AutomaticClusteringHelper { public class AutomaticClusteringHelper {
static double MAXCOST= 999999; // public static double[][] createAdjacencyMatrix(List<ExpandedComponentInstanceSymbol> subcomps, Collection<ConnectorSymbol> connectors, Map<String, Integer> subcompLabels) {
public static double[][] createAdjacencyMatrix(List<EMAComponentInstanceSymbol> subcomps, Collection<EMAConnectorInstanceSymbol> connectors, Map<String, Integer> subcompLabels) {
public static double[][] createAdjacencyMatrix(List<ExpandedComponentInstanceSymbol> subcomps, Collection<ConnectorSymbol> connectors, Map<String, Integer> subcompLabels) {
// Nodes = subcomponents // Nodes = subcomponents
// Verts = connectors between subcomponents // Verts = connectors between subcomponents
double[][] res = new double[subcomps.size()][subcomps.size()]; double[][] res = new double[subcomps.size()][subcomps.size()];
connectors.forEach(con -> { connectors.forEach(con -> {
Optional<ExpandedComponentInstanceSymbol> sourceCompOpt = con.getSourcePort().getComponentInstance(); EMAComponentInstanceSymbol sourceCompOpt = con.getSourcePort().getComponentInstance();
Optional<ExpandedComponentInstanceSymbol> targetCompOpt = con.getTargetPort().getComponentInstance(); EMAComponentInstanceSymbol targetCompOpt = con.getTargetPort().getComponentInstance();
if (sourceCompOpt.isPresent() && targetCompOpt.isPresent()) { int index1 = subcompLabels.get(sourceCompOpt.getFullName());
int index1 = subcompLabels.get(sourceCompOpt.get().getFullName()); int index2 = subcompLabels.get(targetCompOpt.getFullName());
int index2 = subcompLabels.get(targetCompOpt.get().getFullName());
res[index1][index2] = getTypeCostHeuristic(con.getSourcePort()); res[index1][index2] = getTypeCostHeuristic(con.getSourcePort());
res[index2][index1] = getTypeCostHeuristic(con.getSourcePort()); res[index2][index1] = getTypeCostHeuristic(con.getSourcePort());
} else {
Log.error("0xADE65: Component of source or target not found!");
}
}); });
...@@ -105,16 +103,16 @@ public class AutomaticClusteringHelper { ...@@ -105,16 +103,16 @@ public class AutomaticClusteringHelper {
return normalizeMatrix(inverseProbabilitiesMatrix(adjacencyMatrix)); return normalizeMatrix(inverseProbabilitiesMatrix(adjacencyMatrix));
} }
public static void annotateComponentWithRosTagsForClusters(ExpandedComponentInstanceSymbol componentInstanceSymbol, List<Set<ExpandedComponentInstanceSymbol>> clusters) { public static void annotateComponentWithRosTagsForClusters(EMAComponentInstanceSymbol componentInstanceSymbol, List<Set<EMAComponentInstanceSymbol>> clusters) {
Collection<ConnectorSymbol> connectors = componentInstanceSymbol.getConnectors(); Collection<EMAConnectorInstanceSymbol> connectors = componentInstanceSymbol.getConnectorInstances();
connectors.forEach(con -> { connectors.forEach(con -> {
// -1 = super comp // -1 = super comp
int sourceClusterLabel = -1; int sourceClusterLabel = -1;
int targetClusterLabel = -1; int targetClusterLabel = -1;
ExpandedComponentInstanceSymbol sourceComp = con.getSourcePort().getComponentInstance().get(); EMAComponentInstanceSymbol sourceComp = con.getSourcePort().getComponentInstance();
ExpandedComponentInstanceSymbol targetComp = con.getTargetPort().getComponentInstance().get(); EMAComponentInstanceSymbol targetComp = con.getTargetPort().getComponentInstance();
for(int i = 0; i < clusters.size(); i++){ for(int i = 0; i < clusters.size(); i++){
if(clusters.get(i).contains(sourceComp)){ if(clusters.get(i).contains(sourceComp)){
...@@ -135,7 +133,7 @@ public class AutomaticClusteringHelper { ...@@ -135,7 +133,7 @@ public class AutomaticClusteringHelper {
} }
public static double getTypeCostHeuristic(PortSymbol port){ public static double getTypeCostHeuristic(EMAPortSymbol port){
return getTypeCostHeuristic(port.getTypeReference()); return getTypeCostHeuristic(port.getTypeReference());
} }
......
package de.monticore.lang.monticar.generator.middleware.clustering; package de.monticore.lang.monticar.generator.middleware.clustering;
import de.monticore.lang.embeddedmontiarc.embeddedmontiarc._symboltable.*; import de.monticore.lang.embeddedmontiarc.embeddedmontiarc._symboltable.cncModel.EMAConnectorBuilder;
import de.monticore.lang.embeddedmontiarc.embeddedmontiarc._symboltable.cncModel.EMAConnectorSymbol;
import de.monticore.lang.embeddedmontiarc.embeddedmontiarc._symboltable.cncModel.EMAPortBuilder;
import de.monticore.lang.embeddedmontiarc.embeddedmontiarc._symboltable.cncModel.EMAPortSymbol;
import de.monticore.lang.embeddedmontiarc.embeddedmontiarc._symboltable.instanceStructure.EMAComponentInstanceBuilder;
import de.monticore.lang.embeddedmontiarc.embeddedmontiarc._symboltable.instanceStructure.EMAComponentInstanceSymbol;
import de.monticore.lang.embeddedmontiarc.embeddedmontiarc._symboltable.instanceStructure.EMAConnectorInstanceSymbol;
import de.monticore.lang.embeddedmontiarc.embeddedmontiarc._symboltable.instanceStructure.EMAPortInstanceSymbol;
import de.monticore.symboltable.CommonScope; import de.monticore.symboltable.CommonScope;
import de.monticore.symboltable.MutableScope; import de.monticore.symboltable.MutableScope;
import de.monticore.symboltable.Symbol; import de.monticore.symboltable.Symbol;
...@@ -19,17 +26,17 @@ public class ClusterFromTagsHelper { ...@@ -19,17 +26,17 @@ public class ClusterFromTagsHelper {
private ClusterFromTagsHelper() { private ClusterFromTagsHelper() {
} }
public static List<Set<ExpandedComponentInstanceSymbol>> getClusters(ExpandedComponentInstanceSymbol componentInstanceSymbol) { public static List<Set<EMAComponentInstanceSymbol>> getClusters(EMAComponentInstanceSymbol componentInstanceSymbol) {
Graph<ExpandedComponentInstanceSymbol, DefaultEdge> graph = new SimpleGraph<>(DefaultEdge.class); Graph<EMAComponentInstanceSymbol, DefaultEdge> graph = new SimpleGraph<>(DefaultEdge.class);
componentInstanceSymbol.getSubComponents().forEach(graph::addVertex); componentInstanceSymbol.getSubComponents().forEach(graph::addVertex);
graph.addVertex(componentInstanceSymbol); graph.addVertex(componentInstanceSymbol);
componentInstanceSymbol.getConnectors().stream() componentInstanceSymbol.getConnectorInstances().stream()
.filter(c -> !(c.getSourcePort().getMiddlewareSymbol().isPresent() && c.getTargetPort().getMiddlewareSymbol().isPresent())) .filter(c -> !(c.getSourcePort().getMiddlewareSymbol().isPresent() && c.getTargetPort().getMiddlewareSymbol().isPresent()))
.forEach(c -> { .forEach(c -> {
ExpandedComponentInstanceSymbol compSource = c.getSourcePort().getComponentInstance().orElse(null); EMAComponentInstanceSymbol compSource = c.getSourcePort().getComponentInstance();
ExpandedComponentInstanceSymbol compTarget = c.getTargetPort().getComponentInstance().orElse(null); EMAComponentInstanceSymbol compTarget = c.getTargetPort().getComponentInstance();
if (compSource == null || compTarget == null) { if (compSource == null || compTarget == null) {
Log.error("ComponentInstance of source or target not found!"); Log.error("ComponentInstance of source or target not found!");
} }
...@@ -38,7 +45,7 @@ public class ClusterFromTagsHelper { ...@@ -38,7 +45,7 @@ public class ClusterFromTagsHelper {
} }
}); });
ConnectivityInspector<ExpandedComponentInstanceSymbol, DefaultEdge> connectivityInspector = new ConnectivityInspector<>(graph); ConnectivityInspector<EMAComponentInstanceSymbol, DefaultEdge> connectivityInspector = new ConnectivityInspector<>(graph);
int instanceSetSize = connectivityInspector.connectedSetOf(componentInstanceSymbol).size(); int instanceSetSize = connectivityInspector.connectedSetOf(componentInstanceSymbol).size();
if (instanceSetSize != 1) { if (instanceSetSize != 1) {
Log.warn("0x8EFC3: The supercomponent can only be connected to subcomponents via middleware ports!"); Log.warn("0x8EFC3: The supercomponent can only be connected to subcomponents via middleware ports!");
...@@ -48,13 +55,13 @@ public class ClusterFromTagsHelper { ...@@ -48,13 +55,13 @@ public class ClusterFromTagsHelper {
if (instanceSetSize != componentInstanceSymbol.getSubComponents().size() + 1) if (instanceSetSize != componentInstanceSymbol.getSubComponents().size() + 1)
graph.removeVertex(componentInstanceSymbol); graph.removeVertex(componentInstanceSymbol);