Skip to content

Partial coloring of the GO graph #5

Open

Description

@asher-pembroke

Is there a way to initialize a few nodes of the output graph? I'm trying to propagate known colors for some of the nodes, but my output graph appears to ignore them. If need be I'll post some example code.

Activity

  1. lamelizard commented on Dec 7, 2020

    @lamelizard
    Owner

    Ah, that's one of the modifications I designed but never programmed.

    GOs node colors are AFAIK never even read in the first place, in reset():

            # set possible colors per node
            for node in self.GO.nodes():
                self._values_per_node[node] = self._all_colors.copy()

    Changing that should not take long.

    What annoys me is, that there currently is no interface to change while it runs / change the allowed isomorphisms.
    But your case should be 95% of what everyone wants anyway, so for the time being that should be enough.

  2. lamelizard commented on Dec 7, 2020

    @lamelizard
    Owner

    According to my notes from 2 years back I also needed to change the constraint propagation -> done.

    @asher-pembroke, I created a new branch, (did not test it enough to release), if you could check it out, that would be great (python setup.py install, you may need to remove the version from pip first)

    I tried the following code

    import networkx as nx
    import graphwfc
    GI = nx.Graph([(1,2),(2,3),(3,4)])
    GI.add_nodes_from([(1,{'c':'b'}),(2,{'c':'b'}),(3,{'c':'r'}),(4,{'c':'y'})])
    GL = nx.Graph([(1,2)])
    GO = nx.random_tree(40)
    leaves = [x for x in GO.nodes() if GO.degree(x)==1]
    for n in leaves:
        GO.add_node(n, c='b')
    
    S = graphwfc.GraphWFCState(GO=GO,GLs=[GL],GI=GI,node_attr='c')
    while not S.run():
        S.reset()
    
    import matplotlib.pyplot as plt
    colors = list(nx.get_node_attributes(S.GO,'c').values())
    nx.draw(S.GO, node_color=colors, node_size=100)
    plt.show()
  3. lamelizard commented on Dec 7, 2020

    @lamelizard
    Owner

    Note to self: changing c='b' to c='y' tends to break (expected exception) while c='r' looks cool -> could use as example in readme if everything works out

  4. asher-pembroke commented on Dec 9, 2020

    @asher-pembroke
    Author

    Hey,
    the update works for my graph! This is great.

    What annoys me is, that there currently is no interface to change while it runs / change the allowed isomorphisms.
    But your case should be 95% of what everyone wants anyway, so for the time being that should be enough.

    Not sure if this is what you mean, but I'm trying to restrict a node's initial coloring to a subset of the available ones. I tried to specify a list for that node's color attribute, but that raises TypeError: unhashable type: 'list'

  5. lamelizard commented on Dec 9, 2020

    @lamelizard
    Owner

    What I meant was, you call run(1) to do a one step iteration, afterwards you would limit the colors, then call run() again, so that you can interact with the algorithm. AFAIK there exists a WFC implementation or two that can do that, but I would need to come up with a good interface.

    Currently I create a set with the one element given as the color attribute -> setting multiple would not work.
    I think it should work if I check if the attribute is one element of all colors or if it is a subset (there is technically an edge case, though...)
    Let's see...

  6. lamelizard commented on Dec 9, 2020

    @lamelizard
    Owner

    Updated the code;
    You should now be able to mix colors as node attributes and node attributes that can be converted to sets of colors (it has to be a subset of the colors in GI)

    import networkx as nx
    import graphwfc
    GI = nx.Graph([(1,2),(2,3),(3,4)])
    GI.add_nodes_from([(1,{'c':'b'}),(2,{'c':'b'}),(3,{'c':'r'}),(4,{'c':'y'})])
    GL = nx.Graph([(1,2)])
    GO = nx.random_tree(40)
    leaves = [x for x in GO.nodes() if GO.degree(x)==1]
    for n in leaves:
        GO.add_node(n, c=('r','y'))
    
    S = graphwfc.GraphWFCState(GO=GO,GLs=[GL],GI=GI,node_attr='c')
    while not S.run():
        S.reset()
    
    import matplotlib.pyplot as plt
    colors = list(nx.get_node_attributes(S.GO,'c').values())
    nx.draw(S.GO, node_color=colors, node_size=100)
    plt.show()

    as we override the attributes in GO, you should get the values back with S.reset()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions