textual changes
This commit is contained in:
parent
c3eb455df1
commit
e34cb09125
3 changed files with 16 additions and 10 deletions
|
|
@ -6,6 +6,9 @@ import java.io.InputStreamReader;
|
|||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Represents a square grid. Integer values at position x,y
|
||||
*/
|
||||
public record Grid(List<List<Integer>> grid) {
|
||||
private static final double timeValueFactor = .2;
|
||||
|
||||
|
|
@ -14,7 +17,7 @@ public record Grid(List<List<Integer>> grid) {
|
|||
BufferedReader reader = new BufferedReader(new InputStreamReader(Grid.class.getClassLoader().getResourceAsStream(resource)));
|
||||
String line;
|
||||
List<List<Integer>> rows = new ArrayList<>();
|
||||
while ((line=reader.readLine())!=null){
|
||||
while ((line = reader.readLine()) != null) {
|
||||
String[] values = line.split(" ");
|
||||
List<Integer> row = new ArrayList<>(values.length);
|
||||
for (int i = 0; i < values.length; i++) {
|
||||
|
|
@ -28,19 +31,18 @@ public record Grid(List<List<Integer>> grid) {
|
|||
}
|
||||
}
|
||||
|
||||
public int getInitialValue(int x, int y){
|
||||
public int getInitialValue(int x, int y) {
|
||||
return grid.get(y).get(x);
|
||||
}
|
||||
|
||||
//assumes square
|
||||
public int getWidth(){
|
||||
public int getWidth() {
|
||||
return grid.size();
|
||||
}
|
||||
|
||||
/**
|
||||
* de waarde van een punt x,y wordt bepaald door de beginwaarde, tenzij we er al geweest zijn
|
||||
* dan telt de tijd sinds we er geweest zijn = afstand in sindsdien afgelegd pad
|
||||
* de waarde is rechtevenredig met de afstand
|
||||
* The value of a point is the initialValue unless it has been visited (in a path)
|
||||
* Immediately after visiting its value is 0 and in steady pace (timeValueFactor) increases with time.
|
||||
*/
|
||||
public double getCurrentValue(Path path, int x, int y) {
|
||||
int gridValue = getInitialValue(x, y);
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@ public class OptimalPathFinder {
|
|||
// paths to be considered, sorted by value
|
||||
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<>();
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -4,13 +4,16 @@ import java.util.ArrayList;
|
|||
import java.util.HashSet;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* Represents a path in a grid, consisting of a sequence of points.
|
||||
*/
|
||||
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<>();
|
||||
|
||||
// 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 Path() {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue