edu.uci.ics.jung.graph.Graph类的使用及代码示例

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

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

Graph介绍

[英]A graph consisting of a set of vertices of type V set and a set of edges of type E. Edges of this graph type have exactly two endpoints; whether these endpoints must be distinct depends on the implementation.

This interface permits, but does not enforce, any of the following common variations of graphs:

  • directed and undirected edges
  • vertices and edges with attributes (for example, weighted edges)
  • vertices and edges of different types (for example, bipartite or multimodal graphs)
  • parallel edges (multiple edges which connect a single set of vertices)
  • representations as matrices or as adjacency lists or adjacency maps
    Extensions or implementations of this interface may enforce or disallow any or all of these variations.

Definitions (with respect to a given vertex v):

  • incoming edge of v: an edge that can be traversed from a neighbor of v to reach v
  • outgoing edge of v: an edge that can be traversed from v to reach some neighbor of v
  • predecessor of v: a vertex at the other end of an incoming edge of v
  • successor of v: a vertex at the other end of an outgoing edge of v
    [中]由一组V类型的顶点和一组E类型的边组成的图。此图类型的边正好有两个端点;这些端点是否必须是不同的取决于实现。
    此接口允许但不强制执行以下图形的任何常见变化:
    *有向边和无向边
    *具有属性的顶点和边(例如,加权边)
    *不同类型的顶点和边(例如,二部图或多模态图)
    *平行边(连接一组顶点的多条边)
    *表示为矩阵或邻接列表或邻接映射
    此接口的扩展或实现可能强制或禁止任何或所有这些变化。
    定义(关于给定顶点v
    *v的传入边:可以从v的邻居穿过以到达v的边
    *v的传出边:可以从v穿过以到达v的某个邻居的边
    *v的前身:位于v传入边另一端的顶点
    *v的后继者:位于v输出边另一端的顶点

代码示例

代码示例来源:origin: geogebra/geogebra

protected void initialize(Graph<V, E> graph) {
  this.graph = graph;
  this.vertex_scores = new HashMap<V, Double>();
  this.edge_scores = new HashMap<E, Double>();
  this.vertex_data = new HashMap<V, BetweennessData>();
  for (V v : graph.getVertices()) {
    this.vertex_scores.put(v, 0.0);
  }
  for (E e : graph.getEdges()) {
    this.edge_scores.put(e, 0.0);
  }
}

代码示例来源:origin: geogebra/geogebra

/**
 * @see edu.uci.ics.jung.graph.Hypergraph#addEdge(Object, Collection,
 *      EdgeType)
 */
@Override
public synchronized boolean addEdge(E e,
    Collection<? extends V> vertices, EdgeType edgeType) {
  return delegate.addEdge(e, vertices, edgeType);
}

代码示例来源:origin: net.sf.jung/jung-graph-impl

/**
 * adds root as a root of the tree
 * @param root the initial tree root
 */
public void setRoot(V root) {
  delegate.addVertex(root);
}

代码示例来源:origin: net.sf.jung/jung-graph-impl

/**
 * @return the root of each tree of this forest as a {@code Collection}.
 */
public Collection<V> getRoots() {
  Collection<V> roots = new HashSet<V>();
  for(V v : delegate.getVertices()) {
    if(delegate.getPredecessorCount(v) == 0) {
      roots.add(v);
    }
  }
  return roots;
}

代码示例来源:origin: OpenNMS/opennms

private Set<V> getRoots() {
  Set<V> roots = graph.getVertices().stream()
      .filter(v -> graph.getInEdges(v).isEmpty())
      // Preserve the order of the roots
      .collect(Collectors.toCollection(LinkedHashSet::new));
  return roots;
}

代码示例来源:origin: com.github.fburato/highwheel-core

private void shift(final Layout<ElementName, Dependency> l, final int dx,
   final int dy) {
  for (final ElementName each : l.getGraph().getVertices()) {
   final Point2D point = l.transform(each);
   point.setLocation(point.getX() + dx, point.getY() + dy);
  }
 }
}

