SNAP Library 3.0, User Reference  2016-07-20 17:56:49
SNAP, a general purpose, high performance system for analysis and manipulation of large networks
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
TNodeEdgeNet< TNodeData, TEdgeData > Class Template Reference

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

#include <network.h>

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. More...
 
 TNodeEdgeNet (const TNodeEdgeNet &Net)
 
 TNodeEdgeNet (TSIn &SIn)
 Constructor that loads the network from a (binary) stream SIn. More...
 
virtual ~TNodeEdgeNet ()
 
virtual void Save (TSOut &SOut) const
 Saves the network to a (binary) stream SOut. More...
 
bool HasFlag (const TGraphFlag &Flag) const
 Allows for run-time checking the type of the network (see the TGraphFlag for flags). More...
 
TNodeEdgeNetoperator= (const TNodeEdgeNet &Net)
 
int GetNodes () const
 Returns the number of nodes in the network. More...
 
int AddNode (int NId=-1)
 Adds a node of ID NId to the network. More...
 
int AddNode (int NId, const TNodeData &NodeDat)
 Adds node data to node with ID NId. More...
 
int AddNode (const TNodeI &NodeI)
 
void DelNode (const int &NId)
 Deletes node of ID NId from the network. More...
 
void DelNode (const TNode &NodeI)
 Deletes node of ID NodeI.GetId() from the network. More...
 
bool IsNode (const int &NId) const
 Tests whether ID NId is a node. More...
 
TNodeI BegNI () const
 Returns an iterator referring to the first node in the network. More...
 
TNodeI EndNI () const
 Returns an iterator referring to the past-the-end node in the network. More...
 
TNodeI GetNI (const int &NId) const
 Returns an iterator referring to the node of ID NId in the network. More...
 
void SetNDat (const int &NId, const TNodeData &NodeDat)
 Sets node data for the node of ID NId in the network. More...
 
TNodeData & GetNDat (const int &NId)
 Returns node data for the node of ID NId in the network. More...
 
const TNodeData & GetNDat (const int &NId) const
 Returns node data for the node of ID NId in the network. More...
 
int GetMxNId () const
 Returns an ID that is larger than any node ID in the network. More...
 
int GetEdges () const
 Returns the number of edges in the network. More...
 
int GetUniqEdges (const bool &IsDir=true) const
 Returns the number of edges in the network with a unique pair of nodes. More...
 
int AddEdge (const int &SrcNId, const int &DstNId, int EId=-1)
 Adds an edge between node IDs SrcNId and DstNId to the graph. More...
 
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. More...
 
int AddEdge (const TEdgeI &EdgeI)
 Adds an edge from EdgeI.GetSrcNId() to EdgeI.GetDstNId() and its edge data to the network. More...
 
void DelEdge (const int &EId)
 Deletes an edge with ID EId from the network. More...
 
void DelEdge (const int &SrcNId, const int &DstNId, const bool &IsDir=true)
 Deletes an edge from node IDs SrcNId to DstNId from the network. More...
 
bool IsEdge (const int &EId) const
 Tests whether an edge with ID EId exists in the network. More...
 
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. More...
 
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. More...
 
int GetEId (const int &SrcNId, const int &DstNId) const
 
TEdgeI BegEI () const
 Returns an iterator referring to the first edge in the network. More...
 
TEdgeI EndEI () const
 Returns an iterator referring to the past-the-end edge in the network. More...
 
TEdgeI GetEI (const int &EId) const
 Not supported/implemented! More...
 
TEdgeI GetEI (const int &SrcNId, const int &DstNId) const
 Returns an iterator referring to edge (SrcNId, DstNId) in the graph. More...
 
void SetEDat (const int &EId, const TEdgeData &EdgeDat)
 Sets edge data for the edge of ID NId in the network. More...
 
TEdgeData & GetEDat (const int &EId)
 Returns edge data for the edge with ID EId. More...
 
const TEdgeData & GetEDat (const int &EId) const
 Returns edge data for the edge with ID EId. More...
 
void SetAllEDat (const TEdgeData &EdgeDat)
 Sets edge data for all the edges in the network to EDat. More...
 
int GetRndNId (TRnd &Rnd=TInt::Rnd)
 Returns an ID of a random node in the network. More...
 
TNodeI GetRndNI (TRnd &Rnd=TInt::Rnd)
 Returns an interator referring to a random node in the network. More...
 
int GetRndEId (TRnd &Rnd=TInt::Rnd)
 Returns an ID of a random edge in the network. More...
 
TEdgeI GetRndEI (TRnd &Rnd=TInt::Rnd)
 Returns an interator referring to a random edge in the network. More...
 
void GetNIdV (TIntV &NIdV) const
 Returns a vector of all node IDs in the network. More...
 
void GetEIdV (TIntV &EIdV) const
 Returns a vector of all edge IDs in the network. More...
 
bool Empty () const
 Tests whether the network is empty (has zero nodes). More...
 
void Clr ()
 Deletes all nodes and edges from the network. More...
 
void Reserve (const int &Nodes, const int &Edges)
 Reserves memory for a network of Nodes nodes and Edges edges. More...
 
void SortNIdById (const bool &Asc=true)
 Sorts nodes by node IDs. More...
 
void SortNIdByDat (const bool &Asc=true)
 Sorts nodes by node data. More...
 
void SortEIdById (const bool &Asc=true)
 Sorts edges by edge IDs. More...
 
void SortEIdByDat (const bool &Asc=true)
 Sorts edges by edge data. More...
 
void Defrag (const bool &OnlyNodeLinks=false)
 Defragments the network. More...
 
bool IsOk (const bool &ThrowExcept=true) const
 Checks the network data structure for internal consistency. More...
 

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(). More...
 
static PNet Load (TSIn &SIn)
 Static constructor that loads the network from a stream SIn and returns a pointer to it. More...
 

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 TCrossNet
 Adds a node NodeI and its node data to the network. More...
 
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 981 of file network.h.

Member Typedef Documentation

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

Definition at line 986 of file network.h.

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

Definition at line 984 of file network.h.

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

Definition at line 985 of file network.h.

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

Definition at line 983 of file network.h.

Constructor & Destructor Documentation

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

Definition at line 1156 of file network.h.

1156 : CRef(), MxNId(0), MxEId(0) { }
TInt MxEId
Definition: network.h:1152
TCRef CRef
Definition: network.h:1151
TInt MxNId
Definition: network.h:1152
template<class TNodeData, class TEdgeData>
TNodeEdgeNet< TNodeData, TEdgeData >::TNodeEdgeNet ( const int &  Nodes,
const int &  Edges 
)
inlineexplicit

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

Definition at line 1158 of file network.h.

1158 : CRef(), MxNId(0), MxEId(0) { Reserve(Nodes, Edges); }
TInt MxEId
Definition: network.h:1152
void Reserve(const int &Nodes, const int &Edges)
Reserves memory for a network of Nodes nodes and Edges edges.
Definition: network.h:1285
TCRef CRef
Definition: network.h:1151
TInt MxNId
Definition: network.h:1152
template<class TNodeData, class TEdgeData>
TNodeEdgeNet< TNodeData, TEdgeData >::TNodeEdgeNet ( const TNodeEdgeNet< TNodeData, TEdgeData > &  Net)
inline

Definition at line 1159 of file network.h.

1159 : MxNId(Net.MxNId), MxEId(Net.MxEId), NodeH(Net.NodeH), EdgeH(Net.EdgeH) { }
TInt MxEId
Definition: network.h:1152
TInt MxNId
Definition: network.h:1152
THash< TInt, TNode > NodeH
Definition: network.h:1153
THash< TInt, TEdge > EdgeH
Definition: network.h:1154
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 1161 of file network.h.

1161 : MxNId(SIn), MxEId(SIn), NodeH(SIn), EdgeH(SIn) { }
TInt MxEId
Definition: network.h:1152
TInt MxNId
Definition: network.h:1152
THash< TInt, TNode > NodeH
Definition: network.h:1153
THash< TInt, TEdge > EdgeH
Definition: network.h:1154
template<class TNodeData, class TEdgeData>
virtual TNodeEdgeNet< TNodeData, TEdgeData >::~TNodeEdgeNet ( )
inlinevirtual

Definition at line 1162 of file network.h.

1162 { }

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

1407  {
1408  if (EId == -1) { EId = MxEId; MxEId++; }
1409  else { MxEId = TMath::Mx(EId+1, MxEId()); }
1410  IAssertR(!IsEdge(EId), TStr::Fmt("EdgeId %d already exists", EId));
1411  IAssertR(IsNode(SrcNId) && IsNode(DstNId), TStr::Fmt("%d or %d not a node.", SrcNId, DstNId).CStr());
1412  EdgeH.AddDat(EId, TEdge(EId, SrcNId, DstNId));
1413  GetNode(SrcNId).OutEIdV.AddSorted(EId);
1414  GetNode(DstNId).InEIdV.AddSorted(EId);
1415  return EId;
1416 }
TInt MxEId
Definition: network.h:1152
#define IAssertR(Cond, Reason)
Definition: bd.h:265
static const T & Mx(const T &LVal, const T &RVal)
Definition: xmath.h:32
bool IsNode(const int &NId) const
Tests whether ID NId is a node.
Definition: network.h:1198
TSizeTy AddSorted(const TVal &Val, const bool &Asc=true, const TSizeTy &_MxVals=-1)
Adds element Val to a sorted vector.
Definition: ds.h:1063
TNode & GetNode(const int &NId)
Definition: network.h:1144
THash< TInt, TEdge > EdgeH
Definition: network.h:1154
bool IsEdge(const int &EId) const
Tests whether an edge with ID EId exists in the network.
Definition: network.h:1244
static TStr Fmt(const char *FmtStr,...)
Definition: dt.cpp:1599
TDat & AddDat(const TKey &Key)
Definition: hash.h:196
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 1419 of file network.h.

1419  {
1420  if (EId == -1) { EId = MxEId; MxEId++; }
1421  else { MxEId = TMath::Mx(EId+1, MxEId()); }
1422  IAssertR(!IsEdge(EId), TStr::Fmt("EdgeId %d already exists", EId));
1423  IAssertR(IsNode(SrcNId) && IsNode(DstNId), TStr::Fmt("%d or %d not a node.", SrcNId, DstNId).CStr());
1424  EdgeH.AddDat(EId, TEdge(EId, SrcNId, DstNId, EdgeDat));
1425  GetNode(SrcNId).OutEIdV.AddSorted(EId);
1426  GetNode(DstNId).InEIdV.AddSorted(EId);
1427  return EId;
1428 }
TInt MxEId
Definition: network.h:1152
#define IAssertR(Cond, Reason)
Definition: bd.h:265
static const T & Mx(const T &LVal, const T &RVal)
Definition: xmath.h:32
bool IsNode(const int &NId) const
Tests whether ID NId is a node.
Definition: network.h:1198
TSizeTy AddSorted(const TVal &Val, const bool &Asc=true, const TSizeTy &_MxVals=-1)
Adds element Val to a sorted vector.
Definition: ds.h:1063
TNode & GetNode(const int &NId)
Definition: network.h:1144
THash< TInt, TEdge > EdgeH
Definition: network.h:1154
bool IsEdge(const int &EId) const
Tests whether an edge with ID EId exists in the network.
Definition: network.h:1244
static TStr Fmt(const char *FmtStr,...)
Definition: dt.cpp:1599
TDat & AddDat(const TKey &Key)
Definition: hash.h:196
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 1234 of file network.h.

