Search in sources :

Example 1 with GraphMapping

use of org.jgrapht.GraphMapping in project winery by eclipse.

the class ComplianceRuleChecker method findMatches.

public List<GraphMapping> findMatches(TOSCAGraph queryGraph, TOSCAGraph searchInGraph) {
    TOSCAIsomorphismMatcher matcher = new TOSCAIsomorphismMatcher();
    Iterator<GraphMapping<TOSCANode, TOSCAEdge>> iterator = matcher.findMatches(queryGraph, searchInGraph, new TOSCAComplianceRuleMatcher());
    return convertToList(iterator);
}
Also used : TOSCAIsomorphismMatcher(org.eclipse.winery.compliance.matching.TOSCAIsomorphismMatcher) TOSCAComplianceRuleMatcher(org.eclipse.winery.compliance.matching.TOSCAComplianceRuleMatcher) GraphMapping(org.jgrapht.GraphMapping)

Example 2 with GraphMapping

use of org.jgrapht.GraphMapping in project winery by eclipse.

the class ComplianceRuleChecker method extractViolatingMappings.

public List<GraphMapping> extractViolatingMappings(TOSCAGraph identifierGraph, List<GraphMapping> identifierMappings, List<GraphMapping> requiredStructureMappings) {
    List<GraphMapping> violatingMappings = new ArrayList<>();
    // for all mappings in identifierMappings, we need to find the corresponding required Structure Mappings
    for (GraphMapping identifierMapping : identifierMappings) {
        boolean foundCorrespondence = false;
        for (GraphMapping requiredStructureMapping : requiredStructureMappings) {
            // get the corresponding TOSCANode from the searchInGraph
            TOSCANode identifierVertexCorrespondence = (TOSCANode) identifierMapping.getVertexCorrespondence(identifierGraph.getReferenceNode(), false);
            foundCorrespondence = (requiredStructureMapping.getVertexCorrespondence(identifierVertexCorrespondence, true) != null) ? true : false;
        }
        if (!foundCorrespondence) {
            violatingMappings.add(identifierMapping);
        }
    }
    return violatingMappings;
}
Also used : ArrayList(java.util.ArrayList) TOSCANode(org.eclipse.winery.compliance.model.TOSCANode) GraphMapping(org.jgrapht.GraphMapping)

Example 3 with GraphMapping

use of org.jgrapht.GraphMapping in project winery by eclipse.

the class TOSCAGraphIsomorphismTest method testTOSCADefaultMatcher.

@Test
public void testTOSCADefaultMatcher() {
    TOSCAEdgeFactory ef = new TOSCAEdgeFactory();
    TOSCAGraph queryGraph = new TOSCAGraph(ef);
    TOSCAGraph searchInGraph = new TOSCAGraph(ef);
    TOSCANode node1 = TOSCAModelHelper.createTOSCANode("node_01", "A");
    TOSCANode node2 = TOSCAModelHelper.createTOSCANode("node_02", "B");
    queryGraph.addVertex(node1);
    queryGraph.addVertex(node2);
    TOSCAEdge edge1 = TOSCAModelHelper.addEdge(queryGraph, node1, node2, "edge_1", "a");
    TOSCANode node3 = TOSCAModelHelper.createTOSCANode("node_03", "A");
    TOSCANode node4 = TOSCAModelHelper.createTOSCANode("node_04", "A");
    TOSCANode node5 = TOSCAModelHelper.createTOSCANode("node_05", "B");
    TOSCANode node6 = TOSCAModelHelper.createTOSCANode("node_06", "B");
    searchInGraph.addVertex(node3);
    searchInGraph.addVertex(node4);
    searchInGraph.addVertex(node5);
    searchInGraph.addVertex(node6);
    TOSCAEdge edge2 = TOSCAModelHelper.addEdge(searchInGraph, node3, node4, "edge_2", "b");
    TOSCAEdge edge3 = TOSCAModelHelper.addEdge(searchInGraph, node3, node5, "edge_3", "a");
    TOSCAEdge edge4 = TOSCAModelHelper.addEdge(searchInGraph, node4, node6, "edge_4", "a");
    TOSCAIsomorphismMatcher matcher = new TOSCAIsomorphismMatcher();
    Iterator<GraphMapping<TOSCANode, TOSCAEdge>> iterator = matcher.findMatches(queryGraph, searchInGraph, null);
    int isomorphismCount = 0;
    while (iterator.hasNext()) {
        isomorphismCount++;
        GraphMapping<TOSCANode, TOSCAEdge> mapping = iterator.next();
        TOSCAEdge edgeCor = mapping.getEdgeCorrespondence(edge1, false);
        TOSCANode nodeCor1 = mapping.getVertexCorrespondence(node1, false);
        TOSCANode nodeCor2 = mapping.getVertexCorrespondence(node2, false);
    }
    assertEquals(2, isomorphismCount);
}
Also used : TOSCAEdge(org.eclipse.winery.compliance.model.TOSCAEdge) TOSCAIsomorphismMatcher(org.eclipse.winery.compliance.matching.TOSCAIsomorphismMatcher) TOSCAGraph(org.eclipse.winery.compliance.model.TOSCAGraph) TOSCANode(org.eclipse.winery.compliance.model.TOSCANode) TOSCAEdgeFactory(org.eclipse.winery.compliance.model.TOSCAEdgeFactory) GraphMapping(org.jgrapht.GraphMapping) Test(org.junit.Test)

