/** * Constructor * * @param graph the input graph */ public AbstractFundamentalCycleBasis(Graph<V, E> graph) { this.graph = GraphTests.requireDirectedOrUndirected(graph); }
/** * Complement Graph Generator. If the target graph allows self-loops the complement of $G$ may * be defined by adding a self-loop to every vertex that does not have one in $G$. This behavior * can be controlled using the boolean <code>generateSelfLoops</code>. * * @param graph input graph * @param generateSelfLoops indicator whether self loops should be generated. If false, no * self-loops are generated, independent of whether the target graph supports self-loops. */ public ComplementGraphGenerator(Graph<V, E> graph, boolean generateSelfLoops) { this.graph = GraphTests.requireDirectedOrUndirected(graph); this.generateSelfLoops = generateSelfLoops; }
/** * Checks that the specified graph is directed and throws an {@link IllegalArgumentException} if * it is not. Also checks that the graph reference is not {@code null} and throws a * {@link NullPointerException} if it is. * * @param graph the graph reference to check for beeing directed and not null * @param <V> the graph vertex type * @param <E> the graph edge type * @return {@code graph} if directed and not {@code null} * @throws NullPointerException if {@code graph} is {@code null} * @throws IllegalArgumentException if {@code graph} is mixed */ public static <V, E> Graph<V, E> requireDirectedOrUndirected(Graph<V, E> graph) { return requireDirectedOrUndirected(graph, GRAPH_MUST_BE_DIRECTED_OR_UNDIRECTED); }
GraphTests.requireDirectedOrUndirected(target); boolean isDirected = target.getType().isDirected();
GraphTests.requireDirectedOrUndirected(target); boolean isDirected = target.getType().isDirected();
/** * Creates a new subgraph. * * @param base the base (backing) graph on which the subgraph will be based. * @param vertexSubset vertices to include in the subgraph. If <code>null</code> then all * vertices are included. * @param edgeSubset edges to in include in the subgraph. If <code>null</code> then all the * edges whose vertices found in the graph are included. */ public AsSubgraph(Graph<V, E> base, Set<? extends V> vertexSubset, Set<? extends E> edgeSubset) { super(); this.base = GraphTests.requireDirectedOrUndirected(base); this.baseType = base.getType(); this.isInduced = edgeSubset == null; if (base instanceof ListenableGraph<?, ?>) { ((ListenableGraph<V, E>) base).addGraphListener(new BaseGraphListener()); } initialize(vertexSubset, edgeSubset); }
/** * Solves the Chinese Postman Problem on the given graph. For Undirected graph, this * implementation uses the @{@link KolmogorovMinimumWeightPerfectMatching} matching algorithm; * for directed graphs, @{@link KuhnMunkresMinimalWeightBipartitePerfectMatching} is used * instead. The input graph must be strongly connected. Otherwise the behavior of this class is * undefined. * * @param graph the input graph (must be a strongly connected graph) * @return Eulerian circuit of minimum weight. */ public GraphPath<V, E> getCPPSolution(Graph<V, E> graph) { // Mixed graphs are currently not supported. Solving the CPP for mixed graphs is NP-Hard GraphTests.requireDirectedOrUndirected(graph); // If graph has no vertices, or no edges, instantly return. if (graph.vertexSet().isEmpty() || graph.edgeSet().isEmpty()) return new HierholzerEulerianCycle<V, E>().getEulerianCycle(graph); assert GraphTests.isStronglyConnected(graph); if (graph.getType().isUndirected()) return solveCPPUndirected(graph); else return solveCPPDirected(graph); }
return; GraphTests.requireDirectedOrUndirected(graph);
/** * Construct a new graph union. * * @param g1 the first graph * @param g2 the second graph * @param operator the weight combiner (policy for edge weight calculation) */ public AsGraphUnion(Graph<V, E> g1, Graph<V, E> g2, WeightCombiner operator) { this.g1 = GraphTests.requireDirectedOrUndirected(g1); this.type1 = g1.getType(); this.g2 = GraphTests.requireDirectedOrUndirected(g2); this.type2 = g2.getType(); if (g1 == g2) { throw new IllegalArgumentException("g1 is equal to g2"); } this.operator = Objects.requireNonNull(operator, "Weight combiner cannot be null"); // compute result type DefaultGraphType.Builder builder = new DefaultGraphType.Builder(); if (type1.isDirected() && type2.isDirected()) { builder = builder.directed(); } else if (type1.isUndirected() && type2.isUndirected()) { builder = builder.undirected(); } else { builder = builder.mixed(); } this.type = builder .allowSelfLoops(type1.isAllowingSelfLoops() || type2.isAllowingSelfLoops()) .allowMultipleEdges(true).weighted(true).modifiable(false).build(); }
GraphTests.requireDirectedOrUndirected(graph);
GraphTests.requireDirectedOrUndirected(g); Graph<V, E> complementGraph; if (g.getType().isSimple())