1234 { return AddEdge(EdgeI.GetSrcNId(), EdgeI.GetDstNId(), EdgeI.GetId(), EdgeI.GetDat()); }
int AddEdge(const int &SrcNId, const int &DstNId, int EId=-1)
Adds an edge between node IDs SrcNId and DstNId to the graph.
Definition: network.h:1407
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 1345 of file network.h.

1345  {
1346  if (NId == -1) {
1347  NId = MxNId; MxNId++;
1348  } else {
1349  IAssertR(!IsNode(NId), TStr::Fmt("NodeId %d already exists", NId));
1350  MxNId = TMath::Mx(NId+1, MxNId());
1351  }
1352  NodeH.AddDat(NId, TNode(NId));
1353  return NId;
1354 }
#define IAssertR(Cond, Reason)
Definition: bd.h:265
static const T & Mx(const T &LVal, const T &RVal)
Definition: xmath.h:32
bool IsNode(const int &NId) const
Tests whether ID NId is a node.
Definition: network.h:1198
TInt MxNId
Definition: network.h:1152
THash< TInt, TNode > NodeH
Definition: network.h:1153
static TStr Fmt(const char *FmtStr,...)
Definition: dt.cpp:1599
TDat & AddDat(const TKey &Key)
Definition: hash.h:196
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 1357 of file network.h.

1357  {
1358  if (NId == -1) {
1359  NId = MxNId; MxNId++;
1360  } else {
1361  IAssertR(!IsNode(NId), TStr::Fmt("NodeId %d already exists", NId));
1362  MxNId = TMath::Mx(NId+1, MxNId());
1363  }
1364  NodeH.AddDat(NId, TNode(NId, NodeDat));
1365  return NId;
1366 }
#define IAssertR(Cond, Reason)
Definition: bd.h:265
static const T & Mx(const T &LVal, const T &RVal)
Definition: xmath.h:32
bool IsNode(const int &NId) const
Tests whether ID NId is a node.
Definition: network.h:1198
TInt MxNId
Definition: network.h:1152
THash< TInt, TNode > NodeH
Definition: network.h:1153
static TStr Fmt(const char *FmtStr,...)
Definition: dt.cpp:1599
TDat & AddDat(const TKey &Key)
Definition: hash.h:196
template<class TNodeData, class TEdgeData>
int TNodeEdgeNet< TNodeData, TEdgeData >::AddNode ( const TNodeI NodeI)
inline

Definition at line 1190 of file network.h.

1190 { return AddNode(NodeI.GetId(), NodeI.GetDat()); }
int AddNode(int NId=-1)
Adds a node of ID NId to the network.
Definition: network.h:1345
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 1251 of file network.h.

1251 { return TEdgeI(EdgeH.BegI(), this); }
TIter BegI() const
Definition: hash.h:171
THash< TInt, TEdge > EdgeH
Definition: network.h:1154
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 1200 of file network.h.

1200 { return TNodeI(NodeH.BegI(), this); }
TIter BegI() const
Definition: hash.h:171
THash< TInt, TNode > NodeH
Definition: network.h:1153
template<class TNodeData, class TEdgeData>
void TNodeEdgeNet< TNodeData, TEdgeData >::Clr ( )
inline

Deletes all nodes and edges from the network.

Definition at line 1283 of file network.h.

1283 { MxNId=0; MxEId=0; NodeH.Clr(); EdgeH.Clr(); }
TInt MxEId
Definition: network.h:1152
TInt MxNId
Definition: network.h:1152
THash< TInt, TNode > NodeH
Definition: network.h:1153
THash< TInt, TEdge > EdgeH
Definition: network.h:1154
void Clr(const bool &DoDel=true, const int &NoDelLim=-1, const bool &ResetDat=true)
Definition: hash.h:319
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 1500 of file network.h.

1500  {
1501  for (int kid = NodeH.FFirstKeyId(); NodeH.FNextKeyId(kid);) {
1502  TNode& Node = NodeH[kid];
1503  Node.InEIdV.Pack(); Node.OutEIdV.Pack();
1504  }
1505  if (! OnlyNodeLinks && ! NodeH.IsKeyIdEqKeyN()) { NodeH.Defrag(); }
1506  if (! OnlyNodeLinks && ! EdgeH.IsKeyIdEqKeyN()) { EdgeH.Defrag(); }
1507 }
bool IsKeyIdEqKeyN() const
Definition: hash.h:191
void Defrag()
Definition: hash.h:513
bool FNextKeyId(int &KeyId) const
Definition: hash.h:436
THash< TInt, TNode > NodeH
Definition: network.h:1153
int FFirstKeyId() const
Definition: hash.h:236
THash< TInt, TEdge > EdgeH
Definition: network.h:1154
void Pack()
Definition: hash.h:247
template<class TNodeData , class TEdgeData >
void TNodeEdgeNet< TNodeData, TEdgeData >::DelEdge ( const int &  EId)

Deletes an edge with ID EId from the network.

Definition at line 1431 of file network.h.

1431  {
1432  IAssert(IsEdge(EId));
1433  const int SrcNId = GetEdge(EId).GetSrcNId();
1434  const int DstNId = GetEdge(EId).GetDstNId();
1435  GetNode(SrcNId).OutEIdV.DelIfIn(EId);
1436  GetNode(DstNId).InEIdV.DelIfIn(EId);
1437  EdgeH.DelKey(EId);
1438 }
#define IAssert(Cond)
Definition: bd.h:262
bool DelIfIn(const TVal &Val)
Removes the first occurrence of element Val.
Definition: ds.h:1151
void DelKey(const TKey &Key)
Definition: hash.h:362
TNode & GetNode(const int &NId)
Definition: network.h:1144
THash< TInt, TEdge > EdgeH
Definition: network.h:1154
bool IsEdge(const int &EId) const
Tests whether an edge with ID EId exists in the network.
Definition: network.h:1244
int GetDstNId() const
Definition: network.h:1030
int GetSrcNId() const
Definition: network.h:1029
TEdge & GetEdge(const int &EId)
Definition: network.h:1147
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 1441 of file network.h.

