コード例 #1
0
  public int run(MyPhyloTree net, int border, boolean storeNetworkInfo, boolean smartMode) {

    int result = 0;
    for (MyPhyloTree n : new GetNetworkCluster().run(net)) {

      trivialEdges = new HashSet<MyEdge>();

      if (smartMode) {
        HashMap<MyNode, HashSet<MyNode>> nodeToPreds = new HashMap<MyNode, HashSet<MyNode>>();
        assingPreds(n.getRoot(), new HashSet<MyNode>(), nodeToPreds);
        cmpTrivialInteractions(n, nodeToPreds);
      }

      Vector<MyEdge> retEdges = new Vector<MyEdge>();
      for (MyNode v : n.getNodes()) {
        if (v.getInDegree() > 1) {
          Iterator<MyEdge> it = v.getInEdges();
          while (it.hasNext()) {
            MyEdge e = it.next();
            if (!trivialEdges.contains(e)) retEdges.add(e);
          }
        }
      }

      int addTaxaDegree = -1;
      for (int k = trivialEdges.size(); k <= border; k++) {
        HashSet<Vector<MyEdge>> allSubsets = new HashSet<Vector<MyEdge>>();
        getAllSubsets(0, retEdges, k - trivialEdges.size(), new Vector<MyEdge>(), allSubsets);
        for (Vector<MyEdge> subset : allSubsets) {
          clearEdges(n);
          setEdges(subset);
          if (checkTree(n)) {
            if (storeNetworkInfo) {
              n.setAddTaxaDegree(k);
              setEdges(subset);
            } else clearEdges(n);
            addTaxaDegree = k;
            break;
          }
        }
        if (addTaxaDegree != -1) break;
      }

      if (addTaxaDegree == -1) return -1;
      else {
        result += addTaxaDegree;
        border -= addTaxaDegree;
      }
    }

    if (result != -1) net.setAddTaxaDegree(result);

    return result;
  }
コード例 #2
0
 private void computeClusterRec(MyPhyloTree n, MyNode v, BitSet cluster, int treeIndex) {
   if (v.getOutDegree() == 0) cluster.set(taxaOrdering.indexOf(n.getLabel(v)));
   else {
     Iterator<MyEdge> it = n.getOutEdges(v);
     while (it.hasNext()) {
       MyEdge e = it.next();
       HashSet<Integer> indices = (HashSet<Integer>) e.getInfo();
       if (indices.contains(treeIndex)) {
         MyNode c = e.getTarget();
         computeClusterRec(n, c, cluster, treeIndex);
       }
     }
   }
 }
コード例 #3
0
 private void cmpTrivialInteractions(MyPhyloTree n, HashMap<MyNode, HashSet<MyNode>> nodeToPreds) {
   HashSet<MyNode> retNodes = new HashSet<MyNode>();
   for (MyNode v : n.getNodes()) {
     if (v.getInDegree() > 1) {
       retNodes.add(v);
     }
   }
   HashSet<MyEdge> toResolve = new HashSet<MyEdge>();
   for (MyNode v : retNodes) {
     Vector<MyNode> parentNodes = new Vector<MyNode>();
     Vector<MyEdge> parentEdges = new Vector<MyEdge>();
     Iterator<MyEdge> it = v.getInEdges();
     while (it.hasNext()) {
       MyEdge e = it.next();
       parentNodes.add(e.getSource());
       parentEdges.add(e);
     }
     for (MyNode p1 : parentNodes) {
       for (MyNode p2 : parentNodes) {
         if (nodeToPreds.get(p1).contains(p2)) {
           if (ancestorCheck(p1, p2)) toResolve.add(parentEdges.get(parentNodes.indexOf(p2)));
         }
       }
     }
   }
   for (MyEdge e : toResolve) trivialEdges.add(e);
 }
コード例 #4
0
 private boolean checkTree(MyPhyloTree net) {
   MyPhyloTree n = new MyPhyloTree(net);
   n.setTimeDegree(null);
   HashSet<MyEdge> criticalEdges = new HashSet<MyEdge>();
   for (MyEdge e : n.getEdges()) {
     if (e.isCritical()) criticalEdges.add(e);
   }
   for (MyEdge e : criticalEdges) {
     MyNode s = e.getSource();
     MyNode t = e.getTarget();
     s.removeOutEdge(e);
     MyNode x = n.newNode();
     n.newEdge(s, x);
     n.newEdge(x, t);
   }
   CheckTimeConsistency checker = new CheckTimeConsistency();
   int k = checker.run(n, 0, false, true, -1);
   if (k != 0) return false;
   return true;
 }
コード例 #5
0
 private void clearEdges(MyPhyloTree n) {
   for (MyEdge e : n.getEdges()) {
     e.setCritical(false);
   }
 }