SNAP Library 6.0, User Reference  2020-12-09 16:24:20
SNAP, a general purpose, high performance system for analysis and manipulation of large networks
TUndirNet Class Reference

Undirected network. More...

#include <network.h>

Classes

class  LoadTNodeFunctor
 
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 TUndirNet TNet
 
typedef TPt< TUndirNetPNet
 

Public Member Functions

 TUndirNet ()
 
 TUndirNet (const int &Nodes, const int &Edges)
 Constructor that reserves enough memory for a network of Nodes nodes and Edges edges. More...
 
 TUndirNet (const TUndirNet &Graph)
 
 TUndirNet (TSIn &SIn)
 Constructor that loads the network from a (binary) stream SIn. More...
 
void Save (TSOut &SOut) const
 Saves the network to a (binary) stream SOut. Expects data structures for sparse attributes. More...
 
void Save_V1 (TSOut &SOut) const
 Saves the network to a (binary) stream SOut. Available for backwards compatibility. More...
 
bool HasFlag (const TGraphFlag &Flag) const
 Allows for run-time checking the type of the network (see the TGraphFlag for flags). More...
 
TUndirNetoperator= (const TUndirNet &Graph)
 
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 AddNodeUnchecked (int NId=-1)
 Adds a node of ID NId to the network, noop if the node already exists. More...
 
int AddNode (const TNodeI &NodeI)
 Adds a node of ID NodeI.GetId() to the network. More...
 
int AddNode (const int &NId, const TIntV &NbrNIdV)
 Adds a node of ID NId to the network and create edges to all nodes in vector NbrNIdV. More...
 
int AddNode (const int &NId, const TVecPool< TInt > &Pool, const int &NIdVId)
 Adds a node of ID NId to the network and create edges to all nodes in vector NIdVId in the vector pool Pool. 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...
 
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 AddEdge (const int &SrcNId, const int &DstNId)
 Adds an edge between node IDs SrcNId and DstNId to the network. More...
 
int AddEdgeUnchecked (const int &SrcNId, const int &DstNId)
 Adds an edge between node IDs SrcNId and DstNId to the network. More...
 
int AddEdge (const TEdgeI &EdgeI)
 Adds an edge between EdgeI.GetSrcNId() and EdgeI.GetDstNId() to the network. More...
 
void DelEdge (const int &SrcNId, const int &DstNId)
 Deletes an edge between node IDs SrcNId and DstNId from the network. More...
 
bool IsEdge (const int &SrcNId, const int &DstNId) const
 Tests whether an edge between node IDs SrcNId and DstNId exists in the network. More...
 
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 network. 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...
 
void GetNIdV (TIntV &NIdV) const
 Gets a vector IDs of all nodes 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 ReserveNIdDeg (const int &NId, const int &Deg)
 Reserves memory for node ID NId having Deg edges. More...
 
void SortNodeAdjV ()
 Sorts the adjacency lists of each node. 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...
 
void Dump (FILE *OutF=stdout) const
 Print the network in a human readable form to an output stream OutF. More...
 
int AddSAttrDatN (const TInt &NId, const TStr &AttrName, const TInt &Val)
 Adds Int sparse attribute with name AttrName to the given node with id NId. More...
 
int AddSAttrDatN (const TInt &NId, const TInt &AttrId, const TInt &Val)
 Adds Int sparse attribute with id AttrId to the given node with id NId. More...
 
int AddSAttrDatN (const TNodeI &NodeI, const TStr &AttrName, const TInt &Val)
 Adds Int sparse attribute with name AttrName to NodeI. More...
 
int AddSAttrDatN (const TNodeI &NodeI, const TInt &AttrId, const TInt &Val)
 Adds Int sparse attribute with id AttrId to NodeI. More...
 
int AddSAttrDatN (const TInt &NId, const TStr &AttrName, const TFlt &Val)
 Adds Flt sparse attribute with name AttrName to the given node with id NId. More...
 
int AddSAttrDatN (const TInt &NId, const TInt &AttrId, const TFlt &Val)
 Adds Flt sparse attribute with id AttrId to the given node with id NId. More...
 
int AddSAttrDatN (const TNodeI &NodeI, const TStr &AttrName, const TFlt &Val)
 Adds Flt sparse attribute with name AttrName to NodeI. More...
 
int AddSAttrDatN (const TNodeI &NodeI, const TInt &AttrId, const TFlt &Val)
 Adds Flt sparse attribute with id AttrId to NodeI. More...
 
int AddSAttrDatN (const TInt &NId, const TStr &AttrName, const TStr &Val)
 Adds Str sparse attribute with name AttrName to the given node with id NId. More...
 
int AddSAttrDatN (const TInt &NId, const TInt &AttrId, const TStr &Val)
 Adds Str sparse attribute with id AttrId to the given node with id NId. More...
 
int AddSAttrDatN (const TNodeI &NodeI, const TStr &AttrName, const TStr &Val)
 Adds Str sparse attribute with name AttrName to NodeI. More...
 
int AddSAttrDatN (const TNodeI &NodeI, const TInt &AttrId, const TStr &Val)
 Adds Str sparse attribute with id AttrId to NodeI. More...
 
int GetSAttrDatN (const TInt &NId, const TStr &AttrName, TInt &ValX) const
 Gets Int sparse attribute with name AttrName from node with id NId. More...
 
int GetSAttrDatN (const TInt &NId, const TInt &AttrId, TInt &ValX) const
 Gets Int sparse attribute with id AttrId from node with id NId. More...
 
int GetSAttrDatN (const TNodeI &NodeI, const TStr &AttrName, TInt &ValX) const
 Gets Int sparse attribute with name AttrName from NodeI. More...
 
int GetSAttrDatN (const TNodeI &NodeI, const TInt &AttrId, TInt &ValX) const
 Gets Int sparse attribute with id AttrId from NodeI. More...
 
int GetSAttrDatN (const TInt &NId, const TStr &AttrName, TFlt &ValX) const
 Gets Flt sparse attribute with name AttrName from node with id NId. More...
 
int GetSAttrDatN (const TInt &NId, const TInt &AttrId, TFlt &ValX) const
 Gets Flt sparse attribute with id AttrId from node with id NId. More...
 
int GetSAttrDatN (const TNodeI &NodeI, const TStr &AttrName, TFlt &ValX) const
 Gets Flt sparse attribute with name AttrName from NodeI. More...
 
int GetSAttrDatN (const TNodeI &NodeI, const TInt &AttrId, TFlt &ValX) const
 Gets Flt sparse attribute with id AttrId from NodeI. More...
 
int GetSAttrDatN (const TInt &NId, const TStr &AttrName, TStr &ValX) const
 Gets Str sparse attribute with name AttrName from node with id NId. More...
 
int GetSAttrDatN (const TInt &NId, const TInt &AttrId, TStr &ValX) const
 Gets Str sparse attribute with id AttrId from node with id NId. More...
 
int GetSAttrDatN (const TNodeI &NodeI, const TStr &AttrName, TStr &ValX) const
 Gets Str sparse attribute with name AttrName from NodeI. More...
 
int GetSAttrDatN (const TNodeI &NodeI, const TInt &AttrId, TStr &ValX) const
 Gets Str sparse attribute with id AttrId from NodeI. More...
 
int DelSAttrDatN (const TInt &NId, const TStr &AttrName)
 Deletes sparse attribute with name AttrName from node with id NId. More...
 
int DelSAttrDatN (const TInt &NId, const TInt &AttrId)
 Deletes sparse attribute with id AttrId from node with id NId. More...
 
int DelSAttrDatN (const TNodeI &NodeI, const TStr &AttrName)
 Deletes sparse attribute with name AttrName from NodeI. More...
 
int DelSAttrDatN (const TNodeI &NodeI, const TInt &AttrId)
 Deletes sparse attribute with id AttrId from NodeI. More...
 
int GetSAttrVN (const TInt &NId, const TAttrType AttrType, TAttrPrV &AttrV) const
 Gets a list of all sparse attributes of type AttrType for node with id NId. More...
 
int GetSAttrVN (const TNodeI &NodeI, const TAttrType AttrType, TAttrPrV &AttrV) const
 Gets a list of all sparse attributes of type AttrType for NodeI. More...
 
int GetIdVSAttrN (const TStr &AttrName, TIntV &IdV) const
 Gets a list of all nodes that have a sparse attribute with name AttrName. More...
 
int GetIdVSAttrN (const TInt &AttrId, TIntV &IdV) const
 Gets a list of all nodes that have a sparse attribute with id AttrId. More...
 
int AddSAttrN (const TStr &Name, const TAttrType &AttrType, TInt &AttrId)
 Adds mapping for sparse attribute with name Name and type AttrType. More...
 
int GetSAttrIdN (const TStr &Name, TInt &AttrIdX, TAttrType &AttrTypeX) const
 Gets id and type for attribute with name Name. More...
 
int GetSAttrNameN (const TInt &AttrId, TStr &NameX, TAttrType &AttrTypeX) const
 Gets name and type for attribute with id AttrId. More...
 
int AddSAttrDatE (const int &SrcNId, const int &DstNId, const TStr &AttrName, const TInt &Val)
 Adds Int sparse attribute with name AttrName to the given edge with ids SrcId and DstId. More...
 
int AddSAttrDatE (const int &SrcNId, const int &DstNId, const TInt &AttrId, const TInt &Val)
 Adds Int sparse attribute with id AttrId to the given edge with ids SrcId and DstId. More...
 
int AddSAttrDatE (const TEdgeI &EdgeI, const TStr &AttrName, const TInt &Val)
 Adds Int sparse attribute with name AttrName to EdgeI. More...
 
int AddSAttrDatE (const TEdgeI &EdgeI, const TInt &AttrId, const TInt &Val)
 Adds Int sparse attribute with id AttrId to EdgeI. More...
 
int AddSAttrDatE (const int &SrcNId, const int &DstNId, const TStr &AttrName, const TFlt &Val)
 Adds Flt sparse attribute with name AttrName to the given edge with ids SrcId and DstId. More...
 
int AddSAttrDatE (const int &SrcNId, const int &DstNId, const TInt &AttrId, const TFlt &Val)
 Adds Flt sparse attribute with id AttrId to the given edge with ids SrcId and DstId. More...
 
int AddSAttrDatE (const TEdgeI &EdgeI, const TStr &AttrName, const TFlt &Val)
 Adds Flt sparse attribute with name AttrName to EdgeI. More...
 
int AddSAttrDatE (const TEdgeI &EdgeI, const TInt &AttrId, const TFlt &Val)
 Adds Flt sparse attribute with id AttrId to EdgeI. More...
 
int AddSAttrDatE (const int &SrcNId, const int &DstNId, const TStr &AttrName, const TStr &Val)
 Adds Str sparse attribute with name AttrName to the given edge with ids SrcId and DstId. More...
 
int AddSAttrDatE (const int &SrcNId, const int &DstNId, const TInt &AttrId, const TStr &Val)
 Adds Str sparse attribute with id AttrId to the given edge with ids SrcId and DstId. More...
 
int AddSAttrDatE (const TEdgeI &EdgeI, const TStr &AttrName, const TStr &Val)
 Adds Str sparse attribute with name AttrName to EdgeI. More...
 
int AddSAttrDatE (const TEdgeI &EdgeI, const TInt &AttrId, const TStr &Val)
 Adds Str sparse attribute with id AttrId to EdgeI. More...
 
int GetSAttrDatE (const int &SrcNId, const int &DstNId, const TStr &AttrName, TInt &ValX) const
 Gets Int sparse attribute with name AttrName from edge with ids SrcId and DstId. More...
 
int GetSAttrDatE (const int &SrcNId, const int &DstNId, const TInt &AttrId, TInt &ValX) const
 Gets Int sparse attribute with id AttrId from edge with ids SrcId and DstId. More...
 
int GetSAttrDatE (const TEdgeI &EdgeI, const TStr &AttrName, TInt &ValX) const
 Gets Int sparse attribute with name AttrName from EdgeI. More...
 
int GetSAttrDatE (const TEdgeI &EdgeI, const TInt &AttrId, TInt &ValX) const
 Gets Int sparse attribute with id AttrId from EdgeI. More...
 
int GetSAttrDatE (const int &SrcNId, const int &DstNId, const TStr &AttrName, TFlt &ValX) const
 Gets Flt sparse attribute with name AttrName from edge with ids SrcId and DstId. More...
 
int GetSAttrDatE (const int &SrcNId, const int &DstNId, const TInt &AttrId, TFlt &ValX) const
 Gets Flt sparse attribute with id AttrId from edge with ids SrcId and DstId. More...
 
int GetSAttrDatE (const TEdgeI &EdgeI, const TStr &AttrName, TFlt &ValX) const
 Gets Flt sparse attribute with name AttrName from EdgeI. More...
 
int GetSAttrDatE (const TEdgeI &EdgeI, const TInt &AttrId, TFlt &ValX) const
 Gets Flt sparse attribute with id AttrId from EdgeI. More...
 
int GetSAttrDatE (const int &SrcNId, const int &DstNId, const TStr &AttrName, TStr &ValX) const
 Gets Str sparse attribute with name AttrName from edge with ids SrcId and DstId. More...
 
int GetSAttrDatE (const int &SrcNId, const int &DstNId, const TInt &AttrId, TStr &ValX) const
 Gets Str sparse attribute with id AttrId from edge with ids SrcId and DstId. More...
 
int GetSAttrDatE (const TEdgeI &EdgeI, const TStr &AttrName, TStr &ValX) const
 Gets Str sparse attribute with name AttrName from EdgeI. More...
 
int GetSAttrDatE (const TEdgeI &EdgeI, const TInt &AttrId, TStr &ValX) const
 Gets Str sparse attribute with id AttrId from EdgeI. More...
 
int DelSAttrDatE (const int &SrcNId, const int &DstNId, const TStr &AttrName)
 Deletes sparse attribute with name AttrName from edge with ids SrcId and DstId. More...
 
int DelSAttrDatE (const int &SrcNId, const int &DstNId, const TInt &AttrId)
 Deletes sparse attribute with id AttrId from edge with ids SrcId and DstId. More...
 
int DelSAttrDatE (const TEdgeI &EdgeI, const TStr &AttrName)
 Deletes sparse attribute with name AttrName from EdgeI. More...
 
int DelSAttrDatE (const TEdgeI &EdgeI, const TInt &AttrId)
 Deletes sparse attribute with id AttrId from EdgeI. More...
 
int GetSAttrVE (const int &SrcNId, const int &DstNId, const TAttrType AttrType, TAttrPrV &AttrV) const
 Gets a list of all sparse attributes of type AttrType for edge with ids SrcId and DstId. More...
 
int GetSAttrVE (const TEdgeI &EdgeI, const TAttrType AttrType, TAttrPrV &AttrV) const
 Gets a list of all sparse attributes of type AttrType for EdgeI. More...
 
int GetIdVSAttrE (const TStr &AttrName, TIntPrV &IdV) const
 Gets a list of all edges that have a sparse attribute with name AttrName. More...
 
int GetIdVSAttrE (const TInt &AttrId, TIntPrV &IdV) const
 Gets a list of all edges that have a sparse attribute with id AttrId. More...
 
int AddSAttrE (const TStr &Name, const TAttrType &AttrType, TInt &AttrId)
 Adds mapping for sparse attribute with name Name and type AttrType. More...
 
int GetSAttrIdE (const TStr &Name, TInt &AttrIdX, TAttrType &AttrTypeX) const
 Gets id and type for attribute with name Name. More...
 
int GetSAttrNameE (const TInt &AttrId, TStr &NameX, TAttrType &AttrTypeX) const
 Gets name and type for attribute with id AttrId. More...
 

Static Public Member Functions

static PUndirNet New ()
 Static constructor that returns a pointer to the network. Call: PUndirNet Graph = TUndirNet::New(). More...
 
static PUndirNet New (const int &Nodes, const int &Edges)
 Static constructor that returns a pointer to the network and reserves enough memory for Nodes nodes and Edges edges. More...
 
static PUndirNet Load (TSIn &SIn)
 Static constructor that loads the network from a stream SIn and returns a pointer to it. More...
 
static PUndirNet Load_V1 (TSIn &SIn)
 Static constructor that loads the network from a stream SIn and returns a pointer to it. Backwards compatible. More...
 
static PUndirNet LoadShM (TShMIn &ShMIn)
 Static constructor that loads the network from memory. More...
 
static PUndirNet GetSmallGraph ()
 Returns a small network on 5 nodes and 5 edges. More...
 

Private Member Functions

TNodeGetNode (const int &NId)
 
const TNodeGetNode (const int &NId) const
 
TIntPr OrderEdgeNodes (const int &SrcNId, const int &DstNId) const
 
void LoadNetworkShM (TShMIn &ShMIn)
 

Private Attributes

TCRef CRef
 
TInt MxNId
 
TInt NEdges
 
THash< TInt, TNodeNodeH
 
TAttr SAttrN
 
TAttrPair SAttrE
 

Friends

class TUndirNetMtx
 
class TPt< TUndirNet >
 

Detailed Description

Undirected network.

Node IDs can be arbitrary non-negative integers. Nodes and edges can have sparse attributes/data associated with them. There is at most one undirected edge between a pair of nodes. Self loops (one per node) are allowed but multiple (parallel) edges are not. The undirected graph data structure is implemented using sorted adjacency lists. This means adding a node takes constant time, while adding an edge takes linear time (since adjacency list is kept sorted) in the node degree. Accessing arbitrary node takes constant time and accessing any edge takes logarithmic time in the node degree.

Definition at line 3397 of file network.h.

Member Typedef Documentation

Definition at line 3400 of file network.h.

Definition at line 3399 of file network.h.

Constructor & Destructor Documentation

TUndirNet::TUndirNet ( )
inline

Definition at line 3534 of file network.h.

3534 : CRef(), MxNId(0), NEdges(0), NodeH(), SAttrN(), SAttrE() { }
THash< TInt, TNode > NodeH
Definition: network.h:3510
TInt MxNId
Definition: network.h:3509
TAttrPair SAttrE
Definition: network.h:3513
TAttr SAttrN
Definition: network.h:3512
TCRef CRef
Definition: network.h:3508
TInt NEdges
Definition: network.h:3509
TUndirNet::TUndirNet ( const int &  Nodes,
const int &  Edges 
)
inlineexplicit

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

Definition at line 3536 of file network.h.

3536 : MxNId(0), NEdges(0), SAttrN(), SAttrE() { Reserve(Nodes, Edges); }
void Reserve(const int &Nodes, const int &Edges)
Reserves memory for a network of Nodes nodes and Edges edges.
Definition: network.h:3683
TInt MxNId
Definition: network.h:3509
TAttrPair SAttrE
Definition: network.h:3513
TAttr SAttrN
Definition: network.h:3512
TInt NEdges
Definition: network.h:3509
TUndirNet::TUndirNet ( const TUndirNet Graph)
inline

Definition at line 3537 of file network.h.

3537  : MxNId(Graph.MxNId), NEdges(Graph.NEdges), NodeH(Graph.NodeH),
3538  SAttrN(), SAttrE() { }
THash< TInt, TNode > NodeH
Definition: network.h:3510
TInt MxNId
Definition: network.h:3509
TAttrPair SAttrE
Definition: network.h:3513
TAttr SAttrN
Definition: network.h:3512
TInt NEdges
Definition: network.h:3509
TUndirNet::TUndirNet ( TSIn SIn)
inline

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

Definition at line 3540 of file network.h.

3540 : MxNId(SIn), NEdges(SIn), NodeH(SIn), SAttrN(SIn), SAttrE(SIn) { }
THash< TInt, TNode > NodeH
Definition: network.h:3510
TInt MxNId
Definition: network.h:3509
TAttrPair SAttrE
Definition: network.h:3513
TAttr SAttrN
Definition: network.h:3512
TInt NEdges
Definition: network.h:3509

Member Function Documentation

int TUndirNet::AddEdge ( const int &  SrcNId,
const int &  DstNId 
)

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

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

Definition at line 2213 of file network.cpp.

2213  {
2214  IAssertR(IsNode(SrcNId) && IsNode(DstNId), TStr::Fmt("%d or %d not a node.", SrcNId, DstNId).CStr());
2215  if (IsEdge(SrcNId, DstNId)) { return -2; } // edge already exists
2216  GetNode(SrcNId).NIdV.AddSorted(DstNId);
2217  if (SrcNId!=DstNId) { // not a self edge
2218  GetNode(DstNId).NIdV.AddSorted(SrcNId); }
2219  NEdges++;
2220  return -1; // no edge id
2221 }
#define IAssertR(Cond, Reason)
Definition: bd.h:265
TSizeTy AddSorted(const TVal &Val, const bool &Asc=true, const TSizeTy &_MxVals=-1)
Adds element Val to a sorted vector.
Definition: ds.h:1117
bool IsEdge(const int &SrcNId, const int &DstNId) const
Tests whether an edge between node IDs SrcNId and DstNId exists in the network.
Definition: network.cpp:2248
bool IsNode(const int &NId) const
Tests whether ID NId is a node.
Definition: network.h:3620
TNode & GetNode(const int &NId)
Definition: network.h:3515
static TStr Fmt(const char *FmtStr,...)
Definition: dt.cpp:1599
TInt NEdges
Definition: network.h:3509
int TUndirNet::AddEdge ( const TEdgeI EdgeI)
inline

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

Definition at line 3650 of file network.h.

3650 { return AddEdge(EdgeI.GetSrcNId(), EdgeI.GetDstNId()); }
int AddEdge(const int &SrcNId, const int &DstNId)
Adds an edge between node IDs SrcNId and DstNId to the network.
Definition: network.cpp:2213
int TUndirNet::AddEdgeUnchecked ( const int &  SrcNId,
const int &  DstNId 
)

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

Returns -1. The method assumes that SrcNId and DstNId are existing nodes in the graph and adds new neighbor values at the end of their adjacency vectors. No checks are performed to verify these assumptions. Adjacency vectors must be sorted and have duplicates removed after a sequence of these operations to assure consistency of data structures.

Definition at line 2224 of file network.cpp.

2224  {
2225  GetNode(SrcNId).NIdV.Add(DstNId);
2226  if (SrcNId!=DstNId) { // not a self edge
2227  GetNode(DstNId).NIdV.Add(SrcNId); }
2228  NEdges++;
2229  return -1; // no edge id
2230 }
TNode & GetNode(const int &NId)
Definition: network.h:3515
TSizeTy Add()
Adds a new element at the end of the vector, after its current last element.
Definition: ds.h:602
TInt NEdges
Definition: network.h:3509
int TUndirNet::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 2124 of file network.cpp.

2124  {
2125  if (NId == -1) {
2126  NId = MxNId; MxNId++;
2127  } else {
2128  IAssertR(!IsNode(NId), TStr::Fmt("NodeId %d already exists", NId));
2129  MxNId = TMath::Mx(NId+1, MxNId());
2130  }
2131  NodeH.AddDat(NId, TNode(NId));
2132  return NId;
2133 }
#define IAssertR(Cond, Reason)
Definition: bd.h:265
THash< TInt, TNode > NodeH
Definition: network.h:3510
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:3620
TInt MxNId
Definition: network.h:3509
static TStr Fmt(const char *FmtStr,...)
Definition: dt.cpp:1599
TDat & AddDat(const TKey &Key)
Definition: hash.h:238
int TUndirNet::AddNode ( const TNodeI NodeI)
inline

Adds a node of ID NodeI.GetId() to the network.

Definition at line 3590 of file network.h.

3590 { return AddNode(NodeI.GetId()); }
int AddNode(int NId=-1)
Adds a node of ID NId to the network.
Definition: network.cpp:2124
int TUndirNet::AddNode ( const int &  NId,
const TIntV NbrNIdV 
)

Adds a node of ID NId to the network and create edges to all nodes in vector NbrNIdV.

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.

The operation can create inconsistent graphs when the neighboring nodes in NbrNIdV vector do not exist. Use TUndirNet::IsOk to check that the resulting graph is consistent after the operation.

Definition at line 2147 of file network.cpp.

2147  {
2148  int NewNId;
2149  if (NId == -1) {
2150  NewNId = MxNId; MxNId++;
2151  } else {
2152  IAssertR(! IsNode(NId), TStr::Fmt("NodeId %d already exists", NId));
2153  NewNId = NId;
2154  MxNId = TMath::Mx(NewNId+1, MxNId());
2155  }
2156  TNode& Node = NodeH.AddDat(NewNId);
2157  Node.Id = NewNId;
2158  Node.NIdV = NbrNIdV;
2159  Node.NIdV.Sort();
2160  NEdges += Node.GetDeg();
2161  for (int i = 0; i < NbrNIdV.Len(); i++) {
2162  GetNode(NbrNIdV[i]).NIdV.AddSorted(NewNId);
2163  }
2164  return NewNId;
2165 }
#define IAssertR(Cond, Reason)
Definition: bd.h:265
THash< TInt, TNode > NodeH
Definition: network.h:3510
static const T & Mx(const T &LVal, const T &RVal)
Definition: xmath.h:32
TSizeTy Len() const
Returns the number of elements in the vector.
Definition: ds.h:575
TSizeTy AddSorted(const TVal &Val, const bool &Asc=true, const TSizeTy &_MxVals=-1)
Adds element Val to a sorted vector.
Definition: ds.h:1117
void Sort(const bool &Asc=true)
Sorts the elements of the vector.
Definition: ds.h:1318
bool IsNode(const int &NId) const
Tests whether ID NId is a node.
Definition: network.h:3620
TNode & GetNode(const int &NId)
Definition: network.h:3515
TInt MxNId
Definition: network.h:3509
static TStr Fmt(const char *FmtStr,...)
Definition: dt.cpp:1599
TInt NEdges
Definition: network.h:3509
TDat & AddDat(const TKey &Key)
Definition: hash.h:238
int TUndirNet::AddNode ( const int &  NId,
const TVecPool< TInt > &  Pool,
const int &  NIdVId 
)

Adds a node of ID NId to the network and create edges to all nodes in vector NIdVId in the vector pool Pool.

//int& NIdVId) 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.

The operation can create inconsistent graphs when the neighboring nodes stored in the Pool vector are not explicitly added to the graph. Use TUndirNet::IsOk to check that the resulting graph is consistent.

Definition at line 2168 of file network.cpp.

2168  {
2169  int NewNId;
2170  if (NId == -1) {
2171  NewNId = MxNId; MxNId++;
2172  } else {
2173  IAssertR(!IsNode(NId), TStr::Fmt("NodeId %d already exists", NId));
2174  NewNId = NId;
2175  MxNId = TMath::Mx(NewNId+1, MxNId());
2176  }
2177  TNode& Node = NodeH.AddDat(NewNId);
2178  Node.Id = NewNId;
2179  Node.NIdV.GenExt(Pool.GetValVPt(NIdVId), Pool.GetVLen(NIdVId));
2180  Node.NIdV.Sort();
2181  NEdges += Node.GetDeg();
2182  return NewNId;
2183 }
#define IAssertR(Cond, Reason)
Definition: bd.h:265
THash< TInt, TNode > NodeH
Definition: network.h:3510
static const T & Mx(const T &LVal, const T &RVal)
Definition: xmath.h:32
TVal * GetValVPt(const int &VId) const
Returns pointer to the first element of the vector with id VId.
Definition: ds.h:1731
bool IsNode(const int &NId) const
Tests whether ID NId is a node.
Definition: network.h:3620
int GetVLen(const int &VId) const
Returns the number of elements in the vector with id VId.
Definition: ds.h:1729
TInt MxNId
Definition: network.h:3509
static TStr Fmt(const char *FmtStr,...)
Definition: dt.cpp:1599
TInt NEdges
Definition: network.h:3509
TDat & AddDat(const TKey &Key)
Definition: hash.h:238
int TUndirNet::AddNodeUnchecked ( int  NId = -1)

Adds a node of ID NId to the network, noop if the node already exists.

Returns -1, if the node NId already exists. Otherwise, it returns the ID of the node being added. If NId is -1, node ID is automatically assigned.

Definition at line 2135 of file network.cpp.

2135  {
2136  if (NId == -1) {
2137  NId = MxNId; MxNId++;
2138  } else {
2139  if (IsNode(NId)) { return -1;}
2140  MxNId = TMath::Mx(NId+1, MxNId());
2141  }
2142  NodeH.AddDat(NId, TNode(NId));
2143  return NId;
2144 }
THash< TInt, TNode > NodeH
Definition: network.h:3510
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:3620
TInt MxNId
Definition: network.h:3509
TDat & AddDat(const TKey &Key)
Definition: hash.h:238
int TUndirNet::AddSAttrDatE ( const int &  SrcNId,
const int &  DstNId,
const TStr AttrName,
const TInt Val 
)

Adds Int sparse attribute with name AttrName to the given edge with ids SrcId and DstId.

Definition at line 2475 of file network.cpp.

2475  {
2476  if (!IsEdge(SrcNId, DstNId)) {
2477  return -1;
2478  }
2479  TIntPr EId = OrderEdgeNodes(SrcNId, DstNId);
2480  return SAttrE.AddSAttrDat(EId, AttrName, Val);
2481 }
bool IsEdge(const int &SrcNId, const int &DstNId) const
Tests whether an edge between node IDs SrcNId and DstNId exists in the network.
Definition: network.cpp:2248
Definition: ds.h:32
int AddSAttrDat(const TIntPr &Id, const TStr &AttrName, const TInt &Val)
Add Int attribute with name AttrName for the given id Id.
Definition: attr.cpp:246
TAttrPair SAttrE
Definition: network.h:3513
TIntPr OrderEdgeNodes(const int &SrcNId, const int &DstNId) const
Definition: network.cpp:2468
int TUndirNet::AddSAttrDatE ( const int &  SrcNId,
const int &  DstNId,
const TInt AttrId,
const TInt Val 
)

Adds Int sparse attribute with id AttrId to the given edge with ids SrcId and DstId.

Definition at line 2483 of file network.cpp.

2483  {
2484  if (!IsEdge(SrcNId, DstNId)) {
2485  return -1;
2486  }
2487  TIntPr EId = OrderEdgeNodes(SrcNId, DstNId);
2488  return SAttrE.AddSAttrDat(EId, AttrId, Val);
2489 }
bool IsEdge(const int &SrcNId, const int &DstNId) const
Tests whether an edge between node IDs SrcNId and DstNId exists in the network.
Definition: network.cpp:2248
Definition: ds.h:32
int AddSAttrDat(const TIntPr &Id, const TStr &AttrName, const TInt &Val)
Add Int attribute with name AttrName for the given id Id.
Definition: attr.cpp:246
TAttrPair SAttrE
Definition: network.h:3513
TIntPr OrderEdgeNodes(const int &SrcNId, const int &DstNId) const
Definition: network.cpp:2468
int TUndirNet::AddSAttrDatE ( const TEdgeI EdgeI,
const TStr AttrName,
const TInt Val 
)
inline

Adds Int sparse attribute with name AttrName to EdgeI.

Definition at line 3835 of file network.h.

3835  {
3836  return AddSAttrDatE(EdgeI.GetSrcNId(), EdgeI.GetDstNId(), AttrName, Val);
3837  }
int AddSAttrDatE(const int &SrcNId, const int &DstNId, const TStr &AttrName, const TInt &Val)
Adds Int sparse attribute with name AttrName to the given edge with ids SrcId and DstId...
Definition: network.cpp:2475
int TUndirNet::AddSAttrDatE ( const TEdgeI EdgeI,
const TInt AttrId,
const TInt Val 
)
inline

Adds Int sparse attribute with id AttrId to EdgeI.

Definition at line 3839 of file network.h.

3839  {
3840  return AddSAttrDatE(EdgeI.GetSrcNId(), EdgeI.GetDstNId(), AttrId, Val);
3841  }
int AddSAttrDatE(const int &SrcNId, const int &DstNId, const TStr &AttrName, const TInt &Val)
Adds Int sparse attribute with name AttrName to the given edge with ids SrcId and DstId...
Definition: network.cpp:2475
int TUndirNet::AddSAttrDatE ( const int &  SrcNId,
const int &  DstNId,
const TStr AttrName,
const TFlt Val 
)

Adds Flt sparse attribute with name AttrName to the given edge with ids SrcId and DstId.

Definition at line 2491 of file network.cpp.

2491  {
2492  if (!IsEdge(SrcNId, DstNId)) {
2493  return -1;
2494  }
2495  TIntPr EId = OrderEdgeNodes(SrcNId, DstNId);
2496  return SAttrE.AddSAttrDat(EId, AttrName, Val);
2497 }
bool IsEdge(const int &SrcNId, const int &DstNId) const
Tests whether an edge between node IDs SrcNId and DstNId exists in the network.
Definition: network.cpp:2248
Definition: ds.h:32
int AddSAttrDat(const TIntPr &Id, const TStr &AttrName, const TInt &Val)
Add Int attribute with name AttrName for the given id Id.
Definition: attr.cpp:246
TAttrPair SAttrE
Definition: network.h:3513
TIntPr OrderEdgeNodes(const int &SrcNId, const int &DstNId) const
Definition: network.cpp:2468
int TUndirNet::AddSAttrDatE ( const int &  SrcNId,
const int &  DstNId,
const TInt AttrId,
const TFlt Val 
)

Adds Flt sparse attribute with id AttrId to the given edge with ids SrcId and DstId.

Definition at line 2499 of file network.cpp.

2499  {
2500  if (!IsEdge(SrcNId, DstNId)) {
2501  return -1;
2502  }
2503  TIntPr EId = OrderEdgeNodes(SrcNId, DstNId);
2504  return SAttrE.AddSAttrDat(EId, AttrId, Val);
2505 }
bool IsEdge(const int &SrcNId, const int &DstNId) const
Tests whether an edge between node IDs SrcNId and DstNId exists in the network.
Definition: network.cpp:2248
Definition: ds.h:32
int AddSAttrDat(const TIntPr &Id, const TStr &AttrName, const TInt &Val)
Add Int attribute with name AttrName for the given id Id.
Definition: attr.cpp:246
TAttrPair SAttrE
Definition: network.h:3513
TIntPr OrderEdgeNodes(const int &SrcNId, const int &DstNId) const
Definition: network.cpp:2468
int TUndirNet::AddSAttrDatE ( const TEdgeI EdgeI,
const TStr AttrName,
const TFlt Val 
)
inline

Adds Flt sparse attribute with name AttrName to EdgeI.

Definition at line 3849 of file network.h.

3849  {
3850  return AddSAttrDatE(EdgeI.GetSrcNId(), EdgeI.GetDstNId(), AttrName, Val);
3851  }
int AddSAttrDatE(const int &SrcNId, const int &DstNId, const TStr &AttrName, const TInt &Val)
Adds Int sparse attribute with name AttrName to the given edge with ids SrcId and DstId...
Definition: network.cpp:2475
int TUndirNet::AddSAttrDatE ( const TEdgeI EdgeI,
const TInt AttrId,
const TFlt Val 
)
inline

Adds Flt sparse attribute with id AttrId to EdgeI.

Definition at line 3853 of file network.h.

3853  {
3854  return AddSAttrDatE(EdgeI.GetSrcNId(), EdgeI.GetDstNId(), AttrId, Val);
3855  }
int AddSAttrDatE(const int &SrcNId, const int &DstNId, const TStr &AttrName, const TInt &Val)
Adds Int sparse attribute with name AttrName to the given edge with ids SrcId and DstId...
Definition: network.cpp:2475
int TUndirNet::AddSAttrDatE ( const int &  SrcNId,
const int &  DstNId,
const TStr AttrName,
const TStr Val 
)

Adds Str sparse attribute with name AttrName to the given edge with ids SrcId and DstId.

Definition at line 2507 of file network.cpp.

2507  {
2508  if (!IsEdge(SrcNId, DstNId)) {
2509  return -1;
2510  }
2511  TIntPr EId = OrderEdgeNodes(SrcNId, DstNId);
2512  return SAttrE.AddSAttrDat(EId, AttrName, Val);
2513 }
bool IsEdge(const int &SrcNId, const int &DstNId) const
Tests whether an edge between node IDs SrcNId and DstNId exists in the network.
Definition: network.cpp:2248
Definition: ds.h:32
int AddSAttrDat(const TIntPr &Id, const TStr &AttrName, const TInt &Val)
Add Int attribute with name AttrName for the given id Id.
Definition: attr.cpp:246
TAttrPair SAttrE
Definition: network.h:3513
TIntPr OrderEdgeNodes(const int &SrcNId, const int &DstNId) const
Definition: network.cpp:2468
int TUndirNet::AddSAttrDatE ( const int &  SrcNId,
const int &  DstNId,
const TInt AttrId,
const TStr Val 
)

Adds Str sparse attribute with id AttrId to the given edge with ids SrcId and DstId.

Definition at line 2515 of file network.cpp.

2515  {
2516  if (!IsEdge(SrcNId, DstNId)) {
2517  return -1;
2518  }
2519  TIntPr EId = OrderEdgeNodes(SrcNId, DstNId);
2520  return SAttrE.AddSAttrDat(EId, AttrId, Val);
2521 }
bool IsEdge(const int &SrcNId, const int &DstNId) const
Tests whether an edge between node IDs SrcNId and DstNId exists in the network.
Definition: network.cpp:2248
Definition: ds.h:32
int AddSAttrDat(const TIntPr &Id, const TStr &AttrName, const TInt &Val)
Add Int attribute with name AttrName for the given id Id.
Definition: attr.cpp:246
TAttrPair SAttrE
Definition: network.h:3513
TIntPr OrderEdgeNodes(const int &SrcNId, const int &DstNId) const
Definition: network.cpp:2468
int TUndirNet::AddSAttrDatE ( const TEdgeI EdgeI,
const TStr AttrName,
const TStr Val 
)
inline

Adds Str sparse attribute with name AttrName to EdgeI.

Definition at line 3863 of file network.h.

3863  {
3864  return AddSAttrDatE(EdgeI.GetSrcNId(), EdgeI.GetDstNId(), AttrName, Val);
3865  }
int AddSAttrDatE(const int &SrcNId, const int &DstNId, const TStr &AttrName, const TInt &Val)
Adds Int sparse attribute with name AttrName to the given edge with ids SrcId and DstId...
Definition: network.cpp:2475
int TUndirNet::AddSAttrDatE ( const TEdgeI EdgeI,
const TInt AttrId,
const TStr Val 
)
inline

Adds Str sparse attribute with id AttrId to EdgeI.

Definition at line 3867 of file network.h.

3867  {
3868  return AddSAttrDatE(EdgeI.GetSrcNId(), EdgeI.GetDstNId(), AttrId, Val);
3869  }
int AddSAttrDatE(const int &SrcNId, const int &DstNId, const TStr &AttrName, const TInt &Val)
Adds Int sparse attribute with name AttrName to the given edge with ids SrcId and DstId...
Definition: network.cpp:2475
int TUndirNet::AddSAttrDatN ( const TInt NId,
const TStr AttrName,
const TInt Val 
)

Adds Int sparse attribute with name AttrName to the given node with id NId.

Definition at line 2342 of file network.cpp.

