from itertools import combinations from compas.datastructures import Network from compas.utilities import linspace, meshgrid from compas_rhino.artists import NetworkArtist X, Y = meshgrid(linspace(0, 10, 10), linspace(0, 5, 5)) points = [] for z in linspace(0, 3, 3): for xs, ys in zip(X, Y): for x, y in zip(xs, ys): points.append([x, y, z]) network = Network() for point in points: network.add_node(x=point[0], y=point[1], z=point[2]) for a, b in combinations(network.nodes(), 2): if network.node_attribute(a, 'z') != network.node_attribute(b, 'z'): network.add_edge(a, b) artist = NetworkArtist(network, layer="ITA20::Network") artist.clear_layer() artist.draw_nodes() artist.draw_edges()
network.add_edge(a, e) network.add_edge(b, e) network.add_edge(c, e) network.add_edge(d, e) # compute all residuals in the current geometry for node in network.nodes(): r = compute_residual(network, node) network.node_attributes(node, ['rx', 'ry', 'rz'], r) # move free nodes in direction of residual for node in network.nodes(): if network.node_attribute(node, 'is_anchor'): continue rx, ry, rz = network.node_attributes(node, ['rx', 'ry', 'rz']) x0, y0, z0 = network.node_attributes(node, 'xyz') x1 = x0 + 0.5 * rx y1 = y0 + 0.5 * ry z1 = z0 + 0.5 * rz network.node_attributes(node, 'xyz', [x1, y1, z1]) # compute all residuals in the new geometry for node in network.nodes(): r = compute_residual(network, node) network.node_attributes(node, ['rx', 'ry', 'rz'], r)
import random from compas_rhino.artists import NetworkArtist from compas.datastructures import Network network = Network() last_node = None for i in range(12): node = network.add_node(x=i // 3, y=i % 3, z=0) network.node_attribute(node, 'weight', random.choice(range(20))) if last_node: network.add_edge(node, i - 1) last_node = node print(network.summary()) print(network.to_data()) text = { node: network.node_attribute(node, 'weight') for node in network.nodes() } artist = NetworkArtist(network, layer='network') artist.clear_layer() artist.draw_nodelabels(text) artist.draw() artist.redraw()
self.value = value or random.choice(range(20)) @property def data(self): return {'value': self.value} @data.setter def data(self, data): self.value = data['value'] network = Network() last_node = None for i in range(12): node = network.add_node(x=i // 3, y=i % 3, z=0) network.node_attribute(node, 'weight', Weight()) if last_node: network.add_edge(node, i - 1) last_node = node print(network.summary()) # print(network.to_data()) network.to_json(__file__ + '.json') network2 = Network.from_json(__file__ + '.json') print(network2.summary()) # print(network2.to_data())