代码示例来源:origin: net.sf.jung/jung-visualization

public Paint apply(E e)
{
  Layout<V, E> layout = vv.getGraphLayout();
  Pair<V> p = layout.getGraph().getEndpoints(e);
  V b = p.getFirst();
  V f = p.getSecond();
  Point2D pb = transformer.transform(layout.apply(b));
  Point2D pf = transformer.transform(layout.apply(f));
  float xB = (float) pb.getX();
  float yB = (float) pb.getY();
  float xF = (float) pf.getX();
  float yF = (float) pf.getY();
  if ((layout.getGraph().getEdgeType(e)) == EdgeType.UNDIRECTED)  {
    xF = (xF + xB) / 2;
    yF = (yF + yB) / 2;
  } 
  if(selfLoop.apply(Context.<Graph<V,E>,E>getInstance(layout.getGraph(), e))) {
    yF += 50;
    xF += 50;
  }
  return new GradientPaint(xB, yB, getColor1(e), xF, yF, getColor2(e), true);
}

代码示例来源:origin: net.sf.jung/jung-visualization

Pair<V> endpoints = graph.getEndpoints(e);
V v1 = endpoints.getFirst();
V v2 = endpoints.getSecond();
if (!rc.getEdgeIncludePredicate().apply(Context.<Graph<V,E>,E>getInstance(graph,e)))
  return;
if (!rc.getVertexIncludePredicate().apply(Context.<Graph<V,E>,V>getInstance(graph,v1)) || 
  !rc.getVertexIncludePredicate().apply(Context.<Graph<V,E>,V>getInstance(graph,v2)))
  return;
p1 = rc.getMultiLayerTransformer().transform(Layer.LAYOUT, p1);
p2 = rc.getMultiLayerTransformer().transform(Layer.LAYOUT, p2);
float x1 = (float) p1.getX();
float y1 = (float) p1.getY();
float x2 = (float) p2.getX();
float y2 = (float) p2.getY();

代码示例来源:origin: net.sf.jung/jung-algorithms

protected void relaxEdges() {
  try {
    for(E e : getGraph().getEdges()) {
      Pair<V> endpoints = getGraph().getEndpoints(e);
      V v1 = endpoints.getFirst();
      V v2 = endpoints.getSecond();
      double vx = p1.getX() - p2.getX();
      double vy = p1.getY() - p2.getY();
      double len = Math.sqrt(vx * vx + vy * vy);
      f = f * Math.pow(stretch, (getGraph().degree(v1) + getGraph().degree(v2) - 2));

代码示例来源:origin: net.sf.jung/jung-visualization

private void checkEdge(E e) {
  Pair<V> endpoints = graph.getEndpoints(e);
  V v1 = endpoints.getFirst();
  V v2 = endpoints.getSecond();
  p1 = rc.getMultiLayerTransformer().transform(Layer.LAYOUT, p1);
  p2 = rc.getMultiLayerTransformer().transform(Layer.LAYOUT, p2);
  float x1 = (float) p1.getX();
  float y1 = (float) p1.getY();
  float x2 = (float) p2.getX();
  float y2 = (float) p2.getY();
  Shape s2 = rc.getVertexShapeTransformer().apply(v2);
  Shape edgeShape = rc.getEdgeShapeTransformer().apply(e);

代码示例来源:origin: org.opendaylight.controller.thirdparty/net.sf.jung2

protected void calcAttraction(E e) {
  Pair<V> endpoints = getGraph().getEndpoints(e);
  V v1 = endpoints.getFirst();
  V v2 = endpoints.getSecond();
  boolean v1_locked = isLocked(v1);
  boolean v2_locked = isLocked(v2);
  Point2D p2 = transform(v2);
  if(p1 == null || p2 == null) return;
  double xDelta = p1.getX() - p2.getX();
  double yDelta = p1.getY() - p2.getY();
  double deltaLength = Math.max(EPSILON, p1.distance(p2));

代码示例来源:origin: net.sf.jung/jung-algorithms

public void setLocation(V v, Point2D location) {
  boolean wasInSublayout = false;
  for(Layout<V,E> layout : layouts.keySet()) {
    if(layout.getGraph().getVertices().contains(v)) {
      Point2D center = layouts.get(layout);
      // transform by the layout itself, but offset to the
      // center of the sublayout
      Dimension d = layout.getSize();
      AffineTransform at = 
        AffineTransform.getTranslateInstance(-center.getX()+d.width/2,-center.getY()+d.height/2);
      Point2D localLocation = at.transform(location, null);
      layout.setLocation(v, localLocation);
      wasInSublayout = true;
    }
  }
  if(wasInSublayout == false && getGraph().getVertices().contains(v)) {
    delegate.setLocation(v, location);
  }
}

代码示例来源:origin: net.sf.jung/jung-visualization

for(E e : graph.getEdges()) {
  Pair<V> endpoints = graph.getEndpoints(e);
  V v1 = endpoints.getFirst();
  V v2 = endpoints.getSecond();
  Point2D p1 = layout.apply(v1);
  Point2D p2 = layout.apply(v2);
  float x1 = (float)p1.getX();
  float y1 = (float)p1.getY();
  float x2 = (float)p2.getX();
  float y2 = (float)p2.getY();
  Shape s2 = rc.getVertexShapeTransformer().apply(v2);
  Shape edgeShape = rc.getEdgeShapeTransformer().apply(e);
for(V v : graph.getVertices()) {
  Shape shape = rc.getVertexShapeTransformer().apply(v);
  Point2D p = layout.apply(v);

代码示例来源:origin: org.apache.batchee/batchee-maven-plugin

final Pair<Node> endpoints = graph.getEndpoints(e);
final Node v1 = endpoints.getFirst();
final Node v2 = endpoints.getSecond();
if (!rc.getEdgeIncludePredicate().evaluate(Context.<Graph<Node, Edge>, Edge>getInstance(graph, e))) {
  return;
if (!rc.getVertexIncludePredicate().evaluate(Context.<Graph<Node, Edge>, Node>getInstance(graph, v1)) ||
  !rc.getVertexIncludePredicate().evaluate(Context.<Graph<Node, Edge>, Node>getInstance(graph, v2))) {
  return;
final FontMetrics fm = g.getFontMetrics();
int w = fm.stringWidth(e.text);
double p = Math.max(0, p1.getX() + p2.getX() - w);
xform.translate(Math.min(layout.getSize().width - w, p / 2), (p1.getY() + p2.getY() - fm.getHeight()) / 2);
g.setTransform(xform);
g.draw(component, rc.getRendererPane(), 0, 0, d.width, d.height, true);

代码示例来源:origin: org.opendaylight.controller.thirdparty/net.sf.jung2

public boolean evaluate(Context<Graph<V,E>,E> context) {
    Pair<V> endpoints = context.graph.getEndpoints(context.element);
    return endpoints.getFirst().equals(endpoints.getSecond());
  }
}

代码示例来源:origin: girtel/Net2Plan

@Override
public void rebuildGraph()
{
  for (GUILink gl : new ArrayList<>(g.getEdges()))
    g.removeEdge(gl);
  for (GUINode gn : new ArrayList<>(g.getVertices()))
    g.removeVertex(gn);
  for (GUINode gn : callback.getVisualizationState().getCanvasAllGUINodes()) g.addVertex(gn);
  for (GUILink gl : callback.getVisualizationState().getCanvasAllGUILinks(true, true))
    g.addEdge(gl, gl.getOriginNode(), gl.getDestinationNode());
  updateAllVerticesXYPosition();
  refresh();
}

代码示例来源:origin: net.sf.jung/jung-samples

public void paint(Graphics g) {
    if(mPred == null) return;
    
    // for all edges, paint edges that are in shortest path
    for (Number e : layout.getGraph().getEdges()) {
      
      if(isBlessed(e)) {
        String v1 = mGraph.getEndpoints(e).getFirst();
        String v2 = mGraph.getEndpoints(e).getSecond();
        Point2D p1 = layout.apply(v1);
        Point2D p2 = layout.apply(v2);
        p1 = vv.getRenderContext().getMultiLayerTransformer().transform(Layer.LAYOUT, p1);
        p2 = vv.getRenderContext().getMultiLayerTransformer().transform(Layer.LAYOUT, p2);
        Renderer<String,Number> renderer = vv.getRenderer();
        renderer.renderEdge(
            vv.getRenderContext(),
            layout,
            e);
      }
    }
  }
});

代码示例来源:origin: org.cloudml/ui.graph

public void drawFromDeploymentModel(){
  Collection<Edge> c = new ArrayList<Edge>(graph.getEdges());
  for(Edge e : c)
    graph.removeEdge(e);
  Collection<Vertex> vs =new ArrayList<Vertex>(graph.getVertices());
  for(Vertex ve : vs)
    graph.removeVertex(ve);
  
  ArrayList<Vertex> v = drawVerticesFromDeploymentModel(dmodel);
  drawEdgesFromDeploymentModel(dmodel, v);
  nodeTypes.removeAll();
  nodeTypes.setModel(fillList());
}

代码示例来源:origin: net.sf.jung/jung-visualization

public void paintEdge(RenderContext<V,E> rc, Layout<V, E> layout, E e) {
  GraphicsDecorator g2d = rc.getGraphicsContext();
  Graph<V,E> graph = layout.getGraph();
  if (!rc.getEdgeIncludePredicate().apply(Context.<Graph<V,E>,E>getInstance(graph,e)))
    return;
  
  // don't draw edge if either incident vertex is not drawn
  Pair<V> endpoints = graph.getEndpoints(e);
  V v1 = endpoints.getFirst();
  V v2 = endpoints.getSecond();
  if (!rc.getVertexIncludePredicate().apply(Context.<Graph<V,E>,V>getInstance(graph,v1)) || 
    !rc.getVertexIncludePredicate().apply(Context.<Graph<V,E>,V>getInstance(graph,v2)))
    return;
  
  Stroke new_stroke = rc.getEdgeStrokeTransformer().apply(e);
  Stroke old_stroke = g2d.getStroke();
  if (new_stroke != null)
    g2d.setStroke(new_stroke);
  
  drawSimpleEdge(rc, layout, e);
  // restore paint and stroke
  if (new_stroke != null)
    g2d.setStroke(old_stroke);
}

代码示例来源:origin: net.sf.jung/jung-visualization

/**
 * Returns <code>true</code> if this edge and its endpoints
 * in this graph are all included in the collections of
 * elements to be rendered, and <code>false</code> otherwise.
 * @param context the edge and graph to be queried
 * @return <code>true</code> if this edge and its endpoints are all
 * included in the collections of elements to be rendered, <code>false</code>
 * otherwise.
 */
protected boolean isEdgeRendered(Context<Graph<V,E>,E> context) {
  Predicate<Context<Graph<V,E>,V>> vertexIncludePredicate =
    vv.getRenderContext().getVertexIncludePredicate();
  Predicate<Context<Graph<V,E>,E>> edgeIncludePredicate =
    vv.getRenderContext().getEdgeIncludePredicate();
  Graph<V,E> g = context.graph;
  E e = context.element;
  boolean edgeTest = edgeIncludePredicate == null || edgeIncludePredicate.apply(context);
  Pair<V> endpoints = g.getEndpoints(e);
  V v1 = endpoints.getFirst();
  V v2 = endpoints.getSecond();
  boolean endpointsTest = vertexIncludePredicate == null ||
    (vertexIncludePredicate.apply(Context.<Graph<V,E>,V>getInstance(g,v1)) && 
        vertexIncludePredicate.apply(Context.<Graph<V,E>,V>getInstance(g,v2)));
  return edgeTest && endpointsTest;
}

相关文章