Source code for dynamo.vectorfield.vfGraph_deprecated

import igraph as ig
import numpy as np

class ConverterMixin(object):
    """Answer by FastTurtle"""

    def convert_to_class(cls, obj):
        obj.__class__ = cls

[docs]class vfGraph(ConverterMixin, ig.Graph): """A class for manipulating the graph creating from the transition matrix, built from the (reconstructed) vector field. This is a derived class from igraph's Graph. """
[docs] def __init__(self, *args, **kwds): super(vfGraph, self).__init__(*args, **kwds)
def build_graph(self, adj_mat): """build sparse diffusion graph. The adjacency matrix needs to preserves divergence.""" sources, targets = adj_mat.nonzero() edgelist = list(zip(sources.tolist(), targets.tolist())) self.__init__( edgelist, edge_attrs={"weight":}, directed=True, ) def multimaxflow(self, sources, sinks): """Multi-source multi-sink maximum flow. Ported from""" v_num, e_num = self.vcount(), self.ecount() usrc = v_num # super-source usink = usrc + 1 # super-sink new_edges = np.hstack( [ np.vstack(([usrc] * len(sources), sources)), np.vstack((sinks, [usink] * len(sinks))), ] ).T self.add_vertices(2) self.add_edges(new_edges) w_sum = sum("weight")[:e_num])["weight"] = [i if i is not None else w_sum for i in["weight"]] mf = self.maxflow(usrc, usink,"weight"))"flow", mf.flow) self.vs.set_attribute_values("pass", self.strength(mode="in", weights=mf.flow)) self.delete_vertices([usrc, usink])
# add gradop, ...