Commit ae35f974 authored by Alexander David Hellwig's avatar Alexander David Hellwig
Browse files

Tag files of all clusterings are now written if writeTagFile==true. Score,...

Tag files of all clusterings are now written if writeTagFile==true. Score, Number of Clusters, Algorithm name and Parameters are also added as comments
parent d542c62c
Pipeline #102188 failed with stages
in 16 minutes and 41 seconds
...@@ -20,6 +20,7 @@ import java.util.*; ...@@ -20,6 +20,7 @@ import java.util.*;
public class DistributedTargetGenerator extends CMakeGenerator { public class DistributedTargetGenerator extends CMakeGenerator {
private boolean generateMiddlewareTags = false; private boolean generateMiddlewareTags = false;
private ClusteringResultList clusteringResults = new ClusteringResultList();
public boolean isGenerateMiddlewareTags() { public boolean isGenerateMiddlewareTags() {
return generateMiddlewareTags; return generateMiddlewareTags;
...@@ -83,6 +84,7 @@ public class DistributedTargetGenerator extends CMakeGenerator { ...@@ -83,6 +84,7 @@ public class DistributedTargetGenerator extends CMakeGenerator {
if(generateMiddlewareTags){ if(generateMiddlewareTags){
MiddlewareTagGenImpl middlewareTagGen = new MiddlewareTagGenImpl(); MiddlewareTagGenImpl middlewareTagGen = new MiddlewareTagGenImpl();
middlewareTagGen.setGenerationTargetPath(generationTargetPath + "emam/"); middlewareTagGen.setGenerationTargetPath(generationTargetPath + "emam/");
middlewareTagGen.setClusteringResults(clusteringResults);
files.addAll(middlewareTagGen.generate(componentInstanceSymbol,taggingResolver)); files.addAll(middlewareTagGen.generate(componentInstanceSymbol,taggingResolver));
} }
...@@ -105,7 +107,7 @@ public class DistributedTargetGenerator extends CMakeGenerator { ...@@ -105,7 +107,7 @@ public class DistributedTargetGenerator extends CMakeGenerator {
//Cluster //Cluster
if(clusteringParameters.getAlgorithmParameters().size() > 0) { if(clusteringParameters.getAlgorithmParameters().size() > 0) {
ClusteringResultList clusteringResults = AutomaticClusteringHelper.executeClusteringFromParams(componentInstanceSymbol, clusteringParameters.getAlgorithmParameters()); clusteringResults = AutomaticClusteringHelper.executeClusteringFromParams(componentInstanceSymbol, clusteringParameters.getAlgorithmParameters());
Optional<Integer> nOpt = clusteringParameters.getNumberOfClusters(); Optional<Integer> nOpt = clusteringParameters.getNumberOfClusters();
for(ClusteringResult c : clusteringResults){ for(ClusteringResult c : clusteringResults){
String prefix = nOpt.isPresent() && !c.hasNumberOfClusters(nOpt.get()) ? "[IGNORED]" : ""; String prefix = nOpt.isPresent() && !c.hasNumberOfClusters(nOpt.get()) ? "[IGNORED]" : "";
......
...@@ -133,13 +133,23 @@ public class AutomaticClusteringHelper { ...@@ -133,13 +133,23 @@ public class AutomaticClusteringHelper {
} }
public static double getTypeCostHeuristic(EMAComponentInstanceSymbol componentInstanceSymbol, List<Set<EMAComponentInstanceSymbol>> clustering){ public static double getTypeCostHeuristic(EMAComponentInstanceSymbol componentInstanceSymbol, List<Set<EMAComponentInstanceSymbol>> clustering){
List<EMAConnectorInstanceSymbol> interClusterConnectors = getInterClusterConnectors(componentInstanceSymbol, clustering);
return interClusterConnectors.stream()
.map(EMAConnectorInstanceSymbol::getTargetPort)
.map(AutomaticClusteringHelper::getTypeCostHeuristic)
.mapToDouble(d -> d)
.sum();
}
public static List<EMAConnectorInstanceSymbol> getInterClusterConnectors(EMAComponentInstanceSymbol componentInstanceSymbol, List<Set<EMAComponentInstanceSymbol>> clustering) {
List<Set<String>> clusteringAsNames = clustering.stream() List<Set<String>> clusteringAsNames = clustering.stream()
.map(s -> s.stream() .map(s -> s.stream()
.map(CommonSymbol::getFullName) .map(CommonSymbol::getFullName)
.collect(Collectors.toSet())) .collect(Collectors.toSet()))
.collect(Collectors.toList()); .collect(Collectors.toList());
List<EMAConnectorInstanceSymbol> interClusterConnectors = componentInstanceSymbol.getConnectorInstances().stream() return componentInstanceSymbol.getConnectorInstances().stream()
.filter(con -> { .filter(con -> {
EMAComponentInstanceSymbol sourceComp = con.getSourcePort().getComponentInstance(); EMAComponentInstanceSymbol sourceComp = con.getSourcePort().getComponentInstance();
EMAComponentInstanceSymbol targetComp = con.getTargetPort().getComponentInstance(); EMAComponentInstanceSymbol targetComp = con.getTargetPort().getComponentInstance();
...@@ -159,12 +169,6 @@ public class AutomaticClusteringHelper { ...@@ -159,12 +169,6 @@ public class AutomaticClusteringHelper {
return sourceClusterIndex != targetClusterIndex; return sourceClusterIndex != targetClusterIndex;
}) })
.collect(Collectors.toList()); .collect(Collectors.toList());
return interClusterConnectors.stream()
.map(EMAConnectorInstanceSymbol::getTargetPort)
.map(AutomaticClusteringHelper::getTypeCostHeuristic)
.mapToDouble(d -> d)
.sum();
} }
public static double getTypeCostHeuristic(EMAPortSymbol port){ public static double getTypeCostHeuristic(EMAPortSymbol port){
......
package de.monticore.lang.monticar.generator.middleware.clustering; package de.monticore.lang.monticar.generator.middleware.clustering;
import de.monticore.lang.embeddedmontiarc.embeddedmontiarc._symboltable.instanceStructure.EMAComponentInstanceSymbol; import de.monticore.lang.embeddedmontiarc.embeddedmontiarc._symboltable.instanceStructure.EMAComponentInstanceSymbol;
import de.monticore.lang.monticar.generator.FileContent;
import de.monticore.lang.monticar.generator.middleware.cli.algorithms.AlgorithmCliParameters; import de.monticore.lang.monticar.generator.middleware.cli.algorithms.AlgorithmCliParameters;
import de.monticore.lang.monticar.generator.middleware.impls.MiddlewareTagGenImpl;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
...@@ -50,4 +52,16 @@ public class ClusteringResult { ...@@ -50,4 +52,16 @@ public class ClusteringResult {
public boolean hasNumberOfClusters(int n){ public boolean hasNumberOfClusters(int n){
return getNumberOfClusters() == n; return getNumberOfClusters() == n;
} }
}
public FileContent getTagFile(String fileName){
FileContent res = new FileContent();
res.setFileName(fileName);
String prefix = "//Algorithm: " + this.getParameters().toString() + "\n" +
"//Number of clusters: " + this.getNumberOfClusters() + "\n" +
"//Score: " + this.getScore() + "\n";
String content = MiddlewareTagGenImpl.getFileContent(component, this.clustering);
res.setFileContent(prefix + content);
return res;
}
}
\ No newline at end of file
package de.monticore.lang.monticar.generator.middleware.clustering; package de.monticore.lang.monticar.generator.middleware.clustering;
import de.monticore.lang.monticar.generator.FileContent;
import de.se_rwth.commons.logging.Log; import de.se_rwth.commons.logging.Log;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Comparator; import java.util.Comparator;
import java.util.List;
import java.util.Optional; import java.util.Optional;
public class ClusteringResultList extends ArrayList<ClusteringResult> { public class ClusteringResultList extends ArrayList<ClusteringResult> {
...@@ -29,4 +31,15 @@ public class ClusteringResultList extends ArrayList<ClusteringResult> { ...@@ -29,4 +31,15 @@ public class ClusteringResultList extends ArrayList<ClusteringResult> {
this.sort(Comparator.comparing(ClusteringResult::getScore)); this.sort(Comparator.comparing(ClusteringResult::getScore));
return this.size() == 0 ? Optional.empty() : Optional.of(this.get(0)); return this.size() == 0 ? Optional.empty() : Optional.of(this.get(0));
} }
public List<FileContent> getAllTagFiles(String baseName){
List<FileContent> res = new ArrayList<>();
int i = 1;
for (ClusteringResult r : this) {
FileContent tagFile = r.getTagFile(baseName + "_" + i + "_" + r.getParameters().getName() + ".tag");
res.add(tagFile);
i++;
}
return res;
}
} }
package de.monticore.lang.monticar.generator.middleware.impls; package de.monticore.lang.monticar.generator.middleware.impls;
import de.monticore.lang.embeddedmontiarc.embeddedmontiarc._symboltable.instanceStructure.EMAComponentInstanceSymbol; 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.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.embeddedmontiarc.tagging.middleware.ros.RosConnectionSymbol;
import de.monticore.lang.monticar.generator.FileContent; import de.monticore.lang.monticar.generator.FileContent;
import de.monticore.lang.monticar.generator.middleware.clustering.AutomaticClusteringHelper;
import de.monticore.lang.monticar.generator.middleware.clustering.ClusteringResultList;
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;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.util.AbstractCollection;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Optional; import java.util.Set;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import java.util.stream.Stream;
public class MiddlewareTagGenImpl implements GeneratorImpl { public class MiddlewareTagGenImpl implements GeneratorImpl {
private String generationTargetPath; private String generationTargetPath;
private ClusteringResultList clusteringResults;
public ClusteringResultList getClusteringResults() {
return clusteringResults;
}
public void setClusteringResults(ClusteringResultList clusteringResults) {
this.clusteringResults = clusteringResults;
}
@Override @Override
public List<File> generate(EMAComponentInstanceSymbol componentInstanceSymbol, TaggingResolver taggingResolver) throws IOException { public List<File> generate(EMAComponentInstanceSymbol componentInstanceSymbol, TaggingResolver taggingResolver) throws IOException {
List<File> res = new ArrayList<>(); List<File> res = new ArrayList<>();
List<EMAPortInstanceSymbol> middlewarePorts = getMiddlewarePorts(componentInstanceSymbol);
res.add(FileHelper.generateFile(generationTargetPath ,generateRosTags(componentInstanceSymbol.getPackageName(),middlewarePorts, false)));
for(FileContent fc : clusteringResults.getAllTagFiles("Clustering")){
res.add(FileHelper.generateFile(generationTargetPath , fc));
}
return res;
}
private static List<EMAPortInstanceSymbol> getMiddlewarePorts(EMAComponentInstanceSymbol componentInstanceSymbol) {
//Collect Ports with Middleware Symbols from Super Component and first level subcomponents //Collect Ports with Middleware Symbols from Super Component and first level subcomponents
List<EMAPortInstanceSymbol> middlewarePortsSuper = componentInstanceSymbol.getPortInstanceList().stream() List<EMAPortInstanceSymbol> middlewarePortsSuper = componentInstanceSymbol.getPortInstanceList().stream()
.filter(portSymbol -> portSymbol.getMiddlewareSymbol().isPresent()) .filter(portSymbol -> portSymbol.getMiddlewareSymbol().isPresent())
...@@ -38,19 +58,27 @@ public class MiddlewareTagGenImpl implements GeneratorImpl { ...@@ -38,19 +58,27 @@ public class MiddlewareTagGenImpl implements GeneratorImpl {
List<EMAPortInstanceSymbol> middlewarePorts = new ArrayList<>(); List<EMAPortInstanceSymbol> middlewarePorts = new ArrayList<>();
middlewarePorts.addAll(middlewarePortsSub); middlewarePorts.addAll(middlewarePortsSub);
middlewarePorts.addAll(middlewarePortsSuper); middlewarePorts.addAll(middlewarePortsSuper);
return middlewarePorts;
res.add(generateRosTags(componentInstanceSymbol.getPackageName(),middlewarePorts));
return res;
} }
private File generateRosTags(String packageName ,List<EMAPortInstanceSymbol> middlewarePorts) throws IOException { public static String getFileContent(EMAComponentInstanceSymbol componentInstanceSymbol, List<Set<EMAComponentInstanceSymbol>> clustering){
List<EMAPortInstanceSymbol> rosPorts = middlewarePorts.stream() List<EMAConnectorInstanceSymbol> affectedConnectors = AutomaticClusteringHelper.getInterClusterConnectors(componentInstanceSymbol, clustering);
.filter(EMAPortInstanceSymbol::isRosPort) List<EMAPortInstanceSymbol> affectedPorts = affectedConnectors.stream().flatMap(c -> Stream.of(c.getSourcePort(), c.getTargetPort())).collect(Collectors.toList());
.collect(Collectors.toList()); return generateRosTags(componentInstanceSymbol.getPackageName(), affectedPorts, true).getFileContent();
}
private static FileContent generateRosTags(String packageName , List<EMAPortInstanceSymbol> affectedPorts, boolean ignoreOldValues){
FileContent result = new FileContent(); FileContent result = new FileContent();
List<EMAPortInstanceSymbol> rosPorts;
if(!ignoreOldValues) {
rosPorts = affectedPorts.stream()
.filter(EMAPortInstanceSymbol::isRosPort)
.collect(Collectors.toList());
}else{
rosPorts = affectedPorts;
}
result.setFileName("RosConnections.tag"); result.setFileName("RosConnections.tag");
StringBuilder content = new StringBuilder(); StringBuilder content = new StringBuilder();
...@@ -63,15 +91,17 @@ public class MiddlewareTagGenImpl implements GeneratorImpl { ...@@ -63,15 +91,17 @@ public class MiddlewareTagGenImpl implements GeneratorImpl {
//Pro port: tag ${port.fullName} with RosConnection (; | topic=(${topicName},${topicType}) , (msgField=${msgField})?); //Pro port: tag ${port.fullName} with RosConnection (; | topic=(${topicName},${topicType}) , (msgField=${msgField})?);
rosPorts.forEach(p -> { rosPorts.forEach(p -> {
content.append("tag " + p.getFullName() + " with RosConnection"); content.append("tag " + p.getFullName() + " with RosConnection");
RosConnectionSymbol rosSymbol = (RosConnectionSymbol) p.getMiddlewareSymbol().get(); if(!ignoreOldValues) {
if(rosSymbol.getTopicName().isPresent() && rosSymbol.getTopicType().isPresent()){ RosConnectionSymbol rosSymbol = (RosConnectionSymbol) p.getMiddlewareSymbol().get();
content.append(" = {topic = ("+ rosSymbol.getTopicName().get() +", " +rosSymbol.getTopicType().get() + ")"); if (rosSymbol.getTopicName().isPresent() && rosSymbol.getTopicType().isPresent()) {
content.append(" = {topic = (" + rosSymbol.getTopicName().get() + ", " + rosSymbol.getTopicType().get() + ")");
if(rosSymbol.getMsgField().isPresent()){ if (rosSymbol.getMsgField().isPresent()) {
content.append(", msgField = " + rosSymbol.getMsgField().get()); content.append(", msgField = " + rosSymbol.getMsgField().get());
} }
content.append("}"); content.append("}");
}
} }
content.append(";\n"); content.append(";\n");
...@@ -79,7 +109,7 @@ public class MiddlewareTagGenImpl implements GeneratorImpl { ...@@ -79,7 +109,7 @@ public class MiddlewareTagGenImpl implements GeneratorImpl {
content.append("}"); content.append("}");
result.setFileContent(content.toString()); result.setFileContent(content.toString());
return FileHelper.generateFile(generationTargetPath ,result); return result;
} }
@Override @Override
......
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
"outputDir": "target/cliTest/flattenSpectralMulti/", "outputDir": "target/cliTest/flattenSpectralMulti/",
"rootModel": "de.rwth.pacman.heithoff2.controller", "rootModel": "de.rwth.pacman.heithoff2.controller",
"generators": ["cpp","roscpp"], "generators": ["cpp","roscpp"],
"writeTagFile":true,
"clusteringParameters":{ "clusteringParameters":{
"flatten":true, "flatten":true,
"algorithmParameters":[ "algorithmParameters":[
......
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