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

Undirected network. More...

#include <network.h>

Classes

class  TEdgeI
 Edge iterator. Only forward iteration (operator++) is supported. More...
 
class  TNode
 
class  TNodeI
 Node iterator. Only forward iteration (operator++) is supported. More...
 

Public Types

typedef 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 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 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 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 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
 

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

Member Typedef Documentation

Definition at line 2751 of file network.h.

Definition at line 2750 of file network.h.

Constructor & Destructor Documentation

TUndirNet::TUndirNet ( )
inline

Definition at line 2863 of file network.h.

2863 : CRef(), MxNId(0), NEdges(0), NodeH(), SAttrN(), SAttrE() { }
THash< TInt, TNode > NodeH
Definition: network.h:2854
TInt MxNId
Definition: network.h:2853
TAttrPair SAttrE
Definition: network.h:2857
TAttr SAttrN
Definition: network.h:2856
TCRef CRef
Definition: network.h:2852
TInt NEdges
Definition: network.h:2853
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 2865 of file network.h.

2865 : 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:2986
TInt MxNId
Definition: network.h:2853
TAttrPair SAttrE
Definition: network.h:2857
TAttr SAttrN
Definition: network.h:2856
TInt NEdges
Definition: network.h:2853
TUndirNet::TUndirNet ( const TUndirNet Graph)
inline

Definition at line 2866 of file network.h.

2866  : MxNId(Graph.MxNId), NEdges(Graph.NEdges), NodeH(Graph.NodeH),
2867  SAttrN(), SAttrE() { }
THash< TInt, TNode > NodeH
Definition: network.h:2854
TInt MxNId
Definition: network.h:2853
TAttrPair SAttrE
Definition: network.h:2857
TAttr SAttrN
Definition: network.h:2856
TInt NEdges
Definition: network.h:2853
TUndirNet::TUndirNet ( TSIn SIn)
inline

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

Definition at line 2869 of file network.h.

2869 : MxNId(SIn), NEdges(SIn), NodeH(SIn), SAttrN(SIn), SAttrE(SIn) { }
THash< TInt, TNode > NodeH
Definition: network.h:2854
TInt MxNId
Definition: network.h:2853
TAttrPair SAttrE
Definition: network.h:2857
TAttr SAttrN
Definition: network.h:2856
TInt NEdges
Definition: network.h:2853

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 1742 of file network.cpp.

1742  {
1743  IAssertR(IsNode(SrcNId) && IsNode(DstNId), TStr::Fmt("%d or %d not a node.", SrcNId, DstNId).CStr());
1744  if (IsEdge(SrcNId, DstNId)) { return -2; } // edge already exists
1745  GetNode(SrcNId).NIdV.AddSorted(DstNId);
1746  if (SrcNId!=DstNId) { // not a self edge
1747  GetNode(DstNId).NIdV.AddSorted(SrcNId); }
1748  NEdges++;
1749  return -1; // edge id
1750 }
#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:1063
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:1768
bool IsNode(const int &NId) const
Tests whether ID NId is a node.
Definition: network.h:2932
TNode & GetNode(const int &NId)
Definition: network.h:2859
static TStr Fmt(const char *FmtStr,...)
Definition: dt.cpp:1599
TInt NEdges
Definition: network.h:2853
int TUndirNet::AddEdge ( const TEdgeI EdgeI)
inline

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

Definition at line 2953 of file network.h.

2953 { 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:1742
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 1664 of file network.cpp.

1664  {
1665  if (NId == -1) {
1666  NId = MxNId; MxNId++;
1667  } else {
1668  IAssertR(!IsNode(NId), TStr::Fmt("NodeId %d already exists", NId));
1669  MxNId = TMath::Mx(NId+1, MxNId());
1670  }
1671  NodeH.AddDat(NId, TNode(NId));
1672  return NId;
1673 }
#define IAssertR(Cond, Reason)
Definition: bd.h:265
THash< TInt, TNode > NodeH
Definition: network.h:2854
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:2932
TInt MxNId
Definition: network.h:2853
static TStr Fmt(const char *FmtStr,...)
Definition: dt.cpp:1599
TDat & AddDat(const TKey &Key)
Definition: hash.h:196
int TUndirNet::AddNode ( const TNodeI NodeI)
inline

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

Definition at line 2902 of file network.h.

2902 { return AddNode(NodeI.GetId()); }
int AddNode(int NId=-1)
Adds a node of ID NId to the network.
Definition: network.cpp:1664
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 1676 of file network.cpp.

1676  {
1677  int NewNId;
1678  if (NId == -1) {
1679  NewNId = MxNId; MxNId++;
1680  } else {
1681  IAssertR(! IsNode(NId), TStr::Fmt("NodeId %d already exists", NId));
1682  NewNId = NId;
1683  MxNId = TMath::Mx(NewNId+1, MxNId());
1684  }
1685  TNode& Node = NodeH.AddDat(NewNId);
1686  Node.Id = NewNId;
1687  Node.NIdV = NbrNIdV;
1688  Node.NIdV.Sort();
1689  NEdges += Node.GetDeg();
1690  for (int i = 0; i < NbrNIdV.Len(); i++) {
1691  GetNode(NbrNIdV[i]).NIdV.AddSorted(NewNId);
1692  }
1693  return NewNId;
1694 }
#define IAssertR(Cond, Reason)
Definition: bd.h:265
THash< TInt, TNode > NodeH
Definition: network.h:2854
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:547
TSizeTy AddSorted(const TVal &Val, const bool &Asc=true, const TSizeTy &_MxVals=-1)
Adds element Val to a sorted vector.
Definition: ds.h:1063
void Sort(const bool &Asc=true)
Sorts the elements of the vector.
Definition: ds.h:1254
bool IsNode(const int &NId) const
Tests whether ID NId is a node.
Definition: network.h:2932
TNode & GetNode(const int &NId)
Definition: network.h:2859
TInt MxNId
Definition: network.h:2853
static TStr Fmt(const char *FmtStr,...)
Definition: dt.cpp:1599
TInt NEdges
Definition: network.h:2853
TDat & AddDat(const TKey &Key)
Definition: hash.h:196
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 1697 of file network.cpp.

1697  {
1698  int NewNId;
1699  if (NId == -1) {
1700  NewNId = MxNId; MxNId++;
1701  } else {
1702  IAssertR(!IsNode(NId), TStr::Fmt("NodeId %d already exists", NId));
1703  NewNId = NId;
1704  MxNId = TMath::Mx(NewNId+1, MxNId());
1705  }
1706  TNode& Node = NodeH.AddDat(NewNId);
1707  Node.Id = NewNId;
1708  Node.NIdV.GenExt(Pool.GetValVPt(NIdVId), Pool.GetVLen(NIdVId));
1709  Node.NIdV.Sort();
1710  NEdges += Node.GetDeg();
1711  return NewNId;
1712 }
#define IAssertR(Cond, Reason)
Definition: bd.h:265
THash< TInt, TNode > NodeH
Definition: network.h:2854
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:1665
bool IsNode(const int &NId) const
Tests whether ID NId is a node.
Definition: network.h:2932
int GetVLen(const int &VId) const
Returns the number of elements in the vector with id VId.
Definition: ds.h:1663
TInt MxNId
Definition: network.h:2853
static TStr Fmt(const char *FmtStr,...)
Definition: dt.cpp:1599
TInt NEdges
Definition: network.h:2853
TDat & AddDat(const TKey &Key)
Definition: hash.h:196
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 1995 of file network.cpp.

1995  {
1996  if (!IsEdge(SrcNId, DstNId)) {
1997  return -1;
1998  }
1999  TIntPr EId = OrderEdgeNodes(SrcNId, DstNId);
2000  return SAttrE.AddSAttrDat(EId, AttrName, Val);
2001 }
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:1768
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:2857
TIntPr OrderEdgeNodes(const int &SrcNId, const int &DstNId) const
Definition: network.cpp:1988
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 2003 of file network.cpp.

2003  {
2004  if (!IsEdge(SrcNId, DstNId)) {
2005  return -1;
2006  }
2007  TIntPr EId = OrderEdgeNodes(SrcNId, DstNId);
2008  return SAttrE.AddSAttrDat(EId, AttrId, Val);
2009 }
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:1768
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:2857
TIntPr OrderEdgeNodes(const int &SrcNId, const int &DstNId) const
Definition: network.cpp:1988
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 3136 of file network.h.

3136  {
3137  return AddSAttrDatE(EdgeI.GetSrcNId(), EdgeI.GetDstNId(), AttrName, Val);
3138  }
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:1995
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 3140 of file network.h.

3140  {
3141  return AddSAttrDatE(EdgeI.GetSrcNId(), EdgeI.GetDstNId(), AttrId, Val);
3142  }
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:1995
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 2011 of file network.cpp.

2011  {
2012  if (!IsEdge(SrcNId, DstNId)) {
2013  return -1;
2014  }
2015  TIntPr EId = OrderEdgeNodes(SrcNId, DstNId);
2016  return SAttrE.AddSAttrDat(EId, AttrName, Val);
2017 }
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:1768
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:2857
TIntPr OrderEdgeNodes(const int &SrcNId, const int &DstNId) const
Definition: network.cpp:1988
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 2019 of file network.cpp.

2019  {
2020  if (!IsEdge(SrcNId, DstNId)) {
2021  return -1;
2022  }
2023  TIntPr EId = OrderEdgeNodes(SrcNId, DstNId);
2024  return SAttrE.AddSAttrDat(EId, AttrId, Val);
2025 }
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:1768
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:2857
TIntPr OrderEdgeNodes(const int &SrcNId, const int &DstNId) const
Definition: network.cpp:1988
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 3150 of file network.h.

3150  {
3151  return AddSAttrDatE(EdgeI.GetSrcNId(), EdgeI.GetDstNId(), AttrName, Val);
3152  }
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:1995
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 3154 of file network.h.

3154  {
3155  return AddSAttrDatE(EdgeI.GetSrcNId(), EdgeI.GetDstNId(), AttrId, Val);
3156  }
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:1995
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 2027 of file network.cpp.

2027  {
2028  if (!IsEdge(SrcNId, DstNId)) {
2029  return -1;
2030  }
2031  TIntPr EId = OrderEdgeNodes(SrcNId, DstNId);
2032  return SAttrE.AddSAttrDat(EId, AttrName, Val);
2033 }
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:1768
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:2857
TIntPr OrderEdgeNodes(const int &SrcNId, const int &DstNId) const
Definition: network.cpp:1988
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 2035 of file network.cpp.

2035  {
2036  if (!IsEdge(SrcNId, DstNId)) {
2037  return -1;
2038  }
2039  TIntPr EId = OrderEdgeNodes(SrcNId, DstNId);
2040  return SAttrE.AddSAttrDat(EId, AttrId, Val);
2041 }
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:1768
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:2857
TIntPr OrderEdgeNodes(const int &SrcNId, const int &DstNId) const
Definition: network.cpp:1988
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 3164 of file network.h.

3164  {
3165  return AddSAttrDatE(EdgeI.GetSrcNId(), EdgeI.GetDstNId(), AttrName, Val);
3166  }
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:1995
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 3168 of file network.h.

3168  {
3169  return AddSAttrDatE(EdgeI.GetSrcNId(), EdgeI.GetDstNId(), AttrId, Val);
3170  }
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:1995
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 1862 of file network.cpp.

1862  {
1863  if (!IsNode(NId)) {
1864  return -1;
1865  }
1866  return SAttrN.AddSAttrDat(NId, AttrName, Val);
1867 }
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:2932
TAttr SAttrN
Definition: network.h:2856
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 1869 of file network.cpp.

1869  {
1870  if (!IsNode(NId)) {
1871  return -1;
1872  }
1873  return SAttrN.AddSAttrDat(NId, AttrId, Val);
1874 }
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:2932
TAttr SAttrN
Definition: network.h:2856
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 3018 of file network.h.

3018  {
3019  return AddSAttrDatN(NodeI.GetId(), AttrName, Val);
3020  }
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:1862
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 3022 of file network.h.

3022  {
3023  return AddSAttrDatN(NodeI.GetId(), AttrId, Val);
3024  }
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:1862
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 1876 of file network.cpp.

1876  {
1877  if (!IsNode(NId)) {
1878  return -1;
1879  }
1880  return SAttrN.AddSAttrDat(NId, AttrName, Val);
1881 }
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:2932
TAttr SAttrN
Definition: network.h:2856
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 1883 of file network.cpp.

1883  {
1884  if (!IsNode(NId)) {
1885  return -1;
1886  }
1887  return SAttrN.AddSAttrDat(NId, AttrId, Val);
1888 }
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:2932
TAttr SAttrN
Definition: network.h:2856
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 3032 of file network.h.

3032  {
3033  return AddSAttrDatN(NodeI.GetId(), AttrName, Val);
3034  }
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:1862
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 3036 of file network.h.

3036  {
3037  return AddSAttrDatN(NodeI.GetId(), AttrId, Val);
3038  }
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:1862
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 1890 of file network.cpp.

1890  {
1891  if (!IsNode(NId)) {
1892  return -1;
1893  }
1894  return SAttrN.AddSAttrDat(NId, AttrName, Val);
1895 }
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:2932
TAttr SAttrN
Definition: network.h:2856
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 1897 of file network.cpp.

1897  {
1898  if (!IsNode(NId)) {
1899  return -1;
1900  }
1901  return SAttrN.AddSAttrDat(NId, AttrId, Val);
1902 }
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:2932
TAttr SAttrN
Definition: network.h:2856
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 3046 of file network.h.

3046  {
3047  return AddSAttrDatN(NodeI.GetId(), AttrName, Val);
3048  }
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:1862
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 3050 of file network.h.

3050  {
3051  return AddSAttrDatN(NodeI.GetId(), AttrId, Val);
3052  }
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:1862
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 2124 of file network.cpp.

2124  {
2125  return SAttrE.AddSAttr(Name, AttrType, AttrId);
2126 }
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:2857
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 1976 of file network.cpp.

1976  {
1977  return SAttrN.AddSAttr(Name, AttrType, AttrId);
1978 }
TAttr SAttrN
Definition: network.h:2856
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 2963 of file network.h.

2963 { 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:2934
TNodeI EndNI() const
Returns an iterator referring to the past-the-end node in the network.
Definition: network.h:2936
int GetNodes() const
Returns the number of nodes in the network.
Definition: network.h:2894
TNodeI TUndirNet::BegNI ( ) const
inline

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

Definition at line 2934 of file network.h.

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

Deletes all nodes and edges from the network.

Definition at line 2984 of file network.h.

2984 { MxNId=0; NEdges=0; NodeH.Clr(); SAttrN.Clr(); SAttrE.Clr(); }
THash< TInt, TNode > NodeH
Definition: network.h:2854
TInt MxNId
Definition: network.h:2853
void Clr()
Clears the contents of the attribute map.
Definition: attr.h:114
TAttrPair SAttrE
Definition: network.h:2857
TAttr SAttrN
Definition: network.h:2856
void Clr(const bool &DoDel=true, const int &NoDelLim=-1, const bool &ResetDat=true)
Definition: hash.h:319
TInt NEdges
Definition: network.h:2853
void Clr()
Clears the contents of the attribute map.
Definition: attr.h:29
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 1792 of file network.cpp.

1792  {
1793  for (int n = NodeH.FFirstKeyId(); NodeH.FNextKeyId(n); ) {
1794  NodeH[n].NIdV.Pack();
1795  }
1796  if (! OnlyNodeLinks && ! NodeH.IsKeyIdEqKeyN()) {
1797  NodeH.Defrag();
1798  }
1799 }
bool IsKeyIdEqKeyN() const
Definition: hash.h:191
THash< TInt, TNode > NodeH
Definition: network.h:2854
void Defrag()
Definition: hash.h:513
bool FNextKeyId(int &KeyId) const
Definition: hash.h:436
int FFirstKeyId() const
Definition: hash.h:236
void Pack()
Definition: hash.h:247
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 1753 of file network.cpp.

1753  {
1754  IAssertR(IsNode(SrcNId) && IsNode(DstNId), TStr::Fmt("%d or %d not a node.", SrcNId, DstNId).CStr());
1755  { TNode& N = GetNode(SrcNId);
1756  const int n = N.NIdV.SearchBin(DstNId);
1757  TIntPr Id(SrcNId, DstNId);
1758  SAttrE.DelSAttrId(Id);
1759  if (n!= -1) { N.NIdV.Del(n); NEdges--; } }
1760  if (SrcNId != DstNId) { // not a self edge
1761  TNode& N = GetNode(DstNId);
1762  const int n = N.NIdV.SearchBin(SrcNId);
1763  if (n!= -1) { N.NIdV.Del(n); }
1764  }
1765 }
#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:2932
TNode & GetNode(const int &NId)
Definition: network.h:2859
Definition: ds.h:32
TAttrPair SAttrE
Definition: network.h:2857
static TStr Fmt(const char *FmtStr,...)
Definition: dt.cpp:1599
TInt NEdges
Definition: network.h:2853
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 1715 of file network.cpp.

1715  {
1716  { AssertR(IsNode(NId), TStr::Fmt("NodeId %d does not exist", NId));
1717  TInt Id(NId);
1718  SAttrN.DelSAttrId(Id);
1719  TNode& Node = GetNode(NId);
1720  NEdges -= Node.GetDeg();
1721  for (int e = 0; e < Node.GetDeg(); e++) {
1722  const int nbr = Node.GetNbrNId(e);
1723  if (nbr == NId) { continue; }
1724  TNode& N = GetNode(nbr);
1725  const int n = N.NIdV.SearchBin(NId);
1726  IAssert(n != -1); // if NId points to N, then N also should point back
1727  if (n!= -1) { N.NIdV.Del(n); }
1728  } }
1729  NodeH.DelKey(NId);
1730 }
#define IAssert(Cond)
Definition: bd.h:262
THash< TInt, TNode > NodeH
Definition: network.h:2854
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:362
bool IsNode(const int &NId) const
Tests whether ID NId is a node.
Definition: network.h:2932
TNode & GetNode(const int &NId)
Definition: network.h:2859
Definition: dt.h:1044
static TStr Fmt(const char *FmtStr,...)
Definition: dt.cpp:1599
TAttr SAttrN
Definition: network.h:2856
#define AssertR(Cond, Reason)
Definition: bd.h:258
TInt NEdges
Definition: network.h:2853
void TUndirNet::DelNode ( const TNode NodeI)
inline

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

Definition at line 2930 of file network.h.

2930 { DelNode(NodeI.GetId()); }
void DelNode(const int &NId)
Deletes node of ID NId from the network.
Definition: network.cpp:1715
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 2091 of file network.cpp.

2091  {
2092  if (!IsEdge(SrcNId, DstNId)) {
2093  return -1;
2094  }
2095  TIntPr EId = OrderEdgeNodes(SrcNId, DstNId);
2096  return SAttrE.DelSAttrDat(EId, AttrName);
2097 }
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:1768
Definition: ds.h:32
TAttrPair SAttrE
Definition: network.h:2857
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:1988
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 2099 of file network.cpp.

2099  {
2100  if (!IsEdge(SrcNId, DstNId)) {
2101  return -1;
2102  }
2103  TIntPr EId = OrderEdgeNodes(SrcNId, DstNId);
2104  return SAttrE.DelSAttrDat(EId, AttrId);
2105 }
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:1768
Definition: ds.h:32
TAttrPair SAttrE
Definition: network.h:2857
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:1988
int TUndirNet::DelSAttrDatE ( const TEdgeI EdgeI,
const TStr AttrName 
)
inline

Deletes sparse attribute with name AttrName from EdgeI.

Definition at line 3220 of file network.h.

3220  {
3221  return DelSAttrDatE(EdgeI.GetSrcNId(), EdgeI.GetDstNId(), AttrName);
3222  }
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:2091
int TUndirNet::DelSAttrDatE ( const TEdgeI EdgeI,
const TInt AttrId 
)
inline

Deletes sparse attribute with id AttrId from EdgeI.

Definition at line 3224 of file network.h.

3224  {
3225  return DelSAttrDatE(EdgeI.GetSrcNId(), EdgeI.GetDstNId(), AttrId);
3226  }
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:2091
int TUndirNet::DelSAttrDatN ( const TInt NId,
const TStr AttrName 
)

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

Definition at line 1946 of file network.cpp.

1946  {
1947  if (!IsNode(NId)) {
1948  return -1;
1949  }
1950  return SAttrN.DelSAttrDat(NId, AttrName);
1951 }
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:2932
TAttr SAttrN
Definition: network.h:2856
int TUndirNet::DelSAttrDatN ( const TInt NId,
const TInt AttrId 
)

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

Definition at line 1953 of file network.cpp.

1953  {
1954  if (!IsNode(NId)) {
1955  return -1;
1956  }
1957  return SAttrN.DelSAttrDat(NId, AttrId);
1958 }
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:2932
TAttr SAttrN
Definition: network.h:2856
int TUndirNet::DelSAttrDatN ( const TNodeI NodeI,
const TStr AttrName 
)
inline

Deletes sparse attribute with name AttrName from NodeI.

Definition at line 3102 of file network.h.

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

Deletes sparse attribute with id AttrId from NodeI.

Definition at line 3106 of file network.h.

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

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

Definition at line 1839 of file network.cpp.

1839  {
1840  const int NodePlaces = (int) ceil(log10((double) GetNodes()));
1841  fprintf(OutF, "-------------------------------------------------\nUndirected Node Graph: nodes: %d, edges: %d\n", GetNodes(), GetEdges());
1842  for (int N = NodeH.FFirstKeyId(); NodeH.FNextKeyId(N); ) {
1843  const TNode& Node = NodeH[N];
1844  fprintf(OutF, " %*d [%d] ", NodePlaces, Node.GetId(), Node.GetDeg());
1845  for (int edge = 0; edge < Node.GetDeg(); edge++) {
1846  fprintf(OutF, " %*d", NodePlaces, Node.GetNbrNId(edge)); }
1847  fprintf(OutF, "\n");
1848  }
1849  fprintf(OutF, "\n");
1850 }
THash< TInt, TNode > NodeH
Definition: network.h:2854
bool FNextKeyId(int &KeyId) const
Definition: hash.h:436
int FFirstKeyId() const
Definition: hash.h:236
int GetNodes() const
Returns the number of nodes in the network.
Definition: network.h:2894
int GetEdges() const
Returns the number of edges in the network.
Definition: network.cpp:1732
bool TUndirNet::Empty ( ) const
inline

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

Definition at line 2982 of file network.h.

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

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

Definition at line 2965 of file network.h.

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

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

Definition at line 2936 of file network.h.

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

Returns the number of edges in the network.

Definition at line 1732 of file network.cpp.

1732  {
1733  //int Edges = 0;
1734  //for (int N=NodeH.FFirstKeyId(); NodeH.FNextKeyId(N); ) {
1735  // Edges += NodeH[N].GetDeg();
1736  //}
1737  //return Edges/2;
1738  return NEdges;
1739 }
TInt NEdges
Definition: network.h:2853
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 1774 of file network.cpp.

1774  {
1775  const int MnNId = TMath::Mn(SrcNId, DstNId);
1776  const int MxNId = TMath::Mx(SrcNId, DstNId);
1777  const TNodeI SrcNI = GetNI(MnNId);
1778  const int NodeN = SrcNI.NodeHI.GetDat().NIdV.SearchBin(MxNId);
1779  IAssert(NodeN != -1);
1780  return TEdgeI(SrcNI, EndNI(), NodeN);
1781 }
#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:2853
TNodeI EndNI() const
Returns an iterator referring to the past-the-end node in the network.
Definition: network.h:2936
TNodeI GetNI(const int &NId) const
Returns an iterator referring to the node of ID NId in the network.
Definition: network.h:2938
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 2116 of file network.cpp.

2116  {
2117  return SAttrE.GetIdVSAttr(AttrName, IdV);
2118 }
int GetIdVSAttr(const TInt &AttrId, const TAttrType Type, TIntPrV &IdV) const
Definition: attr.cpp:411
TAttrPair SAttrE
Definition: network.h:2857
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 2120 of file network.cpp.

2120  {
2121  return SAttrE.GetIdVSAttr(AttrId, IdV);
2122 }
int GetIdVSAttr(const TInt &AttrId, const TAttrType Type, TIntPrV &IdV) const
Definition: attr.cpp:411
TAttrPair SAttrE
Definition: network.h:2857
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 1968 of file network.cpp.

1968  {
1969  return SAttrN.GetIdVSAttr(AttrName, IdV);
1970 }
int GetIdVSAttr(const TInt &AttrId, const TAttrType Type, TIntV &IdV) const
Definition: attr.cpp:167
TAttr SAttrN
Definition: network.h:2856
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 1972 of file network.cpp.

1972  {
1973  return SAttrN.GetIdVSAttr(AttrId, IdV);
1974 }
int GetIdVSAttr(const TInt &AttrId, const TAttrType Type, TIntV &IdV) const
Definition: attr.cpp:167
TAttr SAttrN
Definition: network.h:2856
int TUndirNet::GetMxNId ( ) const
inline

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

Definition at line 2940 of file network.h.

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

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

Definition at line 2938 of file network.h.

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

Gets a vector IDs of all nodes in the network.

Definition at line 1785 of file network.cpp.

1785  {
1786  NIdV.Gen(GetNodes(), 0);
1787  for (int N=NodeH.FFirstKeyId(); NodeH.FNextKeyId(N); ) {
1788  NIdV.Add(NodeH.GetKey(N)); }
1789 }
THash< TInt, TNode > NodeH
Definition: network.h:2854
bool FNextKeyId(int &KeyId) const
Definition: hash.h:436
int FFirstKeyId() const
Definition: hash.h:236
int GetNodes() const
Returns the number of nodes in the network.
Definition: network.h:2894
void Gen(const TSizeTy &_Vals)
Constructs a vector (an array) of _Vals elements.
Definition: ds.h:495
TSizeTy Add()
Adds a new element at the end of the vector, after its current last element.
Definition: ds.h:574
const TKey & GetKey(const int &KeyId) const
Definition: hash.h:210
TNode& TUndirNet::GetNode ( const int &  NId)
inlineprivate

Definition at line 2859 of file network.h.

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

Definition at line 2860 of file network.h.

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

Returns the number of nodes in the network.

Definition at line 2894 of file network.h.

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

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

Definition at line 2977 of file network.h.

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

Returns an ID of a random node in the network.

Definition at line 2975 of file network.h.

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

2043  {
2044  if (!IsEdge(SrcNId, DstNId)) {
2045  return -1;
2046  }
2047  TIntPr EId = OrderEdgeNodes(SrcNId, DstNId);
2048  return SAttrE.GetSAttrDat(EId, AttrName, Val);
2049 }
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:1768
Definition: ds.h:32
TAttrPair SAttrE
Definition: network.h:2857
TIntPr OrderEdgeNodes(const int &SrcNId, const int &DstNId) const
Definition: network.cpp:1988
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 2051 of file network.cpp.

2051  {
2052  if (!IsEdge(SrcNId, DstNId)) {
2053  return -1;
2054  }
2055  TIntPr EId = OrderEdgeNodes(SrcNId, DstNId);
2056  return SAttrE.GetSAttrDat(EId, AttrId, Val);
2057 }
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:1768
Definition: ds.h:32
TAttrPair SAttrE
Definition: network.h:2857
TIntPr OrderEdgeNodes(const int &SrcNId, const int &DstNId) const
Definition: network.cpp:1988
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 3178 of file network.h.

3178  {
3179  return GetSAttrDatE(EdgeI.GetSrcNId(), EdgeI.GetDstNId(), AttrName, ValX);
3180  }
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:2043
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 3182 of file network.h.

3182  {
3183  return GetSAttrDatE(EdgeI.GetSrcNId(), EdgeI.GetDstNId(), AttrId, ValX);
3184  }
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:2043
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 2059 of file network.cpp.

2059  {
2060  if (!IsEdge(SrcNId, DstNId)) {
2061  return -1;
2062  }
2063  TIntPr EId = OrderEdgeNodes(SrcNId, DstNId);
2064  return SAttrE.GetSAttrDat(EId, AttrName, Val);
2065 }
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:1768
Definition: ds.h:32
TAttrPair SAttrE
Definition: network.h:2857
TIntPr OrderEdgeNodes(const int &SrcNId, const int &DstNId) const
Definition: network.cpp:1988
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 2067 of file network.cpp.

2067  {
2068  if (!IsEdge(SrcNId, DstNId)) {
2069  return -1;
2070  }
2071  TIntPr EId = OrderEdgeNodes(SrcNId, DstNId);
2072  return SAttrE.GetSAttrDat(EId, AttrId, Val);
2073 }
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:1768
Definition: ds.h:32
TAttrPair SAttrE
Definition: network.h:2857
TIntPr OrderEdgeNodes(const int &SrcNId, const int &DstNId) const
Definition: network.cpp:1988
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 3192 of file network.h.

3192  {
3193  return GetSAttrDatE(EdgeI.GetSrcNId(), EdgeI.GetDstNId(), AttrName, ValX);
3194  }
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:2043
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 3196 of file network.h.

3196  {
3197  return GetSAttrDatE(EdgeI.GetSrcNId(), EdgeI.GetDstNId(), AttrId, ValX);
3198  }
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:2043
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 2075 of file network.cpp.

2075  {
2076  if (!IsEdge(SrcNId, DstNId)) {
2077  return -1;
2078  }
2079  TIntPr EId = OrderEdgeNodes(SrcNId, DstNId);
2080  return SAttrE.GetSAttrDat(EId, AttrName, Val);
2081 }
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:1768
Definition: ds.h:32
TAttrPair SAttrE
Definition: network.h:2857
TIntPr OrderEdgeNodes(const int &SrcNId, const int &DstNId) const
Definition: network.cpp:1988
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 2083 of file network.cpp.

2083  {
2084  if (!IsEdge(SrcNId, DstNId)) {
2085  return -1;
2086  }
2087  TIntPr EId = OrderEdgeNodes(SrcNId, DstNId);
2088  return SAttrE.GetSAttrDat(EId, AttrId, Val);
2089 }
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:1768
Definition: ds.h:32
TAttrPair SAttrE
Definition: network.h:2857
TIntPr OrderEdgeNodes(const int &SrcNId, const int &DstNId) const
Definition: network.cpp:1988
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 3206 of file network.h.

3206  {
3207  return GetSAttrDatE(EdgeI.GetSrcNId(), EdgeI.GetDstNId(), AttrName, ValX);
3208  }
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:2043
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 3210 of file network.h.

3210  {
3211  return GetSAttrDatE(EdgeI.GetSrcNId(), EdgeI.GetDstNId(), AttrId, ValX);
3212  }
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:2043
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 1904 of file network.cpp.

1904  {
1905  if (!IsNode(NId)) {
1906  return -1;
1907  }
1908  return SAttrN.GetSAttrDat(NId, AttrName, Val);
1909 }
bool IsNode(const int &NId) const
Tests whether ID NId is a node.
Definition: network.h:2932
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:2856
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 1911 of file network.cpp.

1911  {
1912  if (!IsNode(NId)) {
1913  return -1;
1914  }
1915  return SAttrN.GetSAttrDat(NId, AttrId, Val);
1916 }
bool IsNode(const int &NId) const
Tests whether ID NId is a node.
Definition: network.h:2932
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:2856
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 3060 of file network.h.

3060  {
3061  return GetSAttrDatN(NodeI.GetId(), AttrName, ValX);
3062  }
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:1904
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 3064 of file network.h.

3064  {
3065  return GetSAttrDatN(NodeI.GetId(), AttrId, ValX);
3066  }
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:1904
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 1918 of file network.cpp.

1918  {
1919  if (!IsNode(NId)) {
1920  return -1;
1921  }
1922  return SAttrN.GetSAttrDat(NId, AttrName, Val);
1923 }
bool IsNode(const int &NId) const
Tests whether ID NId is a node.
Definition: network.h:2932
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:2856
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 1925 of file network.cpp.

1925  {
1926  if (!IsNode(NId)) {
1927  return -1;
1928  }
1929  return SAttrN.GetSAttrDat(NId, AttrId, Val);
1930 }
bool IsNode(const int &NId) const
Tests whether ID NId is a node.
Definition: network.h:2932
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:2856
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 3074 of file network.h.

3074  {
3075  return GetSAttrDatN(NodeI.GetId(), AttrName, ValX);
3076  }
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:1904
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 3078 of file network.h.

3078  {
3079  return GetSAttrDatN(NodeI.GetId(), AttrId, ValX);
3080  }
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:1904
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 1932 of file network.cpp.

1932  {
1933  if (!IsNode(NId)) {
1934  return -1;
1935  }
1936  return SAttrN.GetSAttrDat(NId, AttrName, Val);
1937 }
bool IsNode(const int &NId) const
Tests whether ID NId is a node.
Definition: network.h:2932
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:2856
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 1939 of file network.cpp.

1939  {
1940  if (!IsNode(NId)) {
1941  return -1;
1942  }
1943  return SAttrN.GetSAttrDat(NId, AttrId, Val);
1944 }
bool IsNode(const int &NId) const
Tests whether ID NId is a node.
Definition: network.h:2932
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:2856
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 3088 of file network.h.

3088  {
3089  return GetSAttrDatN(NodeI.GetId(), AttrName, ValX);
3090  }
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:1904
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 3092 of file network.h.

3092  {
3093  return GetSAttrDatN(NodeI.GetId(), AttrId, ValX);
3094  }
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:1904
int TUndirNet::GetSAttrIdE ( const TStr Name,
TInt AttrIdX,
TAttrType AttrTypeX 
) const

Gets id and type for attribute with name Name.

Definition at line 2128 of file network.cpp.

2128  {
2129  return SAttrE.GetSAttrId(Name, AttrId, AttrType);
2130 }
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:2857
int TUndirNet::GetSAttrIdN ( const TStr Name,
TInt AttrIdX,
TAttrType AttrTypeX 
) const

Gets id and type for attribute with name Name.

Definition at line 1980 of file network.cpp.

1980  {
1981  return SAttrN.GetSAttrId(Name, AttrId, AttrType);
1982 }
TAttr SAttrN
Definition: network.h:2856
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 2132 of file network.cpp.

2132  {
2133  return SAttrE.GetSAttrName(AttrId, Name, AttrType);
2134 }
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:2857
int TUndirNet::GetSAttrNameN ( const TInt AttrId,
TStr NameX,
TAttrType AttrTypeX 
) const

Gets name and type for attribute with id AttrId.

Definition at line 1984 of file network.cpp.

1984  {
1985  return SAttrN.GetSAttrName(AttrId, Name, AttrType);
1986 }
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:2856
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 2107 of file network.cpp.

2107  {
2108  if (!IsEdge(SrcNId, DstNId)) {
2109  return -1;
2110  }
2111  TIntPr EId = OrderEdgeNodes(SrcNId, DstNId);
2112  SAttrE.GetSAttrV(EId, AttrType, AttrV);
2113  return 0;
2114 }
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:1768
Definition: ds.h:32
TAttrPair SAttrE
Definition: network.h:2857
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:1988
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 3230 of file network.h.

3230  {
3231  return GetSAttrVE(EdgeI.GetSrcNId(), EdgeI.GetDstNId(), AttrType, AttrV);
3232  }
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:2107
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 1960 of file network.cpp.

1960  {
1961  if (!IsNode(NId)) {
1962  return -1;
1963  }
1964  SAttrN.GetSAttrV(NId, AttrType, AttrV);
1965  return 0;
1966 }
bool IsNode(const int &NId) const
Tests whether ID NId is a node.
Definition: network.h:2932
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:2856
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 3113 of file network.h.

3113  {
3114  return GetSAttrVN(NodeI.GetId(), AttrType, AttrV);
3115  }
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:1960
PUndirNet TUndirNet::GetSmallGraph ( )
static

Returns a small network on 5 nodes and 5 edges.

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

Definition at line 1853 of file network.cpp.

1853  {
1854  PUndirNet Graph = TUndirNet::New();
1855  for (int i = 0; i < 5; i++) { Graph->AddNode(i); }
1856  Graph->AddEdge(0,1); Graph->AddEdge(0,2);
1857  Graph->AddEdge(0,3); Graph->AddEdge(0,4);
1858  Graph->AddEdge(1,2);
1859  return Graph;
1860 }
static PUndirNet New()
Static constructor that returns a pointer to the network. Call: PUndirNet Graph = TUndirNet::New()...
Definition: network.h:2876
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 1659 of file network.cpp.

1659  {
1660  return HasGraphFlag(TUndirNet::TNet, Flag);
1661 }
#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:2748
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 1768 of file network.cpp.

1768  {
1769  if (! IsNode(SrcNId) || ! IsNode(DstNId)) return false;
1770  return GetNode(SrcNId).IsNbrNId(DstNId);
1771 }
bool IsNode(const int &NId) const
Tests whether ID NId is a node.
Definition: network.h:2932
TNode & GetNode(const int &NId)
Definition: network.h:2859
bool IsNbrNId(const int &NId) const
Definition: network.h:2770
bool TUndirNet::IsNode ( const int &  NId) const
inline

Tests whether ID NId is a node.

Definition at line 2932 of file network.h.

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

1802  {
1803  bool RetVal = true;
1804  for (int N = NodeH.FFirstKeyId(); NodeH.FNextKeyId(N); ) {
1805  const TNode& Node = NodeH[N];
1806  if (! Node.NIdV.IsSorted()) {
1807  const TStr Msg = TStr::Fmt("Neighbor list of node %d is not sorted.", Node.GetId());
1808  if (ThrowExcept) { EAssertR(false, Msg); } else { ErrNotify(Msg.CStr()); }
1809  RetVal=false;
1810  }
1811  int prevNId = -1;
1812  for (int e = 0; e < Node.GetDeg(); e++) {
1813  if (! IsNode(Node.GetNbrNId(e))) {
1814  const TStr Msg = TStr::Fmt("Edge %d --> %d: node %d does not exist.",
1815  Node.GetId(), Node.GetNbrNId(e), Node.GetNbrNId(e));
1816  if (ThrowExcept) { EAssertR(false, Msg); } else { ErrNotify(Msg.CStr()); }
1817  RetVal=false;
1818  }
1819  if (e > 0 && prevNId == Node.GetNbrNId(e)) {
1820  const TStr Msg = TStr::Fmt("Node %d has duplicate edge %d --> %d.",
1821  Node.GetId(), Node.GetId(), Node.GetNbrNId(e));
1822  if (ThrowExcept) { EAssertR(false, Msg); } else { ErrNotify(Msg.CStr()); }
1823  RetVal=false;
1824  }
1825  prevNId = Node.GetNbrNId(e);
1826  }
1827  }
1828  int EdgeCnt = 0;
1829  for (TEdgeI EI = BegEI(); EI < EndEI(); EI++) { EdgeCnt++; }
1830  if (EdgeCnt != GetEdges()) {
1831  const TStr Msg = TStr::Fmt("Number of edges counter is corrupted: GetEdges():%d, EdgeCount:%d.", GetEdges(), EdgeCnt);
1832  if (ThrowExcept) { EAssertR(false, Msg); } else { ErrNotify(Msg.CStr()); }
1833  RetVal=false;
1834  }
1835  return RetVal;
1836 }
THash< TInt, TNode > NodeH
Definition: network.h:2854
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:2932
bool FNextKeyId(int &KeyId) const
Definition: hash.h:436
int FFirstKeyId() const
Definition: hash.h:236
int GetEdges() const
Returns the number of edges in the network.
Definition: network.cpp:1732
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:2965
char * CStr()
Definition: dt.h:476
TEdgeI BegEI() const
Returns an iterator referring to the first edge in the network.
Definition: network.h:2963
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 2882 of file network.h.

2882 { return PUndirNet(new TUndirNet(SIn)); }
TUndirNet()
Definition: network.h:2863
TPt< TUndirNet > PUndirNet
Pointer to an undirected network (TUndirNet)
Definition: network.h:2723
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 2884 of file network.h.

2884  { PUndirNet Graph = PUndirNet(new TUndirNet());
2885  Graph->MxNId.Load(SIn); Graph->NEdges.Load(SIn); Graph->NodeH.Load(SIn); return Graph;
2886  }
TUndirNet()
Definition: network.h:2863
TPt< TUndirNet > PUndirNet
Pointer to an undirected network (TUndirNet)
Definition: network.h:2723
Definition: bd.h:196
static PUndirNet TUndirNet::New ( )
inlinestatic

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

Definition at line 2876 of file network.h.

2876 { return new TUndirNet(); }
TUndirNet()
Definition: network.h:2863
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 2880 of file network.h.

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

Definition at line 2890 of file network.h.

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

Definition at line 1988 of file network.cpp.

1988  {
1989  if (SrcNId < DstNId) {
1990  return TIntPr(SrcNId, DstNId);
1991  }
1992  return TIntPr(DstNId, SrcNId);
1993 }
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 2986 of file network.h.

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

Reserves memory for node ID NId having Deg edges.

Definition at line 2988 of file network.h.

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

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

Definition at line 2871 of file network.h.

2871  { MxNId.Save(SOut); NEdges.Save(SOut); NodeH.Save(SOut);
2872  SAttrN.Save(SOut); SAttrE.Save(SOut); }
THash< TInt, TNode > NodeH
Definition: network.h:2854
void Save(TSOut &SOut) const
Definition: dt.h:1060
void Save(TSOut &SOut) const
Definition: hash.h:141
void Save(TSOut &SOut) const
Saves the attributes to a (binary) stream SOut.
Definition: attr.h:110
TInt MxNId
Definition: network.h:2853
TAttrPair SAttrE
Definition: network.h:2857
void Save(TSOut &SOut) const
Saves the attributes to a (binary) stream SOut.
Definition: attr.h:25
TAttr SAttrN
Definition: network.h:2856
TInt NEdges
Definition: network.h:2853
void TUndirNet::Save_V1 ( TSOut SOut) const
inline

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

Definition at line 2874 of file network.h.

2874 { MxNId.Save(SOut); NEdges.Save(SOut); NodeH.Save(SOut); }
THash< TInt, TNode > NodeH
Definition: network.h:2854
void Save(TSOut &SOut) const
Definition: dt.h:1060
void Save(TSOut &SOut) const
Definition: hash.h:141
TInt MxNId
Definition: network.h:2853
TInt NEdges
Definition: network.h:2853

Friends And Related Function Documentation

friend class TPt< TUndirNet >
friend

Definition at line 3248 of file network.h.

friend class TUndirNetMtx
friend

Definition at line 3247 of file network.h.

Member Data Documentation

TCRef TUndirNet::CRef
private

Definition at line 2852 of file network.h.

TInt TUndirNet::MxNId
private

Definition at line 2853 of file network.h.

TInt TUndirNet::NEdges
private

Definition at line 2853 of file network.h.

THash<TInt, TNode> TUndirNet::NodeH
private

Definition at line 2854 of file network.h.

TAttrPair TUndirNet::SAttrE
private

Definition at line 2857 of file network.h.

TAttr TUndirNet::SAttrN
private

Definition at line 2856 of file network.h.


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