textual changes

This commit is contained in:
Shautvast 2024-11-09 22:56:24 +01:00
parent c3eb455df1
commit e34cb09125
3 changed files with 16 additions and 10 deletions

View file

@ -6,6 +6,9 @@ import java.io.InputStreamReader;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
/**
* Represents a square grid. Integer values at position x,y
*/
public record Grid(List<List<Integer>> grid) { public record Grid(List<List<Integer>> grid) {
private static final double timeValueFactor = .2; private static final double timeValueFactor = .2;
@ -38,9 +41,8 @@ public record Grid(List<List<Integer>> grid) {
} }
/** /**
* de waarde van een punt x,y wordt bepaald door de beginwaarde, tenzij we er al geweest zijn * The value of a point is the initialValue unless it has been visited (in a path)
* dan telt de tijd sinds we er geweest zijn = afstand in sindsdien afgelegd pad * Immediately after visiting its value is 0 and in steady pace (timeValueFactor) increases with time.
* de waarde is rechtevenredig met de afstand
*/ */
public double getCurrentValue(Path path, int x, int y) { public double getCurrentValue(Path path, int x, int y) {
int gridValue = getInitialValue(x, y); int gridValue = getInitialValue(x, y);

View file

@ -15,6 +15,7 @@ public class OptimalPathFinder {
// paths to be considered, sorted by value // paths to be considered, sorted by value
private final PriorityQueue<Path> paths = new PriorityQueue<>(); private final PriorityQueue<Path> paths = new PriorityQueue<>();
/// can likely be replaced by Set<Integer> (path hashcode) --> takes up less memory
private final Set<Path> takenPaths = new HashSet<>(); private final Set<Path> takenPaths = new HashSet<>();
/** /**

View file

@ -4,13 +4,16 @@ import java.util.ArrayList;
import java.util.HashSet; import java.util.HashSet;
import java.util.Objects; import java.util.Objects;
/**
* Represents a path in a grid, consisting of a sequence of points.
*/
public class Path implements Comparable<Path> { public class Path implements Comparable<Path> {
// beide bevatten de al afgelegde punten //both these collections contain the current points in the path
// points is bedoeld om door de punten te lopen // points is meant to traverse the points
public final ArrayList<Point> points = new ArrayList<>(); public final ArrayList<Point> points = new ArrayList<>();
// trodden is bedoeld om zo snel mogelijk vast te stellen of we al op het punt geweest zijn // the purpose of trodden is to quickly determine if a point is part of this path
private final HashSet<Integer> trodden = new HashSet<>(); private final HashSet<Integer> trodden = new HashSet<>();
private Path() { private Path() {