diff -r 4cade8579363 -r 7a98fe2ed989 lemon/dijkstra.h --- a/lemon/dijkstra.h Mon Oct 24 17:03:02 2005 +0000 +++ b/lemon/dijkstra.h Wed Oct 26 10:50:47 2005 +0000 @@ -61,7 +61,6 @@ ///This function instantiates a \ref HeapCrossRef. /// \param G is the graph, to which we would like to define the /// HeapCrossRef. - /// \todo The graph alone may be insufficient for the initialization static HeapCrossRef *createHeapCrossRef(const GR &G) { return new HeapCrossRef(G); @@ -74,8 +73,7 @@ ///\sa BinHeap ///\sa Dijkstra typedef BinHeap, - std::less > Heap; + HeapCrossRef, std::less > Heap; static Heap *createHeap(HeapCrossRef& R) { @@ -360,12 +358,12 @@ struct DefHeapTraits : public Traits { typedef CR HeapCrossRef; typedef H Heap; - static HeapCrossRef *createHeapCrossRef(const Graph &G) { - return new HeapCrossRef(G); + static HeapCrossRef *createHeapCrossRef(const Graph &) { + throw UninitializedParameter(); } - static Heap *createHeap(HeapCrossRef &R) + static Heap *createHeap(HeapCrossRef &) { - return new Heap(R); + throw UninitializedParameter(); } }; ///\ref named-templ-param "Named parameter" for setting heap and cross @@ -379,6 +377,32 @@ : public Dijkstra< Graph, LengthMap, DefHeapTraits > { typedef Dijkstra< Graph, LengthMap, DefHeapTraits > Create; }; + + template + struct DefStandardHeapTraits : public Traits { + typedef CR HeapCrossRef; + typedef H Heap; + static HeapCrossRef *createHeapCrossRef(const Graph &G) { + return new HeapCrossRef(G); + } + static Heap *createHeap(HeapCrossRef &R) + { + return new Heap(R); + } + }; + ///\ref named-templ-param "Named parameter" for setting heap and cross + ///reference type with automatic allocation + + ///\ref named-templ-param "Named parameter" for setting heap and cross + ///reference type. It can allocate the heap and the cross reference + ///object if the cross reference's constructor waits for the graph as + ///parameter and the heap's constructor waits for the cross reference. + template > + struct DefStandardHeap + : public Dijkstra< Graph, LengthMap, DefStandardHeapTraits > { + typedef Dijkstra< Graph, LengthMap, DefStandardHeapTraits > + Create; + }; ///@} @@ -456,6 +480,28 @@ return *this; } + ///Sets the heap and the cross reference used by algorithm. + + ///Sets the heap and the cross reference used by algorithm. + ///If you don't use this function before calling \ref run(), + ///it will allocate one. The destuctor deallocates this + ///automatically allocated map, of course. + ///\return (*this) + Dijkstra &heap(Heap& heap, HeapCrossRef &crossRef) + { + if(local_heap_cross_ref) { + delete _heap_cross_ref; + local_heap_cross_ref=false; + } + _heap_cross_ref = &crossRef; + if(local_heap) { + delete _heap; + local_heap=false; + } + _heap = &heap; + return *this; + } + private: void finalizeNodeData(Node v,Value dst) {