当前位置: 首页>>代码示例>>Java>>正文


Java Hypergraph.getEdges方法代码示例

本文整理汇总了Java中edu.uci.ics.jung.graph.Hypergraph.getEdges方法的典型用法代码示例。如果您正苦于以下问题:Java Hypergraph.getEdges方法的具体用法?Java Hypergraph.getEdges怎么用?Java Hypergraph.getEdges使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在edu.uci.ics.jung.graph.Hypergraph的用法示例。


在下文中一共展示了Hypergraph.getEdges方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: writeEdgeData

import edu.uci.ics.jung.graph.Hypergraph; //导入方法依赖的package包/类
protected void writeEdgeData(Hypergraph<V,E> g, Writer w) throws IOException
{
	for (E e: g.getEdges())
	{
		Collection<V> vertices = g.getIncidentVertices(e);
		String id = edge_ids.transform(e);
		String e_string;
		boolean is_hyperedge = !(g instanceof Graph);
           if (is_hyperedge)
           {
               e_string = "<hyperedge ";
               // add ID if present
               if (id != null)
                   e_string += "id=\"" + id + "\" ";
           }
           else
		{
			Pair<V> endpoints = new Pair<V>(vertices);
			V v1 = endpoints.getFirst();
			V v2 = endpoints.getSecond();
			e_string = "<edge ";
			// add ID if present
			if (id != null)
				e_string += "id=\"" + id + "\" ";
			// add edge type if doesn't match default
			EdgeType edge_type = g.getEdgeType(e);
			if (directed && edge_type == EdgeType.UNDIRECTED)
				e_string += "directed=\"false\" ";
			if (!directed && edge_type == EdgeType.DIRECTED)
				e_string += "directed=\"true\" ";
			e_string += "source=\"" + vertex_ids.transform(v1) + 
				"\" target=\"" + vertex_ids.transform(v2) + "\"";
		}
		
		boolean closed = false;
		// write description out if any
		String desc = edge_desc.transform(e);
		if (desc != null)
		{
			w.write(e_string + ">\n");
			closed = true;
			w.write("<desc>" + desc + "</desc>\n");
		}
		// write data out if any
		for (String key : edge_data.keySet())
		{
			Transformer<E, ?> t = edge_data.get(key).transformer;
			Object value = t.transform(e);
			if (value != null)
			{
				if (!closed)
				{
					w.write(e_string + ">\n");
					closed = true;
				}
				w.write(format("data", "key", key, StringEscapeUtils.escapeXml(value.toString())) + "\n");
			}
		}
		// if this is a hyperedge, write endpoints out if any
		if (is_hyperedge)
		{
			for (V v : vertices)
			{
				if (!closed)
				{
					w.write(e_string + ">\n");
					closed = true;
				}
				w.write("<endpoint node=\"" + vertex_ids.transform(v) + "\"/>\n");
			}
		}
		
		if (!closed)
			w.write(e_string + "/>\n"); // no contents; close the edge with "/>"
		else
		    if (is_hyperedge)
		        w.write("</hyperedge>\n");
		    else
		        w.write("</edge>\n");
	}
}
 
开发者ID:iTransformers,项目名称:netTransformer,代码行数:82,代码来源:MyGraphMLWriter.java

示例2: foldHypergraphEdges

import edu.uci.ics.jung.graph.Hypergraph; //导入方法依赖的package包/类
/**
 * Creates a <code>Graph</code> which is an edge-folded version of <code>h</code>, where
 * hyperedges are replaced by k-cliques in the output graph.
 * 
 * <p>The vertices of the new graph are the same objects as the vertices of 
 * <code>h</code>, and <code>a</code> 
 * is connected to <code>b</code> in the new graph if the corresponding vertices
 * in <code>h</code> are connected by a hyperedge.  Thus, each hyperedge with 
 * <i>k</i> vertices in <code>h</code> induces a <i>k</i>-clique in the new graph.</p>
 * 
 * <p>The edges of the new graph consist of collections of each hyperedge that connected
 * the corresponding vertex pair in the original graph.</p>
 * 
 * @param <V> vertex type
 * @param <E> input edge type
 * @param h hypergraph to be folded
 * @param graph_factory factory used to generate the output graph
 * @return a copy of the input graph where hyperedges are replaced by cliques
 */
public static <V,E> Graph<V, Collection<E>> foldHypergraphEdges(Hypergraph<V,E> h, 
        Factory<Graph<V, Collection<E>>> graph_factory)
{
    Graph<V, Collection<E>> target = graph_factory.create();

    for (V v : h.getVertices())
        target.addVertex(v);
    
    for (E e : h.getEdges())
    {
        ArrayList<V> incident = new ArrayList<V>(h.getIncidentVertices(e));
        populateTarget(target, e, incident);
    }
    return target;
}
 
开发者ID:SiLeBAT,项目名称:BfROpenLab,代码行数:35,代码来源:FoldingTransformer.java

示例3: foldHypergraphVertices

import edu.uci.ics.jung.graph.Hypergraph; //导入方法依赖的package包/类
/**
 * Creates a <code>Graph</code> which is a vertex-folded version of <code>h</code>, whose
 * vertices are the input's hyperedges and whose edges are induced by adjacent hyperedges
 * in the input.
 * 
 * <p>The vertices of the new graph are the same objects as the hyperedges of 
 * <code>h</code>, and <code>a</code> 
 * is connected to <code>b</code> in the new graph if the corresponding edges
 * in <code>h</code> have a vertex in common.  Thus, each vertex incident to  
 * <i>k</i> edges in <code>h</code> induces a <i>k</i>-clique in the new graph.</p>
 * 
 * <p>The edges of the new graph are created by the specified factory.</p>
 * 
 * @param <V> vertex type
 * @param <E> input edge type
 * @param <F> output edge type
 * @param h hypergraph to be folded
 * @param graph_factory factory used to generate the output graph
 * @param edge_factory factory used to generate the output edges
 * @return a transformation of the input graph whose vertices correspond to the input's hyperedges 
 * and edges are induced by hyperedges sharing vertices in the input
 */
public static <V,E,F> Graph<E,F> foldHypergraphVertices(Hypergraph<V,E> h, 
        Factory<Graph<E,F>> graph_factory, Factory<F> edge_factory)
{
    Graph<E,F> target = graph_factory.create();
    
    for (E e : h.getEdges())
        target.addVertex(e);
    
    for (V v : h.getVertices())
    {
        ArrayList<E> incident = new ArrayList<E>(h.getIncidentEdges(v));
        for (int i = 0; i < incident.size(); i++)
            for (int j = i+1; j < incident.size(); j++)
                target.addEdge(edge_factory.create(), incident.get(i), incident.get(j));
    }
    
    return target;
}
 
开发者ID:SiLeBAT,项目名称:BfROpenLab,代码行数:41,代码来源:FoldingTransformer.java

示例4: writeEdgeData

import edu.uci.ics.jung.graph.Hypergraph; //导入方法依赖的package包/类
protected void writeEdgeData(Hypergraph<V,E> g, Writer w) throws IOException
{
	for (E e: g.getEdges())
	{
		Collection<V> vertices = g.getIncidentVertices(e);
		String id = edge_ids.transform(e);
		String e_string;
		boolean is_hyperedge = !(g instanceof Graph);
           if (is_hyperedge)
           {
               e_string = "<hyperedge ";
               // add ID if present
               if (id != null)
                   e_string += "id=\"" + id + "\" ";
           }
           else
		{
			Pair<V> endpoints = new Pair<V>(vertices);
			V v1 = endpoints.getFirst();
			V v2 = endpoints.getSecond();
			e_string = "<edge ";
			// add ID if present
			if (id != null)
				e_string += "id=\"" + id + "\" ";
			// add edge type if doesn't match default
			EdgeType edge_type = g.getEdgeType(e);
			if (directed && edge_type == EdgeType.UNDIRECTED)
				e_string += "directed=\"false\" ";
			if (!directed && edge_type == EdgeType.DIRECTED)
				e_string += "directed=\"true\" ";
			e_string += "source=\"" + vertex_ids.transform(v1) + 
				"\" target=\"" + vertex_ids.transform(v2) + "\"";
		}
		
		boolean closed = false;
		// write description out if any
		String desc = edge_desc.transform(e);
		if (desc != null)
		{
			w.write(e_string + ">\n");
			closed = true;
			w.write("<desc>" + desc + "</desc>\n");
		}
		// write data out if any
		for (String key : edge_data.keySet())
		{
			Transformer<E, ?> t = edge_data.get(key).transformer;
			Object value = t.transform(e);
			if (value != null)
			{
				if (!closed)
				{
					w.write(e_string + ">\n");
					closed = true;
				}
				w.write(format("data", "key", key, value.toString()) + "\n");
			}
		}
		// if this is a hyperedge, write endpoints out if any
		if (is_hyperedge)
		{
			for (V v : vertices)
			{
				if (!closed)
				{
					w.write(e_string + ">\n");
					closed = true;
				}
				w.write("<endpoint node=\"" + vertex_ids.transform(v) + "\"/>\n");
			}
		}
		
		if (!closed)
			w.write(e_string + "/>\n"); // no contents; close the edge with "/>"
		else
		    if (is_hyperedge)
		        w.write("</hyperedge>\n");
		    else
		        w.write("</edge>\n");
	}
}
 
