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


Java GraphPath.getWeight方法代码示例

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


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

示例1: getShortestPath

import org.jgrapht.GraphPath; //导入方法依赖的package包/类
public static GraphPath getShortestPath(Network network, List<Stop> possibleSources, List<Stop> possibleTargets, @Nullable IEdgeWeighter weighter) {
    AStarShortestPath as = new AStarShortestPath(network);
    AStarAdmissibleHeuristic heuristic = new AStarAdmissibleHeuristic<Stop>() {
        @Override
        public double getCostEstimate(Stop sourceVertex, Stop targetVertex) {
            return 0;
        }
    };
    List<GraphPath> paths = new ArrayList<>();
    // assume that only this class can perform this trick with the "hackish" annotations
    // lock on class so that if this method is called concurrently the annotations won't be messed up
    synchronized (Route.class) {
        IEdgeWeighter prevWeighter = network.getEdgeWeighter();
        if (weighter != null) {
            network.setEdgeWeighter(weighter);
        }
        for (Stop pSource : possibleSources) {
            for (Stop pTarget : possibleTargets) {
                // hackish "annotations" for the connection weighter
                pSource.putMeta("is_route_source", true);
                pTarget.putMeta("is_route_target", true);

                paths.add(as.getShortestPath(pSource, pTarget, heuristic));
                pSource.putMeta("is_route_source", null);
                pTarget.putMeta("is_route_target", null);
            }
        }
        network.setEdgeWeighter(prevWeighter);
    }

    GraphPath path = null;
    for (GraphPath p : paths) {
        if (path == null || p.getWeight() < path.getWeight()) {
            path = p;
        }
    }
    return path;
}
 
开发者ID:gbl08ma,项目名称:underlx,代码行数:39,代码来源:Route.java

示例2: getDestinos

import org.jgrapht.GraphPath; //导入方法依赖的package包/类
public List<Integer> getDestinos(int inicio, int tirada){
	List<Integer> destinos = new ArrayList<Integer>();
	for (int i = 0; i < casillas.length; i++) {
		DijkstraShortestPath<Casilla, DefaultEdge> dijkstra = new DijkstraShortestPath<Casilla, DefaultEdge>(
				grafo, casillas[inicio], casillas[i]);
		GraphPath<Casilla, DefaultEdge> path = dijkstra.getPath();
		if (path.getWeight() == tirada)
			destinos.add(i);
	}
	return destinos;
}
 
开发者ID:Arquisoft,项目名称:Trivial4b,代码行数:12,代码来源:Grafo.java

示例3: 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;
  }
}
 
开发者ID:ddf-project,项目名称:DDF,代码行数:52,代码来源:RepresentationHandler.java


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