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

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? graph.cpp

?? adaboost code in matlab
?? 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

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
欧美日韩精品一区视频| 亚洲网友自拍偷拍| 亚洲一区二区精品久久av| 日本欧美肥老太交大片| 91亚洲国产成人精品一区二区三| 欧美午夜精品久久久| 国产网红主播福利一区二区| 亚洲444eee在线观看| 波多野结衣中文字幕一区 | 成人免费高清视频| 欧美日韩高清影院| 亚洲女厕所小便bbb| 成人亚洲精品久久久久软件| 日韩美女主播在线视频一区二区三区 | 在线观看精品一区| 国产精品美女视频| 麻豆精品一区二区av白丝在线| 在线观看亚洲专区| 亚洲色图清纯唯美| 国产91丝袜在线播放0| 日韩精品专区在线影院重磅| 日韩国产精品久久久| 欧美日韩国产首页| 亚洲v日本v欧美v久久精品| 在线免费不卡电影| 亚洲激情校园春色| 色94色欧美sute亚洲线路一久| 久久久亚洲午夜电影| 国产综合色产在线精品| 亚洲精品一区二区三区在线观看| 日韩电影一区二区三区四区| 欧美人成免费网站| 日韩综合一区二区| 日韩欧美一级精品久久| 日本女优在线视频一区二区| 制服丝袜亚洲色图| 久久精品久久综合| 精品精品欲导航| 久久se精品一区二区| 精品国产百合女同互慰| 国产精品一区在线观看乱码| 久久久亚洲午夜电影| 国产成人综合精品三级| 国产日韩欧美一区二区三区综合 | 在线免费观看日本欧美| 亚洲高清免费观看高清完整版在线观看| 色先锋aa成人| 午夜精品久久久久久不卡8050| 91精品国产黑色紧身裤美女| 蜜臀av性久久久久蜜臀aⅴ四虎| 日韩三级电影网址| 国产成人av一区二区| 中文字幕在线视频一区| 91国偷自产一区二区开放时间 | 国产欧美日本一区二区三区| heyzo一本久久综合| 亚洲精品成人精品456| 欧美电影一区二区| 国产综合一区二区| 亚洲欧洲在线观看av| 欧美久久久久中文字幕| 狠狠色综合日日| 亚洲女与黑人做爰| 日韩欧美亚洲国产另类| 成人app网站| 强制捆绑调教一区二区| 中文字幕久久午夜不卡| 欧美日韩美女一区二区| 国产毛片精品视频| 亚洲精品乱码久久久久久久久| 51午夜精品国产| 成人av在线资源网站| 亚洲3atv精品一区二区三区| 欧美国产精品专区| 在线不卡免费av| av在线播放不卡| 九九视频精品免费| 亚洲卡通欧美制服中文| 久久夜色精品国产噜噜av| 在线这里只有精品| 国产麻豆精品一区二区| 日韩精品一级中文字幕精品视频免费观看| 久久久久久电影| 欧美日韩高清一区二区| 暴力调教一区二区三区| 秋霞电影网一区二区| 一区二区三区欧美久久| 国产欧美一区二区精品仙草咪| 欧美裸体bbwbbwbbw| 99久久国产综合精品女不卡| 精品影视av免费| 亚洲18色成人| 亚洲乱码中文字幕| 日本一区二区三区电影| 日韩午夜激情免费电影| 欧美色区777第一页| 91香蕉视频在线| 成人av资源网站| 国产99久久久国产精品免费看| 日本aⅴ亚洲精品中文乱码| 亚洲综合精品久久| 亚洲免费观看高清完整| 中文字幕av一区二区三区| 精品国产一区二区三区久久久蜜月| 在线这里只有精品| 成年人网站91| 99riav久久精品riav| 丁香网亚洲国际| 国产原创一区二区| 极品少妇xxxx偷拍精品少妇| 日本不卡视频一二三区| 欧美aaaaaa午夜精品| 午夜欧美大尺度福利影院在线看| 一区二区三区蜜桃网| 亚洲精品第一国产综合野| 亚洲女爱视频在线| 一级精品视频在线观看宜春院 | 久久伊人蜜桃av一区二区| 欧美一二三四在线| 日韩视频一区二区在线观看| 欧美精品九九99久久| 91精品久久久久久久99蜜桃| 717成人午夜免费福利电影| 制服.丝袜.亚洲.中文.综合| 欧美一区二区三区喷汁尤物| 欧美一级日韩不卡播放免费| 日韩美一区二区三区| 久久亚洲一区二区三区四区| 国产婷婷色一区二区三区 | 国产人成一区二区三区影院| 久久免费午夜影院| 欧美韩国日本综合| 国产精品色婷婷| 亚洲综合免费观看高清在线观看| 亚洲v中文字幕| 另类调教123区| 国产高清亚洲一区| 99精品欧美一区二区三区综合在线| 94-欧美-setu| 欧美视频三区在线播放| 欧美日韩在线直播| 26uuu亚洲婷婷狠狠天堂| 国产精品色噜噜| 亚洲国产一区二区在线播放| 捆绑调教美女网站视频一区| 国产精品性做久久久久久| 色综合激情久久| 日韩一区二区三区在线| 欧美国产精品一区二区| 亚洲午夜精品网| 国内精品国产成人| 91免费观看在线| 欧美大片顶级少妇| 亚洲欧美色图小说| 日韩在线a电影| 成人国产一区二区三区精品| 欧美性猛交一区二区三区精品 | 欧美日韩激情在线| 久久精品亚洲一区二区三区浴池 | 国产女同性恋一区二区| 一区二区三区日韩欧美精品| 国产在线看一区| 欧美在线观看禁18| 久久久久国色av免费看影院| 亚洲一级片在线观看| 国产成人av电影| 欧美一区二区三区在线| 国产精品福利av| 久草精品在线观看| 91久久精品一区二区三区| 精品日韩一区二区| 亚洲国产精品久久久男人的天堂| 国产一区二区美女| 制服丝袜亚洲网站| 亚洲综合另类小说| 波多野结衣一区二区三区| 日韩一区二区三区在线观看| 亚洲综合激情小说| 91社区在线播放| 中文字幕巨乱亚洲| 国产综合一区二区| 日韩一级免费一区| 亚洲影院理伦片| 91视频免费看| 久久精品亚洲精品国产欧美kt∨| 亚洲h在线观看| 欧美性三三影院| 亚洲精品高清视频在线观看| 99精品视频在线播放观看| 国产欧美日韩亚州综合 | 午夜亚洲国产au精品一区二区| 国产成人三级在线观看| 精品乱人伦一区二区三区| 日韩黄色片在线观看| 欧美放荡的少妇| 日本aⅴ精品一区二区三区| 欧美日韩三级在线| 亚洲妇女屁股眼交7| 欧美日韩国产小视频在线观看| 亚洲综合网站在线观看|