コード例 #1
0
ファイル: test.py プロジェクト: MrTerrorbyte/FlightRoutes
	def test_calculations(self):
		''' using my json file, tests shortest path, cost, distance, and time '''
		json_file = open("test.json")
		json_data = json.load(json_file)
		json_file.close()
		self.graph = Graph()
		self.metros = json_data["metros"]
		self.routes = json_data["routes"]
		self.graph = self.graph.construct_json_graph(self.metros, self.routes)
		self.assertEqual(['cityTwo','cityOne','cityFour'] , calculations.shortest_path(self.graph, 'cityTwo', 'cityFour'))	
		shortest_path = calculations.shortest_path(self.graph, 'cityTwo', 'cityFour')
		self.assertEqual(['cityTwo', 'cityOne', 'cityFour'] , shortest_path)	
		self.assertEqual(8000, calculations.calculate_dist(self.graph, shortest_path))
		self.assertEqual(804.0, calculations.calculate_time(self.graph, shortest_path))
		self.assertEqual(2550.0, calculations.calculate_cost(self.graph, shortest_path))
コード例 #2
0
ファイル: main.py プロジェクト: MrTerrorbyte/FlightRoutes
def shortest_route_state():
    ''' uses dijkstra's algorithm '''
    start = raw_input(
        "Type in the city name you wish to start from or type in -9 to exit\n")
    while start != '-9' and start not in graph.vertex_dict:
        print "There is no city by that name."
        start = raw_input(
            "Type in the city name you wish to start from or type in -9 to exit\n"
        )

    if start == '-9':
        exit_state()

    dest = raw_input(
        "Type in the city name you wish to end at or type in -9 to exit\n")
    while dest != '-9' and dest not in graph.vertex_dict:
        print "There is no city by that name."
        dest = raw_input(
            "Type in the city name you wish to end at or type in -9 to exit\n")

    if dest == '-9':
        exit_state()

    route_list = calculations.shortest_path(graph, start, dest)
    print "\nThe shortest route is", route_list
    print "The total distance of your route is", calculations.calculate_dist(
        graph, route_list), "kilometers"
    print "The total cost of your route is", calculations.calculate_cost(
        graph, route_list), "dollars"
    print "The total time of your route is", calculations.calculate_time(
        graph, route_list), "minutes\n"
    start_state()
コード例 #3
0
 def test_calculations(self):
     ''' using my json file, tests shortest path, cost, distance, and time '''
     json_file = open("test.json")
     json_data = json.load(json_file)
     json_file.close()
     self.graph = Graph()
     self.metros = json_data["metros"]
     self.routes = json_data["routes"]
     self.graph = self.graph.construct_json_graph(self.metros, self.routes)
     self.assertEqual(['cityTwo', 'cityOne', 'cityFour'],
                      calculations.shortest_path(self.graph, 'cityTwo',
                                                 'cityFour'))
     shortest_path = calculations.shortest_path(self.graph, 'cityTwo',
                                                'cityFour')
     self.assertEqual(['cityTwo', 'cityOne', 'cityFour'], shortest_path)
     self.assertEqual(
         8000, calculations.calculate_dist(self.graph, shortest_path))
     self.assertEqual(
         804.0, calculations.calculate_time(self.graph, shortest_path))
     self.assertEqual(
         2550.0, calculations.calculate_cost(self.graph, shortest_path))
コード例 #4
0
ファイル: main.py プロジェクト: MrTerrorbyte/FlightRoutes
def shortest_route_state():
	''' uses dijkstra's algorithm '''
	start = raw_input("Type in the city name you wish to start from or type in -9 to exit\n")
	while start != '-9' and start not in graph.vertex_dict:
		print "There is no city by that name."
		start = raw_input("Type in the city name you wish to start from or type in -9 to exit\n")
	
	if start == '-9':
		exit_state()

	dest = raw_input("Type in the city name you wish to end at or type in -9 to exit\n")
	while dest != '-9' and dest not in graph.vertex_dict:
		print "There is no city by that name."
		dest = raw_input("Type in the city name you wish to end at or type in -9 to exit\n")

	if dest == '-9':
		exit_state()
	
	route_list = calculations.shortest_path(graph, start, dest)
	print "\nThe shortest route is", route_list
	print "The total distance of your route is", calculations.calculate_dist(graph, route_list), "kilometers"
	print "The total cost of your route is", calculations.calculate_cost(graph, route_list), "dollars"
	print "The total time of your route is", calculations.calculate_time(graph, route_list), "minutes\n"
	start_state()