示例#1
0
      /**
       * Inserts a pair of disjoint elements. Determines whether they can be used to reorder existing sets of lables.
       * @param a : One part of pair
       * @param b : Other part of pair
       * @return : true if a new cluster was required for the insertion.
       */
      bool insert(const DisjointElement& a, const DisjointElement& b)
      {
        const size_t& aLabel = a.getRoot();
        const size_t& bLabel = b.getRoot();
        bool newItem = true;

        GroupType containingAny;
        GroupType containingNone;
        // ------------- Find equivalent sets
        for(GroupType::iterator i = m_groups.begin(); i != m_groups.end(); ++i)
        {
          GroupType::value_type& cluster =*i;
          if(cluster.find(aLabel) != cluster.end())
          {
            containingAny.push_back(cluster);
          }
          else if(cluster.find(bLabel) != cluster.end())
          {
            containingAny.push_back(cluster);
          }
          else
          {
            containingNone.push_back(cluster); // Current iterated set contains NEITHER of these labels. It can therfore be ignored.
          }
        }
        // ------------ Process equivalent sets
        if(containingAny.empty())
        {
          // Neither label is yet known to any set. We must add a new set for these
          GroupType::value_type newSet;
          newSet.insert(aLabel);
          newSet.insert(bLabel);
          m_groups.push_back(newSet);
        }
        else
        {
          // At least one set already contains at least one label. We merge all such sets into a master set.

          // implement copy and swap. Rebuild the sets.
          GroupType temp = containingNone;
          GroupType::value_type masterSet;
          masterSet.insert(aLabel); // Incase it doesn't already contain a
          masterSet.insert(bLabel); // Incase it doesn't already contain b
          for(auto i = containingAny.begin(); i != containingAny.end(); ++i)
          {
            GroupType::value_type& childSet = *i;
            masterSet.insert(childSet.begin(), childSet.end()); // Build the master set.
          }
          temp.push_back(masterSet);
          m_groups = temp; // Swap.
          newItem = false;
        }
        return newItem;
      }
示例#2
0
 /**
  * Make composite clusters from the merged groups.
  * @return Merged composite clusters.
  */
 std::list<boost::shared_ptr<CompositeCluster> >  makeCompositeClusters()
 {
   std::list<boost::shared_ptr<CompositeCluster> >  composites;
   for(auto i = m_groups.begin(); i != m_groups.end(); ++i)
   {
     GroupType::value_type& labelSet = *i;
     auto composite = boost::make_shared<CompositeCluster>();
     for(auto j = labelSet.begin(); j != labelSet.end(); ++j)
     {
       boost::shared_ptr<ICluster>& cluster = m_register[(*j)];
       composite->add(cluster);
     }
     composites.push_back(composite);
   }
   return composites;
 }