コード例 #1
0
ファイル: NodeSorting.java プロジェクト: zoranzaric/GTNA
 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;
   }
 }
コード例 #2
0
 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;
 }
コード例 #3
0
 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;
 }
コード例 #4
0
ファイル: Gilbert.java プロジェクト: Jsalim/GTNA
 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);
 }