org.jgrapht.Graph.getType()方法的使用及代码示例

x33g5p2x  于2022-01-20 转载在 其他  
字(9.9k)|赞(0)|评价(0)|浏览(131)

本文整理了Java中org.jgrapht.Graph.getType()方法的一些代码示例,展示了Graph.getType()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Graph.getType()方法的具体详情如下:
包路径:org.jgrapht.Graph
类名称:Graph
方法名:getType

Graph.getType介绍

[英]Get the graph type. The graph type can be used to query for additional metadata such as whether the graph supports directed or undirected edges, self-loops, multiple (parallel) edges, weights, etc.
[中]获取图形类型。图形类型可用于查询其他元数据,例如图形是否支持有向边或无向边、自循环、多条(平行)边、权重等。

代码示例

代码示例来源:origin: org.jgrapht/jgrapht-core

/**
 * {@inheritDoc}
 */
@Override
public GraphType getType()
{
  return base.getType();
}

代码示例来源:origin: org.jgrapht/jgrapht-core

/**
 * {@inheritDoc}
 */
@Override
public GraphType getType()
{
  return delegate.getType();
}

代码示例来源:origin: org.jgrapht/jgrapht-core

/**
 * Constructor for AsWeightedGraph where the weights are provided through a map. Invocations of
 * the @link{setEdgeWeight} method will update the map. Moreover, calls to @link{setEdgeWeight}
 * are propagated to the underlying graph.
 *
 * @param graph the backing graph over which a weighted view is to be created.
 * @param weights the map containing the edge weights.
 * @throws NullPointerException if the graph or the weights are null.
 */
public AsWeightedGraph(Graph<V, E> graph, Map<E, Double> weights)
{
  this(graph, weights, graph.getType().isWeighted());
}

代码示例来源:origin: org.jgrapht/jgrapht-io

/**
 * Compute the connector
 * 
 * @param graph the graph
 * @return the connector
 */
private String computeConnector(Graph<V, E> graph)
{
  StringBuilder connectorBuilder = new StringBuilder();
  if (graph.getType().isDirected()) {
    connectorBuilder.append(" ").append(DOTUtils.DIRECTED_GRAPH_EDGEOP).append(" ");
  } else {
    connectorBuilder.append(" ").append(DOTUtils.UNDIRECTED_GRAPH_EDGEOP).append(" ");
  }
  return connectorBuilder.toString();
}

代码示例来源:origin: org.jgrapht/jgrapht-io

private void writeGraphStart(TransformerHandler handler, Graph<V, E> g)
  throws SAXException
{
  // <graph>
  AttributesImpl attr = new AttributesImpl();
  attr.addAttribute(
    "", "", "edgedefault", "CDATA", g.getType().isDirected() ? "directed" : "undirected");
  handler.startElement("", "", "graph", attr);
}

代码示例来源:origin: org.jgrapht/jgrapht-core

/**
 * Constructs a new BiconnectivityInspector
 * 
 * @param graph the input graph
 */
public BiconnectivityInspector(Graph<V, E> graph)
{
  this.graph = Objects.requireNonNull(graph);
  if (graph.getType().isDirected())
    this.graph = new AsUndirectedGraph<>(graph);
}

代码示例来源:origin: org.jgrapht/jgrapht-core

/**
 * Construct a new maximum flow
 * 
 * @param network the network
 * @param epsilon the tolerance for the comparison of floating point values
 */
public MaximumFlowAlgorithmBase(Graph<V, E> network, double epsilon)
{
  this.network = network;
  this.directedGraph = network.getType().isDirected();
  this.comparator = new ToleranceDoubleComparator(epsilon);
}

代码示例来源:origin: org.jgrapht/jgrapht-core

/**
 * Creates a connectivity inspector for the specified graph.
 *
 * @param g the graph for which a connectivity inspector to be created.
 */
public ConnectivityInspector(Graph<V, E> g)
{
  init();
  this.graph = Objects.requireNonNull(g);
  if (g.getType().isDirected())
    this.graph = new AsUndirectedGraph<>(g);
}

代码示例来源:origin: org.jgrapht/jgrapht-core

