diff --git a/.idea/runConfigurations.xml b/.idea/runConfigurations.xml deleted file mode 100644 index 797acea53eb091cf5b30518802c3073f544adeed..0000000000000000000000000000000000000000 --- a/.idea/runConfigurations.xml +++ /dev/null @@ -1,10 +0,0 @@ -<?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 diff --git a/.idea/vcs.xml b/.idea/vcs.xml index 3efd6af6ca58753c16fef9f14181ca6ad6b2424d..94a25f7f4cb416c083d265558da75d457237d671 100644 --- a/.idea/vcs.xml +++ b/.idea/vcs.xml @@ -2,6 +2,5 @@ <project version="4"> <component name="VcsDirectoryMappings"> <mapping directory="$PROJECT_DIR$" vcs="Git" /> - <mapping directory="$PROJECT_DIR$/oving-9" vcs="Git" /> </component> </project> \ No newline at end of file diff --git a/out/production/Real Task 9/Edge.class b/out/production/Real Task 9/Edge.class index afeeff6b44c8ec35823fa38da5e2c49bac4baeda..14558bb7546093f55720f9c15345ba0d27851afb 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 40f31e9f19e17ce985ba42d57de48b50c8f227ad..0c6c382ad9a41d781e20acf34e6f6501c83d1319 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 2de2d582346d50f8eceabced107d5e3a19a8fefe..71fa9ab4bf0e98c63565b85282d57b5e83bbb33a 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 47d6ee4f448093bd53bf445cdfd44fd70bf5527d..e91aa3619c6fcebbf9ecf7dbbdb5e0d015315356 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 a60a2172accb5a71c732692a1b729c9012d2ff6d..e752a6ced322f09e3c572a918ffc150f19a687d4 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 cfdc631bf11d9eaac069555bdd8deb5f634c7bfd..3ee5cc7596fd7657b0fddd0b9b36ffe9b53021cf 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,30 @@ 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"); - int startNumber = 0; + Objects.requireNonNull(g).loadEdges("kanter.txt"); + //g.loadNodes("noder.txt"); + /*int startNumber = 0; List<Edge> edges = g.getShortestPath(0,3); 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.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, "testOslo.txt"); + } catch (Exception e) { + e.printStackTrace(); } - } } @@ -154,6 +156,7 @@ class Edge implements Comparable<Edge>{ } class Graph{ + private final int size; private final HashMap<Integer, List<Edge>> adjacencyList = new HashMap<>(); private final List<Node> nodes = new ArrayList<>(); @@ -162,8 +165,8 @@ class Graph{ } public Graph(String inFile) throws IOException { - int numberOfNodes = Utils.readFirstLine(inFile); - for(int i = 0; i < numberOfNodes; ++i) { + size = Utils.readFirstLine(inFile); + for(int i = 0; i < size; ++i) { adjacencyList.put(i, new ArrayList<>()); } } @@ -268,6 +271,7 @@ class Graph{ public int [] fromLandmark(int landMark){ PriorityQueue<Edge> priorityQueue = new PriorityQueue<>(); int nodeSize = adjacencyList.size(); + System.out.println(nodeSize); int[] pathWeight = new int[nodeSize]; Arrays.fill(pathWeight, Integer.MAX_VALUE); pathWeight[landMark] = 0; @@ -283,11 +287,11 @@ class Graph{ for(Edge edge: adjacencyList.get(nextNode)){ edge.setCurrentWeight(pathWeight[start]); priorityQueue.add(edge); - index ++; } + index ++; priorityQueue.addAll(adjacencyList.get(nextNode)); } - if(index == nodeSize) return pathWeight; + if(index == size) return pathWeight; } return null; } @@ -329,14 +333,12 @@ 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) throws IOException{ + FileWriter writer = new FileWriter(fileName); + for (int j : array) { + writer.write(j + "\n"); } - file.close(); + writer.close(); } public static String[] dividedText(String line, int number){