use of com.thinkaurelius.titan.core.TitanKey in project titan by thinkaurelius.
the class GraphGenerator method generateData.
/**
* Generate a scale-free graph using parameters specified in the
* {@link Schema} object provided to this instance's constructor. The types
* must already exist. The types can be created by either calling
* {@link #generateTypesAndData(TitanGraph)} instead of this method or by
* calling {@link Schema#makeTypes(TitanGraph)} before calling this method.
*
* @param g A graph with types predefined. If it already contains vertices
* or relations, they may be overwritten.
*/
public void generateData(TitanGraph g) {
// Generate vertices
for (long i = uidCounter; i < schema.getVertexCount() + INITIAL_VERTEX_UID - 1; i++) {
Vertex v = g.addVertex(i);
// DistributionGenerator doesn't currently support VertexAnnotator
vertexAnnotator.annotate(v, null);
}
// Generate edges
for (int i = 0; i < schema.getEdgeLabels(); i++) {
DistributionGenerator gen = new DistributionGenerator(schema.getEdgeLabelName(i), edgeAnnotator);
gen.setOutDistribution(new PowerLawDistribution(GAMMA));
gen.setInDistribution(new PowerLawDistribution(GAMMA));
gen.generate(g, schema.getEdgeCount());
}
g.commit();
TitanTransaction tx = g.newTransaction();
// Add a vertex that has an out edge to every other vertex
Vertex hiOutDeg = tx.addVertex(Schema.SUPERNODE_UID);
String label = schema.getSupernodeOutLabel();
TitanKey uidKey = tx.getPropertyKey(Schema.UID_PROP);
hiOutDeg.setProperty(Schema.UID_PROP, Schema.SUPERNODE_UID);
String pKey = schema.getSortKeyForLabel(label);
for (long i = INITIAL_VERTEX_UID; i < schema.getVertexCount(); i++) {
Vertex in = tx.getVertex(uidKey, i);
Edge e = hiOutDeg.addEdge(label, in);
e.setProperty(pKey, (int) i);
}
tx.commit();
}
Aggregations