SNAP Library 2.2, Developer Reference  2014-03-11 19:15:55
SNAP, a general purpose, high performance system for analysis and manipulation of large networks
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
TNodeNet< TNodeData > Class Template Reference

Node Network (directed graph, TNGraph with data on nodes only). More...

#include <network.h>

Collaboration diagram for TNodeNet< TNodeData >:

List of all members.

Classes

class  TEdgeI
 Edge iterator. Only forward iteration (operator++) is supported. More...
class  TNode
class  TNodeI
 Node iterator. Only forward iteration (operator++) is supported. More...

Public Types

typedef TNodeData TNodeDat
typedef TNodeNet< TNodeData > TNet
typedef TPt< TNetPNet

Public Member Functions

 TNodeNet ()
 TNodeNet (const int &Nodes, const int &Edges)
 Constructor that reserves enough memory for a network of Nodes nodes and Edges edges.
 TNodeNet (const TNodeNet &NodeNet)
 TNodeNet (TSIn &SIn)
 Constructor that loads the network from a (binary) stream SIn.
virtual ~TNodeNet ()
virtual void Save (TSOut &SOut) const
 Saves the network to a (binary) stream SOut.
bool HasFlag (const TGraphFlag &Flag) const
 Allows for run-time checking the type of the network (see the TGraphFlag for flags).
TNodeNetoperator= (const TNodeNet &NodeNet)
int GetNodes () const
 Returns the number of nodes in the network.
int AddNode (int NId=-1)
 Adds a node of ID NId to the network.
int AddNode (int NId, const TNodeData &NodeDat)
 Adds a node of ID NId and node data NodeDat to the network.
int AddNode (const TNodeI &NodeId)
 Adds a node NodeId and its node data to the network.
void DelNode (const int &NId)
 Deletes node of ID NId from the network.
void DelNode (const TNode &NodeI)
 Deletes node of ID NodeI.GetId() from the network.
bool IsNode (const int &NId) const
 Tests whether ID NId is a node.
TNodeI BegNI () const
 Returns an iterator referring to the first node in the network.
TNodeI EndNI () const
 Returns an iterator referring to the past-the-end node in the network.
TNodeI GetNI (const int &NId) const
 Returns an iterator referring to the node of ID NId in the network.
const TNodeGetNode (const int &NId) const
 Returns node element for the node of ID NId in the network.
void SetNDat (const int &NId, const TNodeData &NodeDat)
 Sets node data for the node of ID NId in the network.
TNodeData & GetNDat (const int &NId)
 Returns node data for the node of ID NId in the network.
const TNodeData & GetNDat (const int &NId) const
 Returns node data for the node of ID NId in the network.
int GetMxNId () const
 Returns an ID that is larger than any node ID in the network.
int GetEdges () const
 Returns the number of edges in the network.
int AddEdge (const int &SrcNId, const int &DstNId)
 Adds an edge from node IDs SrcNId to node DstNId to the network.
int AddEdge (const TEdgeI &EdgeI)
 Adds an edge from EdgeI.GetSrcNId() to EdgeI.GetDstNId() to the network.
void DelEdge (const int &SrcNId, const int &DstNId, const bool &IsDir=true)
 Deletes an edge from node IDs SrcNId to DstNId from the network.
bool IsEdge (const int &SrcNId, const int &DstNId, const bool &IsDir=true) const
 Tests whether an edge from node IDs SrcNId to DstNId exists in the network.
TEdgeI BegEI () const
 Returns an iterator referring to the first edge in the network.
TEdgeI EndEI () const
 Returns an iterator referring to the past-the-end edge in the network.
TEdgeI GetEI (const int &EId) const
 Not supported/implemented!
TEdgeI GetEI (const int &SrcNId, const int &DstNId) const
 Returns an iterator referring to edge (SrcNId, DstNId) in the network.
int GetRndNId (TRnd &Rnd=TInt::Rnd)
 Returns an ID of a random node in the network.
TNodeI GetRndNI (TRnd &Rnd=TInt::Rnd)
 Returns an interator referring to a random node in the network.
void GetNIdV (TIntV &NIdV) const
 Gets a vector IDs of all nodes in the network.
bool Empty () const
 Tests whether the network is empty (has zero nodes).
void Clr (const bool &DoDel=true, const bool &ResetDat=true)
 Deletes all nodes and edges from the network.
void Reserve (const int &Nodes, const int &Edges)
 Reserves memory for a network of Nodes nodes and Edges edges.
void SortNIdById (const bool &Asc=true)
 Sorts nodes by node IDs.
void SortNIdByDat (const bool &Asc=true)
 Sorts nodes by node data.
void Defrag (const bool &OnlyNodeLinks=false)
 Defragments the network.
bool IsOk (const bool &ThrowExcept=true) const
 Checks the network data structure for internal consistency.

Static Public Member Functions

static PNet New ()
 Static constructor that returns a pointer to the network. Call: TPt <TNodeNet<TNodeData> > Net = TNodeNet<TNodeData>::New().
static PNet Load (TSIn &SIn)
 Static constructor that loads the network from a stream SIn and returns a pointer to it.

Protected Member Functions

TNodeGetNode (const int &NId)

Protected Attributes

TCRef CRef
TInt MxNId
THash< TInt, TNodeNodeH

Friends

class TPt< TNodeNet< TNodeData > >

Detailed Description

template<class TNodeData>
class TNodeNet< TNodeData >

Node Network (directed graph, TNGraph with data on nodes only).

Definition at line 14 of file network.h.


Member Typedef Documentation

template<class TNodeData>
typedef TPt<TNet> TNodeNet< TNodeData >::PNet

Reimplemented in TTimeNet.

Definition at line 18 of file network.h.

template<class TNodeData>
typedef TNodeNet<TNodeData> TNodeNet< TNodeData >::TNet

Reimplemented in TTimeNet.

Definition at line 17 of file network.h.

template<class TNodeData>
typedef TNodeData TNodeNet< TNodeData >::TNodeDat

Definition at line 16 of file network.h.


Constructor & Destructor Documentation

template<class TNodeData>
TNodeNet< TNodeData >::TNodeNet ( ) [inline]

Definition at line 138 of file network.h.

Referenced by TNodeNet< TSecTm >::Load(), and TNodeNet< TSecTm >::New().

: CRef(), MxNId(0), NodeH() { }

Here is the caller graph for this function:

template<class TNodeData>
TNodeNet< TNodeData >::TNodeNet ( const int &  Nodes,
const int &  Edges 
) [inline, explicit]

Constructor that reserves enough memory for a network of Nodes nodes and Edges edges.

Definition at line 140 of file network.h.

: MxNId(0) { Reserve(Nodes, Edges); }
template<class TNodeData>
TNodeNet< TNodeData >::TNodeNet ( const TNodeNet< TNodeData > &  NodeNet) [inline]

Definition at line 141 of file network.h.

: MxNId(NodeNet.MxNId), NodeH(NodeNet.NodeH) { }
template<class TNodeData>
TNodeNet< TNodeData >::TNodeNet ( TSIn SIn) [inline]

Constructor that loads the network from a (binary) stream SIn.

Definition at line 143 of file network.h.

: MxNId(SIn), NodeH(SIn) { }
template<class TNodeData>
virtual TNodeNet< TNodeData >::~TNodeNet ( ) [inline, virtual]

Definition at line 144 of file network.h.

{ }

Member Function Documentation

template<class TNodeData >
int TNodeNet< TNodeData >::AddEdge ( const int &  SrcNId,
const int &  DstNId 
)

Adds an edge from node IDs SrcNId to node DstNId to the network.

If the edge already exists return -2. If the edge was successfully added return -1. Normally the function should return an ID of the edge added but since edges in TNodeNet have no IDs we return -1. Function aborts if SrcNId or DstNId are not nodes in the network.

Definition at line 331 of file network.h.

References TStr::Fmt(), and IAssertR.

Referenced by TTimeNet::GetSubGraph(), TTimeNet::LoadAmazon(), TTimeNet::LoadArxiv(), TTimeNet::LoadBipartite(), and TTimeNet::LoadPatents().

                                                                     {
  IAssertR(IsNode(SrcNId) && IsNode(DstNId), TStr::Fmt("%d or %d not a node.", SrcNId, DstNId).CStr());
  if (IsEdge(SrcNId, DstNId)) { return -2; }
  GetNode(SrcNId).OutNIdV.AddSorted(DstNId);
  GetNode(DstNId).InNIdV.AddSorted(SrcNId);
  return -1; // edge id
}

Here is the call graph for this function:

Here is the caller graph for this function:

template<class TNodeData>
int TNodeNet< TNodeData >::AddEdge ( const TEdgeI EdgeI) [inline]

Adds an edge from EdgeI.GetSrcNId() to EdgeI.GetDstNId() to the network.

Definition at line 209 of file network.h.

Referenced by TNodeNet< TSecTm >::AddEdge().

{ return AddEdge(EdgeI.GetSrcNId(), EdgeI.GetDstNId()); }

Here is the caller graph for this function:

template<class TNodeData >
int TNodeNet< TNodeData >::AddNode ( int  NId = -1)

Adds a node of ID NId to the network.

Returns the ID of the node being added. If NId is -1, node ID is automatically assigned. Aborts, if a node with ID NId already exists.

Definition at line 273 of file network.h.

References TStr::Fmt(), IAssertR, and TMath::Mx().

Referenced by TTimeNet::GetSubGraph(), TTimeNet::LoadAmazon(), TTimeNet::LoadArxiv(), TTimeNet::LoadBipartite(), and TTimeNet::LoadPatents().

                                        {
  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;
}

Here is the call graph for this function:

Here is the caller graph for this function:

template<class TNodeData>
int TNodeNet< TNodeData >::AddNode ( int  NId,
const TNodeData &  NodeDat 
)

Adds a node of ID NId and node data NodeDat to the network.

Returns the ID of the node being added. If NId is -1, node ID is automatically assigned. Aborts, if a node with ID NId already exists.

Definition at line 285 of file network.h.

References TStr::Fmt(), IAssertR, and TMath::Mx().

                                                                  {
  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, NodeDat));
  return NId;
}

Here is the call graph for this function:

template<class TNodeData>
int TNodeNet< TNodeData >::AddNode ( const TNodeI NodeId) [inline]

Adds a node NodeId and its node data to the network.

Definition at line 171 of file network.h.

Referenced by TNodeNet< TSecTm >::AddNode().

{ return AddNode(NodeId.GetId(), NodeId.GetDat()); }

Here is the caller graph for this function:

template<class TNodeData>
TEdgeI TNodeNet< TNodeData >::BegEI ( ) const [inline]

Returns an iterator referring to the first edge in the network.

Definition at line 219 of file network.h.

{ TNodeI NI=BegNI();  while(NI<EndNI() && NI.GetOutDeg()==0) NI++;  return TEdgeI(NI, EndNI()); }
template<class TNodeData>
TNodeI TNodeNet< TNodeData >::BegNI ( ) const [inline]

Returns an iterator referring to the first node in the network.

Definition at line 181 of file network.h.

Referenced by TNodeNet< TSecTm >::BegEI(), TTimeNet::LoadArxiv(), and TTimeNet::LoadPatents().

{ return TNodeI(NodeH.BegI(), this); }

Here is the caller graph for this function:

template<class TNodeData>
void TNodeNet< TNodeData >::Clr ( const bool &  DoDel = true,
const bool &  ResetDat = true 
) [inline]

Deletes all nodes and edges from the network.

Definition at line 237 of file network.h.

                                                              {
    MxNId = 0;  NodeH.Clr(DoDel, -1, ResetDat); }
template<class TNodeData >
void TNodeNet< TNodeData >::Defrag ( const bool &  OnlyNodeLinks = false)

Defragments the network.

After performing many node and edge insertions and deletions to a network, the network data structure will be fragmented in memory. This function compacts down the network data structure and frees unneeded memory.

Definition at line 373 of file network.h.

References TNodeNet< TNodeData >::TNode::InNIdV, TNodeNet< TNodeData >::TNode::OutNIdV, and TVec< TVal, TSizeTy >::Pack().

Referenced by TTimeNet::GetSubGraph(), TTimeNet::LoadAmazon(), TTimeNet::LoadArxiv(), TTimeNet::LoadBipartite(), and TTimeNet::LoadPatents().

                                                          {
  for (int n = NodeH.FFirstKeyId(); NodeH.FNextKeyId(n); ) {
    TNode& Node = NodeH[n];
    Node.InNIdV.Pack();  Node.OutNIdV.Pack();
  }
  if (! OnlyNodeLinks && ! NodeH.IsKeyIdEqKeyN()) {
    NodeH.Defrag(); }
}

Here is the call graph for this function:

Here is the caller graph for this function:

template<class TNodeData >
void TNodeNet< TNodeData >::DelEdge ( const int &  SrcNId,
const int &  DstNId,
const bool &  IsDir = true 
)

Deletes an edge from node IDs SrcNId to DstNId from the network.

If the edge (SrcNId, DstNId) does not exist in the network function still completes. But the function aborts if SrcNId or DstNId are not nodes in the network.

Definition at line 340 of file network.h.

References TStr::Fmt(), and IAssertR.

                                                                                         {
  IAssertR(IsNode(SrcNId) && IsNode(DstNId), TStr::Fmt("%d or %d not a node.", SrcNId, DstNId).CStr());
  GetNode(SrcNId).OutNIdV.DelIfIn(DstNId);
  GetNode(DstNId).InNIdV.DelIfIn(SrcNId);
  if (! IsDir) {
    GetNode(DstNId).OutNIdV.DelIfIn(SrcNId);
    GetNode(SrcNId).InNIdV.DelIfIn(DstNId);
  }
}

Here is the call graph for this function:

template<class TNodeData >
void TNodeNet< TNodeData >::DelNode ( const int &  NId)

Deletes node of ID NId from the network.

If the node of ID NId does not exist the function aborts.

Definition at line 297 of file network.h.

References TVec< TVal, TSizeTy >::Del(), TNodeNet< TNodeData >::TNode::GetInDeg(), TNodeNet< TNodeData >::TNode::GetInNId(), TNodeNet< TNodeData >::TNode::GetOutDeg(), TNodeNet< TNodeData >::TNode::GetOutNId(), TNodeNet< TNodeData >::TNode::InNIdV, TNodeNet< TNodeData >::TNode::OutNIdV, and TVec< TVal, TSizeTy >::SearchBin().

Referenced by TTimeNet::LoadArxiv(), and TTimeNet::LoadPatents().

                                                {
  { TNode& Node = GetNode(NId);
  for (int e = 0; e < Node.GetOutDeg(); e++) {
  const int nbr = Node.GetOutNId(e);
  if (nbr == NId) { continue; }
    TNode& N = GetNode(nbr);
    int n = N.InNIdV.SearchBin(NId);
    if (n!= -1) { N.InNIdV.Del(n); }
  }
  for (int e = 0; e < Node.GetInDeg(); e++) {
  const int nbr = Node.GetInNId(e);
  if (nbr == NId) { continue; }
    TNode& N = GetNode(nbr);
    int n = N.OutNIdV.SearchBin(NId);
    if (n!= -1) { N.OutNIdV.Del(n); }
  } }
  NodeH.DelKey(NId);
}

Here is the call graph for this function:

Here is the caller graph for this function:

template<class TNodeData>
void TNodeNet< TNodeData >::DelNode ( const TNode NodeI) [inline]

Deletes node of ID NodeI.GetId() from the network.

Definition at line 177 of file network.h.

Referenced by TNodeNet< TSecTm >::DelNode().

{ DelNode(NodeI.GetId()); }

Here is the caller graph for this function:

template<class TNodeData>
bool TNodeNet< TNodeData >::Empty ( ) const [inline]

Tests whether the network is empty (has zero nodes).

Definition at line 235 of file network.h.

{ return GetNodes()==0; }
template<class TNodeData>
TEdgeI TNodeNet< TNodeData >::EndEI ( ) const [inline]

Returns an iterator referring to the past-the-end edge in the network.

Definition at line 221 of file network.h.

{ return TEdgeI(EndNI(), EndNI()); }
template<class TNodeData>
TNodeI TNodeNet< TNodeData >::EndNI ( ) const [inline]

Returns an iterator referring to the past-the-end node in the network.

Definition at line 183 of file network.h.

Referenced by TNodeNet< TSecTm >::BegEI(), TNodeNet< TSecTm >::EndEI(), TTimeNet::LoadArxiv(), and TTimeNet::LoadPatents().

{ return TNodeI(NodeH.EndI(), this); }

Here is the caller graph for this function:

template<class TNodeData >
int TNodeNet< TNodeData >::GetEdges ( ) const

Returns the number of edges in the network.

Definition at line 323 of file network.h.

Referenced by TTimeNet::LoadAmazon(), TTimeNet::LoadArxiv(), TTimeNet::LoadBipartite(), and TTimeNet::LoadPatents().

                                        {
  int edges=0;
  for (int N=NodeH.FFirstKeyId(); NodeH.FNextKeyId(N);) {
    edges+=NodeH[N].GetOutDeg(); }
  return edges;
}

