Changeset 105:a3c73e9b9b2e in lemon-0.x
- Timestamp:
- 02/20/04 22:45:07 (21 years ago)
- Branch:
- default
- Phase:
- public
- Convert:
- svn:c9d7d8f5-90d6-0310-b91f-818b3a526b0e/lemon/trunk@140
- Location:
- src/work
- Files:
-
- 23 edited
Legend:
- Unmodified
- Added
- Removed
-
src/work/alpar/gwrapper.h
r103 r105 3 3 #define GRAPH_WRAPPER_H 4 4 5 namespace marci{5 namespace hugo { 6 6 7 7 template<typename G> -
src/work/alpar/smart_graph.h
r104 r105 1 // -*- mode:C++ -*- 2 1 3 #ifndef SMART_GRAPH_H 2 4 #define SMART_GRAPH_H … … 5 7 #include <vector> 6 8 7 namespace marci{9 namespace hugo { 8 10 9 11 class SmartGraph { … … 36 38 class InEdgeIt; 37 39 38 // class NodeIt { int n; };39 // class EachNodeIt : public NodeIt { };40 // class EdgeIt { int n; };41 // class EachEdgeIt : public EdgeIt {};42 // class OutEdgeIt : public EdgeIt {};43 // class InEdgeIt : public EdgeIt {};40 // class NodeIt { int n; }; 41 // class EachNodeIt : public NodeIt { }; 42 // class EdgeIt { int n; }; 43 // class EachEdgeIt : public EdgeIt {}; 44 // class OutEdgeIt : public EdgeIt {}; 45 // class InEdgeIt : public EdgeIt {}; 44 46 // class SymEdgeIt; 45 46 template <typename T> class NodeMap;47 48 template <typename T> class NodeMap; 47 49 template <typename T> class EdgeMap; 48 50 49 private: 50 51 template <typename T> friend class NodeMap; 52 template <typename T> friend class EdgeMap; 51 public: 52 53 /* default constructor */ 54 55 SmartGraph() : nodes(), edges() { } 56 57 ~SmartGraph() {} 58 59 int nodeNum() const { return nodes.size(); } //FIXME: What is this? 60 int edgeNum() const { return edges.size(); } //FIXME: What is this? 61 62 NodeIt tail(EdgeIt e) const { return edges[e.n].tail; } 63 NodeIt head(EdgeIt e) const { return edges[e.n].head; } 64 65 NodeIt aNode(const OutEdgeIt& e) const { return tail(e); } 66 NodeIt aNode(const InEdgeIt& e) const { return head(e); } 67 //NodeIt aNode(const SymEdgeIt& e) const { return e.aNode(); } 68 69 NodeIt bNode(const OutEdgeIt& e) const { return head(e); } 70 NodeIt bNode(const InEdgeIt& e) const { return tail(e); } 71 //NodeIt bNode(const SymEdgeIt& e) const { return e.bNode(); } 72 73 EachNodeIt& getFirst(EachNodeIt& v) const { 74 v=EachNodeIt(*this); return v; } 75 EachEdgeIt& getFirst(EachEdgeIt& e) const { 76 e=EachEdgeIt(*this); return e; } 77 OutEdgeIt& getFirst(OutEdgeIt& e, const NodeIt v) const { 78 e=OutEdgeIt(*this,v); return e; } 79 InEdgeIt& getFirst(InEdgeIt& e, const NodeIt v) const { 80 e=InEdgeIt(*this,v); return e; } 81 82 template< typename It > 83 It first() const { 84 It e; 85 getFirst(e); 86 return e; 87 } 88 89 template< typename It > 90 It first(NodeIt v) const { 91 It e; 92 getFirst(e, v); 93 return e; 94 } 95 96 bool valid(EdgeIt e) const { return e.n!=INVALID; } 97 bool valid(EachEdgeIt e) const { return e.n<int(edges.size()); } 98 bool valid(NodeIt n) const { return n.n<int(nodes.size()); } 99 100 template <typename It> It next(It it) const 101 // { It tmp(it); return goNext(tmp); } 102 { It tmp; tmp.n=it.n+1; return tmp; } 103 104 NodeIt& goNext(NodeIt& it) const { ++it.n; return it; } 105 OutEdgeIt& goNext(OutEdgeIt& it) const 106 { it.n=edges[it.n].next_out; return it; } 107 InEdgeIt& goNext(InEdgeIt& it) const 108 { it.n=edges[it.n].next_in; return it; } 109 EachEdgeIt& goNext(EachEdgeIt& it) const { ++it.n; return it; } 110 111 int id(NodeIt v) const { return v.n; } 112 int id(EdgeIt e) const { return e.n; } 113 114 NodeIt addNode() { 115 NodeIt n; n.n=nodes.size(); 116 nodes.push_back(NodeT()); //FIXME: Hmmm... 117 return n; 118 } 119 EdgeIt addEdge(NodeIt u, NodeIt v) { 120 EdgeIt e; e.n=edges.size(); edges.push_back(EdgeT()); //FIXME: Hmmm... 121 edges[e.n].tail=u.n; edges[e.n].head=v.n; 122 edges[e.n].next_out=nodes[u.n].first_out; 123 edges[e.n].next_in=nodes[v.n].first_in; 124 nodes[u.n].first_out=nodes[v.n].first_in=e.n; 125 return e; 126 } 127 128 void clear() {nodes.clear();edges.clear();} 129 130 class NodeIt { 131 friend class SmartGraph; 132 template <typename T> friend class NodeMap; 133 134 friend class EdgeIt; 135 friend class OutEdgeIt; 136 friend class InEdgeIt; 137 friend class SymEdgeIt; 138 139 protected: 140 int n; 141 friend int SmartGraph::id(NodeIt v) const; 142 public: 143 NodeIt() {} 144 NodeIt(int nn) {n=nn;} 145 bool operator==(const NodeIt i) const {return n==i.n;} 146 bool operator!=(const NodeIt i) const {return n!=i.n;} 147 }; 148 149 class EachNodeIt : public NodeIt { 150 friend class SmartGraph; 151 public: 152 EachNodeIt(const SmartGraph& G) : NodeIt(0) { } 153 EachNodeIt() : NodeIt() { } 154 }; 155 156 class EdgeIt { 157 friend class SmartGraph; 158 template <typename T> friend class EdgeMap; 159 160 friend class NodeIt; 161 friend class EachNodeIt; 162 protected: 163 int n; 164 friend int SmartGraph::id(EdgeIt e) const; 165 public: 166 EdgeIt() { } 167 EdgeIt(int nn) {n=nn;} 168 bool operator==(const EdgeIt i) const {return n==i.n;} 169 bool operator!=(const EdgeIt i) const {return n!=i.n;} 170 }; 171 172 class EachEdgeIt : public EdgeIt { 173 friend class SmartGraph; 174 public: 175 EachEdgeIt(const SmartGraph& G) : EdgeIt(0) { } 176 EachEdgeIt() : EdgeIt() { } 177 }; 178 179 class OutEdgeIt : public EdgeIt { 180 friend class SmartGraph; 181 public: 182 OutEdgeIt() : EdgeIt() { } 183 OutEdgeIt(const SmartGraph& G,const NodeIt v) 184 : EdgeIt(G.nodes[v.n].first_out) {} 185 }; 186 187 class InEdgeIt : public EdgeIt { 188 friend class SmartGraph; 189 public: 190 InEdgeIt() : EdgeIt() { } 191 InEdgeIt(const SmartGraph& G,NodeIt v) :EdgeIt(G.nodes[v.n].first_in){} 192 }; 193 194 // Map types 53 195 54 196 template <typename T> … … 66 208 T& operator[](NodeIt n) { return container[n.n]; } 67 209 const T& operator[](NodeIt n) const { return container[n.n]; } 68 void resize() { container.resize(G.nodeNum()); }69 void resize(T a) { container.resize(G.nodeNum(), a); }210 void update() { container.resize(G.nodeNum()); } 211 void update(T a) { container.resize(G.nodeNum(), a); } 70 212 }; 71 213 … … 84 226 T& operator[](EdgeIt e) { return container[e.n]; } 85 227 const T& operator[](EdgeIt e) const { return container[e.n]; } 86 void resize() { container.resize(G.edgeNum()); } 87 void resize(T a) { container.resize(G.edgeNum(), a); } 88 }; 89 90 public: 91 92 /* default constructor */ 93 94 SmartGraph() : nodes(), edges() { } 95 96 ~SmartGraph() {} 97 98 int nodeNum() const { return nodes.size(); } //FIXME: What is this? 99 int edgeNum() const { return edges.size(); } //FIXME: What is this? 100 101 NodeIt tail(EdgeIt e) const { return edges[e.n].tail; } 102 NodeIt head(EdgeIt e) const { return edges[e.n].head; } 103 104 NodeIt aNode(const OutEdgeIt& e) const { return tail(e); } 105 NodeIt aNode(const InEdgeIt& e) const { return head(e); } 106 //NodeIt aNode(const SymEdgeIt& e) const { return e.aNode(); } 107 108 NodeIt bNode(const OutEdgeIt& e) const { return head(e); } 109 NodeIt bNode(const InEdgeIt& e) const { return tail(e); } 110 //NodeIt bNode(const SymEdgeIt& e) const { return e.bNode(); } 111 112 EachNodeIt& getFirst(EachNodeIt& v) const { 113 v=EachNodeIt(*this); return v; } 114 EachEdgeIt& getFirst(EachEdgeIt& e) const { 115 e=EachEdgeIt(*this); return e; } 116 OutEdgeIt& getFirst(OutEdgeIt& e, const NodeIt v) const { 117 e=OutEdgeIt(*this,v); return e; } 118 InEdgeIt& getFirst(InEdgeIt& e, const NodeIt v) const { 119 e=InEdgeIt(*this,v); return e; } 120 121 template< typename It > 122 It first() const { 123 It e; 124 getFirst(e); 125 return e; 126 } 127 128 template< typename It > 129 It first(NodeIt v) const { 130 It e; 131 getFirst(e, v); 132 return e; 133 } 134 135 bool valid(EdgeIt e) const { return e.n!=INVALID; } 136 bool valid(EachEdgeIt e) const { return e.n<int(edges.size()); } 137 bool valid(NodeIt n) const { return n.n<int(nodes.size()); } 138 139 template <typename It> It next(It it) const { 140 It tmp(it); return goNext(it); } 141 142 NodeIt& goNext(NodeIt& it) const { ++it.n; return it; } 143 OutEdgeIt& goNext(OutEdgeIt& it) const 144 { it.n=edges[it.n].next_out; return it; } 145 InEdgeIt& goNext(InEdgeIt& it) const 146 { it.n=edges[it.n].next_in; return it; } 147 EachEdgeIt& goNext(EachEdgeIt& it) const { ++it.n; return it; } 148 149 int id(NodeIt v) const { return v.n; } 150 int id(EdgeIt e) const { return e.n; } 151 152 NodeIt addNode() { 153 NodeIt n; n.n=nodes.size(); 154 nodes.push_back(NodeT()); //FIXME: Hmmm... 155 return n; 156 } 157 EdgeIt addEdge(NodeIt u, NodeIt v) { 158 EdgeIt e; e.n=edges.size(); edges.push_back(EdgeT()); //FIXME: Hmmm... 159 edges[e.n].tail=u.n; edges[e.n].head=v.n; 160 edges[e.n].next_out=nodes[u.n].first_out; 161 edges[e.n].next_in=nodes[v.n].first_in; 162 nodes[u.n].first_out=nodes[v.n].first_in=e.n; 163 return e; 164 } 165 166 void clear() {nodes.clear();edges.clear();} 167 168 class NodeIt { 169 friend class SmartGraph; 170 template <typename T> friend class NodeMap; 171 172 friend class EdgeIt; 173 friend class OutEdgeIt; 174 friend class InEdgeIt; 175 friend class SymEdgeIt; 176 177 protected: 178 int n; 179 friend int SmartGraph::id(NodeIt v) const; 180 public: 181 NodeIt() {} 182 NodeIt(int nn) {n=nn;} 183 bool operator==(const NodeIt i) const {return n==i.n;} 184 bool operator!=(const NodeIt i) const {return n!=i.n;} 185 }; 186 187 class EachNodeIt : public NodeIt { 188 friend class SmartGraph; 189 public: 190 EachNodeIt(const SmartGraph& G) : NodeIt(0) { } 191 EachNodeIt() : NodeIt() { } 192 }; 193 194 class EdgeIt { 195 friend class SmartGraph; 196 template <typename T> friend class EdgeMap; 197 198 friend class NodeIt; 199 friend class EachNodeIt; 200 protected: 201 int n; 202 friend int SmartGraph::id(EdgeIt e) const; 203 public: 204 EdgeIt() { } 205 EdgeIt(int nn) {n=nn;} 206 bool operator==(const EdgeIt i) const {return n==i.n;} 207 bool operator!=(const EdgeIt i) const {return n!=i.n;} 208 }; 209 210 class EachEdgeIt : public EdgeIt { 211 friend class SmartGraph; 212 public: 213 EachEdgeIt(const SmartGraph& G) : EdgeIt(0) { } 214 EachEdgeIt() : EdgeIt() { } 215 }; 216 217 class OutEdgeIt : public EdgeIt { 218 friend class SmartGraph; 219 public: 220 OutEdgeIt() : EdgeIt() { } 221 OutEdgeIt(const SmartGraph& G,const NodeIt v) 222 : EdgeIt(G.nodes[v.n].first_out) {} 223 }; 224 225 class InEdgeIt : public EdgeIt { 226 friend class SmartGraph; 227 public: 228 InEdgeIt() : EdgeIt() { } 229 InEdgeIt(const SmartGraph& G,NodeIt v) :EdgeIt(G.nodes[v.n].first_in){} 230 }; 228 void update() { container.resize(G.edgeNum()); } 229 void update(T a) { container.resize(G.edgeNum(), a); } 230 }; 231 232 233 234 231 235 }; 232 } //namespace marci236 } //namespace hugo 233 237 234 238 #endif //SMART_GRAPH_H -
src/work/athos/pf_demo.cc
r77 r105 8 8 #include "preflow_push.hh" 9 9 10 using namespace marci;10 using namespace hugo; 11 11 12 12 -
src/work/athos/preflow_push.hh
r77 r105 13 13 using namespace std; 14 14 15 namespace marci{15 namespace hugo { 16 16 17 17 template <typename graph_type, typename T> … … 435 435 436 436 437 }//namespace marci437 }//namespace hugo 438 438 439 439 #endif //PREFLOW_PUSH_HH -
src/work/athos/reverse_bfs.hh
r77 r105 97 97 }; 98 98 99 } // namespace marci99 } // namespace hugo 100 100 101 101 #endif //REVERSE_BFS_HH -
src/work/bfs_iterator.hh
r99 r105 7 7 #include <graph_wrapper.h> 8 8 9 namespace marci{9 namespace hugo { 10 10 11 11 template <typename Graph> … … 756 756 757 757 758 } // namespace marci758 } // namespace hugo 759 759 760 760 #endif //BFS_ITERATOR_HH -
src/work/bin_heap_demo.cc
r39 r105 4 4 #include <map> 5 5 6 using namespace marci;6 using namespace hugo; 7 7 using namespace std; 8 8 -
src/work/jacint/dijkstra.hh
r78 r105 53 53 54 54 namespace std { 55 namespace marci{55 namespace hugo { 56 56 57 57 … … 186 186 187 187 188 } // namespace marci188 } // namespace hugo 189 189 } 190 190 #endif //DIJKSTRA_HH -
src/work/jacint/flow_test.cc
r78 r105 9 9 //#include <dijkstra.h> 10 10 11 using namespace marci;11 using namespace hugo; 12 12 13 13 -
src/work/jacint/preflow_hl2.h
r101 r105 42 42 #include <queue> 43 43 44 namespace marci{44 namespace hugo { 45 45 46 46 template <typename Graph, typename T, … … 397 397 398 398 }; 399 }//namespace marci399 }//namespace hugo 400 400 #endif 401 401 -
src/work/jacint/preflow_hl3.h
r101 r105 45 45 #include <queue> 46 46 47 namespace marci{47 namespace hugo { 48 48 49 49 template <typename Graph, typename T, … … 465 465 466 466 }; 467 }//namespace marci467 }//namespace hugo 468 468 #endif 469 469 -
src/work/jacint/preflow_hl4.h
r102 r105 45 45 #include <queue> 46 46 47 namespace marci{47 namespace hugo { 48 48 49 49 template <typename Graph, typename T, … … 479 479 480 480 }; 481 }//namespace marci481 }//namespace hugo 482 482 #endif 483 483 -
src/work/jacint/preflow_push_hl.h
r101 r105 44 44 #include <queue> 45 45 46 namespace marci{46 namespace hugo { 47 47 48 48 template <typename Graph, typename T, … … 391 391 392 392 }; 393 }//namespace marci393 }//namespace hugo 394 394 #endif 395 395 -
src/work/jacint/preflow_push_hl.hh
r47 r105 33 33 #include <reverse_bfs.hh> 34 34 35 namespace marci{35 namespace hugo { 36 36 37 37 template <typename graph_type, typename T> … … 313 313 314 314 }; 315 }//namespace marci315 }//namespace hugo 316 316 #endif 317 317 -
src/work/jacint/preflow_push_max_flow.h
r97 r105 34 34 35 35 36 namespace marci{36 namespace hugo { 37 37 38 38 template <typename Graph, typename T, … … 288 288 289 289 }; 290 }//namespace marci290 }//namespace hugo 291 291 #endif 292 292 -
src/work/jacint/preflow_push_max_flow.hh
r47 r105 33 33 34 34 35 namespace marci{35 namespace hugo { 36 36 37 37 template <typename graph_type, typename T> … … 307 307 308 308 }; 309 }//namespace marci309 }//namespace hugo 310 310 #endif 311 311 -
src/work/jacint/reverse_bfs.h
r78 r105 83 83 }; 84 84 85 } // namespace marci85 } // namespace hugo 86 86 87 87 #endif //REVERSE_BFS_HH -
src/work/jacint/reverse_bfs.hh
r78 r105 88 88 }; 89 89 90 } // namespace marci90 } // namespace hugo 91 91 92 92 #endif //REVERSE_BFS_HH -
src/work/marci/dimacs.hh
r69 r105 6 6 #include <vector> 7 7 8 namespace marci{8 namespace hugo { 9 9 10 10 template<typename Graph, typename CapacityMap> … … 50 50 getline(is, str); 51 51 typename Graph::EdgeIt e=G.addEdge(nodes[i], nodes[j]); 52 capacity. resize();52 capacity.update(); 53 53 capacity.set(e, cap); 54 54 break; … … 57 57 } 58 58 59 } //namespace marci59 } //namespace hugo 60 60 61 61 #endif //DIMACS_HH -
src/work/marci/edmonds_karp_demo.cc
r100 r105 7 7 #include <time_measure.h> 8 8 9 using namespace marci;9 using namespace hugo; 10 10 11 11 // Use a DIMACS max flow file as stdin. -
src/work/marci/graph_wrapper.h
r76 r105 3 3 #define GRAPH_WRAPPER_H 4 4 5 namespace marci{5 namespace hugo { 6 6 7 7 template<typename Graph> … … 574 574 575 575 576 } //namespace marci576 } //namespace hugo 577 577 578 578 #endif //GRAPH_WRAPPER_H -
src/work/marci/preflow_demo_athos.cc
r82 r105 7 7 #include <time_measure.h> 8 8 9 using namespace marci;9 using namespace hugo; 10 10 11 11 // Use a DIMACS max flow file as stdin. -
src/work/marci/preflow_demo_jacint.cc
r100 r105 8 8 #include <time_measure.h> 9 9 10 using namespace marci;10 using namespace hugo; 11 11 12 12 // Use a DIMACS max flow file as stdin.
Note: See TracChangeset
for help on using the changeset viewer.