Skip to content
Snippets Groups Projects
Commit 26a6dd9d authored by Anders Austlid's avatar Anders Austlid
Browse files

Fixed landmark preprocessing.

parent 798f8cd3
No related branches found
No related tags found
No related merge requests found
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="RunConfigurationProducerService">
<option name="ignoredProducers">
<set>
<option value="com.android.tools.idea.compose.preview.runconfiguration.ComposePreviewRunConfigurationProducer" />
</set>
</option>
</component>
</project>
\ No newline at end of file
...@@ -2,6 +2,5 @@ ...@@ -2,6 +2,5 @@
<project version="4"> <project version="4">
<component name="VcsDirectoryMappings"> <component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" /> <mapping directory="$PROJECT_DIR$" vcs="Git" />
<mapping directory="$PROJECT_DIR$/oving-9" vcs="Git" />
</component> </component>
</project> </project>
\ No newline at end of file
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
import java.io.BufferedReader; import java.io.*;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.IOException;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import java.nio.channels.FileChannel; import java.nio.channels.FileChannel;
import java.nio.file.Files; import java.nio.file.Files;
...@@ -14,25 +11,30 @@ public class Task9 { ...@@ -14,25 +11,30 @@ public class Task9 {
Graph g = null; Graph g = null;
try { try {
g = new Graph("noder Iceland.txt"); g = new Graph("noder.txt");
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
} }
Objects.requireNonNull(g).loadEdges("kanterIceland.txt"); Objects.requireNonNull(g).loadEdges("kanter.txt");
int startNumber = 0; //g.loadNodes("noder.txt");
/*int startNumber = 0;
List<Edge> edges = g.getShortestPath(0,3); List<Edge> edges = g.getShortestPath(0,3);
System.out.println(startNumber); System.out.println(startNumber);
for (Edge edge: edges) { for (Edge edge: edges) {
System.out.println(edge.getDestination()); System.out.println(edge.getDestination());
} }
System.out.println("----------------------- Dijkstra Done --------------------------------"); System.out.println("----------------------- Dijkstra Done --------------------------------");
g.loadNodes("noder Iceland.txt"); g.readNodeInformation("interessepkt.txt");
g.readNodeInformation("interessepktIceland.txt");
Node[] listOfPlaces = g.getListOfPlaces(0,Byte.parseByte("2"),Byte.parseByte("8")); Node[] listOfPlaces = g.getListOfPlaces(0,Byte.parseByte("2"),Byte.parseByte("8"));
for(Node node: listOfPlaces){ for(Node node: listOfPlaces){
System.out.println(node.getLatitude()+","+node.getLongitude()); System.out.println(node.getLatitude()+","+node.getLongitude());
}*/
int[] array = g.fromLandmark(3430400);
try {
Utils.arrayToFile(array, "testOslo.txt");
} catch (Exception e) {
e.printStackTrace();
} }
} }
} }
...@@ -154,6 +156,7 @@ class Edge implements Comparable<Edge>{ ...@@ -154,6 +156,7 @@ class Edge implements Comparable<Edge>{
} }
class Graph{ class Graph{
private final int size;
private final HashMap<Integer, List<Edge>> adjacencyList = new HashMap<>(); private final HashMap<Integer, List<Edge>> adjacencyList = new HashMap<>();
private final List<Node> nodes = new ArrayList<>(); private final List<Node> nodes = new ArrayList<>();
...@@ -162,8 +165,8 @@ class Graph{ ...@@ -162,8 +165,8 @@ class Graph{
} }
public Graph(String inFile) throws IOException { public Graph(String inFile) throws IOException {
int numberOfNodes = Utils.readFirstLine(inFile); size = Utils.readFirstLine(inFile);
for(int i = 0; i < numberOfNodes; ++i) { for(int i = 0; i < size; ++i) {
adjacencyList.put(i, new ArrayList<>()); adjacencyList.put(i, new ArrayList<>());
} }
} }
...@@ -268,6 +271,7 @@ class Graph{ ...@@ -268,6 +271,7 @@ class Graph{
public int [] fromLandmark(int landMark){ public int [] fromLandmark(int landMark){
PriorityQueue<Edge> priorityQueue = new PriorityQueue<>(); PriorityQueue<Edge> priorityQueue = new PriorityQueue<>();
int nodeSize = adjacencyList.size(); int nodeSize = adjacencyList.size();
System.out.println(nodeSize);
int[] pathWeight = new int[nodeSize]; int[] pathWeight = new int[nodeSize];
Arrays.fill(pathWeight, Integer.MAX_VALUE); Arrays.fill(pathWeight, Integer.MAX_VALUE);
pathWeight[landMark] = 0; pathWeight[landMark] = 0;
...@@ -283,11 +287,11 @@ class Graph{ ...@@ -283,11 +287,11 @@ class Graph{
for(Edge edge: adjacencyList.get(nextNode)){ for(Edge edge: adjacencyList.get(nextNode)){
edge.setCurrentWeight(pathWeight[start]); edge.setCurrentWeight(pathWeight[start]);
priorityQueue.add(edge); priorityQueue.add(edge);
index ++;
} }
index ++;
priorityQueue.addAll(adjacencyList.get(nextNode)); priorityQueue.addAll(adjacencyList.get(nextNode));
} }
if(index == nodeSize) return pathWeight; if(index == size) return pathWeight;
} }
return null; return null;
} }
...@@ -329,14 +333,12 @@ class Utils{ ...@@ -329,14 +333,12 @@ class Utils{
return currentDirectoryPath + System.getProperty("file.separator") +fileName; return currentDirectoryPath + System.getProperty("file.separator") +fileName;
} }
public void arrayToFile(int[] array, String fileName) throws IOException{ public static void arrayToFile(int[] array, String fileName) throws IOException{
FileOutputStream out= new FileOutputStream(fileName); FileWriter writer = new FileWriter(fileName);
FileChannel file = out.getChannel(); for (int j : array) {
ByteBuffer but = file.map(FileChannel.MapMode.READ_WRITE,0, 4L * array.length); writer.write(j + "\n");
for(int i : array){
but.putInt(i);
} }
file.close(); writer.close();
} }
public static String[] dividedText(String line, int number){ public static String[] dividedText(String line, int number){
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment