私は、都市や州の名前や緯度や場所などのグローバルな測位データを取るプロジェクトを設計しようとしています。私はまた、すべての都市の間に距離を持っています。私はこの情報すべてを使ってグラフを作成し、それを操作していくつかのグラフアルゴリズムを実行したいと思います。私は各場所のデータを含む都市オブジェクトを持つことに決めました。オブジェクトを区別するためのハッシュ関数が必要ですか?ノードを結合しエッジを削除するグラフアルゴリズムをどのように処理すればよいですか?オブジェクトをnetworkxで動作させるにはどうすればいいですか?
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]))
これは本当に悪い形です。私は元のプログラムを書き直していますが、これは以前のバージョンから取ったアプローチです。
:ここ
は(愚かな)の例ですか? – Spaceghost