Search in sources :

Example 6 with TitanKey

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();
}
Also used : Vertex(com.tinkerpop.blueprints.Vertex) DistributionGenerator(com.tinkerpop.furnace.alpha.generators.DistributionGenerator) PowerLawDistribution(com.tinkerpop.furnace.alpha.generators.PowerLawDistribution) TitanTransaction(com.thinkaurelius.titan.core.TitanTransaction) Edge(com.tinkerpop.blueprints.Edge) TitanKey(com.thinkaurelius.titan.core.TitanKey)

Aggregations

TitanKey (com.thinkaurelius.titan.core.TitanKey)6 Vertex (com.tinkerpop.blueprints.Vertex)4 TitanTransaction (com.thinkaurelius.titan.core.TitanTransaction)3 TitanGraph (com.thinkaurelius.titan.core.TitanGraph)2 Edge (com.tinkerpop.blueprints.Edge)2 TitanEdge (com.thinkaurelius.titan.core.TitanEdge)1 TitanVertex (com.thinkaurelius.titan.core.TitanVertex)1 InternalVertex (com.thinkaurelius.titan.graphdb.internal.InternalVertex)1 PerformanceTest (com.thinkaurelius.titan.testutil.PerformanceTest)1 DistributionGenerator (com.tinkerpop.furnace.alpha.generators.DistributionGenerator)1 PowerLawDistribution (com.tinkerpop.furnace.alpha.generators.PowerLawDistribution)1 Random (java.util.Random)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 Test (org.junit.Test)1