Search in sources :

Example 21 with DefaultEdge

use of org.jgrapht.graph.DefaultEdge in project graal by graphik-team.

the class GraphPositionDependencies method initFiniteRank.

public void initFiniteRank() {
    if (this.isFiniteRank == null) {
        this.isFiniteRank = new TreeSet<PredicatePosition>();
        StrongConnectivityAlgorithm<PredicatePosition, DefaultEdge> sccInspector = new KosarajuStrongConnectivityInspector<PredicatePosition, DefaultEdge>(graph);
        List<Set<PredicatePosition>> sccList = sccInspector.stronglyConnectedSets();
        for (Set<PredicatePosition> scc : sccList) {
            boolean componentIsFiniteRank = true;
            for (PredicatePosition p1 : scc) {
                for (PredicatePosition p2 : scc) {
                    for (DefaultEdge edge : graph.getAllEdges(p1, p2)) {
                        if (edge instanceof SpecialEdge) {
                            componentIsFiniteRank = false;
                        }
                    }
                }
            }
            // store information
            if (componentIsFiniteRank) {
                for (PredicatePosition p : scc) {
                    this.isFiniteRank.add(p);
                }
            }
        }
    }
}
Also used : KosarajuStrongConnectivityInspector(org.jgrapht.alg.KosarajuStrongConnectivityInspector) Set(java.util.Set) TreeSet(java.util.TreeSet) DefaultEdge(org.jgrapht.graph.DefaultEdge) PredicatePosition(fr.lirmm.graphik.graal.rulesetanalyser.util.PredicatePosition)

Example 22 with DefaultEdge

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

the class AbstractOrgClosureTest method checkChildrenSets.

private void checkChildrenSets(Set<String> oidsToCheck) {
    try (Session session = openSession()) {
        // noinspection unchecked
        SimpleDirectedGraph<String, DefaultEdge> tc = (SimpleDirectedGraph<String, DefaultEdge>) 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, session);
            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) Session(org.hibernate.Session)

Example 23 with DefaultEdge

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

the class AbstractOrgClosureTest method checkOrgGraph.

// checks org graph w.r.t. real org/parentref situation in repo
protected void checkOrgGraph() throws SchemaException {
    OperationResult result = new OperationResult("temp");
    int numberOfOrgsInRepo = repositoryService.countObjects(OrgType.class, null, null, result);
    info("Checking graph with repo. Orgs in repo: " + numberOfOrgsInRepo + ", orgs in graph: " + orgGraph.vertexSet().size());
    Assertions.assertThat(orgGraph.vertexSet()).withFailMessage("# of orgs in repo (" + numberOfOrgsInRepo + ") is different from # of orgs in graph (" + orgGraph.vertexSet().size() + ")").hasSize(numberOfOrgsInRepo);
    for (String oid : orgGraph.vertexSet()) {
        // info("Checking " + oid);
        OrgType orgType;
        try {
            orgType = repositoryService.getObject(OrgType.class, oid, null, result).asObjectable();
        } catch (ObjectNotFoundException | SchemaException e) {
            throw new AssertionError("Couldn't fetch " + oid, e);
        }
        assertTrue(orgGraph.vertexSet().contains(orgType.getOid()));
        Set<String> parentOidsInRepo = new HashSet<>();
        for (ObjectReferenceType ort : orgType.getParentOrgRef()) {
            if (orgGraph.vertexSet().contains(ort.getOid())) {
                // i.e. the parent does exist
                parentOidsInRepo.add(ort.getOid());
            }
        }
        Set<String> parentOidsInGraph = new HashSet<>();
        for (DefaultEdge edge : orgGraph.outgoingEdgesOf(oid)) {
            parentOidsInGraph.add(orgGraph.getEdgeTarget(edge));
        }
        assertEquals("Unexpected parentRefOrg set in " + orgType, parentOidsInGraph, parentOidsInRepo);
    }
    info("Graph is OK w.r.t. repo");
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) ObjectReferenceType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType) OrgType(com.evolveum.midpoint.xml.ns._public.common.common_3.OrgType) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException) DefaultEdge(org.jgrapht.graph.DefaultEdge) OperationResult(com.evolveum.midpoint.schema.result.OperationResult)

Example 24 with DefaultEdge

use of org.jgrapht.graph.DefaultEdge in project mule by mulesoft.

