SNAP Library 2.4, User Reference  2015-05-11 19:40:56
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)
 Adds a node NodeI and its node data to the network. More...
 
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 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

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

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.

1153 : CRef(), MxNId(0), MxEId(0) { }
TInt MxEId
Definition: network.h:1149
TCRef CRef
Definition: network.h:1148
TInt MxNId
Definition: network.h:1149
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 1155 of file network.h.

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

Definition at line 1156 of file network.h.

1156 : MxNId(Net.MxNId), MxEId(Net.MxEId), NodeH(Net.NodeH), EdgeH(Net.EdgeH) { }
TInt MxEId
Definition: network.h:1149
TInt MxNId
Definition: network.h:1149
THash< TInt, TNode > NodeH
Definition: network.h:1150
THash< TInt, TEdge > EdgeH
Definition: network.h:1151
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.

1158 : MxNId(SIn), MxEId(SIn), NodeH(SIn), EdgeH(SIn) { }
TInt MxEId
Definition: network.h:1149
TInt MxNId
Definition: network.h:1149
THash< TInt, TNode > NodeH
Definition: network.h:1150
THash< TInt, TEdge > EdgeH
Definition: network.h:1151
template<class TNodeData, class TEdgeData>
virtual TNodeEdgeNet< TNodeData, TEdgeData >::~TNodeEdgeNet ( )
inlinevirtual

Definition at line 1159 of file network.h.

1159 { }

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.

1403  {
1404  if (EId == -1) { EId = MxEId; MxEId++; }
1405  else { MxEId = TMath::Mx(EId+1, MxEId()); }
1406  IAssertR(!IsEdge(EId), TStr::Fmt("EdgeId %d already exists", EId));
1407  IAssertR(IsNode(SrcNId) && IsNode(DstNId), TStr::Fmt("%d or %d not a node.", SrcNId, DstNId).CStr());
1408  EdgeH.AddDat(EId, TEdge(EId, SrcNId, DstNId));
1409  GetNode(SrcNId).OutEIdV.AddSorted(EId);
1410  GetNode(DstNId).InEIdV.AddSorted(EId);
1411  return EId;
1412 }
TInt MxEId
Definition: network.h:1149
#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:1194
TSizeTy AddSorted(const TVal &Val, const bool &Asc=true, const TSizeTy &_MxVals=-1)
Adds element Val to a sorted vector.
Definition: ds.h:1027
TNode & GetNode(const int &NId)
Definition: network.h:1141
THash< TInt, TEdge > EdgeH
Definition: network.h:1151
bool IsEdge(const int &EId) const
Tests whether an edge with ID EId exists in the network.
Definition: network.h:1240
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 1415 of file network.h.

1415  {
1416  if (EId == -1) { EId = MxEId; MxEId++; }
1417  else { MxEId = TMath::Mx(EId+1, MxEId()); }
1418  IAssertR(!IsEdge(EId), TStr::Fmt("EdgeId %d already exists", EId));
1419  IAssertR(IsNode(SrcNId) && IsNode(DstNId), TStr::Fmt("%d or %d not a node.", SrcNId, DstNId).CStr());
1420  EdgeH.AddDat(EId, TEdge(EId, SrcNId, DstNId, EdgeDat));
1421  GetNode(SrcNId).OutEIdV.AddSorted(EId);
1422  GetNode(DstNId).InEIdV.AddSorted(EId);
1423  return EId;
1424 }
TInt MxEId
Definition: network.h:1149
#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:1194
TSizeTy AddSorted(const TVal &Val, const bool &Asc=true, const TSizeTy &_MxVals=-1)
Adds element Val to a sorted vector.
Definition: ds.h:1027
TNode & GetNode(const int &NId)
Definition: network.h:1141
THash< TInt, TEdge > EdgeH
Definition: network.h:1151
bool IsEdge(const int &EId) const
Tests whether an edge with ID EId exists in the network.
Definition: network.h:1240
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 1230 of file network.h.

1230 { 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:1403
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.

1341  {
1342  if (NId == -1) {
1343  NId = MxNId; MxNId++;
1344  } else {
1345  IAssertR(!IsNode(NId), TStr::Fmt("NodeId %d already exists", NId));
1346  MxNId = TMath::Mx(NId+1, MxNId());
1347  }
1348  NodeH.AddDat(NId, TNode(NId));
1349  return NId;
1350 }
#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:1194
TInt MxNId
Definition: network.h:1149
THash< TInt, TNode > NodeH
Definition: network.h:1150
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 1353 of file network.h.

1353  {
1354  if (NId == -1) {
1355  NId = MxNId; MxNId++;
1356  } else {
1357  IAssertR(!IsNode(NId), TStr::Fmt("NodeId %d already exists", NId));
1358  MxNId = TMath::Mx(NId+1, MxNId());
1359  }
1360  NodeH.AddDat(NId, TNode(NId, NodeDat));
1361  return NId;
1362 }
#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:1194
TInt MxNId
Definition: network.h:1149
THash< TInt, TNode > NodeH
Definition: network.h:1150
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

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

Definition at line 1186 of file network.h.

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

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

1196 { return TNodeI(NodeH.BegI(), this); }
TIter BegI() const
Definition: hash.h:171
THash< TInt, TNode > NodeH
Definition: network.h:1150
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.

1279 { MxNId=0; MxEId=0; NodeH.Clr(); EdgeH.Clr(); }
TInt MxEId
Definition: network.h:1149
TInt MxNId
Definition: network.h:1149
THash< TInt, TNode > NodeH
Definition: network.h:1150
THash< TInt, TEdge > EdgeH
Definition: network.h:1151
void Clr(const bool &DoDel=true, const int &NoDelLim=-1, const bool &ResetDat=true)
Definition: hash.h:315
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.

1496  {
1497  for (int kid = NodeH.FFirstKeyId(); NodeH.FNextKeyId(kid);) {
1498  TNode& Node = NodeH[kid];
1499  Node.InEIdV.Pack(); Node.OutEIdV.Pack();
1500  }
1501  if (! OnlyNodeLinks && ! NodeH.IsKeyIdEqKeyN()) { NodeH.Defrag(); }
1502  if (! OnlyNodeLinks && ! EdgeH.IsKeyIdEqKeyN()) { EdgeH.Defrag(); }
1503 }
bool IsKeyIdEqKeyN() const
Definition: hash.h:191
void Defrag()
Definition: hash.h:509
bool FNextKeyId(int &KeyId) const
Definition: hash.h:432
THash< TInt, TNode > NodeH
Definition: network.h:1150
int FFirstKeyId() const
Definition: hash.h:232
THash< TInt, TEdge > EdgeH
Definition: network.h:1151
void Pack()
Definition: hash.h:243
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 1427 of file network.h.

1427  {
1428  IAssert(IsEdge(EId));
1429  const int SrcNId = GetEdge(EId).GetSrcNId();
1430  const int DstNId = GetEdge(EId).GetDstNId();
1431  GetNode(SrcNId).OutEIdV.DelIfIn(EId);
1432  GetNode(DstNId).InEIdV.DelIfIn(EId);
1433  EdgeH.DelKey(EId);
1434 }
#define IAssert(Cond)
Definition: bd.h:262
bool DelIfIn(const TVal &Val)
Removes the first occurrence of element Val.
Definition: ds.h:1115
void DelKey(const TKey &Key)
Definition: hash.h:358
TNode & GetNode(const int &NId)
Definition: network.h:1141
THash< TInt, TEdge > EdgeH
Definition: network.h:1151
bool IsEdge(const int &EId) const
Tests whether an edge with ID EId exists in the network.
Definition: network.h:1240
int GetDstNId() const
Definition: network.h:1027
int GetSrcNId() const
Definition: network.h:1026
TEdge & GetEdge(const int &EId)
Definition: network.h:1144
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.

1437  {
1438  int EId;
1439  IAssert(IsEdge(SrcNId, DstNId, EId, IsDir));
1440  GetNode(SrcNId).OutEIdV.DelIfIn(EId);
1441  GetNode(DstNId).InEIdV.DelIfIn(EId);
1442  EdgeH.DelKey(EId);
1443 }
#define IAssert(Cond)
Definition: bd.h:262
bool DelIfIn(const TVal &Val)
Removes the first occurrence of element Val.
Definition: ds.h:1115
void DelKey(const TKey &Key)
Definition: hash.h:358
TNode & GetNode(const int &NId)
Definition: network.h:1141
THash< TInt, TEdge > EdgeH
Definition: network.h:1151
bool IsEdge(const int &EId) const
Tests whether an edge with ID EId exists in the network.
Definition: network.h:1240
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.

1365  {
1366  const TNode& Node = GetNode(NId);
1367  for (int out = 0; out < Node.GetOutDeg(); out++) {
1368  const int EId = Node.GetOutEId(out);
1369  const TEdge& Edge = GetEdge(EId);
1370  IAssert(Edge.GetSrcNId() == NId);
1371  GetNode(Edge.GetDstNId()).InEIdV.DelIfIn(EId);
1372  EdgeH.DelKey(EId);
1373  }
1374  for (int in = 0; in < Node.GetInDeg(); in++) {
1375  const int EId = Node.GetInEId(in);
1376  const TEdge& Edge = GetEdge(EId);
1377  IAssert(Edge.GetDstNId() == NId);
1378  GetNode(Edge.GetSrcNId()).OutEIdV.DelIfIn(EId);
1379  EdgeH.DelKey(EId);
1380  }
1381  NodeH.DelKey(NId);
1382 }
#define IAssert(Cond)
Definition: bd.h:262
void DelKey(const TKey &Key)
Definition: hash.h:358
TNode & GetNode(const int &NId)
Definition: network.h:1141
THash< TInt, TNode > NodeH
Definition: network.h:1150
THash< TInt, TEdge > EdgeH
Definition: network.h:1151
TEdge & GetEdge(const int &EId)
Definition: network.h:1144
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.

1192 { DelNode(NodeI.GetId()); }
void DelNode(const int &NId)
Deletes node of ID NId from the network.
Definition: network.h:1365
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.

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

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

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

1257 { return EdgeH.GetDat(EId).EdgeDat; }
TEdgeData EdgeDat
Definition: network.h:1016
const TDat & GetDat(const TKey &Key) const
Definition: hash.h:220
THash< TInt, TEdge > EdgeH
Definition: network.h:1151
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.

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

Definition at line 1144 of file network.h.

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

Definition at line 1145 of file network.h.

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

Definition at line 1146 of file network.h.

1146 { return EdgeH[EdgeKeyId]; }
THash< TInt, TEdge > EdgeH
Definition: network.h:1151
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.

1212 { return EdgeH.Len(); }
THash< TInt, TEdge > EdgeH
Definition: network.h:1151
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 1251 of file network.h.

1251 { return TEdgeI(EdgeH.GetI(EId), this); }
THash< TInt, TEdge > EdgeH
Definition: network.h:1151
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 1253 of file network.h.

1253 { return GetEI(GetEId(SrcNId, DstNId)); }
TEdgeI GetEI(const int &EId) const
Not supported/implemented!
Definition: network.h:1251
int GetEId(const int &SrcNId, const int &DstNId) const
Definition: network.h:1245
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.

1245 { 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:1240
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 1488 of file network.h.

1488  {
1489  EIdV.Gen(GetEdges(), 0);
1490  for (int E=EdgeH.FFirstKeyId(); EdgeH.FNextKeyId(E);) {
1491  EIdV.Add(EdgeH.GetKey(E));
1492  }
1493 }
bool FNextKeyId(int &KeyId) const
Definition: hash.h:432
int FFirstKeyId() const
Definition: hash.h:232
THash< TInt, TEdge > EdgeH
Definition: network.h:1151
int GetEdges() const
Returns the number of edges in the network.
Definition: network.h:1212
void Gen(const TSizeTy &_Vals)
Constructs a vector (an array) of _Vals elements.
Definition: ds.h:486
TSizeTy Add()
Adds a new element at the end of the vector, after its current last element.
Definition: ds.h:559
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 1208 of file network.h.

1208 { return MxNId; }
TInt MxNId
Definition: network.h:1149
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 1204 of file network.h.

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

1206 { return NodeH.GetDat(NId).NodeDat; }
const TDat & GetDat(const TKey &Key) const
Definition: hash.h:220
TNodeData NodeDat
Definition: network.h:989
THash< TInt, TNode > NodeH
Definition: network.h:1150
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.

1200 { return TNodeI(NodeH.GetI(NId), this); }
THash< TInt, TNode > NodeH
Definition: network.h:1150
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 1480 of file network.h.

1480  {
1481  NIdV.Gen(GetNodes(), 0);
1482  for (int N=NodeH.FFirstKeyId(); NodeH.FNextKeyId(N);) {
1483  NIdV.Add(NodeH.GetKey(N));
1484  }
1485 }
int GetNodes() const
Returns the number of nodes in the network.
Definition: network.h:1172
bool FNextKeyId(int &KeyId) const
Definition: hash.h:432
THash< TInt, TNode > NodeH
Definition: network.h:1150
int FFirstKeyId() const
Definition: hash.h:232
void Gen(const TSizeTy &_Vals)
Constructs a vector (an array) of _Vals elements.
Definition: ds.h:486
TSizeTy Add()
Adds a new element at the end of the vector, after its current last element.
Definition: ds.h:559
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 1141 of file network.h.

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

Definition at line 1142 of file network.h.

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

Definition at line 1143 of file network.h.

1143 { return NodeH[NodeKeyId]; }
THash< TInt, TNode > NodeH
Definition: network.h:1150
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.

1172 { return NodeH.Len(); }
THash< TInt, TNode > NodeH
Definition: network.h:1150
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 1270 of file network.h.

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

1268 { return EdgeH.GetKey(EdgeH.GetRndKeyId(Rnd, 0.8)); }
THash< TInt, TEdge > EdgeH
Definition: network.h:1151
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:398
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 1266 of file network.h.

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

1264 { return NodeH.GetKey(NodeH.GetRndKeyId(Rnd, 0.8)); }
THash< TInt, TNode > NodeH
Definition: network.h:1150
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:398
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 1391 of file network.h.

1391  {
1392  TIntPrSet UniqESet(GetEdges());
1393  for (TEdgeI EI = BegEI(); EI < EndEI(); EI++) {
1394  const int Src = EI.GetSrcNId();
1395  const int Dst = EI.GetDstNId();
1396  if (IsDir) { UniqESet.AddKey(TIntPr(Src, Dst)); }
1397  else { UniqESet.AddKey(TIntPr(TMath::Mn(Src, Dst), TMath::Mx(Src, Dst))); }
1398  }
1399  return UniqESet.Len();
1400 }
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:1247
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:1212
TEdgeI EndEI() const
Returns an iterator referring to the past-the-end edge in the network.
Definition: network.h:1249
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.

1316  {
1317  return HasGraphFlag(typename TNet, Flag);
1318 }
#define HasGraphFlag(TGraph, Flag)
For quick testing of the properties of the graph/network object (see TGraphFlag). ...
Definition: gbase.h:38
TNodeEdgeNet< TNodeData, TEdgeData > TNet
Definition: network.h:982
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.

1240 { return EdgeH.IsKey(EId); }
THash< TInt, TEdge > EdgeH
Definition: network.h:1151
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 1242 of file network.h.

1242 { 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:1240
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.

1446  {
1447  if (! IsNode(SrcNId)) { return false; }
1448  if (! IsNode(DstNId)) { return false; }
1449  const TNode& SrcNode = GetNode(SrcNId);
1450  for (int edge = 0; edge < SrcNode.GetOutDeg(); edge++) {
1451  const TEdge& Edge = GetEdge(SrcNode.GetOutEId(edge));
1452  if (DstNId == Edge.GetDstNId()) {
1453  EId = Edge.GetId(); return true; }
1454  }
1455  if (! IsDir) {
1456  for (int edge = 0; edge < SrcNode.GetInDeg(); edge++) {
1457  const TEdge& Edge = GetEdge(SrcNode.GetInEId(edge));
1458  if (DstNId == Edge.GetSrcNId()) {
1459  EId = Edge.GetId(); return true; }
1460  }
1461  }
1462  return false;
1463 }
bool IsNode(const int &NId) const
Tests whether ID NId is a node.
Definition: network.h:1194
TNode & GetNode(const int &NId)
Definition: network.h:1141
int GetId() const
Definition: network.h:1025
TEdge & GetEdge(const int &EId)
Definition: network.h:1144
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 1194 of file network.h.

1194 { return NodeH.IsKey(NId); }
THash< TInt, TNode > NodeH
Definition: network.h:1150
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 1506 of file network.h.

1506  {
1507  bool RetVal = true;
1508  for (int N = NodeH.FFirstKeyId(); NodeH.FNextKeyId(N); ) {
1509  const TNode& Node = NodeH[N];
1510  if (! Node.OutEIdV.IsSorted()) {
1511  const TStr Msg = TStr::Fmt("Out-edge list of node %d is not sorted.", Node.GetId());
1512  if (ThrowExcept) { EAssertR(false, Msg); } else { ErrNotify(Msg.CStr()); } RetVal=false;
1513  }
1514  if (! Node.InEIdV.IsSorted()) {
1515  const TStr Msg = TStr::Fmt("In-edge list of node %d is not sorted.", Node.GetId());
1516  if (ThrowExcept) { EAssertR(false, Msg); } else { ErrNotify(Msg.CStr()); } RetVal=false;
1517  }
1518  // check out-edge ids
1519  int prevEId = -1;
1520  for (int e = 0; e < Node.GetOutDeg(); e++) {
1521  if (! IsEdge(Node.GetOutEId(e))) {
1522  const TStr Msg = TStr::Fmt("Out-edge id %d of node %d does not exist.", Node.GetOutEId(e), Node.GetId());
1523  if (ThrowExcept) { EAssertR(false, Msg); } else { ErrNotify(Msg.CStr()); } RetVal=false;
1524  }
1525  if (e > 0 && prevEId == Node.GetOutEId(e)) {
1526  const TStr Msg = TStr::Fmt("Node %d has duplidate out-edge id %d.", Node.GetId(), Node.GetOutEId(e));
1527  if (ThrowExcept) { EAssertR(false, Msg); } else { ErrNotify(Msg.CStr()); } RetVal=false;
1528  }
1529  prevEId = Node.GetOutEId(e);
1530  }
1531  // check in-edge ids
1532  prevEId = -1;
1533  for (int e = 0; e < Node.GetInDeg(); e++) {
1534  if (! IsEdge(Node.GetInEId(e))) {
1535  const TStr Msg = TStr::Fmt("Out-edge id %d of node %d does not exist.", Node.GetInEId(e), Node.GetId());
1536  if (ThrowExcept) { EAssertR(false, Msg); } else { ErrNotify(Msg.CStr()); } RetVal=false;
1537  }
1538  if (e > 0 && prevEId == Node.GetInEId(e)) {
1539  const TStr Msg = TStr::Fmt("Node %d has duplidate out-edge id %d.", Node.GetId(), Node.GetInEId(e));
1540  if (ThrowExcept) { EAssertR(false, Msg); } else { ErrNotify(Msg.CStr()); } RetVal=false;
1541  }
1542  prevEId = Node.GetInEId(e);
1543  }
1544  }
1545  for (int E = EdgeH.FFirstKeyId(); EdgeH.FNextKeyId(E); ) {
1546  const TEdge& Edge = EdgeH[E];
1547  if (! IsNode(Edge.GetSrcNId())) {
1548  const TStr Msg = TStr::Fmt("Edge %d source node %d does not exist.", Edge.GetId(), Edge.GetSrcNId());
1549  if (ThrowExcept) { EAssertR(false, Msg); } else { ErrNotify(Msg.CStr()); } RetVal=false;
1550  }
1551  if (! IsNode(Edge.GetDstNId())) {
1552  const TStr Msg = TStr::Fmt("Edge %d destination node %d does not exist.", Edge.GetId(), Edge.GetDstNId());
1553  if (ThrowExcept) { EAssertR(false, Msg); } else { ErrNotify(Msg.CStr()); } RetVal=false;
1554  }
1555  }
1556  return RetVal;
1557 }
bool IsNode(const int &NId) const
Tests whether ID NId is a node.
Definition: network.h:1194
void ErrNotify(const char *NotifyCStr)
Definition: bd.h:74
bool FNextKeyId(int &KeyId) const
Definition: hash.h:432
THash< TInt, TNode > NodeH
Definition: network.h:1150
int FFirstKeyId() const
Definition: hash.h:232
THash< TInt, TEdge > EdgeH
Definition: network.h:1151
bool IsEdge(const int &EId) const
Tests whether an edge with ID EId exists in the network.
Definition: network.h:1240
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 1165 of file network.h.

1165 { return PNet(new TNet(SIn)); }
TNodeEdgeNet< TNodeData, TEdgeData > TNet
Definition: network.h:982
TPt< TNet > PNet
Definition: network.h:983
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 1163 of file network.h.

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

Definition at line 1168 of file network.h.

1168  {
1169  if (this!=&Net) { NodeH=Net.NodeH; EdgeH=Net.EdgeH; MxNId=Net.MxNId; MxEId=Net.MxEId; } return *this; }
TInt MxEId
Definition: network.h:1149
TInt MxNId
Definition: network.h:1149
THash< TInt, TNode > NodeH
Definition: network.h:1150
THash< TInt, TEdge > EdgeH
Definition: network.h:1151
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.

1281  {
1282  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:1150
THash< TInt, TEdge > EdgeH
Definition: network.h:1151
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 1161 of file network.h.

1161 { MxNId.Save(SOut); MxEId.Save(SOut); NodeH.Save(SOut); EdgeH.Save(SOut); }
TInt MxEId
Definition: network.h:1149
void Save(TSOut &SOut) const
Definition: dt.h:1058
void Save(TSOut &SOut) const
Definition: hash.h:141
TInt MxNId
Definition: network.h:1149
THash< TInt, TNode > NodeH
Definition: network.h:1150
THash< TInt, TEdge > EdgeH
Definition: network.h:1151
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.

1472  {
1473  for (TEdgeI EI = BegEI(); EI < EndEI(); EI++) {
1474  EI() = EdgeDat;
1475  }
1476 }
TEdgeI BegEI() const
Returns an iterator referring to the first edge in the network.
Definition: network.h:1247
TEdgeI EndEI() const
Returns an iterator referring to the past-the-end edge in the network.
Definition: network.h:1249
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.

1466  {
1467  IAssertR(IsEdge(EId), TStr::Fmt("EdgeId %d does not exist.", EId).CStr());
1468  GetEI(EId).GetDat() = EdgeDat;
1469 }
#define IAssertR(Cond, Reason)
Definition: bd.h:265
TEdgeI GetEI(const int &EId) const
Not supported/implemented!
Definition: network.h:1251
const TEdgeData & GetDat() const
Definition: network.h:1131
bool IsEdge(const int &EId) const
Tests whether an edge with ID EId exists in the network.
Definition: network.h:1240
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 1385 of file network.h.

1385  {
1386  IAssertR(IsNode(NId), TStr::Fmt("NodeId %d does not exist.", NId).CStr());
1387  NodeH.GetDat(NId).NodeDat = NodeDat;
1388 }
#define IAssertR(Cond, Reason)
Definition: bd.h:265
bool IsNode(const int &NId) const
Tests whether ID NId is a node.
Definition: network.h:1194
const TDat & GetDat(const TKey &Key) const
Definition: hash.h:220
TNodeData NodeDat
Definition: network.h:989
THash< TInt, TNode > NodeH
Definition: network.h:1150
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 1290 of file network.h.

1290 { EdgeH.SortByDat(Asc); }
THash< TInt, TEdge > EdgeH
Definition: network.h:1151
void SortByDat(const bool &Asc=true)
Definition: hash.h:246
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.

1288 { EdgeH.SortByKey(Asc); }
THash< TInt, TEdge > EdgeH
Definition: network.h:1151
void SortByKey(const bool &Asc=true)
Definition: hash.h:245
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.

1286 { NodeH.SortByDat(Asc); }
THash< TInt, TNode > NodeH
Definition: network.h:1150
void SortByDat(const bool &Asc=true)
Definition: hash.h:246
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.

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

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>
THash<TInt, TEdge> TNodeEdgeNet< TNodeData, TEdgeData >::EdgeH
protected

Definition at line 1151 of file network.h.

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

Definition at line 1149 of file network.h.

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

Definition at line 1149 of file network.h.

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

Definition at line 1150 of file network.h.


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