亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關(guān)于我們
? 蟲蟲下載站

?? graph.cpp

?? it is an adaboost weak learner
?? CPP
字號:
// File graph.cpp    Graph<V,W> class template implementation file
// shinnerl@ucla.edu   

#ifndef GRAPH_CPP
#define GRAPH_CPP

/*
template <class V, class W>   
void Graph<V,W>::getComponent(const V& v0, set<V>& myPiece)
{
  // Find all vertices connected to v0, put them in myPiece with v0.

  cerr << "\nYou must implement function Graph<V,W>::getComponent()."
       << std::endl;
  assert(0);
}
*/


template <class V, class W>   // Verify "undirectedness" of graph data
bool Graph<V,W>::isSymmetric( pair<V,V>& badEdge ) 
{  
   // The weight for edge {u,v} must be stored twice, for both (u,v) and (v,u). 
   // This function stops as soon as it finds one bad edge and 
   // passes it back, returning false.  If *all* edges are ok, it returns true.
   // There is no efficient way to avoid visiting every stored edge *twice*.
   //
   // Recall, edge (u,v) with weight w is stored in u's Adjacency map as 
   //   the pair (v,w).  

   bool symmetric = true;
   std::map<V, map<V,W> >::iterator p;
   for (p = map< V, map<V,W> >::begin(); 
        p !=map< V, map<V,W> >::end(); 
        ++p)
   {
      const V& v_i      = p->first;          // shorthand
      map<V,W>& v_i_map = p->second;         // shorthand
      if (!v_i_map.empty())
      {
        std::map<V,W>::iterator q;
	for ( q = v_i_map.begin();
	       symmetric && q != v_i_map.end();
	       ++q )
	 {
            const V& neighbor   = q->first;
            W edgeWeight        = q->second;
            W* counterWeightPtr = findEdge(neighbor, v_i);
            if (!counterWeightPtr || (*counterWeightPtr != edgeWeight))
            {
               symmetric = false;
               badEdge.first  = v_i;
               badEdge.second = neighbor;
            }
	 }
      }
   } 
   return symmetric;  
}

template <class V, class W>          
void Graph<V,W>::insertVertex( const V& v )
{
   operator[](v) = map<V,W>();  // Initially, v has no neighbors. 
}


template <class V, class W>          
void Graph<V,W>::removeVertex( const V& v )
{ 
   // Before removing v, we must remove all edges incident upon it.
   // To do this, we visit every neighbor of v and remove v from
   //  that neighbor's adjacency map.  Then we remove v.

   map<V,W> *Aptr = findVertex( v );
   if (Aptr) {
      std::map<V,W>::iterator p; 
      for ( p = Aptr->map<V,W>::begin(); 
	    p != Aptr->map<V,W>::end(); 
	    ++p ) {
         map<V,W> *tAptr = findVertex(p->first);
         tAptr->erase( v );   // tAptr nonzero if the Graph is symmetric.
      }                        
   }                        
   map<V, map<V,W> >::erase(v);
}

template <class V, class W>          // Symmetry preserving.
void Graph<V,W>::removeEdge( const V& v1, const V& v2 )
{
   map<V,W> *A1ptr = findVertex(v1), 
            *A2ptr = findVertex(v2);
   if (A1ptr && A2ptr)
   {
      if (findEdge(v1, v2))
         A1ptr->erase( v2 );
      if (findEdge(v2, v1))
         A2ptr->erase( v1 );
   }
}

template <class V, class W>           // Symmetry preserving.        
void Graph<V,W>::setEdge(const V& v1, const V& v2, const W& w)
{
   map<V,W> *A1ptr = findVertex(v1), 
	    *A2ptr = findVertex(v2);
   if (A1ptr && A2ptr)
   {
       A1ptr->operator[](v2) = w; 
       A2ptr->operator[](v1) = w; 
   }
}

