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


Java WeightedGraph.setEdgeWeight方法代码示例

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


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

示例1: getWeightedGraph

import org.jgrapht.WeightedGraph; //导入方法依赖的package包/类
/**
 * Convert FNSS Topology to JGraphT weighted graph.
 * 
 * The weights assigned to the edges of the returned graph are the link
 * weights of the original FNSS topology. If the topology object does not
 * have weights assigned, all nodes are assigned a weight equal to 1.
 * 
 * Because of the specific limitations of JGraphT, the edges of the returned
 * graph must be instances of JGraphT <code>DefaultWeightedEdge</code>, and
 * do not hold capacity, buffer sizes and delay information possibly present
 * in the original FNSS Topology. The returned graph maintains however
 * link weight information.
 * 
 * See examples for further information.
 * 
 * @param topology FNSS Topology object
 * @return A JGraphT weighted graph
 */
public static WeightedGraph<String, DefaultWeightedEdge> getWeightedGraph(Topology topology) {
	WeightedGraph<String, DefaultWeightedEdge> graph = null;
	if (topology.isDirected()) {
		graph = new SimpleDirectedWeightedGraph<String, DefaultWeightedEdge>(DefaultWeightedEdge.class);
	} else {
		graph = new SimpleWeightedGraph<String, DefaultWeightedEdge>(DefaultWeightedEdge.class);
	}
	for(String node : topology.getAllNodes()) {
		graph.addVertex(node);
	}
	for(Pair<String, String> endpoints : topology.getAllEdges()) {
		float weight = topology.getEdge(endpoints).getWeight();
		DefaultWeightedEdge edge = new DefaultWeightedEdge();
		graph.addEdge(endpoints.getU(), endpoints.getV(), edge);
		graph.setEdgeWeight(edge, weight);
	}
	return graph;
}
 
开发者ID:fnss,项目名称:fnss-java,代码行数:37,代码来源:JGraphTConverter.java

示例2: generateZoneGraph

import org.jgrapht.WeightedGraph; //导入方法依赖的package包/类
public static WeightedGraph<NdPoint, DefaultWeightedEdge> generateZoneGraph(Collection<Zone> allZones) {
    WeightedGraph<NdPoint, DefaultWeightedEdge> graph = new SimpleWeightedGraph<NdPoint, DefaultWeightedEdge>(
            DefaultWeightedEdge.class);
    for (Zone p : allZones) {
        graph.addVertex(p.getLocation());
    }
    for (Zone p1 : allZones) {
        for (Zone p2 : p1.getNeighbours()) {
            DefaultWeightedEdge edge = graph.addEdge(p1.getLocation(), p2.getLocation());
            /**
             * If we get edge==null, the edge already has been added.
             */
            if (edge != null) {
                graph.setEdgeWeight(edge, p1.distanceTo(p2));
            }
        }
    }

    return graph;
}
 
开发者ID:eishub,项目名称:BW4T,代码行数:21,代码来源:GraphHelper.java

示例3: weightedDirectedGraph

import org.jgrapht.WeightedGraph; //导入方法依赖的package包/类
/**
 * Create a simple directed graph.
 */
@SuppressWarnings("boxing")
public static WeightedGraph<Integer, DefaultWeightedEdge> weightedDirectedGraph()
{
	final WeightedGraph<Integer, DefaultWeightedEdge> g = new SimpleWeightedGraph<>(
			DefaultWeightedEdge.class);

	final Set<Integer> vertices = CollectionUtil.toSet(7, 5, 3, 11, 8, 2, 9, 10);
	for (final Integer v : vertices)
	{
		g.addVertex(v);
	}

	final DefaultWeightedEdge e = g.addEdge(7, 8);
	g.setEdgeWeight(e, 1.0d);

	return g;
}
 
开发者ID:openfurther,项目名称:further-open-core,代码行数:21,代码来源:GraphTestUtil.java

示例4: testGraphIO

import org.jgrapht.WeightedGraph; //导入方法依赖的package包/类
@Test
public void testGraphIO()
		throws IOException, CASException, ClassNotFoundException, InstantiationException, IllegalAccessException,
		IllegalArgumentException, InvocationTargetException, NoSuchMethodException, SecurityException {
	WeightedGraph<Figure, DefaultWeightedEdge> graph = new SimpleWeightedGraph<Figure, DefaultWeightedEdge>(
			DefaultWeightedEdge.class);
	for (int i = 0; i < figures.length; i++) {
		graph.addVertex(figures[i]);
	}
	for (int i = 0; i < figures.length - 1; i++) {
		DefaultWeightedEdge edge = graph.addEdge(figures[i], figures[i + 1]);
		graph.setEdgeWeight(edge, random.nextDouble());
	}

	GraphExporter ge = new GraphExporter();
	ge.export(jcas.createView("Testview"), graph);

	Graph<Figure, DefaultWeightedEdge> g2 = GraphImporter.getGraph(jcas, "Testview");

	assertNotNull(g2);
	assertFalse(g2.vertexSet().isEmpty());
	for (int i = 0; i < figures.length; i++) {
		for (int j = 0; j < figures.length; j++) {
			assertEquals(graph.containsEdge(figures[i], figures[j]), g2.containsEdge(figures[i], figures[j]));
			if (graph.containsEdge(figures[i], figures[j])) {
				assertEquals(graph.getEdgeWeight(graph.getEdge(figures[i], figures[j])),
						g2.getEdgeWeight(g2.getEdge(figures[i], figures[j])), 0.1);
			}
		}
	}

}
 
开发者ID:quadrama,项目名称:DramaNLP,代码行数:33,代码来源:TestGraphIO.java


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