diff -r c6acc34f98dc -r 1a7fe3bef514 lemon/core.h --- a/lemon/core.h Fri Oct 16 10:21:37 2009 +0200 +++ b/lemon/core.h Thu Nov 05 15:50:01 2009 +0100 @@ -2,7 +2,7 @@ * * This file is a part of LEMON, a generic C++ optimization library. * - * Copyright (C) 2003-2008 + * Copyright (C) 2003-2009 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport * (Egervary Research Group on Combinatorial Optimization, EGRES). * @@ -27,6 +27,16 @@ #include #include +// Disable the following warnings when compiling with MSVC: +// C4250: 'class1' : inherits 'class2::member' via dominance +// C4355: 'this' : used in base member initializer list +// C4503: 'function' : decorated name length exceeded, name was truncated +// C4800: 'type' : forcing value to bool 'true' or 'false' (performance warning) +// C4996: 'function': was declared deprecated +#ifdef _MSC_VER +#pragma warning( disable : 4250 4355 4503 4800 4996 ) +#endif + ///\file ///\brief LEMON core utilities. /// @@ -1034,28 +1044,27 @@ /// ///\sa findArc() ///\sa ArcLookUp, AllArcLookUp, DynArcLookUp - template - class ConArcIt : public _Graph::Arc { + template + class ConArcIt : public GR::Arc { + typedef typename GR::Arc Parent; + public: - typedef _Graph Graph; - typedef typename Graph::Arc Parent; - - typedef typename Graph::Arc Arc; - typedef typename Graph::Node Node; + typedef typename GR::Arc Arc; + typedef typename GR::Node Node; /// \brief Constructor. /// /// Construct a new ConArcIt iterating on the arcs that /// connects nodes \c u and \c v. - ConArcIt(const Graph& g, Node u, Node v) : _graph(g) { + ConArcIt(const GR& g, Node u, Node v) : _graph(g) { Parent::operator=(findArc(_graph, u, v)); } /// \brief Constructor. /// /// Construct a new ConArcIt that continues the iterating from arc \c a. - ConArcIt(const Graph& g, Arc a) : Parent(a), _graph(g) {} + ConArcIt(const GR& g, Arc a) : Parent(a), _graph(g) {} /// \brief Increment operator. /// @@ -1066,7 +1075,7 @@ return *this; } private: - const Graph& _graph; + const GR& _graph; }; namespace _core_bits { @@ -1157,28 +1166,27 @@ ///\endcode /// ///\sa findEdge() - template - class ConEdgeIt : public _Graph::Edge { + template + class ConEdgeIt : public GR::Edge { + typedef typename GR::Edge Parent; + public: - typedef _Graph Graph; - typedef typename Graph::Edge Parent; - - typedef typename Graph::Edge Edge; - typedef typename Graph::Node Node; + typedef typename GR::Edge Edge; + typedef typename GR::Node Node; /// \brief Constructor. /// /// Construct a new ConEdgeIt iterating on the edges that /// connects nodes \c u and \c v. - ConEdgeIt(const Graph& g, Node u, Node v) : _graph(g), _u(u), _v(v) { + ConEdgeIt(const GR& g, Node u, Node v) : _graph(g), _u(u), _v(v) { Parent::operator=(findEdge(_graph, _u, _v)); } /// \brief Constructor. /// /// Construct a new ConEdgeIt that continues iterating from edge \c e. - ConEdgeIt(const Graph& g, Edge e) : Parent(e), _graph(g) {} + ConEdgeIt(const GR& g, Edge e) : Parent(e), _graph(g) {} /// \brief Increment operator. /// @@ -1188,7 +1196,7 @@ return *this; } private: - const Graph& _graph; + const GR& _graph; Node _u, _v; }; @@ -1211,29 +1219,32 @@ ///optimal time bound in a constant factor for any distribution of ///queries. /// - ///\tparam G The type of the underlying digraph. + ///\tparam GR The type of the underlying digraph. /// ///\sa ArcLookUp ///\sa AllArcLookUp - template + template class DynArcLookUp - : protected ItemSetTraits::ItemNotifier::ObserverBase + : protected ItemSetTraits::ItemNotifier::ObserverBase { - public: - typedef typename ItemSetTraits + typedef typename ItemSetTraits ::ItemNotifier::ObserverBase Parent; - TEMPLATE_DIGRAPH_TYPEDEFS(G); - typedef G Digraph; + TEMPLATE_DIGRAPH_TYPEDEFS(GR); + + public: + + /// The Digraph type + typedef GR Digraph; protected: - class AutoNodeMap : public ItemSetTraits::template Map::Type { + class AutoNodeMap : public ItemSetTraits::template Map::Type { + typedef typename ItemSetTraits::template Map::Type Parent; + public: - typedef typename ItemSetTraits::template Map::Type Parent; - - AutoNodeMap(const G& digraph) : Parent(digraph, INVALID) {} + AutoNodeMap(const GR& digraph) : Parent(digraph, INVALID) {} virtual void add(const Node& node) { Parent::add(node); @@ -1257,12 +1268,6 @@ } }; - const Digraph &_g; - AutoNodeMap _head; - typename Digraph::template ArcMap _parent; - typename Digraph::template ArcMap _left; - typename Digraph::template ArcMap _right; - class ArcLess { const Digraph &g; public: @@ -1273,6 +1278,14 @@ } }; + protected: + + const Digraph &_g; + AutoNodeMap _head; + typename Digraph::template ArcMap _parent; + typename Digraph::template ArcMap _left; + typename Digraph::template ArcMap _right; + public: ///Constructor @@ -1315,27 +1328,27 @@ virtual void clear() { for(NodeIt n(_g);n!=INVALID;++n) { - _head.set(n, INVALID); + _head[n] = INVALID; } } void insert(Arc arc) { Node s = _g.source(arc); Node t = _g.target(arc); - _left.set(arc, INVALID); - _right.set(arc, INVALID); + _left[arc] = INVALID; + _right[arc] = INVALID; Arc e = _head[s]; if (e == INVALID) { - _head.set(s, arc); - _parent.set(arc, INVALID); + _head[s] = arc; + _parent[arc] = INVALID; return; } while (true) { if (t < _g.target(e)) { if (_left[e] == INVALID) { - _left.set(e, arc); - _parent.set(arc, e); + _left[e] = arc; + _parent[arc] = e; splay(arc); return; } else { @@ -1343,8 +1356,8 @@ } } else { if (_right[e] == INVALID) { - _right.set(e, arc); - _parent.set(arc, e); + _right[e] = arc; + _parent[arc] = e; splay(arc); return; } else { @@ -1357,27 +1370,27 @@ void remove(Arc arc) { if (_left[arc] == INVALID) { if (_right[arc] != INVALID) { - _parent.set(_right[arc], _parent[arc]); + _parent[_right[arc]] = _parent[arc]; } if (_parent[arc] != INVALID) { if (_left[_parent[arc]] == arc) { - _left.set(_parent[arc], _right[arc]); + _left[_parent[arc]] = _right[arc]; } else { - _right.set(_parent[arc], _right[arc]); + _right[_parent[arc]] = _right[arc]; } } else { - _head.set(_g.source(arc), _right[arc]); + _head[_g.source(arc)] = _right[arc]; } } else if (_right[arc] == INVALID) { - _parent.set(_left[arc], _parent[arc]); + _parent[_left[arc]] = _parent[arc]; if (_parent[arc] != INVALID) { if (_left[_parent[arc]] == arc) { - _left.set(_parent[arc], _left[arc]); + _left[_parent[arc]] = _left[arc]; } else { - _right.set(_parent[arc], _left[arc]); + _right[_parent[arc]] = _left[arc]; } } else { - _head.set(_g.source(arc), _left[arc]); + _head[_g.source(arc)] = _left[arc]; } } else { Arc e = _left[arc]; @@ -1387,38 +1400,38 @@ e = _right[e]; } Arc s = _parent[e]; - _right.set(_parent[e], _left[e]); + _right[_parent[e]] = _left[e]; if (_left[e] != INVALID) { - _parent.set(_left[e], _parent[e]); + _parent[_left[e]] = _parent[e]; } - _left.set(e, _left[arc]); - _parent.set(_left[arc], e); - _right.set(e, _right[arc]); - _parent.set(_right[arc], e); + _left[e] = _left[arc]; + _parent[_left[arc]] = e; + _right[e] = _right[arc]; + _parent[_right[arc]] = e; - _parent.set(e, _parent[arc]); + _parent[e] = _parent[arc]; if (_parent[arc] != INVALID) { if (_left[_parent[arc]] == arc) { - _left.set(_parent[arc], e); + _left[_parent[arc]] = e; } else { - _right.set(_parent[arc], e); + _right[_parent[arc]] = e; } } splay(s); } else { - _right.set(e, _right[arc]); - _parent.set(_right[arc], e); - _parent.set(e, _parent[arc]); + _right[e] = _right[arc]; + _parent[_right[arc]] = e; + _parent[e] = _parent[arc]; if (_parent[arc] != INVALID) { if (_left[_parent[arc]] == arc) { - _left.set(_parent[arc], e); + _left[_parent[arc]] = e; } else { - _right.set(_parent[arc], e); + _right[_parent[arc]] = e; } } else { - _head.set(_g.source(arc), e); + _head[_g.source(arc)] = e; } } } @@ -1430,17 +1443,17 @@ Arc me=v[m]; if (a < m) { Arc left = refreshRec(v,a,m-1); - _left.set(me, left); - _parent.set(left, me); + _left[me] = left; + _parent[left] = me; } else { - _left.set(me, INVALID); + _left[me] = INVALID; } if (m < b) { Arc right = refreshRec(v,m+1,b); - _right.set(me, right); - _parent.set(right, me); + _right[me] = right; + _parent[right] = me; } else { - _right.set(me, INVALID); + _right[me] = INVALID; } return me; } @@ -1452,46 +1465,46 @@ if (!v.empty()) { std::sort(v.begin(),v.end(),ArcLess(_g)); Arc head = refreshRec(v,0,v.size()-1); - _head.set(n, head); - _parent.set(head, INVALID); + _head[n] = head; + _parent[head] = INVALID; } - else _head.set(n, INVALID); + else _head[n] = INVALID; } } void zig(Arc v) { Arc w = _parent[v]; - _parent.set(v, _parent[w]); - _parent.set(w, v); - _left.set(w, _right[v]); - _right.set(v, w); + _parent[v] = _parent[w]; + _parent[w] = v; + _left[w] = _right[v]; + _right[v] = w; if (_parent[v] != INVALID) { if (_right[_parent[v]] == w) { - _right.set(_parent[v], v); + _right[_parent[v]] = v; } else { - _left.set(_parent[v], v); + _left[_parent[v]] = v; } } if (_left[w] != INVALID){ - _parent.set(_left[w], w); + _parent[_left[w]] = w; } } void zag(Arc v) { Arc w = _parent[v]; - _parent.set(v, _parent[w]); - _parent.set(w, v); - _right.set(w, _left[v]); - _left.set(v, w); + _parent[v] = _parent[w]; + _parent[w] = v; + _right[w] = _left[v]; + _left[v] = w; if (_parent[v] != INVALID){ if (_left[_parent[v]] == w) { - _left.set(_parent[v], v); + _left[_parent[v]] = v; } else { - _right.set(_parent[v], v); + _right[_parent[v]] = v; } } if (_right[w] != INVALID){ - _parent.set(_right[w], w); + _parent[_right[w]] = w; } } @@ -1623,16 +1636,19 @@ ///digraph changes. This is a time consuming (superlinearly proportional ///(O(m logm)) to the number of arcs). /// - ///\tparam G The type of the underlying digraph. + ///\tparam GR The type of the underlying digraph. /// ///\sa DynArcLookUp ///\sa AllArcLookUp - template + template class ArcLookUp { + TEMPLATE_DIGRAPH_TYPEDEFS(GR); + public: - TEMPLATE_DIGRAPH_TYPEDEFS(G); - typedef G Digraph; + + /// The Digraph type + typedef GR Digraph; protected: const Digraph &_g; @@ -1733,22 +1749,21 @@ ///digraph changes. This is a time consuming (superlinearly proportional ///(O(m logm)) to the number of arcs). /// - ///\tparam G The type of the underlying digraph. + ///\tparam GR The type of the underlying digraph. /// ///\sa DynArcLookUp ///\sa ArcLookUp - template - class AllArcLookUp : public ArcLookUp + template + class AllArcLookUp : public ArcLookUp { - using ArcLookUp::_g; - using ArcLookUp::_right; - using ArcLookUp::_left; - using ArcLookUp::_head; + using ArcLookUp::_g; + using ArcLookUp::_right; + using ArcLookUp::_left; + using ArcLookUp::_head; - TEMPLATE_DIGRAPH_TYPEDEFS(G); - typedef G Digraph; + TEMPLATE_DIGRAPH_TYPEDEFS(GR); - typename Digraph::template ArcMap _next; + typename GR::template ArcMap _next; Arc refreshNext(Arc head,Arc next=INVALID) { @@ -1767,13 +1782,17 @@ } public: + + /// The Digraph type + typedef GR Digraph; + ///Constructor ///Constructor. /// ///It builds up the search database, which remains valid until the digraph ///changes. - AllArcLookUp(const Digraph &g) : ArcLookUp(g), _next(g) {refreshNext();} + AllArcLookUp(const Digraph &g) : ArcLookUp(g), _next(g) {refreshNext();} ///Refresh the data structure at a node. @@ -1783,7 +1802,7 @@ ///the number of the outgoing arcs of \c n. void refresh(Node n) { - ArcLookUp::refresh(n); + ArcLookUp::refresh(n); refreshNext(_head[n]); } @@ -1830,7 +1849,7 @@ #ifdef DOXYGEN Arc operator()(Node s, Node t, Arc prev=INVALID) const {} #else - using ArcLookUp::operator() ; + using ArcLookUp::operator() ; Arc operator()(Node s, Node t, Arc prev) const { return prev==INVALID?(*this)(s,t):_next[prev];