Exemple #1
0
 public int compare(NodeImpl n1, NodeImpl n2) {
   int v1 = n1.out().length;
   int v2 = n2.out().length;
   if (v1 == v2) {
     return 0;
   } else if (v1 > v2) {
     return -1;
   } else {
     return 1;
   }
 }
 private Set<NodeImpl> neighborhood(NodeImpl node, boolean onlyOut) {
   Set<NodeImpl> n = new HashSet<NodeImpl>();
   NodeImpl[] OUT = node.out();
   for (NodeImpl out : OUT) {
     n.add(out);
   }
   if (!onlyOut) {
     NodeImpl[] IN = node.in();
     for (NodeImpl in : IN) {
       n.add(in);
     }
   }
   return n;
 }
 private int edgesInNeighborhood(Set<NodeImpl> n) {
   int edges = 0;
   Iterator<NodeImpl> iter = n.iterator();
   while (iter.hasNext()) {
     NodeImpl current = iter.next();
     NodeImpl[] OUT = current.out();
     for (NodeImpl out : OUT) {
       if (n.contains(out)) {
         edges++;
       }
     }
   }
   return edges;
 }
Exemple #4
0
 public Graph generate() {
   Timer timer = new Timer();
   Random rand = new Random(System.currentTimeMillis());
   NodeImpl[] nodes = NodeImpl.init(this.nodes());
   double p = (double) this.EDGES / (double) (this.nodes() * this.nodes());
   if (this.BIDIRECTIONAL) {
     p /= 2;
   }
   Edges edges = new Edges(nodes, (int) (this.EDGES * 1.05));
   for (int i = 0; i < nodes.length; i++) {
     for (int j = 0; j < nodes.length; j++) {
       if (i != j) {
         if (rand.nextDouble() < p) {
           if (this.BIDIRECTIONAL) {
             edges.add(nodes[i], nodes[j]);
             edges.add(nodes[j], nodes[i]);
           } else {
             edges.add(nodes[i], nodes[j]);
           }
         }
       }
     }
   }
   edges.fill();
   timer.end();
   return new Graph(this.description(), nodes, timer);
 }