Skip to content

Commit

Permalink
change tsp.sqlite to tsp.db
Browse files Browse the repository at this point in the history
  • Loading branch information
tnlin committed Aug 14, 2016
1 parent 55f6835 commit 1a017f2
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ numpy==1.11.1, python2/3的環境下皆可運行

![image](http://i.imgur.com/GoZRbzt.png")

最後再把結果存入`data/tsp.sqlite`內,方便未來分析
最後再把結果存入`data/tsp.db`內,方便未來分析

推薦下載 [Sqlite Browser](http://sqlitebrowser.org/) GUI管理工具來開啟資料庫

Expand Down
7 changes: 4 additions & 3 deletions tsp.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def accept(cost_new, cost_current, T):
np.random.rand() < np.exp(-(cost_new - cost_current) / T) )

def save_sqlite(payloads):
conn = sqlite3.connect('data/tsp.sqlite')
conn = sqlite3.connect('data/tsp.db')
c = conn.cursor()
c.execute("CREATE TABLE IF NOT EXISTS TSP (costs REAL, route TEXT, markov_step INTEGER) ")
c.execute('INSERT INTO TSP VALUES (?,?,?)' , payloads)
Expand Down Expand Up @@ -123,10 +123,11 @@ def main():
T *= T_ALPHA
costs.append(cost_best)
# Monitor the temperature & cost
print("Temperature:", T,", Distance:",cost_best)
print("Temperature:", "%.2f" % round(T, 2),\
" Distance:", "%.2f" % round(cost_best, 2))

# Show final cost & route
print("Final Distance:", costs[-1])
print("Final Distance:", round(costs[-1], 2))
print("Best Route", sol_best)

route = json.dumps(sol_best.tolist())
Expand Down

0 comments on commit 1a017f2

Please sign in to comment.