1441  {
1442  int EId;
1443  IAssert(IsEdge(SrcNId, DstNId, EId, IsDir));
1444  GetNode(SrcNId).OutEIdV.DelIfIn(EId);
1445  GetNode(DstNId).InEIdV.DelIfIn(EId);
1446  EdgeH.DelKey(EId);
1447 }
#define IAssert(Cond)
Definition: bd.h:262
bool DelIfIn(const TVal &Val)
Removes the first occurrence of element Val.
Definition: ds.h:1151
void DelKey(const TKey &Key)
Definition: hash.h:362
TNode & GetNode(const int &NId)
Definition: network.h:1144
THash< TInt, TEdge > EdgeH
Definition: network.h:1154
bool IsEdge(const int &EId) const
Tests whether an edge with ID EId exists in the network.
Definition: network.h:1244
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 1369 of file network.h.

1369  {
1370  const TNode& Node = GetNode(NId);
1371  for (int out = 0; out < Node.GetOutDeg(); out++) {
1372  const int EId = Node.GetOutEId(out);
1373  const TEdge& Edge = GetEdge(EId);
1374  IAssert(Edge.GetSrcNId() == NId);
1375  GetNode(Edge.GetDstNId()).InEIdV.DelIfIn(EId);
1376  EdgeH.DelKey(EId);
1377  }
1378  for (int in = 0; in < Node.GetInDeg(); in++) {
1379  const int EId = Node.GetInEId(in);
1380  const TEdge& Edge = GetEdge(EId);
1381  IAssert(Edge.GetDstNId() == NId);
1382  GetNode(Edge.GetSrcNId()).OutEIdV.DelIfIn(EId);
1383  EdgeH.DelKey(EId);
1384  }
1385  NodeH.DelKey(NId);
1386 }
#define IAssert(Cond)
Definition: bd.h:262
void DelKey(const TKey &Key)
Definition: hash.h:362
TNode & GetNode(const int &NId)
Definition: network.h:1144
THash< TInt, TNode > NodeH
Definition: network.h:1153
THash< TInt, TEdge > EdgeH
Definition: network.h:1154
TEdge & GetEdge(const int &EId)
Definition: network.h:1147
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 1196 of file network.h.

1196 { DelNode(NodeI.GetId()); }
void DelNode(const int &NId)
Deletes node of ID NId from the network.
Definition: network.h:1369
template<class TNodeData, class TEdgeData>
bool TNodeEdgeNet< TNodeData, TEdgeData >::Empty ( ) const
inline

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

Definition at line 1281 of file network.h.

1281 { return GetNodes()==0; }
int GetNodes() const
Returns the number of nodes in the network.
Definition: network.h:1175
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 1253 of file network.h.

1253 { return TEdgeI(EdgeH.EndI(), this); }
TIter EndI() const
Definition: hash.h:176
THash< TInt, TEdge > EdgeH
Definition: network.h:1154
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 1202 of file network.h.

1202 { return TNodeI(NodeH.EndI(), this); }
TIter EndI() const
Definition: hash.h:176
THash< TInt, TNode > NodeH
Definition: network.h:1153
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 1261 of file network.h.

1261 { return EdgeH.GetDat(EId).EdgeDat; }
TEdgeData EdgeDat
Definition: network.h:1019
const TDat & GetDat(const TKey &Key) const
Definition: hash.h:220
THash< TInt, TEdge > EdgeH
Definition: network.h:1154
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 1263 of file network.h.

1263 { return EdgeH.GetDat(EId).EdgeDat; }
TEdgeData EdgeDat
Definition: network.h:1019
const TDat & GetDat(const TKey &Key) const
Definition: hash.h:220
THash< TInt, TEdge > EdgeH
Definition: network.h:1154
template<class TNodeData, class TEdgeData>
TEdge& TNodeEdgeNet< TNodeData, TEdgeData >::GetEdge ( const int &  EId)
inlineprivate

Definition at line 1147 of file network.h.

1147 { return EdgeH.GetDat(EId); }
const TDat & GetDat(const TKey &Key) const
Definition: hash.h:220
THash< TInt, TEdge > EdgeH
Definition: network.h:1154
template<class TNodeData, class TEdgeData>
const TEdge& TNodeEdgeNet< TNodeData, TEdgeData >::GetEdge ( const int &  EId) const
inlineprivate

Definition at line 1148 of file network.h.

1148 { return EdgeH.GetDat(EId); }
const TDat & GetDat(const TKey &Key) const
Definition: hash.h:220
THash< TInt, TEdge > EdgeH
Definition: network.h:1154
template<class TNodeData, class TEdgeData>
const TEdge& TNodeEdgeNet< TNodeData, TEdgeData >::GetEdgeKId ( const int &  EdgeKeyId) const
inlineprivate

Definition at line 1149 of file network.h.

1149 { return EdgeH[EdgeKeyId]; }
THash< TInt, TEdge > EdgeH
Definition: network.h:1154
template<class TNodeData, class TEdgeData>
int TNodeEdgeNet< TNodeData, TEdgeData >::GetEdges ( ) const
inline

Returns the number of edges in the network.

Definition at line 1216 of file network.h.

1216 { return EdgeH.Len(); }
THash< TInt, TEdge > EdgeH
Definition: network.h:1154
int Len() const
Definition: hash.h:186
template<class TNodeData, class TEdgeData>
TEdgeI TNodeEdgeNet< TNodeData, TEdgeData >::GetEI ( const int &  EId) const
inline