template <class V, class W>         
map<V,W>*  Graph<V,W>::findVertex(const V& v) const
{ 
  map<V,W>* nhbdPtr = 0;
  std::map< V, map<V,W> >::const_iterator p1 
     = map< V, map<V,W> >::find(v);
  if (p1 != map< V, map<V,W> >::end())
     nhbdPtr = const_cast<map<V,W>*>(&(p1->second));    // cast
  return nhbdPtr;
}

template <class V, class W>         
W* Graph<V,W>::findEdge( const V& v1, const V& v2 ) const
{
   W* Wptr = 0;
   map<V,W>* AmapPtr = findVertex(v1);
   if (AmapPtr)
   {
      std::map<V,W>::iterator p2 = AmapPtr->find(v2);
      if (p2 != AmapPtr->end())
        Wptr = &(p2->second);
   }
   return Wptr;
}


template <class V, class W>         // Vertex adjacency map output
void Graph<V,W>::print( ostream& os )
{
  std::map< V, map<V, W> >::iterator p;
  for (p = map< V, map<V,W> >::begin(); 
       p !=map< V, map<V,W> >::end(); 
       ++p){
     os << p->first; 
     os << "  { ";
     std::map<V, W>::iterator q;
     for (q = p->second.begin(); 
	  q !=p->second.end(); 
	  ++q)
        os << " ( " << q->first 
	   << " , " << q->second << " ) ";
     os << " } " << std::endl;
  }
  os << std::endl;
}


template <class V, class W>         // Vertex adjacency map input
void Graph<V,W>::read( istream& is )
{
   erase();
   V v;
   map<V,W> A;
   while (is){
     is >> v;
     if (is){
        getAdjacencyMap(is, A);
	operator[](v) = A;
     }
   }

   pair<V,V> badPair;
   if (!isSymmetric( badPair ))
   {
      stringstream info;
      info << "\nError in graph input at edge ("
           << badPair.first << " , " << badPair.second << "). \n"
	   << "The graph must be undirected. Graph discarded. \n\n" 
	   << "See sample file \"g1.dat\" for format conventions; note spacing."
	   << std::endl;
      erase();
      throw Error(info.str());
   }
}

template <class V, class W>         // Vertex adjacency map input
void Graph<V,W>::getAdjacencyMap( istream& is,  map<V,W>& A )
{
   A.map<V,W>::clear();            
   char ch = ' ';
   while ( is && ch != '{')
     is >> ch;

   bool done = false;
   V neighbor;
   W weight;
   while (is && !done)
   {
      is >> ch;
      done = (!is || ch =='}');
      if (!done && ch == '(')
      {
      	is >> neighbor;
	is >> ch;       // Separating comma.
      	is >> weight;
	is >> ch;       // Closing paren.
      	A[neighbor] = weight;
      }
   }
}


// --- Begin leastCostPath code ---

template <class V, class W>   
struct PathVertex            // wrapper used by leastCostPath().
{
   V vertex;
   V predecessor;
   W pathWeight;

   PathVertex() {}                           
   PathVertex( const V& v, const W& pw )    // For searching.
     : vertex(v), pathWeight(pw) {}           
   PathVertex( const V& v, const V& p, const W& pw ) 
     : vertex(v), predecessor(p), pathWeight(pw) {}

   bool operator<( const PathVertex& w ) const
    {return     (pathWeight < w.pathWeight && vertex != w.vertex)
             || (pathWeight == w.pathWeight && vertex < w.vertex);}
   bool operator<=( const PathVertex& w ) const
    {return    (*this < w )
            || (pathWeight <= w.pathWeight && vertex == w.vertex);}
   bool operator>( const PathVertex& w ) const
    {return !operator<=(w);}
   bool operator>=( const PathVertex& w ) const
    {return !operator<(w); }
   bool operator==( const PathVertex& w ) const
    {return  (vertex == w.vertex);}
   bool operator!=( const PathVertex& w ) const
    {return !operator==(w); }
};

