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


Java DefaultWeightedEdge类代码示例

本文整理汇总了Java中org.jgrapht.graph.DefaultWeightedEdge的典型用法代码示例。如果您正苦于以下问题:Java DefaultWeightedEdge类的具体用法?Java DefaultWeightedEdge怎么用?Java DefaultWeightedEdge使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: getWeightedGraph

import org.jgrapht.graph.DefaultWeightedEdge; //导入依赖的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: edgeUseGraph

import org.jgrapht.graph.DefaultWeightedEdge; //导入依赖的package包/类
public static void edgeUseGraph(OSMResource way, List<Long> wayComposition, HashMap<Long, OSMObject> nodeOSMObjects,
		DefaultDirectedWeightedGraph<Long, DefaultWeightedEdge> g) {
	for (Long nodeId : wayComposition) {
		OSMObject nodeObject = nodeOSMObjects.get(nodeId);
		// Look for the right node version that matches way input
		boolean before = true;
		int i = 0;
		if (nodeObject == null)
			// Cas où le way est composé d'un noeud qui n'a pas été chargé:
			// celui-ci a dû être supprimé après coup
			continue; // Ou interroger la base de données ?

		if (nodeObject.getContributions().size() > 0) {
			while (before && ((i + 1) < nodeObject.getContributions().size())) {
				if (nodeObject.getContributions().get(i).getDate().after(way.getDate()))
					before = false;
				else
					i++;
			}
			if (nodeObject.getContributions().get(i).getUid() != way.getUid())
				addEdgeUseGraph(g, (long) way.getUid(), (long) nodeObject.getContributions().get(i).getUid());
		}
	}
}
 
开发者ID:IGNF,项目名称:geoxygene,代码行数:25,代码来源:SocialGraph.java

示例3: getMaxEdge

import org.jgrapht.graph.DefaultWeightedEdge; //导入依赖的package包/类
public static void getMaxEdge(DefaultDirectedWeightedGraph<Long, DefaultWeightedEdge> g,
		DefaultDirectedWeightedGraph<Long, DefaultWeightedEdge> subg) {
	Collection<DefaultWeightedEdge> edges = subg.edgeSet();
	for (DefaultWeightedEdge edge : edges) {
		if (!g.containsEdge(subg.getEdgeSource(edge), subg.getEdgeTarget(edge))) {
			g.addEdge(subg.getEdgeSource(edge), subg.getEdgeTarget(edge));
			DefaultWeightedEdge newEdge = g.getEdge(subg.getEdgeSource(edge), subg.getEdgeTarget(edge));
			g.setEdgeWeight(newEdge, subg.getEdgeWeight(edge));
		} else {
			DefaultWeightedEdge existingEdge = g.getEdge(subg.getEdgeSource(edge), subg.getEdgeTarget(edge));
			double depthIni = g.getEdgeWeight(existingEdge);
			double depthToCompare = subg.getEdgeWeight(edge);
			g.setEdgeWeight(existingEdge, Math.max(depthIni, depthToCompare));
		}
	}
}
 
开发者ID:IGNF,项目名称:geoxygene,代码行数:17,代码来源:SocialGraph.java

示例4: mergeGraph

