static void breadth_first_search(const GraphType& graph, 
                                 const VertexIndexType& source,
                                 const int& k_steps,
                                 AssociativeContainer& visited_vertices) {
  /* CHECK: AssociativeContainer::value_type == VertexIndexType */

  std::queue<VertexIndexType> even_epoch_queue;
  std::queue<VertexIndexType> odd_epoch_queue;
  std::queue<VertexIndexType>& current_queue = even_epoch_queue;
  std::queue<VertexIndexType>& next_queue = odd_epoch_queue;

  current_queue.push (source);
  int step_number = 0;
  while (step_number<k_steps) {
    while (!current_queue.empty ()) {
      const int vertex = current_queue.front ();
      current_queue.pop ();
      visited_vertices.insert (vertex);
      for (int target_index=graph.begin(vertex); 
           target_index<graph.end(vertex);
           ++target_index) {
        const int target = graph.get_target (target_index);
        if (visited_vertices.end()==visited_vertices.find (target)) {
          next_queue.push (target);
        }
      }
    }
    ++step_number;
    current_queue = (step_number&0x10)?even_epoch_queue:odd_epoch_queue;
    next_queue = (step_number&0x01)?even_epoch_queue:odd_epoch_queue;
  }
}
Example #2
0
 void erase_if_dispatch(AssociativeContainer& c, Predicate p,
                        associative_container_tag, stable_tag)
 {
   typename AssociativeContainer::iterator i, next;
   for (i = next = c.begin(); next != c.end(); i = next) {
     ++next;
     if (p(*i))
       c.erase(i);
   }
 }
void remove_if(AssociativeContainer& C, Predicate p)
{
	typedef typename AssociativeContainer::iterator iterator;

	iterator cur = C.begin();
	const iterator last = C.end();

	while ((cur = std::find_if(cur, last, p)) != last)
	{
		iterator tmp = cur++;
		C.erase(tmp);
	}
}
Example #4
0
 void erase_if_dispatch(AssociativeContainer& c, Predicate p,
                        associative_container_tag, unstable_tag)
 {
   // This method is really slow, so hopefully we won't have any
   // associative containers with unstable iterators!
   // Is there a better way to do this?
   typename AssociativeContainer::iterator i;
   typename AssociativeContainer::size_type n = c.size();
   while (n--)
     for (i = c.begin(); i != c.end(); ++i)
       if (p(*i)) {
         c.erase(i);
         break;
       }
 }
Example #5
0
 typename AssociativeContainer::const_iterator
 find_dispatch(const AssociativeContainer& c,
               const Value& value,
               associative_container_tag)
 {
   return c.find(value);
 }
Example #6
0
 std::pair<typename AssociativeContainer::iterator,
           typename AssociativeContainer::iterator>
 equal_range_dispatch(AssociativeContainer& c,
                      const Value& value,
                      associative_container_tag)
 {
   return c.equal_range(value);
 }
Example #7
0
bool get(const AssociativeContainer& container,
         const KeyType& key,
         MappedType** ppValue)
{
   if (!container.count(key))
      return false;
   
   *ppValue = &(const_cast<AssociativeContainer&>(container)[key]);
   return true;
}
static void construct_adjacency_matrix 
                        (const GraphType& graph,
                         const AssociativeContainer& vertices,
    __gnu_cxx::hash_map<VertexIndexType, VertexIndexType>& label_map,
    __gnu_cxx::hash_map<VertexIndexType, VertexIndexType>& reverse_label_map,
                         std::vector<EdgeWeightType>& adjacency_matrix) {
  typedef typename AssociativeContainer::const_iterator 
                              AssociativeContainerConstIterator;
                                        
  /* resize the adjacency matrix to hold the adjacencies */
  const int num_vertices = vertices.size ();
  adjacency_matrix.resize (num_vertices*num_vertices, 0.0);

  /* Create a map, which remaps the old vertices into new vertices */
  VertexIndexType new_label=0;
  AssociativeContainerConstIterator iter = vertices.begin();
  AssociativeContainerConstIterator end = vertices.end();

  while (iter!=end) {
    const VertexIndexType current_vertex = *iter++;
    label_map [current_vertex] = new_label;
    reverse_label_map [new_label] = current_vertex;
    ++new_label;
  }
  assert (new_label==num_vertices);
  
  /* now do the adjacencies */
  iter = vertices.begin();
  while (iter!=end) {
    const VertexIndexType old_vertex = *iter++;
    const VertexIndexType new_vertex = label_map [old_vertex];
    for (int target_index=graph.begin(old_vertex); 
         target_index<graph.end(old_vertex);
         ++target_index) {
      const VertexIndexType adjacent_vertex=graph.get_target (target_index);

      /* only add the adjacency if the target is one of "vertices". */
      if (vertices.end()!=vertices.find (adjacent_vertex)) {
        const int element_offset = 
          (num_vertices*new_vertex) + label_map [adjacent_vertex];
        adjacency_matrix [element_offset] = graph.get_weight (target_index);
      }
    }
  }
}
Example #9
0
 std::pair<typename AssociativeContainer::iterator, bool>
 push_dispatch(AssociativeContainer& c, const T& v,
               multiple_associative_container_tag)
 {
   return std::make_pair(c.insert(v), true);
 }