Example 4 with GraphMapping

use of org.jgrapht.GraphMapping in project winery by eclipse.

the class InstanceModelRefinementPlugin method isApplicable.

public boolean isApplicable(TTopologyTemplate template, ToscaGraph topologyGraph) {
    List<TTopologyTemplate> detectors = getDetectorGraphs();
    this.subGraphs = new ArrayList<>();
    IToscaMatcher matcher = getToscaMatcher();
    detectors.forEach(detector -> {
        ToscaGraph detectorGraph = ToscaTransformer.createTOSCAGraph(detector);
        Iterator<GraphMapping<ToscaNode, ToscaEdge>> matches = this.isomorphismMatcher.findMatches(detectorGraph, topologyGraph, matcher);
        int[] ids = { 0 };
        matches.forEachRemaining(match -> {
            ArrayList<String> nodeIdsToBeReplaced = new ArrayList<>();
            detectorGraph.vertexSet().forEach(toscaNode -> nodeIdsToBeReplaced.add(match.getVertexCorrespondence(toscaNode, false).getTemplate().getId()));
            if (!nodeIdsToBeReplaced.isEmpty()) {
                Set<String> additionalInputs = this.determineAdditionalInputs(template, nodeIdsToBeReplaced);
                this.subGraphs.add(new RefineableSubgraph(match, detectorGraph, nodeIdsToBeReplaced, additionalInputs, ids[0]++));
            }
        });
    });
    return !this.subGraphs.isEmpty();
}
Also used : ToscaGraph(org.eclipse.winery.topologygraph.model.ToscaGraph) ArrayList(java.util.ArrayList) IToscaMatcher(org.eclipse.winery.topologygraph.matching.IToscaMatcher) TTopologyTemplate(org.eclipse.winery.model.tosca.TTopologyTemplate) GraphMapping(org.jgrapht.GraphMapping)

Example 5 with GraphMapping

use of org.jgrapht.GraphMapping in project winery by eclipse.

the class ComplianceRuleChecker method extractViolatingMappings.

public List<GraphMapping> extractViolatingMappings(ToscaGraph identifierGraph, List<GraphMapping> identifierMappings, List<GraphMapping> requiredStructureMappings) {
    List<GraphMapping> violatingMappings = new ArrayList<>();
    // for all mappings in identifierMappings, we need to find the corresponding required Structure Mappings
    for (GraphMapping identifierMapping : identifierMappings) {
        boolean foundCorrespondence = false;
        for (GraphMapping requiredStructureMapping : requiredStructureMappings) {
            // get the corresponding ToscaNode from the searchInGraph
            ToscaNode identifierVertexCorrespondence = (ToscaNode) identifierMapping.getVertexCorrespondence(identifierGraph.getReferenceNode(), false);
            foundCorrespondence = (requiredStructureMapping.getVertexCorrespondence(identifierVertexCorrespondence, true) != null) ? true : false;
        }
        if (!foundCorrespondence) {
            violatingMappings.add(identifierMapping);
        }
    }
    return violatingMappings;
}
Also used : ToscaNode(org.eclipse.winery.topologygraph.model.ToscaNode) ArrayList(java.util.ArrayList) GraphMapping(org.jgrapht.GraphMapping)

Aggregations

GraphMapping (org.jgrapht.GraphMapping)17 ArrayList (java.util.ArrayList)9 ToscaIsomorphismMatcher (org.eclipse.winery.topologygraph.matching.ToscaIsomorphismMatcher)8 ToscaGraph (org.eclipse.winery.topologygraph.model.ToscaGraph)8 ToscaNode (org.eclipse.winery.topologygraph.model.ToscaNode)8 TTopologyTemplate (org.eclipse.winery.model.tosca.TTopologyTemplate)6 ToscaEdge (org.eclipse.winery.topologygraph.model.ToscaEdge)6 TNodeTemplate (org.eclipse.winery.model.tosca.TNodeTemplate)5 Test (org.junit.jupiter.api.Test)5 QName (javax.xml.namespace.QName)4 IToscaMatcher (org.eclipse.winery.topologygraph.matching.IToscaMatcher)4 ComplianceRuleChecker (org.eclipse.winery.compliance.checking.ComplianceRuleChecker)3 TOSCANode (org.eclipse.winery.compliance.model.TOSCANode)3 RefinementCandidate (org.eclipse.winery.model.adaptation.substitution.refinement.RefinementCandidate)3 TRelationshipTemplate (org.eclipse.winery.model.tosca.TRelationshipTemplate)3 Collection (java.util.Collection)2 Collections (java.util.Collections)2 Iterator (java.util.Iterator)2 LinkedHashMap (java.util.LinkedHashMap)2 List (java.util.List)2