import org.jgrapht.graph.DefaultWeightedEdge; //导入依赖的package包/类
public static void mergeGraph(DefaultDirectedWeightedGraph<Long, DefaultWeightedEdge> g1,
		DefaultDirectedWeightedGraph<Long, DefaultWeightedEdge> g2) {
	Collection<DefaultWeightedEdge> edges = g2.edgeSet();
	for (DefaultWeightedEdge edge : edges) {
		if (!g1.containsVertex(g2.getEdgeTarget(edge)))
			g1.addVertex(g2.getEdgeTarget(edge));
		if (!g1.containsVertex(g2.getEdgeSource(edge)))
			g1.addVertex(g2.getEdgeSource(edge));
		if (!g1.containsEdge(g2.getEdgeSource(edge), g2.getEdgeTarget(edge))) {
			g1.addEdge(g2.getEdgeSource(edge), g2.getEdgeTarget(edge));
			DefaultWeightedEdge newEdge = g1.getEdge(g2.getEdgeSource(edge), g2.getEdgeTarget(edge));
			g1.setEdgeWeight(newEdge, g2.getEdgeWeight(edge));
		} else {
			DefaultWeightedEdge existingEdge = g1.getEdge(g2.getEdgeSource(edge), g2.getEdgeTarget(edge));
			g1.setEdgeWeight(existingEdge, g1.getEdgeWeight(existingEdge) + g2.getEdgeWeight(edge));
		}
	}
}
 
开发者ID:IGNF,项目名称:geoxygene,代码行数:19,代码来源:SocialGraph.java

示例5: writeGraph2CSV

import org.jgrapht.graph.DefaultWeightedEdge; //导入依赖的package包/类
/**
	 * Warning: use writeColocationGraph2CSV to export colocation graphs into
	 * CSV files.
	 */
	public static void writeGraph2CSV(DefaultDirectedWeightedGraph<Long, DefaultWeightedEdge> usegraph, File file)
			throws IOException {
		CSVWriter writer = new CSVWriter(new FileWriter(file), ';');
//		System.out.println("écriture du fichier csv");
		// write header
		String[] line = new String[3];
		line[0] = "source";
		line[1] = "target";
		line[2] = "weight";
		writer.writeNext(line);
		for (DefaultWeightedEdge e : usegraph.edgeSet()) {
			line = new String[3];
			line[0] = String.valueOf(usegraph.getEdgeSource(e).longValue() + (long) 111);
			line[1] = String.valueOf(usegraph.getEdgeTarget(e).longValue() + (long) 111);
			line[2] = String.valueOf(usegraph.getEdgeWeight(e));
			writer.writeNext(line);
		}
		writer.close();
	}
 
开发者ID:IGNF,项目名称:geoxygene,代码行数:24,代码来源:SocialGraph.java

示例6: writeSimpleWeightedGraph2CSV

import org.jgrapht.graph.DefaultWeightedEdge; //导入依赖的package包/类
public static void writeSimpleWeightedGraph2CSV(SimpleWeightedGraph<Long, DefaultWeightedEdge> colocationgraph,
		File file) throws IOException {
	CSVWriter writer = new CSVWriter(new FileWriter(file), ';');
	// write header
	String[] line = new String[4];
	line[0] = "source";
	line[1] = "target";
	line[2] = "weight";
	line[3] = "type";
	writer.writeNext(line);
	for (DefaultWeightedEdge e : colocationgraph.edgeSet()) {
		line = new String[4];
		line[0] = String.valueOf(colocationgraph.getEdgeSource(e).longValue() + (long) 111);
		line[1] = String.valueOf(colocationgraph.getEdgeTarget(e).longValue() + (long) 111);
		line[2] = String.valueOf(colocationgraph.getEdgeWeight(e));
		line[3] = "undirected";
		writer.writeNext(line);
	}
	writer.close();
}
 
开发者ID:IGNF,项目名称:geoxygene,代码行数:21,代码来源:SocialGraph.java

示例7: participationCoefficient