2342  {
2343  if (!IsNode(NId)) {
2344  return -1;
2345  }
2346  return SAttrN.AddSAttrDat(NId, AttrName, Val);
2347 }
int AddSAttrDat(const TInt &Id, const TStr &AttrName, const TInt &Val)
Add Int attribute with name AttrName for the given id Id.
Definition: attr.cpp:2
bool IsNode(const int &NId) const
Tests whether ID NId is a node.
Definition: network.h:3620
TAttr SAttrN
Definition: network.h:3512
int TUndirNet::AddSAttrDatN ( const TInt NId,
const TInt AttrId,
const TInt Val 
)

Adds Int sparse attribute with id AttrId to the given node with id NId.

Definition at line 2349 of file network.cpp.

2349  {
2350  if (!IsNode(NId)) {
2351  return -1;
2352  }
2353  return SAttrN.AddSAttrDat(NId, AttrId, Val);
2354 }
int AddSAttrDat(const TInt &Id, const TStr &AttrName, const TInt &Val)
Add Int attribute with name AttrName for the given id Id.
Definition: attr.cpp:2
bool IsNode(const int &NId) const
Tests whether ID NId is a node.
Definition: network.h:3620
TAttr SAttrN
Definition: network.h:3512
int TUndirNet::AddSAttrDatN ( const TNodeI NodeI,
const TStr AttrName,
const TInt Val 
)
inline

Adds Int sparse attribute with name AttrName to NodeI.

Definition at line 3717 of file network.h.

3717  {
3718  return AddSAttrDatN(NodeI.GetId(), AttrName, Val);
3719  }
int AddSAttrDatN(const TInt &NId, const TStr &AttrName, const TInt &Val)
Adds Int sparse attribute with name AttrName to the given node with id NId.
Definition: network.cpp:2342
int TUndirNet::AddSAttrDatN ( const TNodeI NodeI,
const TInt AttrId,
const TInt Val 
)
inline

Adds Int sparse attribute with id AttrId to NodeI.

Definition at line 3721 of file network.h.

3721  {
3722  return AddSAttrDatN(NodeI.GetId(), AttrId, Val);
3723  }
int AddSAttrDatN(const TInt &NId, const TStr &AttrName, const TInt &Val)
Adds Int sparse attribute with name AttrName to the given node with id NId.
Definition: network.cpp:2342
int TUndirNet::AddSAttrDatN ( const TInt NId,
const TStr AttrName,
const TFlt Val 
)

Adds Flt sparse attribute with name AttrName to the given node with id NId.

Definition at line 2356 of file network.cpp.

2356  {
2357  if (!IsNode(NId)) {
2358  return -1;
2359  }
2360  return SAttrN.AddSAttrDat(NId, AttrName, Val);
2361 }
int AddSAttrDat(const TInt &Id, const TStr &AttrName, const TInt &Val)
Add Int attribute with name AttrName for the given id Id.
Definition: attr.cpp:2
bool IsNode(const int &NId) const
Tests whether ID NId is a node.
Definition: network.h:3620
TAttr SAttrN
Definition: network.h:3512
int TUndirNet::AddSAttrDatN ( const TInt NId,
const TInt AttrId,
const TFlt Val 
)

Adds Flt sparse attribute with id AttrId to the given node with id NId.

Definition at line 2363 of file network.cpp.

2363  {
2364  if (!IsNode(NId)) {
2365  return -1;
2366  }
2367  return SAttrN.AddSAttrDat(NId, AttrId, Val);
2368 }
int AddSAttrDat(const TInt &Id, const TStr &AttrName, const TInt &Val)
Add Int attribute with name AttrName for the given id Id.
Definition: attr.cpp:2
bool IsNode(const int &NId) const
Tests whether ID NId is a node.
Definition: network.h:3620
TAttr SAttrN
Definition: network.h:3512
int TUndirNet::AddSAttrDatN ( const TNodeI NodeI,
const TStr AttrName,
const TFlt Val 
)
inline

Adds Flt sparse attribute with name AttrName to NodeI.

Definition at line 3731 of file network.h.

3731  {
3732  return AddSAttrDatN(NodeI.GetId(), AttrName, Val);
3733  }
int AddSAttrDatN(const TInt &NId, const TStr &AttrName, const TInt &Val)
Adds Int sparse attribute with name AttrName to the given node with id NId.
Definition: network.cpp:2342
int TUndirNet::AddSAttrDatN ( const TNodeI NodeI,
const TInt AttrId,
const TFlt Val 
)
inline

Adds Flt sparse attribute with id AttrId to NodeI.

Definition at line 3735 of file network.h.

3735  {
3736  return AddSAttrDatN(NodeI.GetId(), AttrId, Val);
3737  }
int AddSAttrDatN(const TInt &NId, const TStr &AttrName, const TInt &Val)
Adds Int sparse attribute with name AttrName to the given node with id NId.
Definition: network.cpp:2342
int TUndirNet::AddSAttrDatN ( const TInt NId,
const TStr AttrName,
const TStr Val 
)

Adds Str sparse attribute with name AttrName to the given node with id NId.

Definition at line 2370 of file network.cpp.

2370  {
2371  if (!IsNode(NId)) {
2372  return -1;
2373  }
2374  return SAttrN.AddSAttrDat(NId, AttrName, Val);
2375 }
int AddSAttrDat(const TInt &Id, const TStr &AttrName, const TInt &Val)
Add Int attribute with name AttrName for the given id Id.
Definition: attr.cpp:2
bool IsNode(const int &NId) const
Tests whether ID NId is a node.
Definition: network.h:3620
TAttr SAttrN
Definition: network.h:3512
int TUndirNet::AddSAttrDatN ( const TInt NId,
const TInt AttrId,
const TStr Val 
)

Adds Str sparse attribute with id AttrId to the given node with id NId.

Definition at line 2377 of file network.cpp.

2377  {
2378  if (!IsNode(NId)) {
2379  return -1;
2380  }
2381  return SAttrN.AddSAttrDat(NId, AttrId, Val);
2382 }
int AddSAttrDat(const TInt &Id, const TStr &AttrName, const TInt &Val)
Add Int attribute with name AttrName for the given id Id.
Definition: attr.cpp:2
bool IsNode(const int &NId) const
Tests whether ID NId is a node.
Definition: network.h:3620
TAttr SAttrN
Definition: network.h:3512
int TUndirNet::AddSAttrDatN ( const TNodeI NodeI,
const TStr AttrName,
const TStr Val 
)
inline

Adds Str sparse attribute with name AttrName to NodeI.

Definition at line 3745 of file network.h.

3745  {
3746  return AddSAttrDatN(NodeI.GetId(), AttrName, Val);
3747  }
int AddSAttrDatN(const TInt &NId, const TStr &AttrName, const TInt &Val)
Adds Int sparse attribute with name AttrName to the given node with id NId.
Definition: network.cpp:2342
int TUndirNet::AddSAttrDatN ( const TNodeI NodeI,
const TInt AttrId,
const TStr Val 
)
inline

Adds Str sparse attribute with id AttrId to NodeI.

Definition at line 3749 of file network.h.

3749  {
3750  return AddSAttrDatN(NodeI.GetId(), AttrId, Val);
3751  }
int AddSAttrDatN(const TInt &NId, const TStr &AttrName, const TInt &Val)
Adds Int sparse attribute with name AttrName to the given node with id NId.
Definition: network.cpp:2342
int TUndirNet::AddSAttrE ( const TStr Name,
const TAttrType AttrType,
TInt AttrId 
)

Adds mapping for sparse attribute with name Name and type AttrType.

Definition at line 2604 of file network.cpp.

2604  {
2605  return SAttrE.AddSAttr(Name, AttrType, AttrId);
2606 }
int AddSAttr(const TStr &Name, const TAttrType &AttrType, TInt &AttrIdX)
Adds a mapping for an attribute with name Name and type AttrType.
Definition: attr.cpp:454
TAttrPair SAttrE
Definition: network.h:3513
int TUndirNet::AddSAttrN ( const TStr Name,
const TAttrType AttrType,
TInt AttrId 
)

Adds mapping for sparse attribute with name Name and type AttrType.

Definition at line 2456 of file network.cpp.

2456  {
2457  return SAttrN.AddSAttr(Name, AttrType, AttrId);
2458 }
TAttr SAttrN
Definition: network.h:3512
int AddSAttr(const TStr &Name, const TAttrType &AttrType, TInt &AttrIdX)
Adds a mapping for an attribute with name Name and type AttrType.
Definition: attr.cpp:210
TEdgeI TUndirNet::BegEI ( ) const
inline

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

Definition at line 3660 of file network.h.

3660 { TNodeI NI = BegNI(); TEdgeI EI(NI, EndNI(), 0); if (GetNodes() != 0 && (NI.GetOutDeg()==0 || NI.GetId()>NI.GetOutNId(0))) { EI++; } return EI; }
TNodeI BegNI() const
Returns an iterator referring to the first node in the network.
Definition: network.h:3622
TNodeI EndNI() const
Returns an iterator referring to the past-the-end node in the network.
Definition: network.h:3624
int GetNodes() const
Returns the number of nodes in the network.
Definition: network.h:3576
TNodeI TUndirNet::BegNI ( ) const
inline

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

Definition at line 3622 of file network.h.

3622 { return TNodeI(NodeH.BegI()); }
THash< TInt, TNode > NodeH
Definition: network.h:3510
TIter BegI() const
Definition: hash.h:213
void TUndirNet::Clr ( )
inline

Deletes all nodes and edges from the network.

Definition at line 3681 of file network.h.

3681 { MxNId=0; NEdges=0; NodeH.Clr(); SAttrN.Clr(); SAttrE.Clr(); }
THash< TInt, TNode > NodeH
Definition: network.h:3510
TInt MxNId
Definition: network.h:3509
void Clr()
Clears the contents of the attribute map.
Definition: attr.h:122
TAttrPair SAttrE
Definition: network.h:3513
TAttr SAttrN
Definition: network.h:3512
void Clr(const bool &DoDel=true, const int &NoDelLim=-1, const bool &ResetDat=true)
Definition: hash.h:361
TInt NEdges
Definition: network.h:3509
void Clr()
Clears the contents of the attribute map.
Definition: attr.h:37
void TUndirNet::Defrag ( const bool &  OnlyNodeLinks = false)

Defragments the network.

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

Definition at line 2272 of file network.cpp.

2272  {
2273  for (int n = NodeH.FFirstKeyId(); NodeH.FNextKeyId(n); ) {
2274  NodeH[n].NIdV.Pack();
2275  }
2276  if (! OnlyNodeLinks && ! NodeH.IsKeyIdEqKeyN()) {
2277  NodeH.Defrag();
2278  }
2279 }
bool IsKeyIdEqKeyN() const
Definition: hash.h:233
THash< TInt, TNode > NodeH
Definition: network.h:3510
void Defrag()
Definition: hash.h:555
bool FNextKeyId(int &KeyId) const
Definition: hash.h:478
int FFirstKeyId() const
Definition: hash.h:278
void Pack()
Definition: hash.h:289
void TUndirNet::DelEdge ( const int &  SrcNId,
const int &  DstNId 
)

Deletes an edge between node IDs SrcNId and DstNId from the network.

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

Definition at line 2233 of file network.cpp.

2233  {
2234  IAssertR(IsNode(SrcNId) && IsNode(DstNId), TStr::Fmt("%d or %d not a node.", SrcNId, DstNId).CStr());
2235  { TNode& N = GetNode(SrcNId);
2236  const int n = N.NIdV.SearchBin(DstNId);
2237  TIntPr Id(SrcNId, DstNId);
2238  SAttrE.DelSAttrId(Id);
2239  if (n!= -1) { N.NIdV.Del(n); NEdges--; } }
2240  if (SrcNId != DstNId) { // not a self edge
2241  TNode& N = GetNode(DstNId);
2242  const int n = N.NIdV.SearchBin(SrcNId);
2243  if (n!= -1) { N.NIdV.Del(n); }
2244  }
2245 }
#define IAssertR(Cond, Reason)
Definition: bd.h:265
void DelSAttrId(const TIntPr &Id)
Delete all attributes for the given id Id.
Definition: attr.cpp:368
bool IsNode(const int &NId) const
Tests whether ID NId is a node.
Definition: network.h:3620
TNode & GetNode(const int &NId)
Definition: network.h:3515
Definition: ds.h:32
TAttrPair SAttrE
Definition: network.h:3513
static TStr Fmt(const char *FmtStr,...)
Definition: dt.cpp:1599
TInt NEdges
Definition: network.h:3509
void TUndirNet::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 2186 of file network.cpp.

