Skip to content

Better docs or API for building graphs w/ custom objects #859

@fubuloubu

Description

@fubuloubu

What is the feature or improvement you would like to see?

Just found this library today, have been using NetworkX to build a production solution for a set of graph problems using custom objects that fetch live information from different sources. I didn't see any documentation on how to do this, but I am looking for an easy way where I can do something like this:

class VertexType(ig.Vertex):
    def __hash__(self) -> int:  # or whatever easy way that igraph can use to represent a node internally
        ...

    # has other properties and methods I can use with igraph's solver algorithms

class EdgeType(ig.Edge):
    def __init__(self, a: VertexType, b: VertexType):
        self.a, self.b = a, b

    def __iter__(self) -> Iterator[VertexType]:  # or whatever way to best represent an edge
        return iter((self.a, self.b))

    # has other properties and methods I can use with igraph's solver algorithms

# Assemble the graph somehow
vs = [VertexType(...), VertexType(...), ..., VertexType(...)]
es = [EdgeType(*vs[:2]), EdgeType(*vs[1:3]), ...]
g = ig.Graph(vs, edges=es)
# Then do stuff w/ `g`

Use cases for the feature

This would be extremely useful because my use case involves a high degree of live-updating the attributes of these objects, and would prefer them as object references to make it much easier and more maintainable to work with. If this seems out of scope for this library, or if there is a better option for it, just let me know

References
n/a

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions