SNAP Library 2.2, User Reference  2014-03-11 19:15:55
SNAP, a general purpose, high performance system for analysis and manipulation of large networks
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
TBPGraph Class Reference

Bipartite graph. More...

#include <graph.h>

List of all members.

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

enum  TNodeTy { bgsUndef, bgsLeft, bgsRight, bgsBoth }
typedef TBPGraph TNet
typedef TPt< TBPGraphPNet

Public Member Functions

 TBPGraph ()
 TBPGraph (const int &Nodes, const int &Edges)
 Constructor that reserves enough memory for a graph of Nodes (LeftNodes+RightNodes) nodes and Edges edges.
 TBPGraph (const TBPGraph &BPGraph)
 !! Reserve(Nodes, Edges); }
 TBPGraph (TSIn &SIn)
 Constructor for loading the graph from a (binary) stream SIn.
void Save (TSOut &SOut) const
 Saves the graph to a (binary) stream SOut.
bool HasFlag (const TGraphFlag &Flag) const
 Allows for run-time checking the type of the graph (see the TGraphFlag for flags).
TBPGraphoperator= (const TBPGraph &BPGraph)
int GetNodes () const
 Returns the total number of nodes in the graph.
int GetLNodes () const
 Returns the number of nodes on the 'left' side of the biparite graph.
int GetRNodes () const
 Returns the number of nodes on the 'right' side of the biparite graph.
int AddNode (int NId=-1, const bool &LeftNode=true)
 Adds a node of ID NId to the graph.
int AddNode (const TNodeI &NodeI)
 Adds a node of ID NodeI.GetId() to the graph.
void DelNode (const int &NId)
 Deletes node of ID NId from the graph.
void DelNode (const TNode &NodeI)
 Deletes node of ID NodeI.GetId() from the graph.
bool IsNode (const int &NId) const
 Tests whether ID NId is a node.
bool IsLNode (const int &NId) const
 Tests whether ID NId is a 'left' side node.
bool IsRNode (const int &NId) const
 Tests whether ID NId is a 'right' side node.
int GetMxNId () const
 Returns an ID that is larger than any node ID in the graph.
TNodeI BegNI () const
 Returns an iterator referring to the first node in the graph.
TNodeI EndNI () const
 Returns an iterator referring to the past-the-end node in the graph.
TNodeI GetNI (const int &NId) const
 Returns an iterator referring to the node of ID NId in the graph.
TNodeI BegLNI () const
 Returns an iterator referring to the first 'left' node in the graph.
TNodeI EndLNI () const
 Returns an iterator referring to the past-the-end 'left' node in the graph.
TNodeI BegRNI () const
 Returns an iterator referring to the first 'right' node in the graph.
TNodeI EndRNI () const
 Returns an iterator referring to the past-the-end 'right' node in the graph.
int GetEdges () const
 Returns the number of edges in the graph.
int AddEdge (const int &LeftNId, const int &RightNId)
 Adds an edge between a node LeftNId on the left and a node RightNId on the right side of the bipartite graph.
int AddEdge (const TEdgeI &EdgeI)
 Adds an edge between EdgeI.GetLNId() and EdgeI.GetRNId() to the graph.
void DelEdge (const int &LeftNId, const int &RightNId)
 Deletes an edge between a node LeftNId on the left and a node RightNId on the right side of the bipartite graph.
bool IsEdge (const int &LeftNId, const int &RightNId) const
 Tests whether an edge between node IDs LeftNId and RightNId exists in the graph.
TEdgeI BegEI () const
 Returns an iterator referring to the first edge in the graph.
TEdgeI EndEI () const
 Returns an iterator referring to the past-the-end edge in the graph.
TEdgeI GetEI (const int &EId) const
 Not supported/implemented!
TEdgeI GetEI (const int &LeftNId, const int &RightNId) const
 Returns an iterator referring to edge (LeftNId, RightNId) in the graph.
int GetRndNId (TRnd &Rnd=TInt::Rnd)
 Returns an ID of a random node in the graph.
int GetRndLNId (TRnd &Rnd=TInt::Rnd)
 Returns an ID of a random 'left' node in the graph.
int GetRndRNId (TRnd &Rnd=TInt::Rnd)
 Returns an ID of a random 'right' node in the graph.
TNodeI GetRndNI (TRnd &Rnd=TInt::Rnd)
 Returns an interator referring to a random node in the graph.
void GetNIdV (TIntV &NIdV) const
 Gets a vector IDs of all nodes in the bipartite graph.
void GetLNIdV (TIntV &NIdV) const
 Gets a vector IDs of all 'left' nodes in the bipartite graph.
void GetRNIdV (TIntV &NIdV) const
 Gets a vector IDs of all 'right' nodes in the bipartite graph.
bool Empty () const
 Tests whether the bipartite graph is empty (has zero nodes).
void Clr ()
 Deletes all nodes and edges from the bipartite graph.
void Reserve (const int &Nodes, const int &Edges)
 Reserves memory for a biparite graph of Nodes nodes and Edges edges.
void Defrag (const bool &OnlyNodeLinks=false)
 Defragments the biparite graph.
bool IsOk (const bool &ThrowExcept=true) const
 Checks the bipartite graph data structure for internal consistency.
void Dump (FILE *OutF=stdout) const
 Print the biparite graph in a human readable form to an output stream OutF.

Static Public Member Functions

static PBPGraph New ()
 Static constructor that returns a pointer to the graph. Call: PBPGraph BPGraph = TBPGraph::New();.
static PBPGraph New (const int &Nodes, const int &Edges)
 Static constructor that returns a pointer to the graph and reserves enough memory for Nodes nodes and Edges edges.
static PBPGraph Load (TSIn &SIn)
 Static constructor that loads the graph from a stream SIn and returns a pointer to it.
static PBPGraph GetSmallGraph ()
 Returns a small graph on 2 'left', 3 'right' nodes and 4 edges.

Private Attributes

TCRef CRef
TInt MxNId
THash< TInt, TNodeLeftH
THash< TInt, TNodeRightH

Friends

class TPt< TBPGraph >

Detailed Description

Bipartite graph.

Definition at line 825 of file graph.h.


Member Typedef Documentation

Definition at line 828 of file graph.h.

Definition at line 827 of file graph.h.


Member Enumeration Documentation

Enumerator:
bgsUndef 
bgsLeft 
bgsRight 
bgsBoth 

Definition at line 829 of file graph.h.

{ bgsUndef, bgsLeft, bgsRight, bgsBoth } TNodeTy; // left or right hand side node

Constructor & Destructor Documentation

TBPGraph::TBPGraph ( ) [inline]

Definition at line 942 of file graph.h.

: CRef(), MxNId(0), LeftH(), RightH() { }
TBPGraph::TBPGraph ( const int &  Nodes,
const int &  Edges 
) [inline, explicit]

Constructor that reserves enough memory for a graph of Nodes (LeftNodes+RightNodes) nodes and Edges edges.

Definition at line 944 of file graph.h.

: MxNId(0) { } 
TBPGraph::TBPGraph ( const TBPGraph BPGraph) [inline]

!! Reserve(Nodes, Edges); }

Definition at line 945 of file graph.h.

: MxNId(BPGraph.MxNId), LeftH(BPGraph.LeftH), RightH(BPGraph.RightH) { }
TBPGraph::TBPGraph ( TSIn SIn) [inline]

Constructor for loading the graph from a (binary) stream SIn.

Definition at line 947 of file graph.h.

: MxNId(SIn), LeftH(SIn), RightH(SIn) { }

Member Function Documentation

int TBPGraph::AddEdge ( const int &  LeftNId,
const int &  RightNId 
)

Adds an edge between a node LeftNId on the left and a node RightNId on the right side of the bipartite graph.

Definition at line 652 of file graph.cpp.

                                                             {
  const bool IsLL = IsLNode(LeftNId), IsLR = IsRNode(LeftNId);
  const bool IsRL = IsLNode(RightNId), IsRR = IsRNode(RightNId);
  IAssertR((IsLL||IsLR)&&(IsRL||IsRR), TStr::Fmt("%d or %d is not a node.", LeftNId, RightNId).CStr());
  IAssertR(LeftNId!=RightNId, "No self-edges are allowed."); 
  IAssertR((IsLL&&!IsLR&&!IsRL&&IsRR)||(!IsLL&&IsLR&&IsRL&&!IsRR), "One node should be on the 'left' and the other on the 'right'.");
  const int LNId = IsLL ? LeftNId : RightNId; // the real left node
  const int RNId = IsLL ? RightNId : LeftNId; // the real right node
  if (LeftH.GetDat(LNId).IsOutNId(RNId)) { return -2; } // edge already exists
  LeftH.GetDat(LNId).NIdV.AddSorted(RNId);
  RightH.GetDat(RNId).NIdV.AddSorted(LNId);
  return -1; // edge id
}
int TBPGraph::AddEdge ( const TEdgeI EdgeI) [inline]

