use of ch.hsr.servicecutter.solver.SolverConfiguration in project context-mapper-dsl by ContextMapper.
the class NewServiceCutContextMapGenerator method generateFromContextMappingModel.
@Override
protected void generateFromContextMappingModel(ContextMappingModel model, IFileSystemAccess2 fsa, URI inputFileURI) {
checkPreconditions(model);
String fileBaseName = inputFileURI.trimFileExtension().lastSegment();
// prepare service cutter input
EntityRelationDiagram erdInput = new ContextMappingModelToServiceCutterERDConverter().convert(fileBaseName, model);
ServiceCutterContextBuilder contextBuilder = new ServiceCutterContextBuilder(erdInput);
SolverConfiguration solverConfig = getSolverConfiguration();
contextBuilder.withCustomSolverConfiguration(solverConfig);
contextBuilder.withUserRepresentations(getUserRepresentations(inputFileURI));
ServiceCutterContext context = contextBuilder.build();
// calculate new service cut
SolverResult result = new ServiceCutter(context).generateDecomposition();
ContextMappingModel newServiceCutModel = new ServiceCutterOutputToContextMappingModelConverter(contextMappingModel, context, getSCLModel(inputFileURI).eResource().getURI()).convert(result);
// save new CML file
int counter = 1;
String baseFileName = inputFileURI.trimFileExtension().lastSegment() + "_" + solverConfig.getAlgorithm().toString().replace(" ", "_") + "_Cut_";
URI fileName = inputFileURI.trimFileExtension().trimSegments(1).appendSegment(baseFileName + counter).appendFileExtension("cml");
while (resourceSet.getURIConverter().exists(fileName, null)) {
counter++;
fileName = inputFileURI.trimFileExtension().trimSegments(1).appendSegment(baseFileName + counter).appendFileExtension("cml");
}
Resource resource = resourceSet.createResource(fileName);
resource.getContents().add(newServiceCutModel);
try {
resource.save(null);
} catch (IOException e) {
throw new RuntimeException("Saving CML model was not possible.", e);
}
// save scoring as graphviz DOT file
fsa.generateFile(fileName.trimFileExtension().lastSegment() + ".gv", generateGraphvizScoringRepresentation(context));
}
use of ch.hsr.servicecutter.solver.SolverConfiguration in project context-mapper-dsl by ContextMapper.
the class ServiceCutterConfigHandler method createInitialServiceCutterConfig.
private ServiceCutterConfig createInitialServiceCutterConfig() {
ServiceCutterConfig config = new ServiceCutterConfig();
SolverConfiguration defaultSolverConfig = new SolverConfigurationFactory().createDefaultConfiguration();
config.setAlgorithm(defaultSolverConfig.getAlgorithm());
config.setAlgorithmParams(defaultSolverConfig.getAlgorithmParams());
config.setPriorities(defaultSolverConfig.getPriorities());
return config;
}
use of ch.hsr.servicecutter.solver.SolverConfiguration in project context-mapper-dsl by ContextMapper.
the class ServiceCutterOutputToContextMappingModelConverter method generateTopComment.
private String generateTopComment() {
StringBuilder sb = new StringBuilder();
sb.append("/* This CML model has been generated with Service Cutter. Timestamp: " + new SimpleDateFormat("dd.MM.YYYY HH:mm:ss z").format(new Date()));
if (this.originalModelState != null)
sb.append(System.lineSeparator() + " * It decomposes the original CML model " + originalModelState.eResource().getURI().toString() + ".");
if (this.sclURI != null)
sb.append(System.lineSeparator() + " * The following user representations file was used for the decomposition: " + sclURI.toString() + ".");
if (this.serviceCutterContext != null) {
SolverConfiguration config = serviceCutterContext.getSolverConfiguration();
sb.append(System.lineSeparator() + " * ");
sb.append(System.lineSeparator() + " * The service cut was generated with the following input parameters (.servicecutter.yml):");
sb.append(System.lineSeparator() + " * Algorithm: " + config.getAlgorithm().name());
for (Map.Entry<String, Double> entry : getAlgorithmParameters4Algo(config.getAlgorithmParams(), config.getAlgorithm()).entrySet()) sb.append(System.lineSeparator() + " * " + entry.getKey() + ": " + entry.getValue().toString());
for (Map.Entry<String, SolverPriority> entry : config.getPriorities().entrySet()) sb.append(System.lineSeparator() + " * " + entry.getKey() + ": " + entry.getValue().name());
}
sb.append(System.lineSeparator() + " */");
return sb.toString();
}
use of ch.hsr.servicecutter.solver.SolverConfiguration in project context-mapper-dsl by ContextMapper.
the class ServiceCutterConfigHandlerTest method canGetDefaultSolverConfiguration.
@Test
public void canGetDefaultSolverConfiguration() {
// given
ServiceCutterConfigHandler handler = new ServiceCutterConfigHandler(testDir);
// when
SolverConfiguration config = handler.getServiceCutterSolverConfiguration();
// then
assertEquals(SolverAlgorithm.MARKOV_CLUSTERING, config.getAlgorithm());
}
use of ch.hsr.servicecutter.solver.SolverConfiguration in project context-mapper-dsl by ContextMapper.
the class ServiceCutterConfigHandler method getServiceCutterSolverConfiguration.
public SolverConfiguration getServiceCutterSolverConfiguration() {
ServiceCutterConfig config = createAndGetServiceCutterConfig();
SolverConfiguration solverConfig = new SolverConfiguration();
solverConfig.setAlgorithm(config.getAlgorithm());
solverConfig.getAlgorithmParams().putAll(config.getAlgorithmParams());
solverConfig.getPriorities().putAll(config.getPriorities());
return solverConfig;
}
Aggregations