BaseGraphClass.cc 22.4 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496
#include "Utility.h"
#include "BaseGraphClass.h"

using namespace std;
//---------------------------------------------------------------------------------
BaseGraphClass::EdgeClass::EdgeClass() :
		mDestVertexID(numeric_limits<unsigned>::max()), mEdgeID(numeric_limits<unsigned>::max()) {
}
BaseGraphClass::EdgeClass::EdgeClass(unsigned aDestVertexID, unsigned aEdgeID) :
		mDestVertexID(aDestVertexID), mEdgeID(aEdgeID) {
}

//---------------------------------------------------------------------------------
ostream& operator<<(ostream& out, const BaseGraphClass& aSG) {
	aSG.Output(out);
	return out;
}
BaseGraphClass::BaseGraphClass() :
		mTopologicalChangeOccurrence(true), mVertexSize(0), mEdgeSize(0) {
}

void BaseGraphClass::ResizeMemory() {
	//NOTE: using the shrink_to_fit() technique as in http://www.gotw.ca/gotw/054.htm
	//for all vertices
	vector<vector<double> >(mVertexNumericAttributeList).swap(mVertexNumericAttributeList);
	vector<vector<string> >(mVertexSymbolicAttributeList).swap(mVertexSymbolicAttributeList);
	vector<vector<bool> >(mVertexStatusAttributeList).swap(mVertexStatusAttributeList);

	//for all edges
	vector<vector<double> >(mEdgeNumericAttributeList).swap(mEdgeNumericAttributeList);
	vector<vector<string> >(mEdgeSymbolicAttributeList).swap(mEdgeSymbolicAttributeList);
	vector<vector<bool> >(mEdgeStatusAttributeList).swap(mEdgeStatusAttributeList);

	//for adjacency structure
	vector<vector<EdgeClass> >(mAdjacencyList).swap(mAdjacencyList);
}

unsigned BaseGraphClass::GetEdgeSource(unsigned aEdgeID) const {
	unsigned src = 0;
	for (unsigned i = 0; i < VertexSize(); i++)
		for (unsigned j = 0; j < mAdjacencyList[i].size(); j++)
			if (mAdjacencyList[i][j].mEdgeID == aEdgeID) {
				src = i;
				return src;
			}
	throw range_error("Edge with id: " + stream_cast<string>(aEdgeID) + " does not exist");
	return src;
}

unsigned BaseGraphClass::GetEdgeDestination(unsigned aEdgeID) const {
	unsigned dest = 0;
	for (unsigned i = 0; i < VertexSize(); i++)
		for (unsigned j = 0; j < mAdjacencyList[i].size(); j++)
			if (mAdjacencyList[i][j].mEdgeID == aEdgeID) {
				dest = mAdjacencyList[i][j].mDestVertexID;
				;
				return dest;
			}
	throw range_error("Edge with id: " + stream_cast<string>(aEdgeID) + " does not exist");
	return dest;
}

unsigned BaseGraphClass::GetVertexInducedRootedSubGraph(const set<unsigned>& aVertexSet, unsigned aNominalRootIndex, BaseGraphClass& oG) const {
	map<unsigned, unsigned> index_map_nominal_to_real;
	for (set<unsigned>::const_iterator it = aVertexSet.begin(); it != aVertexSet.end(); ++it) {
		unsigned nominal_index = *it;
		unsigned real_index = oG.InsertVertex();
		index_map_nominal_to_real[nominal_index] = real_index;
		oG.SetVertexNumericAttributeList(real_index, mVertexNumericAttributeList[nominal_index]);
		oG.SetVertexSymbolicAttributeList(real_index, mVertexSymbolicAttributeList[nominal_index]);
		oG.SetVertexStatusAttributeList(real_index, mVertexStatusAttributeList[nominal_index]);
	}
	unsigned real_root_index = index_map_nominal_to_real[aNominalRootIndex];
	for (set<unsigned>::const_iterator it = aVertexSet.begin(); it != aVertexSet.end(); ++it) {
		unsigned u = *it;
		unsigned nominal_src_index = u;
		for (unsigned v = 0; v < mAdjacencyList[u].size(); ++v) {
			unsigned nominal_dest_index = mAdjacencyList[u][v].mDestVertexID;
			//if dest vertex is among the input set then add corresponding edge
			if (aVertexSet.count(nominal_dest_index) > 0) {
				unsigned real_src_index = index_map_nominal_to_real[nominal_src_index];
				unsigned real_dest_index = index_map_nominal_to_real[nominal_dest_index];
				unsigned nominal_edge_index = mAdjacencyList[u][v].mEdgeID;
				unsigned real_edge_index = oG.InsertEdge(real_src_index, real_dest_index);
				oG.SetEdgeNumericAttributeList(real_edge_index, mEdgeNumericAttributeList[nominal_edge_index]);
				oG.SetEdgeSymbolicAttributeList(real_edge_index, mEdgeSymbolicAttributeList[nominal_edge_index]);
				oG.SetEdgeStatusAttributeList(real_edge_index, mEdgeStatusAttributeList[nominal_edge_index]);
			}
		}
	}
	return real_root_index;
}