Adds an edge between EdgeI.GetLNId() and EdgeI.GetRNId() to the graph.

Definition at line 1008 of file graph.h.

{ return AddEdge(EdgeI.GetSrcNId(), EdgeI.GetDstNId()); }
int TBPGraph::AddNode ( int  NId = -1,
const bool &  LeftNode = true 
)

Adds a node of ID NId to the graph.

Definition at line 618 of file graph.cpp.

                                                   {
  if (NId == -1) { NId = MxNId;  MxNId++; }
  else if (IsLNode(NId)) { IAssertR(LeftNode, TStr::Fmt("Node with id %s already exists on the 'left'.", NId));  return NId; }
  else if (IsRNode(NId)) { IAssertR(! LeftNode, TStr::Fmt("Node with id %s already exists on the 'right'.", NId));  return NId; }
  else { MxNId = TMath::Mx(NId+1, MxNId()); }
  if (LeftNode) { LeftH.AddDat(NId, TNode(NId)); }
  else { RightH.AddDat(NId, TNode(NId)); }
  return NId;
}
int TBPGraph::AddNode ( const TNodeI NodeI) [inline]

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

Definition at line 972 of file graph.h.

{ return AddNode(NodeI.GetId(), NodeI.IsLeft()); }
TEdgeI TBPGraph::BegEI ( ) const [inline]

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

Definition at line 1015 of file graph.h.

{ TNodeI NI=BegLNI(); while (NI<EndLNI() && (NI.GetOutDeg()==0 || NI.GetId()>NI.GetOutNId(0))) { NI++; } return TEdgeI(NI, EndLNI()); }
TNodeI TBPGraph::BegLNI ( ) const [inline]

Returns an iterator referring to the first 'left' node in the graph.

Definition at line 994 of file graph.h.

{ return TNodeI(LeftH.BegI(), RightH.EndI()); }
TNodeI TBPGraph::BegNI ( ) const [inline]

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

Definition at line 988 of file graph.h.

{ return TNodeI(LeftH.BegI(), RightH.BegI()); }
TNodeI TBPGraph::BegRNI ( ) const [inline]

Returns an iterator referring to the first 'right' node in the graph.

Definition at line 998 of file graph.h.

{ return TNodeI(LeftH.EndI(), RightH.BegI()); }
void TBPGraph::Clr ( ) [inline]

Deletes all nodes and edges from the bipartite graph.

Definition at line 1042 of file graph.h.

{ MxNId=0; LeftH.Clr(); RightH.Clr(); }
void TBPGraph::Defrag ( const bool &  OnlyNodeLinks = false)

Defragments the biparite graph.

Definition at line 741 of file graph.cpp.

                                               {
  for (int n = LeftH.FFirstKeyId(); LeftH.FNextKeyId(n); ) {
    LeftH[n].NIdV.Pack(); }
  for (int n = RightH.FFirstKeyId(); RightH.FNextKeyId(n); ) {
    RightH[n].NIdV.Pack(); }
  if (! OnlyNodeLinks && ! LeftH.IsKeyIdEqKeyN()) { LeftH.Defrag(); }
  if (! OnlyNodeLinks && ! RightH.IsKeyIdEqKeyN()) { RightH.Defrag(); }
}
void TBPGraph::DelEdge ( const int &  LeftNId,
const int &  RightNId 
)

Deletes an edge between a node LeftNId on the left and a node RightNId on the right side of the bipartite graph.

Definition at line 666 of file graph.cpp.

                                                              {
  const bool IsLL = IsLNode(LeftNId), IsLR = IsRNode(LeftNId);
  const bool IsRL = IsLNode(RightNId), IsRR = IsRNode(RightNId);
  IAssertR((IsLL||IsLR)&&(IsRL||IsRR), TStr::Fmt("%d or %d is not a node.", LeftNId, RightNId).CStr());
  IAssertR(LeftNId!=RightNId, "No self-edges are allowed."); 
  IAssertR((IsLL&&!IsLR&&!IsRL&&IsRR)||(!IsLL&&IsLR&&IsRL&&!IsRR), "One node should be on the 'left' and the other on the 'right'.");
  const int LNId = IsLL ? LeftNId : RightNId; // the real left node
  const int RNId = IsLL ? RightNId : LeftNId; // the real right node
  { TIntV& NIdV = LeftH.GetDat(LNId).NIdV;
  const int n = NIdV.SearchBin(RNId);
  if (n != -1) { NIdV.Del(n); } }
  { TIntV& NIdV = RightH.GetDat(RNId).NIdV;
  const int n = NIdV.SearchBin(LNId);
  if (n != -1) { NIdV.Del(n); } }
}
void TBPGraph::DelNode ( const int &  NId)

Deletes node of ID NId from the graph.

Definition at line 629 of file graph.cpp.

                                     {
  AssertR(IsNode(NId), TStr::Fmt("NodeId %d does not exist", NId));
  THash<TInt, TNode>& SrcH = IsLNode(NId) ? LeftH : RightH;
  THash<TInt, TNode>& DstH = IsLNode(NId) ? RightH : LeftH;
  { TNode& Node = SrcH.GetDat(NId);
  for (int e = 0; e < Node.GetOutDeg(); e++) {
    const int nbr = Node.GetOutNId(e);
    IAssertR(nbr != NId, "Bipartite graph has a loop!");
    TNode& N = DstH.GetDat(nbr);
    const int n = N.NIdV.SearchBin(NId);
    IAssert(n!= -1); 
    N.NIdV.Del(n);
  } }
  SrcH.DelKey(NId);
}
void TBPGraph::DelNode ( const TNode NodeI) [inline]

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

Definition at line 977 of file graph.h.

{ DelNode(NodeI.GetId()); }
void TBPGraph::Dump ( FILE *  OutF = stdout) const

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

Definition at line 792 of file graph.cpp.

                                    {
  const int NodePlaces = (int) ceil(log10((double) GetNodes()));
  fprintf(OutF, "-------------------------------------------------\nBipartite Graph: nodes: %d+%d=%d, edges: %d\n", GetLNodes(), GetRNodes(), GetNodes(), GetEdges());
  for (int N = LeftH.FFirstKeyId(); LeftH.FNextKeyId(N); ) {
    const TNode& Node = LeftH[N];
    fprintf(OutF, "  %*d [%d] ", NodePlaces, Node.GetId(), Node.GetDeg());
    for (int edge = 0; edge < Node.GetDeg(); edge++) {
      fprintf(OutF, " %*d", NodePlaces, Node.GetNbrNId(edge)); }
    fprintf(OutF, "\n");
  }
  fprintf(OutF, "\n");
  /*// Also dump the 'right' side
  fprintf(OutF, "\n");
  for (int N = RightH.FFirstKeyId(); RightH.FNextKeyId(N); ) {
    const TNode& Node = RightH[N];
    fprintf(OutF, "  %*d [%d] ", NodePlaces, Node.GetId(), Node.GetDeg());
    for (int edge = 0; edge < Node.GetDeg(); edge++) {
      fprintf(OutF, " %*d", NodePlaces, Node.GetNbrNId(edge)); }
    fprintf(OutF, "\n");
  }
  fprintf(OutF, "\n"); //*/
}
bool TBPGraph::Empty ( ) const [inline]

Tests whether the bipartite graph is empty (has zero nodes).

Definition at line 1040 of file graph.h.

{ return GetNodes()==0; }
TEdgeI TBPGraph::EndEI ( ) const [inline]

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

Definition at line 1017 of file graph.h.

{ return TEdgeI(EndNI(), EndNI()); }
TNodeI TBPGraph::EndLNI ( ) const [inline]

Returns an iterator referring to the past-the-end 'left' node in the graph.

Definition at line 996 of file graph.h.

{ return EndNI(); }
TNodeI TBPGraph::EndNI ( ) const [inline]

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

