http://www.perlmonks.org?node_id=1047544


in reply to Re^5: Optimization Help
in thread Optimization Help

Mapping is of total length equal to $#{$self->Matrix}, and represents the mapping of a node in graph 1 to the node in graph 2. So the first element in $mapping indicates that the first node in the graph1 is mapped to said node in graph 2, with -1 indicating no match. Most of the time, the size of $mapping is in the 20 to 150 element range, although there are outliers.

Below is an example of how mapping changes when comparing two identical graphs:

-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,- +1 0,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1 0,1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1 0,1,2,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1 0,1,2,3,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1 0,1,2,3,4,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1 0,1,2,3,4,5,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1 0,1,2,3,4,5,6,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1 0,1,2,3,4,5,6,7,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1 0,1,2,3,4,5,6,7,8,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1 0,1,2,3,4,5,6,7,8,9,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1 0,1,2,3,4,5,6,7,8,9,10,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1 0,1,2,3,4,5,6,7,8,9,10,11,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1 0,1,2,3,4,5,6,7,8,9,10,11,12,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1 0,1,2,3,4,5,6,7,8,9,10,11,12,13,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,-1,-1,-1,-1,-1,-1,-1,-1,-1 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,-1,-1,-1,-1,-1,-1,-1,-1 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,-1,-1,-1,-1,-1,-1,-1 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,-1,-1,-1,-1,-1,-1 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,-1,-1,-1,-1,-1 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,-1,-1,-1,-1 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,-1,-1,-1 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,-1,-1 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,-1

And here with dissimilar graphs:

-1,-1,-1,-1,-1,-1,-1,-1,-1,-1 0,-1,-1,-1,-1,-1,-1,-1,-1,-1 0,-1,-1,-1,-1,-1,-1,-1,-1,-1 1,-1,-1,-1,-1,-1,-1,-1,-1,-1 1,-1,-1,-1,-1,-1,-1,-1,-1,-1 3,-1,-1,-1,-1,-1,-1,-1,-1,-1 3,-1,-1,-1,-1,-1,-1,-1,-1,-1 4,-1,-1,-1,-1,-1,-1,-1,-1,-1 4,-1,-1,-1,-1,-1,-1,-1,-1,-1 6,-1,-1,-1,-1,-1,-1,-1,-1,-1 6,-1,-1,-1,-1,-1,-1,-1,-1,-1 8,-1,-1,-1,-1,-1,-1,-1,-1,-1 8,-1,-1,-1,-1,-1,-1,-1,-1,-1

Replies are listed 'Best First'.
Re^7: Optimization Help
by BrowserUk (Patriarch) on Aug 02, 2013 at 06:32 UTC

    In Re^2: Optimization Help you said : "the mapping vector is 1D", but the mappings you've posted above look like 2D?

    (It looks like there is considerable scope for further optimisations. Particularly in the "similar" case, but I'd need to see what you actually pass to the sub for $mapping?)


    With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.
      Sorry those are separate vectors, each line is a separate I didn't make that very clear...

      <-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1> is the first mapping vector, <0,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1> is the second and so on.

      #IDENTICAL / SIMILAR vectors: -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,- +1 0,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1 0,1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1 0,1,2,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1 0,1,2,3,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1 0,1,2,3,4,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1 0,1,2,3,4,5,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1 0,1,2,3,4,5,6,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,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1,-1,-1,-1,-1,-1,-1,-1,-1 1,-1,-1,-1,-1,-1,-1,-1,-1,-1 3,-1,-1,-1,-1,-1,-1,-1,-1,-1 3,-1,-1,-1,-1,-1,-1,-1,-1,-1 4,-1,-1,-1,-1,-1,-1,-1,-1,-1 4,-1,-1,-1,-1,-1,-1,-1,-1,-1 6,-1,-1,-1,-1,-1,-1,-1,-1,-1 6,-1,-1,-1,-1,-1,-1,-1,-1,-1 8,-1,-1,-1,-1,-1,-1,-1,-1,-1 8,-1,-1,-1,-1,-1,-1,-1,-1,-1

      Yeah, we've struggled with that, the similar case, for a while here in the lab, the way we are doing it now is vastly better than the original algorithm by Ullmann we were using.

        the way we are doing it now is vastly better than the original algorithm by Ullmann we were using.

        So, you are searching for subgraph isomorphisms?

        If so, is it possible for you to describe what the graphs are and what you are looking for when comparing them, in terms of the underlying data rather than graph theory?

        I ask because I've never yet encountered a real use for a graph theory algorithm that wasn't more efficiently coded by ignoring graph theory.

        As with all theoretical algorithms; GT algorithms have to deal with, and work for, all possible graphs of the given type regardless of what data and data relationships they actually represent.

        In every real-world case I remember, knowledge of the actual data and required results allowed me to make assumptions and take short cuts that the theorists cannot.


        With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
        Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
        "Science is about questioning the status quo. Questioning authority".
        In the absence of evidence, opinion is indistinguishable from prejudice.
        Also, I should state that these are not all of the mapping vectors generated during the enumeration process, just some of them at different time points. The latter vectors were generated after the earlier ones in the list. However, the ones I did not print off are essentially the same. Can't print all of them, too many.