diff --git a/out/production/Real Task 9/Edge.class b/out/production/Real Task 9/Edge.class index 16a47ae97242568e77411163203e44ad161c740c..7fd1be6e68bded02b0f4d8c46e4c334dcd367285 100644 Binary files a/out/production/Real Task 9/Edge.class and b/out/production/Real Task 9/Edge.class differ diff --git a/out/production/Real Task 9/Graph.class b/out/production/Real Task 9/Graph.class index 8ff085fd2db473c4efc6d1bfa1b843360ae7a078..5c610c40b6145614ce8b993ab6cc27a29a2d93d7 100644 Binary files a/out/production/Real Task 9/Graph.class and b/out/production/Real Task 9/Graph.class differ diff --git a/out/production/Real Task 9/Node.class b/out/production/Real Task 9/Node.class index 475776a62db1b866d202182bc77bb6fb005c6b8c..14e512d9b34000de0f0721b515cb3f4674ebc931 100644 Binary files a/out/production/Real Task 9/Node.class and b/out/production/Real Task 9/Node.class differ diff --git a/out/production/Real Task 9/Task9.class b/out/production/Real Task 9/Task9.class index d36257c4ddee5b121870accf5dc28f3eed9e5e32..4a7e703788449427a81302b4d747bb04b89415db 100644 Binary files a/out/production/Real Task 9/Task9.class and b/out/production/Real Task 9/Task9.class differ diff --git a/out/production/Real Task 9/Utils.class b/out/production/Real Task 9/Utils.class index 3f0ecb08d44e89d639403c649d4be5b74443f189..5f3d837e6c5a4ec9ecb8e4eec4ef1ae32401fd0f 100644 Binary files a/out/production/Real Task 9/Utils.class and b/out/production/Real Task 9/Utils.class differ diff --git a/src/Task9.java b/src/Task9.java index 289747edae9382bb8e390d9aa78d2ed7b0e41be8..d7025f1348bb0a361d05ba7f9ccf497f7539e829 100644 --- a/src/Task9.java +++ b/src/Task9.java @@ -1,7 +1,4 @@ -import java.io.BufferedReader; -import java.io.FileOutputStream; -import java.io.FileReader; -import java.io.IOException; +import java.io.*; import java.nio.ByteBuffer; import java.nio.channels.FileChannel; import java.nio.file.Files; @@ -14,25 +11,31 @@ public class Task9 { Graph g = null; try { - g = new Graph("noder Iceland.txt"); + g = new Graph("noder.txt"); } catch (IOException e) { e.printStackTrace(); } - Objects.requireNonNull(g).loadEdges("kanterIceland.txt"); + //Objects.requireNonNull(g).loadEdges("kanterIceland.txt"); + Objects.requireNonNull(g).loadInverseEdges("kanter.txt"); int startNumber = 0; List<Edge> edges = g.getShortestPath(0,3); - System.out.println(startNumber); + /*System.out.println(startNumber); for (Edge edge: edges) { System.out.println(edge.getDestination()); } System.out.println("----------------------- Dijkstra Done --------------------------------"); - g.loadNodes("noder Iceland.txt"); - g.readNodeInformation("interessepktIceland.txt"); + g.loadNodes("noder.txt"); + g.readNodeInformation("interessepkt.txt"); Node[] listOfPlaces = g.getListOfPlaces(0,Byte.parseByte("2"),Byte.parseByte("8")); for(Node node: listOfPlaces){ System.out.println(node.getLatitude()+","+node.getLongitude()); + }*/ + int[] array = g.fromLandmark(3430400); + try { + Utils.arrayToFile(array, "testOsloInverse.txt", 3430400); + } catch (Exception e) { + e.printStackTrace(); } - } } @@ -339,15 +342,29 @@ class Utils{ return currentDirectoryPath + System.getProperty("file.separator") +fileName; } -public void arrayToFile(int[] array, String fileName) throws IOException{ - FileOutputStream out= new FileOutputStream(fileName); - FileChannel file = out.getChannel(); - ByteBuffer but = file.map(FileChannel.MapMode.READ_WRITE,0, 4L * array.length); - for(int i : array){ - but.putInt(i); + public static void arrayToFile(int[] array, String fileName, int landmark) throws IOException{ + try(FileWriter writer = new FileWriter(fileName)) { + writer.write(landmark + "\n"); + for (int j : array) { + if(j == array[array.length - 1]) writer.write(Integer.toString(j)); + writer.write(j + "\n"); + } } - file.close(); -} + } + + public static int[] fileToArray(String fileName, int size) throws Exception { + int[] array = new int[size]; + try (BufferedReader reader = Files.newBufferedReader(Paths.get(fileName))) { + String currentLine = null; + int index = 0; + while((currentLine = reader.readLine()) != null) { + array[index] = Integer.parseInt(currentLine); + ++index; + } + } + return array; + } + public static String[] dividedText(String line, int number){ String[] divided = new String[number]; diff --git a/testOslo.txt b/testOslo.txt new file mode 100644 index 0000000000000000000000000000000000000000..b26b48d50409c91020f5c376eb6a1608bd9fdba0 Binary files /dev/null and b/testOslo.txt differ diff --git a/testOsloInverse.txt b/testOsloInverse.txt new file mode 100644 index 0000000000000000000000000000000000000000..b6b088f3eb07bc78c1a3bf696fad67a8d272f3c0 Binary files /dev/null and b/testOsloInverse.txt differ