Definition at line 990 of file graph.h.

{ return TNodeI(LeftH.EndI(), RightH.EndI()); }
TNodeI TBPGraph::EndRNI ( ) const [inline]

Returns an iterator referring to the past-the-end 'right' node in the graph.

Definition at line 1000 of file graph.h.

{ return EndNI(); }
int TBPGraph::GetEdges ( ) const

Returns the number of edges in the graph.

Definition at line 645 of file graph.cpp.

                             {
  int Edges = 0;
  for (int N=LeftH.FFirstKeyId(); LeftH.FNextKeyId(N); ) {
    Edges += LeftH[N].GetDeg(); }
  return Edges;
}
TEdgeI TBPGraph::GetEI ( const int &  EId) const

Not supported/implemented!

TBPGraph::TEdgeI TBPGraph::GetEI ( const int &  LeftNId,
const int &  RightNId 
) const

Returns an iterator referring to edge (LeftNId, RightNId) in the graph.

Definition at line 687 of file graph.cpp.

                                                                            {
  const bool IsLL = IsLNode(LeftNId), IsLR = IsRNode(LeftNId);
  const bool IsRL = IsLNode(RightNId), IsRR = IsRNode(RightNId);
  IAssertR((IsLL||IsLR)&&(IsRL||IsRR), TStr::Fmt("%d or %d is not a node.", LeftNId, RightNId).CStr());
  IAssertR(LeftNId!=RightNId, "No self-edges are allowed."); 
  IAssertR((IsLL&&!IsLR&&!IsRL&&IsRR)||(!IsLL&&IsLR&&IsRL&&!IsRR), "One node should be on the 'left' and the other on the 'right'.");
  const int LNId = IsLL ? LeftNId : RightNId; // the real left node
  const int RNId = IsLL ? RightNId : LeftNId; // the real right node
  const TNodeI SrcNI = GetNI(LNId);
  const int NodeN = SrcNI.LeftHI.GetDat().NIdV.SearchBin(RNId);
  IAssertR(NodeN != -1, "Right edge endpoint does not exists!");
  return TEdgeI(SrcNI, EndNI(), NodeN);
}
void TBPGraph::GetLNIdV ( TIntV NIdV) const

Gets a vector IDs of all 'left' nodes in the bipartite graph.

Definition at line 725 of file graph.cpp.

                                         {
  NIdV.Gen(GetLNodes(), 0);
  for (int N=LeftH.FFirstKeyId(); LeftH.FNextKeyId(N); ) {
    NIdV.Add(LeftH.GetKey(N)); }
}
int TBPGraph::GetLNodes ( ) const [inline]

Returns the number of nodes on the 'left' side of the biparite graph.

Definition at line 965 of file graph.h.

{ return LeftH.Len(); }
int TBPGraph::GetMxNId ( ) const [inline]

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

Definition at line 985 of file graph.h.

{ return MxNId; }
TNodeI TBPGraph::GetNI ( const int &  NId) const [inline]

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

Definition at line 992 of file graph.h.

{ return IsLNode(NId) ? TNodeI(LeftH.GetI(NId), RightH.EndI()) : TNodeI(LeftH.EndI(), RightH.GetI(NId)); }
void TBPGraph::GetNIdV ( TIntV NIdV) const

Gets a vector IDs of all nodes in the bipartite graph.

Definition at line 717 of file graph.cpp.

                                        {
  NIdV.Gen(GetNodes(), 0);
  for (int N=LeftH.FFirstKeyId(); LeftH.FNextKeyId(N); ) {
    NIdV.Add(LeftH.GetKey(N)); }
  for (int N=RightH.FFirstKeyId(); RightH.FNextKeyId(N); ) {
    NIdV.Add(RightH.GetKey(N)); }
}
int TBPGraph::GetNodes ( ) const [inline]

Returns the total number of nodes in the graph.

Definition at line 963 of file graph.h.

{ return GetLNodes() + GetRNodes(); }

Returns an ID of a random 'left' node in the graph.

Definition at line 709 of file graph.cpp.

                                  { 
  return LeftH.GetKey(LeftH.GetRndKeyId(Rnd, 0.8)); 
}
TNodeI TBPGraph::GetRndNI ( TRnd Rnd = TInt::Rnd) [inline]

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

Definition at line 1031 of file graph.h.

{ return GetNI(GetRndNId(Rnd)); }

Returns an ID of a random node in the graph.

Definition at line 701 of file graph.cpp.

                                 { 
  const int NNodes = GetNodes();
  if (Rnd.GetUniDevInt(NNodes) < GetLNodes()) {
    return GetRndLNId(Rnd); }
  else {
    return GetRndRNId(Rnd); }
}

Returns an ID of a random 'right' node in the graph.

Definition at line 713 of file graph.cpp.

                                  { 
  return RightH.GetKey(RightH.GetRndKeyId(Rnd, 0.8)); 
}
void TBPGraph::GetRNIdV ( TIntV NIdV) const

Gets a vector IDs of all 'right' nodes in the bipartite graph.

Definition at line 731 of file graph.cpp.

                                         {
  NIdV.Gen(GetRNodes(), 0);
  for (int N=RightH.FFirstKeyId(); RightH.FNextKeyId(N); ) {
    NIdV.Add(RightH.GetKey(N)); }
}
int TBPGraph::GetRNodes ( ) const [inline]

Returns the number of nodes on the 'right' side of the biparite graph.

Definition at line 967 of file graph.h.

{ return RightH.Len(); }

Returns a small graph on 2 'left', 3 'right' nodes and 4 edges.

Definition at line 815 of file graph.cpp.

                                 {
  PBPGraph BP = TBPGraph::New();
  BP->AddNode(0, true);
  BP->AddNode(1, true);
  BP->AddNode(2, false);
  BP->AddNode(3, false);
  BP->AddNode(4, false);
  BP->AddEdge(0, 2);
  BP->AddEdge(0, 3);
  BP->AddEdge(1, 2);
  BP->AddEdge(1, 3);
  BP->AddEdge(1, 4);
  return BP;
}
bool TBPGraph::HasFlag ( const TGraphFlag Flag) const

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

bool TBPGraph::IsEdge ( const int &  LeftNId,
const int &  RightNId 
) const

Tests whether an edge between node IDs LeftNId and RightNId exists in the graph.

Definition at line 682 of file graph.cpp.

                                                                   {
  if (! IsNode(LeftNId) || ! IsNode(RightNId)) { return false; }
  return IsLNode(LeftNId) ? LeftH.GetDat(LeftNId).IsOutNId(RightNId) : RightH.GetDat(LeftNId).IsOutNId(RightNId);
}
bool TBPGraph::IsLNode ( const int &  NId) const [inline]

Tests whether ID NId is a 'left' side node.

Definition at line 981 of file graph.h.

{ return LeftH.IsKey(NId); }
bool TBPGraph::IsNode ( const int &  NId) const [inline]

Tests whether ID NId is a node.

Definition at line 979 of file graph.h.

{ return IsLNode(NId) || IsRNode(NId); }
bool TBPGraph::IsOk ( const bool &  ThrowExcept = true) const

Checks the bipartite graph data structure for internal consistency.

