COIN-OR::LEMON - Graph Library

Changeset 774:4297098d9677 in lemon-0.x for src/hugo/full_graph.h


Ignore:
Timestamp:
08/30/04 14:01:47 (16 years ago)
Author:
Alpar Juttner
Branch:
default
Phase:
public
Convert:
svn:c9d7d8f5-90d6-0310-b91f-818b3a526b0e/lemon/trunk@1066
Message:

Merge back the whole branches/hugo++ to trunk.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/hugo/full_graph.h

    r752 r774  
    6464    Node head(Edge e) const { return e.n/NodeNum; }
    6565
    66     Node aNode(OutEdgeIt e) const { return tail(e); }
    67     Node aNode(InEdgeIt e) const { return head(e); }
    68 
    69     Node bNode(OutEdgeIt e) const { return head(e); }
    70     Node bNode(InEdgeIt e) const { return tail(e); }
    71 
    7266    NodeIt& first(NodeIt& v) const {
    7367      v=NodeIt(*this); return v; }
     
    7973      e=InEdgeIt(*this,v); return e; }
    8074
    81     static bool valid(Edge e) { return e.n!=-1; }
    82     static bool valid(Node n) { return n.n!=-1; }
    83    
    84     template <typename It> It getNext(It it) const
    85     { It tmp(it); return next(tmp); }
    86 
    87     NodeIt& next(NodeIt& it) const {
    88       it.n=(it.n+2)%(NodeNum+1)-1;
    89       return it;
    90     }
    91     OutEdgeIt& next(OutEdgeIt& it) const
    92     { it.n+=NodeNum; if(it.n>=EdgeNum) it.n=-1; return it; }
    93     InEdgeIt& next(InEdgeIt& it) const
    94     { if(!((++it.n)%NodeNum)) it.n=-1; return it; }
    95     static EdgeIt& next(EdgeIt& it) { --it.n; return it; }
    96 
    9775    static int id(Node v) { return v.n; }
    9876    static int id(Edge e) { return e.n; }
    9977
     78    /// Finds an edge between two nodes.
     79   
     80    /// Finds an edge from node \c u to node \c v.
     81    ///
     82    /// If \c prev is \ref INVALID (this is the default value), then
     83    /// It finds the first edge from \c u to \c v. Otherwise it looks for
     84    /// the next edge from \c u to \c v after \c prev.
     85    /// \return The found edge or INVALID if there is no such an edge.
     86    Edge findEdge(Node u,Node v, Edge prev = INVALID)
     87    {
     88      return prev.n==-1?Edge(*this,u.n,v.n):INVALID;
     89    }
     90   
     91     
    10092    class Node {
    10193      friend class FullGraph;
     
    120112   
    121113    class NodeIt : public Node {
     114      const FullGraph *G;
    122115      friend class FullGraph;
    123116    public:
    124117      NodeIt() : Node() { }
     118      NodeIt(const FullGraph& _G,Node n) : Node(n), G(&_G) { }
    125119      NodeIt(Invalid i) : Node(i) { }
    126       NodeIt(const FullGraph& G) : Node(G.NodeNum?0:-1) { }
     120      NodeIt(const FullGraph& _G) : Node(_G.NodeNum?0:-1), G(&_G) { }
    127121      ///\todo Undocumented conversion Node -\> NodeIt.
    128       NodeIt(const FullGraph& G, const Node &n) : Node(n) { }
     122      NodeIt& operator++() { n=(n+2)%(G->NodeNum+1)-1;return *this; }
    129123    };
    130124
     
    139133      friend int FullGraph::id(Edge e);
    140134
    141       Edge(int nn) {n=nn;}
     135      Edge(int nn) : n(nn) {}
     136      Edge(const FullGraph &G, int tail, int head) : n(G.NodeNum*head+tail) {}
    142137    public:
    143138      Edge() { }
     
    155150      friend class FullGraph;
    156151    public:
    157       EdgeIt(const FullGraph& G) : Edge(G.EdgeNum-1) { }
     152      EdgeIt(const FullGraph& _G) : Edge(_G.EdgeNum-1) { }
     153      EdgeIt(const FullGraph&, Edge e) : Edge(e) { }
    158154      EdgeIt (Invalid i) : Edge(i) { }
    159155      EdgeIt() : Edge() { }
     156      EdgeIt& operator++() { --n; return *this; }
     157
    160158      ///\bug This is a workaround until somebody tells me how to
    161159      ///make class \c SymFullGraph::SymEdgeMap friend of Edge
     
    164162   
    165163    class OutEdgeIt : public Edge {
     164      const FullGraph *G;
    166165      friend class FullGraph;
    167166    public:
    168167      OutEdgeIt() : Edge() { }
     168      OutEdgeIt(const FullGraph& _G, Edge e) : Edge(e), G(&_G) { }
    169169      OutEdgeIt (Invalid i) : Edge(i) { }
    170170
    171       OutEdgeIt(const FullGraph& G,const Node v)
    172         : Edge(v.n) {}
     171      OutEdgeIt(const FullGraph& _G,const Node v) : Edge(v.n), G(&_G) {}
     172     
     173      OutEdgeIt& operator++()
     174      { n+=G->NodeNum; if(n>=G->EdgeNum) n=-1; return *this; }
     175
    173176    };
    174177   
    175178    class InEdgeIt : public Edge {
     179      const FullGraph *G;
    176180      friend class FullGraph;
    177181    public:
    178182      InEdgeIt() : Edge() { }
     183      InEdgeIt(const FullGraph& _G, Edge e) : Edge(e), G(&_G) { }
    179184      InEdgeIt (Invalid i) : Edge(i) { }
    180       InEdgeIt(const FullGraph& G,Node v) :Edge(v.n*G.NodeNum){}
     185      InEdgeIt(const FullGraph& _G,Node v) : Edge(v.n*_G.NodeNum), G(&_G) {}
     186      InEdgeIt& operator++()
     187      { if(!((++n)%G->NodeNum)) n=-1; return *this; }
    181188    };
    182189
     
    280287        return *this;
    281288      }
    282      
     289
    283290      void update() {}
    284291      void update(T a) {}
Note: See TracChangeset for help on using the changeset viewer.