List<Set<PlanFragmentId>> components = new StrongConnectivityInspector<>(graph).stronglyConnectedSets();
/** * Returns the average two-term reliability (A2TR) of the network. A2TR is computed * as the ratio between the number of node-pair for which a path can be found * and the same number when the network is connected (<i>Nx(N-1)</i>, where * <i>N</i> is the number of nodes in the network). The value is in range [0, 1]. * * @return Average two-term reliability */ public double getAverageTwoTermReliability() { if (E == 0) return 0; DirectedGraph<Node, Link> graph = getGraph_JGraphT(); StrongConnectivityInspector<Node, Link> ci = new StrongConnectivityInspector<Node, Link>(graph); List<Set<Node>> connectedComponents = ci.stronglyConnectedSets(); double sum = 0; Iterator<Set<Node>> it = connectedComponents.iterator(); while (it.hasNext()) { int componentSize = it.next().size(); sum += componentSize * (componentSize - 1); } return sum / (N * (N - 1)); }
private void groupDeps() { StrongConnectivityInspector<AFuncDeclIR, DefaultEdge> visitor = new StrongConnectivityInspector<>(deps); for (Set<AFuncDeclIR> scs : visitor.stronglyConnectedSets()) { if (scs.size() > 1) { AMrFuncGroupDeclIR aux = new AMrFuncGroupDeclIR(); aux.setFuncs(new LinkedList<>(scs)); // this line also removes the function from the functions block result.getDecls().add(aux); } } }
protected Set<ATermAppl> computeCycles() { Set<ATermAppl> cyclicConcepts = CollectionUtils.makeIdentitySet(); cyclicConcepts.addAll( getEquivalents( TOP ) ); StrongConnectivityInspector<ATermAppl, DefaultEdge> scInspector = new StrongConnectivityInspector<ATermAppl, DefaultEdge>( graph ); List<Set<ATermAppl>> sccList = scInspector.stronglyConnectedSets(); for( Set<ATermAppl> scc : sccList ) { if( scc.size() == 1 ) continue; cyclicConcepts.addAll( scc ); collapseCycle( scc ); } return cyclicConcepts; }
protected Set<ATermAppl> computeCycles() { Set<ATermAppl> cyclicConcepts = CollectionUtils.makeIdentitySet(); cyclicConcepts.addAll( getEquivalents( TOP ) ); StrongConnectivityInspector<ATermAppl, DefaultEdge> scInspector = new StrongConnectivityInspector<ATermAppl, DefaultEdge>( graph ); List<Set<ATermAppl>> sccList = scInspector.stronglyConnectedSets(); for( Set<ATermAppl> scc : sccList ) { if( scc.size() == 1 ) continue; cyclicConcepts.addAll( scc ); collapseCycle( scc ); } return cyclicConcepts; }
private List<MappingConfiguration> getTopologicallyOrderedMappingConfigurations( JsonixContext context, final List<ModuleConfiguration> moduleConfigurations) { final DirectedGraph<MappingConfiguration, Object> mappingConfigurationDependencyGraph = buildMappingConfigurationDependencyGraph( context, moduleConfigurations); final StrongConnectivityInspector<MappingConfiguration, Object> strongConnectivityInspector = new StrongConnectivityInspector<MappingConfiguration, Object>( mappingConfigurationDependencyGraph); final List<Set<MappingConfiguration>> stronglyConnectedSets = strongConnectivityInspector .stronglyConnectedSets(); for (Set<MappingConfiguration> stronglyConnectedSet : stronglyConnectedSets) { if (stronglyConnectedSet.size() > 1) { throw new IllegalArgumentException(MessageFormat.format( "Mappings have the following dependency cycle: {0}", stronglyConnectedSet.toString())); } } final List<MappingConfiguration> mappingConfigurations = new ArrayList<MappingConfiguration>( mappingConfigurationDependencyGraph.vertexSet().size()); for (Iterator<MappingConfiguration> mappingConfigurationsInTopologicalOrderIterator = new TopologicalOrderIterator<MappingConfiguration, Object>( mappingConfigurationDependencyGraph); mappingConfigurationsInTopologicalOrderIterator .hasNext();) { mappingConfigurations .add(mappingConfigurationsInTopologicalOrderIterator.next()); } return mappingConfigurations; }
private List<MappingConfiguration> getTopologicallyOrderedMappingConfigurations( JsonixContext context, final List<ModuleConfiguration> moduleConfigurations) { final DirectedGraph<MappingConfiguration, Object> mappingConfigurationDependencyGraph = buildMappingConfigurationDependencyGraph( context, moduleConfigurations); final StrongConnectivityInspector<MappingConfiguration, Object> strongConnectivityInspector = new StrongConnectivityInspector<MappingConfiguration, Object>( mappingConfigurationDependencyGraph); final List<Set<MappingConfiguration>> stronglyConnectedSets = strongConnectivityInspector .stronglyConnectedSets(); for (Set<MappingConfiguration> stronglyConnectedSet : stronglyConnectedSets) { if (stronglyConnectedSet.size() > 1) { throw new IllegalArgumentException(MessageFormat.format( "Mappings have the following dependency cycle: {0}", stronglyConnectedSet.toString())); } } final List<MappingConfiguration> mappingConfigurations = new ArrayList<MappingConfiguration>( mappingConfigurationDependencyGraph.vertexSet().size()); for (Iterator<MappingConfiguration> mappingConfigurationsInTopologicalOrderIterator = new TopologicalOrderIterator<MappingConfiguration, Object>( mappingConfigurationDependencyGraph); mappingConfigurationsInTopologicalOrderIterator .hasNext();) { mappingConfigurations .add(mappingConfigurationsInTopologicalOrderIterator.next()); } return mappingConfigurations; }
/** Check whether the graph is connected, that is, if it is possible to connect every node to each other. * * @param graph The graph to analyze * @return {@code true} if the graph is connected, and false otherwise */ public static boolean isConnected(org.jgrapht.Graph graph) { if (graph instanceof DirectedGraph) { StrongConnectivityInspector ci = new StrongConnectivityInspector((DirectedGraph) graph); return ci.isStronglyConnected(); } else if (graph instanceof UndirectedGraph) { ConnectivityInspector ci = new ConnectivityInspector((UndirectedGraph) graph); return ci.isGraphConnected(); } throw new RuntimeException("Bad"); }
/** * Returns the components of the graph that are cycles. * Taken from the implementation of {@link CycleDetector#findCycles()}. (EPL) */ private static <T, E> ListIterable<Set<T>> getCycleComponents(final DirectedGraph<T, E> graph) { StrongConnectivityInspector<T, E> inspector = new StrongConnectivityInspector<T, E>(graph); return ListAdapter.adapt(inspector.stronglyConnectedSets()).select(new Predicate<Set<T>>() { @Override public boolean accept(Set<T> each) { if (each.size() > 1) { // multi-vertex strongly-connected component is a cycle return true; } // vertex with an edge to itself is a cycle T vertex = each.iterator().next(); return graph.containsEdge(vertex, vertex); } }); } }
/** * Returns the components of the graph that are cycles. * Taken from the implementation of {@link CycleDetector#findCycles()}. (EPL) */ private static <T, E> ListIterable<Set<T>> getCycleComponents(final DirectedGraph<T, E> graph) { StrongConnectivityInspector<T, E> inspector = new StrongConnectivityInspector<T, E>(graph); return ListAdapter.adapt(inspector.stronglyConnectedSets()).select(new Predicate<Set<T>>() { @Override public boolean accept(Set<T> each) { if (each.size() > 1) { // multi-vertex strongly-connected component is a cycle return true; } // vertex with an edge to itself is a cycle T vertex = each.iterator().next(); return graph.containsEdge(vertex, vertex); } }); } }
private static List<Set<VUCent>> getConnectedComponents(Graph<VUCent, Edge> graph, String orientation) { LOGGER.info("Calculating connected components... "); final long start = System.currentTimeMillis(); List<Set<VUCent>> sets; if (parseGlobalOrientation(orientation).equals(UNDIRECTED)) { sets = new ConnectivityInspector<VUCent, Edge>( (UndirectedGraph<VUCent, Edge>) graph).connectedSets(); } else { sets = new StrongConnectivityInspector<VUCent, Edge>( (DirectedGraph) graph).stronglyConnectedSets(); } logTime(LOGGER, start); return sets; }
private static List<Set<VUCent>> getConnectedComponents(Graph<VUCent, Edge> graph, String orientation) { LOGGER.info("Calculating connected components... "); final long start = System.currentTimeMillis(); List<Set<VUCent>> sets; if (parseGlobalOrientation(orientation).equals(UNDIRECTED)) { sets = new ConnectivityInspector<VUCent, Edge>( (UndirectedGraph<VUCent, Edge>) graph).connectedSets(); } else { sets = new StrongConnectivityInspector<VUCent, Edge>( (DirectedGraph) graph).stronglyConnectedSets(); } logTime(LOGGER, start); return sets; }
private void estimateTreeSizesForCyclesWithIndividuals(OptimizedDirectedMultigraph<OWLClass> existentialRestrictionGraph, OptimizedDirectedMultigraph<OWLClass> toldSubsumptionGraph, Map<OWLClass, Integer> individualCount) { StrongConnectivityInspector<OWLClass, DefaultWeightedEdge> connectivityInspector = new StrongConnectivityInspector<OWLClass, DefaultWeightedEdge>(existentialRestrictionGraph); for (Set<OWLClass> connectedSet : connectivityInspector.stronglyConnectedSets()) { if (connectedSet.size() <= 1) continue;
private void estimateTreeSizesForCyclesWithIndividuals(OptimizedDirectedMultigraph<OWLClass> existentialRestrictionGraph, OptimizedDirectedMultigraph<OWLClass> toldSubsumptionGraph, Map<OWLClass, Integer> individualCount) { StrongConnectivityInspector<OWLClass, DefaultWeightedEdge> connectivityInspector = new StrongConnectivityInspector<OWLClass, DefaultWeightedEdge>(existentialRestrictionGraph); for (Set<OWLClass> connectedSet : connectivityInspector.stronglyConnectedSets()) { if (connectedSet.size() <= 1) continue;
List<Set<PlanFragmentId>> components = new StrongConnectivityInspector<>(graph).stronglyConnectedSets();
List<Set<PlanFragmentId>> components = new StrongConnectivityInspector<>(graph).stronglyConnectedSets();
List<Set<PlanFragmentId>> components = new StrongConnectivityInspector<>(graph).stronglyConnectedSets();
private void estimateTreeSizesForCycles(OptimizedDirectedMultigraph<OWLClass> existentialRestrictionGraph) { int maxSizeOfCompleteGraphToIgnore = getMaxSizeOfCompleteGraphToIgnore(m_MaxTreeSize); StrongConnectivityInspector<OWLClass, DefaultWeightedEdge> connectivityInspector = new StrongConnectivityInspector<OWLClass, DefaultWeightedEdge>(existentialRestrictionGraph); for (Set<OWLClass> connectedSet : connectivityInspector.stronglyConnectedSets()) { if (connectedSet.size() <= maxSizeOfCompleteGraphToIgnore) continue; DirectedSubgraph<OWLClass, DefaultWeightedEdge> subgraph = new DirectedSubgraph<OWLClass, DefaultWeightedEdge>(existentialRestrictionGraph, connectedSet, null); double estimatedTreeSize = 1.0; for (OWLClass owlClass : connectedSet) { estimatedTreeSize *= subgraph.outDegreeOf(owlClass); } if (estimatedTreeSize > m_MaxTreeSize) { Lint lint = m_LintFactory.make(); lint.addAllParticipatingClasses(connectedSet); lint.setSeverity(new Severity(estimatedTreeSize)); m_AccumulatedLints.add(lint); } } }
private void estimateTreeSizesForCycles(OptimizedDirectedMultigraph<OWLClass> existentialRestrictionGraph) { int maxSizeOfCompleteGraphToIgnore = getMaxSizeOfCompleteGraphToIgnore(m_MaxTreeSize); StrongConnectivityInspector<OWLClass, DefaultWeightedEdge> connectivityInspector = new StrongConnectivityInspector<OWLClass, DefaultWeightedEdge>(existentialRestrictionGraph); for (Set<OWLClass> connectedSet : connectivityInspector.stronglyConnectedSets()) { if (connectedSet.size() <= maxSizeOfCompleteGraphToIgnore) continue; DirectedSubgraph<OWLClass, DefaultWeightedEdge> subgraph = new DirectedSubgraph<OWLClass, DefaultWeightedEdge>(existentialRestrictionGraph, connectedSet, null); double estimatedTreeSize = 1.0; for (OWLClass owlClass : connectedSet) { estimatedTreeSize *= subgraph.outDegreeOf(owlClass); } if (estimatedTreeSize > m_MaxTreeSize) { Lint lint = m_LintFactory.make(); lint.addAllParticipatingClasses(connectedSet); lint.setSeverity(new Severity(estimatedTreeSize)); m_AccumulatedLints.add(lint); } } }
List<Set<V>> stronglyConnectedSets = new StrongConnectivityInspector<V, E>(graph).stronglyConnectedSets();