unsigned BaseGraphClass::InsertVertex() {
	unsigned vertex_size = mVertexSize;
	mVertexSymbolicIDList.push_back("");
	mAdjacencyList.push_back(vector<EdgeClass>());
	mVertexNumericAttributeList.push_back(vector<double>());
	mVertexSymbolicAttributeList.push_back(vector<string>());
	mVertexStatusAttributeList.push_back(vector<bool>());
	mVertexSize++;
	mTopologicalChangeOccurrence = true;
	return vertex_size;
}

unsigned BaseGraphClass::InsertEdge(unsigned aSrcVertexID, unsigned aDestVertexID) {
	if (aSrcVertexID >= mVertexSize || aDestVertexID >= mVertexSize) throw range_error("Edge between non existing vertices: " + stream_cast<string>(aSrcVertexID) + " " + stream_cast<string>(aDestVertexID));
	unsigned edge_size = mEdgeSize;
	mAdjacencyList[aSrcVertexID].push_back(EdgeClass(aDestVertexID, edge_size));
	mEdgeNumericAttributeList.push_back(vector<double>());
	mEdgeSymbolicAttributeList.push_back(vector<string>());
	mEdgeStatusAttributeList.push_back(vector<bool>());
	mEdgeSize++;
	mTopologicalChangeOccurrence = true;
	return edge_size;
}

void BaseGraphClass::SetVertexSymbolicID(unsigned aID, string aSID) {
	mVertexSymbolicIDList[aID] = aSID;
}
string BaseGraphClass::GetVertexSymbolicID(unsigned aID) const {
	return mVertexSymbolicIDList[aID];
}

void BaseGraphClass::SetVertexNumericAttributeList(unsigned aID, const vector<double>& aAttributeList) {
	if (aID >= mVertexSize) throw range_error("Setting vertex attribute for non existing vertex: " + stream_cast<string>(aID));
	mVertexNumericAttributeList[aID] = aAttributeList;
}
void BaseGraphClass::SetVertexNumericAttributeList(unsigned aID, unsigned aAttributeID, double aValue) {
	if (aID >= mVertexSize) throw range_error("Setting vertex attribute for non existing vertex: " + stream_cast<string>(aID));
	if (aAttributeID < mVertexNumericAttributeList[aID].size()) mVertexNumericAttributeList[aID][aAttributeID] = aValue;
	else {
		unsigned size = aAttributeID + 1;
		vector<double> attribute_list(size, 0);
		for (unsigned i = 0; i < mVertexNumericAttributeList[aID].size(); ++i)
			attribute_list[i] = mVertexNumericAttributeList[aID][i];
		attribute_list[aAttributeID] = aValue;
		mVertexNumericAttributeList[aID] = attribute_list;
	}
}
void BaseGraphClass::SetVertexSymbolicAttributeList(unsigned aID, const vector<string>& aAttributeList) {
#ifdef CHECKLIMITS
	if (aID >= mVertexSize) throw range_error("Setting vertex attribute for non existing vertex: " + stream_cast<string>(aID));
#endif
	mVertexSymbolicAttributeList[aID] = aAttributeList;
}
void BaseGraphClass::SetVertesSymbolicAttribute(unsigned aID, unsigned aAttributeID, const string& aValue) {
#ifdef CHECKLIMITS
	if (aID >= mVertexSize) throw range_error("Setting vertex attribute for non existing vertex: " + stream_cast<string>(aID));
#endif
	if (aAttributeID < mVertexSymbolicAttributeList[aID].size()) mVertexSymbolicAttributeList[aID][aAttributeID] = aValue;
	else {
		unsigned size = aAttributeID + 1;
		vector<string> attribute_list(size, "");
		for (unsigned i = 0; i < mVertexSymbolicAttributeList[aID].size(); ++i)
			attribute_list[i] = mVertexSymbolicAttributeList[aID][i];
		attribute_list[aAttributeID] = aValue;
		mVertexSymbolicAttributeList[aID] = attribute_list;
	}
}
void BaseGraphClass::SetVertexStatusAttributeList(unsigned aID, const vector<bool>& aAttributeList) {
	mTopologicalChangeOccurrence = true;
#ifdef CHECKLIMITS
	if (aID >= mVertexSize) throw range_error("Setting vertex attribute for non existing vertex: " + stream_cast<string>(aID));
#endif
	mVertexStatusAttributeList[aID] = aAttributeList;
}
void BaseGraphClass::SetVertexStatusAttributeList(unsigned aID, unsigned aAttributeID, bool aValue) {
	mTopologicalChangeOccurrence = true;
#ifdef CHECKLIMITS
	if (aID >= mVertexSize) throw range_error("Setting vertex attribute for non existing vertex: " + stream_cast<string>(aID));
#endif
	if (aAttributeID < mVertexStatusAttributeList[aID].size()) mVertexStatusAttributeList[aID][aAttributeID] = aValue;
	else {
		unsigned size = aAttributeID + 1;
		vector<bool> attribute_list(size, false);
		for (unsigned i = 0; i < mVertexStatusAttributeList[aID].size(); ++i)
			attribute_list[i] = mVertexStatusAttributeList[aID][i];
		attribute_list[aAttributeID] = aValue;
		mVertexStatusAttributeList[aID] = attribute_list;
	}
}
vector<string> BaseGraphClass::GetVertexSymbolicAttributeList(unsigned aID) const {
#ifdef CHECKLIMITS
	if (aID >= mVertexSize) throw range_error("Getting vertex attributes for non existing vertex: " + stream_cast<string>(aID));
#endif
	return mVertexSymbolicAttributeList[aID];
}
vector<double> BaseGraphClass::GetVertexNumericAttributeList(unsigned aID) const {
#ifdef CHECKLIMITS
	if (aID >= mVertexSize) throw range_error("Getting vertex attributes for non existing vertex: " + stream_cast<string>(aID));
#endif
	return mVertexNumericAttributeList[aID];
}
vector<bool> BaseGraphClass::GetVertexStatusAttributeList(unsigned aID) const {
#ifdef CHECKLIMITS
	if (aID >= mVertexSize) throw range_error("Getting vertex attributes for non existing vertex: " + stream_cast<string>(aID));
#endif
	return mVertexStatusAttributeList[aID];
}

string BaseGraphClass::GetVertexSymbolicAttribute(unsigned aID, unsigned aAttributeID) const {
#ifdef CHECKLIMITS
	if (aID >= mVertexSize) throw range_error("Getting vertex attributes for non existing vertex: " + stream_cast<string>(aID));
#endif
	if (aAttributeID > mVertexSymbolicAttributeList[aID].size()) throw range_error("Getting vertex attributes for non existing attribute id: " + stream_cast<string>(aAttributeID));
	return mVertexSymbolicAttributeList[aID][aAttributeID];
}
double BaseGraphClass::GetVertexNumericAttribute(unsigned aID, unsigned aAttributeID) const {
#ifdef CHECKLIMITS
	if (aID >= mVertexSize) throw range_error("Getting vertex attributes for non existing vertex: " + stream_cast<string>(aID));
#endif
	if (aAttributeID > mVertexNumericAttributeList[aID].size()) throw range_error("Getting vertex attributes for non existing attribute id: " + stream_cast<string>(aAttributeID));
	return mVertexNumericAttributeList[aID][aAttributeID];
}
bool BaseGraphClass::GetVertexStatusAttribute(unsigned aID, unsigned aAttributeID) const {
#ifdef CHECKLIMITS
	if (aID >= mVertexSize) throw range_error("Getting vertex attributes for non existing vertex: " + stream_cast<string>(aID));
#endif
	if (aAttributeID > mVertexStatusAttributeList[aID].size()) throw range_error("Getting vertex attributes for non existing attribute id: " + stream_cast<string>(aAttributeID));
	return mVertexStatusAttributeList[aID][aAttributeID];
}

