Exemple #1
0
def dijkstra_shortest_path(start_node, dest_node):
    """
            Test Dijkstra's shortest path in comparison to networkx's shortest_path.

            Parameters:
            -----------
            start_node: networkx Node
                The starting node.
            dest_node: networkx Node
                The ending node.

            Passing Criteria:
            --------
            Both path lengths must be the same.

        """
    context = Context(strategies.StrategyDijkstra(graph, 0, 'vanilla'))
    path = context.run_strategy_route(start_node, dest_node)
    regular_path_length = graph_utils.get_path_length(graph, path)
    print("Dijkstra shortest path", path)
    nx_shortest_path = shortest_path(start_node, dest_node)
    nx_shortest_path_length = graph_utils.get_path_length(
        graph, nx_shortest_path)
    if nx_shortest_path_length == regular_path_length:
        print("Test Passed")
    else:
        print("Test Failed")
    print("\n")
Exemple #2
0
def dijkstra_max_elevation_grade(start_node, dest_node):
    """
                    Test Dijkstra's max elevation path using grade as the weight.

                    Parameters:
                    -----------
                    start_node: networkx Node
                        The starting node.
                    dest_node: networkx Node
                        The ending node.

                    Passing Criteria:
                    --------
                    max_elevation path must have the smaller path length than the limit
                     and grade is greater than regular greater.

                """
    print("Dijkstra max elevation using grade as weight")
    context = Context(strategies.StrategyDijkstra(graph, limit, 'max grade'))
    path = context.run_strategy_route(start_node, dest_node)
    print("Elevation path", path)
    grade = graph_utils.get_average_grade(graph, path)
    max_path_length = graph_utils.get_path_length(graph, path)

    context = Context(strategies.StrategyDijkstra(graph, 0, 'vanilla'))
    path = context.run_strategy_route(start_node, dest_node)
    print("Vanilla path", path)
    regular_grade = graph_utils.get_average_grade(graph, path)
    regular_path_length = graph_utils.get_path_length(graph, path)
    max_length = regular_path_length * (1 + limit)
    print("Vanilla path length:", regular_path_length,
          "\nMax Possible Path length:", max_length,
          "\nLength of elevation path:", max_path_length)
    print("Vanilla path Grade:", round(regular_grade, 2), "\nNew Grade:",
          round(grade, 2))
    if max_path_length <= max_length:
        if grade >= regular_grade:
            print("Test Passed")
        else:
            print(
                "Test Passed: Path length. Dijkstra's wasn't able to maximize grade"
            )
    else:
        print("Test Failed")
    print("\n")
Exemple #3
0
def dijkstra_min_elevation(start_node, dest_node):
    """
                Test Dijkstra's min elevation path using elevation as the weight.

                Parameters:
                -----------
                start_node: networkx Node
                    The starting node.
                dest_node: networkx Node
                    The ending node.

                Passing Criteria:
                --------
                min_elevation path must have the smaller path length than the limit
                 and min_elevation is less than regular elevation.

    """
    print("Dijkstra min elevation using elevation change as weight")
    context = Context(
        strategies.StrategyDijkstra(graph, limit, 'min elevation_change'))
    path = context.run_strategy_route(start_node, dest_node)
    print("Elevation path", path)
    elevation = graph_utils.get_path_elevation(graph, path)
    max_path_length = graph_utils.get_path_length(graph, path)

    context = Context(strategies.StrategyDijkstra(graph, 0, 'vanilla'))
    path = context.run_strategy_route(start_node, dest_node)
    print("Vanilla path", path)
    regular_elevation = graph_utils.get_path_elevation(graph, path)
    regular_path_length = graph_utils.get_path_length(graph, path)
    max_length = regular_path_length * (1 + limit)
    print("Vanilla path length:", regular_path_length,
          "\nMax Possible Path length:", max_length,
          "\nLength of elevation path:", max_path_length)
    print("Vanilla path Elevation:", regular_elevation, "\nNew Elevation:",
          elevation)
    if max_path_length <= max_length and elevation <= regular_elevation:
        print("Test Passed")
    else:
        print("Test Failed")
    print("\n")