SNAP Library 2.0, Developer Reference  2013-05-13 16:33:57
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
TNodeEDatNet< TNodeData, TEdgeData > Class Template Reference

Node Edge Network (directed graph, TNGraph with data on nodes and edges). More...

#include <network.h>

Collaboration diagram for TNodeEDatNet< TNodeData, TEdgeData >:

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 TEdgeData TEdgeDat
typedef TNodeEDatNet
< TNodeData, TEdgeData > 
TNet
typedef TPt< TNetPNet
typedef TVec< TPair< TInt,
TEdgeData > > 
TNIdDatPrV

Public Member Functions

 TNodeEDatNet ()
 TNodeEDatNet (const int &Nodes, const int &Edges)
 Constructor that reserves enough memory for a network of Nodes nodes and Edges edges.
 TNodeEDatNet (const TNodeEDatNet &NodeNet)
 TNodeEDatNet (TSIn &SIn)
 Constructor that loads the network from a (binary) stream SIn.
virtual ~TNodeEDatNet ()
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).
TNodeEDatNetoperator= (const TNodeEDatNet &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 the maximum id of a any node 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 int &SrcNId, const int &DstNId, const TEdgeData &EdgeDat)
 Adds an edge and edge data from node IDs SrcNId to node DstNId.
int AddEdge (const TEdgeI &EdgeI)
 Adds an edge from EdgeI.GetSrcNId() to EdgeI.GetDstNId() and its edge data 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.
void SetEDat (const int &SrcNId, const int &DstNId, const TEdgeData &EdgeDat)
 Sets edge data for the edge between nodes SrcNId and DstNId in the network.
bool GetEDat (const int &SrcNId, const int &DstNId, TEdgeData &EdgeDat) const
 Returns edge data in Data for the edge from node IDs SrcNId to DstNId.
TEdgeData & GetEDat (const int &SrcNId, const int &DstNId)
 Returns edge data for the edge from node IDs SrcNId to DstNId.
const TEdgeData & GetEDat (const int &SrcNId, const int &DstNId) const
 Returns edge data for the edge from node IDs SrcNId to DstNId.
void SetAllEDat (const TEdgeData &EdgeDat)
 Sets edge data for all the edges in the network to EDat.
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 <TNodeEDatNet<TNodeData, TEdgeData> > Net = TNodeEDatNet<TNodeData, TEdgeData>::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)

Static Protected Member Functions

static int GetNIdPos (const TVec< TPair< TInt, TEdgeData > > &NIdV, const int &NId)

Protected Attributes

TCRef CRef
TInt MxNId
THash< TInt, TNodeNodeH

Friends

class TPt< TNodeEDatNet< TNodeData, TEdgeData > >

Detailed Description

template<class TNodeData, class TEdgeData>
class TNodeEDatNet< TNodeData, TEdgeData >

Node Edge Network (directed graph, TNGraph with data on nodes and edges).

Definition at line 441 of file network.h.


Member Typedef Documentation

template<class TNodeData, class TEdgeData>
typedef TPt<TNet> TNodeEDatNet< TNodeData, TEdgeData >::PNet

Definition at line 446 of file network.h.

template<class TNodeData, class TEdgeData>
typedef TEdgeData TNodeEDatNet< TNodeData, TEdgeData >::TEdgeDat

Definition at line 444 of file network.h.

template<class TNodeData, class TEdgeData>
typedef TNodeEDatNet<TNodeData, TEdgeData> TNodeEDatNet< TNodeData, TEdgeData >::TNet

Definition at line 445 of file network.h.

template<class TNodeData, class TEdgeData>
typedef TVec<TPair<TInt, TEdgeData> > TNodeEDatNet< TNodeData, TEdgeData >::TNIdDatPrV

Definition at line 447 of file network.h.

template<class TNodeData, class TEdgeData>
typedef TNodeData TNodeEDatNet< TNodeData, TEdgeData >::TNodeDat

Definition at line 443 of file network.h.


Constructor & Destructor Documentation

template<class TNodeData, class TEdgeData>
TNodeEDatNet< TNodeData, TEdgeData >::TNodeEDatNet ( ) [inline]

Definition at line 583 of file network.h.

: CRef(), MxNId(0), NodeH() { }
template<class TNodeData, class TEdgeData>
TNodeEDatNet< TNodeData, TEdgeData >::TNodeEDatNet ( 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 585 of file network.h.

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

Definition at line 586 of file network.h.

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

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

Definition at line 588 of file network.h.

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

Definition at line 589 of file network.h.

{ }

Member Function Documentation

template<class TNodeData , class TEdgeData >
int TNodeEDatNet< TNodeData, TEdgeData >::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 does not exist and was successfully added return -1. Normally the function should return an ID of the edge added but since edges in TNodeEDatNet have no IDs we return -1. Function aborts if SrcNId or DstNId are not nodes in the network.

Definition at line 810 of file network.h.

Referenced by TNIBs::LoadGroundTruthTxt(), TNIBs::LoadInferredTxt(), and TNIBs::UpdateDiff().

                                                                                    {
  return AddEdge(SrcNId, DstNId, TEdgeData());
}

Here is the caller graph for this function:

template<class TNodeData , class TEdgeData>
int TNodeEDatNet< TNodeData, TEdgeData >::AddEdge ( const int &  SrcNId,
const int &  DstNId,
const TEdgeData &  EdgeDat 
)

Adds an edge and edge data from node IDs SrcNId to node DstNId.

If the edge already exists, set edges data and returns -2. If the edge does not exist and was successfully added returns -1. Normally the function should return an ID of the edge added but since edges in TNodeEDatNet have no IDs it returns -1. Function aborts if SrcNId or DstNId are not nodes in the network.

Definition at line 815 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());
  //IAssert(! IsEdge(SrcNId, DstNId));
  if (IsEdge(SrcNId, DstNId)) {
    GetEDat(SrcNId, DstNId) = EdgeDat;
    return -2;
  }
  GetNode(SrcNId).OutNIdV.AddSorted(TPair<TInt, TEdgeData>(DstNId, EdgeDat));
  GetNode(DstNId).InNIdV.AddSorted(SrcNId);
  return -1; // edge id
}

Here is the call graph for this function:

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

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

Definition at line 662 of file network.h.

Referenced by TNodeEDatNet< TStr, TFltFltH >::AddEdge().

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

Here is the caller graph for this function:

template<class TNodeData , class TEdgeData >
int TNodeEDatNet< TNodeData, TEdgeData >::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 752 of file network.h.

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

Referenced by TNIBs::Init(), TNIBs::LoadGroundTruthNodesTxt(), TNIBs::LoadGroundTruthTxt(), TNIBs::LoadInferredNodesTxt(), and TNIBs::LoadInferredTxt().

                                                       {
  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, class TEdgeData >
int TNodeEDatNet< TNodeData, TEdgeData >::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 764 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, class TEdgeData>
int TNodeEDatNet< TNodeData, TEdgeData >::AddNode ( const TNodeI NodeId) [inline]

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

Definition at line 616 of file network.h.

Referenced by TNodeEDatNet< TStr, TFltFltH >::AddNode().

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

Here is the caller graph for this function:

template<class TNodeData, class TEdgeData>
TEdgeI TNodeEDatNet< TNodeData, TEdgeData >::BegEI ( ) const [inline]

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

Definition at line 672 of file network.h.

Referenced by TNIBs::BSG(), TNIBs::FG(), TNIBs::GetGroundTruthGraphAtT(), TNIBs::GetGroundTruthNetworkAtT(), TNIBs::GetInferredGraphAtT(), TNIBs::GetInferredNetworkAtT(), TNIBs::SaveGroundTruth(), TNIBs::SaveGroundTruthPajek(), TNIBs::SaveInferred(), TNIBs::SaveInferredEdges(), TNIBs::SaveInferredPajek(), and TNIBs::SG().

{ TNodeI NI=BegNI();  while(NI<EndNI() && NI.GetOutDeg()==0) NI++; return TEdgeI(NI, EndNI()); }

Here is the caller graph for this function:

template<class TNodeData, class TEdgeData>
TNodeI TNodeEDatNet< TNodeData, TEdgeData >::BegNI ( ) const [inline]

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

Definition at line 626 of file network.h.

Referenced by TNodeEDatNet< TStr, TFltFltH >::BegEI().

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

Here is the caller graph for this function:

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

Deletes all nodes and edges from the network.

Definition at line 702 of file network.h.

Referenced by TNIBs::Init(), TNIBs::LoadGroundTruthNodesTxt(), TNIBs::LoadGroundTruthTxt(), TNIBs::LoadInferredNodesTxt(), and TNIBs::LoadInferredTxt().

                                                              {
    MxNId = 0;  NodeH.Clr(DoDel, -1, ResetDat); }

Here is the caller graph for this function:

template<class TNodeData , class TEdgeData >
void TNodeEDatNet< TNodeData, TEdgeData >::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 909 of file network.h.

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

                                                                         {
  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:

template<class TNodeData , class TEdgeData >
void TNodeEDatNet< TNodeData, TEdgeData >::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 828 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());
  int pos = GetNIdPos(GetNode(SrcNId).OutNIdV, DstNId);
  if (pos != -1) { GetNode(SrcNId).OutNIdV.Del(pos); }
  pos = GetNode(DstNId).InNIdV.SearchBin(SrcNId);
  if (pos != -1) { GetNode(DstNId).InNIdV.Del(pos); }
  if (! IsDir) {
    pos = GetNIdPos(GetNode(DstNId).OutNIdV, SrcNId);
    if (pos != -1) { GetNode(DstNId).OutNIdV.Del(pos); }
    pos = GetNode(SrcNId).InNIdV.SearchBin(DstNId);
    if (pos != -1) { GetNode(SrcNId).InNIdV.Del(pos); }
  }
}