void BaseGraphClass::SetEdgeNumericAttributeList(unsigned aID, const vector<double>& aAttributeList) {
#ifdef CHECKLIMITS
	if (aID >= mEdgeSize) throw range_error("Setting edge attribute for non existing edge: " + stream_cast<string>(aID));
#endif
	mEdgeNumericAttributeList[aID] = aAttributeList;
}

void BaseGraphClass::SetEdgeNumericAttribute(unsigned aID, unsigned aAttributeID, double aValue) {
#ifdef CHECKLIMITS
	if (aID >= mEdgeSize) throw range_error("Setting edge attribute for non existing edge: " + stream_cast<string>(aID));
#endif
	if (aAttributeID < mEdgeNumericAttributeList[aID].size()) mEdgeNumericAttributeList[aID][aAttributeID] = aValue;
	else {
		unsigned size = aAttributeID + 1;
		vector<double> attribute_list(size, 0);
		for (unsigned i = 0; i < mEdgeNumericAttributeList[aID].size(); ++i)
			attribute_list[i] = mEdgeNumericAttributeList[aID][i];
		attribute_list[aAttributeID] = aValue;
		mEdgeNumericAttributeList[aID] = attribute_list;
	}
}

void BaseGraphClass::SetEdgeNumericAttribute(unsigned aSrcID, unsigned aDestID, unsigned aAttributeID, double aValue) {
	unsigned edge_id = GetEdgeID(aSrcID, aDestID);
	SetEdgeNumericAttribute(edge_id, aAttributeID, aValue);
}
void BaseGraphClass::SetEdgeSymbolicAttributeList(unsigned aID, const vector<string>& aAttributeList) {
#ifdef CHECKLIMITS
	if (aID >= mEdgeSize) throw range_error("Setting edge attribute for non existing edge: " + stream_cast<string>(aID));
#endif
	mEdgeSymbolicAttributeList[aID] = aAttributeList;
}
void BaseGraphClass::SetEdgeSymbolicAttribute(unsigned aID, unsigned aAttributeID, const string& aValue) {
#ifdef CHECKLIMITS
	if (aID >= mEdgeSize) throw range_error("Setting edge attribute for non existing edge: " + stream_cast<string>(aID));
#endif
	if (aAttributeID < mEdgeSymbolicAttributeList[aID].size()) mEdgeSymbolicAttributeList[aID][aAttributeID] = aValue;
	else {
		unsigned size = aAttributeID + 1;
		vector<string> attribute_list(size, "");
		for (unsigned i = 0; i < mEdgeSymbolicAttributeList[aID].size(); ++i)
			attribute_list[i] = mEdgeSymbolicAttributeList[aID][i];
		attribute_list[aAttributeID] = aValue;
		mEdgeSymbolicAttributeList[aID] = attribute_list;
	}
}
void BaseGraphClass::SetEdgeSymbolicAttribute(unsigned aSrcID, unsigned aDestID, unsigned aAttributeID, const string& aValue) {
	unsigned edge_id = GetEdgeID(aSrcID, aDestID);
	SetEdgeSymbolicAttribute(edge_id, aAttributeID, aValue);
}
void BaseGraphClass::SetEdgeStatusAttributeList(unsigned aID, const vector<bool>& aAttributeList) {
	mTopologicalChangeOccurrence = true;
#ifdef CHECKLIMITS
	if (aID >= mEdgeSize) throw range_error("Setting edge attribute for non existing edge: " + stream_cast<string>(aID));
#endif
	mEdgeStatusAttributeList[aID] = aAttributeList;
}
void BaseGraphClass::SetEdgeStatusAttribute(unsigned aID, unsigned aAttributeID, bool aValue) {
	mTopologicalChangeOccurrence = true;
#ifdef CHECKLIMITS
	if (aID >= mEdgeSize) throw range_error("Setting edge attribute for non existing edge: " + stream_cast<string>(aID));
#endif
	if (aAttributeID < mEdgeStatusAttributeList[aID].size()) mEdgeStatusAttributeList[aID][aAttributeID] = aValue;
	else {
		unsigned size = aAttributeID + 1;
		vector<bool> attribute_list(size, false);
		for (unsigned i = 0; i < mEdgeStatusAttributeList[aID].size(); ++i)
			attribute_list[i] = mEdgeStatusAttributeList[aID][i];
		attribute_list[aAttributeID] = aValue;
		mEdgeStatusAttributeList[aID] = attribute_list;
	}
}
void BaseGraphClass::SetEdgeStatusAttribute(unsigned aSrcID, unsigned aDestID, unsigned aAttributeID, bool aValue) {
	unsigned edge_id = GetEdgeID(aSrcID, aDestID);
	SetEdgeStatusAttribute(edge_id, aAttributeID, aValue);
}