Not supported/implemented!

Definition at line 1255 of file network.h.

1255 { return TEdgeI(EdgeH.GetI(EId), this); }
THash< TInt, TEdge > EdgeH
Definition: network.h:1154
TIter GetI(const TKey &Key) const
Definition: hash.h:178
template<class TNodeData, class TEdgeData>
TEdgeI TNodeEdgeNet< TNodeData, TEdgeData >::GetEI ( const int &  SrcNId,
const int &  DstNId 
) const
inline

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

Definition at line 1257 of file network.h.

1257 { return GetEI(GetEId(SrcNId, DstNId)); }
TEdgeI GetEI(const int &EId) const
Not supported/implemented!
Definition: network.h:1255
int GetEId(const int &SrcNId, const int &DstNId) const
Definition: network.h:1249
template<class TNodeData, class TEdgeData>
int TNodeEdgeNet< TNodeData, TEdgeData >::GetEId ( const int &  SrcNId,
const int &  DstNId 
) const
inline

Definition at line 1249 of file network.h.

1249 { int EId; return IsEdge(SrcNId, DstNId, EId)?EId:-1; }
bool IsEdge(const int &EId) const
Tests whether an edge with ID EId exists in the network.
Definition: network.h:1244
template<class TNodeData , class TEdgeData >
void TNodeEdgeNet< TNodeData, TEdgeData >::GetEIdV ( TIntV EIdV) const

Returns a vector of all edge IDs in the network.

Definition at line 1492 of file network.h.

1492  {
1493  EIdV.Gen(GetEdges(), 0);
1494  for (int E=EdgeH.FFirstKeyId(); EdgeH.FNextKeyId(E);) {
1495  EIdV.Add(EdgeH.GetKey(E));
1496  }
1497 }
bool FNextKeyId(int &KeyId) const
Definition: hash.h:436
int FFirstKeyId() const
Definition: hash.h:236
THash< TInt, TEdge > EdgeH
Definition: network.h:1154
int GetEdges() const
Returns the number of edges in the network.
Definition: network.h:1216
void Gen(const TSizeTy &_Vals)
Constructs a vector (an array) of _Vals elements.
Definition: ds.h:495
TSizeTy Add()
Adds a new element at the end of the vector, after its current last element.
Definition: ds.h:574
const TKey & GetKey(const int &KeyId) const
Definition: hash.h:210
template<class TNodeData, class TEdgeData>
int TNodeEdgeNet< TNodeData, TEdgeData >::GetMxNId ( ) const
inline

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

Definition at line 1212 of file network.h.

1212 { return MxNId; }
TInt MxNId
Definition: network.h:1152
template<class TNodeData, class TEdgeData>
TNodeData& TNodeEdgeNet< TNodeData, TEdgeData >::GetNDat ( const int &  NId)
inline

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

Definition at line 1208 of file network.h.

1208 { return NodeH.GetDat(NId).NodeDat; }
const TDat & GetDat(const TKey &Key) const
Definition: hash.h:220
TNodeData NodeDat
Definition: network.h:992
THash< TInt, TNode > NodeH
Definition: network.h:1153
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 1210 of file network.h.

1210 { return NodeH.GetDat(NId).NodeDat; }
const TDat & GetDat(const TKey &Key) const
Definition: hash.h:220
TNodeData NodeDat
Definition: network.h:992
THash< TInt, TNode > NodeH
Definition: network.h:1153
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 1204 of file network.h.

1204 { return TNodeI(NodeH.GetI(NId), this); }
THash< TInt, TNode > NodeH
Definition: network.h:1153
TIter GetI(const TKey &Key) const
Definition: hash.h:178
template<class TNodeData , class TEdgeData >
void TNodeEdgeNet< TNodeData, TEdgeData >::GetNIdV ( TIntV NIdV) const

Returns a vector of all node IDs in the network.

Definition at line 1484 of file network.h.

1484  {
1485  NIdV.Gen(GetNodes(), 0);
1486  for (int N=NodeH.FFirstKeyId(); NodeH.FNextKeyId(N);) {
1487  NIdV.Add(NodeH.GetKey(N));
1488  }
1489 }
int GetNodes() const
Returns the number of nodes in the network.
Definition: network.h:1175
bool FNextKeyId(int &KeyId) const
Definition: hash.h:436
THash< TInt, TNode > NodeH
Definition: network.h:1153
int FFirstKeyId() const
Definition: hash.h:236
void Gen(const TSizeTy &_Vals)
Constructs a vector (an array) of _Vals elements.
Definition: ds.h:495
TSizeTy Add()
Adds a new element at the end of the vector, after its current last element.
Definition: ds.h:574
const TKey & GetKey(const int &KeyId) const
Definition: hash.h:210
template<class TNodeData, class TEdgeData>
TNode& TNodeEdgeNet< TNodeData, TEdgeData >::GetNode ( const int &  NId)
inlineprivate

Definition at line 1144 of file network.h.

1144 { return NodeH.GetDat(NId); }
const TDat & GetDat(const TKey &Key) const
Definition: hash.h:220
THash< TInt, TNode > NodeH
Definition: network.h:1153
template<class TNodeData, class TEdgeData>
const TNode& TNodeEdgeNet< TNodeData, TEdgeData >::GetNode ( const int &  NId) const
inlineprivate

Definition at line 1145 of file network.h.

1145 { return NodeH.GetDat(NId); }
const TDat & GetDat(const TKey &Key) const
Definition: hash.h:220
THash< TInt, TNode > NodeH
Definition: network.h:1153
template<class TNodeData, class TEdgeData>
const TNode& TNodeEdgeNet< TNodeData, TEdgeData >::GetNodeKId ( const int &  NodeKeyId) const
inlineprivate

Definition at line 1146 of file network.h.

1146 { return NodeH[NodeKeyId]; }
THash< TInt, TNode > NodeH
Definition: network.h:1153
template<class TNodeData, class TEdgeData>
int TNodeEdgeNet< TNodeData, TEdgeData >::GetNodes ( ) const
inline

Returns the number of nodes in the network.

Definition at line 1175 of file network.h.

1175 { return NodeH.Len(); }
THash< TInt, TNode > NodeH
Definition: network.h:1153
int Len() const
Definition: hash.h:186
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 1274 of file network.h.

1274 { return GetEI(GetRndEId(Rnd)); }
TEdgeI GetEI(const int &EId) const
Not supported/implemented!
Definition: network.h:1255
int GetRndEId(TRnd &Rnd=TInt::Rnd)
Returns an ID of a random edge in the network.
Definition: network.h:1272
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 1272 of file network.h.

1272 { return EdgeH.GetKey(EdgeH.GetRndKeyId(Rnd, 0.8)); }
THash< TInt, TEdge > EdgeH
Definition: network.h:1154
int GetRndKeyId(TRnd &Rnd) const
Get an index of a random element. If the hash table has many deleted keys, this may take a long time...
Definition: hash.h:402
const TKey & GetKey(const int &KeyId) const
Definition: hash.h:210
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 1270 of file network.h.

1270 { return GetNI(GetRndNId(Rnd)); }
int GetRndNId(TRnd &Rnd=TInt::Rnd)
Returns an ID of a random node in the network.
Definition: network.h:1268
TNodeI GetNI(const int &NId) const
Returns an iterator referring to the node of ID NId in the network.
Definition: network.h:1204
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 1268 of file network.h.

1268 { return NodeH.GetKey(NodeH.GetRndKeyId(Rnd, 0.8)); }
THash< TInt, TNode > NodeH
Definition: network.h:1153
int GetRndKeyId(TRnd &Rnd) const
Get an index of a random element. If the hash table has many deleted keys, this may take a long time...
Definition: hash.h:402
const TKey & GetKey(const int &KeyId) const
Definition: hash.h:210
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 1395 of file network.h.

1395  {
1396  TIntPrSet UniqESet(GetEdges());
1397  for (TEdgeI EI = BegEI(); EI < EndEI(); EI++) {
1398  const int Src = EI.GetSrcNId();
1399  const int Dst = EI.GetDstNId();
1400  if (IsDir) { UniqESet.AddKey(TIntPr(Src, Dst)); }
1401  else { UniqESet.AddKey(TIntPr(TMath::Mn(Src, Dst), TMath::Mx(Src, Dst))); }
1402  }
1403  return UniqESet.Len();
1404 }
static const T & Mn(const T &LVal, const T &RVal)
Definition: xmath.h:36
TPair< TInt, TInt > TIntPr
Definition: ds.h:83
TEdgeI BegEI() const
Returns an iterator referring to the first edge in the network.
Definition: network.h:1251
static const T & Mx(const T &LVal, const T &RVal)
Definition: xmath.h:32
int GetEdges() const
Returns the number of edges in the network.
Definition: network.h:1216
TEdgeI EndEI() const
Returns an iterator referring to the past-the-end edge in the network.
Definition: network.h:1253
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 1320 of file network.h.

1320  {
1321  return HasGraphFlag(typename TNet, Flag);
1322 }
#define HasGraphFlag(TGraph, Flag)
For quick testing of the properties of the graph/network object (see TGraphFlag). ...
Definition: gbase.h:41
TNodeEdgeNet< TNodeData, TEdgeData > TNet
Definition: network.h:985
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 1244 of file network.h.

1244 { return EdgeH.IsKey(EId); }
THash< TInt, TEdge > EdgeH
Definition: network.h:1154
bool IsKey(const TKey &Key) const
Definition: hash.h:216
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 1246 of file network.h.

1246 { int EId; return IsEdge(SrcNId, DstNId, EId, IsDir); }
bool IsEdge(const int &EId) const
Tests whether an edge with ID EId exists in the network.
Definition: network.h:1244
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 1450 of file network.h.

1450  {
1451  if (! IsNode(SrcNId)) { return false; }
1452  if (! IsNode(DstNId)) { return false; }
1453  const TNode& SrcNode = GetNode(SrcNId);
1454  for (int edge = 0; edge < SrcNode.GetOutDeg(); edge++) {
1455  const TEdge& Edge = GetEdge(SrcNode.GetOutEId(edge));
1456  if (DstNId == Edge.GetDstNId()) {
1457  EId = Edge.GetId(); return true; }
1458  }
1459  if (! IsDir) {
1460  for (int edge = 0; edge < SrcNode.GetInDeg(); edge++) {
1461  const TEdge& Edge = GetEdge(SrcNode.GetInEId(edge));
1462  if (DstNId == Edge.GetSrcNId()) {
1463  EId = Edge.GetId(); return true; }
1464  }
1465  }
1466  return false;
1467 }
bool IsNode(const int &NId) const
Tests whether ID NId is a node.
Definition: network.h:1198
TNode & GetNode(const int &NId)
Definition: network.h:1144
int GetId() const
Definition: network.h:1028
TEdge & GetEdge(const int &EId)
Definition: network.h:1147
template<class TNodeData, class TEdgeData>
bool TNodeEdgeNet< TNodeData, TEdgeData >::IsNode ( const int &  NId) const
inline

Tests whether ID NId is a node.

Definition at line 1198 of file network.h.

1198 { return NodeH.IsKey(NId); }
THash< TInt, TNode > NodeH
Definition: network.h:1153
bool IsKey(const TKey &Key) const
Definition: hash.h:216
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 1510 of file network.h.

