int TUNGraph::AddNode(int NId) { if (NId == -1) { NId = MxNId; MxNId++; } else if (IsNode(NId)) { return NId; } // already a node else { MxNId = TMath::Mx(NId+1, MxNId()); } NodeH.AddDat(NId, TNode(NId)); return NId; }
// add a node with a list of neighbors // (use TNGraphMP::IsOk to check whether the graph is consistent) void TNEANetMP::AddNodeWithEdges(const TInt& NId, TIntV& InEIdV, TIntV& OutEIdV) { int NodeIdx = abs((NId.GetPrimHashCd()) % Reserved()); int NodeKeyId = NodeH.AddKey13(NodeIdx, NId); MxNId = TMath::Mx(NId+1, MxNId()); NodeH[NodeKeyId] = TNode(NId); NodeH[NodeKeyId].InEIdV.MoveFrom(InEIdV); NodeH[NodeKeyId].OutEIdV.MoveFrom(OutEIdV); }
///////////////////////////////////////////////// // Bipartite graph int TBPGraph::AddNode(int NId, const bool& LeftNode) { if (NId == -1) { NId = MxNId; MxNId++; } else if (IsLNode(NId)) { IAssertR(LeftNode, TStr::Fmt("Node with id %s already exists on the 'left'.", NId)); return NId; } else if (IsRNode(NId)) { IAssertR(! LeftNode, TStr::Fmt("Node with id %s already exists on the 'right'.", NId)); return NId; } else { MxNId = TMath::Mx(NId+1, MxNId()); } if (LeftNode) { LeftH.AddDat(NId, TNode(NId)); } else { RightH.AddDat(NId, TNode(NId)); } return NId; }
// add a node from a vector pool // (use TUNGraph::IsOk to check whether the graph is consistent) int TUNGraph::AddNode(const int& NId, const TVecPool<TInt>& Pool, const int& NIdVId) { IAssert(NId != -1); IAssertR(! IsNode(NId), TStr::Fmt("NodeId %d already exists", NId)); MxNId = TMath::Mx(NId+1, MxNId()); TNode& Node = NodeH.AddDat(NId); Node.Id = NId; Node.NIdV.GenExt(Pool.GetValVPt(NIdVId), Pool.GetVLen(NIdVId)); Node.NIdV.Sort(); return NId; }
// add a node with a list of neighbors // (use TUNGraph::IsOk to check whether the graph is consistent) int TUNGraph::AddNode(const int& NId, const TIntV& NbhNIdV) { IAssert(NId != -1); IAssertR(! IsNode(NId), TStr::Fmt("NodeId %d already exists", NId)); MxNId = TMath::Mx(NId+1, MxNId()); TNode& Node = NodeH.AddDat(NId); Node.Id = NId; Node.NIdV = NbhNIdV; Node.NIdV.Sort(); return NId; }
// Add a node of ID NId to the graph. int TUNGraph::AddNode(int NId) { if (NId == -1) { NId = MxNId; MxNId++; } else { IAssertR(!IsNode(NId), TStr::Fmt("NodeId %d already exists", NId)); MxNId = TMath::Mx(NId+1, MxNId()); } NodeH.AddDat(NId, TNode(NId)); return NId; }
// Add a node of ID NId to the graph and create edges to all nodes in vector NbrNIdV. int TUNGraph::AddNode(const int& NId, const TIntV& NbrNIdV) { int NewNId; if (NId == -1) { NewNId = MxNId; MxNId++; } else { IAssertR(!IsNode(NId), TStr::Fmt("NodeId %d already exists", NId)); NewNId = NId; MxNId = TMath::Mx(NewNId+1, MxNId()); } TNode& Node = NodeH.AddDat(NewNId); Node.Id = NewNId; Node.NIdV = NbrNIdV; Node.NIdV.Sort(); return NewNId; }
// Add a node of ID NId to the graph and create edges to all nodes in the vector NIdVId in the vector pool Pool). int TUNGraph::AddNode(const int& NId, const TVecPool<TInt>& Pool, const int& NIdVId) { int NewNId; if (NId == -1) { NewNId = MxNId; MxNId++; } else { IAssertR(!IsNode(NId), TStr::Fmt("NodeId %d already exists", NId)); NewNId = NId; MxNId = TMath::Mx(NewNId+1, MxNId()); } TNode& Node = NodeH.AddDat(NewNId); Node.Id = NewNId; Node.NIdV.GenExt(Pool.GetValVPt(NIdVId), Pool.GetVLen(NIdVId)); Node.NIdV.Sort(); NEdges += Node.GetDeg(); return NewNId; }
int TNEANetMP::AddNode(int NId) { int i; if (NId == -1) { NId = MxNId; MxNId++; } else { IAssertR(!IsNode(NId), TStr::Fmt("NodeId %d already exists", NId)); MxNId = TMath::Mx(NId+1, MxNId()); } // update attribute columns NodeH.AddDat(NId, TNode(NId)); for (i = 0; i < VecOfIntVecsN.Len(); i++) { TVec<TInt>& IntVec = VecOfIntVecsN[i]; IntVec.Ins(NodeH.GetKeyId(NId), TInt::Mn); } TVec<TStr> DefIntVec = TVec<TStr>(); IntDefaultsN.GetKeyV(DefIntVec); for (i = 0; i < DefIntVec.Len(); i++) { TStr attr = DefIntVec[i]; TVec<TInt>& IntVec = VecOfIntVecsN[KeyToIndexTypeN.GetDat(DefIntVec[i]).Val2]; IntVec[NodeH.GetKeyId(NId)] = GetIntAttrDefaultN(attr); } for (i = 0; i < VecOfStrVecsN.Len(); i++) { TVec<TStr>& StrVec = VecOfStrVecsN[i]; StrVec.Ins(NodeH.GetKeyId(NId), TStr::GetNullStr()); } TVec<TStr> DefStrVec = TVec<TStr>(); IntDefaultsN.GetKeyV(DefStrVec); for (i = 0; i < DefStrVec.Len(); i++) { TStr attr = DefStrVec[i]; TVec<TStr>& StrVec = VecOfStrVecsN[KeyToIndexTypeN.GetDat(DefStrVec[i]).Val2]; StrVec[NodeH.GetKeyId(NId)] = GetStrAttrDefaultN(attr); } for (i = 0; i < VecOfFltVecsN.Len(); i++) { TVec<TFlt>& FltVec = VecOfFltVecsN[i]; FltVec.Ins(NodeH.GetKeyId(NId), TFlt::Mn); } TVec<TStr> DefFltVec = TVec<TStr>(); FltDefaultsN.GetKeyV(DefFltVec); for (i = 0; i < DefFltVec.Len(); i++) { TStr attr = DefFltVec[i]; TVec<TFlt>& FltVec = VecOfFltVecsN[KeyToIndexTypeN.GetDat(DefFltVec[i]).Val2]; FltVec[NodeH.GetKeyId(NId)] = GetFltAttrDefaultN(attr); } return NId; }
// Add a node of ID NId to the graph and create edges to all nodes in vector NbrNIdV. int TUNGraph::AddNode(const int& NId, const TIntV& NbrNIdV) { int NewNId; if (NId == -1) { NewNId = MxNId; MxNId++; } else { IAssertR(! IsNode(NId), TStr::Fmt("NodeId %d already exists", NId)); NewNId = NId; MxNId = TMath::Mx(NewNId+1, MxNId()); } TNode& Node = NodeH.AddDat(NewNId); Node.Id = NewNId; Node.NIdV = NbrNIdV; Node.NIdV.Sort(); NEdges += Node.GetDeg(); for (int i = 0; i < NbrNIdV.Len(); i++) { GetNode(NbrNIdV[i]).NIdV.AddSorted(NewNId); } return NewNId; }
int TNGraph::AddNodeUnchecked(int NId) { if (IsNode(NId)) { return NId;} MxNId = TMath::Mx(NId+1, MxNId()); NodeH.AddDat(NId, TNode(NId)); return NId; }