textual changes
This commit is contained in:
parent
47597143fb
commit
c1e802662c
1 changed files with 11 additions and 12 deletions
|
|
@ -12,19 +12,19 @@ import java.util.*;
|
||||||
*/
|
*/
|
||||||
public class OptimalPathFinder {
|
public class OptimalPathFinder {
|
||||||
|
|
||||||
// paths to be considered
|
// paths to be considered, sorted by value
|
||||||
private final PriorityQueue<Path> paths = new PriorityQueue<>();
|
private final PriorityQueue<Path> paths = new PriorityQueue<>();
|
||||||
|
|
||||||
private final Set<Path> takenPaths = new HashSet<>();
|
private final Set<Path> takenPaths = new HashSet<>();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param g het Grid (vierkant)
|
* @param g square grid
|
||||||
* @param N grootte van het Grid
|
* @param N size of grid
|
||||||
* @param t totaal aantal discrete tijdstappen
|
* @param t total number of discrete timesteps
|
||||||
* @param T maximale tijdsduur
|
* @param T max algorithm elapsed time
|
||||||
* @param x startpositie X
|
* @param x start position X
|
||||||
* @param y startpositie Y
|
* @param y start position Y
|
||||||
* @return het meest waardevolle pad
|
* @return most valuable path (points and value)
|
||||||
*/
|
*/
|
||||||
public Path findOptimalPath(Grid g, int N, int t, long T, int x, int y) {
|
public Path findOptimalPath(Grid g, int N, int t, long T, int x, int y) {
|
||||||
Path path = Path.newPath(g, Point.create(g, x, y));
|
Path path = Path.newPath(g, Point.create(g, x, y));
|
||||||
|
|
@ -41,20 +41,19 @@ public class OptimalPathFinder {
|
||||||
// take current highest ranking path
|
// take current highest ranking path
|
||||||
path = paths.peek();
|
path = paths.peek();
|
||||||
assert path != null;
|
assert path != null;
|
||||||
|
|
||||||
while (path.length() >= t) {
|
while (path.length() >= t) {
|
||||||
// dit pad heeft lengte t bereikt, we kunnen niet verder
|
// path has reached max length, evict
|
||||||
paths.poll();
|
paths.poll();
|
||||||
// meer waarde dan de huidige max ?
|
// meer waarde dan de huidige max ?
|
||||||
if (path.value() > max.value()) {
|
if (path.value() > max.value()) {
|
||||||
max = path;
|
max = path;
|
||||||
}
|
}
|
||||||
|
|
||||||
// pak de volgende
|
// next path to evaluate
|
||||||
path = paths.peek();
|
path = paths.peek();
|
||||||
}
|
}
|
||||||
|
|
||||||
// System.out.println("paths:" + paths.size());
|
|
||||||
// System.out.println("CUR: " + path);
|
|
||||||
Point currentPos = path.getHead();
|
Point currentPos = path.getHead();
|
||||||
x = currentPos.x;
|
x = currentPos.x;
|
||||||
y = currentPos.y;
|
y = currentPos.y;
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue