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);
}
}
}
}
}
}
Aggregations