template <class V, class W>
ostream& operator<<( ostream& os, const PathVertex<V,W>& pv )
{os << pv.vertex; return os;}

template <class V, class W>
istream& operator>>( istream& is, PathVertex<V,W>& pv )
{is >> pv.vertex >> pv.predecessor >> pv.pathWeight; return is;}


template <class T>
T popLeast ( std::set<T>&  theSet )
{
   assert (!theSet.empty());      // Precondition: theSet must be nonempty.
   std::set<T>::iterator p = theSet.begin();
   T answer = *p;
   theSet.erase(answer);          
   return answer;
}


template <class V, class W>                 
W Graph<V,W>::leastCostPath( const V& vStart, const V& vEnd, 
                             deque<V>& pathDeque ) const
{ 
 //  Dijkstra's algorithm.  The tree of least cost paths is stored in
 //  an STL map<V,V> called "pathMap."  Each vertex in the pathMap
 //  is paired with a unique predecessor (vStart is paired with itself).
 //
 //  The boundary or "edge" of this tree of least cost paths is 
 //  stored twice to support two different modes of access: by
 //  pathWeight and by vertex.
 //  The "boundarySet" is also an STL set< PathVertex<V,W> >. 
 //  Its elements are ordered first by pathWeight and second by 
 //  vertex name, as defined by PathVertex::operator<(...).   Its 
 //  least-weight element is efficiently removed and added to 
 //  the pathMap at each step of the algorithm. 
 //  The "boundaryMap" is an STL map<V, W> that supports simple 
 //  pathWeight look-up by vertex key.  It facilitates the 
 //  boundary-weight updating that must be applied to all neighbors 
 //  of each newly added element of the pathMap.
 //
 //  Precondition: Vertex vStart must be in the graph.

   map<V,V> pathMap;
   std::set< PathVertex<V,W> > boundarySet;      
   map<V, W> boundaryMap;            
   bool done = false;
   W pathCost(0);                    // Assuming  W=0 makes sense.
   if (vStart == vEnd)
      done = true;
   else // Initialize. Put vStart's neighbors in the boundarySet as triples.
   {
     pathMap[vStart] = vStart;
     map<V,W>* neighbors = findVertex( vStart );
     assert(neighbors);
     std::map<V,W>::iterator p;
     for ( p = neighbors->begin(); p != neighbors->end(); ++p )
     {
       const V& terminus   = p->first;
       W& edgeWeight       = p->second;
       boundarySet.insert( PathVertex<V,W>(terminus, vStart, edgeWeight) );
       boundaryMap[terminus]  = edgeWeight;        
     }
   }

   while (!done && !boundarySet.empty())    
   {                
     // Main loop.  Get boundary vertex of least pathWeight
     //             and add it to the table, updating any other 
     //             boundary vertices as appropriate.

     PathVertex<V,W> pvNearest = popLeast( boundarySet );
     V& vNew  = pvNearest.vertex;
     W& pwNew = pvNearest.pathWeight;
     boundaryMap.erase( vNew );        
     pathMap[vNew] = pvNearest.predecessor;
     if (vNew != vEnd)
     {
	map<V,W>* vNewNeighbors = findVertex( vNew );
	std::map<V,W>::iterator p;
	for ( p = vNewNeighbors->begin(); p != vNewNeighbors->end(); ++p )
	{
           const V& terminus   = p->first;
           if( pathMap.find(terminus) == pathMap.end() ) // if terminus is not 
           {                                             //   in the pathMap...
              W& edgeWeight = p->second;
      	      W oldWeight;             // old weight of terminus in boundaryMap
   	      W npwt = edgeWeight + pwNew;   // npwt = new weight of terminus
		  std::map<V,W>::iterator pbm = boundaryMap.find(terminus);
   	      if ( pbm != boundaryMap.end() )
   	      { 
		oldWeight = pbm->second;
      	        if (npwt < oldWeight) 
   	        {
   	          boundarySet.erase(PathVertex<V,W>( terminus, oldWeight ));
   	          boundarySet.insert( PathVertex<V,W>(terminus, vNew, npwt) );
   	          boundaryMap[terminus] = npwt;
   	        }
   	      }
   	      else 
	      {
   	         boundarySet.insert( PathVertex<V,W>( terminus, vNew, npwt) );
   	         boundaryMap[terminus] = npwt;
	      }
           }
	}
     }
     else
     {
       pathCost = pwNew;
       done = true;
     }
   }
   if (done && vStart != vEnd) // Get the path from the table as a deque.
   {                           
      pathDeque.push_front(vEnd);
      V curr = vEnd;
      do{
	   std::map<V,V>::iterator pps = pathMap.find( curr );
	   assert( pps != pathMap.end() );
	   curr = pps->second;
	   pathDeque.push_front(curr);
      }while( curr != vStart );
   }
   else if (!done)
      cout << "\nNo path between those vertices exists." << endl;
   else
      ;                // vStart == vEnd
   return pathCost;
}