开发者ID:SiLeBAT,项目名称:BfROpenLab,代码行数:82,代码来源:GraphMLWriter.java

示例5: fold

import edu.uci.ics.jung.graph.Hypergraph; //导入方法依赖的package包/类
/**
 * Creates a <code>Graph</code> which is a "folded" version of <code>h</code>.
 * 
 * <p>If <code>use_vertices</code> is true, the vertices of the new graph 
 * correspond to the vertices of <code>h</code>, and <code>a</code> 
 * is connected to <code>b</code> in the new graph if the corresponding vertices
 * in <code>h</code> are connected by a hyperedge.  Thus, each hyperedge with 
 * <i>k</i> vertices in <code>h</code> would induce a <i>k</i>-clique in the new graph.</p>
 * 
 * <p>If <code>use_vertices</code> is false, then the vertices of the new
 * graph correspond to the hyperedges of <code>h</code>, and <code>a</code>
 * is connected to <code>b</code> in the new graph if the corresponding hyperedges
 * in <code>h</code> share a vertex.  Thus, each vertex connected to <i>k</i> 
 * hyperedges in <code>h</code> would induce a <i>k</i>-clique in the new graph.</p>
 * 
 * <p>If <code>nev</code> is null, 
 * adds the connecting element as a decoration on the corresponding edge in the new
 * graph; otherwise, sets the weight of each edge to the number of parallel 
 * paths between the corresponding vertices in the original graph that are 
 * encountered in the folding process.</p>
 */
public Graph fold(Hypergraph h, Graph target, boolean use_vertices, NumberEdgeValue nev, BidiMap map)
{
    undirected = true;
    
    if (target == null)
        target = createGraph();

    VertexGenerator vg = GraphUtils.getVertexGenerator(target);
    if (vg == null)
        vg = new TypedVertexGenerator(target);
    
    Map m = new HashMap();
    Set vertices;
    Set edges;
    
    // vertices and hyperedges are duals of one another; we can treat
    // them equivalently for this purpose
    if (use_vertices)
    {
        vertices = h.getVertices();
        edges = h.getEdges();
    }
    else
    {
        vertices = h.getEdges();
        edges = h.getVertices();
    }
    
    // create vertices:
    // for each "vertex", create a new vertex and import user data
    for (Iterator iter = vertices.iterator(); iter.hasNext(); )
    {
        Element av = (Element)iter.next();
        Vertex v = vg.create();
        v.importUserData(av);
        target.addVertex(v);
        m.put(av, v);
        map.put(v, av);
    }
    
    // create edges:
    // for each "hyperedge", create an edge between each incident vertex pair
    for (Iterator iter = edges.iterator(); iter.hasNext(); )
    {
        Element he = (Element)iter.next();
        Set elts = he.getIncidentElements();
        Vertex[] v_array = new Vertex[elts.size()];
        int i = 0;
        for (Iterator e_iter = elts.iterator(); e_iter.hasNext(); )
            v_array[i++] = (Vertex)(m.get(e_iter.next()));
        for (i = 0; i < v_array.length; i++)
            for (int j = i + 1; j < v_array.length; j++)
                addEdge(target, v_array[i], he, v_array[j], nev);
    }
    
    return target;
}
 
开发者ID:markus1978,项目名称:clickwatch,代码行数:79,代码来源:FoldingTransformer.java


注:本文中的edu.uci.ics.jung.graph.Hypergraph.getEdges方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。