Here is the caller graph for this function:

template<class TNodeData>
TEdgeI TNodeNet< TNodeData >::GetEI ( const int &  EId) const

Not supported/implemented!

template<class TNodeData >
TNodeNet< TNodeData >::TEdgeI TNodeNet< TNodeData >::GetEI ( const int &  SrcNId,
const int &  DstNId 
) const

Returns an iterator referring to edge (SrcNId, DstNId) in the network.

Definition at line 365 of file network.h.

References TNodeNet< TNodeData >::TNodeI::NodeHI.

                                                                                                         {
  const TNodeI SrcNI = GetNI(SrcNId);
  const int NodeN = SrcNI.NodeHI.GetDat().OutNIdV.SearchBin(DstNId);
  if (NodeN == -1) { return EndEI(); }
  return TEdgeI(SrcNI, EndNI(), NodeN);
}
template<class TNodeData>
int TNodeNet< TNodeData >::GetMxNId ( ) const [inline]

Returns an ID that is larger than any node ID in the network.

Definition at line 195 of file network.h.

{ return MxNId; }
template<class TNodeData>
TNodeData& TNodeNet< TNodeData >::GetNDat ( const int &  NId) [inline]

Returns node data for the node of ID NId in the network.

Definition at line 191 of file network.h.

Referenced by TNodeNet< TNodeData >::TNodeI::GetInNDat(), TNodeNet< TNodeData >::TNodeI::GetNbrNDat(), TNodeNet< TNodeData >::TNodeI::GetOutNDat(), TTimeNet::LoadArxiv(), TTimeNet::LoadBipartite(), and TTimeNet::LoadPatents().

{ return NodeH.GetDat(NId).NodeDat; }

Here is the caller graph for this function:

template<class TNodeData>
const TNodeData& TNodeNet< TNodeData >::GetNDat ( const int &  NId) const [inline]

Returns node data for the node of ID NId in the network.

Definition at line 193 of file network.h.

{ return NodeH.GetDat(NId).NodeDat; }
template<class TNodeData>
TNodeI TNodeNet< TNodeData >::GetNI ( const int &  NId) const [inline]

Returns an iterator referring to the node of ID NId in the network.

Definition at line 185 of file network.h.

Referenced by TNodeNet< TSecTm >::GetRndNI().

{ return TNodeI(NodeH.GetI(NId), this); }

Here is the caller graph for this function:

template<class TNodeData >
void TNodeNet< TNodeData >::GetNIdV ( TIntV NIdV) const

Gets a vector IDs of all nodes in the network.

Definition at line 358 of file network.h.

References TVec< TVal, TSizeTy >::Add(), and TVec< TVal, TSizeTy >::Reserve().

                                                   {
  NIdV.Reserve(GetNodes(), 0);
  for (int N=NodeH.FFirstKeyId(); NodeH.FNextKeyId(N); ) {
    NIdV.Add(NodeH.GetKey(N)); }
}

Here is the call graph for this function:

template<class TNodeData>
TNode& TNodeNet< TNodeData >::GetNode ( const int &  NId) [inline, protected]

Definition at line 130 of file network.h.

{ return NodeH.GetDat(NId); }
template<class TNodeData>
const TNode& TNodeNet< TNodeData >::GetNode ( const int &  NId) const [inline]

Returns node element for the node of ID NId in the network.

Definition at line 187 of file network.h.

{ return NodeH.GetDat(NId); }
template<class TNodeData>
int TNodeNet< TNodeData >::GetNodes ( ) const [inline]

Returns the number of nodes in the network.

Definition at line 157 of file network.h.

Referenced by TNodeNet< TSecTm >::Empty(), TTimeNet::LoadAmazon(), TTimeNet::LoadArxiv(), TTimeNet::LoadBipartite(), and TTimeNet::LoadPatents().

{ return NodeH.Len(); }

Here is the caller graph for this function:

template<class TNodeData>
TNodeI TNodeNet< TNodeData >::GetRndNI ( TRnd Rnd = TInt::Rnd) [inline]

Returns an interator referring to a random node in the network.

Definition at line 230 of file network.h.

{ return GetNI(GetRndNId(Rnd)); }
template<class TNodeData>
int TNodeNet< TNodeData >::GetRndNId ( TRnd Rnd = TInt::Rnd) [inline]

Returns an ID of a random node in the network.

Definition at line 228 of file network.h.

