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.*;
public class DistributedTargetGenerator extends CMakeGenerator {
private boolean generateMiddlewareTags = false;
private ClusteringResultList clusteringResults = new ClusteringResultList();
public boolean isGenerateMiddlewareTags() {
return generateMiddlewareTags;
......@@ -83,6 +84,7 @@ public class DistributedTargetGenerator extends CMakeGenerator {
if(generateMiddlewareTags){
MiddlewareTagGenImpl middlewareTagGen = new MiddlewareTagGenImpl();
middlewareTagGen.setGenerationTargetPath(generationTargetPath + "emam/");
middlewareTagGen.setClusteringResults(clusteringResults);
files.addAll(middlewareTagGen.generate(componentInstanceSymbol,taggingResolver));
}
......@@ -105,7 +107,7 @@ public class DistributedTargetGenerator extends CMakeGenerator {
//Cluster
if(clusteringParameters.getAlgorithmParameters().size() > 0) {
ClusteringResultList clusteringResults = AutomaticClusteringHelper.executeClusteringFromParams(componentInstanceSymbol, clusteringParameters.getAlgorithmParameters());
clusteringResults = AutomaticClusteringHelper.executeClusteringFromParams(componentInstanceSymbol, clusteringParameters.getAlgorithmParameters());
Optional<Integer> nOpt = clusteringParameters.getNumberOfClusters();
for(ClusteringResult c : clusteringResults){
String prefix = nOpt.isPresent() && !c.hasNumberOfClusters(nOpt.get()) ? "[IGNORED]" : "";
......
......@@ -133,13 +133,23 @@ public class AutomaticClusteringHelper {
}
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()
.map(s -> s.stream()
.map(CommonSymbol::getFullName)
.collect(Collectors.toSet()))
.collect(Collectors.toList());
List<EMAConnectorInstanceSymbol> interClusterConnectors = componentInstanceSymbol.getConnectorInstances().stream()
return componentInstanceSymbol.getConnectorInstances().stream()
.filter(con -> {
EMAComponentInstanceSymbol sourceComp = con.getSourcePort().getComponentInstance();
EMAComponentInstanceSymbol targetComp = con.getTargetPort().getComponentInstance();
......@@ -159,12 +169,6 @@ public class AutomaticClusteringHelper {
return sourceClusterIndex != targetClusterIndex;
})
.collect(Collectors.toList());
return interClusterConnectors.stream()
.map(EMAConnectorInstanceSymbol::getTargetPort)
.map(AutomaticClusteringHelper::getTypeCostHeuristic)
.mapToDouble(d -> d)
.sum();
}
public static double getTypeCostHeuristic(EMAPortSymbol port){
......
package de.monticore.lang.monticar.generator.middleware.clustering;
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.impls.MiddlewareTagGenImpl;
import java.util.List;
import java.util.Set;
......@@ -50,4 +52,16 @@ public class ClusteringResult {
public boolean hasNumberOfClusters(int 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;
import de.monticore.lang.monticar.generator.FileContent;
import de.se_rwth.commons.logging.Log;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.Optional;
public class ClusteringResultList extends ArrayList<ClusteringResult> {
......@@ -29,4 +31,15 @@ public class ClusteringResultList extends ArrayList<ClusteringResult> {
this.sort(Comparator.comparing(ClusteringResult::getScore));
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;
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.tagging.middleware.MiddlewareSymbol;
import de.monticore.lang.embeddedmontiarc.tagging.middleware.ros.RosConnectionSymbol;
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.tagging._symboltable.TaggingResolver;
import java.io.File;
import java.io.IOException;
import java.util.AbstractCollection;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.Stream;
public class MiddlewareTagGenImpl implements GeneratorImpl {
private String generationTargetPath;
private ClusteringResultList clusteringResults;
public ClusteringResultList getClusteringResults() {
return clusteringResults;
}
public void setClusteringResults(ClusteringResultList clusteringResults) {
this.clusteringResults = clusteringResults;
}
@Override
public List<File> generate(EMAComponentInstanceSymbol componentInstanceSymbol, TaggingResolver taggingResolver) throws IOException {
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
List<EMAPortInstanceSymbol> middlewarePortsSuper = componentInstanceSymbol.getPortInstanceList().stream()
.filter(portSymbol -> portSymbol.getMiddlewareSymbol().isPresent())
......@@ -38,19 +58,27 @@ public class MiddlewareTagGenImpl implements GeneratorImpl {
List<EMAPortInstanceSymbol> middlewarePorts = new ArrayList<>();
middlewarePorts.addAll(middlewarePortsSub);
middlewarePorts.addAll(middlewarePortsSuper);
res.add(generateRosTags(componentInstanceSymbol.getPackageName(),middlewarePorts));
return res;
return middlewarePorts;
}
private File generateRosTags(String packageName ,List<EMAPortInstanceSymbol> middlewarePorts) throws IOException {
List<EMAPortInstanceSymbol> rosPorts = middlewarePorts.stream()
.filter(EMAPortInstanceSymbol::isRosPort)
.collect(Collectors.toList());
public static String getFileContent(EMAComponentInstanceSymbol componentInstanceSymbol, List<Set<EMAComponentInstanceSymbol>> clustering){
List<EMAConnectorInstanceSymbol> affectedConnectors = AutomaticClusteringHelper.getInterClusterConnectors(componentInstanceSymbol, clustering);
List<EMAPortInstanceSymbol> affectedPorts = affectedConnectors.stream().flatMap(c -> Stream.of(c.getSourcePort(), c.getTargetPort())).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();
List<EMAPortInstanceSymbol> rosPorts;
if(!ignoreOldValues) {
rosPorts = affectedPorts.stream()
.filter(EMAPortInstanceSymbol::isRosPort)
.collect(Collectors.toList());
}else{
rosPorts = affectedPorts;
}
result.setFileName("RosConnections.tag");
StringBuilder content = new StringBuilder();
......@@ -63,15 +91,17 @@ public class MiddlewareTagGenImpl implements GeneratorImpl {
//Pro port: tag ${port.fullName} with RosConnection (; | topic=(${topicName},${topicType}) , (msgField=${msgField})?);
rosPorts.forEach(p -> {
content.append("tag " + p.getFullName() + " with RosConnection");
RosConnectionSymbol rosSymbol = (RosConnectionSymbol) p.getMiddlewareSymbol().get();
if(rosSymbol.getTopicName().isPresent() && rosSymbol.getTopicType().isPresent()){
content.append(" = {topic = ("+ rosSymbol.getTopicName().get() +", " +rosSymbol.getTopicType().get() + ")");
if(!ignoreOldValues) {
RosConnectionSymbol rosSymbol = (RosConnectionSymbol) p.getMiddlewareSymbol().get();
if (rosSymbol.getTopicName().isPresent() && rosSymbol.getTopicType().isPresent()) {
content.append(" = {topic = (" + rosSymbol.getTopicName().get() + ", " + rosSymbol.getTopicType().get() + ")");
if(rosSymbol.getMsgField().isPresent()){
content.append(", msgField = " + rosSymbol.getMsgField().get());
}
if (rosSymbol.getMsgField().isPresent()) {
content.append(", msgField = " + rosSymbol.getMsgField().get());
}
content.append("}");
content.append("}");
}
}
content.append(";\n");
......@@ -79,7 +109,7 @@ public class MiddlewareTagGenImpl implements GeneratorImpl {
content.append("}");
result.setFileContent(content.toString());
return FileHelper.generateFile(generationTargetPath ,result);
return result;
}
@Override
......
......@@ -3,6 +3,7 @@
"outputDir": "target/cliTest/flattenSpectralMulti/",
"rootModel": "de.rwth.pacman.heithoff2.controller",
"generators": ["cpp","roscpp"],
"writeTagFile":true,
"clusteringParameters":{
"flatten":true,
"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