#python-3.x #shapely
#python #igraph #стройный
Вопрос:
Я пытаюсь определить ребра графа, которые пересекаются, на основе некоторых ограничений. Мой код выглядит следующим образом:
#getCellPinPts returns coordinates of the vertex
# I am using igraph and shapely packages
linestrings = [LineString((getCellPinPts(G.es[edge]["startCell"],cellMid[G.es[edge]["nameIdx"]],
G.es[edge]["pin"], G["stepSize"]),
getCellPinPts(G.es[edge]["endCell"],cellMid[G.es[edge]["endNameIdx"]],
G.es[edge]["endPin"], G["stepSize"]))) for edge in range(len(G.es))]
intersect = [ 1 for idx1,x in enumerate(linestrings) for idx2,y in enumerate(linestrings) if idx1<idx2
and x.intersects(y)
and not(G.es[idx1]["family"] == G.es[idx2]["family"])
]
totalIntersections = np.sum(intersect)
Проблемы связаны с вложенным циклом, для вычисления пересечений требуется много времени. Есть ли способ ускорить код пересечения?