Beispiel #1
0
Partition::Partition(const vector<string>& n,const dynamic_bitset<>& g,const dynamic_bitset<>& mask) 
  :names(n),group1((~ g) & mask),group2(g & mask)
{
  assert(n.size() == g.size());
  assert(g.size() == mask.size());
  assert(not group1.intersects(group2));
}
Beispiel #2
0
uint32_t cFixedAlloc::findFirstOf(bool check, dynamic_bitset<>& bit) {
	for ( int i = 0; i < bit.size(); ++i ) {
		if ( bit[i] == check )	return i;
	}

	return bit.size() + 1;
}
Beispiel #3
0
/// Check that any two present nodes are connected by a path of present nodes
bool all_characters_connected(const Tree& T,dynamic_bitset<> present,const vector<int>& _ignore) {
  assert(present.size() == T.n_nodes());

  //--------- set the ignored nodes to 'not present' -----------//
  dynamic_bitset<> ignore(present.size());
  for(int i=0;i<_ignore.size();i++) {
    int n = _ignore[i];
    present[n] = false;
    ignore[n] = true;
  }

  //---------- for each internal node... -------------//
  for(int n1=T.n_leaves(); n1<T.n_nodes(); n1++) {

    if (present[n1] or ignore[n1]) continue;
      
    //------- if it is '-' and not ignored ... -------//
    vector<const_nodeview> neighbors;
    append(T[n1].neighbors(),neighbors);
    assert(neighbors.size() == 3);

    //---- check the three attatched subtrees ... ----//
    int total=0;
    for(int i=0;i<neighbors.size();i++) {
      dynamic_bitset<> group = T.partition(n1,neighbors[i]);
      if (present.intersects(group))
	total++;
    }

    //----- nodes should be present in only one. -----//
    if (total > 1)
      return false;
  }
  return true;
}
typename allocator<T>::size_type allocator<T>::find_free_memory(const dynamic_bitset & memfree, dynamic_bitset & mask)
{
	/* search mask in memfree */
	const size_type needed_mem_size = mask.count();
	if (memfree.count() < needed_mem_size) {
#		if DEBUG_SMA_TRACE_FIND_FREE_MEM
		std::cout << "not enough free memory found" << std::endl;
#		endif
		return memfree.size();
	}
	assert(needed_mem_size <= memfree.size());
	const size_type asize = memfree.size() - needed_mem_size;
	size_type pos = 0;
	while (pos <= asize) {
#		if DEBUG_SMA_TRACE_FIND_FREE_MEM
		std::cout << "pos:     " << pos << "/" << asize << std::endl;
		std::cout << "mask:    " << mask << std::endl;
		std::cout << "memfree: " << memfree << std::endl;
#		endif
		/* check if enough memory is free in interval [pos, pos+needed_mem_size) */
		if ((memfree & mask) == mask) {
			/* free memory found */
#			if DEBUG_SMA_TRACE_FIND_FREE_MEM
			std::cout << "free memory found at pos=" << pos << std::endl;
#			endif
			return pos;
		} else {
			/* increment pos for next iteration */
#			if DEBUG_SMA_TRACE_FIND_FREE_MEM
			std::cout << "memfree:  " << memfree << "    "
				  << memfree << std::endl;
			std::cout << "inc mask: " << mask << " -> ";
#			endif
			const size_type oldpos = pos;
			pos = memfree.find_next(oldpos);
			assert(pos >= oldpos);
			mask <<= pos - oldpos;
#			if DEBUG_SMA_TRACE_FIND_FREE_MEM
			std::cout << mask << std::endl;
			std::cout << "pos: " << oldpos << " -> "
				  << pos << std::endl;
#			endif
			assert(mask.count() == needed_mem_size);
		}
	}
	/* no free memory found */
#	if DEBUG_SMA_TRACE_FIND_FREE_MEM
	std::cout << "not enough free memory found" << std::endl;
#	endif
	return memfree.size();
}
typename allocator<T>::dynamic_bitset allocator<T>::free_memory(const dynamic_bitset & memfree,
	                                                        dynamic_bitset && mask)
{
	assert(memfree.size() == mask.size());
	assert(memfree.count() + mask.count() <= memfree.size());
	auto res = memfree | mask;
#	if DEBUG_SMA_TRACE_BITSET
	std::cout << "a=memfree: " << memfree << std::endl;
	std::cout << "b=   mask: " << mask << std::endl;
	std::cout << "r=  a | b: " << res << std::endl;
#	endif
	assert(memfree.count() + mask.count() == res.count());
	return res;
}
Beispiel #6
0
bool 
compare_complete_partitions::operator()(const dynamic_bitset<>& p1,
					const dynamic_bitset<>& p2) const
{
  assert(p1.size() == p2.size());

  for(int i=0;i<p1.size();i++) {
    if (p2[i] and not p1[i])
      return true;
    if (p1[i] and not p2[i])
      return false;
  }
  return false;
}
Beispiel #7
0
static
bool can_die_early(const NGHolder &g, const vector<StateInfo> &info,
                   const dynamic_bitset<> &s,
                   map<dynamic_bitset<>, u32> &visited, u32 age_limit) {
    if (contains(visited, s) && visited[s] >= age_limit) {
        /* we have already (or are in the process) of visiting here with a
         * looser limit. */
        return false;
    }
    visited[s] = age_limit;

    if (s.none()) {
        DEBUG_PRINTF("dead\n");
        return true;
    }

    if (age_limit == 0) {
        return false;
    }

    dynamic_bitset<> all_succ(s.size());
    step(g, info, s, &all_succ);
    all_succ.reset(NODE_START_DOTSTAR);

    for (u32 i = 0; i < N_CHARS; i++) {
        dynamic_bitset<> next = all_succ;
        filter_by_reach(info, &next, CharReach(i));
        if (can_die_early(g, info, next, visited, age_limit - 1)) {
            return true;
        }
    }

    return false;
}
Beispiel #8
0
void connect_all_characters(const Tree& T,dynamic_bitset<>& present)
{
  assert(present.size() == T.n_nodes());
  
  //---------- for each internal node... -------------//
  for(int n1=T.n_leaves(); n1<T.n_nodes(); n1++) 
  {
    if (present[n1]) continue;

    //------- if it is '-' and not ignored ... -------//
    vector<const_nodeview> neighbors;
    append(T[n1].neighbors(),neighbors);
    assert(neighbors.size() == 3);

    //---- check the three attatched subtrees ... ----//
    int total=0;
    for(int i=0;i<neighbors.size();i++)
    {
      dynamic_bitset<> group = T.partition(n1,neighbors[i]);
      if (present.intersects(group))
	total++;
    }

    if (total > 1)
      present[n1] = true;
  }
  assert(all_characters_connected(T,present,vector<int>()));
}
Beispiel #9
0
bool A_constant(alignment A1, alignment A2, const dynamic_bitset<>& ignore) {
  assert(A1.n_sequences() == A2.n_sequences());

  // equality holds if we have internal node sequences -- otherwise ignore is larger
  assert(A1.n_sequences() <= ignore.size());

  // convert to feature-number notation
  ublas::matrix<int> M1 = M(A1);
  ublas::matrix<int> M2 = M(A2);

  // lookup and cache the column each feature is in
  vector< vector< int> > column_indices = column_lookup(A2);

  //----- Check that the sequence lengths match ------//
  for(int i=0;i<M1.size2();i++) {
    if (ignore[i]) continue;

    if (A1.seqlength(i) != A2.seqlength(i))
      return false;
  }

  //----- Check that each homology in A1 is in A2 -----//
  for(int column=0; column<A1.length(); column++)
    for(int s1=0; s1 < A1.n_sequences(); s1++) {
      if (ignore[s1]) continue;
      for(int s2=s1+1; s2 < A1.n_sequences(); s2++) {
	if (ignore[s2]) continue;
	if (not A_match(M1,column,s1,s2,M2,column_indices))
	  return false;
      }
    }

  return true;
}
vector<int> diffset_for_single_item(dynamic_bitset<> tids) {
    vector<int> diffset;
    dynamic_bitset<>::size_type size = tids.size();
    for (dynamic_bitset<>::size_type i = 0; i < size; ++i)
        if ( ! tids.test(i))
            diffset.push_back(i);
    return diffset;
}
Beispiel #11
0
Partition::Partition(const Partition& p,const dynamic_bitset<>& mask)
  :names(p.names),
   group1(p.group1 & mask),
   group2(p.group2 & mask)
{
  assert(mask.size() == p.group1.size());
  assert(not group1.intersects(group2));
}
void StreamGenerator::setBitstreamBits(dynamic_bitset<>& bitStream,
                                       int num, size_t bitsetIndex, size_t numIndex) {

    unsigned int size = sizeof (unsigned int)*8;
    if (numIndex < size) {

        if (bitsetIndex < bitStream.size()) {
            bitStream[bitsetIndex] = (num >> numIndex) & 0x1;
            setBitstreamBits(bitStream, num, bitsetIndex + 1, numIndex + 1);
        }
    }
Beispiel #13
0
int Tree::induce_partition(const dynamic_bitset<>& partition) 
{
  assert(partition.size() == n_leaves());
  
  prepare_partitions();

  dynamic_bitset<> partition1(n_nodes());
  dynamic_bitset<> partition2(n_nodes());

  // copy bits from smaller bitset on leaves to larger bitset on all nodes
  for(int i=0;i<partition.size();i++) {
    if (partition[i])
      partition1.flip(i);
    else
      partition2.flip(i);
  }

  for(int i=n_leaves();i<n_nodes();i++) 
  {
    vector<BranchNode*> group1;
    vector<BranchNode*> group2;

    // divide the branches out into two groups
    BranchNode * BN = nodes_[i];
    do {
      if (not partition1.intersects(cached_partitions[BN->branch]))
	group2.push_back(BN);
      else if (not partition2.intersects(cached_partitions[BN->branch]))
	group1.push_back(BN);
      else {
	group1.clear();
	group2.clear();
	break;
      }
      
      BN = BN->next;
    } while (BN != nodes_[i]);

    // this node can't separate the groups
    if (not group1.size() and not group2.size()) continue;

    BranchNode* bn = NULL;

    // groups are already split!
    if (group1.size() == 1)
      bn = group1[0];
    // groups are already split!
    else if (group2.size() == 1)
      bn = group2[0];
    // split the node and note the name of the newly added branch
    else {
      bn = split_node(group1,group2);
      reanalyze(nodes_[0]);
    }

    if (not bn)
      return -1;
    else
      return std::min(bn->branch,bn->out->branch);
  }
  throw myexception()<<"induce_partition: partition conflicts with tree!";
}
Beispiel #14
0
Partition::Partition(const dynamic_bitset<>& g,const dynamic_bitset<>& mask) 
  :group1((~g) & mask),group2(g & mask)
{
  assert(g.size() == mask.size());
  assert(not group1.intersects(group2));
}
Beispiel #15
0
Partition::Partition(const vector<string>& n,const dynamic_bitset<>& g) 
  :names(n),group1(g),group2(~g)
{
  assert(n.size() == g.size());
  assert(not group1.intersects(group2));
}