ソースを参照

garbage, probably broken graph generation

tarfeef101 6 年 前
コミット
dbc7fb15b1
1 ファイル変更35 行追加0 行削除
  1. 35 0
      a2/tsp_local.py

+ 35 - 0
a2/tsp_local.py

@@ -251,5 +251,40 @@ def main():
     plt.ioff()
     plt.switch_backend('agg')
     solver("instance_10.txt", 1, 0)
+    solution_steps = []
+    solution_scores = []
+    
+    for i in range(14, 17):
+        steps = []
+        solution_steps.append(steps)
+        scores = []
+        solution_scores.append(scores)
+        
+        for j in range(1, 11):
+            filepath = "tsp_problems/" + str(i) + "/instance_" + str(j) + ".txt"
+            prob_steps = 0
+            prob_scores = 0
+            # run problem 100 times
+            for k in range(0, 100):
+                # path, cost, steps returned
+                result = solver(filepath, 1)
+                prob_steps += result[2]
+                prob_scores += result[1]
+            
+            steps.append(prob_steps / 100.0)
+            scores.append(prob_scores / 100.0)
+            
+    figure, axes = plt.subplots(1, 3, True)
+            
+    for i in range(0, 3):
+        axes[i].plot(range(1, 11), solution_steps[i], label = "Steps to Solution")
+        axes[i].set_xlabel("Problem Instance")
+        axes[i].set_ylabel("Steps Taken")
+        axis_twin = axes[i].twinx()
+        axis_twin.plot(range(1, 11), solution_scores[i], label = "Solution Cost/Distance")
+        axis_twin.set_ylabel("Distance in units")
+
+    axes.legend()
+    plt.savefig("hill_climbing.pdf")
 
 main()