Search in sources :

Example 36 with NodeDraft

use of org.gephi.io.importer.api.NodeDraft in project gephi by gephi.

the class MultiGraph method generate.

@Override
public void generate(ContainerLoader container) {
    NodeDraft[] nodeArray = new NodeDraft[numberOfNodes];
    for (int i = 0; i < numberOfNodes; i++) {
        NodeDraft nodeDraft = container.factory().newNodeDraft("n" + i);
        container.addNode(nodeDraft);
        nodeArray[i] = nodeDraft;
    }
    String[] edgeTypes = new String[numberOfEdgeTypes];
    for (int i = 0; i < edgeTypes.length; i++) {
        edgeTypes[i] = "Type " + i;
    }
    Random random = new Random();
    if (wiringProbability > 0) {
        for (int i = 0; i < numberOfNodes - 1; i++) {
            NodeDraft node1 = nodeArray[i];
            for (int j = i + 1; j < numberOfNodes; j++) {
                NodeDraft node2 = nodeArray[j];
                if (random.nextDouble() < wiringProbability) {
                    if (random.nextDouble() < 0.3) {
                        // Double
                        EdgeDraft edgeDraft1 = container.factory().newEdgeDraft();
                        edgeDraft1.setSource(node1);
                        edgeDraft1.setTarget(node2);
                        edgeDraft1.setType(edgeTypes[0]);
                        edgeDraft1.setLabel((String) edgeDraft1.getType());
                        container.addEdge(edgeDraft1);
                        EdgeDraft edgeDraft2 = container.factory().newEdgeDraft();
                        edgeDraft2.setSource(node1);
                        edgeDraft2.setTarget(node2);
                        edgeDraft2.setType(edgeTypes[1]);
                        edgeDraft2.setLabel((String) edgeDraft2.getType());
                        container.addEdge(edgeDraft2);
                    } else {
                        // Single
                        EdgeDraft edgeDraft = container.factory().newEdgeDraft();
                        edgeDraft.setSource(node1);
                        edgeDraft.setTarget(node2);
                        edgeDraft.setType(edgeTypes[random.nextInt(edgeTypes.length)]);
                        edgeDraft.setLabel((String) edgeDraft.getType());
                        container.addEdge(edgeDraft);
                    }
                }
            }
        }
    }
}
Also used : EdgeDraft(org.gephi.io.importer.api.EdgeDraft) Random(java.util.Random) NodeDraft(org.gephi.io.importer.api.NodeDraft)

Aggregations

NodeDraft (org.gephi.io.importer.api.NodeDraft)36 EdgeDraft (org.gephi.io.importer.api.EdgeDraft)17 Issue (org.gephi.io.importer.api.Issue)15 IOException (java.io.IOException)5 StringTokenizer (java.util.StringTokenizer)5 Random (java.util.Random)4 SQLException (java.sql.SQLException)2 ColumnDraft (org.gephi.io.importer.api.ColumnDraft)2 ResultSet (java.sql.ResultSet)1 ResultSetMetaData (java.sql.ResultSetMetaData)1 Statement (java.sql.Statement)1 Map (java.util.Map)1 Matcher (java.util.regex.Matcher)1 Pattern (java.util.regex.Pattern)1 Edge (org.gephi.graph.api.Edge)1 Graph (org.gephi.graph.api.Graph)1 GraphController (org.gephi.graph.api.GraphController)1 GraphFactory (org.gephi.graph.api.GraphFactory)1 Node (org.gephi.graph.api.Node)1 ContainerUnloader (org.gephi.io.importer.api.ContainerUnloader)1