/** * Returns true if {@code network} has at least one cycle. A cycle is defined as a non-empty * subset of edges in a graph arranged to form a path (a sequence of adjacent outgoing edges) * starting and ending with the same node. * * <p>This method will detect any non-empty cycle, including self-loops (a cycle of length 1). */ public static boolean hasCycle(Network<?, ?> network) { // In a directed graph, parallel edges cannot introduce a cycle in an acyclic graph. // However, in an undirected graph, any parallel edge induces a cycle in the graph. if (!network.isDirected() && network.allowsParallelEdges() && network.edges().size() > network.asGraph().edges().size()) { return true; } return hasCycle(network.asGraph()); }
/** * Returns true if {@code network} has at least one cycle. A cycle is defined as a non-empty * subset of edges in a graph arranged to form a path (a sequence of adjacent outgoing edges) * starting and ending with the same node. * * <p>This method will detect any non-empty cycle, including self-loops (a cycle of length 1). */ public static boolean hasCycle(Network<?, ?> network) { // In a directed graph, parallel edges cannot introduce a cycle in an acyclic graph. // However, in an undirected graph, any parallel edge induces a cycle in the graph. if (!network.isDirected() && network.allowsParallelEdges() && network.edges().size() > network.asGraph().edges().size()) { return true; } return hasCycle(network.asGraph()); }
/** * Returns true if {@code network} has at least one cycle. A cycle is defined as a non-empty * subset of edges in a graph arranged to form a path (a sequence of adjacent outgoing edges) * starting and ending with the same node. * * <p>This method will detect any non-empty cycle, including self-loops (a cycle of length 1). */ public static boolean hasCycle(Network<?, ?> network) { // In a directed graph, parallel edges cannot introduce a cycle in an acyclic graph. // However, in an undirected graph, any parallel edge induces a cycle in the graph. if (!network.isDirected() && network.allowsParallelEdges() && network.edges().size() > network.asGraph().edges().size()) { return true; } return hasCycle(network.asGraph()); }
String edgeString = networkString.substring(edgeStart); Graph<N> asGraph = network.asGraph(); AbstractGraphTest.validateGraph(asGraph); assertThat(network.nodes()).isEqualTo(asGraph.nodes());
/** * Creates an instance with the specified graph, distance metric, and averaging behavior. * * @param graph The graph on which the node scores are to be calculated. * @param distance The metric to use for specifying the distance between pairs of nodes. * @param averaging Specifies whether the values returned is the sum of all v-distances or the * mean v-distance. * @param ignore_missing Specifies whether scores for missing distances are to ignore missing * distances or be set to null. * @param ignore_self_distances Specifies whether distances from a node to itself should be * included in its score. */ public DistanceCentralityScorer( Network<N, E> graph, Distance<N> distance, boolean averaging, boolean ignore_missing, boolean ignore_self_distances) { this.graph = graph.asGraph(); this.distance = distance; this.averaging = averaging; this.ignore_missing = ignore_missing; this.ignore_self_distances = ignore_self_distances; this.output = new HashMap<N, Double>(); }
/** */ protected void drawShortest() { if (mFrom == null || mTo == null) { return; } BFSDistanceLabeler<String> bdl = new BFSDistanceLabeler<>(); bdl.labelDistances(mGraph.asGraph(), mFrom); mPred = new HashSet<>(); // grab a predecessor String v = mTo; Set<String> prd = bdl.getPredecessors(v); mPred.add(mTo); while (prd != null && prd.size() > 0) { v = prd.iterator().next(); mPred.add(v); if (v.equals(mFrom)) { return; } prd = bdl.getPredecessors(v); } }
public void setNetwork(Network<N, E> network, boolean forceUpdate) { log.trace("setNetwork to n:{} e:{}", network.nodes(), network.edges()); this.network = network; this.layoutModel.setGraph(network.asGraph()); if (forceUpdate && this.layoutAlgorithm != null) { log.trace("will accept {}", layoutAlgorithm); layoutModel.accept(this.layoutAlgorithm); log.trace("will fire stateChanged"); changeSupport.fireStateChanged(); log.trace("fired stateChanged"); } }
/** * Returns true if {@code network} has at least one cycle. A cycle is defined as a non-empty * subset of edges in a graph arranged to form a path (a sequence of adjacent outgoing edges) * starting and ending with the same node. * * <p>This method will detect any non-empty cycle, including self-loops (a cycle of length 1). */ public static boolean hasCycle(Network<?, ?> network) { // In a directed graph, parallel edges cannot introduce a cycle in an acyclic graph. // However, in an undirected graph, any parallel edge induces a cycle in the graph. if (!network.isDirected() && network.allowsParallelEdges() && network.edges().size() > network.asGraph().edges().size()) { return true; } return hasCycle(network.asGraph()); }
/** * Returns true if {@code network} has at least one cycle. A cycle is defined as a non-empty * subset of edges in a graph arranged to form a path (a sequence of adjacent outgoing edges) * starting and ending with the same node. * * <p>This method will detect any non-empty cycle, including self-loops (a cycle of length 1). */ public static boolean hasCycle(Network<?, ?> network) { // In a directed graph, parallel edges cannot introduce a cycle in an acyclic graph. // However, in an undirected graph, any parallel edge induces a cycle in the graph. if (!network.isDirected() && network.allowsParallelEdges() && network.edges().size() > network.asGraph().edges().size()) { return true; } return hasCycle(network.asGraph()); }
/** * For each node <code>v</code> in <code>g</code>, calculates the average shortest path length * from <code>v</code> to all other nodes in <code>g</code>, ignoring edge weights. * * @see #diameter(Hypergraph) * @see edu.uci.ics.jung.algorithms.scoring.ClosenessCentrality * @param g the graph for which distances are to be calculated * @param <N> the node type * @param <E> the edge type * @return a map from each node to the mean distance to each other (reachable) node */ public static <N, E> Function<N, Double> averageDistances(Network<N, E> g) { final ClosenessCentrality<N, E> cc = new ClosenessCentrality<N, E>(g, new UnweightedShortestPath<N>(g.asGraph())); return new NodeScoreTransformer<N, Double>(cc); }
this.layoutModel = LoadingCacheLayoutModel.<N>builder() .setGraph(network.asGraph()) .setSize(layoutSize.width, layoutSize.height) .setInitializer(
new AggregateLayoutModel<>( LoadingCacheLayoutModel.<String>builder() .setGraph(graph.asGraph()) .setSize(preferredSize.width, preferredSize.height) .build());
public void visit(LayoutModel<N> layoutModel) { // save off the existing layoutModel this.layoutModel = layoutModel; // create a LayoutModel to hold points for the transition this.transitionLayoutModel = LoadingCacheLayoutModel.<N>builder() .setGraph(visualizationServer.getModel().getNetwork().asGraph()) .setLayoutModel(layoutModel) .setInitializer(layoutModel) .build(); // start off the transitionLayoutModel with the endLayoutAlgorithm transitionLayoutModel.accept(endLayoutAlgorithm); }
String edgeString = networkString.substring(edgeStart); Graph<N> asGraph = network.asGraph(); AbstractGraphTest.validateGraph(asGraph); assertThat(network.nodes()).isEqualTo(asGraph.nodes());