Changeset 108:0351b00fd283 in lemon-0.x for src/work
- Timestamp:
- 02/20/04 23:01:02 (21 years ago)
- Branch:
- default
- Phase:
- public
- Convert:
- svn:c9d7d8f5-90d6-0310-b91f-818b3a526b0e/lemon/trunk@143
- Location:
- src/work/alpar
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
src/work/alpar/f_ed_ka.h
r95 r108 12 12 //#include <bfs_iterator.hh> 13 13 14 namespace marci{14 namespace hugo { 15 15 template <typename Graph, typename FlowMap, typename CapacityMap> 16 16 typename FlowMap::ValueType maxFlow(Graph &G, … … 115 115 } 116 116 117 } // namespace marci117 } // namespace hugo 118 118 119 119 #endif //EDMONDS_KARP_HH -
src/work/alpar/f_ed_ka_demo.cc
r103 r108 9 9 #include "../marci/time_measure.h" 10 10 11 using namespace marci;11 using namespace hugo; 12 12 13 13 // Use a DIMACS max flow file as stdin. … … 15 15 16 16 int main(int, char **) { 17 //typedef SmartGraph Graph;18 typedef ListGraph Graph;17 typedef SmartGraph Graph; 18 //typedef ListGraph Graph; 19 19 20 20 typedef Graph::NodeIt NodeIt; … … 24 24 Graph G; 25 25 NodeIt s, t; 26 Graph:: EdgeMap<int> cap(G);26 Graph::DynEdgeMap<int> cap(G); 27 27 readDimacsMaxFlow(std::cin, G, s, t, cap); 28 28 29 29 std::cout << "edmonds karp demo..." << std::endl; 30 Graph:: EdgeMap<int> flow(G); //0 flow30 Graph::DynEdgeMap<int> flow(G); //0 flow 31 31 32 32 int ret; -
src/work/alpar/smart_graph.h
r105 r108 28 28 std::vector<EdgeT> edges; 29 29 30 template <typename Key> class DynMapBase 31 { 32 protected: 33 SmartGraph* G; 34 public: 35 virtual void add(const Key k) = NULL; 36 virtual void erase(const Key k) = NULL; 37 DynMapBase(SmartGraph &_G) : G(&_G) {} 38 virtual ~DynMapBase() {} 39 friend class SmartGraph; 40 }; 30 41 31 42 public: 43 template <typename T> class DynEdgeMap; 44 template <typename T> class DynEdgeMap; 32 45 33 46 class NodeIt; 47 class EdgeIt; 48 49 protected: 50 std::vector<DynMapBase<NodeIt> * > dyn_node_maps; 51 std::vector<DynMapBase<EdgeIt> * > dyn_edge_maps; 52 53 public: 54 34 55 class EachNodeIt; 35 class EdgeIt;36 56 class EachEdgeIt; 37 57 class OutEdgeIt; … … 55 75 SmartGraph() : nodes(), edges() { } 56 76 57 ~SmartGraph() {} 77 ~SmartGraph() 78 { 79 for(std::vector<DynMapBase<NodeIt> * >::iterator i=dyn_node_maps.begin(); 80 i!=dyn_node_maps.end(); ++i) (**i).G=NULL; 81 for(std::vector<DynMapBase<EdgeIt> * >::iterator i=dyn_edge_maps.begin(); 82 i!=dyn_edge_maps.end(); ++i) (**i).G=NULL; 83 } 58 84 59 85 int nodeNum() const { return nodes.size(); } //FIXME: What is this? 60 86 int edgeNum() const { return edges.size(); } //FIXME: What is this? 61 87 88 int maxNodeId() const { return nodes.size(); } //FIXME: What is this? 89 int maxEdgeId() const { return edges.size(); } //FIXME: What is this? 90 91 62 92 NodeIt tail(EdgeIt e) const { return edges[e.n].tail; } 63 93 NodeIt head(EdgeIt e) const { return edges[e.n].head; } … … 115 145 NodeIt n; n.n=nodes.size(); 116 146 nodes.push_back(NodeT()); //FIXME: Hmmm... 147 148 for(std::vector<DynMapBase<NodeIt> * >::iterator i=dyn_node_maps.begin(); 149 i!=dyn_node_maps.end(); ++i) (**i).add(n.n); 150 117 151 return n; 118 152 } 153 119 154 EdgeIt addEdge(NodeIt u, NodeIt v) { 120 155 EdgeIt e; e.n=edges.size(); edges.push_back(EdgeT()); //FIXME: Hmmm... … … 123 158 edges[e.n].next_in=nodes[v.n].first_in; 124 159 nodes[u.n].first_out=nodes[v.n].first_in=e.n; 160 161 for(std::vector<DynMapBase<EdgeIt> * >::iterator i=dyn_edge_maps.begin(); 162 i!=dyn_edge_maps.end(); ++i) (**i).add(e.n); 163 125 164 return e; 126 165 } … … 131 170 friend class SmartGraph; 132 171 template <typename T> friend class NodeMap; 172 template <typename T> friend class DynNodeMap; 133 173 134 174 friend class EdgeIt; … … 157 197 friend class SmartGraph; 158 198 template <typename T> friend class EdgeMap; 199 template <typename T> friend class DynEdgeMap; 159 200 160 201 friend class NodeIt; … … 201 242 typedef T ValueType; 202 243 typedef NodeIt KeyType; 203 NodeMap(const SmartGraph& _G) : G(_G), container(G. nodeNum()) { }244 NodeMap(const SmartGraph& _G) : G(_G), container(G.maxNodeId()) { } 204 245 NodeMap(const SmartGraph& _G, T a) : 205 G(_G), container(G. nodeNum(), a) { }246 G(_G), container(G.maxNodeId(), a) { } 206 247 void set(NodeIt n, T a) { container[n.n]=a; } 207 248 T get(NodeIt n) const { return container[n.n]; } 208 249 T& operator[](NodeIt n) { return container[n.n]; } 209 250 const T& operator[](NodeIt n) const { return container[n.n]; } 210 void update() { container.resize(G. nodeNum()); }211 void update(T a) { container.resize(G. nodeNum(), a); }251 void update() { container.resize(G.maxNodeId()); } 252 void update(T a) { container.resize(G.maxNodeId(), a); } 212 253 }; 213 254 … … 219 260 typedef T ValueType; 220 261 typedef EdgeIt KeyType; 221 EdgeMap(const SmartGraph& _G) : G(_G), container(G. edgeNum()) { }262 EdgeMap(const SmartGraph& _G) : G(_G), container(G.maxEdgeId()) { } 222 263 EdgeMap(const SmartGraph& _G, T a) : 223 G(_G), container(G. edgeNum(), a) { }264 G(_G), container(G.maxEdgeId(), a) { } 224 265 void set(EdgeIt e, T a) { container[e.n]=a; } 225 266 T get(EdgeIt e) const { return container[e.n]; } 226 267 T& operator[](EdgeIt e) { return container[e.n]; } 227 268 const T& operator[](EdgeIt e) const { return container[e.n]; } 228 void update() { container.resize(G.edgeNum()); } 229 void update(T a) { container.resize(G.edgeNum(), a); } 230 }; 231 232 233 234 269 void update() { container.resize(G.maxEdgeId()); } 270 void update(T a) { container.resize(G.maxEdgeId(), a); } 271 }; 272 273 template <typename T> class DynNodeMap : public DynMapBase<NodeIt> 274 { 275 std::vector<T> container; 276 277 public: 278 typedef T ValueType; 279 typedef NodeIt KeyType; 280 281 DynNodeMap(SmartGraph &_G) : 282 DynMapBase<NodeIt>(_G), container(_G.maxNodeId()) 283 { 284 //FIXME: What if there are empty Id's? 285 G->dyn_node_maps.push_back(this); 286 } 287 ~DynNodeMap() 288 { 289 if(G) { 290 std::vector<DynMapBase<NodeIt>* >::iterator i; 291 for(i=G->dyn_node_maps.begin(); 292 i!=G->dyn_node_maps.end() && *i!=this; ++i) ; 293 if(*i==this) G->dyn_node_maps.erase(i); //FIXME: Way too slow... 294 } 295 } 296 297 void add(const NodeIt k) 298 { 299 if(k.n>=container.size()) container.resize(k.n+1); 300 } 301 void erase(const NodeIt k) 302 { 303 //FIXME: Please implement me. 304 } 305 306 void set(NodeIt n, T a) { container[n.n]=a; } 307 T get(NodeIt n) const { return container[n.n]; } 308 T& operator[](NodeIt n) { return container[n.n]; } 309 const T& operator[](NodeIt n) const { return container[n.n]; } 310 311 void update() {} //Useless for DynMaps 312 void update(T a) {} //Useless for DynMaps 313 }; 314 315 template <typename T> class DynEdgeMap : public DynMapBase<EdgeIt> 316 { 317 std::vector<T> container; 318 319 public: 320 typedef T ValueType; 321 typedef EdgeIt KeyType; 322 323 DynEdgeMap(SmartGraph &_G) : 324 DynMapBase<EdgeIt>(_G), container(_G.maxEdgeId()) 325 { 326 //FIXME: What if there are empty Id's? 327 //FIXME: Can I do that? : 328 G->dyn_edge_maps.push_back(this); 329 } 330 ~DynEdgeMap() 331 { 332 if(G) { 333 std::vector<DynMapBase<EdgeIt>* >::iterator i; 334 for(i=G->dyn_edge_maps.begin(); 335 i!=G->dyn_edge_maps.end() && *i!=this; ++i) ; 336 if(*i==this) G->dyn_edge_maps.erase(i); //FIXME: Way too slow... 337 } 338 } 339 340 void add(const EdgeIt k) 341 { 342 if(k.n>=int(container.size())) container.resize(k.n+1); 343 } 344 void erase(const EdgeIt k) 345 { 346 //FIXME: Please implement me. 347 } 348 349 void set(EdgeIt n, T a) { container[n.n]=a; } 350 T get(EdgeIt n) const { return container[n.n]; } 351 T& operator[](EdgeIt n) { return container[n.n]; } 352 const T& operator[](EdgeIt n) const { return container[n.n]; } 353 354 void update() {} //Useless for DynMaps 355 void update(T a) {} //Useless for DynMaps 356 }; 357 235 358 }; 236 359 } //namespace hugo
Note: See TracChangeset
for help on using the changeset viewer.