def testAL(self): """Part (c): short path""" source = dijkstra.node_by_name(self.nodes, 'BRIDGEPORT', 'AL') destination = dijkstra.node_by_name(self.nodes, 'STEVENSON', 'AL') ans = dijkstra.shortest_path(self.nodes, self.links, dijkstra.distance, source, destination) self.assertEqual(3, len(ans)) self.verifyPath(ans, self.links, source, destination)
def flat_earth(filename="path_flat.kml"): """Test long path""" loader = nhpn.Loader() nodes = loader.nodes() links = loader.links() source = dijkstra.node_by_name(nodes, "CAMDEN", "NJ") destination = dijkstra.node_by_name(nodes, "SAN DIEGO", "CA") ans = dijkstra.shortest_path(nodes, links, dijkstra.distance, source, destination) nhpn.Visualizer.toKML(ans, "path_flat.kml")
def flat_earth(filename='path_flat.kml'): """Test long path""" loader = nhpn.Loader() nodes = loader.nodes() links = loader.links() source = dijkstra.node_by_name(nodes, 'CAMDEN', 'NJ') destination = dijkstra.node_by_name(nodes, 'SAN DIEGO', 'CA') ans = dijkstra.shortest_path(nodes, links, dijkstra.distance, source, destination) nhpn.Visualizer.toKML(ans, 'path_flat.kml')
def flat_earth(filename = 'path_flat.kml'): """Test long path""" nodes, links = dijkstra.load_data() dijkstra.create_adjacency_lists(nodes, links) source = dijkstra.node_by_name(nodes, 'PASADENA', 'CA') destination = dijkstra.node_by_name(nodes, 'CAMBRIDGE', 'MA') ans = dijkstra.shortest_path(nodes, links, dijkstra.distance, source, destination) nhpn.Visualizer.toKML(ans, 'path_flat.kml') print "path_flat.kml created"
def curved_earth(filename='path_curved.kml'): """Test long path""" loader = nhpn.Loader() nodes = loader.nodes() links = loader.links() def distance(node1, node2): """Returns the distance between node1 and node2, including the Earth's curvature.""" A = node1.latitude * pi / 10**6 / 180 B = node1.longitude * pi / 10**6 / 180 C = node2.latitude * pi / 10**6 / 180 D = node2.longitude * pi / 10**6 / 180 return acos(sin(A) * sin(C) + cos(A) * cos(C) * cos(B - D)) source = dijkstra.node_by_name(nodes, 'CAMDEN', 'NJ') destination = dijkstra.node_by_name(nodes, 'SAN DIEGO', 'CA') ans = dijkstra.shortest_path(nodes, links, distance, source, destination) nhpn.Visualizer.toKML(ans, 'path_curved.kml')
def curved_earth(filename="path_curved.kml"): """Test long path""" loader = nhpn.Loader() nodes = loader.nodes() links = loader.links() def distance(node1, node2): """Returns the distance between node1 and node2, including the Earth's curvature.""" A = node1.latitude * pi / 10 ** 6 / 180 B = node1.longitude * pi / 10 ** 6 / 180 C = node2.latitude * pi / 10 ** 6 / 180 D = node2.longitude * pi / 10 ** 6 / 180 return acos(sin(A) * sin(C) + cos(A) * cos(C) * cos(B - D)) source = dijkstra.node_by_name(nodes, "CAMDEN", "NJ") destination = dijkstra.node_by_name(nodes, "SAN DIEGO", "CA") ans = dijkstra.shortest_path(nodes, links, distance, source, destination) nhpn.Visualizer.toKML(ans, "path_curved.kml")
def curved_earth(filename = 'path_curved.kml'): """Test long path""" nodes, links = dijkstra.load_data() dijkstra.create_adjacency_lists(nodes, links) def distance(node1, node2): """Returns the distance between node1 and node2, including the Earth's curvature.""" A = node1.latitude*pi/10**6/180 B = node1.longitude*pi/10**6/180 C = node2.latitude*pi/10**6/180 D = node2.longitude*pi/10**6/180 return acos(sin(A)*sin(C)+cos(A)*cos(C)*cos(B-D)) source = dijkstra.node_by_name(nodes, 'PASADENA', 'CA') destination = dijkstra.node_by_name(nodes, 'CAMBRIDGE', 'MA') ans = dijkstra.shortest_path(nodes, links, distance, source, destination) nhpn.Visualizer.toKML(ans, 'path_curved.kml') print "path_curved.kml created"
def test1(self): """Part (a): node_by_name""" ans = dijkstra.node_by_name(self.nodes, 'CAMDEN', 'NJ') self.assertEqual(ans.state, 'NJ') self.assertEqual('CAMDEN CBD', ans.description)
def test1(self): """Part (a): node_by_name""" ans = dijkstra.node_by_name(self.nodes, 'CAMBRIDGE', 'MA') self.assertEqual(ans.state, 'MA') self.assertEqual('NORTH CAMBRIDGE', ans.description)