Grafalgo
Library of useful data structures and algorithms
|
00001 00009 #ifndef FLOGRAPH_H 00010 #define FLOGRAPH_H 00011 00012 #include "stdinc.h" 00013 #include "Util.h" 00014 #include "Digraph.h" 00015 00016 namespace grafalgo { 00017 00018 typedef int flow; 00019 00024 class Flograph : public Digraph { 00025 public: Flograph(int=3,int=2,int=1,int=2); 00026 Flograph(const Flograph&); 00027 virtual ~Flograph(); 00028 00029 void resize(int,int); 00030 void resize(int numv) { resize(numv, numv); } 00031 void expand(int,int); 00032 void expand(int numv) { resize(numv, max(numv,m())); } 00033 void copyFrom(const Flograph&); 00034 00035 // methods for accessing, setting source and sink 00036 vertex src() const; 00037 vertex snk() const; 00038 void setSrc(vertex); 00039 void setSnk(vertex); 00040 00041 // methods for dealing with flows 00042 flow cap(vertex,edge) const; 00043 flow f(vertex,edge) const; 00044 flow res(vertex,edge) const; 00045 void addFlow(vertex,edge,flow); 00046 void setFlow(edge,flow); 00047 void clearFlow(); 00048 void setCapacity(edge,flow); 00049 00050 virtual edge join(vertex,vertex); 00051 00052 string& edge2string(edge, string&) const; 00053 string& toDotString(string&) const; 00054 00055 void randCapacity(flow, flow); 00056 void rgraph(int, int, int); 00057 protected: 00058 vertex s, t; 00059 struct FloInfo { 00060 flow cpy; 00061 flow flo; 00062 }; 00063 FloInfo *floInfo; 00064 00065 00066 // various helper methods 00067 void makeSpace(int,int); 00068 void freeSpace(); 00069 void virtual shuffle(int*, int*); 00070 string& adjList2string(edge,string&) const; 00071 bool readAdjList(istream&); 00072 00073 Flograph& operator=(const Flograph&); 00074 }; 00075 00079 inline vertex Flograph::src() const { return s; } 00080 00084 inline vertex Flograph::snk() const { return t; } 00085 00091 inline flow Flograph::cap(vertex v, edge e) const { 00092 assert(1 <= v && v <= n() && 1 <= e && e <= m()); 00093 return tail(e) == v ? floInfo[e].cpy : 0; 00094 } 00095 00101 inline flow Flograph::f(vertex v, edge e) const { 00102 assert(1 <= v && v <= n() && 1 <= e && e <= m()); 00103 return tail(e) == v ? floInfo[e].flo : -floInfo[e].flo; 00104 } 00105 00111 inline flow Flograph::res(vertex v, edge e) const { 00112 assert(1 <= v && v <= n() && 1 <= e && e <= m()); 00113 return tail(e) == v ? floInfo[e].cpy - floInfo[e].flo : floInfo[e].flo; 00114 } 00115 00120 inline void Flograph::setFlow(edge e, flow fval) { 00121 assert(1 <= e && e <= m()); 00122 floInfo[e].flo = fval; 00123 } 00124 00129 inline void Flograph::setCapacity(edge e, flow capp) { 00130 assert(1 <= e && e <= m()); 00131 floInfo[e].cpy = capp; 00132 } 00133 00137 inline void Flograph::setSrc(vertex ss) { s = ss; } 00138 00142 inline void Flograph::setSnk(vertex tt) { t = tt; } 00143 00144 } // ends namespace 00145 00146 #endif