GraphClass.cc 25.2 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 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598
//* -*- mode:c++ -*- */
#include "GraphClass.h"

std::string& getcolor(const string& s) {
	static std::map<std::string, int> colorize;
	static std::string colors[] = { "#ffaa66", "#aaff66", "#ff66aa", "#66ffaa", "#aa66ff", "#66aaff", "#ff6666", "#66ff66", "#6666ff", "#ffff66", "#ff66ff", "#66ffff", "#ffaaaa", "#aaffaa", "#aaaaff", "#ffffaa", "#ffaaff", "#aaffff", "#ffdddd", "#ddffdd", "#ddddff", "#ffffdd", "#ffddff", "#ddffff", "#aaaa66", "#ff9900" };
	static int global_idx = 0;
	int idx;
	std::map<std::string, int>::const_iterator found = colorize.find(s);
	if (found != colorize.end()) {
		idx = found->second;
	} else {
		idx = global_idx = ((global_idx >= 25) ? 0 : (global_idx + 1));
		colorize[s] = idx;
	}
	return colors[idx];
}

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

ostream& operator<<(ostream& out, const GraphClass& aG) {
	return aG.Output(out);
}

string GraphClass::GetGraphID() const {
	return mGraphID;
}
void GraphClass::SetGraphID(string aGraphID) {
	mGraphID = aGraphID;
}

ostream& GraphClass::Output(ostream& out) const {
	out<<"One line graph serialization:"<<endl;
	out<<Serialize()<<endl;
	out<<"Extended graph serialization:"<<endl;
	out<<"Vertex list information:"<<endl;
	for (unsigned i = 0; i < mAdjacencyList.size(); ++i) {
		out << "Vertex id: " << i << " ";
		out << "SymID: " << GetVertexSymbolicID(i) << std::endl;
		out << "  symb[ ";
		for (unsigned k = 0; k < mVertexSymbolicAttributeList[i].size(); ++k)
			out << mVertexSymbolicAttributeList[i][k] << " ";
		out << "]" << std::endl;
		out << "  num[";
		for (unsigned k = 0; k < mVertexNumericAttributeList[i].size(); ++k)
			out << mVertexNumericAttributeList[i][k] << " ";
		out << "]" << std::endl;
		out << "  status[ ";
		out << "vertex_kind:" << (GetVertexKind(i) ? "entity" : "relation") << " ";
		out << "first_endpoint:" << (GetVertexViewPoint(i) ? "yes" : "no") << " ";
		out << "kernel_point:" << (GetVertexKernelPoint(i) ? "yes" : "no") << " ";
		out << "abstraction_of:" << (GetVertexAbstraction(i) ? "yes" : "no") << " ";
		out << "dead:" << (GetVertexDead(i) ? "yes" : "no") << " ";
		out << "]" << std::endl;
		out << "  Adjacency list (vertex index): ";
		for (unsigned k = 0; k < mAdjacencyList[i].size(); ++k)
			out << mAdjacencyList[i][k].mDestVertexID << " ";
		out << endl;
		out << "  Adjacency list (edge index): ";
		for (unsigned k = 0; k < mAdjacencyList[i].size(); ++k)
			out << mAdjacencyList[i][k].mEdgeID << " ";
		out << endl;
	}

	out<<"Edge list information:"<<endl;
	for (unsigned i = 0; i < mEdgeSize; ++i) {
			out << "Edge id: " << i << std::endl;
			out << "  symb[ ";
			for (unsigned k = 0; k < mEdgeSymbolicAttributeList[i].size(); ++k)
				out << mEdgeSymbolicAttributeList[i][k] << " ";
			out << "]" << std::endl;
			out << "  num[";
			for (unsigned k = 0; k < mEdgeNumericAttributeList[i].size(); ++k)
				out << mEdgeNumericAttributeList[i][k] << " ";
			out << "]" << std::endl;
			out << "  status[ ";
			out << "abstraction_of:" << (GetEdgeAbstractionOf(i) ? "yes" : "no") << " ";
			out << "part_of:" << (GetEdgePartOf(i) ? "yes" : "no") << " ";
			out << "]" << std::endl;
	}

	out << "Map (src,dest) -> distance (" << mSrcDestMaptoDistance.size() << "):" << endl;
	for (map<pair<unsigned, unsigned>, int>::const_iterator it = mSrcDestMaptoDistance.begin(); it != mSrcDestMaptoDistance.end(); ++it)
		out << "(src id:" << it->first.first << " , dest id:" << it->first.second << ") -> distance:" << it->second << endl;

	out << "Map (src,distance) -> dest list (" << mSrcDistanceMaptoDestList.size() << "):" << endl;
	for (map<pair<unsigned, int>, vector<unsigned> >::const_iterator it = mSrcDistanceMaptoDestList.begin(); it != mSrcDistanceMaptoDestList.end(); ++it) {
		out << "(src id:" << it->first.first << " , distance:" << it->first.second << ") -> dest id list: ";
		const vector<unsigned>& dest_list = it->second;
		for (unsigned i = 0; i < dest_list.size(); ++i)
			out << dest_list[i] << " ";
		out << endl;
	}
	return out;
}

// void GraphClass::SaveAsUnionDotFile(const string& aGid, const string& aFilename)const{
//   std::ofstream dot_stream;
//   dot_stream.open(aFilename.c_str(),ios::out);
//   dot_stream << "graph \"" << aGid << "\"{" << std::endl;
//   for (unsigned v=0; v<mVertexSize; ++v) {
//     dot_stream << v << " [label=\"";
//     for (unsigned j=0;j<mVertexSymbolicAttributeList[v].size();++j) {
//       if (j==0)
// 	dot_stream << mVertexSymbolicAttributeList[v][j] << (mVertexSymbolicAttributeList[v].size()>1 ? "(" : "");
//       else if (j<mVertexSymbolicAttributeList[v].size()-1)
// 	dot_stream
// 	  //<< j << ":"
// 	  << mVertexSymbolicAttributeList[v][j] << ",";
//       else
// 	dot_stream
// 	  //<< j << ":"
// 	  << mVertexSymbolicAttributeList[v][j] << ")";
//     }
//     for (unsigned j=0;j<mVertexNumericAttributeList[v].size();++j) {
//       if (j==0) dot_stream << "(";
//       dot_stream
// 	//<< j << ":"
// 	<< mVertexNumericAttributeList[v][j]
// 	<< (j==mVertexNumericAttributeList[v].size()-1 ? ")" :",");
//     }
//     dot_stream << "\", shape=\"circle\""
// 	       << ",width=\""<< stream_cast<string>(mVertexNumericAttributeList[v][0])<<"\""
// 	       << ",color=\"" << getcolor(mVertexSymbolicAttributeList[v][0])<<"\""
// 	       << ",style=\"filled\""
// 	       <<" , penwidth=\""<<stream_cast<string>(mVertexNumericAttributeList[v][0]*3)<<"\""
//                << "]" << std::endl;
//   }
//   for (unsigned u=0; u<mVertexSize; ++u) {
//     for (unsigned vpos=0; vpos < mAdjacencyList[u].size(); ++vpos) {
//       unsigned int v = mAdjacencyList[u][vpos].mDestVertexID;
//       if (u<v){ // internally there are both u-v and v-u but we want to draw an undirected graph!
// 	unsigned edge_id = mAdjacencyList[u][vpos].mEdgeID;
// 	dot_stream << u << " -- " << v << " [label=\"";
// 	for (unsigned j=0;j<mEdgeSymbolicAttributeList[edge_id].size();++j){
// 	  dot_stream
// 	    //<< j << ":"
// 	    << mEdgeSymbolicAttributeList[edge_id][j]<<" ";
// 	}
// 	for (unsigned j=0;j<mEdgeNumericAttributeList[edge_id].size();++j){
// 	  if (j==0) dot_stream << "(";
// 	  dot_stream
// 	    //<< j << ":"
// 	    << mEdgeNumericAttributeList[edge_id][j]
// 	    << (j==mEdgeNumericAttributeList[edge_id].size()-1 ? ")" :",");
// 	}
// 	dot_stream << "\"";
// 	dot_stream<<" , weight=\""<<mEdgeNumericAttributeList[edge_id][0]<<"\"";
// 	dot_stream<<" , penwidth=\""<<mEdgeNumericAttributeList[edge_id][0]<<"\"";
// 	dot_stream << "]" << std::endl;
//       } else {}
//     }
//   }
//   dot_stream << "}" << std::endl;
//   dot_stream.close();
// }

