13 for (
int n = 0; n < NIdV.
Len(); n++) {
14 if (Graph->IsNode(NIdV[n])) {
16 if (! RenumberNodes) { NewGraph.
AddNode(NIdV[n]); }
17 else { NewGraph.
AddNode(NIdSet.GetKeyId(NIdV[n])); }
20 if (! RenumberNodes) {
21 for (
int n = 0; n < NIdSet.Len(); n++) {
22 const int SrcNId = NIdSet[n];
24 for (
int edge = 0; edge < NI.
GetOutDeg(); edge++) {
26 if (NIdSet.IsKey(OutNId)) {
27 NewGraph.
AddEdge(SrcNId, OutNId); }
31 for (
int n = 0; n < NIdSet.Len(); n++) {
32 const int SrcNId = NIdSet[n];
34 for (
int edge = 0; edge < NI.
GetOutDeg(); edge++) {
36 if (NIdSet.IsKey(OutNId)) {
37 NewGraph.
AddEdge(NIdSet.GetKeyId(SrcNId), NIdSet.GetKeyId(OutNId)); }
48 TNGraph& NewGraph = *NewGraphPt;
51 for (
int n = 0; n < NIdV.
Len(); n++) {
52 if (Graph->
IsNode(NIdV[n])) {
54 if (! RenumberNodes) { NewGraph.
AddNode(NIdV[n]); }
55 else { NewGraph.
AddNode(NIdSet.GetKeyId(NIdV[n])); }
58 if (! RenumberNodes) {
59 for (
int n = 0; n < NIdSet.Len(); n++) {
60 const int SrcNId = NIdSet[n];
62 for (
int edge = 0; edge < NI.
GetOutDeg(); edge++) {
64 if (NIdSet.IsKey(OutNId)) {
65 NewGraph.
AddEdge(SrcNId, OutNId); }
69 for (
int n = 0; n < NIdSet.Len(); n++) {
70 const int SrcNId = NIdSet[n];
72 for (
int edge = 0; edge < NI.
GetOutDeg(); edge++) {
74 if (NIdSet.IsKey(OutNId)) {
75 NewGraph.
AddEdge(NIdSet.GetKeyId(SrcNId), NIdSet.GetKeyId(OutNId)); }
87 for (
int i = 0; i < CtrNode.
GetInDeg(); ++i) {
91 for (
int i = 0; i < CtrNode.
GetInDeg(); ++i) {
94 for (
int j = 0; j < NbrNode.
GetInDeg(); ++j) {
96 if (NewGraph.
IsNode(NbrNbrNId)) {
97 if (!NewGraph.
IsEdge(NbrNId, NbrNbrNId)) {
98 NewGraph.
AddEdge(NbrNId, NbrNbrNId);
110 TNGraph& NewGraph = *NewGraphPt;
113 for (
int i = 0; i < CtrNode.
GetDeg(); ++i) {
118 for (
int i = 0; i < CtrNode.
GetDeg(); ++i) {
121 for (
int j = 0; j < NbrNode.
GetInDeg(); ++j) {
122 int NbrNbrNId = NbrNode.
GetInNId(j);
123 if (NewGraph.
IsNode(NbrNbrNId)) {
124 NewGraph.
AddEdge(NbrNbrNId, NbrNId);
129 for (
int j = 0; j < NbrNode.
GetOutDeg(); ++j) {
131 if (!NewGraph.
IsNode(NbrNbrNId)) {
int GetNbrNId(const int &NodeN) const
Returns ID of NodeN-th neighboring node.
static PNGraph New()
Static constructor that returns a pointer to the graph. Call: PNGraph Graph = TNGraph::New().
TNodeI GetNI(const int &NId) const
Returns an iterator referring to the node of ID NId in the graph.
int AddNode(int NId=-1)
Adds a node of ID NId to the graph.
TSizeTy Len() const
Returns the number of elements in the vector.
Node iterator. Only forward iteration (operator++) is supported.
PUNGraph GetEgonet(const PUNGraph &Graph, const int CtrNId, int &ArndEdges)
Returns the egonet of node CtrNId as center in undirected graph Graph. And returns number of edges ar...
int AddNode(int NId=-1)
Adds a node of ID NId to the graph.
int GetOutDeg() const
Returns out-degree of the current node (returns same as value GetDeg() since the graph is undirected)...
int AddEdge(const int &SrcNId, const int &DstNId)
Adds an edge from node IDs SrcNId to node DstNId to the graph.
void Reserve(const int &Nodes, const int &Edges)
Reserves memory for a graph of Nodes nodes and Edges edges.
PUNGraph GetSubGraph(const PUNGraph &Graph, const TIntV &NIdV, const bool &RenumberNodes)
Returns an induced subgraph of an undirected graph Graph with NIdV nodes with an optional node renumb...
bool IsNode(const int &NId) const
Tests whether ID NId is a node.
static PUNGraph New()
Static constructor that returns a pointer to the graph. Call: PUNGraph Graph = TUNGraph::New().
int AddKey(const TKey &Key)
int GetDeg() const
Returns degree of the current node, the sum of in-degree and out-degree.
int AddEdge(const int &SrcNId, const int &DstNId)
Adds an edge between node IDs SrcNId and DstNId to the graph.
int GetOutNId(const int &NodeN) const
Returns ID of NodeN-th out-node (the node the current node points to).
int GetOutDeg() const
Returns out-degree of the current node.
int GetInDeg() const
Returns in-degree of the current node (returns same as value GetDeg() since the graph is undirected)...
Node iterator. Only forward iteration (operator++) is supported.
void Reserve(const int &Nodes, const int &Edges)
Reserves memory for a graph of Nodes nodes and Edges edges.
bool IsNode(const int &NId) const
Tests whether ID NId is a node.
int GetInDeg() const
Returns in-degree of the current node.
bool IsEdge(const int &SrcNId, const int &DstNId) const
Tests whether an edge between node IDs SrcNId and DstNId exists in the graph.
int GetInNId(const int &NodeN) const
Returns ID of NodeN-th in-node (the node pointing to the current node).
int GetOutNId(const int &NodeN) const
Returns ID of NodeN-th out-node (the node the current node points to).
int GetInNId(const int &NodeN) const
Returns ID of NodeN-th in-node (the node pointing to the current node).