[phpBB Debug] PHP Warning: in file [ROOT]/phpbb/session.php on line 583: sizeof(): Parameter must be an array or an object that implements Countable
[phpBB Debug] PHP Warning: in file [ROOT]/phpbb/session.php on line 639: sizeof(): Parameter must be an array or an object that implements Countable
[phpBB Debug] PHP Warning: in file [ROOT]/includes/functions.php on line 4516: Cannot modify header information - headers already sent by (output started at [ROOT]/includes/functions.php:3262)
[phpBB Debug] PHP Warning: in file [ROOT]/includes/functions.php on line 4516: Cannot modify header information - headers already sent by (output started at [ROOT]/includes/functions.php:3262)
[phpBB Debug] PHP Warning: in file [ROOT]/includes/functions.php on line 4516: Cannot modify header information - headers already sent by (output started at [ROOT]/includes/functions.php:3262)
Gephi forums •Wait until filter finishes?
Page 1 of 1

Wait until filter finishes?

Posted: 20 Aug 2013 18:52
by Apple Cider
Hello,

I've got a function which filters the graph and auto-lays it out. The trouble is, the filtering doesn't complete before it starts the layout. This is probably very basic, but what would be a good way to wait for filtering to complete before proceeding with the autolayout? It seems with FilterController's filterVisible(Query) method it spins off a new Thread, but I'm not sure how to deal with it. Here's what I've got going:

Code: Select all

public void filter() {
            Partition<Node> categoryPartition = partitionController.buildPartition(nodeCategory, graph);
            
            String[] categories = new String[]{"SOURCE", "SCORED", "BRIDGE"};
            Query categoryQuery = FilterUtils.createNodeQuery(categoryPartition, categories);
            Query distQuery = FilterUtils.createNeighborhoodQuery(source, 1);
            
            Query query = FilterUtils.unionQueries(new Query[]{categoryQuery, distQuery});
            
            filterController.filterVisible(query);
        }

public void layout() {
            AutoLayout layout = new AutoLayout(1, TimeUnit.SECONDS);
            layout.setGraphModel(graphModel);
            
            ForceAtlasLayout forceDirectedLayout = new ForceAtlasLayout(null);
            AutoLayout.DynamicProperty repulsionProperty = 
                AutoLayout.createDynamicProperty("forceAtlas.repulsionStrength.name",
                                                 5000D, 0f);
            layout.addLayout(forceDirectedLayout, 1f, 
                             new AutoLayout.DynamicProperty[]{repulsionProperty});
        
            layout.execute();
}
And it's executed as a LongTask in this function:

Code: Select all

public void execute() {
        Progress.setDisplayName(progressTicket, "Analytic running...");
        Progress.start(progressTicket);
        
        Progress.progress(progressTicket, "Loading graph into Gephi...");
        performImport();
        
        Progress.progress(progressTicket, "Filtering graph...");
        filter();
        
        Progress.progress(progressTicket, "Laying out graph...");
        layout();
        //and so forth...
}
I'm not sure if this is more of a Toolkit question, so apologies if it belongs there! Thanks for the help!

Re: Wait until filter finishes?

Posted: 24 Aug 2013 08:43
by seinecle
I'm not a pro Java dev so this answer might be plain wrong, but at least it will take you 2 seconds to test:
=> put a return variable to your filter method:

Code: Select all

public [b]String[/b] filter() {
            Partition<Node> categoryPartition = partitionController.buildPartition(nodeCategory, graph);
            
            String[] categories = new String[]{"SOURCE", "SCORED", "BRIDGE"};
            Query categoryQuery = FilterUtils.createNodeQuery(categoryPartition, categories);
            Query distQuery = FilterUtils.createNeighborhoodQuery(source, 1);
            
            Query query = FilterUtils.unionQueries(new Query[]{categoryQuery, distQuery});
            
            filterController.filterVisible(query);

            [b]return "filtered!";[/b]
       }
Then in your execute method:

Code: Select all

          String result = filter();
This should definitely make the layout() function wait for the filter() function to return a result before getting initiated. Still I am a bit surprised because I thought Java was synchronous all the way - but it would seem that void methods are run asynchronously?