Skip to content
This repository has been archived by the owner on Jul 29, 2019. It is now read-only.

Network ~900Nodes can't use improvedLayout #2906

Closed
baba2k opened this issue Mar 25, 2017 · 14 comments
Closed

Network ~900Nodes can't use improvedLayout #2906

baba2k opened this issue Mar 25, 2017 · 14 comments

Comments

@baba2k
Copy link

baba2k commented Mar 25, 2017

Hello,

i want to display a network with ~900 nodes and ~ 2500 edges with visjs. Network: http://pastebin.com/DD7BWmuT

  var options = {
     groups: {
        failure: {
           color: {
              background: 'red'
           }
        },
        state: {
           color: {
              background: 'lime'
           }
        },
        startstate: {
           font: {
              size: 33,
			  color: 'white'
           },
           color: {
              background: 'blueviolet'
           }
        },
        finalstate: {
           font: {
              size: 33,
			  color: 'white'
           },
           color: {
              background: 'blue'
           }
        }
     },
     edges: {
        arrows: {
           to: {
              enabled: true
           }
        },
    smooth: {
       enabled: false,
           type: 'continuous'
        }
     },
physics: {
        stabilization: false,
     },
	 layout: {
	    randomSeed: 191006,
	    improvedLayout: true
	 }
  };

And got the following message:
This network could not be positioned by this version of the improved layout algorithm. Please disable improvedLayout for better performance.

It takes with improvedLayout true and false 7489 iterations to stabilize.
Whats wrong with this network or configuration? Used actual version 4.19.1.

//EDIT: I've tried it with some other big networks like posted above and got this message every time.

Thank you!

@baba2k baba2k changed the title Network ~900Nodes can't use imporvedLayout Network ~900Nodes can't use improvedLayout Mar 25, 2017
@wimrijnders
Copy link
Contributor

I managed to reproduce this. I must say it looks glorious on screen:

untitled

However, the layout easing does take ages; it's still going on while I type this.

The issue, in a nutshell, is that the network is big and very interconnected.

The message:

This network could not be positioned by this version of the improved layout algorithm

...occurs because the layout algorithm attempts to divide the network into clusters, but fails. The idea of clustering is to improve performance by being able to handle the clusters independently.
However, the nodes here are so interconnected that no clustering is possible.

You can get rid of this message by setting improvedLayout: false in the options, but this, of course, doesn't solve the stabilizing-time issue.

The best ways out that I see is:

  • Reduce the number of nodes
  • Pre-assign coordinates to the nodes

Of note: for less than 100 nodes, a different layout algorithm kicks in, which should perform better.

I'm afraid I can't help further; perhaps someone more savvy than me has a better idea.

@wimrijnders
Copy link
Contributor

If the goal is to just display the network, I can offer the following idea:

  • Load the current network and let the layout easing run for a while
  • Use network.getPositions() the retrieve the calculated coordinates
  • Set these coordinates in the network data

This should display the network much faster on startup.

@wimrijnders
Copy link
Contributor

wimrijnders commented Mar 26, 2017

You can also achieve some speed improvement with the physics options. For example:

var options {
...
   physics: {
    enabled: false
   }
};

Displays instantly, nodes are so packed in a circle, you can hardly discern them.

var options {
...
   physics: {
    stabilization: {
      iterations: 500
    }
   }
};

After an initial delay, displays a decent network but much faster. It's still moving though.

It might also be worthwhile to play around with the physicsConfiguration example.

@baba2k
Copy link
Author

baba2k commented Mar 26, 2017

Thank you for your information about the algorithm and settings! Absolute positions is not an option.

I've got stabilized the network in 987 iterations 9 seconds with this options:

var options = {
    groups: {
        failure: {
            color: {
                background: 'red'
            }
        },
        state: {
            color: {
                background: 'lime'
            }
        },
        startstate: {
            font: {
                size: 33,
                color: 'white'
            },
            color: {
                background: 'blueviolet'
            }
        },
        finalstate: {
            font: {
                size: 33,
                color: 'white'
            },
            color: {
                background: 'blue'
            }
        }
    },
    edges: {
        arrows: {
            to: {
                enabled: true
            }
        },
        smooth: {
            enabled: false,
            type: 'continuous'
        }
    },
    physics: {
        adaptiveTimestep: true,
        barnesHut: {
            gravitationalConstant: -8000,
            springConstant: 0.04,
            springLength: 95
        },
        stabilization: {
            iterations: 987
        }
    },
    layout: {
        randomSeed: 191006,
        improvedLayout: true
    }
};

Is this a good solution? :-)

@wimrijnders
Copy link
Contributor

I would say that this is an excellent solution!

It would not have occurred to me to use such a huge negative gravitationalConstant, but it works.
I managed to get a still pretty decent layout with iterations : 400, so maybe you can lower it some:

untitled

But, on the whole, this is better than anything I managed to tinker up.

@wimrijnders
Copy link
Contributor

And you might as well set improvedLayout: false for a tiny extra bit of performance improvement. That algorithm is not going to kick in anyway.

@baba2k
Copy link
Author

baba2k commented Mar 26, 2017

Thank you! I thought had no performance improvement, because the iterations with improvedLayout: false are the same. I need any tiny extra bit of performance improvement.

@baba2k
Copy link
Author

baba2k commented Apr 2, 2017

Today i used Firefox to show the network. This browser needs 2468 iterations and 2 minutes to stabilize. Any idea? Thanks!

@wimrijnders
Copy link
Contributor

This issue and #2900 together represent everything I know about improving the performance of very big networks. I really don't think I can add any more to this. So please scan #2900 to see if it gives you any more idea.

@wimrijnders
Copy link
Contributor

Today i used Firefox to show the network. This browser needs 2468 iterations and 2 minutes to stabilize. Any idea? Thanks!

Revisited this issue: if I set stabilization.iterations: 2000, the stabilization takes seconds(1) and the network is stabilized.

(1) On my machine, which is admittedly a pretty hefty beast. YMMV.

@wimrijnders
Copy link
Contributor

@baba2k Did this answer your question? Is there any further assistance you need?

@wimrijnders
Copy link
Contributor

Closed due to inactivity. Feel free to reopen if this is still relevant.

@shangxinbo
Copy link

got something useful! thanks all!

@Thj007
Copy link

Thj007 commented Apr 18, 2018

now I have 7k nodes, then I'm try to use your options to draw my network, but It also use a few minutes, may be 6-10 minutes.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants