Skip to content

Commit

Permalink
Improve snakeline available path from stating point
Browse files Browse the repository at this point in the history
Signed-off-by: Thomas ADAM <[email protected]>
  • Loading branch information
tadam50 committed Jan 29, 2024
1 parent 7591084 commit ffcec64
Show file tree
Hide file tree
Showing 13 changed files with 52 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ protected List<Point> calculatePolylineSnakeLine(LayoutParameters layoutParamete
// Add starting point
polyline.add(p1);
// Find snakeline path
polyline.addAll(model.buildSnakeline(pathFinder, p1, dNode1, p2, dNode2, layoutParameters.getZoneLayoutSnakeLinePadding()));
polyline.addAll(model.buildSnakeline(pathFinder, ss1Graph.getId(), p1, dNode1, ss2Graph.getId(), p2, dNode2, layoutParameters.getZoneLayoutSnakeLinePadding()));
// Add ending point
polyline.add(p2);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ public Matrix set(int row, int col, MatrixCell cell) {
return this;
}

public Optional<MatrixCell> get(String id) {
return stream().filter(c -> c.getId().equals(id)).findAny();
}

public MatrixCell get(int row, int col) {
return cells[row][col];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,25 +49,27 @@ private int getY(int row, double snakelineMargin) {
}

public List<Point> buildSnakeline(PathFinder pathfinder,
Point p1, Direction d1,
Point p2, Direction d2,
String ss1Id, Point p1, Direction d1,
String ss2Id, Point p2, Direction d2,
double snakelineMargin) {
insertFreePathInSubstation(p1, d1, snakelineMargin);
insertFreePathInSubstation(p2, d2, snakelineMargin);
matrix.get(ss1Id).ifPresent(matrixCell -> insertFreePathInSubstation(matrixCell.row(), p1, d1, snakelineMargin));
matrix.get(ss2Id).ifPresent(matrixCell -> insertFreePathInSubstation(matrixCell.row(), p2, d2, snakelineMargin));

// Use path finding algo
return pathfinder.findShortestPath(pathFinderGrid, p1, p2);
}

private void insertFreePathInSubstation(Point p, Direction d, double snakelineMargin) {
int dy = 1;

private void insertFreePathInSubstation(int row, Point p, Direction d, double snakelineMargin) {
int x1 = (int) p.getX();
int y1 = (int) p.getY();
int ss1Y = y1 + (int) snakelineMargin * (d == Direction.TOP ? -1 : 1);
int min1Y = Math.max(Math.min(y1, ss1Y), 0);
int max1Y = Math.max(y1, ss1Y) + dy;
for (int y = min1Y; y < max1Y; y++) {
int ssY = getY(row, snakelineMargin);
int min1Y = ssY - (int) snakelineMargin;
int max1Y = y1;
if (d == Direction.BOTTOM) {
min1Y = y1;
max1Y = ssY + (int) matrix.getMatrixCellHeight(row) + (int) snakelineMargin;
}
for (int y = min1Y; y <= max1Y; y++) {
pathFinderGrid.setAvailability(x1, y, true);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6128,20 +6128,20 @@
"node1" : "line1_ONE",
"node2" : "line1_TWO"
} ],
"snakeLine" : [ 585.0, 330.0, 585.0, 330.0, 585.0, 244.0, 1960.0, 244.0, 1960.0, 90.0, 2175.0, 90.0, 2175.0, 244.0, 2195.0, 244.0, 2195.0, 267.0, 2195.0, 267.0 ]
"snakeLine" : [ 585.0, 330.0, 585.0, 330.0, 585.0, 90.0, 2195.0, 90.0, 2195.0, 267.0, 2195.0, 267.0 ]
}, {
"id" : "hvdc_lcc",
"nodes" : [ {
"node1" : "hvdc_lcc_ONE",
"node2" : "hvdc_lcc_TWO"
} ],
"snakeLine" : [ 135.0, 330.0, 135.0, 330.0, 135.0, 274.0, 125.0, 274.0, 125.0, 244.0, 90.0, 244.0, 90.0, 60.0, 2050.0, 60.0, 2050.0, 244.0, 2095.0, 244.0, 2095.0, 267.0, 2095.0, 267.0 ]
"snakeLine" : [ 135.0, 330.0, 135.0, 330.0, 135.0, 124.0, 1960.0, 124.0, 1960.0, 90.0, 2095.0, 90.0, 2095.0, 267.0, 2095.0, 267.0 ]
}, {
"id" : "hvdc_vsc",
"nodes" : [ {
"node1" : "hvdc_vsc_ONE",
"node2" : "hvdc_vsc_TWO"
} ],
"snakeLine" : [ 185.0, 330.0, 185.0, 330.0, 185.0, 274.0, 155.0, 274.0, 155.0, 214.0, 125.0, 214.0, 125.0, 184.0, 90.0, 184.0, 90.0, 90.0, 60.0, 90.0, 60.0, 30.0, 2020.0, 30.0, 2020.0, 90.0, 2145.0, 90.0, 2145.0, 267.0, 2145.0, 267.0 ]
"snakeLine" : [ 185.0, 330.0, 185.0, 330.0, 185.0, 60.0, 2145.0, 60.0, 2145.0, 267.0, 2145.0, 267.0 ]
} ]
}
Original file line number Diff line number Diff line change
Expand Up @@ -6129,20 +6129,20 @@
"node1" : "line1_ONE",
"node2" : "line1_TWO"
} ],
"snakeLine" : [ 735.0, 270.0, 735.0, 270.0, 735.0, 181.0, 1110.0, 181.0, 1110.0, 90.0, 1345.0, 90.0, 1345.0, 175.0, 1345.0, 175.0 ]
"snakeLine" : [ 735.0, 270.0, 735.0, 270.0, 735.0, 90.0, 1345.0, 90.0, 1345.0, 175.0, 1345.0, 175.0 ]
}, {
"id" : "hvdc_lcc",
"nodes" : [ {
"node1" : "hvdc_lcc_ONE",
"node2" : "hvdc_lcc_TWO"
} ],
"snakeLine" : [ 285.0, 270.0, 285.0, 270.0, 285.0, 181.0, 270.0, 181.0, 270.0, 151.0, 240.0, 151.0, 240.0, 121.0, 210.0, 121.0, 210.0, 90.0, 90.0, 90.0, 90.0, 60.0, 1200.0, 60.0, 1200.0, 151.0, 1245.0, 151.0, 1245.0, 175.0, 1245.0, 175.0 ]
"snakeLine" : [ 285.0, 270.0, 285.0, 270.0, 285.0, 151.0, 1110.0, 151.0, 1110.0, 90.0, 1245.0, 90.0, 1245.0, 175.0, 1245.0, 175.0 ]
}, {
"id" : "hvdc_vsc",
"nodes" : [ {
"node1" : "hvdc_vsc_ONE",
"node2" : "hvdc_vsc_TWO"
} ],
"snakeLine" : [ 335.0, 270.0, 335.0, 270.0, 335.0, 241.0, 1080.0, 241.0, 1080.0, 1892.0, 1170.0, 1892.0, 1170.0, 90.0, 1295.0, 90.0, 1295.0, 175.0, 1295.0, 175.0 ]
"snakeLine" : [ 335.0, 270.0, 335.0, 270.0, 335.0, 60.0, 1295.0, 60.0, 1295.0, 175.0, 1295.0, 175.0 ]
} ]
}
Original file line number Diff line number Diff line change
Expand Up @@ -6142,6 +6142,6 @@
"node1" : "hvdc_vsc_ONE",
"node2" : "hvdc_vsc_TWO"
} ],
"snakeLine" : [ 185.0, 330.0, 185.0, 330.0, 185.0, 304.0, 275.0, 304.0, 275.0, 274.0, 935.0, 274.0, 935.0, 909.0, 90.0, 909.0, 90.0, 969.0, 265.0, 969.0, 265.0, 1059.0, 265.0, 1059.0 ]
"snakeLine" : [ 185.0, 330.0, 185.0, 330.0, 185.0, 60.0, 30.0, 60.0, 30.0, 969.0, 265.0, 969.0, 265.0, 1059.0, 265.0, 1059.0 ]
} ]
}
Original file line number Diff line number Diff line change
Expand Up @@ -6129,20 +6129,20 @@
"node1" : "line1_ONE",
"node2" : "line1_TWO"
} ],
"snakeLine" : [ 735.0, 270.0, 735.0, 270.0, 735.0, 241.0, 90.0, 241.0, 90.0, 2023.0, 270.0, 2023.0, 270.0, 2042.0, 270.0, 2042.0 ]
"snakeLine" : [ 735.0, 270.0, 735.0, 270.0, 735.0, 241.0, 240.0, 241.0, 240.0, 1892.0, 270.0, 1892.0, 270.0, 2042.0, 270.0, 2042.0 ]
}, {
"id" : "hvdc_lcc",
"nodes" : [ {
"node1" : "hvdc_lcc_ONE",
"node2" : "hvdc_lcc_TWO"
} ],
"snakeLine" : [ 285.0, 270.0, 285.0, 270.0, 285.0, 241.0, 120.0, 241.0, 120.0, 1892.0, 90.0, 1892.0, 90.0, 1982.0, 170.0, 1982.0, 170.0, 2042.0, 170.0, 2042.0 ]
"snakeLine" : [ 285.0, 270.0, 285.0, 270.0, 285.0, 211.0, 180.0, 211.0, 180.0, 1892.0, 170.0, 1892.0, 170.0, 2042.0, 170.0, 2042.0 ]
}, {
"id" : "hvdc_vsc",
"nodes" : [ {
"node1" : "hvdc_vsc_ONE",
"node2" : "hvdc_vsc_TWO"
} ],
"snakeLine" : [ 335.0, 270.0, 335.0, 270.0, 335.0, 211.0, 210.0, 211.0, 210.0, 181.0, 150.0, 181.0, 150.0, 151.0, 120.0, 151.0, 120.0, 121.0, 90.0, 121.0, 90.0, 90.0, 60.0, 90.0, 60.0, 1952.0, 220.0, 1952.0, 220.0, 2042.0, 220.0, 2042.0 ]
"snakeLine" : [ 335.0, 270.0, 335.0, 270.0, 335.0, 241.0, 270.0, 241.0, 270.0, 211.0, 210.0, 211.0, 210.0, 1892.0, 220.0, 1892.0, 220.0, 2042.0, 220.0, 2042.0 ]
} ]
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit ffcec64

Please sign in to comment.