Search in sources :

Example 1 with SolverConfiguration

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));
}
Also used : ServiceCutterContext(ch.hsr.servicecutter.api.ServiceCutterContext) ContextMappingModelToServiceCutterERDConverter(org.contextmapper.dsl.generator.servicecutter.input.converter.ContextMappingModelToServiceCutterERDConverter) SolverResult(ch.hsr.servicecutter.api.model.SolverResult) Resource(org.eclipse.emf.ecore.resource.Resource) IOException(java.io.IOException) URI(org.eclipse.emf.common.util.URI) ServiceCutter(ch.hsr.servicecutter.api.ServiceCutter) SolverConfiguration(ch.hsr.servicecutter.solver.SolverConfiguration) ContextMappingModel(org.contextmapper.dsl.contextMappingDSL.ContextMappingModel) EntityRelationDiagram(ch.hsr.servicecutter.api.model.EntityRelationDiagram) ServiceCutterOutputToContextMappingModelConverter(org.contextmapper.dsl.generator.servicecutter.output.converter.ServiceCutterOutputToContextMappingModelConverter) ServiceCutterContextBuilder(ch.hsr.servicecutter.api.ServiceCutterContextBuilder)

Example 2 with SolverConfiguration

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;
}
Also used : SolverConfiguration(ch.hsr.servicecutter.solver.SolverConfiguration) SolverConfigurationFactory(ch.hsr.servicecutter.api.SolverConfigurationFactory)

Example 3 with SolverConfiguration

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();
}
Also used : SimpleDateFormat(java.text.SimpleDateFormat) HashMap(java.util.HashMap) Map(java.util.Map) ContextMap(org.contextmapper.dsl.contextMappingDSL.ContextMap) SolverPriority(ch.hsr.servicecutter.solver.SolverPriority) Date(java.util.Date) SolverConfiguration(ch.hsr.servicecutter.solver.SolverConfiguration)

Example 4 with SolverConfiguration

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());
}
Also used : SolverConfiguration(ch.hsr.servicecutter.solver.SolverConfiguration) Test(org.junit.jupiter.api.Test) AbstractDirectoryIntegrationTest(org.contextmapper.dsl.AbstractDirectoryIntegrationTest)

Example 5 with SolverConfiguration

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;
}
Also used : SolverConfiguration(ch.hsr.servicecutter.solver.SolverConfiguration)

Aggregations

SolverConfiguration (ch.hsr.servicecutter.solver.SolverConfiguration)5 ServiceCutter (ch.hsr.servicecutter.api.ServiceCutter)1 ServiceCutterContext (ch.hsr.servicecutter.api.ServiceCutterContext)1 ServiceCutterContextBuilder (ch.hsr.servicecutter.api.ServiceCutterContextBuilder)1 SolverConfigurationFactory (ch.hsr.servicecutter.api.SolverConfigurationFactory)1 EntityRelationDiagram (ch.hsr.servicecutter.api.model.EntityRelationDiagram)1 SolverResult (ch.hsr.servicecutter.api.model.SolverResult)1 SolverPriority (ch.hsr.servicecutter.solver.SolverPriority)1 IOException (java.io.IOException)1 SimpleDateFormat (java.text.SimpleDateFormat)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 AbstractDirectoryIntegrationTest (org.contextmapper.dsl.AbstractDirectoryIntegrationTest)1 ContextMap (org.contextmapper.dsl.contextMappingDSL.ContextMap)1 ContextMappingModel (org.contextmapper.dsl.contextMappingDSL.ContextMappingModel)1 ContextMappingModelToServiceCutterERDConverter (org.contextmapper.dsl.generator.servicecutter.input.converter.ContextMappingModelToServiceCutterERDConverter)1 ServiceCutterOutputToContextMappingModelConverter (org.contextmapper.dsl.generator.servicecutter.output.converter.ServiceCutterOutputToContextMappingModelConverter)1 URI (org.eclipse.emf.common.util.URI)1 Resource (org.eclipse.emf.ecore.resource.Resource)1