都市や州の名前、緯度や場所などの全地球測位データを取得するプロジェクトを設計しようとしています。また、都市のすべてのペア間の距離もあります。このすべての情報を使用してグラフを作成し、それを操作していくつかのグラフアルゴリズムを実行したいと思います。各場所のデータを含む都市オブジェクトを作成することにしました。オブジェクトを区別するためのハッシュ関数が必要ですか?そして、ノードを組み合わせてエッジを削除するグラフアルゴリズムをどのように処理する必要がありますか?
def minCut(self):
"""Returns the lowest-cost set of edges that will disconnect a graph"""
smcut = (float('infinity'), None)
cities = self.__selectedcities[:]
edges = self.__selectededges[:]
g = self.__makeGRAPH(cities, edges)
if not nx.is_connected(g):
print("The graph is already diconnected!")
return
while len(g.nodes()) >1:
stphasecut = self.mincutphase(g)
if stphasecut[2] < smcut:
smcut = (stphasecut[2], None)
self.__merge(g, stphasecut[0], stphasecut[1])
print("Weight of the min-cut: "+str(smcut[1]))
本当に悪い状態です。元のプログラムを書き直していますが、これは以前のバージョンから採用したアプローチです。