Exemple #1
0
void TGraphEnumUtils::GetIndGraph(const PNGraph &G, const TIntV &sg, PNGraph &indG) {
	//Add nodes
	for(int i=0; i<sg.Len(); i++) indG->AddNode(sg[i]);
	//Add edges
	for(int i=0; i<sg.Len(); i++) {
		int nId = sg[i];
		TNGraph::TNodeI nIt = G->GetNI(nId);
		//
		int deg = nIt.GetOutDeg();
		for(int j=0; j<deg; j++) {
			int dstId = nIt.GetNbrNId(j);
			if(nId == dstId) continue;
			//
			if(indG->IsNode(dstId)) indG->AddEdge(nId, dstId);
		}
	}
}