SNAP Library , Developer Reference  2013-01-07 14:03:36
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
TNodeEdgeNet< TNodeData, TEdgeData > Class Template Reference

#include <network.h>

Collaboration diagram for TNodeEdgeNet< TNodeData, TEdgeData >:

List of all members.

Classes

class  TEdge
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 TNodeEdgeNet
< TNodeData, TEdgeData > 
TNet
typedef TPt< TNetPNet

Public Member Functions

 TNodeEdgeNet ()
 TNodeEdgeNet (const int &Nodes, const int &Edges)
 Constructor that reserves enough memory for a network of Nodes nodes and Edges edges.
 TNodeEdgeNet (const TNodeEdgeNet &Net)
 TNodeEdgeNet (TSIn &SIn)
 Constructor that loads the network from a (binary) stream SIn.
virtual ~TNodeEdgeNet ()
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).
TNodeEdgeNetoperator= (const TNodeEdgeNet &Net)
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 node data to node with ID NId.
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.
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 GetUniqEdges (const bool &IsDir=true) const
 Returns the number of edges in the network with a unique pair of nodes.
int AddEdge (const int &SrcNId, const int &DstNId, int EId=-1)
 Adds an edge between node IDs SrcNId and DstNId to the graph.
int AddEdge (const int &SrcNId, const int &DstNId, int EId, 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 &EId)
 Deletes an edge with ID EId from 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 &EId) const
 Tests whether an edge with ID EId exists in 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.
bool IsEdge (const int &SrcNId, const int &DstNId, int &EId, const bool &IsDir=true) const
 Tests whether an edge from node IDs SrcNId to DstNId with edge ID EId exists in the network.
int GetEId (const int &SrcNId, const int &DstNId) const
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
TEdgeI GetEI (const int &SrcNId, const int &DstNId) const
void SetEDat (const int &EId, const TEdgeData &EdgeDat)
 Sets edge data for the edge of ID NId in the network.
TEdgeData & GetEDat (const int &EId)
 Returns edge data for the edge with ID EId.
const TEdgeData & GetEDat (const int &EId) const
 Returns edge data for the edge with ID EId.
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.
int GetRndEId (TRnd &Rnd=TInt::Rnd)
 Returns an ID of a random edge in the network.
TEdgeI GetRndEI (TRnd &Rnd=TInt::Rnd)
 Returns an interator referring to a random edge in the network.
void GetNIdV (TIntV &NIdV) const
 Returns a vector of all node IDs in the network.
void GetEIdV (TIntV &EIdV) const
 Returns a vector of all edge IDs in the network.
bool Empty () const
 Tests whether the network is empty (has zero nodes).
void Clr ()
 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 SortEIdById (const bool &Asc=true)
 Sorts edges by edge IDs.
void SortEIdByDat (const bool &Asc=true)
 Sorts edges by edge 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 <TNodeEdgeNet<TNodeData, TEdgeData> > Net = TNodeEdgeNet<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 Attributes

TCRef CRef
TInt MxNId
TInt MxEId
THash< TInt, TNodeNodeH
THash< TInt, TEdgeEdgeH

Private Member Functions

TNodeGetNode (const int &NId)
const TNodeGetNode (const int &NId) const
const TNodeGetNodeKId (const int &NodeKeyId) const
TEdgeGetEdge (const int &EId)
const TEdgeGetEdge (const int &EId) const
const TEdgeGetEdgeKId (const int &EdgeKeyId) const

Friends

class TPt< TNodeEdgeNet< TNodeData, TEdgeData > >

Detailed Description

template<class TNodeData, class TEdgeData>
class TNodeEdgeNet< TNodeData, TEdgeData >

Node Edge Network (directed multigraph, TNEGraph with data on nodes and edges).

Definition at line 978 of file network.h.


Member Typedef Documentation

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

Reimplemented in TTimeNENet.

Definition at line 983 of file network.h.

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

Definition at line 981 of file network.h.

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

Reimplemented in TTimeNENet.

Definition at line 982 of file network.h.

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

Definition at line 980 of file network.h.


Constructor & Destructor Documentation

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

Definition at line 1153 of file network.h.

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

: CRef(), MxNId(0), MxEId(0) { Reserve(Nodes, Edges); }
template<class TNodeData, class TEdgeData>
TNodeEdgeNet< TNodeData, TEdgeData >::TNodeEdgeNet ( const TNodeEdgeNet< TNodeData, TEdgeData > &  Net) [inline]

Definition at line 1156 of file network.h.