1510  {
1511  bool RetVal = true;
1512  for (int N = NodeH.FFirstKeyId(); NodeH.FNextKeyId(N); ) {
1513  const TNode& Node = NodeH[N];
1514  if (! Node.OutEIdV.IsSorted()) {
1515  const TStr Msg = TStr::Fmt("Out-edge list of node %d is not sorted.", Node.GetId());
1516  if (ThrowExcept) { EAssertR(false, Msg); } else { ErrNotify(Msg.CStr()); } RetVal=false;
1517  }
1518  if (! Node.InEIdV.IsSorted()) {
1519  const TStr Msg = TStr::Fmt("In-edge list of node %d is not sorted.", Node.GetId());
1520  if (ThrowExcept) { EAssertR(false, Msg); } else { ErrNotify(Msg.CStr()); } RetVal=false;
1521  }
1522  // check out-edge ids
1523  int prevEId = -1;
1524  for (int e = 0; e < Node.GetOutDeg(); e++) {
1525  if (! IsEdge(Node.GetOutEId(e))) {
1526  const TStr Msg = TStr::Fmt("Out-edge id %d of node %d does not exist.", Node.GetOutEId(e), Node.GetId());
1527  if (ThrowExcept) { EAssertR(false, Msg); } else { ErrNotify(Msg.CStr()); } RetVal=false;
1528  }
1529  if (e > 0 && prevEId == Node.GetOutEId(e)) {
1530  const TStr Msg = TStr::Fmt("Node %d has duplidate out-edge id %d.", Node.GetId(), Node.GetOutEId(e));
1531  if (ThrowExcept) { EAssertR(false, Msg); } else { ErrNotify(Msg.CStr()); } RetVal=false;
1532  }
1533  prevEId = Node.GetOutEId(e);
1534  }
1535  // check in-edge ids
1536  prevEId = -1;
1537  for (int e = 0; e < Node.GetInDeg(); e++) {
1538  if (! IsEdge(Node.GetInEId(e))) {
1539  const TStr Msg = TStr::Fmt("Out-edge id %d of node %d does not exist.", Node.GetInEId(e), Node.GetId());
1540  if (ThrowExcept) { EAssertR(false, Msg); } else { ErrNotify(Msg.CStr()); } RetVal=false;
1541  }
1542  if (e > 0 && prevEId == Node.GetInEId(e)) {
1543  const TStr Msg = TStr::Fmt("Node %d has duplidate out-edge id %d.", Node.GetId(), Node.GetInEId(e));
1544  if (ThrowExcept) { EAssertR(false, Msg); } else { ErrNotify(Msg.CStr()); } RetVal=false;
1545  }
1546  prevEId = Node.GetInEId(e);
1547  }
1548  }
1549  for (int E = EdgeH.FFirstKeyId(); EdgeH.FNextKeyId(E); ) {
1550  const TEdge& Edge = EdgeH[E];
1551  if (! IsNode(Edge.GetSrcNId())) {
1552  const TStr Msg = TStr::Fmt("Edge %d source node %d does not exist.", Edge.GetId(), Edge.GetSrcNId());
1553  if (ThrowExcept) { EAssertR(false, Msg); } else { ErrNotify(Msg.CStr()); } RetVal=false;
1554  }
1555  if (! IsNode(Edge.GetDstNId())) {
1556  const TStr Msg = TStr::Fmt("Edge %d destination node %d does not exist.", Edge.GetId(), Edge.GetDstNId());
1557  if (ThrowExcept) { EAssertR(false, Msg); } else { ErrNotify(Msg.CStr()); } RetVal=false;
1558  }
1559  }
1560  return RetVal;
1561 }
bool IsNode(const int &NId) const
Tests whether ID NId is a node.
Definition: network.h:1198
void ErrNotify(const char *NotifyCStr)
Definition: bd.h:74
bool FNextKeyId(int &KeyId) const
Definition: hash.h:436
THash< TInt, TNode > NodeH
Definition: network.h:1153
int FFirstKeyId() const
Definition: hash.h:236
THash< TInt, TEdge > EdgeH
Definition: network.h:1154
bool IsEdge(const int &EId) const
Tests whether an edge with ID EId exists in the network.
Definition: network.h:1244
Definition: dt.h:412
static TStr Fmt(const char *FmtStr,...)
Definition: dt.cpp:1599
#define EAssertR(Cond, MsgStr)
Definition: bd.h:283
char * CStr()
Definition: dt.h:476
template<class TNodeData, class TEdgeData>
static PNet TNodeEdgeNet< TNodeData, TEdgeData >::Load ( TSIn SIn)
inlinestatic

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

Definition at line 1168 of file network.h.

1168 { return PNet(new TNet(SIn)); }
TNodeEdgeNet< TNodeData, TEdgeData > TNet
Definition: network.h:985
TPt< TNet > PNet
Definition: network.h:986
template<class TNodeData, class TEdgeData>
static PNet TNodeEdgeNet< TNodeData, TEdgeData >::New ( )
inlinestatic

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

Definition at line 1166 of file network.h.

1166 { return PNet(new TNet()); }
TNodeEdgeNet< TNodeData, TEdgeData > TNet
Definition: network.h:985
TPt< TNet > PNet
Definition: network.h:986
template<class TNodeData, class TEdgeData>
TNodeEdgeNet& TNodeEdgeNet< TNodeData, TEdgeData >::operator= ( const TNodeEdgeNet< TNodeData, TEdgeData > &  Net)
inline

Definition at line 1171 of file network.h.

1171  {
1172  if (this!=&Net) { NodeH=Net.NodeH; EdgeH=Net.EdgeH; MxNId=Net.MxNId; MxEId=Net.MxEId; } return *this; }
TInt MxEId
Definition: network.h:1152
TInt MxNId
Definition: network.h:1152
THash< TInt, TNode > NodeH
Definition: network.h:1153
THash< TInt, TEdge > EdgeH
Definition: network.h:1154
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 1285 of file network.h.

1285  {
1286  if (Nodes>0) { NodeH.Gen(Nodes/2); } if (Edges>0) { EdgeH.Gen(Edges/2); } }
void Gen(const int &ExpectVals)
Definition: hash.h:180
THash< TInt, TNode > NodeH
Definition: network.h:1153
THash< TInt, TEdge > EdgeH
Definition: network.h:1154
template<class TNodeData, class TEdgeData>
virtual void TNodeEdgeNet< TNodeData, TEdgeData >::Save ( TSOut SOut) const
inlinevirtual

Saves the network to a (binary) stream SOut.

Reimplemented in TTimeNENet.

Definition at line 1164 of file network.h.

1164 { MxNId.Save(SOut); MxEId.Save(SOut); NodeH.Save(SOut); EdgeH.Save(SOut); }
TInt MxEId
Definition: network.h:1152
void Save(TSOut &SOut) const
Definition: dt.h:1060
void Save(TSOut &SOut) const
Definition: hash.h:141
TInt MxNId
Definition: network.h:1152
THash< TInt, TNode > NodeH
Definition: network.h:1153
THash< TInt, TEdge > EdgeH
Definition: network.h:1154
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 1476 of file network.h.

1476  {
1477  for (TEdgeI EI = BegEI(); EI < EndEI(); EI++) {
1478  EI() = EdgeDat;
1479  }
1480 }
TEdgeI BegEI() const
Returns an iterator referring to the first edge in the network.
Definition: network.h:1251
TEdgeI EndEI() const
Returns an iterator referring to the past-the-end edge in the network.
Definition: network.h:1253
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 1470 of file network.h.

1470  {
1471  IAssertR(IsEdge(EId), TStr::Fmt("EdgeId %d does not exist.", EId).CStr());
1472  GetEI(EId).GetDat() = EdgeDat;
1473 }
#define IAssertR(Cond, Reason)
Definition: bd.h:265
TEdgeI GetEI(const int &EId) const
Not supported/implemented!
Definition: network.h:1255
const TEdgeData & GetDat() const
Definition: network.h:1134
bool IsEdge(const int &EId) const
Tests whether an edge with ID EId exists in the network.
Definition: network.h:1244
static TStr Fmt(const char *FmtStr,...)
Definition: dt.cpp:1599
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 1389 of file network.h.

1389  {
1390  IAssertR(IsNode(NId), TStr::Fmt("NodeId %d does not exist.", NId).CStr());
1391  NodeH.GetDat(NId).NodeDat = NodeDat;
1392 }
#define IAssertR(Cond, Reason)
Definition: bd.h:265
bool IsNode(const int &NId) const
Tests whether ID NId is a node.
Definition: network.h:1198
const TDat & GetDat(const TKey &Key) const
Definition: hash.h:220
TNodeData NodeDat
Definition: network.h:992
THash< TInt, TNode > NodeH
Definition: network.h:1153
static TStr Fmt(const char *FmtStr,...)
Definition: dt.cpp:1599
template<class TNodeData, class TEdgeData>
void TNodeEdgeNet< TNodeData, TEdgeData >::SortEIdByDat ( const bool &  Asc = true)
inline

Sorts edges by edge data.

Definition at line 1294 of file network.h.

1294 { EdgeH.SortByDat(Asc); }
THash< TInt, TEdge > EdgeH
Definition: network.h:1154
void SortByDat(const bool &Asc=true)
Definition: hash.h:250
template<class TNodeData, class TEdgeData>
void TNodeEdgeNet< TNodeData, TEdgeData >::SortEIdById ( const bool &  Asc = true)
inline

Sorts edges by edge IDs.

Definition at line 1292 of file network.h.

1292 { EdgeH.SortByKey(Asc); }
THash< TInt, TEdge > EdgeH
Definition: network.h:1154
void SortByKey(const bool &Asc=true)
Definition: hash.h:249
template<class TNodeData, class TEdgeData>
void TNodeEdgeNet< TNodeData, TEdgeData >::SortNIdByDat ( const bool &  Asc = true)
inline

Sorts nodes by node data.

Definition at line 1290 of file network.h.

1290 { NodeH.SortByDat(Asc); }
THash< TInt, TNode > NodeH
Definition: network.h:1153
void SortByDat(const bool &Asc=true)
Definition: hash.h:250
template<class TNodeData, class TEdgeData>
void TNodeEdgeNet< TNodeData, TEdgeData >::SortNIdById ( const bool &  Asc = true)
inline

Sorts nodes by node IDs.

Definition at line 1288 of file network.h.

1288 { NodeH.SortByKey(Asc); }
THash< TInt, TNode > NodeH
Definition: network.h:1153
void SortByKey(const bool &Asc=true)
Definition: hash.h:249

Friends And Related Function Documentation

template<class TNodeData, class TEdgeData>
friend class TCrossNet
friend

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

Definition at line 1189 of file network.h.

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

Definition at line 1308 of file network.h.

Member Data Documentation

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

Definition at line 1151 of file network.h.

template<class TNodeData, class TEdgeData>
THash<TInt, TEdge> TNodeEdgeNet< TNodeData, TEdgeData >::EdgeH
protected

Definition at line 1154 of file network.h.

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

Definition at line 1152 of file network.h.

template<class TNodeData, class TEdgeData>
TInt TNodeEdgeNet< TNodeData, TEdgeData >::MxNId
protected

Definition at line 1152 of file network.h.

template<class TNodeData, class TEdgeData>
THash<TInt, TNode> TNodeEdgeNet< TNodeData, TEdgeData >::NodeH
protected

Definition at line 1153 of file network.h.


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