79076486

Date: 2024-10-11 00:20:03
Score: 2.5
Natty:
Report link

This may be a naive answer as I've literally just installed networkx and am facing a similar problem... but would it be feasible to make a copy the graph and remove all the edges which don't meet the constraint?

import networkx as nx

MG = nx.MultiDiGraph()
MG.add_edge('a', 'b')
MG.add_edge('b', 'c')
MG.add_edge('c', 'd')
MG.add_edge('b', 'd', aura="orange")

assert nx.shortest_path(MG, 'a', 'd') == ['a', 'b', 'd']

MG_no_orange = MG.copy()
MG_no_orange.remove_edges_from(e for e in MG.edges if MG.edges[e].get('aura') == 'orange')

assert nx.shortest_path(MG_no_orange, 'a', 'd') == ['a', 'b', 'c', 'd']
Reasons:
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Me too answer (2.5): facing a similar problem
  • Ends in question mark (2):
  • High reputation (-1):
Posted by: Jack Deeth