All Downloads are FREE. Search and download functionalities are using the official Maven repository.

cdc.graphs.impl.tests.RandomGraphGenerator Maven / Gradle / Ivy

There is a newer version: 0.71.2
Show newest version
package cdc.graphs.impl.tests;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

public final class RandomGraphGenerator {
    private final Random random = new Random();

    public RandomGraphGenerator() {
        super();
    }

    public void setSeed(long seed) {
        random.setSeed(seed);
    }

    public > void fill(TestGraph graph,
                                                                 int nodesCount,
                                                                 int edgesCount) {

        final List nodes = new ArrayList<>();
        for (int index = 0; index < nodesCount; index++) {
            nodes.add(graph.getOrCreateNode("N" + index));
        }
        for (int index = 0; index < edgesCount; index++) {
            final N source = nodes.get(random.nextInt(nodesCount));
            final N target = nodes.get(random.nextInt(nodesCount));
            graph.createEdge("E" + index, source, target);
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy