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];
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];
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];
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];
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) {
120 for (
int i = 0; i < CtrNode.
GetDeg(); ++i) {
123 for (
int j = 0; j < NbrNode.
GetInDeg(); ++j) {
124 int NbrNbrNId = NbrNode.
GetInNId(j);
125 if (NewGraph.
IsNode(NbrNbrNId)) {
126 NewGraph.
AddEdge(NbrNbrNId, NbrNId);
131 for (
int j = 0; j < NbrNode.
GetOutDeg(); ++j) {
133 if (NewGraph.
IsNode(NbrNbrNId)) {
134 NewGraph.
AddEdge(NbrNId, NbrNbrNId);
144 Graph2->AddNode(NId);
148 Graph1->IntAttrNameNI(NId, IntAttrNames);
149 Graph1->IntAttrValueNI(NId, IntAttrValues);
150 for (
int i = 0; i < IntAttrNames.
Len(); i++) {
151 Graph2->AddIntAttrDatN(NId, IntAttrValues[i], IntAttrNames[i]);
156 Graph1->FltAttrNameNI(NId, FltAttrNames);
157 Graph1->FltAttrValueNI(NId, FltAttrValues);
158 for (
int i = 0; i < FltAttrNames.
Len(); i++) {
159 Graph2->AddFltAttrDatN(NId, FltAttrValues[i], FltAttrNames[i]);
164 Graph1->StrAttrNameNI(NId, StrAttrNames);
165 Graph1->StrAttrValueNI(NId, StrAttrValues);
166 for (
int i = 0; i < StrAttrNames.
Len(); i++) {
167 Graph2->AddStrAttrDatN(NId, StrAttrValues[i], StrAttrNames[i]);
172 Graph1->IntVAttrNameNI(NId, IntVAttrNames);
173 Graph1->IntVAttrValueNI(NId, IntVAttrValues);
174 for (
int i = 0; i < IntVAttrNames.
Len(); i++) {
175 Graph2->AddIntVAttrDatN(NId, IntVAttrValues[i], IntVAttrNames[i]);
186 Graph1->IntAttrNameEI(EId, IntAttrNames);
187 Graph1->IntAttrValueEI(EId, IntAttrValues);
188 for (
int i = 0; i < IntAttrNames.
Len(); i++) {
189 Graph2->AddIntAttrDatE(EId, IntAttrValues[i], IntAttrNames[i]);
194 Graph1->FltAttrNameEI(EId, FltAttrNames);
195 Graph1->FltAttrValueEI(EId, FltAttrValues);
196 for (
int i = 0; i < FltAttrNames.
Len(); i++) {
197 Graph2->AddFltAttrDatE(EId, FltAttrValues[i], FltAttrNames[i]);
202 Graph1->StrAttrNameEI(EId, StrAttrNames);
203 Graph1->StrAttrValueEI(EId, StrAttrValues);
204 for (
int i = 0; i < StrAttrNames.
Len(); i++) {
205 Graph2->AddStrAttrDatE(EId, StrAttrValues[i], StrAttrNames[i]);
210 Graph1->IntVAttrNameEI(EId, IntVAttrNames);
211 Graph1->IntVAttrValueEI(EId, IntVAttrValues);
212 for (
int i = 0; i < IntVAttrNames.
Len(); i++) {
213 Graph2->AddIntVAttrDatE(EId, IntVAttrValues[i], IntVAttrNames[i]);
218 Graph2->AddEdge(NId, NbrId);
219 const int EId = Graph2->GetEId(NId, NbrId);
223 Graph1->IntAttrNameEI(EId, IntAttrNames);
224 Graph1->IntAttrValueEI(EId, IntAttrValues);
225 for (
int i = 0; i < IntAttrNames.
Len(); i++) {
226 Graph2->AddIntAttrDatE(EId, IntAttrValues[i], IntAttrNames[i]);
231 Graph1->FltAttrNameEI(EId, FltAttrNames);
232 Graph1->FltAttrValueEI(EId, FltAttrValues);
233 for (
int i = 0; i < FltAttrNames.
Len(); i++) {
234 Graph2->AddFltAttrDatE(EId, FltAttrValues[i], FltAttrNames[i]);
239 Graph1->StrAttrNameEI(EId, StrAttrNames);
240 Graph1->StrAttrValueEI(EId, StrAttrValues);
241 for (
int i = 0; i < StrAttrNames.
Len(); i++) {
242 Graph2->AddStrAttrDatE(EId, StrAttrValues[i], StrAttrNames[i]);
247 Graph1->IntVAttrNameEI(EId, IntVAttrNames);
248 Graph1->IntVAttrValueEI(EId, IntVAttrValues);
249 for (
int i = 0; i < IntVAttrNames.
Len(); i++) {
250 Graph2->AddIntVAttrDatE(EId, IntVAttrValues[i], IntVAttrNames[i]);
256 TNEANet &NewGraph = *NewGraphPt;
263 for (
int r = 0; r < Radius; ++r) {
264 while (!Queue1.
Empty()) {
265 const int NId = Queue1.
Top();
268 for (
int i = 0; i < Node.
GetInDeg(); ++i) {
270 if (!NewGraph.
IsNode(InNId)) {
275 if (!NewGraph.
IsEdge(InEId)) {
279 for (
int i = 0; i < Node.
GetOutDeg(); ++i) {
281 if (!NewGraph.
IsNode(OutNId)) {
286 if (!NewGraph.
IsEdge(OutEId)) {
290 for (
int i = 0; i < Node.
GetInDeg(); ++i) {
293 for (
int j = 0; j < InNode.
GetInDeg(); ++j) {
295 if (NewGraph.
IsNode(NbrInNId)) {
296 const int NbrInEId = InNode.
GetInEId(j);
297 if (!NewGraph.
IsEdge(NbrInEId)) {
302 for (
int j = 0; j < InNode.
GetOutDeg(); ++j) {
304 if (NewGraph.
IsNode(NbrOutNId)) {
305 const int NbrOutEId = InNode.
GetOutEId(j);
306 if (!NewGraph.
IsEdge(NbrOutEId)) {
312 for (
int i = 0; i < Node.
GetOutDeg(); ++i) {
315 for (
int j = 0; j < OutNode.
GetInDeg(); ++j) {
317 if (NewGraph.
IsNode(NbrInNId)) {
318 const int NbrInEId = OutNode.
GetInEId(j);
319 if (!NewGraph.
IsEdge(NbrInEId)) {
324 for (
int j = 0; j < OutNode.
GetOutDeg(); ++j) {
326 if (NewGraph.
IsNode(NbrOutNId)) {
327 const int NbrOutEId = OutNode.
GetOutEId(j);
328 if (!NewGraph.
IsEdge(NbrOutEId)) {
335 tempSwapQueue = Queue1;
337 Queue2 = tempSwapQueue;
344 TNEANet &NewGraph = *NewGraphPt;
351 for (
int r = 0; r < Radius; ++r) {
352 while (!Queue1.
Empty()) {
353 const int NId = Queue1.
Top();
356 for (
int i = 0; i < Node.
GetInDeg(); ++i) {
358 if (!NewGraph.
IsNode(InNId)) {
363 if (!NewGraph.
IsEdge(InEId)) {
367 for (
int i = 0; i < Node.
GetInDeg(); ++i) {
370 for (
int j = 0; j < InNode.
GetInDeg(); ++j) {
372 if (NewGraph.
IsNode(NbrInNId)) {
373 const int NbrInEId = InNode.
GetInEId(j);
374 if (!NewGraph.
IsEdge(NbrInEId)) {
379 for (
int j = 0; j < InNode.
GetOutDeg(); ++j) {
381 if (NewGraph.
IsNode(NbrOutNId)) {
382 const int NbrOutEId = InNode.
GetOutEId(j);
383 if (!NewGraph.
IsEdge(NbrOutEId)) {
390 tempSwapQueue = Queue1;
392 Queue2 = tempSwapQueue;
399 TNEANet &NewGraph = *NewGraphPt;
406 for (
int r = 0; r < Radius; ++r) {
407 while (!Queue1.
Empty()) {
408 const int NId = Queue1.
Top();
411 for (
int i = 0; i < Node.
GetOutDeg(); ++i) {
413 if (!NewGraph.
IsNode(OutNId)) {
418 if (!NewGraph.
IsEdge(OutEId)) {
422 for (
int i = 0; i < Node.
GetOutDeg(); ++i) {
425 for (
int j = 0; j < OutNode.
GetInDeg(); ++j) {
427 if (NewGraph.
IsNode(NbrInNId)) {
428 const int InEId = OutNode.
GetInEId(j);
429 if (!NewGraph.
IsEdge(InEId)) {
434 for (
int j = 0; j < OutNode.
GetOutDeg(); ++j) {
436 if (NewGraph.
IsNode(NbrOutNId)) {
438 if (!NewGraph.
IsEdge(OutEId)) {
445 tempSwapQueue = Queue1;
447 Queue2 = tempSwapQueue;
455 TNEANet& NewGraph = *NewGraphPt;
463 bool usePercent = (percent != -1.0);
464 int numSamples = MaxNum;
465 for (
int r = 0; r < Radius; ++r) {
466 while (!Queue1.
Empty()) {
467 const int NId = Queue1.
Top();
470 sampleQueue.
Clr(
true);
471 for (
int i = 0; i < Node.
GetInDeg(); ++i) {
473 if (!NewGraph.
IsNode(InNId)) {
474 sampleQueue.
Push(InNId);
478 numSamples = (int) (percent * sampleQueue.
Len());
480 sampleQueue.
Sample(numSamples);
481 for (
int i = 0; i < numSamples && !sampleQueue.
Empty(); ++i) {
482 const int InNId = sampleQueue.
Top();
484 if (!NewGraph.
IsNode(InNId)) {
488 if (!NewGraph.
IsEdge(InNId, NId)) {
492 for (
int i = 0; i < Node.
GetInDeg(); ++i) {
494 if (!NewGraph.
IsNode(InNId)) {
continue; }
496 for (
int j = 0; j < InNode.
GetInDeg(); ++j) {
498 if (NewGraph.
IsNode(NbrInNId)) {
499 if (!NewGraph.
IsEdge(NbrInNId, InNId)) {
504 for (
int j = 0; j < InNode.
GetOutDeg(); ++j) {
506 if (NewGraph.
IsNode(NbrOutNId)) {
507 if (!NewGraph.
IsEdge(InNId, NbrOutNId)) {
514 tempSwapQueue = Queue1;
516 Queue2 = tempSwapQueue;
522 for (PNEANet::TObj::TNodeI NI = SrcGraph->BegNI(); NI < SrcGraph->EndNI(); NI++) {
523 if (! DstGraph->IsNode(NI.GetId())){
527 for (PNEANet::TObj::TEdgeI EI = SrcGraph->BegEI(); EI < SrcGraph->EndEI(); EI++) {
528 if (! DstGraph->IsEdge(EI.GetSrcNId(), EI.GetDstNId()) || ! DstGraph->IsEdge(EI.GetId())){
529 if (! DstGraph->IsEdge(EI.GetId())){
int GetNbrNId(const int &NodeN) const
Returns ID of NodeN-th neighboring node.
Main namespace for all the Snap global entities.
int GetOutNId(const int &EdgeN) const
Returns ID of EdgeN-th out-node (the node the current node points to).
int GetOutDeg() const
Returns out-degree of the current node.
PNEANet GetEgonetAttr(const PNEANet &Graph, const int CtrNId, const int Radius)
Returns the complete egonet of at given radius and copies node and edge attributes.
static PNGraph New()
Static constructor that returns a pointer to the graph. Call: PNGraph Graph = TNGraph::New().
PNEANet GetInEgonetSubAttr(const PNEANet &Graph, const int CtrNId, const int Radius, const int MaxNum, const float percent)
Returns the randomly sampled egonet with nodes sampled based on percentage or raw number...
int GetInNId(const int &EdgeN) const
Returns ID of EdgeN-th in-node (the node pointing to the current node).
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.
int GetOutEId(const int &EdgeN) const
Returns ID of EdgeN-th out-edge.
bool IsEdge(const int &EId) const
Tests whether an edge with edge ID EId exists in the graph.
int AddNode(int NId=-1)
Adds a node of ID NId to the graph.
Node iterator. Only forward iteration (operator++) is supported.
PNEANet GetGraphUnionAttr(PNEANet &DstGraph, const PNEANet &SrcGraph)
int GetInEId(const int &EdgeN) const
Returns ID of EdgeN-th in-edge.
void Pop()
Removes the first element from the queue.
bool Empty() const
Tests whether the queue is empty (contains no elements).
PNEANet GetInEgonetAttr(const PNEANet &Graph, const int CtrNId, const int Radius)
Returns the in-egonet of at given radius and copies node and edge attributes.
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 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...
TNodeI GetNI(const int &NId) const
Returns an iterator referring to the node of ID NId in the graph.
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 GetInDeg() const
Returns in-degree of the current node.
int Len() const
Returns the number of elements in the queue.
int GetDeg() const
Returns degree of the current node, the sum of in-degree and out-degree.
Directed multigraph with node edge attributes.
int AddEdge(const int &SrcNId, const int &DstNId)
Adds an edge between node IDs SrcNId and DstNId to the graph.
void Clr(const bool &DoDel=true)
Deletes all elements from the queue.
Edge iterator. Only forward iteration (operator++) is supported.
int GetOutNId(const int &NodeN) const
Returns ID of NodeN-th out-node (the node the current node points to).
void Sample(const int num, TRnd &Rnd=TInt::Rnd)
int GetOutDeg() const
Returns out-degree of the current node.
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...
void Push(const TVal &Val)
Adds an element at the end of the queue.
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 AddNodeWithAttributes(const PNEANet &Graph1, PNEANet &Graph2, const int NId)
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.
const TVal & Top() const
Returns the value of the first element in the queue, but does not remove the element.
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).
static PNEANet New()
Static cons returns pointer to graph. Ex: PNEANet Graph=TNEANet::New().
int GetOutNId(const int &NodeN) const
Returns ID of NodeN-th out-node (the node the current node points to).
void AddEdgeWithAttributes(const PNEANet &Graph1, PNEANet &Graph2, const int EId)
int GetInNId(const int &NodeN) const
Returns ID of NodeN-th in-node (the node pointing to the current node).
Vector is a sequence TVal objects representing an array that can change in size.
PNEANet GetOutEgonetAttr(const PNEANet &Graph, const int CtrNId, const int Radius)
Returns the out-egonet of at given radius and copies node and edge attributes.