import org.jgrapht.graph.DefaultWeightedEdge; //导入依赖的package包/类
public static HashMap<Long, Double> participationCoefficient(
		SimpleWeightedGraph<Long, DefaultWeightedEdge> simpleG1,
		SimpleWeightedGraph<Long, DefaultWeightedEdge> simpleG2,
		SimpleWeightedGraph<Long, DefaultWeightedEdge> simpleG3,
		SimpleWeightedGraph<Long, DefaultWeightedEdge> simpleG4, HashMap<Long, Long> overlappingDegList) {
	// nbLayer/(nbLayer-1)
	Double m = Double.valueOf(4) / Double.valueOf(3);
	HashMap<Long, Double> participationList = new HashMap<Long, Double>();
	for (Long v : simpleG1.vertexSet()) {
		Double overlap = Double.valueOf(overlappingDegList.get(v));
		if (overlap == 0)
			continue;
		Double m1 = Double.valueOf(simpleG1.degreeOf(v)) / overlap;
		Double m2 = Double.valueOf(simpleG2.degreeOf(v)) / overlap;
		Double m3 = Double.valueOf(simpleG3.degreeOf(v)) / overlap;
		Double m4 = Double.valueOf(simpleG4.degreeOf(v)) / overlap;
		Double sum = m1 * m1 + m2 * m2 + m3 * m3 + m4 * m4;
		Double pcoeff = m * (1 - sum);
		participationList.put(v, pcoeff);
		// System.out.println("Utilisateur : " + v + " - participation coeff
		// : " + (double) pcoeff);
	}
	return participationList;
}
 
开发者ID:IGNF,项目名称:geoxygene,代码行数:25,代码来源:GraphAnalysis.java

示例8: createSimpleAdjacencyMatrix

import org.jgrapht.graph.DefaultWeightedEdge; //导入依赖的package包/类
/**
 * creates the adjacency matrix of a simple weighted graph
 **/
public static double[][] createSimpleAdjacencyMatrix(SimpleWeightedGraph<Long, DefaultWeightedEdge> simpleG,
		double threshold) {
	HashMap<Long, Integer> contributorIndex = contributorIndex(simpleG);
	// Crée une matrice de taille nbContributeurs x nbContributeurs
	// initialisés à zéro par défaut
	double[][] adj = new double[simpleG.vertexSet().size()][simpleG.vertexSet().size()];
	for (DefaultWeightedEdge e : simpleG.edgeSet()) {
		Long nodeI = simpleG.getEdgeSource(e);
		Long nodeF = simpleG.getEdgeTarget(e);
		double w = simpleG.getEdgeWeight(e);
		// Remplit la matrice symétrique
		int j = contributorIndex.get(nodeI);
		int k = contributorIndex.get(nodeF);
		if (w >= threshold) {
			adj[j][k] = 1;
			adj[k][j] = 1;
		}
	}
	return adj;
}
 
开发者ID:IGNF,项目名称:geoxygene,代码行数:24,代码来源:GraphAnalysis.java

示例9: createInteractionMatrix

import org.jgrapht.graph.DefaultWeightedEdge; //导入依赖的package包/类
public static double[][] createInteractionMatrix(SimpleWeightedGraph<Long, DefaultWeightedEdge> simpleG) {
	HashMap<Long, Integer> contributorIndex = new HashMap<Long, Integer>();
	int i = 0;
	for (Long v : simpleG.vertexSet()) {
		contributorIndex.put(v, i);
		// System.out.println("Ajout de l'utilisateur " + v + " indice " +
		// i);
		i++;
	}
	// Crée une matrice de taille nbContributeurs x nbContributeurs
	// initialisés à zéro par défaut
	double[][] adj = new double[simpleG.vertexSet().size()][simpleG.vertexSet().size()];
	for (DefaultWeightedEdge e : simpleG.edgeSet()) {
		Long nodeI = simpleG.getEdgeSource(e);
		Long nodeF = simpleG.getEdgeTarget(e);
		double w = simpleG.getEdgeWeight(e);
		// Remplit la matrice symétrique
		int j = contributorIndex.get(nodeI);
		int k = contributorIndex.get(nodeF);
		adj[j][k] = w;
		adj[k][j] = w;
	}
	return adj;
}
 
开发者ID:IGNF,项目名称:geoxygene,代码行数:25,代码来源:GraphAnalysis.java

示例10: createMultiplexAdjacencyMatrix

import org.jgrapht.graph.DefaultWeightedEdge; //导入依赖的package包/类
/**
 * creates the adjacency matrix of a multiplex system composed of 4 simple
 * weighted graphs
 **/
public static ArrayList<double[][]> createMultiplexAdjacencyMatrix(
		SimpleWeightedGraph<Long, DefaultWeightedEdge> simpleG1,
		SimpleWeightedGraph<Long, DefaultWeightedEdge> simpleG2,
		SimpleWeightedGraph<Long, DefaultWeightedEdge> simpleG3,
		SimpleWeightedGraph<Long, DefaultWeightedEdge> simpleG4) {
	double[][] adjG1 = createSimpleAdjacencyMatrix(simpleG1, 1);
	double[][] adjG2 = createSimpleAdjacencyMatrix(simpleG2, 1);
	double[][] adjG3 = createSimpleAdjacencyMatrix(simpleG3, 1);
	double[][] adjG4 = createSimpleAdjacencyMatrix(simpleG4, 0);
	ArrayList<double[][]> adjMultiplex = new ArrayList<double[][]>();
	adjMultiplex.add(adjG1);
	adjMultiplex.add(adjG2);
	adjMultiplex.add(adjG3);
	adjMultiplex.add(adjG4);
	return adjMultiplex;

}
 
开发者ID:IGNF,项目名称:geoxygene,代码行数:22,代码来源:GraphAnalysis.java

示例11: addGraph

import org.jgrapht.graph.DefaultWeightedEdge; //导入依赖的package包/类
public static DirectedWeightedMultigraph<Long, RelationshipEdge> addGraph(
		DefaultDirectedWeightedGraph<Long, DefaultWeightedEdge> g, String label,
		DirectedWeightedMultigraph<Long, RelationshipEdge> graph) {
	System.out.println("Add Graph");
	for (Long vertex : g.vertexSet()) {
		graph.addVertex(vertex);
	}
	for (DefaultWeightedEdge e : g.edgeSet()) {
		graph.addEdge(g.getEdgeSource(e), g.getEdgeTarget(e),
				new RelationshipEdge<Long>(g.getEdgeSource(e), g.getEdgeTarget(e), label));
		RelationshipEdge<Long> edge = graph.getEdge(g.getEdgeSource(e), g.getEdgeTarget(e));
		graph.setEdgeWeight(edge, g.getEdgeWeight(e));
		System.out.println("Edge added");
	}
	return graph;
}
 
开发者ID:IGNF,项目名称:geoxygene,代码行数:17,代码来源:LabeledEdges.java

示例12: mitosis

import org.jgrapht.graph.DefaultWeightedEdge; //导入依赖的package包/类
@Override
public List<IMST<T>> mitosis() throws Exception {
  double largestWeight = 0;
  DefaultWeightedEdge largestEdge = null;
  List<DefaultWeightedEdge> edges = new ArrayList<>();
  edges.addAll(mst.edgeSet());
  Collections.sort(edges, (el1, el2) -> graph.getEdgeSource(el1).getValue()
      .compareTo(graph.getEdgeSource(el2).getValue()));
  for (DefaultWeightedEdge edge : edges) {
    if (mst.getEdgeWeight(edge) > largestWeight) {
      largestWeight = mst.getEdgeWeight(edge);
      largestEdge = edge;
    }
  }
  List<IMST<T>> newGraphs = new ArrayList<>();
  mst.removeEdge(largestEdge);
  newGraphs.add(createSubGraph(mst, mst.getEdgeSource(largestEdge)));
  newGraphs.add(createSubGraph(mst, mst.getEdgeTarget(largestEdge)));
  return newGraphs;
}
 
开发者ID:vitrivr,项目名称:cineast,代码行数:21,代码来源:MST.java

示例13: getMST

