lemon/dijkstra.h
changeset 1741 7a98fe2ed989
parent 1734 2fb5ceac10e7
child 1761 896464fe9fbb
     1.1 --- a/lemon/dijkstra.h	Mon Oct 24 17:03:02 2005 +0000
     1.2 +++ b/lemon/dijkstra.h	Wed Oct 26 10:50:47 2005 +0000
     1.3 @@ -61,7 +61,6 @@
     1.4      ///This function instantiates a \ref HeapCrossRef. 
     1.5      /// \param G is the graph, to which we would like to define the 
     1.6      /// HeapCrossRef.
     1.7 -    /// \todo The graph alone may be insufficient for the initialization
     1.8      static HeapCrossRef *createHeapCrossRef(const GR &G) 
     1.9      {
    1.10        return new HeapCrossRef(G);
    1.11 @@ -74,8 +73,7 @@
    1.12      ///\sa BinHeap
    1.13      ///\sa Dijkstra
    1.14      typedef BinHeap<typename Graph::Node, typename LM::Value,
    1.15 -		    typename GR::template NodeMap<int>,
    1.16 -		    std::less<Value> > Heap;
    1.17 +		    HeapCrossRef, std::less<Value> > Heap;
    1.18  
    1.19      static Heap *createHeap(HeapCrossRef& R) 
    1.20      {
    1.21 @@ -360,12 +358,12 @@
    1.22      struct DefHeapTraits : public Traits {
    1.23        typedef CR HeapCrossRef;
    1.24        typedef H Heap;
    1.25 -      static HeapCrossRef *createHeapCrossRef(const Graph &G) {
    1.26 -	return new HeapCrossRef(G);
    1.27 +      static HeapCrossRef *createHeapCrossRef(const Graph &) {
    1.28 +	throw UninitializedParameter();
    1.29        }
    1.30 -      static Heap *createHeap(HeapCrossRef &R) 
    1.31 +      static Heap *createHeap(HeapCrossRef &) 
    1.32        {
    1.33 -	return new Heap(R);
    1.34 +	throw UninitializedParameter();
    1.35        }
    1.36      };
    1.37      ///\ref named-templ-param "Named parameter" for setting heap and cross 
    1.38 @@ -379,6 +377,32 @@
    1.39        : public Dijkstra< Graph,	LengthMap, DefHeapTraits<H, CR> > { 
    1.40        typedef Dijkstra< Graph,	LengthMap, DefHeapTraits<H, CR> > Create;
    1.41      };
    1.42 +
    1.43 +    template <class H, class CR>
    1.44 +    struct DefStandardHeapTraits : public Traits {
    1.45 +      typedef CR HeapCrossRef;
    1.46 +      typedef H Heap;
    1.47 +      static HeapCrossRef *createHeapCrossRef(const Graph &G) {
    1.48 +	return new HeapCrossRef(G);
    1.49 +      }
    1.50 +      static Heap *createHeap(HeapCrossRef &R) 
    1.51 +      {
    1.52 +	return new Heap(R);
    1.53 +      }
    1.54 +    };
    1.55 +    ///\ref named-templ-param "Named parameter" for setting heap and cross 
    1.56 +    ///reference type with automatic allocation
    1.57 +
    1.58 +    ///\ref named-templ-param "Named parameter" for setting heap and cross 
    1.59 +    ///reference type. It can allocate the heap and the cross reference 
    1.60 +    ///object if the cross reference's constructor waits for the graph as 
    1.61 +    ///parameter and the heap's constructor waits for the cross reference.
    1.62 +    template <class H, class CR = typename Graph::template NodeMap<int> >
    1.63 +    struct DefStandardHeap
    1.64 +      : public Dijkstra< Graph,	LengthMap, DefStandardHeapTraits<H, CR> > { 
    1.65 +      typedef Dijkstra< Graph,	LengthMap, DefStandardHeapTraits<H, CR> > 
    1.66 +      Create;
    1.67 +    };
    1.68      
    1.69      ///@}
    1.70  
    1.71 @@ -456,6 +480,28 @@
    1.72        return *this;
    1.73      }
    1.74  
    1.75 +    ///Sets the heap and the cross reference used by algorithm.
    1.76 +
    1.77 +    ///Sets the heap and the cross reference used by algorithm.
    1.78 +    ///If you don't use this function before calling \ref run(),
    1.79 +    ///it will allocate one. The destuctor deallocates this
    1.80 +    ///automatically allocated map, of course.
    1.81 +    ///\return <tt> (*this) </tt>
    1.82 +    Dijkstra &heap(Heap& heap, HeapCrossRef &crossRef)
    1.83 +    {
    1.84 +      if(local_heap_cross_ref) {
    1.85 +	delete _heap_cross_ref;
    1.86 +	local_heap_cross_ref=false;
    1.87 +      }
    1.88 +      _heap_cross_ref = &crossRef;
    1.89 +      if(local_heap) {
    1.90 +	delete _heap;
    1.91 +	local_heap=false;
    1.92 +      }
    1.93 +      _heap = &heap;
    1.94 +      return *this;
    1.95 +    }
    1.96 +
    1.97    private:
    1.98      void finalizeNodeData(Node v,Value dst)
    1.99      {