COIN-OR::LEMON - Graph Library

Changeset 579:859f8c7e2a40 in lemon-0.x for src/hugo


Ignore:
Timestamp:
05/07/04 17:58:45 (20 years ago)
Author:
Alpar Juttner
Branch:
default
Phase:
public
Convert:
svn:c9d7d8f5-90d6-0310-b91f-818b3a526b0e/lemon/trunk@755
Message:

EdgeSet? is more or less working.

Location:
src/hugo
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • src/hugo/list_graph.h

    r578 r579  
    9595    class InEdgeIt;
    9696   
    97     template <typename T> class NodeMap;
    98     template <typename T> class EdgeMap;
    99    
    10097  public:
    10198
     
    329326      NodeIt(Invalid i) : Node(i) { }
    330327      NodeIt(const ListGraph& G) : Node(G.first_node) { }
     328      ///\todo Undocumented conversion Node -\> NodeIt.
     329      NodeIt(const ListGraph& G, const Node &n) : Node(n) { }
    331330    };
    332331
     
    483482    template <typename T> class EdgeMap : public DynMapBase<Edge>
    484483    {
     484    protected:
    485485      std::vector<T> container;
    486486
     
    945945      friend class NodeSet;
    946946    public:
     947      NodeIt() : Node() { }
     948      NodeIt(Invalid i) : Node(i) { }
    947949      NodeIt(const NodeSet& G) : Node(G.first_node) { }
    948       NodeIt() : Node() { }
     950      ///\todo Undocumented conversion Node -\> NodeIt.
     951      NodeIt(const NodeSet& G, const Node &n) : Node(n) { }
     952
    949953    };
    950954
     
    11831187      NodeIt(const typename NodeGraphType::NodeIt &n)
    11841188        : NodeGraphType::NodeIt(n) {}
     1189      ///\todo Undocumented conversion Node -\> NodeIt.
     1190      NodeIt(const EdgeSet& _G, const Node &n)
     1191        : NodeGraphType::NodeIt(_G.G,n) { }
     1192
    11851193      operator Node() { return Node(*this);}
    11861194    };
     
    13271335      }
    13281336      else {
    1329         NodeIt n;
    1330         for(n=next(edges[it.n].head);
     1337        NodeIt n(*this,edges[it.n].head);
     1338        for(n=next(n);
    13311339            valid(n) && nodes[n].first_in == -1;
    13321340            next(n)) ;
     
    13391347
    13401348    /// Adds a new node to the graph.
    1341     Node addNode() { return G.AddNode(); }
     1349    Node addNode() { return G.addNode(); }
    13421350   
    13431351    Edge addEdge(Node u, Node v) {
     
    14101418    void erase(Edge e) { eraseEdge(e.n); }
    14111419
     1420    ///Clear all edges. (Doesn't clear the nodes!)
     1421    void clear() {
     1422      edges.clear();
     1423      first_free_edge=-1;
     1424    }
     1425
     1426
    14121427//     //\bug Dynamic maps must be updated!
    14131428//     //
     
    14171432//     }
    14181433
     1434  public:
     1435    template <typename T> class EdgeMap;
     1436   
     1437    ///
    14191438    class Edge {
     1439    public:
    14201440      friend class EdgeSet;
    14211441      template <typename T> friend class EdgeMap;
    14221442
    1423       //template <typename T> friend class SymEdgeSet::SymEdgeMap;     
    1424       //friend Edge SymEdgeSet::opposite(Edge) const;
    1425      
    14261443      friend class Node;
    14271444      friend class NodeIt;
     1445    public:
     1446      ///\bug It shoud be at least protected
     1447      ///
     1448      int n;
    14281449    protected:
    1429       int n;
    14301450      friend int EdgeSet::id(Edge e) const;
    14311451
     
    14451465    class EdgeIt : public Edge {
    14461466      friend class EdgeSet;
     1467      template <typename T> friend class EdgeMap;
     1468   
     1469     
    14471470    public:
    14481471      EdgeIt(const EdgeSet& G) : Edge() {
     
    14671490      OutEdgeIt (Invalid i) : Edge(i) { }
    14681491
    1469       OutEdgeIt(const EdgeSet& G,const Node v) : Edge(nodes[v].first_out) { }
     1492      OutEdgeIt(const EdgeSet& G,const Node v) : Edge(G.nodes[v].first_out) { }
    14701493    };
    14711494   
     
    14751498      InEdgeIt() : Edge() { }
    14761499      InEdgeIt (Invalid i) : Edge(i) { }
    1477       InEdgeIt(const EdgeSet& G,Node v) :Edge(nodes[v].first_in) { }
     1500      InEdgeIt(const EdgeSet& G,Node v) :Edge(G.nodes[v].first_in) { }
    14781501    };
    14791502
     
    14811504      public NodeGraphType::template NodeMap<T>
    14821505    {
    1483     public:
    1484       NodeMap(const EdgeSet &_G) :
    1485         NodeGraphType::NodeMap(_G.G) { } //AJAJJ <T> would be wrong!!!
    1486       NodeMap(const EdgeSet &_G,const T &t) :
    1487         NodeGraphType::NodeMap(_G.G,t) { }
     1506      //This is a must, the constructors need it.
     1507      typedef typename NodeGraphType::template NodeMap<T> ParentNodeMap;
     1508    public:
     1509      NodeMap(const EdgeSet &_G) : ParentNodeMap(_G.G) { }
     1510      NodeMap(const EdgeSet &_G,const T &t) : ParentNodeMap(_G.G,t) { }
    14881511      //It is unnecessary
    14891512      NodeMap(const typename NodeGraphType::template NodeMap<T> &m) :
    1490         NodeGraphType::NodeMap(m) { }
     1513        ParentNodeMap(m) { }
    14911514
    14921515      ///\todo It can copy between different types.
     
    14941517      template<typename TT>
    14951518      NodeMap(const typename NodeGraphType::template NodeMap<TT> &m)
    1496         : NodeGraphType::NodeMap(m) { }
    1497     };
    1498    
     1519        : ParentNodeMap(m) { }
     1520    };
     1521   
     1522    ///
    14991523    template <typename T> class EdgeMap : public DynMapBase<Edge>
    15001524    {
     1525    protected:
     1526    public:
     1527      ///\bug It should be at least protected
     1528      ///
    15011529      std::vector<T> container;
    15021530
     
    15581586      void erase(const Edge) { }
    15591587     
    1560       void set(Edge n, T a) { container[n.n]=a; }
     1588      ///\bug This doesn't work. Why?
     1589      ///      void set(Edge n, T a) { container[n.n]=a; }
     1590      void set(Edge n, T a) { container[G->id(n)]=a; }
    15611591      //T get(Edge n) const { return container[n.n]; }
    15621592      typename std::vector<T>::reference
    1563       operator[](Edge n) { return container[n.n]; }
     1593      ///\bug This doesn't work. Why?
     1594      ///      operator[](Edge n) { return container[n.n]; }
     1595      operator[](Edge n) { return container[G->id(n)]; }
    15641596      typename std::vector<T>::const_reference
    1565       operator[](Edge n) const { return container[n.n]; }
     1597      ///\bug This doesn't work. Why?
     1598      ///      operator[](Edge n) const { return container[n.n]; }
     1599      operator[](Edge n) const { return container[G->id(n)]; }
    15661600
    15671601      ///\warning There is no safety check at all!
     
    15751609        return *this;
    15761610      }
     1611     
     1612      template<typename TT> friend class EdgeMap;
     1613
    15771614      template<typename TT>
    15781615      const EdgeMap<T>& operator=(const EdgeMap<TT> &m)
     
    15881625  };
    15891626
    1590   template< typename GG>
    1591   int EdgeSet<GG>::id(Node v) const { return G.id(v); }
     1627  template<typename GG>
     1628  inline int EdgeSet<GG>::id(Node v) const { return G.id(v); }
    15921629
    15931630/// @} 
  • src/hugo/smart_graph.h

    r542 r579  
    221221      NodeIt(Invalid i) : Node(i) { }
    222222      NodeIt(const SmartGraph& G) : Node(G.nodes.size()?0:-1) { }
     223      ///\todo Undocumented conversion Node -\> NodeIt.
     224      NodeIt(const SmartGraph& G, const Node &n) : Node(n) { }
    223225    };
    224226
Note: See TracChangeset for help on using the changeset viewer.