Search in sources :

Example 1 with SimpleDirectedGraph

use of org.jgrapht.graph.SimpleDirectedGraph in project ambrose by twitter.

the class AmbroseCascadingGraphConverter method getNodeFeatures.

/**
   * Retrieves array of simple class names of nodes within a particular flow step.
   *
   * @param step step in main flow.
   * @return list step's graph's vertex names.
   */
protected String[] getNodeFeatures(BaseFlowStep step) {
    SimpleDirectedGraph graph = step.getGraph();
    Object[] vertices = graph.vertexSet().toArray();
    String[] returnedFeatures = new String[vertices.length];
    for (int i = 0; i < returnedFeatures.length; i++) {
        returnedFeatures[i] = vertices[i].getClass().getSimpleName();
    }
    return returnedFeatures;
}
Also used : SimpleDirectedGraph(org.jgrapht.graph.SimpleDirectedGraph)

Example 2 with SimpleDirectedGraph

use of org.jgrapht.graph.SimpleDirectedGraph in project midpoint by Evolveum.

the class AbstractOrgClosureTest method checkChildrenSets.

private void checkChildrenSets(Set<String> oidsToCheck) {
    SimpleDirectedGraph<String, DefaultEdge> tc = (SimpleDirectedGraph) orgGraph.clone();
    TransitiveClosure.INSTANCE.closeSimpleDirectedGraph(tc);
    for (String subroot : oidsToCheck) {
        LOGGER.info("Checking descendants of {}", subroot);
        Set<String> expectedChildren = new HashSet<>();
        for (DefaultEdge edge : tc.incomingEdgesOf(subroot)) {
            expectedChildren.add(tc.getEdgeSource(edge));
        }
        expectedChildren.add(subroot);
        LOGGER.trace("Expected children: {}", expectedChildren);
        Set<String> actualChildren = getActualChildrenOf(subroot);
        LOGGER.trace("Actual children: {}", actualChildren);
        Set<String> expectedMinusActual = new HashSet<>(expectedChildren);
        expectedMinusActual.removeAll(actualChildren);
        if (!expectedMinusActual.isEmpty()) {
            System.out.println("Expected-Actual = " + expectedMinusActual);
        }
        Set<String> actualMinusExpected = new HashSet<>(actualChildren);
        actualMinusExpected.removeAll(expectedChildren);
        if (!actualMinusExpected.isEmpty()) {
            System.out.println("Actual-Expected = " + actualMinusExpected);
        }
        assertEquals("Incorrect children for " + subroot, expectedChildren, actualChildren);
    }
}
Also used : SimpleDirectedGraph(org.jgrapht.graph.SimpleDirectedGraph) DefaultEdge(org.jgrapht.graph.DefaultEdge) HashSet(java.util.HashSet)

Example 3 with SimpleDirectedGraph

use of org.jgrapht.graph.SimpleDirectedGraph in project winery by eclipse.

the class Detection method detectPattern.

/**
 * 2. step: Create all subgraphs of the topology graph and test for isomorphism with pattern graphs
 *
 * @param tTopologyTemplate: the TOSCA topology will be labeled
 */
private void detectPattern(TTopologyTemplate tTopologyTemplate) {
    abstractTopology = new AbstractTopology(tTopologyTemplate, labeledNodeTemplates);
    List<TNodeTemplate> tNodeTemplateList = ModelUtilities.getAllNodeTemplates(tTopologyTemplate);
    List<TRelationshipTemplate> tRelationshipTemplateList = ModelUtilities.getAllRelationshipTemplates(tTopologyTemplate);
    getLowestNode(tNodeTemplateList.get(0), tRelationshipTemplateList);
    Set<TNodeTemplateExtended> allNodes = abstractTopology.getGraph().vertexSet();
    TNodeTemplateExtended baseNodeExtended = new TNodeTemplateExtended();
    Iterator iterator = allNodes.iterator();
    // search for the lowest node in the abstract topology graph, this is used to copy the lowest node from the original Topology to the AbstractTopology
    while (iterator.hasNext()) {
        TNodeTemplateExtended temp = (TNodeTemplateExtended) iterator.next();
        if (temp.getNodeTemplate().getId().equals(basisNodeTemplate.getId())) {
            baseNodeExtended = temp;
            break;
        }
    }
    // map the topology outgoing from the given base node
    abstractTopology.map(baseNodeExtended);
    // in the patternList all graphs of the pattern objects are added
    List<DirectedGraph<PatternComponent, RelationshipEdge>> patternList = new ArrayList<>();
    HashMap<Integer, String> patternNames = new HashMap<>();
    // create objects of all known patterns
    ExecutionEnvironmentPattern executionEnvironmentPattern = new ExecutionEnvironmentPattern();
    NodeBasedAvailabilityPattern nodeBasedAvailabilityPattern = new NodeBasedAvailabilityPattern();
    ElasticityManagerPattern elasticityManagerPattern = new ElasticityManagerPattern();
    ElasticLoadBalancerPattern elasticLoadBalancerPattern = new ElasticLoadBalancerPattern();
    ElasticQueuePattern elasticQueuePattern = new ElasticQueuePattern();
    EnvironmentBasedAvailabilityPattern environmentBasedAvailabilityPattern = new EnvironmentBasedAvailabilityPattern();
    MessageOrientedMiddlewarePattern messageOrientedMiddlewarePattern = new MessageOrientedMiddlewarePattern();
    RelationalDatabasePattern relationalDatabasePattern = new RelationalDatabasePattern();
    KeyValueStoragePattern keyValueStoragePattern = new KeyValueStoragePattern();
    ExecutionEnvironmentPattern2 executionEnvironmentPattern2 = new ExecutionEnvironmentPattern2();
    // to receive the right pattern name for the current counter, pattern names are associated with numbers
    patternNames.put(0, patternExecEnv);
    patternNames.put(1, patternNodeBasedAvail);
    patternNames.put(2, patternElasticityManager);
    patternNames.put(3, patternElasticLoadBalancer);
    patternNames.put(4, patternElasticQueue);
    patternNames.put(5, patternEnvBasedAvail);
    patternNames.put(6, patternMessageMiddleware);
    patternNames.put(7, patternRelationalDatabase);
    patternNames.put(8, patternKeyValueStorage);
    patternNames.put(9, patternExecEnv);
    // pattern are added in order
    patternList.add(executionEnvironmentPattern.getPatternGraph());
    patternList.add(nodeBasedAvailabilityPattern.getPatternGraph());
    patternList.add(elasticityManagerPattern.getPatternGraph());
    patternList.add(elasticLoadBalancerPattern.getPatternGraph());
    patternList.add(elasticQueuePattern.getPatternGraph());
    patternList.add(environmentBasedAvailabilityPattern.getPatternGraph());
    patternList.add(messageOrientedMiddlewarePattern.getPatternGraph());
    patternList.add(relationalDatabasePattern.getPatternGraph());
    patternList.add(keyValueStoragePattern.getPatternGraph());
    patternList.add(executionEnvironmentPattern2.getPatternGraph());
    int countIndex = 0;
    // abstractTopology represents the base graph, for each pattern graph search for a subgraph isomorphism between base graph & pattern graph
    for (DirectedGraph<PatternComponent, RelationshipEdge> pattern : patternList) {
        VF2SubgraphIsomorphismInspector<TNodeTemplateExtended, RelationshipEdge> inspector = new VF2SubgraphIsomorphismInspector(abstractTopology.getGraph(), pattern);
        if (inspector.isomorphismExists()) {
            Iterator it = inspector.getMappings();
            while (it.hasNext()) {
                IsomorphicGraphMapping mapping = (IsomorphicGraphMapping) it.next();
                // list for counting all matches between pattern nodes and base graph nodes, must be true for all
                List<Boolean> matched = new ArrayList<>();
                // this graph holds the nodes of the base graph in which the pattern occurs
                DirectedGraph<TNodeTemplateExtended, RelationshipEdge> originGraph = new SimpleDirectedGraph<>(RelationshipEdge.class);
                // each node of the pattern graph is compared to the according node in the GraphMapping
                for (PatternComponent p : pattern.vertexSet()) {
                    // check if matched subgraph and topology have the same components, get the correspondent vertex in the mapping for a node
                    TNodeTemplateExtended v = (TNodeTemplateExtended) mapping.getVertexCorrespondence(p, false);
                    // if the names equal, the node is added to the originGraph and a boolean with value true is added to the matched list
                    if (p.getName().equals(v.getLabel())) {
                        matched.add(true);
                        originGraph.addVertex(v);
                    } else {
                        matched.add(false);
                    }
                }
                // correspondent to the countIndex, the pattern name is retrieved
                if (!matched.contains(false) && !impossiblePattern.contains(patternNames.get(countIndex))) {
                    // add a new pattern position: the pattern name & the subgraph in which it occurs, this graph was built up in the previous step
                    PatternPosition temp = new PatternPosition(patternNames.get(countIndex), originGraph);
                    patternPositions.add(temp);
                    detectedPattern.add(patternNames.get(countIndex));
                    // sett some additional probabilities
                    if (patternNames.get(countIndex).equals(patternEnvBasedAvail)) {
                        patternProbabilityHigh.add(patternPublicCloud);
                    } else if (patternNames.get(countIndex).equals(patternEnvBasedAvail)) {
                        impossiblePattern.add(patternNodeBasedAvail);
                    } else if (patternNames.get(countIndex).equals(patternNodeBasedAvail)) {
                        impossiblePattern.add(patternEnvBasedAvail);
                    }
                }
            }
        }
        countIndex++;
    }
}
Also used : IsomorphicGraphMapping(org.jgrapht.alg.isomorphism.IsomorphicGraphMapping) DirectedGraph(org.jgrapht.DirectedGraph) SimpleDirectedGraph(org.jgrapht.graph.SimpleDirectedGraph) TRelationshipTemplate(org.eclipse.winery.model.tosca.TRelationshipTemplate) TNodeTemplate(org.eclipse.winery.model.tosca.TNodeTemplate) VF2SubgraphIsomorphismInspector(org.jgrapht.alg.isomorphism.VF2SubgraphIsomorphismInspector) SimpleDirectedGraph(org.jgrapht.graph.SimpleDirectedGraph)

Aggregations

SimpleDirectedGraph (org.jgrapht.graph.SimpleDirectedGraph)3 HashSet (java.util.HashSet)1 TNodeTemplate (org.eclipse.winery.model.tosca.TNodeTemplate)1 TRelationshipTemplate (org.eclipse.winery.model.tosca.TRelationshipTemplate)1 DirectedGraph (org.jgrapht.DirectedGraph)1 IsomorphicGraphMapping (org.jgrapht.alg.isomorphism.IsomorphicGraphMapping)1 VF2SubgraphIsomorphismInspector (org.jgrapht.alg.isomorphism.VF2SubgraphIsomorphismInspector)1 DefaultEdge (org.jgrapht.graph.DefaultEdge)1