コード例 #1
0
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);
      }
    }
  }
}
コード例 #2
0
ファイル: container_traits.hpp プロジェクト: 2asoft/xray-16
 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);
   }
 }
コード例 #3
0
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);
	}
}
コード例 #4
0
ファイル: container_traits.hpp プロジェクト: 2asoft/xray-16
 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;
       }
 }
コード例 #5
0
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;   
}