/**
 * Test whether an undirected graph is a tree.
 *
 * @param graph the input graph
 * @param <V> the graph vertex type
 * @param <E> the graph edge type
 * @return true if the graph is tree, false otherwise
 */
public static <V, E> boolean isTree(Graph<V, E> graph)
{
  if (!graph.getType().isUndirected()) {
    throw new IllegalArgumentException(GRAPH_MUST_BE_UNDIRECTED);
  }
  return (graph.edgeSet().size() == (graph.vertexSet().size() - 1)) && isConnected(graph);
}

代码示例来源:origin: org.jgrapht/jgrapht-core

/**
 * Creates a new induced subgraph. Running-time = O(1).
 *
 * @param base the base (backing) graph on which the subgraph will be based.
 * @param vertexMask vertices to exclude in the subgraph. If a vertex is masked, it is as if it
 *        is not in the subgraph. Edges incident to the masked vertex are also masked.
 * @param edgeMask edges to exclude in the subgraph. If an edge is masked, it is as if it is not
 *        in the subgraph.
 */
public MaskSubgraph(Graph<V, E> base, Predicate<V> vertexMask, Predicate<E> edgeMask)
{
  super();
  this.base = Objects.requireNonNull(base, "Invalid graph provided");
  this.baseType = base.getType();
  this.vertexMask = Objects.requireNonNull(vertexMask, "Invalid vertex mask provided");
  this.edgeMask = Objects.requireNonNull(edgeMask, "Invalid edge mask provided");
  this.vertices = new MaskVertexSet<>(base.vertexSet(), vertexMask);
  this.edges = new MaskEdgeSet<>(base, base.edgeSet(), vertexMask, edgeMask);
}

代码示例来源:origin: org.jgrapht/jgrapht-core

/**
 * Creates a weak chordality inspector for the {@code graph}
 *
 * @param graph the inspected {@code graph}
 */
public WeakChordalityInspector(Graph<V, E> graph)
{
  this.graph = Objects.requireNonNull(graph);
  if (graph.getType().isDirected()) {
    this.graph = new AsUndirectedGraph<>(graph);
  }
  n = graph.vertexSet().size();
  m = graph.edgeSet().size();
  initMappings();
}

代码示例来源:origin: org.jgrapht/jgrapht-core

/**
 * Test whether an undirected graph is a forest. A forest is a set of disjoint trees. By
 * definition, any acyclic graph is a forest. This includes the empty graph and the class of
 * tree graphs.
 *
 * @param graph the input graph
 * @param <V> the graph vertex type
 * @param <E> the graph edge type
 * @return true if the graph is forest, false otherwise
 */
public static <V, E> boolean isForest(Graph<V, E> graph)
{
  if (!graph.getType().isUndirected()) {
    throw new IllegalArgumentException(GRAPH_MUST_BE_UNDIRECTED);
  }
  if (graph.vertexSet().isEmpty()) // null graph is not a forest
    return false;
  int nrConnectedComponents = new ConnectivityInspector<>(graph).connectedSets().size();
  return graph.edgeSet().size() + nrConnectedComponents == graph.vertexSet().size();
}

代码示例来源:origin: org.jgrapht/jgrapht-core

/**
 * Create a graph type builder which will create the same graph type as the parameter graph. The
 * new graph will use the same vertex and edge suppliers as the input graph.
 * 
 * @param graph a graph
 * @return a type builder
 * @param <V> the graph vertex type
 * @param <E> the graph edge type
 */
public static <V, E> GraphTypeBuilder<V, E> forGraph(Graph<V, E> graph)
{
  GraphTypeBuilder<V, E> builder = forGraphType(graph.getType());
  builder.vertexSupplier = graph.getVertexSupplier();
  builder.edgeSupplier = graph.getEdgeSupplier();
  return builder;
}

代码示例来源:origin: org.jgrapht/jgrapht-core

/**
 * {@inheritDoc}
 */
