public static Graph<String,Number> createDirectedAcyclicGraph(int layers,int maxNodesPerLayer,double linkprob){
  DirectedGraph<String,Number> dag=new DirectedSparseMultigraph<String,Number>();
  Set<String> previousLayers=new HashSet<String>();
  Set<String> inThisLayer=new HashSet<String>();
  for (int i=0; i < layers; i++) {
    int nodesThisLayer=(int)(Math.random() * maxNodesPerLayer) + 1;
    for (int j=0; j < nodesThisLayer; j++) {
      String v=i + ":" + j;
      dag.addVertex(v);
      inThisLayer.add(v);
      for (      String v2 : previousLayers) {
        if (Math.random() < linkprob) {
          Double de=new Double(Math.random());
          dag.addEdge(de,v,v2);
        }
      }
    }
    previousLayers.addAll(inThisLayer);
    inThisLayer.clear();
  }
  return dag;
}

public static Graph < String , Number > createDirectedAcyclicGraph ( int layers , int maxNodesPerLayer , double linkprob ) { DirectedGraph < String , Number > dag = new DirectedSparseMultigraph < String , Number > ( ) ; Set < String > previousLayers = new HashSet < String > ( ) ; Set < String > inThisLayer = new HashSet < String > ( ) ; for ( int i = 0 ; i < layers ; i ++ ) { int nodesThisLayer = ( int ) ( Math . random ( ) * maxNodesPerLayer ) + 1 ; for ( int j = 0 ; j < nodesThisLayer ; j ++ ) { String v = i + ":" + j ; dag . addVertex ( v ) ; inThisLayer . add ( v ) ; for ( String v2 : previousLayers ) { if ( Math . random ( ) < linkprob ) { Double de = new Double ( Math . random ( ) ) ; dag . addEdge ( de , v , v2 ) ; } } } previousLayers . addAll ( inThisLayer ) ; inThisLayer . clear ( ) ; } return dag ; }
creates a sample directed acyclic graph by generating several " layers " , and connecting nodes ( randomly ) to nodes in earlier ( but never later ) layers . the number of vertices in each layer is a random value in the range [ 1 , maxnodesperlayer ] .
