本文整理汇总了Java中edu.uci.ics.jung.graph.Graph.getVertices方法的典型用法代码示例。如果您正苦于以下问题:Java Graph.getVertices方法的具体用法?Java Graph.getVertices怎么用?Java Graph.getVertices使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类edu.uci.ics.jung.graph.Graph
的用法示例。
在下文中一共展示了Graph.getVertices方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: connected
import edu.uci.ics.jung.graph.Graph; //导入方法依赖的package包/类
/**
* Test whether a graph is connected.
*
* @param graph to test.
* @return true if graph is connected, false otherwise.
*/
public static boolean connected(Graph<IVertex, IEdge> graph) {
DijkstraShortestPath<IVertex, IEdge> sp = new DijkstraShortestPath<>(graph);
Collection<IVertex> verts = graph.getVertices();
// forall vertA, vertB in graph exists connecting path <=> graph is connected
for (IVertex vertA : verts) {
for (IVertex vertB : verts) {
if (sp.getDistance(vertA, vertB) == null) {
return false;
}
}
}
return true;
}
示例2: reverseEdges
import edu.uci.ics.jung.graph.Graph; //导入方法依赖的package包/类
/**
* This method reverse the path "path" in the graph "graph" and returns it.
*
* @param graph
* the input graph which will not be changed.
* @param path
* the path to reverse
* @return a new graph with the reversed path
*/
private Graph<V, E> reverseEdges(Graph<V, E> graph, List<E> path) {
if (graph == null || path == null)
throw new IllegalArgumentException();
Graph<V, E> clone = new DirectedOrderedSparseMultigraph<V, E>();
for (V v : graph.getVertices())
clone.addVertex(v);
for (E e : graph.getEdges())
clone.addEdge(e, graph.getEndpoints(e));
for (E link : path) {
V src = clone.getSource(link);
V dst = clone.getDest(link);
clone.removeEdge(link);
clone.addEdge(link, dst, src, EdgeType.DIRECTED);
}
return clone;
}
示例3: graphToAdjacencyMatrix
import edu.uci.ics.jung.graph.Graph; //导入方法依赖的package包/类
public static int[][] graphToAdjacencyMatrix(Graph<Vertex,Edge> graph){
int size = graph.getVertices().size();
Vertex[] vertices = new Vertex[size];
int c = 0;
for (Vertex vertex : graph.getVertices()) {
vertices[c++] = vertex;
}
int[][] matrix = new int[size][];
for (int i = 0; i < matrix.length; i++) {
matrix[i] = new int[size];
for (int j = 0; j < matrix[i].length; j++) {
//matrix[i][j]= vertices[j].findEdge(vertices[i]) != null ? 1 : 0;
matrix[i][j]= ( ( graph.findEdge(vertices[j], vertices[i]) != null )
|| (graph.findEdge(vertices[i], vertices[j]) != null ) ) ? 1 : 0;
}
}
return matrix;
}
示例4: computeGraphCoreness
import edu.uci.ics.jung.graph.Graph; //导入方法依赖的package包/类
private void computeGraphCoreness(Graph<V, E> g) {
degree = new HashMap<V, Integer>();
weightedDegree = new HashMap<V, Integer>();
normalizedWeight = new HashMap<E, Integer>();
coreIndex = 0;
for (V v : g.getVertices()) {
degree.put(v, g.degree(v));
}
normalizeWeights(g.getEdges());
computeWeightedDegree(paramAlpha, paramBeta);
while (!weightedDegree.isEmpty())
computeCore(minWeightedDegree);
}
示例5: outdegreeDistribution
import edu.uci.ics.jung.graph.Graph; //导入方法依赖的package包/类
/**
* Determine the outdegree distribution of a graph.
*
* @param graph
* to analyze.
* @return a map with the outdegree as keys and the number of nodes with
* this outdegree as the corresponding value.
*/
public static Map<Integer,Integer> outdegreeDistribution(Graph<IVertex, IEdge> graph) {
Map<Integer, Integer> result = new HashMap<Integer, Integer>();
Collection<IVertex> verts = graph.getVertices();
for (IVertex vertex : verts) {
int outdegree = graph.getOutEdges(vertex).size();
Integer cnt = result.get(outdegree);
cnt = (cnt == null) ? 0 : cnt;
cnt++;
result.put(outdegree, cnt);
}
return result;
}
示例6: graphToDot
import edu.uci.ics.jung.graph.Graph; //导入方法依赖的package包/类
public static void graphToDot(Graph<Vertex,Edge> graph, PrintStream ps){
ps.println("digraph g {");
ps.println("node [style=filled, color=black, fillcolor=gray, shape=circle, label=\"\", height=.15, width=.15]");
for (Vertex vertex : graph.getVertices()) {
ps.println(vertex.toString() + "[label=\"" + vertex.getLabel() + "\"]");
}
for (Edge edge :graph.getEdges()) {
ps.println( graph.getSource(edge)+ "->" + graph.getDest(edge).toString());
}
ps.println("}");
}
示例7: caculateCenter
import edu.uci.ics.jung.graph.Graph; //导入方法依赖的package包/类
/**
* Calculates the center of masses of a network given its layout and as if the nodes had constant weight.
* @param layout positions of the nodes of the networks
* @param graph network to analyze
* @return Point2D with the coordinates of the center
*/
static public Point2D caculateCenter(Layout<Vertex, Edge> layout, Graph<Vertex,Edge> graph)
{
Point2D center = new Point2D.Double(0.0d,0.0d);
double n = 0.0d;
for (Vertex vertex : graph.getVertices())
{
Point2D vertexPosition = layout.transform(vertex);
center.setLocation(center.getX() + vertexPosition.getX(), center.getY() + vertexPosition.getY());
n++;
}
center.setLocation(center.getX() / n, center.getY() / n);
return center;
}
示例8: computeRho
import edu.uci.ics.jung.graph.Graph; //导入方法依赖的package包/类
private void computeRho(Graph<V, E> g, int cmax) {
for(V v : g.getVertices() ) {
int sum = 0;
for(V n : getNeighborsWithHigherCoreness(g, v) ) {
sum += cmax - coreness.get(n);
}
double r = (1 - EPSILON) * (cmax - coreness.get(v) ) +
(EPSILON / getNeighborsWithHigherCoreness(g, v).size() ) * sum;
if(r > 0 && cmaxRadius > r)
cmaxRadius = r;
rho.put(v, r);
}
}
示例9: FixedLayout
import edu.uci.ics.jung.graph.Graph; //导入方法依赖的package包/类
/**
* Constructor for the fixed layout of a given graph
* @param g graph to generate the fixed layout
*/
public FixedLayout(Graph<Vertex,E> g, Layout<Vertex,Edge> layout){
super(g);
for (Vertex vertex : g.getVertices())
vertex.setPosition(layout.transform(vertex));
initialize();
}
示例10: computeRho
import edu.uci.ics.jung.graph.Graph; //导入方法依赖的package包/类
private void computeRho(Graph<V, E> g, int cmax) {
for (V v : g.getVertices()) {
int sum = 0;
for (V n : getNeighborsWithHigherCoreness(g, v)) {
sum += cmax - coreness.get(n);
}
double r = (1 - EPSILON) * (cmax - coreness.get(v))
+ (EPSILON / getNeighborsWithHigherCoreness(g, v).size())
* sum;
if (r > 0 && cmaxRadius > r)
cmaxRadius = r;
rho.put(v, r);
}
}
示例11: computeRho
import edu.uci.ics.jung.graph.Graph; //导入方法依赖的package包/类
private void computeRho(Graph<V, E> g, int cmax) {
for(V v : g.getVertices() ) {
int sum = 0;
for(V n : getNeighborsWithHigherCoreness(g, v) ) {
sum += cmax - coreness.get(n);
}
double r = (1 - EPSILON) * (cmax - coreness.get(v) ) +
(EPSILON / getNeighborsWithHigherCoreness(g, v).size() ) * sum;
rho.put(v, r*RHO_SCALE);
}
}
示例12: rotateGraph
import edu.uci.ics.jung.graph.Graph; //导入方法依赖的package包/类
/**
* Rotates the current graph around itself.
* @param rotateAngle the angle on which the graph should rotate
*/
private void rotateGraph(double rotateAngle) {
if (this.localNetworkModel!=null) {
Graph<GraphNode, GraphEdge> graph = this.localNetworkModel.getGraph();
if (graph!=null) {
Vector<GraphNode> graphNodes = new Vector<GraphNode>(graph.getVertices());
if (graphNodes.size()>1) {
double centerX = this.getVisualizationViewer().getCenter().getX();
double centerY = this.getVisualizationViewer().getCenter().getY();
// --- Get all GraphNodes and rotate then around the center ---
for (GraphNode graphNode : graphNodes) {
double newX = 0;
double newY = 0;
double oldX = graphNode.getPosition().getX() - centerX;
double oldY = graphNode.getPosition().getY() - centerY;
double hypotenuse = Math.pow((Math.pow(oldX, 2) + Math.pow(oldY, 2)), 0.5);
hypotenuse = Math.round(hypotenuse*10)/10;
double oldAngle = Math.atan(oldY / oldX);
if (Double.isNaN(oldAngle)==false) {
if (oldX < 0 && oldY >= 0) {
oldAngle += Math.PI;
} else if (oldX < 0 && oldY < 0){
oldAngle += Math.PI;
}else if (oldX >= 0 && oldY < 0){
oldAngle += 2*Math.PI;
}
double newAngle = oldAngle + rotateAngle;
newX = Math.cos(newAngle) * hypotenuse;
newY = Math.sin(newAngle) * hypotenuse;
}
Point2D newPosition = new Point2D.Double(centerX+newX, centerY+newY);
graphNode.setPosition(newPosition);
}
Layout<GraphNode, GraphEdge> layout = new StaticLayout<GraphNode, GraphEdge>(graph);
layout.setInitializer(new Transformer<GraphNode, Point2D>() {
public Point2D transform(GraphNode node) {
return node.getPosition(); // The position is specified in the GraphNode instance
}
});
this.getVisualizationViewer().setGraphLayout(layout);
this.getVisualizationViewer().repaint();
}
}
}
}