2186  {
2187  { AssertR(IsNode(NId), TStr::Fmt("NodeId %d does not exist", NId));
2188  TInt Id(NId);
2189  SAttrN.DelSAttrId(Id);
2190  TNode& Node = GetNode(NId);
2191  NEdges -= Node.GetDeg();
2192  for (int e = 0; e < Node.GetDeg(); e++) {
2193  const int nbr = Node.GetNbrNId(e);
2194  if (nbr == NId) { continue; }
2195  TNode& N = GetNode(nbr);
2196  const int n = N.NIdV.SearchBin(NId);
2197  IAssert(n != -1); // if NId points to N, then N also should point back
2198  if (n!= -1) { N.NIdV.Del(n); }
2199  } }
2200  NodeH.DelKey(NId);
2201 }
#define IAssert(Cond)
Definition: bd.h:262
THash< TInt, TNode > NodeH
Definition: network.h:3510
void DelSAttrId(const TInt &Id)
Delete all attributes for the given id Id.
Definition: attr.cpp:124
void DelKey(const TKey &Key)
Definition: hash.h:404
bool IsNode(const int &NId) const
Tests whether ID NId is a node.
Definition: network.h:3620
TNode & GetNode(const int &NId)
Definition: network.h:3515
Definition: dt.h:1137
static TStr Fmt(const char *FmtStr,...)
Definition: dt.cpp:1599
TAttr SAttrN
Definition: network.h:3512
#define AssertR(Cond, Reason)
Definition: bd.h:258
TInt NEdges
Definition: network.h:3509
void TUndirNet::DelNode ( const TNode NodeI)
inline

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

Definition at line 3618 of file network.h.

3618 { DelNode(NodeI.GetId()); }
void DelNode(const int &NId)
Deletes node of ID NId from the network.
Definition: network.cpp:2186
int TUndirNet::DelSAttrDatE ( const int &  SrcNId,
const int &  DstNId,
const TStr AttrName 
)

Deletes sparse attribute with name AttrName from edge with ids SrcId and DstId.

Definition at line 2571 of file network.cpp.

2571  {
2572  if (!IsEdge(SrcNId, DstNId)) {
2573  return -1;
2574  }
2575  TIntPr EId = OrderEdgeNodes(SrcNId, DstNId);
2576  return SAttrE.DelSAttrDat(EId, AttrName);
2577 }
bool IsEdge(const int &SrcNId, const int &DstNId) const
Tests whether an edge between node IDs SrcNId and DstNId exists in the network.
Definition: network.cpp:2248
Definition: ds.h:32
TAttrPair SAttrE
Definition: network.h:3513
int DelSAttrDat(const TIntPr &Id, const TStr &AttrName)
Delete attribute with name AttrName for the given id Id.
Definition: attr.cpp:347
TIntPr OrderEdgeNodes(const int &SrcNId, const int &DstNId) const
Definition: network.cpp:2468
int TUndirNet::DelSAttrDatE ( const int &  SrcNId,
const int &  DstNId,
const TInt AttrId 
)

Deletes sparse attribute with id AttrId from edge with ids SrcId and DstId.

Definition at line 2579 of file network.cpp.

2579  {
2580  if (!IsEdge(SrcNId, DstNId)) {
2581  return -1;
2582  }
2583  TIntPr EId = OrderEdgeNodes(SrcNId, DstNId);
2584  return SAttrE.DelSAttrDat(EId, AttrId);
2585 }
bool IsEdge(const int &SrcNId, const int &DstNId) const
Tests whether an edge between node IDs SrcNId and DstNId exists in the network.
Definition: network.cpp:2248
Definition: ds.h:32
TAttrPair SAttrE
Definition: network.h:3513
int DelSAttrDat(const TIntPr &Id, const TStr &AttrName)
Delete attribute with name AttrName for the given id Id.
Definition: attr.cpp:347
TIntPr OrderEdgeNodes(const int &SrcNId, const int &DstNId) const
Definition: network.cpp:2468
int TUndirNet::DelSAttrDatE ( const TEdgeI EdgeI,
const TStr AttrName 
)
inline

Deletes sparse attribute with name AttrName from EdgeI.

Definition at line 3919 of file network.h.

3919  {
3920  return DelSAttrDatE(EdgeI.GetSrcNId(), EdgeI.GetDstNId(), AttrName);
3921  }
int DelSAttrDatE(const int &SrcNId, const int &DstNId, const TStr &AttrName)
Deletes sparse attribute with name AttrName from edge with ids SrcId and DstId.
Definition: network.cpp:2571
int TUndirNet::DelSAttrDatE ( const TEdgeI EdgeI,
const TInt AttrId 
)
inline

Deletes sparse attribute with id AttrId from EdgeI.

Definition at line 3923 of file network.h.

3923  {
3924  return DelSAttrDatE(EdgeI.GetSrcNId(), EdgeI.GetDstNId(), AttrId);
3925  }
int DelSAttrDatE(const int &SrcNId, const int &DstNId, const TStr &AttrName)
Deletes sparse attribute with name AttrName from edge with ids SrcId and DstId.
Definition: network.cpp:2571
int TUndirNet::DelSAttrDatN ( const TInt NId,
const TStr AttrName 
)

Deletes sparse attribute with name AttrName from node with id NId.

Definition at line 2426 of file network.cpp.

2426  {
2427  if (!IsNode(NId)) {
2428  return -1;
2429  }
2430  return SAttrN.DelSAttrDat(NId, AttrName);
2431 }
int DelSAttrDat(const TInt &Id, const TStr &AttrName)
Delete attribute with name AttrName for the given id Id.
Definition: attr.cpp:103
bool IsNode(const int &NId) const
Tests whether ID NId is a node.
Definition: network.h:3620
TAttr SAttrN
Definition: network.h:3512
int TUndirNet::DelSAttrDatN ( const TInt NId,
const TInt AttrId 
)

Deletes sparse attribute with id AttrId from node with id NId.

Definition at line 2433 of file network.cpp.

2433  {
2434  if (!IsNode(NId)) {
2435  return -1;
2436  }
2437  return SAttrN.DelSAttrDat(NId, AttrId);
2438 }
int DelSAttrDat(const TInt &Id, const TStr &AttrName)
Delete attribute with name AttrName for the given id Id.
Definition: attr.cpp:103
bool IsNode(const int &NId) const
Tests whether ID NId is a node.
Definition: network.h:3620
TAttr SAttrN
Definition: network.h:3512
int TUndirNet::DelSAttrDatN ( const TNodeI NodeI,
const TStr AttrName 
)
inline

Deletes sparse attribute with name AttrName from NodeI.

Definition at line 3801 of file network.h.

3801  {
3802  return DelSAttrDatN(NodeI.GetId(), AttrName);
3803  }
int DelSAttrDatN(const TInt &NId, const TStr &AttrName)
Deletes sparse attribute with name AttrName from node with id NId.
Definition: network.cpp:2426
int TUndirNet::DelSAttrDatN ( const TNodeI NodeI,
const TInt AttrId 
)
inline

Deletes sparse attribute with id AttrId from NodeI.

Definition at line 3805 of file network.h.

3805  {
3806  return DelSAttrDatN(NodeI.GetId(), AttrId);
3807  }
int DelSAttrDatN(const TInt &NId, const TStr &AttrName)
Deletes sparse attribute with name AttrName from node with id NId.
Definition: network.cpp:2426
void TUndirNet::Dump ( FILE *  OutF = stdout) const

Print the network in a human readable form to an output stream OutF.

Definition at line 2319 of file network.cpp.

2319  {
2320  const int NodePlaces = (int) ceil(log10((double) GetNodes()));
2321  fprintf(OutF, "-------------------------------------------------\nUndirected Node Graph: nodes: %d, edges: %d\n", GetNodes(), GetEdges());
2322  for (int N = NodeH.FFirstKeyId(); NodeH.FNextKeyId(N); ) {
2323  const TNode& Node = NodeH[N];
2324  fprintf(OutF, " %*d [%d] ", NodePlaces, Node.GetId(), Node.GetDeg());
2325  for (int edge = 0; edge < Node.GetDeg(); edge++) {
2326  fprintf(OutF, " %*d", NodePlaces, Node.GetNbrNId(edge)); }
2327  fprintf(OutF, "\n");
2328  }
2329  fprintf(OutF, "\n");
2330 }
THash< TInt, TNode > NodeH
Definition: network.h:3510
bool FNextKeyId(int &KeyId) const
Definition: hash.h:478
int FFirstKeyId() const
Definition: hash.h:278
int GetNodes() const
Returns the number of nodes in the network.
Definition: network.h:3576
int GetEdges() const
Returns the number of edges in the network.
Definition: network.cpp:2203
bool TUndirNet::Empty ( ) const
inline

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

Definition at line 3679 of file network.h.

3679 { return GetNodes()==0; }
int GetNodes() const
Returns the number of nodes in the network.
Definition: network.h:3576
TEdgeI TUndirNet::EndEI ( ) const
inline

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

Definition at line 3662 of file network.h.

3662 { return TEdgeI(EndNI(), EndNI()); }
TNodeI EndNI() const
Returns an iterator referring to the past-the-end node in the network.
Definition: network.h:3624
TNodeI TUndirNet::EndNI ( ) const
inline

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

Definition at line 3624 of file network.h.

3624 { return TNodeI(NodeH.EndI()); }
THash< TInt, TNode > NodeH
Definition: network.h:3510
TIter EndI() const
Definition: hash.h:218
int TUndirNet::GetEdges ( ) const

Returns the number of edges in the network.

Definition at line 2203 of file network.cpp.

2203  {
2204  //int Edges = 0;
2205  //for (int N=NodeH.FFirstKeyId(); NodeH.FNextKeyId(N); ) {
2206  // Edges += NodeH[N].GetDeg();
2207  //}
2208  //return Edges/2;
2209  return NEdges;
2210 }
TInt NEdges
Definition: network.h:3509
TEdgeI TUndirNet::GetEI ( const int &  EId) const

Not supported/implemented!

TUndirNet::TEdgeI TUndirNet::GetEI ( const int &  SrcNId,
const int &  DstNId 
) const

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

Note that since this is an undirected graph GetEI(SrcNId, DstNId) has the same effect as GetEI(DstNId, SrcNId).

Definition at line 2254 of file network.cpp.

2254  {
2255  const int MnNId = TMath::Mn(SrcNId, DstNId);
2256  const int MxNId = TMath::Mx(SrcNId, DstNId);
2257  const TNodeI SrcNI = GetNI(MnNId);
2258  const int NodeN = SrcNI.NodeHI.GetDat().NIdV.SearchBin(MxNId);
2259  IAssert(NodeN != -1);
2260  return TEdgeI(SrcNI, EndNI(), NodeN);
2261 }
#define IAssert(Cond)
Definition: bd.h:262
static const T & Mn(const T &LVal, const T &RVal)
Definition: xmath.h:36
static const T & Mx(const T &LVal, const T &RVal)
Definition: xmath.h:32
TInt MxNId
Definition: network.h:3509
TNodeI EndNI() const
Returns an iterator referring to the past-the-end node in the network.
Definition: network.h:3624
TNodeI GetNI(const int &NId) const
Returns an iterator referring to the node of ID NId in the network.
Definition: network.h:3626
int TUndirNet::GetIdVSAttrE ( const TStr AttrName,
TIntPrV IdV 
) const

Gets a list of all edges that have a sparse attribute with name AttrName.

Definition at line 2596 of file network.cpp.

2596  {
2597  return SAttrE.GetIdVSAttr(AttrName, IdV);
2598 }
int GetIdVSAttr(const TInt &AttrId, const TAttrType Type, TIntPrV &IdV) const
Definition: attr.cpp:411
TAttrPair SAttrE
Definition: network.h:3513
int TUndirNet::GetIdVSAttrE ( const TInt AttrId,
TIntPrV IdV 
) const

Gets a list of all edges that have a sparse attribute with id AttrId.

Definition at line 2600 of file network.cpp.

2600  {
2601  return SAttrE.GetIdVSAttr(AttrId, IdV);
2602 }
int GetIdVSAttr(const TInt &AttrId, const TAttrType Type, TIntPrV &IdV) const
Definition: attr.cpp:411
TAttrPair SAttrE
Definition: network.h:3513
int TUndirNet::GetIdVSAttrN ( const TStr AttrName,
TIntV IdV 
) const

Gets a list of all nodes that have a sparse attribute with name AttrName.

Definition at line 2448 of file network.cpp.

2448  {
2449  return SAttrN.GetIdVSAttr(AttrName, IdV);
2450 }
int GetIdVSAttr(const TInt &AttrId, const TAttrType Type, TIntV &IdV) const
Definition: attr.cpp:167
TAttr SAttrN
Definition: network.h:3512
int TUndirNet::GetIdVSAttrN ( const TInt AttrId,
TIntV IdV 
) const

Gets a list of all nodes that have a sparse attribute with id AttrId.

Definition at line 2452 of file network.cpp.

2452  {
2453  return SAttrN.GetIdVSAttr(AttrId, IdV);
2454 }
int GetIdVSAttr(const TInt &AttrId, const TAttrType Type, TIntV &IdV) const
Definition: attr.cpp:167
TAttr SAttrN
Definition: network.h:3512
int TUndirNet::GetMxNId ( ) const
inline

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

Definition at line 3628 of file network.h.

3628 { return MxNId; }
TInt MxNId
Definition: network.h:3509
TNodeI TUndirNet::GetNI ( const int &  NId) const
inline

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

Definition at line 3626 of file network.h.

3626 { return TNodeI(NodeH.GetI(NId)); }
THash< TInt, TNode > NodeH
Definition: network.h:3510
TIter GetI(const TKey &Key) const
Definition: hash.h:220
void TUndirNet::GetNIdV ( TIntV NIdV) const

Gets a vector IDs of all nodes in the network.

Definition at line 2265 of file network.cpp.

2265  {
2266  NIdV.Gen(GetNodes(), 0);
2267  for (int N=NodeH.FFirstKeyId(); NodeH.FNextKeyId(N); ) {
2268  NIdV.Add(NodeH.GetKey(N)); }
2269 }
THash< TInt, TNode > NodeH
Definition: network.h:3510
bool FNextKeyId(int &KeyId) const
Definition: hash.h:478
int FFirstKeyId() const
Definition: hash.h:278
int GetNodes() const
Returns the number of nodes in the network.
Definition: network.h:3576
void Gen(const TSizeTy &_Vals)
Constructs a vector (an array) of _Vals elements.
Definition: ds.h:523
TSizeTy Add()
Adds a new element at the end of the vector, after its current last element.
Definition: ds.h:602
const TKey & GetKey(const int &KeyId) const
Definition: hash.h:252
TNode& TUndirNet::GetNode ( const int &  NId)
inlineprivate

Definition at line 3515 of file network.h.

3515 { return NodeH.GetDat(NId); }
THash< TInt, TNode > NodeH
Definition: network.h:3510
const TDat & GetDat(const TKey &Key) const
Definition: hash.h:262
const TNode& TUndirNet::GetNode ( const int &  NId) const
inlineprivate

Definition at line 3516 of file network.h.

3516 { return NodeH.GetDat(NId); }
THash< TInt, TNode > NodeH
Definition: network.h:3510
const TDat & GetDat(const TKey &Key) const
Definition: hash.h:262
int TUndirNet::GetNodes ( ) const
inline

Returns the number of nodes in the network.

Definition at line 3576 of file network.h.

3576 { return NodeH.Len(); }
THash< TInt, TNode > NodeH
Definition: network.h:3510
int Len() const
Definition: hash.h:228
TNodeI TUndirNet::GetRndNI ( TRnd Rnd = TInt::Rnd)
inline

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

Definition at line 3674 of file network.h.

3674 { return GetNI(GetRndNId(Rnd)); }
int GetRndNId(TRnd &Rnd=TInt::Rnd)
Returns an ID of a random node in the network.
Definition: network.h:3672
TNodeI GetNI(const int &NId) const
Returns an iterator referring to the node of ID NId in the network.
Definition: network.h:3626
int TUndirNet::GetRndNId ( TRnd Rnd = TInt::Rnd)
inline

Returns an ID of a random node in the network.

Definition at line 3672 of file network.h.

3672 { return NodeH.GetKey(NodeH.GetRndKeyId(Rnd, 0.8)); }
THash< TInt, TNode > NodeH
Definition: network.h:3510
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:444
const TKey & GetKey(const int &KeyId) const
Definition: hash.h:252
int TUndirNet::GetSAttrDatE ( const int &  SrcNId,
const int &  DstNId,
const TStr AttrName,
TInt ValX 
) const

Gets Int sparse attribute with name AttrName from edge with ids SrcId and DstId.

Definition at line 2523 of file network.cpp.

2523  {
2524  if (!IsEdge(SrcNId, DstNId)) {
2525  return -1;
2526  }
2527  TIntPr EId = OrderEdgeNodes(SrcNId, DstNId);
2528  return SAttrE.GetSAttrDat(EId, AttrName, Val);
2529 }
int GetSAttrDat(const TIntPr &Id, const TStr &AttrName, TInt &ValX) const
Get Int attribute with name AttrName for the given id Id.
Definition: attr.cpp:298
bool IsEdge(const int &SrcNId, const int &DstNId) const
Tests whether an edge between node IDs SrcNId and DstNId exists in the network.
Definition: network.cpp:2248
Definition: ds.h:32
TAttrPair SAttrE
Definition: network.h:3513
TIntPr OrderEdgeNodes(const int &SrcNId, const int &DstNId) const
Definition: network.cpp:2468
int TUndirNet::GetSAttrDatE ( const int &  SrcNId,
const int &  DstNId,
const TInt AttrId,
TInt ValX 
) const

Gets Int sparse attribute with id AttrId from edge with ids SrcId and DstId.

Definition at line 2531 of file network.cpp.

2531  {
2532  if (!IsEdge(SrcNId, DstNId)) {
2533  return -1;
2534  }
2535  TIntPr EId = OrderEdgeNodes(SrcNId, DstNId);
2536  return SAttrE.GetSAttrDat(EId, AttrId, Val);
2537 }
int GetSAttrDat(const TIntPr &Id, const TStr &AttrName, TInt &ValX) const
Get Int attribute with name AttrName for the given id Id.
Definition: attr.cpp:298
bool IsEdge(const int &SrcNId, const int &DstNId) const
Tests whether an edge between node IDs SrcNId and DstNId exists in the network.
Definition: network.cpp:2248
Definition: ds.h:32
TAttrPair SAttrE
Definition: network.h:3513
TIntPr OrderEdgeNodes(const int &SrcNId, const int &DstNId) const
Definition: network.cpp:2468
int TUndirNet::GetSAttrDatE ( const TEdgeI EdgeI,
const TStr AttrName,
TInt ValX 
) const
inline

Gets Int sparse attribute with name AttrName from EdgeI.

Definition at line 3877 of file network.h.

3877  {
3878  return GetSAttrDatE(EdgeI.GetSrcNId(), EdgeI.GetDstNId(), AttrName, ValX);
3879  }
int GetSAttrDatE(const int &SrcNId, const int &DstNId, const TStr &AttrName, TInt &ValX) const
Gets Int sparse attribute with name AttrName from edge with ids SrcId and DstId.
Definition: network.cpp:2523
int TUndirNet::GetSAttrDatE ( const TEdgeI EdgeI,
const TInt AttrId,
TInt ValX 
) const
inline

Gets Int sparse attribute with id AttrId from EdgeI.

Definition at line 3881 of file network.h.

3881  {
3882  return GetSAttrDatE(EdgeI.GetSrcNId(), EdgeI.GetDstNId(), AttrId, ValX);
3883  }
int GetSAttrDatE(const int &SrcNId, const int &DstNId, const TStr &AttrName, TInt &ValX) const
Gets Int sparse attribute with name AttrName from edge with ids SrcId and DstId.
Definition: network.cpp:2523
int TUndirNet::GetSAttrDatE ( const int &  SrcNId,
const int &  DstNId,
const TStr AttrName,
TFlt ValX 
) const

Gets Flt sparse attribute with name AttrName from edge with ids SrcId and DstId.

Definition at line 2539 of file network.cpp.

2539  {
2540  if (!IsEdge(SrcNId, DstNId)) {
2541  return -1;
2542  }
2543  TIntPr EId = OrderEdgeNodes(SrcNId, DstNId);
2544  return SAttrE.GetSAttrDat(EId, AttrName, Val);
2545 }
int GetSAttrDat(const TIntPr &Id, const TStr &AttrName, TInt &ValX) const
Get Int attribute with name AttrName for the given id Id.
Definition: attr.cpp:298
bool IsEdge(const int &SrcNId, const int &DstNId) const
Tests whether an edge between node IDs SrcNId and DstNId exists in the network.
Definition: network.cpp:2248
Definition: ds.h:32
TAttrPair SAttrE
Definition: network.h:3513
TIntPr OrderEdgeNodes(const int &SrcNId, const int &DstNId) const
Definition: network.cpp:2468
int TUndirNet::GetSAttrDatE ( const int &  SrcNId,
const int &  DstNId,
const TInt AttrId,
TFlt ValX 
) const

Gets Flt sparse attribute with id AttrId from edge with ids SrcId and DstId.

Definition at line 2547 of file network.cpp.

2547  {
2548  if (!IsEdge(SrcNId, DstNId)) {
2549  return -1;
2550  }
2551  TIntPr EId = OrderEdgeNodes(SrcNId, DstNId);
2552  return SAttrE.GetSAttrDat(EId, AttrId, Val);
2553 }
int GetSAttrDat(const TIntPr &Id, const TStr &AttrName, TInt &ValX) const
Get Int attribute with name AttrName for the given id Id.
Definition: attr.cpp:298
bool IsEdge(const int &SrcNId, const int &DstNId) const
Tests whether an edge between node IDs SrcNId and DstNId exists in the network.
Definition: network.cpp:2248
Definition: ds.h:32
TAttrPair SAttrE
Definition: network.h:3513
TIntPr OrderEdgeNodes(const int &SrcNId, const int &DstNId) const
Definition: network.cpp:2468
int TUndirNet::GetSAttrDatE ( const TEdgeI EdgeI,
const TStr AttrName,
TFlt ValX 
) const
inline

Gets Flt sparse attribute with name AttrName from EdgeI.

Definition at line 3891 of file network.h.

3891  {
3892  return GetSAttrDatE(EdgeI.GetSrcNId(), EdgeI.GetDstNId(), AttrName, ValX);
3893  }
int GetSAttrDatE(const int &SrcNId, const int &DstNId, const TStr &AttrName, TInt &ValX) const
Gets Int sparse attribute with name AttrName from edge with ids SrcId and DstId.
Definition: network.cpp:2523
int TUndirNet::GetSAttrDatE ( const TEdgeI EdgeI,
const TInt AttrId,
TFlt ValX 
) const
inline

Gets Flt sparse attribute with id AttrId from EdgeI.

Definition at line 3895 of file network.h.

3895  {
3896  return GetSAttrDatE(EdgeI.GetSrcNId(), EdgeI.GetDstNId(), AttrId, ValX);
3897  }
int GetSAttrDatE(const int &SrcNId, const int &DstNId, const TStr &AttrName, TInt &ValX) const
Gets Int sparse attribute with name AttrName from edge with ids SrcId and DstId.
Definition: network.cpp:2523
int TUndirNet::GetSAttrDatE ( const int &  SrcNId,
const int &  DstNId,
const TStr AttrName,
TStr ValX 
) const

Gets Str sparse attribute with name AttrName from edge with ids SrcId and DstId.

Definition at line 2555 of file network.cpp.

2555  {
2556  if (!IsEdge(SrcNId, DstNId)) {
2557  return -1;
2558  }
2559  TIntPr EId = OrderEdgeNodes(SrcNId, DstNId);
2560  return SAttrE.GetSAttrDat(EId, AttrName, Val);
2561 }
int GetSAttrDat(const TIntPr &Id, const TStr &AttrName, TInt &ValX) const
Get Int attribute with name AttrName for the given id Id.
Definition: attr.cpp:298
bool IsEdge(const int &SrcNId, const int &DstNId) const
Tests whether an edge between node IDs SrcNId and DstNId exists in the network.
Definition: network.cpp:2248
Definition: ds.h:32
TAttrPair SAttrE
Definition: network.h:3513
TIntPr OrderEdgeNodes(const int &SrcNId, const int &DstNId) const
Definition: network.cpp:2468
int TUndirNet::GetSAttrDatE ( const int &  SrcNId,
const int &  DstNId,
const TInt AttrId,
TStr ValX 
) const

Gets Str sparse attribute with id AttrId from edge with ids SrcId and DstId.

Definition at line 2563 of file network.cpp.

2563  {
2564  if (!IsEdge(SrcNId, DstNId)) {
2565  return -1;
2566  }
2567  TIntPr EId = OrderEdgeNodes(SrcNId, DstNId);
2568  return SAttrE.GetSAttrDat(EId, AttrId, Val);
2569 }
int GetSAttrDat(const TIntPr &Id, const TStr &AttrName, TInt &ValX) const
Get Int attribute with name AttrName for the given id Id.
Definition: attr.cpp:298
bool IsEdge(const int &SrcNId, const int &DstNId) const
Tests whether an edge between node IDs SrcNId and DstNId exists in the network.
Definition: network.cpp:2248
Definition: ds.h:32
TAttrPair SAttrE
Definition: network.h:3513
TIntPr OrderEdgeNodes(const int &SrcNId, const int &DstNId) const
Definition: network.cpp:2468
int TUndirNet::GetSAttrDatE ( const TEdgeI EdgeI,
const TStr AttrName,
TStr ValX 
) const
inline

Gets Str sparse attribute with name AttrName from EdgeI.

Definition at line 3905 of file network.h.

3905  {
3906  return GetSAttrDatE(EdgeI.GetSrcNId(), EdgeI.GetDstNId(), AttrName, ValX);
3907  }
int GetSAttrDatE(const int &SrcNId, const int &DstNId, const TStr &AttrName, TInt &ValX) const
Gets Int sparse attribute with name AttrName from edge with ids SrcId and DstId.
Definition: network.cpp:2523
int TUndirNet::GetSAttrDatE ( const TEdgeI EdgeI,
const TInt AttrId,
TStr ValX 
) const
inline

Gets Str sparse attribute with id AttrId from EdgeI.

Definition at line 3909 of file network.h.

3909  {
3910  return GetSAttrDatE(EdgeI.GetSrcNId(), EdgeI.GetDstNId(), AttrId, ValX);
3911  }
int GetSAttrDatE(const int &SrcNId, const int &DstNId, const TStr &AttrName, TInt &ValX) const
Gets Int sparse attribute with name AttrName from edge with ids SrcId and DstId.
Definition: network.cpp:2523
int TUndirNet::GetSAttrDatN ( const TInt NId,
const TStr AttrName,
TInt ValX 
) const