import org.jgrapht.graph.DefaultWeightedEdge; //导入依赖的package包/类
private SimpleWeightedGraph<MSTNode<T>, DefaultWeightedEdge> getMST() {
  if (graph.vertexSet().size() == 1)
   {
    return graph; // PrimMinimum
  }

  SpanningTree<DefaultWeightedEdge> internMst = new KruskalMinimumSpanningTree<>(graph)
      .getSpanningTree();
  Set<DefaultWeightedEdge> edges = internMst.getEdges();
  Set<MSTNode<T>> nodes = graph.vertexSet();
  SimpleWeightedGraph<MSTNode<T>, DefaultWeightedEdge> internSWG = new SimpleWeightedGraph<>(
      DefaultWeightedEdge.class);
  for (MSTNode<T> node : nodes) {
    internSWG.addVertex(node);
  }
  for (DefaultWeightedEdge dwe : edges) {
    DefaultWeightedEdge newEdge = internSWG.addEdge(graph.getEdgeSource(dwe),
        graph.getEdgeTarget(dwe));
    internSWG.setEdgeWeight(newEdge, graph.getEdgeWeight(dwe));
  }
  return internSWG;
}
 
开发者ID:vitrivr,项目名称:cineast,代码行数:23,代码来源:MST.java

示例14: build

import org.jgrapht.graph.DefaultWeightedEdge; //导入依赖的package包/类
/**
 * Builds a simple weighted graph
 * @param data The input list of tuples each holds two indices and distance between them
 */
public static Graph<Integer, DefaultWeightedEdge> build(List<Tuple3<Integer, Integer, Double>> data) {

	// initialize a weighted graph
	Graph<Integer, DefaultWeightedEdge> graph = new SimpleWeightedGraph<Integer, DefaultWeightedEdge>(DefaultWeightedEdge.class);

	// add vertices and edges to the weighted graph
	for (Tuple3<Integer, Integer, Double> t : data) {

		int i = t._1();
		int j = t._2();
		double score = t._3();

		graph.addVertex(i);
		graph.addVertex(j);
		DefaultWeightedEdge e = graph.addEdge(i, j);
		((AbstractBaseGraph<Integer, DefaultWeightedEdge>) graph).setEdgeWeight(e, score);

	}
	return graph;
}
 
开发者ID:biojava,项目名称:biojava-spark,代码行数:25,代码来源:WeightedGraph.java

示例15: getMinimumSpanningTree

import org.jgrapht.graph.DefaultWeightedEdge; //导入依赖的package包/类
/**
 * Builds a graph that contains a Minimum Spanning Tree
 * @param graph The input weighted graph
 */
public static Graph<Integer, DefaultWeightedEdge> getMinimumSpanningTree(Graph<Integer, DefaultWeightedEdge> graph) {

	// get the edges of a Minimum Spanning Tree generated for a weighted graph
	PrimMinimumSpanningTree<Integer, DefaultWeightedEdge> tree = new PrimMinimumSpanningTree<Integer, DefaultWeightedEdge>(graph);
	Set<DefaultWeightedEdge> mspEdges = tree.getMinimumSpanningTreeEdgeSet();

	// build a new graph from the MST edges
	Graph<Integer, DefaultWeightedEdge> mspGraph = new SimpleWeightedGraph<Integer, DefaultWeightedEdge>(DefaultWeightedEdge.class);

	for (DefaultWeightedEdge e : mspEdges) {

		int sourceV = graph.getEdgeSource(e);
		int targetV = graph.getEdgeTarget(e);

		mspGraph.addVertex(sourceV);
		mspGraph.addVertex(targetV);

		DefaultWeightedEdge edge = graph.getEdge(sourceV, targetV);
		double w = graph.getEdgeWeight(edge);
		mspGraph.addEdge(sourceV, targetV, edge);
		((AbstractBaseGraph<Integer, DefaultWeightedEdge>) mspGraph).setEdgeWeight(edge, w);
	}

	return mspGraph;
}
 
开发者ID:biojava,项目名称:biojava-spark,代码行数:30,代码来源:WeightedGraph.java


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