vendredi 9 avril 2021

In Which Design Pattern is the code block given below?

In this code block, I create a route map according to the city and neighbor city information given in the file and find the shortest path between the two cities with the uniform cost search algorithm in python.

Could you give a brief information about the design pattern used in this code?

I will not share all of the code, I will share its simplified version:

import...

class CityNotFoundError(Exception):
    def __init__(self, city):
        print("%s does not exist in Map Route csv file." % city)


def build_graph(dataSet):
    paths= {}
    ...  
    return paths


def uniform_cost_search(graph, start, end):
...
            print("Shoertest Path: " + str(current[1]) + ", and It's Cost = " + str(current[0]))
            break
...


if __name__ == "__main__":
    print("Enter City Road Map File Path: ")
    filePath = input()
    dataSet = pd.read_csv(filePath)
...
    cityPath = build_graph(dataSet);
    uniform_cost_search(cityPath, startCity, targetCity)

Aucun commentaire:

Enregistrer un commentaire