Gets Int sparse attribute with name AttrName from node with id NId.

Definition at line 2384 of file network.cpp.

2384  {
2385  if (!IsNode(NId)) {
2386  return -1;
2387  }
2388  return SAttrN.GetSAttrDat(NId, AttrName, Val);
2389 }
bool IsNode(const int &NId) const
Tests whether ID NId is a node.
Definition: network.h:3620
int GetSAttrDat(const TInt &Id, const TStr &AttrName, TInt &ValX) const
Get Int attribute with name AttrName for the given id Id.
Definition: attr.cpp:54
TAttr SAttrN
Definition: network.h:3512
int TUndirNet::GetSAttrDatN ( const TInt NId,
const TInt AttrId,
TInt ValX 
) const

Gets Int sparse attribute with id AttrId from node with id NId.

Definition at line 2391 of file network.cpp.

2391  {
2392  if (!IsNode(NId)) {
2393  return -1;
2394  }
2395  return SAttrN.GetSAttrDat(NId, AttrId, Val);
2396 }
bool IsNode(const int &NId) const
Tests whether ID NId is a node.
Definition: network.h:3620
int GetSAttrDat(const TInt &Id, const TStr &AttrName, TInt &ValX) const
Get Int attribute with name AttrName for the given id Id.
Definition: attr.cpp:54
TAttr SAttrN
Definition: network.h:3512
int TUndirNet::GetSAttrDatN ( const TNodeI NodeI,
const TStr AttrName,
TInt ValX 
) const
inline

Gets Int sparse attribute with name AttrName from NodeI.

Definition at line 3759 of file network.h.

3759  {
3760  return GetSAttrDatN(NodeI.GetId(), AttrName, ValX);
3761  }
int GetSAttrDatN(const TInt &NId, const TStr &AttrName, TInt &ValX) const
Gets Int sparse attribute with name AttrName from node with id NId.
Definition: network.cpp:2384
int TUndirNet::GetSAttrDatN ( const TNodeI NodeI,
const TInt AttrId,
TInt ValX 
) const
inline

Gets Int sparse attribute with id AttrId from NodeI.

Definition at line 3763 of file network.h.

3763  {
3764  return GetSAttrDatN(NodeI.GetId(), AttrId, ValX);
3765  }
int GetSAttrDatN(const TInt &NId, const TStr &AttrName, TInt &ValX) const
Gets Int sparse attribute with name AttrName from node with id NId.
Definition: network.cpp:2384
int TUndirNet::GetSAttrDatN ( const TInt NId,
const TStr AttrName,
TFlt ValX 
) const

Gets Flt sparse attribute with name AttrName from node with id NId.

Definition at line 2398 of file network.cpp.

2398  {
2399  if (!IsNode(NId)) {
2400  return -1;
2401  }
2402  return SAttrN.GetSAttrDat(NId, AttrName, Val);
2403 }
bool IsNode(const int &NId) const
Tests whether ID NId is a node.
Definition: network.h:3620
int GetSAttrDat(const TInt &Id, const TStr &AttrName, TInt &ValX) const
Get Int attribute with name AttrName for the given id Id.
Definition: attr.cpp:54
TAttr SAttrN
Definition: network.h:3512
int TUndirNet::GetSAttrDatN ( const TInt NId,
const TInt AttrId,
TFlt ValX 
) const

Gets Flt sparse attribute with id AttrId from node with id NId.

Definition at line 2405 of file network.cpp.

2405  {
2406  if (!IsNode(NId)) {
2407  return -1;
2408  }
2409  return SAttrN.GetSAttrDat(NId, AttrId, Val);
2410 }
bool IsNode(const int &NId) const
Tests whether ID NId is a node.
Definition: network.h:3620
int GetSAttrDat(const TInt &Id, const TStr &AttrName, TInt &ValX) const
Get Int attribute with name AttrName for the given id Id.
Definition: attr.cpp:54
TAttr SAttrN
Definition: network.h:3512
int TUndirNet::GetSAttrDatN ( const TNodeI NodeI,
const TStr AttrName,
TFlt ValX 
) const
inline

Gets Flt sparse attribute with name AttrName from NodeI.

Definition at line 3773 of file network.h.

3773  {
3774  return GetSAttrDatN(NodeI.GetId(), AttrName, ValX);
3775  }
int GetSAttrDatN(const TInt &NId, const TStr &AttrName, TInt &ValX) const
Gets Int sparse attribute with name AttrName from node with id NId.
Definition: network.cpp:2384
int TUndirNet::GetSAttrDatN ( const TNodeI NodeI,
const TInt AttrId,
TFlt ValX 
) const
inline

Gets Flt sparse attribute with id AttrId from NodeI.

Definition at line 3777 of file network.h.

3777  {
3778  return GetSAttrDatN(NodeI.GetId(), AttrId, ValX);
3779  }
int GetSAttrDatN(const TInt &NId, const TStr &AttrName, TInt &ValX) const
Gets Int sparse attribute with name AttrName from node with id NId.
Definition: network.cpp:2384
int TUndirNet::GetSAttrDatN ( const TInt NId,
const TStr AttrName,
TStr ValX 
) const

Gets Str sparse attribute with name AttrName from node with id NId.

Definition at line 2412 of file network.cpp.

2412  {
2413  if (!IsNode(NId)) {
2414  return -1;
2415  }
2416  return SAttrN.GetSAttrDat(NId, AttrName, Val);
2417 }
bool IsNode(const int &NId) const
Tests whether ID NId is a node.
Definition: network.h:3620
int GetSAttrDat(const TInt &Id, const TStr &AttrName, TInt &ValX) const
Get Int attribute with name AttrName for the given id Id.
Definition: attr.cpp:54
TAttr SAttrN
Definition: network.h:3512
int TUndirNet::GetSAttrDatN ( const TInt NId,
const TInt AttrId,
TStr ValX 
) const

Gets Str sparse attribute with id AttrId from node with id NId.

Definition at line 2419 of file network.cpp.

2419  {
2420  if (!IsNode(NId)) {
2421  return -1;
2422  }
2423  return SAttrN.GetSAttrDat(NId, AttrId, Val);
2424 }
bool IsNode(const int &NId) const
Tests whether ID NId is a node.
Definition: network.h:3620
int GetSAttrDat(const TInt &Id, const TStr &AttrName, TInt &ValX) const
Get Int attribute with name AttrName for the given id Id.
Definition: attr.cpp:54
TAttr SAttrN
Definition: network.h:3512
int TUndirNet::GetSAttrDatN ( const TNodeI NodeI,
const TStr AttrName,
TStr ValX 
) const
inline

Gets Str sparse attribute with name AttrName from NodeI.

Definition at line 3787 of file network.h.

3787  {
3788  return GetSAttrDatN(NodeI.GetId(), AttrName, ValX);
3789  }
int GetSAttrDatN(const TInt &NId, const TStr &AttrName, TInt &ValX) const
Gets Int sparse attribute with name AttrName from node with id NId.
Definition: network.cpp:2384
int TUndirNet::GetSAttrDatN ( const TNodeI NodeI,
const TInt AttrId,
TStr ValX 
) const
inline

Gets Str sparse attribute with id AttrId from NodeI.

Definition at line 3791 of file network.h.

3791  {
3792  return GetSAttrDatN(NodeI.GetId(), AttrId, ValX);
3793  }
int GetSAttrDatN(const TInt &NId, const TStr &AttrName, TInt &ValX) const
Gets Int sparse attribute with name AttrName from node with id NId.
Definition: network.cpp:2384
int TUndirNet::GetSAttrIdE ( const TStr Name,
TInt AttrIdX,
TAttrType AttrTypeX 
) const

Gets id and type for attribute with name Name.

Definition at line 2608 of file network.cpp.

2608  {
2609  return SAttrE.GetSAttrId(Name, AttrId, AttrType);
2610 }
int GetSAttrId(const TStr &Name, TInt &AttrIdX, TAttrType &AttrTypeX) const
Given the attribute name Name, get the attribute id and type.
Definition: attr.cpp:467
TAttrPair SAttrE
Definition: network.h:3513
int TUndirNet::GetSAttrIdN ( const TStr Name,
TInt AttrIdX,
TAttrType AttrTypeX 
) const

Gets id and type for attribute with name Name.

Definition at line 2460 of file network.cpp.

2460  {
2461  return SAttrN.GetSAttrId(Name, AttrId, AttrType);
2462 }
TAttr SAttrN
Definition: network.h:3512
int GetSAttrId(const TStr &Name, TInt &AttrIdX, TAttrType &AttrTypeX) const
Given the attribute name Name, get the attribute id.
Definition: attr.cpp:224
int TUndirNet::GetSAttrNameE ( const TInt AttrId,
TStr NameX,
TAttrType AttrTypeX 
) const

Gets name and type for attribute with id AttrId.

Definition at line 2612 of file network.cpp.

2612  {
2613  return SAttrE.GetSAttrName(AttrId, Name, AttrType);
2614 }
int GetSAttrName(const TInt &AttrId, TStr &NameX, TAttrType &AttrTypeX) const
Given the attribute id AttrId, get the attribute name and type.
Definition: attr.cpp:477
TAttrPair SAttrE
Definition: network.h:3513
int TUndirNet::GetSAttrNameN ( const TInt AttrId,
TStr NameX,
TAttrType AttrTypeX 
) const

Gets name and type for attribute with id AttrId.

Definition at line 2464 of file network.cpp.

2464  {
2465  return SAttrN.GetSAttrName(AttrId, Name, AttrType);
2466 }
int GetSAttrName(const TInt &AttrId, TStr &NameX, TAttrType &AttrTypeX) const
Given the attribute id AttrId, get the attribute name.
Definition: attr.cpp:233
TAttr SAttrN
Definition: network.h:3512
int TUndirNet::GetSAttrVE ( const int &  SrcNId,
const int &  DstNId,
const TAttrType  AttrType,
TAttrPrV AttrV 
) const

Gets a list of all sparse attributes of type AttrType for edge with ids SrcId and DstId.

Definition at line 2587 of file network.cpp.

2587  {
2588  if (!IsEdge(SrcNId, DstNId)) {
2589  return -1;
2590  }
2591  TIntPr EId = OrderEdgeNodes(SrcNId, DstNId);
2592  SAttrE.GetSAttrV(EId, AttrType, AttrV);
2593  return 0;
2594 }
bool IsEdge(const int &SrcNId, const int &DstNId) const
Tests whether an edge between node IDs SrcNId and DstNId exists in the network.
Definition: network.cpp:2248
Definition: ds.h:32
TAttrPair SAttrE
Definition: network.h:3513
void GetSAttrV(const TIntPr &Id, const TAttrType AttrType, TAttrPrV &AttrV) const
Get a list of all attributes of the given type AttrType for the given id Id.
Definition: attr.cpp:383
TIntPr OrderEdgeNodes(const int &SrcNId, const int &DstNId) const
Definition: network.cpp:2468
int TUndirNet::GetSAttrVE ( const TEdgeI EdgeI,
const TAttrType  AttrType,
TAttrPrV AttrV 
) const
inline

Gets a list of all sparse attributes of type AttrType for EdgeI.

Definition at line 3929 of file network.h.

3929  {
3930  return GetSAttrVE(EdgeI.GetSrcNId(), EdgeI.GetDstNId(), AttrType, AttrV);
3931  }
int GetSAttrVE(const int &SrcNId, const int &DstNId, const TAttrType AttrType, TAttrPrV &AttrV) const
Gets a list of all sparse attributes of type AttrType for edge with ids SrcId and DstId...
Definition: network.cpp:2587
int TUndirNet::GetSAttrVN ( const TInt NId,
const TAttrType  AttrType,
TAttrPrV AttrV 
) const

Gets a list of all sparse attributes of type AttrType for node with id NId.

Definition at line 2440 of file network.cpp.

2440  {
2441  if (!IsNode(NId)) {
2442  return -1;
2443  }
2444  SAttrN.GetSAttrV(NId, AttrType, AttrV);
2445  return 0;
2446 }
bool IsNode(const int &NId) const
Tests whether ID NId is a node.
Definition: network.h:3620
void GetSAttrV(const TInt &Id, const TAttrType AttrType, TAttrPrV &AttrV) const
Get a list of all attributes of type AttrType for the given id Id.
Definition: attr.cpp:139
TAttr SAttrN
Definition: network.h:3512
int TUndirNet::GetSAttrVN ( const TNodeI NodeI,
const TAttrType  AttrType,
TAttrPrV AttrV 
) const
inline

Gets a list of all sparse attributes of type AttrType for NodeI.

Definition at line 3812 of file network.h.

3812  {
3813  return GetSAttrVN(NodeI.GetId(), AttrType, AttrV);
3814  }
int GetSAttrVN(const TInt &NId, const TAttrType AttrType, TAttrPrV &AttrV) const
Gets a list of all sparse attributes of type AttrType for node with id NId.
Definition: network.cpp:2440
PUndirNet TUndirNet::GetSmallGraph ( )
static