Example #10
0
 std::pair<typename AssociativeContainer::iterator, bool>
 push_dispatch(AssociativeContainer& c, const T& v, 
               unique_associative_container_tag)
 {
   return c.insert(v);
 }
Example #11
0
 void erase_dispatch(AssociativeContainer& c, const T& x, 
                     associative_container_tag)
 {
   c.erase(x);
 }
void writeLatex(  AssociativeContainer & p, 
                  bool draw_box = true, 
                  bool dumpcout = false,
                  std::ostream & ostr = std::cout)
{   
   typedef typename AssociativeContainer::iterator Iterator;
   Iterator it;

   ostr << std::fixed << std::setprecision(8);

   int sum = 0;
   for(it = p.begin(); it != p.end(); it++)
   {
      sum += it->second;
   }

   // ##########
   // create statistics plot

   
   // a priori computation of the vertical position of the histogram bar names
   //
   long size_entries = p.size();
   size_t key_size_max = 0;
   double text_vertical_position = 0.0;
   double box_vertical_size = 0.0;
   double box_horizontal_size = 0.0;
   
   for(it = p.begin(); it != p.end(); it++)
   {
      // determine the maximal key size of all entries
      if( (it->first).size() > key_size_max )
         key_size_max = (it->first).size();

      // the reference is: for a key of 8 characters, the vspace is 40.0
      // so conclude about the actual size of the key by using this ratio.
      text_vertical_position = key_size_max * 40.0 / 8.0;
      
      // determine the size of the pspicture box. 
      // use some reference ratios to derive a suitable size
      box_vertical_size = text_vertical_position;
      box_horizontal_size = size_entries * 4.0 / 3.0;
   }     

   ostr << std::endl;
   ostr << "%-----------" << std::endl;
   ostr << "%%% PLOT %%%" << std::endl;
   ostr << "%-----------" << std::endl;
   ostr << "\\begin{minipage}[ht]{0.20\\textwidth}" << std::endl;
   if(draw_box)
      ostr << "\\fbox{" << std::endl;
   ostr << "\\setlength{\\unitlength}{1cm}" << std::endl;
   ostr << "\\psset{xunit=0.7cm, yunit=0.03017058cm}" << std::endl;
   ostr << "\\begin{pspicture}(-1.0,-" << box_vertical_size << ")("<< box_horizontal_size <<",130)" << std::endl;
   ostr << "\\psaxes[labels=y,Dx=1,Dy=50.](0,0)(" << size_entries << ",100)" << std::endl;
   ostr << "\\pspolygon[fillcolor=black, fillstyle=solid](-0.08,104.55414013)(0,109.53290870)(0.08,104.55414013)" << std::endl;
   
   int i=0;
   for(it = p.begin(); it != p.end(); it++)
   {
      // detect underscores in the key and prefix them with a '\' 
      // so its latex conform
      std::string key = gsse::check_for_special_characters(it->first);      

      double percentage = ( boost::lexical_cast<double>(it->second) /  boost::lexical_cast<double>(sum))*100.0;

   #ifdef DEBUG
      std::cout << "  key_size" << key_size << std::endl;
      std::cout << "  text_vertical_position: " << text_vertical_position << std::endl;
   #endif         
      ostr.precision(2);
      ostr << "\\psframe[linewidth=1pt, fillcolor=gray, fillstyle=solid] (" << i 
         << ".30000000,0)(" << i << ".70000000," << percentage << ")" << std::endl;
      ostr << "\\rput[bl](" << i++ << ".35000000,-" << text_vertical_position << "){\\rotateleft{\\footnotesize " 
         << key << "}}" << std::endl;
   }

   ostr << "\\end{pspicture}" << std::endl;
   if(draw_box)
      ostr << "}" << std::endl;      
   ostr << "\\end{minipage}" << std::endl;

   ostr << std::endl;

   ostr << "%------------" << std::endl;
   ostr << "%%% TABLE %%%" << std::endl;
   ostr << "%------------" << std::endl;

   // ##########
   // create statistics table
   ostr << "\\begin{minipage}[ht]{0.20\\textwidth}" << std::endl;
   ostr << "\\begin{tabular}{crr}" << std::endl;

   if(dumpcout)
   {
      std::cout << "## mesh classification: " << std::endl;
      std::cout << "---------------------------------------------" << std::endl;
   }

   for(it = p.begin(); it != p.end(); it++)
   {
      double percentage = ( boost::lexical_cast<double>(it->second) /  boost::lexical_cast<double>(sum))*100.0;      
      if(dumpcout)
      {
         std::cout << "  " << gsse::check_for_special_characters(it->first) << "    \t" << percentage << " %" << std::endl;
         std::cout << "---------------------------------------------" << std::endl;
      }
      ostr << gsse::check_for_special_characters(it->first) << " & " << it->second << " & " << percentage << "\\% \\\\" << std::endl;
   }

   ostr << "\\end{tabular}" << std::endl;
   ostr << "\\end{minipage}" << std::endl;
   ostr << "%------------" << std::endl;
   ostr << "%------------" << std::endl;
   ostr << std::endl;   
}
Example #13
0
 void erase_certainties(AssociativeContainer& c) {
   BOOST_FOREACH(const Card& card, fixed_) {
     c.erase(card);
   }
 void const_constraints(const AssociativeContainer& c) {
   ci = c.find(k);
   n = c.count(k);
   cr = c.equal_range(k);
 }