Referenced by TNodeNet< TSecTm >::GetRndNI().

{ return NodeH.GetKey(NodeH.GetRndKeyId(Rnd, 0.8)); }

Here is the caller graph for this function:

template<class TNodeData >
bool TNodeNet< TNodeData >::HasFlag ( const TGraphFlag Flag) const

Allows for run-time checking the type of the network (see the TGraphFlag for flags).

Definition at line 268 of file network.h.

References HasGraphFlag.

                                                              {
  return HasGraphFlag(typename TNet, Flag);
}
template<class TNodeData >
bool TNodeNet< TNodeData >::IsEdge ( const int &  SrcNId,
const int &  DstNId,
const bool &  IsDir = true 
) const

Tests whether an edge from node IDs SrcNId to DstNId exists in the network.

Definition at line 351 of file network.h.

Referenced by TTimeNet::LoadAmazon(), TTimeNet::LoadArxiv(), TTimeNet::LoadBipartite(), and TTimeNet::LoadPatents().

                                                                                              {
  if (! IsNode(SrcNId) || ! IsNode(DstNId)) { return false; }
  if (IsDir) { return GetNode(SrcNId).IsOutNId(DstNId); }
  else { return GetNode(SrcNId).IsOutNId(DstNId) || GetNode(DstNId).IsOutNId(SrcNId); }
}

Here is the caller graph for this function:

template<class TNodeData>
bool TNodeNet< TNodeData >::IsNode ( const int &  NId) const [inline]

Tests whether ID NId is a node.

Definition at line 179 of file network.h.

Referenced by TTimeNet::GetSubGraph(), TTimeNet::LoadAmazon(), TTimeNet::LoadArxiv(), TTimeNet::LoadBipartite(), and TTimeNet::LoadPatents().

{ return NodeH.IsKey(NId); }

Here is the caller graph for this function:

template<class TNodeData >
bool TNodeNet< TNodeData >::IsOk ( const bool &  ThrowExcept = true) const

Checks the network data structure for internal consistency.

For each node in the network check that its neighbors are also nodes in the network.

Definition at line 383 of file network.h.

References TStr::CStr(), EAssertR, ErrNotify(), TStr::Fmt(), TNodeNet< TNodeData >::TNode::GetId(), TNodeNet< TNodeData >::TNode::GetInDeg(), TNodeNet< TNodeData >::TNode::GetInNId(), TNodeNet< TNodeData >::TNode::GetOutDeg(), TNodeNet< TNodeData >::TNode::GetOutNId(), TNodeNet< TNodeData >::TNode::InNIdV, TVec< TVal, TSizeTy >::IsSorted(), and TNodeNet< TNodeData >::TNode::OutNIdV.

                                                            {
  bool RetVal = true;
  for (int N = NodeH.FFirstKeyId(); NodeH.FNextKeyId(N); ) {
    const TNode& Node = NodeH[N];
    if (! Node.OutNIdV.IsSorted()) {
      const TStr Msg = TStr::Fmt("Out-neighbor list of node %d is not sorted.", Node.GetId());
      if (ThrowExcept) { EAssertR(false, Msg); } else { ErrNotify(Msg.CStr()); } RetVal=false;
    }
    if (! Node.InNIdV.IsSorted()) {
      const TStr Msg = TStr::Fmt("In-neighbor list of node %d is not sorted.", Node.GetId());
      if (ThrowExcept) { EAssertR(false, Msg); } else { ErrNotify(Msg.CStr()); } RetVal=false;
    }
    // check out-edges
    int prevNId = -1;
    for (int e = 0; e < Node.GetOutDeg(); e++) {
      if (! IsNode(Node.GetOutNId(e))) {
        const TStr Msg = TStr::Fmt("Out-edge %d --> %d: node %d does not exist.",
          Node.GetId(), Node.GetOutNId(e), Node.GetOutNId(e));
        if (ThrowExcept) { EAssertR(false, Msg); } else { ErrNotify(Msg.CStr()); } RetVal=false;
      }
      if (e > 0 && prevNId == Node.GetOutNId(e)) {
        const TStr Msg = TStr::Fmt("Node %d has duplidate out-edge %d --> %d.",
          Node.GetId(), Node.GetId(), Node.GetOutNId(e));
        if (ThrowExcept) { EAssertR(false, Msg); } else { ErrNotify(Msg.CStr()); } RetVal=false;
      }
      prevNId = Node.GetOutNId(e);
    }
    // check in-edges
    prevNId = -1;
    for (int e = 0; e < Node.GetInDeg(); e++) {
      if (! IsNode(Node.GetInNId(e))) {
        const TStr Msg = TStr::Fmt("In-edge %d <-- %d: node %d does not exist.",
          Node.GetId(), Node.GetInNId(e), Node.GetInNId(e));
        if (ThrowExcept) { EAssertR(false, Msg); } else { ErrNotify(Msg.CStr()); } RetVal=false;
      }
      if (e > 0 && prevNId == Node.GetInNId(e)) {
        const TStr Msg = TStr::Fmt("Node %d has duplidate in-edge %d <-- %d.",
          Node.GetId(), Node.GetId(), Node.GetInNId(e));
        if (ThrowExcept) { EAssertR(false, Msg); } else { ErrNotify(Msg.CStr()); } RetVal=false;
      }
      prevNId = Node.GetInNId(e);
    }
  }
  return RetVal;
}