// --- End leastCostPath code ---


#endif

?? 快捷鍵說明

復(fù)制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
日韩国产高清影视| 一区二区三区四区激情| 九九**精品视频免费播放| 在线不卡一区二区| 午夜精品久久久久久不卡8050| 色欧美88888久久久久久影院| 亚洲色图在线看| 在线免费观看不卡av| 午夜精品福利久久久| 日韩欧美在线观看一区二区三区| 免费观看日韩电影| 亚洲精品在线三区| 成人h精品动漫一区二区三区| 中文字幕五月欧美| 欧美日韩精品一区视频| 老色鬼精品视频在线观看播放| 精品91自产拍在线观看一区| 成人av综合在线| 一区二区三区蜜桃| 日韩欧美中文字幕一区| 国产成人精品aa毛片| 成人欧美一区二区三区1314| 欧美羞羞免费网站| 秋霞午夜鲁丝一区二区老狼| 久久女同精品一区二区| 色妞www精品视频| 日精品一区二区三区| 国产午夜精品一区二区三区视频 | 日韩视频在线你懂得| 玖玖九九国产精品| 亚洲欧洲制服丝袜| 精品久久久久久久久久久久包黑料| 成人av网站免费观看| 午夜日韩在线观看| 国产精品妹子av| 91精品国产色综合久久ai换脸| 国产成人亚洲精品狼色在线| 亚洲在线中文字幕| 亚洲国产成人在线| 4438成人网| 91日韩精品一区| 精品在线免费观看| 亚洲福利一区二区| 国产精品久久久久9999吃药| 91精品国模一区二区三区| www.欧美日韩国产在线| 久久国产剧场电影| 亚洲一区在线观看免费| 欧美极品另类videosde| 欧美不卡一二三| 欧美人体做爰大胆视频| 色综合视频在线观看| 国产成人一级电影| 九色综合国产一区二区三区| 午夜精品影院在线观看| 自拍偷拍亚洲综合| 中文一区在线播放| 欧美精品一区二区三区视频| 制服丝袜亚洲播放| 欧美日韩1234| 色噜噜久久综合| 色综合天天综合网国产成人综合天| 经典三级一区二区| 麻豆久久一区二区| 日韩国产欧美视频| 日韩电影在线观看网站| 国产一区二区免费视频| 免费看欧美女人艹b| 日韩不卡免费视频| 午夜精品福利一区二区蜜股av| 一区二区在线电影| 亚洲激情校园春色| 亚洲精品第一国产综合野| 亚洲精品日日夜夜| 一区二区高清在线| 亚洲国产精品久久一线不卡| 亚洲欧美另类小说视频| 亚洲精品视频在线观看免费 | av成人免费在线观看| 国产福利不卡视频| 成人自拍视频在线| av中文字幕一区| 91在线观看视频| 日本韩国精品在线| 欧美另类z0zxhd电影| 欧美日韩视频一区二区| 欧美一级一级性生活免费录像| 日韩欧美在线123| 精品理论电影在线| 国产欧美一区二区精品性色超碰| 国产欧美一区二区三区鸳鸯浴| 中文字幕一区日韩精品欧美| 亚洲人一二三区| 午夜欧美在线一二页| 美女www一区二区| 国产一区二区久久| 波多野结衣亚洲| 在线观看欧美日本| 欧美一级欧美三级| 国产日韩欧美综合在线| 中文字幕日韩一区二区| 亚洲午夜电影在线| 精品在线观看视频| 不卡的电视剧免费网站有什么| 日本高清不卡一区| 欧美va天堂va视频va在线| 国产精品午夜春色av| 一区二区三区欧美| 激情图片小说一区| 一本到高清视频免费精品| 91精品国产综合久久久蜜臀图片| 久久五月婷婷丁香社区| 亚洲免费av高清| 黑人巨大精品欧美黑白配亚洲| 成人黄色网址在线观看| 欧美日韩成人一区| 中文字幕成人av| 日韩综合一区二区| 成人国产视频在线观看| 欧美久久婷婷综合色| 国产精品网站在线播放| 视频在线观看91| 不卡视频在线看| 精品国产网站在线观看| 亚洲卡通动漫在线| 国产成人精品亚洲日本在线桃色| 在线精品视频一区二区三四| 久久综合九色综合97_久久久| 一区二区三区高清| 国产精品一区免费视频| 91精品国产综合久久香蕉的特点| 中文字幕五月欧美| 国产一区三区三区| 欧美一级在线视频| 午夜免费欧美电影| 99久久综合精品| 2021中文字幕一区亚洲| 午夜一区二区三区视频| 成人免费va视频| 久久亚洲捆绑美女| 蜜桃精品视频在线| 欧美色手机在线观看| 亚洲特级片在线| 成人免费视频一区| 久久久99免费| 黄页视频在线91| 日韩一级视频免费观看在线| 亚洲一卡二卡三卡四卡| 色综合天天视频在线观看| 欧美国产一区二区| 国产一区二区在线观看视频| 制服丝袜亚洲网站| 午夜激情一区二区| 欧美日韩日日夜夜| 亚洲v精品v日韩v欧美v专区| 色吧成人激情小说| 一区二区三区在线免费| 不卡视频免费播放| 亚洲欧洲www| 97超碰欧美中文字幕| 国产精品毛片高清在线完整版| 国产激情一区二区三区四区 | 欧美日本国产视频| 一区二区三区中文在线观看| 99免费精品视频| 亚洲男人天堂一区| 色综合 综合色| 一区二区三区欧美亚洲| 欧美性视频一区二区三区| 亚洲电影视频在线| 91精品国产免费| 久久aⅴ国产欧美74aaa| 久久久国产一区二区三区四区小说 | 欧美性生活大片视频| 亚洲一卡二卡三卡四卡| 欧美片网站yy| 日本欧美一区二区三区| 91精品黄色片免费大全| 精品无人区卡一卡二卡三乱码免费卡| 精品va天堂亚洲国产| 国产精品1区2区| 综合在线观看色| 欧美日韩精品免费| 青娱乐精品在线视频| 久久久五月婷婷| 成人天堂资源www在线| 亚洲精品伦理在线| 欧美一区二区国产| 成人午夜伦理影院| 一二三四区精品视频| 日韩一二三区不卡| 成人开心网精品视频| 亚洲综合色在线| 日韩欧美国产三级| 成人一区二区三区| 婷婷夜色潮精品综合在线| 欧美大肚乱孕交hd孕妇| 成人av在线网站| 午夜欧美2019年伦理| 国产日韩精品视频一区|