The consistency of the graph model

Extensions and customization
Post Reply [phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1275: count(): Parameter must be an array or an object that implements Countable
Warlax
Posts:18
Joined:19 May 2010 20:45
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1275: count(): Parameter must be an array or an object that implements Countable
The consistency of the graph model

Post by Warlax » 18 Aug 2010 04:46

Hi,

I wrote a statistic that will take a connected graph, will find each node's betweeness centrality and remove the node with the highest BC. Once that's done, it will repeat the process until the node becomes fragmented, i.e. it is no longer possible to reach every node from any other node.

It works great - until you reload the same file in a second workspace that is.
I need to reload the same file again because while I was removing nodes, I am losing information about the graph I loaded - so short of keeping a list of all removed nodes in memory and re-adding them after the statistic is done, I just reload the file again.

When I re-open the file, and run the statistic on that again - I get a different result then the one I would get for the first run. I debugged this for about 4 hours and narrowed it down to something odd.

This is how I get the graph that I use in the statistic's execute(...) method.

Code: Select all

        
        GraphController graphController = Lookup.getDefault().lookup(GraphController.class);
        ProjectController pc = Lookup.getDefault().lookup(ProjectController.class);
        GraphModel model = graphController.getModel();
        UndirectedGraph graph = model.getUndirectedGraph();
As you see, I am manually trying to assure it's the right graph -- even though I am being passed a GraphModel -- because that didn't work either.

You see, the way I check if the network is fragmented relies on checking what nodes are reachable from a node - i.e. its neighbors. To that end, I use the getNeighbors(Node) method of my UndirectedGraph object.
While debugging, it came to my attention that there's some internal ID number for each node that is completely different than the one visible in the data table view (an attribute value read from the gexf file) and from the one returned in Node.getId( ). Running the second time, I could 'hover' my mouse over the node object I got and see the number '20'. Considering that I am running my tool the second time on a network that has 35 nodes, why am I still seeing the number 20?

I don't know what to do - I've spent all day and it's getting really frustrating. I can tell that the nodes I am operating on the second time around belong to a completely new set of IDs (that I get via the Node.getId( ) method) which is fine, but the graph.getNeighbor(graph.getNode(id)) call must return a subset of the actual neighbors - and I think that has to do with the previous run of my statistic tool that has removed some nodes and their edges.

I think I must be doing something wrong or using a wrong assumption about how Gephi keeps its graph models, workspaces, and graphs in check...

What should I do?

Sorry for the long post.

User avatar
mbastian
Gephi Architect
Posts:728
Joined:10 Dec 2009 10:11
Location:San Francisco, CA
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1275: count(): Parameter must be an array or an object that implements Countable

Re: The consistency of the graph model

Post by mbastian » 18 Aug 2010 08:28

This is how I get the graph that I use in the statistic's execute(...) method.
By doing this you get the GraphModel fror the current workspace, this is fine if your current workspace is the one you want to run the metric. That's why it is better to use the GraphModel passed in the execute method. Each workspace has a single GraphModel.
While debugging, it came to my attention that there's some internal ID number for each node that is completely different than the one visible in the data table view (an attribute value read from the gexf file) and from the one returned in Node.getId( ).
Yes Gephi has two IDs, one internal the system is maintaining and one coming from import. You should use NodeData.getId() to get the one you have in the GEXF file. I'll complete the documentation of the Node.getId() to inform better users about the existence of the other identifier.

Warlax
Posts:18
Joined:19 May 2010 20:45
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1275: count(): Parameter must be an array or an object that implements Countable

Re: The consistency of the graph model

Post by Warlax » 18 Aug 2010 17:42

So what you suggest is to use node.getNodeData().getId() to identify each node uniquely.
How would I then get that node's neighbors if I use the ID to keep track of it?

In other words, what if I use the ID I get from node.getNodeData().getId() in another method which has no sense of the 'node' object? I can't use graph.getNode( ) as that relies on the ID one would get from node.getId( ) -- I am dumbfounded - don't know how to proceed.

The original question was also not properly answered: why, after removing a node using...

Code: Select all

    NodeIterator iter = graph.getNodes().iterator();
    Node node = iter.next();
    int id = node.getID();
    removeNode(id);
    .
    .
    .
    public void removeNode(int id)
    {
        graph.remove(graph.getNode(id));
    }
...and re-opening the same graph file into a separate workspace, do I still get that the node I removed is not a neighbor of any of the nodes it used to be neighbor of, even though it clearly exists in the new graph?

User avatar
mbastian
Gephi Architect
Posts:728
Joined:10 Dec 2009 10:11
Location:San Francisco, CA
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1275: count(): Parameter must be an array or an object that implements Countable

Re: The consistency of the graph model

Post by mbastian » 19 Aug 2010 08:31

So what you suggest is to use node.getNodeData().getId() to identify each node uniquely.
How would I then get that node's neighbors if I use the ID to keep track of it?
Yes, in a word don't use Node.getId() at all if you want to identify nodes between different workspaces. NodeData.getId() gives you a unique identifier that is the same in each workspace of the same file.
In other words, what if I use the ID I get from node.getNodeData().getId() in another method which has no sense of the 'node' object? I can't use graph.getNode( ) as that relies on the ID one would get from node.getId( ) -- I am dumbfounded - don't know how to proceed.
Sorry I don't get that, please show me more of your code so I can understand what is the problem.
...and re-opening the same graph file into a separate workspace, do I still get that the node I removed is not a neighbor of any of the nodes it used to be neighbor of, even though it clearly exists in the new graph?
I see an issue with your code, don't call NodeIterator.next() without calling NodeIterator.hasNext() before. That would return wrong nodes.

Warlax
Posts:18
Joined:19 May 2010 20:45
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1275: count(): Parameter must be an array or an object that implements Countable

Re: The consistency of the graph model

Post by Warlax » 19 Aug 2010 15:16

I'm not going to post the whole code, it's too big.
My question is this:

If I do this:

Code: Select all

    String id = node.getNodeData().getId();
How can I get the neighbors of that node using that id?

Code: Select all

graph.getNeighbors(id); 
needs an integer ID, like the one I would get using

Code: Select all

node.getId()
If I convert the String id to an integer, wouldn't that be the wrong ID number to use with graph.getNeighbors ?

User avatar
mbastian
Gephi Architect
Posts:728
Joined:10 Dec 2009 10:11
Location:San Francisco, CA
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1275: count(): Parameter must be an array or an object that implements Countable

Re: The consistency of the graph model

Post by mbastian » 19 Aug 2010 15:50

You should use Graph.getNode(String) method

Code: Select all

String id = node.getNodeData().getId();
graph.getNeighbors(graph.getNode(id)); 

Warlax
Posts:18
Joined:19 May 2010 20:45
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1275: count(): Parameter must be an array or an object that implements Countable

Re: The consistency of the graph model

Post by Warlax » 19 Aug 2010 15:56

Oh, excuse my stupidity. I assumed that didn't exist.

Post Reply
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1275: count(): Parameter must be an array or an object that implements Countable
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1275: count(): Parameter must be an array or an object that implements Countable