lemon/prim.h
changeset 2428 c06e86364234
parent 2391 14a343be7a5a
child 2490 31a93dd6f714
equal deleted inserted replaced
11:07336b4933ea 12:d93dd4011ef5
   399     Prim() {}
   399     Prim() {}
   400 
   400 
   401   public:      
   401   public:      
   402     
   402     
   403     ///Constructor.
   403     ///Constructor.
   404     
   404     ///
   405     ///\param _graph the graph the algorithm will run on.
   405     ///\param _graph the graph the algorithm will run on.
   406     ///\param _cost the cost map used by the algorithm.
   406     ///\param _cost the cost map used by the algorithm.
   407     Prim(const UGraph& _graph, const CostMap& _cost) :
   407     Prim(const UGraph& _graph, const CostMap& _cost) :
   408       graph(&_graph), cost(&_cost),
   408       graph(&_graph), cost(&_cost),
   409       _pred(NULL), local_pred(false),
   409       _pred(0), local_pred(false),
   410       _tree(NULL), local_tree(false),
   410       _tree(0), local_tree(false),
   411       _processed(NULL), local_processed(false),
   411       _processed(0), local_processed(false),
   412       _heap_cross_ref(NULL), local_heap_cross_ref(false),
   412       _heap_cross_ref(0), local_heap_cross_ref(false),
   413       _heap(NULL), local_heap(false)
   413       _heap(0), local_heap(false)
   414     {
   414     {
   415       checkConcept<concepts::UGraph, UGraph>();
   415       checkConcept<concepts::UGraph, UGraph>();
   416     }
   416     }
   417     
   417     
   418     ///Destructor.
   418     ///Destructor.
   423       if(local_heap_cross_ref) delete _heap_cross_ref;
   423       if(local_heap_cross_ref) delete _heap_cross_ref;
   424       if(local_heap) delete _heap;
   424       if(local_heap) delete _heap;
   425     }
   425     }
   426 
   426 
   427     ///\brief Sets the cost map.
   427     ///\brief Sets the cost map.
   428 
   428     ///
   429     ///Sets the cost map.
   429     ///Sets the cost map.
   430     ///\return <tt> (*this) </tt>
   430     ///\return <tt> (*this) </tt>
   431     Prim &costMap(const CostMap &m){
   431     Prim &costMap(const CostMap &m){
   432       cost = &m;
   432       cost = &m;
   433       return *this;
   433       return *this;
   434     }
   434     }
   435 
   435 
   436     ///\brief Sets the map storing the predecessor edges.
   436     ///\brief Sets the map storing the predecessor edges.
   437 
   437     ///
   438     ///Sets the map storing the predecessor edges.
   438     ///Sets the map storing the predecessor edges.
   439     ///If you don't use this function before calling \ref run(),
   439     ///If you don't use this function before calling \ref run(),
   440     ///it will allocate one. The destuctor deallocates this
   440     ///it will allocate one. The destuctor deallocates this
   441     ///automatically allocated map, of course.
   441     ///automatically allocated map, of course.
   442     ///\return <tt> (*this) </tt>
   442     ///\return <tt> (*this) </tt>
   448       _pred = &m;
   448       _pred = &m;
   449       return *this;
   449       return *this;
   450     }
   450     }
   451 
   451 
   452     ///\brief Sets the map storing the tree edges.
   452     ///\brief Sets the map storing the tree edges.
   453 
   453     ///
   454     ///Sets the map storing the tree edges.
   454     ///Sets the map storing the tree edges.
   455     ///If you don't use this function before calling \ref run(),
   455     ///If you don't use this function before calling \ref run(),
   456     ///it will allocate one. The destuctor deallocates this
   456     ///it will allocate one. The destuctor deallocates this
   457     ///automatically allocated map, of course.
   457     ///automatically allocated map, of course.
   458     ///By default this is a NullMap.
   458     ///By default this is a NullMap.
   465       _tree = &m;
   465       _tree = &m;
   466       return *this;
   466       return *this;
   467     }
   467     }
   468 
   468 
   469     ///\brief Sets the heap and the cross reference used by algorithm.
   469     ///\brief Sets the heap and the cross reference used by algorithm.
   470 
   470     ///
   471     ///Sets the heap and the cross reference used by algorithm.
   471     ///Sets the heap and the cross reference used by algorithm.
   472     ///If you don't use this function before calling \ref run(),
   472     ///If you don't use this function before calling \ref run(),
   473     ///it will allocate one. The destuctor deallocates this
   473     ///it will allocate one. The destuctor deallocates this
   474     ///automatically allocated map, of course.
   474     ///automatically allocated map, of course.
   475     ///\return <tt> (*this) </tt>
   475     ///\return <tt> (*this) </tt>
   499     ///computation.
   499     ///computation.
   500 
   500 
   501     ///@{
   501     ///@{
   502 
   502 
   503     ///\brief Initializes the internal data structures.
   503     ///\brief Initializes the internal data structures.
   504 
   504     ///
   505     ///Initializes the internal data structures.
   505     ///Initializes the internal data structures.
   506     ///
   506     ///
   507     void init(){
   507     void init(){
   508       create_maps();
   508       create_maps();
   509       _heap->clear();
   509       _heap->clear();
   513 	_heap_cross_ref->set(u,Heap::PRE_HEAP);
   513 	_heap_cross_ref->set(u,Heap::PRE_HEAP);
   514       }
   514       }
   515     }
   515     }
   516     
   516     
   517     ///\brief Adds a new source node.
   517     ///\brief Adds a new source node.
   518 
   518     ///
   519     ///Adds a new source node to the priority heap.
   519     ///Adds a new source node to the priority heap.
   520     ///
   520     ///
   521     ///It checks if the node has already been added to the heap and
   521     ///It checks if the node has already been added to the heap and
   522     ///it is pushed to the heap only if it was not in the heap.
   522     ///it is pushed to the heap only if it was not in the heap.
   523     void addSource(Node s){
   523     void addSource(Node s){
   524       if(_heap->state(s) != Heap::IN_HEAP) {
   524       if(_heap->state(s) != Heap::IN_HEAP) {
   525 	_heap->push(s,Value());
   525 	_heap->push(s,Value());
   526       }
   526       }
   527     }
   527     }
   528     ///\brief Processes the next node in the priority heap
   528     ///\brief Processes the next node in the priority heap
   529 
   529     ///
   530     ///Processes the next node in the priority heap.
   530     ///Processes the next node in the priority heap.
   531     ///
   531     ///
   532     ///\return The processed node.
   532     ///\return The processed node.
   533     ///
   533     ///
   534     ///\warning The priority heap must not be empty!
   534     ///\warning The priority heap must not be empty!
   557       if ((*_pred)[v]!=INVALID)_tree->set((*_pred)[v],true);
   557       if ((*_pred)[v]!=INVALID)_tree->set((*_pred)[v],true);
   558       return v;
   558       return v;
   559     }
   559     }
   560 
   560 
   561     ///\brief Next node to be processed.
   561     ///\brief Next node to be processed.
   562     
   562     ///
   563     ///Next node to be processed.
   563     ///Next node to be processed.
   564     ///
   564     ///
   565     ///\return The next node to be processed or INVALID if the priority heap
   565     ///\return The next node to be processed or INVALID if the priority heap
   566     /// is empty.
   566     /// is empty.
   567     Node nextNode(){ 
   567     Node nextNode(){ 
   568       return _heap->empty()?_heap->top():INVALID;
   568       return _heap->empty()?_heap->top():INVALID;
   569     }
   569     }
   570  
   570  
   571     ///\brief Returns \c false if there are nodes to be processed in the priority heap
   571     ///\brief Returns \c false if there are nodes to be processed in
       
   572     ///the priority heap
   572     ///
   573     ///
   573     ///Returns \c false if there are nodes
   574     ///Returns \c false if there are nodes
   574     ///to be processed in the priority heap
   575     ///to be processed in the priority heap
   575     bool emptyQueue() { return _heap->empty(); }
   576     bool emptyQueue() { return _heap->empty(); }
   576     ///\brief Returns the number of the nodes to be processed in the priority heap
   577 
   577 
   578     ///\brief Returns the number of the nodes to be processed in the
       
   579     ///priority heap
       
   580     ///
   578     ///Returns the number of the nodes to be processed in the priority heap
   581     ///Returns the number of the nodes to be processed in the priority heap
   579     ///
   582     ///
   580     int queueSize() { return _heap->size(); }
   583     int queueSize() { return _heap->size(); }
   581     
   584     
   582     ///\brief Executes the algorithm.
   585     ///\brief Executes the algorithm.
   583 
   586     ///
   584     ///Executes the algorithm.
   587     ///Executes the algorithm.
   585     ///
   588     ///
   586     ///\pre init() must be called and at least one node should be added
   589     ///\pre init() must be called and at least one node should be added
   587     ///with addSource() before using this function.
   590     ///with addSource() before using this function.
   588     ///
   591     ///
   593     void start(){
   596     void start(){
   594       while ( !_heap->empty() ) processNextNode();
   597       while ( !_heap->empty() ) processNextNode();
   595     }
   598     }
   596     
   599     
   597     ///\brief Executes the algorithm until a condition is met.
   600     ///\brief Executes the algorithm until a condition is met.
   598 
   601     ///
   599     ///Executes the algorithm until a condition is met.
   602     ///Executes the algorithm until a condition is met.
   600     ///
   603     ///
   601     ///\pre init() must be called and at least one node should be added
   604     ///\pre init() must be called and at least one node should be added
   602     ///with addSource() before using this function.
   605     ///with addSource() before using this function.
   603     ///
   606     ///
   608       while ( !_heap->empty() && !nm[_heap->top()] ) processNextNode();
   611       while ( !_heap->empty() && !nm[_heap->top()] ) processNextNode();
   609       if ( !_heap->empty() ) _processed->set(_heap->top(),true);
   612       if ( !_heap->empty() ) _processed->set(_heap->top(),true);
   610     }
   613     }
   611     
   614     
   612     ///\brief Runs %Prim algorithm.
   615     ///\brief Runs %Prim algorithm.
   613     
   616     ///
   614     ///This method runs the %Prim algorithm
   617     ///This method runs the %Prim algorithm
   615     ///in order to compute the
   618     ///in order to compute the
   616     ///minimum spanning tree (or minimum spanning forest).
   619     ///minimum spanning tree (or minimum spanning forest).
   617     ///The method also works on graphs that has more than one components.
   620     ///The method also works on graphs that has more than one components.
   618     ///In this case it computes the minimum spanning forest.
   621     ///In this case it computes the minimum spanning forest.
   625 	}
   628 	}
   626       }
   629       }
   627     }
   630     }
   628 
   631 
   629     ///\brief Runs %Prim algorithm from node \c s.
   632     ///\brief Runs %Prim algorithm from node \c s.
   630     
   633     ///
   631     ///This method runs the %Prim algorithm from node \c s
   634     ///This method runs the %Prim algorithm from node \c s
   632     ///in order to
   635     ///in order to
   633     ///compute the
   636     ///compute the
   634     ///minimun spanning tree
   637     ///minimun spanning tree
   635     ///
   638     ///
   636     ///\note d.run(s) is just a shortcut of the following code.
   639     ///\note p.run(s) is just a shortcut of the following code.
   637     ///\code
   640     ///\code
   638     ///  d.init();
   641     ///  p.init();
   639     ///  d.addSource(s);
   642     ///  p.addSource(s);
   640     ///  d.start();
   643     ///  p.start();
   641     ///\endcode
   644     ///\endcode
   642     ///\note If the graph has more than one components, the method
   645     ///\note If the graph has more than one components, the method
   643     ///will compute the minimun spanning tree for only one component.
   646     ///will compute the minimun spanning tree for only one component.
   644     ///
   647     ///
   645     ///See \ref run() if you want to compute the minimal spanning forest.
   648     ///See \ref run() if you want to compute the minimal spanning forest.
   659     
   662     
   660     ///@{
   663     ///@{
   661 
   664 
   662     ///\brief Returns the 'previous edge' of the minimum spanning tree.
   665     ///\brief Returns the 'previous edge' of the minimum spanning tree.
   663 
   666 
   664     ///For a node \c v it returns the 'previous edge' of the minimum spanning tree,
   667     ///For a node \c v it returns the 'previous edge' of the minimum
   665     ///i.e. it returns the edge from where \c v was reached. For a source node
   668     ///spanning tree, i.e. it returns the edge from where \c v was
   666     ///or an unreachable node it is \ref INVALID.
   669     ///reached. For a source node or an unreachable node it is \ref
   667     ///The minimum spanning tree used here is equal to the minimum spanning tree used
   670     ///INVALID.  The minimum spanning tree used here is equal to the
   668     ///in \ref predNode().  \pre \ref run() or \ref start() must be called before
   671     ///minimum spanning tree used in \ref predNode().  
   669     ///using this function.
   672     ///\pre \ref run() or \ref start() must be called before using
       
   673     ///this function.
   670     UEdge predEdge(Node v) const { return (*_pred)[v]; }
   674     UEdge predEdge(Node v) const { return (*_pred)[v]; }
   671 
   675 
   672     ///\brief Returns the 'previous node' of the minimum spanning tree.
   676     ///\brief Returns the 'previous node' of the minimum spanning
   673 
   677     ///tree.
   674     ///For a node \c v it returns the 'previous node' of the minimum spanning tree,
   678     ///
   675     ///i.e. it returns the node from where \c v was reached. For a source node
   679     ///For a node \c v it returns the 'previous node' of the minimum
   676     ///or an unreachable node it is \ref INVALID.
   680     ///spanning tree, i.e. it returns the node from where \c v was
   677     //The minimum spanning tree used here is equal to the minimum spanning
   681     ///reached. For a source node or an unreachable node it is \ref
   678     ///tree used in \ref predEdge().  \pre \ref run() or \ref start() must be called
   682     ///INVALID.  //The minimum spanning tree used here is equal to the
   679     ///before using this function.
   683     ///minimum spanning tree used in \ref predEdge().  
       
   684     ///\pre \ref run() or \ref start() must be called before using
       
   685     ///this function.
   680     Node predNode(Node v) const { return (*_pred)[v]==INVALID ? INVALID:
   686     Node predNode(Node v) const { return (*_pred)[v]==INVALID ? INVALID:
   681 				  graph->source((*_pred)[v]); }
   687 				  graph->source((*_pred)[v]); }
   682     
   688     
   683     ///\brief Returns a reference to the NodeMap of the edges of the minimum spanning tree.
   689     ///\brief Returns a reference to the NodeMap of the edges of the
   684 
       
   685     ///Returns a reference to the NodeMap of the edges of the
       
   686     ///minimum spanning tree.
   690     ///minimum spanning tree.
   687     ///\pre \ref run() or \ref start() must be called before using this function.
   691     ///
       
   692     ///Returns a reference to the NodeMap of the edges of the minimum
       
   693     ///spanning tree.
       
   694     ///\pre \ref run() or \ref start() must be called before using
       
   695     ///this function.
   688     const PredMap &predMap() const { return *_pred;}
   696     const PredMap &predMap() const { return *_pred;}
   689  
   697  
   690     ///\brief Returns a reference to the tree edges map.
   698     ///\brief Returns a reference to the tree edges map.
   691 
   699 
   692     ///Returns a reference to the TreeEdgeMap of the edges of the
   700     ///Returns a reference to the TreeEdgeMap of the edges of the
   693     ///minimum spanning tree. The value of the map is \c true only if the edge is in
   701     ///minimum spanning tree. The value of the map is \c true only if
   694     ///the minimum spanning tree.
   702     ///the edge is in the minimum spanning tree.
       
   703     ///
   695     ///\warning By default, the TreeEdgeMap is a NullMap.
   704     ///\warning By default, the TreeEdgeMap is a NullMap.
   696     ///
   705     ///
   697     ///If it is not set before the execution of the algorithm, use the \ref
   706     ///If it is not set before the execution of the algorithm, use the
   698     ///treeMap(TreeMap&) function (after the execution) to set an UEdgeMap with the
   707     ///\ref treeMap(TreeMap&) function (after the execution) to set an
   699     ///edges of the minimum spanning tree in O(n) time where n is the number of
   708     ///UEdgeMap with the edges of the minimum spanning tree in O(n)
   700     ///nodes in the graph.
   709     ///time where n is the number of nodes in the graph.
   701     ///\pre \ref run() or \ref start() must be called before using this function.
   710     ///\pre \ref run() or \ref start() must be called before using
       
   711     ///this function.
   702     const TreeMap &treeMap() const { return *_tree;}
   712     const TreeMap &treeMap() const { return *_tree;}
   703  
   713  
   704     ///\brief Sets the tree edges map.
   714     ///\brief Sets the tree edges map.
   705 
   715     ///
   706     ///Sets the TreeMap of the edges of the minimum spanning tree.
   716     ///Sets the TreeMap of the edges of the minimum spanning tree.
   707     ///The map values belonging to the edges of the minimum
   717     ///The map values belonging to the edges of the minimum
   708     ///spanning tree are set to \c tree_edge_value or \c true by default,
   718     ///spanning tree are set to \c tree_edge_value or \c true by default,
   709     ///the other map values remain untouched.
   719     ///the other map values remain untouched.
   710     ///
   720     ///
   711     ///\pre \ref run() or \ref start() must be called before using this function.
   721     ///\pre \ref run() or \ref start() must be called before using
       
   722     ///this function.
   712 
   723 
   713     template<class TreeMap>
   724     template<class TreeMap>
   714     void quickTreeEdges(
   725     void quickTreeEdges(TreeMap& tree) const {
   715         TreeMap& tree,
       
   716         const typename TreeMap::Value& tree_edge_value=true) const {
       
   717       for(NodeIt i(*graph);i!=INVALID;++i){
   726       for(NodeIt i(*graph);i!=INVALID;++i){
   718         if((*_pred)[i]!=INVALID) tree.set((*_pred)[i],tree_edge_value);
   727         if((*_pred)[i]!=INVALID) tree.set((*_pred)[i],true);
   719       }
   728       }
   720     }
   729     }
   721 
   730 
   722     ///\brief Sets the tree edges map.
   731     ///\brief Sets the tree edges map.
   723 
   732     ///
   724     ///Sets the TreeMap of the edges of the minimum spanning tree.
   733     ///Sets the TreeMap of the edges of the minimum spanning tree.
   725     ///The map values belonging to the edges of the minimum
   734     ///The map values belonging to the edges of the minimum
   726     ///spanning tree are set to \c tree_edge_value or \c true by default while
   735     ///spanning tree are set to \c tree_edge_value or \c true by default while
   727     ///the edge values not belonging to the minimum spanning tree are set to
   736     ///the edge values not belonging to the minimum spanning tree are set to
   728     ///\c tree_default_value or \c false by default.
   737     ///\c tree_default_value or \c false by default.
   729     ///
   738     ///
   730     ///\pre \ref run() or \ref start() must be called before using this function.
   739     ///\pre \ref run() or \ref start() must be called before using
   731 
   740     ///this function.
   732     template<class TreeMap>
   741     template <class TreeMap>
   733     void treeEdges(
   742     void treeEdges(TreeMap& tree) const {
   734         TreeMap& tree,
   743       typedef typename ItemSetTraits<UGraph,UEdge>::ItemIt TreeMapIt;
   735         const typename TreeMap::Value& tree_edge_value=true,
   744       for(TreeMapIt i(*graph); i != INVALID; ++i) {
   736         const typename TreeMap::Value& tree_default_value=false) const {
   745 	tree.set(i,false);
   737       for(typename ItemSetTraits<UGraph,UEdge>::ItemIt i(*graph);i!=INVALID;++i)
   746       }
   738 	tree.set(i,tree_default_value);
   747       for(NodeIt i(*graph); i != INVALID; ++i){
   739       for(NodeIt i(*graph);i!=INVALID;++i){
   748         if((*_pred)[i] != INVALID) tree.set((*_pred)[i],true);
   740         if((*_pred)[i]!=INVALID) tree.set((*_pred)[i],tree_edge_value);
       
   741       }
   749       }
   742     }
   750     }
   743 
   751 
   744     ///\brief Checks if a node is reachable from the starting node.
   752     ///\brief Checks if a node is reachable from the starting node.
   745 
   753     ///
   746     ///Returns \c true if \c v is reachable from the starting node.
   754     ///Returns \c true if \c v is reachable from the starting node.
   747     ///\warning The source nodes are inditated as unreached.
   755     ///\warning The source nodes are inditated as unreached.
   748     ///\pre \ref run() or \ref start() must be called before using this function.
   756     ///\pre \ref run() or \ref start() must be called before using
       
   757     ///this function.
   749     ///
   758     ///
   750     bool reached(Node v) { return (*_heap_cross_ref)[v] != Heap::PRE_HEAP; }
   759     bool reached(Node v) { return (*_heap_cross_ref)[v] != Heap::PRE_HEAP; }
   751 
   760 
   752     ///\brief Checks if a node is processed.
   761     ///\brief Checks if a node is processed.
   753 
   762     ///
   754     ///Returns \c true if \c v is processed, i.e. \c v is already connencted to the
   763     ///Returns \c true if \c v is processed, i.e. \c v is already
   755     ///minimum spanning tree.
   764     ///connencted to the minimum spanning tree.  \pre \ref run() or
   756     ///\pre \ref run() or \ref start() must be called before using this function.
   765     ///\ref start() must be called before using this function.
   757     ///
       
   758     bool processed(Node v) { return (*_heap_cross_ref)[v] == Heap::POST_HEAP; }
   766     bool processed(Node v) { return (*_heap_cross_ref)[v] == Heap::POST_HEAP; }
   759     
   767     
   760 
   768 
   761     ///\brief Checks if an edge is in the spanning tree or not.
   769     ///\brief Checks if an edge is in the spanning tree or not.
   762 
   770     ///
   763     ///Checks if an edge is in the spanning tree or not.
   771     ///Checks if an edge is in the spanning tree or not.
   764     ///\param e is the edge that will be checked
   772     ///\param e is the edge that will be checked
   765     ///\return \c true if e is in the spanning tree, \c false otherwise
   773     ///\return \c true if e is in the spanning tree, \c false otherwise
   766     bool tree(UEdge e){
   774     bool tree(UEdge e){
   767       return (*_pred)[*graph.source(e)]==e || (*_pred)[*graph.target(e)]==e;
   775       return (*_pred)[*graph.source(e)]==e || (*_pred)[*graph.target(e)]==e;
   768     }
   776     }
       
   777 
       
   778     ///\brief Returns the value of the total cost of the spanning tree.
       
   779     ///
       
   780     /// Returns the value of the total cost of the spanning tree.
       
   781     Value treeValue() const {
       
   782       Value value = 0;
       
   783       for(NodeIt i(*graph); i!= INVALID; ++i){
       
   784         if ((*_pred)[i] != INVALID) value += (*cost)[(*_pred)[i]];
       
   785       }
       
   786       return value;
       
   787     }
   769     ///@}
   788     ///@}
   770   };
   789   };
   771 
   790 
   772 
   791 
   773   /// \ingroup spantree
   792   /// \ingroup spantree
   777   /// Function type interface for Prim algorithm.
   796   /// Function type interface for Prim algorithm.
   778   /// \param graph the UGraph that the algorithm runs on
   797   /// \param graph the UGraph that the algorithm runs on
   779   /// \param cost the CostMap of the edges
   798   /// \param cost the CostMap of the edges
   780   /// \retval tree the EdgeMap that contains whether an edge is in 
   799   /// \retval tree the EdgeMap that contains whether an edge is in 
   781   /// the spanning tree or not
   800   /// the spanning tree or not
       
   801   /// \return The total cost of the spanning tree
   782   ///
   802   ///
   783   ///\sa Prim
   803   ///\sa Prim
   784   template<class Graph,class CostMap,class TreeMap>
   804   template<class Graph,class CostMap,class TreeMap>
   785   void prim(const Graph& graph, const CostMap& cost,TreeMap& tree){
   805   typename CostMap::Value prim(const Graph& graph, 
   786     typename Prim<Graph,CostMap>::template DefTreeMap<TreeMap>::
   806                                const CostMap& cost,
       
   807                                TreeMap& tree){
       
   808     typename Prim<Graph,CostMap>::
       
   809       template DefTreeMap<TreeMap>::
   787       Create prm(graph,cost);
   810       Create prm(graph,cost);
   788     prm.treeMap(tree);
   811     prm.treeMap(tree);
   789     prm.run();
   812     prm.run();
       
   813     return prm.treeValue();
   790   }
   814   }
   791 
   815 
       
   816   /// \ingroup spantree
       
   817   ///
       
   818   /// \brief Function type interface for Prim algorithm.
       
   819   ///
       
   820   /// Function type interface for Prim algorithm.
       
   821   /// \param graph the UGraph that the algorithm runs on
       
   822   /// \param cost the CostMap of the edges
       
   823   /// the spanning tree or not
       
   824   /// \return The total cost of the spanning tree
       
   825   ///
       
   826   ///\sa Prim
       
   827   template<class Graph,class CostMap,class TreeMap>
       
   828   typename CostMap::Value prim(const Graph& graph, 
       
   829                                const CostMap& cost){
       
   830     typename Prim<Graph,CostMap>::
       
   831       Create prm(graph,cost);
       
   832     prm.run();
       
   833     return prm.treeValue();
       
   834   }
       
   835 
   792 } //END OF NAMESPACE LEMON
   836 } //END OF NAMESPACE LEMON
   793 
   837 
   794 #endif
   838 #endif