Skip to content

Commit 97d89c3

Browse files
committed
Strangely enough, but I cannot repeat the bugs.
1 parent 86b82ac commit 97d89c3

File tree

31 files changed

+256
-8
lines changed

31 files changed

+256
-8
lines changed

src/main/java/io/github/coderodde/pathfinding/app/SettingsPane.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -400,7 +400,7 @@ protected List<Cell> call() throws Exception {
400400
this.path,
401401
pathfindingSettings));
402402
}
403-
});
403+
});
404404

405405
new Thread(task).start();
406406

src/main/java/io/github/coderodde/pathfinding/finders/BeamStackSearchFinder.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ public List<Cell> findPath(GridModel model,
7979

8080
while (!beamStack.isEmpty() && beamStack.peek().fmax >= U.value) {
8181
beamStack.pop();
82-
}
82+
}
8383

8484
if (beamStack.isEmpty()) {
8585
return optimalPath == null ? List.of() : optimalPath;
@@ -316,9 +316,8 @@ private static void pruneLayer(GridModel model,
316316

317317
for (HeapNode heapNode : pruneList) {
318318
open.remove(heapNode);
319-
320319
Cell cell = heapNode.cell;
321-
320+
322321
if (!cell.getCellType().equals(CellType.SOURCE) &&
323322
!cell.getCellType().equals(CellType.TARGET)) {
324323
model.setCellType(cell, CellType.VISITED);

src/main/java/io/github/coderodde/pathfinding/logic/PathfindingSettings.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ public int getBeamWidth() {
111111
}
112112

113113
public void setBeamWidth(int beamWidth) {
114+
System.out.println("Setting beam width " + beamWidth);
114115
if (beamWidth < 1) {
115116
throw new IllegalArgumentException(
116117
String.format("beamWidth(%d) < 1", beamWidth));

src/main/java/io/github/coderodde/pathfinding/logic/SearchStatistics.java

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,21 @@ public SearchStatistics(Label labelVisited,
4444
this.labelRejected = labelRejected;
4545
this.labelSelectors.addAll(Arrays.asList(selectors));
4646

47-
this.labelVisited .setText("Visited: N/A");
48-
this.labelOpened .setText("Opened: N/A");
49-
this.labelTraced .setText("Traced: N/A");
50-
this.labelRejected.setText("Rejected: N/A");
47+
if (labelVisited != null) {
48+
this.labelVisited .setText("Visited: N/A");
49+
}
50+
51+
if (labelOpened != null) {
52+
this.labelOpened .setText("Opened: N/A");
53+
}
54+
55+
if (labelTraced != null) {
56+
this.labelTraced .setText("Traced: N/A");
57+
}
58+
59+
if (labelRejected != null) {
60+
this.labelRejected.setText("Rejected: N/A");
61+
}
5162
}
5263

5364
public void incrementVisited() {
@@ -65,6 +76,10 @@ public void decrementOpened() {
6576
public void incrementTraced() {
6677
traced++;
6778

79+
if (labelTraced == null) {
80+
return;
81+
}
82+
6883
Platform.runLater(() -> {
6984
if (labelSelectors.contains(LabelSelector.TRACED)) {
7085
labelTraced.setText(String.format("Traced: %d", traced));
@@ -77,6 +92,10 @@ public void incrementTraced() {
7792
public void incrementRejected() {
7893
rejected++;
7994

95+
if (labelRejected == null) {
96+
return;
97+
}
98+
8099
Platform.runLater(() -> {
81100
if (labelSelectors.contains(LabelSelector.REJECTED)) {
82101
labelRejected.setText(String.format("Rejected: %d", rejected));
@@ -89,6 +108,10 @@ public void incrementRejected() {
89108
public void addToOpened(int delta) {
90109
opened += delta;
91110

111+
if (labelOpened == null) {
112+
return;
113+
}
114+
92115
Platform.runLater(() -> {
93116
if (labelSelectors.contains(LabelSelector.OPENED)) {
94117
labelOpened.setText(String.format("Opened: %d", opened));
@@ -101,6 +124,10 @@ public void addToOpened(int delta) {
101124
public void addToVisited(int delta) {
102125
visited += delta;
103126

127+
if (labelVisited == null) {
128+
return;
129+
}
130+
104131
Platform.runLater(() -> {
105132
if (labelSelectors.contains(LabelSelector.VISITED)) {
106133
labelVisited.setText(String.format("Visited: %d", visited));
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
package io.github.coderodde.pathfinding.finders;
2+
3+
import io.github.coderodde.pathfinding.heuristics.OctileHeuristicFunction;
4+
import io.github.coderodde.pathfinding.logic.GridCellNeighbourIterable;
5+
import io.github.coderodde.pathfinding.logic.GridNodeExpander;
6+
import io.github.coderodde.pathfinding.logic.PathfindingSettings;
7+
import io.github.coderodde.pathfinding.logic.SearchState;
8+
import io.github.coderodde.pathfinding.logic.SearchStatistics;
9+
import io.github.coderodde.pathfinding.model.GridModel;
10+
import io.github.coderodde.pathfinding.utils.Cell;
11+
import io.github.coderodde.pathfinding.utils.CellType;
12+
import java.util.List;
13+
import org.junit.Test;
14+
import static org.junit.Assert.*;
15+
16+
public class BeamStackSearchFinderTest {
17+
18+
private final PathfindingSettings ps = new PathfindingSettings();
19+
private final SearchState searchState = new SearchState();
20+
private final SearchStatistics searchStatistics =
21+
new SearchStatistics(null,
22+
null,
23+
null,
24+
null);
25+
26+
public BeamStackSearchFinderTest() {
27+
ps.setDontCrossCorners(true);
28+
ps.setFinder(new BeamStackSearchFinder());
29+
ps.setHeuristicFunction(new OctileHeuristicFunction());
30+
ps.setFrequency(1000);
31+
}
32+
33+
@Test
34+
public void hasSolutionPath() {
35+
GridModel model = new GridModel(20, 5);
36+
model.moveTarget(17, 2);
37+
model.moveSource(15, 2);
38+
model.setCellType(16, 2, CellType.WALL);
39+
ps.setBeamWidth(1);
40+
41+
GridNodeExpander expander = new GridNodeExpander(model, ps);
42+
43+
GridCellNeighbourIterable iterable =
44+
new GridCellNeighbourIterable(model,
45+
expander,
46+
ps);
47+
48+
List<Cell> pathBreadthFirstSearch =
49+
new BFSFinder()
50+
.findPath(model,
51+
iterable,
52+
ps,
53+
searchState,
54+
searchStatistics);
55+
56+
List<Cell> pathBeamStackSearch =
57+
new BeamStackSearchFinder()
58+
.findPath(model,
59+
iterable,
60+
ps,
61+
searchState,
62+
searchStatistics);
63+
64+
System.out.println("BSS: " + pathBeamStackSearch.size());
65+
System.out.println("BFS: " + pathBreadthFirstSearch.size());
66+
67+
assertEquals(pathBreadthFirstSearch.size(),
68+
pathBeamStackSearch.size());
69+
}
70+
71+
@Test
72+
public void debugNoPath() {
73+
GridModel model = new GridModel(53, 33);
74+
model.moveTarget(6, 4);
75+
model.moveSource(3, 4);
76+
model.setCellType(4, 2, CellType.WALL);
77+
model.setCellType(4, 3, CellType.WALL);
78+
model.setCellType(5, 3, CellType.WALL);
79+
model.setCellType(5, 4, CellType.WALL);
80+
model.setCellType(5, 5, CellType.WALL);
81+
82+
ps.setBeamWidth(1);
83+
84+
GridNodeExpander expander = new GridNodeExpander(model, ps);
85+
86+
GridCellNeighbourIterable iterable =
87+
new GridCellNeighbourIterable(model,
88+
expander,
89+
ps);
90+
91+
List<Cell> pathBreadthFirstSearch =
92+
new BFSFinder()
93+
.findPath(model,
94+
iterable,
95+
ps,
96+
searchState,
97+
searchStatistics);
98+
99+
List<Cell> pathBeamStackSearch =
100+
new BeamStackSearchFinder()
101+
.findPath(model,
102+
iterable,
103+
ps,
104+
searchState,
105+
searchStatistics);
106+
107+
System.out.println("BSS: " + pathBeamStackSearch.size());
108+
System.out.println("BFS: " + pathBreadthFirstSearch.size());
109+
110+
assertEquals(pathBreadthFirstSearch.size(),
111+
pathBeamStackSearch.size());
112+
}
113+
}
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

0 commit comments

Comments
 (0)