本文整理汇总了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;
}
示例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;
}
示例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;
}
}