1

Context: I want to do shortest path search for a mobile detector, source system operating in 2D Cartesian coordinates i.e. a 20 m x 10 m space. Using igraph for python, I have created a Lattice graph over these dimensions with vertices corresponding to coordinates that the detector can travel to and edges connecting neighboring vertices. The figure below is created using the layout_grid method from igraph

enter image description here.

I want to add a simple rectangular obstruction to the space similar to the figure below and correspondingly to the Lattice graph :

https://alienryderflex.com/shortest_path/

Problem: I know that the vertices and edges corresponding to the 2D coordinates of the obstruction need to be removed using the delete_vertices method but I'm not sure how to map the 2D obstruction coordinates to the vertices in the Lattice graph. Any suggestions are appreciated.

Example code:

import numpy as np
from igraph import Graph
#Rectangular obstruction
obstruction = [[5, 0], [10, 0], [10, 5], [5, 5]]
#Create graph
g = Graph().Lattice([20.0,10.0],nei=1,circular=False)
g.delete_vertices([***obstruction coordinates***])
#Coordinates to 2D grid
coords = np.asarray(g.layout_grid(width=int(search_area[2][0])).coords)
pproctor
  • 101
  • 1
  • 10

1 Answers1

0

The original igraph documentation describes how they are labeled. If x is the column, y is the row and h is the height (second dimension) of the lattice, the following functions converts coordinate in the lattice to a vertex ID.

def coordinate_to_id(x, y, h):
    """Convert coorindate (x, y) to ID for a lattice of height h."""
    return y * w + x

Note that you will have to delete all vertices at once as igraph will update its internal identifiers.

PidgeyUsedGust
  • 797
  • 4
  • 11