本文整理匯總了Java中edu.uci.ics.jung.graph.util.EdgeType.UNDIRECTED屬性的典型用法代碼示例。如果您正苦於以下問題:Java EdgeType.UNDIRECTED屬性的具體用法?Java EdgeType.UNDIRECTED怎麽用?Java EdgeType.UNDIRECTED使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在類edu.uci.ics.jung.graph.util.EdgeType
的用法示例。
在下文中一共展示了EdgeType.UNDIRECTED屬性的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getGraph
/**
* Convert FNSS topology to JUNG graph.
*
* @param topology FNSS Topology object
* @return A JUNG graph
*/
public static Graph<String, Edge> getGraph(Topology topology) {
Graph<String, Edge> graph = null;
EdgeType edgeType = null;
if (topology.isDirected()) {
graph = new DirectedSparseGraph<String, Edge>();
edgeType = EdgeType.DIRECTED;
} else {
graph = new UndirectedSparseGraph<String, Edge>();
edgeType = EdgeType.UNDIRECTED;
}
for(String node : topology.getAllNodes()) {
graph.addVertex(node);
}
for(Pair<String, String> edge : topology.getAllEdges()) {
graph.addEdge(topology.getEdge(edge), edge.getU(), edge.getV(), edgeType);
}
return graph;
}
示例2: addEdge
/**
* Overriding addEdge method from SparseGraph to conform
* to the
*/
/* @Override
public boolean addEdge(Edge arg0, java.util.Collection<? extends Vertex> arg1, EdgeType arg2) {
if(directed) {
return super.addEdge(arg0, arg1, EdgeType.DIRECTED);
} else {
return super.addEdge(arg0, arg1, EdgeType.UNDIRECTED);
}
};*/
@Override
public boolean addEdge(Edge e, Vertex v1, Vertex v2, EdgeType edge_type) {
if(findEdgeSet(v1, v2).size() > 0 && !multiGraph ) {
System.err.println("The graph does not allow parallel edges");
return false;
}
if(directed)
return super.addEdge(e, v1, v2, EdgeType.DIRECTED);
else
return super.addEdge(e, v1, v2, EdgeType.UNDIRECTED);
}
示例3: transform
public Paint transform(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.transform(b));
Point2D pf = transformer.transform(layout.transform(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.evaluate(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);
}
示例4: mouseReleased
/**
* If startVertex is non-null, and the mouse is released over an
* existing vertex, create an undirected edge from startVertex to
* the vertex under the mouse pointer. If shift was also pressed,
* create a directed edge instead.
*/
@SuppressWarnings("unchecked")
public void mouseReleased(MouseEvent e) {
if(checkModifiers(e)) {
final VisualizationViewer<V,E> vv =
(VisualizationViewer<V,E>)e.getSource();
final Point2D p = e.getPoint();
Layout<V,E> layout = vv.getModel().getGraphLayout();
GraphElementAccessor<V,E> pickSupport = vv.getPickSupport();
if(pickSupport != null) {
final V vertex = pickSupport.getVertex(layout, p.getX(), p.getY());
if(vertex != null && startVertex != null) {
Graph<V,E> graph =
vv.getGraphLayout().getGraph();
graph.addEdge(edgeFactory.create(),
startVertex, vertex, edgeIsDirected);
vv.repaint();
}
}
startVertex = null;
down = null;
edgeIsDirected = EdgeType.UNDIRECTED;
vv.removePostRenderPaintable(edgePaintable);
vv.removePostRenderPaintable(arrowPaintable);
}
}
示例5: createRandomEdge
private void createRandomEdge(Collection<V> preexistingNodes,
V newVertex, Set<Pair<V>> added_pairs) {
V attach_point;
boolean created_edge = false;
Pair<V> endpoints;
do {
attach_point = vertex_index.get(mRandom.nextInt(vertex_index.size()));
endpoints = new Pair<V>(newVertex, attach_point);
// // if parallel edges are not allowed, skip attach_point if <newVertex, attach_point>
// // already exists; note that because of the way edges are added, we only need to check
// // the list of candidate edges for duplicates.
// if (!(mGraph instanceof MultiGraph))
// {
// if (added_pairs.contains(endpoints))
// continue;
// if (mGraph.getDefaultEdgeType() == EdgeType.UNDIRECTED &&
// added_pairs.contains(new Pair<SubstrateNode>(attach_point, newVertex)))
// continue;
// }
double degree = mGraph.inDegree(attach_point);
// subtract 1 from numVertices because we don't want to count newVertex
// (which has already been added to the graph, but not to vertex_index)
double attach_prob = (degree + 1) / (mGraph.getEdgeCount() + mGraph.getVertexCount() - 1);
if (attach_prob >= mRandom.nextDouble())
created_edge = true;
}
while (!created_edge);
added_pairs.add(endpoints);
if (mGraph.getDefaultEdgeType() == EdgeType.UNDIRECTED) {
added_pairs.add(new Pair<V>(attach_point, newVertex));
}
}
示例6: evolveGraph
private void evolveGraph() {
Collection<V> preexistingNodes = mGraph.getVertices();
V newVertex = factory.createNode();
mGraph.addVertex(newVertex);
// generate and store the new edges; don't add them to the graph
// yet because we don't want to bias the degree calculations
// (all new edges in a timestep should be added in parallel)
Set<Pair<V>> added_pairs = new HashSet<Pair<V>>(mNumEdgesToAttachPerStep*3);
for (int i = 0; i < mNumEdgesToAttachPerStep; i++) {
createRandomEdge(preexistingNodes, newVertex, added_pairs);
}
for (Pair<V> pair : added_pairs)
{
V v1 = pair.getFirst();
V v2 = pair.getSecond();
if (mGraph.getDefaultEdgeType() != EdgeType.UNDIRECTED ||
!mGraph.isNeighbor(v1, v2))
mGraph.addEdge(factory.createEdge(), pair);
}
// now that we're done attaching edges to this new vertex,
// add it to the index
vertex_index.add(newVertex);
index_vertex.put(newVertex, new Integer(vertex_index.size() - 1));
}
示例7: MyGraph
/**
* Creates an instance.
*/
public MyGraph() {
super(EdgeType.UNDIRECTED);
vertices = new HashMap<>();
edges = new HashMap<>();
taxonNodeToVertexMap = new HashMap<>();
nodeIdsToEdgesMap = new HashMap<>();
}
示例8: mousePressed
/**
* If the mouse is pressed in an empty area, create a new vertex there.
* If the mouse is pressed on an existing vertex, prepare to create
* an edge from that vertex to another
*/
@SuppressWarnings("unchecked")
@Override
public void mousePressed(MouseEvent e) {
if (checkModifiers(e)) {
final VisualizationViewer<Vertex, Edge> vv = (VisualizationViewer<Vertex, Edge>) e.getSource();
final Point2D p = e.getPoint();
GraphElementAccessor<Vertex, Edge> pickSupport = vv.getPickSupport();
if (pickSupport != null) {
final Vertex vertex = pickSupport.getVertex(vv.getModel().getGraphLayout(), p.getX(), p.getY());
if (vertex != null) { // get ready to make an edge
creatingAnEdge = true;
Graph<Vertex, Edge> graph = vv.getModel().getGraphLayout().getGraph();
edgeType = (graph instanceof DirectedGraph) ? EdgeType.DIRECTED : EdgeType.UNDIRECTED;
if ((e.getModifiers() & MouseEvent.SHIFT_MASK) != 0 && graph instanceof UndirectedGraph == false) {
edgeType = EdgeType.DIRECTED;
}
super.mousePressed(e);
} else { // make a new vertex
creatingAnEdge = false;
Vertex newVertex = (Vertex) vertexFactory.create();
action = new CreateVertexUndoableAction(vv.getGraphLayout(), newVertex, vv.getRenderContext().getMultiLayerTransformer().inverseTransform(p));
action.execute();
UndoableControl.getController().actionExecuted(action);
}
}
}
}
示例9: addEdge
/**
* Below several method override the methods
* from BrowsableNetwork so that the directivity of the
* network matches with the direction parameter
* in this network
*/
@Override
public boolean addEdge(Edge arg0, java.util.Collection<? extends Vertex> arg1, EdgeType arg2) {
if(directed)
return super.addEdge(arg0, arg1, EdgeType.DIRECTED);
else
return super.addEdge(arg0, arg1, EdgeType.UNDIRECTED);
}
示例10: evaluate
public boolean evaluate(Context<Graph<V,E>,E> context)
{
Graph<V,E> graph = context.graph;
E e = context.element;
if (graph.getEdgeType(e) == EdgeType.DIRECTED && show_d) {
return true;
}
if (graph.getEdgeType(e) == EdgeType.UNDIRECTED && show_u) {
return true;
}
return false;
}
示例11: addEdge
@Override
public boolean addEdge(EdgeWrapper<E> edge, Pair<? extends V> endpoints, EdgeType edgeType) {
graphMatrix.setEdge(edge.getEdge(), endpoints.getFirst(), endpoints.getSecond());
if (edgeType == EdgeType.UNDIRECTED) {
graphMatrix.setEdge(edge.getEdge(), endpoints.getSecond(), endpoints.getFirst());
}
return true;
}
示例12: evaluate
@Override
public boolean evaluate(Context<Graph<V, E>, E> context) {
Graph<V, E> graph = context.graph;
E edge = context.element;
if (graph.getEdgeType(edge) == EdgeType.DIRECTED) {
return true;
}
if (graph.getEdgeType(edge) == EdgeType.UNDIRECTED) {
return true;
}
return true;
}
示例13: createRandomEdge
private void createRandomEdge(Collection<V> preexistingNodes,
V newVertex, Set<Pair<V>> added_pairs) {
V attach_point;
boolean created_edge = false;
Pair<V> endpoints;
do {
attach_point = vertex_index.get(mRandom.nextInt(vertex_index.size()));
endpoints = new Pair<V>(newVertex, attach_point);
// if parallel edges are not allowed, skip attach_point if <newVertex, attach_point>
// already exists; note that because of the way edges are added, we only need to check
// the list of candidate edges for duplicates.
if (!(mGraph instanceof MultiGraph))
{
if (added_pairs.contains(endpoints))
continue;
if (mGraph.getDefaultEdgeType() == EdgeType.UNDIRECTED &&
added_pairs.contains(new Pair<V>(attach_point, newVertex)))
continue;
}
double degree = mGraph.inDegree(attach_point);
// subtract 1 from numVertices because we don't want to count newVertex
// (which has already been added to the graph, but not to vertex_index)
double attach_prob = (degree + 1) / (mGraph.getEdgeCount() + mGraph.getVertexCount() - 1);
if (attach_prob >= mRandom.nextDouble())
created_edge = true;
}
while (!created_edge);
added_pairs.add(endpoints);
if (mGraph.getDefaultEdgeType() == EdgeType.UNDIRECTED) {
added_pairs.add(new Pair<V>(attach_point, newVertex));
}
}
示例14: evolveGraph
private void evolveGraph() {
Collection<V> preexistingNodes = mGraph.getVertices();
V newVertex = vertexFactory.create();
mGraph.addVertex(newVertex);
// generate and store the new edges; don't add them to the graph
// yet because we don't want to bias the degree calculations
// (all new edges in a timestep should be added in parallel)
Set<Pair<V>> added_pairs = new HashSet<Pair<V>>(mNumEdgesToAttachPerStep*3);
for (int i = 0; i < mNumEdgesToAttachPerStep; i++)
createRandomEdge(preexistingNodes, newVertex, added_pairs);
for (Pair<V> pair : added_pairs)
{
V v1 = pair.getFirst();
V v2 = pair.getSecond();
if (mGraph.getDefaultEdgeType() != EdgeType.UNDIRECTED ||
!mGraph.isNeighbor(v1, v2))
mGraph.addEdge(edgeFactory.create(), pair);
}
// now that we're done attaching edges to this new vertex,
// add it to the index
vertex_index.add(newVertex);
index_vertex.put(newVertex, new Integer(vertex_index.size() - 1));
}
示例15: toDirected
/**
* Transforms <code>graph</code> (which may be of any directionality)
* into a directed graph.
* Specifically:
* <ul>
* <li/>Vertices are copied from <code>graph</code>.
* <li/>Undirected edges are 'converted' into two new antiparallel directed edges in the new graph.
* <li/>Each directed edge (if any) in <code>graph</code> is 'recreated' with a new edge in the new
* graph if <code>create_new</code> is true, or copied from <code>graph</code> otherwise.
* </ul>
*
* @param graph the graph to be transformed
* @param create_new specifies whether existing directed edges are to be copied or recreated
* @param graph_factory used to create the new graph object
* @param edge_factory used to create new edges
* @return the transformed <code>Graph</code>
*/
public static <V,E> Graph<V,E> toDirected(Graph<V,E> graph, Factory<DirectedGraph<V,E>> graph_factory,
Factory<E> edge_factory, boolean create_new)
{
DirectedGraph<V,E> out = graph_factory.create();
for (V v : graph.getVertices())
out.addVertex(v);
for (E e : graph.getEdges())
{
Pair<V> endpoints = graph.getEndpoints(e);
if (graph.getEdgeType(e) == EdgeType.UNDIRECTED)
{
V v1 = endpoints.getFirst();
V v2 = endpoints.getSecond();
out.addEdge(edge_factory.create(), v1, v2, EdgeType.DIRECTED);
out.addEdge(edge_factory.create(), v2, v1, EdgeType.DIRECTED);
}
else // if the edge is directed, just add it
{
V source = graph.getSource(e);
V dest = graph.getDest(e);
E to_add = create_new ? edge_factory.create() : e;
out.addEdge(to_add, source, dest, EdgeType.DIRECTED);
}
}
return out;
}