the class XmlExtensionLoaderDelegate method loadModuleExtension.

private void loadModuleExtension(ExtensionDeclarer declarer, URL resource, Document moduleDocument, Set<ExtensionModel> extensions, boolean comesFromTNS) {
    final ComponentModel moduleModel = getModuleComponentModel(resource, moduleDocument);
    if (!moduleModel.getIdentifier().equals(MODULE_IDENTIFIER)) {
        throw new MuleRuntimeException(createStaticMessage(format("The root element of a module must be '%s', but found '%s'", MODULE_IDENTIFIER.toString(), moduleModel.getIdentifier().toString())));
    }
    final String name = moduleModel.getParameters().get(MODULE_NAME);
    // TODO(fernandezlautaro): MULE-11010 remove version from ExtensionModel
    final String version = "4.0.0";
    final String category = moduleModel.getParameters().get(CATEGORY);
    final String vendor = moduleModel.getParameters().get(VENDOR);
    final XmlDslModel xmlDslModel = getXmlDslModel(moduleModel, name, version);
    final String description = getDescription(moduleModel);
    final String xmlnsTnsValue = moduleModel.getParameters().get(XMLNS_TNS);
    if (xmlnsTnsValue != null && !xmlDslModel.getNamespace().equals(xmlnsTnsValue)) {
        throw new MuleRuntimeException(createStaticMessage(format("The %s attribute value of the module must be '%s', but found '%s'", XMLNS_TNS, xmlDslModel.getNamespace(), xmlnsTnsValue)));
    }
    fillDeclarer(declarer, name, version, category, vendor, xmlDslModel, description);
    declarer.withModelProperty(getXmlExtensionModelProperty(moduleModel, xmlDslModel));
    DirectedGraph<String, DefaultEdge> directedGraph = new DefaultDirectedGraph<>(DefaultEdge.class);
    // loading public operations
    final Optional<ConfigurationDeclarer> configurationDeclarer = loadPropertiesFrom(declarer, moduleModel, extensions);
    final HasOperationDeclarer hasOperationDeclarer = configurationDeclarer.isPresent() ? configurationDeclarer.get() : declarer;
    loadOperationsFrom(hasOperationDeclarer, moduleModel, directedGraph, xmlDslModel, OperationVisibility.PUBLIC);
    // loading private operations
    if (comesFromTNS) {
        // when parsing for the TNS, we need the <operation/>s to be part of the extension model to validate the XML properly
        loadOperationsFrom(hasOperationDeclarer, moduleModel, directedGraph, xmlDslModel, OperationVisibility.PRIVATE);
    } else {
        // when parsing for the macro expansion, the <operation/>s will be left in the PrivateOperationsModelProperty model property
        final ExtensionDeclarer temporalDeclarer = new ExtensionDeclarer();
        fillDeclarer(temporalDeclarer, name, version, category, vendor, xmlDslModel, description);
        loadOperationsFrom(temporalDeclarer, moduleModel, directedGraph, xmlDslModel, OperationVisibility.PRIVATE);
        final ExtensionModel result = createExtensionModel(temporalDeclarer);
        declarer.withModelProperty(new PrivateOperationsModelProperty(result.getOperationModels()));
    }
    final CycleDetector<String, DefaultEdge> cycleDetector = new CycleDetector<>(directedGraph);
    final Set<String> cycles = cycleDetector.findCycles();
    if (!cycles.isEmpty()) {
        throw new MuleRuntimeException(createStaticMessage(format(CYCLIC_OPERATIONS_ERROR, new TreeSet(cycles))));
    }
}
Also used : DefaultDirectedGraph(org.jgrapht.graph.DefaultDirectedGraph) ConfigurationDeclarer(org.mule.runtime.api.meta.model.declaration.fluent.ConfigurationDeclarer) HasOperationDeclarer(org.mule.runtime.api.meta.model.declaration.fluent.HasOperationDeclarer) ExtensionModel(org.mule.runtime.api.meta.model.ExtensionModel) DefaultEdge(org.jgrapht.graph.DefaultEdge) CycleDetector(org.jgrapht.alg.CycleDetector) PrivateOperationsModelProperty(org.mule.runtime.config.internal.dsl.model.extension.xml.property.PrivateOperationsModelProperty) ExtensionDeclarer(org.mule.runtime.api.meta.model.declaration.fluent.ExtensionDeclarer) TreeSet(java.util.TreeSet) ComponentModel(org.mule.runtime.config.internal.model.ComponentModel) MuleRuntimeException(org.mule.runtime.api.exception.MuleRuntimeException) XmlDslModel(org.mule.runtime.api.meta.model.XmlDslModel)

Example 25 with DefaultEdge

use of org.jgrapht.graph.DefaultEdge in project presto by prestodb.

the class PhasedExecutionSchedule method extractPhases.

@VisibleForTesting
static List<Set<PlanFragmentId>> extractPhases(Collection<PlanFragment> fragments) {
    // Build a graph where the plan fragments are vertexes and the edges represent
    // a before -> after relationship.  For example, a join hash build has an edge
    // to the join probe.
    DirectedGraph<PlanFragmentId, DefaultEdge> graph = new DefaultDirectedGraph<>(DefaultEdge.class);
    fragments.forEach(fragment -> graph.addVertex(fragment.getId()));
    Visitor visitor = new Visitor(fragments, graph);
    for (PlanFragment fragment : fragments) {
        visitor.processFragment(fragment.getId());
    }
    // Computes all the strongly connected components of the directed graph.
    // These are the "phases" which hold the set of fragments that must be started
    // at the same time to avoid deadlock.
    List<Set<PlanFragmentId>> components = new StrongConnectivityInspector<>(graph).stronglyConnectedSets();
    Map<PlanFragmentId, Set<PlanFragmentId>> componentMembership = new HashMap<>();
    for (Set<PlanFragmentId> component : components) {
        for (PlanFragmentId planFragmentId : component) {
            componentMembership.put(planFragmentId, component);
        }
    }
    // build graph of components (phases)
    DirectedGraph<Set<PlanFragmentId>, DefaultEdge> componentGraph = new DefaultDirectedGraph<>(DefaultEdge.class);
    components.forEach(componentGraph::addVertex);
    for (DefaultEdge edge : graph.edgeSet()) {
        PlanFragmentId source = graph.getEdgeSource(edge);
        PlanFragmentId target = graph.getEdgeTarget(edge);
        Set<PlanFragmentId> from = componentMembership.get(source);
        Set<PlanFragmentId> to = componentMembership.get(target);
        if (!from.equals(to)) {
            // the topological order iterator below doesn't include vertices that have self-edges, so don't add them
            componentGraph.addEdge(from, to);
        }
    }
    List<Set<PlanFragmentId>> schedulePhases = ImmutableList.copyOf(new TopologicalOrderIterator<>(componentGraph));
    return schedulePhases;
}
Also used : HashSet(java.util.HashSet) ImmutableSet(com.google.common.collect.ImmutableSet) Set(java.util.Set) InternalPlanVisitor(com.facebook.presto.sql.planner.plan.InternalPlanVisitor) DefaultDirectedGraph(org.jgrapht.graph.DefaultDirectedGraph) HashMap(java.util.HashMap) DefaultEdge(org.jgrapht.graph.DefaultEdge) PlanFragment(com.facebook.presto.sql.planner.PlanFragment) PlanFragmentId(com.facebook.presto.sql.planner.plan.PlanFragmentId) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Aggregations

DefaultEdge (org.jgrapht.graph.DefaultEdge)26 ClassInfo (com.jopdesign.common.ClassInfo)8 HashMap (java.util.HashMap)7 HashSet (java.util.HashSet)6 Set (java.util.Set)5 DefaultDirectedGraph (org.jgrapht.graph.DefaultDirectedGraph)5 BitSet (java.util.BitSet)4 FileWriter (java.io.FileWriter)3 IOException (java.io.IOException)3 ArrayList (java.util.ArrayList)3 TopologicalOrderIterator (org.jgrapht.traverse.TopologicalOrderIterator)3 File (java.io.File)2 StringWriter (java.io.StringWriter)2 LinkedList (java.util.LinkedList)2 TreeSet (java.util.TreeSet)2 ExportException (org.jgrapht.nio.ExportException)2 GraphExpr (org.matheclipse.core.expression.data.GraphExpr)2 IAST (org.matheclipse.core.interfaces.IAST)2 IASTDataset (org.matheclipse.core.interfaces.IASTDataset)2 IExpr (org.matheclipse.core.interfaces.IExpr)2