Here is the call graph for this function:

template<class TNodeData , class TEdgeData >
void TNodeEDatNet< TNodeData, TEdgeData >::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 782 of file network.h.

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

                                                               {
  const TNode& Node = GetNode(NId);
  for (int out = 0; out < Node.GetOutDeg(); out++) {
    const int nbr = Node.GetOutNId(out);
    if (nbr == NId) { continue; }
    TIntV& NIdV = GetNode(nbr).InNIdV;
    const int pos = NIdV.SearchBin(NId);
    if (pos != -1) { NIdV.Del(pos); }
  }
  for (int in = 0; in < Node.GetInDeg(); in++) {
    const int nbr = Node.GetInNId(in);
    if (nbr == NId) { continue; }
    TNIdDatPrV& NIdDatV = GetNode(nbr).OutNIdV;
    const int pos = GetNIdPos(NIdDatV, NId);
    if (pos != -1) { NIdDatV.Del(pos); }
  }
  NodeH.DelKey(NId);
}

Here is the call graph for this function:

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

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

Definition at line 622 of file network.h.

Referenced by TNodeEDatNet< TStr, TFltFltH >::DelNode().

{ DelNode(NodeI.GetId()); }

Here is the caller graph for this function:

template<class TNodeData, class TEdgeData>
bool TNodeEDatNet< TNodeData, TEdgeData >::Empty ( ) const [inline]

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

Definition at line 700 of file network.h.

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

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

Definition at line 674 of file network.h.

Referenced by TNIBs::BSG(), TNIBs::FG(), TNIBs::GetGroundTruthGraphAtT(), TNIBs::GetGroundTruthNetworkAtT(), TNIBs::GetInferredGraphAtT(), TNIBs::GetInferredNetworkAtT(), TNIBs::SaveGroundTruth(), TNIBs::SaveGroundTruthPajek(), TNIBs::SaveInferred(), TNIBs::SaveInferredEdges(), TNIBs::SaveInferredPajek(), and TNIBs::SG().

{ return TEdgeI(EndNI(), EndNI()); }

Here is the caller graph for this function:

template<class TNodeData, class TEdgeData>
TNodeI TNodeEDatNet< TNodeData, TEdgeData >::EndNI ( ) const [inline]

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

Definition at line 628 of file network.h.

Referenced by TNodeEDatNet< TStr, TFltFltH >::BegEI(), and TNodeEDatNet< TStr, TFltFltH >::EndEI().

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