std::string GraphClass::vertex_label_serialize(unsigned v, std::string separator) const {
	stringstream os;
	os << (GetVertexKernelPoint(v) == true ? "*" : "");
	for (unsigned j = 0; j < mVertexSymbolicAttributeList[v].size(); ++j) {
		if (j == 0) os << mVertexSymbolicAttributeList[v][j] << (mVertexSymbolicAttributeList[v].size() > 1 ? "(" : "");
		else if (j < mVertexSymbolicAttributeList[v].size() - 1) os
		//<< j << ":"
		<< mVertexSymbolicAttributeList[v][j] << ",";
		else os
		//<< j << ":"
		<< mVertexSymbolicAttributeList[v][j] << ")";
	}
	for (unsigned j = 0; j < mVertexNumericAttributeList[v].size(); ++j) {
		if (j == 0) os << "(";
		os
		//<< j << ":"
		<< mVertexNumericAttributeList[v][j] << (j == mVertexNumericAttributeList[v].size() - 1 ? ")" : ",");
	}
	if (GetVertexKind(v) == true) os << separator << GetVertexSymbolicID(v);
	if (IsSliced()) os << separator << "{" << GetSliceID(v) << "}";
	return os.str();
}

std::string GraphClass::edge_label_serialize(unsigned edge_id) const {
	stringstream os;
	for (unsigned j = 0; j < mEdgeSymbolicAttributeList[edge_id].size(); ++j)
		os
		//<< j << ":"
		<< mEdgeSymbolicAttributeList[edge_id][j] << " ";
	for (unsigned j = 0; j < mEdgeNumericAttributeList[edge_id].size(); ++j)
		os
		//<< j << ":"
		<< mEdgeNumericAttributeList[edge_id][j] << " ";
	return os.str();
}

/**
 Create a dot file of a given interpretation for
 debugging/visualization. E-vertices are represented as boxes,
 R-vertices as diamonds, dead vertices are dashed. Symbolic IDs and
 slice identifiers if meaningful are printed for debugging purposes.
 */
void GraphClass::SaveAsDotFile(const string& aFilename) const {
	std::ofstream dot_stream;
	dot_stream.open(aFilename.c_str(), ios::out);
	dot_stream << "graph \"" << mGraphID << "\"{" << std::endl;
	for (unsigned v = 0; v < mVertexSize; ++v) {
		dot_stream
				<< v
				<< " [label=\""
				<< vertex_label_serialize(v)
				<< "\", shape="
				<< (GetVertexKind(v) == true ? "box" : "diamond")
				<< ",style="
				<< (GetVertexDead(v) == false ? "filled" : "dashed")
				<< ",fillcolor=\""
				<< getcolor(IsSliced() ? GetSliceID(v) : mVertexSymbolicAttributeList[v][0])
				<< "\"]"
				<< std::endl;
	}
	for (unsigned u = 0; u < mVertexSize; ++u) {
		for (unsigned vpos = 0; vpos < mAdjacencyList[u].size(); ++vpos) {
			unsigned int v = mAdjacencyList[u][vpos].mDestVertexID;
			if (v < u) { // internally there are both u-v and v-u but we want to draw an undirected graph!
				unsigned edge_id = mAdjacencyList[u][vpos].mEdgeID;
				dot_stream << u << " -- " << v << " [label=\"" << edge_label_serialize(edge_id) << "\"]" << std::endl;
			} else {
			}
		}
	}
	dot_stream << "}" << std::endl;
	dot_stream.close();
}

/**
 Create a GML file of a given interpretation for
 debugging/visualization. E-vertices are represented as boxes,
 R-vertices as diamonds, dead vertices are dashed. Symbolic IDs and
 slice identifiers if meaningful are printed for debugging purposes.
 */
void GraphClass::SaveAsGMLFile(const string& aFilename) const {
	std::ofstream gml_stream;
	gml_stream.open(aFilename.c_str(), ios::out);
	gml_stream << "graph [" << std::endl << "\tcomment \"" << mGraphID << "\"" << std::endl << "\tdirected 0" << std::endl << "\tid 0" << std::endl << "\tlabel \"" << mGraphID << "\"" << std::endl;
	for (unsigned v = 0; v < mVertexSize; ++v) {
		gml_stream << "\tnode [" << std::endl << "\t\tid " << v << std::endl << "\t\tLabelGraphics [ text \"" << vertex_label_serialize(v, " - ") << "\" ]" << std::endl;
		gml_stream << "\t\tgraphics [" << std::endl << "\t\t\ttype \"" << (GetVertexKind(v) == true ? "rectangle" : "diamond") << "\"" << std::endl << "\t\t\tfill \"" << (getcolor(IsSliced() ? GetSliceID(v) : mVertexSymbolicAttributeList[v][0])) << "\"" << std::endl << "\t\t]" << std::endl;
		gml_stream << "\t]" << std::endl; // end node
	}
	for (unsigned u = 0; u < mVertexSize; ++u) {
		for (unsigned vpos = 0; vpos < mAdjacencyList[u].size(); ++vpos) {
			unsigned int v = mAdjacencyList[u][vpos].mDestVertexID;
			if (v < u) { // internally there are both u-v and v-u but we want to draw an undirected graph!
				unsigned edge_id = mAdjacencyList[u][vpos].mEdgeID;
				gml_stream << "\tedge [" << std::endl << "\t\tlabel \"" << edge_label_serialize(edge_id) << "\"" << std::endl;
				gml_stream << "\t\tsource " << u << std::endl << "\t\ttarget " << v << std::endl;
				gml_stream << "\t]" << std::endl; // end edge
			} else {
			}
		}
	}
	gml_stream << "]" << std::endl;
	gml_stream.close();
}

/**
 Create a GDL file of a given interpretation for
 debugging/visualization (using aiSee). E-vertices are represented
 as boxes, R-vertices as diamonds, dead vertices are
 dashed. Symbolic IDs and slice identifiers if meaningful are
 printed for debugging purposes.
 */
void GraphClass::SaveAsGDLFile(const string& aFilename) const {
	std::ofstream gdl_stream;
	gdl_stream.open(aFilename.c_str(), ios::out);
	gdl_stream << "graph: { title: " << "\"" << mGraphID << "\"" << std::endl << "\tlayoutalgorithm: forcedir" << std::endl << std::endl;
	for (unsigned v = 0; v < mVertexSize; ++v) {
		gdl_stream << "node: {"
		//               << " color: \"" << (getcolor(IsSliced()?GetSliceID(v):mVertexSymbolicAttributeList[v][0]))<<"\""
				<< " title: \""
				<< v
				<< "\""
				<< " shape: "
				<< (GetVertexKind(v) == true ? "box" : "rhomb")
				<< " label: \""
				<< vertex_label_serialize(v, "\n")
				<< "\" }"
				<< std::endl;
	}
	for (unsigned u = 0; u < mVertexSize; ++u) {
		for (unsigned vpos = 0; vpos < mAdjacencyList[u].size(); ++vpos) {
			unsigned int v = mAdjacencyList[u][vpos].mDestVertexID;
			if (v < u) { // internally there are both u-v and v-u but we want to draw an undirected graph!
				//unsigned edge_id = mAdjacencyList[u][vpos].mEdgeID;
				gdl_stream << "edge: { " << "sourcename: \"" << u << "\"" << " targetname: \"" << v << "\" }" << std::endl;
			} else {
			}
		}
	}
	gdl_stream << "}" << std::endl;
	gdl_stream.close();
}

/**
 Create a CSV file of a given interpretation for
 debugging/visualization. Only interactions (between entities and
 relationships) are saved.
 */
void GraphClass::SaveAsCSVFile(const string& aFilename) const {
	std::ofstream csv_stream;
	csv_stream.open(aFilename.c_str(), ios::out);
	for (unsigned u = 0; u < mVertexSize; ++u) {
		for (unsigned vpos = 0; vpos < mAdjacencyList[u].size(); ++vpos) {
			unsigned int v = mAdjacencyList[u][vpos].mDestVertexID;
			if (v < u) { // internally there are both u-v and v-u but we want to draw an undirected graph!
				unsigned edge_id = mAdjacencyList[u][vpos].mEdgeID;
				csv_stream << u << "," << vertex_label_serialize(u, " - ") << "," << v << "," << vertex_label_serialize(v, " - ") << "," << edge_id << "," << edge_label_serialize(edge_id) << std::endl;
			} else {
			}
		}
	}
	csv_stream.close();
}

void GraphClass::SaveAsGspanFile(const string& aFilename) const {
	std::ofstream gspan_stream;
	gspan_stream.open(aFilename.c_str(), ios::out);
	gspan_stream << "t # " << mGraphID << std::endl;
	for (unsigned v = 0; v < mVertexSize; ++v) {
		gspan_stream << "v " << v << " ";
		for (unsigned i = 0; i < mVertexSymbolicAttributeList[v].size(); i++)
			gspan_stream << mVertexSymbolicAttributeList[v][i] << " ";
		for (unsigned i = 0; i < mVertexNumericAttributeList[v].size(); i++)
			gspan_stream << mVertexNumericAttributeList[v][i] << " ";
		gspan_stream << endl;
	}
	for (unsigned u = 0; u < mVertexSize; ++u) {
		for (unsigned vpos = 0; vpos < mAdjacencyList[u].size(); ++vpos) {
			unsigned int v = mAdjacencyList[u][vpos].mDestVertexID;
			unsigned e = mAdjacencyList[u][vpos].mEdgeID;
			if (u < v) { // internally there are both u-v and v-u but we want to draw an undirected graph!
				gspan_stream << "e " << u << " " << v << " ";
				for (unsigned i = 0; i < mEdgeSymbolicAttributeList[e].size(); i++)
					gspan_stream << mEdgeSymbolicAttributeList[e][i] << " ";
				for (unsigned i = 0; i < mEdgeNumericAttributeList[e].size(); i++)
					gspan_stream << mEdgeNumericAttributeList[e][i] << " ";
				gspan_stream << endl;
			} else {
			}
		}
	}
	gspan_stream.close();
}

void GraphClass::ExportGraph(const string& aFilename, const string& aFormat) const {
	if (aFormat == "dot") SaveAsDotFile(aFilename + "." + aFormat);
	else if (aFormat == "gml") SaveAsGMLFile(aFilename + "." + aFormat);
	else if (aFormat == "gdl") SaveAsGDLFile(aFilename + "." + aFormat);
	else if (aFormat == "csv") SaveAsCSVFile(aFilename + "." + aFormat);
	else if (aFormat == "gspan") SaveAsGspanFile(aFilename + "." + aFormat);
	else throw std::out_of_range("ERROR18: Invalid export format in GraphClass::ExportGraph()");
}

void GraphClass::SetSliceID(unsigned aID, const string& aSliceID) {
	if (aID >= mSliceIdList.size()) mSliceIdList.resize(2 * mSliceIdList.size());
	mSliceIdList[aID] = aSliceID;
}

string GraphClass::GetSliceID(unsigned aID) const {
	return mSliceIdList[aID];
}

void GraphClass::SetVertexKernelPoint(unsigned aID, bool aState) {
	mTopologicalChangeOccurrence = true;
	SetVertexStatusAttributeList(aID, KERNEL_POINT_ID, aState);
}
bool GraphClass::GetVertexKernelPoint(unsigned aID) const {
	return GetVertexStatusAttribute(aID, KERNEL_POINT_ID);
}
void GraphClass::SetVertexKind(unsigned aID, bool aKind) {
	SetVertexStatusAttributeList(aID, KIND_ID, aKind);
}
bool GraphClass::GetVertexKind(unsigned aID) const {
	return GetVertexStatusAttribute(aID, KIND_ID);
}
void GraphClass::SetVertexViewPoint(unsigned aID, bool aState) {
	SetVertexStatusAttributeList(aID, VIEWPOINT_ID, aState);
}
bool GraphClass::GetVertexViewPoint(unsigned aID) const {
	return GetVertexStatusAttribute(aID, VIEWPOINT_ID);
}
void GraphClass::SetVertexAlive(unsigned aID, bool aState) {
	SetVertexDead(aID, !aState);
}
bool GraphClass::GetVertexAlive(unsigned aID) const {
	return !GetVertexDead(aID);
}
void GraphClass::SetVertexDead(unsigned aID, bool aState) {
	mTopologicalChangeOccurrence = true;
	SetVertexStatusAttributeList(aID, DEAD_ID, aState);
}
void GraphClass::KillVertices(std::string aLabel) {
	mTopologicalChangeOccurrence = true;
	for (unsigned v = 0; v < mVertexSize; ++v) {
		if (GetVertexLabel(v) == aLabel) {
			SetVertexDead(v, true);
			cout << "Graph_id:" << mGraphID << " killed_vertex_id:" << v << " label:" << vertex_label_serialize(v, " - ") << std::endl; ////FIXME: only for debugging purposes
		}
	}
}

bool GraphClass::GetVertexDead(unsigned aID) const {
	return GetVertexStatusAttribute(aID, DEAD_ID);
}

bool GraphClass::GetVertexAbstraction(unsigned aID) const {
	return GetVertexStatusAttribute(aID, ABSTRACTION_ID);
}
void GraphClass::SetVertexAbstraction(unsigned aID, bool aStatus) {
	SetVertexStatusAttributeList(aID, ABSTRACTION_ID, aStatus);
}

void GraphClass::SetVertexLabel(unsigned aID, const string& aLabel) {
	SetVertesSymbolicAttribute(aID, LABEL_VERTEX_ATTRIBUTE_ID, aLabel);
}
string GraphClass::GetVertexLabel(unsigned aID) const {
	return GetVertexSymbolicAttribute(aID, LABEL_VERTEX_ATTRIBUTE_ID);
}
string GraphClass::GetVertexLabelConcatenated(unsigned aID) const {
	return GetVertexSymbolicAttribute(aID, LABEL_VERTEX_ATTRIBUTE_ID);
}
string GraphClass::GetEdgeLabel(unsigned aSrcID, unsigned aDestID) const {
	return GetEdgeSymbolicAttribute(aSrcID, aDestID, EDGE_ATTRIBUTE_ID);
}
string GraphClass::GetEdgeLabel(unsigned aEdgeID) const {
	return GetEdgeSymbolicAttribute(aEdgeID, EDGE_ATTRIBUTE_ID);
}
string GraphClass::GetEdgeLabelConcatenated(unsigned aSrcID, unsigned aDestID) const {
	return GetEdgeSymbolicAttribute(aSrcID, aDestID, EDGE_ATTRIBUTE_ID);
}
string GraphClass::GetEdgeLabelConcatenated(unsigned aEdgeID) const {
	return GetEdgeSymbolicAttribute(aEdgeID, EDGE_ATTRIBUTE_ID);
}
void GraphClass::SetEdgeLabel(unsigned aSrcID, unsigned aDestID, const string& aLabel) {
	SetEdgeSymbolicAttribute(aSrcID, aDestID, EDGE_ATTRIBUTE_ID, aLabel);
}
bool GraphClass::GetEdgeAbstractionOf(unsigned aSrcID, unsigned aDestID) const {
	return GetEdgeStatusAttribute(aSrcID, aDestID, EDGE_ABSTRACTIONOF_ID);
}
bool GraphClass::GetEdgeAbstractionOf(unsigned aEdgeID) const {
	return GetEdgeStatusAttribute(aEdgeID, EDGE_ABSTRACTIONOF_ID);
}
void GraphClass::SetEdgeAbstractionOf(unsigned aSrcID, unsigned aDestID, bool aStatus) {
	SetEdgeStatusAttribute(aSrcID, aDestID, EDGE_ABSTRACTIONOF_ID, aStatus);
}
void GraphClass::SetEdgeAbstractionOf(unsigned aEdgeID, bool aStatus) {
	SetEdgeStatusAttribute(aEdgeID, EDGE_ABSTRACTIONOF_ID, aStatus);
}
bool GraphClass::GetEdgePartOf(unsigned aSrcID, unsigned aDestID) const {
	return GetEdgeStatusAttribute(aSrcID, aDestID, EDGE_PARTOF_ID);
}
bool GraphClass::GetEdgePartOf(unsigned aEdgeID) const {
	return GetEdgeStatusAttribute(aEdgeID, EDGE_PARTOF_ID);
}
void GraphClass::SetEdgePartOf(unsigned aSrcID, unsigned aDestID, bool aStatus) {
	SetEdgeStatusAttribute(aSrcID, aDestID, EDGE_PARTOF_ID, aStatus);
}
void GraphClass::SetEdgePartOf(unsigned aEdgeID, bool aStatus) {
	SetEdgeStatusAttribute(aEdgeID, EDGE_PARTOF_ID, aStatus);
}
bool GraphClass::Check() const {
	if (VertexSize() == 0) throw logic_error("ERROR14: Empty data structure: vertex set");
	//if (EdgeSize()==0) throw logic_error("ERROR15: Empty data structure: edge set");
	if (mSrcDestMaptoDistance.size() == 0) throw logic_error("ERROR16: Empty data structure: (src,dest) -> distance map");
	if (mSrcDistanceMaptoDestList.size() == 0) throw logic_error("ERROR17: Empty data structure: (src,distance) -> dest list map");
	return true;
}

/**
 Returns a vector of ids of vertices adjacent to aID that are
 ALIVE. Overriden function from
 BaseGraphClass::GetVertexAdjacentList(unsigned aID)const.
 */
vector<unsigned> GraphClass::GetVertexAdjacentList(unsigned aID) const {
	vector<unsigned> adjacent_list;
	for (unsigned i = 0; i < mAdjacencyList[aID].size(); ++i) {
		unsigned vid = mAdjacencyList[aID][i].mDestVertexID;
		if (GetVertexAlive(vid)) adjacent_list.push_back(vid);
	}
	return adjacent_list;
}

void GraphClass::ComputePairwiseDistanceInformation(int aMaxDistance, int aMaxRadius, vector<unsigned> aViewPointList) const {
	if (aMaxDistance != -1) mMaxDistance = aMaxDistance;
	if (aMaxRadius != -1) mMaxRadius = aMaxRadius;
	if (mTopologicalChangeOccurrence == true) {
		unsigned distance_bound = max(mMaxRadius, mMaxDistance);
		mSrcDestMaptoDistance.clear();
			for (unsigned i = 0; i < VertexSize(); i++) {
				if (GetVertexDead(i) == false) // Paolo
					if (GetVertexAbstraction(i) == false) SingleVertexBoundedBreadthFirstVisit(i, distance_bound, mSrcDestMaptoDistance);
			}
		mSrcDistanceMaptoDestList.clear();
		for (map<pair<unsigned, unsigned>, int>::iterator it = mSrcDestMaptoDistance.begin(); it != mSrcDestMaptoDistance.end(); ++it) {
			unsigned src_id = it->first.first;
			unsigned dest_id = it->first.second;
			int distance = it->second;
			mSrcDistanceMaptoDestList[make_pair(src_id, distance)].push_back(dest_id);
		}

		mTopologicalChangeOccurrence = false;
	} else {
	}
}

void GraphClass::SingleVertexBoundedBreadthFirstVisit(unsigned aRootVertexIndex, int aRadius, map<pair<unsigned, unsigned>, int>& oSrcDestMaptoDistance) const {
	map<int, int> dest_mapto_distance;
	dest_mapto_distance[aRootVertexIndex] = 0;
	map<int, bool> already_explored;//NOTE: we use a map as the limited depth breadth first visit can visit much fewer vertices than there are vertices
	already_explored[aRootVertexIndex] = true;
	queue<int> q;
	q.push(aRootVertexIndex); //initialize queue with the root vertex
	while (q.empty() == false) {
		int u = q.front();
		for (unsigned j = 0; j < mAdjacencyList[u].size(); j++) {
			int v = mAdjacencyList[u][j].mDestVertexID;
			if (already_explored[v] == true || GetVertexDead(v) == true || GetVertexAbstraction(v) == true) {//do nothing, ignore the vertex
			} else {
				if (dest_mapto_distance[u] + 1 <= aRadius) {
					dest_mapto_distance[v] = dest_mapto_distance[u] + 1;
					already_explored[v] = true;
					q.push(v);
				}
			}
		}
		q.pop();
	}
	//compute (src,dest) \mapto distance
	for (map<int, int>::const_iterator it = dest_mapto_distance.begin(); it != dest_mapto_distance.end(); ++it) {
		unsigned dest_vertex_id = (unsigned) (it->first);
		int distance = it->second;
		oSrcDestMaptoDistance.insert(make_pair(make_pair(aRootVertexIndex, dest_vertex_id), distance));
	}
}

vector<unsigned> GraphClass::GetFixedDistanceVertexIDList(unsigned aSrcID, int aDistance) const {
	if (mTopologicalChangeOccurrence == true) ComputePairwiseDistanceInformation();
	if (mSrcDistanceMaptoDestList.count(make_pair(aSrcID, aDistance)) == 0) return vector<unsigned>(0);
	else return mSrcDistanceMaptoDestList.find(make_pair(aSrcID, aDistance))->second;
}
int GraphClass::PairwiseDistance(unsigned aSrcID, unsigned aDestID) const {
	if (mTopologicalChangeOccurrence == true) ComputePairwiseDistanceInformation();
	if (mSrcDestMaptoDistance.count(make_pair(aSrcID, aDestID)) == 0) return -1;
	else return (mSrcDestMaptoDistance.find(make_pair(aSrcID, aDestID)))->second;
}

set<unsigned> GraphClass::GetUnionShortestPathsVertexIDList(unsigned aSrcID, unsigned aDestID, unsigned aDistance) const {
	return GetUnionShortestPathsVertexIDList(aSrcID, aDestID, aDistance, aDistance);
}

set<unsigned> GraphClass::GetUnionShortestPathsVertexIDList(unsigned aSrcID, unsigned aDestID, unsigned aDistance, unsigned aRadius) const {
	set<unsigned> union_shortest_paths_set;
	for (unsigned d = 0; d <= aRadius; d++) {
		//get all vertices at distance d from src
		vector<unsigned> src_neighbors = GetFixedDistanceVertexIDList(aSrcID, d);
		set<unsigned> src_neighbors_set;
		for (unsigned i = 0; i < src_neighbors.size(); i++)
			src_neighbors_set.insert(src_neighbors[i]);
		//get all vertices at distance aDistance-d from dest
		vector<unsigned> dest_neighbors = GetFixedDistanceVertexIDList(aDestID, aDistance - d);
		set<unsigned> dest_neighbors_set;
		for (unsigned i = 0; i < dest_neighbors.size(); i++)
			dest_neighbors_set.insert(dest_neighbors[i]);
		//store intersection set
		set_intersection(src_neighbors_set.begin(), src_neighbors_set.end(), dest_neighbors_set.begin(), dest_neighbors_set.end(), inserter(union_shortest_paths_set, union_shortest_paths_set.begin()));
	}
	return union_shortest_paths_set;
}

set<unsigned> GraphClass::GetUnionThickShortestPathsVertexIDSet(unsigned aSrcID, unsigned aDestID, unsigned aDistance, unsigned aThickness) const {
	set<unsigned> path = GetUnionShortestPathsVertexIDList(aSrcID, aDestID, aDistance);
	set<unsigned> thick_path;
	for (set<unsigned>::iterator it = path.begin(); it != path.end(); ++it) {
		unsigned id = *it;
		//for each vertex extract neighborhood subgraph
		vector<unsigned> neighborhood = GetNeighborhoodVertexIDList(id, aThickness);
		for (unsigned i = 0; i < neighborhood.size(); ++i)
			thick_path.insert(neighborhood[i]);
	}
	return thick_path;
}

vector<unsigned> GraphClass::GetNeighborhoodVertexIDList(unsigned aSrcID, unsigned aRadius) const {
	vector<unsigned> neighborhood;
	for (unsigned d = 0; d <= aRadius; d++) {
		vector<unsigned> circle = GetFixedDistanceVertexIDList(aSrcID, d);
		for (unsigned i = 0; i < circle.size(); ++i)
			neighborhood.push_back(circle[i]);
	}
	return neighborhood;
}