# HG changeset patch # User deba # Date 1131993521 0 # Node ID 62e7d237e1fb521ccfa07035ca1475786482d9df # Parent c7dd9d8c770a834d38a3fc1df32691be77011523 Modification on the base graph concept The extended interface does not changed diff -r c7dd9d8c770a -r 62e7d237e1fb lemon/bits/graph_extender.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/lemon/bits/graph_extender.h Mon Nov 14 18:38:41 2005 +0000 @@ -0,0 +1,381 @@ +/* -*- C++ -*- + * lemon/graph_extender.h - Part of LEMON, a generic C++ optimization library + * + * Copyright (C) 2005 Egervary Jeno Kombinatorikus Optimalizalasi + * Kutatocsoport (Egervary Research Group on Combinatorial Optimization, + * EGRES). + * + * Permission to use, modify and distribute this software is granted + * provided that this copyright notice appears in all copies. For + * precise terms see the accompanying LICENSE file. + * + * This software is provided "AS IS" with no warranty of any kind, + * express or implied, and with no claim as to its suitability for any + * purpose. + * + */ + +#ifndef LEMON_GRAPH_EXTENDER_H +#define LEMON_GRAPH_EXTENDER_H + +#include + +namespace lemon { + + template + class GraphExtender : public _Base { + public: + + typedef _Base Parent; + typedef GraphExtender Graph; + + typedef typename Parent::Node Node; + typedef typename Parent::Edge Edge; + + int maxId(Node) const { + return Parent::maxNodeId(); + } + + int maxId(Edge) const { + return Parent::maxEdgeId(); + } + + Node fromId(int id, Node) const { + return Parent::nodeFromId(id); + } + + Edge fromId(int id, Edge) const { + return Parent::edgeFromId(id); + } + + Node oppositeNode(const Node &n, const Edge &e) const { + if (n == Parent::source(e)) + return Parent::target(e); + else if(n==Parent::target(e)) + return Parent::source(e); + else + return INVALID; + } + + }; + + template + class UndirGraphExtender : public _Base { + typedef _Base Parent; + typedef UndirGraphExtender Graph; + + public: + + typedef typename Parent::Edge UndirEdge; + typedef typename Parent::Node Node; + + class Edge : public UndirEdge { + friend class UndirGraphExtender; + + protected: + // FIXME: Marci use opposite logic in his graph adaptors. It would + // be reasonable to syncronize... + bool forward; + + Edge(const UndirEdge &ue, bool _forward) : + UndirEdge(ue), forward(_forward) {} + + public: + Edge() {} + + /// Invalid edge constructor + Edge(Invalid i) : UndirEdge(i), forward(true) {} + + bool operator==(const Edge &that) const { + return forward==that.forward && UndirEdge(*this)==UndirEdge(that); + } + bool operator!=(const Edge &that) const { + return forward!=that.forward || UndirEdge(*this)!=UndirEdge(that); + } + bool operator<(const Edge &that) const { + return forward> 1), bool(id & 1)); + } + + UndirEdge undirEdgeFromId(int id) const { + return Parent::edgeFromId(id >> 1); + } + + Node fromId(int id, Node) const { + return nodeFromId(id); + } + + Edge fromId(int id, Edge) const { + return edgeFromId(id); + } + + UndirEdge fromId(int id, UndirEdge) const { + return undirEdgeFromId(id); + } + + + Edge findEdge(Node source, Node target, Edge prev) const { + if (prev == INVALID) { + UndirEdge edge = Parent::findEdge(source, target); + if (edge != INVALID) return direct(edge, true); + edge = Parent::findEdge(target, source); + if (edge != INVALID) return direct(edge, false); + } else if (direction(prev)) { + UndirEdge edge = Parent::findEdge(source, target, prev); + if (edge != INVALID) return direct(edge, true); + edge = Parent::findEdge(target, source); + if (edge != INVALID) return direct(edge, false); + } else { + UndirEdge edge = Parent::findEdge(target, source, prev); + if (edge != INVALID) return direct(edge, false); + } + return INVALID; + } + + UndirEdge findUndirEdge(Node source, Node target, UndirEdge prev) const { + if (prev == INVALID) { + UndirEdge edge = Parent::findEdge(source, target); + if (edge != INVALID) return edge; + edge = Parent::findEdge(target, source); + if (edge != INVALID) return edge; + } else if (Parent::source(prev) == source) { + UndirEdge edge = Parent::findEdge(source, target, prev); + if (edge != INVALID) return edge; + edge = Parent::findEdge(target, source); + if (edge != INVALID) return edge; + } else { + UndirEdge edge = Parent::findEdge(target, source, prev); + if (edge != INVALID) return edge; + } + return INVALID; + } + + }; + +} + +#endif // LEMON_UNDIR_GRAPH_EXTENDER_H diff -r c7dd9d8c770a -r 62e7d237e1fb lemon/bits/undir_graph_extender.h --- a/lemon/bits/undir_graph_extender.h Mon Nov 14 18:36:45 2005 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,311 +0,0 @@ -/* -*- C++ -*- - * - * lemon/undir_graph_extender.h - Part of LEMON, a generic C++ - * optimization library - * - * Copyright (C) 2005 Egervary Jeno Kombinatorikus Optimalizalasi - * Kutatocsoport (Egervary Research Group on Combinatorial Optimization, - * EGRES). - * - * Permission to use, modify and distribute this software is granted - * provided that this copyright notice appears in all copies. For - * precise terms see the accompanying LICENSE file. - * - * This software is provided "AS IS" with no warranty of any kind, - * express or implied, and with no claim as to its suitability for any - * purpose. - * - */ - -#ifndef LEMON_UNDIR_GRAPH_EXTENDER_H -#define LEMON_UNDIR_GRAPH_EXTENDER_H - -#include - -namespace lemon { - - template - class UndirGraphExtender : public _Base { - typedef _Base Parent; - typedef UndirGraphExtender Graph; - - public: - - typedef typename Parent::Edge UndirEdge; - typedef typename Parent::Node Node; - - class Edge : public UndirEdge { - friend class UndirGraphExtender; - - protected: - // FIXME: Marci use opposite logic in his graph adaptors. It would - // be reasonable to syncronize... - bool forward; - - Edge(const UndirEdge &ue, bool _forward) : - UndirEdge(ue), forward(_forward) {} - - public: - Edge() {} - - /// Invalid edge constructor - Edge(Invalid i) : UndirEdge(i), forward(true) {} - - bool operator==(const Edge &that) const { - return forward==that.forward && UndirEdge(*this)==UndirEdge(that); - } - bool operator!=(const Edge &that) const { - return forward!=that.forward || UndirEdge(*this)!=UndirEdge(that); - } - bool operator<(const Edge &that) const { - return forward #include #include - -#include +#include #include #include @@ -70,12 +69,12 @@ /// Maximum node ID. ///\sa id(Node) - int maxId(Node = INVALID) const { return _nodeNum-1; } + int maxNodeId() const { return _nodeNum-1; } /// Maximum edge ID. /// Maximum edge ID. ///\sa id(Edge) - int maxId(Edge = INVALID) const { return _edgeNum-1; } + int maxEdgeId() const { return _edgeNum-1; } Node source(Edge e) const { return e.id % _nodeNum; } Node target(Edge e) const { return e.id / _nodeNum; } @@ -101,9 +100,9 @@ ///\return The ID of the edge \c e. static int id(Edge e) { return e.id; } - static Node fromId(int id, Node) { return Node(id);} + static Node nodeFromId(int id) { return Node(id);} - static Edge fromId(int id, Edge) { return Edge(id);} + static Edge edgeFromId(int id) { return Edge(id);} typedef True FindEdgeTag; @@ -190,14 +189,10 @@ }; - - typedef AlterableGraphExtender - AlterableFullGraphBase; - typedef IterableGraphExtender - IterableFullGraphBase; typedef StaticMappableGraphExtender< IterableGraphExtender< - AlterableGraphExtender > > ExtendedFullGraphBase; + AlterableGraphExtender< + GraphExtender > > > ExtendedFullGraphBase; /// \ingroup graphs /// @@ -217,7 +212,6 @@ FullGraph(int n) { construct(n); } }; - ///@} class UndirFullGraphBase { int _nodeNum; @@ -252,12 +246,12 @@ /// Maximum node ID. ///\sa id(Node) - int maxId(Node = INVALID) const { return _nodeNum-1; } + int maxNodeId() const { return _nodeNum-1; } /// Maximum edge ID. /// Maximum edge ID. ///\sa id(Edge) - int maxId(Edge = INVALID) const { return _edgeNum-1; } + int maxEdgeId() const { return _edgeNum-1; } Node source(Edge e) const { /// \todo we may do it faster diff -r c7dd9d8c770a -r 62e7d237e1fb lemon/graph_adaptor.h --- a/lemon/graph_adaptor.h Mon Nov 14 18:36:45 2005 +0000 +++ b/lemon/graph_adaptor.h Mon Nov 14 18:38:41 2005 +0000 @@ -33,7 +33,7 @@ #include #include #include -#include +#include #include namespace lemon { @@ -1859,11 +1859,11 @@ int id(const Node& node) const { return graph->id(node); } int id(const Edge& edge) const { return edge.id; } - Node fromId(int id, Node) const { return graph->fromId(id, Node()); } - Edge fromId(int id, Edge) const { return Edge(id); } + Node nodeFromId(int id) const { return graph->fromId(id, Node()); } + Edge edgeFromId(int id) const { return Edge(id); } - int maxId(Node) const { return graph->maxId(Node()); }; - int maxId(Edge) const { return edges.size() - 1; } + int maxNodeId() const { return graph->maxId(Node()); }; + int maxEdgeId() const { return edges.size() - 1; } Node source(const Edge& edge) const { return edges[edge.id].source;} Node target(const Edge& edge) const { return edges[edge.id].target;} diff -r c7dd9d8c770a -r 62e7d237e1fb lemon/grid_graph.h --- a/lemon/grid_graph.h Mon Nov 14 18:36:45 2005 +0000 +++ b/lemon/grid_graph.h Mon Nov 14 18:38:41 2005 +0000 @@ -24,8 +24,7 @@ #include #include #include - -#include +#include #include @@ -164,12 +163,12 @@ /// Maximum node ID. ///\sa id(Node) - int maxId(Node = INVALID) const { return nodeNum() - 1; } + int maxNodeId() const { return nodeNum() - 1; } /// Maximum edge ID. /// Maximum edge ID. ///\sa id(Edge) - int maxId(Edge = INVALID) const { return edgeNum() - 1; } + int maxEdgeId() const { return edgeNum() - 1; } /// \brief Gives back the source node of an edge. /// @@ -215,9 +214,9 @@ ///\return The ID of the edge \c e. static int id(Edge e) { return e.id; } - static Node fromId(int id, Node) { return Node(id);} + static Node nodeFromId(int id) { return Node(id);} - static Edge fromId(int id, Edge) { return Edge(id);} + static Edge edgeFromId(int id) { return Edge(id);} typedef True FindEdgeTag; @@ -358,8 +357,8 @@ /// \code /// GridGraph graph(h, w); /// GridGraph::NodeMap val(graph); - /// for (int i = 0; i < graph.height(); ++i) { - /// for (int j = 0; j < graph.width(); ++j) { + /// for (int i = 0; i < graph.width(); ++i) { + /// for (int j = 0; j < graph.height(); ++j) { /// val[graph(i, j)] = i + j; /// } /// } @@ -503,14 +502,14 @@ /// \brief Row map of the grid graph /// - /// Just returns an RowMap for the grid graph. + /// Just returns a RowMap for the grid graph. GridGraph::RowMap rowMap(const GridGraph& graph) { return GridGraph::RowMap(graph); } - /// \brief Coloumn map of the grid graph + /// \brief Column map of the grid graph /// - /// Just returns an ColMap for the grid graph. + /// Just returns a ColMap for the grid graph. GridGraph::ColMap colMap(const GridGraph& graph) { return GridGraph::ColMap(graph); } diff -r c7dd9d8c770a -r 62e7d237e1fb lemon/hypercube_graph.h --- a/lemon/hypercube_graph.h Mon Nov 14 18:36:45 2005 +0000 +++ b/lemon/hypercube_graph.h Mon Nov 14 18:38:41 2005 +0000 @@ -21,10 +21,12 @@ #include #include #include +#include #include #include #include +#include ///\ingroup graphs ///\file @@ -32,7 +34,7 @@ namespace lemon { - /// \brief Base graph for HyperGraph. + /// \brief Base graph for HyperCubeGraph. /// /// Base graph for hyper-cube graph. It describes some member functions /// which can be used in the HyperCubeGraph. @@ -77,12 +79,12 @@ /// Maximum node ID. ///\sa id(Node) - int maxId(Node = INVALID) const { return nodeNum() - 1; } + int maxNodeId() const { return nodeNum() - 1; } /// Maximum edge ID. /// Maximum edge ID. ///\sa id(Edge) - int maxId(Edge = INVALID) const { return edgeNum() - 1; } + int maxEdgeId() const { return edgeNum() - 1; } /// \brief Gives back the source node of an edge. /// @@ -118,9 +120,9 @@ ///\return The ID of the edge \c e. static int id(Edge e) { return e.id; } - static Node fromId(int id, Node) { return Node(id);} + static Node nodeFromId(int id) { return Node(id);} - static Edge fromId(int id, Edge) { return Edge(id);} + static Edge edgeFromId(int id) { return Edge(id);} class Node { friend class HyperCubeGraphBase; @@ -235,7 +237,8 @@ typedef StaticMappableGraphExtender< IterableGraphExtender< AlterableGraphExtender< - HyperCubeGraphBase > > > ExtendedHyperCubeGraphBase; + GraphExtender< + HyperCubeGraphBase> > > > ExtendedHyperCubeGraphBase; /// \ingroup graphs /// @@ -307,7 +310,8 @@ HyperMap(const Graph& graph, It begin, It end, T fv = 0.0, const BF& bf = BF()) : _graph(graph), _values(begin, end), _first_value(fv), _bin_func(bf) { - if (_values.size() != graph.dimension()) {} + LEMON_ASSERT(_values.size() != graph.dimension(), + "Wrong size of dimension"); } /// \brief Gives back the partial accumulated value. diff -r c7dd9d8c770a -r 62e7d237e1fb lemon/list_graph.h --- a/lemon/list_graph.h Mon Nov 14 18:36:45 2005 +0000 +++ b/lemon/list_graph.h Mon Nov 14 18:38:41 2005 +0000 @@ -27,8 +27,7 @@ #include #include #include - -#include +#include #include @@ -105,13 +104,13 @@ /// Maximum node ID. ///\sa id(Node) - int maxId(Node = INVALID) const { return nodes.size()-1; } + int maxNodeId() const { return nodes.size()-1; } /// Maximum edge ID. /// Maximum edge ID. ///\sa id(Edge) - int maxId(Edge = INVALID) const { return edges.size()-1; } + int maxEdgeId() const { return edges.size()-1; } Node source(Edge e) const { return edges[e.id].source; } Node target(Edge e) const { return edges[e.id].target; } @@ -164,8 +163,8 @@ static int id(Node v) { return v.id; } static int id(Edge e) { return e.id; } - static Node fromId(int id, Node) { return Node(id);} - static Edge fromId(int id, Edge) { return Edge(id);} + static Node nodeFromId(int id) { return Node(id);} + static Edge edgeFromId(int id) { return Edge(id);} /// Adds a new node to the graph. @@ -315,7 +314,8 @@ ExtendableGraphExtender< MappableGraphExtender< IterableGraphExtender< - AlterableGraphExtender > > > > > ExtendedListGraphBase; + AlterableGraphExtender< + GraphExtender > > > > > > ExtendedListGraphBase; /// \addtogroup graphs /// @{ diff -r c7dd9d8c770a -r 62e7d237e1fb lemon/smart_graph.h --- a/lemon/smart_graph.h Mon Nov 14 18:36:45 2005 +0000 +++ b/lemon/smart_graph.h Mon Nov 14 18:38:41 2005 +0000 @@ -30,8 +30,7 @@ #include #include #include - -#include +#include #include @@ -90,12 +89,12 @@ /// Maximum node ID. ///\sa id(Node) - int maxId(Node) const { return nodes.size()-1; } + int maxNodeId() const { return nodes.size()-1; } /// Maximum edge ID. /// Maximum edge ID. ///\sa id(Edge) - int maxId(Edge) const { return edges.size()-1; } + int maxEdgeId() const { return edges.size()-1; } Node source(Edge e) const { return edges[e.n].source; } Node target(Edge e) const { return edges[e.n].target; } @@ -103,8 +102,8 @@ /// Node ID. /// The ID of a valid Node is a nonnegative integer not greater than - /// \ref maxId(Node). The range of the ID's is not surely continuous - /// and the greatest node ID can be actually less then \ref maxId(Node). + /// \ref maxNodeId(). The range of the ID's is not surely continuous + /// and the greatest node ID can be actually less then \ref maxNodeId(). /// /// The ID of the \ref INVALID node is -1. ///\return The ID of the node \c v. @@ -112,16 +111,16 @@ /// Edge ID. /// The ID of a valid Edge is a nonnegative integer not greater than - /// \ref maxId(Edge). The range of the ID's is not surely continuous - /// and the greatest edge ID can be actually less then \ref maxId(Edge). + /// \ref maxEdgeId(). The range of the ID's is not surely continuous + /// and the greatest edge ID can be actually less then \ref maxEdgeId(). /// /// The ID of the \ref INVALID edge is -1. ///\return The ID of the edge \c e. static int id(Edge e) { return e.n; } - static Node fromId(int id, Node) { return Node(id);} + static Node nodeFromId(int id) { return Node(id);} - static Edge fromId(int id, Edge) { return Edge(id);} + static Edge edgeFromId(int id) { return Edge(id);} Node addNode() { Node n; n.n=nodes.size(); @@ -151,10 +150,6 @@ protected: int n; - ///\e - - ///\todo It should be removed (or at least define a setToId() instead). - /// Node(int nn) {n=nn;} public: Node() {} @@ -171,8 +166,6 @@ protected: int n; - ///\todo It should be removed (or at least define a setToId() instead). - /// Edge(int nn) {n=nn;} public: Edge() { } @@ -230,10 +223,10 @@ ExtendableGraphExtender< MappableGraphExtender< IterableGraphExtender< - AlterableGraphExtender > > > > ExtendedSmartGraphBase; + AlterableGraphExtender< + GraphExtender > > > > > ExtendedSmartGraphBase; - /// \addtogroup graphs - /// @{ + /// \ingroup graphs ///A smart graph class.