Grafalgo
Library of useful data structures and algorithms
|
00001 00009 #ifndef WGRAPH_H 00010 #define WGRAPH_H 00011 00012 #include "stdinc.h" 00013 #include "Graph.h" 00014 00015 typedef int weight; 00016 00017 namespace grafalgo { 00018 00028 class Wgraph : public Graph { 00029 public: Wgraph(int=1,int=1); 00030 ~Wgraph(); 00031 00032 void resize(int, int); 00033 void resize(int numv) { resize(numv,numv); } 00034 void expand(int, int); 00035 void expand(int numv) { resize(numv,max(numv,m())); } 00036 void copyFrom(const Wgraph&); 00037 00038 // methods for accessing/changing weight 00039 int weight(edge) const; 00040 void setWeight(edge,int); 00041 00042 // create a string representation 00043 using Graph::edge2string; 00044 string& edge2string(edge, vertex, string&) const; 00045 string& toDotString(string&) const; 00046 00047 void randWeight(int, int); 00048 private: 00049 int *wt; 00050 void makeSpace(int,int); 00051 void freeSpace(); 00052 bool readAdjList(istream&); 00053 string& adjList2string(vertex,string&) const; 00054 }; 00055 00060 inline int Wgraph::weight(edge e) const { 00061 assert(0 <= e && e <= maxEdge); 00062 return (evec[e].l == 0 ? 0 : wt[e]); 00063 } 00064 00069 inline void Wgraph::setWeight(edge e, int w) { 00070 assert(0 <= e && e <= maxEdge); wt[e] = w; 00071 } 00072 00073 } // ends namespace 00074 00075 #endif