Changes for new EMA Version

parent f90a4558
Pipeline #98741 failed with stages
in 5 minutes and 27 seconds
......@@ -2,6 +2,9 @@ package de.monticore.lang.monticar.generator.middleware.clustering;
import de.monticore.expressionsbasis._ast.ASTExpression;
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.math._ast.ASTNumberExpression;
import de.monticore.lang.monticar.common2._ast.ASTCommonMatrixType;
......@@ -21,25 +24,21 @@ 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) {
// Nodes = subcomponents
// Verts = connectors between subcomponents
double[][] res = new double[subcomps.size()][subcomps.size()];
connectors.forEach(con -> {
Optional<ExpandedComponentInstanceSymbol> sourceCompOpt = con.getSourcePort().getComponentInstance();
Optional<ExpandedComponentInstanceSymbol> targetCompOpt = con.getTargetPort().getComponentInstance();
EMAComponentInstanceSymbol sourceCompOpt = con.getSourcePort().getComponentInstance();
EMAComponentInstanceSymbol targetCompOpt = con.getTargetPort().getComponentInstance();
if (sourceCompOpt.isPresent() && targetCompOpt.isPresent()) {
int index1 = subcompLabels.get(sourceCompOpt.get().getFullName());
int index2 = subcompLabels.get(targetCompOpt.get().getFullName());
int index1 = subcompLabels.get(sourceCompOpt.getFullName());
int index2 = subcompLabels.get(targetCompOpt.getFullName());
res[index1][index2] = getTypeCostHeuristic(con.getSourcePort());
res[index2][index1] = getTypeCostHeuristic(con.getSourcePort());
} else {
Log.error("0xADE65: Component of source or target not found!");
}
});
......@@ -105,16 +104,16 @@ public class AutomaticClusteringHelper {
return normalizeMatrix(inverseProbabilitiesMatrix(adjacencyMatrix));
}
public static void annotateComponentWithRosTagsForClusters(ExpandedComponentInstanceSymbol componentInstanceSymbol, List<Set<ExpandedComponentInstanceSymbol>> clusters) {
Collection<ConnectorSymbol> connectors = componentInstanceSymbol.getConnectors();
public static void annotateComponentWithRosTagsForClusters(EMAComponentInstanceSymbol componentInstanceSymbol, List<Set<EMAComponentInstanceSymbol>> clusters) {
Collection<EMAConnectorInstanceSymbol> connectors = componentInstanceSymbol.getConnectorInstances();
connectors.forEach(con -> {
// -1 = super comp
int sourceClusterLabel = -1;
int targetClusterLabel = -1;
ExpandedComponentInstanceSymbol sourceComp = con.getSourcePort().getComponentInstance().get();
ExpandedComponentInstanceSymbol targetComp = con.getTargetPort().getComponentInstance().get();
EMAComponentInstanceSymbol sourceComp = con.getSourcePort().getComponentInstance();
EMAComponentInstanceSymbol targetComp = con.getTargetPort().getComponentInstance();
for(int i = 0; i < clusters.size(); i++){
if(clusters.get(i).contains(sourceComp)){
......@@ -135,7 +134,7 @@ public class AutomaticClusteringHelper {
}
public static double getTypeCostHeuristic(PortSymbol port){
public static double getTypeCostHeuristic(EMAPortSymbol port){
return getTypeCostHeuristic(port.getTypeReference());
}
......
package de.monticore.lang.monticar.generator.middleware.clustering;
import de.monticore.lang.embeddedmontiarc.embeddedmontiarc._symboltable.ExpandedComponentInstanceSymbol;
import de.monticore.lang.embeddedmontiarc.embeddedmontiarc._symboltable.instanceStructure.EMAComponentInstanceSymbol;
import java.util.List;
import java.util.Set;
// product if for clustering factory
public interface ClusteringAlgorithm {
public List<Set<ExpandedComponentInstanceSymbol>> cluster(ExpandedComponentInstanceSymbol component, Object... args);
public List<Set<EMAComponentInstanceSymbol>> cluster(EMAComponentInstanceSymbol component, Object... args);
}
......@@ -2,7 +2,7 @@ package de.monticore.lang.monticar.generator.middleware.clustering.algorithms;
import com.clust4j.algo.AffinityPropagation;
import com.clust4j.algo.AffinityPropagationParameters;
import de.monticore.lang.embeddedmontiarc.embeddedmontiarc._symboltable.ExpandedComponentInstanceSymbol;
import de.monticore.lang.embeddedmontiarc.embeddedmontiarc._symboltable.instanceStructure.EMAComponentInstanceSymbol;
import de.monticore.lang.monticar.generator.middleware.clustering.AutomaticClusteringHelper;
import de.monticore.lang.monticar.generator.middleware.clustering.ClusteringAlgorithm;
import de.monticore.lang.monticar.generator.middleware.helpers.ComponentHelper;
......@@ -14,9 +14,9 @@ import java.util.*;
public class AffinityPropagationAlgorithm implements ClusteringAlgorithm {
@Override
public List<Set<ExpandedComponentInstanceSymbol>> cluster(ExpandedComponentInstanceSymbol component, Object... args) {
public List<Set<EMAComponentInstanceSymbol>> cluster(EMAComponentInstanceSymbol component, Object... args) {
List<ExpandedComponentInstanceSymbol> subcompsOrderedByName = ComponentHelper.getSubcompsOrderedByName(component);
List<EMAComponentInstanceSymbol> subcompsOrderedByName = ComponentHelper.getSubcompsOrderedByName(component);
Map<String, Integer> labelsForSubcomps = ComponentHelper.getLabelsForSubcomps(subcompsOrderedByName);
double[][] adjMatrix = AutomaticClusteringHelper.createAdjacencyMatrix(subcompsOrderedByName,
ComponentHelper.getInnerConnectors(component),
......@@ -28,7 +28,7 @@ public class AffinityPropagationAlgorithm implements ClusteringAlgorithm {
final int[] labels = clustering.getLabels();
List<Set<ExpandedComponentInstanceSymbol>> res = new ArrayList<>();
List<Set<EMAComponentInstanceSymbol>> res = new ArrayList<>();
for(int i = 0; i < labels.length; i++){
res.add(new HashSet<>());
......
package de.monticore.lang.monticar.generator.middleware.clustering.algorithms;
import de.monticore.lang.embeddedmontiarc.embeddedmontiarc._symboltable.ExpandedComponentInstanceSymbol;
import de.monticore.lang.embeddedmontiarc.embeddedmontiarc._symboltable.instanceStructure.EMAComponentInstanceSymbol;
import de.monticore.lang.monticar.generator.middleware.clustering.AutomaticClusteringHelper;
import de.monticore.lang.monticar.generator.middleware.clustering.ClusteringAlgorithm;
import de.monticore.lang.monticar.generator.middleware.helpers.ComponentHelper;
......@@ -12,9 +12,9 @@ import java.util.*;
// DBSCAN clusterer product implementation
public class DBSCANClusteringAlgorithm implements ClusteringAlgorithm {
@Override
public List<Set<ExpandedComponentInstanceSymbol>> cluster(ExpandedComponentInstanceSymbol component, Object... args) {
public List<Set<EMAComponentInstanceSymbol>> cluster(EMAComponentInstanceSymbol component, Object... args) {
List<Set<ExpandedComponentInstanceSymbol>> res = new ArrayList<>();
List<Set<EMAComponentInstanceSymbol>> res = new ArrayList<>();
// params
Integer minPts= null;
......@@ -69,7 +69,7 @@ public class DBSCANClusteringAlgorithm implements ClusteringAlgorithm {
if (error) {
Log.error("DBSCANClusteringAlgorithm: Mandatory parameter(s) missing!");
} else {
List<ExpandedComponentInstanceSymbol> subcompsOrderedByName = ComponentHelper.getSubcompsOrderedByName(component);
List<EMAComponentInstanceSymbol> subcompsOrderedByName = ComponentHelper.getSubcompsOrderedByName(component);
Map<String, Integer> labelsForSubcomps = ComponentHelper.getLabelsForSubcomps(subcompsOrderedByName);
double[][] adjMatrix = AutomaticClusteringHelper.createAdjacencyMatrix(subcompsOrderedByName,
ComponentHelper.getInnerConnectors(component),
......
package de.monticore.lang.monticar.generator.middleware.clustering.algorithms;
import de.monticore.lang.embeddedmontiarc.embeddedmontiarc._symboltable.ExpandedComponentInstanceSymbol;
import de.monticore.lang.embeddedmontiarc.embeddedmontiarc._symboltable.instanceStructure.EMAComponentInstanceSymbol;
import de.monticore.lang.monticar.generator.middleware.clustering.AutomaticClusteringHelper;
import de.monticore.lang.monticar.generator.middleware.clustering.ClusteringAlgorithm;
import de.monticore.lang.monticar.generator.middleware.helpers.ComponentHelper;
......@@ -67,9 +67,9 @@ public class MarkovClusteringAlgorithm implements ClusteringAlgorithm {
}
@Override
public List<Set<ExpandedComponentInstanceSymbol>> cluster(ExpandedComponentInstanceSymbol component, Object... args) {
public List<Set<EMAComponentInstanceSymbol>> cluster(EMAComponentInstanceSymbol component, Object... args) {
List<Set<ExpandedComponentInstanceSymbol>> res = new ArrayList<>();
List<Set<EMAComponentInstanceSymbol>> res = new ArrayList<>();
// params
Double maxResidual= null;
......@@ -136,7 +136,7 @@ public class MarkovClusteringAlgorithm implements ClusteringAlgorithm {
if (error) {
Log.error("MarkovClusteringAlgorithm: Mandatory parameter(s) missing!");
} else {
List<ExpandedComponentInstanceSymbol> subcompsOrderedByName = ComponentHelper.getSubcompsOrderedByName(component);
List<EMAComponentInstanceSymbol> subcompsOrderedByName = ComponentHelper.getSubcompsOrderedByName(component);
Map<String, Integer> labelsForSubcomps = ComponentHelper.getLabelsForSubcomps(subcompsOrderedByName);
double[][] adjMatrix = AutomaticClusteringHelper.createAdjacencyMatrix(subcompsOrderedByName,
ComponentHelper.getInnerConnectors(component),
......
package de.monticore.lang.monticar.generator.middleware.clustering.algorithms;
import de.monticore.lang.embeddedmontiarc.embeddedmontiarc._symboltable.ExpandedComponentInstanceSymbol;
import de.monticore.lang.embeddedmontiarc.embeddedmontiarc._symboltable.instanceStructure.EMAComponentInstanceSymbol;
import de.monticore.lang.monticar.generator.middleware.clustering.AutomaticClusteringHelper;
import de.monticore.lang.monticar.generator.middleware.clustering.ClusteringAlgorithm;
import de.monticore.lang.monticar.generator.middleware.helpers.ComponentHelper;
......@@ -12,9 +12,9 @@ import java.util.*;
// spectral clusterer product implementation
public class SpectralClusteringAlgorithm implements ClusteringAlgorithm {
@Override
public List<Set<ExpandedComponentInstanceSymbol>> cluster(ExpandedComponentInstanceSymbol component, Object... args) {
public List<Set<EMAComponentInstanceSymbol>> cluster(EMAComponentInstanceSymbol component, Object... args) {
List<Set<ExpandedComponentInstanceSymbol>> res = new ArrayList<>();
List<Set<EMAComponentInstanceSymbol>> res = new ArrayList<>();
// params
Integer numClusters= null;
......@@ -75,7 +75,7 @@ public class SpectralClusteringAlgorithm implements ClusteringAlgorithm {
if (error) {
Log.error("SpectralClusteringAlgorithm: Mandatory parameter(s) missing!");
} else {
List<ExpandedComponentInstanceSymbol> subcompsOrderedByName = ComponentHelper.getSubcompsOrderedByName(component);
List<EMAComponentInstanceSymbol> subcompsOrderedByName = ComponentHelper.getSubcompsOrderedByName(component);
Map<String, Integer> labelsForSubcomps = ComponentHelper.getLabelsForSubcomps(subcompsOrderedByName);
double[][] adjMatrix = AutomaticClusteringHelper.createAdjacencyMatrix(subcompsOrderedByName,
ComponentHelper.getInnerConnectors(component),
......
package de.monticore.lang.monticar.generator.middleware.helpers;
import de.monticore.lang.embeddedmontiarc.embeddedmontiarc._symboltable.ConnectorSymbol;
import de.monticore.lang.embeddedmontiarc.embeddedmontiarc._symboltable.ExpandedComponentInstanceSymbol;
import de.monticore.lang.embeddedmontiarc.embeddedmontiarc._symboltable.instanceStructure.EMAComponentInstanceSymbol;
import de.monticore.lang.embeddedmontiarc.embeddedmontiarc._symboltable.instanceStructure.EMAConnectorInstanceSymbol;
import java.util.*;
import java.util.stream.Collectors;
public class ComponentHelper {
public static List<ExpandedComponentInstanceSymbol> getSubcompsOrderedByName(ExpandedComponentInstanceSymbol componentInstanceSymbol){
public static List<EMAComponentInstanceSymbol> getSubcompsOrderedByName(EMAComponentInstanceSymbol componentInstanceSymbol){
return componentInstanceSymbol.getSubComponents().stream()
.sorted(Comparator.comparing(ExpandedComponentInstanceSymbol::getFullName))
.sorted(Comparator.comparing(EMAComponentInstanceSymbol::getFullName))
.collect(Collectors.toList());
}
public static Collection<ConnectorSymbol> getInnerConnectors(ExpandedComponentInstanceSymbol componentInstanceSymbol){
public static Collection<EMAConnectorInstanceSymbol> getInnerConnectors(EMAComponentInstanceSymbol componentInstanceSymbol){
String superCompName = componentInstanceSymbol.getFullName();
return componentInstanceSymbol.getConnectors().stream()
return componentInstanceSymbol.getConnectorInstances().stream()
//filter out all connectors to super component
.filter(con -> !con.getSourcePort().getComponentInstance().get().getFullName().equals(superCompName)
&& !con.getTargetPort().getComponentInstance().get().getFullName().equals(superCompName))
.filter(con -> !con.getSourcePort().getComponentInstance().getFullName().equals(superCompName)
&& !con.getTargetPort().getComponentInstance().getFullName().equals(superCompName))
.collect(Collectors.toList());
}
public static Map<String, Integer> getLabelsForSubcomps(List<ExpandedComponentInstanceSymbol> subcomps) {
public static Map<String, Integer> getLabelsForSubcomps(List<EMAComponentInstanceSymbol> subcomps) {
Map<String, Integer> componentIndecies = new HashMap<>();
int[] i = {0};
......
package de.monticore.lang.monticar.generator.middleware.impls;
import de.monticore.lang.embeddedmontiarc.embeddedmontiarc._symboltable.ExpandedComponentInstanceSymbol;
import de.monticore.lang.embeddedmontiarc.embeddedmontiarc._symboltable.PortSymbol;
import de.monticore.lang.embeddedmontiarc.embeddedmontiarc._symboltable.instanceStructure.EMAComponentInstanceSymbol;
import de.monticore.lang.embeddedmontiarc.embeddedmontiarc._symboltable.instanceStructure.EMAPortInstanceSymbol;
import de.monticore.lang.embeddedmontiarc.tagging.middleware.MiddlewareSymbol;
import de.monticore.lang.embeddedmontiarc.tagging.middleware.ros.RosConnectionSymbol;
import de.monticore.lang.monticar.generator.FileContent;
......@@ -21,21 +21,21 @@ public class MiddlewareTagGenImpl implements GeneratorImpl {
private String generationTargetPath;
@Override
public List<File> generate(ExpandedComponentInstanceSymbol componentInstanceSymbol, TaggingResolver taggingResolver) throws IOException {
public List<File> generate(EMAComponentInstanceSymbol componentInstanceSymbol, TaggingResolver taggingResolver) throws IOException {
List<File> res = new ArrayList<>();
//Collect Ports with Middleware Symbols from Super Component and first level subcomponents
List<PortSymbol> middlewarePortsSuper = componentInstanceSymbol.getPortsList().stream()
List<EMAPortInstanceSymbol> middlewarePortsSuper = componentInstanceSymbol.getPortInstanceList().stream()
.filter(portSymbol -> portSymbol.getMiddlewareSymbol().isPresent())
.collect(Collectors.toList());
List<PortSymbol> middlewarePortsSub = componentInstanceSymbol.getSubComponents()
List<EMAPortInstanceSymbol> middlewarePortsSub = componentInstanceSymbol.getSubComponents()
.stream()
.flatMap(ecis -> ecis.getPortsList().stream())
.flatMap(ecis -> ecis.getPortInstanceList().stream())
.filter(portSymbol -> portSymbol.getMiddlewareSymbol().isPresent())
.collect(Collectors.toList());
List<PortSymbol> middlewarePorts = new ArrayList<>();
List<EMAPortInstanceSymbol> middlewarePorts = new ArrayList<>();
middlewarePorts.addAll(middlewarePortsSub);
middlewarePorts.addAll(middlewarePortsSuper);
......@@ -44,9 +44,9 @@ public class MiddlewareTagGenImpl implements GeneratorImpl {
return res;
}
private File generateRosTags(String packageName ,List<PortSymbol> middlewarePorts) throws IOException {
List<PortSymbol> rosPorts = middlewarePorts.stream()
.filter(PortSymbol::isRosPort)
private File generateRosTags(String packageName ,List<EMAPortInstanceSymbol> middlewarePorts) throws IOException {
List<EMAPortInstanceSymbol> rosPorts = middlewarePorts.stream()
.filter(EMAPortInstanceSymbol::isRosPort)
.collect(Collectors.toList());
FileContent result = new FileContent();
......@@ -88,7 +88,7 @@ public class MiddlewareTagGenImpl implements GeneratorImpl {
}
@Override
public boolean willAccept(ExpandedComponentInstanceSymbol componentInstanceSymbol) {
public boolean willAccept(EMAComponentInstanceSymbol componentInstanceSymbol) {
//TODO: fill?
return true;
}
......
......@@ -2,6 +2,7 @@ package de.monticore.lang.monticar.generator.middleware;
import de.monticore.lang.embeddedmontiarc.embeddedmontiarc._ast.ASTComponent;
import de.monticore.lang.embeddedmontiarc.embeddedmontiarc._symboltable.cncModel.EMAComponentSymbol;
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.EMAPortInstanceSymbol;
import de.monticore.lang.embeddedmontiarc.embeddedmontiarcmath.cocos.EmbeddedMontiArcMathCoCos;
......@@ -343,10 +344,10 @@ public class GenerationTest extends AbstractSymtabTest {
TaggingResolver taggingResolver = createSymTabAndTaggingResolver(TEST_PATH);
RosToEmamTagSchema.registerTagTypes(taggingResolver);
ExpandedComponentInstanceSymbol componentInstanceSymbol = taggingResolver.<ExpandedComponentInstanceSymbol>resolve("lab.system", ExpandedComponentInstanceSymbol.KIND).orElse(null);
EMAComponentInstanceSymbol componentInstanceSymbol = taggingResolver.<EMAComponentInstanceSymbol>resolve("lab.system", EMAComponentInstanceSymbol.KIND).orElse(null);
assertNotNull(componentInstanceSymbol);
//make sure the middleware tags are loaded
Map<PortSymbol, RosConnectionSymbol> tags = TagHelper.resolveTags(taggingResolver, componentInstanceSymbol);
Map<EMAPortSymbol, RosConnectionSymbol> tags = TagHelper.resolveTags(taggingResolver, componentInstanceSymbol);
DistributedTargetGenerator middlewareGenerator = new DistributedTargetGenerator();
......@@ -366,10 +367,10 @@ public class GenerationTest extends AbstractSymtabTest {
TaggingResolver taggingResolver = createSymTabAndTaggingResolver(TEST_PATH);
RosToEmamTagSchema.registerTagTypes(taggingResolver);
ExpandedComponentInstanceSymbol componentInstanceSymbol = taggingResolver.<ExpandedComponentInstanceSymbol>resolve("lab.system", ExpandedComponentInstanceSymbol.KIND).orElse(null);
EMAComponentInstanceSymbol componentInstanceSymbol = taggingResolver.<EMAComponentInstanceSymbol>resolve("lab.system", EMAComponentInstanceSymbol.KIND).orElse(null);
assertNotNull(componentInstanceSymbol);
//make sure the middleware tags are loaded
Map<PortSymbol, RosConnectionSymbol> tags = TagHelper.resolveTags(taggingResolver, componentInstanceSymbol);
Map<EMAPortSymbol, RosConnectionSymbol> tags = TagHelper.resolveTags(taggingResolver, componentInstanceSymbol);
DistributedTargetGenerator middlewareGenerator = new DistributedTargetGenerator();
middlewareGenerator.setGenerationTargetPath("./target/generated-sources-cmake/labWithTags/src/");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment