Skip to content

Commit

Permalink
优化路径计算: 修正换乘数初始值并记录路径中的线路信息
Browse files Browse the repository at this point in the history
  • Loading branch information
lcy362 committed May 15, 2024
1 parent ac4190d commit 87e47ee
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/main/java/com/mobo/mobosubway/data/PathInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public class PathInfo {

private double distance = MAX_DISTANCE;

private int transferNum = -1; //换乘数
private int transferNum = 0; //换乘数

@Deprecated
private List<String> detail = new ArrayList<>(); //详细路径
Expand Down Expand Up @@ -55,12 +55,14 @@ public void addNodeToPath(NextStationInfo station) {
PathNode pathNode = new PathNode();
pathNode.setStationName(station.getName());
pathNode.setStationId(station.getId());
if (!StringUtils.equals(station.getLine(), currentLine)) {
if (StringUtils.isNotBlank(currentLine) && !StringUtils.equals(station.getLine(), currentLine)) {
transferNum++;
pathNode.setTransfer(true);
}
if (!StringUtils.equals(station.getLine(), currentLine)) {
pathLine.add(station.getLine());
}
currentLine = station.getLine();
pathLine.add(currentLine);

pathDetail.add(pathNode);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,10 @@ protected void handleAllPath(Map<String, PathInfo> knownPath, Map<String, PathIn
nextPath.setDistance(calculateNewDistance(nowPath, currentStation, nextPath));
log.debug("set " + stations.get(nextPath.getStationId()).getName() + " distance to " + nextPath.getDistance());
nextPath.setDetail(new ArrayList<>(nowPath.getDetail()));
nextPath.setPathLine(new ArrayList<>(nowPath.getPathLine()));
nextPath.setPathDetail(new ArrayList<>(nowPath.getPathDetail()));
nextPath.setTransferNum(nowPath.getTransferNum());
nextPath.setCurrentLine(nowPath.getCurrentLine());
nextPath.addNodeToPath(currentStation.getNextStations().get(nextPath.getStationId()));
});

Expand Down

0 comments on commit 87e47ee

Please sign in to comment.