I am storing the open coords as two attributes in one list:
self.x, self.y = []
My attempt at an edge list (lifted from stack overflow lol):
edge = []
for i in self.x, self.y:
for j in i[1]:
edge.append([i[0], j])
for i in edge:
print(i)
Whenever I try this the error:
for j in i[1]:
TypeError: 'int' object is not subscriptable
comes up.
I'm guessing this is because it's a tuple? I am trying to create an adjacency list with weighted edges of the distance between the coords, but I haven't thought about adding the weights yet.
The coords, when added to a big list, look like this:
[[[0, 0], [1, 0], [2, 0].....]]
But when I insert them into the class, I do it separately.
On another note, can I store the all coords into one attribute like this effectively? Or would the attribute overwrite each time and only do one coord??
I was expecting, or hoped, that it would create edges between nodes to then create an adjacency list (of which I have no clue how to code either). With the completed graph, I aim to create an a* algorithm..
Sorry, if this may be obvious but I haven't coded properly in a very long time. I am aware it is kinda messy.
Thank you.
Something like this?
which prints:
itertools.product(range(3), range(3))produces:In calling the method to build the adjacency list, all coordinates-tuple combinatorial (cartesian product, specifically) pairwise (excluding self-pairs...) connections were added to the dictionary for each individual coordinates tuple. This is what is printed above as the output. Below this is visualized.
Visualize the adjacency list as a network graph
And also, visualizing a slightly different pyvis+networkx graph, where the calculated distances (used to represent 'weights' in the example here) have an influence (e.g., by instead setting
net.barnes_hut()):