Browse Source

Cleaned up main, moved verification to own file

Toni Fadjukoff 8 years ago
parent
commit
27d0ae7e22

+ 5 - 31
src/main/kotlin/name/lamperi/orbital/main.kt View File

@@ -10,40 +10,14 @@ fun solveFile(file : File) {
10 10
     println(graph)
11 11
 
12 12
     val solution = solveGraph("Start", "End", graph)
13
-    println("Distance was ${solution.size} and route is $solution.")
14
-    println(solution.map {
15
-        val n = graph.nodes[it]!!
16
-        n.info.point
17
-    })
18
-    println(solution.map {
19
-        val n = graph.nodes[it]!!
20
-        toVec(n.info.point).len()
21
-    })
13
+    println("Distance was ${solution.size-1} hops and intermediate route is ${solution.subList(1,solution.size-1)}.")
22 14
 
23
-    val nodeList = graph.nodes.toList()
24
-    for (i in 1..solution.size-1) {
25
-        val a = graph.nodes[solution[i-1]]!!
26
-        val b = graph.nodes[solution[i]]!!
27
-
28
-        val av = toVec(a.info.point)
29
-        val bv = toVec(b.info.point)
30
-
31
-        val cv = bv - av
32
-
33
-        println("From ${a.info.name} to ${b.info.name}")
34
-        for (j in 1 .. 1000) {
35
-            val f = j * 0.001
36
-            val dist = (av + cv*f).len()
37
-            if (dist < EARTH_RADIUS) {
38
-                println(dist)
39
-            }
40
-        }
41
-        println("")
42
-    }
15
+    verify(graph, solution)
43 16
 }
44 17
 
18
+
45 19
 fun main(args : Array<String>) {
46
-    //solveFile(File("src/main/resources/satellites.txt"))
47
-    //solveFile(File("src/main/resources/satellites2.txt"))
20
+    solveFile(File("src/main/resources/satellites.txt"))
21
+    solveFile(File("src/main/resources/satellites2.txt"))
48 22
     solveFile(File("src/main/resources/satellites3.txt"))
49 23
 }

+ 23 - 0
src/main/kotlin/name/lamperi/orbital/verify.kt View File

@@ -0,0 +1,23 @@
1
+package name.lamperi.orbital
2
+
3
+fun verify(graph : Graph, solution : List<String>) {
4
+    // This verify method takes 1000 points from line to verify they do not pass earth
5
+    val nodeList = graph.nodes.toList()
6
+    for (i in 1..solution.size-1) {
7
+        val a = graph.nodes[solution[i-1]]!!
8
+        val b = graph.nodes[solution[i]]!!
9
+
10
+        val av = toVec(a.info.point)
11
+        val bv = toVec(b.info.point)
12
+
13
+        val cv = bv - av
14
+
15
+        for (j in 1 .. 1000) {
16
+            val f = j * 0.001
17
+            val dist = (av + cv*f).len()
18
+            if (dist < EARTH_RADIUS) {
19
+                throw IllegalArgumentException("Not a solution")
20
+            }
21
+        }
22
+    }
23
+}