Definition at line 750 of file graph.cpp.

                                                 {
  bool RetVal = false;
  // edge lists are sorted
  for (int n = LeftH.FFirstKeyId(); LeftH.FNextKeyId(n); ) {
    if (! LeftH[n].NIdV.IsSorted()) {
      const TStr Msg = TStr::Fmt("Neighbor list of node %d is not sorted.", LeftH[n].GetId());
      if (ThrowExcept) { EAssertR(false, Msg); } else { ErrNotify(Msg.CStr()); } RetVal=false; }
  }
  for (int n = RightH.FFirstKeyId(); RightH.FNextKeyId(n); ) {
    if (! RightH[n].NIdV.IsSorted()) {
      const TStr Msg = TStr::Fmt("Neighbor list of node %d is not sorted.", RightH[n].GetId());
      if (ThrowExcept) { EAssertR(false, Msg); } else { ErrNotify(Msg.CStr()); } RetVal=false; }
  }
  // nodes only appear on one side
  for (int n = LeftH.FFirstKeyId(); LeftH.FNextKeyId(n); ) {
    if (RightH.IsKey(LeftH[n].GetId())) {
      const TStr Msg = TStr::Fmt("'Left' node %d also appears on the 'right'.", LeftH[n].GetId());
      if (ThrowExcept) { EAssertR(false, Msg); } else { ErrNotify(Msg.CStr()); } RetVal=false; }
  } 
  for (int n = RightH.FFirstKeyId(); RightH.FNextKeyId(n); ) {
    if (LeftH.IsKey(RightH[n].GetId())) {
      const TStr Msg = TStr::Fmt("'Right' node %d also appears on the 'left'.", RightH[n].GetId());
      if (ThrowExcept) { EAssertR(false, Msg); } else { ErrNotify(Msg.CStr()); } RetVal=false; }
  }
  // edges only point from left to right and right to left
  for (int n = LeftH.FFirstKeyId(); LeftH.FNextKeyId(n); ) {
    for (int e = 0; e < LeftH[n].NIdV.Len(); e++) {
      if (! RightH.IsKey(LeftH[n].NIdV[e]) || ! RightH.GetDat(LeftH[n].NIdV[e]).NIdV.IsIn(LeftH[n].GetId())) {
        const TStr Msg = TStr::Fmt("'Left' node %d does not point to the 'right' node %d.", LeftH[n].GetId(), LeftH[n].NIdV[e]());
        if (ThrowExcept) { EAssertR(false, Msg); } else { ErrNotify(Msg.CStr()); } RetVal=false; }
    }
  }
  for (int n = RightH.FFirstKeyId(); RightH.FNextKeyId(n); ) {
    for (int e = 0; e < RightH[n].NIdV.Len(); e++) {
      if (! LeftH.IsKey(RightH[n].NIdV[e]) || ! LeftH.GetDat(RightH[n].NIdV[e]).NIdV.IsIn(RightH[n].GetId())) {
        const TStr Msg = TStr::Fmt("'Left' node %d does not point to the 'right' node %d.", RightH[n].GetId(), RightH[n].NIdV[e]());
        if (ThrowExcept) { EAssertR(false, Msg); } else { ErrNotify(Msg.CStr()); } RetVal=false; }
    }
  }
  return RetVal;
}
bool TBPGraph::IsRNode ( const int &  NId) const [inline]

Tests whether ID NId is a 'right' side node.

Definition at line 983 of file graph.h.

{ return RightH.IsKey(NId); }
static PBPGraph TBPGraph::Load ( TSIn SIn) [inline, static]

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

Definition at line 956 of file graph.h.

{ return PBPGraph(new TBPGraph(SIn)); }
static PBPGraph TBPGraph::New ( ) [inline, static]

Static constructor that returns a pointer to the graph. Call: PBPGraph BPGraph = TBPGraph::New();.

Definition at line 951 of file graph.h.

{ return new TBPGraph(); }
static PBPGraph TBPGraph::New ( const int &  Nodes,
const int &  Edges 
) [inline, static]

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

Definition at line 954 of file graph.h.

{ return new TBPGraph(Nodes, Edges); }
TBPGraph& TBPGraph::operator= ( const TBPGraph BPGraph) [inline]

Definition at line 959 of file graph.h.

                                                 {
    if (this!=&BPGraph) { MxNId=BPGraph.MxNId; LeftH=BPGraph.LeftH; RightH=BPGraph.RightH; }  return *this; }
void TBPGraph::Reserve ( const int &  Nodes,
const int &  Edges 
)

Reserves memory for a biparite graph of Nodes nodes and Edges edges.

Definition at line 737 of file graph.cpp.

                                                         { 
  if (Nodes>0) { LeftH.Gen(Nodes/2); RightH.Gen(Nodes/2); } 
}
void TBPGraph::Save ( TSOut SOut) const [inline]

Saves the graph to a (binary) stream SOut.

Definition at line 949 of file graph.h.

{ MxNId.Save(SOut); LeftH.Save(SOut); RightH.Save(SOut); }

Friends And Related Function Documentation

friend class TPt< TBPGraph > [friend]

Definition at line 1057 of file graph.h.


Member Data Documentation

TCRef TBPGraph::CRef [private]

Definition at line 934 of file graph.h.

Definition at line 936 of file graph.h.

TInt TBPGraph::MxNId [private]

Definition at line 935 of file graph.h.

Definition at line 937 of file graph.h.


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