[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 •Editing the graph on the fly
Page 1 of 1

Editing the graph on the fly

Posted: 20 Dec 2010 16:20
by dcombe
Hello.
I want to create a plugin which is able to modify the graph while it is executed.
I started using the statistics plugin template. Here is what it looks like :

Code: Select all

public void execute(GraphModel graphModel, AttributeModel attributeModel) {
        Graph graph = graphModel.getGraphVisible();
        graph.readLock();
        
        try {
            Progress.start(progressTicket, graph.getNodeCount());

            // For edges that will be removed
           Vector<Edge> edges=new Vector<Edge>();
            int i=0;
            
            for (Node m : graph.getNodes()) {
                    int m_inf_n=1;
                    for (Node n : graph.getNodes()) {
                        if(m_inf_n==1){// in order to test only one time each couple of nodes
                            if(!m.equals(n))
                                m_inf_n=0;
                            continue;
                        }
                        if(TEST){
                                Edge e=graphModel.factory().new Edge(m, n);
                                edges.add(e);
                        }
                    }
                Progress.progress(progressTicket);
                if (cancel) {
                    break;
                }
            }
            graph.readUnlockAll();
            graph.writeLock();

            //Writing the new edges
            for( Edge e : edges){
                    graph.addEdge(e);
            }
            
            graph.readUnlockAll();
        } catch (Exception e) {
            // print stack trace as report
            StringWriter sw=new StringWriter();
            PrintWriter pw=new PrintWriter(sw, true);
            e.printStackTrace(pw);
            pw.flush();
            sw.flush();
            res+= sw.toString();
        } finally {
            //Unlock graph
            graph.readUnlockAll();
        }
    }
The application appear unstable after the execution of the function.
Am I editing the graph in a good manner ? Should I use an EdgeDraft instead ? Do I need to refresh some display ?

David

Re: Editing the graph on the fly

Posted: 21 Dec 2010 08:24
by mbastian
Hi David, it seems you are not closing the write lock you opened. That is critical and will eventually crash the application.

Code: Select all

            graph.writeLock();

            //Writing the new edges
            for( Edge e : edges){
                    graph.addEdge(e);
            }
           
            graph.writeUnlock();

Re: Editing the graph on the fly

Posted: 26 Nov 2014 07:19
by wicky10
Should I use an EdgeDraft instead ? http://pass4-sure.ws/Do I need to refresh some display ?