//get methods
vector<string> BaseGraphClass::GetEdgeSymbolicAttributeList(unsigned aSrcID, unsigned aDestID) const {
	unsigned edge_id = GetEdgeID(aSrcID, aDestID);
	return mEdgeSymbolicAttributeList[edge_id];
}
vector<string> BaseGraphClass::GetEdgeSymbolicAttributeList(unsigned aEdgeID) const {
#ifdef CHECKLIMITS
	if (aEdgeID >= mEdgeSymbolicAttributeList.size()) throw range_error("Getting edge attributes for non existing edgeid: " + stream_cast<string>(aEdgeID));
#endif
	return mEdgeSymbolicAttributeList[aEdgeID];
}
string BaseGraphClass::GetEdgeSymbolicAttribute(unsigned aSrcID, unsigned aDestID, unsigned aAttributeID) const {
	unsigned edge_id = GetEdgeID(aSrcID, aDestID);
#ifdef CHECKLIMITS
	if (aAttributeID >= mEdgeSymbolicAttributeList[edge_id].size()) throw range_error("Getting edge attribute for non existing attribute id: " + stream_cast<string>(aAttributeID));
#endif
	return mEdgeSymbolicAttributeList[edge_id][aAttributeID];
}
string BaseGraphClass::GetEdgeSymbolicAttribute(unsigned aEdgeID, unsigned aAttributeID) const {
#ifdef CHECKLIMITS
	if (aAttributeID >= mEdgeSymbolicAttributeList[aEdgeID].size()) throw range_error("Getting edge attribute for non existing attribute id: " + stream_cast<string>(aAttributeID));
#endif
	return mEdgeSymbolicAttributeList[aEdgeID][aAttributeID];
}

vector<double> BaseGraphClass::GetEdgeNumericAttributeList(unsigned aSrcID, unsigned aDestID) const {
	unsigned edge_id = GetEdgeID(aSrcID, aDestID);
	return mEdgeNumericAttributeList[edge_id];
}
vector<double> BaseGraphClass::GetEdgeNumericAttributeList(unsigned aEdgeID) const {
#ifdef CHECKLIMITS
	if (aEdgeID >= mEdgeNumericAttributeList.size()) throw range_error("Getting edge attributes for non existing edgeid: " + stream_cast<string>(aEdgeID));
#endif
	return mEdgeNumericAttributeList[aEdgeID];
}
double BaseGraphClass::GetEdgeNumericAttribute(unsigned aSrcID, unsigned aDestID, unsigned aAttributeID) const {
	unsigned edge_id = GetEdgeID(aSrcID, aDestID);
#ifdef CHECKLIMITS
	if (aAttributeID >= mEdgeNumericAttributeList[edge_id].size()) throw range_error("Getting edge attribute for non existing attribute id: " + stream_cast<string>(aAttributeID));
#endif
	return mEdgeNumericAttributeList[edge_id][aAttributeID];
}
double BaseGraphClass::GetEdgeNumericAttribute(unsigned aEdgeID, unsigned aAttributeID) const {
#ifdef CHECKLIMITS
	if (aAttributeID >= mEdgeNumericAttributeList[aEdgeID].size()) throw range_error("Getting edge attribute for non existing attribute id: " + stream_cast<string>(aAttributeID));
#endif
	return mEdgeNumericAttributeList[aEdgeID][aAttributeID];
}

