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


Java SimpleWeightedGraph.addEdge方法代码示例

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


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

示例1: getMST

import org.jgrapht.graph.SimpleWeightedGraph; //导入方法依赖的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

示例2: directedGraph2simpleGraph

import org.jgrapht.graph.SimpleWeightedGraph; //导入方法依赖的package包/类
/**
 * converts a directed weighted graph into a simple weighted graph by
 * keeping the maximum weight of 2 parallel edges
 */
public static SimpleWeightedGraph<Long, DefaultWeightedEdge> directedGraph2simpleGraph(
		DefaultDirectedWeightedGraph<Long, DefaultWeightedEdge> directedG) {
	SimpleWeightedGraph<Long, DefaultWeightedEdge> simpleG = new SimpleWeightedGraph<Long, DefaultWeightedEdge>(
			DefaultWeightedEdge.class);
	// Parcourt les sommets du graphe orienté et les copie dans le graphe
	// simple
	for (Long v : directedG.vertexSet()) {
		simpleG.addVertex(v);
	}
	// Parcourt l'ensemble des arcs du graphe orienté
	for (DefaultWeightedEdge e : directedG.edgeSet()) {
		Long nodeIni = directedG.getEdgeSource(e);
		Long nodeFin = directedG.getEdgeTarget(e);
		double w = directedG.getEdgeWeight(e);
		if (!simpleG.containsEdge(nodeIni, nodeFin)) {
			simpleG.addEdge(nodeIni, nodeFin, e);
		} else {
			// On prend le poids max de deux arcs parallèles
			DefaultWeightedEdge e1 = simpleG.getEdge(nodeFin, nodeIni);
			if (simpleG.getEdgeWeight(e1) < w)
				simpleG.setEdgeWeight(e1, w);
		}
	}
	System.out.println("Graphe simple créé : " + simpleG.vertexSet().size() + " sommets et "
			+ simpleG.edgeSet().size() + " arcs");
	// for (DefaultWeightedEdge e : simpleG.edgeSet()) {
	// if (simpleG.getEdgeSource(e) == (long) 210173)
	// System.out.println(
	// "Source 210173 - Target " + simpleG.getEdgeTarget(e) + " - Poids " +
	// simpleG.getEdgeWeight(e));
	// }
	return simpleG;
}
 
开发者ID:IGNF,项目名称:geoxygene,代码行数:38,代码来源:GraphAnalysis.java

示例3: monoplex

import org.jgrapht.graph.SimpleWeightedGraph; //导入方法依赖的package包/类
public static SimpleWeightedGraph<Long, DefaultWeightedEdge> monoplex(
		ArrayList<double[][]> multiplexAdjacencyMatrix, HashMap<Long, Integer> contributorIndex) {
	SimpleWeightedGraph<Long, DefaultWeightedEdge> simpleG = new SimpleWeightedGraph<Long, DefaultWeightedEdge>(
			DefaultWeightedEdge.class);
	// Parcourt les sommets du graphe orienté et les copie dans le graphe
	// simple
	for (Long v : contributorIndex.keySet()) {
		simpleG.addVertex(v);
	}

	// Add edges
	int nbContributors = multiplexAdjacencyMatrix.get(0).length;
	int dim = multiplexAdjacencyMatrix.size();
	System.out.println("nb contributors = " + nbContributors + "; nb dimensions = " + dim);

	for (int i = 0; i < nbContributors - 1; i++) {
		Long uid1 = (Long) contributorIndex.keySet().toArray()[i];
		for (int j = i + 1; j < nbContributors; j++) {
			Long uid2 = (Long) contributorIndex.keySet().toArray()[j];
			int sum = 0;

			for (int d = 0; d < dim; d++) {
				sum += multiplexAdjacencyMatrix.get(d)[i][j];
			}
			if (sum == 0)
				continue;

			DefaultWeightedEdge e = simpleG.addEdge(uid1, uid2);
			simpleG.setEdgeWeight(e, (double) sum);
		}

	}
	return simpleG;

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

示例4: extractNetwork

import org.jgrapht.graph.SimpleWeightedGraph; //导入方法依赖的package包/类
protected WeightedGraph<Figure, DefaultWeightedEdge> extractNetwork(JCas jcas, Annotation range) {
	SimpleWeightedGraph<Figure, DefaultWeightedEdge> graph = new SimpleWeightedGraph<Figure, DefaultWeightedEdge>(
			DefaultWeightedEdge.class);
	for (Figure figure : JCasUtil.select(jcas, Figure.class)) {

		if (!graph.containsVertex(figure)) {
			graph.addVertex(figure);
		}
	}

	for (Scene scene : JCasUtil.select(jcas, Scene.class)) {
		List<Speaker> speakers = JCasUtil.selectCovered(Speaker.class, scene);
		for (Speaker s1 : speakers) {
			Figure gf1 = s1.getFigure();
			if (gf1 != null)
				for (Speaker s2 : speakers) {
					Figure gf2 = s2.getFigure();
					if (gf2 != null)
						if (graph.containsEdge(gf1, gf2)) {
							DefaultWeightedEdge edge = graph.getEdge(gf1, gf2);
							double w = graph.getEdgeWeight(edge);
							graph.setEdgeWeight(edge, w + 1.0);
						} else {
							if (gf1 != gf2)
								graph.addEdge(gf1, gf2);
						}
				}
		}
		;
	}
	return graph;
}
 
开发者ID:quadrama,项目名称:DramaNLP,代码行数:33,代码来源:NetworkExtractor.java

示例5: createCoLocationGraph

import org.jgrapht.graph.SimpleWeightedGraph; //导入方法依赖的package包/类
public static SimpleWeightedGraph<Long, DefaultWeightedEdge> createCoLocationGraph(
		HashMap<Long, OSMContributor> myOSMContributors, List<Double> bbox, List<String> timespan, double threshold)
		throws Exception {
	SimpleWeightedGraph<Long, DefaultWeightedEdge> g = new SimpleWeightedGraph<Long, DefaultWeightedEdge>(
			DefaultWeightedEdge.class);
	// Remplit pour chaque OSMContributor l'attribut ActivityAreas
	assignActivityAreas(myOSMContributors, bbox, timespan, threshold);
	List<OSMContributor> myContributorList = new ArrayList<OSMContributor>();
	for (OSMContributor contributor : myOSMContributors.values()) {
		myContributorList.add(contributor);
	}
	// Parcourt la liste des contributeurs
	for (int i = 0; i < myContributorList.size() - 1; i++) {
		IFeatureCollection<DefaultFeature> areaCurrentContributor = myContributorList.get(i).getActivityAreas();
		if (areaCurrentContributor == null)
			continue;
		if (!g.containsVertex((long) myContributorList.get(i).getId()))
			g.addVertex((long) myContributorList.get(i).getId());
		// Parcourt les contributeurs suivants de la liste
		for (int j = i + 1; j < myOSMContributors.size(); j++) {
			if (!g.containsVertex((long) myContributorList.get(j).getId()))
				g.addVertex((long) myContributorList.get(j).getId());
			IFeatureCollection<DefaultFeature> areaNextContributor = myContributorList.get(j).getActivityAreas();
			if (areaNextContributor == null)
				continue;
			double totalDistance = 0;
			// Parcourt les zones d'activité du contributeur courant
			for (int u = 0; u < areaCurrentContributor.size(); u++) {
				IGeometry currentZone = areaCurrentContributor.get(u).getGeom();
				// Parcourt les zones d'activité du contributeur suivant
				for (int v = 0; v < areaCurrentContributor.size(); v++) {
					IGeometry nextZone = areaCurrentContributor.get(v).getGeom();
					// Calcul de la distance surfacique s'il y a
					// intersection
					if (currentZone.intersects(nextZone)) {
						double union = currentZone.union(nextZone).area();
						double intersection = currentZone.intersection(nextZone).area();
						double distance = 1 - intersection / union;
						totalDistance += distance;
					}
				}

			}
			if (totalDistance > 0) {
				// double union =
				// areaCurrentContributor.union(areaNextContributor).area();
				// double intersection =
				// areaCurrentContributor.intersection(areaNextContributor).area();
				// double distance = 1 - intersection / union;
				DefaultWeightedEdge e = g.addEdge((long) myContributorList.get(i).getId(),
						(long) myContributorList.get(j).getId());
				g.setEdgeWeight(e, 1 / totalDistance);
				// if (distance > 0)
				// g.setEdgeWeight(e, 1 / distance);
				// else
				// g.setEdgeWeight(e, Double.POSITIVE_INFINITY);
			}

		}
	}

	return g;
}
 
开发者ID:IGNF,项目名称:geoxygene,代码行数:64,代码来源:SocialGraph.java

示例6: generateNdPointGraph

import org.jgrapht.graph.SimpleWeightedGraph; //导入方法依赖的package包/类
private static SimpleWeightedGraph<NdPoint, DefaultWeightedEdge> generateNdPointGraph(NdPoint start,
        Collection<Zone> allZones, Collection<BoundedMoveableObject> obstacles, int botSize) {

    SimpleWeightedGraph<NdPoint, DefaultWeightedEdge> graph = new SimpleWeightedGraph<NdPoint, DefaultWeightedEdge>(
            DefaultWeightedEdge.class);


    List<NdPoint> vertices = returnVacantPoints(allZones, obstacles, botSize / 2);
    vertices.add(start);
    // Margin is botsize / 2, since the points move under the center of the bot.
    sanitizeVertices(allZones, vertices, obstacles, botSize / 2);


    // Add all the vertices.
    for (NdPoint p : vertices) {
        graph.addVertex(p);
    }


    /*
        Create the edges
        Each vertex can have 4 edges in GRID space. Since we won't be considering
        diagonal travel.
     */
    for (NdPoint vertex : vertices) {
        NdPoint[] neighbours = {
                new NdPoint(vertex.getX(), vertex.getY() + 1),
                new NdPoint(vertex.getX(), vertex.getY() - 1),
                new NdPoint(vertex.getX() - 1, vertex.getY()),
                new NdPoint(vertex.getX() + 1, vertex.getY())
        };

        for (NdPoint neighbour : neighbours) {
            if (vertices.contains(neighbour)) {
                // Default edge distance is 1. So we're good.
                graph.addEdge(vertex, neighbour);
            }
        }

    }

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

示例7: toGraph

import org.jgrapht.graph.SimpleWeightedGraph; //导入方法依赖的package包/类
public static UnmodifiableGraph<Coordinate, DefaultWeightedEdge> toGraph(GridMap map) {

        SimpleWeightedGraph<Coordinate, DefaultWeightedEdge> graph =
                new SimpleWeightedGraph<Coordinate, DefaultWeightedEdge>(DefaultWeightedEdge.class);
        
        int dims = map.dims();
        int length = map.length();
        int[] sizes = map.sizes();
        int[] idx = new int[dims];

        // Add every vertex that is not an obstacle
        for (int v = 0; v < length; v++) {
            if (map.get(idx) >= 0) {
                graph.addVertex(new IntCoord(idx));
            }

            for (int i = 0; i < dims; i++) {
                if (idx[i] < sizes[i] - 1) {
                    idx[i]++;
                    break;
                } else {
                    idx[i] = 0;
                }
            }
        }

        // Add every non-obstacle edge
        for (int v = 0; v < length; v++) {
            for (int i = 0; i < dims; i++) {
                if (idx[i] < sizes[i] - 1) {
                    int[] idx1 = Arrays.copyOf(idx, idx.length);
                    idx1[i]++;

                    if (map.get(idx) >= 0 && map.get(idx1) >= 0) {
                        DefaultWeightedEdge e = graph.addEdge(new IntCoord(idx), new IntCoord(idx1));
                        graph.setEdgeWeight(e, ((double)map.get(idx) + (double)map.get(idx1))/2.0 + 1.0);
                    }
                }
            }

            for (int i = 0; i < dims; i++) {
                if (idx[i] < sizes[i] - 1) {
                    idx[i]++;
                    break;
                } else {
                    idx[i] = 0;
                }
            }
        }

        return new UnmodifiableGraph<Coordinate, DefaultWeightedEdge>(graph);
    }
 
开发者ID:psigen,项目名称:robotutils,代码行数:53,代码来源:GridMapUtils.java


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