src/main/java/org/thegalactic/dgraph/DAGraph.java
public static DAGraph<Integer, ?> random(int size, double threshold) {
        DAGraph<Integer, ?> graph = new DAGraph<Integer, Object>();
        // addition of Nodes
        for (int i = 1; i <= size; i++) {
            graph.addNode(new Node<Integer>(Integer.valueOf(i)));
        }
        // addition of edges
        for (Node<Integer> source : graph.getNodes()) {
            for (Node<Integer> target : graph.getNodes()) {
                // Test to avoid cycles
                if (source.compareTo(target) > 0) {
                    if (Math.random() < threshold) {
                        graph.addEdge(source, target);
                    }
                }
            }
        }
        return graph;
    }
/**
     * Generates a random directed and acyclic graph (DAG) of size nodes.
     *
     * @param size      the number of nodes of the generated graph
     * @param threshold the threshold to generate an edge
     *
     * @return a random acyclic graph
     */
Generates a random directed and acyclic graph (DAG) of size nodes.
@param size      the number of nodes of the generated graph
@param threshold the threshold to generate an edge

@return a random acyclic graph
Generates a random directed and acyclic graph ( DAG ) of size nodes . @param size the number of nodes of the generated graph @param threshold the threshold to generate an edge @return a random acyclic graph
public static DAGraph<Integer, ?> random(int size, double threshold) {
        DAGraph<Integer, ?> graph = new DAGraph<Integer, Object>();
        for (int i = 1; i <= size; i++) {
            graph.addNode(new Node<Integer>(Integer.valueOf(i)));
        }
        for (Node<Integer> source : graph.getNodes()) {
            for (Node<Integer> target : graph.getNodes()) {
                if (source.compareTo(target) > 0) {
                    if (Math.random() < threshold) {
                        graph.addEdge(source, target);
                    }
                }
            }
        }
        return graph;
    }
public static DAGraph < Integer , ? > random ( int size , double threshold ) { DAGraph < Integer , ? > graph = new DAGraph < Integer , Object > ( ) ; for ( int i = 1 ; i <= size ; i ++ ) { graph . addNode ( new Node < Integer > ( Integer . valueOf ( i ) ) ) ; } for ( Node < Integer > source : graph . getNodes ( ) ) { for ( Node < Integer > target : graph . getNodes ( ) ) { if ( source . compareTo ( target ) > 0 ) { if ( Math . random ( ) < threshold ) { graph . addEdge ( source , target ) ; } } } } return graph ; }
Generates a random directed and acyclic graph (DAG) of size nodes.
Generates a random directed and acyclic graph ( DAG ) of size nodes .
// addition of Nodes // addition of edges // Test to avoid cycles