vector<bool> BaseGraphClass::GetEdgeStatusAttributeList(unsigned aSrcID, unsigned aDestID) const {
	unsigned edge_id = GetEdgeID(aSrcID, aDestID);
	return mEdgeStatusAttributeList[edge_id];
}
vector<bool> BaseGraphClass::GetEdgeStatusAttributeList(unsigned aEdgeID) const {
#ifdef CHECKLIMITS
	if (aEdgeID >= mEdgeStatusAttributeList.size()) throw range_error("Getting edge attributes for non existing edgeid: " + stream_cast<string>(aEdgeID));
#endif
	return mEdgeStatusAttributeList[aEdgeID];
}
bool BaseGraphClass::GetEdgeStatusAttribute(unsigned aSrcID, unsigned aDestID, unsigned aAttributeID) const {
	unsigned edge_id = GetEdgeID(aSrcID, aDestID);
#ifdef CHECKLIMITS
	if (aAttributeID >= mEdgeStatusAttributeList[edge_id].size()) throw range_error("Getting edge attribute for non existing attribute id: " + stream_cast<string>(aAttributeID));
#endif
	return mEdgeStatusAttributeList[edge_id][aAttributeID];
}
bool BaseGraphClass::GetEdgeStatusAttribute(unsigned aEdgeID, unsigned aAttributeID) const {
#ifdef CHECKLIMITS
	if (aAttributeID >= mEdgeStatusAttributeList[aEdgeID].size()) throw range_error("Getting edge attribute for non existing attribute id: " + stream_cast<string>(aAttributeID));
#endif
	return mEdgeStatusAttributeList[aEdgeID][aAttributeID];
}

bool BaseGraphClass::IsEdge(unsigned aSrcID, unsigned aDestID) const {
	for (unsigned j = 0; j < mAdjacencyList[aSrcID].size(); j++)
		if (mAdjacencyList[aSrcID][j].mDestVertexID == aDestID) return true;
	return false;
}
unsigned BaseGraphClass::GetEdgeID(unsigned aSrcID, unsigned aDestID) const {
	for (unsigned j = 0; j < mAdjacencyList[aSrcID].size(); j++)
		if (mAdjacencyList[aSrcID][j].mDestVertexID == aDestID) {
			unsigned edge_id = mAdjacencyList[aSrcID][j].mEdgeID;
			return edge_id;
		}
	throw range_error("Edge between " + stream_cast<string>(aSrcID) + " and " + stream_cast<string>(aDestID) + " does not exist");
	return 0;
}

vector<unsigned> BaseGraphClass::GetVertexAdjacentList(unsigned aID) const {
	vector<unsigned> adjacent_list;
	for (unsigned i = 0; i < mAdjacencyList[aID].size(); ++i)
		adjacent_list.push_back(mAdjacencyList[aID][i].mDestVertexID);
	return adjacent_list;
}

unsigned BaseGraphClass::VertexAdjacentListSize(unsigned aID)const{
	return mAdjacencyList[aID].size();
}

vector<unsigned> BaseGraphClass::GetEdgeAdjacentList(unsigned aID) const {
	vector<unsigned> adjacent_list;
	for (unsigned i = 0; i < mAdjacencyList[aID].size(); ++i)
		adjacent_list.push_back(mAdjacencyList[aID][i].mEdgeID);
	return adjacent_list;
}