Here is the caller graph for this function:

template<class TNodeData , class TEdgeData>
bool TNodeEDatNet< TNodeData, TEdgeData >::GetEDat ( const int &  SrcNId,
const int &  DstNId,
TEdgeData &  EdgeDat 
) const

Returns edge data in Data for the edge from node IDs SrcNId to DstNId.

Returns true, if the edge was found. Otherwise, returns false.

Definition at line 857 of file network.h.

References TNodeEDatNet< TNodeData, TEdgeData >::TNode::GetOutEDat(), and TNodeEDatNet< TNodeData, TEdgeData >::TNode::OutNIdV.

Referenced by TNIBs::BSG(), TNIBs::ComputePerformanceNId(), TNIBs::FG(), TNIBs::GenCascade(), TNodeEDatNet< TNodeData, TEdgeData >::TNodeI::GetInEDat(), TNIBs::LabelBurstAutomaton(), TNIBs::LoadGroundTruthTxt(), TNIBs::LoadInferredTxt(), TNIBs::SG(), and TNIBs::UpdateDiff().

                                                                                                               {
  if (! IsEdge(SrcNId, DstNId)) { return false; }
  const TNode& N = GetNode(SrcNId);
  EdgeDat = N.GetOutEDat(GetNIdPos(N.OutNIdV, DstNId));
  return true;
}

Here is the call graph for this function:

Here is the caller graph for this function:

template<class TNodeData , class TEdgeData>
TEdgeData & TNodeEDatNet< TNodeData, TEdgeData >::GetEDat ( const int &  SrcNId,
const int &  DstNId 
)

Returns edge data for the edge from node IDs SrcNId to DstNId.

Definition at line 865 of file network.h.

References Assert, TNodeEDatNet< TNodeData, TEdgeData >::TNode::GetOutEDat(), and TNodeEDatNet< TNodeData, TEdgeData >::TNode::OutNIdV.

                                                                                           {
  Assert(IsEdge(SrcNId, DstNId));
  TNode& N = GetNode(SrcNId);
  return N.GetOutEDat(GetNIdPos(N.OutNIdV, DstNId));
}

Here is the call graph for this function:

template<class TNodeData , class TEdgeData>
const TEdgeData & TNodeEDatNet< TNodeData, TEdgeData >::GetEDat ( const int &  SrcNId,
const int &  DstNId 
) const

Returns edge data for the edge from node IDs SrcNId to DstNId.

Definition at line 872 of file network.h.

References Assert, TNodeEDatNet< TNodeData, TEdgeData >::TNode::GetOutEDat(), and TNodeEDatNet< TNodeData, TEdgeData >::TNode::OutNIdV.

                                                                                                       {
  Assert(IsEdge(SrcNId, DstNId));
  const TNode& N = GetNode(SrcNId);
  return N.GetOutEDat(GetNIdPos(N.OutNIdV, DstNId));
}

Here is the call graph for this function:

template<class TNodeData , class TEdgeData >
int TNodeEDatNet< TNodeData, TEdgeData >::GetEdges ( ) const

Returns the number of edges in the network.

Definition at line 802 of file network.h.

Referenced by TNIBs::LoadGroundTruthTxt(), and TNIBs::LoadInferredTxt().

                                                       {
  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, class TEdgeData>
TEdgeI TNodeEDatNet< TNodeData, TEdgeData >::GetEI ( const int &  EId) const

Not supported/implemented!

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

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

Definition at line 886 of file network.h.

References TVec< TVal, TSizeTy >::Len(), and TNodeEDatNet< TNodeData, TEdgeData >::TNodeI::NodeHI.

                                                                                                                                       {
  const TNodeI SrcNI = GetNI(SrcNId);
  int NodeN = -1;
  //SrcNI.NodeHI.GetDat().OutNIdV.SearchBin(DstNId);
  const TNIdDatPrV& NIdDatV = SrcNI.NodeHI.GetDat().OutNIdV;
  int LValN=0, RValN=NIdDatV.Len()-1;
  while (RValN>=LValN){
    int ValN=(LValN+RValN)/2;
    if (DstNId==NIdDatV[ValN].Val1){ NodeN=ValN; break; }
    if (DstNId<NIdDatV[ValN].Val1){RValN=ValN-1;} else {LValN=ValN+1;}
  }
  if (NodeN == -1) { return EndEI(); }
  else { return TEdgeI(SrcNI, EndNI(), NodeN); }
}

Here is the call graph for this function:

template<class TNodeData, class TEdgeData>
int TNodeEDatNet< TNodeData, TEdgeData >::GetMxNId ( ) const [inline]

Returns the maximum id of a any node in the network.

Definition at line 640 of file network.h.

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

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

Definition at line 636 of file network.h.

Referenced by TNodeEDatNet< TNodeData, TEdgeData >::TNodeI::GetInNDat(), TNodeEDatNet< TNodeData, TEdgeData >::TNodeI::GetNbrNDat(), and TNodeEDatNet< TNodeData, TEdgeData >::TNodeI::GetOutNDat().

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

Here is the caller graph for this function:

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

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

Definition at line 638 of file network.h.

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

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

Definition at line 630 of file network.h.

Referenced by TNIBs::ComputePerformanceNId(), TNIBs::GenCascade(), and TNodeEDatNet< TStr, TFltFltH >::GetRndNI().

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

Here is the caller graph for this function:

template<class TNodeData , class TEdgeData>
int TNodeEDatNet< TNodeData, TEdgeData >::GetNIdPos ( const TVec< TPair< TInt, TEdgeData > > &  NIdV,
const int &  NId 
) [static, protected]

Definition at line 739 of file network.h.

Referenced by TNodeEDatNet< TNodeData, TEdgeData >::TNode::IsOutNId().

                                                                                                           {
  int LValN=0, RValN = NIdV.Len()-1;
  while (RValN >= LValN) {
    const int ValN = (LValN+RValN)/2;
    const int CurNId = NIdV[ValN].Val1;
    if (NId == CurNId) { return ValN; }
    if (NId < CurNId) { RValN=ValN-1; }
    else { LValN=ValN+1; }
  }
  return -1;
}

Here is the caller graph for this function:

template<class TNodeData , class TEdgeData >
void TNodeEDatNet< TNodeData, TEdgeData >::GetNIdV ( TIntV NIdV) const

Gets a vector IDs of all nodes in the network.

Definition at line 902 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, class TEdgeData>
TNode& TNodeEDatNet< TNodeData, TEdgeData >::GetNode ( const int &  NId) [inline, protected]

Definition at line 576 of file network.h.

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

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

Definition at line 632 of file network.h.

{ return NodeH.GetDat(NId); }
template<class TNodeData, class TEdgeData>
int TNodeEDatNet< TNodeData, TEdgeData >::GetNodes ( ) const [inline]
template<class TNodeData, class TEdgeData>
TNodeI TNodeEDatNet< TNodeData, TEdgeData >::GetRndNI ( TRnd Rnd = TInt::Rnd) [inline]

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

Definition at line 695 of file network.h.

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

Returns an ID of a random node in the network.

Definition at line 693 of file network.h.

Referenced by TNIBs::GenCascade(), and TNodeEDatNet< TStr, TFltFltH >::GetRndNI().

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

Here is the caller graph for this function:

template<class TNodeData , class TEdgeData >
bool TNodeEDatNet< TNodeData, TEdgeData >::HasFlag ( const TGraphFlag Flag) const

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

Definition at line 734 of file network.h.

References HasGraphFlag.

                                                                             {
  return HasGraphFlag(typename TNet, Flag);
}
template<class TNodeData , class TEdgeData >
bool TNodeEDatNet< TNodeData, TEdgeData >::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 843 of file network.h.

Referenced by TNIBs::BSG(), TNIBs::ComputePerformanceNId(), TNIBs::FG(), TNIBs::SG(), and TNIBs::UpdateDiff().

                                                                                                             {
  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, class TEdgeData>
bool TNodeEDatNet< TNodeData, TEdgeData >::IsNode ( const int &  NId) const [inline]

Tests whether ID NId is a node.

Definition at line 624 of file network.h.

Referenced by TNIBs::UpdateDiff().

{ return NodeH.IsKey(NId); }

Here is the caller graph for this function:

template<class TNodeData , class TEdgeData >
bool TNodeEDatNet< TNodeData, TEdgeData >::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 920 of file network.h.

References TStr::CStr(), EAssertR, ErrNotify(), TStr::Fmt(), TNodeEDatNet< TNodeData, TEdgeData >::TNode::GetId(), TNodeEDatNet< TNodeData, TEdgeData >::TNode::GetInDeg(), TNodeEDatNet< TNodeData, TEdgeData >::TNode::GetInNId(), TNodeEDatNet< TNodeData, TEdgeData >::TNode::GetOutDeg(), TNodeEDatNet< TNodeData, TEdgeData >::TNode::GetOutNId(), TNodeEDatNet< TNodeData, TEdgeData >::TNode::InNIdV, TVec< TVal, TSizeTy >::IsSorted(), and TNodeEDatNet< TNodeData, TEdgeData >::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, class TEdgeData>
static PNet TNodeEDatNet< TNodeData, TEdgeData >::Load ( TSIn SIn) [inline, static]

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

Definition at line 595 of file network.h.

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

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

Definition at line 593 of file network.h.

Referenced by TNIBs::GetGroundTruthNetworkAtT(), TNIBs::GetInferredNetworkAtT(), and main().

{ return PNet(new TNet()); }

Here is the caller graph for this function:

template<class TNodeData, class TEdgeData>
TNodeEDatNet& TNodeEDatNet< TNodeData, TEdgeData >::operator= ( const TNodeEDatNet< TNodeData, TEdgeData > &  NodeNet) [inline]

Definition at line 598 of file network.h.

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

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

Definition at line 705 of file network.h.

Referenced by TNodeEDatNet< TStr, TFltFltH >::TNodeEDatNet().

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

Here is the caller graph for this function:

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

Saves the network to a (binary) stream SOut.

Definition at line 591 of file network.h.

Referenced by TNIBs::Save().

{ MxNId.Save(SOut);  NodeH.Save(SOut); }

Here is the caller graph for this function:

template<class TNodeData , class TEdgeData>
void TNodeEDatNet< TNodeData, TEdgeData >::SetAllEDat ( const TEdgeData &  EdgeDat)

Sets edge data for all the edges in the network to EDat.

Definition at line 879 of file network.h.

                                                                            {
  for (TEdgeI EI = BegEI(); EI < EndEI(); EI++) {
    EI() = EdgeDat;
  }
}
template<class TNodeData , class TEdgeData>
void TNodeEDatNet< TNodeData, TEdgeData >::SetEDat ( const int &  SrcNId,
const int &  DstNId,
const TEdgeData &  EdgeDat 
)

Sets edge data for the edge between nodes SrcNId and DstNId in the network.

Definition at line 850 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());
  IAssertR(IsEdge(SrcNId, DstNId), TStr::Fmt("Edge between %d and %d does not exist.", SrcNId, DstNId).CStr());
  GetEDat(SrcNId, DstNId) = EdgeDat;
}

Here is the call graph for this function:

template<class TNodeData, class TEdgeData >
void TNodeEDatNet< TNodeData, TEdgeData >::SetNDat ( const int &  NId,
const TNodeData &  NodeDat 
)

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

Definition at line 776 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, class TEdgeData>
void TNodeEDatNet< TNodeData, TEdgeData >::SortNIdByDat ( const bool &  Asc = true) [inline]

Sorts nodes by node data.

Definition at line 709 of file network.h.

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

Sorts nodes by node IDs.

Definition at line 707 of file network.h.

{ NodeH.SortByKey(Asc); }

Friends And Related Function Documentation

template<class TNodeData, class TEdgeData>
friend class TPt< TNodeEDatNet< TNodeData, TEdgeData > > [friend]

Definition at line 723 of file network.h.


Member Data Documentation

template<class TNodeData, class TEdgeData>
TCRef TNodeEDatNet< TNodeData, TEdgeData >::CRef [protected]

Definition at line 579 of file network.h.

template<class TNodeData, class TEdgeData>
TInt TNodeEDatNet< TNodeData, TEdgeData >::MxNId [protected]

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