@Override
public MinimumCostFlow<E> getMinimumCostFlow(
  final MinimumCostFlowProblem<V, E> minimumCostFlowProblem)
{
  this.problem = Objects.requireNonNull(minimumCostFlowProblem);
  if (problem.getGraph().getType().isUndirected()) {
    throw new IllegalArgumentException(
      "The algorithm doesn't support undirected flow networks");
  }
  n = problem.getGraph().vertexSet().size();
  m = problem.getGraph().edgeSet().size();
  calculateMinimumCostFlow();
  return minimumCostFlow;
}

代码示例来源:origin: org.jgrapht/jgrapht-core

@Override
public Spanner<E> getSpanner()
{
  if (graph.getType().isWeighted()) {
    return new WeightedSpannerAlgorithm().run();
  } else {
    return new UnweightedSpannerAlgorithm().run();
  }
}

代码示例来源:origin: org.jgrapht/jgrapht-core

/**
 * Returns all anticomponents of a graph and a vertex set.
 * 
 * @param g A Graph
 * @param Y A set of vertices
 * @return List of anticomponents of Y in g
 */
private List<Set<V>> findAllAnticomponentsOfY(Graph<V, E> g, Set<V> Y)
{
  Graph<V, E> target;
  if (g.getType().isSimple())
    target = new SimpleGraph<>(
      g.getVertexSupplier(), g.getEdgeSupplier(), g.getType().isWeighted());
  else
    target = new Multigraph<>(
      g.getVertexSupplier(), g.getEdgeSupplier(), g.getType().isWeighted());
  new ComplementGraphGenerator<>(g).generateGraph(target);
  return findAllComponents(target, Y);
}

代码示例来源:origin: org.jgrapht/jgrapht-core

private void computeGlobalClusteringCoefficient()
{
  NeighborCache<V, E> neighborCache = new NeighborCache<>(graph);
  computed = true;
  double numberTriplets = 0;
  for (V v : graph.vertexSet()) {
    if (graph.getType().isUndirected()) {
      numberTriplets += 1.0 * graph.degreeOf(v) * (graph.degreeOf(v) - 1) / 2;
    } else {
      numberTriplets += 1.0 * neighborCache.predecessorsOf(v).size()
        * neighborCache.successorsOf(v).size();
    }
  }
  globalClusteringCoefficient = 3 * GraphMetrics.getNumberOfTriangles(graph) / numberTriplets;
}

代码示例来源:origin: org.jgrapht/jgrapht-core

/**
 * 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);
}

代码示例来源:origin: org.jgrapht/jgrapht-io

private void exportAdjacencyMatrix(Graph<V, E> g, Writer writer)
{
  for (V from : g.vertexSet()) {
    // assign ids in vertex set iteration order
    vertexIDProvider.getName(from);
  }
  PrintWriter out = new PrintWriter(writer);
  if (g.getType().isDirected()) {
    for (V from : g.vertexSet()) {
      exportAdjacencyMatrixVertex(out, from, Graphs.successorListOf(g, from));
    }
  } else {
    for (V from : g.vertexSet()) {
      exportAdjacencyMatrixVertex(out, from, Graphs.neighborListOf(g, from));
    }
  }
  out.flush();
}

代码示例来源:origin: org.jgrapht/jgrapht-core

private Graph<DistinctGraphObject<V, V, E>,
  DistinctGraphObject<E, V, E>> getDistinctObjectGraph(Graph<V, E> graph)
{
  Graph<DistinctGraphObject<V, V, E>,
    DistinctGraphObject<E, V, E>> transformedGraph = GraphTypeBuilder
      .<DistinctGraphObject<V, V, E>,
        DistinctGraphObject<E, V, E>> forGraphType(graph.getType())
      .buildGraph();
  for (V vertex : graph.vertexSet()) {
    transformedGraph.addVertex(new DistinctGraphObject<>(vertex, graph));
  }
  for (E edge : graph.edgeSet()) {
    transformedGraph.addEdge(
      new DistinctGraphObject<>(graph.getEdgeSource(edge), graph),
      new DistinctGraphObject<>(graph.getEdgeTarget(edge), graph),
      new DistinctGraphObject<>(edge, graph));
  }
  return transformedGraph;
}

相关文章