Lekcja – Podgrafy
lines = { 'BE' : ['IT', 'DE'], 'IT' : ['ES', 'PT'], 'DE' : ['PL'], 'LT' : ['SE'], 'ES' : ['DE', 'BE'], 'PT' : ['ES'], 'PL' : ['LT'], 'SE' : [] } req1 = { 'IT': ['PT'], 'PT': ['ES'], 'ES': ['BE', 'DE'] } req2 = { 'BE': ['DE'], 'DE': ['SE'] } req3 = { 'GB': ['BE'], 'BE': ['DE'] } def is_subgraph(V, V_sub): for v in V_sub.keys(): if not v in V.keys(): print('Missing node:', v) return False else: for e in V_sub[v]: if not e in V[v]: print('Missing connection:', v, e) return False return True print('REQ-1:', is_subgraph(lines, req1)) print('REQ-2:', is_subgraph(lines, req2)) print('REQ-3:', is_subgraph(lines, req3))
Lab
cantor = { 'EUR' : ['USD', 'GBP', 'CHF'], 'USD' : ['EUR', 'GBP', 'CHF'], 'SEK' : ['EUR'], 'JPY' : ['EUR', 'USD'], 'CAD' : ['USD', 'EUR'], 'GBP' : [], 'CHF' : [] } client1 = { 'EUR' : ['USD'], 'USD' : [] } client2 = { 'EUR' : ['CAD'], 'USD' : ['EUR' ], 'SEK' : ['EUR'], 'CAD' : [] } client3 = { 'JPY' : [], 'EUR' : ['USD'], 'USD' : ['JPY'] } def is_subgraph(V, V_sub): for v in V_sub.keys(): if not v in V.keys(): print('Missing node:', v) return False else: for e in V_sub[v]: if not e in V[v]: print('Missing connection:', v, e) return False return True print(f"Client1: {is_subgraph(cantor, client1)}") print(f"Client2: {is_subgraph(cantor, client2)}") print(f"Client3: {is_subgraph(cantor, client3)}")