: MxNId(Net.MxNId), MxEId(Net.MxEId), NodeH(Net.NodeH), EdgeH(Net.EdgeH) { }
template<class TNodeData, class TEdgeData>
TNodeEdgeNet< TNodeData, TEdgeData >::TNodeEdgeNet ( TSIn SIn) [inline]

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

Definition at line 1158 of file network.h.

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

Definition at line 1159 of file network.h.

{ }

Member Function Documentation

template<class TNodeData , class TEdgeData >
int TNodeEdgeNet< TNodeData, TEdgeData >::AddEdge ( const int &  SrcNId,
const int &  DstNId,
int  EId = -1 
)

Adds an edge between node IDs SrcNId and DstNId to the graph.

Returns the ID of the edge being added. If EId is -1, edge ID is automatically assigned. Aborts, if an edge with ID EId already exists. Aborts, if SrcNId or DstNId are not nodes in the graph.

Definition at line 1403 of file network.h.

References THash< TKey, TDat, THashFunc >::AddDat(), TVec< TVal >::AddSorted(), TNodeEdgeNet< TNodeData, TEdgeData >::EdgeH, TStr::Fmt(), TNodeEdgeNet< TNodeData, TEdgeData >::GetNode(), IAssertR, TNodeEdgeNet< TNodeData, TEdgeData >::TNode::InEIdV, TNodeEdgeNet< TNodeData, TEdgeData >::IsEdge(), TNodeEdgeNet< TNodeData, TEdgeData >::IsNode(), TMath::Mx(), TNodeEdgeNet< TNodeData, TEdgeData >::MxEId, and TNodeEdgeNet< TNodeData, TEdgeData >::TNode::OutEIdV.

Referenced by TTimeNENet::GetESubGraph(), TTimeNENet::GetGraphUpToTm(), and TTimeNENet::GetSubGraph().

                                                                                             {
  if (EId == -1) { EId = MxEId;  MxEId++; }
  else { MxEId = TMath::Mx(EId+1, MxEId()); }
  IAssertR(!IsEdge(EId), TStr::Fmt("EdgeId %d already exists", EId));
  IAssertR(IsNode(SrcNId) && IsNode(DstNId), TStr::Fmt("%d or %d not a node.", SrcNId, DstNId).CStr());
  EdgeH.AddDat(EId, TEdge(EId, SrcNId, DstNId));
  GetNode(SrcNId).OutEIdV.AddSorted(EId);
  GetNode(DstNId).InEIdV.AddSorted(EId);
  return EId;
}

Here is the call graph for this function:

Here is the caller graph for this function:

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

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

Returns the ID of the edge being added. If EId is -1, edge ID is automatically assigned. Aborts, if an edge with ID EId already exists. Aborts, if SrcNId or DstNId are not nodes in the graph.

Definition at line 1415 of file network.h.

References THash< TKey, TDat, THashFunc >::AddDat(), TVec< TVal >::AddSorted(), TNodeEdgeNet< TNodeData, TEdgeData >::EdgeH, TStr::Fmt(), TNodeEdgeNet< TNodeData, TEdgeData >::GetNode(), IAssertR, TNodeEdgeNet< TNodeData, TEdgeData >::TNode::InEIdV, TNodeEdgeNet< TNodeData, TEdgeData >::IsEdge(), TNodeEdgeNet< TNodeData, TEdgeData >::IsNode(), TMath::Mx(), TNodeEdgeNet< TNodeData, TEdgeData >::MxEId, and TNodeEdgeNet< TNodeData, TEdgeData >::TNode::OutEIdV.

                                                                                                                       {
  if (EId == -1) { EId = MxEId;  MxEId++; }
  else { MxEId = TMath::Mx(EId+1, MxEId()); }
  IAssertR(!IsEdge(EId), TStr::Fmt("EdgeId %d already exists", EId));
  IAssertR(IsNode(SrcNId) && IsNode(DstNId), TStr::Fmt("%d or %d not a node.", SrcNId, DstNId).CStr());
  EdgeH.AddDat(EId, TEdge(EId, SrcNId, DstNId, EdgeDat));
  GetNode(SrcNId).OutEIdV.AddSorted(EId);
  GetNode(DstNId).InEIdV.AddSorted(EId);
  return EId;
}

Here is the call graph for this function:

template<class TNodeData, class TEdgeData>
int TNodeEdgeNet< 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 1230 of file network.h.

Referenced by TNodeEdgeNet< TSecTm, TSecTm >::AddEdge().

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

Here is the caller graph for this function:

template<class TNodeData , class TEdgeData >
int TNodeEdgeNet< 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 1341 of file network.h.

References THash< TKey, TDat, THashFunc >::AddDat(), TStr::Fmt(), IAssertR, TNodeEdgeNet< TNodeData, TEdgeData >::IsNode(), TMath::Mx(), TNodeEdgeNet< TNodeData, TEdgeData >::MxNId, and TNodeEdgeNet< TNodeData, TEdgeData >::NodeH.

Referenced by TTimeNENet::GetESubGraph(), TTimeNENet::GetGraphUpToTm(), and TTimeNENet::GetSubGraph().

                                                       {
  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 TNodeEdgeNet< TNodeData, TEdgeData >::AddNode ( int  NId,
const TNodeData &  NodeDat 
)

Adds node data to node with ID NId.

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 1353 of file network.h.

References THash< TKey, TDat, THashFunc >::AddDat(), TStr::Fmt(), IAssertR, TNodeEdgeNet< TNodeData, TEdgeData >::IsNode(), TMath::Mx(), TNodeEdgeNet< TNodeData, TEdgeData >::MxNId, and TNodeEdgeNet< TNodeData, TEdgeData >::NodeH.

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

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

Definition at line 1186 of file network.h.

Referenced by TNodeEdgeNet< TSecTm, TSecTm >::AddNode().

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

Here is the caller graph for this function:

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

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

Definition at line 1247 of file network.h.

Referenced by TNodeEdgeNet< TNodeData, TEdgeData >::GetUniqEdges(), and TNodeEdgeNet< TNodeData, TEdgeData >::SetAllEDat().

{ return TEdgeI(EdgeH.BegI(), this); }

Here is the caller graph for this function:

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

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

Definition at line 1196 of file network.h.

{ return TNodeI(NodeH.BegI(), this); }
template<class TNodeData, class TEdgeData>
void TNodeEdgeNet< TNodeData, TEdgeData >::Clr ( ) [inline]

Deletes all nodes and edges from the network.

Definition at line 1279 of file network.h.

{ MxNId=0;  MxEId=0;  NodeH.Clr();  EdgeH.Clr(); }
template<class TNodeData , class TEdgeData >
void TNodeEdgeNet< 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 1496 of file network.h.

References THash< TKey, TDat, THashFunc >::Defrag(), TNodeEdgeNet< TNodeData, TEdgeData >::EdgeH, THash< TKey, TDat, THashFunc >::FFirstKeyId(), THash< TKey, TDat, THashFunc >::FNextKeyId(), TNodeEdgeNet< TNodeData, TEdgeData >::TNode::InEIdV, THash< TKey, TDat, THashFunc >::IsKeyIdEqKeyN(), TNodeEdgeNet< TNodeData, TEdgeData >::NodeH, TNodeEdgeNet< TNodeData, TEdgeData >::TNode::OutEIdV, and TVec< TVal >::Pack().

Referenced by TTimeNENet::GetESubGraph(), TTimeNENet::GetGraphUpToTm(), and TTimeNENet::GetSubGraph().

                                                                         {
  for (int kid = NodeH.FFirstKeyId(); NodeH.FNextKeyId(kid);) {
    TNode& Node = NodeH[kid];
    Node.InEIdV.Pack();  Node.OutEIdV.Pack();
  }
  if (! OnlyNodeLinks && ! NodeH.IsKeyIdEqKeyN()) { NodeH.Defrag(); }
  if (! OnlyNodeLinks && ! EdgeH.IsKeyIdEqKeyN()) { EdgeH.Defrag(); }
}

Here is the call graph for this function:

Here is the caller graph for this function:

template<class TNodeData , class TEdgeData >
void TNodeEdgeNet< 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 1437 of file network.h.

References TVec< TVal >::DelIfIn(), THash< TKey, TDat, THashFunc >::DelKey(), TNodeEdgeNet< TNodeData, TEdgeData >::EdgeH, TNodeEdgeNet< TNodeData, TEdgeData >::GetNode(), IAssert, TNodeEdgeNet< TNodeData, TEdgeData >::TNode::InEIdV, TNodeEdgeNet< TNodeData, TEdgeData >::IsEdge(), and TNodeEdgeNet< TNodeData, TEdgeData >::TNode::OutEIdV.

                                                                                                        {
  int EId;
  IAssert(IsEdge(SrcNId, DstNId, EId, IsDir));
  GetNode(SrcNId).OutEIdV.DelIfIn(EId);
  GetNode(DstNId).InEIdV.DelIfIn(EId);
  EdgeH.DelKey(EId);
}

Here is the call graph for this function:

template<class TNodeData , class TEdgeData >
void TNodeEdgeNet< 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 1365 of file network.h.

References THash< TKey, TDat, THashFunc >::DelKey(), TNodeEdgeNet< TNodeData, TEdgeData >::EdgeH, TNodeEdgeNet< TNodeData, TEdgeData >::TEdge::GetDstNId(), TNodeEdgeNet< TNodeData, TEdgeData >::GetEdge(), TNodeEdgeNet< TNodeData, TEdgeData >::TNode::GetInDeg(), TNodeEdgeNet< TNodeData, TEdgeData >::TNode::GetInEId(), TNodeEdgeNet< TNodeData, TEdgeData >::GetNode(), TNodeEdgeNet< TNodeData, TEdgeData >::TNode::GetOutDeg(), TNodeEdgeNet< TNodeData, TEdgeData >::TNode::GetOutEId(), TNodeEdgeNet< TNodeData, TEdgeData >::TEdge::GetSrcNId(), IAssert, and TNodeEdgeNet< TNodeData, TEdgeData >::NodeH.

                                                               {
  const TNode& Node = GetNode(NId);
  for (int out = 0; out < Node.GetOutDeg(); out++) {
    const int EId = Node.GetOutEId(out);
    const TEdge& Edge = GetEdge(EId);
    IAssert(Edge.GetSrcNId() == NId);
    GetNode(Edge.GetDstNId()).InEIdV.DelIfIn(EId);
    EdgeH.DelKey(EId);
  }
  for (int in = 0; in < Node.GetInDeg(); in++) {
    const int EId = Node.GetInEId(in);
    const TEdge& Edge = GetEdge(EId);
    IAssert(Edge.GetDstNId() == NId);
    GetNode(Edge.GetSrcNId()).OutEIdV.DelIfIn(EId);
    EdgeH.DelKey(EId);
  }
  NodeH.DelKey(NId);
}

Here is the call graph for this function:

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

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

Definition at line 1192 of file network.h.

Referenced by TNodeEdgeNet< TSecTm, TSecTm >::DelNode().

{ DelNode(NodeI.GetId()); }

Here is the caller graph for this function:

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

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

Definition at line 1277 of file network.h.

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

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

Definition at line 1249 of file network.h.

Referenced by TNodeEdgeNet< TNodeData, TEdgeData >::GetUniqEdges(), and TNodeEdgeNet< TNodeData, TEdgeData >::SetAllEDat().

{ return TEdgeI(EdgeH.EndI(), this); }

Here is the caller graph for this function:

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

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

Definition at line 1198 of file network.h.

{ return TNodeI(NodeH.EndI(), this); }
template<class TNodeData, class TEdgeData>
TEdgeData& TNodeEdgeNet< TNodeData, TEdgeData >::GetEDat ( const int &  EId) [inline]

Returns edge data for the edge with ID EId.

Definition at line 1257 of file network.h.

Referenced by TNodeEdgeNet< TNodeData, TEdgeData >::TNodeI::GetInEDat(), TNodeEdgeNet< TNodeData, TEdgeData >::TNodeI::GetNbrEDat(), and TNodeEdgeNet< TNodeData, TEdgeData >::TNodeI::GetOutEDat().

{ return EdgeH.GetDat(EId).EdgeDat; }

Here is the caller graph for this function:

template<class TNodeData, class TEdgeData>
const TEdgeData& TNodeEdgeNet< TNodeData, TEdgeData >::GetEDat ( const int &  EId) const [inline]

Returns edge data for the edge with ID EId.

Definition at line 1259 of file network.h.

{ return EdgeH.GetDat(EId).EdgeDat; }
template<class TNodeData, class TEdgeData>
const TEdge& TNodeEdgeNet< TNodeData, TEdgeData >::GetEdge ( const int &  EId) const [inline, private]

Definition at line 1145 of file network.h.

{ return EdgeH.GetDat(EId); }
template<class TNodeData, class TEdgeData>
const TEdge& TNodeEdgeNet< TNodeData, TEdgeData >::GetEdgeKId ( const int &  EdgeKeyId) const [inline, private]

Definition at line 1146 of file network.h.

{ return EdgeH[EdgeKeyId]; }
template<class TNodeData, class TEdgeData>
int TNodeEdgeNet< TNodeData, TEdgeData >::GetEdges ( ) const [inline]

Returns the number of edges in the network.

Definition at line 1212 of file network.h.

Referenced by TNodeEdgeNet< TNodeData, TEdgeData >::GetEIdV(), and TNodeEdgeNet< TNodeData, TEdgeData >::GetUniqEdges().

{ return EdgeH.Len(); }

Here is the caller graph for this function:

template<class TNodeData, class TEdgeData>
TEdgeI TNodeEdgeNet< TNodeData, TEdgeData >::GetEI ( const int &  EId) const [inline]

Definition at line 1251 of file network.h.

Referenced by TNodeEdgeNet< TSecTm, TSecTm >::GetRndEI(), and TNodeEdgeNet< TNodeData, TEdgeData >::SetEDat().

{ return TEdgeI(EdgeH.GetI(EId), this); }

Here is the caller graph for this function:

template<class TNodeData, class TEdgeData>
TEdgeI TNodeEdgeNet< TNodeData, TEdgeData >::GetEI ( const int &  SrcNId,
const int &  DstNId 
) const [inline]

Definition at line 1253 of file network.h.

Referenced by TNodeEdgeNet< TSecTm, TSecTm >::GetEI().

{ return GetEI(GetEId(SrcNId, DstNId)); }

Here is the caller graph for this function:

template<class TNodeData, class TEdgeData>
int TNodeEdgeNet< TNodeData, TEdgeData >::GetEId ( const int &  SrcNId,
const int &  DstNId 
) const [inline]

Definition at line 1245 of file network.h.

Referenced by TNodeEdgeNet< TSecTm, TSecTm >::GetEI().

{ int EId; return IsEdge(SrcNId, DstNId, EId)?EId:-1; }

Here is the caller graph for this function:

template<class TNodeData , class TEdgeData >
void TNodeEdgeNet< TNodeData, TEdgeData >::GetEIdV ( TIntV EIdV) const
template<class TNodeData, class TEdgeData>
int TNodeEdgeNet< TNodeData, TEdgeData >::GetMxNId ( ) const [inline]

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

Definition at line 1208 of file network.h.

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

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

Definition at line 1206 of file network.h.

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

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

Definition at line 1200 of file network.h.

Referenced by TNodeEdgeNet< TSecTm, TSecTm >::GetRndNI().

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

Here is the caller graph for this function:

template<class TNodeData , class TEdgeData >
void TNodeEdgeNet< TNodeData, TEdgeData >::GetNIdV ( TIntV NIdV) const
template<class TNodeData, class TEdgeData>
TNode& TNodeEdgeNet< TNodeData, TEdgeData >::GetNode ( const int &  NId) [inline, private]
template<class TNodeData, class TEdgeData>
const TNode& TNodeEdgeNet< TNodeData, TEdgeData >::GetNode ( const int &  NId) const [inline, private]

Definition at line 1142 of file network.h.

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

Definition at line 1143 of file network.h.

{ return NodeH[NodeKeyId]; }
template<class TNodeData, class TEdgeData>
int TNodeEdgeNet< TNodeData, TEdgeData >::GetNodes ( ) const [inline]

Returns the number of nodes in the network.

Definition at line 1172 of file network.h.

Referenced by TNodeEdgeNet< TSecTm, TSecTm >::Empty(), and TNodeEdgeNet< TNodeData, TEdgeData >::GetNIdV().

{ return NodeH.Len(); }

Here is the caller graph for this function:

template<class TNodeData, class TEdgeData>
TEdgeI TNodeEdgeNet< TNodeData, TEdgeData >::GetRndEI ( TRnd Rnd = TInt::Rnd) [inline]

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

Definition at line 1270 of file network.h.

{ return GetEI(GetRndEId(Rnd)); }
template<class TNodeData, class TEdgeData>
int TNodeEdgeNet< TNodeData, TEdgeData >::GetRndEId ( TRnd Rnd = TInt::Rnd) [inline]

Returns an ID of a random edge in the network.

Definition at line 1268 of file network.h.

Referenced by TNodeEdgeNet< TSecTm, TSecTm >::GetRndEI().

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

Here is the caller graph for this function:

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

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

Definition at line 1266 of file network.h.

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

Returns an ID of a random node in the network.

Definition at line 1264 of file network.h.

Referenced by TNodeEdgeNet< TSecTm, TSecTm >::GetRndNI().

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

Here is the caller graph for this function:

template<class TNodeData , class TEdgeData >
int TNodeEdgeNet< TNodeData, TEdgeData >::GetUniqEdges ( const bool &  IsDir = true) const

Returns the number of edges in the network with a unique pair of nodes.

Definition at line 1391 of file network.h.

References THashSet< TKey, THashFunc >::AddKey(), TNodeEdgeNet< TNodeData, TEdgeData >::BegEI(), TNodeEdgeNet< TNodeData, TEdgeData >::EndEI(), TNodeEdgeNet< TNodeData, TEdgeData >::GetEdges(), THashSet< TKey, THashFunc >::Len(), TMath::Mn(), and TMath::Mx().

                                                                            {
  TIntPrSet UniqESet(GetEdges());
  for (TEdgeI EI = BegEI(); EI < EndEI(); EI++) {
    const int Src = EI.GetSrcNId();
    const int Dst = EI.GetDstNId();
    if (IsDir) { UniqESet.AddKey(TIntPr(Src, Dst)); }
    else { UniqESet.AddKey(TIntPr(TMath::Mn(Src, Dst), TMath::Mx(Src, Dst))); }
  }
  return UniqESet.Len();
}

Here is the call graph for this function:

template<class TNodeData , class TEdgeData >
bool TNodeEdgeNet< 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 1316 of file network.h.

References HasGraphFlag.

                                                                             {
  return HasGraphFlag(typename TNet, Flag);
}
template<class TNodeData, class TEdgeData>
bool TNodeEdgeNet< TNodeData, TEdgeData >::IsEdge ( const int &  EId) const [inline]

Tests whether an edge with ID EId exists in the network.

Definition at line 1240 of file network.h.

Referenced by TNodeEdgeNet< TNodeData, TEdgeData >::AddEdge(), TNodeEdgeNet< TNodeData, TEdgeData >::DelEdge(), TNodeEdgeNet< TSecTm, TSecTm >::GetEId(), TNodeEdgeNet< TNodeData, TEdgeData >::IsOk(), and TNodeEdgeNet< TNodeData, TEdgeData >::SetEDat().

{ return EdgeH.IsKey(EId); }

Here is the caller graph for this function:

template<class TNodeData, class TEdgeData>
bool TNodeEdgeNet< TNodeData, TEdgeData >::IsEdge ( const int &  SrcNId,
const int &  DstNId,
const bool &  IsDir = true 
) const [inline]

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

Definition at line 1242 of file network.h.

Referenced by TNodeEdgeNet< TSecTm, TSecTm >::IsEdge().

{ int EId;  return IsEdge(SrcNId, DstNId, EId, IsDir); }

Here is the caller graph for this function:

template<class TNodeData , class TEdgeData >
bool TNodeEdgeNet< TNodeData, TEdgeData >::IsEdge ( const int &  SrcNId,
const int &  DstNId,
int &  EId,
const bool &  IsDir = true 
) const

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

Definition at line 1446 of file network.h.

References TNodeEdgeNet< TNodeData, TEdgeData >::TEdge::GetDstNId(), TNodeEdgeNet< TNodeData, TEdgeData >::GetEdge(), TNodeEdgeNet< TNodeData, TEdgeData >::TEdge::GetId(), TNodeEdgeNet< TNodeData, TEdgeData >::TNode::GetInDeg(), TNodeEdgeNet< TNodeData, TEdgeData >::TNode::GetInEId(), TNodeEdgeNet< TNodeData, TEdgeData >::GetNode(), TNodeEdgeNet< TNodeData, TEdgeData >::TNode::GetOutDeg(), TNodeEdgeNet< TNodeData, TEdgeData >::TNode::GetOutEId(), TNodeEdgeNet< TNodeData, TEdgeData >::TEdge::GetSrcNId(), and TNodeEdgeNet< TNodeData, TEdgeData >::IsNode().

                                                                                                                       {
  if (! IsNode(SrcNId)) { return false; }
  if (! IsNode(DstNId)) { return false; }
  const TNode& SrcNode = GetNode(SrcNId);
  for (int edge = 0; edge < SrcNode.GetOutDeg(); edge++) {
    const TEdge& Edge = GetEdge(SrcNode.GetOutEId(edge));
    if (DstNId == Edge.GetDstNId()) {
      EId = Edge.GetId();  return true; }
  }
  if (! IsDir) {
    for (int edge = 0; edge < SrcNode.GetInDeg(); edge++) {
    const TEdge& Edge = GetEdge(SrcNode.GetInEId(edge));
    if (DstNId == Edge.GetSrcNId()) {
      EId = Edge.GetId();  return true; }
    }
  }
  return false;
}

Here is the call graph for this function:

template<class TNodeData, class TEdgeData>
bool TNodeEdgeNet< TNodeData, TEdgeData >::IsNode ( const int &  NId) const [inline]
template<class TNodeData , class TEdgeData >
bool TNodeEdgeNet< 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 1506 of file network.h.

References TStr::CStr(), EAssertR, TNodeEdgeNet< TNodeData, TEdgeData >::EdgeH, ErrNotify(), THash< TKey, TDat, THashFunc >::FFirstKeyId(), TStr::Fmt(), THash< TKey, TDat, THashFunc >::FNextKeyId(), TNodeEdgeNet< TNodeData, TEdgeData >::TEdge::GetDstNId(), TNodeEdgeNet< TNodeData, TEdgeData >::TNode::GetId(), TNodeEdgeNet< TNodeData, TEdgeData >::TEdge::GetId(), TNodeEdgeNet< TNodeData, TEdgeData >::TNode::GetInDeg(), TNodeEdgeNet< TNodeData, TEdgeData >::TNode::GetInEId(), TNodeEdgeNet< TNodeData, TEdgeData >::TNode::GetOutDeg(), TNodeEdgeNet< TNodeData, TEdgeData >::TNode::GetOutEId(), TNodeEdgeNet< TNodeData, TEdgeData >::TEdge::GetSrcNId(), TNodeEdgeNet< TNodeData, TEdgeData >::TNode::InEIdV, TNodeEdgeNet< TNodeData, TEdgeData >::IsEdge(), TNodeEdgeNet< TNodeData, TEdgeData >::IsNode(), TVec< TVal >::IsSorted(), TNodeEdgeNet< TNodeData, TEdgeData >::NodeH, and TNodeEdgeNet< TNodeData, TEdgeData >::TNode::OutEIdV.

                                                                           {
  bool RetVal = true;
  for (int N = NodeH.FFirstKeyId(); NodeH.FNextKeyId(N); ) {
    const TNode& Node = NodeH[N];
    if (! Node.OutEIdV.IsSorted()) {
      const TStr Msg = TStr::Fmt("Out-edge list of node %d is not sorted.", Node.GetId());
      if (ThrowExcept) { EAssertR(false, Msg); } else { ErrNotify(Msg.CStr()); } RetVal=false;
    }
    if (! Node.InEIdV.IsSorted()) {
      const TStr Msg = TStr::Fmt("In-edge list of node %d is not sorted.", Node.GetId());
      if (ThrowExcept) { EAssertR(false, Msg); } else { ErrNotify(Msg.CStr()); } RetVal=false;
    }
    // check out-edge ids
    int prevEId = -1;
    for (int e = 0; e < Node.GetOutDeg(); e++) {
      if (! IsEdge(Node.GetOutEId(e))) {
        const TStr Msg = TStr::Fmt("Out-edge id %d of node %d does not exist.",  Node.GetOutEId(e), Node.GetId());
        if (ThrowExcept) { EAssertR(false, Msg); } else { ErrNotify(Msg.CStr()); } RetVal=false;
      }
      if (e > 0 && prevEId == Node.GetOutEId(e)) {
        const TStr Msg = TStr::Fmt("Node %d has duplidate out-edge id %d.", Node.GetId(), Node.GetOutEId(e));
        if (ThrowExcept) { EAssertR(false, Msg); } else { ErrNotify(Msg.CStr()); } RetVal=false;
      }
      prevEId = Node.GetOutEId(e);
    }
    // check in-edge ids
    prevEId = -1;
    for (int e = 0; e < Node.GetInDeg(); e++) {
      if (! IsEdge(Node.GetInEId(e))) {
        const TStr Msg = TStr::Fmt("Out-edge id %d of node %d does not exist.",  Node.GetInEId(e), Node.GetId());
        if (ThrowExcept) { EAssertR(false, Msg); } else { ErrNotify(Msg.CStr()); } RetVal=false;
      }
      if (e > 0 && prevEId == Node.GetInEId(e)) {
        const TStr Msg = TStr::Fmt("Node %d has duplidate out-edge id %d.", Node.GetId(), Node.GetInEId(e));
        if (ThrowExcept) { EAssertR(false, Msg); } else { ErrNotify(Msg.CStr()); } RetVal=false;
      }
      prevEId = Node.GetInEId(e);
    }
  }
  for (int E = EdgeH.FFirstKeyId(); EdgeH.FNextKeyId(E); ) {
    const TEdge& Edge = EdgeH[E];
    if (! IsNode(Edge.GetSrcNId())) {
      const TStr Msg = TStr::Fmt("Edge %d source node %d does not exist.", Edge.GetId(), Edge.GetSrcNId());
      if (ThrowExcept) { EAssertR(false, Msg); } else { ErrNotify(Msg.CStr()); } RetVal=false;
    }
    if (! IsNode(Edge.GetDstNId())) {
      const TStr Msg = TStr::Fmt("Edge %d destination node %d does not exist.", Edge.GetId(), Edge.GetDstNId());
      if (ThrowExcept) { EAssertR(false, Msg); } else { ErrNotify(Msg.CStr()); } RetVal=false;
    }
  }
  return RetVal;
}

Here is the call graph for this function:

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

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

Reimplemented in TTimeNENet.

Definition at line 1165 of file network.h.

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

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

Reimplemented in TTimeNENet.

Definition at line 1163 of file network.h.

{ return PNet(new TNet()); }
template<class TNodeData, class TEdgeData>
TNodeEdgeNet& TNodeEdgeNet< TNodeData, TEdgeData >::operator= ( const TNodeEdgeNet< TNodeData, TEdgeData > &  Net) [inline]

Definition at line 1168 of file network.h.

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

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

Definition at line 1281 of file network.h.

Referenced by TTimeNENet::GetESubGraph(), TTimeNENet::GetSubGraph(), and TNodeEdgeNet< TSecTm, TSecTm >::TNodeEdgeNet().

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

Here is the caller graph for this function:

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

Saves the network to a (binary) stream SOut.

Reimplemented in TTimeNENet.

Definition at line 1161 of file network.h.

{ MxNId.Save(SOut);  MxEId.Save(SOut);  NodeH.Save(SOut);  EdgeH.Save(SOut); }
template<class TNodeData , class TEdgeData>
void TNodeEdgeNet< TNodeData, TEdgeData >::SetAllEDat ( const TEdgeData &  EdgeDat)

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

Definition at line 1472 of file network.h.

References TNodeEdgeNet< TNodeData, TEdgeData >::BegEI(), and TNodeEdgeNet< TNodeData, TEdgeData >::EndEI().

                                                                            {
  for (TEdgeI EI = BegEI(); EI < EndEI(); EI++) {
    EI() = EdgeDat;
  }
}

Here is the call graph for this function:

template<class TNodeData , class TEdgeData>
void TNodeEdgeNet< TNodeData, TEdgeData >::SetEDat ( const int &  EId,
const TEdgeData &  EdgeDat 
)

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

Definition at line 1466 of file network.h.

References TStr::Fmt(), TNodeEdgeNet< TNodeData, TEdgeData >::TEdgeI::GetDat(), TNodeEdgeNet< TNodeData, TEdgeData >::GetEI(), IAssertR, and TNodeEdgeNet< TNodeData, TEdgeData >::IsEdge().

                                                                                         {
  IAssertR(IsEdge(EId), TStr::Fmt("EdgeId %d does not exist.", EId).CStr());
  GetEI(EId).GetDat() = EdgeDat;
}

Here is the call graph for this function:

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

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

Definition at line 1385 of file network.h.

References TStr::Fmt(), THash< TKey, TDat, THashFunc >::GetDat(), IAssertR, TNodeEdgeNet< TNodeData, TEdgeData >::IsNode(), TNodeEdgeNet< TNodeData, TEdgeData >::TNode::NodeDat, and TNodeEdgeNet< TNodeData, TEdgeData >::NodeH.

                                                                                         {
  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 TNodeEdgeNet< TNodeData, TEdgeData >::SortEIdByDat ( const bool &  Asc = true) [inline]

Sorts edges by edge data.

Definition at line 1290 of file network.h.

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

Sorts edges by edge IDs.

Definition at line 1288 of file network.h.

{ EdgeH.SortByKey(Asc); }
template<class TNodeData, class TEdgeData>
void TNodeEdgeNet< TNodeData, TEdgeData >::SortNIdByDat ( const bool &  Asc = true) [inline]

Sorts nodes by node data.

Definition at line 1286 of file network.h.

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

Sorts nodes by node IDs.

Definition at line 1284 of file network.h.

{ NodeH.SortByKey(Asc); }

Friends And Related Function Documentation

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

Definition at line 1304 of file network.h.


Member Data Documentation

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

Definition at line 1148 of file network.h.

template<class TNodeData, class TEdgeData>
TInt TNodeEdgeNet< TNodeData, TEdgeData >::MxEId [protected]

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