0
{'a': [{'c','d'}, {'d'} ],
'b': [{'c','d'}, set() ],
'c': [set(), {'a','b','d'}],
'd': [{'a','c'}, {'a','b'} ],
'e': [set(), set() ]}
class Graph:
def __init__(self,*args):
self.edges = {}
def __le__(self,right):
for key, value in self.edges.items():
if key not in right.items() or value not in right.items():
return False
return True
定義用於比較兩個圖的< =運算符。我們定義g1的含義爲g2,因爲g1是g2的子圖,這意味着g1中存在的所有節點出現在g2中,並且g1(原始節點,目的節點)中的所有邊prsent出現在g1中G2。一般而言,對於任何圖g,g < = g的計算結果爲真。如何修正勒方法
,當我跑我的樂功能,它產生以下錯誤:
g1.edges = {'a': [{'c'},{'d'}], 'b': [{'c','d'}, set()], 'c': [set(),{'a','b'}], 'd': [{'a'},{'b'}]}
g2.edges = {'a': [{'c'},{'d'}], 'b': [{'c','d'}, set()], 'c': [set(),{'a','b','d'}], 'd': [{'a','c'},{'b'}]}
g3.edges = {'a': [{'c','d'},{'d'}], 'b': [{'c','d'}, set()], 'c': [set(),{'a','b','d'}], 'd': [{'a','c'},{'a','b'}], 'e': [set(),set()]}
104 # Test <=
111 *Error: g1 <= g1 and g2 <= g2 and g3 <= g3 raised exception; unevaluated: True
112 *Error: g1 <= g2 raised exception; unevaluated: True
113 *Error: g2 <= g3 raised exception; unevaluated: True
115 *Error: g1 <= g2 raised exception; unevaluated: False
117 *Error: g2 <= g3 raised exception; unevaluated: False
有人可以幫我解決我的樂功能?謝謝。
該圖的結構不清楚。我會期望一個節點與一個鄰居列表或一組鄰居相關聯。但是''b'是什麼:[{'c','d'},set()]'是指? – phynfo
@phynfo這是一個有向圖,所以,大概每個節點都與一對輸出/輸入弧相關聯。 ''b':[{'c','d'},set()]'意味着'b'有一個弧到'c'和'd',並且沒有與右邊圖片匹配的弧形弧。 –