Search in sources :

Example 1 with TOSCAGraph

use of org.eclipse.winery.compliance.model.TOSCAGraph 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 2 with TOSCAGraph

use of org.eclipse.winery.compliance.model.TOSCAGraph in project winery by eclipse.

the class TOSCATransformer method createTOSCAGraph.

public static TOSCAGraph createTOSCAGraph(TTopologyTemplate topologyTemplate) {
    TOSCAGraph graph = new TOSCAGraph(new TOSCAEdgeFactory());
    @NonNull List<TRelationshipTemplate> relationshipTemplates = topologyTemplate.getRelationshipTemplates();
    @NonNull List<TNodeTemplate> nodeTemplates = topologyTemplate.getNodeTemplates();
    Map<TNodeTemplate, TOSCANode> nodes = new HashMap<>();
    for (TNodeTemplate nodeTemplate : nodeTemplates) {
        TOSCANode node = createAndInitializeTOSCANode(nodeTemplate);
        nodes.put(nodeTemplate, node);
        graph.addVertex(node);
    }
    for (TRelationshipTemplate tRelationshipTemplate : relationshipTemplates) {
        TOSCAEdge edge = graph.addEdge(nodes.get(tRelationshipTemplate.getSourceElement().getRef()), nodes.get(tRelationshipTemplate.getTargetElement().getRef()));
        initializeTOSCAEdge(tRelationshipTemplate, edge);
    }
    return graph;
}
Also used : TOSCAEdge(org.eclipse.winery.compliance.model.TOSCAEdge) HashMap(java.util.HashMap) NonNull(org.eclipse.jdt.annotation.NonNull) TRelationshipTemplate(org.eclipse.winery.model.tosca.TRelationshipTemplate) TOSCAGraph(org.eclipse.winery.compliance.model.TOSCAGraph) TOSCANode(org.eclipse.winery.compliance.model.TOSCANode) TNodeTemplate(org.eclipse.winery.model.tosca.TNodeTemplate) TOSCAEdgeFactory(org.eclipse.winery.compliance.model.TOSCAEdgeFactory)

Aggregations

TOSCAEdge (org.eclipse.winery.compliance.model.TOSCAEdge)2 TOSCAEdgeFactory (org.eclipse.winery.compliance.model.TOSCAEdgeFactory)2 TOSCAGraph (org.eclipse.winery.compliance.model.TOSCAGraph)2 TOSCANode (org.eclipse.winery.compliance.model.TOSCANode)2 HashMap (java.util.HashMap)1 NonNull (org.eclipse.jdt.annotation.NonNull)1 TOSCAIsomorphismMatcher (org.eclipse.winery.compliance.matching.TOSCAIsomorphismMatcher)1 TNodeTemplate (org.eclipse.winery.model.tosca.TNodeTemplate)1 TRelationshipTemplate (org.eclipse.winery.model.tosca.TRelationshipTemplate)1 GraphMapping (org.jgrapht.GraphMapping)1 Test (org.junit.Test)1