本文整理汇总了Java中org.jgrapht.GraphPath.getEdgeList方法的典型用法代码示例。如果您正苦于以下问题:Java GraphPath.getEdgeList方法的具体用法?Java GraphPath.getEdgeList怎么用?Java GraphPath.getEdgeList使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.jgrapht.GraphPath
的用法示例。
在下文中一共展示了GraphPath.getEdgeList方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getDistance
import org.jgrapht.GraphPath; //导入方法依赖的package包/类
/**
* Calculates the distance between two regions in this map.<br>
* <br>
*
* Distance is defined as the length of the shortest path in a graph representation of this map,
* where two regions share an edge if and only if they are adjacent. All edges have weight / lenght 1.
* <br>
* If no path was found, {@link #getNumberOfRegions()}-1 is returned.
*/
public int getDistance(Region regionOne, Region regionTwo) {
if (regionOne.equals(regionTwo)) {
return 0;
}
GraphPath<Region, DefaultEdge> shortestPath = getFloyedWarshallDistances().getShortestPath(regionOne, regionTwo);
if (shortestPath == null) {
//No path found, return max distance
return getNumberOfRegions() - 1;
}
List<DefaultEdge> path = shortestPath.getEdgeList();
if (path == null) {
//No path found, return max distance
return getNumberOfRegions() - 1;
}
return path.size();
}
示例2: edges_comparator
import org.jgrapht.GraphPath; //导入方法依赖的package包/类
public boolean edges_comparator (GraphPath<Object,IntraDomainEdge> gp1, GraphPath<Object,IntraDomainEdge> gp2){
List <IntraDomainEdge> edgeList1;
List <IntraDomainEdge> edgeList2;
edgeList1 = gp1.getEdgeList();
edgeList2 = gp2.getEdgeList();
if (edgeList1.isEmpty()== true){
is_equal = false;
return is_equal;
}
if (edgeList2.isEmpty()== true){
is_equal = false;
return is_equal;
}
if (edgeList1.size() != edgeList2.size()){
is_equal = false;
}else{
is_equal=true;
for(int i=0;i<edgeList1.size();i++){
if (edgeList1.get(i).getTarget().equals(edgeList2.get(i).getTarget()) == false){
is_equal = false;
return is_equal;
}
}
}
return is_equal;
}
示例3: partitionKMeans
import org.jgrapht.GraphPath; //导入方法依赖的package包/类
/**
* Obtains a graph partitioning of the passed graph. The algorithm is similar to KMeans (with K = 1) clustering and is stochastic (i.e. return a different partitioning per call for the same passed graph)
* @param graph
* @param numPartitions
* @param r
* @param randomBase
*/
public static GraphPartitioningState partitionKMeans(SimpleGraph<Node, Border> graph, int numPartitions, Random r,boolean randomBase)
{
GraphPartitioningState partitionsGraph = new GraphPartitioningState();
ArrayList<Node> nodes = GraphUtil.getNodesArrayList(graph);
ArrayList<Integer> taken = generateRandomWithoutReplacment(r, nodes.size(), numPartitions);
// Create partitions and initialize them with the randomly chosen nodes
Partition[] partitions = new Partition[numPartitions];
int base = 0;
if(randomBase)
base = secondaryRand.nextInt(Integer.MAX_VALUE);
//assign the seeds to partitions
for (int i = 0; i < partitions.length; i++) {
partitions[i] = new Partition(base+i);
partitions[i].addMember(nodes.get(taken.get(i)));
}
// assign each vertex to one of the partitions based on min path length
for (int i = 0; i < nodes.size(); i++) {
int closest = -1;
int length = 0, minLength = Integer.MAX_VALUE;
if (!taken.contains(i)) {
for (int j = 0; j < taken.size(); j++) {
GraphPath<Node,Border> path = BellmanFordShortestPath.findPathBetween(graph, nodes.get(i), nodes.get(taken.get(j)));
if (path == null)// there is a vertex that has no path to any
// of the means centers
{
System.out.println("Some vertices have no path to their assigned center");
}
else
{
List<Border> lst = path.getEdgeList();
length = lst.size();
}
if (length < minLength)
{
minLength = length;
closest = j;
}
}
partitions[closest].addMember(nodes.get(i));
}
}
for (int i = 0; i < partitions.length; i++)
{
partitionsGraph.addVertex(partitions[i]);
}
buildQuotientGraph(partitionsGraph, graph);
return partitionsGraph;
}
示例4: getRoute
import org.jgrapht.GraphPath; //导入方法依赖的package包/类
public List<Line> getRoute(Node from, Node to) {
GraphPath<Node, Line> path = DijkstraShortestPath.findPathBetween(netDelegate, from, to);
return path == null ? null : path.getEdgeList();
}
示例5: createRepresentation
import org.jgrapht.GraphPath; //导入方法依赖的package包/类
/**
* Converts from existing representation(s) to the desired representation, which has the specified dataType.
* <p/>
* The base representation returns only the default representation if the dataType matches the default type. Otherwise
* it returns null.
*
* @param dataType
* @return
*/
private Representation createRepresentation(Representation representation) throws DDFException {
Collection<Representation> vertices = this.mReps.values();
//List<GraphPath<Representation<?>, ConvertFunction<?, ?>>> pathList = new ArrayList<GraphPath<Representation<?>, ConvertFunction<?, ?>>>();
double minWeight = Double.MAX_VALUE;
GraphPath<Representation, ConvertFunction> minPath = null;
for (Representation vertex : vertices) {
mLog.info(">>>>>> start vertex = " + vertex.getTypeSpecsString());
mLog.info(">>>>>> end Vertex = " + representation.getTypeSpecsString());
GraphPath<Representation, ConvertFunction> shortestPath = this.mGraph.getShortestPath(vertex, representation);
if (shortestPath != null) {
mLog.info(">>>> shortestPath != null");
if (shortestPath.getWeight() < minWeight) {
minWeight = shortestPath.getWeight();
minPath = shortestPath;
}
}
}
if (minPath == null) {
return null;
} else {
Representation startVertex = minPath.getStartVertex();
Representation startRepresentation = null;
for (Representation rep : this.mReps.values()) {
if (rep.equals(startVertex)) {
startRepresentation = rep;
}
}
mLog.info("minPath.getWeight = " + minPath.getWeight());
mLog.info("minPath.lenth = " + minPath.getEdgeList().size());
mLog.info("startVertext = " + minPath.getStartVertex().getTypeSpecsString());
mLog.info("endVertex = " + minPath.getEndVertex().getTypeSpecsString());
List<ConvertFunction> convertFunctions = minPath.getEdgeList();
Representation objectRepresentation = startRepresentation;
for (ConvertFunction func : convertFunctions) {
objectRepresentation = func.apply(objectRepresentation);
}
return objectRepresentation;
}
}
示例6: largetTest
import org.jgrapht.GraphPath; //导入方法依赖的package包/类
@Test
public void largetTest() {
graph.putIfAbsent(state2);
graph.putIfAbsent(state3);
graph.putIfAbsent(state4);
graph.putIfAbsent(state5);
graph.addEdge(index, state2, newXpathEventable("/index/2"));
graph.addEdge(state2, index, newXpathEventable("/2/index"));
graph.addEdge(state2, state3, newXpathEventable("/2/3"));
graph.addEdge(index, state4, newXpathEventable("/index/4"));
graph.addEdge(state2, state5, newXpathEventable("/2/5"));
graph.addEdge(state4, index, newXpathEventable("/4/index"));
graph.addEdge(index, state5, newXpathEventable("/index/5"));
graph.addEdge(state4, state2, newXpathEventable("/4/2"));
graph.addEdge(state3, state5, newXpathEventable("/3/5"));
List<List<GraphPath<StateVertex, Eventable>>> results = graph.getAllPossiblePaths(index);
assertThat(results, hasSize(2));
assertThat(results.get(0), hasSize(5));
assertThat(results.get(0).get(0).getEdgeList(), hasSize(1));
assertThat(results.get(1), hasSize(2));
// int max = 0;
Set<Eventable> uEvents = new HashSet<Eventable>();
for (List<GraphPath<StateVertex, Eventable>> paths : results) {
for (GraphPath<StateVertex, Eventable> p : paths) {
// System.out.print(" Edge: " + x + ":" + y);
// int z = 0;
for (Eventable edge : p.getEdgeList()) {
// System.out.print(", " + edge.toString());
if (!uEvents.contains(edge)) {
uEvents.add(edge);
}
}
}
}
}