Returns a small network on 5 nodes and 5 edges.

/// Graph:   3--0--4
///            /|
///           1-2
/// 

Definition at line 2333 of file network.cpp.

2333  {
2334  PUndirNet Graph = TUndirNet::New();
2335  for (int i = 0; i < 5; i++) { Graph->AddNode(i); }
2336  Graph->AddEdge(0,1); Graph->AddEdge(0,2);
2337  Graph->AddEdge(0,3); Graph->AddEdge(0,4);
2338  Graph->AddEdge(1,2);
2339  return Graph;
2340 }
static PUndirNet New()
Static constructor that returns a pointer to the network. Call: PUndirNet Graph = TUndirNet::New()...
Definition: network.h:3547
Definition: bd.h:196
bool TUndirNet::HasFlag ( const TGraphFlag Flag) const

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

Definition at line 2119 of file network.cpp.

2119  {
2120  return HasGraphFlag(TUndirNet::TNet, Flag);
2121 }
#define HasGraphFlag(TGraph, Flag)
For quick testing of the properties of the graph/network object (see TGraphFlag). ...
Definition: gbase.h:41
Undirected network.
Definition: network.h:3397
bool TUndirNet::IsEdge ( const int &  SrcNId,
const int &  DstNId 
) const

Tests whether an edge between node IDs SrcNId and DstNId exists in the network.

Definition at line 2248 of file network.cpp.

2248  {
2249  if (! IsNode(SrcNId) || ! IsNode(DstNId)) return false;
2250  return GetNode(SrcNId).IsNbrNId(DstNId);
2251 }
bool IsNode(const int &NId) const
Tests whether ID NId is a node.
Definition: network.h:3620
TNode & GetNode(const int &NId)
Definition: network.h:3515
bool IsNbrNId(const int &NId) const
Definition: network.h:3419
bool TUndirNet::IsNode ( const int &  NId) const
inline

Tests whether ID NId is a node.

Definition at line 3620 of file network.h.

3620 { return NodeH.IsKey(NId); }
THash< TInt, TNode > NodeH
Definition: network.h:3510
bool IsKey(const TKey &Key) const
Definition: hash.h:258
bool TUndirNet::IsOk ( const bool &  ThrowExcept = true) const

Checks the network data structure for internal consistency.

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

Definition at line 2282 of file network.cpp.

2282  {
2283  bool RetVal = true;
2284  for (int N = NodeH.FFirstKeyId(); NodeH.FNextKeyId(N); ) {
2285  const TNode& Node = NodeH[N];
2286  if (! Node.NIdV.IsSorted()) {
2287  const TStr Msg = TStr::Fmt("Neighbor list of node %d is not sorted.", Node.GetId());
2288  if (ThrowExcept) { EAssertR(false, Msg); } else { ErrNotify(Msg.CStr()); }
2289  RetVal=false;
2290  }
2291  int prevNId = -1;
2292  for (int e = 0; e < Node.GetDeg(); e++) {
2293  if (! IsNode(Node.GetNbrNId(e))) {
2294  const TStr Msg = TStr::Fmt("Edge %d --> %d: node %d does not exist.",
2295  Node.GetId(), Node.GetNbrNId(e), Node.GetNbrNId(e));
2296  if (ThrowExcept) { EAssertR(false, Msg); } else { ErrNotify(Msg.CStr()); }
2297  RetVal=false;
2298  }
2299  if (e > 0 && prevNId == Node.GetNbrNId(e)) {
2300  const TStr Msg = TStr::Fmt("Node %d has duplicate edge %d --> %d.",
2301  Node.GetId(), Node.GetId(), Node.GetNbrNId(e));
2302  if (ThrowExcept) { EAssertR(false, Msg); } else { ErrNotify(Msg.CStr()); }
2303  RetVal=false;
2304  }
2305  prevNId = Node.GetNbrNId(e);
2306  }
2307  }
2308  int EdgeCnt = 0;
2309  for (TEdgeI EI = BegEI(); EI < EndEI(); EI++) { EdgeCnt++; }
2310  if (EdgeCnt != GetEdges()) {
2311  const TStr Msg = TStr::Fmt("Number of edges counter is corrupted: GetEdges():%d, EdgeCount:%d.", GetEdges(), EdgeCnt);
2312  if (ThrowExcept) { EAssertR(false, Msg); } else { ErrNotify(Msg.CStr()); }
2313  RetVal=false;
2314  }
2315  return RetVal;
2316 }
THash< TInt, TNode > NodeH
Definition: network.h:3510
void ErrNotify(const char *NotifyCStr)
Definition: bd.h:74
bool IsNode(const int &NId) const
Tests whether ID NId is a node.
Definition: network.h:3620
bool FNextKeyId(int &KeyId) const
Definition: hash.h:478
int FFirstKeyId() const
Definition: hash.h:278
int GetEdges() const
Returns the number of edges in the network.
Definition: network.cpp:2203
Definition: dt.h:412
static TStr Fmt(const char *FmtStr,...)
Definition: dt.cpp:1599
#define EAssertR(Cond, MsgStr)
Definition: bd.h:283
TEdgeI EndEI() const
Returns an iterator referring to the past-the-end edge in the network.
Definition: network.h:3662
char * CStr()
Definition: dt.h:479
TEdgeI BegEI() const
Returns an iterator referring to the first edge in the network.
Definition: network.h:3660
static PUndirNet TUndirNet::Load ( TSIn SIn)
inlinestatic

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

Definition at line 3553 of file network.h.

3553 { return PUndirNet(new TUndirNet(SIn)); }
TUndirNet()
Definition: network.h:3534
TPt< TUndirNet > PUndirNet
Pointer to an undirected network (TUndirNet)
Definition: network.h:3372
static PUndirNet TUndirNet::Load_V1 ( TSIn SIn)
inlinestatic

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

Definition at line 3555 of file network.h.

3555  { PUndirNet Graph = PUndirNet(new TUndirNet());
3556  Graph->MxNId.Load(SIn); Graph->NEdges.Load(SIn); Graph->NodeH.Load(SIn); return Graph;
3557  }
TUndirNet()
Definition: network.h:3534
TPt< TUndirNet > PUndirNet
Pointer to an undirected network (TUndirNet)
Definition: network.h:3372
Definition: bd.h:196
void TUndirNet::LoadNetworkShM ( TShMIn ShMIn)
inlineprivate

Definition at line 3525 of file network.h.

3525  {
3526  MxNId = TInt(ShMIn);
3527  NEdges = TInt(ShMIn);
3528  LoadTNodeFunctor NodeFn;
3529  NodeH.LoadShM(ShMIn, NodeFn);
3530  SAttrN.Load(ShMIn);
3531  SAttrE = TAttrPair(ShMIn);
3532  }
THash< TInt, TNode > NodeH
Definition: network.h:3510
Definition: attr.h:98
void LoadShM(TShMIn &ShMIn)
Load THash from shared memory file. Copying/Deleting Keys is illegal.
Definition: hash.h:157
TInt MxNId
Definition: network.h:3509
Definition: dt.h:1137
TAttrPair SAttrE
Definition: network.h:3513
TAttr SAttrN
Definition: network.h:3512
void Load(TSIn &SIn)
Load attribute from input stream.
Definition: attr.h:25
TInt NEdges
Definition: network.h:3509
static PUndirNet TUndirNet::LoadShM ( TShMIn ShMIn)
inlinestatic

Static constructor that loads the network from memory.

The object is read-only. It does not support operations that edit the edge vectors of nodes or perform illegal operations on the NodeH, EdgeH (deletion or swapping keys).

Definition at line 3564 of file network.h.

3564  {
3565  TUndirNet* Network = new TUndirNet();
3566  Network->LoadNetworkShM(ShMIn);
3567  return PUndirNet(Network);
3568  }
void LoadNetworkShM(TShMIn &ShMIn)
Definition: network.h:3525
TUndirNet()
Definition: network.h:3534
TPt< TUndirNet > PUndirNet
Pointer to an undirected network (TUndirNet)
Definition: network.h:3372
Undirected network.
Definition: network.h:3397
static PUndirNet TUndirNet::New ( )
inlinestatic

Static constructor that returns a pointer to the network. Call: PUndirNet Graph = TUndirNet::New().

Definition at line 3547 of file network.h.

3547 { return new TUndirNet(); }
TUndirNet()
Definition: network.h:3534
static PUndirNet TUndirNet::New ( const int &  Nodes,
const int &  Edges 
)
inlinestatic

Static constructor that returns a pointer to the network and reserves enough memory for Nodes nodes and Edges edges.

Call: PUndirNet Net = TUndirNet::New(Nodes, Edges).

Definition at line 3551 of file network.h.

3551 { return new TUndirNet(Nodes, Edges); }
TUndirNet()
Definition: network.h:3534
TUndirNet& TUndirNet::operator= ( const TUndirNet Graph)
inline

Definition at line 3572 of file network.h.

3572  {
3573  if (this!=&Graph) { MxNId=Graph.MxNId; NEdges=Graph.NEdges; NodeH=Graph.NodeH; } return *this; }
THash< TInt, TNode > NodeH
Definition: network.h:3510
TInt MxNId
Definition: network.h:3509
TInt NEdges
Definition: network.h:3509
TIntPr TUndirNet::OrderEdgeNodes ( const int &  SrcNId,
const int &  DstNId 
) const
private

Definition at line 2468 of file network.cpp.

2468  {
2469  if (SrcNId < DstNId) {
2470  return TIntPr(SrcNId, DstNId);
2471  }
2472  return TIntPr(DstNId, SrcNId);
2473 }
TPair< TInt, TInt > TIntPr
Definition: ds.h:83
void TUndirNet::Reserve ( const int &  Nodes,
const int &  Edges 
)
inline

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

Definition at line 3683 of file network.h.

3683 { if (Nodes>0) NodeH.Gen(Nodes/2); }
THash< TInt, TNode > NodeH
Definition: network.h:3510
void Gen(const int &ExpectVals)
Definition: hash.h:222
void TUndirNet::ReserveNIdDeg ( const int &  NId,
const int &  Deg 
)
inline

Reserves memory for node ID NId having Deg edges.

Definition at line 3685 of file network.h.

3685 { GetNode(NId).NIdV.Reserve(Deg); }
TNode & GetNode(const int &NId)
Definition: network.h:3515
void Reserve(const TSizeTy &_MxVals)
Reserves enough memory for the vector to store _MxVals elements.
Definition: ds.h:543
void TUndirNet::Save ( TSOut SOut) const
inline

Saves the network to a (binary) stream SOut. Expects data structures for sparse attributes.

Definition at line 3542 of file network.h.

3542  { MxNId.Save(SOut); NEdges.Save(SOut); NodeH.Save(SOut);
3543  SAttrN.Save(SOut); SAttrE.Save(SOut); }
THash< TInt, TNode > NodeH
Definition: network.h:3510
void Save(TSOut &SOut) const
Definition: dt.h:1153
void Save(TSOut &SOut) const
Definition: hash.h:183
void Save(TSOut &SOut) const
Saves the attributes to a (binary) stream SOut.
Definition: attr.h:118
TInt MxNId
Definition: network.h:3509
TAttrPair SAttrE
Definition: network.h:3513
void Save(TSOut &SOut) const
Saves the attributes to a (binary) stream SOut.
Definition: attr.h:33
TAttr SAttrN
Definition: network.h:3512
TInt NEdges
Definition: network.h:3509
void TUndirNet::Save_V1 ( TSOut SOut) const
inline

Saves the network to a (binary) stream SOut. Available for backwards compatibility.

Definition at line 3545 of file network.h.

3545 { MxNId.Save(SOut); NEdges.Save(SOut); NodeH.Save(SOut); }
THash< TInt, TNode > NodeH
Definition: network.h:3510
void Save(TSOut &SOut) const
Definition: dt.h:1153
void Save(TSOut &SOut) const
Definition: hash.h:183
TInt MxNId
Definition: network.h:3509
TInt NEdges
Definition: network.h:3509
void TUndirNet::SortNodeAdjV ( )
inline

Sorts the adjacency lists of each node.

Definition at line 3687 of file network.h.

3687 { for (TNodeI NI = BegNI(); NI < EndNI(); NI++) { NI.SortNIdV();} }
TNodeI BegNI() const
Returns an iterator referring to the first node in the network.
Definition: network.h:3622
TNodeI EndNI() const
Returns an iterator referring to the past-the-end node in the network.
Definition: network.h:3624

Friends And Related Function Documentation

friend class TPt< TUndirNet >
friend

Definition at line 3947 of file network.h.

friend class TUndirNetMtx
friend

Definition at line 3946 of file network.h.

Member Data Documentation

TCRef TUndirNet::CRef
private

Definition at line 3508 of file network.h.

TInt TUndirNet::MxNId
private

Definition at line 3509 of file network.h.

TInt TUndirNet::NEdges
private

Definition at line 3509 of file network.h.

THash<TInt, TNode> TUndirNet::NodeH
private

Definition at line 3510 of file network.h.

TAttrPair TUndirNet::SAttrE
private

Definition at line 3513 of file network.h.

TAttr TUndirNet::SAttrN
private

Definition at line 3512 of file network.h.


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