ostream& BaseGraphClass::Output(ostream& out) const {
	out << "Graph adjacency list (" << mAdjacencyList.size() << ")" << endl;
	for (unsigned i = 0; i < mAdjacencyList.size(); ++i) {
		out << i << " ";
		for (unsigned j = 0; j < mAdjacencyList[i].size(); ++j)
			out << mAdjacencyList[i][j].mDestVertexID << " ";
		out << endl;
	}

	out << "Vertex Numeric Attribute List (" << mVertexNumericAttributeList.size() << ")" << endl;
	for (unsigned i = 0; i < mVertexNumericAttributeList.size(); ++i) {
		out << i << " ";
		for (unsigned j = 0; j < mVertexNumericAttributeList[i].size(); ++j)
			out << j << ":" << mVertexNumericAttributeList[i][j] << " ";
		out << endl;
	}

	out << "Vertex Symbolic Attribute List (" << mVertexSymbolicAttributeList.size() << ")" << endl;
	for (unsigned i = 0; i < mVertexSymbolicAttributeList.size(); ++i) {
		out << i << " ";
		for (unsigned j = 0; j < mVertexSymbolicAttributeList[i].size(); ++j)
			out << j << ":" << mVertexSymbolicAttributeList[i][j] << " ";
		out << endl;
	}

	out << "Vertex Status Attribute List (" << mVertexStatusAttributeList.size() << ")" << endl;
	for (unsigned i = 0; i < mVertexStatusAttributeList.size(); ++i) {
		out << i << " ";
		for (unsigned j = 0; j < mVertexStatusAttributeList[i].size(); ++j)
			out << j << ":" << mVertexStatusAttributeList[i][j] << " ";
		out << endl;
	}

	out << "Edge Numeric Attribute List (" << mEdgeNumericAttributeList.size() << ")" << endl;
	for (unsigned i = 0; i < mEdgeNumericAttributeList.size(); ++i) {
		out << i << " ";
		for (unsigned j = 0; j < mEdgeNumericAttributeList[i].size(); ++j)
			out << j << ":" << mEdgeNumericAttributeList[i][j] << " ";
		out << endl;
	}

	out << "Edge Symbolic Attribute List (" << mEdgeSymbolicAttributeList.size() << ")" << endl;
	for (unsigned i = 0; i < mEdgeSymbolicAttributeList.size(); ++i) {
		out << i << " ";
		for (unsigned j = 0; j < mEdgeSymbolicAttributeList[i].size(); ++j)
			out << j << ":" << mEdgeSymbolicAttributeList[i][j] << " ";
		out << endl;
	}

	out << "Edge Status Attribute List (" << mEdgeStatusAttributeList.size() << ")" << endl;
	for (unsigned i = 0; i < mEdgeStatusAttributeList.size(); ++i) {
		out << i << " ";
		for (unsigned j = 0; j < mEdgeStatusAttributeList[i].size(); ++j)
			out << j << ":" << mEdgeStatusAttributeList[i][j] << " ";
		out << endl;
	}

	return out;
}

string BaseGraphClass::Serialize() const {
	string encoding;
	encoding += "#v:"+stream_cast<string>(mVertexSize) + " ";
	for (unsigned i = 0; i < mVertexSize; ++i) {
		string vlabel = mVertexSymbolicAttributeList[i][0]; //NOTE: output only first symbolic attribute as vertex label
		encoding += vlabel + " ";
	}
	encoding += "#e:"+stream_cast<string>(mEdgeSize) + " ";
	for (unsigned u = 0; u < mVertexSize; ++u) {
		for (unsigned j = 0; j < mAdjacencyList[u].size(); j++) {
			unsigned v = mAdjacencyList[u][j].mDestVertexID;
			unsigned eid = mAdjacencyList[u][j].mEdgeID;
			string elabel = mEdgeSymbolicAttributeList[eid][0]; //NOTE: output only first symbolic attribute as edge label
			encoding += stream_cast<string>(u) + " " + stream_cast<string>(v) + " " + elabel + " ";
		}
	}
	return encoding;
}
unsigned BaseGraphClass::VertexSize() const {
	return mVertexSize;
}
unsigned BaseGraphClass::EdgeSize() const {
	return mEdgeSize;
}
bool BaseGraphClass::IsEmpty() const {
	if (VertexSize() == 0 && EdgeSize() == 0) return true;
	else return false;
}

//---------------------------------------------------------------------------------