Here is the call graph for this function:

template<class TNodeData>
static PNet TNodeNet< TNodeData >::Load ( TSIn SIn) [inline, static]

Static constructor that loads the network from a stream SIn and returns a pointer to it.

Reimplemented in TTimeNet.

Definition at line 150 of file network.h.

{ return PNet(new TNodeNet(SIn)); }
template<class TNodeData>
static PNet TNodeNet< TNodeData >::New ( ) [inline, static]

Static constructor that returns a pointer to the network. Call: TPt <TNodeNet<TNodeData> > Net = TNodeNet<TNodeData>::New().

Reimplemented in TTimeNet.

Definition at line 148 of file network.h.

{ return PNet(new TNodeNet()); }
template<class TNodeData>
TNodeNet& TNodeNet< TNodeData >::operator= ( const TNodeNet< TNodeData > &  NodeNet) [inline]

Definition at line 153 of file network.h.

                                                 {
    if (this!=&NodeNet) { NodeH=NodeNet.NodeH;  MxNId=NodeNet.MxNId; }  return *this; }
template<class TNodeData>
void TNodeNet< TNodeData >::Reserve ( const int &  Nodes,
const int &  Edges 
) [inline]

Reserves memory for a network of Nodes nodes and Edges edges.

Definition at line 240 of file network.h.

Referenced by TTimeNet::GetSubGraph(), TTimeNet::LoadAmazon(), TTimeNet::LoadPatents(), and TNodeNet< TSecTm >::TNodeNet().

{ if (Nodes>0) { NodeH.Gen(Nodes/2); } }

Here is the caller graph for this function:

template<class TNodeData>
virtual void TNodeNet< TNodeData >::Save ( TSOut SOut) const [inline, virtual]

Saves the network to a (binary) stream SOut.

Reimplemented in TTimeNet.

Definition at line 146 of file network.h.

{ MxNId.Save(SOut);  NodeH.Save(SOut); }
template<class TNodeData>
void TNodeNet< TNodeData >::SetNDat ( const int &  NId,
const TNodeData &  NodeDat 
)

Sets node data for the node of ID NId in the network.

Definition at line 317 of file network.h.

References TStr::Fmt(), and IAssertR.

                                                                          {
  IAssertR(IsNode(NId), TStr::Fmt("NodeId %d does not exist.", NId).CStr());
  NodeH.GetDat(NId).NodeDat = NodeDat;
}

Here is the call graph for this function:

template<class TNodeData>
void TNodeNet< TNodeData >::SortNIdByDat ( const bool &  Asc = true) [inline]

Sorts nodes by node data.

Definition at line 244 of file network.h.

{ NodeH.SortByDat(Asc); }
template<class TNodeData>
void TNodeNet< TNodeData >::SortNIdById ( const bool &  Asc = true) [inline]

Sorts nodes by node IDs.

Definition at line 242 of file network.h.

{ NodeH.SortByKey(Asc); }

Friends And Related Function Documentation

template<class TNodeData>
friend class TPt< TNodeNet< TNodeData > > [friend]

Definition at line 258 of file network.h.


Member Data Documentation

template<class TNodeData>
TCRef TNodeNet< TNodeData >::CRef [protected]

Definition at line 133 of file network.h.

template<class TNodeData>
TInt TNodeNet< TNodeData >::MxNId [protected]

The documentation for this class was generated from the following file: