├── .gitignore ├── map.png ├── SA_animation.gif ├── README.md ├── MAP_LICENSE.md ├── capitals.json └── ga └── attacking_queens.py /.gitignore: -------------------------------------------------------------------------------- 1 | .ipynb_checkpoints/ 2 | -------------------------------------------------------------------------------- /map.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/canyon289/AIND-Simulated_Annealing/master/map.png -------------------------------------------------------------------------------- /SA_animation.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/canyon289/AIND-Simulated_Annealing/master/SA_animation.gif -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | In this exercise you will check your understanding of simulated annealing by implementing the algorithm in a Jupyter notebook and using it to solve the Traveling Salesman Problem (TSP) between US state capitals. 2 | 3 | To launch the notebook, run the following command from a terminal with anaconda3 installed and on the application path: 4 | 5 | jupyter notebook AIND-Simulated_Annealing.ipynb 6 | -------------------------------------------------------------------------------- /MAP_LICENSE.md: -------------------------------------------------------------------------------- 1 | Map services and data downloaded from The National Map are free and in the public domain. There are no restrictions; however, we request that the following acknowledgment statement of the originating agency be included in products and data derived from our map services when citing, copying, or reprinting: "Map services and data available from U.S. Geological Survey, National Geospatial Program." https://www2.usgs.gov/faq/categories/10154/3550 -------------------------------------------------------------------------------- /capitals.json: -------------------------------------------------------------------------------- 1 | {"Oklahoma City": [392.8, 356.4], "Montgomery": [559.6, 404.8], "Saint Paul": [451.6, 186.0], "Trenton": [698.8, 239.6], "Salt Lake City": [204.0, 243.2], "Columbus": [590.8, 263.2], "Austin": [389.2, 448.4], "Phoenix": [179.6, 371.2], "Hartford": [719.6, 205.2], "Baton Rouge": [489.6, 442.0], "Salem": [80.0, 139.2], "Little Rock": [469.2, 367.2], "Richmond": [673.2, 293.6], "Jackson": [501.6, 409.6], "Des Moines": [447.6, 246.0], "Lansing": [563.6, 216.4], "Denver": [293.6, 274.0], "Boise": [159.6, 182.8], "Raleigh": [662.0, 328.8], "Atlanta": [585.6, 376.8], "Madison": [500.8, 217.6], "Indianapolis": [548.0, 272.8], "Nashville": [546.4, 336.8], "Columbia": [632.4, 364.8], "Providence": [735.2, 201.2], "Boston": [738.4, 190.8], "Tallahassee": [594.8, 434.8], "Sacramento": [68.4, 254.0], "Albany": [702.0, 193.6], "Harrisburg": [670.8, 244.0]} -------------------------------------------------------------------------------- /ga/attacking_queens.py: -------------------------------------------------------------------------------- 1 | """ 2 | Program to calculate number of attacking queens 3 | """ 4 | from scipy import stats 5 | from collections import Counter 6 | from itertools import combinations 7 | import ipdb 8 | 9 | def attacking_queens(queen_string): 10 | # Get number of row wise attacking queens 11 | numbers = [int(i) for i in queen_string] 12 | row_attacks = 0 13 | for pair in combinations(numbers,2): 14 | if pair[0] == pair[1]: 15 | row_attacks +=1 16 | 17 | # Get diagonals by checking if slope is zero 18 | integers = [(i,int(l)) for i,l in enumerate(queen_string,1)] 19 | 20 | diagonal_attacks = 0 21 | # Calculate Slope, if 1 it's a diagonal attack 22 | 23 | for queen_1, queen_2 in combinations(integers, 2): 24 | l = [*zip(queen_1,queen_2)] 25 | slope, _, _, _, _ = stats.linregress(l) 26 | if slope in (-1,1): 27 | diagonal_attacks +=1 28 | 29 | return row_attacks + diagonal_attacks 30 | 31 | #jprint(attacking_queens('24748552')) 32 | #print(attacking_queens('32752411')) 33 | #print(attacking_queens('24415124')) 34 | #print(attacking_queens('32543213')) 35 | 36 | print(attacking_queens('32748552')) 37 | print(attacking_queens('32752124')) 38 | print(attacking_queens('24752411')) 39 | 40 | --------------------------------------------------------------------------------