Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

undir_graph.h

Go to the documentation of this file.
00001 /* -*- C++ -*-
00002  *
00003  * lemon/concept/undir_graph_component.h - Part of LEMON, a generic
00004  * C++ optimization library
00005  *
00006  * Copyright (C) 2005 Egervary Jeno Kombinatorikus Optimalizalasi
00007  * Kutatocsoport (Egervary Research Group on Combinatorial Optimization,
00008  * EGRES).
00009  *
00010  * Permission to use, modify and distribute this software is granted
00011  * provided that this copyright notice appears in all copies. For
00012  * precise terms see the accompanying LICENSE file.
00013  *
00014  * This software is provided "AS IS" with no warranty of any kind,
00015  * express or implied, and with no claim as to its suitability for any
00016  * purpose.
00017  *
00018  */
00019 
00023 
00024 
00025 #ifndef LEMON_CONCEPT_UNDIR_GRAPH_H
00026 #define LEMON_CONCEPT_UNDIR_GRAPH_H
00027 
00028 #include <lemon/concept/graph_component.h>
00029 #include <lemon/concept/graph.h>
00030 #include <lemon/utility.h>
00031 
00032 namespace lemon {
00033   namespace concept {
00034 
00035 //     /// Skeleton class which describes an edge with direction in \ref
00036 //     /// UndirGraph "undirected graph".
00037     template <typename UndirGraph>
00038     class UndirGraphEdge : public UndirGraph::UndirEdge {
00039       typedef typename UndirGraph::UndirEdge UndirEdge;
00040       typedef typename UndirGraph::Node Node;
00041     public:
00042 
00044       UndirGraphEdge() {}
00045 
00047       UndirGraphEdge(const UndirGraphEdge& e) : UndirGraph::UndirEdge(e) {}
00048 
00050       UndirGraphEdge(Invalid) {}
00051 
00057       UndirGraphEdge(const UndirGraph &g,
00058                      UndirEdge undir_edge, Node n) {
00059         ignore_unused_variable_warning(undir_edge);
00060         ignore_unused_variable_warning(g);
00061         ignore_unused_variable_warning(n);
00062       }
00063 
00065       UndirGraphEdge& operator=(UndirGraphEdge) { return *this; }
00066 
00068       bool operator==(UndirGraphEdge) const { return true; }
00070       bool operator!=(UndirGraphEdge) const { return false; }
00071 
00073       bool operator<(UndirGraphEdge) const { return false; }
00074 
00075       template <typename Edge>
00076       struct Constraints {
00077         void constraints() {
00078           const_constraints();
00079         }
00080         void const_constraints() const {
00082           UndirEdge ue = e;
00083           ue = e;
00084 
00085           Edge e_with_source(graph,ue,n);
00086           ignore_unused_variable_warning(e_with_source);
00087         }
00088         Edge e;
00089         UndirEdge ue;
00090         UndirGraph graph;
00091         Node n;
00092       };
00093     };
00094     
00095 
00096     struct BaseIterableUndirGraphConcept {
00097 
00098       template <typename Graph>
00099       struct Constraints {
00100 
00101         typedef typename Graph::UndirEdge UndirEdge;
00102         typedef typename Graph::Edge Edge;
00103         typedef typename Graph::Node Node;
00104 
00105         void constraints() {
00106           checkConcept<BaseIterableGraphComponent, Graph>();
00107           checkConcept<GraphItem<>, UndirEdge>();
00108           //checkConcept<UndirGraphEdge<Graph>, Edge>();
00109 
00110           graph.first(ue);
00111           graph.next(ue);
00112 
00113           const_constraints();
00114         }
00115         void const_constraints() {
00116           Node n;
00117           n = graph.target(ue);
00118           n = graph.source(ue);
00119           n = graph.oppositeNode(n0, ue);
00120 
00121           bool b;
00122           b = graph.direction(e);
00123           Edge e = graph.direct(UndirEdge(), true);
00124           e = graph.direct(UndirEdge(), n);
00125  
00126           ignore_unused_variable_warning(b);
00127         }
00128 
00129         Graph graph;
00130         Edge e;
00131         Node n0;
00132         UndirEdge ue;
00133       };
00134 
00135     };
00136 
00137 
00138     struct IterableUndirGraphConcept {
00139 
00140       template <typename Graph>
00141       struct Constraints {
00142         void constraints() {
00145           //checkConcept< BaseIterableUndirGraphConcept, Graph > ();
00146 
00147           checkConcept<IterableGraphComponent, Graph> ();
00148 
00149           typedef typename Graph::UndirEdge UndirEdge;
00150           typedef typename Graph::UndirEdgeIt UndirEdgeIt;
00151           typedef typename Graph::IncEdgeIt IncEdgeIt;
00152 
00153           checkConcept<GraphIterator<Graph, UndirEdge>, UndirEdgeIt>();
00154           checkConcept<GraphIncIterator<Graph, UndirEdge>, IncEdgeIt>();
00155         }
00156       };
00157 
00158     };
00159 
00160     struct MappableUndirGraphConcept {
00161 
00162       template <typename Graph>
00163       struct Constraints {
00164 
00165         struct Dummy {
00166           int value;
00167           Dummy() : value(0) {}
00168           Dummy(int _v) : value(_v) {}
00169         };
00170 
00171         void constraints() {
00172           checkConcept<MappableGraphComponent, Graph>();
00173 
00174           typedef typename Graph::template UndirEdgeMap<int> IntMap;
00175           checkConcept<GraphMap<Graph, typename Graph::UndirEdge, int>,
00176             IntMap >();
00177 
00178           typedef typename Graph::template UndirEdgeMap<bool> BoolMap;
00179           checkConcept<GraphMap<Graph, typename Graph::UndirEdge, bool>,
00180             BoolMap >();
00181 
00182           typedef typename Graph::template UndirEdgeMap<Dummy> DummyMap;
00183           checkConcept<GraphMap<Graph, typename Graph::UndirEdge, Dummy>,
00184             DummyMap >();
00185         }
00186       };
00187 
00188     };
00189 
00190     struct ExtendableUndirGraphConcept {
00191 
00192       template <typename Graph>
00193       struct Constraints {
00194         void constraints() {
00195           node_a = graph.addNode();
00196           uedge = graph.addEdge(node_a, node_b);
00197         }
00198         typename Graph::Node node_a, node_b;
00199         typename Graph::UndirEdge uedge;
00200         Graph graph;
00201       };
00202 
00203     };
00204 
00205     struct ErasableUndirGraphConcept {
00206 
00207       template <typename Graph>
00208       struct Constraints {
00209         void constraints() {
00210           graph.erase(n);
00211           graph.erase(e);
00212         }
00213         Graph graph;
00214         typename Graph::Node n;
00215         typename Graph::UndirEdge e;
00216       };
00217 
00218     };
00219 
00222 
00223 
00225 
00242 
00243     class UndirGraph {
00244     public:
00246 
00249       typedef True UndirTag;
00250 
00253 
00258       class Node {
00259       public:
00261 
00264         Node() { }
00266 
00269         Node(const Node&) { }
00270 
00272 
00275         Node(Invalid) { }
00277 
00280         bool operator==(Node) const { return true; }
00281 
00283         
00286         bool operator!=(Node) const { return true; }
00287 
00289         
00298         bool operator<(Node) const { return false; }
00299 
00300       };
00301     
00303 
00311       class NodeIt : public Node {
00312       public:
00314 
00317         NodeIt() { }
00319         
00322         NodeIt(const NodeIt& n) : Node(n) { }
00324 
00327         NodeIt(Invalid) { }
00329 
00332         NodeIt(const UndirGraph&) { }
00334 
00339         NodeIt(const UndirGraph&, const Node&) { }
00341 
00344         NodeIt& operator++() { return *this; }
00345       };
00346     
00347     
00349 
00352       class UndirEdge {
00353       public:
00355 
00358         UndirEdge() { }
00360 
00363         UndirEdge(const UndirEdge&) { }
00365 
00368         UndirEdge(Invalid) { }
00370 
00373         bool operator==(UndirEdge) const { return true; }
00375 
00378         bool operator!=(UndirEdge) const { return true; }
00379 
00381         
00390         bool operator<(UndirEdge) const { return false; }
00391       };
00392 
00394 
00402       class UndirEdgeIt : public UndirEdge {
00403       public:
00405 
00408         UndirEdgeIt() { }
00410 
00413         UndirEdgeIt(const UndirEdgeIt& e) : UndirEdge(e) { }
00415 
00418         UndirEdgeIt(Invalid) { }
00420     
00422         UndirEdgeIt(const UndirGraph&) { }
00424 
00429         UndirEdgeIt(const UndirGraph&, const UndirEdge&) { } 
00431         
00433         UndirEdgeIt& operator++() { return *this; }
00434       };
00435 
00450       class IncEdgeIt : public UndirEdge {
00451       public:
00453 
00456         IncEdgeIt() { }
00458 
00461         IncEdgeIt(const IncEdgeIt& e) : UndirEdge(e) { }
00463 
00466         IncEdgeIt(Invalid) { }
00468     
00471         IncEdgeIt(const UndirGraph&, const Node&) { }
00473 
00477         IncEdgeIt(const UndirGraph&, const UndirEdge&) { }
00479 
00482         IncEdgeIt& operator++() { return *this; }
00483       };
00484 
00486 
00489       class Edge : public UndirEdge {
00490       public:
00492 
00495         Edge() { }
00497 
00500         Edge(const Edge& e) : UndirEdge(e) { }
00502 
00505         Edge(Invalid) { }
00507 
00510         bool operator==(Edge) const { return true; }
00512 
00515         bool operator!=(Edge) const { return true; }
00516 
00518         
00527         bool operator<(Edge) const { return false; }
00528         
00529       }; 
00531 
00539       class EdgeIt : public Edge {
00540       public:
00542 
00545         EdgeIt() { }
00547 
00550         EdgeIt(const EdgeIt& e) : Edge(e) { }
00552 
00555         EdgeIt(Invalid) { }
00557     
00560         EdgeIt(const UndirGraph &g) { ignore_unused_variable_warning(g); }
00562 
00566         EdgeIt(const UndirGraph&, const Edge&) { } 
00568         
00570         EdgeIt& operator++() { return *this; }
00571       };
00572    
00574 
00584     
00585       class OutEdgeIt : public Edge {
00586       public:
00588 
00591         OutEdgeIt() { }
00593 
00596         OutEdgeIt(const OutEdgeIt& e) : Edge(e) { }
00598 
00601         OutEdgeIt(Invalid) { }
00603     
00608         OutEdgeIt(const UndirGraph& n, const Node& g) {
00609           ignore_unused_variable_warning(n);
00610           ignore_unused_variable_warning(g);
00611         }
00613 
00617         OutEdgeIt(const UndirGraph&, const Edge&) { }
00619         
00622         OutEdgeIt& operator++() { return *this; }
00623       };
00624 
00626 
00636 
00637       class InEdgeIt : public Edge {
00638       public:
00640 
00643         InEdgeIt() { }
00645 
00648         InEdgeIt(const InEdgeIt& e) : Edge(e) { }
00650 
00653         InEdgeIt(Invalid) { }
00655     
00660         InEdgeIt(const UndirGraph& g, const Node& n) { 
00661           ignore_unused_variable_warning(n);
00662           ignore_unused_variable_warning(g);
00663         }
00665 
00669         InEdgeIt(const UndirGraph&, const Edge&) { }
00671 
00674         InEdgeIt& operator++() { return *this; }
00675       };
00676 
00684       template<class T> 
00685       class NodeMap : public ReadWriteMap< Node, T >
00686       {
00687       public:
00688 
00690         NodeMap(const UndirGraph&) { }
00692         NodeMap(const UndirGraph&, T) { }
00693 
00695         NodeMap(const NodeMap& nm) : ReadWriteMap< Node, T >(nm) { }
00697         NodeMap& operator=(const NodeMap&) { return *this; }
00698         // \todo fix this concept
00699       };
00700 
00708       template<class T> 
00709       class EdgeMap : public ReadWriteMap<Edge,T>
00710       {
00711       public:
00712 
00714         EdgeMap(const UndirGraph&) { }
00716         EdgeMap(const UndirGraph&, T) { }
00718         EdgeMap(const EdgeMap& em) : ReadWriteMap<Edge,T>(em) { }
00720         EdgeMap& operator=(const EdgeMap&) { return *this; }
00721         // \todo fix this concept    
00722       };
00723 
00725 
00731       template<class T> 
00732       class UndirEdgeMap : public ReadWriteMap<UndirEdge,T>
00733       {
00734       public:
00735 
00737         UndirEdgeMap(const UndirGraph&) { }
00739         UndirEdgeMap(const UndirGraph&, T) { }
00741         UndirEdgeMap(const UndirEdgeMap& em) : ReadWriteMap<UndirEdge,T>(em) {}
00743         UndirEdgeMap &operator=(const UndirEdgeMap&) { return *this; }
00744         // \todo fix this concept    
00745       };
00746 
00751       Edge direct(const UndirEdge&, const Node&) const {
00752         return INVALID;
00753       }
00754 
00760       Edge direct(const UndirEdge&, bool) const {
00761         return INVALID;
00762       }
00763 
00768       bool direction(Edge) const { return true; }
00769 
00773       Edge oppositeEdge(Edge) const { return INVALID; }
00774 
00778       Node oppositeNode(Node, UndirEdge) const { return INVALID; }
00779 
00791       Node source(UndirEdge) const { return INVALID; }
00792 
00794       Node target(UndirEdge) const { return INVALID; }
00795 
00797       Node source(Edge) const { return INVALID; }
00798 
00800       Node target(Edge) const { return INVALID; }
00801 
00802 //       /// \brief First node of the graph
00803 //       ///
00804 //       /// \note This method is part of so called \ref
00805 //       /// developpers_interface "Developpers' interface", so it shouldn't
00806 //       /// be used in an end-user program.
00807       void first(Node&) const {}
00808 //       /// \brief Next node of the graph
00809 //       ///
00810 //       /// \note This method is part of so called \ref
00811 //       /// developpers_interface "Developpers' interface", so it shouldn't
00812 //       /// be used in an end-user program.
00813       void next(Node&) const {}
00814 
00815 //       /// \brief First undirected edge of the graph
00816 //       ///
00817 //       /// \note This method is part of so called \ref
00818 //       /// developpers_interface "Developpers' interface", so it shouldn't
00819 //       /// be used in an end-user program.
00820       void first(UndirEdge&) const {}
00821 //       /// \brief Next undirected edge of the graph
00822 //       ///
00823 //       /// \note This method is part of so called \ref
00824 //       /// developpers_interface "Developpers' interface", so it shouldn't
00825 //       /// be used in an end-user program.
00826       void next(UndirEdge&) const {}
00827 
00828 //       /// \brief First directed edge of the graph
00829 //       ///
00830 //       /// \note This method is part of so called \ref
00831 //       /// developpers_interface "Developpers' interface", so it shouldn't
00832 //       /// be used in an end-user program.
00833       void first(Edge&) const {}
00834 //       /// \brief Next directed edge of the graph
00835 //       ///
00836 //       /// \note This method is part of so called \ref
00837 //       /// developpers_interface "Developpers' interface", so it shouldn't
00838 //       /// be used in an end-user program.
00839       void next(Edge&) const {}
00840 
00841 //       /// \brief First outgoing edge from a given node
00842 //       ///
00843 //       /// \note This method is part of so called \ref
00844 //       /// developpers_interface "Developpers' interface", so it shouldn't
00845 //       /// be used in an end-user program.
00846       void firstOut(Edge&, Node) const {}
00847 //       /// \brief Next outgoing edge to a node
00848 //       ///
00849 //       /// \note This method is part of so called \ref
00850 //       /// developpers_interface "Developpers' interface", so it shouldn't
00851 //       /// be used in an end-user program.
00852       void nextOut(Edge&) const {}
00853 
00854 //       /// \brief First incoming edge to a given node
00855 //       ///
00856 //       /// \note This method is part of so called \ref
00857 //       /// developpers_interface "Developpers' interface", so it shouldn't
00858 //       /// be used in an end-user program.
00859       void firstIn(Edge&, Node) const {}
00860 //       /// \brief Next incoming edge to a node
00861 //       ///
00862 //       /// \note This method is part of so called \ref
00863 //       /// developpers_interface "Developpers' interface", so it shouldn't
00864 //       /// be used in an end-user program.
00865       void nextIn(Edge&) const {}
00866 
00867 
00871       Node baseNode(OutEdgeIt e) const {
00872         return source(e);
00873       }
00878       Node runningNode(OutEdgeIt e) const {
00879         return target(e);
00880       }
00881 
00885       Node baseNode(InEdgeIt e) const {
00886         return target(e);
00887       }
00892       Node runningNode(InEdgeIt e) const {
00893         return source(e);
00894       }
00895 
00899       Node baseNode(IncEdgeIt) const {
00900         return INVALID;
00901       }
00902       
00906       Node runningNode(IncEdgeIt) const {
00907         return INVALID;
00908       }
00909 
00910       template <typename Graph>
00911       struct Constraints {
00912         void constraints() {
00913           checkConcept<BaseIterableUndirGraphConcept, Graph>();
00914           checkConcept<IterableUndirGraphConcept, Graph>();
00915           checkConcept<MappableUndirGraphConcept, Graph>();
00916         }
00917       };
00918 
00919     };
00920 
00925     class ExtendableUndirGraph : public UndirGraph {
00926     public:
00927       
00932       Node addNode();
00933 
00938       UndirEdge addEdge(const Node& from, const Node& to);
00939 
00944       void clear() { }
00945 
00946       template <typename Graph>
00947       struct Constraints {
00948         void constraints() {
00949           checkConcept<BaseIterableUndirGraphConcept, Graph>();
00950           checkConcept<IterableUndirGraphConcept, Graph>();
00951           checkConcept<MappableUndirGraphConcept, Graph>();
00952 
00953           checkConcept<UndirGraph, Graph>();
00954           checkConcept<ExtendableUndirGraphConcept, Graph>();
00955           checkConcept<ClearableGraphComponent, Graph>();
00956         }
00957       };
00958 
00959     };
00960 
00965     class ErasableUndirGraph : public ExtendableUndirGraph {
00966     public:
00967 
00972       void erase(Node) { }
00977       void erase(UndirEdge) { }
00978 
00979       template <typename Graph>
00980       struct Constraints {
00981         void constraints() {
00982           checkConcept<ExtendableUndirGraph, Graph>();
00983           checkConcept<ErasableUndirGraphConcept, Graph>();
00984         }
00985       };
00986 
00987     };
00988 
00990 
00991   }
00992 
00993 }
00994 
00995 #endif

Generated on Sat Aug 27 14:14:50 2005 for LEMON by  doxygen 1.4.4