Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include "ColPackHeaders.h"
00023
00024 using namespace std;
00025
00026 namespace ColPack
00027 {
00028
00029 void GraphCore::Clear()
00030 {
00031 m_i_MaximumVertexDegree = _UNKNOWN;
00032 m_i_MinimumVertexDegree = _UNKNOWN;
00033
00034 m_d_AverageVertexDegree = _UNKNOWN;
00035
00036 m_s_InputFile.clear();
00037
00038 m_vi_Vertices.clear();
00039 m_vi_Edges.clear();
00040
00041 m_vd_Values.clear();
00042
00043 return;
00044 }
00045
00046
00047 int GraphCore::GetVertexCount()
00048 {
00049 return(STEP_DOWN(m_vi_Vertices.size()));
00050 }
00051
00052
00053
00054 int GraphCore::GetEdgeCount()
00055 {
00056 return(m_vi_Edges.size()/2);
00057 }
00058
00059
00060
00061 int GraphCore::GetMaximumVertexDegree()
00062 {
00063 return(m_i_MaximumVertexDegree);
00064 }
00065
00066
00067
00068 int GraphCore::GetMinimumVertexDegree()
00069 {
00070 return(m_i_MinimumVertexDegree);
00071 }
00072
00073
00074
00075 double GraphCore::GetAverageVertexDegree()
00076 {
00077 return(m_d_AverageVertexDegree);
00078 }
00079
00080
00081
00082 string GraphCore::GetInputFile()
00083 {
00084 return(m_s_InputFile);
00085 }
00086
00087
00088 void GraphCore::GetVertices(vector<int> &output) const
00089 {
00090 output = (m_vi_Vertices);
00091 }
00092
00093
00094
00095 void GraphCore::GetEdges(vector<int> &output) const
00096 {
00097 output = (m_vi_Edges);
00098 }
00099
00100
00101
00102 void GraphCore::GetValues(vector<double> &output) const
00103 {
00104 output = (m_vd_Values);
00105 }
00106
00107 void GraphCore::GetVertexEdgeMap(map< int, map< int, int> > &output)
00108 {
00109
00110
00111
00112 output = (m_mimi2_VertexEdgeMap);
00113 }
00114
00115 void GraphCore::GetDisjointSets(DisjointSets &output)
00116 {
00117
00118
00119
00120
00121 output = (m_ds_DisjointSets);
00122 }
00123
00124 void GraphCore::GetD1Neighbor(int VertexIndex, vector<int> &D1Neighbor, int excludedVertex) {
00125 if(VertexIndex > (int)m_vi_Vertices.size() - 2) {
00126 cout<<"Illegal request. VertexIndex is too large. VertexIndex > m_vi_Vertices.size() - 2"<<endl;
00127 return;
00128 }
00129 if(VertexIndex < 0) {
00130 cout<<"Illegal request. VertexIndex is too small. VertexIndex < 0"<<endl;
00131 return;
00132 }
00133 D1Neighbor.clear();
00134 for(int i=m_vi_Vertices[VertexIndex]; i<m_vi_Vertices[STEP_UP(VertexIndex)]; i++) {
00135 if( excludedVertex == m_vi_Edges[i]) continue;
00136 D1Neighbor.push_back(m_vi_Edges[i]);
00137 }
00138 }
00139
00141 void GraphCore::PrintVertexD1Neighbor(int VertexIndex, int excludedVertex) {
00142 if(VertexIndex > (int)m_vi_Vertices.size() - 2) {
00143 cout<<"Illegal request. VertexIndex is too large. VertexIndex > m_vi_Vertices.size() - 2"<<endl;
00144 return;
00145 }
00146 if(VertexIndex < 0) {
00147 cout<<"Illegal request. VertexIndex is too small. VertexIndex < 0"<<endl;
00148 return;
00149 }
00150 cout<<"Distance-1 neighbors of "<<VertexIndex<<" are (0-based): ";
00151 for(int i=m_vi_Vertices[VertexIndex]; i<m_vi_Vertices[STEP_UP(VertexIndex)]; i++) {
00152 if( excludedVertex == m_vi_Edges[i]) continue;
00153 cout<<m_vi_Edges[i]<<" ";
00154 }
00155 cout<<"( # of edges = "<<m_vi_Vertices[STEP_UP(VertexIndex)] - m_vi_Vertices[VertexIndex]<<")"<<endl;
00156 }
00157
00159 void GraphCore::PrintVertexD2Neighbor(int VertexIndex) {
00160 cout<<"--Distance-1 neighbors of "<<VertexIndex<<" are: --------------------------"<<endl;
00161 for(int i=m_vi_Vertices[VertexIndex]; i<m_vi_Vertices[STEP_UP(VertexIndex)]; i++) {
00162 PrintVertexD1Neighbor(m_vi_Edges[i], VertexIndex);
00163 }
00164 cout<<"----------------------------------------------------"<<endl;
00165 }
00166
00168
00174 bool GraphCore::AreD2Neighbor(int VertexIndex1, int VertexIndex2) {
00175 set<int> D1_of_VertexIndex1, D1_of_VertexIndex2;
00176 vector<int> Intersect_set;
00177
00178 for(int i=m_vi_Vertices[VertexIndex1]; i<m_vi_Vertices[STEP_UP(VertexIndex1)]; i++)
00179 D1_of_VertexIndex1.insert(m_vi_Edges[i]);
00180 for(int i=m_vi_Vertices[VertexIndex2]; i<m_vi_Vertices[STEP_UP(VertexIndex2)]; i++)
00181 D1_of_VertexIndex2.insert(m_vi_Edges[i]);
00182
00183 Intersect_set.resize(D1_of_VertexIndex1.size(),-1);
00184 set_intersection(D1_of_VertexIndex1.begin(), D1_of_VertexIndex1.end(),
00185 D1_of_VertexIndex2.begin(), D1_of_VertexIndex2.end(),
00186 Intersect_set.begin() );
00187 int size = Intersect_set.size();
00188 while(Intersect_set[size-1] == -1 && size >= 1) size--;
00189 Intersect_set.resize(size,-1);
00190
00191
00192 if(size>0) {
00193
00194 printf("%d and %d connected through vertices: ", VertexIndex1, VertexIndex2);
00195 copy(Intersect_set.begin(), Intersect_set.end(), ostream_iterator<int>(cout, " "));
00196 cout << endl;
00197 return true;
00198 }
00199 return false;
00200
00201
00202
00203
00204
00205
00206
00207
00208
00209 }
00210
00211 bool GraphCore::operator==(const GraphCore &other) const {
00212
00213 if (this == &other)
00214 return true;
00215
00216
00217 vector<int> other_Vertices, other_Edges;
00218 vector<double> other_Values;
00219
00220 other.GetVertices(other_Vertices);
00221 other.GetEdges(other_Edges);
00222 other.GetValues(other_Values);
00223
00224
00225
00226
00227
00228
00229
00230
00231
00232
00233
00234
00235 if(m_vi_Vertices==other_Vertices && m_vi_Edges==other_Edges && m_vd_Values==other_Values ) return true;
00236 else return false;
00237
00238 }
00239
00240 bool GraphCore::areEqual(const GraphCore &other, bool structureOnly) const {
00241
00242 if (this == &other)
00243 return true;
00244
00245
00246 vector<int> other_Vertices, other_Edges;
00247 vector<double> other_Values;
00248
00249 other.GetVertices(other_Vertices);
00250 other.GetEdges(other_Edges);
00251 if (!structureOnly) other.GetValues(other_Values);
00252
00253
00254
00255
00256
00257
00258
00259
00260
00261
00262
00263
00264 if(!structureOnly) {
00265 if(m_vi_Vertices==other_Vertices && m_vi_Edges==other_Edges && m_vd_Values==other_Values ) return true;
00266 else return false;
00267 }
00268 else {
00269 if(m_vi_Vertices==other_Vertices && m_vi_Edges==other_Edges ) return true;
00270 else return false;
00271 }
00272
00273 }
00274
00275
00276
00277
00278
00279 }
00280