Network.add_node

Network.add_node is not functioning the way Network.add_vertex used to work!
For some reason, when I add a node random edges are produced and random nodes are removed.

can you post an example?

starting network:

use network.delete_edge to remove one pair of crossings:

add a node at the crossing point of the removed edges:

from compas.datastructures import Network
from compas.geometry import intersection_line_line_xy
from compas_plotters import NetworkPlotter

nodes = [[0, 0, 0], [1, 0, 0], [2, 0, 0], [0, 1, 0], [1, 1, 0], [2, 1, 0]]
edges = [[0, 1], [1, 2], [3, 4], [4, 5], [0, 3], [1, 4], [2, 5], [0, 4], [1, 5], [1, 3], [2, 4]]
network = Network.from_nodes_and_edges(nodes, edges)

e1 = network.edge_coordinates(0, 4)
e2 = network.edge_coordinates(1, 3)

xyz = intersection_line_line_xy(e1, e2)

network.delete_edge(0, 4)
network.delete_edge(1, 3)

x = network.add_node(x=xyz[0], y=xyz[1], z=xyz[2])

network.add_edge(x, 0)
network.add_edge(x, 1)
network.add_edge(x, 3)
network.add_edge(x, 4)

plotter = NetworkPlotter(network, figsize=(8, 5))
plotter.draw_nodes(text='key', radius=0.03)
plotter.draw_edges()
plotter.show()

produces this

is that not what you want?

Well, I was doing the exact same thing, but I found out that I was copying the network, to keep the first one intact, and that caused the problem.

If I run your code also with the net=network.copy() before doing the changes, and do the modifications on the net, I won’t get the same result!

Do you know what is happening here?

yes sorry my mistake. update compas and try again :slight_smile:

just FYI,

i had forgotten to make the max_int_key part of the data attribute for serialisation.
this is used in the background for making an independent copy and therefore auto-increment would use 0 as the next available integer after copying…

1 Like